blob: 2632781982488e3ededb8c047ff566e95aba50c1 [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>
Robert Carr0d480722017-01-10 16:42:54 -080041#include <gui/Surface.h>
Mathias Agopian90ac7992012-02-25 18:48:35 -080042#include <gui/SurfaceComposerClient.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080043
Mathias Agopian41f673c2011-11-17 17:48:35 -080044#include <private/gui/ComposerService.h>
Mathias Agopian90ac7992012-02-25 18:48:35 -080045#include <private/gui/LayerState.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080046
47namespace android {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080048// ---------------------------------------------------------------------------
49
Mathias Agopian7e27f052010-05-28 14:22:23 -070050ANDROID_SINGLETON_STATIC_INSTANCE(ComposerService);
51
Mathias Agopianb7e930d2010-06-01 15:12:58 -070052ComposerService::ComposerService()
53: Singleton<ComposerService>() {
Andy McFadden6652b3e2012-09-06 18:45:56 -070054 Mutex::Autolock _l(mLock);
55 connectLocked();
56}
57
58void ComposerService::connectLocked() {
Mathias Agopianb7e930d2010-06-01 15:12:58 -070059 const String16 name("SurfaceFlinger");
60 while (getService(name, &mComposerService) != NO_ERROR) {
61 usleep(250000);
62 }
Andy McFadden6652b3e2012-09-06 18:45:56 -070063 assert(mComposerService != NULL);
64
65 // Create the death listener.
66 class DeathObserver : public IBinder::DeathRecipient {
67 ComposerService& mComposerService;
68 virtual void binderDied(const wp<IBinder>& who) {
69 ALOGW("ComposerService remote (surfaceflinger) died [%p]",
70 who.unsafe_get());
71 mComposerService.composerServiceDied();
72 }
73 public:
Chih-Hung Hsiehe2347b72016-04-25 15:41:05 -070074 explicit DeathObserver(ComposerService& mgr) : mComposerService(mgr) { }
Andy McFadden6652b3e2012-09-06 18:45:56 -070075 };
76
77 mDeathObserver = new DeathObserver(*const_cast<ComposerService*>(this));
Marco Nelissen2ea926b2014-11-14 08:01:01 -080078 IInterface::asBinder(mComposerService)->linkToDeath(mDeathObserver);
Mathias Agopianb7e930d2010-06-01 15:12:58 -070079}
80
Andy McFadden6652b3e2012-09-06 18:45:56 -070081/*static*/ sp<ISurfaceComposer> ComposerService::getComposerService() {
82 ComposerService& instance = ComposerService::getInstance();
83 Mutex::Autolock _l(instance.mLock);
84 if (instance.mComposerService == NULL) {
85 ComposerService::getInstance().connectLocked();
86 assert(instance.mComposerService != NULL);
87 ALOGD("ComposerService reconnected");
88 }
89 return instance.mComposerService;
90}
91
92void ComposerService::composerServiceDied()
93{
94 Mutex::Autolock _l(mLock);
95 mComposerService = NULL;
96 mDeathObserver = NULL;
Mathias Agopianb7e930d2010-06-01 15:12:58 -070097}
98
Mathias Agopian7e27f052010-05-28 14:22:23 -070099// ---------------------------------------------------------------------------
100
Mathias Agopian698c0872011-06-28 19:09:31 -0700101static inline
Mathias Agopiane57f2922012-08-09 16:29:12 -0700102int compare_type(const ComposerState& lhs, const ComposerState& rhs) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700103 if (lhs.client < rhs.client) return -1;
104 if (lhs.client > rhs.client) return 1;
105 if (lhs.state.surface < rhs.state.surface) return -1;
106 if (lhs.state.surface > rhs.state.surface) return 1;
107 return 0;
108}
109
Mathias Agopiane57f2922012-08-09 16:29:12 -0700110static inline
111int compare_type(const DisplayState& lhs, const DisplayState& rhs) {
112 return compare_type(lhs.token, rhs.token);
113}
114
Mathias Agopian7e27f052010-05-28 14:22:23 -0700115class Composer : public Singleton<Composer>
116{
Mathias Agopiand4784a32010-05-27 19:41:15 -0700117 friend class Singleton<Composer>;
118
Mathias Agopian698c0872011-06-28 19:09:31 -0700119 mutable Mutex mLock;
Mathias Agopiane57f2922012-08-09 16:29:12 -0700120 SortedVector<ComposerState> mComposerStates;
121 SortedVector<DisplayState > mDisplayStates;
Jamie Gennis28378392011-10-12 17:39:00 -0700122 uint32_t mForceSynchronous;
Jeff Brownf3f7db62012-08-31 02:18:38 -0700123 uint32_t mTransactionNestCount;
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700124 bool mAnimation;
Mathias Agopian698c0872011-06-28 19:09:31 -0700125
Jamie Gennisb8d69a52011-10-10 15:48:06 -0700126 Composer() : Singleton<Composer>(),
Jeff Brownf3f7db62012-08-31 02:18:38 -0700127 mForceSynchronous(0), mTransactionNestCount(0),
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700128 mAnimation(false)
Jamie Gennis28378392011-10-12 17:39:00 -0700129 { }
Mathias Agopian698c0872011-06-28 19:09:31 -0700130
Jeff Brownf3f7db62012-08-31 02:18:38 -0700131 void openGlobalTransactionImpl();
Jamie Gennis28378392011-10-12 17:39:00 -0700132 void closeGlobalTransactionImpl(bool synchronous);
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700133 void setAnimationTransactionImpl();
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -0700134 status_t enableVSyncInjectionsImpl(bool enable);
135 status_t injectVSyncImpl(nsecs_t when);
Mathias Agopian698c0872011-06-28 19:09:31 -0700136
137 layer_state_t* getLayerStateLocked(
Mathias Agopianac9fa422013-02-11 16:40:36 -0800138 const sp<SurfaceComposerClient>& client, const sp<IBinder>& id);
Mathias Agopian698c0872011-06-28 19:09:31 -0700139
Mathias Agopiane57f2922012-08-09 16:29:12 -0700140 DisplayState& getDisplayStateLocked(const sp<IBinder>& token);
141
Mathias Agopiand4784a32010-05-27 19:41:15 -0700142public:
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700143 sp<IBinder> createDisplay(const String8& displayName, bool secure);
Jesse Hall6c913be2013-08-08 12:15:49 -0700144 void destroyDisplay(const sp<IBinder>& display);
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700145 sp<IBinder> getBuiltInDisplay(int32_t id);
Mathias Agopian698c0872011-06-28 19:09:31 -0700146
Mathias Agopianac9fa422013-02-11 16:40:36 -0800147 status_t setPosition(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
Mathias Agopian41b6aab2011-08-30 18:51:54 -0700148 float x, float y);
Mathias Agopianac9fa422013-02-11 16:40:36 -0800149 status_t setSize(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
Mathias Agopian698c0872011-06-28 19:09:31 -0700150 uint32_t w, uint32_t h);
Mathias Agopianac9fa422013-02-11 16:40:36 -0800151 status_t setLayer(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
Robert Carrae060832016-11-28 10:51:00 -0800152 int32_t z);
Mathias Agopianac9fa422013-02-11 16:40:36 -0800153 status_t setFlags(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
Mathias Agopian698c0872011-06-28 19:09:31 -0700154 uint32_t flags, uint32_t mask);
155 status_t setTransparentRegionHint(
Mathias Agopianac9fa422013-02-11 16:40:36 -0800156 const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
Mathias Agopian698c0872011-06-28 19:09:31 -0700157 const Region& transparentRegion);
Mathias Agopianac9fa422013-02-11 16:40:36 -0800158 status_t setAlpha(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
Mathias Agopian698c0872011-06-28 19:09:31 -0700159 float alpha);
Mathias Agopianac9fa422013-02-11 16:40:36 -0800160 status_t setMatrix(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
Mathias Agopian698c0872011-06-28 19:09:31 -0700161 float dsdx, float dtdx, float dsdy, float dtdy);
Jamie Gennisb8d69a52011-10-10 15:48:06 -0700162 status_t setOrientation(int orientation);
Mathias Agopianac9fa422013-02-11 16:40:36 -0800163 status_t setCrop(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700164 const Rect& crop);
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000165 status_t setFinalCrop(const sp<SurfaceComposerClient>& client,
166 const sp<IBinder>& id, const Rect& crop);
Mathias Agopian87855782012-07-24 21:41:09 -0700167 status_t setLayerStack(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-11 16:40:36 -0800168 const sp<IBinder>& id, uint32_t layerStack);
Dan Stoza7dde5992015-05-22 09:51:44 -0700169 status_t deferTransactionUntil(const sp<SurfaceComposerClient>& client,
170 const sp<IBinder>& id, const sp<IBinder>& handle,
171 uint64_t frameNumber);
Robert Carr0d480722017-01-10 16:42:54 -0800172 status_t deferTransactionUntil(const sp<SurfaceComposerClient>& client,
173 const sp<IBinder>& id, const sp<Surface>& barrierSurface,
174 uint64_t frameNumber);
Robert Carr1db73f62016-12-21 12:58:51 -0800175 status_t reparentChildren(const sp<SurfaceComposerClient>& client,
176 const sp<IBinder>& id,
177 const sp<IBinder>& newParentHandle);
Robert Carr9524cb32017-02-13 11:32:32 -0800178 status_t detachChildren(const sp<SurfaceComposerClient>& client,
179 const sp<IBinder>& id);
Robert Carrc3574f72016-03-24 12:19:32 -0700180 status_t setOverrideScalingMode(const sp<SurfaceComposerClient>& client,
181 const sp<IBinder>& id, int32_t overrideScalingMode);
Robert Carr99e27f02016-06-16 15:18:02 -0700182 status_t setGeometryAppliesWithResize(const sp<SurfaceComposerClient>& client,
Robert Carr82364e32016-05-15 11:27:47 -0700183 const sp<IBinder>& id);
Mathias Agopian698c0872011-06-28 19:09:31 -0700184
Pablo Ceballos1aad24c2016-08-04 10:24:22 -0700185 status_t setDisplaySurface(const sp<IBinder>& token,
186 sp<IGraphicBufferProducer> bufferProducer);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700187 void setDisplayLayerStack(const sp<IBinder>& token, uint32_t layerStack);
Mathias Agopian00e8c7a2012-09-04 19:30:46 -0700188 void setDisplayProjection(const sp<IBinder>& token,
189 uint32_t orientation,
190 const Rect& layerStackRect,
191 const Rect& displayRect);
Michael Wright1f6078a2014-06-26 16:01:02 -0700192 void setDisplaySize(const sp<IBinder>& token, uint32_t width, uint32_t height);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700193
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700194 static void setAnimationTransaction() {
195 Composer::getInstance().setAnimationTransactionImpl();
196 }
197
Jeff Brownf3f7db62012-08-31 02:18:38 -0700198 static void openGlobalTransaction() {
199 Composer::getInstance().openGlobalTransactionImpl();
200 }
201
Jamie Gennis28378392011-10-12 17:39:00 -0700202 static void closeGlobalTransaction(bool synchronous) {
203 Composer::getInstance().closeGlobalTransactionImpl(synchronous);
Mathias Agopiand4784a32010-05-27 19:41:15 -0700204 }
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -0700205
206 static status_t enableVSyncInjections(bool enable) {
207 return Composer::getInstance().enableVSyncInjectionsImpl(enable);
208 }
209
210 static status_t injectVSync(nsecs_t when) {
211 return Composer::getInstance().injectVSyncImpl(when);
212 }
Mathias Agopiand4784a32010-05-27 19:41:15 -0700213};
214
215ANDROID_SINGLETON_STATIC_INSTANCE(Composer);
216
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800217// ---------------------------------------------------------------------------
218
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700219sp<IBinder> Composer::createDisplay(const String8& displayName, bool secure) {
220 return ComposerService::getComposerService()->createDisplay(displayName,
221 secure);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700222}
223
Jesse Hall6c913be2013-08-08 12:15:49 -0700224void Composer::destroyDisplay(const sp<IBinder>& display) {
225 return ComposerService::getComposerService()->destroyDisplay(display);
226}
227
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700228sp<IBinder> Composer::getBuiltInDisplay(int32_t id) {
229 return ComposerService::getComposerService()->getBuiltInDisplay(id);
230}
231
Jeff Brownf3f7db62012-08-31 02:18:38 -0700232void Composer::openGlobalTransactionImpl() {
233 { // scope for the lock
234 Mutex::Autolock _l(mLock);
235 mTransactionNestCount += 1;
236 }
237}
238
Jamie Gennis28378392011-10-12 17:39:00 -0700239void Composer::closeGlobalTransactionImpl(bool synchronous) {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700240 sp<ISurfaceComposer> sm(ComposerService::getComposerService());
Mathias Agopian698c0872011-06-28 19:09:31 -0700241
242 Vector<ComposerState> transaction;
Mathias Agopian8b33f032012-07-24 20:43:54 -0700243 Vector<DisplayState> displayTransaction;
Jamie Gennis28378392011-10-12 17:39:00 -0700244 uint32_t flags = 0;
Mathias Agopian698c0872011-06-28 19:09:31 -0700245
246 { // scope for the lock
247 Mutex::Autolock _l(mLock);
Jeff Brownf3f7db62012-08-31 02:18:38 -0700248 mForceSynchronous |= synchronous;
249 if (!mTransactionNestCount) {
250 ALOGW("At least one call to closeGlobalTransaction() was not matched by a prior "
251 "call to openGlobalTransaction().");
252 } else if (--mTransactionNestCount) {
253 return;
254 }
255
Mathias Agopiane57f2922012-08-09 16:29:12 -0700256 transaction = mComposerStates;
257 mComposerStates.clear();
Jamie Gennisb8d69a52011-10-10 15:48:06 -0700258
Mathias Agopiane57f2922012-08-09 16:29:12 -0700259 displayTransaction = mDisplayStates;
260 mDisplayStates.clear();
Jamie Gennis28378392011-10-12 17:39:00 -0700261
Jeff Brownf3f7db62012-08-31 02:18:38 -0700262 if (mForceSynchronous) {
Jamie Gennis28378392011-10-12 17:39:00 -0700263 flags |= ISurfaceComposer::eSynchronous;
264 }
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700265 if (mAnimation) {
266 flags |= ISurfaceComposer::eAnimation;
267 }
268
Jamie Gennis28378392011-10-12 17:39:00 -0700269 mForceSynchronous = false;
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700270 mAnimation = false;
Mathias Agopian698c0872011-06-28 19:09:31 -0700271 }
272
Mathias Agopian8b33f032012-07-24 20:43:54 -0700273 sm->setTransactionState(transaction, displayTransaction, flags);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800274}
275
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -0700276status_t Composer::enableVSyncInjectionsImpl(bool enable) {
277 sp<ISurfaceComposer> sm(ComposerService::getComposerService());
278 return sm->enableVSyncInjections(enable);
279}
280
281status_t Composer::injectVSyncImpl(nsecs_t when) {
282 sp<ISurfaceComposer> sm(ComposerService::getComposerService());
283 return sm->injectVSync(when);
284}
285
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700286void Composer::setAnimationTransactionImpl() {
287 Mutex::Autolock _l(mLock);
288 mAnimation = true;
289}
290
Mathias Agopian698c0872011-06-28 19:09:31 -0700291layer_state_t* Composer::getLayerStateLocked(
Mathias Agopianac9fa422013-02-11 16:40:36 -0800292 const sp<SurfaceComposerClient>& client, const sp<IBinder>& id) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700293
294 ComposerState s;
295 s.client = client->mClient;
296 s.state.surface = id;
297
Mathias Agopiane57f2922012-08-09 16:29:12 -0700298 ssize_t index = mComposerStates.indexOf(s);
Mathias Agopian698c0872011-06-28 19:09:31 -0700299 if (index < 0) {
300 // we don't have it, add an initialized layer_state to our list
Mathias Agopiane57f2922012-08-09 16:29:12 -0700301 index = mComposerStates.add(s);
Mathias Agopian698c0872011-06-28 19:09:31 -0700302 }
303
Mathias Agopiane57f2922012-08-09 16:29:12 -0700304 ComposerState* const out = mComposerStates.editArray();
Mathias Agopian698c0872011-06-28 19:09:31 -0700305 return &(out[index].state);
306}
307
308status_t Composer::setPosition(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-11 16:40:36 -0800309 const sp<IBinder>& id, float x, float y) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700310 Mutex::Autolock _l(mLock);
311 layer_state_t* s = getLayerStateLocked(client, id);
312 if (!s)
313 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700314 s->what |= layer_state_t::ePositionChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700315 s->x = x;
316 s->y = y;
317 return NO_ERROR;
318}
319
320status_t Composer::setSize(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-11 16:40:36 -0800321 const sp<IBinder>& id, uint32_t w, uint32_t h) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700322 Mutex::Autolock _l(mLock);
323 layer_state_t* s = getLayerStateLocked(client, id);
324 if (!s)
325 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700326 s->what |= layer_state_t::eSizeChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700327 s->w = w;
328 s->h = h;
Jamie Gennis28378392011-10-12 17:39:00 -0700329
Jorim Jaggi092123c2016-04-13 01:40:35 +0000330 // Resizing a surface makes the transaction synchronous.
331 mForceSynchronous = true;
332
Mathias Agopian698c0872011-06-28 19:09:31 -0700333 return NO_ERROR;
334}
335
336status_t Composer::setLayer(const sp<SurfaceComposerClient>& client,
Robert Carrae060832016-11-28 10:51:00 -0800337 const sp<IBinder>& id, int32_t z) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700338 Mutex::Autolock _l(mLock);
339 layer_state_t* s = getLayerStateLocked(client, id);
340 if (!s)
341 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700342 s->what |= layer_state_t::eLayerChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700343 s->z = z;
344 return NO_ERROR;
345}
346
347status_t Composer::setFlags(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-11 16:40:36 -0800348 const sp<IBinder>& id, uint32_t flags,
Mathias Agopian698c0872011-06-28 19:09:31 -0700349 uint32_t mask) {
350 Mutex::Autolock _l(mLock);
351 layer_state_t* s = getLayerStateLocked(client, id);
352 if (!s)
353 return BAD_INDEX;
Pablo Ceballos53390e12015-08-04 11:25:59 -0700354 if ((mask & layer_state_t::eLayerOpaque) ||
355 (mask & layer_state_t::eLayerHidden) ||
356 (mask & layer_state_t::eLayerSecure)) {
Dan Stoza23116082015-06-18 14:58:39 -0700357 s->what |= layer_state_t::eFlagsChanged;
Andy McFadden4125a4f2014-01-29 17:17:11 -0800358 }
Mathias Agopian698c0872011-06-28 19:09:31 -0700359 s->flags &= ~mask;
360 s->flags |= (flags & mask);
361 s->mask |= mask;
362 return NO_ERROR;
363}
364
365status_t Composer::setTransparentRegionHint(
Mathias Agopianac9fa422013-02-11 16:40:36 -0800366 const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
Mathias Agopian698c0872011-06-28 19:09:31 -0700367 const Region& transparentRegion) {
368 Mutex::Autolock _l(mLock);
369 layer_state_t* s = getLayerStateLocked(client, id);
370 if (!s)
371 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700372 s->what |= layer_state_t::eTransparentRegionChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700373 s->transparentRegion = transparentRegion;
374 return NO_ERROR;
375}
376
377status_t Composer::setAlpha(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-11 16:40:36 -0800378 const sp<IBinder>& id, float alpha) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700379 Mutex::Autolock _l(mLock);
380 layer_state_t* s = getLayerStateLocked(client, id);
381 if (!s)
382 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700383 s->what |= layer_state_t::eAlphaChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700384 s->alpha = alpha;
385 return NO_ERROR;
386}
387
Mathias Agopian87855782012-07-24 21:41:09 -0700388status_t Composer::setLayerStack(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-11 16:40:36 -0800389 const sp<IBinder>& id, uint32_t layerStack) {
Mathias Agopian87855782012-07-24 21:41:09 -0700390 Mutex::Autolock _l(mLock);
391 layer_state_t* s = getLayerStateLocked(client, id);
392 if (!s)
393 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700394 s->what |= layer_state_t::eLayerStackChanged;
Mathias Agopian87855782012-07-24 21:41:09 -0700395 s->layerStack = layerStack;
396 return NO_ERROR;
397}
398
Mathias Agopian698c0872011-06-28 19:09:31 -0700399status_t Composer::setMatrix(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-11 16:40:36 -0800400 const sp<IBinder>& id, float dsdx, float dtdx,
Mathias Agopian698c0872011-06-28 19:09:31 -0700401 float dsdy, float dtdy) {
402 Mutex::Autolock _l(mLock);
403 layer_state_t* s = getLayerStateLocked(client, id);
404 if (!s)
405 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700406 s->what |= layer_state_t::eMatrixChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700407 layer_state_t::matrix22_t matrix;
408 matrix.dsdx = dsdx;
409 matrix.dtdx = dtdx;
410 matrix.dsdy = dsdy;
411 matrix.dtdy = dtdy;
412 s->matrix = matrix;
413 return NO_ERROR;
414}
415
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700416status_t Composer::setCrop(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-11 16:40:36 -0800417 const sp<IBinder>& id, const Rect& crop) {
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700418 Mutex::Autolock _l(mLock);
419 layer_state_t* s = getLayerStateLocked(client, id);
420 if (!s)
421 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700422 s->what |= layer_state_t::eCropChanged;
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700423 s->crop = crop;
424 return NO_ERROR;
425}
426
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000427status_t Composer::setFinalCrop(const sp<SurfaceComposerClient>& client,
428 const sp<IBinder>& id, const Rect& crop) {
429 Mutex::Autolock _l(mLock);
430 layer_state_t* s = getLayerStateLocked(client, id);
431 if (!s) {
432 return BAD_INDEX;
433 }
434 s->what |= layer_state_t::eFinalCropChanged;
435 s->finalCrop = crop;
436 return NO_ERROR;
437}
438
Dan Stoza7dde5992015-05-22 09:51:44 -0700439status_t Composer::deferTransactionUntil(
440 const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
441 const sp<IBinder>& handle, uint64_t frameNumber) {
442 Mutex::Autolock lock(mLock);
443 layer_state_t* s = getLayerStateLocked(client, id);
444 if (!s) {
445 return BAD_INDEX;
446 }
447 s->what |= layer_state_t::eDeferTransaction;
Robert Carr0d480722017-01-10 16:42:54 -0800448 s->barrierHandle = handle;
449 s->frameNumber = frameNumber;
450 return NO_ERROR;
451}
452
453status_t Composer::deferTransactionUntil(
454 const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
455 const sp<Surface>& barrierSurface, uint64_t frameNumber) {
456 Mutex::Autolock lock(mLock);
457 layer_state_t* s = getLayerStateLocked(client, id);
458 if (!s) {
459 return BAD_INDEX;
460 }
461 s->what |= layer_state_t::eDeferTransaction;
462 s->barrierGbp = barrierSurface->getIGraphicBufferProducer();
Dan Stoza7dde5992015-05-22 09:51:44 -0700463 s->frameNumber = frameNumber;
464 return NO_ERROR;
465}
466
Robert Carr1db73f62016-12-21 12:58:51 -0800467status_t Composer::reparentChildren(
468 const sp<SurfaceComposerClient>& client,
469 const sp<IBinder>& id,
470 const sp<IBinder>& newParentHandle) {
471 Mutex::Autolock lock(mLock);
472 layer_state_t* s = getLayerStateLocked(client, id);
473 if (!s) {
474 return BAD_INDEX;
475 }
476 s->what |= layer_state_t::eReparentChildren;
477 s->reparentHandle = newParentHandle;
478 return NO_ERROR;
479}
480
Robert Carr9524cb32017-02-13 11:32:32 -0800481status_t Composer::detachChildren(
482 const sp<SurfaceComposerClient>& client,
483 const sp<IBinder>& id) {
484 Mutex::Autolock lock(mLock);
485 layer_state_t* s = getLayerStateLocked(client, id);
486 if (!s) {
487 return BAD_INDEX;
488 }
489 s->what |= layer_state_t::eDetachChildren;
490 return NO_ERROR;
491}
492
Robert Carrc3574f72016-03-24 12:19:32 -0700493status_t Composer::setOverrideScalingMode(
494 const sp<SurfaceComposerClient>& client,
495 const sp<IBinder>& id, int32_t overrideScalingMode) {
496 Mutex::Autolock lock(mLock);
497 layer_state_t* s = getLayerStateLocked(client, id);
498 if (!s) {
499 return BAD_INDEX;
500 }
501
502 switch (overrideScalingMode) {
503 case NATIVE_WINDOW_SCALING_MODE_FREEZE:
504 case NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW:
505 case NATIVE_WINDOW_SCALING_MODE_SCALE_CROP:
506 case NATIVE_WINDOW_SCALING_MODE_NO_SCALE_CROP:
507 case -1:
508 break;
509 default:
510 ALOGE("unknown scaling mode: %d",
511 overrideScalingMode);
512 return BAD_VALUE;
513 }
514
515 s->what |= layer_state_t::eOverrideScalingModeChanged;
516 s->overrideScalingMode = overrideScalingMode;
517 return NO_ERROR;
518}
519
Robert Carr99e27f02016-06-16 15:18:02 -0700520status_t Composer::setGeometryAppliesWithResize(
Robert Carr82364e32016-05-15 11:27:47 -0700521 const sp<SurfaceComposerClient>& client,
522 const sp<IBinder>& id) {
523 Mutex::Autolock lock(mLock);
524 layer_state_t* s = getLayerStateLocked(client, id);
525 if (!s) {
526 return BAD_INDEX;
527 }
Robert Carr99e27f02016-06-16 15:18:02 -0700528 s->what |= layer_state_t::eGeometryAppliesWithResize;
Robert Carr82364e32016-05-15 11:27:47 -0700529 return NO_ERROR;
530}
531
Mathias Agopian698c0872011-06-28 19:09:31 -0700532// ---------------------------------------------------------------------------
533
Mathias Agopiane57f2922012-08-09 16:29:12 -0700534DisplayState& Composer::getDisplayStateLocked(const sp<IBinder>& token) {
535 DisplayState s;
536 s.token = token;
537 ssize_t index = mDisplayStates.indexOf(s);
538 if (index < 0) {
539 // we don't have it, add an initialized layer_state to our list
540 s.what = 0;
541 index = mDisplayStates.add(s);
542 }
Dan Stozad723bd72014-11-18 10:24:03 -0800543 return mDisplayStates.editItemAt(static_cast<size_t>(index));
Mathias Agopiane57f2922012-08-09 16:29:12 -0700544}
545
Pablo Ceballos1aad24c2016-08-04 10:24:22 -0700546status_t Composer::setDisplaySurface(const sp<IBinder>& token,
547 sp<IGraphicBufferProducer> bufferProducer) {
Pablo Ceballoseddbef82016-09-01 11:21:21 -0700548 if (bufferProducer.get() != nullptr) {
549 // Make sure that composition can never be stalled by a virtual display
550 // consumer that isn't processing buffers fast enough.
551 status_t err = bufferProducer->setAsyncMode(true);
552 if (err != NO_ERROR) {
553 ALOGE("Composer::setDisplaySurface Failed to enable async mode on the "
554 "BufferQueue. This BufferQueue cannot be used for virtual "
555 "display. (%d)", err);
556 return err;
557 }
Pablo Ceballos1aad24c2016-08-04 10:24:22 -0700558 }
Mathias Agopiane57f2922012-08-09 16:29:12 -0700559 Mutex::Autolock _l(mLock);
560 DisplayState& s(getDisplayStateLocked(token));
Andy McFadden2adaf042012-12-18 09:49:45 -0800561 s.surface = bufferProducer;
Mathias Agopiane57f2922012-08-09 16:29:12 -0700562 s.what |= DisplayState::eSurfaceChanged;
Pablo Ceballos1aad24c2016-08-04 10:24:22 -0700563 return NO_ERROR;
Mathias Agopiane57f2922012-08-09 16:29:12 -0700564}
565
566void Composer::setDisplayLayerStack(const sp<IBinder>& token,
567 uint32_t layerStack) {
568 Mutex::Autolock _l(mLock);
569 DisplayState& s(getDisplayStateLocked(token));
570 s.layerStack = layerStack;
571 s.what |= DisplayState::eLayerStackChanged;
572}
573
Mathias Agopian00e8c7a2012-09-04 19:30:46 -0700574void Composer::setDisplayProjection(const sp<IBinder>& token,
575 uint32_t orientation,
576 const Rect& layerStackRect,
577 const Rect& displayRect) {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700578 Mutex::Autolock _l(mLock);
579 DisplayState& s(getDisplayStateLocked(token));
580 s.orientation = orientation;
Mathias Agopian00e8c7a2012-09-04 19:30:46 -0700581 s.viewport = layerStackRect;
582 s.frame = displayRect;
583 s.what |= DisplayState::eDisplayProjectionChanged;
Jorim Jaggi092123c2016-04-13 01:40:35 +0000584 mForceSynchronous = true; // TODO: do we actually still need this?
Mathias Agopiane57f2922012-08-09 16:29:12 -0700585}
586
Michael Wright1f6078a2014-06-26 16:01:02 -0700587void Composer::setDisplaySize(const sp<IBinder>& token, uint32_t width, uint32_t height) {
588 Mutex::Autolock _l(mLock);
589 DisplayState& s(getDisplayStateLocked(token));
590 s.width = width;
591 s.height = height;
592 s.what |= DisplayState::eDisplaySizeChanged;
593}
594
Mathias Agopiane57f2922012-08-09 16:29:12 -0700595// ---------------------------------------------------------------------------
596
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800597SurfaceComposerClient::SurfaceComposerClient()
Mathias Agopian698c0872011-06-28 19:09:31 -0700598 : mStatus(NO_INIT), mComposer(Composer::getInstance())
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800599{
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800600}
601
Robert Carr1db73f62016-12-21 12:58:51 -0800602SurfaceComposerClient::SurfaceComposerClient(const sp<IGraphicBufferProducer>& root)
603 : mStatus(NO_INIT), mComposer(Composer::getInstance()), mParent(root)
604{
605}
606
Mathias Agopian698c0872011-06-28 19:09:31 -0700607void SurfaceComposerClient::onFirstRef() {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700608 sp<ISurfaceComposer> sm(ComposerService::getComposerService());
Mathias Agopiand4784a32010-05-27 19:41:15 -0700609 if (sm != 0) {
Robert Carr1db73f62016-12-21 12:58:51 -0800610 auto rootProducer = mParent.promote();
611 sp<ISurfaceComposerClient> conn;
612 conn = (rootProducer != nullptr) ? sm->createScopedConnection(rootProducer) :
613 sm->createConnection();
Mathias Agopiand4784a32010-05-27 19:41:15 -0700614 if (conn != 0) {
615 mClient = conn;
Mathias Agopiand4784a32010-05-27 19:41:15 -0700616 mStatus = NO_ERROR;
617 }
618 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800619}
620
Mathias Agopian698c0872011-06-28 19:09:31 -0700621SurfaceComposerClient::~SurfaceComposerClient() {
Mathias Agopian631f3582010-05-25 17:51:34 -0700622 dispose();
623}
Mathias Agopiandd3423c2009-09-23 15:44:05 -0700624
Mathias Agopian698c0872011-06-28 19:09:31 -0700625status_t SurfaceComposerClient::initCheck() const {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800626 return mStatus;
627}
628
Mathias Agopian698c0872011-06-28 19:09:31 -0700629sp<IBinder> SurfaceComposerClient::connection() const {
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800630 return IInterface::asBinder(mClient);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800631}
632
Mathias Agopiand4784a32010-05-27 19:41:15 -0700633status_t SurfaceComposerClient::linkToComposerDeath(
634 const sp<IBinder::DeathRecipient>& recipient,
Mathias Agopian698c0872011-06-28 19:09:31 -0700635 void* cookie, uint32_t flags) {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700636 sp<ISurfaceComposer> sm(ComposerService::getComposerService());
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800637 return IInterface::asBinder(sm)->linkToDeath(recipient, cookie, flags);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800638}
639
Mathias Agopian698c0872011-06-28 19:09:31 -0700640void SurfaceComposerClient::dispose() {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800641 // this can be called more than once.
Mathias Agopian7e27f052010-05-28 14:22:23 -0700642 sp<ISurfaceComposerClient> client;
Mathias Agopiand4784a32010-05-27 19:41:15 -0700643 Mutex::Autolock _lm(mLock);
644 if (mClient != 0) {
Mathias Agopiand4784a32010-05-27 19:41:15 -0700645 client = mClient; // hold ref while lock is held
646 mClient.clear();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800647 }
Mathias Agopiand4784a32010-05-27 19:41:15 -0700648 mStatus = NO_INIT;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800649}
650
Mathias Agopian698c0872011-06-28 19:09:31 -0700651sp<SurfaceControl> SurfaceComposerClient::createSurface(
Mathias Agopian698c0872011-06-28 19:09:31 -0700652 const String8& name,
Mathias Agopian698c0872011-06-28 19:09:31 -0700653 uint32_t w,
654 uint32_t h,
655 PixelFormat format,
Robert Carr1f0a16a2016-10-24 16:27:39 -0700656 uint32_t flags,
Albert Chaulk479c60c2017-01-27 14:21:34 -0500657 SurfaceControl* parent,
658 uint32_t windowType,
659 uint32_t ownerUid)
Mathias Agopian698c0872011-06-28 19:09:31 -0700660{
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700661 sp<SurfaceControl> sur;
Mathias Agopian698c0872011-06-28 19:09:31 -0700662 if (mStatus == NO_ERROR) {
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700663 sp<IBinder> handle;
Robert Carr1f0a16a2016-10-24 16:27:39 -0700664 sp<IBinder> parentHandle;
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700665 sp<IGraphicBufferProducer> gbp;
Robert Carr1f0a16a2016-10-24 16:27:39 -0700666
667 if (parent != nullptr) {
668 parentHandle = parent->getHandle();
669 }
670 status_t err = mClient->createSurface(name, w, h, format, flags, parentHandle,
Albert Chaulk479c60c2017-01-27 14:21:34 -0500671 windowType, ownerUid, &handle, &gbp);
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700672 ALOGE_IF(err, "SurfaceComposerClient::createSurface error %s", strerror(-err));
673 if (err == NO_ERROR) {
674 sur = new SurfaceControl(this, handle, gbp);
Mathias Agopian698c0872011-06-28 19:09:31 -0700675 }
676 }
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700677 return sur;
Mathias Agopian698c0872011-06-28 19:09:31 -0700678}
679
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700680sp<IBinder> SurfaceComposerClient::createDisplay(const String8& displayName,
681 bool secure) {
682 return Composer::getInstance().createDisplay(displayName, secure);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700683}
684
Jesse Hall6c913be2013-08-08 12:15:49 -0700685void SurfaceComposerClient::destroyDisplay(const sp<IBinder>& display) {
686 Composer::getInstance().destroyDisplay(display);
687}
688
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700689sp<IBinder> SurfaceComposerClient::getBuiltInDisplay(int32_t id) {
690 return Composer::getInstance().getBuiltInDisplay(id);
691}
692
Mathias Agopianac9fa422013-02-11 16:40:36 -0800693status_t SurfaceComposerClient::destroySurface(const sp<IBinder>& sid) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700694 if (mStatus != NO_ERROR)
695 return mStatus;
696 status_t err = mClient->destroySurface(sid);
697 return err;
698}
699
Svetoslavd85084b2014-03-20 10:28:31 -0700700status_t SurfaceComposerClient::clearLayerFrameStats(const sp<IBinder>& token) const {
701 if (mStatus != NO_ERROR) {
702 return mStatus;
703 }
704 return mClient->clearLayerFrameStats(token);
705}
706
707status_t SurfaceComposerClient::getLayerFrameStats(const sp<IBinder>& token,
708 FrameStats* outStats) const {
709 if (mStatus != NO_ERROR) {
710 return mStatus;
711 }
712 return mClient->getLayerFrameStats(token, outStats);
713}
714
Robert Carr367c5682016-06-20 11:55:28 -0700715status_t SurfaceComposerClient::getTransformToDisplayInverse(const sp<IBinder>& token,
716 bool* outTransformToDisplayInverse) const {
717 if (mStatus != NO_ERROR) {
718 return mStatus;
719 }
720 return mClient->getTransformToDisplayInverse(token, outTransformToDisplayInverse);
721}
722
Mathias Agopian698c0872011-06-28 19:09:31 -0700723inline Composer& SurfaceComposerClient::getComposer() {
724 return mComposer;
725}
726
727// ----------------------------------------------------------------------------
728
729void SurfaceComposerClient::openGlobalTransaction() {
Jeff Brownf3f7db62012-08-31 02:18:38 -0700730 Composer::openGlobalTransaction();
Mathias Agopian698c0872011-06-28 19:09:31 -0700731}
732
Jamie Gennis28378392011-10-12 17:39:00 -0700733void SurfaceComposerClient::closeGlobalTransaction(bool synchronous) {
734 Composer::closeGlobalTransaction(synchronous);
Mathias Agopian698c0872011-06-28 19:09:31 -0700735}
736
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700737void SurfaceComposerClient::setAnimationTransaction() {
738 Composer::setAnimationTransaction();
739}
740
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -0700741status_t SurfaceComposerClient::enableVSyncInjections(bool enable) {
742 return Composer::enableVSyncInjections(enable);
743}
744
745status_t SurfaceComposerClient::injectVSync(nsecs_t when) {
746 return Composer::injectVSync(when);
747}
748
Mathias Agopian698c0872011-06-28 19:09:31 -0700749// ----------------------------------------------------------------------------
750
Mathias Agopianac9fa422013-02-11 16:40:36 -0800751status_t SurfaceComposerClient::setCrop(const sp<IBinder>& id, const Rect& crop) {
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700752 return getComposer().setCrop(this, id, crop);
753}
754
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000755status_t SurfaceComposerClient::setFinalCrop(const sp<IBinder>& id,
756 const Rect& crop) {
757 return getComposer().setFinalCrop(this, id, crop);
758}
759
Mathias Agopianac9fa422013-02-11 16:40:36 -0800760status_t SurfaceComposerClient::setPosition(const sp<IBinder>& id, float x, float y) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700761 return getComposer().setPosition(this, id, x, y);
762}
763
Mathias Agopianac9fa422013-02-11 16:40:36 -0800764status_t SurfaceComposerClient::setSize(const sp<IBinder>& id, uint32_t w, uint32_t h) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700765 return getComposer().setSize(this, id, w, h);
766}
767
Robert Carrae060832016-11-28 10:51:00 -0800768status_t SurfaceComposerClient::setLayer(const sp<IBinder>& id, int32_t z) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700769 return getComposer().setLayer(this, id, z);
770}
771
Mathias Agopianac9fa422013-02-11 16:40:36 -0800772status_t SurfaceComposerClient::hide(const sp<IBinder>& id) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700773 return getComposer().setFlags(this, id,
Mathias Agopian3165cc22012-08-08 19:42:09 -0700774 layer_state_t::eLayerHidden,
775 layer_state_t::eLayerHidden);
Mathias Agopian698c0872011-06-28 19:09:31 -0700776}
777
Mathias Agopianac9fa422013-02-11 16:40:36 -0800778status_t SurfaceComposerClient::show(const sp<IBinder>& id) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700779 return getComposer().setFlags(this, id,
780 0,
Mathias Agopian3165cc22012-08-08 19:42:09 -0700781 layer_state_t::eLayerHidden);
Mathias Agopian698c0872011-06-28 19:09:31 -0700782}
783
Mathias Agopianac9fa422013-02-11 16:40:36 -0800784status_t SurfaceComposerClient::setFlags(const sp<IBinder>& id, uint32_t flags,
Mathias Agopian698c0872011-06-28 19:09:31 -0700785 uint32_t mask) {
786 return getComposer().setFlags(this, id, flags, mask);
787}
788
Mathias Agopianac9fa422013-02-11 16:40:36 -0800789status_t SurfaceComposerClient::setTransparentRegionHint(const sp<IBinder>& id,
Mathias Agopian698c0872011-06-28 19:09:31 -0700790 const Region& transparentRegion) {
791 return getComposer().setTransparentRegionHint(this, id, transparentRegion);
792}
793
Mathias Agopianac9fa422013-02-11 16:40:36 -0800794status_t SurfaceComposerClient::setAlpha(const sp<IBinder>& id, float alpha) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700795 return getComposer().setAlpha(this, id, alpha);
796}
797
Mathias Agopianac9fa422013-02-11 16:40:36 -0800798status_t SurfaceComposerClient::setLayerStack(const sp<IBinder>& id, uint32_t layerStack) {
Mathias Agopian87855782012-07-24 21:41:09 -0700799 return getComposer().setLayerStack(this, id, layerStack);
800}
801
Mathias Agopianac9fa422013-02-11 16:40:36 -0800802status_t SurfaceComposerClient::setMatrix(const sp<IBinder>& id, float dsdx, float dtdx,
Mathias Agopian698c0872011-06-28 19:09:31 -0700803 float dsdy, float dtdy) {
804 return getComposer().setMatrix(this, id, dsdx, dtdx, dsdy, dtdy);
805}
806
Dan Stoza7dde5992015-05-22 09:51:44 -0700807status_t SurfaceComposerClient::deferTransactionUntil(const sp<IBinder>& id,
808 const sp<IBinder>& handle, uint64_t frameNumber) {
809 return getComposer().deferTransactionUntil(this, id, handle, frameNumber);
810}
811
Robert Carr0d480722017-01-10 16:42:54 -0800812status_t SurfaceComposerClient::deferTransactionUntil(const sp<IBinder>& id,
813 const sp<Surface>& barrierSurface, uint64_t frameNumber) {
814 return getComposer().deferTransactionUntil(this, id, barrierSurface, frameNumber);
815}
816
Robert Carr1db73f62016-12-21 12:58:51 -0800817status_t SurfaceComposerClient::reparentChildren(const sp<IBinder>& id,
818 const sp<IBinder>& newParentHandle) {
819 return getComposer().reparentChildren(this, id, newParentHandle);
820}
821
Robert Carr9524cb32017-02-13 11:32:32 -0800822status_t SurfaceComposerClient::detachChildren(const sp<IBinder>& id) {
823 return getComposer().detachChildren(this, id);
824}
825
Robert Carrc3574f72016-03-24 12:19:32 -0700826status_t SurfaceComposerClient::setOverrideScalingMode(
827 const sp<IBinder>& id, int32_t overrideScalingMode) {
828 return getComposer().setOverrideScalingMode(
829 this, id, overrideScalingMode);
830}
831
Robert Carr99e27f02016-06-16 15:18:02 -0700832status_t SurfaceComposerClient::setGeometryAppliesWithResize(
Robert Carr82364e32016-05-15 11:27:47 -0700833 const sp<IBinder>& id) {
Robert Carr99e27f02016-06-16 15:18:02 -0700834 return getComposer().setGeometryAppliesWithResize(this, id);
Robert Carr82364e32016-05-15 11:27:47 -0700835}
836
Mathias Agopian698c0872011-06-28 19:09:31 -0700837// ----------------------------------------------------------------------------
838
Pablo Ceballos1aad24c2016-08-04 10:24:22 -0700839status_t SurfaceComposerClient::setDisplaySurface(const sp<IBinder>& token,
840 sp<IGraphicBufferProducer> bufferProducer) {
841 return Composer::getInstance().setDisplaySurface(token, bufferProducer);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700842}
843
844void SurfaceComposerClient::setDisplayLayerStack(const sp<IBinder>& token,
845 uint32_t layerStack) {
846 Composer::getInstance().setDisplayLayerStack(token, layerStack);
847}
848
Mathias Agopian00e8c7a2012-09-04 19:30:46 -0700849void SurfaceComposerClient::setDisplayProjection(const sp<IBinder>& token,
850 uint32_t orientation,
851 const Rect& layerStackRect,
852 const Rect& displayRect) {
853 Composer::getInstance().setDisplayProjection(token, orientation,
854 layerStackRect, displayRect);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700855}
856
Michael Wright1f6078a2014-06-26 16:01:02 -0700857void SurfaceComposerClient::setDisplaySize(const sp<IBinder>& token,
858 uint32_t width, uint32_t height) {
859 Composer::getInstance().setDisplaySize(token, width, height);
860}
861
Mathias Agopiane57f2922012-08-09 16:29:12 -0700862// ----------------------------------------------------------------------------
863
Dan Stoza7f7da322014-05-02 15:26:25 -0700864status_t SurfaceComposerClient::getDisplayConfigs(
865 const sp<IBinder>& display, Vector<DisplayInfo>* configs)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800866{
Dan Stoza7f7da322014-05-02 15:26:25 -0700867 return ComposerService::getComposerService()->getDisplayConfigs(display, configs);
868}
869
870status_t SurfaceComposerClient::getDisplayInfo(const sp<IBinder>& display,
871 DisplayInfo* info) {
872 Vector<DisplayInfo> configs;
873 status_t result = getDisplayConfigs(display, &configs);
874 if (result != NO_ERROR) {
875 return result;
876 }
877
878 int activeId = getActiveConfig(display);
879 if (activeId < 0) {
880 ALOGE("No active configuration found");
881 return NAME_NOT_FOUND;
882 }
883
Dan Stozad723bd72014-11-18 10:24:03 -0800884 *info = configs[static_cast<size_t>(activeId)];
Dan Stoza7f7da322014-05-02 15:26:25 -0700885 return NO_ERROR;
886}
887
888int SurfaceComposerClient::getActiveConfig(const sp<IBinder>& display) {
889 return ComposerService::getComposerService()->getActiveConfig(display);
890}
891
892status_t SurfaceComposerClient::setActiveConfig(const sp<IBinder>& display, int id) {
893 return ComposerService::getComposerService()->setActiveConfig(display, id);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800894}
895
Michael Wright28f24d02016-07-12 13:30:53 -0700896status_t SurfaceComposerClient::getDisplayColorModes(const sp<IBinder>& display,
897 Vector<android_color_mode_t>* outColorModes) {
898 return ComposerService::getComposerService()->getDisplayColorModes(display, outColorModes);
899}
900
901android_color_mode_t SurfaceComposerClient::getActiveColorMode(const sp<IBinder>& display) {
902 return ComposerService::getComposerService()->getActiveColorMode(display);
903}
904
905status_t SurfaceComposerClient::setActiveColorMode(const sp<IBinder>& display,
906 android_color_mode_t colorMode) {
907 return ComposerService::getComposerService()->setActiveColorMode(display, colorMode);
908}
909
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700910void SurfaceComposerClient::setDisplayPowerMode(const sp<IBinder>& token,
911 int mode) {
912 ComposerService::getComposerService()->setPowerMode(token, mode);
Jeff Brown2a09bb32012-10-08 19:13:57 -0700913}
914
Svetoslavd85084b2014-03-20 10:28:31 -0700915status_t SurfaceComposerClient::clearAnimationFrameStats() {
916 return ComposerService::getComposerService()->clearAnimationFrameStats();
917}
918
919status_t SurfaceComposerClient::getAnimationFrameStats(FrameStats* outStats) {
920 return ComposerService::getComposerService()->getAnimationFrameStats(outStats);
921}
922
Dan Stozac4f471e2016-03-24 09:31:08 -0700923status_t SurfaceComposerClient::getHdrCapabilities(const sp<IBinder>& display,
924 HdrCapabilities* outCapabilities) {
925 return ComposerService::getComposerService()->getHdrCapabilities(display,
926 outCapabilities);
927}
928
Mathias Agopian698c0872011-06-28 19:09:31 -0700929// ----------------------------------------------------------------------------
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800930
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800931status_t ScreenshotClient::capture(
932 const sp<IBinder>& display,
933 const sp<IGraphicBufferProducer>& producer,
Dan Stozac1879002014-05-22 15:59:05 -0700934 Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
Robert Carrae060832016-11-28 10:51:00 -0800935 int32_t minLayerZ, int32_t maxLayerZ, bool useIdentityTransform) {
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800936 sp<ISurfaceComposer> s(ComposerService::getComposerService());
937 if (s == NULL) return NO_INIT;
Dan Stozac1879002014-05-22 15:59:05 -0700938 return s->captureScreen(display, producer, sourceCrop,
Dan Stozac7014012014-02-14 15:03:43 -0800939 reqWidth, reqHeight, minLayerZ, maxLayerZ, useIdentityTransform);
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800940}
941
Robert Carr673134e2017-01-09 19:48:38 -0800942status_t ScreenshotClient::captureToBuffer(const sp<IBinder>& display,
943 Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
Robert Carrae060832016-11-28 10:51:00 -0800944 int32_t minLayerZ, int32_t maxLayerZ, bool useIdentityTransform,
Robert Carr673134e2017-01-09 19:48:38 -0800945 uint32_t rotation,
946 sp<GraphicBuffer>* outBuffer) {
947 sp<ISurfaceComposer> s(ComposerService::getComposerService());
948 if (s == NULL) return NO_INIT;
949
950 sp<IGraphicBufferConsumer> gbpConsumer;
951 sp<IGraphicBufferProducer> producer;
952 BufferQueue::createBufferQueue(&producer, &gbpConsumer);
953 sp<BufferItemConsumer> consumer(new BufferItemConsumer(gbpConsumer,
954 GRALLOC_USAGE_HW_TEXTURE | GRALLOC_USAGE_SW_READ_NEVER | GRALLOC_USAGE_SW_WRITE_NEVER,
955 1, true));
956
957 status_t ret = s->captureScreen(display, producer, sourceCrop, reqWidth, reqHeight,
958 minLayerZ, maxLayerZ, useIdentityTransform,
959 static_cast<ISurfaceComposer::Rotation>(rotation));
960 if (ret != NO_ERROR) {
961 return ret;
962 }
963 BufferItem b;
964 consumer->acquireBuffer(&b, 0, true);
965 *outBuffer = b.mGraphicBuffer;
966 return ret;
967}
968
Mathias Agopian74c40c02010-09-29 13:02:36 -0700969ScreenshotClient::ScreenshotClient()
Mathias Agopianabe815d2013-03-19 22:22:21 -0700970 : mHaveBuffer(false) {
971 memset(&mBuffer, 0, sizeof(mBuffer));
Mathias Agopian74c40c02010-09-29 13:02:36 -0700972}
973
Mathias Agopian8000d062013-03-26 18:15:35 -0700974ScreenshotClient::~ScreenshotClient() {
975 ScreenshotClient::release();
976}
977
Mathias Agopianabe815d2013-03-19 22:22:21 -0700978sp<CpuConsumer> ScreenshotClient::getCpuConsumer() const {
979 if (mCpuConsumer == NULL) {
Dan Stoza6d5a7bb2014-03-13 11:39:09 -0700980 sp<IGraphicBufferConsumer> consumer;
981 BufferQueue::createBufferQueue(&mProducer, &consumer);
982 mCpuConsumer = new CpuConsumer(consumer, 1);
Mathias Agopianabe815d2013-03-19 22:22:21 -0700983 mCpuConsumer->setName(String8("ScreenshotClient"));
984 }
985 return mCpuConsumer;
Mathias Agopianbf2c6a62010-12-10 16:22:31 -0800986}
987
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700988status_t ScreenshotClient::update(const sp<IBinder>& display,
Dan Stozac1879002014-05-22 15:59:05 -0700989 Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
Robert Carrae060832016-11-28 10:51:00 -0800990 int32_t minLayerZ, int32_t maxLayerZ,
Riley Andrewsd15ef272014-09-04 16:19:44 -0700991 bool useIdentityTransform, uint32_t rotation) {
Mathias Agopianbf2c6a62010-12-10 16:22:31 -0800992 sp<ISurfaceComposer> s(ComposerService::getComposerService());
993 if (s == NULL) return NO_INIT;
Mathias Agopianabe815d2013-03-19 22:22:21 -0700994 sp<CpuConsumer> cpuConsumer = getCpuConsumer();
995
996 if (mHaveBuffer) {
997 mCpuConsumer->unlockBuffer(mBuffer);
998 memset(&mBuffer, 0, sizeof(mBuffer));
999 mHaveBuffer = false;
1000 }
1001
Dan Stozac1879002014-05-22 15:59:05 -07001002 status_t err = s->captureScreen(display, mProducer, sourceCrop,
Riley Andrewsd15ef272014-09-04 16:19:44 -07001003 reqWidth, reqHeight, minLayerZ, maxLayerZ, useIdentityTransform,
1004 static_cast<ISurfaceComposer::Rotation>(rotation));
Mathias Agopianabe815d2013-03-19 22:22:21 -07001005
1006 if (err == NO_ERROR) {
1007 err = mCpuConsumer->lockNextBuffer(&mBuffer);
1008 if (err == NO_ERROR) {
1009 mHaveBuffer = true;
1010 }
1011 }
1012 return err;
1013}
1014
Riley Andrewsd15ef272014-09-04 16:19:44 -07001015status_t ScreenshotClient::update(const sp<IBinder>& display,
1016 Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
Robert Carrae060832016-11-28 10:51:00 -08001017 int32_t minLayerZ, int32_t maxLayerZ,
Riley Andrewsd15ef272014-09-04 16:19:44 -07001018 bool useIdentityTransform) {
1019
1020 return ScreenshotClient::update(display, sourceCrop, reqWidth, reqHeight,
1021 minLayerZ, maxLayerZ, useIdentityTransform, ISurfaceComposer::eRotateNone);
1022}
1023
Dan Stozac1879002014-05-22 15:59:05 -07001024status_t ScreenshotClient::update(const sp<IBinder>& display, Rect sourceCrop,
Dan Stozac7014012014-02-14 15:03:43 -08001025 bool useIdentityTransform) {
Robert Carrae060832016-11-28 10:51:00 -08001026 return ScreenshotClient::update(display, sourceCrop, 0, 0,
1027 INT32_MIN, INT32_MAX,
Riley Andrewsd15ef272014-09-04 16:19:44 -07001028 useIdentityTransform, ISurfaceComposer::eRotateNone);
Mathias Agopianabe815d2013-03-19 22:22:21 -07001029}
1030
Dan Stozac1879002014-05-22 15:59:05 -07001031status_t ScreenshotClient::update(const sp<IBinder>& display, Rect sourceCrop,
Dan Stozac7014012014-02-14 15:03:43 -08001032 uint32_t reqWidth, uint32_t reqHeight, bool useIdentityTransform) {
Dan Stozac1879002014-05-22 15:59:05 -07001033 return ScreenshotClient::update(display, sourceCrop, reqWidth, reqHeight,
Robert Carrae060832016-11-28 10:51:00 -08001034 INT32_MIN, INT32_MAX,
1035 useIdentityTransform, ISurfaceComposer::eRotateNone);
Mathias Agopian74c40c02010-09-29 13:02:36 -07001036}
1037
1038void ScreenshotClient::release() {
Mathias Agopianabe815d2013-03-19 22:22:21 -07001039 if (mHaveBuffer) {
1040 mCpuConsumer->unlockBuffer(mBuffer);
1041 memset(&mBuffer, 0, sizeof(mBuffer));
1042 mHaveBuffer = false;
1043 }
1044 mCpuConsumer.clear();
Mathias Agopian74c40c02010-09-29 13:02:36 -07001045}
1046
1047void const* ScreenshotClient::getPixels() const {
Mathias Agopianabe815d2013-03-19 22:22:21 -07001048 return mBuffer.data;
Mathias Agopian74c40c02010-09-29 13:02:36 -07001049}
1050
1051uint32_t ScreenshotClient::getWidth() const {
Mathias Agopianabe815d2013-03-19 22:22:21 -07001052 return mBuffer.width;
Mathias Agopian74c40c02010-09-29 13:02:36 -07001053}
1054
1055uint32_t ScreenshotClient::getHeight() const {
Mathias Agopianabe815d2013-03-19 22:22:21 -07001056 return mBuffer.height;
Mathias Agopian74c40c02010-09-29 13:02:36 -07001057}
1058
1059PixelFormat ScreenshotClient::getFormat() const {
Mathias Agopianabe815d2013-03-19 22:22:21 -07001060 return mBuffer.format;
Mathias Agopian74c40c02010-09-29 13:02:36 -07001061}
1062
1063uint32_t ScreenshotClient::getStride() const {
Mathias Agopianabe815d2013-03-19 22:22:21 -07001064 return mBuffer.stride;
Mathias Agopian74c40c02010-09-29 13:02:36 -07001065}
1066
1067size_t ScreenshotClient::getSize() const {
Mathias Agopianabe815d2013-03-19 22:22:21 -07001068 return mBuffer.stride * mBuffer.height * bytesPerPixel(mBuffer.format);
Mathias Agopian74c40c02010-09-29 13:02:36 -07001069}
1070
1071// ----------------------------------------------------------------------------
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001072}; // namespace android