OSDN Git Service

drm_hwcomposer: libdrmgetter: fix RGB565 format translation
authorRoman Stratiienko <r.stratiienko@gmail.com>
Fri, 30 Oct 2020 11:53:00 +0000 (13:53 +0200)
committerRoman Stratiienko <r.stratiienko@gmail.com>
Tue, 3 Nov 2020 06:32:35 +0000 (08:32 +0200)
FOSS graphic components (gbm_gralloc, mesa3d) are translating
HAL_PIXEL_FORMAT_RGB_565 to DRM_FORMAT_RGB565 without swapping
the R and B components. Same must be done here.

Fixes wrong colors in some games (i.e. Pixel Wheels).

Signed-off-by: Roman Stratiienko <r.stratiienko@gmail.com>
bufferinfo/legacy/BufferInfoLibdrm.cpp

index 3f6a6fd..bd51d0e 100644 (file)
@@ -184,7 +184,18 @@ int BufferInfoLibdrm::ConvertBoInfo(buffer_handle_t handle, hwc_drm_bo_t *bo) {
   } else {
     bo->pitches[0] = gr_handle->stride;
     bo->offsets[0] = 0;
-    bo->format = ConvertHalFormatToDrm(gr_handle->format);
+
+    /* FOSS graphic components (gbm_gralloc, mesa3d) are translating
+     * HAL_PIXEL_FORMAT_RGB_565 to DRM_FORMAT_RGB565 without swapping
+     * the R and B components. Same must be done here. */
+    switch (bo->hal_format) {
+      case HAL_PIXEL_FORMAT_RGB_565:
+        bo->format = DRM_FORMAT_RGB565;
+        break;
+      default:
+        bo->format = ConvertHalFormatToDrm(gr_handle->format);
+    }
+
     if (bo->format == DRM_FORMAT_INVALID)
       return -EINVAL;
   }