chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Peiyong Lin | 0e003c9 | 2018-09-17 11:09:51 -0700 | [diff] [blame] | 3 | #include <ui/GraphicTypes.h> |
Peiyong Lin | efefaac | 2018-08-17 12:27:51 -0700 | [diff] [blame] | 4 | #include <ui/Transform.h> |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 5 | |
Robert Carr | 578038f | 2018-03-09 12:25:24 -0800 | [diff] [blame] | 6 | #include <functional> |
Robert Carr | 12a3b9b | 2022-03-10 09:55:29 -0800 | [diff] [blame^] | 7 | #include "Layer.h" |
Robert Carr | 578038f | 2018-03-09 12:25:24 -0800 | [diff] [blame] | 8 | |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 9 | namespace android { |
| 10 | |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 11 | class DisplayDevice; |
| 12 | |
Chia-I Wu | b68fac7 | 2018-08-23 12:05:27 -0700 | [diff] [blame] | 13 | // RenderArea describes a rectangular area that layers can be rendered to. |
| 14 | // |
| 15 | // There is a logical render area and a physical render area. When a layer is |
| 16 | // rendered to the render area, it is first transformed and clipped to the logical |
| 17 | // render area. The transformed and clipped layer is then projected onto the |
| 18 | // physical render area. |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 19 | class RenderArea { |
| 20 | public: |
Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 21 | using RotationFlags = ui::Transform::RotationFlags; |
| 22 | |
chaviw | 50da504 | 2018-04-09 13:49:37 -0700 | [diff] [blame] | 23 | enum class CaptureFill {CLEAR, OPAQUE}; |
| 24 | |
| 25 | static float getCaptureFillValue(CaptureFill captureFill); |
| 26 | |
Marin Shalamanov | 1c43429 | 2020-06-12 01:47:29 +0200 | [diff] [blame] | 27 | RenderArea(ui::Size reqSize, CaptureFill captureFill, ui::Dataspace reqDataSpace, |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 28 | const Rect& layerStackRect, bool allowSecureLayers = false, |
chaviw | 70cb6a4 | 2020-07-30 13:57:36 -0700 | [diff] [blame] | 29 | RotationFlags rotation = ui::Transform::ROT_0) |
| 30 | : mAllowSecureLayers(allowSecureLayers), |
| 31 | mReqSize(reqSize), |
Peiyong Lin | 0e003c9 | 2018-09-17 11:09:51 -0700 | [diff] [blame] | 32 | mReqDataSpace(reqDataSpace), |
Chia-I Wu | c80dcbb | 2018-08-24 15:34:02 -0700 | [diff] [blame] | 33 | mCaptureFill(captureFill), |
Vishnu Nair | 3a7346c | 2019-12-04 08:09:09 -0800 | [diff] [blame] | 34 | mRotationFlags(rotation), |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 35 | mLayerStackSpaceRect(layerStackRect) {} |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 36 | |
| 37 | virtual ~RenderArea() = default; |
| 38 | |
Chia-I Wu | b68fac7 | 2018-08-23 12:05:27 -0700 | [diff] [blame] | 39 | // Invoke drawLayers to render layers into the render area. |
Robert Carr | 578038f | 2018-03-09 12:25:24 -0800 | [diff] [blame] | 40 | virtual void render(std::function<void()> drawLayers) { drawLayers(); } |
| 41 | |
Chia-I Wu | b68fac7 | 2018-08-23 12:05:27 -0700 | [diff] [blame] | 42 | // Returns true if the render area is secure. A secure layer should be |
| 43 | // blacked out / skipped when rendered to an insecure render area. |
| 44 | virtual bool isSecure() const = 0; |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 45 | |
Chia-I Wu | b68fac7 | 2018-08-23 12:05:27 -0700 | [diff] [blame] | 46 | // Returns true if the otherwise disabled layer filtering should be |
| 47 | // enabled when rendering to this render area. |
| 48 | virtual bool needsFiltering() const = 0; |
| 49 | |
| 50 | // Returns the transform to be applied on layers to transform them into |
| 51 | // the logical render area. |
| 52 | virtual const ui::Transform& getTransform() const = 0; |
| 53 | |
| 54 | // Returns the size of the logical render area. Layers are clipped to the |
| 55 | // logical render area. |
| 56 | virtual int getWidth() const = 0; |
| 57 | virtual int getHeight() const = 0; |
| 58 | virtual Rect getBounds() const = 0; |
| 59 | |
| 60 | // Returns the source crop of the render area. The source crop defines |
| 61 | // how layers are projected from the logical render area onto the physical |
| 62 | // render area. It can be larger than the logical render area. It can |
| 63 | // also be optionally rotated. |
| 64 | // |
Alec Mouri | 5a6d857 | 2020-03-23 23:56:15 -0700 | [diff] [blame] | 65 | // The source crop is specified in layer space (when rendering a layer and |
| 66 | // its children), or in layer-stack space (when rendering all layers visible |
| 67 | // on the display). |
Chia-I Wu | b68fac7 | 2018-08-23 12:05:27 -0700 | [diff] [blame] | 68 | virtual Rect getSourceCrop() const = 0; |
| 69 | |
| 70 | // Returns the rotation of the source crop and the layers. |
Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 71 | RotationFlags getRotationFlags() const { return mRotationFlags; } |
Chia-I Wu | b68fac7 | 2018-08-23 12:05:27 -0700 | [diff] [blame] | 72 | |
| 73 | // Returns the size of the physical render area. |
Marin Shalamanov | 1c43429 | 2020-06-12 01:47:29 +0200 | [diff] [blame] | 74 | int getReqWidth() const { return mReqSize.width; } |
| 75 | int getReqHeight() const { return mReqSize.height; } |
Chia-I Wu | b68fac7 | 2018-08-23 12:05:27 -0700 | [diff] [blame] | 76 | |
Peiyong Lin | 0e003c9 | 2018-09-17 11:09:51 -0700 | [diff] [blame] | 77 | // Returns the composition data space of the render area. |
| 78 | ui::Dataspace getReqDataSpace() const { return mReqDataSpace; } |
| 79 | |
Chia-I Wu | b68fac7 | 2018-08-23 12:05:27 -0700 | [diff] [blame] | 80 | // Returns the fill color of the physical render area. Regions not |
| 81 | // covered by any rendered layer should be filled with this color. |
Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 82 | CaptureFill getCaptureFill() const { return mCaptureFill; } |
chaviw | 50da504 | 2018-04-09 13:49:37 -0700 | [diff] [blame] | 83 | |
Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 84 | virtual sp<const DisplayDevice> getDisplayDevice() const = 0; |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 85 | |
Vishnu Nair | 3a7346c | 2019-12-04 08:09:09 -0800 | [diff] [blame] | 86 | // Returns the source display viewport. |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 87 | const Rect& getLayerStackSpaceRect() const { return mLayerStackSpaceRect; } |
Vishnu Nair | 3a7346c | 2019-12-04 08:09:09 -0800 | [diff] [blame] | 88 | |
Robert Carr | 12a3b9b | 2022-03-10 09:55:29 -0800 | [diff] [blame^] | 89 | // If this is a LayerRenderArea, return the root layer of the |
| 90 | // capture operation. |
| 91 | virtual sp<Layer> getParentLayer() const { return nullptr; } |
| 92 | |
chaviw | 70cb6a4 | 2020-07-30 13:57:36 -0700 | [diff] [blame] | 93 | protected: |
| 94 | const bool mAllowSecureLayers; |
| 95 | |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 96 | private: |
Marin Shalamanov | 1c43429 | 2020-06-12 01:47:29 +0200 | [diff] [blame] | 97 | const ui::Size mReqSize; |
Peiyong Lin | 0e003c9 | 2018-09-17 11:09:51 -0700 | [diff] [blame] | 98 | const ui::Dataspace mReqDataSpace; |
Chia-I Wu | c80dcbb | 2018-08-24 15:34:02 -0700 | [diff] [blame] | 99 | const CaptureFill mCaptureFill; |
Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 100 | const RotationFlags mRotationFlags; |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 101 | const Rect mLayerStackSpaceRect; |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 102 | }; |
| 103 | |
Chia-I Wu | 83ce7c1 | 2017-10-19 15:18:55 -0700 | [diff] [blame] | 104 | } // namespace android |