blob: 7ed12b7bb4dfc6737b08a4becdaef8f890c02d1e [file] [log] [blame]
The Android Open Source Projectedbf3b62009-03-04 03:31:441/*
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-04 03:31:4420#include <sys/types.h>
The Android Open Source Projectedbf3b62009-03-04 03:31:4421
The Android Open Source Projectedbf3b62009-03-04 03:31:4422#include <utils/Errors.h>
The Android Open Source Projectedbf3b62009-03-04 03:31:4423#include <utils/Log.h>
Mathias Agopiand4784a32010-05-28 02:41:1524#include <utils/Singleton.h>
Mathias Agopiana67932f2011-04-20 21:20:5925#include <utils/SortedVector.h>
26#include <utils/String8.h>
27#include <utils/threads.h>
The Android Open Source Projectedbf3b62009-03-04 03:31:4428
Mathias Agopian9cce3252010-02-10 01:46:3729#include <binder/IMemory.h>
Mathias Agopiana67932f2011-04-20 21:20:5930#include <binder/IServiceManager.h>
Mathias Agopian9cce3252010-02-10 01:46:3731
Michael Wright28f24d02016-07-12 20:30:5332#include <system/graphics.h>
33
Mathias Agopian076b1cc2009-04-10 21:24:3034#include <ui/DisplayInfo.h>
The Android Open Source Projectedbf3b62009-03-04 03:31:4435
Mathias Agopianabe815d2013-03-20 05:22:2136#include <gui/CpuConsumer.h>
Mathias Agopiane3c697f2013-02-15 01:11:0237#include <gui/IGraphicBufferProducer.h>
Mathias Agopian90ac7992012-02-26 02:48:3538#include <gui/ISurfaceComposer.h>
39#include <gui/ISurfaceComposerClient.h>
40#include <gui/SurfaceComposerClient.h>
The Android Open Source Projectedbf3b62009-03-04 03:31:4441
Mathias Agopian41f673c2011-11-18 01:48:3542#include <private/gui/ComposerService.h>
Mathias Agopian90ac7992012-02-26 02:48:3543#include <private/gui/LayerState.h>
The Android Open Source Projectedbf3b62009-03-04 03:31:4444
45namespace android {
The Android Open Source Projectedbf3b62009-03-04 03:31:4446// ---------------------------------------------------------------------------
47
Mathias Agopian7e27f052010-05-28 21:22:2348ANDROID_SINGLETON_STATIC_INSTANCE(ComposerService);
49
Mathias Agopianb7e930d2010-06-01 22:12:5850ComposerService::ComposerService()
51: Singleton<ComposerService>() {
Andy McFadden6652b3e2012-09-07 01:45:5652 Mutex::Autolock _l(mLock);
53 connectLocked();
54}
55
56void ComposerService::connectLocked() {
Mathias Agopianb7e930d2010-06-01 22:12:5857 const String16 name("SurfaceFlinger");
58 while (getService(name, &mComposerService) != NO_ERROR) {
59 usleep(250000);
60 }
Andy McFadden6652b3e2012-09-07 01:45:5661 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:
72 DeathObserver(ComposerService& mgr) : mComposerService(mgr) { }
73 };
74
75 mDeathObserver = new DeathObserver(*const_cast<ComposerService*>(this));
Marco Nelissen2ea926b2014-11-14 16:01:0176 IInterface::asBinder(mComposerService)->linkToDeath(mDeathObserver);
Mathias Agopianb7e930d2010-06-01 22:12:5877}
78
Andy McFadden6652b3e2012-09-07 01:45:5679/*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 22:12:5895}
96
Mathias Agopian7e27f052010-05-28 21:22:2397// ---------------------------------------------------------------------------
98
Mathias Agopian698c0872011-06-29 02:09:3199static inline
Mathias Agopiane57f2922012-08-09 23:29:12100int compare_type(const ComposerState& lhs, const ComposerState& rhs) {
Mathias Agopian698c0872011-06-29 02:09:31101 if (lhs.client < rhs.client) return -1;
102 if (lhs.client > rhs.client) return 1;
103 if (lhs.state.surface < rhs.state.surface) return -1;
104 if (lhs.state.surface > rhs.state.surface) return 1;
105 return 0;
106}
107
Mathias Agopiane57f2922012-08-09 23:29:12108static inline
109int compare_type(const DisplayState& lhs, const DisplayState& rhs) {
110 return compare_type(lhs.token, rhs.token);
111}
112
Mathias Agopian7e27f052010-05-28 21:22:23113class Composer : public Singleton<Composer>
114{
Mathias Agopiand4784a32010-05-28 02:41:15115 friend class Singleton<Composer>;
116
Mathias Agopian698c0872011-06-29 02:09:31117 mutable Mutex mLock;
Mathias Agopiane57f2922012-08-09 23:29:12118 SortedVector<ComposerState> mComposerStates;
119 SortedVector<DisplayState > mDisplayStates;
Jamie Gennis28378392011-10-13 00:39:00120 uint32_t mForceSynchronous;
Jeff Brownf3f7db62012-08-31 09:18:38121 uint32_t mTransactionNestCount;
Jamie Gennis2d5e2302012-10-16 01:24:43122 bool mAnimation;
Mathias Agopian698c0872011-06-29 02:09:31123
Jamie Gennisb8d69a52011-10-10 22:48:06124 Composer() : Singleton<Composer>(),
Jeff Brownf3f7db62012-08-31 09:18:38125 mForceSynchronous(0), mTransactionNestCount(0),
Jamie Gennis2d5e2302012-10-16 01:24:43126 mAnimation(false)
Jamie Gennis28378392011-10-13 00:39:00127 { }
Mathias Agopian698c0872011-06-29 02:09:31128
Jeff Brownf3f7db62012-08-31 09:18:38129 void openGlobalTransactionImpl();
Jamie Gennis28378392011-10-13 00:39:00130 void closeGlobalTransactionImpl(bool synchronous);
Jamie Gennis2d5e2302012-10-16 01:24:43131 void setAnimationTransactionImpl();
Mathias Agopian698c0872011-06-29 02:09:31132
133 layer_state_t* getLayerStateLocked(
Mathias Agopianac9fa422013-02-12 00:40:36134 const sp<SurfaceComposerClient>& client, const sp<IBinder>& id);
Mathias Agopian698c0872011-06-29 02:09:31135
Mathias Agopiane57f2922012-08-09 23:29:12136 DisplayState& getDisplayStateLocked(const sp<IBinder>& token);
137
Mathias Agopiand4784a32010-05-28 02:41:15138public:
Jamie Gennisdd3cb842012-10-20 01:19:11139 sp<IBinder> createDisplay(const String8& displayName, bool secure);
Jesse Hall6c913be2013-08-08 19:15:49140 void destroyDisplay(const sp<IBinder>& display);
Jeff Brown9d4e3d22012-08-25 03:00:51141 sp<IBinder> getBuiltInDisplay(int32_t id);
Mathias Agopian698c0872011-06-29 02:09:31142
Mathias Agopianac9fa422013-02-12 00:40:36143 status_t setPosition(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
Mathias Agopian41b6aab2011-08-31 01:51:54144 float x, float y);
Mathias Agopianac9fa422013-02-12 00:40:36145 status_t setSize(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
Mathias Agopian698c0872011-06-29 02:09:31146 uint32_t w, uint32_t h);
Mathias Agopianac9fa422013-02-12 00:40:36147 status_t setLayer(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
Dan Stozad723bd72014-11-18 18:24:03148 uint32_t z);
Mathias Agopianac9fa422013-02-12 00:40:36149 status_t setFlags(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
Mathias Agopian698c0872011-06-29 02:09:31150 uint32_t flags, uint32_t mask);
151 status_t setTransparentRegionHint(
Mathias Agopianac9fa422013-02-12 00:40:36152 const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
Mathias Agopian698c0872011-06-29 02:09:31153 const Region& transparentRegion);
Mathias Agopianac9fa422013-02-12 00:40:36154 status_t setAlpha(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
Mathias Agopian698c0872011-06-29 02:09:31155 float alpha);
Mathias Agopianac9fa422013-02-12 00:40:36156 status_t setMatrix(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
Mathias Agopian698c0872011-06-29 02:09:31157 float dsdx, float dtdx, float dsdy, float dtdy);
Jamie Gennisb8d69a52011-10-10 22:48:06158 status_t setOrientation(int orientation);
Mathias Agopianac9fa422013-02-12 00:40:36159 status_t setCrop(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
Jamie Gennisf15a83f2012-05-11 03:43:55160 const Rect& crop);
Pablo Ceballosacbe6782016-03-04 17:54:21161 status_t setFinalCrop(const sp<SurfaceComposerClient>& client,
162 const sp<IBinder>& id, const Rect& crop);
Mathias Agopian87855782012-07-25 04:41:09163 status_t setLayerStack(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-12 00:40:36164 const sp<IBinder>& id, uint32_t layerStack);
Dan Stoza7dde5992015-05-22 16:51:44165 status_t deferTransactionUntil(const sp<SurfaceComposerClient>& client,
166 const sp<IBinder>& id, const sp<IBinder>& handle,
167 uint64_t frameNumber);
Robert Carrc3574f72016-03-24 19:19:32168 status_t setOverrideScalingMode(const sp<SurfaceComposerClient>& client,
169 const sp<IBinder>& id, int32_t overrideScalingMode);
Robert Carr99e27f02016-06-16 22:18:02170 status_t setGeometryAppliesWithResize(const sp<SurfaceComposerClient>& client,
Robert Carr82364e32016-05-15 18:27:47171 const sp<IBinder>& id);
Mathias Agopian698c0872011-06-29 02:09:31172
Pablo Ceballos1aad24c2016-08-04 17:24:22173 status_t setDisplaySurface(const sp<IBinder>& token,
174 sp<IGraphicBufferProducer> bufferProducer);
Mathias Agopiane57f2922012-08-09 23:29:12175 void setDisplayLayerStack(const sp<IBinder>& token, uint32_t layerStack);
Mathias Agopian00e8c7a2012-09-05 02:30:46176 void setDisplayProjection(const sp<IBinder>& token,
177 uint32_t orientation,
178 const Rect& layerStackRect,
179 const Rect& displayRect);
Michael Wright1f6078a2014-06-26 23:01:02180 void setDisplaySize(const sp<IBinder>& token, uint32_t width, uint32_t height);
Mathias Agopiane57f2922012-08-09 23:29:12181
Jamie Gennis2d5e2302012-10-16 01:24:43182 static void setAnimationTransaction() {
183 Composer::getInstance().setAnimationTransactionImpl();
184 }
185
Jeff Brownf3f7db62012-08-31 09:18:38186 static void openGlobalTransaction() {
187 Composer::getInstance().openGlobalTransactionImpl();
188 }
189
Jamie Gennis28378392011-10-13 00:39:00190 static void closeGlobalTransaction(bool synchronous) {
191 Composer::getInstance().closeGlobalTransactionImpl(synchronous);
Mathias Agopiand4784a32010-05-28 02:41:15192 }
193};
194
195ANDROID_SINGLETON_STATIC_INSTANCE(Composer);
196
The Android Open Source Projectedbf3b62009-03-04 03:31:44197// ---------------------------------------------------------------------------
198
Jamie Gennisdd3cb842012-10-20 01:19:11199sp<IBinder> Composer::createDisplay(const String8& displayName, bool secure) {
200 return ComposerService::getComposerService()->createDisplay(displayName,
201 secure);
Mathias Agopiane57f2922012-08-09 23:29:12202}
203
Jesse Hall6c913be2013-08-08 19:15:49204void Composer::destroyDisplay(const sp<IBinder>& display) {
205 return ComposerService::getComposerService()->destroyDisplay(display);
206}
207
Jeff Brown9d4e3d22012-08-25 03:00:51208sp<IBinder> Composer::getBuiltInDisplay(int32_t id) {
209 return ComposerService::getComposerService()->getBuiltInDisplay(id);
210}
211
Jeff Brownf3f7db62012-08-31 09:18:38212void Composer::openGlobalTransactionImpl() {
213 { // scope for the lock
214 Mutex::Autolock _l(mLock);
215 mTransactionNestCount += 1;
216 }
217}
218
Jamie Gennis28378392011-10-13 00:39:00219void Composer::closeGlobalTransactionImpl(bool synchronous) {
Mathias Agopiane57f2922012-08-09 23:29:12220 sp<ISurfaceComposer> sm(ComposerService::getComposerService());
Mathias Agopian698c0872011-06-29 02:09:31221
222 Vector<ComposerState> transaction;
Mathias Agopian8b33f032012-07-25 03:43:54223 Vector<DisplayState> displayTransaction;
Jamie Gennis28378392011-10-13 00:39:00224 uint32_t flags = 0;
Mathias Agopian698c0872011-06-29 02:09:31225
226 { // scope for the lock
227 Mutex::Autolock _l(mLock);
Jeff Brownf3f7db62012-08-31 09:18:38228 mForceSynchronous |= synchronous;
229 if (!mTransactionNestCount) {
230 ALOGW("At least one call to closeGlobalTransaction() was not matched by a prior "
231 "call to openGlobalTransaction().");
232 } else if (--mTransactionNestCount) {
233 return;
234 }
235
Mathias Agopiane57f2922012-08-09 23:29:12236 transaction = mComposerStates;
237 mComposerStates.clear();
Jamie Gennisb8d69a52011-10-10 22:48:06238
Mathias Agopiane57f2922012-08-09 23:29:12239 displayTransaction = mDisplayStates;
240 mDisplayStates.clear();
Jamie Gennis28378392011-10-13 00:39:00241
Jeff Brownf3f7db62012-08-31 09:18:38242 if (mForceSynchronous) {
Jamie Gennis28378392011-10-13 00:39:00243 flags |= ISurfaceComposer::eSynchronous;
244 }
Jamie Gennis2d5e2302012-10-16 01:24:43245 if (mAnimation) {
246 flags |= ISurfaceComposer::eAnimation;
247 }
248
Jamie Gennis28378392011-10-13 00:39:00249 mForceSynchronous = false;
Jamie Gennis2d5e2302012-10-16 01:24:43250 mAnimation = false;
Mathias Agopian698c0872011-06-29 02:09:31251 }
252
Mathias Agopian8b33f032012-07-25 03:43:54253 sm->setTransactionState(transaction, displayTransaction, flags);
The Android Open Source Projectedbf3b62009-03-04 03:31:44254}
255
Jamie Gennis2d5e2302012-10-16 01:24:43256void Composer::setAnimationTransactionImpl() {
257 Mutex::Autolock _l(mLock);
258 mAnimation = true;
259}
260
Mathias Agopian698c0872011-06-29 02:09:31261layer_state_t* Composer::getLayerStateLocked(
Mathias Agopianac9fa422013-02-12 00:40:36262 const sp<SurfaceComposerClient>& client, const sp<IBinder>& id) {
Mathias Agopian698c0872011-06-29 02:09:31263
264 ComposerState s;
265 s.client = client->mClient;
266 s.state.surface = id;
267
Mathias Agopiane57f2922012-08-09 23:29:12268 ssize_t index = mComposerStates.indexOf(s);
Mathias Agopian698c0872011-06-29 02:09:31269 if (index < 0) {
270 // we don't have it, add an initialized layer_state to our list
Mathias Agopiane57f2922012-08-09 23:29:12271 index = mComposerStates.add(s);
Mathias Agopian698c0872011-06-29 02:09:31272 }
273
Mathias Agopiane57f2922012-08-09 23:29:12274 ComposerState* const out = mComposerStates.editArray();
Mathias Agopian698c0872011-06-29 02:09:31275 return &(out[index].state);
276}
277
278status_t Composer::setPosition(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-12 00:40:36279 const sp<IBinder>& id, float x, float y) {
Mathias Agopian698c0872011-06-29 02:09:31280 Mutex::Autolock _l(mLock);
281 layer_state_t* s = getLayerStateLocked(client, id);
282 if (!s)
283 return BAD_INDEX;
Mathias Agopian3165cc22012-08-09 02:42:09284 s->what |= layer_state_t::ePositionChanged;
Mathias Agopian698c0872011-06-29 02:09:31285 s->x = x;
286 s->y = y;
287 return NO_ERROR;
288}
289
290status_t Composer::setSize(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-12 00:40:36291 const sp<IBinder>& id, uint32_t w, uint32_t h) {
Mathias Agopian698c0872011-06-29 02:09:31292 Mutex::Autolock _l(mLock);
293 layer_state_t* s = getLayerStateLocked(client, id);
294 if (!s)
295 return BAD_INDEX;
Mathias Agopian3165cc22012-08-09 02:42:09296 s->what |= layer_state_t::eSizeChanged;
Mathias Agopian698c0872011-06-29 02:09:31297 s->w = w;
298 s->h = h;
Jamie Gennis28378392011-10-13 00:39:00299
Jorim Jaggi092123c2016-04-13 01:40:35300 // Resizing a surface makes the transaction synchronous.
301 mForceSynchronous = true;
302
Mathias Agopian698c0872011-06-29 02:09:31303 return NO_ERROR;
304}
305
306status_t Composer::setLayer(const sp<SurfaceComposerClient>& client,
Dan Stozad723bd72014-11-18 18:24:03307 const sp<IBinder>& id, uint32_t z) {
Mathias Agopian698c0872011-06-29 02:09:31308 Mutex::Autolock _l(mLock);
309 layer_state_t* s = getLayerStateLocked(client, id);
310 if (!s)
311 return BAD_INDEX;
Mathias Agopian3165cc22012-08-09 02:42:09312 s->what |= layer_state_t::eLayerChanged;
Mathias Agopian698c0872011-06-29 02:09:31313 s->z = z;
314 return NO_ERROR;
315}
316
317status_t Composer::setFlags(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-12 00:40:36318 const sp<IBinder>& id, uint32_t flags,
Mathias Agopian698c0872011-06-29 02:09:31319 uint32_t mask) {
320 Mutex::Autolock _l(mLock);
321 layer_state_t* s = getLayerStateLocked(client, id);
322 if (!s)
323 return BAD_INDEX;
Pablo Ceballos53390e12015-08-04 18:25:59324 if ((mask & layer_state_t::eLayerOpaque) ||
325 (mask & layer_state_t::eLayerHidden) ||
326 (mask & layer_state_t::eLayerSecure)) {
Dan Stoza23116082015-06-18 21:58:39327 s->what |= layer_state_t::eFlagsChanged;
Andy McFadden4125a4f2014-01-30 01:17:11328 }
Mathias Agopian698c0872011-06-29 02:09:31329 s->flags &= ~mask;
330 s->flags |= (flags & mask);
331 s->mask |= mask;
332 return NO_ERROR;
333}
334
335status_t Composer::setTransparentRegionHint(
Mathias Agopianac9fa422013-02-12 00:40:36336 const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
Mathias Agopian698c0872011-06-29 02:09:31337 const Region& transparentRegion) {
338 Mutex::Autolock _l(mLock);
339 layer_state_t* s = getLayerStateLocked(client, id);
340 if (!s)
341 return BAD_INDEX;
Mathias Agopian3165cc22012-08-09 02:42:09342 s->what |= layer_state_t::eTransparentRegionChanged;
Mathias Agopian698c0872011-06-29 02:09:31343 s->transparentRegion = transparentRegion;
344 return NO_ERROR;
345}
346
347status_t Composer::setAlpha(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-12 00:40:36348 const sp<IBinder>& id, float alpha) {
Mathias Agopian698c0872011-06-29 02:09:31349 Mutex::Autolock _l(mLock);
350 layer_state_t* s = getLayerStateLocked(client, id);
351 if (!s)
352 return BAD_INDEX;
Mathias Agopian3165cc22012-08-09 02:42:09353 s->what |= layer_state_t::eAlphaChanged;
Mathias Agopian698c0872011-06-29 02:09:31354 s->alpha = alpha;
355 return NO_ERROR;
356}
357
Mathias Agopian87855782012-07-25 04:41:09358status_t Composer::setLayerStack(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-12 00:40:36359 const sp<IBinder>& id, uint32_t layerStack) {
Mathias Agopian87855782012-07-25 04:41:09360 Mutex::Autolock _l(mLock);
361 layer_state_t* s = getLayerStateLocked(client, id);
362 if (!s)
363 return BAD_INDEX;
Mathias Agopian3165cc22012-08-09 02:42:09364 s->what |= layer_state_t::eLayerStackChanged;
Mathias Agopian87855782012-07-25 04:41:09365 s->layerStack = layerStack;
366 return NO_ERROR;
367}
368
Mathias Agopian698c0872011-06-29 02:09:31369status_t Composer::setMatrix(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-12 00:40:36370 const sp<IBinder>& id, float dsdx, float dtdx,
Mathias Agopian698c0872011-06-29 02:09:31371 float dsdy, float dtdy) {
372 Mutex::Autolock _l(mLock);
373 layer_state_t* s = getLayerStateLocked(client, id);
374 if (!s)
375 return BAD_INDEX;
Mathias Agopian3165cc22012-08-09 02:42:09376 s->what |= layer_state_t::eMatrixChanged;
Mathias Agopian698c0872011-06-29 02:09:31377 layer_state_t::matrix22_t matrix;
378 matrix.dsdx = dsdx;
379 matrix.dtdx = dtdx;
380 matrix.dsdy = dsdy;
381 matrix.dtdy = dtdy;
382 s->matrix = matrix;
383 return NO_ERROR;
384}
385
Jamie Gennisf15a83f2012-05-11 03:43:55386status_t Composer::setCrop(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-12 00:40:36387 const sp<IBinder>& id, const Rect& crop) {
Jamie Gennisf15a83f2012-05-11 03:43:55388 Mutex::Autolock _l(mLock);
389 layer_state_t* s = getLayerStateLocked(client, id);
390 if (!s)
391 return BAD_INDEX;
Mathias Agopian3165cc22012-08-09 02:42:09392 s->what |= layer_state_t::eCropChanged;
Jamie Gennisf15a83f2012-05-11 03:43:55393 s->crop = crop;
394 return NO_ERROR;
395}
396
Pablo Ceballosacbe6782016-03-04 17:54:21397status_t Composer::setFinalCrop(const sp<SurfaceComposerClient>& client,
398 const sp<IBinder>& id, const Rect& crop) {
399 Mutex::Autolock _l(mLock);
400 layer_state_t* s = getLayerStateLocked(client, id);
401 if (!s) {
402 return BAD_INDEX;
403 }
404 s->what |= layer_state_t::eFinalCropChanged;
405 s->finalCrop = crop;
406 return NO_ERROR;
407}
408
Dan Stoza7dde5992015-05-22 16:51:44409status_t Composer::deferTransactionUntil(
410 const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
411 const sp<IBinder>& handle, uint64_t frameNumber) {
412 Mutex::Autolock lock(mLock);
413 layer_state_t* s = getLayerStateLocked(client, id);
414 if (!s) {
415 return BAD_INDEX;
416 }
417 s->what |= layer_state_t::eDeferTransaction;
418 s->handle = handle;
419 s->frameNumber = frameNumber;
420 return NO_ERROR;
421}
422
Robert Carrc3574f72016-03-24 19:19:32423status_t Composer::setOverrideScalingMode(
424 const sp<SurfaceComposerClient>& client,
425 const sp<IBinder>& id, int32_t overrideScalingMode) {
426 Mutex::Autolock lock(mLock);
427 layer_state_t* s = getLayerStateLocked(client, id);
428 if (!s) {
429 return BAD_INDEX;
430 }
431
432 switch (overrideScalingMode) {
433 case NATIVE_WINDOW_SCALING_MODE_FREEZE:
434 case NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW:
435 case NATIVE_WINDOW_SCALING_MODE_SCALE_CROP:
436 case NATIVE_WINDOW_SCALING_MODE_NO_SCALE_CROP:
437 case -1:
438 break;
439 default:
440 ALOGE("unknown scaling mode: %d",
441 overrideScalingMode);
442 return BAD_VALUE;
443 }
444
445 s->what |= layer_state_t::eOverrideScalingModeChanged;
446 s->overrideScalingMode = overrideScalingMode;
447 return NO_ERROR;
448}
449
Robert Carr99e27f02016-06-16 22:18:02450status_t Composer::setGeometryAppliesWithResize(
Robert Carr82364e32016-05-15 18:27:47451 const sp<SurfaceComposerClient>& client,
452 const sp<IBinder>& id) {
453 Mutex::Autolock lock(mLock);
454 layer_state_t* s = getLayerStateLocked(client, id);
455 if (!s) {
456 return BAD_INDEX;
457 }
Robert Carr99e27f02016-06-16 22:18:02458 s->what |= layer_state_t::eGeometryAppliesWithResize;
Robert Carr82364e32016-05-15 18:27:47459 return NO_ERROR;
460}
461
Mathias Agopian698c0872011-06-29 02:09:31462// ---------------------------------------------------------------------------
463
Mathias Agopiane57f2922012-08-09 23:29:12464DisplayState& Composer::getDisplayStateLocked(const sp<IBinder>& token) {
465 DisplayState s;
466 s.token = token;
467 ssize_t index = mDisplayStates.indexOf(s);
468 if (index < 0) {
469 // we don't have it, add an initialized layer_state to our list
470 s.what = 0;
471 index = mDisplayStates.add(s);
472 }
Dan Stozad723bd72014-11-18 18:24:03473 return mDisplayStates.editItemAt(static_cast<size_t>(index));
Mathias Agopiane57f2922012-08-09 23:29:12474}
475
Pablo Ceballos1aad24c2016-08-04 17:24:22476status_t Composer::setDisplaySurface(const sp<IBinder>& token,
477 sp<IGraphicBufferProducer> bufferProducer) {
478 // Make sure that composition can never be stalled by a virtual display
479 // consumer that isn't processing buffers fast enough.
480 status_t err = bufferProducer->setAsyncMode(true);
481 if (err != NO_ERROR) {
482 ALOGE("Composer::setDisplaySurface Failed to enable async mode on the "
483 "BufferQueue. This BufferQueue cannot be used for virtual "
484 "display. (%d)", err);
485 return err;
486 }
Mathias Agopiane57f2922012-08-09 23:29:12487 Mutex::Autolock _l(mLock);
488 DisplayState& s(getDisplayStateLocked(token));
Andy McFadden2adaf042012-12-18 17:49:45489 s.surface = bufferProducer;
Mathias Agopiane57f2922012-08-09 23:29:12490 s.what |= DisplayState::eSurfaceChanged;
Pablo Ceballos1aad24c2016-08-04 17:24:22491 return NO_ERROR;
Mathias Agopiane57f2922012-08-09 23:29:12492}
493
494void Composer::setDisplayLayerStack(const sp<IBinder>& token,
495 uint32_t layerStack) {
496 Mutex::Autolock _l(mLock);
497 DisplayState& s(getDisplayStateLocked(token));
498 s.layerStack = layerStack;
499 s.what |= DisplayState::eLayerStackChanged;
500}
501
Mathias Agopian00e8c7a2012-09-05 02:30:46502void Composer::setDisplayProjection(const sp<IBinder>& token,
503 uint32_t orientation,
504 const Rect& layerStackRect,
505 const Rect& displayRect) {
Mathias Agopiane57f2922012-08-09 23:29:12506 Mutex::Autolock _l(mLock);
507 DisplayState& s(getDisplayStateLocked(token));
508 s.orientation = orientation;
Mathias Agopian00e8c7a2012-09-05 02:30:46509 s.viewport = layerStackRect;
510 s.frame = displayRect;
511 s.what |= DisplayState::eDisplayProjectionChanged;
Jorim Jaggi092123c2016-04-13 01:40:35512 mForceSynchronous = true; // TODO: do we actually still need this?
Mathias Agopiane57f2922012-08-09 23:29:12513}
514
Michael Wright1f6078a2014-06-26 23:01:02515void Composer::setDisplaySize(const sp<IBinder>& token, uint32_t width, uint32_t height) {
516 Mutex::Autolock _l(mLock);
517 DisplayState& s(getDisplayStateLocked(token));
518 s.width = width;
519 s.height = height;
520 s.what |= DisplayState::eDisplaySizeChanged;
521}
522
Mathias Agopiane57f2922012-08-09 23:29:12523// ---------------------------------------------------------------------------
524
The Android Open Source Projectedbf3b62009-03-04 03:31:44525SurfaceComposerClient::SurfaceComposerClient()
Mathias Agopian698c0872011-06-29 02:09:31526 : mStatus(NO_INIT), mComposer(Composer::getInstance())
The Android Open Source Projectedbf3b62009-03-04 03:31:44527{
The Android Open Source Projectedbf3b62009-03-04 03:31:44528}
529
Mathias Agopian698c0872011-06-29 02:09:31530void SurfaceComposerClient::onFirstRef() {
Mathias Agopiane57f2922012-08-09 23:29:12531 sp<ISurfaceComposer> sm(ComposerService::getComposerService());
Mathias Agopiand4784a32010-05-28 02:41:15532 if (sm != 0) {
Mathias Agopian7e27f052010-05-28 21:22:23533 sp<ISurfaceComposerClient> conn = sm->createConnection();
Mathias Agopiand4784a32010-05-28 02:41:15534 if (conn != 0) {
535 mClient = conn;
Mathias Agopiand4784a32010-05-28 02:41:15536 mStatus = NO_ERROR;
537 }
538 }
The Android Open Source Projectedbf3b62009-03-04 03:31:44539}
540
Mathias Agopian698c0872011-06-29 02:09:31541SurfaceComposerClient::~SurfaceComposerClient() {
Mathias Agopian631f3582010-05-26 00:51:34542 dispose();
543}
Mathias Agopiandd3423c2009-09-23 22:44:05544
Mathias Agopian698c0872011-06-29 02:09:31545status_t SurfaceComposerClient::initCheck() const {
The Android Open Source Projectedbf3b62009-03-04 03:31:44546 return mStatus;
547}
548
Mathias Agopian698c0872011-06-29 02:09:31549sp<IBinder> SurfaceComposerClient::connection() const {
Marco Nelissen2ea926b2014-11-14 16:01:01550 return IInterface::asBinder(mClient);
The Android Open Source Projectedbf3b62009-03-04 03:31:44551}
552
Mathias Agopiand4784a32010-05-28 02:41:15553status_t SurfaceComposerClient::linkToComposerDeath(
554 const sp<IBinder::DeathRecipient>& recipient,
Mathias Agopian698c0872011-06-29 02:09:31555 void* cookie, uint32_t flags) {
Mathias Agopiane57f2922012-08-09 23:29:12556 sp<ISurfaceComposer> sm(ComposerService::getComposerService());
Marco Nelissen2ea926b2014-11-14 16:01:01557 return IInterface::asBinder(sm)->linkToDeath(recipient, cookie, flags);
The Android Open Source Projectedbf3b62009-03-04 03:31:44558}
559
Mathias Agopian698c0872011-06-29 02:09:31560void SurfaceComposerClient::dispose() {
The Android Open Source Projectedbf3b62009-03-04 03:31:44561 // this can be called more than once.
Mathias Agopian7e27f052010-05-28 21:22:23562 sp<ISurfaceComposerClient> client;
Mathias Agopiand4784a32010-05-28 02:41:15563 Mutex::Autolock _lm(mLock);
564 if (mClient != 0) {
Mathias Agopiand4784a32010-05-28 02:41:15565 client = mClient; // hold ref while lock is held
566 mClient.clear();
The Android Open Source Projectedbf3b62009-03-04 03:31:44567 }
Mathias Agopiand4784a32010-05-28 02:41:15568 mStatus = NO_INIT;
The Android Open Source Projectedbf3b62009-03-04 03:31:44569}
570
Mathias Agopian698c0872011-06-29 02:09:31571sp<SurfaceControl> SurfaceComposerClient::createSurface(
Mathias Agopian698c0872011-06-29 02:09:31572 const String8& name,
Mathias Agopian698c0872011-06-29 02:09:31573 uint32_t w,
574 uint32_t h,
575 PixelFormat format,
576 uint32_t flags)
577{
Mathias Agopian4d9b8222013-03-13 00:11:48578 sp<SurfaceControl> sur;
Mathias Agopian698c0872011-06-29 02:09:31579 if (mStatus == NO_ERROR) {
Mathias Agopian4d9b8222013-03-13 00:11:48580 sp<IBinder> handle;
581 sp<IGraphicBufferProducer> gbp;
582 status_t err = mClient->createSurface(name, w, h, format, flags,
583 &handle, &gbp);
584 ALOGE_IF(err, "SurfaceComposerClient::createSurface error %s", strerror(-err));
585 if (err == NO_ERROR) {
586 sur = new SurfaceControl(this, handle, gbp);
Mathias Agopian698c0872011-06-29 02:09:31587 }
588 }
Mathias Agopian4d9b8222013-03-13 00:11:48589 return sur;
Mathias Agopian698c0872011-06-29 02:09:31590}
591
Jamie Gennisdd3cb842012-10-20 01:19:11592sp<IBinder> SurfaceComposerClient::createDisplay(const String8& displayName,
593 bool secure) {
594 return Composer::getInstance().createDisplay(displayName, secure);
Mathias Agopiane57f2922012-08-09 23:29:12595}
596
Jesse Hall6c913be2013-08-08 19:15:49597void SurfaceComposerClient::destroyDisplay(const sp<IBinder>& display) {
598 Composer::getInstance().destroyDisplay(display);
599}
600
Jeff Brown9d4e3d22012-08-25 03:00:51601sp<IBinder> SurfaceComposerClient::getBuiltInDisplay(int32_t id) {
602 return Composer::getInstance().getBuiltInDisplay(id);
603}
604
Mathias Agopianac9fa422013-02-12 00:40:36605status_t SurfaceComposerClient::destroySurface(const sp<IBinder>& sid) {
Mathias Agopian698c0872011-06-29 02:09:31606 if (mStatus != NO_ERROR)
607 return mStatus;
608 status_t err = mClient->destroySurface(sid);
609 return err;
610}
611
Svetoslavd85084b2014-03-20 17:28:31612status_t SurfaceComposerClient::clearLayerFrameStats(const sp<IBinder>& token) const {
613 if (mStatus != NO_ERROR) {
614 return mStatus;
615 }
616 return mClient->clearLayerFrameStats(token);
617}
618
619status_t SurfaceComposerClient::getLayerFrameStats(const sp<IBinder>& token,
620 FrameStats* outStats) const {
621 if (mStatus != NO_ERROR) {
622 return mStatus;
623 }
624 return mClient->getLayerFrameStats(token, outStats);
625}
626
Robert Carr367c5682016-06-20 18:55:28627status_t SurfaceComposerClient::getTransformToDisplayInverse(const sp<IBinder>& token,
628 bool* outTransformToDisplayInverse) const {
629 if (mStatus != NO_ERROR) {
630 return mStatus;
631 }
632 return mClient->getTransformToDisplayInverse(token, outTransformToDisplayInverse);
633}
634
Mathias Agopian698c0872011-06-29 02:09:31635inline Composer& SurfaceComposerClient::getComposer() {
636 return mComposer;
637}
638
639// ----------------------------------------------------------------------------
640
641void SurfaceComposerClient::openGlobalTransaction() {
Jeff Brownf3f7db62012-08-31 09:18:38642 Composer::openGlobalTransaction();
Mathias Agopian698c0872011-06-29 02:09:31643}
644
Jamie Gennis28378392011-10-13 00:39:00645void SurfaceComposerClient::closeGlobalTransaction(bool synchronous) {
646 Composer::closeGlobalTransaction(synchronous);
Mathias Agopian698c0872011-06-29 02:09:31647}
648
Jamie Gennis2d5e2302012-10-16 01:24:43649void SurfaceComposerClient::setAnimationTransaction() {
650 Composer::setAnimationTransaction();
651}
652
Mathias Agopian698c0872011-06-29 02:09:31653// ----------------------------------------------------------------------------
654
Mathias Agopianac9fa422013-02-12 00:40:36655status_t SurfaceComposerClient::setCrop(const sp<IBinder>& id, const Rect& crop) {
Jamie Gennisf15a83f2012-05-11 03:43:55656 return getComposer().setCrop(this, id, crop);
657}
658
Pablo Ceballosacbe6782016-03-04 17:54:21659status_t SurfaceComposerClient::setFinalCrop(const sp<IBinder>& id,
660 const Rect& crop) {
661 return getComposer().setFinalCrop(this, id, crop);
662}
663
Mathias Agopianac9fa422013-02-12 00:40:36664status_t SurfaceComposerClient::setPosition(const sp<IBinder>& id, float x, float y) {
Mathias Agopian698c0872011-06-29 02:09:31665 return getComposer().setPosition(this, id, x, y);
666}
667
Mathias Agopianac9fa422013-02-12 00:40:36668status_t SurfaceComposerClient::setSize(const sp<IBinder>& id, uint32_t w, uint32_t h) {
Mathias Agopian698c0872011-06-29 02:09:31669 return getComposer().setSize(this, id, w, h);
670}
671
Dan Stozad723bd72014-11-18 18:24:03672status_t SurfaceComposerClient::setLayer(const sp<IBinder>& id, uint32_t z) {
Mathias Agopian698c0872011-06-29 02:09:31673 return getComposer().setLayer(this, id, z);
674}
675
Mathias Agopianac9fa422013-02-12 00:40:36676status_t SurfaceComposerClient::hide(const sp<IBinder>& id) {
Mathias Agopian698c0872011-06-29 02:09:31677 return getComposer().setFlags(this, id,
Mathias Agopian3165cc22012-08-09 02:42:09678 layer_state_t::eLayerHidden,
679 layer_state_t::eLayerHidden);
Mathias Agopian698c0872011-06-29 02:09:31680}
681
Mathias Agopianac9fa422013-02-12 00:40:36682status_t SurfaceComposerClient::show(const sp<IBinder>& id) {
Mathias Agopian698c0872011-06-29 02:09:31683 return getComposer().setFlags(this, id,
684 0,
Mathias Agopian3165cc22012-08-09 02:42:09685 layer_state_t::eLayerHidden);
Mathias Agopian698c0872011-06-29 02:09:31686}
687
Mathias Agopianac9fa422013-02-12 00:40:36688status_t SurfaceComposerClient::setFlags(const sp<IBinder>& id, uint32_t flags,
Mathias Agopian698c0872011-06-29 02:09:31689 uint32_t mask) {
690 return getComposer().setFlags(this, id, flags, mask);
691}
692
Mathias Agopianac9fa422013-02-12 00:40:36693status_t SurfaceComposerClient::setTransparentRegionHint(const sp<IBinder>& id,
Mathias Agopian698c0872011-06-29 02:09:31694 const Region& transparentRegion) {
695 return getComposer().setTransparentRegionHint(this, id, transparentRegion);
696}
697
Mathias Agopianac9fa422013-02-12 00:40:36698status_t SurfaceComposerClient::setAlpha(const sp<IBinder>& id, float alpha) {
Mathias Agopian698c0872011-06-29 02:09:31699 return getComposer().setAlpha(this, id, alpha);
700}
701
Mathias Agopianac9fa422013-02-12 00:40:36702status_t SurfaceComposerClient::setLayerStack(const sp<IBinder>& id, uint32_t layerStack) {
Mathias Agopian87855782012-07-25 04:41:09703 return getComposer().setLayerStack(this, id, layerStack);
704}
705
Mathias Agopianac9fa422013-02-12 00:40:36706status_t SurfaceComposerClient::setMatrix(const sp<IBinder>& id, float dsdx, float dtdx,
Mathias Agopian698c0872011-06-29 02:09:31707 float dsdy, float dtdy) {
708 return getComposer().setMatrix(this, id, dsdx, dtdx, dsdy, dtdy);
709}
710
Dan Stoza7dde5992015-05-22 16:51:44711status_t SurfaceComposerClient::deferTransactionUntil(const sp<IBinder>& id,
712 const sp<IBinder>& handle, uint64_t frameNumber) {
713 return getComposer().deferTransactionUntil(this, id, handle, frameNumber);
714}
715
Robert Carrc3574f72016-03-24 19:19:32716status_t SurfaceComposerClient::setOverrideScalingMode(
717 const sp<IBinder>& id, int32_t overrideScalingMode) {
718 return getComposer().setOverrideScalingMode(
719 this, id, overrideScalingMode);
720}
721
Robert Carr99e27f02016-06-16 22:18:02722status_t SurfaceComposerClient::setGeometryAppliesWithResize(
Robert Carr82364e32016-05-15 18:27:47723 const sp<IBinder>& id) {
Robert Carr99e27f02016-06-16 22:18:02724 return getComposer().setGeometryAppliesWithResize(this, id);
Robert Carr82364e32016-05-15 18:27:47725}
726
Mathias Agopian698c0872011-06-29 02:09:31727// ----------------------------------------------------------------------------
728
Pablo Ceballos1aad24c2016-08-04 17:24:22729status_t SurfaceComposerClient::setDisplaySurface(const sp<IBinder>& token,
730 sp<IGraphicBufferProducer> bufferProducer) {
731 return Composer::getInstance().setDisplaySurface(token, bufferProducer);
Mathias Agopiane57f2922012-08-09 23:29:12732}
733
734void SurfaceComposerClient::setDisplayLayerStack(const sp<IBinder>& token,
735 uint32_t layerStack) {
736 Composer::getInstance().setDisplayLayerStack(token, layerStack);
737}
738
Mathias Agopian00e8c7a2012-09-05 02:30:46739void SurfaceComposerClient::setDisplayProjection(const sp<IBinder>& token,
740 uint32_t orientation,
741 const Rect& layerStackRect,
742 const Rect& displayRect) {
743 Composer::getInstance().setDisplayProjection(token, orientation,
744 layerStackRect, displayRect);
Mathias Agopiane57f2922012-08-09 23:29:12745}
746
Michael Wright1f6078a2014-06-26 23:01:02747void SurfaceComposerClient::setDisplaySize(const sp<IBinder>& token,
748 uint32_t width, uint32_t height) {
749 Composer::getInstance().setDisplaySize(token, width, height);
750}
751
Mathias Agopiane57f2922012-08-09 23:29:12752// ----------------------------------------------------------------------------
753
Dan Stoza7f7da322014-05-02 22:26:25754status_t SurfaceComposerClient::getDisplayConfigs(
755 const sp<IBinder>& display, Vector<DisplayInfo>* configs)
The Android Open Source Projectedbf3b62009-03-04 03:31:44756{
Dan Stoza7f7da322014-05-02 22:26:25757 return ComposerService::getComposerService()->getDisplayConfigs(display, configs);
758}
759
760status_t SurfaceComposerClient::getDisplayInfo(const sp<IBinder>& display,
761 DisplayInfo* info) {
762 Vector<DisplayInfo> configs;
763 status_t result = getDisplayConfigs(display, &configs);
764 if (result != NO_ERROR) {
765 return result;
766 }
767
768 int activeId = getActiveConfig(display);
769 if (activeId < 0) {
770 ALOGE("No active configuration found");
771 return NAME_NOT_FOUND;
772 }
773
Dan Stozad723bd72014-11-18 18:24:03774 *info = configs[static_cast<size_t>(activeId)];
Dan Stoza7f7da322014-05-02 22:26:25775 return NO_ERROR;
776}
777
778int SurfaceComposerClient::getActiveConfig(const sp<IBinder>& display) {
779 return ComposerService::getComposerService()->getActiveConfig(display);
780}
781
782status_t SurfaceComposerClient::setActiveConfig(const sp<IBinder>& display, int id) {
783 return ComposerService::getComposerService()->setActiveConfig(display, id);
The Android Open Source Projectedbf3b62009-03-04 03:31:44784}
785
Michael Wright28f24d02016-07-12 20:30:53786status_t SurfaceComposerClient::getDisplayColorModes(const sp<IBinder>& display,
787 Vector<android_color_mode_t>* outColorModes) {
788 return ComposerService::getComposerService()->getDisplayColorModes(display, outColorModes);
789}
790
791android_color_mode_t SurfaceComposerClient::getActiveColorMode(const sp<IBinder>& display) {
792 return ComposerService::getComposerService()->getActiveColorMode(display);
793}
794
795status_t SurfaceComposerClient::setActiveColorMode(const sp<IBinder>& display,
796 android_color_mode_t colorMode) {
797 return ComposerService::getComposerService()->setActiveColorMode(display, colorMode);
798}
799
Prashant Malani2c9b11f2014-05-25 08:36:31800void SurfaceComposerClient::setDisplayPowerMode(const sp<IBinder>& token,
801 int mode) {
802 ComposerService::getComposerService()->setPowerMode(token, mode);
Jeff Brown2a09bb32012-10-09 02:13:57803}
804
Svetoslavd85084b2014-03-20 17:28:31805status_t SurfaceComposerClient::clearAnimationFrameStats() {
806 return ComposerService::getComposerService()->clearAnimationFrameStats();
807}
808
809status_t SurfaceComposerClient::getAnimationFrameStats(FrameStats* outStats) {
810 return ComposerService::getComposerService()->getAnimationFrameStats(outStats);
811}
812
Dan Stozac4f471e2016-03-24 16:31:08813status_t SurfaceComposerClient::getHdrCapabilities(const sp<IBinder>& display,
814 HdrCapabilities* outCapabilities) {
815 return ComposerService::getComposerService()->getHdrCapabilities(display,
816 outCapabilities);
817}
818
Mathias Agopian698c0872011-06-29 02:09:31819// ----------------------------------------------------------------------------
The Android Open Source Projectedbf3b62009-03-04 03:31:44820
Mathias Agopian2a9fc492013-03-01 21:42:57821status_t ScreenshotClient::capture(
822 const sp<IBinder>& display,
823 const sp<IGraphicBufferProducer>& producer,
Dan Stozac1879002014-05-22 22:59:05824 Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
Dan Stozac7014012014-02-14 23:03:43825 uint32_t minLayerZ, uint32_t maxLayerZ, bool useIdentityTransform) {
Mathias Agopian2a9fc492013-03-01 21:42:57826 sp<ISurfaceComposer> s(ComposerService::getComposerService());
827 if (s == NULL) return NO_INIT;
Dan Stozac1879002014-05-22 22:59:05828 return s->captureScreen(display, producer, sourceCrop,
Dan Stozac7014012014-02-14 23:03:43829 reqWidth, reqHeight, minLayerZ, maxLayerZ, useIdentityTransform);
Mathias Agopian2a9fc492013-03-01 21:42:57830}
831
Mathias Agopian74c40c02010-09-29 20:02:36832ScreenshotClient::ScreenshotClient()
Mathias Agopianabe815d2013-03-20 05:22:21833 : mHaveBuffer(false) {
834 memset(&mBuffer, 0, sizeof(mBuffer));
Mathias Agopian74c40c02010-09-29 20:02:36835}
836
Mathias Agopian8000d062013-03-27 01:15:35837ScreenshotClient::~ScreenshotClient() {
838 ScreenshotClient::release();
839}
840
Mathias Agopianabe815d2013-03-20 05:22:21841sp<CpuConsumer> ScreenshotClient::getCpuConsumer() const {
842 if (mCpuConsumer == NULL) {
Dan Stoza6d5a7bb2014-03-13 18:39:09843 sp<IGraphicBufferConsumer> consumer;
844 BufferQueue::createBufferQueue(&mProducer, &consumer);
845 mCpuConsumer = new CpuConsumer(consumer, 1);
Mathias Agopianabe815d2013-03-20 05:22:21846 mCpuConsumer->setName(String8("ScreenshotClient"));
847 }
848 return mCpuConsumer;
Mathias Agopianbf2c6a62010-12-11 00:22:31849}
850
Jeff Brown9d4e3d22012-08-25 03:00:51851status_t ScreenshotClient::update(const sp<IBinder>& display,
Dan Stozac1879002014-05-22 22:59:05852 Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
Dan Stozac7014012014-02-14 23:03:43853 uint32_t minLayerZ, uint32_t maxLayerZ,
Riley Andrewsd15ef272014-09-04 23:19:44854 bool useIdentityTransform, uint32_t rotation) {
Mathias Agopianbf2c6a62010-12-11 00:22:31855 sp<ISurfaceComposer> s(ComposerService::getComposerService());
856 if (s == NULL) return NO_INIT;
Mathias Agopianabe815d2013-03-20 05:22:21857 sp<CpuConsumer> cpuConsumer = getCpuConsumer();
858
859 if (mHaveBuffer) {
860 mCpuConsumer->unlockBuffer(mBuffer);
861 memset(&mBuffer, 0, sizeof(mBuffer));
862 mHaveBuffer = false;
863 }
864
Dan Stozac1879002014-05-22 22:59:05865 status_t err = s->captureScreen(display, mProducer, sourceCrop,
Riley Andrewsd15ef272014-09-04 23:19:44866 reqWidth, reqHeight, minLayerZ, maxLayerZ, useIdentityTransform,
867 static_cast<ISurfaceComposer::Rotation>(rotation));
Mathias Agopianabe815d2013-03-20 05:22:21868
869 if (err == NO_ERROR) {
870 err = mCpuConsumer->lockNextBuffer(&mBuffer);
871 if (err == NO_ERROR) {
872 mHaveBuffer = true;
873 }
874 }
875 return err;
876}
877
Riley Andrewsd15ef272014-09-04 23:19:44878status_t ScreenshotClient::update(const sp<IBinder>& display,
879 Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
880 uint32_t minLayerZ, uint32_t maxLayerZ,
881 bool useIdentityTransform) {
882
883 return ScreenshotClient::update(display, sourceCrop, reqWidth, reqHeight,
884 minLayerZ, maxLayerZ, useIdentityTransform, ISurfaceComposer::eRotateNone);
885}
886
Dan Stozac1879002014-05-22 22:59:05887status_t ScreenshotClient::update(const sp<IBinder>& display, Rect sourceCrop,
Dan Stozac7014012014-02-14 23:03:43888 bool useIdentityTransform) {
Dan Stozaf10c46e2014-11-11 18:32:31889 return ScreenshotClient::update(display, sourceCrop, 0, 0, 0, -1U,
Riley Andrewsd15ef272014-09-04 23:19:44890 useIdentityTransform, ISurfaceComposer::eRotateNone);
Mathias Agopianabe815d2013-03-20 05:22:21891}
892
Dan Stozac1879002014-05-22 22:59:05893status_t ScreenshotClient::update(const sp<IBinder>& display, Rect sourceCrop,
Dan Stozac7014012014-02-14 23:03:43894 uint32_t reqWidth, uint32_t reqHeight, bool useIdentityTransform) {
Dan Stozac1879002014-05-22 22:59:05895 return ScreenshotClient::update(display, sourceCrop, reqWidth, reqHeight,
Dan Stozaf10c46e2014-11-11 18:32:31896 0, -1U, useIdentityTransform, ISurfaceComposer::eRotateNone);
Mathias Agopian74c40c02010-09-29 20:02:36897}
898
899void ScreenshotClient::release() {
Mathias Agopianabe815d2013-03-20 05:22:21900 if (mHaveBuffer) {
901 mCpuConsumer->unlockBuffer(mBuffer);
902 memset(&mBuffer, 0, sizeof(mBuffer));
903 mHaveBuffer = false;
904 }
905 mCpuConsumer.clear();
Mathias Agopian74c40c02010-09-29 20:02:36906}
907
908void const* ScreenshotClient::getPixels() const {
Mathias Agopianabe815d2013-03-20 05:22:21909 return mBuffer.data;
Mathias Agopian74c40c02010-09-29 20:02:36910}
911
912uint32_t ScreenshotClient::getWidth() const {
Mathias Agopianabe815d2013-03-20 05:22:21913 return mBuffer.width;
Mathias Agopian74c40c02010-09-29 20:02:36914}
915
916uint32_t ScreenshotClient::getHeight() const {
Mathias Agopianabe815d2013-03-20 05:22:21917 return mBuffer.height;
Mathias Agopian74c40c02010-09-29 20:02:36918}
919
920PixelFormat ScreenshotClient::getFormat() const {
Mathias Agopianabe815d2013-03-20 05:22:21921 return mBuffer.format;
Mathias Agopian74c40c02010-09-29 20:02:36922}
923
924uint32_t ScreenshotClient::getStride() const {
Mathias Agopianabe815d2013-03-20 05:22:21925 return mBuffer.stride;
Mathias Agopian74c40c02010-09-29 20:02:36926}
927
928size_t ScreenshotClient::getSize() const {
Mathias Agopianabe815d2013-03-20 05:22:21929 return mBuffer.stride * mBuffer.height * bytesPerPixel(mBuffer.format);
Mathias Agopian74c40c02010-09-29 20:02:36930}
931
932// ----------------------------------------------------------------------------
The Android Open Source Projectedbf3b62009-03-04 03:31:44933}; // namespace android