blob: e33cc37b24256847de0581c9e4dc3b0c06e79fac [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);
Robert Carrc3574f72016-03-24 12:19:32 -0700166 status_t setOverrideScalingMode(const sp<SurfaceComposerClient>& client,
167 const sp<IBinder>& id, int32_t overrideScalingMode);
Mathias Agopian698c0872011-06-28 19:09:31 -0700168
Andy McFadden2adaf042012-12-18 09:49:45 -0800169 void setDisplaySurface(const sp<IBinder>& token,
170 const sp<IGraphicBufferProducer>& bufferProducer);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700171 void setDisplayLayerStack(const sp<IBinder>& token, uint32_t layerStack);
Mathias Agopian00e8c7a2012-09-04 19:30:46 -0700172 void setDisplayProjection(const sp<IBinder>& token,
173 uint32_t orientation,
174 const Rect& layerStackRect,
175 const Rect& displayRect);
Michael Wright1f6078a2014-06-26 16:01:02 -0700176 void setDisplaySize(const sp<IBinder>& token, uint32_t width, uint32_t height);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700177
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700178 static void setAnimationTransaction() {
179 Composer::getInstance().setAnimationTransactionImpl();
180 }
181
Jeff Brownf3f7db62012-08-31 02:18:38 -0700182 static void openGlobalTransaction() {
183 Composer::getInstance().openGlobalTransactionImpl();
184 }
185
Jamie Gennis28378392011-10-12 17:39:00 -0700186 static void closeGlobalTransaction(bool synchronous) {
187 Composer::getInstance().closeGlobalTransactionImpl(synchronous);
Mathias Agopiand4784a32010-05-27 19:41:15 -0700188 }
189};
190
191ANDROID_SINGLETON_STATIC_INSTANCE(Composer);
192
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800193// ---------------------------------------------------------------------------
194
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700195sp<IBinder> Composer::createDisplay(const String8& displayName, bool secure) {
196 return ComposerService::getComposerService()->createDisplay(displayName,
197 secure);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700198}
199
Jesse Hall6c913be2013-08-08 12:15:49 -0700200void Composer::destroyDisplay(const sp<IBinder>& display) {
201 return ComposerService::getComposerService()->destroyDisplay(display);
202}
203
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700204sp<IBinder> Composer::getBuiltInDisplay(int32_t id) {
205 return ComposerService::getComposerService()->getBuiltInDisplay(id);
206}
207
Jeff Brownf3f7db62012-08-31 02:18:38 -0700208void Composer::openGlobalTransactionImpl() {
209 { // scope for the lock
210 Mutex::Autolock _l(mLock);
211 mTransactionNestCount += 1;
212 }
213}
214
Jamie Gennis28378392011-10-12 17:39:00 -0700215void Composer::closeGlobalTransactionImpl(bool synchronous) {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700216 sp<ISurfaceComposer> sm(ComposerService::getComposerService());
Mathias Agopian698c0872011-06-28 19:09:31 -0700217
218 Vector<ComposerState> transaction;
Mathias Agopian8b33f032012-07-24 20:43:54 -0700219 Vector<DisplayState> displayTransaction;
Jamie Gennis28378392011-10-12 17:39:00 -0700220 uint32_t flags = 0;
Mathias Agopian698c0872011-06-28 19:09:31 -0700221
222 { // scope for the lock
223 Mutex::Autolock _l(mLock);
Jeff Brownf3f7db62012-08-31 02:18:38 -0700224 mForceSynchronous |= synchronous;
225 if (!mTransactionNestCount) {
226 ALOGW("At least one call to closeGlobalTransaction() was not matched by a prior "
227 "call to openGlobalTransaction().");
228 } else if (--mTransactionNestCount) {
229 return;
230 }
231
Mathias Agopiane57f2922012-08-09 16:29:12 -0700232 transaction = mComposerStates;
233 mComposerStates.clear();
Jamie Gennisb8d69a52011-10-10 15:48:06 -0700234
Mathias Agopiane57f2922012-08-09 16:29:12 -0700235 displayTransaction = mDisplayStates;
236 mDisplayStates.clear();
Jamie Gennis28378392011-10-12 17:39:00 -0700237
Jeff Brownf3f7db62012-08-31 02:18:38 -0700238 if (mForceSynchronous) {
Jamie Gennis28378392011-10-12 17:39:00 -0700239 flags |= ISurfaceComposer::eSynchronous;
240 }
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700241 if (mAnimation) {
242 flags |= ISurfaceComposer::eAnimation;
243 }
244
Jamie Gennis28378392011-10-12 17:39:00 -0700245 mForceSynchronous = false;
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700246 mAnimation = false;
Mathias Agopian698c0872011-06-28 19:09:31 -0700247 }
248
Mathias Agopian8b33f032012-07-24 20:43:54 -0700249 sm->setTransactionState(transaction, displayTransaction, flags);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800250}
251
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700252void Composer::setAnimationTransactionImpl() {
253 Mutex::Autolock _l(mLock);
254 mAnimation = true;
255}
256
Mathias Agopian698c0872011-06-28 19:09:31 -0700257layer_state_t* Composer::getLayerStateLocked(
Mathias Agopianac9fa422013-02-11 16:40:36 -0800258 const sp<SurfaceComposerClient>& client, const sp<IBinder>& id) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700259
260 ComposerState s;
261 s.client = client->mClient;
262 s.state.surface = id;
263
Mathias Agopiane57f2922012-08-09 16:29:12 -0700264 ssize_t index = mComposerStates.indexOf(s);
Mathias Agopian698c0872011-06-28 19:09:31 -0700265 if (index < 0) {
266 // we don't have it, add an initialized layer_state to our list
Mathias Agopiane57f2922012-08-09 16:29:12 -0700267 index = mComposerStates.add(s);
Mathias Agopian698c0872011-06-28 19:09:31 -0700268 }
269
Mathias Agopiane57f2922012-08-09 16:29:12 -0700270 ComposerState* const out = mComposerStates.editArray();
Mathias Agopian698c0872011-06-28 19:09:31 -0700271 return &(out[index].state);
272}
273
274status_t Composer::setPosition(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-11 16:40:36 -0800275 const sp<IBinder>& id, float x, float y) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700276 Mutex::Autolock _l(mLock);
277 layer_state_t* s = getLayerStateLocked(client, id);
278 if (!s)
279 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700280 s->what |= layer_state_t::ePositionChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700281 s->x = x;
282 s->y = y;
283 return NO_ERROR;
284}
285
286status_t Composer::setSize(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-11 16:40:36 -0800287 const sp<IBinder>& id, uint32_t w, uint32_t h) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700288 Mutex::Autolock _l(mLock);
289 layer_state_t* s = getLayerStateLocked(client, id);
290 if (!s)
291 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700292 s->what |= layer_state_t::eSizeChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700293 s->w = w;
294 s->h = h;
Jamie Gennis28378392011-10-12 17:39:00 -0700295
Jorim Jaggi092123c2016-04-13 01:40:35 +0000296 // Resizing a surface makes the transaction synchronous.
297 mForceSynchronous = true;
298
Mathias Agopian698c0872011-06-28 19:09:31 -0700299 return NO_ERROR;
300}
301
302status_t Composer::setLayer(const sp<SurfaceComposerClient>& client,
Dan Stozad723bd72014-11-18 10:24:03 -0800303 const sp<IBinder>& id, uint32_t z) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700304 Mutex::Autolock _l(mLock);
305 layer_state_t* s = getLayerStateLocked(client, id);
306 if (!s)
307 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700308 s->what |= layer_state_t::eLayerChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700309 s->z = z;
310 return NO_ERROR;
311}
312
313status_t Composer::setFlags(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-11 16:40:36 -0800314 const sp<IBinder>& id, uint32_t flags,
Mathias Agopian698c0872011-06-28 19:09:31 -0700315 uint32_t mask) {
316 Mutex::Autolock _l(mLock);
317 layer_state_t* s = getLayerStateLocked(client, id);
318 if (!s)
319 return BAD_INDEX;
Pablo Ceballos53390e12015-08-04 11:25:59 -0700320 if ((mask & layer_state_t::eLayerOpaque) ||
321 (mask & layer_state_t::eLayerHidden) ||
322 (mask & layer_state_t::eLayerSecure)) {
Dan Stoza23116082015-06-18 14:58:39 -0700323 s->what |= layer_state_t::eFlagsChanged;
Andy McFadden4125a4f2014-01-29 17:17:11 -0800324 }
Mathias Agopian698c0872011-06-28 19:09:31 -0700325 s->flags &= ~mask;
326 s->flags |= (flags & mask);
327 s->mask |= mask;
328 return NO_ERROR;
329}
330
331status_t Composer::setTransparentRegionHint(
Mathias Agopianac9fa422013-02-11 16:40:36 -0800332 const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
Mathias Agopian698c0872011-06-28 19:09:31 -0700333 const Region& transparentRegion) {
334 Mutex::Autolock _l(mLock);
335 layer_state_t* s = getLayerStateLocked(client, id);
336 if (!s)
337 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700338 s->what |= layer_state_t::eTransparentRegionChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700339 s->transparentRegion = transparentRegion;
340 return NO_ERROR;
341}
342
343status_t Composer::setAlpha(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-11 16:40:36 -0800344 const sp<IBinder>& id, float alpha) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700345 Mutex::Autolock _l(mLock);
346 layer_state_t* s = getLayerStateLocked(client, id);
347 if (!s)
348 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700349 s->what |= layer_state_t::eAlphaChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700350 s->alpha = alpha;
351 return NO_ERROR;
352}
353
Mathias Agopian87855782012-07-24 21:41:09 -0700354status_t Composer::setLayerStack(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-11 16:40:36 -0800355 const sp<IBinder>& id, uint32_t layerStack) {
Mathias Agopian87855782012-07-24 21:41:09 -0700356 Mutex::Autolock _l(mLock);
357 layer_state_t* s = getLayerStateLocked(client, id);
358 if (!s)
359 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700360 s->what |= layer_state_t::eLayerStackChanged;
Mathias Agopian87855782012-07-24 21:41:09 -0700361 s->layerStack = layerStack;
362 return NO_ERROR;
363}
364
Mathias Agopian698c0872011-06-28 19:09:31 -0700365status_t Composer::setMatrix(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-11 16:40:36 -0800366 const sp<IBinder>& id, float dsdx, float dtdx,
Mathias Agopian698c0872011-06-28 19:09:31 -0700367 float dsdy, float dtdy) {
368 Mutex::Autolock _l(mLock);
369 layer_state_t* s = getLayerStateLocked(client, id);
370 if (!s)
371 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700372 s->what |= layer_state_t::eMatrixChanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700373 layer_state_t::matrix22_t matrix;
374 matrix.dsdx = dsdx;
375 matrix.dtdx = dtdx;
376 matrix.dsdy = dsdy;
377 matrix.dtdy = dtdy;
378 s->matrix = matrix;
379 return NO_ERROR;
380}
381
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700382status_t Composer::setCrop(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-11 16:40:36 -0800383 const sp<IBinder>& id, const Rect& crop) {
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700384 Mutex::Autolock _l(mLock);
385 layer_state_t* s = getLayerStateLocked(client, id);
386 if (!s)
387 return BAD_INDEX;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700388 s->what |= layer_state_t::eCropChanged;
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700389 s->crop = crop;
390 return NO_ERROR;
391}
392
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000393status_t Composer::setFinalCrop(const sp<SurfaceComposerClient>& client,
394 const sp<IBinder>& id, const Rect& crop) {
395 Mutex::Autolock _l(mLock);
396 layer_state_t* s = getLayerStateLocked(client, id);
397 if (!s) {
398 return BAD_INDEX;
399 }
400 s->what |= layer_state_t::eFinalCropChanged;
401 s->finalCrop = crop;
402 return NO_ERROR;
403}
404
Dan Stoza7dde5992015-05-22 09:51:44 -0700405status_t Composer::deferTransactionUntil(
406 const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
407 const sp<IBinder>& handle, uint64_t frameNumber) {
408 Mutex::Autolock lock(mLock);
409 layer_state_t* s = getLayerStateLocked(client, id);
410 if (!s) {
411 return BAD_INDEX;
412 }
413 s->what |= layer_state_t::eDeferTransaction;
414 s->handle = handle;
415 s->frameNumber = frameNumber;
416 return NO_ERROR;
417}
418
Robert Carrc3574f72016-03-24 12:19:32 -0700419status_t Composer::setOverrideScalingMode(
420 const sp<SurfaceComposerClient>& client,
421 const sp<IBinder>& id, int32_t overrideScalingMode) {
422 Mutex::Autolock lock(mLock);
423 layer_state_t* s = getLayerStateLocked(client, id);
424 if (!s) {
425 return BAD_INDEX;
426 }
427
428 switch (overrideScalingMode) {
429 case NATIVE_WINDOW_SCALING_MODE_FREEZE:
430 case NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW:
431 case NATIVE_WINDOW_SCALING_MODE_SCALE_CROP:
432 case NATIVE_WINDOW_SCALING_MODE_NO_SCALE_CROP:
433 case -1:
434 break;
435 default:
436 ALOGE("unknown scaling mode: %d",
437 overrideScalingMode);
438 return BAD_VALUE;
439 }
440
441 s->what |= layer_state_t::eOverrideScalingModeChanged;
442 s->overrideScalingMode = overrideScalingMode;
443 return NO_ERROR;
444}
445
Mathias Agopian698c0872011-06-28 19:09:31 -0700446// ---------------------------------------------------------------------------
447
Mathias Agopiane57f2922012-08-09 16:29:12 -0700448DisplayState& Composer::getDisplayStateLocked(const sp<IBinder>& token) {
449 DisplayState s;
450 s.token = token;
451 ssize_t index = mDisplayStates.indexOf(s);
452 if (index < 0) {
453 // we don't have it, add an initialized layer_state to our list
454 s.what = 0;
455 index = mDisplayStates.add(s);
456 }
Dan Stozad723bd72014-11-18 10:24:03 -0800457 return mDisplayStates.editItemAt(static_cast<size_t>(index));
Mathias Agopiane57f2922012-08-09 16:29:12 -0700458}
459
460void Composer::setDisplaySurface(const sp<IBinder>& token,
Andy McFadden2adaf042012-12-18 09:49:45 -0800461 const sp<IGraphicBufferProducer>& bufferProducer) {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700462 Mutex::Autolock _l(mLock);
463 DisplayState& s(getDisplayStateLocked(token));
Andy McFadden2adaf042012-12-18 09:49:45 -0800464 s.surface = bufferProducer;
Mathias Agopiane57f2922012-08-09 16:29:12 -0700465 s.what |= DisplayState::eSurfaceChanged;
466}
467
468void Composer::setDisplayLayerStack(const sp<IBinder>& token,
469 uint32_t layerStack) {
470 Mutex::Autolock _l(mLock);
471 DisplayState& s(getDisplayStateLocked(token));
472 s.layerStack = layerStack;
473 s.what |= DisplayState::eLayerStackChanged;
474}
475
Mathias Agopian00e8c7a2012-09-04 19:30:46 -0700476void Composer::setDisplayProjection(const sp<IBinder>& token,
477 uint32_t orientation,
478 const Rect& layerStackRect,
479 const Rect& displayRect) {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700480 Mutex::Autolock _l(mLock);
481 DisplayState& s(getDisplayStateLocked(token));
482 s.orientation = orientation;
Mathias Agopian00e8c7a2012-09-04 19:30:46 -0700483 s.viewport = layerStackRect;
484 s.frame = displayRect;
485 s.what |= DisplayState::eDisplayProjectionChanged;
Jorim Jaggi092123c2016-04-13 01:40:35 +0000486 mForceSynchronous = true; // TODO: do we actually still need this?
Mathias Agopiane57f2922012-08-09 16:29:12 -0700487}
488
Michael Wright1f6078a2014-06-26 16:01:02 -0700489void Composer::setDisplaySize(const sp<IBinder>& token, uint32_t width, uint32_t height) {
490 Mutex::Autolock _l(mLock);
491 DisplayState& s(getDisplayStateLocked(token));
492 s.width = width;
493 s.height = height;
494 s.what |= DisplayState::eDisplaySizeChanged;
495}
496
Mathias Agopiane57f2922012-08-09 16:29:12 -0700497// ---------------------------------------------------------------------------
498
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800499SurfaceComposerClient::SurfaceComposerClient()
Mathias Agopian698c0872011-06-28 19:09:31 -0700500 : mStatus(NO_INIT), mComposer(Composer::getInstance())
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800501{
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800502}
503
Mathias Agopian698c0872011-06-28 19:09:31 -0700504void SurfaceComposerClient::onFirstRef() {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700505 sp<ISurfaceComposer> sm(ComposerService::getComposerService());
Mathias Agopiand4784a32010-05-27 19:41:15 -0700506 if (sm != 0) {
Mathias Agopian7e27f052010-05-28 14:22:23 -0700507 sp<ISurfaceComposerClient> conn = sm->createConnection();
Mathias Agopiand4784a32010-05-27 19:41:15 -0700508 if (conn != 0) {
509 mClient = conn;
Mathias Agopiand4784a32010-05-27 19:41:15 -0700510 mStatus = NO_ERROR;
511 }
512 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800513}
514
Mathias Agopian698c0872011-06-28 19:09:31 -0700515SurfaceComposerClient::~SurfaceComposerClient() {
Mathias Agopian631f3582010-05-25 17:51:34 -0700516 dispose();
517}
Mathias Agopiandd3423c2009-09-23 15:44:05 -0700518
Mathias Agopian698c0872011-06-28 19:09:31 -0700519status_t SurfaceComposerClient::initCheck() const {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800520 return mStatus;
521}
522
Mathias Agopian698c0872011-06-28 19:09:31 -0700523sp<IBinder> SurfaceComposerClient::connection() const {
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800524 return IInterface::asBinder(mClient);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800525}
526
Mathias Agopiand4784a32010-05-27 19:41:15 -0700527status_t SurfaceComposerClient::linkToComposerDeath(
528 const sp<IBinder::DeathRecipient>& recipient,
Mathias Agopian698c0872011-06-28 19:09:31 -0700529 void* cookie, uint32_t flags) {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700530 sp<ISurfaceComposer> sm(ComposerService::getComposerService());
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800531 return IInterface::asBinder(sm)->linkToDeath(recipient, cookie, flags);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800532}
533
Mathias Agopian698c0872011-06-28 19:09:31 -0700534void SurfaceComposerClient::dispose() {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800535 // this can be called more than once.
Mathias Agopian7e27f052010-05-28 14:22:23 -0700536 sp<ISurfaceComposerClient> client;
Mathias Agopiand4784a32010-05-27 19:41:15 -0700537 Mutex::Autolock _lm(mLock);
538 if (mClient != 0) {
Mathias Agopiand4784a32010-05-27 19:41:15 -0700539 client = mClient; // hold ref while lock is held
540 mClient.clear();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800541 }
Mathias Agopiand4784a32010-05-27 19:41:15 -0700542 mStatus = NO_INIT;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800543}
544
Mathias Agopian698c0872011-06-28 19:09:31 -0700545sp<SurfaceControl> SurfaceComposerClient::createSurface(
Mathias Agopian698c0872011-06-28 19:09:31 -0700546 const String8& name,
Mathias Agopian698c0872011-06-28 19:09:31 -0700547 uint32_t w,
548 uint32_t h,
549 PixelFormat format,
550 uint32_t flags)
551{
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700552 sp<SurfaceControl> sur;
Mathias Agopian698c0872011-06-28 19:09:31 -0700553 if (mStatus == NO_ERROR) {
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700554 sp<IBinder> handle;
555 sp<IGraphicBufferProducer> gbp;
556 status_t err = mClient->createSurface(name, w, h, format, flags,
557 &handle, &gbp);
558 ALOGE_IF(err, "SurfaceComposerClient::createSurface error %s", strerror(-err));
559 if (err == NO_ERROR) {
560 sur = new SurfaceControl(this, handle, gbp);
Mathias Agopian698c0872011-06-28 19:09:31 -0700561 }
562 }
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700563 return sur;
Mathias Agopian698c0872011-06-28 19:09:31 -0700564}
565
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700566sp<IBinder> SurfaceComposerClient::createDisplay(const String8& displayName,
567 bool secure) {
568 return Composer::getInstance().createDisplay(displayName, secure);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700569}
570
Jesse Hall6c913be2013-08-08 12:15:49 -0700571void SurfaceComposerClient::destroyDisplay(const sp<IBinder>& display) {
572 Composer::getInstance().destroyDisplay(display);
573}
574
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700575sp<IBinder> SurfaceComposerClient::getBuiltInDisplay(int32_t id) {
576 return Composer::getInstance().getBuiltInDisplay(id);
577}
578
Mathias Agopianac9fa422013-02-11 16:40:36 -0800579status_t SurfaceComposerClient::destroySurface(const sp<IBinder>& sid) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700580 if (mStatus != NO_ERROR)
581 return mStatus;
582 status_t err = mClient->destroySurface(sid);
583 return err;
584}
585
Svetoslavd85084b2014-03-20 10:28:31 -0700586status_t SurfaceComposerClient::clearLayerFrameStats(const sp<IBinder>& token) const {
587 if (mStatus != NO_ERROR) {
588 return mStatus;
589 }
590 return mClient->clearLayerFrameStats(token);
591}
592
593status_t SurfaceComposerClient::getLayerFrameStats(const sp<IBinder>& token,
594 FrameStats* outStats) const {
595 if (mStatus != NO_ERROR) {
596 return mStatus;
597 }
598 return mClient->getLayerFrameStats(token, outStats);
599}
600
Mathias Agopian698c0872011-06-28 19:09:31 -0700601inline Composer& SurfaceComposerClient::getComposer() {
602 return mComposer;
603}
604
605// ----------------------------------------------------------------------------
606
607void SurfaceComposerClient::openGlobalTransaction() {
Jeff Brownf3f7db62012-08-31 02:18:38 -0700608 Composer::openGlobalTransaction();
Mathias Agopian698c0872011-06-28 19:09:31 -0700609}
610
Jamie Gennis28378392011-10-12 17:39:00 -0700611void SurfaceComposerClient::closeGlobalTransaction(bool synchronous) {
612 Composer::closeGlobalTransaction(synchronous);
Mathias Agopian698c0872011-06-28 19:09:31 -0700613}
614
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700615void SurfaceComposerClient::setAnimationTransaction() {
616 Composer::setAnimationTransaction();
617}
618
Mathias Agopian698c0872011-06-28 19:09:31 -0700619// ----------------------------------------------------------------------------
620
Mathias Agopianac9fa422013-02-11 16:40:36 -0800621status_t SurfaceComposerClient::setCrop(const sp<IBinder>& id, const Rect& crop) {
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700622 return getComposer().setCrop(this, id, crop);
623}
624
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000625status_t SurfaceComposerClient::setFinalCrop(const sp<IBinder>& id,
626 const Rect& crop) {
627 return getComposer().setFinalCrop(this, id, crop);
628}
629
Mathias Agopianac9fa422013-02-11 16:40:36 -0800630status_t SurfaceComposerClient::setPosition(const sp<IBinder>& id, float x, float y) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700631 return getComposer().setPosition(this, id, x, y);
632}
633
Mathias Agopianac9fa422013-02-11 16:40:36 -0800634status_t SurfaceComposerClient::setSize(const sp<IBinder>& id, uint32_t w, uint32_t h) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700635 return getComposer().setSize(this, id, w, h);
636}
637
Dan Stozad723bd72014-11-18 10:24:03 -0800638status_t SurfaceComposerClient::setLayer(const sp<IBinder>& id, uint32_t z) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700639 return getComposer().setLayer(this, id, z);
640}
641
Mathias Agopianac9fa422013-02-11 16:40:36 -0800642status_t SurfaceComposerClient::hide(const sp<IBinder>& id) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700643 return getComposer().setFlags(this, id,
Mathias Agopian3165cc22012-08-08 19:42:09 -0700644 layer_state_t::eLayerHidden,
645 layer_state_t::eLayerHidden);
Mathias Agopian698c0872011-06-28 19:09:31 -0700646}
647
Mathias Agopianac9fa422013-02-11 16:40:36 -0800648status_t SurfaceComposerClient::show(const sp<IBinder>& id) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700649 return getComposer().setFlags(this, id,
650 0,
Mathias Agopian3165cc22012-08-08 19:42:09 -0700651 layer_state_t::eLayerHidden);
Mathias Agopian698c0872011-06-28 19:09:31 -0700652}
653
Mathias Agopianac9fa422013-02-11 16:40:36 -0800654status_t SurfaceComposerClient::setFlags(const sp<IBinder>& id, uint32_t flags,
Mathias Agopian698c0872011-06-28 19:09:31 -0700655 uint32_t mask) {
656 return getComposer().setFlags(this, id, flags, mask);
657}
658
Mathias Agopianac9fa422013-02-11 16:40:36 -0800659status_t SurfaceComposerClient::setTransparentRegionHint(const sp<IBinder>& id,
Mathias Agopian698c0872011-06-28 19:09:31 -0700660 const Region& transparentRegion) {
661 return getComposer().setTransparentRegionHint(this, id, transparentRegion);
662}
663
Mathias Agopianac9fa422013-02-11 16:40:36 -0800664status_t SurfaceComposerClient::setAlpha(const sp<IBinder>& id, float alpha) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700665 return getComposer().setAlpha(this, id, alpha);
666}
667
Mathias Agopianac9fa422013-02-11 16:40:36 -0800668status_t SurfaceComposerClient::setLayerStack(const sp<IBinder>& id, uint32_t layerStack) {
Mathias Agopian87855782012-07-24 21:41:09 -0700669 return getComposer().setLayerStack(this, id, layerStack);
670}
671
Mathias Agopianac9fa422013-02-11 16:40:36 -0800672status_t SurfaceComposerClient::setMatrix(const sp<IBinder>& id, float dsdx, float dtdx,
Mathias Agopian698c0872011-06-28 19:09:31 -0700673 float dsdy, float dtdy) {
674 return getComposer().setMatrix(this, id, dsdx, dtdx, dsdy, dtdy);
675}
676
Dan Stoza7dde5992015-05-22 09:51:44 -0700677status_t SurfaceComposerClient::deferTransactionUntil(const sp<IBinder>& id,
678 const sp<IBinder>& handle, uint64_t frameNumber) {
679 return getComposer().deferTransactionUntil(this, id, handle, frameNumber);
680}
681
Robert Carrc3574f72016-03-24 12:19:32 -0700682status_t SurfaceComposerClient::setOverrideScalingMode(
683 const sp<IBinder>& id, int32_t overrideScalingMode) {
684 return getComposer().setOverrideScalingMode(
685 this, id, overrideScalingMode);
686}
687
Mathias Agopian698c0872011-06-28 19:09:31 -0700688// ----------------------------------------------------------------------------
689
Mathias Agopiane57f2922012-08-09 16:29:12 -0700690void SurfaceComposerClient::setDisplaySurface(const sp<IBinder>& token,
Andy McFadden2adaf042012-12-18 09:49:45 -0800691 const sp<IGraphicBufferProducer>& bufferProducer) {
692 Composer::getInstance().setDisplaySurface(token, bufferProducer);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700693}
694
695void SurfaceComposerClient::setDisplayLayerStack(const sp<IBinder>& token,
696 uint32_t layerStack) {
697 Composer::getInstance().setDisplayLayerStack(token, layerStack);
698}
699
Mathias Agopian00e8c7a2012-09-04 19:30:46 -0700700void SurfaceComposerClient::setDisplayProjection(const sp<IBinder>& token,
701 uint32_t orientation,
702 const Rect& layerStackRect,
703 const Rect& displayRect) {
704 Composer::getInstance().setDisplayProjection(token, orientation,
705 layerStackRect, displayRect);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700706}
707
Michael Wright1f6078a2014-06-26 16:01:02 -0700708void SurfaceComposerClient::setDisplaySize(const sp<IBinder>& token,
709 uint32_t width, uint32_t height) {
710 Composer::getInstance().setDisplaySize(token, width, height);
711}
712
Mathias Agopiane57f2922012-08-09 16:29:12 -0700713// ----------------------------------------------------------------------------
714
Dan Stoza7f7da322014-05-02 15:26:25 -0700715status_t SurfaceComposerClient::getDisplayConfigs(
716 const sp<IBinder>& display, Vector<DisplayInfo>* configs)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800717{
Dan Stoza7f7da322014-05-02 15:26:25 -0700718 return ComposerService::getComposerService()->getDisplayConfigs(display, configs);
719}
720
721status_t SurfaceComposerClient::getDisplayInfo(const sp<IBinder>& display,
722 DisplayInfo* info) {
723 Vector<DisplayInfo> configs;
724 status_t result = getDisplayConfigs(display, &configs);
725 if (result != NO_ERROR) {
726 return result;
727 }
728
729 int activeId = getActiveConfig(display);
730 if (activeId < 0) {
731 ALOGE("No active configuration found");
732 return NAME_NOT_FOUND;
733 }
734
Dan Stozad723bd72014-11-18 10:24:03 -0800735 *info = configs[static_cast<size_t>(activeId)];
Dan Stoza7f7da322014-05-02 15:26:25 -0700736 return NO_ERROR;
737}
738
739int SurfaceComposerClient::getActiveConfig(const sp<IBinder>& display) {
740 return ComposerService::getComposerService()->getActiveConfig(display);
741}
742
743status_t SurfaceComposerClient::setActiveConfig(const sp<IBinder>& display, int id) {
744 return ComposerService::getComposerService()->setActiveConfig(display, id);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800745}
746
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700747void SurfaceComposerClient::setDisplayPowerMode(const sp<IBinder>& token,
748 int mode) {
749 ComposerService::getComposerService()->setPowerMode(token, mode);
Jeff Brown2a09bb32012-10-08 19:13:57 -0700750}
751
Svetoslavd85084b2014-03-20 10:28:31 -0700752status_t SurfaceComposerClient::clearAnimationFrameStats() {
753 return ComposerService::getComposerService()->clearAnimationFrameStats();
754}
755
756status_t SurfaceComposerClient::getAnimationFrameStats(FrameStats* outStats) {
757 return ComposerService::getComposerService()->getAnimationFrameStats(outStats);
758}
759
Dan Stozac4f471e2016-03-24 09:31:08 -0700760status_t SurfaceComposerClient::getHdrCapabilities(const sp<IBinder>& display,
761 HdrCapabilities* outCapabilities) {
762 return ComposerService::getComposerService()->getHdrCapabilities(display,
763 outCapabilities);
764}
765
Mathias Agopian698c0872011-06-28 19:09:31 -0700766// ----------------------------------------------------------------------------
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800767
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800768status_t ScreenshotClient::capture(
769 const sp<IBinder>& display,
770 const sp<IGraphicBufferProducer>& producer,
Dan Stozac1879002014-05-22 15:59:05 -0700771 Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
Dan Stozac7014012014-02-14 15:03:43 -0800772 uint32_t minLayerZ, uint32_t maxLayerZ, bool useIdentityTransform) {
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800773 sp<ISurfaceComposer> s(ComposerService::getComposerService());
774 if (s == NULL) return NO_INIT;
Dan Stozac1879002014-05-22 15:59:05 -0700775 return s->captureScreen(display, producer, sourceCrop,
Dan Stozac7014012014-02-14 15:03:43 -0800776 reqWidth, reqHeight, minLayerZ, maxLayerZ, useIdentityTransform);
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800777}
778
Mathias Agopian74c40c02010-09-29 13:02:36 -0700779ScreenshotClient::ScreenshotClient()
Mathias Agopianabe815d2013-03-19 22:22:21 -0700780 : mHaveBuffer(false) {
781 memset(&mBuffer, 0, sizeof(mBuffer));
Mathias Agopian74c40c02010-09-29 13:02:36 -0700782}
783
Mathias Agopian8000d062013-03-26 18:15:35 -0700784ScreenshotClient::~ScreenshotClient() {
785 ScreenshotClient::release();
786}
787
Mathias Agopianabe815d2013-03-19 22:22:21 -0700788sp<CpuConsumer> ScreenshotClient::getCpuConsumer() const {
789 if (mCpuConsumer == NULL) {
Dan Stoza6d5a7bb2014-03-13 11:39:09 -0700790 sp<IGraphicBufferConsumer> consumer;
791 BufferQueue::createBufferQueue(&mProducer, &consumer);
792 mCpuConsumer = new CpuConsumer(consumer, 1);
Mathias Agopianabe815d2013-03-19 22:22:21 -0700793 mCpuConsumer->setName(String8("ScreenshotClient"));
794 }
795 return mCpuConsumer;
Mathias Agopianbf2c6a62010-12-10 16:22:31 -0800796}
797
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700798status_t ScreenshotClient::update(const sp<IBinder>& display,
Dan Stozac1879002014-05-22 15:59:05 -0700799 Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
Dan Stozac7014012014-02-14 15:03:43 -0800800 uint32_t minLayerZ, uint32_t maxLayerZ,
Riley Andrewsd15ef272014-09-04 16:19:44 -0700801 bool useIdentityTransform, uint32_t rotation) {
Mathias Agopianbf2c6a62010-12-10 16:22:31 -0800802 sp<ISurfaceComposer> s(ComposerService::getComposerService());
803 if (s == NULL) return NO_INIT;
Mathias Agopianabe815d2013-03-19 22:22:21 -0700804 sp<CpuConsumer> cpuConsumer = getCpuConsumer();
805
806 if (mHaveBuffer) {
807 mCpuConsumer->unlockBuffer(mBuffer);
808 memset(&mBuffer, 0, sizeof(mBuffer));
809 mHaveBuffer = false;
810 }
811
Dan Stozac1879002014-05-22 15:59:05 -0700812 status_t err = s->captureScreen(display, mProducer, sourceCrop,
Riley Andrewsd15ef272014-09-04 16:19:44 -0700813 reqWidth, reqHeight, minLayerZ, maxLayerZ, useIdentityTransform,
814 static_cast<ISurfaceComposer::Rotation>(rotation));
Mathias Agopianabe815d2013-03-19 22:22:21 -0700815
816 if (err == NO_ERROR) {
817 err = mCpuConsumer->lockNextBuffer(&mBuffer);
818 if (err == NO_ERROR) {
819 mHaveBuffer = true;
820 }
821 }
822 return err;
823}
824
Riley Andrewsd15ef272014-09-04 16:19:44 -0700825status_t ScreenshotClient::update(const sp<IBinder>& display,
826 Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
827 uint32_t minLayerZ, uint32_t maxLayerZ,
828 bool useIdentityTransform) {
829
830 return ScreenshotClient::update(display, sourceCrop, reqWidth, reqHeight,
831 minLayerZ, maxLayerZ, useIdentityTransform, ISurfaceComposer::eRotateNone);
832}
833
Dan Stozac1879002014-05-22 15:59:05 -0700834status_t ScreenshotClient::update(const sp<IBinder>& display, Rect sourceCrop,
Dan Stozac7014012014-02-14 15:03:43 -0800835 bool useIdentityTransform) {
Dan Stozaf10c46e2014-11-11 10:32:31 -0800836 return ScreenshotClient::update(display, sourceCrop, 0, 0, 0, -1U,
Riley Andrewsd15ef272014-09-04 16:19:44 -0700837 useIdentityTransform, ISurfaceComposer::eRotateNone);
Mathias Agopianabe815d2013-03-19 22:22:21 -0700838}
839
Dan Stozac1879002014-05-22 15:59:05 -0700840status_t ScreenshotClient::update(const sp<IBinder>& display, Rect sourceCrop,
Dan Stozac7014012014-02-14 15:03:43 -0800841 uint32_t reqWidth, uint32_t reqHeight, bool useIdentityTransform) {
Dan Stozac1879002014-05-22 15:59:05 -0700842 return ScreenshotClient::update(display, sourceCrop, reqWidth, reqHeight,
Dan Stozaf10c46e2014-11-11 10:32:31 -0800843 0, -1U, useIdentityTransform, ISurfaceComposer::eRotateNone);
Mathias Agopian74c40c02010-09-29 13:02:36 -0700844}
845
846void ScreenshotClient::release() {
Mathias Agopianabe815d2013-03-19 22:22:21 -0700847 if (mHaveBuffer) {
848 mCpuConsumer->unlockBuffer(mBuffer);
849 memset(&mBuffer, 0, sizeof(mBuffer));
850 mHaveBuffer = false;
851 }
852 mCpuConsumer.clear();
Mathias Agopian74c40c02010-09-29 13:02:36 -0700853}
854
855void const* ScreenshotClient::getPixels() const {
Mathias Agopianabe815d2013-03-19 22:22:21 -0700856 return mBuffer.data;
Mathias Agopian74c40c02010-09-29 13:02:36 -0700857}
858
859uint32_t ScreenshotClient::getWidth() const {
Mathias Agopianabe815d2013-03-19 22:22:21 -0700860 return mBuffer.width;
Mathias Agopian74c40c02010-09-29 13:02:36 -0700861}
862
863uint32_t ScreenshotClient::getHeight() const {
Mathias Agopianabe815d2013-03-19 22:22:21 -0700864 return mBuffer.height;
Mathias Agopian74c40c02010-09-29 13:02:36 -0700865}
866
867PixelFormat ScreenshotClient::getFormat() const {
Mathias Agopianabe815d2013-03-19 22:22:21 -0700868 return mBuffer.format;
Mathias Agopian74c40c02010-09-29 13:02:36 -0700869}
870
871uint32_t ScreenshotClient::getStride() const {
Mathias Agopianabe815d2013-03-19 22:22:21 -0700872 return mBuffer.stride;
Mathias Agopian74c40c02010-09-29 13:02:36 -0700873}
874
875size_t ScreenshotClient::getSize() const {
Mathias Agopianabe815d2013-03-19 22:22:21 -0700876 return mBuffer.stride * mBuffer.height * bytesPerPixel(mBuffer.format);
Mathias Agopian74c40c02010-09-29 13:02:36 -0700877}
878
879// ----------------------------------------------------------------------------
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800880}; // namespace android