blob: 67dd726ebaf279390e49a422a02833d2489d2813 [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 */
Vishnu Nairf03652d2019-07-16 17:56:56 -0700205 std::unordered_map<sp<IBinder>, sp<SurfaceControl>, SurfaceComposerClient::IBinderHash>
206 surfaceControls;
Marissa Walld600d572019-03-26 15:38:50 -0700207 for (const auto& transactionStats : listenerStats.transactionStats) {
208 for (auto callbackId : transactionStats.callbackIds) {
Marissa Wall80d94ad2019-01-18 16:04:36 -0800209 auto& [callbackFunction, callbackSurfaceControls] = mCallbacks[callbackId];
210 surfaceControls.insert(callbackSurfaceControls.begin(), callbackSurfaceControls.end());
211 }
212 }
213
Marissa Walld600d572019-03-26 15:38:50 -0700214 for (const auto& transactionStats : listenerStats.transactionStats) {
215 for (auto callbackId : transactionStats.callbackIds) {
Marissa Wall80d94ad2019-01-18 16:04:36 -0800216 auto& [callbackFunction, callbackSurfaceControls] = mCallbacks[callbackId];
217 if (!callbackFunction) {
Marissa Walle2ffb422018-10-12 11:33:52 -0700218 ALOGE("cannot call null callback function, skipping");
219 continue;
220 }
Marissa Wall80d94ad2019-01-18 16:04:36 -0800221 std::vector<SurfaceControlStats> surfaceControlStats;
222 for (const auto& surfaceStats : transactionStats.surfaceStats) {
223 surfaceControlStats.emplace_back(surfaceControls[surfaceStats.surfaceControl],
224 surfaceStats.acquireTime,
225 surfaceStats.previousReleaseFence);
226 }
227
228 callbackFunction(transactionStats.latchTime, transactionStats.presentFence,
229 surfaceControlStats);
Marissa Walle2ffb422018-10-12 11:33:52 -0700230 mCallbacks.erase(callbackId);
231 }
232 }
Marissa Wall7a9b6ff2018-08-21 17:26:20 -0700233}
234
235// ---------------------------------------------------------------------------
236
Marissa Wall78b72202019-03-15 14:58:34 -0700237void bufferCacheCallback(void* /*context*/, uint64_t graphicBufferId);
238
Marissa Wall73411622019-01-25 10:45:41 -0800239class BufferCache : public Singleton<BufferCache> {
240public:
241 BufferCache() : token(new BBinder()) {}
242
243 sp<IBinder> getToken() {
244 return IInterface::asBinder(TransactionCompletedListener::getIInstance());
245 }
246
Marissa Wall78b72202019-03-15 14:58:34 -0700247 status_t getCacheId(const sp<GraphicBuffer>& buffer, uint64_t* cacheId) {
Yi Kongd2639aa2019-02-28 11:58:32 -0800248 std::lock_guard<std::mutex> lock(mMutex);
Marissa Wall73411622019-01-25 10:45:41 -0800249
Marissa Wall78b72202019-03-15 14:58:34 -0700250 auto itr = mBuffers.find(buffer->getId());
Marissa Wall73411622019-01-25 10:45:41 -0800251 if (itr == mBuffers.end()) {
Marissa Wall78b72202019-03-15 14:58:34 -0700252 return BAD_VALUE;
Marissa Wall73411622019-01-25 10:45:41 -0800253 }
Marissa Wall78b72202019-03-15 14:58:34 -0700254 itr->second = getCounter();
255 *cacheId = buffer->getId();
256 return NO_ERROR;
Marissa Wall73411622019-01-25 10:45:41 -0800257 }
258
Marissa Wall78b72202019-03-15 14:58:34 -0700259 uint64_t cache(const sp<GraphicBuffer>& buffer) {
Yi Kongd2639aa2019-02-28 11:58:32 -0800260 std::lock_guard<std::mutex> lock(mMutex);
Marissa Wall73411622019-01-25 10:45:41 -0800261
Marissa Wall78b72202019-03-15 14:58:34 -0700262 if (mBuffers.size() >= BUFFER_CACHE_MAX_SIZE) {
263 evictLeastRecentlyUsedBuffer();
264 }
Marissa Wall73411622019-01-25 10:45:41 -0800265
Marissa Wall78b72202019-03-15 14:58:34 -0700266 buffer->addDeathCallback(bufferCacheCallback, nullptr);
267
268 mBuffers[buffer->getId()] = getCounter();
269 return buffer->getId();
270 }
271
272 void uncache(uint64_t cacheId) {
273 std::lock_guard<std::mutex> lock(mMutex);
274 uncacheLocked(cacheId);
275 }
276
277 void uncacheLocked(uint64_t cacheId) REQUIRES(mMutex) {
278 mBuffers.erase(cacheId);
279 SurfaceComposerClient::doUncacheBufferTransaction(cacheId);
Marissa Wall73411622019-01-25 10:45:41 -0800280 }
281
282private:
Marissa Wall78b72202019-03-15 14:58:34 -0700283 void evictLeastRecentlyUsedBuffer() REQUIRES(mMutex) {
Marissa Wall73411622019-01-25 10:45:41 -0800284 auto itr = mBuffers.begin();
Marissa Wall78b72202019-03-15 14:58:34 -0700285 uint64_t minCounter = itr->second;
Marissa Wall73411622019-01-25 10:45:41 -0800286 auto minBuffer = itr;
287 itr++;
288
289 while (itr != mBuffers.end()) {
Marissa Wall78b72202019-03-15 14:58:34 -0700290 uint64_t counter = itr->second;
Marissa Wall73411622019-01-25 10:45:41 -0800291 if (counter < minCounter) {
292 minCounter = counter;
293 minBuffer = itr;
294 }
295 itr++;
296 }
Marissa Wall78b72202019-03-15 14:58:34 -0700297 uncacheLocked(minBuffer->first);
Marissa Wall73411622019-01-25 10:45:41 -0800298 }
299
300 uint64_t getCounter() REQUIRES(mMutex) {
301 static uint64_t counter = 0;
302 return counter++;
303 }
304
Marissa Wall73411622019-01-25 10:45:41 -0800305 std::mutex mMutex;
Marissa Wall78b72202019-03-15 14:58:34 -0700306 std::map<uint64_t /*Cache id*/, uint64_t /*counter*/> mBuffers GUARDED_BY(mMutex);
Marissa Wall73411622019-01-25 10:45:41 -0800307
308 // Used by ISurfaceComposer to identify which process is sending the cached buffer.
309 sp<IBinder> token;
310};
311
312ANDROID_SINGLETON_STATIC_INSTANCE(BufferCache);
313
Marissa Wall78b72202019-03-15 14:58:34 -0700314void bufferCacheCallback(void* /*context*/, uint64_t graphicBufferId) {
315 // GraphicBuffer id's are used as the cache ids.
316 BufferCache::getInstance().uncache(graphicBufferId);
317}
318
Marissa Wall73411622019-01-25 10:45:41 -0800319// ---------------------------------------------------------------------------
320
Marissa Wall17b4e452018-12-26 16:32:34 -0800321SurfaceComposerClient::Transaction::Transaction(const Transaction& other)
322 : mForceSynchronous(other.mForceSynchronous),
323 mTransactionNestCount(other.mTransactionNestCount),
324 mAnimation(other.mAnimation),
325 mEarlyWakeup(other.mEarlyWakeup),
Vishnu Nair621102e2019-06-12 14:16:57 -0700326 mContainsBuffer(other.mContainsBuffer),
Marissa Wall17b4e452018-12-26 16:32:34 -0800327 mDesiredPresentTime(other.mDesiredPresentTime) {
Robert Carr4cdc58f2017-08-23 14:22:20 -0700328 mDisplayStates = other.mDisplayStates;
329 mComposerStates = other.mComposerStates;
chaviw273171b2018-12-26 11:46:30 -0800330 mInputWindowCommands = other.mInputWindowCommands;
Vishnu Nair621102e2019-06-12 14:16:57 -0700331 mListenerCallbacks = other.mListenerCallbacks;
332}
333
334std::unique_ptr<SurfaceComposerClient::Transaction>
335SurfaceComposerClient::Transaction::createFromParcel(const Parcel* parcel) {
336 auto transaction = std::make_unique<Transaction>();
337 if (transaction->readFromParcel(parcel) == NO_ERROR) {
338 return transaction;
339 }
340 return nullptr;
341}
342
343status_t SurfaceComposerClient::Transaction::readFromParcel(const Parcel* parcel) {
344 const uint32_t forceSynchronous = parcel->readUint32();
345 const uint32_t transactionNestCount = parcel->readUint32();
346 const bool animation = parcel->readBool();
347 const bool earlyWakeup = parcel->readBool();
348 const bool containsBuffer = parcel->readBool();
349 const int64_t desiredPresentTime = parcel->readInt64();
350
351 size_t count = static_cast<size_t>(parcel->readUint32());
352 if (count > parcel->dataSize()) {
353 return BAD_VALUE;
354 }
355 SortedVector<DisplayState> displayStates;
356 displayStates.setCapacity(count);
357 for (size_t i = 0; i < count; i++) {
358 DisplayState displayState;
359 if (displayState.read(*parcel) == BAD_VALUE) {
360 return BAD_VALUE;
361 }
362 displayStates.add(displayState);
363 }
364
365 count = static_cast<size_t>(parcel->readUint32());
366 if (count > parcel->dataSize()) {
367 return BAD_VALUE;
368 }
Vishnu Nairf03652d2019-07-16 17:56:56 -0700369 std::unordered_map<sp<IBinder>, ComposerState, IBinderHash> composerStates;
Vishnu Nair621102e2019-06-12 14:16:57 -0700370 composerStates.reserve(count);
371 for (size_t i = 0; i < count; i++) {
Vishnu Nairf03652d2019-07-16 17:56:56 -0700372 sp<IBinder> surfaceControlHandle = parcel->readStrongBinder();
Vishnu Nair621102e2019-06-12 14:16:57 -0700373
374 ComposerState composerState;
375 if (composerState.read(*parcel) == BAD_VALUE) {
376 return BAD_VALUE;
377 }
Vishnu Nairf03652d2019-07-16 17:56:56 -0700378 composerStates[surfaceControlHandle] = composerState;
Vishnu Nair621102e2019-06-12 14:16:57 -0700379 }
380
381 InputWindowCommands inputWindowCommands;
382 inputWindowCommands.read(*parcel);
383
384 // Parsing was successful. Update the object.
385 mForceSynchronous = forceSynchronous;
386 mTransactionNestCount = transactionNestCount;
387 mAnimation = animation;
388 mEarlyWakeup = earlyWakeup;
389 mContainsBuffer = containsBuffer;
390 mDesiredPresentTime = desiredPresentTime;
391 mDisplayStates = displayStates;
392 mComposerStates = composerStates;
393 mInputWindowCommands = inputWindowCommands;
394 // listener callbacks contain function pointer addresses and may not be safe to parcel.
395 mListenerCallbacks.clear();
396 return NO_ERROR;
397}
398
399status_t SurfaceComposerClient::Transaction::writeToParcel(Parcel* parcel) const {
400 parcel->writeUint32(mForceSynchronous);
401 parcel->writeUint32(mTransactionNestCount);
402 parcel->writeBool(mAnimation);
403 parcel->writeBool(mEarlyWakeup);
404 parcel->writeBool(mContainsBuffer);
405 parcel->writeInt64(mDesiredPresentTime);
406 parcel->writeUint32(static_cast<uint32_t>(mDisplayStates.size()));
407 for (auto const& displayState : mDisplayStates) {
408 displayState.write(*parcel);
409 }
410
411 parcel->writeUint32(static_cast<uint32_t>(mComposerStates.size()));
Vishnu Nairf03652d2019-07-16 17:56:56 -0700412 for (auto const& [surfaceHandle, composerState] : mComposerStates) {
413 parcel->writeStrongBinder(surfaceHandle);
Vishnu Nair621102e2019-06-12 14:16:57 -0700414 composerState.write(*parcel);
415 }
416
417 mInputWindowCommands.write(*parcel);
418 return NO_ERROR;
Mathias Agopian698c0872011-06-28 19:09:31 -0700419}
420
Robert Carr2c5f6d22017-09-26 12:30:35 -0700421SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::merge(Transaction&& other) {
Vishnu Nairf03652d2019-07-16 17:56:56 -0700422 for (auto const& [surfaceHandle, composerState] : other.mComposerStates) {
423 if (mComposerStates.count(surfaceHandle) == 0) {
424 mComposerStates[surfaceHandle] = composerState;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700425 } else {
Vishnu Nairf03652d2019-07-16 17:56:56 -0700426 mComposerStates[surfaceHandle].state.merge(composerState.state);
Robert Carr2c5f6d22017-09-26 12:30:35 -0700427 }
428 }
Robert Carr2c5f6d22017-09-26 12:30:35 -0700429
430 for (auto const& state : other.mDisplayStates) {
431 ssize_t index = mDisplayStates.indexOf(state);
432 if (index < 0) {
433 mDisplayStates.add(state);
434 } else {
435 mDisplayStates.editItemAt(static_cast<size_t>(index)).merge(state);
436 }
437 }
Robert Carr2c5f6d22017-09-26 12:30:35 -0700438
Marissa Wallc837b5e2018-10-12 10:04:44 -0700439 for (const auto& [listener, callbackInfo] : other.mListenerCallbacks) {
440 auto& [callbackIds, surfaceControls] = callbackInfo;
441 mListenerCallbacks[listener].callbackIds.insert(std::make_move_iterator(
442 callbackIds.begin()),
443 std::make_move_iterator(callbackIds.end()));
444 mListenerCallbacks[listener]
445 .surfaceControls.insert(std::make_move_iterator(surfaceControls.begin()),
446 std::make_move_iterator(surfaceControls.end()));
447 }
Marissa Wallc837b5e2018-10-12 10:04:44 -0700448
chaviw273171b2018-12-26 11:46:30 -0800449 mInputWindowCommands.merge(other.mInputWindowCommands);
450
Marissa Wall78b72202019-03-15 14:58:34 -0700451 mContainsBuffer = other.mContainsBuffer;
Jorim Jaggie3b57002019-07-22 17:18:52 +0200452 mEarlyWakeup = mEarlyWakeup || other.mEarlyWakeup;
Vishnu Nairfef244e2019-06-17 18:07:51 -0700453 other.clear();
Robert Carr2c5f6d22017-09-26 12:30:35 -0700454 return *this;
455}
456
Vishnu Nairfef244e2019-06-17 18:07:51 -0700457void SurfaceComposerClient::Transaction::clear() {
458 mComposerStates.clear();
459 mDisplayStates.clear();
460 mListenerCallbacks.clear();
461 mInputWindowCommands.clear();
462 mContainsBuffer = false;
463 mForceSynchronous = 0;
464 mTransactionNestCount = 0;
465 mAnimation = false;
466 mEarlyWakeup = false;
467 mDesiredPresentTime = -1;
468}
469
Vishnu Nairf03652d2019-07-16 17:56:56 -0700470void SurfaceComposerClient::doDropReferenceTransaction(const sp<IBinder>& handle) {
Robert Carr6fb1a7e2018-12-11 12:07:25 -0800471 sp<ISurfaceComposer> sf(ComposerService::getComposerService());
472 Vector<ComposerState> composerStates;
473 Vector<DisplayState> displayStates;
474
475 ComposerState s;
Robert Carr6fb1a7e2018-12-11 12:07:25 -0800476 s.state.surface = handle;
477 s.state.what |= layer_state_t::eReparent;
478 s.state.parentHandleForChild = nullptr;
479
480 composerStates.add(s);
Valerie Haufa889122019-04-15 13:56:05 -0700481 sp<IBinder> applyToken = IInterface::asBinder(TransactionCompletedListener::getIInstance());
482 sf->setTransactionState(composerStates, displayStates, 0, applyToken, {}, -1, {}, {});
Marissa Wall78b72202019-03-15 14:58:34 -0700483}
484
485void SurfaceComposerClient::doUncacheBufferTransaction(uint64_t cacheId) {
486 sp<ISurfaceComposer> sf(ComposerService::getComposerService());
487
Marissa Wall947d34e2019-03-29 14:03:53 -0700488 client_cache_t uncacheBuffer;
Marissa Wall78b72202019-03-15 14:58:34 -0700489 uncacheBuffer.token = BufferCache::getInstance().getToken();
Marissa Wall947d34e2019-03-29 14:03:53 -0700490 uncacheBuffer.id = cacheId;
Marissa Wall78b72202019-03-15 14:58:34 -0700491
Valerie Haufa889122019-04-15 13:56:05 -0700492 sp<IBinder> applyToken = IInterface::asBinder(TransactionCompletedListener::getIInstance());
493 sf->setTransactionState({}, {}, 0, applyToken, {}, -1, uncacheBuffer, {});
Marissa Wall78b72202019-03-15 14:58:34 -0700494}
495
496void SurfaceComposerClient::Transaction::cacheBuffers() {
497 if (!mContainsBuffer) {
498 return;
499 }
500
501 size_t count = 0;
Vishnu Nairf03652d2019-07-16 17:56:56 -0700502 for (auto& [handle, cs] : mComposerStates) {
503 layer_state_t* s = getLayerState(handle);
Marissa Wall78b72202019-03-15 14:58:34 -0700504 if (!(s->what & layer_state_t::eBufferChanged)) {
505 continue;
506 }
507
Marissa Wall00597242019-03-27 10:35:19 -0700508 // Don't try to cache a null buffer. Sending null buffers is cheap so we shouldn't waste
509 // time trying to cache them.
510 if (!s->buffer) {
511 continue;
512 }
513
Marissa Wall78b72202019-03-15 14:58:34 -0700514 uint64_t cacheId = 0;
515 status_t ret = BufferCache::getInstance().getCacheId(s->buffer, &cacheId);
516 if (ret == NO_ERROR) {
Marissa Walla141abe2019-03-27 16:28:07 -0700517 s->what &= ~static_cast<uint64_t>(layer_state_t::eBufferChanged);
Marissa Wall78b72202019-03-15 14:58:34 -0700518 s->buffer = nullptr;
519 } else {
520 cacheId = BufferCache::getInstance().cache(s->buffer);
521 }
522 s->what |= layer_state_t::eCachedBufferChanged;
523 s->cachedBuffer.token = BufferCache::getInstance().getToken();
Marissa Wall947d34e2019-03-29 14:03:53 -0700524 s->cachedBuffer.id = cacheId;
Marissa Wall78b72202019-03-15 14:58:34 -0700525
526 // If we have more buffers than the size of the cache, we should stop caching so we don't
527 // evict other buffers in this transaction
528 count++;
529 if (count >= BUFFER_CACHE_MAX_SIZE) {
530 break;
531 }
532 }
Robert Carr6fb1a7e2018-12-11 12:07:25 -0800533}
534
Robert Carr4cdc58f2017-08-23 14:22:20 -0700535status_t SurfaceComposerClient::Transaction::apply(bool synchronous) {
536 if (mStatus != NO_ERROR) {
537 return mStatus;
538 }
539
540 sp<ISurfaceComposer> sf(ComposerService::getComposerService());
541
Marissa Wall3dad52d2019-03-22 14:03:19 -0700542 std::vector<ListenerCallbacks> listenerCallbacks;
543
Marissa Wallc837b5e2018-10-12 10:04:44 -0700544 // For every listener with registered callbacks
545 for (const auto& [listener, callbackInfo] : mListenerCallbacks) {
546 auto& [callbackIds, surfaceControls] = callbackInfo;
547 if (callbackIds.empty()) {
548 continue;
549 }
550
Valerie Hau5de3ad22019-08-20 07:47:43 -0700551 listenerCallbacks.emplace_back(IInterface::asBinder(listener), std::move(callbackIds));
Marissa Walle2ffb422018-10-12 11:33:52 -0700552
Marissa Wallc837b5e2018-10-12 10:04:44 -0700553 // If the listener has any SurfaceControls set on this Transaction update the surface state
554 for (const auto& surfaceControl : surfaceControls) {
555 layer_state_t* s = getLayerState(surfaceControl);
556 if (!s) {
557 ALOGE("failed to get layer state");
558 continue;
559 }
Marissa Wall3dad52d2019-03-22 14:03:19 -0700560 s->what |= layer_state_t::eHasListenerCallbacksChanged;
561 s->hasListenerCallbacks = true;
Marissa Wallc837b5e2018-10-12 10:04:44 -0700562 }
563 }
564 mListenerCallbacks.clear();
565
Marissa Wall78b72202019-03-15 14:58:34 -0700566 cacheBuffers();
567
Robert Carr4cdc58f2017-08-23 14:22:20 -0700568 Vector<ComposerState> composerStates;
569 Vector<DisplayState> displayStates;
570 uint32_t flags = 0;
571
572 mForceSynchronous |= synchronous;
573
chaviw8e3fe5d2018-02-22 10:55:42 -0800574 for (auto const& kv : mComposerStates){
575 composerStates.add(kv.second);
576 }
577
Robert Carr4cdc58f2017-08-23 14:22:20 -0700578 mComposerStates.clear();
579
580 displayStates = mDisplayStates;
581 mDisplayStates.clear();
582
583 if (mForceSynchronous) {
584 flags |= ISurfaceComposer::eSynchronous;
585 }
586 if (mAnimation) {
587 flags |= ISurfaceComposer::eAnimation;
588 }
Dan Stoza84d619e2018-03-28 17:07:36 -0700589 if (mEarlyWakeup) {
590 flags |= ISurfaceComposer::eEarlyWakeup;
591 }
Robert Carr4cdc58f2017-08-23 14:22:20 -0700592
593 mForceSynchronous = false;
594 mAnimation = false;
Dan Stoza84d619e2018-03-28 17:07:36 -0700595 mEarlyWakeup = false;
Robert Carr4cdc58f2017-08-23 14:22:20 -0700596
Marissa Wall713b63f2018-10-17 15:42:43 -0700597 sp<IBinder> applyToken = IInterface::asBinder(TransactionCompletedListener::getIInstance());
Marissa Wall17b4e452018-12-26 16:32:34 -0800598 sf->setTransactionState(composerStates, displayStates, flags, applyToken, mInputWindowCommands,
Marissa Wall78b72202019-03-15 14:58:34 -0700599 mDesiredPresentTime,
Marissa Wall3dad52d2019-03-22 14:03:19 -0700600 {} /*uncacheBuffer - only set in doUncacheBufferTransaction*/,
601 listenerCallbacks);
chaviw273171b2018-12-26 11:46:30 -0800602 mInputWindowCommands.clear();
Robert Carr4cdc58f2017-08-23 14:22:20 -0700603 mStatus = NO_ERROR;
604 return NO_ERROR;
Mathias Agopiane57f2922012-08-09 16:29:12 -0700605}
606
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800607// ---------------------------------------------------------------------------
608
Robert Carr4cdc58f2017-08-23 14:22:20 -0700609sp<IBinder> SurfaceComposerClient::createDisplay(const String8& displayName, bool secure) {
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700610 return ComposerService::getComposerService()->createDisplay(displayName,
611 secure);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700612}
613
Robert Carr4cdc58f2017-08-23 14:22:20 -0700614void SurfaceComposerClient::destroyDisplay(const sp<IBinder>& display) {
Jesse Hall6c913be2013-08-08 12:15:49 -0700615 return ComposerService::getComposerService()->destroyDisplay(display);
616}
617
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -0800618std::vector<PhysicalDisplayId> SurfaceComposerClient::getPhysicalDisplayIds() {
619 return ComposerService::getComposerService()->getPhysicalDisplayIds();
620}
621
622std::optional<PhysicalDisplayId> SurfaceComposerClient::getInternalDisplayId() {
623 return ComposerService::getComposerService()->getInternalDisplayId();
624}
625
626sp<IBinder> SurfaceComposerClient::getPhysicalDisplayToken(PhysicalDisplayId displayId) {
627 return ComposerService::getComposerService()->getPhysicalDisplayToken(displayId);
628}
629
630sp<IBinder> SurfaceComposerClient::getInternalDisplayToken() {
631 return ComposerService::getComposerService()->getInternalDisplayToken();
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700632}
633
Robert Carr4cdc58f2017-08-23 14:22:20 -0700634void SurfaceComposerClient::Transaction::setAnimationTransaction() {
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700635 mAnimation = true;
636}
637
Dan Stoza84d619e2018-03-28 17:07:36 -0700638void SurfaceComposerClient::Transaction::setEarlyWakeup() {
639 mEarlyWakeup = true;
640}
641
Vishnu Nairf03652d2019-07-16 17:56:56 -0700642layer_state_t* SurfaceComposerClient::Transaction::getLayerState(const sp<IBinder>& handle) {
643 if (mComposerStates.count(handle) == 0) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700644 // we don't have it, add an initialized layer_state to our list
chaviw8e3fe5d2018-02-22 10:55:42 -0800645 ComposerState s;
Vishnu Nairf03652d2019-07-16 17:56:56 -0700646 s.state.surface = handle;
647 mComposerStates[handle] = s;
Mathias Agopian698c0872011-06-28 19:09:31 -0700648 }
649
Vishnu Nairf03652d2019-07-16 17:56:56 -0700650 return &(mComposerStates[handle].state);
Mathias Agopian698c0872011-06-28 19:09:31 -0700651}
652
Marissa Wallc837b5e2018-10-12 10:04:44 -0700653void SurfaceComposerClient::Transaction::registerSurfaceControlForCallback(
654 const sp<SurfaceControl>& sc) {
Marissa Wall80d94ad2019-01-18 16:04:36 -0800655 auto& callbackInfo = mListenerCallbacks[TransactionCompletedListener::getIInstance()];
656 callbackInfo.surfaceControls.insert(sc);
657
658 TransactionCompletedListener::getInstance()
659 ->addSurfaceControlToCallbacks(sc, callbackInfo.callbackIds);
Marissa Wallc837b5e2018-10-12 10:04:44 -0700660}
661
Robert Carr4cdc58f2017-08-23 14:22:20 -0700662SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setPosition(
663 const sp<SurfaceControl>& sc, float x, float y) {
chaviw763ef572018-02-22 16:04:57 -0800664 layer_state_t* s = getLayerState(sc);
Robert Carr4cdc58f2017-08-23 14:22:20 -0700665 if (!s) {
666 mStatus = BAD_INDEX;
667 return *this;
668 }
Mathias Agopian3165cc22012-08-08 19:42:09 -0700669 s->what |= layer_state_t::ePositionChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700670 s->x = x;
671 s->y = y;
Marissa Wallc837b5e2018-10-12 10:04:44 -0700672
673 registerSurfaceControlForCallback(sc);
Robert Carr4cdc58f2017-08-23 14:22:20 -0700674 return *this;
Mathias Agopian698c0872011-06-28 19:09:31 -0700675}
676
Robert Carr4cdc58f2017-08-23 14:22:20 -0700677SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::show(
678 const sp<SurfaceControl>& sc) {
679 return setFlags(sc, 0, layer_state_t::eLayerHidden);
680}
681
682SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::hide(
683 const sp<SurfaceControl>& sc) {
684 return setFlags(sc, layer_state_t::eLayerHidden, layer_state_t::eLayerHidden);
685}
686
687SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setSize(
688 const sp<SurfaceControl>& sc, uint32_t w, uint32_t h) {
chaviw763ef572018-02-22 16:04:57 -0800689 layer_state_t* s = getLayerState(sc);
Robert Carr4cdc58f2017-08-23 14:22:20 -0700690 if (!s) {
691 mStatus = BAD_INDEX;
692 return *this;
693 }
Mathias Agopian3165cc22012-08-08 19:42:09 -0700694 s->what |= layer_state_t::eSizeChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700695 s->w = w;
696 s->h = h;
Jamie Gennis28378392011-10-12 17:39:00 -0700697
Marissa Wallc837b5e2018-10-12 10:04:44 -0700698 registerSurfaceControlForCallback(sc);
Robert Carr4cdc58f2017-08-23 14:22:20 -0700699 return *this;
Mathias Agopian698c0872011-06-28 19:09:31 -0700700}
701
Robert Carr4cdc58f2017-08-23 14:22:20 -0700702SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setLayer(
703 const sp<SurfaceControl>& sc, int32_t z) {
chaviw763ef572018-02-22 16:04:57 -0800704 layer_state_t* s = getLayerState(sc);
Robert Carr4cdc58f2017-08-23 14:22:20 -0700705 if (!s) {
706 mStatus = BAD_INDEX;
707 return *this;
708 }
Mathias Agopian3165cc22012-08-08 19:42:09 -0700709 s->what |= layer_state_t::eLayerChanged;
chaviw32377582019-05-13 11:15:19 -0700710 s->what &= ~layer_state_t::eRelativeLayerChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700711 s->z = z;
Marissa Wallc837b5e2018-10-12 10:04:44 -0700712
713 registerSurfaceControlForCallback(sc);
Robert Carr4cdc58f2017-08-23 14:22:20 -0700714 return *this;
Mathias Agopian698c0872011-06-28 19:09:31 -0700715}
716
Robert Carr4cdc58f2017-08-23 14:22:20 -0700717SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setRelativeLayer(const sp<SurfaceControl>& sc, const sp<IBinder>& relativeTo,
Robert Carrdb66e622017-04-10 16:55:57 -0700718 int32_t z) {
chaviw763ef572018-02-22 16:04:57 -0800719 layer_state_t* s = getLayerState(sc);
Robert Carrdb66e622017-04-10 16:55:57 -0700720 if (!s) {
Robert Carr4cdc58f2017-08-23 14:22:20 -0700721 mStatus = BAD_INDEX;
Robert Carr30c8d902019-04-04 13:12:49 -0700722 return *this;
Robert Carrdb66e622017-04-10 16:55:57 -0700723 }
724 s->what |= layer_state_t::eRelativeLayerChanged;
chaviw32377582019-05-13 11:15:19 -0700725 s->what &= ~layer_state_t::eLayerChanged;
Robert Carrdb66e622017-04-10 16:55:57 -0700726 s->relativeLayerHandle = relativeTo;
727 s->z = z;
Marissa Wallc837b5e2018-10-12 10:04:44 -0700728
729 registerSurfaceControlForCallback(sc);
Robert Carr4cdc58f2017-08-23 14:22:20 -0700730 return *this;
Robert Carrdb66e622017-04-10 16:55:57 -0700731}
732
Robert Carr4cdc58f2017-08-23 14:22:20 -0700733SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setFlags(
734 const sp<SurfaceControl>& sc, uint32_t flags,
Mathias Agopian698c0872011-06-28 19:09:31 -0700735 uint32_t mask) {
chaviw763ef572018-02-22 16:04:57 -0800736 layer_state_t* s = getLayerState(sc);
Robert Carr4cdc58f2017-08-23 14:22:20 -0700737 if (!s) {
738 mStatus = BAD_INDEX;
739 return *this;
740 }
Pablo Ceballos53390e12015-08-04 11:25:59 -0700741 if ((mask & layer_state_t::eLayerOpaque) ||
742 (mask & layer_state_t::eLayerHidden) ||
743 (mask & layer_state_t::eLayerSecure)) {
Dan Stoza23116082015-06-18 14:58:39 -0700744 s->what |= layer_state_t::eFlagsChanged;
Andy McFadden4125a4f2014-01-29 17:17:11 -0800745 }
Mathias Agopian698c0872011-06-28 19:09:31 -0700746 s->flags &= ~mask;
747 s->flags |= (flags & mask);
748 s->mask |= mask;
Marissa Wallc837b5e2018-10-12 10:04:44 -0700749
750 registerSurfaceControlForCallback(sc);
Robert Carr4cdc58f2017-08-23 14:22:20 -0700751 return *this;
Mathias Agopian698c0872011-06-28 19:09:31 -0700752}
753
Robert Carr4cdc58f2017-08-23 14:22:20 -0700754SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setTransparentRegionHint(
755 const sp<SurfaceControl>& sc,
Mathias Agopian698c0872011-06-28 19:09:31 -0700756 const Region& transparentRegion) {
chaviw763ef572018-02-22 16:04:57 -0800757 layer_state_t* s = getLayerState(sc);
Robert Carr4cdc58f2017-08-23 14:22:20 -0700758 if (!s) {
759 mStatus = BAD_INDEX;
760 return *this;
761 }
Mathias Agopian3165cc22012-08-08 19:42:09 -0700762 s->what |= layer_state_t::eTransparentRegionChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700763 s->transparentRegion = transparentRegion;
Marissa Wallc837b5e2018-10-12 10:04:44 -0700764
765 registerSurfaceControlForCallback(sc);
Robert Carr4cdc58f2017-08-23 14:22:20 -0700766 return *this;
Mathias Agopian698c0872011-06-28 19:09:31 -0700767}
768
Robert Carr4cdc58f2017-08-23 14:22:20 -0700769SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setAlpha(
770 const sp<SurfaceControl>& sc, float alpha) {
chaviw763ef572018-02-22 16:04:57 -0800771 layer_state_t* s = getLayerState(sc);
Robert Carr4cdc58f2017-08-23 14:22:20 -0700772 if (!s) {
773 mStatus = BAD_INDEX;
774 return *this;
775 }
Mathias Agopian3165cc22012-08-08 19:42:09 -0700776 s->what |= layer_state_t::eAlphaChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700777 s->alpha = alpha;
Marissa Wallc837b5e2018-10-12 10:04:44 -0700778
779 registerSurfaceControlForCallback(sc);
Robert Carr4cdc58f2017-08-23 14:22:20 -0700780 return *this;
Mathias Agopian698c0872011-06-28 19:09:31 -0700781}
782
Robert Carr4cdc58f2017-08-23 14:22:20 -0700783SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setLayerStack(
784 const sp<SurfaceControl>& sc, uint32_t layerStack) {
chaviw763ef572018-02-22 16:04:57 -0800785 layer_state_t* s = getLayerState(sc);
Robert Carr4cdc58f2017-08-23 14:22:20 -0700786 if (!s) {
787 mStatus = BAD_INDEX;
788 return *this;
789 }
Mathias Agopian3165cc22012-08-08 19:42:09 -0700790 s->what |= layer_state_t::eLayerStackChanged;
Mathias Agopian87855782012-07-24 21:41:09 -0700791 s->layerStack = layerStack;
Marissa Wallc837b5e2018-10-12 10:04:44 -0700792
793 registerSurfaceControlForCallback(sc);
Robert Carr4cdc58f2017-08-23 14:22:20 -0700794 return *this;
Mathias Agopian87855782012-07-24 21:41:09 -0700795}
796
Evan Rosky1f6d6d52018-12-06 10:47:26 -0800797SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setMetadata(
Garfield Tan01a56132019-08-05 16:44:21 -0700798 const sp<SurfaceControl>& sc, uint32_t key, const Parcel& p) {
Evan Rosky1f6d6d52018-12-06 10:47:26 -0800799 layer_state_t* s = getLayerState(sc);
800 if (!s) {
801 mStatus = BAD_INDEX;
802 return *this;
803 }
804 s->what |= layer_state_t::eMetadataChanged;
Garfield Tan01a56132019-08-05 16:44:21 -0700805
806 s->metadata.mMap[key] = {p.data(), p.data() + p.dataSize()};
Evan Rosky1f6d6d52018-12-06 10:47:26 -0800807
808 registerSurfaceControlForCallback(sc);
809 return *this;
810}
811
Robert Carr4cdc58f2017-08-23 14:22:20 -0700812SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setMatrix(
813 const sp<SurfaceControl>& sc, float dsdx, float dtdx,
Robert Carrcb6e1e32017-02-21 19:48:26 -0800814 float dtdy, float dsdy) {
chaviw763ef572018-02-22 16:04:57 -0800815 layer_state_t* s = getLayerState(sc);
Robert Carr4cdc58f2017-08-23 14:22:20 -0700816 if (!s) {
817 mStatus = BAD_INDEX;
818 return *this;
819 }
Mathias Agopian3165cc22012-08-08 19:42:09 -0700820 s->what |= layer_state_t::eMatrixChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700821 layer_state_t::matrix22_t matrix;
822 matrix.dsdx = dsdx;
823 matrix.dtdx = dtdx;
824 matrix.dsdy = dsdy;
825 matrix.dtdy = dtdy;
826 s->matrix = matrix;
Marissa Wallc837b5e2018-10-12 10:04:44 -0700827
828 registerSurfaceControlForCallback(sc);
Robert Carr4cdc58f2017-08-23 14:22:20 -0700829 return *this;
Mathias Agopian698c0872011-06-28 19:09:31 -0700830}
831
Marissa Wallf58c14b2018-07-24 10:50:43 -0700832SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setCrop_legacy(
Robert Carr4cdc58f2017-08-23 14:22:20 -0700833 const sp<SurfaceControl>& sc, const Rect& crop) {
chaviw763ef572018-02-22 16:04:57 -0800834 layer_state_t* s = getLayerState(sc);
Robert Carr4cdc58f2017-08-23 14:22:20 -0700835 if (!s) {
836 mStatus = BAD_INDEX;
837 return *this;
838 }
Marissa Wallf58c14b2018-07-24 10:50:43 -0700839 s->what |= layer_state_t::eCropChanged_legacy;
840 s->crop_legacy = crop;
Marissa Wallc837b5e2018-10-12 10:04:44 -0700841
842 registerSurfaceControlForCallback(sc);
Robert Carr4cdc58f2017-08-23 14:22:20 -0700843 return *this;
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700844}
845
Lucas Dupin1b6531c2018-07-05 17:18:21 -0700846SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setCornerRadius(
847 const sp<SurfaceControl>& sc, float cornerRadius) {
848 layer_state_t* s = getLayerState(sc);
849 if (!s) {
850 mStatus = BAD_INDEX;
851 return *this;
852 }
853 s->what |= layer_state_t::eCornerRadiusChanged;
854 s->cornerRadius = cornerRadius;
855 return *this;
856}
857
Marissa Wallf58c14b2018-07-24 10:50:43 -0700858SurfaceComposerClient::Transaction&
859SurfaceComposerClient::Transaction::deferTransactionUntil_legacy(const sp<SurfaceControl>& sc,
860 const sp<IBinder>& handle,
861 uint64_t frameNumber) {
chaviw763ef572018-02-22 16:04:57 -0800862 layer_state_t* s = getLayerState(sc);
Dan Stoza7dde5992015-05-22 09:51:44 -0700863 if (!s) {
Robert Carr4cdc58f2017-08-23 14:22:20 -0700864 mStatus = BAD_INDEX;
865 return *this;
Dan Stoza7dde5992015-05-22 09:51:44 -0700866 }
Marissa Wallf58c14b2018-07-24 10:50:43 -0700867 s->what |= layer_state_t::eDeferTransaction_legacy;
868 s->barrierHandle_legacy = handle;
869 s->frameNumber_legacy = frameNumber;
Marissa Wallc837b5e2018-10-12 10:04:44 -0700870
871 registerSurfaceControlForCallback(sc);
Robert Carr4cdc58f2017-08-23 14:22:20 -0700872 return *this;
Robert Carr0d480722017-01-10 16:42:54 -0800873}
874
Marissa Wallf58c14b2018-07-24 10:50:43 -0700875SurfaceComposerClient::Transaction&
876SurfaceComposerClient::Transaction::deferTransactionUntil_legacy(const sp<SurfaceControl>& sc,
877 const sp<Surface>& barrierSurface,
878 uint64_t frameNumber) {
chaviw763ef572018-02-22 16:04:57 -0800879 layer_state_t* s = getLayerState(sc);
Robert Carr0d480722017-01-10 16:42:54 -0800880 if (!s) {
Robert Carr4cdc58f2017-08-23 14:22:20 -0700881 mStatus = BAD_INDEX;
882 return *this;
Robert Carr0d480722017-01-10 16:42:54 -0800883 }
Marissa Wallf58c14b2018-07-24 10:50:43 -0700884 s->what |= layer_state_t::eDeferTransaction_legacy;
885 s->barrierGbp_legacy = barrierSurface->getIGraphicBufferProducer();
886 s->frameNumber_legacy = frameNumber;
Marissa Wallc837b5e2018-10-12 10:04:44 -0700887
888 registerSurfaceControlForCallback(sc);
Robert Carr4cdc58f2017-08-23 14:22:20 -0700889 return *this;
Dan Stoza7dde5992015-05-22 09:51:44 -0700890}
891
Robert Carr4cdc58f2017-08-23 14:22:20 -0700892SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::reparentChildren(
893 const sp<SurfaceControl>& sc,
Robert Carr1db73f62016-12-21 12:58:51 -0800894 const sp<IBinder>& newParentHandle) {
chaviw763ef572018-02-22 16:04:57 -0800895 layer_state_t* s = getLayerState(sc);
Robert Carr1db73f62016-12-21 12:58:51 -0800896 if (!s) {
Robert Carr4cdc58f2017-08-23 14:22:20 -0700897 mStatus = BAD_INDEX;
898 return *this;
Robert Carr1db73f62016-12-21 12:58:51 -0800899 }
900 s->what |= layer_state_t::eReparentChildren;
901 s->reparentHandle = newParentHandle;
Marissa Wallc837b5e2018-10-12 10:04:44 -0700902
903 registerSurfaceControlForCallback(sc);
Robert Carr4cdc58f2017-08-23 14:22:20 -0700904 return *this;
Robert Carr1db73f62016-12-21 12:58:51 -0800905}
906
Robert Carr4cdc58f2017-08-23 14:22:20 -0700907SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::reparent(
908 const sp<SurfaceControl>& sc,
chaviwf1961f72017-09-18 16:41:07 -0700909 const sp<IBinder>& newParentHandle) {
chaviw763ef572018-02-22 16:04:57 -0800910 layer_state_t* s = getLayerState(sc);
chaviw06178942017-07-27 10:25:59 -0700911 if (!s) {
Robert Carr4cdc58f2017-08-23 14:22:20 -0700912 mStatus = BAD_INDEX;
913 return *this;
chaviw06178942017-07-27 10:25:59 -0700914 }
chaviwf1961f72017-09-18 16:41:07 -0700915 s->what |= layer_state_t::eReparent;
chaviw06178942017-07-27 10:25:59 -0700916 s->parentHandleForChild = newParentHandle;
Marissa Wallc837b5e2018-10-12 10:04:44 -0700917
918 registerSurfaceControlForCallback(sc);
Robert Carr4cdc58f2017-08-23 14:22:20 -0700919 return *this;
chaviw06178942017-07-27 10:25:59 -0700920}
921
Robert Carr4cdc58f2017-08-23 14:22:20 -0700922SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setColor(
923 const sp<SurfaceControl>& sc,
924 const half3& color) {
chaviw763ef572018-02-22 16:04:57 -0800925 layer_state_t* s = getLayerState(sc);
Robert Carr9524cb32017-02-13 11:32:32 -0800926 if (!s) {
Robert Carr4cdc58f2017-08-23 14:22:20 -0700927 mStatus = BAD_INDEX;
928 return *this;
929 }
930 s->what |= layer_state_t::eColorChanged;
931 s->color = color;
Marissa Wallc837b5e2018-10-12 10:04:44 -0700932
933 registerSurfaceControlForCallback(sc);
Robert Carr4cdc58f2017-08-23 14:22:20 -0700934 return *this;
935}
936
Valerie Haudd0b7572019-01-29 14:59:27 -0800937SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setBackgroundColor(
938 const sp<SurfaceControl>& sc, const half3& color, float alpha, ui::Dataspace dataspace) {
Valerie Haued54efa2019-01-11 20:03:14 -0800939 layer_state_t* s = getLayerState(sc);
940 if (!s) {
941 mStatus = BAD_INDEX;
942 return *this;
943 }
944
Valerie Haudd0b7572019-01-29 14:59:27 -0800945 s->what |= layer_state_t::eBackgroundColorChanged;
946 s->color = color;
947 s->bgColorAlpha = alpha;
948 s->bgColorDataspace = dataspace;
Valerie Haued54efa2019-01-11 20:03:14 -0800949
950 registerSurfaceControlForCallback(sc);
951 return *this;
952}
953
Marissa Wall61c58622018-07-18 10:12:20 -0700954SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setTransform(
955 const sp<SurfaceControl>& sc, uint32_t transform) {
956 layer_state_t* s = getLayerState(sc);
957 if (!s) {
958 mStatus = BAD_INDEX;
959 return *this;
960 }
961 s->what |= layer_state_t::eTransformChanged;
962 s->transform = transform;
Marissa Wallc837b5e2018-10-12 10:04:44 -0700963
964 registerSurfaceControlForCallback(sc);
Marissa Wall61c58622018-07-18 10:12:20 -0700965 return *this;
966}
967
968SurfaceComposerClient::Transaction&
969SurfaceComposerClient::Transaction::setTransformToDisplayInverse(const sp<SurfaceControl>& sc,
970 bool transformToDisplayInverse) {
971 layer_state_t* s = getLayerState(sc);
972 if (!s) {
973 mStatus = BAD_INDEX;
974 return *this;
975 }
976 s->what |= layer_state_t::eTransformToDisplayInverseChanged;
977 s->transformToDisplayInverse = transformToDisplayInverse;
Marissa Wallc837b5e2018-10-12 10:04:44 -0700978
979 registerSurfaceControlForCallback(sc);
Marissa Wall61c58622018-07-18 10:12:20 -0700980 return *this;
981}
982
983SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setCrop(
984 const sp<SurfaceControl>& sc, const Rect& crop) {
985 layer_state_t* s = getLayerState(sc);
986 if (!s) {
987 mStatus = BAD_INDEX;
988 return *this;
989 }
990 s->what |= layer_state_t::eCropChanged;
991 s->crop = crop;
Marissa Wallc837b5e2018-10-12 10:04:44 -0700992
993 registerSurfaceControlForCallback(sc);
Marissa Wall61c58622018-07-18 10:12:20 -0700994 return *this;
995}
996
Marissa Wall861616d2018-10-22 12:52:23 -0700997SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setFrame(
998 const sp<SurfaceControl>& sc, const Rect& frame) {
999 layer_state_t* s = getLayerState(sc);
1000 if (!s) {
1001 mStatus = BAD_INDEX;
1002 return *this;
1003 }
1004 s->what |= layer_state_t::eFrameChanged;
1005 s->frame = frame;
1006
1007 registerSurfaceControlForCallback(sc);
1008 return *this;
1009}
1010
Marissa Wall61c58622018-07-18 10:12:20 -07001011SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setBuffer(
1012 const sp<SurfaceControl>& sc, const sp<GraphicBuffer>& buffer) {
1013 layer_state_t* s = getLayerState(sc);
1014 if (!s) {
1015 mStatus = BAD_INDEX;
1016 return *this;
1017 }
Marissa Wall78b72202019-03-15 14:58:34 -07001018 s->what |= layer_state_t::eBufferChanged;
1019 s->buffer = buffer;
Marissa Wallebc2c052019-01-16 19:16:55 -08001020
1021 registerSurfaceControlForCallback(sc);
Marissa Wall78b72202019-03-15 14:58:34 -07001022
1023 mContainsBuffer = true;
Marissa Wallebc2c052019-01-16 19:16:55 -08001024 return *this;
1025}
1026
Marissa Wall61c58622018-07-18 10:12:20 -07001027SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setAcquireFence(
1028 const sp<SurfaceControl>& sc, const sp<Fence>& fence) {
1029 layer_state_t* s = getLayerState(sc);
1030 if (!s) {
1031 mStatus = BAD_INDEX;
1032 return *this;
1033 }
1034 s->what |= layer_state_t::eAcquireFenceChanged;
1035 s->acquireFence = fence;
Marissa Wallc837b5e2018-10-12 10:04:44 -07001036
1037 registerSurfaceControlForCallback(sc);
Marissa Wall61c58622018-07-18 10:12:20 -07001038 return *this;
1039}
1040
1041SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setDataspace(
1042 const sp<SurfaceControl>& sc, ui::Dataspace dataspace) {
1043 layer_state_t* s = getLayerState(sc);
1044 if (!s) {
1045 mStatus = BAD_INDEX;
1046 return *this;
1047 }
1048 s->what |= layer_state_t::eDataspaceChanged;
1049 s->dataspace = dataspace;
Marissa Wallc837b5e2018-10-12 10:04:44 -07001050
1051 registerSurfaceControlForCallback(sc);
Marissa Wall61c58622018-07-18 10:12:20 -07001052 return *this;
1053}
1054
1055SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setHdrMetadata(
1056 const sp<SurfaceControl>& sc, const HdrMetadata& hdrMetadata) {
1057 layer_state_t* s = getLayerState(sc);
1058 if (!s) {
1059 mStatus = BAD_INDEX;
1060 return *this;
1061 }
1062 s->what |= layer_state_t::eHdrMetadataChanged;
1063 s->hdrMetadata = hdrMetadata;
Marissa Wallc837b5e2018-10-12 10:04:44 -07001064
1065 registerSurfaceControlForCallback(sc);
Marissa Wall61c58622018-07-18 10:12:20 -07001066 return *this;
1067}
1068
1069SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setSurfaceDamageRegion(
1070 const sp<SurfaceControl>& sc, const Region& surfaceDamageRegion) {
1071 layer_state_t* s = getLayerState(sc);
1072 if (!s) {
1073 mStatus = BAD_INDEX;
1074 return *this;
1075 }
1076 s->what |= layer_state_t::eSurfaceDamageRegionChanged;
1077 s->surfaceDamageRegion = surfaceDamageRegion;
Marissa Wallc837b5e2018-10-12 10:04:44 -07001078
1079 registerSurfaceControlForCallback(sc);
Marissa Wall61c58622018-07-18 10:12:20 -07001080 return *this;
1081}
1082
1083SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setApi(
1084 const sp<SurfaceControl>& sc, int32_t api) {
1085 layer_state_t* s = getLayerState(sc);
1086 if (!s) {
1087 mStatus = BAD_INDEX;
1088 return *this;
1089 }
1090 s->what |= layer_state_t::eApiChanged;
1091 s->api = api;
Marissa Wallc837b5e2018-10-12 10:04:44 -07001092
1093 registerSurfaceControlForCallback(sc);
Marissa Wall61c58622018-07-18 10:12:20 -07001094 return *this;
1095}
1096
1097SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setSidebandStream(
1098 const sp<SurfaceControl>& sc, const sp<NativeHandle>& sidebandStream) {
1099 layer_state_t* s = getLayerState(sc);
1100 if (!s) {
1101 mStatus = BAD_INDEX;
1102 return *this;
1103 }
1104 s->what |= layer_state_t::eSidebandStreamChanged;
1105 s->sidebandStream = sidebandStream;
Marissa Wallc837b5e2018-10-12 10:04:44 -07001106
1107 registerSurfaceControlForCallback(sc);
1108 return *this;
1109}
1110
Marissa Wall17b4e452018-12-26 16:32:34 -08001111SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setDesiredPresentTime(
1112 nsecs_t desiredPresentTime) {
1113 mDesiredPresentTime = desiredPresentTime;
1114 return *this;
1115}
1116
Peiyong Linc502cb72019-03-01 15:00:23 -08001117SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setColorSpaceAgnostic(
1118 const sp<SurfaceControl>& sc, const bool agnostic) {
1119 layer_state_t* s = getLayerState(sc);
1120 if (!s) {
1121 mStatus = BAD_INDEX;
1122 return *this;
1123 }
1124 s->what |= layer_state_t::eColorSpaceAgnosticChanged;
1125 s->colorSpaceAgnostic = agnostic;
1126
1127 registerSurfaceControlForCallback(sc);
1128 return *this;
1129}
1130
Marissa Wallc837b5e2018-10-12 10:04:44 -07001131SurfaceComposerClient::Transaction&
1132SurfaceComposerClient::Transaction::addTransactionCompletedCallback(
Marissa Walle2ffb422018-10-12 11:33:52 -07001133 TransactionCompletedCallbackTakesContext callback, void* callbackContext) {
Marissa Wallc837b5e2018-10-12 10:04:44 -07001134 auto listener = TransactionCompletedListener::getInstance();
1135
Marissa Wall80d94ad2019-01-18 16:04:36 -08001136 auto callbackWithContext = std::bind(callback, callbackContext, std::placeholders::_1,
1137 std::placeholders::_2, std::placeholders::_3);
1138 const auto& surfaceControls =
1139 mListenerCallbacks[TransactionCompletedListener::getIInstance()].surfaceControls;
Marissa Wallc837b5e2018-10-12 10:04:44 -07001140
Marissa Wall80d94ad2019-01-18 16:04:36 -08001141 CallbackId callbackId = listener->addCallbackFunction(callbackWithContext, surfaceControls);
Marissa Wallc837b5e2018-10-12 10:04:44 -07001142
1143 mListenerCallbacks[TransactionCompletedListener::getIInstance()].callbackIds.emplace(
1144 callbackId);
Marissa Wall61c58622018-07-18 10:12:20 -07001145 return *this;
1146}
1147
Robert Carr4cdc58f2017-08-23 14:22:20 -07001148SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::detachChildren(
1149 const sp<SurfaceControl>& sc) {
chaviw763ef572018-02-22 16:04:57 -08001150 layer_state_t* s = getLayerState(sc);
Robert Carr4cdc58f2017-08-23 14:22:20 -07001151 if (!s) {
1152 mStatus = BAD_INDEX;
Greg Kaiserd45fdc32019-04-30 06:14:19 -07001153 return *this;
Robert Carr9524cb32017-02-13 11:32:32 -08001154 }
1155 s->what |= layer_state_t::eDetachChildren;
Marissa Wallc837b5e2018-10-12 10:04:44 -07001156
1157 registerSurfaceControlForCallback(sc);
Robert Carr4cdc58f2017-08-23 14:22:20 -07001158 return *this;
Robert Carr9524cb32017-02-13 11:32:32 -08001159}
1160
Robert Carr4cdc58f2017-08-23 14:22:20 -07001161SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setOverrideScalingMode(
1162 const sp<SurfaceControl>& sc, int32_t overrideScalingMode) {
chaviw763ef572018-02-22 16:04:57 -08001163 layer_state_t* s = getLayerState(sc);
Robert Carrc3574f72016-03-24 12:19:32 -07001164 if (!s) {
Robert Carr4cdc58f2017-08-23 14:22:20 -07001165 mStatus = BAD_INDEX;
1166 return *this;
Robert Carrc3574f72016-03-24 12:19:32 -07001167 }
1168
1169 switch (overrideScalingMode) {
1170 case NATIVE_WINDOW_SCALING_MODE_FREEZE:
1171 case NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW:
1172 case NATIVE_WINDOW_SCALING_MODE_SCALE_CROP:
1173 case NATIVE_WINDOW_SCALING_MODE_NO_SCALE_CROP:
1174 case -1:
1175 break;
1176 default:
1177 ALOGE("unknown scaling mode: %d",
1178 overrideScalingMode);
Robert Carr4cdc58f2017-08-23 14:22:20 -07001179 mStatus = BAD_VALUE;
1180 return *this;
Robert Carrc3574f72016-03-24 12:19:32 -07001181 }
1182
1183 s->what |= layer_state_t::eOverrideScalingModeChanged;
1184 s->overrideScalingMode = overrideScalingMode;
Marissa Wallc837b5e2018-10-12 10:04:44 -07001185
1186 registerSurfaceControlForCallback(sc);
Robert Carr4cdc58f2017-08-23 14:22:20 -07001187 return *this;
Robert Carrc3574f72016-03-24 12:19:32 -07001188}
1189
Robert Carr2c358bf2018-08-08 15:58:15 -07001190#ifndef NO_INPUT
1191SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setInputWindowInfo(
1192 const sp<SurfaceControl>& sc,
1193 const InputWindowInfo& info) {
1194 layer_state_t* s = getLayerState(sc);
1195 if (!s) {
1196 mStatus = BAD_INDEX;
1197 return *this;
1198 }
1199 s->inputInfo = info;
1200 s->what |= layer_state_t::eInputInfoChanged;
1201 return *this;
1202}
chaviw273171b2018-12-26 11:46:30 -08001203
1204SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::transferTouchFocus(
1205 const sp<IBinder>& fromToken, const sp<IBinder>& toToken) {
1206 InputWindowCommands::TransferTouchFocusCommand transferTouchFocusCommand;
1207 transferTouchFocusCommand.fromToken = fromToken;
1208 transferTouchFocusCommand.toToken = toToken;
1209 mInputWindowCommands.transferTouchFocusCommands.emplace_back(transferTouchFocusCommand);
1210 return *this;
1211}
1212
chaviwa911b102019-02-14 10:18:33 -08001213SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::syncInputWindows() {
1214 mInputWindowCommands.syncInputWindows = true;
1215 return *this;
1216}
1217
Robert Carr2c358bf2018-08-08 15:58:15 -07001218#endif
1219
Peiyong Lind3788632018-09-18 16:01:31 -07001220SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setColorTransform(
1221 const sp<SurfaceControl>& sc, const mat3& matrix, const vec3& translation) {
1222 layer_state_t* s = getLayerState(sc);
1223 if (!s) {
1224 mStatus = BAD_INDEX;
1225 return *this;
1226 }
1227 s->what |= layer_state_t::eColorTransformChanged;
1228 s->colorTransform = mat4(matrix, translation);
Marissa Wallc837b5e2018-10-12 10:04:44 -07001229
1230 registerSurfaceControlForCallback(sc);
Peiyong Lind3788632018-09-18 16:01:31 -07001231 return *this;
1232}
1233
Robert Carrfb4d58b2019-01-15 09:21:27 -08001234SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setGeometry(
1235 const sp<SurfaceControl>& sc, const Rect& source, const Rect& dst, int transform) {
1236 setCrop_legacy(sc, source);
1237
1238 int x = dst.left;
1239 int y = dst.top;
Robert Carr66365e42019-04-08 16:58:04 -07001240
1241 float sourceWidth = source.getWidth();
1242 float sourceHeight = source.getHeight();
1243
1244 float xScale = sourceWidth < 0 ? 1.0f : dst.getWidth() / sourceWidth;
1245 float yScale = sourceHeight < 0 ? 1.0f : dst.getHeight() / sourceHeight;
Robert Carrfb4d58b2019-01-15 09:21:27 -08001246 float matrix[4] = {1, 0, 0, 1};
1247
1248 switch (transform) {
1249 case NATIVE_WINDOW_TRANSFORM_FLIP_H:
1250 matrix[0] = -xScale; matrix[1] = 0;
1251 matrix[2] = 0; matrix[3] = yScale;
1252 x += source.getWidth();
1253 break;
1254 case NATIVE_WINDOW_TRANSFORM_FLIP_V:
1255 matrix[0] = xScale; matrix[1] = 0;
1256 matrix[2] = 0; matrix[3] = -yScale;
1257 y += source.getHeight();
1258 break;
1259 case NATIVE_WINDOW_TRANSFORM_ROT_90:
1260 matrix[0] = 0; matrix[1] = -yScale;
1261 matrix[2] = xScale; matrix[3] = 0;
1262 x += source.getHeight();
1263 break;
1264 case NATIVE_WINDOW_TRANSFORM_ROT_180:
1265 matrix[0] = -xScale; matrix[1] = 0;
1266 matrix[2] = 0; matrix[3] = -yScale;
1267 x += source.getWidth();
1268 y += source.getHeight();
1269 break;
1270 case NATIVE_WINDOW_TRANSFORM_ROT_270:
1271 matrix[0] = 0; matrix[1] = yScale;
1272 matrix[2] = -xScale; matrix[3] = 0;
1273 y += source.getWidth();
1274 break;
1275 default:
1276 matrix[0] = xScale; matrix[1] = 0;
1277 matrix[2] = 0; matrix[3] = yScale;
1278 break;
1279 }
1280 setMatrix(sc, matrix[0], matrix[1], matrix[2], matrix[3]);
1281 setPosition(sc, x, y);
1282
1283 return *this;
1284}
1285
Mathias Agopian698c0872011-06-28 19:09:31 -07001286// ---------------------------------------------------------------------------
1287
chaviw763ef572018-02-22 16:04:57 -08001288DisplayState& SurfaceComposerClient::Transaction::getDisplayState(const sp<IBinder>& token) {
Mathias Agopiane57f2922012-08-09 16:29:12 -07001289 DisplayState s;
1290 s.token = token;
1291 ssize_t index = mDisplayStates.indexOf(s);
1292 if (index < 0) {
1293 // we don't have it, add an initialized layer_state to our list
1294 s.what = 0;
1295 index = mDisplayStates.add(s);
1296 }
Dan Stozad723bd72014-11-18 10:24:03 -08001297 return mDisplayStates.editItemAt(static_cast<size_t>(index));
Mathias Agopiane57f2922012-08-09 16:29:12 -07001298}
1299
Robert Carr4cdc58f2017-08-23 14:22:20 -07001300status_t SurfaceComposerClient::Transaction::setDisplaySurface(const sp<IBinder>& token,
1301 const sp<IGraphicBufferProducer>& bufferProducer) {
Pablo Ceballoseddbef82016-09-01 11:21:21 -07001302 if (bufferProducer.get() != nullptr) {
1303 // Make sure that composition can never be stalled by a virtual display
1304 // consumer that isn't processing buffers fast enough.
1305 status_t err = bufferProducer->setAsyncMode(true);
1306 if (err != NO_ERROR) {
1307 ALOGE("Composer::setDisplaySurface Failed to enable async mode on the "
1308 "BufferQueue. This BufferQueue cannot be used for virtual "
1309 "display. (%d)", err);
1310 return err;
1311 }
Pablo Ceballos1aad24c2016-08-04 10:24:22 -07001312 }
chaviw763ef572018-02-22 16:04:57 -08001313 DisplayState& s(getDisplayState(token));
Andy McFadden2adaf042012-12-18 09:49:45 -08001314 s.surface = bufferProducer;
Mathias Agopiane57f2922012-08-09 16:29:12 -07001315 s.what |= DisplayState::eSurfaceChanged;
Pablo Ceballos1aad24c2016-08-04 10:24:22 -07001316 return NO_ERROR;
Mathias Agopiane57f2922012-08-09 16:29:12 -07001317}
1318
Robert Carr4cdc58f2017-08-23 14:22:20 -07001319void SurfaceComposerClient::Transaction::setDisplayLayerStack(const sp<IBinder>& token,
Mathias Agopiane57f2922012-08-09 16:29:12 -07001320 uint32_t layerStack) {
chaviw763ef572018-02-22 16:04:57 -08001321 DisplayState& s(getDisplayState(token));
Mathias Agopiane57f2922012-08-09 16:29:12 -07001322 s.layerStack = layerStack;
1323 s.what |= DisplayState::eLayerStackChanged;
1324}
1325
Robert Carr4cdc58f2017-08-23 14:22:20 -07001326void SurfaceComposerClient::Transaction::setDisplayProjection(const sp<IBinder>& token,
Mathias Agopian00e8c7a2012-09-04 19:30:46 -07001327 uint32_t orientation,
1328 const Rect& layerStackRect,
1329 const Rect& displayRect) {
chaviw763ef572018-02-22 16:04:57 -08001330 DisplayState& s(getDisplayState(token));
Mathias Agopiane57f2922012-08-09 16:29:12 -07001331 s.orientation = orientation;
Mathias Agopian00e8c7a2012-09-04 19:30:46 -07001332 s.viewport = layerStackRect;
1333 s.frame = displayRect;
1334 s.what |= DisplayState::eDisplayProjectionChanged;
Jorim Jaggi092123c2016-04-13 01:40:35 +00001335 mForceSynchronous = true; // TODO: do we actually still need this?
Mathias Agopiane57f2922012-08-09 16:29:12 -07001336}
1337
Robert Carr4cdc58f2017-08-23 14:22:20 -07001338void SurfaceComposerClient::Transaction::setDisplaySize(const sp<IBinder>& token, uint32_t width, uint32_t height) {
chaviw763ef572018-02-22 16:04:57 -08001339 DisplayState& s(getDisplayState(token));
Michael Wright1f6078a2014-06-26 16:01:02 -07001340 s.width = width;
1341 s.height = height;
1342 s.what |= DisplayState::eDisplaySizeChanged;
1343}
1344
Mathias Agopiane57f2922012-08-09 16:29:12 -07001345// ---------------------------------------------------------------------------
1346
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001347SurfaceComposerClient::SurfaceComposerClient()
Robert Carr4cdc58f2017-08-23 14:22:20 -07001348 : mStatus(NO_INIT)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001349{
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001350}
1351
Jorim Jaggif3cf4bc2017-11-30 14:19:23 +01001352SurfaceComposerClient::SurfaceComposerClient(const sp<ISurfaceComposerClient>& client)
1353 : mStatus(NO_ERROR), mClient(client)
1354{
1355}
1356
Mathias Agopian698c0872011-06-28 19:09:31 -07001357void SurfaceComposerClient::onFirstRef() {
Robert Carr4cdc58f2017-08-23 14:22:20 -07001358 sp<ISurfaceComposer> sf(ComposerService::getComposerService());
Yi Kong48a619f2018-06-05 16:34:59 -07001359 if (sf != nullptr && mStatus == NO_INIT) {
Robert Carr1db73f62016-12-21 12:58:51 -08001360 sp<ISurfaceComposerClient> conn;
Robert Carrb89ea9d2018-12-10 13:01:14 -08001361 conn = sf->createConnection();
Yi Kong48a619f2018-06-05 16:34:59 -07001362 if (conn != nullptr) {
Mathias Agopiand4784a32010-05-27 19:41:15 -07001363 mClient = conn;
Mathias Agopiand4784a32010-05-27 19:41:15 -07001364 mStatus = NO_ERROR;
1365 }
1366 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001367}
1368
Mathias Agopian698c0872011-06-28 19:09:31 -07001369SurfaceComposerClient::~SurfaceComposerClient() {
Mathias Agopian631f3582010-05-25 17:51:34 -07001370 dispose();
1371}
Mathias Agopiandd3423c2009-09-23 15:44:05 -07001372
Mathias Agopian698c0872011-06-28 19:09:31 -07001373status_t SurfaceComposerClient::initCheck() const {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001374 return mStatus;
1375}
1376
Mathias Agopian698c0872011-06-28 19:09:31 -07001377sp<IBinder> SurfaceComposerClient::connection() const {
Marco Nelissen2ea926b2014-11-14 08:01:01 -08001378 return IInterface::asBinder(mClient);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001379}
1380
Mathias Agopiand4784a32010-05-27 19:41:15 -07001381status_t SurfaceComposerClient::linkToComposerDeath(
1382 const sp<IBinder::DeathRecipient>& recipient,
Mathias Agopian698c0872011-06-28 19:09:31 -07001383 void* cookie, uint32_t flags) {
Robert Carr4cdc58f2017-08-23 14:22:20 -07001384 sp<ISurfaceComposer> sf(ComposerService::getComposerService());
1385 return IInterface::asBinder(sf)->linkToDeath(recipient, cookie, flags);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001386}
1387
Mathias Agopian698c0872011-06-28 19:09:31 -07001388void SurfaceComposerClient::dispose() {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001389 // this can be called more than once.
Mathias Agopian7e27f052010-05-28 14:22:23 -07001390 sp<ISurfaceComposerClient> client;
Mathias Agopiand4784a32010-05-27 19:41:15 -07001391 Mutex::Autolock _lm(mLock);
Yi Kong48a619f2018-06-05 16:34:59 -07001392 if (mClient != nullptr) {
Mathias Agopiand4784a32010-05-27 19:41:15 -07001393 client = mClient; // hold ref while lock is held
1394 mClient.clear();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001395 }
Mathias Agopiand4784a32010-05-27 19:41:15 -07001396 mStatus = NO_INIT;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001397}
1398
Evan Rosky1f6d6d52018-12-06 10:47:26 -08001399sp<SurfaceControl> SurfaceComposerClient::createSurface(const String8& name, uint32_t w, uint32_t h,
1400 PixelFormat format, uint32_t flags,
1401 SurfaceControl* parent,
1402 LayerMetadata metadata) {
Robert Carr3b382ed2018-03-14 13:49:41 -07001403 sp<SurfaceControl> s;
Evan Rosky1f6d6d52018-12-06 10:47:26 -08001404 createSurfaceChecked(name, w, h, format, &s, flags, parent, std::move(metadata));
Robert Carr3b382ed2018-03-14 13:49:41 -07001405 return s;
1406}
1407
Marissa Wall35187b32019-01-08 10:08:52 -08001408sp<SurfaceControl> SurfaceComposerClient::createWithSurfaceParent(const String8& name, uint32_t w,
1409 uint32_t h, PixelFormat format,
1410 uint32_t flags, Surface* parent,
Evan Rosky1f6d6d52018-12-06 10:47:26 -08001411 LayerMetadata metadata) {
Marissa Wall35187b32019-01-08 10:08:52 -08001412 sp<SurfaceControl> sur;
1413 status_t err = mStatus;
1414
1415 if (mStatus == NO_ERROR) {
1416 sp<IBinder> handle;
1417 sp<IGraphicBufferProducer> parentGbp = parent->getIGraphicBufferProducer();
1418 sp<IGraphicBufferProducer> gbp;
1419
Evan Rosky1f6d6d52018-12-06 10:47:26 -08001420 err = mClient->createWithSurfaceParent(name, w, h, format, flags, parentGbp,
1421 std::move(metadata), &handle, &gbp);
Marissa Wall35187b32019-01-08 10:08:52 -08001422 ALOGE_IF(err, "SurfaceComposerClient::createWithSurfaceParent error %s", strerror(-err));
1423 if (err == NO_ERROR) {
1424 return new SurfaceControl(this, handle, gbp, true /* owned */);
1425 }
1426 }
1427 return nullptr;
1428}
1429
Evan Rosky1f6d6d52018-12-06 10:47:26 -08001430status_t SurfaceComposerClient::createSurfaceChecked(const String8& name, uint32_t w, uint32_t h,
1431 PixelFormat format,
1432 sp<SurfaceControl>* outSurface, uint32_t flags,
1433 SurfaceControl* parent,
1434 LayerMetadata metadata) {
Mathias Agopian4d9b8222013-03-12 17:11:48 -07001435 sp<SurfaceControl> sur;
Robert Carr740eaf02018-03-27 12:59:18 -07001436 status_t err = mStatus;
Robert Carr3b382ed2018-03-14 13:49:41 -07001437
Mathias Agopian698c0872011-06-28 19:09:31 -07001438 if (mStatus == NO_ERROR) {
Mathias Agopian4d9b8222013-03-12 17:11:48 -07001439 sp<IBinder> handle;
Robert Carr1f0a16a2016-10-24 16:27:39 -07001440 sp<IBinder> parentHandle;
Mathias Agopian4d9b8222013-03-12 17:11:48 -07001441 sp<IGraphicBufferProducer> gbp;
Robert Carr1f0a16a2016-10-24 16:27:39 -07001442
1443 if (parent != nullptr) {
1444 parentHandle = parent->getHandle();
1445 }
Evan Rosky1f6d6d52018-12-06 10:47:26 -08001446
1447 err = mClient->createSurface(name, w, h, format, flags, parentHandle, std::move(metadata),
1448 &handle, &gbp);
Mathias Agopian4d9b8222013-03-12 17:11:48 -07001449 ALOGE_IF(err, "SurfaceComposerClient::createSurface error %s", strerror(-err));
1450 if (err == NO_ERROR) {
Robert Carr3b382ed2018-03-14 13:49:41 -07001451 *outSurface = new SurfaceControl(this, handle, gbp, true /* owned */);
Mathias Agopian698c0872011-06-28 19:09:31 -07001452 }
1453 }
Robert Carr3b382ed2018-03-14 13:49:41 -07001454 return err;
Mathias Agopian698c0872011-06-28 19:09:31 -07001455}
1456
Svetoslavd85084b2014-03-20 10:28:31 -07001457status_t SurfaceComposerClient::clearLayerFrameStats(const sp<IBinder>& token) const {
1458 if (mStatus != NO_ERROR) {
1459 return mStatus;
1460 }
1461 return mClient->clearLayerFrameStats(token);
1462}
1463
1464status_t SurfaceComposerClient::getLayerFrameStats(const sp<IBinder>& token,
1465 FrameStats* outStats) const {
1466 if (mStatus != NO_ERROR) {
1467 return mStatus;
1468 }
1469 return mClient->getLayerFrameStats(token, outStats);
1470}
1471
Mathias Agopian698c0872011-06-28 19:09:31 -07001472// ----------------------------------------------------------------------------
1473
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -07001474status_t SurfaceComposerClient::enableVSyncInjections(bool enable) {
Robert Carr4cdc58f2017-08-23 14:22:20 -07001475 sp<ISurfaceComposer> sf(ComposerService::getComposerService());
1476 return sf->enableVSyncInjections(enable);
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -07001477}
1478
1479status_t SurfaceComposerClient::injectVSync(nsecs_t when) {
Robert Carr4cdc58f2017-08-23 14:22:20 -07001480 sp<ISurfaceComposer> sf(ComposerService::getComposerService());
1481 return sf->injectVSync(when);
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -07001482}
1483
Dan Stoza7f7da322014-05-02 15:26:25 -07001484status_t SurfaceComposerClient::getDisplayConfigs(
1485 const sp<IBinder>& display, Vector<DisplayInfo>* configs)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001486{
Dan Stoza7f7da322014-05-02 15:26:25 -07001487 return ComposerService::getComposerService()->getDisplayConfigs(display, configs);
1488}
1489
1490status_t SurfaceComposerClient::getDisplayInfo(const sp<IBinder>& display,
1491 DisplayInfo* info) {
1492 Vector<DisplayInfo> configs;
1493 status_t result = getDisplayConfigs(display, &configs);
1494 if (result != NO_ERROR) {
1495 return result;
1496 }
1497
1498 int activeId = getActiveConfig(display);
1499 if (activeId < 0) {
1500 ALOGE("No active configuration found");
1501 return NAME_NOT_FOUND;
1502 }
1503
Dan Stozad723bd72014-11-18 10:24:03 -08001504 *info = configs[static_cast<size_t>(activeId)];
Dan Stoza7f7da322014-05-02 15:26:25 -07001505 return NO_ERROR;
1506}
1507
1508int SurfaceComposerClient::getActiveConfig(const sp<IBinder>& display) {
1509 return ComposerService::getComposerService()->getActiveConfig(display);
1510}
1511
1512status_t SurfaceComposerClient::setActiveConfig(const sp<IBinder>& display, int id) {
1513 return ComposerService::getComposerService()->setActiveConfig(display, id);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001514}
1515
Ady Abraham838de062019-02-04 10:24:03 -08001516status_t SurfaceComposerClient::setAllowedDisplayConfigs(
1517 const sp<IBinder>& displayToken, const std::vector<int32_t>& allowedConfigs) {
1518 return ComposerService::getComposerService()->setAllowedDisplayConfigs(displayToken,
1519 allowedConfigs);
1520}
1521
Ady Abrahamd9b3ea62019-02-26 14:08:03 -08001522status_t SurfaceComposerClient::getAllowedDisplayConfigs(const sp<IBinder>& displayToken,
1523 std::vector<int32_t>* outAllowedConfigs) {
1524 return ComposerService::getComposerService()->getAllowedDisplayConfigs(displayToken,
1525 outAllowedConfigs);
1526}
1527
Michael Wright28f24d02016-07-12 13:30:53 -07001528status_t SurfaceComposerClient::getDisplayColorModes(const sp<IBinder>& display,
Peiyong Lina52f0292018-03-14 17:26:31 -07001529 Vector<ColorMode>* outColorModes) {
Michael Wright28f24d02016-07-12 13:30:53 -07001530 return ComposerService::getComposerService()->getDisplayColorModes(display, outColorModes);
1531}
1532
Daniel Solomon42d04562019-01-20 21:03:19 -08001533status_t SurfaceComposerClient::getDisplayNativePrimaries(const sp<IBinder>& display,
1534 ui::DisplayPrimaries& outPrimaries) {
1535 return ComposerService::getComposerService()->getDisplayNativePrimaries(display, outPrimaries);
1536}
1537
Peiyong Lina52f0292018-03-14 17:26:31 -07001538ColorMode SurfaceComposerClient::getActiveColorMode(const sp<IBinder>& display) {
Michael Wright28f24d02016-07-12 13:30:53 -07001539 return ComposerService::getComposerService()->getActiveColorMode(display);
1540}
1541
1542status_t SurfaceComposerClient::setActiveColorMode(const sp<IBinder>& display,
Peiyong Lina52f0292018-03-14 17:26:31 -07001543 ColorMode colorMode) {
Michael Wright28f24d02016-07-12 13:30:53 -07001544 return ComposerService::getComposerService()->setActiveColorMode(display, colorMode);
1545}
1546
Prashant Malani2c9b11f2014-05-25 01:36:31 -07001547void SurfaceComposerClient::setDisplayPowerMode(const sp<IBinder>& token,
1548 int mode) {
1549 ComposerService::getComposerService()->setPowerMode(token, mode);
Jeff Brown2a09bb32012-10-08 19:13:57 -07001550}
1551
Peiyong Linc6780972018-10-28 15:24:08 -07001552status_t SurfaceComposerClient::getCompositionPreference(
1553 ui::Dataspace* defaultDataspace, ui::PixelFormat* defaultPixelFormat,
1554 ui::Dataspace* wideColorGamutDataspace, ui::PixelFormat* wideColorGamutPixelFormat) {
1555 return ComposerService::getComposerService()
1556 ->getCompositionPreference(defaultDataspace, defaultPixelFormat,
1557 wideColorGamutDataspace, wideColorGamutPixelFormat);
Peiyong Lin0256f722018-08-31 15:45:10 -07001558}
1559
Peiyong Lin08d10512019-01-16 13:27:35 -08001560bool SurfaceComposerClient::getProtectedContentSupport() {
1561 bool supported = false;
1562 ComposerService::getComposerService()->getProtectedContentSupport(&supported);
1563 return supported;
1564}
1565
Svetoslavd85084b2014-03-20 10:28:31 -07001566status_t SurfaceComposerClient::clearAnimationFrameStats() {
1567 return ComposerService::getComposerService()->clearAnimationFrameStats();
1568}
1569
1570status_t SurfaceComposerClient::getAnimationFrameStats(FrameStats* outStats) {
1571 return ComposerService::getComposerService()->getAnimationFrameStats(outStats);
1572}
1573
Dan Stozac4f471e2016-03-24 09:31:08 -07001574status_t SurfaceComposerClient::getHdrCapabilities(const sp<IBinder>& display,
1575 HdrCapabilities* outCapabilities) {
1576 return ComposerService::getComposerService()->getHdrCapabilities(display,
1577 outCapabilities);
1578}
1579
Kevin DuBois9c0a1762018-10-16 13:32:31 -07001580status_t SurfaceComposerClient::getDisplayedContentSamplingAttributes(const sp<IBinder>& display,
1581 ui::PixelFormat* outFormat,
1582 ui::Dataspace* outDataspace,
1583 uint8_t* outComponentMask) {
1584 return ComposerService::getComposerService()
1585 ->getDisplayedContentSamplingAttributes(display, outFormat, outDataspace,
1586 outComponentMask);
1587}
1588
Kevin DuBois74e53772018-11-19 10:52:38 -08001589status_t SurfaceComposerClient::setDisplayContentSamplingEnabled(const sp<IBinder>& display,
1590 bool enable, uint8_t componentMask,
1591 uint64_t maxFrames) {
1592 return ComposerService::getComposerService()->setDisplayContentSamplingEnabled(display, enable,
1593 componentMask,
1594 maxFrames);
1595}
1596
Kevin DuBois1d4249a2018-08-29 10:45:14 -07001597status_t SurfaceComposerClient::getDisplayedContentSample(const sp<IBinder>& display,
1598 uint64_t maxFrames, uint64_t timestamp,
1599 DisplayedFrameStats* outStats) {
1600 return ComposerService::getComposerService()->getDisplayedContentSample(display, maxFrames,
1601 timestamp, outStats);
1602}
Marissa Wall35187b32019-01-08 10:08:52 -08001603
Peiyong Lin4f3fddf2019-01-24 17:21:24 -08001604status_t SurfaceComposerClient::isWideColorDisplay(const sp<IBinder>& display,
1605 bool* outIsWideColorDisplay) {
1606 return ComposerService::getComposerService()->isWideColorDisplay(display,
1607 outIsWideColorDisplay);
1608}
1609
Kevin DuBois00c66832019-02-18 16:21:31 -08001610status_t SurfaceComposerClient::addRegionSamplingListener(
1611 const Rect& samplingArea, const sp<IBinder>& stopLayerHandle,
1612 const sp<IRegionSamplingListener>& listener) {
1613 return ComposerService::getComposerService()->addRegionSamplingListener(samplingArea,
1614 stopLayerHandle,
1615 listener);
1616}
1617
1618status_t SurfaceComposerClient::removeRegionSamplingListener(
1619 const sp<IRegionSamplingListener>& listener) {
1620 return ComposerService::getComposerService()->removeRegionSamplingListener(listener);
1621}
1622
Dan Gittik57e63c52019-01-18 16:37:54 +00001623bool SurfaceComposerClient::getDisplayBrightnessSupport(const sp<IBinder>& displayToken) {
1624 bool support = false;
1625 ComposerService::getComposerService()->getDisplayBrightnessSupport(displayToken, &support);
1626 return support;
1627}
1628
1629status_t SurfaceComposerClient::setDisplayBrightness(const sp<IBinder>& displayToken,
1630 float brightness) {
1631 return ComposerService::getComposerService()->setDisplayBrightness(displayToken, brightness);
1632}
1633
Ady Abraham8532d012019-05-08 14:50:56 -07001634status_t SurfaceComposerClient::notifyPowerHint(int32_t hintId) {
1635 return ComposerService::getComposerService()->notifyPowerHint(hintId);
1636}
1637
Mathias Agopian698c0872011-06-28 19:09:31 -07001638// ----------------------------------------------------------------------------
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001639
Peiyong Lin0e003c92018-09-17 11:09:51 -07001640status_t ScreenshotClient::capture(const sp<IBinder>& display, const ui::Dataspace reqDataSpace,
1641 const ui::PixelFormat reqPixelFormat, Rect sourceCrop,
1642 uint32_t reqWidth, uint32_t reqHeight, bool useIdentityTransform,
Robert Carr108b2c72019-04-02 16:32:58 -07001643 uint32_t rotation, bool captureSecureLayers,
1644 sp<GraphicBuffer>* outBuffer, bool& outCapturedSecureLayers) {
Mathias Agopian2a9fc492013-03-01 13:42:57 -08001645 sp<ISurfaceComposer> s(ComposerService::getComposerService());
Yi Kong48a619f2018-06-05 16:34:59 -07001646 if (s == nullptr) return NO_INIT;
Robert Carr108b2c72019-04-02 16:32:58 -07001647 status_t ret =
1648 s->captureScreen(display, outBuffer, outCapturedSecureLayers, reqDataSpace,
1649 reqPixelFormat, sourceCrop, reqWidth, reqHeight, useIdentityTransform,
1650 static_cast<ISurfaceComposer::Rotation>(rotation),
1651 captureSecureLayers);
Robert Carr673134e2017-01-09 19:48:38 -08001652 if (ret != NO_ERROR) {
1653 return ret;
1654 }
Robert Carr673134e2017-01-09 19:48:38 -08001655 return ret;
1656}
1657
Robert Carrfa8855f2019-02-19 10:05:00 -08001658status_t ScreenshotClient::capture(const sp<IBinder>& display, const ui::Dataspace reqDataSpace,
1659 const ui::PixelFormat reqPixelFormat, Rect sourceCrop,
1660 uint32_t reqWidth, uint32_t reqHeight, bool useIdentityTransform,
1661 uint32_t rotation, sp<GraphicBuffer>* outBuffer) {
Robert Carr108b2c72019-04-02 16:32:58 -07001662 bool ignored;
1663 return capture(display, reqDataSpace, reqPixelFormat, sourceCrop, reqWidth, reqHeight,
1664 useIdentityTransform, rotation, false, outBuffer, ignored);
Robert Carrfa8855f2019-02-19 10:05:00 -08001665}
1666
chaviw93df2ea2019-04-30 16:45:12 -07001667status_t ScreenshotClient::capture(uint64_t displayOrLayerStack, ui::Dataspace* outDataspace,
1668 sp<GraphicBuffer>* outBuffer) {
1669 sp<ISurfaceComposer> s(ComposerService::getComposerService());
1670 if (s == nullptr) return NO_INIT;
1671 return s->captureScreen(displayOrLayerStack, outDataspace, outBuffer);
1672}
1673
Peiyong Lin0e003c92018-09-17 11:09:51 -07001674status_t ScreenshotClient::captureLayers(const sp<IBinder>& layerHandle,
1675 const ui::Dataspace reqDataSpace,
1676 const ui::PixelFormat reqPixelFormat, Rect sourceCrop,
Chavi Weingarten40482ff2017-11-30 01:51:40 +00001677 float frameScale, sp<GraphicBuffer>* outBuffer) {
chaviwa76b2712017-09-20 12:02:26 -07001678 sp<ISurfaceComposer> s(ComposerService::getComposerService());
Yi Kong48a619f2018-06-05 16:34:59 -07001679 if (s == nullptr) return NO_INIT;
Peiyong Lin0e003c92018-09-17 11:09:51 -07001680 status_t ret = s->captureLayers(layerHandle, outBuffer, reqDataSpace, reqPixelFormat,
Robert Carr866455f2019-04-02 16:28:26 -07001681 sourceCrop, {}, frameScale, false /* childrenOnly */);
Robert Carr578038f2018-03-09 12:25:24 -08001682 return ret;
1683}
1684
Robert Carr866455f2019-04-02 16:28:26 -07001685status_t ScreenshotClient::captureChildLayers(
1686 const sp<IBinder>& layerHandle, const ui::Dataspace reqDataSpace,
1687 const ui::PixelFormat reqPixelFormat, Rect sourceCrop,
1688 const std::unordered_set<sp<IBinder>, ISurfaceComposer::SpHash<IBinder>>& excludeHandles,
1689 float frameScale, sp<GraphicBuffer>* outBuffer) {
Robert Carr578038f2018-03-09 12:25:24 -08001690 sp<ISurfaceComposer> s(ComposerService::getComposerService());
Yi Kong48a619f2018-06-05 16:34:59 -07001691 if (s == nullptr) return NO_INIT;
Robert Carr866455f2019-04-02 16:28:26 -07001692 status_t ret =
1693 s->captureLayers(layerHandle, outBuffer, reqDataSpace, reqPixelFormat, sourceCrop,
1694 excludeHandles, frameScale, true /* childrenOnly */);
chaviw7206d492017-11-10 16:16:12 -08001695 return ret;
chaviwa76b2712017-09-20 12:02:26 -07001696}
Mathias Agopian74c40c02010-09-29 13:02:36 -07001697// ----------------------------------------------------------------------------
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001698}; // namespace android