blob: a6246d9a6a8d78931da942e5bc57a45c14a75b6a [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:
Dominik Laskowski718f9602019-11-09 20:01:35 -080020 using RotationFlags = ui::Transform::RotationFlags;
21
chaviw50da5042018-04-09 13:49:37 -070022 enum class CaptureFill {CLEAR, OPAQUE};
23
24 static float getCaptureFillValue(CaptureFill captureFill);
25
Marin Shalamanov1c434292020-06-12 01:47:29 +020026 RenderArea(ui::Size reqSize, CaptureFill captureFill, ui::Dataspace reqDataSpace,
27 const Rect& displayViewport, RotationFlags rotation = ui::Transform::ROT_0)
28 : mReqSize(reqSize),
Peiyong Lin0e003c92018-09-17 11:09:51 -070029 mReqDataSpace(reqDataSpace),
Chia-I Wuc80dcbb2018-08-24 15:34:02 -070030 mCaptureFill(captureFill),
Vishnu Nair3a7346c2019-12-04 08:09:09 -080031 mRotationFlags(rotation),
32 mDisplayViewport(displayViewport) {}
chaviwa76b2712017-09-20 12:02:26 -070033
34 virtual ~RenderArea() = default;
35
Chia-I Wub68fac72018-08-23 12:05:27 -070036 // Invoke drawLayers to render layers into the render area.
Robert Carr578038f2018-03-09 12:25:24 -080037 virtual void render(std::function<void()> drawLayers) { drawLayers(); }
38
Chia-I Wub68fac72018-08-23 12:05:27 -070039 // Returns true if the render area is secure. A secure layer should be
40 // blacked out / skipped when rendered to an insecure render area.
41 virtual bool isSecure() const = 0;
chaviwa76b2712017-09-20 12:02:26 -070042
Chia-I Wub68fac72018-08-23 12:05:27 -070043 // Returns true if the otherwise disabled layer filtering should be
44 // enabled when rendering to this render area.
45 virtual bool needsFiltering() const = 0;
46
47 // Returns the transform to be applied on layers to transform them into
48 // the logical render area.
49 virtual const ui::Transform& getTransform() const = 0;
50
51 // Returns the size of the logical render area. Layers are clipped to the
52 // logical render area.
53 virtual int getWidth() const = 0;
54 virtual int getHeight() const = 0;
55 virtual Rect getBounds() const = 0;
56
57 // Returns the source crop of the render area. The source crop defines
58 // how layers are projected from the logical render area onto the physical
59 // render area. It can be larger than the logical render area. It can
60 // also be optionally rotated.
61 //
Alec Mouri5a6d8572020-03-23 23:56:15 -070062 // The source crop is specified in layer space (when rendering a layer and
63 // its children), or in layer-stack space (when rendering all layers visible
64 // on the display).
Chia-I Wub68fac72018-08-23 12:05:27 -070065 virtual Rect getSourceCrop() const = 0;
66
67 // Returns the rotation of the source crop and the layers.
Dominik Laskowski718f9602019-11-09 20:01:35 -080068 RotationFlags getRotationFlags() const { return mRotationFlags; }
Chia-I Wub68fac72018-08-23 12:05:27 -070069
70 // 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
Vishnu Nair3a7346c2019-12-04 08:09:09 -080083 // Returns the source display viewport.
84 const Rect& getDisplayViewport() const { return mDisplayViewport; }
85
chaviwa76b2712017-09-20 12:02:26 -070086private:
Marin Shalamanov1c434292020-06-12 01:47:29 +020087 const ui::Size mReqSize;
Peiyong Lin0e003c92018-09-17 11:09:51 -070088 const ui::Dataspace mReqDataSpace;
Chia-I Wuc80dcbb2018-08-24 15:34:02 -070089 const CaptureFill mCaptureFill;
Dominik Laskowski718f9602019-11-09 20:01:35 -080090 const RotationFlags mRotationFlags;
Vishnu Nair3a7346c2019-12-04 08:09:09 -080091 const Rect mDisplayViewport;
chaviwa76b2712017-09-20 12:02:26 -070092};
93
Chia-I Wu83ce7c12017-10-19 15:18:55 -070094} // namespace android