From ff299aef2000bd1093c6a6f80c2adda35ae8e206 Mon Sep 17 00:00:00 2001 From: John Reck Date: Thu, 21 Nov 2019 14:40:53 -0800 Subject: [PATCH] Fix for Surface#lockHardwareCanvas lockups By avoiding setting a dequeue buffer timeout we avoid hitting a different path in BufferQueue that prevents async behavior from happening. This restores P's behavior in this path. Bug: 143860379 Test: repro app in bug Change-Id: Iffbd9f9e6689a40876ff3aa74c10020e3f09fc6a Merged-In: Iffbd9f9e6689a40876ff3aa74c10020e3f09fc6a --- core/jni/android_view_Surface.cpp | 2 +- libs/hwui/renderthread/CanvasContext.cpp | 8 +++++--- libs/hwui/renderthread/CanvasContext.h | 2 +- libs/hwui/renderthread/RenderProxy.cpp | 7 ++++--- libs/hwui/renderthread/RenderProxy.h | 2 +- 5 files changed, 12 insertions(+), 9 deletions(-) diff --git a/core/jni/android_view_Surface.cpp b/core/jni/android_view_Surface.cpp index ff14a2acc4d77..ca10c8d5a2528 100644 --- a/core/jni/android_view_Surface.cpp +++ b/core/jni/android_view_Surface.cpp @@ -488,7 +488,7 @@ static jlong create(JNIEnv* env, jclass clazz, jlong rootNodePtr, jlong surfaceP proxy->setWideGamut(true); } proxy->setSwapBehavior(SwapBehavior::kSwap_discardBuffer); - proxy->setSurface(surface); + proxy->setSurface(surface, false); // Shadows can't be used via this interface, so just set the light source // to all 0s. proxy->setLightAlpha(0, 0); diff --git a/libs/hwui/renderthread/CanvasContext.cpp b/libs/hwui/renderthread/CanvasContext.cpp index 9898a1c30856d..827cced2883b7 100644 --- a/libs/hwui/renderthread/CanvasContext.cpp +++ b/libs/hwui/renderthread/CanvasContext.cpp @@ -143,13 +143,15 @@ void CanvasContext::destroy() { mAnimationContext->destroy(); } -void CanvasContext::setSurface(sp&& surface) { +void CanvasContext::setSurface(sp&& surface, bool enableTimeout) { ATRACE_CALL(); if (surface) { mNativeSurface = new ReliableSurface{std::move(surface)}; - // TODO: Fix error handling & re-shorten timeout - mNativeSurface->setDequeueTimeout(4000_ms); + if (enableTimeout) { + // TODO: Fix error handling & re-shorten timeout + mNativeSurface->setDequeueTimeout(4000_ms); + } } else { mNativeSurface = nullptr; } diff --git a/libs/hwui/renderthread/CanvasContext.h b/libs/hwui/renderthread/CanvasContext.h index 982c087b031a5..a0233ca357aa8 100644 --- a/libs/hwui/renderthread/CanvasContext.h +++ b/libs/hwui/renderthread/CanvasContext.h @@ -110,7 +110,7 @@ public: // Won't take effect until next EGLSurface creation void setSwapBehavior(SwapBehavior swapBehavior); - void setSurface(sp&& surface); + void setSurface(sp&& surface, bool enableTimeout = true); bool pauseSurface(); void setStopped(bool stopped); bool hasSurface() const { return mNativeSurface.get(); } diff --git a/libs/hwui/renderthread/RenderProxy.cpp b/libs/hwui/renderthread/RenderProxy.cpp index 1a1b9dac37f6b..edb82f4db16db 100644 --- a/libs/hwui/renderthread/RenderProxy.cpp +++ b/libs/hwui/renderthread/RenderProxy.cpp @@ -82,9 +82,10 @@ void RenderProxy::setName(const char* name) { mRenderThread.queue().runSync([this, name]() { mContext->setName(std::string(name)); }); } -void RenderProxy::setSurface(const sp& surface) { - mRenderThread.queue().post( - [this, surf = surface]() mutable { mContext->setSurface(std::move(surf)); }); +void RenderProxy::setSurface(const sp& surface, bool enableTimeout) { + mRenderThread.queue().post([this, surf = surface, enableTimeout]() mutable { + mContext->setSurface(std::move(surf), enableTimeout); + }); } void RenderProxy::allocateBuffers() { diff --git a/libs/hwui/renderthread/RenderProxy.h b/libs/hwui/renderthread/RenderProxy.h index a0f08cbd26f9e..76cd0ee2a2cef 100644 --- a/libs/hwui/renderthread/RenderProxy.h +++ b/libs/hwui/renderthread/RenderProxy.h @@ -69,7 +69,7 @@ public: ANDROID_API bool loadSystemProperties(); ANDROID_API void setName(const char* name); - ANDROID_API void setSurface(const sp& surface); + ANDROID_API void setSurface(const sp& surface, bool enableTimeout = true); ANDROID_API void allocateBuffers(); ANDROID_API bool pause(); ANDROID_API void setStopped(bool stopped);