From d6297f7d096cee1ce180ac7bc26604a179e742c5 Mon Sep 17 00:00:00 2001 From: Mathias Agopian Date: Mon, 17 May 2010 17:27:26 -0700 Subject: [PATCH] fix some bugs in SharedBufferStack::resize added buffers should now be labeled properly. Change-Id: I28aa753fbe89ab89134e7753575319478934c7fa --- include/private/surfaceflinger/SharedBufferStack.h | 9 +++++---- libs/surfaceflinger_client/SharedBufferStack.cpp | 6 ++++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/include/private/surfaceflinger/SharedBufferStack.h b/include/private/surfaceflinger/SharedBufferStack.h index c23832d49..a1a02e06a 100644 --- a/include/private/surfaceflinger/SharedBufferStack.h +++ b/include/private/surfaceflinger/SharedBufferStack.h @@ -295,7 +295,8 @@ private: friend class BufferList; uint32_t mask, curr; const_iterator(uint32_t mask) : - mask(mask), curr(31 - __builtin_clz(mask)) { } + mask(mask), curr(__builtin_clz(mask)) { + } public: inline bool operator == (const const_iterator& rhs) const { return mask == rhs.mask; @@ -304,9 +305,9 @@ private: return mask != rhs.mask; } inline int operator *() const { return curr; } - inline const const_iterator& operator ++(int) { - mask &= ~curr; - curr = 31 - __builtin_clz(mask); + inline const const_iterator& operator ++() { + mask &= ~(1<<(31-curr)); + curr = __builtin_clz(mask); return *this; } }; diff --git a/libs/surfaceflinger_client/SharedBufferStack.cpp b/libs/surfaceflinger_client/SharedBufferStack.cpp index 4a980268f..570574863 100644 --- a/libs/surfaceflinger_client/SharedBufferStack.cpp +++ b/libs/surfaceflinger_client/SharedBufferStack.cpp @@ -560,6 +560,7 @@ status_t SharedBufferServer::resize(int newNumBuffers) int base = numBuffers; int32_t avail = stack.available; int tail = head - avail + 1; + if (tail >= 0) { int8_t* const index = const_cast(stack.index); const int nb = numBuffers - head; @@ -573,8 +574,9 @@ status_t SharedBufferServer::resize(int newNumBuffers) // fill the new free space with unused buffers BufferList::const_iterator curr(mBufferList.free_begin()); for (int i=0 ; i