blob: 088933afb66151cf3dc6cd1cc26bb013a04e6623 [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 Agopiana67932f2011-04-20 14:20:59 -070029#include <binder/IServiceManager.h>
Mathias Agopian9cce3252010-02-09 17:46:37 -080030
Michael Wright28f24d02016-07-12 13:30:53 -070031#include <system/graphics.h>
32
Mathias Agopian076b1cc2009-04-10 14:24:30 -070033#include <ui/DisplayInfo.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080034
Robert Carr673134e2017-01-09 19:48:38 -080035#include <gui/BufferItemConsumer.h>
Mathias Agopianabe815d2013-03-19 22:22:21 -070036#include <gui/CpuConsumer.h>
Mathias Agopiane3c697f2013-02-14 17:11:02 -080037#include <gui/IGraphicBufferProducer.h>
Mathias Agopian90ac7992012-02-25 18:48:35 -080038#include <gui/ISurfaceComposer.h>
39#include <gui/ISurfaceComposerClient.h>
Robert Carr0d480722017-01-10 16:42:54 -080040#include <gui/Surface.h>
Mathias Agopian90ac7992012-02-25 18:48:35 -080041#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,
Robert Carrcb6e1e32017-02-21 19:48:26 -0800160 float dsdx, float dtdx, float dtdy, float dsdy);
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 Carr0d480722017-01-10 16:42:54 -0800171 status_t deferTransactionUntil(const sp<SurfaceComposerClient>& client,
172 const sp<IBinder>& id, const sp<Surface>& barrierSurface,
173 uint64_t frameNumber);
Robert Carr1db73f62016-12-21 12:58:51 -0800174 status_t reparentChildren(const sp<SurfaceComposerClient>& client,
175 const sp<IBinder>& id,
176 const sp<IBinder>& newParentHandle);
Robert Carr9524cb32017-02-13 11:32:32 -0800177 status_t detachChildren(const sp<SurfaceComposerClient>& client,
178 const sp<IBinder>& id);
Robert Carrc3574f72016-03-24 12:19:32 -0700179 status_t setOverrideScalingMode(const sp<SurfaceComposerClient>& client,
180 const sp<IBinder>& id, int32_t overrideScalingMode);
Robert Carr99e27f02016-06-16 15:18:02 -0700181 status_t setGeometryAppliesWithResize(const sp<SurfaceComposerClient>& client,
Robert Carr82364e32016-05-15 11:27:47 -0700182 const sp<IBinder>& id);
Mathias Agopian698c0872011-06-28 19:09:31 -0700183
Pablo Ceballos1aad24c2016-08-04 10:24:22 -0700184 status_t setDisplaySurface(const sp<IBinder>& token,
185 sp<IGraphicBufferProducer> bufferProducer);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700186 void setDisplayLayerStack(const sp<IBinder>& token, uint32_t layerStack);
Mathias Agopian00e8c7a2012-09-04 19:30:46 -0700187 void setDisplayProjection(const sp<IBinder>& token,
188 uint32_t orientation,
189 const Rect& layerStackRect,
190 const Rect& displayRect);
Michael Wright1f6078a2014-06-26 16:01:02 -0700191 void setDisplaySize(const sp<IBinder>& token, uint32_t width, uint32_t height);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700192
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700193 static void setAnimationTransaction() {
194 Composer::getInstance().setAnimationTransactionImpl();
195 }
196
Jeff Brownf3f7db62012-08-31 02:18:38 -0700197 static void openGlobalTransaction() {
198 Composer::getInstance().openGlobalTransactionImpl();
199 }
200
Jamie Gennis28378392011-10-12 17:39:00 -0700201 static void closeGlobalTransaction(bool synchronous) {
202 Composer::getInstance().closeGlobalTransactionImpl(synchronous);
Mathias Agopiand4784a32010-05-27 19:41:15 -0700203 }
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -0700204
205 static status_t enableVSyncInjections(bool enable) {
206 return Composer::getInstance().enableVSyncInjectionsImpl(enable);
207 }
208
209 static status_t injectVSync(nsecs_t when) {
210 return Composer::getInstance().injectVSyncImpl(when);
211 }
Mathias Agopiand4784a32010-05-27 19:41:15 -0700212};
213
214ANDROID_SINGLETON_STATIC_INSTANCE(Composer);
215
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800216// ---------------------------------------------------------------------------
217
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700218sp<IBinder> Composer::createDisplay(const String8& displayName, bool secure) {
219 return ComposerService::getComposerService()->createDisplay(displayName,
220 secure);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700221}
222
Jesse Hall6c913be2013-08-08 12:15:49 -0700223void Composer::destroyDisplay(const sp<IBinder>& display) {
224 return ComposerService::getComposerService()->destroyDisplay(display);
225}
226
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700227sp<IBinder> Composer::getBuiltInDisplay(int32_t id) {
228 return ComposerService::getComposerService()->getBuiltInDisplay(id);
229}
230
Jeff Brownf3f7db62012-08-31 02:18:38 -0700231void Composer::openGlobalTransactionImpl() {
232 { // scope for the lock
233 Mutex::Autolock _l(mLock);
234 mTransactionNestCount += 1;
235 }
236}
237
Jamie Gennis28378392011-10-12 17:39:00 -0700238void Composer::closeGlobalTransactionImpl(bool synchronous) {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700239 sp<ISurfaceComposer> sm(ComposerService::getComposerService());
Mathias Agopian698c0872011-06-28 19:09:31 -0700240
241 Vector<ComposerState> transaction;
Mathias Agopian8b33f032012-07-24 20:43:54 -0700242 Vector<DisplayState> displayTransaction;
Jamie Gennis28378392011-10-12 17:39:00 -0700243 uint32_t flags = 0;
Mathias Agopian698c0872011-06-28 19:09:31 -0700244
245 { // scope for the lock
246 Mutex::Autolock _l(mLock);
Jeff Brownf3f7db62012-08-31 02:18:38 -0700247 mForceSynchronous |= synchronous;
248 if (!mTransactionNestCount) {
249 ALOGW("At least one call to closeGlobalTransaction() was not matched by a prior "
250 "call to openGlobalTransaction().");
251 } else if (--mTransactionNestCount) {
252 return;
253 }
254
Mathias Agopiane57f2922012-08-09 16:29:12 -0700255 transaction = mComposerStates;
256 mComposerStates.clear();
Jamie Gennisb8d69a52011-10-10 15:48:06 -0700257
Mathias Agopiane57f2922012-08-09 16:29:12 -0700258 displayTransaction = mDisplayStates;
259 mDisplayStates.clear();
Jamie Gennis28378392011-10-12 17:39:00 -0700260
Jeff Brownf3f7db62012-08-31 02:18:38 -0700261 if (mForceSynchronous) {
Jamie Gennis28378392011-10-12 17:39:00 -0700262 flags |= ISurfaceComposer::eSynchronous;
263 }
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700264 if (mAnimation) {
265 flags |= ISurfaceComposer::eAnimation;
266 }
267
Jamie Gennis28378392011-10-12 17:39:00 -0700268 mForceSynchronous = false;
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700269 mAnimation = false;
Mathias Agopian698c0872011-06-28 19:09:31 -0700270 }
271
Mathias Agopian8b33f032012-07-24 20:43:54 -0700272 sm->setTransactionState(transaction, displayTransaction, flags);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800273}
274
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -0700275status_t Composer::enableVSyncInjectionsImpl(bool enable) {
276 sp<ISurfaceComposer> sm(ComposerService::getComposerService());
277 return sm->enableVSyncInjections(enable);
278}
279
280status_t Composer::injectVSyncImpl(nsecs_t when) {
281 sp<ISurfaceComposer> sm(ComposerService::getComposerService());
282 return sm->injectVSync(when);
283}
284
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700285void Composer::setAnimationTransactionImpl() {
286 Mutex::Autolock _l(mLock);
287 mAnimation = true;
288}
289
Mathias Agopian698c0872011-06-28 19:09:31 -0700290layer_state_t* Composer::getLayerStateLocked(
Mathias Agopianac9fa422013-02-11 16:40:36 -0800291 const sp<SurfaceComposerClient>& client, const sp<IBinder>& id) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700292
293 ComposerState s;
294 s.client = client->mClient;
295 s.state.surface = id;
296
Mathias Agopiane57f2922012-08-09 16:29:12 -0700297 ssize_t index = mComposerStates.indexOf(s);
Mathias Agopian698c0872011-06-28 19:09:31 -0700298 if (index < 0) {
299 // we don't have it, add an initialized layer_state to our list
Mathias Agopiane57f2922012-08-09 16:29:12 -0700300 index = mComposerStates.add(s);
Mathias Agopian698c0872011-06-28 19:09:31 -0700301 }
302
Mathias Agopiane57f2922012-08-09 16:29:12 -0700303 ComposerState* const out = mComposerStates.editArray();
Mathias Agopian698c0872011-06-28 19:09:31 -0700304 return &(out[index].state);
305}
306
307status_t Composer::setPosition(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-11 16:40:36 -0800308 const sp<IBinder>& id, float x, float y) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700309 Mutex::Autolock _l(mLock);
310 layer_state_t* s = getLayerStateLocked(client, id);
311 if (!s)
312 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700313 s->what |= layer_state_t::ePositionChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700314 s->x = x;
315 s->y = y;
316 return NO_ERROR;
317}
318
319status_t Composer::setSize(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-11 16:40:36 -0800320 const sp<IBinder>& id, uint32_t w, uint32_t h) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700321 Mutex::Autolock _l(mLock);
322 layer_state_t* s = getLayerStateLocked(client, id);
323 if (!s)
324 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700325 s->what |= layer_state_t::eSizeChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700326 s->w = w;
327 s->h = h;
Jamie Gennis28378392011-10-12 17:39:00 -0700328
Jorim Jaggi092123c2016-04-13 01:40:35 +0000329 // Resizing a surface makes the transaction synchronous.
330 mForceSynchronous = true;
331
Mathias Agopian698c0872011-06-28 19:09:31 -0700332 return NO_ERROR;
333}
334
335status_t Composer::setLayer(const sp<SurfaceComposerClient>& client,
Robert Carrae060832016-11-28 10:51:00 -0800336 const sp<IBinder>& id, int32_t z) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700337 Mutex::Autolock _l(mLock);
338 layer_state_t* s = getLayerStateLocked(client, id);
339 if (!s)
340 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700341 s->what |= layer_state_t::eLayerChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700342 s->z = z;
343 return NO_ERROR;
344}
345
346status_t Composer::setFlags(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-11 16:40:36 -0800347 const sp<IBinder>& id, uint32_t flags,
Mathias Agopian698c0872011-06-28 19:09:31 -0700348 uint32_t mask) {
349 Mutex::Autolock _l(mLock);
350 layer_state_t* s = getLayerStateLocked(client, id);
351 if (!s)
352 return BAD_INDEX;
Pablo Ceballos53390e12015-08-04 11:25:59 -0700353 if ((mask & layer_state_t::eLayerOpaque) ||
354 (mask & layer_state_t::eLayerHidden) ||
355 (mask & layer_state_t::eLayerSecure)) {
Dan Stoza23116082015-06-18 14:58:39 -0700356 s->what |= layer_state_t::eFlagsChanged;
Andy McFadden4125a4f2014-01-29 17:17:11 -0800357 }
Mathias Agopian698c0872011-06-28 19:09:31 -0700358 s->flags &= ~mask;
359 s->flags |= (flags & mask);
360 s->mask |= mask;
361 return NO_ERROR;
362}
363
364status_t Composer::setTransparentRegionHint(
Mathias Agopianac9fa422013-02-11 16:40:36 -0800365 const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
Mathias Agopian698c0872011-06-28 19:09:31 -0700366 const Region& transparentRegion) {
367 Mutex::Autolock _l(mLock);
368 layer_state_t* s = getLayerStateLocked(client, id);
369 if (!s)
370 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700371 s->what |= layer_state_t::eTransparentRegionChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700372 s->transparentRegion = transparentRegion;
373 return NO_ERROR;
374}
375
376status_t Composer::setAlpha(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-11 16:40:36 -0800377 const sp<IBinder>& id, float alpha) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700378 Mutex::Autolock _l(mLock);
379 layer_state_t* s = getLayerStateLocked(client, id);
380 if (!s)
381 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700382 s->what |= layer_state_t::eAlphaChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700383 s->alpha = alpha;
384 return NO_ERROR;
385}
386
Mathias Agopian87855782012-07-24 21:41:09 -0700387status_t Composer::setLayerStack(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-11 16:40:36 -0800388 const sp<IBinder>& id, uint32_t layerStack) {
Mathias Agopian87855782012-07-24 21:41:09 -0700389 Mutex::Autolock _l(mLock);
390 layer_state_t* s = getLayerStateLocked(client, id);
391 if (!s)
392 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700393 s->what |= layer_state_t::eLayerStackChanged;
Mathias Agopian87855782012-07-24 21:41:09 -0700394 s->layerStack = layerStack;
395 return NO_ERROR;
396}
397
Mathias Agopian698c0872011-06-28 19:09:31 -0700398status_t Composer::setMatrix(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-11 16:40:36 -0800399 const sp<IBinder>& id, float dsdx, float dtdx,
Robert Carrcb6e1e32017-02-21 19:48:26 -0800400 float dtdy, float dsdy) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700401 Mutex::Autolock _l(mLock);
402 layer_state_t* s = getLayerStateLocked(client, id);
403 if (!s)
404 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700405 s->what |= layer_state_t::eMatrixChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700406 layer_state_t::matrix22_t matrix;
407 matrix.dsdx = dsdx;
408 matrix.dtdx = dtdx;
409 matrix.dsdy = dsdy;
410 matrix.dtdy = dtdy;
411 s->matrix = matrix;
412 return NO_ERROR;
413}
414
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700415status_t Composer::setCrop(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-11 16:40:36 -0800416 const sp<IBinder>& id, const Rect& crop) {
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700417 Mutex::Autolock _l(mLock);
418 layer_state_t* s = getLayerStateLocked(client, id);
419 if (!s)
420 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700421 s->what |= layer_state_t::eCropChanged;
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700422 s->crop = crop;
423 return NO_ERROR;
424}
425
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000426status_t Composer::setFinalCrop(const sp<SurfaceComposerClient>& client,
427 const sp<IBinder>& id, const Rect& crop) {
428 Mutex::Autolock _l(mLock);
429 layer_state_t* s = getLayerStateLocked(client, id);
430 if (!s) {
431 return BAD_INDEX;
432 }
433 s->what |= layer_state_t::eFinalCropChanged;
434 s->finalCrop = crop;
435 return NO_ERROR;
436}
437
Dan Stoza7dde5992015-05-22 09:51:44 -0700438status_t Composer::deferTransactionUntil(
439 const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
440 const sp<IBinder>& handle, uint64_t frameNumber) {
441 Mutex::Autolock lock(mLock);
442 layer_state_t* s = getLayerStateLocked(client, id);
443 if (!s) {
444 return BAD_INDEX;
445 }
446 s->what |= layer_state_t::eDeferTransaction;
Robert Carr0d480722017-01-10 16:42:54 -0800447 s->barrierHandle = handle;
448 s->frameNumber = frameNumber;
449 return NO_ERROR;
450}
451
452status_t Composer::deferTransactionUntil(
453 const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
454 const sp<Surface>& barrierSurface, uint64_t frameNumber) {
455 Mutex::Autolock lock(mLock);
456 layer_state_t* s = getLayerStateLocked(client, id);
457 if (!s) {
458 return BAD_INDEX;
459 }
460 s->what |= layer_state_t::eDeferTransaction;
461 s->barrierGbp = barrierSurface->getIGraphicBufferProducer();
Dan Stoza7dde5992015-05-22 09:51:44 -0700462 s->frameNumber = frameNumber;
463 return NO_ERROR;
464}
465
Robert Carr1db73f62016-12-21 12:58:51 -0800466status_t Composer::reparentChildren(
467 const sp<SurfaceComposerClient>& client,
468 const sp<IBinder>& id,
469 const sp<IBinder>& newParentHandle) {
470 Mutex::Autolock lock(mLock);
471 layer_state_t* s = getLayerStateLocked(client, id);
472 if (!s) {
473 return BAD_INDEX;
474 }
475 s->what |= layer_state_t::eReparentChildren;
476 s->reparentHandle = newParentHandle;
477 return NO_ERROR;
478}
479
Robert Carr9524cb32017-02-13 11:32:32 -0800480status_t Composer::detachChildren(
481 const sp<SurfaceComposerClient>& client,
482 const sp<IBinder>& id) {
483 Mutex::Autolock lock(mLock);
484 layer_state_t* s = getLayerStateLocked(client, id);
485 if (!s) {
486 return BAD_INDEX;
487 }
488 s->what |= layer_state_t::eDetachChildren;
489 return NO_ERROR;
490}
491
Robert Carrc3574f72016-03-24 12:19:32 -0700492status_t Composer::setOverrideScalingMode(
493 const sp<SurfaceComposerClient>& client,
494 const sp<IBinder>& id, int32_t overrideScalingMode) {
495 Mutex::Autolock lock(mLock);
496 layer_state_t* s = getLayerStateLocked(client, id);
497 if (!s) {
498 return BAD_INDEX;
499 }
500
501 switch (overrideScalingMode) {
502 case NATIVE_WINDOW_SCALING_MODE_FREEZE:
503 case NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW:
504 case NATIVE_WINDOW_SCALING_MODE_SCALE_CROP:
505 case NATIVE_WINDOW_SCALING_MODE_NO_SCALE_CROP:
506 case -1:
507 break;
508 default:
509 ALOGE("unknown scaling mode: %d",
510 overrideScalingMode);
511 return BAD_VALUE;
512 }
513
514 s->what |= layer_state_t::eOverrideScalingModeChanged;
515 s->overrideScalingMode = overrideScalingMode;
516 return NO_ERROR;
517}
518
Robert Carr99e27f02016-06-16 15:18:02 -0700519status_t Composer::setGeometryAppliesWithResize(
Robert Carr82364e32016-05-15 11:27:47 -0700520 const sp<SurfaceComposerClient>& client,
521 const sp<IBinder>& id) {
522 Mutex::Autolock lock(mLock);
523 layer_state_t* s = getLayerStateLocked(client, id);
524 if (!s) {
525 return BAD_INDEX;
526 }
Robert Carr99e27f02016-06-16 15:18:02 -0700527 s->what |= layer_state_t::eGeometryAppliesWithResize;
Robert Carr82364e32016-05-15 11:27:47 -0700528 return NO_ERROR;
529}
530
Mathias Agopian698c0872011-06-28 19:09:31 -0700531// ---------------------------------------------------------------------------
532
Mathias Agopiane57f2922012-08-09 16:29:12 -0700533DisplayState& Composer::getDisplayStateLocked(const sp<IBinder>& token) {
534 DisplayState s;
535 s.token = token;
536 ssize_t index = mDisplayStates.indexOf(s);
537 if (index < 0) {
538 // we don't have it, add an initialized layer_state to our list
539 s.what = 0;
540 index = mDisplayStates.add(s);
541 }
Dan Stozad723bd72014-11-18 10:24:03 -0800542 return mDisplayStates.editItemAt(static_cast<size_t>(index));
Mathias Agopiane57f2922012-08-09 16:29:12 -0700543}
544
Pablo Ceballos1aad24c2016-08-04 10:24:22 -0700545status_t Composer::setDisplaySurface(const sp<IBinder>& token,
546 sp<IGraphicBufferProducer> bufferProducer) {
Pablo Ceballoseddbef82016-09-01 11:21:21 -0700547 if (bufferProducer.get() != nullptr) {
548 // Make sure that composition can never be stalled by a virtual display
549 // consumer that isn't processing buffers fast enough.
550 status_t err = bufferProducer->setAsyncMode(true);
551 if (err != NO_ERROR) {
552 ALOGE("Composer::setDisplaySurface Failed to enable async mode on the "
553 "BufferQueue. This BufferQueue cannot be used for virtual "
554 "display. (%d)", err);
555 return err;
556 }
Pablo Ceballos1aad24c2016-08-04 10:24:22 -0700557 }
Mathias Agopiane57f2922012-08-09 16:29:12 -0700558 Mutex::Autolock _l(mLock);
559 DisplayState& s(getDisplayStateLocked(token));
Andy McFadden2adaf042012-12-18 09:49:45 -0800560 s.surface = bufferProducer;
Mathias Agopiane57f2922012-08-09 16:29:12 -0700561 s.what |= DisplayState::eSurfaceChanged;
Pablo Ceballos1aad24c2016-08-04 10:24:22 -0700562 return NO_ERROR;
Mathias Agopiane57f2922012-08-09 16:29:12 -0700563}
564
565void Composer::setDisplayLayerStack(const sp<IBinder>& token,
566 uint32_t layerStack) {
567 Mutex::Autolock _l(mLock);
568 DisplayState& s(getDisplayStateLocked(token));
569 s.layerStack = layerStack;
570 s.what |= DisplayState::eLayerStackChanged;
571}
572
Mathias Agopian00e8c7a2012-09-04 19:30:46 -0700573void Composer::setDisplayProjection(const sp<IBinder>& token,
574 uint32_t orientation,
575 const Rect& layerStackRect,
576 const Rect& displayRect) {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700577 Mutex::Autolock _l(mLock);
578 DisplayState& s(getDisplayStateLocked(token));
579 s.orientation = orientation;
Mathias Agopian00e8c7a2012-09-04 19:30:46 -0700580 s.viewport = layerStackRect;
581 s.frame = displayRect;
582 s.what |= DisplayState::eDisplayProjectionChanged;
Jorim Jaggi092123c2016-04-13 01:40:35 +0000583 mForceSynchronous = true; // TODO: do we actually still need this?
Mathias Agopiane57f2922012-08-09 16:29:12 -0700584}
585
Michael Wright1f6078a2014-06-26 16:01:02 -0700586void Composer::setDisplaySize(const sp<IBinder>& token, uint32_t width, uint32_t height) {
587 Mutex::Autolock _l(mLock);
588 DisplayState& s(getDisplayStateLocked(token));
589 s.width = width;
590 s.height = height;
591 s.what |= DisplayState::eDisplaySizeChanged;
592}
593
Mathias Agopiane57f2922012-08-09 16:29:12 -0700594// ---------------------------------------------------------------------------
595
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800596SurfaceComposerClient::SurfaceComposerClient()
Mathias Agopian698c0872011-06-28 19:09:31 -0700597 : mStatus(NO_INIT), mComposer(Composer::getInstance())
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800598{
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800599}
600
Robert Carr1db73f62016-12-21 12:58:51 -0800601SurfaceComposerClient::SurfaceComposerClient(const sp<IGraphicBufferProducer>& root)
602 : mStatus(NO_INIT), mComposer(Composer::getInstance()), mParent(root)
603{
604}
605
Mathias Agopian698c0872011-06-28 19:09:31 -0700606void SurfaceComposerClient::onFirstRef() {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700607 sp<ISurfaceComposer> sm(ComposerService::getComposerService());
Mathias Agopiand4784a32010-05-27 19:41:15 -0700608 if (sm != 0) {
Robert Carr1db73f62016-12-21 12:58:51 -0800609 auto rootProducer = mParent.promote();
610 sp<ISurfaceComposerClient> conn;
611 conn = (rootProducer != nullptr) ? sm->createScopedConnection(rootProducer) :
612 sm->createConnection();
Mathias Agopiand4784a32010-05-27 19:41:15 -0700613 if (conn != 0) {
614 mClient = conn;
Mathias Agopiand4784a32010-05-27 19:41:15 -0700615 mStatus = NO_ERROR;
616 }
617 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800618}
619
Mathias Agopian698c0872011-06-28 19:09:31 -0700620SurfaceComposerClient::~SurfaceComposerClient() {
Mathias Agopian631f3582010-05-25 17:51:34 -0700621 dispose();
622}
Mathias Agopiandd3423c2009-09-23 15:44:05 -0700623
Mathias Agopian698c0872011-06-28 19:09:31 -0700624status_t SurfaceComposerClient::initCheck() const {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800625 return mStatus;
626}
627
Mathias Agopian698c0872011-06-28 19:09:31 -0700628sp<IBinder> SurfaceComposerClient::connection() const {
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800629 return IInterface::asBinder(mClient);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800630}
631
Mathias Agopiand4784a32010-05-27 19:41:15 -0700632status_t SurfaceComposerClient::linkToComposerDeath(
633 const sp<IBinder::DeathRecipient>& recipient,
Mathias Agopian698c0872011-06-28 19:09:31 -0700634 void* cookie, uint32_t flags) {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700635 sp<ISurfaceComposer> sm(ComposerService::getComposerService());
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800636 return IInterface::asBinder(sm)->linkToDeath(recipient, cookie, flags);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800637}
638
Mathias Agopian698c0872011-06-28 19:09:31 -0700639void SurfaceComposerClient::dispose() {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800640 // this can be called more than once.
Mathias Agopian7e27f052010-05-28 14:22:23 -0700641 sp<ISurfaceComposerClient> client;
Mathias Agopiand4784a32010-05-27 19:41:15 -0700642 Mutex::Autolock _lm(mLock);
643 if (mClient != 0) {
Mathias Agopiand4784a32010-05-27 19:41:15 -0700644 client = mClient; // hold ref while lock is held
645 mClient.clear();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800646 }
Mathias Agopiand4784a32010-05-27 19:41:15 -0700647 mStatus = NO_INIT;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800648}
649
Mathias Agopian698c0872011-06-28 19:09:31 -0700650sp<SurfaceControl> SurfaceComposerClient::createSurface(
Mathias Agopian698c0872011-06-28 19:09:31 -0700651 const String8& name,
Mathias Agopian698c0872011-06-28 19:09:31 -0700652 uint32_t w,
653 uint32_t h,
654 PixelFormat format,
Robert Carr1f0a16a2016-10-24 16:27:39 -0700655 uint32_t flags,
Albert Chaulk479c60c2017-01-27 14:21:34 -0500656 SurfaceControl* parent,
657 uint32_t windowType,
658 uint32_t ownerUid)
Mathias Agopian698c0872011-06-28 19:09:31 -0700659{
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700660 sp<SurfaceControl> sur;
Mathias Agopian698c0872011-06-28 19:09:31 -0700661 if (mStatus == NO_ERROR) {
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700662 sp<IBinder> handle;
Robert Carr1f0a16a2016-10-24 16:27:39 -0700663 sp<IBinder> parentHandle;
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700664 sp<IGraphicBufferProducer> gbp;
Robert Carr1f0a16a2016-10-24 16:27:39 -0700665
666 if (parent != nullptr) {
667 parentHandle = parent->getHandle();
668 }
669 status_t err = mClient->createSurface(name, w, h, format, flags, parentHandle,
Albert Chaulk479c60c2017-01-27 14:21:34 -0500670 windowType, ownerUid, &handle, &gbp);
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700671 ALOGE_IF(err, "SurfaceComposerClient::createSurface error %s", strerror(-err));
672 if (err == NO_ERROR) {
673 sur = new SurfaceControl(this, handle, gbp);
Mathias Agopian698c0872011-06-28 19:09:31 -0700674 }
675 }
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700676 return sur;
Mathias Agopian698c0872011-06-28 19:09:31 -0700677}
678
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700679sp<IBinder> SurfaceComposerClient::createDisplay(const String8& displayName,
680 bool secure) {
681 return Composer::getInstance().createDisplay(displayName, secure);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700682}
683
Jesse Hall6c913be2013-08-08 12:15:49 -0700684void SurfaceComposerClient::destroyDisplay(const sp<IBinder>& display) {
685 Composer::getInstance().destroyDisplay(display);
686}
687
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700688sp<IBinder> SurfaceComposerClient::getBuiltInDisplay(int32_t id) {
689 return Composer::getInstance().getBuiltInDisplay(id);
690}
691
Mathias Agopianac9fa422013-02-11 16:40:36 -0800692status_t SurfaceComposerClient::destroySurface(const sp<IBinder>& sid) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700693 if (mStatus != NO_ERROR)
694 return mStatus;
695 status_t err = mClient->destroySurface(sid);
696 return err;
697}
698
Svetoslavd85084b2014-03-20 10:28:31 -0700699status_t SurfaceComposerClient::clearLayerFrameStats(const sp<IBinder>& token) const {
700 if (mStatus != NO_ERROR) {
701 return mStatus;
702 }
703 return mClient->clearLayerFrameStats(token);
704}
705
706status_t SurfaceComposerClient::getLayerFrameStats(const sp<IBinder>& token,
707 FrameStats* outStats) const {
708 if (mStatus != NO_ERROR) {
709 return mStatus;
710 }
711 return mClient->getLayerFrameStats(token, outStats);
712}
713
Robert Carr367c5682016-06-20 11:55:28 -0700714status_t SurfaceComposerClient::getTransformToDisplayInverse(const sp<IBinder>& token,
715 bool* outTransformToDisplayInverse) const {
716 if (mStatus != NO_ERROR) {
717 return mStatus;
718 }
719 return mClient->getTransformToDisplayInverse(token, outTransformToDisplayInverse);
720}
721
Mathias Agopian698c0872011-06-28 19:09:31 -0700722inline Composer& SurfaceComposerClient::getComposer() {
723 return mComposer;
724}
725
726// ----------------------------------------------------------------------------
727
728void SurfaceComposerClient::openGlobalTransaction() {
Jeff Brownf3f7db62012-08-31 02:18:38 -0700729 Composer::openGlobalTransaction();
Mathias Agopian698c0872011-06-28 19:09:31 -0700730}
731
Jamie Gennis28378392011-10-12 17:39:00 -0700732void SurfaceComposerClient::closeGlobalTransaction(bool synchronous) {
733 Composer::closeGlobalTransaction(synchronous);
Mathias Agopian698c0872011-06-28 19:09:31 -0700734}
735
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700736void SurfaceComposerClient::setAnimationTransaction() {
737 Composer::setAnimationTransaction();
738}
739
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -0700740status_t SurfaceComposerClient::enableVSyncInjections(bool enable) {
741 return Composer::enableVSyncInjections(enable);
742}
743
744status_t SurfaceComposerClient::injectVSync(nsecs_t when) {
745 return Composer::injectVSync(when);
746}
747
Mathias Agopian698c0872011-06-28 19:09:31 -0700748// ----------------------------------------------------------------------------
749
Mathias Agopianac9fa422013-02-11 16:40:36 -0800750status_t SurfaceComposerClient::setCrop(const sp<IBinder>& id, const Rect& crop) {
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700751 return getComposer().setCrop(this, id, crop);
752}
753
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000754status_t SurfaceComposerClient::setFinalCrop(const sp<IBinder>& id,
755 const Rect& crop) {
756 return getComposer().setFinalCrop(this, id, crop);
757}
758
Mathias Agopianac9fa422013-02-11 16:40:36 -0800759status_t SurfaceComposerClient::setPosition(const sp<IBinder>& id, float x, float y) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700760 return getComposer().setPosition(this, id, x, y);
761}
762
Mathias Agopianac9fa422013-02-11 16:40:36 -0800763status_t SurfaceComposerClient::setSize(const sp<IBinder>& id, uint32_t w, uint32_t h) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700764 return getComposer().setSize(this, id, w, h);
765}
766
Robert Carrae060832016-11-28 10:51:00 -0800767status_t SurfaceComposerClient::setLayer(const sp<IBinder>& id, int32_t z) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700768 return getComposer().setLayer(this, id, z);
769}
770
Mathias Agopianac9fa422013-02-11 16:40:36 -0800771status_t SurfaceComposerClient::hide(const sp<IBinder>& id) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700772 return getComposer().setFlags(this, id,
Mathias Agopian3165cc22012-08-08 19:42:09 -0700773 layer_state_t::eLayerHidden,
774 layer_state_t::eLayerHidden);
Mathias Agopian698c0872011-06-28 19:09:31 -0700775}
776
Mathias Agopianac9fa422013-02-11 16:40:36 -0800777status_t SurfaceComposerClient::show(const sp<IBinder>& id) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700778 return getComposer().setFlags(this, id,
779 0,
Mathias Agopian3165cc22012-08-08 19:42:09 -0700780 layer_state_t::eLayerHidden);
Mathias Agopian698c0872011-06-28 19:09:31 -0700781}
782
Mathias Agopianac9fa422013-02-11 16:40:36 -0800783status_t SurfaceComposerClient::setFlags(const sp<IBinder>& id, uint32_t flags,
Mathias Agopian698c0872011-06-28 19:09:31 -0700784 uint32_t mask) {
785 return getComposer().setFlags(this, id, flags, mask);
786}
787
Mathias Agopianac9fa422013-02-11 16:40:36 -0800788status_t SurfaceComposerClient::setTransparentRegionHint(const sp<IBinder>& id,
Mathias Agopian698c0872011-06-28 19:09:31 -0700789 const Region& transparentRegion) {
790 return getComposer().setTransparentRegionHint(this, id, transparentRegion);
791}
792
Mathias Agopianac9fa422013-02-11 16:40:36 -0800793status_t SurfaceComposerClient::setAlpha(const sp<IBinder>& id, float alpha) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700794 return getComposer().setAlpha(this, id, alpha);
795}
796
Mathias Agopianac9fa422013-02-11 16:40:36 -0800797status_t SurfaceComposerClient::setLayerStack(const sp<IBinder>& id, uint32_t layerStack) {
Mathias Agopian87855782012-07-24 21:41:09 -0700798 return getComposer().setLayerStack(this, id, layerStack);
799}
800
Mathias Agopianac9fa422013-02-11 16:40:36 -0800801status_t SurfaceComposerClient::setMatrix(const sp<IBinder>& id, float dsdx, float dtdx,
Robert Carrcb6e1e32017-02-21 19:48:26 -0800802 float dtdy, float dsdy) {
803 return getComposer().setMatrix(this, id, dsdx, dtdx, dtdy, dsdy);
Mathias Agopian698c0872011-06-28 19:09:31 -0700804}
805
Dan Stoza7dde5992015-05-22 09:51:44 -0700806status_t SurfaceComposerClient::deferTransactionUntil(const sp<IBinder>& id,
807 const sp<IBinder>& handle, uint64_t frameNumber) {
808 return getComposer().deferTransactionUntil(this, id, handle, frameNumber);
809}
810
Robert Carr0d480722017-01-10 16:42:54 -0800811status_t SurfaceComposerClient::deferTransactionUntil(const sp<IBinder>& id,
812 const sp<Surface>& barrierSurface, uint64_t frameNumber) {
813 return getComposer().deferTransactionUntil(this, id, barrierSurface, frameNumber);
814}
815
Robert Carr1db73f62016-12-21 12:58:51 -0800816status_t SurfaceComposerClient::reparentChildren(const sp<IBinder>& id,
817 const sp<IBinder>& newParentHandle) {
818 return getComposer().reparentChildren(this, id, newParentHandle);
819}
820
Robert Carr9524cb32017-02-13 11:32:32 -0800821status_t SurfaceComposerClient::detachChildren(const sp<IBinder>& id) {
822 return getComposer().detachChildren(this, id);
823}
824
Robert Carrc3574f72016-03-24 12:19:32 -0700825status_t SurfaceComposerClient::setOverrideScalingMode(
826 const sp<IBinder>& id, int32_t overrideScalingMode) {
827 return getComposer().setOverrideScalingMode(
828 this, id, overrideScalingMode);
829}
830
Robert Carr99e27f02016-06-16 15:18:02 -0700831status_t SurfaceComposerClient::setGeometryAppliesWithResize(
Robert Carr82364e32016-05-15 11:27:47 -0700832 const sp<IBinder>& id) {
Robert Carr99e27f02016-06-16 15:18:02 -0700833 return getComposer().setGeometryAppliesWithResize(this, id);
Robert Carr82364e32016-05-15 11:27:47 -0700834}
835
Mathias Agopian698c0872011-06-28 19:09:31 -0700836// ----------------------------------------------------------------------------
837
Pablo Ceballos1aad24c2016-08-04 10:24:22 -0700838status_t SurfaceComposerClient::setDisplaySurface(const sp<IBinder>& token,
839 sp<IGraphicBufferProducer> bufferProducer) {
840 return Composer::getInstance().setDisplaySurface(token, bufferProducer);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700841}
842
843void SurfaceComposerClient::setDisplayLayerStack(const sp<IBinder>& token,
844 uint32_t layerStack) {
845 Composer::getInstance().setDisplayLayerStack(token, layerStack);
846}
847
Mathias Agopian00e8c7a2012-09-04 19:30:46 -0700848void SurfaceComposerClient::setDisplayProjection(const sp<IBinder>& token,
849 uint32_t orientation,
850 const Rect& layerStackRect,
851 const Rect& displayRect) {
852 Composer::getInstance().setDisplayProjection(token, orientation,
853 layerStackRect, displayRect);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700854}
855
Michael Wright1f6078a2014-06-26 16:01:02 -0700856void SurfaceComposerClient::setDisplaySize(const sp<IBinder>& token,
857 uint32_t width, uint32_t height) {
858 Composer::getInstance().setDisplaySize(token, width, height);
859}
860
Mathias Agopiane57f2922012-08-09 16:29:12 -0700861// ----------------------------------------------------------------------------
862
Dan Stoza7f7da322014-05-02 15:26:25 -0700863status_t SurfaceComposerClient::getDisplayConfigs(
864 const sp<IBinder>& display, Vector<DisplayInfo>* configs)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800865{
Dan Stoza7f7da322014-05-02 15:26:25 -0700866 return ComposerService::getComposerService()->getDisplayConfigs(display, configs);
867}
868
869status_t SurfaceComposerClient::getDisplayInfo(const sp<IBinder>& display,
870 DisplayInfo* info) {
871 Vector<DisplayInfo> configs;
872 status_t result = getDisplayConfigs(display, &configs);
873 if (result != NO_ERROR) {
874 return result;
875 }
876
877 int activeId = getActiveConfig(display);
878 if (activeId < 0) {
879 ALOGE("No active configuration found");
880 return NAME_NOT_FOUND;
881 }
882
Dan Stozad723bd72014-11-18 10:24:03 -0800883 *info = configs[static_cast<size_t>(activeId)];
Dan Stoza7f7da322014-05-02 15:26:25 -0700884 return NO_ERROR;
885}
886
887int SurfaceComposerClient::getActiveConfig(const sp<IBinder>& display) {
888 return ComposerService::getComposerService()->getActiveConfig(display);
889}
890
891status_t SurfaceComposerClient::setActiveConfig(const sp<IBinder>& display, int id) {
892 return ComposerService::getComposerService()->setActiveConfig(display, id);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800893}
894
Michael Wright28f24d02016-07-12 13:30:53 -0700895status_t SurfaceComposerClient::getDisplayColorModes(const sp<IBinder>& display,
896 Vector<android_color_mode_t>* outColorModes) {
897 return ComposerService::getComposerService()->getDisplayColorModes(display, outColorModes);
898}
899
900android_color_mode_t SurfaceComposerClient::getActiveColorMode(const sp<IBinder>& display) {
901 return ComposerService::getComposerService()->getActiveColorMode(display);
902}
903
904status_t SurfaceComposerClient::setActiveColorMode(const sp<IBinder>& display,
905 android_color_mode_t colorMode) {
906 return ComposerService::getComposerService()->setActiveColorMode(display, colorMode);
907}
908
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700909void SurfaceComposerClient::setDisplayPowerMode(const sp<IBinder>& token,
910 int mode) {
911 ComposerService::getComposerService()->setPowerMode(token, mode);
Jeff Brown2a09bb32012-10-08 19:13:57 -0700912}
913
Svetoslavd85084b2014-03-20 10:28:31 -0700914status_t SurfaceComposerClient::clearAnimationFrameStats() {
915 return ComposerService::getComposerService()->clearAnimationFrameStats();
916}
917
918status_t SurfaceComposerClient::getAnimationFrameStats(FrameStats* outStats) {
919 return ComposerService::getComposerService()->getAnimationFrameStats(outStats);
920}
921
Dan Stozac4f471e2016-03-24 09:31:08 -0700922status_t SurfaceComposerClient::getHdrCapabilities(const sp<IBinder>& display,
923 HdrCapabilities* outCapabilities) {
924 return ComposerService::getComposerService()->getHdrCapabilities(display,
925 outCapabilities);
926}
927
Mathias Agopian698c0872011-06-28 19:09:31 -0700928// ----------------------------------------------------------------------------
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800929
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800930status_t ScreenshotClient::capture(
931 const sp<IBinder>& display,
932 const sp<IGraphicBufferProducer>& producer,
Dan Stozac1879002014-05-22 15:59:05 -0700933 Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
Robert Carrae060832016-11-28 10:51:00 -0800934 int32_t minLayerZ, int32_t maxLayerZ, bool useIdentityTransform) {
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800935 sp<ISurfaceComposer> s(ComposerService::getComposerService());
936 if (s == NULL) return NO_INIT;
Dan Stozac1879002014-05-22 15:59:05 -0700937 return s->captureScreen(display, producer, sourceCrop,
Dan Stozac7014012014-02-14 15:03:43 -0800938 reqWidth, reqHeight, minLayerZ, maxLayerZ, useIdentityTransform);
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800939}
940
Robert Carr673134e2017-01-09 19:48:38 -0800941status_t ScreenshotClient::captureToBuffer(const sp<IBinder>& display,
942 Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
Robert Carrae060832016-11-28 10:51:00 -0800943 int32_t minLayerZ, int32_t maxLayerZ, bool useIdentityTransform,
Robert Carr673134e2017-01-09 19:48:38 -0800944 uint32_t rotation,
945 sp<GraphicBuffer>* outBuffer) {
946 sp<ISurfaceComposer> s(ComposerService::getComposerService());
947 if (s == NULL) return NO_INIT;
948
949 sp<IGraphicBufferConsumer> gbpConsumer;
950 sp<IGraphicBufferProducer> producer;
951 BufferQueue::createBufferQueue(&producer, &gbpConsumer);
952 sp<BufferItemConsumer> consumer(new BufferItemConsumer(gbpConsumer,
953 GRALLOC_USAGE_HW_TEXTURE | GRALLOC_USAGE_SW_READ_NEVER | GRALLOC_USAGE_SW_WRITE_NEVER,
954 1, true));
955
956 status_t ret = s->captureScreen(display, producer, sourceCrop, reqWidth, reqHeight,
957 minLayerZ, maxLayerZ, useIdentityTransform,
958 static_cast<ISurfaceComposer::Rotation>(rotation));
959 if (ret != NO_ERROR) {
960 return ret;
961 }
962 BufferItem b;
963 consumer->acquireBuffer(&b, 0, true);
964 *outBuffer = b.mGraphicBuffer;
965 return ret;
966}
967
Mathias Agopian74c40c02010-09-29 13:02:36 -0700968ScreenshotClient::ScreenshotClient()
Mathias Agopianabe815d2013-03-19 22:22:21 -0700969 : mHaveBuffer(false) {
970 memset(&mBuffer, 0, sizeof(mBuffer));
Mathias Agopian74c40c02010-09-29 13:02:36 -0700971}
972
Mathias Agopian8000d062013-03-26 18:15:35 -0700973ScreenshotClient::~ScreenshotClient() {
974 ScreenshotClient::release();
975}
976
Mathias Agopianabe815d2013-03-19 22:22:21 -0700977sp<CpuConsumer> ScreenshotClient::getCpuConsumer() const {
978 if (mCpuConsumer == NULL) {
Dan Stoza6d5a7bb2014-03-13 11:39:09 -0700979 sp<IGraphicBufferConsumer> consumer;
980 BufferQueue::createBufferQueue(&mProducer, &consumer);
981 mCpuConsumer = new CpuConsumer(consumer, 1);
Mathias Agopianabe815d2013-03-19 22:22:21 -0700982 mCpuConsumer->setName(String8("ScreenshotClient"));
983 }
984 return mCpuConsumer;
Mathias Agopianbf2c6a62010-12-10 16:22:31 -0800985}
986
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700987status_t ScreenshotClient::update(const sp<IBinder>& display,
Dan Stozac1879002014-05-22 15:59:05 -0700988 Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
Robert Carrae060832016-11-28 10:51:00 -0800989 int32_t minLayerZ, int32_t maxLayerZ,
Riley Andrewsd15ef272014-09-04 16:19:44 -0700990 bool useIdentityTransform, uint32_t rotation) {
Mathias Agopianbf2c6a62010-12-10 16:22:31 -0800991 sp<ISurfaceComposer> s(ComposerService::getComposerService());
992 if (s == NULL) return NO_INIT;
Mathias Agopianabe815d2013-03-19 22:22:21 -0700993 sp<CpuConsumer> cpuConsumer = getCpuConsumer();
994
995 if (mHaveBuffer) {
996 mCpuConsumer->unlockBuffer(mBuffer);
997 memset(&mBuffer, 0, sizeof(mBuffer));
998 mHaveBuffer = false;
999 }
1000
Dan Stozac1879002014-05-22 15:59:05 -07001001 status_t err = s->captureScreen(display, mProducer, sourceCrop,
Riley Andrewsd15ef272014-09-04 16:19:44 -07001002 reqWidth, reqHeight, minLayerZ, maxLayerZ, useIdentityTransform,
1003 static_cast<ISurfaceComposer::Rotation>(rotation));
Mathias Agopianabe815d2013-03-19 22:22:21 -07001004
1005 if (err == NO_ERROR) {
1006 err = mCpuConsumer->lockNextBuffer(&mBuffer);
1007 if (err == NO_ERROR) {
1008 mHaveBuffer = true;
1009 }
1010 }
1011 return err;
1012}
1013
Riley Andrewsd15ef272014-09-04 16:19:44 -07001014status_t ScreenshotClient::update(const sp<IBinder>& display,
1015 Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
Robert Carrae060832016-11-28 10:51:00 -08001016 int32_t minLayerZ, int32_t maxLayerZ,
Riley Andrewsd15ef272014-09-04 16:19:44 -07001017 bool useIdentityTransform) {
1018
1019 return ScreenshotClient::update(display, sourceCrop, reqWidth, reqHeight,
1020 minLayerZ, maxLayerZ, useIdentityTransform, ISurfaceComposer::eRotateNone);
1021}
1022
Dan Stozac1879002014-05-22 15:59:05 -07001023status_t ScreenshotClient::update(const sp<IBinder>& display, Rect sourceCrop,
Dan Stozac7014012014-02-14 15:03:43 -08001024 bool useIdentityTransform) {
Robert Carrae060832016-11-28 10:51:00 -08001025 return ScreenshotClient::update(display, sourceCrop, 0, 0,
1026 INT32_MIN, INT32_MAX,
Riley Andrewsd15ef272014-09-04 16:19:44 -07001027 useIdentityTransform, ISurfaceComposer::eRotateNone);
Mathias Agopianabe815d2013-03-19 22:22:21 -07001028}
1029
Dan Stozac1879002014-05-22 15:59:05 -07001030status_t ScreenshotClient::update(const sp<IBinder>& display, Rect sourceCrop,
Dan Stozac7014012014-02-14 15:03:43 -08001031 uint32_t reqWidth, uint32_t reqHeight, bool useIdentityTransform) {
Dan Stozac1879002014-05-22 15:59:05 -07001032 return ScreenshotClient::update(display, sourceCrop, reqWidth, reqHeight,
Robert Carrae060832016-11-28 10:51:00 -08001033 INT32_MIN, INT32_MAX,
1034 useIdentityTransform, ISurfaceComposer::eRotateNone);
Mathias Agopian74c40c02010-09-29 13:02:36 -07001035}
1036
1037void ScreenshotClient::release() {
Mathias Agopianabe815d2013-03-19 22:22:21 -07001038 if (mHaveBuffer) {
1039 mCpuConsumer->unlockBuffer(mBuffer);
1040 memset(&mBuffer, 0, sizeof(mBuffer));
1041 mHaveBuffer = false;
1042 }
1043 mCpuConsumer.clear();
Mathias Agopian74c40c02010-09-29 13:02:36 -07001044}
1045
1046void const* ScreenshotClient::getPixels() const {
Mathias Agopianabe815d2013-03-19 22:22:21 -07001047 return mBuffer.data;
Mathias Agopian74c40c02010-09-29 13:02:36 -07001048}
1049
1050uint32_t ScreenshotClient::getWidth() const {
Mathias Agopianabe815d2013-03-19 22:22:21 -07001051 return mBuffer.width;
Mathias Agopian74c40c02010-09-29 13:02:36 -07001052}
1053
1054uint32_t ScreenshotClient::getHeight() const {
Mathias Agopianabe815d2013-03-19 22:22:21 -07001055 return mBuffer.height;
Mathias Agopian74c40c02010-09-29 13:02:36 -07001056}
1057
1058PixelFormat ScreenshotClient::getFormat() const {
Mathias Agopianabe815d2013-03-19 22:22:21 -07001059 return mBuffer.format;
Mathias Agopian74c40c02010-09-29 13:02:36 -07001060}
1061
1062uint32_t ScreenshotClient::getStride() const {
Mathias Agopianabe815d2013-03-19 22:22:21 -07001063 return mBuffer.stride;
Mathias Agopian74c40c02010-09-29 13:02:36 -07001064}
1065
1066size_t ScreenshotClient::getSize() const {
Mathias Agopianabe815d2013-03-19 22:22:21 -07001067 return mBuffer.stride * mBuffer.height * bytesPerPixel(mBuffer.format);
Mathias Agopian74c40c02010-09-29 13:02:36 -07001068}
1069
1070// ----------------------------------------------------------------------------
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001071}; // namespace android