blob: 5f3d608a556324759795c7d67cdae91b8fce455d [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;
Jamie Gennisb8d69a52011-10-10 15:48:06 -070094 int mOrientation;
Mathias Agopian698c0872011-06-28 19:09:31 -070095
Jamie Gennisb8d69a52011-10-10 15:48:06 -070096 Composer() : Singleton<Composer>(),
97 mOrientation(ISurfaceComposer::eOrientationUnchanged) { }
Mathias Agopian698c0872011-06-28 19:09:31 -070098
99 void closeGlobalTransactionImpl();
100
101 layer_state_t* getLayerStateLocked(
102 const sp<SurfaceComposerClient>& client, SurfaceID id);
103
Mathias Agopiand4784a32010-05-27 19:41:15 -0700104public:
Mathias Agopian698c0872011-06-28 19:09:31 -0700105
106 status_t setPosition(const sp<SurfaceComposerClient>& client, SurfaceID id,
Mathias Agopian41b6aab2011-08-30 18:51:54 -0700107 float x, float y);
Mathias Agopian698c0872011-06-28 19:09:31 -0700108 status_t setSize(const sp<SurfaceComposerClient>& client, SurfaceID id,
109 uint32_t w, uint32_t h);
110 status_t setLayer(const sp<SurfaceComposerClient>& client, SurfaceID id,
111 int32_t z);
112 status_t setFlags(const sp<SurfaceComposerClient>& client, SurfaceID id,
113 uint32_t flags, uint32_t mask);
114 status_t setTransparentRegionHint(
115 const sp<SurfaceComposerClient>& client, SurfaceID id,
116 const Region& transparentRegion);
117 status_t setAlpha(const sp<SurfaceComposerClient>& client, SurfaceID id,
118 float alpha);
119 status_t setMatrix(const sp<SurfaceComposerClient>& client, SurfaceID id,
120 float dsdx, float dtdx, float dsdy, float dtdy);
121 status_t setFreezeTint(
122 const sp<SurfaceComposerClient>& client, SurfaceID id,
123 uint32_t tint);
Jamie Gennisb8d69a52011-10-10 15:48:06 -0700124 status_t setOrientation(int orientation);
Mathias Agopian698c0872011-06-28 19:09:31 -0700125
Mathias Agopiand4784a32010-05-27 19:41:15 -0700126 static void closeGlobalTransaction() {
127 Composer::getInstance().closeGlobalTransactionImpl();
128 }
129};
130
131ANDROID_SINGLETON_STATIC_INSTANCE(Composer);
132
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800133// ---------------------------------------------------------------------------
134
Mathias Agopian698c0872011-06-28 19:09:31 -0700135void Composer::closeGlobalTransactionImpl() {
136 sp<ISurfaceComposer> sm(getComposerService());
137
138 Vector<ComposerState> transaction;
Jamie Gennisb8d69a52011-10-10 15:48:06 -0700139 int orientation;
Mathias Agopian698c0872011-06-28 19:09:31 -0700140
141 { // scope for the lock
142 Mutex::Autolock _l(mLock);
143 transaction = mStates;
144 mStates.clear();
Jamie Gennisb8d69a52011-10-10 15:48:06 -0700145
146 orientation = mOrientation;
147 mOrientation = ISurfaceComposer::eOrientationUnchanged;
Mathias Agopian698c0872011-06-28 19:09:31 -0700148 }
149
Jamie Gennisb8d69a52011-10-10 15:48:06 -0700150 sm->setTransactionState(transaction, orientation);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800151}
152
Mathias Agopian698c0872011-06-28 19:09:31 -0700153layer_state_t* Composer::getLayerStateLocked(
154 const sp<SurfaceComposerClient>& client, SurfaceID id) {
155
156 ComposerState s;
157 s.client = client->mClient;
158 s.state.surface = id;
159
160 ssize_t index = mStates.indexOf(s);
161 if (index < 0) {
162 // we don't have it, add an initialized layer_state to our list
163 index = mStates.add(s);
164 }
165
166 ComposerState* const out = mStates.editArray();
167 return &(out[index].state);
168}
169
170status_t Composer::setPosition(const sp<SurfaceComposerClient>& client,
Mathias Agopian41b6aab2011-08-30 18:51:54 -0700171 SurfaceID id, float x, float y) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700172 Mutex::Autolock _l(mLock);
173 layer_state_t* s = getLayerStateLocked(client, id);
174 if (!s)
175 return BAD_INDEX;
176 s->what |= ISurfaceComposer::ePositionChanged;
177 s->x = x;
178 s->y = y;
179 return NO_ERROR;
180}
181
182status_t Composer::setSize(const sp<SurfaceComposerClient>& client,
183 SurfaceID id, uint32_t w, uint32_t h) {
184 Mutex::Autolock _l(mLock);
185 layer_state_t* s = getLayerStateLocked(client, id);
186 if (!s)
187 return BAD_INDEX;
188 s->what |= ISurfaceComposer::eSizeChanged;
189 s->w = w;
190 s->h = h;
191 return NO_ERROR;
192}
193
194status_t Composer::setLayer(const sp<SurfaceComposerClient>& client,
195 SurfaceID id, int32_t z) {
196 Mutex::Autolock _l(mLock);
197 layer_state_t* s = getLayerStateLocked(client, id);
198 if (!s)
199 return BAD_INDEX;
200 s->what |= ISurfaceComposer::eLayerChanged;
201 s->z = z;
202 return NO_ERROR;
203}
204
205status_t Composer::setFlags(const sp<SurfaceComposerClient>& client,
206 SurfaceID id, uint32_t flags,
207 uint32_t mask) {
208 Mutex::Autolock _l(mLock);
209 layer_state_t* s = getLayerStateLocked(client, id);
210 if (!s)
211 return BAD_INDEX;
212 s->what |= ISurfaceComposer::eVisibilityChanged;
213 s->flags &= ~mask;
214 s->flags |= (flags & mask);
215 s->mask |= mask;
216 return NO_ERROR;
217}
218
219status_t Composer::setTransparentRegionHint(
220 const sp<SurfaceComposerClient>& client, SurfaceID id,
221 const Region& transparentRegion) {
222 Mutex::Autolock _l(mLock);
223 layer_state_t* s = getLayerStateLocked(client, id);
224 if (!s)
225 return BAD_INDEX;
226 s->what |= ISurfaceComposer::eTransparentRegionChanged;
227 s->transparentRegion = transparentRegion;
228 return NO_ERROR;
229}
230
231status_t Composer::setAlpha(const sp<SurfaceComposerClient>& client,
232 SurfaceID id, float alpha) {
233 Mutex::Autolock _l(mLock);
234 layer_state_t* s = getLayerStateLocked(client, id);
235 if (!s)
236 return BAD_INDEX;
237 s->what |= ISurfaceComposer::eAlphaChanged;
238 s->alpha = alpha;
239 return NO_ERROR;
240}
241
242status_t Composer::setMatrix(const sp<SurfaceComposerClient>& client,
243 SurfaceID id, float dsdx, float dtdx,
244 float dsdy, float dtdy) {
245 Mutex::Autolock _l(mLock);
246 layer_state_t* s = getLayerStateLocked(client, id);
247 if (!s)
248 return BAD_INDEX;
249 s->what |= ISurfaceComposer::eMatrixChanged;
250 layer_state_t::matrix22_t matrix;
251 matrix.dsdx = dsdx;
252 matrix.dtdx = dtdx;
253 matrix.dsdy = dsdy;
254 matrix.dtdy = dtdy;
255 s->matrix = matrix;
256 return NO_ERROR;
257}
258
259status_t Composer::setFreezeTint(const sp<SurfaceComposerClient>& client,
260 SurfaceID id, uint32_t tint) {
261 Mutex::Autolock _l(mLock);
262 layer_state_t* s = getLayerStateLocked(client, id);
263 if (!s)
264 return BAD_INDEX;
265 s->what |= ISurfaceComposer::eFreezeTintChanged;
266 s->tint = tint;
267 return NO_ERROR;
268}
269
Jamie Gennisb8d69a52011-10-10 15:48:06 -0700270status_t Composer::setOrientation(int orientation) {
271 Mutex::Autolock _l(mLock);
272 mOrientation = orientation;
273 return NO_ERROR;
274}
275
Mathias Agopian698c0872011-06-28 19:09:31 -0700276// ---------------------------------------------------------------------------
277
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800278SurfaceComposerClient::SurfaceComposerClient()
Mathias Agopian698c0872011-06-28 19:09:31 -0700279 : mStatus(NO_INIT), mComposer(Composer::getInstance())
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800280{
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800281}
282
Mathias Agopian698c0872011-06-28 19:09:31 -0700283void SurfaceComposerClient::onFirstRef() {
Mathias Agopiand4784a32010-05-27 19:41:15 -0700284 sp<ISurfaceComposer> sm(getComposerService());
285 if (sm != 0) {
Mathias Agopian7e27f052010-05-28 14:22:23 -0700286 sp<ISurfaceComposerClient> conn = sm->createConnection();
Mathias Agopiand4784a32010-05-27 19:41:15 -0700287 if (conn != 0) {
288 mClient = conn;
Mathias Agopiand4784a32010-05-27 19:41:15 -0700289 mStatus = NO_ERROR;
290 }
291 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800292}
293
Mathias Agopian698c0872011-06-28 19:09:31 -0700294SurfaceComposerClient::~SurfaceComposerClient() {
Mathias Agopian631f3582010-05-25 17:51:34 -0700295 dispose();
296}
Mathias Agopiandd3423c2009-09-23 15:44:05 -0700297
Mathias Agopian698c0872011-06-28 19:09:31 -0700298status_t SurfaceComposerClient::initCheck() const {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800299 return mStatus;
300}
301
Mathias Agopian698c0872011-06-28 19:09:31 -0700302sp<IBinder> SurfaceComposerClient::connection() const {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800303 return (mClient != 0) ? mClient->asBinder() : 0;
304}
305
Mathias Agopiand4784a32010-05-27 19:41:15 -0700306status_t SurfaceComposerClient::linkToComposerDeath(
307 const sp<IBinder::DeathRecipient>& recipient,
Mathias Agopian698c0872011-06-28 19:09:31 -0700308 void* cookie, uint32_t flags) {
Mathias Agopiand4784a32010-05-27 19:41:15 -0700309 sp<ISurfaceComposer> sm(getComposerService());
310 return sm->asBinder()->linkToDeath(recipient, cookie, flags);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800311}
312
Mathias Agopian698c0872011-06-28 19:09:31 -0700313void SurfaceComposerClient::dispose() {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800314 // this can be called more than once.
Mathias Agopian7e27f052010-05-28 14:22:23 -0700315 sp<ISurfaceComposerClient> client;
Mathias Agopiand4784a32010-05-27 19:41:15 -0700316 Mutex::Autolock _lm(mLock);
317 if (mClient != 0) {
Mathias Agopiand4784a32010-05-27 19:41:15 -0700318 client = mClient; // hold ref while lock is held
319 mClient.clear();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800320 }
Mathias Agopiand4784a32010-05-27 19:41:15 -0700321 mStatus = NO_INIT;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800322}
323
Mathias Agopian698c0872011-06-28 19:09:31 -0700324sp<SurfaceControl> SurfaceComposerClient::createSurface(
325 DisplayID display,
326 uint32_t w,
327 uint32_t h,
328 PixelFormat format,
329 uint32_t flags)
330{
331 String8 name;
332 const size_t SIZE = 128;
333 char buffer[SIZE];
334 snprintf(buffer, SIZE, "<pid_%d>", getpid());
335 name.append(buffer);
336
337 return SurfaceComposerClient::createSurface(name, display,
338 w, h, format, flags);
339}
340
341sp<SurfaceControl> SurfaceComposerClient::createSurface(
342 const String8& name,
343 DisplayID display,
344 uint32_t w,
345 uint32_t h,
346 PixelFormat format,
347 uint32_t flags)
348{
349 sp<SurfaceControl> result;
350 if (mStatus == NO_ERROR) {
351 ISurfaceComposerClient::surface_data_t data;
352 sp<ISurface> surface = mClient->createSurface(&data, name,
353 display, w, h, format, flags);
354 if (surface != 0) {
Mathias Agopianc10d9d92011-07-20 16:46:11 -0700355 result = new SurfaceControl(this, surface, data);
Mathias Agopian698c0872011-06-28 19:09:31 -0700356 }
357 }
358 return result;
359}
360
361status_t SurfaceComposerClient::destroySurface(SurfaceID sid) {
362 if (mStatus != NO_ERROR)
363 return mStatus;
364 status_t err = mClient->destroySurface(sid);
365 return err;
366}
367
368inline Composer& SurfaceComposerClient::getComposer() {
369 return mComposer;
370}
371
372// ----------------------------------------------------------------------------
373
374void SurfaceComposerClient::openGlobalTransaction() {
375 // Currently a no-op
376}
377
378void SurfaceComposerClient::closeGlobalTransaction() {
379 Composer::closeGlobalTransaction();
380}
381
382// ----------------------------------------------------------------------------
383
384status_t SurfaceComposerClient::setFreezeTint(SurfaceID id, uint32_t tint) {
385 return getComposer().setFreezeTint(this, id, tint);
386}
387
Mathias Agopian41b6aab2011-08-30 18:51:54 -0700388status_t SurfaceComposerClient::setPosition(SurfaceID id, float x, float y) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700389 return getComposer().setPosition(this, id, x, y);
390}
391
392status_t SurfaceComposerClient::setSize(SurfaceID id, uint32_t w, uint32_t h) {
393 return getComposer().setSize(this, id, w, h);
394}
395
396status_t SurfaceComposerClient::setLayer(SurfaceID id, int32_t z) {
397 return getComposer().setLayer(this, id, z);
398}
399
400status_t SurfaceComposerClient::hide(SurfaceID id) {
401 return getComposer().setFlags(this, id,
402 ISurfaceComposer::eLayerHidden,
403 ISurfaceComposer::eLayerHidden);
404}
405
406status_t SurfaceComposerClient::show(SurfaceID id, int32_t) {
407 return getComposer().setFlags(this, id,
408 0,
409 ISurfaceComposer::eLayerHidden);
410}
411
412status_t SurfaceComposerClient::freeze(SurfaceID id) {
413 return getComposer().setFlags(this, id,
414 ISurfaceComposer::eLayerFrozen,
415 ISurfaceComposer::eLayerFrozen);
416}
417
418status_t SurfaceComposerClient::unfreeze(SurfaceID id) {
419 return getComposer().setFlags(this, id,
420 0,
421 ISurfaceComposer::eLayerFrozen);
422}
423
424status_t SurfaceComposerClient::setFlags(SurfaceID id, uint32_t flags,
425 uint32_t mask) {
426 return getComposer().setFlags(this, id, flags, mask);
427}
428
429status_t SurfaceComposerClient::setTransparentRegionHint(SurfaceID id,
430 const Region& transparentRegion) {
431 return getComposer().setTransparentRegionHint(this, id, transparentRegion);
432}
433
434status_t SurfaceComposerClient::setAlpha(SurfaceID id, float alpha) {
435 return getComposer().setAlpha(this, id, alpha);
436}
437
438status_t SurfaceComposerClient::setMatrix(SurfaceID id, float dsdx, float dtdx,
439 float dsdy, float dtdy) {
440 return getComposer().setMatrix(this, id, dsdx, dtdx, dsdy, dtdy);
441}
442
Jamie Gennisb8d69a52011-10-10 15:48:06 -0700443status_t SurfaceComposerClient::setOrientation(DisplayID dpy,
444 int orientation, uint32_t flags)
445{
446 return Composer::getInstance().setOrientation(orientation);
447}
448
Mathias Agopian698c0872011-06-28 19:09:31 -0700449// ----------------------------------------------------------------------------
450
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800451status_t SurfaceComposerClient::getDisplayInfo(
452 DisplayID dpy, DisplayInfo* info)
453{
Mathias Agopiana67932f2011-04-20 14:20:59 -0700454 if (uint32_t(dpy)>=NUM_DISPLAY_MAX)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800455 return BAD_VALUE;
456
457 volatile surface_flinger_cblk_t const * cblk = get_cblk();
458 volatile display_cblk_t const * dcblk = cblk->displays + dpy;
459
460 info->w = dcblk->w;
461 info->h = dcblk->h;
462 info->orientation = dcblk->orientation;
463 info->xdpi = dcblk->xdpi;
464 info->ydpi = dcblk->ydpi;
465 info->fps = dcblk->fps;
466 info->density = dcblk->density;
467 return getPixelFormatInfo(dcblk->format, &(info->pixelFormatInfo));
468}
469
470ssize_t SurfaceComposerClient::getDisplayWidth(DisplayID dpy)
471{
Mathias Agopiana67932f2011-04-20 14:20:59 -0700472 if (uint32_t(dpy)>=NUM_DISPLAY_MAX)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800473 return BAD_VALUE;
474 volatile surface_flinger_cblk_t const * cblk = get_cblk();
475 volatile display_cblk_t const * dcblk = cblk->displays + dpy;
476 return dcblk->w;
477}
478
479ssize_t SurfaceComposerClient::getDisplayHeight(DisplayID dpy)
480{
Mathias Agopiana67932f2011-04-20 14:20:59 -0700481 if (uint32_t(dpy)>=NUM_DISPLAY_MAX)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800482 return BAD_VALUE;
483 volatile surface_flinger_cblk_t const * cblk = get_cblk();
484 volatile display_cblk_t const * dcblk = cblk->displays + dpy;
485 return dcblk->h;
486}
487
488ssize_t SurfaceComposerClient::getDisplayOrientation(DisplayID dpy)
489{
Mathias Agopiana67932f2011-04-20 14:20:59 -0700490 if (uint32_t(dpy)>=NUM_DISPLAY_MAX)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800491 return BAD_VALUE;
492 volatile surface_flinger_cblk_t const * cblk = get_cblk();
493 volatile display_cblk_t const * dcblk = cblk->displays + dpy;
494 return dcblk->orientation;
495}
496
497ssize_t SurfaceComposerClient::getNumberOfDisplays()
498{
499 volatile surface_flinger_cblk_t const * cblk = get_cblk();
500 uint32_t connected = cblk->connected;
501 int n = 0;
502 while (connected) {
503 if (connected&1) n++;
504 connected >>= 1;
505 }
506 return n;
507}
508
Mathias Agopian698c0872011-06-28 19:09:31 -0700509// ----------------------------------------------------------------------------
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800510
511status_t SurfaceComposerClient::freezeDisplay(DisplayID dpy, uint32_t flags)
512{
Jamie Gennisb8d69a52011-10-10 15:48:06 -0700513 // This has been made a no-op because it can cause Gralloc buffer deadlocks.
514 return NO_ERROR;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800515}
516
517status_t SurfaceComposerClient::unfreezeDisplay(DisplayID dpy, uint32_t flags)
518{
Jamie Gennisb8d69a52011-10-10 15:48:06 -0700519 // This has been made a no-op because it can cause Gralloc buffer deadlocks.
520 return NO_ERROR;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800521}
522
Mathias Agopiand4784a32010-05-27 19:41:15 -0700523// ----------------------------------------------------------------------------
Mathias Agopian74c40c02010-09-29 13:02:36 -0700524
525ScreenshotClient::ScreenshotClient()
526 : mWidth(0), mHeight(0), mFormat(PIXEL_FORMAT_NONE) {
527}
528
529status_t ScreenshotClient::update() {
530 sp<ISurfaceComposer> s(ComposerService::getComposerService());
531 if (s == NULL) return NO_INIT;
532 mHeap = 0;
533 return s->captureScreen(0, &mHeap,
Mathias Agopianbf2c6a62010-12-10 16:22:31 -0800534 &mWidth, &mHeight, &mFormat, 0, 0,
535 0, -1UL);
Mathias Agopian74c40c02010-09-29 13:02:36 -0700536}
537
538status_t ScreenshotClient::update(uint32_t reqWidth, uint32_t reqHeight) {
539 sp<ISurfaceComposer> s(ComposerService::getComposerService());
540 if (s == NULL) return NO_INIT;
541 mHeap = 0;
542 return s->captureScreen(0, &mHeap,
Mathias Agopianbf2c6a62010-12-10 16:22:31 -0800543 &mWidth, &mHeight, &mFormat, reqWidth, reqHeight,
544 0, -1UL);
545}
546
547status_t ScreenshotClient::update(uint32_t reqWidth, uint32_t reqHeight,
548 uint32_t minLayerZ, uint32_t maxLayerZ) {
549 sp<ISurfaceComposer> s(ComposerService::getComposerService());
550 if (s == NULL) return NO_INIT;
551 mHeap = 0;
552 return s->captureScreen(0, &mHeap,
553 &mWidth, &mHeight, &mFormat, reqWidth, reqHeight,
554 minLayerZ, maxLayerZ);
Mathias Agopian74c40c02010-09-29 13:02:36 -0700555}
556
557void ScreenshotClient::release() {
558 mHeap = 0;
559}
560
561void const* ScreenshotClient::getPixels() const {
562 return mHeap->getBase();
563}
564
565uint32_t ScreenshotClient::getWidth() const {
566 return mWidth;
567}
568
569uint32_t ScreenshotClient::getHeight() const {
570 return mHeight;
571}
572
573PixelFormat ScreenshotClient::getFormat() const {
574 return mFormat;
575}
576
577uint32_t ScreenshotClient::getStride() const {
578 return mWidth;
579}
580
581size_t ScreenshotClient::getSize() const {
582 return mHeap->getSize();
583}
584
585// ----------------------------------------------------------------------------
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800586}; // namespace android