blob: 4930e336fbbd9b82f355221b5605e3c4e603c633 [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 Agopian87855782012-07-24 21:41:09 -0700127 status_t setLayerStack(const sp<SurfaceComposerClient>& client,
128 SurfaceID id, uint32_t layerStack);
Mathias Agopian698c0872011-06-28 19:09:31 -0700129
Jamie Gennis28378392011-10-12 17:39:00 -0700130 static void closeGlobalTransaction(bool synchronous) {
131 Composer::getInstance().closeGlobalTransactionImpl(synchronous);
Mathias Agopiand4784a32010-05-27 19:41:15 -0700132 }
133};
134
135ANDROID_SINGLETON_STATIC_INSTANCE(Composer);
136
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800137// ---------------------------------------------------------------------------
138
Jamie Gennis28378392011-10-12 17:39:00 -0700139void Composer::closeGlobalTransactionImpl(bool synchronous) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700140 sp<ISurfaceComposer> sm(getComposerService());
141
142 Vector<ComposerState> transaction;
Mathias Agopian8b33f032012-07-24 20:43:54 -0700143 Vector<DisplayState> displayTransaction;
Jamie Gennis28378392011-10-12 17:39:00 -0700144 uint32_t flags = 0;
Mathias Agopian698c0872011-06-28 19:09:31 -0700145
146 { // scope for the lock
147 Mutex::Autolock _l(mLock);
148 transaction = mStates;
149 mStates.clear();
Jamie Gennisb8d69a52011-10-10 15:48:06 -0700150
Mathias Agopian8b33f032012-07-24 20:43:54 -0700151 // FIXME: this should be the displays transaction state here
152 DisplayState item;
153 item.orientation = mOrientation;
154 displayTransaction.add(item);
155
Jamie Gennisb8d69a52011-10-10 15:48:06 -0700156 mOrientation = ISurfaceComposer::eOrientationUnchanged;
Jamie Gennis28378392011-10-12 17:39:00 -0700157
158 if (synchronous || mForceSynchronous) {
159 flags |= ISurfaceComposer::eSynchronous;
160 }
161 mForceSynchronous = false;
Mathias Agopian698c0872011-06-28 19:09:31 -0700162 }
163
Mathias Agopian8b33f032012-07-24 20:43:54 -0700164 sm->setTransactionState(transaction, displayTransaction, flags);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800165}
166
Mathias Agopian698c0872011-06-28 19:09:31 -0700167layer_state_t* Composer::getLayerStateLocked(
168 const sp<SurfaceComposerClient>& client, SurfaceID id) {
169
170 ComposerState s;
171 s.client = client->mClient;
172 s.state.surface = id;
173
174 ssize_t index = mStates.indexOf(s);
175 if (index < 0) {
176 // we don't have it, add an initialized layer_state to our list
177 index = mStates.add(s);
178 }
179
180 ComposerState* const out = mStates.editArray();
181 return &(out[index].state);
182}
183
184status_t Composer::setPosition(const sp<SurfaceComposerClient>& client,
Mathias Agopian41b6aab2011-08-30 18:51:54 -0700185 SurfaceID id, float x, float y) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700186 Mutex::Autolock _l(mLock);
187 layer_state_t* s = getLayerStateLocked(client, id);
188 if (!s)
189 return BAD_INDEX;
190 s->what |= ISurfaceComposer::ePositionChanged;
191 s->x = x;
192 s->y = y;
193 return NO_ERROR;
194}
195
196status_t Composer::setSize(const sp<SurfaceComposerClient>& client,
197 SurfaceID id, uint32_t w, uint32_t h) {
198 Mutex::Autolock _l(mLock);
199 layer_state_t* s = getLayerStateLocked(client, id);
200 if (!s)
201 return BAD_INDEX;
202 s->what |= ISurfaceComposer::eSizeChanged;
203 s->w = w;
204 s->h = h;
Jamie Gennis28378392011-10-12 17:39:00 -0700205
206 // Resizing a surface makes the transaction synchronous.
207 mForceSynchronous = true;
208
Mathias Agopian698c0872011-06-28 19:09:31 -0700209 return NO_ERROR;
210}
211
212status_t Composer::setLayer(const sp<SurfaceComposerClient>& client,
213 SurfaceID id, int32_t z) {
214 Mutex::Autolock _l(mLock);
215 layer_state_t* s = getLayerStateLocked(client, id);
216 if (!s)
217 return BAD_INDEX;
218 s->what |= ISurfaceComposer::eLayerChanged;
219 s->z = z;
220 return NO_ERROR;
221}
222
223status_t Composer::setFlags(const sp<SurfaceComposerClient>& client,
224 SurfaceID id, uint32_t flags,
225 uint32_t mask) {
226 Mutex::Autolock _l(mLock);
227 layer_state_t* s = getLayerStateLocked(client, id);
228 if (!s)
229 return BAD_INDEX;
230 s->what |= ISurfaceComposer::eVisibilityChanged;
231 s->flags &= ~mask;
232 s->flags |= (flags & mask);
233 s->mask |= mask;
234 return NO_ERROR;
235}
236
237status_t Composer::setTransparentRegionHint(
238 const sp<SurfaceComposerClient>& client, SurfaceID id,
239 const Region& transparentRegion) {
240 Mutex::Autolock _l(mLock);
241 layer_state_t* s = getLayerStateLocked(client, id);
242 if (!s)
243 return BAD_INDEX;
244 s->what |= ISurfaceComposer::eTransparentRegionChanged;
245 s->transparentRegion = transparentRegion;
246 return NO_ERROR;
247}
248
249status_t Composer::setAlpha(const sp<SurfaceComposerClient>& client,
250 SurfaceID id, float alpha) {
251 Mutex::Autolock _l(mLock);
252 layer_state_t* s = getLayerStateLocked(client, id);
253 if (!s)
254 return BAD_INDEX;
255 s->what |= ISurfaceComposer::eAlphaChanged;
256 s->alpha = alpha;
257 return NO_ERROR;
258}
259
Mathias Agopian87855782012-07-24 21:41:09 -0700260status_t Composer::setLayerStack(const sp<SurfaceComposerClient>& client,
261 SurfaceID id, uint32_t layerStack) {
262 Mutex::Autolock _l(mLock);
263 layer_state_t* s = getLayerStateLocked(client, id);
264 if (!s)
265 return BAD_INDEX;
266 s->what |= ISurfaceComposer::eLayerStackChanged;
267 s->layerStack = layerStack;
268 return NO_ERROR;
269}
270
Mathias Agopian698c0872011-06-28 19:09:31 -0700271status_t Composer::setMatrix(const sp<SurfaceComposerClient>& client,
272 SurfaceID id, float dsdx, float dtdx,
273 float dsdy, float dtdy) {
274 Mutex::Autolock _l(mLock);
275 layer_state_t* s = getLayerStateLocked(client, id);
276 if (!s)
277 return BAD_INDEX;
278 s->what |= ISurfaceComposer::eMatrixChanged;
279 layer_state_t::matrix22_t matrix;
280 matrix.dsdx = dsdx;
281 matrix.dtdx = dtdx;
282 matrix.dsdy = dsdy;
283 matrix.dtdy = dtdy;
284 s->matrix = matrix;
285 return NO_ERROR;
286}
287
Jamie Gennisb8d69a52011-10-10 15:48:06 -0700288status_t Composer::setOrientation(int orientation) {
289 Mutex::Autolock _l(mLock);
290 mOrientation = orientation;
Jamie Gennis28378392011-10-12 17:39:00 -0700291
292 // Changing the orientation makes the transaction synchronous.
293 mForceSynchronous = true;
294
Jamie Gennisb8d69a52011-10-10 15:48:06 -0700295 return NO_ERROR;
296}
297
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700298status_t Composer::setCrop(const sp<SurfaceComposerClient>& client,
299 SurfaceID id, const Rect& crop) {
300 Mutex::Autolock _l(mLock);
301 layer_state_t* s = getLayerStateLocked(client, id);
302 if (!s)
303 return BAD_INDEX;
304 s->what |= ISurfaceComposer::eCropChanged;
305 s->crop = crop;
306 return NO_ERROR;
307}
308
Mathias Agopian698c0872011-06-28 19:09:31 -0700309// ---------------------------------------------------------------------------
310
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800311SurfaceComposerClient::SurfaceComposerClient()
Mathias Agopian698c0872011-06-28 19:09:31 -0700312 : mStatus(NO_INIT), mComposer(Composer::getInstance())
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800313{
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800314}
315
Mathias Agopian698c0872011-06-28 19:09:31 -0700316void SurfaceComposerClient::onFirstRef() {
Mathias Agopiand4784a32010-05-27 19:41:15 -0700317 sp<ISurfaceComposer> sm(getComposerService());
318 if (sm != 0) {
Mathias Agopian7e27f052010-05-28 14:22:23 -0700319 sp<ISurfaceComposerClient> conn = sm->createConnection();
Mathias Agopiand4784a32010-05-27 19:41:15 -0700320 if (conn != 0) {
321 mClient = conn;
Mathias Agopiand4784a32010-05-27 19:41:15 -0700322 mStatus = NO_ERROR;
323 }
324 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800325}
326
Mathias Agopian698c0872011-06-28 19:09:31 -0700327SurfaceComposerClient::~SurfaceComposerClient() {
Mathias Agopian631f3582010-05-25 17:51:34 -0700328 dispose();
329}
Mathias Agopiandd3423c2009-09-23 15:44:05 -0700330
Mathias Agopian698c0872011-06-28 19:09:31 -0700331status_t SurfaceComposerClient::initCheck() const {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800332 return mStatus;
333}
334
Mathias Agopian698c0872011-06-28 19:09:31 -0700335sp<IBinder> SurfaceComposerClient::connection() const {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800336 return (mClient != 0) ? mClient->asBinder() : 0;
337}
338
Mathias Agopiand4784a32010-05-27 19:41:15 -0700339status_t SurfaceComposerClient::linkToComposerDeath(
340 const sp<IBinder::DeathRecipient>& recipient,
Mathias Agopian698c0872011-06-28 19:09:31 -0700341 void* cookie, uint32_t flags) {
Mathias Agopiand4784a32010-05-27 19:41:15 -0700342 sp<ISurfaceComposer> sm(getComposerService());
343 return sm->asBinder()->linkToDeath(recipient, cookie, flags);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800344}
345
Mathias Agopian698c0872011-06-28 19:09:31 -0700346void SurfaceComposerClient::dispose() {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800347 // this can be called more than once.
Mathias Agopian7e27f052010-05-28 14:22:23 -0700348 sp<ISurfaceComposerClient> client;
Mathias Agopiand4784a32010-05-27 19:41:15 -0700349 Mutex::Autolock _lm(mLock);
350 if (mClient != 0) {
Mathias Agopiand4784a32010-05-27 19:41:15 -0700351 client = mClient; // hold ref while lock is held
352 mClient.clear();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800353 }
Mathias Agopiand4784a32010-05-27 19:41:15 -0700354 mStatus = NO_INIT;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800355}
356
Mathias Agopian698c0872011-06-28 19:09:31 -0700357sp<SurfaceControl> SurfaceComposerClient::createSurface(
358 DisplayID display,
359 uint32_t w,
360 uint32_t h,
361 PixelFormat format,
362 uint32_t flags)
363{
364 String8 name;
365 const size_t SIZE = 128;
366 char buffer[SIZE];
367 snprintf(buffer, SIZE, "<pid_%d>", getpid());
368 name.append(buffer);
369
370 return SurfaceComposerClient::createSurface(name, display,
371 w, h, format, flags);
372}
373
374sp<SurfaceControl> SurfaceComposerClient::createSurface(
375 const String8& name,
376 DisplayID display,
377 uint32_t w,
378 uint32_t h,
379 PixelFormat format,
380 uint32_t flags)
381{
382 sp<SurfaceControl> result;
383 if (mStatus == NO_ERROR) {
384 ISurfaceComposerClient::surface_data_t data;
385 sp<ISurface> surface = mClient->createSurface(&data, name,
386 display, w, h, format, flags);
387 if (surface != 0) {
Mathias Agopianc10d9d92011-07-20 16:46:11 -0700388 result = new SurfaceControl(this, surface, data);
Mathias Agopian698c0872011-06-28 19:09:31 -0700389 }
390 }
391 return result;
392}
393
394status_t SurfaceComposerClient::destroySurface(SurfaceID sid) {
395 if (mStatus != NO_ERROR)
396 return mStatus;
397 status_t err = mClient->destroySurface(sid);
398 return err;
399}
400
401inline Composer& SurfaceComposerClient::getComposer() {
402 return mComposer;
403}
404
405// ----------------------------------------------------------------------------
406
407void SurfaceComposerClient::openGlobalTransaction() {
408 // Currently a no-op
409}
410
Jamie Gennis28378392011-10-12 17:39:00 -0700411void SurfaceComposerClient::closeGlobalTransaction(bool synchronous) {
412 Composer::closeGlobalTransaction(synchronous);
Mathias Agopian698c0872011-06-28 19:09:31 -0700413}
414
415// ----------------------------------------------------------------------------
416
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700417status_t SurfaceComposerClient::setCrop(SurfaceID id, const Rect& crop) {
418 return getComposer().setCrop(this, id, crop);
419}
420
Mathias Agopian41b6aab2011-08-30 18:51:54 -0700421status_t SurfaceComposerClient::setPosition(SurfaceID id, float x, float y) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700422 return getComposer().setPosition(this, id, x, y);
423}
424
425status_t SurfaceComposerClient::setSize(SurfaceID id, uint32_t w, uint32_t h) {
426 return getComposer().setSize(this, id, w, h);
427}
428
429status_t SurfaceComposerClient::setLayer(SurfaceID id, int32_t z) {
430 return getComposer().setLayer(this, id, z);
431}
432
433status_t SurfaceComposerClient::hide(SurfaceID id) {
434 return getComposer().setFlags(this, id,
435 ISurfaceComposer::eLayerHidden,
436 ISurfaceComposer::eLayerHidden);
437}
438
439status_t SurfaceComposerClient::show(SurfaceID id, int32_t) {
440 return getComposer().setFlags(this, id,
441 0,
442 ISurfaceComposer::eLayerHidden);
443}
444
Mathias Agopian698c0872011-06-28 19:09:31 -0700445status_t SurfaceComposerClient::setFlags(SurfaceID id, uint32_t flags,
446 uint32_t mask) {
447 return getComposer().setFlags(this, id, flags, mask);
448}
449
450status_t SurfaceComposerClient::setTransparentRegionHint(SurfaceID id,
451 const Region& transparentRegion) {
452 return getComposer().setTransparentRegionHint(this, id, transparentRegion);
453}
454
455status_t SurfaceComposerClient::setAlpha(SurfaceID id, float alpha) {
456 return getComposer().setAlpha(this, id, alpha);
457}
458
Mathias Agopian87855782012-07-24 21:41:09 -0700459status_t SurfaceComposerClient::setLayerStack(SurfaceID id, uint32_t layerStack) {
460 return getComposer().setLayerStack(this, id, layerStack);
461}
462
Mathias Agopian698c0872011-06-28 19:09:31 -0700463status_t SurfaceComposerClient::setMatrix(SurfaceID id, float dsdx, float dtdx,
464 float dsdy, float dtdy) {
465 return getComposer().setMatrix(this, id, dsdx, dtdx, dsdy, dtdy);
466}
467
Jamie Gennisb8d69a52011-10-10 15:48:06 -0700468status_t SurfaceComposerClient::setOrientation(DisplayID dpy,
469 int orientation, uint32_t flags)
470{
471 return Composer::getInstance().setOrientation(orientation);
472}
473
Mathias Agopian698c0872011-06-28 19:09:31 -0700474// ----------------------------------------------------------------------------
475
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800476status_t SurfaceComposerClient::getDisplayInfo(
477 DisplayID dpy, DisplayInfo* info)
478{
Mathias Agopiana67932f2011-04-20 14:20:59 -0700479 if (uint32_t(dpy)>=NUM_DISPLAY_MAX)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800480 return BAD_VALUE;
481
482 volatile surface_flinger_cblk_t const * cblk = get_cblk();
483 volatile display_cblk_t const * dcblk = cblk->displays + dpy;
484
485 info->w = dcblk->w;
486 info->h = dcblk->h;
487 info->orientation = dcblk->orientation;
488 info->xdpi = dcblk->xdpi;
489 info->ydpi = dcblk->ydpi;
490 info->fps = dcblk->fps;
491 info->density = dcblk->density;
492 return getPixelFormatInfo(dcblk->format, &(info->pixelFormatInfo));
493}
494
495ssize_t SurfaceComposerClient::getDisplayWidth(DisplayID dpy)
496{
Mathias Agopiana67932f2011-04-20 14:20:59 -0700497 if (uint32_t(dpy)>=NUM_DISPLAY_MAX)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800498 return BAD_VALUE;
499 volatile surface_flinger_cblk_t const * cblk = get_cblk();
500 volatile display_cblk_t const * dcblk = cblk->displays + dpy;
501 return dcblk->w;
502}
503
504ssize_t SurfaceComposerClient::getDisplayHeight(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->h;
511}
512
513ssize_t SurfaceComposerClient::getDisplayOrientation(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->orientation;
520}
521
522ssize_t SurfaceComposerClient::getNumberOfDisplays()
523{
524 volatile surface_flinger_cblk_t const * cblk = get_cblk();
525 uint32_t connected = cblk->connected;
526 int n = 0;
527 while (connected) {
528 if (connected&1) n++;
529 connected >>= 1;
530 }
531 return n;
532}
533
Mathias Agopian698c0872011-06-28 19:09:31 -0700534// ----------------------------------------------------------------------------
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800535
Mathias Agopian74c40c02010-09-29 13:02:36 -0700536ScreenshotClient::ScreenshotClient()
537 : mWidth(0), mHeight(0), mFormat(PIXEL_FORMAT_NONE) {
538}
539
540status_t ScreenshotClient::update() {
541 sp<ISurfaceComposer> s(ComposerService::getComposerService());
542 if (s == NULL) return NO_INIT;
543 mHeap = 0;
544 return s->captureScreen(0, &mHeap,
Mathias Agopianbf2c6a62010-12-10 16:22:31 -0800545 &mWidth, &mHeight, &mFormat, 0, 0,
546 0, -1UL);
Mathias Agopian74c40c02010-09-29 13:02:36 -0700547}
548
549status_t ScreenshotClient::update(uint32_t reqWidth, uint32_t reqHeight) {
550 sp<ISurfaceComposer> s(ComposerService::getComposerService());
551 if (s == NULL) return NO_INIT;
552 mHeap = 0;
553 return s->captureScreen(0, &mHeap,
Mathias Agopianbf2c6a62010-12-10 16:22:31 -0800554 &mWidth, &mHeight, &mFormat, reqWidth, reqHeight,
555 0, -1UL);
556}
557
558status_t ScreenshotClient::update(uint32_t reqWidth, uint32_t reqHeight,
559 uint32_t minLayerZ, uint32_t maxLayerZ) {
560 sp<ISurfaceComposer> s(ComposerService::getComposerService());
561 if (s == NULL) return NO_INIT;
562 mHeap = 0;
563 return s->captureScreen(0, &mHeap,
564 &mWidth, &mHeight, &mFormat, reqWidth, reqHeight,
565 minLayerZ, maxLayerZ);
Mathias Agopian74c40c02010-09-29 13:02:36 -0700566}
567
568void ScreenshotClient::release() {
569 mHeap = 0;
570}
571
572void const* ScreenshotClient::getPixels() const {
573 return mHeap->getBase();
574}
575
576uint32_t ScreenshotClient::getWidth() const {
577 return mWidth;
578}
579
580uint32_t ScreenshotClient::getHeight() const {
581 return mHeight;
582}
583
584PixelFormat ScreenshotClient::getFormat() const {
585 return mFormat;
586}
587
588uint32_t ScreenshotClient::getStride() const {
589 return mWidth;
590}
591
592size_t ScreenshotClient::getSize() const {
593 return mHeap->getSize();
594}
595
596// ----------------------------------------------------------------------------
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800597}; // namespace android