onscreen/native: Add and use choose_onscreen_egl_config helper

If the EGL_KHR_no_config_context extension is supported, use it to
choose a format per onscreen which is compatible with the scanout CRTC
and the GL rendering API used.

Suggested by Jonas Ådahl.

v2:
* Drop code which checked for GLES3 renderability. Makes no sense for
  various reasons, in particular that EGLconfigs are about EGLSurfaces,
  whereas secondary GPU contexts use an FBO for blitting.
* Use error parameter directly for meta_renderer_native_choose_gbm_format
  call (Jonas Ådahl)

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3139>
This commit is contained in:
Michel Dänzer 2023-10-31 18:47:31 +01:00 committed by Marge Bot
parent 4c42eab358
commit e1f795ff79
5 changed files with 63 additions and 7 deletions

View File

@ -32,7 +32,7 @@
#include "cogl/cogl-display.h"
#include "cogl/cogl-renderer.h"
#include "cogl/cogl-onscreen-template.h"
#include "cogl/cogl-onscreen-template-private.h"
struct _CoglDisplay
{

View File

@ -194,7 +194,7 @@ COGL_EXPORT gboolean
_cogl_winsys_egl_renderer_connect_common (CoglRenderer *renderer,
GError **error);
void
COGL_EXPORT void
cogl_display_egl_determine_attributes (CoglDisplay *display,
const CoglFramebufferConfig *config,
EGLint *attributes);

View File

@ -47,6 +47,7 @@
#include "backends/native/meta-render-device.h"
#include "backends/native/meta-renderer-native-gles3.h"
#include "backends/native/meta-renderer-native-private.h"
#include "cogl/cogl.h"
#include "common/meta-cogl-drm-formats.h"
typedef enum _MetaSharedFramebufferImportStatus
@ -1743,6 +1744,45 @@ get_supported_kms_formats (CoglOnscreen *onscreen)
return meta_crtc_kms_copy_drm_format_list (crtc_kms);
}
static gboolean
choose_onscreen_egl_config (CoglOnscreen *onscreen,
EGLConfig *out_config,
GError **error)
{
MetaOnscreenNative *onscreen_native = META_ONSCREEN_NATIVE (onscreen);
CoglFramebuffer *framebuffer = COGL_FRAMEBUFFER (onscreen);
CoglContext *cogl_context = cogl_framebuffer_get_context (framebuffer);
CoglDisplay *cogl_display = cogl_context->display;
CoglRenderer *cogl_renderer = cogl_display->renderer;
CoglRendererEGL *cogl_renderer_egl = cogl_renderer->winsys;
EGLDisplay egl_display = cogl_renderer_egl->edpy;
MetaEgl *egl = meta_onscreen_native_get_egl (onscreen_native);
MetaCrtcKms *crtc_kms = META_CRTC_KMS (onscreen_native->crtc);
EGLint attrs[MAX_EGL_CONFIG_ATTRIBS];
g_autoptr (GError) local_error = NULL;
static const uint32_t formats[] = {
GBM_FORMAT_XRGB8888,
GBM_FORMAT_ARGB8888,
};
cogl_display_egl_determine_attributes (cogl_display,
&cogl_display->onscreen_template->config,
attrs);
if (meta_renderer_native_choose_gbm_format (crtc_kms,
egl,
egl_display,
attrs,
formats,
G_N_ELEMENTS (formats),
"surface",
out_config,
error))
return TRUE;
return FALSE;
}
static gboolean
create_surfaces_gbm (CoglOnscreen *onscreen,
int width,
@ -1766,6 +1806,7 @@ create_surfaces_gbm (CoglOnscreen *onscreen,
struct gbm_surface *new_gbm_surface = NULL;
EGLNativeWindowType egl_native_window;
EGLSurface new_egl_surface;
EGLConfig egl_config;
uint32_t format;
GArray *modifiers;
@ -1775,9 +1816,14 @@ create_surfaces_gbm (CoglOnscreen *onscreen,
render_device_gbm = META_RENDER_DEVICE_GBM (renderer_gpu_data->render_device);
gbm_device = meta_render_device_gbm_get_gbm_device (render_device_gbm);
if (!(cogl_renderer_egl->private_features &
COGL_EGL_WINSYS_FEATURE_NO_CONFIG_CONTEXT) ||
!choose_onscreen_egl_config (onscreen, &egl_config, error))
egl_config = cogl_display_egl->egl_config;
format = get_gbm_format_from_egl (egl,
cogl_renderer_egl->edpy,
cogl_display_egl->egl_config);
egl_config);
if (meta_renderer_native_use_modifiers (renderer_native))
modifiers = get_supported_modifiers (onscreen, format);
@ -1819,7 +1865,7 @@ create_surfaces_gbm (CoglOnscreen *onscreen,
new_egl_surface =
meta_egl_create_window_surface (egl,
cogl_renderer_egl->edpy,
cogl_display_egl->egl_config,
egl_config,
egl_native_window,
NULL,
error);

View File

@ -412,7 +412,8 @@ choose_egl_config_from_gbm_format (MetaEgl *egl,
}
gboolean
meta_renderer_native_choose_gbm_format (MetaEgl *egl,
meta_renderer_native_choose_gbm_format (MetaCrtcKms *crtc_kms,
MetaEgl *egl,
EGLDisplay egl_display,
EGLint *attributes,
const uint32_t *formats,
@ -427,6 +428,13 @@ meta_renderer_native_choose_gbm_format (MetaEgl *egl,
{
g_clear_error (error);
if (crtc_kms && !meta_crtc_kms_supports_format (crtc_kms, formats[i]))
{
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
"KMS CRTC doesn't support format");
continue;
}
if (choose_egl_config_from_gbm_format (egl,
egl_display,
attributes,
@ -471,7 +479,8 @@ meta_renderer_native_choose_egl_config (CoglDisplay *cogl_display,
GBM_FORMAT_ARGB8888,
};
return meta_renderer_native_choose_gbm_format (egl,
return meta_renderer_native_choose_gbm_format (NULL,
egl,
egl_display,
attributes,
formats,

View File

@ -76,7 +76,8 @@ gboolean meta_renderer_native_has_addfb2 (MetaRendererNative *renderer_native);
MetaRendererNativeMode meta_renderer_native_get_mode (MetaRendererNative *renderer_native);
gboolean meta_renderer_native_choose_gbm_format (MetaEgl *egl,
gboolean meta_renderer_native_choose_gbm_format (MetaCrtcKms *crtc_kms,
MetaEgl *egl,
EGLDisplay egl_display,
EGLint *attributes,
const uint32_t *formats,