blob: 00a4bf63cafcc603021ee864060ee23ab1195c15 [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 Agopiana67932f2011-04-20 14:20:59 -070034#include <surfaceflinger/ISurface.h>
Mathias Agopian9cce3252010-02-09 17:46:37 -080035#include <surfaceflinger/ISurfaceComposer.h>
Mathias Agopian7e27f052010-05-28 14:22:23 -070036#include <surfaceflinger/ISurfaceComposerClient.h>
Mathias Agopian9cce3252010-02-09 17:46:37 -080037#include <surfaceflinger/SurfaceComposerClient.h>
38
39#include <private/surfaceflinger/LayerState.h>
40#include <private/surfaceflinger/SharedBufferStack.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080041
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;
94
95 Composer() : Singleton<Composer>() { }
96
97 void closeGlobalTransactionImpl();
98
99 layer_state_t* getLayerStateLocked(
100 const sp<SurfaceComposerClient>& client, SurfaceID id);
101
Mathias Agopiand4784a32010-05-27 19:41:15 -0700102public:
Mathias Agopian698c0872011-06-28 19:09:31 -0700103
104 status_t setPosition(const sp<SurfaceComposerClient>& client, SurfaceID id,
Mathias Agopian41b6aab2011-08-30 18:51:54 -0700105 float x, float y);
Mathias Agopian698c0872011-06-28 19:09:31 -0700106 status_t setSize(const sp<SurfaceComposerClient>& client, SurfaceID id,
107 uint32_t w, uint32_t h);
108 status_t setLayer(const sp<SurfaceComposerClient>& client, SurfaceID id,
109 int32_t z);
110 status_t setFlags(const sp<SurfaceComposerClient>& client, SurfaceID id,
111 uint32_t flags, uint32_t mask);
112 status_t setTransparentRegionHint(
113 const sp<SurfaceComposerClient>& client, SurfaceID id,
114 const Region& transparentRegion);
115 status_t setAlpha(const sp<SurfaceComposerClient>& client, SurfaceID id,
116 float alpha);
117 status_t setMatrix(const sp<SurfaceComposerClient>& client, SurfaceID id,
118 float dsdx, float dtdx, float dsdy, float dtdy);
119 status_t setFreezeTint(
120 const sp<SurfaceComposerClient>& client, SurfaceID id,
121 uint32_t tint);
122
Mathias Agopiand4784a32010-05-27 19:41:15 -0700123 static void closeGlobalTransaction() {
124 Composer::getInstance().closeGlobalTransactionImpl();
125 }
126};
127
128ANDROID_SINGLETON_STATIC_INSTANCE(Composer);
129
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800130// ---------------------------------------------------------------------------
131
Mathias Agopian698c0872011-06-28 19:09:31 -0700132void Composer::closeGlobalTransactionImpl() {
133 sp<ISurfaceComposer> sm(getComposerService());
134
135 Vector<ComposerState> transaction;
136
137 { // scope for the lock
138 Mutex::Autolock _l(mLock);
139 transaction = mStates;
140 mStates.clear();
141 }
142
143 sm->setTransactionState(transaction);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800144}
145
Mathias Agopian698c0872011-06-28 19:09:31 -0700146layer_state_t* Composer::getLayerStateLocked(
147 const sp<SurfaceComposerClient>& client, SurfaceID id) {
148
149 ComposerState s;
150 s.client = client->mClient;
151 s.state.surface = id;
152
153 ssize_t index = mStates.indexOf(s);
154 if (index < 0) {
155 // we don't have it, add an initialized layer_state to our list
156 index = mStates.add(s);
157 }
158
159 ComposerState* const out = mStates.editArray();
160 return &(out[index].state);
161}
162
163status_t Composer::setPosition(const sp<SurfaceComposerClient>& client,
Mathias Agopian41b6aab2011-08-30 18:51:54 -0700164 SurfaceID id, float x, float y) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700165 Mutex::Autolock _l(mLock);
166 layer_state_t* s = getLayerStateLocked(client, id);
167 if (!s)
168 return BAD_INDEX;
169 s->what |= ISurfaceComposer::ePositionChanged;
170 s->x = x;
171 s->y = y;
172 return NO_ERROR;
173}
174
175status_t Composer::setSize(const sp<SurfaceComposerClient>& client,
176 SurfaceID id, uint32_t w, uint32_t h) {
177 Mutex::Autolock _l(mLock);
178 layer_state_t* s = getLayerStateLocked(client, id);
179 if (!s)
180 return BAD_INDEX;
181 s->what |= ISurfaceComposer::eSizeChanged;
182 s->w = w;
183 s->h = h;
184 return NO_ERROR;
185}
186
187status_t Composer::setLayer(const sp<SurfaceComposerClient>& client,
188 SurfaceID id, int32_t z) {
189 Mutex::Autolock _l(mLock);
190 layer_state_t* s = getLayerStateLocked(client, id);
191 if (!s)
192 return BAD_INDEX;
193 s->what |= ISurfaceComposer::eLayerChanged;
194 s->z = z;
195 return NO_ERROR;
196}
197
198status_t Composer::setFlags(const sp<SurfaceComposerClient>& client,
199 SurfaceID id, uint32_t flags,
200 uint32_t mask) {
201 Mutex::Autolock _l(mLock);
202 layer_state_t* s = getLayerStateLocked(client, id);
203 if (!s)
204 return BAD_INDEX;
205 s->what |= ISurfaceComposer::eVisibilityChanged;
206 s->flags &= ~mask;
207 s->flags |= (flags & mask);
208 s->mask |= mask;
209 return NO_ERROR;
210}
211
212status_t Composer::setTransparentRegionHint(
213 const sp<SurfaceComposerClient>& client, SurfaceID id,
214 const Region& transparentRegion) {
215 Mutex::Autolock _l(mLock);
216 layer_state_t* s = getLayerStateLocked(client, id);
217 if (!s)
218 return BAD_INDEX;
219 s->what |= ISurfaceComposer::eTransparentRegionChanged;
220 s->transparentRegion = transparentRegion;
221 return NO_ERROR;
222}
223
224status_t Composer::setAlpha(const sp<SurfaceComposerClient>& client,
225 SurfaceID id, float alpha) {
226 Mutex::Autolock _l(mLock);
227 layer_state_t* s = getLayerStateLocked(client, id);
228 if (!s)
229 return BAD_INDEX;
230 s->what |= ISurfaceComposer::eAlphaChanged;
231 s->alpha = alpha;
232 return NO_ERROR;
233}
234
235status_t Composer::setMatrix(const sp<SurfaceComposerClient>& client,
236 SurfaceID id, float dsdx, float dtdx,
237 float dsdy, float dtdy) {
238 Mutex::Autolock _l(mLock);
239 layer_state_t* s = getLayerStateLocked(client, id);
240 if (!s)
241 return BAD_INDEX;
242 s->what |= ISurfaceComposer::eMatrixChanged;
243 layer_state_t::matrix22_t matrix;
244 matrix.dsdx = dsdx;
245 matrix.dtdx = dtdx;
246 matrix.dsdy = dsdy;
247 matrix.dtdy = dtdy;
248 s->matrix = matrix;
249 return NO_ERROR;
250}
251
252status_t Composer::setFreezeTint(const sp<SurfaceComposerClient>& client,
253 SurfaceID id, uint32_t tint) {
254 Mutex::Autolock _l(mLock);
255 layer_state_t* s = getLayerStateLocked(client, id);
256 if (!s)
257 return BAD_INDEX;
258 s->what |= ISurfaceComposer::eFreezeTintChanged;
259 s->tint = tint;
260 return NO_ERROR;
261}
262
263// ---------------------------------------------------------------------------
264
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800265SurfaceComposerClient::SurfaceComposerClient()
Mathias Agopian698c0872011-06-28 19:09:31 -0700266 : mStatus(NO_INIT), mComposer(Composer::getInstance())
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800267{
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800268}
269
Mathias Agopian698c0872011-06-28 19:09:31 -0700270void SurfaceComposerClient::onFirstRef() {
Mathias Agopiand4784a32010-05-27 19:41:15 -0700271 sp<ISurfaceComposer> sm(getComposerService());
272 if (sm != 0) {
Mathias Agopian7e27f052010-05-28 14:22:23 -0700273 sp<ISurfaceComposerClient> conn = sm->createConnection();
Mathias Agopiand4784a32010-05-27 19:41:15 -0700274 if (conn != 0) {
275 mClient = conn;
Mathias Agopiand4784a32010-05-27 19:41:15 -0700276 mStatus = NO_ERROR;
277 }
278 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800279}
280
Mathias Agopian698c0872011-06-28 19:09:31 -0700281SurfaceComposerClient::~SurfaceComposerClient() {
Mathias Agopian631f3582010-05-25 17:51:34 -0700282 dispose();
283}
Mathias Agopiandd3423c2009-09-23 15:44:05 -0700284
Mathias Agopian698c0872011-06-28 19:09:31 -0700285status_t SurfaceComposerClient::initCheck() const {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800286 return mStatus;
287}
288
Mathias Agopian698c0872011-06-28 19:09:31 -0700289sp<IBinder> SurfaceComposerClient::connection() const {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800290 return (mClient != 0) ? mClient->asBinder() : 0;
291}
292
Mathias Agopiand4784a32010-05-27 19:41:15 -0700293status_t SurfaceComposerClient::linkToComposerDeath(
294 const sp<IBinder::DeathRecipient>& recipient,
Mathias Agopian698c0872011-06-28 19:09:31 -0700295 void* cookie, uint32_t flags) {
Mathias Agopiand4784a32010-05-27 19:41:15 -0700296 sp<ISurfaceComposer> sm(getComposerService());
297 return sm->asBinder()->linkToDeath(recipient, cookie, flags);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800298}
299
Mathias Agopian698c0872011-06-28 19:09:31 -0700300void SurfaceComposerClient::dispose() {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800301 // this can be called more than once.
Mathias Agopian7e27f052010-05-28 14:22:23 -0700302 sp<ISurfaceComposerClient> client;
Mathias Agopiand4784a32010-05-27 19:41:15 -0700303 Mutex::Autolock _lm(mLock);
304 if (mClient != 0) {
Mathias Agopiand4784a32010-05-27 19:41:15 -0700305 client = mClient; // hold ref while lock is held
306 mClient.clear();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800307 }
Mathias Agopiand4784a32010-05-27 19:41:15 -0700308 mStatus = NO_INIT;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800309}
310
Mathias Agopian698c0872011-06-28 19:09:31 -0700311sp<SurfaceControl> SurfaceComposerClient::createSurface(
312 DisplayID display,
313 uint32_t w,
314 uint32_t h,
315 PixelFormat format,
316 uint32_t flags)
317{
318 String8 name;
319 const size_t SIZE = 128;
320 char buffer[SIZE];
321 snprintf(buffer, SIZE, "<pid_%d>", getpid());
322 name.append(buffer);
323
324 return SurfaceComposerClient::createSurface(name, display,
325 w, h, format, flags);
326}
327
328sp<SurfaceControl> SurfaceComposerClient::createSurface(
329 const String8& name,
330 DisplayID display,
331 uint32_t w,
332 uint32_t h,
333 PixelFormat format,
334 uint32_t flags)
335{
336 sp<SurfaceControl> result;
337 if (mStatus == NO_ERROR) {
338 ISurfaceComposerClient::surface_data_t data;
339 sp<ISurface> surface = mClient->createSurface(&data, name,
340 display, w, h, format, flags);
341 if (surface != 0) {
Mathias Agopianc10d9d92011-07-20 16:46:11 -0700342 result = new SurfaceControl(this, surface, data);
Mathias Agopian698c0872011-06-28 19:09:31 -0700343 }
344 }
345 return result;
346}
347
348status_t SurfaceComposerClient::destroySurface(SurfaceID sid) {
349 if (mStatus != NO_ERROR)
350 return mStatus;
351 status_t err = mClient->destroySurface(sid);
352 return err;
353}
354
355inline Composer& SurfaceComposerClient::getComposer() {
356 return mComposer;
357}
358
359// ----------------------------------------------------------------------------
360
361void SurfaceComposerClient::openGlobalTransaction() {
362 // Currently a no-op
363}
364
365void SurfaceComposerClient::closeGlobalTransaction() {
366 Composer::closeGlobalTransaction();
367}
368
369// ----------------------------------------------------------------------------
370
371status_t SurfaceComposerClient::setFreezeTint(SurfaceID id, uint32_t tint) {
372 return getComposer().setFreezeTint(this, id, tint);
373}
374
Mathias Agopian41b6aab2011-08-30 18:51:54 -0700375status_t SurfaceComposerClient::setPosition(SurfaceID id, float x, float y) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700376 return getComposer().setPosition(this, id, x, y);
377}
378
379status_t SurfaceComposerClient::setSize(SurfaceID id, uint32_t w, uint32_t h) {
380 return getComposer().setSize(this, id, w, h);
381}
382
383status_t SurfaceComposerClient::setLayer(SurfaceID id, int32_t z) {
384 return getComposer().setLayer(this, id, z);
385}
386
387status_t SurfaceComposerClient::hide(SurfaceID id) {
388 return getComposer().setFlags(this, id,
389 ISurfaceComposer::eLayerHidden,
390 ISurfaceComposer::eLayerHidden);
391}
392
393status_t SurfaceComposerClient::show(SurfaceID id, int32_t) {
394 return getComposer().setFlags(this, id,
395 0,
396 ISurfaceComposer::eLayerHidden);
397}
398
399status_t SurfaceComposerClient::freeze(SurfaceID id) {
400 return getComposer().setFlags(this, id,
401 ISurfaceComposer::eLayerFrozen,
402 ISurfaceComposer::eLayerFrozen);
403}
404
405status_t SurfaceComposerClient::unfreeze(SurfaceID id) {
406 return getComposer().setFlags(this, id,
407 0,
408 ISurfaceComposer::eLayerFrozen);
409}
410
411status_t SurfaceComposerClient::setFlags(SurfaceID id, uint32_t flags,
412 uint32_t mask) {
413 return getComposer().setFlags(this, id, flags, mask);
414}
415
416status_t SurfaceComposerClient::setTransparentRegionHint(SurfaceID id,
417 const Region& transparentRegion) {
418 return getComposer().setTransparentRegionHint(this, id, transparentRegion);
419}
420
421status_t SurfaceComposerClient::setAlpha(SurfaceID id, float alpha) {
422 return getComposer().setAlpha(this, id, alpha);
423}
424
425status_t SurfaceComposerClient::setMatrix(SurfaceID id, float dsdx, float dtdx,
426 float dsdy, float dtdy) {
427 return getComposer().setMatrix(this, id, dsdx, dtdx, dsdy, dtdy);
428}
429
430// ----------------------------------------------------------------------------
431
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800432status_t SurfaceComposerClient::getDisplayInfo(
433 DisplayID dpy, DisplayInfo* info)
434{
Mathias Agopiana67932f2011-04-20 14:20:59 -0700435 if (uint32_t(dpy)>=NUM_DISPLAY_MAX)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800436 return BAD_VALUE;
437
438 volatile surface_flinger_cblk_t const * cblk = get_cblk();
439 volatile display_cblk_t const * dcblk = cblk->displays + dpy;
440
441 info->w = dcblk->w;
442 info->h = dcblk->h;
443 info->orientation = dcblk->orientation;
444 info->xdpi = dcblk->xdpi;
445 info->ydpi = dcblk->ydpi;
446 info->fps = dcblk->fps;
447 info->density = dcblk->density;
448 return getPixelFormatInfo(dcblk->format, &(info->pixelFormatInfo));
449}
450
451ssize_t SurfaceComposerClient::getDisplayWidth(DisplayID dpy)
452{
Mathias Agopiana67932f2011-04-20 14:20:59 -0700453 if (uint32_t(dpy)>=NUM_DISPLAY_MAX)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800454 return BAD_VALUE;
455 volatile surface_flinger_cblk_t const * cblk = get_cblk();
456 volatile display_cblk_t const * dcblk = cblk->displays + dpy;
457 return dcblk->w;
458}
459
460ssize_t SurfaceComposerClient::getDisplayHeight(DisplayID dpy)
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 volatile surface_flinger_cblk_t const * cblk = get_cblk();
465 volatile display_cblk_t const * dcblk = cblk->displays + dpy;
466 return dcblk->h;
467}
468
469ssize_t SurfaceComposerClient::getDisplayOrientation(DisplayID dpy)
470{
Mathias Agopiana67932f2011-04-20 14:20:59 -0700471 if (uint32_t(dpy)>=NUM_DISPLAY_MAX)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800472 return BAD_VALUE;
473 volatile surface_flinger_cblk_t const * cblk = get_cblk();
474 volatile display_cblk_t const * dcblk = cblk->displays + dpy;
475 return dcblk->orientation;
476}
477
478ssize_t SurfaceComposerClient::getNumberOfDisplays()
479{
480 volatile surface_flinger_cblk_t const * cblk = get_cblk();
481 uint32_t connected = cblk->connected;
482 int n = 0;
483 while (connected) {
484 if (connected&1) n++;
485 connected >>= 1;
486 }
487 return n;
488}
489
Mathias Agopian698c0872011-06-28 19:09:31 -0700490// ----------------------------------------------------------------------------
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800491
492status_t SurfaceComposerClient::freezeDisplay(DisplayID dpy, uint32_t flags)
493{
Mathias Agopiandd3423c2009-09-23 15:44:05 -0700494 sp<ISurfaceComposer> sm(getComposerService());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800495 return sm->freezeDisplay(dpy, flags);
496}
497
498status_t SurfaceComposerClient::unfreezeDisplay(DisplayID dpy, uint32_t flags)
499{
Mathias Agopiandd3423c2009-09-23 15:44:05 -0700500 sp<ISurfaceComposer> sm(getComposerService());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800501 return sm->unfreezeDisplay(dpy, flags);
502}
503
Mathias Agopian698c0872011-06-28 19:09:31 -0700504int SurfaceComposerClient::setOrientation(DisplayID dpy,
Mathias Agopianc08731e2009-03-27 18:11:38 -0700505 int orientation, uint32_t flags)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800506{
Mathias Agopiandd3423c2009-09-23 15:44:05 -0700507 sp<ISurfaceComposer> sm(getComposerService());
Mathias Agopianc08731e2009-03-27 18:11:38 -0700508 return sm->setOrientation(dpy, orientation, flags);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800509}
510
Mathias Agopiand4784a32010-05-27 19:41:15 -0700511// ----------------------------------------------------------------------------
Mathias Agopian74c40c02010-09-29 13:02:36 -0700512
513ScreenshotClient::ScreenshotClient()
514 : mWidth(0), mHeight(0), mFormat(PIXEL_FORMAT_NONE) {
515}
516
517status_t ScreenshotClient::update() {
518 sp<ISurfaceComposer> s(ComposerService::getComposerService());
519 if (s == NULL) return NO_INIT;
520 mHeap = 0;
521 return s->captureScreen(0, &mHeap,
Mathias Agopianbf2c6a62010-12-10 16:22:31 -0800522 &mWidth, &mHeight, &mFormat, 0, 0,
523 0, -1UL);
Mathias Agopian74c40c02010-09-29 13:02:36 -0700524}
525
526status_t ScreenshotClient::update(uint32_t reqWidth, uint32_t reqHeight) {
527 sp<ISurfaceComposer> s(ComposerService::getComposerService());
528 if (s == NULL) return NO_INIT;
529 mHeap = 0;
530 return s->captureScreen(0, &mHeap,
Mathias Agopianbf2c6a62010-12-10 16:22:31 -0800531 &mWidth, &mHeight, &mFormat, reqWidth, reqHeight,
532 0, -1UL);
533}
534
535status_t ScreenshotClient::update(uint32_t reqWidth, uint32_t reqHeight,
536 uint32_t minLayerZ, uint32_t maxLayerZ) {
537 sp<ISurfaceComposer> s(ComposerService::getComposerService());
538 if (s == NULL) return NO_INIT;
539 mHeap = 0;
540 return s->captureScreen(0, &mHeap,
541 &mWidth, &mHeight, &mFormat, reqWidth, reqHeight,
542 minLayerZ, maxLayerZ);
Mathias Agopian74c40c02010-09-29 13:02:36 -0700543}
544
545void ScreenshotClient::release() {
546 mHeap = 0;
547}
548
549void const* ScreenshotClient::getPixels() const {
550 return mHeap->getBase();
551}
552
553uint32_t ScreenshotClient::getWidth() const {
554 return mWidth;
555}
556
557uint32_t ScreenshotClient::getHeight() const {
558 return mHeight;
559}
560
561PixelFormat ScreenshotClient::getFormat() const {
562 return mFormat;
563}
564
565uint32_t ScreenshotClient::getStride() const {
566 return mWidth;
567}
568
569size_t ScreenshotClient::getSize() const {
570 return mHeap->getSize();
571}
572
573// ----------------------------------------------------------------------------
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800574}; // namespace android
575