Commit add24cb7 authored by Roman Stratiienko's avatar Roman Stratiienko
Browse files

drm_hwcomposer: stop using pixel_stride



pixel_stride is used only to validate buffer when importing using
GraphicBufferMapper::importBuffer() method.

The problem is we can't always get this value from buffer_handle_t.
Libdrm and MapperMetadata getters can only calculate this value based
on byte stride and buffer format. But this calculation isn't always
possible, which causes importBuffer() to fail.

Instead we can use GrallocMapper::importBuffer() method,
which doesn't require to validate the buffer.

This commit is not compatible with Android-P.

Signed-off-by: Roman Stratiienko's avatarRoman Stratiienko <r.stratiienko@gmail.com>
parent 33365c2b
......@@ -44,6 +44,7 @@ cc_defaults {
"libcutils",
"libdrm",
"libhardware",
"libhidlbase",
"liblog",
"libsync",
"libui",
......
......@@ -96,24 +96,6 @@ uint32_t LegacyBufferInfoGetter::ConvertHalFormatToDrm(uint32_t hal_format) {
}
}
uint32_t BufferInfoGetter::DrmFormatToBitsPerPixel(uint32_t drm_format) {
switch (drm_format) {
case DRM_FORMAT_ARGB8888:
case DRM_FORMAT_XBGR8888:
case DRM_FORMAT_ABGR8888:
return 32;
case DRM_FORMAT_BGR888:
return 24;
case DRM_FORMAT_BGR565:
return 16;
case DRM_FORMAT_YVU420:
return 12;
default:
ALOGE("Cannot convert hal format %u to bpp (returning 32)", drm_format);
return 32;
}
}
bool BufferInfoGetter::IsDrmFormatRgb(uint32_t drm_format) {
switch (drm_format) {
case DRM_FORMAT_ARGB8888:
......
......@@ -40,7 +40,6 @@ class BufferInfoGetter {
static BufferInfoGetter *GetInstance();
static uint32_t DrmFormatToBitsPerPixel(uint32_t drm_format);
static bool IsDrmFormatRgb(uint32_t drm_format);
};
......
......@@ -45,7 +45,6 @@ int BufferInfoImagination::ConvertBoInfo(buffer_handle_t handle,
bo->prime_fds[0] = hnd->fd[0];
bo->pitches[0] = ALIGN(hnd->iWidth, HW_ALIGN) * hnd->uiBpp >> 3;
bo->hal_format = hnd->iFormat;
bo->pixel_stride = hnd->aiStride[0];
switch (hnd->iFormat) {
#ifdef HAL_PIXEL_FORMAT_BGRX_8888
......
......@@ -189,9 +189,6 @@ int BufferInfoLibdrm::ConvertBoInfo(buffer_handle_t handle, hwc_drm_bo_t *bo) {
return -EINVAL;
}
bo->pixel_stride = (gr_handle->stride * 8) /
DrmFormatToBitsPerPixel(bo->format);
return 0;
}
......
......@@ -91,7 +91,6 @@ int BufferInfoMaliHisi::ConvertBoInfo(buffer_handle_t handle,
bo->hal_format = hnd->req_format;
bo->format = fmt;
bo->usage = hnd->usage;
bo->pixel_stride = hnd->stride;
bo->pitches[0] = hnd->byte_stride;
bo->prime_fds[0] = hnd->share_fd;
bo->offsets[0] = 0;
......
......@@ -48,7 +48,6 @@ int BufferInfoMaliMediatek::ConvertBoInfo(buffer_handle_t handle,
bo->hal_format = hnd->req_format;
bo->format = fmt;
bo->usage = hnd->consumer_usage | hnd->producer_usage;
bo->pixel_stride = hnd->stride;
bo->prime_fds[0] = hnd->share_fd;
bo->pitches[0] = hnd->byte_stride;
bo->offsets[0] = 0;
......
......@@ -83,7 +83,6 @@ int BufferInfoMaliMeson::ConvertBoInfo(buffer_handle_t handle,
bo->hal_format = hnd->req_format;
bo->format = fmt;
bo->usage = hnd->usage;
bo->pixel_stride = hnd->stride;
bo->prime_fds[0] = hnd->share_fd;
bo->pitches[0] = hnd->byte_stride;
bo->offsets[0] = 0;
......
......@@ -38,7 +38,6 @@ int BufferInfoMinigbm::ConvertBoInfo(buffer_handle_t handle, hwc_drm_bo_t *bo) {
bo->hal_format = gr_handle->droid_format;
bo->format = gr_handle->format;
bo->usage = gr_handle->usage;
bo->pixel_stride = gr_handle->pixel_stride;
bo->prime_fds[0] = gr_handle->fds[0];
bo->pitches[0] = gr_handle->strides[0];
bo->offsets[0] = gr_handle->offsets[0];
......
......@@ -26,7 +26,6 @@ typedef struct hwc_drm_bo {
uint32_t format; /* DRM_FORMAT_* from drm_fourcc.h */
uint32_t hal_format; /* HAL_PIXEL_FORMAT_* */
uint32_t usage;
uint32_t pixel_stride;
uint32_t pitches[HWC_DRM_BO_MAX_PLANES];
uint32_t offsets[HWC_DRM_BO_MAX_PLANES];
uint32_t prime_fds[HWC_DRM_BO_MAX_PLANES];
......
......@@ -99,8 +99,7 @@ class DrmHwcNativeHandle {
return *this;
}
int CopyBufferHandle(buffer_handle_t handle, int width, int height,
int layerCount, int format, int usage, int stride);
int CopyBufferHandle(buffer_handle_t handle);
void Clear();
......
......@@ -18,6 +18,7 @@
#define LOG_TAG "hwc-drm-utils"
#include <log/log.h>
#include <ui/Gralloc.h>
#include <ui/GraphicBufferMapper.h>
#include "bufferinfo/BufferInfoGetter.h"
......@@ -64,25 +65,15 @@ int DrmHwcBuffer::ImportBuffer(buffer_handle_t handle, Importer *importer) {
return 0;
}
int DrmHwcNativeHandle::CopyBufferHandle(buffer_handle_t handle, int width,
int height, int layerCount, int format,
int usage, int stride) {
int DrmHwcNativeHandle::CopyBufferHandle(buffer_handle_t handle) {
native_handle_t *handle_copy;
GraphicBufferMapper &gm(GraphicBufferMapper::get());
int ret;
#ifdef HWC2_USE_OLD_GB_IMPORT
UNUSED(width);
UNUSED(height);
UNUSED(layerCount);
UNUSED(format);
UNUSED(usage);
UNUSED(stride);
ret = gm.importBuffer(handle, const_cast<buffer_handle_t *>(&handle_copy));
#else
ret = gm.importBuffer(handle, width, height, layerCount, format, usage,
stride, const_cast<buffer_handle_t *>(&handle_copy));
#endif
ret = gm.getGrallocMapper().importBuffer(handle,
const_cast<buffer_handle_t *>(
&handle_copy));
if (ret) {
ALOGE("Failed to import buffer handle %d", ret);
return ret;
......@@ -117,9 +108,7 @@ int DrmHwcLayer::ImportBuffer(Importer *importer) {
const hwc_drm_bo *bo = buffer.operator->();
ret = handle.CopyBufferHandle(sf_handle, bo->width, bo->height,
1 /*layer_count*/, bo->hal_format, bo->usage,
bo->pixel_stride);
ret = handle.CopyBufferHandle(sf_handle);
if (ret)
return ret;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment