diff --git a/core/java/android/view/ThreadedRenderer.java b/core/java/android/view/ThreadedRenderer.java index f44d4c1ac9df2..c972476565404 100644 --- a/core/java/android/view/ThreadedRenderer.java +++ b/core/java/android/view/ThreadedRenderer.java @@ -485,24 +485,14 @@ public final class ThreadedRenderer { } /** - * Halts any current rendering into the surface. Use this if it is unclear whether + * Stops any 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. - * - * Any subsequent draws will override the pause, resuming normal operation. + * Suspends any rendering into the surface, but will not do any destruction */ 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. @@ -998,7 +988,6 @@ 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, diff --git a/core/java/android/view/ViewRootImpl.java b/core/java/android/view/ViewRootImpl.java index 94c4cef959ba1..a324767ac4ede 100644 --- a/core/java/android/view/ViewRootImpl.java +++ b/core/java/android/view/ViewRootImpl.java @@ -1079,16 +1079,13 @@ 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 (renderer != null) { - renderer.destroyHardwareResources(mView); + if (mAttachInfo.mHardwareRenderer != null) { + if (DEBUG_DRAW) Log.d(mTag, "WindowStopped on " + getTitle()); + mAttachInfo.mHardwareRenderer.updateSurface(null); + mAttachInfo.mHardwareRenderer.destroyHardwareResources(mView); } } } diff --git a/core/jni/android_view_ThreadedRenderer.cpp b/core/jni/android_view_ThreadedRenderer.cpp index ef45c87277aea..3d6520903a7b9 100644 --- a/core/jni/android_view_ThreadedRenderer.cpp +++ b/core/jni/android_view_ThreadedRenderer.cpp @@ -479,12 +479,6 @@ 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(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(proxyPtr); @@ -738,7 +732,6 @@ 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 }, diff --git a/libs/hwui/renderthread/CanvasContext.cpp b/libs/hwui/renderthread/CanvasContext.cpp index 890d4a1ea2246..ab66b2aceb4c8 100644 --- a/libs/hwui/renderthread/CanvasContext.cpp +++ b/libs/hwui/renderthread/CanvasContext.cpp @@ -113,11 +113,18 @@ 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; } @@ -139,18 +146,6 @@ 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) { @@ -177,9 +172,7 @@ void CanvasContext::setOpaque(bool opaque) { mOpaque = opaque; } -bool CanvasContext::makeCurrent() { - if (mStopped) return false; - +void CanvasContext::makeCurrent() { // 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; @@ -187,7 +180,6 @@ bool CanvasContext::makeCurrent() { if (error) { setSurface(nullptr); } - return !error; } static bool wasSkipped(FrameInfo* info) { @@ -679,7 +671,7 @@ void CanvasContext::runWithGlContext(RenderTask* task) { } Layer* CanvasContext::createTextureLayer() { - mEglManager.initialize(); + requireSurface(); return LayerRenderer::createTextureLayer(mRenderThread.renderState()); } diff --git a/libs/hwui/renderthread/CanvasContext.h b/libs/hwui/renderthread/CanvasContext.h index 52df3abe2cae7..9350114e1abcd 100644 --- a/libs/hwui/renderthread/CanvasContext.h +++ b/libs/hwui/renderthread/CanvasContext.h @@ -82,14 +82,13 @@ 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); - bool makeCurrent(); + void makeCurrent(); void prepareTree(TreeInfo& info, int64_t* uiFrameInfo, int64_t syncQueued, RenderNode* target); void draw(); @@ -173,6 +172,7 @@ private: friend class android::uirenderer::RenderState; void setSurface(Surface* window); + void requireSurface(); void freePrefetchedLayers(TreeObserver* observer); @@ -185,7 +185,6 @@ private: EglManager& mEglManager; sp mNativeSurface; EGLSurface mEglSurface = EGL_NO_SURFACE; - bool mStopped = false; bool mBufferPreserved = false; SwapBehavior mSwapBehavior = kSwap_default; struct SwapHistory { diff --git a/libs/hwui/renderthread/DrawFrameTask.cpp b/libs/hwui/renderthread/DrawFrameTask.cpp index ed472ac4bd02a..651aaa23e3410 100644 --- a/libs/hwui/renderthread/DrawFrameTask.cpp +++ b/libs/hwui/renderthread/DrawFrameTask.cpp @@ -115,7 +115,7 @@ bool DrawFrameTask::syncFrameState(TreeInfo& info) { ATRACE_CALL(); int64_t vsync = mFrameInfo[static_cast(FrameInfoIndex::Vsync)]; mRenderThread->timeLord().vsyncReceived(vsync); - bool canDraw = mContext->makeCurrent(); + mContext->makeCurrent(); Caches::getInstance().textureCache.resetMarkInUse(mContext); for (size_t i = 0; i < mLayers.size(); i++) { @@ -126,9 +126,8 @@ bool DrawFrameTask::syncFrameState(TreeInfo& info) { // This is after the prepareTree so that any pending operations // (RenderNode tree state, prefetched layers, etc...) will be flushed. - if (CC_UNLIKELY(!mContext->hasSurface() || !canDraw)) { + if (CC_UNLIKELY(!mContext->hasSurface())) { mSyncResult |= kSync_LostSurfaceRewardIfFound; - info.out.canDrawThisFrame = false; } if (info.out.hasAnimations) { diff --git a/libs/hwui/renderthread/EglManager.cpp b/libs/hwui/renderthread/EglManager.cpp index ac6a28fe62891..8def7ad03d344 100644 --- a/libs/hwui/renderthread/EglManager.cpp +++ b/libs/hwui/renderthread/EglManager.cpp @@ -270,6 +270,12 @@ bool EglManager::makeCurrent(EGLSurface surface, EGLint* errOut) { // Ensure we always have a valid surface & context surface = mPBufferSurface; } + // TODO: Temporary to help diagnose b/27286867 + if (mCurrentSurface == mPBufferSurface || surface == mPBufferSurface) { + ALOGD("Switching from surface %p%s to %p%s", mCurrentSurface, + mCurrentSurface == mPBufferSurface ? " (pbuffer)" : "", + surface, surface == mPBufferSurface ? " (pbuffer)" : ""); + } if (!eglMakeCurrent(mEglDisplay, surface, surface, mEglContext)) { if (errOut) { *errOut = eglGetError(); diff --git a/libs/hwui/renderthread/RenderProxy.cpp b/libs/hwui/renderthread/RenderProxy.cpp index c5a2dc7bd8ce8..1116383e4eab0 100644 --- a/libs/hwui/renderthread/RenderProxy.cpp +++ b/libs/hwui/renderthread/RenderProxy.cpp @@ -167,18 +167,6 @@ bool RenderProxy::pauseSurface(const sp& surface) { return (bool) postAndWait(task); } -CREATE_BRIDGE2(setStopped, CanvasContext* context, bool stopped) { - args->context->setStopped(args->stopped); - return nullptr; -} - -void RenderProxy::setStopped(bool stopped) { - SETUP_TASK(setStopped); - args->context = mContext; - args->stopped = stopped; - postAndWait(task); -} - CREATE_BRIDGE6(setup, CanvasContext* context, int width, int height, float lightRadius, uint8_t ambientShadowAlpha, uint8_t spotShadowAlpha) { args->context->setup(args->width, args->height, args->lightRadius, diff --git a/libs/hwui/renderthread/RenderProxy.h b/libs/hwui/renderthread/RenderProxy.h index 32d3283bd8142..ecc296b4738ea 100644 --- a/libs/hwui/renderthread/RenderProxy.h +++ b/libs/hwui/renderthread/RenderProxy.h @@ -79,7 +79,6 @@ public: ANDROID_API void initialize(const sp& surface); ANDROID_API void updateSurface(const sp& surface); ANDROID_API bool pauseSurface(const sp& surface); - ANDROID_API void setStopped(bool stopped); ANDROID_API void setup(int width, int height, float lightRadius, uint8_t ambientShadowAlpha, uint8_t spotShadowAlpha); ANDROID_API void setLightCenter(const Vector3& lightCenter);