blob: ece07a33fb78d79d4cb335fc841edd83f7bb202d [file] [log] [blame]
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#define LOG_TAG "SurfaceComposerClient"
18
19#include <stdint.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080020#include <sys/types.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080021
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080022#include <utils/Errors.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080023#include <utils/Log.h>
Mathias Agopiand4784a32010-05-27 19:41:15 -070024#include <utils/Singleton.h>
Mathias Agopiana67932f2011-04-20 14:20:59 -070025#include <utils/SortedVector.h>
26#include <utils/String8.h>
27#include <utils/threads.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080028
Mathias Agopian9cce3252010-02-09 17:46:37 -080029#include <binder/IMemory.h>
Mathias Agopiana67932f2011-04-20 14:20:59 -070030#include <binder/IServiceManager.h>
Mathias Agopian9cce3252010-02-09 17:46:37 -080031
Michael Wright28f24d02016-07-12 13:30:53 -070032#include <system/graphics.h>
33
Mathias Agopian076b1cc2009-04-10 14:24:30 -070034#include <ui/DisplayInfo.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080035
Robert Carr673134e2017-01-09 19:48:38 -080036#include <gui/BufferItemConsumer.h>
Mathias Agopianabe815d2013-03-19 22:22:21 -070037#include <gui/CpuConsumer.h>
Mathias Agopiane3c697f2013-02-14 17:11:02 -080038#include <gui/IGraphicBufferProducer.h>
Mathias Agopian90ac7992012-02-25 18:48:35 -080039#include <gui/ISurfaceComposer.h>
40#include <gui/ISurfaceComposerClient.h>
41#include <gui/SurfaceComposerClient.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080042
Mathias Agopian41f673c2011-11-17 17:48:35 -080043#include <private/gui/ComposerService.h>
Mathias Agopian90ac7992012-02-25 18:48:35 -080044#include <private/gui/LayerState.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080045
46namespace android {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080047// ---------------------------------------------------------------------------
48
Mathias Agopian7e27f052010-05-28 14:22:23 -070049ANDROID_SINGLETON_STATIC_INSTANCE(ComposerService);
50
Mathias Agopianb7e930d2010-06-01 15:12:58 -070051ComposerService::ComposerService()
52: Singleton<ComposerService>() {
Andy McFadden6652b3e2012-09-06 18:45:56 -070053 Mutex::Autolock _l(mLock);
54 connectLocked();
55}
56
57void ComposerService::connectLocked() {
Mathias Agopianb7e930d2010-06-01 15:12:58 -070058 const String16 name("SurfaceFlinger");
59 while (getService(name, &mComposerService) != NO_ERROR) {
60 usleep(250000);
61 }
Andy McFadden6652b3e2012-09-06 18:45:56 -070062 assert(mComposerService != NULL);
63
64 // Create the death listener.
65 class DeathObserver : public IBinder::DeathRecipient {
66 ComposerService& mComposerService;
67 virtual void binderDied(const wp<IBinder>& who) {
68 ALOGW("ComposerService remote (surfaceflinger) died [%p]",
69 who.unsafe_get());
70 mComposerService.composerServiceDied();
71 }
72 public:
Chih-Hung Hsiehe2347b72016-04-25 15:41:05 -070073 explicit DeathObserver(ComposerService& mgr) : mComposerService(mgr) { }
Andy McFadden6652b3e2012-09-06 18:45:56 -070074 };
75
76 mDeathObserver = new DeathObserver(*const_cast<ComposerService*>(this));
Marco Nelissen2ea926b2014-11-14 08:01:01 -080077 IInterface::asBinder(mComposerService)->linkToDeath(mDeathObserver);
Mathias Agopianb7e930d2010-06-01 15:12:58 -070078}
79
Andy McFadden6652b3e2012-09-06 18:45:56 -070080/*static*/ sp<ISurfaceComposer> ComposerService::getComposerService() {
81 ComposerService& instance = ComposerService::getInstance();
82 Mutex::Autolock _l(instance.mLock);
83 if (instance.mComposerService == NULL) {
84 ComposerService::getInstance().connectLocked();
85 assert(instance.mComposerService != NULL);
86 ALOGD("ComposerService reconnected");
87 }
88 return instance.mComposerService;
89}
90
91void ComposerService::composerServiceDied()
92{
93 Mutex::Autolock _l(mLock);
94 mComposerService = NULL;
95 mDeathObserver = NULL;
Mathias Agopianb7e930d2010-06-01 15:12:58 -070096}
97
Mathias Agopian7e27f052010-05-28 14:22:23 -070098// ---------------------------------------------------------------------------
99
Mathias Agopian698c0872011-06-28 19:09:31 -0700100static inline
Mathias Agopiane57f2922012-08-09 16:29:12 -0700101int compare_type(const ComposerState& lhs, const ComposerState& rhs) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700102 if (lhs.client < rhs.client) return -1;
103 if (lhs.client > rhs.client) return 1;
104 if (lhs.state.surface < rhs.state.surface) return -1;
105 if (lhs.state.surface > rhs.state.surface) return 1;
106 return 0;
107}
108
Mathias Agopiane57f2922012-08-09 16:29:12 -0700109static inline
110int compare_type(const DisplayState& lhs, const DisplayState& rhs) {
111 return compare_type(lhs.token, rhs.token);
112}
113
Mathias Agopian7e27f052010-05-28 14:22:23 -0700114class Composer : public Singleton<Composer>
115{
Mathias Agopiand4784a32010-05-27 19:41:15 -0700116 friend class Singleton<Composer>;
117
Mathias Agopian698c0872011-06-28 19:09:31 -0700118 mutable Mutex mLock;
Mathias Agopiane57f2922012-08-09 16:29:12 -0700119 SortedVector<ComposerState> mComposerStates;
120 SortedVector<DisplayState > mDisplayStates;
Jamie Gennis28378392011-10-12 17:39:00 -0700121 uint32_t mForceSynchronous;
Jeff Brownf3f7db62012-08-31 02:18:38 -0700122 uint32_t mTransactionNestCount;
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700123 bool mAnimation;
Mathias Agopian698c0872011-06-28 19:09:31 -0700124
Jamie Gennisb8d69a52011-10-10 15:48:06 -0700125 Composer() : Singleton<Composer>(),
Jeff Brownf3f7db62012-08-31 02:18:38 -0700126 mForceSynchronous(0), mTransactionNestCount(0),
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700127 mAnimation(false)
Jamie Gennis28378392011-10-12 17:39:00 -0700128 { }
Mathias Agopian698c0872011-06-28 19:09:31 -0700129
Jeff Brownf3f7db62012-08-31 02:18:38 -0700130 void openGlobalTransactionImpl();
Jamie Gennis28378392011-10-12 17:39:00 -0700131 void closeGlobalTransactionImpl(bool synchronous);
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700132 void setAnimationTransactionImpl();
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -0700133 status_t enableVSyncInjectionsImpl(bool enable);
134 status_t injectVSyncImpl(nsecs_t when);
Mathias Agopian698c0872011-06-28 19:09:31 -0700135
136 layer_state_t* getLayerStateLocked(
Mathias Agopianac9fa422013-02-11 16:40:36 -0800137 const sp<SurfaceComposerClient>& client, const sp<IBinder>& id);
Mathias Agopian698c0872011-06-28 19:09:31 -0700138
Mathias Agopiane57f2922012-08-09 16:29:12 -0700139 DisplayState& getDisplayStateLocked(const sp<IBinder>& token);
140
Mathias Agopiand4784a32010-05-27 19:41:15 -0700141public:
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700142 sp<IBinder> createDisplay(const String8& displayName, bool secure);
Jesse Hall6c913be2013-08-08 12:15:49 -0700143 void destroyDisplay(const sp<IBinder>& display);
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700144 sp<IBinder> getBuiltInDisplay(int32_t id);
Mathias Agopian698c0872011-06-28 19:09:31 -0700145
Mathias Agopianac9fa422013-02-11 16:40:36 -0800146 status_t setPosition(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
Mathias Agopian41b6aab2011-08-30 18:51:54 -0700147 float x, float y);
Mathias Agopianac9fa422013-02-11 16:40:36 -0800148 status_t setSize(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
Mathias Agopian698c0872011-06-28 19:09:31 -0700149 uint32_t w, uint32_t h);
Mathias Agopianac9fa422013-02-11 16:40:36 -0800150 status_t setLayer(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
Robert Carrae060832016-11-28 10:51:00 -0800151 int32_t z);
Albert Chaulk6cf6af02016-11-22 13:52:43 -0500152 status_t setLayerInfo(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
153 uint32_t type, uint32_t appid);
Mathias Agopianac9fa422013-02-11 16:40:36 -0800154 status_t setFlags(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
Mathias Agopian698c0872011-06-28 19:09:31 -0700155 uint32_t flags, uint32_t mask);
156 status_t setTransparentRegionHint(
Mathias Agopianac9fa422013-02-11 16:40:36 -0800157 const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
Mathias Agopian698c0872011-06-28 19:09:31 -0700158 const Region& transparentRegion);
Mathias Agopianac9fa422013-02-11 16:40:36 -0800159 status_t setAlpha(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
Mathias Agopian698c0872011-06-28 19:09:31 -0700160 float alpha);
Mathias Agopianac9fa422013-02-11 16:40:36 -0800161 status_t setMatrix(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
Mathias Agopian698c0872011-06-28 19:09:31 -0700162 float dsdx, float dtdx, float dsdy, float dtdy);
Jamie Gennisb8d69a52011-10-10 15:48:06 -0700163 status_t setOrientation(int orientation);
Mathias Agopianac9fa422013-02-11 16:40:36 -0800164 status_t setCrop(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700165 const Rect& crop);
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000166 status_t setFinalCrop(const sp<SurfaceComposerClient>& client,
167 const sp<IBinder>& id, const Rect& crop);
Mathias Agopian87855782012-07-24 21:41:09 -0700168 status_t setLayerStack(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-11 16:40:36 -0800169 const sp<IBinder>& id, uint32_t layerStack);
Dan Stoza7dde5992015-05-22 09:51:44 -0700170 status_t deferTransactionUntil(const sp<SurfaceComposerClient>& client,
171 const sp<IBinder>& id, const sp<IBinder>& handle,
172 uint64_t frameNumber);
Robert Carr1db73f62016-12-21 12:58:51 -0800173 status_t reparentChildren(const sp<SurfaceComposerClient>& client,
174 const sp<IBinder>& id,
175 const sp<IBinder>& newParentHandle);
Robert Carrc3574f72016-03-24 12:19:32 -0700176 status_t setOverrideScalingMode(const sp<SurfaceComposerClient>& client,
177 const sp<IBinder>& id, int32_t overrideScalingMode);
Robert Carr99e27f02016-06-16 15:18:02 -0700178 status_t setGeometryAppliesWithResize(const sp<SurfaceComposerClient>& client,
Robert Carr82364e32016-05-15 11:27:47 -0700179 const sp<IBinder>& id);
Mathias Agopian698c0872011-06-28 19:09:31 -0700180
Pablo Ceballos1aad24c2016-08-04 10:24:22 -0700181 status_t setDisplaySurface(const sp<IBinder>& token,
182 sp<IGraphicBufferProducer> bufferProducer);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700183 void setDisplayLayerStack(const sp<IBinder>& token, uint32_t layerStack);
Mathias Agopian00e8c7a2012-09-04 19:30:46 -0700184 void setDisplayProjection(const sp<IBinder>& token,
185 uint32_t orientation,
186 const Rect& layerStackRect,
187 const Rect& displayRect);
Michael Wright1f6078a2014-06-26 16:01:02 -0700188 void setDisplaySize(const sp<IBinder>& token, uint32_t width, uint32_t height);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700189
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700190 static void setAnimationTransaction() {
191 Composer::getInstance().setAnimationTransactionImpl();
192 }
193
Jeff Brownf3f7db62012-08-31 02:18:38 -0700194 static void openGlobalTransaction() {
195 Composer::getInstance().openGlobalTransactionImpl();
196 }
197
Jamie Gennis28378392011-10-12 17:39:00 -0700198 static void closeGlobalTransaction(bool synchronous) {
199 Composer::getInstance().closeGlobalTransactionImpl(synchronous);
Mathias Agopiand4784a32010-05-27 19:41:15 -0700200 }
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -0700201
202 static status_t enableVSyncInjections(bool enable) {
203 return Composer::getInstance().enableVSyncInjectionsImpl(enable);
204 }
205
206 static status_t injectVSync(nsecs_t when) {
207 return Composer::getInstance().injectVSyncImpl(when);
208 }
Mathias Agopiand4784a32010-05-27 19:41:15 -0700209};
210
211ANDROID_SINGLETON_STATIC_INSTANCE(Composer);
212
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800213// ---------------------------------------------------------------------------
214
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700215sp<IBinder> Composer::createDisplay(const String8& displayName, bool secure) {
216 return ComposerService::getComposerService()->createDisplay(displayName,
217 secure);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700218}
219
Jesse Hall6c913be2013-08-08 12:15:49 -0700220void Composer::destroyDisplay(const sp<IBinder>& display) {
221 return ComposerService::getComposerService()->destroyDisplay(display);
222}
223
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700224sp<IBinder> Composer::getBuiltInDisplay(int32_t id) {
225 return ComposerService::getComposerService()->getBuiltInDisplay(id);
226}
227
Jeff Brownf3f7db62012-08-31 02:18:38 -0700228void Composer::openGlobalTransactionImpl() {
229 { // scope for the lock
230 Mutex::Autolock _l(mLock);
231 mTransactionNestCount += 1;
232 }
233}
234
Jamie Gennis28378392011-10-12 17:39:00 -0700235void Composer::closeGlobalTransactionImpl(bool synchronous) {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700236 sp<ISurfaceComposer> sm(ComposerService::getComposerService());
Mathias Agopian698c0872011-06-28 19:09:31 -0700237
238 Vector<ComposerState> transaction;
Mathias Agopian8b33f032012-07-24 20:43:54 -0700239 Vector<DisplayState> displayTransaction;
Jamie Gennis28378392011-10-12 17:39:00 -0700240 uint32_t flags = 0;
Mathias Agopian698c0872011-06-28 19:09:31 -0700241
242 { // scope for the lock
243 Mutex::Autolock _l(mLock);
Jeff Brownf3f7db62012-08-31 02:18:38 -0700244 mForceSynchronous |= synchronous;
245 if (!mTransactionNestCount) {
246 ALOGW("At least one call to closeGlobalTransaction() was not matched by a prior "
247 "call to openGlobalTransaction().");
248 } else if (--mTransactionNestCount) {
249 return;
250 }
251
Mathias Agopiane57f2922012-08-09 16:29:12 -0700252 transaction = mComposerStates;
253 mComposerStates.clear();
Jamie Gennisb8d69a52011-10-10 15:48:06 -0700254
Mathias Agopiane57f2922012-08-09 16:29:12 -0700255 displayTransaction = mDisplayStates;
256 mDisplayStates.clear();
Jamie Gennis28378392011-10-12 17:39:00 -0700257
Jeff Brownf3f7db62012-08-31 02:18:38 -0700258 if (mForceSynchronous) {
Jamie Gennis28378392011-10-12 17:39:00 -0700259 flags |= ISurfaceComposer::eSynchronous;
260 }
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700261 if (mAnimation) {
262 flags |= ISurfaceComposer::eAnimation;
263 }
264
Jamie Gennis28378392011-10-12 17:39:00 -0700265 mForceSynchronous = false;
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700266 mAnimation = false;
Mathias Agopian698c0872011-06-28 19:09:31 -0700267 }
268
Mathias Agopian8b33f032012-07-24 20:43:54 -0700269 sm->setTransactionState(transaction, displayTransaction, flags);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800270}
271
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -0700272status_t Composer::enableVSyncInjectionsImpl(bool enable) {
273 sp<ISurfaceComposer> sm(ComposerService::getComposerService());
274 return sm->enableVSyncInjections(enable);
275}
276
277status_t Composer::injectVSyncImpl(nsecs_t when) {
278 sp<ISurfaceComposer> sm(ComposerService::getComposerService());
279 return sm->injectVSync(when);
280}
281
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700282void Composer::setAnimationTransactionImpl() {
283 Mutex::Autolock _l(mLock);
284 mAnimation = true;
285}
286
Mathias Agopian698c0872011-06-28 19:09:31 -0700287layer_state_t* Composer::getLayerStateLocked(
Mathias Agopianac9fa422013-02-11 16:40:36 -0800288 const sp<SurfaceComposerClient>& client, const sp<IBinder>& id) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700289
290 ComposerState s;
291 s.client = client->mClient;
292 s.state.surface = id;
293
Mathias Agopiane57f2922012-08-09 16:29:12 -0700294 ssize_t index = mComposerStates.indexOf(s);
Mathias Agopian698c0872011-06-28 19:09:31 -0700295 if (index < 0) {
296 // we don't have it, add an initialized layer_state to our list
Mathias Agopiane57f2922012-08-09 16:29:12 -0700297 index = mComposerStates.add(s);
Mathias Agopian698c0872011-06-28 19:09:31 -0700298 }
299
Mathias Agopiane57f2922012-08-09 16:29:12 -0700300 ComposerState* const out = mComposerStates.editArray();
Mathias Agopian698c0872011-06-28 19:09:31 -0700301 return &(out[index].state);
302}
303
304status_t Composer::setPosition(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-11 16:40:36 -0800305 const sp<IBinder>& id, float x, float y) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700306 Mutex::Autolock _l(mLock);
307 layer_state_t* s = getLayerStateLocked(client, id);
308 if (!s)
309 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700310 s->what |= layer_state_t::ePositionChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700311 s->x = x;
312 s->y = y;
313 return NO_ERROR;
314}
315
316status_t Composer::setSize(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-11 16:40:36 -0800317 const sp<IBinder>& id, uint32_t w, uint32_t h) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700318 Mutex::Autolock _l(mLock);
319 layer_state_t* s = getLayerStateLocked(client, id);
320 if (!s)
321 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700322 s->what |= layer_state_t::eSizeChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700323 s->w = w;
324 s->h = h;
Jamie Gennis28378392011-10-12 17:39:00 -0700325
Jorim Jaggi092123c2016-04-13 01:40:35 +0000326 // Resizing a surface makes the transaction synchronous.
327 mForceSynchronous = true;
328
Mathias Agopian698c0872011-06-28 19:09:31 -0700329 return NO_ERROR;
330}
331
332status_t Composer::setLayer(const sp<SurfaceComposerClient>& client,
Robert Carrae060832016-11-28 10:51:00 -0800333 const sp<IBinder>& id, int32_t z) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700334 Mutex::Autolock _l(mLock);
335 layer_state_t* s = getLayerStateLocked(client, id);
336 if (!s)
337 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700338 s->what |= layer_state_t::eLayerChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700339 s->z = z;
340 return NO_ERROR;
341}
342
Albert Chaulk6cf6af02016-11-22 13:52:43 -0500343status_t Composer::setLayerInfo(const sp<SurfaceComposerClient>& client,
344 const sp<IBinder>& id, uint32_t type, uint32_t appid) {
345 Mutex::Autolock _l(mLock);
346 layer_state_t* s = getLayerStateLocked(client, id);
347 if (!s)
348 return BAD_INDEX;
349 s->what |= layer_state_t::eLayerInfoChanged;
350 s->type = type;
351 s->appid = appid;
352 return NO_ERROR;
353}
354
Mathias Agopian698c0872011-06-28 19:09:31 -0700355status_t Composer::setFlags(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-11 16:40:36 -0800356 const sp<IBinder>& id, uint32_t flags,
Mathias Agopian698c0872011-06-28 19:09:31 -0700357 uint32_t mask) {
358 Mutex::Autolock _l(mLock);
359 layer_state_t* s = getLayerStateLocked(client, id);
360 if (!s)
361 return BAD_INDEX;
Pablo Ceballos53390e12015-08-04 11:25:59 -0700362 if ((mask & layer_state_t::eLayerOpaque) ||
363 (mask & layer_state_t::eLayerHidden) ||
364 (mask & layer_state_t::eLayerSecure)) {
Dan Stoza23116082015-06-18 14:58:39 -0700365 s->what |= layer_state_t::eFlagsChanged;
Andy McFadden4125a4f2014-01-29 17:17:11 -0800366 }
Mathias Agopian698c0872011-06-28 19:09:31 -0700367 s->flags &= ~mask;
368 s->flags |= (flags & mask);
369 s->mask |= mask;
370 return NO_ERROR;
371}
372
373status_t Composer::setTransparentRegionHint(
Mathias Agopianac9fa422013-02-11 16:40:36 -0800374 const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
Mathias Agopian698c0872011-06-28 19:09:31 -0700375 const Region& transparentRegion) {
376 Mutex::Autolock _l(mLock);
377 layer_state_t* s = getLayerStateLocked(client, id);
378 if (!s)
379 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700380 s->what |= layer_state_t::eTransparentRegionChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700381 s->transparentRegion = transparentRegion;
382 return NO_ERROR;
383}
384
385status_t Composer::setAlpha(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-11 16:40:36 -0800386 const sp<IBinder>& id, float alpha) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700387 Mutex::Autolock _l(mLock);
388 layer_state_t* s = getLayerStateLocked(client, id);
389 if (!s)
390 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700391 s->what |= layer_state_t::eAlphaChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700392 s->alpha = alpha;
393 return NO_ERROR;
394}
395
Mathias Agopian87855782012-07-24 21:41:09 -0700396status_t Composer::setLayerStack(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-11 16:40:36 -0800397 const sp<IBinder>& id, uint32_t layerStack) {
Mathias Agopian87855782012-07-24 21:41:09 -0700398 Mutex::Autolock _l(mLock);
399 layer_state_t* s = getLayerStateLocked(client, id);
400 if (!s)
401 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700402 s->what |= layer_state_t::eLayerStackChanged;
Mathias Agopian87855782012-07-24 21:41:09 -0700403 s->layerStack = layerStack;
404 return NO_ERROR;
405}
406
Mathias Agopian698c0872011-06-28 19:09:31 -0700407status_t Composer::setMatrix(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-11 16:40:36 -0800408 const sp<IBinder>& id, float dsdx, float dtdx,
Mathias Agopian698c0872011-06-28 19:09:31 -0700409 float dsdy, float dtdy) {
410 Mutex::Autolock _l(mLock);
411 layer_state_t* s = getLayerStateLocked(client, id);
412 if (!s)
413 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700414 s->what |= layer_state_t::eMatrixChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700415 layer_state_t::matrix22_t matrix;
416 matrix.dsdx = dsdx;
417 matrix.dtdx = dtdx;
418 matrix.dsdy = dsdy;
419 matrix.dtdy = dtdy;
420 s->matrix = matrix;
421 return NO_ERROR;
422}
423
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700424status_t Composer::setCrop(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-11 16:40:36 -0800425 const sp<IBinder>& id, const Rect& crop) {
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700426 Mutex::Autolock _l(mLock);
427 layer_state_t* s = getLayerStateLocked(client, id);
428 if (!s)
429 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700430 s->what |= layer_state_t::eCropChanged;
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700431 s->crop = crop;
432 return NO_ERROR;
433}
434
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000435status_t Composer::setFinalCrop(const sp<SurfaceComposerClient>& client,
436 const sp<IBinder>& id, const Rect& crop) {
437 Mutex::Autolock _l(mLock);
438 layer_state_t* s = getLayerStateLocked(client, id);
439 if (!s) {
440 return BAD_INDEX;
441 }
442 s->what |= layer_state_t::eFinalCropChanged;
443 s->finalCrop = crop;
444 return NO_ERROR;
445}
446
Dan Stoza7dde5992015-05-22 09:51:44 -0700447status_t Composer::deferTransactionUntil(
448 const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
449 const sp<IBinder>& handle, uint64_t frameNumber) {
450 Mutex::Autolock lock(mLock);
451 layer_state_t* s = getLayerStateLocked(client, id);
452 if (!s) {
453 return BAD_INDEX;
454 }
455 s->what |= layer_state_t::eDeferTransaction;
456 s->handle = handle;
457 s->frameNumber = frameNumber;
458 return NO_ERROR;
459}
460
Robert Carr1db73f62016-12-21 12:58:51 -0800461status_t Composer::reparentChildren(
462 const sp<SurfaceComposerClient>& client,
463 const sp<IBinder>& id,
464 const sp<IBinder>& newParentHandle) {
465 Mutex::Autolock lock(mLock);
466 layer_state_t* s = getLayerStateLocked(client, id);
467 if (!s) {
468 return BAD_INDEX;
469 }
470 s->what |= layer_state_t::eReparentChildren;
471 s->reparentHandle = newParentHandle;
472 return NO_ERROR;
473}
474
Robert Carrc3574f72016-03-24 12:19:32 -0700475status_t Composer::setOverrideScalingMode(
476 const sp<SurfaceComposerClient>& client,
477 const sp<IBinder>& id, int32_t overrideScalingMode) {
478 Mutex::Autolock lock(mLock);
479 layer_state_t* s = getLayerStateLocked(client, id);
480 if (!s) {
481 return BAD_INDEX;
482 }
483
484 switch (overrideScalingMode) {
485 case NATIVE_WINDOW_SCALING_MODE_FREEZE:
486 case NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW:
487 case NATIVE_WINDOW_SCALING_MODE_SCALE_CROP:
488 case NATIVE_WINDOW_SCALING_MODE_NO_SCALE_CROP:
489 case -1:
490 break;
491 default:
492 ALOGE("unknown scaling mode: %d",
493 overrideScalingMode);
494 return BAD_VALUE;
495 }
496
497 s->what |= layer_state_t::eOverrideScalingModeChanged;
498 s->overrideScalingMode = overrideScalingMode;
499 return NO_ERROR;
500}
501
Robert Carr99e27f02016-06-16 15:18:02 -0700502status_t Composer::setGeometryAppliesWithResize(
Robert Carr82364e32016-05-15 11:27:47 -0700503 const sp<SurfaceComposerClient>& client,
504 const sp<IBinder>& id) {
505 Mutex::Autolock lock(mLock);
506 layer_state_t* s = getLayerStateLocked(client, id);
507 if (!s) {
508 return BAD_INDEX;
509 }
Robert Carr99e27f02016-06-16 15:18:02 -0700510 s->what |= layer_state_t::eGeometryAppliesWithResize;
Robert Carr82364e32016-05-15 11:27:47 -0700511 return NO_ERROR;
512}
513
Mathias Agopian698c0872011-06-28 19:09:31 -0700514// ---------------------------------------------------------------------------
515
Mathias Agopiane57f2922012-08-09 16:29:12 -0700516DisplayState& Composer::getDisplayStateLocked(const sp<IBinder>& token) {
517 DisplayState s;
518 s.token = token;
519 ssize_t index = mDisplayStates.indexOf(s);
520 if (index < 0) {
521 // we don't have it, add an initialized layer_state to our list
522 s.what = 0;
523 index = mDisplayStates.add(s);
524 }
Dan Stozad723bd72014-11-18 10:24:03 -0800525 return mDisplayStates.editItemAt(static_cast<size_t>(index));
Mathias Agopiane57f2922012-08-09 16:29:12 -0700526}
527
Pablo Ceballos1aad24c2016-08-04 10:24:22 -0700528status_t Composer::setDisplaySurface(const sp<IBinder>& token,
529 sp<IGraphicBufferProducer> bufferProducer) {
Pablo Ceballoseddbef82016-09-01 11:21:21 -0700530 if (bufferProducer.get() != nullptr) {
531 // Make sure that composition can never be stalled by a virtual display
532 // consumer that isn't processing buffers fast enough.
533 status_t err = bufferProducer->setAsyncMode(true);
534 if (err != NO_ERROR) {
535 ALOGE("Composer::setDisplaySurface Failed to enable async mode on the "
536 "BufferQueue. This BufferQueue cannot be used for virtual "
537 "display. (%d)", err);
538 return err;
539 }
Pablo Ceballos1aad24c2016-08-04 10:24:22 -0700540 }
Mathias Agopiane57f2922012-08-09 16:29:12 -0700541 Mutex::Autolock _l(mLock);
542 DisplayState& s(getDisplayStateLocked(token));
Andy McFadden2adaf042012-12-18 09:49:45 -0800543 s.surface = bufferProducer;
Mathias Agopiane57f2922012-08-09 16:29:12 -0700544 s.what |= DisplayState::eSurfaceChanged;
Pablo Ceballos1aad24c2016-08-04 10:24:22 -0700545 return NO_ERROR;
Mathias Agopiane57f2922012-08-09 16:29:12 -0700546}
547
548void Composer::setDisplayLayerStack(const sp<IBinder>& token,
549 uint32_t layerStack) {
550 Mutex::Autolock _l(mLock);
551 DisplayState& s(getDisplayStateLocked(token));
552 s.layerStack = layerStack;
553 s.what |= DisplayState::eLayerStackChanged;
554}
555
Mathias Agopian00e8c7a2012-09-04 19:30:46 -0700556void Composer::setDisplayProjection(const sp<IBinder>& token,
557 uint32_t orientation,
558 const Rect& layerStackRect,
559 const Rect& displayRect) {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700560 Mutex::Autolock _l(mLock);
561 DisplayState& s(getDisplayStateLocked(token));
562 s.orientation = orientation;
Mathias Agopian00e8c7a2012-09-04 19:30:46 -0700563 s.viewport = layerStackRect;
564 s.frame = displayRect;
565 s.what |= DisplayState::eDisplayProjectionChanged;
Jorim Jaggi092123c2016-04-13 01:40:35 +0000566 mForceSynchronous = true; // TODO: do we actually still need this?
Mathias Agopiane57f2922012-08-09 16:29:12 -0700567}
568
Michael Wright1f6078a2014-06-26 16:01:02 -0700569void Composer::setDisplaySize(const sp<IBinder>& token, uint32_t width, uint32_t height) {
570 Mutex::Autolock _l(mLock);
571 DisplayState& s(getDisplayStateLocked(token));
572 s.width = width;
573 s.height = height;
574 s.what |= DisplayState::eDisplaySizeChanged;
575}
576
Mathias Agopiane57f2922012-08-09 16:29:12 -0700577// ---------------------------------------------------------------------------
578
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800579SurfaceComposerClient::SurfaceComposerClient()
Mathias Agopian698c0872011-06-28 19:09:31 -0700580 : mStatus(NO_INIT), mComposer(Composer::getInstance())
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800581{
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800582}
583
Robert Carr1db73f62016-12-21 12:58:51 -0800584SurfaceComposerClient::SurfaceComposerClient(const sp<IGraphicBufferProducer>& root)
585 : mStatus(NO_INIT), mComposer(Composer::getInstance()), mParent(root)
586{
587}
588
Mathias Agopian698c0872011-06-28 19:09:31 -0700589void SurfaceComposerClient::onFirstRef() {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700590 sp<ISurfaceComposer> sm(ComposerService::getComposerService());
Mathias Agopiand4784a32010-05-27 19:41:15 -0700591 if (sm != 0) {
Robert Carr1db73f62016-12-21 12:58:51 -0800592 auto rootProducer = mParent.promote();
593 sp<ISurfaceComposerClient> conn;
594 conn = (rootProducer != nullptr) ? sm->createScopedConnection(rootProducer) :
595 sm->createConnection();
Mathias Agopiand4784a32010-05-27 19:41:15 -0700596 if (conn != 0) {
597 mClient = conn;
Mathias Agopiand4784a32010-05-27 19:41:15 -0700598 mStatus = NO_ERROR;
599 }
600 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800601}
602
Mathias Agopian698c0872011-06-28 19:09:31 -0700603SurfaceComposerClient::~SurfaceComposerClient() {
Mathias Agopian631f3582010-05-25 17:51:34 -0700604 dispose();
605}
Mathias Agopiandd3423c2009-09-23 15:44:05 -0700606
Mathias Agopian698c0872011-06-28 19:09:31 -0700607status_t SurfaceComposerClient::initCheck() const {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800608 return mStatus;
609}
610
Mathias Agopian698c0872011-06-28 19:09:31 -0700611sp<IBinder> SurfaceComposerClient::connection() const {
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800612 return IInterface::asBinder(mClient);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800613}
614
Mathias Agopiand4784a32010-05-27 19:41:15 -0700615status_t SurfaceComposerClient::linkToComposerDeath(
616 const sp<IBinder::DeathRecipient>& recipient,
Mathias Agopian698c0872011-06-28 19:09:31 -0700617 void* cookie, uint32_t flags) {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700618 sp<ISurfaceComposer> sm(ComposerService::getComposerService());
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800619 return IInterface::asBinder(sm)->linkToDeath(recipient, cookie, flags);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800620}
621
Mathias Agopian698c0872011-06-28 19:09:31 -0700622void SurfaceComposerClient::dispose() {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800623 // this can be called more than once.
Mathias Agopian7e27f052010-05-28 14:22:23 -0700624 sp<ISurfaceComposerClient> client;
Mathias Agopiand4784a32010-05-27 19:41:15 -0700625 Mutex::Autolock _lm(mLock);
626 if (mClient != 0) {
Mathias Agopiand4784a32010-05-27 19:41:15 -0700627 client = mClient; // hold ref while lock is held
628 mClient.clear();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800629 }
Mathias Agopiand4784a32010-05-27 19:41:15 -0700630 mStatus = NO_INIT;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800631}
632
Mathias Agopian698c0872011-06-28 19:09:31 -0700633sp<SurfaceControl> SurfaceComposerClient::createSurface(
Mathias Agopian698c0872011-06-28 19:09:31 -0700634 const String8& name,
Mathias Agopian698c0872011-06-28 19:09:31 -0700635 uint32_t w,
636 uint32_t h,
637 PixelFormat format,
Robert Carr1f0a16a2016-10-24 16:27:39 -0700638 uint32_t flags,
639 SurfaceControl* parent)
Mathias Agopian698c0872011-06-28 19:09:31 -0700640{
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700641 sp<SurfaceControl> sur;
Mathias Agopian698c0872011-06-28 19:09:31 -0700642 if (mStatus == NO_ERROR) {
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700643 sp<IBinder> handle;
Robert Carr1f0a16a2016-10-24 16:27:39 -0700644 sp<IBinder> parentHandle;
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700645 sp<IGraphicBufferProducer> gbp;
Robert Carr1f0a16a2016-10-24 16:27:39 -0700646
647 if (parent != nullptr) {
648 parentHandle = parent->getHandle();
649 }
650 status_t err = mClient->createSurface(name, w, h, format, flags, parentHandle,
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700651 &handle, &gbp);
652 ALOGE_IF(err, "SurfaceComposerClient::createSurface error %s", strerror(-err));
653 if (err == NO_ERROR) {
654 sur = new SurfaceControl(this, handle, gbp);
Mathias Agopian698c0872011-06-28 19:09:31 -0700655 }
656 }
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700657 return sur;
Mathias Agopian698c0872011-06-28 19:09:31 -0700658}
659
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700660sp<IBinder> SurfaceComposerClient::createDisplay(const String8& displayName,
661 bool secure) {
662 return Composer::getInstance().createDisplay(displayName, secure);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700663}
664
Jesse Hall6c913be2013-08-08 12:15:49 -0700665void SurfaceComposerClient::destroyDisplay(const sp<IBinder>& display) {
666 Composer::getInstance().destroyDisplay(display);
667}
668
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700669sp<IBinder> SurfaceComposerClient::getBuiltInDisplay(int32_t id) {
670 return Composer::getInstance().getBuiltInDisplay(id);
671}
672
Mathias Agopianac9fa422013-02-11 16:40:36 -0800673status_t SurfaceComposerClient::destroySurface(const sp<IBinder>& sid) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700674 if (mStatus != NO_ERROR)
675 return mStatus;
676 status_t err = mClient->destroySurface(sid);
677 return err;
678}
679
Svetoslavd85084b2014-03-20 10:28:31 -0700680status_t SurfaceComposerClient::clearLayerFrameStats(const sp<IBinder>& token) const {
681 if (mStatus != NO_ERROR) {
682 return mStatus;
683 }
684 return mClient->clearLayerFrameStats(token);
685}
686
687status_t SurfaceComposerClient::getLayerFrameStats(const sp<IBinder>& token,
688 FrameStats* outStats) const {
689 if (mStatus != NO_ERROR) {
690 return mStatus;
691 }
692 return mClient->getLayerFrameStats(token, outStats);
693}
694
Robert Carr367c5682016-06-20 11:55:28 -0700695status_t SurfaceComposerClient::getTransformToDisplayInverse(const sp<IBinder>& token,
696 bool* outTransformToDisplayInverse) const {
697 if (mStatus != NO_ERROR) {
698 return mStatus;
699 }
700 return mClient->getTransformToDisplayInverse(token, outTransformToDisplayInverse);
701}
702
Mathias Agopian698c0872011-06-28 19:09:31 -0700703inline Composer& SurfaceComposerClient::getComposer() {
704 return mComposer;
705}
706
707// ----------------------------------------------------------------------------
708
709void SurfaceComposerClient::openGlobalTransaction() {
Jeff Brownf3f7db62012-08-31 02:18:38 -0700710 Composer::openGlobalTransaction();
Mathias Agopian698c0872011-06-28 19:09:31 -0700711}
712
Jamie Gennis28378392011-10-12 17:39:00 -0700713void SurfaceComposerClient::closeGlobalTransaction(bool synchronous) {
714 Composer::closeGlobalTransaction(synchronous);
Mathias Agopian698c0872011-06-28 19:09:31 -0700715}
716
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700717void SurfaceComposerClient::setAnimationTransaction() {
718 Composer::setAnimationTransaction();
719}
720
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -0700721status_t SurfaceComposerClient::enableVSyncInjections(bool enable) {
722 return Composer::enableVSyncInjections(enable);
723}
724
725status_t SurfaceComposerClient::injectVSync(nsecs_t when) {
726 return Composer::injectVSync(when);
727}
728
Mathias Agopian698c0872011-06-28 19:09:31 -0700729// ----------------------------------------------------------------------------
730
Mathias Agopianac9fa422013-02-11 16:40:36 -0800731status_t SurfaceComposerClient::setCrop(const sp<IBinder>& id, const Rect& crop) {
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700732 return getComposer().setCrop(this, id, crop);
733}
734
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000735status_t SurfaceComposerClient::setFinalCrop(const sp<IBinder>& id,
736 const Rect& crop) {
737 return getComposer().setFinalCrop(this, id, crop);
738}
739
Mathias Agopianac9fa422013-02-11 16:40:36 -0800740status_t SurfaceComposerClient::setPosition(const sp<IBinder>& id, float x, float y) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700741 return getComposer().setPosition(this, id, x, y);
742}
743
Mathias Agopianac9fa422013-02-11 16:40:36 -0800744status_t SurfaceComposerClient::setSize(const sp<IBinder>& id, uint32_t w, uint32_t h) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700745 return getComposer().setSize(this, id, w, h);
746}
747
Robert Carrae060832016-11-28 10:51:00 -0800748status_t SurfaceComposerClient::setLayer(const sp<IBinder>& id, int32_t z) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700749 return getComposer().setLayer(this, id, z);
750}
751
Albert Chaulk6cf6af02016-11-22 13:52:43 -0500752status_t SurfaceComposerClient::setLayerInfo(const sp<IBinder>& id, uint32_t type, uint32_t appid) {
753 return getComposer().setLayerInfo(this, id, type, appid);
754}
755
Mathias Agopianac9fa422013-02-11 16:40:36 -0800756status_t SurfaceComposerClient::hide(const sp<IBinder>& id) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700757 return getComposer().setFlags(this, id,
Mathias Agopian3165cc22012-08-08 19:42:09 -0700758 layer_state_t::eLayerHidden,
759 layer_state_t::eLayerHidden);
Mathias Agopian698c0872011-06-28 19:09:31 -0700760}
761
Mathias Agopianac9fa422013-02-11 16:40:36 -0800762status_t SurfaceComposerClient::show(const sp<IBinder>& id) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700763 return getComposer().setFlags(this, id,
764 0,
Mathias Agopian3165cc22012-08-08 19:42:09 -0700765 layer_state_t::eLayerHidden);
Mathias Agopian698c0872011-06-28 19:09:31 -0700766}
767
Mathias Agopianac9fa422013-02-11 16:40:36 -0800768status_t SurfaceComposerClient::setFlags(const sp<IBinder>& id, uint32_t flags,
Mathias Agopian698c0872011-06-28 19:09:31 -0700769 uint32_t mask) {
770 return getComposer().setFlags(this, id, flags, mask);
771}
772
Mathias Agopianac9fa422013-02-11 16:40:36 -0800773status_t SurfaceComposerClient::setTransparentRegionHint(const sp<IBinder>& id,
Mathias Agopian698c0872011-06-28 19:09:31 -0700774 const Region& transparentRegion) {
775 return getComposer().setTransparentRegionHint(this, id, transparentRegion);
776}
777
Mathias Agopianac9fa422013-02-11 16:40:36 -0800778status_t SurfaceComposerClient::setAlpha(const sp<IBinder>& id, float alpha) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700779 return getComposer().setAlpha(this, id, alpha);
780}
781
Mathias Agopianac9fa422013-02-11 16:40:36 -0800782status_t SurfaceComposerClient::setLayerStack(const sp<IBinder>& id, uint32_t layerStack) {
Mathias Agopian87855782012-07-24 21:41:09 -0700783 return getComposer().setLayerStack(this, id, layerStack);
784}
785
Mathias Agopianac9fa422013-02-11 16:40:36 -0800786status_t SurfaceComposerClient::setMatrix(const sp<IBinder>& id, float dsdx, float dtdx,
Mathias Agopian698c0872011-06-28 19:09:31 -0700787 float dsdy, float dtdy) {
788 return getComposer().setMatrix(this, id, dsdx, dtdx, dsdy, dtdy);
789}
790
Dan Stoza7dde5992015-05-22 09:51:44 -0700791status_t SurfaceComposerClient::deferTransactionUntil(const sp<IBinder>& id,
792 const sp<IBinder>& handle, uint64_t frameNumber) {
793 return getComposer().deferTransactionUntil(this, id, handle, frameNumber);
794}
795
Robert Carr1db73f62016-12-21 12:58:51 -0800796status_t SurfaceComposerClient::reparentChildren(const sp<IBinder>& id,
797 const sp<IBinder>& newParentHandle) {
798 return getComposer().reparentChildren(this, id, newParentHandle);
799}
800
Robert Carrc3574f72016-03-24 12:19:32 -0700801status_t SurfaceComposerClient::setOverrideScalingMode(
802 const sp<IBinder>& id, int32_t overrideScalingMode) {
803 return getComposer().setOverrideScalingMode(
804 this, id, overrideScalingMode);
805}
806
Robert Carr99e27f02016-06-16 15:18:02 -0700807status_t SurfaceComposerClient::setGeometryAppliesWithResize(
Robert Carr82364e32016-05-15 11:27:47 -0700808 const sp<IBinder>& id) {
Robert Carr99e27f02016-06-16 15:18:02 -0700809 return getComposer().setGeometryAppliesWithResize(this, id);
Robert Carr82364e32016-05-15 11:27:47 -0700810}
811
Mathias Agopian698c0872011-06-28 19:09:31 -0700812// ----------------------------------------------------------------------------
813
Pablo Ceballos1aad24c2016-08-04 10:24:22 -0700814status_t SurfaceComposerClient::setDisplaySurface(const sp<IBinder>& token,
815 sp<IGraphicBufferProducer> bufferProducer) {
816 return Composer::getInstance().setDisplaySurface(token, bufferProducer);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700817}
818
819void SurfaceComposerClient::setDisplayLayerStack(const sp<IBinder>& token,
820 uint32_t layerStack) {
821 Composer::getInstance().setDisplayLayerStack(token, layerStack);
822}
823
Mathias Agopian00e8c7a2012-09-04 19:30:46 -0700824void SurfaceComposerClient::setDisplayProjection(const sp<IBinder>& token,
825 uint32_t orientation,
826 const Rect& layerStackRect,
827 const Rect& displayRect) {
828 Composer::getInstance().setDisplayProjection(token, orientation,
829 layerStackRect, displayRect);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700830}
831
Michael Wright1f6078a2014-06-26 16:01:02 -0700832void SurfaceComposerClient::setDisplaySize(const sp<IBinder>& token,
833 uint32_t width, uint32_t height) {
834 Composer::getInstance().setDisplaySize(token, width, height);
835}
836
Mathias Agopiane57f2922012-08-09 16:29:12 -0700837// ----------------------------------------------------------------------------
838
Dan Stoza7f7da322014-05-02 15:26:25 -0700839status_t SurfaceComposerClient::getDisplayConfigs(
840 const sp<IBinder>& display, Vector<DisplayInfo>* configs)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800841{
Dan Stoza7f7da322014-05-02 15:26:25 -0700842 return ComposerService::getComposerService()->getDisplayConfigs(display, configs);
843}
844
845status_t SurfaceComposerClient::getDisplayInfo(const sp<IBinder>& display,
846 DisplayInfo* info) {
847 Vector<DisplayInfo> configs;
848 status_t result = getDisplayConfigs(display, &configs);
849 if (result != NO_ERROR) {
850 return result;
851 }
852
853 int activeId = getActiveConfig(display);
854 if (activeId < 0) {
855 ALOGE("No active configuration found");
856 return NAME_NOT_FOUND;
857 }
858
Dan Stozad723bd72014-11-18 10:24:03 -0800859 *info = configs[static_cast<size_t>(activeId)];
Dan Stoza7f7da322014-05-02 15:26:25 -0700860 return NO_ERROR;
861}
862
863int SurfaceComposerClient::getActiveConfig(const sp<IBinder>& display) {
864 return ComposerService::getComposerService()->getActiveConfig(display);
865}
866
867status_t SurfaceComposerClient::setActiveConfig(const sp<IBinder>& display, int id) {
868 return ComposerService::getComposerService()->setActiveConfig(display, id);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800869}
870
Michael Wright28f24d02016-07-12 13:30:53 -0700871status_t SurfaceComposerClient::getDisplayColorModes(const sp<IBinder>& display,
872 Vector<android_color_mode_t>* outColorModes) {
873 return ComposerService::getComposerService()->getDisplayColorModes(display, outColorModes);
874}
875
876android_color_mode_t SurfaceComposerClient::getActiveColorMode(const sp<IBinder>& display) {
877 return ComposerService::getComposerService()->getActiveColorMode(display);
878}
879
880status_t SurfaceComposerClient::setActiveColorMode(const sp<IBinder>& display,
881 android_color_mode_t colorMode) {
882 return ComposerService::getComposerService()->setActiveColorMode(display, colorMode);
883}
884
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700885void SurfaceComposerClient::setDisplayPowerMode(const sp<IBinder>& token,
886 int mode) {
887 ComposerService::getComposerService()->setPowerMode(token, mode);
Jeff Brown2a09bb32012-10-08 19:13:57 -0700888}
889
Svetoslavd85084b2014-03-20 10:28:31 -0700890status_t SurfaceComposerClient::clearAnimationFrameStats() {
891 return ComposerService::getComposerService()->clearAnimationFrameStats();
892}
893
894status_t SurfaceComposerClient::getAnimationFrameStats(FrameStats* outStats) {
895 return ComposerService::getComposerService()->getAnimationFrameStats(outStats);
896}
897
Dan Stozac4f471e2016-03-24 09:31:08 -0700898status_t SurfaceComposerClient::getHdrCapabilities(const sp<IBinder>& display,
899 HdrCapabilities* outCapabilities) {
900 return ComposerService::getComposerService()->getHdrCapabilities(display,
901 outCapabilities);
902}
903
Mathias Agopian698c0872011-06-28 19:09:31 -0700904// ----------------------------------------------------------------------------
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800905
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800906status_t ScreenshotClient::capture(
907 const sp<IBinder>& display,
908 const sp<IGraphicBufferProducer>& producer,
Dan Stozac1879002014-05-22 15:59:05 -0700909 Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
Robert Carrae060832016-11-28 10:51:00 -0800910 int32_t minLayerZ, int32_t maxLayerZ, bool useIdentityTransform) {
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800911 sp<ISurfaceComposer> s(ComposerService::getComposerService());
912 if (s == NULL) return NO_INIT;
Dan Stozac1879002014-05-22 15:59:05 -0700913 return s->captureScreen(display, producer, sourceCrop,
Dan Stozac7014012014-02-14 15:03:43 -0800914 reqWidth, reqHeight, minLayerZ, maxLayerZ, useIdentityTransform);
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800915}
916
Robert Carr673134e2017-01-09 19:48:38 -0800917status_t ScreenshotClient::captureToBuffer(const sp<IBinder>& display,
918 Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
Robert Carrae060832016-11-28 10:51:00 -0800919 int32_t minLayerZ, int32_t maxLayerZ, bool useIdentityTransform,
Robert Carr673134e2017-01-09 19:48:38 -0800920 uint32_t rotation,
921 sp<GraphicBuffer>* outBuffer) {
922 sp<ISurfaceComposer> s(ComposerService::getComposerService());
923 if (s == NULL) return NO_INIT;
924
925 sp<IGraphicBufferConsumer> gbpConsumer;
926 sp<IGraphicBufferProducer> producer;
927 BufferQueue::createBufferQueue(&producer, &gbpConsumer);
928 sp<BufferItemConsumer> consumer(new BufferItemConsumer(gbpConsumer,
929 GRALLOC_USAGE_HW_TEXTURE | GRALLOC_USAGE_SW_READ_NEVER | GRALLOC_USAGE_SW_WRITE_NEVER,
930 1, true));
931
932 status_t ret = s->captureScreen(display, producer, sourceCrop, reqWidth, reqHeight,
933 minLayerZ, maxLayerZ, useIdentityTransform,
934 static_cast<ISurfaceComposer::Rotation>(rotation));
935 if (ret != NO_ERROR) {
936 return ret;
937 }
938 BufferItem b;
939 consumer->acquireBuffer(&b, 0, true);
940 *outBuffer = b.mGraphicBuffer;
941 return ret;
942}
943
Mathias Agopian74c40c02010-09-29 13:02:36 -0700944ScreenshotClient::ScreenshotClient()
Mathias Agopianabe815d2013-03-19 22:22:21 -0700945 : mHaveBuffer(false) {
946 memset(&mBuffer, 0, sizeof(mBuffer));
Mathias Agopian74c40c02010-09-29 13:02:36 -0700947}
948
Mathias Agopian8000d062013-03-26 18:15:35 -0700949ScreenshotClient::~ScreenshotClient() {
950 ScreenshotClient::release();
951}
952
Mathias Agopianabe815d2013-03-19 22:22:21 -0700953sp<CpuConsumer> ScreenshotClient::getCpuConsumer() const {
954 if (mCpuConsumer == NULL) {
Dan Stoza6d5a7bb2014-03-13 11:39:09 -0700955 sp<IGraphicBufferConsumer> consumer;
956 BufferQueue::createBufferQueue(&mProducer, &consumer);
957 mCpuConsumer = new CpuConsumer(consumer, 1);
Mathias Agopianabe815d2013-03-19 22:22:21 -0700958 mCpuConsumer->setName(String8("ScreenshotClient"));
959 }
960 return mCpuConsumer;
Mathias Agopianbf2c6a62010-12-10 16:22:31 -0800961}
962
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700963status_t ScreenshotClient::update(const sp<IBinder>& display,
Dan Stozac1879002014-05-22 15:59:05 -0700964 Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
Robert Carrae060832016-11-28 10:51:00 -0800965 int32_t minLayerZ, int32_t maxLayerZ,
Riley Andrewsd15ef272014-09-04 16:19:44 -0700966 bool useIdentityTransform, uint32_t rotation) {
Mathias Agopianbf2c6a62010-12-10 16:22:31 -0800967 sp<ISurfaceComposer> s(ComposerService::getComposerService());
968 if (s == NULL) return NO_INIT;
Mathias Agopianabe815d2013-03-19 22:22:21 -0700969 sp<CpuConsumer> cpuConsumer = getCpuConsumer();
970
971 if (mHaveBuffer) {
972 mCpuConsumer->unlockBuffer(mBuffer);
973 memset(&mBuffer, 0, sizeof(mBuffer));
974 mHaveBuffer = false;
975 }
976
Dan Stozac1879002014-05-22 15:59:05 -0700977 status_t err = s->captureScreen(display, mProducer, sourceCrop,
Riley Andrewsd15ef272014-09-04 16:19:44 -0700978 reqWidth, reqHeight, minLayerZ, maxLayerZ, useIdentityTransform,
979 static_cast<ISurfaceComposer::Rotation>(rotation));
Mathias Agopianabe815d2013-03-19 22:22:21 -0700980
981 if (err == NO_ERROR) {
982 err = mCpuConsumer->lockNextBuffer(&mBuffer);
983 if (err == NO_ERROR) {
984 mHaveBuffer = true;
985 }
986 }
987 return err;
988}
989
Riley Andrewsd15ef272014-09-04 16:19:44 -0700990status_t ScreenshotClient::update(const sp<IBinder>& display,
991 Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
Robert Carrae060832016-11-28 10:51:00 -0800992 int32_t minLayerZ, int32_t maxLayerZ,
Riley Andrewsd15ef272014-09-04 16:19:44 -0700993 bool useIdentityTransform) {
994
995 return ScreenshotClient::update(display, sourceCrop, reqWidth, reqHeight,
996 minLayerZ, maxLayerZ, useIdentityTransform, ISurfaceComposer::eRotateNone);
997}
998
Dan Stozac1879002014-05-22 15:59:05 -0700999status_t ScreenshotClient::update(const sp<IBinder>& display, Rect sourceCrop,
Dan Stozac7014012014-02-14 15:03:43 -08001000 bool useIdentityTransform) {
Robert Carrae060832016-11-28 10:51:00 -08001001 return ScreenshotClient::update(display, sourceCrop, 0, 0,
1002 INT32_MIN, INT32_MAX,
Riley Andrewsd15ef272014-09-04 16:19:44 -07001003 useIdentityTransform, ISurfaceComposer::eRotateNone);
Mathias Agopianabe815d2013-03-19 22:22:21 -07001004}
1005
Dan Stozac1879002014-05-22 15:59:05 -07001006status_t ScreenshotClient::update(const sp<IBinder>& display, Rect sourceCrop,
Dan Stozac7014012014-02-14 15:03:43 -08001007 uint32_t reqWidth, uint32_t reqHeight, bool useIdentityTransform) {
Dan Stozac1879002014-05-22 15:59:05 -07001008 return ScreenshotClient::update(display, sourceCrop, reqWidth, reqHeight,
Robert Carrae060832016-11-28 10:51:00 -08001009 INT32_MIN, INT32_MAX,
1010 useIdentityTransform, ISurfaceComposer::eRotateNone);
Mathias Agopian74c40c02010-09-29 13:02:36 -07001011}
1012
1013void ScreenshotClient::release() {
Mathias Agopianabe815d2013-03-19 22:22:21 -07001014 if (mHaveBuffer) {
1015 mCpuConsumer->unlockBuffer(mBuffer);
1016 memset(&mBuffer, 0, sizeof(mBuffer));
1017 mHaveBuffer = false;
1018 }
1019 mCpuConsumer.clear();
Mathias Agopian74c40c02010-09-29 13:02:36 -07001020}
1021
1022void const* ScreenshotClient::getPixels() const {
Mathias Agopianabe815d2013-03-19 22:22:21 -07001023 return mBuffer.data;
Mathias Agopian74c40c02010-09-29 13:02:36 -07001024}
1025
1026uint32_t ScreenshotClient::getWidth() const {
Mathias Agopianabe815d2013-03-19 22:22:21 -07001027 return mBuffer.width;
Mathias Agopian74c40c02010-09-29 13:02:36 -07001028}
1029
1030uint32_t ScreenshotClient::getHeight() const {
Mathias Agopianabe815d2013-03-19 22:22:21 -07001031 return mBuffer.height;
Mathias Agopian74c40c02010-09-29 13:02:36 -07001032}
1033
1034PixelFormat ScreenshotClient::getFormat() const {
Mathias Agopianabe815d2013-03-19 22:22:21 -07001035 return mBuffer.format;
Mathias Agopian74c40c02010-09-29 13:02:36 -07001036}
1037
1038uint32_t ScreenshotClient::getStride() const {
Mathias Agopianabe815d2013-03-19 22:22:21 -07001039 return mBuffer.stride;
Mathias Agopian74c40c02010-09-29 13:02:36 -07001040}
1041
1042size_t ScreenshotClient::getSize() const {
Mathias Agopianabe815d2013-03-19 22:22:21 -07001043 return mBuffer.stride * mBuffer.height * bytesPerPixel(mBuffer.format);
Mathias Agopian74c40c02010-09-29 13:02:36 -07001044}
1045
1046// ----------------------------------------------------------------------------
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001047}; // namespace android