blob: 3df5f74fc9bdec82eb3fa0b46fc2d692f45ddbf5 [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
Mathias Agopianabe815d2013-03-19 22:22:21 -070036#include <gui/CpuConsumer.h>
Mathias Agopiane3c697f2013-02-14 17:11:02 -080037#include <gui/IGraphicBufferProducer.h>
Mathias Agopian90ac7992012-02-25 18:48:35 -080038#include <gui/ISurfaceComposer.h>
39#include <gui/ISurfaceComposerClient.h>
40#include <gui/SurfaceComposerClient.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080041
Mathias Agopian41f673c2011-11-17 17:48:35 -080042#include <private/gui/ComposerService.h>
Mathias Agopian90ac7992012-02-25 18:48:35 -080043#include <private/gui/LayerState.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080044
45namespace android {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080046// ---------------------------------------------------------------------------
47
Mathias Agopian7e27f052010-05-28 14:22:23 -070048ANDROID_SINGLETON_STATIC_INSTANCE(ComposerService);
49
Mathias Agopianb7e930d2010-06-01 15:12:58 -070050ComposerService::ComposerService()
51: Singleton<ComposerService>() {
Andy McFadden6652b3e2012-09-06 18:45:56 -070052 Mutex::Autolock _l(mLock);
53 connectLocked();
54}
55
56void ComposerService::connectLocked() {
Mathias Agopianb7e930d2010-06-01 15:12:58 -070057 const String16 name("SurfaceFlinger");
58 while (getService(name, &mComposerService) != NO_ERROR) {
59 usleep(250000);
60 }
Andy McFadden6652b3e2012-09-06 18:45:56 -070061 assert(mComposerService != NULL);
62
63 // Create the death listener.
64 class DeathObserver : public IBinder::DeathRecipient {
65 ComposerService& mComposerService;
66 virtual void binderDied(const wp<IBinder>& who) {
67 ALOGW("ComposerService remote (surfaceflinger) died [%p]",
68 who.unsafe_get());
69 mComposerService.composerServiceDied();
70 }
71 public:
72 DeathObserver(ComposerService& mgr) : mComposerService(mgr) { }
73 };
74
75 mDeathObserver = new DeathObserver(*const_cast<ComposerService*>(this));
Marco Nelissen2ea926b2014-11-14 08:01:01 -080076 IInterface::asBinder(mComposerService)->linkToDeath(mDeathObserver);
Mathias Agopianb7e930d2010-06-01 15:12:58 -070077}
78
Andy McFadden6652b3e2012-09-06 18:45:56 -070079/*static*/ sp<ISurfaceComposer> ComposerService::getComposerService() {
80 ComposerService& instance = ComposerService::getInstance();
81 Mutex::Autolock _l(instance.mLock);
82 if (instance.mComposerService == NULL) {
83 ComposerService::getInstance().connectLocked();
84 assert(instance.mComposerService != NULL);
85 ALOGD("ComposerService reconnected");
86 }
87 return instance.mComposerService;
88}
89
90void ComposerService::composerServiceDied()
91{
92 Mutex::Autolock _l(mLock);
93 mComposerService = NULL;
94 mDeathObserver = NULL;
Mathias Agopianb7e930d2010-06-01 15:12:58 -070095}
96
Mathias Agopian7e27f052010-05-28 14:22:23 -070097// ---------------------------------------------------------------------------
98
Mathias Agopian698c0872011-06-28 19:09:31 -070099static inline
Mathias Agopiane57f2922012-08-09 16:29:12 -0700100int compare_type(const ComposerState& lhs, const ComposerState& rhs) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700101 if (lhs.client < rhs.client) return -1;
102 if (lhs.client > rhs.client) return 1;
103 if (lhs.state.surface < rhs.state.surface) return -1;
104 if (lhs.state.surface > rhs.state.surface) return 1;
105 return 0;
106}
107
Mathias Agopiane57f2922012-08-09 16:29:12 -0700108static inline
109int compare_type(const DisplayState& lhs, const DisplayState& rhs) {
110 return compare_type(lhs.token, rhs.token);
111}
112
Mathias Agopian7e27f052010-05-28 14:22:23 -0700113class Composer : public Singleton<Composer>
114{
Mathias Agopiand4784a32010-05-27 19:41:15 -0700115 friend class Singleton<Composer>;
116
Mathias Agopian698c0872011-06-28 19:09:31 -0700117 mutable Mutex mLock;
Mathias Agopiane57f2922012-08-09 16:29:12 -0700118 SortedVector<ComposerState> mComposerStates;
119 SortedVector<DisplayState > mDisplayStates;
Jamie Gennis28378392011-10-12 17:39:00 -0700120 uint32_t mForceSynchronous;
Jeff Brownf3f7db62012-08-31 02:18:38 -0700121 uint32_t mTransactionNestCount;
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700122 bool mAnimation;
Mathias Agopian698c0872011-06-28 19:09:31 -0700123
Jamie Gennisb8d69a52011-10-10 15:48:06 -0700124 Composer() : Singleton<Composer>(),
Jeff Brownf3f7db62012-08-31 02:18:38 -0700125 mForceSynchronous(0), mTransactionNestCount(0),
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700126 mAnimation(false)
Jamie Gennis28378392011-10-12 17:39:00 -0700127 { }
Mathias Agopian698c0872011-06-28 19:09:31 -0700128
Jeff Brownf3f7db62012-08-31 02:18:38 -0700129 void openGlobalTransactionImpl();
Jamie Gennis28378392011-10-12 17:39:00 -0700130 void closeGlobalTransactionImpl(bool synchronous);
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700131 void setAnimationTransactionImpl();
Mathias Agopian698c0872011-06-28 19:09:31 -0700132
133 layer_state_t* getLayerStateLocked(
Mathias Agopianac9fa422013-02-11 16:40:36 -0800134 const sp<SurfaceComposerClient>& client, const sp<IBinder>& id);
Mathias Agopian698c0872011-06-28 19:09:31 -0700135
Mathias Agopiane57f2922012-08-09 16:29:12 -0700136 DisplayState& getDisplayStateLocked(const sp<IBinder>& token);
137
Mathias Agopiand4784a32010-05-27 19:41:15 -0700138public:
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700139 sp<IBinder> createDisplay(const String8& displayName, bool secure);
Jesse Hall6c913be2013-08-08 12:15:49 -0700140 void destroyDisplay(const sp<IBinder>& display);
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700141 sp<IBinder> getBuiltInDisplay(int32_t id);
Mathias Agopian698c0872011-06-28 19:09:31 -0700142
Mathias Agopianac9fa422013-02-11 16:40:36 -0800143 status_t setPosition(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
Mathias Agopian41b6aab2011-08-30 18:51:54 -0700144 float x, float y);
Mathias Agopianac9fa422013-02-11 16:40:36 -0800145 status_t setSize(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
Mathias Agopian698c0872011-06-28 19:09:31 -0700146 uint32_t w, uint32_t h);
Mathias Agopianac9fa422013-02-11 16:40:36 -0800147 status_t setLayer(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
Dan Stozad723bd72014-11-18 10:24:03 -0800148 uint32_t z);
Mathias Agopianac9fa422013-02-11 16:40:36 -0800149 status_t setFlags(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
Mathias Agopian698c0872011-06-28 19:09:31 -0700150 uint32_t flags, uint32_t mask);
151 status_t setTransparentRegionHint(
Mathias Agopianac9fa422013-02-11 16:40:36 -0800152 const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
Mathias Agopian698c0872011-06-28 19:09:31 -0700153 const Region& transparentRegion);
Mathias Agopianac9fa422013-02-11 16:40:36 -0800154 status_t setAlpha(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
Mathias Agopian698c0872011-06-28 19:09:31 -0700155 float alpha);
Mathias Agopianac9fa422013-02-11 16:40:36 -0800156 status_t setMatrix(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
Mathias Agopian698c0872011-06-28 19:09:31 -0700157 float dsdx, float dtdx, float dsdy, float dtdy);
Jamie Gennisb8d69a52011-10-10 15:48:06 -0700158 status_t setOrientation(int orientation);
Mathias Agopianac9fa422013-02-11 16:40:36 -0800159 status_t setCrop(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700160 const Rect& crop);
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000161 status_t setFinalCrop(const sp<SurfaceComposerClient>& client,
162 const sp<IBinder>& id, const Rect& crop);
Mathias Agopian87855782012-07-24 21:41:09 -0700163 status_t setLayerStack(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-11 16:40:36 -0800164 const sp<IBinder>& id, uint32_t layerStack);
Dan Stoza7dde5992015-05-22 09:51:44 -0700165 status_t deferTransactionUntil(const sp<SurfaceComposerClient>& client,
166 const sp<IBinder>& id, const sp<IBinder>& handle,
167 uint64_t frameNumber);
Robert Carrc3574f72016-03-24 12:19:32 -0700168 status_t setOverrideScalingMode(const sp<SurfaceComposerClient>& client,
169 const sp<IBinder>& id, int32_t overrideScalingMode);
Robert Carr99e27f02016-06-16 15:18:02 -0700170 status_t setGeometryAppliesWithResize(const sp<SurfaceComposerClient>& client,
Robert Carr82364e32016-05-15 11:27:47 -0700171 const sp<IBinder>& id);
Mathias Agopian698c0872011-06-28 19:09:31 -0700172
Andy McFadden2adaf042012-12-18 09:49:45 -0800173 void setDisplaySurface(const sp<IBinder>& token,
174 const sp<IGraphicBufferProducer>& bufferProducer);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700175 void setDisplayLayerStack(const sp<IBinder>& token, uint32_t layerStack);
Mathias Agopian00e8c7a2012-09-04 19:30:46 -0700176 void setDisplayProjection(const sp<IBinder>& token,
177 uint32_t orientation,
178 const Rect& layerStackRect,
179 const Rect& displayRect);
Michael Wright1f6078a2014-06-26 16:01:02 -0700180 void setDisplaySize(const sp<IBinder>& token, uint32_t width, uint32_t height);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700181
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700182 static void setAnimationTransaction() {
183 Composer::getInstance().setAnimationTransactionImpl();
184 }
185
Jeff Brownf3f7db62012-08-31 02:18:38 -0700186 static void openGlobalTransaction() {
187 Composer::getInstance().openGlobalTransactionImpl();
188 }
189
Jamie Gennis28378392011-10-12 17:39:00 -0700190 static void closeGlobalTransaction(bool synchronous) {
191 Composer::getInstance().closeGlobalTransactionImpl(synchronous);
Mathias Agopiand4784a32010-05-27 19:41:15 -0700192 }
193};
194
195ANDROID_SINGLETON_STATIC_INSTANCE(Composer);
196
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800197// ---------------------------------------------------------------------------
198
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700199sp<IBinder> Composer::createDisplay(const String8& displayName, bool secure) {
200 return ComposerService::getComposerService()->createDisplay(displayName,
201 secure);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700202}
203
Jesse Hall6c913be2013-08-08 12:15:49 -0700204void Composer::destroyDisplay(const sp<IBinder>& display) {
205 return ComposerService::getComposerService()->destroyDisplay(display);
206}
207
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700208sp<IBinder> Composer::getBuiltInDisplay(int32_t id) {
209 return ComposerService::getComposerService()->getBuiltInDisplay(id);
210}
211
Jeff Brownf3f7db62012-08-31 02:18:38 -0700212void Composer::openGlobalTransactionImpl() {
213 { // scope for the lock
214 Mutex::Autolock _l(mLock);
215 mTransactionNestCount += 1;
216 }
217}
218
Jamie Gennis28378392011-10-12 17:39:00 -0700219void Composer::closeGlobalTransactionImpl(bool synchronous) {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700220 sp<ISurfaceComposer> sm(ComposerService::getComposerService());
Mathias Agopian698c0872011-06-28 19:09:31 -0700221
222 Vector<ComposerState> transaction;
Mathias Agopian8b33f032012-07-24 20:43:54 -0700223 Vector<DisplayState> displayTransaction;
Jamie Gennis28378392011-10-12 17:39:00 -0700224 uint32_t flags = 0;
Mathias Agopian698c0872011-06-28 19:09:31 -0700225
226 { // scope for the lock
227 Mutex::Autolock _l(mLock);
Jeff Brownf3f7db62012-08-31 02:18:38 -0700228 mForceSynchronous |= synchronous;
229 if (!mTransactionNestCount) {
230 ALOGW("At least one call to closeGlobalTransaction() was not matched by a prior "
231 "call to openGlobalTransaction().");
232 } else if (--mTransactionNestCount) {
233 return;
234 }
235
Mathias Agopiane57f2922012-08-09 16:29:12 -0700236 transaction = mComposerStates;
237 mComposerStates.clear();
Jamie Gennisb8d69a52011-10-10 15:48:06 -0700238
Mathias Agopiane57f2922012-08-09 16:29:12 -0700239 displayTransaction = mDisplayStates;
240 mDisplayStates.clear();
Jamie Gennis28378392011-10-12 17:39:00 -0700241
Jeff Brownf3f7db62012-08-31 02:18:38 -0700242 if (mForceSynchronous) {
Jamie Gennis28378392011-10-12 17:39:00 -0700243 flags |= ISurfaceComposer::eSynchronous;
244 }
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700245 if (mAnimation) {
246 flags |= ISurfaceComposer::eAnimation;
247 }
248
Jamie Gennis28378392011-10-12 17:39:00 -0700249 mForceSynchronous = false;
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700250 mAnimation = false;
Mathias Agopian698c0872011-06-28 19:09:31 -0700251 }
252
Mathias Agopian8b33f032012-07-24 20:43:54 -0700253 sm->setTransactionState(transaction, displayTransaction, flags);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800254}
255
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700256void Composer::setAnimationTransactionImpl() {
257 Mutex::Autolock _l(mLock);
258 mAnimation = true;
259}
260
Mathias Agopian698c0872011-06-28 19:09:31 -0700261layer_state_t* Composer::getLayerStateLocked(
Mathias Agopianac9fa422013-02-11 16:40:36 -0800262 const sp<SurfaceComposerClient>& client, const sp<IBinder>& id) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700263
264 ComposerState s;
265 s.client = client->mClient;
266 s.state.surface = id;
267
Mathias Agopiane57f2922012-08-09 16:29:12 -0700268 ssize_t index = mComposerStates.indexOf(s);
Mathias Agopian698c0872011-06-28 19:09:31 -0700269 if (index < 0) {
270 // we don't have it, add an initialized layer_state to our list
Mathias Agopiane57f2922012-08-09 16:29:12 -0700271 index = mComposerStates.add(s);
Mathias Agopian698c0872011-06-28 19:09:31 -0700272 }
273
Mathias Agopiane57f2922012-08-09 16:29:12 -0700274 ComposerState* const out = mComposerStates.editArray();
Mathias Agopian698c0872011-06-28 19:09:31 -0700275 return &(out[index].state);
276}
277
278status_t Composer::setPosition(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-11 16:40:36 -0800279 const sp<IBinder>& id, float x, float y) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700280 Mutex::Autolock _l(mLock);
281 layer_state_t* s = getLayerStateLocked(client, id);
282 if (!s)
283 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700284 s->what |= layer_state_t::ePositionChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700285 s->x = x;
286 s->y = y;
287 return NO_ERROR;
288}
289
290status_t Composer::setSize(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-11 16:40:36 -0800291 const sp<IBinder>& id, uint32_t w, uint32_t h) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700292 Mutex::Autolock _l(mLock);
293 layer_state_t* s = getLayerStateLocked(client, id);
294 if (!s)
295 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700296 s->what |= layer_state_t::eSizeChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700297 s->w = w;
298 s->h = h;
Jamie Gennis28378392011-10-12 17:39:00 -0700299
Jorim Jaggi092123c2016-04-13 01:40:35 +0000300 // Resizing a surface makes the transaction synchronous.
301 mForceSynchronous = true;
302
Mathias Agopian698c0872011-06-28 19:09:31 -0700303 return NO_ERROR;
304}
305
306status_t Composer::setLayer(const sp<SurfaceComposerClient>& client,
Dan Stozad723bd72014-11-18 10:24:03 -0800307 const sp<IBinder>& id, uint32_t z) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700308 Mutex::Autolock _l(mLock);
309 layer_state_t* s = getLayerStateLocked(client, id);
310 if (!s)
311 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700312 s->what |= layer_state_t::eLayerChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700313 s->z = z;
314 return NO_ERROR;
315}
316
317status_t Composer::setFlags(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-11 16:40:36 -0800318 const sp<IBinder>& id, uint32_t flags,
Mathias Agopian698c0872011-06-28 19:09:31 -0700319 uint32_t mask) {
320 Mutex::Autolock _l(mLock);
321 layer_state_t* s = getLayerStateLocked(client, id);
322 if (!s)
323 return BAD_INDEX;
Pablo Ceballos53390e12015-08-04 11:25:59 -0700324 if ((mask & layer_state_t::eLayerOpaque) ||
325 (mask & layer_state_t::eLayerHidden) ||
326 (mask & layer_state_t::eLayerSecure)) {
Dan Stoza23116082015-06-18 14:58:39 -0700327 s->what |= layer_state_t::eFlagsChanged;
Andy McFadden4125a4f2014-01-29 17:17:11 -0800328 }
Mathias Agopian698c0872011-06-28 19:09:31 -0700329 s->flags &= ~mask;
330 s->flags |= (flags & mask);
331 s->mask |= mask;
332 return NO_ERROR;
333}
334
335status_t Composer::setTransparentRegionHint(
Mathias Agopianac9fa422013-02-11 16:40:36 -0800336 const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
Mathias Agopian698c0872011-06-28 19:09:31 -0700337 const Region& transparentRegion) {
338 Mutex::Autolock _l(mLock);
339 layer_state_t* s = getLayerStateLocked(client, id);
340 if (!s)
341 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700342 s->what |= layer_state_t::eTransparentRegionChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700343 s->transparentRegion = transparentRegion;
344 return NO_ERROR;
345}
346
347status_t Composer::setAlpha(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-11 16:40:36 -0800348 const sp<IBinder>& id, float alpha) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700349 Mutex::Autolock _l(mLock);
350 layer_state_t* s = getLayerStateLocked(client, id);
351 if (!s)
352 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700353 s->what |= layer_state_t::eAlphaChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700354 s->alpha = alpha;
355 return NO_ERROR;
356}
357
Mathias Agopian87855782012-07-24 21:41:09 -0700358status_t Composer::setLayerStack(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-11 16:40:36 -0800359 const sp<IBinder>& id, uint32_t layerStack) {
Mathias Agopian87855782012-07-24 21:41:09 -0700360 Mutex::Autolock _l(mLock);
361 layer_state_t* s = getLayerStateLocked(client, id);
362 if (!s)
363 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700364 s->what |= layer_state_t::eLayerStackChanged;
Mathias Agopian87855782012-07-24 21:41:09 -0700365 s->layerStack = layerStack;
366 return NO_ERROR;
367}
368
Mathias Agopian698c0872011-06-28 19:09:31 -0700369status_t Composer::setMatrix(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-11 16:40:36 -0800370 const sp<IBinder>& id, float dsdx, float dtdx,
Mathias Agopian698c0872011-06-28 19:09:31 -0700371 float dsdy, float dtdy) {
372 Mutex::Autolock _l(mLock);
373 layer_state_t* s = getLayerStateLocked(client, id);
374 if (!s)
375 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700376 s->what |= layer_state_t::eMatrixChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700377 layer_state_t::matrix22_t matrix;
378 matrix.dsdx = dsdx;
379 matrix.dtdx = dtdx;
380 matrix.dsdy = dsdy;
381 matrix.dtdy = dtdy;
382 s->matrix = matrix;
383 return NO_ERROR;
384}
385
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700386status_t Composer::setCrop(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-11 16:40:36 -0800387 const sp<IBinder>& id, const Rect& crop) {
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700388 Mutex::Autolock _l(mLock);
389 layer_state_t* s = getLayerStateLocked(client, id);
390 if (!s)
391 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700392 s->what |= layer_state_t::eCropChanged;
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700393 s->crop = crop;
394 return NO_ERROR;
395}
396
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000397status_t Composer::setFinalCrop(const sp<SurfaceComposerClient>& client,
398 const sp<IBinder>& id, const Rect& crop) {
399 Mutex::Autolock _l(mLock);
400 layer_state_t* s = getLayerStateLocked(client, id);
401 if (!s) {
402 return BAD_INDEX;
403 }
404 s->what |= layer_state_t::eFinalCropChanged;
405 s->finalCrop = crop;
406 return NO_ERROR;
407}
408
Dan Stoza7dde5992015-05-22 09:51:44 -0700409status_t Composer::deferTransactionUntil(
410 const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
411 const sp<IBinder>& handle, uint64_t frameNumber) {
412 Mutex::Autolock lock(mLock);
413 layer_state_t* s = getLayerStateLocked(client, id);
414 if (!s) {
415 return BAD_INDEX;
416 }
417 s->what |= layer_state_t::eDeferTransaction;
418 s->handle = handle;
419 s->frameNumber = frameNumber;
420 return NO_ERROR;
421}
422
Robert Carrc3574f72016-03-24 12:19:32 -0700423status_t Composer::setOverrideScalingMode(
424 const sp<SurfaceComposerClient>& client,
425 const sp<IBinder>& id, int32_t overrideScalingMode) {
426 Mutex::Autolock lock(mLock);
427 layer_state_t* s = getLayerStateLocked(client, id);
428 if (!s) {
429 return BAD_INDEX;
430 }
431
432 switch (overrideScalingMode) {
433 case NATIVE_WINDOW_SCALING_MODE_FREEZE:
434 case NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW:
435 case NATIVE_WINDOW_SCALING_MODE_SCALE_CROP:
436 case NATIVE_WINDOW_SCALING_MODE_NO_SCALE_CROP:
437 case -1:
438 break;
439 default:
440 ALOGE("unknown scaling mode: %d",
441 overrideScalingMode);
442 return BAD_VALUE;
443 }
444
445 s->what |= layer_state_t::eOverrideScalingModeChanged;
446 s->overrideScalingMode = overrideScalingMode;
447 return NO_ERROR;
448}
449
Robert Carr99e27f02016-06-16 15:18:02 -0700450status_t Composer::setGeometryAppliesWithResize(
Robert Carr82364e32016-05-15 11:27:47 -0700451 const sp<SurfaceComposerClient>& client,
452 const sp<IBinder>& id) {
453 Mutex::Autolock lock(mLock);
454 layer_state_t* s = getLayerStateLocked(client, id);
455 if (!s) {
456 return BAD_INDEX;
457 }
Robert Carr99e27f02016-06-16 15:18:02 -0700458 s->what |= layer_state_t::eGeometryAppliesWithResize;
Robert Carr82364e32016-05-15 11:27:47 -0700459 return NO_ERROR;
460}
461
Mathias Agopian698c0872011-06-28 19:09:31 -0700462// ---------------------------------------------------------------------------
463
Mathias Agopiane57f2922012-08-09 16:29:12 -0700464DisplayState& Composer::getDisplayStateLocked(const sp<IBinder>& token) {
465 DisplayState s;
466 s.token = token;
467 ssize_t index = mDisplayStates.indexOf(s);
468 if (index < 0) {
469 // we don't have it, add an initialized layer_state to our list
470 s.what = 0;
471 index = mDisplayStates.add(s);
472 }
Dan Stozad723bd72014-11-18 10:24:03 -0800473 return mDisplayStates.editItemAt(static_cast<size_t>(index));
Mathias Agopiane57f2922012-08-09 16:29:12 -0700474}
475
476void Composer::setDisplaySurface(const sp<IBinder>& token,
Andy McFadden2adaf042012-12-18 09:49:45 -0800477 const sp<IGraphicBufferProducer>& bufferProducer) {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700478 Mutex::Autolock _l(mLock);
479 DisplayState& s(getDisplayStateLocked(token));
Andy McFadden2adaf042012-12-18 09:49:45 -0800480 s.surface = bufferProducer;
Mathias Agopiane57f2922012-08-09 16:29:12 -0700481 s.what |= DisplayState::eSurfaceChanged;
482}
483
484void Composer::setDisplayLayerStack(const sp<IBinder>& token,
485 uint32_t layerStack) {
486 Mutex::Autolock _l(mLock);
487 DisplayState& s(getDisplayStateLocked(token));
488 s.layerStack = layerStack;
489 s.what |= DisplayState::eLayerStackChanged;
490}
491
Mathias Agopian00e8c7a2012-09-04 19:30:46 -0700492void Composer::setDisplayProjection(const sp<IBinder>& token,
493 uint32_t orientation,
494 const Rect& layerStackRect,
495 const Rect& displayRect) {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700496 Mutex::Autolock _l(mLock);
497 DisplayState& s(getDisplayStateLocked(token));
498 s.orientation = orientation;
Mathias Agopian00e8c7a2012-09-04 19:30:46 -0700499 s.viewport = layerStackRect;
500 s.frame = displayRect;
501 s.what |= DisplayState::eDisplayProjectionChanged;
Jorim Jaggi092123c2016-04-13 01:40:35 +0000502 mForceSynchronous = true; // TODO: do we actually still need this?
Mathias Agopiane57f2922012-08-09 16:29:12 -0700503}
504
Michael Wright1f6078a2014-06-26 16:01:02 -0700505void Composer::setDisplaySize(const sp<IBinder>& token, uint32_t width, uint32_t height) {
506 Mutex::Autolock _l(mLock);
507 DisplayState& s(getDisplayStateLocked(token));
508 s.width = width;
509 s.height = height;
510 s.what |= DisplayState::eDisplaySizeChanged;
511}
512
Mathias Agopiane57f2922012-08-09 16:29:12 -0700513// ---------------------------------------------------------------------------
514
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800515SurfaceComposerClient::SurfaceComposerClient()
Mathias Agopian698c0872011-06-28 19:09:31 -0700516 : mStatus(NO_INIT), mComposer(Composer::getInstance())
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800517{
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800518}
519
Mathias Agopian698c0872011-06-28 19:09:31 -0700520void SurfaceComposerClient::onFirstRef() {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700521 sp<ISurfaceComposer> sm(ComposerService::getComposerService());
Mathias Agopiand4784a32010-05-27 19:41:15 -0700522 if (sm != 0) {
Mathias Agopian7e27f052010-05-28 14:22:23 -0700523 sp<ISurfaceComposerClient> conn = sm->createConnection();
Mathias Agopiand4784a32010-05-27 19:41:15 -0700524 if (conn != 0) {
525 mClient = conn;
Mathias Agopiand4784a32010-05-27 19:41:15 -0700526 mStatus = NO_ERROR;
527 }
528 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800529}
530
Mathias Agopian698c0872011-06-28 19:09:31 -0700531SurfaceComposerClient::~SurfaceComposerClient() {
Mathias Agopian631f3582010-05-25 17:51:34 -0700532 dispose();
533}
Mathias Agopiandd3423c2009-09-23 15:44:05 -0700534
Mathias Agopian698c0872011-06-28 19:09:31 -0700535status_t SurfaceComposerClient::initCheck() const {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800536 return mStatus;
537}
538
Mathias Agopian698c0872011-06-28 19:09:31 -0700539sp<IBinder> SurfaceComposerClient::connection() const {
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800540 return IInterface::asBinder(mClient);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800541}
542
Mathias Agopiand4784a32010-05-27 19:41:15 -0700543status_t SurfaceComposerClient::linkToComposerDeath(
544 const sp<IBinder::DeathRecipient>& recipient,
Mathias Agopian698c0872011-06-28 19:09:31 -0700545 void* cookie, uint32_t flags) {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700546 sp<ISurfaceComposer> sm(ComposerService::getComposerService());
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800547 return IInterface::asBinder(sm)->linkToDeath(recipient, cookie, flags);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800548}
549
Mathias Agopian698c0872011-06-28 19:09:31 -0700550void SurfaceComposerClient::dispose() {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800551 // this can be called more than once.
Mathias Agopian7e27f052010-05-28 14:22:23 -0700552 sp<ISurfaceComposerClient> client;
Mathias Agopiand4784a32010-05-27 19:41:15 -0700553 Mutex::Autolock _lm(mLock);
554 if (mClient != 0) {
Mathias Agopiand4784a32010-05-27 19:41:15 -0700555 client = mClient; // hold ref while lock is held
556 mClient.clear();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800557 }
Mathias Agopiand4784a32010-05-27 19:41:15 -0700558 mStatus = NO_INIT;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800559}
560
Mathias Agopian698c0872011-06-28 19:09:31 -0700561sp<SurfaceControl> SurfaceComposerClient::createSurface(
Mathias Agopian698c0872011-06-28 19:09:31 -0700562 const String8& name,
Mathias Agopian698c0872011-06-28 19:09:31 -0700563 uint32_t w,
564 uint32_t h,
565 PixelFormat format,
566 uint32_t flags)
567{
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700568 sp<SurfaceControl> sur;
Mathias Agopian698c0872011-06-28 19:09:31 -0700569 if (mStatus == NO_ERROR) {
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700570 sp<IBinder> handle;
571 sp<IGraphicBufferProducer> gbp;
572 status_t err = mClient->createSurface(name, w, h, format, flags,
573 &handle, &gbp);
574 ALOGE_IF(err, "SurfaceComposerClient::createSurface error %s", strerror(-err));
575 if (err == NO_ERROR) {
576 sur = new SurfaceControl(this, handle, gbp);
Mathias Agopian698c0872011-06-28 19:09:31 -0700577 }
578 }
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700579 return sur;
Mathias Agopian698c0872011-06-28 19:09:31 -0700580}
581
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700582sp<IBinder> SurfaceComposerClient::createDisplay(const String8& displayName,
583 bool secure) {
584 return Composer::getInstance().createDisplay(displayName, secure);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700585}
586
Jesse Hall6c913be2013-08-08 12:15:49 -0700587void SurfaceComposerClient::destroyDisplay(const sp<IBinder>& display) {
588 Composer::getInstance().destroyDisplay(display);
589}
590
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700591sp<IBinder> SurfaceComposerClient::getBuiltInDisplay(int32_t id) {
592 return Composer::getInstance().getBuiltInDisplay(id);
593}
594
Mathias Agopianac9fa422013-02-11 16:40:36 -0800595status_t SurfaceComposerClient::destroySurface(const sp<IBinder>& sid) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700596 if (mStatus != NO_ERROR)
597 return mStatus;
598 status_t err = mClient->destroySurface(sid);
599 return err;
600}
601
Svetoslavd85084b2014-03-20 10:28:31 -0700602status_t SurfaceComposerClient::clearLayerFrameStats(const sp<IBinder>& token) const {
603 if (mStatus != NO_ERROR) {
604 return mStatus;
605 }
606 return mClient->clearLayerFrameStats(token);
607}
608
609status_t SurfaceComposerClient::getLayerFrameStats(const sp<IBinder>& token,
610 FrameStats* outStats) const {
611 if (mStatus != NO_ERROR) {
612 return mStatus;
613 }
614 return mClient->getLayerFrameStats(token, outStats);
615}
616
Robert Carr367c5682016-06-20 11:55:28 -0700617status_t SurfaceComposerClient::getTransformToDisplayInverse(const sp<IBinder>& token,
618 bool* outTransformToDisplayInverse) const {
619 if (mStatus != NO_ERROR) {
620 return mStatus;
621 }
622 return mClient->getTransformToDisplayInverse(token, outTransformToDisplayInverse);
623}
624
Mathias Agopian698c0872011-06-28 19:09:31 -0700625inline Composer& SurfaceComposerClient::getComposer() {
626 return mComposer;
627}
628
629// ----------------------------------------------------------------------------
630
631void SurfaceComposerClient::openGlobalTransaction() {
Jeff Brownf3f7db62012-08-31 02:18:38 -0700632 Composer::openGlobalTransaction();
Mathias Agopian698c0872011-06-28 19:09:31 -0700633}
634
Jamie Gennis28378392011-10-12 17:39:00 -0700635void SurfaceComposerClient::closeGlobalTransaction(bool synchronous) {
636 Composer::closeGlobalTransaction(synchronous);
Mathias Agopian698c0872011-06-28 19:09:31 -0700637}
638
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700639void SurfaceComposerClient::setAnimationTransaction() {
640 Composer::setAnimationTransaction();
641}
642
Mathias Agopian698c0872011-06-28 19:09:31 -0700643// ----------------------------------------------------------------------------
644
Mathias Agopianac9fa422013-02-11 16:40:36 -0800645status_t SurfaceComposerClient::setCrop(const sp<IBinder>& id, const Rect& crop) {
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700646 return getComposer().setCrop(this, id, crop);
647}
648
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000649status_t SurfaceComposerClient::setFinalCrop(const sp<IBinder>& id,
650 const Rect& crop) {
651 return getComposer().setFinalCrop(this, id, crop);
652}
653
Mathias Agopianac9fa422013-02-11 16:40:36 -0800654status_t SurfaceComposerClient::setPosition(const sp<IBinder>& id, float x, float y) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700655 return getComposer().setPosition(this, id, x, y);
656}
657
Mathias Agopianac9fa422013-02-11 16:40:36 -0800658status_t SurfaceComposerClient::setSize(const sp<IBinder>& id, uint32_t w, uint32_t h) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700659 return getComposer().setSize(this, id, w, h);
660}
661
Dan Stozad723bd72014-11-18 10:24:03 -0800662status_t SurfaceComposerClient::setLayer(const sp<IBinder>& id, uint32_t z) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700663 return getComposer().setLayer(this, id, z);
664}
665
Mathias Agopianac9fa422013-02-11 16:40:36 -0800666status_t SurfaceComposerClient::hide(const sp<IBinder>& id) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700667 return getComposer().setFlags(this, id,
Mathias Agopian3165cc22012-08-08 19:42:09 -0700668 layer_state_t::eLayerHidden,
669 layer_state_t::eLayerHidden);
Mathias Agopian698c0872011-06-28 19:09:31 -0700670}
671
Mathias Agopianac9fa422013-02-11 16:40:36 -0800672status_t SurfaceComposerClient::show(const sp<IBinder>& id) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700673 return getComposer().setFlags(this, id,
674 0,
Mathias Agopian3165cc22012-08-08 19:42:09 -0700675 layer_state_t::eLayerHidden);
Mathias Agopian698c0872011-06-28 19:09:31 -0700676}
677
Mathias Agopianac9fa422013-02-11 16:40:36 -0800678status_t SurfaceComposerClient::setFlags(const sp<IBinder>& id, uint32_t flags,
Mathias Agopian698c0872011-06-28 19:09:31 -0700679 uint32_t mask) {
680 return getComposer().setFlags(this, id, flags, mask);
681}
682
Mathias Agopianac9fa422013-02-11 16:40:36 -0800683status_t SurfaceComposerClient::setTransparentRegionHint(const sp<IBinder>& id,
Mathias Agopian698c0872011-06-28 19:09:31 -0700684 const Region& transparentRegion) {
685 return getComposer().setTransparentRegionHint(this, id, transparentRegion);
686}
687
Mathias Agopianac9fa422013-02-11 16:40:36 -0800688status_t SurfaceComposerClient::setAlpha(const sp<IBinder>& id, float alpha) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700689 return getComposer().setAlpha(this, id, alpha);
690}
691
Mathias Agopianac9fa422013-02-11 16:40:36 -0800692status_t SurfaceComposerClient::setLayerStack(const sp<IBinder>& id, uint32_t layerStack) {
Mathias Agopian87855782012-07-24 21:41:09 -0700693 return getComposer().setLayerStack(this, id, layerStack);
694}
695
Mathias Agopianac9fa422013-02-11 16:40:36 -0800696status_t SurfaceComposerClient::setMatrix(const sp<IBinder>& id, float dsdx, float dtdx,
Mathias Agopian698c0872011-06-28 19:09:31 -0700697 float dsdy, float dtdy) {
698 return getComposer().setMatrix(this, id, dsdx, dtdx, dsdy, dtdy);
699}
700
Dan Stoza7dde5992015-05-22 09:51:44 -0700701status_t SurfaceComposerClient::deferTransactionUntil(const sp<IBinder>& id,
702 const sp<IBinder>& handle, uint64_t frameNumber) {
703 return getComposer().deferTransactionUntil(this, id, handle, frameNumber);
704}
705
Robert Carrc3574f72016-03-24 12:19:32 -0700706status_t SurfaceComposerClient::setOverrideScalingMode(
707 const sp<IBinder>& id, int32_t overrideScalingMode) {
708 return getComposer().setOverrideScalingMode(
709 this, id, overrideScalingMode);
710}
711
Robert Carr99e27f02016-06-16 15:18:02 -0700712status_t SurfaceComposerClient::setGeometryAppliesWithResize(
Robert Carr82364e32016-05-15 11:27:47 -0700713 const sp<IBinder>& id) {
Robert Carr99e27f02016-06-16 15:18:02 -0700714 return getComposer().setGeometryAppliesWithResize(this, id);
Robert Carr82364e32016-05-15 11:27:47 -0700715}
716
Mathias Agopian698c0872011-06-28 19:09:31 -0700717// ----------------------------------------------------------------------------
718
Mathias Agopiane57f2922012-08-09 16:29:12 -0700719void SurfaceComposerClient::setDisplaySurface(const sp<IBinder>& token,
Andy McFadden2adaf042012-12-18 09:49:45 -0800720 const sp<IGraphicBufferProducer>& bufferProducer) {
721 Composer::getInstance().setDisplaySurface(token, bufferProducer);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700722}
723
724void SurfaceComposerClient::setDisplayLayerStack(const sp<IBinder>& token,
725 uint32_t layerStack) {
726 Composer::getInstance().setDisplayLayerStack(token, layerStack);
727}
728
Mathias Agopian00e8c7a2012-09-04 19:30:46 -0700729void SurfaceComposerClient::setDisplayProjection(const sp<IBinder>& token,
730 uint32_t orientation,
731 const Rect& layerStackRect,
732 const Rect& displayRect) {
733 Composer::getInstance().setDisplayProjection(token, orientation,
734 layerStackRect, displayRect);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700735}
736
Michael Wright1f6078a2014-06-26 16:01:02 -0700737void SurfaceComposerClient::setDisplaySize(const sp<IBinder>& token,
738 uint32_t width, uint32_t height) {
739 Composer::getInstance().setDisplaySize(token, width, height);
740}
741
Mathias Agopiane57f2922012-08-09 16:29:12 -0700742// ----------------------------------------------------------------------------
743
Dan Stoza7f7da322014-05-02 15:26:25 -0700744status_t SurfaceComposerClient::getDisplayConfigs(
745 const sp<IBinder>& display, Vector<DisplayInfo>* configs)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800746{
Dan Stoza7f7da322014-05-02 15:26:25 -0700747 return ComposerService::getComposerService()->getDisplayConfigs(display, configs);
748}
749
750status_t SurfaceComposerClient::getDisplayInfo(const sp<IBinder>& display,
751 DisplayInfo* info) {
752 Vector<DisplayInfo> configs;
753 status_t result = getDisplayConfigs(display, &configs);
754 if (result != NO_ERROR) {
755 return result;
756 }
757
758 int activeId = getActiveConfig(display);
759 if (activeId < 0) {
760 ALOGE("No active configuration found");
761 return NAME_NOT_FOUND;
762 }
763
Dan Stozad723bd72014-11-18 10:24:03 -0800764 *info = configs[static_cast<size_t>(activeId)];
Dan Stoza7f7da322014-05-02 15:26:25 -0700765 return NO_ERROR;
766}
767
768int SurfaceComposerClient::getActiveConfig(const sp<IBinder>& display) {
769 return ComposerService::getComposerService()->getActiveConfig(display);
770}
771
772status_t SurfaceComposerClient::setActiveConfig(const sp<IBinder>& display, int id) {
773 return ComposerService::getComposerService()->setActiveConfig(display, id);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800774}
775
Michael Wright28f24d02016-07-12 13:30:53 -0700776status_t SurfaceComposerClient::getDisplayColorModes(const sp<IBinder>& display,
777 Vector<android_color_mode_t>* outColorModes) {
778 return ComposerService::getComposerService()->getDisplayColorModes(display, outColorModes);
779}
780
781android_color_mode_t SurfaceComposerClient::getActiveColorMode(const sp<IBinder>& display) {
782 return ComposerService::getComposerService()->getActiveColorMode(display);
783}
784
785status_t SurfaceComposerClient::setActiveColorMode(const sp<IBinder>& display,
786 android_color_mode_t colorMode) {
787 return ComposerService::getComposerService()->setActiveColorMode(display, colorMode);
788}
789
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700790void SurfaceComposerClient::setDisplayPowerMode(const sp<IBinder>& token,
791 int mode) {
792 ComposerService::getComposerService()->setPowerMode(token, mode);
Jeff Brown2a09bb32012-10-08 19:13:57 -0700793}
794
Svetoslavd85084b2014-03-20 10:28:31 -0700795status_t SurfaceComposerClient::clearAnimationFrameStats() {
796 return ComposerService::getComposerService()->clearAnimationFrameStats();
797}
798
799status_t SurfaceComposerClient::getAnimationFrameStats(FrameStats* outStats) {
800 return ComposerService::getComposerService()->getAnimationFrameStats(outStats);
801}
802
Dan Stozac4f471e2016-03-24 09:31:08 -0700803status_t SurfaceComposerClient::getHdrCapabilities(const sp<IBinder>& display,
804 HdrCapabilities* outCapabilities) {
805 return ComposerService::getComposerService()->getHdrCapabilities(display,
806 outCapabilities);
807}
808
Mathias Agopian698c0872011-06-28 19:09:31 -0700809// ----------------------------------------------------------------------------
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800810
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800811status_t ScreenshotClient::capture(
812 const sp<IBinder>& display,
813 const sp<IGraphicBufferProducer>& producer,
Dan Stozac1879002014-05-22 15:59:05 -0700814 Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
Dan Stozac7014012014-02-14 15:03:43 -0800815 uint32_t minLayerZ, uint32_t maxLayerZ, bool useIdentityTransform) {
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800816 sp<ISurfaceComposer> s(ComposerService::getComposerService());
817 if (s == NULL) return NO_INIT;
Dan Stozac1879002014-05-22 15:59:05 -0700818 return s->captureScreen(display, producer, sourceCrop,
Dan Stozac7014012014-02-14 15:03:43 -0800819 reqWidth, reqHeight, minLayerZ, maxLayerZ, useIdentityTransform);
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800820}
821
Mathias Agopian74c40c02010-09-29 13:02:36 -0700822ScreenshotClient::ScreenshotClient()
Mathias Agopianabe815d2013-03-19 22:22:21 -0700823 : mHaveBuffer(false) {
824 memset(&mBuffer, 0, sizeof(mBuffer));
Mathias Agopian74c40c02010-09-29 13:02:36 -0700825}
826
Mathias Agopian8000d062013-03-26 18:15:35 -0700827ScreenshotClient::~ScreenshotClient() {
828 ScreenshotClient::release();
829}
830
Mathias Agopianabe815d2013-03-19 22:22:21 -0700831sp<CpuConsumer> ScreenshotClient::getCpuConsumer() const {
832 if (mCpuConsumer == NULL) {
Dan Stoza6d5a7bb2014-03-13 11:39:09 -0700833 sp<IGraphicBufferConsumer> consumer;
834 BufferQueue::createBufferQueue(&mProducer, &consumer);
835 mCpuConsumer = new CpuConsumer(consumer, 1);
Mathias Agopianabe815d2013-03-19 22:22:21 -0700836 mCpuConsumer->setName(String8("ScreenshotClient"));
837 }
838 return mCpuConsumer;
Mathias Agopianbf2c6a62010-12-10 16:22:31 -0800839}
840
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700841status_t ScreenshotClient::update(const sp<IBinder>& display,
Dan Stozac1879002014-05-22 15:59:05 -0700842 Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
Dan Stozac7014012014-02-14 15:03:43 -0800843 uint32_t minLayerZ, uint32_t maxLayerZ,
Riley Andrewsd15ef272014-09-04 16:19:44 -0700844 bool useIdentityTransform, uint32_t rotation) {
Mathias Agopianbf2c6a62010-12-10 16:22:31 -0800845 sp<ISurfaceComposer> s(ComposerService::getComposerService());
846 if (s == NULL) return NO_INIT;
Mathias Agopianabe815d2013-03-19 22:22:21 -0700847 sp<CpuConsumer> cpuConsumer = getCpuConsumer();
848
849 if (mHaveBuffer) {
850 mCpuConsumer->unlockBuffer(mBuffer);
851 memset(&mBuffer, 0, sizeof(mBuffer));
852 mHaveBuffer = false;
853 }
854
Dan Stozac1879002014-05-22 15:59:05 -0700855 status_t err = s->captureScreen(display, mProducer, sourceCrop,
Riley Andrewsd15ef272014-09-04 16:19:44 -0700856 reqWidth, reqHeight, minLayerZ, maxLayerZ, useIdentityTransform,
857 static_cast<ISurfaceComposer::Rotation>(rotation));
Mathias Agopianabe815d2013-03-19 22:22:21 -0700858
859 if (err == NO_ERROR) {
860 err = mCpuConsumer->lockNextBuffer(&mBuffer);
861 if (err == NO_ERROR) {
862 mHaveBuffer = true;
863 }
864 }
865 return err;
866}
867
Riley Andrewsd15ef272014-09-04 16:19:44 -0700868status_t ScreenshotClient::update(const sp<IBinder>& display,
869 Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
870 uint32_t minLayerZ, uint32_t maxLayerZ,
871 bool useIdentityTransform) {
872
873 return ScreenshotClient::update(display, sourceCrop, reqWidth, reqHeight,
874 minLayerZ, maxLayerZ, useIdentityTransform, ISurfaceComposer::eRotateNone);
875}
876
Dan Stozac1879002014-05-22 15:59:05 -0700877status_t ScreenshotClient::update(const sp<IBinder>& display, Rect sourceCrop,
Dan Stozac7014012014-02-14 15:03:43 -0800878 bool useIdentityTransform) {
Dan Stozaf10c46e2014-11-11 10:32:31 -0800879 return ScreenshotClient::update(display, sourceCrop, 0, 0, 0, -1U,
Riley Andrewsd15ef272014-09-04 16:19:44 -0700880 useIdentityTransform, ISurfaceComposer::eRotateNone);
Mathias Agopianabe815d2013-03-19 22:22:21 -0700881}
882
Dan Stozac1879002014-05-22 15:59:05 -0700883status_t ScreenshotClient::update(const sp<IBinder>& display, Rect sourceCrop,
Dan Stozac7014012014-02-14 15:03:43 -0800884 uint32_t reqWidth, uint32_t reqHeight, bool useIdentityTransform) {
Dan Stozac1879002014-05-22 15:59:05 -0700885 return ScreenshotClient::update(display, sourceCrop, reqWidth, reqHeight,
Dan Stozaf10c46e2014-11-11 10:32:31 -0800886 0, -1U, useIdentityTransform, ISurfaceComposer::eRotateNone);
Mathias Agopian74c40c02010-09-29 13:02:36 -0700887}
888
889void ScreenshotClient::release() {
Mathias Agopianabe815d2013-03-19 22:22:21 -0700890 if (mHaveBuffer) {
891 mCpuConsumer->unlockBuffer(mBuffer);
892 memset(&mBuffer, 0, sizeof(mBuffer));
893 mHaveBuffer = false;
894 }
895 mCpuConsumer.clear();
Mathias Agopian74c40c02010-09-29 13:02:36 -0700896}
897
898void const* ScreenshotClient::getPixels() const {
Mathias Agopianabe815d2013-03-19 22:22:21 -0700899 return mBuffer.data;
Mathias Agopian74c40c02010-09-29 13:02:36 -0700900}
901
902uint32_t ScreenshotClient::getWidth() const {
Mathias Agopianabe815d2013-03-19 22:22:21 -0700903 return mBuffer.width;
Mathias Agopian74c40c02010-09-29 13:02:36 -0700904}
905
906uint32_t ScreenshotClient::getHeight() const {
Mathias Agopianabe815d2013-03-19 22:22:21 -0700907 return mBuffer.height;
Mathias Agopian74c40c02010-09-29 13:02:36 -0700908}
909
910PixelFormat ScreenshotClient::getFormat() const {
Mathias Agopianabe815d2013-03-19 22:22:21 -0700911 return mBuffer.format;
Mathias Agopian74c40c02010-09-29 13:02:36 -0700912}
913
914uint32_t ScreenshotClient::getStride() const {
Mathias Agopianabe815d2013-03-19 22:22:21 -0700915 return mBuffer.stride;
Mathias Agopian74c40c02010-09-29 13:02:36 -0700916}
917
918size_t ScreenshotClient::getSize() const {
Mathias Agopianabe815d2013-03-19 22:22:21 -0700919 return mBuffer.stride * mBuffer.height * bytesPerPixel(mBuffer.format);
Mathias Agopian74c40c02010-09-29 13:02:36 -0700920}
921
922// ----------------------------------------------------------------------------
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800923}; // namespace android