blob: 2632781982488e3ededb8c047ff566e95aba50c1 [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 Carr9524cb32017-02-13 19:32:32178 status_t detachChildren(const sp<SurfaceComposerClient>& client,
179 const sp<IBinder>& id);
Robert Carrc3574f72016-03-24 19:19:32180 status_t setOverrideScalingMode(const sp<SurfaceComposerClient>& client,
181 const sp<IBinder>& id, int32_t overrideScalingMode);
Robert Carr99e27f02016-06-16 22:18:02182 status_t setGeometryAppliesWithResize(const sp<SurfaceComposerClient>& client,
Robert Carr82364e32016-05-15 18:27:47183 const sp<IBinder>& id);
Mathias Agopian698c0872011-06-29 02:09:31184
Pablo Ceballos1aad24c2016-08-04 17:24:22185 status_t setDisplaySurface(const sp<IBinder>& token,
186 sp<IGraphicBufferProducer> bufferProducer);
Mathias Agopiane57f2922012-08-09 23:29:12187 void setDisplayLayerStack(const sp<IBinder>& token, uint32_t layerStack);
Mathias Agopian00e8c7a2012-09-05 02:30:46188 void setDisplayProjection(const sp<IBinder>& token,
189 uint32_t orientation,
190 const Rect& layerStackRect,
191 const Rect& displayRect);
Michael Wright1f6078a2014-06-26 23:01:02192 void setDisplaySize(const sp<IBinder>& token, uint32_t width, uint32_t height);
Mathias Agopiane57f2922012-08-09 23:29:12193
Jamie Gennis2d5e2302012-10-16 01:24:43194 static void setAnimationTransaction() {
195 Composer::getInstance().setAnimationTransactionImpl();
196 }
197
Jeff Brownf3f7db62012-08-31 09:18:38198 static void openGlobalTransaction() {
199 Composer::getInstance().openGlobalTransactionImpl();
200 }
201
Jamie Gennis28378392011-10-13 00:39:00202 static void closeGlobalTransaction(bool synchronous) {
203 Composer::getInstance().closeGlobalTransactionImpl(synchronous);
Mathias Agopiand4784a32010-05-28 02:41:15204 }
Sahil Dhanjuc1ba5c42016-06-08 03:09:20205
206 static status_t enableVSyncInjections(bool enable) {
207 return Composer::getInstance().enableVSyncInjectionsImpl(enable);
208 }
209
210 static status_t injectVSync(nsecs_t when) {
211 return Composer::getInstance().injectVSyncImpl(when);
212 }
Mathias Agopiand4784a32010-05-28 02:41:15213};
214
215ANDROID_SINGLETON_STATIC_INSTANCE(Composer);
216
The Android Open Source Projectedbf3b62009-03-04 03:31:44217// ---------------------------------------------------------------------------
218
Jamie Gennisdd3cb842012-10-20 01:19:11219sp<IBinder> Composer::createDisplay(const String8& displayName, bool secure) {
220 return ComposerService::getComposerService()->createDisplay(displayName,
221 secure);
Mathias Agopiane57f2922012-08-09 23:29:12222}
223
Jesse Hall6c913be2013-08-08 19:15:49224void Composer::destroyDisplay(const sp<IBinder>& display) {
225 return ComposerService::getComposerService()->destroyDisplay(display);
226}
227
Jeff Brown9d4e3d22012-08-25 03:00:51228sp<IBinder> Composer::getBuiltInDisplay(int32_t id) {
229 return ComposerService::getComposerService()->getBuiltInDisplay(id);
230}
231
Jeff Brownf3f7db62012-08-31 09:18:38232void Composer::openGlobalTransactionImpl() {
233 { // scope for the lock
234 Mutex::Autolock _l(mLock);
235 mTransactionNestCount += 1;
236 }
237}
238
Jamie Gennis28378392011-10-13 00:39:00239void Composer::closeGlobalTransactionImpl(bool synchronous) {
Mathias Agopiane57f2922012-08-09 23:29:12240 sp<ISurfaceComposer> sm(ComposerService::getComposerService());
Mathias Agopian698c0872011-06-29 02:09:31241
242 Vector<ComposerState> transaction;
Mathias Agopian8b33f032012-07-25 03:43:54243 Vector<DisplayState> displayTransaction;
Jamie Gennis28378392011-10-13 00:39:00244 uint32_t flags = 0;
Mathias Agopian698c0872011-06-29 02:09:31245
246 { // scope for the lock
247 Mutex::Autolock _l(mLock);
Jeff Brownf3f7db62012-08-31 09:18:38248 mForceSynchronous |= synchronous;
249 if (!mTransactionNestCount) {
250 ALOGW("At least one call to closeGlobalTransaction() was not matched by a prior "
251 "call to openGlobalTransaction().");
252 } else if (--mTransactionNestCount) {
253 return;
254 }
255
Mathias Agopiane57f2922012-08-09 23:29:12256 transaction = mComposerStates;
257 mComposerStates.clear();
Jamie Gennisb8d69a52011-10-10 22:48:06258
Mathias Agopiane57f2922012-08-09 23:29:12259 displayTransaction = mDisplayStates;
260 mDisplayStates.clear();
Jamie Gennis28378392011-10-13 00:39:00261
Jeff Brownf3f7db62012-08-31 09:18:38262 if (mForceSynchronous) {
Jamie Gennis28378392011-10-13 00:39:00263 flags |= ISurfaceComposer::eSynchronous;
264 }
Jamie Gennis2d5e2302012-10-16 01:24:43265 if (mAnimation) {
266 flags |= ISurfaceComposer::eAnimation;
267 }
268
Jamie Gennis28378392011-10-13 00:39:00269 mForceSynchronous = false;
Jamie Gennis2d5e2302012-10-16 01:24:43270 mAnimation = false;
Mathias Agopian698c0872011-06-29 02:09:31271 }
272
Mathias Agopian8b33f032012-07-25 03:43:54273 sm->setTransactionState(transaction, displayTransaction, flags);
The Android Open Source Projectedbf3b62009-03-04 03:31:44274}
275
Sahil Dhanjuc1ba5c42016-06-08 03:09:20276status_t Composer::enableVSyncInjectionsImpl(bool enable) {
277 sp<ISurfaceComposer> sm(ComposerService::getComposerService());
278 return sm->enableVSyncInjections(enable);
279}
280
281status_t Composer::injectVSyncImpl(nsecs_t when) {
282 sp<ISurfaceComposer> sm(ComposerService::getComposerService());
283 return sm->injectVSync(when);
284}
285
Jamie Gennis2d5e2302012-10-16 01:24:43286void Composer::setAnimationTransactionImpl() {
287 Mutex::Autolock _l(mLock);
288 mAnimation = true;
289}
290
Mathias Agopian698c0872011-06-29 02:09:31291layer_state_t* Composer::getLayerStateLocked(
Mathias Agopianac9fa422013-02-12 00:40:36292 const sp<SurfaceComposerClient>& client, const sp<IBinder>& id) {
Mathias Agopian698c0872011-06-29 02:09:31293
294 ComposerState s;
295 s.client = client->mClient;
296 s.state.surface = id;
297
Mathias Agopiane57f2922012-08-09 23:29:12298 ssize_t index = mComposerStates.indexOf(s);
Mathias Agopian698c0872011-06-29 02:09:31299 if (index < 0) {
300 // we don't have it, add an initialized layer_state to our list
Mathias Agopiane57f2922012-08-09 23:29:12301 index = mComposerStates.add(s);
Mathias Agopian698c0872011-06-29 02:09:31302 }
303
Mathias Agopiane57f2922012-08-09 23:29:12304 ComposerState* const out = mComposerStates.editArray();
Mathias Agopian698c0872011-06-29 02:09:31305 return &(out[index].state);
306}
307
308status_t Composer::setPosition(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-12 00:40:36309 const sp<IBinder>& id, float x, float y) {
Mathias Agopian698c0872011-06-29 02:09:31310 Mutex::Autolock _l(mLock);
311 layer_state_t* s = getLayerStateLocked(client, id);
312 if (!s)
313 return BAD_INDEX;
Mathias Agopian3165cc22012-08-09 02:42:09314 s->what |= layer_state_t::ePositionChanged;
Mathias Agopian698c0872011-06-29 02:09:31315 s->x = x;
316 s->y = y;
317 return NO_ERROR;
318}
319
320status_t Composer::setSize(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-12 00:40:36321 const sp<IBinder>& id, uint32_t w, uint32_t h) {
Mathias Agopian698c0872011-06-29 02:09:31322 Mutex::Autolock _l(mLock);
323 layer_state_t* s = getLayerStateLocked(client, id);
324 if (!s)
325 return BAD_INDEX;
Mathias Agopian3165cc22012-08-09 02:42:09326 s->what |= layer_state_t::eSizeChanged;
Mathias Agopian698c0872011-06-29 02:09:31327 s->w = w;
328 s->h = h;
Jamie Gennis28378392011-10-13 00:39:00329
Jorim Jaggi092123c2016-04-13 01:40:35330 // Resizing a surface makes the transaction synchronous.
331 mForceSynchronous = true;
332
Mathias Agopian698c0872011-06-29 02:09:31333 return NO_ERROR;
334}
335
336status_t Composer::setLayer(const sp<SurfaceComposerClient>& client,
Robert Carrae060832016-11-28 18:51:00337 const sp<IBinder>& id, int32_t z) {
Mathias Agopian698c0872011-06-29 02:09:31338 Mutex::Autolock _l(mLock);
339 layer_state_t* s = getLayerStateLocked(client, id);
340 if (!s)
341 return BAD_INDEX;
Mathias Agopian3165cc22012-08-09 02:42:09342 s->what |= layer_state_t::eLayerChanged;
Mathias Agopian698c0872011-06-29 02:09:31343 s->z = z;
344 return NO_ERROR;
345}
346
347status_t Composer::setFlags(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-12 00:40:36348 const sp<IBinder>& id, uint32_t flags,
Mathias Agopian698c0872011-06-29 02:09:31349 uint32_t mask) {
350 Mutex::Autolock _l(mLock);
351 layer_state_t* s = getLayerStateLocked(client, id);
352 if (!s)
353 return BAD_INDEX;
Pablo Ceballos53390e12015-08-04 18:25:59354 if ((mask & layer_state_t::eLayerOpaque) ||
355 (mask & layer_state_t::eLayerHidden) ||
356 (mask & layer_state_t::eLayerSecure)) {
Dan Stoza23116082015-06-18 21:58:39357 s->what |= layer_state_t::eFlagsChanged;
Andy McFadden4125a4f2014-01-30 01:17:11358 }
Mathias Agopian698c0872011-06-29 02:09:31359 s->flags &= ~mask;
360 s->flags |= (flags & mask);
361 s->mask |= mask;
362 return NO_ERROR;
363}
364
365status_t Composer::setTransparentRegionHint(
Mathias Agopianac9fa422013-02-12 00:40:36366 const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
Mathias Agopian698c0872011-06-29 02:09:31367 const Region& transparentRegion) {
368 Mutex::Autolock _l(mLock);
369 layer_state_t* s = getLayerStateLocked(client, id);
370 if (!s)
371 return BAD_INDEX;
Mathias Agopian3165cc22012-08-09 02:42:09372 s->what |= layer_state_t::eTransparentRegionChanged;
Mathias Agopian698c0872011-06-29 02:09:31373 s->transparentRegion = transparentRegion;
374 return NO_ERROR;
375}
376
377status_t Composer::setAlpha(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-12 00:40:36378 const sp<IBinder>& id, float alpha) {
Mathias Agopian698c0872011-06-29 02:09:31379 Mutex::Autolock _l(mLock);
380 layer_state_t* s = getLayerStateLocked(client, id);
381 if (!s)
382 return BAD_INDEX;
Mathias Agopian3165cc22012-08-09 02:42:09383 s->what |= layer_state_t::eAlphaChanged;
Mathias Agopian698c0872011-06-29 02:09:31384 s->alpha = alpha;
385 return NO_ERROR;
386}
387
Mathias Agopian87855782012-07-25 04:41:09388status_t Composer::setLayerStack(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-12 00:40:36389 const sp<IBinder>& id, uint32_t layerStack) {
Mathias Agopian87855782012-07-25 04:41:09390 Mutex::Autolock _l(mLock);
391 layer_state_t* s = getLayerStateLocked(client, id);
392 if (!s)
393 return BAD_INDEX;
Mathias Agopian3165cc22012-08-09 02:42:09394 s->what |= layer_state_t::eLayerStackChanged;
Mathias Agopian87855782012-07-25 04:41:09395 s->layerStack = layerStack;
396 return NO_ERROR;
397}
398
Mathias Agopian698c0872011-06-29 02:09:31399status_t Composer::setMatrix(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-12 00:40:36400 const sp<IBinder>& id, float dsdx, float dtdx,
Mathias Agopian698c0872011-06-29 02:09:31401 float dsdy, float dtdy) {
402 Mutex::Autolock _l(mLock);
403 layer_state_t* s = getLayerStateLocked(client, id);
404 if (!s)
405 return BAD_INDEX;
Mathias Agopian3165cc22012-08-09 02:42:09406 s->what |= layer_state_t::eMatrixChanged;
Mathias Agopian698c0872011-06-29 02:09:31407 layer_state_t::matrix22_t matrix;
408 matrix.dsdx = dsdx;
409 matrix.dtdx = dtdx;
410 matrix.dsdy = dsdy;
411 matrix.dtdy = dtdy;
412 s->matrix = matrix;
413 return NO_ERROR;
414}
415
Jamie Gennisf15a83f2012-05-11 03:43:55416status_t Composer::setCrop(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-12 00:40:36417 const sp<IBinder>& id, const Rect& crop) {
Jamie Gennisf15a83f2012-05-11 03:43:55418 Mutex::Autolock _l(mLock);
419 layer_state_t* s = getLayerStateLocked(client, id);
420 if (!s)
421 return BAD_INDEX;
Mathias Agopian3165cc22012-08-09 02:42:09422 s->what |= layer_state_t::eCropChanged;
Jamie Gennisf15a83f2012-05-11 03:43:55423 s->crop = crop;
424 return NO_ERROR;
425}
426
Pablo Ceballosacbe6782016-03-04 17:54:21427status_t Composer::setFinalCrop(const sp<SurfaceComposerClient>& client,
428 const sp<IBinder>& id, const Rect& crop) {
429 Mutex::Autolock _l(mLock);
430 layer_state_t* s = getLayerStateLocked(client, id);
431 if (!s) {
432 return BAD_INDEX;
433 }
434 s->what |= layer_state_t::eFinalCropChanged;
435 s->finalCrop = crop;
436 return NO_ERROR;
437}
438
Dan Stoza7dde5992015-05-22 16:51:44439status_t Composer::deferTransactionUntil(
440 const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
441 const sp<IBinder>& handle, uint64_t frameNumber) {
442 Mutex::Autolock lock(mLock);
443 layer_state_t* s = getLayerStateLocked(client, id);
444 if (!s) {
445 return BAD_INDEX;
446 }
447 s->what |= layer_state_t::eDeferTransaction;
Robert Carr0d480722017-01-11 00:42:54448 s->barrierHandle = handle;
449 s->frameNumber = frameNumber;
450 return NO_ERROR;
451}
452
453status_t Composer::deferTransactionUntil(
454 const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
455 const sp<Surface>& barrierSurface, uint64_t frameNumber) {
456 Mutex::Autolock lock(mLock);
457 layer_state_t* s = getLayerStateLocked(client, id);
458 if (!s) {
459 return BAD_INDEX;
460 }
461 s->what |= layer_state_t::eDeferTransaction;
462 s->barrierGbp = barrierSurface->getIGraphicBufferProducer();
Dan Stoza7dde5992015-05-22 16:51:44463 s->frameNumber = frameNumber;
464 return NO_ERROR;
465}
466
Robert Carr1db73f62016-12-21 20:58:51467status_t Composer::reparentChildren(
468 const sp<SurfaceComposerClient>& client,
469 const sp<IBinder>& id,
470 const sp<IBinder>& newParentHandle) {
471 Mutex::Autolock lock(mLock);
472 layer_state_t* s = getLayerStateLocked(client, id);
473 if (!s) {
474 return BAD_INDEX;
475 }
476 s->what |= layer_state_t::eReparentChildren;
477 s->reparentHandle = newParentHandle;
478 return NO_ERROR;
479}
480
Robert Carr9524cb32017-02-13 19:32:32481status_t Composer::detachChildren(
482 const sp<SurfaceComposerClient>& client,
483 const sp<IBinder>& id) {
484 Mutex::Autolock lock(mLock);
485 layer_state_t* s = getLayerStateLocked(client, id);
486 if (!s) {
487 return BAD_INDEX;
488 }
489 s->what |= layer_state_t::eDetachChildren;
490 return NO_ERROR;
491}
492
Robert Carrc3574f72016-03-24 19:19:32493status_t Composer::setOverrideScalingMode(
494 const sp<SurfaceComposerClient>& client,
495 const sp<IBinder>& id, int32_t overrideScalingMode) {
496 Mutex::Autolock lock(mLock);
497 layer_state_t* s = getLayerStateLocked(client, id);
498 if (!s) {
499 return BAD_INDEX;
500 }
501
502 switch (overrideScalingMode) {
503 case NATIVE_WINDOW_SCALING_MODE_FREEZE:
504 case NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW:
505 case NATIVE_WINDOW_SCALING_MODE_SCALE_CROP:
506 case NATIVE_WINDOW_SCALING_MODE_NO_SCALE_CROP:
507 case -1:
508 break;
509 default:
510 ALOGE("unknown scaling mode: %d",
511 overrideScalingMode);
512 return BAD_VALUE;
513 }
514
515 s->what |= layer_state_t::eOverrideScalingModeChanged;
516 s->overrideScalingMode = overrideScalingMode;
517 return NO_ERROR;
518}
519
Robert Carr99e27f02016-06-16 22:18:02520status_t Composer::setGeometryAppliesWithResize(
Robert Carr82364e32016-05-15 18:27:47521 const sp<SurfaceComposerClient>& client,
522 const sp<IBinder>& id) {
523 Mutex::Autolock lock(mLock);
524 layer_state_t* s = getLayerStateLocked(client, id);
525 if (!s) {
526 return BAD_INDEX;
527 }
Robert Carr99e27f02016-06-16 22:18:02528 s->what |= layer_state_t::eGeometryAppliesWithResize;
Robert Carr82364e32016-05-15 18:27:47529 return NO_ERROR;
530}
531
Mathias Agopian698c0872011-06-29 02:09:31532// ---------------------------------------------------------------------------
533
Mathias Agopiane57f2922012-08-09 23:29:12534DisplayState& Composer::getDisplayStateLocked(const sp<IBinder>& token) {
535 DisplayState s;
536 s.token = token;
537 ssize_t index = mDisplayStates.indexOf(s);
538 if (index < 0) {
539 // we don't have it, add an initialized layer_state to our list
540 s.what = 0;
541 index = mDisplayStates.add(s);
542 }
Dan Stozad723bd72014-11-18 18:24:03543 return mDisplayStates.editItemAt(static_cast<size_t>(index));
Mathias Agopiane57f2922012-08-09 23:29:12544}
545
Pablo Ceballos1aad24c2016-08-04 17:24:22546status_t Composer::setDisplaySurface(const sp<IBinder>& token,
547 sp<IGraphicBufferProducer> bufferProducer) {
Pablo Ceballoseddbef82016-09-01 18:21:21548 if (bufferProducer.get() != nullptr) {
549 // Make sure that composition can never be stalled by a virtual display
550 // consumer that isn't processing buffers fast enough.
551 status_t err = bufferProducer->setAsyncMode(true);
552 if (err != NO_ERROR) {
553 ALOGE("Composer::setDisplaySurface Failed to enable async mode on the "
554 "BufferQueue. This BufferQueue cannot be used for virtual "
555 "display. (%d)", err);
556 return err;
557 }
Pablo Ceballos1aad24c2016-08-04 17:24:22558 }
Mathias Agopiane57f2922012-08-09 23:29:12559 Mutex::Autolock _l(mLock);
560 DisplayState& s(getDisplayStateLocked(token));
Andy McFadden2adaf042012-12-18 17:49:45561 s.surface = bufferProducer;
Mathias Agopiane57f2922012-08-09 23:29:12562 s.what |= DisplayState::eSurfaceChanged;
Pablo Ceballos1aad24c2016-08-04 17:24:22563 return NO_ERROR;
Mathias Agopiane57f2922012-08-09 23:29:12564}
565
566void Composer::setDisplayLayerStack(const sp<IBinder>& token,
567 uint32_t layerStack) {
568 Mutex::Autolock _l(mLock);
569 DisplayState& s(getDisplayStateLocked(token));
570 s.layerStack = layerStack;
571 s.what |= DisplayState::eLayerStackChanged;
572}
573
Mathias Agopian00e8c7a2012-09-05 02:30:46574void Composer::setDisplayProjection(const sp<IBinder>& token,
575 uint32_t orientation,
576 const Rect& layerStackRect,
577 const Rect& displayRect) {
Mathias Agopiane57f2922012-08-09 23:29:12578 Mutex::Autolock _l(mLock);
579 DisplayState& s(getDisplayStateLocked(token));
580 s.orientation = orientation;
Mathias Agopian00e8c7a2012-09-05 02:30:46581 s.viewport = layerStackRect;
582 s.frame = displayRect;
583 s.what |= DisplayState::eDisplayProjectionChanged;
Jorim Jaggi092123c2016-04-13 01:40:35584 mForceSynchronous = true; // TODO: do we actually still need this?
Mathias Agopiane57f2922012-08-09 23:29:12585}
586
Michael Wright1f6078a2014-06-26 23:01:02587void Composer::setDisplaySize(const sp<IBinder>& token, uint32_t width, uint32_t height) {
588 Mutex::Autolock _l(mLock);
589 DisplayState& s(getDisplayStateLocked(token));
590 s.width = width;
591 s.height = height;
592 s.what |= DisplayState::eDisplaySizeChanged;
593}
594
Mathias Agopiane57f2922012-08-09 23:29:12595// ---------------------------------------------------------------------------
596
The Android Open Source Projectedbf3b62009-03-04 03:31:44597SurfaceComposerClient::SurfaceComposerClient()
Mathias Agopian698c0872011-06-29 02:09:31598 : mStatus(NO_INIT), mComposer(Composer::getInstance())
The Android Open Source Projectedbf3b62009-03-04 03:31:44599{
The Android Open Source Projectedbf3b62009-03-04 03:31:44600}
601
Robert Carr1db73f62016-12-21 20:58:51602SurfaceComposerClient::SurfaceComposerClient(const sp<IGraphicBufferProducer>& root)
603 : mStatus(NO_INIT), mComposer(Composer::getInstance()), mParent(root)
604{
605}
606
Mathias Agopian698c0872011-06-29 02:09:31607void SurfaceComposerClient::onFirstRef() {
Mathias Agopiane57f2922012-08-09 23:29:12608 sp<ISurfaceComposer> sm(ComposerService::getComposerService());
Mathias Agopiand4784a32010-05-28 02:41:15609 if (sm != 0) {
Robert Carr1db73f62016-12-21 20:58:51610 auto rootProducer = mParent.promote();
611 sp<ISurfaceComposerClient> conn;
612 conn = (rootProducer != nullptr) ? sm->createScopedConnection(rootProducer) :
613 sm->createConnection();
Mathias Agopiand4784a32010-05-28 02:41:15614 if (conn != 0) {
615 mClient = conn;
Mathias Agopiand4784a32010-05-28 02:41:15616 mStatus = NO_ERROR;
617 }
618 }
The Android Open Source Projectedbf3b62009-03-04 03:31:44619}
620
Mathias Agopian698c0872011-06-29 02:09:31621SurfaceComposerClient::~SurfaceComposerClient() {
Mathias Agopian631f3582010-05-26 00:51:34622 dispose();
623}
Mathias Agopiandd3423c2009-09-23 22:44:05624
Mathias Agopian698c0872011-06-29 02:09:31625status_t SurfaceComposerClient::initCheck() const {
The Android Open Source Projectedbf3b62009-03-04 03:31:44626 return mStatus;
627}
628
Mathias Agopian698c0872011-06-29 02:09:31629sp<IBinder> SurfaceComposerClient::connection() const {
Marco Nelissen2ea926b2014-11-14 16:01:01630 return IInterface::asBinder(mClient);
The Android Open Source Projectedbf3b62009-03-04 03:31:44631}
632
Mathias Agopiand4784a32010-05-28 02:41:15633status_t SurfaceComposerClient::linkToComposerDeath(
634 const sp<IBinder::DeathRecipient>& recipient,
Mathias Agopian698c0872011-06-29 02:09:31635 void* cookie, uint32_t flags) {
Mathias Agopiane57f2922012-08-09 23:29:12636 sp<ISurfaceComposer> sm(ComposerService::getComposerService());
Marco Nelissen2ea926b2014-11-14 16:01:01637 return IInterface::asBinder(sm)->linkToDeath(recipient, cookie, flags);
The Android Open Source Projectedbf3b62009-03-04 03:31:44638}
639
Mathias Agopian698c0872011-06-29 02:09:31640void SurfaceComposerClient::dispose() {
The Android Open Source Projectedbf3b62009-03-04 03:31:44641 // this can be called more than once.
Mathias Agopian7e27f052010-05-28 21:22:23642 sp<ISurfaceComposerClient> client;
Mathias Agopiand4784a32010-05-28 02:41:15643 Mutex::Autolock _lm(mLock);
644 if (mClient != 0) {
Mathias Agopiand4784a32010-05-28 02:41:15645 client = mClient; // hold ref while lock is held
646 mClient.clear();
The Android Open Source Projectedbf3b62009-03-04 03:31:44647 }
Mathias Agopiand4784a32010-05-28 02:41:15648 mStatus = NO_INIT;
The Android Open Source Projectedbf3b62009-03-04 03:31:44649}
650
Mathias Agopian698c0872011-06-29 02:09:31651sp<SurfaceControl> SurfaceComposerClient::createSurface(
Mathias Agopian698c0872011-06-29 02:09:31652 const String8& name,
Mathias Agopian698c0872011-06-29 02:09:31653 uint32_t w,
654 uint32_t h,
655 PixelFormat format,
Robert Carr1f0a16a2016-10-24 23:27:39656 uint32_t flags,
Albert Chaulk479c60c2017-01-27 19:21:34657 SurfaceControl* parent,
658 uint32_t windowType,
659 uint32_t ownerUid)
Mathias Agopian698c0872011-06-29 02:09:31660{
Mathias Agopian4d9b8222013-03-13 00:11:48661 sp<SurfaceControl> sur;
Mathias Agopian698c0872011-06-29 02:09:31662 if (mStatus == NO_ERROR) {
Mathias Agopian4d9b8222013-03-13 00:11:48663 sp<IBinder> handle;
Robert Carr1f0a16a2016-10-24 23:27:39664 sp<IBinder> parentHandle;
Mathias Agopian4d9b8222013-03-13 00:11:48665 sp<IGraphicBufferProducer> gbp;
Robert Carr1f0a16a2016-10-24 23:27:39666
667 if (parent != nullptr) {
668 parentHandle = parent->getHandle();
669 }
670 status_t err = mClient->createSurface(name, w, h, format, flags, parentHandle,
Albert Chaulk479c60c2017-01-27 19:21:34671 windowType, ownerUid, &handle, &gbp);
Mathias Agopian4d9b8222013-03-13 00:11:48672 ALOGE_IF(err, "SurfaceComposerClient::createSurface error %s", strerror(-err));
673 if (err == NO_ERROR) {
674 sur = new SurfaceControl(this, handle, gbp);
Mathias Agopian698c0872011-06-29 02:09:31675 }
676 }
Mathias Agopian4d9b8222013-03-13 00:11:48677 return sur;
Mathias Agopian698c0872011-06-29 02:09:31678}
679
Jamie Gennisdd3cb842012-10-20 01:19:11680sp<IBinder> SurfaceComposerClient::createDisplay(const String8& displayName,
681 bool secure) {
682 return Composer::getInstance().createDisplay(displayName, secure);
Mathias Agopiane57f2922012-08-09 23:29:12683}
684
Jesse Hall6c913be2013-08-08 19:15:49685void SurfaceComposerClient::destroyDisplay(const sp<IBinder>& display) {
686 Composer::getInstance().destroyDisplay(display);
687}
688
Jeff Brown9d4e3d22012-08-25 03:00:51689sp<IBinder> SurfaceComposerClient::getBuiltInDisplay(int32_t id) {
690 return Composer::getInstance().getBuiltInDisplay(id);
691}
692
Mathias Agopianac9fa422013-02-12 00:40:36693status_t SurfaceComposerClient::destroySurface(const sp<IBinder>& sid) {
Mathias Agopian698c0872011-06-29 02:09:31694 if (mStatus != NO_ERROR)
695 return mStatus;
696 status_t err = mClient->destroySurface(sid);
697 return err;
698}
699
Svetoslavd85084b2014-03-20 17:28:31700status_t SurfaceComposerClient::clearLayerFrameStats(const sp<IBinder>& token) const {
701 if (mStatus != NO_ERROR) {
702 return mStatus;
703 }
704 return mClient->clearLayerFrameStats(token);
705}
706
707status_t SurfaceComposerClient::getLayerFrameStats(const sp<IBinder>& token,
708 FrameStats* outStats) const {
709 if (mStatus != NO_ERROR) {
710 return mStatus;
711 }
712 return mClient->getLayerFrameStats(token, outStats);
713}
714
Robert Carr367c5682016-06-20 18:55:28715status_t SurfaceComposerClient::getTransformToDisplayInverse(const sp<IBinder>& token,
716 bool* outTransformToDisplayInverse) const {
717 if (mStatus != NO_ERROR) {
718 return mStatus;
719 }
720 return mClient->getTransformToDisplayInverse(token, outTransformToDisplayInverse);
721}
722
Mathias Agopian698c0872011-06-29 02:09:31723inline Composer& SurfaceComposerClient::getComposer() {
724 return mComposer;
725}
726
727// ----------------------------------------------------------------------------
728
729void SurfaceComposerClient::openGlobalTransaction() {
Jeff Brownf3f7db62012-08-31 09:18:38730 Composer::openGlobalTransaction();
Mathias Agopian698c0872011-06-29 02:09:31731}
732
Jamie Gennis28378392011-10-13 00:39:00733void SurfaceComposerClient::closeGlobalTransaction(bool synchronous) {
734 Composer::closeGlobalTransaction(synchronous);
Mathias Agopian698c0872011-06-29 02:09:31735}
736
Jamie Gennis2d5e2302012-10-16 01:24:43737void SurfaceComposerClient::setAnimationTransaction() {
738 Composer::setAnimationTransaction();
739}
740
Sahil Dhanjuc1ba5c42016-06-08 03:09:20741status_t SurfaceComposerClient::enableVSyncInjections(bool enable) {
742 return Composer::enableVSyncInjections(enable);
743}
744
745status_t SurfaceComposerClient::injectVSync(nsecs_t when) {
746 return Composer::injectVSync(when);
747}
748
Mathias Agopian698c0872011-06-29 02:09:31749// ----------------------------------------------------------------------------
750
Mathias Agopianac9fa422013-02-12 00:40:36751status_t SurfaceComposerClient::setCrop(const sp<IBinder>& id, const Rect& crop) {
Jamie Gennisf15a83f2012-05-11 03:43:55752 return getComposer().setCrop(this, id, crop);
753}
754
Pablo Ceballosacbe6782016-03-04 17:54:21755status_t SurfaceComposerClient::setFinalCrop(const sp<IBinder>& id,
756 const Rect& crop) {
757 return getComposer().setFinalCrop(this, id, crop);
758}
759
Mathias Agopianac9fa422013-02-12 00:40:36760status_t SurfaceComposerClient::setPosition(const sp<IBinder>& id, float x, float y) {
Mathias Agopian698c0872011-06-29 02:09:31761 return getComposer().setPosition(this, id, x, y);
762}
763
Mathias Agopianac9fa422013-02-12 00:40:36764status_t SurfaceComposerClient::setSize(const sp<IBinder>& id, uint32_t w, uint32_t h) {
Mathias Agopian698c0872011-06-29 02:09:31765 return getComposer().setSize(this, id, w, h);
766}
767
Robert Carrae060832016-11-28 18:51:00768status_t SurfaceComposerClient::setLayer(const sp<IBinder>& id, int32_t z) {
Mathias Agopian698c0872011-06-29 02:09:31769 return getComposer().setLayer(this, id, z);
770}
771
Mathias Agopianac9fa422013-02-12 00:40:36772status_t SurfaceComposerClient::hide(const sp<IBinder>& id) {
Mathias Agopian698c0872011-06-29 02:09:31773 return getComposer().setFlags(this, id,
Mathias Agopian3165cc22012-08-09 02:42:09774 layer_state_t::eLayerHidden,
775 layer_state_t::eLayerHidden);
Mathias Agopian698c0872011-06-29 02:09:31776}
777
Mathias Agopianac9fa422013-02-12 00:40:36778status_t SurfaceComposerClient::show(const sp<IBinder>& id) {
Mathias Agopian698c0872011-06-29 02:09:31779 return getComposer().setFlags(this, id,
780 0,
Mathias Agopian3165cc22012-08-09 02:42:09781 layer_state_t::eLayerHidden);
Mathias Agopian698c0872011-06-29 02:09:31782}
783
Mathias Agopianac9fa422013-02-12 00:40:36784status_t SurfaceComposerClient::setFlags(const sp<IBinder>& id, uint32_t flags,
Mathias Agopian698c0872011-06-29 02:09:31785 uint32_t mask) {
786 return getComposer().setFlags(this, id, flags, mask);
787}
788
Mathias Agopianac9fa422013-02-12 00:40:36789status_t SurfaceComposerClient::setTransparentRegionHint(const sp<IBinder>& id,
Mathias Agopian698c0872011-06-29 02:09:31790 const Region& transparentRegion) {
791 return getComposer().setTransparentRegionHint(this, id, transparentRegion);
792}
793
Mathias Agopianac9fa422013-02-12 00:40:36794status_t SurfaceComposerClient::setAlpha(const sp<IBinder>& id, float alpha) {
Mathias Agopian698c0872011-06-29 02:09:31795 return getComposer().setAlpha(this, id, alpha);
796}
797
Mathias Agopianac9fa422013-02-12 00:40:36798status_t SurfaceComposerClient::setLayerStack(const sp<IBinder>& id, uint32_t layerStack) {
Mathias Agopian87855782012-07-25 04:41:09799 return getComposer().setLayerStack(this, id, layerStack);
800}
801
Mathias Agopianac9fa422013-02-12 00:40:36802status_t SurfaceComposerClient::setMatrix(const sp<IBinder>& id, float dsdx, float dtdx,
Mathias Agopian698c0872011-06-29 02:09:31803 float dsdy, float dtdy) {
804 return getComposer().setMatrix(this, id, dsdx, dtdx, dsdy, dtdy);
805}
806
Dan Stoza7dde5992015-05-22 16:51:44807status_t SurfaceComposerClient::deferTransactionUntil(const sp<IBinder>& id,
808 const sp<IBinder>& handle, uint64_t frameNumber) {
809 return getComposer().deferTransactionUntil(this, id, handle, frameNumber);
810}
811
Robert Carr0d480722017-01-11 00:42:54812status_t SurfaceComposerClient::deferTransactionUntil(const sp<IBinder>& id,
813 const sp<Surface>& barrierSurface, uint64_t frameNumber) {
814 return getComposer().deferTransactionUntil(this, id, barrierSurface, frameNumber);
815}
816
Robert Carr1db73f62016-12-21 20:58:51817status_t SurfaceComposerClient::reparentChildren(const sp<IBinder>& id,
818 const sp<IBinder>& newParentHandle) {
819 return getComposer().reparentChildren(this, id, newParentHandle);
820}
821
Robert Carr9524cb32017-02-13 19:32:32822status_t SurfaceComposerClient::detachChildren(const sp<IBinder>& id) {
823 return getComposer().detachChildren(this, id);
824}
825
Robert Carrc3574f72016-03-24 19:19:32826status_t SurfaceComposerClient::setOverrideScalingMode(
827 const sp<IBinder>& id, int32_t overrideScalingMode) {
828 return getComposer().setOverrideScalingMode(
829 this, id, overrideScalingMode);
830}
831
Robert Carr99e27f02016-06-16 22:18:02832status_t SurfaceComposerClient::setGeometryAppliesWithResize(
Robert Carr82364e32016-05-15 18:27:47833 const sp<IBinder>& id) {
Robert Carr99e27f02016-06-16 22:18:02834 return getComposer().setGeometryAppliesWithResize(this, id);
Robert Carr82364e32016-05-15 18:27:47835}
836
Mathias Agopian698c0872011-06-29 02:09:31837// ----------------------------------------------------------------------------
838
Pablo Ceballos1aad24c2016-08-04 17:24:22839status_t SurfaceComposerClient::setDisplaySurface(const sp<IBinder>& token,
840 sp<IGraphicBufferProducer> bufferProducer) {
841 return Composer::getInstance().setDisplaySurface(token, bufferProducer);
Mathias Agopiane57f2922012-08-09 23:29:12842}
843
844void SurfaceComposerClient::setDisplayLayerStack(const sp<IBinder>& token,
845 uint32_t layerStack) {
846 Composer::getInstance().setDisplayLayerStack(token, layerStack);
847}
848
Mathias Agopian00e8c7a2012-09-05 02:30:46849void SurfaceComposerClient::setDisplayProjection(const sp<IBinder>& token,
850 uint32_t orientation,
851 const Rect& layerStackRect,
852 const Rect& displayRect) {
853 Composer::getInstance().setDisplayProjection(token, orientation,
854 layerStackRect, displayRect);
Mathias Agopiane57f2922012-08-09 23:29:12855}
856
Michael Wright1f6078a2014-06-26 23:01:02857void SurfaceComposerClient::setDisplaySize(const sp<IBinder>& token,
858 uint32_t width, uint32_t height) {
859 Composer::getInstance().setDisplaySize(token, width, height);
860}
861
Mathias Agopiane57f2922012-08-09 23:29:12862// ----------------------------------------------------------------------------
863
Dan Stoza7f7da322014-05-02 22:26:25864status_t SurfaceComposerClient::getDisplayConfigs(
865 const sp<IBinder>& display, Vector<DisplayInfo>* configs)
The Android Open Source Projectedbf3b62009-03-04 03:31:44866{
Dan Stoza7f7da322014-05-02 22:26:25867 return ComposerService::getComposerService()->getDisplayConfigs(display, configs);
868}
869
870status_t SurfaceComposerClient::getDisplayInfo(const sp<IBinder>& display,
871 DisplayInfo* info) {
872 Vector<DisplayInfo> configs;
873 status_t result = getDisplayConfigs(display, &configs);
874 if (result != NO_ERROR) {
875 return result;
876 }
877
878 int activeId = getActiveConfig(display);
879 if (activeId < 0) {
880 ALOGE("No active configuration found");
881 return NAME_NOT_FOUND;
882 }
883
Dan Stozad723bd72014-11-18 18:24:03884 *info = configs[static_cast<size_t>(activeId)];
Dan Stoza7f7da322014-05-02 22:26:25885 return NO_ERROR;
886}
887
888int SurfaceComposerClient::getActiveConfig(const sp<IBinder>& display) {
889 return ComposerService::getComposerService()->getActiveConfig(display);
890}
891
892status_t SurfaceComposerClient::setActiveConfig(const sp<IBinder>& display, int id) {
893 return ComposerService::getComposerService()->setActiveConfig(display, id);
The Android Open Source Projectedbf3b62009-03-04 03:31:44894}
895
Michael Wright28f24d02016-07-12 20:30:53896status_t SurfaceComposerClient::getDisplayColorModes(const sp<IBinder>& display,
897 Vector<android_color_mode_t>* outColorModes) {
898 return ComposerService::getComposerService()->getDisplayColorModes(display, outColorModes);
899}
900
901android_color_mode_t SurfaceComposerClient::getActiveColorMode(const sp<IBinder>& display) {
902 return ComposerService::getComposerService()->getActiveColorMode(display);
903}
904
905status_t SurfaceComposerClient::setActiveColorMode(const sp<IBinder>& display,
906 android_color_mode_t colorMode) {
907 return ComposerService::getComposerService()->setActiveColorMode(display, colorMode);
908}
909
Prashant Malani2c9b11f2014-05-25 08:36:31910void SurfaceComposerClient::setDisplayPowerMode(const sp<IBinder>& token,
911 int mode) {
912 ComposerService::getComposerService()->setPowerMode(token, mode);
Jeff Brown2a09bb32012-10-09 02:13:57913}
914
Svetoslavd85084b2014-03-20 17:28:31915status_t SurfaceComposerClient::clearAnimationFrameStats() {
916 return ComposerService::getComposerService()->clearAnimationFrameStats();
917}
918
919status_t SurfaceComposerClient::getAnimationFrameStats(FrameStats* outStats) {
920 return ComposerService::getComposerService()->getAnimationFrameStats(outStats);
921}
922
Dan Stozac4f471e2016-03-24 16:31:08923status_t SurfaceComposerClient::getHdrCapabilities(const sp<IBinder>& display,
924 HdrCapabilities* outCapabilities) {
925 return ComposerService::getComposerService()->getHdrCapabilities(display,
926 outCapabilities);
927}
928
Mathias Agopian698c0872011-06-29 02:09:31929// ----------------------------------------------------------------------------
The Android Open Source Projectedbf3b62009-03-04 03:31:44930
Mathias Agopian2a9fc492013-03-01 21:42:57931status_t ScreenshotClient::capture(
932 const sp<IBinder>& display,
933 const sp<IGraphicBufferProducer>& producer,
Dan Stozac1879002014-05-22 22:59:05934 Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
Robert Carrae060832016-11-28 18:51:00935 int32_t minLayerZ, int32_t maxLayerZ, bool useIdentityTransform) {
Mathias Agopian2a9fc492013-03-01 21:42:57936 sp<ISurfaceComposer> s(ComposerService::getComposerService());
937 if (s == NULL) return NO_INIT;
Dan Stozac1879002014-05-22 22:59:05938 return s->captureScreen(display, producer, sourceCrop,
Dan Stozac7014012014-02-14 23:03:43939 reqWidth, reqHeight, minLayerZ, maxLayerZ, useIdentityTransform);
Mathias Agopian2a9fc492013-03-01 21:42:57940}
941
Robert Carr673134e2017-01-10 03:48:38942status_t ScreenshotClient::captureToBuffer(const sp<IBinder>& display,
943 Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
Robert Carrae060832016-11-28 18:51:00944 int32_t minLayerZ, int32_t maxLayerZ, bool useIdentityTransform,
Robert Carr673134e2017-01-10 03:48:38945 uint32_t rotation,
946 sp<GraphicBuffer>* outBuffer) {
947 sp<ISurfaceComposer> s(ComposerService::getComposerService());
948 if (s == NULL) return NO_INIT;
949
950 sp<IGraphicBufferConsumer> gbpConsumer;
951 sp<IGraphicBufferProducer> producer;
952 BufferQueue::createBufferQueue(&producer, &gbpConsumer);
953 sp<BufferItemConsumer> consumer(new BufferItemConsumer(gbpConsumer,
954 GRALLOC_USAGE_HW_TEXTURE | GRALLOC_USAGE_SW_READ_NEVER | GRALLOC_USAGE_SW_WRITE_NEVER,
955 1, true));
956
957 status_t ret = s->captureScreen(display, producer, sourceCrop, reqWidth, reqHeight,
958 minLayerZ, maxLayerZ, useIdentityTransform,
959 static_cast<ISurfaceComposer::Rotation>(rotation));
960 if (ret != NO_ERROR) {
961 return ret;
962 }
963 BufferItem b;
964 consumer->acquireBuffer(&b, 0, true);
965 *outBuffer = b.mGraphicBuffer;
966 return ret;
967}
968
Mathias Agopian74c40c02010-09-29 20:02:36969ScreenshotClient::ScreenshotClient()
Mathias Agopianabe815d2013-03-20 05:22:21970 : mHaveBuffer(false) {
971 memset(&mBuffer, 0, sizeof(mBuffer));
Mathias Agopian74c40c02010-09-29 20:02:36972}
973
Mathias Agopian8000d062013-03-27 01:15:35974ScreenshotClient::~ScreenshotClient() {
975 ScreenshotClient::release();
976}
977
Mathias Agopianabe815d2013-03-20 05:22:21978sp<CpuConsumer> ScreenshotClient::getCpuConsumer() const {
979 if (mCpuConsumer == NULL) {
Dan Stoza6d5a7bb2014-03-13 18:39:09980 sp<IGraphicBufferConsumer> consumer;
981 BufferQueue::createBufferQueue(&mProducer, &consumer);
982 mCpuConsumer = new CpuConsumer(consumer, 1);
Mathias Agopianabe815d2013-03-20 05:22:21983 mCpuConsumer->setName(String8("ScreenshotClient"));
984 }
985 return mCpuConsumer;
Mathias Agopianbf2c6a62010-12-11 00:22:31986}
987
Jeff Brown9d4e3d22012-08-25 03:00:51988status_t ScreenshotClient::update(const sp<IBinder>& display,
Dan Stozac1879002014-05-22 22:59:05989 Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
Robert Carrae060832016-11-28 18:51:00990 int32_t minLayerZ, int32_t maxLayerZ,
Riley Andrewsd15ef272014-09-04 23:19:44991 bool useIdentityTransform, uint32_t rotation) {
Mathias Agopianbf2c6a62010-12-11 00:22:31992 sp<ISurfaceComposer> s(ComposerService::getComposerService());
993 if (s == NULL) return NO_INIT;
Mathias Agopianabe815d2013-03-20 05:22:21994 sp<CpuConsumer> cpuConsumer = getCpuConsumer();
995
996 if (mHaveBuffer) {
997 mCpuConsumer->unlockBuffer(mBuffer);
998 memset(&mBuffer, 0, sizeof(mBuffer));
999 mHaveBuffer = false;
1000 }
1001
Dan Stozac1879002014-05-22 22:59:051002 status_t err = s->captureScreen(display, mProducer, sourceCrop,
Riley Andrewsd15ef272014-09-04 23:19:441003 reqWidth, reqHeight, minLayerZ, maxLayerZ, useIdentityTransform,
1004 static_cast<ISurfaceComposer::Rotation>(rotation));
Mathias Agopianabe815d2013-03-20 05:22:211005
1006 if (err == NO_ERROR) {
1007 err = mCpuConsumer->lockNextBuffer(&mBuffer);
1008 if (err == NO_ERROR) {
1009 mHaveBuffer = true;
1010 }
1011 }
1012 return err;
1013}
1014
Riley Andrewsd15ef272014-09-04 23:19:441015status_t ScreenshotClient::update(const sp<IBinder>& display,
1016 Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
Robert Carrae060832016-11-28 18:51:001017 int32_t minLayerZ, int32_t maxLayerZ,
Riley Andrewsd15ef272014-09-04 23:19:441018 bool useIdentityTransform) {
1019
1020 return ScreenshotClient::update(display, sourceCrop, reqWidth, reqHeight,
1021 minLayerZ, maxLayerZ, useIdentityTransform, ISurfaceComposer::eRotateNone);
1022}
1023
Dan Stozac1879002014-05-22 22:59:051024status_t ScreenshotClient::update(const sp<IBinder>& display, Rect sourceCrop,
Dan Stozac7014012014-02-14 23:03:431025 bool useIdentityTransform) {
Robert Carrae060832016-11-28 18:51:001026 return ScreenshotClient::update(display, sourceCrop, 0, 0,
1027 INT32_MIN, INT32_MAX,
Riley Andrewsd15ef272014-09-04 23:19:441028 useIdentityTransform, ISurfaceComposer::eRotateNone);
Mathias Agopianabe815d2013-03-20 05:22:211029}
1030
Dan Stozac1879002014-05-22 22:59:051031status_t ScreenshotClient::update(const sp<IBinder>& display, Rect sourceCrop,
Dan Stozac7014012014-02-14 23:03:431032 uint32_t reqWidth, uint32_t reqHeight, bool useIdentityTransform) {
Dan Stozac1879002014-05-22 22:59:051033 return ScreenshotClient::update(display, sourceCrop, reqWidth, reqHeight,
Robert Carrae060832016-11-28 18:51:001034 INT32_MIN, INT32_MAX,
1035 useIdentityTransform, ISurfaceComposer::eRotateNone);
Mathias Agopian74c40c02010-09-29 20:02:361036}
1037
1038void ScreenshotClient::release() {
Mathias Agopianabe815d2013-03-20 05:22:211039 if (mHaveBuffer) {
1040 mCpuConsumer->unlockBuffer(mBuffer);
1041 memset(&mBuffer, 0, sizeof(mBuffer));
1042 mHaveBuffer = false;
1043 }
1044 mCpuConsumer.clear();
Mathias Agopian74c40c02010-09-29 20:02:361045}
1046
1047void const* ScreenshotClient::getPixels() const {
Mathias Agopianabe815d2013-03-20 05:22:211048 return mBuffer.data;
Mathias Agopian74c40c02010-09-29 20:02:361049}
1050
1051uint32_t ScreenshotClient::getWidth() const {
Mathias Agopianabe815d2013-03-20 05:22:211052 return mBuffer.width;
Mathias Agopian74c40c02010-09-29 20:02:361053}
1054
1055uint32_t ScreenshotClient::getHeight() const {
Mathias Agopianabe815d2013-03-20 05:22:211056 return mBuffer.height;
Mathias Agopian74c40c02010-09-29 20:02:361057}
1058
1059PixelFormat ScreenshotClient::getFormat() const {
Mathias Agopianabe815d2013-03-20 05:22:211060 return mBuffer.format;
Mathias Agopian74c40c02010-09-29 20:02:361061}
1062
1063uint32_t ScreenshotClient::getStride() const {
Mathias Agopianabe815d2013-03-20 05:22:211064 return mBuffer.stride;
Mathias Agopian74c40c02010-09-29 20:02:361065}
1066
1067size_t ScreenshotClient::getSize() const {
Mathias Agopianabe815d2013-03-20 05:22:211068 return mBuffer.stride * mBuffer.height * bytesPerPixel(mBuffer.format);
Mathias Agopian74c40c02010-09-29 20:02:361069}
1070
1071// ----------------------------------------------------------------------------
The Android Open Source Projectedbf3b62009-03-04 03:31:441072}; // namespace android