blob: c12ff45e41bee1297644bc770bfeee9db0f7033f [file] [log] [blame]
chaviwa76b2712017-09-20 12:02:26 -07001#pragma once
2
Peiyong Linefefaac2018-08-17 12:27:51 -07003#include <ui/Transform.h>
chaviwa76b2712017-09-20 12:02:26 -07004
Robert Carr578038f2018-03-09 12:25:24 -08005#include <functional>
6
chaviwa76b2712017-09-20 12:02:26 -07007namespace android {
8
Chia-I Wub68fac72018-08-23 12:05:27 -07009// RenderArea describes a rectangular area that layers can be rendered to.
10//
11// There is a logical render area and a physical render area. When a layer is
12// rendered to the render area, it is first transformed and clipped to the logical
13// render area. The transformed and clipped layer is then projected onto the
14// physical render area.
chaviwa76b2712017-09-20 12:02:26 -070015class RenderArea {
16public:
chaviw50da5042018-04-09 13:49:37 -070017 enum class CaptureFill {CLEAR, OPAQUE};
18
19 static float getCaptureFillValue(CaptureFill captureFill);
20
Chia-I Wu9d1abea2018-08-23 13:44:43 -070021 RenderArea(uint32_t reqWidth, uint32_t reqHeight, CaptureFill captureFill,
Chia-I Wuc80dcbb2018-08-24 15:34:02 -070022 ui::Transform::orientation_flags rotation = ui::Transform::ROT_0)
23 : mReqWidth(reqWidth),
24 mReqHeight(reqHeight),
25 mCaptureFill(captureFill),
26 mRotationFlags(rotation) {}
chaviwa76b2712017-09-20 12:02:26 -070027
28 virtual ~RenderArea() = default;
29
Chia-I Wub68fac72018-08-23 12:05:27 -070030 // Invoke drawLayers to render layers into the render area.
Robert Carr578038f2018-03-09 12:25:24 -080031 virtual void render(std::function<void()> drawLayers) { drawLayers(); }
32
Chia-I Wub68fac72018-08-23 12:05:27 -070033 // Returns true if the render area is secure. A secure layer should be
34 // blacked out / skipped when rendered to an insecure render area.
35 virtual bool isSecure() const = 0;
chaviwa76b2712017-09-20 12:02:26 -070036
Chia-I Wub68fac72018-08-23 12:05:27 -070037 // Returns true if the otherwise disabled layer filtering should be
38 // enabled when rendering to this render area.
39 virtual bool needsFiltering() const = 0;
40
41 // Returns the transform to be applied on layers to transform them into
42 // the logical render area.
43 virtual const ui::Transform& getTransform() const = 0;
44
45 // Returns the size of the logical render area. Layers are clipped to the
46 // logical render area.
47 virtual int getWidth() const = 0;
48 virtual int getHeight() const = 0;
49 virtual Rect getBounds() const = 0;
50
51 // Returns the source crop of the render area. The source crop defines
52 // how layers are projected from the logical render area onto the physical
53 // render area. It can be larger than the logical render area. It can
54 // also be optionally rotated.
55 //
56 // Layers are first clipped to the source crop (in addition to being
57 // clipped to the logical render area already). The source crop and the
58 // layers are then rotated around the center of the source crop, and
59 // scaled to the physical render area linearly.
60 virtual Rect getSourceCrop() const = 0;
61
62 // Returns the rotation of the source crop and the layers.
63 ui::Transform::orientation_flags getRotationFlags() const { return mRotationFlags; };
64
65 // Returns the size of the physical render area.
66 int getReqWidth() const { return mReqWidth; };
67 int getReqHeight() const { return mReqHeight; };
68
69 // Returns the fill color of the physical render area. Regions not
70 // covered by any rendered layer should be filled with this color.
chaviw50da5042018-04-09 13:49:37 -070071 CaptureFill getCaptureFill() const { return mCaptureFill; };
72
Chia-I Wub68fac72018-08-23 12:05:27 -070073 status_t updateDimensions(int displayRotation);
74
chaviwa76b2712017-09-20 12:02:26 -070075private:
chaviwa76b2712017-09-20 12:02:26 -070076 uint32_t mReqWidth;
Chia-I Wu9d1abea2018-08-23 13:44:43 -070077 uint32_t mReqHeight;
Chia-I Wuc80dcbb2018-08-24 15:34:02 -070078 const CaptureFill mCaptureFill;
79 const ui::Transform::orientation_flags mRotationFlags;
chaviwa76b2712017-09-20 12:02:26 -070080};
81
Chia-I Wu83ce7c12017-10-19 15:18:55 -070082} // namespace android