• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2007 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
19 #include <android/gui/DropInputMode.h>
20 #include <gui/BufferQueue.h>
21 #include <gui/ISurfaceComposerClient.h>
22 #include <gui/LayerState.h>
23 #include <gui/WindowInfo.h>
24 #include <layerproto/LayerProtoHeader.h>
25 #include <math/vec4.h>
26 #include <renderengine/Mesh.h>
27 #include <renderengine/Texture.h>
28 #include <sys/types.h>
29 #include <ui/BlurRegion.h>
30 #include <ui/FloatRect.h>
31 #include <ui/FrameStats.h>
32 #include <ui/GraphicBuffer.h>
33 #include <ui/PixelFormat.h>
34 #include <ui/Region.h>
35 #include <ui/StretchEffect.h>
36 #include <ui/Transform.h>
37 #include <utils/RefBase.h>
38 #include <utils/Timers.h>
39 
40 #include <compositionengine/LayerFE.h>
41 #include <scheduler/Fps.h>
42 #include <scheduler/Seamlessness.h>
43 
44 #include <chrono>
45 #include <cstdint>
46 #include <list>
47 #include <optional>
48 #include <vector>
49 
50 #include "Client.h"
51 #include "ClientCache.h"
52 #include "DisplayHardware/ComposerHal.h"
53 #include "DisplayHardware/HWComposer.h"
54 #include "FrameTracker.h"
55 #include "LayerVector.h"
56 #include "MonitoredProducer.h"
57 #include "RenderArea.h"
58 #include "Scheduler/LayerInfo.h"
59 #include "SurfaceFlinger.h"
60 #include "Tracing/LayerTracing.h"
61 #include "TransactionCallbackInvoker.h"
62 
63 using namespace android::surfaceflinger;
64 
65 namespace android {
66 
67 class Client;
68 class Colorizer;
69 class DisplayDevice;
70 class GraphicBuffer;
71 class SurfaceFlinger;
72 class LayerDebugInfo;
73 
74 namespace compositionengine {
75 class OutputLayer;
76 struct LayerFECompositionState;
77 }
78 
79 namespace impl {
80 class SurfaceInterceptor;
81 }
82 
83 namespace frametimeline {
84 class SurfaceFrame;
85 } // namespace frametimeline
86 
87 struct LayerCreationArgs {
88     LayerCreationArgs(SurfaceFlinger*, sp<Client>, std::string name, uint32_t flags, LayerMetadata);
89 
90     SurfaceFlinger* flinger;
91     const sp<Client> client;
92     std::string name;
93     uint32_t flags;
94     LayerMetadata metadata;
95 
96     pid_t callingPid;
97     uid_t callingUid;
98     uint32_t textureName;
99     std::optional<uint32_t> sequence = std::nullopt;
100     bool addToRoot = true;
101 };
102 
103 class Layer : public virtual RefBase, compositionengine::LayerFE {
104     static std::atomic<int32_t> sSequence;
105     // The following constants represent priority of the window. SF uses this information when
106     // deciding which window has a priority when deciding about the refresh rate of the screen.
107     // Priority 0 is considered the highest priority. -1 means that the priority is unset.
108     static constexpr int32_t PRIORITY_UNSET = -1;
109     // Windows that are in focus and voted for the preferred mode ID
110     static constexpr int32_t PRIORITY_FOCUSED_WITH_MODE = 0;
111     // // Windows that are in focus, but have not requested a specific mode ID.
112     static constexpr int32_t PRIORITY_FOCUSED_WITHOUT_MODE = 1;
113     // Windows that are not in focus, but voted for a specific mode ID.
114     static constexpr int32_t PRIORITY_NOT_FOCUSED_WITH_MODE = 2;
115 
116 public:
117     enum { // flags for doTransaction()
118         eDontUpdateGeometryState = 0x00000001,
119         eVisibleRegion = 0x00000002,
120         eInputInfoChanged = 0x00000004
121     };
122 
123     struct Geometry {
124         uint32_t w;
125         uint32_t h;
126         ui::Transform transform;
127 
128         inline bool operator==(const Geometry& rhs) const {
129             return (w == rhs.w && h == rhs.h) && (transform.tx() == rhs.transform.tx()) &&
130                     (transform.ty() == rhs.transform.ty());
131         }
132         inline bool operator!=(const Geometry& rhs) const { return !operator==(rhs); }
133     };
134 
135     struct RoundedCornerState {
136         RoundedCornerState() = default;
RoundedCornerStateRoundedCornerState137         RoundedCornerState(const FloatRect& cropRect, const vec2& radius)
138               : cropRect(cropRect), radius(radius) {}
139 
140         // Rounded rectangle in local layer coordinate space.
141         FloatRect cropRect = FloatRect();
142         // Radius of the rounded rectangle.
143         vec2 radius;
hasRoundedCornersRoundedCornerState144         bool hasRoundedCorners() const { return radius.x > 0.0f && radius.y > 0.0f; }
145     };
146 
147     using FrameRate = scheduler::LayerInfo::FrameRate;
148     using FrameRateCompatibility = scheduler::LayerInfo::FrameRateCompatibility;
149 
150     struct State {
151         Geometry active_legacy;
152         Geometry requested_legacy;
153         int32_t z;
154 
155         ui::LayerStack layerStack;
156 
157         uint32_t flags;
158         uint8_t reserved[2];
159         int32_t sequence; // changes when visible regions can change
160         bool modified;
161 
162         // Crop is expressed in layer space coordinate.
163         Rect crop;
164         Rect requestedCrop;
165 
166         // the transparentRegion hint is a bit special, it's latched only
167         // when we receive a buffer -- this is because it's "content"
168         // dependent.
169         Region activeTransparentRegion_legacy;
170         Region requestedTransparentRegion_legacy;
171 
172         LayerMetadata metadata;
173 
174         // If non-null, a Surface this Surface's Z-order is interpreted relative to.
175         wp<Layer> zOrderRelativeOf;
176         bool isRelativeOf{false};
177 
178         // A list of surfaces whose Z-order is interpreted relative to ours.
179         SortedVector<wp<Layer>> zOrderRelatives;
180 
181         half4 color;
182         float cornerRadius;
183         int backgroundBlurRadius;
184 
185         gui::WindowInfo inputInfo;
186         wp<Layer> touchableRegionCrop;
187 
188         // dataspace is only used by BufferStateLayer and EffectLayer
189         ui::Dataspace dataspace;
190 
191         // The fields below this point are only used by BufferStateLayer
192         uint64_t frameNumber;
193         uint32_t width;
194         uint32_t height;
195         ui::Transform transform;
196 
197         uint32_t bufferTransform;
198         bool transformToDisplayInverse;
199 
200         Region transparentRegionHint;
201 
202         std::shared_ptr<renderengine::ExternalTexture> buffer;
203         client_cache_t clientCacheId;
204         sp<Fence> acquireFence;
205         std::shared_ptr<FenceTime> acquireFenceTime;
206         HdrMetadata hdrMetadata;
207         Region surfaceDamageRegion;
208         int32_t api;
209 
210         sp<NativeHandle> sidebandStream;
211         mat4 colorTransform;
212         bool hasColorTransform;
213 
214         // pointer to background color layer that, if set, appears below the buffer state layer
215         // and the buffer state layer's children.  Z order will be set to
216         // INT_MIN
217         sp<Layer> bgColorLayer;
218 
219         // The deque of callback handles for this frame. The back of the deque contains the most
220         // recent callback handle.
221         std::deque<sp<CallbackHandle>> callbackHandles;
222         bool colorSpaceAgnostic;
223         nsecs_t desiredPresentTime = 0;
224         bool isAutoTimestamp = true;
225 
226         // Length of the cast shadow. If the radius is > 0, a shadow of length shadowRadius will
227         // be rendered around the layer.
228         float shadowRadius;
229 
230         // Layer regions that are made of custom materials, like frosted glass
231         std::vector<BlurRegion> blurRegions;
232 
233         // Priority of the layer assigned by Window Manager.
234         int32_t frameRateSelectionPriority;
235 
236         FrameRate frameRate;
237 
238         // The combined frame rate of parents / children of this layer
239         FrameRate frameRateForLayerTree;
240 
241         // Set by window manager indicating the layer and all its children are
242         // in a different orientation than the display. The hint suggests that
243         // the graphic producers should receive a transform hint as if the
244         // display was in this orientation. When the display changes to match
245         // the layer orientation, the graphic producer may not need to allocate
246         // a buffer of a different size. ui::Transform::ROT_INVALID means the
247         // a fixed transform hint is not set.
248         ui::Transform::RotationFlags fixedTransformHint;
249 
250         // The vsync info that was used to start the transaction
251         FrameTimelineInfo frameTimelineInfo;
252 
253         // When the transaction was posted
254         nsecs_t postTime;
255 
256         sp<ITransactionCompletedListener> releaseBufferListener;
257         // SurfaceFrame that tracks the timeline of Transactions that contain a Buffer. Only one
258         // such SurfaceFrame exists because only one buffer can be presented on the layer per vsync.
259         // If multiple buffers are queued, the prior ones will be dropped, along with the
260         // SurfaceFrame that's tracking them.
261         std::shared_ptr<frametimeline::SurfaceFrame> bufferSurfaceFrameTX;
262         // A map of token(frametimelineVsyncId) to the SurfaceFrame that's tracking a transaction
263         // that contains the token. Only one SurfaceFrame exisits for transactions that share the
264         // same token, unless they are presented in different vsyncs.
265         std::unordered_map<int64_t, std::shared_ptr<frametimeline::SurfaceFrame>>
266                 bufferlessSurfaceFramesTX;
267         // An arbitrary threshold for the number of BufferlessSurfaceFrames in the state. Used to
268         // trigger a warning if the number of SurfaceFrames crosses the threshold.
269         static constexpr uint32_t kStateSurfaceFramesThreshold = 25;
270 
271         // Stretch effect to apply to this layer
272         StretchEffect stretchEffect;
273 
274         // Whether or not this layer is a trusted overlay for input
275         bool isTrustedOverlay;
276 
277         Rect bufferCrop;
278         Rect destinationFrame;
279 
280         sp<IBinder> releaseBufferEndpoint;
281 
282         gui::DropInputMode dropInputMode;
283 
284         bool autoRefresh = false;
285 
286         bool dimmingEnabled = true;
287     };
288 
289     /*
290      * Trivial class, used to ensure that mFlinger->onLayerDestroyed(mLayer)
291      * is called.
292      */
293     class LayerCleaner {
294         sp<SurfaceFlinger> mFlinger;
295         sp<Layer> mLayer;
296         BBinder* mHandle;
297 
298     protected:
~LayerCleaner()299         ~LayerCleaner() {
300             // destroy client resources
301             mFlinger->onHandleDestroyed(mHandle, mLayer);
302         }
303 
304     public:
LayerCleaner(const sp<SurfaceFlinger> & flinger,const sp<Layer> & layer,BBinder * handle)305         LayerCleaner(const sp<SurfaceFlinger>& flinger, const sp<Layer>& layer, BBinder* handle)
306               : mFlinger(flinger), mLayer(layer), mHandle(handle) {}
307     };
308 
309     /*
310      * The layer handle is just a BBinder object passed to the client
311      * (remote process) -- we don't keep any reference on our side such that
312      * the dtor is called when the remote side let go of its reference.
313      *
314      * LayerCleaner ensures that mFlinger->onLayerDestroyed() is called for
315      * this layer when the handle is destroyed.
316      */
317     class Handle : public BBinder, public LayerCleaner {
318     public:
Handle(const sp<SurfaceFlinger> & flinger,const sp<Layer> & layer)319         Handle(const sp<SurfaceFlinger>& flinger, const sp<Layer>& layer)
320               : LayerCleaner(flinger, layer, this), owner(layer) {}
getInterfaceDescriptor()321         const String16& getInterfaceDescriptor() const override { return kDescriptor; }
322 
323         static const String16 kDescriptor;
324         wp<Layer> owner;
325     };
326 
327     static wp<Layer> fromHandle(const sp<IBinder>& handle);
328 
329     explicit Layer(const LayerCreationArgs& args);
330     virtual ~Layer();
331 
332     static bool isLayerFocusedBasedOnPriority(int32_t priority);
333     static void miniDumpHeader(std::string& result);
334 
335     // Provide unique string for each class type in the Layer hierarchy
336     virtual const char* getType() const = 0;
337 
338     // true if this layer is visible, false otherwise
339     virtual bool isVisible() const = 0;
340 
341     virtual sp<Layer> createClone() = 0;
342 
343     // Geometry setting functions.
344     //
345     // The following group of functions are used to specify the layers
346     // bounds, and the mapping of the texture on to those bounds. According
347     // to various settings changes to them may apply immediately, or be delayed until
348     // a pending resize is completed by the producer submitting a buffer. For example
349     // if we were to change the buffer size, and update the matrix ahead of the
350     // new buffer arriving, then we would be stretching the buffer to a different
351     // aspect before and after the buffer arriving, which probably isn't what we wanted.
352     //
353     // The first set of geometry functions are controlled by the scaling mode, described
354     // in window.h. The scaling mode may be set by the client, as it submits buffers.
355     //
356     // Put simply, if our scaling mode is SCALING_MODE_FREEZE, then
357     // matrix updates will not be applied while a resize is pending
358     // and the size and transform will remain in their previous state
359     // until a new buffer is submitted. If the scaling mode is another value
360     // then the old-buffer will immediately be scaled to the pending size
361     // and the new matrix will be immediately applied following this scaling
362     // transformation.
363 
364     // Set the default buffer size for the assosciated Producer, in pixels. This is
365     // also the rendered size of the layer prior to any transformations. Parent
366     // or local matrix transformations will not affect the size of the buffer,
367     // but may affect it's on-screen size or clipping.
368     virtual bool setSize(uint32_t w, uint32_t h);
369     // Set a 2x2 transformation matrix on the layer. This transform
370     // will be applied after parent transforms, but before any final
371     // producer specified transform.
372     virtual bool setMatrix(const layer_state_t::matrix22_t& matrix);
373 
374     // This second set of geometry attributes are controlled by
375     // setGeometryAppliesWithResize, and their default mode is to be
376     // immediate. If setGeometryAppliesWithResize is specified
377     // while a resize is pending, then update of these attributes will
378     // be delayed until the resize completes.
379 
380     // setPosition operates in parent buffer space (pre parent-transform) or display
381     // space for top-level layers.
382     virtual bool setPosition(float x, float y);
383     // Buffer space
384     virtual bool setCrop(const Rect& crop);
385 
386     // TODO(b/38182121): Could we eliminate the various latching modes by
387     // using the layer hierarchy?
388     // -----------------------------------------------------------------------
389     virtual bool setLayer(int32_t z);
390     virtual bool setRelativeLayer(const sp<IBinder>& relativeToHandle, int32_t relativeZ);
391 
392     virtual bool setAlpha(float alpha);
setColor(const half3 &)393     virtual bool setColor(const half3& /*color*/) { return false; };
394 
395     // Set rounded corner radius for this layer and its children.
396     //
397     // We only support 1 radius per layer in the hierarchy, where parent layers have precedence.
398     // The shape of the rounded corner rectangle is specified by the crop rectangle of the layer
399     // from which we inferred the rounded corner radius.
400     virtual bool setCornerRadius(float cornerRadius);
401     // When non-zero, everything below this layer will be blurred by backgroundBlurRadius, which
402     // is specified in pixels.
403     virtual bool setBackgroundBlurRadius(int backgroundBlurRadius);
404     virtual bool setBlurRegions(const std::vector<BlurRegion>& effectRegions);
405     virtual bool setTransparentRegionHint(const Region& transparent);
406     virtual bool setTrustedOverlay(bool);
407     virtual bool setFlags(uint32_t flags, uint32_t mask);
408     virtual bool setLayerStack(ui::LayerStack);
409     virtual ui::LayerStack getLayerStack() const;
410     virtual bool setMetadata(const LayerMetadata& data);
411     virtual void setChildrenDrawingParent(const sp<Layer>&);
412     virtual bool reparent(const sp<IBinder>& newParentHandle);
413     virtual bool setColorTransform(const mat4& matrix);
414     virtual mat4 getColorTransform() const;
415     virtual bool hasColorTransform() const;
isColorSpaceAgnostic()416     virtual bool isColorSpaceAgnostic() const { return mDrawingState.colorSpaceAgnostic; }
isDimmingEnabled()417     virtual bool isDimmingEnabled() const { return getDrawingState().dimmingEnabled; };
418 
419     // Used only to set BufferStateLayer state
setTransform(uint32_t)420     virtual bool setTransform(uint32_t /*transform*/) { return false; };
setTransformToDisplayInverse(bool)421     virtual bool setTransformToDisplayInverse(bool /*transformToDisplayInverse*/) { return false; };
setBuffer(std::shared_ptr<renderengine::ExternalTexture> &,const BufferData &,nsecs_t,nsecs_t,bool,std::optional<nsecs_t>,const FrameTimelineInfo &)422     virtual bool setBuffer(std::shared_ptr<renderengine::ExternalTexture>& /* buffer */,
423                            const BufferData& /* bufferData */, nsecs_t /* postTime */,
424                            nsecs_t /*desiredPresentTime*/, bool /*isAutoTimestamp*/,
425                            std::optional<nsecs_t> /* dequeueTime */,
426                            const FrameTimelineInfo& /*info*/) {
427         return false;
428     };
setDataspace(ui::Dataspace)429     virtual bool setDataspace(ui::Dataspace /*dataspace*/) { return false; };
setHdrMetadata(const HdrMetadata &)430     virtual bool setHdrMetadata(const HdrMetadata& /*hdrMetadata*/) { return false; };
setSurfaceDamageRegion(const Region &)431     virtual bool setSurfaceDamageRegion(const Region& /*surfaceDamage*/) { return false; };
setApi(int32_t)432     virtual bool setApi(int32_t /*api*/) { return false; };
setSidebandStream(const sp<NativeHandle> &)433     virtual bool setSidebandStream(const sp<NativeHandle>& /*sidebandStream*/) { return false; };
434     virtual bool setTransactionCompletedListeners(
435             const std::vector<sp<CallbackHandle>>& /*handles*/);
436     virtual bool setBackgroundColor(const half3& color, float alpha, ui::Dataspace dataspace);
437     virtual bool setColorSpaceAgnostic(const bool agnostic);
438     virtual bool setDimmingEnabled(const bool dimmingEnabled);
439     virtual bool setFrameRateSelectionPriority(int32_t priority);
440     virtual bool setFixedTransformHint(ui::Transform::RotationFlags fixedTransformHint);
setAutoRefresh(bool)441     virtual void setAutoRefresh(bool /* autoRefresh */) {}
442     bool setDropInputMode(gui::DropInputMode);
443 
444     //  If the variable is not set on the layer, it traverses up the tree to inherit the frame
445     //  rate priority from its parent.
446     virtual int32_t getFrameRateSelectionPriority() const;
getDataSpace()447     virtual ui::Dataspace getDataSpace() const { return ui::Dataspace::UNKNOWN; }
448 
449     virtual sp<compositionengine::LayerFE> getCompositionEngineLayerFE() const;
450     virtual compositionengine::LayerFECompositionState* editCompositionState();
451 
452     // If we have received a new buffer this frame, we will pass its surface
453     // damage down to hardware composer. Otherwise, we must send a region with
454     // one empty rect.
useSurfaceDamage()455     virtual void useSurfaceDamage() {}
useEmptyDamage()456     virtual void useEmptyDamage() {}
457     Region getVisibleRegion(const DisplayDevice*) const;
458 
459     /*
460      * isOpaque - true if this surface is opaque
461      *
462      * This takes into account the buffer format (i.e. whether or not the
463      * pixel format includes an alpha channel) and the "opaque" flag set
464      * on the layer.  It does not examine the current plane alpha value.
465      */
isOpaque(const Layer::State &)466     virtual bool isOpaque(const Layer::State&) const { return false; }
467 
468     /*
469      * Returns whether this layer can receive input.
470      */
471     virtual bool canReceiveInput() const;
472 
473     /*
474      * isProtected - true if the layer may contain protected contents in the
475      * GRALLOC_USAGE_PROTECTED sense.
476      */
isProtected()477     virtual bool isProtected() const { return false; }
478 
479     /*
480      * isFixedSize - true if content has a fixed size
481      */
isFixedSize()482     virtual bool isFixedSize() const { return true; }
483 
484     /*
485      * usesSourceCrop - true if content should use a source crop
486      */
usesSourceCrop()487     virtual bool usesSourceCrop() const { return false; }
488 
489     // Most layers aren't created from the main thread, and therefore need to
490     // grab the SF state lock to access HWC, but ContainerLayer does, so we need
491     // to avoid grabbing the lock again to avoid deadlock
isCreatedFromMainThread()492     virtual bool isCreatedFromMainThread() const { return false; }
493 
getActiveWidth(const Layer::State & s)494     uint32_t getActiveWidth(const Layer::State& s) const { return s.width; }
getActiveHeight(const Layer::State & s)495     uint32_t getActiveHeight(const Layer::State& s) const { return s.height; }
getActiveTransform(const Layer::State & s)496     ui::Transform getActiveTransform(const Layer::State& s) const { return s.transform; }
getActiveTransparentRegion(const Layer::State & s)497     virtual Region getActiveTransparentRegion(const Layer::State& s) const {
498         return s.activeTransparentRegion_legacy;
499     }
getCrop(const Layer::State & s)500     virtual Rect getCrop(const Layer::State& s) const { return s.crop; }
needsFiltering(const DisplayDevice *)501     virtual bool needsFiltering(const DisplayDevice*) const { return false; }
502 
503     // True if this layer requires filtering
504     // This method is distinct from needsFiltering() in how the filter
505     // requirement is computed. needsFiltering() compares displayFrame and crop,
506     // where as this method transforms the displayFrame to layer-stack space
507     // first. This method should be used if there is no physical display to
508     // project onto when taking screenshots, as the filtering requirements are
509     // different.
510     // If the parent transform needs to be undone when capturing the layer, then
511     // the inverse parent transform is also required.
needsFilteringForScreenshots(const DisplayDevice *,const ui::Transform &)512     virtual bool needsFilteringForScreenshots(const DisplayDevice*, const ui::Transform&) const {
513         return false;
514     }
515 
updateCloneBufferInfo()516     virtual void updateCloneBufferInfo(){};
517 
setDefaultBufferSize(uint32_t,uint32_t)518     virtual void setDefaultBufferSize(uint32_t /*w*/, uint32_t /*h*/) {}
519 
isHdrY410()520     virtual bool isHdrY410() const { return false; }
521 
shouldPresentNow(nsecs_t)522     virtual bool shouldPresentNow(nsecs_t /*expectedPresentTime*/) const { return false; }
523 
524     /*
525      * called after composition.
526      * returns true if the layer latched a new buffer this frame.
527      */
onPostComposition(const DisplayDevice *,const std::shared_ptr<FenceTime> &,const std::shared_ptr<FenceTime> &,const CompositorTiming &)528     virtual void onPostComposition(const DisplayDevice*,
529                                    const std::shared_ptr<FenceTime>& /*glDoneFence*/,
530                                    const std::shared_ptr<FenceTime>& /*presentFence*/,
531                                    const CompositorTiming&) {}
532 
533     // If a buffer was replaced this frame, release the former buffer
releasePendingBuffer(nsecs_t)534     virtual void releasePendingBuffer(nsecs_t /*dequeueReadyTime*/) { }
535 
finalizeFrameEventHistory(const std::shared_ptr<FenceTime> &,const CompositorTiming &)536     virtual void finalizeFrameEventHistory(const std::shared_ptr<FenceTime>& /*glDoneFence*/,
537                                            const CompositorTiming& /*compositorTiming*/) {}
538 
539     /*
540      * latchBuffer - called each time the screen is redrawn and returns whether
541      * the visible regions need to be recomputed (this is a fairly heavy
542      * operation, so this should be set only if needed). Typically this is used
543      * to figure out if the content or size of a surface has changed.
544      */
latchBuffer(bool &,nsecs_t,nsecs_t)545     virtual bool latchBuffer(bool& /*recomputeVisibleRegions*/, nsecs_t /*latchTime*/,
546                              nsecs_t /*expectedPresentTime*/) {
547         return false;
548     }
549 
latchAndReleaseBuffer()550     virtual void latchAndReleaseBuffer() {}
551 
552     /*
553      * returns the rectangle that crops the content of the layer and scales it
554      * to the layer's size.
555      */
getBufferCrop()556     virtual Rect getBufferCrop() const { return Rect(); }
557 
558     /*
559      * Returns the transform applied to the buffer.
560      */
getBufferTransform()561     virtual uint32_t getBufferTransform() const { return 0; }
562 
getBuffer()563     virtual sp<GraphicBuffer> getBuffer() const { return nullptr; }
getExternalTexture()564     virtual const std::shared_ptr<renderengine::ExternalTexture>& getExternalTexture() const {
565         return mDrawingState.buffer;
566     };
567 
getTransformHint()568     virtual ui::Transform::RotationFlags getTransformHint() const { return ui::Transform::ROT_0; }
569 
570     /*
571      * Returns if a frame is ready
572      */
hasReadyFrame()573     virtual bool hasReadyFrame() const { return false; }
574 
getQueuedFrameCount()575     virtual int32_t getQueuedFrameCount() const { return 0; }
576 
577     /**
578      * Returns active buffer size in the correct orientation. Buffer size is determined by undoing
579      * any buffer transformations. If the layer has no buffer then return INVALID_RECT.
580      */
getBufferSize(const Layer::State &)581     virtual Rect getBufferSize(const Layer::State&) const { return Rect::INVALID_RECT; }
582 
583     /**
584      * Returns the source bounds. If the bounds are not defined, it is inferred from the
585      * buffer size. Failing that, the bounds are determined from the passed in parent bounds.
586      * For the root layer, this is the display viewport size.
587      */
computeSourceBounds(const FloatRect & parentBounds)588     virtual FloatRect computeSourceBounds(const FloatRect& parentBounds) const {
589         return parentBounds;
590     }
591     virtual FrameRate getFrameRateForLayerTree() const;
592 
getTransformToDisplayInverse()593     virtual bool getTransformToDisplayInverse() const { return false; }
594 
595     // Returns how rounded corners should be drawn for this layer.
596     // A layer can override its parent's rounded corner settings if the parent's rounded
597     // corner crop does not intersect with its own rounded corner crop.
598     virtual RoundedCornerState getRoundedCornerState() const;
599 
hasRoundedCorners()600     bool hasRoundedCorners() const override { return getRoundedCornerState().hasRoundedCorners(); }
601 
getPixelFormat()602     virtual PixelFormat getPixelFormat() const { return PIXEL_FORMAT_NONE; }
603     /**
604      * Return whether this layer needs an input info. For most layer types
605      * this is only true if they explicitly set an input-info but BufferLayer
606      * overrides this so we can generate input-info for Buffered layers that don't
607      * have them (for input occlusion detection checks).
608      */
needsInputInfo()609     virtual bool needsInputInfo() const { return hasInputInfo(); }
610 
611     // Implements RefBase.
612     void onFirstRef() override;
613 
614     // implements compositionengine::LayerFE
615     const compositionengine::LayerFECompositionState* getCompositionState() const override;
616     bool onPreComposition(nsecs_t) override;
617     void prepareCompositionState(compositionengine::LayerFE::StateSubset subset) override;
618     std::vector<compositionengine::LayerFE::LayerSettings> prepareClientCompositionList(
619             compositionengine::LayerFE::ClientCompositionTargetSettings&) override;
620     void onLayerDisplayed(ftl::SharedFuture<FenceResult>) override;
621 
setWasClientComposed(const sp<Fence> & fence)622     void setWasClientComposed(const sp<Fence>& fence) override {
623         mLastClientCompositionFence = fence;
624         mClearClientCompositionFenceOnLayerDisplayed = false;
625     }
626 
627     const char* getDebugName() const override;
628 
629     bool setShadowRadius(float shadowRadius);
630 
631     // Before color management is introduced, contents on Android have to be
632     // desaturated in order to match what they appears like visually.
633     // With color management, these contents will appear desaturated, thus
634     // needed to be saturated so that they match what they are designed for
635     // visually.
636     bool isLegacyDataSpace() const;
637 
getTransactionFlags()638     uint32_t getTransactionFlags() const { return mTransactionFlags; }
639 
640     // Sets the masked bits.
641     void setTransactionFlags(uint32_t mask);
642 
643     // Clears and returns the masked bits.
644     uint32_t clearTransactionFlags(uint32_t mask);
645 
646     FloatRect getBounds(const Region& activeTransparentRegion) const;
647     FloatRect getBounds() const;
648 
649     // Compute bounds for the layer and cache the results.
650     void computeBounds(FloatRect parentBounds, ui::Transform parentTransform, float shadowRadius);
651 
getSequence()652     int32_t getSequence() const override { return sequence; }
653 
654     // For tracing.
655     // TODO: Replace with raw buffer id from buffer metadata when that becomes available.
656     // GraphicBuffer::getId() does not provide a reliable global identifier. Since the traces
657     // creates its tracks by buffer id and has no way of associating a buffer back to the process
658     // that created it, the current implementation is only sufficient for cases where a buffer is
659     // only used within a single layer.
getCurrentBufferId()660     uint64_t getCurrentBufferId() const { return getBuffer() ? getBuffer()->getId() : 0; }
661 
662     /*
663      * isSecure - true if this surface is secure, that is if it prevents
664      * screenshots or VNC servers. A surface can be set to be secure by the
665      * application, being secure doesn't mean the surface has DRM contents.
666      */
667     bool isSecure() const;
668 
669     /*
670      * isHiddenByPolicy - true if this layer has been forced invisible.
671      * just because this is false, doesn't mean isVisible() is true.
672      * For example if this layer has no active buffer, it may not be hidden by
673      * policy, but it still can not be visible.
674      */
675     bool isHiddenByPolicy() const;
676 
677     // True if the layer should be skipped in screenshots, screen recordings,
678     // and mirroring to external or virtual displays.
679     bool isInternalDisplayOverlay() const;
680 
getOutputFilter()681     ui::LayerFilter getOutputFilter() const {
682         return {getLayerStack(), isInternalDisplayOverlay()};
683     }
684 
685     bool isRemovedFromCurrentState() const;
686 
687     LayerProto* writeToProto(LayersProto& layersProto, uint32_t traceFlags);
688 
689     // Write states that are modified by the main thread. This includes drawing
690     // state as well as buffer data. This should be called in the main or tracing
691     // thread.
692     void writeToProtoDrawingState(LayerProto* layerInfo);
693     // Write drawing or current state. If writing current state, the caller should hold the
694     // external mStateLock. If writing drawing state, this function should be called on the
695     // main or tracing thread.
696     void writeToProtoCommonState(LayerProto* layerInfo, LayerVector::StateSet,
697                                  uint32_t traceFlags = LayerTracing::TRACE_ALL);
698 
getWindowType()699     gui::WindowInfo::Type getWindowType() const { return mWindowType; }
700 
701     void updateMirrorInfo();
702 
703     /*
704      * doTransaction - process the transaction. This is a good place to figure
705      * out which attributes of the surface have changed.
706      */
707     virtual uint32_t doTransaction(uint32_t transactionFlags);
708 
709     /*
710      * Remove relative z for the layer if its relative parent is not part of the
711      * provided layer tree.
712      */
713     void removeRelativeZ(const std::vector<Layer*>& layersInTree);
714 
715     /*
716      * Remove from current state and mark for removal.
717      */
718     void removeFromCurrentState();
719 
720     /*
721      * called with the state lock from a binder thread when the layer is
722      * removed from the current list to the pending removal list
723      */
724     void onRemovedFromCurrentState();
725 
726     /*
727      * Called when the layer is added back to the current state list.
728      */
729     void addToCurrentState();
730 
731     /*
732      * Sets display transform hint on BufferLayerConsumer.
733      */
734     void updateTransformHint(ui::Transform::RotationFlags);
735 
getDrawingState()736     inline const State& getDrawingState() const { return mDrawingState; }
getDrawingState()737     inline State& getDrawingState() { return mDrawingState; }
738 
739     LayerDebugInfo getLayerDebugInfo(const DisplayDevice*) const;
740 
741     void miniDump(std::string& result, const DisplayDevice&) const;
742     void dumpFrameStats(std::string& result) const;
743     void dumpCallingUidPid(std::string& result) const;
744     void clearFrameStats();
745     void logFrameStats();
746     void getFrameStats(FrameStats* outStats) const;
747     void onDisconnect();
748 
749     ui::Transform getTransform() const;
750     bool isTransformValid() const;
751 
752     // Returns the Alpha of the Surface, accounting for the Alpha
753     // of parent Surfaces in the hierarchy (alpha's will be multiplied
754     // down the hierarchy).
755     half getAlpha() const;
756     half4 getColor() const;
757     int32_t getBackgroundBlurRadius() const;
drawShadows()758     bool drawShadows() const { return mEffectiveShadowRadius > 0.f; };
759 
760     // Returns the transform hint set by Window Manager on the layer or one of its parents.
761     // This traverses the current state because the data is needed when creating
762     // the layer(off drawing thread) and the hint should be available before the producer
763     // is ready to acquire a buffer.
764     ui::Transform::RotationFlags getFixedTransformHint() const;
765 
766     /**
767      * Traverse this layer and it's hierarchy of children directly. Unlike traverseInZOrder
768      * which will not emit children who have relativeZOrder to another layer, this method
769      * just directly emits all children. It also emits them in no particular order.
770      * So this method is not suitable for graphical operations, as it doesn't represent
771      * the scene state, but it's also more efficient than traverseInZOrder and so useful for
772      * book-keeping.
773      */
774     void traverse(LayerVector::StateSet, const LayerVector::Visitor&);
775     void traverseInReverseZOrder(LayerVector::StateSet, const LayerVector::Visitor&);
776     void traverseInZOrder(LayerVector::StateSet, const LayerVector::Visitor&);
777 
778     /**
779      * Traverse only children in z order, ignoring relative layers that are not children of the
780      * parent.
781      */
782     void traverseChildrenInZOrder(LayerVector::StateSet, const LayerVector::Visitor&);
783 
784     size_t getChildrenCount() const;
785 
786     // ONLY CALL THIS FROM THE LAYER DTOR!
787     // See b/141111965.  We need to add current children to offscreen layers in
788     // the layer dtor so as not to dangle layers.  Since the layer has not
789     // committed its transaction when the layer is destroyed, we must add
790     // current children.  This is safe in the dtor as we will no longer update
791     // the current state, but should not be called anywhere else!
getCurrentChildren()792     LayerVector& getCurrentChildren() { return mCurrentChildren; }
793 
794     void addChild(const sp<Layer>&);
795     // Returns index if removed, or negative value otherwise
796     // for symmetry with Vector::remove
797     ssize_t removeChild(const sp<Layer>& layer);
getParent()798     sp<Layer> getParent() const { return mCurrentParent.promote(); }
799 
800     // Should be called with the surfaceflinger statelock held
isAtRoot()801     bool isAtRoot() const { return mIsAtRoot; }
setIsAtRoot(bool isAtRoot)802     void setIsAtRoot(bool isAtRoot) { mIsAtRoot = isAtRoot; }
803 
hasParent()804     bool hasParent() const { return getParent() != nullptr; }
805     Rect getScreenBounds(bool reduceTransparentRegion = true) const;
806     bool setChildLayer(const sp<Layer>& childLayer, int32_t z);
807     bool setChildRelativeLayer(const sp<Layer>& childLayer,
808             const sp<IBinder>& relativeToHandle, int32_t relativeZ);
809 
810     // Copy the current list of children to the drawing state. Called by
811     // SurfaceFlinger to complete a transaction.
812     void commitChildList();
813     int32_t getZ(LayerVector::StateSet) const;
814 
815     /**
816      * Returns the cropped buffer size or the layer crop if the layer has no buffer. Return
817      * INVALID_RECT if the layer has no buffer and no crop.
818      * A layer with an invalid buffer size and no crop is considered to be boundless. The layer
819      * bounds are constrained by its parent bounds.
820      */
821     Rect getCroppedBufferSize(const Layer::State& s) const;
822 
823     bool setFrameRate(FrameRate);
824 
setFrameTimelineInfoForBuffer(const FrameTimelineInfo &)825     virtual void setFrameTimelineInfoForBuffer(const FrameTimelineInfo& /*info*/) {}
826     void setFrameTimelineVsyncForBufferTransaction(const FrameTimelineInfo& info, nsecs_t postTime);
827     void setFrameTimelineVsyncForBufferlessTransaction(const FrameTimelineInfo& info,
828                                                        nsecs_t postTime);
829 
830     void addSurfaceFrameDroppedForBuffer(
831             std::shared_ptr<frametimeline::SurfaceFrame>& surfaceFrame);
832     void addSurfaceFramePresentedForBuffer(
833             std::shared_ptr<frametimeline::SurfaceFrame>& surfaceFrame, nsecs_t acquireFenceTime,
834             nsecs_t currentLatchTime);
835 
836     std::shared_ptr<frametimeline::SurfaceFrame> createSurfaceFrameForTransaction(
837             const FrameTimelineInfo& info, nsecs_t postTime);
838     std::shared_ptr<frametimeline::SurfaceFrame> createSurfaceFrameForBuffer(
839             const FrameTimelineInfo& info, nsecs_t queueTime, std::string debugName);
840 
841     // Creates a new handle each time, so we only expect
842     // this to be called once.
843     sp<IBinder> getHandle();
getName()844     const std::string& getName() const { return mName; }
845     bool getPremultipledAlpha() const;
846     void setInputInfo(const gui::WindowInfo& info);
847 
848     struct InputDisplayArgs {
849         const ui::Transform* transform = nullptr;
850         bool isSecure = false;
851     };
852     gui::WindowInfo fillInputInfo(const InputDisplayArgs& displayArgs);
853 
854     /**
855      * Returns whether this layer has an explicitly set input-info.
856      */
857     bool hasInputInfo() const;
858 
859     // Sets the GameMode for the tree rooted at this layer. A layer in the tree inherits this
860     // GameMode unless it (or an ancestor) has GAME_MODE_METADATA.
861     void setGameModeForTree(GameMode);
862 
setGameMode(GameMode gameMode)863     void setGameMode(GameMode gameMode) { mGameMode = gameMode; }
getGameMode()864     GameMode getGameMode() const { return mGameMode; }
865 
getOwnerUid()866     virtual uid_t getOwnerUid() const { return mOwnerUid; }
867 
getOwnerPid()868     pid_t getOwnerPid() { return mOwnerPid; }
869 
870     // This layer is not a clone, but it's the parent to the cloned hierarchy. The
871     // variable mClonedChild represents the top layer that will be cloned so this
872     // layer will be the parent of mClonedChild.
873     // The layers in the cloned hierarchy will match the lifetime of the real layers. That is
874     // if the real layer is destroyed, then the clone layer will also be destroyed.
875     sp<Layer> mClonedChild;
876     bool mHadClonedChild = false;
877     void setClonedChild(const sp<Layer>& mClonedChild);
878 
879     mutable bool contentDirty{false};
880     Region surfaceDamageRegion;
881 
882     // Layer serial number.  This gives layers an explicit ordering, so we
883     // have a stable sort order when their layer stack and Z-order are
884     // the same.
885     const int32_t sequence;
886 
887     bool mPendingHWCDestroy{false};
888 
backpressureEnabled()889     bool backpressureEnabled() { return mDrawingState.flags & layer_state_t::eEnableBackpressure; }
890 
891     bool setStretchEffect(const StretchEffect& effect);
892     StretchEffect getStretchEffect() const;
893 
setBufferCrop(const Rect &)894     virtual bool setBufferCrop(const Rect& /* bufferCrop */) { return false; }
setDestinationFrame(const Rect &)895     virtual bool setDestinationFrame(const Rect& /* destinationFrame */) { return false; }
getPendingBufferCounter()896     virtual std::atomic<int32_t>* getPendingBufferCounter() { return nullptr; }
getPendingBufferCounterName()897     virtual std::string getPendingBufferCounterName() { return ""; }
updateGeometry()898     virtual bool updateGeometry() { return false; }
899 
simpleBufferUpdate(const layer_state_t &)900     virtual bool simpleBufferUpdate(const layer_state_t&) const { return false; }
901 
902 protected:
903     friend class impl::SurfaceInterceptor;
904 
905     // For unit tests
906     friend class TestableSurfaceFlinger;
907     friend class FpsReporterTest;
908     friend class RefreshRateSelectionTest;
909     friend class SetFrameRateTest;
910     friend class TransactionFrameTracerTest;
911     friend class TransactionSurfaceFrameTest;
912 
913     virtual void setInitialValuesForClone(const sp<Layer>& clonedFrom);
914     virtual std::optional<compositionengine::LayerFE::LayerSettings> prepareClientComposition(
915             compositionengine::LayerFE::ClientCompositionTargetSettings&);
916     virtual void preparePerFrameCompositionState();
917     virtual void commitTransaction(State& stateToCommit);
onSurfaceFrameCreated(const std::shared_ptr<frametimeline::SurfaceFrame> &)918     virtual void onSurfaceFrameCreated(const std::shared_ptr<frametimeline::SurfaceFrame>&) {}
919 
920     // Returns mCurrentScaling mode (originating from the
921     // Client) or mOverrideScalingMode mode (originating from
922     // the Surface Controller) if set.
getEffectiveScalingMode()923     virtual uint32_t getEffectiveScalingMode() const { return 0; }
924 
925     sp<compositionengine::LayerFE> asLayerFE() const;
getClonedFrom()926     sp<Layer> getClonedFrom() { return mClonedFrom != nullptr ? mClonedFrom.promote() : nullptr; }
isClone()927     bool isClone() { return mClonedFrom != nullptr; }
isClonedFromAlive()928     bool isClonedFromAlive() { return getClonedFrom() != nullptr; }
929 
930     void cloneDrawingState(const Layer* from);
931     void updateClonedDrawingState(std::map<sp<Layer>, sp<Layer>>& clonedLayersMap);
932     void updateClonedChildren(const sp<Layer>& mirrorRoot,
933                               std::map<sp<Layer>, sp<Layer>>& clonedLayersMap);
934     void updateClonedRelatives(const std::map<sp<Layer>, sp<Layer>>& clonedLayersMap);
935     void addChildToDrawing(const sp<Layer>&);
936     void updateClonedInputInfo(const std::map<sp<Layer>, sp<Layer>>& clonedLayersMap);
937 
938     // Modifies the passed in layer settings to clear the contents. If the blackout flag is set,
939     // the settings clears the content with a solid black fill.
940     void prepareClearClientComposition(LayerFE::LayerSettings&, bool blackout) const;
941     void prepareShadowClientComposition(LayerFE::LayerSettings& caster, const Rect& layerStackRect);
942 
943     void prepareBasicGeometryCompositionState();
944     void prepareGeometryCompositionState();
945     void prepareCursorCompositionState();
946 
947     uint32_t getEffectiveUsage(uint32_t usage) const;
948 
949     /**
950      * Setup rounded corners coordinates of this layer, taking into account the layer bounds and
951      * crop coordinates, transforming them into layer space.
952      */
953     void setupRoundedCornersCropCoordinates(Rect win, const FloatRect& roundedCornersCrop) const;
954     void setParent(const sp<Layer>&);
955     LayerVector makeTraversalList(LayerVector::StateSet, bool* outSkipRelativeZUsers);
956     void addZOrderRelative(const wp<Layer>& relative);
957     void removeZOrderRelative(const wp<Layer>& relative);
958     compositionengine::OutputLayer* findOutputLayerForDisplay(const DisplayDevice*) const;
959     bool usingRelativeZ(LayerVector::StateSet) const;
960 
961     virtual ui::Transform getInputTransform() const;
962     /**
963      * Get the bounds in layer space within which this layer can receive input.
964      *
965      * These bounds are used to:
966      * - Determine the input frame for the layer to be used for occlusion detection; and
967      * - Determine the coordinate space within which the layer will receive input. The top-left of
968      *   this rect will be the origin of the coordinate space that the input events sent to the
969      *   layer will be in (prior to accounting for surface insets).
970      *
971      * The layer can still receive touch input if these bounds are invalid if
972      * "replaceTouchableRegionWithCrop" is specified. In this case, the layer will receive input
973      * in this layer's space, regardless of the specified crop layer.
974      */
975     virtual Rect getInputBounds() const;
976 
977     // constant
978     sp<SurfaceFlinger> mFlinger;
979 
980     bool mPremultipliedAlpha{true};
981     const std::string mName;
982     const std::string mTransactionName{"TX - " + mName};
983 
984     // These are only accessed by the main thread or the tracing thread.
985     State mDrawingState;
986 
987     uint32_t mTransactionFlags{0};
988     // Updated in doTransaction, used to track the last sequence number we
989     // committed. Currently this is really only used for updating visible
990     // regions.
991     int32_t mLastCommittedTxSequence = -1;
992 
993     // Timestamp history for UIAutomation. Thread safe.
994     FrameTracker mFrameTracker;
995 
996     // main thread
997     sp<NativeHandle> mSidebandStream;
998     // False if the buffer and its contents have been previously used for GPU
999     // composition, true otherwise.
1000     bool mIsActiveBufferUpdatedForGpu = true;
1001 
1002     // We encode unset as -1.
1003     std::atomic<uint64_t> mCurrentFrameNumber{0};
1004     // Whether filtering is needed b/c of the drawingstate
1005     bool mNeedsFiltering{false};
1006 
1007     std::atomic<bool> mRemovedFromDrawingState{false};
1008 
1009     // page-flip thread (currently main thread)
1010     bool mProtectedByApp{false}; // application requires protected path to external sink
1011 
1012     // protected by mLock
1013     mutable Mutex mLock;
1014 
1015     const wp<Client> mClientRef;
1016 
1017     // This layer can be a cursor on some displays.
1018     bool mPotentialCursor{false};
1019 
1020     LayerVector mCurrentChildren{LayerVector::StateSet::Current};
1021     LayerVector mDrawingChildren{LayerVector::StateSet::Drawing};
1022 
1023     wp<Layer> mCurrentParent;
1024     wp<Layer> mDrawingParent;
1025 
1026     // Window types from WindowManager.LayoutParams
1027     const gui::WindowInfo::Type mWindowType;
1028 
1029     // The owner of the layer. If created from a non system process, it will be the calling uid.
1030     // If created from a system process, the value can be passed in.
1031     uid_t mOwnerUid;
1032 
1033     // The owner pid of the layer. If created from a non system process, it will be the calling pid.
1034     // If created from a system process, the value can be passed in.
1035     pid_t mOwnerPid;
1036 
1037     // Keeps track of the time SF latched the last buffer from this layer.
1038     // Used in buffer stuffing analysis in FrameTimeline.
1039     nsecs_t mLastLatchTime = 0;
1040 
1041     mutable bool mDrawingStateModified = false;
1042 
1043     sp<Fence> mLastClientCompositionFence;
1044     bool mClearClientCompositionFenceOnLayerDisplayed = false;
1045 private:
setTransformHint(ui::Transform::RotationFlags)1046     virtual void setTransformHint(ui::Transform::RotationFlags) {}
1047 
1048     // Returns true if the layer can draw shadows on its border.
canDrawShadows()1049     virtual bool canDrawShadows() const { return true; }
1050 
1051     aidl::android::hardware::graphics::composer3::Composition getCompositionType(
1052             const DisplayDevice&) const;
1053 
1054     /**
1055      * Returns an unsorted vector of all layers that are part of this tree.
1056      * That includes the current layer and all its descendants.
1057      */
1058     std::vector<Layer*> getLayersInTree(LayerVector::StateSet);
1059     /**
1060      * Traverses layers that are part of this tree in the correct z order.
1061      * layersInTree must be sorted before calling this method.
1062      */
1063     void traverseChildrenInZOrderInner(const std::vector<Layer*>& layersInTree,
1064                                        LayerVector::StateSet, const LayerVector::Visitor&);
1065     LayerVector makeChildrenTraversalList(LayerVector::StateSet,
1066                                           const std::vector<Layer*>& layersInTree);
1067 
1068     void updateTreeHasFrameRateVote();
1069     bool propagateFrameRateForLayerTree(FrameRate parentFrameRate, bool* transactionNeeded);
1070     bool setFrameRateForLayerTree(FrameRate);
1071     void setZOrderRelativeOf(const wp<Layer>& relativeOf);
1072     bool isTrustedOverlay() const;
1073     gui::DropInputMode getDropInputMode() const;
1074     void handleDropInputMode(gui::WindowInfo& info) const;
1075 
1076     // Find the root of the cloned hierarchy, this means the first non cloned parent.
1077     // This will return null if first non cloned parent is not found.
1078     sp<Layer> getClonedRoot();
1079 
1080     // Finds the top most layer in the hierarchy. This will find the root Layer where the parent is
1081     // null.
1082     sp<Layer> getRootLayer();
1083 
1084     // Fills in the touch occlusion mode of the first parent (including this layer) that
1085     // hasInputInfo() or no-op if no such parent is found.
1086     void fillTouchOcclusionMode(gui::WindowInfo& info);
1087 
1088     // Fills in the frame and transform info for the gui::WindowInfo.
1089     void fillInputFrameInfo(gui::WindowInfo&, const ui::Transform& screenToDisplay);
1090 
1091     // Cached properties computed from drawing state
1092     // Effective transform taking into account parent transforms and any parent scaling, which is
1093     // a transform from the current layer coordinate space to display(screen) coordinate space.
1094     ui::Transform mEffectiveTransform;
1095 
1096     // Bounds of the layer before any transformation is applied and before it has been cropped
1097     // by its parents.
1098     FloatRect mSourceBounds;
1099 
1100     // Bounds of the layer in layer space. This is the mSourceBounds cropped by its layer crop and
1101     // its parent bounds.
1102     FloatRect mBounds;
1103 
1104     // Layer bounds in screen space.
1105     FloatRect mScreenBounds;
1106 
1107     bool mGetHandleCalled = false;
1108 
1109     // Tracks the process and user id of the caller when creating this layer
1110     // to help debugging.
1111     pid_t mCallingPid;
1112     uid_t mCallingUid;
1113 
1114     // The current layer is a clone of mClonedFrom. This means that this layer will update it's
1115     // properties based on mClonedFrom. When mClonedFrom latches a new buffer for BufferLayers,
1116     // this layer will update it's buffer. When mClonedFrom updates it's drawing state, children,
1117     // and relatives, this layer will update as well.
1118     wp<Layer> mClonedFrom;
1119 
1120     // The inherited shadow radius after taking into account the layer hierarchy. This is the
1121     // final shadow radius for this layer. If a shadow is specified for a layer, then effective
1122     // shadow radius is the set shadow radius, otherwise its the parent's shadow radius.
1123     float mEffectiveShadowRadius = 0.f;
1124 
1125     // Game mode for the layer. Set by WindowManagerShell and recorded by SurfaceFlingerStats.
1126     GameMode mGameMode = GameMode::Unsupported;
1127 
1128     // A list of regions on this layer that should have blurs.
1129     const std::vector<BlurRegion> getBlurRegions() const;
1130 
1131     bool mIsAtRoot = false;
1132 
1133     uint32_t mLayerCreationFlags;
1134     bool findInHierarchy(const sp<Layer>&);
1135 };
1136 
1137 std::ostream& operator<<(std::ostream& stream, const Layer::FrameRate& rate);
1138 
1139 } // namespace android
1140