xref: /aosp_15_r20/frameworks/native/services/surfaceflinger/Layer.h (revision 38e8c45f13ce32b0dcecb25141ffecaf386fa17f)
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 <android/gui/ISurfaceComposerClient.h>
21 #include <com_android_graphics_surfaceflinger_flags.h>
22 #include <ftl/small_map.h>
23 #include <gui/BufferQueue.h>
24 #include <gui/LayerState.h>
25 #include <gui/WindowInfo.h>
26 #include <layerproto/LayerProtoHeader.h>
27 #include <math/vec4.h>
28 #include <sys/types.h>
29 #include <ui/BlurRegion.h>
30 #include <ui/DisplayMap.h>
31 #include <ui/FloatRect.h>
32 #include <ui/FrameStats.h>
33 #include <ui/GraphicBuffer.h>
34 #include <ui/LayerStack.h>
35 #include <ui/PixelFormat.h>
36 #include <ui/Region.h>
37 #include <ui/StretchEffect.h>
38 #include <ui/Transform.h>
39 #include <utils/RefBase.h>
40 #include <utils/Timers.h>
41 
42 #include <compositionengine/LayerFE.h>
43 #include <compositionengine/LayerFECompositionState.h>
44 #include <scheduler/Fps.h>
45 #include <scheduler/Seamlessness.h>
46 
47 #include <cstdint>
48 #include <functional>
49 #include <optional>
50 #include <vector>
51 
52 #include "Client.h"
53 #include "DisplayHardware/HWComposer.h"
54 #include "FrameTracker.h"
55 #include "LayerFE.h"
56 #include "LayerVector.h"
57 #include "Scheduler/LayerInfo.h"
58 #include "SurfaceFlinger.h"
59 #include "TransactionCallbackInvoker.h"
60 
61 using namespace android::surfaceflinger;
62 
63 namespace android {
64 
65 class Client;
66 class Colorizer;
67 class DisplayDevice;
68 class GraphicBuffer;
69 class SurfaceFlinger;
70 
71 namespace compositionengine {
72 class OutputLayer;
73 struct LayerFECompositionState;
74 }
75 
76 namespace frametimeline {
77 class SurfaceFrame;
78 } // namespace frametimeline
79 
80 class Layer : public virtual RefBase {
81 public:
82     // The following constants represent priority of the window. SF uses this information when
83     // deciding which window has a priority when deciding about the refresh rate of the screen.
84     // Priority 0 is considered the highest priority. -1 means that the priority is unset.
85     static constexpr int32_t PRIORITY_UNSET = -1;
86     // Windows that are in focus and voted for the preferred mode ID
87     static constexpr int32_t PRIORITY_FOCUSED_WITH_MODE = 0;
88     // // Windows that are in focus, but have not requested a specific mode ID.
89     static constexpr int32_t PRIORITY_FOCUSED_WITHOUT_MODE = 1;
90     // Windows that are not in focus, but voted for a specific mode ID.
91     static constexpr int32_t PRIORITY_NOT_FOCUSED_WITH_MODE = 2;
92 
93     using FrameRate = scheduler::LayerInfo::FrameRate;
94     using FrameRateCompatibility = scheduler::FrameRateCompatibility;
95     using FrameRateSelectionStrategy = scheduler::LayerInfo::FrameRateSelectionStrategy;
96 
97     struct State {
98         int32_t sequence; // changes when visible regions can change
99         // Crop is expressed in layer space coordinate.
100         FloatRect crop;
101         LayerMetadata metadata;
102 
103         ui::Dataspace dataspace;
104 
105         uint64_t frameNumber;
106         uint64_t previousFrameNumber;
107         // high watermark framenumber to use to check for barriers to protect ourselves
108         // from out of order transactions
109         uint64_t barrierFrameNumber;
110         ui::Transform transform;
111 
112         uint32_t producerId = 0;
113         // high watermark producerId to use to check for barriers to protect ourselves
114         // from out of order transactions
115         uint32_t barrierProducerId = 0;
116 
117         uint32_t bufferTransform;
118         bool transformToDisplayInverse;
119         Region transparentRegionHint;
120         std::shared_ptr<renderengine::ExternalTexture> buffer;
121         sp<Fence> acquireFence;
122         std::shared_ptr<FenceTime> acquireFenceTime;
123         sp<NativeHandle> sidebandStream;
124         mat4 colorTransform;
125 
126         // The deque of callback handles for this frame. The back of the deque contains the most
127         // recent callback handle.
128         std::deque<sp<CallbackHandle>> callbackHandles;
129         nsecs_t desiredPresentTime = 0;
130         bool isAutoTimestamp = true;
131 
132         // The combined frame rate of parents / children of this layer
133         FrameRate frameRateForLayerTree;
134 
135         // The vsync info that was used to start the transaction
136         FrameTimelineInfo frameTimelineInfo;
137 
138         // When the transaction was posted
139         nsecs_t postTime;
140         sp<ITransactionCompletedListener> releaseBufferListener;
141         // SurfaceFrame that tracks the timeline of Transactions that contain a Buffer. Only one
142         // such SurfaceFrame exists because only one buffer can be presented on the layer per vsync.
143         // If multiple buffers are queued, the prior ones will be dropped, along with the
144         // SurfaceFrame that's tracking them.
145         std::shared_ptr<frametimeline::SurfaceFrame> bufferSurfaceFrameTX;
146         // A map of token(frametimelineVsyncId) to the SurfaceFrame that's tracking a transaction
147         // that contains the token. Only one SurfaceFrame exisits for transactions that share the
148         // same token, unless they are presented in different vsyncs.
149         std::unordered_map<int64_t, std::shared_ptr<frametimeline::SurfaceFrame>>
150                 bufferlessSurfaceFramesTX;
151         // An arbitrary threshold for the number of BufferlessSurfaceFrames in the state. Used to
152         // trigger a warning if the number of SurfaceFrames crosses the threshold.
153         static constexpr uint32_t kStateSurfaceFramesThreshold = 25;
154         Rect bufferCrop;
155         Rect destinationFrame;
156         sp<IBinder> releaseBufferEndpoint;
157         bool autoRefresh = false;
158         float currentHdrSdrRatio = 1.f;
159         float desiredHdrSdrRatio = -1.f;
160         int64_t latchedVsyncId = 0;
161         bool useVsyncIdForRefreshRateSelection = false;
162     };
163 
164     explicit Layer(const surfaceflinger::LayerCreationArgs& args);
165     virtual ~Layer();
166 
167     static bool isLayerFocusedBasedOnPriority(int32_t priority);
168     static void miniDumpHeader(std::string& result);
169 
170     // This second set of geometry attributes are controlled by
171     // setGeometryAppliesWithResize, and their default mode is to be
172     // immediate. If setGeometryAppliesWithResize is specified
173     // while a resize is pending, then update of these attributes will
174     // be delayed until the resize completes.
175 
176     // Buffer space
177     bool setCrop(const FloatRect& crop);
178 
179     bool setTransform(uint32_t /*transform*/);
180     bool setTransformToDisplayInverse(bool /*transformToDisplayInverse*/);
181     bool setBuffer(std::shared_ptr<renderengine::ExternalTexture>& /* buffer */,
182                    const BufferData& /* bufferData */, nsecs_t /* postTime */,
183                    nsecs_t /*desiredPresentTime*/, bool /*isAutoTimestamp*/,
184                    const FrameTimelineInfo& /*info*/, gui::GameMode gameMode);
185     void setDesiredPresentTime(nsecs_t /*desiredPresentTime*/, bool /*isAutoTimestamp*/);
186     bool setDataspace(ui::Dataspace /*dataspace*/);
187     bool setExtendedRangeBrightness(float currentBufferRatio, float desiredRatio);
188     bool setDesiredHdrHeadroom(float desiredRatio);
189     bool setSidebandStream(const sp<NativeHandle>& /*sidebandStream*/,
190                            const FrameTimelineInfo& /* info*/, nsecs_t /* postTime */,
191                            gui::GameMode gameMode);
192     bool setTransactionCompletedListeners(const std::vector<sp<CallbackHandle>>& /*handles*/,
193                                           bool willPresent);
194 
195     sp<LayerFE> getCompositionEngineLayerFE(const frontend::LayerHierarchy::TraversalPath&);
196 
197     // If we have received a new buffer this frame, we will pass its surface
198     // damage down to hardware composer. Otherwise, we must send a region with
199     // one empty rect.
200     Region getVisibleRegion(const DisplayDevice*) const;
201     void updateLastLatchTime(nsecs_t latchtime);
202 
getCrop(const Layer::State & s)203     Rect getCrop(const Layer::State& s) const { return Rect(s.crop); }
204 
205     // from graphics API
206     static ui::Dataspace translateDataspace(ui::Dataspace dataspace);
207     uint64_t mPreviousFrameNumber = 0;
208 
209     void onCompositionPresented(const DisplayDevice*,
210                                 const std::shared_ptr<FenceTime>& /*glDoneFence*/,
211                                 const std::shared_ptr<FenceTime>& /*presentFence*/,
212                                 const CompositorTiming&, gui::GameMode gameMode);
213 
214     // If a buffer was replaced this frame, release the former buffer
215     void releasePendingBuffer(nsecs_t /*dequeueReadyTime*/);
216 
217     /*
218      * latchBuffer - called each time the screen is redrawn and returns whether
219      * the visible regions need to be recomputed (this is a fairly heavy
220      * operation, so this should be set only if needed). Typically this is used
221      * to figure out if the content or size of a surface has changed.
222      */
223     bool latchBufferImpl(bool& /*recomputeVisibleRegions*/, nsecs_t /*latchTime*/,
224                          bool bgColorOnly);
225 
226     sp<GraphicBuffer> getBuffer() const;
227     /**
228      * Returns active buffer size in the correct orientation. Buffer size is determined by undoing
229      * any buffer transformations. Returns Rect::INVALID_RECT if the layer has no buffer or the
230      * layer does not have a display frame and its parent is not bounded.
231      */
232     Rect getBufferSize(const Layer::State&) const;
233 
234     FrameRate getFrameRateForLayerTree() const;
235 
236     bool getTransformToDisplayInverse() const;
237 
238     // Implements RefBase.
239     void onFirstRef() override;
240 
241     struct BufferInfo {
242         nsecs_t mDesiredPresentTime;
243         std::shared_ptr<FenceTime> mFenceTime;
244         sp<Fence> mFence;
245         uint32_t mTransform{0};
246         ui::Dataspace mDataspace{ui::Dataspace::UNKNOWN};
247         std::chrono::steady_clock::time_point mTimeSinceDataspaceUpdate =
248                 std::chrono::steady_clock::time_point::min();
249         Rect mCrop;
250         PixelFormat mPixelFormat{PIXEL_FORMAT_NONE};
251         bool mTransformToDisplayInverse{false};
252         std::shared_ptr<renderengine::ExternalTexture> mBuffer;
253         uint64_t mFrameNumber;
254         sp<IBinder> mReleaseBufferEndpoint;
255         bool mFrameLatencyNeeded{false};
256         float mDesiredHdrSdrRatio = -1.f;
257     };
258 
259     BufferInfo mBufferInfo;
260     std::shared_ptr<gui::BufferReleaseChannel::ProducerEndpoint> mBufferReleaseChannel;
261 
262     bool fenceHasSignaled() const;
263     void onPreComposition(nsecs_t refreshStartTime);
264 
265     // Tracks mLastClientCompositionFence and gets the callback handle for this layer.
266     sp<CallbackHandle> findCallbackHandle();
267 
268     // Adds the future release fence to a list of fences that are used to release the
269     // last presented buffer. Also keeps track of the layerstack in a list of previous
270     // layerstacks that have been presented.
271     void prepareReleaseCallbacks(ftl::Future<FenceResult>, ui::LayerStack layerStack);
272 
setWasClientComposed(const sp<Fence> & fence)273     void setWasClientComposed(const sp<Fence>& fence) {
274         mLastClientCompositionFence = fence;
275         mClearClientCompositionFenceOnLayerDisplayed = false;
276     }
277 
278     const char* getDebugName() const;
279 
280     static bool computeTrustedPresentationState(const FloatRect& bounds,
281                                                 const FloatRect& sourceBounds,
282                                                 const Region& coveredRegion,
283                                                 const FloatRect& screenBounds, float,
284                                                 const ui::Transform&,
285                                                 const TrustedPresentationThresholds&);
286     void updateTrustedPresentationState(const DisplayDevice* display,
287                                         const frontend::LayerSnapshot* snapshot, int64_t time_in_ms,
288                                         bool leaveState);
289 
hasTrustedPresentationListener()290     inline bool hasTrustedPresentationListener() {
291         return mTrustedPresentationListener.callbackInterface != nullptr;
292     }
293 
294     // Sets the masked bits.
295     void setTransactionFlags(uint32_t mask);
296 
getSequence()297     int32_t getSequence() const { return sequence; }
298 
299     // For tracing.
300     // TODO: Replace with raw buffer id from buffer metadata when that becomes available.
301     // GraphicBuffer::getId() does not provide a reliable global identifier. Since the traces
302     // creates its tracks by buffer id and has no way of associating a buffer back to the process
303     // that created it, the current implementation is only sufficient for cases where a buffer is
304     // only used within a single layer.
getCurrentBufferId()305     uint64_t getCurrentBufferId() const { return getBuffer() ? getBuffer()->getId() : 0; }
306 
307     void writeCompositionStateToProto(perfetto::protos::LayerProto* layerProto,
308                                       ui::LayerStack layerStack);
309 
getDrawingState()310     inline const State& getDrawingState() const { return mDrawingState; }
getDrawingState()311     inline State& getDrawingState() { return mDrawingState; }
312 
313     void miniDump(std::string& result, const frontend::LayerSnapshot&, const DisplayDevice&) const;
314     void dumpFrameStats(std::string& result) const;
315     void clearFrameStats();
316     void logFrameStats();
317     void getFrameStats(FrameStats* outStats) const;
318     void onDisconnect();
319 
onHandleDestroyed()320     bool onHandleDestroyed() { return mHandleAlive = false; }
321 
322     /**
323      * Returns the cropped buffer size or the layer crop if the layer has no buffer. Return
324      * INVALID_RECT if the layer has no buffer and no crop.
325      * A layer with an invalid buffer size and no crop is considered to be boundless. The layer
326      * bounds are constrained by its parent bounds.
327      */
328     Rect getCroppedBufferSize(const Layer::State& s) const;
329 
330     void setFrameTimelineVsyncForBufferTransaction(const FrameTimelineInfo& info, nsecs_t postTime,
331                                                    gui::GameMode gameMode);
332     void setFrameTimelineVsyncForBufferlessTransaction(const FrameTimelineInfo& info,
333                                                        nsecs_t postTime, gui::GameMode gameMode);
334 
335     void addSurfaceFrameDroppedForBuffer(std::shared_ptr<frametimeline::SurfaceFrame>& surfaceFrame,
336                                          nsecs_t dropTime);
337     void addSurfaceFramePresentedForBuffer(
338             std::shared_ptr<frametimeline::SurfaceFrame>& surfaceFrame, nsecs_t acquireFenceTime,
339             nsecs_t currentLatchTime);
340 
341     std::shared_ptr<frametimeline::SurfaceFrame> createSurfaceFrameForTransaction(
342             const FrameTimelineInfo& info, nsecs_t postTime, gui::GameMode gameMode);
343     std::shared_ptr<frametimeline::SurfaceFrame> createSurfaceFrameForBuffer(
344             const FrameTimelineInfo& info, nsecs_t queueTime, std::string debugName,
345             gui::GameMode gameMode);
346     void setFrameTimelineVsyncForSkippedFrames(const FrameTimelineInfo& info, nsecs_t postTime,
347                                                std::string debugName, gui::GameMode gameMode);
348 
349     bool setTrustedPresentationInfo(TrustedPresentationThresholds const& thresholds,
350                                     TrustedPresentationListener const& listener);
351     void setBufferReleaseChannel(
352             const std::shared_ptr<gui::BufferReleaseChannel::ProducerEndpoint>& channel);
353 
354     // Creates a new handle each time, so we only expect
355     // this to be called once.
356     sp<IBinder> getHandle();
getName()357     const std::string& getName() const { return mName; }
358 
getOwnerUid()359     virtual uid_t getOwnerUid() const { return mOwnerUid; }
360 
361     // Used to check if mUsedVsyncIdForRefreshRateSelection should be expired when it stop updating.
362     nsecs_t mMaxTimeForUseVsyncId = 0;
363     // True when DrawState.useVsyncIdForRefreshRateSelection previously set to true during updating
364     // buffer.
365     bool mUsedVsyncIdForRefreshRateSelection{false};
366 
367     // Layer serial number.  This gives layers an explicit ordering, so we
368     // have a stable sort order when their layer stack and Z-order are
369     // the same.
370     const int32_t sequence;
371 
372     // See mPendingBufferTransactions
373     void decrementPendingBufferCount();
getPendingBufferCounter()374     std::atomic<int32_t>* getPendingBufferCounter() { return &mPendingBuffers; }
getPendingBufferCounterName()375     std::string getPendingBufferCounterName() { return mBlastTransactionName; }
376     void callReleaseBufferCallback(const sp<ITransactionCompletedListener>& listener,
377                                    const sp<GraphicBuffer>& buffer, uint64_t framenumber,
378                                    const sp<Fence>& releaseFence);
379     bool setFrameRateForLayerTree(FrameRate, const scheduler::LayerProps&, nsecs_t now);
380     void recordLayerHistoryBufferUpdate(const scheduler::LayerProps&, nsecs_t now);
381     void recordLayerHistoryAnimationTx(const scheduler::LayerProps&, nsecs_t now);
hasBuffer()382     bool hasBuffer() const { return mBufferInfo.mBuffer != nullptr; }
setTransformHint(std::optional<ui::Transform::RotationFlags> transformHint)383     void setTransformHint(std::optional<ui::Transform::RotationFlags> transformHint) {
384         mTransformHint = transformHint;
385     }
386     void commitTransaction();
387     // Keeps track of the previously presented layer stacks. This is used to get
388     // the release fences from the correct displays when we release the last buffer
389     // from the layer.
390     std::vector<ui::LayerStack> mPreviouslyPresentedLayerStacks;
391 
392     // Release fences for buffers that have not yet received a release
393     // callback. A release callback may not be given when capturing
394     // screenshots asynchronously. There may be no buffer update for the
395     // layer, but the layer will still be composited on the screen in every
396     // frame. Kepping track of these fences ensures that they are not dropped
397     // and can be dispatched to the client at a later time. Older fences are
398     // dropped when a layer stack receives a new fence.
399     // TODO(b/300533018): Track fence per multi-instance RenderEngine
400     ftl::SmallMap<ui::LayerStack, ftl::Future<FenceResult>, ui::kDisplayCapacity>
401             mAdditionalPreviousReleaseFences;
402 
403     // Exposed so SurfaceFlinger can assert that it's held
404     const sp<SurfaceFlinger> mFlinger;
405 
406     // Check if the damage region is a small dirty.
407     void setIsSmallDirty(frontend::LayerSnapshot* snapshot);
408 
409 protected:
410     // For unit tests
411     friend class TestableSurfaceFlinger;
412     friend class FpsReporterTest;
413     friend class RefreshRateSelectionTest;
414     friend class SetFrameRateTest;
415     friend class TransactionFrameTracerTest;
416     friend class TransactionSurfaceFrameTest;
417 
418     void gatherBufferInfo();
419 
420     compositionengine::OutputLayer* findOutputLayerForDisplay(const DisplayDevice*) const;
421     compositionengine::OutputLayer* findOutputLayerForDisplay(
422             const DisplayDevice*, const frontend::LayerHierarchy::TraversalPath& path) const;
423 
424     const std::string mName;
425     const std::string mTransactionName{"TX - " + mName};
426 
427     // These are only accessed by the main thread.
428     State mDrawingState;
429 
430     TrustedPresentationThresholds mTrustedPresentationThresholds;
431     TrustedPresentationListener mTrustedPresentationListener;
432     bool mLastComputedTrustedPresentationState = false;
433     bool mLastReportedTrustedPresentationState = false;
434     int64_t mEnteredTrustedPresentationStateTime = -1;
435 
436     uint32_t mTransactionFlags{0};
437 
438     // Leverages FrameTimeline to generate FrameStats. Since FrameTimeline already has the data,
439     // statistical history needs to only be tracked by count of frames.
440     // TODO: Deprecate the '--latency-clear' and get rid of this.
441     std::atomic<uint16_t> mFrameStatsHistorySize;
442     // Timestamp history for UIAutomation. Thread safe.
443     FrameTracker mDeprecatedFrameTracker;
444 
445     // main thread
446     sp<NativeHandle> mSidebandStream;
447 
448     // We encode unset as -1.
449     std::atomic<uint64_t> mCurrentFrameNumber{0};
450 
451     // protected by mLock
452     mutable Mutex mLock;
453 
454     // This layer can be a cursor on some displays.
455     bool mPotentialCursor{false};
456 
457     // Window types from WindowManager.LayoutParams
458     const gui::WindowInfo::Type mWindowType;
459 
460     // The owner of the layer. If created from a non system process, it will be the calling uid.
461     // If created from a system process, the value can be passed in.
462     uid_t mOwnerUid;
463 
464     // The owner pid of the layer. If created from a non system process, it will be the calling pid.
465     // If created from a system process, the value can be passed in.
466     pid_t mOwnerPid;
467 
468     int32_t mOwnerAppId;
469 
470     // Keeps track of the time SF latched the last buffer from this layer.
471     // Used in buffer stuffing analysis in FrameTimeline.
472     nsecs_t mLastLatchTime = 0;
473 
474     sp<Fence> mLastClientCompositionFence;
475     bool mClearClientCompositionFenceOnLayerDisplayed = false;
476 private:
477     // Range of uids allocated for a user.
478     // This value is taken from android.os.UserHandle#PER_USER_RANGE.
479     static constexpr int32_t PER_USER_RANGE = 100000;
480 
481     friend class SlotGenerationTest;
482     friend class TransactionFrameTracerTest;
483     friend class TransactionSurfaceFrameTest;
484 
getSidebandStreamChanged()485     bool getSidebandStreamChanged() const { return mSidebandStreamChanged; }
486 
487     std::atomic<bool> mSidebandStreamChanged{false};
488 
489     aidl::android::hardware::graphics::composer3::Composition getCompositionType(
490             const DisplayDevice&) const;
491     aidl::android::hardware::graphics::composer3::Composition getCompositionType(
492             const compositionengine::OutputLayer*) const;
493 
494     inline void tracePendingBufferCount(int32_t pendingBuffers);
495 
496     // Latch sideband stream and returns true if the dirty region should be updated.
497     bool latchSidebandStream(bool& recomputeVisibleRegions);
498 
499     void updateTexImage(nsecs_t latchTime, bool bgColorOnly = false);
500 
501     // Crop that applies to the buffer
502     Rect computeBufferCrop(const State& s);
503 
504     void callReleaseBufferCallback(const sp<ITransactionCompletedListener>& listener,
505                                    const sp<GraphicBuffer>& buffer, uint64_t framenumber,
506                                    const sp<Fence>& releaseFence,
507                                    uint32_t currentMaxAcquiredBufferCount);
508 
hasBufferOrSidebandStream()509     bool hasBufferOrSidebandStream() const {
510         return ((mSidebandStream != nullptr) || (mBufferInfo.mBuffer != nullptr));
511     }
512 
hasBufferOrSidebandStreamInDrawing()513     bool hasBufferOrSidebandStreamInDrawing() const {
514         return ((mDrawingState.sidebandStream != nullptr) || (mDrawingState.buffer != nullptr));
515     }
516 
517     bool mGetHandleCalled = false;
518 
519     // The inherited shadow radius after taking into account the layer hierarchy. This is the
520     // final shadow radius for this layer. If a shadow is specified for a layer, then effective
521     // shadow radius is the set shadow radius, otherwise its the parent's shadow radius.
522     float mEffectiveShadowRadius = 0.f;
523 
524     // Game mode for the layer. Set by WindowManagerShell and recorded by SurfaceFlingerStats.
525     gui::GameMode mGameMode = gui::GameMode::Unsupported;
526 
527     bool mIsAtRoot = false;
528 
529     uint32_t mLayerCreationFlags;
530 
531     void releasePreviousBuffer();
532     void resetDrawingStateBufferInfo();
533 
534     // Transform hint provided to the producer. This must be accessed holding
535     // the mStateLock.
536     std::optional<ui::Transform::RotationFlags> mTransformHint = std::nullopt;
537 
538     ReleaseCallbackId mPreviousReleaseCallbackId = ReleaseCallbackId::INVALID_ID;
539     sp<IBinder> mPreviousReleaseBufferEndpoint;
540 
541     bool mReleasePreviousBuffer = false;
542 
543     // Stores the last set acquire fence signal time used to populate the callback handle's acquire
544     // time.
545     std::variant<nsecs_t, sp<Fence>> mCallbackHandleAcquireTimeOrFence = -1;
546 
547     const std::string mBlastTransactionName{"BufferTX - " + mName};
548     // This integer is incremented everytime a buffer arrives at the server for this layer,
549     // and decremented when a buffer is dropped or latched. When changed the integer is exported
550     // to systrace with SFTRACE_INT and mBlastTransactionName. This way when debugging perf it is
551     // possible to see when a buffer arrived at the server, and in which frame it latched.
552     //
553     // You can understand the trace this way:
554     //     - If the integer increases, a buffer arrived at the server.
555     //     - If the integer decreases in latchBuffer, that buffer was latched
556     //     - If the integer decreases in setBuffer, a buffer was dropped
557     std::atomic<int32_t> mPendingBuffers{0};
558 
559     // Contains requested position and matrix updates. This will be applied if the client does
560     // not specify a destination frame.
561     ui::Transform mRequestedTransform;
562 
563     std::vector<std::pair<frontend::LayerHierarchy::TraversalPath, sp<LayerFE>>> mLayerFEs;
564     bool mHandleAlive = false;
getTimeline()565     std::optional<std::reference_wrapper<frametimeline::FrameTimeline>> getTimeline() const {
566         return *mFlinger->mFrameTimeline;
567     }
568 };
569 
570 std::ostream& operator<<(std::ostream& stream, const Layer::FrameRate& rate);
571 
572 } // namespace android
573