]> git.sesse.net Git - vlc/blobdiff - modules/video_output/xcb/xvideo.c
vout_window_t: simplify via anynomous union
[vlc] / modules / video_output / xcb / xvideo.c
index d2cb1cad6055b3adaabe43a4a88885570e558c1f..0328e1e8be11b8000e1a578059051e6fa78be587 100644 (file)
@@ -35,6 +35,7 @@
 #include <vlc_plugin.h>
 #include <vlc_vout_display.h>
 #include <vlc_picture_pool.h>
+#include <vlc_dialog.h>
 
 #include "xcb_vlc.h"
 
@@ -85,6 +86,7 @@ struct vout_display_sys_t
     xcb_connection_t *conn;
     vout_window_t *embed;/* VLC window */
 
+    xcb_cursor_t cursor; /* blank cursor */
     xcb_window_t window; /* drawable X window */
     xcb_gcontext_t gc;   /* context to put images */
     xcb_xv_port_t port;  /* XVideo port */
@@ -268,6 +270,19 @@ FindFormat (vout_display_t *vd,
             msg_Warn (vd, "incompatible size %ux%u -> %"PRIu32"x%"PRIu32,
                       fmt->i_width, fmt->i_height,
                       i->width, i->height);
+            var_Create (vd->p_libvlc, "xvideo-resolution-error", VLC_VAR_BOOL);
+            if (!var_GetBool (vd->p_libvlc, "xvideo-resolution-error"))
+            {
+                dialog_FatalWait (vd, _("Video acceleration not available"),
+                    _("Your video output acceleration driver does not support "
+                      "the required resolution: %ux%u pixels. The maximum "
+                      "supported resolution is %"PRIu32"x%"PRIu32".\n"
+                      "Video output acceleration will be disabled. However, "
+                      "rendering videos with overly large resolution "
+                      "may cause severe performance degration."),
+                                  width, height, i->width, i->height);
+                var_SetBool (vd->p_libvlc, "xvideo-resolution-error", true);
+            }
             free (i);
             continue;
         }
@@ -308,7 +323,8 @@ static int Open (vlc_object_t *obj)
     }
 
     const xcb_screen_t *screen;
-    p_sys->embed = GetWindow (vd, conn, &screen, &p_sys->shm);
+    uint8_t depth;
+    p_sys->embed = GetWindow (vd, conn, &screen, &depth, &p_sys->shm);
     if (p_sys->embed == NULL)
     {
         xcb_disconnect (conn);
@@ -319,11 +335,12 @@ static int Open (vlc_object_t *obj)
     /* */
     p_sys->att = NULL;
     p_sys->pool = NULL;
+    p_sys->window = xcb_generate_id (conn);
 
     /* Cache adaptors infos */
     xcb_xv_query_adaptors_reply_t *adaptors =
         xcb_xv_query_adaptors_reply (conn,
-            xcb_xv_query_adaptors (conn, p_sys->embed->handle.xid), NULL);
+            xcb_xv_query_adaptors (conn, p_sys->embed->xid), NULL);
     if (adaptors == NULL)
         goto error;
 
@@ -373,7 +390,7 @@ static int Open (vlc_object_t *obj)
             chromas = chromas_default;
 
         vlc_fourcc_t chroma;
-        for (size_t i = 0; chromas[i] && (xfmt == NULL); i++)
+        for (size_t i = 0; chromas[i]; i++)
         {
             chroma = chromas[i];
 
@@ -387,10 +404,22 @@ static int Open (vlc_object_t *obj)
             }
 
             xfmt = FindFormat (vd, chroma, &fmt, a->base_id, r, &p_sys->att);
+            if (xfmt != NULL)
+            {
+                p_sys->id = xfmt->id;
+                fmt.i_chroma = chroma;
+                if (xfmt->type == XCB_XV_IMAGE_FORMAT_INFO_TYPE_RGB)
+                {
+                    fmt.i_rmask = xfmt->red_mask;
+                    fmt.i_gmask = xfmt->green_mask;
+                    fmt.i_bmask = xfmt->blue_mask;
+                }
+                break;
+            }
         }
-
+        free (r);
         if (xfmt == NULL) /* No acceptable image formats */
-            goto skip_adaptor;
+            continue;
 
         /* Grab a port */
         for (unsigned i = 0; i < a->num_ports; i++)
@@ -405,14 +434,13 @@ static int Open (vlc_object_t *obj)
              if (result == 0)
              {
                  p_sys->port = port;
-                 found_adaptor = true;
-                 break;
+                 goto grabbed_port;
              }
              msg_Dbg (vd, "cannot grab port %"PRIu32, port);
         }
-        if (!found_adaptor)
-            goto skip_adaptor;
+        continue; /* No usable port */
 
+    grabbed_port:
         /* Found port - initialize selected format */
         name = strndup (xcb_xv_adaptor_info_name (a), a->name_size);
         if (name != NULL)
@@ -421,19 +449,39 @@ static int Open (vlc_object_t *obj)
             free (name);
         }
         msg_Dbg (vd, "using port %"PRIu32, p_sys->port);
-
-        p_sys->id = xfmt->id;
         msg_Dbg (vd, "using image format 0x%"PRIx32, p_sys->id);
-        fmt.i_chroma = chroma;
-        if (xfmt->type == XCB_XV_IMAGE_FORMAT_INFO_TYPE_RGB)
+
+        /* Look for an X11 visual, create a window */
+        xcb_xv_format_t *f = xcb_xv_adaptor_info_formats (a);
+        for (uint_fast16_t i = a->num_formats; i > 0; i--, f++)
         {
-            fmt.i_rmask = xfmt->red_mask;
-            fmt.i_gmask = xfmt->green_mask;
-            fmt.i_bmask = xfmt->blue_mask;
+            if (f->depth != depth)
+                continue; /* this would fail anyway */
+
+            const uint32_t mask =
+                /* XCB_CW_EVENT_MASK */
+                XCB_EVENT_MASK_VISIBILITY_CHANGE;
+            xcb_void_cookie_t c;
+
+            c = xcb_create_window_checked (conn, f->depth, p_sys->window,
+                 p_sys->embed->xid, 0, 0, 1, 1, 0,
+                 XCB_WINDOW_CLASS_INPUT_OUTPUT, f->visual,
+                 XCB_CW_EVENT_MASK, &mask);
+
+            if (!CheckError (vd, conn, "cannot create X11 window", c))
+            {
+                msg_Dbg (vd, "using X11 visual ID 0x%"PRIx32
+                         " (depth: %"PRIu8")", f->visual, f->depth);
+                msg_Dbg (vd, "using X11 window 0x%08"PRIx32, p_sys->window);
+                goto created_window;
+            }
         }
+        xcb_xv_ungrab_port (conn, p_sys->port, XCB_CURRENT_TIME);
+        continue; /* No workable XVideo format (visual/depth) */
 
-    skip_adaptor:
-        free (r);
+    created_window:
+        found_adaptor = true;
+        break;
     }
     free (adaptors);
     if (!found_adaptor)
@@ -441,26 +489,9 @@ static int Open (vlc_object_t *obj)
         msg_Err (vd, "no available XVideo adaptor");
         goto error;
     }
-
-    /* Create window */
+    else
     {
-        const uint32_t mask =
-            /* XCB_CW_EVENT_MASK */
-            XCB_EVENT_MASK_BUTTON_PRESS | XCB_EVENT_MASK_BUTTON_RELEASE |
-            XCB_EVENT_MASK_POINTER_MOTION | XCB_EVENT_MASK_VISIBILITY_CHANGE;
-        xcb_void_cookie_t c;
-        xcb_window_t window = xcb_generate_id (conn);
-
-        c = xcb_create_window_checked (conn, screen->root_depth, window,
-                                       p_sys->embed->handle.xid, 0, 0, 1, 1, 0,
-                                       XCB_WINDOW_CLASS_INPUT_OUTPUT,
-                                       screen->root_visual,
-                                       XCB_CW_EVENT_MASK, &mask);
-        if (CheckError (vd, conn, "cannot create X11 window", c))
-            goto error;
-        p_sys->window = window;
-        msg_Dbg (vd, "using X11 window 0x%08"PRIx32, window);
-        xcb_map_window (conn, window);
+        xcb_map_window (conn, p_sys->window);
 
         vout_display_place_t place;
 
@@ -469,10 +500,12 @@ static int Open (vlc_object_t *obj)
         p_sys->height = place.height;
 
         /* */
-        const uint32_t values[] = { place.x, place.y, place.width, place.height };
-        xcb_configure_window (conn, window,
+        const uint32_t values[] = {
+            place.x, place.y, place.width, place.height };
+        xcb_configure_window (conn, p_sys->window,
                               XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y |
-                              XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT,
+                              XCB_CONFIG_WINDOW_WIDTH |
+                              XCB_CONFIG_WINDOW_HEIGHT,
                               values);
     }
     p_sys->visible = false;
@@ -482,6 +515,9 @@ static int Open (vlc_object_t *obj)
     xcb_create_gc (conn, p_sys->gc, p_sys->window, 0, NULL);
     msg_Dbg (vd, "using X11 graphic context 0x%08"PRIx32, p_sys->gc);
 
+    /* Create cursor */
+    p_sys->cursor = CreateBlankCursor (conn, screen);
+
     /* */
     p_sys->pool = NULL;
 
@@ -676,7 +712,7 @@ static int Control (vout_display_t *vd, int query, va_list ap)
     {
         const vout_display_cfg_t *cfg;
         const video_format_t *source;
-        bool is_forced;
+        bool is_forced = false;
 
         if (query == VOUT_DISPLAY_CHANGE_SOURCE_ASPECT
          || query == VOUT_DISPLAY_CHANGE_SOURCE_CROP)
@@ -723,12 +759,12 @@ static int Control (vout_display_t *vd, int query, va_list ap)
         return vout_window_SetOnTop (p_sys->embed, on_top);
     }
 
-    /* TODO */
-#if 0
     /* Hide the mouse. It will be send when
      * vout_display_t::info.b_hide_mouse is false */
-    VOUT_DISPLAY_HIDE_MOUSE,
-#endif
+    case VOUT_DISPLAY_HIDE_MOUSE:
+        xcb_change_window_attributes (p_sys->conn, p_sys->embed->xid,
+                                  XCB_CW_CURSOR, &(uint32_t){ p_sys->cursor });
+        return VLC_SUCCESS;
     case VOUT_DISPLAY_RESET_PICTURES:
         assert(0);
     default: