blob: 6ad47d8b715410ddbb2107f584f0b64e728e7efa [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
Mathias Agopian076b1cc2009-04-10 14:24:30 -070032#include <ui/DisplayInfo.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080033
Mathias Agopianabe815d2013-03-19 22:22:21 -070034#include <gui/CpuConsumer.h>
Mathias Agopiane3c697f2013-02-14 17:11:02 -080035#include <gui/IGraphicBufferProducer.h>
Mathias Agopian90ac7992012-02-25 18:48:35 -080036#include <gui/ISurfaceComposer.h>
37#include <gui/ISurfaceComposerClient.h>
38#include <gui/SurfaceComposerClient.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080039
Mathias Agopian41f673c2011-11-17 17:48:35 -080040#include <private/gui/ComposerService.h>
Mathias Agopian90ac7992012-02-25 18:48:35 -080041#include <private/gui/LayerState.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080042
43namespace android {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080044// ---------------------------------------------------------------------------
45
Mathias Agopian7e27f052010-05-28 14:22:23 -070046ANDROID_SINGLETON_STATIC_INSTANCE(ComposerService);
47
Mathias Agopianb7e930d2010-06-01 15:12:58 -070048ComposerService::ComposerService()
49: Singleton<ComposerService>() {
Andy McFadden6652b3e2012-09-06 18:45:56 -070050 Mutex::Autolock _l(mLock);
51 connectLocked();
52}
53
54void ComposerService::connectLocked() {
Mathias Agopianb7e930d2010-06-01 15:12:58 -070055 const String16 name("SurfaceFlinger");
56 while (getService(name, &mComposerService) != NO_ERROR) {
57 usleep(250000);
58 }
Andy McFadden6652b3e2012-09-06 18:45:56 -070059 assert(mComposerService != NULL);
60
61 // Create the death listener.
62 class DeathObserver : public IBinder::DeathRecipient {
63 ComposerService& mComposerService;
64 virtual void binderDied(const wp<IBinder>& who) {
65 ALOGW("ComposerService remote (surfaceflinger) died [%p]",
66 who.unsafe_get());
67 mComposerService.composerServiceDied();
68 }
69 public:
70 DeathObserver(ComposerService& mgr) : mComposerService(mgr) { }
71 };
72
73 mDeathObserver = new DeathObserver(*const_cast<ComposerService*>(this));
Marco Nelissen2ea926b2014-11-14 08:01:01 -080074 IInterface::asBinder(mComposerService)->linkToDeath(mDeathObserver);
Mathias Agopianb7e930d2010-06-01 15:12:58 -070075}
76
Andy McFadden6652b3e2012-09-06 18:45:56 -070077/*static*/ sp<ISurfaceComposer> ComposerService::getComposerService() {
78 ComposerService& instance = ComposerService::getInstance();
79 Mutex::Autolock _l(instance.mLock);
80 if (instance.mComposerService == NULL) {
81 ComposerService::getInstance().connectLocked();
82 assert(instance.mComposerService != NULL);
83 ALOGD("ComposerService reconnected");
84 }
85 return instance.mComposerService;
86}
87
88void ComposerService::composerServiceDied()
89{
90 Mutex::Autolock _l(mLock);
91 mComposerService = NULL;
92 mDeathObserver = NULL;
Mathias Agopianb7e930d2010-06-01 15:12:58 -070093}
94
Mathias Agopian7e27f052010-05-28 14:22:23 -070095// ---------------------------------------------------------------------------
96
Mathias Agopian698c0872011-06-28 19:09:31 -070097static inline
Mathias Agopiane57f2922012-08-09 16:29:12 -070098int compare_type(const ComposerState& lhs, const ComposerState& rhs) {
Mathias Agopian698c0872011-06-28 19:09:31 -070099 if (lhs.client < rhs.client) return -1;
100 if (lhs.client > rhs.client) return 1;
101 if (lhs.state.surface < rhs.state.surface) return -1;
102 if (lhs.state.surface > rhs.state.surface) return 1;
103 return 0;
104}
105
Mathias Agopiane57f2922012-08-09 16:29:12 -0700106static inline
107int compare_type(const DisplayState& lhs, const DisplayState& rhs) {
108 return compare_type(lhs.token, rhs.token);
109}
110
Mathias Agopian7e27f052010-05-28 14:22:23 -0700111class Composer : public Singleton<Composer>
112{
Mathias Agopiand4784a32010-05-27 19:41:15 -0700113 friend class Singleton<Composer>;
114
Mathias Agopian698c0872011-06-28 19:09:31 -0700115 mutable Mutex mLock;
Mathias Agopiane57f2922012-08-09 16:29:12 -0700116 SortedVector<ComposerState> mComposerStates;
117 SortedVector<DisplayState > mDisplayStates;
Jamie Gennis28378392011-10-12 17:39:00 -0700118 uint32_t mForceSynchronous;
Jeff Brownf3f7db62012-08-31 02:18:38 -0700119 uint32_t mTransactionNestCount;
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700120 bool mAnimation;
Mathias Agopian698c0872011-06-28 19:09:31 -0700121
Jamie Gennisb8d69a52011-10-10 15:48:06 -0700122 Composer() : Singleton<Composer>(),
Jeff Brownf3f7db62012-08-31 02:18:38 -0700123 mForceSynchronous(0), mTransactionNestCount(0),
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700124 mAnimation(false)
Jamie Gennis28378392011-10-12 17:39:00 -0700125 { }
Mathias Agopian698c0872011-06-28 19:09:31 -0700126
Jeff Brownf3f7db62012-08-31 02:18:38 -0700127 void openGlobalTransactionImpl();
Jamie Gennis28378392011-10-12 17:39:00 -0700128 void closeGlobalTransactionImpl(bool synchronous);
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700129 void setAnimationTransactionImpl();
Mathias Agopian698c0872011-06-28 19:09:31 -0700130
131 layer_state_t* getLayerStateLocked(
Mathias Agopianac9fa422013-02-11 16:40:36 -0800132 const sp<SurfaceComposerClient>& client, const sp<IBinder>& id);
Mathias Agopian698c0872011-06-28 19:09:31 -0700133
Mathias Agopiane57f2922012-08-09 16:29:12 -0700134 DisplayState& getDisplayStateLocked(const sp<IBinder>& token);
135
Mathias Agopiand4784a32010-05-27 19:41:15 -0700136public:
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700137 sp<IBinder> createDisplay(const String8& displayName, bool secure);
Jesse Hall6c913be2013-08-08 12:15:49 -0700138 void destroyDisplay(const sp<IBinder>& display);
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700139 sp<IBinder> getBuiltInDisplay(int32_t id);
Mathias Agopian698c0872011-06-28 19:09:31 -0700140
Mathias Agopianac9fa422013-02-11 16:40:36 -0800141 status_t setPosition(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
Mathias Agopian41b6aab2011-08-30 18:51:54 -0700142 float x, float y);
Mathias Agopianac9fa422013-02-11 16:40:36 -0800143 status_t setSize(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
Mathias Agopian698c0872011-06-28 19:09:31 -0700144 uint32_t w, uint32_t h);
Mathias Agopianac9fa422013-02-11 16:40:36 -0800145 status_t setLayer(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
Dan Stozad723bd72014-11-18 10:24:03 -0800146 uint32_t z);
Mathias Agopianac9fa422013-02-11 16:40:36 -0800147 status_t setFlags(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
Mathias Agopian698c0872011-06-28 19:09:31 -0700148 uint32_t flags, uint32_t mask);
149 status_t setTransparentRegionHint(
Mathias Agopianac9fa422013-02-11 16:40:36 -0800150 const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
Mathias Agopian698c0872011-06-28 19:09:31 -0700151 const Region& transparentRegion);
Mathias Agopianac9fa422013-02-11 16:40:36 -0800152 status_t setAlpha(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
Mathias Agopian698c0872011-06-28 19:09:31 -0700153 float alpha);
Mathias Agopianac9fa422013-02-11 16:40:36 -0800154 status_t setMatrix(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
Mathias Agopian698c0872011-06-28 19:09:31 -0700155 float dsdx, float dtdx, float dsdy, float dtdy);
Jamie Gennisb8d69a52011-10-10 15:48:06 -0700156 status_t setOrientation(int orientation);
Mathias Agopianac9fa422013-02-11 16:40:36 -0800157 status_t setCrop(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700158 const Rect& crop);
Mathias Agopian87855782012-07-24 21:41:09 -0700159 status_t setLayerStack(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-11 16:40:36 -0800160 const sp<IBinder>& id, uint32_t layerStack);
Mathias Agopian698c0872011-06-28 19:09:31 -0700161
Andy McFadden2adaf042012-12-18 09:49:45 -0800162 void setDisplaySurface(const sp<IBinder>& token,
163 const sp<IGraphicBufferProducer>& bufferProducer);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700164 void setDisplayLayerStack(const sp<IBinder>& token, uint32_t layerStack);
Mathias Agopian00e8c7a2012-09-04 19:30:46 -0700165 void setDisplayProjection(const sp<IBinder>& token,
166 uint32_t orientation,
167 const Rect& layerStackRect,
168 const Rect& displayRect);
Michael Wright1f6078a2014-06-26 16:01:02 -0700169 void setDisplaySize(const sp<IBinder>& token, uint32_t width, uint32_t height);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700170
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700171 static void setAnimationTransaction() {
172 Composer::getInstance().setAnimationTransactionImpl();
173 }
174
Jeff Brownf3f7db62012-08-31 02:18:38 -0700175 static void openGlobalTransaction() {
176 Composer::getInstance().openGlobalTransactionImpl();
177 }
178
Jamie Gennis28378392011-10-12 17:39:00 -0700179 static void closeGlobalTransaction(bool synchronous) {
180 Composer::getInstance().closeGlobalTransactionImpl(synchronous);
Mathias Agopiand4784a32010-05-27 19:41:15 -0700181 }
182};
183
184ANDROID_SINGLETON_STATIC_INSTANCE(Composer);
185
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800186// ---------------------------------------------------------------------------
187
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700188sp<IBinder> Composer::createDisplay(const String8& displayName, bool secure) {
189 return ComposerService::getComposerService()->createDisplay(displayName,
190 secure);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700191}
192
Jesse Hall6c913be2013-08-08 12:15:49 -0700193void Composer::destroyDisplay(const sp<IBinder>& display) {
194 return ComposerService::getComposerService()->destroyDisplay(display);
195}
196
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700197sp<IBinder> Composer::getBuiltInDisplay(int32_t id) {
198 return ComposerService::getComposerService()->getBuiltInDisplay(id);
199}
200
Jeff Brownf3f7db62012-08-31 02:18:38 -0700201void Composer::openGlobalTransactionImpl() {
202 { // scope for the lock
203 Mutex::Autolock _l(mLock);
204 mTransactionNestCount += 1;
205 }
206}
207
Jamie Gennis28378392011-10-12 17:39:00 -0700208void Composer::closeGlobalTransactionImpl(bool synchronous) {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700209 sp<ISurfaceComposer> sm(ComposerService::getComposerService());
Mathias Agopian698c0872011-06-28 19:09:31 -0700210
211 Vector<ComposerState> transaction;
Mathias Agopian8b33f032012-07-24 20:43:54 -0700212 Vector<DisplayState> displayTransaction;
Jamie Gennis28378392011-10-12 17:39:00 -0700213 uint32_t flags = 0;
Mathias Agopian698c0872011-06-28 19:09:31 -0700214
215 { // scope for the lock
216 Mutex::Autolock _l(mLock);
Jeff Brownf3f7db62012-08-31 02:18:38 -0700217 mForceSynchronous |= synchronous;
218 if (!mTransactionNestCount) {
219 ALOGW("At least one call to closeGlobalTransaction() was not matched by a prior "
220 "call to openGlobalTransaction().");
221 } else if (--mTransactionNestCount) {
222 return;
223 }
224
Mathias Agopiane57f2922012-08-09 16:29:12 -0700225 transaction = mComposerStates;
226 mComposerStates.clear();
Jamie Gennisb8d69a52011-10-10 15:48:06 -0700227
Mathias Agopiane57f2922012-08-09 16:29:12 -0700228 displayTransaction = mDisplayStates;
229 mDisplayStates.clear();
Jamie Gennis28378392011-10-12 17:39:00 -0700230
Jeff Brownf3f7db62012-08-31 02:18:38 -0700231 if (mForceSynchronous) {
Jamie Gennis28378392011-10-12 17:39:00 -0700232 flags |= ISurfaceComposer::eSynchronous;
233 }
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700234 if (mAnimation) {
235 flags |= ISurfaceComposer::eAnimation;
236 }
237
Jamie Gennis28378392011-10-12 17:39:00 -0700238 mForceSynchronous = false;
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700239 mAnimation = false;
Mathias Agopian698c0872011-06-28 19:09:31 -0700240 }
241
Mathias Agopian8b33f032012-07-24 20:43:54 -0700242 sm->setTransactionState(transaction, displayTransaction, flags);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800243}
244
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700245void Composer::setAnimationTransactionImpl() {
246 Mutex::Autolock _l(mLock);
247 mAnimation = true;
248}
249
Mathias Agopian698c0872011-06-28 19:09:31 -0700250layer_state_t* Composer::getLayerStateLocked(
Mathias Agopianac9fa422013-02-11 16:40:36 -0800251 const sp<SurfaceComposerClient>& client, const sp<IBinder>& id) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700252
253 ComposerState s;
254 s.client = client->mClient;
255 s.state.surface = id;
256
Mathias Agopiane57f2922012-08-09 16:29:12 -0700257 ssize_t index = mComposerStates.indexOf(s);
Mathias Agopian698c0872011-06-28 19:09:31 -0700258 if (index < 0) {
259 // we don't have it, add an initialized layer_state to our list
Mathias Agopiane57f2922012-08-09 16:29:12 -0700260 index = mComposerStates.add(s);
Mathias Agopian698c0872011-06-28 19:09:31 -0700261 }
262
Mathias Agopiane57f2922012-08-09 16:29:12 -0700263 ComposerState* const out = mComposerStates.editArray();
Mathias Agopian698c0872011-06-28 19:09:31 -0700264 return &(out[index].state);
265}
266
267status_t Composer::setPosition(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-11 16:40:36 -0800268 const sp<IBinder>& id, float x, float y) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700269 Mutex::Autolock _l(mLock);
270 layer_state_t* s = getLayerStateLocked(client, id);
271 if (!s)
272 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700273 s->what |= layer_state_t::ePositionChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700274 s->x = x;
275 s->y = y;
276 return NO_ERROR;
277}
278
279status_t Composer::setSize(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-11 16:40:36 -0800280 const sp<IBinder>& id, uint32_t w, uint32_t h) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700281 Mutex::Autolock _l(mLock);
282 layer_state_t* s = getLayerStateLocked(client, id);
283 if (!s)
284 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700285 s->what |= layer_state_t::eSizeChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700286 s->w = w;
287 s->h = h;
Jamie Gennis28378392011-10-12 17:39:00 -0700288
289 // Resizing a surface makes the transaction synchronous.
290 mForceSynchronous = true;
291
Mathias Agopian698c0872011-06-28 19:09:31 -0700292 return NO_ERROR;
293}
294
295status_t Composer::setLayer(const sp<SurfaceComposerClient>& client,
Dan Stozad723bd72014-11-18 10:24:03 -0800296 const sp<IBinder>& id, uint32_t z) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700297 Mutex::Autolock _l(mLock);
298 layer_state_t* s = getLayerStateLocked(client, id);
299 if (!s)
300 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700301 s->what |= layer_state_t::eLayerChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700302 s->z = z;
303 return NO_ERROR;
304}
305
306status_t Composer::setFlags(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-11 16:40:36 -0800307 const sp<IBinder>& id, uint32_t flags,
Mathias Agopian698c0872011-06-28 19:09:31 -0700308 uint32_t mask) {
309 Mutex::Autolock _l(mLock);
310 layer_state_t* s = getLayerStateLocked(client, id);
311 if (!s)
312 return BAD_INDEX;
Dan Stoza23116082015-06-18 14:58:39 -0700313 if (mask & layer_state_t::eLayerOpaque ||
314 mask & layer_state_t::eLayerHidden ||
315 mask & layer_state_t::eLayerSecure) {
316 s->what |= layer_state_t::eFlagsChanged;
Andy McFadden4125a4f2014-01-29 17:17:11 -0800317 }
Mathias Agopian698c0872011-06-28 19:09:31 -0700318 s->flags &= ~mask;
319 s->flags |= (flags & mask);
320 s->mask |= mask;
321 return NO_ERROR;
322}
323
324status_t Composer::setTransparentRegionHint(
Mathias Agopianac9fa422013-02-11 16:40:36 -0800325 const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
Mathias Agopian698c0872011-06-28 19:09:31 -0700326 const Region& transparentRegion) {
327 Mutex::Autolock _l(mLock);
328 layer_state_t* s = getLayerStateLocked(client, id);
329 if (!s)
330 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700331 s->what |= layer_state_t::eTransparentRegionChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700332 s->transparentRegion = transparentRegion;
333 return NO_ERROR;
334}
335
336status_t Composer::setAlpha(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-11 16:40:36 -0800337 const sp<IBinder>& id, float alpha) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700338 Mutex::Autolock _l(mLock);
339 layer_state_t* s = getLayerStateLocked(client, id);
340 if (!s)
341 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700342 s->what |= layer_state_t::eAlphaChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700343 s->alpha = alpha;
344 return NO_ERROR;
345}
346
Mathias Agopian87855782012-07-24 21:41:09 -0700347status_t Composer::setLayerStack(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-11 16:40:36 -0800348 const sp<IBinder>& id, uint32_t layerStack) {
Mathias Agopian87855782012-07-24 21:41:09 -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::eLayerStackChanged;
Mathias Agopian87855782012-07-24 21:41:09 -0700354 s->layerStack = layerStack;
355 return NO_ERROR;
356}
357
Mathias Agopian698c0872011-06-28 19:09:31 -0700358status_t Composer::setMatrix(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-11 16:40:36 -0800359 const sp<IBinder>& id, float dsdx, float dtdx,
Mathias Agopian698c0872011-06-28 19:09:31 -0700360 float dsdy, float dtdy) {
361 Mutex::Autolock _l(mLock);
362 layer_state_t* s = getLayerStateLocked(client, id);
363 if (!s)
364 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700365 s->what |= layer_state_t::eMatrixChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700366 layer_state_t::matrix22_t matrix;
367 matrix.dsdx = dsdx;
368 matrix.dtdx = dtdx;
369 matrix.dsdy = dsdy;
370 matrix.dtdy = dtdy;
371 s->matrix = matrix;
372 return NO_ERROR;
373}
374
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700375status_t Composer::setCrop(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-11 16:40:36 -0800376 const sp<IBinder>& id, const Rect& crop) {
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700377 Mutex::Autolock _l(mLock);
378 layer_state_t* s = getLayerStateLocked(client, id);
379 if (!s)
380 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700381 s->what |= layer_state_t::eCropChanged;
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700382 s->crop = crop;
383 return NO_ERROR;
384}
385
Mathias Agopian698c0872011-06-28 19:09:31 -0700386// ---------------------------------------------------------------------------
387
Mathias Agopiane57f2922012-08-09 16:29:12 -0700388DisplayState& Composer::getDisplayStateLocked(const sp<IBinder>& token) {
389 DisplayState s;
390 s.token = token;
391 ssize_t index = mDisplayStates.indexOf(s);
392 if (index < 0) {
393 // we don't have it, add an initialized layer_state to our list
394 s.what = 0;
395 index = mDisplayStates.add(s);
396 }
Dan Stozad723bd72014-11-18 10:24:03 -0800397 return mDisplayStates.editItemAt(static_cast<size_t>(index));
Mathias Agopiane57f2922012-08-09 16:29:12 -0700398}
399
400void Composer::setDisplaySurface(const sp<IBinder>& token,
Andy McFadden2adaf042012-12-18 09:49:45 -0800401 const sp<IGraphicBufferProducer>& bufferProducer) {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700402 Mutex::Autolock _l(mLock);
403 DisplayState& s(getDisplayStateLocked(token));
Andy McFadden2adaf042012-12-18 09:49:45 -0800404 s.surface = bufferProducer;
Mathias Agopiane57f2922012-08-09 16:29:12 -0700405 s.what |= DisplayState::eSurfaceChanged;
406}
407
408void Composer::setDisplayLayerStack(const sp<IBinder>& token,
409 uint32_t layerStack) {
410 Mutex::Autolock _l(mLock);
411 DisplayState& s(getDisplayStateLocked(token));
412 s.layerStack = layerStack;
413 s.what |= DisplayState::eLayerStackChanged;
414}
415
Mathias Agopian00e8c7a2012-09-04 19:30:46 -0700416void Composer::setDisplayProjection(const sp<IBinder>& token,
417 uint32_t orientation,
418 const Rect& layerStackRect,
419 const Rect& displayRect) {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700420 Mutex::Autolock _l(mLock);
421 DisplayState& s(getDisplayStateLocked(token));
422 s.orientation = orientation;
Mathias Agopian00e8c7a2012-09-04 19:30:46 -0700423 s.viewport = layerStackRect;
424 s.frame = displayRect;
425 s.what |= DisplayState::eDisplayProjectionChanged;
Mathias Agopiane57f2922012-08-09 16:29:12 -0700426 mForceSynchronous = true; // TODO: do we actually still need this?
427}
428
Michael Wright1f6078a2014-06-26 16:01:02 -0700429void Composer::setDisplaySize(const sp<IBinder>& token, uint32_t width, uint32_t height) {
430 Mutex::Autolock _l(mLock);
431 DisplayState& s(getDisplayStateLocked(token));
432 s.width = width;
433 s.height = height;
434 s.what |= DisplayState::eDisplaySizeChanged;
435}
436
Mathias Agopiane57f2922012-08-09 16:29:12 -0700437// ---------------------------------------------------------------------------
438
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800439SurfaceComposerClient::SurfaceComposerClient()
Mathias Agopian698c0872011-06-28 19:09:31 -0700440 : mStatus(NO_INIT), mComposer(Composer::getInstance())
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800441{
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800442}
443
Mathias Agopian698c0872011-06-28 19:09:31 -0700444void SurfaceComposerClient::onFirstRef() {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700445 sp<ISurfaceComposer> sm(ComposerService::getComposerService());
Mathias Agopiand4784a32010-05-27 19:41:15 -0700446 if (sm != 0) {
Mathias Agopian7e27f052010-05-28 14:22:23 -0700447 sp<ISurfaceComposerClient> conn = sm->createConnection();
Mathias Agopiand4784a32010-05-27 19:41:15 -0700448 if (conn != 0) {
449 mClient = conn;
Mathias Agopiand4784a32010-05-27 19:41:15 -0700450 mStatus = NO_ERROR;
451 }
452 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800453}
454
Mathias Agopian698c0872011-06-28 19:09:31 -0700455SurfaceComposerClient::~SurfaceComposerClient() {
Mathias Agopian631f3582010-05-25 17:51:34 -0700456 dispose();
457}
Mathias Agopiandd3423c2009-09-23 15:44:05 -0700458
Mathias Agopian698c0872011-06-28 19:09:31 -0700459status_t SurfaceComposerClient::initCheck() const {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800460 return mStatus;
461}
462
Mathias Agopian698c0872011-06-28 19:09:31 -0700463sp<IBinder> SurfaceComposerClient::connection() const {
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800464 return IInterface::asBinder(mClient);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800465}
466
Mathias Agopiand4784a32010-05-27 19:41:15 -0700467status_t SurfaceComposerClient::linkToComposerDeath(
468 const sp<IBinder::DeathRecipient>& recipient,
Mathias Agopian698c0872011-06-28 19:09:31 -0700469 void* cookie, uint32_t flags) {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700470 sp<ISurfaceComposer> sm(ComposerService::getComposerService());
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800471 return IInterface::asBinder(sm)->linkToDeath(recipient, cookie, flags);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800472}
473
Mathias Agopian698c0872011-06-28 19:09:31 -0700474void SurfaceComposerClient::dispose() {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800475 // this can be called more than once.
Mathias Agopian7e27f052010-05-28 14:22:23 -0700476 sp<ISurfaceComposerClient> client;
Mathias Agopiand4784a32010-05-27 19:41:15 -0700477 Mutex::Autolock _lm(mLock);
478 if (mClient != 0) {
Mathias Agopiand4784a32010-05-27 19:41:15 -0700479 client = mClient; // hold ref while lock is held
480 mClient.clear();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800481 }
Mathias Agopiand4784a32010-05-27 19:41:15 -0700482 mStatus = NO_INIT;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800483}
484
Mathias Agopian698c0872011-06-28 19:09:31 -0700485sp<SurfaceControl> SurfaceComposerClient::createSurface(
Mathias Agopian698c0872011-06-28 19:09:31 -0700486 const String8& name,
Mathias Agopian698c0872011-06-28 19:09:31 -0700487 uint32_t w,
488 uint32_t h,
489 PixelFormat format,
490 uint32_t flags)
491{
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700492 sp<SurfaceControl> sur;
Mathias Agopian698c0872011-06-28 19:09:31 -0700493 if (mStatus == NO_ERROR) {
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700494 sp<IBinder> handle;
495 sp<IGraphicBufferProducer> gbp;
496 status_t err = mClient->createSurface(name, w, h, format, flags,
497 &handle, &gbp);
498 ALOGE_IF(err, "SurfaceComposerClient::createSurface error %s", strerror(-err));
499 if (err == NO_ERROR) {
500 sur = new SurfaceControl(this, handle, gbp);
Mathias Agopian698c0872011-06-28 19:09:31 -0700501 }
502 }
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700503 return sur;
Mathias Agopian698c0872011-06-28 19:09:31 -0700504}
505
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700506sp<IBinder> SurfaceComposerClient::createDisplay(const String8& displayName,
507 bool secure) {
508 return Composer::getInstance().createDisplay(displayName, secure);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700509}
510
Jesse Hall6c913be2013-08-08 12:15:49 -0700511void SurfaceComposerClient::destroyDisplay(const sp<IBinder>& display) {
512 Composer::getInstance().destroyDisplay(display);
513}
514
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700515sp<IBinder> SurfaceComposerClient::getBuiltInDisplay(int32_t id) {
516 return Composer::getInstance().getBuiltInDisplay(id);
517}
518
Mathias Agopianac9fa422013-02-11 16:40:36 -0800519status_t SurfaceComposerClient::destroySurface(const sp<IBinder>& sid) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700520 if (mStatus != NO_ERROR)
521 return mStatus;
522 status_t err = mClient->destroySurface(sid);
523 return err;
524}
525
Svetoslavd85084b2014-03-20 10:28:31 -0700526status_t SurfaceComposerClient::clearLayerFrameStats(const sp<IBinder>& token) const {
527 if (mStatus != NO_ERROR) {
528 return mStatus;
529 }
530 return mClient->clearLayerFrameStats(token);
531}
532
533status_t SurfaceComposerClient::getLayerFrameStats(const sp<IBinder>& token,
534 FrameStats* outStats) const {
535 if (mStatus != NO_ERROR) {
536 return mStatus;
537 }
538 return mClient->getLayerFrameStats(token, outStats);
539}
540
Mathias Agopian698c0872011-06-28 19:09:31 -0700541inline Composer& SurfaceComposerClient::getComposer() {
542 return mComposer;
543}
544
545// ----------------------------------------------------------------------------
546
547void SurfaceComposerClient::openGlobalTransaction() {
Jeff Brownf3f7db62012-08-31 02:18:38 -0700548 Composer::openGlobalTransaction();
Mathias Agopian698c0872011-06-28 19:09:31 -0700549}
550
Jamie Gennis28378392011-10-12 17:39:00 -0700551void SurfaceComposerClient::closeGlobalTransaction(bool synchronous) {
552 Composer::closeGlobalTransaction(synchronous);
Mathias Agopian698c0872011-06-28 19:09:31 -0700553}
554
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700555void SurfaceComposerClient::setAnimationTransaction() {
556 Composer::setAnimationTransaction();
557}
558
Mathias Agopian698c0872011-06-28 19:09:31 -0700559// ----------------------------------------------------------------------------
560
Mathias Agopianac9fa422013-02-11 16:40:36 -0800561status_t SurfaceComposerClient::setCrop(const sp<IBinder>& id, const Rect& crop) {
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700562 return getComposer().setCrop(this, id, crop);
563}
564
Mathias Agopianac9fa422013-02-11 16:40:36 -0800565status_t SurfaceComposerClient::setPosition(const sp<IBinder>& id, float x, float y) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700566 return getComposer().setPosition(this, id, x, y);
567}
568
Mathias Agopianac9fa422013-02-11 16:40:36 -0800569status_t SurfaceComposerClient::setSize(const sp<IBinder>& id, uint32_t w, uint32_t h) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700570 return getComposer().setSize(this, id, w, h);
571}
572
Dan Stozad723bd72014-11-18 10:24:03 -0800573status_t SurfaceComposerClient::setLayer(const sp<IBinder>& id, uint32_t z) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700574 return getComposer().setLayer(this, id, z);
575}
576
Mathias Agopianac9fa422013-02-11 16:40:36 -0800577status_t SurfaceComposerClient::hide(const sp<IBinder>& id) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700578 return getComposer().setFlags(this, id,
Mathias Agopian3165cc22012-08-08 19:42:09 -0700579 layer_state_t::eLayerHidden,
580 layer_state_t::eLayerHidden);
Mathias Agopian698c0872011-06-28 19:09:31 -0700581}
582
Mathias Agopianac9fa422013-02-11 16:40:36 -0800583status_t SurfaceComposerClient::show(const sp<IBinder>& id) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700584 return getComposer().setFlags(this, id,
585 0,
Mathias Agopian3165cc22012-08-08 19:42:09 -0700586 layer_state_t::eLayerHidden);
Mathias Agopian698c0872011-06-28 19:09:31 -0700587}
588
Mathias Agopianac9fa422013-02-11 16:40:36 -0800589status_t SurfaceComposerClient::setFlags(const sp<IBinder>& id, uint32_t flags,
Mathias Agopian698c0872011-06-28 19:09:31 -0700590 uint32_t mask) {
591 return getComposer().setFlags(this, id, flags, mask);
592}
593
Mathias Agopianac9fa422013-02-11 16:40:36 -0800594status_t SurfaceComposerClient::setTransparentRegionHint(const sp<IBinder>& id,
Mathias Agopian698c0872011-06-28 19:09:31 -0700595 const Region& transparentRegion) {
596 return getComposer().setTransparentRegionHint(this, id, transparentRegion);
597}
598
Mathias Agopianac9fa422013-02-11 16:40:36 -0800599status_t SurfaceComposerClient::setAlpha(const sp<IBinder>& id, float alpha) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700600 return getComposer().setAlpha(this, id, alpha);
601}
602
Mathias Agopianac9fa422013-02-11 16:40:36 -0800603status_t SurfaceComposerClient::setLayerStack(const sp<IBinder>& id, uint32_t layerStack) {
Mathias Agopian87855782012-07-24 21:41:09 -0700604 return getComposer().setLayerStack(this, id, layerStack);
605}
606
Mathias Agopianac9fa422013-02-11 16:40:36 -0800607status_t SurfaceComposerClient::setMatrix(const sp<IBinder>& id, float dsdx, float dtdx,
Mathias Agopian698c0872011-06-28 19:09:31 -0700608 float dsdy, float dtdy) {
609 return getComposer().setMatrix(this, id, dsdx, dtdx, dsdy, dtdy);
610}
611
612// ----------------------------------------------------------------------------
613
Mathias Agopiane57f2922012-08-09 16:29:12 -0700614void SurfaceComposerClient::setDisplaySurface(const sp<IBinder>& token,
Andy McFadden2adaf042012-12-18 09:49:45 -0800615 const sp<IGraphicBufferProducer>& bufferProducer) {
616 Composer::getInstance().setDisplaySurface(token, bufferProducer);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700617}
618
619void SurfaceComposerClient::setDisplayLayerStack(const sp<IBinder>& token,
620 uint32_t layerStack) {
621 Composer::getInstance().setDisplayLayerStack(token, layerStack);
622}
623
Mathias Agopian00e8c7a2012-09-04 19:30:46 -0700624void SurfaceComposerClient::setDisplayProjection(const sp<IBinder>& token,
625 uint32_t orientation,
626 const Rect& layerStackRect,
627 const Rect& displayRect) {
628 Composer::getInstance().setDisplayProjection(token, orientation,
629 layerStackRect, displayRect);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700630}
631
Michael Wright1f6078a2014-06-26 16:01:02 -0700632void SurfaceComposerClient::setDisplaySize(const sp<IBinder>& token,
633 uint32_t width, uint32_t height) {
634 Composer::getInstance().setDisplaySize(token, width, height);
635}
636
Mathias Agopiane57f2922012-08-09 16:29:12 -0700637// ----------------------------------------------------------------------------
638
Dan Stoza7f7da322014-05-02 15:26:25 -0700639status_t SurfaceComposerClient::getDisplayConfigs(
640 const sp<IBinder>& display, Vector<DisplayInfo>* configs)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800641{
Dan Stoza7f7da322014-05-02 15:26:25 -0700642 return ComposerService::getComposerService()->getDisplayConfigs(display, configs);
643}
644
645status_t SurfaceComposerClient::getDisplayInfo(const sp<IBinder>& display,
646 DisplayInfo* info) {
647 Vector<DisplayInfo> configs;
648 status_t result = getDisplayConfigs(display, &configs);
649 if (result != NO_ERROR) {
650 return result;
651 }
652
653 int activeId = getActiveConfig(display);
654 if (activeId < 0) {
655 ALOGE("No active configuration found");
656 return NAME_NOT_FOUND;
657 }
658
Dan Stozad723bd72014-11-18 10:24:03 -0800659 *info = configs[static_cast<size_t>(activeId)];
Dan Stoza7f7da322014-05-02 15:26:25 -0700660 return NO_ERROR;
661}
662
663int SurfaceComposerClient::getActiveConfig(const sp<IBinder>& display) {
664 return ComposerService::getComposerService()->getActiveConfig(display);
665}
666
667status_t SurfaceComposerClient::setActiveConfig(const sp<IBinder>& display, int id) {
668 return ComposerService::getComposerService()->setActiveConfig(display, id);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800669}
670
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700671void SurfaceComposerClient::setDisplayPowerMode(const sp<IBinder>& token,
672 int mode) {
673 ComposerService::getComposerService()->setPowerMode(token, mode);
Jeff Brown2a09bb32012-10-08 19:13:57 -0700674}
675
Svetoslavd85084b2014-03-20 10:28:31 -0700676status_t SurfaceComposerClient::clearAnimationFrameStats() {
677 return ComposerService::getComposerService()->clearAnimationFrameStats();
678}
679
680status_t SurfaceComposerClient::getAnimationFrameStats(FrameStats* outStats) {
681 return ComposerService::getComposerService()->getAnimationFrameStats(outStats);
682}
683
Mathias Agopian698c0872011-06-28 19:09:31 -0700684// ----------------------------------------------------------------------------
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800685
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800686status_t ScreenshotClient::capture(
687 const sp<IBinder>& display,
688 const sp<IGraphicBufferProducer>& producer,
Dan Stozac1879002014-05-22 15:59:05 -0700689 Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
Dan Stozac7014012014-02-14 15:03:43 -0800690 uint32_t minLayerZ, uint32_t maxLayerZ, bool useIdentityTransform) {
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800691 sp<ISurfaceComposer> s(ComposerService::getComposerService());
692 if (s == NULL) return NO_INIT;
Dan Stozac1879002014-05-22 15:59:05 -0700693 return s->captureScreen(display, producer, sourceCrop,
Dan Stozac7014012014-02-14 15:03:43 -0800694 reqWidth, reqHeight, minLayerZ, maxLayerZ, useIdentityTransform);
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800695}
696
Mathias Agopian74c40c02010-09-29 13:02:36 -0700697ScreenshotClient::ScreenshotClient()
Mathias Agopianabe815d2013-03-19 22:22:21 -0700698 : mHaveBuffer(false) {
699 memset(&mBuffer, 0, sizeof(mBuffer));
Mathias Agopian74c40c02010-09-29 13:02:36 -0700700}
701
Mathias Agopian8000d062013-03-26 18:15:35 -0700702ScreenshotClient::~ScreenshotClient() {
703 ScreenshotClient::release();
704}
705
Mathias Agopianabe815d2013-03-19 22:22:21 -0700706sp<CpuConsumer> ScreenshotClient::getCpuConsumer() const {
707 if (mCpuConsumer == NULL) {
Dan Stoza6d5a7bb2014-03-13 11:39:09 -0700708 sp<IGraphicBufferConsumer> consumer;
709 BufferQueue::createBufferQueue(&mProducer, &consumer);
710 mCpuConsumer = new CpuConsumer(consumer, 1);
Mathias Agopianabe815d2013-03-19 22:22:21 -0700711 mCpuConsumer->setName(String8("ScreenshotClient"));
712 }
713 return mCpuConsumer;
Mathias Agopianbf2c6a62010-12-10 16:22:31 -0800714}
715
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700716status_t ScreenshotClient::update(const sp<IBinder>& display,
Dan Stozac1879002014-05-22 15:59:05 -0700717 Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
Dan Stozac7014012014-02-14 15:03:43 -0800718 uint32_t minLayerZ, uint32_t maxLayerZ,
Riley Andrewsd15ef272014-09-04 16:19:44 -0700719 bool useIdentityTransform, uint32_t rotation) {
Mathias Agopianbf2c6a62010-12-10 16:22:31 -0800720 sp<ISurfaceComposer> s(ComposerService::getComposerService());
721 if (s == NULL) return NO_INIT;
Mathias Agopianabe815d2013-03-19 22:22:21 -0700722 sp<CpuConsumer> cpuConsumer = getCpuConsumer();
723
724 if (mHaveBuffer) {
725 mCpuConsumer->unlockBuffer(mBuffer);
726 memset(&mBuffer, 0, sizeof(mBuffer));
727 mHaveBuffer = false;
728 }
729
Dan Stozac1879002014-05-22 15:59:05 -0700730 status_t err = s->captureScreen(display, mProducer, sourceCrop,
Riley Andrewsd15ef272014-09-04 16:19:44 -0700731 reqWidth, reqHeight, minLayerZ, maxLayerZ, useIdentityTransform,
732 static_cast<ISurfaceComposer::Rotation>(rotation));
Mathias Agopianabe815d2013-03-19 22:22:21 -0700733
734 if (err == NO_ERROR) {
735 err = mCpuConsumer->lockNextBuffer(&mBuffer);
736 if (err == NO_ERROR) {
737 mHaveBuffer = true;
738 }
739 }
740 return err;
741}
742
Riley Andrewsd15ef272014-09-04 16:19:44 -0700743status_t ScreenshotClient::update(const sp<IBinder>& display,
744 Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
745 uint32_t minLayerZ, uint32_t maxLayerZ,
746 bool useIdentityTransform) {
747
748 return ScreenshotClient::update(display, sourceCrop, reqWidth, reqHeight,
749 minLayerZ, maxLayerZ, useIdentityTransform, ISurfaceComposer::eRotateNone);
750}
751
Dan Stozac1879002014-05-22 15:59:05 -0700752status_t ScreenshotClient::update(const sp<IBinder>& display, Rect sourceCrop,
Dan Stozac7014012014-02-14 15:03:43 -0800753 bool useIdentityTransform) {
Dan Stozaf10c46e2014-11-11 10:32:31 -0800754 return ScreenshotClient::update(display, sourceCrop, 0, 0, 0, -1U,
Riley Andrewsd15ef272014-09-04 16:19:44 -0700755 useIdentityTransform, ISurfaceComposer::eRotateNone);
Mathias Agopianabe815d2013-03-19 22:22:21 -0700756}
757
Dan Stozac1879002014-05-22 15:59:05 -0700758status_t ScreenshotClient::update(const sp<IBinder>& display, Rect sourceCrop,
Dan Stozac7014012014-02-14 15:03:43 -0800759 uint32_t reqWidth, uint32_t reqHeight, bool useIdentityTransform) {
Dan Stozac1879002014-05-22 15:59:05 -0700760 return ScreenshotClient::update(display, sourceCrop, reqWidth, reqHeight,
Dan Stozaf10c46e2014-11-11 10:32:31 -0800761 0, -1U, useIdentityTransform, ISurfaceComposer::eRotateNone);
Mathias Agopian74c40c02010-09-29 13:02:36 -0700762}
763
764void ScreenshotClient::release() {
Mathias Agopianabe815d2013-03-19 22:22:21 -0700765 if (mHaveBuffer) {
766 mCpuConsumer->unlockBuffer(mBuffer);
767 memset(&mBuffer, 0, sizeof(mBuffer));
768 mHaveBuffer = false;
769 }
770 mCpuConsumer.clear();
Mathias Agopian74c40c02010-09-29 13:02:36 -0700771}
772
773void const* ScreenshotClient::getPixels() const {
Mathias Agopianabe815d2013-03-19 22:22:21 -0700774 return mBuffer.data;
Mathias Agopian74c40c02010-09-29 13:02:36 -0700775}
776
777uint32_t ScreenshotClient::getWidth() const {
Mathias Agopianabe815d2013-03-19 22:22:21 -0700778 return mBuffer.width;
Mathias Agopian74c40c02010-09-29 13:02:36 -0700779}
780
781uint32_t ScreenshotClient::getHeight() const {
Mathias Agopianabe815d2013-03-19 22:22:21 -0700782 return mBuffer.height;
Mathias Agopian74c40c02010-09-29 13:02:36 -0700783}
784
785PixelFormat ScreenshotClient::getFormat() const {
Mathias Agopianabe815d2013-03-19 22:22:21 -0700786 return mBuffer.format;
Mathias Agopian74c40c02010-09-29 13:02:36 -0700787}
788
789uint32_t ScreenshotClient::getStride() const {
Mathias Agopianabe815d2013-03-19 22:22:21 -0700790 return mBuffer.stride;
Mathias Agopian74c40c02010-09-29 13:02:36 -0700791}
792
793size_t ScreenshotClient::getSize() const {
Mathias Agopianabe815d2013-03-19 22:22:21 -0700794 return mBuffer.stride * mBuffer.height * bytesPerPixel(mBuffer.format);
Mathias Agopian74c40c02010-09-29 13:02:36 -0700795}
796
797// ----------------------------------------------------------------------------
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800798}; // namespace android