blob: d59f205d3c7a60e670da205e88577859832ad973 [file] [log] [blame]
The Android Open Source Project9066cfe2009-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 Project9066cfe2009-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 Agopian1473f462009-04-10 14:24:30 -070022#include <cutils/native_handle.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080023
24#include <utils/Errors.h>
25#include <utils/Log.h>
26#include <utils/StopWatch.h>
27
28#include <ui/PixelFormat.h>
Mathias Agopian1473f462009-04-10 14:24:30 -070029#include <ui/Surface.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080030
Mathias Agopian9779b222009-09-07 16:32:45 -070031#include "Buffer.h"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080032#include "clz.h"
33#include "Layer.h"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080034#include "SurfaceFlinger.h"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080035#include "DisplayHardware/DisplayHardware.h"
36
37
38#define DEBUG_RESIZE 0
39
40
41namespace android {
42
43// ---------------------------------------------------------------------------
44
45const uint32_t Layer::typeInfo = LayerBaseClient::typeInfo | 4;
46const char* const Layer::typeID = "Layer";
47
48// ---------------------------------------------------------------------------
49
Mathias Agopian9779b222009-09-07 16:32:45 -070050Layer::Layer(SurfaceFlinger* flinger, DisplayID display,
51 const sp<Client>& c, int32_t i)
Mathias Agopian248b5bd2009-09-10 19:41:18 -070052 : LayerBaseClient(flinger, display, c, i),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080053 mSecure(false),
Mathias Agopiancc934762009-09-23 19:16:27 -070054 mNeedsBlending(true),
55 mNeedsDithering(false)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080056{
57 // no OpenGL operation is possible here, since we might not be
58 // in the OpenGL thread.
Mathias Agopian9779b222009-09-07 16:32:45 -070059 mFrontBufferIndex = lcblk->getFrontBuffer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080060}
61
62Layer::~Layer()
63{
Mathias Agopiana3aa6c92009-04-22 15:23:34 -070064 destroy();
65 // the actual buffers will be destroyed here
Mathias Agopian248b5bd2009-09-10 19:41:18 -070066}
Mathias Agopian9779b222009-09-07 16:32:45 -070067
Mathias Agopian248b5bd2009-09-10 19:41:18 -070068// called with SurfaceFlinger::mStateLock as soon as the layer is entered
69// in the purgatory list
70void Layer::onRemoved()
71{
72 // wake up the condition
73 lcblk->setStatus(NO_INIT);
Mathias Agopiana3aa6c92009-04-22 15:23:34 -070074}
75
76void Layer::destroy()
77{
Mathias Agopian9779b222009-09-07 16:32:45 -070078 for (size_t i=0 ; i<NUM_BUFFERS ; i++) {
Mathias Agopian1473f462009-04-10 14:24:30 -070079 if (mTextures[i].name != -1U) {
Mathias Agopian81b0aa62009-04-22 15:49:28 -070080 glDeleteTextures(1, &mTextures[i].name);
Mathias Agopiana3aa6c92009-04-22 15:23:34 -070081 mTextures[i].name = -1U;
Mathias Agopian1473f462009-04-10 14:24:30 -070082 }
83 if (mTextures[i].image != EGL_NO_IMAGE_KHR) {
84 EGLDisplay dpy(mFlinger->graphicPlane(0).getEGLDisplay());
85 eglDestroyImageKHR(dpy, mTextures[i].image);
Mathias Agopiana3aa6c92009-04-22 15:23:34 -070086 mTextures[i].image = EGL_NO_IMAGE_KHR;
Mathias Agopian1473f462009-04-10 14:24:30 -070087 }
Mathias Agopian248b5bd2009-09-10 19:41:18 -070088 Mutex::Autolock _l(mLock);
Mathias Agopian9779b222009-09-07 16:32:45 -070089 mBuffers[i].clear();
Mathias Agopian248b5bd2009-09-10 19:41:18 -070090 mWidth = mHeight = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080091 }
Mathias Agopian2e4b68d2009-09-23 16:44:00 -070092 mSurface.clear();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080093}
94
Mathias Agopian1473f462009-04-10 14:24:30 -070095sp<LayerBaseClient::Surface> Layer::createSurface() const
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080096{
97 return mSurface;
98}
99
Mathias Agopian6cf0db22009-04-17 19:36:26 -0700100status_t Layer::ditch()
101{
Mathias Agopiana3aa6c92009-04-22 15:23:34 -0700102 // the layer is not on screen anymore. free as much resources as possible
Mathias Agopian2e4b68d2009-09-23 16:44:00 -0700103 destroy();
Mathias Agopian6cf0db22009-04-17 19:36:26 -0700104 return NO_ERROR;
105}
106
Mathias Agopian6edf5af2009-06-19 17:00:27 -0700107status_t Layer::setBuffers( uint32_t w, uint32_t h,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800108 PixelFormat format, uint32_t flags)
109{
Mathias Agopiancc934762009-09-23 19:16:27 -0700110 // this surfaces pixel format
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800111 PixelFormatInfo info;
112 status_t err = getPixelFormatInfo(format, &info);
113 if (err) return err;
114
Mathias Agopiancc934762009-09-23 19:16:27 -0700115 // the display's pixel format
116 const DisplayHardware& hw(graphicPlane(0).displayHardware());
117 PixelFormatInfo displayInfo;
118 getPixelFormatInfo(hw.getFormat(), &displayInfo);
119
Mathias Agopian1473f462009-04-10 14:24:30 -0700120 uint32_t bufferFlags = 0;
Mathias Agopian1473f462009-04-10 14:24:30 -0700121 if (flags & ISurfaceComposer::eSecure)
122 bufferFlags |= Buffer::SECURE;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800123
Mathias Agopian9779b222009-09-07 16:32:45 -0700124 mFormat = format;
125 mWidth = w;
126 mHeight = h;
Mathias Agopian1473f462009-04-10 14:24:30 -0700127 mSecure = (bufferFlags & Buffer::SECURE) ? true : false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800128 mNeedsBlending = (info.h_alpha - info.l_alpha) > 0;
Mathias Agopiancc934762009-09-23 19:16:27 -0700129
130 // we use the red index
131 int displayRedSize = displayInfo.getSize(PixelFormatInfo::INDEX_RED);
132 int layerRedsize = info.getSize(PixelFormatInfo::INDEX_RED);
133 mNeedsDithering = layerRedsize > displayRedSize;
134
Mathias Agopian9779b222009-09-07 16:32:45 -0700135 mBufferFlags = bufferFlags;
136 for (size_t i=0 ; i<NUM_BUFFERS ; i++) {
137 mBuffers[i] = new Buffer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800138 }
Mathias Agopian6cf0db22009-04-17 19:36:26 -0700139 mSurface = new SurfaceLayer(mFlinger, clientIndex(), this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800140 return NO_ERROR;
141}
142
143void Layer::reloadTexture(const Region& dirty)
144{
Mathias Agopian9779b222009-09-07 16:32:45 -0700145 Mutex::Autolock _l(mLock);
146 sp<Buffer> buffer(getFrontBuffer());
Mathias Agopiandff8e582009-05-04 14:17:04 -0700147 if (LIKELY(mFlags & DisplayHardware::DIRECT_TEXTURE)) {
Mathias Agopian1473f462009-04-10 14:24:30 -0700148 int index = mFrontBufferIndex;
149 if (LIKELY(!mTextures[index].dirty)) {
150 glBindTexture(GL_TEXTURE_2D, mTextures[index].name);
151 } else {
152 // we need to recreate the texture
153 EGLDisplay dpy(mFlinger->graphicPlane(0).getEGLDisplay());
154
155 // create the new texture name if needed
156 if (UNLIKELY(mTextures[index].name == -1U)) {
157 mTextures[index].name = createTexture();
158 } else {
159 glBindTexture(GL_TEXTURE_2D, mTextures[index].name);
160 }
161
162 // free the previous image
163 if (mTextures[index].image != EGL_NO_IMAGE_KHR) {
164 eglDestroyImageKHR(dpy, mTextures[index].image);
165 mTextures[index].image = EGL_NO_IMAGE_KHR;
166 }
167
168 // construct an EGL_NATIVE_BUFFER_ANDROID
169 android_native_buffer_t* clientBuf = buffer->getNativeBuffer();
170
171 // create the new EGLImageKHR
172 const EGLint attrs[] = {
173 EGL_IMAGE_PRESERVED_KHR, EGL_TRUE,
174 EGL_NONE, EGL_NONE
175 };
176 mTextures[index].image = eglCreateImageKHR(
177 dpy, EGL_NO_CONTEXT, EGL_NATIVE_BUFFER_ANDROID,
178 (EGLClientBuffer)clientBuf, attrs);
179
180 LOGE_IF(mTextures[index].image == EGL_NO_IMAGE_KHR,
181 "eglCreateImageKHR() failed. err=0x%4x",
182 eglGetError());
183
184 if (mTextures[index].image != EGL_NO_IMAGE_KHR) {
185 glEGLImageTargetTexture2DOES(GL_TEXTURE_2D,
186 (GLeglImageOES)mTextures[index].image);
187 GLint error = glGetError();
188 if (UNLIKELY(error != GL_NO_ERROR)) {
189 // this failed, for instance, because we don't support
190 // NPOT.
191 // FIXME: do something!
Mathias Agopianac7f13b2009-09-17 19:19:08 -0700192 LOGD("layer=%p, glEGLImageTargetTexture2DOES(%p) "
Mathias Agopian64a7c6b2009-09-14 18:10:30 -0700193 "failed err=0x%04x",
194 this, mTextures[index].image, error);
Mathias Agopian1473f462009-04-10 14:24:30 -0700195 mFlags &= ~DisplayHardware::DIRECT_TEXTURE;
196 } else {
197 // Everything went okay!
Mathias Agopian999543b2009-06-23 18:08:22 -0700198 mTextures[index].dirty = false;
199 mTextures[index].width = clientBuf->width;
200 mTextures[index].height = clientBuf->height;
Mathias Agopian1473f462009-04-10 14:24:30 -0700201 }
202 }
203 }
204 } else {
205 GGLSurface t;
Mathias Agopiandff8e582009-05-04 14:17:04 -0700206 status_t res = buffer->lock(&t, GRALLOC_USAGE_SW_READ_RARELY);
207 LOGE_IF(res, "error %d (%s) locking buffer %p",
208 res, strerror(res), buffer.get());
209 if (res == NO_ERROR) {
Mathias Agopian1473f462009-04-10 14:24:30 -0700210 if (UNLIKELY(mTextures[0].name == -1U)) {
211 mTextures[0].name = createTexture();
212 }
Mathias Agopian999543b2009-06-23 18:08:22 -0700213 loadTexture(&mTextures[0], mTextures[0].name, dirty, t);
Mathias Agopiandff8e582009-05-04 14:17:04 -0700214 buffer->unlock();
Mathias Agopian1473f462009-04-10 14:24:30 -0700215 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800216 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800217}
218
219
220void Layer::onDraw(const Region& clip) const
221{
Mathias Agopian1473f462009-04-10 14:24:30 -0700222 const int index = (mFlags & DisplayHardware::DIRECT_TEXTURE) ?
223 mFrontBufferIndex : 0;
224 GLuint textureName = mTextures[index].name;
Mathias Agopian1473f462009-04-10 14:24:30 -0700225 if (UNLIKELY(textureName == -1LU)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800226 // the texture has not been created yet, this Layer has
227 // in fact never been drawn into. this happens frequently with
228 // SurfaceView.
229 clearWithOpenGL(clip);
230 return;
231 }
Mathias Agopian999543b2009-06-23 18:08:22 -0700232 drawWithOpenGL(clip, mTextures[index]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800233}
234
Mathias Agopian9779b222009-09-07 16:32:45 -0700235sp<SurfaceBuffer> Layer::requestBuffer(int index, int usage)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800236{
Mathias Agopian248b5bd2009-09-10 19:41:18 -0700237 sp<Buffer> buffer;
238
239 // this ensures our client doesn't go away while we're accessing
240 // the shared area.
241 sp<Client> ourClient(client.promote());
242 if (ourClient == 0) {
243 // oops, the client is already gone
244 return buffer;
245 }
246
Mathias Agopian1473f462009-04-10 14:24:30 -0700247 /*
Mathias Agopian9779b222009-09-07 16:32:45 -0700248 * This is called from the client's Surface::dequeue(). This can happen
249 * at any time, especially while we're in the middle of using the
250 * buffer 'index' as our front buffer.
Mathias Agopian1473f462009-04-10 14:24:30 -0700251 *
Mathias Agopian9779b222009-09-07 16:32:45 -0700252 * Make sure the buffer we're resizing is not the front buffer and has been
253 * dequeued. Once this condition is asserted, we are guaranteed that this
254 * buffer cannot become the front buffer under our feet, since we're called
255 * from Surface::dequeue()
Mathias Agopian1473f462009-04-10 14:24:30 -0700256 */
Mathias Agopian9779b222009-09-07 16:32:45 -0700257 status_t err = lcblk->assertReallocate(index);
258 LOGE_IF(err, "assertReallocate(%d) failed (%s)", index, strerror(-err));
Mathias Agopian248b5bd2009-09-10 19:41:18 -0700259 if (err != NO_ERROR) {
260 // the surface may have died
261 return buffer;
262 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800263
Mathias Agopian248b5bd2009-09-10 19:41:18 -0700264 uint32_t w, h;
265 { // scope for the lock
266 Mutex::Autolock _l(mLock);
267 w = mWidth;
268 h = mHeight;
269 buffer = mBuffers[index];
Mathias Agopianac7f13b2009-09-17 19:19:08 -0700270
271 // destroy() could have been called before we get here, we log it
272 // because it's uncommon, and the code below should handle it
273 LOGW_IF(buffer==0,
274 "mBuffers[%d] is null (mWidth=%d, mHeight=%d)",
275 index, w, h);
276
Mathias Agopian248b5bd2009-09-10 19:41:18 -0700277 mBuffers[index].clear();
278 }
279
Mathias Agopianac7f13b2009-09-17 19:19:08 -0700280 if (buffer!=0 && buffer->getStrongCount() == 1) {
Mathias Agopian9779b222009-09-07 16:32:45 -0700281 err = buffer->reallocate(w, h, mFormat, usage, mBufferFlags);
Mathias Agopian1473f462009-04-10 14:24:30 -0700282 } else {
Mathias Agopian9779b222009-09-07 16:32:45 -0700283 // here we have to reallocate a new buffer because we could have a
284 // client in our process with a reference to it (eg: status bar),
285 // and we can't release the handle under its feet.
286 buffer.clear();
287 buffer = new Buffer(w, h, mFormat, usage, mBufferFlags);
288 err = buffer->initCheck();
289 }
290
291 if (err || buffer->handle == 0) {
292 LOGE_IF(err || buffer->handle == 0,
293 "Layer::requestBuffer(this=%p), index=%d, w=%d, h=%d failed (%s)",
294 this, index, w, h, strerror(-err));
295 } else {
296 LOGD_IF(DEBUG_RESIZE,
Mathias Agopiane1b6f242009-09-29 22:39:22 -0700297 "Layer::requestBuffer(this=%p), index=%d, w=%d, h=%d, handle=%p",
298 this, index, w, h, buffer->handle);
Mathias Agopian9779b222009-09-07 16:32:45 -0700299 }
300
301 if (err == NO_ERROR && buffer->handle != 0) {
Mathias Agopian248b5bd2009-09-10 19:41:18 -0700302 Mutex::Autolock _l(mLock);
303 if (mWidth && mHeight) {
304 // and we have new buffer
305 mBuffers[index] = buffer;
306 // texture is now dirty...
307 mTextures[index].dirty = true;
308 } else {
309 // oops we got killed while we were allocating the buffer
310 buffer.clear();
311 }
Mathias Agopian1473f462009-04-10 14:24:30 -0700312 }
313 return buffer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800314}
315
316uint32_t Layer::doTransaction(uint32_t flags)
317{
318 const Layer::State& front(drawingState());
319 const Layer::State& temp(currentState());
320
Mathias Agopiane1b6f242009-09-29 22:39:22 -0700321 if ((front.requested_w != temp.requested_w) ||
322 (front.requested_h != temp.requested_h)) {
Mathias Agopian9779b222009-09-07 16:32:45 -0700323 // the size changed, we need to ask our client to request a new buffer
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800324 LOGD_IF(DEBUG_RESIZE,
Mathias Agopian9779b222009-09-07 16:32:45 -0700325 "resize (layer=%p), requested (%dx%d), "
326 "drawing (%d,%d), (%dx%d), (%dx%d)",
Mathias Agopiane1b6f242009-09-29 22:39:22 -0700327 this,
328 int(temp.requested_w), int(temp.requested_h),
329 int(front.requested_w), int(front.requested_h),
Mathias Agopian9779b222009-09-07 16:32:45 -0700330 int(mBuffers[0]->getWidth()), int(mBuffers[0]->getHeight()),
331 int(mBuffers[1]->getWidth()), int(mBuffers[1]->getHeight()));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800332
Mathias Agopian9779b222009-09-07 16:32:45 -0700333 // record the new size, form this point on, when the client request a
334 // buffer, it'll get the new size.
Mathias Agopiane1b6f242009-09-29 22:39:22 -0700335 setDrawingSize(temp.requested_w, temp.requested_h);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800336
Mathias Agopian9779b222009-09-07 16:32:45 -0700337 // we're being resized and there is a freeze display request,
338 // acquire a freeze lock, so that the screen stays put
339 // until we've redrawn at the new size; this is to avoid
340 // glitches upon orientation changes.
341 if (mFlinger->hasFreezeRequest()) {
342 // if the surface is hidden, don't try to acquire the
343 // freeze lock, since hidden surfaces may never redraw
344 if (!(front.flags & ISurfaceComposer::eLayerHidden)) {
345 mFreezeLock = mFlinger->getFreezeLock();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800346 }
347 }
Mathias Agopian7cf03ba2009-09-16 18:27:24 -0700348
349 // recompute the visible region
350 flags |= Layer::eVisibleRegion;
351 this->contentDirty = true;
352 // all buffers need reallocation
353 lcblk->reallocate();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800354 }
Mathias Agopian9779b222009-09-07 16:32:45 -0700355
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800356 if (temp.sequence != front.sequence) {
357 if (temp.flags & ISurfaceComposer::eLayerHidden || temp.alpha == 0) {
358 // this surface is now hidden, so it shouldn't hold a freeze lock
359 // (it may never redraw, which is fine if it is hidden)
360 mFreezeLock.clear();
361 }
362 }
363
364 return LayerBase::doTransaction(flags);
365}
366
Mathias Agopian9779b222009-09-07 16:32:45 -0700367void Layer::setDrawingSize(uint32_t w, uint32_t h) {
368 Mutex::Autolock _l(mLock);
369 mWidth = w;
370 mHeight = h;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800371}
372
373// ----------------------------------------------------------------------------
374// pageflip handling...
375// ----------------------------------------------------------------------------
376
377void Layer::lockPageFlip(bool& recomputeVisibleRegions)
378{
Mathias Agopian9779b222009-09-07 16:32:45 -0700379 ssize_t buf = lcblk->retireAndLock();
380 if (buf < NO_ERROR) {
381 //LOGW("nothing to retire (%s)", strerror(-buf));
382 // NOTE: here the buffer is locked because we will used
383 // for composition later in the loop
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800384 return;
385 }
Mathias Agopian1473f462009-04-10 14:24:30 -0700386
Mathias Agopian9779b222009-09-07 16:32:45 -0700387 // we retired a buffer, which becomes the new front buffer
388 mFrontBufferIndex = buf;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800389
Mathias Agopian9779b222009-09-07 16:32:45 -0700390 // get the dirty region
391 sp<Buffer> newFrontBuffer(getBuffer(buf));
392 const Region dirty(lcblk->getDirtyRegion(buf));
393 mPostedDirtyRegion = dirty.intersect( newFrontBuffer->getBounds() );
Mathias Agopian1473f462009-04-10 14:24:30 -0700394
Mathias Agopian7cf03ba2009-09-16 18:27:24 -0700395
396 const Layer::State& front(drawingState());
397 if (newFrontBuffer->getWidth() == front.w &&
398 newFrontBuffer->getHeight() ==front.h) {
399 mFreezeLock.clear();
400 }
401
Mathias Agopian9779b222009-09-07 16:32:45 -0700402 // FIXME: signal an event if we have more buffers waiting
403 // mFlinger->signalEvent();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800404
Mathias Agopian9779b222009-09-07 16:32:45 -0700405 reloadTexture( mPostedDirtyRegion );
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800406}
407
408void Layer::unlockPageFlip(
409 const Transform& planeTransform, Region& outDirtyRegion)
410{
411 Region dirtyRegion(mPostedDirtyRegion);
412 if (!dirtyRegion.isEmpty()) {
413 mPostedDirtyRegion.clear();
414 // The dirty region is given in the layer's coordinate space
415 // transform the dirty region by the surface's transformation
416 // and the global transformation.
417 const Layer::State& s(drawingState());
418 const Transform tr(planeTransform * s.transform);
419 dirtyRegion = tr.transform(dirtyRegion);
420
421 // At this point, the dirty region is in screen space.
422 // Make sure it's constrained by the visible region (which
423 // is in screen space as well).
424 dirtyRegion.andSelf(visibleRegionScreen);
425 outDirtyRegion.orSelf(dirtyRegion);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800426 }
427}
428
429void Layer::finishPageFlip()
430{
Mathias Agopian9779b222009-09-07 16:32:45 -0700431 status_t err = lcblk->unlock( mFrontBufferIndex );
432 LOGE_IF(err!=NO_ERROR,
433 "layer %p, buffer=%d wasn't locked!",
434 this, mFrontBufferIndex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800435}
436
Mathias Agopian1473f462009-04-10 14:24:30 -0700437// ---------------------------------------------------------------------------
438
Mathias Agopian6cf0db22009-04-17 19:36:26 -0700439Layer::SurfaceLayer::SurfaceLayer(const sp<SurfaceFlinger>& flinger,
440 SurfaceID id, const sp<Layer>& owner)
441 : Surface(flinger, id, owner->getIdentity(), owner)
442{
443}
444
445Layer::SurfaceLayer::~SurfaceLayer()
Mathias Agopian1473f462009-04-10 14:24:30 -0700446{
447}
448
Mathias Agopian9779b222009-09-07 16:32:45 -0700449sp<SurfaceBuffer> Layer::SurfaceLayer::requestBuffer(int index, int usage)
Mathias Agopian1473f462009-04-10 14:24:30 -0700450{
Mathias Agopian9779b222009-09-07 16:32:45 -0700451 sp<SurfaceBuffer> buffer;
Mathias Agopian1473f462009-04-10 14:24:30 -0700452 sp<Layer> owner(getOwner());
453 if (owner != 0) {
Mathias Agopian9779b222009-09-07 16:32:45 -0700454 LOGE_IF(uint32_t(index)>=NUM_BUFFERS,
455 "getBuffer() index (%d) out of range", index);
456 if (uint32_t(index) < NUM_BUFFERS) {
457 buffer = owner->requestBuffer(index, usage);
458 }
Mathias Agopian1473f462009-04-10 14:24:30 -0700459 }
460 return buffer;
461}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800462
463// ---------------------------------------------------------------------------
464
465
466}; // namespace android