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