summaryrefslogtreecommitdiffstats
path: root/libs/surfaceflinger/BufferAllocator.cpp
diff options
context:
space:
mode:
authorMathias Agopian <mathias@google.com>2009-09-07 16:32:45 -0700
committerMathias Agopian <mathias@google.com>2009-09-07 16:32:45 -0700
commit9779b221e999583ff89e0dfc40e56398737adbb3 (patch)
tree76b185d252b95b05e8d74e7a1644b843f8839725 /libs/surfaceflinger/BufferAllocator.cpp
parenta4eb91da03bd785bc91bed0d25a9efaa9baba1c1 (diff)
downloadframeworks_base-9779b221e999583ff89e0dfc40e56398737adbb3.zip
frameworks_base-9779b221e999583ff89e0dfc40e56398737adbb3.tar.gz
frameworks_base-9779b221e999583ff89e0dfc40e56398737adbb3.tar.bz2
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
Diffstat (limited to 'libs/surfaceflinger/BufferAllocator.cpp')
-rw-r--r--libs/surfaceflinger/BufferAllocator.cpp11
1 files changed, 10 insertions, 1 deletions
diff --git a/libs/surfaceflinger/BufferAllocator.cpp b/libs/surfaceflinger/BufferAllocator.cpp
index cee8b64..19867a5 100644
--- a/libs/surfaceflinger/BufferAllocator.cpp
+++ b/libs/surfaceflinger/BufferAllocator.cpp
@@ -71,14 +71,23 @@ void BufferAllocator::dump(String8& result) const
result.append(buffer);
}
+static inline uint32_t clamp(uint32_t c) {
+ return c>0 ? c : 1;
+}
+
status_t BufferAllocator::alloc(uint32_t w, uint32_t h, PixelFormat format,
int usage, buffer_handle_t* handle, int32_t* stride)
{
Mutex::Autolock _l(mLock);
-
+
+ // make sure to not allocate a 0 x 0 buffer
+ w = clamp(w);
+ h = clamp(h);
+
// we have a h/w allocator and h/w buffer is requested
status_t err = mAllocDev->alloc(mAllocDev,
w, h, format, usage, handle, stride);
+
LOGW_IF(err, "alloc(%u, %u, %d, %08x, ...) failed %d (%s)",
w, h, format, usage, err, strerror(-err));