display: metadata fixes

* Do not log error on invalid metadata fds, such usages are
possible in some scenarios
* Correct usage of metadata API for some cases.

CRs-Fixed: 2122143
Change-Id: Id9cc7f4d27ef1890668f414d92b96cd419b6a066
This commit is contained in:
Naseer Ahmed
2017-10-05 20:39:05 -04:00
parent 71f5daa4ea
commit 7aff26123e
4 changed files with 17 additions and 13 deletions

View File

@@ -725,7 +725,7 @@ gralloc1_error_t BufferManager::Perform(int operation, va_list args) {
return GRALLOC1_ERROR_BAD_VALUE; return GRALLOC1_ERROR_BAD_VALUE;
} }
if (getMetaData(hnd, GET_MAP_SECURE_BUFFER, map_secure_buffer) == 0) { if (getMetaData(hnd, GET_MAP_SECURE_BUFFER, map_secure_buffer) != 0) {
*map_secure_buffer = 0; *map_secure_buffer = 0;
} }
} break; } break;
@@ -853,8 +853,8 @@ gralloc1_error_t BufferManager::GetFlexLayout(const private_handle_t *hnd,
return GRALLOC1_ERROR_UNSUPPORTED; return GRALLOC1_ERROR_UNSUPPORTED;
} }
android_ycbcr ycbcr; android_ycbcr yuvPlaneInfo[2];
int err = GetYUVPlaneInfo(hnd, &ycbcr); int err = GetYUVPlaneInfo(hnd, yuvPlaneInfo);
if (err != 0) { if (err != 0) {
return GRALLOC1_ERROR_BAD_HANDLE; return GRALLOC1_ERROR_BAD_HANDLE;
@@ -872,6 +872,8 @@ gralloc1_error_t BufferManager::GetFlexLayout(const private_handle_t *hnd,
layout->planes[i].v_subsampling = 2; layout->planes[i].v_subsampling = 2;
} }
// We are only returning flex layout for progressive or single field formats.
struct android_ycbcr ycbcr = yuvPlaneInfo[0];
layout->planes[0].top_left = static_cast<uint8_t *>(ycbcr.y); layout->planes[0].top_left = static_cast<uint8_t *>(ycbcr.y);
layout->planes[0].component = FLEX_COMPONENT_Y; layout->planes[0].component = FLEX_COMPONENT_Y;
layout->planes[0].v_increment = static_cast<int32_t>(ycbcr.ystride); layout->planes[0].v_increment = static_cast<int32_t>(ycbcr.ystride);

View File

@@ -312,7 +312,7 @@ void GetYuvUbwcSPPlaneInfo(uint64_t base, uint32_t width, uint32_t height,
} }
void GetYuvUbwcInterlacedSPPlaneInfo(uint64_t base, uint32_t width, uint32_t height, void GetYuvUbwcInterlacedSPPlaneInfo(uint64_t base, uint32_t width, uint32_t height,
int color_format, struct android_ycbcr *ycbcr) { int color_format, struct android_ycbcr ycbcr[2]) {
unsigned int uv_stride, uv_height, uv_size; unsigned int uv_stride, uv_height, uv_size;
unsigned int alignment = 4096; unsigned int alignment = 4096;
uint64_t field_base; uint64_t field_base;
@@ -329,6 +329,7 @@ void GetYuvUbwcInterlacedSPPlaneInfo(uint64_t base, uint32_t width, uint32_t hei
field_base = base; field_base = base;
GetYuvUbwcSPPlaneInfo(field_base, width, height, COLOR_FMT_NV12_UBWC, &ycbcr[0]); GetYuvUbwcSPPlaneInfo(field_base, width, height, COLOR_FMT_NV12_UBWC, &ycbcr[0]);
memset(ycbcr[1].reserved, 0, sizeof(ycbcr[1].reserved));
field_base = reinterpret_cast<uint64_t>(ycbcr[0].cb) + uv_size; field_base = reinterpret_cast<uint64_t>(ycbcr[0].cb) + uv_size;
GetYuvUbwcSPPlaneInfo(field_base, width, height, COLOR_FMT_NV12_UBWC, &ycbcr[1]); GetYuvUbwcSPPlaneInfo(field_base, width, height, COLOR_FMT_NV12_UBWC, &ycbcr[1]);
} }
@@ -346,7 +347,7 @@ void GetYuvSPPlaneInfo(uint64_t base, uint32_t width, uint32_t height, uint32_t
ycbcr->chroma_step = 2 * bpp; ycbcr->chroma_step = 2 * bpp;
} }
int GetYUVPlaneInfo(const private_handle_t *hnd, struct android_ycbcr *ycbcr) { int GetYUVPlaneInfo(const private_handle_t *hnd, struct android_ycbcr ycbcr[2]) {
int err = 0; int err = 0;
uint32_t width = UINT(hnd->width); uint32_t width = UINT(hnd->width);
uint32_t height = UINT(hnd->height); uint32_t height = UINT(hnd->height);
@@ -382,7 +383,7 @@ int GetYUVPlaneInfo(const private_handle_t *hnd, struct android_ycbcr *ycbcr) {
// Check metadata for interlaced content. // Check metadata for interlaced content.
int interlace_flag = 0; int interlace_flag = 0;
if (getMetaData(const_cast<private_handle_t *>(hnd), if (getMetaData(const_cast<private_handle_t *>(hnd),
GET_PP_PARAM_INTERLACED, &interlace_flag) != 0) { GET_PP_PARAM_INTERLACED, &interlace_flag) == 0) {
interlaced = interlace_flag; interlaced = interlace_flag;
} }
@@ -772,7 +773,7 @@ int GetBufferLayout(private_handle_t *hnd, uint32_t stride[4],
return -EINVAL; return -EINVAL;
} }
struct android_ycbcr yuvInfo = {}; struct android_ycbcr yuvPlaneInfo[2] = {};
*num_planes = 1; *num_planes = 1;
stride[0] = 0; stride[0] = 0;
@@ -808,12 +809,14 @@ int GetBufferLayout(private_handle_t *hnd, uint32_t stride[4],
} }
(*num_planes)++; (*num_planes)++;
int ret = GetYUVPlaneInfo(hnd, &yuvInfo); int ret = GetYUVPlaneInfo(hnd, yuvPlaneInfo);
if (ret < 0) { if (ret < 0) {
ALOGE("%s failed", __FUNCTION__); ALOGE("%s failed", __FUNCTION__);
return ret; return ret;
} }
// We are only returning buffer layout for progressive or single field formats.
struct android_ycbcr yuvInfo = yuvPlaneInfo[0];
stride[0] = static_cast<uint32_t>(yuvInfo.ystride); stride[0] = static_cast<uint32_t>(yuvInfo.ystride);
offset[0] = static_cast<uint32_t>(reinterpret_cast<uint64_t>(yuvInfo.y) - hnd->base); offset[0] = static_cast<uint32_t>(reinterpret_cast<uint64_t>(yuvInfo.y) - hnd->base);
stride[1] = static_cast<uint32_t>(yuvInfo.cstride); stride[1] = static_cast<uint32_t>(yuvInfo.cstride);

View File

@@ -71,7 +71,7 @@ void GetBufferSizeAndDimensions(const BufferInfo &d, unsigned int *size,
unsigned int *alignedw, unsigned int *alignedh); unsigned int *alignedw, unsigned int *alignedh);
void GetAlignedWidthAndHeight(const BufferInfo &d, unsigned int *aligned_w, void GetAlignedWidthAndHeight(const BufferInfo &d, unsigned int *aligned_w,
unsigned int *aligned_h); unsigned int *aligned_h);
int GetYUVPlaneInfo(const private_handle_t *hnd, struct android_ycbcr *ycbcr); int GetYUVPlaneInfo(const private_handle_t *hnd, struct android_ycbcr ycbcr[2]);
int GetRgbDataAddress(private_handle_t *hnd, void **rgb_data); int GetRgbDataAddress(private_handle_t *hnd, void **rgb_data);
bool IsUBwcFormat(int format); bool IsUBwcFormat(int format);
bool IsUBwcSupported(int format); bool IsUBwcSupported(int format);
@@ -84,7 +84,7 @@ void GetYuvSPPlaneInfo(uint64_t base, uint32_t width, uint32_t height, uint32_t
void GetYuvUbwcSPPlaneInfo(uint64_t base, uint32_t width, uint32_t height, int color_format, void GetYuvUbwcSPPlaneInfo(uint64_t base, uint32_t width, uint32_t height, int color_format,
struct android_ycbcr *ycbcr); struct android_ycbcr *ycbcr);
void GetYuvUbwcInterlacedSPPlaneInfo(uint64_t base, uint32_t width, uint32_t height, void GetYuvUbwcInterlacedSPPlaneInfo(uint64_t base, uint32_t width, uint32_t height,
int color_format, struct android_ycbcr *ycbcr); int color_format, struct android_ycbcr ycbcr[2]);
void GetRgbUBwcBlockSize(uint32_t bpp, int *block_width, int *block_height); void GetRgbUBwcBlockSize(uint32_t bpp, int *block_width, int *block_height);
unsigned int GetRgbUBwcMetaBufferSize(int width, int height, uint32_t bpp); unsigned int GetRgbUBwcMetaBufferSize(int width, int height, uint32_t bpp);
unsigned int GetUBwcSize(int width, int height, int format, unsigned int alignedw, unsigned int GetUBwcSize(int width, int height, int format, unsigned int alignedw,

View File

@@ -44,9 +44,8 @@ static int validateAndMap(private_handle_t* handle) {
ALOGE("%s: Private handle is invalid - handle:%p", __func__, handle); ALOGE("%s: Private handle is invalid - handle:%p", __func__, handle);
return -1; return -1;
} }
if (handle->fd_metadata == -1) { if (handle->fd_metadata < 0) {
ALOGE("%s: Invalid metadata fd - handle:%p fd: %d", // Silently return, metadata cannot be used
__func__, handle, handle->fd_metadata);
return -1; return -1;
} }