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