blob: aa66ccf1720b0aa67cd33ef77381ba080d67577b [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
42 virtual ~RenderArea() = default;
43
Chia-I Wub68fac72018-08-23 12:05:27 -070044 // Returns true if the render area is secure. A secure layer should be
45 // blacked out / skipped when rendered to an insecure render area.
46 virtual bool isSecure() const = 0;
chaviwa76b2712017-09-20 12:02:26 -070047
Chia-I Wub68fac72018-08-23 12:05:27 -070048 // Returns the transform to be applied on layers to transform them into
49 // the logical render area.
50 virtual const ui::Transform& getTransform() const = 0;
51
Chia-I Wub68fac72018-08-23 12:05:27 -070052 // Returns the source crop of the render area. The source crop defines
53 // how layers are projected from the logical render area onto the physical
54 // render area. It can be larger than the logical render area. It can
55 // also be optionally rotated.
56 //
Alec Mouri5a6d8572020-03-23 23:56:15 -070057 // The source crop is specified in layer space (when rendering a layer and
58 // its children), or in layer-stack space (when rendering all layers visible
59 // on the display).
Chia-I Wub68fac72018-08-23 12:05:27 -070060 virtual Rect getSourceCrop() const = 0;
61
Chia-I Wub68fac72018-08-23 12:05:27 -070062 // Returns the size of the physical render area.
Marin Shalamanov1c434292020-06-12 01:47:29 +020063 int getReqWidth() const { return mReqSize.width; }
64 int getReqHeight() const { return mReqSize.height; }
Chia-I Wub68fac72018-08-23 12:05:27 -070065
Peiyong Lin0e003c92018-09-17 11:09:51 -070066 // Returns the composition data space of the render area.
67 ui::Dataspace getReqDataSpace() const { return mReqDataSpace; }
68
Chia-I Wub68fac72018-08-23 12:05:27 -070069 // Returns the fill color of the physical render area. Regions not
70 // covered by any rendered layer should be filled with this color.
Dominik Laskowski718f9602019-11-09 20:01:35 -080071 CaptureFill getCaptureFill() const { return mCaptureFill; }
chaviw50da5042018-04-09 13:49:37 -070072
Dominik Laskowski718f9602019-11-09 20:01:35 -080073 virtual sp<const DisplayDevice> getDisplayDevice() const = 0;
Lloyd Pique37c2c9b2018-12-04 17:25:10 -080074
Robert Carr12a3b9b2022-03-10 09:55:29 -080075 // If this is a LayerRenderArea, return the root layer of the
76 // capture operation.
77 virtual sp<Layer> getParentLayer() const { return nullptr; }
78
Melody Hsu50c151a2024-05-14 06:11:12 +000079 // If this is a LayerRenderArea, return the layer snapshot
80 // of the root layer of the capture operation
81 virtual const frontend::LayerSnapshot* getLayerSnapshot() const { return nullptr; }
82
Alec Mouri3e5965f2023-04-07 18:00:58 +000083 // Returns whether the render result may be used for system animations that
84 // must preserve the exact colors of the display.
Vishnu Nair871886e2024-06-26 17:17:51 -070085 bool getHintForSeamlessTransition() const {
86 return mOptions.test(Options::HINT_FOR_SEAMLESS_TRANSITION);
87 }
Alec Mouri3e5965f2023-04-07 18:00:58 +000088
chaviw70cb6a42020-07-30 13:57:36 -070089protected:
Vishnu Nair871886e2024-06-26 17:17:51 -070090 ftl::Flags<Options> mOptions;
chaviw70cb6a42020-07-30 13:57:36 -070091
chaviwa76b2712017-09-20 12:02:26 -070092private:
Marin Shalamanov1c434292020-06-12 01:47:29 +020093 const ui::Size mReqSize;
Peiyong Lin0e003c92018-09-17 11:09:51 -070094 const ui::Dataspace mReqDataSpace;
Chia-I Wuc80dcbb2018-08-24 15:34:02 -070095 const CaptureFill mCaptureFill;
chaviwa76b2712017-09-20 12:02:26 -070096};
97
Chia-I Wu83ce7c12017-10-19 15:18:55 -070098} // namespace android