• 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 #include "Layer.h"
8 
9 namespace android {
10 
11 class DisplayDevice;
12 
13 // RenderArea describes a rectangular area that layers can be rendered to.
14 //
15 // There is a logical render area and a physical render area.  When a layer is
16 // rendered to the render area, it is first transformed and clipped to the logical
17 // render area.  The transformed and clipped layer is then projected onto the
18 // physical render area.
19 class RenderArea {
20 public:
21     using RotationFlags = ui::Transform::RotationFlags;
22 
23     enum class CaptureFill {CLEAR, OPAQUE};
24 
25     static float getCaptureFillValue(CaptureFill captureFill);
26 
27     RenderArea(ui::Size reqSize, CaptureFill captureFill, ui::Dataspace reqDataSpace,
28                const Rect& layerStackRect, bool allowSecureLayers = false,
29                RotationFlags rotation = ui::Transform::ROT_0)
mAllowSecureLayers(allowSecureLayers)30           : mAllowSecureLayers(allowSecureLayers),
31             mReqSize(reqSize),
32             mReqDataSpace(reqDataSpace),
33             mCaptureFill(captureFill),
34             mRotationFlags(rotation),
35             mLayerStackSpaceRect(layerStackRect) {}
36 
37     virtual ~RenderArea() = default;
38 
39     // Invoke drawLayers to render layers into the render area.
render(std::function<void ()> drawLayers)40     virtual void render(std::function<void()> drawLayers) { drawLayers(); }
41 
42     // Returns true if the render area is secure.  A secure layer should be
43     // blacked out / skipped when rendered to an insecure render area.
44     virtual bool isSecure() const = 0;
45 
46     // Returns true if the otherwise disabled layer filtering should be
47     // enabled when rendering to this render area.
48     virtual bool needsFiltering() const = 0;
49 
50     // Returns the transform to be applied on layers to transform them into
51     // the logical render area.
52     virtual const ui::Transform& getTransform() const = 0;
53 
54     // Returns the size of the logical render area.  Layers are clipped to the
55     // logical render area.
56     virtual int getWidth() const = 0;
57     virtual int getHeight() const = 0;
58     virtual Rect getBounds() const = 0;
59 
60     // Returns the source crop of the render area.  The source crop defines
61     // how layers are projected from the logical render area onto the physical
62     // render area.  It can be larger than the logical render area.  It can
63     // also be optionally rotated.
64     //
65     // The source crop is specified in layer space (when rendering a layer and
66     // its children), or in layer-stack space (when rendering all layers visible
67     // on the display).
68     virtual Rect getSourceCrop() const = 0;
69 
70     // Returns the rotation of the source crop and the layers.
getRotationFlags()71     RotationFlags getRotationFlags() const { return mRotationFlags; }
72 
73     // Returns the size of the physical render area.
getReqWidth()74     int getReqWidth() const { return mReqSize.width; }
getReqHeight()75     int getReqHeight() const { return mReqSize.height; }
76 
77     // Returns the composition data space of the render area.
getReqDataSpace()78     ui::Dataspace getReqDataSpace() const { return mReqDataSpace; }
79 
80     // Returns the fill color of the physical render area.  Regions not
81     // covered by any rendered layer should be filled with this color.
getCaptureFill()82     CaptureFill getCaptureFill() const { return mCaptureFill; }
83 
84     virtual sp<const DisplayDevice> getDisplayDevice() const = 0;
85 
86     // Returns the source display viewport.
getLayerStackSpaceRect()87     const Rect& getLayerStackSpaceRect() const { return mLayerStackSpaceRect; }
88 
89     // If this is a LayerRenderArea, return the root layer of the
90     // capture operation.
getParentLayer()91     virtual sp<Layer> getParentLayer() const { return nullptr; }
92 
93 protected:
94     const bool mAllowSecureLayers;
95 
96 private:
97     const ui::Size mReqSize;
98     const ui::Dataspace mReqDataSpace;
99     const CaptureFill mCaptureFill;
100     const RotationFlags mRotationFlags;
101     const Rect mLayerStackSpaceRect;
102 };
103 
104 } // namespace android
105