blob: ae81c8fbd1c5431a48d20b1d9068cdde36b9a6c6 [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,
Robert Carrae060832016-11-28 10:51:00 -0800151 int32_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 Carr1db73f62016-12-21 12:58:51 -0800171 status_t reparentChildren(const sp<SurfaceComposerClient>& client,
172 const sp<IBinder>& id,
173 const sp<IBinder>& newParentHandle);
Robert Carrc3574f72016-03-24 12:19:32 -0700174 status_t setOverrideScalingMode(const sp<SurfaceComposerClient>& client,
175 const sp<IBinder>& id, int32_t overrideScalingMode);
Robert Carr99e27f02016-06-16 15:18:02 -0700176 status_t setGeometryAppliesWithResize(const sp<SurfaceComposerClient>& client,
Robert Carr82364e32016-05-15 11:27:47 -0700177 const sp<IBinder>& id);
Mathias Agopian698c0872011-06-28 19:09:31 -0700178
Pablo Ceballos1aad24c2016-08-04 10:24:22 -0700179 status_t setDisplaySurface(const sp<IBinder>& token,
180 sp<IGraphicBufferProducer> bufferProducer);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700181 void setDisplayLayerStack(const sp<IBinder>& token, uint32_t layerStack);
Mathias Agopian00e8c7a2012-09-04 19:30:46 -0700182 void setDisplayProjection(const sp<IBinder>& token,
183 uint32_t orientation,
184 const Rect& layerStackRect,
185 const Rect& displayRect);
Michael Wright1f6078a2014-06-26 16:01:02 -0700186 void setDisplaySize(const sp<IBinder>& token, uint32_t width, uint32_t height);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700187
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700188 static void setAnimationTransaction() {
189 Composer::getInstance().setAnimationTransactionImpl();
190 }
191
Jeff Brownf3f7db62012-08-31 02:18:38 -0700192 static void openGlobalTransaction() {
193 Composer::getInstance().openGlobalTransactionImpl();
194 }
195
Jamie Gennis28378392011-10-12 17:39:00 -0700196 static void closeGlobalTransaction(bool synchronous) {
197 Composer::getInstance().closeGlobalTransactionImpl(synchronous);
Mathias Agopiand4784a32010-05-27 19:41:15 -0700198 }
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -0700199
200 static status_t enableVSyncInjections(bool enable) {
201 return Composer::getInstance().enableVSyncInjectionsImpl(enable);
202 }
203
204 static status_t injectVSync(nsecs_t when) {
205 return Composer::getInstance().injectVSyncImpl(when);
206 }
Mathias Agopiand4784a32010-05-27 19:41:15 -0700207};
208
209ANDROID_SINGLETON_STATIC_INSTANCE(Composer);
210
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800211// ---------------------------------------------------------------------------
212
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700213sp<IBinder> Composer::createDisplay(const String8& displayName, bool secure) {
214 return ComposerService::getComposerService()->createDisplay(displayName,
215 secure);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700216}
217
Jesse Hall6c913be2013-08-08 12:15:49 -0700218void Composer::destroyDisplay(const sp<IBinder>& display) {
219 return ComposerService::getComposerService()->destroyDisplay(display);
220}
221
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700222sp<IBinder> Composer::getBuiltInDisplay(int32_t id) {
223 return ComposerService::getComposerService()->getBuiltInDisplay(id);
224}
225
Jeff Brownf3f7db62012-08-31 02:18:38 -0700226void Composer::openGlobalTransactionImpl() {
227 { // scope for the lock
228 Mutex::Autolock _l(mLock);
229 mTransactionNestCount += 1;
230 }
231}
232
Jamie Gennis28378392011-10-12 17:39:00 -0700233void Composer::closeGlobalTransactionImpl(bool synchronous) {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700234 sp<ISurfaceComposer> sm(ComposerService::getComposerService());
Mathias Agopian698c0872011-06-28 19:09:31 -0700235
236 Vector<ComposerState> transaction;
Mathias Agopian8b33f032012-07-24 20:43:54 -0700237 Vector<DisplayState> displayTransaction;
Jamie Gennis28378392011-10-12 17:39:00 -0700238 uint32_t flags = 0;
Mathias Agopian698c0872011-06-28 19:09:31 -0700239
240 { // scope for the lock
241 Mutex::Autolock _l(mLock);
Jeff Brownf3f7db62012-08-31 02:18:38 -0700242 mForceSynchronous |= synchronous;
243 if (!mTransactionNestCount) {
244 ALOGW("At least one call to closeGlobalTransaction() was not matched by a prior "
245 "call to openGlobalTransaction().");
246 } else if (--mTransactionNestCount) {
247 return;
248 }
249
Mathias Agopiane57f2922012-08-09 16:29:12 -0700250 transaction = mComposerStates;
251 mComposerStates.clear();
Jamie Gennisb8d69a52011-10-10 15:48:06 -0700252
Mathias Agopiane57f2922012-08-09 16:29:12 -0700253 displayTransaction = mDisplayStates;
254 mDisplayStates.clear();
Jamie Gennis28378392011-10-12 17:39:00 -0700255
Jeff Brownf3f7db62012-08-31 02:18:38 -0700256 if (mForceSynchronous) {
Jamie Gennis28378392011-10-12 17:39:00 -0700257 flags |= ISurfaceComposer::eSynchronous;
258 }
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700259 if (mAnimation) {
260 flags |= ISurfaceComposer::eAnimation;
261 }
262
Jamie Gennis28378392011-10-12 17:39:00 -0700263 mForceSynchronous = false;
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700264 mAnimation = false;
Mathias Agopian698c0872011-06-28 19:09:31 -0700265 }
266
Mathias Agopian8b33f032012-07-24 20:43:54 -0700267 sm->setTransactionState(transaction, displayTransaction, flags);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800268}
269
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -0700270status_t Composer::enableVSyncInjectionsImpl(bool enable) {
271 sp<ISurfaceComposer> sm(ComposerService::getComposerService());
272 return sm->enableVSyncInjections(enable);
273}
274
275status_t Composer::injectVSyncImpl(nsecs_t when) {
276 sp<ISurfaceComposer> sm(ComposerService::getComposerService());
277 return sm->injectVSync(when);
278}
279
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700280void Composer::setAnimationTransactionImpl() {
281 Mutex::Autolock _l(mLock);
282 mAnimation = true;
283}
284
Mathias Agopian698c0872011-06-28 19:09:31 -0700285layer_state_t* Composer::getLayerStateLocked(
Mathias Agopianac9fa422013-02-11 16:40:36 -0800286 const sp<SurfaceComposerClient>& client, const sp<IBinder>& id) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700287
288 ComposerState s;
289 s.client = client->mClient;
290 s.state.surface = id;
291
Mathias Agopiane57f2922012-08-09 16:29:12 -0700292 ssize_t index = mComposerStates.indexOf(s);
Mathias Agopian698c0872011-06-28 19:09:31 -0700293 if (index < 0) {
294 // we don't have it, add an initialized layer_state to our list
Mathias Agopiane57f2922012-08-09 16:29:12 -0700295 index = mComposerStates.add(s);
Mathias Agopian698c0872011-06-28 19:09:31 -0700296 }
297
Mathias Agopiane57f2922012-08-09 16:29:12 -0700298 ComposerState* const out = mComposerStates.editArray();
Mathias Agopian698c0872011-06-28 19:09:31 -0700299 return &(out[index].state);
300}
301
302status_t Composer::setPosition(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-11 16:40:36 -0800303 const sp<IBinder>& id, float x, float y) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700304 Mutex::Autolock _l(mLock);
305 layer_state_t* s = getLayerStateLocked(client, id);
306 if (!s)
307 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700308 s->what |= layer_state_t::ePositionChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700309 s->x = x;
310 s->y = y;
311 return NO_ERROR;
312}
313
314status_t Composer::setSize(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-11 16:40:36 -0800315 const sp<IBinder>& id, uint32_t w, uint32_t h) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700316 Mutex::Autolock _l(mLock);
317 layer_state_t* s = getLayerStateLocked(client, id);
318 if (!s)
319 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700320 s->what |= layer_state_t::eSizeChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700321 s->w = w;
322 s->h = h;
Jamie Gennis28378392011-10-12 17:39:00 -0700323
Jorim Jaggi092123c2016-04-13 01:40:35 +0000324 // Resizing a surface makes the transaction synchronous.
325 mForceSynchronous = true;
326
Mathias Agopian698c0872011-06-28 19:09:31 -0700327 return NO_ERROR;
328}
329
330status_t Composer::setLayer(const sp<SurfaceComposerClient>& client,
Robert Carrae060832016-11-28 10:51:00 -0800331 const sp<IBinder>& id, int32_t z) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700332 Mutex::Autolock _l(mLock);
333 layer_state_t* s = getLayerStateLocked(client, id);
334 if (!s)
335 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700336 s->what |= layer_state_t::eLayerChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700337 s->z = z;
338 return NO_ERROR;
339}
340
341status_t Composer::setFlags(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-11 16:40:36 -0800342 const sp<IBinder>& id, uint32_t flags,
Mathias Agopian698c0872011-06-28 19:09:31 -0700343 uint32_t mask) {
344 Mutex::Autolock _l(mLock);
345 layer_state_t* s = getLayerStateLocked(client, id);
346 if (!s)
347 return BAD_INDEX;
Pablo Ceballos53390e12015-08-04 11:25:59 -0700348 if ((mask & layer_state_t::eLayerOpaque) ||
349 (mask & layer_state_t::eLayerHidden) ||
350 (mask & layer_state_t::eLayerSecure)) {
Dan Stoza23116082015-06-18 14:58:39 -0700351 s->what |= layer_state_t::eFlagsChanged;
Andy McFadden4125a4f2014-01-29 17:17:11 -0800352 }
Mathias Agopian698c0872011-06-28 19:09:31 -0700353 s->flags &= ~mask;
354 s->flags |= (flags & mask);
355 s->mask |= mask;
356 return NO_ERROR;
357}
358
359status_t Composer::setTransparentRegionHint(
Mathias Agopianac9fa422013-02-11 16:40:36 -0800360 const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
Mathias Agopian698c0872011-06-28 19:09:31 -0700361 const Region& transparentRegion) {
362 Mutex::Autolock _l(mLock);
363 layer_state_t* s = getLayerStateLocked(client, id);
364 if (!s)
365 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700366 s->what |= layer_state_t::eTransparentRegionChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700367 s->transparentRegion = transparentRegion;
368 return NO_ERROR;
369}
370
371status_t Composer::setAlpha(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-11 16:40:36 -0800372 const sp<IBinder>& id, float alpha) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700373 Mutex::Autolock _l(mLock);
374 layer_state_t* s = getLayerStateLocked(client, id);
375 if (!s)
376 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700377 s->what |= layer_state_t::eAlphaChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700378 s->alpha = alpha;
379 return NO_ERROR;
380}
381
Mathias Agopian87855782012-07-24 21:41:09 -0700382status_t Composer::setLayerStack(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-11 16:40:36 -0800383 const sp<IBinder>& id, uint32_t layerStack) {
Mathias Agopian87855782012-07-24 21:41:09 -0700384 Mutex::Autolock _l(mLock);
385 layer_state_t* s = getLayerStateLocked(client, id);
386 if (!s)
387 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700388 s->what |= layer_state_t::eLayerStackChanged;
Mathias Agopian87855782012-07-24 21:41:09 -0700389 s->layerStack = layerStack;
390 return NO_ERROR;
391}
392
Mathias Agopian698c0872011-06-28 19:09:31 -0700393status_t Composer::setMatrix(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-11 16:40:36 -0800394 const sp<IBinder>& id, float dsdx, float dtdx,
Mathias Agopian698c0872011-06-28 19:09:31 -0700395 float dsdy, float dtdy) {
396 Mutex::Autolock _l(mLock);
397 layer_state_t* s = getLayerStateLocked(client, id);
398 if (!s)
399 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700400 s->what |= layer_state_t::eMatrixChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700401 layer_state_t::matrix22_t matrix;
402 matrix.dsdx = dsdx;
403 matrix.dtdx = dtdx;
404 matrix.dsdy = dsdy;
405 matrix.dtdy = dtdy;
406 s->matrix = matrix;
407 return NO_ERROR;
408}
409
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700410status_t Composer::setCrop(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-11 16:40:36 -0800411 const sp<IBinder>& id, const Rect& crop) {
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700412 Mutex::Autolock _l(mLock);
413 layer_state_t* s = getLayerStateLocked(client, id);
414 if (!s)
415 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700416 s->what |= layer_state_t::eCropChanged;
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700417 s->crop = crop;
418 return NO_ERROR;
419}
420
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000421status_t Composer::setFinalCrop(const sp<SurfaceComposerClient>& client,
422 const sp<IBinder>& id, const Rect& crop) {
423 Mutex::Autolock _l(mLock);
424 layer_state_t* s = getLayerStateLocked(client, id);
425 if (!s) {
426 return BAD_INDEX;
427 }
428 s->what |= layer_state_t::eFinalCropChanged;
429 s->finalCrop = crop;
430 return NO_ERROR;
431}
432
Dan Stoza7dde5992015-05-22 09:51:44 -0700433status_t Composer::deferTransactionUntil(
434 const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
435 const sp<IBinder>& handle, uint64_t frameNumber) {
436 Mutex::Autolock lock(mLock);
437 layer_state_t* s = getLayerStateLocked(client, id);
438 if (!s) {
439 return BAD_INDEX;
440 }
441 s->what |= layer_state_t::eDeferTransaction;
442 s->handle = handle;
443 s->frameNumber = frameNumber;
444 return NO_ERROR;
445}
446
Robert Carr1db73f62016-12-21 12:58:51 -0800447status_t Composer::reparentChildren(
448 const sp<SurfaceComposerClient>& client,
449 const sp<IBinder>& id,
450 const sp<IBinder>& newParentHandle) {
451 Mutex::Autolock lock(mLock);
452 layer_state_t* s = getLayerStateLocked(client, id);
453 if (!s) {
454 return BAD_INDEX;
455 }
456 s->what |= layer_state_t::eReparentChildren;
457 s->reparentHandle = newParentHandle;
458 return NO_ERROR;
459}
460
Robert Carrc3574f72016-03-24 12:19:32 -0700461status_t Composer::setOverrideScalingMode(
462 const sp<SurfaceComposerClient>& client,
463 const sp<IBinder>& id, int32_t overrideScalingMode) {
464 Mutex::Autolock lock(mLock);
465 layer_state_t* s = getLayerStateLocked(client, id);
466 if (!s) {
467 return BAD_INDEX;
468 }
469
470 switch (overrideScalingMode) {
471 case NATIVE_WINDOW_SCALING_MODE_FREEZE:
472 case NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW:
473 case NATIVE_WINDOW_SCALING_MODE_SCALE_CROP:
474 case NATIVE_WINDOW_SCALING_MODE_NO_SCALE_CROP:
475 case -1:
476 break;
477 default:
478 ALOGE("unknown scaling mode: %d",
479 overrideScalingMode);
480 return BAD_VALUE;
481 }
482
483 s->what |= layer_state_t::eOverrideScalingModeChanged;
484 s->overrideScalingMode = overrideScalingMode;
485 return NO_ERROR;
486}
487
Robert Carr99e27f02016-06-16 15:18:02 -0700488status_t Composer::setGeometryAppliesWithResize(
Robert Carr82364e32016-05-15 11:27:47 -0700489 const sp<SurfaceComposerClient>& client,
490 const sp<IBinder>& id) {
491 Mutex::Autolock lock(mLock);
492 layer_state_t* s = getLayerStateLocked(client, id);
493 if (!s) {
494 return BAD_INDEX;
495 }
Robert Carr99e27f02016-06-16 15:18:02 -0700496 s->what |= layer_state_t::eGeometryAppliesWithResize;
Robert Carr82364e32016-05-15 11:27:47 -0700497 return NO_ERROR;
498}
499
Mathias Agopian698c0872011-06-28 19:09:31 -0700500// ---------------------------------------------------------------------------
501
Mathias Agopiane57f2922012-08-09 16:29:12 -0700502DisplayState& Composer::getDisplayStateLocked(const sp<IBinder>& token) {
503 DisplayState s;
504 s.token = token;
505 ssize_t index = mDisplayStates.indexOf(s);
506 if (index < 0) {
507 // we don't have it, add an initialized layer_state to our list
508 s.what = 0;
509 index = mDisplayStates.add(s);
510 }
Dan Stozad723bd72014-11-18 10:24:03 -0800511 return mDisplayStates.editItemAt(static_cast<size_t>(index));
Mathias Agopiane57f2922012-08-09 16:29:12 -0700512}
513
Pablo Ceballos1aad24c2016-08-04 10:24:22 -0700514status_t Composer::setDisplaySurface(const sp<IBinder>& token,
515 sp<IGraphicBufferProducer> bufferProducer) {
Pablo Ceballoseddbef82016-09-01 11:21:21 -0700516 if (bufferProducer.get() != nullptr) {
517 // Make sure that composition can never be stalled by a virtual display
518 // consumer that isn't processing buffers fast enough.
519 status_t err = bufferProducer->setAsyncMode(true);
520 if (err != NO_ERROR) {
521 ALOGE("Composer::setDisplaySurface Failed to enable async mode on the "
522 "BufferQueue. This BufferQueue cannot be used for virtual "
523 "display. (%d)", err);
524 return err;
525 }
Pablo Ceballos1aad24c2016-08-04 10:24:22 -0700526 }
Mathias Agopiane57f2922012-08-09 16:29:12 -0700527 Mutex::Autolock _l(mLock);
528 DisplayState& s(getDisplayStateLocked(token));
Andy McFadden2adaf042012-12-18 09:49:45 -0800529 s.surface = bufferProducer;
Mathias Agopiane57f2922012-08-09 16:29:12 -0700530 s.what |= DisplayState::eSurfaceChanged;
Pablo Ceballos1aad24c2016-08-04 10:24:22 -0700531 return NO_ERROR;
Mathias Agopiane57f2922012-08-09 16:29:12 -0700532}
533
534void Composer::setDisplayLayerStack(const sp<IBinder>& token,
535 uint32_t layerStack) {
536 Mutex::Autolock _l(mLock);
537 DisplayState& s(getDisplayStateLocked(token));
538 s.layerStack = layerStack;
539 s.what |= DisplayState::eLayerStackChanged;
540}
541
Mathias Agopian00e8c7a2012-09-04 19:30:46 -0700542void Composer::setDisplayProjection(const sp<IBinder>& token,
543 uint32_t orientation,
544 const Rect& layerStackRect,
545 const Rect& displayRect) {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700546 Mutex::Autolock _l(mLock);
547 DisplayState& s(getDisplayStateLocked(token));
548 s.orientation = orientation;
Mathias Agopian00e8c7a2012-09-04 19:30:46 -0700549 s.viewport = layerStackRect;
550 s.frame = displayRect;
551 s.what |= DisplayState::eDisplayProjectionChanged;
Jorim Jaggi092123c2016-04-13 01:40:35 +0000552 mForceSynchronous = true; // TODO: do we actually still need this?
Mathias Agopiane57f2922012-08-09 16:29:12 -0700553}
554
Michael Wright1f6078a2014-06-26 16:01:02 -0700555void Composer::setDisplaySize(const sp<IBinder>& token, uint32_t width, uint32_t height) {
556 Mutex::Autolock _l(mLock);
557 DisplayState& s(getDisplayStateLocked(token));
558 s.width = width;
559 s.height = height;
560 s.what |= DisplayState::eDisplaySizeChanged;
561}
562
Mathias Agopiane57f2922012-08-09 16:29:12 -0700563// ---------------------------------------------------------------------------
564
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800565SurfaceComposerClient::SurfaceComposerClient()
Mathias Agopian698c0872011-06-28 19:09:31 -0700566 : mStatus(NO_INIT), mComposer(Composer::getInstance())
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800567{
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800568}
569
Robert Carr1db73f62016-12-21 12:58:51 -0800570SurfaceComposerClient::SurfaceComposerClient(const sp<IGraphicBufferProducer>& root)
571 : mStatus(NO_INIT), mComposer(Composer::getInstance()), mParent(root)
572{
573}
574
Mathias Agopian698c0872011-06-28 19:09:31 -0700575void SurfaceComposerClient::onFirstRef() {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700576 sp<ISurfaceComposer> sm(ComposerService::getComposerService());
Mathias Agopiand4784a32010-05-27 19:41:15 -0700577 if (sm != 0) {
Robert Carr1db73f62016-12-21 12:58:51 -0800578 auto rootProducer = mParent.promote();
579 sp<ISurfaceComposerClient> conn;
580 conn = (rootProducer != nullptr) ? sm->createScopedConnection(rootProducer) :
581 sm->createConnection();
Mathias Agopiand4784a32010-05-27 19:41:15 -0700582 if (conn != 0) {
583 mClient = conn;
Mathias Agopiand4784a32010-05-27 19:41:15 -0700584 mStatus = NO_ERROR;
585 }
586 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800587}
588
Mathias Agopian698c0872011-06-28 19:09:31 -0700589SurfaceComposerClient::~SurfaceComposerClient() {
Mathias Agopian631f3582010-05-25 17:51:34 -0700590 dispose();
591}
Mathias Agopiandd3423c2009-09-23 15:44:05 -0700592
Mathias Agopian698c0872011-06-28 19:09:31 -0700593status_t SurfaceComposerClient::initCheck() const {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800594 return mStatus;
595}
596
Mathias Agopian698c0872011-06-28 19:09:31 -0700597sp<IBinder> SurfaceComposerClient::connection() const {
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800598 return IInterface::asBinder(mClient);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800599}
600
Mathias Agopiand4784a32010-05-27 19:41:15 -0700601status_t SurfaceComposerClient::linkToComposerDeath(
602 const sp<IBinder::DeathRecipient>& recipient,
Mathias Agopian698c0872011-06-28 19:09:31 -0700603 void* cookie, uint32_t flags) {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700604 sp<ISurfaceComposer> sm(ComposerService::getComposerService());
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800605 return IInterface::asBinder(sm)->linkToDeath(recipient, cookie, flags);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800606}
607
Mathias Agopian698c0872011-06-28 19:09:31 -0700608void SurfaceComposerClient::dispose() {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800609 // this can be called more than once.
Mathias Agopian7e27f052010-05-28 14:22:23 -0700610 sp<ISurfaceComposerClient> client;
Mathias Agopiand4784a32010-05-27 19:41:15 -0700611 Mutex::Autolock _lm(mLock);
612 if (mClient != 0) {
Mathias Agopiand4784a32010-05-27 19:41:15 -0700613 client = mClient; // hold ref while lock is held
614 mClient.clear();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800615 }
Mathias Agopiand4784a32010-05-27 19:41:15 -0700616 mStatus = NO_INIT;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800617}
618
Mathias Agopian698c0872011-06-28 19:09:31 -0700619sp<SurfaceControl> SurfaceComposerClient::createSurface(
Mathias Agopian698c0872011-06-28 19:09:31 -0700620 const String8& name,
Mathias Agopian698c0872011-06-28 19:09:31 -0700621 uint32_t w,
622 uint32_t h,
623 PixelFormat format,
Robert Carr1f0a16a2016-10-24 16:27:39 -0700624 uint32_t flags,
Albert Chaulk479c60c2017-01-27 14:21:34 -0500625 SurfaceControl* parent,
626 uint32_t windowType,
627 uint32_t ownerUid)
Mathias Agopian698c0872011-06-28 19:09:31 -0700628{
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700629 sp<SurfaceControl> sur;
Mathias Agopian698c0872011-06-28 19:09:31 -0700630 if (mStatus == NO_ERROR) {
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700631 sp<IBinder> handle;
Robert Carr1f0a16a2016-10-24 16:27:39 -0700632 sp<IBinder> parentHandle;
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700633 sp<IGraphicBufferProducer> gbp;
Robert Carr1f0a16a2016-10-24 16:27:39 -0700634
635 if (parent != nullptr) {
636 parentHandle = parent->getHandle();
637 }
638 status_t err = mClient->createSurface(name, w, h, format, flags, parentHandle,
Albert Chaulk479c60c2017-01-27 14:21:34 -0500639 windowType, ownerUid, &handle, &gbp);
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700640 ALOGE_IF(err, "SurfaceComposerClient::createSurface error %s", strerror(-err));
641 if (err == NO_ERROR) {
642 sur = new SurfaceControl(this, handle, gbp);
Mathias Agopian698c0872011-06-28 19:09:31 -0700643 }
644 }
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700645 return sur;
Mathias Agopian698c0872011-06-28 19:09:31 -0700646}
647
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700648sp<IBinder> SurfaceComposerClient::createDisplay(const String8& displayName,
649 bool secure) {
650 return Composer::getInstance().createDisplay(displayName, secure);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700651}
652
Jesse Hall6c913be2013-08-08 12:15:49 -0700653void SurfaceComposerClient::destroyDisplay(const sp<IBinder>& display) {
654 Composer::getInstance().destroyDisplay(display);
655}
656
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700657sp<IBinder> SurfaceComposerClient::getBuiltInDisplay(int32_t id) {
658 return Composer::getInstance().getBuiltInDisplay(id);
659}
660
Mathias Agopianac9fa422013-02-11 16:40:36 -0800661status_t SurfaceComposerClient::destroySurface(const sp<IBinder>& sid) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700662 if (mStatus != NO_ERROR)
663 return mStatus;
664 status_t err = mClient->destroySurface(sid);
665 return err;
666}
667
Svetoslavd85084b2014-03-20 10:28:31 -0700668status_t SurfaceComposerClient::clearLayerFrameStats(const sp<IBinder>& token) const {
669 if (mStatus != NO_ERROR) {
670 return mStatus;
671 }
672 return mClient->clearLayerFrameStats(token);
673}
674
675status_t SurfaceComposerClient::getLayerFrameStats(const sp<IBinder>& token,
676 FrameStats* outStats) const {
677 if (mStatus != NO_ERROR) {
678 return mStatus;
679 }
680 return mClient->getLayerFrameStats(token, outStats);
681}
682
Robert Carr367c5682016-06-20 11:55:28 -0700683status_t SurfaceComposerClient::getTransformToDisplayInverse(const sp<IBinder>& token,
684 bool* outTransformToDisplayInverse) const {
685 if (mStatus != NO_ERROR) {
686 return mStatus;
687 }
688 return mClient->getTransformToDisplayInverse(token, outTransformToDisplayInverse);
689}
690
Mathias Agopian698c0872011-06-28 19:09:31 -0700691inline Composer& SurfaceComposerClient::getComposer() {
692 return mComposer;
693}
694
695// ----------------------------------------------------------------------------
696
697void SurfaceComposerClient::openGlobalTransaction() {
Jeff Brownf3f7db62012-08-31 02:18:38 -0700698 Composer::openGlobalTransaction();
Mathias Agopian698c0872011-06-28 19:09:31 -0700699}
700
Jamie Gennis28378392011-10-12 17:39:00 -0700701void SurfaceComposerClient::closeGlobalTransaction(bool synchronous) {
702 Composer::closeGlobalTransaction(synchronous);
Mathias Agopian698c0872011-06-28 19:09:31 -0700703}
704
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700705void SurfaceComposerClient::setAnimationTransaction() {
706 Composer::setAnimationTransaction();
707}
708
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -0700709status_t SurfaceComposerClient::enableVSyncInjections(bool enable) {
710 return Composer::enableVSyncInjections(enable);
711}
712
713status_t SurfaceComposerClient::injectVSync(nsecs_t when) {
714 return Composer::injectVSync(when);
715}
716
Mathias Agopian698c0872011-06-28 19:09:31 -0700717// ----------------------------------------------------------------------------
718
Mathias Agopianac9fa422013-02-11 16:40:36 -0800719status_t SurfaceComposerClient::setCrop(const sp<IBinder>& id, const Rect& crop) {
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700720 return getComposer().setCrop(this, id, crop);
721}
722
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000723status_t SurfaceComposerClient::setFinalCrop(const sp<IBinder>& id,
724 const Rect& crop) {
725 return getComposer().setFinalCrop(this, id, crop);
726}
727
Mathias Agopianac9fa422013-02-11 16:40:36 -0800728status_t SurfaceComposerClient::setPosition(const sp<IBinder>& id, float x, float y) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700729 return getComposer().setPosition(this, id, x, y);
730}
731
Mathias Agopianac9fa422013-02-11 16:40:36 -0800732status_t SurfaceComposerClient::setSize(const sp<IBinder>& id, uint32_t w, uint32_t h) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700733 return getComposer().setSize(this, id, w, h);
734}
735
Robert Carrae060832016-11-28 10:51:00 -0800736status_t SurfaceComposerClient::setLayer(const sp<IBinder>& id, int32_t z) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700737 return getComposer().setLayer(this, id, z);
738}
739
Mathias Agopianac9fa422013-02-11 16:40:36 -0800740status_t SurfaceComposerClient::hide(const sp<IBinder>& id) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700741 return getComposer().setFlags(this, id,
Mathias Agopian3165cc22012-08-08 19:42:09 -0700742 layer_state_t::eLayerHidden,
743 layer_state_t::eLayerHidden);
Mathias Agopian698c0872011-06-28 19:09:31 -0700744}
745
Mathias Agopianac9fa422013-02-11 16:40:36 -0800746status_t SurfaceComposerClient::show(const sp<IBinder>& id) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700747 return getComposer().setFlags(this, id,
748 0,
Mathias Agopian3165cc22012-08-08 19:42:09 -0700749 layer_state_t::eLayerHidden);
Mathias Agopian698c0872011-06-28 19:09:31 -0700750}
751
Mathias Agopianac9fa422013-02-11 16:40:36 -0800752status_t SurfaceComposerClient::setFlags(const sp<IBinder>& id, uint32_t flags,
Mathias Agopian698c0872011-06-28 19:09:31 -0700753 uint32_t mask) {
754 return getComposer().setFlags(this, id, flags, mask);
755}
756
Mathias Agopianac9fa422013-02-11 16:40:36 -0800757status_t SurfaceComposerClient::setTransparentRegionHint(const sp<IBinder>& id,
Mathias Agopian698c0872011-06-28 19:09:31 -0700758 const Region& transparentRegion) {
759 return getComposer().setTransparentRegionHint(this, id, transparentRegion);
760}
761
Mathias Agopianac9fa422013-02-11 16:40:36 -0800762status_t SurfaceComposerClient::setAlpha(const sp<IBinder>& id, float alpha) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700763 return getComposer().setAlpha(this, id, alpha);
764}
765
Mathias Agopianac9fa422013-02-11 16:40:36 -0800766status_t SurfaceComposerClient::setLayerStack(const sp<IBinder>& id, uint32_t layerStack) {
Mathias Agopian87855782012-07-24 21:41:09 -0700767 return getComposer().setLayerStack(this, id, layerStack);
768}
769
Mathias Agopianac9fa422013-02-11 16:40:36 -0800770status_t SurfaceComposerClient::setMatrix(const sp<IBinder>& id, float dsdx, float dtdx,
Mathias Agopian698c0872011-06-28 19:09:31 -0700771 float dsdy, float dtdy) {
772 return getComposer().setMatrix(this, id, dsdx, dtdx, dsdy, dtdy);
773}
774
Dan Stoza7dde5992015-05-22 09:51:44 -0700775status_t SurfaceComposerClient::deferTransactionUntil(const sp<IBinder>& id,
776 const sp<IBinder>& handle, uint64_t frameNumber) {
777 return getComposer().deferTransactionUntil(this, id, handle, frameNumber);
778}
779
Robert Carr1db73f62016-12-21 12:58:51 -0800780status_t SurfaceComposerClient::reparentChildren(const sp<IBinder>& id,
781 const sp<IBinder>& newParentHandle) {
782 return getComposer().reparentChildren(this, id, newParentHandle);
783}
784
Robert Carrc3574f72016-03-24 12:19:32 -0700785status_t SurfaceComposerClient::setOverrideScalingMode(
786 const sp<IBinder>& id, int32_t overrideScalingMode) {
787 return getComposer().setOverrideScalingMode(
788 this, id, overrideScalingMode);
789}
790
Robert Carr99e27f02016-06-16 15:18:02 -0700791status_t SurfaceComposerClient::setGeometryAppliesWithResize(
Robert Carr82364e32016-05-15 11:27:47 -0700792 const sp<IBinder>& id) {
Robert Carr99e27f02016-06-16 15:18:02 -0700793 return getComposer().setGeometryAppliesWithResize(this, id);
Robert Carr82364e32016-05-15 11:27:47 -0700794}
795
Mathias Agopian698c0872011-06-28 19:09:31 -0700796// ----------------------------------------------------------------------------
797
Pablo Ceballos1aad24c2016-08-04 10:24:22 -0700798status_t SurfaceComposerClient::setDisplaySurface(const sp<IBinder>& token,
799 sp<IGraphicBufferProducer> bufferProducer) {
800 return Composer::getInstance().setDisplaySurface(token, bufferProducer);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700801}
802
803void SurfaceComposerClient::setDisplayLayerStack(const sp<IBinder>& token,
804 uint32_t layerStack) {
805 Composer::getInstance().setDisplayLayerStack(token, layerStack);
806}
807
Mathias Agopian00e8c7a2012-09-04 19:30:46 -0700808void SurfaceComposerClient::setDisplayProjection(const sp<IBinder>& token,
809 uint32_t orientation,
810 const Rect& layerStackRect,
811 const Rect& displayRect) {
812 Composer::getInstance().setDisplayProjection(token, orientation,
813 layerStackRect, displayRect);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700814}
815
Michael Wright1f6078a2014-06-26 16:01:02 -0700816void SurfaceComposerClient::setDisplaySize(const sp<IBinder>& token,
817 uint32_t width, uint32_t height) {
818 Composer::getInstance().setDisplaySize(token, width, height);
819}
820
Mathias Agopiane57f2922012-08-09 16:29:12 -0700821// ----------------------------------------------------------------------------
822
Dan Stoza7f7da322014-05-02 15:26:25 -0700823status_t SurfaceComposerClient::getDisplayConfigs(
824 const sp<IBinder>& display, Vector<DisplayInfo>* configs)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800825{
Dan Stoza7f7da322014-05-02 15:26:25 -0700826 return ComposerService::getComposerService()->getDisplayConfigs(display, configs);
827}
828
829status_t SurfaceComposerClient::getDisplayInfo(const sp<IBinder>& display,
830 DisplayInfo* info) {
831 Vector<DisplayInfo> configs;
832 status_t result = getDisplayConfigs(display, &configs);
833 if (result != NO_ERROR) {
834 return result;
835 }
836
837 int activeId = getActiveConfig(display);
838 if (activeId < 0) {
839 ALOGE("No active configuration found");
840 return NAME_NOT_FOUND;
841 }
842
Dan Stozad723bd72014-11-18 10:24:03 -0800843 *info = configs[static_cast<size_t>(activeId)];
Dan Stoza7f7da322014-05-02 15:26:25 -0700844 return NO_ERROR;
845}
846
847int SurfaceComposerClient::getActiveConfig(const sp<IBinder>& display) {
848 return ComposerService::getComposerService()->getActiveConfig(display);
849}
850
851status_t SurfaceComposerClient::setActiveConfig(const sp<IBinder>& display, int id) {
852 return ComposerService::getComposerService()->setActiveConfig(display, id);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800853}
854
Michael Wright28f24d02016-07-12 13:30:53 -0700855status_t SurfaceComposerClient::getDisplayColorModes(const sp<IBinder>& display,
856 Vector<android_color_mode_t>* outColorModes) {
857 return ComposerService::getComposerService()->getDisplayColorModes(display, outColorModes);
858}
859
860android_color_mode_t SurfaceComposerClient::getActiveColorMode(const sp<IBinder>& display) {
861 return ComposerService::getComposerService()->getActiveColorMode(display);
862}
863
864status_t SurfaceComposerClient::setActiveColorMode(const sp<IBinder>& display,
865 android_color_mode_t colorMode) {
866 return ComposerService::getComposerService()->setActiveColorMode(display, colorMode);
867}
868
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700869void SurfaceComposerClient::setDisplayPowerMode(const sp<IBinder>& token,
870 int mode) {
871 ComposerService::getComposerService()->setPowerMode(token, mode);
Jeff Brown2a09bb32012-10-08 19:13:57 -0700872}
873
Svetoslavd85084b2014-03-20 10:28:31 -0700874status_t SurfaceComposerClient::clearAnimationFrameStats() {
875 return ComposerService::getComposerService()->clearAnimationFrameStats();
876}
877
878status_t SurfaceComposerClient::getAnimationFrameStats(FrameStats* outStats) {
879 return ComposerService::getComposerService()->getAnimationFrameStats(outStats);
880}
881
Dan Stozac4f471e2016-03-24 09:31:08 -0700882status_t SurfaceComposerClient::getHdrCapabilities(const sp<IBinder>& display,
883 HdrCapabilities* outCapabilities) {
884 return ComposerService::getComposerService()->getHdrCapabilities(display,
885 outCapabilities);
886}
887
Mathias Agopian698c0872011-06-28 19:09:31 -0700888// ----------------------------------------------------------------------------
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800889
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800890status_t ScreenshotClient::capture(
891 const sp<IBinder>& display,
892 const sp<IGraphicBufferProducer>& producer,
Dan Stozac1879002014-05-22 15:59:05 -0700893 Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
Robert Carrae060832016-11-28 10:51:00 -0800894 int32_t minLayerZ, int32_t maxLayerZ, bool useIdentityTransform) {
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800895 sp<ISurfaceComposer> s(ComposerService::getComposerService());
896 if (s == NULL) return NO_INIT;
Dan Stozac1879002014-05-22 15:59:05 -0700897 return s->captureScreen(display, producer, sourceCrop,
Dan Stozac7014012014-02-14 15:03:43 -0800898 reqWidth, reqHeight, minLayerZ, maxLayerZ, useIdentityTransform);
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800899}
900
Robert Carr673134e2017-01-09 19:48:38 -0800901status_t ScreenshotClient::captureToBuffer(const sp<IBinder>& display,
902 Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
Robert Carrae060832016-11-28 10:51:00 -0800903 int32_t minLayerZ, int32_t maxLayerZ, bool useIdentityTransform,
Robert Carr673134e2017-01-09 19:48:38 -0800904 uint32_t rotation,
905 sp<GraphicBuffer>* outBuffer) {
906 sp<ISurfaceComposer> s(ComposerService::getComposerService());
907 if (s == NULL) return NO_INIT;
908
909 sp<IGraphicBufferConsumer> gbpConsumer;
910 sp<IGraphicBufferProducer> producer;
911 BufferQueue::createBufferQueue(&producer, &gbpConsumer);
912 sp<BufferItemConsumer> consumer(new BufferItemConsumer(gbpConsumer,
913 GRALLOC_USAGE_HW_TEXTURE | GRALLOC_USAGE_SW_READ_NEVER | GRALLOC_USAGE_SW_WRITE_NEVER,
914 1, true));
915
916 status_t ret = s->captureScreen(display, producer, sourceCrop, reqWidth, reqHeight,
917 minLayerZ, maxLayerZ, useIdentityTransform,
918 static_cast<ISurfaceComposer::Rotation>(rotation));
919 if (ret != NO_ERROR) {
920 return ret;
921 }
922 BufferItem b;
923 consumer->acquireBuffer(&b, 0, true);
924 *outBuffer = b.mGraphicBuffer;
925 return ret;
926}
927
Mathias Agopian74c40c02010-09-29 13:02:36 -0700928ScreenshotClient::ScreenshotClient()
Mathias Agopianabe815d2013-03-19 22:22:21 -0700929 : mHaveBuffer(false) {
930 memset(&mBuffer, 0, sizeof(mBuffer));
Mathias Agopian74c40c02010-09-29 13:02:36 -0700931}
932
Mathias Agopian8000d062013-03-26 18:15:35 -0700933ScreenshotClient::~ScreenshotClient() {
934 ScreenshotClient::release();
935}
936
Mathias Agopianabe815d2013-03-19 22:22:21 -0700937sp<CpuConsumer> ScreenshotClient::getCpuConsumer() const {
938 if (mCpuConsumer == NULL) {
Dan Stoza6d5a7bb2014-03-13 11:39:09 -0700939 sp<IGraphicBufferConsumer> consumer;
940 BufferQueue::createBufferQueue(&mProducer, &consumer);
941 mCpuConsumer = new CpuConsumer(consumer, 1);
Mathias Agopianabe815d2013-03-19 22:22:21 -0700942 mCpuConsumer->setName(String8("ScreenshotClient"));
943 }
944 return mCpuConsumer;
Mathias Agopianbf2c6a62010-12-10 16:22:31 -0800945}
946
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700947status_t ScreenshotClient::update(const sp<IBinder>& display,
Dan Stozac1879002014-05-22 15:59:05 -0700948 Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
Robert Carrae060832016-11-28 10:51:00 -0800949 int32_t minLayerZ, int32_t maxLayerZ,
Riley Andrewsd15ef272014-09-04 16:19:44 -0700950 bool useIdentityTransform, uint32_t rotation) {
Mathias Agopianbf2c6a62010-12-10 16:22:31 -0800951 sp<ISurfaceComposer> s(ComposerService::getComposerService());
952 if (s == NULL) return NO_INIT;
Mathias Agopianabe815d2013-03-19 22:22:21 -0700953 sp<CpuConsumer> cpuConsumer = getCpuConsumer();
954
955 if (mHaveBuffer) {
956 mCpuConsumer->unlockBuffer(mBuffer);
957 memset(&mBuffer, 0, sizeof(mBuffer));
958 mHaveBuffer = false;
959 }
960
Dan Stozac1879002014-05-22 15:59:05 -0700961 status_t err = s->captureScreen(display, mProducer, sourceCrop,
Riley Andrewsd15ef272014-09-04 16:19:44 -0700962 reqWidth, reqHeight, minLayerZ, maxLayerZ, useIdentityTransform,
963 static_cast<ISurfaceComposer::Rotation>(rotation));
Mathias Agopianabe815d2013-03-19 22:22:21 -0700964
965 if (err == NO_ERROR) {
966 err = mCpuConsumer->lockNextBuffer(&mBuffer);
967 if (err == NO_ERROR) {
968 mHaveBuffer = true;
969 }
970 }
971 return err;
972}
973
Riley Andrewsd15ef272014-09-04 16:19:44 -0700974status_t ScreenshotClient::update(const sp<IBinder>& display,
975 Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
Robert Carrae060832016-11-28 10:51:00 -0800976 int32_t minLayerZ, int32_t maxLayerZ,
Riley Andrewsd15ef272014-09-04 16:19:44 -0700977 bool useIdentityTransform) {
978
979 return ScreenshotClient::update(display, sourceCrop, reqWidth, reqHeight,
980 minLayerZ, maxLayerZ, useIdentityTransform, ISurfaceComposer::eRotateNone);
981}
982
Dan Stozac1879002014-05-22 15:59:05 -0700983status_t ScreenshotClient::update(const sp<IBinder>& display, Rect sourceCrop,
Dan Stozac7014012014-02-14 15:03:43 -0800984 bool useIdentityTransform) {
Robert Carrae060832016-11-28 10:51:00 -0800985 return ScreenshotClient::update(display, sourceCrop, 0, 0,
986 INT32_MIN, INT32_MAX,
Riley Andrewsd15ef272014-09-04 16:19:44 -0700987 useIdentityTransform, ISurfaceComposer::eRotateNone);
Mathias Agopianabe815d2013-03-19 22:22:21 -0700988}
989
Dan Stozac1879002014-05-22 15:59:05 -0700990status_t ScreenshotClient::update(const sp<IBinder>& display, Rect sourceCrop,
Dan Stozac7014012014-02-14 15:03:43 -0800991 uint32_t reqWidth, uint32_t reqHeight, bool useIdentityTransform) {
Dan Stozac1879002014-05-22 15:59:05 -0700992 return ScreenshotClient::update(display, sourceCrop, reqWidth, reqHeight,
Robert Carrae060832016-11-28 10:51:00 -0800993 INT32_MIN, INT32_MAX,
994 useIdentityTransform, ISurfaceComposer::eRotateNone);
Mathias Agopian74c40c02010-09-29 13:02:36 -0700995}
996
997void ScreenshotClient::release() {
Mathias Agopianabe815d2013-03-19 22:22:21 -0700998 if (mHaveBuffer) {
999 mCpuConsumer->unlockBuffer(mBuffer);
1000 memset(&mBuffer, 0, sizeof(mBuffer));
1001 mHaveBuffer = false;
1002 }
1003 mCpuConsumer.clear();
Mathias Agopian74c40c02010-09-29 13:02:36 -07001004}
1005
1006void const* ScreenshotClient::getPixels() const {
Mathias Agopianabe815d2013-03-19 22:22:21 -07001007 return mBuffer.data;
Mathias Agopian74c40c02010-09-29 13:02:36 -07001008}
1009
1010uint32_t ScreenshotClient::getWidth() const {
Mathias Agopianabe815d2013-03-19 22:22:21 -07001011 return mBuffer.width;
Mathias Agopian74c40c02010-09-29 13:02:36 -07001012}
1013
1014uint32_t ScreenshotClient::getHeight() const {
Mathias Agopianabe815d2013-03-19 22:22:21 -07001015 return mBuffer.height;
Mathias Agopian74c40c02010-09-29 13:02:36 -07001016}
1017
1018PixelFormat ScreenshotClient::getFormat() const {
Mathias Agopianabe815d2013-03-19 22:22:21 -07001019 return mBuffer.format;
Mathias Agopian74c40c02010-09-29 13:02:36 -07001020}
1021
1022uint32_t ScreenshotClient::getStride() const {
Mathias Agopianabe815d2013-03-19 22:22:21 -07001023 return mBuffer.stride;
Mathias Agopian74c40c02010-09-29 13:02:36 -07001024}
1025
1026size_t ScreenshotClient::getSize() const {
Mathias Agopianabe815d2013-03-19 22:22:21 -07001027 return mBuffer.stride * mBuffer.height * bytesPerPixel(mBuffer.format);
Mathias Agopian74c40c02010-09-29 13:02:36 -07001028}
1029
1030// ----------------------------------------------------------------------------
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001031}; // namespace android