From f5f90f122111bdf351112ad966b87c6560783ddb Mon Sep 17 00:00:00 2001 From: Matt Buckley Date: Sat, 28 Jan 2023 04:09:14 +0000 Subject: [PATCH] Create HintSessionWrapper right after CanvasContext Move the construction of the HintSessionWrapper to RT right after the creation of the CanvasContext to ensure enough time is provided to not block the critical path in most cases. Bug: 266560774 Test: manual Change-Id: I1a67b163acd9c41156d9b9e14e974c67b6ba6ed5 --- libs/hwui/renderthread/CanvasContext.cpp | 6 ++++-- libs/hwui/renderthread/CanvasContext.h | 2 ++ libs/hwui/renderthread/RenderProxy.cpp | 8 ++++++-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/libs/hwui/renderthread/CanvasContext.cpp b/libs/hwui/renderthread/CanvasContext.cpp index db4d1dc5c1585..0d091b3224ddc 100644 --- a/libs/hwui/renderthread/CanvasContext.cpp +++ b/libs/hwui/renderthread/CanvasContext.cpp @@ -194,8 +194,6 @@ void CanvasContext::setSurface(ANativeWindow* window, bool enableTimeout) { ATRACE_CALL(); if (window) { - // Ensure the hint session is running here, away from any critical paths - mHintSessionWrapper.init(); mNativeSurface = std::make_unique(window); mNativeSurface->init(); if (enableTimeout) { @@ -1033,6 +1031,10 @@ void CanvasContext::setSyncDelayDuration(nsecs_t duration) { mSyncDelayDuration = duration; } +void CanvasContext::startHintSession() { + mHintSessionWrapper.init(); +} + } /* namespace renderthread */ } /* namespace uirenderer */ } /* namespace android */ diff --git a/libs/hwui/renderthread/CanvasContext.h b/libs/hwui/renderthread/CanvasContext.h index a274d2f2377f2..d7fe0d635b485 100644 --- a/libs/hwui/renderthread/CanvasContext.h +++ b/libs/hwui/renderthread/CanvasContext.h @@ -227,6 +227,8 @@ public: void setSyncDelayDuration(nsecs_t duration); + void startHintSession(); + private: CanvasContext(RenderThread& thread, bool translucent, RenderNode* rootRenderNode, IContextFactory* contextFactory, std::unique_ptr renderPipeline, diff --git a/libs/hwui/renderthread/RenderProxy.cpp b/libs/hwui/renderthread/RenderProxy.cpp index 5edb0b1dd8185..353078d37a75e 100644 --- a/libs/hwui/renderthread/RenderProxy.cpp +++ b/libs/hwui/renderthread/RenderProxy.cpp @@ -45,8 +45,12 @@ RenderProxy::RenderProxy(bool translucent, RenderNode* rootRenderNode, pid_t uiThreadId = pthread_gettid_np(pthread_self()); pid_t renderThreadId = getRenderThreadTid(); mContext = mRenderThread.queue().runSync([=, this]() -> CanvasContext* { - return CanvasContext::create(mRenderThread, translucent, rootRenderNode, contextFactory, - uiThreadId, renderThreadId); + CanvasContext* context = CanvasContext::create(mRenderThread, translucent, rootRenderNode, + contextFactory, uiThreadId, renderThreadId); + if (context != nullptr) { + mRenderThread.queue().post([=] { context->startHintSession(); }); + } + return context; }); mDrawFrameTask.setContext(&mRenderThread, mContext, rootRenderNode); }