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 fromTraverseLayersLambda(std::function<void (const LayerVector::Visitor &)> traverseLayers)42 static std::function<std::vector<std::pair<Layer*, sp<LayerFE>>>()> fromTraverseLayersLambda( 43 std::function<void(const LayerVector::Visitor&)> traverseLayers) { 44 return [traverseLayers = std::move(traverseLayers)]() { 45 std::vector<std::pair<Layer*, sp<LayerFE>>> layers; 46 traverseLayers([&](Layer* layer) { 47 // Layer::prepareClientComposition uses the layer's snapshot to populate the 48 // resulting LayerSettings. Calling Layer::updateSnapshot ensures that LayerSettings 49 // are generated with the layer's current buffer and geometry. 50 layer->updateSnapshot(true /* updateGeometry */); 51 layers.emplace_back(layer, layer->copyCompositionEngineLayerFE()); 52 }); 53 return layers; 54 }; 55 } 56 57 virtual ~RenderArea() = default; 58 59 // Returns true if the render area is secure. A secure layer should be 60 // blacked out / skipped when rendered to an insecure render area. 61 virtual bool isSecure() const = 0; 62 63 // Returns the transform to be applied on layers to transform them into 64 // the logical render area. 65 virtual const ui::Transform& getTransform() const = 0; 66 67 // Returns the source crop of the render area. The source crop defines 68 // how layers are projected from the logical render area onto the physical 69 // render area. It can be larger than the logical render area. It can 70 // also be optionally rotated. 71 // 72 // The source crop is specified in layer space (when rendering a layer and 73 // its children), or in layer-stack space (when rendering all layers visible 74 // on the display). 75 virtual Rect getSourceCrop() const = 0; 76 77 // Returns the size of the physical render area. getReqWidth()78 int getReqWidth() const { return mReqSize.width; } getReqHeight()79 int getReqHeight() const { return mReqSize.height; } 80 81 // Returns the composition data space of the render area. getReqDataSpace()82 ui::Dataspace getReqDataSpace() const { return mReqDataSpace; } 83 84 // Returns the fill color of the physical render area. Regions not 85 // covered by any rendered layer should be filled with this color. getCaptureFill()86 CaptureFill getCaptureFill() const { return mCaptureFill; } 87 88 virtual sp<const DisplayDevice> getDisplayDevice() const = 0; 89 90 // If this is a LayerRenderArea, return the root layer of the 91 // capture operation. getParentLayer()92 virtual sp<Layer> getParentLayer() const { return nullptr; } 93 94 // If this is a LayerRenderArea, return the layer snapshot 95 // of the root layer of the capture operation getLayerSnapshot()96 virtual const frontend::LayerSnapshot* getLayerSnapshot() const { return nullptr; } 97 98 // Returns whether the render result may be used for system animations that 99 // must preserve the exact colors of the display. getHintForSeamlessTransition()100 bool getHintForSeamlessTransition() const { 101 return mOptions.test(Options::HINT_FOR_SEAMLESS_TRANSITION); 102 } 103 104 protected: 105 ftl::Flags<Options> mOptions; 106 107 private: 108 const ui::Size mReqSize; 109 const ui::Dataspace mReqDataSpace; 110 const CaptureFill mCaptureFill; 111 }; 112 113 } // namespace android 114