From 378ef07760eda717367d9429428c42d54d54d9a7 Mon Sep 17 00:00:00 2001 From: Francis Hart Date: Tue, 1 Apr 2014 15:30:53 +0300 Subject: 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 --- libs/ui/GraphicBufferMapper.cpp | 62 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) (limited to 'libs/ui/GraphicBufferMapper.cpp') diff --git a/libs/ui/GraphicBufferMapper.cpp b/libs/ui/GraphicBufferMapper.cpp index a4cfce2999..320b6c03d4 100644 --- a/libs/ui/GraphicBufferMapper.cpp +++ b/libs/ui/GraphicBufferMapper.cpp @@ -20,6 +20,8 @@ #include #include +#include + #include #include #include @@ -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 -- cgit v1.2.3-59-g8ed1b