[Mesa-dev] [PATCH] egl, wayland: RGB565 format support on Back-buffer

2015-02-10 Thread Dongwon Kim
From: Vivek Kasireddy 

In current code, color format is always hardcoded to
__DRI_IMAGE_FORMAT_ARGB when buffer or DRI image is
allocated in function calls, get_back_bo and dri2_get_buffers,
regardless of current target's color format. This problem
may leads to incorrect render pitch calculation, which
eventually ends up with wrong offset of pixels in
the frame buffer when the image is in different color format
from dri surf's, especially with different bpp. (e.g. RGB565-16bpp)

Attached code patch simply adds RGB565 and XRGB cases to two
functions noted above to resolve the issue.

v2: added a case of XRGB, format and bpp selection is done
via switch-case (not "if-else" anymore)

Signed-off-by: Vivek Kasireddy 
Signed-off-by: Dongwon Kim 
---
 src/egl/drivers/dri2/platform_wayland.c |   41 ---
 1 file changed, 38 insertions(+), 3 deletions(-)

diff --git a/src/egl/drivers/dri2/platform_wayland.c 
b/src/egl/drivers/dri2/platform_wayland.c
index 3c34e07..07f68a2 100644
--- a/src/egl/drivers/dri2/platform_wayland.c
+++ b/src/egl/drivers/dri2/platform_wayland.c
@@ -292,6 +292,26 @@ get_back_bo(struct dri2_egl_surface *dri2_surf)
struct dri2_egl_display *dri2_dpy =
   dri2_egl_display(dri2_surf->base.Resource.Display);
int i;
+   unsigned int dri_image_format;
+
+   /* currently supports three WL DRM formats,
+* WL_DRM_FORMAT_ARGB, WL_DRM_FORMAT_XRGB,
+* and WL_DRM_FORMAT_RGB565
+*/
+   switch (dri2_surf->format) {
+   case WL_DRM_FORMAT_ARGB:
+  dri_image_format = __DRI_IMAGE_FORMAT_ARGB;
+  break;
+   case WL_DRM_FORMAT_XRGB:
+  dri_image_format = __DRI_IMAGE_FORMAT_XRGB;
+  break;
+   case WL_DRM_FORMAT_RGB565:
+  dri_image_format = __DRI_IMAGE_FORMAT_RGB565;
+  break;
+   default:
+  /* format is not supported */
+  return -1;
+   }
 
/* We always want to throttle to some event (either a frame callback or
 * a sync request) after the commit so that we can be sure the
@@ -322,7 +342,7 @@ get_back_bo(struct dri2_egl_surface *dri2_surf)
  dri2_dpy->image->createImage(dri2_dpy->dri_screen,
   dri2_surf->base.Width,
   dri2_surf->base.Height,
-  __DRI_IMAGE_FORMAT_ARGB,
+  dri_image_format,
   __DRI_IMAGE_USE_SHARE,
   NULL);
   dri2_surf->back->age = 0;
@@ -462,11 +482,26 @@ dri2_wl_get_buffers(__DRIdrawable * driDrawable,
 unsigned int *attachments, int count,
 int *out_count, void *loaderPrivate)
 {
+   struct dri2_egl_surface *dri2_surf = loaderPrivate;
unsigned int *attachments_with_format;
__DRIbuffer *buffer;
-   const unsigned int format = 32;
+   unsigned int bpp;
+
int i;
 
+   switch (dri2_surf->format) {
+   case WL_DRM_FORMAT_ARGB:
+   case WL_DRM_FORMAT_XRGB:
+  bpp = 32;
+  break;
+   case WL_DRM_FORMAT_RGB565:
+  bpp = 16;
+  break;
+   default:
+  /* format is not supported */
+  return NULL;
+   }
+
attachments_with_format = calloc(count, 2 * sizeof(unsigned int));
if (!attachments_with_format) {
   *out_count = 0;
@@ -475,7 +510,7 @@ dri2_wl_get_buffers(__DRIdrawable * driDrawable,
 
for (i = 0; i < count; ++i) {
   attachments_with_format[2*i] = attachments[i];
-  attachments_with_format[2*i + 1] = format;
+  attachments_with_format[2*i + 1] = bpp;
}
 
buffer =
-- 
1.7.9.5

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH] egl, wayland: RGB565 format support on Back-buffer

2015-02-03 Thread Dongwon Kim
In current code, color format is always hardcoded to __DRI_IMAGE_FORMAT_ARGB
when buffer or DRI image is allocated in function calls, get_back_bo and 
dri2_get_buffers,
regardless of current target's color format. This problem may leads to 
incorrect render
pitch calculation, which eventually ends up with wrong offset of pixels in the 
frame buffer
when the image is in different color format from dri surf's, especially with 
different bpp.
(e.g. 16bpp)

Attached code patch simply adds RGB565 case to two functions noted above to 
resolve
the issue.

Signed-off-by: Vivek Kasireddy 
Signed-off-by: Dongwon Kim 
---
 src/egl/drivers/dri2/platform_wayland.c |   10 --
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/src/egl/drivers/dri2/platform_wayland.c 
b/src/egl/drivers/dri2/platform_wayland.c
index 3c34e07..78761e2 100644
--- a/src/egl/drivers/dri2/platform_wayland.c
+++ b/src/egl/drivers/dri2/platform_wayland.c
@@ -293,6 +293,11 @@ get_back_bo(struct dri2_egl_surface *dri2_surf)
   dri2_egl_display(dri2_surf->base.Resource.Display);
int i;
 
+   /* currently supports two DRI image formats, __DRI_IMAGE_FORMAT_RGB565 or 
__DRI_IMAGE_FORMAT_ARGB,
+* one of which is selected depending on dri surface format */
+   const unsigned int dri_image_format =
+(dri2_surf->format == WL_DRM_FORMAT_RGB565) ? 
__DRI_IMAGE_FORMAT_RGB565 : __DRI_IMAGE_FORMAT_ARGB;
+
/* We always want to throttle to some event (either a frame callback or
 * a sync request) after the commit so that we can be sure the
 * compositor has had a chance to handle it and send us a release event
@@ -322,7 +327,7 @@ get_back_bo(struct dri2_egl_surface *dri2_surf)
  dri2_dpy->image->createImage(dri2_dpy->dri_screen,
   dri2_surf->base.Width,
   dri2_surf->base.Height,
-  __DRI_IMAGE_FORMAT_ARGB,
+  dri_image_format,
   __DRI_IMAGE_USE_SHARE,
   NULL);
   dri2_surf->back->age = 0;
@@ -462,9 +467,10 @@ dri2_wl_get_buffers(__DRIdrawable * driDrawable,
 unsigned int *attachments, int count,
 int *out_count, void *loaderPrivate)
 {
+   struct dri2_egl_surface *dri2_surf = loaderPrivate;
unsigned int *attachments_with_format;
__DRIbuffer *buffer;
-   const unsigned int format = 32;
+   const unsigned int format = (dri2_surf->format == WL_DRM_FORMAT_RGB565) ? 
16 : 32;
int i;
 
attachments_with_format = calloc(count, 2 * sizeof(unsigned int));
-- 
1.7.9.5

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev