From c890c384c82111d49dacfcc886b89adf9819844f Mon Sep 17 00:00:00 2001 From: Daniel Stone Date: Fri, 6 Mar 2020 13:04:18 +0000 Subject: [PATCH] gl-renderer: Replace display-create args with struct gl_rendererer's output_create has a lot of arguments now. Add a structure for the options to make it more clear what is what. This is in preparation for adding bare-integer arguments which are ripe for confusion when passing positional arguments. Signed-off-by: Daniel Stone --- libweston/backend-drm/drm-gbm.c | 19 ++++++++-------- libweston/backend-headless/headless.c | 19 ++++++++-------- libweston/backend-wayland/wayland.c | 14 +++++++----- libweston/backend-x11/x11.c | 16 +++++++------- libweston/renderer-gl/gl-renderer.c | 21 +++++++++--------- libweston/renderer-gl/gl-renderer.h | 32 +++++++++++++++++---------- 6 files changed, 65 insertions(+), 56 deletions(-) diff --git a/libweston/backend-drm/drm-gbm.c b/libweston/backend-drm/drm-gbm.c index 324c2a83..e06372f1 100644 --- a/libweston/backend-drm/drm-gbm.c +++ b/libweston/backend-drm/drm-gbm.c @@ -98,18 +98,19 @@ drm_backend_create_gl_renderer(struct drm_backend *b) fallback_format_for(b->gbm_format), 0, }; - unsigned n_formats = 2; + struct gl_renderer_display_options options = { + .egl_platform = EGL_PLATFORM_GBM_KHR, + .egl_native_display = b->gbm, + .egl_surface_type = EGL_WINDOW_BIT, + .drm_formats = format, + .drm_formats_count = 2, + }; if (format[1]) - n_formats = 3; - if (gl_renderer->display_create(b->compositor, - EGL_PLATFORM_GBM_KHR, - (void *)b->gbm, - EGL_WINDOW_BIT, - format, - n_formats) < 0) { + options.drm_formats_count = 3; + + if (gl_renderer->display_create(b->compositor, &options) < 0) return -1; - } return 0; } diff --git a/libweston/backend-headless/headless.c b/libweston/backend-headless/headless.c index e9d0ad8f..39cd1fd2 100644 --- a/libweston/backend-headless/headless.c +++ b/libweston/backend-headless/headless.c @@ -387,20 +387,19 @@ headless_destroy(struct weston_compositor *ec) static int headless_gl_renderer_init(struct headless_backend *b) { + const struct gl_renderer_display_options options = { + .egl_platform = EGL_PLATFORM_SURFACELESS_MESA, + .egl_native_display = EGL_DEFAULT_DISPLAY, + .egl_surface_type = EGL_PBUFFER_BIT, + .drm_formats = headless_formats, + .drm_formats_count = ARRAY_LENGTH(headless_formats), + }; + b->glri = weston_load_module("gl-renderer.so", "gl_renderer_interface"); if (!b->glri) return -1; - if (b->glri->display_create(b->compositor, - EGL_PLATFORM_SURFACELESS_MESA, - EGL_DEFAULT_DISPLAY, - EGL_PBUFFER_BIT, - headless_formats, - ARRAY_LENGTH(headless_formats)) < 0) { - return -1; - } - - return 0; + return b->glri->display_create(b->compositor, &options); } static const struct weston_windowed_output_api api = { diff --git a/libweston/backend-wayland/wayland.c b/libweston/backend-wayland/wayland.c index 83145c93..d638fe95 100644 --- a/libweston/backend-wayland/wayland.c +++ b/libweston/backend-wayland/wayland.c @@ -2773,12 +2773,14 @@ wayland_backend_create(struct weston_compositor *compositor, } if (!b->use_pixman) { - if (gl_renderer->display_create(compositor, - EGL_PLATFORM_WAYLAND_KHR, - b->parent.wl_display, - EGL_WINDOW_BIT, - wayland_formats, - ARRAY_LENGTH(wayland_formats)) < 0) { + const struct gl_renderer_display_options options = { + .egl_platform = EGL_PLATFORM_WAYLAND_KHR, + .egl_native_display = b->parent.wl_display, + .egl_surface_type = EGL_WINDOW_BIT, + .drm_formats = wayland_formats, + .drm_formats_count = ARRAY_LENGTH(wayland_formats), + }; + if (gl_renderer->display_create(compositor, &options) < 0) { weston_log("Failed to initialize the GL renderer; " "falling back to pixman.\n"); b->use_pixman = true; diff --git a/libweston/backend-x11/x11.c b/libweston/backend-x11/x11.c index 6d558edb..23d501f0 100644 --- a/libweston/backend-x11/x11.c +++ b/libweston/backend-x11/x11.c @@ -1794,20 +1794,20 @@ x11_destroy(struct weston_compositor *ec) static int init_gl_renderer(struct x11_backend *b) { - int ret; + const struct gl_renderer_display_options options = { + .egl_platform = EGL_PLATFORM_X11_KHR, + .egl_native_display = b->dpy, + .egl_surface_type = EGL_WINDOW_BIT, + .drm_formats = x11_formats, + .drm_formats_count = ARRAY_LENGTH(x11_formats), + }; gl_renderer = weston_load_module("gl-renderer.so", "gl_renderer_interface"); if (!gl_renderer) return -1; - ret = gl_renderer->display_create(b->compositor, EGL_PLATFORM_X11_KHR, - (void *) b->dpy, - EGL_WINDOW_BIT, - x11_formats, - ARRAY_LENGTH(x11_formats)); - - return ret; + return gl_renderer->display_create(b->compositor, &options); } static const struct weston_windowed_output_api api = { diff --git a/libweston/renderer-gl/gl-renderer.c b/libweston/renderer-gl/gl-renderer.c index 462f422c..3a000e51 100644 --- a/libweston/renderer-gl/gl-renderer.c +++ b/libweston/renderer-gl/gl-renderer.c @@ -3374,11 +3374,7 @@ gl_renderer_create_pbuffer_surface(struct gl_renderer *gr) { static int gl_renderer_display_create(struct weston_compositor *ec, - EGLenum platform, - void *native_display, - EGLint egl_surface_type, - const uint32_t *drm_formats, - unsigned drm_formats_count) + const struct gl_renderer_display_options *options) { struct gl_renderer *gr; @@ -3386,7 +3382,7 @@ gl_renderer_display_create(struct weston_compositor *ec, if (gr == NULL) return -1; - gr->platform = platform; + gr->platform = options->egl_platform; if (gl_renderer_setup_egl_client_extensions(gr) < 0) goto fail; @@ -3401,7 +3397,7 @@ gl_renderer_display_create(struct weston_compositor *ec, gl_renderer_surface_get_content_size; gr->base.surface_copy_content = gl_renderer_surface_copy_content; - if (gl_renderer_setup_egl_display(gr, native_display) < 0) + if (gl_renderer_setup_egl_display(gr, options->egl_native_display) < 0) goto fail; log_egl_info(gr->egl_display); @@ -3412,13 +3408,16 @@ gl_renderer_display_create(struct weston_compositor *ec, goto fail_with_error; if (!gr->has_configless_context) { + EGLint egl_surface_type = options->egl_surface_type; + if (!gr->has_surfaceless_context) egl_surface_type |= EGL_PBUFFER_BIT; - gr->egl_config = gl_renderer_get_egl_config(gr, - egl_surface_type, - drm_formats, - drm_formats_count); + gr->egl_config = + gl_renderer_get_egl_config(gr, + egl_surface_type, + options->drm_formats, + options->drm_formats_count); if (gr->egl_config == EGL_NO_CONFIG_KHR) { weston_log("failed to choose EGL config\n"); goto fail_terminate; diff --git a/libweston/renderer-gl/gl-renderer.h b/libweston/renderer-gl/gl-renderer.h index 2bca2d00..e1d35d41 100644 --- a/libweston/renderer-gl/gl-renderer.h +++ b/libweston/renderer-gl/gl-renderer.h @@ -58,18 +58,30 @@ enum gl_renderer_border_side { GL_RENDERER_BORDER_BOTTOM = 3, }; +/** + * Options passed to the \c display_create method of the GL renderer interface. + * + * \see struct gl_renderer_interface + */ +struct gl_renderer_display_options { + /** The EGL platform identifier */ + EGLenum egl_platform; + /** The native display corresponding to the given EGL platform */ + void *egl_native_display; + /** EGL_SURFACE_TYPE bits for the base EGLConfig */ + EGLint egl_surface_type; + /** Array of DRM pixel formats acceptable for the base EGLConfig */ + const uint32_t *drm_formats; + /** The \c drm_formats array length */ + unsigned drm_formats_count; +}; + struct gl_renderer_interface { /** * Initialize GL-renderer with the given EGL platform and native display * * \param ec The weston_compositor where to initialize. - * \param platform The EGL platform identifier. - * \param native_display The native display corresponding to the given - * EGL platform. - * \param egl_surface_type EGL_SURFACE_TYPE bits for the base EGLConfig. - * \param drm_formats Array of DRM pixel formats that are acceptable - * for the base EGLConfig. - * \param drm_formats_count The drm_formats array length. + * \param options The options struct describing display configuration * \return 0 on success, -1 on failure. * * This function creates an EGLDisplay and initializes it. It also @@ -96,11 +108,7 @@ struct gl_renderer_interface { * DRM format. */ int (*display_create)(struct weston_compositor *ec, - EGLenum platform, - void *native_display, - EGLint egl_surface_type, - const uint32_t *drm_formats, - unsigned drm_formats_count); + const struct gl_renderer_display_options *options); /** * Attach GL-renderer to the output with a native window