[mutter] cogl: Introduce and use cogl_context_is_hardware_accelerated



commit d133f94f8f711cef436e6f4cf5bd4d0bbbe81f22
Author: Adam Jackson <ajax redhat com>
Date:   Wed Jun 17 18:42:53 2020 -0400

    cogl: Introduce and use cogl_context_is_hardware_accelerated
    
    We delegate the answer through CoglDriverVtable::is_hardware_accelerated
    since this is properly a property of the renderer, and not something the
    cogl core should know about. The answer given for the nop driver is
    admittedly arbitrary, yes it's infinitely fast but no there's not any
    "hardware" making it so.
    
    https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1194

 cogl/cogl/cogl-context.c                    |  6 ++++++
 cogl/cogl/cogl-context.h                    | 10 ++++++++++
 cogl/cogl/cogl-driver.h                     |  3 +++
 cogl/cogl/driver/gl/cogl-util-gl-private.h  |  3 +++
 cogl/cogl/driver/gl/cogl-util-gl.c          | 25 +++++++++++++++++++++++++
 cogl/cogl/driver/gl/gl/cogl-driver-gl.c     |  1 +
 cogl/cogl/driver/gl/gles/cogl-driver-gles.c |  1 +
 cogl/cogl/driver/nop/cogl-driver-nop.c      |  7 +++++++
 src/backends/meta-renderer.c                | 17 +----------------
 9 files changed, 57 insertions(+), 16 deletions(-)
---
diff --git a/cogl/cogl/cogl-context.c b/cogl/cogl/cogl-context.c
index 50b4b68aed..bc92ec38e8 100644
--- a/cogl/cogl/cogl-context.c
+++ b/cogl/cogl/cogl-context.c
@@ -593,3 +593,9 @@ cogl_get_graphics_reset_status (CoglContext *context)
       return COGL_GRAPHICS_RESET_STATUS_NO_ERROR;
     }
 }
+
+gboolean
+cogl_context_is_hardware_accelerated (CoglContext *context)
+{
+  return context->driver_vtable->is_hardware_accelerated (context);
+}
diff --git a/cogl/cogl/cogl-context.h b/cogl/cogl/cogl-context.h
index 2807f2a5ac..e0d79d9278 100644
--- a/cogl/cogl/cogl-context.h
+++ b/cogl/cogl/cogl-context.h
@@ -357,6 +357,16 @@ typedef enum _CoglGraphicsResetStatus
 COGL_EXPORT CoglGraphicsResetStatus
 cogl_get_graphics_reset_status (CoglContext *context);
 
+/**
+ * cogl_context_is_hardware_accelerated:
+ * @context: a #CoglContext pointer
+ *
+ * Returns: %TRUE if the @context is hardware accelerated, or %FALSE if
+ * not.
+ */
+COGL_EXPORT gboolean
+cogl_context_is_hardware_accelerated (CoglContext *context);
+
 G_END_DECLS
 
 #endif /* __COGL_CONTEXT_H__ */
diff --git a/cogl/cogl/cogl-driver.h b/cogl/cogl/cogl-driver.h
index 5dcecf8629..e52a99cfb8 100644
--- a/cogl/cogl/cogl-driver.h
+++ b/cogl/cogl/cogl-driver.h
@@ -46,6 +46,9 @@ struct _CoglDriverVtable
   void
   (* context_deinit) (CoglContext *context);
 
+  gboolean
+  (* is_hardware_accelerated) (CoglContext *context);
+
   /* TODO: factor this out since this is OpenGL specific and
    * so can be ignored by non-OpenGL drivers. */
   gboolean
diff --git a/cogl/cogl/driver/gl/cogl-util-gl-private.h b/cogl/cogl/driver/gl/cogl-util-gl-private.h
index 52279be678..c434ebde01 100644
--- a/cogl/cogl/driver/gl/cogl-util-gl-private.h
+++ b/cogl/cogl/driver/gl/cogl-util-gl-private.h
@@ -91,6 +91,9 @@ _cogl_gl_util_clear_gl_errors (CoglContext *ctx);
 gboolean
 _cogl_gl_util_catch_out_of_memory (CoglContext *ctx, GError **error);
 
+gboolean
+_cogl_driver_gl_is_hardware_accelerated (CoglContext *context);
+
 /* Parses a GL version number stored in a string. @version_string must
  * point to the beginning of the version number (ie, it can't point to
  * the "OpenGL ES" part on GLES). The version number can be followed
diff --git a/cogl/cogl/driver/gl/cogl-util-gl.c b/cogl/cogl/driver/gl/cogl-util-gl.c
index 34488c7d8f..d21ee01248 100644
--- a/cogl/cogl/driver/gl/cogl-util-gl.c
+++ b/cogl/cogl/driver/gl/cogl-util-gl.c
@@ -179,3 +179,28 @@ _cogl_gl_util_parse_gl_version (const char *version_string,
 
   return TRUE;
 }
+
+/*
+ * This should arguably use something like GLX_MESA_query_renderer, but
+ * a) that's GLX-only, and you could add it to EGL too but
+ * b) that'd make this a winsys query when really it's not a property of
+ *    the winsys but the renderer, and
+ * c) only Mesa really supports it anyway, and
+ * d) Mesa is the only software renderer of interest.
+ *
+ * So instead just check a list of known software renderer strings.
+ */
+gboolean
+_cogl_driver_gl_is_hardware_accelerated (CoglContext *ctx)
+{
+  const char *renderer = (const char *) ctx->glGetString (GL_RENDERER);
+  gboolean software;
+
+  software = strstr (renderer, "llvmpipe") != NULL ||
+             strstr (renderer, "softpipe") != NULL ||
+             strstr (renderer, "software rasterizer") != NULL ||
+             strstr (renderer, "Software Rasterizer") != NULL ||
+             strstr (renderer, "SWR");
+
+  return !software;
+}
diff --git a/cogl/cogl/driver/gl/gl/cogl-driver-gl.c b/cogl/cogl/driver/gl/gl/cogl-driver-gl.c
index 220c581e99..29492b04c7 100644
--- a/cogl/cogl/driver/gl/gl/cogl-driver-gl.c
+++ b/cogl/cogl/driver/gl/gl/cogl-driver-gl.c
@@ -532,6 +532,7 @@ _cogl_driver_gl =
   {
     _cogl_driver_gl_real_context_init,
     _cogl_driver_gl_context_deinit,
+    _cogl_driver_gl_is_hardware_accelerated,
     _cogl_driver_pixel_format_from_gl_internal,
     _cogl_driver_pixel_format_to_gl,
     _cogl_driver_update_features,
diff --git a/cogl/cogl/driver/gl/gles/cogl-driver-gles.c b/cogl/cogl/driver/gl/gles/cogl-driver-gles.c
index daaaec44f0..04e35c56ad 100644
--- a/cogl/cogl/driver/gl/gles/cogl-driver-gles.c
+++ b/cogl/cogl/driver/gl/gles/cogl-driver-gles.c
@@ -396,6 +396,7 @@ _cogl_driver_gles =
   {
     _cogl_driver_gl_context_init,
     _cogl_driver_gl_context_deinit,
+    _cogl_driver_gl_is_hardware_accelerated,
     _cogl_driver_pixel_format_from_gl_internal,
     _cogl_driver_pixel_format_to_gl,
     _cogl_driver_update_features,
diff --git a/cogl/cogl/driver/nop/cogl-driver-nop.c b/cogl/cogl/driver/nop/cogl-driver-nop.c
index 3594a966b2..664c653dbc 100644
--- a/cogl/cogl/driver/nop/cogl-driver-nop.c
+++ b/cogl/cogl/driver/nop/cogl-driver-nop.c
@@ -63,11 +63,18 @@ _cogl_driver_nop_context_deinit (CoglContext *context)
 {
 }
 
+static gboolean
+_cogl_driver_nop_is_hardware_accelerated (CoglContext *context)
+{
+  return FALSE;
+}
+
 const CoglDriverVtable
 _cogl_driver_nop =
   {
     _cogl_driver_nop_context_init,
     _cogl_driver_nop_context_deinit,
+    _cogl_driver_nop_is_hardware_accelerated,
     NULL, /* pixel_format_from_gl_internal */
     NULL, /* pixel_format_to_gl */
     _cogl_driver_update_features,
diff --git a/src/backends/meta-renderer.c b/src/backends/meta-renderer.c
index 983a570e1c..b5cc37efbf 100644
--- a/src/backends/meta-renderer.c
+++ b/src/backends/meta-renderer.c
@@ -194,23 +194,8 @@ meta_renderer_is_hardware_accelerated (MetaRenderer *renderer)
   ClutterBackend *clutter_backend = meta_backend_get_clutter_backend (backend);
   CoglContext *cogl_context =
     clutter_backend_get_cogl_context (clutter_backend);
-  CoglGpuInfo *info = &cogl_context->gpu;
 
-  switch (info->architecture)
-    {
-    case COGL_GPU_INFO_ARCHITECTURE_UNKNOWN:
-    case COGL_GPU_INFO_ARCHITECTURE_SANDYBRIDGE:
-    case COGL_GPU_INFO_ARCHITECTURE_SGX:
-    case COGL_GPU_INFO_ARCHITECTURE_MALI:
-      return TRUE;
-    case COGL_GPU_INFO_ARCHITECTURE_LLVMPIPE:
-    case COGL_GPU_INFO_ARCHITECTURE_SOFTPIPE:
-    case COGL_GPU_INFO_ARCHITECTURE_SWRAST:
-      return FALSE;
-    }
-
-  g_assert_not_reached ();
-  return FALSE;
+  return cogl_context_is_hardware_accelerated (cogl_context);
 }
 
 static void


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