blob: 8c2538ca198d6d756b08af911c29ad1a8c521a23 [file] [log] [blame]
The Android Open Source Projectedbf3b62009-03-04 03:31:441/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#define LOG_TAG "SurfaceComposerClient"
18
19#include <stdint.h>
The Android Open Source Projectedbf3b62009-03-04 03:31:4420#include <sys/types.h>
The Android Open Source Projectedbf3b62009-03-04 03:31:4421
The Android Open Source Projectedbf3b62009-03-04 03:31:4422#include <utils/Errors.h>
The Android Open Source Projectedbf3b62009-03-04 03:31:4423#include <utils/Log.h>
Mathias Agopiana67932f2011-04-20 21:20:5924#include <utils/SortedVector.h>
25#include <utils/String8.h>
26#include <utils/threads.h>
The Android Open Source Projectedbf3b62009-03-04 03:31:4427
Marissa Wall7a9b6ff2018-08-22 00:26:2028#include <binder/IPCThreadState.h>
Mathias Agopiana67932f2011-04-20 21:20:5929#include <binder/IServiceManager.h>
Marissa Wall7a9b6ff2018-08-22 00:26:2030#include <binder/ProcessState.h>
Mathias Agopian9cce3252010-02-10 01:46:3731
Michael Wright28f24d02016-07-12 20:30:5332#include <system/graphics.h>
33
Mathias Agopian076b1cc2009-04-10 21:24:3034#include <ui/DisplayInfo.h>
The Android Open Source Projectedbf3b62009-03-04 03:31:4435
Robert Carr673134e2017-01-10 03:48:3836#include <gui/BufferItemConsumer.h>
Mathias Agopianabe815d2013-03-20 05:22:2137#include <gui/CpuConsumer.h>
Mathias Agopiane3c697f2013-02-15 01:11:0238#include <gui/IGraphicBufferProducer.h>
Mathias Agopian90ac7992012-02-26 02:48:3539#include <gui/ISurfaceComposer.h>
40#include <gui/ISurfaceComposerClient.h>
Robert Carr4cdc58f2017-08-23 21:22:2041#include <gui/LayerState.h>
Robert Carr0d480722017-01-11 00:42:5442#include <gui/Surface.h>
Mathias Agopian90ac7992012-02-26 02:48:3543#include <gui/SurfaceComposerClient.h>
The Android Open Source Projectedbf3b62009-03-04 03:31:4444
Robert Carr2c358bf2018-08-08 22:58:1545#ifndef NO_INPUT
46#include <input/InputWindow.h>
47#endif
48
Mathias Agopian41f673c2011-11-18 01:48:3549#include <private/gui/ComposerService.h>
The Android Open Source Projectedbf3b62009-03-04 03:31:4450
Marissa Wall73411622019-01-25 18:45:4151// 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-04 03:31:4454namespace android {
Peiyong Lin9f034472018-03-28 22:29:0055
56using ui::ColorMode;
The Android Open Source Projectedbf3b62009-03-04 03:31:4457// ---------------------------------------------------------------------------
58
Mathias Agopian7e27f052010-05-28 21:22:2359ANDROID_SINGLETON_STATIC_INSTANCE(ComposerService);
60
Mathias Agopianb7e930d2010-06-01 22:12:5861ComposerService::ComposerService()
62: Singleton<ComposerService>() {
Andy McFadden6652b3e2012-09-07 01:45:5663 Mutex::Autolock _l(mLock);
64 connectLocked();
65}
66
67void ComposerService::connectLocked() {
Mathias Agopianb7e930d2010-06-01 22:12:5868 const String16 name("SurfaceFlinger");
69 while (getService(name, &mComposerService) != NO_ERROR) {
70 usleep(250000);
71 }
Yi Konga03e0442018-07-17 18:16:5772 assert(mComposerService != nullptr);
Andy McFadden6652b3e2012-09-07 01:45:5673
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 22:41:0583 explicit DeathObserver(ComposerService& mgr) : mComposerService(mgr) { }
Andy McFadden6652b3e2012-09-07 01:45:5684 };
85
86 mDeathObserver = new DeathObserver(*const_cast<ComposerService*>(this));
Marco Nelissen2ea926b2014-11-14 16:01:0187 IInterface::asBinder(mComposerService)->linkToDeath(mDeathObserver);
Mathias Agopianb7e930d2010-06-01 22:12:5888}
89
Andy McFadden6652b3e2012-09-07 01:45:5690/*static*/ sp<ISurfaceComposer> ComposerService::getComposerService() {
91 ComposerService& instance = ComposerService::getInstance();
92 Mutex::Autolock _l(instance.mLock);
Yi Kong48a619f2018-06-05 23:34:5993 if (instance.mComposerService == nullptr) {
Andy McFadden6652b3e2012-09-07 01:45:5694 ComposerService::getInstance().connectLocked();
Yi Konga03e0442018-07-17 18:16:5795 assert(instance.mComposerService != nullptr);
Andy McFadden6652b3e2012-09-07 01:45:5696 ALOGD("ComposerService reconnected");
97 }
98 return instance.mComposerService;
99}
100
101void ComposerService::composerServiceDied()
102{
103 Mutex::Autolock _l(mLock);
Yi Kong48a619f2018-06-05 23:34:59104 mComposerService = nullptr;
105 mDeathObserver = nullptr;
Mathias Agopianb7e930d2010-06-01 22:12:58106}
107
Robert Carrfb4d58b2019-01-15 17:21:27108class 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 21:22:23129// ---------------------------------------------------------------------------
130
Marissa Wall7a9b6ff2018-08-22 00:26:20131// 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 17:04:44135// 0 is an invalid callback id
136TransactionCompletedListener::TransactionCompletedListener() : mCallbackIdCounter(1) {}
137
138CallbackId TransactionCompletedListener::getNextIdLocked() {
139 return mCallbackIdCounter++;
140}
141
Marissa Wall7a9b6ff2018-08-22 00:26:20142sp<TransactionCompletedListener> TransactionCompletedListener::getInstance() {
143 static sp<TransactionCompletedListener> sInstance = new TransactionCompletedListener;
144 return sInstance;
145}
146
Marissa Wallc837b5e2018-10-12 17:04:44147sp<ITransactionCompletedListener> TransactionCompletedListener::getIInstance() {
148 return static_cast<sp<ITransactionCompletedListener>>(getInstance());
149}
150
151void TransactionCompletedListener::startListeningLocked() {
Marissa Wall7a9b6ff2018-08-22 00:26:20152 if (mListening) {
153 return;
154 }
155 ProcessState::self()->startThreadPool();
156 mListening = true;
157}
158
Marissa Wall80d94ad2019-01-19 00:04:36159CallbackId TransactionCompletedListener::addCallbackFunction(
160 const TransactionCompletedCallback& callbackFunction,
161 const std::unordered_set<sp<SurfaceControl>, SurfaceComposerClient::SCHash>&
162 surfaceControls) {
Marissa Wallc837b5e2018-10-12 17:04:44163 std::lock_guard<std::mutex> lock(mMutex);
164 startListeningLocked();
165
166 CallbackId callbackId = getNextIdLocked();
Marissa Wall80d94ad2019-01-19 00:04:36167 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 17:04:44175 return callbackId;
176}
177
Marissa Wall80d94ad2019-01-19 00:04:36178void 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 18:33:52191void TransactionCompletedListener::onTransactionCompleted(ListenerStats listenerStats) {
192 std::lock_guard lock(mMutex);
193
Marissa Wall80d94ad2019-01-19 00:04:36194 /* 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 Walle2ffb422018-10-12 18:33:52206 for (const auto& [callbackIds, transactionStats] : listenerStats.transactionStats) {
207 for (auto callbackId : callbackIds) {
Marissa Wall80d94ad2019-01-19 00:04:36208 auto& [callbackFunction, callbackSurfaceControls] = mCallbacks[callbackId];
209 surfaceControls.insert(callbackSurfaceControls.begin(), callbackSurfaceControls.end());
210 }
211 }
212
213 for (const auto& [callbackIds, transactionStats] : listenerStats.transactionStats) {
214 for (auto callbackId : callbackIds) {
215 auto& [callbackFunction, callbackSurfaceControls] = mCallbacks[callbackId];
216 if (!callbackFunction) {
Marissa Walle2ffb422018-10-12 18:33:52217 ALOGE("cannot call null callback function, skipping");
218 continue;
219 }
Marissa Wall80d94ad2019-01-19 00:04:36220 std::vector<SurfaceControlStats> surfaceControlStats;
221 for (const auto& surfaceStats : transactionStats.surfaceStats) {
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 18:33:52229 mCallbacks.erase(callbackId);
230 }
231 }
Marissa Wall7a9b6ff2018-08-22 00:26:20232}
233
234// ---------------------------------------------------------------------------
235
Marissa Wall73411622019-01-25 18:45:41236class BufferCache : public Singleton<BufferCache> {
237public:
238 BufferCache() : token(new BBinder()) {}
239
240 sp<IBinder> getToken() {
241 return IInterface::asBinder(TransactionCompletedListener::getIInstance());
242 }
243
244 int32_t getId(const sp<GraphicBuffer>& buffer) {
245 std::lock_guard lock(mMutex);
246
247 auto itr = mBuffers.find(buffer);
248 if (itr == mBuffers.end()) {
249 return -1;
250 }
251 itr->second.counter = getCounter();
252 return itr->second.id;
253 }
254
255 int32_t cache(const sp<GraphicBuffer>& buffer) {
256 std::lock_guard lock(mMutex);
257
258 int32_t bufferId = getNextAvailableId();
259
260 mBuffers[buffer].id = bufferId;
261 mBuffers[buffer].counter = getCounter();
262 return bufferId;
263 }
264
265private:
266 int32_t evictDestroyedBuffer() REQUIRES(mMutex) {
267 auto itr = mBuffers.begin();
268 while (itr != mBuffers.end()) {
269 auto& buffer = itr->first;
270 if (buffer == nullptr || buffer.promote() == nullptr) {
271 int32_t bufferId = itr->second.id;
272 mBuffers.erase(itr);
273 return bufferId;
274 }
275 itr++;
276 }
277 return -1;
278 }
279
280 int32_t evictLeastRecentlyUsedBuffer() REQUIRES(mMutex) {
281 if (mBuffers.size() < 0) {
282 return -1;
283 }
284 auto itr = mBuffers.begin();
285 uint64_t minCounter = itr->second.counter;
286 auto minBuffer = itr;
287 itr++;
288
289 while (itr != mBuffers.end()) {
290 uint64_t counter = itr->second.counter;
291 if (counter < minCounter) {
292 minCounter = counter;
293 minBuffer = itr;
294 }
295 itr++;
296 }
297 int32_t minBufferId = minBuffer->second.id;
298 mBuffers.erase(minBuffer);
299 return minBufferId;
300 }
301
302 int32_t getNextAvailableId() REQUIRES(mMutex) {
303 static int32_t id = 0;
304 if (id + 1 < BUFFER_CACHE_MAX_SIZE) {
305 return id++;
306 }
307
308 // There are no more valid cache ids. To set additional buffers, evict existing buffers
309 // and reuse their cache ids.
310 int32_t bufferId = evictDestroyedBuffer();
311 if (bufferId > 0) {
312 return bufferId;
313 }
314 return evictLeastRecentlyUsedBuffer();
315 }
316
317 uint64_t getCounter() REQUIRES(mMutex) {
318 static uint64_t counter = 0;
319 return counter++;
320 }
321
322 struct Metadata {
323 // The cache id of a buffer that can be set to ISurfaceComposer. When ISurfaceComposer
324 // recieves this id, it can retrieve the buffer from its cache. Caching GraphicBuffers
325 // is important because sending them across processes is expensive.
326 int32_t id = 0;
327 // When a buffer is set, a counter is incremented and stored in the cache's metadata.
328 // When an buffer must be evicted, the entry with the lowest counter value is chosen.
329 uint64_t counter = 0;
330 };
331
332 std::mutex mMutex;
333 std::map<wp<GraphicBuffer>, Metadata> mBuffers GUARDED_BY(mMutex);
334
335 // Used by ISurfaceComposer to identify which process is sending the cached buffer.
336 sp<IBinder> token;
337};
338
339ANDROID_SINGLETON_STATIC_INSTANCE(BufferCache);
340
341// ---------------------------------------------------------------------------
342
Marissa Wall17b4e452018-12-27 00:32:34343SurfaceComposerClient::Transaction::Transaction(const Transaction& other)
344 : mForceSynchronous(other.mForceSynchronous),
345 mTransactionNestCount(other.mTransactionNestCount),
346 mAnimation(other.mAnimation),
347 mEarlyWakeup(other.mEarlyWakeup),
348 mDesiredPresentTime(other.mDesiredPresentTime) {
Robert Carr4cdc58f2017-08-23 21:22:20349 mDisplayStates = other.mDisplayStates;
350 mComposerStates = other.mComposerStates;
chaviw273171b2018-12-26 19:46:30351 mInputWindowCommands = other.mInputWindowCommands;
Mathias Agopian698c0872011-06-29 02:09:31352}
353
Robert Carr2c5f6d22017-09-26 19:30:35354SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::merge(Transaction&& other) {
chaviw8e3fe5d2018-02-22 18:55:42355 for (auto const& kv : other.mComposerStates) {
356 if (mComposerStates.count(kv.first) == 0) {
357 mComposerStates[kv.first] = kv.second;
Robert Carr2c5f6d22017-09-26 19:30:35358 } else {
chaviw8e3fe5d2018-02-22 18:55:42359 mComposerStates[kv.first].state.merge(kv.second.state);
Robert Carr2c5f6d22017-09-26 19:30:35360 }
361 }
362 other.mComposerStates.clear();
363
364 for (auto const& state : other.mDisplayStates) {
365 ssize_t index = mDisplayStates.indexOf(state);
366 if (index < 0) {
367 mDisplayStates.add(state);
368 } else {
369 mDisplayStates.editItemAt(static_cast<size_t>(index)).merge(state);
370 }
371 }
372 other.mDisplayStates.clear();
373
Marissa Wallc837b5e2018-10-12 17:04:44374 for (const auto& [listener, callbackInfo] : other.mListenerCallbacks) {
375 auto& [callbackIds, surfaceControls] = callbackInfo;
376 mListenerCallbacks[listener].callbackIds.insert(std::make_move_iterator(
377 callbackIds.begin()),
378 std::make_move_iterator(callbackIds.end()));
379 mListenerCallbacks[listener]
380 .surfaceControls.insert(std::make_move_iterator(surfaceControls.begin()),
381 std::make_move_iterator(surfaceControls.end()));
382 }
383 other.mListenerCallbacks.clear();
384
chaviw273171b2018-12-26 19:46:30385 mInputWindowCommands.merge(other.mInputWindowCommands);
Vishnu Nairec0ab382019-02-13 23:32:56386 other.mInputWindowCommands.clear();
chaviw273171b2018-12-26 19:46:30387
Robert Carr2c5f6d22017-09-26 19:30:35388 return *this;
389}
390
Robert Carr6fb1a7e2018-12-11 20:07:25391void SurfaceComposerClient::doDropReferenceTransaction(const sp<IBinder>& handle,
392 const sp<ISurfaceComposerClient>& client) {
393 sp<ISurfaceComposer> sf(ComposerService::getComposerService());
394 Vector<ComposerState> composerStates;
395 Vector<DisplayState> displayStates;
396
397 ComposerState s;
398 s.client = client;
399 s.state.surface = handle;
400 s.state.what |= layer_state_t::eReparent;
401 s.state.parentHandleForChild = nullptr;
402
403 composerStates.add(s);
Marissa Wall17b4e452018-12-27 00:32:34404 sf->setTransactionState(composerStates, displayStates, 0, nullptr, {}, -1);
Robert Carr6fb1a7e2018-12-11 20:07:25405}
406
Robert Carr4cdc58f2017-08-23 21:22:20407status_t SurfaceComposerClient::Transaction::apply(bool synchronous) {
408 if (mStatus != NO_ERROR) {
409 return mStatus;
410 }
411
412 sp<ISurfaceComposer> sf(ComposerService::getComposerService());
413
Marissa Wallc837b5e2018-10-12 17:04:44414 // For every listener with registered callbacks
415 for (const auto& [listener, callbackInfo] : mListenerCallbacks) {
416 auto& [callbackIds, surfaceControls] = callbackInfo;
417 if (callbackIds.empty()) {
418 continue;
419 }
420
Marissa Walle2ffb422018-10-12 18:33:52421 // If the listener does not have any SurfaceControls set on this Transaction, send the
422 // callback now
423 if (surfaceControls.empty()) {
424 listener->onTransactionCompleted(ListenerStats::createEmpty(listener, callbackIds));
425 }
426
Marissa Wallc837b5e2018-10-12 17:04:44427 // If the listener has any SurfaceControls set on this Transaction update the surface state
428 for (const auto& surfaceControl : surfaceControls) {
429 layer_state_t* s = getLayerState(surfaceControl);
430 if (!s) {
431 ALOGE("failed to get layer state");
432 continue;
433 }
434 s->what |= layer_state_t::eListenerCallbacksChanged;
435 s->listenerCallbacks.emplace_back(listener, std::move(callbackIds));
436 }
437 }
438 mListenerCallbacks.clear();
439
Robert Carr4cdc58f2017-08-23 21:22:20440 Vector<ComposerState> composerStates;
441 Vector<DisplayState> displayStates;
442 uint32_t flags = 0;
443
444 mForceSynchronous |= synchronous;
445
chaviw8e3fe5d2018-02-22 18:55:42446 for (auto const& kv : mComposerStates){
447 composerStates.add(kv.second);
448 }
449
Robert Carr4cdc58f2017-08-23 21:22:20450 mComposerStates.clear();
451
452 displayStates = mDisplayStates;
453 mDisplayStates.clear();
454
455 if (mForceSynchronous) {
456 flags |= ISurfaceComposer::eSynchronous;
457 }
458 if (mAnimation) {
459 flags |= ISurfaceComposer::eAnimation;
460 }
Dan Stoza84d619e2018-03-29 00:07:36461 if (mEarlyWakeup) {
462 flags |= ISurfaceComposer::eEarlyWakeup;
463 }
Robert Carr4cdc58f2017-08-23 21:22:20464
465 mForceSynchronous = false;
466 mAnimation = false;
Dan Stoza84d619e2018-03-29 00:07:36467 mEarlyWakeup = false;
Robert Carr4cdc58f2017-08-23 21:22:20468
Marissa Wall713b63f2018-10-17 22:42:43469 sp<IBinder> applyToken = IInterface::asBinder(TransactionCompletedListener::getIInstance());
Marissa Wall17b4e452018-12-27 00:32:34470 sf->setTransactionState(composerStates, displayStates, flags, applyToken, mInputWindowCommands,
471 mDesiredPresentTime);
chaviw273171b2018-12-26 19:46:30472 mInputWindowCommands.clear();
Robert Carr4cdc58f2017-08-23 21:22:20473 mStatus = NO_ERROR;
474 return NO_ERROR;
Mathias Agopiane57f2922012-08-09 23:29:12475}
476
The Android Open Source Projectedbf3b62009-03-04 03:31:44477// ---------------------------------------------------------------------------
478
Robert Carr4cdc58f2017-08-23 21:22:20479sp<IBinder> SurfaceComposerClient::createDisplay(const String8& displayName, bool secure) {
Jamie Gennisdd3cb842012-10-20 01:19:11480 return ComposerService::getComposerService()->createDisplay(displayName,
481 secure);
Mathias Agopiane57f2922012-08-09 23:29:12482}
483
Robert Carr4cdc58f2017-08-23 21:22:20484void SurfaceComposerClient::destroyDisplay(const sp<IBinder>& display) {
Jesse Hall6c913be2013-08-08 19:15:49485 return ComposerService::getComposerService()->destroyDisplay(display);
486}
487
Dominik Laskowskidcb38bb2019-01-25 10:35:50488std::vector<PhysicalDisplayId> SurfaceComposerClient::getPhysicalDisplayIds() {
489 return ComposerService::getComposerService()->getPhysicalDisplayIds();
490}
491
492std::optional<PhysicalDisplayId> SurfaceComposerClient::getInternalDisplayId() {
493 return ComposerService::getComposerService()->getInternalDisplayId();
494}
495
496sp<IBinder> SurfaceComposerClient::getPhysicalDisplayToken(PhysicalDisplayId displayId) {
497 return ComposerService::getComposerService()->getPhysicalDisplayToken(displayId);
498}
499
500sp<IBinder> SurfaceComposerClient::getInternalDisplayToken() {
501 return ComposerService::getComposerService()->getInternalDisplayToken();
Jeff Brown9d4e3d22012-08-25 03:00:51502}
503
Robert Carr4cdc58f2017-08-23 21:22:20504void SurfaceComposerClient::Transaction::setAnimationTransaction() {
Jamie Gennis2d5e2302012-10-16 01:24:43505 mAnimation = true;
506}
507
Dan Stoza84d619e2018-03-29 00:07:36508void SurfaceComposerClient::Transaction::setEarlyWakeup() {
509 mEarlyWakeup = true;
510}
511
chaviw763ef572018-02-23 00:04:57512layer_state_t* SurfaceComposerClient::Transaction::getLayerState(const sp<SurfaceControl>& sc) {
chaviw8e3fe5d2018-02-22 18:55:42513 if (mComposerStates.count(sc) == 0) {
Mathias Agopian698c0872011-06-29 02:09:31514 // we don't have it, add an initialized layer_state to our list
chaviw8e3fe5d2018-02-22 18:55:42515 ComposerState s;
516 s.client = sc->getClient()->mClient;
517 s.state.surface = sc->getHandle();
518 mComposerStates[sc] = s;
Mathias Agopian698c0872011-06-29 02:09:31519 }
520
chaviw8e3fe5d2018-02-22 18:55:42521 return &(mComposerStates[sc].state);
Mathias Agopian698c0872011-06-29 02:09:31522}
523
Marissa Wallc837b5e2018-10-12 17:04:44524void SurfaceComposerClient::Transaction::registerSurfaceControlForCallback(
525 const sp<SurfaceControl>& sc) {
Marissa Wall80d94ad2019-01-19 00:04:36526 auto& callbackInfo = mListenerCallbacks[TransactionCompletedListener::getIInstance()];
527 callbackInfo.surfaceControls.insert(sc);
528
529 TransactionCompletedListener::getInstance()
530 ->addSurfaceControlToCallbacks(sc, callbackInfo.callbackIds);
Marissa Wallc837b5e2018-10-12 17:04:44531}
532
Robert Carr4cdc58f2017-08-23 21:22:20533SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setPosition(
534 const sp<SurfaceControl>& sc, float x, float y) {
chaviw763ef572018-02-23 00:04:57535 layer_state_t* s = getLayerState(sc);
Robert Carr4cdc58f2017-08-23 21:22:20536 if (!s) {
537 mStatus = BAD_INDEX;
538 return *this;
539 }
Mathias Agopian3165cc22012-08-09 02:42:09540 s->what |= layer_state_t::ePositionChanged;
Mathias Agopian698c0872011-06-29 02:09:31541 s->x = x;
542 s->y = y;
Marissa Wallc837b5e2018-10-12 17:04:44543
544 registerSurfaceControlForCallback(sc);
Robert Carr4cdc58f2017-08-23 21:22:20545 return *this;
Mathias Agopian698c0872011-06-29 02:09:31546}
547
Robert Carr4cdc58f2017-08-23 21:22:20548SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::show(
549 const sp<SurfaceControl>& sc) {
550 return setFlags(sc, 0, layer_state_t::eLayerHidden);
551}
552
553SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::hide(
554 const sp<SurfaceControl>& sc) {
555 return setFlags(sc, layer_state_t::eLayerHidden, layer_state_t::eLayerHidden);
556}
557
558SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setSize(
559 const sp<SurfaceControl>& sc, uint32_t w, uint32_t h) {
chaviw763ef572018-02-23 00:04:57560 layer_state_t* s = getLayerState(sc);
Robert Carr4cdc58f2017-08-23 21:22:20561 if (!s) {
562 mStatus = BAD_INDEX;
563 return *this;
564 }
Mathias Agopian3165cc22012-08-09 02:42:09565 s->what |= layer_state_t::eSizeChanged;
Mathias Agopian698c0872011-06-29 02:09:31566 s->w = w;
567 s->h = h;
Jamie Gennis28378392011-10-13 00:39:00568
Marissa Wallc837b5e2018-10-12 17:04:44569 registerSurfaceControlForCallback(sc);
Robert Carr4cdc58f2017-08-23 21:22:20570 return *this;
Mathias Agopian698c0872011-06-29 02:09:31571}
572
Robert Carr4cdc58f2017-08-23 21:22:20573SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setLayer(
574 const sp<SurfaceControl>& sc, int32_t z) {
chaviw763ef572018-02-23 00:04:57575 layer_state_t* s = getLayerState(sc);
Robert Carr4cdc58f2017-08-23 21:22:20576 if (!s) {
577 mStatus = BAD_INDEX;
578 return *this;
579 }
Mathias Agopian3165cc22012-08-09 02:42:09580 s->what |= layer_state_t::eLayerChanged;
Mathias Agopian698c0872011-06-29 02:09:31581 s->z = z;
Marissa Wallc837b5e2018-10-12 17:04:44582
583 registerSurfaceControlForCallback(sc);
Robert Carr4cdc58f2017-08-23 21:22:20584 return *this;
Mathias Agopian698c0872011-06-29 02:09:31585}
586
Robert Carr4cdc58f2017-08-23 21:22:20587SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setRelativeLayer(const sp<SurfaceControl>& sc, const sp<IBinder>& relativeTo,
Robert Carrdb66e622017-04-10 23:55:57588 int32_t z) {
chaviw763ef572018-02-23 00:04:57589 layer_state_t* s = getLayerState(sc);
Robert Carrdb66e622017-04-10 23:55:57590 if (!s) {
Robert Carr4cdc58f2017-08-23 21:22:20591 mStatus = BAD_INDEX;
Robert Carrdb66e622017-04-10 23:55:57592 }
593 s->what |= layer_state_t::eRelativeLayerChanged;
594 s->relativeLayerHandle = relativeTo;
595 s->z = z;
Marissa Wallc837b5e2018-10-12 17:04:44596
597 registerSurfaceControlForCallback(sc);
Robert Carr4cdc58f2017-08-23 21:22:20598 return *this;
Robert Carrdb66e622017-04-10 23:55:57599}
600
Robert Carr4cdc58f2017-08-23 21:22:20601SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setFlags(
602 const sp<SurfaceControl>& sc, uint32_t flags,
Mathias Agopian698c0872011-06-29 02:09:31603 uint32_t mask) {
chaviw763ef572018-02-23 00:04:57604 layer_state_t* s = getLayerState(sc);
Robert Carr4cdc58f2017-08-23 21:22:20605 if (!s) {
606 mStatus = BAD_INDEX;
607 return *this;
608 }
Pablo Ceballos53390e12015-08-04 18:25:59609 if ((mask & layer_state_t::eLayerOpaque) ||
610 (mask & layer_state_t::eLayerHidden) ||
611 (mask & layer_state_t::eLayerSecure)) {
Dan Stoza23116082015-06-18 21:58:39612 s->what |= layer_state_t::eFlagsChanged;
Andy McFadden4125a4f2014-01-30 01:17:11613 }
Mathias Agopian698c0872011-06-29 02:09:31614 s->flags &= ~mask;
615 s->flags |= (flags & mask);
616 s->mask |= mask;
Marissa Wallc837b5e2018-10-12 17:04:44617
618 registerSurfaceControlForCallback(sc);
Robert Carr4cdc58f2017-08-23 21:22:20619 return *this;
Mathias Agopian698c0872011-06-29 02:09:31620}
621
Robert Carr4cdc58f2017-08-23 21:22:20622SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setTransparentRegionHint(
623 const sp<SurfaceControl>& sc,
Mathias Agopian698c0872011-06-29 02:09:31624 const Region& transparentRegion) {
chaviw763ef572018-02-23 00:04:57625 layer_state_t* s = getLayerState(sc);
Robert Carr4cdc58f2017-08-23 21:22:20626 if (!s) {
627 mStatus = BAD_INDEX;
628 return *this;
629 }
Mathias Agopian3165cc22012-08-09 02:42:09630 s->what |= layer_state_t::eTransparentRegionChanged;
Mathias Agopian698c0872011-06-29 02:09:31631 s->transparentRegion = transparentRegion;
Marissa Wallc837b5e2018-10-12 17:04:44632
633 registerSurfaceControlForCallback(sc);
Robert Carr4cdc58f2017-08-23 21:22:20634 return *this;
Mathias Agopian698c0872011-06-29 02:09:31635}
636
Robert Carr4cdc58f2017-08-23 21:22:20637SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setAlpha(
638 const sp<SurfaceControl>& sc, float alpha) {
chaviw763ef572018-02-23 00:04:57639 layer_state_t* s = getLayerState(sc);
Robert Carr4cdc58f2017-08-23 21:22:20640 if (!s) {
641 mStatus = BAD_INDEX;
642 return *this;
643 }
Mathias Agopian3165cc22012-08-09 02:42:09644 s->what |= layer_state_t::eAlphaChanged;
Mathias Agopian698c0872011-06-29 02:09:31645 s->alpha = alpha;
Marissa Wallc837b5e2018-10-12 17:04:44646
647 registerSurfaceControlForCallback(sc);
Robert Carr4cdc58f2017-08-23 21:22:20648 return *this;
Mathias Agopian698c0872011-06-29 02:09:31649}
650
Robert Carr4cdc58f2017-08-23 21:22:20651SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setLayerStack(
652 const sp<SurfaceControl>& sc, uint32_t layerStack) {
chaviw763ef572018-02-23 00:04:57653 layer_state_t* s = getLayerState(sc);
Robert Carr4cdc58f2017-08-23 21:22:20654 if (!s) {
655 mStatus = BAD_INDEX;
656 return *this;
657 }
Mathias Agopian3165cc22012-08-09 02:42:09658 s->what |= layer_state_t::eLayerStackChanged;
Mathias Agopian87855782012-07-25 04:41:09659 s->layerStack = layerStack;
Marissa Wallc837b5e2018-10-12 17:04:44660
661 registerSurfaceControlForCallback(sc);
Robert Carr4cdc58f2017-08-23 21:22:20662 return *this;
Mathias Agopian87855782012-07-25 04:41:09663}
664
Evan Rosky1f6d6d52018-12-06 18:47:26665SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setMetadata(
666 const sp<SurfaceControl>& sc, uint32_t key, std::vector<uint8_t> data) {
667 layer_state_t* s = getLayerState(sc);
668 if (!s) {
669 mStatus = BAD_INDEX;
670 return *this;
671 }
672 s->what |= layer_state_t::eMetadataChanged;
673 s->metadata.mMap[key] = std::move(data);
674
675 registerSurfaceControlForCallback(sc);
676 return *this;
677}
678
Robert Carr4cdc58f2017-08-23 21:22:20679SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setMatrix(
680 const sp<SurfaceControl>& sc, float dsdx, float dtdx,
Robert Carrcb6e1e32017-02-22 03:48:26681 float dtdy, float dsdy) {
chaviw763ef572018-02-23 00:04:57682 layer_state_t* s = getLayerState(sc);
Robert Carr4cdc58f2017-08-23 21:22:20683 if (!s) {
684 mStatus = BAD_INDEX;
685 return *this;
686 }
Mathias Agopian3165cc22012-08-09 02:42:09687 s->what |= layer_state_t::eMatrixChanged;
Mathias Agopian698c0872011-06-29 02:09:31688 layer_state_t::matrix22_t matrix;
689 matrix.dsdx = dsdx;
690 matrix.dtdx = dtdx;
691 matrix.dsdy = dsdy;
692 matrix.dtdy = dtdy;
693 s->matrix = matrix;
Marissa Wallc837b5e2018-10-12 17:04:44694
695 registerSurfaceControlForCallback(sc);
Robert Carr4cdc58f2017-08-23 21:22:20696 return *this;
Mathias Agopian698c0872011-06-29 02:09:31697}
698
Marissa Wallf58c14b2018-07-24 17:50:43699SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setCrop_legacy(
Robert Carr4cdc58f2017-08-23 21:22:20700 const sp<SurfaceControl>& sc, const Rect& crop) {
chaviw763ef572018-02-23 00:04:57701 layer_state_t* s = getLayerState(sc);
Robert Carr4cdc58f2017-08-23 21:22:20702 if (!s) {
703 mStatus = BAD_INDEX;
704 return *this;
705 }
Marissa Wallf58c14b2018-07-24 17:50:43706 s->what |= layer_state_t::eCropChanged_legacy;
707 s->crop_legacy = crop;
Marissa Wallc837b5e2018-10-12 17:04:44708
709 registerSurfaceControlForCallback(sc);
Robert Carr4cdc58f2017-08-23 21:22:20710 return *this;
Jamie Gennisf15a83f2012-05-11 03:43:55711}
712
Lucas Dupin1b6531c2018-07-06 00:18:21713SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setCornerRadius(
714 const sp<SurfaceControl>& sc, float cornerRadius) {
715 layer_state_t* s = getLayerState(sc);
716 if (!s) {
717 mStatus = BAD_INDEX;
718 return *this;
719 }
720 s->what |= layer_state_t::eCornerRadiusChanged;
721 s->cornerRadius = cornerRadius;
722 return *this;
723}
724
Marissa Wallf58c14b2018-07-24 17:50:43725SurfaceComposerClient::Transaction&
726SurfaceComposerClient::Transaction::deferTransactionUntil_legacy(const sp<SurfaceControl>& sc,
727 const sp<IBinder>& handle,
728 uint64_t frameNumber) {
chaviw763ef572018-02-23 00:04:57729 layer_state_t* s = getLayerState(sc);
Dan Stoza7dde5992015-05-22 16:51:44730 if (!s) {
Robert Carr4cdc58f2017-08-23 21:22:20731 mStatus = BAD_INDEX;
732 return *this;
Dan Stoza7dde5992015-05-22 16:51:44733 }
Marissa Wallf58c14b2018-07-24 17:50:43734 s->what |= layer_state_t::eDeferTransaction_legacy;
735 s->barrierHandle_legacy = handle;
736 s->frameNumber_legacy = frameNumber;
Marissa Wallc837b5e2018-10-12 17:04:44737
738 registerSurfaceControlForCallback(sc);
Robert Carr4cdc58f2017-08-23 21:22:20739 return *this;
Robert Carr0d480722017-01-11 00:42:54740}
741
Marissa Wallf58c14b2018-07-24 17:50:43742SurfaceComposerClient::Transaction&
743SurfaceComposerClient::Transaction::deferTransactionUntil_legacy(const sp<SurfaceControl>& sc,
744 const sp<Surface>& barrierSurface,
745 uint64_t frameNumber) {
chaviw763ef572018-02-23 00:04:57746 layer_state_t* s = getLayerState(sc);
Robert Carr0d480722017-01-11 00:42:54747 if (!s) {
Robert Carr4cdc58f2017-08-23 21:22:20748 mStatus = BAD_INDEX;
749 return *this;
Robert Carr0d480722017-01-11 00:42:54750 }
Marissa Wallf58c14b2018-07-24 17:50:43751 s->what |= layer_state_t::eDeferTransaction_legacy;
752 s->barrierGbp_legacy = barrierSurface->getIGraphicBufferProducer();
753 s->frameNumber_legacy = frameNumber;
Marissa Wallc837b5e2018-10-12 17:04:44754
755 registerSurfaceControlForCallback(sc);
Robert Carr4cdc58f2017-08-23 21:22:20756 return *this;
Dan Stoza7dde5992015-05-22 16:51:44757}
758
Robert Carr4cdc58f2017-08-23 21:22:20759SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::reparentChildren(
760 const sp<SurfaceControl>& sc,
Robert Carr1db73f62016-12-21 20:58:51761 const sp<IBinder>& newParentHandle) {
chaviw763ef572018-02-23 00:04:57762 layer_state_t* s = getLayerState(sc);
Robert Carr1db73f62016-12-21 20:58:51763 if (!s) {
Robert Carr4cdc58f2017-08-23 21:22:20764 mStatus = BAD_INDEX;
765 return *this;
Robert Carr1db73f62016-12-21 20:58:51766 }
767 s->what |= layer_state_t::eReparentChildren;
768 s->reparentHandle = newParentHandle;
Marissa Wallc837b5e2018-10-12 17:04:44769
770 registerSurfaceControlForCallback(sc);
Robert Carr4cdc58f2017-08-23 21:22:20771 return *this;
Robert Carr1db73f62016-12-21 20:58:51772}
773
Robert Carr4cdc58f2017-08-23 21:22:20774SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::reparent(
775 const sp<SurfaceControl>& sc,
chaviwf1961f72017-09-18 23:41:07776 const sp<IBinder>& newParentHandle) {
chaviw763ef572018-02-23 00:04:57777 layer_state_t* s = getLayerState(sc);
chaviw06178942017-07-27 17:25:59778 if (!s) {
Robert Carr4cdc58f2017-08-23 21:22:20779 mStatus = BAD_INDEX;
780 return *this;
chaviw06178942017-07-27 17:25:59781 }
chaviwf1961f72017-09-18 23:41:07782 s->what |= layer_state_t::eReparent;
chaviw06178942017-07-27 17:25:59783 s->parentHandleForChild = newParentHandle;
Marissa Wallc837b5e2018-10-12 17:04:44784
785 registerSurfaceControlForCallback(sc);
Robert Carr4cdc58f2017-08-23 21:22:20786 return *this;
chaviw06178942017-07-27 17:25:59787}
788
Robert Carr4cdc58f2017-08-23 21:22:20789SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setColor(
790 const sp<SurfaceControl>& sc,
791 const half3& color) {
chaviw763ef572018-02-23 00:04:57792 layer_state_t* s = getLayerState(sc);
Robert Carr9524cb32017-02-13 19:32:32793 if (!s) {
Robert Carr4cdc58f2017-08-23 21:22:20794 mStatus = BAD_INDEX;
795 return *this;
796 }
797 s->what |= layer_state_t::eColorChanged;
798 s->color = color;
Marissa Wallc837b5e2018-10-12 17:04:44799
800 registerSurfaceControlForCallback(sc);
Robert Carr4cdc58f2017-08-23 21:22:20801 return *this;
802}
803
Valerie Haudd0b7572019-01-29 22:59:27804SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setBackgroundColor(
805 const sp<SurfaceControl>& sc, const half3& color, float alpha, ui::Dataspace dataspace) {
Valerie Haued54efa2019-01-12 04:03:14806 layer_state_t* s = getLayerState(sc);
807 if (!s) {
808 mStatus = BAD_INDEX;
809 return *this;
810 }
811
Valerie Haudd0b7572019-01-29 22:59:27812 s->what |= layer_state_t::eBackgroundColorChanged;
813 s->color = color;
814 s->bgColorAlpha = alpha;
815 s->bgColorDataspace = dataspace;
Valerie Haued54efa2019-01-12 04:03:14816
817 registerSurfaceControlForCallback(sc);
818 return *this;
819}
820
Marissa Wall61c58622018-07-18 17:12:20821SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setTransform(
822 const sp<SurfaceControl>& sc, uint32_t transform) {
823 layer_state_t* s = getLayerState(sc);
824 if (!s) {
825 mStatus = BAD_INDEX;
826 return *this;
827 }
828 s->what |= layer_state_t::eTransformChanged;
829 s->transform = transform;
Marissa Wallc837b5e2018-10-12 17:04:44830
831 registerSurfaceControlForCallback(sc);
Marissa Wall61c58622018-07-18 17:12:20832 return *this;
833}
834
835SurfaceComposerClient::Transaction&
836SurfaceComposerClient::Transaction::setTransformToDisplayInverse(const sp<SurfaceControl>& sc,
837 bool transformToDisplayInverse) {
838 layer_state_t* s = getLayerState(sc);
839 if (!s) {
840 mStatus = BAD_INDEX;
841 return *this;
842 }
843 s->what |= layer_state_t::eTransformToDisplayInverseChanged;
844 s->transformToDisplayInverse = transformToDisplayInverse;
Marissa Wallc837b5e2018-10-12 17:04:44845
846 registerSurfaceControlForCallback(sc);
Marissa Wall61c58622018-07-18 17:12:20847 return *this;
848}
849
850SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setCrop(
851 const sp<SurfaceControl>& sc, const Rect& crop) {
852 layer_state_t* s = getLayerState(sc);
853 if (!s) {
854 mStatus = BAD_INDEX;
855 return *this;
856 }
857 s->what |= layer_state_t::eCropChanged;
858 s->crop = crop;
Marissa Wallc837b5e2018-10-12 17:04:44859
860 registerSurfaceControlForCallback(sc);
Marissa Wall61c58622018-07-18 17:12:20861 return *this;
862}
863
Marissa Wall861616d2018-10-22 19:52:23864SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setFrame(
865 const sp<SurfaceControl>& sc, const Rect& frame) {
866 layer_state_t* s = getLayerState(sc);
867 if (!s) {
868 mStatus = BAD_INDEX;
869 return *this;
870 }
871 s->what |= layer_state_t::eFrameChanged;
872 s->frame = frame;
873
874 registerSurfaceControlForCallback(sc);
875 return *this;
876}
877
Marissa Wall61c58622018-07-18 17:12:20878SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setBuffer(
879 const sp<SurfaceControl>& sc, const sp<GraphicBuffer>& buffer) {
880 layer_state_t* s = getLayerState(sc);
881 if (!s) {
882 mStatus = BAD_INDEX;
883 return *this;
884 }
Marissa Wallc837b5e2018-10-12 17:04:44885
Marissa Wall73411622019-01-25 18:45:41886 int32_t bufferId = BufferCache::getInstance().getId(buffer);
887 if (bufferId < 0) {
888 bufferId = BufferCache::getInstance().cache(buffer);
Marissa Wall61c58622018-07-18 17:12:20889
Marissa Wall73411622019-01-25 18:45:41890 s->what |= layer_state_t::eBufferChanged;
891 s->buffer = buffer;
Marissa Wallebc2c052019-01-17 03:16:55892 }
Marissa Wall73411622019-01-25 18:45:41893
Marissa Wallebc2c052019-01-17 03:16:55894 s->what |= layer_state_t::eCachedBufferChanged;
Marissa Wall73411622019-01-25 18:45:41895 s->cachedBuffer.token = BufferCache::getInstance().getToken();
Marissa Wallebc2c052019-01-17 03:16:55896 s->cachedBuffer.bufferId = bufferId;
897
898 registerSurfaceControlForCallback(sc);
899 return *this;
900}
901
Marissa Wall61c58622018-07-18 17:12:20902SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setAcquireFence(
903 const sp<SurfaceControl>& sc, const sp<Fence>& fence) {
904 layer_state_t* s = getLayerState(sc);
905 if (!s) {
906 mStatus = BAD_INDEX;
907 return *this;
908 }
909 s->what |= layer_state_t::eAcquireFenceChanged;
910 s->acquireFence = fence;
Marissa Wallc837b5e2018-10-12 17:04:44911
912 registerSurfaceControlForCallback(sc);
Marissa Wall61c58622018-07-18 17:12:20913 return *this;
914}
915
916SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setDataspace(
917 const sp<SurfaceControl>& sc, ui::Dataspace dataspace) {
918 layer_state_t* s = getLayerState(sc);
919 if (!s) {
920 mStatus = BAD_INDEX;
921 return *this;
922 }
923 s->what |= layer_state_t::eDataspaceChanged;
924 s->dataspace = dataspace;
Marissa Wallc837b5e2018-10-12 17:04:44925
926 registerSurfaceControlForCallback(sc);
Marissa Wall61c58622018-07-18 17:12:20927 return *this;
928}
929
930SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setHdrMetadata(
931 const sp<SurfaceControl>& sc, const HdrMetadata& hdrMetadata) {
932 layer_state_t* s = getLayerState(sc);
933 if (!s) {
934 mStatus = BAD_INDEX;
935 return *this;
936 }
937 s->what |= layer_state_t::eHdrMetadataChanged;
938 s->hdrMetadata = hdrMetadata;
Marissa Wallc837b5e2018-10-12 17:04:44939
940 registerSurfaceControlForCallback(sc);
Marissa Wall61c58622018-07-18 17:12:20941 return *this;
942}
943
944SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setSurfaceDamageRegion(
945 const sp<SurfaceControl>& sc, const Region& surfaceDamageRegion) {
946 layer_state_t* s = getLayerState(sc);
947 if (!s) {
948 mStatus = BAD_INDEX;
949 return *this;
950 }
951 s->what |= layer_state_t::eSurfaceDamageRegionChanged;
952 s->surfaceDamageRegion = surfaceDamageRegion;
Marissa Wallc837b5e2018-10-12 17:04:44953
954 registerSurfaceControlForCallback(sc);
Marissa Wall61c58622018-07-18 17:12:20955 return *this;
956}
957
958SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setApi(
959 const sp<SurfaceControl>& sc, int32_t api) {
960 layer_state_t* s = getLayerState(sc);
961 if (!s) {
962 mStatus = BAD_INDEX;
963 return *this;
964 }
965 s->what |= layer_state_t::eApiChanged;
966 s->api = api;
Marissa Wallc837b5e2018-10-12 17:04:44967
968 registerSurfaceControlForCallback(sc);
Marissa Wall61c58622018-07-18 17:12:20969 return *this;
970}
971
972SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setSidebandStream(
973 const sp<SurfaceControl>& sc, const sp<NativeHandle>& sidebandStream) {
974 layer_state_t* s = getLayerState(sc);
975 if (!s) {
976 mStatus = BAD_INDEX;
977 return *this;
978 }
979 s->what |= layer_state_t::eSidebandStreamChanged;
980 s->sidebandStream = sidebandStream;
Marissa Wallc837b5e2018-10-12 17:04:44981
982 registerSurfaceControlForCallback(sc);
983 return *this;
984}
985
Marissa Wall17b4e452018-12-27 00:32:34986SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setDesiredPresentTime(
987 nsecs_t desiredPresentTime) {
988 mDesiredPresentTime = desiredPresentTime;
989 return *this;
990}
991
Marissa Wallc837b5e2018-10-12 17:04:44992SurfaceComposerClient::Transaction&
993SurfaceComposerClient::Transaction::addTransactionCompletedCallback(
Marissa Walle2ffb422018-10-12 18:33:52994 TransactionCompletedCallbackTakesContext callback, void* callbackContext) {
Marissa Wallc837b5e2018-10-12 17:04:44995 auto listener = TransactionCompletedListener::getInstance();
996
Marissa Wall80d94ad2019-01-19 00:04:36997 auto callbackWithContext = std::bind(callback, callbackContext, std::placeholders::_1,
998 std::placeholders::_2, std::placeholders::_3);
999 const auto& surfaceControls =
1000 mListenerCallbacks[TransactionCompletedListener::getIInstance()].surfaceControls;
Marissa Wallc837b5e2018-10-12 17:04:441001
Marissa Wall80d94ad2019-01-19 00:04:361002 CallbackId callbackId = listener->addCallbackFunction(callbackWithContext, surfaceControls);
Marissa Wallc837b5e2018-10-12 17:04:441003
1004 mListenerCallbacks[TransactionCompletedListener::getIInstance()].callbackIds.emplace(
1005 callbackId);
Marissa Wall61c58622018-07-18 17:12:201006 return *this;
1007}
1008
Robert Carr4cdc58f2017-08-23 21:22:201009SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::detachChildren(
1010 const sp<SurfaceControl>& sc) {
chaviw763ef572018-02-23 00:04:571011 layer_state_t* s = getLayerState(sc);
Robert Carr4cdc58f2017-08-23 21:22:201012 if (!s) {
1013 mStatus = BAD_INDEX;
Robert Carr9524cb32017-02-13 19:32:321014 }
1015 s->what |= layer_state_t::eDetachChildren;
Marissa Wallc837b5e2018-10-12 17:04:441016
1017 registerSurfaceControlForCallback(sc);
Robert Carr4cdc58f2017-08-23 21:22:201018 return *this;
Robert Carr9524cb32017-02-13 19:32:321019}
1020
Robert Carr4cdc58f2017-08-23 21:22:201021SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setOverrideScalingMode(
1022 const sp<SurfaceControl>& sc, int32_t overrideScalingMode) {
chaviw763ef572018-02-23 00:04:571023 layer_state_t* s = getLayerState(sc);
Robert Carrc3574f72016-03-24 19:19:321024 if (!s) {
Robert Carr4cdc58f2017-08-23 21:22:201025 mStatus = BAD_INDEX;
1026 return *this;
Robert Carrc3574f72016-03-24 19:19:321027 }
1028
1029 switch (overrideScalingMode) {
1030 case NATIVE_WINDOW_SCALING_MODE_FREEZE:
1031 case NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW:
1032 case NATIVE_WINDOW_SCALING_MODE_SCALE_CROP:
1033 case NATIVE_WINDOW_SCALING_MODE_NO_SCALE_CROP:
1034 case -1:
1035 break;
1036 default:
1037 ALOGE("unknown scaling mode: %d",
1038 overrideScalingMode);
Robert Carr4cdc58f2017-08-23 21:22:201039 mStatus = BAD_VALUE;
1040 return *this;
Robert Carrc3574f72016-03-24 19:19:321041 }
1042
1043 s->what |= layer_state_t::eOverrideScalingModeChanged;
1044 s->overrideScalingMode = overrideScalingMode;
Marissa Wallc837b5e2018-10-12 17:04:441045
1046 registerSurfaceControlForCallback(sc);
Robert Carr4cdc58f2017-08-23 21:22:201047 return *this;
Robert Carrc3574f72016-03-24 19:19:321048}
1049
Robert Carr4cdc58f2017-08-23 21:22:201050SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setGeometryAppliesWithResize(
1051 const sp<SurfaceControl>& sc) {
chaviw763ef572018-02-23 00:04:571052 layer_state_t* s = getLayerState(sc);
Robert Carr82364e32016-05-15 18:27:471053 if (!s) {
Robert Carr4cdc58f2017-08-23 21:22:201054 mStatus = BAD_INDEX;
1055 return *this;
Robert Carr82364e32016-05-15 18:27:471056 }
Robert Carr99e27f02016-06-16 22:18:021057 s->what |= layer_state_t::eGeometryAppliesWithResize;
Marissa Wallc837b5e2018-10-12 17:04:441058
1059 registerSurfaceControlForCallback(sc);
Robert Carr4cdc58f2017-08-23 21:22:201060 return *this;
Robert Carr82364e32016-05-15 18:27:471061}
1062
Robert Carr2c358bf2018-08-08 22:58:151063#ifndef NO_INPUT
1064SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setInputWindowInfo(
1065 const sp<SurfaceControl>& sc,
1066 const InputWindowInfo& info) {
1067 layer_state_t* s = getLayerState(sc);
1068 if (!s) {
1069 mStatus = BAD_INDEX;
1070 return *this;
1071 }
1072 s->inputInfo = info;
1073 s->what |= layer_state_t::eInputInfoChanged;
1074 return *this;
1075}
chaviw273171b2018-12-26 19:46:301076
1077SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::transferTouchFocus(
1078 const sp<IBinder>& fromToken, const sp<IBinder>& toToken) {
1079 InputWindowCommands::TransferTouchFocusCommand transferTouchFocusCommand;
1080 transferTouchFocusCommand.fromToken = fromToken;
1081 transferTouchFocusCommand.toToken = toToken;
1082 mInputWindowCommands.transferTouchFocusCommands.emplace_back(transferTouchFocusCommand);
1083 return *this;
1084}
1085
chaviwa911b102019-02-14 18:18:331086SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::syncInputWindows() {
1087 mInputWindowCommands.syncInputWindows = true;
1088 return *this;
1089}
1090
Robert Carr2c358bf2018-08-08 22:58:151091#endif
1092
Peiyong Lind3788632018-09-18 23:01:311093SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setColorTransform(
1094 const sp<SurfaceControl>& sc, const mat3& matrix, const vec3& translation) {
1095 layer_state_t* s = getLayerState(sc);
1096 if (!s) {
1097 mStatus = BAD_INDEX;
1098 return *this;
1099 }
1100 s->what |= layer_state_t::eColorTransformChanged;
1101 s->colorTransform = mat4(matrix, translation);
Marissa Wallc837b5e2018-10-12 17:04:441102
1103 registerSurfaceControlForCallback(sc);
Peiyong Lind3788632018-09-18 23:01:311104 return *this;
1105}
1106
Robert Carrfb4d58b2019-01-15 17:21:271107SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setGeometry(
1108 const sp<SurfaceControl>& sc, const Rect& source, const Rect& dst, int transform) {
1109 setCrop_legacy(sc, source);
1110
1111 int x = dst.left;
1112 int y = dst.top;
1113 float xScale = dst.getWidth() / static_cast<float>(source.getWidth());
1114 float yScale = dst.getHeight() / static_cast<float>(source.getHeight());
1115 float matrix[4] = {1, 0, 0, 1};
1116
1117 switch (transform) {
1118 case NATIVE_WINDOW_TRANSFORM_FLIP_H:
1119 matrix[0] = -xScale; matrix[1] = 0;
1120 matrix[2] = 0; matrix[3] = yScale;
1121 x += source.getWidth();
1122 break;
1123 case NATIVE_WINDOW_TRANSFORM_FLIP_V:
1124 matrix[0] = xScale; matrix[1] = 0;
1125 matrix[2] = 0; matrix[3] = -yScale;
1126 y += source.getHeight();
1127 break;
1128 case NATIVE_WINDOW_TRANSFORM_ROT_90:
1129 matrix[0] = 0; matrix[1] = -yScale;
1130 matrix[2] = xScale; matrix[3] = 0;
1131 x += source.getHeight();
1132 break;
1133 case NATIVE_WINDOW_TRANSFORM_ROT_180:
1134 matrix[0] = -xScale; matrix[1] = 0;
1135 matrix[2] = 0; matrix[3] = -yScale;
1136 x += source.getWidth();
1137 y += source.getHeight();
1138 break;
1139 case NATIVE_WINDOW_TRANSFORM_ROT_270:
1140 matrix[0] = 0; matrix[1] = yScale;
1141 matrix[2] = -xScale; matrix[3] = 0;
1142 y += source.getWidth();
1143 break;
1144 default:
1145 matrix[0] = xScale; matrix[1] = 0;
1146 matrix[2] = 0; matrix[3] = yScale;
1147 break;
1148 }
1149 setMatrix(sc, matrix[0], matrix[1], matrix[2], matrix[3]);
1150 setPosition(sc, x, y);
1151
1152 return *this;
1153}
1154
Mathias Agopian698c0872011-06-29 02:09:311155// ---------------------------------------------------------------------------
1156
chaviw763ef572018-02-23 00:04:571157DisplayState& SurfaceComposerClient::Transaction::getDisplayState(const sp<IBinder>& token) {
Mathias Agopiane57f2922012-08-09 23:29:121158 DisplayState s;
1159 s.token = token;
1160 ssize_t index = mDisplayStates.indexOf(s);
1161 if (index < 0) {
1162 // we don't have it, add an initialized layer_state to our list
1163 s.what = 0;
1164 index = mDisplayStates.add(s);
1165 }
Dan Stozad723bd72014-11-18 18:24:031166 return mDisplayStates.editItemAt(static_cast<size_t>(index));
Mathias Agopiane57f2922012-08-09 23:29:121167}
1168
Robert Carr4cdc58f2017-08-23 21:22:201169status_t SurfaceComposerClient::Transaction::setDisplaySurface(const sp<IBinder>& token,
1170 const sp<IGraphicBufferProducer>& bufferProducer) {
Pablo Ceballoseddbef82016-09-01 18:21:211171 if (bufferProducer.get() != nullptr) {
1172 // Make sure that composition can never be stalled by a virtual display
1173 // consumer that isn't processing buffers fast enough.
1174 status_t err = bufferProducer->setAsyncMode(true);
1175 if (err != NO_ERROR) {
1176 ALOGE("Composer::setDisplaySurface Failed to enable async mode on the "
1177 "BufferQueue. This BufferQueue cannot be used for virtual "
1178 "display. (%d)", err);
1179 return err;
1180 }
Pablo Ceballos1aad24c2016-08-04 17:24:221181 }
chaviw763ef572018-02-23 00:04:571182 DisplayState& s(getDisplayState(token));
Andy McFadden2adaf042012-12-18 17:49:451183 s.surface = bufferProducer;
Mathias Agopiane57f2922012-08-09 23:29:121184 s.what |= DisplayState::eSurfaceChanged;
Pablo Ceballos1aad24c2016-08-04 17:24:221185 return NO_ERROR;
Mathias Agopiane57f2922012-08-09 23:29:121186}
1187
Robert Carr4cdc58f2017-08-23 21:22:201188void SurfaceComposerClient::Transaction::setDisplayLayerStack(const sp<IBinder>& token,
Mathias Agopiane57f2922012-08-09 23:29:121189 uint32_t layerStack) {
chaviw763ef572018-02-23 00:04:571190 DisplayState& s(getDisplayState(token));
Mathias Agopiane57f2922012-08-09 23:29:121191 s.layerStack = layerStack;
1192 s.what |= DisplayState::eLayerStackChanged;
1193}
1194
Robert Carr4cdc58f2017-08-23 21:22:201195void SurfaceComposerClient::Transaction::setDisplayProjection(const sp<IBinder>& token,
Mathias Agopian00e8c7a2012-09-05 02:30:461196 uint32_t orientation,
1197 const Rect& layerStackRect,
1198 const Rect& displayRect) {
chaviw763ef572018-02-23 00:04:571199 DisplayState& s(getDisplayState(token));
Mathias Agopiane57f2922012-08-09 23:29:121200 s.orientation = orientation;
Mathias Agopian00e8c7a2012-09-05 02:30:461201 s.viewport = layerStackRect;
1202 s.frame = displayRect;
1203 s.what |= DisplayState::eDisplayProjectionChanged;
Jorim Jaggi092123c2016-04-13 01:40:351204 mForceSynchronous = true; // TODO: do we actually still need this?
Mathias Agopiane57f2922012-08-09 23:29:121205}
1206
Robert Carr4cdc58f2017-08-23 21:22:201207void SurfaceComposerClient::Transaction::setDisplaySize(const sp<IBinder>& token, uint32_t width, uint32_t height) {
chaviw763ef572018-02-23 00:04:571208 DisplayState& s(getDisplayState(token));
Michael Wright1f6078a2014-06-26 23:01:021209 s.width = width;
1210 s.height = height;
1211 s.what |= DisplayState::eDisplaySizeChanged;
1212}
1213
Mathias Agopiane57f2922012-08-09 23:29:121214// ---------------------------------------------------------------------------
1215
The Android Open Source Projectedbf3b62009-03-04 03:31:441216SurfaceComposerClient::SurfaceComposerClient()
Robert Carr4cdc58f2017-08-23 21:22:201217 : mStatus(NO_INIT)
The Android Open Source Projectedbf3b62009-03-04 03:31:441218{
The Android Open Source Projectedbf3b62009-03-04 03:31:441219}
1220
Jorim Jaggif3cf4bc2017-11-30 13:19:231221SurfaceComposerClient::SurfaceComposerClient(const sp<ISurfaceComposerClient>& client)
1222 : mStatus(NO_ERROR), mClient(client)
1223{
1224}
1225
Mathias Agopian698c0872011-06-29 02:09:311226void SurfaceComposerClient::onFirstRef() {
Robert Carr4cdc58f2017-08-23 21:22:201227 sp<ISurfaceComposer> sf(ComposerService::getComposerService());
Yi Kong48a619f2018-06-05 23:34:591228 if (sf != nullptr && mStatus == NO_INIT) {
Robert Carr1db73f62016-12-21 20:58:511229 sp<ISurfaceComposerClient> conn;
Robert Carrb89ea9d2018-12-10 21:01:141230 conn = sf->createConnection();
Yi Kong48a619f2018-06-05 23:34:591231 if (conn != nullptr) {
Mathias Agopiand4784a32010-05-28 02:41:151232 mClient = conn;
Mathias Agopiand4784a32010-05-28 02:41:151233 mStatus = NO_ERROR;
1234 }
1235 }
The Android Open Source Projectedbf3b62009-03-04 03:31:441236}
1237
Mathias Agopian698c0872011-06-29 02:09:311238SurfaceComposerClient::~SurfaceComposerClient() {
Mathias Agopian631f3582010-05-26 00:51:341239 dispose();
1240}
Mathias Agopiandd3423c2009-09-23 22:44:051241
Mathias Agopian698c0872011-06-29 02:09:311242status_t SurfaceComposerClient::initCheck() const {
The Android Open Source Projectedbf3b62009-03-04 03:31:441243 return mStatus;
1244}
1245
Mathias Agopian698c0872011-06-29 02:09:311246sp<IBinder> SurfaceComposerClient::connection() const {
Marco Nelissen2ea926b2014-11-14 16:01:011247 return IInterface::asBinder(mClient);
The Android Open Source Projectedbf3b62009-03-04 03:31:441248}
1249
Mathias Agopiand4784a32010-05-28 02:41:151250status_t SurfaceComposerClient::linkToComposerDeath(
1251 const sp<IBinder::DeathRecipient>& recipient,
Mathias Agopian698c0872011-06-29 02:09:311252 void* cookie, uint32_t flags) {
Robert Carr4cdc58f2017-08-23 21:22:201253 sp<ISurfaceComposer> sf(ComposerService::getComposerService());
1254 return IInterface::asBinder(sf)->linkToDeath(recipient, cookie, flags);
The Android Open Source Projectedbf3b62009-03-04 03:31:441255}
1256
Mathias Agopian698c0872011-06-29 02:09:311257void SurfaceComposerClient::dispose() {
The Android Open Source Projectedbf3b62009-03-04 03:31:441258 // this can be called more than once.
Mathias Agopian7e27f052010-05-28 21:22:231259 sp<ISurfaceComposerClient> client;
Mathias Agopiand4784a32010-05-28 02:41:151260 Mutex::Autolock _lm(mLock);
Yi Kong48a619f2018-06-05 23:34:591261 if (mClient != nullptr) {
Mathias Agopiand4784a32010-05-28 02:41:151262 client = mClient; // hold ref while lock is held
1263 mClient.clear();
The Android Open Source Projectedbf3b62009-03-04 03:31:441264 }
Mathias Agopiand4784a32010-05-28 02:41:151265 mStatus = NO_INIT;
The Android Open Source Projectedbf3b62009-03-04 03:31:441266}
1267
Evan Rosky1f6d6d52018-12-06 18:47:261268sp<SurfaceControl> SurfaceComposerClient::createSurface(const String8& name, uint32_t w, uint32_t h,
1269 PixelFormat format, uint32_t flags,
1270 SurfaceControl* parent,
1271 LayerMetadata metadata) {
Robert Carr3b382ed2018-03-14 20:49:411272 sp<SurfaceControl> s;
Evan Rosky1f6d6d52018-12-06 18:47:261273 createSurfaceChecked(name, w, h, format, &s, flags, parent, std::move(metadata));
Robert Carr3b382ed2018-03-14 20:49:411274 return s;
1275}
1276
Marissa Wall35187b32019-01-08 18:08:521277sp<SurfaceControl> SurfaceComposerClient::createWithSurfaceParent(const String8& name, uint32_t w,
1278 uint32_t h, PixelFormat format,
1279 uint32_t flags, Surface* parent,
Evan Rosky1f6d6d52018-12-06 18:47:261280 LayerMetadata metadata) {
Marissa Wall35187b32019-01-08 18:08:521281 sp<SurfaceControl> sur;
1282 status_t err = mStatus;
1283
1284 if (mStatus == NO_ERROR) {
1285 sp<IBinder> handle;
1286 sp<IGraphicBufferProducer> parentGbp = parent->getIGraphicBufferProducer();
1287 sp<IGraphicBufferProducer> gbp;
1288
Evan Rosky1f6d6d52018-12-06 18:47:261289 err = mClient->createWithSurfaceParent(name, w, h, format, flags, parentGbp,
1290 std::move(metadata), &handle, &gbp);
Marissa Wall35187b32019-01-08 18:08:521291 ALOGE_IF(err, "SurfaceComposerClient::createWithSurfaceParent error %s", strerror(-err));
1292 if (err == NO_ERROR) {
1293 return new SurfaceControl(this, handle, gbp, true /* owned */);
1294 }
1295 }
1296 return nullptr;
1297}
1298
Evan Rosky1f6d6d52018-12-06 18:47:261299status_t SurfaceComposerClient::createSurfaceChecked(const String8& name, uint32_t w, uint32_t h,
1300 PixelFormat format,
1301 sp<SurfaceControl>* outSurface, uint32_t flags,
1302 SurfaceControl* parent,
1303 LayerMetadata metadata) {
Mathias Agopian4d9b8222013-03-13 00:11:481304 sp<SurfaceControl> sur;
Robert Carr740eaf02018-03-27 19:59:181305 status_t err = mStatus;
Robert Carr3b382ed2018-03-14 20:49:411306
Mathias Agopian698c0872011-06-29 02:09:311307 if (mStatus == NO_ERROR) {
Mathias Agopian4d9b8222013-03-13 00:11:481308 sp<IBinder> handle;
Robert Carr1f0a16a2016-10-24 23:27:391309 sp<IBinder> parentHandle;
Mathias Agopian4d9b8222013-03-13 00:11:481310 sp<IGraphicBufferProducer> gbp;
Robert Carr1f0a16a2016-10-24 23:27:391311
1312 if (parent != nullptr) {
1313 parentHandle = parent->getHandle();
1314 }
Evan Rosky1f6d6d52018-12-06 18:47:261315
1316 err = mClient->createSurface(name, w, h, format, flags, parentHandle, std::move(metadata),
1317 &handle, &gbp);
Mathias Agopian4d9b8222013-03-13 00:11:481318 ALOGE_IF(err, "SurfaceComposerClient::createSurface error %s", strerror(-err));
1319 if (err == NO_ERROR) {
Robert Carr3b382ed2018-03-14 20:49:411320 *outSurface = new SurfaceControl(this, handle, gbp, true /* owned */);
Mathias Agopian698c0872011-06-29 02:09:311321 }
1322 }
Robert Carr3b382ed2018-03-14 20:49:411323 return err;
Mathias Agopian698c0872011-06-29 02:09:311324}
1325
Svetoslavd85084b2014-03-20 17:28:311326status_t SurfaceComposerClient::clearLayerFrameStats(const sp<IBinder>& token) const {
1327 if (mStatus != NO_ERROR) {
1328 return mStatus;
1329 }
1330 return mClient->clearLayerFrameStats(token);
1331}
1332
1333status_t SurfaceComposerClient::getLayerFrameStats(const sp<IBinder>& token,
1334 FrameStats* outStats) const {
1335 if (mStatus != NO_ERROR) {
1336 return mStatus;
1337 }
1338 return mClient->getLayerFrameStats(token, outStats);
1339}
1340
Mathias Agopian698c0872011-06-29 02:09:311341// ----------------------------------------------------------------------------
1342
Sahil Dhanjuc1ba5c42016-06-08 03:09:201343status_t SurfaceComposerClient::enableVSyncInjections(bool enable) {
Robert Carr4cdc58f2017-08-23 21:22:201344 sp<ISurfaceComposer> sf(ComposerService::getComposerService());
1345 return sf->enableVSyncInjections(enable);
Sahil Dhanjuc1ba5c42016-06-08 03:09:201346}
1347
1348status_t SurfaceComposerClient::injectVSync(nsecs_t when) {
Robert Carr4cdc58f2017-08-23 21:22:201349 sp<ISurfaceComposer> sf(ComposerService::getComposerService());
1350 return sf->injectVSync(when);
Sahil Dhanjuc1ba5c42016-06-08 03:09:201351}
1352
Dan Stoza7f7da322014-05-02 22:26:251353status_t SurfaceComposerClient::getDisplayConfigs(
1354 const sp<IBinder>& display, Vector<DisplayInfo>* configs)
The Android Open Source Projectedbf3b62009-03-04 03:31:441355{
Dan Stoza7f7da322014-05-02 22:26:251356 return ComposerService::getComposerService()->getDisplayConfigs(display, configs);
1357}
1358
1359status_t SurfaceComposerClient::getDisplayInfo(const sp<IBinder>& display,
1360 DisplayInfo* info) {
1361 Vector<DisplayInfo> configs;
1362 status_t result = getDisplayConfigs(display, &configs);
1363 if (result != NO_ERROR) {
1364 return result;
1365 }
1366
1367 int activeId = getActiveConfig(display);
1368 if (activeId < 0) {
1369 ALOGE("No active configuration found");
1370 return NAME_NOT_FOUND;
1371 }
1372
Dan Stozad723bd72014-11-18 18:24:031373 *info = configs[static_cast<size_t>(activeId)];
Dan Stoza7f7da322014-05-02 22:26:251374 return NO_ERROR;
1375}
1376
1377int SurfaceComposerClient::getActiveConfig(const sp<IBinder>& display) {
1378 return ComposerService::getComposerService()->getActiveConfig(display);
1379}
1380
1381status_t SurfaceComposerClient::setActiveConfig(const sp<IBinder>& display, int id) {
1382 return ComposerService::getComposerService()->setActiveConfig(display, id);
The Android Open Source Projectedbf3b62009-03-04 03:31:441383}
1384
Michael Wright28f24d02016-07-12 20:30:531385status_t SurfaceComposerClient::getDisplayColorModes(const sp<IBinder>& display,
Peiyong Lina52f0292018-03-15 00:26:311386 Vector<ColorMode>* outColorModes) {
Michael Wright28f24d02016-07-12 20:30:531387 return ComposerService::getComposerService()->getDisplayColorModes(display, outColorModes);
1388}
1389
Daniel Solomon42d04562019-01-21 05:03:191390status_t SurfaceComposerClient::getDisplayNativePrimaries(const sp<IBinder>& display,
1391 ui::DisplayPrimaries& outPrimaries) {
1392 return ComposerService::getComposerService()->getDisplayNativePrimaries(display, outPrimaries);
1393}
1394
Peiyong Lina52f0292018-03-15 00:26:311395ColorMode SurfaceComposerClient::getActiveColorMode(const sp<IBinder>& display) {
Michael Wright28f24d02016-07-12 20:30:531396 return ComposerService::getComposerService()->getActiveColorMode(display);
1397}
1398
1399status_t SurfaceComposerClient::setActiveColorMode(const sp<IBinder>& display,
Peiyong Lina52f0292018-03-15 00:26:311400 ColorMode colorMode) {
Michael Wright28f24d02016-07-12 20:30:531401 return ComposerService::getComposerService()->setActiveColorMode(display, colorMode);
1402}
1403
Prashant Malani2c9b11f2014-05-25 08:36:311404void SurfaceComposerClient::setDisplayPowerMode(const sp<IBinder>& token,
1405 int mode) {
1406 ComposerService::getComposerService()->setPowerMode(token, mode);
Jeff Brown2a09bb32012-10-09 02:13:571407}
1408
Peiyong Linc6780972018-10-28 22:24:081409status_t SurfaceComposerClient::getCompositionPreference(
1410 ui::Dataspace* defaultDataspace, ui::PixelFormat* defaultPixelFormat,
1411 ui::Dataspace* wideColorGamutDataspace, ui::PixelFormat* wideColorGamutPixelFormat) {
1412 return ComposerService::getComposerService()
1413 ->getCompositionPreference(defaultDataspace, defaultPixelFormat,
1414 wideColorGamutDataspace, wideColorGamutPixelFormat);
Peiyong Lin0256f722018-08-31 22:45:101415}
1416
Peiyong Lin08d10512019-01-16 21:27:351417bool SurfaceComposerClient::getProtectedContentSupport() {
1418 bool supported = false;
1419 ComposerService::getComposerService()->getProtectedContentSupport(&supported);
1420 return supported;
1421}
1422
Svetoslavd85084b2014-03-20 17:28:311423status_t SurfaceComposerClient::clearAnimationFrameStats() {
1424 return ComposerService::getComposerService()->clearAnimationFrameStats();
1425}
1426
1427status_t SurfaceComposerClient::getAnimationFrameStats(FrameStats* outStats) {
1428 return ComposerService::getComposerService()->getAnimationFrameStats(outStats);
1429}
1430
Dan Stozac4f471e2016-03-24 16:31:081431status_t SurfaceComposerClient::getHdrCapabilities(const sp<IBinder>& display,
1432 HdrCapabilities* outCapabilities) {
1433 return ComposerService::getComposerService()->getHdrCapabilities(display,
1434 outCapabilities);
1435}
1436
Kevin DuBois9c0a1762018-10-16 20:32:311437status_t SurfaceComposerClient::getDisplayedContentSamplingAttributes(const sp<IBinder>& display,
1438 ui::PixelFormat* outFormat,
1439 ui::Dataspace* outDataspace,
1440 uint8_t* outComponentMask) {
1441 return ComposerService::getComposerService()
1442 ->getDisplayedContentSamplingAttributes(display, outFormat, outDataspace,
1443 outComponentMask);
1444}
1445
Kevin DuBois74e53772018-11-19 18:52:381446status_t SurfaceComposerClient::setDisplayContentSamplingEnabled(const sp<IBinder>& display,
1447 bool enable, uint8_t componentMask,
1448 uint64_t maxFrames) {
1449 return ComposerService::getComposerService()->setDisplayContentSamplingEnabled(display, enable,
1450 componentMask,
1451 maxFrames);
1452}
1453
Kevin DuBois1d4249a2018-08-29 17:45:141454status_t SurfaceComposerClient::getDisplayedContentSample(const sp<IBinder>& display,
1455 uint64_t maxFrames, uint64_t timestamp,
1456 DisplayedFrameStats* outStats) {
1457 return ComposerService::getComposerService()->getDisplayedContentSample(display, maxFrames,
1458 timestamp, outStats);
1459}
Marissa Wall35187b32019-01-08 18:08:521460
Peiyong Lin4f3fddf2019-01-25 01:21:241461status_t SurfaceComposerClient::isWideColorDisplay(const sp<IBinder>& display,
1462 bool* outIsWideColorDisplay) {
1463 return ComposerService::getComposerService()->isWideColorDisplay(display,
1464 outIsWideColorDisplay);
1465}
1466
Mathias Agopian698c0872011-06-29 02:09:311467// ----------------------------------------------------------------------------
The Android Open Source Projectedbf3b62009-03-04 03:31:441468
Peiyong Lin0e003c92018-09-17 18:09:511469status_t ScreenshotClient::capture(const sp<IBinder>& display, const ui::Dataspace reqDataSpace,
1470 const ui::PixelFormat reqPixelFormat, Rect sourceCrop,
1471 uint32_t reqWidth, uint32_t reqHeight, bool useIdentityTransform,
1472 uint32_t rotation, sp<GraphicBuffer>* outBuffer) {
Mathias Agopian2a9fc492013-03-01 21:42:571473 sp<ISurfaceComposer> s(ComposerService::getComposerService());
Yi Kong48a619f2018-06-05 23:34:591474 if (s == nullptr) return NO_INIT;
Peiyong Lin0e003c92018-09-17 18:09:511475 status_t ret = s->captureScreen(display, outBuffer, reqDataSpace, reqPixelFormat, sourceCrop,
1476 reqWidth, reqHeight, useIdentityTransform,
Chavi Weingarten40482ff2017-11-30 01:51:401477 static_cast<ISurfaceComposer::Rotation>(rotation));
Robert Carr673134e2017-01-10 03:48:381478 if (ret != NO_ERROR) {
1479 return ret;
1480 }
Robert Carr673134e2017-01-10 03:48:381481 return ret;
1482}
1483
Peiyong Lin0e003c92018-09-17 18:09:511484status_t ScreenshotClient::captureLayers(const sp<IBinder>& layerHandle,
1485 const ui::Dataspace reqDataSpace,
1486 const ui::PixelFormat reqPixelFormat, Rect sourceCrop,
Chavi Weingarten40482ff2017-11-30 01:51:401487 float frameScale, sp<GraphicBuffer>* outBuffer) {
chaviwa76b2712017-09-20 19:02:261488 sp<ISurfaceComposer> s(ComposerService::getComposerService());
Yi Kong48a619f2018-06-05 23:34:591489 if (s == nullptr) return NO_INIT;
Peiyong Lin0e003c92018-09-17 18:09:511490 status_t ret = s->captureLayers(layerHandle, outBuffer, reqDataSpace, reqPixelFormat,
1491 sourceCrop, frameScale, false /* childrenOnly */);
Robert Carr578038f2018-03-09 20:25:241492 return ret;
1493}
1494
Peiyong Lin0e003c92018-09-17 18:09:511495status_t ScreenshotClient::captureChildLayers(const sp<IBinder>& layerHandle,
1496 const ui::Dataspace reqDataSpace,
1497 const ui::PixelFormat reqPixelFormat, Rect sourceCrop,
Robert Carr578038f2018-03-09 20:25:241498 float frameScale, sp<GraphicBuffer>* outBuffer) {
1499 sp<ISurfaceComposer> s(ComposerService::getComposerService());
Yi Kong48a619f2018-06-05 23:34:591500 if (s == nullptr) return NO_INIT;
Peiyong Lin0e003c92018-09-17 18:09:511501 status_t ret = s->captureLayers(layerHandle, outBuffer, reqDataSpace, reqPixelFormat,
1502 sourceCrop, frameScale, true /* childrenOnly */);
chaviw7206d492017-11-11 00:16:121503 return ret;
chaviwa76b2712017-09-20 19:02:261504}
Mathias Agopian74c40c02010-09-29 20:02:361505// ----------------------------------------------------------------------------
The Android Open Source Projectedbf3b62009-03-04 03:31:441506}; // namespace android