blob: fd277f1beb2678f990287e97cd604a5b32bd1caf [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 Agopiand4784a32010-05-28 02:41:1524#include <utils/Singleton.h>
Mathias Agopiana67932f2011-04-20 21:20:5925#include <utils/SortedVector.h>
26#include <utils/String8.h>
27#include <utils/threads.h>
The Android Open Source Projectedbf3b62009-03-04 03:31:4428
Mathias Agopian9cce3252010-02-10 01:46:3729#include <binder/IMemory.h>
Mathias Agopiana67932f2011-04-20 21:20:5930#include <binder/IServiceManager.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 Carr0d480722017-01-11 00:42:5441#include <gui/Surface.h>
Mathias Agopian90ac7992012-02-26 02:48:3542#include <gui/SurfaceComposerClient.h>
The Android Open Source Projectedbf3b62009-03-04 03:31:4443
Mathias Agopian41f673c2011-11-18 01:48:3544#include <private/gui/ComposerService.h>
Mathias Agopian90ac7992012-02-26 02:48:3545#include <private/gui/LayerState.h>
The Android Open Source Projectedbf3b62009-03-04 03:31:4446
47namespace android {
The Android Open Source Projectedbf3b62009-03-04 03:31:4448// ---------------------------------------------------------------------------
49
Mathias Agopian7e27f052010-05-28 21:22:2350ANDROID_SINGLETON_STATIC_INSTANCE(ComposerService);
51
Mathias Agopianb7e930d2010-06-01 22:12:5852ComposerService::ComposerService()
53: Singleton<ComposerService>() {
Andy McFadden6652b3e2012-09-07 01:45:5654 Mutex::Autolock _l(mLock);
55 connectLocked();
56}
57
58void ComposerService::connectLocked() {
Mathias Agopianb7e930d2010-06-01 22:12:5859 const String16 name("SurfaceFlinger");
60 while (getService(name, &mComposerService) != NO_ERROR) {
61 usleep(250000);
62 }
Andy McFadden6652b3e2012-09-07 01:45:5663 assert(mComposerService != NULL);
64
65 // Create the death listener.
66 class DeathObserver : public IBinder::DeathRecipient {
67 ComposerService& mComposerService;
68 virtual void binderDied(const wp<IBinder>& who) {
69 ALOGW("ComposerService remote (surfaceflinger) died [%p]",
70 who.unsafe_get());
71 mComposerService.composerServiceDied();
72 }
73 public:
Chih-Hung Hsiehe2347b72016-04-25 22:41:0574 explicit DeathObserver(ComposerService& mgr) : mComposerService(mgr) { }
Andy McFadden6652b3e2012-09-07 01:45:5675 };
76
77 mDeathObserver = new DeathObserver(*const_cast<ComposerService*>(this));
Marco Nelissen2ea926b2014-11-14 16:01:0178 IInterface::asBinder(mComposerService)->linkToDeath(mDeathObserver);
Mathias Agopianb7e930d2010-06-01 22:12:5879}
80
Andy McFadden6652b3e2012-09-07 01:45:5681/*static*/ sp<ISurfaceComposer> ComposerService::getComposerService() {
82 ComposerService& instance = ComposerService::getInstance();
83 Mutex::Autolock _l(instance.mLock);
84 if (instance.mComposerService == NULL) {
85 ComposerService::getInstance().connectLocked();
86 assert(instance.mComposerService != NULL);
87 ALOGD("ComposerService reconnected");
88 }
89 return instance.mComposerService;
90}
91
92void ComposerService::composerServiceDied()
93{
94 Mutex::Autolock _l(mLock);
95 mComposerService = NULL;
96 mDeathObserver = NULL;
Mathias Agopianb7e930d2010-06-01 22:12:5897}
98
Mathias Agopian7e27f052010-05-28 21:22:2399// ---------------------------------------------------------------------------
100
Mathias Agopian698c0872011-06-29 02:09:31101static inline
Mathias Agopiane57f2922012-08-09 23:29:12102int compare_type(const ComposerState& lhs, const ComposerState& rhs) {
Mathias Agopian698c0872011-06-29 02:09:31103 if (lhs.client < rhs.client) return -1;
104 if (lhs.client > rhs.client) return 1;
105 if (lhs.state.surface < rhs.state.surface) return -1;
106 if (lhs.state.surface > rhs.state.surface) return 1;
107 return 0;
108}
109
Mathias Agopiane57f2922012-08-09 23:29:12110static inline
111int compare_type(const DisplayState& lhs, const DisplayState& rhs) {
112 return compare_type(lhs.token, rhs.token);
113}
114
Mathias Agopian7e27f052010-05-28 21:22:23115class Composer : public Singleton<Composer>
116{
Mathias Agopiand4784a32010-05-28 02:41:15117 friend class Singleton<Composer>;
118
Mathias Agopian698c0872011-06-29 02:09:31119 mutable Mutex mLock;
Mathias Agopiane57f2922012-08-09 23:29:12120 SortedVector<ComposerState> mComposerStates;
121 SortedVector<DisplayState > mDisplayStates;
Jamie Gennis28378392011-10-13 00:39:00122 uint32_t mForceSynchronous;
Jeff Brownf3f7db62012-08-31 09:18:38123 uint32_t mTransactionNestCount;
Jamie Gennis2d5e2302012-10-16 01:24:43124 bool mAnimation;
Mathias Agopian698c0872011-06-29 02:09:31125
Jamie Gennisb8d69a52011-10-10 22:48:06126 Composer() : Singleton<Composer>(),
Jeff Brownf3f7db62012-08-31 09:18:38127 mForceSynchronous(0), mTransactionNestCount(0),
Jamie Gennis2d5e2302012-10-16 01:24:43128 mAnimation(false)
Jamie Gennis28378392011-10-13 00:39:00129 { }
Mathias Agopian698c0872011-06-29 02:09:31130
Jeff Brownf3f7db62012-08-31 09:18:38131 void openGlobalTransactionImpl();
Jamie Gennis28378392011-10-13 00:39:00132 void closeGlobalTransactionImpl(bool synchronous);
Jamie Gennis2d5e2302012-10-16 01:24:43133 void setAnimationTransactionImpl();
Sahil Dhanjuc1ba5c42016-06-08 03:09:20134 status_t enableVSyncInjectionsImpl(bool enable);
135 status_t injectVSyncImpl(nsecs_t when);
Mathias Agopian698c0872011-06-29 02:09:31136
137 layer_state_t* getLayerStateLocked(
Mathias Agopianac9fa422013-02-12 00:40:36138 const sp<SurfaceComposerClient>& client, const sp<IBinder>& id);
Mathias Agopian698c0872011-06-29 02:09:31139
Mathias Agopiane57f2922012-08-09 23:29:12140 DisplayState& getDisplayStateLocked(const sp<IBinder>& token);
141
Mathias Agopiand4784a32010-05-28 02:41:15142public:
Jamie Gennisdd3cb842012-10-20 01:19:11143 sp<IBinder> createDisplay(const String8& displayName, bool secure);
Jesse Hall6c913be2013-08-08 19:15:49144 void destroyDisplay(const sp<IBinder>& display);
Jeff Brown9d4e3d22012-08-25 03:00:51145 sp<IBinder> getBuiltInDisplay(int32_t id);
Mathias Agopian698c0872011-06-29 02:09:31146
Mathias Agopianac9fa422013-02-12 00:40:36147 status_t setPosition(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
Mathias Agopian41b6aab2011-08-31 01:51:54148 float x, float y);
Mathias Agopianac9fa422013-02-12 00:40:36149 status_t setSize(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
Mathias Agopian698c0872011-06-29 02:09:31150 uint32_t w, uint32_t h);
Mathias Agopianac9fa422013-02-12 00:40:36151 status_t setLayer(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
Robert Carrae060832016-11-28 18:51:00152 int32_t z);
Mathias Agopianac9fa422013-02-12 00:40:36153 status_t setFlags(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
Mathias Agopian698c0872011-06-29 02:09:31154 uint32_t flags, uint32_t mask);
155 status_t setTransparentRegionHint(
Mathias Agopianac9fa422013-02-12 00:40:36156 const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
Mathias Agopian698c0872011-06-29 02:09:31157 const Region& transparentRegion);
Mathias Agopianac9fa422013-02-12 00:40:36158 status_t setAlpha(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
Mathias Agopian698c0872011-06-29 02:09:31159 float alpha);
Mathias Agopianac9fa422013-02-12 00:40:36160 status_t setMatrix(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
Mathias Agopian698c0872011-06-29 02:09:31161 float dsdx, float dtdx, float dsdy, float dtdy);
Jamie Gennisb8d69a52011-10-10 22:48:06162 status_t setOrientation(int orientation);
Mathias Agopianac9fa422013-02-12 00:40:36163 status_t setCrop(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
Jamie Gennisf15a83f2012-05-11 03:43:55164 const Rect& crop);
Pablo Ceballosacbe6782016-03-04 17:54:21165 status_t setFinalCrop(const sp<SurfaceComposerClient>& client,
166 const sp<IBinder>& id, const Rect& crop);
Mathias Agopian87855782012-07-25 04:41:09167 status_t setLayerStack(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-12 00:40:36168 const sp<IBinder>& id, uint32_t layerStack);
Dan Stoza7dde5992015-05-22 16:51:44169 status_t deferTransactionUntil(const sp<SurfaceComposerClient>& client,
170 const sp<IBinder>& id, const sp<IBinder>& handle,
171 uint64_t frameNumber);
Robert Carr0d480722017-01-11 00:42:54172 status_t deferTransactionUntil(const sp<SurfaceComposerClient>& client,
173 const sp<IBinder>& id, const sp<Surface>& barrierSurface,
174 uint64_t frameNumber);
Robert Carr1db73f62016-12-21 20:58:51175 status_t reparentChildren(const sp<SurfaceComposerClient>& client,
176 const sp<IBinder>& id,
177 const sp<IBinder>& newParentHandle);
Robert Carrc3574f72016-03-24 19:19:32178 status_t setOverrideScalingMode(const sp<SurfaceComposerClient>& client,
179 const sp<IBinder>& id, int32_t overrideScalingMode);
Robert Carr99e27f02016-06-16 22:18:02180 status_t setGeometryAppliesWithResize(const sp<SurfaceComposerClient>& client,
Robert Carr82364e32016-05-15 18:27:47181 const sp<IBinder>& id);
Mathias Agopian698c0872011-06-29 02:09:31182
Pablo Ceballos1aad24c2016-08-04 17:24:22183 status_t setDisplaySurface(const sp<IBinder>& token,
184 sp<IGraphicBufferProducer> bufferProducer);
Mathias Agopiane57f2922012-08-09 23:29:12185 void setDisplayLayerStack(const sp<IBinder>& token, uint32_t layerStack);
Mathias Agopian00e8c7a2012-09-05 02:30:46186 void setDisplayProjection(const sp<IBinder>& token,
187 uint32_t orientation,
188 const Rect& layerStackRect,
189 const Rect& displayRect);
Michael Wright1f6078a2014-06-26 23:01:02190 void setDisplaySize(const sp<IBinder>& token, uint32_t width, uint32_t height);
Mathias Agopiane57f2922012-08-09 23:29:12191
Jamie Gennis2d5e2302012-10-16 01:24:43192 static void setAnimationTransaction() {
193 Composer::getInstance().setAnimationTransactionImpl();
194 }
195
Jeff Brownf3f7db62012-08-31 09:18:38196 static void openGlobalTransaction() {
197 Composer::getInstance().openGlobalTransactionImpl();
198 }
199
Jamie Gennis28378392011-10-13 00:39:00200 static void closeGlobalTransaction(bool synchronous) {
201 Composer::getInstance().closeGlobalTransactionImpl(synchronous);
Mathias Agopiand4784a32010-05-28 02:41:15202 }
Sahil Dhanjuc1ba5c42016-06-08 03:09:20203
204 static status_t enableVSyncInjections(bool enable) {
205 return Composer::getInstance().enableVSyncInjectionsImpl(enable);
206 }
207
208 static status_t injectVSync(nsecs_t when) {
209 return Composer::getInstance().injectVSyncImpl(when);
210 }
Mathias Agopiand4784a32010-05-28 02:41:15211};
212
213ANDROID_SINGLETON_STATIC_INSTANCE(Composer);
214
The Android Open Source Projectedbf3b62009-03-04 03:31:44215// ---------------------------------------------------------------------------
216
Jamie Gennisdd3cb842012-10-20 01:19:11217sp<IBinder> Composer::createDisplay(const String8& displayName, bool secure) {
218 return ComposerService::getComposerService()->createDisplay(displayName,
219 secure);
Mathias Agopiane57f2922012-08-09 23:29:12220}
221
Jesse Hall6c913be2013-08-08 19:15:49222void Composer::destroyDisplay(const sp<IBinder>& display) {
223 return ComposerService::getComposerService()->destroyDisplay(display);
224}
225
Jeff Brown9d4e3d22012-08-25 03:00:51226sp<IBinder> Composer::getBuiltInDisplay(int32_t id) {
227 return ComposerService::getComposerService()->getBuiltInDisplay(id);
228}
229
Jeff Brownf3f7db62012-08-31 09:18:38230void Composer::openGlobalTransactionImpl() {
231 { // scope for the lock
232 Mutex::Autolock _l(mLock);
233 mTransactionNestCount += 1;
234 }
235}
236
Jamie Gennis28378392011-10-13 00:39:00237void Composer::closeGlobalTransactionImpl(bool synchronous) {
Mathias Agopiane57f2922012-08-09 23:29:12238 sp<ISurfaceComposer> sm(ComposerService::getComposerService());
Mathias Agopian698c0872011-06-29 02:09:31239
240 Vector<ComposerState> transaction;
Mathias Agopian8b33f032012-07-25 03:43:54241 Vector<DisplayState> displayTransaction;
Jamie Gennis28378392011-10-13 00:39:00242 uint32_t flags = 0;
Mathias Agopian698c0872011-06-29 02:09:31243
244 { // scope for the lock
245 Mutex::Autolock _l(mLock);
Jeff Brownf3f7db62012-08-31 09:18:38246 mForceSynchronous |= synchronous;
247 if (!mTransactionNestCount) {
248 ALOGW("At least one call to closeGlobalTransaction() was not matched by a prior "
249 "call to openGlobalTransaction().");
250 } else if (--mTransactionNestCount) {
251 return;
252 }
253
Mathias Agopiane57f2922012-08-09 23:29:12254 transaction = mComposerStates;
255 mComposerStates.clear();
Jamie Gennisb8d69a52011-10-10 22:48:06256
Mathias Agopiane57f2922012-08-09 23:29:12257 displayTransaction = mDisplayStates;
258 mDisplayStates.clear();
Jamie Gennis28378392011-10-13 00:39:00259
Jeff Brownf3f7db62012-08-31 09:18:38260 if (mForceSynchronous) {
Jamie Gennis28378392011-10-13 00:39:00261 flags |= ISurfaceComposer::eSynchronous;
262 }
Jamie Gennis2d5e2302012-10-16 01:24:43263 if (mAnimation) {
264 flags |= ISurfaceComposer::eAnimation;
265 }
266
Jamie Gennis28378392011-10-13 00:39:00267 mForceSynchronous = false;
Jamie Gennis2d5e2302012-10-16 01:24:43268 mAnimation = false;
Mathias Agopian698c0872011-06-29 02:09:31269 }
270
Mathias Agopian8b33f032012-07-25 03:43:54271 sm->setTransactionState(transaction, displayTransaction, flags);
The Android Open Source Projectedbf3b62009-03-04 03:31:44272}
273
Sahil Dhanjuc1ba5c42016-06-08 03:09:20274status_t Composer::enableVSyncInjectionsImpl(bool enable) {
275 sp<ISurfaceComposer> sm(ComposerService::getComposerService());
276 return sm->enableVSyncInjections(enable);
277}
278
279status_t Composer::injectVSyncImpl(nsecs_t when) {
280 sp<ISurfaceComposer> sm(ComposerService::getComposerService());
281 return sm->injectVSync(when);
282}
283
Jamie Gennis2d5e2302012-10-16 01:24:43284void Composer::setAnimationTransactionImpl() {
285 Mutex::Autolock _l(mLock);
286 mAnimation = true;
287}
288
Mathias Agopian698c0872011-06-29 02:09:31289layer_state_t* Composer::getLayerStateLocked(
Mathias Agopianac9fa422013-02-12 00:40:36290 const sp<SurfaceComposerClient>& client, const sp<IBinder>& id) {
Mathias Agopian698c0872011-06-29 02:09:31291
292 ComposerState s;
293 s.client = client->mClient;
294 s.state.surface = id;
295
Mathias Agopiane57f2922012-08-09 23:29:12296 ssize_t index = mComposerStates.indexOf(s);
Mathias Agopian698c0872011-06-29 02:09:31297 if (index < 0) {
298 // we don't have it, add an initialized layer_state to our list
Mathias Agopiane57f2922012-08-09 23:29:12299 index = mComposerStates.add(s);
Mathias Agopian698c0872011-06-29 02:09:31300 }
301
Mathias Agopiane57f2922012-08-09 23:29:12302 ComposerState* const out = mComposerStates.editArray();
Mathias Agopian698c0872011-06-29 02:09:31303 return &(out[index].state);
304}
305
306status_t Composer::setPosition(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-12 00:40:36307 const sp<IBinder>& id, float x, float y) {
Mathias Agopian698c0872011-06-29 02:09:31308 Mutex::Autolock _l(mLock);
309 layer_state_t* s = getLayerStateLocked(client, id);
310 if (!s)
311 return BAD_INDEX;
Mathias Agopian3165cc22012-08-09 02:42:09312 s->what |= layer_state_t::ePositionChanged;
Mathias Agopian698c0872011-06-29 02:09:31313 s->x = x;
314 s->y = y;
315 return NO_ERROR;
316}
317
318status_t Composer::setSize(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-12 00:40:36319 const sp<IBinder>& id, uint32_t w, uint32_t h) {
Mathias Agopian698c0872011-06-29 02:09:31320 Mutex::Autolock _l(mLock);
321 layer_state_t* s = getLayerStateLocked(client, id);
322 if (!s)
323 return BAD_INDEX;
Mathias Agopian3165cc22012-08-09 02:42:09324 s->what |= layer_state_t::eSizeChanged;
Mathias Agopian698c0872011-06-29 02:09:31325 s->w = w;
326 s->h = h;
Jamie Gennis28378392011-10-13 00:39:00327
Jorim Jaggi092123c2016-04-13 01:40:35328 // Resizing a surface makes the transaction synchronous.
329 mForceSynchronous = true;
330
Mathias Agopian698c0872011-06-29 02:09:31331 return NO_ERROR;
332}
333
334status_t Composer::setLayer(const sp<SurfaceComposerClient>& client,
Robert Carrae060832016-11-28 18:51:00335 const sp<IBinder>& id, int32_t z) {
Mathias Agopian698c0872011-06-29 02:09:31336 Mutex::Autolock _l(mLock);
337 layer_state_t* s = getLayerStateLocked(client, id);
338 if (!s)
339 return BAD_INDEX;
Mathias Agopian3165cc22012-08-09 02:42:09340 s->what |= layer_state_t::eLayerChanged;
Mathias Agopian698c0872011-06-29 02:09:31341 s->z = z;
342 return NO_ERROR;
343}
344
345status_t Composer::setFlags(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-12 00:40:36346 const sp<IBinder>& id, uint32_t flags,
Mathias Agopian698c0872011-06-29 02:09:31347 uint32_t mask) {
348 Mutex::Autolock _l(mLock);
349 layer_state_t* s = getLayerStateLocked(client, id);
350 if (!s)
351 return BAD_INDEX;
Pablo Ceballos53390e12015-08-04 18:25:59352 if ((mask & layer_state_t::eLayerOpaque) ||
353 (mask & layer_state_t::eLayerHidden) ||
354 (mask & layer_state_t::eLayerSecure)) {
Dan Stoza23116082015-06-18 21:58:39355 s->what |= layer_state_t::eFlagsChanged;
Andy McFadden4125a4f2014-01-30 01:17:11356 }
Mathias Agopian698c0872011-06-29 02:09:31357 s->flags &= ~mask;
358 s->flags |= (flags & mask);
359 s->mask |= mask;
360 return NO_ERROR;
361}
362
363status_t Composer::setTransparentRegionHint(
Mathias Agopianac9fa422013-02-12 00:40:36364 const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
Mathias Agopian698c0872011-06-29 02:09:31365 const Region& transparentRegion) {
366 Mutex::Autolock _l(mLock);
367 layer_state_t* s = getLayerStateLocked(client, id);
368 if (!s)
369 return BAD_INDEX;
Mathias Agopian3165cc22012-08-09 02:42:09370 s->what |= layer_state_t::eTransparentRegionChanged;
Mathias Agopian698c0872011-06-29 02:09:31371 s->transparentRegion = transparentRegion;
372 return NO_ERROR;
373}
374
375status_t Composer::setAlpha(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-12 00:40:36376 const sp<IBinder>& id, float alpha) {
Mathias Agopian698c0872011-06-29 02:09:31377 Mutex::Autolock _l(mLock);
378 layer_state_t* s = getLayerStateLocked(client, id);
379 if (!s)
380 return BAD_INDEX;
Mathias Agopian3165cc22012-08-09 02:42:09381 s->what |= layer_state_t::eAlphaChanged;
Mathias Agopian698c0872011-06-29 02:09:31382 s->alpha = alpha;
383 return NO_ERROR;
384}
385
Mathias Agopian87855782012-07-25 04:41:09386status_t Composer::setLayerStack(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-12 00:40:36387 const sp<IBinder>& id, uint32_t layerStack) {
Mathias Agopian87855782012-07-25 04:41:09388 Mutex::Autolock _l(mLock);
389 layer_state_t* s = getLayerStateLocked(client, id);
390 if (!s)
391 return BAD_INDEX;
Mathias Agopian3165cc22012-08-09 02:42:09392 s->what |= layer_state_t::eLayerStackChanged;
Mathias Agopian87855782012-07-25 04:41:09393 s->layerStack = layerStack;
394 return NO_ERROR;
395}
396
Mathias Agopian698c0872011-06-29 02:09:31397status_t Composer::setMatrix(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-12 00:40:36398 const sp<IBinder>& id, float dsdx, float dtdx,
Mathias Agopian698c0872011-06-29 02:09:31399 float dsdy, float dtdy) {
400 Mutex::Autolock _l(mLock);
401 layer_state_t* s = getLayerStateLocked(client, id);
402 if (!s)
403 return BAD_INDEX;
Mathias Agopian3165cc22012-08-09 02:42:09404 s->what |= layer_state_t::eMatrixChanged;
Mathias Agopian698c0872011-06-29 02:09:31405 layer_state_t::matrix22_t matrix;
406 matrix.dsdx = dsdx;
407 matrix.dtdx = dtdx;
408 matrix.dsdy = dsdy;
409 matrix.dtdy = dtdy;
410 s->matrix = matrix;
411 return NO_ERROR;
412}
413
Jamie Gennisf15a83f2012-05-11 03:43:55414status_t Composer::setCrop(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-12 00:40:36415 const sp<IBinder>& id, const Rect& crop) {
Jamie Gennisf15a83f2012-05-11 03:43:55416 Mutex::Autolock _l(mLock);
417 layer_state_t* s = getLayerStateLocked(client, id);
418 if (!s)
419 return BAD_INDEX;
Mathias Agopian3165cc22012-08-09 02:42:09420 s->what |= layer_state_t::eCropChanged;
Jamie Gennisf15a83f2012-05-11 03:43:55421 s->crop = crop;
422 return NO_ERROR;
423}
424
Pablo Ceballosacbe6782016-03-04 17:54:21425status_t Composer::setFinalCrop(const sp<SurfaceComposerClient>& client,
426 const sp<IBinder>& id, const Rect& crop) {
427 Mutex::Autolock _l(mLock);
428 layer_state_t* s = getLayerStateLocked(client, id);
429 if (!s) {
430 return BAD_INDEX;
431 }
432 s->what |= layer_state_t::eFinalCropChanged;
433 s->finalCrop = crop;
434 return NO_ERROR;
435}
436
Dan Stoza7dde5992015-05-22 16:51:44437status_t Composer::deferTransactionUntil(
438 const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
439 const sp<IBinder>& handle, uint64_t frameNumber) {
440 Mutex::Autolock lock(mLock);
441 layer_state_t* s = getLayerStateLocked(client, id);
442 if (!s) {
443 return BAD_INDEX;
444 }
445 s->what |= layer_state_t::eDeferTransaction;
Robert Carr0d480722017-01-11 00:42:54446 s->barrierHandle = handle;
447 s->frameNumber = frameNumber;
448 return NO_ERROR;
449}
450
451status_t Composer::deferTransactionUntil(
452 const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
453 const sp<Surface>& barrierSurface, uint64_t frameNumber) {
454 Mutex::Autolock lock(mLock);
455 layer_state_t* s = getLayerStateLocked(client, id);
456 if (!s) {
457 return BAD_INDEX;
458 }
459 s->what |= layer_state_t::eDeferTransaction;
460 s->barrierGbp = barrierSurface->getIGraphicBufferProducer();
Dan Stoza7dde5992015-05-22 16:51:44461 s->frameNumber = frameNumber;
462 return NO_ERROR;
463}
464
Robert Carr1db73f62016-12-21 20:58:51465status_t Composer::reparentChildren(
466 const sp<SurfaceComposerClient>& client,
467 const sp<IBinder>& id,
468 const sp<IBinder>& newParentHandle) {
469 Mutex::Autolock lock(mLock);
470 layer_state_t* s = getLayerStateLocked(client, id);
471 if (!s) {
472 return BAD_INDEX;
473 }
474 s->what |= layer_state_t::eReparentChildren;
475 s->reparentHandle = newParentHandle;
476 return NO_ERROR;
477}
478
Robert Carrc3574f72016-03-24 19:19:32479status_t Composer::setOverrideScalingMode(
480 const sp<SurfaceComposerClient>& client,
481 const sp<IBinder>& id, int32_t overrideScalingMode) {
482 Mutex::Autolock lock(mLock);
483 layer_state_t* s = getLayerStateLocked(client, id);
484 if (!s) {
485 return BAD_INDEX;
486 }
487
488 switch (overrideScalingMode) {
489 case NATIVE_WINDOW_SCALING_MODE_FREEZE:
490 case NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW:
491 case NATIVE_WINDOW_SCALING_MODE_SCALE_CROP:
492 case NATIVE_WINDOW_SCALING_MODE_NO_SCALE_CROP:
493 case -1:
494 break;
495 default:
496 ALOGE("unknown scaling mode: %d",
497 overrideScalingMode);
498 return BAD_VALUE;
499 }
500
501 s->what |= layer_state_t::eOverrideScalingModeChanged;
502 s->overrideScalingMode = overrideScalingMode;
503 return NO_ERROR;
504}
505
Robert Carr99e27f02016-06-16 22:18:02506status_t Composer::setGeometryAppliesWithResize(
Robert Carr82364e32016-05-15 18:27:47507 const sp<SurfaceComposerClient>& client,
508 const sp<IBinder>& id) {
509 Mutex::Autolock lock(mLock);
510 layer_state_t* s = getLayerStateLocked(client, id);
511 if (!s) {
512 return BAD_INDEX;
513 }
Robert Carr99e27f02016-06-16 22:18:02514 s->what |= layer_state_t::eGeometryAppliesWithResize;
Robert Carr82364e32016-05-15 18:27:47515 return NO_ERROR;
516}
517
Mathias Agopian698c0872011-06-29 02:09:31518// ---------------------------------------------------------------------------
519
Mathias Agopiane57f2922012-08-09 23:29:12520DisplayState& Composer::getDisplayStateLocked(const sp<IBinder>& token) {
521 DisplayState s;
522 s.token = token;
523 ssize_t index = mDisplayStates.indexOf(s);
524 if (index < 0) {
525 // we don't have it, add an initialized layer_state to our list
526 s.what = 0;
527 index = mDisplayStates.add(s);
528 }
Dan Stozad723bd72014-11-18 18:24:03529 return mDisplayStates.editItemAt(static_cast<size_t>(index));
Mathias Agopiane57f2922012-08-09 23:29:12530}
531
Pablo Ceballos1aad24c2016-08-04 17:24:22532status_t Composer::setDisplaySurface(const sp<IBinder>& token,
533 sp<IGraphicBufferProducer> bufferProducer) {
Pablo Ceballoseddbef82016-09-01 18:21:21534 if (bufferProducer.get() != nullptr) {
535 // Make sure that composition can never be stalled by a virtual display
536 // consumer that isn't processing buffers fast enough.
537 status_t err = bufferProducer->setAsyncMode(true);
538 if (err != NO_ERROR) {
539 ALOGE("Composer::setDisplaySurface Failed to enable async mode on the "
540 "BufferQueue. This BufferQueue cannot be used for virtual "
541 "display. (%d)", err);
542 return err;
543 }
Pablo Ceballos1aad24c2016-08-04 17:24:22544 }
Mathias Agopiane57f2922012-08-09 23:29:12545 Mutex::Autolock _l(mLock);
546 DisplayState& s(getDisplayStateLocked(token));
Andy McFadden2adaf042012-12-18 17:49:45547 s.surface = bufferProducer;
Mathias Agopiane57f2922012-08-09 23:29:12548 s.what |= DisplayState::eSurfaceChanged;
Pablo Ceballos1aad24c2016-08-04 17:24:22549 return NO_ERROR;
Mathias Agopiane57f2922012-08-09 23:29:12550}
551
552void Composer::setDisplayLayerStack(const sp<IBinder>& token,
553 uint32_t layerStack) {
554 Mutex::Autolock _l(mLock);
555 DisplayState& s(getDisplayStateLocked(token));
556 s.layerStack = layerStack;
557 s.what |= DisplayState::eLayerStackChanged;
558}
559
Mathias Agopian00e8c7a2012-09-05 02:30:46560void Composer::setDisplayProjection(const sp<IBinder>& token,
561 uint32_t orientation,
562 const Rect& layerStackRect,
563 const Rect& displayRect) {
Mathias Agopiane57f2922012-08-09 23:29:12564 Mutex::Autolock _l(mLock);
565 DisplayState& s(getDisplayStateLocked(token));
566 s.orientation = orientation;
Mathias Agopian00e8c7a2012-09-05 02:30:46567 s.viewport = layerStackRect;
568 s.frame = displayRect;
569 s.what |= DisplayState::eDisplayProjectionChanged;
Jorim Jaggi092123c2016-04-13 01:40:35570 mForceSynchronous = true; // TODO: do we actually still need this?
Mathias Agopiane57f2922012-08-09 23:29:12571}
572
Michael Wright1f6078a2014-06-26 23:01:02573void Composer::setDisplaySize(const sp<IBinder>& token, uint32_t width, uint32_t height) {
574 Mutex::Autolock _l(mLock);
575 DisplayState& s(getDisplayStateLocked(token));
576 s.width = width;
577 s.height = height;
578 s.what |= DisplayState::eDisplaySizeChanged;
579}
580
Mathias Agopiane57f2922012-08-09 23:29:12581// ---------------------------------------------------------------------------
582
The Android Open Source Projectedbf3b62009-03-04 03:31:44583SurfaceComposerClient::SurfaceComposerClient()
Mathias Agopian698c0872011-06-29 02:09:31584 : mStatus(NO_INIT), mComposer(Composer::getInstance())
The Android Open Source Projectedbf3b62009-03-04 03:31:44585{
The Android Open Source Projectedbf3b62009-03-04 03:31:44586}
587
Robert Carr1db73f62016-12-21 20:58:51588SurfaceComposerClient::SurfaceComposerClient(const sp<IGraphicBufferProducer>& root)
589 : mStatus(NO_INIT), mComposer(Composer::getInstance()), mParent(root)
590{
591}
592
Mathias Agopian698c0872011-06-29 02:09:31593void SurfaceComposerClient::onFirstRef() {
Mathias Agopiane57f2922012-08-09 23:29:12594 sp<ISurfaceComposer> sm(ComposerService::getComposerService());
Mathias Agopiand4784a32010-05-28 02:41:15595 if (sm != 0) {
Robert Carr1db73f62016-12-21 20:58:51596 auto rootProducer = mParent.promote();
597 sp<ISurfaceComposerClient> conn;
598 conn = (rootProducer != nullptr) ? sm->createScopedConnection(rootProducer) :
599 sm->createConnection();
Mathias Agopiand4784a32010-05-28 02:41:15600 if (conn != 0) {
601 mClient = conn;
Mathias Agopiand4784a32010-05-28 02:41:15602 mStatus = NO_ERROR;
603 }
604 }
The Android Open Source Projectedbf3b62009-03-04 03:31:44605}
606
Mathias Agopian698c0872011-06-29 02:09:31607SurfaceComposerClient::~SurfaceComposerClient() {
Mathias Agopian631f3582010-05-26 00:51:34608 dispose();
609}
Mathias Agopiandd3423c2009-09-23 22:44:05610
Mathias Agopian698c0872011-06-29 02:09:31611status_t SurfaceComposerClient::initCheck() const {
The Android Open Source Projectedbf3b62009-03-04 03:31:44612 return mStatus;
613}
614
Mathias Agopian698c0872011-06-29 02:09:31615sp<IBinder> SurfaceComposerClient::connection() const {
Marco Nelissen2ea926b2014-11-14 16:01:01616 return IInterface::asBinder(mClient);
The Android Open Source Projectedbf3b62009-03-04 03:31:44617}
618
Mathias Agopiand4784a32010-05-28 02:41:15619status_t SurfaceComposerClient::linkToComposerDeath(
620 const sp<IBinder::DeathRecipient>& recipient,
Mathias Agopian698c0872011-06-29 02:09:31621 void* cookie, uint32_t flags) {
Mathias Agopiane57f2922012-08-09 23:29:12622 sp<ISurfaceComposer> sm(ComposerService::getComposerService());
Marco Nelissen2ea926b2014-11-14 16:01:01623 return IInterface::asBinder(sm)->linkToDeath(recipient, cookie, flags);
The Android Open Source Projectedbf3b62009-03-04 03:31:44624}
625
Mathias Agopian698c0872011-06-29 02:09:31626void SurfaceComposerClient::dispose() {
The Android Open Source Projectedbf3b62009-03-04 03:31:44627 // this can be called more than once.
Mathias Agopian7e27f052010-05-28 21:22:23628 sp<ISurfaceComposerClient> client;
Mathias Agopiand4784a32010-05-28 02:41:15629 Mutex::Autolock _lm(mLock);
630 if (mClient != 0) {
Mathias Agopiand4784a32010-05-28 02:41:15631 client = mClient; // hold ref while lock is held
632 mClient.clear();
The Android Open Source Projectedbf3b62009-03-04 03:31:44633 }
Mathias Agopiand4784a32010-05-28 02:41:15634 mStatus = NO_INIT;
The Android Open Source Projectedbf3b62009-03-04 03:31:44635}
636
Mathias Agopian698c0872011-06-29 02:09:31637sp<SurfaceControl> SurfaceComposerClient::createSurface(
Mathias Agopian698c0872011-06-29 02:09:31638 const String8& name,
Mathias Agopian698c0872011-06-29 02:09:31639 uint32_t w,
640 uint32_t h,
641 PixelFormat format,
Robert Carr1f0a16a2016-10-24 23:27:39642 uint32_t flags,
Albert Chaulk479c60c2017-01-27 19:21:34643 SurfaceControl* parent,
644 uint32_t windowType,
645 uint32_t ownerUid)
Mathias Agopian698c0872011-06-29 02:09:31646{
Mathias Agopian4d9b8222013-03-13 00:11:48647 sp<SurfaceControl> sur;
Mathias Agopian698c0872011-06-29 02:09:31648 if (mStatus == NO_ERROR) {
Mathias Agopian4d9b8222013-03-13 00:11:48649 sp<IBinder> handle;
Robert Carr1f0a16a2016-10-24 23:27:39650 sp<IBinder> parentHandle;
Mathias Agopian4d9b8222013-03-13 00:11:48651 sp<IGraphicBufferProducer> gbp;
Robert Carr1f0a16a2016-10-24 23:27:39652
653 if (parent != nullptr) {
654 parentHandle = parent->getHandle();
655 }
656 status_t err = mClient->createSurface(name, w, h, format, flags, parentHandle,
Albert Chaulk479c60c2017-01-27 19:21:34657 windowType, ownerUid, &handle, &gbp);
Mathias Agopian4d9b8222013-03-13 00:11:48658 ALOGE_IF(err, "SurfaceComposerClient::createSurface error %s", strerror(-err));
659 if (err == NO_ERROR) {
660 sur = new SurfaceControl(this, handle, gbp);
Mathias Agopian698c0872011-06-29 02:09:31661 }
662 }
Mathias Agopian4d9b8222013-03-13 00:11:48663 return sur;
Mathias Agopian698c0872011-06-29 02:09:31664}
665
Jamie Gennisdd3cb842012-10-20 01:19:11666sp<IBinder> SurfaceComposerClient::createDisplay(const String8& displayName,
667 bool secure) {
668 return Composer::getInstance().createDisplay(displayName, secure);
Mathias Agopiane57f2922012-08-09 23:29:12669}
670
Jesse Hall6c913be2013-08-08 19:15:49671void SurfaceComposerClient::destroyDisplay(const sp<IBinder>& display) {
672 Composer::getInstance().destroyDisplay(display);
673}
674
Jeff Brown9d4e3d22012-08-25 03:00:51675sp<IBinder> SurfaceComposerClient::getBuiltInDisplay(int32_t id) {
676 return Composer::getInstance().getBuiltInDisplay(id);
677}
678
Mathias Agopianac9fa422013-02-12 00:40:36679status_t SurfaceComposerClient::destroySurface(const sp<IBinder>& sid) {
Mathias Agopian698c0872011-06-29 02:09:31680 if (mStatus != NO_ERROR)
681 return mStatus;
682 status_t err = mClient->destroySurface(sid);
683 return err;
684}
685
Svetoslavd85084b2014-03-20 17:28:31686status_t SurfaceComposerClient::clearLayerFrameStats(const sp<IBinder>& token) const {
687 if (mStatus != NO_ERROR) {
688 return mStatus;
689 }
690 return mClient->clearLayerFrameStats(token);
691}
692
693status_t SurfaceComposerClient::getLayerFrameStats(const sp<IBinder>& token,
694 FrameStats* outStats) const {
695 if (mStatus != NO_ERROR) {
696 return mStatus;
697 }
698 return mClient->getLayerFrameStats(token, outStats);
699}
700
Robert Carr367c5682016-06-20 18:55:28701status_t SurfaceComposerClient::getTransformToDisplayInverse(const sp<IBinder>& token,
702 bool* outTransformToDisplayInverse) const {
703 if (mStatus != NO_ERROR) {
704 return mStatus;
705 }
706 return mClient->getTransformToDisplayInverse(token, outTransformToDisplayInverse);
707}
708
Mathias Agopian698c0872011-06-29 02:09:31709inline Composer& SurfaceComposerClient::getComposer() {
710 return mComposer;
711}
712
713// ----------------------------------------------------------------------------
714
715void SurfaceComposerClient::openGlobalTransaction() {
Jeff Brownf3f7db62012-08-31 09:18:38716 Composer::openGlobalTransaction();
Mathias Agopian698c0872011-06-29 02:09:31717}
718
Jamie Gennis28378392011-10-13 00:39:00719void SurfaceComposerClient::closeGlobalTransaction(bool synchronous) {
720 Composer::closeGlobalTransaction(synchronous);
Mathias Agopian698c0872011-06-29 02:09:31721}
722
Jamie Gennis2d5e2302012-10-16 01:24:43723void SurfaceComposerClient::setAnimationTransaction() {
724 Composer::setAnimationTransaction();
725}
726
Sahil Dhanjuc1ba5c42016-06-08 03:09:20727status_t SurfaceComposerClient::enableVSyncInjections(bool enable) {
728 return Composer::enableVSyncInjections(enable);
729}
730
731status_t SurfaceComposerClient::injectVSync(nsecs_t when) {
732 return Composer::injectVSync(when);
733}
734
Mathias Agopian698c0872011-06-29 02:09:31735// ----------------------------------------------------------------------------
736
Mathias Agopianac9fa422013-02-12 00:40:36737status_t SurfaceComposerClient::setCrop(const sp<IBinder>& id, const Rect& crop) {
Jamie Gennisf15a83f2012-05-11 03:43:55738 return getComposer().setCrop(this, id, crop);
739}
740
Pablo Ceballosacbe6782016-03-04 17:54:21741status_t SurfaceComposerClient::setFinalCrop(const sp<IBinder>& id,
742 const Rect& crop) {
743 return getComposer().setFinalCrop(this, id, crop);
744}
745
Mathias Agopianac9fa422013-02-12 00:40:36746status_t SurfaceComposerClient::setPosition(const sp<IBinder>& id, float x, float y) {
Mathias Agopian698c0872011-06-29 02:09:31747 return getComposer().setPosition(this, id, x, y);
748}
749
Mathias Agopianac9fa422013-02-12 00:40:36750status_t SurfaceComposerClient::setSize(const sp<IBinder>& id, uint32_t w, uint32_t h) {
Mathias Agopian698c0872011-06-29 02:09:31751 return getComposer().setSize(this, id, w, h);
752}
753
Robert Carrae060832016-11-28 18:51:00754status_t SurfaceComposerClient::setLayer(const sp<IBinder>& id, int32_t z) {
Mathias Agopian698c0872011-06-29 02:09:31755 return getComposer().setLayer(this, id, z);
756}
757
Mathias Agopianac9fa422013-02-12 00:40:36758status_t SurfaceComposerClient::hide(const sp<IBinder>& id) {
Mathias Agopian698c0872011-06-29 02:09:31759 return getComposer().setFlags(this, id,
Mathias Agopian3165cc22012-08-09 02:42:09760 layer_state_t::eLayerHidden,
761 layer_state_t::eLayerHidden);
Mathias Agopian698c0872011-06-29 02:09:31762}
763
Mathias Agopianac9fa422013-02-12 00:40:36764status_t SurfaceComposerClient::show(const sp<IBinder>& id) {
Mathias Agopian698c0872011-06-29 02:09:31765 return getComposer().setFlags(this, id,
766 0,
Mathias Agopian3165cc22012-08-09 02:42:09767 layer_state_t::eLayerHidden);
Mathias Agopian698c0872011-06-29 02:09:31768}
769
Mathias Agopianac9fa422013-02-12 00:40:36770status_t SurfaceComposerClient::setFlags(const sp<IBinder>& id, uint32_t flags,
Mathias Agopian698c0872011-06-29 02:09:31771 uint32_t mask) {
772 return getComposer().setFlags(this, id, flags, mask);
773}
774
Mathias Agopianac9fa422013-02-12 00:40:36775status_t SurfaceComposerClient::setTransparentRegionHint(const sp<IBinder>& id,
Mathias Agopian698c0872011-06-29 02:09:31776 const Region& transparentRegion) {
777 return getComposer().setTransparentRegionHint(this, id, transparentRegion);
778}
779
Mathias Agopianac9fa422013-02-12 00:40:36780status_t SurfaceComposerClient::setAlpha(const sp<IBinder>& id, float alpha) {
Mathias Agopian698c0872011-06-29 02:09:31781 return getComposer().setAlpha(this, id, alpha);
782}
783
Mathias Agopianac9fa422013-02-12 00:40:36784status_t SurfaceComposerClient::setLayerStack(const sp<IBinder>& id, uint32_t layerStack) {
Mathias Agopian87855782012-07-25 04:41:09785 return getComposer().setLayerStack(this, id, layerStack);
786}
787
Mathias Agopianac9fa422013-02-12 00:40:36788status_t SurfaceComposerClient::setMatrix(const sp<IBinder>& id, float dsdx, float dtdx,
Mathias Agopian698c0872011-06-29 02:09:31789 float dsdy, float dtdy) {
790 return getComposer().setMatrix(this, id, dsdx, dtdx, dsdy, dtdy);
791}
792
Dan Stoza7dde5992015-05-22 16:51:44793status_t SurfaceComposerClient::deferTransactionUntil(const sp<IBinder>& id,
794 const sp<IBinder>& handle, uint64_t frameNumber) {
795 return getComposer().deferTransactionUntil(this, id, handle, frameNumber);
796}
797
Robert Carr0d480722017-01-11 00:42:54798status_t SurfaceComposerClient::deferTransactionUntil(const sp<IBinder>& id,
799 const sp<Surface>& barrierSurface, uint64_t frameNumber) {
800 return getComposer().deferTransactionUntil(this, id, barrierSurface, frameNumber);
801}
802
Robert Carr1db73f62016-12-21 20:58:51803status_t SurfaceComposerClient::reparentChildren(const sp<IBinder>& id,
804 const sp<IBinder>& newParentHandle) {
805 return getComposer().reparentChildren(this, id, newParentHandle);
806}
807
Robert Carrc3574f72016-03-24 19:19:32808status_t SurfaceComposerClient::setOverrideScalingMode(
809 const sp<IBinder>& id, int32_t overrideScalingMode) {
810 return getComposer().setOverrideScalingMode(
811 this, id, overrideScalingMode);
812}
813
Robert Carr99e27f02016-06-16 22:18:02814status_t SurfaceComposerClient::setGeometryAppliesWithResize(
Robert Carr82364e32016-05-15 18:27:47815 const sp<IBinder>& id) {
Robert Carr99e27f02016-06-16 22:18:02816 return getComposer().setGeometryAppliesWithResize(this, id);
Robert Carr82364e32016-05-15 18:27:47817}
818
Mathias Agopian698c0872011-06-29 02:09:31819// ----------------------------------------------------------------------------
820
Pablo Ceballos1aad24c2016-08-04 17:24:22821status_t SurfaceComposerClient::setDisplaySurface(const sp<IBinder>& token,
822 sp<IGraphicBufferProducer> bufferProducer) {
823 return Composer::getInstance().setDisplaySurface(token, bufferProducer);
Mathias Agopiane57f2922012-08-09 23:29:12824}
825
826void SurfaceComposerClient::setDisplayLayerStack(const sp<IBinder>& token,
827 uint32_t layerStack) {
828 Composer::getInstance().setDisplayLayerStack(token, layerStack);
829}
830
Mathias Agopian00e8c7a2012-09-05 02:30:46831void SurfaceComposerClient::setDisplayProjection(const sp<IBinder>& token,
832 uint32_t orientation,
833 const Rect& layerStackRect,
834 const Rect& displayRect) {
835 Composer::getInstance().setDisplayProjection(token, orientation,
836 layerStackRect, displayRect);
Mathias Agopiane57f2922012-08-09 23:29:12837}
838
Michael Wright1f6078a2014-06-26 23:01:02839void SurfaceComposerClient::setDisplaySize(const sp<IBinder>& token,
840 uint32_t width, uint32_t height) {
841 Composer::getInstance().setDisplaySize(token, width, height);
842}
843
Mathias Agopiane57f2922012-08-09 23:29:12844// ----------------------------------------------------------------------------
845
Dan Stoza7f7da322014-05-02 22:26:25846status_t SurfaceComposerClient::getDisplayConfigs(
847 const sp<IBinder>& display, Vector<DisplayInfo>* configs)
The Android Open Source Projectedbf3b62009-03-04 03:31:44848{
Dan Stoza7f7da322014-05-02 22:26:25849 return ComposerService::getComposerService()->getDisplayConfigs(display, configs);
850}
851
852status_t SurfaceComposerClient::getDisplayInfo(const sp<IBinder>& display,
853 DisplayInfo* info) {
854 Vector<DisplayInfo> configs;
855 status_t result = getDisplayConfigs(display, &configs);
856 if (result != NO_ERROR) {
857 return result;
858 }
859
860 int activeId = getActiveConfig(display);
861 if (activeId < 0) {
862 ALOGE("No active configuration found");
863 return NAME_NOT_FOUND;
864 }
865
Dan Stozad723bd72014-11-18 18:24:03866 *info = configs[static_cast<size_t>(activeId)];
Dan Stoza7f7da322014-05-02 22:26:25867 return NO_ERROR;
868}
869
870int SurfaceComposerClient::getActiveConfig(const sp<IBinder>& display) {
871 return ComposerService::getComposerService()->getActiveConfig(display);
872}
873
874status_t SurfaceComposerClient::setActiveConfig(const sp<IBinder>& display, int id) {
875 return ComposerService::getComposerService()->setActiveConfig(display, id);
The Android Open Source Projectedbf3b62009-03-04 03:31:44876}
877
Michael Wright28f24d02016-07-12 20:30:53878status_t SurfaceComposerClient::getDisplayColorModes(const sp<IBinder>& display,
879 Vector<android_color_mode_t>* outColorModes) {
880 return ComposerService::getComposerService()->getDisplayColorModes(display, outColorModes);
881}
882
883android_color_mode_t SurfaceComposerClient::getActiveColorMode(const sp<IBinder>& display) {
884 return ComposerService::getComposerService()->getActiveColorMode(display);
885}
886
887status_t SurfaceComposerClient::setActiveColorMode(const sp<IBinder>& display,
888 android_color_mode_t colorMode) {
889 return ComposerService::getComposerService()->setActiveColorMode(display, colorMode);
890}
891
Prashant Malani2c9b11f2014-05-25 08:36:31892void SurfaceComposerClient::setDisplayPowerMode(const sp<IBinder>& token,
893 int mode) {
894 ComposerService::getComposerService()->setPowerMode(token, mode);
Jeff Brown2a09bb32012-10-09 02:13:57895}
896
Svetoslavd85084b2014-03-20 17:28:31897status_t SurfaceComposerClient::clearAnimationFrameStats() {
898 return ComposerService::getComposerService()->clearAnimationFrameStats();
899}
900
901status_t SurfaceComposerClient::getAnimationFrameStats(FrameStats* outStats) {
902 return ComposerService::getComposerService()->getAnimationFrameStats(outStats);
903}
904
Dan Stozac4f471e2016-03-24 16:31:08905status_t SurfaceComposerClient::getHdrCapabilities(const sp<IBinder>& display,
906 HdrCapabilities* outCapabilities) {
907 return ComposerService::getComposerService()->getHdrCapabilities(display,
908 outCapabilities);
909}
910
Mathias Agopian698c0872011-06-29 02:09:31911// ----------------------------------------------------------------------------
The Android Open Source Projectedbf3b62009-03-04 03:31:44912
Mathias Agopian2a9fc492013-03-01 21:42:57913status_t ScreenshotClient::capture(
914 const sp<IBinder>& display,
915 const sp<IGraphicBufferProducer>& producer,
Dan Stozac1879002014-05-22 22:59:05916 Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
Robert Carrae060832016-11-28 18:51:00917 int32_t minLayerZ, int32_t maxLayerZ, bool useIdentityTransform) {
Mathias Agopian2a9fc492013-03-01 21:42:57918 sp<ISurfaceComposer> s(ComposerService::getComposerService());
919 if (s == NULL) return NO_INIT;
Dan Stozac1879002014-05-22 22:59:05920 return s->captureScreen(display, producer, sourceCrop,
Dan Stozac7014012014-02-14 23:03:43921 reqWidth, reqHeight, minLayerZ, maxLayerZ, useIdentityTransform);
Mathias Agopian2a9fc492013-03-01 21:42:57922}
923
Robert Carr673134e2017-01-10 03:48:38924status_t ScreenshotClient::captureToBuffer(const sp<IBinder>& display,
925 Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
Robert Carrae060832016-11-28 18:51:00926 int32_t minLayerZ, int32_t maxLayerZ, bool useIdentityTransform,
Robert Carr673134e2017-01-10 03:48:38927 uint32_t rotation,
928 sp<GraphicBuffer>* outBuffer) {
929 sp<ISurfaceComposer> s(ComposerService::getComposerService());
930 if (s == NULL) return NO_INIT;
931
932 sp<IGraphicBufferConsumer> gbpConsumer;
933 sp<IGraphicBufferProducer> producer;
934 BufferQueue::createBufferQueue(&producer, &gbpConsumer);
935 sp<BufferItemConsumer> consumer(new BufferItemConsumer(gbpConsumer,
936 GRALLOC_USAGE_HW_TEXTURE | GRALLOC_USAGE_SW_READ_NEVER | GRALLOC_USAGE_SW_WRITE_NEVER,
937 1, true));
938
939 status_t ret = s->captureScreen(display, producer, sourceCrop, reqWidth, reqHeight,
940 minLayerZ, maxLayerZ, useIdentityTransform,
941 static_cast<ISurfaceComposer::Rotation>(rotation));
942 if (ret != NO_ERROR) {
943 return ret;
944 }
945 BufferItem b;
946 consumer->acquireBuffer(&b, 0, true);
947 *outBuffer = b.mGraphicBuffer;
948 return ret;
949}
950
Mathias Agopian74c40c02010-09-29 20:02:36951ScreenshotClient::ScreenshotClient()
Mathias Agopianabe815d2013-03-20 05:22:21952 : mHaveBuffer(false) {
953 memset(&mBuffer, 0, sizeof(mBuffer));
Mathias Agopian74c40c02010-09-29 20:02:36954}
955
Mathias Agopian8000d062013-03-27 01:15:35956ScreenshotClient::~ScreenshotClient() {
957 ScreenshotClient::release();
958}
959
Mathias Agopianabe815d2013-03-20 05:22:21960sp<CpuConsumer> ScreenshotClient::getCpuConsumer() const {
961 if (mCpuConsumer == NULL) {
Dan Stoza6d5a7bb2014-03-13 18:39:09962 sp<IGraphicBufferConsumer> consumer;
963 BufferQueue::createBufferQueue(&mProducer, &consumer);
964 mCpuConsumer = new CpuConsumer(consumer, 1);
Mathias Agopianabe815d2013-03-20 05:22:21965 mCpuConsumer->setName(String8("ScreenshotClient"));
966 }
967 return mCpuConsumer;
Mathias Agopianbf2c6a62010-12-11 00:22:31968}
969
Jeff Brown9d4e3d22012-08-25 03:00:51970status_t ScreenshotClient::update(const sp<IBinder>& display,
Dan Stozac1879002014-05-22 22:59:05971 Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
Robert Carrae060832016-11-28 18:51:00972 int32_t minLayerZ, int32_t maxLayerZ,
Riley Andrewsd15ef272014-09-04 23:19:44973 bool useIdentityTransform, uint32_t rotation) {
Mathias Agopianbf2c6a62010-12-11 00:22:31974 sp<ISurfaceComposer> s(ComposerService::getComposerService());
975 if (s == NULL) return NO_INIT;
Mathias Agopianabe815d2013-03-20 05:22:21976 sp<CpuConsumer> cpuConsumer = getCpuConsumer();
977
978 if (mHaveBuffer) {
979 mCpuConsumer->unlockBuffer(mBuffer);
980 memset(&mBuffer, 0, sizeof(mBuffer));
981 mHaveBuffer = false;
982 }
983
Dan Stozac1879002014-05-22 22:59:05984 status_t err = s->captureScreen(display, mProducer, sourceCrop,
Riley Andrewsd15ef272014-09-04 23:19:44985 reqWidth, reqHeight, minLayerZ, maxLayerZ, useIdentityTransform,
986 static_cast<ISurfaceComposer::Rotation>(rotation));
Mathias Agopianabe815d2013-03-20 05:22:21987
988 if (err == NO_ERROR) {
989 err = mCpuConsumer->lockNextBuffer(&mBuffer);
990 if (err == NO_ERROR) {
991 mHaveBuffer = true;
992 }
993 }
994 return err;
995}
996
Riley Andrewsd15ef272014-09-04 23:19:44997status_t ScreenshotClient::update(const sp<IBinder>& display,
998 Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
Robert Carrae060832016-11-28 18:51:00999 int32_t minLayerZ, int32_t maxLayerZ,
Riley Andrewsd15ef272014-09-04 23:19:441000 bool useIdentityTransform) {
1001
1002 return ScreenshotClient::update(display, sourceCrop, reqWidth, reqHeight,
1003 minLayerZ, maxLayerZ, useIdentityTransform, ISurfaceComposer::eRotateNone);
1004}
1005
Dan Stozac1879002014-05-22 22:59:051006status_t ScreenshotClient::update(const sp<IBinder>& display, Rect sourceCrop,
Dan Stozac7014012014-02-14 23:03:431007 bool useIdentityTransform) {
Robert Carrae060832016-11-28 18:51:001008 return ScreenshotClient::update(display, sourceCrop, 0, 0,
1009 INT32_MIN, INT32_MAX,
Riley Andrewsd15ef272014-09-04 23:19:441010 useIdentityTransform, ISurfaceComposer::eRotateNone);
Mathias Agopianabe815d2013-03-20 05:22:211011}
1012
Dan Stozac1879002014-05-22 22:59:051013status_t ScreenshotClient::update(const sp<IBinder>& display, Rect sourceCrop,
Dan Stozac7014012014-02-14 23:03:431014 uint32_t reqWidth, uint32_t reqHeight, bool useIdentityTransform) {
Dan Stozac1879002014-05-22 22:59:051015 return ScreenshotClient::update(display, sourceCrop, reqWidth, reqHeight,
Robert Carrae060832016-11-28 18:51:001016 INT32_MIN, INT32_MAX,
1017 useIdentityTransform, ISurfaceComposer::eRotateNone);
Mathias Agopian74c40c02010-09-29 20:02:361018}
1019
1020void ScreenshotClient::release() {
Mathias Agopianabe815d2013-03-20 05:22:211021 if (mHaveBuffer) {
1022 mCpuConsumer->unlockBuffer(mBuffer);
1023 memset(&mBuffer, 0, sizeof(mBuffer));
1024 mHaveBuffer = false;
1025 }
1026 mCpuConsumer.clear();
Mathias Agopian74c40c02010-09-29 20:02:361027}
1028
1029void const* ScreenshotClient::getPixels() const {
Mathias Agopianabe815d2013-03-20 05:22:211030 return mBuffer.data;
Mathias Agopian74c40c02010-09-29 20:02:361031}
1032
1033uint32_t ScreenshotClient::getWidth() const {
Mathias Agopianabe815d2013-03-20 05:22:211034 return mBuffer.width;
Mathias Agopian74c40c02010-09-29 20:02:361035}
1036
1037uint32_t ScreenshotClient::getHeight() const {
Mathias Agopianabe815d2013-03-20 05:22:211038 return mBuffer.height;
Mathias Agopian74c40c02010-09-29 20:02:361039}
1040
1041PixelFormat ScreenshotClient::getFormat() const {
Mathias Agopianabe815d2013-03-20 05:22:211042 return mBuffer.format;
Mathias Agopian74c40c02010-09-29 20:02:361043}
1044
1045uint32_t ScreenshotClient::getStride() const {
Mathias Agopianabe815d2013-03-20 05:22:211046 return mBuffer.stride;
Mathias Agopian74c40c02010-09-29 20:02:361047}
1048
1049size_t ScreenshotClient::getSize() const {
Mathias Agopianabe815d2013-03-20 05:22:211050 return mBuffer.stride * mBuffer.height * bytesPerPixel(mBuffer.format);
Mathias Agopian74c40c02010-09-29 20:02:361051}
1052
1053// ----------------------------------------------------------------------------
The Android Open Source Projectedbf3b62009-03-04 03:31:441054}; // namespace android