blob: 27fb2a8cd7b1d2e1ce9b3ebcff0a8b58f48f03d1 [file] [log] [blame]
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#define LOG_TAG "SurfaceComposerClient"
18
19#include <stdint.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080020#include <sys/types.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080021
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080022#include <utils/Errors.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080023#include <utils/Log.h>
Mathias Agopiana67932f2011-04-20 14:20:59 -070024#include <utils/SortedVector.h>
25#include <utils/String8.h>
26#include <utils/threads.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080027
Marissa Wall7a9b6ff2018-08-21 17:26:20 -070028#include <binder/IPCThreadState.h>
Mathias Agopiana67932f2011-04-20 14:20:59 -070029#include <binder/IServiceManager.h>
Marissa Wall7a9b6ff2018-08-21 17:26:20 -070030#include <binder/ProcessState.h>
Mathias Agopian9cce3252010-02-09 17:46:37 -080031
Michael Wright28f24d02016-07-12 13:30:53 -070032#include <system/graphics.h>
33
Robert Carr673134e2017-01-09 19:48:38 -080034#include <gui/BufferItemConsumer.h>
Mathias Agopianabe815d2013-03-19 22:22:21 -070035#include <gui/CpuConsumer.h>
Mathias Agopiane3c697f2013-02-14 17:11:02 -080036#include <gui/IGraphicBufferProducer.h>
Mathias Agopian90ac7992012-02-25 18:48:35 -080037#include <gui/ISurfaceComposer.h>
38#include <gui/ISurfaceComposerClient.h>
Robert Carr4cdc58f2017-08-23 14:22:20 -070039#include <gui/LayerState.h>
Robert Carr0d480722017-01-10 16:42:54 -080040#include <gui/Surface.h>
Mathias Agopian90ac7992012-02-25 18:48:35 -080041#include <gui/SurfaceComposerClient.h>
Marin Shalamanova7fe3042021-01-29 21:02:08 +010042#include <ui/DisplayMode.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080043
Robert Carr2c358bf2018-08-08 15:58:15 -070044#ifndef NO_INPUT
45#include <input/InputWindow.h>
46#endif
47
Mathias Agopian41f673c2011-11-17 17:48:35 -080048#include <private/gui/ComposerService.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080049
Marissa Wall73411622019-01-25 10:45:41 -080050// This server size should always be smaller than the server cache size
51#define BUFFER_CACHE_MAX_SIZE 64
52
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080053namespace android {
Peiyong Lin9f034472018-03-28 15:29:00 -070054
55using ui::ColorMode;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080056// ---------------------------------------------------------------------------
57
Mathias Agopian7e27f052010-05-28 14:22:23 -070058ANDROID_SINGLETON_STATIC_INSTANCE(ComposerService);
59
Mathias Agopianb7e930d2010-06-01 15:12:58 -070060ComposerService::ComposerService()
61: Singleton<ComposerService>() {
Andy McFadden6652b3e2012-09-06 18:45:56 -070062 Mutex::Autolock _l(mLock);
63 connectLocked();
64}
65
66void ComposerService::connectLocked() {
Mathias Agopianb7e930d2010-06-01 15:12:58 -070067 const String16 name("SurfaceFlinger");
68 while (getService(name, &mComposerService) != NO_ERROR) {
69 usleep(250000);
70 }
Yi Konga03e0442018-07-17 11:16:57 -070071 assert(mComposerService != nullptr);
Andy McFadden6652b3e2012-09-06 18:45:56 -070072
73 // Create the death listener.
74 class DeathObserver : public IBinder::DeathRecipient {
75 ComposerService& mComposerService;
76 virtual void binderDied(const wp<IBinder>& who) {
77 ALOGW("ComposerService remote (surfaceflinger) died [%p]",
78 who.unsafe_get());
79 mComposerService.composerServiceDied();
80 }
81 public:
Chih-Hung Hsiehe2347b72016-04-25 15:41:05 -070082 explicit DeathObserver(ComposerService& mgr) : mComposerService(mgr) { }
Andy McFadden6652b3e2012-09-06 18:45:56 -070083 };
84
85 mDeathObserver = new DeathObserver(*const_cast<ComposerService*>(this));
Marco Nelissen2ea926b2014-11-14 08:01:01 -080086 IInterface::asBinder(mComposerService)->linkToDeath(mDeathObserver);
Mathias Agopianb7e930d2010-06-01 15:12:58 -070087}
88
Andy McFadden6652b3e2012-09-06 18:45:56 -070089/*static*/ sp<ISurfaceComposer> ComposerService::getComposerService() {
90 ComposerService& instance = ComposerService::getInstance();
91 Mutex::Autolock _l(instance.mLock);
Yi Kong48a619f2018-06-05 16:34:59 -070092 if (instance.mComposerService == nullptr) {
Andy McFadden6652b3e2012-09-06 18:45:56 -070093 ComposerService::getInstance().connectLocked();
Yi Konga03e0442018-07-17 11:16:57 -070094 assert(instance.mComposerService != nullptr);
Andy McFadden6652b3e2012-09-06 18:45:56 -070095 ALOGD("ComposerService reconnected");
96 }
97 return instance.mComposerService;
98}
99
100void ComposerService::composerServiceDied()
101{
102 Mutex::Autolock _l(mLock);
Yi Kong48a619f2018-06-05 16:34:59 -0700103 mComposerService = nullptr;
104 mDeathObserver = nullptr;
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700105}
106
Robert Carrfb4d58b2019-01-15 09:21:27 -0800107class DefaultComposerClient: public Singleton<DefaultComposerClient> {
108 Mutex mLock;
109 sp<SurfaceComposerClient> mClient;
110 friend class Singleton<ComposerService>;
111public:
112 static sp<SurfaceComposerClient> getComposerClient() {
113 DefaultComposerClient& dc = DefaultComposerClient::getInstance();
114 Mutex::Autolock _l(dc.mLock);
115 if (dc.mClient == nullptr) {
116 dc.mClient = new SurfaceComposerClient;
117 }
118 return dc.mClient;
119 }
120};
121ANDROID_SINGLETON_STATIC_INSTANCE(DefaultComposerClient);
122
123
124sp<SurfaceComposerClient> SurfaceComposerClient::getDefault() {
125 return DefaultComposerClient::getComposerClient();
126}
127
Jorim Jaggi9c03b502020-11-24 23:51:31 +0100128JankDataListener::~JankDataListener() {
129}
130
Mathias Agopian7e27f052010-05-28 14:22:23 -0700131// ---------------------------------------------------------------------------
132
Marissa Wall7a9b6ff2018-08-21 17:26:20 -0700133// TransactionCompletedListener does not use ANDROID_SINGLETON_STATIC_INSTANCE because it needs
134// to be able to return a sp<> to its instance to pass to SurfaceFlinger.
135// ANDROID_SINGLETON_STATIC_INSTANCE only allows a reference to an instance.
136
Marissa Wallc837b5e2018-10-12 10:04:44 -0700137// 0 is an invalid callback id
138TransactionCompletedListener::TransactionCompletedListener() : mCallbackIdCounter(1) {}
139
140CallbackId TransactionCompletedListener::getNextIdLocked() {
141 return mCallbackIdCounter++;
142}
143
Marissa Wall7a9b6ff2018-08-21 17:26:20 -0700144sp<TransactionCompletedListener> TransactionCompletedListener::getInstance() {
145 static sp<TransactionCompletedListener> sInstance = new TransactionCompletedListener;
146 return sInstance;
147}
148
Marissa Wallc837b5e2018-10-12 10:04:44 -0700149sp<ITransactionCompletedListener> TransactionCompletedListener::getIInstance() {
150 return static_cast<sp<ITransactionCompletedListener>>(getInstance());
151}
152
153void TransactionCompletedListener::startListeningLocked() {
Marissa Wall7a9b6ff2018-08-21 17:26:20 -0700154 if (mListening) {
155 return;
156 }
157 ProcessState::self()->startThreadPool();
158 mListening = true;
159}
160
Marissa Wall80d94ad2019-01-18 16:04:36 -0800161CallbackId TransactionCompletedListener::addCallbackFunction(
162 const TransactionCompletedCallback& callbackFunction,
163 const std::unordered_set<sp<SurfaceControl>, SurfaceComposerClient::SCHash>&
164 surfaceControls) {
Marissa Wallc837b5e2018-10-12 10:04:44 -0700165 std::lock_guard<std::mutex> lock(mMutex);
166 startListeningLocked();
167
168 CallbackId callbackId = getNextIdLocked();
Marissa Wall80d94ad2019-01-18 16:04:36 -0800169 mCallbacks[callbackId].callbackFunction = callbackFunction;
170
171 auto& callbackSurfaceControls = mCallbacks[callbackId].surfaceControls;
172
173 for (const auto& surfaceControl : surfaceControls) {
174 callbackSurfaceControls[surfaceControl->getHandle()] = surfaceControl;
175 }
176
Marissa Wallc837b5e2018-10-12 10:04:44 -0700177 return callbackId;
178}
179
Jorim Jaggi9c03b502020-11-24 23:51:31 +0100180void TransactionCompletedListener::addJankListener(const sp<JankDataListener>& listener,
181 sp<SurfaceControl> surfaceControl) {
182 std::lock_guard<std::mutex> lock(mMutex);
183 mJankListeners.insert({surfaceControl->getHandle(), listener});
184}
185
186void TransactionCompletedListener::removeJankListener(const sp<JankDataListener>& listener) {
187 std::lock_guard<std::mutex> lock(mMutex);
188 for (auto it = mJankListeners.begin(); it != mJankListeners.end();) {
189 if (it->second == listener) {
190 it = mJankListeners.erase(it);
191 } else {
192 it++;
193 }
194 }
195}
196
Marissa Wall80d94ad2019-01-18 16:04:36 -0800197void TransactionCompletedListener::addSurfaceControlToCallbacks(
198 const sp<SurfaceControl>& surfaceControl,
199 const std::unordered_set<CallbackId>& callbackIds) {
200 std::lock_guard<std::mutex> lock(mMutex);
201
202 for (auto callbackId : callbackIds) {
203 mCallbacks[callbackId].surfaceControls.emplace(std::piecewise_construct,
204 std::forward_as_tuple(
205 surfaceControl->getHandle()),
206 std::forward_as_tuple(surfaceControl));
207 }
208}
209
Marissa Walle2ffb422018-10-12 11:33:52 -0700210void TransactionCompletedListener::onTransactionCompleted(ListenerStats listenerStats) {
Valerie Haud3b90d22019-11-06 09:37:31 -0800211 std::unordered_map<CallbackId, CallbackTranslation> callbacksMap;
Jorim Jaggi9c03b502020-11-24 23:51:31 +0100212 std::multimap<sp<IBinder>, sp<JankDataListener>> jankListenersMap;
Valerie Haud3b90d22019-11-06 09:37:31 -0800213 {
214 std::lock_guard<std::mutex> lock(mMutex);
Marissa Walle2ffb422018-10-12 11:33:52 -0700215
Valerie Haud3b90d22019-11-06 09:37:31 -0800216 /* This listener knows all the sp<IBinder> to sp<SurfaceControl> for all its registered
217 * callbackIds, except for when Transactions are merged together. This probably cannot be
218 * solved before this point because the Transactions could be merged together and applied in
219 * a different process.
220 *
221 * Fortunately, we get all the callbacks for this listener for the same frame together at
222 * the same time. This means if any Transactions were merged together, we will get their
223 * callbacks at the same time. We can combine all the sp<IBinder> to sp<SurfaceControl> maps
224 * for all the callbackIds to generate one super map that contains all the sp<IBinder> to
225 * sp<SurfaceControl> that could possibly exist for the callbacks.
226 */
227 callbacksMap = mCallbacks;
Jorim Jaggi9c03b502020-11-24 23:51:31 +0100228 jankListenersMap = mJankListeners;
Valerie Haud3b90d22019-11-06 09:37:31 -0800229 for (const auto& transactionStats : listenerStats.transactionStats) {
230 for (auto& callbackId : transactionStats.callbackIds) {
231 mCallbacks.erase(callbackId);
232 }
Marissa Wall80d94ad2019-01-18 16:04:36 -0800233 }
234 }
Marissa Walld600d572019-03-26 15:38:50 -0700235 for (const auto& transactionStats : listenerStats.transactionStats) {
236 for (auto callbackId : transactionStats.callbackIds) {
Valerie Haud3b90d22019-11-06 09:37:31 -0800237 auto& [callbackFunction, callbackSurfaceControls] = callbacksMap[callbackId];
Marissa Wall80d94ad2019-01-18 16:04:36 -0800238 if (!callbackFunction) {
Marissa Walle2ffb422018-10-12 11:33:52 -0700239 ALOGE("cannot call null callback function, skipping");
240 continue;
241 }
Marissa Wall80d94ad2019-01-18 16:04:36 -0800242 std::vector<SurfaceControlStats> surfaceControlStats;
243 for (const auto& surfaceStats : transactionStats.surfaceStats) {
Valerie Haud3b90d22019-11-06 09:37:31 -0800244 surfaceControlStats
245 .emplace_back(callbacksMap[callbackId]
246 .surfaceControls[surfaceStats.surfaceControl],
Valerie Hau871d6352020-01-29 08:44:02 -0800247 transactionStats.latchTime, surfaceStats.acquireTime,
248 transactionStats.presentFence,
249 surfaceStats.previousReleaseFence, surfaceStats.transformHint,
250 surfaceStats.eventStats);
Valerie Hau84d87ff2020-01-08 17:23:21 -0800251 if (callbacksMap[callbackId].surfaceControls[surfaceStats.surfaceControl]) {
252 callbacksMap[callbackId]
253 .surfaceControls[surfaceStats.surfaceControl]
254 ->setTransformHint(surfaceStats.transformHint);
255 }
Marissa Wall80d94ad2019-01-18 16:04:36 -0800256 }
257
258 callbackFunction(transactionStats.latchTime, transactionStats.presentFence,
259 surfaceControlStats);
Marissa Walle2ffb422018-10-12 11:33:52 -0700260 }
Jorim Jaggi9c03b502020-11-24 23:51:31 +0100261 for (const auto& surfaceStats : transactionStats.surfaceStats) {
262 if (surfaceStats.jankData.empty()) continue;
263 for (auto it = jankListenersMap.find(surfaceStats.surfaceControl);
264 it != jankListenersMap.end(); it++) {
265 it->second->onJankDataAvailable(surfaceStats.jankData);
266 }
267 }
Marissa Walle2ffb422018-10-12 11:33:52 -0700268 }
Marissa Wall7a9b6ff2018-08-21 17:26:20 -0700269}
270
271// ---------------------------------------------------------------------------
272
Robert Carre06ad2b2020-04-10 15:09:33 -0700273void removeDeadBufferCallback(void* /*context*/, uint64_t graphicBufferId);
Marissa Wall78b72202019-03-15 14:58:34 -0700274
Robert Carre06ad2b2020-04-10 15:09:33 -0700275/**
276 * We use the BufferCache to reduce the overhead of exchanging GraphicBuffers with
277 * the server. If we were to simply parcel the GraphicBuffer we would pay two overheads
278 * 1. Cost of sending the FD
279 * 2. Cost of importing the GraphicBuffer with the mapper in the receiving process.
280 * To ease this cost we implement the following scheme of caching buffers to integers,
281 * or said-otherwise, naming them with integers. This is the scheme known as slots in
282 * the legacy BufferQueue system.
283 * 1. When sending Buffers to SurfaceFlinger we look up the Buffer in the cache.
284 * 2. If there is a cache-hit we remove the Buffer from the Transaction and instead
285 * send the cached integer.
286 * 3. If there is a cache miss, we cache the new buffer and send the integer
287 * along with the Buffer, SurfaceFlinger on it's side creates a new cache
288 * entry, and we use the integer for further communication.
289 * A few details about lifetime:
290 * 1. The cache evicts by LRU. The server side cache is keyed by BufferCache::getToken
291 * which is per process Unique. The server side cache is larger than the client side
292 * cache so that the server will never evict entries before the client.
293 * 2. When the client evicts an entry it notifies the server via an uncacheBuffer
294 * transaction.
295 * 3. The client only references the Buffers by ID, and uses buffer->addDeathCallback
296 * to auto-evict destroyed buffers.
297 */
Marissa Wall73411622019-01-25 10:45:41 -0800298class BufferCache : public Singleton<BufferCache> {
299public:
300 BufferCache() : token(new BBinder()) {}
301
302 sp<IBinder> getToken() {
303 return IInterface::asBinder(TransactionCompletedListener::getIInstance());
304 }
305
Marissa Wall78b72202019-03-15 14:58:34 -0700306 status_t getCacheId(const sp<GraphicBuffer>& buffer, uint64_t* cacheId) {
Yi Kongd2639aa2019-02-28 11:58:32 -0800307 std::lock_guard<std::mutex> lock(mMutex);
Marissa Wall73411622019-01-25 10:45:41 -0800308
Marissa Wall78b72202019-03-15 14:58:34 -0700309 auto itr = mBuffers.find(buffer->getId());
Marissa Wall73411622019-01-25 10:45:41 -0800310 if (itr == mBuffers.end()) {
Marissa Wall78b72202019-03-15 14:58:34 -0700311 return BAD_VALUE;
Marissa Wall73411622019-01-25 10:45:41 -0800312 }
Marissa Wall78b72202019-03-15 14:58:34 -0700313 itr->second = getCounter();
314 *cacheId = buffer->getId();
315 return NO_ERROR;
Marissa Wall73411622019-01-25 10:45:41 -0800316 }
317
Marissa Wall78b72202019-03-15 14:58:34 -0700318 uint64_t cache(const sp<GraphicBuffer>& buffer) {
Yi Kongd2639aa2019-02-28 11:58:32 -0800319 std::lock_guard<std::mutex> lock(mMutex);
Marissa Wall73411622019-01-25 10:45:41 -0800320
Marissa Wall78b72202019-03-15 14:58:34 -0700321 if (mBuffers.size() >= BUFFER_CACHE_MAX_SIZE) {
322 evictLeastRecentlyUsedBuffer();
323 }
Marissa Wall73411622019-01-25 10:45:41 -0800324
Robert Carre06ad2b2020-04-10 15:09:33 -0700325 buffer->addDeathCallback(removeDeadBufferCallback, nullptr);
Marissa Wall78b72202019-03-15 14:58:34 -0700326
327 mBuffers[buffer->getId()] = getCounter();
328 return buffer->getId();
329 }
330
331 void uncache(uint64_t cacheId) {
332 std::lock_guard<std::mutex> lock(mMutex);
333 uncacheLocked(cacheId);
334 }
335
336 void uncacheLocked(uint64_t cacheId) REQUIRES(mMutex) {
337 mBuffers.erase(cacheId);
338 SurfaceComposerClient::doUncacheBufferTransaction(cacheId);
Marissa Wall73411622019-01-25 10:45:41 -0800339 }
340
341private:
Marissa Wall78b72202019-03-15 14:58:34 -0700342 void evictLeastRecentlyUsedBuffer() REQUIRES(mMutex) {
Marissa Wall73411622019-01-25 10:45:41 -0800343 auto itr = mBuffers.begin();
Marissa Wall78b72202019-03-15 14:58:34 -0700344 uint64_t minCounter = itr->second;
Marissa Wall73411622019-01-25 10:45:41 -0800345 auto minBuffer = itr;
346 itr++;
347
348 while (itr != mBuffers.end()) {
Marissa Wall78b72202019-03-15 14:58:34 -0700349 uint64_t counter = itr->second;
Marissa Wall73411622019-01-25 10:45:41 -0800350 if (counter < minCounter) {
351 minCounter = counter;
352 minBuffer = itr;
353 }
354 itr++;
355 }
Marissa Wall78b72202019-03-15 14:58:34 -0700356 uncacheLocked(minBuffer->first);
Marissa Wall73411622019-01-25 10:45:41 -0800357 }
358
359 uint64_t getCounter() REQUIRES(mMutex) {
360 static uint64_t counter = 0;
361 return counter++;
362 }
363
Marissa Wall73411622019-01-25 10:45:41 -0800364 std::mutex mMutex;
Marissa Wall78b72202019-03-15 14:58:34 -0700365 std::map<uint64_t /*Cache id*/, uint64_t /*counter*/> mBuffers GUARDED_BY(mMutex);
Marissa Wall73411622019-01-25 10:45:41 -0800366
367 // Used by ISurfaceComposer to identify which process is sending the cached buffer.
368 sp<IBinder> token;
369};
370
371ANDROID_SINGLETON_STATIC_INSTANCE(BufferCache);
372
Robert Carre06ad2b2020-04-10 15:09:33 -0700373void removeDeadBufferCallback(void* /*context*/, uint64_t graphicBufferId) {
Marissa Wall78b72202019-03-15 14:58:34 -0700374 // GraphicBuffer id's are used as the cache ids.
375 BufferCache::getInstance().uncache(graphicBufferId);
376}
377
Marissa Wall73411622019-01-25 10:45:41 -0800378// ---------------------------------------------------------------------------
379
Pablo Gamito7eb7ee72020-08-05 10:57:05 +0000380// Initialize transaction id counter used to generate transaction ids
381// Transactions will start counting at 1, 0 is used for invalid transactions
382std::atomic<uint32_t> SurfaceComposerClient::Transaction::idCounter = 1;
383
384SurfaceComposerClient::Transaction::Transaction() {
385 mId = generateId();
386}
387
Marissa Wall17b4e452018-12-26 16:32:34 -0800388SurfaceComposerClient::Transaction::Transaction(const Transaction& other)
Pablo Gamito7eb7ee72020-08-05 10:57:05 +0000389 : mId(other.mId),
390 mForceSynchronous(other.mForceSynchronous),
Marissa Wall17b4e452018-12-26 16:32:34 -0800391 mTransactionNestCount(other.mTransactionNestCount),
392 mAnimation(other.mAnimation),
393 mEarlyWakeup(other.mEarlyWakeup),
Ady Abrahambf1349c2020-06-12 14:26:18 -0700394 mExplicitEarlyWakeupStart(other.mExplicitEarlyWakeupStart),
395 mExplicitEarlyWakeupEnd(other.mExplicitEarlyWakeupEnd),
Vishnu Nair621102e2019-06-12 14:16:57 -0700396 mContainsBuffer(other.mContainsBuffer),
Ady Abraham22c7b5c2020-09-22 19:33:40 -0700397 mDesiredPresentTime(other.mDesiredPresentTime),
Ady Abrahamf0c56492020-12-17 18:04:15 -0800398 mIsAutoTimestamp(other.mIsAutoTimestamp),
Siarhei Vishniakoufc434ac2021-01-13 10:28:00 -1000399 mFrameTimelineInfo(other.mFrameTimelineInfo),
Vishnu Nair277142c2021-01-05 18:35:29 -0800400 mApplyToken(other.mApplyToken) {
Robert Carr4cdc58f2017-08-23 14:22:20 -0700401 mDisplayStates = other.mDisplayStates;
402 mComposerStates = other.mComposerStates;
chaviw273171b2018-12-26 11:46:30 -0800403 mInputWindowCommands = other.mInputWindowCommands;
Vishnu Nair621102e2019-06-12 14:16:57 -0700404 mListenerCallbacks = other.mListenerCallbacks;
405}
406
407std::unique_ptr<SurfaceComposerClient::Transaction>
408SurfaceComposerClient::Transaction::createFromParcel(const Parcel* parcel) {
409 auto transaction = std::make_unique<Transaction>();
410 if (transaction->readFromParcel(parcel) == NO_ERROR) {
411 return transaction;
412 }
413 return nullptr;
414}
415
Pablo Gamito7eb7ee72020-08-05 10:57:05 +0000416int64_t SurfaceComposerClient::Transaction::generateId() {
417 return (((int64_t)getpid()) << 32) | idCounter++;
418}
419
Vishnu Nair621102e2019-06-12 14:16:57 -0700420status_t SurfaceComposerClient::Transaction::readFromParcel(const Parcel* parcel) {
421 const uint32_t forceSynchronous = parcel->readUint32();
422 const uint32_t transactionNestCount = parcel->readUint32();
423 const bool animation = parcel->readBool();
424 const bool earlyWakeup = parcel->readBool();
Ady Abrahambf1349c2020-06-12 14:26:18 -0700425 const bool explicitEarlyWakeupStart = parcel->readBool();
426 const bool explicitEarlyWakeupEnd = parcel->readBool();
Vishnu Nair621102e2019-06-12 14:16:57 -0700427 const bool containsBuffer = parcel->readBool();
428 const int64_t desiredPresentTime = parcel->readInt64();
Ady Abrahamf0c56492020-12-17 18:04:15 -0800429 const bool isAutoTimestamp = parcel->readBool();
Siarhei Vishniakoufc434ac2021-01-13 10:28:00 -1000430 FrameTimelineInfo frameTimelineInfo;
431 SAFE_PARCEL(frameTimelineInfo.read, *parcel);
432
Vishnu Nair277142c2021-01-05 18:35:29 -0800433 sp<IBinder> applyToken;
434 parcel->readNullableStrongBinder(&applyToken);
Vishnu Nair621102e2019-06-12 14:16:57 -0700435 size_t count = static_cast<size_t>(parcel->readUint32());
436 if (count > parcel->dataSize()) {
437 return BAD_VALUE;
438 }
439 SortedVector<DisplayState> displayStates;
440 displayStates.setCapacity(count);
441 for (size_t i = 0; i < count; i++) {
442 DisplayState displayState;
443 if (displayState.read(*parcel) == BAD_VALUE) {
444 return BAD_VALUE;
445 }
446 displayStates.add(displayState);
447 }
448
449 count = static_cast<size_t>(parcel->readUint32());
450 if (count > parcel->dataSize()) {
451 return BAD_VALUE;
452 }
Valerie Hau9dab9732019-08-20 09:29:25 -0700453 std::unordered_map<sp<ITransactionCompletedListener>, CallbackInfo, TCLHash> listenerCallbacks;
454 listenerCallbacks.reserve(count);
455 for (size_t i = 0; i < count; i++) {
456 sp<ITransactionCompletedListener> listener =
457 interface_cast<ITransactionCompletedListener>(parcel->readStrongBinder());
458 size_t numCallbackIds = parcel->readUint32();
459 if (numCallbackIds > parcel->dataSize()) {
460 return BAD_VALUE;
461 }
462 for (size_t j = 0; j < numCallbackIds; j++) {
463 listenerCallbacks[listener].callbackIds.insert(parcel->readInt64());
464 }
465 size_t numSurfaces = parcel->readUint32();
466 if (numSurfaces > parcel->dataSize()) {
467 return BAD_VALUE;
468 }
469 for (size_t j = 0; j < numSurfaces; j++) {
470 sp<SurfaceControl> surface;
Pablo Gamito421dfd52020-09-22 18:11:45 +0000471 SAFE_PARCEL(SurfaceControl::readFromParcel, *parcel, &surface);
Valerie Hau9dab9732019-08-20 09:29:25 -0700472 listenerCallbacks[listener].surfaceControls.insert(surface);
473 }
474 }
475
476 count = static_cast<size_t>(parcel->readUint32());
477 if (count > parcel->dataSize()) {
478 return BAD_VALUE;
479 }
Vishnu Nairf03652d2019-07-16 17:56:56 -0700480 std::unordered_map<sp<IBinder>, ComposerState, IBinderHash> composerStates;
Vishnu Nair621102e2019-06-12 14:16:57 -0700481 composerStates.reserve(count);
482 for (size_t i = 0; i < count; i++) {
Pablo Gamitodbc31672020-09-01 18:28:58 +0000483 sp<IBinder> surfaceControlHandle;
484 SAFE_PARCEL(parcel->readStrongBinder, &surfaceControlHandle);
Vishnu Nair621102e2019-06-12 14:16:57 -0700485
486 ComposerState composerState;
487 if (composerState.read(*parcel) == BAD_VALUE) {
488 return BAD_VALUE;
489 }
Pablo Gamitodbc31672020-09-01 18:28:58 +0000490
Vishnu Nairf03652d2019-07-16 17:56:56 -0700491 composerStates[surfaceControlHandle] = composerState;
Vishnu Nair621102e2019-06-12 14:16:57 -0700492 }
493
494 InputWindowCommands inputWindowCommands;
495 inputWindowCommands.read(*parcel);
496
497 // Parsing was successful. Update the object.
498 mForceSynchronous = forceSynchronous;
499 mTransactionNestCount = transactionNestCount;
500 mAnimation = animation;
501 mEarlyWakeup = earlyWakeup;
Ady Abrahambf1349c2020-06-12 14:26:18 -0700502 mExplicitEarlyWakeupStart = explicitEarlyWakeupStart;
503 mExplicitEarlyWakeupEnd = explicitEarlyWakeupEnd;
Vishnu Nair621102e2019-06-12 14:16:57 -0700504 mContainsBuffer = containsBuffer;
505 mDesiredPresentTime = desiredPresentTime;
Ady Abrahamf0c56492020-12-17 18:04:15 -0800506 mIsAutoTimestamp = isAutoTimestamp;
Siarhei Vishniakoufc434ac2021-01-13 10:28:00 -1000507 mFrameTimelineInfo = frameTimelineInfo;
Vishnu Nair621102e2019-06-12 14:16:57 -0700508 mDisplayStates = displayStates;
Valerie Hau9dab9732019-08-20 09:29:25 -0700509 mListenerCallbacks = listenerCallbacks;
Vishnu Nair621102e2019-06-12 14:16:57 -0700510 mComposerStates = composerStates;
511 mInputWindowCommands = inputWindowCommands;
Vishnu Nair277142c2021-01-05 18:35:29 -0800512 mApplyToken = applyToken;
Vishnu Nair621102e2019-06-12 14:16:57 -0700513 return NO_ERROR;
514}
515
516status_t SurfaceComposerClient::Transaction::writeToParcel(Parcel* parcel) const {
Robert Carr158531d2020-04-08 10:53:30 -0700517 // If we write the Transaction to a parcel, we want to ensure the Buffers are cached
518 // before crossing the IPC boundary. Otherwise the receiving party will cache the buffers
519 // but is unlikely to use them again as they are owned by the other process.
520 // You may be asking yourself, is this const cast safe? Const cast is safe up
521 // until the point where you try and write to an object that was originally const at which
522 // point we enter undefined behavior. In this case we are safe though, because there are
523 // two possibilities:
524 // 1. The SurfaceComposerClient::Transaction was originally non-const. Safe.
525 // 2. It was originall const! In this case not only was it useless, but it by definition
526 // contains no composer states and so cacheBuffers will not perform any writes.
527
528 const_cast<SurfaceComposerClient::Transaction*>(this)->cacheBuffers();
529
Vishnu Nair621102e2019-06-12 14:16:57 -0700530 parcel->writeUint32(mForceSynchronous);
531 parcel->writeUint32(mTransactionNestCount);
532 parcel->writeBool(mAnimation);
533 parcel->writeBool(mEarlyWakeup);
Ady Abrahambf1349c2020-06-12 14:26:18 -0700534 parcel->writeBool(mExplicitEarlyWakeupStart);
535 parcel->writeBool(mExplicitEarlyWakeupEnd);
Vishnu Nair621102e2019-06-12 14:16:57 -0700536 parcel->writeBool(mContainsBuffer);
537 parcel->writeInt64(mDesiredPresentTime);
Ady Abrahamf0c56492020-12-17 18:04:15 -0800538 parcel->writeBool(mIsAutoTimestamp);
Siarhei Vishniakoufc434ac2021-01-13 10:28:00 -1000539 SAFE_PARCEL(mFrameTimelineInfo.write, *parcel);
Vishnu Nair277142c2021-01-05 18:35:29 -0800540 parcel->writeStrongBinder(mApplyToken);
Vishnu Nair621102e2019-06-12 14:16:57 -0700541 parcel->writeUint32(static_cast<uint32_t>(mDisplayStates.size()));
542 for (auto const& displayState : mDisplayStates) {
543 displayState.write(*parcel);
544 }
545
Valerie Hau9dab9732019-08-20 09:29:25 -0700546 parcel->writeUint32(static_cast<uint32_t>(mListenerCallbacks.size()));
547 for (auto const& [listener, callbackInfo] : mListenerCallbacks) {
548 parcel->writeStrongBinder(ITransactionCompletedListener::asBinder(listener));
549 parcel->writeUint32(static_cast<uint32_t>(callbackInfo.callbackIds.size()));
550 for (auto callbackId : callbackInfo.callbackIds) {
551 parcel->writeInt64(callbackId);
552 }
553 parcel->writeUint32(static_cast<uint32_t>(callbackInfo.surfaceControls.size()));
554 for (auto surfaceControl : callbackInfo.surfaceControls) {
Pablo Gamito421dfd52020-09-22 18:11:45 +0000555 SAFE_PARCEL(surfaceControl->writeToParcel, *parcel);
Valerie Hau9dab9732019-08-20 09:29:25 -0700556 }
557 }
558
Vishnu Nair621102e2019-06-12 14:16:57 -0700559 parcel->writeUint32(static_cast<uint32_t>(mComposerStates.size()));
Pablo Gamitodbc31672020-09-01 18:28:58 +0000560 for (auto const& [handle, composerState] : mComposerStates) {
561 SAFE_PARCEL(parcel->writeStrongBinder, handle);
Vishnu Nair621102e2019-06-12 14:16:57 -0700562 composerState.write(*parcel);
563 }
564
565 mInputWindowCommands.write(*parcel);
566 return NO_ERROR;
Mathias Agopian698c0872011-06-28 19:09:31 -0700567}
568
Robert Carr2c5f6d22017-09-26 12:30:35 -0700569SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::merge(Transaction&& other) {
Pablo Gamitodbc31672020-09-01 18:28:58 +0000570 for (auto const& [handle, composerState] : other.mComposerStates) {
571 if (mComposerStates.count(handle) == 0) {
572 mComposerStates[handle] = composerState;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700573 } else {
Pablo Gamitodbc31672020-09-01 18:28:58 +0000574 mComposerStates[handle].state.merge(composerState.state);
Robert Carr2c5f6d22017-09-26 12:30:35 -0700575 }
576 }
Robert Carr2c5f6d22017-09-26 12:30:35 -0700577
578 for (auto const& state : other.mDisplayStates) {
579 ssize_t index = mDisplayStates.indexOf(state);
580 if (index < 0) {
581 mDisplayStates.add(state);
582 } else {
583 mDisplayStates.editItemAt(static_cast<size_t>(index)).merge(state);
584 }
585 }
Robert Carr2c5f6d22017-09-26 12:30:35 -0700586
Marissa Wallc837b5e2018-10-12 10:04:44 -0700587 for (const auto& [listener, callbackInfo] : other.mListenerCallbacks) {
588 auto& [callbackIds, surfaceControls] = callbackInfo;
589 mListenerCallbacks[listener].callbackIds.insert(std::make_move_iterator(
590 callbackIds.begin()),
591 std::make_move_iterator(callbackIds.end()));
Valerie Hau9dab9732019-08-20 09:29:25 -0700592
Valerie Hau236eba32020-01-03 16:53:39 -0800593 mListenerCallbacks[listener].surfaceControls.insert(surfaceControls.begin(),
594 surfaceControls.end());
595
596 auto& currentProcessCallbackInfo =
597 mListenerCallbacks[TransactionCompletedListener::getIInstance()];
598 currentProcessCallbackInfo.surfaceControls
599 .insert(std::make_move_iterator(surfaceControls.begin()),
600 std::make_move_iterator(surfaceControls.end()));
601
602 // register all surface controls for all callbackIds for this listener that is merging
603 for (const auto& surfaceControl : currentProcessCallbackInfo.surfaceControls) {
604 TransactionCompletedListener::getInstance()
605 ->addSurfaceControlToCallbacks(surfaceControl,
606 currentProcessCallbackInfo.callbackIds);
607 }
Marissa Wallc837b5e2018-10-12 10:04:44 -0700608 }
Marissa Wallc837b5e2018-10-12 10:04:44 -0700609
chaviw273171b2018-12-26 11:46:30 -0800610 mInputWindowCommands.merge(other.mInputWindowCommands);
611
Robert Carrbbc85622020-04-08 10:45:12 -0700612 mContainsBuffer |= other.mContainsBuffer;
Jorim Jaggie3b57002019-07-22 17:18:52 +0200613 mEarlyWakeup = mEarlyWakeup || other.mEarlyWakeup;
Ady Abrahambf1349c2020-06-12 14:26:18 -0700614 mExplicitEarlyWakeupStart = mExplicitEarlyWakeupStart || other.mExplicitEarlyWakeupStart;
615 mExplicitEarlyWakeupEnd = mExplicitEarlyWakeupEnd || other.mExplicitEarlyWakeupEnd;
Vishnu Nair277142c2021-01-05 18:35:29 -0800616 mApplyToken = other.mApplyToken;
Ady Abraham22c7b5c2020-09-22 19:33:40 -0700617
Siarhei Vishniakoufc434ac2021-01-13 10:28:00 -1000618 mFrameTimelineInfo.merge(other.mFrameTimelineInfo);
Ady Abraham22c7b5c2020-09-22 19:33:40 -0700619
Vishnu Nairfef244e2019-06-17 18:07:51 -0700620 other.clear();
Robert Carr2c5f6d22017-09-26 12:30:35 -0700621 return *this;
622}
623
Vishnu Nairfef244e2019-06-17 18:07:51 -0700624void SurfaceComposerClient::Transaction::clear() {
625 mComposerStates.clear();
626 mDisplayStates.clear();
627 mListenerCallbacks.clear();
628 mInputWindowCommands.clear();
629 mContainsBuffer = false;
630 mForceSynchronous = 0;
631 mTransactionNestCount = 0;
632 mAnimation = false;
633 mEarlyWakeup = false;
Ady Abrahambf1349c2020-06-12 14:26:18 -0700634 mExplicitEarlyWakeupStart = false;
635 mExplicitEarlyWakeupEnd = false;
Ady Abrahamf0c56492020-12-17 18:04:15 -0800636 mDesiredPresentTime = 0;
637 mIsAutoTimestamp = true;
Siarhei Vishniakoufc434ac2021-01-13 10:28:00 -1000638 mFrameTimelineInfo.clear();
Vishnu Nair277142c2021-01-05 18:35:29 -0800639 mApplyToken = nullptr;
Vishnu Nairfef244e2019-06-17 18:07:51 -0700640}
641
Marissa Wall78b72202019-03-15 14:58:34 -0700642void SurfaceComposerClient::doUncacheBufferTransaction(uint64_t cacheId) {
643 sp<ISurfaceComposer> sf(ComposerService::getComposerService());
644
Marissa Wall947d34e2019-03-29 14:03:53 -0700645 client_cache_t uncacheBuffer;
Marissa Wall78b72202019-03-15 14:58:34 -0700646 uncacheBuffer.token = BufferCache::getInstance().getToken();
Marissa Wall947d34e2019-03-29 14:03:53 -0700647 uncacheBuffer.id = cacheId;
Marissa Wall78b72202019-03-15 14:58:34 -0700648
Valerie Haufa889122019-04-15 13:56:05 -0700649 sp<IBinder> applyToken = IInterface::asBinder(TransactionCompletedListener::getIInstance());
Siarhei Vishniakoufc434ac2021-01-13 10:28:00 -1000650 sf->setTransactionState(FrameTimelineInfo{}, {}, {}, 0, applyToken, {}, systemTime(), true,
651 uncacheBuffer, false, {}, 0 /* Undefined transactionId */);
Marissa Wall78b72202019-03-15 14:58:34 -0700652}
653
654void SurfaceComposerClient::Transaction::cacheBuffers() {
655 if (!mContainsBuffer) {
656 return;
657 }
658
659 size_t count = 0;
Vishnu Nairf03652d2019-07-16 17:56:56 -0700660 for (auto& [handle, cs] : mComposerStates) {
Pablo Gamitodbc31672020-09-01 18:28:58 +0000661 layer_state_t* s = &(mComposerStates[handle].state);
Marissa Wall78b72202019-03-15 14:58:34 -0700662 if (!(s->what & layer_state_t::eBufferChanged)) {
663 continue;
Robert Carr28037922020-04-08 10:57:07 -0700664 } else if (s->what & layer_state_t::eCachedBufferChanged) {
665 // If eBufferChanged and eCachedBufferChanged are both trued then that means
666 // we already cached the buffer in a previous call to cacheBuffers, perhaps
667 // from writeToParcel on a Transaction that was merged in to this one.
668 continue;
Marissa Wall78b72202019-03-15 14:58:34 -0700669 }
670
Marissa Wall00597242019-03-27 10:35:19 -0700671 // Don't try to cache a null buffer. Sending null buffers is cheap so we shouldn't waste
672 // time trying to cache them.
673 if (!s->buffer) {
674 continue;
675 }
676
Marissa Wall78b72202019-03-15 14:58:34 -0700677 uint64_t cacheId = 0;
678 status_t ret = BufferCache::getInstance().getCacheId(s->buffer, &cacheId);
679 if (ret == NO_ERROR) {
Robert Carre06ad2b2020-04-10 15:09:33 -0700680 // Cache-hit. Strip the buffer and send only the id.
Marissa Walla141abe2019-03-27 16:28:07 -0700681 s->what &= ~static_cast<uint64_t>(layer_state_t::eBufferChanged);
Marissa Wall78b72202019-03-15 14:58:34 -0700682 s->buffer = nullptr;
683 } else {
Robert Carre06ad2b2020-04-10 15:09:33 -0700684 // Cache-miss. Include the buffer and send the new cacheId.
Marissa Wall78b72202019-03-15 14:58:34 -0700685 cacheId = BufferCache::getInstance().cache(s->buffer);
686 }
687 s->what |= layer_state_t::eCachedBufferChanged;
688 s->cachedBuffer.token = BufferCache::getInstance().getToken();
Marissa Wall947d34e2019-03-29 14:03:53 -0700689 s->cachedBuffer.id = cacheId;
Marissa Wall78b72202019-03-15 14:58:34 -0700690
691 // If we have more buffers than the size of the cache, we should stop caching so we don't
692 // evict other buffers in this transaction
693 count++;
694 if (count >= BUFFER_CACHE_MAX_SIZE) {
695 break;
696 }
697 }
Robert Carr6fb1a7e2018-12-11 12:07:25 -0800698}
699
Robert Carr4cdc58f2017-08-23 14:22:20 -0700700status_t SurfaceComposerClient::Transaction::apply(bool synchronous) {
701 if (mStatus != NO_ERROR) {
702 return mStatus;
703 }
704
705 sp<ISurfaceComposer> sf(ComposerService::getComposerService());
706
Valerie Hau9dab9732019-08-20 09:29:25 -0700707 bool hasListenerCallbacks = !mListenerCallbacks.empty();
Marissa Wall3dad52d2019-03-22 14:03:19 -0700708 std::vector<ListenerCallbacks> listenerCallbacks;
Marissa Wallc837b5e2018-10-12 10:04:44 -0700709 // For every listener with registered callbacks
710 for (const auto& [listener, callbackInfo] : mListenerCallbacks) {
711 auto& [callbackIds, surfaceControls] = callbackInfo;
712 if (callbackIds.empty()) {
713 continue;
714 }
715
Valerie Hau9dab9732019-08-20 09:29:25 -0700716 if (surfaceControls.empty()) {
717 listenerCallbacks.emplace_back(IInterface::asBinder(listener), std::move(callbackIds));
718 } else {
719 // If the listener has any SurfaceControls set on this Transaction update the surface
720 // state
721 for (const auto& surfaceControl : surfaceControls) {
722 layer_state_t* s = getLayerState(surfaceControl);
723 if (!s) {
724 ALOGE("failed to get layer state");
725 continue;
726 }
727 std::vector<CallbackId> callbacks(callbackIds.begin(), callbackIds.end());
728 s->what |= layer_state_t::eHasListenerCallbacksChanged;
729 s->listeners.emplace_back(IInterface::asBinder(listener), callbacks);
Marissa Wallc837b5e2018-10-12 10:04:44 -0700730 }
Marissa Wallc837b5e2018-10-12 10:04:44 -0700731 }
732 }
Valerie Hau9dab9732019-08-20 09:29:25 -0700733
Marissa Wall78b72202019-03-15 14:58:34 -0700734 cacheBuffers();
735
Robert Carr4cdc58f2017-08-23 14:22:20 -0700736 Vector<ComposerState> composerStates;
737 Vector<DisplayState> displayStates;
738 uint32_t flags = 0;
739
740 mForceSynchronous |= synchronous;
741
chaviw8e3fe5d2018-02-22 10:55:42 -0800742 for (auto const& kv : mComposerStates){
743 composerStates.add(kv.second);
744 }
745
Adithya Srinivasand3efcb32020-10-20 18:08:22 -0700746 displayStates = std::move(mDisplayStates);
Robert Carr4cdc58f2017-08-23 14:22:20 -0700747
748 if (mForceSynchronous) {
749 flags |= ISurfaceComposer::eSynchronous;
750 }
751 if (mAnimation) {
752 flags |= ISurfaceComposer::eAnimation;
753 }
Dan Stoza84d619e2018-03-28 17:07:36 -0700754 if (mEarlyWakeup) {
755 flags |= ISurfaceComposer::eEarlyWakeup;
756 }
Robert Carr4cdc58f2017-08-23 14:22:20 -0700757
Ady Abrahambf1349c2020-06-12 14:26:18 -0700758 // If both mExplicitEarlyWakeupStart and mExplicitEarlyWakeupEnd are set
759 // it is equivalent for none
760 if (mExplicitEarlyWakeupStart && !mExplicitEarlyWakeupEnd) {
761 flags |= ISurfaceComposer::eExplicitEarlyWakeupStart;
762 }
763 if (mExplicitEarlyWakeupEnd && !mExplicitEarlyWakeupStart) {
764 flags |= ISurfaceComposer::eExplicitEarlyWakeupEnd;
765 }
766
Vishnu Nair277142c2021-01-05 18:35:29 -0800767 sp<IBinder> applyToken = mApplyToken
768 ? mApplyToken
769 : IInterface::asBinder(TransactionCompletedListener::getIInstance());
770
Siarhei Vishniakoufc434ac2021-01-13 10:28:00 -1000771 sf->setTransactionState(mFrameTimelineInfo, composerStates, displayStates, flags, applyToken,
Ady Abrahamf0c56492020-12-17 18:04:15 -0800772 mInputWindowCommands, mDesiredPresentTime, mIsAutoTimestamp,
Marissa Wall3dad52d2019-03-22 14:03:19 -0700773 {} /*uncacheBuffer - only set in doUncacheBufferTransaction*/,
Adithya Srinivasand3efcb32020-10-20 18:08:22 -0700774 hasListenerCallbacks, listenerCallbacks, mId);
775 mId = generateId();
776
777 // Clear the current states and flags
778 clear();
779
Robert Carr4cdc58f2017-08-23 14:22:20 -0700780 mStatus = NO_ERROR;
781 return NO_ERROR;
Mathias Agopiane57f2922012-08-09 16:29:12 -0700782}
783
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800784// ---------------------------------------------------------------------------
785
Robert Carr4cdc58f2017-08-23 14:22:20 -0700786sp<IBinder> SurfaceComposerClient::createDisplay(const String8& displayName, bool secure) {
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700787 return ComposerService::getComposerService()->createDisplay(displayName,
788 secure);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700789}
790
Robert Carr4cdc58f2017-08-23 14:22:20 -0700791void SurfaceComposerClient::destroyDisplay(const sp<IBinder>& display) {
Jesse Hall6c913be2013-08-08 12:15:49 -0700792 return ComposerService::getComposerService()->destroyDisplay(display);
793}
794
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -0800795std::vector<PhysicalDisplayId> SurfaceComposerClient::getPhysicalDisplayIds() {
796 return ComposerService::getComposerService()->getPhysicalDisplayIds();
797}
798
799std::optional<PhysicalDisplayId> SurfaceComposerClient::getInternalDisplayId() {
800 return ComposerService::getComposerService()->getInternalDisplayId();
801}
802
803sp<IBinder> SurfaceComposerClient::getPhysicalDisplayToken(PhysicalDisplayId displayId) {
804 return ComposerService::getComposerService()->getPhysicalDisplayToken(displayId);
805}
806
807sp<IBinder> SurfaceComposerClient::getInternalDisplayToken() {
808 return ComposerService::getComposerService()->getInternalDisplayToken();
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700809}
810
Robert Carr4cdc58f2017-08-23 14:22:20 -0700811void SurfaceComposerClient::Transaction::setAnimationTransaction() {
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700812 mAnimation = true;
813}
814
Dan Stoza84d619e2018-03-28 17:07:36 -0700815void SurfaceComposerClient::Transaction::setEarlyWakeup() {
816 mEarlyWakeup = true;
817}
818
Ady Abrahambf1349c2020-06-12 14:26:18 -0700819void SurfaceComposerClient::Transaction::setExplicitEarlyWakeupStart() {
820 mExplicitEarlyWakeupStart = true;
821}
822
823void SurfaceComposerClient::Transaction::setExplicitEarlyWakeupEnd() {
824 mExplicitEarlyWakeupEnd = true;
825}
826
Pablo Gamitodbc31672020-09-01 18:28:58 +0000827layer_state_t* SurfaceComposerClient::Transaction::getLayerState(const sp<SurfaceControl>& sc) {
828 auto handle = sc->getHandle();
829
Vishnu Nairf03652d2019-07-16 17:56:56 -0700830 if (mComposerStates.count(handle) == 0) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700831 // we don't have it, add an initialized layer_state to our list
chaviw8e3fe5d2018-02-22 10:55:42 -0800832 ComposerState s;
Pablo Gamitodbc31672020-09-01 18:28:58 +0000833
Vishnu Nairf03652d2019-07-16 17:56:56 -0700834 s.state.surface = handle;
Pablo Gamitodbc31672020-09-01 18:28:58 +0000835 s.state.layerId = sc->getLayerId();
836
Vishnu Nairf03652d2019-07-16 17:56:56 -0700837 mComposerStates[handle] = s;
Mathias Agopian698c0872011-06-28 19:09:31 -0700838 }
839
Vishnu Nairf03652d2019-07-16 17:56:56 -0700840 return &(mComposerStates[handle].state);
Mathias Agopian698c0872011-06-28 19:09:31 -0700841}
842
Marissa Wallc837b5e2018-10-12 10:04:44 -0700843void SurfaceComposerClient::Transaction::registerSurfaceControlForCallback(
844 const sp<SurfaceControl>& sc) {
Marissa Wall80d94ad2019-01-18 16:04:36 -0800845 auto& callbackInfo = mListenerCallbacks[TransactionCompletedListener::getIInstance()];
846 callbackInfo.surfaceControls.insert(sc);
847
848 TransactionCompletedListener::getInstance()
849 ->addSurfaceControlToCallbacks(sc, callbackInfo.callbackIds);
Marissa Wallc837b5e2018-10-12 10:04:44 -0700850}
851
Robert Carr4cdc58f2017-08-23 14:22:20 -0700852SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setPosition(
853 const sp<SurfaceControl>& sc, float x, float y) {
chaviw763ef572018-02-22 16:04:57 -0800854 layer_state_t* s = getLayerState(sc);
Robert Carr4cdc58f2017-08-23 14:22:20 -0700855 if (!s) {
856 mStatus = BAD_INDEX;
857 return *this;
858 }
Mathias Agopian3165cc22012-08-08 19:42:09 -0700859 s->what |= layer_state_t::ePositionChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700860 s->x = x;
861 s->y = y;
Marissa Wallc837b5e2018-10-12 10:04:44 -0700862
863 registerSurfaceControlForCallback(sc);
Robert Carr4cdc58f2017-08-23 14:22:20 -0700864 return *this;
Mathias Agopian698c0872011-06-28 19:09:31 -0700865}
866
Robert Carr4cdc58f2017-08-23 14:22:20 -0700867SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::show(
868 const sp<SurfaceControl>& sc) {
869 return setFlags(sc, 0, layer_state_t::eLayerHidden);
870}
871
872SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::hide(
873 const sp<SurfaceControl>& sc) {
874 return setFlags(sc, layer_state_t::eLayerHidden, layer_state_t::eLayerHidden);
875}
876
877SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setSize(
878 const sp<SurfaceControl>& sc, uint32_t w, uint32_t h) {
chaviw763ef572018-02-22 16:04:57 -0800879 layer_state_t* s = getLayerState(sc);
Robert Carr4cdc58f2017-08-23 14:22:20 -0700880 if (!s) {
881 mStatus = BAD_INDEX;
882 return *this;
883 }
Mathias Agopian3165cc22012-08-08 19:42:09 -0700884 s->what |= layer_state_t::eSizeChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700885 s->w = w;
886 s->h = h;
Jamie Gennis28378392011-10-12 17:39:00 -0700887
Marissa Wallc837b5e2018-10-12 10:04:44 -0700888 registerSurfaceControlForCallback(sc);
Robert Carr4cdc58f2017-08-23 14:22:20 -0700889 return *this;
Mathias Agopian698c0872011-06-28 19:09:31 -0700890}
891
Robert Carr4cdc58f2017-08-23 14:22:20 -0700892SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setLayer(
893 const sp<SurfaceControl>& sc, int32_t z) {
chaviw763ef572018-02-22 16:04:57 -0800894 layer_state_t* s = getLayerState(sc);
Robert Carr4cdc58f2017-08-23 14:22:20 -0700895 if (!s) {
896 mStatus = BAD_INDEX;
897 return *this;
898 }
Mathias Agopian3165cc22012-08-08 19:42:09 -0700899 s->what |= layer_state_t::eLayerChanged;
chaviw32377582019-05-13 11:15:19 -0700900 s->what &= ~layer_state_t::eRelativeLayerChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700901 s->z = z;
Marissa Wallc837b5e2018-10-12 10:04:44 -0700902
903 registerSurfaceControlForCallback(sc);
Robert Carr4cdc58f2017-08-23 14:22:20 -0700904 return *this;
Mathias Agopian698c0872011-06-28 19:09:31 -0700905}
906
Pablo Gamito11dcc222020-09-12 15:49:39 +0000907SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setRelativeLayer(
908 const sp<SurfaceControl>& sc, const sp<SurfaceControl>& relativeTo, int32_t z) {
chaviw763ef572018-02-22 16:04:57 -0800909 layer_state_t* s = getLayerState(sc);
Robert Carrdb66e622017-04-10 16:55:57 -0700910 if (!s) {
Robert Carr4cdc58f2017-08-23 14:22:20 -0700911 mStatus = BAD_INDEX;
Robert Carr30c8d902019-04-04 13:12:49 -0700912 return *this;
Robert Carrdb66e622017-04-10 16:55:57 -0700913 }
914 s->what |= layer_state_t::eRelativeLayerChanged;
chaviw32377582019-05-13 11:15:19 -0700915 s->what &= ~layer_state_t::eLayerChanged;
Pablo Gamito11dcc222020-09-12 15:49:39 +0000916 s->relativeLayerSurfaceControl = relativeTo;
Robert Carrdb66e622017-04-10 16:55:57 -0700917 s->z = z;
Marissa Wallc837b5e2018-10-12 10:04:44 -0700918
919 registerSurfaceControlForCallback(sc);
Robert Carr4cdc58f2017-08-23 14:22:20 -0700920 return *this;
Robert Carrdb66e622017-04-10 16:55:57 -0700921}
922
Robert Carr4cdc58f2017-08-23 14:22:20 -0700923SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setFlags(
924 const sp<SurfaceControl>& sc, uint32_t flags,
Mathias Agopian698c0872011-06-28 19:09:31 -0700925 uint32_t mask) {
chaviw763ef572018-02-22 16:04:57 -0800926 layer_state_t* s = getLayerState(sc);
Robert Carr4cdc58f2017-08-23 14:22:20 -0700927 if (!s) {
928 mStatus = BAD_INDEX;
929 return *this;
930 }
chaviwc5676c62020-09-18 15:01:04 -0700931 if ((mask & layer_state_t::eLayerOpaque) || (mask & layer_state_t::eLayerHidden) ||
Vishnu Nairf6eddb62021-01-27 22:02:11 -0800932 (mask & layer_state_t::eLayerSecure) || (mask & layer_state_t::eLayerSkipScreenshot) ||
933 (mask & layer_state_t::eEnableBackpressure)) {
Dan Stoza23116082015-06-18 14:58:39 -0700934 s->what |= layer_state_t::eFlagsChanged;
Andy McFadden4125a4f2014-01-29 17:17:11 -0800935 }
Mathias Agopian698c0872011-06-28 19:09:31 -0700936 s->flags &= ~mask;
937 s->flags |= (flags & mask);
938 s->mask |= mask;
Marissa Wallc837b5e2018-10-12 10:04:44 -0700939
940 registerSurfaceControlForCallback(sc);
Robert Carr4cdc58f2017-08-23 14:22:20 -0700941 return *this;
Mathias Agopian698c0872011-06-28 19:09:31 -0700942}
943
Robert Carr4cdc58f2017-08-23 14:22:20 -0700944SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setTransparentRegionHint(
945 const sp<SurfaceControl>& sc,
Mathias Agopian698c0872011-06-28 19:09:31 -0700946 const Region& transparentRegion) {
chaviw763ef572018-02-22 16:04:57 -0800947 layer_state_t* s = getLayerState(sc);
Robert Carr4cdc58f2017-08-23 14:22:20 -0700948 if (!s) {
949 mStatus = BAD_INDEX;
950 return *this;
951 }
Mathias Agopian3165cc22012-08-08 19:42:09 -0700952 s->what |= layer_state_t::eTransparentRegionChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700953 s->transparentRegion = transparentRegion;
Marissa Wallc837b5e2018-10-12 10:04:44 -0700954
955 registerSurfaceControlForCallback(sc);
Robert Carr4cdc58f2017-08-23 14:22:20 -0700956 return *this;
Mathias Agopian698c0872011-06-28 19:09:31 -0700957}
958
Robert Carr4cdc58f2017-08-23 14:22:20 -0700959SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setAlpha(
960 const sp<SurfaceControl>& sc, float alpha) {
chaviw763ef572018-02-22 16:04:57 -0800961 layer_state_t* s = getLayerState(sc);
Robert Carr4cdc58f2017-08-23 14:22:20 -0700962 if (!s) {
963 mStatus = BAD_INDEX;
964 return *this;
965 }
Mathias Agopian3165cc22012-08-08 19:42:09 -0700966 s->what |= layer_state_t::eAlphaChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700967 s->alpha = alpha;
Marissa Wallc837b5e2018-10-12 10:04:44 -0700968
969 registerSurfaceControlForCallback(sc);
Robert Carr4cdc58f2017-08-23 14:22:20 -0700970 return *this;
Mathias Agopian698c0872011-06-28 19:09:31 -0700971}
972
Robert Carr4cdc58f2017-08-23 14:22:20 -0700973SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setLayerStack(
974 const sp<SurfaceControl>& sc, uint32_t layerStack) {
chaviw763ef572018-02-22 16:04:57 -0800975 layer_state_t* s = getLayerState(sc);
Robert Carr4cdc58f2017-08-23 14:22:20 -0700976 if (!s) {
977 mStatus = BAD_INDEX;
978 return *this;
979 }
Mathias Agopian3165cc22012-08-08 19:42:09 -0700980 s->what |= layer_state_t::eLayerStackChanged;
Mathias Agopian87855782012-07-24 21:41:09 -0700981 s->layerStack = layerStack;
Marissa Wallc837b5e2018-10-12 10:04:44 -0700982
983 registerSurfaceControlForCallback(sc);
Robert Carr4cdc58f2017-08-23 14:22:20 -0700984 return *this;
Mathias Agopian87855782012-07-24 21:41:09 -0700985}
986
Evan Rosky1f6d6d52018-12-06 10:47:26 -0800987SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setMetadata(
Garfield Tan01a56132019-08-05 16:44:21 -0700988 const sp<SurfaceControl>& sc, uint32_t key, const Parcel& p) {
Evan Rosky1f6d6d52018-12-06 10:47:26 -0800989 layer_state_t* s = getLayerState(sc);
990 if (!s) {
991 mStatus = BAD_INDEX;
992 return *this;
993 }
994 s->what |= layer_state_t::eMetadataChanged;
Garfield Tan01a56132019-08-05 16:44:21 -0700995
996 s->metadata.mMap[key] = {p.data(), p.data() + p.dataSize()};
Evan Rosky1f6d6d52018-12-06 10:47:26 -0800997
998 registerSurfaceControlForCallback(sc);
999 return *this;
1000}
1001
Robert Carr4cdc58f2017-08-23 14:22:20 -07001002SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setMatrix(
1003 const sp<SurfaceControl>& sc, float dsdx, float dtdx,
Robert Carrcb6e1e32017-02-21 19:48:26 -08001004 float dtdy, float dsdy) {
chaviw763ef572018-02-22 16:04:57 -08001005 layer_state_t* s = getLayerState(sc);
Robert Carr4cdc58f2017-08-23 14:22:20 -07001006 if (!s) {
1007 mStatus = BAD_INDEX;
1008 return *this;
1009 }
Mathias Agopian3165cc22012-08-08 19:42:09 -07001010 s->what |= layer_state_t::eMatrixChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -07001011 layer_state_t::matrix22_t matrix;
1012 matrix.dsdx = dsdx;
1013 matrix.dtdx = dtdx;
1014 matrix.dsdy = dsdy;
1015 matrix.dtdy = dtdy;
1016 s->matrix = matrix;
Marissa Wallc837b5e2018-10-12 10:04:44 -07001017
1018 registerSurfaceControlForCallback(sc);
Robert Carr4cdc58f2017-08-23 14:22:20 -07001019 return *this;
Mathias Agopian698c0872011-06-28 19:09:31 -07001020}
1021
Marissa Wallf58c14b2018-07-24 10:50:43 -07001022SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setCrop_legacy(
Robert Carr4cdc58f2017-08-23 14:22:20 -07001023 const sp<SurfaceControl>& sc, const Rect& crop) {
chaviw763ef572018-02-22 16:04:57 -08001024 layer_state_t* s = getLayerState(sc);
Robert Carr4cdc58f2017-08-23 14:22:20 -07001025 if (!s) {
1026 mStatus = BAD_INDEX;
1027 return *this;
1028 }
Marissa Wallf58c14b2018-07-24 10:50:43 -07001029 s->what |= layer_state_t::eCropChanged_legacy;
1030 s->crop_legacy = crop;
Marissa Wallc837b5e2018-10-12 10:04:44 -07001031
1032 registerSurfaceControlForCallback(sc);
Robert Carr4cdc58f2017-08-23 14:22:20 -07001033 return *this;
Jamie Gennisf15a83f2012-05-10 20:43:55 -07001034}
1035
Lucas Dupin1b6531c2018-07-05 17:18:21 -07001036SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setCornerRadius(
1037 const sp<SurfaceControl>& sc, float cornerRadius) {
1038 layer_state_t* s = getLayerState(sc);
1039 if (!s) {
1040 mStatus = BAD_INDEX;
1041 return *this;
1042 }
1043 s->what |= layer_state_t::eCornerRadiusChanged;
1044 s->cornerRadius = cornerRadius;
1045 return *this;
1046}
1047
Lucas Dupin19c8f0e2019-11-25 17:55:44 -08001048SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setBackgroundBlurRadius(
1049 const sp<SurfaceControl>& sc, int backgroundBlurRadius) {
1050 layer_state_t* s = getLayerState(sc);
1051 if (!s) {
1052 mStatus = BAD_INDEX;
1053 return *this;
1054 }
1055 s->what |= layer_state_t::eBackgroundBlurRadiusChanged;
1056 s->backgroundBlurRadius = backgroundBlurRadius;
1057 return *this;
1058}
1059
Lucas Dupinc3800b82020-10-02 16:24:48 -07001060SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setBlurRegions(
1061 const sp<SurfaceControl>& sc, const std::vector<BlurRegion>& blurRegions) {
1062 layer_state_t* s = getLayerState(sc);
1063 if (!s) {
1064 mStatus = BAD_INDEX;
1065 return *this;
1066 }
1067 s->what |= layer_state_t::eBlurRegionsChanged;
1068 s->blurRegions = blurRegions;
1069 return *this;
1070}
1071
Marissa Wallf58c14b2018-07-24 10:50:43 -07001072SurfaceComposerClient::Transaction&
Pablo Gamito11dcc222020-09-12 15:49:39 +00001073SurfaceComposerClient::Transaction::deferTransactionUntil_legacy(
1074 const sp<SurfaceControl>& sc, const sp<SurfaceControl>& barrierSurfaceControl,
1075 uint64_t frameNumber) {
chaviw763ef572018-02-22 16:04:57 -08001076 layer_state_t* s = getLayerState(sc);
Dan Stoza7dde5992015-05-22 09:51:44 -07001077 if (!s) {
Robert Carr4cdc58f2017-08-23 14:22:20 -07001078 mStatus = BAD_INDEX;
1079 return *this;
Dan Stoza7dde5992015-05-22 09:51:44 -07001080 }
Marissa Wallf58c14b2018-07-24 10:50:43 -07001081 s->what |= layer_state_t::eDeferTransaction_legacy;
Pablo Gamito11dcc222020-09-12 15:49:39 +00001082 s->barrierSurfaceControl_legacy = barrierSurfaceControl;
Vishnu Nair6b7c5c92020-09-29 17:27:05 -07001083 s->barrierFrameNumber = frameNumber;
Marissa Wallc837b5e2018-10-12 10:04:44 -07001084
1085 registerSurfaceControlForCallback(sc);
Robert Carr4cdc58f2017-08-23 14:22:20 -07001086 return *this;
Robert Carr0d480722017-01-10 16:42:54 -08001087}
1088
Robert Carr4cdc58f2017-08-23 14:22:20 -07001089SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::reparentChildren(
Pablo Gamito11dcc222020-09-12 15:49:39 +00001090 const sp<SurfaceControl>& sc, const sp<SurfaceControl>& newParent) {
chaviw763ef572018-02-22 16:04:57 -08001091 layer_state_t* s = getLayerState(sc);
Robert Carr1db73f62016-12-21 12:58:51 -08001092 if (!s) {
Robert Carr4cdc58f2017-08-23 14:22:20 -07001093 mStatus = BAD_INDEX;
1094 return *this;
Robert Carr1db73f62016-12-21 12:58:51 -08001095 }
1096 s->what |= layer_state_t::eReparentChildren;
Pablo Gamito11dcc222020-09-12 15:49:39 +00001097 s->reparentSurfaceControl = newParent;
Marissa Wallc837b5e2018-10-12 10:04:44 -07001098
1099 registerSurfaceControlForCallback(sc);
Robert Carr4cdc58f2017-08-23 14:22:20 -07001100 return *this;
Robert Carr1db73f62016-12-21 12:58:51 -08001101}
1102
Robert Carr4cdc58f2017-08-23 14:22:20 -07001103SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::reparent(
Pablo Gamito11dcc222020-09-12 15:49:39 +00001104 const sp<SurfaceControl>& sc, const sp<SurfaceControl>& newParent) {
chaviw763ef572018-02-22 16:04:57 -08001105 layer_state_t* s = getLayerState(sc);
chaviw06178942017-07-27 10:25:59 -07001106 if (!s) {
Robert Carr4cdc58f2017-08-23 14:22:20 -07001107 mStatus = BAD_INDEX;
1108 return *this;
chaviw06178942017-07-27 10:25:59 -07001109 }
chaviwf1961f72017-09-18 16:41:07 -07001110 s->what |= layer_state_t::eReparent;
Pablo Gamito11dcc222020-09-12 15:49:39 +00001111 s->parentSurfaceControlForChild = newParent;
Marissa Wallc837b5e2018-10-12 10:04:44 -07001112
1113 registerSurfaceControlForCallback(sc);
Robert Carr4cdc58f2017-08-23 14:22:20 -07001114 return *this;
chaviw06178942017-07-27 10:25:59 -07001115}
1116
Robert Carr4cdc58f2017-08-23 14:22:20 -07001117SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setColor(
1118 const sp<SurfaceControl>& sc,
1119 const half3& color) {
chaviw763ef572018-02-22 16:04:57 -08001120 layer_state_t* s = getLayerState(sc);
Robert Carr9524cb32017-02-13 11:32:32 -08001121 if (!s) {
Robert Carr4cdc58f2017-08-23 14:22:20 -07001122 mStatus = BAD_INDEX;
1123 return *this;
1124 }
1125 s->what |= layer_state_t::eColorChanged;
1126 s->color = color;
Marissa Wallc837b5e2018-10-12 10:04:44 -07001127
1128 registerSurfaceControlForCallback(sc);
Robert Carr4cdc58f2017-08-23 14:22:20 -07001129 return *this;
1130}
1131
Valerie Haudd0b7572019-01-29 14:59:27 -08001132SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setBackgroundColor(
1133 const sp<SurfaceControl>& sc, const half3& color, float alpha, ui::Dataspace dataspace) {
Valerie Haued54efa2019-01-11 20:03:14 -08001134 layer_state_t* s = getLayerState(sc);
1135 if (!s) {
1136 mStatus = BAD_INDEX;
1137 return *this;
1138 }
1139
Valerie Haudd0b7572019-01-29 14:59:27 -08001140 s->what |= layer_state_t::eBackgroundColorChanged;
1141 s->color = color;
1142 s->bgColorAlpha = alpha;
1143 s->bgColorDataspace = dataspace;
Valerie Haued54efa2019-01-11 20:03:14 -08001144
1145 registerSurfaceControlForCallback(sc);
1146 return *this;
1147}
1148
Marissa Wall61c58622018-07-18 10:12:20 -07001149SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setTransform(
1150 const sp<SurfaceControl>& sc, uint32_t transform) {
1151 layer_state_t* s = getLayerState(sc);
1152 if (!s) {
1153 mStatus = BAD_INDEX;
1154 return *this;
1155 }
1156 s->what |= layer_state_t::eTransformChanged;
1157 s->transform = transform;
Marissa Wallc837b5e2018-10-12 10:04:44 -07001158
1159 registerSurfaceControlForCallback(sc);
Marissa Wall61c58622018-07-18 10:12:20 -07001160 return *this;
1161}
1162
1163SurfaceComposerClient::Transaction&
1164SurfaceComposerClient::Transaction::setTransformToDisplayInverse(const sp<SurfaceControl>& sc,
1165 bool transformToDisplayInverse) {
1166 layer_state_t* s = getLayerState(sc);
1167 if (!s) {
1168 mStatus = BAD_INDEX;
1169 return *this;
1170 }
1171 s->what |= layer_state_t::eTransformToDisplayInverseChanged;
1172 s->transformToDisplayInverse = transformToDisplayInverse;
Marissa Wallc837b5e2018-10-12 10:04:44 -07001173
1174 registerSurfaceControlForCallback(sc);
Marissa Wall61c58622018-07-18 10:12:20 -07001175 return *this;
1176}
1177
1178SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setCrop(
1179 const sp<SurfaceControl>& sc, const Rect& crop) {
1180 layer_state_t* s = getLayerState(sc);
1181 if (!s) {
1182 mStatus = BAD_INDEX;
1183 return *this;
1184 }
1185 s->what |= layer_state_t::eCropChanged;
1186 s->crop = crop;
Marissa Wallc837b5e2018-10-12 10:04:44 -07001187
1188 registerSurfaceControlForCallback(sc);
Marissa Wall61c58622018-07-18 10:12:20 -07001189 return *this;
1190}
1191
Marissa Wall861616d2018-10-22 12:52:23 -07001192SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setFrame(
1193 const sp<SurfaceControl>& sc, const Rect& frame) {
1194 layer_state_t* s = getLayerState(sc);
1195 if (!s) {
1196 mStatus = BAD_INDEX;
1197 return *this;
1198 }
1199 s->what |= layer_state_t::eFrameChanged;
Marin Shalamanov6ad317c2020-07-29 23:34:07 +02001200 s->orientedDisplaySpaceRect = frame;
Marissa Wall861616d2018-10-22 12:52:23 -07001201
1202 registerSurfaceControlForCallback(sc);
1203 return *this;
1204}
1205
Marissa Wall61c58622018-07-18 10:12:20 -07001206SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setBuffer(
1207 const sp<SurfaceControl>& sc, const sp<GraphicBuffer>& buffer) {
1208 layer_state_t* s = getLayerState(sc);
1209 if (!s) {
1210 mStatus = BAD_INDEX;
1211 return *this;
1212 }
Marissa Wall78b72202019-03-15 14:58:34 -07001213 s->what |= layer_state_t::eBufferChanged;
1214 s->buffer = buffer;
Ady Abrahamf0c56492020-12-17 18:04:15 -08001215 if (mIsAutoTimestamp) {
1216 mDesiredPresentTime = systemTime();
1217 }
Marissa Wallebc2c052019-01-16 19:16:55 -08001218
1219 registerSurfaceControlForCallback(sc);
Marissa Wall78b72202019-03-15 14:58:34 -07001220
1221 mContainsBuffer = true;
Marissa Wallebc2c052019-01-16 19:16:55 -08001222 return *this;
1223}
1224
Marissa Wall61c58622018-07-18 10:12:20 -07001225SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setAcquireFence(
1226 const sp<SurfaceControl>& sc, const sp<Fence>& fence) {
1227 layer_state_t* s = getLayerState(sc);
1228 if (!s) {
1229 mStatus = BAD_INDEX;
1230 return *this;
1231 }
1232 s->what |= layer_state_t::eAcquireFenceChanged;
1233 s->acquireFence = fence;
Marissa Wallc837b5e2018-10-12 10:04:44 -07001234
1235 registerSurfaceControlForCallback(sc);
Marissa Wall61c58622018-07-18 10:12:20 -07001236 return *this;
1237}
1238
1239SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setDataspace(
1240 const sp<SurfaceControl>& sc, ui::Dataspace dataspace) {
1241 layer_state_t* s = getLayerState(sc);
1242 if (!s) {
1243 mStatus = BAD_INDEX;
1244 return *this;
1245 }
1246 s->what |= layer_state_t::eDataspaceChanged;
1247 s->dataspace = dataspace;
Marissa Wallc837b5e2018-10-12 10:04:44 -07001248
1249 registerSurfaceControlForCallback(sc);
Marissa Wall61c58622018-07-18 10:12:20 -07001250 return *this;
1251}
1252
1253SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setHdrMetadata(
1254 const sp<SurfaceControl>& sc, const HdrMetadata& hdrMetadata) {
1255 layer_state_t* s = getLayerState(sc);
1256 if (!s) {
1257 mStatus = BAD_INDEX;
1258 return *this;
1259 }
1260 s->what |= layer_state_t::eHdrMetadataChanged;
1261 s->hdrMetadata = hdrMetadata;
Marissa Wallc837b5e2018-10-12 10:04:44 -07001262
1263 registerSurfaceControlForCallback(sc);
Marissa Wall61c58622018-07-18 10:12:20 -07001264 return *this;
1265}
1266
1267SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setSurfaceDamageRegion(
1268 const sp<SurfaceControl>& sc, const Region& surfaceDamageRegion) {
1269 layer_state_t* s = getLayerState(sc);
1270 if (!s) {
1271 mStatus = BAD_INDEX;
1272 return *this;
1273 }
1274 s->what |= layer_state_t::eSurfaceDamageRegionChanged;
1275 s->surfaceDamageRegion = surfaceDamageRegion;
Marissa Wallc837b5e2018-10-12 10:04:44 -07001276
1277 registerSurfaceControlForCallback(sc);
Marissa Wall61c58622018-07-18 10:12:20 -07001278 return *this;
1279}
1280
1281SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setApi(
1282 const sp<SurfaceControl>& sc, int32_t api) {
1283 layer_state_t* s = getLayerState(sc);
1284 if (!s) {
1285 mStatus = BAD_INDEX;
1286 return *this;
1287 }
1288 s->what |= layer_state_t::eApiChanged;
1289 s->api = api;
Marissa Wallc837b5e2018-10-12 10:04:44 -07001290
1291 registerSurfaceControlForCallback(sc);
Marissa Wall61c58622018-07-18 10:12:20 -07001292 return *this;
1293}
1294
1295SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setSidebandStream(
1296 const sp<SurfaceControl>& sc, const sp<NativeHandle>& sidebandStream) {
1297 layer_state_t* s = getLayerState(sc);
1298 if (!s) {
1299 mStatus = BAD_INDEX;
1300 return *this;
1301 }
1302 s->what |= layer_state_t::eSidebandStreamChanged;
1303 s->sidebandStream = sidebandStream;
Marissa Wallc837b5e2018-10-12 10:04:44 -07001304
1305 registerSurfaceControlForCallback(sc);
1306 return *this;
1307}
1308
Marissa Wall17b4e452018-12-26 16:32:34 -08001309SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setDesiredPresentTime(
1310 nsecs_t desiredPresentTime) {
1311 mDesiredPresentTime = desiredPresentTime;
Ady Abrahamf0c56492020-12-17 18:04:15 -08001312 mIsAutoTimestamp = false;
Marissa Wall17b4e452018-12-26 16:32:34 -08001313 return *this;
1314}
1315
Peiyong Linc502cb72019-03-01 15:00:23 -08001316SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setColorSpaceAgnostic(
1317 const sp<SurfaceControl>& sc, const bool agnostic) {
1318 layer_state_t* s = getLayerState(sc);
1319 if (!s) {
1320 mStatus = BAD_INDEX;
1321 return *this;
1322 }
1323 s->what |= layer_state_t::eColorSpaceAgnosticChanged;
1324 s->colorSpaceAgnostic = agnostic;
1325
1326 registerSurfaceControlForCallback(sc);
1327 return *this;
1328}
1329
Marissa Wallc837b5e2018-10-12 10:04:44 -07001330SurfaceComposerClient::Transaction&
Ana Krulecc84d09b2019-11-02 23:10:29 +01001331SurfaceComposerClient::Transaction::setFrameRateSelectionPriority(const sp<SurfaceControl>& sc,
1332 int32_t priority) {
1333 layer_state_t* s = getLayerState(sc);
1334 if (!s) {
1335 mStatus = BAD_INDEX;
1336 return *this;
1337 }
1338
1339 s->what |= layer_state_t::eFrameRateSelectionPriority;
1340 s->frameRateSelectionPriority = priority;
1341
1342 registerSurfaceControlForCallback(sc);
1343 return *this;
1344}
1345
1346SurfaceComposerClient::Transaction&
Marissa Wallc837b5e2018-10-12 10:04:44 -07001347SurfaceComposerClient::Transaction::addTransactionCompletedCallback(
Marissa Walle2ffb422018-10-12 11:33:52 -07001348 TransactionCompletedCallbackTakesContext callback, void* callbackContext) {
Marissa Wallc837b5e2018-10-12 10:04:44 -07001349 auto listener = TransactionCompletedListener::getInstance();
1350
Marissa Wall80d94ad2019-01-18 16:04:36 -08001351 auto callbackWithContext = std::bind(callback, callbackContext, std::placeholders::_1,
1352 std::placeholders::_2, std::placeholders::_3);
1353 const auto& surfaceControls =
1354 mListenerCallbacks[TransactionCompletedListener::getIInstance()].surfaceControls;
Marissa Wallc837b5e2018-10-12 10:04:44 -07001355
Marissa Wall80d94ad2019-01-18 16:04:36 -08001356 CallbackId callbackId = listener->addCallbackFunction(callbackWithContext, surfaceControls);
Marissa Wallc837b5e2018-10-12 10:04:44 -07001357
1358 mListenerCallbacks[TransactionCompletedListener::getIInstance()].callbackIds.emplace(
1359 callbackId);
Marissa Wall61c58622018-07-18 10:12:20 -07001360 return *this;
1361}
1362
Valerie Hau871d6352020-01-29 08:44:02 -08001363SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::notifyProducerDisconnect(
1364 const sp<SurfaceControl>& sc) {
1365 layer_state_t* s = getLayerState(sc);
1366 if (!s) {
1367 mStatus = BAD_INDEX;
1368 return *this;
1369 }
1370
1371 s->what |= layer_state_t::eProducerDisconnect;
1372 return *this;
1373}
1374
Vishnu Nair6b7c5c92020-09-29 17:27:05 -07001375SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setFrameNumber(
1376 const sp<SurfaceControl>& sc, uint64_t frameNumber) {
1377 layer_state_t* s = getLayerState(sc);
1378 if (!s) {
1379 mStatus = BAD_INDEX;
1380 return *this;
1381 }
1382
1383 s->what |= layer_state_t::eFrameNumberChanged;
1384 s->frameNumber = frameNumber;
1385
1386 return *this;
1387}
1388
Robert Carr2c358bf2018-08-08 15:58:15 -07001389#ifndef NO_INPUT
1390SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setInputWindowInfo(
1391 const sp<SurfaceControl>& sc,
1392 const InputWindowInfo& info) {
1393 layer_state_t* s = getLayerState(sc);
1394 if (!s) {
1395 mStatus = BAD_INDEX;
1396 return *this;
1397 }
Chris Ye0783e992020-06-02 21:34:49 -07001398 s->inputHandle = new InputWindowHandle(info);
Robert Carr2c358bf2018-08-08 15:58:15 -07001399 s->what |= layer_state_t::eInputInfoChanged;
1400 return *this;
1401}
chaviw273171b2018-12-26 11:46:30 -08001402
Vishnu Naire798b472020-07-23 13:52:21 -07001403SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setFocusedWindow(
Vishnu Naire798b472020-07-23 13:52:21 -07001404 const FocusRequest& request) {
1405 mInputWindowCommands.focusRequests.push_back(request);
1406 return *this;
1407}
1408
chaviwa911b102019-02-14 10:18:33 -08001409SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::syncInputWindows() {
1410 mInputWindowCommands.syncInputWindows = true;
1411 return *this;
1412}
1413
Robert Carr2c358bf2018-08-08 15:58:15 -07001414#endif
1415
Peiyong Lind3788632018-09-18 16:01:31 -07001416SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setColorTransform(
1417 const sp<SurfaceControl>& sc, const mat3& matrix, const vec3& translation) {
1418 layer_state_t* s = getLayerState(sc);
1419 if (!s) {
1420 mStatus = BAD_INDEX;
1421 return *this;
1422 }
1423 s->what |= layer_state_t::eColorTransformChanged;
1424 s->colorTransform = mat4(matrix, translation);
Marissa Wallc837b5e2018-10-12 10:04:44 -07001425
1426 registerSurfaceControlForCallback(sc);
Peiyong Lind3788632018-09-18 16:01:31 -07001427 return *this;
1428}
1429
Robert Carrfb4d58b2019-01-15 09:21:27 -08001430SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setGeometry(
1431 const sp<SurfaceControl>& sc, const Rect& source, const Rect& dst, int transform) {
1432 setCrop_legacy(sc, source);
1433
1434 int x = dst.left;
1435 int y = dst.top;
Robert Carr66365e42019-04-08 16:58:04 -07001436
1437 float sourceWidth = source.getWidth();
1438 float sourceHeight = source.getHeight();
1439
1440 float xScale = sourceWidth < 0 ? 1.0f : dst.getWidth() / sourceWidth;
1441 float yScale = sourceHeight < 0 ? 1.0f : dst.getHeight() / sourceHeight;
Robert Carrfb4d58b2019-01-15 09:21:27 -08001442 float matrix[4] = {1, 0, 0, 1};
1443
1444 switch (transform) {
1445 case NATIVE_WINDOW_TRANSFORM_FLIP_H:
1446 matrix[0] = -xScale; matrix[1] = 0;
1447 matrix[2] = 0; matrix[3] = yScale;
1448 x += source.getWidth();
1449 break;
1450 case NATIVE_WINDOW_TRANSFORM_FLIP_V:
1451 matrix[0] = xScale; matrix[1] = 0;
1452 matrix[2] = 0; matrix[3] = -yScale;
1453 y += source.getHeight();
1454 break;
1455 case NATIVE_WINDOW_TRANSFORM_ROT_90:
1456 matrix[0] = 0; matrix[1] = -yScale;
1457 matrix[2] = xScale; matrix[3] = 0;
1458 x += source.getHeight();
1459 break;
1460 case NATIVE_WINDOW_TRANSFORM_ROT_180:
1461 matrix[0] = -xScale; matrix[1] = 0;
1462 matrix[2] = 0; matrix[3] = -yScale;
1463 x += source.getWidth();
1464 y += source.getHeight();
1465 break;
1466 case NATIVE_WINDOW_TRANSFORM_ROT_270:
1467 matrix[0] = 0; matrix[1] = yScale;
1468 matrix[2] = -xScale; matrix[3] = 0;
1469 y += source.getWidth();
1470 break;
1471 default:
1472 matrix[0] = xScale; matrix[1] = 0;
1473 matrix[2] = 0; matrix[3] = yScale;
1474 break;
1475 }
1476 setMatrix(sc, matrix[0], matrix[1], matrix[2], matrix[3]);
chaviw76f5f2f2019-09-23 10:15:51 -07001477 float offsetX = xScale * source.left;
1478 float offsetY = yScale * source.top;
1479 setPosition(sc, x - offsetX, y - offsetY);
Robert Carrfb4d58b2019-01-15 09:21:27 -08001480
1481 return *this;
1482}
1483
Vishnu Nairc97b8db2019-10-29 18:19:35 -07001484SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setShadowRadius(
1485 const sp<SurfaceControl>& sc, float shadowRadius) {
1486 layer_state_t* s = getLayerState(sc);
1487 if (!s) {
1488 mStatus = BAD_INDEX;
1489 return *this;
1490 }
1491 s->what |= layer_state_t::eShadowRadiusChanged;
1492 s->shadowRadius = shadowRadius;
1493 return *this;
1494}
1495
Steven Thomas3172e202020-01-06 19:25:30 -08001496SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setFrameRate(
Marin Shalamanov46084422020-10-13 12:33:42 +02001497 const sp<SurfaceControl>& sc, float frameRate, int8_t compatibility,
1498 bool shouldBeSeamless) {
Steven Thomas3172e202020-01-06 19:25:30 -08001499 layer_state_t* s = getLayerState(sc);
1500 if (!s) {
1501 mStatus = BAD_INDEX;
1502 return *this;
1503 }
Ady Abrahamdd5bfa92021-01-07 17:56:08 -08001504 // Allow privileged values as well here, those will be ignored by SF if
1505 // the caller is not privileged
1506 if (!ValidateFrameRate(frameRate, compatibility, "Transaction::setFrameRate",
1507 /*privileged=*/true)) {
Steven Thomas62a4cf82020-01-31 12:04:03 -08001508 mStatus = BAD_VALUE;
1509 return *this;
1510 }
Steven Thomas3172e202020-01-06 19:25:30 -08001511 s->what |= layer_state_t::eFrameRateChanged;
1512 s->frameRate = frameRate;
Steven Thomas62a4cf82020-01-31 12:04:03 -08001513 s->frameRateCompatibility = compatibility;
Marin Shalamanov46084422020-10-13 12:33:42 +02001514 s->shouldBeSeamless = shouldBeSeamless;
Steven Thomas3172e202020-01-06 19:25:30 -08001515 return *this;
1516}
1517
Vishnu Nair6213bd92020-05-08 17:42:25 -07001518SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setFixedTransformHint(
1519 const sp<SurfaceControl>& sc, int32_t fixedTransformHint) {
1520 layer_state_t* s = getLayerState(sc);
1521 if (!s) {
1522 mStatus = BAD_INDEX;
1523 return *this;
1524 }
1525
1526 const ui::Transform::RotationFlags transform = fixedTransformHint == -1
1527 ? ui::Transform::ROT_INVALID
1528 : ui::Transform::toRotationFlags(static_cast<ui::Rotation>(fixedTransformHint));
1529 s->what |= layer_state_t::eFixedTransformHintChanged;
1530 s->fixedTransformHint = transform;
1531 return *this;
1532}
1533
Siarhei Vishniakoufc434ac2021-01-13 10:28:00 -10001534SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setFrameTimelineInfo(
1535 const FrameTimelineInfo& frameTimelineInfo) {
1536 mFrameTimelineInfo = frameTimelineInfo;
Ady Abraham22c7b5c2020-09-22 19:33:40 -07001537 return *this;
1538}
1539
Siarhei Vishniakoufc434ac2021-01-13 10:28:00 -10001540SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setFrameTimelineInfo(
1541 const sp<SurfaceControl>& sc, const FrameTimelineInfo& frameTimelineInfo) {
Robert Carr9b611b72020-10-19 12:00:23 -07001542 layer_state_t* s = getLayerState(sc);
1543 if (!s) {
1544 mStatus = BAD_INDEX;
1545 return *this;
1546 }
1547
Siarhei Vishniakoufc434ac2021-01-13 10:28:00 -10001548 s->what |= layer_state_t::eFrameTimelineInfoChanged;
1549 s->frameTimelineInfo = frameTimelineInfo;
Robert Carr9b611b72020-10-19 12:00:23 -07001550 return *this;
1551}
1552
Vishnu Naircf26a0a2020-11-13 12:56:20 -08001553SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setAutoRefresh(
1554 const sp<SurfaceControl>& sc, bool autoRefresh) {
1555 layer_state_t* s = getLayerState(sc);
1556 if (!s) {
1557 mStatus = BAD_INDEX;
1558 return *this;
1559 }
1560
1561 s->what |= layer_state_t::eAutoRefreshChanged;
1562 s->autoRefresh = autoRefresh;
1563 return *this;
1564}
1565
Vishnu Nair277142c2021-01-05 18:35:29 -08001566SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setApplyToken(
1567 const sp<IBinder>& applyToken) {
1568 mApplyToken = applyToken;
1569 return *this;
1570}
1571
John Reckcdb4ed72021-02-04 13:39:33 -05001572SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setStretchEffect(
1573 const sp<SurfaceControl>& sc, float left, float top, float right, float bottom, float vecX,
1574 float vecY, float maxAmount) {
1575 layer_state_t* s = getLayerState(sc);
1576 if (!s) {
1577 mStatus = BAD_INDEX;
1578 return *this;
1579 }
1580
1581 s->what |= layer_state_t::eStretchChanged;
1582 s->stretchEffect = StretchEffect{.area = {left, top, right, bottom},
1583 .vectorX = vecX,
1584 .vectorY = vecY,
1585 .maxAmount = maxAmount};
1586 return *this;
1587}
1588
Mathias Agopian698c0872011-06-28 19:09:31 -07001589// ---------------------------------------------------------------------------
1590
chaviw763ef572018-02-22 16:04:57 -08001591DisplayState& SurfaceComposerClient::Transaction::getDisplayState(const sp<IBinder>& token) {
Mathias Agopiane57f2922012-08-09 16:29:12 -07001592 DisplayState s;
1593 s.token = token;
1594 ssize_t index = mDisplayStates.indexOf(s);
1595 if (index < 0) {
1596 // we don't have it, add an initialized layer_state to our list
1597 s.what = 0;
1598 index = mDisplayStates.add(s);
1599 }
Dan Stozad723bd72014-11-18 10:24:03 -08001600 return mDisplayStates.editItemAt(static_cast<size_t>(index));
Mathias Agopiane57f2922012-08-09 16:29:12 -07001601}
1602
Robert Carr4cdc58f2017-08-23 14:22:20 -07001603status_t SurfaceComposerClient::Transaction::setDisplaySurface(const sp<IBinder>& token,
1604 const sp<IGraphicBufferProducer>& bufferProducer) {
Pablo Ceballoseddbef82016-09-01 11:21:21 -07001605 if (bufferProducer.get() != nullptr) {
1606 // Make sure that composition can never be stalled by a virtual display
1607 // consumer that isn't processing buffers fast enough.
1608 status_t err = bufferProducer->setAsyncMode(true);
1609 if (err != NO_ERROR) {
1610 ALOGE("Composer::setDisplaySurface Failed to enable async mode on the "
1611 "BufferQueue. This BufferQueue cannot be used for virtual "
1612 "display. (%d)", err);
1613 return err;
1614 }
Pablo Ceballos1aad24c2016-08-04 10:24:22 -07001615 }
chaviw763ef572018-02-22 16:04:57 -08001616 DisplayState& s(getDisplayState(token));
Andy McFadden2adaf042012-12-18 09:49:45 -08001617 s.surface = bufferProducer;
Mathias Agopiane57f2922012-08-09 16:29:12 -07001618 s.what |= DisplayState::eSurfaceChanged;
Pablo Ceballos1aad24c2016-08-04 10:24:22 -07001619 return NO_ERROR;
Mathias Agopiane57f2922012-08-09 16:29:12 -07001620}
1621
Robert Carr4cdc58f2017-08-23 14:22:20 -07001622void SurfaceComposerClient::Transaction::setDisplayLayerStack(const sp<IBinder>& token,
Mathias Agopiane57f2922012-08-09 16:29:12 -07001623 uint32_t layerStack) {
chaviw763ef572018-02-22 16:04:57 -08001624 DisplayState& s(getDisplayState(token));
Mathias Agopiane57f2922012-08-09 16:29:12 -07001625 s.layerStack = layerStack;
1626 s.what |= DisplayState::eLayerStackChanged;
1627}
1628
Robert Carr4cdc58f2017-08-23 14:22:20 -07001629void SurfaceComposerClient::Transaction::setDisplayProjection(const sp<IBinder>& token,
Dominik Laskowski718f9602019-11-09 20:01:35 -08001630 ui::Rotation orientation,
1631 const Rect& layerStackRect,
1632 const Rect& displayRect) {
chaviw763ef572018-02-22 16:04:57 -08001633 DisplayState& s(getDisplayState(token));
Mathias Agopiane57f2922012-08-09 16:29:12 -07001634 s.orientation = orientation;
Marin Shalamanov6ad317c2020-07-29 23:34:07 +02001635 s.layerStackSpaceRect = layerStackRect;
1636 s.orientedDisplaySpaceRect = displayRect;
Mathias Agopian00e8c7a2012-09-04 19:30:46 -07001637 s.what |= DisplayState::eDisplayProjectionChanged;
Jorim Jaggi092123c2016-04-13 01:40:35 +00001638 mForceSynchronous = true; // TODO: do we actually still need this?
Mathias Agopiane57f2922012-08-09 16:29:12 -07001639}
1640
Robert Carr4cdc58f2017-08-23 14:22:20 -07001641void SurfaceComposerClient::Transaction::setDisplaySize(const sp<IBinder>& token, uint32_t width, uint32_t height) {
chaviw763ef572018-02-22 16:04:57 -08001642 DisplayState& s(getDisplayState(token));
Michael Wright1f6078a2014-06-26 16:01:02 -07001643 s.width = width;
1644 s.height = height;
1645 s.what |= DisplayState::eDisplaySizeChanged;
1646}
1647
Mathias Agopiane57f2922012-08-09 16:29:12 -07001648// ---------------------------------------------------------------------------
1649
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001650SurfaceComposerClient::SurfaceComposerClient()
Robert Carr4cdc58f2017-08-23 14:22:20 -07001651 : mStatus(NO_INIT)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001652{
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001653}
1654
Jorim Jaggif3cf4bc2017-11-30 14:19:23 +01001655SurfaceComposerClient::SurfaceComposerClient(const sp<ISurfaceComposerClient>& client)
1656 : mStatus(NO_ERROR), mClient(client)
1657{
1658}
1659
Mathias Agopian698c0872011-06-28 19:09:31 -07001660void SurfaceComposerClient::onFirstRef() {
Robert Carr4cdc58f2017-08-23 14:22:20 -07001661 sp<ISurfaceComposer> sf(ComposerService::getComposerService());
Yi Kong48a619f2018-06-05 16:34:59 -07001662 if (sf != nullptr && mStatus == NO_INIT) {
Robert Carr1db73f62016-12-21 12:58:51 -08001663 sp<ISurfaceComposerClient> conn;
Robert Carrb89ea9d2018-12-10 13:01:14 -08001664 conn = sf->createConnection();
Yi Kong48a619f2018-06-05 16:34:59 -07001665 if (conn != nullptr) {
Mathias Agopiand4784a32010-05-27 19:41:15 -07001666 mClient = conn;
Mathias Agopiand4784a32010-05-27 19:41:15 -07001667 mStatus = NO_ERROR;
1668 }
1669 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001670}
1671
Mathias Agopian698c0872011-06-28 19:09:31 -07001672SurfaceComposerClient::~SurfaceComposerClient() {
Mathias Agopian631f3582010-05-25 17:51:34 -07001673 dispose();
1674}
Mathias Agopiandd3423c2009-09-23 15:44:05 -07001675
Mathias Agopian698c0872011-06-28 19:09:31 -07001676status_t SurfaceComposerClient::initCheck() const {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001677 return mStatus;
1678}
1679
Mathias Agopian698c0872011-06-28 19:09:31 -07001680sp<IBinder> SurfaceComposerClient::connection() const {
Marco Nelissen2ea926b2014-11-14 08:01:01 -08001681 return IInterface::asBinder(mClient);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001682}
1683
Mathias Agopiand4784a32010-05-27 19:41:15 -07001684status_t SurfaceComposerClient::linkToComposerDeath(
1685 const sp<IBinder::DeathRecipient>& recipient,
Mathias Agopian698c0872011-06-28 19:09:31 -07001686 void* cookie, uint32_t flags) {
Robert Carr4cdc58f2017-08-23 14:22:20 -07001687 sp<ISurfaceComposer> sf(ComposerService::getComposerService());
1688 return IInterface::asBinder(sf)->linkToDeath(recipient, cookie, flags);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001689}
1690
Mathias Agopian698c0872011-06-28 19:09:31 -07001691void SurfaceComposerClient::dispose() {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001692 // this can be called more than once.
Mathias Agopian7e27f052010-05-28 14:22:23 -07001693 sp<ISurfaceComposerClient> client;
Mathias Agopiand4784a32010-05-27 19:41:15 -07001694 Mutex::Autolock _lm(mLock);
Yi Kong48a619f2018-06-05 16:34:59 -07001695 if (mClient != nullptr) {
Mathias Agopiand4784a32010-05-27 19:41:15 -07001696 client = mClient; // hold ref while lock is held
1697 mClient.clear();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001698 }
Mathias Agopiand4784a32010-05-27 19:41:15 -07001699 mStatus = NO_INIT;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001700}
1701
Evan Rosky1f6d6d52018-12-06 10:47:26 -08001702sp<SurfaceControl> SurfaceComposerClient::createSurface(const String8& name, uint32_t w, uint32_t h,
1703 PixelFormat format, uint32_t flags,
Vishnu Nair992496b2020-10-22 17:27:21 -07001704 const sp<IBinder>& parentHandle,
Valerie Hau1acd6962019-10-28 16:35:48 -07001705 LayerMetadata metadata,
1706 uint32_t* outTransformHint) {
Robert Carr3b382ed2018-03-14 13:49:41 -07001707 sp<SurfaceControl> s;
Vishnu Nair992496b2020-10-22 17:27:21 -07001708 createSurfaceChecked(name, w, h, format, &s, flags, parentHandle, std::move(metadata),
Valerie Hau1acd6962019-10-28 16:35:48 -07001709 outTransformHint);
Robert Carr3b382ed2018-03-14 13:49:41 -07001710 return s;
1711}
1712
Marissa Wall35187b32019-01-08 10:08:52 -08001713sp<SurfaceControl> SurfaceComposerClient::createWithSurfaceParent(const String8& name, uint32_t w,
1714 uint32_t h, PixelFormat format,
1715 uint32_t flags, Surface* parent,
Valerie Hau1acd6962019-10-28 16:35:48 -07001716 LayerMetadata metadata,
1717 uint32_t* outTransformHint) {
Marissa Wall35187b32019-01-08 10:08:52 -08001718 sp<SurfaceControl> sur;
1719 status_t err = mStatus;
1720
1721 if (mStatus == NO_ERROR) {
1722 sp<IBinder> handle;
1723 sp<IGraphicBufferProducer> parentGbp = parent->getIGraphicBufferProducer();
1724 sp<IGraphicBufferProducer> gbp;
1725
Valerie Hau1acd6962019-10-28 16:35:48 -07001726 uint32_t transformHint = 0;
Pablo Gamito2ec1f7b2020-09-01 14:18:49 +00001727 int32_t id = -1;
Evan Rosky1f6d6d52018-12-06 10:47:26 -08001728 err = mClient->createWithSurfaceParent(name, w, h, format, flags, parentGbp,
Pablo Gamito2ec1f7b2020-09-01 14:18:49 +00001729 std::move(metadata), &handle, &gbp, &id,
1730 &transformHint);
Valerie Hau1acd6962019-10-28 16:35:48 -07001731 if (outTransformHint) {
1732 *outTransformHint = transformHint;
1733 }
Marissa Wall35187b32019-01-08 10:08:52 -08001734 ALOGE_IF(err, "SurfaceComposerClient::createWithSurfaceParent error %s", strerror(-err));
1735 if (err == NO_ERROR) {
Pablo Gamitodbc31672020-09-01 18:28:58 +00001736 return new SurfaceControl(this, handle, gbp, id, transformHint);
Marissa Wall35187b32019-01-08 10:08:52 -08001737 }
1738 }
1739 return nullptr;
1740}
1741
Evan Rosky1f6d6d52018-12-06 10:47:26 -08001742status_t SurfaceComposerClient::createSurfaceChecked(const String8& name, uint32_t w, uint32_t h,
1743 PixelFormat format,
1744 sp<SurfaceControl>* outSurface, uint32_t flags,
Vishnu Nair992496b2020-10-22 17:27:21 -07001745 const sp<IBinder>& parentHandle,
1746 LayerMetadata metadata,
Valerie Hau1acd6962019-10-28 16:35:48 -07001747 uint32_t* outTransformHint) {
Mathias Agopian4d9b8222013-03-12 17:11:48 -07001748 sp<SurfaceControl> sur;
Robert Carr740eaf02018-03-27 12:59:18 -07001749 status_t err = mStatus;
Robert Carr3b382ed2018-03-14 13:49:41 -07001750
Mathias Agopian698c0872011-06-28 19:09:31 -07001751 if (mStatus == NO_ERROR) {
Mathias Agopian4d9b8222013-03-12 17:11:48 -07001752 sp<IBinder> handle;
1753 sp<IGraphicBufferProducer> gbp;
Robert Carr1f0a16a2016-10-24 16:27:39 -07001754
Valerie Hau1acd6962019-10-28 16:35:48 -07001755 uint32_t transformHint = 0;
Pablo Gamito2ec1f7b2020-09-01 14:18:49 +00001756 int32_t id = -1;
Evan Rosky1f6d6d52018-12-06 10:47:26 -08001757 err = mClient->createSurface(name, w, h, format, flags, parentHandle, std::move(metadata),
Pablo Gamito2ec1f7b2020-09-01 14:18:49 +00001758 &handle, &gbp, &id, &transformHint);
1759
Valerie Hau1acd6962019-10-28 16:35:48 -07001760 if (outTransformHint) {
1761 *outTransformHint = transformHint;
1762 }
Mathias Agopian4d9b8222013-03-12 17:11:48 -07001763 ALOGE_IF(err, "SurfaceComposerClient::createSurface error %s", strerror(-err));
1764 if (err == NO_ERROR) {
Pablo Gamitodbc31672020-09-01 18:28:58 +00001765 *outSurface = new SurfaceControl(this, handle, gbp, id, transformHint);
Mathias Agopian698c0872011-06-28 19:09:31 -07001766 }
1767 }
Robert Carr3b382ed2018-03-14 13:49:41 -07001768 return err;
Mathias Agopian698c0872011-06-28 19:09:31 -07001769}
1770
chaviwfe94a222019-08-21 13:52:59 -07001771sp<SurfaceControl> SurfaceComposerClient::mirrorSurface(SurfaceControl* mirrorFromSurface) {
1772 if (mirrorFromSurface == nullptr) {
1773 return nullptr;
1774 }
1775
1776 sp<IBinder> handle;
1777 sp<IBinder> mirrorFromHandle = mirrorFromSurface->getHandle();
Pablo Gamito2ec1f7b2020-09-01 14:18:49 +00001778 int32_t layer_id = -1;
1779 status_t err = mClient->mirrorSurface(mirrorFromHandle, &handle, &layer_id);
chaviwfe94a222019-08-21 13:52:59 -07001780 if (err == NO_ERROR) {
Pablo Gamitodbc31672020-09-01 18:28:58 +00001781 return new SurfaceControl(this, handle, nullptr, layer_id, true /* owned */);
chaviwfe94a222019-08-21 13:52:59 -07001782 }
1783 return nullptr;
1784}
1785
Svetoslavd85084b2014-03-20 10:28:31 -07001786status_t SurfaceComposerClient::clearLayerFrameStats(const sp<IBinder>& token) const {
1787 if (mStatus != NO_ERROR) {
1788 return mStatus;
1789 }
1790 return mClient->clearLayerFrameStats(token);
1791}
1792
1793status_t SurfaceComposerClient::getLayerFrameStats(const sp<IBinder>& token,
1794 FrameStats* outStats) const {
1795 if (mStatus != NO_ERROR) {
1796 return mStatus;
1797 }
1798 return mClient->getLayerFrameStats(token, outStats);
1799}
1800
Mathias Agopian698c0872011-06-28 19:09:31 -07001801// ----------------------------------------------------------------------------
1802
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -07001803status_t SurfaceComposerClient::enableVSyncInjections(bool enable) {
Robert Carr4cdc58f2017-08-23 14:22:20 -07001804 sp<ISurfaceComposer> sf(ComposerService::getComposerService());
1805 return sf->enableVSyncInjections(enable);
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -07001806}
1807
1808status_t SurfaceComposerClient::injectVSync(nsecs_t when) {
Robert Carr4cdc58f2017-08-23 14:22:20 -07001809 sp<ISurfaceComposer> sf(ComposerService::getComposerService());
1810 return sf->injectVSync(when);
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -07001811}
1812
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -08001813status_t SurfaceComposerClient::getDisplayState(const sp<IBinder>& display,
1814 ui::DisplayState* state) {
1815 return ComposerService::getComposerService()->getDisplayState(display, state);
1816}
1817
1818status_t SurfaceComposerClient::getDisplayInfo(const sp<IBinder>& display, DisplayInfo* info) {
1819 return ComposerService::getComposerService()->getDisplayInfo(display, info);
1820}
1821
Marin Shalamanova7fe3042021-01-29 21:02:08 +01001822status_t SurfaceComposerClient::getDisplayModes(const sp<IBinder>& display,
1823 Vector<ui::DisplayMode>* modes) {
1824 return ComposerService::getComposerService()->getDisplayModes(display, modes);
Dan Stoza7f7da322014-05-02 15:26:25 -07001825}
1826
Marin Shalamanova7fe3042021-01-29 21:02:08 +01001827status_t SurfaceComposerClient::getActiveDisplayMode(const sp<IBinder>& display,
1828 ui::DisplayMode* mode) {
1829 Vector<ui::DisplayMode> modes;
1830 status_t result = getDisplayModes(display, &modes);
Dan Stoza7f7da322014-05-02 15:26:25 -07001831 if (result != NO_ERROR) {
1832 return result;
1833 }
1834
Marin Shalamanova7fe3042021-01-29 21:02:08 +01001835 int activeId = getActiveDisplayModeId(display);
Dan Stoza7f7da322014-05-02 15:26:25 -07001836 if (activeId < 0) {
Marin Shalamanova7fe3042021-01-29 21:02:08 +01001837 ALOGE("No active mode found");
Dan Stoza7f7da322014-05-02 15:26:25 -07001838 return NAME_NOT_FOUND;
1839 }
1840
Marin Shalamanova7fe3042021-01-29 21:02:08 +01001841 *mode = modes[static_cast<size_t>(activeId)];
Dan Stoza7f7da322014-05-02 15:26:25 -07001842 return NO_ERROR;
1843}
1844
Marin Shalamanova7fe3042021-01-29 21:02:08 +01001845int SurfaceComposerClient::getActiveDisplayModeId(const sp<IBinder>& display) {
1846 return ComposerService::getComposerService()->getActiveDisplayModeId(display);
Dan Stoza7f7da322014-05-02 15:26:25 -07001847}
1848
Marin Shalamanova7fe3042021-01-29 21:02:08 +01001849status_t SurfaceComposerClient::setDesiredDisplayModeSpecs(
1850 const sp<IBinder>& displayToken, size_t defaultMode, bool allowGroupSwitching,
Marin Shalamanov30b0b3c2020-10-13 19:15:06 +02001851 float primaryRefreshRateMin, float primaryRefreshRateMax, float appRequestRefreshRateMin,
1852 float appRequestRefreshRateMax) {
Steven Thomasf734df42020-04-13 21:09:28 -07001853 return ComposerService::getComposerService()
Marin Shalamanova7fe3042021-01-29 21:02:08 +01001854 ->setDesiredDisplayModeSpecs(displayToken, defaultMode, allowGroupSwitching,
1855 primaryRefreshRateMin, primaryRefreshRateMax,
1856 appRequestRefreshRateMin, appRequestRefreshRateMax);
Ana Krulec0782b882019-10-15 17:34:54 -07001857}
1858
Marin Shalamanova7fe3042021-01-29 21:02:08 +01001859status_t SurfaceComposerClient::getDesiredDisplayModeSpecs(
1860 const sp<IBinder>& displayToken, size_t* outDefaultMode, bool* outAllowGroupSwitching,
Marin Shalamanov30b0b3c2020-10-13 19:15:06 +02001861 float* outPrimaryRefreshRateMin, float* outPrimaryRefreshRateMax,
1862 float* outAppRequestRefreshRateMin, float* outAppRequestRefreshRateMax) {
Steven Thomasf734df42020-04-13 21:09:28 -07001863 return ComposerService::getComposerService()
Marin Shalamanova7fe3042021-01-29 21:02:08 +01001864 ->getDesiredDisplayModeSpecs(displayToken, outDefaultMode, outAllowGroupSwitching,
1865 outPrimaryRefreshRateMin, outPrimaryRefreshRateMax,
1866 outAppRequestRefreshRateMin, outAppRequestRefreshRateMax);
Ana Krulec234bb162019-11-10 22:55:55 +01001867}
1868
Michael Wright28f24d02016-07-12 13:30:53 -07001869status_t SurfaceComposerClient::getDisplayColorModes(const sp<IBinder>& display,
Peiyong Lina52f0292018-03-14 17:26:31 -07001870 Vector<ColorMode>* outColorModes) {
Michael Wright28f24d02016-07-12 13:30:53 -07001871 return ComposerService::getComposerService()->getDisplayColorModes(display, outColorModes);
1872}
1873
Daniel Solomon42d04562019-01-20 21:03:19 -08001874status_t SurfaceComposerClient::getDisplayNativePrimaries(const sp<IBinder>& display,
1875 ui::DisplayPrimaries& outPrimaries) {
1876 return ComposerService::getComposerService()->getDisplayNativePrimaries(display, outPrimaries);
1877}
1878
Peiyong Lina52f0292018-03-14 17:26:31 -07001879ColorMode SurfaceComposerClient::getActiveColorMode(const sp<IBinder>& display) {
Michael Wright28f24d02016-07-12 13:30:53 -07001880 return ComposerService::getComposerService()->getActiveColorMode(display);
1881}
1882
1883status_t SurfaceComposerClient::setActiveColorMode(const sp<IBinder>& display,
Peiyong Lina52f0292018-03-14 17:26:31 -07001884 ColorMode colorMode) {
Michael Wright28f24d02016-07-12 13:30:53 -07001885 return ComposerService::getComposerService()->setActiveColorMode(display, colorMode);
1886}
1887
Galia Peycheva5492cb52019-10-30 14:13:16 +01001888bool SurfaceComposerClient::getAutoLowLatencyModeSupport(const sp<IBinder>& display) {
1889 bool supported = false;
1890 ComposerService::getComposerService()->getAutoLowLatencyModeSupport(display, &supported);
1891 return supported;
1892}
1893
1894void SurfaceComposerClient::setAutoLowLatencyMode(const sp<IBinder>& display, bool on) {
1895 ComposerService::getComposerService()->setAutoLowLatencyMode(display, on);
1896}
1897
1898bool SurfaceComposerClient::getGameContentTypeSupport(const sp<IBinder>& display) {
1899 bool supported = false;
1900 ComposerService::getComposerService()->getGameContentTypeSupport(display, &supported);
1901 return supported;
1902}
1903
1904void SurfaceComposerClient::setGameContentType(const sp<IBinder>& display, bool on) {
1905 ComposerService::getComposerService()->setGameContentType(display, on);
1906}
1907
Prashant Malani2c9b11f2014-05-25 01:36:31 -07001908void SurfaceComposerClient::setDisplayPowerMode(const sp<IBinder>& token,
1909 int mode) {
1910 ComposerService::getComposerService()->setPowerMode(token, mode);
Jeff Brown2a09bb32012-10-08 19:13:57 -07001911}
1912
Peiyong Linc6780972018-10-28 15:24:08 -07001913status_t SurfaceComposerClient::getCompositionPreference(
1914 ui::Dataspace* defaultDataspace, ui::PixelFormat* defaultPixelFormat,
1915 ui::Dataspace* wideColorGamutDataspace, ui::PixelFormat* wideColorGamutPixelFormat) {
1916 return ComposerService::getComposerService()
1917 ->getCompositionPreference(defaultDataspace, defaultPixelFormat,
1918 wideColorGamutDataspace, wideColorGamutPixelFormat);
Peiyong Lin0256f722018-08-31 15:45:10 -07001919}
1920
Peiyong Lin08d10512019-01-16 13:27:35 -08001921bool SurfaceComposerClient::getProtectedContentSupport() {
1922 bool supported = false;
1923 ComposerService::getComposerService()->getProtectedContentSupport(&supported);
1924 return supported;
1925}
1926
Svetoslavd85084b2014-03-20 10:28:31 -07001927status_t SurfaceComposerClient::clearAnimationFrameStats() {
1928 return ComposerService::getComposerService()->clearAnimationFrameStats();
1929}
1930
1931status_t SurfaceComposerClient::getAnimationFrameStats(FrameStats* outStats) {
1932 return ComposerService::getComposerService()->getAnimationFrameStats(outStats);
1933}
1934
Dan Stozac4f471e2016-03-24 09:31:08 -07001935status_t SurfaceComposerClient::getHdrCapabilities(const sp<IBinder>& display,
1936 HdrCapabilities* outCapabilities) {
1937 return ComposerService::getComposerService()->getHdrCapabilities(display,
1938 outCapabilities);
1939}
1940
Kevin DuBois9c0a1762018-10-16 13:32:31 -07001941status_t SurfaceComposerClient::getDisplayedContentSamplingAttributes(const sp<IBinder>& display,
1942 ui::PixelFormat* outFormat,
1943 ui::Dataspace* outDataspace,
1944 uint8_t* outComponentMask) {
1945 return ComposerService::getComposerService()
1946 ->getDisplayedContentSamplingAttributes(display, outFormat, outDataspace,
1947 outComponentMask);
1948}
1949
Kevin DuBois74e53772018-11-19 10:52:38 -08001950status_t SurfaceComposerClient::setDisplayContentSamplingEnabled(const sp<IBinder>& display,
1951 bool enable, uint8_t componentMask,
1952 uint64_t maxFrames) {
1953 return ComposerService::getComposerService()->setDisplayContentSamplingEnabled(display, enable,
1954 componentMask,
1955 maxFrames);
1956}
1957
Kevin DuBois1d4249a2018-08-29 10:45:14 -07001958status_t SurfaceComposerClient::getDisplayedContentSample(const sp<IBinder>& display,
1959 uint64_t maxFrames, uint64_t timestamp,
1960 DisplayedFrameStats* outStats) {
1961 return ComposerService::getComposerService()->getDisplayedContentSample(display, maxFrames,
1962 timestamp, outStats);
1963}
Marissa Wall35187b32019-01-08 10:08:52 -08001964
Peiyong Lin4f3fddf2019-01-24 17:21:24 -08001965status_t SurfaceComposerClient::isWideColorDisplay(const sp<IBinder>& display,
1966 bool* outIsWideColorDisplay) {
1967 return ComposerService::getComposerService()->isWideColorDisplay(display,
1968 outIsWideColorDisplay);
1969}
1970
Kevin DuBois00c66832019-02-18 16:21:31 -08001971status_t SurfaceComposerClient::addRegionSamplingListener(
1972 const Rect& samplingArea, const sp<IBinder>& stopLayerHandle,
1973 const sp<IRegionSamplingListener>& listener) {
1974 return ComposerService::getComposerService()->addRegionSamplingListener(samplingArea,
1975 stopLayerHandle,
1976 listener);
1977}
1978
1979status_t SurfaceComposerClient::removeRegionSamplingListener(
1980 const sp<IRegionSamplingListener>& listener) {
1981 return ComposerService::getComposerService()->removeRegionSamplingListener(listener);
1982}
1983
Dan Gittik57e63c52019-01-18 16:37:54 +00001984bool SurfaceComposerClient::getDisplayBrightnessSupport(const sp<IBinder>& displayToken) {
1985 bool support = false;
1986 ComposerService::getComposerService()->getDisplayBrightnessSupport(displayToken, &support);
1987 return support;
1988}
1989
1990status_t SurfaceComposerClient::setDisplayBrightness(const sp<IBinder>& displayToken,
1991 float brightness) {
1992 return ComposerService::getComposerService()->setDisplayBrightness(displayToken, brightness);
1993}
1994
Lais Andrade3a6e47d2020-04-02 11:20:16 +01001995status_t SurfaceComposerClient::notifyPowerBoost(int32_t boostId) {
1996 return ComposerService::getComposerService()->notifyPowerBoost(boostId);
Ady Abraham8532d012019-05-08 14:50:56 -07001997}
1998
Vishnu Nairb13bb952019-11-15 10:24:08 -08001999status_t SurfaceComposerClient::setGlobalShadowSettings(const half4& ambientColor,
2000 const half4& spotColor, float lightPosY,
2001 float lightPosZ, float lightRadius) {
2002 return ComposerService::getComposerService()->setGlobalShadowSettings(ambientColor, spotColor,
2003 lightPosY, lightPosZ,
2004 lightRadius);
2005}
2006
Ana Krulec31f2b3c2020-12-14 14:30:09 -08002007int SurfaceComposerClient::getGPUContextPriority() {
2008 return ComposerService::getComposerService()->getGPUContextPriority();
2009}
2010
Mathias Agopian698c0872011-06-28 19:09:31 -07002011// ----------------------------------------------------------------------------
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08002012
chaviw690db382020-07-27 16:46:46 -07002013status_t ScreenshotClient::captureDisplay(const DisplayCaptureArgs& captureArgs,
chaviwe7b9f272020-08-18 16:08:59 -07002014 const sp<IScreenCaptureListener>& captureListener) {
Mathias Agopian2a9fc492013-03-01 13:42:57 -08002015 sp<ISurfaceComposer> s(ComposerService::getComposerService());
Yi Kong48a619f2018-06-05 16:34:59 -07002016 if (s == nullptr) return NO_INIT;
chaviw8ffc7b82020-08-18 11:25:37 -07002017
chaviwe7b9f272020-08-18 16:08:59 -07002018 return s->captureDisplay(captureArgs, captureListener);
Robert Carr673134e2017-01-09 19:48:38 -08002019}
2020
chaviw690db382020-07-27 16:46:46 -07002021status_t ScreenshotClient::captureDisplay(uint64_t displayOrLayerStack,
chaviwe7b9f272020-08-18 16:08:59 -07002022 const sp<IScreenCaptureListener>& captureListener) {
chaviw93df2ea2019-04-30 16:45:12 -07002023 sp<ISurfaceComposer> s(ComposerService::getComposerService());
2024 if (s == nullptr) return NO_INIT;
chaviw8ffc7b82020-08-18 11:25:37 -07002025
chaviwe7b9f272020-08-18 16:08:59 -07002026 return s->captureDisplay(displayOrLayerStack, captureListener);
chaviw93df2ea2019-04-30 16:45:12 -07002027}
2028
chaviw26c52482020-07-28 16:25:52 -07002029status_t ScreenshotClient::captureLayers(const LayerCaptureArgs& captureArgs,
chaviwe7b9f272020-08-18 16:08:59 -07002030 const sp<IScreenCaptureListener>& captureListener) {
chaviwa76b2712017-09-20 12:02:26 -07002031 sp<ISurfaceComposer> s(ComposerService::getComposerService());
Yi Kong48a619f2018-06-05 16:34:59 -07002032 if (s == nullptr) return NO_INIT;
chaviw8ffc7b82020-08-18 11:25:37 -07002033
chaviwe7b9f272020-08-18 16:08:59 -07002034 return s->captureLayers(captureArgs, captureListener);
chaviwa76b2712017-09-20 12:02:26 -07002035}
Dominik Laskowski718f9602019-11-09 20:01:35 -08002036
2037} // namespace android