blob: 5de148e3bd58415a29ee051c822ad484ba86292e [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>
Robert Carr12a3b9b2022-03-10 09:55:29 -08007#include "Layer.h"
Robert Carr578038f2018-03-09 12:25:24 -08008
chaviwa76b2712017-09-20 12:02:26 -07009namespace android {
10
Lloyd Pique37c2c9b2018-12-04 17:25:10 -080011class DisplayDevice;
12
Chia-I Wub68fac72018-08-23 12:05:27 -070013// 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.
chaviwa76b2712017-09-20 12:02:26 -070019class RenderArea {
20public:
chaviw50da5042018-04-09 13:49:37 -070021 enum class CaptureFill {CLEAR, OPAQUE};
22
23 static float getCaptureFillValue(CaptureFill captureFill);
24
Marin Shalamanov1c434292020-06-12 01:47:29 +020025 RenderArea(ui::Size reqSize, CaptureFill captureFill, ui::Dataspace reqDataSpace,
Melody Hsu70a63e52023-11-17 19:49:12 +000026 bool hintForSeamlessTransition, bool allowSecureLayers = false)
chaviw70cb6a42020-07-30 13:57:36 -070027 : mAllowSecureLayers(allowSecureLayers),
28 mReqSize(reqSize),
Peiyong Lin0e003c92018-09-17 11:09:51 -070029 mReqDataSpace(reqDataSpace),
Chia-I Wuc80dcbb2018-08-24 15:34:02 -070030 mCaptureFill(captureFill),
Alec Mouri3e5965f2023-04-07 18:00:58 +000031 mHintForSeamlessTransition(hintForSeamlessTransition) {}
chaviwa76b2712017-09-20 12:02:26 -070032
Vishnu Nair7aa0eb72023-01-24 03:59:27 +000033 static std::function<std::vector<std::pair<Layer*, sp<LayerFE>>>()> fromTraverseLayersLambda(
34 std::function<void(const LayerVector::Visitor&)> traverseLayers) {
35 return [traverseLayers = std::move(traverseLayers)]() {
36 std::vector<std::pair<Layer*, sp<LayerFE>>> layers;
37 traverseLayers([&](Layer* layer) {
38 // Layer::prepareClientComposition uses the layer's snapshot to populate the
39 // resulting LayerSettings. Calling Layer::updateSnapshot ensures that LayerSettings
40 // are generated with the layer's current buffer and geometry.
41 layer->updateSnapshot(true /* updateGeometry */);
42 layers.emplace_back(layer, layer->copyCompositionEngineLayerFE());
43 });
44 return layers;
45 };
46 }
47
chaviwa76b2712017-09-20 12:02:26 -070048 virtual ~RenderArea() = default;
49
Chia-I Wub68fac72018-08-23 12:05:27 -070050 // Invoke drawLayers to render layers into the render area.
Robert Carr578038f2018-03-09 12:25:24 -080051 virtual void render(std::function<void()> drawLayers) { drawLayers(); }
52
Chia-I Wub68fac72018-08-23 12:05:27 -070053 // Returns true if the render area is secure. A secure layer should be
54 // blacked out / skipped when rendered to an insecure render area.
55 virtual bool isSecure() const = 0;
chaviwa76b2712017-09-20 12:02:26 -070056
Chia-I Wub68fac72018-08-23 12:05:27 -070057 // Returns the transform to be applied on layers to transform them into
58 // the logical render area.
59 virtual const ui::Transform& getTransform() const = 0;
60
Chia-I Wub68fac72018-08-23 12:05:27 -070061 // Returns the source crop of the render area. The source crop defines
62 // how layers are projected from the logical render area onto the physical
63 // render area. It can be larger than the logical render area. It can
64 // also be optionally rotated.
65 //
Alec Mouri5a6d8572020-03-23 23:56:15 -070066 // The source crop is specified in layer space (when rendering a layer and
67 // its children), or in layer-stack space (when rendering all layers visible
68 // on the display).
Chia-I Wub68fac72018-08-23 12:05:27 -070069 virtual Rect getSourceCrop() const = 0;
70
Chia-I Wub68fac72018-08-23 12:05:27 -070071 // Returns the size of the physical render area.
Marin Shalamanov1c434292020-06-12 01:47:29 +020072 int getReqWidth() const { return mReqSize.width; }
73 int getReqHeight() const { return mReqSize.height; }
Chia-I Wub68fac72018-08-23 12:05:27 -070074
Peiyong Lin0e003c92018-09-17 11:09:51 -070075 // Returns the composition data space of the render area.
76 ui::Dataspace getReqDataSpace() const { return mReqDataSpace; }
77
Chia-I Wub68fac72018-08-23 12:05:27 -070078 // Returns the fill color of the physical render area. Regions not
79 // covered by any rendered layer should be filled with this color.
Dominik Laskowski718f9602019-11-09 20:01:35 -080080 CaptureFill getCaptureFill() const { return mCaptureFill; }
chaviw50da5042018-04-09 13:49:37 -070081
Dominik Laskowski718f9602019-11-09 20:01:35 -080082 virtual sp<const DisplayDevice> getDisplayDevice() const = 0;
Lloyd Pique37c2c9b2018-12-04 17:25:10 -080083
Robert Carr12a3b9b2022-03-10 09:55:29 -080084 // If this is a LayerRenderArea, return the root layer of the
85 // capture operation.
86 virtual sp<Layer> getParentLayer() const { return nullptr; }
87
Alec Mouri3e5965f2023-04-07 18:00:58 +000088 // Returns whether the render result may be used for system animations that
89 // must preserve the exact colors of the display.
90 bool getHintForSeamlessTransition() const { return mHintForSeamlessTransition; }
91
chaviw70cb6a42020-07-30 13:57:36 -070092protected:
93 const bool mAllowSecureLayers;
94
chaviwa76b2712017-09-20 12:02:26 -070095private:
Marin Shalamanov1c434292020-06-12 01:47:29 +020096 const ui::Size mReqSize;
Peiyong Lin0e003c92018-09-17 11:09:51 -070097 const ui::Dataspace mReqDataSpace;
Chia-I Wuc80dcbb2018-08-24 15:34:02 -070098 const CaptureFill mCaptureFill;
Alec Mouri3e5965f2023-04-07 18:00:58 +000099 const bool mHintForSeamlessTransition;
chaviwa76b2712017-09-20 12:02:26 -0700100};
101
Chia-I Wu83ce7c12017-10-19 15:18:55 -0700102} // namespace android