Within CpuConsumer, use gralloc lockAsync/unlockAsync

Change-Id: I6b2cd195e111c3c7bf94c8052af4db92e09649a5
This commit is contained in:
Riley Andrews 2014-08-18 16:57:11 -07:00
parent 866399093f
commit d53e052322

View File

@ -93,18 +93,38 @@ status_t CpuConsumer::lockNextBuffer(LockedBuffer *nativeBuffer) {
int buf = b.mBuf;
void *bufferPointer = NULL;
android_ycbcr ycbcr = android_ycbcr();
if (b.mFence.get()) {
err = b.mFence->waitForever("CpuConsumer::lockNextBuffer");
if (mSlots[buf].mGraphicBuffer->getPixelFormat() ==
HAL_PIXEL_FORMAT_YCbCr_420_888) {
err = mSlots[buf].mGraphicBuffer->lockAsyncYCbCr(
GraphicBuffer::USAGE_SW_READ_OFTEN,
b.mCrop,
&ycbcr,
b.mFence->dup());
if (err != OK) {
CC_LOGE("Failed to wait for fence of acquired buffer: %s (%d)",
CC_LOGE("Unable to lock YCbCr buffer for CPU reading: %s (%d)",
strerror(-err), err);
return err;
}
bufferPointer = ycbcr.y;
} else {
err = mSlots[buf].mGraphicBuffer->lockAsync(
GraphicBuffer::USAGE_SW_READ_OFTEN,
b.mCrop,
&bufferPointer,
b.mFence->dup());
if (err != OK) {
CC_LOGE("Unable to lock buffer for CPU reading: %s (%d)",
strerror(-err), err);
return err;
}
}
void *bufferPointer = NULL;
android_ycbcr ycbcr = android_ycbcr();
} else {
if (mSlots[buf].mGraphicBuffer->getPixelFormat() ==
HAL_PIXEL_FORMAT_YCbCr_420_888) {
err = mSlots[buf].mGraphicBuffer->lockYCbCr(
@ -130,6 +150,7 @@ status_t CpuConsumer::lockNextBuffer(LockedBuffer *nativeBuffer) {
return err;
}
}
}
size_t lockedIdx = 0;
for (; lockedIdx < mMaxLockedBuffers; lockedIdx++) {
@ -189,14 +210,22 @@ status_t CpuConsumer::unlockBuffer(const LockedBuffer &nativeBuffer) {
status_t CpuConsumer::releaseAcquiredBufferLocked(int lockedIdx) {
status_t err;
int fd = -1;
err = mAcquiredBuffers[lockedIdx].mGraphicBuffer->unlock();
err = mAcquiredBuffers[lockedIdx].mGraphicBuffer->unlockAsync(&fd);
if (err != OK) {
CC_LOGE("%s: Unable to unlock graphic buffer %d", __FUNCTION__,
lockedIdx);
return err;
}
int buf = mAcquiredBuffers[lockedIdx].mSlot;
if (CC_LIKELY(fd != -1)) {
sp<Fence> fence(new Fence(fd));
addReleaseFenceLocked(
mAcquiredBuffers[lockedIdx].mSlot,
mSlots[buf].mGraphicBuffer,
fence);
}
// release the buffer if it hasn't already been freed by the BufferQueue.
// This can happen, for example, when the producer of this buffer