blob: fb76720084c6b69fed3f55009720fca63f5f6aa3 [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"
Mathias Agopiana350ff92010-08-10 17:14:02 -070038#include "DisplayHardware/HWComposer.h"
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080039
40
41#define DEBUG_RESIZE 0
42
43
44namespace android {
45
Mathias Agopianca99fb82010-04-14 16:43:44 -070046template <typename T> inline T min(T a, T b) {
47 return a<b ? a : b;
48}
49
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080050// ---------------------------------------------------------------------------
51
Mathias Agopian96f08192010-06-02 23:28:45 -070052Layer::Layer(SurfaceFlinger* flinger,
53 DisplayID display, const sp<Client>& client)
54 : LayerBaseClient(flinger, display, client),
Mathias Agopian1f7bec62010-06-25 18:02:21 -070055 mGLExtensions(GLExtensions::getInstance()),
Mathias Agopian401c2572009-09-23 19:16:27 -070056 mNeedsBlending(true),
Mathias Agopiand606de62010-05-10 20:06:11 -070057 mNeedsDithering(false),
Mathias Agopianb7e930d2010-06-01 15:12:58 -070058 mSecure(false),
Mathias Agopian1f7bec62010-06-25 18:02:21 -070059 mTextureManager(),
Mathias Agopiana138f892010-05-21 17:24:35 -070060 mBufferManager(mTextureManager),
61 mWidth(0), mHeight(0), mFixedSize(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 Agopianb7e930d2010-06-01 15:12:58 -070079status_t Layer::setToken(const sp<UserClient>& userClient,
80 SharedClient* sharedClient, int32_t token)
Mathias Agopian96f08192010-06-02 23:28:45 -070081{
Mathias Agopian579b3f82010-06-08 19:54:15 -070082 sp<SharedBufferServer> lcblk = new SharedBufferServer(
Mathias Agopianb7e930d2010-06-01 15:12:58 -070083 sharedClient, token, mBufferManager.getDefaultBufferCount(),
Mathias Agopian96f08192010-06-02 23:28:45 -070084 getIdentity());
85
Mathias Agopianb7e930d2010-06-01 15:12:58 -070086 status_t err = mUserClientRef.setToken(userClient, lcblk, token);
Mathias Agopian579b3f82010-06-08 19:54:15 -070087
88 LOGE_IF(err != NO_ERROR,
89 "ClientRef::setToken(%p, %p, %u) failed",
90 userClient.get(), lcblk.get(), token);
91
92 if (err == NO_ERROR) {
93 // we need to free the buffers associated with this surface
Mathias Agopianb7e930d2010-06-01 15:12:58 -070094 }
95
96 return err;
97}
98
99int32_t Layer::getToken() const
100{
101 return mUserClientRef.getToken();
Mathias Agopian96f08192010-06-02 23:28:45 -0700102}
103
Mathias Agopian579b3f82010-06-08 19:54:15 -0700104sp<UserClient> Layer::getClient() const
105{
106 return mUserClientRef.getClient();
107}
108
Mathias Agopiand606de62010-05-10 20:06:11 -0700109// called with SurfaceFlinger::mStateLock as soon as the layer is entered
110// in the purgatory list
111void Layer::onRemoved()
112{
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700113 ClientRef::Access sharedClient(mUserClientRef);
114 SharedBufferServer* lcblk(sharedClient.get());
115 if (lcblk) {
Mathias Agopian96f08192010-06-02 23:28:45 -0700116 // wake up the condition
117 lcblk->setStatus(NO_INIT);
118 }
Mathias Agopian48d819a2009-09-10 19:41:18 -0700119}
Mathias Agopiancbb288b2009-09-07 16:32:45 -0700120
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700121sp<LayerBaseClient::Surface> Layer::createSurface() const
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800122{
123 return mSurface;
124}
125
Mathias Agopian9a112062009-04-17 19:36:26 -0700126status_t Layer::ditch()
127{
Mathias Agopianbb641242010-05-18 17:06:55 -0700128 // NOTE: Called from the main UI thread
129
Mathias Agopian0aa758d2009-04-22 15:23:34 -0700130 // the layer is not on screen anymore. free as much resources as possible
Mathias Agopianf5430db2009-12-11 00:56:10 -0800131 mFreezeLock.clear();
Mathias Agopianbb641242010-05-18 17:06:55 -0700132
133 EGLDisplay dpy(mFlinger->graphicPlane(0).getEGLDisplay());
134 mBufferManager.destroy(dpy);
135 mSurface.clear();
136
137 Mutex::Autolock _l(mLock);
138 mWidth = mHeight = 0;
Mathias Agopian9a112062009-04-17 19:36:26 -0700139 return NO_ERROR;
140}
141
Mathias Agopianf9d93272009-06-19 17:00:27 -0700142status_t Layer::setBuffers( uint32_t w, uint32_t h,
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800143 PixelFormat format, uint32_t flags)
144{
Mathias Agopian401c2572009-09-23 19:16:27 -0700145 // this surfaces pixel format
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800146 PixelFormatInfo info;
147 status_t err = getPixelFormatInfo(format, &info);
148 if (err) return err;
149
Mathias Agopian401c2572009-09-23 19:16:27 -0700150 // the display's pixel format
151 const DisplayHardware& hw(graphicPlane(0).displayHardware());
Mathias Agopianca99fb82010-04-14 16:43:44 -0700152 uint32_t const maxSurfaceDims = min(
153 hw.getMaxTextureSize(), hw.getMaxViewportDims());
154
155 // never allow a surface larger than what our underlying GL implementation
156 // can handle.
157 if ((uint32_t(w)>maxSurfaceDims) || (uint32_t(h)>maxSurfaceDims)) {
158 return BAD_VALUE;
159 }
160
Mathias Agopian401c2572009-09-23 19:16:27 -0700161 PixelFormatInfo displayInfo;
162 getPixelFormatInfo(hw.getFormat(), &displayInfo);
Mathias Agopiana4b740e2009-10-05 18:20:39 -0700163 const uint32_t hwFlags = hw.getFlags();
164
Mathias Agopiancbb288b2009-09-07 16:32:45 -0700165 mFormat = format;
Mathias Agopianca99fb82010-04-14 16:43:44 -0700166 mWidth = w;
Mathias Agopiancbb288b2009-09-07 16:32:45 -0700167 mHeight = h;
Mathias Agopianeff062c2010-08-25 14:59:15 -0700168
169 mReqFormat = format;
170 mReqWidth = w;
171 mReqHeight = h;
172
Mathias Agopian3330b202009-10-05 17:07:12 -0700173 mSecure = (flags & ISurfaceComposer::eSecure) ? true : false;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800174 mNeedsBlending = (info.h_alpha - info.l_alpha) > 0;
Mathias Agopianca99fb82010-04-14 16:43:44 -0700175
Mathias Agopian401c2572009-09-23 19:16:27 -0700176 // we use the red index
177 int displayRedSize = displayInfo.getSize(PixelFormatInfo::INDEX_RED);
178 int layerRedsize = info.getSize(PixelFormatInfo::INDEX_RED);
179 mNeedsDithering = layerRedsize > displayRedSize;
180
Mathias Agopian96f08192010-06-02 23:28:45 -0700181 mSurface = new SurfaceLayer(mFlinger, this);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800182 return NO_ERROR;
183}
184
Mathias Agopiana350ff92010-08-10 17:14:02 -0700185void Layer::setGeometry(hwc_layer_t* hwcl)
186{
187 hwcl->compositionType = HWC_FRAMEBUFFER;
188 hwcl->hints = 0;
189 hwcl->flags = 0;
190 hwcl->transform = 0;
191 hwcl->blending = HWC_BLENDING_NONE;
192
193 // we can't do alpha-fade with the hwc HAL
194 const State& s(drawingState());
195 if (s.alpha < 0xFF) {
196 hwcl->flags = HWC_SKIP_LAYER;
197 return;
198 }
199
200 // we can only handle simple transformation
201 if (mOrientation & Transform::ROT_INVALID) {
202 hwcl->flags = HWC_SKIP_LAYER;
203 return;
204 }
205
206 hwcl->transform = mOrientation;
207
208 if (needsBlending()) {
209 hwcl->blending = mPremultipliedAlpha ?
210 HWC_BLENDING_PREMULT : HWC_BLENDING_COVERAGE;
211 }
212
213 hwcl->displayFrame.left = mTransformedBounds.left;
214 hwcl->displayFrame.top = mTransformedBounds.top;
215 hwcl->displayFrame.right = mTransformedBounds.right;
216 hwcl->displayFrame.bottom = mTransformedBounds.bottom;
217
218 hwcl->visibleRegionScreen.rects =
219 reinterpret_cast<hwc_rect_t const *>(
220 visibleRegionScreen.getArray(
221 &hwcl->visibleRegionScreen.numRects));
222}
223
224void Layer::setPerFrameData(hwc_layer_t* hwcl) {
225 sp<GraphicBuffer> buffer(mBufferManager.getActiveBuffer());
226 if (buffer == NULL) {
227 // this situation can happen if we ran out of memory for instance.
228 // not much we can do. continue to use whatever texture was bound
229 // to this context.
230 hwcl->handle = NULL;
231 return;
232 }
233 hwcl->handle = const_cast<native_handle_t*>(buffer->handle);
234 // TODO: set the crop value properly
235 hwcl->sourceCrop.left = 0;
236 hwcl->sourceCrop.top = 0;
237 hwcl->sourceCrop.right = buffer->width;
238 hwcl->sourceCrop.bottom = buffer->height;
239}
240
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800241void Layer::reloadTexture(const Region& dirty)
242{
Mathias Agopiand606de62010-05-10 20:06:11 -0700243 sp<GraphicBuffer> buffer(mBufferManager.getActiveBuffer());
Mathias Agopian8f03b472009-12-10 15:52:29 -0800244 if (buffer == NULL) {
245 // this situation can happen if we ran out of memory for instance.
246 // not much we can do. continue to use whatever texture was bound
247 // to this context.
248 return;
249 }
250
Mathias Agopian1f7bec62010-06-25 18:02:21 -0700251 if (mGLExtensions.haveDirectTexture()) {
Mathias Agopiand606de62010-05-10 20:06:11 -0700252 EGLDisplay dpy(mFlinger->graphicPlane(0).getEGLDisplay());
253 if (mBufferManager.initEglImage(dpy, buffer) != NO_ERROR) {
254 // not sure what we can do here...
Mathias Agopiand606de62010-05-10 20:06:11 -0700255 goto slowpath;
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700256 }
Mathias Agopian1f7bec62010-06-25 18:02:21 -0700257 } else {
Mathias Agopianfcfeb4b2010-03-08 11:14:20 -0800258slowpath:
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700259 GGLSurface t;
Mathias Agopianf1b38242010-08-20 15:59:53 -0700260 if (buffer->usage & GRALLOC_USAGE_SW_READ_MASK) {
261 status_t res = buffer->lock(&t, GRALLOC_USAGE_SW_READ_OFTEN);
262 LOGE_IF(res, "error %d (%s) locking buffer %p",
263 res, strerror(res), buffer.get());
264 if (res == NO_ERROR) {
265 mBufferManager.loadTexture(dirty, t);
266 buffer->unlock();
267 }
268 } else {
269 // we can't do anything
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700270 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800271 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800272}
273
Mathias Agopian74c40c02010-09-29 13:02:36 -0700274void Layer::drawForSreenShot() const
275{
276 bool currentFixedSize = mFixedSize;
277 bool currentBlending = mNeedsBlending;
278 const_cast<Layer*>(this)->mFixedSize = false;
279 const_cast<Layer*>(this)->mFixedSize = true;
280 LayerBase::drawForSreenShot();
281 const_cast<Layer*>(this)->mFixedSize = currentFixedSize;
282 const_cast<Layer*>(this)->mNeedsBlending = currentBlending;
283}
284
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800285void Layer::onDraw(const Region& clip) const
286{
Mathias Agopiand606de62010-05-10 20:06:11 -0700287 Texture tex(mBufferManager.getActiveTexture());
288 if (tex.name == -1LU) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800289 // the texture has not been created yet, this Layer has
Mathias Agopian179169e2010-05-06 20:21:45 -0700290 // in fact never been drawn into. This happens frequently with
291 // SurfaceView because the WindowManager can't know when the client
292 // has drawn the first time.
293
294 // If there is nothing under us, we paint the screen in black, otherwise
295 // we just skip this update.
296
297 // figure out if there is something below us
298 Region under;
299 const SurfaceFlinger::LayerVector& drawingLayers(mFlinger->mDrawingState.layersSortedByZ);
300 const size_t count = drawingLayers.size();
301 for (size_t i=0 ; i<count ; ++i) {
302 const sp<LayerBase>& layer(drawingLayers[i]);
303 if (layer.get() == static_cast<LayerBase const*>(this))
304 break;
305 under.orSelf(layer->visibleRegionScreen);
306 }
307 // if not everything below us is covered, we plug the holes!
308 Region holes(clip.subtract(under));
309 if (!holes.isEmpty()) {
Mathias Agopian0a917752010-06-14 21:20:00 -0700310 clearWithOpenGL(holes, 0, 0, 0, 1);
Mathias Agopian179169e2010-05-06 20:21:45 -0700311 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800312 return;
313 }
Mathias Agopiand606de62010-05-10 20:06:11 -0700314 drawWithOpenGL(clip, tex);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800315}
316
Mathias Agopiana7f66922010-05-26 22:08:52 -0700317bool Layer::needsFiltering() const
318{
319 if (!(mFlags & DisplayHardware::SLOW_CONFIG)) {
320 // NOTE: there is a race here, because mFixedSize is updated in a
321 // binder transaction. however, it doesn't really matter since it is
322 // evaluated each time we draw. To be perfectly correct, this flag
323 // would have to be associated with a buffer.
324 if (mFixedSize)
325 return true;
326 }
327 return LayerBase::needsFiltering();
328}
329
Mathias Agopianb5b7f262010-05-07 15:58:44 -0700330
331status_t Layer::setBufferCount(int bufferCount)
332{
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700333 ClientRef::Access sharedClient(mUserClientRef);
334 SharedBufferServer* lcblk(sharedClient.get());
335 if (!lcblk) {
Mathias Agopianb5b7f262010-05-07 15:58:44 -0700336 // oops, the client is already gone
337 return DEAD_OBJECT;
338 }
339
Mathias Agopianbb641242010-05-18 17:06:55 -0700340 // NOTE: lcblk->resize() is protected by an internal lock
341 status_t err = lcblk->resize(bufferCount);
342 if (err == NO_ERROR)
343 mBufferManager.resize(bufferCount);
Mathias Agopianb5b7f262010-05-07 15:58:44 -0700344
345 return err;
346}
347
Mathias Agopiana138f892010-05-21 17:24:35 -0700348sp<GraphicBuffer> Layer::requestBuffer(int index,
349 uint32_t reqWidth, uint32_t reqHeight, uint32_t reqFormat,
350 uint32_t usage)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800351{
Mathias Agopian3330b202009-10-05 17:07:12 -0700352 sp<GraphicBuffer> buffer;
Mathias Agopian48d819a2009-09-10 19:41:18 -0700353
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700354 if (int32_t(reqWidth | reqHeight | reqFormat) < 0)
Mathias Agopiana138f892010-05-21 17:24:35 -0700355 return buffer;
356
357 if ((!reqWidth && reqHeight) || (reqWidth && !reqHeight))
358 return buffer;
359
Mathias Agopian48d819a2009-09-10 19:41:18 -0700360 // this ensures our client doesn't go away while we're accessing
361 // the shared area.
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700362 ClientRef::Access sharedClient(mUserClientRef);
363 SharedBufferServer* lcblk(sharedClient.get());
364 if (!lcblk) {
Mathias Agopian48d819a2009-09-10 19:41:18 -0700365 // oops, the client is already gone
366 return buffer;
367 }
368
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700369 /*
Mathias Agopiancbb288b2009-09-07 16:32:45 -0700370 * This is called from the client's Surface::dequeue(). This can happen
371 * at any time, especially while we're in the middle of using the
372 * buffer 'index' as our front buffer.
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700373 */
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800374
Mathias Agopian208cb072010-07-27 20:11:35 -0700375 status_t err = NO_ERROR;
Mathias Agopiana138f892010-05-21 17:24:35 -0700376 uint32_t w, h, f;
Mathias Agopian48d819a2009-09-10 19:41:18 -0700377 { // scope for the lock
378 Mutex::Autolock _l(mLock);
Mathias Agopianeff062c2010-08-25 14:59:15 -0700379
380 // zero means default
Mathias Agopiane44d21a2010-09-21 10:52:42 -0700381 const bool fixedSize = reqWidth && reqHeight;
Mathias Agopianeff062c2010-08-25 14:59:15 -0700382 if (!reqFormat) reqFormat = mFormat;
383 if (!reqWidth) reqWidth = mWidth;
384 if (!reqHeight) reqHeight = mHeight;
385
386 w = reqWidth;
387 h = reqHeight;
388 f = reqFormat;
389
390 if ((reqWidth != mReqWidth) || (reqHeight != mReqHeight) ||
391 (reqFormat != mReqFormat)) {
392 mReqWidth = reqWidth;
393 mReqHeight = reqHeight;
394 mReqFormat = reqFormat;
Mathias Agopiane44d21a2010-09-21 10:52:42 -0700395 mFixedSize = fixedSize;
Mathias Agopianeff062c2010-08-25 14:59:15 -0700396
Mathias Agopiana138f892010-05-21 17:24:35 -0700397 lcblk->reallocateAllExcept(index);
398 }
Mathias Agopian48d819a2009-09-10 19:41:18 -0700399 }
400
Mathias Agopian208cb072010-07-27 20:11:35 -0700401 // here we have to reallocate a new buffer because the buffer could be
402 // used as the front buffer, or by a client in our process
403 // (eg: status bar), and we can't release the handle under its feet.
Mathias Agopian3330b202009-10-05 17:07:12 -0700404 const uint32_t effectiveUsage = getEffectiveUsage(usage);
Mathias Agopian208cb072010-07-27 20:11:35 -0700405 buffer = new GraphicBuffer(w, h, f, effectiveUsage);
406 err = buffer->initCheck();
Mathias Agopiancbb288b2009-09-07 16:32:45 -0700407
408 if (err || buffer->handle == 0) {
409 LOGE_IF(err || buffer->handle == 0,
410 "Layer::requestBuffer(this=%p), index=%d, w=%d, h=%d failed (%s)",
411 this, index, w, h, strerror(-err));
412 } else {
413 LOGD_IF(DEBUG_RESIZE,
Mathias Agopian7e4a5872009-09-29 22:39:22 -0700414 "Layer::requestBuffer(this=%p), index=%d, w=%d, h=%d, handle=%p",
415 this, index, w, h, buffer->handle);
Mathias Agopiancbb288b2009-09-07 16:32:45 -0700416 }
417
418 if (err == NO_ERROR && buffer->handle != 0) {
Mathias Agopian48d819a2009-09-10 19:41:18 -0700419 Mutex::Autolock _l(mLock);
Mathias Agopiana138f892010-05-21 17:24:35 -0700420 mBufferManager.attachBuffer(index, buffer);
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700421 }
422 return buffer;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800423}
424
Mathias Agopian3330b202009-10-05 17:07:12 -0700425uint32_t Layer::getEffectiveUsage(uint32_t usage) const
426{
427 /*
428 * buffers used for software rendering, but h/w composition
429 * are allocated with SW_READ_OFTEN | SW_WRITE_OFTEN | HW_TEXTURE
430 *
431 * buffers used for h/w rendering and h/w composition
432 * are allocated with HW_RENDER | HW_TEXTURE
433 *
434 * buffers used with h/w rendering and either NPOT or no egl_image_ext
435 * are allocated with SW_READ_RARELY | HW_RENDER
436 *
437 */
438
439 if (mSecure) {
440 // secure buffer, don't store it into the GPU
441 usage = GraphicBuffer::USAGE_SW_READ_OFTEN |
442 GraphicBuffer::USAGE_SW_WRITE_OFTEN;
443 } else {
444 // it's allowed to modify the usage flags here, but generally
445 // the requested flags should be honored.
Mathias Agopian89141f92010-05-10 20:10:10 -0700446 // request EGLImage for all buffers
447 usage |= GraphicBuffer::USAGE_HW_TEXTURE;
Mathias Agopian3330b202009-10-05 17:07:12 -0700448 }
449 return usage;
450}
451
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800452uint32_t Layer::doTransaction(uint32_t flags)
453{
454 const Layer::State& front(drawingState());
455 const Layer::State& temp(currentState());
456
Mathias Agopiana138f892010-05-21 17:24:35 -0700457 const bool sizeChanged = (front.requested_w != temp.requested_w) ||
458 (front.requested_h != temp.requested_h);
459
460 if (sizeChanged) {
Mathias Agopiancbb288b2009-09-07 16:32:45 -0700461 // the size changed, we need to ask our client to request a new buffer
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800462 LOGD_IF(DEBUG_RESIZE,
Mathias Agopiana138f892010-05-21 17:24:35 -0700463 "resize (layer=%p), requested (%dx%d), drawing (%d,%d)",
464 this,
465 int(temp.requested_w), int(temp.requested_h),
466 int(front.requested_w), int(front.requested_h));
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800467
Mathias Agopiana138f892010-05-21 17:24:35 -0700468 if (!isFixedSize()) {
469 // we're being resized and there is a freeze display request,
470 // acquire a freeze lock, so that the screen stays put
471 // until we've redrawn at the new size; this is to avoid
472 // glitches upon orientation changes.
473 if (mFlinger->hasFreezeRequest()) {
474 // if the surface is hidden, don't try to acquire the
475 // freeze lock, since hidden surfaces may never redraw
476 if (!(front.flags & ISurfaceComposer::eLayerHidden)) {
477 mFreezeLock = mFlinger->getFreezeLock();
478 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800479 }
Mathias Agopiana138f892010-05-21 17:24:35 -0700480
481 // this will make sure LayerBase::doTransaction doesn't update
482 // the drawing state's size
483 Layer::State& editDraw(mDrawingState);
484 editDraw.requested_w = temp.requested_w;
485 editDraw.requested_h = temp.requested_h;
486
487 // record the new size, form this point on, when the client request
488 // a buffer, it'll get the new size.
489 setBufferSize(temp.requested_w, temp.requested_h);
490
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700491 ClientRef::Access sharedClient(mUserClientRef);
492 SharedBufferServer* lcblk(sharedClient.get());
493 if (lcblk) {
Mathias Agopian96f08192010-06-02 23:28:45 -0700494 // all buffers need reallocation
495 lcblk->reallocateAll();
496 }
Mathias Agopiana138f892010-05-21 17:24:35 -0700497 } else {
498 // record the new size
499 setBufferSize(temp.requested_w, temp.requested_h);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800500 }
501 }
Mathias Agopiancbb288b2009-09-07 16:32:45 -0700502
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800503 if (temp.sequence != front.sequence) {
504 if (temp.flags & ISurfaceComposer::eLayerHidden || temp.alpha == 0) {
505 // this surface is now hidden, so it shouldn't hold a freeze lock
506 // (it may never redraw, which is fine if it is hidden)
507 mFreezeLock.clear();
508 }
509 }
510
511 return LayerBase::doTransaction(flags);
512}
513
Mathias Agopiana138f892010-05-21 17:24:35 -0700514void Layer::setBufferSize(uint32_t w, uint32_t h) {
Mathias Agopiancbb288b2009-09-07 16:32:45 -0700515 Mutex::Autolock _l(mLock);
516 mWidth = w;
517 mHeight = h;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800518}
519
Mathias Agopiana138f892010-05-21 17:24:35 -0700520bool Layer::isFixedSize() const {
521 Mutex::Autolock _l(mLock);
522 return mFixedSize;
523}
524
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800525// ----------------------------------------------------------------------------
526// pageflip handling...
527// ----------------------------------------------------------------------------
528
529void Layer::lockPageFlip(bool& recomputeVisibleRegions)
530{
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700531 ClientRef::Access sharedClient(mUserClientRef);
532 SharedBufferServer* lcblk(sharedClient.get());
533 if (!lcblk) {
Mathias Agopian96f08192010-06-02 23:28:45 -0700534 // client died
535 recomputeVisibleRegions = true;
536 return;
537 }
538
Mathias Agopiancbb288b2009-09-07 16:32:45 -0700539 ssize_t buf = lcblk->retireAndLock();
Mathias Agopiand606de62010-05-10 20:06:11 -0700540 if (buf == NOT_ENOUGH_DATA) {
541 // NOTE: This is not an error, it simply means there is nothing to
542 // retire. The buffer is locked because we will use it
Mathias Agopiancbb288b2009-09-07 16:32:45 -0700543 // for composition later in the loop
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800544 return;
545 }
Mathias Agopiand343e3d2010-03-15 18:15:20 -0700546
Mathias Agopiand606de62010-05-10 20:06:11 -0700547 if (buf < NO_ERROR) {
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700548 LOGE("retireAndLock() buffer index (%d) out of range", int(buf));
Mathias Agopiand343e3d2010-03-15 18:15:20 -0700549 mPostedDirtyRegion.clear();
550 return;
551 }
552
Mathias Agopiancbb288b2009-09-07 16:32:45 -0700553 // we retired a buffer, which becomes the new front buffer
Mathias Agopiand606de62010-05-10 20:06:11 -0700554 if (mBufferManager.setActiveBufferIndex(buf) < NO_ERROR) {
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700555 LOGE("retireAndLock() buffer index (%d) out of range", int(buf));
Mathias Agopiand606de62010-05-10 20:06:11 -0700556 mPostedDirtyRegion.clear();
557 return;
558 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800559
Mathias Agopian3330b202009-10-05 17:07:12 -0700560 sp<GraphicBuffer> newFrontBuffer(getBuffer(buf));
Mathias Agopiand343e3d2010-03-15 18:15:20 -0700561 if (newFrontBuffer != NULL) {
Mathias Agopianb661d662010-08-19 17:01:19 -0700562 // get the dirty region
Mathias Agopiand343e3d2010-03-15 18:15:20 -0700563 // compute the posted region
564 const Region dirty(lcblk->getDirtyRegion(buf));
565 mPostedDirtyRegion = dirty.intersect( newFrontBuffer->getBounds() );
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700566
Mathias Agopiand343e3d2010-03-15 18:15:20 -0700567 // update the layer size and release freeze-lock
568 const Layer::State& front(drawingState());
569 if (newFrontBuffer->getWidth() == front.requested_w &&
570 newFrontBuffer->getHeight() == front.requested_h)
Mathias Agopiandf3e0b92009-09-30 14:07:22 -0700571 {
Mathias Agopiand343e3d2010-03-15 18:15:20 -0700572 if ((front.w != front.requested_w) ||
573 (front.h != front.requested_h))
574 {
575 // Here we pretend the transaction happened by updating the
576 // current and drawing states. Drawing state is only accessed
577 // in this thread, no need to have it locked
578 Layer::State& editDraw(mDrawingState);
579 editDraw.w = editDraw.requested_w;
580 editDraw.h = editDraw.requested_h;
Mathias Agopiandf3e0b92009-09-30 14:07:22 -0700581
Mathias Agopiand343e3d2010-03-15 18:15:20 -0700582 // We also need to update the current state so that we don't
583 // end-up doing too much work during the next transaction.
584 // NOTE: We actually don't need hold the transaction lock here
585 // because State::w and State::h are only accessed from
586 // this thread
587 Layer::State& editTemp(currentState());
588 editTemp.w = editDraw.w;
589 editTemp.h = editDraw.h;
Mathias Agopiandf3e0b92009-09-30 14:07:22 -0700590
Mathias Agopiand343e3d2010-03-15 18:15:20 -0700591 // recompute visible region
592 recomputeVisibleRegions = true;
593 }
594
595 // we now have the correct size, unfreeze the screen
596 mFreezeLock.clear();
Mathias Agopiandf3e0b92009-09-30 14:07:22 -0700597 }
Mathias Agopianb661d662010-08-19 17:01:19 -0700598
599 // get the crop region
600 setBufferCrop( lcblk->getCrop(buf) );
601
602 // get the transformation
603 setBufferTransform( lcblk->getTransform(buf) );
604
Mathias Agopiand343e3d2010-03-15 18:15:20 -0700605 } else {
606 // this should not happen unless we ran out of memory while
607 // allocating the buffer. we're hoping that things will get back
608 // to normal the next time the app tries to draw into this buffer.
609 // meanwhile, pretend the screen didn't update.
610 mPostedDirtyRegion.clear();
Mathias Agopiancaa600c2009-09-16 18:27:24 -0700611 }
612
Mathias Agopiane7005012009-10-07 16:44:10 -0700613 if (lcblk->getQueuedCount()) {
614 // signal an event if we have more buffers waiting
615 mFlinger->signalEvent();
616 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800617
Mathias Agopian245e4d72010-04-21 15:24:11 -0700618 /* a buffer was posted, so we need to call reloadTexture(), which
619 * will update our internal data structures (eg: EGLImageKHR or
620 * texture names). we need to do this even if mPostedDirtyRegion is
621 * empty -- it's orthogonal to the fact that a new buffer was posted,
622 * for instance, a degenerate case could be that the user did an empty
623 * update but repainted the buffer with appropriate content (after a
624 * resize for instance).
625 */
626 reloadTexture( mPostedDirtyRegion );
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800627}
628
629void Layer::unlockPageFlip(
630 const Transform& planeTransform, Region& outDirtyRegion)
631{
632 Region dirtyRegion(mPostedDirtyRegion);
633 if (!dirtyRegion.isEmpty()) {
634 mPostedDirtyRegion.clear();
635 // The dirty region is given in the layer's coordinate space
636 // transform the dirty region by the surface's transformation
637 // and the global transformation.
638 const Layer::State& s(drawingState());
639 const Transform tr(planeTransform * s.transform);
640 dirtyRegion = tr.transform(dirtyRegion);
641
642 // At this point, the dirty region is in screen space.
643 // Make sure it's constrained by the visible region (which
644 // is in screen space as well).
645 dirtyRegion.andSelf(visibleRegionScreen);
646 outDirtyRegion.orSelf(dirtyRegion);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800647 }
Mathias Agopianc61de172009-11-30 11:15:41 -0800648 if (visibleRegionScreen.isEmpty()) {
649 // an invisible layer should not hold a freeze-lock
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700650 // (because it may never be updated and therefore never release it)
Mathias Agopianc61de172009-11-30 11:15:41 -0800651 mFreezeLock.clear();
652 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800653}
654
655void Layer::finishPageFlip()
656{
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700657 ClientRef::Access sharedClient(mUserClientRef);
658 SharedBufferServer* lcblk(sharedClient.get());
659 if (lcblk) {
Mathias Agopian96f08192010-06-02 23:28:45 -0700660 int buf = mBufferManager.getActiveBufferIndex();
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700661 if (buf >= 0) {
662 status_t err = lcblk->unlock( buf );
663 LOGE_IF(err!=NO_ERROR,
664 "layer %p, buffer=%d wasn't locked!",
665 this, buf);
666 }
Mathias Agopian96f08192010-06-02 23:28:45 -0700667 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800668}
669
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700670
671void Layer::dump(String8& result, char* buffer, size_t SIZE) const
672{
673 LayerBaseClient::dump(result, buffer, SIZE);
674
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700675 ClientRef::Access sharedClient(mUserClientRef);
676 SharedBufferServer* lcblk(sharedClient.get());
677 uint32_t totalTime = 0;
678 if (lcblk) {
679 SharedBufferStack::Statistics stats = lcblk->getStats();
680 totalTime= stats.totalTime;
681 result.append( lcblk->dump(" ") );
682 }
683
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700684 sp<const GraphicBuffer> buf0(getBuffer(0));
685 sp<const GraphicBuffer> buf1(getBuffer(1));
686 uint32_t w0=0, h0=0, s0=0;
687 uint32_t w1=0, h1=0, s1=0;
688 if (buf0 != 0) {
689 w0 = buf0->getWidth();
690 h0 = buf0->getHeight();
691 s0 = buf0->getStride();
692 }
693 if (buf1 != 0) {
694 w1 = buf1->getWidth();
695 h1 = buf1->getHeight();
696 s1 = buf1->getStride();
697 }
698 snprintf(buffer, SIZE,
699 " "
700 "format=%2d, [%3ux%3u:%3u] [%3ux%3u:%3u],"
701 " freezeLock=%p, dq-q-time=%u us\n",
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700702 mFormat, w0, h0, s0, w1, h1, s1,
703 getFreezeLock().get(), totalTime);
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700704
705 result.append(buffer);
706}
707
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700708// ---------------------------------------------------------------------------
709
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700710Layer::ClientRef::ClientRef()
Mathias Agopian579b3f82010-06-08 19:54:15 -0700711 : mControlBlock(0), mToken(-1) {
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700712}
713
714Layer::ClientRef::~ClientRef() {
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700715}
716
717int32_t Layer::ClientRef::getToken() const {
718 Mutex::Autolock _l(mLock);
719 return mToken;
720}
721
Mathias Agopian579b3f82010-06-08 19:54:15 -0700722sp<UserClient> Layer::ClientRef::getClient() const {
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700723 Mutex::Autolock _l(mLock);
Mathias Agopian579b3f82010-06-08 19:54:15 -0700724 return mUserClient.promote();
725}
726
727status_t Layer::ClientRef::setToken(const sp<UserClient>& uc,
728 const sp<SharedBufferServer>& sharedClient, int32_t token) {
729 Mutex::Autolock _l(mLock);
730
731 { // scope for strong mUserClient reference
732 sp<UserClient> userClient(mUserClient.promote());
733 if (mUserClient != 0 && mControlBlock != 0) {
734 mControlBlock->setStatus(NO_INIT);
735 }
736 }
737
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700738 mUserClient = uc;
739 mToken = token;
Mathias Agopian579b3f82010-06-08 19:54:15 -0700740 mControlBlock = sharedClient;
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700741 return NO_ERROR;
742}
743
744sp<UserClient> Layer::ClientRef::getUserClientUnsafe() const {
745 return mUserClient.promote();
746}
747
748// this class gives us access to SharedBufferServer safely
749// it makes sure the UserClient (and its associated shared memory)
750// won't go away while we're accessing it.
751Layer::ClientRef::Access::Access(const ClientRef& ref)
Mathias Agopian579b3f82010-06-08 19:54:15 -0700752 : mControlBlock(0)
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700753{
754 Mutex::Autolock _l(ref.mLock);
755 mUserClientStrongRef = ref.mUserClient.promote();
756 if (mUserClientStrongRef != 0)
Mathias Agopian579b3f82010-06-08 19:54:15 -0700757 mControlBlock = ref.mControlBlock;
758}
759
760Layer::ClientRef::Access::~Access()
761{
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700762}
763
764// ---------------------------------------------------------------------------
765
Mathias Agopiand606de62010-05-10 20:06:11 -0700766Layer::BufferManager::BufferManager(TextureManager& tm)
Mathias Agopianbb641242010-05-18 17:06:55 -0700767 : mNumBuffers(NUM_BUFFERS), mTextureManager(tm),
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700768 mActiveBuffer(-1), mFailover(false)
Mathias Agopiand606de62010-05-10 20:06:11 -0700769{
770}
771
Mathias Agopianbb641242010-05-18 17:06:55 -0700772Layer::BufferManager::~BufferManager()
773{
774}
775
776status_t Layer::BufferManager::resize(size_t size)
777{
778 Mutex::Autolock _l(mLock);
779 mNumBuffers = size;
780 return NO_ERROR;
Mathias Agopiand606de62010-05-10 20:06:11 -0700781}
782
783// only for debugging
784sp<GraphicBuffer> Layer::BufferManager::getBuffer(size_t index) const {
785 return mBufferData[index].buffer;
786}
787
788status_t Layer::BufferManager::setActiveBufferIndex(size_t index) {
Mathias Agopiand606de62010-05-10 20:06:11 -0700789 mActiveBuffer = index;
790 return NO_ERROR;
791}
792
793size_t Layer::BufferManager::getActiveBufferIndex() const {
794 return mActiveBuffer;
795}
796
797Texture Layer::BufferManager::getActiveTexture() const {
Mathias Agopianbb641242010-05-18 17:06:55 -0700798 Texture res;
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700799 if (mFailover || mActiveBuffer<0) {
Mathias Agopianbb641242010-05-18 17:06:55 -0700800 res = mFailoverTexture;
801 } else {
802 static_cast<Image&>(res) = mBufferData[mActiveBuffer].texture;
803 }
804 return res;
Mathias Agopiand606de62010-05-10 20:06:11 -0700805}
806
807sp<GraphicBuffer> Layer::BufferManager::getActiveBuffer() const {
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700808 sp<GraphicBuffer> result;
809 const ssize_t activeBuffer = mActiveBuffer;
810 if (activeBuffer >= 0) {
811 BufferData const * const buffers = mBufferData;
812 Mutex::Autolock _l(mLock);
813 result = buffers[activeBuffer].buffer;
814 }
815 return result;
Mathias Agopiand606de62010-05-10 20:06:11 -0700816}
817
818sp<GraphicBuffer> Layer::BufferManager::detachBuffer(size_t index)
819{
Mathias Agopianbb641242010-05-18 17:06:55 -0700820 BufferData* const buffers = mBufferData;
Mathias Agopiand606de62010-05-10 20:06:11 -0700821 sp<GraphicBuffer> buffer;
822 Mutex::Autolock _l(mLock);
Mathias Agopianbb641242010-05-18 17:06:55 -0700823 buffer = buffers[index].buffer;
824 buffers[index].buffer = 0;
Mathias Agopiand606de62010-05-10 20:06:11 -0700825 return buffer;
826}
827
828status_t Layer::BufferManager::attachBuffer(size_t index,
829 const sp<GraphicBuffer>& buffer)
830{
Mathias Agopianbb641242010-05-18 17:06:55 -0700831 BufferData* const buffers = mBufferData;
Mathias Agopiand606de62010-05-10 20:06:11 -0700832 Mutex::Autolock _l(mLock);
Mathias Agopianbb641242010-05-18 17:06:55 -0700833 buffers[index].buffer = buffer;
834 buffers[index].texture.dirty = true;
Mathias Agopiand606de62010-05-10 20:06:11 -0700835 return NO_ERROR;
836}
837
838status_t Layer::BufferManager::destroy(EGLDisplay dpy)
839{
Mathias Agopianbb641242010-05-18 17:06:55 -0700840 BufferData* const buffers = mBufferData;
841 size_t num;
842 { // scope for the lock
843 Mutex::Autolock _l(mLock);
844 num = mNumBuffers;
845 for (size_t i=0 ; i<num ; i++) {
846 buffers[i].buffer = 0;
847 }
848 }
849 for (size_t i=0 ; i<num ; i++) {
850 destroyTexture(&buffers[i].texture, dpy);
Mathias Agopiand606de62010-05-10 20:06:11 -0700851 }
852 destroyTexture(&mFailoverTexture, dpy);
853 return NO_ERROR;
854}
855
856status_t Layer::BufferManager::initEglImage(EGLDisplay dpy,
857 const sp<GraphicBuffer>& buffer)
858{
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700859 status_t err = NO_INIT;
860 ssize_t index = mActiveBuffer;
861 if (index >= 0) {
Mathias Agopian1f7bec62010-06-25 18:02:21 -0700862 if (!mFailover) {
863 Image& texture(mBufferData[index].texture);
864 err = mTextureManager.initEglImage(&texture, dpy, buffer);
865 // if EGLImage fails, we switch to regular texture mode, and we
866 // free all resources associated with using EGLImages.
867 if (err == NO_ERROR) {
868 mFailover = false;
869 destroyTexture(&mFailoverTexture, dpy);
870 } else {
871 mFailover = true;
872 const size_t num = mNumBuffers;
873 for (size_t i=0 ; i<num ; i++) {
874 destroyTexture(&mBufferData[i].texture, dpy);
875 }
Andreas Hubere049a952010-06-25 09:25:19 -0700876 }
Mathias Agopian1f7bec62010-06-25 18:02:21 -0700877 } else {
878 // we failed once, don't try again
879 err = BAD_VALUE;
Mathias Agopiand606de62010-05-10 20:06:11 -0700880 }
881 }
882 return err;
883}
884
885status_t Layer::BufferManager::loadTexture(
886 const Region& dirty, const GGLSurface& t)
887{
888 return mTextureManager.loadTexture(&mFailoverTexture, dirty, t);
889}
890
Mathias Agopianbb641242010-05-18 17:06:55 -0700891status_t Layer::BufferManager::destroyTexture(Image* tex, EGLDisplay dpy)
892{
893 if (tex->name != -1U) {
894 glDeleteTextures(1, &tex->name);
895 tex->name = -1U;
896 }
897 if (tex->image != EGL_NO_IMAGE_KHR) {
898 eglDestroyImageKHR(dpy, tex->image);
899 tex->image = EGL_NO_IMAGE_KHR;
900 }
901 return NO_ERROR;
902}
903
Mathias Agopiand606de62010-05-10 20:06:11 -0700904// ---------------------------------------------------------------------------
905
Mathias Agopian9a112062009-04-17 19:36:26 -0700906Layer::SurfaceLayer::SurfaceLayer(const sp<SurfaceFlinger>& flinger,
Mathias Agopian96f08192010-06-02 23:28:45 -0700907 const sp<Layer>& owner)
908 : Surface(flinger, owner->getIdentity(), owner)
Mathias Agopian9a112062009-04-17 19:36:26 -0700909{
910}
911
912Layer::SurfaceLayer::~SurfaceLayer()
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700913{
914}
915
Mathias Agopiana138f892010-05-21 17:24:35 -0700916sp<GraphicBuffer> Layer::SurfaceLayer::requestBuffer(int index,
917 uint32_t w, uint32_t h, uint32_t format, uint32_t usage)
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700918{
Mathias Agopian3330b202009-10-05 17:07:12 -0700919 sp<GraphicBuffer> buffer;
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700920 sp<Layer> owner(getOwner());
921 if (owner != 0) {
Mathias Agopianbb641242010-05-18 17:06:55 -0700922 /*
923 * requestBuffer() cannot be called from the main thread
924 * as it could cause a dead-lock, since it may have to wait
925 * on conditions updated my the main thread.
926 */
Mathias Agopiana138f892010-05-21 17:24:35 -0700927 buffer = owner->requestBuffer(index, w, h, format, usage);
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700928 }
929 return buffer;
930}
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800931
Mathias Agopianb5b7f262010-05-07 15:58:44 -0700932status_t Layer::SurfaceLayer::setBufferCount(int bufferCount)
933{
934 status_t err = DEAD_OBJECT;
935 sp<Layer> owner(getOwner());
936 if (owner != 0) {
Mathias Agopianbb641242010-05-18 17:06:55 -0700937 /*
938 * setBufferCount() cannot be called from the main thread
939 * as it could cause a dead-lock, since it may have to wait
940 * on conditions updated my the main thread.
941 */
Mathias Agopianb5b7f262010-05-07 15:58:44 -0700942 err = owner->setBufferCount(bufferCount);
943 }
944 return err;
945}
946
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800947// ---------------------------------------------------------------------------
948
949
950}; // namespace android