drm_hwcomposer: Store pixel_stride in the hwc_drm_bo
The new GraphicBufferMapper ImportBuffer takes a pixel_stride
as an argument, so we need to caluclate that and store it in
the hwc_drm_bo at import so we can use it here.
I'd still welcome better ideas to calculate pixel_stride for
generic drm importer.
Change-Id: Iea2c483f3750dd5bed38740802b560911bc54ef2
Signed-off-by: John Stultz <john.stultz@linaro.org>
---
v2:
* Utilized pixel stride values already in some gralloc handle
implementations
* Fixed embarasing bit/byte math snafu (preserving bits per
pixel since YUV conversions using bytes doesn't seem sane)
- Extra review still would be appreciated here!
v3:
* Renamed to use Drm... instead of DRM...
diff --git a/drmhwcgralloc.h b/drmhwcgralloc.h
index abfd2c1..65a4007 100644
--- a/drmhwcgralloc.h
+++ b/drmhwcgralloc.h
@@ -26,6 +26,7 @@
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 gem_handles[HWC_DRM_BO_MAX_PLANES];
diff --git a/platformdrmgeneric.cpp b/platformdrmgeneric.cpp
index 491b2e3..24d0650 100644
--- a/platformdrmgeneric.cpp
+++ b/platformdrmgeneric.cpp
@@ -83,6 +83,24 @@
}
}
+uint32_t DrmGenericImporter::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;
+ }
+}
+
int DrmGenericImporter::ImportBuffer(buffer_handle_t handle, hwc_drm_bo_t *bo) {
gralloc_handle_t *gr_handle = gralloc_handle(handle);
if (!gr_handle)
@@ -101,6 +119,8 @@
bo->hal_format = gr_handle->format;
bo->format = ConvertHalFormatToDrm(gr_handle->format);
bo->usage = gr_handle->usage;
+ bo->pixel_stride = (gr_handle->stride * 8) /
+ DrmFormatToBitsPerPixel(bo->format);
bo->pitches[0] = gr_handle->stride;
bo->gem_handles[0] = gem_handle;
bo->offsets[0] = 0;
diff --git a/platformdrmgeneric.h b/platformdrmgeneric.h
index ebe27b7..d46e8b0 100644
--- a/platformdrmgeneric.h
+++ b/platformdrmgeneric.h
@@ -35,6 +35,7 @@
int ReleaseBuffer(hwc_drm_bo_t *bo) override;
uint32_t ConvertHalFormatToDrm(uint32_t hal_format);
+ uint32_t DrmFormatToBitsPerPixel(uint32_t drm_format);
private:
DrmDevice *drm_;
diff --git a/platformhisi.cpp b/platformhisi.cpp
index 1723cb8..68bb5a7 100644
--- a/platformhisi.cpp
+++ b/platformhisi.cpp
@@ -99,7 +99,7 @@
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->gem_handles[0] = gem_handle;
bo->offsets[0] = 0;
diff --git a/platformminigbm.cpp b/platformminigbm.cpp
index 24112aa..2040768 100644
--- a/platformminigbm.cpp
+++ b/platformminigbm.cpp
@@ -85,6 +85,7 @@
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->pitches[0] = gr_handle->strides[0];
bo->offsets[0] = gr_handle->offsets[0];
bo->gem_handles[0] = gem_handle;