From 8c31e1db2a2cea4278503d6b9b27bca87946ef36 Mon Sep 17 00:00:00 2001 From: Robert Carr Date: Wed, 1 Mar 2017 12:02:05 -0800 Subject: [PATCH] SurfaceView: Include surfaceInsets in position calculation Previously the WM was taking care of this. Fixes: 35588318 Fixes: 34888808 Test: Manual Change-Id: I8b48d89f830bbef43b0132d191b29552e9c35702 --- core/java/android/view/SurfaceView.java | 17 ++++++++++++++--- core/jni/android_view_RenderNode.cpp | 4 ---- core/jni/android_view_ThreadedRenderer.cpp | 4 ---- libs/hwui/TreeInfo.h | 2 -- 4 files changed, 14 insertions(+), 13 deletions(-) diff --git a/core/java/android/view/SurfaceView.java b/core/java/android/view/SurfaceView.java index 64306338311bc..61b12475d5427 100644 --- a/core/java/android/view/SurfaceView.java +++ b/core/java/android/view/SurfaceView.java @@ -404,6 +404,15 @@ public class SurfaceView extends View { } } + private Rect getParentSurfaceInsets() { + final ViewRootImpl root = getViewRootImpl(); + if (root == null) { + return null; + } else { + return root.mWindowAttributes.surfaceInsets; + } + } + /** @hide */ protected void updateSurface() { if (!mHaveFrame) { @@ -459,6 +468,9 @@ public class SurfaceView extends View { mTranslator.translateRectInAppWindowToScreen(mScreenRect); } + final Rect surfaceInsets = getParentSurfaceInsets(); + mScreenRect.offset(surfaceInsets.left, surfaceInsets.top); + if (creating) { mSurfaceSession = new SurfaceSession(viewRoot.mSurface); mSurfaceControl = new SurfaceControl(mSurfaceSession, @@ -615,7 +627,7 @@ public class SurfaceView extends View { } else { // Calculate the window position in case RT loses the window // and we need to fallback to a UI-thread driven position update - getLocationInWindow(mLocation); + getLocationInSurface(mLocation); final boolean positionChanged = mWindowSpaceLeft != mLocation[0] || mWindowSpaceTop != mLocation[1]; final boolean layoutSizeChanged = getWidth() != mScreenRect.width() @@ -628,8 +640,6 @@ public class SurfaceView extends View { mLocation[0] = getWidth(); mLocation[1] = getHeight(); - transformFromViewToWindowSpace(mLocation); - mScreenRect.set(mWindowSpaceLeft, mWindowSpaceTop, mLocation[0], mLocation[1]); @@ -688,6 +698,7 @@ public class SurfaceView extends View { if (mSurfaceControl == null) { return; } + // TODO: This is teensy bit racey in that a brand new SurfaceView moving on // its 2nd frame if RenderThread is running slowly could potentially see // this as false, enter the branch, get pre-empted, then this comes along diff --git a/core/jni/android_view_RenderNode.cpp b/core/jni/android_view_RenderNode.cpp index edcbb3f783c36..6e8c931325626 100644 --- a/core/jni/android_view_RenderNode.cpp +++ b/core/jni/android_view_RenderNode.cpp @@ -452,10 +452,6 @@ static void android_view_RenderNode_requestPositionUpdates(JNIEnv* env, jobject, const RenderProperties& props = node.properties(); uirenderer::Rect bounds(props.getWidth(), props.getHeight()); transform.mapRect(bounds); - bounds.left -= info.windowInsetLeft; - bounds.right -= info.windowInsetLeft; - bounds.top -= info.windowInsetTop; - bounds.bottom -= info.windowInsetTop; if (CC_LIKELY(transform.isPureTranslate())) { // snap/round the computed bounds, so they match the rounding behavior diff --git a/core/jni/android_view_ThreadedRenderer.cpp b/core/jni/android_view_ThreadedRenderer.cpp index 37eae48a7a119..99edf6ef944ef 100644 --- a/core/jni/android_view_ThreadedRenderer.cpp +++ b/core/jni/android_view_ThreadedRenderer.cpp @@ -178,13 +178,9 @@ public: } } // TODO: This is hacky - info.windowInsetLeft = -stagingProperties().getLeft(); - info.windowInsetTop = -stagingProperties().getTop(); info.updateWindowPositions = true; RenderNode::prepareTree(info); info.updateWindowPositions = false; - info.windowInsetLeft = 0; - info.windowInsetTop = 0; info.errorHandler = nullptr; } diff --git a/libs/hwui/TreeInfo.h b/libs/hwui/TreeInfo.h index c6fbe2bd55ded..e39614b6a5ea4 100644 --- a/libs/hwui/TreeInfo.h +++ b/libs/hwui/TreeInfo.h @@ -91,8 +91,6 @@ public: LayerUpdateQueue* layerUpdateQueue = nullptr; ErrorHandler* errorHandler = nullptr; - int32_t windowInsetLeft = 0; - int32_t windowInsetTop = 0; bool updateWindowPositions = false; struct Out {