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
This commit is contained in:
Adam Jackson 2020-06-17 18:42:53 -04:00
parent e216d9c6ad
commit d133f94f8f
9 changed files with 57 additions and 16 deletions

View File

@ -593,3 +593,9 @@ cogl_get_graphics_reset_status (CoglContext *context)
return COGL_GRAPHICS_RESET_STATUS_NO_ERROR; return COGL_GRAPHICS_RESET_STATUS_NO_ERROR;
} }
} }
gboolean
cogl_context_is_hardware_accelerated (CoglContext *context)
{
return context->driver_vtable->is_hardware_accelerated (context);
}

View File

@ -357,6 +357,16 @@ typedef enum _CoglGraphicsResetStatus
COGL_EXPORT CoglGraphicsResetStatus COGL_EXPORT CoglGraphicsResetStatus
cogl_get_graphics_reset_status (CoglContext *context); 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 G_END_DECLS
#endif /* __COGL_CONTEXT_H__ */ #endif /* __COGL_CONTEXT_H__ */

View File

@ -46,6 +46,9 @@ struct _CoglDriverVtable
void void
(* context_deinit) (CoglContext *context); (* context_deinit) (CoglContext *context);
gboolean
(* is_hardware_accelerated) (CoglContext *context);
/* TODO: factor this out since this is OpenGL specific and /* TODO: factor this out since this is OpenGL specific and
* so can be ignored by non-OpenGL drivers. */ * so can be ignored by non-OpenGL drivers. */
gboolean gboolean

View File

@ -91,6 +91,9 @@ _cogl_gl_util_clear_gl_errors (CoglContext *ctx);
gboolean gboolean
_cogl_gl_util_catch_out_of_memory (CoglContext *ctx, GError **error); _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 /* 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 * 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 * the "OpenGL ES" part on GLES). The version number can be followed

View File

@ -179,3 +179,28 @@ _cogl_gl_util_parse_gl_version (const char *version_string,
return TRUE; 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;
}

View File

@ -532,6 +532,7 @@ _cogl_driver_gl =
{ {
_cogl_driver_gl_real_context_init, _cogl_driver_gl_real_context_init,
_cogl_driver_gl_context_deinit, _cogl_driver_gl_context_deinit,
_cogl_driver_gl_is_hardware_accelerated,
_cogl_driver_pixel_format_from_gl_internal, _cogl_driver_pixel_format_from_gl_internal,
_cogl_driver_pixel_format_to_gl, _cogl_driver_pixel_format_to_gl,
_cogl_driver_update_features, _cogl_driver_update_features,

View File

@ -396,6 +396,7 @@ _cogl_driver_gles =
{ {
_cogl_driver_gl_context_init, _cogl_driver_gl_context_init,
_cogl_driver_gl_context_deinit, _cogl_driver_gl_context_deinit,
_cogl_driver_gl_is_hardware_accelerated,
_cogl_driver_pixel_format_from_gl_internal, _cogl_driver_pixel_format_from_gl_internal,
_cogl_driver_pixel_format_to_gl, _cogl_driver_pixel_format_to_gl,
_cogl_driver_update_features, _cogl_driver_update_features,

View File

@ -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 const CoglDriverVtable
_cogl_driver_nop = _cogl_driver_nop =
{ {
_cogl_driver_nop_context_init, _cogl_driver_nop_context_init,
_cogl_driver_nop_context_deinit, _cogl_driver_nop_context_deinit,
_cogl_driver_nop_is_hardware_accelerated,
NULL, /* pixel_format_from_gl_internal */ NULL, /* pixel_format_from_gl_internal */
NULL, /* pixel_format_to_gl */ NULL, /* pixel_format_to_gl */
_cogl_driver_update_features, _cogl_driver_update_features,

View File

@ -194,23 +194,8 @@ meta_renderer_is_hardware_accelerated (MetaRenderer *renderer)
ClutterBackend *clutter_backend = meta_backend_get_clutter_backend (backend); ClutterBackend *clutter_backend = meta_backend_get_clutter_backend (backend);
CoglContext *cogl_context = CoglContext *cogl_context =
clutter_backend_get_cogl_context (clutter_backend); clutter_backend_get_cogl_context (clutter_backend);
CoglGpuInfo *info = &cogl_context->gpu;
switch (info->architecture) return cogl_context_is_hardware_accelerated (cogl_context);
{
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;
} }
static void static void