[vlc-devel] [PATCH 3/3] XCB windowless: use Display given rather than creating new xcb connection

Cheng Sun chengsun9 at gmail.com
Sun Dec 30 23:47:35 CET 2012


Fixes compatibility with Chrome
---
 npapi/Makefile.am           |  2 +-
 npapi/vlcwindowless_xcb.cpp | 43 +++++++++++++++++++++++++------------------
 npapi/vlcwindowless_xcb.h   |  3 ++-
 3 files changed, 28 insertions(+), 20 deletions(-)

diff --git a/npapi/Makefile.am b/npapi/Makefile.am
index a96df6d..7a97351 100644
--- a/npapi/Makefile.am
+++ b/npapi/Makefile.am
@@ -80,7 +80,7 @@ endif # !USE_GTK
 
 if HAVE_XCB
 AM_CPPFLAGS += $(XCB_CFLAGS)
-libvlcplugin_la_LIBADD += $(XCB_LIBS)
+libvlcplugin_la_LIBADD += $(XCB_LIBS) -lX11-xcb
 SOURCES_support += \
 	vlcwindowless_xcb.cpp \
 	vlcwindowless_xcb.h
diff --git a/npapi/vlcwindowless_xcb.cpp b/npapi/vlcwindowless_xcb.cpp
index 6e0d781..7bc95f0 100644
--- a/npapi/vlcwindowless_xcb.cpp
+++ b/npapi/vlcwindowless_xcb.cpp
@@ -23,45 +23,52 @@
 
 #include "vlcwindowless_xcb.h"
 
+#include <X11/Xlib-xcb.h>
 #include <xcb/xcb.h>
 #include <xcb/xproto.h>
 #include <cstring>
 #include <cstdlib>
 
 VlcWindowlessXCB::VlcWindowlessXCB(NPP instance, NPuint16_t mode) :
-    VlcWindowlessBase(instance, mode), m_conn(0), m_screen(0)
+    VlcWindowlessBase(instance, mode), m_conn(0), m_colormap(0)
 {
+}
+
+VlcWindowlessXCB::~VlcWindowlessXCB()
+{
+}
+
+bool VlcWindowlessXCB::initXCB()
+{
+    /*
     if (!(m_conn = xcb_connect(NULL, NULL)))
     {
         fprintf(stderr, "Can't connect to XCB\n");
         return;
     }
+    */
 
-    /* Retrieve the setup */
-    const xcb_setup_t *setup;
-    if (!(setup = xcb_get_setup(m_conn)))
-    {
-        fprintf(stderr, "Can't get the XCB setup\n");
-        return;
+    NPSetWindowCallbackStruct *info =
+            static_cast<NPSetWindowCallbackStruct *>(npwindow.ws_info);
+
+    if (!info) {
+        /* NPP_SetWindow has not been called yet */
+        return false;
     }
 
-    /* Get the first screen */
-    m_screen = xcb_setup_roots_iterator(setup).data;
-}
+    m_conn = XGetXCBConnection(info->display);
+    m_colormap = info->colormap;
 
-VlcWindowlessXCB::~VlcWindowlessXCB()
-{
-    xcb_disconnect(m_conn);
+    return true;
 }
 
 void VlcWindowlessXCB::drawBackground(xcb_drawable_t drawable)
 {
     /* Obtain the background color */
-    xcb_colormap_t colormap = m_screen->default_colormap;
     unsigned r = 0, g = 0, b = 0;
     HTMLColor2RGB(get_options().get_bg_color().c_str(), &r, &g, &b);
     xcb_alloc_color_reply_t *reply = xcb_alloc_color_reply(m_conn,
-            xcb_alloc_color(m_conn, colormap,
+            xcb_alloc_color(m_conn, m_colormap,
                             (uint16_t) r << 8,
                             (uint16_t) g << 8,
                             (uint16_t) b << 8), NULL);
@@ -95,9 +102,9 @@ bool VlcWindowlessXCB::handle_event(void *event)
         xcb_generic_error_t *err;
         XGraphicsExposeEvent *xgeevent = reinterpret_cast<XGraphicsExposeEvent *>(xevent);
 
-        /* Something went wrong during initialization */
-        if (!m_conn || !m_screen)
-            break;
+        /* Initialize xcb connection if necessary */
+        if (!m_conn)
+            if (!initXCB()) break;
 
         drawBackground(xgeevent->drawable);
 
diff --git a/npapi/vlcwindowless_xcb.h b/npapi/vlcwindowless_xcb.h
index 41bb005..d79396b 100644
--- a/npapi/vlcwindowless_xcb.h
+++ b/npapi/vlcwindowless_xcb.h
@@ -38,11 +38,12 @@ public:
     bool handle_event(void *event);
 
 protected:
+    bool initXCB();
     void drawBackground(xcb_drawable_t drawable);
 
 private:
     xcb_connection_t *m_conn;
-    xcb_screen_t *m_screen;
+    xcb_colormap_t m_colormap;
 };
 
 
-- 
1.8.0.3




More information about the vlc-devel mailing list