blob: 8aa0c55169134288717d265e0b5c3ce01c5acbad [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;
Mathias Agopian8b33f032012-07-24 20:43:54 -0700141 Vector<DisplayState> displayTransaction;
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
Mathias Agopian8b33f032012-07-24 20:43:54 -0700149 // FIXME: this should be the displays transaction state here
150 DisplayState item;
151 item.orientation = mOrientation;
152 displayTransaction.add(item);
153
Jamie Gennisb8d69a52011-10-10 15:48:06 -0700154 mOrientation = ISurfaceComposer::eOrientationUnchanged;
Jamie Gennis28378392011-10-12 17:39:00 -0700155
156 if (synchronous || mForceSynchronous) {
157 flags |= ISurfaceComposer::eSynchronous;
158 }
159 mForceSynchronous = false;
Mathias Agopian698c0872011-06-28 19:09:31 -0700160 }
161
Mathias Agopian8b33f032012-07-24 20:43:54 -0700162 sm->setTransactionState(transaction, displayTransaction, flags);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800163}
164
Mathias Agopian698c0872011-06-28 19:09:31 -0700165layer_state_t* Composer::getLayerStateLocked(
166 const sp<SurfaceComposerClient>& client, SurfaceID id) {
167
168 ComposerState s;
169 s.client = client->mClient;
170 s.state.surface = id;
171
172 ssize_t index = mStates.indexOf(s);
173 if (index < 0) {
174 // we don't have it, add an initialized layer_state to our list
175 index = mStates.add(s);
176 }
177
178 ComposerState* const out = mStates.editArray();
179 return &(out[index].state);
180}
181
182status_t Composer::setPosition(const sp<SurfaceComposerClient>& client,
Mathias Agopian41b6aab2011-08-30 18:51:54 -0700183 SurfaceID id, float x, float y) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700184 Mutex::Autolock _l(mLock);
185 layer_state_t* s = getLayerStateLocked(client, id);
186 if (!s)
187 return BAD_INDEX;
188 s->what |= ISurfaceComposer::ePositionChanged;
189 s->x = x;
190 s->y = y;
191 return NO_ERROR;
192}
193
194status_t Composer::setSize(const sp<SurfaceComposerClient>& client,
195 SurfaceID id, uint32_t w, uint32_t h) {
196 Mutex::Autolock _l(mLock);
197 layer_state_t* s = getLayerStateLocked(client, id);
198 if (!s)
199 return BAD_INDEX;
200 s->what |= ISurfaceComposer::eSizeChanged;
201 s->w = w;
202 s->h = h;
Jamie Gennis28378392011-10-12 17:39:00 -0700203
204 // Resizing a surface makes the transaction synchronous.
205 mForceSynchronous = true;
206
Mathias Agopian698c0872011-06-28 19:09:31 -0700207 return NO_ERROR;
208}
209
210status_t Composer::setLayer(const sp<SurfaceComposerClient>& client,
211 SurfaceID id, int32_t z) {
212 Mutex::Autolock _l(mLock);
213 layer_state_t* s = getLayerStateLocked(client, id);
214 if (!s)
215 return BAD_INDEX;
216 s->what |= ISurfaceComposer::eLayerChanged;
217 s->z = z;
218 return NO_ERROR;
219}
220
221status_t Composer::setFlags(const sp<SurfaceComposerClient>& client,
222 SurfaceID id, uint32_t flags,
223 uint32_t mask) {
224 Mutex::Autolock _l(mLock);
225 layer_state_t* s = getLayerStateLocked(client, id);
226 if (!s)
227 return BAD_INDEX;
228 s->what |= ISurfaceComposer::eVisibilityChanged;
229 s->flags &= ~mask;
230 s->flags |= (flags & mask);
231 s->mask |= mask;
232 return NO_ERROR;
233}
234
235status_t Composer::setTransparentRegionHint(
236 const sp<SurfaceComposerClient>& client, SurfaceID id,
237 const Region& transparentRegion) {
238 Mutex::Autolock _l(mLock);
239 layer_state_t* s = getLayerStateLocked(client, id);
240 if (!s)
241 return BAD_INDEX;
242 s->what |= ISurfaceComposer::eTransparentRegionChanged;
243 s->transparentRegion = transparentRegion;
244 return NO_ERROR;
245}
246
247status_t Composer::setAlpha(const sp<SurfaceComposerClient>& client,
248 SurfaceID id, float alpha) {
249 Mutex::Autolock _l(mLock);
250 layer_state_t* s = getLayerStateLocked(client, id);
251 if (!s)
252 return BAD_INDEX;
253 s->what |= ISurfaceComposer::eAlphaChanged;
254 s->alpha = alpha;
255 return NO_ERROR;
256}
257
258status_t Composer::setMatrix(const sp<SurfaceComposerClient>& client,
259 SurfaceID id, float dsdx, float dtdx,
260 float dsdy, float dtdy) {
261 Mutex::Autolock _l(mLock);
262 layer_state_t* s = getLayerStateLocked(client, id);
263 if (!s)
264 return BAD_INDEX;
265 s->what |= ISurfaceComposer::eMatrixChanged;
266 layer_state_t::matrix22_t matrix;
267 matrix.dsdx = dsdx;
268 matrix.dtdx = dtdx;
269 matrix.dsdy = dsdy;
270 matrix.dtdy = dtdy;
271 s->matrix = matrix;
272 return NO_ERROR;
273}
274
Jamie Gennisb8d69a52011-10-10 15:48:06 -0700275status_t Composer::setOrientation(int orientation) {
276 Mutex::Autolock _l(mLock);
277 mOrientation = orientation;
Jamie Gennis28378392011-10-12 17:39:00 -0700278
279 // Changing the orientation makes the transaction synchronous.
280 mForceSynchronous = true;
281
Jamie Gennisb8d69a52011-10-10 15:48:06 -0700282 return NO_ERROR;
283}
284
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700285status_t Composer::setCrop(const sp<SurfaceComposerClient>& client,
286 SurfaceID id, const Rect& crop) {
287 Mutex::Autolock _l(mLock);
288 layer_state_t* s = getLayerStateLocked(client, id);
289 if (!s)
290 return BAD_INDEX;
291 s->what |= ISurfaceComposer::eCropChanged;
292 s->crop = crop;
293 return NO_ERROR;
294}
295
Mathias Agopian698c0872011-06-28 19:09:31 -0700296// ---------------------------------------------------------------------------
297
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800298SurfaceComposerClient::SurfaceComposerClient()
Mathias Agopian698c0872011-06-28 19:09:31 -0700299 : mStatus(NO_INIT), mComposer(Composer::getInstance())
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800300{
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800301}
302
Mathias Agopian698c0872011-06-28 19:09:31 -0700303void SurfaceComposerClient::onFirstRef() {
Mathias Agopiand4784a32010-05-27 19:41:15 -0700304 sp<ISurfaceComposer> sm(getComposerService());
305 if (sm != 0) {
Mathias Agopian7e27f052010-05-28 14:22:23 -0700306 sp<ISurfaceComposerClient> conn = sm->createConnection();
Mathias Agopiand4784a32010-05-27 19:41:15 -0700307 if (conn != 0) {
308 mClient = conn;
Mathias Agopiand4784a32010-05-27 19:41:15 -0700309 mStatus = NO_ERROR;
310 }
311 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800312}
313
Mathias Agopian698c0872011-06-28 19:09:31 -0700314SurfaceComposerClient::~SurfaceComposerClient() {
Mathias Agopian631f3582010-05-25 17:51:34 -0700315 dispose();
316}
Mathias Agopiandd3423c2009-09-23 15:44:05 -0700317
Mathias Agopian698c0872011-06-28 19:09:31 -0700318status_t SurfaceComposerClient::initCheck() const {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800319 return mStatus;
320}
321
Mathias Agopian698c0872011-06-28 19:09:31 -0700322sp<IBinder> SurfaceComposerClient::connection() const {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800323 return (mClient != 0) ? mClient->asBinder() : 0;
324}
325
Mathias Agopiand4784a32010-05-27 19:41:15 -0700326status_t SurfaceComposerClient::linkToComposerDeath(
327 const sp<IBinder::DeathRecipient>& recipient,
Mathias Agopian698c0872011-06-28 19:09:31 -0700328 void* cookie, uint32_t flags) {
Mathias Agopiand4784a32010-05-27 19:41:15 -0700329 sp<ISurfaceComposer> sm(getComposerService());
330 return sm->asBinder()->linkToDeath(recipient, cookie, flags);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800331}
332
Mathias Agopian698c0872011-06-28 19:09:31 -0700333void SurfaceComposerClient::dispose() {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800334 // this can be called more than once.
Mathias Agopian7e27f052010-05-28 14:22:23 -0700335 sp<ISurfaceComposerClient> client;
Mathias Agopiand4784a32010-05-27 19:41:15 -0700336 Mutex::Autolock _lm(mLock);
337 if (mClient != 0) {
Mathias Agopiand4784a32010-05-27 19:41:15 -0700338 client = mClient; // hold ref while lock is held
339 mClient.clear();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800340 }
Mathias Agopiand4784a32010-05-27 19:41:15 -0700341 mStatus = NO_INIT;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800342}
343
Mathias Agopian698c0872011-06-28 19:09:31 -0700344sp<SurfaceControl> SurfaceComposerClient::createSurface(
345 DisplayID display,
346 uint32_t w,
347 uint32_t h,
348 PixelFormat format,
349 uint32_t flags)
350{
351 String8 name;
352 const size_t SIZE = 128;
353 char buffer[SIZE];
354 snprintf(buffer, SIZE, "<pid_%d>", getpid());
355 name.append(buffer);
356
357 return SurfaceComposerClient::createSurface(name, display,
358 w, h, format, flags);
359}
360
361sp<SurfaceControl> SurfaceComposerClient::createSurface(
362 const String8& name,
363 DisplayID display,
364 uint32_t w,
365 uint32_t h,
366 PixelFormat format,
367 uint32_t flags)
368{
369 sp<SurfaceControl> result;
370 if (mStatus == NO_ERROR) {
371 ISurfaceComposerClient::surface_data_t data;
372 sp<ISurface> surface = mClient->createSurface(&data, name,
373 display, w, h, format, flags);
374 if (surface != 0) {
Mathias Agopianc10d9d92011-07-20 16:46:11 -0700375 result = new SurfaceControl(this, surface, data);
Mathias Agopian698c0872011-06-28 19:09:31 -0700376 }
377 }
378 return result;
379}
380
381status_t SurfaceComposerClient::destroySurface(SurfaceID sid) {
382 if (mStatus != NO_ERROR)
383 return mStatus;
384 status_t err = mClient->destroySurface(sid);
385 return err;
386}
387
388inline Composer& SurfaceComposerClient::getComposer() {
389 return mComposer;
390}
391
392// ----------------------------------------------------------------------------
393
394void SurfaceComposerClient::openGlobalTransaction() {
395 // Currently a no-op
396}
397
Jamie Gennis28378392011-10-12 17:39:00 -0700398void SurfaceComposerClient::closeGlobalTransaction(bool synchronous) {
399 Composer::closeGlobalTransaction(synchronous);
Mathias Agopian698c0872011-06-28 19:09:31 -0700400}
401
402// ----------------------------------------------------------------------------
403
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700404status_t SurfaceComposerClient::setCrop(SurfaceID id, const Rect& crop) {
405 return getComposer().setCrop(this, id, crop);
406}
407
Mathias Agopian41b6aab2011-08-30 18:51:54 -0700408status_t SurfaceComposerClient::setPosition(SurfaceID id, float x, float y) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700409 return getComposer().setPosition(this, id, x, y);
410}
411
412status_t SurfaceComposerClient::setSize(SurfaceID id, uint32_t w, uint32_t h) {
413 return getComposer().setSize(this, id, w, h);
414}
415
416status_t SurfaceComposerClient::setLayer(SurfaceID id, int32_t z) {
417 return getComposer().setLayer(this, id, z);
418}
419
420status_t SurfaceComposerClient::hide(SurfaceID id) {
421 return getComposer().setFlags(this, id,
422 ISurfaceComposer::eLayerHidden,
423 ISurfaceComposer::eLayerHidden);
424}
425
426status_t SurfaceComposerClient::show(SurfaceID id, int32_t) {
427 return getComposer().setFlags(this, id,
428 0,
429 ISurfaceComposer::eLayerHidden);
430}
431
Mathias Agopian698c0872011-06-28 19:09:31 -0700432status_t SurfaceComposerClient::setFlags(SurfaceID id, uint32_t flags,
433 uint32_t mask) {
434 return getComposer().setFlags(this, id, flags, mask);
435}
436
437status_t SurfaceComposerClient::setTransparentRegionHint(SurfaceID id,
438 const Region& transparentRegion) {
439 return getComposer().setTransparentRegionHint(this, id, transparentRegion);
440}
441
442status_t SurfaceComposerClient::setAlpha(SurfaceID id, float alpha) {
443 return getComposer().setAlpha(this, id, alpha);
444}
445
446status_t SurfaceComposerClient::setMatrix(SurfaceID id, float dsdx, float dtdx,
447 float dsdy, float dtdy) {
448 return getComposer().setMatrix(this, id, dsdx, dtdx, dsdy, dtdy);
449}
450
Jamie Gennisb8d69a52011-10-10 15:48:06 -0700451status_t SurfaceComposerClient::setOrientation(DisplayID dpy,
452 int orientation, uint32_t flags)
453{
454 return Composer::getInstance().setOrientation(orientation);
455}
456
Mathias Agopian698c0872011-06-28 19:09:31 -0700457// ----------------------------------------------------------------------------
458
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800459status_t SurfaceComposerClient::getDisplayInfo(
460 DisplayID dpy, DisplayInfo* info)
461{
Mathias Agopiana67932f2011-04-20 14:20:59 -0700462 if (uint32_t(dpy)>=NUM_DISPLAY_MAX)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800463 return BAD_VALUE;
464
465 volatile surface_flinger_cblk_t const * cblk = get_cblk();
466 volatile display_cblk_t const * dcblk = cblk->displays + dpy;
467
468 info->w = dcblk->w;
469 info->h = dcblk->h;
470 info->orientation = dcblk->orientation;
471 info->xdpi = dcblk->xdpi;
472 info->ydpi = dcblk->ydpi;
473 info->fps = dcblk->fps;
474 info->density = dcblk->density;
475 return getPixelFormatInfo(dcblk->format, &(info->pixelFormatInfo));
476}
477
478ssize_t SurfaceComposerClient::getDisplayWidth(DisplayID dpy)
479{
Mathias Agopiana67932f2011-04-20 14:20:59 -0700480 if (uint32_t(dpy)>=NUM_DISPLAY_MAX)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800481 return BAD_VALUE;
482 volatile surface_flinger_cblk_t const * cblk = get_cblk();
483 volatile display_cblk_t const * dcblk = cblk->displays + dpy;
484 return dcblk->w;
485}
486
487ssize_t SurfaceComposerClient::getDisplayHeight(DisplayID dpy)
488{
Mathias Agopiana67932f2011-04-20 14:20:59 -0700489 if (uint32_t(dpy)>=NUM_DISPLAY_MAX)
The Android Open Source Projectedbf3b62009-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->h;
494}
495
496ssize_t SurfaceComposerClient::getDisplayOrientation(DisplayID dpy)
497{
Mathias Agopiana67932f2011-04-20 14:20:59 -0700498 if (uint32_t(dpy)>=NUM_DISPLAY_MAX)
The Android Open Source Projectedbf3b62009-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->orientation;
503}
504
505ssize_t SurfaceComposerClient::getNumberOfDisplays()
506{
507 volatile surface_flinger_cblk_t const * cblk = get_cblk();
508 uint32_t connected = cblk->connected;
509 int n = 0;
510 while (connected) {
511 if (connected&1) n++;
512 connected >>= 1;
513 }
514 return n;
515}
516
Mathias Agopian698c0872011-06-28 19:09:31 -0700517// ----------------------------------------------------------------------------
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800518
Mathias Agopian74c40c02010-09-29 13:02:36 -0700519ScreenshotClient::ScreenshotClient()
520 : mWidth(0), mHeight(0), mFormat(PIXEL_FORMAT_NONE) {
521}
522
523status_t ScreenshotClient::update() {
524 sp<ISurfaceComposer> s(ComposerService::getComposerService());
525 if (s == NULL) return NO_INIT;
526 mHeap = 0;
527 return s->captureScreen(0, &mHeap,
Mathias Agopianbf2c6a62010-12-10 16:22:31 -0800528 &mWidth, &mHeight, &mFormat, 0, 0,
529 0, -1UL);
Mathias Agopian74c40c02010-09-29 13:02:36 -0700530}
531
532status_t ScreenshotClient::update(uint32_t reqWidth, uint32_t reqHeight) {
533 sp<ISurfaceComposer> s(ComposerService::getComposerService());
534 if (s == NULL) return NO_INIT;
535 mHeap = 0;
536 return s->captureScreen(0, &mHeap,
Mathias Agopianbf2c6a62010-12-10 16:22:31 -0800537 &mWidth, &mHeight, &mFormat, reqWidth, reqHeight,
538 0, -1UL);
539}
540
541status_t ScreenshotClient::update(uint32_t reqWidth, uint32_t reqHeight,
542 uint32_t minLayerZ, uint32_t maxLayerZ) {
543 sp<ISurfaceComposer> s(ComposerService::getComposerService());
544 if (s == NULL) return NO_INIT;
545 mHeap = 0;
546 return s->captureScreen(0, &mHeap,
547 &mWidth, &mHeight, &mFormat, reqWidth, reqHeight,
548 minLayerZ, maxLayerZ);
Mathias Agopian74c40c02010-09-29 13:02:36 -0700549}
550
551void ScreenshotClient::release() {
552 mHeap = 0;
553}
554
555void const* ScreenshotClient::getPixels() const {
556 return mHeap->getBase();
557}
558
559uint32_t ScreenshotClient::getWidth() const {
560 return mWidth;
561}
562
563uint32_t ScreenshotClient::getHeight() const {
564 return mHeight;
565}
566
567PixelFormat ScreenshotClient::getFormat() const {
568 return mFormat;
569}
570
571uint32_t ScreenshotClient::getStride() const {
572 return mWidth;
573}
574
575size_t ScreenshotClient::getSize() const {
576 return mHeap->getSize();
577}
578
579// ----------------------------------------------------------------------------
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800580}; // namespace android