blob: 99d9ebaa921b5046b1e03c72dc6a12dacaaa367b [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
17#define LOG_TAG "SurfaceComposerClient"
18
19#include <stdint.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080020#include <sys/types.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080021
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080022#include <utils/Errors.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080023#include <utils/Log.h>
Mathias Agopiana67932f2011-04-20 14:20:59 -070024#include <utils/SortedVector.h>
25#include <utils/String8.h>
26#include <utils/threads.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080027
Marissa Wall7a9b6ff2018-08-21 17:26:20 -070028#include <binder/IPCThreadState.h>
Mathias Agopiana67932f2011-04-20 14:20:59 -070029#include <binder/IServiceManager.h>
Marissa Wall7a9b6ff2018-08-21 17:26:20 -070030#include <binder/ProcessState.h>
Mathias Agopian9cce3252010-02-09 17:46:37 -080031
Michael Wright28f24d02016-07-12 13:30:53 -070032#include <system/graphics.h>
33
Robert Carr673134e2017-01-09 19:48:38 -080034#include <gui/BufferItemConsumer.h>
Mathias Agopianabe815d2013-03-19 22:22:21 -070035#include <gui/CpuConsumer.h>
Mathias Agopiane3c697f2013-02-14 17:11:02 -080036#include <gui/IGraphicBufferProducer.h>
Mathias Agopian90ac7992012-02-25 18:48:35 -080037#include <gui/ISurfaceComposer.h>
38#include <gui/ISurfaceComposerClient.h>
Robert Carr4cdc58f2017-08-23 14:22:20 -070039#include <gui/LayerState.h>
Robert Carr0d480722017-01-10 16:42:54 -080040#include <gui/Surface.h>
Mathias Agopian90ac7992012-02-25 18:48:35 -080041#include <gui/SurfaceComposerClient.h>
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -080042#include <ui/DisplayConfig.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080043
Robert Carr2c358bf2018-08-08 15:58:15 -070044#ifndef NO_INPUT
45#include <input/InputWindow.h>
46#endif
47
Mathias Agopian41f673c2011-11-17 17:48:35 -080048#include <private/gui/ComposerService.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080049
Marissa Wall73411622019-01-25 10:45:41 -080050// This server size should always be smaller than the server cache size
51#define BUFFER_CACHE_MAX_SIZE 64
52
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080053namespace android {
Peiyong Lin9f034472018-03-28 15:29:00 -070054
55using ui::ColorMode;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080056// ---------------------------------------------------------------------------
57
Mathias Agopian7e27f052010-05-28 14:22:23 -070058ANDROID_SINGLETON_STATIC_INSTANCE(ComposerService);
59
Mathias Agopianb7e930d2010-06-01 15:12:58 -070060ComposerService::ComposerService()
61: Singleton<ComposerService>() {
Andy McFadden6652b3e2012-09-06 18:45:56 -070062 Mutex::Autolock _l(mLock);
63 connectLocked();
64}
65
66void ComposerService::connectLocked() {
Mathias Agopianb7e930d2010-06-01 15:12:58 -070067 const String16 name("SurfaceFlinger");
68 while (getService(name, &mComposerService) != NO_ERROR) {
69 usleep(250000);
70 }
Yi Konga03e0442018-07-17 11:16:57 -070071 assert(mComposerService != nullptr);
Andy McFadden6652b3e2012-09-06 18:45:56 -070072
73 // Create the death listener.
74 class DeathObserver : public IBinder::DeathRecipient {
75 ComposerService& mComposerService;
76 virtual void binderDied(const wp<IBinder>& who) {
77 ALOGW("ComposerService remote (surfaceflinger) died [%p]",
78 who.unsafe_get());
79 mComposerService.composerServiceDied();
80 }
81 public:
Chih-Hung Hsiehe2347b72016-04-25 15:41:05 -070082 explicit DeathObserver(ComposerService& mgr) : mComposerService(mgr) { }
Andy McFadden6652b3e2012-09-06 18:45:56 -070083 };
84
85 mDeathObserver = new DeathObserver(*const_cast<ComposerService*>(this));
Marco Nelissen2ea926b2014-11-14 08:01:01 -080086 IInterface::asBinder(mComposerService)->linkToDeath(mDeathObserver);
Mathias Agopianb7e930d2010-06-01 15:12:58 -070087}
88
Andy McFadden6652b3e2012-09-06 18:45:56 -070089/*static*/ sp<ISurfaceComposer> ComposerService::getComposerService() {
90 ComposerService& instance = ComposerService::getInstance();
91 Mutex::Autolock _l(instance.mLock);
Yi Kong48a619f2018-06-05 16:34:59 -070092 if (instance.mComposerService == nullptr) {
Andy McFadden6652b3e2012-09-06 18:45:56 -070093 ComposerService::getInstance().connectLocked();
Yi Konga03e0442018-07-17 11:16:57 -070094 assert(instance.mComposerService != nullptr);
Andy McFadden6652b3e2012-09-06 18:45:56 -070095 ALOGD("ComposerService reconnected");
96 }
97 return instance.mComposerService;
98}
99
100void ComposerService::composerServiceDied()
101{
102 Mutex::Autolock _l(mLock);
Yi Kong48a619f2018-06-05 16:34:59 -0700103 mComposerService = nullptr;
104 mDeathObserver = nullptr;
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700105}
106
Robert Carrfb4d58b2019-01-15 09:21:27 -0800107class DefaultComposerClient: public Singleton<DefaultComposerClient> {
108 Mutex mLock;
109 sp<SurfaceComposerClient> mClient;
110 friend class Singleton<ComposerService>;
111public:
112 static sp<SurfaceComposerClient> getComposerClient() {
113 DefaultComposerClient& dc = DefaultComposerClient::getInstance();
114 Mutex::Autolock _l(dc.mLock);
115 if (dc.mClient == nullptr) {
116 dc.mClient = new SurfaceComposerClient;
117 }
118 return dc.mClient;
119 }
120};
121ANDROID_SINGLETON_STATIC_INSTANCE(DefaultComposerClient);
122
123
124sp<SurfaceComposerClient> SurfaceComposerClient::getDefault() {
125 return DefaultComposerClient::getComposerClient();
126}
127
Mathias Agopian7e27f052010-05-28 14:22:23 -0700128// ---------------------------------------------------------------------------
129
Marissa Wall7a9b6ff2018-08-21 17:26:20 -0700130// TransactionCompletedListener does not use ANDROID_SINGLETON_STATIC_INSTANCE because it needs
131// to be able to return a sp<> to its instance to pass to SurfaceFlinger.
132// ANDROID_SINGLETON_STATIC_INSTANCE only allows a reference to an instance.
133
Marissa Wallc837b5e2018-10-12 10:04:44 -0700134// 0 is an invalid callback id
135TransactionCompletedListener::TransactionCompletedListener() : mCallbackIdCounter(1) {}
136
137CallbackId TransactionCompletedListener::getNextIdLocked() {
138 return mCallbackIdCounter++;
139}
140
Marissa Wall7a9b6ff2018-08-21 17:26:20 -0700141sp<TransactionCompletedListener> TransactionCompletedListener::getInstance() {
142 static sp<TransactionCompletedListener> sInstance = new TransactionCompletedListener;
143 return sInstance;
144}
145
Marissa Wallc837b5e2018-10-12 10:04:44 -0700146sp<ITransactionCompletedListener> TransactionCompletedListener::getIInstance() {
147 return static_cast<sp<ITransactionCompletedListener>>(getInstance());
148}
149
150void TransactionCompletedListener::startListeningLocked() {
Marissa Wall7a9b6ff2018-08-21 17:26:20 -0700151 if (mListening) {
152 return;
153 }
154 ProcessState::self()->startThreadPool();
155 mListening = true;
156}
157
Marissa Wall80d94ad2019-01-18 16:04:36 -0800158CallbackId TransactionCompletedListener::addCallbackFunction(
159 const TransactionCompletedCallback& callbackFunction,
160 const std::unordered_set<sp<SurfaceControl>, SurfaceComposerClient::SCHash>&
161 surfaceControls) {
Marissa Wallc837b5e2018-10-12 10:04:44 -0700162 std::lock_guard<std::mutex> lock(mMutex);
163 startListeningLocked();
164
165 CallbackId callbackId = getNextIdLocked();
Marissa Wall80d94ad2019-01-18 16:04:36 -0800166 mCallbacks[callbackId].callbackFunction = callbackFunction;
167
168 auto& callbackSurfaceControls = mCallbacks[callbackId].surfaceControls;
169
170 for (const auto& surfaceControl : surfaceControls) {
171 callbackSurfaceControls[surfaceControl->getHandle()] = surfaceControl;
172 }
173
Marissa Wallc837b5e2018-10-12 10:04:44 -0700174 return callbackId;
175}
176
Marissa Wall80d94ad2019-01-18 16:04:36 -0800177void TransactionCompletedListener::addSurfaceControlToCallbacks(
178 const sp<SurfaceControl>& surfaceControl,
179 const std::unordered_set<CallbackId>& callbackIds) {
180 std::lock_guard<std::mutex> lock(mMutex);
181
182 for (auto callbackId : callbackIds) {
183 mCallbacks[callbackId].surfaceControls.emplace(std::piecewise_construct,
184 std::forward_as_tuple(
185 surfaceControl->getHandle()),
186 std::forward_as_tuple(surfaceControl));
187 }
188}
189
Marissa Walle2ffb422018-10-12 11:33:52 -0700190void TransactionCompletedListener::onTransactionCompleted(ListenerStats listenerStats) {
Valerie Haud3b90d22019-11-06 09:37:31 -0800191 std::unordered_map<CallbackId, CallbackTranslation> callbacksMap;
192 {
193 std::lock_guard<std::mutex> lock(mMutex);
Marissa Walle2ffb422018-10-12 11:33:52 -0700194
Valerie Haud3b90d22019-11-06 09:37:31 -0800195 /* This listener knows all the sp<IBinder> to sp<SurfaceControl> for all its registered
196 * callbackIds, except for when Transactions are merged together. This probably cannot be
197 * solved before this point because the Transactions could be merged together and applied in
198 * a different process.
199 *
200 * Fortunately, we get all the callbacks for this listener for the same frame together at
201 * the same time. This means if any Transactions were merged together, we will get their
202 * callbacks at the same time. We can combine all the sp<IBinder> to sp<SurfaceControl> maps
203 * for all the callbackIds to generate one super map that contains all the sp<IBinder> to
204 * sp<SurfaceControl> that could possibly exist for the callbacks.
205 */
206 callbacksMap = mCallbacks;
207 for (const auto& transactionStats : listenerStats.transactionStats) {
208 for (auto& callbackId : transactionStats.callbackIds) {
209 mCallbacks.erase(callbackId);
210 }
Marissa Wall80d94ad2019-01-18 16:04:36 -0800211 }
212 }
Marissa Walld600d572019-03-26 15:38:50 -0700213 for (const auto& transactionStats : listenerStats.transactionStats) {
214 for (auto callbackId : transactionStats.callbackIds) {
Valerie Haud3b90d22019-11-06 09:37:31 -0800215 auto& [callbackFunction, callbackSurfaceControls] = callbacksMap[callbackId];
Marissa Wall80d94ad2019-01-18 16:04:36 -0800216 if (!callbackFunction) {
Marissa Walle2ffb422018-10-12 11:33:52 -0700217 ALOGE("cannot call null callback function, skipping");
218 continue;
219 }
Marissa Wall80d94ad2019-01-18 16:04:36 -0800220 std::vector<SurfaceControlStats> surfaceControlStats;
221 for (const auto& surfaceStats : transactionStats.surfaceStats) {
Valerie Haud3b90d22019-11-06 09:37:31 -0800222 surfaceControlStats
223 .emplace_back(callbacksMap[callbackId]
224 .surfaceControls[surfaceStats.surfaceControl],
Valerie Hau871d6352020-01-29 08:44:02 -0800225 transactionStats.latchTime, surfaceStats.acquireTime,
226 transactionStats.presentFence,
227 surfaceStats.previousReleaseFence, surfaceStats.transformHint,
228 surfaceStats.eventStats);
Valerie Hau84d87ff2020-01-08 17:23:21 -0800229 if (callbacksMap[callbackId].surfaceControls[surfaceStats.surfaceControl]) {
230 callbacksMap[callbackId]
231 .surfaceControls[surfaceStats.surfaceControl]
232 ->setTransformHint(surfaceStats.transformHint);
233 }
Marissa Wall80d94ad2019-01-18 16:04:36 -0800234 }
235
236 callbackFunction(transactionStats.latchTime, transactionStats.presentFence,
237 surfaceControlStats);
Marissa Walle2ffb422018-10-12 11:33:52 -0700238 }
239 }
Marissa Wall7a9b6ff2018-08-21 17:26:20 -0700240}
241
242// ---------------------------------------------------------------------------
243
Robert Carre06ad2b2020-04-10 15:09:33 -0700244void removeDeadBufferCallback(void* /*context*/, uint64_t graphicBufferId);
Marissa Wall78b72202019-03-15 14:58:34 -0700245
Robert Carre06ad2b2020-04-10 15:09:33 -0700246/**
247 * We use the BufferCache to reduce the overhead of exchanging GraphicBuffers with
248 * the server. If we were to simply parcel the GraphicBuffer we would pay two overheads
249 * 1. Cost of sending the FD
250 * 2. Cost of importing the GraphicBuffer with the mapper in the receiving process.
251 * To ease this cost we implement the following scheme of caching buffers to integers,
252 * or said-otherwise, naming them with integers. This is the scheme known as slots in
253 * the legacy BufferQueue system.
254 * 1. When sending Buffers to SurfaceFlinger we look up the Buffer in the cache.
255 * 2. If there is a cache-hit we remove the Buffer from the Transaction and instead
256 * send the cached integer.
257 * 3. If there is a cache miss, we cache the new buffer and send the integer
258 * along with the Buffer, SurfaceFlinger on it's side creates a new cache
259 * entry, and we use the integer for further communication.
260 * A few details about lifetime:
261 * 1. The cache evicts by LRU. The server side cache is keyed by BufferCache::getToken
262 * which is per process Unique. The server side cache is larger than the client side
263 * cache so that the server will never evict entries before the client.
264 * 2. When the client evicts an entry it notifies the server via an uncacheBuffer
265 * transaction.
266 * 3. The client only references the Buffers by ID, and uses buffer->addDeathCallback
267 * to auto-evict destroyed buffers.
268 */
Marissa Wall73411622019-01-25 10:45:41 -0800269class BufferCache : public Singleton<BufferCache> {
270public:
271 BufferCache() : token(new BBinder()) {}
272
273 sp<IBinder> getToken() {
274 return IInterface::asBinder(TransactionCompletedListener::getIInstance());
275 }
276
Marissa Wall78b72202019-03-15 14:58:34 -0700277 status_t getCacheId(const sp<GraphicBuffer>& buffer, uint64_t* cacheId) {
Yi Kongd2639aa2019-02-28 11:58:32 -0800278 std::lock_guard<std::mutex> lock(mMutex);
Marissa Wall73411622019-01-25 10:45:41 -0800279
Marissa Wall78b72202019-03-15 14:58:34 -0700280 auto itr = mBuffers.find(buffer->getId());
Marissa Wall73411622019-01-25 10:45:41 -0800281 if (itr == mBuffers.end()) {
Marissa Wall78b72202019-03-15 14:58:34 -0700282 return BAD_VALUE;
Marissa Wall73411622019-01-25 10:45:41 -0800283 }
Marissa Wall78b72202019-03-15 14:58:34 -0700284 itr->second = getCounter();
285 *cacheId = buffer->getId();
286 return NO_ERROR;
Marissa Wall73411622019-01-25 10:45:41 -0800287 }
288
Marissa Wall78b72202019-03-15 14:58:34 -0700289 uint64_t cache(const sp<GraphicBuffer>& buffer) {
Yi Kongd2639aa2019-02-28 11:58:32 -0800290 std::lock_guard<std::mutex> lock(mMutex);
Marissa Wall73411622019-01-25 10:45:41 -0800291
Marissa Wall78b72202019-03-15 14:58:34 -0700292 if (mBuffers.size() >= BUFFER_CACHE_MAX_SIZE) {
293 evictLeastRecentlyUsedBuffer();
294 }
Marissa Wall73411622019-01-25 10:45:41 -0800295
Robert Carre06ad2b2020-04-10 15:09:33 -0700296 buffer->addDeathCallback(removeDeadBufferCallback, nullptr);
Marissa Wall78b72202019-03-15 14:58:34 -0700297
298 mBuffers[buffer->getId()] = getCounter();
299 return buffer->getId();
300 }
301
302 void uncache(uint64_t cacheId) {
303 std::lock_guard<std::mutex> lock(mMutex);
304 uncacheLocked(cacheId);
305 }
306
307 void uncacheLocked(uint64_t cacheId) REQUIRES(mMutex) {
308 mBuffers.erase(cacheId);
309 SurfaceComposerClient::doUncacheBufferTransaction(cacheId);
Marissa Wall73411622019-01-25 10:45:41 -0800310 }
311
312private:
Marissa Wall78b72202019-03-15 14:58:34 -0700313 void evictLeastRecentlyUsedBuffer() REQUIRES(mMutex) {
Marissa Wall73411622019-01-25 10:45:41 -0800314 auto itr = mBuffers.begin();
Marissa Wall78b72202019-03-15 14:58:34 -0700315 uint64_t minCounter = itr->second;
Marissa Wall73411622019-01-25 10:45:41 -0800316 auto minBuffer = itr;
317 itr++;
318
319 while (itr != mBuffers.end()) {
Marissa Wall78b72202019-03-15 14:58:34 -0700320 uint64_t counter = itr->second;
Marissa Wall73411622019-01-25 10:45:41 -0800321 if (counter < minCounter) {
322 minCounter = counter;
323 minBuffer = itr;
324 }
325 itr++;
326 }
Marissa Wall78b72202019-03-15 14:58:34 -0700327 uncacheLocked(minBuffer->first);
Marissa Wall73411622019-01-25 10:45:41 -0800328 }
329
330 uint64_t getCounter() REQUIRES(mMutex) {
331 static uint64_t counter = 0;
332 return counter++;
333 }
334
Marissa Wall73411622019-01-25 10:45:41 -0800335 std::mutex mMutex;
Marissa Wall78b72202019-03-15 14:58:34 -0700336 std::map<uint64_t /*Cache id*/, uint64_t /*counter*/> mBuffers GUARDED_BY(mMutex);
Marissa Wall73411622019-01-25 10:45:41 -0800337
338 // Used by ISurfaceComposer to identify which process is sending the cached buffer.
339 sp<IBinder> token;
340};
341
342ANDROID_SINGLETON_STATIC_INSTANCE(BufferCache);
343
Robert Carre06ad2b2020-04-10 15:09:33 -0700344void removeDeadBufferCallback(void* /*context*/, uint64_t graphicBufferId) {
Marissa Wall78b72202019-03-15 14:58:34 -0700345 // GraphicBuffer id's are used as the cache ids.
346 BufferCache::getInstance().uncache(graphicBufferId);
347}
348
Marissa Wall73411622019-01-25 10:45:41 -0800349// ---------------------------------------------------------------------------
350
Pablo Gamito7eb7ee72020-08-05 10:57:05 +0000351// Initialize transaction id counter used to generate transaction ids
352// Transactions will start counting at 1, 0 is used for invalid transactions
353std::atomic<uint32_t> SurfaceComposerClient::Transaction::idCounter = 1;
354
355SurfaceComposerClient::Transaction::Transaction() {
356 mId = generateId();
357}
358
Marissa Wall17b4e452018-12-26 16:32:34 -0800359SurfaceComposerClient::Transaction::Transaction(const Transaction& other)
Pablo Gamito7eb7ee72020-08-05 10:57:05 +0000360 : mId(other.mId),
361 mForceSynchronous(other.mForceSynchronous),
Marissa Wall17b4e452018-12-26 16:32:34 -0800362 mTransactionNestCount(other.mTransactionNestCount),
363 mAnimation(other.mAnimation),
364 mEarlyWakeup(other.mEarlyWakeup),
Ady Abrahambf1349c2020-06-12 14:26:18 -0700365 mExplicitEarlyWakeupStart(other.mExplicitEarlyWakeupStart),
366 mExplicitEarlyWakeupEnd(other.mExplicitEarlyWakeupEnd),
Vishnu Nair621102e2019-06-12 14:16:57 -0700367 mContainsBuffer(other.mContainsBuffer),
Ady Abraham22c7b5c2020-09-22 19:33:40 -0700368 mDesiredPresentTime(other.mDesiredPresentTime),
369 mFrameTimelineVsyncId(other.mFrameTimelineVsyncId) {
Robert Carr4cdc58f2017-08-23 14:22:20 -0700370 mDisplayStates = other.mDisplayStates;
371 mComposerStates = other.mComposerStates;
chaviw273171b2018-12-26 11:46:30 -0800372 mInputWindowCommands = other.mInputWindowCommands;
Vishnu Nair621102e2019-06-12 14:16:57 -0700373 mListenerCallbacks = other.mListenerCallbacks;
374}
375
376std::unique_ptr<SurfaceComposerClient::Transaction>
377SurfaceComposerClient::Transaction::createFromParcel(const Parcel* parcel) {
378 auto transaction = std::make_unique<Transaction>();
379 if (transaction->readFromParcel(parcel) == NO_ERROR) {
380 return transaction;
381 }
382 return nullptr;
383}
384
Pablo Gamito7eb7ee72020-08-05 10:57:05 +0000385int64_t SurfaceComposerClient::Transaction::generateId() {
386 return (((int64_t)getpid()) << 32) | idCounter++;
387}
388
Vishnu Nair621102e2019-06-12 14:16:57 -0700389status_t SurfaceComposerClient::Transaction::readFromParcel(const Parcel* parcel) {
390 const uint32_t forceSynchronous = parcel->readUint32();
391 const uint32_t transactionNestCount = parcel->readUint32();
392 const bool animation = parcel->readBool();
393 const bool earlyWakeup = parcel->readBool();
Ady Abrahambf1349c2020-06-12 14:26:18 -0700394 const bool explicitEarlyWakeupStart = parcel->readBool();
395 const bool explicitEarlyWakeupEnd = parcel->readBool();
Vishnu Nair621102e2019-06-12 14:16:57 -0700396 const bool containsBuffer = parcel->readBool();
397 const int64_t desiredPresentTime = parcel->readInt64();
Ady Abraham22c7b5c2020-09-22 19:33:40 -0700398 const int64_t frameTimelineVsyncId = parcel->readInt64();
Vishnu Nair621102e2019-06-12 14:16:57 -0700399
400 size_t count = static_cast<size_t>(parcel->readUint32());
401 if (count > parcel->dataSize()) {
402 return BAD_VALUE;
403 }
404 SortedVector<DisplayState> displayStates;
405 displayStates.setCapacity(count);
406 for (size_t i = 0; i < count; i++) {
407 DisplayState displayState;
408 if (displayState.read(*parcel) == BAD_VALUE) {
409 return BAD_VALUE;
410 }
411 displayStates.add(displayState);
412 }
413
414 count = static_cast<size_t>(parcel->readUint32());
415 if (count > parcel->dataSize()) {
416 return BAD_VALUE;
417 }
Valerie Hau9dab9732019-08-20 09:29:25 -0700418 std::unordered_map<sp<ITransactionCompletedListener>, CallbackInfo, TCLHash> listenerCallbacks;
419 listenerCallbacks.reserve(count);
420 for (size_t i = 0; i < count; i++) {
421 sp<ITransactionCompletedListener> listener =
422 interface_cast<ITransactionCompletedListener>(parcel->readStrongBinder());
423 size_t numCallbackIds = parcel->readUint32();
424 if (numCallbackIds > parcel->dataSize()) {
425 return BAD_VALUE;
426 }
427 for (size_t j = 0; j < numCallbackIds; j++) {
428 listenerCallbacks[listener].callbackIds.insert(parcel->readInt64());
429 }
430 size_t numSurfaces = parcel->readUint32();
431 if (numSurfaces > parcel->dataSize()) {
432 return BAD_VALUE;
433 }
434 for (size_t j = 0; j < numSurfaces; j++) {
435 sp<SurfaceControl> surface;
Pablo Gamito421dfd52020-09-22 18:11:45 +0000436 SAFE_PARCEL(SurfaceControl::readFromParcel, *parcel, &surface);
Valerie Hau9dab9732019-08-20 09:29:25 -0700437 listenerCallbacks[listener].surfaceControls.insert(surface);
438 }
439 }
440
441 count = static_cast<size_t>(parcel->readUint32());
442 if (count > parcel->dataSize()) {
443 return BAD_VALUE;
444 }
Vishnu Nairf03652d2019-07-16 17:56:56 -0700445 std::unordered_map<sp<IBinder>, ComposerState, IBinderHash> composerStates;
Vishnu Nair621102e2019-06-12 14:16:57 -0700446 composerStates.reserve(count);
447 for (size_t i = 0; i < count; i++) {
Pablo Gamitodbc31672020-09-01 18:28:58 +0000448 sp<IBinder> surfaceControlHandle;
449 SAFE_PARCEL(parcel->readStrongBinder, &surfaceControlHandle);
Vishnu Nair621102e2019-06-12 14:16:57 -0700450
451 ComposerState composerState;
452 if (composerState.read(*parcel) == BAD_VALUE) {
453 return BAD_VALUE;
454 }
Pablo Gamitodbc31672020-09-01 18:28:58 +0000455
Vishnu Nairf03652d2019-07-16 17:56:56 -0700456 composerStates[surfaceControlHandle] = composerState;
Vishnu Nair621102e2019-06-12 14:16:57 -0700457 }
458
459 InputWindowCommands inputWindowCommands;
460 inputWindowCommands.read(*parcel);
461
462 // Parsing was successful. Update the object.
463 mForceSynchronous = forceSynchronous;
464 mTransactionNestCount = transactionNestCount;
465 mAnimation = animation;
466 mEarlyWakeup = earlyWakeup;
Ady Abrahambf1349c2020-06-12 14:26:18 -0700467 mExplicitEarlyWakeupStart = explicitEarlyWakeupStart;
468 mExplicitEarlyWakeupEnd = explicitEarlyWakeupEnd;
Vishnu Nair621102e2019-06-12 14:16:57 -0700469 mContainsBuffer = containsBuffer;
470 mDesiredPresentTime = desiredPresentTime;
Ady Abraham22c7b5c2020-09-22 19:33:40 -0700471 mFrameTimelineVsyncId = frameTimelineVsyncId;
Vishnu Nair621102e2019-06-12 14:16:57 -0700472 mDisplayStates = displayStates;
Valerie Hau9dab9732019-08-20 09:29:25 -0700473 mListenerCallbacks = listenerCallbacks;
Vishnu Nair621102e2019-06-12 14:16:57 -0700474 mComposerStates = composerStates;
475 mInputWindowCommands = inputWindowCommands;
Vishnu Nair621102e2019-06-12 14:16:57 -0700476 return NO_ERROR;
477}
478
479status_t SurfaceComposerClient::Transaction::writeToParcel(Parcel* parcel) const {
Robert Carr158531d2020-04-08 10:53:30 -0700480 // If we write the Transaction to a parcel, we want to ensure the Buffers are cached
481 // before crossing the IPC boundary. Otherwise the receiving party will cache the buffers
482 // but is unlikely to use them again as they are owned by the other process.
483 // You may be asking yourself, is this const cast safe? Const cast is safe up
484 // until the point where you try and write to an object that was originally const at which
485 // point we enter undefined behavior. In this case we are safe though, because there are
486 // two possibilities:
487 // 1. The SurfaceComposerClient::Transaction was originally non-const. Safe.
488 // 2. It was originall const! In this case not only was it useless, but it by definition
489 // contains no composer states and so cacheBuffers will not perform any writes.
490
491 const_cast<SurfaceComposerClient::Transaction*>(this)->cacheBuffers();
492
Vishnu Nair621102e2019-06-12 14:16:57 -0700493 parcel->writeUint32(mForceSynchronous);
494 parcel->writeUint32(mTransactionNestCount);
495 parcel->writeBool(mAnimation);
496 parcel->writeBool(mEarlyWakeup);
Ady Abrahambf1349c2020-06-12 14:26:18 -0700497 parcel->writeBool(mExplicitEarlyWakeupStart);
498 parcel->writeBool(mExplicitEarlyWakeupEnd);
Vishnu Nair621102e2019-06-12 14:16:57 -0700499 parcel->writeBool(mContainsBuffer);
500 parcel->writeInt64(mDesiredPresentTime);
Ady Abraham22c7b5c2020-09-22 19:33:40 -0700501 parcel->writeInt64(mFrameTimelineVsyncId);
Vishnu Nair621102e2019-06-12 14:16:57 -0700502 parcel->writeUint32(static_cast<uint32_t>(mDisplayStates.size()));
503 for (auto const& displayState : mDisplayStates) {
504 displayState.write(*parcel);
505 }
506
Valerie Hau9dab9732019-08-20 09:29:25 -0700507 parcel->writeUint32(static_cast<uint32_t>(mListenerCallbacks.size()));
508 for (auto const& [listener, callbackInfo] : mListenerCallbacks) {
509 parcel->writeStrongBinder(ITransactionCompletedListener::asBinder(listener));
510 parcel->writeUint32(static_cast<uint32_t>(callbackInfo.callbackIds.size()));
511 for (auto callbackId : callbackInfo.callbackIds) {
512 parcel->writeInt64(callbackId);
513 }
514 parcel->writeUint32(static_cast<uint32_t>(callbackInfo.surfaceControls.size()));
515 for (auto surfaceControl : callbackInfo.surfaceControls) {
Pablo Gamito421dfd52020-09-22 18:11:45 +0000516 SAFE_PARCEL(surfaceControl->writeToParcel, *parcel);
Valerie Hau9dab9732019-08-20 09:29:25 -0700517 }
518 }
519
Vishnu Nair621102e2019-06-12 14:16:57 -0700520 parcel->writeUint32(static_cast<uint32_t>(mComposerStates.size()));
Pablo Gamitodbc31672020-09-01 18:28:58 +0000521 for (auto const& [handle, composerState] : mComposerStates) {
522 SAFE_PARCEL(parcel->writeStrongBinder, handle);
Vishnu Nair621102e2019-06-12 14:16:57 -0700523 composerState.write(*parcel);
524 }
525
526 mInputWindowCommands.write(*parcel);
527 return NO_ERROR;
Mathias Agopian698c0872011-06-28 19:09:31 -0700528}
529
Robert Carr2c5f6d22017-09-26 12:30:35 -0700530SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::merge(Transaction&& other) {
Pablo Gamitodbc31672020-09-01 18:28:58 +0000531 for (auto const& [handle, composerState] : other.mComposerStates) {
532 if (mComposerStates.count(handle) == 0) {
533 mComposerStates[handle] = composerState;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700534 } else {
Pablo Gamitodbc31672020-09-01 18:28:58 +0000535 mComposerStates[handle].state.merge(composerState.state);
Robert Carr2c5f6d22017-09-26 12:30:35 -0700536 }
537 }
Robert Carr2c5f6d22017-09-26 12:30:35 -0700538
539 for (auto const& state : other.mDisplayStates) {
540 ssize_t index = mDisplayStates.indexOf(state);
541 if (index < 0) {
542 mDisplayStates.add(state);
543 } else {
544 mDisplayStates.editItemAt(static_cast<size_t>(index)).merge(state);
545 }
546 }
Robert Carr2c5f6d22017-09-26 12:30:35 -0700547
Marissa Wallc837b5e2018-10-12 10:04:44 -0700548 for (const auto& [listener, callbackInfo] : other.mListenerCallbacks) {
549 auto& [callbackIds, surfaceControls] = callbackInfo;
550 mListenerCallbacks[listener].callbackIds.insert(std::make_move_iterator(
551 callbackIds.begin()),
552 std::make_move_iterator(callbackIds.end()));
Valerie Hau9dab9732019-08-20 09:29:25 -0700553
Valerie Hau236eba32020-01-03 16:53:39 -0800554 mListenerCallbacks[listener].surfaceControls.insert(surfaceControls.begin(),
555 surfaceControls.end());
556
557 auto& currentProcessCallbackInfo =
558 mListenerCallbacks[TransactionCompletedListener::getIInstance()];
559 currentProcessCallbackInfo.surfaceControls
560 .insert(std::make_move_iterator(surfaceControls.begin()),
561 std::make_move_iterator(surfaceControls.end()));
562
563 // register all surface controls for all callbackIds for this listener that is merging
564 for (const auto& surfaceControl : currentProcessCallbackInfo.surfaceControls) {
565 TransactionCompletedListener::getInstance()
566 ->addSurfaceControlToCallbacks(surfaceControl,
567 currentProcessCallbackInfo.callbackIds);
568 }
Marissa Wallc837b5e2018-10-12 10:04:44 -0700569 }
Marissa Wallc837b5e2018-10-12 10:04:44 -0700570
chaviw273171b2018-12-26 11:46:30 -0800571 mInputWindowCommands.merge(other.mInputWindowCommands);
572
Robert Carrbbc85622020-04-08 10:45:12 -0700573 mContainsBuffer |= other.mContainsBuffer;
Jorim Jaggie3b57002019-07-22 17:18:52 +0200574 mEarlyWakeup = mEarlyWakeup || other.mEarlyWakeup;
Ady Abrahambf1349c2020-06-12 14:26:18 -0700575 mExplicitEarlyWakeupStart = mExplicitEarlyWakeupStart || other.mExplicitEarlyWakeupStart;
576 mExplicitEarlyWakeupEnd = mExplicitEarlyWakeupEnd || other.mExplicitEarlyWakeupEnd;
Ady Abraham22c7b5c2020-09-22 19:33:40 -0700577
578 // When merging vsync Ids we take the oldest one
579 if (mFrameTimelineVsyncId != ISurfaceComposer::INVALID_VSYNC_ID &&
580 other.mFrameTimelineVsyncId != ISurfaceComposer::INVALID_VSYNC_ID) {
581 mFrameTimelineVsyncId = std::max(mFrameTimelineVsyncId, other.mFrameTimelineVsyncId);
582 } else if (mFrameTimelineVsyncId == ISurfaceComposer::INVALID_VSYNC_ID) {
583 mFrameTimelineVsyncId = other.mFrameTimelineVsyncId;
584 }
585
Vishnu Nairfef244e2019-06-17 18:07:51 -0700586 other.clear();
Robert Carr2c5f6d22017-09-26 12:30:35 -0700587 return *this;
588}
589
Vishnu Nairfef244e2019-06-17 18:07:51 -0700590void SurfaceComposerClient::Transaction::clear() {
591 mComposerStates.clear();
592 mDisplayStates.clear();
593 mListenerCallbacks.clear();
594 mInputWindowCommands.clear();
595 mContainsBuffer = false;
596 mForceSynchronous = 0;
597 mTransactionNestCount = 0;
598 mAnimation = false;
599 mEarlyWakeup = false;
Ady Abrahambf1349c2020-06-12 14:26:18 -0700600 mExplicitEarlyWakeupStart = false;
601 mExplicitEarlyWakeupEnd = false;
Vishnu Nairfef244e2019-06-17 18:07:51 -0700602 mDesiredPresentTime = -1;
Ady Abraham22c7b5c2020-09-22 19:33:40 -0700603 mFrameTimelineVsyncId = ISurfaceComposer::INVALID_VSYNC_ID;
Vishnu Nairfef244e2019-06-17 18:07:51 -0700604}
605
Marissa Wall78b72202019-03-15 14:58:34 -0700606void SurfaceComposerClient::doUncacheBufferTransaction(uint64_t cacheId) {
607 sp<ISurfaceComposer> sf(ComposerService::getComposerService());
608
Marissa Wall947d34e2019-03-29 14:03:53 -0700609 client_cache_t uncacheBuffer;
Marissa Wall78b72202019-03-15 14:58:34 -0700610 uncacheBuffer.token = BufferCache::getInstance().getToken();
Marissa Wall947d34e2019-03-29 14:03:53 -0700611 uncacheBuffer.id = cacheId;
Marissa Wall78b72202019-03-15 14:58:34 -0700612
Valerie Haufa889122019-04-15 13:56:05 -0700613 sp<IBinder> applyToken = IInterface::asBinder(TransactionCompletedListener::getIInstance());
Ady Abraham22c7b5c2020-09-22 19:33:40 -0700614 sf->setTransactionState(ISurfaceComposer::INVALID_VSYNC_ID, {}, {}, 0, applyToken, {}, -1,
615 uncacheBuffer, false, {}, 0 /* Undefined transactionId */);
Marissa Wall78b72202019-03-15 14:58:34 -0700616}
617
618void SurfaceComposerClient::Transaction::cacheBuffers() {
619 if (!mContainsBuffer) {
620 return;
621 }
622
623 size_t count = 0;
Vishnu Nairf03652d2019-07-16 17:56:56 -0700624 for (auto& [handle, cs] : mComposerStates) {
Pablo Gamitodbc31672020-09-01 18:28:58 +0000625 layer_state_t* s = &(mComposerStates[handle].state);
Marissa Wall78b72202019-03-15 14:58:34 -0700626 if (!(s->what & layer_state_t::eBufferChanged)) {
627 continue;
Robert Carr28037922020-04-08 10:57:07 -0700628 } else if (s->what & layer_state_t::eCachedBufferChanged) {
629 // If eBufferChanged and eCachedBufferChanged are both trued then that means
630 // we already cached the buffer in a previous call to cacheBuffers, perhaps
631 // from writeToParcel on a Transaction that was merged in to this one.
632 continue;
Marissa Wall78b72202019-03-15 14:58:34 -0700633 }
634
Marissa Wall00597242019-03-27 10:35:19 -0700635 // Don't try to cache a null buffer. Sending null buffers is cheap so we shouldn't waste
636 // time trying to cache them.
637 if (!s->buffer) {
638 continue;
639 }
640
Marissa Wall78b72202019-03-15 14:58:34 -0700641 uint64_t cacheId = 0;
642 status_t ret = BufferCache::getInstance().getCacheId(s->buffer, &cacheId);
643 if (ret == NO_ERROR) {
Robert Carre06ad2b2020-04-10 15:09:33 -0700644 // Cache-hit. Strip the buffer and send only the id.
Marissa Walla141abe2019-03-27 16:28:07 -0700645 s->what &= ~static_cast<uint64_t>(layer_state_t::eBufferChanged);
Marissa Wall78b72202019-03-15 14:58:34 -0700646 s->buffer = nullptr;
647 } else {
Robert Carre06ad2b2020-04-10 15:09:33 -0700648 // Cache-miss. Include the buffer and send the new cacheId.
Marissa Wall78b72202019-03-15 14:58:34 -0700649 cacheId = BufferCache::getInstance().cache(s->buffer);
650 }
651 s->what |= layer_state_t::eCachedBufferChanged;
652 s->cachedBuffer.token = BufferCache::getInstance().getToken();
Marissa Wall947d34e2019-03-29 14:03:53 -0700653 s->cachedBuffer.id = cacheId;
Marissa Wall78b72202019-03-15 14:58:34 -0700654
655 // If we have more buffers than the size of the cache, we should stop caching so we don't
656 // evict other buffers in this transaction
657 count++;
658 if (count >= BUFFER_CACHE_MAX_SIZE) {
659 break;
660 }
661 }
Robert Carr6fb1a7e2018-12-11 12:07:25 -0800662}
663
Robert Carr4cdc58f2017-08-23 14:22:20 -0700664status_t SurfaceComposerClient::Transaction::apply(bool synchronous) {
665 if (mStatus != NO_ERROR) {
666 return mStatus;
667 }
668
669 sp<ISurfaceComposer> sf(ComposerService::getComposerService());
670
Valerie Hau9dab9732019-08-20 09:29:25 -0700671 bool hasListenerCallbacks = !mListenerCallbacks.empty();
Marissa Wall3dad52d2019-03-22 14:03:19 -0700672 std::vector<ListenerCallbacks> listenerCallbacks;
Marissa Wallc837b5e2018-10-12 10:04:44 -0700673 // For every listener with registered callbacks
674 for (const auto& [listener, callbackInfo] : mListenerCallbacks) {
675 auto& [callbackIds, surfaceControls] = callbackInfo;
676 if (callbackIds.empty()) {
677 continue;
678 }
679
Valerie Hau9dab9732019-08-20 09:29:25 -0700680 if (surfaceControls.empty()) {
681 listenerCallbacks.emplace_back(IInterface::asBinder(listener), std::move(callbackIds));
682 } else {
683 // If the listener has any SurfaceControls set on this Transaction update the surface
684 // state
685 for (const auto& surfaceControl : surfaceControls) {
686 layer_state_t* s = getLayerState(surfaceControl);
687 if (!s) {
688 ALOGE("failed to get layer state");
689 continue;
690 }
691 std::vector<CallbackId> callbacks(callbackIds.begin(), callbackIds.end());
692 s->what |= layer_state_t::eHasListenerCallbacksChanged;
693 s->listeners.emplace_back(IInterface::asBinder(listener), callbacks);
Marissa Wallc837b5e2018-10-12 10:04:44 -0700694 }
Marissa Wallc837b5e2018-10-12 10:04:44 -0700695 }
696 }
Valerie Hau9dab9732019-08-20 09:29:25 -0700697
Marissa Wallc837b5e2018-10-12 10:04:44 -0700698 mListenerCallbacks.clear();
699
Marissa Wall78b72202019-03-15 14:58:34 -0700700 cacheBuffers();
701
Robert Carr4cdc58f2017-08-23 14:22:20 -0700702 Vector<ComposerState> composerStates;
703 Vector<DisplayState> displayStates;
704 uint32_t flags = 0;
705
706 mForceSynchronous |= synchronous;
707
chaviw8e3fe5d2018-02-22 10:55:42 -0800708 for (auto const& kv : mComposerStates){
709 composerStates.add(kv.second);
710 }
711
Robert Carr4cdc58f2017-08-23 14:22:20 -0700712 mComposerStates.clear();
713
714 displayStates = mDisplayStates;
715 mDisplayStates.clear();
716
717 if (mForceSynchronous) {
718 flags |= ISurfaceComposer::eSynchronous;
719 }
720 if (mAnimation) {
721 flags |= ISurfaceComposer::eAnimation;
722 }
Dan Stoza84d619e2018-03-28 17:07:36 -0700723 if (mEarlyWakeup) {
724 flags |= ISurfaceComposer::eEarlyWakeup;
725 }
Robert Carr4cdc58f2017-08-23 14:22:20 -0700726
Ady Abrahambf1349c2020-06-12 14:26:18 -0700727 // If both mExplicitEarlyWakeupStart and mExplicitEarlyWakeupEnd are set
728 // it is equivalent for none
729 if (mExplicitEarlyWakeupStart && !mExplicitEarlyWakeupEnd) {
730 flags |= ISurfaceComposer::eExplicitEarlyWakeupStart;
731 }
732 if (mExplicitEarlyWakeupEnd && !mExplicitEarlyWakeupStart) {
733 flags |= ISurfaceComposer::eExplicitEarlyWakeupEnd;
734 }
735
Robert Carr4cdc58f2017-08-23 14:22:20 -0700736 mForceSynchronous = false;
737 mAnimation = false;
Dan Stoza84d619e2018-03-28 17:07:36 -0700738 mEarlyWakeup = false;
Ady Abrahambf1349c2020-06-12 14:26:18 -0700739 mExplicitEarlyWakeupStart = false;
740 mExplicitEarlyWakeupEnd = false;
Robert Carr4cdc58f2017-08-23 14:22:20 -0700741
Pablo Gamito7eb7ee72020-08-05 10:57:05 +0000742 uint64_t transactionId = mId;
743 mId = generateId();
744
Marissa Wall713b63f2018-10-17 15:42:43 -0700745 sp<IBinder> applyToken = IInterface::asBinder(TransactionCompletedListener::getIInstance());
Ady Abraham22c7b5c2020-09-22 19:33:40 -0700746 sf->setTransactionState(mFrameTimelineVsyncId, composerStates, displayStates, flags, applyToken,
747 mInputWindowCommands, mDesiredPresentTime,
Marissa Wall3dad52d2019-03-22 14:03:19 -0700748 {} /*uncacheBuffer - only set in doUncacheBufferTransaction*/,
Pablo Gamito7eb7ee72020-08-05 10:57:05 +0000749 hasListenerCallbacks, listenerCallbacks, transactionId);
chaviw273171b2018-12-26 11:46:30 -0800750 mInputWindowCommands.clear();
Robert Carr4cdc58f2017-08-23 14:22:20 -0700751 mStatus = NO_ERROR;
752 return NO_ERROR;
Mathias Agopiane57f2922012-08-09 16:29:12 -0700753}
754
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800755// ---------------------------------------------------------------------------
756
Robert Carr4cdc58f2017-08-23 14:22:20 -0700757sp<IBinder> SurfaceComposerClient::createDisplay(const String8& displayName, bool secure) {
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700758 return ComposerService::getComposerService()->createDisplay(displayName,
759 secure);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700760}
761
Robert Carr4cdc58f2017-08-23 14:22:20 -0700762void SurfaceComposerClient::destroyDisplay(const sp<IBinder>& display) {
Jesse Hall6c913be2013-08-08 12:15:49 -0700763 return ComposerService::getComposerService()->destroyDisplay(display);
764}
765
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -0800766std::vector<PhysicalDisplayId> SurfaceComposerClient::getPhysicalDisplayIds() {
767 return ComposerService::getComposerService()->getPhysicalDisplayIds();
768}
769
770std::optional<PhysicalDisplayId> SurfaceComposerClient::getInternalDisplayId() {
771 return ComposerService::getComposerService()->getInternalDisplayId();
772}
773
774sp<IBinder> SurfaceComposerClient::getPhysicalDisplayToken(PhysicalDisplayId displayId) {
775 return ComposerService::getComposerService()->getPhysicalDisplayToken(displayId);
776}
777
778sp<IBinder> SurfaceComposerClient::getInternalDisplayToken() {
779 return ComposerService::getComposerService()->getInternalDisplayToken();
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700780}
781
Robert Carr4cdc58f2017-08-23 14:22:20 -0700782void SurfaceComposerClient::Transaction::setAnimationTransaction() {
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700783 mAnimation = true;
784}
785
Dan Stoza84d619e2018-03-28 17:07:36 -0700786void SurfaceComposerClient::Transaction::setEarlyWakeup() {
787 mEarlyWakeup = true;
788}
789
Ady Abrahambf1349c2020-06-12 14:26:18 -0700790void SurfaceComposerClient::Transaction::setExplicitEarlyWakeupStart() {
791 mExplicitEarlyWakeupStart = true;
792}
793
794void SurfaceComposerClient::Transaction::setExplicitEarlyWakeupEnd() {
795 mExplicitEarlyWakeupEnd = true;
796}
797
Pablo Gamitodbc31672020-09-01 18:28:58 +0000798layer_state_t* SurfaceComposerClient::Transaction::getLayerState(const sp<SurfaceControl>& sc) {
799 auto handle = sc->getHandle();
800
Vishnu Nairf03652d2019-07-16 17:56:56 -0700801 if (mComposerStates.count(handle) == 0) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700802 // we don't have it, add an initialized layer_state to our list
chaviw8e3fe5d2018-02-22 10:55:42 -0800803 ComposerState s;
Pablo Gamitodbc31672020-09-01 18:28:58 +0000804
Vishnu Nairf03652d2019-07-16 17:56:56 -0700805 s.state.surface = handle;
Pablo Gamitodbc31672020-09-01 18:28:58 +0000806 s.state.layerId = sc->getLayerId();
807
Vishnu Nairf03652d2019-07-16 17:56:56 -0700808 mComposerStates[handle] = s;
Mathias Agopian698c0872011-06-28 19:09:31 -0700809 }
810
Vishnu Nairf03652d2019-07-16 17:56:56 -0700811 return &(mComposerStates[handle].state);
Mathias Agopian698c0872011-06-28 19:09:31 -0700812}
813
Marissa Wallc837b5e2018-10-12 10:04:44 -0700814void SurfaceComposerClient::Transaction::registerSurfaceControlForCallback(
815 const sp<SurfaceControl>& sc) {
Marissa Wall80d94ad2019-01-18 16:04:36 -0800816 auto& callbackInfo = mListenerCallbacks[TransactionCompletedListener::getIInstance()];
817 callbackInfo.surfaceControls.insert(sc);
818
819 TransactionCompletedListener::getInstance()
820 ->addSurfaceControlToCallbacks(sc, callbackInfo.callbackIds);
Marissa Wallc837b5e2018-10-12 10:04:44 -0700821}
822
Robert Carr4cdc58f2017-08-23 14:22:20 -0700823SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setPosition(
824 const sp<SurfaceControl>& sc, float x, float y) {
chaviw763ef572018-02-22 16:04:57 -0800825 layer_state_t* s = getLayerState(sc);
Robert Carr4cdc58f2017-08-23 14:22:20 -0700826 if (!s) {
827 mStatus = BAD_INDEX;
828 return *this;
829 }
Mathias Agopian3165cc22012-08-08 19:42:09 -0700830 s->what |= layer_state_t::ePositionChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700831 s->x = x;
832 s->y = y;
Marissa Wallc837b5e2018-10-12 10:04:44 -0700833
834 registerSurfaceControlForCallback(sc);
Robert Carr4cdc58f2017-08-23 14:22:20 -0700835 return *this;
Mathias Agopian698c0872011-06-28 19:09:31 -0700836}
837
Robert Carr4cdc58f2017-08-23 14:22:20 -0700838SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::show(
839 const sp<SurfaceControl>& sc) {
840 return setFlags(sc, 0, layer_state_t::eLayerHidden);
841}
842
843SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::hide(
844 const sp<SurfaceControl>& sc) {
845 return setFlags(sc, layer_state_t::eLayerHidden, layer_state_t::eLayerHidden);
846}
847
848SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setSize(
849 const sp<SurfaceControl>& sc, uint32_t w, uint32_t h) {
chaviw763ef572018-02-22 16:04:57 -0800850 layer_state_t* s = getLayerState(sc);
Robert Carr4cdc58f2017-08-23 14:22:20 -0700851 if (!s) {
852 mStatus = BAD_INDEX;
853 return *this;
854 }
Mathias Agopian3165cc22012-08-08 19:42:09 -0700855 s->what |= layer_state_t::eSizeChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700856 s->w = w;
857 s->h = h;
Jamie Gennis28378392011-10-12 17:39:00 -0700858
Marissa Wallc837b5e2018-10-12 10:04:44 -0700859 registerSurfaceControlForCallback(sc);
Robert Carr4cdc58f2017-08-23 14:22:20 -0700860 return *this;
Mathias Agopian698c0872011-06-28 19:09:31 -0700861}
862
Robert Carr4cdc58f2017-08-23 14:22:20 -0700863SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setLayer(
864 const sp<SurfaceControl>& sc, int32_t z) {
chaviw763ef572018-02-22 16:04:57 -0800865 layer_state_t* s = getLayerState(sc);
Robert Carr4cdc58f2017-08-23 14:22:20 -0700866 if (!s) {
867 mStatus = BAD_INDEX;
868 return *this;
869 }
Mathias Agopian3165cc22012-08-08 19:42:09 -0700870 s->what |= layer_state_t::eLayerChanged;
chaviw32377582019-05-13 11:15:19 -0700871 s->what &= ~layer_state_t::eRelativeLayerChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700872 s->z = z;
Marissa Wallc837b5e2018-10-12 10:04:44 -0700873
874 registerSurfaceControlForCallback(sc);
Robert Carr4cdc58f2017-08-23 14:22:20 -0700875 return *this;
Mathias Agopian698c0872011-06-28 19:09:31 -0700876}
877
Pablo Gamito11dcc222020-09-12 15:49:39 +0000878SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setRelativeLayer(
879 const sp<SurfaceControl>& sc, const sp<SurfaceControl>& relativeTo, int32_t z) {
chaviw763ef572018-02-22 16:04:57 -0800880 layer_state_t* s = getLayerState(sc);
Robert Carrdb66e622017-04-10 16:55:57 -0700881 if (!s) {
Robert Carr4cdc58f2017-08-23 14:22:20 -0700882 mStatus = BAD_INDEX;
Robert Carr30c8d902019-04-04 13:12:49 -0700883 return *this;
Robert Carrdb66e622017-04-10 16:55:57 -0700884 }
885 s->what |= layer_state_t::eRelativeLayerChanged;
chaviw32377582019-05-13 11:15:19 -0700886 s->what &= ~layer_state_t::eLayerChanged;
Pablo Gamito11dcc222020-09-12 15:49:39 +0000887 s->relativeLayerSurfaceControl = relativeTo;
Robert Carrdb66e622017-04-10 16:55:57 -0700888 s->z = z;
Marissa Wallc837b5e2018-10-12 10:04:44 -0700889
890 registerSurfaceControlForCallback(sc);
Robert Carr4cdc58f2017-08-23 14:22:20 -0700891 return *this;
Robert Carrdb66e622017-04-10 16:55:57 -0700892}
893
Robert Carr4cdc58f2017-08-23 14:22:20 -0700894SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setFlags(
895 const sp<SurfaceControl>& sc, uint32_t flags,
Mathias Agopian698c0872011-06-28 19:09:31 -0700896 uint32_t mask) {
chaviw763ef572018-02-22 16:04:57 -0800897 layer_state_t* s = getLayerState(sc);
Robert Carr4cdc58f2017-08-23 14:22:20 -0700898 if (!s) {
899 mStatus = BAD_INDEX;
900 return *this;
901 }
chaviwc5676c62020-09-18 15:01:04 -0700902 if ((mask & layer_state_t::eLayerOpaque) || (mask & layer_state_t::eLayerHidden) ||
903 (mask & layer_state_t::eLayerSecure) || (mask & layer_state_t::eLayerSkipScreenshot)) {
Dan Stoza23116082015-06-18 14:58:39 -0700904 s->what |= layer_state_t::eFlagsChanged;
Andy McFadden4125a4f2014-01-29 17:17:11 -0800905 }
Mathias Agopian698c0872011-06-28 19:09:31 -0700906 s->flags &= ~mask;
907 s->flags |= (flags & mask);
908 s->mask |= mask;
Marissa Wallc837b5e2018-10-12 10:04:44 -0700909
910 registerSurfaceControlForCallback(sc);
Robert Carr4cdc58f2017-08-23 14:22:20 -0700911 return *this;
Mathias Agopian698c0872011-06-28 19:09:31 -0700912}
913
Robert Carr4cdc58f2017-08-23 14:22:20 -0700914SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setTransparentRegionHint(
915 const sp<SurfaceControl>& sc,
Mathias Agopian698c0872011-06-28 19:09:31 -0700916 const Region& transparentRegion) {
chaviw763ef572018-02-22 16:04:57 -0800917 layer_state_t* s = getLayerState(sc);
Robert Carr4cdc58f2017-08-23 14:22:20 -0700918 if (!s) {
919 mStatus = BAD_INDEX;
920 return *this;
921 }
Mathias Agopian3165cc22012-08-08 19:42:09 -0700922 s->what |= layer_state_t::eTransparentRegionChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700923 s->transparentRegion = transparentRegion;
Marissa Wallc837b5e2018-10-12 10:04:44 -0700924
925 registerSurfaceControlForCallback(sc);
Robert Carr4cdc58f2017-08-23 14:22:20 -0700926 return *this;
Mathias Agopian698c0872011-06-28 19:09:31 -0700927}
928
Robert Carr4cdc58f2017-08-23 14:22:20 -0700929SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setAlpha(
930 const sp<SurfaceControl>& sc, float alpha) {
chaviw763ef572018-02-22 16:04:57 -0800931 layer_state_t* s = getLayerState(sc);
Robert Carr4cdc58f2017-08-23 14:22:20 -0700932 if (!s) {
933 mStatus = BAD_INDEX;
934 return *this;
935 }
Mathias Agopian3165cc22012-08-08 19:42:09 -0700936 s->what |= layer_state_t::eAlphaChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700937 s->alpha = alpha;
Marissa Wallc837b5e2018-10-12 10:04:44 -0700938
939 registerSurfaceControlForCallback(sc);
Robert Carr4cdc58f2017-08-23 14:22:20 -0700940 return *this;
Mathias Agopian698c0872011-06-28 19:09:31 -0700941}
942
Robert Carr4cdc58f2017-08-23 14:22:20 -0700943SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setLayerStack(
944 const sp<SurfaceControl>& sc, uint32_t layerStack) {
chaviw763ef572018-02-22 16:04:57 -0800945 layer_state_t* s = getLayerState(sc);
Robert Carr4cdc58f2017-08-23 14:22:20 -0700946 if (!s) {
947 mStatus = BAD_INDEX;
948 return *this;
949 }
Mathias Agopian3165cc22012-08-08 19:42:09 -0700950 s->what |= layer_state_t::eLayerStackChanged;
Mathias Agopian87855782012-07-24 21:41:09 -0700951 s->layerStack = layerStack;
Marissa Wallc837b5e2018-10-12 10:04:44 -0700952
953 registerSurfaceControlForCallback(sc);
Robert Carr4cdc58f2017-08-23 14:22:20 -0700954 return *this;
Mathias Agopian87855782012-07-24 21:41:09 -0700955}
956
Evan Rosky1f6d6d52018-12-06 10:47:26 -0800957SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setMetadata(
Garfield Tan01a56132019-08-05 16:44:21 -0700958 const sp<SurfaceControl>& sc, uint32_t key, const Parcel& p) {
Evan Rosky1f6d6d52018-12-06 10:47:26 -0800959 layer_state_t* s = getLayerState(sc);
960 if (!s) {
961 mStatus = BAD_INDEX;
962 return *this;
963 }
964 s->what |= layer_state_t::eMetadataChanged;
Garfield Tan01a56132019-08-05 16:44:21 -0700965
966 s->metadata.mMap[key] = {p.data(), p.data() + p.dataSize()};
Evan Rosky1f6d6d52018-12-06 10:47:26 -0800967
968 registerSurfaceControlForCallback(sc);
969 return *this;
970}
971
Robert Carr4cdc58f2017-08-23 14:22:20 -0700972SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setMatrix(
973 const sp<SurfaceControl>& sc, float dsdx, float dtdx,
Robert Carrcb6e1e32017-02-21 19:48:26 -0800974 float dtdy, float dsdy) {
chaviw763ef572018-02-22 16:04:57 -0800975 layer_state_t* s = getLayerState(sc);
Robert Carr4cdc58f2017-08-23 14:22:20 -0700976 if (!s) {
977 mStatus = BAD_INDEX;
978 return *this;
979 }
Mathias Agopian3165cc22012-08-08 19:42:09 -0700980 s->what |= layer_state_t::eMatrixChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700981 layer_state_t::matrix22_t matrix;
982 matrix.dsdx = dsdx;
983 matrix.dtdx = dtdx;
984 matrix.dsdy = dsdy;
985 matrix.dtdy = dtdy;
986 s->matrix = matrix;
Marissa Wallc837b5e2018-10-12 10:04:44 -0700987
988 registerSurfaceControlForCallback(sc);
Robert Carr4cdc58f2017-08-23 14:22:20 -0700989 return *this;
Mathias Agopian698c0872011-06-28 19:09:31 -0700990}
991
Marissa Wallf58c14b2018-07-24 10:50:43 -0700992SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setCrop_legacy(
Robert Carr4cdc58f2017-08-23 14:22:20 -0700993 const sp<SurfaceControl>& sc, const Rect& crop) {
chaviw763ef572018-02-22 16:04:57 -0800994 layer_state_t* s = getLayerState(sc);
Robert Carr4cdc58f2017-08-23 14:22:20 -0700995 if (!s) {
996 mStatus = BAD_INDEX;
997 return *this;
998 }
Marissa Wallf58c14b2018-07-24 10:50:43 -0700999 s->what |= layer_state_t::eCropChanged_legacy;
1000 s->crop_legacy = crop;
Marissa Wallc837b5e2018-10-12 10:04:44 -07001001
1002 registerSurfaceControlForCallback(sc);
Robert Carr4cdc58f2017-08-23 14:22:20 -07001003 return *this;
Jamie Gennisf15a83f2012-05-10 20:43:55 -07001004}
1005
Lucas Dupin1b6531c2018-07-05 17:18:21 -07001006SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setCornerRadius(
1007 const sp<SurfaceControl>& sc, float cornerRadius) {
1008 layer_state_t* s = getLayerState(sc);
1009 if (!s) {
1010 mStatus = BAD_INDEX;
1011 return *this;
1012 }
1013 s->what |= layer_state_t::eCornerRadiusChanged;
1014 s->cornerRadius = cornerRadius;
1015 return *this;
1016}
1017
Lucas Dupin19c8f0e2019-11-25 17:55:44 -08001018SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setBackgroundBlurRadius(
1019 const sp<SurfaceControl>& sc, int backgroundBlurRadius) {
1020 layer_state_t* s = getLayerState(sc);
1021 if (!s) {
1022 mStatus = BAD_INDEX;
1023 return *this;
1024 }
1025 s->what |= layer_state_t::eBackgroundBlurRadiusChanged;
1026 s->backgroundBlurRadius = backgroundBlurRadius;
1027 return *this;
1028}
1029
Marissa Wallf58c14b2018-07-24 10:50:43 -07001030SurfaceComposerClient::Transaction&
Pablo Gamito11dcc222020-09-12 15:49:39 +00001031SurfaceComposerClient::Transaction::deferTransactionUntil_legacy(
1032 const sp<SurfaceControl>& sc, const sp<SurfaceControl>& barrierSurfaceControl,
1033 uint64_t frameNumber) {
chaviw763ef572018-02-22 16:04:57 -08001034 layer_state_t* s = getLayerState(sc);
Dan Stoza7dde5992015-05-22 09:51:44 -07001035 if (!s) {
Robert Carr4cdc58f2017-08-23 14:22:20 -07001036 mStatus = BAD_INDEX;
1037 return *this;
Dan Stoza7dde5992015-05-22 09:51:44 -07001038 }
Marissa Wallf58c14b2018-07-24 10:50:43 -07001039 s->what |= layer_state_t::eDeferTransaction_legacy;
Pablo Gamito11dcc222020-09-12 15:49:39 +00001040 s->barrierSurfaceControl_legacy = barrierSurfaceControl;
Vishnu Nair6b7c5c92020-09-29 17:27:05 -07001041 s->barrierFrameNumber = frameNumber;
Marissa Wallc837b5e2018-10-12 10:04:44 -07001042
1043 registerSurfaceControlForCallback(sc);
Robert Carr4cdc58f2017-08-23 14:22:20 -07001044 return *this;
Robert Carr0d480722017-01-10 16:42:54 -08001045}
1046
Marissa Wallf58c14b2018-07-24 10:50:43 -07001047SurfaceComposerClient::Transaction&
1048SurfaceComposerClient::Transaction::deferTransactionUntil_legacy(const sp<SurfaceControl>& sc,
1049 const sp<Surface>& barrierSurface,
1050 uint64_t frameNumber) {
chaviw763ef572018-02-22 16:04:57 -08001051 layer_state_t* s = getLayerState(sc);
Robert Carr0d480722017-01-10 16:42:54 -08001052 if (!s) {
Robert Carr4cdc58f2017-08-23 14:22:20 -07001053 mStatus = BAD_INDEX;
1054 return *this;
Robert Carr0d480722017-01-10 16:42:54 -08001055 }
Marissa Wallf58c14b2018-07-24 10:50:43 -07001056 s->what |= layer_state_t::eDeferTransaction_legacy;
1057 s->barrierGbp_legacy = barrierSurface->getIGraphicBufferProducer();
Vishnu Nair6b7c5c92020-09-29 17:27:05 -07001058 s->barrierFrameNumber = frameNumber;
Marissa Wallc837b5e2018-10-12 10:04:44 -07001059
1060 registerSurfaceControlForCallback(sc);
Robert Carr4cdc58f2017-08-23 14:22:20 -07001061 return *this;
Dan Stoza7dde5992015-05-22 09:51:44 -07001062}
1063
Robert Carr4cdc58f2017-08-23 14:22:20 -07001064SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::reparentChildren(
Pablo Gamito11dcc222020-09-12 15:49:39 +00001065 const sp<SurfaceControl>& sc, const sp<SurfaceControl>& newParent) {
chaviw763ef572018-02-22 16:04:57 -08001066 layer_state_t* s = getLayerState(sc);
Robert Carr1db73f62016-12-21 12:58:51 -08001067 if (!s) {
Robert Carr4cdc58f2017-08-23 14:22:20 -07001068 mStatus = BAD_INDEX;
1069 return *this;
Robert Carr1db73f62016-12-21 12:58:51 -08001070 }
1071 s->what |= layer_state_t::eReparentChildren;
Pablo Gamito11dcc222020-09-12 15:49:39 +00001072 s->reparentSurfaceControl = newParent;
Marissa Wallc837b5e2018-10-12 10:04:44 -07001073
1074 registerSurfaceControlForCallback(sc);
Robert Carr4cdc58f2017-08-23 14:22:20 -07001075 return *this;
Robert Carr1db73f62016-12-21 12:58:51 -08001076}
1077
Robert Carr4cdc58f2017-08-23 14:22:20 -07001078SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::reparent(
Pablo Gamito11dcc222020-09-12 15:49:39 +00001079 const sp<SurfaceControl>& sc, const sp<SurfaceControl>& newParent) {
chaviw763ef572018-02-22 16:04:57 -08001080 layer_state_t* s = getLayerState(sc);
chaviw06178942017-07-27 10:25:59 -07001081 if (!s) {
Robert Carr4cdc58f2017-08-23 14:22:20 -07001082 mStatus = BAD_INDEX;
1083 return *this;
chaviw06178942017-07-27 10:25:59 -07001084 }
chaviwf1961f72017-09-18 16:41:07 -07001085 s->what |= layer_state_t::eReparent;
Pablo Gamito11dcc222020-09-12 15:49:39 +00001086 s->parentSurfaceControlForChild = newParent;
Marissa Wallc837b5e2018-10-12 10:04:44 -07001087
1088 registerSurfaceControlForCallback(sc);
Robert Carr4cdc58f2017-08-23 14:22:20 -07001089 return *this;
chaviw06178942017-07-27 10:25:59 -07001090}
1091
Robert Carr4cdc58f2017-08-23 14:22:20 -07001092SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setColor(
1093 const sp<SurfaceControl>& sc,
1094 const half3& color) {
chaviw763ef572018-02-22 16:04:57 -08001095 layer_state_t* s = getLayerState(sc);
Robert Carr9524cb32017-02-13 11:32:32 -08001096 if (!s) {
Robert Carr4cdc58f2017-08-23 14:22:20 -07001097 mStatus = BAD_INDEX;
1098 return *this;
1099 }
1100 s->what |= layer_state_t::eColorChanged;
1101 s->color = color;
Marissa Wallc837b5e2018-10-12 10:04:44 -07001102
1103 registerSurfaceControlForCallback(sc);
Robert Carr4cdc58f2017-08-23 14:22:20 -07001104 return *this;
1105}
1106
Valerie Haudd0b7572019-01-29 14:59:27 -08001107SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setBackgroundColor(
1108 const sp<SurfaceControl>& sc, const half3& color, float alpha, ui::Dataspace dataspace) {
Valerie Haued54efa2019-01-11 20:03:14 -08001109 layer_state_t* s = getLayerState(sc);
1110 if (!s) {
1111 mStatus = BAD_INDEX;
1112 return *this;
1113 }
1114
Valerie Haudd0b7572019-01-29 14:59:27 -08001115 s->what |= layer_state_t::eBackgroundColorChanged;
1116 s->color = color;
1117 s->bgColorAlpha = alpha;
1118 s->bgColorDataspace = dataspace;
Valerie Haued54efa2019-01-11 20:03:14 -08001119
1120 registerSurfaceControlForCallback(sc);
1121 return *this;
1122}
1123
Marissa Wall61c58622018-07-18 10:12:20 -07001124SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setTransform(
1125 const sp<SurfaceControl>& sc, uint32_t transform) {
1126 layer_state_t* s = getLayerState(sc);
1127 if (!s) {
1128 mStatus = BAD_INDEX;
1129 return *this;
1130 }
1131 s->what |= layer_state_t::eTransformChanged;
1132 s->transform = transform;
Marissa Wallc837b5e2018-10-12 10:04:44 -07001133
1134 registerSurfaceControlForCallback(sc);
Marissa Wall61c58622018-07-18 10:12:20 -07001135 return *this;
1136}
1137
1138SurfaceComposerClient::Transaction&
1139SurfaceComposerClient::Transaction::setTransformToDisplayInverse(const sp<SurfaceControl>& sc,
1140 bool transformToDisplayInverse) {
1141 layer_state_t* s = getLayerState(sc);
1142 if (!s) {
1143 mStatus = BAD_INDEX;
1144 return *this;
1145 }
1146 s->what |= layer_state_t::eTransformToDisplayInverseChanged;
1147 s->transformToDisplayInverse = transformToDisplayInverse;
Marissa Wallc837b5e2018-10-12 10:04:44 -07001148
1149 registerSurfaceControlForCallback(sc);
Marissa Wall61c58622018-07-18 10:12:20 -07001150 return *this;
1151}
1152
1153SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setCrop(
1154 const sp<SurfaceControl>& sc, const Rect& crop) {
1155 layer_state_t* s = getLayerState(sc);
1156 if (!s) {
1157 mStatus = BAD_INDEX;
1158 return *this;
1159 }
1160 s->what |= layer_state_t::eCropChanged;
1161 s->crop = crop;
Marissa Wallc837b5e2018-10-12 10:04:44 -07001162
1163 registerSurfaceControlForCallback(sc);
Marissa Wall61c58622018-07-18 10:12:20 -07001164 return *this;
1165}
1166
Marissa Wall861616d2018-10-22 12:52:23 -07001167SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setFrame(
1168 const sp<SurfaceControl>& sc, const Rect& frame) {
1169 layer_state_t* s = getLayerState(sc);
1170 if (!s) {
1171 mStatus = BAD_INDEX;
1172 return *this;
1173 }
1174 s->what |= layer_state_t::eFrameChanged;
Marin Shalamanov6ad317c2020-07-29 23:34:07 +02001175 s->orientedDisplaySpaceRect = frame;
Marissa Wall861616d2018-10-22 12:52:23 -07001176
1177 registerSurfaceControlForCallback(sc);
1178 return *this;
1179}
1180
Marissa Wall61c58622018-07-18 10:12:20 -07001181SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setBuffer(
1182 const sp<SurfaceControl>& sc, const sp<GraphicBuffer>& buffer) {
1183 layer_state_t* s = getLayerState(sc);
1184 if (!s) {
1185 mStatus = BAD_INDEX;
1186 return *this;
1187 }
Marissa Wall78b72202019-03-15 14:58:34 -07001188 s->what |= layer_state_t::eBufferChanged;
1189 s->buffer = buffer;
Marissa Wallebc2c052019-01-16 19:16:55 -08001190
1191 registerSurfaceControlForCallback(sc);
Marissa Wall78b72202019-03-15 14:58:34 -07001192
1193 mContainsBuffer = true;
Marissa Wallebc2c052019-01-16 19:16:55 -08001194 return *this;
1195}
1196
Marissa Wall61c58622018-07-18 10:12:20 -07001197SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setAcquireFence(
1198 const sp<SurfaceControl>& sc, const sp<Fence>& fence) {
1199 layer_state_t* s = getLayerState(sc);
1200 if (!s) {
1201 mStatus = BAD_INDEX;
1202 return *this;
1203 }
1204 s->what |= layer_state_t::eAcquireFenceChanged;
1205 s->acquireFence = fence;
Marissa Wallc837b5e2018-10-12 10:04:44 -07001206
1207 registerSurfaceControlForCallback(sc);
Marissa Wall61c58622018-07-18 10:12:20 -07001208 return *this;
1209}
1210
1211SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setDataspace(
1212 const sp<SurfaceControl>& sc, ui::Dataspace dataspace) {
1213 layer_state_t* s = getLayerState(sc);
1214 if (!s) {
1215 mStatus = BAD_INDEX;
1216 return *this;
1217 }
1218 s->what |= layer_state_t::eDataspaceChanged;
1219 s->dataspace = dataspace;
Marissa Wallc837b5e2018-10-12 10:04:44 -07001220
1221 registerSurfaceControlForCallback(sc);
Marissa Wall61c58622018-07-18 10:12:20 -07001222 return *this;
1223}
1224
1225SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setHdrMetadata(
1226 const sp<SurfaceControl>& sc, const HdrMetadata& hdrMetadata) {
1227 layer_state_t* s = getLayerState(sc);
1228 if (!s) {
1229 mStatus = BAD_INDEX;
1230 return *this;
1231 }
1232 s->what |= layer_state_t::eHdrMetadataChanged;
1233 s->hdrMetadata = hdrMetadata;
Marissa Wallc837b5e2018-10-12 10:04:44 -07001234
1235 registerSurfaceControlForCallback(sc);
Marissa Wall61c58622018-07-18 10:12:20 -07001236 return *this;
1237}
1238
1239SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setSurfaceDamageRegion(
1240 const sp<SurfaceControl>& sc, const Region& surfaceDamageRegion) {
1241 layer_state_t* s = getLayerState(sc);
1242 if (!s) {
1243 mStatus = BAD_INDEX;
1244 return *this;
1245 }
1246 s->what |= layer_state_t::eSurfaceDamageRegionChanged;
1247 s->surfaceDamageRegion = surfaceDamageRegion;
Marissa Wallc837b5e2018-10-12 10:04:44 -07001248
1249 registerSurfaceControlForCallback(sc);
Marissa Wall61c58622018-07-18 10:12:20 -07001250 return *this;
1251}
1252
1253SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setApi(
1254 const sp<SurfaceControl>& sc, int32_t api) {
1255 layer_state_t* s = getLayerState(sc);
1256 if (!s) {
1257 mStatus = BAD_INDEX;
1258 return *this;
1259 }
1260 s->what |= layer_state_t::eApiChanged;
1261 s->api = api;
Marissa Wallc837b5e2018-10-12 10:04:44 -07001262
1263 registerSurfaceControlForCallback(sc);
Marissa Wall61c58622018-07-18 10:12:20 -07001264 return *this;
1265}
1266
1267SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setSidebandStream(
1268 const sp<SurfaceControl>& sc, const sp<NativeHandle>& sidebandStream) {
1269 layer_state_t* s = getLayerState(sc);
1270 if (!s) {
1271 mStatus = BAD_INDEX;
1272 return *this;
1273 }
1274 s->what |= layer_state_t::eSidebandStreamChanged;
1275 s->sidebandStream = sidebandStream;
Marissa Wallc837b5e2018-10-12 10:04:44 -07001276
1277 registerSurfaceControlForCallback(sc);
1278 return *this;
1279}
1280
Marissa Wall17b4e452018-12-26 16:32:34 -08001281SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setDesiredPresentTime(
1282 nsecs_t desiredPresentTime) {
1283 mDesiredPresentTime = desiredPresentTime;
1284 return *this;
1285}
1286
Peiyong Linc502cb72019-03-01 15:00:23 -08001287SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setColorSpaceAgnostic(
1288 const sp<SurfaceControl>& sc, const bool agnostic) {
1289 layer_state_t* s = getLayerState(sc);
1290 if (!s) {
1291 mStatus = BAD_INDEX;
1292 return *this;
1293 }
1294 s->what |= layer_state_t::eColorSpaceAgnosticChanged;
1295 s->colorSpaceAgnostic = agnostic;
1296
1297 registerSurfaceControlForCallback(sc);
1298 return *this;
1299}
1300
Marissa Wallc837b5e2018-10-12 10:04:44 -07001301SurfaceComposerClient::Transaction&
Ana Krulecc84d09b2019-11-02 23:10:29 +01001302SurfaceComposerClient::Transaction::setFrameRateSelectionPriority(const sp<SurfaceControl>& sc,
1303 int32_t priority) {
1304 layer_state_t* s = getLayerState(sc);
1305 if (!s) {
1306 mStatus = BAD_INDEX;
1307 return *this;
1308 }
1309
1310 s->what |= layer_state_t::eFrameRateSelectionPriority;
1311 s->frameRateSelectionPriority = priority;
1312
1313 registerSurfaceControlForCallback(sc);
1314 return *this;
1315}
1316
1317SurfaceComposerClient::Transaction&
Marissa Wallc837b5e2018-10-12 10:04:44 -07001318SurfaceComposerClient::Transaction::addTransactionCompletedCallback(
Marissa Walle2ffb422018-10-12 11:33:52 -07001319 TransactionCompletedCallbackTakesContext callback, void* callbackContext) {
Marissa Wallc837b5e2018-10-12 10:04:44 -07001320 auto listener = TransactionCompletedListener::getInstance();
1321
Marissa Wall80d94ad2019-01-18 16:04:36 -08001322 auto callbackWithContext = std::bind(callback, callbackContext, std::placeholders::_1,
1323 std::placeholders::_2, std::placeholders::_3);
1324 const auto& surfaceControls =
1325 mListenerCallbacks[TransactionCompletedListener::getIInstance()].surfaceControls;
Marissa Wallc837b5e2018-10-12 10:04:44 -07001326
Marissa Wall80d94ad2019-01-18 16:04:36 -08001327 CallbackId callbackId = listener->addCallbackFunction(callbackWithContext, surfaceControls);
Marissa Wallc837b5e2018-10-12 10:04:44 -07001328
1329 mListenerCallbacks[TransactionCompletedListener::getIInstance()].callbackIds.emplace(
1330 callbackId);
Marissa Wall61c58622018-07-18 10:12:20 -07001331 return *this;
1332}
1333
Valerie Hau871d6352020-01-29 08:44:02 -08001334SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::notifyProducerDisconnect(
1335 const sp<SurfaceControl>& sc) {
1336 layer_state_t* s = getLayerState(sc);
1337 if (!s) {
1338 mStatus = BAD_INDEX;
1339 return *this;
1340 }
1341
1342 s->what |= layer_state_t::eProducerDisconnect;
1343 return *this;
1344}
1345
Vishnu Nair6b7c5c92020-09-29 17:27:05 -07001346SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setFrameNumber(
1347 const sp<SurfaceControl>& sc, uint64_t frameNumber) {
1348 layer_state_t* s = getLayerState(sc);
1349 if (!s) {
1350 mStatus = BAD_INDEX;
1351 return *this;
1352 }
1353
1354 s->what |= layer_state_t::eFrameNumberChanged;
1355 s->frameNumber = frameNumber;
1356
1357 return *this;
1358}
1359
Robert Carr4cdc58f2017-08-23 14:22:20 -07001360SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::detachChildren(
1361 const sp<SurfaceControl>& sc) {
chaviw763ef572018-02-22 16:04:57 -08001362 layer_state_t* s = getLayerState(sc);
Robert Carr4cdc58f2017-08-23 14:22:20 -07001363 if (!s) {
1364 mStatus = BAD_INDEX;
Greg Kaiserd45fdc32019-04-30 06:14:19 -07001365 return *this;
Robert Carr9524cb32017-02-13 11:32:32 -08001366 }
1367 s->what |= layer_state_t::eDetachChildren;
Marissa Wallc837b5e2018-10-12 10:04:44 -07001368
1369 registerSurfaceControlForCallback(sc);
Robert Carr4cdc58f2017-08-23 14:22:20 -07001370 return *this;
Robert Carr9524cb32017-02-13 11:32:32 -08001371}
1372
Robert Carr4cdc58f2017-08-23 14:22:20 -07001373SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setOverrideScalingMode(
1374 const sp<SurfaceControl>& sc, int32_t overrideScalingMode) {
chaviw763ef572018-02-22 16:04:57 -08001375 layer_state_t* s = getLayerState(sc);
Robert Carrc3574f72016-03-24 12:19:32 -07001376 if (!s) {
Robert Carr4cdc58f2017-08-23 14:22:20 -07001377 mStatus = BAD_INDEX;
1378 return *this;
Robert Carrc3574f72016-03-24 12:19:32 -07001379 }
1380
1381 switch (overrideScalingMode) {
1382 case NATIVE_WINDOW_SCALING_MODE_FREEZE:
1383 case NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW:
1384 case NATIVE_WINDOW_SCALING_MODE_SCALE_CROP:
1385 case NATIVE_WINDOW_SCALING_MODE_NO_SCALE_CROP:
1386 case -1:
1387 break;
1388 default:
1389 ALOGE("unknown scaling mode: %d",
1390 overrideScalingMode);
Robert Carr4cdc58f2017-08-23 14:22:20 -07001391 mStatus = BAD_VALUE;
1392 return *this;
Robert Carrc3574f72016-03-24 12:19:32 -07001393 }
1394
1395 s->what |= layer_state_t::eOverrideScalingModeChanged;
1396 s->overrideScalingMode = overrideScalingMode;
Marissa Wallc837b5e2018-10-12 10:04:44 -07001397
1398 registerSurfaceControlForCallback(sc);
Robert Carr4cdc58f2017-08-23 14:22:20 -07001399 return *this;
Robert Carrc3574f72016-03-24 12:19:32 -07001400}
1401
Robert Carr2c358bf2018-08-08 15:58:15 -07001402#ifndef NO_INPUT
1403SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setInputWindowInfo(
1404 const sp<SurfaceControl>& sc,
1405 const InputWindowInfo& info) {
1406 layer_state_t* s = getLayerState(sc);
1407 if (!s) {
1408 mStatus = BAD_INDEX;
1409 return *this;
1410 }
Chris Ye0783e992020-06-02 21:34:49 -07001411 s->inputHandle = new InputWindowHandle(info);
Robert Carr2c358bf2018-08-08 15:58:15 -07001412 s->what |= layer_state_t::eInputInfoChanged;
1413 return *this;
1414}
chaviw273171b2018-12-26 11:46:30 -08001415
Vishnu Naire798b472020-07-23 13:52:21 -07001416SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setFocusedWindow(
Vishnu Nair958da932020-08-21 17:12:37 -07001417 const sp<IBinder>& token, const sp<IBinder>& focusedToken, nsecs_t timestampNanos,
1418 int32_t displayId) {
Vishnu Naire798b472020-07-23 13:52:21 -07001419 FocusRequest request;
1420 request.token = token;
1421 request.focusedToken = focusedToken;
1422 request.timestamp = timestampNanos;
Vishnu Nair958da932020-08-21 17:12:37 -07001423 request.displayId = displayId;
Vishnu Naire798b472020-07-23 13:52:21 -07001424 return setFocusedWindow(request);
1425}
1426
1427SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setFocusedWindow(
1428 const FocusRequest& request) {
1429 mInputWindowCommands.focusRequests.push_back(request);
1430 return *this;
1431}
1432
chaviwa911b102019-02-14 10:18:33 -08001433SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::syncInputWindows() {
1434 mInputWindowCommands.syncInputWindows = true;
1435 return *this;
1436}
1437
Robert Carr2c358bf2018-08-08 15:58:15 -07001438#endif
1439
Peiyong Lind3788632018-09-18 16:01:31 -07001440SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setColorTransform(
1441 const sp<SurfaceControl>& sc, const mat3& matrix, const vec3& translation) {
1442 layer_state_t* s = getLayerState(sc);
1443 if (!s) {
1444 mStatus = BAD_INDEX;
1445 return *this;
1446 }
1447 s->what |= layer_state_t::eColorTransformChanged;
1448 s->colorTransform = mat4(matrix, translation);
Marissa Wallc837b5e2018-10-12 10:04:44 -07001449
1450 registerSurfaceControlForCallback(sc);
Peiyong Lind3788632018-09-18 16:01:31 -07001451 return *this;
1452}
1453
Robert Carrfb4d58b2019-01-15 09:21:27 -08001454SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setGeometry(
1455 const sp<SurfaceControl>& sc, const Rect& source, const Rect& dst, int transform) {
1456 setCrop_legacy(sc, source);
1457
1458 int x = dst.left;
1459 int y = dst.top;
Robert Carr66365e42019-04-08 16:58:04 -07001460
1461 float sourceWidth = source.getWidth();
1462 float sourceHeight = source.getHeight();
1463
1464 float xScale = sourceWidth < 0 ? 1.0f : dst.getWidth() / sourceWidth;
1465 float yScale = sourceHeight < 0 ? 1.0f : dst.getHeight() / sourceHeight;
Robert Carrfb4d58b2019-01-15 09:21:27 -08001466 float matrix[4] = {1, 0, 0, 1};
1467
1468 switch (transform) {
1469 case NATIVE_WINDOW_TRANSFORM_FLIP_H:
1470 matrix[0] = -xScale; matrix[1] = 0;
1471 matrix[2] = 0; matrix[3] = yScale;
1472 x += source.getWidth();
1473 break;
1474 case NATIVE_WINDOW_TRANSFORM_FLIP_V:
1475 matrix[0] = xScale; matrix[1] = 0;
1476 matrix[2] = 0; matrix[3] = -yScale;
1477 y += source.getHeight();
1478 break;
1479 case NATIVE_WINDOW_TRANSFORM_ROT_90:
1480 matrix[0] = 0; matrix[1] = -yScale;
1481 matrix[2] = xScale; matrix[3] = 0;
1482 x += source.getHeight();
1483 break;
1484 case NATIVE_WINDOW_TRANSFORM_ROT_180:
1485 matrix[0] = -xScale; matrix[1] = 0;
1486 matrix[2] = 0; matrix[3] = -yScale;
1487 x += source.getWidth();
1488 y += source.getHeight();
1489 break;
1490 case NATIVE_WINDOW_TRANSFORM_ROT_270:
1491 matrix[0] = 0; matrix[1] = yScale;
1492 matrix[2] = -xScale; matrix[3] = 0;
1493 y += source.getWidth();
1494 break;
1495 default:
1496 matrix[0] = xScale; matrix[1] = 0;
1497 matrix[2] = 0; matrix[3] = yScale;
1498 break;
1499 }
1500 setMatrix(sc, matrix[0], matrix[1], matrix[2], matrix[3]);
chaviw76f5f2f2019-09-23 10:15:51 -07001501 float offsetX = xScale * source.left;
1502 float offsetY = yScale * source.top;
1503 setPosition(sc, x - offsetX, y - offsetY);
Robert Carrfb4d58b2019-01-15 09:21:27 -08001504
1505 return *this;
1506}
1507
Vishnu Nairc97b8db2019-10-29 18:19:35 -07001508SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setShadowRadius(
1509 const sp<SurfaceControl>& sc, float shadowRadius) {
1510 layer_state_t* s = getLayerState(sc);
1511 if (!s) {
1512 mStatus = BAD_INDEX;
1513 return *this;
1514 }
1515 s->what |= layer_state_t::eShadowRadiusChanged;
1516 s->shadowRadius = shadowRadius;
1517 return *this;
1518}
1519
Steven Thomas3172e202020-01-06 19:25:30 -08001520SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setFrameRate(
Steven Thomas62a4cf82020-01-31 12:04:03 -08001521 const sp<SurfaceControl>& sc, float frameRate, int8_t compatibility) {
Steven Thomas3172e202020-01-06 19:25:30 -08001522 layer_state_t* s = getLayerState(sc);
1523 if (!s) {
1524 mStatus = BAD_INDEX;
1525 return *this;
1526 }
Steven Thomas62a4cf82020-01-31 12:04:03 -08001527 if (!ValidateFrameRate(frameRate, compatibility, "Transaction::setFrameRate")) {
1528 mStatus = BAD_VALUE;
1529 return *this;
1530 }
Steven Thomas3172e202020-01-06 19:25:30 -08001531 s->what |= layer_state_t::eFrameRateChanged;
1532 s->frameRate = frameRate;
Steven Thomas62a4cf82020-01-31 12:04:03 -08001533 s->frameRateCompatibility = compatibility;
Steven Thomas3172e202020-01-06 19:25:30 -08001534 return *this;
1535}
1536
Vishnu Nair6213bd92020-05-08 17:42:25 -07001537SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setFixedTransformHint(
1538 const sp<SurfaceControl>& sc, int32_t fixedTransformHint) {
1539 layer_state_t* s = getLayerState(sc);
1540 if (!s) {
1541 mStatus = BAD_INDEX;
1542 return *this;
1543 }
1544
1545 const ui::Transform::RotationFlags transform = fixedTransformHint == -1
1546 ? ui::Transform::ROT_INVALID
1547 : ui::Transform::toRotationFlags(static_cast<ui::Rotation>(fixedTransformHint));
1548 s->what |= layer_state_t::eFixedTransformHintChanged;
1549 s->fixedTransformHint = transform;
1550 return *this;
1551}
1552
Ady Abraham22c7b5c2020-09-22 19:33:40 -07001553SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setFrameTimelineVsync(
1554 int64_t frameTimelineVsyncId) {
1555 mFrameTimelineVsyncId = frameTimelineVsyncId;
1556 return *this;
1557}
1558
Mathias Agopian698c0872011-06-28 19:09:31 -07001559// ---------------------------------------------------------------------------
1560
chaviw763ef572018-02-22 16:04:57 -08001561DisplayState& SurfaceComposerClient::Transaction::getDisplayState(const sp<IBinder>& token) {
Mathias Agopiane57f2922012-08-09 16:29:12 -07001562 DisplayState s;
1563 s.token = token;
1564 ssize_t index = mDisplayStates.indexOf(s);
1565 if (index < 0) {
1566 // we don't have it, add an initialized layer_state to our list
1567 s.what = 0;
1568 index = mDisplayStates.add(s);
1569 }
Dan Stozad723bd72014-11-18 10:24:03 -08001570 return mDisplayStates.editItemAt(static_cast<size_t>(index));
Mathias Agopiane57f2922012-08-09 16:29:12 -07001571}
1572
Robert Carr4cdc58f2017-08-23 14:22:20 -07001573status_t SurfaceComposerClient::Transaction::setDisplaySurface(const sp<IBinder>& token,
1574 const sp<IGraphicBufferProducer>& bufferProducer) {
Pablo Ceballoseddbef82016-09-01 11:21:21 -07001575 if (bufferProducer.get() != nullptr) {
1576 // Make sure that composition can never be stalled by a virtual display
1577 // consumer that isn't processing buffers fast enough.
1578 status_t err = bufferProducer->setAsyncMode(true);
1579 if (err != NO_ERROR) {
1580 ALOGE("Composer::setDisplaySurface Failed to enable async mode on the "
1581 "BufferQueue. This BufferQueue cannot be used for virtual "
1582 "display. (%d)", err);
1583 return err;
1584 }
Pablo Ceballos1aad24c2016-08-04 10:24:22 -07001585 }
chaviw763ef572018-02-22 16:04:57 -08001586 DisplayState& s(getDisplayState(token));
Andy McFadden2adaf042012-12-18 09:49:45 -08001587 s.surface = bufferProducer;
Mathias Agopiane57f2922012-08-09 16:29:12 -07001588 s.what |= DisplayState::eSurfaceChanged;
Pablo Ceballos1aad24c2016-08-04 10:24:22 -07001589 return NO_ERROR;
Mathias Agopiane57f2922012-08-09 16:29:12 -07001590}
1591
Robert Carr4cdc58f2017-08-23 14:22:20 -07001592void SurfaceComposerClient::Transaction::setDisplayLayerStack(const sp<IBinder>& token,
Mathias Agopiane57f2922012-08-09 16:29:12 -07001593 uint32_t layerStack) {
chaviw763ef572018-02-22 16:04:57 -08001594 DisplayState& s(getDisplayState(token));
Mathias Agopiane57f2922012-08-09 16:29:12 -07001595 s.layerStack = layerStack;
1596 s.what |= DisplayState::eLayerStackChanged;
1597}
1598
Robert Carr4cdc58f2017-08-23 14:22:20 -07001599void SurfaceComposerClient::Transaction::setDisplayProjection(const sp<IBinder>& token,
Dominik Laskowski718f9602019-11-09 20:01:35 -08001600 ui::Rotation orientation,
1601 const Rect& layerStackRect,
1602 const Rect& displayRect) {
chaviw763ef572018-02-22 16:04:57 -08001603 DisplayState& s(getDisplayState(token));
Mathias Agopiane57f2922012-08-09 16:29:12 -07001604 s.orientation = orientation;
Marin Shalamanov6ad317c2020-07-29 23:34:07 +02001605 s.layerStackSpaceRect = layerStackRect;
1606 s.orientedDisplaySpaceRect = displayRect;
Mathias Agopian00e8c7a2012-09-04 19:30:46 -07001607 s.what |= DisplayState::eDisplayProjectionChanged;
Jorim Jaggi092123c2016-04-13 01:40:35 +00001608 mForceSynchronous = true; // TODO: do we actually still need this?
Mathias Agopiane57f2922012-08-09 16:29:12 -07001609}
1610
Robert Carr4cdc58f2017-08-23 14:22:20 -07001611void SurfaceComposerClient::Transaction::setDisplaySize(const sp<IBinder>& token, uint32_t width, uint32_t height) {
chaviw763ef572018-02-22 16:04:57 -08001612 DisplayState& s(getDisplayState(token));
Michael Wright1f6078a2014-06-26 16:01:02 -07001613 s.width = width;
1614 s.height = height;
1615 s.what |= DisplayState::eDisplaySizeChanged;
1616}
1617
Mathias Agopiane57f2922012-08-09 16:29:12 -07001618// ---------------------------------------------------------------------------
1619
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001620SurfaceComposerClient::SurfaceComposerClient()
Robert Carr4cdc58f2017-08-23 14:22:20 -07001621 : mStatus(NO_INIT)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001622{
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001623}
1624
Jorim Jaggif3cf4bc2017-11-30 14:19:23 +01001625SurfaceComposerClient::SurfaceComposerClient(const sp<ISurfaceComposerClient>& client)
1626 : mStatus(NO_ERROR), mClient(client)
1627{
1628}
1629
Mathias Agopian698c0872011-06-28 19:09:31 -07001630void SurfaceComposerClient::onFirstRef() {
Robert Carr4cdc58f2017-08-23 14:22:20 -07001631 sp<ISurfaceComposer> sf(ComposerService::getComposerService());
Yi Kong48a619f2018-06-05 16:34:59 -07001632 if (sf != nullptr && mStatus == NO_INIT) {
Robert Carr1db73f62016-12-21 12:58:51 -08001633 sp<ISurfaceComposerClient> conn;
Robert Carrb89ea9d2018-12-10 13:01:14 -08001634 conn = sf->createConnection();
Yi Kong48a619f2018-06-05 16:34:59 -07001635 if (conn != nullptr) {
Mathias Agopiand4784a32010-05-27 19:41:15 -07001636 mClient = conn;
Mathias Agopiand4784a32010-05-27 19:41:15 -07001637 mStatus = NO_ERROR;
1638 }
1639 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001640}
1641
Mathias Agopian698c0872011-06-28 19:09:31 -07001642SurfaceComposerClient::~SurfaceComposerClient() {
Mathias Agopian631f3582010-05-25 17:51:34 -07001643 dispose();
1644}
Mathias Agopiandd3423c2009-09-23 15:44:05 -07001645
Mathias Agopian698c0872011-06-28 19:09:31 -07001646status_t SurfaceComposerClient::initCheck() const {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001647 return mStatus;
1648}
1649
Mathias Agopian698c0872011-06-28 19:09:31 -07001650sp<IBinder> SurfaceComposerClient::connection() const {
Marco Nelissen2ea926b2014-11-14 08:01:01 -08001651 return IInterface::asBinder(mClient);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001652}
1653
Mathias Agopiand4784a32010-05-27 19:41:15 -07001654status_t SurfaceComposerClient::linkToComposerDeath(
1655 const sp<IBinder::DeathRecipient>& recipient,
Mathias Agopian698c0872011-06-28 19:09:31 -07001656 void* cookie, uint32_t flags) {
Robert Carr4cdc58f2017-08-23 14:22:20 -07001657 sp<ISurfaceComposer> sf(ComposerService::getComposerService());
1658 return IInterface::asBinder(sf)->linkToDeath(recipient, cookie, flags);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001659}
1660
Mathias Agopian698c0872011-06-28 19:09:31 -07001661void SurfaceComposerClient::dispose() {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001662 // this can be called more than once.
Mathias Agopian7e27f052010-05-28 14:22:23 -07001663 sp<ISurfaceComposerClient> client;
Mathias Agopiand4784a32010-05-27 19:41:15 -07001664 Mutex::Autolock _lm(mLock);
Yi Kong48a619f2018-06-05 16:34:59 -07001665 if (mClient != nullptr) {
Mathias Agopiand4784a32010-05-27 19:41:15 -07001666 client = mClient; // hold ref while lock is held
1667 mClient.clear();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001668 }
Mathias Agopiand4784a32010-05-27 19:41:15 -07001669 mStatus = NO_INIT;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001670}
1671
Evan Rosky1f6d6d52018-12-06 10:47:26 -08001672sp<SurfaceControl> SurfaceComposerClient::createSurface(const String8& name, uint32_t w, uint32_t h,
1673 PixelFormat format, uint32_t flags,
1674 SurfaceControl* parent,
Valerie Hau1acd6962019-10-28 16:35:48 -07001675 LayerMetadata metadata,
1676 uint32_t* outTransformHint) {
Robert Carr3b382ed2018-03-14 13:49:41 -07001677 sp<SurfaceControl> s;
Valerie Hau1acd6962019-10-28 16:35:48 -07001678 createSurfaceChecked(name, w, h, format, &s, flags, parent, std::move(metadata),
1679 outTransformHint);
Robert Carr3b382ed2018-03-14 13:49:41 -07001680 return s;
1681}
1682
Marissa Wall35187b32019-01-08 10:08:52 -08001683sp<SurfaceControl> SurfaceComposerClient::createWithSurfaceParent(const String8& name, uint32_t w,
1684 uint32_t h, PixelFormat format,
1685 uint32_t flags, Surface* parent,
Valerie Hau1acd6962019-10-28 16:35:48 -07001686 LayerMetadata metadata,
1687 uint32_t* outTransformHint) {
Marissa Wall35187b32019-01-08 10:08:52 -08001688 sp<SurfaceControl> sur;
1689 status_t err = mStatus;
1690
1691 if (mStatus == NO_ERROR) {
1692 sp<IBinder> handle;
1693 sp<IGraphicBufferProducer> parentGbp = parent->getIGraphicBufferProducer();
1694 sp<IGraphicBufferProducer> gbp;
1695
Valerie Hau1acd6962019-10-28 16:35:48 -07001696 uint32_t transformHint = 0;
Pablo Gamito2ec1f7b2020-09-01 14:18:49 +00001697 int32_t id = -1;
Evan Rosky1f6d6d52018-12-06 10:47:26 -08001698 err = mClient->createWithSurfaceParent(name, w, h, format, flags, parentGbp,
Pablo Gamito2ec1f7b2020-09-01 14:18:49 +00001699 std::move(metadata), &handle, &gbp, &id,
1700 &transformHint);
Valerie Hau1acd6962019-10-28 16:35:48 -07001701 if (outTransformHint) {
1702 *outTransformHint = transformHint;
1703 }
Marissa Wall35187b32019-01-08 10:08:52 -08001704 ALOGE_IF(err, "SurfaceComposerClient::createWithSurfaceParent error %s", strerror(-err));
1705 if (err == NO_ERROR) {
Pablo Gamitodbc31672020-09-01 18:28:58 +00001706 return new SurfaceControl(this, handle, gbp, id, transformHint);
Marissa Wall35187b32019-01-08 10:08:52 -08001707 }
1708 }
1709 return nullptr;
1710}
1711
Evan Rosky1f6d6d52018-12-06 10:47:26 -08001712status_t SurfaceComposerClient::createSurfaceChecked(const String8& name, uint32_t w, uint32_t h,
1713 PixelFormat format,
1714 sp<SurfaceControl>* outSurface, uint32_t flags,
Valerie Hau1acd6962019-10-28 16:35:48 -07001715 SurfaceControl* parent, LayerMetadata metadata,
1716 uint32_t* outTransformHint) {
Mathias Agopian4d9b8222013-03-12 17:11:48 -07001717 sp<SurfaceControl> sur;
Robert Carr740eaf02018-03-27 12:59:18 -07001718 status_t err = mStatus;
Robert Carr3b382ed2018-03-14 13:49:41 -07001719
Mathias Agopian698c0872011-06-28 19:09:31 -07001720 if (mStatus == NO_ERROR) {
Mathias Agopian4d9b8222013-03-12 17:11:48 -07001721 sp<IBinder> handle;
Robert Carr1f0a16a2016-10-24 16:27:39 -07001722 sp<IBinder> parentHandle;
Mathias Agopian4d9b8222013-03-12 17:11:48 -07001723 sp<IGraphicBufferProducer> gbp;
Robert Carr1f0a16a2016-10-24 16:27:39 -07001724
1725 if (parent != nullptr) {
1726 parentHandle = parent->getHandle();
1727 }
Evan Rosky1f6d6d52018-12-06 10:47:26 -08001728
Valerie Hau1acd6962019-10-28 16:35:48 -07001729 uint32_t transformHint = 0;
Pablo Gamito2ec1f7b2020-09-01 14:18:49 +00001730 int32_t id = -1;
Evan Rosky1f6d6d52018-12-06 10:47:26 -08001731 err = mClient->createSurface(name, w, h, format, flags, parentHandle, std::move(metadata),
Pablo Gamito2ec1f7b2020-09-01 14:18:49 +00001732 &handle, &gbp, &id, &transformHint);
1733
Valerie Hau1acd6962019-10-28 16:35:48 -07001734 if (outTransformHint) {
1735 *outTransformHint = transformHint;
1736 }
Mathias Agopian4d9b8222013-03-12 17:11:48 -07001737 ALOGE_IF(err, "SurfaceComposerClient::createSurface error %s", strerror(-err));
1738 if (err == NO_ERROR) {
Pablo Gamitodbc31672020-09-01 18:28:58 +00001739 *outSurface = new SurfaceControl(this, handle, gbp, id, transformHint);
Mathias Agopian698c0872011-06-28 19:09:31 -07001740 }
1741 }
Robert Carr3b382ed2018-03-14 13:49:41 -07001742 return err;
Mathias Agopian698c0872011-06-28 19:09:31 -07001743}
1744
chaviwfe94a222019-08-21 13:52:59 -07001745sp<SurfaceControl> SurfaceComposerClient::mirrorSurface(SurfaceControl* mirrorFromSurface) {
1746 if (mirrorFromSurface == nullptr) {
1747 return nullptr;
1748 }
1749
1750 sp<IBinder> handle;
1751 sp<IBinder> mirrorFromHandle = mirrorFromSurface->getHandle();
Pablo Gamito2ec1f7b2020-09-01 14:18:49 +00001752 int32_t layer_id = -1;
1753 status_t err = mClient->mirrorSurface(mirrorFromHandle, &handle, &layer_id);
chaviwfe94a222019-08-21 13:52:59 -07001754 if (err == NO_ERROR) {
Pablo Gamitodbc31672020-09-01 18:28:58 +00001755 return new SurfaceControl(this, handle, nullptr, layer_id, true /* owned */);
chaviwfe94a222019-08-21 13:52:59 -07001756 }
1757 return nullptr;
1758}
1759
Svetoslavd85084b2014-03-20 10:28:31 -07001760status_t SurfaceComposerClient::clearLayerFrameStats(const sp<IBinder>& token) const {
1761 if (mStatus != NO_ERROR) {
1762 return mStatus;
1763 }
1764 return mClient->clearLayerFrameStats(token);
1765}
1766
1767status_t SurfaceComposerClient::getLayerFrameStats(const sp<IBinder>& token,
1768 FrameStats* outStats) const {
1769 if (mStatus != NO_ERROR) {
1770 return mStatus;
1771 }
1772 return mClient->getLayerFrameStats(token, outStats);
1773}
1774
Mathias Agopian698c0872011-06-28 19:09:31 -07001775// ----------------------------------------------------------------------------
1776
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -07001777status_t SurfaceComposerClient::enableVSyncInjections(bool enable) {
Robert Carr4cdc58f2017-08-23 14:22:20 -07001778 sp<ISurfaceComposer> sf(ComposerService::getComposerService());
1779 return sf->enableVSyncInjections(enable);
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -07001780}
1781
1782status_t SurfaceComposerClient::injectVSync(nsecs_t when) {
Robert Carr4cdc58f2017-08-23 14:22:20 -07001783 sp<ISurfaceComposer> sf(ComposerService::getComposerService());
1784 return sf->injectVSync(when);
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -07001785}
1786
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -08001787status_t SurfaceComposerClient::getDisplayState(const sp<IBinder>& display,
1788 ui::DisplayState* state) {
1789 return ComposerService::getComposerService()->getDisplayState(display, state);
1790}
1791
1792status_t SurfaceComposerClient::getDisplayInfo(const sp<IBinder>& display, DisplayInfo* info) {
1793 return ComposerService::getComposerService()->getDisplayInfo(display, info);
1794}
1795
1796status_t SurfaceComposerClient::getDisplayConfigs(const sp<IBinder>& display,
1797 Vector<DisplayConfig>* configs) {
Dan Stoza7f7da322014-05-02 15:26:25 -07001798 return ComposerService::getComposerService()->getDisplayConfigs(display, configs);
1799}
1800
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -08001801status_t SurfaceComposerClient::getActiveDisplayConfig(const sp<IBinder>& display,
1802 DisplayConfig* config) {
1803 Vector<DisplayConfig> configs;
Dan Stoza7f7da322014-05-02 15:26:25 -07001804 status_t result = getDisplayConfigs(display, &configs);
1805 if (result != NO_ERROR) {
1806 return result;
1807 }
1808
1809 int activeId = getActiveConfig(display);
1810 if (activeId < 0) {
1811 ALOGE("No active configuration found");
1812 return NAME_NOT_FOUND;
1813 }
1814
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -08001815 *config = configs[static_cast<size_t>(activeId)];
Dan Stoza7f7da322014-05-02 15:26:25 -07001816 return NO_ERROR;
1817}
1818
1819int SurfaceComposerClient::getActiveConfig(const sp<IBinder>& display) {
1820 return ComposerService::getComposerService()->getActiveConfig(display);
1821}
1822
Ana Krulec0782b882019-10-15 17:34:54 -07001823status_t SurfaceComposerClient::setDesiredDisplayConfigSpecs(const sp<IBinder>& displayToken,
Ana Kruleced3a8cc2019-11-14 00:55:07 +01001824 int32_t defaultConfig,
Steven Thomasf734df42020-04-13 21:09:28 -07001825 float primaryRefreshRateMin,
1826 float primaryRefreshRateMax,
1827 float appRequestRefreshRateMin,
1828 float appRequestRefreshRateMax) {
1829 return ComposerService::getComposerService()
1830 ->setDesiredDisplayConfigSpecs(displayToken, defaultConfig, primaryRefreshRateMin,
1831 primaryRefreshRateMax, appRequestRefreshRateMin,
1832 appRequestRefreshRateMax);
Ana Krulec0782b882019-10-15 17:34:54 -07001833}
1834
Ana Krulec234bb162019-11-10 22:55:55 +01001835status_t SurfaceComposerClient::getDesiredDisplayConfigSpecs(const sp<IBinder>& displayToken,
Ana Kruleced3a8cc2019-11-14 00:55:07 +01001836 int32_t* outDefaultConfig,
Steven Thomasf734df42020-04-13 21:09:28 -07001837 float* outPrimaryRefreshRateMin,
1838 float* outPrimaryRefreshRateMax,
1839 float* outAppRequestRefreshRateMin,
1840 float* outAppRequestRefreshRateMax) {
1841 return ComposerService::getComposerService()
1842 ->getDesiredDisplayConfigSpecs(displayToken, outDefaultConfig, outPrimaryRefreshRateMin,
1843 outPrimaryRefreshRateMax, outAppRequestRefreshRateMin,
1844 outAppRequestRefreshRateMax);
Ana Krulec234bb162019-11-10 22:55:55 +01001845}
1846
Michael Wright28f24d02016-07-12 13:30:53 -07001847status_t SurfaceComposerClient::getDisplayColorModes(const sp<IBinder>& display,
Peiyong Lina52f0292018-03-14 17:26:31 -07001848 Vector<ColorMode>* outColorModes) {
Michael Wright28f24d02016-07-12 13:30:53 -07001849 return ComposerService::getComposerService()->getDisplayColorModes(display, outColorModes);
1850}
1851
Daniel Solomon42d04562019-01-20 21:03:19 -08001852status_t SurfaceComposerClient::getDisplayNativePrimaries(const sp<IBinder>& display,
1853 ui::DisplayPrimaries& outPrimaries) {
1854 return ComposerService::getComposerService()->getDisplayNativePrimaries(display, outPrimaries);
1855}
1856
Peiyong Lina52f0292018-03-14 17:26:31 -07001857ColorMode SurfaceComposerClient::getActiveColorMode(const sp<IBinder>& display) {
Michael Wright28f24d02016-07-12 13:30:53 -07001858 return ComposerService::getComposerService()->getActiveColorMode(display);
1859}
1860
1861status_t SurfaceComposerClient::setActiveColorMode(const sp<IBinder>& display,
Peiyong Lina52f0292018-03-14 17:26:31 -07001862 ColorMode colorMode) {
Michael Wright28f24d02016-07-12 13:30:53 -07001863 return ComposerService::getComposerService()->setActiveColorMode(display, colorMode);
1864}
1865
Galia Peycheva5492cb52019-10-30 14:13:16 +01001866bool SurfaceComposerClient::getAutoLowLatencyModeSupport(const sp<IBinder>& display) {
1867 bool supported = false;
1868 ComposerService::getComposerService()->getAutoLowLatencyModeSupport(display, &supported);
1869 return supported;
1870}
1871
1872void SurfaceComposerClient::setAutoLowLatencyMode(const sp<IBinder>& display, bool on) {
1873 ComposerService::getComposerService()->setAutoLowLatencyMode(display, on);
1874}
1875
1876bool SurfaceComposerClient::getGameContentTypeSupport(const sp<IBinder>& display) {
1877 bool supported = false;
1878 ComposerService::getComposerService()->getGameContentTypeSupport(display, &supported);
1879 return supported;
1880}
1881
1882void SurfaceComposerClient::setGameContentType(const sp<IBinder>& display, bool on) {
1883 ComposerService::getComposerService()->setGameContentType(display, on);
1884}
1885
Prashant Malani2c9b11f2014-05-25 01:36:31 -07001886void SurfaceComposerClient::setDisplayPowerMode(const sp<IBinder>& token,
1887 int mode) {
1888 ComposerService::getComposerService()->setPowerMode(token, mode);
Jeff Brown2a09bb32012-10-08 19:13:57 -07001889}
1890
Peiyong Linc6780972018-10-28 15:24:08 -07001891status_t SurfaceComposerClient::getCompositionPreference(
1892 ui::Dataspace* defaultDataspace, ui::PixelFormat* defaultPixelFormat,
1893 ui::Dataspace* wideColorGamutDataspace, ui::PixelFormat* wideColorGamutPixelFormat) {
1894 return ComposerService::getComposerService()
1895 ->getCompositionPreference(defaultDataspace, defaultPixelFormat,
1896 wideColorGamutDataspace, wideColorGamutPixelFormat);
Peiyong Lin0256f722018-08-31 15:45:10 -07001897}
1898
Peiyong Lin08d10512019-01-16 13:27:35 -08001899bool SurfaceComposerClient::getProtectedContentSupport() {
1900 bool supported = false;
1901 ComposerService::getComposerService()->getProtectedContentSupport(&supported);
1902 return supported;
1903}
1904
Svetoslavd85084b2014-03-20 10:28:31 -07001905status_t SurfaceComposerClient::clearAnimationFrameStats() {
1906 return ComposerService::getComposerService()->clearAnimationFrameStats();
1907}
1908
1909status_t SurfaceComposerClient::getAnimationFrameStats(FrameStats* outStats) {
1910 return ComposerService::getComposerService()->getAnimationFrameStats(outStats);
1911}
1912
Dan Stozac4f471e2016-03-24 09:31:08 -07001913status_t SurfaceComposerClient::getHdrCapabilities(const sp<IBinder>& display,
1914 HdrCapabilities* outCapabilities) {
1915 return ComposerService::getComposerService()->getHdrCapabilities(display,
1916 outCapabilities);
1917}
1918
Kevin DuBois9c0a1762018-10-16 13:32:31 -07001919status_t SurfaceComposerClient::getDisplayedContentSamplingAttributes(const sp<IBinder>& display,
1920 ui::PixelFormat* outFormat,
1921 ui::Dataspace* outDataspace,
1922 uint8_t* outComponentMask) {
1923 return ComposerService::getComposerService()
1924 ->getDisplayedContentSamplingAttributes(display, outFormat, outDataspace,
1925 outComponentMask);
1926}
1927
Kevin DuBois74e53772018-11-19 10:52:38 -08001928status_t SurfaceComposerClient::setDisplayContentSamplingEnabled(const sp<IBinder>& display,
1929 bool enable, uint8_t componentMask,
1930 uint64_t maxFrames) {
1931 return ComposerService::getComposerService()->setDisplayContentSamplingEnabled(display, enable,
1932 componentMask,
1933 maxFrames);
1934}
1935
Kevin DuBois1d4249a2018-08-29 10:45:14 -07001936status_t SurfaceComposerClient::getDisplayedContentSample(const sp<IBinder>& display,
1937 uint64_t maxFrames, uint64_t timestamp,
1938 DisplayedFrameStats* outStats) {
1939 return ComposerService::getComposerService()->getDisplayedContentSample(display, maxFrames,
1940 timestamp, outStats);
1941}
Marissa Wall35187b32019-01-08 10:08:52 -08001942
Peiyong Lin4f3fddf2019-01-24 17:21:24 -08001943status_t SurfaceComposerClient::isWideColorDisplay(const sp<IBinder>& display,
1944 bool* outIsWideColorDisplay) {
1945 return ComposerService::getComposerService()->isWideColorDisplay(display,
1946 outIsWideColorDisplay);
1947}
1948
Kevin DuBois00c66832019-02-18 16:21:31 -08001949status_t SurfaceComposerClient::addRegionSamplingListener(
1950 const Rect& samplingArea, const sp<IBinder>& stopLayerHandle,
1951 const sp<IRegionSamplingListener>& listener) {
1952 return ComposerService::getComposerService()->addRegionSamplingListener(samplingArea,
1953 stopLayerHandle,
1954 listener);
1955}
1956
1957status_t SurfaceComposerClient::removeRegionSamplingListener(
1958 const sp<IRegionSamplingListener>& listener) {
1959 return ComposerService::getComposerService()->removeRegionSamplingListener(listener);
1960}
1961
Dan Gittik57e63c52019-01-18 16:37:54 +00001962bool SurfaceComposerClient::getDisplayBrightnessSupport(const sp<IBinder>& displayToken) {
1963 bool support = false;
1964 ComposerService::getComposerService()->getDisplayBrightnessSupport(displayToken, &support);
1965 return support;
1966}
1967
1968status_t SurfaceComposerClient::setDisplayBrightness(const sp<IBinder>& displayToken,
1969 float brightness) {
1970 return ComposerService::getComposerService()->setDisplayBrightness(displayToken, brightness);
1971}
1972
Lais Andrade3a6e47d2020-04-02 11:20:16 +01001973status_t SurfaceComposerClient::notifyPowerBoost(int32_t boostId) {
1974 return ComposerService::getComposerService()->notifyPowerBoost(boostId);
Ady Abraham8532d012019-05-08 14:50:56 -07001975}
1976
Vishnu Nairb13bb952019-11-15 10:24:08 -08001977status_t SurfaceComposerClient::setGlobalShadowSettings(const half4& ambientColor,
1978 const half4& spotColor, float lightPosY,
1979 float lightPosZ, float lightRadius) {
1980 return ComposerService::getComposerService()->setGlobalShadowSettings(ambientColor, spotColor,
1981 lightPosY, lightPosZ,
1982 lightRadius);
1983}
1984
Mathias Agopian698c0872011-06-28 19:09:31 -07001985// ----------------------------------------------------------------------------
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001986
chaviw690db382020-07-27 16:46:46 -07001987status_t ScreenshotClient::captureDisplay(const DisplayCaptureArgs& captureArgs,
chaviwe7b9f272020-08-18 16:08:59 -07001988 const sp<IScreenCaptureListener>& captureListener) {
Mathias Agopian2a9fc492013-03-01 13:42:57 -08001989 sp<ISurfaceComposer> s(ComposerService::getComposerService());
Yi Kong48a619f2018-06-05 16:34:59 -07001990 if (s == nullptr) return NO_INIT;
chaviw8ffc7b82020-08-18 11:25:37 -07001991
chaviwe7b9f272020-08-18 16:08:59 -07001992 return s->captureDisplay(captureArgs, captureListener);
Robert Carr673134e2017-01-09 19:48:38 -08001993}
1994
chaviw690db382020-07-27 16:46:46 -07001995status_t ScreenshotClient::captureDisplay(uint64_t displayOrLayerStack,
chaviwe7b9f272020-08-18 16:08:59 -07001996 const sp<IScreenCaptureListener>& captureListener) {
chaviw93df2ea2019-04-30 16:45:12 -07001997 sp<ISurfaceComposer> s(ComposerService::getComposerService());
1998 if (s == nullptr) return NO_INIT;
chaviw8ffc7b82020-08-18 11:25:37 -07001999
chaviwe7b9f272020-08-18 16:08:59 -07002000 return s->captureDisplay(displayOrLayerStack, captureListener);
chaviw93df2ea2019-04-30 16:45:12 -07002001}
2002
chaviw26c52482020-07-28 16:25:52 -07002003status_t ScreenshotClient::captureLayers(const LayerCaptureArgs& captureArgs,
chaviwe7b9f272020-08-18 16:08:59 -07002004 const sp<IScreenCaptureListener>& captureListener) {
chaviwa76b2712017-09-20 12:02:26 -07002005 sp<ISurfaceComposer> s(ComposerService::getComposerService());
Yi Kong48a619f2018-06-05 16:34:59 -07002006 if (s == nullptr) return NO_INIT;
chaviw8ffc7b82020-08-18 11:25:37 -07002007
chaviwe7b9f272020-08-18 16:08:59 -07002008 return s->captureLayers(captureArgs, captureListener);
chaviwa76b2712017-09-20 12:02:26 -07002009}
Dominik Laskowski718f9602019-11-09 20:01:35 -08002010
2011} // namespace android