blob: 4739cc3072c1bb2bf7c39090303f71ceba0f7c45 [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
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080017#include <stdlib.h>
18#include <stdint.h>
19#include <sys/types.h>
20
21#include <cutils/properties.h>
Mathias Agopian076b1cc2009-04-10 14:24:30 -070022#include <cutils/native_handle.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080023
24#include <utils/Errors.h>
25#include <utils/Log.h>
26#include <utils/StopWatch.h>
27
Mathias Agopian3330b202009-10-05 17:07:12 -070028#include <ui/GraphicBuffer.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080029#include <ui/PixelFormat.h>
Mathias Agopian9cce3252010-02-09 17:46:37 -080030
31#include <surfaceflinger/Surface.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080032
33#include "clz.h"
Mathias Agopian1f7bec62010-06-25 18:02:21 -070034#include "GLExtensions.h"
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080035#include "Layer.h"
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080036#include "SurfaceFlinger.h"
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080037#include "DisplayHardware/DisplayHardware.h"
38
39
40#define DEBUG_RESIZE 0
41
42
43namespace android {
44
Mathias Agopianca99fb82010-04-14 16:43:44 -070045template <typename T> inline T min(T a, T b) {
46 return a<b ? a : b;
47}
48
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080049// ---------------------------------------------------------------------------
50
Mathias Agopian96f08192010-06-02 23:28:45 -070051Layer::Layer(SurfaceFlinger* flinger,
52 DisplayID display, const sp<Client>& client)
53 : LayerBaseClient(flinger, display, client),
Mathias Agopian1f7bec62010-06-25 18:02:21 -070054 mGLExtensions(GLExtensions::getInstance()),
Mathias Agopian401c2572009-09-23 19:16:27 -070055 mNeedsBlending(true),
Mathias Agopiand606de62010-05-10 20:06:11 -070056 mNeedsDithering(false),
Mathias Agopianb7e930d2010-06-01 15:12:58 -070057 mSecure(false),
Mathias Agopian1f7bec62010-06-25 18:02:21 -070058 mTextureManager(),
Mathias Agopiana138f892010-05-21 17:24:35 -070059 mBufferManager(mTextureManager),
Mathias Agopian22c67842010-11-01 23:32:18 -070060 mWidth(0), mHeight(0), mNeedsScaling(false), mFixedSize(false),
61 mBypassState(false)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080062{
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080063}
64
65Layer::~Layer()
66{
Mathias Agopianbb641242010-05-18 17:06:55 -070067 // FIXME: must be called from the main UI thread
68 EGLDisplay dpy(mFlinger->graphicPlane(0).getEGLDisplay());
69 mBufferManager.destroy(dpy);
70
Mathias Agopianb7e930d2010-06-01 15:12:58 -070071 // we can use getUserClientUnsafe here because we know we're
72 // single-threaded at that point.
73 sp<UserClient> ourClient(mUserClientRef.getUserClientUnsafe());
74 if (ourClient != 0) {
75 ourClient->detachLayer(this);
76 }
Mathias Agopiand606de62010-05-10 20:06:11 -070077}
78
Mathias Agopianb4081bb2011-05-19 15:38:14 -070079void Layer::destroy() const {
80 mFlinger->destroyLayer(this);
81}
82
Mathias Agopianb7e930d2010-06-01 15:12:58 -070083status_t Layer::setToken(const sp<UserClient>& userClient,
84 SharedClient* sharedClient, int32_t token)
Mathias Agopian96f08192010-06-02 23:28:45 -070085{
Mathias Agopian579b3f82010-06-08 19:54:15 -070086 sp<SharedBufferServer> lcblk = new SharedBufferServer(
Mathias Agopianb7e930d2010-06-01 15:12:58 -070087 sharedClient, token, mBufferManager.getDefaultBufferCount(),
Mathias Agopian96f08192010-06-02 23:28:45 -070088 getIdentity());
89
Mathias Agopianb7e930d2010-06-01 15:12:58 -070090 status_t err = mUserClientRef.setToken(userClient, lcblk, token);
Mathias Agopian579b3f82010-06-08 19:54:15 -070091
92 LOGE_IF(err != NO_ERROR,
93 "ClientRef::setToken(%p, %p, %u) failed",
94 userClient.get(), lcblk.get(), token);
95
96 if (err == NO_ERROR) {
97 // we need to free the buffers associated with this surface
Mathias Agopianb7e930d2010-06-01 15:12:58 -070098 }
99
100 return err;
101}
102
103int32_t Layer::getToken() const
104{
105 return mUserClientRef.getToken();
Mathias Agopian96f08192010-06-02 23:28:45 -0700106}
107
Mathias Agopian579b3f82010-06-08 19:54:15 -0700108sp<UserClient> Layer::getClient() const
109{
110 return mUserClientRef.getClient();
111}
112
Mathias Agopiand606de62010-05-10 20:06:11 -0700113// called with SurfaceFlinger::mStateLock as soon as the layer is entered
114// in the purgatory list
115void Layer::onRemoved()
116{
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700117 ClientRef::Access sharedClient(mUserClientRef);
118 SharedBufferServer* lcblk(sharedClient.get());
119 if (lcblk) {
Mathias Agopian96f08192010-06-02 23:28:45 -0700120 // wake up the condition
121 lcblk->setStatus(NO_INIT);
122 }
Mathias Agopian48d819a2009-09-10 19:41:18 -0700123}
Mathias Agopiancbb288b2009-09-07 16:32:45 -0700124
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700125sp<LayerBaseClient::Surface> Layer::createSurface() const
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800126{
Mathias Agopianf7662af2011-03-09 16:13:31 -0800127 return mSurface;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800128}
129
Mathias Agopianf9d93272009-06-19 17:00:27 -0700130status_t Layer::setBuffers( uint32_t w, uint32_t h,
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800131 PixelFormat format, uint32_t flags)
132{
Mathias Agopian401c2572009-09-23 19:16:27 -0700133 // this surfaces pixel format
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800134 PixelFormatInfo info;
135 status_t err = getPixelFormatInfo(format, &info);
136 if (err) return err;
137
Mathias Agopian401c2572009-09-23 19:16:27 -0700138 // the display's pixel format
139 const DisplayHardware& hw(graphicPlane(0).displayHardware());
Mathias Agopianca99fb82010-04-14 16:43:44 -0700140 uint32_t const maxSurfaceDims = min(
141 hw.getMaxTextureSize(), hw.getMaxViewportDims());
142
143 // never allow a surface larger than what our underlying GL implementation
144 // can handle.
145 if ((uint32_t(w)>maxSurfaceDims) || (uint32_t(h)>maxSurfaceDims)) {
146 return BAD_VALUE;
147 }
148
Mathias Agopian401c2572009-09-23 19:16:27 -0700149 PixelFormatInfo displayInfo;
150 getPixelFormatInfo(hw.getFormat(), &displayInfo);
Mathias Agopiana4b740e2009-10-05 18:20:39 -0700151 const uint32_t hwFlags = hw.getFlags();
152
Mathias Agopiancbb288b2009-09-07 16:32:45 -0700153 mFormat = format;
Mathias Agopianca99fb82010-04-14 16:43:44 -0700154 mWidth = w;
Mathias Agopiancbb288b2009-09-07 16:32:45 -0700155 mHeight = h;
Mathias Agopianeff062c2010-08-25 14:59:15 -0700156
157 mReqFormat = format;
158 mReqWidth = w;
159 mReqHeight = h;
160
Mathias Agopian3330b202009-10-05 17:07:12 -0700161 mSecure = (flags & ISurfaceComposer::eSecure) ? true : false;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800162 mNeedsBlending = (info.h_alpha - info.l_alpha) > 0;
Mathias Agopianca99fb82010-04-14 16:43:44 -0700163
Mathias Agopian401c2572009-09-23 19:16:27 -0700164 // we use the red index
165 int displayRedSize = displayInfo.getSize(PixelFormatInfo::INDEX_RED);
166 int layerRedsize = info.getSize(PixelFormatInfo::INDEX_RED);
167 mNeedsDithering = layerRedsize > displayRedSize;
168
Mathias Agopianf7662af2011-03-09 16:13:31 -0800169 mSurface = new SurfaceLayer(mFlinger, this);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800170 return NO_ERROR;
171}
172
173void Layer::reloadTexture(const Region& dirty)
174{
Mathias Agopiand606de62010-05-10 20:06:11 -0700175 sp<GraphicBuffer> buffer(mBufferManager.getActiveBuffer());
Mathias Agopian8f03b472009-12-10 15:52:29 -0800176 if (buffer == NULL) {
177 // this situation can happen if we ran out of memory for instance.
178 // not much we can do. continue to use whatever texture was bound
179 // to this context.
180 return;
181 }
182
Mathias Agopian1f7bec62010-06-25 18:02:21 -0700183 if (mGLExtensions.haveDirectTexture()) {
Mathias Agopiand606de62010-05-10 20:06:11 -0700184 EGLDisplay dpy(mFlinger->graphicPlane(0).getEGLDisplay());
185 if (mBufferManager.initEglImage(dpy, buffer) != NO_ERROR) {
186 // not sure what we can do here...
Mathias Agopiand606de62010-05-10 20:06:11 -0700187 goto slowpath;
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700188 }
Mathias Agopian1f7bec62010-06-25 18:02:21 -0700189 } else {
Mathias Agopianfcfeb4b2010-03-08 11:14:20 -0800190slowpath:
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700191 GGLSurface t;
Mathias Agopianf1b38242010-08-20 15:59:53 -0700192 if (buffer->usage & GRALLOC_USAGE_SW_READ_MASK) {
193 status_t res = buffer->lock(&t, GRALLOC_USAGE_SW_READ_OFTEN);
194 LOGE_IF(res, "error %d (%s) locking buffer %p",
195 res, strerror(res), buffer.get());
196 if (res == NO_ERROR) {
197 mBufferManager.loadTexture(dirty, t);
198 buffer->unlock();
199 }
200 } else {
201 // we can't do anything
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700202 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800203 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800204}
205
Mathias Agopiandf85c452010-09-29 13:02:36 -0700206void Layer::drawForSreenShot() const
207{
Mathias Agopian733189d2010-12-02 21:32:29 -0800208 const bool currentFiltering = mNeedsFiltering;
209 const_cast<Layer*>(this)->mNeedsFiltering = true;
Mathias Agopiandf85c452010-09-29 13:02:36 -0700210 LayerBase::drawForSreenShot();
Mathias Agopian733189d2010-12-02 21:32:29 -0800211 const_cast<Layer*>(this)->mNeedsFiltering = currentFiltering;
Mathias Agopiandf85c452010-09-29 13:02:36 -0700212}
213
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800214void Layer::onDraw(const Region& clip) const
215{
Mathias Agopiand606de62010-05-10 20:06:11 -0700216 Texture tex(mBufferManager.getActiveTexture());
217 if (tex.name == -1LU) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800218 // the texture has not been created yet, this Layer has
Mathias Agopian179169e2010-05-06 20:21:45 -0700219 // in fact never been drawn into. This happens frequently with
220 // SurfaceView because the WindowManager can't know when the client
221 // has drawn the first time.
222
223 // If there is nothing under us, we paint the screen in black, otherwise
224 // we just skip this update.
225
226 // figure out if there is something below us
227 Region under;
228 const SurfaceFlinger::LayerVector& drawingLayers(mFlinger->mDrawingState.layersSortedByZ);
229 const size_t count = drawingLayers.size();
230 for (size_t i=0 ; i<count ; ++i) {
231 const sp<LayerBase>& layer(drawingLayers[i]);
232 if (layer.get() == static_cast<LayerBase const*>(this))
233 break;
234 under.orSelf(layer->visibleRegionScreen);
235 }
236 // if not everything below us is covered, we plug the holes!
237 Region holes(clip.subtract(under));
238 if (!holes.isEmpty()) {
Mathias Agopian0a917752010-06-14 21:20:00 -0700239 clearWithOpenGL(holes, 0, 0, 0, 1);
Mathias Agopian179169e2010-05-06 20:21:45 -0700240 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800241 return;
242 }
Mathias Agopian22c67842010-11-01 23:32:18 -0700243
244#ifdef USE_COMPOSITION_BYPASS
245 sp<GraphicBuffer> buffer(mBufferManager.getActiveBuffer());
246 if ((buffer != NULL) && (buffer->transform)) {
247 // Here we have a "bypass" buffer, but we need to composite it
248 // most likely because it's not fullscreen anymore.
249 // Since the buffer may have a transformation applied by the client
250 // we need to inverse this transformation here.
251
252 // calculate the inverse of the buffer transform
253 const uint32_t mask = HAL_TRANSFORM_FLIP_V | HAL_TRANSFORM_FLIP_H;
254 const uint32_t bufferTransformInverse = buffer->transform ^ mask;
255
256 // To accomplish the inverse transform, we use "mBufferTransform"
257 // which is not used by Layer.cpp
258 const_cast<Layer*>(this)->mBufferTransform = bufferTransformInverse;
259 drawWithOpenGL(clip, tex);
260 // reset to "no transfrom"
261 const_cast<Layer*>(this)->mBufferTransform = 0;
262 return;
263 }
264#endif
265
Mathias Agopiand606de62010-05-10 20:06:11 -0700266 drawWithOpenGL(clip, tex);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800267}
268
Mathias Agopiana7f66922010-05-26 22:08:52 -0700269bool Layer::needsFiltering() const
270{
271 if (!(mFlags & DisplayHardware::SLOW_CONFIG)) {
Mathias Agopian733189d2010-12-02 21:32:29 -0800272 // if our buffer is not the same size than ourselves,
273 // we need filtering.
274 Mutex::Autolock _l(mLock);
275 if (mNeedsScaling)
Mathias Agopiana7f66922010-05-26 22:08:52 -0700276 return true;
277 }
278 return LayerBase::needsFiltering();
279}
280
Mathias Agopianb5b7f262010-05-07 15:58:44 -0700281
282status_t Layer::setBufferCount(int bufferCount)
283{
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700284 ClientRef::Access sharedClient(mUserClientRef);
285 SharedBufferServer* lcblk(sharedClient.get());
286 if (!lcblk) {
Mathias Agopianb5b7f262010-05-07 15:58:44 -0700287 // oops, the client is already gone
288 return DEAD_OBJECT;
289 }
290
Mathias Agopianbb641242010-05-18 17:06:55 -0700291 // NOTE: lcblk->resize() is protected by an internal lock
292 status_t err = lcblk->resize(bufferCount);
293 if (err == NO_ERROR)
294 mBufferManager.resize(bufferCount);
Mathias Agopianb5b7f262010-05-07 15:58:44 -0700295
296 return err;
297}
298
Mathias Agopiana138f892010-05-21 17:24:35 -0700299sp<GraphicBuffer> Layer::requestBuffer(int index,
300 uint32_t reqWidth, uint32_t reqHeight, uint32_t reqFormat,
301 uint32_t usage)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800302{
Mathias Agopian3330b202009-10-05 17:07:12 -0700303 sp<GraphicBuffer> buffer;
Mathias Agopian48d819a2009-09-10 19:41:18 -0700304
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700305 if (int32_t(reqWidth | reqHeight | reqFormat) < 0)
Mathias Agopiana138f892010-05-21 17:24:35 -0700306 return buffer;
307
308 if ((!reqWidth && reqHeight) || (reqWidth && !reqHeight))
309 return buffer;
310
Mathias Agopian48d819a2009-09-10 19:41:18 -0700311 // this ensures our client doesn't go away while we're accessing
312 // the shared area.
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700313 ClientRef::Access sharedClient(mUserClientRef);
314 SharedBufferServer* lcblk(sharedClient.get());
315 if (!lcblk) {
Mathias Agopian48d819a2009-09-10 19:41:18 -0700316 // oops, the client is already gone
317 return buffer;
318 }
319
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700320 /*
Mathias Agopiancbb288b2009-09-07 16:32:45 -0700321 * This is called from the client's Surface::dequeue(). This can happen
322 * at any time, especially while we're in the middle of using the
323 * buffer 'index' as our front buffer.
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700324 */
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800325
Mathias Agopian22c67842010-11-01 23:32:18 -0700326 uint32_t w, h, f, bypass;
Mathias Agopian48d819a2009-09-10 19:41:18 -0700327 { // scope for the lock
328 Mutex::Autolock _l(mLock);
Mathias Agopianeff062c2010-08-25 14:59:15 -0700329
Mathias Agopian22c67842010-11-01 23:32:18 -0700330 bypass = mBypassState;
331
Mathias Agopianeff062c2010-08-25 14:59:15 -0700332 // zero means default
Mathias Agopian733189d2010-12-02 21:32:29 -0800333 mFixedSize = reqWidth && reqHeight;
Mathias Agopianeff062c2010-08-25 14:59:15 -0700334 if (!reqFormat) reqFormat = mFormat;
335 if (!reqWidth) reqWidth = mWidth;
336 if (!reqHeight) reqHeight = mHeight;
337
338 w = reqWidth;
339 h = reqHeight;
340 f = reqFormat;
341
342 if ((reqWidth != mReqWidth) || (reqHeight != mReqHeight) ||
343 (reqFormat != mReqFormat)) {
344 mReqWidth = reqWidth;
345 mReqHeight = reqHeight;
346 mReqFormat = reqFormat;
Mathias Agopian733189d2010-12-02 21:32:29 -0800347 mNeedsScaling = mWidth != mReqWidth || mHeight != mReqHeight;
Mathias Agopianeff062c2010-08-25 14:59:15 -0700348
Mathias Agopiana138f892010-05-21 17:24:35 -0700349 lcblk->reallocateAllExcept(index);
350 }
Mathias Agopian48d819a2009-09-10 19:41:18 -0700351 }
352
Mathias Agopian208cb072010-07-27 20:11:35 -0700353 // here we have to reallocate a new buffer because the buffer could be
354 // used as the front buffer, or by a client in our process
355 // (eg: status bar), and we can't release the handle under its feet.
Mathias Agopian22c67842010-11-01 23:32:18 -0700356 uint32_t effectiveUsage = getEffectiveUsage(usage);
357
358 status_t err = NO_MEMORY;
359
360#ifdef USE_COMPOSITION_BYPASS
361 if (!mSecure && bypass && (effectiveUsage & GRALLOC_USAGE_HW_RENDER)) {
362 // always allocate a buffer matching the screen size. the size
363 // may be different from (w,h) if the buffer is rotated.
364 const DisplayHardware& hw(graphicPlane(0).displayHardware());
365 int32_t w = hw.getWidth();
366 int32_t h = hw.getHeight();
367 int32_t f = hw.getFormat();
368
369 buffer = new GraphicBuffer(w, h, f, effectiveUsage | GRALLOC_USAGE_HW_FB);
370 err = buffer->initCheck();
371 buffer->transform = uint8_t(getOrientation());
372
373 if (err != NO_ERROR) {
374 // allocation didn't succeed, probably because an older bypass
375 // window hasn't released all its resources yet.
376 ClientRef::Access sharedClient(mUserClientRef);
377 SharedBufferServer* lcblk(sharedClient.get());
378 if (lcblk) {
379 // all buffers need reallocation
380 lcblk->reallocateAll();
381 }
382 }
383 }
384#endif
385
386 if (err != NO_ERROR) {
387 buffer = new GraphicBuffer(w, h, f, effectiveUsage);
388 err = buffer->initCheck();
389 }
Mathias Agopiancbb288b2009-09-07 16:32:45 -0700390
391 if (err || buffer->handle == 0) {
Mathias Agopian678bdd62010-12-03 17:33:09 -0800392 GraphicBuffer::dumpAllocationsToSystemLog();
Mathias Agopiancbb288b2009-09-07 16:32:45 -0700393 LOGE_IF(err || buffer->handle == 0,
394 "Layer::requestBuffer(this=%p), index=%d, w=%d, h=%d failed (%s)",
395 this, index, w, h, strerror(-err));
396 } else {
397 LOGD_IF(DEBUG_RESIZE,
Mathias Agopian7e4a5872009-09-29 22:39:22 -0700398 "Layer::requestBuffer(this=%p), index=%d, w=%d, h=%d, handle=%p",
399 this, index, w, h, buffer->handle);
Mathias Agopiancbb288b2009-09-07 16:32:45 -0700400 }
401
402 if (err == NO_ERROR && buffer->handle != 0) {
Mathias Agopian48d819a2009-09-10 19:41:18 -0700403 Mutex::Autolock _l(mLock);
Mathias Agopiana138f892010-05-21 17:24:35 -0700404 mBufferManager.attachBuffer(index, buffer);
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700405 }
406 return buffer;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800407}
408
Mathias Agopian3330b202009-10-05 17:07:12 -0700409uint32_t Layer::getEffectiveUsage(uint32_t usage) const
410{
411 /*
412 * buffers used for software rendering, but h/w composition
413 * are allocated with SW_READ_OFTEN | SW_WRITE_OFTEN | HW_TEXTURE
414 *
415 * buffers used for h/w rendering and h/w composition
416 * are allocated with HW_RENDER | HW_TEXTURE
417 *
418 * buffers used with h/w rendering and either NPOT or no egl_image_ext
419 * are allocated with SW_READ_RARELY | HW_RENDER
420 *
421 */
422
423 if (mSecure) {
424 // secure buffer, don't store it into the GPU
425 usage = GraphicBuffer::USAGE_SW_READ_OFTEN |
426 GraphicBuffer::USAGE_SW_WRITE_OFTEN;
427 } else {
428 // it's allowed to modify the usage flags here, but generally
429 // the requested flags should be honored.
Mathias Agopian89141f92010-05-10 20:10:10 -0700430 // request EGLImage for all buffers
431 usage |= GraphicBuffer::USAGE_HW_TEXTURE;
Mathias Agopian3330b202009-10-05 17:07:12 -0700432 }
433 return usage;
434}
435
Mathias Agopian22c67842010-11-01 23:32:18 -0700436bool Layer::setBypass(bool enable)
437{
438 Mutex::Autolock _l(mLock);
439
440 if (mNeedsScaling || mNeedsFiltering) {
441 return false;
442 }
443
444 if (mBypassState != enable) {
445 mBypassState = enable;
446 ClientRef::Access sharedClient(mUserClientRef);
447 SharedBufferServer* lcblk(sharedClient.get());
448 if (lcblk) {
449 // all buffers need reallocation
450 lcblk->reallocateAll();
451 }
452 }
453
454 return true;
455}
456
Mathias Agopiane24cc7a2010-12-07 21:00:25 -0800457void Layer::updateBuffersOrientation()
458{
459 sp<GraphicBuffer> buffer(getBypassBuffer());
460 if (buffer != NULL && mOrientation != buffer->transform) {
461 ClientRef::Access sharedClient(mUserClientRef);
462 SharedBufferServer* lcblk(sharedClient.get());
463 if (lcblk) { // all buffers need reallocation
464 lcblk->reallocateAll();
465 }
466 }
467}
468
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800469uint32_t Layer::doTransaction(uint32_t flags)
470{
471 const Layer::State& front(drawingState());
472 const Layer::State& temp(currentState());
473
Mathias Agopiana138f892010-05-21 17:24:35 -0700474 const bool sizeChanged = (front.requested_w != temp.requested_w) ||
475 (front.requested_h != temp.requested_h);
476
477 if (sizeChanged) {
Mathias Agopiancbb288b2009-09-07 16:32:45 -0700478 // the size changed, we need to ask our client to request a new buffer
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800479 LOGD_IF(DEBUG_RESIZE,
Mathias Agopiana138f892010-05-21 17:24:35 -0700480 "resize (layer=%p), requested (%dx%d), drawing (%d,%d)",
481 this,
482 int(temp.requested_w), int(temp.requested_h),
483 int(front.requested_w), int(front.requested_h));
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800484
Mathias Agopiana138f892010-05-21 17:24:35 -0700485 if (!isFixedSize()) {
486 // we're being resized and there is a freeze display request,
487 // acquire a freeze lock, so that the screen stays put
488 // until we've redrawn at the new size; this is to avoid
489 // glitches upon orientation changes.
490 if (mFlinger->hasFreezeRequest()) {
491 // if the surface is hidden, don't try to acquire the
492 // freeze lock, since hidden surfaces may never redraw
493 if (!(front.flags & ISurfaceComposer::eLayerHidden)) {
494 mFreezeLock = mFlinger->getFreezeLock();
495 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800496 }
Mathias Agopiana138f892010-05-21 17:24:35 -0700497
498 // this will make sure LayerBase::doTransaction doesn't update
499 // the drawing state's size
500 Layer::State& editDraw(mDrawingState);
501 editDraw.requested_w = temp.requested_w;
502 editDraw.requested_h = temp.requested_h;
503
504 // record the new size, form this point on, when the client request
505 // a buffer, it'll get the new size.
506 setBufferSize(temp.requested_w, temp.requested_h);
507
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700508 ClientRef::Access sharedClient(mUserClientRef);
509 SharedBufferServer* lcblk(sharedClient.get());
510 if (lcblk) {
Mathias Agopian96f08192010-06-02 23:28:45 -0700511 // all buffers need reallocation
512 lcblk->reallocateAll();
513 }
Mathias Agopiana138f892010-05-21 17:24:35 -0700514 } else {
515 // record the new size
516 setBufferSize(temp.requested_w, temp.requested_h);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800517 }
518 }
Mathias Agopiancbb288b2009-09-07 16:32:45 -0700519
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800520 if (temp.sequence != front.sequence) {
521 if (temp.flags & ISurfaceComposer::eLayerHidden || temp.alpha == 0) {
522 // this surface is now hidden, so it shouldn't hold a freeze lock
523 // (it may never redraw, which is fine if it is hidden)
524 mFreezeLock.clear();
525 }
526 }
527
528 return LayerBase::doTransaction(flags);
529}
530
Mathias Agopiana138f892010-05-21 17:24:35 -0700531void Layer::setBufferSize(uint32_t w, uint32_t h) {
Mathias Agopiancbb288b2009-09-07 16:32:45 -0700532 Mutex::Autolock _l(mLock);
533 mWidth = w;
534 mHeight = h;
Mathias Agopian733189d2010-12-02 21:32:29 -0800535 mNeedsScaling = mWidth != mReqWidth || mHeight != mReqHeight;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800536}
537
Mathias Agopiana138f892010-05-21 17:24:35 -0700538bool Layer::isFixedSize() const {
539 Mutex::Autolock _l(mLock);
540 return mFixedSize;
541}
542
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800543// ----------------------------------------------------------------------------
544// pageflip handling...
545// ----------------------------------------------------------------------------
546
547void Layer::lockPageFlip(bool& recomputeVisibleRegions)
548{
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700549 ClientRef::Access sharedClient(mUserClientRef);
550 SharedBufferServer* lcblk(sharedClient.get());
551 if (!lcblk) {
Mathias Agopian96f08192010-06-02 23:28:45 -0700552 // client died
553 recomputeVisibleRegions = true;
554 return;
555 }
556
Mathias Agopiancbb288b2009-09-07 16:32:45 -0700557 ssize_t buf = lcblk->retireAndLock();
Mathias Agopiand606de62010-05-10 20:06:11 -0700558 if (buf == NOT_ENOUGH_DATA) {
559 // NOTE: This is not an error, it simply means there is nothing to
560 // retire. The buffer is locked because we will use it
Mathias Agopiancbb288b2009-09-07 16:32:45 -0700561 // for composition later in the loop
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800562 return;
563 }
Mathias Agopiand343e3d2010-03-15 18:15:20 -0700564
Mathias Agopiand606de62010-05-10 20:06:11 -0700565 if (buf < NO_ERROR) {
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700566 LOGE("retireAndLock() buffer index (%d) out of range", int(buf));
Mathias Agopiand343e3d2010-03-15 18:15:20 -0700567 mPostedDirtyRegion.clear();
568 return;
569 }
570
Mathias Agopiancbb288b2009-09-07 16:32:45 -0700571 // we retired a buffer, which becomes the new front buffer
Mathias Agopiand606de62010-05-10 20:06:11 -0700572 if (mBufferManager.setActiveBufferIndex(buf) < NO_ERROR) {
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700573 LOGE("retireAndLock() buffer index (%d) out of range", int(buf));
Mathias Agopiand606de62010-05-10 20:06:11 -0700574 mPostedDirtyRegion.clear();
575 return;
576 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800577
Mathias Agopian3330b202009-10-05 17:07:12 -0700578 sp<GraphicBuffer> newFrontBuffer(getBuffer(buf));
Mathias Agopiand343e3d2010-03-15 18:15:20 -0700579 if (newFrontBuffer != NULL) {
Mathias Agopianb661d662010-08-19 17:01:19 -0700580 // get the dirty region
Mathias Agopiand343e3d2010-03-15 18:15:20 -0700581 // compute the posted region
582 const Region dirty(lcblk->getDirtyRegion(buf));
583 mPostedDirtyRegion = dirty.intersect( newFrontBuffer->getBounds() );
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700584
Mathias Agopiand343e3d2010-03-15 18:15:20 -0700585 // update the layer size and release freeze-lock
586 const Layer::State& front(drawingState());
587 if (newFrontBuffer->getWidth() == front.requested_w &&
588 newFrontBuffer->getHeight() == front.requested_h)
Mathias Agopiandf3e0b92009-09-30 14:07:22 -0700589 {
Mathias Agopiand343e3d2010-03-15 18:15:20 -0700590 if ((front.w != front.requested_w) ||
591 (front.h != front.requested_h))
592 {
593 // Here we pretend the transaction happened by updating the
594 // current and drawing states. Drawing state is only accessed
595 // in this thread, no need to have it locked
596 Layer::State& editDraw(mDrawingState);
597 editDraw.w = editDraw.requested_w;
598 editDraw.h = editDraw.requested_h;
Mathias Agopiandf3e0b92009-09-30 14:07:22 -0700599
Mathias Agopiand343e3d2010-03-15 18:15:20 -0700600 // We also need to update the current state so that we don't
601 // end-up doing too much work during the next transaction.
602 // NOTE: We actually don't need hold the transaction lock here
603 // because State::w and State::h are only accessed from
604 // this thread
605 Layer::State& editTemp(currentState());
606 editTemp.w = editDraw.w;
607 editTemp.h = editDraw.h;
Mathias Agopiandf3e0b92009-09-30 14:07:22 -0700608
Mathias Agopiand343e3d2010-03-15 18:15:20 -0700609 // recompute visible region
610 recomputeVisibleRegions = true;
611 }
612
613 // we now have the correct size, unfreeze the screen
614 mFreezeLock.clear();
Mathias Agopiandf3e0b92009-09-30 14:07:22 -0700615 }
Mathias Agopianb661d662010-08-19 17:01:19 -0700616
617 // get the crop region
618 setBufferCrop( lcblk->getCrop(buf) );
619
620 // get the transformation
621 setBufferTransform( lcblk->getTransform(buf) );
622
Mathias Agopiand343e3d2010-03-15 18:15:20 -0700623 } else {
624 // this should not happen unless we ran out of memory while
625 // allocating the buffer. we're hoping that things will get back
626 // to normal the next time the app tries to draw into this buffer.
627 // meanwhile, pretend the screen didn't update.
628 mPostedDirtyRegion.clear();
Mathias Agopiancaa600c2009-09-16 18:27:24 -0700629 }
630
Mathias Agopiane7005012009-10-07 16:44:10 -0700631 if (lcblk->getQueuedCount()) {
632 // signal an event if we have more buffers waiting
633 mFlinger->signalEvent();
634 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800635
Mathias Agopian245e4d72010-04-21 15:24:11 -0700636 /* a buffer was posted, so we need to call reloadTexture(), which
637 * will update our internal data structures (eg: EGLImageKHR or
638 * texture names). we need to do this even if mPostedDirtyRegion is
639 * empty -- it's orthogonal to the fact that a new buffer was posted,
640 * for instance, a degenerate case could be that the user did an empty
641 * update but repainted the buffer with appropriate content (after a
642 * resize for instance).
643 */
644 reloadTexture( mPostedDirtyRegion );
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800645}
646
647void Layer::unlockPageFlip(
648 const Transform& planeTransform, Region& outDirtyRegion)
649{
650 Region dirtyRegion(mPostedDirtyRegion);
651 if (!dirtyRegion.isEmpty()) {
652 mPostedDirtyRegion.clear();
653 // The dirty region is given in the layer's coordinate space
654 // transform the dirty region by the surface's transformation
655 // and the global transformation.
656 const Layer::State& s(drawingState());
657 const Transform tr(planeTransform * s.transform);
658 dirtyRegion = tr.transform(dirtyRegion);
659
660 // At this point, the dirty region is in screen space.
661 // Make sure it's constrained by the visible region (which
662 // is in screen space as well).
663 dirtyRegion.andSelf(visibleRegionScreen);
664 outDirtyRegion.orSelf(dirtyRegion);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800665 }
Mathias Agopianc61de172009-11-30 11:15:41 -0800666 if (visibleRegionScreen.isEmpty()) {
667 // an invisible layer should not hold a freeze-lock
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700668 // (because it may never be updated and therefore never release it)
Mathias Agopianc61de172009-11-30 11:15:41 -0800669 mFreezeLock.clear();
670 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800671}
672
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700673void Layer::dump(String8& result, char* buffer, size_t SIZE) const
674{
675 LayerBaseClient::dump(result, buffer, SIZE);
676
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700677 ClientRef::Access sharedClient(mUserClientRef);
678 SharedBufferServer* lcblk(sharedClient.get());
679 uint32_t totalTime = 0;
680 if (lcblk) {
681 SharedBufferStack::Statistics stats = lcblk->getStats();
682 totalTime= stats.totalTime;
683 result.append( lcblk->dump(" ") );
684 }
685
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700686 sp<const GraphicBuffer> buf0(getBuffer(0));
687 sp<const GraphicBuffer> buf1(getBuffer(1));
688 uint32_t w0=0, h0=0, s0=0;
689 uint32_t w1=0, h1=0, s1=0;
690 if (buf0 != 0) {
691 w0 = buf0->getWidth();
692 h0 = buf0->getHeight();
693 s0 = buf0->getStride();
694 }
695 if (buf1 != 0) {
696 w1 = buf1->getWidth();
697 h1 = buf1->getHeight();
698 s1 = buf1->getStride();
699 }
700 snprintf(buffer, SIZE,
701 " "
702 "format=%2d, [%3ux%3u:%3u] [%3ux%3u:%3u],"
Mathias Agopian22c67842010-11-01 23:32:18 -0700703 " freezeLock=%p, bypass=%d, dq-q-time=%u us\n",
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700704 mFormat, w0, h0, s0, w1, h1, s1,
Mathias Agopian22c67842010-11-01 23:32:18 -0700705 getFreezeLock().get(), mBypassState, totalTime);
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700706
707 result.append(buffer);
708}
709
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700710// ---------------------------------------------------------------------------
711
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700712Layer::ClientRef::ClientRef()
Mathias Agopian579b3f82010-06-08 19:54:15 -0700713 : mControlBlock(0), mToken(-1) {
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700714}
715
716Layer::ClientRef::~ClientRef() {
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700717}
718
719int32_t Layer::ClientRef::getToken() const {
720 Mutex::Autolock _l(mLock);
721 return mToken;
722}
723
Mathias Agopian579b3f82010-06-08 19:54:15 -0700724sp<UserClient> Layer::ClientRef::getClient() const {
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700725 Mutex::Autolock _l(mLock);
Mathias Agopian579b3f82010-06-08 19:54:15 -0700726 return mUserClient.promote();
727}
728
729status_t Layer::ClientRef::setToken(const sp<UserClient>& uc,
730 const sp<SharedBufferServer>& sharedClient, int32_t token) {
731 Mutex::Autolock _l(mLock);
732
733 { // scope for strong mUserClient reference
734 sp<UserClient> userClient(mUserClient.promote());
735 if (mUserClient != 0 && mControlBlock != 0) {
736 mControlBlock->setStatus(NO_INIT);
737 }
738 }
739
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700740 mUserClient = uc;
741 mToken = token;
Mathias Agopian579b3f82010-06-08 19:54:15 -0700742 mControlBlock = sharedClient;
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700743 return NO_ERROR;
744}
745
746sp<UserClient> Layer::ClientRef::getUserClientUnsafe() const {
747 return mUserClient.promote();
748}
749
750// this class gives us access to SharedBufferServer safely
751// it makes sure the UserClient (and its associated shared memory)
752// won't go away while we're accessing it.
753Layer::ClientRef::Access::Access(const ClientRef& ref)
Mathias Agopian579b3f82010-06-08 19:54:15 -0700754 : mControlBlock(0)
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700755{
756 Mutex::Autolock _l(ref.mLock);
757 mUserClientStrongRef = ref.mUserClient.promote();
758 if (mUserClientStrongRef != 0)
Mathias Agopian579b3f82010-06-08 19:54:15 -0700759 mControlBlock = ref.mControlBlock;
760}
761
762Layer::ClientRef::Access::~Access()
763{
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700764}
765
766// ---------------------------------------------------------------------------
767
Mathias Agopiand606de62010-05-10 20:06:11 -0700768Layer::BufferManager::BufferManager(TextureManager& tm)
Mathias Agopianbb641242010-05-18 17:06:55 -0700769 : mNumBuffers(NUM_BUFFERS), mTextureManager(tm),
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700770 mActiveBuffer(-1), mFailover(false)
Mathias Agopiand606de62010-05-10 20:06:11 -0700771{
772}
773
Mathias Agopianbb641242010-05-18 17:06:55 -0700774Layer::BufferManager::~BufferManager()
775{
776}
777
778status_t Layer::BufferManager::resize(size_t size)
779{
780 Mutex::Autolock _l(mLock);
781 mNumBuffers = size;
782 return NO_ERROR;
Mathias Agopiand606de62010-05-10 20:06:11 -0700783}
784
785// only for debugging
786sp<GraphicBuffer> Layer::BufferManager::getBuffer(size_t index) const {
787 return mBufferData[index].buffer;
788}
789
790status_t Layer::BufferManager::setActiveBufferIndex(size_t index) {
Mathias Agopiand606de62010-05-10 20:06:11 -0700791 mActiveBuffer = index;
792 return NO_ERROR;
793}
794
795size_t Layer::BufferManager::getActiveBufferIndex() const {
796 return mActiveBuffer;
797}
798
799Texture Layer::BufferManager::getActiveTexture() const {
Mathias Agopianbb641242010-05-18 17:06:55 -0700800 Texture res;
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700801 if (mFailover || mActiveBuffer<0) {
Mathias Agopianbb641242010-05-18 17:06:55 -0700802 res = mFailoverTexture;
803 } else {
804 static_cast<Image&>(res) = mBufferData[mActiveBuffer].texture;
805 }
806 return res;
Mathias Agopiand606de62010-05-10 20:06:11 -0700807}
808
809sp<GraphicBuffer> Layer::BufferManager::getActiveBuffer() const {
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700810 sp<GraphicBuffer> result;
811 const ssize_t activeBuffer = mActiveBuffer;
812 if (activeBuffer >= 0) {
813 BufferData const * const buffers = mBufferData;
814 Mutex::Autolock _l(mLock);
815 result = buffers[activeBuffer].buffer;
816 }
817 return result;
Mathias Agopiand606de62010-05-10 20:06:11 -0700818}
819
820sp<GraphicBuffer> Layer::BufferManager::detachBuffer(size_t index)
821{
Mathias Agopianbb641242010-05-18 17:06:55 -0700822 BufferData* const buffers = mBufferData;
Mathias Agopiand606de62010-05-10 20:06:11 -0700823 sp<GraphicBuffer> buffer;
824 Mutex::Autolock _l(mLock);
Mathias Agopianbb641242010-05-18 17:06:55 -0700825 buffer = buffers[index].buffer;
826 buffers[index].buffer = 0;
Mathias Agopiand606de62010-05-10 20:06:11 -0700827 return buffer;
828}
829
830status_t Layer::BufferManager::attachBuffer(size_t index,
831 const sp<GraphicBuffer>& buffer)
832{
Mathias Agopianbb641242010-05-18 17:06:55 -0700833 BufferData* const buffers = mBufferData;
Mathias Agopiand606de62010-05-10 20:06:11 -0700834 Mutex::Autolock _l(mLock);
Mathias Agopianbb641242010-05-18 17:06:55 -0700835 buffers[index].buffer = buffer;
836 buffers[index].texture.dirty = true;
Mathias Agopiand606de62010-05-10 20:06:11 -0700837 return NO_ERROR;
838}
839
840status_t Layer::BufferManager::destroy(EGLDisplay dpy)
841{
Mathias Agopianbb641242010-05-18 17:06:55 -0700842 BufferData* const buffers = mBufferData;
843 size_t num;
844 { // scope for the lock
845 Mutex::Autolock _l(mLock);
846 num = mNumBuffers;
847 for (size_t i=0 ; i<num ; i++) {
848 buffers[i].buffer = 0;
849 }
850 }
851 for (size_t i=0 ; i<num ; i++) {
852 destroyTexture(&buffers[i].texture, dpy);
Mathias Agopiand606de62010-05-10 20:06:11 -0700853 }
854 destroyTexture(&mFailoverTexture, dpy);
855 return NO_ERROR;
856}
857
858status_t Layer::BufferManager::initEglImage(EGLDisplay dpy,
859 const sp<GraphicBuffer>& buffer)
860{
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700861 status_t err = NO_INIT;
862 ssize_t index = mActiveBuffer;
863 if (index >= 0) {
Mathias Agopian1f7bec62010-06-25 18:02:21 -0700864 if (!mFailover) {
865 Image& texture(mBufferData[index].texture);
866 err = mTextureManager.initEglImage(&texture, dpy, buffer);
867 // if EGLImage fails, we switch to regular texture mode, and we
868 // free all resources associated with using EGLImages.
869 if (err == NO_ERROR) {
870 mFailover = false;
871 destroyTexture(&mFailoverTexture, dpy);
872 } else {
873 mFailover = true;
874 const size_t num = mNumBuffers;
875 for (size_t i=0 ; i<num ; i++) {
876 destroyTexture(&mBufferData[i].texture, dpy);
877 }
Andreas Hubere049a952010-06-25 09:25:19 -0700878 }
Mathias Agopian1f7bec62010-06-25 18:02:21 -0700879 } else {
880 // we failed once, don't try again
881 err = BAD_VALUE;
Mathias Agopiand606de62010-05-10 20:06:11 -0700882 }
883 }
884 return err;
885}
886
887status_t Layer::BufferManager::loadTexture(
888 const Region& dirty, const GGLSurface& t)
889{
890 return mTextureManager.loadTexture(&mFailoverTexture, dirty, t);
891}
892
Mathias Agopianbb641242010-05-18 17:06:55 -0700893status_t Layer::BufferManager::destroyTexture(Image* tex, EGLDisplay dpy)
894{
895 if (tex->name != -1U) {
896 glDeleteTextures(1, &tex->name);
897 tex->name = -1U;
898 }
899 if (tex->image != EGL_NO_IMAGE_KHR) {
900 eglDestroyImageKHR(dpy, tex->image);
901 tex->image = EGL_NO_IMAGE_KHR;
902 }
903 return NO_ERROR;
904}
905
Mathias Agopiand606de62010-05-10 20:06:11 -0700906// ---------------------------------------------------------------------------
907
Mathias Agopian9a112062009-04-17 19:36:26 -0700908Layer::SurfaceLayer::SurfaceLayer(const sp<SurfaceFlinger>& flinger,
Mathias Agopian96f08192010-06-02 23:28:45 -0700909 const sp<Layer>& owner)
910 : Surface(flinger, owner->getIdentity(), owner)
Mathias Agopian9a112062009-04-17 19:36:26 -0700911{
912}
913
914Layer::SurfaceLayer::~SurfaceLayer()
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700915{
916}
917
Mathias Agopiana138f892010-05-21 17:24:35 -0700918sp<GraphicBuffer> Layer::SurfaceLayer::requestBuffer(int index,
919 uint32_t w, uint32_t h, uint32_t format, uint32_t usage)
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700920{
Mathias Agopian3330b202009-10-05 17:07:12 -0700921 sp<GraphicBuffer> buffer;
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700922 sp<Layer> owner(getOwner());
923 if (owner != 0) {
Mathias Agopianbb641242010-05-18 17:06:55 -0700924 /*
925 * requestBuffer() cannot be called from the main thread
926 * as it could cause a dead-lock, since it may have to wait
927 * on conditions updated my the main thread.
928 */
Mathias Agopiana138f892010-05-21 17:24:35 -0700929 buffer = owner->requestBuffer(index, w, h, format, usage);
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700930 }
931 return buffer;
932}
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800933
Mathias Agopianb5b7f262010-05-07 15:58:44 -0700934status_t Layer::SurfaceLayer::setBufferCount(int bufferCount)
935{
936 status_t err = DEAD_OBJECT;
937 sp<Layer> owner(getOwner());
938 if (owner != 0) {
Mathias Agopianbb641242010-05-18 17:06:55 -0700939 /*
940 * setBufferCount() cannot be called from the main thread
941 * as it could cause a dead-lock, since it may have to wait
942 * on conditions updated my the main thread.
943 */
Mathias Agopianb5b7f262010-05-07 15:58:44 -0700944 err = owner->setBufferCount(bufferCount);
945 }
946 return err;
947}
948
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800949// ---------------------------------------------------------------------------
950
951
952}; // namespace android