blob: 04b5446d42c5d27f1b192134aa58aa09fd21608e [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
294 // Resizing a surface makes the transaction synchronous.
295 mForceSynchronous = true;
296
Mathias Agopian698c0872011-06-28 19:09:31 -0700297 return NO_ERROR;
298}
299
300status_t Composer::setLayer(const sp<SurfaceComposerClient>& client,
Dan Stozad723bd72014-11-18 10:24:03 -0800301 const sp<IBinder>& id, uint32_t z) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700302 Mutex::Autolock _l(mLock);
303 layer_state_t* s = getLayerStateLocked(client, id);
304 if (!s)
305 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700306 s->what |= layer_state_t::eLayerChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700307 s->z = z;
308 return NO_ERROR;
309}
310
311status_t Composer::setFlags(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-11 16:40:36 -0800312 const sp<IBinder>& id, uint32_t flags,
Mathias Agopian698c0872011-06-28 19:09:31 -0700313 uint32_t mask) {
314 Mutex::Autolock _l(mLock);
315 layer_state_t* s = getLayerStateLocked(client, id);
316 if (!s)
317 return BAD_INDEX;
Pablo Ceballos53390e12015-08-04 11:25:59 -0700318 if ((mask & layer_state_t::eLayerOpaque) ||
319 (mask & layer_state_t::eLayerHidden) ||
320 (mask & layer_state_t::eLayerSecure)) {
Dan Stoza23116082015-06-18 14:58:39 -0700321 s->what |= layer_state_t::eFlagsChanged;
Andy McFadden4125a4f2014-01-29 17:17:11 -0800322 }
Mathias Agopian698c0872011-06-28 19:09:31 -0700323 s->flags &= ~mask;
324 s->flags |= (flags & mask);
325 s->mask |= mask;
326 return NO_ERROR;
327}
328
329status_t Composer::setTransparentRegionHint(
Mathias Agopianac9fa422013-02-11 16:40:36 -0800330 const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
Mathias Agopian698c0872011-06-28 19:09:31 -0700331 const Region& transparentRegion) {
332 Mutex::Autolock _l(mLock);
333 layer_state_t* s = getLayerStateLocked(client, id);
334 if (!s)
335 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700336 s->what |= layer_state_t::eTransparentRegionChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700337 s->transparentRegion = transparentRegion;
338 return NO_ERROR;
339}
340
341status_t Composer::setAlpha(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-11 16:40:36 -0800342 const sp<IBinder>& id, float alpha) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700343 Mutex::Autolock _l(mLock);
344 layer_state_t* s = getLayerStateLocked(client, id);
345 if (!s)
346 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700347 s->what |= layer_state_t::eAlphaChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700348 s->alpha = alpha;
349 return NO_ERROR;
350}
351
Mathias Agopian87855782012-07-24 21:41:09 -0700352status_t Composer::setLayerStack(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-11 16:40:36 -0800353 const sp<IBinder>& id, uint32_t layerStack) {
Mathias Agopian87855782012-07-24 21:41:09 -0700354 Mutex::Autolock _l(mLock);
355 layer_state_t* s = getLayerStateLocked(client, id);
356 if (!s)
357 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700358 s->what |= layer_state_t::eLayerStackChanged;
Mathias Agopian87855782012-07-24 21:41:09 -0700359 s->layerStack = layerStack;
360 return NO_ERROR;
361}
362
Mathias Agopian698c0872011-06-28 19:09:31 -0700363status_t Composer::setMatrix(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-11 16:40:36 -0800364 const sp<IBinder>& id, float dsdx, float dtdx,
Mathias Agopian698c0872011-06-28 19:09:31 -0700365 float dsdy, float dtdy) {
366 Mutex::Autolock _l(mLock);
367 layer_state_t* s = getLayerStateLocked(client, id);
368 if (!s)
369 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700370 s->what |= layer_state_t::eMatrixChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700371 layer_state_t::matrix22_t matrix;
372 matrix.dsdx = dsdx;
373 matrix.dtdx = dtdx;
374 matrix.dsdy = dsdy;
375 matrix.dtdy = dtdy;
376 s->matrix = matrix;
377 return NO_ERROR;
378}
379
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700380status_t Composer::setCrop(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-11 16:40:36 -0800381 const sp<IBinder>& id, const Rect& crop) {
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700382 Mutex::Autolock _l(mLock);
383 layer_state_t* s = getLayerStateLocked(client, id);
384 if (!s)
385 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700386 s->what |= layer_state_t::eCropChanged;
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700387 s->crop = crop;
388 return NO_ERROR;
389}
390
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000391status_t Composer::setFinalCrop(const sp<SurfaceComposerClient>& client,
392 const sp<IBinder>& id, const Rect& crop) {
393 Mutex::Autolock _l(mLock);
394 layer_state_t* s = getLayerStateLocked(client, id);
395 if (!s) {
396 return BAD_INDEX;
397 }
398 s->what |= layer_state_t::eFinalCropChanged;
399 s->finalCrop = crop;
400 return NO_ERROR;
401}
402
Dan Stoza7dde5992015-05-22 09:51:44 -0700403status_t Composer::deferTransactionUntil(
404 const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
405 const sp<IBinder>& handle, uint64_t frameNumber) {
406 Mutex::Autolock lock(mLock);
407 layer_state_t* s = getLayerStateLocked(client, id);
408 if (!s) {
409 return BAD_INDEX;
410 }
411 s->what |= layer_state_t::eDeferTransaction;
412 s->handle = handle;
413 s->frameNumber = frameNumber;
414 return NO_ERROR;
415}
416
Mathias Agopian698c0872011-06-28 19:09:31 -0700417// ---------------------------------------------------------------------------
418
Mathias Agopiane57f2922012-08-09 16:29:12 -0700419DisplayState& Composer::getDisplayStateLocked(const sp<IBinder>& token) {
420 DisplayState s;
421 s.token = token;
422 ssize_t index = mDisplayStates.indexOf(s);
423 if (index < 0) {
424 // we don't have it, add an initialized layer_state to our list
425 s.what = 0;
426 index = mDisplayStates.add(s);
427 }
Dan Stozad723bd72014-11-18 10:24:03 -0800428 return mDisplayStates.editItemAt(static_cast<size_t>(index));
Mathias Agopiane57f2922012-08-09 16:29:12 -0700429}
430
431void Composer::setDisplaySurface(const sp<IBinder>& token,
Andy McFadden2adaf042012-12-18 09:49:45 -0800432 const sp<IGraphicBufferProducer>& bufferProducer) {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700433 Mutex::Autolock _l(mLock);
434 DisplayState& s(getDisplayStateLocked(token));
Andy McFadden2adaf042012-12-18 09:49:45 -0800435 s.surface = bufferProducer;
Mathias Agopiane57f2922012-08-09 16:29:12 -0700436 s.what |= DisplayState::eSurfaceChanged;
437}
438
439void Composer::setDisplayLayerStack(const sp<IBinder>& token,
440 uint32_t layerStack) {
441 Mutex::Autolock _l(mLock);
442 DisplayState& s(getDisplayStateLocked(token));
443 s.layerStack = layerStack;
444 s.what |= DisplayState::eLayerStackChanged;
445}
446
Mathias Agopian00e8c7a2012-09-04 19:30:46 -0700447void Composer::setDisplayProjection(const sp<IBinder>& token,
448 uint32_t orientation,
449 const Rect& layerStackRect,
450 const Rect& displayRect) {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700451 Mutex::Autolock _l(mLock);
452 DisplayState& s(getDisplayStateLocked(token));
453 s.orientation = orientation;
Mathias Agopian00e8c7a2012-09-04 19:30:46 -0700454 s.viewport = layerStackRect;
455 s.frame = displayRect;
456 s.what |= DisplayState::eDisplayProjectionChanged;
Mathias Agopiane57f2922012-08-09 16:29:12 -0700457 mForceSynchronous = true; // TODO: do we actually still need this?
458}
459
Michael Wright1f6078a2014-06-26 16:01:02 -0700460void Composer::setDisplaySize(const sp<IBinder>& token, uint32_t width, uint32_t height) {
461 Mutex::Autolock _l(mLock);
462 DisplayState& s(getDisplayStateLocked(token));
463 s.width = width;
464 s.height = height;
465 s.what |= DisplayState::eDisplaySizeChanged;
466}
467
Mathias Agopiane57f2922012-08-09 16:29:12 -0700468// ---------------------------------------------------------------------------
469
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800470SurfaceComposerClient::SurfaceComposerClient()
Mathias Agopian698c0872011-06-28 19:09:31 -0700471 : mStatus(NO_INIT), mComposer(Composer::getInstance())
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800472{
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800473}
474
Mathias Agopian698c0872011-06-28 19:09:31 -0700475void SurfaceComposerClient::onFirstRef() {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700476 sp<ISurfaceComposer> sm(ComposerService::getComposerService());
Mathias Agopiand4784a32010-05-27 19:41:15 -0700477 if (sm != 0) {
Mathias Agopian7e27f052010-05-28 14:22:23 -0700478 sp<ISurfaceComposerClient> conn = sm->createConnection();
Mathias Agopiand4784a32010-05-27 19:41:15 -0700479 if (conn != 0) {
480 mClient = conn;
Mathias Agopiand4784a32010-05-27 19:41:15 -0700481 mStatus = NO_ERROR;
482 }
483 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800484}
485
Mathias Agopian698c0872011-06-28 19:09:31 -0700486SurfaceComposerClient::~SurfaceComposerClient() {
Mathias Agopian631f3582010-05-25 17:51:34 -0700487 dispose();
488}
Mathias Agopiandd3423c2009-09-23 15:44:05 -0700489
Mathias Agopian698c0872011-06-28 19:09:31 -0700490status_t SurfaceComposerClient::initCheck() const {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800491 return mStatus;
492}
493
Mathias Agopian698c0872011-06-28 19:09:31 -0700494sp<IBinder> SurfaceComposerClient::connection() const {
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800495 return IInterface::asBinder(mClient);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800496}
497
Mathias Agopiand4784a32010-05-27 19:41:15 -0700498status_t SurfaceComposerClient::linkToComposerDeath(
499 const sp<IBinder::DeathRecipient>& recipient,
Mathias Agopian698c0872011-06-28 19:09:31 -0700500 void* cookie, uint32_t flags) {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700501 sp<ISurfaceComposer> sm(ComposerService::getComposerService());
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800502 return IInterface::asBinder(sm)->linkToDeath(recipient, cookie, flags);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800503}
504
Mathias Agopian698c0872011-06-28 19:09:31 -0700505void SurfaceComposerClient::dispose() {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800506 // this can be called more than once.
Mathias Agopian7e27f052010-05-28 14:22:23 -0700507 sp<ISurfaceComposerClient> client;
Mathias Agopiand4784a32010-05-27 19:41:15 -0700508 Mutex::Autolock _lm(mLock);
509 if (mClient != 0) {
Mathias Agopiand4784a32010-05-27 19:41:15 -0700510 client = mClient; // hold ref while lock is held
511 mClient.clear();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800512 }
Mathias Agopiand4784a32010-05-27 19:41:15 -0700513 mStatus = NO_INIT;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800514}
515
Mathias Agopian698c0872011-06-28 19:09:31 -0700516sp<SurfaceControl> SurfaceComposerClient::createSurface(
Mathias Agopian698c0872011-06-28 19:09:31 -0700517 const String8& name,
Mathias Agopian698c0872011-06-28 19:09:31 -0700518 uint32_t w,
519 uint32_t h,
520 PixelFormat format,
521 uint32_t flags)
522{
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700523 sp<SurfaceControl> sur;
Mathias Agopian698c0872011-06-28 19:09:31 -0700524 if (mStatus == NO_ERROR) {
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700525 sp<IBinder> handle;
526 sp<IGraphicBufferProducer> gbp;
527 status_t err = mClient->createSurface(name, w, h, format, flags,
528 &handle, &gbp);
529 ALOGE_IF(err, "SurfaceComposerClient::createSurface error %s", strerror(-err));
530 if (err == NO_ERROR) {
531 sur = new SurfaceControl(this, handle, gbp);
Mathias Agopian698c0872011-06-28 19:09:31 -0700532 }
533 }
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700534 return sur;
Mathias Agopian698c0872011-06-28 19:09:31 -0700535}
536
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700537sp<IBinder> SurfaceComposerClient::createDisplay(const String8& displayName,
538 bool secure) {
539 return Composer::getInstance().createDisplay(displayName, secure);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700540}
541
Jesse Hall6c913be2013-08-08 12:15:49 -0700542void SurfaceComposerClient::destroyDisplay(const sp<IBinder>& display) {
543 Composer::getInstance().destroyDisplay(display);
544}
545
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700546sp<IBinder> SurfaceComposerClient::getBuiltInDisplay(int32_t id) {
547 return Composer::getInstance().getBuiltInDisplay(id);
548}
549
Mathias Agopianac9fa422013-02-11 16:40:36 -0800550status_t SurfaceComposerClient::destroySurface(const sp<IBinder>& sid) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700551 if (mStatus != NO_ERROR)
552 return mStatus;
553 status_t err = mClient->destroySurface(sid);
554 return err;
555}
556
Svetoslavd85084b2014-03-20 10:28:31 -0700557status_t SurfaceComposerClient::clearLayerFrameStats(const sp<IBinder>& token) const {
558 if (mStatus != NO_ERROR) {
559 return mStatus;
560 }
561 return mClient->clearLayerFrameStats(token);
562}
563
564status_t SurfaceComposerClient::getLayerFrameStats(const sp<IBinder>& token,
565 FrameStats* outStats) const {
566 if (mStatus != NO_ERROR) {
567 return mStatus;
568 }
569 return mClient->getLayerFrameStats(token, outStats);
570}
571
Mathias Agopian698c0872011-06-28 19:09:31 -0700572inline Composer& SurfaceComposerClient::getComposer() {
573 return mComposer;
574}
575
576// ----------------------------------------------------------------------------
577
578void SurfaceComposerClient::openGlobalTransaction() {
Jeff Brownf3f7db62012-08-31 02:18:38 -0700579 Composer::openGlobalTransaction();
Mathias Agopian698c0872011-06-28 19:09:31 -0700580}
581
Jamie Gennis28378392011-10-12 17:39:00 -0700582void SurfaceComposerClient::closeGlobalTransaction(bool synchronous) {
583 Composer::closeGlobalTransaction(synchronous);
Mathias Agopian698c0872011-06-28 19:09:31 -0700584}
585
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700586void SurfaceComposerClient::setAnimationTransaction() {
587 Composer::setAnimationTransaction();
588}
589
Mathias Agopian698c0872011-06-28 19:09:31 -0700590// ----------------------------------------------------------------------------
591
Mathias Agopianac9fa422013-02-11 16:40:36 -0800592status_t SurfaceComposerClient::setCrop(const sp<IBinder>& id, const Rect& crop) {
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700593 return getComposer().setCrop(this, id, crop);
594}
595
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000596status_t SurfaceComposerClient::setFinalCrop(const sp<IBinder>& id,
597 const Rect& crop) {
598 return getComposer().setFinalCrop(this, id, crop);
599}
600
Mathias Agopianac9fa422013-02-11 16:40:36 -0800601status_t SurfaceComposerClient::setPosition(const sp<IBinder>& id, float x, float y) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700602 return getComposer().setPosition(this, id, x, y);
603}
604
Mathias Agopianac9fa422013-02-11 16:40:36 -0800605status_t SurfaceComposerClient::setSize(const sp<IBinder>& id, uint32_t w, uint32_t h) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700606 return getComposer().setSize(this, id, w, h);
607}
608
Dan Stozad723bd72014-11-18 10:24:03 -0800609status_t SurfaceComposerClient::setLayer(const sp<IBinder>& id, uint32_t z) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700610 return getComposer().setLayer(this, id, z);
611}
612
Mathias Agopianac9fa422013-02-11 16:40:36 -0800613status_t SurfaceComposerClient::hide(const sp<IBinder>& id) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700614 return getComposer().setFlags(this, id,
Mathias Agopian3165cc22012-08-08 19:42:09 -0700615 layer_state_t::eLayerHidden,
616 layer_state_t::eLayerHidden);
Mathias Agopian698c0872011-06-28 19:09:31 -0700617}
618
Mathias Agopianac9fa422013-02-11 16:40:36 -0800619status_t SurfaceComposerClient::show(const sp<IBinder>& id) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700620 return getComposer().setFlags(this, id,
621 0,
Mathias Agopian3165cc22012-08-08 19:42:09 -0700622 layer_state_t::eLayerHidden);
Mathias Agopian698c0872011-06-28 19:09:31 -0700623}
624
Mathias Agopianac9fa422013-02-11 16:40:36 -0800625status_t SurfaceComposerClient::setFlags(const sp<IBinder>& id, uint32_t flags,
Mathias Agopian698c0872011-06-28 19:09:31 -0700626 uint32_t mask) {
627 return getComposer().setFlags(this, id, flags, mask);
628}
629
Mathias Agopianac9fa422013-02-11 16:40:36 -0800630status_t SurfaceComposerClient::setTransparentRegionHint(const sp<IBinder>& id,
Mathias Agopian698c0872011-06-28 19:09:31 -0700631 const Region& transparentRegion) {
632 return getComposer().setTransparentRegionHint(this, id, transparentRegion);
633}
634
Mathias Agopianac9fa422013-02-11 16:40:36 -0800635status_t SurfaceComposerClient::setAlpha(const sp<IBinder>& id, float alpha) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700636 return getComposer().setAlpha(this, id, alpha);
637}
638
Mathias Agopianac9fa422013-02-11 16:40:36 -0800639status_t SurfaceComposerClient::setLayerStack(const sp<IBinder>& id, uint32_t layerStack) {
Mathias Agopian87855782012-07-24 21:41:09 -0700640 return getComposer().setLayerStack(this, id, layerStack);
641}
642
Mathias Agopianac9fa422013-02-11 16:40:36 -0800643status_t SurfaceComposerClient::setMatrix(const sp<IBinder>& id, float dsdx, float dtdx,
Mathias Agopian698c0872011-06-28 19:09:31 -0700644 float dsdy, float dtdy) {
645 return getComposer().setMatrix(this, id, dsdx, dtdx, dsdy, dtdy);
646}
647
Dan Stoza7dde5992015-05-22 09:51:44 -0700648status_t SurfaceComposerClient::deferTransactionUntil(const sp<IBinder>& id,
649 const sp<IBinder>& handle, uint64_t frameNumber) {
650 return getComposer().deferTransactionUntil(this, id, handle, frameNumber);
651}
652
Mathias Agopian698c0872011-06-28 19:09:31 -0700653// ----------------------------------------------------------------------------
654
Mathias Agopiane57f2922012-08-09 16:29:12 -0700655void SurfaceComposerClient::setDisplaySurface(const sp<IBinder>& token,
Andy McFadden2adaf042012-12-18 09:49:45 -0800656 const sp<IGraphicBufferProducer>& bufferProducer) {
657 Composer::getInstance().setDisplaySurface(token, bufferProducer);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700658}
659
660void SurfaceComposerClient::setDisplayLayerStack(const sp<IBinder>& token,
661 uint32_t layerStack) {
662 Composer::getInstance().setDisplayLayerStack(token, layerStack);
663}
664
Mathias Agopian00e8c7a2012-09-04 19:30:46 -0700665void SurfaceComposerClient::setDisplayProjection(const sp<IBinder>& token,
666 uint32_t orientation,
667 const Rect& layerStackRect,
668 const Rect& displayRect) {
669 Composer::getInstance().setDisplayProjection(token, orientation,
670 layerStackRect, displayRect);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700671}
672
Michael Wright1f6078a2014-06-26 16:01:02 -0700673void SurfaceComposerClient::setDisplaySize(const sp<IBinder>& token,
674 uint32_t width, uint32_t height) {
675 Composer::getInstance().setDisplaySize(token, width, height);
676}
677
Mathias Agopiane57f2922012-08-09 16:29:12 -0700678// ----------------------------------------------------------------------------
679
Dan Stoza7f7da322014-05-02 15:26:25 -0700680status_t SurfaceComposerClient::getDisplayConfigs(
681 const sp<IBinder>& display, Vector<DisplayInfo>* configs)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800682{
Dan Stoza7f7da322014-05-02 15:26:25 -0700683 return ComposerService::getComposerService()->getDisplayConfigs(display, configs);
684}
685
686status_t SurfaceComposerClient::getDisplayInfo(const sp<IBinder>& display,
687 DisplayInfo* info) {
688 Vector<DisplayInfo> configs;
689 status_t result = getDisplayConfigs(display, &configs);
690 if (result != NO_ERROR) {
691 return result;
692 }
693
694 int activeId = getActiveConfig(display);
695 if (activeId < 0) {
696 ALOGE("No active configuration found");
697 return NAME_NOT_FOUND;
698 }
699
Dan Stozad723bd72014-11-18 10:24:03 -0800700 *info = configs[static_cast<size_t>(activeId)];
Dan Stoza7f7da322014-05-02 15:26:25 -0700701 return NO_ERROR;
702}
703
704int SurfaceComposerClient::getActiveConfig(const sp<IBinder>& display) {
705 return ComposerService::getComposerService()->getActiveConfig(display);
706}
707
708status_t SurfaceComposerClient::setActiveConfig(const sp<IBinder>& display, int id) {
709 return ComposerService::getComposerService()->setActiveConfig(display, id);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800710}
711
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700712void SurfaceComposerClient::setDisplayPowerMode(const sp<IBinder>& token,
713 int mode) {
714 ComposerService::getComposerService()->setPowerMode(token, mode);
Jeff Brown2a09bb32012-10-08 19:13:57 -0700715}
716
Svetoslavd85084b2014-03-20 10:28:31 -0700717status_t SurfaceComposerClient::clearAnimationFrameStats() {
718 return ComposerService::getComposerService()->clearAnimationFrameStats();
719}
720
721status_t SurfaceComposerClient::getAnimationFrameStats(FrameStats* outStats) {
722 return ComposerService::getComposerService()->getAnimationFrameStats(outStats);
723}
724
Mathias Agopian698c0872011-06-28 19:09:31 -0700725// ----------------------------------------------------------------------------
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800726
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800727status_t ScreenshotClient::capture(
728 const sp<IBinder>& display,
729 const sp<IGraphicBufferProducer>& producer,
Dan Stozac1879002014-05-22 15:59:05 -0700730 Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
Dan Stozac7014012014-02-14 15:03:43 -0800731 uint32_t minLayerZ, uint32_t maxLayerZ, bool useIdentityTransform) {
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800732 sp<ISurfaceComposer> s(ComposerService::getComposerService());
733 if (s == NULL) return NO_INIT;
Dan Stozac1879002014-05-22 15:59:05 -0700734 return s->captureScreen(display, producer, sourceCrop,
Dan Stozac7014012014-02-14 15:03:43 -0800735 reqWidth, reqHeight, minLayerZ, maxLayerZ, useIdentityTransform);
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800736}
737
Mathias Agopian74c40c02010-09-29 13:02:36 -0700738ScreenshotClient::ScreenshotClient()
Mathias Agopianabe815d2013-03-19 22:22:21 -0700739 : mHaveBuffer(false) {
740 memset(&mBuffer, 0, sizeof(mBuffer));
Mathias Agopian74c40c02010-09-29 13:02:36 -0700741}
742
Mathias Agopian8000d062013-03-26 18:15:35 -0700743ScreenshotClient::~ScreenshotClient() {
744 ScreenshotClient::release();
745}
746
Mathias Agopianabe815d2013-03-19 22:22:21 -0700747sp<CpuConsumer> ScreenshotClient::getCpuConsumer() const {
748 if (mCpuConsumer == NULL) {
Dan Stoza6d5a7bb2014-03-13 11:39:09 -0700749 sp<IGraphicBufferConsumer> consumer;
750 BufferQueue::createBufferQueue(&mProducer, &consumer);
751 mCpuConsumer = new CpuConsumer(consumer, 1);
Mathias Agopianabe815d2013-03-19 22:22:21 -0700752 mCpuConsumer->setName(String8("ScreenshotClient"));
753 }
754 return mCpuConsumer;
Mathias Agopianbf2c6a62010-12-10 16:22:31 -0800755}
756
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700757status_t ScreenshotClient::update(const sp<IBinder>& display,
Dan Stozac1879002014-05-22 15:59:05 -0700758 Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
Dan Stozac7014012014-02-14 15:03:43 -0800759 uint32_t minLayerZ, uint32_t maxLayerZ,
Riley Andrewsd15ef272014-09-04 16:19:44 -0700760 bool useIdentityTransform, uint32_t rotation) {
Mathias Agopianbf2c6a62010-12-10 16:22:31 -0800761 sp<ISurfaceComposer> s(ComposerService::getComposerService());
762 if (s == NULL) return NO_INIT;
Mathias Agopianabe815d2013-03-19 22:22:21 -0700763 sp<CpuConsumer> cpuConsumer = getCpuConsumer();
764
765 if (mHaveBuffer) {
766 mCpuConsumer->unlockBuffer(mBuffer);
767 memset(&mBuffer, 0, sizeof(mBuffer));
768 mHaveBuffer = false;
769 }
770
Dan Stozac1879002014-05-22 15:59:05 -0700771 status_t err = s->captureScreen(display, mProducer, sourceCrop,
Riley Andrewsd15ef272014-09-04 16:19:44 -0700772 reqWidth, reqHeight, minLayerZ, maxLayerZ, useIdentityTransform,
773 static_cast<ISurfaceComposer::Rotation>(rotation));
Mathias Agopianabe815d2013-03-19 22:22:21 -0700774
775 if (err == NO_ERROR) {
776 err = mCpuConsumer->lockNextBuffer(&mBuffer);
777 if (err == NO_ERROR) {
778 mHaveBuffer = true;
779 }
780 }
781 return err;
782}
783
Riley Andrewsd15ef272014-09-04 16:19:44 -0700784status_t ScreenshotClient::update(const sp<IBinder>& display,
785 Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
786 uint32_t minLayerZ, uint32_t maxLayerZ,
787 bool useIdentityTransform) {
788
789 return ScreenshotClient::update(display, sourceCrop, reqWidth, reqHeight,
790 minLayerZ, maxLayerZ, useIdentityTransform, ISurfaceComposer::eRotateNone);
791}
792
Dan Stozac1879002014-05-22 15:59:05 -0700793status_t ScreenshotClient::update(const sp<IBinder>& display, Rect sourceCrop,
Dan Stozac7014012014-02-14 15:03:43 -0800794 bool useIdentityTransform) {
Dan Stozaf10c46e2014-11-11 10:32:31 -0800795 return ScreenshotClient::update(display, sourceCrop, 0, 0, 0, -1U,
Riley Andrewsd15ef272014-09-04 16:19:44 -0700796 useIdentityTransform, ISurfaceComposer::eRotateNone);
Mathias Agopianabe815d2013-03-19 22:22:21 -0700797}
798
Dan Stozac1879002014-05-22 15:59:05 -0700799status_t ScreenshotClient::update(const sp<IBinder>& display, Rect sourceCrop,
Dan Stozac7014012014-02-14 15:03:43 -0800800 uint32_t reqWidth, uint32_t reqHeight, bool useIdentityTransform) {
Dan Stozac1879002014-05-22 15:59:05 -0700801 return ScreenshotClient::update(display, sourceCrop, reqWidth, reqHeight,
Dan Stozaf10c46e2014-11-11 10:32:31 -0800802 0, -1U, useIdentityTransform, ISurfaceComposer::eRotateNone);
Mathias Agopian74c40c02010-09-29 13:02:36 -0700803}
804
805void ScreenshotClient::release() {
Mathias Agopianabe815d2013-03-19 22:22:21 -0700806 if (mHaveBuffer) {
807 mCpuConsumer->unlockBuffer(mBuffer);
808 memset(&mBuffer, 0, sizeof(mBuffer));
809 mHaveBuffer = false;
810 }
811 mCpuConsumer.clear();
Mathias Agopian74c40c02010-09-29 13:02:36 -0700812}
813
814void const* ScreenshotClient::getPixels() const {
Mathias Agopianabe815d2013-03-19 22:22:21 -0700815 return mBuffer.data;
Mathias Agopian74c40c02010-09-29 13:02:36 -0700816}
817
818uint32_t ScreenshotClient::getWidth() const {
Mathias Agopianabe815d2013-03-19 22:22:21 -0700819 return mBuffer.width;
Mathias Agopian74c40c02010-09-29 13:02:36 -0700820}
821
822uint32_t ScreenshotClient::getHeight() const {
Mathias Agopianabe815d2013-03-19 22:22:21 -0700823 return mBuffer.height;
Mathias Agopian74c40c02010-09-29 13:02:36 -0700824}
825
826PixelFormat ScreenshotClient::getFormat() const {
Mathias Agopianabe815d2013-03-19 22:22:21 -0700827 return mBuffer.format;
Mathias Agopian74c40c02010-09-29 13:02:36 -0700828}
829
830uint32_t ScreenshotClient::getStride() const {
Mathias Agopianabe815d2013-03-19 22:22:21 -0700831 return mBuffer.stride;
Mathias Agopian74c40c02010-09-29 13:02:36 -0700832}
833
834size_t ScreenshotClient::getSize() const {
Mathias Agopianabe815d2013-03-19 22:22:21 -0700835 return mBuffer.stride * mBuffer.height * bytesPerPixel(mBuffer.format);
Mathias Agopian74c40c02010-09-29 13:02:36 -0700836}
837
838// ----------------------------------------------------------------------------
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800839}; // namespace android