blob: edc6442da77a08fe2c6e40d3f018afb9dec3b13d [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
Lloyd Pique37c2c9b2018-12-04 17:25:10 -080010class DisplayDevice;
11
Chia-I Wub68fac72018-08-23 12:05:27 -070012// RenderArea describes a rectangular area that layers can be rendered to.
13//
14// There is a logical render area and a physical render area. When a layer is
15// rendered to the render area, it is first transformed and clipped to the logical
16// render area. The transformed and clipped layer is then projected onto the
17// physical render area.
chaviwa76b2712017-09-20 12:02:26 -070018class RenderArea {
19public:
chaviw50da5042018-04-09 13:49:37 -070020 enum class CaptureFill {CLEAR, OPAQUE};
21
22 static float getCaptureFillValue(CaptureFill captureFill);
23
Chia-I Wu9d1abea2018-08-23 13:44:43 -070024 RenderArea(uint32_t reqWidth, uint32_t reqHeight, CaptureFill captureFill,
Peiyong Lin0e003c92018-09-17 11:09:51 -070025 ui::Dataspace reqDataSpace,
Chia-I Wuc80dcbb2018-08-24 15:34:02 -070026 ui::Transform::orientation_flags rotation = ui::Transform::ROT_0)
27 : mReqWidth(reqWidth),
28 mReqHeight(reqHeight),
Peiyong Lin0e003c92018-09-17 11:09:51 -070029 mReqDataSpace(reqDataSpace),
Chia-I Wuc80dcbb2018-08-24 15:34:02 -070030 mCaptureFill(captureFill),
31 mRotationFlags(rotation) {}
chaviwa76b2712017-09-20 12:02:26 -070032
33 virtual ~RenderArea() = default;
34
Chia-I Wub68fac72018-08-23 12:05:27 -070035 // Invoke drawLayers to render layers into the render area.
Robert Carr578038f2018-03-09 12:25:24 -080036 virtual void render(std::function<void()> drawLayers) { drawLayers(); }
37
Chia-I Wub68fac72018-08-23 12:05:27 -070038 // Returns true if the render area is secure. A secure layer should be
39 // blacked out / skipped when rendered to an insecure render area.
40 virtual bool isSecure() const = 0;
chaviwa76b2712017-09-20 12:02:26 -070041
Chia-I Wub68fac72018-08-23 12:05:27 -070042 // Returns true if the otherwise disabled layer filtering should be
43 // enabled when rendering to this render area.
44 virtual bool needsFiltering() const = 0;
45
46 // Returns the transform to be applied on layers to transform them into
47 // the logical render area.
48 virtual const ui::Transform& getTransform() const = 0;
49
50 // Returns the size of the logical render area. Layers are clipped to the
51 // logical render area.
52 virtual int getWidth() const = 0;
53 virtual int getHeight() const = 0;
54 virtual Rect getBounds() const = 0;
55
56 // Returns the source crop of the render area. The source crop defines
57 // how layers are projected from the logical render area onto the physical
58 // render area. It can be larger than the logical render area. It can
59 // also be optionally rotated.
60 //
61 // Layers are first clipped to the source crop (in addition to being
62 // clipped to the logical render area already). The source crop and the
63 // layers are then rotated around the center of the source crop, and
64 // scaled to the physical render area linearly.
65 virtual Rect getSourceCrop() const = 0;
66
67 // Returns the rotation of the source crop and the layers.
68 ui::Transform::orientation_flags getRotationFlags() const { return mRotationFlags; };
69
70 // Returns the size of the physical render area.
71 int getReqWidth() const { return mReqWidth; };
72 int getReqHeight() const { return mReqHeight; };
73
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.
chaviw50da5042018-04-09 13:49:37 -070079 CaptureFill getCaptureFill() const { return mCaptureFill; };
80
Lloyd Pique37c2c9b2018-12-04 17:25:10 -080081 virtual const sp<const DisplayDevice> getDisplayDevice() const = 0;
82
chaviwa76b2712017-09-20 12:02:26 -070083private:
Chia-I Wu20261cb2018-08-23 12:55:44 -070084 const uint32_t mReqWidth;
85 const uint32_t mReqHeight;
Peiyong Lin0e003c92018-09-17 11:09:51 -070086 const ui::Dataspace mReqDataSpace;
Chia-I Wuc80dcbb2018-08-24 15:34:02 -070087 const CaptureFill mCaptureFill;
88 const ui::Transform::orientation_flags mRotationFlags;
chaviwa76b2712017-09-20 12:02:26 -070089};
90
Chia-I Wu83ce7c12017-10-19 15:18:55 -070091} // namespace android