From 1003c499017267bc497fc45cf8802cb933d9781b Mon Sep 17 00:00:00 2001 From: Thomas Buhot Date: Fri, 4 Dec 2015 12:18:03 +0100 Subject: libhwui: make setSurface asynchronous On the critical path of the cold launch of applications the main thread of the started application tells the RenderThread to create a surface. This process is synchronous and blocks the main thread of the application until the creation of the EGLContext is complete. As a consequence the launch time of the application is delayed by time spent allocating the EGL Context in the RenderThread. With this optimization the launch time of any application is improved (for example settings by 20 to 40 ms). Change-Id: I41cfe4e18f2d26af5058b8b17c19df60ac1e5d85 Signed-off-by: Thomas Buhot Signed-off-by: Zhiquan Liu --- libs/hwui/renderthread/CanvasContext.cpp | 5 ++--- libs/hwui/renderthread/CanvasContext.h | 2 +- libs/hwui/renderthread/RenderProxy.cpp | 7 ++++--- libs/hwui/renderthread/RenderProxy.h | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) (limited to 'libs') diff --git a/libs/hwui/renderthread/CanvasContext.cpp b/libs/hwui/renderthread/CanvasContext.cpp index 6dfb6e8..87a703c 100644 --- a/libs/hwui/renderthread/CanvasContext.cpp +++ b/libs/hwui/renderthread/CanvasContext.cpp @@ -110,12 +110,11 @@ void CanvasContext::setSwapBehavior(SwapBehavior swapBehavior) { mSwapBehavior = swapBehavior; } -bool CanvasContext::initialize(ANativeWindow* window) { +void CanvasContext::initialize(ANativeWindow* window) { setSurface(window); - if (mCanvas) return false; + if (mCanvas) return; mCanvas = new OpenGLRenderer(mRenderThread.renderState()); mCanvas->initProperties(); - return true; } void CanvasContext::updateSurface(ANativeWindow* window) { diff --git a/libs/hwui/renderthread/CanvasContext.h b/libs/hwui/renderthread/CanvasContext.h index f2fa9cd..1e6f830 100644 --- a/libs/hwui/renderthread/CanvasContext.h +++ b/libs/hwui/renderthread/CanvasContext.h @@ -67,7 +67,7 @@ public: // Won't take effect until next EGLSurface creation void setSwapBehavior(SwapBehavior swapBehavior); - bool initialize(ANativeWindow* window); + void initialize(ANativeWindow* window); void updateSurface(ANativeWindow* window); bool pauseSurface(ANativeWindow* window); bool hasSurface() { return mNativeWindow.get(); } diff --git a/libs/hwui/renderthread/RenderProxy.cpp b/libs/hwui/renderthread/RenderProxy.cpp index 6d9acd4..30f0073 100644 --- a/libs/hwui/renderthread/RenderProxy.cpp +++ b/libs/hwui/renderthread/RenderProxy.cpp @@ -140,14 +140,15 @@ void RenderProxy::setName(const char* name) { } CREATE_BRIDGE2(initialize, CanvasContext* context, ANativeWindow* window) { - return (void*) args->context->initialize(args->window); + args->context->initialize(args->window); + return nullptr; } -bool RenderProxy::initialize(const sp& window) { +void RenderProxy::initialize(const sp& window) { SETUP_TASK(initialize); args->context = mContext; args->window = window.get(); - return (bool) postAndWait(task); + post(task); } CREATE_BRIDGE2(updateSurface, CanvasContext* context, ANativeWindow* window) { diff --git a/libs/hwui/renderthread/RenderProxy.h b/libs/hwui/renderthread/RenderProxy.h index 5febbe0..db03b29 100644 --- a/libs/hwui/renderthread/RenderProxy.h +++ b/libs/hwui/renderthread/RenderProxy.h @@ -67,7 +67,7 @@ public: ANDROID_API bool loadSystemProperties(); ANDROID_API void setName(const char* name); - ANDROID_API bool initialize(const sp& window); + ANDROID_API void initialize(const sp& window); ANDROID_API void updateSurface(const sp& window); ANDROID_API bool pauseSurface(const sp& window); ANDROID_API void setup(int width, int height, float lightRadius, -- cgit v1.1