blob: 58b2a8737a98c850958f6607149fbba090263284 [file] [log] [blame]
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#define LOG_TAG "SurfaceComposerClient"
18
19#include <stdint.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080020#include <sys/types.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080021
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080022#include <utils/Errors.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080023#include <utils/Log.h>
Mathias Agopiand4784a32010-05-27 19:41:15 -070024#include <utils/Singleton.h>
Mathias Agopiana67932f2011-04-20 14:20:59 -070025#include <utils/SortedVector.h>
26#include <utils/String8.h>
27#include <utils/threads.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080028
Mathias Agopian9cce3252010-02-09 17:46:37 -080029#include <binder/IMemory.h>
Mathias Agopiana67932f2011-04-20 14:20:59 -070030#include <binder/IServiceManager.h>
Mathias Agopian9cce3252010-02-09 17:46:37 -080031
Michael Wright28f24d02016-07-12 13:30:53 -070032#include <system/graphics.h>
33
Mathias Agopian076b1cc2009-04-10 14:24:30 -070034#include <ui/DisplayInfo.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080035
Robert Carr673134e2017-01-09 19:48:38 -080036#include <gui/BufferItemConsumer.h>
Mathias Agopianabe815d2013-03-19 22:22:21 -070037#include <gui/CpuConsumer.h>
Mathias Agopiane3c697f2013-02-14 17:11:02 -080038#include <gui/IGraphicBufferProducer.h>
Mathias Agopian90ac7992012-02-25 18:48:35 -080039#include <gui/ISurfaceComposer.h>
40#include <gui/ISurfaceComposerClient.h>
41#include <gui/SurfaceComposerClient.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080042
Mathias Agopian41f673c2011-11-17 17:48:35 -080043#include <private/gui/ComposerService.h>
Mathias Agopian90ac7992012-02-25 18:48:35 -080044#include <private/gui/LayerState.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080045
46namespace android {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080047// ---------------------------------------------------------------------------
48
Mathias Agopian7e27f052010-05-28 14:22:23 -070049ANDROID_SINGLETON_STATIC_INSTANCE(ComposerService);
50
Mathias Agopianb7e930d2010-06-01 15:12:58 -070051ComposerService::ComposerService()
52: Singleton<ComposerService>() {
Andy McFadden6652b3e2012-09-06 18:45:56 -070053 Mutex::Autolock _l(mLock);
54 connectLocked();
55}
56
57void ComposerService::connectLocked() {
Mathias Agopianb7e930d2010-06-01 15:12:58 -070058 const String16 name("SurfaceFlinger");
59 while (getService(name, &mComposerService) != NO_ERROR) {
60 usleep(250000);
61 }
Andy McFadden6652b3e2012-09-06 18:45:56 -070062 assert(mComposerService != NULL);
63
64 // Create the death listener.
65 class DeathObserver : public IBinder::DeathRecipient {
66 ComposerService& mComposerService;
67 virtual void binderDied(const wp<IBinder>& who) {
68 ALOGW("ComposerService remote (surfaceflinger) died [%p]",
69 who.unsafe_get());
70 mComposerService.composerServiceDied();
71 }
72 public:
Chih-Hung Hsiehe2347b72016-04-25 15:41:05 -070073 explicit DeathObserver(ComposerService& mgr) : mComposerService(mgr) { }
Andy McFadden6652b3e2012-09-06 18:45:56 -070074 };
75
76 mDeathObserver = new DeathObserver(*const_cast<ComposerService*>(this));
Marco Nelissen2ea926b2014-11-14 08:01:01 -080077 IInterface::asBinder(mComposerService)->linkToDeath(mDeathObserver);
Mathias Agopianb7e930d2010-06-01 15:12:58 -070078}
79
Andy McFadden6652b3e2012-09-06 18:45:56 -070080/*static*/ sp<ISurfaceComposer> ComposerService::getComposerService() {
81 ComposerService& instance = ComposerService::getInstance();
82 Mutex::Autolock _l(instance.mLock);
83 if (instance.mComposerService == NULL) {
84 ComposerService::getInstance().connectLocked();
85 assert(instance.mComposerService != NULL);
86 ALOGD("ComposerService reconnected");
87 }
88 return instance.mComposerService;
89}
90
91void ComposerService::composerServiceDied()
92{
93 Mutex::Autolock _l(mLock);
94 mComposerService = NULL;
95 mDeathObserver = NULL;
Mathias Agopianb7e930d2010-06-01 15:12:58 -070096}
97
Mathias Agopian7e27f052010-05-28 14:22:23 -070098// ---------------------------------------------------------------------------
99
Mathias Agopian698c0872011-06-28 19:09:31 -0700100static inline
Mathias Agopiane57f2922012-08-09 16:29:12 -0700101int compare_type(const ComposerState& lhs, const ComposerState& rhs) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700102 if (lhs.client < rhs.client) return -1;
103 if (lhs.client > rhs.client) return 1;
104 if (lhs.state.surface < rhs.state.surface) return -1;
105 if (lhs.state.surface > rhs.state.surface) return 1;
106 return 0;
107}
108
Mathias Agopiane57f2922012-08-09 16:29:12 -0700109static inline
110int compare_type(const DisplayState& lhs, const DisplayState& rhs) {
111 return compare_type(lhs.token, rhs.token);
112}
113
Mathias Agopian7e27f052010-05-28 14:22:23 -0700114class Composer : public Singleton<Composer>
115{
Mathias Agopiand4784a32010-05-27 19:41:15 -0700116 friend class Singleton<Composer>;
117
Mathias Agopian698c0872011-06-28 19:09:31 -0700118 mutable Mutex mLock;
Mathias Agopiane57f2922012-08-09 16:29:12 -0700119 SortedVector<ComposerState> mComposerStates;
120 SortedVector<DisplayState > mDisplayStates;
Jamie Gennis28378392011-10-12 17:39:00 -0700121 uint32_t mForceSynchronous;
Jeff Brownf3f7db62012-08-31 02:18:38 -0700122 uint32_t mTransactionNestCount;
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700123 bool mAnimation;
Mathias Agopian698c0872011-06-28 19:09:31 -0700124
Jamie Gennisb8d69a52011-10-10 15:48:06 -0700125 Composer() : Singleton<Composer>(),
Jeff Brownf3f7db62012-08-31 02:18:38 -0700126 mForceSynchronous(0), mTransactionNestCount(0),
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700127 mAnimation(false)
Jamie Gennis28378392011-10-12 17:39:00 -0700128 { }
Mathias Agopian698c0872011-06-28 19:09:31 -0700129
Jeff Brownf3f7db62012-08-31 02:18:38 -0700130 void openGlobalTransactionImpl();
Jamie Gennis28378392011-10-12 17:39:00 -0700131 void closeGlobalTransactionImpl(bool synchronous);
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700132 void setAnimationTransactionImpl();
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -0700133 status_t enableVSyncInjectionsImpl(bool enable);
134 status_t injectVSyncImpl(nsecs_t when);
Mathias Agopian698c0872011-06-28 19:09:31 -0700135
136 layer_state_t* getLayerStateLocked(
Mathias Agopianac9fa422013-02-11 16:40:36 -0800137 const sp<SurfaceComposerClient>& client, const sp<IBinder>& id);
Mathias Agopian698c0872011-06-28 19:09:31 -0700138
Mathias Agopiane57f2922012-08-09 16:29:12 -0700139 DisplayState& getDisplayStateLocked(const sp<IBinder>& token);
140
Mathias Agopiand4784a32010-05-27 19:41:15 -0700141public:
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700142 sp<IBinder> createDisplay(const String8& displayName, bool secure);
Jesse Hall6c913be2013-08-08 12:15:49 -0700143 void destroyDisplay(const sp<IBinder>& display);
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700144 sp<IBinder> getBuiltInDisplay(int32_t id);
Mathias Agopian698c0872011-06-28 19:09:31 -0700145
Mathias Agopianac9fa422013-02-11 16:40:36 -0800146 status_t setPosition(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
Mathias Agopian41b6aab2011-08-30 18:51:54 -0700147 float x, float y);
Mathias Agopianac9fa422013-02-11 16:40:36 -0800148 status_t setSize(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
Mathias Agopian698c0872011-06-28 19:09:31 -0700149 uint32_t w, uint32_t h);
Mathias Agopianac9fa422013-02-11 16:40:36 -0800150 status_t setLayer(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
Dan Stozad723bd72014-11-18 10:24:03 -0800151 uint32_t z);
Mathias Agopianac9fa422013-02-11 16:40:36 -0800152 status_t setFlags(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
Mathias Agopian698c0872011-06-28 19:09:31 -0700153 uint32_t flags, uint32_t mask);
154 status_t setTransparentRegionHint(
Mathias Agopianac9fa422013-02-11 16:40:36 -0800155 const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
Mathias Agopian698c0872011-06-28 19:09:31 -0700156 const Region& transparentRegion);
Mathias Agopianac9fa422013-02-11 16:40:36 -0800157 status_t setAlpha(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
Mathias Agopian698c0872011-06-28 19:09:31 -0700158 float alpha);
Mathias Agopianac9fa422013-02-11 16:40:36 -0800159 status_t setMatrix(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
Mathias Agopian698c0872011-06-28 19:09:31 -0700160 float dsdx, float dtdx, float dsdy, float dtdy);
Jamie Gennisb8d69a52011-10-10 15:48:06 -0700161 status_t setOrientation(int orientation);
Mathias Agopianac9fa422013-02-11 16:40:36 -0800162 status_t setCrop(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700163 const Rect& crop);
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000164 status_t setFinalCrop(const sp<SurfaceComposerClient>& client,
165 const sp<IBinder>& id, const Rect& crop);
Mathias Agopian87855782012-07-24 21:41:09 -0700166 status_t setLayerStack(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-11 16:40:36 -0800167 const sp<IBinder>& id, uint32_t layerStack);
Dan Stoza7dde5992015-05-22 09:51:44 -0700168 status_t deferTransactionUntil(const sp<SurfaceComposerClient>& client,
169 const sp<IBinder>& id, const sp<IBinder>& handle,
170 uint64_t frameNumber);
Robert Carrc3574f72016-03-24 12:19:32 -0700171 status_t setOverrideScalingMode(const sp<SurfaceComposerClient>& client,
172 const sp<IBinder>& id, int32_t overrideScalingMode);
Robert Carr99e27f02016-06-16 15:18:02 -0700173 status_t setGeometryAppliesWithResize(const sp<SurfaceComposerClient>& client,
Robert Carr82364e32016-05-15 11:27:47 -0700174 const sp<IBinder>& id);
Mathias Agopian698c0872011-06-28 19:09:31 -0700175
Pablo Ceballos1aad24c2016-08-04 10:24:22 -0700176 status_t setDisplaySurface(const sp<IBinder>& token,
177 sp<IGraphicBufferProducer> bufferProducer);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700178 void setDisplayLayerStack(const sp<IBinder>& token, uint32_t layerStack);
Mathias Agopian00e8c7a2012-09-04 19:30:46 -0700179 void setDisplayProjection(const sp<IBinder>& token,
180 uint32_t orientation,
181 const Rect& layerStackRect,
182 const Rect& displayRect);
Michael Wright1f6078a2014-06-26 16:01:02 -0700183 void setDisplaySize(const sp<IBinder>& token, uint32_t width, uint32_t height);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700184
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700185 static void setAnimationTransaction() {
186 Composer::getInstance().setAnimationTransactionImpl();
187 }
188
Jeff Brownf3f7db62012-08-31 02:18:38 -0700189 static void openGlobalTransaction() {
190 Composer::getInstance().openGlobalTransactionImpl();
191 }
192
Jamie Gennis28378392011-10-12 17:39:00 -0700193 static void closeGlobalTransaction(bool synchronous) {
194 Composer::getInstance().closeGlobalTransactionImpl(synchronous);
Mathias Agopiand4784a32010-05-27 19:41:15 -0700195 }
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -0700196
197 static status_t enableVSyncInjections(bool enable) {
198 return Composer::getInstance().enableVSyncInjectionsImpl(enable);
199 }
200
201 static status_t injectVSync(nsecs_t when) {
202 return Composer::getInstance().injectVSyncImpl(when);
203 }
Mathias Agopiand4784a32010-05-27 19:41:15 -0700204};
205
206ANDROID_SINGLETON_STATIC_INSTANCE(Composer);
207
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800208// ---------------------------------------------------------------------------
209
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700210sp<IBinder> Composer::createDisplay(const String8& displayName, bool secure) {
211 return ComposerService::getComposerService()->createDisplay(displayName,
212 secure);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700213}
214
Jesse Hall6c913be2013-08-08 12:15:49 -0700215void Composer::destroyDisplay(const sp<IBinder>& display) {
216 return ComposerService::getComposerService()->destroyDisplay(display);
217}
218
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700219sp<IBinder> Composer::getBuiltInDisplay(int32_t id) {
220 return ComposerService::getComposerService()->getBuiltInDisplay(id);
221}
222
Jeff Brownf3f7db62012-08-31 02:18:38 -0700223void Composer::openGlobalTransactionImpl() {
224 { // scope for the lock
225 Mutex::Autolock _l(mLock);
226 mTransactionNestCount += 1;
227 }
228}
229
Jamie Gennis28378392011-10-12 17:39:00 -0700230void Composer::closeGlobalTransactionImpl(bool synchronous) {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700231 sp<ISurfaceComposer> sm(ComposerService::getComposerService());
Mathias Agopian698c0872011-06-28 19:09:31 -0700232
233 Vector<ComposerState> transaction;
Mathias Agopian8b33f032012-07-24 20:43:54 -0700234 Vector<DisplayState> displayTransaction;
Jamie Gennis28378392011-10-12 17:39:00 -0700235 uint32_t flags = 0;
Mathias Agopian698c0872011-06-28 19:09:31 -0700236
237 { // scope for the lock
238 Mutex::Autolock _l(mLock);
Jeff Brownf3f7db62012-08-31 02:18:38 -0700239 mForceSynchronous |= synchronous;
240 if (!mTransactionNestCount) {
241 ALOGW("At least one call to closeGlobalTransaction() was not matched by a prior "
242 "call to openGlobalTransaction().");
243 } else if (--mTransactionNestCount) {
244 return;
245 }
246
Mathias Agopiane57f2922012-08-09 16:29:12 -0700247 transaction = mComposerStates;
248 mComposerStates.clear();
Jamie Gennisb8d69a52011-10-10 15:48:06 -0700249
Mathias Agopiane57f2922012-08-09 16:29:12 -0700250 displayTransaction = mDisplayStates;
251 mDisplayStates.clear();
Jamie Gennis28378392011-10-12 17:39:00 -0700252
Jeff Brownf3f7db62012-08-31 02:18:38 -0700253 if (mForceSynchronous) {
Jamie Gennis28378392011-10-12 17:39:00 -0700254 flags |= ISurfaceComposer::eSynchronous;
255 }
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700256 if (mAnimation) {
257 flags |= ISurfaceComposer::eAnimation;
258 }
259
Jamie Gennis28378392011-10-12 17:39:00 -0700260 mForceSynchronous = false;
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700261 mAnimation = false;
Mathias Agopian698c0872011-06-28 19:09:31 -0700262 }
263
Mathias Agopian8b33f032012-07-24 20:43:54 -0700264 sm->setTransactionState(transaction, displayTransaction, flags);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800265}
266
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -0700267status_t Composer::enableVSyncInjectionsImpl(bool enable) {
268 sp<ISurfaceComposer> sm(ComposerService::getComposerService());
269 return sm->enableVSyncInjections(enable);
270}
271
272status_t Composer::injectVSyncImpl(nsecs_t when) {
273 sp<ISurfaceComposer> sm(ComposerService::getComposerService());
274 return sm->injectVSync(when);
275}
276
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700277void Composer::setAnimationTransactionImpl() {
278 Mutex::Autolock _l(mLock);
279 mAnimation = true;
280}
281
Mathias Agopian698c0872011-06-28 19:09:31 -0700282layer_state_t* Composer::getLayerStateLocked(
Mathias Agopianac9fa422013-02-11 16:40:36 -0800283 const sp<SurfaceComposerClient>& client, const sp<IBinder>& id) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700284
285 ComposerState s;
286 s.client = client->mClient;
287 s.state.surface = id;
288
Mathias Agopiane57f2922012-08-09 16:29:12 -0700289 ssize_t index = mComposerStates.indexOf(s);
Mathias Agopian698c0872011-06-28 19:09:31 -0700290 if (index < 0) {
291 // we don't have it, add an initialized layer_state to our list
Mathias Agopiane57f2922012-08-09 16:29:12 -0700292 index = mComposerStates.add(s);
Mathias Agopian698c0872011-06-28 19:09:31 -0700293 }
294
Mathias Agopiane57f2922012-08-09 16:29:12 -0700295 ComposerState* const out = mComposerStates.editArray();
Mathias Agopian698c0872011-06-28 19:09:31 -0700296 return &(out[index].state);
297}
298
299status_t Composer::setPosition(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-11 16:40:36 -0800300 const sp<IBinder>& id, float x, float y) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700301 Mutex::Autolock _l(mLock);
302 layer_state_t* s = getLayerStateLocked(client, id);
303 if (!s)
304 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700305 s->what |= layer_state_t::ePositionChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700306 s->x = x;
307 s->y = y;
308 return NO_ERROR;
309}
310
311status_t Composer::setSize(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-11 16:40:36 -0800312 const sp<IBinder>& id, uint32_t w, uint32_t h) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700313 Mutex::Autolock _l(mLock);
314 layer_state_t* s = getLayerStateLocked(client, id);
315 if (!s)
316 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700317 s->what |= layer_state_t::eSizeChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700318 s->w = w;
319 s->h = h;
Jamie Gennis28378392011-10-12 17:39:00 -0700320
Jorim Jaggi092123c2016-04-13 01:40:35 +0000321 // Resizing a surface makes the transaction synchronous.
322 mForceSynchronous = true;
323
Mathias Agopian698c0872011-06-28 19:09:31 -0700324 return NO_ERROR;
325}
326
327status_t Composer::setLayer(const sp<SurfaceComposerClient>& client,
Dan Stozad723bd72014-11-18 10:24:03 -0800328 const sp<IBinder>& id, uint32_t z) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700329 Mutex::Autolock _l(mLock);
330 layer_state_t* s = getLayerStateLocked(client, id);
331 if (!s)
332 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700333 s->what |= layer_state_t::eLayerChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700334 s->z = z;
335 return NO_ERROR;
336}
337
338status_t Composer::setFlags(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-11 16:40:36 -0800339 const sp<IBinder>& id, uint32_t flags,
Mathias Agopian698c0872011-06-28 19:09:31 -0700340 uint32_t mask) {
341 Mutex::Autolock _l(mLock);
342 layer_state_t* s = getLayerStateLocked(client, id);
343 if (!s)
344 return BAD_INDEX;
Pablo Ceballos53390e12015-08-04 11:25:59 -0700345 if ((mask & layer_state_t::eLayerOpaque) ||
346 (mask & layer_state_t::eLayerHidden) ||
347 (mask & layer_state_t::eLayerSecure)) {
Dan Stoza23116082015-06-18 14:58:39 -0700348 s->what |= layer_state_t::eFlagsChanged;
Andy McFadden4125a4f2014-01-29 17:17:11 -0800349 }
Mathias Agopian698c0872011-06-28 19:09:31 -0700350 s->flags &= ~mask;
351 s->flags |= (flags & mask);
352 s->mask |= mask;
353 return NO_ERROR;
354}
355
356status_t Composer::setTransparentRegionHint(
Mathias Agopianac9fa422013-02-11 16:40:36 -0800357 const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
Mathias Agopian698c0872011-06-28 19:09:31 -0700358 const Region& transparentRegion) {
359 Mutex::Autolock _l(mLock);
360 layer_state_t* s = getLayerStateLocked(client, id);
361 if (!s)
362 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700363 s->what |= layer_state_t::eTransparentRegionChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700364 s->transparentRegion = transparentRegion;
365 return NO_ERROR;
366}
367
368status_t Composer::setAlpha(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-11 16:40:36 -0800369 const sp<IBinder>& id, float alpha) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700370 Mutex::Autolock _l(mLock);
371 layer_state_t* s = getLayerStateLocked(client, id);
372 if (!s)
373 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700374 s->what |= layer_state_t::eAlphaChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700375 s->alpha = alpha;
376 return NO_ERROR;
377}
378
Mathias Agopian87855782012-07-24 21:41:09 -0700379status_t Composer::setLayerStack(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-11 16:40:36 -0800380 const sp<IBinder>& id, uint32_t layerStack) {
Mathias Agopian87855782012-07-24 21:41:09 -0700381 Mutex::Autolock _l(mLock);
382 layer_state_t* s = getLayerStateLocked(client, id);
383 if (!s)
384 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700385 s->what |= layer_state_t::eLayerStackChanged;
Mathias Agopian87855782012-07-24 21:41:09 -0700386 s->layerStack = layerStack;
387 return NO_ERROR;
388}
389
Mathias Agopian698c0872011-06-28 19:09:31 -0700390status_t Composer::setMatrix(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-11 16:40:36 -0800391 const sp<IBinder>& id, float dsdx, float dtdx,
Mathias Agopian698c0872011-06-28 19:09:31 -0700392 float dsdy, float dtdy) {
393 Mutex::Autolock _l(mLock);
394 layer_state_t* s = getLayerStateLocked(client, id);
395 if (!s)
396 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700397 s->what |= layer_state_t::eMatrixChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700398 layer_state_t::matrix22_t matrix;
399 matrix.dsdx = dsdx;
400 matrix.dtdx = dtdx;
401 matrix.dsdy = dsdy;
402 matrix.dtdy = dtdy;
403 s->matrix = matrix;
404 return NO_ERROR;
405}
406
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700407status_t Composer::setCrop(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-11 16:40:36 -0800408 const sp<IBinder>& id, const Rect& crop) {
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700409 Mutex::Autolock _l(mLock);
410 layer_state_t* s = getLayerStateLocked(client, id);
411 if (!s)
412 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700413 s->what |= layer_state_t::eCropChanged;
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700414 s->crop = crop;
415 return NO_ERROR;
416}
417
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000418status_t Composer::setFinalCrop(const sp<SurfaceComposerClient>& client,
419 const sp<IBinder>& id, const Rect& crop) {
420 Mutex::Autolock _l(mLock);
421 layer_state_t* s = getLayerStateLocked(client, id);
422 if (!s) {
423 return BAD_INDEX;
424 }
425 s->what |= layer_state_t::eFinalCropChanged;
426 s->finalCrop = crop;
427 return NO_ERROR;
428}
429
Dan Stoza7dde5992015-05-22 09:51:44 -0700430status_t Composer::deferTransactionUntil(
431 const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
432 const sp<IBinder>& handle, uint64_t frameNumber) {
433 Mutex::Autolock lock(mLock);
434 layer_state_t* s = getLayerStateLocked(client, id);
435 if (!s) {
436 return BAD_INDEX;
437 }
438 s->what |= layer_state_t::eDeferTransaction;
439 s->handle = handle;
440 s->frameNumber = frameNumber;
441 return NO_ERROR;
442}
443
Robert Carrc3574f72016-03-24 12:19:32 -0700444status_t Composer::setOverrideScalingMode(
445 const sp<SurfaceComposerClient>& client,
446 const sp<IBinder>& id, int32_t overrideScalingMode) {
447 Mutex::Autolock lock(mLock);
448 layer_state_t* s = getLayerStateLocked(client, id);
449 if (!s) {
450 return BAD_INDEX;
451 }
452
453 switch (overrideScalingMode) {
454 case NATIVE_WINDOW_SCALING_MODE_FREEZE:
455 case NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW:
456 case NATIVE_WINDOW_SCALING_MODE_SCALE_CROP:
457 case NATIVE_WINDOW_SCALING_MODE_NO_SCALE_CROP:
458 case -1:
459 break;
460 default:
461 ALOGE("unknown scaling mode: %d",
462 overrideScalingMode);
463 return BAD_VALUE;
464 }
465
466 s->what |= layer_state_t::eOverrideScalingModeChanged;
467 s->overrideScalingMode = overrideScalingMode;
468 return NO_ERROR;
469}
470
Robert Carr99e27f02016-06-16 15:18:02 -0700471status_t Composer::setGeometryAppliesWithResize(
Robert Carr82364e32016-05-15 11:27:47 -0700472 const sp<SurfaceComposerClient>& client,
473 const sp<IBinder>& id) {
474 Mutex::Autolock lock(mLock);
475 layer_state_t* s = getLayerStateLocked(client, id);
476 if (!s) {
477 return BAD_INDEX;
478 }
Robert Carr99e27f02016-06-16 15:18:02 -0700479 s->what |= layer_state_t::eGeometryAppliesWithResize;
Robert Carr82364e32016-05-15 11:27:47 -0700480 return NO_ERROR;
481}
482
Mathias Agopian698c0872011-06-28 19:09:31 -0700483// ---------------------------------------------------------------------------
484
Mathias Agopiane57f2922012-08-09 16:29:12 -0700485DisplayState& Composer::getDisplayStateLocked(const sp<IBinder>& token) {
486 DisplayState s;
487 s.token = token;
488 ssize_t index = mDisplayStates.indexOf(s);
489 if (index < 0) {
490 // we don't have it, add an initialized layer_state to our list
491 s.what = 0;
492 index = mDisplayStates.add(s);
493 }
Dan Stozad723bd72014-11-18 10:24:03 -0800494 return mDisplayStates.editItemAt(static_cast<size_t>(index));
Mathias Agopiane57f2922012-08-09 16:29:12 -0700495}
496
Pablo Ceballos1aad24c2016-08-04 10:24:22 -0700497status_t Composer::setDisplaySurface(const sp<IBinder>& token,
498 sp<IGraphicBufferProducer> bufferProducer) {
Pablo Ceballoseddbef82016-09-01 11:21:21 -0700499 if (bufferProducer.get() != nullptr) {
500 // Make sure that composition can never be stalled by a virtual display
501 // consumer that isn't processing buffers fast enough.
502 status_t err = bufferProducer->setAsyncMode(true);
503 if (err != NO_ERROR) {
504 ALOGE("Composer::setDisplaySurface Failed to enable async mode on the "
505 "BufferQueue. This BufferQueue cannot be used for virtual "
506 "display. (%d)", err);
507 return err;
508 }
Pablo Ceballos1aad24c2016-08-04 10:24:22 -0700509 }
Mathias Agopiane57f2922012-08-09 16:29:12 -0700510 Mutex::Autolock _l(mLock);
511 DisplayState& s(getDisplayStateLocked(token));
Andy McFadden2adaf042012-12-18 09:49:45 -0800512 s.surface = bufferProducer;
Mathias Agopiane57f2922012-08-09 16:29:12 -0700513 s.what |= DisplayState::eSurfaceChanged;
Pablo Ceballos1aad24c2016-08-04 10:24:22 -0700514 return NO_ERROR;
Mathias Agopiane57f2922012-08-09 16:29:12 -0700515}
516
517void Composer::setDisplayLayerStack(const sp<IBinder>& token,
518 uint32_t layerStack) {
519 Mutex::Autolock _l(mLock);
520 DisplayState& s(getDisplayStateLocked(token));
521 s.layerStack = layerStack;
522 s.what |= DisplayState::eLayerStackChanged;
523}
524
Mathias Agopian00e8c7a2012-09-04 19:30:46 -0700525void Composer::setDisplayProjection(const sp<IBinder>& token,
526 uint32_t orientation,
527 const Rect& layerStackRect,
528 const Rect& displayRect) {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700529 Mutex::Autolock _l(mLock);
530 DisplayState& s(getDisplayStateLocked(token));
531 s.orientation = orientation;
Mathias Agopian00e8c7a2012-09-04 19:30:46 -0700532 s.viewport = layerStackRect;
533 s.frame = displayRect;
534 s.what |= DisplayState::eDisplayProjectionChanged;
Jorim Jaggi092123c2016-04-13 01:40:35 +0000535 mForceSynchronous = true; // TODO: do we actually still need this?
Mathias Agopiane57f2922012-08-09 16:29:12 -0700536}
537
Michael Wright1f6078a2014-06-26 16:01:02 -0700538void Composer::setDisplaySize(const sp<IBinder>& token, uint32_t width, uint32_t height) {
539 Mutex::Autolock _l(mLock);
540 DisplayState& s(getDisplayStateLocked(token));
541 s.width = width;
542 s.height = height;
543 s.what |= DisplayState::eDisplaySizeChanged;
544}
545
Mathias Agopiane57f2922012-08-09 16:29:12 -0700546// ---------------------------------------------------------------------------
547
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800548SurfaceComposerClient::SurfaceComposerClient()
Mathias Agopian698c0872011-06-28 19:09:31 -0700549 : mStatus(NO_INIT), mComposer(Composer::getInstance())
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800550{
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800551}
552
Mathias Agopian698c0872011-06-28 19:09:31 -0700553void SurfaceComposerClient::onFirstRef() {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700554 sp<ISurfaceComposer> sm(ComposerService::getComposerService());
Mathias Agopiand4784a32010-05-27 19:41:15 -0700555 if (sm != 0) {
Mathias Agopian7e27f052010-05-28 14:22:23 -0700556 sp<ISurfaceComposerClient> conn = sm->createConnection();
Mathias Agopiand4784a32010-05-27 19:41:15 -0700557 if (conn != 0) {
558 mClient = conn;
Mathias Agopiand4784a32010-05-27 19:41:15 -0700559 mStatus = NO_ERROR;
560 }
561 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800562}
563
Mathias Agopian698c0872011-06-28 19:09:31 -0700564SurfaceComposerClient::~SurfaceComposerClient() {
Mathias Agopian631f3582010-05-25 17:51:34 -0700565 dispose();
566}
Mathias Agopiandd3423c2009-09-23 15:44:05 -0700567
Mathias Agopian698c0872011-06-28 19:09:31 -0700568status_t SurfaceComposerClient::initCheck() const {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800569 return mStatus;
570}
571
Mathias Agopian698c0872011-06-28 19:09:31 -0700572sp<IBinder> SurfaceComposerClient::connection() const {
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800573 return IInterface::asBinder(mClient);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800574}
575
Mathias Agopiand4784a32010-05-27 19:41:15 -0700576status_t SurfaceComposerClient::linkToComposerDeath(
577 const sp<IBinder::DeathRecipient>& recipient,
Mathias Agopian698c0872011-06-28 19:09:31 -0700578 void* cookie, uint32_t flags) {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700579 sp<ISurfaceComposer> sm(ComposerService::getComposerService());
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800580 return IInterface::asBinder(sm)->linkToDeath(recipient, cookie, flags);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800581}
582
Mathias Agopian698c0872011-06-28 19:09:31 -0700583void SurfaceComposerClient::dispose() {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800584 // this can be called more than once.
Mathias Agopian7e27f052010-05-28 14:22:23 -0700585 sp<ISurfaceComposerClient> client;
Mathias Agopiand4784a32010-05-27 19:41:15 -0700586 Mutex::Autolock _lm(mLock);
587 if (mClient != 0) {
Mathias Agopiand4784a32010-05-27 19:41:15 -0700588 client = mClient; // hold ref while lock is held
589 mClient.clear();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800590 }
Mathias Agopiand4784a32010-05-27 19:41:15 -0700591 mStatus = NO_INIT;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800592}
593
Mathias Agopian698c0872011-06-28 19:09:31 -0700594sp<SurfaceControl> SurfaceComposerClient::createSurface(
Mathias Agopian698c0872011-06-28 19:09:31 -0700595 const String8& name,
Mathias Agopian698c0872011-06-28 19:09:31 -0700596 uint32_t w,
597 uint32_t h,
598 PixelFormat format,
599 uint32_t flags)
600{
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700601 sp<SurfaceControl> sur;
Mathias Agopian698c0872011-06-28 19:09:31 -0700602 if (mStatus == NO_ERROR) {
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700603 sp<IBinder> handle;
604 sp<IGraphicBufferProducer> gbp;
605 status_t err = mClient->createSurface(name, w, h, format, flags,
606 &handle, &gbp);
607 ALOGE_IF(err, "SurfaceComposerClient::createSurface error %s", strerror(-err));
608 if (err == NO_ERROR) {
609 sur = new SurfaceControl(this, handle, gbp);
Mathias Agopian698c0872011-06-28 19:09:31 -0700610 }
611 }
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700612 return sur;
Mathias Agopian698c0872011-06-28 19:09:31 -0700613}
614
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700615sp<IBinder> SurfaceComposerClient::createDisplay(const String8& displayName,
616 bool secure) {
617 return Composer::getInstance().createDisplay(displayName, secure);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700618}
619
Jesse Hall6c913be2013-08-08 12:15:49 -0700620void SurfaceComposerClient::destroyDisplay(const sp<IBinder>& display) {
621 Composer::getInstance().destroyDisplay(display);
622}
623
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700624sp<IBinder> SurfaceComposerClient::getBuiltInDisplay(int32_t id) {
625 return Composer::getInstance().getBuiltInDisplay(id);
626}
627
Mathias Agopianac9fa422013-02-11 16:40:36 -0800628status_t SurfaceComposerClient::destroySurface(const sp<IBinder>& sid) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700629 if (mStatus != NO_ERROR)
630 return mStatus;
631 status_t err = mClient->destroySurface(sid);
632 return err;
633}
634
Svetoslavd85084b2014-03-20 10:28:31 -0700635status_t SurfaceComposerClient::clearLayerFrameStats(const sp<IBinder>& token) const {
636 if (mStatus != NO_ERROR) {
637 return mStatus;
638 }
639 return mClient->clearLayerFrameStats(token);
640}
641
642status_t SurfaceComposerClient::getLayerFrameStats(const sp<IBinder>& token,
643 FrameStats* outStats) const {
644 if (mStatus != NO_ERROR) {
645 return mStatus;
646 }
647 return mClient->getLayerFrameStats(token, outStats);
648}
649
Robert Carr367c5682016-06-20 11:55:28 -0700650status_t SurfaceComposerClient::getTransformToDisplayInverse(const sp<IBinder>& token,
651 bool* outTransformToDisplayInverse) const {
652 if (mStatus != NO_ERROR) {
653 return mStatus;
654 }
655 return mClient->getTransformToDisplayInverse(token, outTransformToDisplayInverse);
656}
657
Mathias Agopian698c0872011-06-28 19:09:31 -0700658inline Composer& SurfaceComposerClient::getComposer() {
659 return mComposer;
660}
661
662// ----------------------------------------------------------------------------
663
664void SurfaceComposerClient::openGlobalTransaction() {
Jeff Brownf3f7db62012-08-31 02:18:38 -0700665 Composer::openGlobalTransaction();
Mathias Agopian698c0872011-06-28 19:09:31 -0700666}
667
Jamie Gennis28378392011-10-12 17:39:00 -0700668void SurfaceComposerClient::closeGlobalTransaction(bool synchronous) {
669 Composer::closeGlobalTransaction(synchronous);
Mathias Agopian698c0872011-06-28 19:09:31 -0700670}
671
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700672void SurfaceComposerClient::setAnimationTransaction() {
673 Composer::setAnimationTransaction();
674}
675
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -0700676status_t SurfaceComposerClient::enableVSyncInjections(bool enable) {
677 return Composer::enableVSyncInjections(enable);
678}
679
680status_t SurfaceComposerClient::injectVSync(nsecs_t when) {
681 return Composer::injectVSync(when);
682}
683
Mathias Agopian698c0872011-06-28 19:09:31 -0700684// ----------------------------------------------------------------------------
685
Mathias Agopianac9fa422013-02-11 16:40:36 -0800686status_t SurfaceComposerClient::setCrop(const sp<IBinder>& id, const Rect& crop) {
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700687 return getComposer().setCrop(this, id, crop);
688}
689
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000690status_t SurfaceComposerClient::setFinalCrop(const sp<IBinder>& id,
691 const Rect& crop) {
692 return getComposer().setFinalCrop(this, id, crop);
693}
694
Mathias Agopianac9fa422013-02-11 16:40:36 -0800695status_t SurfaceComposerClient::setPosition(const sp<IBinder>& id, float x, float y) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700696 return getComposer().setPosition(this, id, x, y);
697}
698
Mathias Agopianac9fa422013-02-11 16:40:36 -0800699status_t SurfaceComposerClient::setSize(const sp<IBinder>& id, uint32_t w, uint32_t h) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700700 return getComposer().setSize(this, id, w, h);
701}
702
Dan Stozad723bd72014-11-18 10:24:03 -0800703status_t SurfaceComposerClient::setLayer(const sp<IBinder>& id, uint32_t z) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700704 return getComposer().setLayer(this, id, z);
705}
706
Mathias Agopianac9fa422013-02-11 16:40:36 -0800707status_t SurfaceComposerClient::hide(const sp<IBinder>& id) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700708 return getComposer().setFlags(this, id,
Mathias Agopian3165cc22012-08-08 19:42:09 -0700709 layer_state_t::eLayerHidden,
710 layer_state_t::eLayerHidden);
Mathias Agopian698c0872011-06-28 19:09:31 -0700711}
712
Mathias Agopianac9fa422013-02-11 16:40:36 -0800713status_t SurfaceComposerClient::show(const sp<IBinder>& id) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700714 return getComposer().setFlags(this, id,
715 0,
Mathias Agopian3165cc22012-08-08 19:42:09 -0700716 layer_state_t::eLayerHidden);
Mathias Agopian698c0872011-06-28 19:09:31 -0700717}
718
Mathias Agopianac9fa422013-02-11 16:40:36 -0800719status_t SurfaceComposerClient::setFlags(const sp<IBinder>& id, uint32_t flags,
Mathias Agopian698c0872011-06-28 19:09:31 -0700720 uint32_t mask) {
721 return getComposer().setFlags(this, id, flags, mask);
722}
723
Mathias Agopianac9fa422013-02-11 16:40:36 -0800724status_t SurfaceComposerClient::setTransparentRegionHint(const sp<IBinder>& id,
Mathias Agopian698c0872011-06-28 19:09:31 -0700725 const Region& transparentRegion) {
726 return getComposer().setTransparentRegionHint(this, id, transparentRegion);
727}
728
Mathias Agopianac9fa422013-02-11 16:40:36 -0800729status_t SurfaceComposerClient::setAlpha(const sp<IBinder>& id, float alpha) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700730 return getComposer().setAlpha(this, id, alpha);
731}
732
Mathias Agopianac9fa422013-02-11 16:40:36 -0800733status_t SurfaceComposerClient::setLayerStack(const sp<IBinder>& id, uint32_t layerStack) {
Mathias Agopian87855782012-07-24 21:41:09 -0700734 return getComposer().setLayerStack(this, id, layerStack);
735}
736
Mathias Agopianac9fa422013-02-11 16:40:36 -0800737status_t SurfaceComposerClient::setMatrix(const sp<IBinder>& id, float dsdx, float dtdx,
Mathias Agopian698c0872011-06-28 19:09:31 -0700738 float dsdy, float dtdy) {
739 return getComposer().setMatrix(this, id, dsdx, dtdx, dsdy, dtdy);
740}
741
Dan Stoza7dde5992015-05-22 09:51:44 -0700742status_t SurfaceComposerClient::deferTransactionUntil(const sp<IBinder>& id,
743 const sp<IBinder>& handle, uint64_t frameNumber) {
744 return getComposer().deferTransactionUntil(this, id, handle, frameNumber);
745}
746
Robert Carrc3574f72016-03-24 12:19:32 -0700747status_t SurfaceComposerClient::setOverrideScalingMode(
748 const sp<IBinder>& id, int32_t overrideScalingMode) {
749 return getComposer().setOverrideScalingMode(
750 this, id, overrideScalingMode);
751}
752
Robert Carr99e27f02016-06-16 15:18:02 -0700753status_t SurfaceComposerClient::setGeometryAppliesWithResize(
Robert Carr82364e32016-05-15 11:27:47 -0700754 const sp<IBinder>& id) {
Robert Carr99e27f02016-06-16 15:18:02 -0700755 return getComposer().setGeometryAppliesWithResize(this, id);
Robert Carr82364e32016-05-15 11:27:47 -0700756}
757
Mathias Agopian698c0872011-06-28 19:09:31 -0700758// ----------------------------------------------------------------------------
759
Pablo Ceballos1aad24c2016-08-04 10:24:22 -0700760status_t SurfaceComposerClient::setDisplaySurface(const sp<IBinder>& token,
761 sp<IGraphicBufferProducer> bufferProducer) {
762 return Composer::getInstance().setDisplaySurface(token, bufferProducer);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700763}
764
765void SurfaceComposerClient::setDisplayLayerStack(const sp<IBinder>& token,
766 uint32_t layerStack) {
767 Composer::getInstance().setDisplayLayerStack(token, layerStack);
768}
769
Mathias Agopian00e8c7a2012-09-04 19:30:46 -0700770void SurfaceComposerClient::setDisplayProjection(const sp<IBinder>& token,
771 uint32_t orientation,
772 const Rect& layerStackRect,
773 const Rect& displayRect) {
774 Composer::getInstance().setDisplayProjection(token, orientation,
775 layerStackRect, displayRect);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700776}
777
Michael Wright1f6078a2014-06-26 16:01:02 -0700778void SurfaceComposerClient::setDisplaySize(const sp<IBinder>& token,
779 uint32_t width, uint32_t height) {
780 Composer::getInstance().setDisplaySize(token, width, height);
781}
782
Mathias Agopiane57f2922012-08-09 16:29:12 -0700783// ----------------------------------------------------------------------------
784
Dan Stoza7f7da322014-05-02 15:26:25 -0700785status_t SurfaceComposerClient::getDisplayConfigs(
786 const sp<IBinder>& display, Vector<DisplayInfo>* configs)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800787{
Dan Stoza7f7da322014-05-02 15:26:25 -0700788 return ComposerService::getComposerService()->getDisplayConfigs(display, configs);
789}
790
791status_t SurfaceComposerClient::getDisplayInfo(const sp<IBinder>& display,
792 DisplayInfo* info) {
793 Vector<DisplayInfo> configs;
794 status_t result = getDisplayConfigs(display, &configs);
795 if (result != NO_ERROR) {
796 return result;
797 }
798
799 int activeId = getActiveConfig(display);
800 if (activeId < 0) {
801 ALOGE("No active configuration found");
802 return NAME_NOT_FOUND;
803 }
804
Dan Stozad723bd72014-11-18 10:24:03 -0800805 *info = configs[static_cast<size_t>(activeId)];
Dan Stoza7f7da322014-05-02 15:26:25 -0700806 return NO_ERROR;
807}
808
809int SurfaceComposerClient::getActiveConfig(const sp<IBinder>& display) {
810 return ComposerService::getComposerService()->getActiveConfig(display);
811}
812
813status_t SurfaceComposerClient::setActiveConfig(const sp<IBinder>& display, int id) {
814 return ComposerService::getComposerService()->setActiveConfig(display, id);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800815}
816
Michael Wright28f24d02016-07-12 13:30:53 -0700817status_t SurfaceComposerClient::getDisplayColorModes(const sp<IBinder>& display,
818 Vector<android_color_mode_t>* outColorModes) {
819 return ComposerService::getComposerService()->getDisplayColorModes(display, outColorModes);
820}
821
822android_color_mode_t SurfaceComposerClient::getActiveColorMode(const sp<IBinder>& display) {
823 return ComposerService::getComposerService()->getActiveColorMode(display);
824}
825
826status_t SurfaceComposerClient::setActiveColorMode(const sp<IBinder>& display,
827 android_color_mode_t colorMode) {
828 return ComposerService::getComposerService()->setActiveColorMode(display, colorMode);
829}
830
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700831void SurfaceComposerClient::setDisplayPowerMode(const sp<IBinder>& token,
832 int mode) {
833 ComposerService::getComposerService()->setPowerMode(token, mode);
Jeff Brown2a09bb32012-10-08 19:13:57 -0700834}
835
Svetoslavd85084b2014-03-20 10:28:31 -0700836status_t SurfaceComposerClient::clearAnimationFrameStats() {
837 return ComposerService::getComposerService()->clearAnimationFrameStats();
838}
839
840status_t SurfaceComposerClient::getAnimationFrameStats(FrameStats* outStats) {
841 return ComposerService::getComposerService()->getAnimationFrameStats(outStats);
842}
843
Dan Stozac4f471e2016-03-24 09:31:08 -0700844status_t SurfaceComposerClient::getHdrCapabilities(const sp<IBinder>& display,
845 HdrCapabilities* outCapabilities) {
846 return ComposerService::getComposerService()->getHdrCapabilities(display,
847 outCapabilities);
848}
849
Mathias Agopian698c0872011-06-28 19:09:31 -0700850// ----------------------------------------------------------------------------
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800851
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800852status_t ScreenshotClient::capture(
853 const sp<IBinder>& display,
854 const sp<IGraphicBufferProducer>& producer,
Dan Stozac1879002014-05-22 15:59:05 -0700855 Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
Dan Stozac7014012014-02-14 15:03:43 -0800856 uint32_t minLayerZ, uint32_t maxLayerZ, bool useIdentityTransform) {
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800857 sp<ISurfaceComposer> s(ComposerService::getComposerService());
858 if (s == NULL) return NO_INIT;
Dan Stozac1879002014-05-22 15:59:05 -0700859 return s->captureScreen(display, producer, sourceCrop,
Dan Stozac7014012014-02-14 15:03:43 -0800860 reqWidth, reqHeight, minLayerZ, maxLayerZ, useIdentityTransform);
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800861}
862
Robert Carr673134e2017-01-09 19:48:38 -0800863status_t ScreenshotClient::captureToBuffer(const sp<IBinder>& display,
864 Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
865 uint32_t minLayerZ, uint32_t maxLayerZ, bool useIdentityTransform,
866 uint32_t rotation,
867 sp<GraphicBuffer>* outBuffer) {
868 sp<ISurfaceComposer> s(ComposerService::getComposerService());
869 if (s == NULL) return NO_INIT;
870
871 sp<IGraphicBufferConsumer> gbpConsumer;
872 sp<IGraphicBufferProducer> producer;
873 BufferQueue::createBufferQueue(&producer, &gbpConsumer);
874 sp<BufferItemConsumer> consumer(new BufferItemConsumer(gbpConsumer,
875 GRALLOC_USAGE_HW_TEXTURE | GRALLOC_USAGE_SW_READ_NEVER | GRALLOC_USAGE_SW_WRITE_NEVER,
876 1, true));
877
878 status_t ret = s->captureScreen(display, producer, sourceCrop, reqWidth, reqHeight,
879 minLayerZ, maxLayerZ, useIdentityTransform,
880 static_cast<ISurfaceComposer::Rotation>(rotation));
881 if (ret != NO_ERROR) {
882 return ret;
883 }
884 BufferItem b;
885 consumer->acquireBuffer(&b, 0, true);
886 *outBuffer = b.mGraphicBuffer;
887 return ret;
888}
889
Mathias Agopian74c40c02010-09-29 13:02:36 -0700890ScreenshotClient::ScreenshotClient()
Mathias Agopianabe815d2013-03-19 22:22:21 -0700891 : mHaveBuffer(false) {
892 memset(&mBuffer, 0, sizeof(mBuffer));
Mathias Agopian74c40c02010-09-29 13:02:36 -0700893}
894
Mathias Agopian8000d062013-03-26 18:15:35 -0700895ScreenshotClient::~ScreenshotClient() {
896 ScreenshotClient::release();
897}
898
Mathias Agopianabe815d2013-03-19 22:22:21 -0700899sp<CpuConsumer> ScreenshotClient::getCpuConsumer() const {
900 if (mCpuConsumer == NULL) {
Dan Stoza6d5a7bb2014-03-13 11:39:09 -0700901 sp<IGraphicBufferConsumer> consumer;
902 BufferQueue::createBufferQueue(&mProducer, &consumer);
903 mCpuConsumer = new CpuConsumer(consumer, 1);
Mathias Agopianabe815d2013-03-19 22:22:21 -0700904 mCpuConsumer->setName(String8("ScreenshotClient"));
905 }
906 return mCpuConsumer;
Mathias Agopianbf2c6a62010-12-10 16:22:31 -0800907}
908
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700909status_t ScreenshotClient::update(const sp<IBinder>& display,
Dan Stozac1879002014-05-22 15:59:05 -0700910 Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
Dan Stozac7014012014-02-14 15:03:43 -0800911 uint32_t minLayerZ, uint32_t maxLayerZ,
Riley Andrewsd15ef272014-09-04 16:19:44 -0700912 bool useIdentityTransform, uint32_t rotation) {
Mathias Agopianbf2c6a62010-12-10 16:22:31 -0800913 sp<ISurfaceComposer> s(ComposerService::getComposerService());
914 if (s == NULL) return NO_INIT;
Mathias Agopianabe815d2013-03-19 22:22:21 -0700915 sp<CpuConsumer> cpuConsumer = getCpuConsumer();
916
917 if (mHaveBuffer) {
918 mCpuConsumer->unlockBuffer(mBuffer);
919 memset(&mBuffer, 0, sizeof(mBuffer));
920 mHaveBuffer = false;
921 }
922
Dan Stozac1879002014-05-22 15:59:05 -0700923 status_t err = s->captureScreen(display, mProducer, sourceCrop,
Riley Andrewsd15ef272014-09-04 16:19:44 -0700924 reqWidth, reqHeight, minLayerZ, maxLayerZ, useIdentityTransform,
925 static_cast<ISurfaceComposer::Rotation>(rotation));
Mathias Agopianabe815d2013-03-19 22:22:21 -0700926
927 if (err == NO_ERROR) {
928 err = mCpuConsumer->lockNextBuffer(&mBuffer);
929 if (err == NO_ERROR) {
930 mHaveBuffer = true;
931 }
932 }
933 return err;
934}
935
Riley Andrewsd15ef272014-09-04 16:19:44 -0700936status_t ScreenshotClient::update(const sp<IBinder>& display,
937 Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
938 uint32_t minLayerZ, uint32_t maxLayerZ,
939 bool useIdentityTransform) {
940
941 return ScreenshotClient::update(display, sourceCrop, reqWidth, reqHeight,
942 minLayerZ, maxLayerZ, useIdentityTransform, ISurfaceComposer::eRotateNone);
943}
944
Dan Stozac1879002014-05-22 15:59:05 -0700945status_t ScreenshotClient::update(const sp<IBinder>& display, Rect sourceCrop,
Dan Stozac7014012014-02-14 15:03:43 -0800946 bool useIdentityTransform) {
Dan Stozaf10c46e2014-11-11 10:32:31 -0800947 return ScreenshotClient::update(display, sourceCrop, 0, 0, 0, -1U,
Riley Andrewsd15ef272014-09-04 16:19:44 -0700948 useIdentityTransform, ISurfaceComposer::eRotateNone);
Mathias Agopianabe815d2013-03-19 22:22:21 -0700949}
950
Dan Stozac1879002014-05-22 15:59:05 -0700951status_t ScreenshotClient::update(const sp<IBinder>& display, Rect sourceCrop,
Dan Stozac7014012014-02-14 15:03:43 -0800952 uint32_t reqWidth, uint32_t reqHeight, bool useIdentityTransform) {
Dan Stozac1879002014-05-22 15:59:05 -0700953 return ScreenshotClient::update(display, sourceCrop, reqWidth, reqHeight,
Dan Stozaf10c46e2014-11-11 10:32:31 -0800954 0, -1U, useIdentityTransform, ISurfaceComposer::eRotateNone);
Mathias Agopian74c40c02010-09-29 13:02:36 -0700955}
956
957void ScreenshotClient::release() {
Mathias Agopianabe815d2013-03-19 22:22:21 -0700958 if (mHaveBuffer) {
959 mCpuConsumer->unlockBuffer(mBuffer);
960 memset(&mBuffer, 0, sizeof(mBuffer));
961 mHaveBuffer = false;
962 }
963 mCpuConsumer.clear();
Mathias Agopian74c40c02010-09-29 13:02:36 -0700964}
965
966void const* ScreenshotClient::getPixels() const {
Mathias Agopianabe815d2013-03-19 22:22:21 -0700967 return mBuffer.data;
Mathias Agopian74c40c02010-09-29 13:02:36 -0700968}
969
970uint32_t ScreenshotClient::getWidth() const {
Mathias Agopianabe815d2013-03-19 22:22:21 -0700971 return mBuffer.width;
Mathias Agopian74c40c02010-09-29 13:02:36 -0700972}
973
974uint32_t ScreenshotClient::getHeight() const {
Mathias Agopianabe815d2013-03-19 22:22:21 -0700975 return mBuffer.height;
Mathias Agopian74c40c02010-09-29 13:02:36 -0700976}
977
978PixelFormat ScreenshotClient::getFormat() const {
Mathias Agopianabe815d2013-03-19 22:22:21 -0700979 return mBuffer.format;
Mathias Agopian74c40c02010-09-29 13:02:36 -0700980}
981
982uint32_t ScreenshotClient::getStride() const {
Mathias Agopianabe815d2013-03-19 22:22:21 -0700983 return mBuffer.stride;
Mathias Agopian74c40c02010-09-29 13:02:36 -0700984}
985
986size_t ScreenshotClient::getSize() const {
Mathias Agopianabe815d2013-03-19 22:22:21 -0700987 return mBuffer.stride * mBuffer.height * bytesPerPixel(mBuffer.format);
Mathias Agopian74c40c02010-09-29 13:02:36 -0700988}
989
990// ----------------------------------------------------------------------------
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800991}; // namespace android