blob: 540dbd92383737753e2163df9dbe907c44285fd7 [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 Carrc3574f72016-03-24 12:19:32 -0700173 status_t setOverrideScalingMode(const sp<SurfaceComposerClient>& client,
174 const sp<IBinder>& id, int32_t overrideScalingMode);
Robert Carr99e27f02016-06-16 15:18:02 -0700175 status_t setGeometryAppliesWithResize(const sp<SurfaceComposerClient>& client,
Robert Carr82364e32016-05-15 11:27:47 -0700176 const sp<IBinder>& id);
Mathias Agopian698c0872011-06-28 19:09:31 -0700177
Pablo Ceballos1aad24c2016-08-04 10:24:22 -0700178 status_t setDisplaySurface(const sp<IBinder>& token,
179 sp<IGraphicBufferProducer> bufferProducer);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700180 void setDisplayLayerStack(const sp<IBinder>& token, uint32_t layerStack);
Mathias Agopian00e8c7a2012-09-04 19:30:46 -0700181 void setDisplayProjection(const sp<IBinder>& token,
182 uint32_t orientation,
183 const Rect& layerStackRect,
184 const Rect& displayRect);
Michael Wright1f6078a2014-06-26 16:01:02 -0700185 void setDisplaySize(const sp<IBinder>& token, uint32_t width, uint32_t height);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700186
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700187 static void setAnimationTransaction() {
188 Composer::getInstance().setAnimationTransactionImpl();
189 }
190
Jeff Brownf3f7db62012-08-31 02:18:38 -0700191 static void openGlobalTransaction() {
192 Composer::getInstance().openGlobalTransactionImpl();
193 }
194
Jamie Gennis28378392011-10-12 17:39:00 -0700195 static void closeGlobalTransaction(bool synchronous) {
196 Composer::getInstance().closeGlobalTransactionImpl(synchronous);
Mathias Agopiand4784a32010-05-27 19:41:15 -0700197 }
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -0700198
199 static status_t enableVSyncInjections(bool enable) {
200 return Composer::getInstance().enableVSyncInjectionsImpl(enable);
201 }
202
203 static status_t injectVSync(nsecs_t when) {
204 return Composer::getInstance().injectVSyncImpl(when);
205 }
Mathias Agopiand4784a32010-05-27 19:41:15 -0700206};
207
208ANDROID_SINGLETON_STATIC_INSTANCE(Composer);
209
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800210// ---------------------------------------------------------------------------
211
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700212sp<IBinder> Composer::createDisplay(const String8& displayName, bool secure) {
213 return ComposerService::getComposerService()->createDisplay(displayName,
214 secure);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700215}
216
Jesse Hall6c913be2013-08-08 12:15:49 -0700217void Composer::destroyDisplay(const sp<IBinder>& display) {
218 return ComposerService::getComposerService()->destroyDisplay(display);
219}
220
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700221sp<IBinder> Composer::getBuiltInDisplay(int32_t id) {
222 return ComposerService::getComposerService()->getBuiltInDisplay(id);
223}
224
Jeff Brownf3f7db62012-08-31 02:18:38 -0700225void Composer::openGlobalTransactionImpl() {
226 { // scope for the lock
227 Mutex::Autolock _l(mLock);
228 mTransactionNestCount += 1;
229 }
230}
231
Jamie Gennis28378392011-10-12 17:39:00 -0700232void Composer::closeGlobalTransactionImpl(bool synchronous) {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700233 sp<ISurfaceComposer> sm(ComposerService::getComposerService());
Mathias Agopian698c0872011-06-28 19:09:31 -0700234
235 Vector<ComposerState> transaction;
Mathias Agopian8b33f032012-07-24 20:43:54 -0700236 Vector<DisplayState> displayTransaction;
Jamie Gennis28378392011-10-12 17:39:00 -0700237 uint32_t flags = 0;
Mathias Agopian698c0872011-06-28 19:09:31 -0700238
239 { // scope for the lock
240 Mutex::Autolock _l(mLock);
Jeff Brownf3f7db62012-08-31 02:18:38 -0700241 mForceSynchronous |= synchronous;
242 if (!mTransactionNestCount) {
243 ALOGW("At least one call to closeGlobalTransaction() was not matched by a prior "
244 "call to openGlobalTransaction().");
245 } else if (--mTransactionNestCount) {
246 return;
247 }
248
Mathias Agopiane57f2922012-08-09 16:29:12 -0700249 transaction = mComposerStates;
250 mComposerStates.clear();
Jamie Gennisb8d69a52011-10-10 15:48:06 -0700251
Mathias Agopiane57f2922012-08-09 16:29:12 -0700252 displayTransaction = mDisplayStates;
253 mDisplayStates.clear();
Jamie Gennis28378392011-10-12 17:39:00 -0700254
Jeff Brownf3f7db62012-08-31 02:18:38 -0700255 if (mForceSynchronous) {
Jamie Gennis28378392011-10-12 17:39:00 -0700256 flags |= ISurfaceComposer::eSynchronous;
257 }
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700258 if (mAnimation) {
259 flags |= ISurfaceComposer::eAnimation;
260 }
261
Jamie Gennis28378392011-10-12 17:39:00 -0700262 mForceSynchronous = false;
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700263 mAnimation = false;
Mathias Agopian698c0872011-06-28 19:09:31 -0700264 }
265
Mathias Agopian8b33f032012-07-24 20:43:54 -0700266 sm->setTransactionState(transaction, displayTransaction, flags);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800267}
268
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -0700269status_t Composer::enableVSyncInjectionsImpl(bool enable) {
270 sp<ISurfaceComposer> sm(ComposerService::getComposerService());
271 return sm->enableVSyncInjections(enable);
272}
273
274status_t Composer::injectVSyncImpl(nsecs_t when) {
275 sp<ISurfaceComposer> sm(ComposerService::getComposerService());
276 return sm->injectVSync(when);
277}
278
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700279void Composer::setAnimationTransactionImpl() {
280 Mutex::Autolock _l(mLock);
281 mAnimation = true;
282}
283
Mathias Agopian698c0872011-06-28 19:09:31 -0700284layer_state_t* Composer::getLayerStateLocked(
Mathias Agopianac9fa422013-02-11 16:40:36 -0800285 const sp<SurfaceComposerClient>& client, const sp<IBinder>& id) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700286
287 ComposerState s;
288 s.client = client->mClient;
289 s.state.surface = id;
290
Mathias Agopiane57f2922012-08-09 16:29:12 -0700291 ssize_t index = mComposerStates.indexOf(s);
Mathias Agopian698c0872011-06-28 19:09:31 -0700292 if (index < 0) {
293 // we don't have it, add an initialized layer_state to our list
Mathias Agopiane57f2922012-08-09 16:29:12 -0700294 index = mComposerStates.add(s);
Mathias Agopian698c0872011-06-28 19:09:31 -0700295 }
296
Mathias Agopiane57f2922012-08-09 16:29:12 -0700297 ComposerState* const out = mComposerStates.editArray();
Mathias Agopian698c0872011-06-28 19:09:31 -0700298 return &(out[index].state);
299}
300
301status_t Composer::setPosition(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-11 16:40:36 -0800302 const sp<IBinder>& id, float x, float y) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700303 Mutex::Autolock _l(mLock);
304 layer_state_t* s = getLayerStateLocked(client, id);
305 if (!s)
306 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700307 s->what |= layer_state_t::ePositionChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700308 s->x = x;
309 s->y = y;
310 return NO_ERROR;
311}
312
313status_t Composer::setSize(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-11 16:40:36 -0800314 const sp<IBinder>& id, uint32_t w, uint32_t h) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700315 Mutex::Autolock _l(mLock);
316 layer_state_t* s = getLayerStateLocked(client, id);
317 if (!s)
318 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700319 s->what |= layer_state_t::eSizeChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700320 s->w = w;
321 s->h = h;
Jamie Gennis28378392011-10-12 17:39:00 -0700322
Jorim Jaggi092123c2016-04-13 01:40:35 +0000323 // Resizing a surface makes the transaction synchronous.
324 mForceSynchronous = true;
325
Mathias Agopian698c0872011-06-28 19:09:31 -0700326 return NO_ERROR;
327}
328
329status_t Composer::setLayer(const sp<SurfaceComposerClient>& client,
Robert Carrae060832016-11-28 10:51:00 -0800330 const sp<IBinder>& id, int32_t z) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700331 Mutex::Autolock _l(mLock);
332 layer_state_t* s = getLayerStateLocked(client, id);
333 if (!s)
334 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700335 s->what |= layer_state_t::eLayerChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700336 s->z = z;
337 return NO_ERROR;
338}
339
Albert Chaulk6cf6af02016-11-22 13:52:43 -0500340status_t Composer::setLayerInfo(const sp<SurfaceComposerClient>& client,
341 const sp<IBinder>& id, uint32_t type, uint32_t appid) {
342 Mutex::Autolock _l(mLock);
343 layer_state_t* s = getLayerStateLocked(client, id);
344 if (!s)
345 return BAD_INDEX;
346 s->what |= layer_state_t::eLayerInfoChanged;
347 s->type = type;
348 s->appid = appid;
349 return NO_ERROR;
350}
351
Mathias Agopian698c0872011-06-28 19:09:31 -0700352status_t Composer::setFlags(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-11 16:40:36 -0800353 const sp<IBinder>& id, uint32_t flags,
Mathias Agopian698c0872011-06-28 19:09:31 -0700354 uint32_t mask) {
355 Mutex::Autolock _l(mLock);
356 layer_state_t* s = getLayerStateLocked(client, id);
357 if (!s)
358 return BAD_INDEX;
Pablo Ceballos53390e12015-08-04 11:25:59 -0700359 if ((mask & layer_state_t::eLayerOpaque) ||
360 (mask & layer_state_t::eLayerHidden) ||
361 (mask & layer_state_t::eLayerSecure)) {
Dan Stoza23116082015-06-18 14:58:39 -0700362 s->what |= layer_state_t::eFlagsChanged;
Andy McFadden4125a4f2014-01-29 17:17:11 -0800363 }
Mathias Agopian698c0872011-06-28 19:09:31 -0700364 s->flags &= ~mask;
365 s->flags |= (flags & mask);
366 s->mask |= mask;
367 return NO_ERROR;
368}
369
370status_t Composer::setTransparentRegionHint(
Mathias Agopianac9fa422013-02-11 16:40:36 -0800371 const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
Mathias Agopian698c0872011-06-28 19:09:31 -0700372 const Region& transparentRegion) {
373 Mutex::Autolock _l(mLock);
374 layer_state_t* s = getLayerStateLocked(client, id);
375 if (!s)
376 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700377 s->what |= layer_state_t::eTransparentRegionChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700378 s->transparentRegion = transparentRegion;
379 return NO_ERROR;
380}
381
382status_t Composer::setAlpha(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-11 16:40:36 -0800383 const sp<IBinder>& id, float alpha) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700384 Mutex::Autolock _l(mLock);
385 layer_state_t* s = getLayerStateLocked(client, id);
386 if (!s)
387 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700388 s->what |= layer_state_t::eAlphaChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700389 s->alpha = alpha;
390 return NO_ERROR;
391}
392
Mathias Agopian87855782012-07-24 21:41:09 -0700393status_t Composer::setLayerStack(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-11 16:40:36 -0800394 const sp<IBinder>& id, uint32_t layerStack) {
Mathias Agopian87855782012-07-24 21:41:09 -0700395 Mutex::Autolock _l(mLock);
396 layer_state_t* s = getLayerStateLocked(client, id);
397 if (!s)
398 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700399 s->what |= layer_state_t::eLayerStackChanged;
Mathias Agopian87855782012-07-24 21:41:09 -0700400 s->layerStack = layerStack;
401 return NO_ERROR;
402}
403
Mathias Agopian698c0872011-06-28 19:09:31 -0700404status_t Composer::setMatrix(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-11 16:40:36 -0800405 const sp<IBinder>& id, float dsdx, float dtdx,
Mathias Agopian698c0872011-06-28 19:09:31 -0700406 float dsdy, float dtdy) {
407 Mutex::Autolock _l(mLock);
408 layer_state_t* s = getLayerStateLocked(client, id);
409 if (!s)
410 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700411 s->what |= layer_state_t::eMatrixChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700412 layer_state_t::matrix22_t matrix;
413 matrix.dsdx = dsdx;
414 matrix.dtdx = dtdx;
415 matrix.dsdy = dsdy;
416 matrix.dtdy = dtdy;
417 s->matrix = matrix;
418 return NO_ERROR;
419}
420
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700421status_t Composer::setCrop(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-11 16:40:36 -0800422 const sp<IBinder>& id, const Rect& crop) {
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700423 Mutex::Autolock _l(mLock);
424 layer_state_t* s = getLayerStateLocked(client, id);
425 if (!s)
426 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700427 s->what |= layer_state_t::eCropChanged;
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700428 s->crop = crop;
429 return NO_ERROR;
430}
431
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000432status_t Composer::setFinalCrop(const sp<SurfaceComposerClient>& client,
433 const sp<IBinder>& id, const Rect& crop) {
434 Mutex::Autolock _l(mLock);
435 layer_state_t* s = getLayerStateLocked(client, id);
436 if (!s) {
437 return BAD_INDEX;
438 }
439 s->what |= layer_state_t::eFinalCropChanged;
440 s->finalCrop = crop;
441 return NO_ERROR;
442}
443
Dan Stoza7dde5992015-05-22 09:51:44 -0700444status_t Composer::deferTransactionUntil(
445 const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
446 const sp<IBinder>& handle, uint64_t frameNumber) {
447 Mutex::Autolock lock(mLock);
448 layer_state_t* s = getLayerStateLocked(client, id);
449 if (!s) {
450 return BAD_INDEX;
451 }
452 s->what |= layer_state_t::eDeferTransaction;
453 s->handle = handle;
454 s->frameNumber = frameNumber;
455 return NO_ERROR;
456}
457
Robert Carrc3574f72016-03-24 12:19:32 -0700458status_t Composer::setOverrideScalingMode(
459 const sp<SurfaceComposerClient>& client,
460 const sp<IBinder>& id, int32_t overrideScalingMode) {
461 Mutex::Autolock lock(mLock);
462 layer_state_t* s = getLayerStateLocked(client, id);
463 if (!s) {
464 return BAD_INDEX;
465 }
466
467 switch (overrideScalingMode) {
468 case NATIVE_WINDOW_SCALING_MODE_FREEZE:
469 case NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW:
470 case NATIVE_WINDOW_SCALING_MODE_SCALE_CROP:
471 case NATIVE_WINDOW_SCALING_MODE_NO_SCALE_CROP:
472 case -1:
473 break;
474 default:
475 ALOGE("unknown scaling mode: %d",
476 overrideScalingMode);
477 return BAD_VALUE;
478 }
479
480 s->what |= layer_state_t::eOverrideScalingModeChanged;
481 s->overrideScalingMode = overrideScalingMode;
482 return NO_ERROR;
483}
484
Robert Carr99e27f02016-06-16 15:18:02 -0700485status_t Composer::setGeometryAppliesWithResize(
Robert Carr82364e32016-05-15 11:27:47 -0700486 const sp<SurfaceComposerClient>& client,
487 const sp<IBinder>& id) {
488 Mutex::Autolock lock(mLock);
489 layer_state_t* s = getLayerStateLocked(client, id);
490 if (!s) {
491 return BAD_INDEX;
492 }
Robert Carr99e27f02016-06-16 15:18:02 -0700493 s->what |= layer_state_t::eGeometryAppliesWithResize;
Robert Carr82364e32016-05-15 11:27:47 -0700494 return NO_ERROR;
495}
496
Mathias Agopian698c0872011-06-28 19:09:31 -0700497// ---------------------------------------------------------------------------
498
Mathias Agopiane57f2922012-08-09 16:29:12 -0700499DisplayState& Composer::getDisplayStateLocked(const sp<IBinder>& token) {
500 DisplayState s;
501 s.token = token;
502 ssize_t index = mDisplayStates.indexOf(s);
503 if (index < 0) {
504 // we don't have it, add an initialized layer_state to our list
505 s.what = 0;
506 index = mDisplayStates.add(s);
507 }
Dan Stozad723bd72014-11-18 10:24:03 -0800508 return mDisplayStates.editItemAt(static_cast<size_t>(index));
Mathias Agopiane57f2922012-08-09 16:29:12 -0700509}
510
Pablo Ceballos1aad24c2016-08-04 10:24:22 -0700511status_t Composer::setDisplaySurface(const sp<IBinder>& token,
512 sp<IGraphicBufferProducer> bufferProducer) {
Pablo Ceballoseddbef82016-09-01 11:21:21 -0700513 if (bufferProducer.get() != nullptr) {
514 // Make sure that composition can never be stalled by a virtual display
515 // consumer that isn't processing buffers fast enough.
516 status_t err = bufferProducer->setAsyncMode(true);
517 if (err != NO_ERROR) {
518 ALOGE("Composer::setDisplaySurface Failed to enable async mode on the "
519 "BufferQueue. This BufferQueue cannot be used for virtual "
520 "display. (%d)", err);
521 return err;
522 }
Pablo Ceballos1aad24c2016-08-04 10:24:22 -0700523 }
Mathias Agopiane57f2922012-08-09 16:29:12 -0700524 Mutex::Autolock _l(mLock);
525 DisplayState& s(getDisplayStateLocked(token));
Andy McFadden2adaf042012-12-18 09:49:45 -0800526 s.surface = bufferProducer;
Mathias Agopiane57f2922012-08-09 16:29:12 -0700527 s.what |= DisplayState::eSurfaceChanged;
Pablo Ceballos1aad24c2016-08-04 10:24:22 -0700528 return NO_ERROR;
Mathias Agopiane57f2922012-08-09 16:29:12 -0700529}
530
531void Composer::setDisplayLayerStack(const sp<IBinder>& token,
532 uint32_t layerStack) {
533 Mutex::Autolock _l(mLock);
534 DisplayState& s(getDisplayStateLocked(token));
535 s.layerStack = layerStack;
536 s.what |= DisplayState::eLayerStackChanged;
537}
538
Mathias Agopian00e8c7a2012-09-04 19:30:46 -0700539void Composer::setDisplayProjection(const sp<IBinder>& token,
540 uint32_t orientation,
541 const Rect& layerStackRect,
542 const Rect& displayRect) {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700543 Mutex::Autolock _l(mLock);
544 DisplayState& s(getDisplayStateLocked(token));
545 s.orientation = orientation;
Mathias Agopian00e8c7a2012-09-04 19:30:46 -0700546 s.viewport = layerStackRect;
547 s.frame = displayRect;
548 s.what |= DisplayState::eDisplayProjectionChanged;
Jorim Jaggi092123c2016-04-13 01:40:35 +0000549 mForceSynchronous = true; // TODO: do we actually still need this?
Mathias Agopiane57f2922012-08-09 16:29:12 -0700550}
551
Michael Wright1f6078a2014-06-26 16:01:02 -0700552void Composer::setDisplaySize(const sp<IBinder>& token, uint32_t width, uint32_t height) {
553 Mutex::Autolock _l(mLock);
554 DisplayState& s(getDisplayStateLocked(token));
555 s.width = width;
556 s.height = height;
557 s.what |= DisplayState::eDisplaySizeChanged;
558}
559
Mathias Agopiane57f2922012-08-09 16:29:12 -0700560// ---------------------------------------------------------------------------
561
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800562SurfaceComposerClient::SurfaceComposerClient()
Mathias Agopian698c0872011-06-28 19:09:31 -0700563 : mStatus(NO_INIT), mComposer(Composer::getInstance())
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800564{
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800565}
566
Mathias Agopian698c0872011-06-28 19:09:31 -0700567void SurfaceComposerClient::onFirstRef() {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700568 sp<ISurfaceComposer> sm(ComposerService::getComposerService());
Mathias Agopiand4784a32010-05-27 19:41:15 -0700569 if (sm != 0) {
Mathias Agopian7e27f052010-05-28 14:22:23 -0700570 sp<ISurfaceComposerClient> conn = sm->createConnection();
Mathias Agopiand4784a32010-05-27 19:41:15 -0700571 if (conn != 0) {
572 mClient = conn;
Mathias Agopiand4784a32010-05-27 19:41:15 -0700573 mStatus = NO_ERROR;
574 }
575 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800576}
577
Mathias Agopian698c0872011-06-28 19:09:31 -0700578SurfaceComposerClient::~SurfaceComposerClient() {
Mathias Agopian631f3582010-05-25 17:51:34 -0700579 dispose();
580}
Mathias Agopiandd3423c2009-09-23 15:44:05 -0700581
Mathias Agopian698c0872011-06-28 19:09:31 -0700582status_t SurfaceComposerClient::initCheck() const {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800583 return mStatus;
584}
585
Mathias Agopian698c0872011-06-28 19:09:31 -0700586sp<IBinder> SurfaceComposerClient::connection() const {
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800587 return IInterface::asBinder(mClient);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800588}
589
Mathias Agopiand4784a32010-05-27 19:41:15 -0700590status_t SurfaceComposerClient::linkToComposerDeath(
591 const sp<IBinder::DeathRecipient>& recipient,
Mathias Agopian698c0872011-06-28 19:09:31 -0700592 void* cookie, uint32_t flags) {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700593 sp<ISurfaceComposer> sm(ComposerService::getComposerService());
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800594 return IInterface::asBinder(sm)->linkToDeath(recipient, cookie, flags);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800595}
596
Mathias Agopian698c0872011-06-28 19:09:31 -0700597void SurfaceComposerClient::dispose() {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800598 // this can be called more than once.
Mathias Agopian7e27f052010-05-28 14:22:23 -0700599 sp<ISurfaceComposerClient> client;
Mathias Agopiand4784a32010-05-27 19:41:15 -0700600 Mutex::Autolock _lm(mLock);
601 if (mClient != 0) {
Mathias Agopiand4784a32010-05-27 19:41:15 -0700602 client = mClient; // hold ref while lock is held
603 mClient.clear();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800604 }
Mathias Agopiand4784a32010-05-27 19:41:15 -0700605 mStatus = NO_INIT;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800606}
607
Mathias Agopian698c0872011-06-28 19:09:31 -0700608sp<SurfaceControl> SurfaceComposerClient::createSurface(
Mathias Agopian698c0872011-06-28 19:09:31 -0700609 const String8& name,
Mathias Agopian698c0872011-06-28 19:09:31 -0700610 uint32_t w,
611 uint32_t h,
612 PixelFormat format,
613 uint32_t flags)
614{
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700615 sp<SurfaceControl> sur;
Mathias Agopian698c0872011-06-28 19:09:31 -0700616 if (mStatus == NO_ERROR) {
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700617 sp<IBinder> handle;
618 sp<IGraphicBufferProducer> gbp;
619 status_t err = mClient->createSurface(name, w, h, format, flags,
620 &handle, &gbp);
621 ALOGE_IF(err, "SurfaceComposerClient::createSurface error %s", strerror(-err));
622 if (err == NO_ERROR) {
623 sur = new SurfaceControl(this, handle, gbp);
Mathias Agopian698c0872011-06-28 19:09:31 -0700624 }
625 }
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700626 return sur;
Mathias Agopian698c0872011-06-28 19:09:31 -0700627}
628
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700629sp<IBinder> SurfaceComposerClient::createDisplay(const String8& displayName,
630 bool secure) {
631 return Composer::getInstance().createDisplay(displayName, secure);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700632}
633
Jesse Hall6c913be2013-08-08 12:15:49 -0700634void SurfaceComposerClient::destroyDisplay(const sp<IBinder>& display) {
635 Composer::getInstance().destroyDisplay(display);
636}
637
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700638sp<IBinder> SurfaceComposerClient::getBuiltInDisplay(int32_t id) {
639 return Composer::getInstance().getBuiltInDisplay(id);
640}
641
Mathias Agopianac9fa422013-02-11 16:40:36 -0800642status_t SurfaceComposerClient::destroySurface(const sp<IBinder>& sid) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700643 if (mStatus != NO_ERROR)
644 return mStatus;
645 status_t err = mClient->destroySurface(sid);
646 return err;
647}
648
Svetoslavd85084b2014-03-20 10:28:31 -0700649status_t SurfaceComposerClient::clearLayerFrameStats(const sp<IBinder>& token) const {
650 if (mStatus != NO_ERROR) {
651 return mStatus;
652 }
653 return mClient->clearLayerFrameStats(token);
654}
655
656status_t SurfaceComposerClient::getLayerFrameStats(const sp<IBinder>& token,
657 FrameStats* outStats) const {
658 if (mStatus != NO_ERROR) {
659 return mStatus;
660 }
661 return mClient->getLayerFrameStats(token, outStats);
662}
663
Robert Carr367c5682016-06-20 11:55:28 -0700664status_t SurfaceComposerClient::getTransformToDisplayInverse(const sp<IBinder>& token,
665 bool* outTransformToDisplayInverse) const {
666 if (mStatus != NO_ERROR) {
667 return mStatus;
668 }
669 return mClient->getTransformToDisplayInverse(token, outTransformToDisplayInverse);
670}
671
Mathias Agopian698c0872011-06-28 19:09:31 -0700672inline Composer& SurfaceComposerClient::getComposer() {
673 return mComposer;
674}
675
676// ----------------------------------------------------------------------------
677
678void SurfaceComposerClient::openGlobalTransaction() {
Jeff Brownf3f7db62012-08-31 02:18:38 -0700679 Composer::openGlobalTransaction();
Mathias Agopian698c0872011-06-28 19:09:31 -0700680}
681
Jamie Gennis28378392011-10-12 17:39:00 -0700682void SurfaceComposerClient::closeGlobalTransaction(bool synchronous) {
683 Composer::closeGlobalTransaction(synchronous);
Mathias Agopian698c0872011-06-28 19:09:31 -0700684}
685
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700686void SurfaceComposerClient::setAnimationTransaction() {
687 Composer::setAnimationTransaction();
688}
689
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -0700690status_t SurfaceComposerClient::enableVSyncInjections(bool enable) {
691 return Composer::enableVSyncInjections(enable);
692}
693
694status_t SurfaceComposerClient::injectVSync(nsecs_t when) {
695 return Composer::injectVSync(when);
696}
697
Mathias Agopian698c0872011-06-28 19:09:31 -0700698// ----------------------------------------------------------------------------
699
Mathias Agopianac9fa422013-02-11 16:40:36 -0800700status_t SurfaceComposerClient::setCrop(const sp<IBinder>& id, const Rect& crop) {
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700701 return getComposer().setCrop(this, id, crop);
702}
703
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000704status_t SurfaceComposerClient::setFinalCrop(const sp<IBinder>& id,
705 const Rect& crop) {
706 return getComposer().setFinalCrop(this, id, crop);
707}
708
Mathias Agopianac9fa422013-02-11 16:40:36 -0800709status_t SurfaceComposerClient::setPosition(const sp<IBinder>& id, float x, float y) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700710 return getComposer().setPosition(this, id, x, y);
711}
712
Mathias Agopianac9fa422013-02-11 16:40:36 -0800713status_t SurfaceComposerClient::setSize(const sp<IBinder>& id, uint32_t w, uint32_t h) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700714 return getComposer().setSize(this, id, w, h);
715}
716
Robert Carrae060832016-11-28 10:51:00 -0800717status_t SurfaceComposerClient::setLayer(const sp<IBinder>& id, int32_t z) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700718 return getComposer().setLayer(this, id, z);
719}
720
Albert Chaulk6cf6af02016-11-22 13:52:43 -0500721status_t SurfaceComposerClient::setLayerInfo(const sp<IBinder>& id, uint32_t type, uint32_t appid) {
722 return getComposer().setLayerInfo(this, id, type, appid);
723}
724
Mathias Agopianac9fa422013-02-11 16:40:36 -0800725status_t SurfaceComposerClient::hide(const sp<IBinder>& id) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700726 return getComposer().setFlags(this, id,
Mathias Agopian3165cc22012-08-08 19:42:09 -0700727 layer_state_t::eLayerHidden,
728 layer_state_t::eLayerHidden);
Mathias Agopian698c0872011-06-28 19:09:31 -0700729}
730
Mathias Agopianac9fa422013-02-11 16:40:36 -0800731status_t SurfaceComposerClient::show(const sp<IBinder>& id) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700732 return getComposer().setFlags(this, id,
733 0,
Mathias Agopian3165cc22012-08-08 19:42:09 -0700734 layer_state_t::eLayerHidden);
Mathias Agopian698c0872011-06-28 19:09:31 -0700735}
736
Mathias Agopianac9fa422013-02-11 16:40:36 -0800737status_t SurfaceComposerClient::setFlags(const sp<IBinder>& id, uint32_t flags,
Mathias Agopian698c0872011-06-28 19:09:31 -0700738 uint32_t mask) {
739 return getComposer().setFlags(this, id, flags, mask);
740}
741
Mathias Agopianac9fa422013-02-11 16:40:36 -0800742status_t SurfaceComposerClient::setTransparentRegionHint(const sp<IBinder>& id,
Mathias Agopian698c0872011-06-28 19:09:31 -0700743 const Region& transparentRegion) {
744 return getComposer().setTransparentRegionHint(this, id, transparentRegion);
745}
746
Mathias Agopianac9fa422013-02-11 16:40:36 -0800747status_t SurfaceComposerClient::setAlpha(const sp<IBinder>& id, float alpha) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700748 return getComposer().setAlpha(this, id, alpha);
749}
750
Mathias Agopianac9fa422013-02-11 16:40:36 -0800751status_t SurfaceComposerClient::setLayerStack(const sp<IBinder>& id, uint32_t layerStack) {
Mathias Agopian87855782012-07-24 21:41:09 -0700752 return getComposer().setLayerStack(this, id, layerStack);
753}
754
Mathias Agopianac9fa422013-02-11 16:40:36 -0800755status_t SurfaceComposerClient::setMatrix(const sp<IBinder>& id, float dsdx, float dtdx,
Mathias Agopian698c0872011-06-28 19:09:31 -0700756 float dsdy, float dtdy) {
757 return getComposer().setMatrix(this, id, dsdx, dtdx, dsdy, dtdy);
758}
759
Dan Stoza7dde5992015-05-22 09:51:44 -0700760status_t SurfaceComposerClient::deferTransactionUntil(const sp<IBinder>& id,
761 const sp<IBinder>& handle, uint64_t frameNumber) {
762 return getComposer().deferTransactionUntil(this, id, handle, frameNumber);
763}
764
Robert Carrc3574f72016-03-24 12:19:32 -0700765status_t SurfaceComposerClient::setOverrideScalingMode(
766 const sp<IBinder>& id, int32_t overrideScalingMode) {
767 return getComposer().setOverrideScalingMode(
768 this, id, overrideScalingMode);
769}
770
Robert Carr99e27f02016-06-16 15:18:02 -0700771status_t SurfaceComposerClient::setGeometryAppliesWithResize(
Robert Carr82364e32016-05-15 11:27:47 -0700772 const sp<IBinder>& id) {
Robert Carr99e27f02016-06-16 15:18:02 -0700773 return getComposer().setGeometryAppliesWithResize(this, id);
Robert Carr82364e32016-05-15 11:27:47 -0700774}
775
Mathias Agopian698c0872011-06-28 19:09:31 -0700776// ----------------------------------------------------------------------------
777
Pablo Ceballos1aad24c2016-08-04 10:24:22 -0700778status_t SurfaceComposerClient::setDisplaySurface(const sp<IBinder>& token,
779 sp<IGraphicBufferProducer> bufferProducer) {
780 return Composer::getInstance().setDisplaySurface(token, bufferProducer);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700781}
782
783void SurfaceComposerClient::setDisplayLayerStack(const sp<IBinder>& token,
784 uint32_t layerStack) {
785 Composer::getInstance().setDisplayLayerStack(token, layerStack);
786}
787
Mathias Agopian00e8c7a2012-09-04 19:30:46 -0700788void SurfaceComposerClient::setDisplayProjection(const sp<IBinder>& token,
789 uint32_t orientation,
790 const Rect& layerStackRect,
791 const Rect& displayRect) {
792 Composer::getInstance().setDisplayProjection(token, orientation,
793 layerStackRect, displayRect);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700794}
795
Michael Wright1f6078a2014-06-26 16:01:02 -0700796void SurfaceComposerClient::setDisplaySize(const sp<IBinder>& token,
797 uint32_t width, uint32_t height) {
798 Composer::getInstance().setDisplaySize(token, width, height);
799}
800
Mathias Agopiane57f2922012-08-09 16:29:12 -0700801// ----------------------------------------------------------------------------
802
Dan Stoza7f7da322014-05-02 15:26:25 -0700803status_t SurfaceComposerClient::getDisplayConfigs(
804 const sp<IBinder>& display, Vector<DisplayInfo>* configs)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800805{
Dan Stoza7f7da322014-05-02 15:26:25 -0700806 return ComposerService::getComposerService()->getDisplayConfigs(display, configs);
807}
808
809status_t SurfaceComposerClient::getDisplayInfo(const sp<IBinder>& display,
810 DisplayInfo* info) {
811 Vector<DisplayInfo> configs;
812 status_t result = getDisplayConfigs(display, &configs);
813 if (result != NO_ERROR) {
814 return result;
815 }
816
817 int activeId = getActiveConfig(display);
818 if (activeId < 0) {
819 ALOGE("No active configuration found");
820 return NAME_NOT_FOUND;
821 }
822
Dan Stozad723bd72014-11-18 10:24:03 -0800823 *info = configs[static_cast<size_t>(activeId)];
Dan Stoza7f7da322014-05-02 15:26:25 -0700824 return NO_ERROR;
825}
826
827int SurfaceComposerClient::getActiveConfig(const sp<IBinder>& display) {
828 return ComposerService::getComposerService()->getActiveConfig(display);
829}
830
831status_t SurfaceComposerClient::setActiveConfig(const sp<IBinder>& display, int id) {
832 return ComposerService::getComposerService()->setActiveConfig(display, id);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800833}
834
Michael Wright28f24d02016-07-12 13:30:53 -0700835status_t SurfaceComposerClient::getDisplayColorModes(const sp<IBinder>& display,
836 Vector<android_color_mode_t>* outColorModes) {
837 return ComposerService::getComposerService()->getDisplayColorModes(display, outColorModes);
838}
839
840android_color_mode_t SurfaceComposerClient::getActiveColorMode(const sp<IBinder>& display) {
841 return ComposerService::getComposerService()->getActiveColorMode(display);
842}
843
844status_t SurfaceComposerClient::setActiveColorMode(const sp<IBinder>& display,
845 android_color_mode_t colorMode) {
846 return ComposerService::getComposerService()->setActiveColorMode(display, colorMode);
847}
848
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700849void SurfaceComposerClient::setDisplayPowerMode(const sp<IBinder>& token,
850 int mode) {
851 ComposerService::getComposerService()->setPowerMode(token, mode);
Jeff Brown2a09bb32012-10-08 19:13:57 -0700852}
853
Svetoslavd85084b2014-03-20 10:28:31 -0700854status_t SurfaceComposerClient::clearAnimationFrameStats() {
855 return ComposerService::getComposerService()->clearAnimationFrameStats();
856}
857
858status_t SurfaceComposerClient::getAnimationFrameStats(FrameStats* outStats) {
859 return ComposerService::getComposerService()->getAnimationFrameStats(outStats);
860}
861
Dan Stozac4f471e2016-03-24 09:31:08 -0700862status_t SurfaceComposerClient::getHdrCapabilities(const sp<IBinder>& display,
863 HdrCapabilities* outCapabilities) {
864 return ComposerService::getComposerService()->getHdrCapabilities(display,
865 outCapabilities);
866}
867
Mathias Agopian698c0872011-06-28 19:09:31 -0700868// ----------------------------------------------------------------------------
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800869
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800870status_t ScreenshotClient::capture(
871 const sp<IBinder>& display,
872 const sp<IGraphicBufferProducer>& producer,
Dan Stozac1879002014-05-22 15:59:05 -0700873 Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
Robert Carrae060832016-11-28 10:51:00 -0800874 int32_t minLayerZ, int32_t maxLayerZ, bool useIdentityTransform) {
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800875 sp<ISurfaceComposer> s(ComposerService::getComposerService());
876 if (s == NULL) return NO_INIT;
Dan Stozac1879002014-05-22 15:59:05 -0700877 return s->captureScreen(display, producer, sourceCrop,
Dan Stozac7014012014-02-14 15:03:43 -0800878 reqWidth, reqHeight, minLayerZ, maxLayerZ, useIdentityTransform);
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800879}
880
Robert Carr673134e2017-01-09 19:48:38 -0800881status_t ScreenshotClient::captureToBuffer(const sp<IBinder>& display,
882 Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
Robert Carrae060832016-11-28 10:51:00 -0800883 int32_t minLayerZ, int32_t maxLayerZ, bool useIdentityTransform,
Robert Carr673134e2017-01-09 19:48:38 -0800884 uint32_t rotation,
885 sp<GraphicBuffer>* outBuffer) {
886 sp<ISurfaceComposer> s(ComposerService::getComposerService());
887 if (s == NULL) return NO_INIT;
888
889 sp<IGraphicBufferConsumer> gbpConsumer;
890 sp<IGraphicBufferProducer> producer;
891 BufferQueue::createBufferQueue(&producer, &gbpConsumer);
892 sp<BufferItemConsumer> consumer(new BufferItemConsumer(gbpConsumer,
893 GRALLOC_USAGE_HW_TEXTURE | GRALLOC_USAGE_SW_READ_NEVER | GRALLOC_USAGE_SW_WRITE_NEVER,
894 1, true));
895
896 status_t ret = s->captureScreen(display, producer, sourceCrop, reqWidth, reqHeight,
897 minLayerZ, maxLayerZ, useIdentityTransform,
898 static_cast<ISurfaceComposer::Rotation>(rotation));
899 if (ret != NO_ERROR) {
900 return ret;
901 }
902 BufferItem b;
903 consumer->acquireBuffer(&b, 0, true);
904 *outBuffer = b.mGraphicBuffer;
905 return ret;
906}
907
Mathias Agopian74c40c02010-09-29 13:02:36 -0700908ScreenshotClient::ScreenshotClient()
Mathias Agopianabe815d2013-03-19 22:22:21 -0700909 : mHaveBuffer(false) {
910 memset(&mBuffer, 0, sizeof(mBuffer));
Mathias Agopian74c40c02010-09-29 13:02:36 -0700911}
912
Mathias Agopian8000d062013-03-26 18:15:35 -0700913ScreenshotClient::~ScreenshotClient() {
914 ScreenshotClient::release();
915}
916
Mathias Agopianabe815d2013-03-19 22:22:21 -0700917sp<CpuConsumer> ScreenshotClient::getCpuConsumer() const {
918 if (mCpuConsumer == NULL) {
Dan Stoza6d5a7bb2014-03-13 11:39:09 -0700919 sp<IGraphicBufferConsumer> consumer;
920 BufferQueue::createBufferQueue(&mProducer, &consumer);
921 mCpuConsumer = new CpuConsumer(consumer, 1);
Mathias Agopianabe815d2013-03-19 22:22:21 -0700922 mCpuConsumer->setName(String8("ScreenshotClient"));
923 }
924 return mCpuConsumer;
Mathias Agopianbf2c6a62010-12-10 16:22:31 -0800925}
926
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700927status_t ScreenshotClient::update(const sp<IBinder>& display,
Dan Stozac1879002014-05-22 15:59:05 -0700928 Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
Robert Carrae060832016-11-28 10:51:00 -0800929 int32_t minLayerZ, int32_t maxLayerZ,
Riley Andrewsd15ef272014-09-04 16:19:44 -0700930 bool useIdentityTransform, uint32_t rotation) {
Mathias Agopianbf2c6a62010-12-10 16:22:31 -0800931 sp<ISurfaceComposer> s(ComposerService::getComposerService());
932 if (s == NULL) return NO_INIT;
Mathias Agopianabe815d2013-03-19 22:22:21 -0700933 sp<CpuConsumer> cpuConsumer = getCpuConsumer();
934
935 if (mHaveBuffer) {
936 mCpuConsumer->unlockBuffer(mBuffer);
937 memset(&mBuffer, 0, sizeof(mBuffer));
938 mHaveBuffer = false;
939 }
940
Dan Stozac1879002014-05-22 15:59:05 -0700941 status_t err = s->captureScreen(display, mProducer, sourceCrop,
Riley Andrewsd15ef272014-09-04 16:19:44 -0700942 reqWidth, reqHeight, minLayerZ, maxLayerZ, useIdentityTransform,
943 static_cast<ISurfaceComposer::Rotation>(rotation));
Mathias Agopianabe815d2013-03-19 22:22:21 -0700944
945 if (err == NO_ERROR) {
946 err = mCpuConsumer->lockNextBuffer(&mBuffer);
947 if (err == NO_ERROR) {
948 mHaveBuffer = true;
949 }
950 }
951 return err;
952}
953
Riley Andrewsd15ef272014-09-04 16:19:44 -0700954status_t ScreenshotClient::update(const sp<IBinder>& display,
955 Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
Robert Carrae060832016-11-28 10:51:00 -0800956 int32_t minLayerZ, int32_t maxLayerZ,
Riley Andrewsd15ef272014-09-04 16:19:44 -0700957 bool useIdentityTransform) {
958
959 return ScreenshotClient::update(display, sourceCrop, reqWidth, reqHeight,
960 minLayerZ, maxLayerZ, useIdentityTransform, ISurfaceComposer::eRotateNone);
961}
962
Dan Stozac1879002014-05-22 15:59:05 -0700963status_t ScreenshotClient::update(const sp<IBinder>& display, Rect sourceCrop,
Dan Stozac7014012014-02-14 15:03:43 -0800964 bool useIdentityTransform) {
Robert Carrae060832016-11-28 10:51:00 -0800965 return ScreenshotClient::update(display, sourceCrop, 0, 0,
966 INT32_MIN, INT32_MAX,
Riley Andrewsd15ef272014-09-04 16:19:44 -0700967 useIdentityTransform, ISurfaceComposer::eRotateNone);
Mathias Agopianabe815d2013-03-19 22:22:21 -0700968}
969
Dan Stozac1879002014-05-22 15:59:05 -0700970status_t ScreenshotClient::update(const sp<IBinder>& display, Rect sourceCrop,
Dan Stozac7014012014-02-14 15:03:43 -0800971 uint32_t reqWidth, uint32_t reqHeight, bool useIdentityTransform) {
Dan Stozac1879002014-05-22 15:59:05 -0700972 return ScreenshotClient::update(display, sourceCrop, reqWidth, reqHeight,
Robert Carrae060832016-11-28 10:51:00 -0800973 INT32_MIN, INT32_MAX,
974 useIdentityTransform, ISurfaceComposer::eRotateNone);
Mathias Agopian74c40c02010-09-29 13:02:36 -0700975}
976
977void ScreenshotClient::release() {
Mathias Agopianabe815d2013-03-19 22:22:21 -0700978 if (mHaveBuffer) {
979 mCpuConsumer->unlockBuffer(mBuffer);
980 memset(&mBuffer, 0, sizeof(mBuffer));
981 mHaveBuffer = false;
982 }
983 mCpuConsumer.clear();
Mathias Agopian74c40c02010-09-29 13:02:36 -0700984}
985
986void const* ScreenshotClient::getPixels() const {
Mathias Agopianabe815d2013-03-19 22:22:21 -0700987 return mBuffer.data;
Mathias Agopian74c40c02010-09-29 13:02:36 -0700988}
989
990uint32_t ScreenshotClient::getWidth() const {
Mathias Agopianabe815d2013-03-19 22:22:21 -0700991 return mBuffer.width;
Mathias Agopian74c40c02010-09-29 13:02:36 -0700992}
993
994uint32_t ScreenshotClient::getHeight() const {
Mathias Agopianabe815d2013-03-19 22:22:21 -0700995 return mBuffer.height;
Mathias Agopian74c40c02010-09-29 13:02:36 -0700996}
997
998PixelFormat ScreenshotClient::getFormat() const {
Mathias Agopianabe815d2013-03-19 22:22:21 -0700999 return mBuffer.format;
Mathias Agopian74c40c02010-09-29 13:02:36 -07001000}
1001
1002uint32_t ScreenshotClient::getStride() const {
Mathias Agopianabe815d2013-03-19 22:22:21 -07001003 return mBuffer.stride;
Mathias Agopian74c40c02010-09-29 13:02:36 -07001004}
1005
1006size_t ScreenshotClient::getSize() const {
Mathias Agopianabe815d2013-03-19 22:22:21 -07001007 return mBuffer.stride * mBuffer.height * bytesPerPixel(mBuffer.format);
Mathias Agopian74c40c02010-09-29 13:02:36 -07001008}
1009
1010// ----------------------------------------------------------------------------
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001011}; // namespace android