Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d3659fa6 authored by wilsonshih's avatar wilsonshih Committed by Wei Sheng Shih
Browse files

Prepare to clean up the drawing snapshot with aspect ratio mismatch

Core won't ask to draw snapshot window if the aspect ratio isn't match.
Add a flag to verify if it is safe to delete.

Flag: com.android.window.flags.draw_snapshot_aspect_ratio_match
Bug: 341020277
Test: presubmit

Change-Id: I3e2b3435ba2ffe60c90c22ed563435e0c1e781d7
parent 7baaa82e
Loading
Loading
Loading
Loading
+9 −7
Original line number Diff line number Diff line
@@ -50,7 +50,6 @@ import android.app.ActivityManager;
import android.app.ActivityThread;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.GraphicBuffer;
import android.graphics.Paint;
import android.graphics.PixelFormat;
@@ -68,6 +67,7 @@ import android.view.WindowManager;
import com.android.internal.R;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.policy.DecorView;
import com.android.window.flags.Flags;

/**
 * Utils class to help draw a snapshot on a surface.
@@ -181,7 +181,8 @@ public class SnapshotDrawerUtils {

            // We consider nearly matched dimensions as there can be rounding errors and the user
            // won't notice very minute differences from scaling one dimension more than the other
            boolean aspectRatioMismatch = !isAspectRatioMatch(mFrame, mSnapshotW, mSnapshotH);
            boolean aspectRatioMismatch = !isAspectRatioMatch(mFrame, mSnapshotW, mSnapshotH)
                    && !Flags.drawSnapshotAspectRatioMatch();

            // Keep a reference to it such that it doesn't get destroyed when finalized.
            SurfaceControl childSurfaceControl = new SurfaceControl.Builder(session)
@@ -382,8 +383,8 @@ public class SnapshotDrawerUtils {
        }
        final SnapshotSurface drawSurface = new SnapshotSurface(
                rootSurface, snapshot, lp.getTitle());

        final WindowManager.LayoutParams attrs = info.topOpaqueWindowLayoutParams;
        final WindowManager.LayoutParams attrs = Flags.drawSnapshotAspectRatioMatch()
                ? info.mainWindowLayoutParams : info.topOpaqueWindowLayoutParams;
        final ActivityManager.RunningTaskInfo runningTaskInfo = info.taskInfo;
        final ActivityManager.TaskDescription taskDescription =
                getOrCreateTaskDescription(runningTaskInfo);
@@ -400,7 +401,8 @@ public class SnapshotDrawerUtils {
    public static WindowManager.LayoutParams createLayoutParameters(StartingWindowInfo info,
            CharSequence title, @WindowManager.LayoutParams.WindowType int windowType,
            int pixelFormat, IBinder token) {
        final WindowManager.LayoutParams attrs = info.topOpaqueWindowLayoutParams;
        final WindowManager.LayoutParams attrs = Flags.drawSnapshotAspectRatioMatch()
                ? info.mainWindowLayoutParams : info.topOpaqueWindowLayoutParams;
        final WindowManager.LayoutParams mainWindowParams = info.mainWindowLayoutParams;
        final InsetsState topWindowInsetsState = info.topOpaqueWindowInsetsState;
        if (attrs == null || mainWindowParams == null || topWindowInsetsState == null) {
@@ -527,7 +529,7 @@ public class SnapshotDrawerUtils {

        void drawStatusBarBackground(Canvas c, @Nullable Rect alreadyDrawnFrame,
                int statusBarHeight) {
            if (statusBarHeight > 0 && Color.alpha(mStatusBarColor) != 0
            if (statusBarHeight > 0 && alpha(mStatusBarColor) != 0
                    && (alreadyDrawnFrame == null || c.getWidth() > alreadyDrawnFrame.right)) {
                final int rightInset = (int) (mSystemBarInsets.right * mScale);
                final int left = alreadyDrawnFrame != null ? alreadyDrawnFrame.right : 0;
@@ -541,7 +543,7 @@ public class SnapshotDrawerUtils {
            getNavigationBarRect(c.getWidth(), c.getHeight(), mSystemBarInsets, navigationBarRect,
                    mScale);
            final boolean visible = isNavigationBarColorViewVisible();
            if (visible && Color.alpha(mNavigationBarColor) != 0
            if (visible && alpha(mNavigationBarColor) != 0
                    && !navigationBarRect.isEmpty()) {
                c.drawRect(navigationBarRect, mNavigationBarPaint);
            }
+11 −0
Original line number Diff line number Diff line
@@ -172,3 +172,14 @@ flag {
    bug: "238206323"
    is_fixed_read_only: true
}

flag {
  name: "draw_snapshot_aspect_ratio_match"
  namespace: "windowing_frontend"
  description: "The aspect ratio should always match when drawing snapshot"
  bug: "341020277"
  is_fixed_read_only: true
  metadata {
    purpose: PURPOSE_BUGFIX
  }
}
 No newline at end of file
+9 −7
Original line number Diff line number Diff line
@@ -3624,6 +3624,7 @@ class Task extends TaskFragment {
        // If the developer has persist a different configuration, we need to override it to the
        // starting window because persisted configuration does not effect to Task.
        info.taskInfo.configuration.setTo(activity.getConfiguration());
        if (!Flags.drawSnapshotAspectRatioMatch()) {
            final ActivityRecord topFullscreenActivity = getTopFullscreenActivity();
            if (topFullscreenActivity != null) {
                final WindowState mainWindow = topFullscreenActivity.findMainWindow(false);
@@ -3633,6 +3634,7 @@ class Task extends TaskFragment {
                    info.topOpaqueWindowLayoutParams = mainWindow.getAttrs();
                }
            }
        }
        return info;
    }