2009-03-04 03:31:44 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2007 The Android Open Source Project
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
|
|
|
#include <cutils/properties.h>
|
2009-04-10 21:24:30 +00:00
|
|
|
#include <cutils/native_handle.h>
|
2009-03-04 03:31:44 +00:00
|
|
|
|
|
|
|
#include <utils/Errors.h>
|
|
|
|
#include <utils/Log.h>
|
|
|
|
#include <utils/StopWatch.h>
|
|
|
|
|
2009-10-06 00:07:12 +00:00
|
|
|
#include <ui/GraphicBuffer.h>
|
2009-03-04 03:31:44 +00:00
|
|
|
#include <ui/PixelFormat.h>
|
2010-02-10 01:46:37 +00:00
|
|
|
|
|
|
|
#include <surfaceflinger/Surface.h>
|
2009-03-04 03:31:44 +00:00
|
|
|
|
|
|
|
#include "clz.h"
|
|
|
|
#include "Layer.h"
|
|
|
|
#include "SurfaceFlinger.h"
|
|
|
|
#include "DisplayHardware/DisplayHardware.h"
|
|
|
|
|
|
|
|
|
|
|
|
#define DEBUG_RESIZE 0
|
|
|
|
|
|
|
|
|
|
|
|
namespace android {
|
|
|
|
|
2010-04-14 23:43:44 +00:00
|
|
|
template <typename T> inline T min(T a, T b) {
|
|
|
|
return a<b ? a : b;
|
|
|
|
}
|
|
|
|
|
2009-03-04 03:31:44 +00:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
fix [2068105] implement queueBuffer/lockBuffer/dequeueBuffer properly
Rewrote SurfaceFlinger's buffer management from the ground-up.
The design now support an arbitrary number of buffers per surface, however the current implementation is limited to four. Currently only 2 buffers are used in practice.
The main new feature is to be able to dequeue all buffers at once (very important when there are only two).
A client can dequeue all buffers until there are none available, it can lock all buffers except the last one that is used for composition. The client will block then, until a new buffer is enqueued.
The current implementation requires that buffers are locked in the same order they are dequeued and enqueued in the same order they are locked. Only one buffer can be locked at a time.
eg. Allowed sequence: DQ, DQ, LOCK, Q, LOCK, Q
eg. Forbidden sequence: DQ, DQ, LOCK, LOCK, Q, Q
2009-09-07 23:32:45 +00:00
|
|
|
Layer::Layer(SurfaceFlinger* flinger, DisplayID display,
|
|
|
|
const sp<Client>& c, int32_t i)
|
2009-09-11 02:41:18 +00:00
|
|
|
: LayerBaseClient(flinger, display, c, i),
|
2009-03-04 03:31:44 +00:00
|
|
|
mSecure(false),
|
2009-10-06 01:20:39 +00:00
|
|
|
mNoEGLImageForSwBuffers(false),
|
2009-09-24 02:16:27 +00:00
|
|
|
mNeedsBlending(true),
|
|
|
|
mNeedsDithering(false)
|
2009-03-04 03:31:44 +00:00
|
|
|
{
|
|
|
|
// no OpenGL operation is possible here, since we might not be
|
|
|
|
// in the OpenGL thread.
|
fix [2068105] implement queueBuffer/lockBuffer/dequeueBuffer properly
Rewrote SurfaceFlinger's buffer management from the ground-up.
The design now support an arbitrary number of buffers per surface, however the current implementation is limited to four. Currently only 2 buffers are used in practice.
The main new feature is to be able to dequeue all buffers at once (very important when there are only two).
A client can dequeue all buffers until there are none available, it can lock all buffers except the last one that is used for composition. The client will block then, until a new buffer is enqueued.
The current implementation requires that buffers are locked in the same order they are dequeued and enqueued in the same order they are locked. Only one buffer can be locked at a time.
eg. Allowed sequence: DQ, DQ, LOCK, Q, LOCK, Q
eg. Forbidden sequence: DQ, DQ, LOCK, LOCK, Q, Q
2009-09-07 23:32:45 +00:00
|
|
|
mFrontBufferIndex = lcblk->getFrontBuffer();
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Layer::~Layer()
|
2009-04-22 22:23:34 +00:00
|
|
|
{
|
|
|
|
destroy();
|
|
|
|
// the actual buffers will be destroyed here
|
2009-09-11 02:41:18 +00:00
|
|
|
}
|
fix [2068105] implement queueBuffer/lockBuffer/dequeueBuffer properly
Rewrote SurfaceFlinger's buffer management from the ground-up.
The design now support an arbitrary number of buffers per surface, however the current implementation is limited to four. Currently only 2 buffers are used in practice.
The main new feature is to be able to dequeue all buffers at once (very important when there are only two).
A client can dequeue all buffers until there are none available, it can lock all buffers except the last one that is used for composition. The client will block then, until a new buffer is enqueued.
The current implementation requires that buffers are locked in the same order they are dequeued and enqueued in the same order they are locked. Only one buffer can be locked at a time.
eg. Allowed sequence: DQ, DQ, LOCK, Q, LOCK, Q
eg. Forbidden sequence: DQ, DQ, LOCK, LOCK, Q, Q
2009-09-07 23:32:45 +00:00
|
|
|
|
2009-04-22 22:23:34 +00:00
|
|
|
void Layer::destroy()
|
2009-03-04 03:31:44 +00:00
|
|
|
{
|
fix [2068105] implement queueBuffer/lockBuffer/dequeueBuffer properly
Rewrote SurfaceFlinger's buffer management from the ground-up.
The design now support an arbitrary number of buffers per surface, however the current implementation is limited to four. Currently only 2 buffers are used in practice.
The main new feature is to be able to dequeue all buffers at once (very important when there are only two).
A client can dequeue all buffers until there are none available, it can lock all buffers except the last one that is used for composition. The client will block then, until a new buffer is enqueued.
The current implementation requires that buffers are locked in the same order they are dequeued and enqueued in the same order they are locked. Only one buffer can be locked at a time.
eg. Allowed sequence: DQ, DQ, LOCK, Q, LOCK, Q
eg. Forbidden sequence: DQ, DQ, LOCK, LOCK, Q, Q
2009-09-07 23:32:45 +00:00
|
|
|
for (size_t i=0 ; i<NUM_BUFFERS ; i++) {
|
2009-04-10 21:24:30 +00:00
|
|
|
if (mTextures[i].name != -1U) {
|
2009-04-22 22:49:28 +00:00
|
|
|
glDeleteTextures(1, &mTextures[i].name);
|
2009-04-22 22:23:34 +00:00
|
|
|
mTextures[i].name = -1U;
|
2009-04-10 21:24:30 +00:00
|
|
|
}
|
|
|
|
if (mTextures[i].image != EGL_NO_IMAGE_KHR) {
|
|
|
|
EGLDisplay dpy(mFlinger->graphicPlane(0).getEGLDisplay());
|
|
|
|
eglDestroyImageKHR(dpy, mTextures[i].image);
|
2009-04-22 22:23:34 +00:00
|
|
|
mTextures[i].image = EGL_NO_IMAGE_KHR;
|
2009-04-10 21:24:30 +00:00
|
|
|
}
|
2009-09-11 02:41:18 +00:00
|
|
|
Mutex::Autolock _l(mLock);
|
fix [2068105] implement queueBuffer/lockBuffer/dequeueBuffer properly
Rewrote SurfaceFlinger's buffer management from the ground-up.
The design now support an arbitrary number of buffers per surface, however the current implementation is limited to four. Currently only 2 buffers are used in practice.
The main new feature is to be able to dequeue all buffers at once (very important when there are only two).
A client can dequeue all buffers until there are none available, it can lock all buffers except the last one that is used for composition. The client will block then, until a new buffer is enqueued.
The current implementation requires that buffers are locked in the same order they are dequeued and enqueued in the same order they are locked. Only one buffer can be locked at a time.
eg. Allowed sequence: DQ, DQ, LOCK, Q, LOCK, Q
eg. Forbidden sequence: DQ, DQ, LOCK, LOCK, Q, Q
2009-09-07 23:32:45 +00:00
|
|
|
mBuffers[i].clear();
|
2009-09-11 02:41:18 +00:00
|
|
|
mWidth = mHeight = 0;
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
2009-09-23 23:44:00 +00:00
|
|
|
mSurface.clear();
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
|
|
|
|
2009-04-10 21:24:30 +00:00
|
|
|
sp<LayerBaseClient::Surface> Layer::createSurface() const
|
2009-03-04 03:31:44 +00:00
|
|
|
{
|
|
|
|
return mSurface;
|
|
|
|
}
|
|
|
|
|
2009-04-18 02:36:26 +00:00
|
|
|
status_t Layer::ditch()
|
|
|
|
{
|
2009-04-22 22:23:34 +00:00
|
|
|
// the layer is not on screen anymore. free as much resources as possible
|
2009-12-11 08:56:10 +00:00
|
|
|
mFreezeLock.clear();
|
2009-09-23 23:44:00 +00:00
|
|
|
destroy();
|
2009-04-18 02:36:26 +00:00
|
|
|
return NO_ERROR;
|
|
|
|
}
|
|
|
|
|
2009-06-20 00:00:27 +00:00
|
|
|
status_t Layer::setBuffers( uint32_t w, uint32_t h,
|
2009-03-04 03:31:44 +00:00
|
|
|
PixelFormat format, uint32_t flags)
|
|
|
|
{
|
2009-09-24 02:16:27 +00:00
|
|
|
// this surfaces pixel format
|
2009-03-04 03:31:44 +00:00
|
|
|
PixelFormatInfo info;
|
|
|
|
status_t err = getPixelFormatInfo(format, &info);
|
|
|
|
if (err) return err;
|
|
|
|
|
2009-09-24 02:16:27 +00:00
|
|
|
// the display's pixel format
|
|
|
|
const DisplayHardware& hw(graphicPlane(0).displayHardware());
|
2010-04-14 23:43:44 +00:00
|
|
|
uint32_t const maxSurfaceDims = min(
|
|
|
|
hw.getMaxTextureSize(), hw.getMaxViewportDims());
|
|
|
|
|
|
|
|
// never allow a surface larger than what our underlying GL implementation
|
|
|
|
// can handle.
|
|
|
|
if ((uint32_t(w)>maxSurfaceDims) || (uint32_t(h)>maxSurfaceDims)) {
|
|
|
|
return BAD_VALUE;
|
|
|
|
}
|
|
|
|
|
2009-09-24 02:16:27 +00:00
|
|
|
PixelFormatInfo displayInfo;
|
|
|
|
getPixelFormatInfo(hw.getFormat(), &displayInfo);
|
2009-10-06 01:20:39 +00:00
|
|
|
const uint32_t hwFlags = hw.getFlags();
|
|
|
|
|
fix [2068105] implement queueBuffer/lockBuffer/dequeueBuffer properly
Rewrote SurfaceFlinger's buffer management from the ground-up.
The design now support an arbitrary number of buffers per surface, however the current implementation is limited to four. Currently only 2 buffers are used in practice.
The main new feature is to be able to dequeue all buffers at once (very important when there are only two).
A client can dequeue all buffers until there are none available, it can lock all buffers except the last one that is used for composition. The client will block then, until a new buffer is enqueued.
The current implementation requires that buffers are locked in the same order they are dequeued and enqueued in the same order they are locked. Only one buffer can be locked at a time.
eg. Allowed sequence: DQ, DQ, LOCK, Q, LOCK, Q
eg. Forbidden sequence: DQ, DQ, LOCK, LOCK, Q, Q
2009-09-07 23:32:45 +00:00
|
|
|
mFormat = format;
|
2010-04-14 23:43:44 +00:00
|
|
|
mWidth = w;
|
fix [2068105] implement queueBuffer/lockBuffer/dequeueBuffer properly
Rewrote SurfaceFlinger's buffer management from the ground-up.
The design now support an arbitrary number of buffers per surface, however the current implementation is limited to four. Currently only 2 buffers are used in practice.
The main new feature is to be able to dequeue all buffers at once (very important when there are only two).
A client can dequeue all buffers until there are none available, it can lock all buffers except the last one that is used for composition. The client will block then, until a new buffer is enqueued.
The current implementation requires that buffers are locked in the same order they are dequeued and enqueued in the same order they are locked. Only one buffer can be locked at a time.
eg. Allowed sequence: DQ, DQ, LOCK, Q, LOCK, Q
eg. Forbidden sequence: DQ, DQ, LOCK, LOCK, Q, Q
2009-09-07 23:32:45 +00:00
|
|
|
mHeight = h;
|
2009-10-06 00:07:12 +00:00
|
|
|
mSecure = (flags & ISurfaceComposer::eSecure) ? true : false;
|
2009-03-04 03:31:44 +00:00
|
|
|
mNeedsBlending = (info.h_alpha - info.l_alpha) > 0;
|
2009-10-06 01:20:39 +00:00
|
|
|
mNoEGLImageForSwBuffers = !(hwFlags & DisplayHardware::CACHED_BUFFERS);
|
2010-04-14 23:43:44 +00:00
|
|
|
|
2009-09-24 02:16:27 +00:00
|
|
|
// we use the red index
|
|
|
|
int displayRedSize = displayInfo.getSize(PixelFormatInfo::INDEX_RED);
|
|
|
|
int layerRedsize = info.getSize(PixelFormatInfo::INDEX_RED);
|
|
|
|
mNeedsDithering = layerRedsize > displayRedSize;
|
|
|
|
|
fix [2068105] implement queueBuffer/lockBuffer/dequeueBuffer properly
Rewrote SurfaceFlinger's buffer management from the ground-up.
The design now support an arbitrary number of buffers per surface, however the current implementation is limited to four. Currently only 2 buffers are used in practice.
The main new feature is to be able to dequeue all buffers at once (very important when there are only two).
A client can dequeue all buffers until there are none available, it can lock all buffers except the last one that is used for composition. The client will block then, until a new buffer is enqueued.
The current implementation requires that buffers are locked in the same order they are dequeued and enqueued in the same order they are locked. Only one buffer can be locked at a time.
eg. Allowed sequence: DQ, DQ, LOCK, Q, LOCK, Q
eg. Forbidden sequence: DQ, DQ, LOCK, LOCK, Q, Q
2009-09-07 23:32:45 +00:00
|
|
|
for (size_t i=0 ; i<NUM_BUFFERS ; i++) {
|
2009-10-06 00:07:12 +00:00
|
|
|
mBuffers[i] = new GraphicBuffer();
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
2009-04-18 02:36:26 +00:00
|
|
|
mSurface = new SurfaceLayer(mFlinger, clientIndex(), this);
|
2009-03-04 03:31:44 +00:00
|
|
|
return NO_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Layer::reloadTexture(const Region& dirty)
|
|
|
|
{
|
fix [2068105] implement queueBuffer/lockBuffer/dequeueBuffer properly
Rewrote SurfaceFlinger's buffer management from the ground-up.
The design now support an arbitrary number of buffers per surface, however the current implementation is limited to four. Currently only 2 buffers are used in practice.
The main new feature is to be able to dequeue all buffers at once (very important when there are only two).
A client can dequeue all buffers until there are none available, it can lock all buffers except the last one that is used for composition. The client will block then, until a new buffer is enqueued.
The current implementation requires that buffers are locked in the same order they are dequeued and enqueued in the same order they are locked. Only one buffer can be locked at a time.
eg. Allowed sequence: DQ, DQ, LOCK, Q, LOCK, Q
eg. Forbidden sequence: DQ, DQ, LOCK, LOCK, Q, Q
2009-09-07 23:32:45 +00:00
|
|
|
Mutex::Autolock _l(mLock);
|
2009-10-07 02:00:57 +00:00
|
|
|
sp<GraphicBuffer> buffer(getFrontBufferLocked());
|
2009-12-10 23:52:29 +00:00
|
|
|
if (buffer == NULL) {
|
|
|
|
// this situation can happen if we ran out of memory for instance.
|
|
|
|
// not much we can do. continue to use whatever texture was bound
|
|
|
|
// to this context.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const int index = mFrontBufferIndex;
|
2009-10-21 23:27:21 +00:00
|
|
|
|
|
|
|
// create the new texture name if needed
|
|
|
|
if (UNLIKELY(mTextures[index].name == -1U)) {
|
|
|
|
mTextures[index].name = createTexture();
|
|
|
|
mTextures[index].width = 0;
|
|
|
|
mTextures[index].height = 0;
|
|
|
|
}
|
|
|
|
|
2009-10-27 03:12:37 +00:00
|
|
|
#ifdef EGL_ANDROID_image_native_buffer
|
2009-10-21 23:27:21 +00:00
|
|
|
if (mFlags & DisplayHardware::DIRECT_TEXTURE) {
|
|
|
|
if (buffer->usage & GraphicBuffer::USAGE_HW_TEXTURE) {
|
|
|
|
if (mTextures[index].dirty) {
|
2010-03-08 19:14:20 +00:00
|
|
|
if (initializeEglImage(buffer, &mTextures[index]) != NO_ERROR) {
|
|
|
|
// not sure what we can do here...
|
|
|
|
mFlags &= ~DisplayHardware::DIRECT_TEXTURE;
|
|
|
|
goto slowpath;
|
|
|
|
}
|
2009-10-21 23:27:21 +00:00
|
|
|
}
|
2009-04-10 21:24:30 +00:00
|
|
|
} else {
|
2009-10-21 23:27:21 +00:00
|
|
|
if (mHybridBuffer==0 || (mHybridBuffer->width != buffer->width ||
|
|
|
|
mHybridBuffer->height != buffer->height)) {
|
|
|
|
mHybridBuffer.clear();
|
|
|
|
mHybridBuffer = new GraphicBuffer(
|
|
|
|
buffer->width, buffer->height, buffer->format,
|
|
|
|
GraphicBuffer::USAGE_SW_WRITE_OFTEN |
|
|
|
|
GraphicBuffer::USAGE_HW_TEXTURE);
|
2010-03-08 19:14:20 +00:00
|
|
|
if (initializeEglImage(
|
|
|
|
mHybridBuffer, &mTextures[0]) != NO_ERROR) {
|
|
|
|
// not sure what we can do here...
|
|
|
|
mFlags &= ~DisplayHardware::DIRECT_TEXTURE;
|
|
|
|
mHybridBuffer.clear();
|
|
|
|
goto slowpath;
|
|
|
|
}
|
2009-04-10 21:24:30 +00:00
|
|
|
}
|
|
|
|
|
2009-10-21 23:27:21 +00:00
|
|
|
GGLSurface t;
|
|
|
|
status_t res = buffer->lock(&t, GRALLOC_USAGE_SW_READ_OFTEN);
|
|
|
|
LOGE_IF(res, "error %d (%s) locking buffer %p",
|
|
|
|
res, strerror(res), buffer.get());
|
|
|
|
if (res == NO_ERROR) {
|
|
|
|
Texture* const texture(&mTextures[0]);
|
|
|
|
|
|
|
|
glBindTexture(GL_TEXTURE_2D, texture->name);
|
|
|
|
|
|
|
|
sp<GraphicBuffer> buf(mHybridBuffer);
|
|
|
|
void* vaddr;
|
|
|
|
res = buf->lock(GraphicBuffer::USAGE_SW_WRITE_OFTEN, &vaddr);
|
|
|
|
if (res == NO_ERROR) {
|
|
|
|
int bpp = 0;
|
|
|
|
switch (t.format) {
|
2010-02-17 01:33:37 +00:00
|
|
|
case HAL_PIXEL_FORMAT_RGB_565:
|
|
|
|
case HAL_PIXEL_FORMAT_RGBA_4444:
|
2009-10-21 23:27:21 +00:00
|
|
|
bpp = 2;
|
|
|
|
break;
|
2010-02-17 01:33:37 +00:00
|
|
|
case HAL_PIXEL_FORMAT_RGBA_8888:
|
|
|
|
case HAL_PIXEL_FORMAT_RGBX_8888:
|
2009-10-21 23:27:21 +00:00
|
|
|
bpp = 4;
|
|
|
|
break;
|
|
|
|
default:
|
2010-02-17 01:33:37 +00:00
|
|
|
if (isSupportedYuvFormat(t.format)) {
|
|
|
|
// just show the Y plane of YUV buffers
|
|
|
|
bpp = 1;
|
|
|
|
break;
|
|
|
|
}
|
2009-10-21 23:27:21 +00:00
|
|
|
// oops, we don't handle this format!
|
|
|
|
LOGE("layer %p, texture=%d, using format %d, which is not "
|
|
|
|
"supported by the GL", this, texture->name, t.format);
|
|
|
|
}
|
|
|
|
if (bpp) {
|
|
|
|
const Rect bounds(dirty.getBounds());
|
|
|
|
size_t src_stride = t.stride;
|
|
|
|
size_t dst_stride = buf->stride;
|
|
|
|
if (src_stride == dst_stride &&
|
|
|
|
bounds.width() == t.width &&
|
|
|
|
bounds.height() == t.height)
|
|
|
|
{
|
|
|
|
memcpy(vaddr, t.data, t.height * t.stride * bpp);
|
|
|
|
} else {
|
|
|
|
GLubyte const * src = t.data +
|
|
|
|
(bounds.left + bounds.top * src_stride) * bpp;
|
|
|
|
GLubyte * dst = (GLubyte *)vaddr +
|
|
|
|
(bounds.left + bounds.top * dst_stride) * bpp;
|
|
|
|
const size_t length = bounds.width() * bpp;
|
|
|
|
size_t h = bounds.height();
|
|
|
|
src_stride *= bpp;
|
|
|
|
dst_stride *= bpp;
|
|
|
|
while (h--) {
|
|
|
|
memcpy(dst, src, length);
|
|
|
|
dst += dst_stride;
|
|
|
|
src += src_stride;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
buf->unlock();
|
2009-04-10 21:24:30 +00:00
|
|
|
}
|
2009-10-21 23:27:21 +00:00
|
|
|
buffer->unlock();
|
|
|
|
}
|
2009-04-10 21:24:30 +00:00
|
|
|
}
|
2009-10-27 03:12:37 +00:00
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
{
|
2010-03-08 19:14:20 +00:00
|
|
|
slowpath:
|
2009-10-21 23:27:21 +00:00
|
|
|
for (size_t i=0 ; i<NUM_BUFFERS ; i++) {
|
2009-10-06 00:07:12 +00:00
|
|
|
mTextures[i].image = EGL_NO_IMAGE_KHR;
|
2009-10-21 23:27:21 +00:00
|
|
|
}
|
2009-04-10 21:24:30 +00:00
|
|
|
GGLSurface t;
|
2009-10-06 00:07:12 +00:00
|
|
|
status_t res = buffer->lock(&t, GRALLOC_USAGE_SW_READ_OFTEN);
|
2009-05-04 21:17:04 +00:00
|
|
|
LOGE_IF(res, "error %d (%s) locking buffer %p",
|
|
|
|
res, strerror(res), buffer.get());
|
|
|
|
if (res == NO_ERROR) {
|
2009-10-06 00:07:12 +00:00
|
|
|
loadTexture(&mTextures[0], dirty, t);
|
2009-05-04 21:17:04 +00:00
|
|
|
buffer->unlock();
|
2009-04-10 21:24:30 +00:00
|
|
|
}
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Layer::onDraw(const Region& clip) const
|
|
|
|
{
|
2009-10-06 00:07:12 +00:00
|
|
|
int index = mFrontBufferIndex;
|
|
|
|
if (mTextures[index].image == EGL_NO_IMAGE_KHR)
|
|
|
|
index = 0;
|
2009-04-10 21:24:30 +00:00
|
|
|
GLuint textureName = mTextures[index].name;
|
|
|
|
if (UNLIKELY(textureName == -1LU)) {
|
2009-03-04 03:31:44 +00:00
|
|
|
// the texture has not been created yet, this Layer has
|
2010-05-07 03:21:45 +00:00
|
|
|
// in fact never been drawn into. This happens frequently with
|
|
|
|
// SurfaceView because the WindowManager can't know when the client
|
|
|
|
// has drawn the first time.
|
|
|
|
|
|
|
|
// If there is nothing under us, we paint the screen in black, otherwise
|
|
|
|
// we just skip this update.
|
|
|
|
|
|
|
|
// figure out if there is something below us
|
|
|
|
Region under;
|
|
|
|
const SurfaceFlinger::LayerVector& drawingLayers(mFlinger->mDrawingState.layersSortedByZ);
|
|
|
|
const size_t count = drawingLayers.size();
|
|
|
|
for (size_t i=0 ; i<count ; ++i) {
|
|
|
|
const sp<LayerBase>& layer(drawingLayers[i]);
|
|
|
|
if (layer.get() == static_cast<LayerBase const*>(this))
|
|
|
|
break;
|
|
|
|
under.orSelf(layer->visibleRegionScreen);
|
|
|
|
}
|
|
|
|
// if not everything below us is covered, we plug the holes!
|
|
|
|
Region holes(clip.subtract(under));
|
|
|
|
if (!holes.isEmpty()) {
|
|
|
|
clearWithOpenGL(holes);
|
|
|
|
}
|
2009-03-04 03:31:44 +00:00
|
|
|
return;
|
|
|
|
}
|
2009-06-24 01:08:22 +00:00
|
|
|
drawWithOpenGL(clip, mTextures[index]);
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
|
|
|
|
2009-10-06 00:07:12 +00:00
|
|
|
sp<GraphicBuffer> Layer::requestBuffer(int index, int usage)
|
2009-03-04 03:31:44 +00:00
|
|
|
{
|
2009-10-06 00:07:12 +00:00
|
|
|
sp<GraphicBuffer> buffer;
|
2009-09-11 02:41:18 +00:00
|
|
|
|
|
|
|
// this ensures our client doesn't go away while we're accessing
|
|
|
|
// the shared area.
|
|
|
|
sp<Client> ourClient(client.promote());
|
|
|
|
if (ourClient == 0) {
|
|
|
|
// oops, the client is already gone
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
|
2009-04-10 21:24:30 +00:00
|
|
|
/*
|
fix [2068105] implement queueBuffer/lockBuffer/dequeueBuffer properly
Rewrote SurfaceFlinger's buffer management from the ground-up.
The design now support an arbitrary number of buffers per surface, however the current implementation is limited to four. Currently only 2 buffers are used in practice.
The main new feature is to be able to dequeue all buffers at once (very important when there are only two).
A client can dequeue all buffers until there are none available, it can lock all buffers except the last one that is used for composition. The client will block then, until a new buffer is enqueued.
The current implementation requires that buffers are locked in the same order they are dequeued and enqueued in the same order they are locked. Only one buffer can be locked at a time.
eg. Allowed sequence: DQ, DQ, LOCK, Q, LOCK, Q
eg. Forbidden sequence: DQ, DQ, LOCK, LOCK, Q, Q
2009-09-07 23:32:45 +00:00
|
|
|
* This is called from the client's Surface::dequeue(). This can happen
|
|
|
|
* at any time, especially while we're in the middle of using the
|
|
|
|
* buffer 'index' as our front buffer.
|
2009-04-10 21:24:30 +00:00
|
|
|
*
|
fix [2068105] implement queueBuffer/lockBuffer/dequeueBuffer properly
Rewrote SurfaceFlinger's buffer management from the ground-up.
The design now support an arbitrary number of buffers per surface, however the current implementation is limited to four. Currently only 2 buffers are used in practice.
The main new feature is to be able to dequeue all buffers at once (very important when there are only two).
A client can dequeue all buffers until there are none available, it can lock all buffers except the last one that is used for composition. The client will block then, until a new buffer is enqueued.
The current implementation requires that buffers are locked in the same order they are dequeued and enqueued in the same order they are locked. Only one buffer can be locked at a time.
eg. Allowed sequence: DQ, DQ, LOCK, Q, LOCK, Q
eg. Forbidden sequence: DQ, DQ, LOCK, LOCK, Q, Q
2009-09-07 23:32:45 +00:00
|
|
|
* Make sure the buffer we're resizing is not the front buffer and has been
|
|
|
|
* dequeued. Once this condition is asserted, we are guaranteed that this
|
|
|
|
* buffer cannot become the front buffer under our feet, since we're called
|
|
|
|
* from Surface::dequeue()
|
2009-04-10 21:24:30 +00:00
|
|
|
*/
|
fix [2068105] implement queueBuffer/lockBuffer/dequeueBuffer properly
Rewrote SurfaceFlinger's buffer management from the ground-up.
The design now support an arbitrary number of buffers per surface, however the current implementation is limited to four. Currently only 2 buffers are used in practice.
The main new feature is to be able to dequeue all buffers at once (very important when there are only two).
A client can dequeue all buffers until there are none available, it can lock all buffers except the last one that is used for composition. The client will block then, until a new buffer is enqueued.
The current implementation requires that buffers are locked in the same order they are dequeued and enqueued in the same order they are locked. Only one buffer can be locked at a time.
eg. Allowed sequence: DQ, DQ, LOCK, Q, LOCK, Q
eg. Forbidden sequence: DQ, DQ, LOCK, LOCK, Q, Q
2009-09-07 23:32:45 +00:00
|
|
|
status_t err = lcblk->assertReallocate(index);
|
|
|
|
LOGE_IF(err, "assertReallocate(%d) failed (%s)", index, strerror(-err));
|
2009-09-11 02:41:18 +00:00
|
|
|
if (err != NO_ERROR) {
|
|
|
|
// the surface may have died
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t w, h;
|
|
|
|
{ // scope for the lock
|
|
|
|
Mutex::Autolock _l(mLock);
|
|
|
|
w = mWidth;
|
|
|
|
h = mHeight;
|
|
|
|
buffer = mBuffers[index];
|
2009-09-18 02:19:08 +00:00
|
|
|
|
|
|
|
// destroy() could have been called before we get here, we log it
|
|
|
|
// because it's uncommon, and the code below should handle it
|
|
|
|
LOGW_IF(buffer==0,
|
|
|
|
"mBuffers[%d] is null (mWidth=%d, mHeight=%d)",
|
|
|
|
index, w, h);
|
|
|
|
|
2009-09-11 02:41:18 +00:00
|
|
|
mBuffers[index].clear();
|
|
|
|
}
|
|
|
|
|
2009-10-06 00:07:12 +00:00
|
|
|
const uint32_t effectiveUsage = getEffectiveUsage(usage);
|
2009-09-18 02:19:08 +00:00
|
|
|
if (buffer!=0 && buffer->getStrongCount() == 1) {
|
2009-10-06 00:07:12 +00:00
|
|
|
err = buffer->reallocate(w, h, mFormat, effectiveUsage);
|
fix [2068105] implement queueBuffer/lockBuffer/dequeueBuffer properly
Rewrote SurfaceFlinger's buffer management from the ground-up.
The design now support an arbitrary number of buffers per surface, however the current implementation is limited to four. Currently only 2 buffers are used in practice.
The main new feature is to be able to dequeue all buffers at once (very important when there are only two).
A client can dequeue all buffers until there are none available, it can lock all buffers except the last one that is used for composition. The client will block then, until a new buffer is enqueued.
The current implementation requires that buffers are locked in the same order they are dequeued and enqueued in the same order they are locked. Only one buffer can be locked at a time.
eg. Allowed sequence: DQ, DQ, LOCK, Q, LOCK, Q
eg. Forbidden sequence: DQ, DQ, LOCK, LOCK, Q, Q
2009-09-07 23:32:45 +00:00
|
|
|
} else {
|
|
|
|
// here we have to reallocate a new buffer because we could have a
|
|
|
|
// client in our process with a reference to it (eg: status bar),
|
|
|
|
// and we can't release the handle under its feet.
|
|
|
|
buffer.clear();
|
2009-10-06 00:07:12 +00:00
|
|
|
buffer = new GraphicBuffer(w, h, mFormat, effectiveUsage);
|
fix [2068105] implement queueBuffer/lockBuffer/dequeueBuffer properly
Rewrote SurfaceFlinger's buffer management from the ground-up.
The design now support an arbitrary number of buffers per surface, however the current implementation is limited to four. Currently only 2 buffers are used in practice.
The main new feature is to be able to dequeue all buffers at once (very important when there are only two).
A client can dequeue all buffers until there are none available, it can lock all buffers except the last one that is used for composition. The client will block then, until a new buffer is enqueued.
The current implementation requires that buffers are locked in the same order they are dequeued and enqueued in the same order they are locked. Only one buffer can be locked at a time.
eg. Allowed sequence: DQ, DQ, LOCK, Q, LOCK, Q
eg. Forbidden sequence: DQ, DQ, LOCK, LOCK, Q, Q
2009-09-07 23:32:45 +00:00
|
|
|
err = buffer->initCheck();
|
2009-04-10 21:24:30 +00:00
|
|
|
}
|
fix [2068105] implement queueBuffer/lockBuffer/dequeueBuffer properly
Rewrote SurfaceFlinger's buffer management from the ground-up.
The design now support an arbitrary number of buffers per surface, however the current implementation is limited to four. Currently only 2 buffers are used in practice.
The main new feature is to be able to dequeue all buffers at once (very important when there are only two).
A client can dequeue all buffers until there are none available, it can lock all buffers except the last one that is used for composition. The client will block then, until a new buffer is enqueued.
The current implementation requires that buffers are locked in the same order they are dequeued and enqueued in the same order they are locked. Only one buffer can be locked at a time.
eg. Allowed sequence: DQ, DQ, LOCK, Q, LOCK, Q
eg. Forbidden sequence: DQ, DQ, LOCK, LOCK, Q, Q
2009-09-07 23:32:45 +00:00
|
|
|
|
|
|
|
if (err || buffer->handle == 0) {
|
|
|
|
LOGE_IF(err || buffer->handle == 0,
|
|
|
|
"Layer::requestBuffer(this=%p), index=%d, w=%d, h=%d failed (%s)",
|
|
|
|
this, index, w, h, strerror(-err));
|
2009-03-04 03:31:44 +00:00
|
|
|
} else {
|
fix [2068105] implement queueBuffer/lockBuffer/dequeueBuffer properly
Rewrote SurfaceFlinger's buffer management from the ground-up.
The design now support an arbitrary number of buffers per surface, however the current implementation is limited to four. Currently only 2 buffers are used in practice.
The main new feature is to be able to dequeue all buffers at once (very important when there are only two).
A client can dequeue all buffers until there are none available, it can lock all buffers except the last one that is used for composition. The client will block then, until a new buffer is enqueued.
The current implementation requires that buffers are locked in the same order they are dequeued and enqueued in the same order they are locked. Only one buffer can be locked at a time.
eg. Allowed sequence: DQ, DQ, LOCK, Q, LOCK, Q
eg. Forbidden sequence: DQ, DQ, LOCK, LOCK, Q, Q
2009-09-07 23:32:45 +00:00
|
|
|
LOGD_IF(DEBUG_RESIZE,
|
2009-09-30 05:39:22 +00:00
|
|
|
"Layer::requestBuffer(this=%p), index=%d, w=%d, h=%d, handle=%p",
|
|
|
|
this, index, w, h, buffer->handle);
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
|
|
|
|
fix [2068105] implement queueBuffer/lockBuffer/dequeueBuffer properly
Rewrote SurfaceFlinger's buffer management from the ground-up.
The design now support an arbitrary number of buffers per surface, however the current implementation is limited to four. Currently only 2 buffers are used in practice.
The main new feature is to be able to dequeue all buffers at once (very important when there are only two).
A client can dequeue all buffers until there are none available, it can lock all buffers except the last one that is used for composition. The client will block then, until a new buffer is enqueued.
The current implementation requires that buffers are locked in the same order they are dequeued and enqueued in the same order they are locked. Only one buffer can be locked at a time.
eg. Allowed sequence: DQ, DQ, LOCK, Q, LOCK, Q
eg. Forbidden sequence: DQ, DQ, LOCK, LOCK, Q, Q
2009-09-07 23:32:45 +00:00
|
|
|
if (err == NO_ERROR && buffer->handle != 0) {
|
2009-09-11 02:41:18 +00:00
|
|
|
Mutex::Autolock _l(mLock);
|
|
|
|
if (mWidth && mHeight) {
|
|
|
|
// and we have new buffer
|
|
|
|
mBuffers[index] = buffer;
|
|
|
|
// texture is now dirty...
|
|
|
|
mTextures[index].dirty = true;
|
|
|
|
} else {
|
|
|
|
// oops we got killed while we were allocating the buffer
|
|
|
|
buffer.clear();
|
|
|
|
}
|
2009-06-20 00:00:27 +00:00
|
|
|
}
|
fix [2068105] implement queueBuffer/lockBuffer/dequeueBuffer properly
Rewrote SurfaceFlinger's buffer management from the ground-up.
The design now support an arbitrary number of buffers per surface, however the current implementation is limited to four. Currently only 2 buffers are used in practice.
The main new feature is to be able to dequeue all buffers at once (very important when there are only two).
A client can dequeue all buffers until there are none available, it can lock all buffers except the last one that is used for composition. The client will block then, until a new buffer is enqueued.
The current implementation requires that buffers are locked in the same order they are dequeued and enqueued in the same order they are locked. Only one buffer can be locked at a time.
eg. Allowed sequence: DQ, DQ, LOCK, Q, LOCK, Q
eg. Forbidden sequence: DQ, DQ, LOCK, LOCK, Q, Q
2009-09-07 23:32:45 +00:00
|
|
|
return buffer;
|
2009-06-20 00:00:27 +00:00
|
|
|
}
|
|
|
|
|
2009-10-06 00:07:12 +00:00
|
|
|
uint32_t Layer::getEffectiveUsage(uint32_t usage) const
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* buffers used for software rendering, but h/w composition
|
|
|
|
* are allocated with SW_READ_OFTEN | SW_WRITE_OFTEN | HW_TEXTURE
|
|
|
|
*
|
|
|
|
* buffers used for h/w rendering and h/w composition
|
|
|
|
* are allocated with HW_RENDER | HW_TEXTURE
|
|
|
|
*
|
|
|
|
* buffers used with h/w rendering and either NPOT or no egl_image_ext
|
|
|
|
* are allocated with SW_READ_RARELY | HW_RENDER
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (mSecure) {
|
|
|
|
// secure buffer, don't store it into the GPU
|
|
|
|
usage = GraphicBuffer::USAGE_SW_READ_OFTEN |
|
|
|
|
GraphicBuffer::USAGE_SW_WRITE_OFTEN;
|
|
|
|
} else {
|
|
|
|
// it's allowed to modify the usage flags here, but generally
|
|
|
|
// the requested flags should be honored.
|
2009-10-06 01:20:39 +00:00
|
|
|
if (mNoEGLImageForSwBuffers) {
|
|
|
|
if (usage & GraphicBuffer::USAGE_HW_MASK) {
|
|
|
|
// request EGLImage for h/w buffers only
|
|
|
|
usage |= GraphicBuffer::USAGE_HW_TEXTURE;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// request EGLImage for all buffers
|
|
|
|
usage |= GraphicBuffer::USAGE_HW_TEXTURE;
|
|
|
|
}
|
2009-10-06 00:07:12 +00:00
|
|
|
}
|
|
|
|
return usage;
|
|
|
|
}
|
|
|
|
|
2009-03-04 03:31:44 +00:00
|
|
|
uint32_t Layer::doTransaction(uint32_t flags)
|
|
|
|
{
|
|
|
|
const Layer::State& front(drawingState());
|
|
|
|
const Layer::State& temp(currentState());
|
|
|
|
|
2009-09-30 05:39:22 +00:00
|
|
|
if ((front.requested_w != temp.requested_w) ||
|
|
|
|
(front.requested_h != temp.requested_h)) {
|
fix [2068105] implement queueBuffer/lockBuffer/dequeueBuffer properly
Rewrote SurfaceFlinger's buffer management from the ground-up.
The design now support an arbitrary number of buffers per surface, however the current implementation is limited to four. Currently only 2 buffers are used in practice.
The main new feature is to be able to dequeue all buffers at once (very important when there are only two).
A client can dequeue all buffers until there are none available, it can lock all buffers except the last one that is used for composition. The client will block then, until a new buffer is enqueued.
The current implementation requires that buffers are locked in the same order they are dequeued and enqueued in the same order they are locked. Only one buffer can be locked at a time.
eg. Allowed sequence: DQ, DQ, LOCK, Q, LOCK, Q
eg. Forbidden sequence: DQ, DQ, LOCK, LOCK, Q, Q
2009-09-07 23:32:45 +00:00
|
|
|
// the size changed, we need to ask our client to request a new buffer
|
2009-03-04 03:31:44 +00:00
|
|
|
LOGD_IF(DEBUG_RESIZE,
|
fix [2068105] implement queueBuffer/lockBuffer/dequeueBuffer properly
Rewrote SurfaceFlinger's buffer management from the ground-up.
The design now support an arbitrary number of buffers per surface, however the current implementation is limited to four. Currently only 2 buffers are used in practice.
The main new feature is to be able to dequeue all buffers at once (very important when there are only two).
A client can dequeue all buffers until there are none available, it can lock all buffers except the last one that is used for composition. The client will block then, until a new buffer is enqueued.
The current implementation requires that buffers are locked in the same order they are dequeued and enqueued in the same order they are locked. Only one buffer can be locked at a time.
eg. Allowed sequence: DQ, DQ, LOCK, Q, LOCK, Q
eg. Forbidden sequence: DQ, DQ, LOCK, LOCK, Q, Q
2009-09-07 23:32:45 +00:00
|
|
|
"resize (layer=%p), requested (%dx%d), "
|
|
|
|
"drawing (%d,%d), (%dx%d), (%dx%d)",
|
2009-09-30 05:39:22 +00:00
|
|
|
this,
|
|
|
|
int(temp.requested_w), int(temp.requested_h),
|
|
|
|
int(front.requested_w), int(front.requested_h),
|
fix [2068105] implement queueBuffer/lockBuffer/dequeueBuffer properly
Rewrote SurfaceFlinger's buffer management from the ground-up.
The design now support an arbitrary number of buffers per surface, however the current implementation is limited to four. Currently only 2 buffers are used in practice.
The main new feature is to be able to dequeue all buffers at once (very important when there are only two).
A client can dequeue all buffers until there are none available, it can lock all buffers except the last one that is used for composition. The client will block then, until a new buffer is enqueued.
The current implementation requires that buffers are locked in the same order they are dequeued and enqueued in the same order they are locked. Only one buffer can be locked at a time.
eg. Allowed sequence: DQ, DQ, LOCK, Q, LOCK, Q
eg. Forbidden sequence: DQ, DQ, LOCK, LOCK, Q, Q
2009-09-07 23:32:45 +00:00
|
|
|
int(mBuffers[0]->getWidth()), int(mBuffers[0]->getHeight()),
|
|
|
|
int(mBuffers[1]->getWidth()), int(mBuffers[1]->getHeight()));
|
|
|
|
|
|
|
|
// we're being resized and there is a freeze display request,
|
|
|
|
// acquire a freeze lock, so that the screen stays put
|
|
|
|
// until we've redrawn at the new size; this is to avoid
|
|
|
|
// glitches upon orientation changes.
|
|
|
|
if (mFlinger->hasFreezeRequest()) {
|
|
|
|
// if the surface is hidden, don't try to acquire the
|
|
|
|
// freeze lock, since hidden surfaces may never redraw
|
|
|
|
if (!(front.flags & ISurfaceComposer::eLayerHidden)) {
|
|
|
|
mFreezeLock = mFlinger->getFreezeLock();
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
|
|
|
}
|
2009-09-17 01:27:24 +00:00
|
|
|
|
2009-09-30 21:07:22 +00:00
|
|
|
// this will make sure LayerBase::doTransaction doesn't update
|
|
|
|
// the drawing state's size
|
|
|
|
Layer::State& editDraw(mDrawingState);
|
|
|
|
editDraw.requested_w = temp.requested_w;
|
|
|
|
editDraw.requested_h = temp.requested_h;
|
|
|
|
|
2009-09-30 19:48:47 +00:00
|
|
|
// record the new size, form this point on, when the client request a
|
|
|
|
// buffer, it'll get the new size.
|
|
|
|
setDrawingSize(temp.requested_w, temp.requested_h);
|
|
|
|
|
2009-09-17 01:27:24 +00:00
|
|
|
// all buffers need reallocation
|
|
|
|
lcblk->reallocate();
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
fix [2068105] implement queueBuffer/lockBuffer/dequeueBuffer properly
Rewrote SurfaceFlinger's buffer management from the ground-up.
The design now support an arbitrary number of buffers per surface, however the current implementation is limited to four. Currently only 2 buffers are used in practice.
The main new feature is to be able to dequeue all buffers at once (very important when there are only two).
A client can dequeue all buffers until there are none available, it can lock all buffers except the last one that is used for composition. The client will block then, until a new buffer is enqueued.
The current implementation requires that buffers are locked in the same order they are dequeued and enqueued in the same order they are locked. Only one buffer can be locked at a time.
eg. Allowed sequence: DQ, DQ, LOCK, Q, LOCK, Q
eg. Forbidden sequence: DQ, DQ, LOCK, LOCK, Q, Q
2009-09-07 23:32:45 +00:00
|
|
|
|
2009-03-04 03:31:44 +00:00
|
|
|
if (temp.sequence != front.sequence) {
|
|
|
|
if (temp.flags & ISurfaceComposer::eLayerHidden || temp.alpha == 0) {
|
|
|
|
// this surface is now hidden, so it shouldn't hold a freeze lock
|
|
|
|
// (it may never redraw, which is fine if it is hidden)
|
|
|
|
mFreezeLock.clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return LayerBase::doTransaction(flags);
|
|
|
|
}
|
|
|
|
|
fix [2068105] implement queueBuffer/lockBuffer/dequeueBuffer properly
Rewrote SurfaceFlinger's buffer management from the ground-up.
The design now support an arbitrary number of buffers per surface, however the current implementation is limited to four. Currently only 2 buffers are used in practice.
The main new feature is to be able to dequeue all buffers at once (very important when there are only two).
A client can dequeue all buffers until there are none available, it can lock all buffers except the last one that is used for composition. The client will block then, until a new buffer is enqueued.
The current implementation requires that buffers are locked in the same order they are dequeued and enqueued in the same order they are locked. Only one buffer can be locked at a time.
eg. Allowed sequence: DQ, DQ, LOCK, Q, LOCK, Q
eg. Forbidden sequence: DQ, DQ, LOCK, LOCK, Q, Q
2009-09-07 23:32:45 +00:00
|
|
|
void Layer::setDrawingSize(uint32_t w, uint32_t h) {
|
|
|
|
Mutex::Autolock _l(mLock);
|
|
|
|
mWidth = w;
|
|
|
|
mHeight = h;
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// pageflip handling...
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void Layer::lockPageFlip(bool& recomputeVisibleRegions)
|
|
|
|
{
|
fix [2068105] implement queueBuffer/lockBuffer/dequeueBuffer properly
Rewrote SurfaceFlinger's buffer management from the ground-up.
The design now support an arbitrary number of buffers per surface, however the current implementation is limited to four. Currently only 2 buffers are used in practice.
The main new feature is to be able to dequeue all buffers at once (very important when there are only two).
A client can dequeue all buffers until there are none available, it can lock all buffers except the last one that is used for composition. The client will block then, until a new buffer is enqueued.
The current implementation requires that buffers are locked in the same order they are dequeued and enqueued in the same order they are locked. Only one buffer can be locked at a time.
eg. Allowed sequence: DQ, DQ, LOCK, Q, LOCK, Q
eg. Forbidden sequence: DQ, DQ, LOCK, LOCK, Q, Q
2009-09-07 23:32:45 +00:00
|
|
|
ssize_t buf = lcblk->retireAndLock();
|
|
|
|
if (buf < NO_ERROR) {
|
|
|
|
//LOGW("nothing to retire (%s)", strerror(-buf));
|
|
|
|
// NOTE: here the buffer is locked because we will used
|
|
|
|
// for composition later in the loop
|
2009-03-04 03:31:44 +00:00
|
|
|
return;
|
|
|
|
}
|
2010-03-16 01:15:20 +00:00
|
|
|
|
|
|
|
// ouch, this really should never happen
|
|
|
|
if (uint32_t(buf)>=NUM_BUFFERS) {
|
|
|
|
LOGE("retireAndLock() buffer index (%d) out of range", buf);
|
|
|
|
mPostedDirtyRegion.clear();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
fix [2068105] implement queueBuffer/lockBuffer/dequeueBuffer properly
Rewrote SurfaceFlinger's buffer management from the ground-up.
The design now support an arbitrary number of buffers per surface, however the current implementation is limited to four. Currently only 2 buffers are used in practice.
The main new feature is to be able to dequeue all buffers at once (very important when there are only two).
A client can dequeue all buffers until there are none available, it can lock all buffers except the last one that is used for composition. The client will block then, until a new buffer is enqueued.
The current implementation requires that buffers are locked in the same order they are dequeued and enqueued in the same order they are locked. Only one buffer can be locked at a time.
eg. Allowed sequence: DQ, DQ, LOCK, Q, LOCK, Q
eg. Forbidden sequence: DQ, DQ, LOCK, LOCK, Q, Q
2009-09-07 23:32:45 +00:00
|
|
|
// we retired a buffer, which becomes the new front buffer
|
|
|
|
mFrontBufferIndex = buf;
|
2009-03-04 03:31:44 +00:00
|
|
|
|
fix [2068105] implement queueBuffer/lockBuffer/dequeueBuffer properly
Rewrote SurfaceFlinger's buffer management from the ground-up.
The design now support an arbitrary number of buffers per surface, however the current implementation is limited to four. Currently only 2 buffers are used in practice.
The main new feature is to be able to dequeue all buffers at once (very important when there are only two).
A client can dequeue all buffers until there are none available, it can lock all buffers except the last one that is used for composition. The client will block then, until a new buffer is enqueued.
The current implementation requires that buffers are locked in the same order they are dequeued and enqueued in the same order they are locked. Only one buffer can be locked at a time.
eg. Allowed sequence: DQ, DQ, LOCK, Q, LOCK, Q
eg. Forbidden sequence: DQ, DQ, LOCK, LOCK, Q, Q
2009-09-07 23:32:45 +00:00
|
|
|
// get the dirty region
|
2009-10-06 00:07:12 +00:00
|
|
|
sp<GraphicBuffer> newFrontBuffer(getBuffer(buf));
|
2010-03-16 01:15:20 +00:00
|
|
|
if (newFrontBuffer != NULL) {
|
|
|
|
// compute the posted region
|
|
|
|
const Region dirty(lcblk->getDirtyRegion(buf));
|
|
|
|
mPostedDirtyRegion = dirty.intersect( newFrontBuffer->getBounds() );
|
|
|
|
|
|
|
|
// update the layer size and release freeze-lock
|
|
|
|
const Layer::State& front(drawingState());
|
|
|
|
if (newFrontBuffer->getWidth() == front.requested_w &&
|
|
|
|
newFrontBuffer->getHeight() == front.requested_h)
|
2009-09-30 21:07:22 +00:00
|
|
|
{
|
2010-03-16 01:15:20 +00:00
|
|
|
if ((front.w != front.requested_w) ||
|
|
|
|
(front.h != front.requested_h))
|
|
|
|
{
|
|
|
|
// Here we pretend the transaction happened by updating the
|
|
|
|
// current and drawing states. Drawing state is only accessed
|
|
|
|
// in this thread, no need to have it locked
|
|
|
|
Layer::State& editDraw(mDrawingState);
|
|
|
|
editDraw.w = editDraw.requested_w;
|
|
|
|
editDraw.h = editDraw.requested_h;
|
|
|
|
|
|
|
|
// We also need to update the current state so that we don't
|
|
|
|
// end-up doing too much work during the next transaction.
|
|
|
|
// NOTE: We actually don't need hold the transaction lock here
|
|
|
|
// because State::w and State::h are only accessed from
|
|
|
|
// this thread
|
|
|
|
Layer::State& editTemp(currentState());
|
|
|
|
editTemp.w = editDraw.w;
|
|
|
|
editTemp.h = editDraw.h;
|
|
|
|
|
|
|
|
// recompute visible region
|
|
|
|
recomputeVisibleRegions = true;
|
|
|
|
}
|
2009-10-08 00:58:29 +00:00
|
|
|
|
2010-03-16 01:15:20 +00:00
|
|
|
// we now have the correct size, unfreeze the screen
|
|
|
|
mFreezeLock.clear();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// this should not happen unless we ran out of memory while
|
|
|
|
// allocating the buffer. we're hoping that things will get back
|
|
|
|
// to normal the next time the app tries to draw into this buffer.
|
|
|
|
// meanwhile, pretend the screen didn't update.
|
|
|
|
mPostedDirtyRegion.clear();
|
2009-09-17 01:27:24 +00:00
|
|
|
}
|
|
|
|
|
2009-10-07 23:44:10 +00:00
|
|
|
if (lcblk->getQueuedCount()) {
|
|
|
|
// signal an event if we have more buffers waiting
|
|
|
|
mFlinger->signalEvent();
|
|
|
|
}
|
2009-03-04 03:31:44 +00:00
|
|
|
|
2010-04-21 22:24:11 +00:00
|
|
|
/* a buffer was posted, so we need to call reloadTexture(), which
|
|
|
|
* will update our internal data structures (eg: EGLImageKHR or
|
|
|
|
* texture names). we need to do this even if mPostedDirtyRegion is
|
|
|
|
* empty -- it's orthogonal to the fact that a new buffer was posted,
|
|
|
|
* for instance, a degenerate case could be that the user did an empty
|
|
|
|
* update but repainted the buffer with appropriate content (after a
|
|
|
|
* resize for instance).
|
|
|
|
*/
|
|
|
|
reloadTexture( mPostedDirtyRegion );
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Layer::unlockPageFlip(
|
|
|
|
const Transform& planeTransform, Region& outDirtyRegion)
|
|
|
|
{
|
|
|
|
Region dirtyRegion(mPostedDirtyRegion);
|
|
|
|
if (!dirtyRegion.isEmpty()) {
|
|
|
|
mPostedDirtyRegion.clear();
|
|
|
|
// The dirty region is given in the layer's coordinate space
|
|
|
|
// transform the dirty region by the surface's transformation
|
|
|
|
// and the global transformation.
|
|
|
|
const Layer::State& s(drawingState());
|
|
|
|
const Transform tr(planeTransform * s.transform);
|
|
|
|
dirtyRegion = tr.transform(dirtyRegion);
|
|
|
|
|
|
|
|
// At this point, the dirty region is in screen space.
|
|
|
|
// Make sure it's constrained by the visible region (which
|
|
|
|
// is in screen space as well).
|
|
|
|
dirtyRegion.andSelf(visibleRegionScreen);
|
|
|
|
outDirtyRegion.orSelf(dirtyRegion);
|
|
|
|
}
|
2009-11-30 19:15:41 +00:00
|
|
|
if (visibleRegionScreen.isEmpty()) {
|
|
|
|
// an invisible layer should not hold a freeze-lock
|
2010-04-21 00:55:49 +00:00
|
|
|
// (because it may never be updated and therefore never release it)
|
2009-11-30 19:15:41 +00:00
|
|
|
mFreezeLock.clear();
|
|
|
|
}
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Layer::finishPageFlip()
|
|
|
|
{
|
fix [2068105] implement queueBuffer/lockBuffer/dequeueBuffer properly
Rewrote SurfaceFlinger's buffer management from the ground-up.
The design now support an arbitrary number of buffers per surface, however the current implementation is limited to four. Currently only 2 buffers are used in practice.
The main new feature is to be able to dequeue all buffers at once (very important when there are only two).
A client can dequeue all buffers until there are none available, it can lock all buffers except the last one that is used for composition. The client will block then, until a new buffer is enqueued.
The current implementation requires that buffers are locked in the same order they are dequeued and enqueued in the same order they are locked. Only one buffer can be locked at a time.
eg. Allowed sequence: DQ, DQ, LOCK, Q, LOCK, Q
eg. Forbidden sequence: DQ, DQ, LOCK, LOCK, Q, Q
2009-09-07 23:32:45 +00:00
|
|
|
status_t err = lcblk->unlock( mFrontBufferIndex );
|
|
|
|
LOGE_IF(err!=NO_ERROR,
|
|
|
|
"layer %p, buffer=%d wasn't locked!",
|
|
|
|
this, mFrontBufferIndex);
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
|
|
|
|
2010-04-21 00:55:49 +00:00
|
|
|
|
|
|
|
void Layer::dump(String8& result, char* buffer, size_t SIZE) const
|
|
|
|
{
|
|
|
|
LayerBaseClient::dump(result, buffer, SIZE);
|
|
|
|
|
|
|
|
SharedBufferStack::Statistics stats = lcblk->getStats();
|
|
|
|
result.append( lcblk->dump(" ") );
|
|
|
|
sp<const GraphicBuffer> buf0(getBuffer(0));
|
|
|
|
sp<const GraphicBuffer> buf1(getBuffer(1));
|
|
|
|
uint32_t w0=0, h0=0, s0=0;
|
|
|
|
uint32_t w1=0, h1=0, s1=0;
|
|
|
|
if (buf0 != 0) {
|
|
|
|
w0 = buf0->getWidth();
|
|
|
|
h0 = buf0->getHeight();
|
|
|
|
s0 = buf0->getStride();
|
|
|
|
}
|
|
|
|
if (buf1 != 0) {
|
|
|
|
w1 = buf1->getWidth();
|
|
|
|
h1 = buf1->getHeight();
|
|
|
|
s1 = buf1->getStride();
|
|
|
|
}
|
|
|
|
snprintf(buffer, SIZE,
|
|
|
|
" "
|
|
|
|
"format=%2d, [%3ux%3u:%3u] [%3ux%3u:%3u],"
|
|
|
|
" freezeLock=%p, dq-q-time=%u us\n",
|
|
|
|
pixelFormat(),
|
|
|
|
w0, h0, s0, w1, h1, s1,
|
|
|
|
getFreezeLock().get(), stats.totalTime);
|
|
|
|
|
|
|
|
result.append(buffer);
|
|
|
|
}
|
|
|
|
|
2009-04-10 21:24:30 +00:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2009-04-18 02:36:26 +00:00
|
|
|
Layer::SurfaceLayer::SurfaceLayer(const sp<SurfaceFlinger>& flinger,
|
|
|
|
SurfaceID id, const sp<Layer>& owner)
|
|
|
|
: Surface(flinger, id, owner->getIdentity(), owner)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
Layer::SurfaceLayer::~SurfaceLayer()
|
2009-04-10 21:24:30 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2009-10-06 00:07:12 +00:00
|
|
|
sp<GraphicBuffer> Layer::SurfaceLayer::requestBuffer(int index, int usage)
|
2009-04-10 21:24:30 +00:00
|
|
|
{
|
2009-10-06 00:07:12 +00:00
|
|
|
sp<GraphicBuffer> buffer;
|
2009-04-10 21:24:30 +00:00
|
|
|
sp<Layer> owner(getOwner());
|
|
|
|
if (owner != 0) {
|
fix [2068105] implement queueBuffer/lockBuffer/dequeueBuffer properly
Rewrote SurfaceFlinger's buffer management from the ground-up.
The design now support an arbitrary number of buffers per surface, however the current implementation is limited to four. Currently only 2 buffers are used in practice.
The main new feature is to be able to dequeue all buffers at once (very important when there are only two).
A client can dequeue all buffers until there are none available, it can lock all buffers except the last one that is used for composition. The client will block then, until a new buffer is enqueued.
The current implementation requires that buffers are locked in the same order they are dequeued and enqueued in the same order they are locked. Only one buffer can be locked at a time.
eg. Allowed sequence: DQ, DQ, LOCK, Q, LOCK, Q
eg. Forbidden sequence: DQ, DQ, LOCK, LOCK, Q, Q
2009-09-07 23:32:45 +00:00
|
|
|
LOGE_IF(uint32_t(index)>=NUM_BUFFERS,
|
|
|
|
"getBuffer() index (%d) out of range", index);
|
|
|
|
if (uint32_t(index) < NUM_BUFFERS) {
|
|
|
|
buffer = owner->requestBuffer(index, usage);
|
|
|
|
}
|
2009-04-10 21:24:30 +00:00
|
|
|
}
|
|
|
|
return buffer;
|
|
|
|
}
|
2009-03-04 03:31:44 +00:00
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
}; // namespace android
|