Loading core/java/android/view/ThreadedRenderer.java +13 −2 Original line number Diff line number Diff line Loading @@ -485,14 +485,24 @@ public final class ThreadedRenderer { } /** * Stops any rendering into the surface. Use this if it is unclear whether * Halts any current rendering into the surface. Use this if it is unclear whether * or not the surface used by the HardwareRenderer will be changing. It * Suspends any rendering into the surface, but will not do any destruction * Suspends any rendering into the surface, but will not do any destruction. * * Any subsequent draws will override the pause, resuming normal operation. */ boolean pauseSurface(Surface surface) { return nPauseSurface(mNativeProxy, surface); } /** * Hard stops or resumes rendering into the surface. This flag is used to * determine whether or not it is safe to use the given surface *at all* */ void setStopped(boolean stopped) { nSetStopped(mNativeProxy, stopped); } /** * Destroys all hardware rendering resources associated with the specified * view hierarchy. Loading Loading @@ -992,6 +1002,7 @@ public final class ThreadedRenderer { private static native void nInitialize(long nativeProxy, Surface window); private static native void nUpdateSurface(long nativeProxy, Surface window); private static native boolean nPauseSurface(long nativeProxy, Surface window); private static native void nSetStopped(long nativeProxy, boolean stopped); private static native void nSetup(long nativeProxy, int width, int height, float lightRadius, int ambientShadowAlpha, int spotShadowAlpha); private static native void nSetLightCenter(long nativeProxy, Loading core/java/android/view/ViewRootImpl.java +15 −4 Original line number Diff line number Diff line Loading @@ -1080,13 +1080,16 @@ public final class ViewRootImpl implements ViewParent, void setWindowStopped(boolean stopped) { if (mStopped != stopped) { mStopped = stopped; final ThreadedRenderer renderer = mAttachInfo.mHardwareRenderer; if (renderer != null) { if (DEBUG_DRAW) Log.d(mTag, "WindowStopped on " + getTitle() + " set to " + mStopped); renderer.setStopped(mStopped); } if (!mStopped) { scheduleTraversals(); } else { if (mAttachInfo.mHardwareRenderer != null) { if (DEBUG_DRAW) Log.d(mTag, "WindowStopped on " + getTitle()); mAttachInfo.mHardwareRenderer.updateSurface(null); mAttachInfo.mHardwareRenderer.destroyHardwareResources(mView); if (renderer != null) { renderer.destroyHardwareResources(mView); } } } Loading Loading @@ -2556,6 +2559,7 @@ public final class ViewRootImpl implements ViewParent, if (mAttachInfo.mHardwareRenderer != null) { mAttachInfo.mHardwareRenderer.fence(); mAttachInfo.mHardwareRenderer.setStopped(mStopped); } if (LOCAL_LOGV) { Loading Loading @@ -2705,6 +2709,13 @@ public final class ViewRootImpl implements ViewParent, // shortly before the draw commands get send to the renderer. final boolean updated = updateContentDrawBounds(); if (mReportNextDraw) { // report next draw overrides setStopped() // This value is re-sync'd to the value of mStopped // in the handling of mReportNextDraw post-draw. mAttachInfo.mHardwareRenderer.setStopped(false); } mAttachInfo.mHardwareRenderer.draw(mView, mAttachInfo, this); if (updated) { Loading core/jni/android_view_ThreadedRenderer.cpp +7 −0 Original line number Diff line number Diff line Loading @@ -479,6 +479,12 @@ static jboolean android_view_ThreadedRenderer_pauseSurface(JNIEnv* env, jobject return proxy->pauseSurface(surface); } static void android_view_ThreadedRenderer_setStopped(JNIEnv* env, jobject clazz, jlong proxyPtr, jboolean stopped) { RenderProxy* proxy = reinterpret_cast<RenderProxy*>(proxyPtr); proxy->setStopped(stopped); } static void android_view_ThreadedRenderer_setup(JNIEnv* env, jobject clazz, jlong proxyPtr, jint width, jint height, jfloat lightRadius, jint ambientShadowAlpha, jint spotShadowAlpha) { RenderProxy* proxy = reinterpret_cast<RenderProxy*>(proxyPtr); Loading Loading @@ -740,6 +746,7 @@ static const JNINativeMethod gMethods[] = { { "nInitialize", "(JLandroid/view/Surface;)V", (void*) android_view_ThreadedRenderer_initialize }, { "nUpdateSurface", "(JLandroid/view/Surface;)V", (void*) android_view_ThreadedRenderer_updateSurface }, { "nPauseSurface", "(JLandroid/view/Surface;)Z", (void*) android_view_ThreadedRenderer_pauseSurface }, { "nSetStopped", "(JZ)V", (void*) android_view_ThreadedRenderer_setStopped }, { "nSetup", "(JIIFII)V", (void*) android_view_ThreadedRenderer_setup }, { "nSetLightCenter", "(JFFF)V", (void*) android_view_ThreadedRenderer_setLightCenter }, { "nSetOpaque", "(JZ)V", (void*) android_view_ThreadedRenderer_setOpaque }, Loading libs/hwui/renderthread/CanvasContext.cpp +17 −9 Original line number Diff line number Diff line Loading @@ -113,18 +113,11 @@ void CanvasContext::setSurface(Surface* surface) { mBufferPreserved = mEglManager.setPreserveBuffer(mEglSurface, preserveBuffer); mHaveNewSurface = true; mSwapHistory.clear(); makeCurrent(); } else { mRenderThread.removeFrameCallback(this); } } void CanvasContext::requireSurface() { LOG_ALWAYS_FATAL_IF(mEglSurface == EGL_NO_SURFACE, "requireSurface() called but no surface set!"); makeCurrent(); } void CanvasContext::setSwapBehavior(SwapBehavior swapBehavior) { mSwapBehavior = swapBehavior; } Loading @@ -146,6 +139,18 @@ bool CanvasContext::pauseSurface(Surface* surface) { return mRenderThread.removeFrameCallback(this); } void CanvasContext::setStopped(bool stopped) { if (mStopped != stopped) { mStopped = stopped; if (mStopped) { mRenderThread.removeFrameCallback(this); if (mEglManager.isCurrent(mEglSurface)) { mEglManager.makeCurrent(EGL_NO_SURFACE); } } } } // TODO: don't pass viewport size, it's automatic via EGL void CanvasContext::setup(int width, int height, float lightRadius, uint8_t ambientShadowAlpha, uint8_t spotShadowAlpha) { Loading @@ -172,7 +177,9 @@ void CanvasContext::setOpaque(bool opaque) { mOpaque = opaque; } void CanvasContext::makeCurrent() { bool CanvasContext::makeCurrent() { if (mStopped) return false; // TODO: Figure out why this workaround is needed, see b/13913604 // In the meantime this matches the behavior of GLRenderer, so it is not a regression EGLint error = 0; Loading @@ -180,6 +187,7 @@ void CanvasContext::makeCurrent() { if (error) { setSurface(nullptr); } return !error; } static bool wasSkipped(FrameInfo* info) { Loading Loading @@ -671,7 +679,7 @@ void CanvasContext::runWithGlContext(RenderTask* task) { } Layer* CanvasContext::createTextureLayer() { requireSurface(); mEglManager.initialize(); return LayerRenderer::createTextureLayer(mRenderThread.renderState()); } Loading libs/hwui/renderthread/CanvasContext.h +3 −2 Original line number Diff line number Diff line Loading @@ -82,13 +82,14 @@ public: void initialize(Surface* surface); void updateSurface(Surface* surface); bool pauseSurface(Surface* surface); void setStopped(bool stopped); bool hasSurface() { return mNativeSurface.get(); } void setup(int width, int height, float lightRadius, uint8_t ambientShadowAlpha, uint8_t spotShadowAlpha); void setLightCenter(const Vector3& lightCenter); void setOpaque(bool opaque); void makeCurrent(); bool makeCurrent(); void prepareTree(TreeInfo& info, int64_t* uiFrameInfo, int64_t syncQueued, RenderNode* target); void draw(); Loading Loading @@ -172,7 +173,6 @@ private: friend class android::uirenderer::RenderState; void setSurface(Surface* window); void requireSurface(); void freePrefetchedLayers(TreeObserver* observer); Loading @@ -185,6 +185,7 @@ private: EglManager& mEglManager; sp<Surface> mNativeSurface; EGLSurface mEglSurface = EGL_NO_SURFACE; bool mStopped = false; bool mBufferPreserved = false; SwapBehavior mSwapBehavior = kSwap_default; struct SwapHistory { Loading Loading
core/java/android/view/ThreadedRenderer.java +13 −2 Original line number Diff line number Diff line Loading @@ -485,14 +485,24 @@ public final class ThreadedRenderer { } /** * Stops any rendering into the surface. Use this if it is unclear whether * Halts any current rendering into the surface. Use this if it is unclear whether * or not the surface used by the HardwareRenderer will be changing. It * Suspends any rendering into the surface, but will not do any destruction * Suspends any rendering into the surface, but will not do any destruction. * * Any subsequent draws will override the pause, resuming normal operation. */ boolean pauseSurface(Surface surface) { return nPauseSurface(mNativeProxy, surface); } /** * Hard stops or resumes rendering into the surface. This flag is used to * determine whether or not it is safe to use the given surface *at all* */ void setStopped(boolean stopped) { nSetStopped(mNativeProxy, stopped); } /** * Destroys all hardware rendering resources associated with the specified * view hierarchy. Loading Loading @@ -992,6 +1002,7 @@ public final class ThreadedRenderer { private static native void nInitialize(long nativeProxy, Surface window); private static native void nUpdateSurface(long nativeProxy, Surface window); private static native boolean nPauseSurface(long nativeProxy, Surface window); private static native void nSetStopped(long nativeProxy, boolean stopped); private static native void nSetup(long nativeProxy, int width, int height, float lightRadius, int ambientShadowAlpha, int spotShadowAlpha); private static native void nSetLightCenter(long nativeProxy, Loading
core/java/android/view/ViewRootImpl.java +15 −4 Original line number Diff line number Diff line Loading @@ -1080,13 +1080,16 @@ public final class ViewRootImpl implements ViewParent, void setWindowStopped(boolean stopped) { if (mStopped != stopped) { mStopped = stopped; final ThreadedRenderer renderer = mAttachInfo.mHardwareRenderer; if (renderer != null) { if (DEBUG_DRAW) Log.d(mTag, "WindowStopped on " + getTitle() + " set to " + mStopped); renderer.setStopped(mStopped); } if (!mStopped) { scheduleTraversals(); } else { if (mAttachInfo.mHardwareRenderer != null) { if (DEBUG_DRAW) Log.d(mTag, "WindowStopped on " + getTitle()); mAttachInfo.mHardwareRenderer.updateSurface(null); mAttachInfo.mHardwareRenderer.destroyHardwareResources(mView); if (renderer != null) { renderer.destroyHardwareResources(mView); } } } Loading Loading @@ -2556,6 +2559,7 @@ public final class ViewRootImpl implements ViewParent, if (mAttachInfo.mHardwareRenderer != null) { mAttachInfo.mHardwareRenderer.fence(); mAttachInfo.mHardwareRenderer.setStopped(mStopped); } if (LOCAL_LOGV) { Loading Loading @@ -2705,6 +2709,13 @@ public final class ViewRootImpl implements ViewParent, // shortly before the draw commands get send to the renderer. final boolean updated = updateContentDrawBounds(); if (mReportNextDraw) { // report next draw overrides setStopped() // This value is re-sync'd to the value of mStopped // in the handling of mReportNextDraw post-draw. mAttachInfo.mHardwareRenderer.setStopped(false); } mAttachInfo.mHardwareRenderer.draw(mView, mAttachInfo, this); if (updated) { Loading
core/jni/android_view_ThreadedRenderer.cpp +7 −0 Original line number Diff line number Diff line Loading @@ -479,6 +479,12 @@ static jboolean android_view_ThreadedRenderer_pauseSurface(JNIEnv* env, jobject return proxy->pauseSurface(surface); } static void android_view_ThreadedRenderer_setStopped(JNIEnv* env, jobject clazz, jlong proxyPtr, jboolean stopped) { RenderProxy* proxy = reinterpret_cast<RenderProxy*>(proxyPtr); proxy->setStopped(stopped); } static void android_view_ThreadedRenderer_setup(JNIEnv* env, jobject clazz, jlong proxyPtr, jint width, jint height, jfloat lightRadius, jint ambientShadowAlpha, jint spotShadowAlpha) { RenderProxy* proxy = reinterpret_cast<RenderProxy*>(proxyPtr); Loading Loading @@ -740,6 +746,7 @@ static const JNINativeMethod gMethods[] = { { "nInitialize", "(JLandroid/view/Surface;)V", (void*) android_view_ThreadedRenderer_initialize }, { "nUpdateSurface", "(JLandroid/view/Surface;)V", (void*) android_view_ThreadedRenderer_updateSurface }, { "nPauseSurface", "(JLandroid/view/Surface;)Z", (void*) android_view_ThreadedRenderer_pauseSurface }, { "nSetStopped", "(JZ)V", (void*) android_view_ThreadedRenderer_setStopped }, { "nSetup", "(JIIFII)V", (void*) android_view_ThreadedRenderer_setup }, { "nSetLightCenter", "(JFFF)V", (void*) android_view_ThreadedRenderer_setLightCenter }, { "nSetOpaque", "(JZ)V", (void*) android_view_ThreadedRenderer_setOpaque }, Loading
libs/hwui/renderthread/CanvasContext.cpp +17 −9 Original line number Diff line number Diff line Loading @@ -113,18 +113,11 @@ void CanvasContext::setSurface(Surface* surface) { mBufferPreserved = mEglManager.setPreserveBuffer(mEglSurface, preserveBuffer); mHaveNewSurface = true; mSwapHistory.clear(); makeCurrent(); } else { mRenderThread.removeFrameCallback(this); } } void CanvasContext::requireSurface() { LOG_ALWAYS_FATAL_IF(mEglSurface == EGL_NO_SURFACE, "requireSurface() called but no surface set!"); makeCurrent(); } void CanvasContext::setSwapBehavior(SwapBehavior swapBehavior) { mSwapBehavior = swapBehavior; } Loading @@ -146,6 +139,18 @@ bool CanvasContext::pauseSurface(Surface* surface) { return mRenderThread.removeFrameCallback(this); } void CanvasContext::setStopped(bool stopped) { if (mStopped != stopped) { mStopped = stopped; if (mStopped) { mRenderThread.removeFrameCallback(this); if (mEglManager.isCurrent(mEglSurface)) { mEglManager.makeCurrent(EGL_NO_SURFACE); } } } } // TODO: don't pass viewport size, it's automatic via EGL void CanvasContext::setup(int width, int height, float lightRadius, uint8_t ambientShadowAlpha, uint8_t spotShadowAlpha) { Loading @@ -172,7 +177,9 @@ void CanvasContext::setOpaque(bool opaque) { mOpaque = opaque; } void CanvasContext::makeCurrent() { bool CanvasContext::makeCurrent() { if (mStopped) return false; // TODO: Figure out why this workaround is needed, see b/13913604 // In the meantime this matches the behavior of GLRenderer, so it is not a regression EGLint error = 0; Loading @@ -180,6 +187,7 @@ void CanvasContext::makeCurrent() { if (error) { setSurface(nullptr); } return !error; } static bool wasSkipped(FrameInfo* info) { Loading Loading @@ -671,7 +679,7 @@ void CanvasContext::runWithGlContext(RenderTask* task) { } Layer* CanvasContext::createTextureLayer() { requireSurface(); mEglManager.initialize(); return LayerRenderer::createTextureLayer(mRenderThread.renderState()); } Loading
libs/hwui/renderthread/CanvasContext.h +3 −2 Original line number Diff line number Diff line Loading @@ -82,13 +82,14 @@ public: void initialize(Surface* surface); void updateSurface(Surface* surface); bool pauseSurface(Surface* surface); void setStopped(bool stopped); bool hasSurface() { return mNativeSurface.get(); } void setup(int width, int height, float lightRadius, uint8_t ambientShadowAlpha, uint8_t spotShadowAlpha); void setLightCenter(const Vector3& lightCenter); void setOpaque(bool opaque); void makeCurrent(); bool makeCurrent(); void prepareTree(TreeInfo& info, int64_t* uiFrameInfo, int64_t syncQueued, RenderNode* target); void draw(); Loading Loading @@ -172,7 +173,6 @@ private: friend class android::uirenderer::RenderState; void setSurface(Surface* window); void requireSurface(); void freePrefetchedLayers(TreeObserver* observer); Loading @@ -185,6 +185,7 @@ private: EglManager& mEglManager; sp<Surface> mNativeSurface; EGLSurface mEglSurface = EGL_NO_SURFACE; bool mStopped = false; bool mBufferPreserved = false; SwapBehavior mSwapBehavior = kSwap_default; struct SwapHistory { Loading