summaryrefslogtreecommitdiffstats
path: root/libs/ui
diff options
context:
space:
mode:
authorFrancis Hart <fhart@nvidia.com>2014-04-01 15:30:53 +0300
committerGreg Hackmann <ghackmann@google.com>2014-05-02 13:28:14 -0700
commit378ef07760eda717367d9429428c42d54d54d9a7 (patch)
treea656f922b8f232d6e4d37a4371685e595d974446 /libs/ui
parentcb079c899ac9d9c5ec90840249821f58c817406c (diff)
downloadframeworks_native-378ef07760eda717367d9429428c42d54d54d9a7.zip
frameworks_native-378ef07760eda717367d9429428c42d54d54d9a7.tar.gz
frameworks_native-378ef07760eda717367d9429428c42d54d54d9a7.tar.bz2
Use asynchronous lock/unlock API
The gralloc API now provides a way for using lock/unlock with the Android explicit synchronisation concept. This changes updates the GraphicBuffer class to also expose this functionality, and updates the Surface class to make use of in line with the dequeueBuffer/queueBuffer mechanism. This new behaviour is dependent on GRALLOC_MODULE_API_VERSION_0_3. If the local gralloc module does not support this then the existing synchronous lock/unlock mechanism will be used. Change-Id: I77daa1beb197b63b1c2f281b8414ac4ae4b5b03c
Diffstat (limited to 'libs/ui')
-rw-r--r--libs/ui/GraphicBuffer.cpp46
-rw-r--r--libs/ui/GraphicBufferMapper.cpp62
2 files changed, 108 insertions, 0 deletions
diff --git a/libs/ui/GraphicBuffer.cpp b/libs/ui/GraphicBuffer.cpp
index 96a7188..1414805 100644
--- a/libs/ui/GraphicBuffer.cpp
+++ b/libs/ui/GraphicBuffer.cpp
@@ -200,6 +200,52 @@ status_t GraphicBuffer::unlock()
return res;
}
+status_t GraphicBuffer::lockAsync(uint32_t usage, void** vaddr, int fenceFd)
+{
+ const Rect lockBounds(width, height);
+ status_t res = lockAsync(usage, lockBounds, vaddr, fenceFd);
+ return res;
+}
+
+status_t GraphicBuffer::lockAsync(uint32_t usage, const Rect& rect, void** vaddr, int fenceFd)
+{
+ if (rect.left < 0 || rect.right > this->width ||
+ rect.top < 0 || rect.bottom > this->height) {
+ ALOGE("locking pixels (%d,%d,%d,%d) outside of buffer (w=%d, h=%d)",
+ rect.left, rect.top, rect.right, rect.bottom,
+ this->width, this->height);
+ return BAD_VALUE;
+ }
+ status_t res = getBufferMapper().lockAsync(handle, usage, rect, vaddr, fenceFd);
+ return res;
+}
+
+status_t GraphicBuffer::lockAsyncYCbCr(uint32_t usage, android_ycbcr *ycbcr, int fenceFd)
+{
+ const Rect lockBounds(width, height);
+ status_t res = lockAsyncYCbCr(usage, lockBounds, ycbcr, fenceFd);
+ return res;
+}
+
+status_t GraphicBuffer::lockAsyncYCbCr(uint32_t usage, const Rect& rect, android_ycbcr *ycbcr, int fenceFd)
+{
+ if (rect.left < 0 || rect.right > this->width ||
+ rect.top < 0 || rect.bottom > this->height) {
+ ALOGE("locking pixels (%d,%d,%d,%d) outside of buffer (w=%d, h=%d)",
+ rect.left, rect.top, rect.right, rect.bottom,
+ this->width, this->height);
+ return BAD_VALUE;
+ }
+ status_t res = getBufferMapper().lockAsyncYCbCr(handle, usage, rect, ycbcr, fenceFd);
+ return res;
+}
+
+status_t GraphicBuffer::unlockAsync(int *fenceFd)
+{
+ status_t res = getBufferMapper().unlockAsync(handle, fenceFd);
+ return res;
+}
+
size_t GraphicBuffer::getFlattenedSize() const {
return (8 + (handle ? handle->numInts : 0))*sizeof(int);
}
diff --git a/libs/ui/GraphicBufferMapper.cpp b/libs/ui/GraphicBufferMapper.cpp
index a4cfce2..320b6c0 100644
--- a/libs/ui/GraphicBufferMapper.cpp
+++ b/libs/ui/GraphicBufferMapper.cpp
@@ -20,6 +20,8 @@
#include <stdint.h>
#include <errno.h>
+#include <sync/sync.h>
+
#include <utils/Errors.h>
#include <utils/Log.h>
#include <utils/Trace.h>
@@ -109,5 +111,65 @@ status_t GraphicBufferMapper::unlock(buffer_handle_t handle)
return err;
}
+status_t GraphicBufferMapper::lockAsync(buffer_handle_t handle,
+ int usage, const Rect& bounds, void** vaddr, int fenceFd)
+{
+ ATRACE_CALL();
+ status_t err;
+
+ if (mAllocMod->common.module_api_version >= GRALLOC_MODULE_API_VERSION_0_3) {
+ err = mAllocMod->lockAsync(mAllocMod, handle, usage,
+ bounds.left, bounds.top, bounds.width(), bounds.height(),
+ vaddr, fenceFd);
+ } else {
+ sync_wait(fenceFd, -1);
+ close(fenceFd);
+ err = mAllocMod->lock(mAllocMod, handle, usage,
+ bounds.left, bounds.top, bounds.width(), bounds.height(),
+ vaddr);
+ }
+
+ ALOGW_IF(err, "lockAsync(...) failed %d (%s)", err, strerror(-err));
+ return err;
+}
+
+status_t GraphicBufferMapper::lockAsyncYCbCr(buffer_handle_t handle,
+ int usage, const Rect& bounds, android_ycbcr *ycbcr, int fenceFd)
+{
+ ATRACE_CALL();
+ status_t err;
+
+ if (mAllocMod->common.module_api_version >= GRALLOC_MODULE_API_VERSION_0_3) {
+ err = mAllocMod->lockAsync_ycbcr(mAllocMod, handle, usage,
+ bounds.left, bounds.top, bounds.width(), bounds.height(),
+ ycbcr, fenceFd);
+ } else {
+ sync_wait(fenceFd, -1);
+ close(fenceFd);
+ err = mAllocMod->lock_ycbcr(mAllocMod, handle, usage,
+ bounds.left, bounds.top, bounds.width(), bounds.height(),
+ ycbcr);
+ }
+
+ ALOGW_IF(err, "lock(...) failed %d (%s)", err, strerror(-err));
+ return err;
+}
+
+status_t GraphicBufferMapper::unlockAsync(buffer_handle_t handle, int *fenceFd)
+{
+ ATRACE_CALL();
+ status_t err;
+
+ if (mAllocMod->common.module_api_version >= GRALLOC_MODULE_API_VERSION_0_3) {
+ err = mAllocMod->unlockAsync(mAllocMod, handle, fenceFd);
+ } else {
+ *fenceFd = -1;
+ err = mAllocMod->unlock(mAllocMod, handle);
+ }
+
+ ALOGW_IF(err, "unlockAsync(...) failed %d (%s)", err, strerror(-err));
+ return err;
+}
+
// ---------------------------------------------------------------------------
}; // namespace android