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> |
Melody Hsu | 50c151a | 2024-05-14 06:11:12 +0000 | [diff] [blame] | 7 | |
| 8 | #include "FrontEnd/LayerSnapshot.h" |
Robert Carr | 12a3b9b | 2022-03-10 09:55:29 -0800 | [diff] [blame] | 9 | #include "Layer.h" |
Robert Carr | 578038f | 2018-03-09 12:25:24 -0800 | [diff] [blame] | 10 | |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 11 | namespace android { |
| 12 | |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 13 | class DisplayDevice; |
| 14 | |
Chia-I Wu | b68fac7 | 2018-08-23 12:05:27 -0700 | [diff] [blame] | 15 | // RenderArea describes a rectangular area that layers can be rendered to. |
| 16 | // |
| 17 | // There is a logical render area and a physical render area. When a layer is |
| 18 | // rendered to the render area, it is first transformed and clipped to the logical |
| 19 | // render area. The transformed and clipped layer is then projected onto the |
| 20 | // physical render area. |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 21 | class RenderArea { |
| 22 | public: |
chaviw | 50da504 | 2018-04-09 13:49:37 -0700 | [diff] [blame] | 23 | enum class CaptureFill {CLEAR, OPAQUE}; |
Vishnu Nair | 871886e | 2024-06-26 17:17:51 -0700 | [diff] [blame^] | 24 | enum class Options { |
| 25 | // If not set, the secure layer would be blacked out or skipped |
| 26 | // when rendered to an insecure render area |
| 27 | CAPTURE_SECURE_LAYERS = 1 << 0, |
chaviw | 50da504 | 2018-04-09 13:49:37 -0700 | [diff] [blame] | 28 | |
Vishnu Nair | 871886e | 2024-06-26 17:17:51 -0700 | [diff] [blame^] | 29 | // If set, the render result may be used for system animations |
| 30 | // that must preserve the exact colors of the display |
| 31 | HINT_FOR_SEAMLESS_TRANSITION = 1 << 1, |
| 32 | }; |
chaviw | 50da504 | 2018-04-09 13:49:37 -0700 | [diff] [blame] | 33 | static float getCaptureFillValue(CaptureFill captureFill); |
| 34 | |
Marin Shalamanov | 1c43429 | 2020-06-12 01:47:29 +0200 | [diff] [blame] | 35 | RenderArea(ui::Size reqSize, CaptureFill captureFill, ui::Dataspace reqDataSpace, |
Vishnu Nair | 871886e | 2024-06-26 17:17:51 -0700 | [diff] [blame^] | 36 | ftl::Flags<Options> options) |
| 37 | : mOptions(options), |
chaviw | 70cb6a4 | 2020-07-30 13:57:36 -0700 | [diff] [blame] | 38 | mReqSize(reqSize), |
Peiyong Lin | 0e003c9 | 2018-09-17 11:09:51 -0700 | [diff] [blame] | 39 | mReqDataSpace(reqDataSpace), |
Vishnu Nair | 871886e | 2024-06-26 17:17:51 -0700 | [diff] [blame^] | 40 | mCaptureFill(captureFill) {} |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 41 | |
Vishnu Nair | 7aa0eb7 | 2023-01-24 03:59:27 +0000 | [diff] [blame] | 42 | static std::function<std::vector<std::pair<Layer*, sp<LayerFE>>>()> fromTraverseLayersLambda( |
| 43 | std::function<void(const LayerVector::Visitor&)> traverseLayers) { |
| 44 | return [traverseLayers = std::move(traverseLayers)]() { |
| 45 | std::vector<std::pair<Layer*, sp<LayerFE>>> layers; |
| 46 | traverseLayers([&](Layer* layer) { |
| 47 | // Layer::prepareClientComposition uses the layer's snapshot to populate the |
| 48 | // resulting LayerSettings. Calling Layer::updateSnapshot ensures that LayerSettings |
| 49 | // are generated with the layer's current buffer and geometry. |
| 50 | layer->updateSnapshot(true /* updateGeometry */); |
| 51 | layers.emplace_back(layer, layer->copyCompositionEngineLayerFE()); |
| 52 | }); |
| 53 | return layers; |
| 54 | }; |
| 55 | } |
| 56 | |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 57 | virtual ~RenderArea() = default; |
| 58 | |
Chia-I Wu | b68fac7 | 2018-08-23 12:05:27 -0700 | [diff] [blame] | 59 | // Returns true if the render area is secure. A secure layer should be |
| 60 | // blacked out / skipped when rendered to an insecure render area. |
| 61 | virtual bool isSecure() const = 0; |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 62 | |
Chia-I Wu | b68fac7 | 2018-08-23 12:05:27 -0700 | [diff] [blame] | 63 | // Returns the transform to be applied on layers to transform them into |
| 64 | // the logical render area. |
| 65 | virtual const ui::Transform& getTransform() const = 0; |
| 66 | |
Chia-I Wu | b68fac7 | 2018-08-23 12:05:27 -0700 | [diff] [blame] | 67 | // Returns the source crop of the render area. The source crop defines |
| 68 | // how layers are projected from the logical render area onto the physical |
| 69 | // render area. It can be larger than the logical render area. It can |
| 70 | // also be optionally rotated. |
| 71 | // |
Alec Mouri | 5a6d857 | 2020-03-23 23:56:15 -0700 | [diff] [blame] | 72 | // The source crop is specified in layer space (when rendering a layer and |
| 73 | // its children), or in layer-stack space (when rendering all layers visible |
| 74 | // on the display). |
Chia-I Wu | b68fac7 | 2018-08-23 12:05:27 -0700 | [diff] [blame] | 75 | virtual Rect getSourceCrop() const = 0; |
| 76 | |
Chia-I Wu | b68fac7 | 2018-08-23 12:05:27 -0700 | [diff] [blame] | 77 | // Returns the size of the physical render area. |
Marin Shalamanov | 1c43429 | 2020-06-12 01:47:29 +0200 | [diff] [blame] | 78 | int getReqWidth() const { return mReqSize.width; } |
| 79 | int getReqHeight() const { return mReqSize.height; } |
Chia-I Wu | b68fac7 | 2018-08-23 12:05:27 -0700 | [diff] [blame] | 80 | |
Peiyong Lin | 0e003c9 | 2018-09-17 11:09:51 -0700 | [diff] [blame] | 81 | // Returns the composition data space of the render area. |
| 82 | ui::Dataspace getReqDataSpace() const { return mReqDataSpace; } |
| 83 | |
Chia-I Wu | b68fac7 | 2018-08-23 12:05:27 -0700 | [diff] [blame] | 84 | // Returns the fill color of the physical render area. Regions not |
| 85 | // covered by any rendered layer should be filled with this color. |
Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 86 | CaptureFill getCaptureFill() const { return mCaptureFill; } |
chaviw | 50da504 | 2018-04-09 13:49:37 -0700 | [diff] [blame] | 87 | |
Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 88 | virtual sp<const DisplayDevice> getDisplayDevice() const = 0; |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 89 | |
Robert Carr | 12a3b9b | 2022-03-10 09:55:29 -0800 | [diff] [blame] | 90 | // If this is a LayerRenderArea, return the root layer of the |
| 91 | // capture operation. |
| 92 | virtual sp<Layer> getParentLayer() const { return nullptr; } |
| 93 | |
Melody Hsu | 50c151a | 2024-05-14 06:11:12 +0000 | [diff] [blame] | 94 | // If this is a LayerRenderArea, return the layer snapshot |
| 95 | // of the root layer of the capture operation |
| 96 | virtual const frontend::LayerSnapshot* getLayerSnapshot() const { return nullptr; } |
| 97 | |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 98 | // Returns whether the render result may be used for system animations that |
| 99 | // must preserve the exact colors of the display. |
Vishnu Nair | 871886e | 2024-06-26 17:17:51 -0700 | [diff] [blame^] | 100 | bool getHintForSeamlessTransition() const { |
| 101 | return mOptions.test(Options::HINT_FOR_SEAMLESS_TRANSITION); |
| 102 | } |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 103 | |
chaviw | 70cb6a4 | 2020-07-30 13:57:36 -0700 | [diff] [blame] | 104 | protected: |
Vishnu Nair | 871886e | 2024-06-26 17:17:51 -0700 | [diff] [blame^] | 105 | ftl::Flags<Options> mOptions; |
chaviw | 70cb6a4 | 2020-07-30 13:57:36 -0700 | [diff] [blame] | 106 | |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 107 | private: |
Marin Shalamanov | 1c43429 | 2020-06-12 01:47:29 +0200 | [diff] [blame] | 108 | const ui::Size mReqSize; |
Peiyong Lin | 0e003c9 | 2018-09-17 11:09:51 -0700 | [diff] [blame] | 109 | const ui::Dataspace mReqDataSpace; |
Chia-I Wu | c80dcbb | 2018-08-24 15:34:02 -0700 | [diff] [blame] | 110 | const CaptureFill mCaptureFill; |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 111 | }; |
| 112 | |
Chia-I Wu | 83ce7c1 | 2017-10-19 15:18:55 -0700 | [diff] [blame] | 113 | } // namespace android |