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(uint32_t reqWidth, uint32_t reqHeight, CaptureFill captureFill, 27 ui::Dataspace reqDataSpace, const Rect& displayViewport, 28 RotationFlags rotation = ui::Transform::ROT_0) mReqWidth(reqWidth)29 : mReqWidth(reqWidth), 30 mReqHeight(reqHeight), 31 mReqDataSpace(reqDataSpace), 32 mCaptureFill(captureFill), 33 mRotationFlags(rotation), 34 mDisplayViewport(displayViewport) {} 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 static_cast<int>(mReqWidth); } getReqHeight()74 int getReqHeight() const { return static_cast<int>(mReqHeight); } 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. getDisplayViewport()86 const Rect& getDisplayViewport() const { return mDisplayViewport; } 87 88 private: 89 const uint32_t mReqWidth; 90 const uint32_t mReqHeight; 91 const ui::Dataspace mReqDataSpace; 92 const CaptureFill mCaptureFill; 93 const RotationFlags mRotationFlags; 94 const Rect mDisplayViewport; 95 }; 96 97 } // namespace android 98