From efc42e2badd2be4e3404cc16619dd3d85d37a7e7 Mon Sep 17 00:00:00 2001 From: Vishnu Nair Date: Tue, 3 Dec 2019 17:36:12 -0800 Subject: Fix SurfaceControl#captureLayers when the layer is boundless - Return an error if the client tries to screenshot a boundless layer without specifying a crop. Otherwise the client will get a screenshot of 0x0. - Use the crop in addition to the buffer size when determining the bounds of the captured layer. This will enable us to capture container layers and color layers that have a crop specified. Fixes: 141326137 Test: atest SurfaceFlinger_test Test: go/wm-smoke Change-Id: Ibba4c01ad2d6739caee0d85b8d9c2d236fbf0ce0 --- services/surfaceflinger/SurfaceFlinger.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'services/surfaceflinger/SurfaceFlinger.cpp') diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp index c555f7985f..8b04b657cf 100644 --- a/services/surfaceflinger/SurfaceFlinger.cpp +++ b/services/surfaceflinger/SurfaceFlinger.cpp @@ -5067,14 +5067,21 @@ status_t SurfaceFlinger::captureLayers( return PERMISSION_DENIED; } + Rect parentSourceBounds = parent->getCroppedBufferSize(parent->getCurrentState()); if (sourceCrop.width() <= 0) { crop.left = 0; - crop.right = parent->getBufferSize(parent->getCurrentState()).getWidth(); + crop.right = parentSourceBounds.getWidth(); } if (sourceCrop.height() <= 0) { crop.top = 0; - crop.bottom = parent->getBufferSize(parent->getCurrentState()).getHeight(); + crop.bottom = parentSourceBounds.getHeight(); + } + + if (crop.isEmpty() || frameScale <= 0.0f) { + // Error out if the layer has no source bounds (i.e. they are boundless) and a source + // crop was not specified, or an invalid frame scale was provided. + return BAD_VALUE; } reqWidth = crop.width() * frameScale; reqHeight = crop.height() * frameScale; -- cgit v1.2.3-59-g8ed1b