blob: b1bd78bc7e232e344a2b126237fd11041e7e49a7 [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);
Jamie Gennisb8d69a52011-10-10 15:48:06 -0700124 status_t setOrientation(int orientation);
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700125 status_t setCrop(const sp<SurfaceComposerClient>& client, SurfaceID id,
126 const Rect& crop);
Mathias Agopian698c0872011-06-28 19:09:31 -0700127
Jamie Gennis28378392011-10-12 17:39:00 -0700128 static void closeGlobalTransaction(bool synchronous) {
129 Composer::getInstance().closeGlobalTransactionImpl(synchronous);
Mathias Agopiand4784a32010-05-27 19:41:15 -0700130 }
131};
132
133ANDROID_SINGLETON_STATIC_INSTANCE(Composer);
134
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800135// ---------------------------------------------------------------------------
136
Jamie Gennis28378392011-10-12 17:39:00 -0700137void Composer::closeGlobalTransactionImpl(bool synchronous) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700138 sp<ISurfaceComposer> sm(getComposerService());
139
140 Vector<ComposerState> transaction;
Jamie Gennisb8d69a52011-10-10 15:48:06 -0700141 int orientation;
Jamie Gennis28378392011-10-12 17:39:00 -0700142 uint32_t flags = 0;
Mathias Agopian698c0872011-06-28 19:09:31 -0700143
144 { // scope for the lock
145 Mutex::Autolock _l(mLock);
146 transaction = mStates;
147 mStates.clear();
Jamie Gennisb8d69a52011-10-10 15:48:06 -0700148
149 orientation = mOrientation;
150 mOrientation = ISurfaceComposer::eOrientationUnchanged;
Jamie Gennis28378392011-10-12 17:39:00 -0700151
152 if (synchronous || mForceSynchronous) {
153 flags |= ISurfaceComposer::eSynchronous;
154 }
155 mForceSynchronous = false;
Mathias Agopian698c0872011-06-28 19:09:31 -0700156 }
157
Jamie Gennis28378392011-10-12 17:39:00 -0700158 sm->setTransactionState(transaction, orientation, flags);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800159}
160
Mathias Agopian698c0872011-06-28 19:09:31 -0700161layer_state_t* Composer::getLayerStateLocked(
162 const sp<SurfaceComposerClient>& client, SurfaceID id) {
163
164 ComposerState s;
165 s.client = client->mClient;
166 s.state.surface = id;
167
168 ssize_t index = mStates.indexOf(s);
169 if (index < 0) {
170 // we don't have it, add an initialized layer_state to our list
171 index = mStates.add(s);
172 }
173
174 ComposerState* const out = mStates.editArray();
175 return &(out[index].state);
176}
177
178status_t Composer::setPosition(const sp<SurfaceComposerClient>& client,
Mathias Agopian41b6aab2011-08-30 18:51:54 -0700179 SurfaceID id, float x, float y) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700180 Mutex::Autolock _l(mLock);
181 layer_state_t* s = getLayerStateLocked(client, id);
182 if (!s)
183 return BAD_INDEX;
184 s->what |= ISurfaceComposer::ePositionChanged;
185 s->x = x;
186 s->y = y;
187 return NO_ERROR;
188}
189
190status_t Composer::setSize(const sp<SurfaceComposerClient>& client,
191 SurfaceID id, uint32_t w, uint32_t h) {
192 Mutex::Autolock _l(mLock);
193 layer_state_t* s = getLayerStateLocked(client, id);
194 if (!s)
195 return BAD_INDEX;
196 s->what |= ISurfaceComposer::eSizeChanged;
197 s->w = w;
198 s->h = h;
Jamie Gennis28378392011-10-12 17:39:00 -0700199
200 // Resizing a surface makes the transaction synchronous.
201 mForceSynchronous = true;
202
Mathias Agopian698c0872011-06-28 19:09:31 -0700203 return NO_ERROR;
204}
205
206status_t Composer::setLayer(const sp<SurfaceComposerClient>& client,
207 SurfaceID id, int32_t z) {
208 Mutex::Autolock _l(mLock);
209 layer_state_t* s = getLayerStateLocked(client, id);
210 if (!s)
211 return BAD_INDEX;
212 s->what |= ISurfaceComposer::eLayerChanged;
213 s->z = z;
214 return NO_ERROR;
215}
216
217status_t Composer::setFlags(const sp<SurfaceComposerClient>& client,
218 SurfaceID id, uint32_t flags,
219 uint32_t mask) {
220 Mutex::Autolock _l(mLock);
221 layer_state_t* s = getLayerStateLocked(client, id);
222 if (!s)
223 return BAD_INDEX;
224 s->what |= ISurfaceComposer::eVisibilityChanged;
225 s->flags &= ~mask;
226 s->flags |= (flags & mask);
227 s->mask |= mask;
228 return NO_ERROR;
229}
230
231status_t Composer::setTransparentRegionHint(
232 const sp<SurfaceComposerClient>& client, SurfaceID id,
233 const Region& transparentRegion) {
234 Mutex::Autolock _l(mLock);
235 layer_state_t* s = getLayerStateLocked(client, id);
236 if (!s)
237 return BAD_INDEX;
238 s->what |= ISurfaceComposer::eTransparentRegionChanged;
239 s->transparentRegion = transparentRegion;
240 return NO_ERROR;
241}
242
243status_t Composer::setAlpha(const sp<SurfaceComposerClient>& client,
244 SurfaceID id, float alpha) {
245 Mutex::Autolock _l(mLock);
246 layer_state_t* s = getLayerStateLocked(client, id);
247 if (!s)
248 return BAD_INDEX;
249 s->what |= ISurfaceComposer::eAlphaChanged;
250 s->alpha = alpha;
251 return NO_ERROR;
252}
253
254status_t Composer::setMatrix(const sp<SurfaceComposerClient>& client,
255 SurfaceID id, float dsdx, float dtdx,
256 float dsdy, float dtdy) {
257 Mutex::Autolock _l(mLock);
258 layer_state_t* s = getLayerStateLocked(client, id);
259 if (!s)
260 return BAD_INDEX;
261 s->what |= ISurfaceComposer::eMatrixChanged;
262 layer_state_t::matrix22_t matrix;
263 matrix.dsdx = dsdx;
264 matrix.dtdx = dtdx;
265 matrix.dsdy = dsdy;
266 matrix.dtdy = dtdy;
267 s->matrix = matrix;
268 return NO_ERROR;
269}
270
Jamie Gennisb8d69a52011-10-10 15:48:06 -0700271status_t Composer::setOrientation(int orientation) {
272 Mutex::Autolock _l(mLock);
273 mOrientation = orientation;
Jamie Gennis28378392011-10-12 17:39:00 -0700274
275 // Changing the orientation makes the transaction synchronous.
276 mForceSynchronous = true;
277
Jamie Gennisb8d69a52011-10-10 15:48:06 -0700278 return NO_ERROR;
279}
280
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700281status_t Composer::setCrop(const sp<SurfaceComposerClient>& client,
282 SurfaceID id, const Rect& crop) {
283 Mutex::Autolock _l(mLock);
284 layer_state_t* s = getLayerStateLocked(client, id);
285 if (!s)
286 return BAD_INDEX;
287 s->what |= ISurfaceComposer::eCropChanged;
288 s->crop = crop;
289 return NO_ERROR;
290}
291
Mathias Agopian698c0872011-06-28 19:09:31 -0700292// ---------------------------------------------------------------------------
293
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800294SurfaceComposerClient::SurfaceComposerClient()
Mathias Agopian698c0872011-06-28 19:09:31 -0700295 : mStatus(NO_INIT), mComposer(Composer::getInstance())
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800296{
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800297}
298
Mathias Agopian698c0872011-06-28 19:09:31 -0700299void SurfaceComposerClient::onFirstRef() {
Mathias Agopiand4784a32010-05-27 19:41:15 -0700300 sp<ISurfaceComposer> sm(getComposerService());
301 if (sm != 0) {
Mathias Agopian7e27f052010-05-28 14:22:23 -0700302 sp<ISurfaceComposerClient> conn = sm->createConnection();
Mathias Agopiand4784a32010-05-27 19:41:15 -0700303 if (conn != 0) {
304 mClient = conn;
Mathias Agopiand4784a32010-05-27 19:41:15 -0700305 mStatus = NO_ERROR;
306 }
307 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800308}
309
Mathias Agopian698c0872011-06-28 19:09:31 -0700310SurfaceComposerClient::~SurfaceComposerClient() {
Mathias Agopian631f3582010-05-25 17:51:34 -0700311 dispose();
312}
Mathias Agopiandd3423c2009-09-23 15:44:05 -0700313
Mathias Agopian698c0872011-06-28 19:09:31 -0700314status_t SurfaceComposerClient::initCheck() const {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800315 return mStatus;
316}
317
Mathias Agopian698c0872011-06-28 19:09:31 -0700318sp<IBinder> SurfaceComposerClient::connection() const {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800319 return (mClient != 0) ? mClient->asBinder() : 0;
320}
321
Mathias Agopiand4784a32010-05-27 19:41:15 -0700322status_t SurfaceComposerClient::linkToComposerDeath(
323 const sp<IBinder::DeathRecipient>& recipient,
Mathias Agopian698c0872011-06-28 19:09:31 -0700324 void* cookie, uint32_t flags) {
Mathias Agopiand4784a32010-05-27 19:41:15 -0700325 sp<ISurfaceComposer> sm(getComposerService());
326 return sm->asBinder()->linkToDeath(recipient, cookie, flags);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800327}
328
Mathias Agopian698c0872011-06-28 19:09:31 -0700329void SurfaceComposerClient::dispose() {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800330 // this can be called more than once.
Mathias Agopian7e27f052010-05-28 14:22:23 -0700331 sp<ISurfaceComposerClient> client;
Mathias Agopiand4784a32010-05-27 19:41:15 -0700332 Mutex::Autolock _lm(mLock);
333 if (mClient != 0) {
Mathias Agopiand4784a32010-05-27 19:41:15 -0700334 client = mClient; // hold ref while lock is held
335 mClient.clear();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800336 }
Mathias Agopiand4784a32010-05-27 19:41:15 -0700337 mStatus = NO_INIT;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800338}
339
Mathias Agopian698c0872011-06-28 19:09:31 -0700340sp<SurfaceControl> SurfaceComposerClient::createSurface(
341 DisplayID display,
342 uint32_t w,
343 uint32_t h,
344 PixelFormat format,
345 uint32_t flags)
346{
347 String8 name;
348 const size_t SIZE = 128;
349 char buffer[SIZE];
350 snprintf(buffer, SIZE, "<pid_%d>", getpid());
351 name.append(buffer);
352
353 return SurfaceComposerClient::createSurface(name, display,
354 w, h, format, flags);
355}
356
357sp<SurfaceControl> SurfaceComposerClient::createSurface(
358 const String8& name,
359 DisplayID display,
360 uint32_t w,
361 uint32_t h,
362 PixelFormat format,
363 uint32_t flags)
364{
365 sp<SurfaceControl> result;
366 if (mStatus == NO_ERROR) {
367 ISurfaceComposerClient::surface_data_t data;
368 sp<ISurface> surface = mClient->createSurface(&data, name,
369 display, w, h, format, flags);
370 if (surface != 0) {
Mathias Agopianc10d9d92011-07-20 16:46:11 -0700371 result = new SurfaceControl(this, surface, data);
Mathias Agopian698c0872011-06-28 19:09:31 -0700372 }
373 }
374 return result;
375}
376
377status_t SurfaceComposerClient::destroySurface(SurfaceID sid) {
378 if (mStatus != NO_ERROR)
379 return mStatus;
380 status_t err = mClient->destroySurface(sid);
381 return err;
382}
383
384inline Composer& SurfaceComposerClient::getComposer() {
385 return mComposer;
386}
387
388// ----------------------------------------------------------------------------
389
390void SurfaceComposerClient::openGlobalTransaction() {
391 // Currently a no-op
392}
393
Jamie Gennis28378392011-10-12 17:39:00 -0700394void SurfaceComposerClient::closeGlobalTransaction(bool synchronous) {
395 Composer::closeGlobalTransaction(synchronous);
Mathias Agopian698c0872011-06-28 19:09:31 -0700396}
397
398// ----------------------------------------------------------------------------
399
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700400status_t SurfaceComposerClient::setCrop(SurfaceID id, const Rect& crop) {
401 return getComposer().setCrop(this, id, crop);
402}
403
Mathias Agopian41b6aab2011-08-30 18:51:54 -0700404status_t SurfaceComposerClient::setPosition(SurfaceID id, float x, float y) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700405 return getComposer().setPosition(this, id, x, y);
406}
407
408status_t SurfaceComposerClient::setSize(SurfaceID id, uint32_t w, uint32_t h) {
409 return getComposer().setSize(this, id, w, h);
410}
411
412status_t SurfaceComposerClient::setLayer(SurfaceID id, int32_t z) {
413 return getComposer().setLayer(this, id, z);
414}
415
416status_t SurfaceComposerClient::hide(SurfaceID id) {
417 return getComposer().setFlags(this, id,
418 ISurfaceComposer::eLayerHidden,
419 ISurfaceComposer::eLayerHidden);
420}
421
422status_t SurfaceComposerClient::show(SurfaceID id, int32_t) {
423 return getComposer().setFlags(this, id,
424 0,
425 ISurfaceComposer::eLayerHidden);
426}
427
Mathias Agopian698c0872011-06-28 19:09:31 -0700428status_t SurfaceComposerClient::setFlags(SurfaceID id, uint32_t flags,
429 uint32_t mask) {
430 return getComposer().setFlags(this, id, flags, mask);
431}
432
433status_t SurfaceComposerClient::setTransparentRegionHint(SurfaceID id,
434 const Region& transparentRegion) {
435 return getComposer().setTransparentRegionHint(this, id, transparentRegion);
436}
437
438status_t SurfaceComposerClient::setAlpha(SurfaceID id, float alpha) {
439 return getComposer().setAlpha(this, id, alpha);
440}
441
442status_t SurfaceComposerClient::setMatrix(SurfaceID id, float dsdx, float dtdx,
443 float dsdy, float dtdy) {
444 return getComposer().setMatrix(this, id, dsdx, dtdx, dsdy, dtdy);
445}
446
Jamie Gennisb8d69a52011-10-10 15:48:06 -0700447status_t SurfaceComposerClient::setOrientation(DisplayID dpy,
448 int orientation, uint32_t flags)
449{
450 return Composer::getInstance().setOrientation(orientation);
451}
452
Mathias Agopian698c0872011-06-28 19:09:31 -0700453// ----------------------------------------------------------------------------
454
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800455status_t SurfaceComposerClient::getDisplayInfo(
456 DisplayID dpy, DisplayInfo* info)
457{
Mathias Agopiana67932f2011-04-20 14:20:59 -0700458 if (uint32_t(dpy)>=NUM_DISPLAY_MAX)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800459 return BAD_VALUE;
460
461 volatile surface_flinger_cblk_t const * cblk = get_cblk();
462 volatile display_cblk_t const * dcblk = cblk->displays + dpy;
463
464 info->w = dcblk->w;
465 info->h = dcblk->h;
466 info->orientation = dcblk->orientation;
467 info->xdpi = dcblk->xdpi;
468 info->ydpi = dcblk->ydpi;
469 info->fps = dcblk->fps;
470 info->density = dcblk->density;
471 return getPixelFormatInfo(dcblk->format, &(info->pixelFormatInfo));
472}
473
474ssize_t SurfaceComposerClient::getDisplayWidth(DisplayID dpy)
475{
Mathias Agopiana67932f2011-04-20 14:20:59 -0700476 if (uint32_t(dpy)>=NUM_DISPLAY_MAX)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800477 return BAD_VALUE;
478 volatile surface_flinger_cblk_t const * cblk = get_cblk();
479 volatile display_cblk_t const * dcblk = cblk->displays + dpy;
480 return dcblk->w;
481}
482
483ssize_t SurfaceComposerClient::getDisplayHeight(DisplayID dpy)
484{
Mathias Agopiana67932f2011-04-20 14:20:59 -0700485 if (uint32_t(dpy)>=NUM_DISPLAY_MAX)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800486 return BAD_VALUE;
487 volatile surface_flinger_cblk_t const * cblk = get_cblk();
488 volatile display_cblk_t const * dcblk = cblk->displays + dpy;
489 return dcblk->h;
490}
491
492ssize_t SurfaceComposerClient::getDisplayOrientation(DisplayID dpy)
493{
Mathias Agopiana67932f2011-04-20 14:20:59 -0700494 if (uint32_t(dpy)>=NUM_DISPLAY_MAX)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800495 return BAD_VALUE;
496 volatile surface_flinger_cblk_t const * cblk = get_cblk();
497 volatile display_cblk_t const * dcblk = cblk->displays + dpy;
498 return dcblk->orientation;
499}
500
501ssize_t SurfaceComposerClient::getNumberOfDisplays()
502{
503 volatile surface_flinger_cblk_t const * cblk = get_cblk();
504 uint32_t connected = cblk->connected;
505 int n = 0;
506 while (connected) {
507 if (connected&1) n++;
508 connected >>= 1;
509 }
510 return n;
511}
512
Mathias Agopian698c0872011-06-28 19:09:31 -0700513// ----------------------------------------------------------------------------
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800514
Mathias Agopian74c40c02010-09-29 13:02:36 -0700515ScreenshotClient::ScreenshotClient()
516 : mWidth(0), mHeight(0), mFormat(PIXEL_FORMAT_NONE) {
517}
518
519status_t ScreenshotClient::update() {
520 sp<ISurfaceComposer> s(ComposerService::getComposerService());
521 if (s == NULL) return NO_INIT;
522 mHeap = 0;
523 return s->captureScreen(0, &mHeap,
Mathias Agopianbf2c6a62010-12-10 16:22:31 -0800524 &mWidth, &mHeight, &mFormat, 0, 0,
525 0, -1UL);
Mathias Agopian74c40c02010-09-29 13:02:36 -0700526}
527
528status_t ScreenshotClient::update(uint32_t reqWidth, uint32_t reqHeight) {
529 sp<ISurfaceComposer> s(ComposerService::getComposerService());
530 if (s == NULL) return NO_INIT;
531 mHeap = 0;
532 return s->captureScreen(0, &mHeap,
Mathias Agopianbf2c6a62010-12-10 16:22:31 -0800533 &mWidth, &mHeight, &mFormat, reqWidth, reqHeight,
534 0, -1UL);
535}
536
537status_t ScreenshotClient::update(uint32_t reqWidth, uint32_t reqHeight,
538 uint32_t minLayerZ, uint32_t maxLayerZ) {
539 sp<ISurfaceComposer> s(ComposerService::getComposerService());
540 if (s == NULL) return NO_INIT;
541 mHeap = 0;
542 return s->captureScreen(0, &mHeap,
543 &mWidth, &mHeight, &mFormat, reqWidth, reqHeight,
544 minLayerZ, maxLayerZ);
Mathias Agopian74c40c02010-09-29 13:02:36 -0700545}
546
547void ScreenshotClient::release() {
548 mHeap = 0;
549}
550
551void const* ScreenshotClient::getPixels() const {
552 return mHeap->getBase();
553}
554
555uint32_t ScreenshotClient::getWidth() const {
556 return mWidth;
557}
558
559uint32_t ScreenshotClient::getHeight() const {
560 return mHeight;
561}
562
563PixelFormat ScreenshotClient::getFormat() const {
564 return mFormat;
565}
566
567uint32_t ScreenshotClient::getStride() const {
568 return mWidth;
569}
570
571size_t ScreenshotClient::getSize() const {
572 return mHeap->getSize();
573}
574
575// ----------------------------------------------------------------------------
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800576}; // namespace android