[mutter/wip/rstrode/rhel-8.0.0: 30/30] wip! cogl: provide way to specify framebuffer format



commit 292642361d5ced53f35c0ea82eaa030c3d118971
Author: Ray Strode <rstrode redhat com>
Date:   Thu Jan 17 09:07:14 2019 -0500

    wip! cogl: provide way to specify framebuffer format
    
    At the moment the onscreen framebuffer pixel format is
    recorded as having the hardcoded value:
    
    COGL_PIXEL_FORMAT_RGBA_8888_PRE
    
    but there's nothing to actually enforce that format is getting
    used.  In fact, mutter is using a gbm surface with format
    GBM_FORMAT_ARGB8888 which translates to COGL_PIXEL_FORMAT_BGRA_8888_PRE.
    
    This commit modifies the onscreen_init vfunc to allow the
    implementation to pass back the format actually being used,
    and changes mutter to do that.
    
    This fixes readpixels color inversion.

 cogl/cogl/cogl-framebuffer.c               |  2 +-
 cogl/cogl/winsys/cogl-winsys-egl.c         |  5 +++--
 cogl/cogl/winsys/cogl-winsys-glx.c         |  5 +++--
 cogl/cogl/winsys/cogl-winsys-private.h     |  2 +-
 cogl/cogl/winsys/cogl-winsys-stub.c        |  5 +++--
 src/backends/native/meta-renderer-native.c | 19 ++++++++++++++++---
 6 files changed, 27 insertions(+), 11 deletions(-)
---
diff --git a/cogl/cogl/cogl-framebuffer.c b/cogl/cogl/cogl-framebuffer.c
index 55b9e3756..656797aaa 100644
--- a/cogl/cogl/cogl-framebuffer.c
+++ b/cogl/cogl/cogl-framebuffer.c
@@ -753,7 +753,7 @@ cogl_framebuffer_allocate (CoglFramebuffer *framebuffer,
           return FALSE;
         }
 
-      if (!winsys->onscreen_init (onscreen, error))
+      if (!winsys->onscreen_init (onscreen, &framebuffer->internal_format, error))
         return FALSE;
 
       /* If the winsys doesn't support dirty events then we'll report
diff --git a/cogl/cogl/winsys/cogl-winsys-egl.c b/cogl/cogl/winsys/cogl-winsys-egl.c
index 66c2661b3..6e4e59e4c 100644
--- a/cogl/cogl/winsys/cogl-winsys-egl.c
+++ b/cogl/cogl/winsys/cogl-winsys-egl.c
@@ -621,8 +621,9 @@ _cogl_winsys_destroy_gles2_context (CoglGLES2Context *gles2_ctx)
 }
 
 static CoglBool
-_cogl_winsys_onscreen_init (CoglOnscreen *onscreen,
-                            CoglError **error)
+_cogl_winsys_onscreen_init (CoglOnscreen     *onscreen,
+                            CoglPixelFormat  *format,
+                            CoglError       **error)
 {
   CoglFramebuffer *framebuffer = COGL_FRAMEBUFFER (onscreen);
   CoglContext *context = framebuffer->context;
diff --git a/cogl/cogl/winsys/cogl-winsys-glx.c b/cogl/cogl/winsys/cogl-winsys-glx.c
index 4a033c0c6..9b0c69edd 100644
--- a/cogl/cogl/winsys/cogl-winsys-glx.c
+++ b/cogl/cogl/winsys/cogl-winsys-glx.c
@@ -1354,8 +1354,9 @@ _cogl_winsys_context_deinit (CoglContext *context)
 }
 
 static CoglBool
-_cogl_winsys_onscreen_init (CoglOnscreen *onscreen,
-                            CoglError **error)
+_cogl_winsys_onscreen_init (CoglOnscreen     *onscreen,
+                            CoglPixelFormat  *format,
+                            CoglError       **error)
 {
   CoglFramebuffer *framebuffer = COGL_FRAMEBUFFER (onscreen);
   CoglContext *context = framebuffer->context;
diff --git a/cogl/cogl/winsys/cogl-winsys-private.h b/cogl/cogl/winsys/cogl-winsys-private.h
index a8e07a509..fecca07d9 100644
--- a/cogl/cogl/winsys/cogl-winsys-private.h
+++ b/cogl/cogl/winsys/cogl-winsys-private.h
@@ -109,7 +109,7 @@ typedef struct _CoglWinsysVtable
   (*context_create_gles2_context) (CoglContext *ctx, CoglError **error);
 
   CoglBool
-  (*onscreen_init) (CoglOnscreen *onscreen, CoglError **error);
+  (*onscreen_init) (CoglOnscreen *onscreen, CoglPixelFormat *format, CoglError **error);
 
   void
   (*onscreen_deinit) (CoglOnscreen *onscreen);
diff --git a/cogl/cogl/winsys/cogl-winsys-stub.c b/cogl/cogl/winsys/cogl-winsys-stub.c
index ba49a9419..3bb5c208f 100644
--- a/cogl/cogl/winsys/cogl-winsys-stub.c
+++ b/cogl/cogl/winsys/cogl-winsys-stub.c
@@ -122,8 +122,9 @@ _cogl_winsys_context_deinit (CoglContext *context)
 }
 
 static CoglBool
-_cogl_winsys_onscreen_init (CoglOnscreen *onscreen,
-                            CoglError **error)
+_cogl_winsys_onscreen_init (CoglOnscreen     *onscreen,
+                            CoglPixelFormat  *format,
+                            CoglError       **error)
 {
   return TRUE;
 }
diff --git a/src/backends/native/meta-renderer-native.c b/src/backends/native/meta-renderer-native.c
index 82b4f62e9..c52a01810 100644
--- a/src/backends/native/meta-renderer-native.c
+++ b/src/backends/native/meta-renderer-native.c
@@ -73,6 +73,9 @@
 #define DRM_FORMAT_INVALID 0
 #endif
 
+/* DRM and GBM formats are identical, but add the macro for legibility */
+#define DRM_FORMAT_FROM_GBM_FORMAT(format) (format)
+
 enum
 {
   PROP_0,
@@ -2589,8 +2592,9 @@ release_dumb_fb (MetaDumbBuffer *dumb_fb,
 }
 
 static gboolean
-meta_renderer_native_init_onscreen (CoglOnscreen *onscreen,
-                                    GError      **error)
+meta_renderer_native_init_onscreen (CoglOnscreen     *onscreen,
+                                    CoglPixelFormat  *cogl_pixel_format,
+                                    GError          **error)
 {
   CoglFramebuffer *framebuffer = COGL_FRAMEBUFFER (onscreen);
   CoglContext *cogl_context = framebuffer->context;
@@ -2598,6 +2602,8 @@ meta_renderer_native_init_onscreen (CoglOnscreen *onscreen,
   CoglDisplayEGL *cogl_display_egl = cogl_display->winsys;
   CoglOnscreenEGL *onscreen_egl;
   MetaOnscreenNative *onscreen_native;
+  uint32_t drm_format;
+  int ret;
 
   _COGL_RETURN_VAL_IF_FAIL (cogl_display_egl->egl_context, FALSE);
 
@@ -2607,6 +2613,14 @@ meta_renderer_native_init_onscreen (CoglOnscreen *onscreen,
   onscreen_native = g_slice_new0 (MetaOnscreenNative);
   onscreen_egl->platform = onscreen_native;
 
+  drm_format = DRM_FORMAT_FROM_GBM_FORMAT (GBM_FORMAT_ARGB8888);
+
+  ret = cogl_pixel_format_from_drm_format (drm_format,
+                                           cogl_pixel_format,
+                                           NULL);
+
+  g_assert (ret);
+
   /*
    * Don't actually initialize anything here, since we may not have the
    * information available yet, and there is no way to pass it at this stage.
@@ -2616,7 +2630,6 @@ meta_renderer_native_init_onscreen (CoglOnscreen *onscreen,
    * TODO: Turn CoglFramebuffer/CoglOnscreen into GObjects, so it's possible
    * to add backend specific properties.
    */
-
   return TRUE;
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]