blob: e8e208f12b5ebff4785eabe6eb7d25745f972678 [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 Agopiane3c697f2013-02-15 01:11:0234#include <gui/IGraphicBufferProducer.h>
Mathias Agopian90ac7992012-02-26 02:48:3535#include <gui/ISurface.h>
36#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));
74 mComposerService->asBinder()->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);
Jeff Brown9d4e3d22012-08-25 03:00:51138 sp<IBinder> getBuiltInDisplay(int32_t id);
Mathias Agopian698c0872011-06-29 02:09:31139
Mathias Agopianac9fa422013-02-12 00:40:36140 status_t setPosition(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
Mathias Agopian41b6aab2011-08-31 01:51:54141 float x, float y);
Mathias Agopianac9fa422013-02-12 00:40:36142 status_t setSize(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
Mathias Agopian698c0872011-06-29 02:09:31143 uint32_t w, uint32_t h);
Mathias Agopianac9fa422013-02-12 00:40:36144 status_t setLayer(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
Mathias Agopian698c0872011-06-29 02:09:31145 int32_t z);
Mathias Agopianac9fa422013-02-12 00:40:36146 status_t setFlags(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
Mathias Agopian698c0872011-06-29 02:09:31147 uint32_t flags, uint32_t mask);
148 status_t setTransparentRegionHint(
Mathias Agopianac9fa422013-02-12 00:40:36149 const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
Mathias Agopian698c0872011-06-29 02:09:31150 const Region& transparentRegion);
Mathias Agopianac9fa422013-02-12 00:40:36151 status_t setAlpha(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
Mathias Agopian698c0872011-06-29 02:09:31152 float alpha);
Mathias Agopianac9fa422013-02-12 00:40:36153 status_t setMatrix(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
Mathias Agopian698c0872011-06-29 02:09:31154 float dsdx, float dtdx, float dsdy, float dtdy);
Jamie Gennisb8d69a52011-10-10 22:48:06155 status_t setOrientation(int orientation);
Mathias Agopianac9fa422013-02-12 00:40:36156 status_t setCrop(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
Jamie Gennisf15a83f2012-05-11 03:43:55157 const Rect& crop);
Mathias Agopian87855782012-07-25 04:41:09158 status_t setLayerStack(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-12 00:40:36159 const sp<IBinder>& id, uint32_t layerStack);
Mathias Agopian698c0872011-06-29 02:09:31160
Andy McFadden2adaf042012-12-18 17:49:45161 void setDisplaySurface(const sp<IBinder>& token,
162 const sp<IGraphicBufferProducer>& bufferProducer);
Mathias Agopiane57f2922012-08-09 23:29:12163 void setDisplayLayerStack(const sp<IBinder>& token, uint32_t layerStack);
Mathias Agopian00e8c7a2012-09-05 02:30:46164 void setDisplayProjection(const sp<IBinder>& token,
165 uint32_t orientation,
166 const Rect& layerStackRect,
167 const Rect& displayRect);
Mathias Agopiane57f2922012-08-09 23:29:12168
Jamie Gennis2d5e2302012-10-16 01:24:43169 static void setAnimationTransaction() {
170 Composer::getInstance().setAnimationTransactionImpl();
171 }
172
Jeff Brownf3f7db62012-08-31 09:18:38173 static void openGlobalTransaction() {
174 Composer::getInstance().openGlobalTransactionImpl();
175 }
176
Jamie Gennis28378392011-10-13 00:39:00177 static void closeGlobalTransaction(bool synchronous) {
178 Composer::getInstance().closeGlobalTransactionImpl(synchronous);
Mathias Agopiand4784a32010-05-28 02:41:15179 }
180};
181
182ANDROID_SINGLETON_STATIC_INSTANCE(Composer);
183
The Android Open Source Projectedbf3b62009-03-04 03:31:44184// ---------------------------------------------------------------------------
185
Jamie Gennisdd3cb842012-10-20 01:19:11186sp<IBinder> Composer::createDisplay(const String8& displayName, bool secure) {
187 return ComposerService::getComposerService()->createDisplay(displayName,
188 secure);
Mathias Agopiane57f2922012-08-09 23:29:12189}
190
Jeff Brown9d4e3d22012-08-25 03:00:51191sp<IBinder> Composer::getBuiltInDisplay(int32_t id) {
192 return ComposerService::getComposerService()->getBuiltInDisplay(id);
193}
194
Jeff Brownf3f7db62012-08-31 09:18:38195void Composer::openGlobalTransactionImpl() {
196 { // scope for the lock
197 Mutex::Autolock _l(mLock);
198 mTransactionNestCount += 1;
199 }
200}
201
Jamie Gennis28378392011-10-13 00:39:00202void Composer::closeGlobalTransactionImpl(bool synchronous) {
Mathias Agopiane57f2922012-08-09 23:29:12203 sp<ISurfaceComposer> sm(ComposerService::getComposerService());
Mathias Agopian698c0872011-06-29 02:09:31204
205 Vector<ComposerState> transaction;
Mathias Agopian8b33f032012-07-25 03:43:54206 Vector<DisplayState> displayTransaction;
Jamie Gennis28378392011-10-13 00:39:00207 uint32_t flags = 0;
Mathias Agopian698c0872011-06-29 02:09:31208
209 { // scope for the lock
210 Mutex::Autolock _l(mLock);
Jeff Brownf3f7db62012-08-31 09:18:38211 mForceSynchronous |= synchronous;
212 if (!mTransactionNestCount) {
213 ALOGW("At least one call to closeGlobalTransaction() was not matched by a prior "
214 "call to openGlobalTransaction().");
215 } else if (--mTransactionNestCount) {
216 return;
217 }
218
Mathias Agopiane57f2922012-08-09 23:29:12219 transaction = mComposerStates;
220 mComposerStates.clear();
Jamie Gennisb8d69a52011-10-10 22:48:06221
Mathias Agopiane57f2922012-08-09 23:29:12222 displayTransaction = mDisplayStates;
223 mDisplayStates.clear();
Jamie Gennis28378392011-10-13 00:39:00224
Jeff Brownf3f7db62012-08-31 09:18:38225 if (mForceSynchronous) {
Jamie Gennis28378392011-10-13 00:39:00226 flags |= ISurfaceComposer::eSynchronous;
227 }
Jamie Gennis2d5e2302012-10-16 01:24:43228 if (mAnimation) {
229 flags |= ISurfaceComposer::eAnimation;
230 }
231
Jamie Gennis28378392011-10-13 00:39:00232 mForceSynchronous = false;
Jamie Gennis2d5e2302012-10-16 01:24:43233 mAnimation = false;
Mathias Agopian698c0872011-06-29 02:09:31234 }
235
Mathias Agopian8b33f032012-07-25 03:43:54236 sm->setTransactionState(transaction, displayTransaction, flags);
The Android Open Source Projectedbf3b62009-03-04 03:31:44237}
238
Jamie Gennis2d5e2302012-10-16 01:24:43239void Composer::setAnimationTransactionImpl() {
240 Mutex::Autolock _l(mLock);
241 mAnimation = true;
242}
243
Mathias Agopian698c0872011-06-29 02:09:31244layer_state_t* Composer::getLayerStateLocked(
Mathias Agopianac9fa422013-02-12 00:40:36245 const sp<SurfaceComposerClient>& client, const sp<IBinder>& id) {
Mathias Agopian698c0872011-06-29 02:09:31246
247 ComposerState s;
248 s.client = client->mClient;
249 s.state.surface = id;
250
Mathias Agopiane57f2922012-08-09 23:29:12251 ssize_t index = mComposerStates.indexOf(s);
Mathias Agopian698c0872011-06-29 02:09:31252 if (index < 0) {
253 // we don't have it, add an initialized layer_state to our list
Mathias Agopiane57f2922012-08-09 23:29:12254 index = mComposerStates.add(s);
Mathias Agopian698c0872011-06-29 02:09:31255 }
256
Mathias Agopiane57f2922012-08-09 23:29:12257 ComposerState* const out = mComposerStates.editArray();
Mathias Agopian698c0872011-06-29 02:09:31258 return &(out[index].state);
259}
260
261status_t Composer::setPosition(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-12 00:40:36262 const sp<IBinder>& id, float x, float y) {
Mathias Agopian698c0872011-06-29 02:09:31263 Mutex::Autolock _l(mLock);
264 layer_state_t* s = getLayerStateLocked(client, id);
265 if (!s)
266 return BAD_INDEX;
Mathias Agopian3165cc22012-08-09 02:42:09267 s->what |= layer_state_t::ePositionChanged;
Mathias Agopian698c0872011-06-29 02:09:31268 s->x = x;
269 s->y = y;
270 return NO_ERROR;
271}
272
273status_t Composer::setSize(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-12 00:40:36274 const sp<IBinder>& id, uint32_t w, uint32_t h) {
Mathias Agopian698c0872011-06-29 02:09:31275 Mutex::Autolock _l(mLock);
276 layer_state_t* s = getLayerStateLocked(client, id);
277 if (!s)
278 return BAD_INDEX;
Mathias Agopian3165cc22012-08-09 02:42:09279 s->what |= layer_state_t::eSizeChanged;
Mathias Agopian698c0872011-06-29 02:09:31280 s->w = w;
281 s->h = h;
Jamie Gennis28378392011-10-13 00:39:00282
283 // Resizing a surface makes the transaction synchronous.
284 mForceSynchronous = true;
285
Mathias Agopian698c0872011-06-29 02:09:31286 return NO_ERROR;
287}
288
289status_t Composer::setLayer(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-12 00:40:36290 const sp<IBinder>& id, int32_t z) {
Mathias Agopian698c0872011-06-29 02:09:31291 Mutex::Autolock _l(mLock);
292 layer_state_t* s = getLayerStateLocked(client, id);
293 if (!s)
294 return BAD_INDEX;
Mathias Agopian3165cc22012-08-09 02:42:09295 s->what |= layer_state_t::eLayerChanged;
Mathias Agopian698c0872011-06-29 02:09:31296 s->z = z;
297 return NO_ERROR;
298}
299
300status_t Composer::setFlags(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-12 00:40:36301 const sp<IBinder>& id, uint32_t flags,
Mathias Agopian698c0872011-06-29 02:09:31302 uint32_t mask) {
303 Mutex::Autolock _l(mLock);
304 layer_state_t* s = getLayerStateLocked(client, id);
305 if (!s)
306 return BAD_INDEX;
Mathias Agopian3165cc22012-08-09 02:42:09307 s->what |= layer_state_t::eVisibilityChanged;
Mathias Agopian698c0872011-06-29 02:09:31308 s->flags &= ~mask;
309 s->flags |= (flags & mask);
310 s->mask |= mask;
311 return NO_ERROR;
312}
313
314status_t Composer::setTransparentRegionHint(
Mathias Agopianac9fa422013-02-12 00:40:36315 const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
Mathias Agopian698c0872011-06-29 02:09:31316 const Region& transparentRegion) {
317 Mutex::Autolock _l(mLock);
318 layer_state_t* s = getLayerStateLocked(client, id);
319 if (!s)
320 return BAD_INDEX;
Mathias Agopian3165cc22012-08-09 02:42:09321 s->what |= layer_state_t::eTransparentRegionChanged;
Mathias Agopian698c0872011-06-29 02:09:31322 s->transparentRegion = transparentRegion;
323 return NO_ERROR;
324}
325
326status_t Composer::setAlpha(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-12 00:40:36327 const sp<IBinder>& id, float alpha) {
Mathias Agopian698c0872011-06-29 02:09:31328 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::eAlphaChanged;
Mathias Agopian698c0872011-06-29 02:09:31333 s->alpha = alpha;
334 return NO_ERROR;
335}
336
Mathias Agopian87855782012-07-25 04:41:09337status_t Composer::setLayerStack(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-12 00:40:36338 const sp<IBinder>& id, uint32_t layerStack) {
Mathias Agopian87855782012-07-25 04:41:09339 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::eLayerStackChanged;
Mathias Agopian87855782012-07-25 04:41:09344 s->layerStack = layerStack;
345 return NO_ERROR;
346}
347
Mathias Agopian698c0872011-06-29 02:09:31348status_t Composer::setMatrix(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-12 00:40:36349 const sp<IBinder>& id, float dsdx, float dtdx,
Mathias Agopian698c0872011-06-29 02:09:31350 float dsdy, float dtdy) {
351 Mutex::Autolock _l(mLock);
352 layer_state_t* s = getLayerStateLocked(client, id);
353 if (!s)
354 return BAD_INDEX;
Mathias Agopian3165cc22012-08-09 02:42:09355 s->what |= layer_state_t::eMatrixChanged;
Mathias Agopian698c0872011-06-29 02:09:31356 layer_state_t::matrix22_t matrix;
357 matrix.dsdx = dsdx;
358 matrix.dtdx = dtdx;
359 matrix.dsdy = dsdy;
360 matrix.dtdy = dtdy;
361 s->matrix = matrix;
362 return NO_ERROR;
363}
364
Jamie Gennisf15a83f2012-05-11 03:43:55365status_t Composer::setCrop(const sp<SurfaceComposerClient>& client,
Mathias Agopianac9fa422013-02-12 00:40:36366 const sp<IBinder>& id, const Rect& crop) {
Jamie Gennisf15a83f2012-05-11 03:43:55367 Mutex::Autolock _l(mLock);
368 layer_state_t* s = getLayerStateLocked(client, id);
369 if (!s)
370 return BAD_INDEX;
Mathias Agopian3165cc22012-08-09 02:42:09371 s->what |= layer_state_t::eCropChanged;
Jamie Gennisf15a83f2012-05-11 03:43:55372 s->crop = crop;
373 return NO_ERROR;
374}
375
Mathias Agopian698c0872011-06-29 02:09:31376// ---------------------------------------------------------------------------
377
Mathias Agopiane57f2922012-08-09 23:29:12378DisplayState& Composer::getDisplayStateLocked(const sp<IBinder>& token) {
379 DisplayState s;
380 s.token = token;
381 ssize_t index = mDisplayStates.indexOf(s);
382 if (index < 0) {
383 // we don't have it, add an initialized layer_state to our list
384 s.what = 0;
385 index = mDisplayStates.add(s);
386 }
387 return mDisplayStates.editItemAt(index);
388}
389
390void Composer::setDisplaySurface(const sp<IBinder>& token,
Andy McFadden2adaf042012-12-18 17:49:45391 const sp<IGraphicBufferProducer>& bufferProducer) {
Mathias Agopiane57f2922012-08-09 23:29:12392 Mutex::Autolock _l(mLock);
393 DisplayState& s(getDisplayStateLocked(token));
Andy McFadden2adaf042012-12-18 17:49:45394 s.surface = bufferProducer;
Mathias Agopiane57f2922012-08-09 23:29:12395 s.what |= DisplayState::eSurfaceChanged;
396}
397
398void Composer::setDisplayLayerStack(const sp<IBinder>& token,
399 uint32_t layerStack) {
400 Mutex::Autolock _l(mLock);
401 DisplayState& s(getDisplayStateLocked(token));
402 s.layerStack = layerStack;
403 s.what |= DisplayState::eLayerStackChanged;
404}
405
Mathias Agopian00e8c7a2012-09-05 02:30:46406void Composer::setDisplayProjection(const sp<IBinder>& token,
407 uint32_t orientation,
408 const Rect& layerStackRect,
409 const Rect& displayRect) {
Mathias Agopiane57f2922012-08-09 23:29:12410 Mutex::Autolock _l(mLock);
411 DisplayState& s(getDisplayStateLocked(token));
412 s.orientation = orientation;
Mathias Agopian00e8c7a2012-09-05 02:30:46413 s.viewport = layerStackRect;
414 s.frame = displayRect;
415 s.what |= DisplayState::eDisplayProjectionChanged;
Mathias Agopiane57f2922012-08-09 23:29:12416 mForceSynchronous = true; // TODO: do we actually still need this?
417}
418
Mathias Agopiane57f2922012-08-09 23:29:12419// ---------------------------------------------------------------------------
420
The Android Open Source Projectedbf3b62009-03-04 03:31:44421SurfaceComposerClient::SurfaceComposerClient()
Mathias Agopian698c0872011-06-29 02:09:31422 : mStatus(NO_INIT), mComposer(Composer::getInstance())
The Android Open Source Projectedbf3b62009-03-04 03:31:44423{
The Android Open Source Projectedbf3b62009-03-04 03:31:44424}
425
Mathias Agopian698c0872011-06-29 02:09:31426void SurfaceComposerClient::onFirstRef() {
Mathias Agopiane57f2922012-08-09 23:29:12427 sp<ISurfaceComposer> sm(ComposerService::getComposerService());
Mathias Agopiand4784a32010-05-28 02:41:15428 if (sm != 0) {
Mathias Agopian7e27f052010-05-28 21:22:23429 sp<ISurfaceComposerClient> conn = sm->createConnection();
Mathias Agopiand4784a32010-05-28 02:41:15430 if (conn != 0) {
431 mClient = conn;
Mathias Agopiand4784a32010-05-28 02:41:15432 mStatus = NO_ERROR;
433 }
434 }
The Android Open Source Projectedbf3b62009-03-04 03:31:44435}
436
Mathias Agopian698c0872011-06-29 02:09:31437SurfaceComposerClient::~SurfaceComposerClient() {
Mathias Agopian631f3582010-05-26 00:51:34438 dispose();
439}
Mathias Agopiandd3423c2009-09-23 22:44:05440
Mathias Agopian698c0872011-06-29 02:09:31441status_t SurfaceComposerClient::initCheck() const {
The Android Open Source Projectedbf3b62009-03-04 03:31:44442 return mStatus;
443}
444
Mathias Agopian698c0872011-06-29 02:09:31445sp<IBinder> SurfaceComposerClient::connection() const {
The Android Open Source Projectedbf3b62009-03-04 03:31:44446 return (mClient != 0) ? mClient->asBinder() : 0;
447}
448
Mathias Agopiand4784a32010-05-28 02:41:15449status_t SurfaceComposerClient::linkToComposerDeath(
450 const sp<IBinder::DeathRecipient>& recipient,
Mathias Agopian698c0872011-06-29 02:09:31451 void* cookie, uint32_t flags) {
Mathias Agopiane57f2922012-08-09 23:29:12452 sp<ISurfaceComposer> sm(ComposerService::getComposerService());
Mathias Agopiand4784a32010-05-28 02:41:15453 return sm->asBinder()->linkToDeath(recipient, cookie, flags);
The Android Open Source Projectedbf3b62009-03-04 03:31:44454}
455
Mathias Agopian698c0872011-06-29 02:09:31456void SurfaceComposerClient::dispose() {
The Android Open Source Projectedbf3b62009-03-04 03:31:44457 // this can be called more than once.
Mathias Agopian7e27f052010-05-28 21:22:23458 sp<ISurfaceComposerClient> client;
Mathias Agopiand4784a32010-05-28 02:41:15459 Mutex::Autolock _lm(mLock);
460 if (mClient != 0) {
Mathias Agopiand4784a32010-05-28 02:41:15461 client = mClient; // hold ref while lock is held
462 mClient.clear();
The Android Open Source Projectedbf3b62009-03-04 03:31:44463 }
Mathias Agopiand4784a32010-05-28 02:41:15464 mStatus = NO_INIT;
The Android Open Source Projectedbf3b62009-03-04 03:31:44465}
466
Mathias Agopian698c0872011-06-29 02:09:31467sp<SurfaceControl> SurfaceComposerClient::createSurface(
Mathias Agopian698c0872011-06-29 02:09:31468 const String8& name,
Mathias Agopian698c0872011-06-29 02:09:31469 uint32_t w,
470 uint32_t h,
471 PixelFormat format,
472 uint32_t flags)
473{
474 sp<SurfaceControl> result;
475 if (mStatus == NO_ERROR) {
Mathias Agopianac9fa422013-02-12 00:40:36476 sp<ISurface> surface = mClient->createSurface(name, w, h, format, flags);
Mathias Agopian698c0872011-06-29 02:09:31477 if (surface != 0) {
Mathias Agopianac9fa422013-02-12 00:40:36478 result = new SurfaceControl(this, surface);
Mathias Agopian698c0872011-06-29 02:09:31479 }
480 }
481 return result;
482}
483
Jamie Gennisdd3cb842012-10-20 01:19:11484sp<IBinder> SurfaceComposerClient::createDisplay(const String8& displayName,
485 bool secure) {
486 return Composer::getInstance().createDisplay(displayName, secure);
Mathias Agopiane57f2922012-08-09 23:29:12487}
488
Jeff Brown9d4e3d22012-08-25 03:00:51489sp<IBinder> SurfaceComposerClient::getBuiltInDisplay(int32_t id) {
490 return Composer::getInstance().getBuiltInDisplay(id);
491}
492
Mathias Agopianac9fa422013-02-12 00:40:36493status_t SurfaceComposerClient::destroySurface(const sp<IBinder>& sid) {
Mathias Agopian698c0872011-06-29 02:09:31494 if (mStatus != NO_ERROR)
495 return mStatus;
496 status_t err = mClient->destroySurface(sid);
497 return err;
498}
499
500inline Composer& SurfaceComposerClient::getComposer() {
501 return mComposer;
502}
503
504// ----------------------------------------------------------------------------
505
506void SurfaceComposerClient::openGlobalTransaction() {
Jeff Brownf3f7db62012-08-31 09:18:38507 Composer::openGlobalTransaction();
Mathias Agopian698c0872011-06-29 02:09:31508}
509
Jamie Gennis28378392011-10-13 00:39:00510void SurfaceComposerClient::closeGlobalTransaction(bool synchronous) {
511 Composer::closeGlobalTransaction(synchronous);
Mathias Agopian698c0872011-06-29 02:09:31512}
513
Jamie Gennis2d5e2302012-10-16 01:24:43514void SurfaceComposerClient::setAnimationTransaction() {
515 Composer::setAnimationTransaction();
516}
517
Mathias Agopian698c0872011-06-29 02:09:31518// ----------------------------------------------------------------------------
519
Mathias Agopianac9fa422013-02-12 00:40:36520status_t SurfaceComposerClient::setCrop(const sp<IBinder>& id, const Rect& crop) {
Jamie Gennisf15a83f2012-05-11 03:43:55521 return getComposer().setCrop(this, id, crop);
522}
523
Mathias Agopianac9fa422013-02-12 00:40:36524status_t SurfaceComposerClient::setPosition(const sp<IBinder>& id, float x, float y) {
Mathias Agopian698c0872011-06-29 02:09:31525 return getComposer().setPosition(this, id, x, y);
526}
527
Mathias Agopianac9fa422013-02-12 00:40:36528status_t SurfaceComposerClient::setSize(const sp<IBinder>& id, uint32_t w, uint32_t h) {
Mathias Agopian698c0872011-06-29 02:09:31529 return getComposer().setSize(this, id, w, h);
530}
531
Mathias Agopianac9fa422013-02-12 00:40:36532status_t SurfaceComposerClient::setLayer(const sp<IBinder>& id, int32_t z) {
Mathias Agopian698c0872011-06-29 02:09:31533 return getComposer().setLayer(this, id, z);
534}
535
Mathias Agopianac9fa422013-02-12 00:40:36536status_t SurfaceComposerClient::hide(const sp<IBinder>& id) {
Mathias Agopian698c0872011-06-29 02:09:31537 return getComposer().setFlags(this, id,
Mathias Agopian3165cc22012-08-09 02:42:09538 layer_state_t::eLayerHidden,
539 layer_state_t::eLayerHidden);
Mathias Agopian698c0872011-06-29 02:09:31540}
541
Mathias Agopianac9fa422013-02-12 00:40:36542status_t SurfaceComposerClient::show(const sp<IBinder>& id) {
Mathias Agopian698c0872011-06-29 02:09:31543 return getComposer().setFlags(this, id,
544 0,
Mathias Agopian3165cc22012-08-09 02:42:09545 layer_state_t::eLayerHidden);
Mathias Agopian698c0872011-06-29 02:09:31546}
547
Mathias Agopianac9fa422013-02-12 00:40:36548status_t SurfaceComposerClient::setFlags(const sp<IBinder>& id, uint32_t flags,
Mathias Agopian698c0872011-06-29 02:09:31549 uint32_t mask) {
550 return getComposer().setFlags(this, id, flags, mask);
551}
552
Mathias Agopianac9fa422013-02-12 00:40:36553status_t SurfaceComposerClient::setTransparentRegionHint(const sp<IBinder>& id,
Mathias Agopian698c0872011-06-29 02:09:31554 const Region& transparentRegion) {
555 return getComposer().setTransparentRegionHint(this, id, transparentRegion);
556}
557
Mathias Agopianac9fa422013-02-12 00:40:36558status_t SurfaceComposerClient::setAlpha(const sp<IBinder>& id, float alpha) {
Mathias Agopian698c0872011-06-29 02:09:31559 return getComposer().setAlpha(this, id, alpha);
560}
561
Mathias Agopianac9fa422013-02-12 00:40:36562status_t SurfaceComposerClient::setLayerStack(const sp<IBinder>& id, uint32_t layerStack) {
Mathias Agopian87855782012-07-25 04:41:09563 return getComposer().setLayerStack(this, id, layerStack);
564}
565
Mathias Agopianac9fa422013-02-12 00:40:36566status_t SurfaceComposerClient::setMatrix(const sp<IBinder>& id, float dsdx, float dtdx,
Mathias Agopian698c0872011-06-29 02:09:31567 float dsdy, float dtdy) {
568 return getComposer().setMatrix(this, id, dsdx, dtdx, dsdy, dtdy);
569}
570
571// ----------------------------------------------------------------------------
572
Mathias Agopiane57f2922012-08-09 23:29:12573void SurfaceComposerClient::setDisplaySurface(const sp<IBinder>& token,
Andy McFadden2adaf042012-12-18 17:49:45574 const sp<IGraphicBufferProducer>& bufferProducer) {
575 Composer::getInstance().setDisplaySurface(token, bufferProducer);
Mathias Agopiane57f2922012-08-09 23:29:12576}
577
578void SurfaceComposerClient::setDisplayLayerStack(const sp<IBinder>& token,
579 uint32_t layerStack) {
580 Composer::getInstance().setDisplayLayerStack(token, layerStack);
581}
582
Mathias Agopian00e8c7a2012-09-05 02:30:46583void SurfaceComposerClient::setDisplayProjection(const sp<IBinder>& token,
584 uint32_t orientation,
585 const Rect& layerStackRect,
586 const Rect& displayRect) {
587 Composer::getInstance().setDisplayProjection(token, orientation,
588 layerStackRect, displayRect);
Mathias Agopiane57f2922012-08-09 23:29:12589}
590
591// ----------------------------------------------------------------------------
592
The Android Open Source Projectedbf3b62009-03-04 03:31:44593status_t SurfaceComposerClient::getDisplayInfo(
Jeff Brown9d4e3d22012-08-25 03:00:51594 const sp<IBinder>& display, DisplayInfo* info)
The Android Open Source Projectedbf3b62009-03-04 03:31:44595{
Jeff Brown9d4e3d22012-08-25 03:00:51596 return ComposerService::getComposerService()->getDisplayInfo(display, info);
The Android Open Source Projectedbf3b62009-03-04 03:31:44597}
598
Jeff Brown2a09bb32012-10-09 02:13:57599void SurfaceComposerClient::blankDisplay(const sp<IBinder>& token) {
600 ComposerService::getComposerService()->blank(token);
601}
602
603void SurfaceComposerClient::unblankDisplay(const sp<IBinder>& token) {
604 ComposerService::getComposerService()->unblank(token);
605}
606
Mathias Agopian698c0872011-06-29 02:09:31607// ----------------------------------------------------------------------------
The Android Open Source Projectedbf3b62009-03-04 03:31:44608
Mathias Agopian74c40c02010-09-29 20:02:36609ScreenshotClient::ScreenshotClient()
610 : mWidth(0), mHeight(0), mFormat(PIXEL_FORMAT_NONE) {
611}
612
Jeff Brown9d4e3d22012-08-25 03:00:51613status_t ScreenshotClient::update(const sp<IBinder>& display) {
Mathias Agopian74c40c02010-09-29 20:02:36614 sp<ISurfaceComposer> s(ComposerService::getComposerService());
615 if (s == NULL) return NO_INIT;
616 mHeap = 0;
Jeff Brown9d4e3d22012-08-25 03:00:51617 return s->captureScreen(display, &mHeap,
Mathias Agopianbf2c6a62010-12-11 00:22:31618 &mWidth, &mHeight, &mFormat, 0, 0,
619 0, -1UL);
Mathias Agopian74c40c02010-09-29 20:02:36620}
621
Jeff Brown9d4e3d22012-08-25 03:00:51622status_t ScreenshotClient::update(const sp<IBinder>& display,
623 uint32_t reqWidth, uint32_t reqHeight) {
Mathias Agopian74c40c02010-09-29 20:02:36624 sp<ISurfaceComposer> s(ComposerService::getComposerService());
625 if (s == NULL) return NO_INIT;
626 mHeap = 0;
Jeff Brown9d4e3d22012-08-25 03:00:51627 return s->captureScreen(display, &mHeap,
Mathias Agopianbf2c6a62010-12-11 00:22:31628 &mWidth, &mHeight, &mFormat, reqWidth, reqHeight,
629 0, -1UL);
630}
631
Jeff Brown9d4e3d22012-08-25 03:00:51632status_t ScreenshotClient::update(const sp<IBinder>& display,
633 uint32_t reqWidth, uint32_t reqHeight,
Mathias Agopianbf2c6a62010-12-11 00:22:31634 uint32_t minLayerZ, uint32_t maxLayerZ) {
635 sp<ISurfaceComposer> s(ComposerService::getComposerService());
636 if (s == NULL) return NO_INIT;
637 mHeap = 0;
Jeff Brown9d4e3d22012-08-25 03:00:51638 return s->captureScreen(display, &mHeap,
Mathias Agopianbf2c6a62010-12-11 00:22:31639 &mWidth, &mHeight, &mFormat, reqWidth, reqHeight,
640 minLayerZ, maxLayerZ);
Mathias Agopian74c40c02010-09-29 20:02:36641}
642
643void ScreenshotClient::release() {
644 mHeap = 0;
645}
646
647void const* ScreenshotClient::getPixels() const {
648 return mHeap->getBase();
649}
650
651uint32_t ScreenshotClient::getWidth() const {
652 return mWidth;
653}
654
655uint32_t ScreenshotClient::getHeight() const {
656 return mHeight;
657}
658
659PixelFormat ScreenshotClient::getFormat() const {
660 return mFormat;
661}
662
663uint32_t ScreenshotClient::getStride() const {
664 return mWidth;
665}
666
667size_t ScreenshotClient::getSize() const {
668 return mHeap->getSize();
669}
670
671// ----------------------------------------------------------------------------
The Android Open Source Projectedbf3b62009-03-04 03:31:44672}; // namespace android