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