Skip to content

Commit

Permalink
Changes to support Gralloc 4.0 mapper
Browse files Browse the repository at this point in the history
As per Gralloc 4.0 mapper, buffer has to be imported before its usage.
So changes done in camera vhal to import the buffer before its usage.

Tracked-On: OAM-105783
Signed-off-by: Deepa K G <[email protected]>
  • Loading branch information
gkdeepa authored and JeevakaPrabu committed May 2, 2023
1 parent d07864d commit 98d9cf6
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 10 deletions.
25 changes: 22 additions & 3 deletions include/GrallocModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@

#ifdef USE_GRALLOC1
#include <hardware/gralloc1.h>
#include <sync/sync.h>
#endif

class GrallocModule {
Expand Down Expand Up @@ -129,8 +128,7 @@ class GrallocModule {
int32_t fenceFd = -1;
int error = m_gralloc1_unlock(m_gralloc1_device, handle, &fenceFd);
if (!error) {
sync_wait(fenceFd, -1);
close(fenceFd);
ALOGVV("m_gralloc1_unlock failed");
}
return error;
}
Expand All @@ -145,6 +143,24 @@ class GrallocModule {
}
}

int importBuffer(buffer_handle_t handle, buffer_handle_t *outBuffer) {
switch (m_major_version) {
case 1:
#ifdef USE_GRALLOC1
{
return m_gralloc1_importbuffer(m_gralloc1_device, handle, outBuffer);
}
#endif
default: {
ALOGE(
"[Gralloc] no gralloc module to import; unknown gralloc major "
"version (%d)",
m_major_version);
return -1;
}
}
}

private:
GrallocModule() {
mModule = nullptr;
Expand All @@ -171,6 +187,8 @@ class GrallocModule {
m_gralloc1_getNumFlexPlanes =
(GRALLOC1_PFN_GET_NUM_FLEX_PLANES)m_gralloc1_device->getFunction(
m_gralloc1_device, GRALLOC1_FUNCTION_GET_NUM_FLEX_PLANES);
m_gralloc1_importbuffer = (GRALLOC1_PFN_IMPORT_BUFFER)m_gralloc1_device->getFunction(
m_gralloc1_device, GRALLOC1_FUNCTION_IMPORT_BUFFER);
break;
#endif
default:
Expand All @@ -187,6 +205,7 @@ class GrallocModule {
GRALLOC1_PFN_UNLOCK m_gralloc1_unlock = nullptr;
GRALLOC1_PFN_LOCK_FLEX m_gralloc1_lockflex = nullptr;
GRALLOC1_PFN_GET_NUM_FLEX_PLANES m_gralloc1_getNumFlexPlanes = nullptr;
GRALLOC1_PFN_IMPORT_BUFFER m_gralloc1_importbuffer = nullptr;
#endif
};

Expand Down
26 changes: 19 additions & 7 deletions src/VirtualFakeCamera3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1079,35 +1079,50 @@ status_t VirtualFakeCamera3::processCaptureRequest(camera3_capture_request *requ
ALOGE("%s: Request %d: Buffer %zu: Fence timed out after %d ms", __FUNCTION__,
frameNumber, i, kFenceTimeoutMs);
}
native_handle_t* rawHandle = native_handle_clone(*(destBuf.buffer));
buffer_handle_t outBuffer;
if (res == OK) {
// Lock buffer for writing
if (srcBuf.stream->format == HAL_PIXEL_FORMAT_YCbCr_420_888 ||
srcBuf.stream->format == HAL_PIXEL_FORMAT_YCrCb_420_SP) {
if (destBuf.format == HAL_PIXEL_FORMAT_YCbCr_420_888 ||
destBuf.format == HAL_PIXEL_FORMAT_YCrCb_420_SP) {
android_ycbcr ycbcr = android_ycbcr();
res = GrallocModule::getInstance().lock_ycbcr(*(destBuf.buffer),

res = GrallocModule::getInstance().importBuffer(rawHandle, &outBuffer);
if (res != OK) {
ALOGE("%s:%d Gralloc importBuffer failed",__FUNCTION__, __LINE__);
res = INVALID_OPERATION;
} else {
res = GrallocModule::getInstance().lock_ycbcr(outBuffer,
#ifdef USE_GRALLOC1
GRALLOC1_PRODUCER_USAGE_CPU_WRITE,
#else
GRALLOC_USAGE_HW_CAMERA_WRITE,
#endif
0, 0, destBuf.width,
destBuf.height, &ycbcr);
destBuf.img = static_cast<uint8_t *>(ycbcr.y);
destBuf.img = static_cast<uint8_t *>(ycbcr.y);
}
} else {
ALOGE("Unexpected private format for flexible YUV: 0x%x", destBuf.format);
res = INVALID_OPERATION;
}
} else {
res = GrallocModule::getInstance().lock(*(destBuf.buffer),
res = GrallocModule::getInstance().importBuffer(rawHandle, &outBuffer);
if (res != OK) {
ALOGE("%s:%d Gralloc importBuffer failed",__FUNCTION__, __LINE__);
res = INVALID_OPERATION;
} else {
res = GrallocModule::getInstance().lock(outBuffer,
#ifdef USE_GRALLOC1
GRALLOC1_PRODUCER_USAGE_CPU_WRITE,
#else
GRALLOC_USAGE_HW_CAMERA_WRITE,
#endif
0, 0, destBuf.width, destBuf.height,
(void **)&(destBuf.img));
}
}
if (res != OK) {
ALOGE("%s: Request %d: Buffer %zu: Unable to lock buffer", __FUNCTION__,
Expand All @@ -1132,6 +1147,7 @@ status_t VirtualFakeCamera3::processCaptureRequest(camera3_capture_request *requ

sensorBuffers->push_back(destBuf);
buffers->push_back(srcBuf);
GrallocModule::getInstance().unlock(outBuffer);
}

/**
Expand Down Expand Up @@ -2720,7 +2736,6 @@ bool VirtualFakeCamera3::ReadoutThread::threadLoop() {
res);
// fallthrough for cleanup
}
GrallocModule::getInstance().unlock(*(buf->buffer));

buf->status = goodBuffer ? CAMERA3_BUFFER_STATUS_OK : CAMERA3_BUFFER_STATUS_ERROR;
buf->acquire_fence = -1;
Expand Down Expand Up @@ -2793,9 +2808,6 @@ bool VirtualFakeCamera3::ReadoutThread::threadLoop() {

void VirtualFakeCamera3::ReadoutThread::onJpegDone(const StreamBuffer &jpegBuffer, bool success) {
Mutex::Autolock jl(mJpegLock);

GrallocModule::getInstance().unlock(*(jpegBuffer.buffer));

mJpegHalBuffer.status = success ? CAMERA3_BUFFER_STATUS_OK : CAMERA3_BUFFER_STATUS_ERROR;
mJpegHalBuffer.acquire_fence = -1;
mJpegHalBuffer.release_fence = -1;
Expand Down

0 comments on commit 98d9cf6

Please sign in to comment.