blob: 707a321e6fe03b6bbd533f61b8b0be6fe9c4b1b4 [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
Mathias Agopian076b1cc2009-04-10 21:24:3032#include <ui/DisplayInfo.h>
The Android Open Source Projectedbf3b62009-03-04 03:31:4433
Mathias Agopianabe815d2013-03-20 05:22:2134#include <gui/CpuConsumer.h>
Mathias Agopiane3c697f2013-02-15 01:11:0235#include <gui/IGraphicBufferProducer.h>
Mathias Agopian90ac7992012-02-26 02:48:3536#include <gui/ISurfaceComposer.h>
37#include <gui/ISurfaceComposerClient.h>
38#include <gui/SurfaceComposerClient.h>
The Android Open Source Projectedbf3b62009-03-04 03:31:4439
Mathias Agopian41f673c2011-11-18 01:48:3540#include <private/gui/ComposerService.h>
Mathias Agopian90ac7992012-02-26 02:48:3541#include <private/gui/LayerState.h>
The Android Open Source Projectedbf3b62009-03-04 03:31:4442
43namespace android {
The Android Open Source Projectedbf3b62009-03-04 03:31:4444// ---------------------------------------------------------------------------
45
Mathias Agopian7e27f052010-05-28 21:22:2346ANDROID_SINGLETON_STATIC_INSTANCE(ComposerService);
47
Mathias Agopianb7e930d2010-06-01 22:12:5848ComposerService::ComposerService()
49: Singleton<ComposerService>() {
Andy McFadden6652b3e2012-09-07 01:45:5650 Mutex::Autolock _l(mLock);
51 connectLocked();
52}
53
54void ComposerService::connectLocked() {
Mathias Agopianb7e930d2010-06-01 22:12:5855 const String16 name("SurfaceFlinger");
56 while (getService(name, &mComposerService) != NO_ERROR) {
57 usleep(250000);
58 }
Andy McFadden6652b3e2012-09-07 01:45:5659 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 16:01:0174 IInterface::asBinder(mComposerService)->linkToDeath(mDeathObserver);
Mathias Agopianb7e930d2010-06-01 22:12:5875}
76
Andy McFadden6652b3e2012-09-07 01:45:5677/*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 22:12:5893}
94
Mathias Agopian7e27f052010-05-28 21:22:2395// ---------------------------------------------------------------------------
96
Mathias Agopian698c0872011-06-29 02:09:3197static inline
Mathias Agopiane57f2922012-08-09 23:29:1298int compare_type(const ComposerState& lhs, const ComposerState& rhs) {
Mathias Agopian698c0872011-06-29 02:09:3199 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 23:29:12106static inline
107int compare_type(const DisplayState& lhs, const DisplayState& rhs) {
108 return compare_type(lhs.token, rhs.token);
109}
110
Mathias Agopian7e27f052010-05-28 21:22:23111class Composer : public Singleton<Composer>
112{
Mathias Agopiand4784a32010-05-28 02:41:15113 friend class Singleton<Composer>;
114
Mathias Agopian698c0872011-06-29 02:09:31115 mutable Mutex mLock;
Mathias Agopiane57f2922012-08-09 23:29:12116 SortedVector<ComposerState> mComposerStates;
117 SortedVector<DisplayState > mDisplayStates;
Jamie Gennis28378392011-10-13 00:39:00118 uint32_t mForceSynchronous;
Jeff Brownf3f7db62012-08-31 09:18:38119 uint32_t mTransactionNestCount;
Jamie Gennis2d5e2302012-10-16 01:24:43120 bool mAnimation;
Mathias Agopian698c0872011-06-29 02:09:31121
Jamie Gennisb8d69a52011-10-10 22:48:06122 Composer() : Singleton<Composer>(),
Jeff Brownf3f7db62012-08-31 09:18:38123 mForceSynchronous(0), mTransactionNestCount(0),
Jamie Gennis2d5e2302012-10-16 01:24:43124 mAnimation(false)
Jamie Gennis28378392011-10-13 00:39:00125 { }
Mathias Agopian698c0872011-06-29 02:09:31126
Jeff Brownf3f7db62012-08-31 09:18:38127 void openGlobalTransactionImpl();
Jamie Gennis28378392011-10-13 00:39:00128 void closeGlobalTransactionImpl(bool synchronous);
Jamie Gennis2d5e2302012-10-16 01:24:43129 void setAnimationTransactionImpl();
Mathias Agopian698c0872011-06-29 02:09:31130
131 layer_state_t* getLayerStateLocked(
Mathias Agopianac9fa422013-02-12 00:40:36132 const sp<SurfaceComposerClient>& client, const sp<IBinder>& id);
Mathias Agopian698c0872011-06-29 02:09:31133
Mathias Agopiane57f2922012-08-09 23:29:12134 DisplayState& getDisplayStateLocked(const sp<IBinder>& token);
135
Mathias Agopiand4784a32010-05-28 02:41:15136public:
Jamie Gennisdd3cb842012-10-20 01:19:11137 sp<IBinder> createDisplay(const String8& displayName, bool secure);
Jesse Hall6c913be2013-08-08 19:15:49138 void destroyDisplay(const sp<IBinder>& display);
Jeff Brown9d4e3d22012-08-25 03:00:51139 sp<IBinder> getBuiltInDisplay(int32_t id);
Mathias Agopian698c0872011-06-29 02:09:31140
Mathias Agopianac9fa422013-02-12 00:40:36141 status_t setPosition(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
Mathias Agopian41b6aab2011-08-31 01:51:54142 float x, float y);
Mathias Agopianac9fa422013-02-12 00:40:36143 status_t setSize(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
Mathias Agopian698c0872011-06-29 02:09:31144 uint32_t w, uint32_t h);
Mathias Agopianac9fa422013-02-12 00:40:36145 status_t setLayer(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
Dan Stozad723bd72014-11-18 18:24:03146 uint32_t z);
Mathias Agopianac9fa422013-02-12 00:40:36147 status_t setFlags(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
Mathias Agopian698c0872011-06-29 02:09:31148 uint32_t flags, uint32_t mask);
149 status_t setTransparentRegionHint(
Mathias Agopianac9fa422013-02-12 00:40:36150 const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
Mathias Agopian698c0872011-06-29 02:09:31151 const Region& transparentRegion);
Mathias Agopianac9fa422013-02-12 00:40:36152 status_t setAlpha(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
Mathias Agopian698c0872011-06-29 02:09:31153 float alpha);
Mathias Agopianac9fa422013-02-12 00:40:36154 status_t setMatrix(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
Mathias Agopian698c0872011-06-29 02:09:31155 float dsdx, float dtdx, float dsdy, float dtdy);
Jamie Gennisb8d69a52011-10-10 22:48:06156 status_t setOrientation(int orientation);
Mathias Agopianac9fa422013-02-12 00:40:36157 status_t setCrop(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
Jamie Gennisf15a83f2012-05-11 03:43:55158 const Rect& crop);
Mathias Agopian87855782012-07-25 04:41:09159 status_t setLayerStack(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-12 00:40:36160 const sp<IBinder>& id, uint32_t layerStack);
Mathias Agopian698c0872011-06-29 02:09:31161
Andy McFadden2adaf042012-12-18 17:49:45162 void setDisplaySurface(const sp<IBinder>& token,
163 const sp<IGraphicBufferProducer>& bufferProducer);
Mathias Agopiane57f2922012-08-09 23:29:12164 void setDisplayLayerStack(const sp<IBinder>& token, uint32_t layerStack);
Mathias Agopian00e8c7a2012-09-05 02:30:46165 void setDisplayProjection(const sp<IBinder>& token,
166 uint32_t orientation,
167 const Rect& layerStackRect,
168 const Rect& displayRect);
Michael Wright1f6078a2014-06-26 23:01:02169 void setDisplaySize(const sp<IBinder>& token, uint32_t width, uint32_t height);
Mathias Agopiane57f2922012-08-09 23:29:12170
Jamie Gennis2d5e2302012-10-16 01:24:43171 static void setAnimationTransaction() {
172 Composer::getInstance().setAnimationTransactionImpl();
173 }
174
Jeff Brownf3f7db62012-08-31 09:18:38175 static void openGlobalTransaction() {
176 Composer::getInstance().openGlobalTransactionImpl();
177 }
178
Jamie Gennis28378392011-10-13 00:39:00179 static void closeGlobalTransaction(bool synchronous) {
180 Composer::getInstance().closeGlobalTransactionImpl(synchronous);
Mathias Agopiand4784a32010-05-28 02:41:15181 }
182};
183
184ANDROID_SINGLETON_STATIC_INSTANCE(Composer);
185
The Android Open Source Projectedbf3b62009-03-04 03:31:44186// ---------------------------------------------------------------------------
187
Jamie Gennisdd3cb842012-10-20 01:19:11188sp<IBinder> Composer::createDisplay(const String8& displayName, bool secure) {
189 return ComposerService::getComposerService()->createDisplay(displayName,
190 secure);
Mathias Agopiane57f2922012-08-09 23:29:12191}
192
Jesse Hall6c913be2013-08-08 19:15:49193void Composer::destroyDisplay(const sp<IBinder>& display) {
194 return ComposerService::getComposerService()->destroyDisplay(display);
195}
196
Jeff Brown9d4e3d22012-08-25 03:00:51197sp<IBinder> Composer::getBuiltInDisplay(int32_t id) {
198 return ComposerService::getComposerService()->getBuiltInDisplay(id);
199}
200
Jeff Brownf3f7db62012-08-31 09:18:38201void Composer::openGlobalTransactionImpl() {
202 { // scope for the lock
203 Mutex::Autolock _l(mLock);
204 mTransactionNestCount += 1;
205 }
206}
207
Jamie Gennis28378392011-10-13 00:39:00208void Composer::closeGlobalTransactionImpl(bool synchronous) {
Mathias Agopiane57f2922012-08-09 23:29:12209 sp<ISurfaceComposer> sm(ComposerService::getComposerService());
Mathias Agopian698c0872011-06-29 02:09:31210
211 Vector<ComposerState> transaction;
Mathias Agopian8b33f032012-07-25 03:43:54212 Vector<DisplayState> displayTransaction;
Jamie Gennis28378392011-10-13 00:39:00213 uint32_t flags = 0;
Mathias Agopian698c0872011-06-29 02:09:31214
215 { // scope for the lock
216 Mutex::Autolock _l(mLock);
Jeff Brownf3f7db62012-08-31 09:18:38217 mForceSynchronous |= synchronous;
218 if (!mTransactionNestCount) {
219 ALOGW("At least one call to closeGlobalTransaction() was not matched by a prior "
220 "call to openGlobalTransaction().");
221 } else if (--mTransactionNestCount) {
222 return;
223 }
224
Mathias Agopiane57f2922012-08-09 23:29:12225 transaction = mComposerStates;
226 mComposerStates.clear();
Jamie Gennisb8d69a52011-10-10 22:48:06227
Mathias Agopiane57f2922012-08-09 23:29:12228 displayTransaction = mDisplayStates;
229 mDisplayStates.clear();
Jamie Gennis28378392011-10-13 00:39:00230
Jeff Brownf3f7db62012-08-31 09:18:38231 if (mForceSynchronous) {
Jamie Gennis28378392011-10-13 00:39:00232 flags |= ISurfaceComposer::eSynchronous;
233 }
Jamie Gennis2d5e2302012-10-16 01:24:43234 if (mAnimation) {
235 flags |= ISurfaceComposer::eAnimation;
236 }
237
Jamie Gennis28378392011-10-13 00:39:00238 mForceSynchronous = false;
Jamie Gennis2d5e2302012-10-16 01:24:43239 mAnimation = false;
Mathias Agopian698c0872011-06-29 02:09:31240 }
241
Mathias Agopian8b33f032012-07-25 03:43:54242 sm->setTransactionState(transaction, displayTransaction, flags);
The Android Open Source Projectedbf3b62009-03-04 03:31:44243}
244
Jamie Gennis2d5e2302012-10-16 01:24:43245void Composer::setAnimationTransactionImpl() {
246 Mutex::Autolock _l(mLock);
247 mAnimation = true;
248}
249
Mathias Agopian698c0872011-06-29 02:09:31250layer_state_t* Composer::getLayerStateLocked(
Mathias Agopianac9fa422013-02-12 00:40:36251 const sp<SurfaceComposerClient>& client, const sp<IBinder>& id) {
Mathias Agopian698c0872011-06-29 02:09:31252
253 ComposerState s;
254 s.client = client->mClient;
255 s.state.surface = id;
256
Mathias Agopiane57f2922012-08-09 23:29:12257 ssize_t index = mComposerStates.indexOf(s);
Mathias Agopian698c0872011-06-29 02:09:31258 if (index < 0) {
259 // we don't have it, add an initialized layer_state to our list
Mathias Agopiane57f2922012-08-09 23:29:12260 index = mComposerStates.add(s);
Mathias Agopian698c0872011-06-29 02:09:31261 }
262
Mathias Agopiane57f2922012-08-09 23:29:12263 ComposerState* const out = mComposerStates.editArray();
Mathias Agopian698c0872011-06-29 02:09:31264 return &(out[index].state);
265}
266
267status_t Composer::setPosition(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-12 00:40:36268 const sp<IBinder>& id, float x, float y) {
Mathias Agopian698c0872011-06-29 02:09:31269 Mutex::Autolock _l(mLock);
270 layer_state_t* s = getLayerStateLocked(client, id);
271 if (!s)
272 return BAD_INDEX;
Mathias Agopian3165cc22012-08-09 02:42:09273 s->what |= layer_state_t::ePositionChanged;
Mathias Agopian698c0872011-06-29 02:09:31274 s->x = x;
275 s->y = y;
276 return NO_ERROR;
277}
278
279status_t Composer::setSize(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-12 00:40:36280 const sp<IBinder>& id, uint32_t w, uint32_t h) {
Mathias Agopian698c0872011-06-29 02:09:31281 Mutex::Autolock _l(mLock);
282 layer_state_t* s = getLayerStateLocked(client, id);
283 if (!s)
284 return BAD_INDEX;
Mathias Agopian3165cc22012-08-09 02:42:09285 s->what |= layer_state_t::eSizeChanged;
Mathias Agopian698c0872011-06-29 02:09:31286 s->w = w;
287 s->h = h;
Jamie Gennis28378392011-10-13 00:39:00288
289 // Resizing a surface makes the transaction synchronous.
290 mForceSynchronous = true;
291
Mathias Agopian698c0872011-06-29 02:09:31292 return NO_ERROR;
293}
294
295status_t Composer::setLayer(const sp<SurfaceComposerClient>& client,
Dan Stozad723bd72014-11-18 18:24:03296 const sp<IBinder>& id, uint32_t z) {
Mathias Agopian698c0872011-06-29 02:09:31297 Mutex::Autolock _l(mLock);
298 layer_state_t* s = getLayerStateLocked(client, id);
299 if (!s)
300 return BAD_INDEX;
Mathias Agopian3165cc22012-08-09 02:42:09301 s->what |= layer_state_t::eLayerChanged;
Mathias Agopian698c0872011-06-29 02:09:31302 s->z = z;
303 return NO_ERROR;
304}
305
306status_t Composer::setFlags(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-12 00:40:36307 const sp<IBinder>& id, uint32_t flags,
Mathias Agopian698c0872011-06-29 02:09:31308 uint32_t mask) {
309 Mutex::Autolock _l(mLock);
310 layer_state_t* s = getLayerStateLocked(client, id);
311 if (!s)
312 return BAD_INDEX;
Andy McFadden4125a4f2014-01-30 01:17:11313 if (mask & layer_state_t::eLayerOpaque) {
314 s->what |= layer_state_t::eOpacityChanged;
315 }
316 if (mask & layer_state_t::eLayerHidden) {
317 s->what |= layer_state_t::eVisibilityChanged;
318 }
Mathias Agopian698c0872011-06-29 02:09:31319 s->flags &= ~mask;
320 s->flags |= (flags & mask);
321 s->mask |= mask;
322 return NO_ERROR;
323}
324
325status_t Composer::setTransparentRegionHint(
Mathias Agopianac9fa422013-02-12 00:40:36326 const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
Mathias Agopian698c0872011-06-29 02:09:31327 const Region& transparentRegion) {
328 Mutex::Autolock _l(mLock);
329 layer_state_t* s = getLayerStateLocked(client, id);
330 if (!s)
331 return BAD_INDEX;
Mathias Agopian3165cc22012-08-09 02:42:09332 s->what |= layer_state_t::eTransparentRegionChanged;
Mathias Agopian698c0872011-06-29 02:09:31333 s->transparentRegion = transparentRegion;
334 return NO_ERROR;
335}
336
337status_t Composer::setAlpha(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-12 00:40:36338 const sp<IBinder>& id, float alpha) {
Mathias Agopian698c0872011-06-29 02:09:31339 Mutex::Autolock _l(mLock);
340 layer_state_t* s = getLayerStateLocked(client, id);
341 if (!s)
342 return BAD_INDEX;
Mathias Agopian3165cc22012-08-09 02:42:09343 s->what |= layer_state_t::eAlphaChanged;
Mathias Agopian698c0872011-06-29 02:09:31344 s->alpha = alpha;
345 return NO_ERROR;
346}
347
Mathias Agopian87855782012-07-25 04:41:09348status_t Composer::setLayerStack(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-12 00:40:36349 const sp<IBinder>& id, uint32_t layerStack) {
Mathias Agopian87855782012-07-25 04:41:09350 Mutex::Autolock _l(mLock);
351 layer_state_t* s = getLayerStateLocked(client, id);
352 if (!s)
353 return BAD_INDEX;
Mathias Agopian3165cc22012-08-09 02:42:09354 s->what |= layer_state_t::eLayerStackChanged;
Mathias Agopian87855782012-07-25 04:41:09355 s->layerStack = layerStack;
356 return NO_ERROR;
357}
358
Mathias Agopian698c0872011-06-29 02:09:31359status_t Composer::setMatrix(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-12 00:40:36360 const sp<IBinder>& id, float dsdx, float dtdx,
Mathias Agopian698c0872011-06-29 02:09:31361 float dsdy, float dtdy) {
362 Mutex::Autolock _l(mLock);
363 layer_state_t* s = getLayerStateLocked(client, id);
364 if (!s)
365 return BAD_INDEX;
Mathias Agopian3165cc22012-08-09 02:42:09366 s->what |= layer_state_t::eMatrixChanged;
Mathias Agopian698c0872011-06-29 02:09:31367 layer_state_t::matrix22_t matrix;
368 matrix.dsdx = dsdx;
369 matrix.dtdx = dtdx;
370 matrix.dsdy = dsdy;
371 matrix.dtdy = dtdy;
372 s->matrix = matrix;
373 return NO_ERROR;
374}
375
Jamie Gennisf15a83f2012-05-11 03:43:55376status_t Composer::setCrop(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-12 00:40:36377 const sp<IBinder>& id, const Rect& crop) {
Jamie Gennisf15a83f2012-05-11 03:43:55378 Mutex::Autolock _l(mLock);
379 layer_state_t* s = getLayerStateLocked(client, id);
380 if (!s)
381 return BAD_INDEX;
Mathias Agopian3165cc22012-08-09 02:42:09382 s->what |= layer_state_t::eCropChanged;
Jamie Gennisf15a83f2012-05-11 03:43:55383 s->crop = crop;
384 return NO_ERROR;
385}
386
Mathias Agopian698c0872011-06-29 02:09:31387// ---------------------------------------------------------------------------
388
Mathias Agopiane57f2922012-08-09 23:29:12389DisplayState& Composer::getDisplayStateLocked(const sp<IBinder>& token) {
390 DisplayState s;
391 s.token = token;
392 ssize_t index = mDisplayStates.indexOf(s);
393 if (index < 0) {
394 // we don't have it, add an initialized layer_state to our list
395 s.what = 0;
396 index = mDisplayStates.add(s);
397 }
Dan Stozad723bd72014-11-18 18:24:03398 return mDisplayStates.editItemAt(static_cast<size_t>(index));
Mathias Agopiane57f2922012-08-09 23:29:12399}
400
401void Composer::setDisplaySurface(const sp<IBinder>& token,
Andy McFadden2adaf042012-12-18 17:49:45402 const sp<IGraphicBufferProducer>& bufferProducer) {
Mathias Agopiane57f2922012-08-09 23:29:12403 Mutex::Autolock _l(mLock);
404 DisplayState& s(getDisplayStateLocked(token));
Andy McFadden2adaf042012-12-18 17:49:45405 s.surface = bufferProducer;
Mathias Agopiane57f2922012-08-09 23:29:12406 s.what |= DisplayState::eSurfaceChanged;
407}
408
409void Composer::setDisplayLayerStack(const sp<IBinder>& token,
410 uint32_t layerStack) {
411 Mutex::Autolock _l(mLock);
412 DisplayState& s(getDisplayStateLocked(token));
413 s.layerStack = layerStack;
414 s.what |= DisplayState::eLayerStackChanged;
415}
416
Mathias Agopian00e8c7a2012-09-05 02:30:46417void Composer::setDisplayProjection(const sp<IBinder>& token,
418 uint32_t orientation,
419 const Rect& layerStackRect,
420 const Rect& displayRect) {
Mathias Agopiane57f2922012-08-09 23:29:12421 Mutex::Autolock _l(mLock);
422 DisplayState& s(getDisplayStateLocked(token));
423 s.orientation = orientation;
Mathias Agopian00e8c7a2012-09-05 02:30:46424 s.viewport = layerStackRect;
425 s.frame = displayRect;
426 s.what |= DisplayState::eDisplayProjectionChanged;
Mathias Agopiane57f2922012-08-09 23:29:12427 mForceSynchronous = true; // TODO: do we actually still need this?
428}
429
Michael Wright1f6078a2014-06-26 23:01:02430void Composer::setDisplaySize(const sp<IBinder>& token, uint32_t width, uint32_t height) {
431 Mutex::Autolock _l(mLock);
432 DisplayState& s(getDisplayStateLocked(token));
433 s.width = width;
434 s.height = height;
435 s.what |= DisplayState::eDisplaySizeChanged;
436}
437
Mathias Agopiane57f2922012-08-09 23:29:12438// ---------------------------------------------------------------------------
439
The Android Open Source Projectedbf3b62009-03-04 03:31:44440SurfaceComposerClient::SurfaceComposerClient()
Mathias Agopian698c0872011-06-29 02:09:31441 : mStatus(NO_INIT), mComposer(Composer::getInstance())
The Android Open Source Projectedbf3b62009-03-04 03:31:44442{
The Android Open Source Projectedbf3b62009-03-04 03:31:44443}
444
Mathias Agopian698c0872011-06-29 02:09:31445void SurfaceComposerClient::onFirstRef() {
Mathias Agopiane57f2922012-08-09 23:29:12446 sp<ISurfaceComposer> sm(ComposerService::getComposerService());
Mathias Agopiand4784a32010-05-28 02:41:15447 if (sm != 0) {
Mathias Agopian7e27f052010-05-28 21:22:23448 sp<ISurfaceComposerClient> conn = sm->createConnection();
Mathias Agopiand4784a32010-05-28 02:41:15449 if (conn != 0) {
450 mClient = conn;
Mathias Agopiand4784a32010-05-28 02:41:15451 mStatus = NO_ERROR;
452 }
453 }
The Android Open Source Projectedbf3b62009-03-04 03:31:44454}
455
Mathias Agopian698c0872011-06-29 02:09:31456SurfaceComposerClient::~SurfaceComposerClient() {
Mathias Agopian631f3582010-05-26 00:51:34457 dispose();
458}
Mathias Agopiandd3423c2009-09-23 22:44:05459
Mathias Agopian698c0872011-06-29 02:09:31460status_t SurfaceComposerClient::initCheck() const {
The Android Open Source Projectedbf3b62009-03-04 03:31:44461 return mStatus;
462}
463
Mathias Agopian698c0872011-06-29 02:09:31464sp<IBinder> SurfaceComposerClient::connection() const {
Marco Nelissen2ea926b2014-11-14 16:01:01465 return IInterface::asBinder(mClient);
The Android Open Source Projectedbf3b62009-03-04 03:31:44466}
467
Mathias Agopiand4784a32010-05-28 02:41:15468status_t SurfaceComposerClient::linkToComposerDeath(
469 const sp<IBinder::DeathRecipient>& recipient,
Mathias Agopian698c0872011-06-29 02:09:31470 void* cookie, uint32_t flags) {
Mathias Agopiane57f2922012-08-09 23:29:12471 sp<ISurfaceComposer> sm(ComposerService::getComposerService());
Marco Nelissen2ea926b2014-11-14 16:01:01472 return IInterface::asBinder(sm)->linkToDeath(recipient, cookie, flags);
The Android Open Source Projectedbf3b62009-03-04 03:31:44473}
474
Mathias Agopian698c0872011-06-29 02:09:31475void SurfaceComposerClient::dispose() {
The Android Open Source Projectedbf3b62009-03-04 03:31:44476 // this can be called more than once.
Mathias Agopian7e27f052010-05-28 21:22:23477 sp<ISurfaceComposerClient> client;
Mathias Agopiand4784a32010-05-28 02:41:15478 Mutex::Autolock _lm(mLock);
479 if (mClient != 0) {
Mathias Agopiand4784a32010-05-28 02:41:15480 client = mClient; // hold ref while lock is held
481 mClient.clear();
The Android Open Source Projectedbf3b62009-03-04 03:31:44482 }
Mathias Agopiand4784a32010-05-28 02:41:15483 mStatus = NO_INIT;
The Android Open Source Projectedbf3b62009-03-04 03:31:44484}
485
Mathias Agopian698c0872011-06-29 02:09:31486sp<SurfaceControl> SurfaceComposerClient::createSurface(
Mathias Agopian698c0872011-06-29 02:09:31487 const String8& name,
Mathias Agopian698c0872011-06-29 02:09:31488 uint32_t w,
489 uint32_t h,
490 PixelFormat format,
491 uint32_t flags)
492{
Mathias Agopian4d9b8222013-03-13 00:11:48493 sp<SurfaceControl> sur;
Mathias Agopian698c0872011-06-29 02:09:31494 if (mStatus == NO_ERROR) {
Mathias Agopian4d9b8222013-03-13 00:11:48495 sp<IBinder> handle;
496 sp<IGraphicBufferProducer> gbp;
497 status_t err = mClient->createSurface(name, w, h, format, flags,
498 &handle, &gbp);
499 ALOGE_IF(err, "SurfaceComposerClient::createSurface error %s", strerror(-err));
500 if (err == NO_ERROR) {
501 sur = new SurfaceControl(this, handle, gbp);
Mathias Agopian698c0872011-06-29 02:09:31502 }
503 }
Mathias Agopian4d9b8222013-03-13 00:11:48504 return sur;
Mathias Agopian698c0872011-06-29 02:09:31505}
506
Jamie Gennisdd3cb842012-10-20 01:19:11507sp<IBinder> SurfaceComposerClient::createDisplay(const String8& displayName,
508 bool secure) {
509 return Composer::getInstance().createDisplay(displayName, secure);
Mathias Agopiane57f2922012-08-09 23:29:12510}
511
Jesse Hall6c913be2013-08-08 19:15:49512void SurfaceComposerClient::destroyDisplay(const sp<IBinder>& display) {
513 Composer::getInstance().destroyDisplay(display);
514}
515
Jeff Brown9d4e3d22012-08-25 03:00:51516sp<IBinder> SurfaceComposerClient::getBuiltInDisplay(int32_t id) {
517 return Composer::getInstance().getBuiltInDisplay(id);
518}
519
Mathias Agopianac9fa422013-02-12 00:40:36520status_t SurfaceComposerClient::destroySurface(const sp<IBinder>& sid) {
Mathias Agopian698c0872011-06-29 02:09:31521 if (mStatus != NO_ERROR)
522 return mStatus;
523 status_t err = mClient->destroySurface(sid);
524 return err;
525}
526
Svetoslavd85084b2014-03-20 17:28:31527status_t SurfaceComposerClient::clearLayerFrameStats(const sp<IBinder>& token) const {
528 if (mStatus != NO_ERROR) {
529 return mStatus;
530 }
531 return mClient->clearLayerFrameStats(token);
532}
533
534status_t SurfaceComposerClient::getLayerFrameStats(const sp<IBinder>& token,
535 FrameStats* outStats) const {
536 if (mStatus != NO_ERROR) {
537 return mStatus;
538 }
539 return mClient->getLayerFrameStats(token, outStats);
540}
541
Mathias Agopian698c0872011-06-29 02:09:31542inline Composer& SurfaceComposerClient::getComposer() {
543 return mComposer;
544}
545
546// ----------------------------------------------------------------------------
547
548void SurfaceComposerClient::openGlobalTransaction() {
Jeff Brownf3f7db62012-08-31 09:18:38549 Composer::openGlobalTransaction();
Mathias Agopian698c0872011-06-29 02:09:31550}
551
Jamie Gennis28378392011-10-13 00:39:00552void SurfaceComposerClient::closeGlobalTransaction(bool synchronous) {
553 Composer::closeGlobalTransaction(synchronous);
Mathias Agopian698c0872011-06-29 02:09:31554}
555
Jamie Gennis2d5e2302012-10-16 01:24:43556void SurfaceComposerClient::setAnimationTransaction() {
557 Composer::setAnimationTransaction();
558}
559
Mathias Agopian698c0872011-06-29 02:09:31560// ----------------------------------------------------------------------------
561
Mathias Agopianac9fa422013-02-12 00:40:36562status_t SurfaceComposerClient::setCrop(const sp<IBinder>& id, const Rect& crop) {
Jamie Gennisf15a83f2012-05-11 03:43:55563 return getComposer().setCrop(this, id, crop);
564}
565
Mathias Agopianac9fa422013-02-12 00:40:36566status_t SurfaceComposerClient::setPosition(const sp<IBinder>& id, float x, float y) {
Mathias Agopian698c0872011-06-29 02:09:31567 return getComposer().setPosition(this, id, x, y);
568}
569
Mathias Agopianac9fa422013-02-12 00:40:36570status_t SurfaceComposerClient::setSize(const sp<IBinder>& id, uint32_t w, uint32_t h) {
Mathias Agopian698c0872011-06-29 02:09:31571 return getComposer().setSize(this, id, w, h);
572}
573
Dan Stozad723bd72014-11-18 18:24:03574status_t SurfaceComposerClient::setLayer(const sp<IBinder>& id, uint32_t z) {
Mathias Agopian698c0872011-06-29 02:09:31575 return getComposer().setLayer(this, id, z);
576}
577
Mathias Agopianac9fa422013-02-12 00:40:36578status_t SurfaceComposerClient::hide(const sp<IBinder>& id) {
Mathias Agopian698c0872011-06-29 02:09:31579 return getComposer().setFlags(this, id,
Mathias Agopian3165cc22012-08-09 02:42:09580 layer_state_t::eLayerHidden,
581 layer_state_t::eLayerHidden);
Mathias Agopian698c0872011-06-29 02:09:31582}
583
Mathias Agopianac9fa422013-02-12 00:40:36584status_t SurfaceComposerClient::show(const sp<IBinder>& id) {
Mathias Agopian698c0872011-06-29 02:09:31585 return getComposer().setFlags(this, id,
586 0,
Mathias Agopian3165cc22012-08-09 02:42:09587 layer_state_t::eLayerHidden);
Mathias Agopian698c0872011-06-29 02:09:31588}
589
Mathias Agopianac9fa422013-02-12 00:40:36590status_t SurfaceComposerClient::setFlags(const sp<IBinder>& id, uint32_t flags,
Mathias Agopian698c0872011-06-29 02:09:31591 uint32_t mask) {
592 return getComposer().setFlags(this, id, flags, mask);
593}
594
Mathias Agopianac9fa422013-02-12 00:40:36595status_t SurfaceComposerClient::setTransparentRegionHint(const sp<IBinder>& id,
Mathias Agopian698c0872011-06-29 02:09:31596 const Region& transparentRegion) {
597 return getComposer().setTransparentRegionHint(this, id, transparentRegion);
598}
599
Mathias Agopianac9fa422013-02-12 00:40:36600status_t SurfaceComposerClient::setAlpha(const sp<IBinder>& id, float alpha) {
Mathias Agopian698c0872011-06-29 02:09:31601 return getComposer().setAlpha(this, id, alpha);
602}
603
Mathias Agopianac9fa422013-02-12 00:40:36604status_t SurfaceComposerClient::setLayerStack(const sp<IBinder>& id, uint32_t layerStack) {
Mathias Agopian87855782012-07-25 04:41:09605 return getComposer().setLayerStack(this, id, layerStack);
606}
607
Mathias Agopianac9fa422013-02-12 00:40:36608status_t SurfaceComposerClient::setMatrix(const sp<IBinder>& id, float dsdx, float dtdx,
Mathias Agopian698c0872011-06-29 02:09:31609 float dsdy, float dtdy) {
610 return getComposer().setMatrix(this, id, dsdx, dtdx, dsdy, dtdy);
611}
612
613// ----------------------------------------------------------------------------
614
Mathias Agopiane57f2922012-08-09 23:29:12615void SurfaceComposerClient::setDisplaySurface(const sp<IBinder>& token,
Andy McFadden2adaf042012-12-18 17:49:45616 const sp<IGraphicBufferProducer>& bufferProducer) {
617 Composer::getInstance().setDisplaySurface(token, bufferProducer);
Mathias Agopiane57f2922012-08-09 23:29:12618}
619
620void SurfaceComposerClient::setDisplayLayerStack(const sp<IBinder>& token,
621 uint32_t layerStack) {
622 Composer::getInstance().setDisplayLayerStack(token, layerStack);
623}
624
Mathias Agopian00e8c7a2012-09-05 02:30:46625void SurfaceComposerClient::setDisplayProjection(const sp<IBinder>& token,
626 uint32_t orientation,
627 const Rect& layerStackRect,
628 const Rect& displayRect) {
629 Composer::getInstance().setDisplayProjection(token, orientation,
630 layerStackRect, displayRect);
Mathias Agopiane57f2922012-08-09 23:29:12631}
632
Michael Wright1f6078a2014-06-26 23:01:02633void SurfaceComposerClient::setDisplaySize(const sp<IBinder>& token,
634 uint32_t width, uint32_t height) {
635 Composer::getInstance().setDisplaySize(token, width, height);
636}
637
Mathias Agopiane57f2922012-08-09 23:29:12638// ----------------------------------------------------------------------------
639
Dan Stoza7f7da322014-05-02 22:26:25640status_t SurfaceComposerClient::getDisplayConfigs(
641 const sp<IBinder>& display, Vector<DisplayInfo>* configs)
The Android Open Source Projectedbf3b62009-03-04 03:31:44642{
Dan Stoza7f7da322014-05-02 22:26:25643 return ComposerService::getComposerService()->getDisplayConfigs(display, configs);
644}
645
646status_t SurfaceComposerClient::getDisplayInfo(const sp<IBinder>& display,
647 DisplayInfo* info) {
648 Vector<DisplayInfo> configs;
649 status_t result = getDisplayConfigs(display, &configs);
650 if (result != NO_ERROR) {
651 return result;
652 }
653
654 int activeId = getActiveConfig(display);
655 if (activeId < 0) {
656 ALOGE("No active configuration found");
657 return NAME_NOT_FOUND;
658 }
659
Dan Stozad723bd72014-11-18 18:24:03660 *info = configs[static_cast<size_t>(activeId)];
Dan Stoza7f7da322014-05-02 22:26:25661 return NO_ERROR;
662}
663
664int SurfaceComposerClient::getActiveConfig(const sp<IBinder>& display) {
665 return ComposerService::getComposerService()->getActiveConfig(display);
666}
667
668status_t SurfaceComposerClient::setActiveConfig(const sp<IBinder>& display, int id) {
669 return ComposerService::getComposerService()->setActiveConfig(display, id);
The Android Open Source Projectedbf3b62009-03-04 03:31:44670}
671
Prashant Malani2c9b11f2014-05-25 08:36:31672void SurfaceComposerClient::setDisplayPowerMode(const sp<IBinder>& token,
673 int mode) {
674 ComposerService::getComposerService()->setPowerMode(token, mode);
Jeff Brown2a09bb32012-10-09 02:13:57675}
676
Svetoslavd85084b2014-03-20 17:28:31677status_t SurfaceComposerClient::clearAnimationFrameStats() {
678 return ComposerService::getComposerService()->clearAnimationFrameStats();
679}
680
681status_t SurfaceComposerClient::getAnimationFrameStats(FrameStats* outStats) {
682 return ComposerService::getComposerService()->getAnimationFrameStats(outStats);
683}
684
Mathias Agopian698c0872011-06-29 02:09:31685// ----------------------------------------------------------------------------
The Android Open Source Projectedbf3b62009-03-04 03:31:44686
Mathias Agopian2a9fc492013-03-01 21:42:57687status_t ScreenshotClient::capture(
688 const sp<IBinder>& display,
689 const sp<IGraphicBufferProducer>& producer,
Dan Stozac1879002014-05-22 22:59:05690 Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
Dan Stozac7014012014-02-14 23:03:43691 uint32_t minLayerZ, uint32_t maxLayerZ, bool useIdentityTransform) {
Mathias Agopian2a9fc492013-03-01 21:42:57692 sp<ISurfaceComposer> s(ComposerService::getComposerService());
693 if (s == NULL) return NO_INIT;
Dan Stozac1879002014-05-22 22:59:05694 return s->captureScreen(display, producer, sourceCrop,
Dan Stozac7014012014-02-14 23:03:43695 reqWidth, reqHeight, minLayerZ, maxLayerZ, useIdentityTransform);
Mathias Agopian2a9fc492013-03-01 21:42:57696}
697
Mathias Agopian74c40c02010-09-29 20:02:36698ScreenshotClient::ScreenshotClient()
Mathias Agopianabe815d2013-03-20 05:22:21699 : mHaveBuffer(false) {
700 memset(&mBuffer, 0, sizeof(mBuffer));
Mathias Agopian74c40c02010-09-29 20:02:36701}
702
Mathias Agopian8000d062013-03-27 01:15:35703ScreenshotClient::~ScreenshotClient() {
704 ScreenshotClient::release();
705}
706
Mathias Agopianabe815d2013-03-20 05:22:21707sp<CpuConsumer> ScreenshotClient::getCpuConsumer() const {
708 if (mCpuConsumer == NULL) {
Dan Stoza6d5a7bb2014-03-13 18:39:09709 sp<IGraphicBufferConsumer> consumer;
710 BufferQueue::createBufferQueue(&mProducer, &consumer);
711 mCpuConsumer = new CpuConsumer(consumer, 1);
Mathias Agopianabe815d2013-03-20 05:22:21712 mCpuConsumer->setName(String8("ScreenshotClient"));
713 }
714 return mCpuConsumer;
Mathias Agopianbf2c6a62010-12-11 00:22:31715}
716
Jeff Brown9d4e3d22012-08-25 03:00:51717status_t ScreenshotClient::update(const sp<IBinder>& display,
Dan Stozac1879002014-05-22 22:59:05718 Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
Dan Stozac7014012014-02-14 23:03:43719 uint32_t minLayerZ, uint32_t maxLayerZ,
Riley Andrewsd15ef272014-09-04 23:19:44720 bool useIdentityTransform, uint32_t rotation) {
Mathias Agopianbf2c6a62010-12-11 00:22:31721 sp<ISurfaceComposer> s(ComposerService::getComposerService());
722 if (s == NULL) return NO_INIT;
Mathias Agopianabe815d2013-03-20 05:22:21723 sp<CpuConsumer> cpuConsumer = getCpuConsumer();
724
725 if (mHaveBuffer) {
726 mCpuConsumer->unlockBuffer(mBuffer);
727 memset(&mBuffer, 0, sizeof(mBuffer));
728 mHaveBuffer = false;
729 }
730
Dan Stozac1879002014-05-22 22:59:05731 status_t err = s->captureScreen(display, mProducer, sourceCrop,
Riley Andrewsd15ef272014-09-04 23:19:44732 reqWidth, reqHeight, minLayerZ, maxLayerZ, useIdentityTransform,
733 static_cast<ISurfaceComposer::Rotation>(rotation));
Mathias Agopianabe815d2013-03-20 05:22:21734
735 if (err == NO_ERROR) {
736 err = mCpuConsumer->lockNextBuffer(&mBuffer);
737 if (err == NO_ERROR) {
738 mHaveBuffer = true;
739 }
740 }
741 return err;
742}
743
Riley Andrewsd15ef272014-09-04 23:19:44744status_t ScreenshotClient::update(const sp<IBinder>& display,
745 Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
746 uint32_t minLayerZ, uint32_t maxLayerZ,
747 bool useIdentityTransform) {
748
749 return ScreenshotClient::update(display, sourceCrop, reqWidth, reqHeight,
750 minLayerZ, maxLayerZ, useIdentityTransform, ISurfaceComposer::eRotateNone);
751}
752
Dan Stozac1879002014-05-22 22:59:05753status_t ScreenshotClient::update(const sp<IBinder>& display, Rect sourceCrop,
Dan Stozac7014012014-02-14 23:03:43754 bool useIdentityTransform) {
Dan Stozaf10c46e2014-11-11 18:32:31755 return ScreenshotClient::update(display, sourceCrop, 0, 0, 0, -1U,
Riley Andrewsd15ef272014-09-04 23:19:44756 useIdentityTransform, ISurfaceComposer::eRotateNone);
Mathias Agopianabe815d2013-03-20 05:22:21757}
758
Dan Stozac1879002014-05-22 22:59:05759status_t ScreenshotClient::update(const sp<IBinder>& display, Rect sourceCrop,
Dan Stozac7014012014-02-14 23:03:43760 uint32_t reqWidth, uint32_t reqHeight, bool useIdentityTransform) {
Dan Stozac1879002014-05-22 22:59:05761 return ScreenshotClient::update(display, sourceCrop, reqWidth, reqHeight,
Dan Stozaf10c46e2014-11-11 18:32:31762 0, -1U, useIdentityTransform, ISurfaceComposer::eRotateNone);
Mathias Agopian74c40c02010-09-29 20:02:36763}
764
765void ScreenshotClient::release() {
Mathias Agopianabe815d2013-03-20 05:22:21766 if (mHaveBuffer) {
767 mCpuConsumer->unlockBuffer(mBuffer);
768 memset(&mBuffer, 0, sizeof(mBuffer));
769 mHaveBuffer = false;
770 }
771 mCpuConsumer.clear();
Mathias Agopian74c40c02010-09-29 20:02:36772}
773
774void const* ScreenshotClient::getPixels() const {
Mathias Agopianabe815d2013-03-20 05:22:21775 return mBuffer.data;
Mathias Agopian74c40c02010-09-29 20:02:36776}
777
778uint32_t ScreenshotClient::getWidth() const {
Mathias Agopianabe815d2013-03-20 05:22:21779 return mBuffer.width;
Mathias Agopian74c40c02010-09-29 20:02:36780}
781
782uint32_t ScreenshotClient::getHeight() const {
Mathias Agopianabe815d2013-03-20 05:22:21783 return mBuffer.height;
Mathias Agopian74c40c02010-09-29 20:02:36784}
785
786PixelFormat ScreenshotClient::getFormat() const {
Mathias Agopianabe815d2013-03-20 05:22:21787 return mBuffer.format;
Mathias Agopian74c40c02010-09-29 20:02:36788}
789
790uint32_t ScreenshotClient::getStride() const {
Mathias Agopianabe815d2013-03-20 05:22:21791 return mBuffer.stride;
Mathias Agopian74c40c02010-09-29 20:02:36792}
793
794size_t ScreenshotClient::getSize() const {
Mathias Agopianabe815d2013-03-20 05:22:21795 return mBuffer.stride * mBuffer.height * bytesPerPixel(mBuffer.format);
Mathias Agopian74c40c02010-09-29 20:02:36796}
797
798// ----------------------------------------------------------------------------
The Android Open Source Projectedbf3b62009-03-04 03:31:44799}; // namespace android