blob: e8d20af4ad7bea3b745418d158219555d504b4e6 [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};
24
25 static float getCaptureFillValue(CaptureFill captureFill);
26
Marin Shalamanov1c434292020-06-12 01:47:29 +020027 RenderArea(ui::Size reqSize, CaptureFill captureFill, ui::Dataspace reqDataSpace,
Melody Hsu70a63e52023-11-17 19:49:12 +000028 bool hintForSeamlessTransition, bool allowSecureLayers = false)
chaviw70cb6a42020-07-30 13:57:36 -070029 : mAllowSecureLayers(allowSecureLayers),
30 mReqSize(reqSize),
Peiyong Lin0e003c92018-09-17 11:09:51 -070031 mReqDataSpace(reqDataSpace),
Chia-I Wuc80dcbb2018-08-24 15:34:02 -070032 mCaptureFill(captureFill),
Alec Mouri3e5965f2023-04-07 18:00:58 +000033 mHintForSeamlessTransition(hintForSeamlessTransition) {}
chaviwa76b2712017-09-20 12:02:26 -070034
Vishnu Nair7aa0eb72023-01-24 03:59:27 +000035 static std::function<std::vector<std::pair<Layer*, sp<LayerFE>>>()> fromTraverseLayersLambda(
36 std::function<void(const LayerVector::Visitor&)> traverseLayers) {
37 return [traverseLayers = std::move(traverseLayers)]() {
38 std::vector<std::pair<Layer*, sp<LayerFE>>> layers;
39 traverseLayers([&](Layer* layer) {
40 // Layer::prepareClientComposition uses the layer's snapshot to populate the
41 // resulting LayerSettings. Calling Layer::updateSnapshot ensures that LayerSettings
42 // are generated with the layer's current buffer and geometry.
43 layer->updateSnapshot(true /* updateGeometry */);
44 layers.emplace_back(layer, layer->copyCompositionEngineLayerFE());
45 });
46 return layers;
47 };
48 }
49
chaviwa76b2712017-09-20 12:02:26 -070050 virtual ~RenderArea() = default;
51
Chia-I Wub68fac72018-08-23 12:05:27 -070052 // Returns true if the render area is secure. A secure layer should be
53 // blacked out / skipped when rendered to an insecure render area.
54 virtual bool isSecure() const = 0;
chaviwa76b2712017-09-20 12:02:26 -070055
Chia-I Wub68fac72018-08-23 12:05:27 -070056 // Returns the transform to be applied on layers to transform them into
57 // the logical render area.
58 virtual const ui::Transform& getTransform() const = 0;
59
Chia-I Wub68fac72018-08-23 12:05:27 -070060 // 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 Mouri5a6d8572020-03-23 23:56:15 -070065 // 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 Wub68fac72018-08-23 12:05:27 -070068 virtual Rect getSourceCrop() const = 0;
69
Chia-I Wub68fac72018-08-23 12:05:27 -070070 // Returns the size of the physical render area.
Marin Shalamanov1c434292020-06-12 01:47:29 +020071 int getReqWidth() const { return mReqSize.width; }
72 int getReqHeight() const { return mReqSize.height; }
Chia-I Wub68fac72018-08-23 12:05:27 -070073
Peiyong Lin0e003c92018-09-17 11:09:51 -070074 // Returns the composition data space of the render area.
75 ui::Dataspace getReqDataSpace() const { return mReqDataSpace; }
76
Chia-I Wub68fac72018-08-23 12:05:27 -070077 // Returns the fill color of the physical render area. Regions not
78 // covered by any rendered layer should be filled with this color.
Dominik Laskowski718f9602019-11-09 20:01:35 -080079 CaptureFill getCaptureFill() const { return mCaptureFill; }
chaviw50da5042018-04-09 13:49:37 -070080
Dominik Laskowski718f9602019-11-09 20:01:35 -080081 virtual sp<const DisplayDevice> getDisplayDevice() const = 0;
Lloyd Pique37c2c9b2018-12-04 17:25:10 -080082
Robert Carr12a3b9b2022-03-10 09:55:29 -080083 // If this is a LayerRenderArea, return the root layer of the
84 // capture operation.
85 virtual sp<Layer> getParentLayer() const { return nullptr; }
86
Melody Hsu50c151a2024-05-14 06:11:12 +000087 // If this is a LayerRenderArea, return the layer snapshot
88 // of the root layer of the capture operation
89 virtual const frontend::LayerSnapshot* getLayerSnapshot() const { return nullptr; }
90
Alec Mouri3e5965f2023-04-07 18:00:58 +000091 // Returns whether the render result may be used for system animations that
92 // must preserve the exact colors of the display.
93 bool getHintForSeamlessTransition() const { return mHintForSeamlessTransition; }
94
chaviw70cb6a42020-07-30 13:57:36 -070095protected:
96 const bool mAllowSecureLayers;
97
chaviwa76b2712017-09-20 12:02:26 -070098private:
Marin Shalamanov1c434292020-06-12 01:47:29 +020099 const ui::Size mReqSize;
Peiyong Lin0e003c92018-09-17 11:09:51 -0700100 const ui::Dataspace mReqDataSpace;
Chia-I Wuc80dcbb2018-08-24 15:34:02 -0700101 const CaptureFill mCaptureFill;
Alec Mouri3e5965f2023-04-07 18:00:58 +0000102 const bool mHintForSeamlessTransition;
chaviwa76b2712017-09-20 12:02:26 -0700103};
104
Chia-I Wu83ce7c12017-10-19 15:18:55 -0700105} // namespace android