diff --git a/core/java/android/view/ThreadedRenderer.java b/core/java/android/view/ThreadedRenderer.java index 2f975b68b9857..29306993454c8 100644 --- a/core/java/android/view/ThreadedRenderer.java +++ b/core/java/android/view/ThreadedRenderer.java @@ -955,6 +955,10 @@ public final class ThreadedRenderer { nSetDebuggingEnabled(enable); } + void allocateBuffers(Surface surface) { + nAllocateBuffers(mNativeProxy, surface); + } + @Override protected void finalize() throws Throwable { try { @@ -1243,4 +1247,5 @@ public final class ThreadedRenderer { private static native void nSetDebuggingEnabled(boolean enabled); private static native void nSetIsolatedProcess(boolean enabled); private static native void nSetContextPriority(int priority); + private static native void nAllocateBuffers(long nativeProxy, Surface window); } diff --git a/core/java/android/view/ViewRootImpl.java b/core/java/android/view/ViewRootImpl.java index ea9bd854a7af6..240f3c0098416 100644 --- a/core/java/android/view/ViewRootImpl.java +++ b/core/java/android/view/ViewRootImpl.java @@ -2101,7 +2101,7 @@ public final class ViewRootImpl implements ViewParent, & View.PFLAG_REQUEST_TRANSPARENT_REGIONS) == 0) { // Don't pre-allocate if transparent regions // are requested as they may not be needed - mSurface.allocateBuffers(); + mAttachInfo.mThreadedRenderer.allocateBuffers(mSurface); } } catch (OutOfResourcesException e) { handleOutOfResourcesException(e); diff --git a/core/jni/android_view_ThreadedRenderer.cpp b/core/jni/android_view_ThreadedRenderer.cpp index 497b2894d4059..4a1774279d280 100644 --- a/core/jni/android_view_ThreadedRenderer.cpp +++ b/core/jni/android_view_ThreadedRenderer.cpp @@ -1054,6 +1054,13 @@ static void android_view_ThreadedRenderer_setContextPriority(JNIEnv*, jclass, Properties::contextPriority = contextPriority; } +static void android_view_ThreadedRenderer_allocateBuffers(JNIEnv* env, jobject clazz, + jlong proxyPtr, jobject jsurface) { + RenderProxy* proxy = reinterpret_cast(proxyPtr); + sp surface = android_view_Surface_getSurface(env, jsurface); + proxy->allocateBuffers(surface); +} + // ---------------------------------------------------------------------------- // FrameMetricsObserver // ---------------------------------------------------------------------------- @@ -1166,6 +1173,7 @@ static const JNINativeMethod gMethods[] = { { "nSetDebuggingEnabled", "(Z)V", (void*)android_view_ThreadedRenderer_setDebuggingEnabled }, { "nSetIsolatedProcess", "(Z)V", (void*)android_view_ThreadedRenderer_setIsolatedProcess }, { "nSetContextPriority", "(I)V", (void*)android_view_ThreadedRenderer_setContextPriority }, + { "nAllocateBuffers", "(JLandroid/view/Surface;)V", (void*)android_view_ThreadedRenderer_allocateBuffers }, }; static JavaVM* mJvm = nullptr; diff --git a/libs/hwui/renderthread/RenderProxy.cpp b/libs/hwui/renderthread/RenderProxy.cpp index 6eca8d2f346f3..e3807e6348907 100644 --- a/libs/hwui/renderthread/RenderProxy.cpp +++ b/libs/hwui/renderthread/RenderProxy.cpp @@ -85,6 +85,11 @@ void RenderProxy::initialize(const sp& surface) { [ this, surf = surface ]() mutable { mContext->setSurface(std::move(surf)); }); } +void RenderProxy::allocateBuffers(const sp& surface) { + mRenderThread.queue().post( + [ surf = surface ]() mutable { surf->allocateBuffers(); }); +} + void RenderProxy::updateSurface(const sp& surface) { mRenderThread.queue().post( [ this, surf = surface ]() mutable { mContext->setSurface(std::move(surf)); }); diff --git a/libs/hwui/renderthread/RenderProxy.h b/libs/hwui/renderthread/RenderProxy.h index 5668484673fb1..c2964a4e35159 100644 --- a/libs/hwui/renderthread/RenderProxy.h +++ b/libs/hwui/renderthread/RenderProxy.h @@ -70,6 +70,7 @@ public: ANDROID_API void setName(const char* name); ANDROID_API void initialize(const sp& surface); + ANDROID_API void allocateBuffers(const sp& surface); ANDROID_API void updateSurface(const sp& surface); ANDROID_API bool pauseSurface(const sp& surface); ANDROID_API void setStopped(bool stopped);