blob: f87fd183b98c9679fadb1111d3f93987b39491ec [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
Mathias Agopianabe815d2013-03-19 22:22:21 -070036#include <gui/CpuConsumer.h>
Mathias Agopiane3c697f2013-02-14 17:11:02 -080037#include <gui/IGraphicBufferProducer.h>
Mathias Agopian90ac7992012-02-25 18:48:35 -080038#include <gui/ISurfaceComposer.h>
39#include <gui/ISurfaceComposerClient.h>
40#include <gui/SurfaceComposerClient.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080041
Mathias Agopian41f673c2011-11-17 17:48:35 -080042#include <private/gui/ComposerService.h>
Mathias Agopian90ac7992012-02-25 18:48:35 -080043#include <private/gui/LayerState.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080044
45namespace android {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080046// ---------------------------------------------------------------------------
47
Mathias Agopian7e27f052010-05-28 14:22:23 -070048ANDROID_SINGLETON_STATIC_INSTANCE(ComposerService);
49
Mathias Agopianb7e930d2010-06-01 15:12:58 -070050ComposerService::ComposerService()
51: Singleton<ComposerService>() {
Andy McFadden6652b3e2012-09-06 18:45:56 -070052 Mutex::Autolock _l(mLock);
53 connectLocked();
54}
55
56void ComposerService::connectLocked() {
Mathias Agopianb7e930d2010-06-01 15:12:58 -070057 const String16 name("SurfaceFlinger");
58 while (getService(name, &mComposerService) != NO_ERROR) {
59 usleep(250000);
60 }
Andy McFadden6652b3e2012-09-06 18:45:56 -070061 assert(mComposerService != NULL);
62
63 // Create the death listener.
64 class DeathObserver : public IBinder::DeathRecipient {
65 ComposerService& mComposerService;
66 virtual void binderDied(const wp<IBinder>& who) {
67 ALOGW("ComposerService remote (surfaceflinger) died [%p]",
68 who.unsafe_get());
69 mComposerService.composerServiceDied();
70 }
71 public:
Chih-Hung Hsiehe2347b72016-04-25 15:41:05 -070072 explicit DeathObserver(ComposerService& mgr) : mComposerService(mgr) { }
Andy McFadden6652b3e2012-09-06 18:45:56 -070073 };
74
75 mDeathObserver = new DeathObserver(*const_cast<ComposerService*>(this));
Marco Nelissen2ea926b2014-11-14 08:01:01 -080076 IInterface::asBinder(mComposerService)->linkToDeath(mDeathObserver);
Mathias Agopianb7e930d2010-06-01 15:12:58 -070077}
78
Andy McFadden6652b3e2012-09-06 18:45:56 -070079/*static*/ sp<ISurfaceComposer> ComposerService::getComposerService() {
80 ComposerService& instance = ComposerService::getInstance();
81 Mutex::Autolock _l(instance.mLock);
82 if (instance.mComposerService == NULL) {
83 ComposerService::getInstance().connectLocked();
84 assert(instance.mComposerService != NULL);
85 ALOGD("ComposerService reconnected");
86 }
87 return instance.mComposerService;
88}
89
90void ComposerService::composerServiceDied()
91{
92 Mutex::Autolock _l(mLock);
93 mComposerService = NULL;
94 mDeathObserver = NULL;
Mathias Agopianb7e930d2010-06-01 15:12:58 -070095}
96
Mathias Agopian7e27f052010-05-28 14:22:23 -070097// ---------------------------------------------------------------------------
98
Mathias Agopian698c0872011-06-28 19:09:31 -070099static inline
Mathias Agopiane57f2922012-08-09 16:29:12 -0700100int compare_type(const ComposerState& lhs, const ComposerState& rhs) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700101 if (lhs.client < rhs.client) return -1;
102 if (lhs.client > rhs.client) return 1;
103 if (lhs.state.surface < rhs.state.surface) return -1;
104 if (lhs.state.surface > rhs.state.surface) return 1;
105 return 0;
106}
107
Mathias Agopiane57f2922012-08-09 16:29:12 -0700108static inline
109int compare_type(const DisplayState& lhs, const DisplayState& rhs) {
110 return compare_type(lhs.token, rhs.token);
111}
112
Mathias Agopian7e27f052010-05-28 14:22:23 -0700113class Composer : public Singleton<Composer>
114{
Mathias Agopiand4784a32010-05-27 19:41:15 -0700115 friend class Singleton<Composer>;
116
Mathias Agopian698c0872011-06-28 19:09:31 -0700117 mutable Mutex mLock;
Mathias Agopiane57f2922012-08-09 16:29:12 -0700118 SortedVector<ComposerState> mComposerStates;
119 SortedVector<DisplayState > mDisplayStates;
Jamie Gennis28378392011-10-12 17:39:00 -0700120 uint32_t mForceSynchronous;
Jeff Brownf3f7db62012-08-31 02:18:38 -0700121 uint32_t mTransactionNestCount;
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700122 bool mAnimation;
Mathias Agopian698c0872011-06-28 19:09:31 -0700123
Jamie Gennisb8d69a52011-10-10 15:48:06 -0700124 Composer() : Singleton<Composer>(),
Jeff Brownf3f7db62012-08-31 02:18:38 -0700125 mForceSynchronous(0), mTransactionNestCount(0),
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700126 mAnimation(false)
Jamie Gennis28378392011-10-12 17:39:00 -0700127 { }
Mathias Agopian698c0872011-06-28 19:09:31 -0700128
Jeff Brownf3f7db62012-08-31 02:18:38 -0700129 void openGlobalTransactionImpl();
Jamie Gennis28378392011-10-12 17:39:00 -0700130 void closeGlobalTransactionImpl(bool synchronous);
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700131 void setAnimationTransactionImpl();
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -0700132 status_t enableVSyncInjectionsImpl(bool enable);
133 status_t injectVSyncImpl(nsecs_t when);
Mathias Agopian698c0872011-06-28 19:09:31 -0700134
135 layer_state_t* getLayerStateLocked(
Mathias Agopianac9fa422013-02-11 16:40:36 -0800136 const sp<SurfaceComposerClient>& client, const sp<IBinder>& id);
Mathias Agopian698c0872011-06-28 19:09:31 -0700137
Mathias Agopiane57f2922012-08-09 16:29:12 -0700138 DisplayState& getDisplayStateLocked(const sp<IBinder>& token);
139
Mathias Agopiand4784a32010-05-27 19:41:15 -0700140public:
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700141 sp<IBinder> createDisplay(const String8& displayName, bool secure);
Jesse Hall6c913be2013-08-08 12:15:49 -0700142 void destroyDisplay(const sp<IBinder>& display);
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700143 sp<IBinder> getBuiltInDisplay(int32_t id);
Mathias Agopian698c0872011-06-28 19:09:31 -0700144
Mathias Agopianac9fa422013-02-11 16:40:36 -0800145 status_t setPosition(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
Mathias Agopian41b6aab2011-08-30 18:51:54 -0700146 float x, float y);
Mathias Agopianac9fa422013-02-11 16:40:36 -0800147 status_t setSize(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
Mathias Agopian698c0872011-06-28 19:09:31 -0700148 uint32_t w, uint32_t h);
Mathias Agopianac9fa422013-02-11 16:40:36 -0800149 status_t setLayer(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
Dan Stozad723bd72014-11-18 10:24:03 -0800150 uint32_t z);
Mathias Agopianac9fa422013-02-11 16:40:36 -0800151 status_t setFlags(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
Mathias Agopian698c0872011-06-28 19:09:31 -0700152 uint32_t flags, uint32_t mask);
153 status_t setTransparentRegionHint(
Mathias Agopianac9fa422013-02-11 16:40:36 -0800154 const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
Mathias Agopian698c0872011-06-28 19:09:31 -0700155 const Region& transparentRegion);
Mathias Agopianac9fa422013-02-11 16:40:36 -0800156 status_t setAlpha(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
Mathias Agopian698c0872011-06-28 19:09:31 -0700157 float alpha);
Mathias Agopianac9fa422013-02-11 16:40:36 -0800158 status_t setMatrix(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
Mathias Agopian698c0872011-06-28 19:09:31 -0700159 float dsdx, float dtdx, float dsdy, float dtdy);
Jamie Gennisb8d69a52011-10-10 15:48:06 -0700160 status_t setOrientation(int orientation);
Mathias Agopianac9fa422013-02-11 16:40:36 -0800161 status_t setCrop(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700162 const Rect& crop);
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000163 status_t setFinalCrop(const sp<SurfaceComposerClient>& client,
164 const sp<IBinder>& id, const Rect& crop);
Mathias Agopian87855782012-07-24 21:41:09 -0700165 status_t setLayerStack(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-11 16:40:36 -0800166 const sp<IBinder>& id, uint32_t layerStack);
Dan Stoza7dde5992015-05-22 09:51:44 -0700167 status_t deferTransactionUntil(const sp<SurfaceComposerClient>& client,
168 const sp<IBinder>& id, const sp<IBinder>& handle,
169 uint64_t frameNumber);
Robert Carrc3574f72016-03-24 12:19:32 -0700170 status_t setOverrideScalingMode(const sp<SurfaceComposerClient>& client,
171 const sp<IBinder>& id, int32_t overrideScalingMode);
Robert Carr99e27f02016-06-16 15:18:02 -0700172 status_t setGeometryAppliesWithResize(const sp<SurfaceComposerClient>& client,
Robert Carr82364e32016-05-15 11:27:47 -0700173 const sp<IBinder>& id);
Mathias Agopian698c0872011-06-28 19:09:31 -0700174
Andy McFadden2adaf042012-12-18 09:49:45 -0800175 void setDisplaySurface(const sp<IBinder>& token,
176 const sp<IGraphicBufferProducer>& bufferProducer);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700177 void setDisplayLayerStack(const sp<IBinder>& token, uint32_t layerStack);
Mathias Agopian00e8c7a2012-09-04 19:30:46 -0700178 void setDisplayProjection(const sp<IBinder>& token,
179 uint32_t orientation,
180 const Rect& layerStackRect,
181 const Rect& displayRect);
Michael Wright1f6078a2014-06-26 16:01:02 -0700182 void setDisplaySize(const sp<IBinder>& token, uint32_t width, uint32_t height);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700183
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700184 static void setAnimationTransaction() {
185 Composer::getInstance().setAnimationTransactionImpl();
186 }
187
Jeff Brownf3f7db62012-08-31 02:18:38 -0700188 static void openGlobalTransaction() {
189 Composer::getInstance().openGlobalTransactionImpl();
190 }
191
Jamie Gennis28378392011-10-12 17:39:00 -0700192 static void closeGlobalTransaction(bool synchronous) {
193 Composer::getInstance().closeGlobalTransactionImpl(synchronous);
Mathias Agopiand4784a32010-05-27 19:41:15 -0700194 }
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -0700195
196 static status_t enableVSyncInjections(bool enable) {
197 return Composer::getInstance().enableVSyncInjectionsImpl(enable);
198 }
199
200 static status_t injectVSync(nsecs_t when) {
201 return Composer::getInstance().injectVSyncImpl(when);
202 }
Mathias Agopiand4784a32010-05-27 19:41:15 -0700203};
204
205ANDROID_SINGLETON_STATIC_INSTANCE(Composer);
206
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800207// ---------------------------------------------------------------------------
208
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700209sp<IBinder> Composer::createDisplay(const String8& displayName, bool secure) {
210 return ComposerService::getComposerService()->createDisplay(displayName,
211 secure);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700212}
213
Jesse Hall6c913be2013-08-08 12:15:49 -0700214void Composer::destroyDisplay(const sp<IBinder>& display) {
215 return ComposerService::getComposerService()->destroyDisplay(display);
216}
217
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700218sp<IBinder> Composer::getBuiltInDisplay(int32_t id) {
219 return ComposerService::getComposerService()->getBuiltInDisplay(id);
220}
221
Jeff Brownf3f7db62012-08-31 02:18:38 -0700222void Composer::openGlobalTransactionImpl() {
223 { // scope for the lock
224 Mutex::Autolock _l(mLock);
225 mTransactionNestCount += 1;
226 }
227}
228
Jamie Gennis28378392011-10-12 17:39:00 -0700229void Composer::closeGlobalTransactionImpl(bool synchronous) {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700230 sp<ISurfaceComposer> sm(ComposerService::getComposerService());
Mathias Agopian698c0872011-06-28 19:09:31 -0700231
232 Vector<ComposerState> transaction;
Mathias Agopian8b33f032012-07-24 20:43:54 -0700233 Vector<DisplayState> displayTransaction;
Jamie Gennis28378392011-10-12 17:39:00 -0700234 uint32_t flags = 0;
Mathias Agopian698c0872011-06-28 19:09:31 -0700235
236 { // scope for the lock
237 Mutex::Autolock _l(mLock);
Jeff Brownf3f7db62012-08-31 02:18:38 -0700238 mForceSynchronous |= synchronous;
239 if (!mTransactionNestCount) {
240 ALOGW("At least one call to closeGlobalTransaction() was not matched by a prior "
241 "call to openGlobalTransaction().");
242 } else if (--mTransactionNestCount) {
243 return;
244 }
245
Mathias Agopiane57f2922012-08-09 16:29:12 -0700246 transaction = mComposerStates;
247 mComposerStates.clear();
Jamie Gennisb8d69a52011-10-10 15:48:06 -0700248
Mathias Agopiane57f2922012-08-09 16:29:12 -0700249 displayTransaction = mDisplayStates;
250 mDisplayStates.clear();
Jamie Gennis28378392011-10-12 17:39:00 -0700251
Jeff Brownf3f7db62012-08-31 02:18:38 -0700252 if (mForceSynchronous) {
Jamie Gennis28378392011-10-12 17:39:00 -0700253 flags |= ISurfaceComposer::eSynchronous;
254 }
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700255 if (mAnimation) {
256 flags |= ISurfaceComposer::eAnimation;
257 }
258
Jamie Gennis28378392011-10-12 17:39:00 -0700259 mForceSynchronous = false;
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700260 mAnimation = false;
Mathias Agopian698c0872011-06-28 19:09:31 -0700261 }
262
Mathias Agopian8b33f032012-07-24 20:43:54 -0700263 sm->setTransactionState(transaction, displayTransaction, flags);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800264}
265
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -0700266status_t Composer::enableVSyncInjectionsImpl(bool enable) {
267 sp<ISurfaceComposer> sm(ComposerService::getComposerService());
268 return sm->enableVSyncInjections(enable);
269}
270
271status_t Composer::injectVSyncImpl(nsecs_t when) {
272 sp<ISurfaceComposer> sm(ComposerService::getComposerService());
273 return sm->injectVSync(when);
274}
275
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700276void Composer::setAnimationTransactionImpl() {
277 Mutex::Autolock _l(mLock);
278 mAnimation = true;
279}
280
Mathias Agopian698c0872011-06-28 19:09:31 -0700281layer_state_t* Composer::getLayerStateLocked(
Mathias Agopianac9fa422013-02-11 16:40:36 -0800282 const sp<SurfaceComposerClient>& client, const sp<IBinder>& id) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700283
284 ComposerState s;
285 s.client = client->mClient;
286 s.state.surface = id;
287
Mathias Agopiane57f2922012-08-09 16:29:12 -0700288 ssize_t index = mComposerStates.indexOf(s);
Mathias Agopian698c0872011-06-28 19:09:31 -0700289 if (index < 0) {
290 // we don't have it, add an initialized layer_state to our list
Mathias Agopiane57f2922012-08-09 16:29:12 -0700291 index = mComposerStates.add(s);
Mathias Agopian698c0872011-06-28 19:09:31 -0700292 }
293
Mathias Agopiane57f2922012-08-09 16:29:12 -0700294 ComposerState* const out = mComposerStates.editArray();
Mathias Agopian698c0872011-06-28 19:09:31 -0700295 return &(out[index].state);
296}
297
298status_t Composer::setPosition(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-11 16:40:36 -0800299 const sp<IBinder>& id, float x, float y) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700300 Mutex::Autolock _l(mLock);
301 layer_state_t* s = getLayerStateLocked(client, id);
302 if (!s)
303 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700304 s->what |= layer_state_t::ePositionChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700305 s->x = x;
306 s->y = y;
307 return NO_ERROR;
308}
309
310status_t Composer::setSize(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-11 16:40:36 -0800311 const sp<IBinder>& id, uint32_t w, uint32_t h) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700312 Mutex::Autolock _l(mLock);
313 layer_state_t* s = getLayerStateLocked(client, id);
314 if (!s)
315 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700316 s->what |= layer_state_t::eSizeChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700317 s->w = w;
318 s->h = h;
Jamie Gennis28378392011-10-12 17:39:00 -0700319
Jorim Jaggi092123c2016-04-13 01:40:35 +0000320 // Resizing a surface makes the transaction synchronous.
321 mForceSynchronous = true;
322
Mathias Agopian698c0872011-06-28 19:09:31 -0700323 return NO_ERROR;
324}
325
326status_t Composer::setLayer(const sp<SurfaceComposerClient>& client,
Dan Stozad723bd72014-11-18 10:24:03 -0800327 const sp<IBinder>& id, uint32_t z) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700328 Mutex::Autolock _l(mLock);
329 layer_state_t* s = getLayerStateLocked(client, id);
330 if (!s)
331 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700332 s->what |= layer_state_t::eLayerChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700333 s->z = z;
334 return NO_ERROR;
335}
336
337status_t Composer::setFlags(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-11 16:40:36 -0800338 const sp<IBinder>& id, uint32_t flags,
Mathias Agopian698c0872011-06-28 19:09:31 -0700339 uint32_t mask) {
340 Mutex::Autolock _l(mLock);
341 layer_state_t* s = getLayerStateLocked(client, id);
342 if (!s)
343 return BAD_INDEX;
Pablo Ceballos53390e12015-08-04 11:25:59 -0700344 if ((mask & layer_state_t::eLayerOpaque) ||
345 (mask & layer_state_t::eLayerHidden) ||
346 (mask & layer_state_t::eLayerSecure)) {
Dan Stoza23116082015-06-18 14:58:39 -0700347 s->what |= layer_state_t::eFlagsChanged;
Andy McFadden4125a4f2014-01-29 17:17:11 -0800348 }
Mathias Agopian698c0872011-06-28 19:09:31 -0700349 s->flags &= ~mask;
350 s->flags |= (flags & mask);
351 s->mask |= mask;
352 return NO_ERROR;
353}
354
355status_t Composer::setTransparentRegionHint(
Mathias Agopianac9fa422013-02-11 16:40:36 -0800356 const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
Mathias Agopian698c0872011-06-28 19:09:31 -0700357 const Region& transparentRegion) {
358 Mutex::Autolock _l(mLock);
359 layer_state_t* s = getLayerStateLocked(client, id);
360 if (!s)
361 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700362 s->what |= layer_state_t::eTransparentRegionChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700363 s->transparentRegion = transparentRegion;
364 return NO_ERROR;
365}
366
367status_t Composer::setAlpha(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-11 16:40:36 -0800368 const sp<IBinder>& id, float alpha) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700369 Mutex::Autolock _l(mLock);
370 layer_state_t* s = getLayerStateLocked(client, id);
371 if (!s)
372 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700373 s->what |= layer_state_t::eAlphaChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700374 s->alpha = alpha;
375 return NO_ERROR;
376}
377
Mathias Agopian87855782012-07-24 21:41:09 -0700378status_t Composer::setLayerStack(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-11 16:40:36 -0800379 const sp<IBinder>& id, uint32_t layerStack) {
Mathias Agopian87855782012-07-24 21:41:09 -0700380 Mutex::Autolock _l(mLock);
381 layer_state_t* s = getLayerStateLocked(client, id);
382 if (!s)
383 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700384 s->what |= layer_state_t::eLayerStackChanged;
Mathias Agopian87855782012-07-24 21:41:09 -0700385 s->layerStack = layerStack;
386 return NO_ERROR;
387}
388
Mathias Agopian698c0872011-06-28 19:09:31 -0700389status_t Composer::setMatrix(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-11 16:40:36 -0800390 const sp<IBinder>& id, float dsdx, float dtdx,
Mathias Agopian698c0872011-06-28 19:09:31 -0700391 float dsdy, float dtdy) {
392 Mutex::Autolock _l(mLock);
393 layer_state_t* s = getLayerStateLocked(client, id);
394 if (!s)
395 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700396 s->what |= layer_state_t::eMatrixChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700397 layer_state_t::matrix22_t matrix;
398 matrix.dsdx = dsdx;
399 matrix.dtdx = dtdx;
400 matrix.dsdy = dsdy;
401 matrix.dtdy = dtdy;
402 s->matrix = matrix;
403 return NO_ERROR;
404}
405
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700406status_t Composer::setCrop(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-11 16:40:36 -0800407 const sp<IBinder>& id, const Rect& crop) {
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700408 Mutex::Autolock _l(mLock);
409 layer_state_t* s = getLayerStateLocked(client, id);
410 if (!s)
411 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700412 s->what |= layer_state_t::eCropChanged;
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700413 s->crop = crop;
414 return NO_ERROR;
415}
416
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000417status_t Composer::setFinalCrop(const sp<SurfaceComposerClient>& client,
418 const sp<IBinder>& id, const Rect& crop) {
419 Mutex::Autolock _l(mLock);
420 layer_state_t* s = getLayerStateLocked(client, id);
421 if (!s) {
422 return BAD_INDEX;
423 }
424 s->what |= layer_state_t::eFinalCropChanged;
425 s->finalCrop = crop;
426 return NO_ERROR;
427}
428
Dan Stoza7dde5992015-05-22 09:51:44 -0700429status_t Composer::deferTransactionUntil(
430 const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
431 const sp<IBinder>& handle, uint64_t frameNumber) {
432 Mutex::Autolock lock(mLock);
433 layer_state_t* s = getLayerStateLocked(client, id);
434 if (!s) {
435 return BAD_INDEX;
436 }
437 s->what |= layer_state_t::eDeferTransaction;
438 s->handle = handle;
439 s->frameNumber = frameNumber;
440 return NO_ERROR;
441}
442
Robert Carrc3574f72016-03-24 12:19:32 -0700443status_t Composer::setOverrideScalingMode(
444 const sp<SurfaceComposerClient>& client,
445 const sp<IBinder>& id, int32_t overrideScalingMode) {
446 Mutex::Autolock lock(mLock);
447 layer_state_t* s = getLayerStateLocked(client, id);
448 if (!s) {
449 return BAD_INDEX;
450 }
451
452 switch (overrideScalingMode) {
453 case NATIVE_WINDOW_SCALING_MODE_FREEZE:
454 case NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW:
455 case NATIVE_WINDOW_SCALING_MODE_SCALE_CROP:
456 case NATIVE_WINDOW_SCALING_MODE_NO_SCALE_CROP:
457 case -1:
458 break;
459 default:
460 ALOGE("unknown scaling mode: %d",
461 overrideScalingMode);
462 return BAD_VALUE;
463 }
464
465 s->what |= layer_state_t::eOverrideScalingModeChanged;
466 s->overrideScalingMode = overrideScalingMode;
467 return NO_ERROR;
468}
469
Robert Carr99e27f02016-06-16 15:18:02 -0700470status_t Composer::setGeometryAppliesWithResize(
Robert Carr82364e32016-05-15 11:27:47 -0700471 const sp<SurfaceComposerClient>& client,
472 const sp<IBinder>& id) {
473 Mutex::Autolock lock(mLock);
474 layer_state_t* s = getLayerStateLocked(client, id);
475 if (!s) {
476 return BAD_INDEX;
477 }
Robert Carr99e27f02016-06-16 15:18:02 -0700478 s->what |= layer_state_t::eGeometryAppliesWithResize;
Robert Carr82364e32016-05-15 11:27:47 -0700479 return NO_ERROR;
480}
481
Mathias Agopian698c0872011-06-28 19:09:31 -0700482// ---------------------------------------------------------------------------
483
Mathias Agopiane57f2922012-08-09 16:29:12 -0700484DisplayState& Composer::getDisplayStateLocked(const sp<IBinder>& token) {
485 DisplayState s;
486 s.token = token;
487 ssize_t index = mDisplayStates.indexOf(s);
488 if (index < 0) {
489 // we don't have it, add an initialized layer_state to our list
490 s.what = 0;
491 index = mDisplayStates.add(s);
492 }
Dan Stozad723bd72014-11-18 10:24:03 -0800493 return mDisplayStates.editItemAt(static_cast<size_t>(index));
Mathias Agopiane57f2922012-08-09 16:29:12 -0700494}
495
496void Composer::setDisplaySurface(const sp<IBinder>& token,
Andy McFadden2adaf042012-12-18 09:49:45 -0800497 const sp<IGraphicBufferProducer>& bufferProducer) {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700498 Mutex::Autolock _l(mLock);
499 DisplayState& s(getDisplayStateLocked(token));
Andy McFadden2adaf042012-12-18 09:49:45 -0800500 s.surface = bufferProducer;
Mathias Agopiane57f2922012-08-09 16:29:12 -0700501 s.what |= DisplayState::eSurfaceChanged;
502}
503
504void Composer::setDisplayLayerStack(const sp<IBinder>& token,
505 uint32_t layerStack) {
506 Mutex::Autolock _l(mLock);
507 DisplayState& s(getDisplayStateLocked(token));
508 s.layerStack = layerStack;
509 s.what |= DisplayState::eLayerStackChanged;
510}
511
Mathias Agopian00e8c7a2012-09-04 19:30:46 -0700512void Composer::setDisplayProjection(const sp<IBinder>& token,
513 uint32_t orientation,
514 const Rect& layerStackRect,
515 const Rect& displayRect) {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700516 Mutex::Autolock _l(mLock);
517 DisplayState& s(getDisplayStateLocked(token));
518 s.orientation = orientation;
Mathias Agopian00e8c7a2012-09-04 19:30:46 -0700519 s.viewport = layerStackRect;
520 s.frame = displayRect;
521 s.what |= DisplayState::eDisplayProjectionChanged;
Jorim Jaggi092123c2016-04-13 01:40:35 +0000522 mForceSynchronous = true; // TODO: do we actually still need this?
Mathias Agopiane57f2922012-08-09 16:29:12 -0700523}
524
Michael Wright1f6078a2014-06-26 16:01:02 -0700525void Composer::setDisplaySize(const sp<IBinder>& token, uint32_t width, uint32_t height) {
526 Mutex::Autolock _l(mLock);
527 DisplayState& s(getDisplayStateLocked(token));
528 s.width = width;
529 s.height = height;
530 s.what |= DisplayState::eDisplaySizeChanged;
531}
532
Mathias Agopiane57f2922012-08-09 16:29:12 -0700533// ---------------------------------------------------------------------------
534
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800535SurfaceComposerClient::SurfaceComposerClient()
Mathias Agopian698c0872011-06-28 19:09:31 -0700536 : mStatus(NO_INIT), mComposer(Composer::getInstance())
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800537{
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800538}
539
Mathias Agopian698c0872011-06-28 19:09:31 -0700540void SurfaceComposerClient::onFirstRef() {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700541 sp<ISurfaceComposer> sm(ComposerService::getComposerService());
Mathias Agopiand4784a32010-05-27 19:41:15 -0700542 if (sm != 0) {
Mathias Agopian7e27f052010-05-28 14:22:23 -0700543 sp<ISurfaceComposerClient> conn = sm->createConnection();
Mathias Agopiand4784a32010-05-27 19:41:15 -0700544 if (conn != 0) {
545 mClient = conn;
Mathias Agopiand4784a32010-05-27 19:41:15 -0700546 mStatus = NO_ERROR;
547 }
548 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800549}
550
Mathias Agopian698c0872011-06-28 19:09:31 -0700551SurfaceComposerClient::~SurfaceComposerClient() {
Mathias Agopian631f3582010-05-25 17:51:34 -0700552 dispose();
553}
Mathias Agopiandd3423c2009-09-23 15:44:05 -0700554
Mathias Agopian698c0872011-06-28 19:09:31 -0700555status_t SurfaceComposerClient::initCheck() const {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800556 return mStatus;
557}
558
Mathias Agopian698c0872011-06-28 19:09:31 -0700559sp<IBinder> SurfaceComposerClient::connection() const {
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800560 return IInterface::asBinder(mClient);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800561}
562
Mathias Agopiand4784a32010-05-27 19:41:15 -0700563status_t SurfaceComposerClient::linkToComposerDeath(
564 const sp<IBinder::DeathRecipient>& recipient,
Mathias Agopian698c0872011-06-28 19:09:31 -0700565 void* cookie, uint32_t flags) {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700566 sp<ISurfaceComposer> sm(ComposerService::getComposerService());
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800567 return IInterface::asBinder(sm)->linkToDeath(recipient, cookie, flags);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800568}
569
Mathias Agopian698c0872011-06-28 19:09:31 -0700570void SurfaceComposerClient::dispose() {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800571 // this can be called more than once.
Mathias Agopian7e27f052010-05-28 14:22:23 -0700572 sp<ISurfaceComposerClient> client;
Mathias Agopiand4784a32010-05-27 19:41:15 -0700573 Mutex::Autolock _lm(mLock);
574 if (mClient != 0) {
Mathias Agopiand4784a32010-05-27 19:41:15 -0700575 client = mClient; // hold ref while lock is held
576 mClient.clear();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800577 }
Mathias Agopiand4784a32010-05-27 19:41:15 -0700578 mStatus = NO_INIT;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800579}
580
Mathias Agopian698c0872011-06-28 19:09:31 -0700581sp<SurfaceControl> SurfaceComposerClient::createSurface(
Mathias Agopian698c0872011-06-28 19:09:31 -0700582 const String8& name,
Mathias Agopian698c0872011-06-28 19:09:31 -0700583 uint32_t w,
584 uint32_t h,
585 PixelFormat format,
586 uint32_t flags)
587{
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700588 sp<SurfaceControl> sur;
Mathias Agopian698c0872011-06-28 19:09:31 -0700589 if (mStatus == NO_ERROR) {
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700590 sp<IBinder> handle;
591 sp<IGraphicBufferProducer> gbp;
592 status_t err = mClient->createSurface(name, w, h, format, flags,
593 &handle, &gbp);
594 ALOGE_IF(err, "SurfaceComposerClient::createSurface error %s", strerror(-err));
595 if (err == NO_ERROR) {
596 sur = new SurfaceControl(this, handle, gbp);
Mathias Agopian698c0872011-06-28 19:09:31 -0700597 }
598 }
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700599 return sur;
Mathias Agopian698c0872011-06-28 19:09:31 -0700600}
601
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700602sp<IBinder> SurfaceComposerClient::createDisplay(const String8& displayName,
603 bool secure) {
604 return Composer::getInstance().createDisplay(displayName, secure);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700605}
606
Jesse Hall6c913be2013-08-08 12:15:49 -0700607void SurfaceComposerClient::destroyDisplay(const sp<IBinder>& display) {
608 Composer::getInstance().destroyDisplay(display);
609}
610
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700611sp<IBinder> SurfaceComposerClient::getBuiltInDisplay(int32_t id) {
612 return Composer::getInstance().getBuiltInDisplay(id);
613}
614
Mathias Agopianac9fa422013-02-11 16:40:36 -0800615status_t SurfaceComposerClient::destroySurface(const sp<IBinder>& sid) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700616 if (mStatus != NO_ERROR)
617 return mStatus;
618 status_t err = mClient->destroySurface(sid);
619 return err;
620}
621
Svetoslavd85084b2014-03-20 10:28:31 -0700622status_t SurfaceComposerClient::clearLayerFrameStats(const sp<IBinder>& token) const {
623 if (mStatus != NO_ERROR) {
624 return mStatus;
625 }
626 return mClient->clearLayerFrameStats(token);
627}
628
629status_t SurfaceComposerClient::getLayerFrameStats(const sp<IBinder>& token,
630 FrameStats* outStats) const {
631 if (mStatus != NO_ERROR) {
632 return mStatus;
633 }
634 return mClient->getLayerFrameStats(token, outStats);
635}
636
Robert Carr367c5682016-06-20 11:55:28 -0700637status_t SurfaceComposerClient::getTransformToDisplayInverse(const sp<IBinder>& token,
638 bool* outTransformToDisplayInverse) const {
639 if (mStatus != NO_ERROR) {
640 return mStatus;
641 }
642 return mClient->getTransformToDisplayInverse(token, outTransformToDisplayInverse);
643}
644
Mathias Agopian698c0872011-06-28 19:09:31 -0700645inline Composer& SurfaceComposerClient::getComposer() {
646 return mComposer;
647}
648
649// ----------------------------------------------------------------------------
650
651void SurfaceComposerClient::openGlobalTransaction() {
Jeff Brownf3f7db62012-08-31 02:18:38 -0700652 Composer::openGlobalTransaction();
Mathias Agopian698c0872011-06-28 19:09:31 -0700653}
654
Jamie Gennis28378392011-10-12 17:39:00 -0700655void SurfaceComposerClient::closeGlobalTransaction(bool synchronous) {
656 Composer::closeGlobalTransaction(synchronous);
Mathias Agopian698c0872011-06-28 19:09:31 -0700657}
658
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700659void SurfaceComposerClient::setAnimationTransaction() {
660 Composer::setAnimationTransaction();
661}
662
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -0700663status_t SurfaceComposerClient::enableVSyncInjections(bool enable) {
664 return Composer::enableVSyncInjections(enable);
665}
666
667status_t SurfaceComposerClient::injectVSync(nsecs_t when) {
668 return Composer::injectVSync(when);
669}
670
Mathias Agopian698c0872011-06-28 19:09:31 -0700671// ----------------------------------------------------------------------------
672
Mathias Agopianac9fa422013-02-11 16:40:36 -0800673status_t SurfaceComposerClient::setCrop(const sp<IBinder>& id, const Rect& crop) {
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700674 return getComposer().setCrop(this, id, crop);
675}
676
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000677status_t SurfaceComposerClient::setFinalCrop(const sp<IBinder>& id,
678 const Rect& crop) {
679 return getComposer().setFinalCrop(this, id, crop);
680}
681
Mathias Agopianac9fa422013-02-11 16:40:36 -0800682status_t SurfaceComposerClient::setPosition(const sp<IBinder>& id, float x, float y) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700683 return getComposer().setPosition(this, id, x, y);
684}
685
Mathias Agopianac9fa422013-02-11 16:40:36 -0800686status_t SurfaceComposerClient::setSize(const sp<IBinder>& id, uint32_t w, uint32_t h) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700687 return getComposer().setSize(this, id, w, h);
688}
689
Dan Stozad723bd72014-11-18 10:24:03 -0800690status_t SurfaceComposerClient::setLayer(const sp<IBinder>& id, uint32_t z) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700691 return getComposer().setLayer(this, id, z);
692}
693
Mathias Agopianac9fa422013-02-11 16:40:36 -0800694status_t SurfaceComposerClient::hide(const sp<IBinder>& id) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700695 return getComposer().setFlags(this, id,
Mathias Agopian3165cc22012-08-08 19:42:09 -0700696 layer_state_t::eLayerHidden,
697 layer_state_t::eLayerHidden);
Mathias Agopian698c0872011-06-28 19:09:31 -0700698}
699
Mathias Agopianac9fa422013-02-11 16:40:36 -0800700status_t SurfaceComposerClient::show(const sp<IBinder>& id) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700701 return getComposer().setFlags(this, id,
702 0,
Mathias Agopian3165cc22012-08-08 19:42:09 -0700703 layer_state_t::eLayerHidden);
Mathias Agopian698c0872011-06-28 19:09:31 -0700704}
705
Mathias Agopianac9fa422013-02-11 16:40:36 -0800706status_t SurfaceComposerClient::setFlags(const sp<IBinder>& id, uint32_t flags,
Mathias Agopian698c0872011-06-28 19:09:31 -0700707 uint32_t mask) {
708 return getComposer().setFlags(this, id, flags, mask);
709}
710
Mathias Agopianac9fa422013-02-11 16:40:36 -0800711status_t SurfaceComposerClient::setTransparentRegionHint(const sp<IBinder>& id,
Mathias Agopian698c0872011-06-28 19:09:31 -0700712 const Region& transparentRegion) {
713 return getComposer().setTransparentRegionHint(this, id, transparentRegion);
714}
715
Mathias Agopianac9fa422013-02-11 16:40:36 -0800716status_t SurfaceComposerClient::setAlpha(const sp<IBinder>& id, float alpha) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700717 return getComposer().setAlpha(this, id, alpha);
718}
719
Mathias Agopianac9fa422013-02-11 16:40:36 -0800720status_t SurfaceComposerClient::setLayerStack(const sp<IBinder>& id, uint32_t layerStack) {
Mathias Agopian87855782012-07-24 21:41:09 -0700721 return getComposer().setLayerStack(this, id, layerStack);
722}
723
Mathias Agopianac9fa422013-02-11 16:40:36 -0800724status_t SurfaceComposerClient::setMatrix(const sp<IBinder>& id, float dsdx, float dtdx,
Mathias Agopian698c0872011-06-28 19:09:31 -0700725 float dsdy, float dtdy) {
726 return getComposer().setMatrix(this, id, dsdx, dtdx, dsdy, dtdy);
727}
728
Dan Stoza7dde5992015-05-22 09:51:44 -0700729status_t SurfaceComposerClient::deferTransactionUntil(const sp<IBinder>& id,
730 const sp<IBinder>& handle, uint64_t frameNumber) {
731 return getComposer().deferTransactionUntil(this, id, handle, frameNumber);
732}
733
Robert Carrc3574f72016-03-24 12:19:32 -0700734status_t SurfaceComposerClient::setOverrideScalingMode(
735 const sp<IBinder>& id, int32_t overrideScalingMode) {
736 return getComposer().setOverrideScalingMode(
737 this, id, overrideScalingMode);
738}
739
Robert Carr99e27f02016-06-16 15:18:02 -0700740status_t SurfaceComposerClient::setGeometryAppliesWithResize(
Robert Carr82364e32016-05-15 11:27:47 -0700741 const sp<IBinder>& id) {
Robert Carr99e27f02016-06-16 15:18:02 -0700742 return getComposer().setGeometryAppliesWithResize(this, id);
Robert Carr82364e32016-05-15 11:27:47 -0700743}
744
Mathias Agopian698c0872011-06-28 19:09:31 -0700745// ----------------------------------------------------------------------------
746
Mathias Agopiane57f2922012-08-09 16:29:12 -0700747void SurfaceComposerClient::setDisplaySurface(const sp<IBinder>& token,
Andy McFadden2adaf042012-12-18 09:49:45 -0800748 const sp<IGraphicBufferProducer>& bufferProducer) {
749 Composer::getInstance().setDisplaySurface(token, bufferProducer);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700750}
751
752void SurfaceComposerClient::setDisplayLayerStack(const sp<IBinder>& token,
753 uint32_t layerStack) {
754 Composer::getInstance().setDisplayLayerStack(token, layerStack);
755}
756
Mathias Agopian00e8c7a2012-09-04 19:30:46 -0700757void SurfaceComposerClient::setDisplayProjection(const sp<IBinder>& token,
758 uint32_t orientation,
759 const Rect& layerStackRect,
760 const Rect& displayRect) {
761 Composer::getInstance().setDisplayProjection(token, orientation,
762 layerStackRect, displayRect);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700763}
764
Michael Wright1f6078a2014-06-26 16:01:02 -0700765void SurfaceComposerClient::setDisplaySize(const sp<IBinder>& token,
766 uint32_t width, uint32_t height) {
767 Composer::getInstance().setDisplaySize(token, width, height);
768}
769
Mathias Agopiane57f2922012-08-09 16:29:12 -0700770// ----------------------------------------------------------------------------
771
Dan Stoza7f7da322014-05-02 15:26:25 -0700772status_t SurfaceComposerClient::getDisplayConfigs(
773 const sp<IBinder>& display, Vector<DisplayInfo>* configs)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800774{
Dan Stoza7f7da322014-05-02 15:26:25 -0700775 return ComposerService::getComposerService()->getDisplayConfigs(display, configs);
776}
777
778status_t SurfaceComposerClient::getDisplayInfo(const sp<IBinder>& display,
779 DisplayInfo* info) {
780 Vector<DisplayInfo> configs;
781 status_t result = getDisplayConfigs(display, &configs);
782 if (result != NO_ERROR) {
783 return result;
784 }
785
786 int activeId = getActiveConfig(display);
787 if (activeId < 0) {
788 ALOGE("No active configuration found");
789 return NAME_NOT_FOUND;
790 }
791
Dan Stozad723bd72014-11-18 10:24:03 -0800792 *info = configs[static_cast<size_t>(activeId)];
Dan Stoza7f7da322014-05-02 15:26:25 -0700793 return NO_ERROR;
794}
795
796int SurfaceComposerClient::getActiveConfig(const sp<IBinder>& display) {
797 return ComposerService::getComposerService()->getActiveConfig(display);
798}
799
800status_t SurfaceComposerClient::setActiveConfig(const sp<IBinder>& display, int id) {
801 return ComposerService::getComposerService()->setActiveConfig(display, id);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800802}
803
Michael Wright28f24d02016-07-12 13:30:53 -0700804status_t SurfaceComposerClient::getDisplayColorModes(const sp<IBinder>& display,
805 Vector<android_color_mode_t>* outColorModes) {
806 return ComposerService::getComposerService()->getDisplayColorModes(display, outColorModes);
807}
808
809android_color_mode_t SurfaceComposerClient::getActiveColorMode(const sp<IBinder>& display) {
810 return ComposerService::getComposerService()->getActiveColorMode(display);
811}
812
813status_t SurfaceComposerClient::setActiveColorMode(const sp<IBinder>& display,
814 android_color_mode_t colorMode) {
815 return ComposerService::getComposerService()->setActiveColorMode(display, colorMode);
816}
817
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700818void SurfaceComposerClient::setDisplayPowerMode(const sp<IBinder>& token,
819 int mode) {
820 ComposerService::getComposerService()->setPowerMode(token, mode);
Jeff Brown2a09bb32012-10-08 19:13:57 -0700821}
822
Svetoslavd85084b2014-03-20 10:28:31 -0700823status_t SurfaceComposerClient::clearAnimationFrameStats() {
824 return ComposerService::getComposerService()->clearAnimationFrameStats();
825}
826
827status_t SurfaceComposerClient::getAnimationFrameStats(FrameStats* outStats) {
828 return ComposerService::getComposerService()->getAnimationFrameStats(outStats);
829}
830
Dan Stozac4f471e2016-03-24 09:31:08 -0700831status_t SurfaceComposerClient::getHdrCapabilities(const sp<IBinder>& display,
832 HdrCapabilities* outCapabilities) {
833 return ComposerService::getComposerService()->getHdrCapabilities(display,
834 outCapabilities);
835}
836
Mathias Agopian698c0872011-06-28 19:09:31 -0700837// ----------------------------------------------------------------------------
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800838
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800839status_t ScreenshotClient::capture(
840 const sp<IBinder>& display,
841 const sp<IGraphicBufferProducer>& producer,
Dan Stozac1879002014-05-22 15:59:05 -0700842 Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
Dan Stozac7014012014-02-14 15:03:43 -0800843 uint32_t minLayerZ, uint32_t maxLayerZ, bool useIdentityTransform) {
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800844 sp<ISurfaceComposer> s(ComposerService::getComposerService());
845 if (s == NULL) return NO_INIT;
Dan Stozac1879002014-05-22 15:59:05 -0700846 return s->captureScreen(display, producer, sourceCrop,
Dan Stozac7014012014-02-14 15:03:43 -0800847 reqWidth, reqHeight, minLayerZ, maxLayerZ, useIdentityTransform);
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800848}
849
Mathias Agopian74c40c02010-09-29 13:02:36 -0700850ScreenshotClient::ScreenshotClient()
Mathias Agopianabe815d2013-03-19 22:22:21 -0700851 : mHaveBuffer(false) {
852 memset(&mBuffer, 0, sizeof(mBuffer));
Mathias Agopian74c40c02010-09-29 13:02:36 -0700853}
854
Mathias Agopian8000d062013-03-26 18:15:35 -0700855ScreenshotClient::~ScreenshotClient() {
856 ScreenshotClient::release();
857}
858
Mathias Agopianabe815d2013-03-19 22:22:21 -0700859sp<CpuConsumer> ScreenshotClient::getCpuConsumer() const {
860 if (mCpuConsumer == NULL) {
Dan Stoza6d5a7bb2014-03-13 11:39:09 -0700861 sp<IGraphicBufferConsumer> consumer;
862 BufferQueue::createBufferQueue(&mProducer, &consumer);
863 mCpuConsumer = new CpuConsumer(consumer, 1);
Mathias Agopianabe815d2013-03-19 22:22:21 -0700864 mCpuConsumer->setName(String8("ScreenshotClient"));
865 }
866 return mCpuConsumer;
Mathias Agopianbf2c6a62010-12-10 16:22:31 -0800867}
868
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700869status_t ScreenshotClient::update(const sp<IBinder>& display,
Dan Stozac1879002014-05-22 15:59:05 -0700870 Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
Dan Stozac7014012014-02-14 15:03:43 -0800871 uint32_t minLayerZ, uint32_t maxLayerZ,
Riley Andrewsd15ef272014-09-04 16:19:44 -0700872 bool useIdentityTransform, uint32_t rotation) {
Mathias Agopianbf2c6a62010-12-10 16:22:31 -0800873 sp<ISurfaceComposer> s(ComposerService::getComposerService());
874 if (s == NULL) return NO_INIT;
Mathias Agopianabe815d2013-03-19 22:22:21 -0700875 sp<CpuConsumer> cpuConsumer = getCpuConsumer();
876
877 if (mHaveBuffer) {
878 mCpuConsumer->unlockBuffer(mBuffer);
879 memset(&mBuffer, 0, sizeof(mBuffer));
880 mHaveBuffer = false;
881 }
882
Dan Stozac1879002014-05-22 15:59:05 -0700883 status_t err = s->captureScreen(display, mProducer, sourceCrop,
Riley Andrewsd15ef272014-09-04 16:19:44 -0700884 reqWidth, reqHeight, minLayerZ, maxLayerZ, useIdentityTransform,
885 static_cast<ISurfaceComposer::Rotation>(rotation));
Mathias Agopianabe815d2013-03-19 22:22:21 -0700886
887 if (err == NO_ERROR) {
888 err = mCpuConsumer->lockNextBuffer(&mBuffer);
889 if (err == NO_ERROR) {
890 mHaveBuffer = true;
891 }
892 }
893 return err;
894}
895
Riley Andrewsd15ef272014-09-04 16:19:44 -0700896status_t ScreenshotClient::update(const sp<IBinder>& display,
897 Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
898 uint32_t minLayerZ, uint32_t maxLayerZ,
899 bool useIdentityTransform) {
900
901 return ScreenshotClient::update(display, sourceCrop, reqWidth, reqHeight,
902 minLayerZ, maxLayerZ, useIdentityTransform, ISurfaceComposer::eRotateNone);
903}
904
Dan Stozac1879002014-05-22 15:59:05 -0700905status_t ScreenshotClient::update(const sp<IBinder>& display, Rect sourceCrop,
Dan Stozac7014012014-02-14 15:03:43 -0800906 bool useIdentityTransform) {
Dan Stozaf10c46e2014-11-11 10:32:31 -0800907 return ScreenshotClient::update(display, sourceCrop, 0, 0, 0, -1U,
Riley Andrewsd15ef272014-09-04 16:19:44 -0700908 useIdentityTransform, ISurfaceComposer::eRotateNone);
Mathias Agopianabe815d2013-03-19 22:22:21 -0700909}
910
Dan Stozac1879002014-05-22 15:59:05 -0700911status_t ScreenshotClient::update(const sp<IBinder>& display, Rect sourceCrop,
Dan Stozac7014012014-02-14 15:03:43 -0800912 uint32_t reqWidth, uint32_t reqHeight, bool useIdentityTransform) {
Dan Stozac1879002014-05-22 15:59:05 -0700913 return ScreenshotClient::update(display, sourceCrop, reqWidth, reqHeight,
Dan Stozaf10c46e2014-11-11 10:32:31 -0800914 0, -1U, useIdentityTransform, ISurfaceComposer::eRotateNone);
Mathias Agopian74c40c02010-09-29 13:02:36 -0700915}
916
917void ScreenshotClient::release() {
Mathias Agopianabe815d2013-03-19 22:22:21 -0700918 if (mHaveBuffer) {
919 mCpuConsumer->unlockBuffer(mBuffer);
920 memset(&mBuffer, 0, sizeof(mBuffer));
921 mHaveBuffer = false;
922 }
923 mCpuConsumer.clear();
Mathias Agopian74c40c02010-09-29 13:02:36 -0700924}
925
926void const* ScreenshotClient::getPixels() const {
Mathias Agopianabe815d2013-03-19 22:22:21 -0700927 return mBuffer.data;
Mathias Agopian74c40c02010-09-29 13:02:36 -0700928}
929
930uint32_t ScreenshotClient::getWidth() const {
Mathias Agopianabe815d2013-03-19 22:22:21 -0700931 return mBuffer.width;
Mathias Agopian74c40c02010-09-29 13:02:36 -0700932}
933
934uint32_t ScreenshotClient::getHeight() const {
Mathias Agopianabe815d2013-03-19 22:22:21 -0700935 return mBuffer.height;
Mathias Agopian74c40c02010-09-29 13:02:36 -0700936}
937
938PixelFormat ScreenshotClient::getFormat() const {
Mathias Agopianabe815d2013-03-19 22:22:21 -0700939 return mBuffer.format;
Mathias Agopian74c40c02010-09-29 13:02:36 -0700940}
941
942uint32_t ScreenshotClient::getStride() const {
Mathias Agopianabe815d2013-03-19 22:22:21 -0700943 return mBuffer.stride;
Mathias Agopian74c40c02010-09-29 13:02:36 -0700944}
945
946size_t ScreenshotClient::getSize() const {
Mathias Agopianabe815d2013-03-19 22:22:21 -0700947 return mBuffer.stride * mBuffer.height * bytesPerPixel(mBuffer.format);
Mathias Agopian74c40c02010-09-29 13:02:36 -0700948}
949
950// ----------------------------------------------------------------------------
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800951}; // namespace android