blob: 034e467be9db3e740dc28bf42af6dc5c25dd2d42 [file] [log] [blame]
chaviwa76b2712017-09-20 12:02:26 -07001#pragma once
2
Peiyong Lin0e003c92018-09-17 11:09:51 -07003#include <ui/GraphicTypes.h>
Peiyong Linefefaac2018-08-17 12:27:51 -07004#include <ui/Transform.h>
chaviwa76b2712017-09-20 12:02:26 -07005
Robert Carr578038f2018-03-09 12:25:24 -08006#include <functional>
Melody Hsu50c151a2024-05-14 06:11:12 +00007
8#include "FrontEnd/LayerSnapshot.h"
Robert Carr12a3b9b2022-03-10 09:55:29 -08009#include "Layer.h"
Robert Carr578038f2018-03-09 12:25:24 -080010
chaviwa76b2712017-09-20 12:02:26 -070011namespace android {
12
Lloyd Pique37c2c9b2018-12-04 17:25:10 -080013class DisplayDevice;
14
Chia-I Wub68fac72018-08-23 12:05:27 -070015// 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.
chaviwa76b2712017-09-20 12:02:26 -070021class RenderArea {
22public:
chaviw50da5042018-04-09 13:49:37 -070023 enum class CaptureFill {CLEAR, OPAQUE};
Vishnu Nair871886e2024-06-26 17:17:51 -070024 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,
chaviw50da5042018-04-09 13:49:37 -070028
Vishnu Nair871886e2024-06-26 17:17:51 -070029 // 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 };
chaviw50da5042018-04-09 13:49:37 -070033 static float getCaptureFillValue(CaptureFill captureFill);
34
Marin Shalamanov1c434292020-06-12 01:47:29 +020035 RenderArea(ui::Size reqSize, CaptureFill captureFill, ui::Dataspace reqDataSpace,
Vishnu Nair871886e2024-06-26 17:17:51 -070036 ftl::Flags<Options> options)
37 : mOptions(options),
chaviw70cb6a42020-07-30 13:57:36 -070038 mReqSize(reqSize),
Peiyong Lin0e003c92018-09-17 11:09:51 -070039 mReqDataSpace(reqDataSpace),
Vishnu Nair871886e2024-06-26 17:17:51 -070040 mCaptureFill(captureFill) {}
chaviwa76b2712017-09-20 12:02:26 -070041
Vishnu Nair7aa0eb72023-01-24 03:59:27 +000042 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
chaviwa76b2712017-09-20 12:02:26 -070057 virtual ~RenderArea() = default;
58
Chia-I Wub68fac72018-08-23 12:05:27 -070059 // 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;
chaviwa76b2712017-09-20 12:02:26 -070062
Chia-I Wub68fac72018-08-23 12:05:27 -070063 // 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 Wub68fac72018-08-23 12:05:27 -070067 // 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 Mouri5a6d8572020-03-23 23:56:15 -070072 // 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 Wub68fac72018-08-23 12:05:27 -070075 virtual Rect getSourceCrop() const = 0;
76
Chia-I Wub68fac72018-08-23 12:05:27 -070077 // Returns the size of the physical render area.
Marin Shalamanov1c434292020-06-12 01:47:29 +020078 int getReqWidth() const { return mReqSize.width; }
79 int getReqHeight() const { return mReqSize.height; }
Chia-I Wub68fac72018-08-23 12:05:27 -070080
Peiyong Lin0e003c92018-09-17 11:09:51 -070081 // Returns the composition data space of the render area.
82 ui::Dataspace getReqDataSpace() const { return mReqDataSpace; }
83
Chia-I Wub68fac72018-08-23 12:05:27 -070084 // Returns the fill color of the physical render area. Regions not
85 // covered by any rendered layer should be filled with this color.
Dominik Laskowski718f9602019-11-09 20:01:35 -080086 CaptureFill getCaptureFill() const { return mCaptureFill; }
chaviw50da5042018-04-09 13:49:37 -070087
Dominik Laskowski718f9602019-11-09 20:01:35 -080088 virtual sp<const DisplayDevice> getDisplayDevice() const = 0;
Lloyd Pique37c2c9b2018-12-04 17:25:10 -080089
Robert Carr12a3b9b2022-03-10 09:55:29 -080090 // If this is a LayerRenderArea, return the root layer of the
91 // capture operation.
92 virtual sp<Layer> getParentLayer() const { return nullptr; }
93
Melody Hsu50c151a2024-05-14 06:11:12 +000094 // 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 Mouri3e5965f2023-04-07 18:00:58 +000098 // Returns whether the render result may be used for system animations that
99 // must preserve the exact colors of the display.
Vishnu Nair871886e2024-06-26 17:17:51 -0700100 bool getHintForSeamlessTransition() const {
101 return mOptions.test(Options::HINT_FOR_SEAMLESS_TRANSITION);
102 }
Alec Mouri3e5965f2023-04-07 18:00:58 +0000103
chaviw70cb6a42020-07-30 13:57:36 -0700104protected:
Vishnu Nair871886e2024-06-26 17:17:51 -0700105 ftl::Flags<Options> mOptions;
chaviw70cb6a42020-07-30 13:57:36 -0700106
chaviwa76b2712017-09-20 12:02:26 -0700107private:
Marin Shalamanov1c434292020-06-12 01:47:29 +0200108 const ui::Size mReqSize;
Peiyong Lin0e003c92018-09-17 11:09:51 -0700109 const ui::Dataspace mReqDataSpace;
Chia-I Wuc80dcbb2018-08-24 15:34:02 -0700110 const CaptureFill mCaptureFill;
chaviwa76b2712017-09-20 12:02:26 -0700111};
112
Chia-I Wu83ce7c12017-10-19 15:18:55 -0700113} // namespace android