blob: 15c4c9a8802dd66c2009b97815abed731802ccb3 [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 Agopiana67932f2011-04-20 14:20:59 -070024#include <utils/SortedVector.h>
25#include <utils/String8.h>
26#include <utils/threads.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080027
Mathias Agopiana67932f2011-04-20 14:20:59 -070028#include <binder/IServiceManager.h>
Mathias Agopian9cce3252010-02-09 17:46:37 -080029
Michael Wright28f24d02016-07-12 13:30:53 -070030#include <system/graphics.h>
31
Mathias Agopian076b1cc2009-04-10 14:24:30 -070032#include <ui/DisplayInfo.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080033
Robert Carr673134e2017-01-09 19:48:38 -080034#include <gui/BufferItemConsumer.h>
Mathias Agopianabe815d2013-03-19 22:22:21 -070035#include <gui/CpuConsumer.h>
Mathias Agopiane3c697f2013-02-14 17:11:02 -080036#include <gui/IGraphicBufferProducer.h>
Mathias Agopian90ac7992012-02-25 18:48:35 -080037#include <gui/ISurfaceComposer.h>
38#include <gui/ISurfaceComposerClient.h>
Robert Carr4cdc58f2017-08-23 14:22:20 -070039#include <gui/LayerState.h>
Robert Carr0d480722017-01-10 16:42:54 -080040#include <gui/Surface.h>
Mathias Agopian90ac7992012-02-25 18:48:35 -080041#include <gui/SurfaceComposerClient.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080042
Mathias Agopian41f673c2011-11-17 17:48:35 -080043#include <private/gui/ComposerService.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080044
45namespace android {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080046// ---------------------------------------------------------------------------
47
Mathias Agopian7e27f052010-05-28 14:22:23 -070048ANDROID_SINGLETON_STATIC_INSTANCE(ComposerService);
49
Mathias Agopianb7e930d2010-06-01 15:12:58 -070050ComposerService::ComposerService()
51: Singleton<ComposerService>() {
Andy McFadden6652b3e2012-09-06 18:45:56 -070052 Mutex::Autolock _l(mLock);
53 connectLocked();
54}
55
56void ComposerService::connectLocked() {
Mathias Agopianb7e930d2010-06-01 15:12:58 -070057 const String16 name("SurfaceFlinger");
58 while (getService(name, &mComposerService) != NO_ERROR) {
59 usleep(250000);
60 }
Andy McFadden6652b3e2012-09-06 18:45:56 -070061 assert(mComposerService != NULL);
62
63 // Create the death listener.
64 class DeathObserver : public IBinder::DeathRecipient {
65 ComposerService& mComposerService;
66 virtual void binderDied(const wp<IBinder>& who) {
67 ALOGW("ComposerService remote (surfaceflinger) died [%p]",
68 who.unsafe_get());
69 mComposerService.composerServiceDied();
70 }
71 public:
Chih-Hung Hsiehe2347b72016-04-25 15:41:05 -070072 explicit DeathObserver(ComposerService& mgr) : mComposerService(mgr) { }
Andy McFadden6652b3e2012-09-06 18:45:56 -070073 };
74
75 mDeathObserver = new DeathObserver(*const_cast<ComposerService*>(this));
Marco Nelissen2ea926b2014-11-14 08:01:01 -080076 IInterface::asBinder(mComposerService)->linkToDeath(mDeathObserver);
Mathias Agopianb7e930d2010-06-01 15:12:58 -070077}
78
Andy McFadden6652b3e2012-09-06 18:45:56 -070079/*static*/ sp<ISurfaceComposer> ComposerService::getComposerService() {
80 ComposerService& instance = ComposerService::getInstance();
81 Mutex::Autolock _l(instance.mLock);
82 if (instance.mComposerService == NULL) {
83 ComposerService::getInstance().connectLocked();
84 assert(instance.mComposerService != NULL);
85 ALOGD("ComposerService reconnected");
86 }
87 return instance.mComposerService;
88}
89
90void ComposerService::composerServiceDied()
91{
92 Mutex::Autolock _l(mLock);
93 mComposerService = NULL;
94 mDeathObserver = NULL;
Mathias Agopianb7e930d2010-06-01 15:12:58 -070095}
96
Mathias Agopian7e27f052010-05-28 14:22:23 -070097// ---------------------------------------------------------------------------
98
Robert Carr4cdc58f2017-08-23 14:22:20 -070099SurfaceComposerClient::Transaction::Transaction(const Transaction& other) :
100 mForceSynchronous(other.mForceSynchronous),
101 mTransactionNestCount(other.mTransactionNestCount),
102 mAnimation(other.mAnimation) {
103 mDisplayStates = other.mDisplayStates;
104 mComposerStates = other.mComposerStates;
Mathias Agopian698c0872011-06-28 19:09:31 -0700105}
106
Robert Carr4cdc58f2017-08-23 14:22:20 -0700107status_t SurfaceComposerClient::Transaction::apply(bool synchronous) {
108 if (mStatus != NO_ERROR) {
109 return mStatus;
110 }
111
112 sp<ISurfaceComposer> sf(ComposerService::getComposerService());
113
114 Vector<ComposerState> composerStates;
115 Vector<DisplayState> displayStates;
116 uint32_t flags = 0;
117
118 mForceSynchronous |= synchronous;
119
120 composerStates = mComposerStates;
121 mComposerStates.clear();
122
123 displayStates = mDisplayStates;
124 mDisplayStates.clear();
125
126 if (mForceSynchronous) {
127 flags |= ISurfaceComposer::eSynchronous;
128 }
129 if (mAnimation) {
130 flags |= ISurfaceComposer::eAnimation;
131 }
132
133 mForceSynchronous = false;
134 mAnimation = false;
135
136 sf->setTransactionState(composerStates, displayStates, flags);
137 mStatus = NO_ERROR;
138 return NO_ERROR;
Mathias Agopiane57f2922012-08-09 16:29:12 -0700139}
140
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800141// ---------------------------------------------------------------------------
142
Robert Carr4cdc58f2017-08-23 14:22:20 -0700143sp<IBinder> SurfaceComposerClient::createDisplay(const String8& displayName, bool secure) {
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700144 return ComposerService::getComposerService()->createDisplay(displayName,
145 secure);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700146}
147
Robert Carr4cdc58f2017-08-23 14:22:20 -0700148void SurfaceComposerClient::destroyDisplay(const sp<IBinder>& display) {
Jesse Hall6c913be2013-08-08 12:15:49 -0700149 return ComposerService::getComposerService()->destroyDisplay(display);
150}
151
Robert Carr4cdc58f2017-08-23 14:22:20 -0700152sp<IBinder> SurfaceComposerClient::getBuiltInDisplay(int32_t id) {
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700153 return ComposerService::getComposerService()->getBuiltInDisplay(id);
154}
155
Robert Carr4cdc58f2017-08-23 14:22:20 -0700156void SurfaceComposerClient::Transaction::setAnimationTransaction() {
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700157 mAnimation = true;
158}
159
Robert Carr4cdc58f2017-08-23 14:22:20 -0700160layer_state_t* SurfaceComposerClient::Transaction::getLayerStateLocked(const sp<SurfaceControl>& sc) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700161 ComposerState s;
Robert Carr4cdc58f2017-08-23 14:22:20 -0700162 s.client = sc->getClient()->mClient;
163 s.state.surface = sc->getHandle();
Mathias Agopian698c0872011-06-28 19:09:31 -0700164
Mathias Agopiane57f2922012-08-09 16:29:12 -0700165 ssize_t index = mComposerStates.indexOf(s);
Mathias Agopian698c0872011-06-28 19:09:31 -0700166 if (index < 0) {
167 // we don't have it, add an initialized layer_state to our list
Mathias Agopiane57f2922012-08-09 16:29:12 -0700168 index = mComposerStates.add(s);
Mathias Agopian698c0872011-06-28 19:09:31 -0700169 }
170
Mathias Agopiane57f2922012-08-09 16:29:12 -0700171 ComposerState* const out = mComposerStates.editArray();
Mathias Agopian698c0872011-06-28 19:09:31 -0700172 return &(out[index].state);
173}
174
Robert Carr4cdc58f2017-08-23 14:22:20 -0700175SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setPosition(
176 const sp<SurfaceControl>& sc, float x, float y) {
177 layer_state_t* s = getLayerStateLocked(sc);
178 if (!s) {
179 mStatus = BAD_INDEX;
180 return *this;
181 }
Mathias Agopian3165cc22012-08-08 19:42:09 -0700182 s->what |= layer_state_t::ePositionChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700183 s->x = x;
184 s->y = y;
Robert Carr4cdc58f2017-08-23 14:22:20 -0700185 return *this;
Mathias Agopian698c0872011-06-28 19:09:31 -0700186}
187
Robert Carr4cdc58f2017-08-23 14:22:20 -0700188SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::show(
189 const sp<SurfaceControl>& sc) {
190 return setFlags(sc, 0, layer_state_t::eLayerHidden);
191}
192
193SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::hide(
194 const sp<SurfaceControl>& sc) {
195 return setFlags(sc, layer_state_t::eLayerHidden, layer_state_t::eLayerHidden);
196}
197
198SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setSize(
199 const sp<SurfaceControl>& sc, uint32_t w, uint32_t h) {
200 layer_state_t* s = getLayerStateLocked(sc);
201 if (!s) {
202 mStatus = BAD_INDEX;
203 return *this;
204 }
Mathias Agopian3165cc22012-08-08 19:42:09 -0700205 s->what |= layer_state_t::eSizeChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700206 s->w = w;
207 s->h = h;
Jamie Gennis28378392011-10-12 17:39:00 -0700208
Jorim Jaggi092123c2016-04-13 01:40:35 +0000209 // Resizing a surface makes the transaction synchronous.
210 mForceSynchronous = true;
211
Robert Carr4cdc58f2017-08-23 14:22:20 -0700212 return *this;
Mathias Agopian698c0872011-06-28 19:09:31 -0700213}
214
Robert Carr4cdc58f2017-08-23 14:22:20 -0700215SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setLayer(
216 const sp<SurfaceControl>& sc, int32_t z) {
217 layer_state_t* s = getLayerStateLocked(sc);
218 if (!s) {
219 mStatus = BAD_INDEX;
220 return *this;
221 }
Mathias Agopian3165cc22012-08-08 19:42:09 -0700222 s->what |= layer_state_t::eLayerChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700223 s->z = z;
Robert Carr4cdc58f2017-08-23 14:22:20 -0700224 return *this;
Mathias Agopian698c0872011-06-28 19:09:31 -0700225}
226
Robert Carr4cdc58f2017-08-23 14:22:20 -0700227SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setRelativeLayer(const sp<SurfaceControl>& sc, const sp<IBinder>& relativeTo,
Robert Carrdb66e622017-04-10 16:55:57 -0700228 int32_t z) {
Robert Carr4cdc58f2017-08-23 14:22:20 -0700229 layer_state_t* s = getLayerStateLocked(sc);
Robert Carrdb66e622017-04-10 16:55:57 -0700230 if (!s) {
Robert Carr4cdc58f2017-08-23 14:22:20 -0700231 mStatus = BAD_INDEX;
Robert Carrdb66e622017-04-10 16:55:57 -0700232 }
233 s->what |= layer_state_t::eRelativeLayerChanged;
234 s->relativeLayerHandle = relativeTo;
235 s->z = z;
Robert Carr4cdc58f2017-08-23 14:22:20 -0700236 return *this;
Robert Carrdb66e622017-04-10 16:55:57 -0700237}
238
Robert Carr4cdc58f2017-08-23 14:22:20 -0700239SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setFlags(
240 const sp<SurfaceControl>& sc, uint32_t flags,
Mathias Agopian698c0872011-06-28 19:09:31 -0700241 uint32_t mask) {
Robert Carr4cdc58f2017-08-23 14:22:20 -0700242 layer_state_t* s = getLayerStateLocked(sc);
243 if (!s) {
244 mStatus = BAD_INDEX;
245 return *this;
246 }
Pablo Ceballos53390e12015-08-04 11:25:59 -0700247 if ((mask & layer_state_t::eLayerOpaque) ||
248 (mask & layer_state_t::eLayerHidden) ||
249 (mask & layer_state_t::eLayerSecure)) {
Dan Stoza23116082015-06-18 14:58:39 -0700250 s->what |= layer_state_t::eFlagsChanged;
Andy McFadden4125a4f2014-01-29 17:17:11 -0800251 }
Mathias Agopian698c0872011-06-28 19:09:31 -0700252 s->flags &= ~mask;
253 s->flags |= (flags & mask);
254 s->mask |= mask;
Robert Carr4cdc58f2017-08-23 14:22:20 -0700255 return *this;
Mathias Agopian698c0872011-06-28 19:09:31 -0700256}
257
Robert Carr4cdc58f2017-08-23 14:22:20 -0700258SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setTransparentRegionHint(
259 const sp<SurfaceControl>& sc,
Mathias Agopian698c0872011-06-28 19:09:31 -0700260 const Region& transparentRegion) {
Robert Carr4cdc58f2017-08-23 14:22:20 -0700261 layer_state_t* s = getLayerStateLocked(sc);
262 if (!s) {
263 mStatus = BAD_INDEX;
264 return *this;
265 }
Mathias Agopian3165cc22012-08-08 19:42:09 -0700266 s->what |= layer_state_t::eTransparentRegionChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700267 s->transparentRegion = transparentRegion;
Robert Carr4cdc58f2017-08-23 14:22:20 -0700268 return *this;
Mathias Agopian698c0872011-06-28 19:09:31 -0700269}
270
Robert Carr4cdc58f2017-08-23 14:22:20 -0700271SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setAlpha(
272 const sp<SurfaceControl>& sc, float alpha) {
273 layer_state_t* s = getLayerStateLocked(sc);
274 if (!s) {
275 mStatus = BAD_INDEX;
276 return *this;
277 }
Mathias Agopian3165cc22012-08-08 19:42:09 -0700278 s->what |= layer_state_t::eAlphaChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700279 s->alpha = alpha;
Robert Carr4cdc58f2017-08-23 14:22:20 -0700280 return *this;
Mathias Agopian698c0872011-06-28 19:09:31 -0700281}
282
Robert Carr4cdc58f2017-08-23 14:22:20 -0700283SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setLayerStack(
284 const sp<SurfaceControl>& sc, uint32_t layerStack) {
285 layer_state_t* s = getLayerStateLocked(sc);
286 if (!s) {
287 mStatus = BAD_INDEX;
288 return *this;
289 }
Mathias Agopian3165cc22012-08-08 19:42:09 -0700290 s->what |= layer_state_t::eLayerStackChanged;
Mathias Agopian87855782012-07-24 21:41:09 -0700291 s->layerStack = layerStack;
Robert Carr4cdc58f2017-08-23 14:22:20 -0700292 return *this;
Mathias Agopian87855782012-07-24 21:41:09 -0700293}
294
Robert Carr4cdc58f2017-08-23 14:22:20 -0700295SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setMatrix(
296 const sp<SurfaceControl>& sc, float dsdx, float dtdx,
Robert Carrcb6e1e32017-02-21 19:48:26 -0800297 float dtdy, float dsdy) {
Robert Carr4cdc58f2017-08-23 14:22:20 -0700298 layer_state_t* s = getLayerStateLocked(sc);
299 if (!s) {
300 mStatus = BAD_INDEX;
301 return *this;
302 }
Mathias Agopian3165cc22012-08-08 19:42:09 -0700303 s->what |= layer_state_t::eMatrixChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700304 layer_state_t::matrix22_t matrix;
305 matrix.dsdx = dsdx;
306 matrix.dtdx = dtdx;
307 matrix.dsdy = dsdy;
308 matrix.dtdy = dtdy;
309 s->matrix = matrix;
Robert Carr4cdc58f2017-08-23 14:22:20 -0700310 return *this;
Mathias Agopian698c0872011-06-28 19:09:31 -0700311}
312
Robert Carr4cdc58f2017-08-23 14:22:20 -0700313SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setCrop(
314 const sp<SurfaceControl>& sc, const Rect& crop) {
315 layer_state_t* s = getLayerStateLocked(sc);
316 if (!s) {
317 mStatus = BAD_INDEX;
318 return *this;
319 }
Mathias Agopian3165cc22012-08-08 19:42:09 -0700320 s->what |= layer_state_t::eCropChanged;
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700321 s->crop = crop;
Robert Carr4cdc58f2017-08-23 14:22:20 -0700322 return *this;
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700323}
324
Robert Carr4cdc58f2017-08-23 14:22:20 -0700325SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setFinalCrop(const sp<SurfaceControl>& sc, const Rect& crop) {
326 layer_state_t* s = getLayerStateLocked(sc);
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000327 if (!s) {
Robert Carr4cdc58f2017-08-23 14:22:20 -0700328 mStatus = BAD_INDEX;
329 return *this;
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000330 }
331 s->what |= layer_state_t::eFinalCropChanged;
332 s->finalCrop = crop;
Robert Carr4cdc58f2017-08-23 14:22:20 -0700333 return *this;
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000334}
335
Robert Carr4cdc58f2017-08-23 14:22:20 -0700336SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::deferTransactionUntil(
337 const sp<SurfaceControl>& sc,
Dan Stoza7dde5992015-05-22 09:51:44 -0700338 const sp<IBinder>& handle, uint64_t frameNumber) {
Robert Carr4cdc58f2017-08-23 14:22:20 -0700339 layer_state_t* s = getLayerStateLocked(sc);
Dan Stoza7dde5992015-05-22 09:51:44 -0700340 if (!s) {
Robert Carr4cdc58f2017-08-23 14:22:20 -0700341 mStatus = BAD_INDEX;
342 return *this;
Dan Stoza7dde5992015-05-22 09:51:44 -0700343 }
344 s->what |= layer_state_t::eDeferTransaction;
Robert Carr0d480722017-01-10 16:42:54 -0800345 s->barrierHandle = handle;
346 s->frameNumber = frameNumber;
Robert Carr4cdc58f2017-08-23 14:22:20 -0700347 return *this;
Robert Carr0d480722017-01-10 16:42:54 -0800348}
349
Robert Carr4cdc58f2017-08-23 14:22:20 -0700350SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::deferTransactionUntil(
351 const sp<SurfaceControl>& sc,
Robert Carr0d480722017-01-10 16:42:54 -0800352 const sp<Surface>& barrierSurface, uint64_t frameNumber) {
Robert Carr4cdc58f2017-08-23 14:22:20 -0700353 layer_state_t* s = getLayerStateLocked(sc);
Robert Carr0d480722017-01-10 16:42:54 -0800354 if (!s) {
Robert Carr4cdc58f2017-08-23 14:22:20 -0700355 mStatus = BAD_INDEX;
356 return *this;
Robert Carr0d480722017-01-10 16:42:54 -0800357 }
358 s->what |= layer_state_t::eDeferTransaction;
359 s->barrierGbp = barrierSurface->getIGraphicBufferProducer();
Dan Stoza7dde5992015-05-22 09:51:44 -0700360 s->frameNumber = frameNumber;
Robert Carr4cdc58f2017-08-23 14:22:20 -0700361 return *this;
Dan Stoza7dde5992015-05-22 09:51:44 -0700362}
363
Robert Carr4cdc58f2017-08-23 14:22:20 -0700364SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::reparentChildren(
365 const sp<SurfaceControl>& sc,
Robert Carr1db73f62016-12-21 12:58:51 -0800366 const sp<IBinder>& newParentHandle) {
Robert Carr4cdc58f2017-08-23 14:22:20 -0700367 layer_state_t* s = getLayerStateLocked(sc);
Robert Carr1db73f62016-12-21 12:58:51 -0800368 if (!s) {
Robert Carr4cdc58f2017-08-23 14:22:20 -0700369 mStatus = BAD_INDEX;
370 return *this;
Robert Carr1db73f62016-12-21 12:58:51 -0800371 }
372 s->what |= layer_state_t::eReparentChildren;
373 s->reparentHandle = newParentHandle;
Robert Carr4cdc58f2017-08-23 14:22:20 -0700374 return *this;
Robert Carr1db73f62016-12-21 12:58:51 -0800375}
376
Robert Carr4cdc58f2017-08-23 14:22:20 -0700377SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::reparent(
378 const sp<SurfaceControl>& sc,
chaviwf1961f72017-09-18 16:41:07 -0700379 const sp<IBinder>& newParentHandle) {
Robert Carr4cdc58f2017-08-23 14:22:20 -0700380 layer_state_t* s = getLayerStateLocked(sc);
chaviw06178942017-07-27 10:25:59 -0700381 if (!s) {
Robert Carr4cdc58f2017-08-23 14:22:20 -0700382 mStatus = BAD_INDEX;
383 return *this;
chaviw06178942017-07-27 10:25:59 -0700384 }
chaviwf1961f72017-09-18 16:41:07 -0700385 s->what |= layer_state_t::eReparent;
chaviw06178942017-07-27 10:25:59 -0700386 s->parentHandleForChild = newParentHandle;
Robert Carr4cdc58f2017-08-23 14:22:20 -0700387 return *this;
chaviw06178942017-07-27 10:25:59 -0700388}
389
Robert Carr4cdc58f2017-08-23 14:22:20 -0700390SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setColor(
391 const sp<SurfaceControl>& sc,
392 const half3& color) {
393 layer_state_t* s = getLayerStateLocked(sc);
Robert Carr9524cb32017-02-13 11:32:32 -0800394 if (!s) {
Robert Carr4cdc58f2017-08-23 14:22:20 -0700395 mStatus = BAD_INDEX;
396 return *this;
397 }
398 s->what |= layer_state_t::eColorChanged;
399 s->color = color;
400 return *this;
401}
402
403SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::detachChildren(
404 const sp<SurfaceControl>& sc) {
405 layer_state_t* s = getLayerStateLocked(sc);
406 if (!s) {
407 mStatus = BAD_INDEX;
Robert Carr9524cb32017-02-13 11:32:32 -0800408 }
409 s->what |= layer_state_t::eDetachChildren;
Robert Carr4cdc58f2017-08-23 14:22:20 -0700410 return *this;
Robert Carr9524cb32017-02-13 11:32:32 -0800411}
412
Robert Carr4cdc58f2017-08-23 14:22:20 -0700413SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setOverrideScalingMode(
414 const sp<SurfaceControl>& sc, int32_t overrideScalingMode) {
415 layer_state_t* s = getLayerStateLocked(sc);
Robert Carrc3574f72016-03-24 12:19:32 -0700416 if (!s) {
Robert Carr4cdc58f2017-08-23 14:22:20 -0700417 mStatus = BAD_INDEX;
418 return *this;
Robert Carrc3574f72016-03-24 12:19:32 -0700419 }
420
421 switch (overrideScalingMode) {
422 case NATIVE_WINDOW_SCALING_MODE_FREEZE:
423 case NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW:
424 case NATIVE_WINDOW_SCALING_MODE_SCALE_CROP:
425 case NATIVE_WINDOW_SCALING_MODE_NO_SCALE_CROP:
426 case -1:
427 break;
428 default:
429 ALOGE("unknown scaling mode: %d",
430 overrideScalingMode);
Robert Carr4cdc58f2017-08-23 14:22:20 -0700431 mStatus = BAD_VALUE;
432 return *this;
Robert Carrc3574f72016-03-24 12:19:32 -0700433 }
434
435 s->what |= layer_state_t::eOverrideScalingModeChanged;
436 s->overrideScalingMode = overrideScalingMode;
Robert Carr4cdc58f2017-08-23 14:22:20 -0700437 return *this;
Robert Carrc3574f72016-03-24 12:19:32 -0700438}
439
Robert Carr4cdc58f2017-08-23 14:22:20 -0700440SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setGeometryAppliesWithResize(
441 const sp<SurfaceControl>& sc) {
442 layer_state_t* s = getLayerStateLocked(sc);
Robert Carr82364e32016-05-15 11:27:47 -0700443 if (!s) {
Robert Carr4cdc58f2017-08-23 14:22:20 -0700444 mStatus = BAD_INDEX;
445 return *this;
Robert Carr82364e32016-05-15 11:27:47 -0700446 }
Robert Carr99e27f02016-06-16 15:18:02 -0700447 s->what |= layer_state_t::eGeometryAppliesWithResize;
Robert Carr4cdc58f2017-08-23 14:22:20 -0700448 return *this;
Robert Carr82364e32016-05-15 11:27:47 -0700449}
450
Mathias Agopian698c0872011-06-28 19:09:31 -0700451// ---------------------------------------------------------------------------
452
Robert Carr4cdc58f2017-08-23 14:22:20 -0700453DisplayState& SurfaceComposerClient::Transaction::getDisplayStateLocked(const sp<IBinder>& token) {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700454 DisplayState s;
455 s.token = token;
456 ssize_t index = mDisplayStates.indexOf(s);
457 if (index < 0) {
458 // we don't have it, add an initialized layer_state to our list
459 s.what = 0;
460 index = mDisplayStates.add(s);
461 }
Dan Stozad723bd72014-11-18 10:24:03 -0800462 return mDisplayStates.editItemAt(static_cast<size_t>(index));
Mathias Agopiane57f2922012-08-09 16:29:12 -0700463}
464
Robert Carr4cdc58f2017-08-23 14:22:20 -0700465status_t SurfaceComposerClient::Transaction::setDisplaySurface(const sp<IBinder>& token,
466 const sp<IGraphicBufferProducer>& bufferProducer) {
Pablo Ceballoseddbef82016-09-01 11:21:21 -0700467 if (bufferProducer.get() != nullptr) {
468 // Make sure that composition can never be stalled by a virtual display
469 // consumer that isn't processing buffers fast enough.
470 status_t err = bufferProducer->setAsyncMode(true);
471 if (err != NO_ERROR) {
472 ALOGE("Composer::setDisplaySurface Failed to enable async mode on the "
473 "BufferQueue. This BufferQueue cannot be used for virtual "
474 "display. (%d)", err);
475 return err;
476 }
Pablo Ceballos1aad24c2016-08-04 10:24:22 -0700477 }
Mathias Agopiane57f2922012-08-09 16:29:12 -0700478 DisplayState& s(getDisplayStateLocked(token));
Andy McFadden2adaf042012-12-18 09:49:45 -0800479 s.surface = bufferProducer;
Mathias Agopiane57f2922012-08-09 16:29:12 -0700480 s.what |= DisplayState::eSurfaceChanged;
Pablo Ceballos1aad24c2016-08-04 10:24:22 -0700481 return NO_ERROR;
Mathias Agopiane57f2922012-08-09 16:29:12 -0700482}
483
Robert Carr4cdc58f2017-08-23 14:22:20 -0700484void SurfaceComposerClient::Transaction::setDisplayLayerStack(const sp<IBinder>& token,
Mathias Agopiane57f2922012-08-09 16:29:12 -0700485 uint32_t layerStack) {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700486 DisplayState& s(getDisplayStateLocked(token));
487 s.layerStack = layerStack;
488 s.what |= DisplayState::eLayerStackChanged;
489}
490
Robert Carr4cdc58f2017-08-23 14:22:20 -0700491void SurfaceComposerClient::Transaction::setDisplayProjection(const sp<IBinder>& token,
Mathias Agopian00e8c7a2012-09-04 19:30:46 -0700492 uint32_t orientation,
493 const Rect& layerStackRect,
494 const Rect& displayRect) {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700495 DisplayState& s(getDisplayStateLocked(token));
496 s.orientation = orientation;
Mathias Agopian00e8c7a2012-09-04 19:30:46 -0700497 s.viewport = layerStackRect;
498 s.frame = displayRect;
499 s.what |= DisplayState::eDisplayProjectionChanged;
Jorim Jaggi092123c2016-04-13 01:40:35 +0000500 mForceSynchronous = true; // TODO: do we actually still need this?
Mathias Agopiane57f2922012-08-09 16:29:12 -0700501}
502
Robert Carr4cdc58f2017-08-23 14:22:20 -0700503void SurfaceComposerClient::Transaction::setDisplaySize(const sp<IBinder>& token, uint32_t width, uint32_t height) {
Michael Wright1f6078a2014-06-26 16:01:02 -0700504 DisplayState& s(getDisplayStateLocked(token));
505 s.width = width;
506 s.height = height;
507 s.what |= DisplayState::eDisplaySizeChanged;
508}
509
Mathias Agopiane57f2922012-08-09 16:29:12 -0700510// ---------------------------------------------------------------------------
511
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800512SurfaceComposerClient::SurfaceComposerClient()
Robert Carr4cdc58f2017-08-23 14:22:20 -0700513 : mStatus(NO_INIT)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800514{
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800515}
516
Robert Carr1db73f62016-12-21 12:58:51 -0800517SurfaceComposerClient::SurfaceComposerClient(const sp<IGraphicBufferProducer>& root)
Robert Carr4cdc58f2017-08-23 14:22:20 -0700518 : mStatus(NO_INIT), mParent(root)
Robert Carr1db73f62016-12-21 12:58:51 -0800519{
520}
521
Mathias Agopian698c0872011-06-28 19:09:31 -0700522void SurfaceComposerClient::onFirstRef() {
Robert Carr4cdc58f2017-08-23 14:22:20 -0700523 sp<ISurfaceComposer> sf(ComposerService::getComposerService());
524 if (sf != 0) {
Robert Carr1db73f62016-12-21 12:58:51 -0800525 auto rootProducer = mParent.promote();
526 sp<ISurfaceComposerClient> conn;
Robert Carr4cdc58f2017-08-23 14:22:20 -0700527 conn = (rootProducer != nullptr) ? sf->createScopedConnection(rootProducer) :
528 sf->createConnection();
Mathias Agopiand4784a32010-05-27 19:41:15 -0700529 if (conn != 0) {
530 mClient = conn;
Mathias Agopiand4784a32010-05-27 19:41:15 -0700531 mStatus = NO_ERROR;
532 }
533 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800534}
535
Mathias Agopian698c0872011-06-28 19:09:31 -0700536SurfaceComposerClient::~SurfaceComposerClient() {
Mathias Agopian631f3582010-05-25 17:51:34 -0700537 dispose();
538}
Mathias Agopiandd3423c2009-09-23 15:44:05 -0700539
Mathias Agopian698c0872011-06-28 19:09:31 -0700540status_t SurfaceComposerClient::initCheck() const {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800541 return mStatus;
542}
543
Mathias Agopian698c0872011-06-28 19:09:31 -0700544sp<IBinder> SurfaceComposerClient::connection() const {
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800545 return IInterface::asBinder(mClient);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800546}
547
Mathias Agopiand4784a32010-05-27 19:41:15 -0700548status_t SurfaceComposerClient::linkToComposerDeath(
549 const sp<IBinder::DeathRecipient>& recipient,
Mathias Agopian698c0872011-06-28 19:09:31 -0700550 void* cookie, uint32_t flags) {
Robert Carr4cdc58f2017-08-23 14:22:20 -0700551 sp<ISurfaceComposer> sf(ComposerService::getComposerService());
552 return IInterface::asBinder(sf)->linkToDeath(recipient, cookie, flags);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800553}
554
Mathias Agopian698c0872011-06-28 19:09:31 -0700555void SurfaceComposerClient::dispose() {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800556 // this can be called more than once.
Mathias Agopian7e27f052010-05-28 14:22:23 -0700557 sp<ISurfaceComposerClient> client;
Mathias Agopiand4784a32010-05-27 19:41:15 -0700558 Mutex::Autolock _lm(mLock);
559 if (mClient != 0) {
Mathias Agopiand4784a32010-05-27 19:41:15 -0700560 client = mClient; // hold ref while lock is held
561 mClient.clear();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800562 }
Mathias Agopiand4784a32010-05-27 19:41:15 -0700563 mStatus = NO_INIT;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800564}
565
Mathias Agopian698c0872011-06-28 19:09:31 -0700566sp<SurfaceControl> SurfaceComposerClient::createSurface(
Mathias Agopian698c0872011-06-28 19:09:31 -0700567 const String8& name,
Mathias Agopian698c0872011-06-28 19:09:31 -0700568 uint32_t w,
569 uint32_t h,
570 PixelFormat format,
Robert Carr1f0a16a2016-10-24 16:27:39 -0700571 uint32_t flags,
Albert Chaulk479c60c2017-01-27 14:21:34 -0500572 SurfaceControl* parent,
573 uint32_t windowType,
574 uint32_t ownerUid)
Mathias Agopian698c0872011-06-28 19:09:31 -0700575{
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700576 sp<SurfaceControl> sur;
Mathias Agopian698c0872011-06-28 19:09:31 -0700577 if (mStatus == NO_ERROR) {
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700578 sp<IBinder> handle;
Robert Carr1f0a16a2016-10-24 16:27:39 -0700579 sp<IBinder> parentHandle;
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700580 sp<IGraphicBufferProducer> gbp;
Robert Carr1f0a16a2016-10-24 16:27:39 -0700581
582 if (parent != nullptr) {
583 parentHandle = parent->getHandle();
584 }
585 status_t err = mClient->createSurface(name, w, h, format, flags, parentHandle,
Albert Chaulk479c60c2017-01-27 14:21:34 -0500586 windowType, ownerUid, &handle, &gbp);
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700587 ALOGE_IF(err, "SurfaceComposerClient::createSurface error %s", strerror(-err));
588 if (err == NO_ERROR) {
589 sur = new SurfaceControl(this, handle, gbp);
Mathias Agopian698c0872011-06-28 19:09:31 -0700590 }
591 }
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700592 return sur;
Mathias Agopian698c0872011-06-28 19:09:31 -0700593}
594
Mathias Agopianac9fa422013-02-11 16:40:36 -0800595status_t SurfaceComposerClient::destroySurface(const sp<IBinder>& sid) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700596 if (mStatus != NO_ERROR)
597 return mStatus;
598 status_t err = mClient->destroySurface(sid);
599 return err;
600}
601
Svetoslavd85084b2014-03-20 10:28:31 -0700602status_t SurfaceComposerClient::clearLayerFrameStats(const sp<IBinder>& token) const {
603 if (mStatus != NO_ERROR) {
604 return mStatus;
605 }
606 return mClient->clearLayerFrameStats(token);
607}
608
609status_t SurfaceComposerClient::getLayerFrameStats(const sp<IBinder>& token,
610 FrameStats* outStats) const {
611 if (mStatus != NO_ERROR) {
612 return mStatus;
613 }
614 return mClient->getLayerFrameStats(token, outStats);
615}
616
Mathias Agopian698c0872011-06-28 19:09:31 -0700617// ----------------------------------------------------------------------------
618
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -0700619status_t SurfaceComposerClient::enableVSyncInjections(bool enable) {
Robert Carr4cdc58f2017-08-23 14:22:20 -0700620 sp<ISurfaceComposer> sf(ComposerService::getComposerService());
621 return sf->enableVSyncInjections(enable);
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -0700622}
623
624status_t SurfaceComposerClient::injectVSync(nsecs_t when) {
Robert Carr4cdc58f2017-08-23 14:22:20 -0700625 sp<ISurfaceComposer> sf(ComposerService::getComposerService());
626 return sf->injectVSync(when);
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -0700627}
628
Dan Stoza7f7da322014-05-02 15:26:25 -0700629status_t SurfaceComposerClient::getDisplayConfigs(
630 const sp<IBinder>& display, Vector<DisplayInfo>* configs)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800631{
Dan Stoza7f7da322014-05-02 15:26:25 -0700632 return ComposerService::getComposerService()->getDisplayConfigs(display, configs);
633}
634
635status_t SurfaceComposerClient::getDisplayInfo(const sp<IBinder>& display,
636 DisplayInfo* info) {
637 Vector<DisplayInfo> configs;
638 status_t result = getDisplayConfigs(display, &configs);
639 if (result != NO_ERROR) {
640 return result;
641 }
642
643 int activeId = getActiveConfig(display);
644 if (activeId < 0) {
645 ALOGE("No active configuration found");
646 return NAME_NOT_FOUND;
647 }
648
Dan Stozad723bd72014-11-18 10:24:03 -0800649 *info = configs[static_cast<size_t>(activeId)];
Dan Stoza7f7da322014-05-02 15:26:25 -0700650 return NO_ERROR;
651}
652
653int SurfaceComposerClient::getActiveConfig(const sp<IBinder>& display) {
654 return ComposerService::getComposerService()->getActiveConfig(display);
655}
656
657status_t SurfaceComposerClient::setActiveConfig(const sp<IBinder>& display, int id) {
658 return ComposerService::getComposerService()->setActiveConfig(display, id);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800659}
660
Michael Wright28f24d02016-07-12 13:30:53 -0700661status_t SurfaceComposerClient::getDisplayColorModes(const sp<IBinder>& display,
662 Vector<android_color_mode_t>* outColorModes) {
663 return ComposerService::getComposerService()->getDisplayColorModes(display, outColorModes);
664}
665
666android_color_mode_t SurfaceComposerClient::getActiveColorMode(const sp<IBinder>& display) {
667 return ComposerService::getComposerService()->getActiveColorMode(display);
668}
669
670status_t SurfaceComposerClient::setActiveColorMode(const sp<IBinder>& display,
671 android_color_mode_t colorMode) {
672 return ComposerService::getComposerService()->setActiveColorMode(display, colorMode);
673}
674
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700675void SurfaceComposerClient::setDisplayPowerMode(const sp<IBinder>& token,
676 int mode) {
677 ComposerService::getComposerService()->setPowerMode(token, mode);
Jeff Brown2a09bb32012-10-08 19:13:57 -0700678}
679
Svetoslavd85084b2014-03-20 10:28:31 -0700680status_t SurfaceComposerClient::clearAnimationFrameStats() {
681 return ComposerService::getComposerService()->clearAnimationFrameStats();
682}
683
684status_t SurfaceComposerClient::getAnimationFrameStats(FrameStats* outStats) {
685 return ComposerService::getComposerService()->getAnimationFrameStats(outStats);
686}
687
Dan Stozac4f471e2016-03-24 09:31:08 -0700688status_t SurfaceComposerClient::getHdrCapabilities(const sp<IBinder>& display,
689 HdrCapabilities* outCapabilities) {
690 return ComposerService::getComposerService()->getHdrCapabilities(display,
691 outCapabilities);
692}
693
Mathias Agopian698c0872011-06-28 19:09:31 -0700694// ----------------------------------------------------------------------------
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800695
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800696status_t ScreenshotClient::capture(
697 const sp<IBinder>& display,
698 const sp<IGraphicBufferProducer>& producer,
Dan Stozac1879002014-05-22 15:59:05 -0700699 Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
Robert Carrae060832016-11-28 10:51:00 -0800700 int32_t minLayerZ, int32_t maxLayerZ, bool useIdentityTransform) {
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800701 sp<ISurfaceComposer> s(ComposerService::getComposerService());
702 if (s == NULL) return NO_INIT;
Dan Stozac1879002014-05-22 15:59:05 -0700703 return s->captureScreen(display, producer, sourceCrop,
Dan Stozac7014012014-02-14 15:03:43 -0800704 reqWidth, reqHeight, minLayerZ, maxLayerZ, useIdentityTransform);
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800705}
706
Robert Carr673134e2017-01-09 19:48:38 -0800707status_t ScreenshotClient::captureToBuffer(const sp<IBinder>& display,
708 Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
Robert Carrae060832016-11-28 10:51:00 -0800709 int32_t minLayerZ, int32_t maxLayerZ, bool useIdentityTransform,
Robert Carr673134e2017-01-09 19:48:38 -0800710 uint32_t rotation,
711 sp<GraphicBuffer>* outBuffer) {
712 sp<ISurfaceComposer> s(ComposerService::getComposerService());
713 if (s == NULL) return NO_INIT;
714
715 sp<IGraphicBufferConsumer> gbpConsumer;
716 sp<IGraphicBufferProducer> producer;
717 BufferQueue::createBufferQueue(&producer, &gbpConsumer);
718 sp<BufferItemConsumer> consumer(new BufferItemConsumer(gbpConsumer,
719 GRALLOC_USAGE_HW_TEXTURE | GRALLOC_USAGE_SW_READ_NEVER | GRALLOC_USAGE_SW_WRITE_NEVER,
720 1, true));
721
722 status_t ret = s->captureScreen(display, producer, sourceCrop, reqWidth, reqHeight,
723 minLayerZ, maxLayerZ, useIdentityTransform,
724 static_cast<ISurfaceComposer::Rotation>(rotation));
725 if (ret != NO_ERROR) {
726 return ret;
727 }
728 BufferItem b;
729 consumer->acquireBuffer(&b, 0, true);
730 *outBuffer = b.mGraphicBuffer;
731 return ret;
732}
733
chaviwa76b2712017-09-20 12:02:26 -0700734status_t ScreenshotClient::captureLayers(const sp<IBinder>& layerHandle,
735 const sp<IGraphicBufferProducer>& producer,
736 uint32_t rotation) {
737 sp<ISurfaceComposer> s(ComposerService::getComposerService());
738 if (s == NULL) return NO_INIT;
739 return s->captureLayers(layerHandle, producer,
740 static_cast<ISurfaceComposer::Rotation>(rotation));
741}
742
Mathias Agopian74c40c02010-09-29 13:02:36 -0700743ScreenshotClient::ScreenshotClient()
Mathias Agopianabe815d2013-03-19 22:22:21 -0700744 : mHaveBuffer(false) {
745 memset(&mBuffer, 0, sizeof(mBuffer));
Mathias Agopian74c40c02010-09-29 13:02:36 -0700746}
747
Mathias Agopian8000d062013-03-26 18:15:35 -0700748ScreenshotClient::~ScreenshotClient() {
749 ScreenshotClient::release();
750}
751
Mathias Agopianabe815d2013-03-19 22:22:21 -0700752sp<CpuConsumer> ScreenshotClient::getCpuConsumer() const {
753 if (mCpuConsumer == NULL) {
Dan Stoza6d5a7bb2014-03-13 11:39:09 -0700754 sp<IGraphicBufferConsumer> consumer;
755 BufferQueue::createBufferQueue(&mProducer, &consumer);
756 mCpuConsumer = new CpuConsumer(consumer, 1);
Mathias Agopianabe815d2013-03-19 22:22:21 -0700757 mCpuConsumer->setName(String8("ScreenshotClient"));
758 }
759 return mCpuConsumer;
Mathias Agopianbf2c6a62010-12-10 16:22:31 -0800760}
761
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700762status_t ScreenshotClient::update(const sp<IBinder>& display,
Dan Stozac1879002014-05-22 15:59:05 -0700763 Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
Robert Carrae060832016-11-28 10:51:00 -0800764 int32_t minLayerZ, int32_t maxLayerZ,
Riley Andrewsd15ef272014-09-04 16:19:44 -0700765 bool useIdentityTransform, uint32_t rotation) {
Mathias Agopianbf2c6a62010-12-10 16:22:31 -0800766 sp<ISurfaceComposer> s(ComposerService::getComposerService());
767 if (s == NULL) return NO_INIT;
Mathias Agopianabe815d2013-03-19 22:22:21 -0700768 sp<CpuConsumer> cpuConsumer = getCpuConsumer();
769
770 if (mHaveBuffer) {
771 mCpuConsumer->unlockBuffer(mBuffer);
772 memset(&mBuffer, 0, sizeof(mBuffer));
773 mHaveBuffer = false;
774 }
775
Dan Stozac1879002014-05-22 15:59:05 -0700776 status_t err = s->captureScreen(display, mProducer, sourceCrop,
Riley Andrewsd15ef272014-09-04 16:19:44 -0700777 reqWidth, reqHeight, minLayerZ, maxLayerZ, useIdentityTransform,
778 static_cast<ISurfaceComposer::Rotation>(rotation));
Mathias Agopianabe815d2013-03-19 22:22:21 -0700779
780 if (err == NO_ERROR) {
781 err = mCpuConsumer->lockNextBuffer(&mBuffer);
782 if (err == NO_ERROR) {
783 mHaveBuffer = true;
784 }
785 }
786 return err;
787}
788
Riley Andrewsd15ef272014-09-04 16:19:44 -0700789status_t ScreenshotClient::update(const sp<IBinder>& display,
790 Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
Robert Carrae060832016-11-28 10:51:00 -0800791 int32_t minLayerZ, int32_t maxLayerZ,
Riley Andrewsd15ef272014-09-04 16:19:44 -0700792 bool useIdentityTransform) {
793
794 return ScreenshotClient::update(display, sourceCrop, reqWidth, reqHeight,
795 minLayerZ, maxLayerZ, useIdentityTransform, ISurfaceComposer::eRotateNone);
796}
797
Dan Stozac1879002014-05-22 15:59:05 -0700798status_t ScreenshotClient::update(const sp<IBinder>& display, Rect sourceCrop,
Dan Stozac7014012014-02-14 15:03:43 -0800799 bool useIdentityTransform) {
Robert Carrae060832016-11-28 10:51:00 -0800800 return ScreenshotClient::update(display, sourceCrop, 0, 0,
801 INT32_MIN, INT32_MAX,
Riley Andrewsd15ef272014-09-04 16:19:44 -0700802 useIdentityTransform, ISurfaceComposer::eRotateNone);
Mathias Agopianabe815d2013-03-19 22:22:21 -0700803}
804
Dan Stozac1879002014-05-22 15:59:05 -0700805status_t ScreenshotClient::update(const sp<IBinder>& display, Rect sourceCrop,
Dan Stozac7014012014-02-14 15:03:43 -0800806 uint32_t reqWidth, uint32_t reqHeight, bool useIdentityTransform) {
Dan Stozac1879002014-05-22 15:59:05 -0700807 return ScreenshotClient::update(display, sourceCrop, reqWidth, reqHeight,
Robert Carrae060832016-11-28 10:51:00 -0800808 INT32_MIN, INT32_MAX,
809 useIdentityTransform, ISurfaceComposer::eRotateNone);
Mathias Agopian74c40c02010-09-29 13:02:36 -0700810}
811
812void ScreenshotClient::release() {
Mathias Agopianabe815d2013-03-19 22:22:21 -0700813 if (mHaveBuffer) {
814 mCpuConsumer->unlockBuffer(mBuffer);
815 memset(&mBuffer, 0, sizeof(mBuffer));
816 mHaveBuffer = false;
817 }
818 mCpuConsumer.clear();
Mathias Agopian74c40c02010-09-29 13:02:36 -0700819}
820
821void const* ScreenshotClient::getPixels() const {
Mathias Agopianabe815d2013-03-19 22:22:21 -0700822 return mBuffer.data;
Mathias Agopian74c40c02010-09-29 13:02:36 -0700823}
824
825uint32_t ScreenshotClient::getWidth() const {
Mathias Agopianabe815d2013-03-19 22:22:21 -0700826 return mBuffer.width;
Mathias Agopian74c40c02010-09-29 13:02:36 -0700827}
828
829uint32_t ScreenshotClient::getHeight() const {
Mathias Agopianabe815d2013-03-19 22:22:21 -0700830 return mBuffer.height;
Mathias Agopian74c40c02010-09-29 13:02:36 -0700831}
832
833PixelFormat ScreenshotClient::getFormat() const {
Mathias Agopianabe815d2013-03-19 22:22:21 -0700834 return mBuffer.format;
Mathias Agopian74c40c02010-09-29 13:02:36 -0700835}
836
837uint32_t ScreenshotClient::getStride() const {
Mathias Agopianabe815d2013-03-19 22:22:21 -0700838 return mBuffer.stride;
Mathias Agopian74c40c02010-09-29 13:02:36 -0700839}
840
841size_t ScreenshotClient::getSize() const {
Mathias Agopianabe815d2013-03-19 22:22:21 -0700842 return mBuffer.stride * mBuffer.height * bytesPerPixel(mBuffer.format);
Mathias Agopian74c40c02010-09-29 13:02:36 -0700843}
844
Romain Guy88d37dd2017-05-26 17:57:05 -0700845android_dataspace ScreenshotClient::getDataSpace() const {
846 return mBuffer.dataSpace;
847}
848
Mathias Agopian74c40c02010-09-29 13:02:36 -0700849// ----------------------------------------------------------------------------
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800850}; // namespace android