Skip to content

Commit d76a74d

Browse files
zhangyichixsysopenci
authored andcommitted
Fixed the validateBufferSize issue
when we use format HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED to allocate the buffer, we get the buffer with format DRM_FORMAT_XBGR8888. The validateBufferSize will return an error because format mismatch. So we should ignore this type. Tracked-On: OAM-110999 Signed-off-by: zhangyichix <yichix.zhang@intel.com>
1 parent dd2d07e commit d76a74d

File tree

4 files changed

+24
-10
lines changed

4 files changed

+24
-10
lines changed

cros_gralloc/cros_gralloc_helpers.cc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
*/
66

77
#include "cros_gralloc_helpers.h"
8+
#include <hardware/gralloc.h>
9+
#include "i915_private_android_types.h"
810

911
#include <sync/sync.h>
1012

@@ -32,6 +34,21 @@ bool is_flex_format(uint32_t format)
3234
}
3335
#endif
3436

37+
bool flex_format_match(uint32_t descriptor_format, uint32_t handle_format, uint64_t usage)
38+
{
39+
bool flag = usage & (GRALLOC_USAGE_HW_CAMERA_READ | GRALLOC_USAGE_HW_CAMERA_WRITE);
40+
41+
/* HACK: See b/28671744 */
42+
if (HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED == descriptor_format &&
43+
((HAL_PIXEL_FORMAT_NV12 == handle_format && flag) ||
44+
(HAL_PIXEL_FORMAT_RGBX_8888 == handle_format && !flag)))
45+
return true;
46+
else if (HAL_PIXEL_FORMAT_YCBCR_420_888 == descriptor_format && HAL_PIXEL_FORMAT_NV12 == handle_format)
47+
return true;
48+
else
49+
return false;
50+
}
51+
3552
uint32_t cros_gralloc_convert_format(int format)
3653
{
3754
/*

cros_gralloc/cros_gralloc_helpers.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ cros_gralloc_handle_t cros_gralloc_convert_handle(buffer_handle_t handle);
2424

2525
int32_t cros_gralloc_sync_wait(int32_t fence, bool close_fence);
2626

27+
bool flex_format_match(uint32_t descriptor_format, uint32_t handle_format, uint64_t usage = 0);
28+
2729
#ifdef USE_GRALLOC1
2830
int32_t cros_gralloc_sync_wait(int32_t acquire_fence);
2931
const char *drmFormat2Str(int format);

cros_gralloc/gralloc1/cros_gralloc1_module.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,8 @@ int32_t CrosGralloc1::validateBufferSize(buffer_handle_t buffer,
330330
return CROS_GRALLOC_ERROR_BAD_HANDLE;
331331
}
332332

333-
if (!is_flex_format(cros_gralloc_convert_format(descriptorInfo->format)) &&
333+
if (!flex_format_match((uint32_t)descriptorInfo->format, (uint32_t)hnd->droid_format,
334+
descriptorInfo->producerUsage | descriptorInfo->consumerUsage) &&
334335
cros_gralloc_convert_format(descriptorInfo->format) != hnd->format) {
335336
return CROS_GRALLOC_ERROR_BAD_VALUE;
336337
}

cros_gralloc/gralloc4/CrosGralloc4Mapper.cc

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
#include "cros_gralloc/gralloc4/CrosGralloc4Utils.h"
1717
#include "helpers.h"
18+
#include "cros_gralloc/cros_gralloc_helpers.h"
1819

1920
#ifdef USE_GRALLOC1
2021
#include "cros_gralloc/i915_private_android_types.h"
@@ -149,16 +150,9 @@ Return<Error> CrosGralloc4Mapper::validateBufferSize(void* rawHandle,
149150
}
150151

151152
PixelFormat crosHandleFormat = static_cast<PixelFormat>(crosHandle->droid_format);
152-
#ifdef USE_GRALLOC1
153-
int32_t yuvFormat = static_cast<int32_t>(descriptor.format);
154-
if (descriptor.format != crosHandleFormat && yuvFormat != crosHandle->droid_format &&
155-
!(descriptor.format == PixelFormat::YCBCR_420_888 &&
156-
crosHandle->droid_format == HAL_PIXEL_FORMAT_NV12)) {
157-
drv_log("Failed to validateBufferSize. Format mismatch.\n");
158-
#else
159-
if (descriptor.format != crosHandleFormat) {
153+
if (descriptor.format != crosHandleFormat &&
154+
!flex_format_match((uint32_t)descriptor.format, (uint32_t)crosHandleFormat, descriptor.usage)) {
160155
drv_log("Failed to validateBufferSize. Format mismatch.\n");
161-
#endif
162156
return Error::BAD_BUFFER;
163157
}
164158

0 commit comments

Comments
 (0)