summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJamie Gennis <jgennis@google.com>2012-12-07 10:58:22 -0800
committerAndroid Git Automerger <android-git-automerger@android.com>2012-12-07 10:58:22 -0800
commit2d659286b59dc7ff7378fe967f1c425e92155995 (patch)
treebd2cbddf30f01970989e25867fca77387632799e
parent3ed2736c10efb2f18062591e308036837d9725a4 (diff)
parent2e59d2c3fdc0bcfedbe9c5d04d7acadc3eff8887 (diff)
downloadframeworks_native-2d659286b59dc7ff7378fe967f1c425e92155995.zip
frameworks_native-2d659286b59dc7ff7378fe967f1c425e92155995.tar.gz
frameworks_native-2d659286b59dc7ff7378fe967f1c425e92155995.tar.bz2
am 2e59d2c3: DO NOT MERGE GraphicBufferAllocator: make frees async
* commit '2e59d2c3fdc0bcfedbe9c5d04d7acadc3eff8887': DO NOT MERGE GraphicBufferAllocator: make frees async
-rw-r--r--include/ui/GraphicBufferAllocator.h1
-rw-r--r--libs/ui/GraphicBufferAllocator.cpp66
2 files changed, 56 insertions, 11 deletions
diff --git a/include/ui/GraphicBufferAllocator.h b/include/ui/GraphicBufferAllocator.h
index dffa788..479cd3e 100644
--- a/include/ui/GraphicBufferAllocator.h
+++ b/include/ui/GraphicBufferAllocator.h
@@ -84,6 +84,7 @@ private:
static KeyedVector<buffer_handle_t, alloc_rec_t> sAllocList;
friend class Singleton<GraphicBufferAllocator>;
+ friend class BufferLiberatorThread;
GraphicBufferAllocator();
~GraphicBufferAllocator();
diff --git a/libs/ui/GraphicBufferAllocator.cpp b/libs/ui/GraphicBufferAllocator.cpp
index ff550d9..72acd7d 100644
--- a/libs/ui/GraphicBufferAllocator.cpp
+++ b/libs/ui/GraphicBufferAllocator.cpp
@@ -129,21 +129,65 @@ status_t GraphicBufferAllocator::alloc(uint32_t w, uint32_t h, PixelFormat forma
return err;
}
-status_t GraphicBufferAllocator::free(buffer_handle_t handle)
-{
- ATRACE_CALL();
- status_t err;
+class BufferLiberatorThread : public Thread {
+public:
+
+ static void queueCaptiveBuffer(buffer_handle_t handle) {
+ static sp<BufferLiberatorThread> thread(new BufferLiberatorThread);
+ static bool running = false;
+ if (!running) {
+ thread->run("BufferLiberator");
+ running = true;
+ }
+ {
+ Mutex::Autolock lock(thread->mMutex);
+ thread->mQueue.push_back(handle);
+ thread->mCondition.signal();
+ }
+ }
- err = mAllocDev->free(mAllocDev, handle);
+private:
- ALOGW_IF(err, "free(...) failed %d (%s)", err, strerror(-err));
- if (err == NO_ERROR) {
- Mutex::Autolock _l(sLock);
- KeyedVector<buffer_handle_t, alloc_rec_t>& list(sAllocList);
- list.removeItem(handle);
+ BufferLiberatorThread() {}
+
+ virtual bool threadLoop() {
+ buffer_handle_t handle;
+ {
+ Mutex::Autolock lock(mMutex);
+ while (mQueue.isEmpty()) {
+ mCondition.wait(mMutex);
+ }
+ handle = mQueue[0];
+ mQueue.removeAt(0);
+ }
+
+ status_t err;
+ GraphicBufferAllocator& gba(GraphicBufferAllocator::get());
+ { // Scope for tracing
+ ATRACE_NAME("gralloc::free");
+ err = gba.mAllocDev->free(gba.mAllocDev, handle);
+ }
+ ALOGW_IF(err, "free(...) failed %d (%s)", err, strerror(-err));
+
+ if (err == NO_ERROR) {
+ Mutex::Autolock _l(GraphicBufferAllocator::sLock);
+ KeyedVector<buffer_handle_t, GraphicBufferAllocator::alloc_rec_t>&
+ list(GraphicBufferAllocator::sAllocList);
+ list.removeItem(handle);
+ }
+
+ return true;
}
- return err;
+ Vector<buffer_handle_t> mQueue;
+ Condition mCondition;
+ Mutex mMutex;
+};
+
+status_t GraphicBufferAllocator::free(buffer_handle_t handle)
+{
+ BufferLiberatorThread::queueCaptiveBuffer(handle);
+ return NO_ERROR;
}
// ---------------------------------------------------------------------------