blob: 8fa21671ebb82c2dba9d97c8d187124bfd524f57 [file] [log] [blame]
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#define LOG_TAG "SurfaceComposerClient"
18
19#include <stdint.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080020#include <sys/types.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080021
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080022#include <utils/Errors.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080023#include <utils/Log.h>
Mathias Agopiand4784a32010-05-27 19:41:15 -070024#include <utils/Singleton.h>
Mathias Agopiana67932f2011-04-20 14:20:59 -070025#include <utils/SortedVector.h>
26#include <utils/String8.h>
27#include <utils/threads.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080028
Mathias Agopian9cce3252010-02-09 17:46:37 -080029#include <binder/IMemory.h>
Mathias Agopiana67932f2011-04-20 14:20:59 -070030#include <binder/IServiceManager.h>
Mathias Agopian9cce3252010-02-09 17:46:37 -080031
Mathias Agopian076b1cc2009-04-10 14:24:30 -070032#include <ui/DisplayInfo.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080033
Mathias Agopian90ac7992012-02-25 18:48:35 -080034#include <gui/ISurface.h>
35#include <gui/ISurfaceComposer.h>
36#include <gui/ISurfaceComposerClient.h>
37#include <gui/SurfaceComposerClient.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080038
Mathias Agopian41f673c2011-11-17 17:48:35 -080039#include <private/gui/ComposerService.h>
Mathias Agopian90ac7992012-02-25 18:48:35 -080040#include <private/gui/LayerState.h>
41#include <private/gui/SharedBufferStack.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080042
43namespace android {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080044// ---------------------------------------------------------------------------
45
Mathias Agopian7e27f052010-05-28 14:22:23 -070046ANDROID_SINGLETON_STATIC_INSTANCE(ComposerService);
47
Mathias Agopianb7e930d2010-06-01 15:12:58 -070048ComposerService::ComposerService()
49: Singleton<ComposerService>() {
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 Agopian7e27f052010-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 Agopian698c0872011-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 Agopian7e27f052010-05-28 14:22:23 -070088class Composer : public Singleton<Composer>
89{
Mathias Agopiand4784a32010-05-27 19:41:15 -070090 friend class Singleton<Composer>;
91
Mathias Agopian698c0872011-06-28 19:09:31 -070092 mutable Mutex mLock;
93 SortedVector<ComposerState> mStates;
Jamie Gennisb8d69a52011-10-10 15:48:06 -070094 int mOrientation;
Jamie Gennis28378392011-10-12 17:39:00 -070095 uint32_t mForceSynchronous;
Mathias Agopian698c0872011-06-28 19:09:31 -070096
Jamie Gennisb8d69a52011-10-10 15:48:06 -070097 Composer() : Singleton<Composer>(),
Jamie Gennis28378392011-10-12 17:39:00 -070098 mOrientation(ISurfaceComposer::eOrientationUnchanged),
99 mForceSynchronous(0)
100 { }
Mathias Agopian698c0872011-06-28 19:09:31 -0700101
Jamie Gennis28378392011-10-12 17:39:00 -0700102 void closeGlobalTransactionImpl(bool synchronous);
Mathias Agopian698c0872011-06-28 19:09:31 -0700103
104 layer_state_t* getLayerStateLocked(
105 const sp<SurfaceComposerClient>& client, SurfaceID id);
106
Mathias Agopiand4784a32010-05-27 19:41:15 -0700107public:
Mathias Agopian698c0872011-06-28 19:09:31 -0700108
109 status_t setPosition(const sp<SurfaceComposerClient>& client, SurfaceID id,
Mathias Agopian41b6aab2011-08-30 18:51:54 -0700110 float x, float y);
Mathias Agopian698c0872011-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 Gennisb8d69a52011-10-10 15:48:06 -0700127 status_t setOrientation(int orientation);
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700128 status_t setCrop(const sp<SurfaceComposerClient>& client, SurfaceID id,
129 const Rect& crop);
Mathias Agopian698c0872011-06-28 19:09:31 -0700130
Jamie Gennis28378392011-10-12 17:39:00 -0700131 static void closeGlobalTransaction(bool synchronous) {
132 Composer::getInstance().closeGlobalTransactionImpl(synchronous);
Mathias Agopiand4784a32010-05-27 19:41:15 -0700133 }
134};
135
136ANDROID_SINGLETON_STATIC_INSTANCE(Composer);
137
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800138// ---------------------------------------------------------------------------
139
Jamie Gennis28378392011-10-12 17:39:00 -0700140void Composer::closeGlobalTransactionImpl(bool synchronous) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700141 sp<ISurfaceComposer> sm(getComposerService());
142
143 Vector<ComposerState> transaction;
Jamie Gennisb8d69a52011-10-10 15:48:06 -0700144 int orientation;
Jamie Gennis28378392011-10-12 17:39:00 -0700145 uint32_t flags = 0;
Mathias Agopian698c0872011-06-28 19:09:31 -0700146
147 { // scope for the lock
148 Mutex::Autolock _l(mLock);
149 transaction = mStates;
150 mStates.clear();
Jamie Gennisb8d69a52011-10-10 15:48:06 -0700151
152 orientation = mOrientation;
153 mOrientation = ISurfaceComposer::eOrientationUnchanged;
Jamie Gennis28378392011-10-12 17:39:00 -0700154
155 if (synchronous || mForceSynchronous) {
156 flags |= ISurfaceComposer::eSynchronous;
157 }
158 mForceSynchronous = false;
Mathias Agopian698c0872011-06-28 19:09:31 -0700159 }
160
Jamie Gennis28378392011-10-12 17:39:00 -0700161 sm->setTransactionState(transaction, orientation, flags);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800162}
163
Mathias Agopian698c0872011-06-28 19:09:31 -0700164layer_state_t* Composer::getLayerStateLocked(
165 const sp<SurfaceComposerClient>& client, SurfaceID id) {
166
167 ComposerState s;
168 s.client = client->mClient;
169 s.state.surface = id;
170
171 ssize_t index = mStates.indexOf(s);
172 if (index < 0) {
173 // we don't have it, add an initialized layer_state to our list
174 index = mStates.add(s);
175 }
176
177 ComposerState* const out = mStates.editArray();
178 return &(out[index].state);
179}
180
181status_t Composer::setPosition(const sp<SurfaceComposerClient>& client,
Mathias Agopian41b6aab2011-08-30 18:51:54 -0700182 SurfaceID id, float x, float y) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700183 Mutex::Autolock _l(mLock);
184 layer_state_t* s = getLayerStateLocked(client, id);
185 if (!s)
186 return BAD_INDEX;
187 s->what |= ISurfaceComposer::ePositionChanged;
188 s->x = x;
189 s->y = y;
190 return NO_ERROR;
191}
192
193status_t Composer::setSize(const sp<SurfaceComposerClient>& client,
194 SurfaceID id, uint32_t w, uint32_t h) {
195 Mutex::Autolock _l(mLock);
196 layer_state_t* s = getLayerStateLocked(client, id);
197 if (!s)
198 return BAD_INDEX;
199 s->what |= ISurfaceComposer::eSizeChanged;
200 s->w = w;
201 s->h = h;
Jamie Gennis28378392011-10-12 17:39:00 -0700202
203 // Resizing a surface makes the transaction synchronous.
204 mForceSynchronous = true;
205
Mathias Agopian698c0872011-06-28 19:09:31 -0700206 return NO_ERROR;
207}
208
209status_t Composer::setLayer(const sp<SurfaceComposerClient>& client,
210 SurfaceID id, int32_t z) {
211 Mutex::Autolock _l(mLock);
212 layer_state_t* s = getLayerStateLocked(client, id);
213 if (!s)
214 return BAD_INDEX;
215 s->what |= ISurfaceComposer::eLayerChanged;
216 s->z = z;
217 return NO_ERROR;
218}
219
220status_t Composer::setFlags(const sp<SurfaceComposerClient>& client,
221 SurfaceID id, uint32_t flags,
222 uint32_t mask) {
223 Mutex::Autolock _l(mLock);
224 layer_state_t* s = getLayerStateLocked(client, id);
225 if (!s)
226 return BAD_INDEX;
227 s->what |= ISurfaceComposer::eVisibilityChanged;
228 s->flags &= ~mask;
229 s->flags |= (flags & mask);
230 s->mask |= mask;
231 return NO_ERROR;
232}
233
234status_t Composer::setTransparentRegionHint(
235 const sp<SurfaceComposerClient>& client, SurfaceID id,
236 const Region& transparentRegion) {
237 Mutex::Autolock _l(mLock);
238 layer_state_t* s = getLayerStateLocked(client, id);
239 if (!s)
240 return BAD_INDEX;
241 s->what |= ISurfaceComposer::eTransparentRegionChanged;
242 s->transparentRegion = transparentRegion;
243 return NO_ERROR;
244}
245
246status_t Composer::setAlpha(const sp<SurfaceComposerClient>& client,
247 SurfaceID id, float alpha) {
248 Mutex::Autolock _l(mLock);
249 layer_state_t* s = getLayerStateLocked(client, id);
250 if (!s)
251 return BAD_INDEX;
252 s->what |= ISurfaceComposer::eAlphaChanged;
253 s->alpha = alpha;
254 return NO_ERROR;
255}
256
257status_t Composer::setMatrix(const sp<SurfaceComposerClient>& client,
258 SurfaceID id, float dsdx, float dtdx,
259 float dsdy, float dtdy) {
260 Mutex::Autolock _l(mLock);
261 layer_state_t* s = getLayerStateLocked(client, id);
262 if (!s)
263 return BAD_INDEX;
264 s->what |= ISurfaceComposer::eMatrixChanged;
265 layer_state_t::matrix22_t matrix;
266 matrix.dsdx = dsdx;
267 matrix.dtdx = dtdx;
268 matrix.dsdy = dsdy;
269 matrix.dtdy = dtdy;
270 s->matrix = matrix;
271 return NO_ERROR;
272}
273
274status_t Composer::setFreezeTint(const sp<SurfaceComposerClient>& client,
275 SurfaceID id, uint32_t tint) {
276 Mutex::Autolock _l(mLock);
277 layer_state_t* s = getLayerStateLocked(client, id);
278 if (!s)
279 return BAD_INDEX;
280 s->what |= ISurfaceComposer::eFreezeTintChanged;
281 s->tint = tint;
282 return NO_ERROR;
283}
284
Jamie Gennisb8d69a52011-10-10 15:48:06 -0700285status_t Composer::setOrientation(int orientation) {
286 Mutex::Autolock _l(mLock);
287 mOrientation = orientation;
Jamie Gennis28378392011-10-12 17:39:00 -0700288
289 // Changing the orientation makes the transaction synchronous.
290 mForceSynchronous = true;
291
Jamie Gennisb8d69a52011-10-10 15:48:06 -0700292 return NO_ERROR;
293}
294
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700295status_t Composer::setCrop(const sp<SurfaceComposerClient>& client,
296 SurfaceID id, const Rect& crop) {
297 Mutex::Autolock _l(mLock);
298 layer_state_t* s = getLayerStateLocked(client, id);
299 if (!s)
300 return BAD_INDEX;
301 s->what |= ISurfaceComposer::eCropChanged;
302 s->crop = crop;
303 return NO_ERROR;
304}
305
Mathias Agopian698c0872011-06-28 19:09:31 -0700306// ---------------------------------------------------------------------------
307
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800308SurfaceComposerClient::SurfaceComposerClient()
Mathias Agopian698c0872011-06-28 19:09:31 -0700309 : mStatus(NO_INIT), mComposer(Composer::getInstance())
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800310{
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800311}
312
Mathias Agopian698c0872011-06-28 19:09:31 -0700313void SurfaceComposerClient::onFirstRef() {
Mathias Agopiand4784a32010-05-27 19:41:15 -0700314 sp<ISurfaceComposer> sm(getComposerService());
315 if (sm != 0) {
Mathias Agopian7e27f052010-05-28 14:22:23 -0700316 sp<ISurfaceComposerClient> conn = sm->createConnection();
Mathias Agopiand4784a32010-05-27 19:41:15 -0700317 if (conn != 0) {
318 mClient = conn;
Mathias Agopiand4784a32010-05-27 19:41:15 -0700319 mStatus = NO_ERROR;
320 }
321 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800322}
323
Mathias Agopian698c0872011-06-28 19:09:31 -0700324SurfaceComposerClient::~SurfaceComposerClient() {
Mathias Agopian631f3582010-05-25 17:51:34 -0700325 dispose();
326}
Mathias Agopiandd3423c2009-09-23 15:44:05 -0700327
Mathias Agopian698c0872011-06-28 19:09:31 -0700328status_t SurfaceComposerClient::initCheck() const {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800329 return mStatus;
330}
331
Mathias Agopian698c0872011-06-28 19:09:31 -0700332sp<IBinder> SurfaceComposerClient::connection() const {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800333 return (mClient != 0) ? mClient->asBinder() : 0;
334}
335
Mathias Agopiand4784a32010-05-27 19:41:15 -0700336status_t SurfaceComposerClient::linkToComposerDeath(
337 const sp<IBinder::DeathRecipient>& recipient,
Mathias Agopian698c0872011-06-28 19:09:31 -0700338 void* cookie, uint32_t flags) {
Mathias Agopiand4784a32010-05-27 19:41:15 -0700339 sp<ISurfaceComposer> sm(getComposerService());
340 return sm->asBinder()->linkToDeath(recipient, cookie, flags);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800341}
342
Mathias Agopian698c0872011-06-28 19:09:31 -0700343void SurfaceComposerClient::dispose() {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800344 // this can be called more than once.
Mathias Agopian7e27f052010-05-28 14:22:23 -0700345 sp<ISurfaceComposerClient> client;
Mathias Agopiand4784a32010-05-27 19:41:15 -0700346 Mutex::Autolock _lm(mLock);
347 if (mClient != 0) {
Mathias Agopiand4784a32010-05-27 19:41:15 -0700348 client = mClient; // hold ref while lock is held
349 mClient.clear();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800350 }
Mathias Agopiand4784a32010-05-27 19:41:15 -0700351 mStatus = NO_INIT;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800352}
353
Mathias Agopian698c0872011-06-28 19:09:31 -0700354sp<SurfaceControl> SurfaceComposerClient::createSurface(
355 DisplayID display,
356 uint32_t w,
357 uint32_t h,
358 PixelFormat format,
359 uint32_t flags)
360{
361 String8 name;
362 const size_t SIZE = 128;
363 char buffer[SIZE];
364 snprintf(buffer, SIZE, "<pid_%d>", getpid());
365 name.append(buffer);
366
367 return SurfaceComposerClient::createSurface(name, display,
368 w, h, format, flags);
369}
370
371sp<SurfaceControl> SurfaceComposerClient::createSurface(
372 const String8& name,
373 DisplayID display,
374 uint32_t w,
375 uint32_t h,
376 PixelFormat format,
377 uint32_t flags)
378{
379 sp<SurfaceControl> result;
380 if (mStatus == NO_ERROR) {
381 ISurfaceComposerClient::surface_data_t data;
382 sp<ISurface> surface = mClient->createSurface(&data, name,
383 display, w, h, format, flags);
384 if (surface != 0) {
Mathias Agopianc10d9d92011-07-20 16:46:11 -0700385 result = new SurfaceControl(this, surface, data);
Mathias Agopian698c0872011-06-28 19:09:31 -0700386 }
387 }
388 return result;
389}
390
391status_t SurfaceComposerClient::destroySurface(SurfaceID sid) {
392 if (mStatus != NO_ERROR)
393 return mStatus;
394 status_t err = mClient->destroySurface(sid);
395 return err;
396}
397
398inline Composer& SurfaceComposerClient::getComposer() {
399 return mComposer;
400}
401
402// ----------------------------------------------------------------------------
403
404void SurfaceComposerClient::openGlobalTransaction() {
405 // Currently a no-op
406}
407
Jamie Gennis28378392011-10-12 17:39:00 -0700408void SurfaceComposerClient::closeGlobalTransaction(bool synchronous) {
409 Composer::closeGlobalTransaction(synchronous);
Mathias Agopian698c0872011-06-28 19:09:31 -0700410}
411
412// ----------------------------------------------------------------------------
413
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700414status_t SurfaceComposerClient::setCrop(SurfaceID id, const Rect& crop) {
415 return getComposer().setCrop(this, id, crop);
416}
417
Mathias Agopian698c0872011-06-28 19:09:31 -0700418status_t SurfaceComposerClient::setFreezeTint(SurfaceID id, uint32_t tint) {
419 return getComposer().setFreezeTint(this, id, tint);
420}
421
Mathias Agopian41b6aab2011-08-30 18:51:54 -0700422status_t SurfaceComposerClient::setPosition(SurfaceID id, float x, float y) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700423 return getComposer().setPosition(this, id, x, y);
424}
425
426status_t SurfaceComposerClient::setSize(SurfaceID id, uint32_t w, uint32_t h) {
427 return getComposer().setSize(this, id, w, h);
428}
429
430status_t SurfaceComposerClient::setLayer(SurfaceID id, int32_t z) {
431 return getComposer().setLayer(this, id, z);
432}
433
434status_t SurfaceComposerClient::hide(SurfaceID id) {
435 return getComposer().setFlags(this, id,
436 ISurfaceComposer::eLayerHidden,
437 ISurfaceComposer::eLayerHidden);
438}
439
440status_t SurfaceComposerClient::show(SurfaceID id, int32_t) {
441 return getComposer().setFlags(this, id,
442 0,
443 ISurfaceComposer::eLayerHidden);
444}
445
446status_t SurfaceComposerClient::freeze(SurfaceID id) {
447 return getComposer().setFlags(this, id,
448 ISurfaceComposer::eLayerFrozen,
449 ISurfaceComposer::eLayerFrozen);
450}
451
452status_t SurfaceComposerClient::unfreeze(SurfaceID id) {
453 return getComposer().setFlags(this, id,
454 0,
455 ISurfaceComposer::eLayerFrozen);
456}
457
458status_t SurfaceComposerClient::setFlags(SurfaceID id, uint32_t flags,
459 uint32_t mask) {
460 return getComposer().setFlags(this, id, flags, mask);
461}
462
463status_t SurfaceComposerClient::setTransparentRegionHint(SurfaceID id,
464 const Region& transparentRegion) {
465 return getComposer().setTransparentRegionHint(this, id, transparentRegion);
466}
467
468status_t SurfaceComposerClient::setAlpha(SurfaceID id, float alpha) {
469 return getComposer().setAlpha(this, id, alpha);
470}
471
472status_t SurfaceComposerClient::setMatrix(SurfaceID id, float dsdx, float dtdx,
473 float dsdy, float dtdy) {
474 return getComposer().setMatrix(this, id, dsdx, dtdx, dsdy, dtdy);
475}
476
Jamie Gennisb8d69a52011-10-10 15:48:06 -0700477status_t SurfaceComposerClient::setOrientation(DisplayID dpy,
478 int orientation, uint32_t flags)
479{
480 return Composer::getInstance().setOrientation(orientation);
481}
482
Mathias Agopian698c0872011-06-28 19:09:31 -0700483// ----------------------------------------------------------------------------
484
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800485status_t SurfaceComposerClient::getDisplayInfo(
486 DisplayID dpy, DisplayInfo* info)
487{
Mathias Agopiana67932f2011-04-20 14:20:59 -0700488 if (uint32_t(dpy)>=NUM_DISPLAY_MAX)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800489 return BAD_VALUE;
490
491 volatile surface_flinger_cblk_t const * cblk = get_cblk();
492 volatile display_cblk_t const * dcblk = cblk->displays + dpy;
493
494 info->w = dcblk->w;
495 info->h = dcblk->h;
496 info->orientation = dcblk->orientation;
497 info->xdpi = dcblk->xdpi;
498 info->ydpi = dcblk->ydpi;
499 info->fps = dcblk->fps;
500 info->density = dcblk->density;
501 return getPixelFormatInfo(dcblk->format, &(info->pixelFormatInfo));
502}
503
504ssize_t SurfaceComposerClient::getDisplayWidth(DisplayID dpy)
505{
Mathias Agopiana67932f2011-04-20 14:20:59 -0700506 if (uint32_t(dpy)>=NUM_DISPLAY_MAX)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800507 return BAD_VALUE;
508 volatile surface_flinger_cblk_t const * cblk = get_cblk();
509 volatile display_cblk_t const * dcblk = cblk->displays + dpy;
510 return dcblk->w;
511}
512
513ssize_t SurfaceComposerClient::getDisplayHeight(DisplayID dpy)
514{
Mathias Agopiana67932f2011-04-20 14:20:59 -0700515 if (uint32_t(dpy)>=NUM_DISPLAY_MAX)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800516 return BAD_VALUE;
517 volatile surface_flinger_cblk_t const * cblk = get_cblk();
518 volatile display_cblk_t const * dcblk = cblk->displays + dpy;
519 return dcblk->h;
520}
521
522ssize_t SurfaceComposerClient::getDisplayOrientation(DisplayID dpy)
523{
Mathias Agopiana67932f2011-04-20 14:20:59 -0700524 if (uint32_t(dpy)>=NUM_DISPLAY_MAX)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800525 return BAD_VALUE;
526 volatile surface_flinger_cblk_t const * cblk = get_cblk();
527 volatile display_cblk_t const * dcblk = cblk->displays + dpy;
528 return dcblk->orientation;
529}
530
531ssize_t SurfaceComposerClient::getNumberOfDisplays()
532{
533 volatile surface_flinger_cblk_t const * cblk = get_cblk();
534 uint32_t connected = cblk->connected;
535 int n = 0;
536 while (connected) {
537 if (connected&1) n++;
538 connected >>= 1;
539 }
540 return n;
541}
542
Mathias Agopian698c0872011-06-28 19:09:31 -0700543// ----------------------------------------------------------------------------
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800544
545status_t SurfaceComposerClient::freezeDisplay(DisplayID dpy, uint32_t flags)
546{
Jamie Gennisb8d69a52011-10-10 15:48:06 -0700547 // This has been made a no-op because it can cause Gralloc buffer deadlocks.
548 return NO_ERROR;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800549}
550
551status_t SurfaceComposerClient::unfreezeDisplay(DisplayID dpy, uint32_t flags)
552{
Jamie Gennisb8d69a52011-10-10 15:48:06 -0700553 // This has been made a no-op because it can cause Gralloc buffer deadlocks.
554 return NO_ERROR;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800555}
556
Mathias Agopiand4784a32010-05-27 19:41:15 -0700557// ----------------------------------------------------------------------------
Mathias Agopian74c40c02010-09-29 13:02:36 -0700558
559ScreenshotClient::ScreenshotClient()
560 : mWidth(0), mHeight(0), mFormat(PIXEL_FORMAT_NONE) {
561}
562
563status_t ScreenshotClient::update() {
564 sp<ISurfaceComposer> s(ComposerService::getComposerService());
565 if (s == NULL) return NO_INIT;
566 mHeap = 0;
567 return s->captureScreen(0, &mHeap,
Mathias Agopianbf2c6a62010-12-10 16:22:31 -0800568 &mWidth, &mHeight, &mFormat, 0, 0,
569 0, -1UL);
Mathias Agopian74c40c02010-09-29 13:02:36 -0700570}
571
572status_t ScreenshotClient::update(uint32_t reqWidth, uint32_t reqHeight) {
573 sp<ISurfaceComposer> s(ComposerService::getComposerService());
574 if (s == NULL) return NO_INIT;
575 mHeap = 0;
576 return s->captureScreen(0, &mHeap,
Mathias Agopianbf2c6a62010-12-10 16:22:31 -0800577 &mWidth, &mHeight, &mFormat, reqWidth, reqHeight,
578 0, -1UL);
579}
580
581status_t ScreenshotClient::update(uint32_t reqWidth, uint32_t reqHeight,
582 uint32_t minLayerZ, uint32_t maxLayerZ) {
583 sp<ISurfaceComposer> s(ComposerService::getComposerService());
584 if (s == NULL) return NO_INIT;
585 mHeap = 0;
586 return s->captureScreen(0, &mHeap,
587 &mWidth, &mHeight, &mFormat, reqWidth, reqHeight,
588 minLayerZ, maxLayerZ);
Mathias Agopian74c40c02010-09-29 13:02:36 -0700589}
590
591void ScreenshotClient::release() {
592 mHeap = 0;
593}
594
595void const* ScreenshotClient::getPixels() const {
596 return mHeap->getBase();
597}
598
599uint32_t ScreenshotClient::getWidth() const {
600 return mWidth;
601}
602
603uint32_t ScreenshotClient::getHeight() const {
604 return mHeight;
605}
606
607PixelFormat ScreenshotClient::getFormat() const {
608 return mFormat;
609}
610
611uint32_t ScreenshotClient::getStride() const {
612 return mWidth;
613}
614
615size_t ScreenshotClient::getSize() const {
616 return mHeap->getSize();
617}
618
619// ----------------------------------------------------------------------------
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800620}; // namespace android