blob: f031296cecec891dc193f78d9b9634931c8b71f4 [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);
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000159 status_t setFinalCrop(const sp<SurfaceComposerClient>& client,
160 const sp<IBinder>& id, const Rect& crop);
Mathias Agopian87855782012-07-24 21:41:09 -0700161 status_t setLayerStack(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-11 16:40:36 -0800162 const sp<IBinder>& id, uint32_t layerStack);
Dan Stoza7dde5992015-05-22 09:51:44 -0700163 status_t deferTransactionUntil(const sp<SurfaceComposerClient>& client,
164 const sp<IBinder>& id, const sp<IBinder>& handle,
165 uint64_t frameNumber);
Mathias Agopian698c0872011-06-28 19:09:31 -0700166
Andy McFadden2adaf042012-12-18 09:49:45 -0800167 void setDisplaySurface(const sp<IBinder>& token,
168 const sp<IGraphicBufferProducer>& bufferProducer);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700169 void setDisplayLayerStack(const sp<IBinder>& token, uint32_t layerStack);
Mathias Agopian00e8c7a2012-09-04 19:30:46 -0700170 void setDisplayProjection(const sp<IBinder>& token,
171 uint32_t orientation,
172 const Rect& layerStackRect,
173 const Rect& displayRect);
Michael Wright1f6078a2014-06-26 16:01:02 -0700174 void setDisplaySize(const sp<IBinder>& token, uint32_t width, uint32_t height);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700175
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700176 static void setAnimationTransaction() {
177 Composer::getInstance().setAnimationTransactionImpl();
178 }
179
Jeff Brownf3f7db62012-08-31 02:18:38 -0700180 static void openGlobalTransaction() {
181 Composer::getInstance().openGlobalTransactionImpl();
182 }
183
Jamie Gennis28378392011-10-12 17:39:00 -0700184 static void closeGlobalTransaction(bool synchronous) {
185 Composer::getInstance().closeGlobalTransactionImpl(synchronous);
Mathias Agopiand4784a32010-05-27 19:41:15 -0700186 }
187};
188
189ANDROID_SINGLETON_STATIC_INSTANCE(Composer);
190
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800191// ---------------------------------------------------------------------------
192
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700193sp<IBinder> Composer::createDisplay(const String8& displayName, bool secure) {
194 return ComposerService::getComposerService()->createDisplay(displayName,
195 secure);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700196}
197
Jesse Hall6c913be2013-08-08 12:15:49 -0700198void Composer::destroyDisplay(const sp<IBinder>& display) {
199 return ComposerService::getComposerService()->destroyDisplay(display);
200}
201
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700202sp<IBinder> Composer::getBuiltInDisplay(int32_t id) {
203 return ComposerService::getComposerService()->getBuiltInDisplay(id);
204}
205
Jeff Brownf3f7db62012-08-31 02:18:38 -0700206void Composer::openGlobalTransactionImpl() {
207 { // scope for the lock
208 Mutex::Autolock _l(mLock);
209 mTransactionNestCount += 1;
210 }
211}
212
Jamie Gennis28378392011-10-12 17:39:00 -0700213void Composer::closeGlobalTransactionImpl(bool synchronous) {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700214 sp<ISurfaceComposer> sm(ComposerService::getComposerService());
Mathias Agopian698c0872011-06-28 19:09:31 -0700215
216 Vector<ComposerState> transaction;
Mathias Agopian8b33f032012-07-24 20:43:54 -0700217 Vector<DisplayState> displayTransaction;
Jamie Gennis28378392011-10-12 17:39:00 -0700218 uint32_t flags = 0;
Mathias Agopian698c0872011-06-28 19:09:31 -0700219
220 { // scope for the lock
221 Mutex::Autolock _l(mLock);
Jeff Brownf3f7db62012-08-31 02:18:38 -0700222 mForceSynchronous |= synchronous;
223 if (!mTransactionNestCount) {
224 ALOGW("At least one call to closeGlobalTransaction() was not matched by a prior "
225 "call to openGlobalTransaction().");
226 } else if (--mTransactionNestCount) {
227 return;
228 }
229
Mathias Agopiane57f2922012-08-09 16:29:12 -0700230 transaction = mComposerStates;
231 mComposerStates.clear();
Jamie Gennisb8d69a52011-10-10 15:48:06 -0700232
Mathias Agopiane57f2922012-08-09 16:29:12 -0700233 displayTransaction = mDisplayStates;
234 mDisplayStates.clear();
Jamie Gennis28378392011-10-12 17:39:00 -0700235
Jeff Brownf3f7db62012-08-31 02:18:38 -0700236 if (mForceSynchronous) {
Jamie Gennis28378392011-10-12 17:39:00 -0700237 flags |= ISurfaceComposer::eSynchronous;
238 }
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700239 if (mAnimation) {
240 flags |= ISurfaceComposer::eAnimation;
241 }
242
Jamie Gennis28378392011-10-12 17:39:00 -0700243 mForceSynchronous = false;
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700244 mAnimation = false;
Mathias Agopian698c0872011-06-28 19:09:31 -0700245 }
246
Mathias Agopian8b33f032012-07-24 20:43:54 -0700247 sm->setTransactionState(transaction, displayTransaction, flags);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800248}
249
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700250void Composer::setAnimationTransactionImpl() {
251 Mutex::Autolock _l(mLock);
252 mAnimation = true;
253}
254
Mathias Agopian698c0872011-06-28 19:09:31 -0700255layer_state_t* Composer::getLayerStateLocked(
Mathias Agopianac9fa422013-02-11 16:40:36 -0800256 const sp<SurfaceComposerClient>& client, const sp<IBinder>& id) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700257
258 ComposerState s;
259 s.client = client->mClient;
260 s.state.surface = id;
261
Mathias Agopiane57f2922012-08-09 16:29:12 -0700262 ssize_t index = mComposerStates.indexOf(s);
Mathias Agopian698c0872011-06-28 19:09:31 -0700263 if (index < 0) {
264 // we don't have it, add an initialized layer_state to our list
Mathias Agopiane57f2922012-08-09 16:29:12 -0700265 index = mComposerStates.add(s);
Mathias Agopian698c0872011-06-28 19:09:31 -0700266 }
267
Mathias Agopiane57f2922012-08-09 16:29:12 -0700268 ComposerState* const out = mComposerStates.editArray();
Mathias Agopian698c0872011-06-28 19:09:31 -0700269 return &(out[index].state);
270}
271
272status_t Composer::setPosition(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-11 16:40:36 -0800273 const sp<IBinder>& id, float x, float y) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700274 Mutex::Autolock _l(mLock);
275 layer_state_t* s = getLayerStateLocked(client, id);
276 if (!s)
277 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700278 s->what |= layer_state_t::ePositionChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700279 s->x = x;
280 s->y = y;
281 return NO_ERROR;
282}
283
284status_t Composer::setSize(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-11 16:40:36 -0800285 const sp<IBinder>& id, uint32_t w, uint32_t h) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700286 Mutex::Autolock _l(mLock);
287 layer_state_t* s = getLayerStateLocked(client, id);
288 if (!s)
289 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700290 s->what |= layer_state_t::eSizeChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700291 s->w = w;
292 s->h = h;
Jamie Gennis28378392011-10-12 17:39:00 -0700293
Mathias Agopian698c0872011-06-28 19:09:31 -0700294 return NO_ERROR;
295}
296
297status_t Composer::setLayer(const sp<SurfaceComposerClient>& client,
Dan Stozad723bd72014-11-18 10:24:03 -0800298 const sp<IBinder>& id, uint32_t z) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700299 Mutex::Autolock _l(mLock);
300 layer_state_t* s = getLayerStateLocked(client, id);
301 if (!s)
302 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700303 s->what |= layer_state_t::eLayerChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700304 s->z = z;
305 return NO_ERROR;
306}
307
308status_t Composer::setFlags(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-11 16:40:36 -0800309 const sp<IBinder>& id, uint32_t flags,
Mathias Agopian698c0872011-06-28 19:09:31 -0700310 uint32_t mask) {
311 Mutex::Autolock _l(mLock);
312 layer_state_t* s = getLayerStateLocked(client, id);
313 if (!s)
314 return BAD_INDEX;
Pablo Ceballos53390e12015-08-04 11:25:59 -0700315 if ((mask & layer_state_t::eLayerOpaque) ||
316 (mask & layer_state_t::eLayerHidden) ||
317 (mask & layer_state_t::eLayerSecure)) {
Dan Stoza23116082015-06-18 14:58:39 -0700318 s->what |= layer_state_t::eFlagsChanged;
Andy McFadden4125a4f2014-01-29 17:17:11 -0800319 }
Mathias Agopian698c0872011-06-28 19:09:31 -0700320 s->flags &= ~mask;
321 s->flags |= (flags & mask);
322 s->mask |= mask;
323 return NO_ERROR;
324}
325
326status_t Composer::setTransparentRegionHint(
Mathias Agopianac9fa422013-02-11 16:40:36 -0800327 const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
Mathias Agopian698c0872011-06-28 19:09:31 -0700328 const Region& transparentRegion) {
329 Mutex::Autolock _l(mLock);
330 layer_state_t* s = getLayerStateLocked(client, id);
331 if (!s)
332 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700333 s->what |= layer_state_t::eTransparentRegionChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700334 s->transparentRegion = transparentRegion;
335 return NO_ERROR;
336}
337
338status_t Composer::setAlpha(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-11 16:40:36 -0800339 const sp<IBinder>& id, float alpha) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700340 Mutex::Autolock _l(mLock);
341 layer_state_t* s = getLayerStateLocked(client, id);
342 if (!s)
343 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700344 s->what |= layer_state_t::eAlphaChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700345 s->alpha = alpha;
346 return NO_ERROR;
347}
348
Mathias Agopian87855782012-07-24 21:41:09 -0700349status_t Composer::setLayerStack(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-11 16:40:36 -0800350 const sp<IBinder>& id, uint32_t layerStack) {
Mathias Agopian87855782012-07-24 21:41:09 -0700351 Mutex::Autolock _l(mLock);
352 layer_state_t* s = getLayerStateLocked(client, id);
353 if (!s)
354 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700355 s->what |= layer_state_t::eLayerStackChanged;
Mathias Agopian87855782012-07-24 21:41:09 -0700356 s->layerStack = layerStack;
357 return NO_ERROR;
358}
359
Mathias Agopian698c0872011-06-28 19:09:31 -0700360status_t Composer::setMatrix(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-11 16:40:36 -0800361 const sp<IBinder>& id, float dsdx, float dtdx,
Mathias Agopian698c0872011-06-28 19:09:31 -0700362 float dsdy, float dtdy) {
363 Mutex::Autolock _l(mLock);
364 layer_state_t* s = getLayerStateLocked(client, id);
365 if (!s)
366 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700367 s->what |= layer_state_t::eMatrixChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700368 layer_state_t::matrix22_t matrix;
369 matrix.dsdx = dsdx;
370 matrix.dtdx = dtdx;
371 matrix.dsdy = dsdy;
372 matrix.dtdy = dtdy;
373 s->matrix = matrix;
374 return NO_ERROR;
375}
376
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700377status_t Composer::setCrop(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-11 16:40:36 -0800378 const sp<IBinder>& id, const Rect& crop) {
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700379 Mutex::Autolock _l(mLock);
380 layer_state_t* s = getLayerStateLocked(client, id);
381 if (!s)
382 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700383 s->what |= layer_state_t::eCropChanged;
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700384 s->crop = crop;
385 return NO_ERROR;
386}
387
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000388status_t Composer::setFinalCrop(const sp<SurfaceComposerClient>& client,
389 const sp<IBinder>& id, const Rect& crop) {
390 Mutex::Autolock _l(mLock);
391 layer_state_t* s = getLayerStateLocked(client, id);
392 if (!s) {
393 return BAD_INDEX;
394 }
395 s->what |= layer_state_t::eFinalCropChanged;
396 s->finalCrop = crop;
397 return NO_ERROR;
398}
399
Dan Stoza7dde5992015-05-22 09:51:44 -0700400status_t Composer::deferTransactionUntil(
401 const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
402 const sp<IBinder>& handle, uint64_t frameNumber) {
403 Mutex::Autolock lock(mLock);
404 layer_state_t* s = getLayerStateLocked(client, id);
405 if (!s) {
406 return BAD_INDEX;
407 }
408 s->what |= layer_state_t::eDeferTransaction;
409 s->handle = handle;
410 s->frameNumber = frameNumber;
411 return NO_ERROR;
412}
413
Mathias Agopian698c0872011-06-28 19:09:31 -0700414// ---------------------------------------------------------------------------
415
Mathias Agopiane57f2922012-08-09 16:29:12 -0700416DisplayState& Composer::getDisplayStateLocked(const sp<IBinder>& token) {
417 DisplayState s;
418 s.token = token;
419 ssize_t index = mDisplayStates.indexOf(s);
420 if (index < 0) {
421 // we don't have it, add an initialized layer_state to our list
422 s.what = 0;
423 index = mDisplayStates.add(s);
424 }
Dan Stozad723bd72014-11-18 10:24:03 -0800425 return mDisplayStates.editItemAt(static_cast<size_t>(index));
Mathias Agopiane57f2922012-08-09 16:29:12 -0700426}
427
428void Composer::setDisplaySurface(const sp<IBinder>& token,
Andy McFadden2adaf042012-12-18 09:49:45 -0800429 const sp<IGraphicBufferProducer>& bufferProducer) {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700430 Mutex::Autolock _l(mLock);
431 DisplayState& s(getDisplayStateLocked(token));
Andy McFadden2adaf042012-12-18 09:49:45 -0800432 s.surface = bufferProducer;
Mathias Agopiane57f2922012-08-09 16:29:12 -0700433 s.what |= DisplayState::eSurfaceChanged;
434}
435
436void Composer::setDisplayLayerStack(const sp<IBinder>& token,
437 uint32_t layerStack) {
438 Mutex::Autolock _l(mLock);
439 DisplayState& s(getDisplayStateLocked(token));
440 s.layerStack = layerStack;
441 s.what |= DisplayState::eLayerStackChanged;
442}
443
Mathias Agopian00e8c7a2012-09-04 19:30:46 -0700444void Composer::setDisplayProjection(const sp<IBinder>& token,
445 uint32_t orientation,
446 const Rect& layerStackRect,
447 const Rect& displayRect) {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700448 Mutex::Autolock _l(mLock);
449 DisplayState& s(getDisplayStateLocked(token));
450 s.orientation = orientation;
Mathias Agopian00e8c7a2012-09-04 19:30:46 -0700451 s.viewport = layerStackRect;
452 s.frame = displayRect;
453 s.what |= DisplayState::eDisplayProjectionChanged;
Mathias Agopiane57f2922012-08-09 16:29:12 -0700454}
455
Michael Wright1f6078a2014-06-26 16:01:02 -0700456void Composer::setDisplaySize(const sp<IBinder>& token, uint32_t width, uint32_t height) {
457 Mutex::Autolock _l(mLock);
458 DisplayState& s(getDisplayStateLocked(token));
459 s.width = width;
460 s.height = height;
461 s.what |= DisplayState::eDisplaySizeChanged;
462}
463
Mathias Agopiane57f2922012-08-09 16:29:12 -0700464// ---------------------------------------------------------------------------
465
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800466SurfaceComposerClient::SurfaceComposerClient()
Mathias Agopian698c0872011-06-28 19:09:31 -0700467 : mStatus(NO_INIT), mComposer(Composer::getInstance())
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800468{
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800469}
470
Mathias Agopian698c0872011-06-28 19:09:31 -0700471void SurfaceComposerClient::onFirstRef() {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700472 sp<ISurfaceComposer> sm(ComposerService::getComposerService());
Mathias Agopiand4784a32010-05-27 19:41:15 -0700473 if (sm != 0) {
Mathias Agopian7e27f052010-05-28 14:22:23 -0700474 sp<ISurfaceComposerClient> conn = sm->createConnection();
Mathias Agopiand4784a32010-05-27 19:41:15 -0700475 if (conn != 0) {
476 mClient = conn;
Mathias Agopiand4784a32010-05-27 19:41:15 -0700477 mStatus = NO_ERROR;
478 }
479 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800480}
481
Mathias Agopian698c0872011-06-28 19:09:31 -0700482SurfaceComposerClient::~SurfaceComposerClient() {
Mathias Agopian631f3582010-05-25 17:51:34 -0700483 dispose();
484}
Mathias Agopiandd3423c2009-09-23 15:44:05 -0700485
Mathias Agopian698c0872011-06-28 19:09:31 -0700486status_t SurfaceComposerClient::initCheck() const {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800487 return mStatus;
488}
489
Mathias Agopian698c0872011-06-28 19:09:31 -0700490sp<IBinder> SurfaceComposerClient::connection() const {
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800491 return IInterface::asBinder(mClient);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800492}
493
Mathias Agopiand4784a32010-05-27 19:41:15 -0700494status_t SurfaceComposerClient::linkToComposerDeath(
495 const sp<IBinder::DeathRecipient>& recipient,
Mathias Agopian698c0872011-06-28 19:09:31 -0700496 void* cookie, uint32_t flags) {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700497 sp<ISurfaceComposer> sm(ComposerService::getComposerService());
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800498 return IInterface::asBinder(sm)->linkToDeath(recipient, cookie, flags);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800499}
500
Mathias Agopian698c0872011-06-28 19:09:31 -0700501void SurfaceComposerClient::dispose() {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800502 // this can be called more than once.
Mathias Agopian7e27f052010-05-28 14:22:23 -0700503 sp<ISurfaceComposerClient> client;
Mathias Agopiand4784a32010-05-27 19:41:15 -0700504 Mutex::Autolock _lm(mLock);
505 if (mClient != 0) {
Mathias Agopiand4784a32010-05-27 19:41:15 -0700506 client = mClient; // hold ref while lock is held
507 mClient.clear();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800508 }
Mathias Agopiand4784a32010-05-27 19:41:15 -0700509 mStatus = NO_INIT;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800510}
511
Mathias Agopian698c0872011-06-28 19:09:31 -0700512sp<SurfaceControl> SurfaceComposerClient::createSurface(
Mathias Agopian698c0872011-06-28 19:09:31 -0700513 const String8& name,
Mathias Agopian698c0872011-06-28 19:09:31 -0700514 uint32_t w,
515 uint32_t h,
516 PixelFormat format,
517 uint32_t flags)
518{
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700519 sp<SurfaceControl> sur;
Mathias Agopian698c0872011-06-28 19:09:31 -0700520 if (mStatus == NO_ERROR) {
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700521 sp<IBinder> handle;
522 sp<IGraphicBufferProducer> gbp;
523 status_t err = mClient->createSurface(name, w, h, format, flags,
524 &handle, &gbp);
525 ALOGE_IF(err, "SurfaceComposerClient::createSurface error %s", strerror(-err));
526 if (err == NO_ERROR) {
527 sur = new SurfaceControl(this, handle, gbp);
Mathias Agopian698c0872011-06-28 19:09:31 -0700528 }
529 }
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700530 return sur;
Mathias Agopian698c0872011-06-28 19:09:31 -0700531}
532
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700533sp<IBinder> SurfaceComposerClient::createDisplay(const String8& displayName,
534 bool secure) {
535 return Composer::getInstance().createDisplay(displayName, secure);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700536}
537
Jesse Hall6c913be2013-08-08 12:15:49 -0700538void SurfaceComposerClient::destroyDisplay(const sp<IBinder>& display) {
539 Composer::getInstance().destroyDisplay(display);
540}
541
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700542sp<IBinder> SurfaceComposerClient::getBuiltInDisplay(int32_t id) {
543 return Composer::getInstance().getBuiltInDisplay(id);
544}
545
Mathias Agopianac9fa422013-02-11 16:40:36 -0800546status_t SurfaceComposerClient::destroySurface(const sp<IBinder>& sid) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700547 if (mStatus != NO_ERROR)
548 return mStatus;
549 status_t err = mClient->destroySurface(sid);
550 return err;
551}
552
Svetoslavd85084b2014-03-20 10:28:31 -0700553status_t SurfaceComposerClient::clearLayerFrameStats(const sp<IBinder>& token) const {
554 if (mStatus != NO_ERROR) {
555 return mStatus;
556 }
557 return mClient->clearLayerFrameStats(token);
558}
559
560status_t SurfaceComposerClient::getLayerFrameStats(const sp<IBinder>& token,
561 FrameStats* outStats) const {
562 if (mStatus != NO_ERROR) {
563 return mStatus;
564 }
565 return mClient->getLayerFrameStats(token, outStats);
566}
567
Mathias Agopian698c0872011-06-28 19:09:31 -0700568inline Composer& SurfaceComposerClient::getComposer() {
569 return mComposer;
570}
571
572// ----------------------------------------------------------------------------
573
574void SurfaceComposerClient::openGlobalTransaction() {
Jeff Brownf3f7db62012-08-31 02:18:38 -0700575 Composer::openGlobalTransaction();
Mathias Agopian698c0872011-06-28 19:09:31 -0700576}
577
Jamie Gennis28378392011-10-12 17:39:00 -0700578void SurfaceComposerClient::closeGlobalTransaction(bool synchronous) {
579 Composer::closeGlobalTransaction(synchronous);
Mathias Agopian698c0872011-06-28 19:09:31 -0700580}
581
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700582void SurfaceComposerClient::setAnimationTransaction() {
583 Composer::setAnimationTransaction();
584}
585
Mathias Agopian698c0872011-06-28 19:09:31 -0700586// ----------------------------------------------------------------------------
587
Mathias Agopianac9fa422013-02-11 16:40:36 -0800588status_t SurfaceComposerClient::setCrop(const sp<IBinder>& id, const Rect& crop) {
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700589 return getComposer().setCrop(this, id, crop);
590}
591
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000592status_t SurfaceComposerClient::setFinalCrop(const sp<IBinder>& id,
593 const Rect& crop) {
594 return getComposer().setFinalCrop(this, id, crop);
595}
596
Mathias Agopianac9fa422013-02-11 16:40:36 -0800597status_t SurfaceComposerClient::setPosition(const sp<IBinder>& id, float x, float y) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700598 return getComposer().setPosition(this, id, x, y);
599}
600
Mathias Agopianac9fa422013-02-11 16:40:36 -0800601status_t SurfaceComposerClient::setSize(const sp<IBinder>& id, uint32_t w, uint32_t h) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700602 return getComposer().setSize(this, id, w, h);
603}
604
Dan Stozad723bd72014-11-18 10:24:03 -0800605status_t SurfaceComposerClient::setLayer(const sp<IBinder>& id, uint32_t z) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700606 return getComposer().setLayer(this, id, z);
607}
608
Mathias Agopianac9fa422013-02-11 16:40:36 -0800609status_t SurfaceComposerClient::hide(const sp<IBinder>& id) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700610 return getComposer().setFlags(this, id,
Mathias Agopian3165cc22012-08-08 19:42:09 -0700611 layer_state_t::eLayerHidden,
612 layer_state_t::eLayerHidden);
Mathias Agopian698c0872011-06-28 19:09:31 -0700613}
614
Mathias Agopianac9fa422013-02-11 16:40:36 -0800615status_t SurfaceComposerClient::show(const sp<IBinder>& id) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700616 return getComposer().setFlags(this, id,
617 0,
Mathias Agopian3165cc22012-08-08 19:42:09 -0700618 layer_state_t::eLayerHidden);
Mathias Agopian698c0872011-06-28 19:09:31 -0700619}
620
Mathias Agopianac9fa422013-02-11 16:40:36 -0800621status_t SurfaceComposerClient::setFlags(const sp<IBinder>& id, uint32_t flags,
Mathias Agopian698c0872011-06-28 19:09:31 -0700622 uint32_t mask) {
623 return getComposer().setFlags(this, id, flags, mask);
624}
625
Mathias Agopianac9fa422013-02-11 16:40:36 -0800626status_t SurfaceComposerClient::setTransparentRegionHint(const sp<IBinder>& id,
Mathias Agopian698c0872011-06-28 19:09:31 -0700627 const Region& transparentRegion) {
628 return getComposer().setTransparentRegionHint(this, id, transparentRegion);
629}
630
Mathias Agopianac9fa422013-02-11 16:40:36 -0800631status_t SurfaceComposerClient::setAlpha(const sp<IBinder>& id, float alpha) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700632 return getComposer().setAlpha(this, id, alpha);
633}
634
Mathias Agopianac9fa422013-02-11 16:40:36 -0800635status_t SurfaceComposerClient::setLayerStack(const sp<IBinder>& id, uint32_t layerStack) {
Mathias Agopian87855782012-07-24 21:41:09 -0700636 return getComposer().setLayerStack(this, id, layerStack);
637}
638
Mathias Agopianac9fa422013-02-11 16:40:36 -0800639status_t SurfaceComposerClient::setMatrix(const sp<IBinder>& id, float dsdx, float dtdx,
Mathias Agopian698c0872011-06-28 19:09:31 -0700640 float dsdy, float dtdy) {
641 return getComposer().setMatrix(this, id, dsdx, dtdx, dsdy, dtdy);
642}
643
Dan Stoza7dde5992015-05-22 09:51:44 -0700644status_t SurfaceComposerClient::deferTransactionUntil(const sp<IBinder>& id,
645 const sp<IBinder>& handle, uint64_t frameNumber) {
646 return getComposer().deferTransactionUntil(this, id, handle, frameNumber);
647}
648
Mathias Agopian698c0872011-06-28 19:09:31 -0700649// ----------------------------------------------------------------------------
650
Mathias Agopiane57f2922012-08-09 16:29:12 -0700651void SurfaceComposerClient::setDisplaySurface(const sp<IBinder>& token,
Andy McFadden2adaf042012-12-18 09:49:45 -0800652 const sp<IGraphicBufferProducer>& bufferProducer) {
653 Composer::getInstance().setDisplaySurface(token, bufferProducer);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700654}
655
656void SurfaceComposerClient::setDisplayLayerStack(const sp<IBinder>& token,
657 uint32_t layerStack) {
658 Composer::getInstance().setDisplayLayerStack(token, layerStack);
659}
660
Mathias Agopian00e8c7a2012-09-04 19:30:46 -0700661void SurfaceComposerClient::setDisplayProjection(const sp<IBinder>& token,
662 uint32_t orientation,
663 const Rect& layerStackRect,
664 const Rect& displayRect) {
665 Composer::getInstance().setDisplayProjection(token, orientation,
666 layerStackRect, displayRect);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700667}
668
Michael Wright1f6078a2014-06-26 16:01:02 -0700669void SurfaceComposerClient::setDisplaySize(const sp<IBinder>& token,
670 uint32_t width, uint32_t height) {
671 Composer::getInstance().setDisplaySize(token, width, height);
672}
673
Mathias Agopiane57f2922012-08-09 16:29:12 -0700674// ----------------------------------------------------------------------------
675
Dan Stoza7f7da322014-05-02 15:26:25 -0700676status_t SurfaceComposerClient::getDisplayConfigs(
677 const sp<IBinder>& display, Vector<DisplayInfo>* configs)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800678{
Dan Stoza7f7da322014-05-02 15:26:25 -0700679 return ComposerService::getComposerService()->getDisplayConfigs(display, configs);
680}
681
682status_t SurfaceComposerClient::getDisplayInfo(const sp<IBinder>& display,
683 DisplayInfo* info) {
684 Vector<DisplayInfo> configs;
685 status_t result = getDisplayConfigs(display, &configs);
686 if (result != NO_ERROR) {
687 return result;
688 }
689
690 int activeId = getActiveConfig(display);
691 if (activeId < 0) {
692 ALOGE("No active configuration found");
693 return NAME_NOT_FOUND;
694 }
695
Dan Stozad723bd72014-11-18 10:24:03 -0800696 *info = configs[static_cast<size_t>(activeId)];
Dan Stoza7f7da322014-05-02 15:26:25 -0700697 return NO_ERROR;
698}
699
700int SurfaceComposerClient::getActiveConfig(const sp<IBinder>& display) {
701 return ComposerService::getComposerService()->getActiveConfig(display);
702}
703
704status_t SurfaceComposerClient::setActiveConfig(const sp<IBinder>& display, int id) {
705 return ComposerService::getComposerService()->setActiveConfig(display, id);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800706}
707
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700708void SurfaceComposerClient::setDisplayPowerMode(const sp<IBinder>& token,
709 int mode) {
710 ComposerService::getComposerService()->setPowerMode(token, mode);
Jeff Brown2a09bb32012-10-08 19:13:57 -0700711}
712
Svetoslavd85084b2014-03-20 10:28:31 -0700713status_t SurfaceComposerClient::clearAnimationFrameStats() {
714 return ComposerService::getComposerService()->clearAnimationFrameStats();
715}
716
717status_t SurfaceComposerClient::getAnimationFrameStats(FrameStats* outStats) {
718 return ComposerService::getComposerService()->getAnimationFrameStats(outStats);
719}
720
Dan Stozac4f471e2016-03-24 09:31:08 -0700721status_t SurfaceComposerClient::getHdrCapabilities(const sp<IBinder>& display,
722 HdrCapabilities* outCapabilities) {
723 return ComposerService::getComposerService()->getHdrCapabilities(display,
724 outCapabilities);
725}
726
Mathias Agopian698c0872011-06-28 19:09:31 -0700727// ----------------------------------------------------------------------------
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800728
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800729status_t ScreenshotClient::capture(
730 const sp<IBinder>& display,
731 const sp<IGraphicBufferProducer>& producer,
Dan Stozac1879002014-05-22 15:59:05 -0700732 Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
Dan Stozac7014012014-02-14 15:03:43 -0800733 uint32_t minLayerZ, uint32_t maxLayerZ, bool useIdentityTransform) {
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800734 sp<ISurfaceComposer> s(ComposerService::getComposerService());
735 if (s == NULL) return NO_INIT;
Dan Stozac1879002014-05-22 15:59:05 -0700736 return s->captureScreen(display, producer, sourceCrop,
Dan Stozac7014012014-02-14 15:03:43 -0800737 reqWidth, reqHeight, minLayerZ, maxLayerZ, useIdentityTransform);
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800738}
739
Mathias Agopian74c40c02010-09-29 13:02:36 -0700740ScreenshotClient::ScreenshotClient()
Mathias Agopianabe815d2013-03-19 22:22:21 -0700741 : mHaveBuffer(false) {
742 memset(&mBuffer, 0, sizeof(mBuffer));
Mathias Agopian74c40c02010-09-29 13:02:36 -0700743}
744
Mathias Agopian8000d062013-03-26 18:15:35 -0700745ScreenshotClient::~ScreenshotClient() {
746 ScreenshotClient::release();
747}
748
Mathias Agopianabe815d2013-03-19 22:22:21 -0700749sp<CpuConsumer> ScreenshotClient::getCpuConsumer() const {
750 if (mCpuConsumer == NULL) {
Dan Stoza6d5a7bb2014-03-13 11:39:09 -0700751 sp<IGraphicBufferConsumer> consumer;
752 BufferQueue::createBufferQueue(&mProducer, &consumer);
753 mCpuConsumer = new CpuConsumer(consumer, 1);
Mathias Agopianabe815d2013-03-19 22:22:21 -0700754 mCpuConsumer->setName(String8("ScreenshotClient"));
755 }
756 return mCpuConsumer;
Mathias Agopianbf2c6a62010-12-10 16:22:31 -0800757}
758
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700759status_t ScreenshotClient::update(const sp<IBinder>& display,
Dan Stozac1879002014-05-22 15:59:05 -0700760 Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
Dan Stozac7014012014-02-14 15:03:43 -0800761 uint32_t minLayerZ, uint32_t maxLayerZ,
Riley Andrewsd15ef272014-09-04 16:19:44 -0700762 bool useIdentityTransform, uint32_t rotation) {
Mathias Agopianbf2c6a62010-12-10 16:22:31 -0800763 sp<ISurfaceComposer> s(ComposerService::getComposerService());
764 if (s == NULL) return NO_INIT;
Mathias Agopianabe815d2013-03-19 22:22:21 -0700765 sp<CpuConsumer> cpuConsumer = getCpuConsumer();
766
767 if (mHaveBuffer) {
768 mCpuConsumer->unlockBuffer(mBuffer);
769 memset(&mBuffer, 0, sizeof(mBuffer));
770 mHaveBuffer = false;
771 }
772
Dan Stozac1879002014-05-22 15:59:05 -0700773 status_t err = s->captureScreen(display, mProducer, sourceCrop,
Riley Andrewsd15ef272014-09-04 16:19:44 -0700774 reqWidth, reqHeight, minLayerZ, maxLayerZ, useIdentityTransform,
775 static_cast<ISurfaceComposer::Rotation>(rotation));
Mathias Agopianabe815d2013-03-19 22:22:21 -0700776
777 if (err == NO_ERROR) {
778 err = mCpuConsumer->lockNextBuffer(&mBuffer);
779 if (err == NO_ERROR) {
780 mHaveBuffer = true;
781 }
782 }
783 return err;
784}
785
Riley Andrewsd15ef272014-09-04 16:19:44 -0700786status_t ScreenshotClient::update(const sp<IBinder>& display,
787 Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
788 uint32_t minLayerZ, uint32_t maxLayerZ,
789 bool useIdentityTransform) {
790
791 return ScreenshotClient::update(display, sourceCrop, reqWidth, reqHeight,
792 minLayerZ, maxLayerZ, useIdentityTransform, ISurfaceComposer::eRotateNone);
793}
794
Dan Stozac1879002014-05-22 15:59:05 -0700795status_t ScreenshotClient::update(const sp<IBinder>& display, Rect sourceCrop,
Dan Stozac7014012014-02-14 15:03:43 -0800796 bool useIdentityTransform) {
Dan Stozaf10c46e2014-11-11 10:32:31 -0800797 return ScreenshotClient::update(display, sourceCrop, 0, 0, 0, -1U,
Riley Andrewsd15ef272014-09-04 16:19:44 -0700798 useIdentityTransform, ISurfaceComposer::eRotateNone);
Mathias Agopianabe815d2013-03-19 22:22:21 -0700799}
800
Dan Stozac1879002014-05-22 15:59:05 -0700801status_t ScreenshotClient::update(const sp<IBinder>& display, Rect sourceCrop,
Dan Stozac7014012014-02-14 15:03:43 -0800802 uint32_t reqWidth, uint32_t reqHeight, bool useIdentityTransform) {
Dan Stozac1879002014-05-22 15:59:05 -0700803 return ScreenshotClient::update(display, sourceCrop, reqWidth, reqHeight,
Dan Stozaf10c46e2014-11-11 10:32:31 -0800804 0, -1U, useIdentityTransform, ISurfaceComposer::eRotateNone);
Mathias Agopian74c40c02010-09-29 13:02:36 -0700805}
806
807void ScreenshotClient::release() {
Mathias Agopianabe815d2013-03-19 22:22:21 -0700808 if (mHaveBuffer) {
809 mCpuConsumer->unlockBuffer(mBuffer);
810 memset(&mBuffer, 0, sizeof(mBuffer));
811 mHaveBuffer = false;
812 }
813 mCpuConsumer.clear();
Mathias Agopian74c40c02010-09-29 13:02:36 -0700814}
815
816void const* ScreenshotClient::getPixels() const {
Mathias Agopianabe815d2013-03-19 22:22:21 -0700817 return mBuffer.data;
Mathias Agopian74c40c02010-09-29 13:02:36 -0700818}
819
820uint32_t ScreenshotClient::getWidth() const {
Mathias Agopianabe815d2013-03-19 22:22:21 -0700821 return mBuffer.width;
Mathias Agopian74c40c02010-09-29 13:02:36 -0700822}
823
824uint32_t ScreenshotClient::getHeight() const {
Mathias Agopianabe815d2013-03-19 22:22:21 -0700825 return mBuffer.height;
Mathias Agopian74c40c02010-09-29 13:02:36 -0700826}
827
828PixelFormat ScreenshotClient::getFormat() const {
Mathias Agopianabe815d2013-03-19 22:22:21 -0700829 return mBuffer.format;
Mathias Agopian74c40c02010-09-29 13:02:36 -0700830}
831
832uint32_t ScreenshotClient::getStride() const {
Mathias Agopianabe815d2013-03-19 22:22:21 -0700833 return mBuffer.stride;
Mathias Agopian74c40c02010-09-29 13:02:36 -0700834}
835
836size_t ScreenshotClient::getSize() const {
Mathias Agopianabe815d2013-03-19 22:22:21 -0700837 return mBuffer.stride * mBuffer.height * bytesPerPixel(mBuffer.format);
Mathias Agopian74c40c02010-09-29 13:02:36 -0700838}
839
840// ----------------------------------------------------------------------------
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800841}; // namespace android