Loading apct-tests/perftests/windowmanager/src/android/wm/RelayoutPerfTest.java +1 −4 Original line number Diff line number Diff line Loading @@ -20,7 +20,6 @@ import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentat import android.app.Activity; import android.content.Context; import android.graphics.Point; import android.os.RemoteException; import android.perftests.utils.BenchmarkState; import android.perftests.utils.PerfStatusReporter; Loading Loading @@ -133,7 +132,6 @@ public class RelayoutPerfTest extends WindowManagerPerfTestBase final WindowManager.LayoutParams mParams; final int mWidth; final int mHeight; final Point mOutSurfaceSize = new Point(); final SurfaceControl mOutSurfaceControl; final IntSupplier mViewVisibility; Loading @@ -156,8 +154,7 @@ public class RelayoutPerfTest extends WindowManagerPerfTestBase while (state.keepRunning()) { session.relayout(mWindow, mParams, mWidth, mHeight, mViewVisibility.getAsInt(), mFlags, mFrameNumber, mOutFrames, mOutMergedConfiguration, mOutSurfaceControl, mOutInsetsState, mOutControls, mOutSurfaceSize); mOutMergedConfiguration, mOutSurfaceControl, mOutInsetsState, mOutControls); } } } Loading core/java/android/service/wallpaper/WallpaperService.java +29 −6 Original line number Diff line number Diff line Loading @@ -87,6 +87,7 @@ import android.view.SurfaceHolder; import android.view.View; import android.view.ViewGroup; import android.view.WindowInsets; import android.view.WindowLayout; import android.view.WindowManager; import android.view.WindowManagerGlobal; import android.window.ClientWindowFrames; Loading Loading @@ -389,8 +390,9 @@ public abstract class WallpaperService extends Service { public void resized(ClientWindowFrames frames, boolean reportDraw, MergedConfiguration mergedConfiguration, boolean forceLayout, boolean alwaysConsumeSystemBars, int displayId) { Message msg = mCaller.obtainMessageI(MSG_WINDOW_RESIZED, reportDraw ? 1 : 0); Message msg = mCaller.obtainMessageIO(MSG_WINDOW_RESIZED, reportDraw ? 1 : 0, mergedConfiguration); mCaller.sendMessage(msg); } Loading Loading @@ -1028,6 +1030,10 @@ public abstract class WallpaperService extends Service { } } private void updateConfiguration(MergedConfiguration mergedConfiguration) { mMergedConfiguration.setTo(mergedConfiguration); } void updateSurface(boolean forceRelayout, boolean forceReport, boolean redrawNeeded) { if (mDestroyed) { Log.w(TAG, "Ignoring updateSurface due to destroyed"); Loading Loading @@ -1066,8 +1072,6 @@ public abstract class WallpaperService extends Service { mLayout.x = 0; mLayout.y = 0; mLayout.width = myWidth; mLayout.height = myHeight; mLayout.format = mFormat; mCurWindowFlags = mWindowFlags; Loading @@ -1076,6 +1080,23 @@ public abstract class WallpaperService extends Service { | WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE; final Configuration config = mMergedConfiguration.getMergedConfiguration(); final Rect maxBounds = config.windowConfiguration.getMaxBounds(); if (myWidth == ViewGroup.LayoutParams.MATCH_PARENT && myHeight == ViewGroup.LayoutParams.MATCH_PARENT) { mLayout.width = myWidth; mLayout.height = myHeight; mLayout.flags &= ~WindowManager.LayoutParams.FLAG_SCALED; } else { final float layoutScale = Math.max( maxBounds.width() / (float) myWidth, maxBounds.height() / (float) myHeight); mLayout.width = (int) (myWidth * layoutScale + .5f); mLayout.height = (int) (myHeight * layoutScale + .5f); mLayout.flags |= WindowManager.LayoutParams.FLAG_SCALED; } mCurWindowPrivateFlags = mWindowPrivateFlags; mLayout.privateFlags = mWindowPrivateFlags; Loading Loading @@ -1122,11 +1143,13 @@ public abstract class WallpaperService extends Service { final int relayoutResult = mSession.relayout( mWindow, mLayout, mWidth, mHeight, View.VISIBLE, 0, -1, mWinFrames, mMergedConfiguration, mSurfaceControl, mInsetsState, mTempControls, mSurfaceSize); mInsetsState, mTempControls); final int transformHint = SurfaceControl.rotationToBufferTransform( (mDisplayInstallOrientation + mDisplay.getRotation()) % 4); mSurfaceControl.setTransformHint(transformHint); WindowLayout.computeSurfaceSize(mLayout, maxBounds, mWidth, mHeight, mWinFrames.frame, false /* dragResizing */, mSurfaceSize); if (mSurfaceControl.isValid()) { if (mBbqSurfaceControl == null) { Loading Loading @@ -1164,7 +1187,6 @@ public abstract class WallpaperService extends Service { int h = mWinFrames.frame.height(); final DisplayCutout rawCutout = mInsetsState.getDisplayCutout(); final Configuration config = getResources().getConfiguration(); final Rect visibleFrame = new Rect(mWinFrames.frame); visibleFrame.intersect(mInsetsState.getDisplayFrame()); WindowInsets windowInsets = mInsetsState.calculateInsets(visibleFrame, Loading Loading @@ -2321,6 +2343,7 @@ public abstract class WallpaperService extends Service { } break; case MSG_WINDOW_RESIZED: { final boolean reportDraw = message.arg1 != 0; mEngine.updateConfiguration(((MergedConfiguration) message.obj)); mEngine.updateSurface(true, false, reportDraw); mEngine.doOffsetsChanged(true); mEngine.scaleAndCropScreenshot(); Loading core/java/android/view/IWindowSession.aidl +1 −3 Original line number Diff line number Diff line Loading @@ -97,7 +97,6 @@ interface IWindowSession { * since it was last displayed. * @param outSurface Object in which is placed the new display surface. * @param insetsState The current insets state in the system. * @param outSurfaceSize The width and height of the surface control * * @return int Result flags: {@link WindowManagerGlobal#RELAYOUT_SHOW_FOCUS}, * {@link WindowManagerGlobal#RELAYOUT_FIRST_TIME}. Loading @@ -106,8 +105,7 @@ interface IWindowSession { int requestedWidth, int requestedHeight, int viewVisibility, int flags, long frameNumber, out ClientWindowFrames outFrames, out MergedConfiguration outMergedConfiguration, out SurfaceControl outSurfaceControl, out InsetsState insetsState, out InsetsSourceControl[] activeControls, out Point outSurfaceSize); out InsetsState insetsState, out InsetsSourceControl[] activeControls); /* * Notify the window manager that an application is relaunching and Loading core/java/android/view/ViewRootImpl.java +15 −5 Original line number Diff line number Diff line Loading @@ -83,6 +83,8 @@ import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR_ADDITIONAL import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_ALERT; import static android.view.WindowManager.LayoutParams.TYPE_TOAST; import static android.view.WindowManager.LayoutParams.TYPE_VOLUME_OVERLAY; import static android.view.WindowManagerGlobal.RELAYOUT_RES_DRAG_RESIZING_DOCKED; import static android.view.WindowManagerGlobal.RELAYOUT_RES_DRAG_RESIZING_FREEFORM; import static android.view.WindowManagerGlobal.RELAYOUT_RES_SURFACE_CHANGED; import static android.view.inputmethod.InputMethodEditorTraceProto.InputMethodClientsTraceProto.ClientSideProto.IME_FOCUS_CONTROLLER; import static android.view.inputmethod.InputMethodEditorTraceProto.InputMethodClientsTraceProto.ClientSideProto.INSETS_CONTROLLER; Loading Loading @@ -2868,9 +2870,9 @@ public final class ViewRootImpl implements ViewParent, } relayoutResult = relayoutWindow(params, viewVisibility, insetsPending); final boolean freeformResizing = (relayoutResult & WindowManagerGlobal.RELAYOUT_RES_DRAG_RESIZING_FREEFORM) != 0; & RELAYOUT_RES_DRAG_RESIZING_FREEFORM) != 0; final boolean dockedResizing = (relayoutResult & WindowManagerGlobal.RELAYOUT_RES_DRAG_RESIZING_DOCKED) != 0; & RELAYOUT_RES_DRAG_RESIZING_DOCKED) != 0; final boolean dragResizing = freeformResizing || dockedResizing; if ((relayoutResult & WindowManagerGlobal.RELAYOUT_RES_BLAST_SYNC) != 0) { if (DEBUG_BLAST) { Loading Loading @@ -7928,22 +7930,30 @@ public final class ViewRootImpl implements ViewParent, } } final int requestedWidth = (int) (mView.getMeasuredWidth() * appScale + 0.5f); final int requestedHeight = (int) (mView.getMeasuredHeight() * appScale + 0.5f); long frameNumber = -1; if (mSurface.isValid()) { frameNumber = mSurface.getNextFrameNumber(); } int relayoutResult = mWindowSession.relayout(mWindow, params, (int) (mView.getMeasuredWidth() * appScale + 0.5f), (int) (mView.getMeasuredHeight() * appScale + 0.5f), viewVisibility, requestedWidth, requestedHeight, viewVisibility, insetsPending ? WindowManagerGlobal.RELAYOUT_INSETS_PENDING : 0, frameNumber, mTmpFrames, mPendingMergedConfiguration, mSurfaceControl, mTempInsets, mTempControls, mSurfaceSize); mTempControls); final int transformHint = SurfaceControl.rotationToBufferTransform( (mDisplayInstallOrientation + mDisplay.getRotation()) % 4); mSurfaceControl.setTransformHint(transformHint); final WindowConfiguration winConfig = getConfiguration().windowConfiguration; final boolean dragResizing = (relayoutResult & (RELAYOUT_RES_DRAG_RESIZING_DOCKED | RELAYOUT_RES_DRAG_RESIZING_FREEFORM)) != 0; WindowLayout.computeSurfaceSize(mWindowAttributes, winConfig.getMaxBounds(), requestedWidth, requestedHeight, mTmpFrames.frame, dragResizing, mSurfaceSize); if (mAttachInfo.mContentCaptureManager != null) { MainContentCaptureSession mainSession = mAttachInfo.mContentCaptureManager .getMainContentCaptureSession(); Loading core/java/android/view/WindowLayout.java +43 −0 Original line number Diff line number Diff line Loading @@ -36,6 +36,7 @@ import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_ERROR; import android.app.WindowConfiguration; import android.app.WindowConfiguration.WindowingMode; import android.graphics.Insets; import android.graphics.Point; import android.graphics.Rect; import android.util.Log; Loading Loading @@ -258,6 +259,7 @@ public class WindowLayout { + " outFrame=" + outFrame.toShortString() + " outParentFrame=" + outParentFrame.toShortString() + " outDisplayFrame=" + outDisplayFrame.toShortString() + " windowBounds=" + windowBounds.toShortString() + " attachedWindowFrame=" + (attachedWindowFrame != null ? attachedWindowFrame.toShortString() : "null") Loading @@ -272,4 +274,45 @@ public class WindowLayout { return clippedByDisplayCutout; } public static void computeSurfaceSize(WindowManager.LayoutParams attrs, Rect maxBounds, int requestedWidth, int requestedHeight, Rect winFrame, boolean dragResizing, Point outSurfaceSize) { int width; int height; if ((attrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0) { // For a scaled surface, we always want the requested size. width = requestedWidth; height = requestedHeight; } else { // When we're doing a drag-resizing, request a surface that's fullscreen size, // so that we don't need to reallocate during the process. This also prevents // buffer drops due to size mismatch. if (dragResizing) { // The maxBounds should match the display size which applies fixed-rotation // transformation if there is any. width = maxBounds.width(); height = maxBounds.height(); } else { width = winFrame.width(); height = winFrame.height(); } } // This doesn't necessarily mean that there is an error in the system. The sizes might be // incorrect, because it is before the first layout or draw. if (width < 1) { width = 1; } if (height < 1) { height = 1; } // Adjust for surface insets. final Rect surfaceInsets = attrs.surfaceInsets; width += surfaceInsets.left + surfaceInsets.right; height += surfaceInsets.top + surfaceInsets.bottom; outSurfaceSize.set(width, height); } } Loading
apct-tests/perftests/windowmanager/src/android/wm/RelayoutPerfTest.java +1 −4 Original line number Diff line number Diff line Loading @@ -20,7 +20,6 @@ import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentat import android.app.Activity; import android.content.Context; import android.graphics.Point; import android.os.RemoteException; import android.perftests.utils.BenchmarkState; import android.perftests.utils.PerfStatusReporter; Loading Loading @@ -133,7 +132,6 @@ public class RelayoutPerfTest extends WindowManagerPerfTestBase final WindowManager.LayoutParams mParams; final int mWidth; final int mHeight; final Point mOutSurfaceSize = new Point(); final SurfaceControl mOutSurfaceControl; final IntSupplier mViewVisibility; Loading @@ -156,8 +154,7 @@ public class RelayoutPerfTest extends WindowManagerPerfTestBase while (state.keepRunning()) { session.relayout(mWindow, mParams, mWidth, mHeight, mViewVisibility.getAsInt(), mFlags, mFrameNumber, mOutFrames, mOutMergedConfiguration, mOutSurfaceControl, mOutInsetsState, mOutControls, mOutSurfaceSize); mOutMergedConfiguration, mOutSurfaceControl, mOutInsetsState, mOutControls); } } } Loading
core/java/android/service/wallpaper/WallpaperService.java +29 −6 Original line number Diff line number Diff line Loading @@ -87,6 +87,7 @@ import android.view.SurfaceHolder; import android.view.View; import android.view.ViewGroup; import android.view.WindowInsets; import android.view.WindowLayout; import android.view.WindowManager; import android.view.WindowManagerGlobal; import android.window.ClientWindowFrames; Loading Loading @@ -389,8 +390,9 @@ public abstract class WallpaperService extends Service { public void resized(ClientWindowFrames frames, boolean reportDraw, MergedConfiguration mergedConfiguration, boolean forceLayout, boolean alwaysConsumeSystemBars, int displayId) { Message msg = mCaller.obtainMessageI(MSG_WINDOW_RESIZED, reportDraw ? 1 : 0); Message msg = mCaller.obtainMessageIO(MSG_WINDOW_RESIZED, reportDraw ? 1 : 0, mergedConfiguration); mCaller.sendMessage(msg); } Loading Loading @@ -1028,6 +1030,10 @@ public abstract class WallpaperService extends Service { } } private void updateConfiguration(MergedConfiguration mergedConfiguration) { mMergedConfiguration.setTo(mergedConfiguration); } void updateSurface(boolean forceRelayout, boolean forceReport, boolean redrawNeeded) { if (mDestroyed) { Log.w(TAG, "Ignoring updateSurface due to destroyed"); Loading Loading @@ -1066,8 +1072,6 @@ public abstract class WallpaperService extends Service { mLayout.x = 0; mLayout.y = 0; mLayout.width = myWidth; mLayout.height = myHeight; mLayout.format = mFormat; mCurWindowFlags = mWindowFlags; Loading @@ -1076,6 +1080,23 @@ public abstract class WallpaperService extends Service { | WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE; final Configuration config = mMergedConfiguration.getMergedConfiguration(); final Rect maxBounds = config.windowConfiguration.getMaxBounds(); if (myWidth == ViewGroup.LayoutParams.MATCH_PARENT && myHeight == ViewGroup.LayoutParams.MATCH_PARENT) { mLayout.width = myWidth; mLayout.height = myHeight; mLayout.flags &= ~WindowManager.LayoutParams.FLAG_SCALED; } else { final float layoutScale = Math.max( maxBounds.width() / (float) myWidth, maxBounds.height() / (float) myHeight); mLayout.width = (int) (myWidth * layoutScale + .5f); mLayout.height = (int) (myHeight * layoutScale + .5f); mLayout.flags |= WindowManager.LayoutParams.FLAG_SCALED; } mCurWindowPrivateFlags = mWindowPrivateFlags; mLayout.privateFlags = mWindowPrivateFlags; Loading Loading @@ -1122,11 +1143,13 @@ public abstract class WallpaperService extends Service { final int relayoutResult = mSession.relayout( mWindow, mLayout, mWidth, mHeight, View.VISIBLE, 0, -1, mWinFrames, mMergedConfiguration, mSurfaceControl, mInsetsState, mTempControls, mSurfaceSize); mInsetsState, mTempControls); final int transformHint = SurfaceControl.rotationToBufferTransform( (mDisplayInstallOrientation + mDisplay.getRotation()) % 4); mSurfaceControl.setTransformHint(transformHint); WindowLayout.computeSurfaceSize(mLayout, maxBounds, mWidth, mHeight, mWinFrames.frame, false /* dragResizing */, mSurfaceSize); if (mSurfaceControl.isValid()) { if (mBbqSurfaceControl == null) { Loading Loading @@ -1164,7 +1187,6 @@ public abstract class WallpaperService extends Service { int h = mWinFrames.frame.height(); final DisplayCutout rawCutout = mInsetsState.getDisplayCutout(); final Configuration config = getResources().getConfiguration(); final Rect visibleFrame = new Rect(mWinFrames.frame); visibleFrame.intersect(mInsetsState.getDisplayFrame()); WindowInsets windowInsets = mInsetsState.calculateInsets(visibleFrame, Loading Loading @@ -2321,6 +2343,7 @@ public abstract class WallpaperService extends Service { } break; case MSG_WINDOW_RESIZED: { final boolean reportDraw = message.arg1 != 0; mEngine.updateConfiguration(((MergedConfiguration) message.obj)); mEngine.updateSurface(true, false, reportDraw); mEngine.doOffsetsChanged(true); mEngine.scaleAndCropScreenshot(); Loading
core/java/android/view/IWindowSession.aidl +1 −3 Original line number Diff line number Diff line Loading @@ -97,7 +97,6 @@ interface IWindowSession { * since it was last displayed. * @param outSurface Object in which is placed the new display surface. * @param insetsState The current insets state in the system. * @param outSurfaceSize The width and height of the surface control * * @return int Result flags: {@link WindowManagerGlobal#RELAYOUT_SHOW_FOCUS}, * {@link WindowManagerGlobal#RELAYOUT_FIRST_TIME}. Loading @@ -106,8 +105,7 @@ interface IWindowSession { int requestedWidth, int requestedHeight, int viewVisibility, int flags, long frameNumber, out ClientWindowFrames outFrames, out MergedConfiguration outMergedConfiguration, out SurfaceControl outSurfaceControl, out InsetsState insetsState, out InsetsSourceControl[] activeControls, out Point outSurfaceSize); out InsetsState insetsState, out InsetsSourceControl[] activeControls); /* * Notify the window manager that an application is relaunching and Loading
core/java/android/view/ViewRootImpl.java +15 −5 Original line number Diff line number Diff line Loading @@ -83,6 +83,8 @@ import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR_ADDITIONAL import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_ALERT; import static android.view.WindowManager.LayoutParams.TYPE_TOAST; import static android.view.WindowManager.LayoutParams.TYPE_VOLUME_OVERLAY; import static android.view.WindowManagerGlobal.RELAYOUT_RES_DRAG_RESIZING_DOCKED; import static android.view.WindowManagerGlobal.RELAYOUT_RES_DRAG_RESIZING_FREEFORM; import static android.view.WindowManagerGlobal.RELAYOUT_RES_SURFACE_CHANGED; import static android.view.inputmethod.InputMethodEditorTraceProto.InputMethodClientsTraceProto.ClientSideProto.IME_FOCUS_CONTROLLER; import static android.view.inputmethod.InputMethodEditorTraceProto.InputMethodClientsTraceProto.ClientSideProto.INSETS_CONTROLLER; Loading Loading @@ -2868,9 +2870,9 @@ public final class ViewRootImpl implements ViewParent, } relayoutResult = relayoutWindow(params, viewVisibility, insetsPending); final boolean freeformResizing = (relayoutResult & WindowManagerGlobal.RELAYOUT_RES_DRAG_RESIZING_FREEFORM) != 0; & RELAYOUT_RES_DRAG_RESIZING_FREEFORM) != 0; final boolean dockedResizing = (relayoutResult & WindowManagerGlobal.RELAYOUT_RES_DRAG_RESIZING_DOCKED) != 0; & RELAYOUT_RES_DRAG_RESIZING_DOCKED) != 0; final boolean dragResizing = freeformResizing || dockedResizing; if ((relayoutResult & WindowManagerGlobal.RELAYOUT_RES_BLAST_SYNC) != 0) { if (DEBUG_BLAST) { Loading Loading @@ -7928,22 +7930,30 @@ public final class ViewRootImpl implements ViewParent, } } final int requestedWidth = (int) (mView.getMeasuredWidth() * appScale + 0.5f); final int requestedHeight = (int) (mView.getMeasuredHeight() * appScale + 0.5f); long frameNumber = -1; if (mSurface.isValid()) { frameNumber = mSurface.getNextFrameNumber(); } int relayoutResult = mWindowSession.relayout(mWindow, params, (int) (mView.getMeasuredWidth() * appScale + 0.5f), (int) (mView.getMeasuredHeight() * appScale + 0.5f), viewVisibility, requestedWidth, requestedHeight, viewVisibility, insetsPending ? WindowManagerGlobal.RELAYOUT_INSETS_PENDING : 0, frameNumber, mTmpFrames, mPendingMergedConfiguration, mSurfaceControl, mTempInsets, mTempControls, mSurfaceSize); mTempControls); final int transformHint = SurfaceControl.rotationToBufferTransform( (mDisplayInstallOrientation + mDisplay.getRotation()) % 4); mSurfaceControl.setTransformHint(transformHint); final WindowConfiguration winConfig = getConfiguration().windowConfiguration; final boolean dragResizing = (relayoutResult & (RELAYOUT_RES_DRAG_RESIZING_DOCKED | RELAYOUT_RES_DRAG_RESIZING_FREEFORM)) != 0; WindowLayout.computeSurfaceSize(mWindowAttributes, winConfig.getMaxBounds(), requestedWidth, requestedHeight, mTmpFrames.frame, dragResizing, mSurfaceSize); if (mAttachInfo.mContentCaptureManager != null) { MainContentCaptureSession mainSession = mAttachInfo.mContentCaptureManager .getMainContentCaptureSession(); Loading
core/java/android/view/WindowLayout.java +43 −0 Original line number Diff line number Diff line Loading @@ -36,6 +36,7 @@ import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_ERROR; import android.app.WindowConfiguration; import android.app.WindowConfiguration.WindowingMode; import android.graphics.Insets; import android.graphics.Point; import android.graphics.Rect; import android.util.Log; Loading Loading @@ -258,6 +259,7 @@ public class WindowLayout { + " outFrame=" + outFrame.toShortString() + " outParentFrame=" + outParentFrame.toShortString() + " outDisplayFrame=" + outDisplayFrame.toShortString() + " windowBounds=" + windowBounds.toShortString() + " attachedWindowFrame=" + (attachedWindowFrame != null ? attachedWindowFrame.toShortString() : "null") Loading @@ -272,4 +274,45 @@ public class WindowLayout { return clippedByDisplayCutout; } public static void computeSurfaceSize(WindowManager.LayoutParams attrs, Rect maxBounds, int requestedWidth, int requestedHeight, Rect winFrame, boolean dragResizing, Point outSurfaceSize) { int width; int height; if ((attrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0) { // For a scaled surface, we always want the requested size. width = requestedWidth; height = requestedHeight; } else { // When we're doing a drag-resizing, request a surface that's fullscreen size, // so that we don't need to reallocate during the process. This also prevents // buffer drops due to size mismatch. if (dragResizing) { // The maxBounds should match the display size which applies fixed-rotation // transformation if there is any. width = maxBounds.width(); height = maxBounds.height(); } else { width = winFrame.width(); height = winFrame.height(); } } // This doesn't necessarily mean that there is an error in the system. The sizes might be // incorrect, because it is before the first layout or draw. if (width < 1) { width = 1; } if (height < 1) { height = 1; } // Adjust for surface insets. final Rect surfaceInsets = attrs.surfaceInsets; width += surfaceInsets.left + surfaceInsets.right; height += surfaceInsets.top + surfaceInsets.bottom; outSurfaceSize.set(width, height); } }