blob: 3242f550fbb2bc6488a5b49cb32cb429da09070a [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);
Dan Stoza7dde5992015-05-22 09:51:44 -0700161 status_t deferTransactionUntil(const sp<SurfaceComposerClient>& client,
162 const sp<IBinder>& id, const sp<IBinder>& handle,
163 uint64_t frameNumber);
Mathias Agopian698c0872011-06-28 19:09:31 -0700164
Andy McFadden2adaf042012-12-18 09:49:45 -0800165 void setDisplaySurface(const sp<IBinder>& token,
166 const sp<IGraphicBufferProducer>& bufferProducer);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700167 void setDisplayLayerStack(const sp<IBinder>& token, uint32_t layerStack);
Mathias Agopian00e8c7a2012-09-04 19:30:46 -0700168 void setDisplayProjection(const sp<IBinder>& token,
169 uint32_t orientation,
170 const Rect& layerStackRect,
171 const Rect& displayRect);
Michael Wright1f6078a2014-06-26 16:01:02 -0700172 void setDisplaySize(const sp<IBinder>& token, uint32_t width, uint32_t height);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700173
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700174 static void setAnimationTransaction() {
175 Composer::getInstance().setAnimationTransactionImpl();
176 }
177
Jeff Brownf3f7db62012-08-31 02:18:38 -0700178 static void openGlobalTransaction() {
179 Composer::getInstance().openGlobalTransactionImpl();
180 }
181
Jamie Gennis28378392011-10-12 17:39:00 -0700182 static void closeGlobalTransaction(bool synchronous) {
183 Composer::getInstance().closeGlobalTransactionImpl(synchronous);
Mathias Agopiand4784a32010-05-27 19:41:15 -0700184 }
185};
186
187ANDROID_SINGLETON_STATIC_INSTANCE(Composer);
188
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800189// ---------------------------------------------------------------------------
190
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700191sp<IBinder> Composer::createDisplay(const String8& displayName, bool secure) {
192 return ComposerService::getComposerService()->createDisplay(displayName,
193 secure);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700194}
195
Jesse Hall6c913be2013-08-08 12:15:49 -0700196void Composer::destroyDisplay(const sp<IBinder>& display) {
197 return ComposerService::getComposerService()->destroyDisplay(display);
198}
199
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700200sp<IBinder> Composer::getBuiltInDisplay(int32_t id) {
201 return ComposerService::getComposerService()->getBuiltInDisplay(id);
202}
203
Jeff Brownf3f7db62012-08-31 02:18:38 -0700204void Composer::openGlobalTransactionImpl() {
205 { // scope for the lock
206 Mutex::Autolock _l(mLock);
207 mTransactionNestCount += 1;
208 }
209}
210
Jamie Gennis28378392011-10-12 17:39:00 -0700211void Composer::closeGlobalTransactionImpl(bool synchronous) {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700212 sp<ISurfaceComposer> sm(ComposerService::getComposerService());
Mathias Agopian698c0872011-06-28 19:09:31 -0700213
214 Vector<ComposerState> transaction;
Mathias Agopian8b33f032012-07-24 20:43:54 -0700215 Vector<DisplayState> displayTransaction;
Jamie Gennis28378392011-10-12 17:39:00 -0700216 uint32_t flags = 0;
Mathias Agopian698c0872011-06-28 19:09:31 -0700217
218 { // scope for the lock
219 Mutex::Autolock _l(mLock);
Jeff Brownf3f7db62012-08-31 02:18:38 -0700220 mForceSynchronous |= synchronous;
221 if (!mTransactionNestCount) {
222 ALOGW("At least one call to closeGlobalTransaction() was not matched by a prior "
223 "call to openGlobalTransaction().");
224 } else if (--mTransactionNestCount) {
225 return;
226 }
227
Mathias Agopiane57f2922012-08-09 16:29:12 -0700228 transaction = mComposerStates;
229 mComposerStates.clear();
Jamie Gennisb8d69a52011-10-10 15:48:06 -0700230
Mathias Agopiane57f2922012-08-09 16:29:12 -0700231 displayTransaction = mDisplayStates;
232 mDisplayStates.clear();
Jamie Gennis28378392011-10-12 17:39:00 -0700233
Jeff Brownf3f7db62012-08-31 02:18:38 -0700234 if (mForceSynchronous) {
Jamie Gennis28378392011-10-12 17:39:00 -0700235 flags |= ISurfaceComposer::eSynchronous;
236 }
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700237 if (mAnimation) {
238 flags |= ISurfaceComposer::eAnimation;
239 }
240
Jamie Gennis28378392011-10-12 17:39:00 -0700241 mForceSynchronous = false;
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700242 mAnimation = false;
Mathias Agopian698c0872011-06-28 19:09:31 -0700243 }
244
Mathias Agopian8b33f032012-07-24 20:43:54 -0700245 sm->setTransactionState(transaction, displayTransaction, flags);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800246}
247
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700248void Composer::setAnimationTransactionImpl() {
249 Mutex::Autolock _l(mLock);
250 mAnimation = true;
251}
252
Mathias Agopian698c0872011-06-28 19:09:31 -0700253layer_state_t* Composer::getLayerStateLocked(
Mathias Agopianac9fa422013-02-11 16:40:36 -0800254 const sp<SurfaceComposerClient>& client, const sp<IBinder>& id) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700255
256 ComposerState s;
257 s.client = client->mClient;
258 s.state.surface = id;
259
Mathias Agopiane57f2922012-08-09 16:29:12 -0700260 ssize_t index = mComposerStates.indexOf(s);
Mathias Agopian698c0872011-06-28 19:09:31 -0700261 if (index < 0) {
262 // we don't have it, add an initialized layer_state to our list
Mathias Agopiane57f2922012-08-09 16:29:12 -0700263 index = mComposerStates.add(s);
Mathias Agopian698c0872011-06-28 19:09:31 -0700264 }
265
Mathias Agopiane57f2922012-08-09 16:29:12 -0700266 ComposerState* const out = mComposerStates.editArray();
Mathias Agopian698c0872011-06-28 19:09:31 -0700267 return &(out[index].state);
268}
269
270status_t Composer::setPosition(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-11 16:40:36 -0800271 const sp<IBinder>& id, float x, float y) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700272 Mutex::Autolock _l(mLock);
273 layer_state_t* s = getLayerStateLocked(client, id);
274 if (!s)
275 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700276 s->what |= layer_state_t::ePositionChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700277 s->x = x;
278 s->y = y;
279 return NO_ERROR;
280}
281
282status_t Composer::setSize(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-11 16:40:36 -0800283 const sp<IBinder>& id, uint32_t w, uint32_t h) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700284 Mutex::Autolock _l(mLock);
285 layer_state_t* s = getLayerStateLocked(client, id);
286 if (!s)
287 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700288 s->what |= layer_state_t::eSizeChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700289 s->w = w;
290 s->h = h;
Jamie Gennis28378392011-10-12 17:39:00 -0700291
292 // Resizing a surface makes the transaction synchronous.
293 mForceSynchronous = true;
294
Mathias Agopian698c0872011-06-28 19:09:31 -0700295 return NO_ERROR;
296}
297
298status_t Composer::setLayer(const sp<SurfaceComposerClient>& client,
Dan Stozad723bd72014-11-18 10:24:03 -0800299 const sp<IBinder>& id, uint32_t z) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700300 Mutex::Autolock _l(mLock);
301 layer_state_t* s = getLayerStateLocked(client, id);
302 if (!s)
303 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700304 s->what |= layer_state_t::eLayerChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700305 s->z = z;
306 return NO_ERROR;
307}
308
309status_t Composer::setFlags(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-11 16:40:36 -0800310 const sp<IBinder>& id, uint32_t flags,
Mathias Agopian698c0872011-06-28 19:09:31 -0700311 uint32_t mask) {
312 Mutex::Autolock _l(mLock);
313 layer_state_t* s = getLayerStateLocked(client, id);
314 if (!s)
315 return BAD_INDEX;
Pablo Ceballos53390e12015-08-04 11:25:59 -0700316 if ((mask & layer_state_t::eLayerOpaque) ||
317 (mask & layer_state_t::eLayerHidden) ||
318 (mask & layer_state_t::eLayerSecure)) {
Dan Stoza23116082015-06-18 14:58:39 -0700319 s->what |= layer_state_t::eFlagsChanged;
Andy McFadden4125a4f2014-01-29 17:17:11 -0800320 }
Mathias Agopian698c0872011-06-28 19:09:31 -0700321 s->flags &= ~mask;
322 s->flags |= (flags & mask);
323 s->mask |= mask;
324 return NO_ERROR;
325}
326
327status_t Composer::setTransparentRegionHint(
Mathias Agopianac9fa422013-02-11 16:40:36 -0800328 const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
Mathias Agopian698c0872011-06-28 19:09:31 -0700329 const Region& transparentRegion) {
330 Mutex::Autolock _l(mLock);
331 layer_state_t* s = getLayerStateLocked(client, id);
332 if (!s)
333 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700334 s->what |= layer_state_t::eTransparentRegionChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700335 s->transparentRegion = transparentRegion;
336 return NO_ERROR;
337}
338
339status_t Composer::setAlpha(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-11 16:40:36 -0800340 const sp<IBinder>& id, float alpha) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700341 Mutex::Autolock _l(mLock);
342 layer_state_t* s = getLayerStateLocked(client, id);
343 if (!s)
344 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700345 s->what |= layer_state_t::eAlphaChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700346 s->alpha = alpha;
347 return NO_ERROR;
348}
349
Mathias Agopian87855782012-07-24 21:41:09 -0700350status_t Composer::setLayerStack(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-11 16:40:36 -0800351 const sp<IBinder>& id, uint32_t layerStack) {
Mathias Agopian87855782012-07-24 21:41:09 -0700352 Mutex::Autolock _l(mLock);
353 layer_state_t* s = getLayerStateLocked(client, id);
354 if (!s)
355 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700356 s->what |= layer_state_t::eLayerStackChanged;
Mathias Agopian87855782012-07-24 21:41:09 -0700357 s->layerStack = layerStack;
358 return NO_ERROR;
359}
360
Mathias Agopian698c0872011-06-28 19:09:31 -0700361status_t Composer::setMatrix(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-11 16:40:36 -0800362 const sp<IBinder>& id, float dsdx, float dtdx,
Mathias Agopian698c0872011-06-28 19:09:31 -0700363 float dsdy, float dtdy) {
364 Mutex::Autolock _l(mLock);
365 layer_state_t* s = getLayerStateLocked(client, id);
366 if (!s)
367 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700368 s->what |= layer_state_t::eMatrixChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700369 layer_state_t::matrix22_t matrix;
370 matrix.dsdx = dsdx;
371 matrix.dtdx = dtdx;
372 matrix.dsdy = dsdy;
373 matrix.dtdy = dtdy;
374 s->matrix = matrix;
375 return NO_ERROR;
376}
377
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700378status_t Composer::setCrop(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-11 16:40:36 -0800379 const sp<IBinder>& id, const Rect& crop) {
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700380 Mutex::Autolock _l(mLock);
381 layer_state_t* s = getLayerStateLocked(client, id);
382 if (!s)
383 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700384 s->what |= layer_state_t::eCropChanged;
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700385 s->crop = crop;
386 return NO_ERROR;
387}
388
Dan Stoza7dde5992015-05-22 09:51:44 -0700389status_t Composer::deferTransactionUntil(
390 const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
391 const sp<IBinder>& handle, uint64_t frameNumber) {
392 Mutex::Autolock lock(mLock);
393 layer_state_t* s = getLayerStateLocked(client, id);
394 if (!s) {
395 return BAD_INDEX;
396 }
397 s->what |= layer_state_t::eDeferTransaction;
398 s->handle = handle;
399 s->frameNumber = frameNumber;
400 return NO_ERROR;
401}
402
Mathias Agopian698c0872011-06-28 19:09:31 -0700403// ---------------------------------------------------------------------------
404
Mathias Agopiane57f2922012-08-09 16:29:12 -0700405DisplayState& Composer::getDisplayStateLocked(const sp<IBinder>& token) {
406 DisplayState s;
407 s.token = token;
408 ssize_t index = mDisplayStates.indexOf(s);
409 if (index < 0) {
410 // we don't have it, add an initialized layer_state to our list
411 s.what = 0;
412 index = mDisplayStates.add(s);
413 }
Dan Stozad723bd72014-11-18 10:24:03 -0800414 return mDisplayStates.editItemAt(static_cast<size_t>(index));
Mathias Agopiane57f2922012-08-09 16:29:12 -0700415}
416
417void Composer::setDisplaySurface(const sp<IBinder>& token,
Andy McFadden2adaf042012-12-18 09:49:45 -0800418 const sp<IGraphicBufferProducer>& bufferProducer) {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700419 Mutex::Autolock _l(mLock);
420 DisplayState& s(getDisplayStateLocked(token));
Andy McFadden2adaf042012-12-18 09:49:45 -0800421 s.surface = bufferProducer;
Mathias Agopiane57f2922012-08-09 16:29:12 -0700422 s.what |= DisplayState::eSurfaceChanged;
423}
424
425void Composer::setDisplayLayerStack(const sp<IBinder>& token,
426 uint32_t layerStack) {
427 Mutex::Autolock _l(mLock);
428 DisplayState& s(getDisplayStateLocked(token));
429 s.layerStack = layerStack;
430 s.what |= DisplayState::eLayerStackChanged;
431}
432
Mathias Agopian00e8c7a2012-09-04 19:30:46 -0700433void Composer::setDisplayProjection(const sp<IBinder>& token,
434 uint32_t orientation,
435 const Rect& layerStackRect,
436 const Rect& displayRect) {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700437 Mutex::Autolock _l(mLock);
438 DisplayState& s(getDisplayStateLocked(token));
439 s.orientation = orientation;
Mathias Agopian00e8c7a2012-09-04 19:30:46 -0700440 s.viewport = layerStackRect;
441 s.frame = displayRect;
442 s.what |= DisplayState::eDisplayProjectionChanged;
Mathias Agopiane57f2922012-08-09 16:29:12 -0700443 mForceSynchronous = true; // TODO: do we actually still need this?
444}
445
Michael Wright1f6078a2014-06-26 16:01:02 -0700446void Composer::setDisplaySize(const sp<IBinder>& token, uint32_t width, uint32_t height) {
447 Mutex::Autolock _l(mLock);
448 DisplayState& s(getDisplayStateLocked(token));
449 s.width = width;
450 s.height = height;
451 s.what |= DisplayState::eDisplaySizeChanged;
452}
453
Mathias Agopiane57f2922012-08-09 16:29:12 -0700454// ---------------------------------------------------------------------------
455
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800456SurfaceComposerClient::SurfaceComposerClient()
Mathias Agopian698c0872011-06-28 19:09:31 -0700457 : mStatus(NO_INIT), mComposer(Composer::getInstance())
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800458{
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800459}
460
Mathias Agopian698c0872011-06-28 19:09:31 -0700461void SurfaceComposerClient::onFirstRef() {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700462 sp<ISurfaceComposer> sm(ComposerService::getComposerService());
Mathias Agopiand4784a32010-05-27 19:41:15 -0700463 if (sm != 0) {
Mathias Agopian7e27f052010-05-28 14:22:23 -0700464 sp<ISurfaceComposerClient> conn = sm->createConnection();
Mathias Agopiand4784a32010-05-27 19:41:15 -0700465 if (conn != 0) {
466 mClient = conn;
Mathias Agopiand4784a32010-05-27 19:41:15 -0700467 mStatus = NO_ERROR;
468 }
469 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800470}
471
Mathias Agopian698c0872011-06-28 19:09:31 -0700472SurfaceComposerClient::~SurfaceComposerClient() {
Mathias Agopian631f3582010-05-25 17:51:34 -0700473 dispose();
474}
Mathias Agopiandd3423c2009-09-23 15:44:05 -0700475
Mathias Agopian698c0872011-06-28 19:09:31 -0700476status_t SurfaceComposerClient::initCheck() const {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800477 return mStatus;
478}
479
Mathias Agopian698c0872011-06-28 19:09:31 -0700480sp<IBinder> SurfaceComposerClient::connection() const {
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800481 return IInterface::asBinder(mClient);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800482}
483
Mathias Agopiand4784a32010-05-27 19:41:15 -0700484status_t SurfaceComposerClient::linkToComposerDeath(
485 const sp<IBinder::DeathRecipient>& recipient,
Mathias Agopian698c0872011-06-28 19:09:31 -0700486 void* cookie, uint32_t flags) {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700487 sp<ISurfaceComposer> sm(ComposerService::getComposerService());
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800488 return IInterface::asBinder(sm)->linkToDeath(recipient, cookie, flags);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800489}
490
Mathias Agopian698c0872011-06-28 19:09:31 -0700491void SurfaceComposerClient::dispose() {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800492 // this can be called more than once.
Mathias Agopian7e27f052010-05-28 14:22:23 -0700493 sp<ISurfaceComposerClient> client;
Mathias Agopiand4784a32010-05-27 19:41:15 -0700494 Mutex::Autolock _lm(mLock);
495 if (mClient != 0) {
Mathias Agopiand4784a32010-05-27 19:41:15 -0700496 client = mClient; // hold ref while lock is held
497 mClient.clear();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800498 }
Mathias Agopiand4784a32010-05-27 19:41:15 -0700499 mStatus = NO_INIT;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800500}
501
Mathias Agopian698c0872011-06-28 19:09:31 -0700502sp<SurfaceControl> SurfaceComposerClient::createSurface(
Mathias Agopian698c0872011-06-28 19:09:31 -0700503 const String8& name,
Mathias Agopian698c0872011-06-28 19:09:31 -0700504 uint32_t w,
505 uint32_t h,
506 PixelFormat format,
507 uint32_t flags)
508{
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700509 sp<SurfaceControl> sur;
Mathias Agopian698c0872011-06-28 19:09:31 -0700510 if (mStatus == NO_ERROR) {
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700511 sp<IBinder> handle;
512 sp<IGraphicBufferProducer> gbp;
513 status_t err = mClient->createSurface(name, w, h, format, flags,
514 &handle, &gbp);
515 ALOGE_IF(err, "SurfaceComposerClient::createSurface error %s", strerror(-err));
516 if (err == NO_ERROR) {
517 sur = new SurfaceControl(this, handle, gbp);
Mathias Agopian698c0872011-06-28 19:09:31 -0700518 }
519 }
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700520 return sur;
Mathias Agopian698c0872011-06-28 19:09:31 -0700521}
522
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700523sp<IBinder> SurfaceComposerClient::createDisplay(const String8& displayName,
524 bool secure) {
525 return Composer::getInstance().createDisplay(displayName, secure);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700526}
527
Jesse Hall6c913be2013-08-08 12:15:49 -0700528void SurfaceComposerClient::destroyDisplay(const sp<IBinder>& display) {
529 Composer::getInstance().destroyDisplay(display);
530}
531
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700532sp<IBinder> SurfaceComposerClient::getBuiltInDisplay(int32_t id) {
533 return Composer::getInstance().getBuiltInDisplay(id);
534}
535
Mathias Agopianac9fa422013-02-11 16:40:36 -0800536status_t SurfaceComposerClient::destroySurface(const sp<IBinder>& sid) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700537 if (mStatus != NO_ERROR)
538 return mStatus;
539 status_t err = mClient->destroySurface(sid);
540 return err;
541}
542
Svetoslavd85084b2014-03-20 10:28:31 -0700543status_t SurfaceComposerClient::clearLayerFrameStats(const sp<IBinder>& token) const {
544 if (mStatus != NO_ERROR) {
545 return mStatus;
546 }
547 return mClient->clearLayerFrameStats(token);
548}
549
550status_t SurfaceComposerClient::getLayerFrameStats(const sp<IBinder>& token,
551 FrameStats* outStats) const {
552 if (mStatus != NO_ERROR) {
553 return mStatus;
554 }
555 return mClient->getLayerFrameStats(token, outStats);
556}
557
Mathias Agopian698c0872011-06-28 19:09:31 -0700558inline Composer& SurfaceComposerClient::getComposer() {
559 return mComposer;
560}
561
562// ----------------------------------------------------------------------------
563
564void SurfaceComposerClient::openGlobalTransaction() {
Jeff Brownf3f7db62012-08-31 02:18:38 -0700565 Composer::openGlobalTransaction();
Mathias Agopian698c0872011-06-28 19:09:31 -0700566}
567
Jamie Gennis28378392011-10-12 17:39:00 -0700568void SurfaceComposerClient::closeGlobalTransaction(bool synchronous) {
569 Composer::closeGlobalTransaction(synchronous);
Mathias Agopian698c0872011-06-28 19:09:31 -0700570}
571
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700572void SurfaceComposerClient::setAnimationTransaction() {
573 Composer::setAnimationTransaction();
574}
575
Mathias Agopian698c0872011-06-28 19:09:31 -0700576// ----------------------------------------------------------------------------
577
Mathias Agopianac9fa422013-02-11 16:40:36 -0800578status_t SurfaceComposerClient::setCrop(const sp<IBinder>& id, const Rect& crop) {
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700579 return getComposer().setCrop(this, id, crop);
580}
581
Mathias Agopianac9fa422013-02-11 16:40:36 -0800582status_t SurfaceComposerClient::setPosition(const sp<IBinder>& id, float x, float y) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700583 return getComposer().setPosition(this, id, x, y);
584}
585
Mathias Agopianac9fa422013-02-11 16:40:36 -0800586status_t SurfaceComposerClient::setSize(const sp<IBinder>& id, uint32_t w, uint32_t h) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700587 return getComposer().setSize(this, id, w, h);
588}
589
Dan Stozad723bd72014-11-18 10:24:03 -0800590status_t SurfaceComposerClient::setLayer(const sp<IBinder>& id, uint32_t z) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700591 return getComposer().setLayer(this, id, z);
592}
593
Mathias Agopianac9fa422013-02-11 16:40:36 -0800594status_t SurfaceComposerClient::hide(const sp<IBinder>& id) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700595 return getComposer().setFlags(this, id,
Mathias Agopian3165cc22012-08-08 19:42:09 -0700596 layer_state_t::eLayerHidden,
597 layer_state_t::eLayerHidden);
Mathias Agopian698c0872011-06-28 19:09:31 -0700598}
599
Mathias Agopianac9fa422013-02-11 16:40:36 -0800600status_t SurfaceComposerClient::show(const sp<IBinder>& id) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700601 return getComposer().setFlags(this, id,
602 0,
Mathias Agopian3165cc22012-08-08 19:42:09 -0700603 layer_state_t::eLayerHidden);
Mathias Agopian698c0872011-06-28 19:09:31 -0700604}
605
Mathias Agopianac9fa422013-02-11 16:40:36 -0800606status_t SurfaceComposerClient::setFlags(const sp<IBinder>& id, uint32_t flags,
Mathias Agopian698c0872011-06-28 19:09:31 -0700607 uint32_t mask) {
608 return getComposer().setFlags(this, id, flags, mask);
609}
610
Mathias Agopianac9fa422013-02-11 16:40:36 -0800611status_t SurfaceComposerClient::setTransparentRegionHint(const sp<IBinder>& id,
Mathias Agopian698c0872011-06-28 19:09:31 -0700612 const Region& transparentRegion) {
613 return getComposer().setTransparentRegionHint(this, id, transparentRegion);
614}
615
Mathias Agopianac9fa422013-02-11 16:40:36 -0800616status_t SurfaceComposerClient::setAlpha(const sp<IBinder>& id, float alpha) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700617 return getComposer().setAlpha(this, id, alpha);
618}
619
Mathias Agopianac9fa422013-02-11 16:40:36 -0800620status_t SurfaceComposerClient::setLayerStack(const sp<IBinder>& id, uint32_t layerStack) {
Mathias Agopian87855782012-07-24 21:41:09 -0700621 return getComposer().setLayerStack(this, id, layerStack);
622}
623
Mathias Agopianac9fa422013-02-11 16:40:36 -0800624status_t SurfaceComposerClient::setMatrix(const sp<IBinder>& id, float dsdx, float dtdx,
Mathias Agopian698c0872011-06-28 19:09:31 -0700625 float dsdy, float dtdy) {
626 return getComposer().setMatrix(this, id, dsdx, dtdx, dsdy, dtdy);
627}
628
Dan Stoza7dde5992015-05-22 09:51:44 -0700629status_t SurfaceComposerClient::deferTransactionUntil(const sp<IBinder>& id,
630 const sp<IBinder>& handle, uint64_t frameNumber) {
631 return getComposer().deferTransactionUntil(this, id, handle, frameNumber);
632}
633
Mathias Agopian698c0872011-06-28 19:09:31 -0700634// ----------------------------------------------------------------------------
635
Mathias Agopiane57f2922012-08-09 16:29:12 -0700636void SurfaceComposerClient::setDisplaySurface(const sp<IBinder>& token,
Andy McFadden2adaf042012-12-18 09:49:45 -0800637 const sp<IGraphicBufferProducer>& bufferProducer) {
638 Composer::getInstance().setDisplaySurface(token, bufferProducer);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700639}
640
641void SurfaceComposerClient::setDisplayLayerStack(const sp<IBinder>& token,
642 uint32_t layerStack) {
643 Composer::getInstance().setDisplayLayerStack(token, layerStack);
644}
645
Mathias Agopian00e8c7a2012-09-04 19:30:46 -0700646void SurfaceComposerClient::setDisplayProjection(const sp<IBinder>& token,
647 uint32_t orientation,
648 const Rect& layerStackRect,
649 const Rect& displayRect) {
650 Composer::getInstance().setDisplayProjection(token, orientation,
651 layerStackRect, displayRect);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700652}
653
Michael Wright1f6078a2014-06-26 16:01:02 -0700654void SurfaceComposerClient::setDisplaySize(const sp<IBinder>& token,
655 uint32_t width, uint32_t height) {
656 Composer::getInstance().setDisplaySize(token, width, height);
657}
658
Mathias Agopiane57f2922012-08-09 16:29:12 -0700659// ----------------------------------------------------------------------------
660
Dan Stoza7f7da322014-05-02 15:26:25 -0700661status_t SurfaceComposerClient::getDisplayConfigs(
662 const sp<IBinder>& display, Vector<DisplayInfo>* configs)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800663{
Dan Stoza7f7da322014-05-02 15:26:25 -0700664 return ComposerService::getComposerService()->getDisplayConfigs(display, configs);
665}
666
667status_t SurfaceComposerClient::getDisplayInfo(const sp<IBinder>& display,
668 DisplayInfo* info) {
669 Vector<DisplayInfo> configs;
670 status_t result = getDisplayConfigs(display, &configs);
671 if (result != NO_ERROR) {
672 return result;
673 }
674
675 int activeId = getActiveConfig(display);
676 if (activeId < 0) {
677 ALOGE("No active configuration found");
678 return NAME_NOT_FOUND;
679 }
680
Dan Stozad723bd72014-11-18 10:24:03 -0800681 *info = configs[static_cast<size_t>(activeId)];
Dan Stoza7f7da322014-05-02 15:26:25 -0700682 return NO_ERROR;
683}
684
685int SurfaceComposerClient::getActiveConfig(const sp<IBinder>& display) {
686 return ComposerService::getComposerService()->getActiveConfig(display);
687}
688
689status_t SurfaceComposerClient::setActiveConfig(const sp<IBinder>& display, int id) {
690 return ComposerService::getComposerService()->setActiveConfig(display, id);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800691}
692
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700693void SurfaceComposerClient::setDisplayPowerMode(const sp<IBinder>& token,
694 int mode) {
695 ComposerService::getComposerService()->setPowerMode(token, mode);
Jeff Brown2a09bb32012-10-08 19:13:57 -0700696}
697
Svetoslavd85084b2014-03-20 10:28:31 -0700698status_t SurfaceComposerClient::clearAnimationFrameStats() {
699 return ComposerService::getComposerService()->clearAnimationFrameStats();
700}
701
702status_t SurfaceComposerClient::getAnimationFrameStats(FrameStats* outStats) {
703 return ComposerService::getComposerService()->getAnimationFrameStats(outStats);
704}
705
Mathias Agopian698c0872011-06-28 19:09:31 -0700706// ----------------------------------------------------------------------------
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800707
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800708status_t ScreenshotClient::capture(
709 const sp<IBinder>& display,
710 const sp<IGraphicBufferProducer>& producer,
Dan Stozac1879002014-05-22 15:59:05 -0700711 Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
Dan Stozac7014012014-02-14 15:03:43 -0800712 uint32_t minLayerZ, uint32_t maxLayerZ, bool useIdentityTransform) {
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800713 sp<ISurfaceComposer> s(ComposerService::getComposerService());
714 if (s == NULL) return NO_INIT;
Dan Stozac1879002014-05-22 15:59:05 -0700715 return s->captureScreen(display, producer, sourceCrop,
Dan Stozac7014012014-02-14 15:03:43 -0800716 reqWidth, reqHeight, minLayerZ, maxLayerZ, useIdentityTransform);
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800717}
718
Mathias Agopian74c40c02010-09-29 13:02:36 -0700719ScreenshotClient::ScreenshotClient()
Mathias Agopianabe815d2013-03-19 22:22:21 -0700720 : mHaveBuffer(false) {
721 memset(&mBuffer, 0, sizeof(mBuffer));
Mathias Agopian74c40c02010-09-29 13:02:36 -0700722}
723
Mathias Agopian8000d062013-03-26 18:15:35 -0700724ScreenshotClient::~ScreenshotClient() {
725 ScreenshotClient::release();
726}
727
Mathias Agopianabe815d2013-03-19 22:22:21 -0700728sp<CpuConsumer> ScreenshotClient::getCpuConsumer() const {
729 if (mCpuConsumer == NULL) {
Dan Stoza6d5a7bb2014-03-13 11:39:09 -0700730 sp<IGraphicBufferConsumer> consumer;
731 BufferQueue::createBufferQueue(&mProducer, &consumer);
732 mCpuConsumer = new CpuConsumer(consumer, 1);
Mathias Agopianabe815d2013-03-19 22:22:21 -0700733 mCpuConsumer->setName(String8("ScreenshotClient"));
734 }
735 return mCpuConsumer;
Mathias Agopianbf2c6a62010-12-10 16:22:31 -0800736}
737
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700738status_t ScreenshotClient::update(const sp<IBinder>& display,
Dan Stozac1879002014-05-22 15:59:05 -0700739 Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
Dan Stozac7014012014-02-14 15:03:43 -0800740 uint32_t minLayerZ, uint32_t maxLayerZ,
Riley Andrewsd15ef272014-09-04 16:19:44 -0700741 bool useIdentityTransform, uint32_t rotation) {
Mathias Agopianbf2c6a62010-12-10 16:22:31 -0800742 sp<ISurfaceComposer> s(ComposerService::getComposerService());
743 if (s == NULL) return NO_INIT;
Mathias Agopianabe815d2013-03-19 22:22:21 -0700744 sp<CpuConsumer> cpuConsumer = getCpuConsumer();
745
746 if (mHaveBuffer) {
747 mCpuConsumer->unlockBuffer(mBuffer);
748 memset(&mBuffer, 0, sizeof(mBuffer));
749 mHaveBuffer = false;
750 }
751
Dan Stozac1879002014-05-22 15:59:05 -0700752 status_t err = s->captureScreen(display, mProducer, sourceCrop,
Riley Andrewsd15ef272014-09-04 16:19:44 -0700753 reqWidth, reqHeight, minLayerZ, maxLayerZ, useIdentityTransform,
754 static_cast<ISurfaceComposer::Rotation>(rotation));
Mathias Agopianabe815d2013-03-19 22:22:21 -0700755
756 if (err == NO_ERROR) {
757 err = mCpuConsumer->lockNextBuffer(&mBuffer);
758 if (err == NO_ERROR) {
759 mHaveBuffer = true;
760 }
761 }
762 return err;
763}
764
Riley Andrewsd15ef272014-09-04 16:19:44 -0700765status_t ScreenshotClient::update(const sp<IBinder>& display,
766 Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
767 uint32_t minLayerZ, uint32_t maxLayerZ,
768 bool useIdentityTransform) {
769
770 return ScreenshotClient::update(display, sourceCrop, reqWidth, reqHeight,
771 minLayerZ, maxLayerZ, useIdentityTransform, ISurfaceComposer::eRotateNone);
772}
773
Dan Stozac1879002014-05-22 15:59:05 -0700774status_t ScreenshotClient::update(const sp<IBinder>& display, Rect sourceCrop,
Dan Stozac7014012014-02-14 15:03:43 -0800775 bool useIdentityTransform) {
Dan Stozaf10c46e2014-11-11 10:32:31 -0800776 return ScreenshotClient::update(display, sourceCrop, 0, 0, 0, -1U,
Riley Andrewsd15ef272014-09-04 16:19:44 -0700777 useIdentityTransform, ISurfaceComposer::eRotateNone);
Mathias Agopianabe815d2013-03-19 22:22:21 -0700778}
779
Dan Stozac1879002014-05-22 15:59:05 -0700780status_t ScreenshotClient::update(const sp<IBinder>& display, Rect sourceCrop,
Dan Stozac7014012014-02-14 15:03:43 -0800781 uint32_t reqWidth, uint32_t reqHeight, bool useIdentityTransform) {
Dan Stozac1879002014-05-22 15:59:05 -0700782 return ScreenshotClient::update(display, sourceCrop, reqWidth, reqHeight,
Dan Stozaf10c46e2014-11-11 10:32:31 -0800783 0, -1U, useIdentityTransform, ISurfaceComposer::eRotateNone);
Mathias Agopian74c40c02010-09-29 13:02:36 -0700784}
785
786void ScreenshotClient::release() {
Mathias Agopianabe815d2013-03-19 22:22:21 -0700787 if (mHaveBuffer) {
788 mCpuConsumer->unlockBuffer(mBuffer);
789 memset(&mBuffer, 0, sizeof(mBuffer));
790 mHaveBuffer = false;
791 }
792 mCpuConsumer.clear();
Mathias Agopian74c40c02010-09-29 13:02:36 -0700793}
794
795void const* ScreenshotClient::getPixels() const {
Mathias Agopianabe815d2013-03-19 22:22:21 -0700796 return mBuffer.data;
Mathias Agopian74c40c02010-09-29 13:02:36 -0700797}
798
799uint32_t ScreenshotClient::getWidth() const {
Mathias Agopianabe815d2013-03-19 22:22:21 -0700800 return mBuffer.width;
Mathias Agopian74c40c02010-09-29 13:02:36 -0700801}
802
803uint32_t ScreenshotClient::getHeight() const {
Mathias Agopianabe815d2013-03-19 22:22:21 -0700804 return mBuffer.height;
Mathias Agopian74c40c02010-09-29 13:02:36 -0700805}
806
807PixelFormat ScreenshotClient::getFormat() const {
Mathias Agopianabe815d2013-03-19 22:22:21 -0700808 return mBuffer.format;
Mathias Agopian74c40c02010-09-29 13:02:36 -0700809}
810
811uint32_t ScreenshotClient::getStride() const {
Mathias Agopianabe815d2013-03-19 22:22:21 -0700812 return mBuffer.stride;
Mathias Agopian74c40c02010-09-29 13:02:36 -0700813}
814
815size_t ScreenshotClient::getSize() const {
Mathias Agopianabe815d2013-03-19 22:22:21 -0700816 return mBuffer.stride * mBuffer.height * bytesPerPixel(mBuffer.format);
Mathias Agopian74c40c02010-09-29 13:02:36 -0700817}
818
819// ----------------------------------------------------------------------------
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800820}; // namespace android