blob: a7a6dd5fc106284a0a4703b90fe6a2196a7e74cf [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
Chia-I Wu9d1abea2018-08-23 13:44:43 -070026 RenderArea(uint32_t reqWidth, uint32_t reqHeight, CaptureFill captureFill,
Vishnu Nair3a7346c2019-12-04 08:09:09 -080027 ui::Dataspace reqDataSpace, const Rect& displayViewport,
Dominik Laskowski718f9602019-11-09 20:01:35 -080028 RotationFlags rotation = ui::Transform::ROT_0)
Chia-I Wuc80dcbb2018-08-24 15:34:02 -070029 : mReqWidth(reqWidth),
30 mReqHeight(reqHeight),
Peiyong Lin0e003c92018-09-17 11:09:51 -070031 mReqDataSpace(reqDataSpace),
Chia-I Wuc80dcbb2018-08-24 15:34:02 -070032 mCaptureFill(captureFill),
Vishnu Nair3a7346c2019-12-04 08:09:09 -080033 mRotationFlags(rotation),
34 mDisplayViewport(displayViewport) {}
chaviwa76b2712017-09-20 12:02:26 -070035
36 virtual ~RenderArea() = default;
37
Chia-I Wub68fac72018-08-23 12:05:27 -070038 // Invoke drawLayers to render layers into the render area.
Robert Carr578038f2018-03-09 12:25:24 -080039 virtual void render(std::function<void()> drawLayers) { drawLayers(); }
40
Chia-I Wub68fac72018-08-23 12:05:27 -070041 // Returns true if the render area is secure. A secure layer should be
42 // blacked out / skipped when rendered to an insecure render area.
43 virtual bool isSecure() const = 0;
chaviwa76b2712017-09-20 12:02:26 -070044
Chia-I Wub68fac72018-08-23 12:05:27 -070045 // Returns true if the otherwise disabled layer filtering should be
46 // enabled when rendering to this render area.
47 virtual bool needsFiltering() const = 0;
48
49 // Returns the transform to be applied on layers to transform them into
50 // the logical render area.
51 virtual const ui::Transform& getTransform() const = 0;
52
53 // Returns the size of the logical render area. Layers are clipped to the
54 // logical render area.
55 virtual int getWidth() const = 0;
56 virtual int getHeight() const = 0;
57 virtual Rect getBounds() const = 0;
58
59 // Returns the source crop of the render area. The source crop defines
60 // how layers are projected from the logical render area onto the physical
61 // render area. It can be larger than the logical render area. It can
62 // also be optionally rotated.
63 //
64 // Layers are first clipped to the source crop (in addition to being
65 // clipped to the logical render area already). The source crop and the
66 // layers are then rotated around the center of the source crop, and
67 // scaled to the physical render area linearly.
68 virtual Rect getSourceCrop() const = 0;
69
70 // Returns the rotation of the source crop and the layers.
Dominik Laskowski718f9602019-11-09 20:01:35 -080071 RotationFlags getRotationFlags() const { return mRotationFlags; }
Chia-I Wub68fac72018-08-23 12:05:27 -070072
73 // Returns the size of the physical render area.
Dominik Laskowski718f9602019-11-09 20:01:35 -080074 int getReqWidth() const { return mReqWidth; }
75 int getReqHeight() const { return mReqHeight; }
Chia-I Wub68fac72018-08-23 12:05:27 -070076
Peiyong Lin0e003c92018-09-17 11:09:51 -070077 // Returns the composition data space of the render area.
78 ui::Dataspace getReqDataSpace() const { return mReqDataSpace; }
79
Chia-I Wub68fac72018-08-23 12:05:27 -070080 // Returns the fill color of the physical render area. Regions not
81 // covered by any rendered layer should be filled with this color.
Dominik Laskowski718f9602019-11-09 20:01:35 -080082 CaptureFill getCaptureFill() const { return mCaptureFill; }
chaviw50da5042018-04-09 13:49:37 -070083
Dominik Laskowski718f9602019-11-09 20:01:35 -080084 virtual sp<const DisplayDevice> getDisplayDevice() const = 0;
Lloyd Pique37c2c9b2018-12-04 17:25:10 -080085
Vishnu Nair3a7346c2019-12-04 08:09:09 -080086 // Returns the source display viewport.
87 const Rect& getDisplayViewport() const { return mDisplayViewport; }
88
chaviwa76b2712017-09-20 12:02:26 -070089private:
Chia-I Wu20261cb2018-08-23 12:55:44 -070090 const uint32_t mReqWidth;
91 const uint32_t mReqHeight;
Peiyong Lin0e003c92018-09-17 11:09:51 -070092 const ui::Dataspace mReqDataSpace;
Chia-I Wuc80dcbb2018-08-24 15:34:02 -070093 const CaptureFill mCaptureFill;
Dominik Laskowski718f9602019-11-09 20:01:35 -080094 const RotationFlags mRotationFlags;
Vishnu Nair3a7346c2019-12-04 08:09:09 -080095 const Rect mDisplayViewport;
chaviwa76b2712017-09-20 12:02:26 -070096};
97
Chia-I Wu83ce7c12017-10-19 15:18:55 -070098} // namespace android