blob: 4ad6c22c0dae6a4c73de5a93b312df0cfb85bb03 [file] [log] [blame]
The Android Open Source Project9066cfe2009-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 Project9066cfe2009-03-03 19:31:44 -080020#include <sys/types.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080021
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080022#include <utils/Errors.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080023#include <utils/Log.h>
Mathias Agopianc7b388c2010-05-27 19:41:15 -070024#include <utils/Singleton.h>
Mathias Agopian7bb843c2011-04-20 14:20:59 -070025#include <utils/SortedVector.h>
26#include <utils/String8.h>
27#include <utils/threads.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080028
Mathias Agopian000479f2010-02-09 17:46:37 -080029#include <binder/IMemory.h>
Mathias Agopian7bb843c2011-04-20 14:20:59 -070030#include <binder/IServiceManager.h>
Mathias Agopian000479f2010-02-09 17:46:37 -080031
Mathias Agopian1473f462009-04-10 14:24:30 -070032#include <ui/DisplayInfo.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080033
Mathias Agopian7bb843c2011-04-20 14:20:59 -070034#include <surfaceflinger/ISurface.h>
Mathias Agopian000479f2010-02-09 17:46:37 -080035#include <surfaceflinger/ISurfaceComposer.h>
Mathias Agopian770492c2010-05-28 14:22:23 -070036#include <surfaceflinger/ISurfaceComposerClient.h>
Mathias Agopian000479f2010-02-09 17:46:37 -080037#include <surfaceflinger/SurfaceComposerClient.h>
38
39#include <private/surfaceflinger/LayerState.h>
40#include <private/surfaceflinger/SharedBufferStack.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080041
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080042
43namespace android {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080044// ---------------------------------------------------------------------------
45
Mathias Agopian770492c2010-05-28 14:22:23 -070046ANDROID_SINGLETON_STATIC_INSTANCE(ComposerService);
47
Mathias Agopian7623da42010-06-01 15:12:58 -070048ComposerService::ComposerService()
49: Singleton<ComposerService>() {
50 const String16 name("SurfaceFlinger");
51 while (getService(name, &mComposerService) != NO_ERROR) {
52 usleep(250000);
53 }
54 mServerCblkMemory = mComposerService->getCblk();
55 mServerCblk = static_cast<surface_flinger_cblk_t volatile *>(
56 mServerCblkMemory->getBase());
57}
58
59sp<ISurfaceComposer> ComposerService::getComposerService() {
60 return ComposerService::getInstance().mComposerService;
61}
62
63surface_flinger_cblk_t const volatile * ComposerService::getControlBlock() {
64 return ComposerService::getInstance().mServerCblk;
65}
Mathias Agopian770492c2010-05-28 14:22:23 -070066
67static inline sp<ISurfaceComposer> getComposerService() {
68 return ComposerService::getComposerService();
69}
70
71static inline surface_flinger_cblk_t const volatile * get_cblk() {
72 return ComposerService::getControlBlock();
73}
74
75// ---------------------------------------------------------------------------
76
Mathias Agopian439863f2011-06-28 19:09:31 -070077// NOTE: this is NOT a member function (it's a friend defined with its
78// declaration).
79static inline
80int compare_type( const ComposerState& lhs, const ComposerState& rhs) {
81 if (lhs.client < rhs.client) return -1;
82 if (lhs.client > rhs.client) return 1;
83 if (lhs.state.surface < rhs.state.surface) return -1;
84 if (lhs.state.surface > rhs.state.surface) return 1;
85 return 0;
86}
87
Mathias Agopian770492c2010-05-28 14:22:23 -070088class Composer : public Singleton<Composer>
89{
Mathias Agopianc7b388c2010-05-27 19:41:15 -070090 friend class Singleton<Composer>;
91
Mathias Agopian439863f2011-06-28 19:09:31 -070092 mutable Mutex mLock;
93 SortedVector<ComposerState> mStates;
Jamie Gennise2909e12011-10-10 15:48:06 -070094 int mOrientation;
Jamie Gennis122aa6b2011-10-12 17:39:00 -070095 uint32_t mForceSynchronous;
Mathias Agopian439863f2011-06-28 19:09:31 -070096
Jamie Gennise2909e12011-10-10 15:48:06 -070097 Composer() : Singleton<Composer>(),
Jamie Gennis122aa6b2011-10-12 17:39:00 -070098 mOrientation(ISurfaceComposer::eOrientationUnchanged),
99 mForceSynchronous(0)
100 { }
Mathias Agopian439863f2011-06-28 19:09:31 -0700101
Jamie Gennis122aa6b2011-10-12 17:39:00 -0700102 void closeGlobalTransactionImpl(bool synchronous);
Mathias Agopian439863f2011-06-28 19:09:31 -0700103
104 layer_state_t* getLayerStateLocked(
105 const sp<SurfaceComposerClient>& client, SurfaceID id);
106
Mathias Agopianc7b388c2010-05-27 19:41:15 -0700107public:
Mathias Agopian439863f2011-06-28 19:09:31 -0700108
109 status_t setPosition(const sp<SurfaceComposerClient>& client, SurfaceID id,
Mathias Agopian34cb9f2a2011-08-30 18:51:54 -0700110 float x, float y);
Mathias Agopian439863f2011-06-28 19:09:31 -0700111 status_t setSize(const sp<SurfaceComposerClient>& client, SurfaceID id,
112 uint32_t w, uint32_t h);
113 status_t setLayer(const sp<SurfaceComposerClient>& client, SurfaceID id,
114 int32_t z);
115 status_t setFlags(const sp<SurfaceComposerClient>& client, SurfaceID id,
116 uint32_t flags, uint32_t mask);
117 status_t setTransparentRegionHint(
118 const sp<SurfaceComposerClient>& client, SurfaceID id,
119 const Region& transparentRegion);
120 status_t setAlpha(const sp<SurfaceComposerClient>& client, SurfaceID id,
121 float alpha);
122 status_t setMatrix(const sp<SurfaceComposerClient>& client, SurfaceID id,
123 float dsdx, float dtdx, float dsdy, float dtdy);
124 status_t setFreezeTint(
125 const sp<SurfaceComposerClient>& client, SurfaceID id,
126 uint32_t tint);
Jamie Gennise2909e12011-10-10 15:48:06 -0700127 status_t setOrientation(int orientation);
Mathias Agopian439863f2011-06-28 19:09:31 -0700128
Jamie Gennis122aa6b2011-10-12 17:39:00 -0700129 static void closeGlobalTransaction(bool synchronous) {
130 Composer::getInstance().closeGlobalTransactionImpl(synchronous);
Mathias Agopianc7b388c2010-05-27 19:41:15 -0700131 }
132};
133
134ANDROID_SINGLETON_STATIC_INSTANCE(Composer);
135
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800136// ---------------------------------------------------------------------------
137
Jamie Gennis122aa6b2011-10-12 17:39:00 -0700138void Composer::closeGlobalTransactionImpl(bool synchronous) {
Mathias Agopian439863f2011-06-28 19:09:31 -0700139 sp<ISurfaceComposer> sm(getComposerService());
140
141 Vector<ComposerState> transaction;
Jamie Gennise2909e12011-10-10 15:48:06 -0700142 int orientation;
Jamie Gennis122aa6b2011-10-12 17:39:00 -0700143 uint32_t flags = 0;
Mathias Agopian439863f2011-06-28 19:09:31 -0700144
145 { // scope for the lock
146 Mutex::Autolock _l(mLock);
147 transaction = mStates;
148 mStates.clear();
Jamie Gennise2909e12011-10-10 15:48:06 -0700149
150 orientation = mOrientation;
151 mOrientation = ISurfaceComposer::eOrientationUnchanged;
Jamie Gennis122aa6b2011-10-12 17:39:00 -0700152
153 if (synchronous || mForceSynchronous) {
154 flags |= ISurfaceComposer::eSynchronous;
155 }
156 mForceSynchronous = false;
Mathias Agopian439863f2011-06-28 19:09:31 -0700157 }
158
Jamie Gennis122aa6b2011-10-12 17:39:00 -0700159 sm->setTransactionState(transaction, orientation, flags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800160}
161
Mathias Agopian439863f2011-06-28 19:09:31 -0700162layer_state_t* Composer::getLayerStateLocked(
163 const sp<SurfaceComposerClient>& client, SurfaceID id) {
164
165 ComposerState s;
166 s.client = client->mClient;
167 s.state.surface = id;
168
169 ssize_t index = mStates.indexOf(s);
170 if (index < 0) {
171 // we don't have it, add an initialized layer_state to our list
172 index = mStates.add(s);
173 }
174
175 ComposerState* const out = mStates.editArray();
176 return &(out[index].state);
177}
178
179status_t Composer::setPosition(const sp<SurfaceComposerClient>& client,
Mathias Agopian34cb9f2a2011-08-30 18:51:54 -0700180 SurfaceID id, float x, float y) {
Mathias Agopian439863f2011-06-28 19:09:31 -0700181 Mutex::Autolock _l(mLock);
182 layer_state_t* s = getLayerStateLocked(client, id);
183 if (!s)
184 return BAD_INDEX;
185 s->what |= ISurfaceComposer::ePositionChanged;
186 s->x = x;
187 s->y = y;
188 return NO_ERROR;
189}
190
191status_t Composer::setSize(const sp<SurfaceComposerClient>& client,
192 SurfaceID id, uint32_t w, uint32_t h) {
193 Mutex::Autolock _l(mLock);
194 layer_state_t* s = getLayerStateLocked(client, id);
195 if (!s)
196 return BAD_INDEX;
197 s->what |= ISurfaceComposer::eSizeChanged;
198 s->w = w;
199 s->h = h;
Jamie Gennis122aa6b2011-10-12 17:39:00 -0700200
201 // Resizing a surface makes the transaction synchronous.
202 mForceSynchronous = true;
203
Mathias Agopian439863f2011-06-28 19:09:31 -0700204 return NO_ERROR;
205}
206
207status_t Composer::setLayer(const sp<SurfaceComposerClient>& client,
208 SurfaceID id, int32_t z) {
209 Mutex::Autolock _l(mLock);
210 layer_state_t* s = getLayerStateLocked(client, id);
211 if (!s)
212 return BAD_INDEX;
213 s->what |= ISurfaceComposer::eLayerChanged;
214 s->z = z;
215 return NO_ERROR;
216}
217
218status_t Composer::setFlags(const sp<SurfaceComposerClient>& client,
219 SurfaceID id, uint32_t flags,
220 uint32_t mask) {
221 Mutex::Autolock _l(mLock);
222 layer_state_t* s = getLayerStateLocked(client, id);
223 if (!s)
224 return BAD_INDEX;
225 s->what |= ISurfaceComposer::eVisibilityChanged;
226 s->flags &= ~mask;
227 s->flags |= (flags & mask);
228 s->mask |= mask;
229 return NO_ERROR;
230}
231
232status_t Composer::setTransparentRegionHint(
233 const sp<SurfaceComposerClient>& client, SurfaceID id,
234 const Region& transparentRegion) {
235 Mutex::Autolock _l(mLock);
236 layer_state_t* s = getLayerStateLocked(client, id);
237 if (!s)
238 return BAD_INDEX;
239 s->what |= ISurfaceComposer::eTransparentRegionChanged;
240 s->transparentRegion = transparentRegion;
241 return NO_ERROR;
242}
243
244status_t Composer::setAlpha(const sp<SurfaceComposerClient>& client,
245 SurfaceID id, float alpha) {
246 Mutex::Autolock _l(mLock);
247 layer_state_t* s = getLayerStateLocked(client, id);
248 if (!s)
249 return BAD_INDEX;
250 s->what |= ISurfaceComposer::eAlphaChanged;
251 s->alpha = alpha;
252 return NO_ERROR;
253}
254
255status_t Composer::setMatrix(const sp<SurfaceComposerClient>& client,
256 SurfaceID id, float dsdx, float dtdx,
257 float dsdy, float dtdy) {
258 Mutex::Autolock _l(mLock);
259 layer_state_t* s = getLayerStateLocked(client, id);
260 if (!s)
261 return BAD_INDEX;
262 s->what |= ISurfaceComposer::eMatrixChanged;
263 layer_state_t::matrix22_t matrix;
264 matrix.dsdx = dsdx;
265 matrix.dtdx = dtdx;
266 matrix.dsdy = dsdy;
267 matrix.dtdy = dtdy;
268 s->matrix = matrix;
269 return NO_ERROR;
270}
271
272status_t Composer::setFreezeTint(const sp<SurfaceComposerClient>& client,
273 SurfaceID id, uint32_t tint) {
274 Mutex::Autolock _l(mLock);
275 layer_state_t* s = getLayerStateLocked(client, id);
276 if (!s)
277 return BAD_INDEX;
278 s->what |= ISurfaceComposer::eFreezeTintChanged;
279 s->tint = tint;
280 return NO_ERROR;
281}
282
Jamie Gennise2909e12011-10-10 15:48:06 -0700283status_t Composer::setOrientation(int orientation) {
284 Mutex::Autolock _l(mLock);
285 mOrientation = orientation;
Jamie Gennis122aa6b2011-10-12 17:39:00 -0700286
287 // Changing the orientation makes the transaction synchronous.
288 mForceSynchronous = true;
289
Jamie Gennise2909e12011-10-10 15:48:06 -0700290 return NO_ERROR;
291}
292
Mathias Agopian439863f2011-06-28 19:09:31 -0700293// ---------------------------------------------------------------------------
294
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800295SurfaceComposerClient::SurfaceComposerClient()
Mathias Agopian439863f2011-06-28 19:09:31 -0700296 : mStatus(NO_INIT), mComposer(Composer::getInstance())
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800297{
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800298}
299
Mathias Agopian439863f2011-06-28 19:09:31 -0700300void SurfaceComposerClient::onFirstRef() {
Mathias Agopianc7b388c2010-05-27 19:41:15 -0700301 sp<ISurfaceComposer> sm(getComposerService());
302 if (sm != 0) {
Mathias Agopian770492c2010-05-28 14:22:23 -0700303 sp<ISurfaceComposerClient> conn = sm->createConnection();
Mathias Agopianc7b388c2010-05-27 19:41:15 -0700304 if (conn != 0) {
305 mClient = conn;
Mathias Agopianc7b388c2010-05-27 19:41:15 -0700306 mStatus = NO_ERROR;
307 }
308 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800309}
310
Mathias Agopian439863f2011-06-28 19:09:31 -0700311SurfaceComposerClient::~SurfaceComposerClient() {
Mathias Agopian2ce19af2010-05-25 17:51:34 -0700312 dispose();
313}
Mathias Agopianbc726112009-09-23 15:44:05 -0700314
Mathias Agopian439863f2011-06-28 19:09:31 -0700315status_t SurfaceComposerClient::initCheck() const {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800316 return mStatus;
317}
318
Mathias Agopian439863f2011-06-28 19:09:31 -0700319sp<IBinder> SurfaceComposerClient::connection() const {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800320 return (mClient != 0) ? mClient->asBinder() : 0;
321}
322
Mathias Agopianc7b388c2010-05-27 19:41:15 -0700323status_t SurfaceComposerClient::linkToComposerDeath(
324 const sp<IBinder::DeathRecipient>& recipient,
Mathias Agopian439863f2011-06-28 19:09:31 -0700325 void* cookie, uint32_t flags) {
Mathias Agopianc7b388c2010-05-27 19:41:15 -0700326 sp<ISurfaceComposer> sm(getComposerService());
327 return sm->asBinder()->linkToDeath(recipient, cookie, flags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800328}
329
Mathias Agopian439863f2011-06-28 19:09:31 -0700330void SurfaceComposerClient::dispose() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800331 // this can be called more than once.
Mathias Agopian770492c2010-05-28 14:22:23 -0700332 sp<ISurfaceComposerClient> client;
Mathias Agopianc7b388c2010-05-27 19:41:15 -0700333 Mutex::Autolock _lm(mLock);
334 if (mClient != 0) {
Mathias Agopianc7b388c2010-05-27 19:41:15 -0700335 client = mClient; // hold ref while lock is held
336 mClient.clear();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800337 }
Mathias Agopianc7b388c2010-05-27 19:41:15 -0700338 mStatus = NO_INIT;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800339}
340
Mathias Agopian439863f2011-06-28 19:09:31 -0700341sp<SurfaceControl> SurfaceComposerClient::createSurface(
342 DisplayID display,
343 uint32_t w,
344 uint32_t h,
345 PixelFormat format,
346 uint32_t flags)
347{
348 String8 name;
349 const size_t SIZE = 128;
350 char buffer[SIZE];
351 snprintf(buffer, SIZE, "<pid_%d>", getpid());
352 name.append(buffer);
353
354 return SurfaceComposerClient::createSurface(name, display,
355 w, h, format, flags);
356}
357
358sp<SurfaceControl> SurfaceComposerClient::createSurface(
359 const String8& name,
360 DisplayID display,
361 uint32_t w,
362 uint32_t h,
363 PixelFormat format,
364 uint32_t flags)
365{
366 sp<SurfaceControl> result;
367 if (mStatus == NO_ERROR) {
368 ISurfaceComposerClient::surface_data_t data;
369 sp<ISurface> surface = mClient->createSurface(&data, name,
370 display, w, h, format, flags);
371 if (surface != 0) {
Mathias Agopian50c24a22011-07-20 16:46:11 -0700372 result = new SurfaceControl(this, surface, data);
Mathias Agopian439863f2011-06-28 19:09:31 -0700373 }
374 }
375 return result;
376}
377
378status_t SurfaceComposerClient::destroySurface(SurfaceID sid) {
379 if (mStatus != NO_ERROR)
380 return mStatus;
381 status_t err = mClient->destroySurface(sid);
382 return err;
383}
384
385inline Composer& SurfaceComposerClient::getComposer() {
386 return mComposer;
387}
388
389// ----------------------------------------------------------------------------
390
391void SurfaceComposerClient::openGlobalTransaction() {
392 // Currently a no-op
393}
394
Jamie Gennis122aa6b2011-10-12 17:39:00 -0700395void SurfaceComposerClient::closeGlobalTransaction(bool synchronous) {
396 Composer::closeGlobalTransaction(synchronous);
Mathias Agopian439863f2011-06-28 19:09:31 -0700397}
398
399// ----------------------------------------------------------------------------
400
401status_t SurfaceComposerClient::setFreezeTint(SurfaceID id, uint32_t tint) {
402 return getComposer().setFreezeTint(this, id, tint);
403}
404
Mathias Agopian34cb9f2a2011-08-30 18:51:54 -0700405status_t SurfaceComposerClient::setPosition(SurfaceID id, float x, float y) {
Mathias Agopian439863f2011-06-28 19:09:31 -0700406 return getComposer().setPosition(this, id, x, y);
407}
408
409status_t SurfaceComposerClient::setSize(SurfaceID id, uint32_t w, uint32_t h) {
410 return getComposer().setSize(this, id, w, h);
411}
412
413status_t SurfaceComposerClient::setLayer(SurfaceID id, int32_t z) {
414 return getComposer().setLayer(this, id, z);
415}
416
417status_t SurfaceComposerClient::hide(SurfaceID id) {
418 return getComposer().setFlags(this, id,
419 ISurfaceComposer::eLayerHidden,
420 ISurfaceComposer::eLayerHidden);
421}
422
423status_t SurfaceComposerClient::show(SurfaceID id, int32_t) {
424 return getComposer().setFlags(this, id,
425 0,
426 ISurfaceComposer::eLayerHidden);
427}
428
429status_t SurfaceComposerClient::freeze(SurfaceID id) {
430 return getComposer().setFlags(this, id,
431 ISurfaceComposer::eLayerFrozen,
432 ISurfaceComposer::eLayerFrozen);
433}
434
435status_t SurfaceComposerClient::unfreeze(SurfaceID id) {
436 return getComposer().setFlags(this, id,
437 0,
438 ISurfaceComposer::eLayerFrozen);
439}
440
441status_t SurfaceComposerClient::setFlags(SurfaceID id, uint32_t flags,
442 uint32_t mask) {
443 return getComposer().setFlags(this, id, flags, mask);
444}
445
446status_t SurfaceComposerClient::setTransparentRegionHint(SurfaceID id,
447 const Region& transparentRegion) {
448 return getComposer().setTransparentRegionHint(this, id, transparentRegion);
449}
450
451status_t SurfaceComposerClient::setAlpha(SurfaceID id, float alpha) {
452 return getComposer().setAlpha(this, id, alpha);
453}
454
455status_t SurfaceComposerClient::setMatrix(SurfaceID id, float dsdx, float dtdx,
456 float dsdy, float dtdy) {
457 return getComposer().setMatrix(this, id, dsdx, dtdx, dsdy, dtdy);
458}
459
Jamie Gennise2909e12011-10-10 15:48:06 -0700460status_t SurfaceComposerClient::setOrientation(DisplayID dpy,
461 int orientation, uint32_t flags)
462{
463 return Composer::getInstance().setOrientation(orientation);
464}
465
Mathias Agopian439863f2011-06-28 19:09:31 -0700466// ----------------------------------------------------------------------------
467
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800468status_t SurfaceComposerClient::getDisplayInfo(
469 DisplayID dpy, DisplayInfo* info)
470{
Mathias Agopian7bb843c2011-04-20 14:20:59 -0700471 if (uint32_t(dpy)>=NUM_DISPLAY_MAX)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800472 return BAD_VALUE;
473
474 volatile surface_flinger_cblk_t const * cblk = get_cblk();
475 volatile display_cblk_t const * dcblk = cblk->displays + dpy;
476
477 info->w = dcblk->w;
478 info->h = dcblk->h;
479 info->orientation = dcblk->orientation;
480 info->xdpi = dcblk->xdpi;
481 info->ydpi = dcblk->ydpi;
482 info->fps = dcblk->fps;
483 info->density = dcblk->density;
484 return getPixelFormatInfo(dcblk->format, &(info->pixelFormatInfo));
485}
486
487ssize_t SurfaceComposerClient::getDisplayWidth(DisplayID dpy)
488{
Mathias Agopian7bb843c2011-04-20 14:20:59 -0700489 if (uint32_t(dpy)>=NUM_DISPLAY_MAX)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800490 return BAD_VALUE;
491 volatile surface_flinger_cblk_t const * cblk = get_cblk();
492 volatile display_cblk_t const * dcblk = cblk->displays + dpy;
493 return dcblk->w;
494}
495
496ssize_t SurfaceComposerClient::getDisplayHeight(DisplayID dpy)
497{
Mathias Agopian7bb843c2011-04-20 14:20:59 -0700498 if (uint32_t(dpy)>=NUM_DISPLAY_MAX)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800499 return BAD_VALUE;
500 volatile surface_flinger_cblk_t const * cblk = get_cblk();
501 volatile display_cblk_t const * dcblk = cblk->displays + dpy;
502 return dcblk->h;
503}
504
505ssize_t SurfaceComposerClient::getDisplayOrientation(DisplayID dpy)
506{
Mathias Agopian7bb843c2011-04-20 14:20:59 -0700507 if (uint32_t(dpy)>=NUM_DISPLAY_MAX)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800508 return BAD_VALUE;
509 volatile surface_flinger_cblk_t const * cblk = get_cblk();
510 volatile display_cblk_t const * dcblk = cblk->displays + dpy;
511 return dcblk->orientation;
512}
513
514ssize_t SurfaceComposerClient::getNumberOfDisplays()
515{
516 volatile surface_flinger_cblk_t const * cblk = get_cblk();
517 uint32_t connected = cblk->connected;
518 int n = 0;
519 while (connected) {
520 if (connected&1) n++;
521 connected >>= 1;
522 }
523 return n;
524}
525
Mathias Agopian439863f2011-06-28 19:09:31 -0700526// ----------------------------------------------------------------------------
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800527
528status_t SurfaceComposerClient::freezeDisplay(DisplayID dpy, uint32_t flags)
529{
Jamie Gennise2909e12011-10-10 15:48:06 -0700530 // This has been made a no-op because it can cause Gralloc buffer deadlocks.
531 return NO_ERROR;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800532}
533
534status_t SurfaceComposerClient::unfreezeDisplay(DisplayID dpy, uint32_t flags)
535{
Jamie Gennise2909e12011-10-10 15:48:06 -0700536 // This has been made a no-op because it can cause Gralloc buffer deadlocks.
537 return NO_ERROR;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800538}
539
Mathias Agopianc7b388c2010-05-27 19:41:15 -0700540// ----------------------------------------------------------------------------
Mathias Agopian38ed2e32010-09-29 13:02:36 -0700541
542ScreenshotClient::ScreenshotClient()
543 : mWidth(0), mHeight(0), mFormat(PIXEL_FORMAT_NONE) {
544}
545
546status_t ScreenshotClient::update() {
547 sp<ISurfaceComposer> s(ComposerService::getComposerService());
548 if (s == NULL) return NO_INIT;
549 mHeap = 0;
550 return s->captureScreen(0, &mHeap,
Mathias Agopian3dd25a62010-12-10 16:22:31 -0800551 &mWidth, &mHeight, &mFormat, 0, 0,
552 0, -1UL);
Mathias Agopian38ed2e32010-09-29 13:02:36 -0700553}
554
555status_t ScreenshotClient::update(uint32_t reqWidth, uint32_t reqHeight) {
556 sp<ISurfaceComposer> s(ComposerService::getComposerService());
557 if (s == NULL) return NO_INIT;
558 mHeap = 0;
559 return s->captureScreen(0, &mHeap,
Mathias Agopian3dd25a62010-12-10 16:22:31 -0800560 &mWidth, &mHeight, &mFormat, reqWidth, reqHeight,
561 0, -1UL);
562}
563
564status_t ScreenshotClient::update(uint32_t reqWidth, uint32_t reqHeight,
565 uint32_t minLayerZ, uint32_t maxLayerZ) {
566 sp<ISurfaceComposer> s(ComposerService::getComposerService());
567 if (s == NULL) return NO_INIT;
568 mHeap = 0;
569 return s->captureScreen(0, &mHeap,
570 &mWidth, &mHeight, &mFormat, reqWidth, reqHeight,
571 minLayerZ, maxLayerZ);
Mathias Agopian38ed2e32010-09-29 13:02:36 -0700572}
573
574void ScreenshotClient::release() {
575 mHeap = 0;
576}
577
578void const* ScreenshotClient::getPixels() const {
579 return mHeap->getBase();
580}
581
582uint32_t ScreenshotClient::getWidth() const {
583 return mWidth;
584}
585
586uint32_t ScreenshotClient::getHeight() const {
587 return mHeight;
588}
589
590PixelFormat ScreenshotClient::getFormat() const {
591 return mFormat;
592}
593
594uint32_t ScreenshotClient::getStride() const {
595 return mWidth;
596}
597
598size_t ScreenshotClient::getSize() const {
599 return mHeap->getSize();
600}
601
602// ----------------------------------------------------------------------------
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800603}; // namespace android