diff options
| author | Vishnu Nair <vishnun@google.com> | 2019-06-24 08:12:28 -0700 |
|---|---|---|
| committer | Vishnu Nair <vishnun@google.com> | 2019-06-24 08:12:32 -0700 |
| commit | eaab0e5aad969bd430ef159d88bc78a6a8120d78 (patch) | |
| tree | 195ddb05bf1d35937669a6ec8327e2aa1be21e73 /core/java/android/view/SurfaceView.java | |
| parent | 798a07f59750e8f74d89ec69b495b0c719276e02 (diff) | |
Remove references of the previous surface control in ViewRootImpl
Partial revert to fix regression from f7645aa9a968e2da227f1edceaa2b83054b451dd which
kept a strong ref of the old SC used to detect when the SC changed. This meant that during the lifetime of an app it could keep an additional buffer alive.
Bug: 135762652, 132205507
Test: go/wm-smoke
Test: dumpsys meminfo
Change-Id: I93df8b4ef8ffdded6c46fb44ca4cd110038d75d0
Diffstat (limited to 'core/java/android/view/SurfaceView.java')
| -rw-r--r-- | core/java/android/view/SurfaceView.java | 54 |
1 files changed, 14 insertions, 40 deletions
diff --git a/core/java/android/view/SurfaceView.java b/core/java/android/view/SurfaceView.java index 17e83ca364bd..f7654716e31f 100644 --- a/core/java/android/view/SurfaceView.java +++ b/core/java/android/view/SurfaceView.java @@ -97,8 +97,7 @@ import java.util.concurrent.locks.ReentrantLock; * artifacts may occur on previous versions of the platform when its window is * positioned asynchronously.</p> */ -public class SurfaceView extends View - implements ViewRootImpl.WindowStoppedCallback, ViewRootImpl.SurfaceChangedCallback { +public class SurfaceView extends View implements ViewRootImpl.WindowStoppedCallback { private static final String TAG = "SurfaceView"; private static final boolean DEBUG = false; @@ -120,7 +119,7 @@ public class SurfaceView extends View boolean mDrawFinished = false; final Rect mScreenRect = new Rect(); - final SurfaceSession mSurfaceSession = new SurfaceSession(); + SurfaceSession mSurfaceSession; SurfaceControl mSurfaceControl; // In the case of format changes we switch out the surface in-place @@ -243,22 +242,11 @@ public class SurfaceView extends View updateSurface(); } - /** @hide */ - @Override - public void surfaceChangedCallback(SurfaceControl.Transaction transaction) { - if (getViewRootImpl() != null && mBackgroundControl != null && mSurfaceControl != null) { - SurfaceControl sc = getViewRootImpl().getSurfaceControl(); - transaction.setRelativeLayer(mBackgroundControl, sc, Integer.MIN_VALUE); - transaction.setRelativeLayer(mSurfaceControl, sc, mSubLayer); - } - } - @Override protected void onAttachedToWindow() { super.onAttachedToWindow(); getViewRootImpl().addWindowStoppedCallback(this); - getViewRootImpl().addSurfaceChangedCallback(this); mWindowStopped = false; mViewVisibility = getVisibility() == VISIBLE; @@ -333,7 +321,6 @@ public class SurfaceView extends View // the SurfaceHolder forward, most live wallpapers do it. if (viewRoot != null) { viewRoot.removeWindowStoppedCallback(this); - viewRoot.removeSurfaceChangedCallback(this); } mAttachedToWindow = false; @@ -615,34 +602,21 @@ public class SurfaceView extends View mScreenRect.offset(surfaceInsets.left, surfaceInsets.top); if (creating) { + viewRoot.createBoundsSurface(mSubLayer); + mSurfaceSession = new SurfaceSession(); mDeferredDestroySurfaceControl = mSurfaceControl; updateOpaqueFlag(); - // SurfaceView hierarchy - // ViewRootImpl surface - // - bounds layer (crops all child surfaces to parent surface insets) - // - SurfaceView surface (drawn relative to ViewRootImpl surface) - // - Background color layer (drawn behind all SurfaceView surfaces) - // - // The bounds layer is used to crop the surface view so it does not draw into - // the parent surface inset region. Since there can be multiple surface views - // below or above the parent surface, one option is to create multiple bounds - // layer for each z order. The other option, the one implement is to create - // a single bounds layer and set z order for each child surface relative to the - // parent surface. - // When creating the surface view, we parent it to the bounds layer and then - // set the relative z order. When the parent surface changes, we have to - // make sure to update the relative z via ViewRootImpl.SurfaceChangedCallback. final String name = "SurfaceView - " + viewRoot.getTitle().toString(); - mSurfaceControl = - new SurfaceControl.Builder(mSurfaceSession) - .setName(name) - .setOpaque((mSurfaceFlags & SurfaceControl.OPAQUE) != 0) - .setBufferSize(mSurfaceWidth, mSurfaceHeight) - .setFormat(mFormat) - .setParent(viewRoot.getBoundsLayer()) - .setFlags(mSurfaceFlags) - .build(); + + mSurfaceControl = new SurfaceControl.Builder(mSurfaceSession) + .setName(name) + .setOpaque((mSurfaceFlags & SurfaceControl.OPAQUE) != 0) + .setBufferSize(mSurfaceWidth, mSurfaceHeight) + .setFormat(mFormat) + .setParent(viewRoot.getSurfaceControl()) + .setFlags(mSurfaceFlags) + .build(); mBackgroundControl = new SurfaceControl.Builder(mSurfaceSession) .setName("Background for -" + name) .setOpaque(true) @@ -665,7 +639,7 @@ public class SurfaceView extends View SurfaceControl.openTransaction(); try { - mSurfaceControl.setRelativeLayer(viewRoot.getSurfaceControl(), mSubLayer); + mSurfaceControl.setLayer(mSubLayer); if (mViewVisibility) { mSurfaceControl.show(); |
