Merge "CpuConsumer: lock buffers that could be YUV as ycbcr" into lmp-mr1-dev
This commit is contained in:
commit
94ee9b5916
@ -54,8 +54,12 @@ class CpuConsumer : public ConsumerBase
|
|||||||
uint32_t scalingMode;
|
uint32_t scalingMode;
|
||||||
int64_t timestamp;
|
int64_t timestamp;
|
||||||
uint64_t frameNumber;
|
uint64_t frameNumber;
|
||||||
// Values below are only valid when using
|
// this is the same as format, except for formats that are compatible with
|
||||||
// HAL_PIXEL_FORMAT_YCbCr_420_888, in which case LockedBuffer::data
|
// a flexible format (e.g. HAL_PIXEL_FORMAT_YCbCr_420_888). In the latter
|
||||||
|
// case this contains that flexible format
|
||||||
|
PixelFormat flexFormat;
|
||||||
|
// Values below are only valid when using HAL_PIXEL_FORMAT_YCbCr_420_888
|
||||||
|
// or compatible format, in which case LockedBuffer::data
|
||||||
// contains the Y channel, and stride is the Y channel stride. For other
|
// contains the Y channel, and stride is the Y channel stride. For other
|
||||||
// formats, these will all be 0.
|
// formats, these will all be 0.
|
||||||
uint8_t *dataCb;
|
uint8_t *dataCb;
|
||||||
|
@ -67,6 +67,34 @@ status_t CpuConsumer::setDefaultBufferFormat(uint32_t defaultFormat)
|
|||||||
return mConsumer->setDefaultBufferFormat(defaultFormat);
|
return mConsumer->setDefaultBufferFormat(defaultFormat);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool isPossiblyYUV(PixelFormat format) {
|
||||||
|
switch ((int)format) {
|
||||||
|
case HAL_PIXEL_FORMAT_RGBA_8888:
|
||||||
|
case HAL_PIXEL_FORMAT_RGBX_8888:
|
||||||
|
case HAL_PIXEL_FORMAT_RGB_888:
|
||||||
|
case HAL_PIXEL_FORMAT_RGB_565:
|
||||||
|
case HAL_PIXEL_FORMAT_BGRA_8888:
|
||||||
|
case HAL_PIXEL_FORMAT_sRGB_A_8888:
|
||||||
|
case HAL_PIXEL_FORMAT_sRGB_X_8888:
|
||||||
|
case HAL_PIXEL_FORMAT_Y8:
|
||||||
|
case HAL_PIXEL_FORMAT_Y16:
|
||||||
|
case HAL_PIXEL_FORMAT_RAW16: // same as HAL_PIXEL_FORMAT_RAW_SENSOR
|
||||||
|
case HAL_PIXEL_FORMAT_RAW10:
|
||||||
|
case HAL_PIXEL_FORMAT_RAW_OPAQUE:
|
||||||
|
case HAL_PIXEL_FORMAT_BLOB:
|
||||||
|
case HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED:
|
||||||
|
return false;
|
||||||
|
|
||||||
|
case HAL_PIXEL_FORMAT_YV12:
|
||||||
|
case HAL_PIXEL_FORMAT_YCbCr_420_888:
|
||||||
|
case HAL_PIXEL_FORMAT_YCbCr_422_SP:
|
||||||
|
case HAL_PIXEL_FORMAT_YCrCb_420_SP:
|
||||||
|
case HAL_PIXEL_FORMAT_YCbCr_422_I:
|
||||||
|
default:
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
status_t CpuConsumer::lockNextBuffer(LockedBuffer *nativeBuffer) {
|
status_t CpuConsumer::lockNextBuffer(LockedBuffer *nativeBuffer) {
|
||||||
status_t err;
|
status_t err;
|
||||||
|
|
||||||
@ -96,59 +124,51 @@ status_t CpuConsumer::lockNextBuffer(LockedBuffer *nativeBuffer) {
|
|||||||
void *bufferPointer = NULL;
|
void *bufferPointer = NULL;
|
||||||
android_ycbcr ycbcr = android_ycbcr();
|
android_ycbcr ycbcr = android_ycbcr();
|
||||||
|
|
||||||
if (b.mFence.get()) {
|
PixelFormat format = mSlots[buf].mGraphicBuffer->getPixelFormat();
|
||||||
if (mSlots[buf].mGraphicBuffer->getPixelFormat() ==
|
PixelFormat flexFormat = format;
|
||||||
HAL_PIXEL_FORMAT_YCbCr_420_888) {
|
if (isPossiblyYUV(format)) {
|
||||||
|
if (b.mFence.get()) {
|
||||||
err = mSlots[buf].mGraphicBuffer->lockAsyncYCbCr(
|
err = mSlots[buf].mGraphicBuffer->lockAsyncYCbCr(
|
||||||
GraphicBuffer::USAGE_SW_READ_OFTEN,
|
GraphicBuffer::USAGE_SW_READ_OFTEN,
|
||||||
b.mCrop,
|
b.mCrop,
|
||||||
&ycbcr,
|
&ycbcr,
|
||||||
b.mFence->dup());
|
b.mFence->dup());
|
||||||
|
|
||||||
if (err != OK) {
|
|
||||||
CC_LOGE("Unable to lock YCbCr buffer for CPU reading: %s (%d)",
|
|
||||||
strerror(-err), err);
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
bufferPointer = ycbcr.y;
|
|
||||||
} else {
|
} else {
|
||||||
|
err = mSlots[buf].mGraphicBuffer->lockYCbCr(
|
||||||
|
GraphicBuffer::USAGE_SW_READ_OFTEN,
|
||||||
|
b.mCrop,
|
||||||
|
&ycbcr);
|
||||||
|
}
|
||||||
|
if (err == OK) {
|
||||||
|
bufferPointer = ycbcr.y;
|
||||||
|
flexFormat = HAL_PIXEL_FORMAT_YCbCr_420_888;
|
||||||
|
if (format != HAL_PIXEL_FORMAT_YCbCr_420_888) {
|
||||||
|
CC_LOGV("locking buffer of format %#x as flex YUV", format);
|
||||||
|
}
|
||||||
|
} else if (format == HAL_PIXEL_FORMAT_YCbCr_420_888) {
|
||||||
|
CC_LOGE("Unable to lock YCbCr buffer for CPU reading: %s (%d)",
|
||||||
|
strerror(-err), err);
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bufferPointer == NULL) { // not flexible YUV
|
||||||
|
if (b.mFence.get()) {
|
||||||
err = mSlots[buf].mGraphicBuffer->lockAsync(
|
err = mSlots[buf].mGraphicBuffer->lockAsync(
|
||||||
GraphicBuffer::USAGE_SW_READ_OFTEN,
|
GraphicBuffer::USAGE_SW_READ_OFTEN,
|
||||||
b.mCrop,
|
b.mCrop,
|
||||||
&bufferPointer,
|
&bufferPointer,
|
||||||
b.mFence->dup());
|
b.mFence->dup());
|
||||||
|
|
||||||
if (err != OK) {
|
|
||||||
CC_LOGE("Unable to lock buffer for CPU reading: %s (%d)",
|
|
||||||
strerror(-err), err);
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (mSlots[buf].mGraphicBuffer->getPixelFormat() ==
|
|
||||||
HAL_PIXEL_FORMAT_YCbCr_420_888) {
|
|
||||||
err = mSlots[buf].mGraphicBuffer->lockYCbCr(
|
|
||||||
GraphicBuffer::USAGE_SW_READ_OFTEN,
|
|
||||||
b.mCrop,
|
|
||||||
&ycbcr);
|
|
||||||
|
|
||||||
if (err != OK) {
|
|
||||||
CC_LOGE("Unable to lock YCbCr buffer for CPU reading: %s (%d)",
|
|
||||||
strerror(-err), err);
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
bufferPointer = ycbcr.y;
|
|
||||||
} else {
|
} else {
|
||||||
err = mSlots[buf].mGraphicBuffer->lock(
|
err = mSlots[buf].mGraphicBuffer->lock(
|
||||||
GraphicBuffer::USAGE_SW_READ_OFTEN,
|
GraphicBuffer::USAGE_SW_READ_OFTEN,
|
||||||
b.mCrop,
|
b.mCrop,
|
||||||
&bufferPointer);
|
&bufferPointer);
|
||||||
|
}
|
||||||
if (err != OK) {
|
if (err != OK) {
|
||||||
CC_LOGE("Unable to lock buffer for CPU reading: %s (%d)",
|
CC_LOGE("Unable to lock buffer for CPU reading: %s (%d)",
|
||||||
strerror(-err), err);
|
strerror(-err), err);
|
||||||
return err;
|
return err;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -170,7 +190,8 @@ status_t CpuConsumer::lockNextBuffer(LockedBuffer *nativeBuffer) {
|
|||||||
reinterpret_cast<uint8_t*>(bufferPointer);
|
reinterpret_cast<uint8_t*>(bufferPointer);
|
||||||
nativeBuffer->width = mSlots[buf].mGraphicBuffer->getWidth();
|
nativeBuffer->width = mSlots[buf].mGraphicBuffer->getWidth();
|
||||||
nativeBuffer->height = mSlots[buf].mGraphicBuffer->getHeight();
|
nativeBuffer->height = mSlots[buf].mGraphicBuffer->getHeight();
|
||||||
nativeBuffer->format = mSlots[buf].mGraphicBuffer->getPixelFormat();
|
nativeBuffer->format = format;
|
||||||
|
nativeBuffer->flexFormat = flexFormat;
|
||||||
nativeBuffer->stride = (ycbcr.y != NULL) ?
|
nativeBuffer->stride = (ycbcr.y != NULL) ?
|
||||||
ycbcr.ystride :
|
ycbcr.ystride :
|
||||||
mSlots[buf].mGraphicBuffer->getStride();
|
mSlots[buf].mGraphicBuffer->getStride();
|
||||||
|
Loading…
Reference in New Issue
Block a user