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 <r.stratiienko@gmail.com>
diff --git a/Android.bp b/Android.bp
index 170bd31..20b22ce 100644
--- a/Android.bp
+++ b/Android.bp
@@ -44,6 +44,7 @@
"libcutils",
"libdrm",
"libhardware",
+ "libhidlbase",
"liblog",
"libsync",
"libui",
diff --git a/bufferinfo/BufferInfoGetter.cpp b/bufferinfo/BufferInfoGetter.cpp
index 8b3f1a4..afdc50e 100644
--- a/bufferinfo/BufferInfoGetter.cpp
+++ b/bufferinfo/BufferInfoGetter.cpp
@@ -96,24 +96,6 @@
}
}
-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:
diff --git a/bufferinfo/BufferInfoGetter.h b/bufferinfo/BufferInfoGetter.h
index 78c29ff..fad3d16 100644
--- a/bufferinfo/BufferInfoGetter.h
+++ b/bufferinfo/BufferInfoGetter.h
@@ -40,7 +40,6 @@
static BufferInfoGetter *GetInstance();
- static uint32_t DrmFormatToBitsPerPixel(uint32_t drm_format);
static bool IsDrmFormatRgb(uint32_t drm_format);
};
diff --git a/bufferinfo/legacy/BufferInfoImagination.cpp b/bufferinfo/legacy/BufferInfoImagination.cpp
index 3d04a4b..84c177e 100644
--- a/bufferinfo/legacy/BufferInfoImagination.cpp
+++ b/bufferinfo/legacy/BufferInfoImagination.cpp
@@ -45,7 +45,6 @@
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
diff --git a/bufferinfo/legacy/BufferInfoLibdrm.cpp b/bufferinfo/legacy/BufferInfoLibdrm.cpp
index 872ee19..3f6a6fd 100644
--- a/bufferinfo/legacy/BufferInfoLibdrm.cpp
+++ b/bufferinfo/legacy/BufferInfoLibdrm.cpp
@@ -189,9 +189,6 @@
return -EINVAL;
}
- bo->pixel_stride = (gr_handle->stride * 8) /
- DrmFormatToBitsPerPixel(bo->format);
-
return 0;
}
diff --git a/bufferinfo/legacy/BufferInfoMaliHisi.cpp b/bufferinfo/legacy/BufferInfoMaliHisi.cpp
index 98b2786..ab5579c 100644
--- a/bufferinfo/legacy/BufferInfoMaliHisi.cpp
+++ b/bufferinfo/legacy/BufferInfoMaliHisi.cpp
@@ -91,7 +91,6 @@
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;
diff --git a/bufferinfo/legacy/BufferInfoMaliMediatek.cpp b/bufferinfo/legacy/BufferInfoMaliMediatek.cpp
index 594b582..ce47343 100644
--- a/bufferinfo/legacy/BufferInfoMaliMediatek.cpp
+++ b/bufferinfo/legacy/BufferInfoMaliMediatek.cpp
@@ -48,7 +48,6 @@
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;
diff --git a/bufferinfo/legacy/BufferInfoMaliMeson.cpp b/bufferinfo/legacy/BufferInfoMaliMeson.cpp
index 2f1ca21..b6896e1 100644
--- a/bufferinfo/legacy/BufferInfoMaliMeson.cpp
+++ b/bufferinfo/legacy/BufferInfoMaliMeson.cpp
@@ -83,7 +83,6 @@
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;
diff --git a/bufferinfo/legacy/BufferInfoMinigbm.cpp b/bufferinfo/legacy/BufferInfoMinigbm.cpp
index 67a85cb..860de08 100644
--- a/bufferinfo/legacy/BufferInfoMinigbm.cpp
+++ b/bufferinfo/legacy/BufferInfoMinigbm.cpp
@@ -38,7 +38,6 @@
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];
diff --git a/include/drmhwcgralloc.h b/include/drmhwcgralloc.h
index b959714..fc0af64 100644
--- a/include/drmhwcgralloc.h
+++ b/include/drmhwcgralloc.h
@@ -26,7 +26,6 @@
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];
diff --git a/include/drmhwcomposer.h b/include/drmhwcomposer.h
index 69313d9..0706ae5 100644
--- a/include/drmhwcomposer.h
+++ b/include/drmhwcomposer.h
@@ -99,8 +99,7 @@
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();
diff --git a/utils/hwcutils.cpp b/utils/hwcutils.cpp
index 2cd46fa..8cd5c65 100644
--- a/utils/hwcutils.cpp
+++ b/utils/hwcutils.cpp
@@ -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 @@
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 @@
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;