blob: dd24c2c9c8250e61bb6d543ff45942e7cb163dd9 [file] [log] [blame]
The Android Open Source Projectedbf3b62009-03-04 03:31:441/*
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-04 03:31:4420#include <sys/types.h>
The Android Open Source Projectedbf3b62009-03-04 03:31:4421
The Android Open Source Projectedbf3b62009-03-04 03:31:4422#include <utils/Errors.h>
The Android Open Source Projectedbf3b62009-03-04 03:31:4423#include <utils/Log.h>
Mathias Agopiana67932f2011-04-20 21:20:5924#include <utils/SortedVector.h>
25#include <utils/String8.h>
26#include <utils/threads.h>
The Android Open Source Projectedbf3b62009-03-04 03:31:4427
Marissa Wall7a9b6ff2018-08-22 00:26:2028#include <binder/IPCThreadState.h>
Mathias Agopiana67932f2011-04-20 21:20:5929#include <binder/IServiceManager.h>
Marissa Wall7a9b6ff2018-08-22 00:26:2030#include <binder/ProcessState.h>
Mathias Agopian9cce3252010-02-10 01:46:3731
Michael Wright28f24d02016-07-12 20:30:5332#include <system/graphics.h>
33
Robert Carr673134e2017-01-10 03:48:3834#include <gui/BufferItemConsumer.h>
Mathias Agopianabe815d2013-03-20 05:22:2135#include <gui/CpuConsumer.h>
Mathias Agopiane3c697f2013-02-15 01:11:0236#include <gui/IGraphicBufferProducer.h>
Mathias Agopian90ac7992012-02-26 02:48:3537#include <gui/ISurfaceComposer.h>
38#include <gui/ISurfaceComposerClient.h>
Robert Carr4cdc58f2017-08-23 21:22:2039#include <gui/LayerState.h>
Robert Carr0d480722017-01-11 00:42:5440#include <gui/Surface.h>
Mathias Agopian90ac7992012-02-26 02:48:3541#include <gui/SurfaceComposerClient.h>
Dominik Laskowski3cb3d4e2019-11-21 19:14:4542#include <ui/DisplayConfig.h>
The Android Open Source Projectedbf3b62009-03-04 03:31:4443
Robert Carr2c358bf2018-08-08 22:58:1544#ifndef NO_INPUT
45#include <input/InputWindow.h>
46#endif
47
Mathias Agopian41f673c2011-11-18 01:48:3548#include <private/gui/ComposerService.h>
The Android Open Source Projectedbf3b62009-03-04 03:31:4449
Marissa Wall73411622019-01-25 18:45:4150// 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-04 03:31:4453namespace android {
Peiyong Lin9f034472018-03-28 22:29:0054
55using ui::ColorMode;
The Android Open Source Projectedbf3b62009-03-04 03:31:4456// ---------------------------------------------------------------------------
57
Mathias Agopian7e27f052010-05-28 21:22:2358ANDROID_SINGLETON_STATIC_INSTANCE(ComposerService);
59
Mathias Agopianb7e930d2010-06-01 22:12:5860ComposerService::ComposerService()
61: Singleton<ComposerService>() {
Andy McFadden6652b3e2012-09-07 01:45:5662 Mutex::Autolock _l(mLock);
63 connectLocked();
64}
65
66void ComposerService::connectLocked() {
Mathias Agopianb7e930d2010-06-01 22:12:5867 const String16 name("SurfaceFlinger");
68 while (getService(name, &mComposerService) != NO_ERROR) {
69 usleep(250000);
70 }
Yi Konga03e0442018-07-17 18:16:5771 assert(mComposerService != nullptr);
Andy McFadden6652b3e2012-09-07 01:45:5672
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 22:41:0582 explicit DeathObserver(ComposerService& mgr) : mComposerService(mgr) { }
Andy McFadden6652b3e2012-09-07 01:45:5683 };
84
85 mDeathObserver = new DeathObserver(*const_cast<ComposerService*>(this));
Marco Nelissen2ea926b2014-11-14 16:01:0186 IInterface::asBinder(mComposerService)->linkToDeath(mDeathObserver);
Mathias Agopianb7e930d2010-06-01 22:12:5887}
88
Andy McFadden6652b3e2012-09-07 01:45:5689/*static*/ sp<ISurfaceComposer> ComposerService::getComposerService() {
90 ComposerService& instance = ComposerService::getInstance();
91 Mutex::Autolock _l(instance.mLock);
Yi Kong48a619f2018-06-05 23:34:5992 if (instance.mComposerService == nullptr) {
Andy McFadden6652b3e2012-09-07 01:45:5693 ComposerService::getInstance().connectLocked();
Yi Konga03e0442018-07-17 18:16:5794 assert(instance.mComposerService != nullptr);
Andy McFadden6652b3e2012-09-07 01:45:5695 ALOGD("ComposerService reconnected");
96 }
97 return instance.mComposerService;
98}
99
100void ComposerService::composerServiceDied()
101{
102 Mutex::Autolock _l(mLock);
Yi Kong48a619f2018-06-05 23:34:59103 mComposerService = nullptr;
104 mDeathObserver = nullptr;
Mathias Agopianb7e930d2010-06-01 22:12:58105}
106
Robert Carrfb4d58b2019-01-15 17:21:27107class 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 21:22:23128// ---------------------------------------------------------------------------
129
Marissa Wall7a9b6ff2018-08-22 00:26:20130// 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 17:04:44134// 0 is an invalid callback id
135TransactionCompletedListener::TransactionCompletedListener() : mCallbackIdCounter(1) {}
136
137CallbackId TransactionCompletedListener::getNextIdLocked() {
138 return mCallbackIdCounter++;
139}
140
Marissa Wall7a9b6ff2018-08-22 00:26:20141sp<TransactionCompletedListener> TransactionCompletedListener::getInstance() {
142 static sp<TransactionCompletedListener> sInstance = new TransactionCompletedListener;
143 return sInstance;
144}
145
Marissa Wallc837b5e2018-10-12 17:04:44146sp<ITransactionCompletedListener> TransactionCompletedListener::getIInstance() {
147 return static_cast<sp<ITransactionCompletedListener>>(getInstance());
148}
149
150void TransactionCompletedListener::startListeningLocked() {
Marissa Wall7a9b6ff2018-08-22 00:26:20151 if (mListening) {
152 return;
153 }
154 ProcessState::self()->startThreadPool();
155 mListening = true;
156}
157
Marissa Wall80d94ad2019-01-19 00:04:36158CallbackId TransactionCompletedListener::addCallbackFunction(
159 const TransactionCompletedCallback& callbackFunction,
160 const std::unordered_set<sp<SurfaceControl>, SurfaceComposerClient::SCHash>&
161 surfaceControls) {
Marissa Wallc837b5e2018-10-12 17:04:44162 std::lock_guard<std::mutex> lock(mMutex);
163 startListeningLocked();
164
165 CallbackId callbackId = getNextIdLocked();
Marissa Wall80d94ad2019-01-19 00:04:36166 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 17:04:44174 return callbackId;
175}
176
Marissa Wall80d94ad2019-01-19 00:04:36177void 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 18:33:52190void TransactionCompletedListener::onTransactionCompleted(ListenerStats listenerStats) {
Valerie Haud3b90d22019-11-06 17:37:31191 std::unordered_map<CallbackId, CallbackTranslation> callbacksMap;
192 {
193 std::lock_guard<std::mutex> lock(mMutex);
Marissa Walle2ffb422018-10-12 18:33:52194
Valerie Haud3b90d22019-11-06 17:37:31195 /* 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-19 00:04:36211 }
212 }
Marissa Walld600d572019-03-26 22:38:50213 for (const auto& transactionStats : listenerStats.transactionStats) {
214 for (auto callbackId : transactionStats.callbackIds) {
Valerie Haud3b90d22019-11-06 17:37:31215 auto& [callbackFunction, callbackSurfaceControls] = callbacksMap[callbackId];
Marissa Wall80d94ad2019-01-19 00:04:36216 if (!callbackFunction) {
Marissa Walle2ffb422018-10-12 18:33:52217 ALOGE("cannot call null callback function, skipping");
218 continue;
219 }
Marissa Wall80d94ad2019-01-19 00:04:36220 std::vector<SurfaceControlStats> surfaceControlStats;
221 for (const auto& surfaceStats : transactionStats.surfaceStats) {
Valerie Haud3b90d22019-11-06 17:37:31222 surfaceControlStats
223 .emplace_back(callbacksMap[callbackId]
224 .surfaceControls[surfaceStats.surfaceControl],
Valerie Hau871d6352020-01-29 16:44:02225 transactionStats.latchTime, surfaceStats.acquireTime,
226 transactionStats.presentFence,
227 surfaceStats.previousReleaseFence, surfaceStats.transformHint,
228 surfaceStats.eventStats);
Valerie Hau84d87ff2020-01-09 01:23:21229 if (callbacksMap[callbackId].surfaceControls[surfaceStats.surfaceControl]) {
230 callbacksMap[callbackId]
231 .surfaceControls[surfaceStats.surfaceControl]
232 ->setTransformHint(surfaceStats.transformHint);
233 }
Marissa Wall80d94ad2019-01-19 00:04:36234 }
235
236 callbackFunction(transactionStats.latchTime, transactionStats.presentFence,
237 surfaceControlStats);
Marissa Walle2ffb422018-10-12 18:33:52238 }
239 }
Marissa Wall7a9b6ff2018-08-22 00:26:20240}
241
242// ---------------------------------------------------------------------------
243
Robert Carre06ad2b2020-04-10 22:09:33244void removeDeadBufferCallback(void* /*context*/, uint64_t graphicBufferId);
Marissa Wall78b72202019-03-15 21:58:34245
Robert Carre06ad2b2020-04-10 22:09:33246/**
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 18:45:41269class 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 21:58:34277 status_t getCacheId(const sp<GraphicBuffer>& buffer, uint64_t* cacheId) {
Yi Kongd2639aa2019-02-28 19:58:32278 std::lock_guard<std::mutex> lock(mMutex);
Marissa Wall73411622019-01-25 18:45:41279
Marissa Wall78b72202019-03-15 21:58:34280 auto itr = mBuffers.find(buffer->getId());
Marissa Wall73411622019-01-25 18:45:41281 if (itr == mBuffers.end()) {
Marissa Wall78b72202019-03-15 21:58:34282 return BAD_VALUE;
Marissa Wall73411622019-01-25 18:45:41283 }
Marissa Wall78b72202019-03-15 21:58:34284 itr->second = getCounter();
285 *cacheId = buffer->getId();
286 return NO_ERROR;
Marissa Wall73411622019-01-25 18:45:41287 }
288
Marissa Wall78b72202019-03-15 21:58:34289 uint64_t cache(const sp<GraphicBuffer>& buffer) {
Yi Kongd2639aa2019-02-28 19:58:32290 std::lock_guard<std::mutex> lock(mMutex);
Marissa Wall73411622019-01-25 18:45:41291
Marissa Wall78b72202019-03-15 21:58:34292 if (mBuffers.size() >= BUFFER_CACHE_MAX_SIZE) {
293 evictLeastRecentlyUsedBuffer();
294 }
Marissa Wall73411622019-01-25 18:45:41295
Robert Carre06ad2b2020-04-10 22:09:33296 buffer->addDeathCallback(removeDeadBufferCallback, nullptr);
Marissa Wall78b72202019-03-15 21:58:34297
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 18:45:41310 }
311
312private:
Marissa Wall78b72202019-03-15 21:58:34313 void evictLeastRecentlyUsedBuffer() REQUIRES(mMutex) {
Marissa Wall73411622019-01-25 18:45:41314 auto itr = mBuffers.begin();
Marissa Wall78b72202019-03-15 21:58:34315 uint64_t minCounter = itr->second;
Marissa Wall73411622019-01-25 18:45:41316 auto minBuffer = itr;
317 itr++;
318
319 while (itr != mBuffers.end()) {
Marissa Wall78b72202019-03-15 21:58:34320 uint64_t counter = itr->second;
Marissa Wall73411622019-01-25 18:45:41321 if (counter < minCounter) {
322 minCounter = counter;
323 minBuffer = itr;
324 }
325 itr++;
326 }
Marissa Wall78b72202019-03-15 21:58:34327 uncacheLocked(minBuffer->first);
Marissa Wall73411622019-01-25 18:45:41328 }
329
330 uint64_t getCounter() REQUIRES(mMutex) {
331 static uint64_t counter = 0;
332 return counter++;
333 }
334
Marissa Wall73411622019-01-25 18:45:41335 std::mutex mMutex;
Marissa Wall78b72202019-03-15 21:58:34336 std::map<uint64_t /*Cache id*/, uint64_t /*counter*/> mBuffers GUARDED_BY(mMutex);
Marissa Wall73411622019-01-25 18:45:41337
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 22:09:33344void removeDeadBufferCallback(void* /*context*/, uint64_t graphicBufferId) {
Marissa Wall78b72202019-03-15 21:58:34345 // GraphicBuffer id's are used as the cache ids.
346 BufferCache::getInstance().uncache(graphicBufferId);
347}
348
Marissa Wall73411622019-01-25 18:45:41349// ---------------------------------------------------------------------------
350
Pablo Gamito7eb7ee72020-08-05 10:57:05351// 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-27 00:32:34359SurfaceComposerClient::Transaction::Transaction(const Transaction& other)
Pablo Gamito7eb7ee72020-08-05 10:57:05360 : mId(other.mId),
361 mForceSynchronous(other.mForceSynchronous),
Marissa Wall17b4e452018-12-27 00:32:34362 mTransactionNestCount(other.mTransactionNestCount),
363 mAnimation(other.mAnimation),
364 mEarlyWakeup(other.mEarlyWakeup),
Ady Abrahambf1349c2020-06-12 21:26:18365 mExplicitEarlyWakeupStart(other.mExplicitEarlyWakeupStart),
366 mExplicitEarlyWakeupEnd(other.mExplicitEarlyWakeupEnd),
Vishnu Nair621102e2019-06-12 21:16:57367 mContainsBuffer(other.mContainsBuffer),
Marissa Wall17b4e452018-12-27 00:32:34368 mDesiredPresentTime(other.mDesiredPresentTime) {
Robert Carr4cdc58f2017-08-23 21:22:20369 mDisplayStates = other.mDisplayStates;
370 mComposerStates = other.mComposerStates;
chaviw273171b2018-12-26 19:46:30371 mInputWindowCommands = other.mInputWindowCommands;
Vishnu Nair621102e2019-06-12 21:16:57372 mListenerCallbacks = other.mListenerCallbacks;
373}
374
375std::unique_ptr<SurfaceComposerClient::Transaction>
376SurfaceComposerClient::Transaction::createFromParcel(const Parcel* parcel) {
377 auto transaction = std::make_unique<Transaction>();
378 if (transaction->readFromParcel(parcel) == NO_ERROR) {
379 return transaction;
380 }
381 return nullptr;
382}
383
Pablo Gamito7eb7ee72020-08-05 10:57:05384int64_t SurfaceComposerClient::Transaction::generateId() {
385 return (((int64_t)getpid()) << 32) | idCounter++;
386}
387
Vishnu Nair621102e2019-06-12 21:16:57388status_t SurfaceComposerClient::Transaction::readFromParcel(const Parcel* parcel) {
389 const uint32_t forceSynchronous = parcel->readUint32();
390 const uint32_t transactionNestCount = parcel->readUint32();
391 const bool animation = parcel->readBool();
392 const bool earlyWakeup = parcel->readBool();
Ady Abrahambf1349c2020-06-12 21:26:18393 const bool explicitEarlyWakeupStart = parcel->readBool();
394 const bool explicitEarlyWakeupEnd = parcel->readBool();
Vishnu Nair621102e2019-06-12 21:16:57395 const bool containsBuffer = parcel->readBool();
396 const int64_t desiredPresentTime = parcel->readInt64();
397
398 size_t count = static_cast<size_t>(parcel->readUint32());
399 if (count > parcel->dataSize()) {
400 return BAD_VALUE;
401 }
402 SortedVector<DisplayState> displayStates;
403 displayStates.setCapacity(count);
404 for (size_t i = 0; i < count; i++) {
405 DisplayState displayState;
406 if (displayState.read(*parcel) == BAD_VALUE) {
407 return BAD_VALUE;
408 }
409 displayStates.add(displayState);
410 }
411
412 count = static_cast<size_t>(parcel->readUint32());
413 if (count > parcel->dataSize()) {
414 return BAD_VALUE;
415 }
Valerie Hau9dab9732019-08-20 16:29:25416 std::unordered_map<sp<ITransactionCompletedListener>, CallbackInfo, TCLHash> listenerCallbacks;
417 listenerCallbacks.reserve(count);
418 for (size_t i = 0; i < count; i++) {
419 sp<ITransactionCompletedListener> listener =
420 interface_cast<ITransactionCompletedListener>(parcel->readStrongBinder());
421 size_t numCallbackIds = parcel->readUint32();
422 if (numCallbackIds > parcel->dataSize()) {
423 return BAD_VALUE;
424 }
425 for (size_t j = 0; j < numCallbackIds; j++) {
426 listenerCallbacks[listener].callbackIds.insert(parcel->readInt64());
427 }
428 size_t numSurfaces = parcel->readUint32();
429 if (numSurfaces > parcel->dataSize()) {
430 return BAD_VALUE;
431 }
432 for (size_t j = 0; j < numSurfaces; j++) {
433 sp<SurfaceControl> surface;
Pablo Gamito421dfd52020-09-22 18:11:45434 SAFE_PARCEL(SurfaceControl::readFromParcel, *parcel, &surface);
Valerie Hau9dab9732019-08-20 16:29:25435 listenerCallbacks[listener].surfaceControls.insert(surface);
436 }
437 }
438
439 count = static_cast<size_t>(parcel->readUint32());
440 if (count > parcel->dataSize()) {
441 return BAD_VALUE;
442 }
Vishnu Nairf03652d2019-07-17 00:56:56443 std::unordered_map<sp<IBinder>, ComposerState, IBinderHash> composerStates;
Vishnu Nair621102e2019-06-12 21:16:57444 composerStates.reserve(count);
445 for (size_t i = 0; i < count; i++) {
Pablo Gamitodbc31672020-09-01 18:28:58446 sp<IBinder> surfaceControlHandle;
447 SAFE_PARCEL(parcel->readStrongBinder, &surfaceControlHandle);
Vishnu Nair621102e2019-06-12 21:16:57448
449 ComposerState composerState;
450 if (composerState.read(*parcel) == BAD_VALUE) {
451 return BAD_VALUE;
452 }
Pablo Gamitodbc31672020-09-01 18:28:58453
Vishnu Nairf03652d2019-07-17 00:56:56454 composerStates[surfaceControlHandle] = composerState;
Vishnu Nair621102e2019-06-12 21:16:57455 }
456
457 InputWindowCommands inputWindowCommands;
458 inputWindowCommands.read(*parcel);
459
460 // Parsing was successful. Update the object.
461 mForceSynchronous = forceSynchronous;
462 mTransactionNestCount = transactionNestCount;
463 mAnimation = animation;
464 mEarlyWakeup = earlyWakeup;
Ady Abrahambf1349c2020-06-12 21:26:18465 mExplicitEarlyWakeupStart = explicitEarlyWakeupStart;
466 mExplicitEarlyWakeupEnd = explicitEarlyWakeupEnd;
Vishnu Nair621102e2019-06-12 21:16:57467 mContainsBuffer = containsBuffer;
468 mDesiredPresentTime = desiredPresentTime;
469 mDisplayStates = displayStates;
Valerie Hau9dab9732019-08-20 16:29:25470 mListenerCallbacks = listenerCallbacks;
Vishnu Nair621102e2019-06-12 21:16:57471 mComposerStates = composerStates;
472 mInputWindowCommands = inputWindowCommands;
Vishnu Nair621102e2019-06-12 21:16:57473 return NO_ERROR;
474}
475
476status_t SurfaceComposerClient::Transaction::writeToParcel(Parcel* parcel) const {
Robert Carr158531d2020-04-08 17:53:30477 // If we write the Transaction to a parcel, we want to ensure the Buffers are cached
478 // before crossing the IPC boundary. Otherwise the receiving party will cache the buffers
479 // but is unlikely to use them again as they are owned by the other process.
480 // You may be asking yourself, is this const cast safe? Const cast is safe up
481 // until the point where you try and write to an object that was originally const at which
482 // point we enter undefined behavior. In this case we are safe though, because there are
483 // two possibilities:
484 // 1. The SurfaceComposerClient::Transaction was originally non-const. Safe.
485 // 2. It was originall const! In this case not only was it useless, but it by definition
486 // contains no composer states and so cacheBuffers will not perform any writes.
487
488 const_cast<SurfaceComposerClient::Transaction*>(this)->cacheBuffers();
489
Vishnu Nair621102e2019-06-12 21:16:57490 parcel->writeUint32(mForceSynchronous);
491 parcel->writeUint32(mTransactionNestCount);
492 parcel->writeBool(mAnimation);
493 parcel->writeBool(mEarlyWakeup);
Ady Abrahambf1349c2020-06-12 21:26:18494 parcel->writeBool(mExplicitEarlyWakeupStart);
495 parcel->writeBool(mExplicitEarlyWakeupEnd);
Vishnu Nair621102e2019-06-12 21:16:57496 parcel->writeBool(mContainsBuffer);
497 parcel->writeInt64(mDesiredPresentTime);
498 parcel->writeUint32(static_cast<uint32_t>(mDisplayStates.size()));
499 for (auto const& displayState : mDisplayStates) {
500 displayState.write(*parcel);
501 }
502
Valerie Hau9dab9732019-08-20 16:29:25503 parcel->writeUint32(static_cast<uint32_t>(mListenerCallbacks.size()));
504 for (auto const& [listener, callbackInfo] : mListenerCallbacks) {
505 parcel->writeStrongBinder(ITransactionCompletedListener::asBinder(listener));
506 parcel->writeUint32(static_cast<uint32_t>(callbackInfo.callbackIds.size()));
507 for (auto callbackId : callbackInfo.callbackIds) {
508 parcel->writeInt64(callbackId);
509 }
510 parcel->writeUint32(static_cast<uint32_t>(callbackInfo.surfaceControls.size()));
511 for (auto surfaceControl : callbackInfo.surfaceControls) {
Pablo Gamito421dfd52020-09-22 18:11:45512 SAFE_PARCEL(surfaceControl->writeToParcel, *parcel);
Valerie Hau9dab9732019-08-20 16:29:25513 }
514 }
515
Vishnu Nair621102e2019-06-12 21:16:57516 parcel->writeUint32(static_cast<uint32_t>(mComposerStates.size()));
Pablo Gamitodbc31672020-09-01 18:28:58517 for (auto const& [handle, composerState] : mComposerStates) {
518 SAFE_PARCEL(parcel->writeStrongBinder, handle);
Vishnu Nair621102e2019-06-12 21:16:57519 composerState.write(*parcel);
520 }
521
522 mInputWindowCommands.write(*parcel);
523 return NO_ERROR;
Mathias Agopian698c0872011-06-29 02:09:31524}
525
Robert Carr2c5f6d22017-09-26 19:30:35526SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::merge(Transaction&& other) {
Pablo Gamitodbc31672020-09-01 18:28:58527 for (auto const& [handle, composerState] : other.mComposerStates) {
528 if (mComposerStates.count(handle) == 0) {
529 mComposerStates[handle] = composerState;
Robert Carr2c5f6d22017-09-26 19:30:35530 } else {
Pablo Gamitodbc31672020-09-01 18:28:58531 mComposerStates[handle].state.merge(composerState.state);
Robert Carr2c5f6d22017-09-26 19:30:35532 }
533 }
Robert Carr2c5f6d22017-09-26 19:30:35534
535 for (auto const& state : other.mDisplayStates) {
536 ssize_t index = mDisplayStates.indexOf(state);
537 if (index < 0) {
538 mDisplayStates.add(state);
539 } else {
540 mDisplayStates.editItemAt(static_cast<size_t>(index)).merge(state);
541 }
542 }
Robert Carr2c5f6d22017-09-26 19:30:35543
Marissa Wallc837b5e2018-10-12 17:04:44544 for (const auto& [listener, callbackInfo] : other.mListenerCallbacks) {
545 auto& [callbackIds, surfaceControls] = callbackInfo;
546 mListenerCallbacks[listener].callbackIds.insert(std::make_move_iterator(
547 callbackIds.begin()),
548 std::make_move_iterator(callbackIds.end()));
Valerie Hau9dab9732019-08-20 16:29:25549
Valerie Hau236eba32020-01-04 00:53:39550 mListenerCallbacks[listener].surfaceControls.insert(surfaceControls.begin(),
551 surfaceControls.end());
552
553 auto& currentProcessCallbackInfo =
554 mListenerCallbacks[TransactionCompletedListener::getIInstance()];
555 currentProcessCallbackInfo.surfaceControls
556 .insert(std::make_move_iterator(surfaceControls.begin()),
557 std::make_move_iterator(surfaceControls.end()));
558
559 // register all surface controls for all callbackIds for this listener that is merging
560 for (const auto& surfaceControl : currentProcessCallbackInfo.surfaceControls) {
561 TransactionCompletedListener::getInstance()
562 ->addSurfaceControlToCallbacks(surfaceControl,
563 currentProcessCallbackInfo.callbackIds);
564 }
Marissa Wallc837b5e2018-10-12 17:04:44565 }
Marissa Wallc837b5e2018-10-12 17:04:44566
chaviw273171b2018-12-26 19:46:30567 mInputWindowCommands.merge(other.mInputWindowCommands);
568
Robert Carrbbc85622020-04-08 17:45:12569 mContainsBuffer |= other.mContainsBuffer;
Jorim Jaggie3b57002019-07-22 15:18:52570 mEarlyWakeup = mEarlyWakeup || other.mEarlyWakeup;
Ady Abrahambf1349c2020-06-12 21:26:18571 mExplicitEarlyWakeupStart = mExplicitEarlyWakeupStart || other.mExplicitEarlyWakeupStart;
572 mExplicitEarlyWakeupEnd = mExplicitEarlyWakeupEnd || other.mExplicitEarlyWakeupEnd;
Vishnu Nairfef244e2019-06-18 01:07:51573 other.clear();
Robert Carr2c5f6d22017-09-26 19:30:35574 return *this;
575}
576
Vishnu Nairfef244e2019-06-18 01:07:51577void SurfaceComposerClient::Transaction::clear() {
578 mComposerStates.clear();
579 mDisplayStates.clear();
580 mListenerCallbacks.clear();
581 mInputWindowCommands.clear();
582 mContainsBuffer = false;
583 mForceSynchronous = 0;
584 mTransactionNestCount = 0;
585 mAnimation = false;
586 mEarlyWakeup = false;
Ady Abrahambf1349c2020-06-12 21:26:18587 mExplicitEarlyWakeupStart = false;
588 mExplicitEarlyWakeupEnd = false;
Vishnu Nairfef244e2019-06-18 01:07:51589 mDesiredPresentTime = -1;
590}
591
Marissa Wall78b72202019-03-15 21:58:34592void SurfaceComposerClient::doUncacheBufferTransaction(uint64_t cacheId) {
593 sp<ISurfaceComposer> sf(ComposerService::getComposerService());
594
Marissa Wall947d34e2019-03-29 21:03:53595 client_cache_t uncacheBuffer;
Marissa Wall78b72202019-03-15 21:58:34596 uncacheBuffer.token = BufferCache::getInstance().getToken();
Marissa Wall947d34e2019-03-29 21:03:53597 uncacheBuffer.id = cacheId;
Marissa Wall78b72202019-03-15 21:58:34598
Valerie Haufa889122019-04-15 20:56:05599 sp<IBinder> applyToken = IInterface::asBinder(TransactionCompletedListener::getIInstance());
Pablo Gamito7eb7ee72020-08-05 10:57:05600 sf->setTransactionState({}, {}, 0, applyToken, {}, -1, uncacheBuffer, false, {},
601 0 /* Undefined transactionId */);
Marissa Wall78b72202019-03-15 21:58:34602}
603
604void SurfaceComposerClient::Transaction::cacheBuffers() {
605 if (!mContainsBuffer) {
606 return;
607 }
608
609 size_t count = 0;
Vishnu Nairf03652d2019-07-17 00:56:56610 for (auto& [handle, cs] : mComposerStates) {
Pablo Gamitodbc31672020-09-01 18:28:58611 layer_state_t* s = &(mComposerStates[handle].state);
Marissa Wall78b72202019-03-15 21:58:34612 if (!(s->what & layer_state_t::eBufferChanged)) {
613 continue;
Robert Carr28037922020-04-08 17:57:07614 } else if (s->what & layer_state_t::eCachedBufferChanged) {
615 // If eBufferChanged and eCachedBufferChanged are both trued then that means
616 // we already cached the buffer in a previous call to cacheBuffers, perhaps
617 // from writeToParcel on a Transaction that was merged in to this one.
618 continue;
Marissa Wall78b72202019-03-15 21:58:34619 }
620
Marissa Wall00597242019-03-27 17:35:19621 // Don't try to cache a null buffer. Sending null buffers is cheap so we shouldn't waste
622 // time trying to cache them.
623 if (!s->buffer) {
624 continue;
625 }
626
Marissa Wall78b72202019-03-15 21:58:34627 uint64_t cacheId = 0;
628 status_t ret = BufferCache::getInstance().getCacheId(s->buffer, &cacheId);
629 if (ret == NO_ERROR) {
Robert Carre06ad2b2020-04-10 22:09:33630 // Cache-hit. Strip the buffer and send only the id.
Marissa Walla141abe2019-03-27 23:28:07631 s->what &= ~static_cast<uint64_t>(layer_state_t::eBufferChanged);
Marissa Wall78b72202019-03-15 21:58:34632 s->buffer = nullptr;
633 } else {
Robert Carre06ad2b2020-04-10 22:09:33634 // Cache-miss. Include the buffer and send the new cacheId.
Marissa Wall78b72202019-03-15 21:58:34635 cacheId = BufferCache::getInstance().cache(s->buffer);
636 }
637 s->what |= layer_state_t::eCachedBufferChanged;
638 s->cachedBuffer.token = BufferCache::getInstance().getToken();
Marissa Wall947d34e2019-03-29 21:03:53639 s->cachedBuffer.id = cacheId;
Marissa Wall78b72202019-03-15 21:58:34640
641 // If we have more buffers than the size of the cache, we should stop caching so we don't
642 // evict other buffers in this transaction
643 count++;
644 if (count >= BUFFER_CACHE_MAX_SIZE) {
645 break;
646 }
647 }
Robert Carr6fb1a7e2018-12-11 20:07:25648}
649
Robert Carr4cdc58f2017-08-23 21:22:20650status_t SurfaceComposerClient::Transaction::apply(bool synchronous) {
651 if (mStatus != NO_ERROR) {
652 return mStatus;
653 }
654
655 sp<ISurfaceComposer> sf(ComposerService::getComposerService());
656
Valerie Hau9dab9732019-08-20 16:29:25657 bool hasListenerCallbacks = !mListenerCallbacks.empty();
Marissa Wall3dad52d2019-03-22 21:03:19658 std::vector<ListenerCallbacks> listenerCallbacks;
Marissa Wallc837b5e2018-10-12 17:04:44659 // For every listener with registered callbacks
660 for (const auto& [listener, callbackInfo] : mListenerCallbacks) {
661 auto& [callbackIds, surfaceControls] = callbackInfo;
662 if (callbackIds.empty()) {
663 continue;
664 }
665
Valerie Hau9dab9732019-08-20 16:29:25666 if (surfaceControls.empty()) {
667 listenerCallbacks.emplace_back(IInterface::asBinder(listener), std::move(callbackIds));
668 } else {
669 // If the listener has any SurfaceControls set on this Transaction update the surface
670 // state
671 for (const auto& surfaceControl : surfaceControls) {
672 layer_state_t* s = getLayerState(surfaceControl);
673 if (!s) {
674 ALOGE("failed to get layer state");
675 continue;
676 }
677 std::vector<CallbackId> callbacks(callbackIds.begin(), callbackIds.end());
678 s->what |= layer_state_t::eHasListenerCallbacksChanged;
679 s->listeners.emplace_back(IInterface::asBinder(listener), callbacks);
Marissa Wallc837b5e2018-10-12 17:04:44680 }
Marissa Wallc837b5e2018-10-12 17:04:44681 }
682 }
Valerie Hau9dab9732019-08-20 16:29:25683
Marissa Wallc837b5e2018-10-12 17:04:44684 mListenerCallbacks.clear();
685
Marissa Wall78b72202019-03-15 21:58:34686 cacheBuffers();
687
Robert Carr4cdc58f2017-08-23 21:22:20688 Vector<ComposerState> composerStates;
689 Vector<DisplayState> displayStates;
690 uint32_t flags = 0;
691
692 mForceSynchronous |= synchronous;
693
chaviw8e3fe5d2018-02-22 18:55:42694 for (auto const& kv : mComposerStates){
695 composerStates.add(kv.second);
696 }
697
Robert Carr4cdc58f2017-08-23 21:22:20698 mComposerStates.clear();
699
700 displayStates = mDisplayStates;
701 mDisplayStates.clear();
702
703 if (mForceSynchronous) {
704 flags |= ISurfaceComposer::eSynchronous;
705 }
706 if (mAnimation) {
707 flags |= ISurfaceComposer::eAnimation;
708 }
Dan Stoza84d619e2018-03-29 00:07:36709 if (mEarlyWakeup) {
710 flags |= ISurfaceComposer::eEarlyWakeup;
711 }
Robert Carr4cdc58f2017-08-23 21:22:20712
Ady Abrahambf1349c2020-06-12 21:26:18713 // If both mExplicitEarlyWakeupStart and mExplicitEarlyWakeupEnd are set
714 // it is equivalent for none
715 if (mExplicitEarlyWakeupStart && !mExplicitEarlyWakeupEnd) {
716 flags |= ISurfaceComposer::eExplicitEarlyWakeupStart;
717 }
718 if (mExplicitEarlyWakeupEnd && !mExplicitEarlyWakeupStart) {
719 flags |= ISurfaceComposer::eExplicitEarlyWakeupEnd;
720 }
721
Robert Carr4cdc58f2017-08-23 21:22:20722 mForceSynchronous = false;
723 mAnimation = false;
Dan Stoza84d619e2018-03-29 00:07:36724 mEarlyWakeup = false;
Ady Abrahambf1349c2020-06-12 21:26:18725 mExplicitEarlyWakeupStart = false;
726 mExplicitEarlyWakeupEnd = false;
Robert Carr4cdc58f2017-08-23 21:22:20727
Pablo Gamito7eb7ee72020-08-05 10:57:05728 uint64_t transactionId = mId;
729 mId = generateId();
730
Marissa Wall713b63f2018-10-17 22:42:43731 sp<IBinder> applyToken = IInterface::asBinder(TransactionCompletedListener::getIInstance());
Marissa Wall17b4e452018-12-27 00:32:34732 sf->setTransactionState(composerStates, displayStates, flags, applyToken, mInputWindowCommands,
Marissa Wall78b72202019-03-15 21:58:34733 mDesiredPresentTime,
Marissa Wall3dad52d2019-03-22 21:03:19734 {} /*uncacheBuffer - only set in doUncacheBufferTransaction*/,
Pablo Gamito7eb7ee72020-08-05 10:57:05735 hasListenerCallbacks, listenerCallbacks, transactionId);
chaviw273171b2018-12-26 19:46:30736 mInputWindowCommands.clear();
Robert Carr4cdc58f2017-08-23 21:22:20737 mStatus = NO_ERROR;
738 return NO_ERROR;
Mathias Agopiane57f2922012-08-09 23:29:12739}
740
The Android Open Source Projectedbf3b62009-03-04 03:31:44741// ---------------------------------------------------------------------------
742
Robert Carr4cdc58f2017-08-23 21:22:20743sp<IBinder> SurfaceComposerClient::createDisplay(const String8& displayName, bool secure) {
Jamie Gennisdd3cb842012-10-20 01:19:11744 return ComposerService::getComposerService()->createDisplay(displayName,
745 secure);
Mathias Agopiane57f2922012-08-09 23:29:12746}
747
Robert Carr4cdc58f2017-08-23 21:22:20748void SurfaceComposerClient::destroyDisplay(const sp<IBinder>& display) {
Jesse Hall6c913be2013-08-08 19:15:49749 return ComposerService::getComposerService()->destroyDisplay(display);
750}
751
Dominik Laskowskidcb38bb2019-01-25 10:35:50752std::vector<PhysicalDisplayId> SurfaceComposerClient::getPhysicalDisplayIds() {
753 return ComposerService::getComposerService()->getPhysicalDisplayIds();
754}
755
756std::optional<PhysicalDisplayId> SurfaceComposerClient::getInternalDisplayId() {
757 return ComposerService::getComposerService()->getInternalDisplayId();
758}
759
760sp<IBinder> SurfaceComposerClient::getPhysicalDisplayToken(PhysicalDisplayId displayId) {
761 return ComposerService::getComposerService()->getPhysicalDisplayToken(displayId);
762}
763
764sp<IBinder> SurfaceComposerClient::getInternalDisplayToken() {
765 return ComposerService::getComposerService()->getInternalDisplayToken();
Jeff Brown9d4e3d22012-08-25 03:00:51766}
767
Robert Carr4cdc58f2017-08-23 21:22:20768void SurfaceComposerClient::Transaction::setAnimationTransaction() {
Jamie Gennis2d5e2302012-10-16 01:24:43769 mAnimation = true;
770}
771
Dan Stoza84d619e2018-03-29 00:07:36772void SurfaceComposerClient::Transaction::setEarlyWakeup() {
773 mEarlyWakeup = true;
774}
775
Ady Abrahambf1349c2020-06-12 21:26:18776void SurfaceComposerClient::Transaction::setExplicitEarlyWakeupStart() {
777 mExplicitEarlyWakeupStart = true;
778}
779
780void SurfaceComposerClient::Transaction::setExplicitEarlyWakeupEnd() {
781 mExplicitEarlyWakeupEnd = true;
782}
783
Pablo Gamitodbc31672020-09-01 18:28:58784layer_state_t* SurfaceComposerClient::Transaction::getLayerState(const sp<SurfaceControl>& sc) {
785 auto handle = sc->getHandle();
786
Vishnu Nairf03652d2019-07-17 00:56:56787 if (mComposerStates.count(handle) == 0) {
Mathias Agopian698c0872011-06-29 02:09:31788 // we don't have it, add an initialized layer_state to our list
chaviw8e3fe5d2018-02-22 18:55:42789 ComposerState s;
Pablo Gamitodbc31672020-09-01 18:28:58790
Vishnu Nairf03652d2019-07-17 00:56:56791 s.state.surface = handle;
Pablo Gamitodbc31672020-09-01 18:28:58792 s.state.layerId = sc->getLayerId();
793
Vishnu Nairf03652d2019-07-17 00:56:56794 mComposerStates[handle] = s;
Mathias Agopian698c0872011-06-29 02:09:31795 }
796
Vishnu Nairf03652d2019-07-17 00:56:56797 return &(mComposerStates[handle].state);
Mathias Agopian698c0872011-06-29 02:09:31798}
799
Marissa Wallc837b5e2018-10-12 17:04:44800void SurfaceComposerClient::Transaction::registerSurfaceControlForCallback(
801 const sp<SurfaceControl>& sc) {
Marissa Wall80d94ad2019-01-19 00:04:36802 auto& callbackInfo = mListenerCallbacks[TransactionCompletedListener::getIInstance()];
803 callbackInfo.surfaceControls.insert(sc);
804
805 TransactionCompletedListener::getInstance()
806 ->addSurfaceControlToCallbacks(sc, callbackInfo.callbackIds);
Marissa Wallc837b5e2018-10-12 17:04:44807}
808
Robert Carr4cdc58f2017-08-23 21:22:20809SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setPosition(
810 const sp<SurfaceControl>& sc, float x, float y) {
chaviw763ef572018-02-23 00:04:57811 layer_state_t* s = getLayerState(sc);
Robert Carr4cdc58f2017-08-23 21:22:20812 if (!s) {
813 mStatus = BAD_INDEX;
814 return *this;
815 }
Mathias Agopian3165cc22012-08-09 02:42:09816 s->what |= layer_state_t::ePositionChanged;
Mathias Agopian698c0872011-06-29 02:09:31817 s->x = x;
818 s->y = y;
Marissa Wallc837b5e2018-10-12 17:04:44819
820 registerSurfaceControlForCallback(sc);
Robert Carr4cdc58f2017-08-23 21:22:20821 return *this;
Mathias Agopian698c0872011-06-29 02:09:31822}
823
Robert Carr4cdc58f2017-08-23 21:22:20824SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::show(
825 const sp<SurfaceControl>& sc) {
826 return setFlags(sc, 0, layer_state_t::eLayerHidden);
827}
828
829SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::hide(
830 const sp<SurfaceControl>& sc) {
831 return setFlags(sc, layer_state_t::eLayerHidden, layer_state_t::eLayerHidden);
832}
833
834SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setSize(
835 const sp<SurfaceControl>& sc, uint32_t w, uint32_t h) {
chaviw763ef572018-02-23 00:04:57836 layer_state_t* s = getLayerState(sc);
Robert Carr4cdc58f2017-08-23 21:22:20837 if (!s) {
838 mStatus = BAD_INDEX;
839 return *this;
840 }
Mathias Agopian3165cc22012-08-09 02:42:09841 s->what |= layer_state_t::eSizeChanged;
Mathias Agopian698c0872011-06-29 02:09:31842 s->w = w;
843 s->h = h;
Jamie Gennis28378392011-10-13 00:39:00844
Marissa Wallc837b5e2018-10-12 17:04:44845 registerSurfaceControlForCallback(sc);
Robert Carr4cdc58f2017-08-23 21:22:20846 return *this;
Mathias Agopian698c0872011-06-29 02:09:31847}
848
Robert Carr4cdc58f2017-08-23 21:22:20849SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setLayer(
850 const sp<SurfaceControl>& sc, int32_t z) {
chaviw763ef572018-02-23 00:04:57851 layer_state_t* s = getLayerState(sc);
Robert Carr4cdc58f2017-08-23 21:22:20852 if (!s) {
853 mStatus = BAD_INDEX;
854 return *this;
855 }
Mathias Agopian3165cc22012-08-09 02:42:09856 s->what |= layer_state_t::eLayerChanged;
chaviw32377582019-05-13 18:15:19857 s->what &= ~layer_state_t::eRelativeLayerChanged;
Mathias Agopian698c0872011-06-29 02:09:31858 s->z = z;
Marissa Wallc837b5e2018-10-12 17:04:44859
860 registerSurfaceControlForCallback(sc);
Robert Carr4cdc58f2017-08-23 21:22:20861 return *this;
Mathias Agopian698c0872011-06-29 02:09:31862}
863
Robert Carr4cdc58f2017-08-23 21:22:20864SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setRelativeLayer(const sp<SurfaceControl>& sc, const sp<IBinder>& relativeTo,
Robert Carrdb66e622017-04-10 23:55:57865 int32_t z) {
chaviw763ef572018-02-23 00:04:57866 layer_state_t* s = getLayerState(sc);
Robert Carrdb66e622017-04-10 23:55:57867 if (!s) {
Robert Carr4cdc58f2017-08-23 21:22:20868 mStatus = BAD_INDEX;
Robert Carr30c8d902019-04-04 20:12:49869 return *this;
Robert Carrdb66e622017-04-10 23:55:57870 }
871 s->what |= layer_state_t::eRelativeLayerChanged;
chaviw32377582019-05-13 18:15:19872 s->what &= ~layer_state_t::eLayerChanged;
Robert Carrdb66e622017-04-10 23:55:57873 s->relativeLayerHandle = relativeTo;
874 s->z = z;
Marissa Wallc837b5e2018-10-12 17:04:44875
876 registerSurfaceControlForCallback(sc);
Robert Carr4cdc58f2017-08-23 21:22:20877 return *this;
Robert Carrdb66e622017-04-10 23:55:57878}
879
Robert Carr4cdc58f2017-08-23 21:22:20880SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setFlags(
881 const sp<SurfaceControl>& sc, uint32_t flags,
Mathias Agopian698c0872011-06-29 02:09:31882 uint32_t mask) {
chaviw763ef572018-02-23 00:04:57883 layer_state_t* s = getLayerState(sc);
Robert Carr4cdc58f2017-08-23 21:22:20884 if (!s) {
885 mStatus = BAD_INDEX;
886 return *this;
887 }
chaviwc5676c62020-09-18 22:01:04888 if ((mask & layer_state_t::eLayerOpaque) || (mask & layer_state_t::eLayerHidden) ||
889 (mask & layer_state_t::eLayerSecure) || (mask & layer_state_t::eLayerSkipScreenshot)) {
Dan Stoza23116082015-06-18 21:58:39890 s->what |= layer_state_t::eFlagsChanged;
Andy McFadden4125a4f2014-01-30 01:17:11891 }
Mathias Agopian698c0872011-06-29 02:09:31892 s->flags &= ~mask;
893 s->flags |= (flags & mask);
894 s->mask |= mask;
Marissa Wallc837b5e2018-10-12 17:04:44895
896 registerSurfaceControlForCallback(sc);
Robert Carr4cdc58f2017-08-23 21:22:20897 return *this;
Mathias Agopian698c0872011-06-29 02:09:31898}
899
Robert Carr4cdc58f2017-08-23 21:22:20900SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setTransparentRegionHint(
901 const sp<SurfaceControl>& sc,
Mathias Agopian698c0872011-06-29 02:09:31902 const Region& transparentRegion) {
chaviw763ef572018-02-23 00:04:57903 layer_state_t* s = getLayerState(sc);
Robert Carr4cdc58f2017-08-23 21:22:20904 if (!s) {
905 mStatus = BAD_INDEX;
906 return *this;
907 }
Mathias Agopian3165cc22012-08-09 02:42:09908 s->what |= layer_state_t::eTransparentRegionChanged;
Mathias Agopian698c0872011-06-29 02:09:31909 s->transparentRegion = transparentRegion;
Marissa Wallc837b5e2018-10-12 17:04:44910
911 registerSurfaceControlForCallback(sc);
Robert Carr4cdc58f2017-08-23 21:22:20912 return *this;
Mathias Agopian698c0872011-06-29 02:09:31913}
914
Robert Carr4cdc58f2017-08-23 21:22:20915SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setAlpha(
916 const sp<SurfaceControl>& sc, float alpha) {
chaviw763ef572018-02-23 00:04:57917 layer_state_t* s = getLayerState(sc);
Robert Carr4cdc58f2017-08-23 21:22:20918 if (!s) {
919 mStatus = BAD_INDEX;
920 return *this;
921 }
Mathias Agopian3165cc22012-08-09 02:42:09922 s->what |= layer_state_t::eAlphaChanged;
Mathias Agopian698c0872011-06-29 02:09:31923 s->alpha = alpha;
Marissa Wallc837b5e2018-10-12 17:04:44924
925 registerSurfaceControlForCallback(sc);
Robert Carr4cdc58f2017-08-23 21:22:20926 return *this;
Mathias Agopian698c0872011-06-29 02:09:31927}
928
Robert Carr4cdc58f2017-08-23 21:22:20929SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setLayerStack(
930 const sp<SurfaceControl>& sc, uint32_t layerStack) {
chaviw763ef572018-02-23 00:04:57931 layer_state_t* s = getLayerState(sc);
Robert Carr4cdc58f2017-08-23 21:22:20932 if (!s) {
933 mStatus = BAD_INDEX;
934 return *this;
935 }
Mathias Agopian3165cc22012-08-09 02:42:09936 s->what |= layer_state_t::eLayerStackChanged;
Mathias Agopian87855782012-07-25 04:41:09937 s->layerStack = layerStack;
Marissa Wallc837b5e2018-10-12 17:04:44938
939 registerSurfaceControlForCallback(sc);
Robert Carr4cdc58f2017-08-23 21:22:20940 return *this;
Mathias Agopian87855782012-07-25 04:41:09941}
942
Evan Rosky1f6d6d52018-12-06 18:47:26943SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setMetadata(
Garfield Tan01a56132019-08-05 23:44:21944 const sp<SurfaceControl>& sc, uint32_t key, const Parcel& p) {
Evan Rosky1f6d6d52018-12-06 18:47:26945 layer_state_t* s = getLayerState(sc);
946 if (!s) {
947 mStatus = BAD_INDEX;
948 return *this;
949 }
950 s->what |= layer_state_t::eMetadataChanged;
Garfield Tan01a56132019-08-05 23:44:21951
952 s->metadata.mMap[key] = {p.data(), p.data() + p.dataSize()};
Evan Rosky1f6d6d52018-12-06 18:47:26953
954 registerSurfaceControlForCallback(sc);
955 return *this;
956}
957
Robert Carr4cdc58f2017-08-23 21:22:20958SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setMatrix(
959 const sp<SurfaceControl>& sc, float dsdx, float dtdx,
Robert Carrcb6e1e32017-02-22 03:48:26960 float dtdy, float dsdy) {
chaviw763ef572018-02-23 00:04:57961 layer_state_t* s = getLayerState(sc);
Robert Carr4cdc58f2017-08-23 21:22:20962 if (!s) {
963 mStatus = BAD_INDEX;
964 return *this;
965 }
Mathias Agopian3165cc22012-08-09 02:42:09966 s->what |= layer_state_t::eMatrixChanged;
Mathias Agopian698c0872011-06-29 02:09:31967 layer_state_t::matrix22_t matrix;
968 matrix.dsdx = dsdx;
969 matrix.dtdx = dtdx;
970 matrix.dsdy = dsdy;
971 matrix.dtdy = dtdy;
972 s->matrix = matrix;
Marissa Wallc837b5e2018-10-12 17:04:44973
974 registerSurfaceControlForCallback(sc);
Robert Carr4cdc58f2017-08-23 21:22:20975 return *this;
Mathias Agopian698c0872011-06-29 02:09:31976}
977
Marissa Wallf58c14b2018-07-24 17:50:43978SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setCrop_legacy(
Robert Carr4cdc58f2017-08-23 21:22:20979 const sp<SurfaceControl>& sc, const Rect& crop) {
chaviw763ef572018-02-23 00:04:57980 layer_state_t* s = getLayerState(sc);
Robert Carr4cdc58f2017-08-23 21:22:20981 if (!s) {
982 mStatus = BAD_INDEX;
983 return *this;
984 }
Marissa Wallf58c14b2018-07-24 17:50:43985 s->what |= layer_state_t::eCropChanged_legacy;
986 s->crop_legacy = crop;
Marissa Wallc837b5e2018-10-12 17:04:44987
988 registerSurfaceControlForCallback(sc);
Robert Carr4cdc58f2017-08-23 21:22:20989 return *this;
Jamie Gennisf15a83f2012-05-11 03:43:55990}
991
Lucas Dupin1b6531c2018-07-06 00:18:21992SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setCornerRadius(
993 const sp<SurfaceControl>& sc, float cornerRadius) {
994 layer_state_t* s = getLayerState(sc);
995 if (!s) {
996 mStatus = BAD_INDEX;
997 return *this;
998 }
999 s->what |= layer_state_t::eCornerRadiusChanged;
1000 s->cornerRadius = cornerRadius;
1001 return *this;
1002}
1003
Lucas Dupin19c8f0e2019-11-26 01:55:441004SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setBackgroundBlurRadius(
1005 const sp<SurfaceControl>& sc, int backgroundBlurRadius) {
1006 layer_state_t* s = getLayerState(sc);
1007 if (!s) {
1008 mStatus = BAD_INDEX;
1009 return *this;
1010 }
1011 s->what |= layer_state_t::eBackgroundBlurRadiusChanged;
1012 s->backgroundBlurRadius = backgroundBlurRadius;
1013 return *this;
1014}
1015
Marissa Wallf58c14b2018-07-24 17:50:431016SurfaceComposerClient::Transaction&
1017SurfaceComposerClient::Transaction::deferTransactionUntil_legacy(const sp<SurfaceControl>& sc,
1018 const sp<IBinder>& handle,
1019 uint64_t frameNumber) {
chaviw763ef572018-02-23 00:04:571020 layer_state_t* s = getLayerState(sc);
Dan Stoza7dde5992015-05-22 16:51:441021 if (!s) {
Robert Carr4cdc58f2017-08-23 21:22:201022 mStatus = BAD_INDEX;
1023 return *this;
Dan Stoza7dde5992015-05-22 16:51:441024 }
Marissa Wallf58c14b2018-07-24 17:50:431025 s->what |= layer_state_t::eDeferTransaction_legacy;
1026 s->barrierHandle_legacy = handle;
1027 s->frameNumber_legacy = frameNumber;
Marissa Wallc837b5e2018-10-12 17:04:441028
1029 registerSurfaceControlForCallback(sc);
Robert Carr4cdc58f2017-08-23 21:22:201030 return *this;
Robert Carr0d480722017-01-11 00:42:541031}
1032
Marissa Wallf58c14b2018-07-24 17:50:431033SurfaceComposerClient::Transaction&
1034SurfaceComposerClient::Transaction::deferTransactionUntil_legacy(const sp<SurfaceControl>& sc,
1035 const sp<Surface>& barrierSurface,
1036 uint64_t frameNumber) {
chaviw763ef572018-02-23 00:04:571037 layer_state_t* s = getLayerState(sc);
Robert Carr0d480722017-01-11 00:42:541038 if (!s) {
Robert Carr4cdc58f2017-08-23 21:22:201039 mStatus = BAD_INDEX;
1040 return *this;
Robert Carr0d480722017-01-11 00:42:541041 }
Marissa Wallf58c14b2018-07-24 17:50:431042 s->what |= layer_state_t::eDeferTransaction_legacy;
1043 s->barrierGbp_legacy = barrierSurface->getIGraphicBufferProducer();
1044 s->frameNumber_legacy = frameNumber;
Marissa Wallc837b5e2018-10-12 17:04:441045
1046 registerSurfaceControlForCallback(sc);
Robert Carr4cdc58f2017-08-23 21:22:201047 return *this;
Dan Stoza7dde5992015-05-22 16:51:441048}
1049
Robert Carr4cdc58f2017-08-23 21:22:201050SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::reparentChildren(
1051 const sp<SurfaceControl>& sc,
Robert Carr1db73f62016-12-21 20:58:511052 const sp<IBinder>& newParentHandle) {
chaviw763ef572018-02-23 00:04:571053 layer_state_t* s = getLayerState(sc);
Robert Carr1db73f62016-12-21 20:58:511054 if (!s) {
Robert Carr4cdc58f2017-08-23 21:22:201055 mStatus = BAD_INDEX;
1056 return *this;
Robert Carr1db73f62016-12-21 20:58:511057 }
1058 s->what |= layer_state_t::eReparentChildren;
1059 s->reparentHandle = newParentHandle;
Marissa Wallc837b5e2018-10-12 17:04:441060
1061 registerSurfaceControlForCallback(sc);
Robert Carr4cdc58f2017-08-23 21:22:201062 return *this;
Robert Carr1db73f62016-12-21 20:58:511063}
1064
Robert Carr4cdc58f2017-08-23 21:22:201065SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::reparent(
1066 const sp<SurfaceControl>& sc,
chaviwf1961f72017-09-18 23:41:071067 const sp<IBinder>& newParentHandle) {
chaviw763ef572018-02-23 00:04:571068 layer_state_t* s = getLayerState(sc);
chaviw06178942017-07-27 17:25:591069 if (!s) {
Robert Carr4cdc58f2017-08-23 21:22:201070 mStatus = BAD_INDEX;
1071 return *this;
chaviw06178942017-07-27 17:25:591072 }
chaviwf1961f72017-09-18 23:41:071073 s->what |= layer_state_t::eReparent;
chaviw06178942017-07-27 17:25:591074 s->parentHandleForChild = newParentHandle;
Marissa Wallc837b5e2018-10-12 17:04:441075
1076 registerSurfaceControlForCallback(sc);
Robert Carr4cdc58f2017-08-23 21:22:201077 return *this;
chaviw06178942017-07-27 17:25:591078}
1079
Robert Carr4cdc58f2017-08-23 21:22:201080SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setColor(
1081 const sp<SurfaceControl>& sc,
1082 const half3& color) {
chaviw763ef572018-02-23 00:04:571083 layer_state_t* s = getLayerState(sc);
Robert Carr9524cb32017-02-13 19:32:321084 if (!s) {
Robert Carr4cdc58f2017-08-23 21:22:201085 mStatus = BAD_INDEX;
1086 return *this;
1087 }
1088 s->what |= layer_state_t::eColorChanged;
1089 s->color = color;
Marissa Wallc837b5e2018-10-12 17:04:441090
1091 registerSurfaceControlForCallback(sc);
Robert Carr4cdc58f2017-08-23 21:22:201092 return *this;
1093}
1094
Valerie Haudd0b7572019-01-29 22:59:271095SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setBackgroundColor(
1096 const sp<SurfaceControl>& sc, const half3& color, float alpha, ui::Dataspace dataspace) {
Valerie Haued54efa2019-01-12 04:03:141097 layer_state_t* s = getLayerState(sc);
1098 if (!s) {
1099 mStatus = BAD_INDEX;
1100 return *this;
1101 }
1102
Valerie Haudd0b7572019-01-29 22:59:271103 s->what |= layer_state_t::eBackgroundColorChanged;
1104 s->color = color;
1105 s->bgColorAlpha = alpha;
1106 s->bgColorDataspace = dataspace;
Valerie Haued54efa2019-01-12 04:03:141107
1108 registerSurfaceControlForCallback(sc);
1109 return *this;
1110}
1111
Marissa Wall61c58622018-07-18 17:12:201112SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setTransform(
1113 const sp<SurfaceControl>& sc, uint32_t transform) {
1114 layer_state_t* s = getLayerState(sc);
1115 if (!s) {
1116 mStatus = BAD_INDEX;
1117 return *this;
1118 }
1119 s->what |= layer_state_t::eTransformChanged;
1120 s->transform = transform;
Marissa Wallc837b5e2018-10-12 17:04:441121
1122 registerSurfaceControlForCallback(sc);
Marissa Wall61c58622018-07-18 17:12:201123 return *this;
1124}
1125
1126SurfaceComposerClient::Transaction&
1127SurfaceComposerClient::Transaction::setTransformToDisplayInverse(const sp<SurfaceControl>& sc,
1128 bool transformToDisplayInverse) {
1129 layer_state_t* s = getLayerState(sc);
1130 if (!s) {
1131 mStatus = BAD_INDEX;
1132 return *this;
1133 }
1134 s->what |= layer_state_t::eTransformToDisplayInverseChanged;
1135 s->transformToDisplayInverse = transformToDisplayInverse;
Marissa Wallc837b5e2018-10-12 17:04:441136
1137 registerSurfaceControlForCallback(sc);
Marissa Wall61c58622018-07-18 17:12:201138 return *this;
1139}
1140
1141SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setCrop(
1142 const sp<SurfaceControl>& sc, const Rect& crop) {
1143 layer_state_t* s = getLayerState(sc);
1144 if (!s) {
1145 mStatus = BAD_INDEX;
1146 return *this;
1147 }
1148 s->what |= layer_state_t::eCropChanged;
1149 s->crop = crop;
Marissa Wallc837b5e2018-10-12 17:04:441150
1151 registerSurfaceControlForCallback(sc);
Marissa Wall61c58622018-07-18 17:12:201152 return *this;
1153}
1154
Marissa Wall861616d2018-10-22 19:52:231155SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setFrame(
1156 const sp<SurfaceControl>& sc, const Rect& frame) {
1157 layer_state_t* s = getLayerState(sc);
1158 if (!s) {
1159 mStatus = BAD_INDEX;
1160 return *this;
1161 }
1162 s->what |= layer_state_t::eFrameChanged;
Marin Shalamanov6ad317c2020-07-29 21:34:071163 s->orientedDisplaySpaceRect = frame;
Marissa Wall861616d2018-10-22 19:52:231164
1165 registerSurfaceControlForCallback(sc);
1166 return *this;
1167}
1168
Marissa Wall61c58622018-07-18 17:12:201169SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setBuffer(
1170 const sp<SurfaceControl>& sc, const sp<GraphicBuffer>& buffer) {
1171 layer_state_t* s = getLayerState(sc);
1172 if (!s) {
1173 mStatus = BAD_INDEX;
1174 return *this;
1175 }
Marissa Wall78b72202019-03-15 21:58:341176 s->what |= layer_state_t::eBufferChanged;
1177 s->buffer = buffer;
Marissa Wallebc2c052019-01-17 03:16:551178
1179 registerSurfaceControlForCallback(sc);
Marissa Wall78b72202019-03-15 21:58:341180
1181 mContainsBuffer = true;
Marissa Wallebc2c052019-01-17 03:16:551182 return *this;
1183}
1184
Marissa Wall61c58622018-07-18 17:12:201185SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setAcquireFence(
1186 const sp<SurfaceControl>& sc, const sp<Fence>& fence) {
1187 layer_state_t* s = getLayerState(sc);
1188 if (!s) {
1189 mStatus = BAD_INDEX;
1190 return *this;
1191 }
1192 s->what |= layer_state_t::eAcquireFenceChanged;
1193 s->acquireFence = fence;
Marissa Wallc837b5e2018-10-12 17:04:441194
1195 registerSurfaceControlForCallback(sc);
Marissa Wall61c58622018-07-18 17:12:201196 return *this;
1197}
1198
1199SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setDataspace(
1200 const sp<SurfaceControl>& sc, ui::Dataspace dataspace) {
1201 layer_state_t* s = getLayerState(sc);
1202 if (!s) {
1203 mStatus = BAD_INDEX;
1204 return *this;
1205 }
1206 s->what |= layer_state_t::eDataspaceChanged;
1207 s->dataspace = dataspace;
Marissa Wallc837b5e2018-10-12 17:04:441208
1209 registerSurfaceControlForCallback(sc);
Marissa Wall61c58622018-07-18 17:12:201210 return *this;
1211}
1212
1213SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setHdrMetadata(
1214 const sp<SurfaceControl>& sc, const HdrMetadata& hdrMetadata) {
1215 layer_state_t* s = getLayerState(sc);
1216 if (!s) {
1217 mStatus = BAD_INDEX;
1218 return *this;
1219 }
1220 s->what |= layer_state_t::eHdrMetadataChanged;
1221 s->hdrMetadata = hdrMetadata;
Marissa Wallc837b5e2018-10-12 17:04:441222
1223 registerSurfaceControlForCallback(sc);
Marissa Wall61c58622018-07-18 17:12:201224 return *this;
1225}
1226
1227SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setSurfaceDamageRegion(
1228 const sp<SurfaceControl>& sc, const Region& surfaceDamageRegion) {
1229 layer_state_t* s = getLayerState(sc);
1230 if (!s) {
1231 mStatus = BAD_INDEX;
1232 return *this;
1233 }
1234 s->what |= layer_state_t::eSurfaceDamageRegionChanged;
1235 s->surfaceDamageRegion = surfaceDamageRegion;
Marissa Wallc837b5e2018-10-12 17:04:441236
1237 registerSurfaceControlForCallback(sc);
Marissa Wall61c58622018-07-18 17:12:201238 return *this;
1239}
1240
1241SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setApi(
1242 const sp<SurfaceControl>& sc, int32_t api) {
1243 layer_state_t* s = getLayerState(sc);
1244 if (!s) {
1245 mStatus = BAD_INDEX;
1246 return *this;
1247 }
1248 s->what |= layer_state_t::eApiChanged;
1249 s->api = api;
Marissa Wallc837b5e2018-10-12 17:04:441250
1251 registerSurfaceControlForCallback(sc);
Marissa Wall61c58622018-07-18 17:12:201252 return *this;
1253}
1254
1255SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setSidebandStream(
1256 const sp<SurfaceControl>& sc, const sp<NativeHandle>& sidebandStream) {
1257 layer_state_t* s = getLayerState(sc);
1258 if (!s) {
1259 mStatus = BAD_INDEX;
1260 return *this;
1261 }
1262 s->what |= layer_state_t::eSidebandStreamChanged;
1263 s->sidebandStream = sidebandStream;
Marissa Wallc837b5e2018-10-12 17:04:441264
1265 registerSurfaceControlForCallback(sc);
1266 return *this;
1267}
1268
Marissa Wall17b4e452018-12-27 00:32:341269SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setDesiredPresentTime(
1270 nsecs_t desiredPresentTime) {
1271 mDesiredPresentTime = desiredPresentTime;
1272 return *this;
1273}
1274
Peiyong Linc502cb72019-03-01 23:00:231275SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setColorSpaceAgnostic(
1276 const sp<SurfaceControl>& sc, const bool agnostic) {
1277 layer_state_t* s = getLayerState(sc);
1278 if (!s) {
1279 mStatus = BAD_INDEX;
1280 return *this;
1281 }
1282 s->what |= layer_state_t::eColorSpaceAgnosticChanged;
1283 s->colorSpaceAgnostic = agnostic;
1284
1285 registerSurfaceControlForCallback(sc);
1286 return *this;
1287}
1288
Marissa Wallc837b5e2018-10-12 17:04:441289SurfaceComposerClient::Transaction&
Ana Krulecc84d09b2019-11-02 22:10:291290SurfaceComposerClient::Transaction::setFrameRateSelectionPriority(const sp<SurfaceControl>& sc,
1291 int32_t priority) {
1292 layer_state_t* s = getLayerState(sc);
1293 if (!s) {
1294 mStatus = BAD_INDEX;
1295 return *this;
1296 }
1297
1298 s->what |= layer_state_t::eFrameRateSelectionPriority;
1299 s->frameRateSelectionPriority = priority;
1300
1301 registerSurfaceControlForCallback(sc);
1302 return *this;
1303}
1304
1305SurfaceComposerClient::Transaction&
Marissa Wallc837b5e2018-10-12 17:04:441306SurfaceComposerClient::Transaction::addTransactionCompletedCallback(
Marissa Walle2ffb422018-10-12 18:33:521307 TransactionCompletedCallbackTakesContext callback, void* callbackContext) {
Marissa Wallc837b5e2018-10-12 17:04:441308 auto listener = TransactionCompletedListener::getInstance();
1309
Marissa Wall80d94ad2019-01-19 00:04:361310 auto callbackWithContext = std::bind(callback, callbackContext, std::placeholders::_1,
1311 std::placeholders::_2, std::placeholders::_3);
1312 const auto& surfaceControls =
1313 mListenerCallbacks[TransactionCompletedListener::getIInstance()].surfaceControls;
Marissa Wallc837b5e2018-10-12 17:04:441314
Marissa Wall80d94ad2019-01-19 00:04:361315 CallbackId callbackId = listener->addCallbackFunction(callbackWithContext, surfaceControls);
Marissa Wallc837b5e2018-10-12 17:04:441316
1317 mListenerCallbacks[TransactionCompletedListener::getIInstance()].callbackIds.emplace(
1318 callbackId);
Marissa Wall61c58622018-07-18 17:12:201319 return *this;
1320}
1321
Valerie Hau871d6352020-01-29 16:44:021322SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::notifyProducerDisconnect(
1323 const sp<SurfaceControl>& sc) {
1324 layer_state_t* s = getLayerState(sc);
1325 if (!s) {
1326 mStatus = BAD_INDEX;
1327 return *this;
1328 }
1329
1330 s->what |= layer_state_t::eProducerDisconnect;
1331 return *this;
1332}
1333
Robert Carr4cdc58f2017-08-23 21:22:201334SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::detachChildren(
1335 const sp<SurfaceControl>& sc) {
chaviw763ef572018-02-23 00:04:571336 layer_state_t* s = getLayerState(sc);
Robert Carr4cdc58f2017-08-23 21:22:201337 if (!s) {
1338 mStatus = BAD_INDEX;
Greg Kaiserd45fdc32019-04-30 13:14:191339 return *this;
Robert Carr9524cb32017-02-13 19:32:321340 }
1341 s->what |= layer_state_t::eDetachChildren;
Marissa Wallc837b5e2018-10-12 17:04:441342
1343 registerSurfaceControlForCallback(sc);
Robert Carr4cdc58f2017-08-23 21:22:201344 return *this;
Robert Carr9524cb32017-02-13 19:32:321345}
1346
Robert Carr4cdc58f2017-08-23 21:22:201347SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setOverrideScalingMode(
1348 const sp<SurfaceControl>& sc, int32_t overrideScalingMode) {
chaviw763ef572018-02-23 00:04:571349 layer_state_t* s = getLayerState(sc);
Robert Carrc3574f72016-03-24 19:19:321350 if (!s) {
Robert Carr4cdc58f2017-08-23 21:22:201351 mStatus = BAD_INDEX;
1352 return *this;
Robert Carrc3574f72016-03-24 19:19:321353 }
1354
1355 switch (overrideScalingMode) {
1356 case NATIVE_WINDOW_SCALING_MODE_FREEZE:
1357 case NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW:
1358 case NATIVE_WINDOW_SCALING_MODE_SCALE_CROP:
1359 case NATIVE_WINDOW_SCALING_MODE_NO_SCALE_CROP:
1360 case -1:
1361 break;
1362 default:
1363 ALOGE("unknown scaling mode: %d",
1364 overrideScalingMode);
Robert Carr4cdc58f2017-08-23 21:22:201365 mStatus = BAD_VALUE;
1366 return *this;
Robert Carrc3574f72016-03-24 19:19:321367 }
1368
1369 s->what |= layer_state_t::eOverrideScalingModeChanged;
1370 s->overrideScalingMode = overrideScalingMode;
Marissa Wallc837b5e2018-10-12 17:04:441371
1372 registerSurfaceControlForCallback(sc);
Robert Carr4cdc58f2017-08-23 21:22:201373 return *this;
Robert Carrc3574f72016-03-24 19:19:321374}
1375
Robert Carr2c358bf2018-08-08 22:58:151376#ifndef NO_INPUT
1377SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setInputWindowInfo(
1378 const sp<SurfaceControl>& sc,
1379 const InputWindowInfo& info) {
1380 layer_state_t* s = getLayerState(sc);
1381 if (!s) {
1382 mStatus = BAD_INDEX;
1383 return *this;
1384 }
Chris Ye0783e992020-06-03 04:34:491385 s->inputHandle = new InputWindowHandle(info);
Robert Carr2c358bf2018-08-08 22:58:151386 s->what |= layer_state_t::eInputInfoChanged;
1387 return *this;
1388}
chaviw273171b2018-12-26 19:46:301389
Vishnu Naire798b472020-07-23 20:52:211390SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setFocusedWindow(
Vishnu Nair958da932020-08-22 00:12:371391 const sp<IBinder>& token, const sp<IBinder>& focusedToken, nsecs_t timestampNanos,
1392 int32_t displayId) {
Vishnu Naire798b472020-07-23 20:52:211393 FocusRequest request;
1394 request.token = token;
1395 request.focusedToken = focusedToken;
1396 request.timestamp = timestampNanos;
Vishnu Nair958da932020-08-22 00:12:371397 request.displayId = displayId;
Vishnu Naire798b472020-07-23 20:52:211398 return setFocusedWindow(request);
1399}
1400
1401SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setFocusedWindow(
1402 const FocusRequest& request) {
1403 mInputWindowCommands.focusRequests.push_back(request);
1404 return *this;
1405}
1406
chaviwa911b102019-02-14 18:18:331407SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::syncInputWindows() {
1408 mInputWindowCommands.syncInputWindows = true;
1409 return *this;
1410}
1411
Robert Carr2c358bf2018-08-08 22:58:151412#endif
1413
Peiyong Lind3788632018-09-18 23:01:311414SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setColorTransform(
1415 const sp<SurfaceControl>& sc, const mat3& matrix, const vec3& translation) {
1416 layer_state_t* s = getLayerState(sc);
1417 if (!s) {
1418 mStatus = BAD_INDEX;
1419 return *this;
1420 }
1421 s->what |= layer_state_t::eColorTransformChanged;
1422 s->colorTransform = mat4(matrix, translation);
Marissa Wallc837b5e2018-10-12 17:04:441423
1424 registerSurfaceControlForCallback(sc);
Peiyong Lind3788632018-09-18 23:01:311425 return *this;
1426}
1427
Robert Carrfb4d58b2019-01-15 17:21:271428SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setGeometry(
1429 const sp<SurfaceControl>& sc, const Rect& source, const Rect& dst, int transform) {
1430 setCrop_legacy(sc, source);
1431
1432 int x = dst.left;
1433 int y = dst.top;
Robert Carr66365e42019-04-08 23:58:041434
1435 float sourceWidth = source.getWidth();
1436 float sourceHeight = source.getHeight();
1437
1438 float xScale = sourceWidth < 0 ? 1.0f : dst.getWidth() / sourceWidth;
1439 float yScale = sourceHeight < 0 ? 1.0f : dst.getHeight() / sourceHeight;
Robert Carrfb4d58b2019-01-15 17:21:271440 float matrix[4] = {1, 0, 0, 1};
1441
1442 switch (transform) {
1443 case NATIVE_WINDOW_TRANSFORM_FLIP_H:
1444 matrix[0] = -xScale; matrix[1] = 0;
1445 matrix[2] = 0; matrix[3] = yScale;
1446 x += source.getWidth();
1447 break;
1448 case NATIVE_WINDOW_TRANSFORM_FLIP_V:
1449 matrix[0] = xScale; matrix[1] = 0;
1450 matrix[2] = 0; matrix[3] = -yScale;
1451 y += source.getHeight();
1452 break;
1453 case NATIVE_WINDOW_TRANSFORM_ROT_90:
1454 matrix[0] = 0; matrix[1] = -yScale;
1455 matrix[2] = xScale; matrix[3] = 0;
1456 x += source.getHeight();
1457 break;
1458 case NATIVE_WINDOW_TRANSFORM_ROT_180:
1459 matrix[0] = -xScale; matrix[1] = 0;
1460 matrix[2] = 0; matrix[3] = -yScale;
1461 x += source.getWidth();
1462 y += source.getHeight();
1463 break;
1464 case NATIVE_WINDOW_TRANSFORM_ROT_270:
1465 matrix[0] = 0; matrix[1] = yScale;
1466 matrix[2] = -xScale; matrix[3] = 0;
1467 y += source.getWidth();
1468 break;
1469 default:
1470 matrix[0] = xScale; matrix[1] = 0;
1471 matrix[2] = 0; matrix[3] = yScale;
1472 break;
1473 }
1474 setMatrix(sc, matrix[0], matrix[1], matrix[2], matrix[3]);
chaviw76f5f2f2019-09-23 17:15:511475 float offsetX = xScale * source.left;
1476 float offsetY = yScale * source.top;
1477 setPosition(sc, x - offsetX, y - offsetY);
Robert Carrfb4d58b2019-01-15 17:21:271478
1479 return *this;
1480}
1481
Vishnu Nairc97b8db2019-10-30 01:19:351482SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setShadowRadius(
1483 const sp<SurfaceControl>& sc, float shadowRadius) {
1484 layer_state_t* s = getLayerState(sc);
1485 if (!s) {
1486 mStatus = BAD_INDEX;
1487 return *this;
1488 }
1489 s->what |= layer_state_t::eShadowRadiusChanged;
1490 s->shadowRadius = shadowRadius;
1491 return *this;
1492}
1493
Steven Thomas3172e202020-01-07 03:25:301494SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setFrameRate(
Steven Thomas62a4cf82020-01-31 20:04:031495 const sp<SurfaceControl>& sc, float frameRate, int8_t compatibility) {
Steven Thomas3172e202020-01-07 03:25:301496 layer_state_t* s = getLayerState(sc);
1497 if (!s) {
1498 mStatus = BAD_INDEX;
1499 return *this;
1500 }
Steven Thomas62a4cf82020-01-31 20:04:031501 if (!ValidateFrameRate(frameRate, compatibility, "Transaction::setFrameRate")) {
1502 mStatus = BAD_VALUE;
1503 return *this;
1504 }
Steven Thomas3172e202020-01-07 03:25:301505 s->what |= layer_state_t::eFrameRateChanged;
1506 s->frameRate = frameRate;
Steven Thomas62a4cf82020-01-31 20:04:031507 s->frameRateCompatibility = compatibility;
Steven Thomas3172e202020-01-07 03:25:301508 return *this;
1509}
1510
Vishnu Nair6213bd92020-05-09 00:42:251511SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setFixedTransformHint(
1512 const sp<SurfaceControl>& sc, int32_t fixedTransformHint) {
1513 layer_state_t* s = getLayerState(sc);
1514 if (!s) {
1515 mStatus = BAD_INDEX;
1516 return *this;
1517 }
1518
1519 const ui::Transform::RotationFlags transform = fixedTransformHint == -1
1520 ? ui::Transform::ROT_INVALID
1521 : ui::Transform::toRotationFlags(static_cast<ui::Rotation>(fixedTransformHint));
1522 s->what |= layer_state_t::eFixedTransformHintChanged;
1523 s->fixedTransformHint = transform;
1524 return *this;
1525}
1526
Mathias Agopian698c0872011-06-29 02:09:311527// ---------------------------------------------------------------------------
1528
chaviw763ef572018-02-23 00:04:571529DisplayState& SurfaceComposerClient::Transaction::getDisplayState(const sp<IBinder>& token) {
Mathias Agopiane57f2922012-08-09 23:29:121530 DisplayState s;
1531 s.token = token;
1532 ssize_t index = mDisplayStates.indexOf(s);
1533 if (index < 0) {
1534 // we don't have it, add an initialized layer_state to our list
1535 s.what = 0;
1536 index = mDisplayStates.add(s);
1537 }
Dan Stozad723bd72014-11-18 18:24:031538 return mDisplayStates.editItemAt(static_cast<size_t>(index));
Mathias Agopiane57f2922012-08-09 23:29:121539}
1540
Robert Carr4cdc58f2017-08-23 21:22:201541status_t SurfaceComposerClient::Transaction::setDisplaySurface(const sp<IBinder>& token,
1542 const sp<IGraphicBufferProducer>& bufferProducer) {
Pablo Ceballoseddbef82016-09-01 18:21:211543 if (bufferProducer.get() != nullptr) {
1544 // Make sure that composition can never be stalled by a virtual display
1545 // consumer that isn't processing buffers fast enough.
1546 status_t err = bufferProducer->setAsyncMode(true);
1547 if (err != NO_ERROR) {
1548 ALOGE("Composer::setDisplaySurface Failed to enable async mode on the "
1549 "BufferQueue. This BufferQueue cannot be used for virtual "
1550 "display. (%d)", err);
1551 return err;
1552 }
Pablo Ceballos1aad24c2016-08-04 17:24:221553 }
chaviw763ef572018-02-23 00:04:571554 DisplayState& s(getDisplayState(token));
Andy McFadden2adaf042012-12-18 17:49:451555 s.surface = bufferProducer;
Mathias Agopiane57f2922012-08-09 23:29:121556 s.what |= DisplayState::eSurfaceChanged;
Pablo Ceballos1aad24c2016-08-04 17:24:221557 return NO_ERROR;
Mathias Agopiane57f2922012-08-09 23:29:121558}
1559
Robert Carr4cdc58f2017-08-23 21:22:201560void SurfaceComposerClient::Transaction::setDisplayLayerStack(const sp<IBinder>& token,
Mathias Agopiane57f2922012-08-09 23:29:121561 uint32_t layerStack) {
chaviw763ef572018-02-23 00:04:571562 DisplayState& s(getDisplayState(token));
Mathias Agopiane57f2922012-08-09 23:29:121563 s.layerStack = layerStack;
1564 s.what |= DisplayState::eLayerStackChanged;
1565}
1566
Robert Carr4cdc58f2017-08-23 21:22:201567void SurfaceComposerClient::Transaction::setDisplayProjection(const sp<IBinder>& token,
Dominik Laskowski718f9602019-11-10 04:01:351568 ui::Rotation orientation,
1569 const Rect& layerStackRect,
1570 const Rect& displayRect) {
chaviw763ef572018-02-23 00:04:571571 DisplayState& s(getDisplayState(token));
Mathias Agopiane57f2922012-08-09 23:29:121572 s.orientation = orientation;
Marin Shalamanov6ad317c2020-07-29 21:34:071573 s.layerStackSpaceRect = layerStackRect;
1574 s.orientedDisplaySpaceRect = displayRect;
Mathias Agopian00e8c7a2012-09-05 02:30:461575 s.what |= DisplayState::eDisplayProjectionChanged;
Jorim Jaggi092123c2016-04-13 01:40:351576 mForceSynchronous = true; // TODO: do we actually still need this?
Mathias Agopiane57f2922012-08-09 23:29:121577}
1578
Robert Carr4cdc58f2017-08-23 21:22:201579void SurfaceComposerClient::Transaction::setDisplaySize(const sp<IBinder>& token, uint32_t width, uint32_t height) {
chaviw763ef572018-02-23 00:04:571580 DisplayState& s(getDisplayState(token));
Michael Wright1f6078a2014-06-26 23:01:021581 s.width = width;
1582 s.height = height;
1583 s.what |= DisplayState::eDisplaySizeChanged;
1584}
1585
Mathias Agopiane57f2922012-08-09 23:29:121586// ---------------------------------------------------------------------------
1587
The Android Open Source Projectedbf3b62009-03-04 03:31:441588SurfaceComposerClient::SurfaceComposerClient()
Robert Carr4cdc58f2017-08-23 21:22:201589 : mStatus(NO_INIT)
The Android Open Source Projectedbf3b62009-03-04 03:31:441590{
The Android Open Source Projectedbf3b62009-03-04 03:31:441591}
1592
Jorim Jaggif3cf4bc2017-11-30 13:19:231593SurfaceComposerClient::SurfaceComposerClient(const sp<ISurfaceComposerClient>& client)
1594 : mStatus(NO_ERROR), mClient(client)
1595{
1596}
1597
Mathias Agopian698c0872011-06-29 02:09:311598void SurfaceComposerClient::onFirstRef() {
Robert Carr4cdc58f2017-08-23 21:22:201599 sp<ISurfaceComposer> sf(ComposerService::getComposerService());
Yi Kong48a619f2018-06-05 23:34:591600 if (sf != nullptr && mStatus == NO_INIT) {
Robert Carr1db73f62016-12-21 20:58:511601 sp<ISurfaceComposerClient> conn;
Robert Carrb89ea9d2018-12-10 21:01:141602 conn = sf->createConnection();
Yi Kong48a619f2018-06-05 23:34:591603 if (conn != nullptr) {
Mathias Agopiand4784a32010-05-28 02:41:151604 mClient = conn;
Mathias Agopiand4784a32010-05-28 02:41:151605 mStatus = NO_ERROR;
1606 }
1607 }
The Android Open Source Projectedbf3b62009-03-04 03:31:441608}
1609
Mathias Agopian698c0872011-06-29 02:09:311610SurfaceComposerClient::~SurfaceComposerClient() {
Mathias Agopian631f3582010-05-26 00:51:341611 dispose();
1612}
Mathias Agopiandd3423c2009-09-23 22:44:051613
Mathias Agopian698c0872011-06-29 02:09:311614status_t SurfaceComposerClient::initCheck() const {
The Android Open Source Projectedbf3b62009-03-04 03:31:441615 return mStatus;
1616}
1617
Mathias Agopian698c0872011-06-29 02:09:311618sp<IBinder> SurfaceComposerClient::connection() const {
Marco Nelissen2ea926b2014-11-14 16:01:011619 return IInterface::asBinder(mClient);
The Android Open Source Projectedbf3b62009-03-04 03:31:441620}
1621
Mathias Agopiand4784a32010-05-28 02:41:151622status_t SurfaceComposerClient::linkToComposerDeath(
1623 const sp<IBinder::DeathRecipient>& recipient,
Mathias Agopian698c0872011-06-29 02:09:311624 void* cookie, uint32_t flags) {
Robert Carr4cdc58f2017-08-23 21:22:201625 sp<ISurfaceComposer> sf(ComposerService::getComposerService());
1626 return IInterface::asBinder(sf)->linkToDeath(recipient, cookie, flags);
The Android Open Source Projectedbf3b62009-03-04 03:31:441627}
1628
Mathias Agopian698c0872011-06-29 02:09:311629void SurfaceComposerClient::dispose() {
The Android Open Source Projectedbf3b62009-03-04 03:31:441630 // this can be called more than once.
Mathias Agopian7e27f052010-05-28 21:22:231631 sp<ISurfaceComposerClient> client;
Mathias Agopiand4784a32010-05-28 02:41:151632 Mutex::Autolock _lm(mLock);
Yi Kong48a619f2018-06-05 23:34:591633 if (mClient != nullptr) {
Mathias Agopiand4784a32010-05-28 02:41:151634 client = mClient; // hold ref while lock is held
1635 mClient.clear();
The Android Open Source Projectedbf3b62009-03-04 03:31:441636 }
Mathias Agopiand4784a32010-05-28 02:41:151637 mStatus = NO_INIT;
The Android Open Source Projectedbf3b62009-03-04 03:31:441638}
1639
Evan Rosky1f6d6d52018-12-06 18:47:261640sp<SurfaceControl> SurfaceComposerClient::createSurface(const String8& name, uint32_t w, uint32_t h,
1641 PixelFormat format, uint32_t flags,
1642 SurfaceControl* parent,
Valerie Hau1acd6962019-10-28 23:35:481643 LayerMetadata metadata,
1644 uint32_t* outTransformHint) {
Robert Carr3b382ed2018-03-14 20:49:411645 sp<SurfaceControl> s;
Valerie Hau1acd6962019-10-28 23:35:481646 createSurfaceChecked(name, w, h, format, &s, flags, parent, std::move(metadata),
1647 outTransformHint);
Robert Carr3b382ed2018-03-14 20:49:411648 return s;
1649}
1650
Marissa Wall35187b32019-01-08 18:08:521651sp<SurfaceControl> SurfaceComposerClient::createWithSurfaceParent(const String8& name, uint32_t w,
1652 uint32_t h, PixelFormat format,
1653 uint32_t flags, Surface* parent,
Valerie Hau1acd6962019-10-28 23:35:481654 LayerMetadata metadata,
1655 uint32_t* outTransformHint) {
Marissa Wall35187b32019-01-08 18:08:521656 sp<SurfaceControl> sur;
1657 status_t err = mStatus;
1658
1659 if (mStatus == NO_ERROR) {
1660 sp<IBinder> handle;
1661 sp<IGraphicBufferProducer> parentGbp = parent->getIGraphicBufferProducer();
1662 sp<IGraphicBufferProducer> gbp;
1663
Valerie Hau1acd6962019-10-28 23:35:481664 uint32_t transformHint = 0;
Pablo Gamito2ec1f7b2020-09-01 14:18:491665 int32_t id = -1;
Evan Rosky1f6d6d52018-12-06 18:47:261666 err = mClient->createWithSurfaceParent(name, w, h, format, flags, parentGbp,
Pablo Gamito2ec1f7b2020-09-01 14:18:491667 std::move(metadata), &handle, &gbp, &id,
1668 &transformHint);
Valerie Hau1acd6962019-10-28 23:35:481669 if (outTransformHint) {
1670 *outTransformHint = transformHint;
1671 }
Marissa Wall35187b32019-01-08 18:08:521672 ALOGE_IF(err, "SurfaceComposerClient::createWithSurfaceParent error %s", strerror(-err));
1673 if (err == NO_ERROR) {
Pablo Gamitodbc31672020-09-01 18:28:581674 return new SurfaceControl(this, handle, gbp, id, transformHint);
Marissa Wall35187b32019-01-08 18:08:521675 }
1676 }
1677 return nullptr;
1678}
1679
Evan Rosky1f6d6d52018-12-06 18:47:261680status_t SurfaceComposerClient::createSurfaceChecked(const String8& name, uint32_t w, uint32_t h,
1681 PixelFormat format,
1682 sp<SurfaceControl>* outSurface, uint32_t flags,
Valerie Hau1acd6962019-10-28 23:35:481683 SurfaceControl* parent, LayerMetadata metadata,
1684 uint32_t* outTransformHint) {
Mathias Agopian4d9b8222013-03-13 00:11:481685 sp<SurfaceControl> sur;
Robert Carr740eaf02018-03-27 19:59:181686 status_t err = mStatus;
Robert Carr3b382ed2018-03-14 20:49:411687
Mathias Agopian698c0872011-06-29 02:09:311688 if (mStatus == NO_ERROR) {
Mathias Agopian4d9b8222013-03-13 00:11:481689 sp<IBinder> handle;
Robert Carr1f0a16a2016-10-24 23:27:391690 sp<IBinder> parentHandle;
Mathias Agopian4d9b8222013-03-13 00:11:481691 sp<IGraphicBufferProducer> gbp;
Robert Carr1f0a16a2016-10-24 23:27:391692
1693 if (parent != nullptr) {
1694 parentHandle = parent->getHandle();
1695 }
Evan Rosky1f6d6d52018-12-06 18:47:261696
Valerie Hau1acd6962019-10-28 23:35:481697 uint32_t transformHint = 0;
Pablo Gamito2ec1f7b2020-09-01 14:18:491698 int32_t id = -1;
Evan Rosky1f6d6d52018-12-06 18:47:261699 err = mClient->createSurface(name, w, h, format, flags, parentHandle, std::move(metadata),
Pablo Gamito2ec1f7b2020-09-01 14:18:491700 &handle, &gbp, &id, &transformHint);
1701
Valerie Hau1acd6962019-10-28 23:35:481702 if (outTransformHint) {
1703 *outTransformHint = transformHint;
1704 }
Mathias Agopian4d9b8222013-03-13 00:11:481705 ALOGE_IF(err, "SurfaceComposerClient::createSurface error %s", strerror(-err));
1706 if (err == NO_ERROR) {
Pablo Gamitodbc31672020-09-01 18:28:581707 *outSurface = new SurfaceControl(this, handle, gbp, id, transformHint);
Mathias Agopian698c0872011-06-29 02:09:311708 }
1709 }
Robert Carr3b382ed2018-03-14 20:49:411710 return err;
Mathias Agopian698c0872011-06-29 02:09:311711}
1712
chaviwfe94a222019-08-21 20:52:591713sp<SurfaceControl> SurfaceComposerClient::mirrorSurface(SurfaceControl* mirrorFromSurface) {
1714 if (mirrorFromSurface == nullptr) {
1715 return nullptr;
1716 }
1717
1718 sp<IBinder> handle;
1719 sp<IBinder> mirrorFromHandle = mirrorFromSurface->getHandle();
Pablo Gamito2ec1f7b2020-09-01 14:18:491720 int32_t layer_id = -1;
1721 status_t err = mClient->mirrorSurface(mirrorFromHandle, &handle, &layer_id);
chaviwfe94a222019-08-21 20:52:591722 if (err == NO_ERROR) {
Pablo Gamitodbc31672020-09-01 18:28:581723 return new SurfaceControl(this, handle, nullptr, layer_id, true /* owned */);
chaviwfe94a222019-08-21 20:52:591724 }
1725 return nullptr;
1726}
1727
Svetoslavd85084b2014-03-20 17:28:311728status_t SurfaceComposerClient::clearLayerFrameStats(const sp<IBinder>& token) const {
1729 if (mStatus != NO_ERROR) {
1730 return mStatus;
1731 }
1732 return mClient->clearLayerFrameStats(token);
1733}
1734
1735status_t SurfaceComposerClient::getLayerFrameStats(const sp<IBinder>& token,
1736 FrameStats* outStats) const {
1737 if (mStatus != NO_ERROR) {
1738 return mStatus;
1739 }
1740 return mClient->getLayerFrameStats(token, outStats);
1741}
1742
Mathias Agopian698c0872011-06-29 02:09:311743// ----------------------------------------------------------------------------
1744
Sahil Dhanjuc1ba5c42016-06-08 03:09:201745status_t SurfaceComposerClient::enableVSyncInjections(bool enable) {
Robert Carr4cdc58f2017-08-23 21:22:201746 sp<ISurfaceComposer> sf(ComposerService::getComposerService());
1747 return sf->enableVSyncInjections(enable);
Sahil Dhanjuc1ba5c42016-06-08 03:09:201748}
1749
1750status_t SurfaceComposerClient::injectVSync(nsecs_t when) {
Robert Carr4cdc58f2017-08-23 21:22:201751 sp<ISurfaceComposer> sf(ComposerService::getComposerService());
1752 return sf->injectVSync(when);
Sahil Dhanjuc1ba5c42016-06-08 03:09:201753}
1754
Dominik Laskowski3cb3d4e2019-11-21 19:14:451755status_t SurfaceComposerClient::getDisplayState(const sp<IBinder>& display,
1756 ui::DisplayState* state) {
1757 return ComposerService::getComposerService()->getDisplayState(display, state);
1758}
1759
1760status_t SurfaceComposerClient::getDisplayInfo(const sp<IBinder>& display, DisplayInfo* info) {
1761 return ComposerService::getComposerService()->getDisplayInfo(display, info);
1762}
1763
1764status_t SurfaceComposerClient::getDisplayConfigs(const sp<IBinder>& display,
1765 Vector<DisplayConfig>* configs) {
Dan Stoza7f7da322014-05-02 22:26:251766 return ComposerService::getComposerService()->getDisplayConfigs(display, configs);
1767}
1768
Dominik Laskowski3cb3d4e2019-11-21 19:14:451769status_t SurfaceComposerClient::getActiveDisplayConfig(const sp<IBinder>& display,
1770 DisplayConfig* config) {
1771 Vector<DisplayConfig> configs;
Dan Stoza7f7da322014-05-02 22:26:251772 status_t result = getDisplayConfigs(display, &configs);
1773 if (result != NO_ERROR) {
1774 return result;
1775 }
1776
1777 int activeId = getActiveConfig(display);
1778 if (activeId < 0) {
1779 ALOGE("No active configuration found");
1780 return NAME_NOT_FOUND;
1781 }
1782
Dominik Laskowski3cb3d4e2019-11-21 19:14:451783 *config = configs[static_cast<size_t>(activeId)];
Dan Stoza7f7da322014-05-02 22:26:251784 return NO_ERROR;
1785}
1786
1787int SurfaceComposerClient::getActiveConfig(const sp<IBinder>& display) {
1788 return ComposerService::getComposerService()->getActiveConfig(display);
1789}
1790
Ana Krulec0782b882019-10-16 00:34:541791status_t SurfaceComposerClient::setDesiredDisplayConfigSpecs(const sp<IBinder>& displayToken,
Ana Kruleced3a8cc2019-11-13 23:55:071792 int32_t defaultConfig,
Steven Thomasf734df42020-04-14 04:09:281793 float primaryRefreshRateMin,
1794 float primaryRefreshRateMax,
1795 float appRequestRefreshRateMin,
1796 float appRequestRefreshRateMax) {
1797 return ComposerService::getComposerService()
1798 ->setDesiredDisplayConfigSpecs(displayToken, defaultConfig, primaryRefreshRateMin,
1799 primaryRefreshRateMax, appRequestRefreshRateMin,
1800 appRequestRefreshRateMax);
Ana Krulec0782b882019-10-16 00:34:541801}
1802
Ana Krulec234bb162019-11-10 21:55:551803status_t SurfaceComposerClient::getDesiredDisplayConfigSpecs(const sp<IBinder>& displayToken,
Ana Kruleced3a8cc2019-11-13 23:55:071804 int32_t* outDefaultConfig,
Steven Thomasf734df42020-04-14 04:09:281805 float* outPrimaryRefreshRateMin,
1806 float* outPrimaryRefreshRateMax,
1807 float* outAppRequestRefreshRateMin,
1808 float* outAppRequestRefreshRateMax) {
1809 return ComposerService::getComposerService()
1810 ->getDesiredDisplayConfigSpecs(displayToken, outDefaultConfig, outPrimaryRefreshRateMin,
1811 outPrimaryRefreshRateMax, outAppRequestRefreshRateMin,
1812 outAppRequestRefreshRateMax);
Ana Krulec234bb162019-11-10 21:55:551813}
1814
Michael Wright28f24d02016-07-12 20:30:531815status_t SurfaceComposerClient::getDisplayColorModes(const sp<IBinder>& display,
Peiyong Lina52f0292018-03-15 00:26:311816 Vector<ColorMode>* outColorModes) {
Michael Wright28f24d02016-07-12 20:30:531817 return ComposerService::getComposerService()->getDisplayColorModes(display, outColorModes);
1818}
1819
Daniel Solomon42d04562019-01-21 05:03:191820status_t SurfaceComposerClient::getDisplayNativePrimaries(const sp<IBinder>& display,
1821 ui::DisplayPrimaries& outPrimaries) {
1822 return ComposerService::getComposerService()->getDisplayNativePrimaries(display, outPrimaries);
1823}
1824
Peiyong Lina52f0292018-03-15 00:26:311825ColorMode SurfaceComposerClient::getActiveColorMode(const sp<IBinder>& display) {
Michael Wright28f24d02016-07-12 20:30:531826 return ComposerService::getComposerService()->getActiveColorMode(display);
1827}
1828
1829status_t SurfaceComposerClient::setActiveColorMode(const sp<IBinder>& display,
Peiyong Lina52f0292018-03-15 00:26:311830 ColorMode colorMode) {
Michael Wright28f24d02016-07-12 20:30:531831 return ComposerService::getComposerService()->setActiveColorMode(display, colorMode);
1832}
1833
Galia Peycheva5492cb52019-10-30 13:13:161834bool SurfaceComposerClient::getAutoLowLatencyModeSupport(const sp<IBinder>& display) {
1835 bool supported = false;
1836 ComposerService::getComposerService()->getAutoLowLatencyModeSupport(display, &supported);
1837 return supported;
1838}
1839
1840void SurfaceComposerClient::setAutoLowLatencyMode(const sp<IBinder>& display, bool on) {
1841 ComposerService::getComposerService()->setAutoLowLatencyMode(display, on);
1842}
1843
1844bool SurfaceComposerClient::getGameContentTypeSupport(const sp<IBinder>& display) {
1845 bool supported = false;
1846 ComposerService::getComposerService()->getGameContentTypeSupport(display, &supported);
1847 return supported;
1848}
1849
1850void SurfaceComposerClient::setGameContentType(const sp<IBinder>& display, bool on) {
1851 ComposerService::getComposerService()->setGameContentType(display, on);
1852}
1853
Prashant Malani2c9b11f2014-05-25 08:36:311854void SurfaceComposerClient::setDisplayPowerMode(const sp<IBinder>& token,
1855 int mode) {
1856 ComposerService::getComposerService()->setPowerMode(token, mode);
Jeff Brown2a09bb32012-10-09 02:13:571857}
1858
Peiyong Linc6780972018-10-28 22:24:081859status_t SurfaceComposerClient::getCompositionPreference(
1860 ui::Dataspace* defaultDataspace, ui::PixelFormat* defaultPixelFormat,
1861 ui::Dataspace* wideColorGamutDataspace, ui::PixelFormat* wideColorGamutPixelFormat) {
1862 return ComposerService::getComposerService()
1863 ->getCompositionPreference(defaultDataspace, defaultPixelFormat,
1864 wideColorGamutDataspace, wideColorGamutPixelFormat);
Peiyong Lin0256f722018-08-31 22:45:101865}
1866
Peiyong Lin08d10512019-01-16 21:27:351867bool SurfaceComposerClient::getProtectedContentSupport() {
1868 bool supported = false;
1869 ComposerService::getComposerService()->getProtectedContentSupport(&supported);
1870 return supported;
1871}
1872
Svetoslavd85084b2014-03-20 17:28:311873status_t SurfaceComposerClient::clearAnimationFrameStats() {
1874 return ComposerService::getComposerService()->clearAnimationFrameStats();
1875}
1876
1877status_t SurfaceComposerClient::getAnimationFrameStats(FrameStats* outStats) {
1878 return ComposerService::getComposerService()->getAnimationFrameStats(outStats);
1879}
1880
Dan Stozac4f471e2016-03-24 16:31:081881status_t SurfaceComposerClient::getHdrCapabilities(const sp<IBinder>& display,
1882 HdrCapabilities* outCapabilities) {
1883 return ComposerService::getComposerService()->getHdrCapabilities(display,
1884 outCapabilities);
1885}
1886
Kevin DuBois9c0a1762018-10-16 20:32:311887status_t SurfaceComposerClient::getDisplayedContentSamplingAttributes(const sp<IBinder>& display,
1888 ui::PixelFormat* outFormat,
1889 ui::Dataspace* outDataspace,
1890 uint8_t* outComponentMask) {
1891 return ComposerService::getComposerService()
1892 ->getDisplayedContentSamplingAttributes(display, outFormat, outDataspace,
1893 outComponentMask);
1894}
1895
Kevin DuBois74e53772018-11-19 18:52:381896status_t SurfaceComposerClient::setDisplayContentSamplingEnabled(const sp<IBinder>& display,
1897 bool enable, uint8_t componentMask,
1898 uint64_t maxFrames) {
1899 return ComposerService::getComposerService()->setDisplayContentSamplingEnabled(display, enable,
1900 componentMask,
1901 maxFrames);
1902}
1903
Kevin DuBois1d4249a2018-08-29 17:45:141904status_t SurfaceComposerClient::getDisplayedContentSample(const sp<IBinder>& display,
1905 uint64_t maxFrames, uint64_t timestamp,
1906 DisplayedFrameStats* outStats) {
1907 return ComposerService::getComposerService()->getDisplayedContentSample(display, maxFrames,
1908 timestamp, outStats);
1909}
Marissa Wall35187b32019-01-08 18:08:521910
Peiyong Lin4f3fddf2019-01-25 01:21:241911status_t SurfaceComposerClient::isWideColorDisplay(const sp<IBinder>& display,
1912 bool* outIsWideColorDisplay) {
1913 return ComposerService::getComposerService()->isWideColorDisplay(display,
1914 outIsWideColorDisplay);
1915}
1916
Kevin DuBois00c66832019-02-19 00:21:311917status_t SurfaceComposerClient::addRegionSamplingListener(
1918 const Rect& samplingArea, const sp<IBinder>& stopLayerHandle,
1919 const sp<IRegionSamplingListener>& listener) {
1920 return ComposerService::getComposerService()->addRegionSamplingListener(samplingArea,
1921 stopLayerHandle,
1922 listener);
1923}
1924
1925status_t SurfaceComposerClient::removeRegionSamplingListener(
1926 const sp<IRegionSamplingListener>& listener) {
1927 return ComposerService::getComposerService()->removeRegionSamplingListener(listener);
1928}
1929
Dan Gittik57e63c52019-01-18 16:37:541930bool SurfaceComposerClient::getDisplayBrightnessSupport(const sp<IBinder>& displayToken) {
1931 bool support = false;
1932 ComposerService::getComposerService()->getDisplayBrightnessSupport(displayToken, &support);
1933 return support;
1934}
1935
1936status_t SurfaceComposerClient::setDisplayBrightness(const sp<IBinder>& displayToken,
1937 float brightness) {
1938 return ComposerService::getComposerService()->setDisplayBrightness(displayToken, brightness);
1939}
1940
Lais Andrade3a6e47d2020-04-02 10:20:161941status_t SurfaceComposerClient::notifyPowerBoost(int32_t boostId) {
1942 return ComposerService::getComposerService()->notifyPowerBoost(boostId);
Ady Abraham8532d012019-05-08 21:50:561943}
1944
Vishnu Nairb13bb952019-11-15 18:24:081945status_t SurfaceComposerClient::setGlobalShadowSettings(const half4& ambientColor,
1946 const half4& spotColor, float lightPosY,
1947 float lightPosZ, float lightRadius) {
1948 return ComposerService::getComposerService()->setGlobalShadowSettings(ambientColor, spotColor,
1949 lightPosY, lightPosZ,
1950 lightRadius);
1951}
1952
Mathias Agopian698c0872011-06-29 02:09:311953// ----------------------------------------------------------------------------
The Android Open Source Projectedbf3b62009-03-04 03:31:441954
chaviw690db382020-07-27 23:46:461955status_t ScreenshotClient::captureDisplay(const DisplayCaptureArgs& captureArgs,
chaviwe7b9f272020-08-18 23:08:591956 const sp<IScreenCaptureListener>& captureListener) {
Mathias Agopian2a9fc492013-03-01 21:42:571957 sp<ISurfaceComposer> s(ComposerService::getComposerService());
Yi Kong48a619f2018-06-05 23:34:591958 if (s == nullptr) return NO_INIT;
chaviw8ffc7b82020-08-18 18:25:371959
chaviwe7b9f272020-08-18 23:08:591960 return s->captureDisplay(captureArgs, captureListener);
Robert Carr673134e2017-01-10 03:48:381961}
1962
chaviw690db382020-07-27 23:46:461963status_t ScreenshotClient::captureDisplay(uint64_t displayOrLayerStack,
chaviwe7b9f272020-08-18 23:08:591964 const sp<IScreenCaptureListener>& captureListener) {
chaviw93df2ea2019-04-30 23:45:121965 sp<ISurfaceComposer> s(ComposerService::getComposerService());
1966 if (s == nullptr) return NO_INIT;
chaviw8ffc7b82020-08-18 18:25:371967
chaviwe7b9f272020-08-18 23:08:591968 return s->captureDisplay(displayOrLayerStack, captureListener);
chaviw93df2ea2019-04-30 23:45:121969}
1970
chaviw26c52482020-07-28 23:25:521971status_t ScreenshotClient::captureLayers(const LayerCaptureArgs& captureArgs,
chaviwe7b9f272020-08-18 23:08:591972 const sp<IScreenCaptureListener>& captureListener) {
chaviwa76b2712017-09-20 19:02:261973 sp<ISurfaceComposer> s(ComposerService::getComposerService());
Yi Kong48a619f2018-06-05 23:34:591974 if (s == nullptr) return NO_INIT;
chaviw8ffc7b82020-08-18 18:25:371975
chaviwe7b9f272020-08-18 23:08:591976 return s->captureLayers(captureArgs, captureListener);
chaviwa76b2712017-09-20 19:02:261977}
Dominik Laskowski718f9602019-11-10 04:01:351978
1979} // namespace android