* commit '38c9e1327a5b24267c3dab5293bc9d7ada6e9fc9': Use asynchronous lock/unlock API
This commit is contained in:
commit
f974bffb36
@ -98,6 +98,11 @@ public:
|
||||
status_t lockYCbCr(uint32_t usage, android_ycbcr *ycbcr);
|
||||
status_t lockYCbCr(uint32_t usage, const Rect& rect, android_ycbcr *ycbcr);
|
||||
status_t unlock();
|
||||
status_t lockAsync(uint32_t usage, void** vaddr, int fenceFd);
|
||||
status_t lockAsync(uint32_t usage, const Rect& rect, void** vaddr, int fenceFd);
|
||||
status_t lockAsyncYCbCr(uint32_t usage, android_ycbcr *ycbcr, int fenceFd);
|
||||
status_t lockAsyncYCbCr(uint32_t usage, const Rect& rect, android_ycbcr *ycbcr, int fenceFd);
|
||||
status_t unlockAsync(int *fenceFd);
|
||||
|
||||
ANativeWindowBuffer* getNativeBuffer() const;
|
||||
|
||||
|
@ -50,6 +50,14 @@ public:
|
||||
|
||||
status_t unlock(buffer_handle_t handle);
|
||||
|
||||
status_t lockAsync(buffer_handle_t handle,
|
||||
int usage, const Rect& bounds, void** vaddr, int fenceFd);
|
||||
|
||||
status_t lockAsyncYCbCr(buffer_handle_t handle,
|
||||
int usage, const Rect& bounds, android_ycbcr *ycbcr, int fenceFd);
|
||||
|
||||
status_t unlockAsync(buffer_handle_t handle, int *fenceFd);
|
||||
|
||||
// dumps information about the mapping of this handle
|
||||
void dump(buffer_handle_t handle);
|
||||
|
||||
|
@ -764,15 +764,6 @@ status_t Surface::lock(
|
||||
ALOGE_IF(err, "dequeueBuffer failed (%s)", strerror(-err));
|
||||
if (err == NO_ERROR) {
|
||||
sp<GraphicBuffer> backBuffer(GraphicBuffer::getSelf(out));
|
||||
sp<Fence> fence(new Fence(fenceFd));
|
||||
|
||||
err = fence->waitForever("Surface::lock");
|
||||
if (err != OK) {
|
||||
ALOGE("Fence::wait failed (%s)", strerror(-err));
|
||||
cancelBuffer(out, fenceFd);
|
||||
return err;
|
||||
}
|
||||
|
||||
const Rect bounds(backBuffer->width, backBuffer->height);
|
||||
|
||||
Region newDirtyRegion;
|
||||
@ -823,9 +814,9 @@ status_t Surface::lock(
|
||||
}
|
||||
|
||||
void* vaddr;
|
||||
status_t res = backBuffer->lock(
|
||||
status_t res = backBuffer->lockAsync(
|
||||
GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN,
|
||||
newDirtyRegion.bounds(), &vaddr);
|
||||
newDirtyRegion.bounds(), &vaddr, fenceFd);
|
||||
|
||||
ALOGW_IF(res, "failed locking buffer (handle = %p)",
|
||||
backBuffer->handle);
|
||||
@ -851,10 +842,11 @@ status_t Surface::unlockAndPost()
|
||||
return INVALID_OPERATION;
|
||||
}
|
||||
|
||||
status_t err = mLockedBuffer->unlock();
|
||||
int fd = -1;
|
||||
status_t err = mLockedBuffer->unlockAsync(&fd);
|
||||
ALOGE_IF(err, "failed unlocking buffer (%p)", mLockedBuffer->handle);
|
||||
|
||||
err = queueBuffer(mLockedBuffer.get(), -1);
|
||||
err = queueBuffer(mLockedBuffer.get(), fd);
|
||||
ALOGE_IF(err, "queueBuffer (handle=%p) failed (%s)",
|
||||
mLockedBuffer->handle, strerror(-err));
|
||||
|
||||
|
@ -208,6 +208,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 (10 + (handle ? handle->numInts : 0))*sizeof(int);
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user