blob: 9bad6dee0406100488dd9076242fb86868a7183b [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>
7
chaviwa76b2712017-09-20 12:02:26 -07008namespace android {
9
Chia-I Wub68fac72018-08-23 12:05:27 -070010// RenderArea describes a rectangular area that layers can be rendered to.
11//
12// There is a logical render area and a physical render area. When a layer is
13// rendered to the render area, it is first transformed and clipped to the logical
14// render area. The transformed and clipped layer is then projected onto the
15// physical render area.
chaviwa76b2712017-09-20 12:02:26 -070016class RenderArea {
17public:
chaviw50da5042018-04-09 13:49:37 -070018 enum class CaptureFill {CLEAR, OPAQUE};
19
20 static float getCaptureFillValue(CaptureFill captureFill);
21
Chia-I Wu9d1abea2018-08-23 13:44:43 -070022 RenderArea(uint32_t reqWidth, uint32_t reqHeight, CaptureFill captureFill,
Peiyong Lin0e003c92018-09-17 11:09:51 -070023 ui::Dataspace reqDataSpace,
Chia-I Wuc80dcbb2018-08-24 15:34:02 -070024 ui::Transform::orientation_flags rotation = ui::Transform::ROT_0)
25 : mReqWidth(reqWidth),
26 mReqHeight(reqHeight),
Peiyong Lin0e003c92018-09-17 11:09:51 -070027 mReqDataSpace(reqDataSpace),
Chia-I Wuc80dcbb2018-08-24 15:34:02 -070028 mCaptureFill(captureFill),
29 mRotationFlags(rotation) {}
chaviwa76b2712017-09-20 12:02:26 -070030
31 virtual ~RenderArea() = default;
32
Chia-I Wub68fac72018-08-23 12:05:27 -070033 // Invoke drawLayers to render layers into the render area.
Robert Carr578038f2018-03-09 12:25:24 -080034 virtual void render(std::function<void()> drawLayers) { drawLayers(); }
35
Chia-I Wub68fac72018-08-23 12:05:27 -070036 // Returns true if the render area is secure. A secure layer should be
37 // blacked out / skipped when rendered to an insecure render area.
38 virtual bool isSecure() const = 0;
chaviwa76b2712017-09-20 12:02:26 -070039
Chia-I Wub68fac72018-08-23 12:05:27 -070040 // Returns true if the otherwise disabled layer filtering should be
41 // enabled when rendering to this render area.
42 virtual bool needsFiltering() const = 0;
43
44 // Returns the transform to be applied on layers to transform them into
45 // the logical render area.
46 virtual const ui::Transform& getTransform() const = 0;
47
48 // Returns the size of the logical render area. Layers are clipped to the
49 // logical render area.
50 virtual int getWidth() const = 0;
51 virtual int getHeight() const = 0;
52 virtual Rect getBounds() const = 0;
53
54 // Returns the source crop of the render area. The source crop defines
55 // how layers are projected from the logical render area onto the physical
56 // render area. It can be larger than the logical render area. It can
57 // also be optionally rotated.
58 //
59 // Layers are first clipped to the source crop (in addition to being
60 // clipped to the logical render area already). The source crop and the
61 // layers are then rotated around the center of the source crop, and
62 // scaled to the physical render area linearly.
63 virtual Rect getSourceCrop() const = 0;
64
65 // Returns the rotation of the source crop and the layers.
66 ui::Transform::orientation_flags getRotationFlags() const { return mRotationFlags; };
67
68 // Returns the size of the physical render area.
69 int getReqWidth() const { return mReqWidth; };
70 int getReqHeight() const { return mReqHeight; };
71
Peiyong Lin0e003c92018-09-17 11:09:51 -070072 // Returns the composition data space of the render area.
73 ui::Dataspace getReqDataSpace() const { return mReqDataSpace; }
74
Chia-I Wub68fac72018-08-23 12:05:27 -070075 // Returns the fill color of the physical render area. Regions not
76 // covered by any rendered layer should be filled with this color.
chaviw50da5042018-04-09 13:49:37 -070077 CaptureFill getCaptureFill() const { return mCaptureFill; };
78
chaviwa76b2712017-09-20 12:02:26 -070079private:
Chia-I Wu20261cb2018-08-23 12:55:44 -070080 const uint32_t mReqWidth;
81 const uint32_t mReqHeight;
Peiyong Lin0e003c92018-09-17 11:09:51 -070082 const ui::Dataspace mReqDataSpace;
Chia-I Wuc80dcbb2018-08-24 15:34:02 -070083 const CaptureFill mCaptureFill;
84 const ui::Transform::orientation_flags mRotationFlags;
chaviwa76b2712017-09-20 12:02:26 -070085};
86
Chia-I Wu83ce7c12017-10-19 15:18:55 -070087} // namespace android