clients/simple-dmabuf-egl: Make use of direct-display
authorMarius Vlad <marius.vlad@collabora.com>
Sat, 16 Nov 2019 18:40:13 +0000 (20:40 +0200)
committerMarius Vlad <marius.vlad@collabora.com>
Thu, 21 Nov 2019 12:28:53 +0000 (14:28 +0200)
Uses weston-direct-display extension.

Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
clients/meson.build
clients/simple-dmabuf-egl.c

index f83b8806a981fa62098e2e31634002fba075d94f..56b6ef55e6709aedb7f744259f2bb7732708ad53 100644 (file)
@@ -58,6 +58,8 @@ simple_clients = [
                        linux_explicit_synchronization_unstable_v1_protocol_c,
                        xdg_shell_client_protocol_h,
                        xdg_shell_protocol_c,
+                       weston_direct_display_client_protocol_h,
+                       weston_direct_display_protocol_c,
                        fullscreen_shell_unstable_v1_client_protocol_h,
                        fullscreen_shell_unstable_v1_protocol_c,
                ],
index 54590e3c95b1908fc3a15b67d7994504ea9cb4ea..9e83d338c0ecde80e7f0de5c072b93a4d8455471 100644 (file)
@@ -50,6 +50,7 @@
 #include "xdg-shell-client-protocol.h"
 #include "fullscreen-shell-unstable-v1-client-protocol.h"
 #include "linux-dmabuf-unstable-v1-client-protocol.h"
+#include "weston-direct-display-client-protocol.h"
 #include "linux-explicit-synchronization-unstable-v1-client-protocol.h"
 
 #include <EGL/egl.h>
@@ -67,6 +68,7 @@
 #define OPT_IMMEDIATE     (1 << 0)  /* create wl_buffer immediately */
 #define OPT_IMPLICIT_SYNC (1 << 1)  /* force implicit sync */
 #define OPT_MANDELBROT    (1 << 2)  /* render mandelbrot */
+#define OPT_DIRECT_DISPLAY     (1 << 3)  /* direct-display */
 
 #define BUFFER_FORMAT DRM_FORMAT_XRGB8888
 #define MAX_BUFFER_PLANES 4
@@ -78,6 +80,7 @@ struct display {
        struct xdg_wm_base *wm_base;
        struct zwp_fullscreen_shell_v1 *fshell;
        struct zwp_linux_dmabuf_v1 *dmabuf;
+       struct weston_direct_display_v1 *direct_display;
        struct zwp_linux_explicit_synchronization_v1 *explicit_sync;
        uint64_t *modifiers;
        int modifiers_count;
@@ -325,11 +328,11 @@ create_fbo_for_buffer(struct display *display, struct buffer *buffer)
 
 static int
 create_dmabuf_buffer(struct display *display, struct buffer *buffer,
-                    int width, int height)
+                    int width, int height, uint32_t opts)
 {
        /* Y-Invert the buffer image, since we are going to renderer to the
         * buffer through a FBO. */
-       static const uint32_t flags = ZWP_LINUX_BUFFER_PARAMS_V1_FLAGS_Y_INVERT;
+       static uint32_t flags = ZWP_LINUX_BUFFER_PARAMS_V1_FLAGS_Y_INVERT;
        struct zwp_linux_buffer_params_v1 *params;
        int i;
 
@@ -398,6 +401,14 @@ create_dmabuf_buffer(struct display *display, struct buffer *buffer,
 #endif
 
        params = zwp_linux_dmabuf_v1_create_params(display->dmabuf);
+
+       if ((opts & OPT_DIRECT_DISPLAY) && display->direct_display) {
+               weston_direct_display_v1_enable(display->direct_display, params);
+               /* turn off Y_INVERT otherwise linux-dmabuf will reject it and
+                * we need all dmabuf flags turned off */
+               flags &= ~ZWP_LINUX_BUFFER_PARAMS_V1_FLAGS_Y_INVERT;
+       }
+
        for (i = 0; i < buffer->plane_count; ++i) {
                zwp_linux_buffer_params_v1_add(params,
                                               buffer->dmabuf_fds[i],
@@ -695,7 +706,7 @@ create_window(struct display *display, int width, int height, int opts)
 
        for (i = 0; i < NUM_BUFFERS; ++i) {
                ret = create_dmabuf_buffer(display, &window->buffers[i],
-                                          width, height);
+                                          width, height, opts);
 
                if (ret < 0)
                        goto error;
@@ -1047,6 +1058,9 @@ registry_handle_global(void *data, struct wl_registry *registry,
                d->explicit_sync = wl_registry_bind(
                        registry, id,
                        &zwp_linux_explicit_synchronization_v1_interface, 1);
+       } else if (strcmp(interface, "weston_direct_display_v1") == 0) {
+               d->direct_display = wl_registry_bind(registry,
+                                                    id, &weston_direct_display_v1_interface, 1);
        }
 }
 
@@ -1417,7 +1431,9 @@ print_usage_and_exit(void)
                "\n\t\t0 to disable explicit sync, "
                "\n\t\t1 to enable explicit sync (default: 1)\n"
                "\t'-m,--mandelbrot'"
-               "\n\t\trender a mandelbrot set with multiple draw calls\n");
+               "\n\t\trender a mandelbrot set with multiple draw calls\n"
+               "\t'-g,--direct-display'"
+               "\n\t\tenables weston-direct-display extension to attempt direct scan-out\n");
        exit(0);
 }
 
@@ -1451,11 +1467,12 @@ main(int argc, char **argv)
                {"size",             required_argument, 0,  's' },
                {"explicit-sync",    required_argument, 0,  'e' },
                {"mandelbrot",       no_argument,       0,  'm' },
+               {"direct-display",   no_argument,       0,  'g' },
                {"help",             no_argument      , 0,  'h' },
                {0, 0, 0, 0}
        };
 
-       while ((c = getopt_long(argc, argv, "hi:d:s:e:m",
+       while ((c = getopt_long(argc, argv, "hi:d:s:e:mg",
                                long_options, &option_index)) != -1) {
                switch (c) {
                case 'i':
@@ -1475,6 +1492,9 @@ main(int argc, char **argv)
                case 'm':
                        opts |= OPT_MANDELBROT;
                        break;
+               case 'g':
+                       opts |= OPT_DIRECT_DISPLAY;
+                       break;
                default:
                        print_usage_and_exit();
                }