Merge changes from topic "screen_decor" into tm-d1-dev am: b4ca20115d

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/19229663

Change-Id: I343f23d9b9a9c305cf0608c3abed1bc6f4731b8a
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Shawn Lin
2022-07-25 03:56:40 +00:00
committed by Automerger Merge Worker
2 changed files with 62 additions and 14 deletions

View File

@@ -3259,10 +3259,11 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
} }
public void setRotationAnimation(ScreenRotationAnimation screenRotationAnimation) { public void setRotationAnimation(ScreenRotationAnimation screenRotationAnimation) {
if (mScreenRotationAnimation != null) { final ScreenRotationAnimation prev = mScreenRotationAnimation;
mScreenRotationAnimation.kill();
}
mScreenRotationAnimation = screenRotationAnimation; mScreenRotationAnimation = screenRotationAnimation;
if (prev != null) {
prev.kill();
}
// Hide the windows which are not significant in rotation animation. So that the windows // Hide the windows which are not significant in rotation animation. So that the windows
// don't need to block the unfreeze time. // don't need to block the unfreeze time.

View File

@@ -40,9 +40,11 @@ import android.graphics.Matrix;
import android.graphics.Point; import android.graphics.Point;
import android.graphics.Rect; import android.graphics.Rect;
import android.hardware.HardwareBuffer; import android.hardware.HardwareBuffer;
import android.os.IBinder;
import android.os.Trace; import android.os.Trace;
import android.util.Slog; import android.util.Slog;
import android.util.proto.ProtoOutputStream; import android.util.proto.ProtoOutputStream;
import android.view.DisplayAddress;
import android.view.DisplayInfo; import android.view.DisplayInfo;
import android.view.Surface; import android.view.Surface;
import android.view.Surface.OutOfResourcesException; import android.view.Surface.OutOfResourcesException;
@@ -165,18 +167,43 @@ class ScreenRotationAnimation {
final SurfaceControl.Transaction t = mService.mTransactionFactory.get(); final SurfaceControl.Transaction t = mService.mTransactionFactory.get();
try { try {
SurfaceControl.LayerCaptureArgs.Builder builder = final SurfaceControl.ScreenshotHardwareBuffer screenshotBuffer;
new SurfaceControl.LayerCaptureArgs.Builder(displayContent.getSurfaceControl()) if (isSizeChanged) {
final DisplayAddress address = displayInfo.address;
if (!(address instanceof DisplayAddress.Physical)) {
Slog.e(TAG, "Display does not have a physical address: " + displayId);
return;
}
final DisplayAddress.Physical physicalAddress =
(DisplayAddress.Physical) address;
final IBinder displayToken = SurfaceControl.getPhysicalDisplayToken(
physicalAddress.getPhysicalDisplayId());
if (displayToken == null) {
Slog.e(TAG, "Display token is null.");
return;
}
// Temporarily not skip screenshot for the rounded corner overlays and screenshot
// the whole display to include the rounded corner overlays.
setSkipScreenshotForRoundedCornerOverlays(false, t);
mRoundedCornerOverlay = displayContent.findRoundedCornerOverlays();
final SurfaceControl.DisplayCaptureArgs captureArgs =
new SurfaceControl.DisplayCaptureArgs.Builder(displayToken)
.setSourceCrop(new Rect(0, 0, width, height))
.setAllowProtected(true)
.setCaptureSecureLayers(true)
.build();
screenshotBuffer = SurfaceControl.captureDisplay(captureArgs);
} else {
SurfaceControl.LayerCaptureArgs captureArgs =
new SurfaceControl.LayerCaptureArgs.Builder(
displayContent.getSurfaceControl())
.setCaptureSecureLayers(true) .setCaptureSecureLayers(true)
.setAllowProtected(true) .setAllowProtected(true)
.setSourceCrop(new Rect(0, 0, width, height)); .setSourceCrop(new Rect(0, 0, width, height))
.build();
if (isSizeChanged) { screenshotBuffer = SurfaceControl.captureLayers(captureArgs);
mRoundedCornerOverlay = displayContent.findRoundedCornerOverlays();
} }
SurfaceControl.ScreenshotHardwareBuffer screenshotBuffer =
SurfaceControl.captureLayers(builder.build());
if (screenshotBuffer == null) { if (screenshotBuffer == null) {
Slog.w(TAG, "Unable to take screenshot of display " + displayId); Slog.w(TAG, "Unable to take screenshot of display " + displayId);
return; return;
@@ -275,6 +302,21 @@ class ScreenRotationAnimation {
t.apply(); t.apply();
} }
void setSkipScreenshotForRoundedCornerOverlays(
boolean skipScreenshot, SurfaceControl.Transaction t) {
mDisplayContent.forAllWindows(w -> {
if (!w.mToken.mRoundedCornerOverlay || !w.isVisible() || !w.mWinAnimator.hasSurface()) {
return;
}
t.setSkipScreenshot(w.mWinAnimator.mSurfaceController.mSurfaceControl, skipScreenshot);
}, false);
if (!skipScreenshot) {
// Use sync apply to apply the change immediately, so that the next
// SC.captureDisplay can capture the screen decor layers.
t.apply(true /* sync */);
}
}
public void dumpDebug(ProtoOutputStream proto, long fieldId) { public void dumpDebug(ProtoOutputStream proto, long fieldId) {
final long token = proto.start(fieldId); final long token = proto.start(fieldId);
proto.write(STARTED, mStarted); proto.write(STARTED, mStarted);
@@ -483,12 +525,17 @@ class ScreenRotationAnimation {
} }
mBackColorSurface = null; mBackColorSurface = null;
} }
if (mRoundedCornerOverlay != null) { if (mRoundedCornerOverlay != null) {
if (mDisplayContent.getRotationAnimation() == null
|| mDisplayContent.getRotationAnimation() == this) {
setSkipScreenshotForRoundedCornerOverlays(true, t);
for (SurfaceControl sc : mRoundedCornerOverlay) { for (SurfaceControl sc : mRoundedCornerOverlay) {
if (sc.isValid()) { if (sc.isValid()) {
t.show(sc); t.show(sc);
} }
} }
}
mRoundedCornerOverlay = null; mRoundedCornerOverlay = null;
} }
t.apply(); t.apply();