• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     using RotationFlags = ui::Transform::RotationFlags;
21 
22     enum class CaptureFill {CLEAR, OPAQUE};
23 
24     static float getCaptureFillValue(CaptureFill captureFill);
25 
26     RenderArea(ui::Size reqSize, CaptureFill captureFill, ui::Dataspace reqDataSpace,
27                const Rect& layerStackRect, bool allowSecureLayers = false,
28                RotationFlags rotation = ui::Transform::ROT_0)
mAllowSecureLayers(allowSecureLayers)29           : mAllowSecureLayers(allowSecureLayers),
30             mReqSize(reqSize),
31             mReqDataSpace(reqDataSpace),
32             mCaptureFill(captureFill),
33             mRotationFlags(rotation),
34             mLayerStackSpaceRect(layerStackRect) {}
35 
36     virtual ~RenderArea() = default;
37 
38     // Invoke drawLayers to render layers into the render area.
render(std::function<void ()> drawLayers)39     virtual void render(std::function<void()> drawLayers) { drawLayers(); }
40 
41     // 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;
44 
45     // 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     // The source crop is specified in layer space (when rendering a layer and
65     // its children), or in layer-stack space (when rendering all layers visible
66     // on the display).
67     virtual Rect getSourceCrop() const = 0;
68 
69     // Returns the rotation of the source crop and the layers.
getRotationFlags()70     RotationFlags getRotationFlags() const { return mRotationFlags; }
71 
72     // Returns the size of the physical render area.
getReqWidth()73     int getReqWidth() const { return mReqSize.width; }
getReqHeight()74     int getReqHeight() const { return mReqSize.height; }
75 
76     // Returns the composition data space of the render area.
getReqDataSpace()77     ui::Dataspace getReqDataSpace() const { return mReqDataSpace; }
78 
79     // Returns the fill color of the physical render area.  Regions not
80     // covered by any rendered layer should be filled with this color.
getCaptureFill()81     CaptureFill getCaptureFill() const { return mCaptureFill; }
82 
83     virtual sp<const DisplayDevice> getDisplayDevice() const = 0;
84 
85     // Returns the source display viewport.
getLayerStackSpaceRect()86     const Rect& getLayerStackSpaceRect() const { return mLayerStackSpaceRect; }
87 
88 protected:
89     const bool mAllowSecureLayers;
90 
91 private:
92     const ui::Size mReqSize;
93     const ui::Dataspace mReqDataSpace;
94     const CaptureFill mCaptureFill;
95     const RotationFlags mRotationFlags;
96     const Rect mLayerStackSpaceRect;
97 };
98 
99 } // namespace android
100