blob: 67ddcf9cee2e4c9489a3cf552ddccd7b9d89e32e [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
28#include <ui/PixelFormat.h>
Mathias Agopian076b1cc2009-04-10 14:24:30 -070029#include <ui/Surface.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080030
Mathias Agopiancbb288b2009-09-07 16:32:45 -070031#include "Buffer.h"
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080032#include "clz.h"
33#include "Layer.h"
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080034#include "SurfaceFlinger.h"
The Android Open Source Projectedbf3b62009-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 Agopiancbb288b2009-09-07 16:32:45 -070050Layer::Layer(SurfaceFlinger* flinger, DisplayID display,
51 const sp<Client>& c, int32_t i)
Mathias Agopian48d819a2009-09-10 19:41:18 -070052 : LayerBaseClient(flinger, display, c, i),
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080053 mSecure(false),
Mathias Agopian401c2572009-09-23 19:16:27 -070054 mNeedsBlending(true),
55 mNeedsDithering(false)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080056{
57 // no OpenGL operation is possible here, since we might not be
58 // in the OpenGL thread.
Mathias Agopiancbb288b2009-09-07 16:32:45 -070059 mFrontBufferIndex = lcblk->getFrontBuffer();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080060}
61
62Layer::~Layer()
63{
Mathias Agopian0aa758d2009-04-22 15:23:34 -070064 destroy();
65 // the actual buffers will be destroyed here
Mathias Agopian48d819a2009-09-10 19:41:18 -070066}
Mathias Agopiancbb288b2009-09-07 16:32:45 -070067
Mathias Agopian48d819a2009-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 Agopian0aa758d2009-04-22 15:23:34 -070074}
75
76void Layer::destroy()
77{
Mathias Agopiancbb288b2009-09-07 16:32:45 -070078 for (size_t i=0 ; i<NUM_BUFFERS ; i++) {
Mathias Agopian076b1cc2009-04-10 14:24:30 -070079 if (mTextures[i].name != -1U) {
Mathias Agopian550b79f2009-04-22 15:49:28 -070080 glDeleteTextures(1, &mTextures[i].name);
Mathias Agopian0aa758d2009-04-22 15:23:34 -070081 mTextures[i].name = -1U;
Mathias Agopian076b1cc2009-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 Agopian0aa758d2009-04-22 15:23:34 -070086 mTextures[i].image = EGL_NO_IMAGE_KHR;
Mathias Agopian076b1cc2009-04-10 14:24:30 -070087 }
Mathias Agopian48d819a2009-09-10 19:41:18 -070088 Mutex::Autolock _l(mLock);
Mathias Agopiancbb288b2009-09-07 16:32:45 -070089 mBuffers[i].clear();
Mathias Agopian48d819a2009-09-10 19:41:18 -070090 mWidth = mHeight = 0;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080091 }
Mathias Agopian8c0a3d72009-09-23 16:44:00 -070092 mSurface.clear();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080093}
94
Mathias Agopian076b1cc2009-04-10 14:24:30 -070095sp<LayerBaseClient::Surface> Layer::createSurface() const
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080096{
97 return mSurface;
98}
99
Mathias Agopian9a112062009-04-17 19:36:26 -0700100status_t Layer::ditch()
101{
Mathias Agopian0aa758d2009-04-22 15:23:34 -0700102 // the layer is not on screen anymore. free as much resources as possible
Mathias Agopian8c0a3d72009-09-23 16:44:00 -0700103 destroy();
Mathias Agopian9a112062009-04-17 19:36:26 -0700104 return NO_ERROR;
105}
106
Mathias Agopianf9d93272009-06-19 17:00:27 -0700107status_t Layer::setBuffers( uint32_t w, uint32_t h,
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800108 PixelFormat format, uint32_t flags)
109{
Mathias Agopian401c2572009-09-23 19:16:27 -0700110 // this surfaces pixel format
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800111 PixelFormatInfo info;
112 status_t err = getPixelFormatInfo(format, &info);
113 if (err) return err;
114
Mathias Agopian401c2572009-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 Agopian076b1cc2009-04-10 14:24:30 -0700120 uint32_t bufferFlags = 0;
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700121 if (flags & ISurfaceComposer::eSecure)
122 bufferFlags |= Buffer::SECURE;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800123
Mathias Agopiancbb288b2009-09-07 16:32:45 -0700124 mFormat = format;
125 mWidth = w;
126 mHeight = h;
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700127 mSecure = (bufferFlags & Buffer::SECURE) ? true : false;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800128 mNeedsBlending = (info.h_alpha - info.l_alpha) > 0;
Mathias Agopian401c2572009-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 Agopiancbb288b2009-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 Projectedbf3b62009-03-03 19:31:44 -0800138 }
Mathias Agopian9a112062009-04-17 19:36:26 -0700139 mSurface = new SurfaceLayer(mFlinger, clientIndex(), this);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800140 return NO_ERROR;
141}
142
143void Layer::reloadTexture(const Region& dirty)
144{
Mathias Agopiancbb288b2009-09-07 16:32:45 -0700145 Mutex::Autolock _l(mLock);
146 sp<Buffer> buffer(getFrontBuffer());
Mathias Agopian0926f502009-05-04 14:17:04 -0700147 if (LIKELY(mFlags & DisplayHardware::DIRECT_TEXTURE)) {
Mathias Agopian076b1cc2009-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 Agopian6d9f6982009-09-17 19:19:08 -0700192 LOGD("layer=%p, glEGLImageTargetTexture2DOES(%p) "
Mathias Agopian816d7d02009-09-14 18:10:30 -0700193 "failed err=0x%04x",
194 this, mTextures[index].image, error);
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700195 mFlags &= ~DisplayHardware::DIRECT_TEXTURE;
196 } else {
197 // Everything went okay!
Mathias Agopian1fed11c2009-06-23 18:08:22 -0700198 mTextures[index].dirty = false;
199 mTextures[index].width = clientBuf->width;
200 mTextures[index].height = clientBuf->height;
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700201 }
202 }
203 }
204 } else {
205 GGLSurface t;
Mathias Agopian0926f502009-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 Agopian076b1cc2009-04-10 14:24:30 -0700210 if (UNLIKELY(mTextures[0].name == -1U)) {
211 mTextures[0].name = createTexture();
212 }
Mathias Agopian1fed11c2009-06-23 18:08:22 -0700213 loadTexture(&mTextures[0], mTextures[0].name, dirty, t);
Mathias Agopian0926f502009-05-04 14:17:04 -0700214 buffer->unlock();
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700215 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800216 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800217}
218
219
220void Layer::onDraw(const Region& clip) const
221{
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700222 const int index = (mFlags & DisplayHardware::DIRECT_TEXTURE) ?
223 mFrontBufferIndex : 0;
224 GLuint textureName = mTextures[index].name;
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700225 if (UNLIKELY(textureName == -1LU)) {
Mathias Agopiancbb288b2009-09-07 16:32:45 -0700226 //LOGW("Layer %p doesn't have a texture", this);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800227 // the texture has not been created yet, this Layer has
228 // in fact never been drawn into. this happens frequently with
229 // SurfaceView.
230 clearWithOpenGL(clip);
231 return;
232 }
Mathias Agopiancbb288b2009-09-07 16:32:45 -0700233
Mathias Agopian1fed11c2009-06-23 18:08:22 -0700234 drawWithOpenGL(clip, mTextures[index]);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800235}
236
Mathias Agopiancbb288b2009-09-07 16:32:45 -0700237sp<SurfaceBuffer> Layer::requestBuffer(int index, int usage)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800238{
Mathias Agopian48d819a2009-09-10 19:41:18 -0700239 sp<Buffer> buffer;
240
241 // this ensures our client doesn't go away while we're accessing
242 // the shared area.
243 sp<Client> ourClient(client.promote());
244 if (ourClient == 0) {
245 // oops, the client is already gone
246 return buffer;
247 }
248
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700249 /*
Mathias Agopiancbb288b2009-09-07 16:32:45 -0700250 * This is called from the client's Surface::dequeue(). This can happen
251 * at any time, especially while we're in the middle of using the
252 * buffer 'index' as our front buffer.
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700253 *
Mathias Agopiancbb288b2009-09-07 16:32:45 -0700254 * Make sure the buffer we're resizing is not the front buffer and has been
255 * dequeued. Once this condition is asserted, we are guaranteed that this
256 * buffer cannot become the front buffer under our feet, since we're called
257 * from Surface::dequeue()
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700258 */
Mathias Agopiancbb288b2009-09-07 16:32:45 -0700259 status_t err = lcblk->assertReallocate(index);
260 LOGE_IF(err, "assertReallocate(%d) failed (%s)", index, strerror(-err));
Mathias Agopian48d819a2009-09-10 19:41:18 -0700261 if (err != NO_ERROR) {
262 // the surface may have died
263 return buffer;
264 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800265
Mathias Agopian48d819a2009-09-10 19:41:18 -0700266 uint32_t w, h;
267 { // scope for the lock
268 Mutex::Autolock _l(mLock);
269 w = mWidth;
270 h = mHeight;
271 buffer = mBuffers[index];
Mathias Agopian6d9f6982009-09-17 19:19:08 -0700272
273 // destroy() could have been called before we get here, we log it
274 // because it's uncommon, and the code below should handle it
275 LOGW_IF(buffer==0,
276 "mBuffers[%d] is null (mWidth=%d, mHeight=%d)",
277 index, w, h);
278
Mathias Agopian48d819a2009-09-10 19:41:18 -0700279 mBuffers[index].clear();
280 }
281
Mathias Agopian6d9f6982009-09-17 19:19:08 -0700282 if (buffer!=0 && buffer->getStrongCount() == 1) {
Mathias Agopiancbb288b2009-09-07 16:32:45 -0700283 err = buffer->reallocate(w, h, mFormat, usage, mBufferFlags);
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700284 } else {
Mathias Agopiancbb288b2009-09-07 16:32:45 -0700285 // here we have to reallocate a new buffer because we could have a
286 // client in our process with a reference to it (eg: status bar),
287 // and we can't release the handle under its feet.
288 buffer.clear();
289 buffer = new Buffer(w, h, mFormat, usage, mBufferFlags);
290 err = buffer->initCheck();
291 }
292
293 if (err || buffer->handle == 0) {
294 LOGE_IF(err || buffer->handle == 0,
295 "Layer::requestBuffer(this=%p), index=%d, w=%d, h=%d failed (%s)",
296 this, index, w, h, strerror(-err));
297 } else {
298 LOGD_IF(DEBUG_RESIZE,
299 "Layer::requestBuffer(this=%p), index=%d, w=%d, h=%d",
300 this, index, w, h);
301 }
302
303 if (err == NO_ERROR && buffer->handle != 0) {
Mathias Agopian48d819a2009-09-10 19:41:18 -0700304 Mutex::Autolock _l(mLock);
305 if (mWidth && mHeight) {
306 // and we have new buffer
307 mBuffers[index] = buffer;
308 // texture is now dirty...
309 mTextures[index].dirty = true;
310 } else {
311 // oops we got killed while we were allocating the buffer
312 buffer.clear();
313 }
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700314 }
315 return buffer;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800316}
317
318uint32_t Layer::doTransaction(uint32_t flags)
319{
320 const Layer::State& front(drawingState());
321 const Layer::State& temp(currentState());
322
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800323 // Index of the back buffer
324 const bool backbufferChanged = (front.w != temp.w) || (front.h != temp.h);
Mathias Agopiancbb288b2009-09-07 16:32:45 -0700325 if (backbufferChanged) {
326 // the size changed, we need to ask our client to request a new buffer
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800327 LOGD_IF(DEBUG_RESIZE,
Mathias Agopiancbb288b2009-09-07 16:32:45 -0700328 "resize (layer=%p), requested (%dx%d), "
329 "drawing (%d,%d), (%dx%d), (%dx%d)",
330 this, int(temp.w), int(temp.h),
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800331 int(drawingState().w), int(drawingState().h),
Mathias Agopiancbb288b2009-09-07 16:32:45 -0700332 int(mBuffers[0]->getWidth()), int(mBuffers[0]->getHeight()),
333 int(mBuffers[1]->getWidth()), int(mBuffers[1]->getHeight()));
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800334
Mathias Agopiancbb288b2009-09-07 16:32:45 -0700335 // record the new size, form this point on, when the client request a
336 // buffer, it'll get the new size.
337 setDrawingSize(temp.w, temp.h);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800338
Mathias Agopiancbb288b2009-09-07 16:32:45 -0700339 // we're being resized and there is a freeze display request,
340 // acquire a freeze lock, so that the screen stays put
341 // until we've redrawn at the new size; this is to avoid
342 // glitches upon orientation changes.
343 if (mFlinger->hasFreezeRequest()) {
344 // if the surface is hidden, don't try to acquire the
345 // freeze lock, since hidden surfaces may never redraw
346 if (!(front.flags & ISurfaceComposer::eLayerHidden)) {
347 mFreezeLock = mFlinger->getFreezeLock();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800348 }
349 }
Mathias Agopiancaa600c2009-09-16 18:27:24 -0700350
351 // recompute the visible region
352 flags |= Layer::eVisibleRegion;
353 this->contentDirty = true;
354 // all buffers need reallocation
355 lcblk->reallocate();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800356 }
Mathias Agopiancbb288b2009-09-07 16:32:45 -0700357
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800358 if (temp.sequence != front.sequence) {
359 if (temp.flags & ISurfaceComposer::eLayerHidden || temp.alpha == 0) {
360 // this surface is now hidden, so it shouldn't hold a freeze lock
361 // (it may never redraw, which is fine if it is hidden)
362 mFreezeLock.clear();
363 }
364 }
365
366 return LayerBase::doTransaction(flags);
367}
368
Mathias Agopiancbb288b2009-09-07 16:32:45 -0700369void Layer::setDrawingSize(uint32_t w, uint32_t h) {
370 Mutex::Autolock _l(mLock);
371 mWidth = w;
372 mHeight = h;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800373}
374
375// ----------------------------------------------------------------------------
376// pageflip handling...
377// ----------------------------------------------------------------------------
378
379void Layer::lockPageFlip(bool& recomputeVisibleRegions)
380{
Mathias Agopiancbb288b2009-09-07 16:32:45 -0700381 ssize_t buf = lcblk->retireAndLock();
382 if (buf < NO_ERROR) {
383 //LOGW("nothing to retire (%s)", strerror(-buf));
384 // NOTE: here the buffer is locked because we will used
385 // for composition later in the loop
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800386 return;
387 }
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700388
Mathias Agopiancbb288b2009-09-07 16:32:45 -0700389 // we retired a buffer, which becomes the new front buffer
390 mFrontBufferIndex = buf;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800391
Mathias Agopiancbb288b2009-09-07 16:32:45 -0700392 // get the dirty region
393 sp<Buffer> newFrontBuffer(getBuffer(buf));
394 const Region dirty(lcblk->getDirtyRegion(buf));
395 mPostedDirtyRegion = dirty.intersect( newFrontBuffer->getBounds() );
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700396
Mathias Agopiancaa600c2009-09-16 18:27:24 -0700397
398 const Layer::State& front(drawingState());
399 if (newFrontBuffer->getWidth() == front.w &&
400 newFrontBuffer->getHeight() ==front.h) {
401 mFreezeLock.clear();
402 }
403
Mathias Agopiancbb288b2009-09-07 16:32:45 -0700404 // FIXME: signal an event if we have more buffers waiting
405 // mFlinger->signalEvent();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800406
Mathias Agopiancbb288b2009-09-07 16:32:45 -0700407 reloadTexture( mPostedDirtyRegion );
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800408}
409
410void Layer::unlockPageFlip(
411 const Transform& planeTransform, Region& outDirtyRegion)
412{
413 Region dirtyRegion(mPostedDirtyRegion);
414 if (!dirtyRegion.isEmpty()) {
415 mPostedDirtyRegion.clear();
416 // The dirty region is given in the layer's coordinate space
417 // transform the dirty region by the surface's transformation
418 // and the global transformation.
419 const Layer::State& s(drawingState());
420 const Transform tr(planeTransform * s.transform);
421 dirtyRegion = tr.transform(dirtyRegion);
422
423 // At this point, the dirty region is in screen space.
424 // Make sure it's constrained by the visible region (which
425 // is in screen space as well).
426 dirtyRegion.andSelf(visibleRegionScreen);
427 outDirtyRegion.orSelf(dirtyRegion);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800428 }
429}
430
431void Layer::finishPageFlip()
432{
Mathias Agopiancbb288b2009-09-07 16:32:45 -0700433 status_t err = lcblk->unlock( mFrontBufferIndex );
434 LOGE_IF(err!=NO_ERROR,
435 "layer %p, buffer=%d wasn't locked!",
436 this, mFrontBufferIndex);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800437}
438
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700439// ---------------------------------------------------------------------------
440
Mathias Agopian9a112062009-04-17 19:36:26 -0700441Layer::SurfaceLayer::SurfaceLayer(const sp<SurfaceFlinger>& flinger,
442 SurfaceID id, const sp<Layer>& owner)
443 : Surface(flinger, id, owner->getIdentity(), owner)
444{
445}
446
447Layer::SurfaceLayer::~SurfaceLayer()
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700448{
449}
450
Mathias Agopiancbb288b2009-09-07 16:32:45 -0700451sp<SurfaceBuffer> Layer::SurfaceLayer::requestBuffer(int index, int usage)
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700452{
Mathias Agopiancbb288b2009-09-07 16:32:45 -0700453 sp<SurfaceBuffer> buffer;
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700454 sp<Layer> owner(getOwner());
455 if (owner != 0) {
Mathias Agopiancbb288b2009-09-07 16:32:45 -0700456 LOGE_IF(uint32_t(index)>=NUM_BUFFERS,
457 "getBuffer() index (%d) out of range", index);
458 if (uint32_t(index) < NUM_BUFFERS) {
459 buffer = owner->requestBuffer(index, usage);
460 }
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700461 }
462 return buffer;
463}
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800464
465// ---------------------------------------------------------------------------
466
467
468}; // namespace android