blob: 9caa20cfb8117e62f425f00702d9bbc0ad54945f [file] [log] [blame]
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001/*
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
Dominik Laskowskib7251f42020-04-20 17:42:59 -070017#pragma once
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080018
Vishnu Nair9cf4a4d2021-09-17 12:16:08 -070019#include <android/gui/DropInputMode.h>
Huihong Luod3d8f8e2022-03-08 14:48:46 -080020#include <android/gui/ISurfaceComposerClient.h>
Melody Hsue4ef87f2024-03-26 23:54:45 +000021#include <ftl/small_map.h>
Peiyong Lincbc184f2018-08-22 13:24:10 -070022#include <gui/BufferQueue.h>
Peiyong Lincbc184f2018-08-22 13:24:10 -070023#include <gui/LayerState.h>
chaviw98318de2021-05-19 16:45:23 -050024#include <gui/WindowInfo.h>
Peiyong Lincbc184f2018-08-22 13:24:10 -070025#include <layerproto/LayerProtoHeader.h>
26#include <math/vec4.h>
Alec Mouri1c8d7202019-06-01 18:51:35 -070027#include <sys/types.h>
Lucas Dupinc3800b82020-10-02 16:24:48 -070028#include <ui/BlurRegion.h>
Melody Hsue4ef87f2024-03-26 23:54:45 +000029#include <ui/DisplayMap.h>
Dan Stoza80d61162017-12-20 15:57:52 -080030#include <ui/FloatRect.h>
Svetoslavd85084b2014-03-20 10:28:31 -070031#include <ui/FrameStats.h>
Mathias Agopian13127d82013-03-05 17:47:11 -080032#include <ui/GraphicBuffer.h>
Melody Hsue4ef87f2024-03-26 23:54:45 +000033#include <ui/LayerStack.h>
Mathias Agopian13127d82013-03-05 17:47:11 -080034#include <ui/PixelFormat.h>
35#include <ui/Region.h>
John Reckcdb4ed72021-02-04 13:39:33 -050036#include <ui/StretchEffect.h>
Peiyong Linefefaac2018-08-17 12:27:51 -070037#include <ui/Transform.h>
Peiyong Lincbc184f2018-08-22 13:24:10 -070038#include <utils/RefBase.h>
Peiyong Lincbc184f2018-08-22 13:24:10 -070039#include <utils/Timers.h>
Mathias Agopian13127d82013-03-05 17:47:11 -080040
Dominik Laskowskif6b4ba62021-11-09 12:46:10 -080041#include <compositionengine/LayerFE.h>
Vishnu Nairbedb44b2022-08-02 21:47:40 +000042#include <compositionengine/LayerFECompositionState.h>
Dominik Laskowskif6b4ba62021-11-09 12:46:10 -080043#include <scheduler/Fps.h>
44#include <scheduler/Seamlessness.h>
45
Robert Carrcdf83202018-03-07 12:48:34 -080046#include <cstdint>
Dominik Laskowski075d3172018-05-24 15:50:06 -070047#include <optional>
Peiyong Lincbc184f2018-08-22 13:24:10 -070048#include <vector>
Dan Stoza7dde5992015-05-22 09:51:44 -070049
Mathias Agopian13127d82013-03-05 17:47:11 -080050#include "Client.h"
Alec Mouri1c8d7202019-06-01 18:51:35 -070051#include "DisplayHardware/HWComposer.h"
David Sodman41fdfc92017-11-06 16:09:56 -080052#include "FrameTracker.h"
Vishnu Naire14c6b32022-08-06 04:20:15 +000053#include "LayerFE.h"
Robert Carr1f0a16a2016-10-24 16:27:39 -070054#include "LayerVector.h"
Ady Abrahambdda8f02021-04-01 16:06:11 -070055#include "Scheduler/LayerInfo.h"
Mathias Agopian13127d82013-03-05 17:47:11 -080056#include "SurfaceFlinger.h"
Robert Carr9a803c32021-01-14 16:57:58 -080057#include "TransactionCallbackInvoker.h"
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080058
chaviw1d044282017-09-27 12:19:28 -070059using namespace android::surfaceflinger;
60
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080061namespace android {
62
Mathias Agopian1f7bec62010-06-25 18:02:21 -070063class Client;
Mathias Agopian3e25fd82013-04-22 17:52:16 +020064class Colorizer;
Mathias Agopian13127d82013-03-05 17:47:11 -080065class DisplayDevice;
66class GraphicBuffer;
67class SurfaceFlinger;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080068
Lloyd Piquefeb73d72018-12-04 17:23:44 -080069namespace compositionengine {
Lloyd Pique37c2c9b2018-12-04 17:25:10 -080070class OutputLayer;
Lloyd Piquea83776c2019-01-29 18:42:32 -080071struct LayerFECompositionState;
Lloyd Piquefeb73d72018-12-04 17:23:44 -080072}
73
Ady Abraham22c7b5c2020-09-22 19:33:40 -070074namespace frametimeline {
75class SurfaceFrame;
76} // namespace frametimeline
77
Vishnu Naire14c6b32022-08-06 04:20:15 +000078class Layer : public virtual RefBase {
Vishnu Nairdc4d31b2022-11-17 03:20:58 +000079public:
Ady Abrahamaae5ed52020-06-26 09:32:43 -070080 // The following constants represent priority of the window. SF uses this information when
81 // deciding which window has a priority when deciding about the refresh rate of the screen.
82 // Priority 0 is considered the highest priority. -1 means that the priority is unset.
Ana Krulecc84d09b2019-11-02 23:10:29 +010083 static constexpr int32_t PRIORITY_UNSET = -1;
Ady Abrahamaae5ed52020-06-26 09:32:43 -070084 // Windows that are in focus and voted for the preferred mode ID
85 static constexpr int32_t PRIORITY_FOCUSED_WITH_MODE = 0;
86 // // Windows that are in focus, but have not requested a specific mode ID.
87 static constexpr int32_t PRIORITY_FOCUSED_WITHOUT_MODE = 1;
88 // Windows that are not in focus, but voted for a specific mode ID.
89 static constexpr int32_t PRIORITY_NOT_FOCUSED_WITH_MODE = 2;
Mathias Agopian13127d82013-03-05 17:47:11 -080090
Mathias Agopian13127d82013-03-05 17:47:11 -080091 enum { // flags for doTransaction()
92 eDontUpdateGeometryState = 0x00000001,
93 eVisibleRegion = 0x00000002,
Robert Carr720e5062018-07-30 17:45:14 -070094 eInputInfoChanged = 0x00000004
Mathias Agopian13127d82013-03-05 17:47:11 -080095 };
96
Ady Abrahambdda8f02021-04-01 16:06:11 -070097 using FrameRate = scheduler::LayerInfo::FrameRate;
Vishnu Nair3fbe3262023-09-29 17:07:00 -070098 using FrameRateCompatibility = scheduler::FrameRateCompatibility;
Rachel Lee58cc90d2023-09-05 18:50:20 -070099 using FrameRateSelectionStrategy = scheduler::LayerInfo::FrameRateSelectionStrategy;
Ady Abraham71c437d2020-01-31 15:56:57 -0800100
Mathias Agopian13127d82013-03-05 17:47:11 -0800101 struct State {
Mathias Agopian13127d82013-03-05 17:47:11 -0800102 int32_t sequence; // changes when visible regions can change
Fabien Sanglard4ed383c2016-12-13 14:02:41 -0800103 // Crop is expressed in layer space coordinate.
chaviw25714502021-02-11 10:01:08 -0800104 Rect crop;
Evan Rosky1f6d6d52018-12-06 10:47:26 -0800105 LayerMetadata metadata;
Robert Carr720e5062018-07-30 17:45:14 -0700106
Valerie Haub153bab2019-03-05 10:47:28 -0800107 ui::Dataspace dataspace;
108
Valerie Hau134651a2020-01-28 16:21:22 -0800109 uint64_t frameNumber;
Alec Mouri21d94322023-10-17 19:51:39 +0000110 uint64_t previousFrameNumber;
Vishnu Nair63221212023-04-06 15:17:37 -0700111 // high watermark framenumber to use to check for barriers to protect ourselves
112 // from out of order transactions
113 uint64_t barrierFrameNumber;
chaviw766c9c52021-02-10 17:36:47 -0800114 ui::Transform transform;
liulijuneb489f62022-10-17 22:02:14 +0800115
116 uint32_t producerId = 0;
Vishnu Nair63221212023-04-06 15:17:37 -0700117 // high watermark producerId to use to check for barriers to protect ourselves
118 // from out of order transactions
119 uint32_t barrierProducerId = 0;
120
chaviw766c9c52021-02-10 17:36:47 -0800121 uint32_t bufferTransform;
Marissa Wall61c58622018-07-18 10:12:20 -0700122 bool transformToDisplayInverse;
Marissa Wall61c58622018-07-18 10:12:20 -0700123 Region transparentRegionHint;
Alec Mouria90a5702021-04-16 16:36:21 +0000124 std::shared_ptr<renderengine::ExternalTexture> buffer;
Marissa Wall61c58622018-07-18 10:12:20 -0700125 sp<Fence> acquireFence;
Ady Abraham6c1b7ac2021-03-31 16:56:03 -0700126 std::shared_ptr<FenceTime> acquireFenceTime;
Marissa Wall61c58622018-07-18 10:12:20 -0700127 sp<NativeHandle> sidebandStream;
Peiyong Lind3788632018-09-18 16:01:31 -0700128 mat4 colorTransform;
Valerie Haued54efa2019-01-11 20:03:14 -0800129
Marissa Walle2ffb422018-10-12 11:33:52 -0700130 // The deque of callback handles for this frame. The back of the deque contains the most
131 // recent callback handle.
132 std::deque<sp<CallbackHandle>> callbackHandles;
Ady Abrahamf0c56492020-12-17 18:04:15 -0800133 nsecs_t desiredPresentTime = 0;
134 bool isAutoTimestamp = true;
Vishnu Nair08f6eae2019-11-26 14:01:39 -0800135
Ady Abraham59fd8ff2021-04-15 20:13:30 -0700136 // The combined frame rate of parents / children of this layer
137 FrameRate frameRateForLayerTree;
Vishnu Nair6213bd92020-05-08 17:42:25 -0700138
Siarhei Vishniakoufc434ac2021-01-13 10:28:00 -1000139 // The vsync info that was used to start the transaction
140 FrameTimelineInfo frameTimelineInfo;
Ady Abraham22c7b5c2020-09-22 19:33:40 -0700141
142 // When the transaction was posted
143 nsecs_t postTime;
Vishnu Nair1506b182021-02-22 14:35:15 -0800144 sp<ITransactionCompletedListener> releaseBufferListener;
Adithya Srinivasanb9a7dab2021-01-14 23:49:46 +0000145 // SurfaceFrame that tracks the timeline of Transactions that contain a Buffer. Only one
146 // such SurfaceFrame exists because only one buffer can be presented on the layer per vsync.
147 // If multiple buffers are queued, the prior ones will be dropped, along with the
148 // SurfaceFrame that's tracking them.
149 std::shared_ptr<frametimeline::SurfaceFrame> bufferSurfaceFrameTX;
150 // A map of token(frametimelineVsyncId) to the SurfaceFrame that's tracking a transaction
151 // that contains the token. Only one SurfaceFrame exisits for transactions that share the
152 // same token, unless they are presented in different vsyncs.
153 std::unordered_map<int64_t, std::shared_ptr<frametimeline::SurfaceFrame>>
154 bufferlessSurfaceFramesTX;
155 // An arbitrary threshold for the number of BufferlessSurfaceFrames in the state. Used to
156 // trigger a warning if the number of SurfaceFrames crosses the threshold.
157 static constexpr uint32_t kStateSurfaceFramesThreshold = 25;
chaviwf3f40fe2021-04-27 15:54:02 -0500158 Rect bufferCrop;
Vishnu Nair6bdec7d2021-05-10 15:01:13 -0700159 Rect destinationFrame;
chaviw0b06a8d2021-08-06 11:49:08 -0500160 sp<IBinder> releaseBufferEndpoint;
Vishnu Nair86653e92021-11-03 17:19:36 -0700161 bool autoRefresh = false;
Sally Qi963049b2023-03-23 14:06:21 -0700162 float currentHdrSdrRatio = 1.f;
Alec Mouri1b0d4e12024-02-12 22:27:19 +0000163 float desiredHdrSdrRatio = -1.f;
Vishnu Nairef68d6d2023-02-28 06:18:27 +0000164 int64_t latchedVsyncId = 0;
Ady Abraham55269162023-05-09 11:26:06 -0700165 bool useVsyncIdForRefreshRateSelection = false;
Mathias Agopian13127d82013-03-05 17:47:11 -0800166 };
167
Kean Mariotti4ba343c2023-04-19 13:31:02 +0000168 explicit Layer(const surfaceflinger::LayerCreationArgs& args);
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700169 virtual ~Layer();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800170
Peiyong Linf243e5e2020-08-22 17:40:59 -0700171 static bool isLayerFocusedBasedOnPriority(int32_t priority);
172 static void miniDumpHeader(std::string& result);
Dominik Laskowski75848362019-11-11 17:57:20 -0800173
Peiyong Linf243e5e2020-08-22 17:40:59 -0700174 // Provide unique string for each class type in the Layer hierarchy
Vishnu Nairdc83d4b2024-08-15 16:29:20 +0000175 const char* getType() const { return "Layer"; }
Robert Carr7bf247e2017-05-18 14:02:49 -0700176
177 // This second set of geometry attributes are controlled by
178 // setGeometryAppliesWithResize, and their default mode is to be
179 // immediate. If setGeometryAppliesWithResize is specified
180 // while a resize is pending, then update of these attributes will
181 // be delayed until the resize completes.
182
Robert Carr7bf247e2017-05-18 14:02:49 -0700183 // Buffer space
Vishnu Nairbc4ee5c2022-08-16 03:19:37 +0000184 bool setCrop(const Rect& crop);
Robert Carr8d5227b2017-03-16 15:41:03 -0700185
Patrick Williamsbb25f802022-08-30 23:02:34 +0000186 bool setTransform(uint32_t /*transform*/);
187 bool setTransformToDisplayInverse(bool /*transformToDisplayInverse*/);
188 bool setBuffer(std::shared_ptr<renderengine::ExternalTexture>& /* buffer */,
189 const BufferData& /* bufferData */, nsecs_t /* postTime */,
190 nsecs_t /*desiredPresentTime*/, bool /*isAutoTimestamp*/,
Vishnu Nair39a74a92024-07-29 19:01:50 +0000191 const FrameTimelineInfo& /*info*/, gui::GameMode gameMode);
Vishnu Nairef68d6d2023-02-28 06:18:27 +0000192 void setDesiredPresentTime(nsecs_t /*desiredPresentTime*/, bool /*isAutoTimestamp*/);
Patrick Williamsbb25f802022-08-30 23:02:34 +0000193 bool setDataspace(ui::Dataspace /*dataspace*/);
John Reck68796592023-01-25 13:47:12 -0500194 bool setExtendedRangeBrightness(float currentBufferRatio, float desiredRatio);
Alec Mouri1b0d4e12024-02-12 22:27:19 +0000195 bool setDesiredHdrHeadroom(float desiredRatio);
Dorin Drimuse5374e52023-08-02 17:52:43 +0000196 bool setSidebandStream(const sp<NativeHandle>& /*sidebandStream*/,
Vishnu Nair39a74a92024-07-29 19:01:50 +0000197 const FrameTimelineInfo& /* info*/, nsecs_t /* postTime */,
198 gui::GameMode gameMode);
Vishnu Nair3af0ec02023-02-10 04:13:48 +0000199 bool setTransactionCompletedListeners(const std::vector<sp<CallbackHandle>>& /*handles*/,
200 bool willPresent);
Vishnu Nair9cf4a4d2021-09-17 12:16:08 -0700201
Vishnu Nair3af0ec02023-02-10 04:13:48 +0000202 sp<LayerFE> getCompositionEngineLayerFE(const frontend::LayerHierarchy::TraversalPath&);
Vishnu Nair3cc15a42023-06-30 06:20:22 +0000203 sp<LayerFE> getOrCreateCompositionEngineLayerFE(const frontend::LayerHierarchy::TraversalPath&);
Vishnu Naire14c6b32022-08-06 04:20:15 +0000204
Dan Stozaee44edd2015-03-23 15:50:23 -0700205 // If we have received a new buffer this frame, we will pass its surface
206 // damage down to hardware composer. Otherwise, we must send a region with
207 // one empty rect.
Alec Mouriadebf5c2021-01-05 12:57:36 -0800208 Region getVisibleRegion(const DisplayDevice*) const;
Vishnu Naira156f482023-02-22 00:23:38 +0000209 void updateLastLatchTime(nsecs_t latchtime);
Dan Stozaee44edd2015-03-23 15:50:23 -0700210
Peiyong Linf243e5e2020-08-22 17:40:59 -0700211 /*
Peiyong Lin05cc0112020-10-14 16:16:37 -0700212 * isProtected - true if the layer may contain protected contents in the
Peiyong Linf243e5e2020-08-22 17:40:59 -0700213 * GRALLOC_USAGE_PROTECTED sense.
214 */
Patrick Williamsbb25f802022-08-30 23:02:34 +0000215 bool isProtected() const;
Peiyong Linf243e5e2020-08-22 17:40:59 -0700216 /*
217 * usesSourceCrop - true if content should use a source crop
218 */
Patrick Williamsbb25f802022-08-30 23:02:34 +0000219 bool usesSourceCrop() const { return hasBufferOrSidebandStream(); }
Peiyong Linf243e5e2020-08-22 17:40:59 -0700220
Vishnu Nairbc4ee5c2022-08-16 03:19:37 +0000221 Rect getCrop(const Layer::State& s) const { return s.crop; }
Patrick Williamsbb25f802022-08-30 23:02:34 +0000222 bool needsFiltering(const DisplayDevice*) const;
Peiyong Linf243e5e2020-08-22 17:40:59 -0700223
Patrick Williamsbb25f802022-08-30 23:02:34 +0000224 // from graphics API
Vishnu Nair3996ee32023-08-14 04:32:31 +0000225 static ui::Dataspace translateDataspace(ui::Dataspace dataspace);
Patrick Williamsbb25f802022-08-30 23:02:34 +0000226 uint64_t mPreviousFrameNumber = 0;
Peiyong Linf243e5e2020-08-22 17:40:59 -0700227
Leon Scroggins III5b581492023-10-31 14:29:41 -0400228 void onCompositionPresented(const DisplayDevice*,
229 const std::shared_ptr<FenceTime>& /*glDoneFence*/,
230 const std::shared_ptr<FenceTime>& /*presentFence*/,
Vishnu Nair39a74a92024-07-29 19:01:50 +0000231 const CompositorTiming&, gui::GameMode gameMode);
Peiyong Linf243e5e2020-08-22 17:40:59 -0700232
233 // If a buffer was replaced this frame, release the former buffer
Patrick Williamsbb25f802022-08-30 23:02:34 +0000234 void releasePendingBuffer(nsecs_t /*dequeueReadyTime*/);
Peiyong Linf243e5e2020-08-22 17:40:59 -0700235
Peiyong Linf243e5e2020-08-22 17:40:59 -0700236 /*
237 * latchBuffer - called each time the screen is redrawn and returns whether
238 * the visible regions need to be recomputed (this is a fairly heavy
239 * operation, so this should be set only if needed). Typically this is used
240 * to figure out if the content or size of a surface has changed.
241 */
Vishnu Naird47bcee2023-02-24 18:08:51 +0000242 bool latchBufferImpl(bool& /*recomputeVisibleRegions*/, nsecs_t /*latchTime*/,
243 bool bgColorOnly);
244
Patrick Williamsbb25f802022-08-30 23:02:34 +0000245 /*
Vishnu Nair7ee4f462023-04-19 09:54:09 -0700246 * Returns true if the currently presented buffer will be released when this layer state
247 * is latched. This will return false if there is no buffer currently presented.
248 */
249 bool willReleaseBufferOnLatch() const;
250
251 /*
Peiyong Linf243e5e2020-08-22 17:40:59 -0700252 * returns the rectangle that crops the content of the layer and scales it
253 * to the layer's size.
254 */
Patrick Williamsbb25f802022-08-30 23:02:34 +0000255 Rect getBufferCrop() const;
Peiyong Linf243e5e2020-08-22 17:40:59 -0700256
257 /*
258 * Returns the transform applied to the buffer.
259 */
Patrick Williamsbb25f802022-08-30 23:02:34 +0000260 uint32_t getBufferTransform() const;
Peiyong Linf243e5e2020-08-22 17:40:59 -0700261
Patrick Williamsbb25f802022-08-30 23:02:34 +0000262 sp<GraphicBuffer> getBuffer() const;
Peiyong Linf243e5e2020-08-22 17:40:59 -0700263 /**
264 * Returns active buffer size in the correct orientation. Buffer size is determined by undoing
Patrick Williamsbb25f802022-08-30 23:02:34 +0000265 * any buffer transformations. Returns Rect::INVALID_RECT if the layer has no buffer or the
266 * layer does not have a display frame and its parent is not bounded.
Peiyong Linf243e5e2020-08-22 17:40:59 -0700267 */
Patrick Williamsbb25f802022-08-30 23:02:34 +0000268 Rect getBufferSize(const Layer::State&) const;
Peiyong Linf243e5e2020-08-22 17:40:59 -0700269
Vishnu Nairdc83d4b2024-08-15 16:29:20 +0000270 FrameRate getFrameRateForLayerTree() const;
Peiyong Linf243e5e2020-08-22 17:40:59 -0700271
Patrick Williamsbb25f802022-08-30 23:02:34 +0000272 bool getTransformToDisplayInverse() const;
Peiyong Linf243e5e2020-08-22 17:40:59 -0700273
Peiyong Linf243e5e2020-08-22 17:40:59 -0700274 // Implements RefBase.
275 void onFirstRef() override;
276
Patrick Williamsbb25f802022-08-30 23:02:34 +0000277 struct BufferInfo {
278 nsecs_t mDesiredPresentTime;
279 std::shared_ptr<FenceTime> mFenceTime;
280 sp<Fence> mFence;
281 uint32_t mTransform{0};
282 ui::Dataspace mDataspace{ui::Dataspace::UNKNOWN};
283 Rect mCrop;
Patrick Williamsbb25f802022-08-30 23:02:34 +0000284 PixelFormat mPixelFormat{PIXEL_FORMAT_NONE};
285 bool mTransformToDisplayInverse{false};
Patrick Williamsbb25f802022-08-30 23:02:34 +0000286 std::shared_ptr<renderengine::ExternalTexture> mBuffer;
287 uint64_t mFrameNumber;
Vishnu Nair7ee4f462023-04-19 09:54:09 -0700288 sp<IBinder> mReleaseBufferEndpoint;
Patrick Williamsbb25f802022-08-30 23:02:34 +0000289 bool mFrameLatencyNeeded{false};
Alec Mouri1b0d4e12024-02-12 22:27:19 +0000290 float mDesiredHdrSdrRatio = -1.f;
Patrick Williamsbb25f802022-08-30 23:02:34 +0000291 };
292
293 BufferInfo mBufferInfo;
Patrick Williams7c9fa272024-08-30 12:38:43 +0000294 std::shared_ptr<gui::BufferReleaseChannel::ProducerEndpoint> mBufferReleaseChannel;
Patrick Williamsbb25f802022-08-30 23:02:34 +0000295
Patrick Williamsbb25f802022-08-30 23:02:34 +0000296 bool fenceHasSignaled() const;
Vishnu Nair3af0ec02023-02-10 04:13:48 +0000297 void onPreComposition(nsecs_t refreshStartTime);
Alec Mouri9892aac2023-12-11 21:16:59 +0000298 void onLayerDisplayed(ftl::SharedFuture<FenceResult>, ui::LayerStack layerStack,
299 std::function<FenceResult(FenceResult)>&& continuation = nullptr);
Robert Carrccab4242021-09-28 16:53:03 -0700300
Melody Hsu793f8362024-01-08 20:00:35 +0000301 // Tracks mLastClientCompositionFence and gets the callback handle for this layer.
302 sp<CallbackHandle> findCallbackHandle();
303
304 // Adds the future release fence to a list of fences that are used to release the
305 // last presented buffer. Also keeps track of the layerstack in a list of previous
306 // layerstacks that have been presented.
307 void prepareReleaseCallbacks(ftl::Future<FenceResult>, ui::LayerStack layerStack);
308
Vishnu Naire14c6b32022-08-06 04:20:15 +0000309 void setWasClientComposed(const sp<Fence>& fence) {
Robert Carrccab4242021-09-28 16:53:03 -0700310 mLastClientCompositionFence = fence;
Robert Carr05da0082022-05-25 23:29:34 -0700311 mClearClientCompositionFenceOnLayerDisplayed = false;
Robert Carrccab4242021-09-28 16:53:03 -0700312 }
313
Vishnu Naire14c6b32022-08-06 04:20:15 +0000314 const char* getDebugName() const;
Peiyong Linf243e5e2020-08-22 17:40:59 -0700315
Lloyd Pique0449b0f2018-12-20 16:23:45 -0800316 uint32_t getTransactionFlags() const { return mTransactionFlags; }
Dominik Laskowski9e168db2021-05-27 16:05:12 -0700317
Chavi Weingarten076acac2023-01-19 17:20:43 +0000318 static bool computeTrustedPresentationState(const FloatRect& bounds,
319 const FloatRect& sourceBounds,
320 const Region& coveredRegion,
321 const FloatRect& screenBounds, float,
322 const ui::Transform&,
323 const TrustedPresentationThresholds&);
Vishnu Nair781d7252023-01-30 18:16:01 +0000324 void updateTrustedPresentationState(const DisplayDevice* display,
325 const frontend::LayerSnapshot* snapshot, int64_t time_in_ms,
Chavi Weingarten076acac2023-01-19 17:20:43 +0000326 bool leaveState);
327
328 inline bool hasTrustedPresentationListener() {
329 return mTrustedPresentationListener.callbackInterface != nullptr;
330 }
331
Dominik Laskowski9e168db2021-05-27 16:05:12 -0700332 // Sets the masked bits.
333 void setTransactionFlags(uint32_t mask);
334
335 // Clears and returns the masked bits.
336 uint32_t clearTransactionFlags(uint32_t mask);
Mathias Agopian13127d82013-03-05 17:47:11 -0800337
Vishnu Naire14c6b32022-08-06 04:20:15 +0000338 int32_t getSequence() const { return sequence; }
Pablo Ceballos40845df2016-01-25 17:41:15 -0800339
Mikael Pessa2e1608f2019-07-19 11:25:35 -0700340 // For tracing.
341 // TODO: Replace with raw buffer id from buffer metadata when that becomes available.
342 // GraphicBuffer::getId() does not provide a reliable global identifier. Since the traces
343 // creates its tracks by buffer id and has no way of associating a buffer back to the process
344 // that created it, the current implementation is only sufficient for cases where a buffer is
345 // only used within a single layer.
chaviwd62d3062019-09-04 14:48:02 -0700346 uint64_t getCurrentBufferId() const { return getBuffer() ? getBuffer()->getId() : 0; }
Mikael Pessa2e1608f2019-07-19 11:25:35 -0700347
Kean Mariotti4ba343c2023-04-19 13:31:02 +0000348 void writeCompositionStateToProto(perfetto::protos::LayerProto* layerProto,
349 ui::LayerStack layerStack);
chaviw08f3cb22020-01-13 13:17:21 -0800350
chaviw98318de2021-05-19 16:45:23 -0500351 gui::WindowInfo::Type getWindowType() const { return mWindowType; }
Peiyong Lin97067b02019-03-29 17:34:45 +0000352
Mathias Agopian1eae0ee2013-06-05 16:59:15 -0700353 /*
Mathias Agopian1eae0ee2013-06-05 16:59:15 -0700354 * doTransaction - process the transaction. This is a good place to figure
355 * out which attributes of the surface have changed.
356 */
Vishnu Nairdc83d4b2024-08-15 16:29:20 +0000357 uint32_t doTransaction(uint32_t transactionFlags);
Vishnu Nairda9c85a2019-06-03 17:26:48 -0700358
Lloyd Pique0449b0f2018-12-20 16:23:45 -0800359 inline const State& getDrawingState() const { return mDrawingState; }
Robert Carr6a160312021-05-17 12:08:20 -0700360 inline State& getDrawingState() { return mDrawingState; }
Mathias Agopian13127d82013-03-05 17:47:11 -0800361
Vishnu Nair3cc15a42023-06-30 06:20:22 +0000362 void miniDump(std::string& result, const frontend::LayerSnapshot&, const DisplayDevice&) const;
Yiwei Zhang5434a782018-12-05 18:06:32 -0800363 void dumpFrameStats(std::string& result) const;
Svetoslavd85084b2014-03-20 10:28:31 -0700364 void clearFrameStats();
Jamie Gennis6547ff42013-07-16 20:12:42 -0700365 void logFrameStats();
Svetoslavd85084b2014-03-20 10:28:31 -0700366 void getFrameStats(FrameStats* outStats) const;
Brian Anderson5ea5e592016-12-01 16:54:33 -0800367 void onDisconnect();
Pablo Ceballosce796e72016-02-04 19:10:51 -0800368
Lloyd Pique0449b0f2018-12-20 16:23:45 -0800369 ui::Transform getTransform() const;
Robert Carr1f0a16a2016-10-24 16:27:39 -0700370
Lloyd Pique0449b0f2018-12-20 16:23:45 -0800371 half4 getColor() const;
Lucas Dupin19c8f0e2019-11-25 17:55:44 -0800372 int32_t getBackgroundBlurRadius() const;
Vishnu Nairb87d94f2020-02-13 09:17:36 -0800373 bool drawShadows() const { return mEffectiveShadowRadius > 0.f; };
Robert Carr6452f122017-03-21 10:41:29 -0700374
Vishnu Nair787aa782023-03-17 13:46:46 -0700375 bool isHandleAlive() const { return mHandleAlive; }
376 bool onHandleDestroyed() { return mHandleAlive = false; }
Vishnu Nair4351ad52019-02-11 14:13:02 -0800377
Vishnu Nairefc42e22019-12-03 17:36:12 -0800378 /**
379 * Returns the cropped buffer size or the layer crop if the layer has no buffer. Return
380 * INVALID_RECT if the layer has no buffer and no crop.
381 * A layer with an invalid buffer size and no crop is considered to be boundless. The layer
382 * bounds are constrained by its parent bounds.
383 */
384 Rect getCroppedBufferSize(const Layer::State& s) const;
385
Vishnu Nairdc83d4b2024-08-15 16:29:20 +0000386 void setFrameTimelineInfoForBuffer(const FrameTimelineInfo& /*info*/) {}
Vishnu Nair39a74a92024-07-29 19:01:50 +0000387 void setFrameTimelineVsyncForBufferTransaction(const FrameTimelineInfo& info, nsecs_t postTime,
388 gui::GameMode gameMode);
Adithya Srinivasanb9a7dab2021-01-14 23:49:46 +0000389 void setFrameTimelineVsyncForBufferlessTransaction(const FrameTimelineInfo& info,
Vishnu Nair39a74a92024-07-29 19:01:50 +0000390 nsecs_t postTime, gui::GameMode gameMode);
Adithya Srinivasanb9a7dab2021-01-14 23:49:46 +0000391
Ady Abraham88930f92023-06-07 10:32:08 -0700392 void addSurfaceFrameDroppedForBuffer(std::shared_ptr<frametimeline::SurfaceFrame>& surfaceFrame,
393 nsecs_t dropTime);
Adithya Srinivasanb9a7dab2021-01-14 23:49:46 +0000394 void addSurfaceFramePresentedForBuffer(
395 std::shared_ptr<frametimeline::SurfaceFrame>& surfaceFrame, nsecs_t acquireFenceTime,
396 nsecs_t currentLatchTime);
397
398 std::shared_ptr<frametimeline::SurfaceFrame> createSurfaceFrameForTransaction(
Vishnu Nair39a74a92024-07-29 19:01:50 +0000399 const FrameTimelineInfo& info, nsecs_t postTime, gui::GameMode gameMode);
Adithya Srinivasanb9a7dab2021-01-14 23:49:46 +0000400 std::shared_ptr<frametimeline::SurfaceFrame> createSurfaceFrameForBuffer(
Vishnu Nair39a74a92024-07-29 19:01:50 +0000401 const FrameTimelineInfo& info, nsecs_t queueTime, std::string debugName,
402 gui::GameMode gameMode);
Ady Abraham88930f92023-06-07 10:32:08 -0700403 void setFrameTimelineVsyncForSkippedFrames(const FrameTimelineInfo& info, nsecs_t postTime,
Vishnu Nair39a74a92024-07-29 19:01:50 +0000404 std::string debugName, gui::GameMode gameMode);
Ady Abraham74e17562020-08-24 18:18:19 -0700405
Chavi Weingarten328a8312023-01-26 21:17:52 +0000406 bool setTrustedPresentationInfo(TrustedPresentationThresholds const& thresholds,
Chavi Weingarten076acac2023-01-19 17:20:43 +0000407 TrustedPresentationListener const& listener);
Patrick Williams7c9fa272024-08-30 12:38:43 +0000408 void setBufferReleaseChannel(
409 const std::shared_ptr<gui::BufferReleaseChannel::ProducerEndpoint>& channel);
Chavi Weingarten076acac2023-01-19 17:20:43 +0000410
Peiyong Linf243e5e2020-08-22 17:40:59 -0700411 // Creates a new handle each time, so we only expect
412 // this to be called once.
413 sp<IBinder> getHandle();
414 const std::string& getName() const { return mName; }
chaviw98318de2021-05-19 16:45:23 -0500415 void setInputInfo(const gui::WindowInfo& info);
Peiyong Linf243e5e2020-08-22 17:40:59 -0700416
Ady Abraham62a0be22020-12-08 16:54:10 -0800417 virtual uid_t getOwnerUid() const { return mOwnerUid; }
Peiyong Linf243e5e2020-08-22 17:40:59 -0700418
Adithya Srinivasan9febda82020-10-19 10:49:41 -0700419 pid_t getOwnerPid() { return mOwnerPid; }
420
Tony Huangf3621102023-09-04 17:14:22 +0800421 int32_t getOwnerAppId() { return mOwnerAppId; }
422
Arthur Hungc70bee22023-06-02 01:35:52 +0000423 // Used to check if mUsedVsyncIdForRefreshRateSelection should be expired when it stop updating.
424 nsecs_t mMaxTimeForUseVsyncId = 0;
425 // True when DrawState.useVsyncIdForRefreshRateSelection previously set to true during updating
426 // buffer.
427 bool mUsedVsyncIdForRefreshRateSelection{false};
428
Peiyong Linf243e5e2020-08-22 17:40:59 -0700429 // Layer serial number. This gives layers an explicit ordering, so we
430 // have a stable sort order when their layer stack and Z-order are
431 // the same.
Vishnu Nair7fb9e5a2021-11-08 12:44:05 -0800432 const int32_t sequence;
Peiyong Linf243e5e2020-08-22 17:40:59 -0700433
434 bool mPendingHWCDestroy{false};
Steven Thomas3172e202020-01-06 19:25:30 -0800435
Patrick Williamsbb25f802022-08-30 23:02:34 +0000436 bool setBufferCrop(const Rect& /* bufferCrop */);
Patrick Williamsbb25f802022-08-30 23:02:34 +0000437 // See mPendingBufferTransactions
438 void decrementPendingBufferCount();
439 std::atomic<int32_t>* getPendingBufferCounter() { return &mPendingBufferTransactions; }
440 std::string getPendingBufferCounterName() { return mBlastTransactionName; }
liulijuneb489f62022-10-17 22:02:14 +0800441 void callReleaseBufferCallback(const sp<ITransactionCompletedListener>& listener,
442 const sp<GraphicBuffer>& buffer, uint64_t framenumber,
443 const sp<Fence>& releaseFence);
Vishnu Nair47b7bb42023-09-29 16:27:33 -0700444 bool setFrameRateForLayerTree(FrameRate, const scheduler::LayerProps&, nsecs_t now);
445 void recordLayerHistoryBufferUpdate(const scheduler::LayerProps&, nsecs_t now);
446 void recordLayerHistoryAnimationTx(const scheduler::LayerProps&, nsecs_t now);
Vishnu Nairc09c0232023-03-02 03:22:35 +0000447 bool hasBuffer() const { return mBufferInfo.mBuffer != nullptr; }
Vishnu Nairb76d99a2023-03-19 18:22:31 -0700448 void setTransformHint(std::optional<ui::Transform::RotationFlags> transformHint) {
449 mTransformHint = transformHint;
450 }
Vishnu Nairc1d19d72023-08-10 12:35:11 -0700451 void commitTransaction();
Vishnu Nair7ee4f462023-04-19 09:54:09 -0700452 // Keeps track of the previously presented layer stacks. This is used to get
453 // the release fences from the correct displays when we release the last buffer
454 // from the layer.
455 std::vector<ui::LayerStack> mPreviouslyPresentedLayerStacks;
Melody Hsu793f8362024-01-08 20:00:35 +0000456
Alec Mouri9892aac2023-12-11 21:16:59 +0000457 struct FenceAndContinuation {
458 ftl::SharedFuture<FenceResult> future;
459 std::function<FenceResult(FenceResult)> continuation;
460
461 ftl::SharedFuture<FenceResult> chain() const {
462 if (continuation) {
463 return ftl::Future(future).then(continuation).share();
464 } else {
465 return future;
466 }
467 }
468 };
Melody Hsu793f8362024-01-08 20:00:35 +0000469 std::vector<FenceAndContinuation> mPreviousReleaseFenceAndContinuations;
470
471 // Release fences for buffers that have not yet received a release
472 // callback. A release callback may not be given when capturing
473 // screenshots asynchronously. There may be no buffer update for the
474 // layer, but the layer will still be composited on the screen in every
475 // frame. Kepping track of these fences ensures that they are not dropped
Melody Hsue4ef87f2024-03-26 23:54:45 +0000476 // and can be dispatched to the client at a later time. Older fences are
477 // dropped when a layer stack receives a new fence.
478 // TODO(b/300533018): Track fence per multi-instance RenderEngine
479 ftl::SmallMap<ui::LayerStack, ftl::Future<FenceResult>, ui::kDisplayCapacity>
480 mAdditionalPreviousReleaseFences;
Melody Hsu793f8362024-01-08 20:00:35 +0000481
Josh Gao194ff392022-09-08 16:19:29 -0700482 // Exposed so SurfaceFlinger can assert that it's held
483 const sp<SurfaceFlinger> mFlinger;
484
Arthur Hungc70bee22023-06-02 01:35:52 +0000485 // Check if the damage region is a small dirty.
Arthur Hung69f95222023-10-04 07:39:02 +0000486 void setIsSmallDirty(frontend::LayerSnapshot* snapshot);
Arthur Hungc70bee22023-06-02 01:35:52 +0000487
Mathias Agopian13127d82013-03-05 17:47:11 -0800488protected:
Peiyong Linf243e5e2020-08-22 17:40:59 -0700489 // For unit tests
490 friend class TestableSurfaceFlinger;
Alec Mouriadebf5c2021-01-05 12:57:36 -0800491 friend class FpsReporterTest;
Peiyong Linf243e5e2020-08-22 17:40:59 -0700492 friend class RefreshRateSelectionTest;
493 friend class SetFrameRateTest;
Adithya Srinivasanb238cd52021-02-04 17:54:05 +0000494 friend class TransactionFrameTracerTest;
Adithya Srinivasanb9a7dab2021-01-14 23:49:46 +0000495 friend class TransactionSurfaceFrameTest;
Peiyong Linf243e5e2020-08-22 17:40:59 -0700496
Patrick Williamsbb25f802022-08-30 23:02:34 +0000497 void gatherBufferInfo();
Peiyong Linf243e5e2020-08-22 17:40:59 -0700498
Peiyong Linf243e5e2020-08-22 17:40:59 -0700499 compositionengine::OutputLayer* findOutputLayerForDisplay(const DisplayDevice*) const;
Vishnu Nair3cc15a42023-06-30 06:20:22 +0000500 compositionengine::OutputLayer* findOutputLayerForDisplay(
501 const DisplayDevice*, const frontend::LayerHierarchy::TraversalPath& path) const;
Peiyong Linf243e5e2020-08-22 17:40:59 -0700502
Dominik Laskowski87a07e42019-10-10 20:38:02 -0700503 const std::string mName;
504 const std::string mTransactionName{"TX - " + mName};
Mathias Agopian13127d82013-03-05 17:47:11 -0800505
Vishnu Nairdc83d4b2024-08-15 16:29:20 +0000506 // These are only accessed by the main thread.
Lloyd Pique0449b0f2018-12-20 16:23:45 -0800507 State mDrawingState;
Lloyd Pique0449b0f2018-12-20 16:23:45 -0800508
Chavi Weingarten076acac2023-01-19 17:20:43 +0000509 TrustedPresentationThresholds mTrustedPresentationThresholds;
510 TrustedPresentationListener mTrustedPresentationListener;
511 bool mLastComputedTrustedPresentationState = false;
512 bool mLastReportedTrustedPresentationState = false;
513 int64_t mEnteredTrustedPresentationStateTime = -1;
514
Robert Carr38d25002021-06-11 14:30:09 -0700515 uint32_t mTransactionFlags{0};
Robert Carr6a160312021-05-17 12:08:20 -0700516 // Updated in doTransaction, used to track the last sequence number we
517 // committed. Currently this is really only used for updating visible
518 // regions.
519 int32_t mLastCommittedTxSequence = -1;
Dan Stoza7dde5992015-05-22 09:51:44 -0700520
Brian Andersond6927fb2016-07-23 23:37:30 -0700521 // Timestamp history for UIAutomation. Thread safe.
Jamie Gennis4b0eba92013-02-05 13:30:24 -0800522 FrameTracker mFrameTracker;
Mathias Agopiana67932f2011-04-20 14:20:59 -0700523
524 // main thread
Lloyd Pique0b785d82018-12-04 17:25:27 -0800525 sp<NativeHandle> mSidebandStream;
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000526
Robert Carrc3574f72016-03-24 12:19:32 -0700527 // We encode unset as -1.
Lloyd Pique42ab75e2018-09-12 20:46:03 -0700528 std::atomic<uint64_t> mCurrentFrameNumber{0};
Mathias Agopian13127d82013-03-05 17:47:11 -0800529
530 // protected by mLock
531 mutable Mutex mLock;
David Sodman0c69cad2017-08-21 12:12:51 -0700532
Riley Andrews03414a12014-07-01 14:22:59 -0700533 // This layer can be a cursor on some displays.
Lloyd Pique42ab75e2018-09-12 20:46:03 -0700534 bool mPotentialCursor{false};
Dan Stoza6b9454d2014-11-07 16:00:59 -0800535
Ady Abraham8f1ee7f2019-04-05 10:32:50 -0700536 // Window types from WindowManager.LayoutParams
chaviw98318de2021-05-19 16:45:23 -0500537 const gui::WindowInfo::Type mWindowType;
Ady Abraham8f1ee7f2019-04-05 10:32:50 -0700538
Alec Mouri9a29e672020-09-14 12:39:14 -0700539 // The owner of the layer. If created from a non system process, it will be the calling uid.
540 // If created from a system process, the value can be passed in.
541 uid_t mOwnerUid;
542
Adithya Srinivasan9febda82020-10-19 10:49:41 -0700543 // The owner pid of the layer. If created from a non system process, it will be the calling pid.
544 // If created from a system process, the value can be passed in.
545 pid_t mOwnerPid;
546
Tony Huangf3621102023-09-04 17:14:22 +0800547 int32_t mOwnerAppId;
548
Adithya Srinivasanb9a7dab2021-01-14 23:49:46 +0000549 // Keeps track of the time SF latched the last buffer from this layer.
550 // Used in buffer stuffing analysis in FrameTimeline.
551 nsecs_t mLastLatchTime = 0;
552
Robert Carrccab4242021-09-28 16:53:03 -0700553 sp<Fence> mLastClientCompositionFence;
Robert Carr05da0082022-05-25 23:29:34 -0700554 bool mClearClientCompositionFenceOnLayerDisplayed = false;
chaviw4b129c22018-04-09 16:19:43 -0700555private:
Tony Huangf3621102023-09-04 17:14:22 +0800556 // Range of uids allocated for a user.
557 // This value is taken from android.os.UserHandle#PER_USER_RANGE.
558 static constexpr int32_t PER_USER_RANGE = 100000;
559
Patrick Williamsbb25f802022-08-30 23:02:34 +0000560 friend class SlotGenerationTest;
561 friend class TransactionFrameTracerTest;
562 friend class TransactionSurfaceFrameTest;
563
Patrick Williamsbb25f802022-08-30 23:02:34 +0000564 bool getSidebandStreamChanged() const { return mSidebandStreamChanged; }
565
566 std::atomic<bool> mSidebandStreamChanged{false};
Dominik Laskowskib7251f42020-04-20 17:42:59 -0700567
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500568 aidl::android::hardware::graphics::composer3::Composition getCompositionType(
569 const DisplayDevice&) const;
Vishnu Nair3cc15a42023-06-30 06:20:22 +0000570 aidl::android::hardware::graphics::composer3::Composition getCompositionType(
571 const compositionengine::OutputLayer*) const;
Vishnu Nair4351ad52019-02-11 14:13:02 -0800572
Patrick Williamsbb25f802022-08-30 23:02:34 +0000573 inline void tracePendingBufferCount(int32_t pendingBuffers);
574
575 // Latch sideband stream and returns true if the dirty region should be updated.
576 bool latchSidebandStream(bool& recomputeVisibleRegions);
577
Vishnu Naird47bcee2023-02-24 18:08:51 +0000578 void updateTexImage(nsecs_t latchTime, bool bgColorOnly = false);
Patrick Williamsbb25f802022-08-30 23:02:34 +0000579
580 // Crop that applies to the buffer
581 Rect computeBufferCrop(const State& s);
582
Patrick Williamsbb25f802022-08-30 23:02:34 +0000583 void callReleaseBufferCallback(const sp<ITransactionCompletedListener>& listener,
584 const sp<GraphicBuffer>& buffer, uint64_t framenumber,
585 const sp<Fence>& releaseFence,
586 uint32_t currentMaxAcquiredBufferCount);
587
Patrick Williamsbb25f802022-08-30 23:02:34 +0000588 bool hasBufferOrSidebandStream() const {
589 return ((mSidebandStream != nullptr) || (mBufferInfo.mBuffer != nullptr));
590 }
591
Vishnu Nair22491b82022-10-18 14:59:14 -0700592 bool hasBufferOrSidebandStreamInDrawing() const {
593 return ((mDrawingState.sidebandStream != nullptr) || (mDrawingState.buffer != nullptr));
594 }
595
Robert Carrc0df3122019-04-11 13:18:21 -0700596 bool mGetHandleCalled = false;
chaviw43cb3cb2019-05-31 15:23:41 -0700597
Vishnu Nairc97b8db2019-10-29 18:19:35 -0700598 // The inherited shadow radius after taking into account the layer hierarchy. This is the
599 // final shadow radius for this layer. If a shadow is specified for a layer, then effective
600 // shadow radius is the set shadow radius, otherwise its the parent's shadow radius.
Vishnu Nairf37dcfb2019-11-16 07:37:09 -0800601 float mEffectiveShadowRadius = 0.f;
Lucas Dupinc3800b82020-10-02 16:24:48 -0700602
Dominik Laskowskif5d0ea52021-09-26 17:27:01 -0700603 // Game mode for the layer. Set by WindowManagerShell and recorded by SurfaceFlingerStats.
Vishnu Nair8fc721b2022-12-22 20:06:32 +0000604 gui::GameMode mGameMode = gui::GameMode::Unsupported;
Adithya Srinivasanac977e62021-05-21 22:50:56 +0000605
Vishnu Nair14d218b2021-07-13 13:57:39 -0700606 bool mIsAtRoot = false;
Vishnu Nair7fb9e5a2021-11-08 12:44:05 -0800607
608 uint32_t mLayerCreationFlags;
Tianhao Yao67dd7122022-02-22 17:48:33 +0000609
Dorin Drimuse5374e52023-08-02 17:52:43 +0000610 void releasePreviousBuffer();
Vishnu Nair7ee4f462023-04-19 09:54:09 -0700611 void resetDrawingStateBufferInfo();
Patrick Williamsbb25f802022-08-30 23:02:34 +0000612
Patrick Williamsbb25f802022-08-30 23:02:34 +0000613 // Transform hint provided to the producer. This must be accessed holding
614 // the mStateLock.
Vishnu Nairb76d99a2023-03-19 18:22:31 -0700615 std::optional<ui::Transform::RotationFlags> mTransformHint = std::nullopt;
Patrick Williamsbb25f802022-08-30 23:02:34 +0000616
Patrick Williamsbb25f802022-08-30 23:02:34 +0000617 ReleaseCallbackId mPreviousReleaseCallbackId = ReleaseCallbackId::INVALID_ID;
Vishnu Nair7ee4f462023-04-19 09:54:09 -0700618 sp<IBinder> mPreviousReleaseBufferEndpoint;
Patrick Williamsbb25f802022-08-30 23:02:34 +0000619
620 bool mReleasePreviousBuffer = false;
621
622 // Stores the last set acquire fence signal time used to populate the callback handle's acquire
623 // time.
624 std::variant<nsecs_t, sp<Fence>> mCallbackHandleAcquireTimeOrFence = -1;
625
Patrick Williamsbb25f802022-08-30 23:02:34 +0000626 const std::string mBlastTransactionName{"BufferTX - " + mName};
627 // This integer is incremented everytime a buffer arrives at the server for this layer,
628 // and decremented when a buffer is dropped or latched. When changed the integer is exported
Vishnu Nair2665ca92024-07-09 22:08:15 +0000629 // to systrace with SFTRACE_INT and mBlastTransactionName. This way when debugging perf it is
Patrick Williamsbb25f802022-08-30 23:02:34 +0000630 // possible to see when a buffer arrived at the server, and in which frame it latched.
631 //
632 // You can understand the trace this way:
633 // - If the integer increases, a buffer arrived at the server.
634 // - If the integer decreases in latchBuffer, that buffer was latched
635 // - If the integer decreases in setBuffer or doTransaction, a buffer was dropped
636 std::atomic<int32_t> mPendingBufferTransactions{0};
637
638 // Contains requested position and matrix updates. This will be applied if the client does
639 // not specify a destination frame.
640 ui::Transform mRequestedTransform;
641
Vishnu Nair3af0ec02023-02-10 04:13:48 +0000642 std::vector<std::pair<frontend::LayerHierarchy::TraversalPath, sp<LayerFE>>> mLayerFEs;
Vishnu Nair787aa782023-03-17 13:46:46 -0700643 bool mHandleAlive = false;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800644};
645
Marin Shalamanov46084422020-10-13 12:33:42 +0200646std::ostream& operator<<(std::ostream& stream, const Layer::FrameRate& rate);
647
Dominik Laskowski34157762018-10-31 13:07:19 -0700648} // namespace android