1 #pragma once
2 
3 #include <ui/GraphicTypes.h>
4 #include <ui/Transform.h>
5 
6 #include <functional>
7 
8 namespace android {
9 
10 class DisplayDevice;
11 
12 // 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.
18 class RenderArea {
19 public:
20     enum class CaptureFill {CLEAR, OPAQUE};
21 
22     static float getCaptureFillValue(CaptureFill captureFill);
23 
24     RenderArea(uint32_t reqWidth, uint32_t reqHeight, CaptureFill captureFill,
25                ui::Dataspace reqDataSpace,
26                ui::Transform::orientation_flags rotation = ui::Transform::ROT_0)
mReqWidth(reqWidth)27           : mReqWidth(reqWidth),
28             mReqHeight(reqHeight),
29             mReqDataSpace(reqDataSpace),
30             mCaptureFill(captureFill),
31             mRotationFlags(rotation) {}
32 
33     virtual ~RenderArea() = default;
34 
35     // Invoke drawLayers to render layers into the render area.
render(std::function<void ()> drawLayers)36     virtual void render(std::function<void()> drawLayers) { drawLayers(); }
37 
38     // 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;
41 
42     // 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.
getRotationFlags()68     ui::Transform::orientation_flags getRotationFlags() const { return mRotationFlags; };
69 
70     // Returns the size of the physical render area.
getReqWidth()71     int getReqWidth() const { return mReqWidth; };
getReqHeight()72     int getReqHeight() const { return mReqHeight; };
73 
74     // Returns the composition data space of the render area.
getReqDataSpace()75     ui::Dataspace getReqDataSpace() const { return mReqDataSpace; }
76 
77     // Returns the fill color of the physical render area.  Regions not
78     // covered by any rendered layer should be filled with this color.
getCaptureFill()79     CaptureFill getCaptureFill() const { return mCaptureFill; };
80 
81     virtual const sp<const DisplayDevice> getDisplayDevice() const = 0;
82 
83 private:
84     const uint32_t mReqWidth;
85     const uint32_t mReqHeight;
86     const ui::Dataspace mReqDataSpace;
87     const CaptureFill mCaptureFill;
88     const ui::Transform::orientation_flags mRotationFlags;
89 };
90 
91 } // namespace android
92