gl-renderer: Replace display-create args with struct
authorDaniel Stone <daniels@collabora.com>
Fri, 6 Mar 2020 13:04:18 +0000 (13:04 +0000)
committerPekka Paalanen <pq@iki.fi>
Fri, 20 Mar 2020 15:25:24 +0000 (15:25 +0000)
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 <daniels@collabora.com>
libweston/backend-drm/drm-gbm.c
libweston/backend-headless/headless.c
libweston/backend-wayland/wayland.c
libweston/backend-x11/x11.c
libweston/renderer-gl/gl-renderer.c
libweston/renderer-gl/gl-renderer.h

index 324c2a83fee06b4ff04319d1b08866a78276228d..e06372f107c7f524ab3073127230fb609332efdc 100644 (file)
@@ -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;
 }
index e9d0ad8f01d5aa6f376dd31c6876425673e4c86f..39cd1fd298e2a39f2b4f456b8bdc4c816652b259 100644 (file)
@@ -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 = {
index 83145c936ee366ab87caf7ae18d6f2d3714e24e1..d638fe953c841f60658b2ffbba8f29af323b23a7 100644 (file)
@@ -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;
index 6d558edb8eb76e84fddbf3541a879c56954d9ea0..23d501f024e206a9abba13787d775770a75dc424 100644 (file)
@@ -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 = {
index 462f422c6083025d2d2960417cb75d06abc22bbf..3a000e51da3dd445a073afdac5194f04f0ccfbcc 100644 (file)
@@ -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;
index 2bca2d00c5320b2293d55a15fd4b53e4f41e6304..e1d35d415a7d98224463886caf6848f188167044 100644 (file)
@@ -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