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
diff --git a/services/surfaceflinger/Layer.h b/services/surfaceflinger/Layer.h
index 7abcd0f..adf3075 100644
--- a/services/surfaceflinger/Layer.h
+++ b/services/surfaceflinger/Layer.h
@@ -699,6 +699,14 @@
 
     Region debugGetVisibleRegionOnDefaultDisplay() const;
 
+    /**
+     * Returns the cropped buffer size or the layer crop if the layer has no buffer. Return
+     * INVALID_RECT if the layer has no buffer and no crop.
+     * A layer with an invalid buffer size and no crop is considered to be boundless. The layer
+     * bounds are constrained by its parent bounds.
+     */
+    Rect getCroppedBufferSize(const Layer::State& s) const;
+
 protected:
     // constant
     sp<SurfaceFlinger> mFlinger;
@@ -907,13 +915,6 @@
                                        const LayerVector::Visitor& visitor);
     LayerVector makeChildrenTraversalList(LayerVector::StateSet stateSet,
                                           const std::vector<Layer*>& layersInTree);
-    /**
-     * Returns the cropped buffer size or the layer crop if the layer has no buffer. Return
-     * INVALID_RECT if the layer has no buffer and no crop.
-     * A layer with an invalid buffer size and no crop is considered to be boundless. The layer
-     * bounds are constrained by its parent bounds.
-     */
-    Rect getCroppedBufferSize(const Layer::State& s) const;
 
     // Cached properties computed from drawing state
     // Effective transform taking into account parent transforms and any parent scaling.