From fef1a1347b7c2f822906c04da8e3092971dd90e1 Mon Sep 17 00:00:00 2001 From: Vadim Caen Date: Mon, 4 Oct 2021 15:33:08 +0200 Subject: [PATCH] Allow a null Rect to be passed as sourceCrop The documenation of SurfaceControl.captureLayers() allows for a null Rect for the sourceCrop, but SurfaceControl.CaptureArgs.Builder#setSourceCrop only allows for NonNull parameter. Test: Builds Fixes: 201993205 Change-Id: I5411630bd787dc7be9d7e253363a030b16fdd9fc --- core/java/android/view/SurfaceControl.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/core/java/android/view/SurfaceControl.java b/core/java/android/view/SurfaceControl.java index 9e5d12223501b..59e6b21184a60 100644 --- a/core/java/android/view/SurfaceControl.java +++ b/core/java/android/view/SurfaceControl.java @@ -817,10 +817,14 @@ public final class SurfaceControl implements Parcelable { /** * The portion of the screen to capture into the buffer. Caller may pass in - * 'new Rect()' if no cropping is desired. + * 'new Rect()' or null if no cropping is desired. */ - public T setSourceCrop(Rect sourceCrop) { - mSourceCrop.set(sourceCrop); + public T setSourceCrop(@Nullable Rect sourceCrop) { + if (sourceCrop == null) { + mSourceCrop.setEmpty(); + } else { + mSourceCrop.set(sourceCrop); + } return getThis(); } @@ -2355,8 +2359,8 @@ public final class SurfaceControl implements Parcelable { * @return Returns a HardwareBuffer that contains the layer capture. * @hide */ - public static ScreenshotHardwareBuffer captureLayers(SurfaceControl layer, Rect sourceCrop, - float frameScale, int format) { + public static ScreenshotHardwareBuffer captureLayers(@NonNull SurfaceControl layer, + @Nullable Rect sourceCrop, float frameScale, int format) { LayerCaptureArgs captureArgs = new LayerCaptureArgs.Builder(layer) .setSourceCrop(sourceCrop) .setFrameScale(frameScale)