1 #pragma once 2 3 #include <ui/GraphicTypes.h> 4 #include <ui/Transform.h> 5 6 #include <functional> 7 8 #include "FrontEnd/LayerSnapshot.h" 9 #include "Layer.h" 10 11 namespace android { 12 13 class DisplayDevice; 14 15 // RenderArea describes a rectangular area that layers can be rendered to. 16 // 17 // There is a logical render area and a physical render area. When a layer is 18 // rendered to the render area, it is first transformed and clipped to the logical 19 // render area. The transformed and clipped layer is then projected onto the 20 // physical render area. 21 class RenderArea { 22 public: 23 enum class CaptureFill {CLEAR, OPAQUE}; 24 enum class Options { 25 // If not set, the secure layer would be blacked out or skipped 26 // when rendered to an insecure render area 27 CAPTURE_SECURE_LAYERS = 1 << 0, 28 29 // If set, the render result may be used for system animations 30 // that must preserve the exact colors of the display 31 HINT_FOR_SEAMLESS_TRANSITION = 1 << 1, 32 }; 33 static float getCaptureFillValue(CaptureFill captureFill); 34 RenderArea(ui::Size reqSize,CaptureFill captureFill,ui::Dataspace reqDataSpace,ftl::Flags<Options> options)35 RenderArea(ui::Size reqSize, CaptureFill captureFill, ui::Dataspace reqDataSpace, 36 ftl::Flags<Options> options) 37 : mOptions(options), 38 mReqSize(reqSize), 39 mReqDataSpace(reqDataSpace), 40 mCaptureFill(captureFill) {} 41 42 virtual ~RenderArea() = default; 43 44 // Returns true if the render area is secure. A secure layer should be 45 // blacked out / skipped when rendered to an insecure render area. 46 virtual bool isSecure() const = 0; 47 48 // Returns the transform to be applied on layers to transform them into 49 // the logical render area. 50 virtual const ui::Transform& getTransform() const = 0; 51 52 // Returns the source crop of the render area. The source crop defines 53 // how layers are projected from the logical render area onto the physical 54 // render area. It can be larger than the logical render area. It can 55 // also be optionally rotated. 56 // 57 // The source crop is specified in layer space (when rendering a layer and 58 // its children), or in layer-stack space (when rendering all layers visible 59 // on the display). 60 virtual Rect getSourceCrop() const = 0; 61 62 // Returns the size of the physical render area. getReqWidth()63 int getReqWidth() const { return mReqSize.width; } getReqHeight()64 int getReqHeight() const { return mReqSize.height; } 65 66 // Returns the composition data space of the render area. getReqDataSpace()67 ui::Dataspace getReqDataSpace() const { return mReqDataSpace; } 68 69 // Returns the fill color of the physical render area. Regions not 70 // covered by any rendered layer should be filled with this color. getCaptureFill()71 CaptureFill getCaptureFill() const { return mCaptureFill; } 72 73 virtual sp<const DisplayDevice> getDisplayDevice() const = 0; 74 75 // If this is a LayerRenderArea, return the root layer of the 76 // capture operation. getParentLayer()77 virtual sp<Layer> getParentLayer() const { return nullptr; } 78 79 // If this is a LayerRenderArea, return the layer snapshot 80 // of the root layer of the capture operation getLayerSnapshot()81 virtual const frontend::LayerSnapshot* getLayerSnapshot() const { return nullptr; } 82 83 // Returns whether the render result may be used for system animations that 84 // must preserve the exact colors of the display. getHintForSeamlessTransition()85 bool getHintForSeamlessTransition() const { 86 return mOptions.test(Options::HINT_FOR_SEAMLESS_TRANSITION); 87 } 88 89 protected: 90 ftl::Flags<Options> mOptions; 91 92 private: 93 const ui::Size mReqSize; 94 const ui::Dataspace mReqDataSpace; 95 const CaptureFill mCaptureFill; 96 }; 97 98 } // namespace android 99