blob: 16a4b353aaa8e7a993ec8614cd72aeb4d1c5101a [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
Mathias Agopian076b1cc2009-04-10 14:24:30 -070034#include <ui/DisplayInfo.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080035
Robert Carr673134e2017-01-09 19:48:38 -080036#include <gui/BufferItemConsumer.h>
Mathias Agopianabe815d2013-03-19 22:22:21 -070037#include <gui/CpuConsumer.h>
Mathias Agopiane3c697f2013-02-14 17:11:02 -080038#include <gui/IGraphicBufferProducer.h>
Mathias Agopian90ac7992012-02-25 18:48:35 -080039#include <gui/ISurfaceComposer.h>
40#include <gui/ISurfaceComposerClient.h>
Robert Carr4cdc58f2017-08-23 14:22:20 -070041#include <gui/LayerState.h>
Robert Carr0d480722017-01-10 16:42:54 -080042#include <gui/Surface.h>
Mathias Agopian90ac7992012-02-25 18:48:35 -080043#include <gui/SurfaceComposerClient.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080044
Robert Carr2c358bf2018-08-08 15:58:15 -070045#ifndef NO_INPUT
46#include <input/InputWindow.h>
47#endif
48
Mathias Agopian41f673c2011-11-17 17:48:35 -080049#include <private/gui/ComposerService.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080050
Marissa Wall73411622019-01-25 10:45:41 -080051// This server size should always be smaller than the server cache size
52#define BUFFER_CACHE_MAX_SIZE 64
53
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080054namespace android {
Peiyong Lin9f034472018-03-28 15:29:00 -070055
56using ui::ColorMode;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080057// ---------------------------------------------------------------------------
58
Mathias Agopian7e27f052010-05-28 14:22:23 -070059ANDROID_SINGLETON_STATIC_INSTANCE(ComposerService);
60
Mathias Agopianb7e930d2010-06-01 15:12:58 -070061ComposerService::ComposerService()
62: Singleton<ComposerService>() {
Andy McFadden6652b3e2012-09-06 18:45:56 -070063 Mutex::Autolock _l(mLock);
64 connectLocked();
65}
66
67void ComposerService::connectLocked() {
Mathias Agopianb7e930d2010-06-01 15:12:58 -070068 const String16 name("SurfaceFlinger");
69 while (getService(name, &mComposerService) != NO_ERROR) {
70 usleep(250000);
71 }
Yi Konga03e0442018-07-17 11:16:57 -070072 assert(mComposerService != nullptr);
Andy McFadden6652b3e2012-09-06 18:45:56 -070073
74 // Create the death listener.
75 class DeathObserver : public IBinder::DeathRecipient {
76 ComposerService& mComposerService;
77 virtual void binderDied(const wp<IBinder>& who) {
78 ALOGW("ComposerService remote (surfaceflinger) died [%p]",
79 who.unsafe_get());
80 mComposerService.composerServiceDied();
81 }
82 public:
Chih-Hung Hsiehe2347b72016-04-25 15:41:05 -070083 explicit DeathObserver(ComposerService& mgr) : mComposerService(mgr) { }
Andy McFadden6652b3e2012-09-06 18:45:56 -070084 };
85
86 mDeathObserver = new DeathObserver(*const_cast<ComposerService*>(this));
Marco Nelissen2ea926b2014-11-14 08:01:01 -080087 IInterface::asBinder(mComposerService)->linkToDeath(mDeathObserver);
Mathias Agopianb7e930d2010-06-01 15:12:58 -070088}
89
Andy McFadden6652b3e2012-09-06 18:45:56 -070090/*static*/ sp<ISurfaceComposer> ComposerService::getComposerService() {
91 ComposerService& instance = ComposerService::getInstance();
92 Mutex::Autolock _l(instance.mLock);
Yi Kong48a619f2018-06-05 16:34:59 -070093 if (instance.mComposerService == nullptr) {
Andy McFadden6652b3e2012-09-06 18:45:56 -070094 ComposerService::getInstance().connectLocked();
Yi Konga03e0442018-07-17 11:16:57 -070095 assert(instance.mComposerService != nullptr);
Andy McFadden6652b3e2012-09-06 18:45:56 -070096 ALOGD("ComposerService reconnected");
97 }
98 return instance.mComposerService;
99}
100
101void ComposerService::composerServiceDied()
102{
103 Mutex::Autolock _l(mLock);
Yi Kong48a619f2018-06-05 16:34:59 -0700104 mComposerService = nullptr;
105 mDeathObserver = nullptr;
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700106}
107
Robert Carrfb4d58b2019-01-15 09:21:27 -0800108class DefaultComposerClient: public Singleton<DefaultComposerClient> {
109 Mutex mLock;
110 sp<SurfaceComposerClient> mClient;
111 friend class Singleton<ComposerService>;
112public:
113 static sp<SurfaceComposerClient> getComposerClient() {
114 DefaultComposerClient& dc = DefaultComposerClient::getInstance();
115 Mutex::Autolock _l(dc.mLock);
116 if (dc.mClient == nullptr) {
117 dc.mClient = new SurfaceComposerClient;
118 }
119 return dc.mClient;
120 }
121};
122ANDROID_SINGLETON_STATIC_INSTANCE(DefaultComposerClient);
123
124
125sp<SurfaceComposerClient> SurfaceComposerClient::getDefault() {
126 return DefaultComposerClient::getComposerClient();
127}
128
Mathias Agopian7e27f052010-05-28 14:22:23 -0700129// ---------------------------------------------------------------------------
130
Marissa Wall7a9b6ff2018-08-21 17:26:20 -0700131// TransactionCompletedListener does not use ANDROID_SINGLETON_STATIC_INSTANCE because it needs
132// to be able to return a sp<> to its instance to pass to SurfaceFlinger.
133// ANDROID_SINGLETON_STATIC_INSTANCE only allows a reference to an instance.
134
Marissa Wallc837b5e2018-10-12 10:04:44 -0700135// 0 is an invalid callback id
136TransactionCompletedListener::TransactionCompletedListener() : mCallbackIdCounter(1) {}
137
138CallbackId TransactionCompletedListener::getNextIdLocked() {
139 return mCallbackIdCounter++;
140}
141
Marissa Wall7a9b6ff2018-08-21 17:26:20 -0700142sp<TransactionCompletedListener> TransactionCompletedListener::getInstance() {
143 static sp<TransactionCompletedListener> sInstance = new TransactionCompletedListener;
144 return sInstance;
145}
146
Marissa Wallc837b5e2018-10-12 10:04:44 -0700147sp<ITransactionCompletedListener> TransactionCompletedListener::getIInstance() {
148 return static_cast<sp<ITransactionCompletedListener>>(getInstance());
149}
150
151void TransactionCompletedListener::startListeningLocked() {
Marissa Wall7a9b6ff2018-08-21 17:26:20 -0700152 if (mListening) {
153 return;
154 }
155 ProcessState::self()->startThreadPool();
156 mListening = true;
157}
158
Marissa Wall80d94ad2019-01-18 16:04:36 -0800159CallbackId TransactionCompletedListener::addCallbackFunction(
160 const TransactionCompletedCallback& callbackFunction,
161 const std::unordered_set<sp<SurfaceControl>, SurfaceComposerClient::SCHash>&
162 surfaceControls) {
Marissa Wallc837b5e2018-10-12 10:04:44 -0700163 std::lock_guard<std::mutex> lock(mMutex);
164 startListeningLocked();
165
166 CallbackId callbackId = getNextIdLocked();
Marissa Wall80d94ad2019-01-18 16:04:36 -0800167 mCallbacks[callbackId].callbackFunction = callbackFunction;
168
169 auto& callbackSurfaceControls = mCallbacks[callbackId].surfaceControls;
170
171 for (const auto& surfaceControl : surfaceControls) {
172 callbackSurfaceControls[surfaceControl->getHandle()] = surfaceControl;
173 }
174
Marissa Wallc837b5e2018-10-12 10:04:44 -0700175 return callbackId;
176}
177
Marissa Wall80d94ad2019-01-18 16:04:36 -0800178void TransactionCompletedListener::addSurfaceControlToCallbacks(
179 const sp<SurfaceControl>& surfaceControl,
180 const std::unordered_set<CallbackId>& callbackIds) {
181 std::lock_guard<std::mutex> lock(mMutex);
182
183 for (auto callbackId : callbackIds) {
184 mCallbacks[callbackId].surfaceControls.emplace(std::piecewise_construct,
185 std::forward_as_tuple(
186 surfaceControl->getHandle()),
187 std::forward_as_tuple(surfaceControl));
188 }
189}
190
Marissa Walle2ffb422018-10-12 11:33:52 -0700191void TransactionCompletedListener::onTransactionCompleted(ListenerStats listenerStats) {
Yi Kongd2639aa2019-02-28 11:58:32 -0800192 std::lock_guard<std::mutex> lock(mMutex);
Marissa Walle2ffb422018-10-12 11:33:52 -0700193
Marissa Wall80d94ad2019-01-18 16:04:36 -0800194 /* This listener knows all the sp<IBinder> to sp<SurfaceControl> for all its registered
195 * callbackIds, except for when Transactions are merged together. This probably cannot be
196 * solved before this point because the Transactions could be merged together and applied in a
197 * different process.
198 *
199 * Fortunately, we get all the callbacks for this listener for the same frame together at the
200 * same time. This means if any Transactions were merged together, we will get their callbacks
201 * at the same time. We can combine all the sp<IBinder> to sp<SurfaceControl> maps for all the
202 * callbackIds to generate one super map that contains all the sp<IBinder> to sp<SurfaceControl>
203 * that could possibly exist for the callbacks.
204 */
205 std::unordered_map<sp<IBinder>, sp<SurfaceControl>, IBinderHash> surfaceControls;
Marissa Walld600d572019-03-26 15:38:50 -0700206 for (const auto& transactionStats : listenerStats.transactionStats) {
207 for (auto callbackId : transactionStats.callbackIds) {
Marissa Wall80d94ad2019-01-18 16:04:36 -0800208 auto& [callbackFunction, callbackSurfaceControls] = mCallbacks[callbackId];
209 surfaceControls.insert(callbackSurfaceControls.begin(), callbackSurfaceControls.end());
210 }
211 }
212
Marissa Walld600d572019-03-26 15:38:50 -0700213 for (const auto& transactionStats : listenerStats.transactionStats) {
214 for (auto callbackId : transactionStats.callbackIds) {
Marissa Wall80d94ad2019-01-18 16:04:36 -0800215 auto& [callbackFunction, callbackSurfaceControls] = mCallbacks[callbackId];
216 if (!callbackFunction) {
Marissa Walle2ffb422018-10-12 11:33:52 -0700217 ALOGE("cannot call null callback function, skipping");
218 continue;
219 }
Marissa Wall80d94ad2019-01-18 16:04:36 -0800220 std::vector<SurfaceControlStats> surfaceControlStats;
221 for (const auto& surfaceStats : transactionStats.surfaceStats) {
222 surfaceControlStats.emplace_back(surfaceControls[surfaceStats.surfaceControl],
223 surfaceStats.acquireTime,
224 surfaceStats.previousReleaseFence);
225 }
226
227 callbackFunction(transactionStats.latchTime, transactionStats.presentFence,
228 surfaceControlStats);
Marissa Walle2ffb422018-10-12 11:33:52 -0700229 mCallbacks.erase(callbackId);
230 }
231 }
Marissa Wall7a9b6ff2018-08-21 17:26:20 -0700232}
233
234// ---------------------------------------------------------------------------
235
Marissa Wall78b72202019-03-15 14:58:34 -0700236void bufferCacheCallback(void* /*context*/, uint64_t graphicBufferId);
237
Marissa Wall73411622019-01-25 10:45:41 -0800238class BufferCache : public Singleton<BufferCache> {
239public:
240 BufferCache() : token(new BBinder()) {}
241
242 sp<IBinder> getToken() {
243 return IInterface::asBinder(TransactionCompletedListener::getIInstance());
244 }
245
Marissa Wall78b72202019-03-15 14:58:34 -0700246 status_t getCacheId(const sp<GraphicBuffer>& buffer, uint64_t* cacheId) {
Yi Kongd2639aa2019-02-28 11:58:32 -0800247 std::lock_guard<std::mutex> lock(mMutex);
Marissa Wall73411622019-01-25 10:45:41 -0800248
Marissa Wall78b72202019-03-15 14:58:34 -0700249 auto itr = mBuffers.find(buffer->getId());
Marissa Wall73411622019-01-25 10:45:41 -0800250 if (itr == mBuffers.end()) {
Marissa Wall78b72202019-03-15 14:58:34 -0700251 return BAD_VALUE;
Marissa Wall73411622019-01-25 10:45:41 -0800252 }
Marissa Wall78b72202019-03-15 14:58:34 -0700253 itr->second = getCounter();
254 *cacheId = buffer->getId();
255 return NO_ERROR;
Marissa Wall73411622019-01-25 10:45:41 -0800256 }
257
Marissa Wall78b72202019-03-15 14:58:34 -0700258 uint64_t cache(const sp<GraphicBuffer>& buffer) {
Yi Kongd2639aa2019-02-28 11:58:32 -0800259 std::lock_guard<std::mutex> lock(mMutex);
Marissa Wall73411622019-01-25 10:45:41 -0800260
Marissa Wall78b72202019-03-15 14:58:34 -0700261 if (mBuffers.size() >= BUFFER_CACHE_MAX_SIZE) {
262 evictLeastRecentlyUsedBuffer();
263 }
Marissa Wall73411622019-01-25 10:45:41 -0800264
Marissa Wall78b72202019-03-15 14:58:34 -0700265 buffer->addDeathCallback(bufferCacheCallback, nullptr);
266
267 mBuffers[buffer->getId()] = getCounter();
268 return buffer->getId();
269 }
270
271 void uncache(uint64_t cacheId) {
272 std::lock_guard<std::mutex> lock(mMutex);
273 uncacheLocked(cacheId);
274 }
275
276 void uncacheLocked(uint64_t cacheId) REQUIRES(mMutex) {
277 mBuffers.erase(cacheId);
278 SurfaceComposerClient::doUncacheBufferTransaction(cacheId);
Marissa Wall73411622019-01-25 10:45:41 -0800279 }
280
281private:
Marissa Wall78b72202019-03-15 14:58:34 -0700282 void evictLeastRecentlyUsedBuffer() REQUIRES(mMutex) {
Marissa Wall73411622019-01-25 10:45:41 -0800283 auto itr = mBuffers.begin();
Marissa Wall78b72202019-03-15 14:58:34 -0700284 uint64_t minCounter = itr->second;
Marissa Wall73411622019-01-25 10:45:41 -0800285 auto minBuffer = itr;
286 itr++;
287
288 while (itr != mBuffers.end()) {
Marissa Wall78b72202019-03-15 14:58:34 -0700289 uint64_t counter = itr->second;
Marissa Wall73411622019-01-25 10:45:41 -0800290 if (counter < minCounter) {
291 minCounter = counter;
292 minBuffer = itr;
293 }
294 itr++;
295 }
Marissa Wall78b72202019-03-15 14:58:34 -0700296 uncacheLocked(minBuffer->first);
Marissa Wall73411622019-01-25 10:45:41 -0800297 }
298
299 uint64_t getCounter() REQUIRES(mMutex) {
300 static uint64_t counter = 0;
301 return counter++;
302 }
303
Marissa Wall73411622019-01-25 10:45:41 -0800304 std::mutex mMutex;
Marissa Wall78b72202019-03-15 14:58:34 -0700305 std::map<uint64_t /*Cache id*/, uint64_t /*counter*/> mBuffers GUARDED_BY(mMutex);
Marissa Wall73411622019-01-25 10:45:41 -0800306
307 // Used by ISurfaceComposer to identify which process is sending the cached buffer.
308 sp<IBinder> token;
309};
310
311ANDROID_SINGLETON_STATIC_INSTANCE(BufferCache);
312
Marissa Wall78b72202019-03-15 14:58:34 -0700313void bufferCacheCallback(void* /*context*/, uint64_t graphicBufferId) {
314 // GraphicBuffer id's are used as the cache ids.
315 BufferCache::getInstance().uncache(graphicBufferId);
316}
317
Marissa Wall73411622019-01-25 10:45:41 -0800318// ---------------------------------------------------------------------------
319
Marissa Wall17b4e452018-12-26 16:32:34 -0800320SurfaceComposerClient::Transaction::Transaction(const Transaction& other)
321 : mForceSynchronous(other.mForceSynchronous),
322 mTransactionNestCount(other.mTransactionNestCount),
323 mAnimation(other.mAnimation),
324 mEarlyWakeup(other.mEarlyWakeup),
Vishnu Nair621102e2019-06-12 14:16:57 -0700325 mContainsBuffer(other.mContainsBuffer),
Marissa Wall17b4e452018-12-26 16:32:34 -0800326 mDesiredPresentTime(other.mDesiredPresentTime) {
Robert Carr4cdc58f2017-08-23 14:22:20 -0700327 mDisplayStates = other.mDisplayStates;
328 mComposerStates = other.mComposerStates;
chaviw273171b2018-12-26 11:46:30 -0800329 mInputWindowCommands = other.mInputWindowCommands;
Vishnu Nair621102e2019-06-12 14:16:57 -0700330 mListenerCallbacks = other.mListenerCallbacks;
331}
332
333std::unique_ptr<SurfaceComposerClient::Transaction>
334SurfaceComposerClient::Transaction::createFromParcel(const Parcel* parcel) {
335 auto transaction = std::make_unique<Transaction>();
336 if (transaction->readFromParcel(parcel) == NO_ERROR) {
337 return transaction;
338 }
339 return nullptr;
340}
341
342status_t SurfaceComposerClient::Transaction::readFromParcel(const Parcel* parcel) {
343 const uint32_t forceSynchronous = parcel->readUint32();
344 const uint32_t transactionNestCount = parcel->readUint32();
345 const bool animation = parcel->readBool();
346 const bool earlyWakeup = parcel->readBool();
347 const bool containsBuffer = parcel->readBool();
348 const int64_t desiredPresentTime = parcel->readInt64();
349
350 size_t count = static_cast<size_t>(parcel->readUint32());
351 if (count > parcel->dataSize()) {
352 return BAD_VALUE;
353 }
354 SortedVector<DisplayState> displayStates;
355 displayStates.setCapacity(count);
356 for (size_t i = 0; i < count; i++) {
357 DisplayState displayState;
358 if (displayState.read(*parcel) == BAD_VALUE) {
359 return BAD_VALUE;
360 }
361 displayStates.add(displayState);
362 }
363
364 count = static_cast<size_t>(parcel->readUint32());
365 if (count > parcel->dataSize()) {
366 return BAD_VALUE;
367 }
368 std::unordered_map<sp<SurfaceControl>, ComposerState, SCHash> composerStates;
369 composerStates.reserve(count);
370 for (size_t i = 0; i < count; i++) {
371 sp<SurfaceControl> surfaceControl = SurfaceControl::readFromParcel(parcel);
372
373 ComposerState composerState;
374 if (composerState.read(*parcel) == BAD_VALUE) {
375 return BAD_VALUE;
376 }
377 composerStates[surfaceControl] = composerState;
378 }
379
380 InputWindowCommands inputWindowCommands;
381 inputWindowCommands.read(*parcel);
382
383 // Parsing was successful. Update the object.
384 mForceSynchronous = forceSynchronous;
385 mTransactionNestCount = transactionNestCount;
386 mAnimation = animation;
387 mEarlyWakeup = earlyWakeup;
388 mContainsBuffer = containsBuffer;
389 mDesiredPresentTime = desiredPresentTime;
390 mDisplayStates = displayStates;
391 mComposerStates = composerStates;
392 mInputWindowCommands = inputWindowCommands;
393 // listener callbacks contain function pointer addresses and may not be safe to parcel.
394 mListenerCallbacks.clear();
395 return NO_ERROR;
396}
397
398status_t SurfaceComposerClient::Transaction::writeToParcel(Parcel* parcel) const {
399 parcel->writeUint32(mForceSynchronous);
400 parcel->writeUint32(mTransactionNestCount);
401 parcel->writeBool(mAnimation);
402 parcel->writeBool(mEarlyWakeup);
403 parcel->writeBool(mContainsBuffer);
404 parcel->writeInt64(mDesiredPresentTime);
405 parcel->writeUint32(static_cast<uint32_t>(mDisplayStates.size()));
406 for (auto const& displayState : mDisplayStates) {
407 displayState.write(*parcel);
408 }
409
410 parcel->writeUint32(static_cast<uint32_t>(mComposerStates.size()));
411 for (auto const& [surfaceControl, composerState] : mComposerStates) {
412 surfaceControl->writeToParcel(parcel);
413 composerState.write(*parcel);
414 }
415
416 mInputWindowCommands.write(*parcel);
417 return NO_ERROR;
Mathias Agopian698c0872011-06-28 19:09:31 -0700418}
419
Robert Carr2c5f6d22017-09-26 12:30:35 -0700420SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::merge(Transaction&& other) {
chaviw8e3fe5d2018-02-22 10:55:42 -0800421 for (auto const& kv : other.mComposerStates) {
422 if (mComposerStates.count(kv.first) == 0) {
423 mComposerStates[kv.first] = kv.second;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700424 } else {
chaviw8e3fe5d2018-02-22 10:55:42 -0800425 mComposerStates[kv.first].state.merge(kv.second.state);
Robert Carr2c5f6d22017-09-26 12:30:35 -0700426 }
427 }
Robert Carr2c5f6d22017-09-26 12:30:35 -0700428
429 for (auto const& state : other.mDisplayStates) {
430 ssize_t index = mDisplayStates.indexOf(state);
431 if (index < 0) {
432 mDisplayStates.add(state);
433 } else {
434 mDisplayStates.editItemAt(static_cast<size_t>(index)).merge(state);
435 }
436 }
Robert Carr2c5f6d22017-09-26 12:30:35 -0700437
Marissa Wallc837b5e2018-10-12 10:04:44 -0700438 for (const auto& [listener, callbackInfo] : other.mListenerCallbacks) {
439 auto& [callbackIds, surfaceControls] = callbackInfo;
440 mListenerCallbacks[listener].callbackIds.insert(std::make_move_iterator(
441 callbackIds.begin()),
442 std::make_move_iterator(callbackIds.end()));
443 mListenerCallbacks[listener]
444 .surfaceControls.insert(std::make_move_iterator(surfaceControls.begin()),
445 std::make_move_iterator(surfaceControls.end()));
446 }
Marissa Wallc837b5e2018-10-12 10:04:44 -0700447
chaviw273171b2018-12-26 11:46:30 -0800448 mInputWindowCommands.merge(other.mInputWindowCommands);
449
Marissa Wall78b72202019-03-15 14:58:34 -0700450 mContainsBuffer = other.mContainsBuffer;
Jorim Jaggie3b57002019-07-22 17:18:52 +0200451 mEarlyWakeup = mEarlyWakeup || other.mEarlyWakeup;
Vishnu Nairfef244e2019-06-17 18:07:51 -0700452 other.clear();
Robert Carr2c5f6d22017-09-26 12:30:35 -0700453 return *this;
454}
455
Vishnu Nairfef244e2019-06-17 18:07:51 -0700456void SurfaceComposerClient::Transaction::clear() {
457 mComposerStates.clear();
458 mDisplayStates.clear();
459 mListenerCallbacks.clear();
460 mInputWindowCommands.clear();
461 mContainsBuffer = false;
462 mForceSynchronous = 0;
463 mTransactionNestCount = 0;
464 mAnimation = false;
465 mEarlyWakeup = false;
466 mDesiredPresentTime = -1;
467}
468
Robert Carr6fb1a7e2018-12-11 12:07:25 -0800469void SurfaceComposerClient::doDropReferenceTransaction(const sp<IBinder>& handle,
470 const sp<ISurfaceComposerClient>& client) {
471 sp<ISurfaceComposer> sf(ComposerService::getComposerService());
472 Vector<ComposerState> composerStates;
473 Vector<DisplayState> displayStates;
474
475 ComposerState s;
476 s.client = client;
477 s.state.surface = handle;
478 s.state.what |= layer_state_t::eReparent;
479 s.state.parentHandleForChild = nullptr;
480
481 composerStates.add(s);
Valerie Haufa889122019-04-15 13:56:05 -0700482 sp<IBinder> applyToken = IInterface::asBinder(TransactionCompletedListener::getIInstance());
483 sf->setTransactionState(composerStates, displayStates, 0, applyToken, {}, -1, {}, {});
Marissa Wall78b72202019-03-15 14:58:34 -0700484}
485
486void SurfaceComposerClient::doUncacheBufferTransaction(uint64_t cacheId) {
487 sp<ISurfaceComposer> sf(ComposerService::getComposerService());
488
Marissa Wall947d34e2019-03-29 14:03:53 -0700489 client_cache_t uncacheBuffer;
Marissa Wall78b72202019-03-15 14:58:34 -0700490 uncacheBuffer.token = BufferCache::getInstance().getToken();
Marissa Wall947d34e2019-03-29 14:03:53 -0700491 uncacheBuffer.id = cacheId;
Marissa Wall78b72202019-03-15 14:58:34 -0700492
Valerie Haufa889122019-04-15 13:56:05 -0700493 sp<IBinder> applyToken = IInterface::asBinder(TransactionCompletedListener::getIInstance());
494 sf->setTransactionState({}, {}, 0, applyToken, {}, -1, uncacheBuffer, {});
Marissa Wall78b72202019-03-15 14:58:34 -0700495}
496
497void SurfaceComposerClient::Transaction::cacheBuffers() {
498 if (!mContainsBuffer) {
499 return;
500 }
501
502 size_t count = 0;
503 for (auto& [sc, cs] : mComposerStates) {
504 layer_state_t* s = getLayerState(sc);
505 if (!(s->what & layer_state_t::eBufferChanged)) {
506 continue;
507 }
508
Marissa Wall00597242019-03-27 10:35:19 -0700509 // Don't try to cache a null buffer. Sending null buffers is cheap so we shouldn't waste
510 // time trying to cache them.
511 if (!s->buffer) {
512 continue;
513 }
514
Marissa Wall78b72202019-03-15 14:58:34 -0700515 uint64_t cacheId = 0;
516 status_t ret = BufferCache::getInstance().getCacheId(s->buffer, &cacheId);
517 if (ret == NO_ERROR) {
Marissa Walla141abe2019-03-27 16:28:07 -0700518 s->what &= ~static_cast<uint64_t>(layer_state_t::eBufferChanged);
Marissa Wall78b72202019-03-15 14:58:34 -0700519 s->buffer = nullptr;
520 } else {
521 cacheId = BufferCache::getInstance().cache(s->buffer);
522 }
523 s->what |= layer_state_t::eCachedBufferChanged;
524 s->cachedBuffer.token = BufferCache::getInstance().getToken();
Marissa Wall947d34e2019-03-29 14:03:53 -0700525 s->cachedBuffer.id = cacheId;
Marissa Wall78b72202019-03-15 14:58:34 -0700526
527 // If we have more buffers than the size of the cache, we should stop caching so we don't
528 // evict other buffers in this transaction
529 count++;
530 if (count >= BUFFER_CACHE_MAX_SIZE) {
531 break;
532 }
533 }
Robert Carr6fb1a7e2018-12-11 12:07:25 -0800534}
535
Robert Carr4cdc58f2017-08-23 14:22:20 -0700536status_t SurfaceComposerClient::Transaction::apply(bool synchronous) {
537 if (mStatus != NO_ERROR) {
538 return mStatus;
539 }
540
541 sp<ISurfaceComposer> sf(ComposerService::getComposerService());
542
Marissa Wall3dad52d2019-03-22 14:03:19 -0700543 std::vector<ListenerCallbacks> listenerCallbacks;
544
Marissa Wallc837b5e2018-10-12 10:04:44 -0700545 // For every listener with registered callbacks
546 for (const auto& [listener, callbackInfo] : mListenerCallbacks) {
547 auto& [callbackIds, surfaceControls] = callbackInfo;
548 if (callbackIds.empty()) {
549 continue;
550 }
551
Marissa Wall3dad52d2019-03-22 14:03:19 -0700552 listenerCallbacks.emplace_back(listener, std::move(callbackIds));
Marissa Walle2ffb422018-10-12 11:33:52 -0700553
Marissa Wallc837b5e2018-10-12 10:04:44 -0700554 // If the listener has any SurfaceControls set on this Transaction update the surface state
555 for (const auto& surfaceControl : surfaceControls) {
556 layer_state_t* s = getLayerState(surfaceControl);
557 if (!s) {
558 ALOGE("failed to get layer state");
559 continue;
560 }
Marissa Wall3dad52d2019-03-22 14:03:19 -0700561 s->what |= layer_state_t::eHasListenerCallbacksChanged;
562 s->hasListenerCallbacks = true;
Marissa Wallc837b5e2018-10-12 10:04:44 -0700563 }
564 }
565 mListenerCallbacks.clear();
566
Marissa Wall78b72202019-03-15 14:58:34 -0700567 cacheBuffers();
568
Robert Carr4cdc58f2017-08-23 14:22:20 -0700569 Vector<ComposerState> composerStates;
570 Vector<DisplayState> displayStates;
571 uint32_t flags = 0;
572
573 mForceSynchronous |= synchronous;
574
chaviw8e3fe5d2018-02-22 10:55:42 -0800575 for (auto const& kv : mComposerStates){
576 composerStates.add(kv.second);
577 }
578
Robert Carr4cdc58f2017-08-23 14:22:20 -0700579 mComposerStates.clear();
580
581 displayStates = mDisplayStates;
582 mDisplayStates.clear();
583
584 if (mForceSynchronous) {
585 flags |= ISurfaceComposer::eSynchronous;
586 }
587 if (mAnimation) {
588 flags |= ISurfaceComposer::eAnimation;
589 }
Dan Stoza84d619e2018-03-28 17:07:36 -0700590 if (mEarlyWakeup) {
591 flags |= ISurfaceComposer::eEarlyWakeup;
592 }
Robert Carr4cdc58f2017-08-23 14:22:20 -0700593
594 mForceSynchronous = false;
595 mAnimation = false;
Dan Stoza84d619e2018-03-28 17:07:36 -0700596 mEarlyWakeup = false;
Robert Carr4cdc58f2017-08-23 14:22:20 -0700597
Marissa Wall713b63f2018-10-17 15:42:43 -0700598 sp<IBinder> applyToken = IInterface::asBinder(TransactionCompletedListener::getIInstance());
Marissa Wall17b4e452018-12-26 16:32:34 -0800599 sf->setTransactionState(composerStates, displayStates, flags, applyToken, mInputWindowCommands,
Marissa Wall78b72202019-03-15 14:58:34 -0700600 mDesiredPresentTime,
Marissa Wall3dad52d2019-03-22 14:03:19 -0700601 {} /*uncacheBuffer - only set in doUncacheBufferTransaction*/,
602 listenerCallbacks);
chaviw273171b2018-12-26 11:46:30 -0800603 mInputWindowCommands.clear();
Robert Carr4cdc58f2017-08-23 14:22:20 -0700604 mStatus = NO_ERROR;
605 return NO_ERROR;
Mathias Agopiane57f2922012-08-09 16:29:12 -0700606}
607
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800608// ---------------------------------------------------------------------------
609
Robert Carr4cdc58f2017-08-23 14:22:20 -0700610sp<IBinder> SurfaceComposerClient::createDisplay(const String8& displayName, bool secure) {
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700611 return ComposerService::getComposerService()->createDisplay(displayName,
612 secure);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700613}
614
Robert Carr4cdc58f2017-08-23 14:22:20 -0700615void SurfaceComposerClient::destroyDisplay(const sp<IBinder>& display) {
Jesse Hall6c913be2013-08-08 12:15:49 -0700616 return ComposerService::getComposerService()->destroyDisplay(display);
617}
618
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -0800619std::vector<PhysicalDisplayId> SurfaceComposerClient::getPhysicalDisplayIds() {
620 return ComposerService::getComposerService()->getPhysicalDisplayIds();
621}
622
623std::optional<PhysicalDisplayId> SurfaceComposerClient::getInternalDisplayId() {
624 return ComposerService::getComposerService()->getInternalDisplayId();
625}
626
627sp<IBinder> SurfaceComposerClient::getPhysicalDisplayToken(PhysicalDisplayId displayId) {
628 return ComposerService::getComposerService()->getPhysicalDisplayToken(displayId);
629}
630
631sp<IBinder> SurfaceComposerClient::getInternalDisplayToken() {
632 return ComposerService::getComposerService()->getInternalDisplayToken();
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700633}
634
Robert Carr4cdc58f2017-08-23 14:22:20 -0700635void SurfaceComposerClient::Transaction::setAnimationTransaction() {
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700636 mAnimation = true;
637}
638
Dan Stoza84d619e2018-03-28 17:07:36 -0700639void SurfaceComposerClient::Transaction::setEarlyWakeup() {
640 mEarlyWakeup = true;
641}
642
chaviw763ef572018-02-22 16:04:57 -0800643layer_state_t* SurfaceComposerClient::Transaction::getLayerState(const sp<SurfaceControl>& sc) {
chaviw8e3fe5d2018-02-22 10:55:42 -0800644 if (mComposerStates.count(sc) == 0) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700645 // we don't have it, add an initialized layer_state to our list
chaviw8e3fe5d2018-02-22 10:55:42 -0800646 ComposerState s;
647 s.client = sc->getClient()->mClient;
648 s.state.surface = sc->getHandle();
649 mComposerStates[sc] = s;
Mathias Agopian698c0872011-06-28 19:09:31 -0700650 }
651
chaviw8e3fe5d2018-02-22 10:55:42 -0800652 return &(mComposerStates[sc].state);
Mathias Agopian698c0872011-06-28 19:09:31 -0700653}
654
Marissa Wallc837b5e2018-10-12 10:04:44 -0700655void SurfaceComposerClient::Transaction::registerSurfaceControlForCallback(
656 const sp<SurfaceControl>& sc) {
Marissa Wall80d94ad2019-01-18 16:04:36 -0800657 auto& callbackInfo = mListenerCallbacks[TransactionCompletedListener::getIInstance()];
658 callbackInfo.surfaceControls.insert(sc);
659
660 TransactionCompletedListener::getInstance()
661 ->addSurfaceControlToCallbacks(sc, callbackInfo.callbackIds);
Marissa Wallc837b5e2018-10-12 10:04:44 -0700662}
663
Robert Carr4cdc58f2017-08-23 14:22:20 -0700664SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setPosition(
665 const sp<SurfaceControl>& sc, float x, float y) {
chaviw763ef572018-02-22 16:04:57 -0800666 layer_state_t* s = getLayerState(sc);
Robert Carr4cdc58f2017-08-23 14:22:20 -0700667 if (!s) {
668 mStatus = BAD_INDEX;
669 return *this;
670 }
Mathias Agopian3165cc22012-08-08 19:42:09 -0700671 s->what |= layer_state_t::ePositionChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700672 s->x = x;
673 s->y = y;
Marissa Wallc837b5e2018-10-12 10:04:44 -0700674
675 registerSurfaceControlForCallback(sc);
Robert Carr4cdc58f2017-08-23 14:22:20 -0700676 return *this;
Mathias Agopian698c0872011-06-28 19:09:31 -0700677}
678
Robert Carr4cdc58f2017-08-23 14:22:20 -0700679SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::show(
680 const sp<SurfaceControl>& sc) {
681 return setFlags(sc, 0, layer_state_t::eLayerHidden);
682}
683
684SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::hide(
685 const sp<SurfaceControl>& sc) {
686 return setFlags(sc, layer_state_t::eLayerHidden, layer_state_t::eLayerHidden);
687}
688
689SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setSize(
690 const sp<SurfaceControl>& sc, uint32_t w, uint32_t h) {
chaviw763ef572018-02-22 16:04:57 -0800691 layer_state_t* s = getLayerState(sc);
Robert Carr4cdc58f2017-08-23 14:22:20 -0700692 if (!s) {
693 mStatus = BAD_INDEX;
694 return *this;
695 }
Mathias Agopian3165cc22012-08-08 19:42:09 -0700696 s->what |= layer_state_t::eSizeChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700697 s->w = w;
698 s->h = h;
Jamie Gennis28378392011-10-12 17:39:00 -0700699
Marissa Wallc837b5e2018-10-12 10:04:44 -0700700 registerSurfaceControlForCallback(sc);
Robert Carr4cdc58f2017-08-23 14:22:20 -0700701 return *this;
Mathias Agopian698c0872011-06-28 19:09:31 -0700702}
703
Robert Carr4cdc58f2017-08-23 14:22:20 -0700704SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setLayer(
705 const sp<SurfaceControl>& sc, int32_t z) {
chaviw763ef572018-02-22 16:04:57 -0800706 layer_state_t* s = getLayerState(sc);
Robert Carr4cdc58f2017-08-23 14:22:20 -0700707 if (!s) {
708 mStatus = BAD_INDEX;
709 return *this;
710 }
Mathias Agopian3165cc22012-08-08 19:42:09 -0700711 s->what |= layer_state_t::eLayerChanged;
chaviw32377582019-05-13 11:15:19 -0700712 s->what &= ~layer_state_t::eRelativeLayerChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700713 s->z = z;
Marissa Wallc837b5e2018-10-12 10:04:44 -0700714
715 registerSurfaceControlForCallback(sc);
Robert Carr4cdc58f2017-08-23 14:22:20 -0700716 return *this;
Mathias Agopian698c0872011-06-28 19:09:31 -0700717}
718
Robert Carr4cdc58f2017-08-23 14:22:20 -0700719SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setRelativeLayer(const sp<SurfaceControl>& sc, const sp<IBinder>& relativeTo,
Robert Carrdb66e622017-04-10 16:55:57 -0700720 int32_t z) {
chaviw763ef572018-02-22 16:04:57 -0800721 layer_state_t* s = getLayerState(sc);
Robert Carrdb66e622017-04-10 16:55:57 -0700722 if (!s) {
Robert Carr4cdc58f2017-08-23 14:22:20 -0700723 mStatus = BAD_INDEX;
Robert Carr30c8d902019-04-04 13:12:49 -0700724 return *this;
Robert Carrdb66e622017-04-10 16:55:57 -0700725 }
726 s->what |= layer_state_t::eRelativeLayerChanged;
chaviw32377582019-05-13 11:15:19 -0700727 s->what &= ~layer_state_t::eLayerChanged;
Robert Carrdb66e622017-04-10 16:55:57 -0700728 s->relativeLayerHandle = relativeTo;
729 s->z = z;
Marissa Wallc837b5e2018-10-12 10:04:44 -0700730
731 registerSurfaceControlForCallback(sc);
Robert Carr4cdc58f2017-08-23 14:22:20 -0700732 return *this;
Robert Carrdb66e622017-04-10 16:55:57 -0700733}
734
Robert Carr4cdc58f2017-08-23 14:22:20 -0700735SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setFlags(
736 const sp<SurfaceControl>& sc, uint32_t flags,
Mathias Agopian698c0872011-06-28 19:09:31 -0700737 uint32_t mask) {
chaviw763ef572018-02-22 16:04:57 -0800738 layer_state_t* s = getLayerState(sc);
Robert Carr4cdc58f2017-08-23 14:22:20 -0700739 if (!s) {
740 mStatus = BAD_INDEX;
741 return *this;
742 }
Pablo Ceballos53390e12015-08-04 11:25:59 -0700743 if ((mask & layer_state_t::eLayerOpaque) ||
744 (mask & layer_state_t::eLayerHidden) ||
745 (mask & layer_state_t::eLayerSecure)) {
Dan Stoza23116082015-06-18 14:58:39 -0700746 s->what |= layer_state_t::eFlagsChanged;
Andy McFadden4125a4f2014-01-29 17:17:11 -0800747 }
Mathias Agopian698c0872011-06-28 19:09:31 -0700748 s->flags &= ~mask;
749 s->flags |= (flags & mask);
750 s->mask |= mask;
Marissa Wallc837b5e2018-10-12 10:04:44 -0700751
752 registerSurfaceControlForCallback(sc);
Robert Carr4cdc58f2017-08-23 14:22:20 -0700753 return *this;
Mathias Agopian698c0872011-06-28 19:09:31 -0700754}
755
Robert Carr4cdc58f2017-08-23 14:22:20 -0700756SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setTransparentRegionHint(
757 const sp<SurfaceControl>& sc,
Mathias Agopian698c0872011-06-28 19:09:31 -0700758 const Region& transparentRegion) {
chaviw763ef572018-02-22 16:04:57 -0800759 layer_state_t* s = getLayerState(sc);
Robert Carr4cdc58f2017-08-23 14:22:20 -0700760 if (!s) {
761 mStatus = BAD_INDEX;
762 return *this;
763 }
Mathias Agopian3165cc22012-08-08 19:42:09 -0700764 s->what |= layer_state_t::eTransparentRegionChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700765 s->transparentRegion = transparentRegion;
Marissa Wallc837b5e2018-10-12 10:04:44 -0700766
767 registerSurfaceControlForCallback(sc);
Robert Carr4cdc58f2017-08-23 14:22:20 -0700768 return *this;
Mathias Agopian698c0872011-06-28 19:09:31 -0700769}
770
Robert Carr4cdc58f2017-08-23 14:22:20 -0700771SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setAlpha(
772 const sp<SurfaceControl>& sc, float alpha) {
chaviw763ef572018-02-22 16:04:57 -0800773 layer_state_t* s = getLayerState(sc);
Robert Carr4cdc58f2017-08-23 14:22:20 -0700774 if (!s) {
775 mStatus = BAD_INDEX;
776 return *this;
777 }
Mathias Agopian3165cc22012-08-08 19:42:09 -0700778 s->what |= layer_state_t::eAlphaChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700779 s->alpha = alpha;
Marissa Wallc837b5e2018-10-12 10:04:44 -0700780
781 registerSurfaceControlForCallback(sc);
Robert Carr4cdc58f2017-08-23 14:22:20 -0700782 return *this;
Mathias Agopian698c0872011-06-28 19:09:31 -0700783}
784
Robert Carr4cdc58f2017-08-23 14:22:20 -0700785SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setLayerStack(
786 const sp<SurfaceControl>& sc, uint32_t layerStack) {
chaviw763ef572018-02-22 16:04:57 -0800787 layer_state_t* s = getLayerState(sc);
Robert Carr4cdc58f2017-08-23 14:22:20 -0700788 if (!s) {
789 mStatus = BAD_INDEX;
790 return *this;
791 }
Mathias Agopian3165cc22012-08-08 19:42:09 -0700792 s->what |= layer_state_t::eLayerStackChanged;
Mathias Agopian87855782012-07-24 21:41:09 -0700793 s->layerStack = layerStack;
Marissa Wallc837b5e2018-10-12 10:04:44 -0700794
795 registerSurfaceControlForCallback(sc);
Robert Carr4cdc58f2017-08-23 14:22:20 -0700796 return *this;
Mathias Agopian87855782012-07-24 21:41:09 -0700797}
798
Evan Rosky1f6d6d52018-12-06 10:47:26 -0800799SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setMetadata(
800 const sp<SurfaceControl>& sc, uint32_t key, std::vector<uint8_t> data) {
801 layer_state_t* s = getLayerState(sc);
802 if (!s) {
803 mStatus = BAD_INDEX;
804 return *this;
805 }
806 s->what |= layer_state_t::eMetadataChanged;
807 s->metadata.mMap[key] = std::move(data);
808
809 registerSurfaceControlForCallback(sc);
810 return *this;
811}
812
Robert Carr4cdc58f2017-08-23 14:22:20 -0700813SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setMatrix(
814 const sp<SurfaceControl>& sc, float dsdx, float dtdx,
Robert Carrcb6e1e32017-02-21 19:48:26 -0800815 float dtdy, float dsdy) {
chaviw763ef572018-02-22 16:04:57 -0800816 layer_state_t* s = getLayerState(sc);
Robert Carr4cdc58f2017-08-23 14:22:20 -0700817 if (!s) {
818 mStatus = BAD_INDEX;
819 return *this;
820 }
Mathias Agopian3165cc22012-08-08 19:42:09 -0700821 s->what |= layer_state_t::eMatrixChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700822 layer_state_t::matrix22_t matrix;
823 matrix.dsdx = dsdx;
824 matrix.dtdx = dtdx;
825 matrix.dsdy = dsdy;
826 matrix.dtdy = dtdy;
827 s->matrix = matrix;
Marissa Wallc837b5e2018-10-12 10:04:44 -0700828
829 registerSurfaceControlForCallback(sc);
Robert Carr4cdc58f2017-08-23 14:22:20 -0700830 return *this;
Mathias Agopian698c0872011-06-28 19:09:31 -0700831}
832
Marissa Wallf58c14b2018-07-24 10:50:43 -0700833SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setCrop_legacy(
Robert Carr4cdc58f2017-08-23 14:22:20 -0700834 const sp<SurfaceControl>& sc, const Rect& crop) {
chaviw763ef572018-02-22 16:04:57 -0800835 layer_state_t* s = getLayerState(sc);
Robert Carr4cdc58f2017-08-23 14:22:20 -0700836 if (!s) {
837 mStatus = BAD_INDEX;
838 return *this;
839 }
Marissa Wallf58c14b2018-07-24 10:50:43 -0700840 s->what |= layer_state_t::eCropChanged_legacy;
841 s->crop_legacy = crop;
Marissa Wallc837b5e2018-10-12 10:04:44 -0700842
843 registerSurfaceControlForCallback(sc);
Robert Carr4cdc58f2017-08-23 14:22:20 -0700844 return *this;
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700845}
846
Lucas Dupin1b6531c2018-07-05 17:18:21 -0700847SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setCornerRadius(
848 const sp<SurfaceControl>& sc, float cornerRadius) {
849 layer_state_t* s = getLayerState(sc);
850 if (!s) {
851 mStatus = BAD_INDEX;
852 return *this;
853 }
854 s->what |= layer_state_t::eCornerRadiusChanged;
855 s->cornerRadius = cornerRadius;
856 return *this;
857}
858
Marissa Wallf58c14b2018-07-24 10:50:43 -0700859SurfaceComposerClient::Transaction&
860SurfaceComposerClient::Transaction::deferTransactionUntil_legacy(const sp<SurfaceControl>& sc,
861 const sp<IBinder>& handle,
862 uint64_t frameNumber) {
chaviw763ef572018-02-22 16:04:57 -0800863 layer_state_t* s = getLayerState(sc);
Dan Stoza7dde5992015-05-22 09:51:44 -0700864 if (!s) {
Robert Carr4cdc58f2017-08-23 14:22:20 -0700865 mStatus = BAD_INDEX;
866 return *this;
Dan Stoza7dde5992015-05-22 09:51:44 -0700867 }
Marissa Wallf58c14b2018-07-24 10:50:43 -0700868 s->what |= layer_state_t::eDeferTransaction_legacy;
869 s->barrierHandle_legacy = handle;
870 s->frameNumber_legacy = frameNumber;
Marissa Wallc837b5e2018-10-12 10:04:44 -0700871
872 registerSurfaceControlForCallback(sc);
Robert Carr4cdc58f2017-08-23 14:22:20 -0700873 return *this;
Robert Carr0d480722017-01-10 16:42:54 -0800874}
875
Marissa Wallf58c14b2018-07-24 10:50:43 -0700876SurfaceComposerClient::Transaction&
877SurfaceComposerClient::Transaction::deferTransactionUntil_legacy(const sp<SurfaceControl>& sc,
878 const sp<Surface>& barrierSurface,
879 uint64_t frameNumber) {
chaviw763ef572018-02-22 16:04:57 -0800880 layer_state_t* s = getLayerState(sc);
Robert Carr0d480722017-01-10 16:42:54 -0800881 if (!s) {
Robert Carr4cdc58f2017-08-23 14:22:20 -0700882 mStatus = BAD_INDEX;
883 return *this;
Robert Carr0d480722017-01-10 16:42:54 -0800884 }
Marissa Wallf58c14b2018-07-24 10:50:43 -0700885 s->what |= layer_state_t::eDeferTransaction_legacy;
886 s->barrierGbp_legacy = barrierSurface->getIGraphicBufferProducer();
887 s->frameNumber_legacy = frameNumber;
Marissa Wallc837b5e2018-10-12 10:04:44 -0700888
889 registerSurfaceControlForCallback(sc);
Robert Carr4cdc58f2017-08-23 14:22:20 -0700890 return *this;
Dan Stoza7dde5992015-05-22 09:51:44 -0700891}
892
Robert Carr4cdc58f2017-08-23 14:22:20 -0700893SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::reparentChildren(
894 const sp<SurfaceControl>& sc,
Robert Carr1db73f62016-12-21 12:58:51 -0800895 const sp<IBinder>& newParentHandle) {
chaviw763ef572018-02-22 16:04:57 -0800896 layer_state_t* s = getLayerState(sc);
Robert Carr1db73f62016-12-21 12:58:51 -0800897 if (!s) {
Robert Carr4cdc58f2017-08-23 14:22:20 -0700898 mStatus = BAD_INDEX;
899 return *this;
Robert Carr1db73f62016-12-21 12:58:51 -0800900 }
901 s->what |= layer_state_t::eReparentChildren;
902 s->reparentHandle = newParentHandle;
Marissa Wallc837b5e2018-10-12 10:04:44 -0700903
904 registerSurfaceControlForCallback(sc);
Robert Carr4cdc58f2017-08-23 14:22:20 -0700905 return *this;
Robert Carr1db73f62016-12-21 12:58:51 -0800906}
907
Robert Carr4cdc58f2017-08-23 14:22:20 -0700908SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::reparent(
909 const sp<SurfaceControl>& sc,
chaviwf1961f72017-09-18 16:41:07 -0700910 const sp<IBinder>& newParentHandle) {
chaviw763ef572018-02-22 16:04:57 -0800911 layer_state_t* s = getLayerState(sc);
chaviw06178942017-07-27 10:25:59 -0700912 if (!s) {
Robert Carr4cdc58f2017-08-23 14:22:20 -0700913 mStatus = BAD_INDEX;
914 return *this;
chaviw06178942017-07-27 10:25:59 -0700915 }
chaviwf1961f72017-09-18 16:41:07 -0700916 s->what |= layer_state_t::eReparent;
chaviw06178942017-07-27 10:25:59 -0700917 s->parentHandleForChild = newParentHandle;
Marissa Wallc837b5e2018-10-12 10:04:44 -0700918
919 registerSurfaceControlForCallback(sc);
Robert Carr4cdc58f2017-08-23 14:22:20 -0700920 return *this;
chaviw06178942017-07-27 10:25:59 -0700921}
922
Robert Carr4cdc58f2017-08-23 14:22:20 -0700923SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setColor(
924 const sp<SurfaceControl>& sc,
925 const half3& color) {
chaviw763ef572018-02-22 16:04:57 -0800926 layer_state_t* s = getLayerState(sc);
Robert Carr9524cb32017-02-13 11:32:32 -0800927 if (!s) {
Robert Carr4cdc58f2017-08-23 14:22:20 -0700928 mStatus = BAD_INDEX;
929 return *this;
930 }
931 s->what |= layer_state_t::eColorChanged;
932 s->color = color;
Marissa Wallc837b5e2018-10-12 10:04:44 -0700933
934 registerSurfaceControlForCallback(sc);
Robert Carr4cdc58f2017-08-23 14:22:20 -0700935 return *this;
936}
937
Valerie Haudd0b7572019-01-29 14:59:27 -0800938SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setBackgroundColor(
939 const sp<SurfaceControl>& sc, const half3& color, float alpha, ui::Dataspace dataspace) {
Valerie Haued54efa2019-01-11 20:03:14 -0800940 layer_state_t* s = getLayerState(sc);
941 if (!s) {
942 mStatus = BAD_INDEX;
943 return *this;
944 }
945
Valerie Haudd0b7572019-01-29 14:59:27 -0800946 s->what |= layer_state_t::eBackgroundColorChanged;
947 s->color = color;
948 s->bgColorAlpha = alpha;
949 s->bgColorDataspace = dataspace;
Valerie Haued54efa2019-01-11 20:03:14 -0800950
951 registerSurfaceControlForCallback(sc);
952 return *this;
953}
954
Marissa Wall61c58622018-07-18 10:12:20 -0700955SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setTransform(
956 const sp<SurfaceControl>& sc, uint32_t transform) {
957 layer_state_t* s = getLayerState(sc);
958 if (!s) {
959 mStatus = BAD_INDEX;
960 return *this;
961 }
962 s->what |= layer_state_t::eTransformChanged;
963 s->transform = transform;
Marissa Wallc837b5e2018-10-12 10:04:44 -0700964
965 registerSurfaceControlForCallback(sc);
Marissa Wall61c58622018-07-18 10:12:20 -0700966 return *this;
967}
968
969SurfaceComposerClient::Transaction&
970SurfaceComposerClient::Transaction::setTransformToDisplayInverse(const sp<SurfaceControl>& sc,
971 bool transformToDisplayInverse) {
972 layer_state_t* s = getLayerState(sc);
973 if (!s) {
974 mStatus = BAD_INDEX;
975 return *this;
976 }
977 s->what |= layer_state_t::eTransformToDisplayInverseChanged;
978 s->transformToDisplayInverse = transformToDisplayInverse;
Marissa Wallc837b5e2018-10-12 10:04:44 -0700979
980 registerSurfaceControlForCallback(sc);
Marissa Wall61c58622018-07-18 10:12:20 -0700981 return *this;
982}
983
984SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setCrop(
985 const sp<SurfaceControl>& sc, const Rect& crop) {
986 layer_state_t* s = getLayerState(sc);
987 if (!s) {
988 mStatus = BAD_INDEX;
989 return *this;
990 }
991 s->what |= layer_state_t::eCropChanged;
992 s->crop = crop;
Marissa Wallc837b5e2018-10-12 10:04:44 -0700993
994 registerSurfaceControlForCallback(sc);
Marissa Wall61c58622018-07-18 10:12:20 -0700995 return *this;
996}
997
Marissa Wall861616d2018-10-22 12:52:23 -0700998SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setFrame(
999 const sp<SurfaceControl>& sc, const Rect& frame) {
1000 layer_state_t* s = getLayerState(sc);
1001 if (!s) {
1002 mStatus = BAD_INDEX;
1003 return *this;
1004 }
1005 s->what |= layer_state_t::eFrameChanged;
1006 s->frame = frame;
1007
1008 registerSurfaceControlForCallback(sc);
1009 return *this;
1010}
1011
Marissa Wall61c58622018-07-18 10:12:20 -07001012SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setBuffer(
1013 const sp<SurfaceControl>& sc, const sp<GraphicBuffer>& buffer) {
1014 layer_state_t* s = getLayerState(sc);
1015 if (!s) {
1016 mStatus = BAD_INDEX;
1017 return *this;
1018 }
Marissa Wall78b72202019-03-15 14:58:34 -07001019 s->what |= layer_state_t::eBufferChanged;
1020 s->buffer = buffer;
Marissa Wallebc2c052019-01-16 19:16:55 -08001021
1022 registerSurfaceControlForCallback(sc);
Marissa Wall78b72202019-03-15 14:58:34 -07001023
1024 mContainsBuffer = true;
Marissa Wallebc2c052019-01-16 19:16:55 -08001025 return *this;
1026}
1027
Marissa Wall61c58622018-07-18 10:12:20 -07001028SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setAcquireFence(
1029 const sp<SurfaceControl>& sc, const sp<Fence>& fence) {
1030 layer_state_t* s = getLayerState(sc);
1031 if (!s) {
1032 mStatus = BAD_INDEX;
1033 return *this;
1034 }
1035 s->what |= layer_state_t::eAcquireFenceChanged;
1036 s->acquireFence = fence;
Marissa Wallc837b5e2018-10-12 10:04:44 -07001037
1038 registerSurfaceControlForCallback(sc);
Marissa Wall61c58622018-07-18 10:12:20 -07001039 return *this;
1040}
1041
1042SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setDataspace(
1043 const sp<SurfaceControl>& sc, ui::Dataspace dataspace) {
1044 layer_state_t* s = getLayerState(sc);
1045 if (!s) {
1046 mStatus = BAD_INDEX;
1047 return *this;
1048 }
1049 s->what |= layer_state_t::eDataspaceChanged;
1050 s->dataspace = dataspace;
Marissa Wallc837b5e2018-10-12 10:04:44 -07001051
1052 registerSurfaceControlForCallback(sc);
Marissa Wall61c58622018-07-18 10:12:20 -07001053 return *this;
1054}
1055
1056SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setHdrMetadata(
1057 const sp<SurfaceControl>& sc, const HdrMetadata& hdrMetadata) {
1058 layer_state_t* s = getLayerState(sc);
1059 if (!s) {
1060 mStatus = BAD_INDEX;
1061 return *this;
1062 }
1063 s->what |= layer_state_t::eHdrMetadataChanged;
1064 s->hdrMetadata = hdrMetadata;
Marissa Wallc837b5e2018-10-12 10:04:44 -07001065
1066 registerSurfaceControlForCallback(sc);
Marissa Wall61c58622018-07-18 10:12:20 -07001067 return *this;
1068}
1069
1070SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setSurfaceDamageRegion(
1071 const sp<SurfaceControl>& sc, const Region& surfaceDamageRegion) {
1072 layer_state_t* s = getLayerState(sc);
1073 if (!s) {
1074 mStatus = BAD_INDEX;
1075 return *this;
1076 }
1077 s->what |= layer_state_t::eSurfaceDamageRegionChanged;
1078 s->surfaceDamageRegion = surfaceDamageRegion;
Marissa Wallc837b5e2018-10-12 10:04:44 -07001079
1080 registerSurfaceControlForCallback(sc);
Marissa Wall61c58622018-07-18 10:12:20 -07001081 return *this;
1082}
1083
1084SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setApi(
1085 const sp<SurfaceControl>& sc, int32_t api) {
1086 layer_state_t* s = getLayerState(sc);
1087 if (!s) {
1088 mStatus = BAD_INDEX;
1089 return *this;
1090 }
1091 s->what |= layer_state_t::eApiChanged;
1092 s->api = api;
Marissa Wallc837b5e2018-10-12 10:04:44 -07001093
1094 registerSurfaceControlForCallback(sc);
Marissa Wall61c58622018-07-18 10:12:20 -07001095 return *this;
1096}
1097
1098SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setSidebandStream(
1099 const sp<SurfaceControl>& sc, const sp<NativeHandle>& sidebandStream) {
1100 layer_state_t* s = getLayerState(sc);
1101 if (!s) {
1102 mStatus = BAD_INDEX;
1103 return *this;
1104 }
1105 s->what |= layer_state_t::eSidebandStreamChanged;
1106 s->sidebandStream = sidebandStream;
Marissa Wallc837b5e2018-10-12 10:04:44 -07001107
1108 registerSurfaceControlForCallback(sc);
1109 return *this;
1110}
1111
Marissa Wall17b4e452018-12-26 16:32:34 -08001112SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setDesiredPresentTime(
1113 nsecs_t desiredPresentTime) {
1114 mDesiredPresentTime = desiredPresentTime;
1115 return *this;
1116}
1117
Peiyong Linc502cb72019-03-01 15:00:23 -08001118SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setColorSpaceAgnostic(
1119 const sp<SurfaceControl>& sc, const bool agnostic) {
1120 layer_state_t* s = getLayerState(sc);
1121 if (!s) {
1122 mStatus = BAD_INDEX;
1123 return *this;
1124 }
1125 s->what |= layer_state_t::eColorSpaceAgnosticChanged;
1126 s->colorSpaceAgnostic = agnostic;
1127
1128 registerSurfaceControlForCallback(sc);
1129 return *this;
1130}
1131
Marissa Wallc837b5e2018-10-12 10:04:44 -07001132SurfaceComposerClient::Transaction&
1133SurfaceComposerClient::Transaction::addTransactionCompletedCallback(
Marissa Walle2ffb422018-10-12 11:33:52 -07001134 TransactionCompletedCallbackTakesContext callback, void* callbackContext) {
Marissa Wallc837b5e2018-10-12 10:04:44 -07001135 auto listener = TransactionCompletedListener::getInstance();
1136
Marissa Wall80d94ad2019-01-18 16:04:36 -08001137 auto callbackWithContext = std::bind(callback, callbackContext, std::placeholders::_1,
1138 std::placeholders::_2, std::placeholders::_3);
1139 const auto& surfaceControls =
1140 mListenerCallbacks[TransactionCompletedListener::getIInstance()].surfaceControls;
Marissa Wallc837b5e2018-10-12 10:04:44 -07001141
Marissa Wall80d94ad2019-01-18 16:04:36 -08001142 CallbackId callbackId = listener->addCallbackFunction(callbackWithContext, surfaceControls);
Marissa Wallc837b5e2018-10-12 10:04:44 -07001143
1144 mListenerCallbacks[TransactionCompletedListener::getIInstance()].callbackIds.emplace(
1145 callbackId);
Marissa Wall61c58622018-07-18 10:12:20 -07001146 return *this;
1147}
1148
Robert Carr4cdc58f2017-08-23 14:22:20 -07001149SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::detachChildren(
1150 const sp<SurfaceControl>& sc) {
chaviw763ef572018-02-22 16:04:57 -08001151 layer_state_t* s = getLayerState(sc);
Robert Carr4cdc58f2017-08-23 14:22:20 -07001152 if (!s) {
1153 mStatus = BAD_INDEX;
Greg Kaiserd45fdc32019-04-30 06:14:19 -07001154 return *this;
Robert Carr9524cb32017-02-13 11:32:32 -08001155 }
1156 s->what |= layer_state_t::eDetachChildren;
Marissa Wallc837b5e2018-10-12 10:04:44 -07001157
1158 registerSurfaceControlForCallback(sc);
Robert Carr4cdc58f2017-08-23 14:22:20 -07001159 return *this;
Robert Carr9524cb32017-02-13 11:32:32 -08001160}
1161
Robert Carr4cdc58f2017-08-23 14:22:20 -07001162SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setOverrideScalingMode(
1163 const sp<SurfaceControl>& sc, int32_t overrideScalingMode) {
chaviw763ef572018-02-22 16:04:57 -08001164 layer_state_t* s = getLayerState(sc);
Robert Carrc3574f72016-03-24 12:19:32 -07001165 if (!s) {
Robert Carr4cdc58f2017-08-23 14:22:20 -07001166 mStatus = BAD_INDEX;
1167 return *this;
Robert Carrc3574f72016-03-24 12:19:32 -07001168 }
1169
1170 switch (overrideScalingMode) {
1171 case NATIVE_WINDOW_SCALING_MODE_FREEZE:
1172 case NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW:
1173 case NATIVE_WINDOW_SCALING_MODE_SCALE_CROP:
1174 case NATIVE_WINDOW_SCALING_MODE_NO_SCALE_CROP:
1175 case -1:
1176 break;
1177 default:
1178 ALOGE("unknown scaling mode: %d",
1179 overrideScalingMode);
Robert Carr4cdc58f2017-08-23 14:22:20 -07001180 mStatus = BAD_VALUE;
1181 return *this;
Robert Carrc3574f72016-03-24 12:19:32 -07001182 }
1183
1184 s->what |= layer_state_t::eOverrideScalingModeChanged;
1185 s->overrideScalingMode = overrideScalingMode;
Marissa Wallc837b5e2018-10-12 10:04:44 -07001186
1187 registerSurfaceControlForCallback(sc);
Robert Carr4cdc58f2017-08-23 14:22:20 -07001188 return *this;
Robert Carrc3574f72016-03-24 12:19:32 -07001189}
1190
Robert Carr4cdc58f2017-08-23 14:22:20 -07001191SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setGeometryAppliesWithResize(
1192 const sp<SurfaceControl>& sc) {
chaviw763ef572018-02-22 16:04:57 -08001193 layer_state_t* s = getLayerState(sc);
Robert Carr82364e32016-05-15 11:27:47 -07001194 if (!s) {
Robert Carr4cdc58f2017-08-23 14:22:20 -07001195 mStatus = BAD_INDEX;
1196 return *this;
Robert Carr82364e32016-05-15 11:27:47 -07001197 }
Robert Carr99e27f02016-06-16 15:18:02 -07001198 s->what |= layer_state_t::eGeometryAppliesWithResize;
Marissa Wallc837b5e2018-10-12 10:04:44 -07001199
1200 registerSurfaceControlForCallback(sc);
Robert Carr4cdc58f2017-08-23 14:22:20 -07001201 return *this;
Robert Carr82364e32016-05-15 11:27:47 -07001202}
1203
Robert Carr2c358bf2018-08-08 15:58:15 -07001204#ifndef NO_INPUT
1205SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setInputWindowInfo(
1206 const sp<SurfaceControl>& sc,
1207 const InputWindowInfo& info) {
1208 layer_state_t* s = getLayerState(sc);
1209 if (!s) {
1210 mStatus = BAD_INDEX;
1211 return *this;
1212 }
1213 s->inputInfo = info;
1214 s->what |= layer_state_t::eInputInfoChanged;
1215 return *this;
1216}
chaviw273171b2018-12-26 11:46:30 -08001217
1218SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::transferTouchFocus(
1219 const sp<IBinder>& fromToken, const sp<IBinder>& toToken) {
1220 InputWindowCommands::TransferTouchFocusCommand transferTouchFocusCommand;
1221 transferTouchFocusCommand.fromToken = fromToken;
1222 transferTouchFocusCommand.toToken = toToken;
1223 mInputWindowCommands.transferTouchFocusCommands.emplace_back(transferTouchFocusCommand);
1224 return *this;
1225}
1226
chaviwa911b102019-02-14 10:18:33 -08001227SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::syncInputWindows() {
1228 mInputWindowCommands.syncInputWindows = true;
1229 return *this;
1230}
1231
Robert Carr2c358bf2018-08-08 15:58:15 -07001232#endif
1233
Peiyong Lind3788632018-09-18 16:01:31 -07001234SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setColorTransform(
1235 const sp<SurfaceControl>& sc, const mat3& matrix, const vec3& translation) {
1236 layer_state_t* s = getLayerState(sc);
1237 if (!s) {
1238 mStatus = BAD_INDEX;
1239 return *this;
1240 }
1241 s->what |= layer_state_t::eColorTransformChanged;
1242 s->colorTransform = mat4(matrix, translation);
Marissa Wallc837b5e2018-10-12 10:04:44 -07001243
1244 registerSurfaceControlForCallback(sc);
Peiyong Lind3788632018-09-18 16:01:31 -07001245 return *this;
1246}
1247
Robert Carrfb4d58b2019-01-15 09:21:27 -08001248SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setGeometry(
1249 const sp<SurfaceControl>& sc, const Rect& source, const Rect& dst, int transform) {
1250 setCrop_legacy(sc, source);
1251
1252 int x = dst.left;
1253 int y = dst.top;
Robert Carr66365e42019-04-08 16:58:04 -07001254
1255 float sourceWidth = source.getWidth();
1256 float sourceHeight = source.getHeight();
1257
1258 float xScale = sourceWidth < 0 ? 1.0f : dst.getWidth() / sourceWidth;
1259 float yScale = sourceHeight < 0 ? 1.0f : dst.getHeight() / sourceHeight;
Robert Carrfb4d58b2019-01-15 09:21:27 -08001260 float matrix[4] = {1, 0, 0, 1};
1261
1262 switch (transform) {
1263 case NATIVE_WINDOW_TRANSFORM_FLIP_H:
1264 matrix[0] = -xScale; matrix[1] = 0;
1265 matrix[2] = 0; matrix[3] = yScale;
1266 x += source.getWidth();
1267 break;
1268 case NATIVE_WINDOW_TRANSFORM_FLIP_V:
1269 matrix[0] = xScale; matrix[1] = 0;
1270 matrix[2] = 0; matrix[3] = -yScale;
1271 y += source.getHeight();
1272 break;
1273 case NATIVE_WINDOW_TRANSFORM_ROT_90:
1274 matrix[0] = 0; matrix[1] = -yScale;
1275 matrix[2] = xScale; matrix[3] = 0;
1276 x += source.getHeight();
1277 break;
1278 case NATIVE_WINDOW_TRANSFORM_ROT_180:
1279 matrix[0] = -xScale; matrix[1] = 0;
1280 matrix[2] = 0; matrix[3] = -yScale;
1281 x += source.getWidth();
1282 y += source.getHeight();
1283 break;
1284 case NATIVE_WINDOW_TRANSFORM_ROT_270:
1285 matrix[0] = 0; matrix[1] = yScale;
1286 matrix[2] = -xScale; matrix[3] = 0;
1287 y += source.getWidth();
1288 break;
1289 default:
1290 matrix[0] = xScale; matrix[1] = 0;
1291 matrix[2] = 0; matrix[3] = yScale;
1292 break;
1293 }
1294 setMatrix(sc, matrix[0], matrix[1], matrix[2], matrix[3]);
1295 setPosition(sc, x, y);
1296
1297 return *this;
1298}
1299
Mathias Agopian698c0872011-06-28 19:09:31 -07001300// ---------------------------------------------------------------------------
1301
chaviw763ef572018-02-22 16:04:57 -08001302DisplayState& SurfaceComposerClient::Transaction::getDisplayState(const sp<IBinder>& token) {
Mathias Agopiane57f2922012-08-09 16:29:12 -07001303 DisplayState s;
1304 s.token = token;
1305 ssize_t index = mDisplayStates.indexOf(s);
1306 if (index < 0) {
1307 // we don't have it, add an initialized layer_state to our list
1308 s.what = 0;
1309 index = mDisplayStates.add(s);
1310 }
Dan Stozad723bd72014-11-18 10:24:03 -08001311 return mDisplayStates.editItemAt(static_cast<size_t>(index));
Mathias Agopiane57f2922012-08-09 16:29:12 -07001312}
1313
Robert Carr4cdc58f2017-08-23 14:22:20 -07001314status_t SurfaceComposerClient::Transaction::setDisplaySurface(const sp<IBinder>& token,
1315 const sp<IGraphicBufferProducer>& bufferProducer) {
Pablo Ceballoseddbef82016-09-01 11:21:21 -07001316 if (bufferProducer.get() != nullptr) {
1317 // Make sure that composition can never be stalled by a virtual display
1318 // consumer that isn't processing buffers fast enough.
1319 status_t err = bufferProducer->setAsyncMode(true);
1320 if (err != NO_ERROR) {
1321 ALOGE("Composer::setDisplaySurface Failed to enable async mode on the "
1322 "BufferQueue. This BufferQueue cannot be used for virtual "
1323 "display. (%d)", err);
1324 return err;
1325 }
Pablo Ceballos1aad24c2016-08-04 10:24:22 -07001326 }
chaviw763ef572018-02-22 16:04:57 -08001327 DisplayState& s(getDisplayState(token));
Andy McFadden2adaf042012-12-18 09:49:45 -08001328 s.surface = bufferProducer;
Mathias Agopiane57f2922012-08-09 16:29:12 -07001329 s.what |= DisplayState::eSurfaceChanged;
Pablo Ceballos1aad24c2016-08-04 10:24:22 -07001330 return NO_ERROR;
Mathias Agopiane57f2922012-08-09 16:29:12 -07001331}
1332
Robert Carr4cdc58f2017-08-23 14:22:20 -07001333void SurfaceComposerClient::Transaction::setDisplayLayerStack(const sp<IBinder>& token,
Mathias Agopiane57f2922012-08-09 16:29:12 -07001334 uint32_t layerStack) {
chaviw763ef572018-02-22 16:04:57 -08001335 DisplayState& s(getDisplayState(token));
Mathias Agopiane57f2922012-08-09 16:29:12 -07001336 s.layerStack = layerStack;
1337 s.what |= DisplayState::eLayerStackChanged;
1338}
1339
Robert Carr4cdc58f2017-08-23 14:22:20 -07001340void SurfaceComposerClient::Transaction::setDisplayProjection(const sp<IBinder>& token,
Mathias Agopian00e8c7a2012-09-04 19:30:46 -07001341 uint32_t orientation,
1342 const Rect& layerStackRect,
1343 const Rect& displayRect) {
chaviw763ef572018-02-22 16:04:57 -08001344 DisplayState& s(getDisplayState(token));
Mathias Agopiane57f2922012-08-09 16:29:12 -07001345 s.orientation = orientation;
Mathias Agopian00e8c7a2012-09-04 19:30:46 -07001346 s.viewport = layerStackRect;
1347 s.frame = displayRect;
1348 s.what |= DisplayState::eDisplayProjectionChanged;
Jorim Jaggi092123c2016-04-13 01:40:35 +00001349 mForceSynchronous = true; // TODO: do we actually still need this?
Mathias Agopiane57f2922012-08-09 16:29:12 -07001350}
1351
Robert Carr4cdc58f2017-08-23 14:22:20 -07001352void SurfaceComposerClient::Transaction::setDisplaySize(const sp<IBinder>& token, uint32_t width, uint32_t height) {
chaviw763ef572018-02-22 16:04:57 -08001353 DisplayState& s(getDisplayState(token));
Michael Wright1f6078a2014-06-26 16:01:02 -07001354 s.width = width;
1355 s.height = height;
1356 s.what |= DisplayState::eDisplaySizeChanged;
1357}
1358
Mathias Agopiane57f2922012-08-09 16:29:12 -07001359// ---------------------------------------------------------------------------
1360
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001361SurfaceComposerClient::SurfaceComposerClient()
Robert Carr4cdc58f2017-08-23 14:22:20 -07001362 : mStatus(NO_INIT)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001363{
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001364}
1365
Jorim Jaggif3cf4bc2017-11-30 14:19:23 +01001366SurfaceComposerClient::SurfaceComposerClient(const sp<ISurfaceComposerClient>& client)
1367 : mStatus(NO_ERROR), mClient(client)
1368{
1369}
1370
Mathias Agopian698c0872011-06-28 19:09:31 -07001371void SurfaceComposerClient::onFirstRef() {
Robert Carr4cdc58f2017-08-23 14:22:20 -07001372 sp<ISurfaceComposer> sf(ComposerService::getComposerService());
Yi Kong48a619f2018-06-05 16:34:59 -07001373 if (sf != nullptr && mStatus == NO_INIT) {
Robert Carr1db73f62016-12-21 12:58:51 -08001374 sp<ISurfaceComposerClient> conn;
Robert Carrb89ea9d2018-12-10 13:01:14 -08001375 conn = sf->createConnection();
Yi Kong48a619f2018-06-05 16:34:59 -07001376 if (conn != nullptr) {
Mathias Agopiand4784a32010-05-27 19:41:15 -07001377 mClient = conn;
Mathias Agopiand4784a32010-05-27 19:41:15 -07001378 mStatus = NO_ERROR;
1379 }
1380 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001381}
1382
Mathias Agopian698c0872011-06-28 19:09:31 -07001383SurfaceComposerClient::~SurfaceComposerClient() {
Mathias Agopian631f3582010-05-25 17:51:34 -07001384 dispose();
1385}
Mathias Agopiandd3423c2009-09-23 15:44:05 -07001386
Mathias Agopian698c0872011-06-28 19:09:31 -07001387status_t SurfaceComposerClient::initCheck() const {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001388 return mStatus;
1389}
1390
Mathias Agopian698c0872011-06-28 19:09:31 -07001391sp<IBinder> SurfaceComposerClient::connection() const {
Marco Nelissen2ea926b2014-11-14 08:01:01 -08001392 return IInterface::asBinder(mClient);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001393}
1394
Mathias Agopiand4784a32010-05-27 19:41:15 -07001395status_t SurfaceComposerClient::linkToComposerDeath(
1396 const sp<IBinder::DeathRecipient>& recipient,
Mathias Agopian698c0872011-06-28 19:09:31 -07001397 void* cookie, uint32_t flags) {
Robert Carr4cdc58f2017-08-23 14:22:20 -07001398 sp<ISurfaceComposer> sf(ComposerService::getComposerService());
1399 return IInterface::asBinder(sf)->linkToDeath(recipient, cookie, flags);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001400}
1401
Mathias Agopian698c0872011-06-28 19:09:31 -07001402void SurfaceComposerClient::dispose() {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001403 // this can be called more than once.
Mathias Agopian7e27f052010-05-28 14:22:23 -07001404 sp<ISurfaceComposerClient> client;
Mathias Agopiand4784a32010-05-27 19:41:15 -07001405 Mutex::Autolock _lm(mLock);
Yi Kong48a619f2018-06-05 16:34:59 -07001406 if (mClient != nullptr) {
Mathias Agopiand4784a32010-05-27 19:41:15 -07001407 client = mClient; // hold ref while lock is held
1408 mClient.clear();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001409 }
Mathias Agopiand4784a32010-05-27 19:41:15 -07001410 mStatus = NO_INIT;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001411}
1412
Evan Rosky1f6d6d52018-12-06 10:47:26 -08001413sp<SurfaceControl> SurfaceComposerClient::createSurface(const String8& name, uint32_t w, uint32_t h,
1414 PixelFormat format, uint32_t flags,
1415 SurfaceControl* parent,
1416 LayerMetadata metadata) {
Robert Carr3b382ed2018-03-14 13:49:41 -07001417 sp<SurfaceControl> s;
Evan Rosky1f6d6d52018-12-06 10:47:26 -08001418 createSurfaceChecked(name, w, h, format, &s, flags, parent, std::move(metadata));
Robert Carr3b382ed2018-03-14 13:49:41 -07001419 return s;
1420}
1421
Marissa Wall35187b32019-01-08 10:08:52 -08001422sp<SurfaceControl> SurfaceComposerClient::createWithSurfaceParent(const String8& name, uint32_t w,
1423 uint32_t h, PixelFormat format,
1424 uint32_t flags, Surface* parent,
Evan Rosky1f6d6d52018-12-06 10:47:26 -08001425 LayerMetadata metadata) {
Marissa Wall35187b32019-01-08 10:08:52 -08001426 sp<SurfaceControl> sur;
1427 status_t err = mStatus;
1428
1429 if (mStatus == NO_ERROR) {
1430 sp<IBinder> handle;
1431 sp<IGraphicBufferProducer> parentGbp = parent->getIGraphicBufferProducer();
1432 sp<IGraphicBufferProducer> gbp;
1433
Evan Rosky1f6d6d52018-12-06 10:47:26 -08001434 err = mClient->createWithSurfaceParent(name, w, h, format, flags, parentGbp,
1435 std::move(metadata), &handle, &gbp);
Marissa Wall35187b32019-01-08 10:08:52 -08001436 ALOGE_IF(err, "SurfaceComposerClient::createWithSurfaceParent error %s", strerror(-err));
1437 if (err == NO_ERROR) {
1438 return new SurfaceControl(this, handle, gbp, true /* owned */);
1439 }
1440 }
1441 return nullptr;
1442}
1443
Evan Rosky1f6d6d52018-12-06 10:47:26 -08001444status_t SurfaceComposerClient::createSurfaceChecked(const String8& name, uint32_t w, uint32_t h,
1445 PixelFormat format,
1446 sp<SurfaceControl>* outSurface, uint32_t flags,
1447 SurfaceControl* parent,
1448 LayerMetadata metadata) {
Mathias Agopian4d9b8222013-03-12 17:11:48 -07001449 sp<SurfaceControl> sur;
Robert Carr740eaf02018-03-27 12:59:18 -07001450 status_t err = mStatus;
Robert Carr3b382ed2018-03-14 13:49:41 -07001451
Mathias Agopian698c0872011-06-28 19:09:31 -07001452 if (mStatus == NO_ERROR) {
Mathias Agopian4d9b8222013-03-12 17:11:48 -07001453 sp<IBinder> handle;
Robert Carr1f0a16a2016-10-24 16:27:39 -07001454 sp<IBinder> parentHandle;
Mathias Agopian4d9b8222013-03-12 17:11:48 -07001455 sp<IGraphicBufferProducer> gbp;
Robert Carr1f0a16a2016-10-24 16:27:39 -07001456
1457 if (parent != nullptr) {
1458 parentHandle = parent->getHandle();
1459 }
Evan Rosky1f6d6d52018-12-06 10:47:26 -08001460
1461 err = mClient->createSurface(name, w, h, format, flags, parentHandle, std::move(metadata),
1462 &handle, &gbp);
Mathias Agopian4d9b8222013-03-12 17:11:48 -07001463 ALOGE_IF(err, "SurfaceComposerClient::createSurface error %s", strerror(-err));
1464 if (err == NO_ERROR) {
Robert Carr3b382ed2018-03-14 13:49:41 -07001465 *outSurface = new SurfaceControl(this, handle, gbp, true /* owned */);
Mathias Agopian698c0872011-06-28 19:09:31 -07001466 }
1467 }
Robert Carr3b382ed2018-03-14 13:49:41 -07001468 return err;
Mathias Agopian698c0872011-06-28 19:09:31 -07001469}
1470
Svetoslavd85084b2014-03-20 10:28:31 -07001471status_t SurfaceComposerClient::clearLayerFrameStats(const sp<IBinder>& token) const {
1472 if (mStatus != NO_ERROR) {
1473 return mStatus;
1474 }
1475 return mClient->clearLayerFrameStats(token);
1476}
1477
1478status_t SurfaceComposerClient::getLayerFrameStats(const sp<IBinder>& token,
1479 FrameStats* outStats) const {
1480 if (mStatus != NO_ERROR) {
1481 return mStatus;
1482 }
1483 return mClient->getLayerFrameStats(token, outStats);
1484}
1485
Mathias Agopian698c0872011-06-28 19:09:31 -07001486// ----------------------------------------------------------------------------
1487
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -07001488status_t SurfaceComposerClient::enableVSyncInjections(bool enable) {
Robert Carr4cdc58f2017-08-23 14:22:20 -07001489 sp<ISurfaceComposer> sf(ComposerService::getComposerService());
1490 return sf->enableVSyncInjections(enable);
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -07001491}
1492
1493status_t SurfaceComposerClient::injectVSync(nsecs_t when) {
Robert Carr4cdc58f2017-08-23 14:22:20 -07001494 sp<ISurfaceComposer> sf(ComposerService::getComposerService());
1495 return sf->injectVSync(when);
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -07001496}
1497
Dan Stoza7f7da322014-05-02 15:26:25 -07001498status_t SurfaceComposerClient::getDisplayConfigs(
1499 const sp<IBinder>& display, Vector<DisplayInfo>* configs)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001500{
Dan Stoza7f7da322014-05-02 15:26:25 -07001501 return ComposerService::getComposerService()->getDisplayConfigs(display, configs);
1502}
1503
1504status_t SurfaceComposerClient::getDisplayInfo(const sp<IBinder>& display,
1505 DisplayInfo* info) {
1506 Vector<DisplayInfo> configs;
1507 status_t result = getDisplayConfigs(display, &configs);
1508 if (result != NO_ERROR) {
1509 return result;
1510 }
1511
1512 int activeId = getActiveConfig(display);
1513 if (activeId < 0) {
1514 ALOGE("No active configuration found");
1515 return NAME_NOT_FOUND;
1516 }
1517
Dan Stozad723bd72014-11-18 10:24:03 -08001518 *info = configs[static_cast<size_t>(activeId)];
Dan Stoza7f7da322014-05-02 15:26:25 -07001519 return NO_ERROR;
1520}
1521
1522int SurfaceComposerClient::getActiveConfig(const sp<IBinder>& display) {
1523 return ComposerService::getComposerService()->getActiveConfig(display);
1524}
1525
1526status_t SurfaceComposerClient::setActiveConfig(const sp<IBinder>& display, int id) {
1527 return ComposerService::getComposerService()->setActiveConfig(display, id);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001528}
1529
Ady Abraham838de062019-02-04 10:24:03 -08001530status_t SurfaceComposerClient::setAllowedDisplayConfigs(
1531 const sp<IBinder>& displayToken, const std::vector<int32_t>& allowedConfigs) {
1532 return ComposerService::getComposerService()->setAllowedDisplayConfigs(displayToken,
1533 allowedConfigs);
1534}
1535
Ady Abrahamd9b3ea62019-02-26 14:08:03 -08001536status_t SurfaceComposerClient::getAllowedDisplayConfigs(const sp<IBinder>& displayToken,
1537 std::vector<int32_t>* outAllowedConfigs) {
1538 return ComposerService::getComposerService()->getAllowedDisplayConfigs(displayToken,
1539 outAllowedConfigs);
1540}
1541
Michael Wright28f24d02016-07-12 13:30:53 -07001542status_t SurfaceComposerClient::getDisplayColorModes(const sp<IBinder>& display,
Peiyong Lina52f0292018-03-14 17:26:31 -07001543 Vector<ColorMode>* outColorModes) {
Michael Wright28f24d02016-07-12 13:30:53 -07001544 return ComposerService::getComposerService()->getDisplayColorModes(display, outColorModes);
1545}
1546
Daniel Solomon42d04562019-01-20 21:03:19 -08001547status_t SurfaceComposerClient::getDisplayNativePrimaries(const sp<IBinder>& display,
1548 ui::DisplayPrimaries& outPrimaries) {
1549 return ComposerService::getComposerService()->getDisplayNativePrimaries(display, outPrimaries);
1550}
1551
Peiyong Lina52f0292018-03-14 17:26:31 -07001552ColorMode SurfaceComposerClient::getActiveColorMode(const sp<IBinder>& display) {
Michael Wright28f24d02016-07-12 13:30:53 -07001553 return ComposerService::getComposerService()->getActiveColorMode(display);
1554}
1555
1556status_t SurfaceComposerClient::setActiveColorMode(const sp<IBinder>& display,
Peiyong Lina52f0292018-03-14 17:26:31 -07001557 ColorMode colorMode) {
Michael Wright28f24d02016-07-12 13:30:53 -07001558 return ComposerService::getComposerService()->setActiveColorMode(display, colorMode);
1559}
1560
Prashant Malani2c9b11f2014-05-25 01:36:31 -07001561void SurfaceComposerClient::setDisplayPowerMode(const sp<IBinder>& token,
1562 int mode) {
1563 ComposerService::getComposerService()->setPowerMode(token, mode);
Jeff Brown2a09bb32012-10-08 19:13:57 -07001564}
1565
Peiyong Linc6780972018-10-28 15:24:08 -07001566status_t SurfaceComposerClient::getCompositionPreference(
1567 ui::Dataspace* defaultDataspace, ui::PixelFormat* defaultPixelFormat,
1568 ui::Dataspace* wideColorGamutDataspace, ui::PixelFormat* wideColorGamutPixelFormat) {
1569 return ComposerService::getComposerService()
1570 ->getCompositionPreference(defaultDataspace, defaultPixelFormat,
1571 wideColorGamutDataspace, wideColorGamutPixelFormat);
Peiyong Lin0256f722018-08-31 15:45:10 -07001572}
1573
Peiyong Lin08d10512019-01-16 13:27:35 -08001574bool SurfaceComposerClient::getProtectedContentSupport() {
1575 bool supported = false;
1576 ComposerService::getComposerService()->getProtectedContentSupport(&supported);
1577 return supported;
1578}
1579
Svetoslavd85084b2014-03-20 10:28:31 -07001580status_t SurfaceComposerClient::clearAnimationFrameStats() {
1581 return ComposerService::getComposerService()->clearAnimationFrameStats();
1582}
1583
1584status_t SurfaceComposerClient::getAnimationFrameStats(FrameStats* outStats) {
1585 return ComposerService::getComposerService()->getAnimationFrameStats(outStats);
1586}
1587
Dan Stozac4f471e2016-03-24 09:31:08 -07001588status_t SurfaceComposerClient::getHdrCapabilities(const sp<IBinder>& display,
1589 HdrCapabilities* outCapabilities) {
1590 return ComposerService::getComposerService()->getHdrCapabilities(display,
1591 outCapabilities);
1592}
1593
Kevin DuBois9c0a1762018-10-16 13:32:31 -07001594status_t SurfaceComposerClient::getDisplayedContentSamplingAttributes(const sp<IBinder>& display,
1595 ui::PixelFormat* outFormat,
1596 ui::Dataspace* outDataspace,
1597 uint8_t* outComponentMask) {
1598 return ComposerService::getComposerService()
1599 ->getDisplayedContentSamplingAttributes(display, outFormat, outDataspace,
1600 outComponentMask);
1601}
1602
Kevin DuBois74e53772018-11-19 10:52:38 -08001603status_t SurfaceComposerClient::setDisplayContentSamplingEnabled(const sp<IBinder>& display,
1604 bool enable, uint8_t componentMask,
1605 uint64_t maxFrames) {
1606 return ComposerService::getComposerService()->setDisplayContentSamplingEnabled(display, enable,
1607 componentMask,
1608 maxFrames);
1609}
1610
Kevin DuBois1d4249a2018-08-29 10:45:14 -07001611status_t SurfaceComposerClient::getDisplayedContentSample(const sp<IBinder>& display,
1612 uint64_t maxFrames, uint64_t timestamp,
1613 DisplayedFrameStats* outStats) {
1614 return ComposerService::getComposerService()->getDisplayedContentSample(display, maxFrames,
1615 timestamp, outStats);
1616}
Marissa Wall35187b32019-01-08 10:08:52 -08001617
Peiyong Lin4f3fddf2019-01-24 17:21:24 -08001618status_t SurfaceComposerClient::isWideColorDisplay(const sp<IBinder>& display,
1619 bool* outIsWideColorDisplay) {
1620 return ComposerService::getComposerService()->isWideColorDisplay(display,
1621 outIsWideColorDisplay);
1622}
1623
Kevin DuBois00c66832019-02-18 16:21:31 -08001624status_t SurfaceComposerClient::addRegionSamplingListener(
1625 const Rect& samplingArea, const sp<IBinder>& stopLayerHandle,
1626 const sp<IRegionSamplingListener>& listener) {
1627 return ComposerService::getComposerService()->addRegionSamplingListener(samplingArea,
1628 stopLayerHandle,
1629 listener);
1630}
1631
1632status_t SurfaceComposerClient::removeRegionSamplingListener(
1633 const sp<IRegionSamplingListener>& listener) {
1634 return ComposerService::getComposerService()->removeRegionSamplingListener(listener);
1635}
1636
Dan Gittik57e63c52019-01-18 16:37:54 +00001637bool SurfaceComposerClient::getDisplayBrightnessSupport(const sp<IBinder>& displayToken) {
1638 bool support = false;
1639 ComposerService::getComposerService()->getDisplayBrightnessSupport(displayToken, &support);
1640 return support;
1641}
1642
1643status_t SurfaceComposerClient::setDisplayBrightness(const sp<IBinder>& displayToken,
1644 float brightness) {
1645 return ComposerService::getComposerService()->setDisplayBrightness(displayToken, brightness);
1646}
1647
Ady Abraham8532d012019-05-08 14:50:56 -07001648status_t SurfaceComposerClient::notifyPowerHint(int32_t hintId) {
1649 return ComposerService::getComposerService()->notifyPowerHint(hintId);
1650}
1651
Mathias Agopian698c0872011-06-28 19:09:31 -07001652// ----------------------------------------------------------------------------
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001653
Peiyong Lin0e003c92018-09-17 11:09:51 -07001654status_t ScreenshotClient::capture(const sp<IBinder>& display, const ui::Dataspace reqDataSpace,
1655 const ui::PixelFormat reqPixelFormat, Rect sourceCrop,
1656 uint32_t reqWidth, uint32_t reqHeight, bool useIdentityTransform,
Robert Carr108b2c72019-04-02 16:32:58 -07001657 uint32_t rotation, bool captureSecureLayers,
1658 sp<GraphicBuffer>* outBuffer, bool& outCapturedSecureLayers) {
Mathias Agopian2a9fc492013-03-01 13:42:57 -08001659 sp<ISurfaceComposer> s(ComposerService::getComposerService());
Yi Kong48a619f2018-06-05 16:34:59 -07001660 if (s == nullptr) return NO_INIT;
Robert Carr108b2c72019-04-02 16:32:58 -07001661 status_t ret =
1662 s->captureScreen(display, outBuffer, outCapturedSecureLayers, reqDataSpace,
1663 reqPixelFormat, sourceCrop, reqWidth, reqHeight, useIdentityTransform,
1664 static_cast<ISurfaceComposer::Rotation>(rotation),
1665 captureSecureLayers);
Robert Carr673134e2017-01-09 19:48:38 -08001666 if (ret != NO_ERROR) {
1667 return ret;
1668 }
Robert Carr673134e2017-01-09 19:48:38 -08001669 return ret;
1670}
1671
Robert Carrfa8855f2019-02-19 10:05:00 -08001672status_t ScreenshotClient::capture(const sp<IBinder>& display, const ui::Dataspace reqDataSpace,
1673 const ui::PixelFormat reqPixelFormat, Rect sourceCrop,
1674 uint32_t reqWidth, uint32_t reqHeight, bool useIdentityTransform,
1675 uint32_t rotation, sp<GraphicBuffer>* outBuffer) {
Robert Carr108b2c72019-04-02 16:32:58 -07001676 bool ignored;
1677 return capture(display, reqDataSpace, reqPixelFormat, sourceCrop, reqWidth, reqHeight,
1678 useIdentityTransform, rotation, false, outBuffer, ignored);
Robert Carrfa8855f2019-02-19 10:05:00 -08001679}
1680
chaviw93df2ea2019-04-30 16:45:12 -07001681status_t ScreenshotClient::capture(uint64_t displayOrLayerStack, ui::Dataspace* outDataspace,
1682 sp<GraphicBuffer>* outBuffer) {
1683 sp<ISurfaceComposer> s(ComposerService::getComposerService());
1684 if (s == nullptr) return NO_INIT;
1685 return s->captureScreen(displayOrLayerStack, outDataspace, outBuffer);
1686}
1687
Peiyong Lin0e003c92018-09-17 11:09:51 -07001688status_t ScreenshotClient::captureLayers(const sp<IBinder>& layerHandle,
1689 const ui::Dataspace reqDataSpace,
1690 const ui::PixelFormat reqPixelFormat, Rect sourceCrop,
Chavi Weingarten40482ff2017-11-30 01:51:40 +00001691 float frameScale, sp<GraphicBuffer>* outBuffer) {
chaviwa76b2712017-09-20 12:02:26 -07001692 sp<ISurfaceComposer> s(ComposerService::getComposerService());
Yi Kong48a619f2018-06-05 16:34:59 -07001693 if (s == nullptr) return NO_INIT;
Peiyong Lin0e003c92018-09-17 11:09:51 -07001694 status_t ret = s->captureLayers(layerHandle, outBuffer, reqDataSpace, reqPixelFormat,
Robert Carr866455f2019-04-02 16:28:26 -07001695 sourceCrop, {}, frameScale, false /* childrenOnly */);
Robert Carr578038f2018-03-09 12:25:24 -08001696 return ret;
1697}
1698
Robert Carr866455f2019-04-02 16:28:26 -07001699status_t ScreenshotClient::captureChildLayers(
1700 const sp<IBinder>& layerHandle, const ui::Dataspace reqDataSpace,
1701 const ui::PixelFormat reqPixelFormat, Rect sourceCrop,
1702 const std::unordered_set<sp<IBinder>, ISurfaceComposer::SpHash<IBinder>>& excludeHandles,
1703 float frameScale, sp<GraphicBuffer>* outBuffer) {
Robert Carr578038f2018-03-09 12:25:24 -08001704 sp<ISurfaceComposer> s(ComposerService::getComposerService());
Yi Kong48a619f2018-06-05 16:34:59 -07001705 if (s == nullptr) return NO_INIT;
Robert Carr866455f2019-04-02 16:28:26 -07001706 status_t ret =
1707 s->captureLayers(layerHandle, outBuffer, reqDataSpace, reqPixelFormat, sourceCrop,
1708 excludeHandles, frameScale, true /* childrenOnly */);
chaviw7206d492017-11-10 16:16:12 -08001709 return ret;
chaviwa76b2712017-09-20 12:02:26 -07001710}
Mathias Agopian74c40c02010-09-29 13:02:36 -07001711// ----------------------------------------------------------------------------
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001712}; // namespace android