npapi-vlc | branch: master | Cheng Sun <[email protected]> | Fri Jan 4 21:08:58 2013 +0000| [cc7ddda2763baa7569f720920d5b44fc5876d203] | committer: Ludovic Fauvet
XCB windowless: use Display given rather than creating new xcb connection Fixes compatibility with Chrome Signed-off-by: Ludovic Fauvet <[email protected]> > http://git.videolan.org/gitweb.cgi/npapi-vlc.git/?a=commit;h=cc7ddda2763baa7569f720920d5b44fc5876d203 --- configure.ac | 13 +++---------- npapi/Makefile.am | 24 ++++++++--------------- npapi/vlcplugin.h | 7 +++---- npapi/vlcwindowless_xcb.cpp | 45 +++++++++++++++++++++---------------------- npapi/vlcwindowless_xcb.h | 3 ++- 5 files changed, 38 insertions(+), 54 deletions(-) diff --git a/configure.ac b/configure.ac index 513d2d1..365bd5d 100644 --- a/configure.ac +++ b/configure.ac @@ -248,24 +248,17 @@ dnl GTK+ for linux toolbar AC_ARG_WITH([gtk], AS_HELP_STRING([--with-gtk], [Build the GTK+ toolbars in NPAPI plugin [default=auto]]),, [with_gtk=yes]) gtk_found=no AS_IF([ test "${SYS}" != "mingw32" -a "${SYS}" != "darwin" ], [ - PKG_CHECK_MODULES(XCB, [xcb],[xcb_found=yes]) + PKG_CHECK_MODULES(XCB, [xcb x11-xcb],[], [ + AC_MSG_ERROR([Please install the libxcb and x11-xcb development files]) + ]) AS_IF([ test "x$with_gtk" != "xno" ], [ PKG_CHECK_MODULES(GTK, [gtk+-2.0], [gtk_found=yes]) ]) - AS_IF([ test "x$gtk_found" == "xno" ], - [ - AS_IF([ test "x$xcb_found" == "xno"], [ - AC_MSG_ERROR([Please install the libxcb development files, or re-run configure with --with-gtk]) - ]) - ]) ]) AS_IF([ test "x$gtk_found" = "xyes" ], AC_DEFINE([USE_GTK], [1], [Define to 1 if using GTK+])) -AS_IF([ test "x$xcb_found" = "xyes" ], - AC_DEFINE([USE_XCB], [1], [Define to 1 if using XCB])) AM_CONDITIONAL(WITH_GTK, [ test "x$gtk_found" = "xyes" ]) -AM_CONDITIONAL(HAVE_XCB, [ test "x$xcb_found" = "xyes" ]) dnl dnl final flags for ActiveX diff --git a/npapi/Makefile.am b/npapi/Makefile.am index c419fbc..5b16024 100644 --- a/npapi/Makefile.am +++ b/npapi/Makefile.am @@ -58,36 +58,28 @@ if FETCH_NPAPI $(libvlcplugin_la_OBJECTS): npapi-sdk endif -AM_CPPFLAGS += -DXP_UNIX -DDATA_PATH=\"$(pkgdatadir)\" -libvlcplugin_la_LIBADD += $(MOZILLA_LIBS) +AM_CPPFLAGS += -DXP_UNIX -DDATA_PATH=\"$(pkgdatadir)\" $(XCB_CFLAGS) +libvlcplugin_la_LIBADD += $(MOZILLA_LIBS) $(XCB_LIBS) SOURCES_support = \ - support/npunix.cpp + support/npunix.cpp \ + vlcwindowless_xcb.cpp \ + vlcwindowless_xcb.h \ + vlcwindowless_base.cpp \ + vlcwindowless_base.h if WITH_GTK AM_CPPFLAGS += $(GTK_CFLAGS) -libvlcplugin_la_LIBADD += $(GTK_LIBS) $(X_LIBS) $(X_PRE_LIBS) -lX11 +libvlcplugin_la_LIBADD += $(GTK_LIBS) SOURCES_support += \ vlcplugin_gtk.cpp \ vlcplugin_gtk.h else # !WITH_GTK -AM_CPPFLAGS += $(XCB_CFLAGS) -libvlcplugin_la_LIBADD += $(XCB_LIBS) SOURCES_support += \ vlcplugin_xcb.cpp \ vlcplugin_xcb.h endif # !USE_GTK -if HAVE_XCB -AM_CPPFLAGS += $(XCB_CFLAGS) -libvlcplugin_la_LIBADD += $(XCB_LIBS) -SOURCES_support += \ - vlcwindowless_xcb.cpp \ - vlcwindowless_xcb.h \ - vlcwindowless_base.cpp \ - vlcwindowless_base.h -endif # !HAVE_XCB - else # Win32 # Under Win32|Mac, Mozilla plugins need to be named NP******.DLL, but under Unix diff --git a/npapi/vlcplugin.h b/npapi/vlcplugin.h index 82c4180..9f993ce 100644 --- a/npapi/vlcplugin.h +++ b/npapi/vlcplugin.h @@ -36,10 +36,6 @@ #include "common.h" #if defined(XP_UNIX) && !defined(XP_MACOSX) -# if defined(USE_XCB) -# include "vlcwindowless_xcb.h" - typedef VlcWindowlessXCB VlcWindowless; -# endif # if defined(USE_GTK) # include "vlcplugin_gtk.h" typedef class VlcPluginGtk VlcPlugin; @@ -47,6 +43,9 @@ # include "vlcplugin_xcb.h" typedef class VlcPluginXcb VlcPlugin; # endif + +# include "vlcwindowless_xcb.h" + typedef VlcWindowlessXCB VlcWindowless; #elif defined(XP_WIN) # include "vlcplugin_win.h" typedef class VlcPluginWin VlcPlugin; diff --git a/npapi/vlcwindowless_xcb.cpp b/npapi/vlcwindowless_xcb.cpp index 6e0d781..6ce2b0d 100644 --- a/npapi/vlcwindowless_xcb.cpp +++ b/npapi/vlcwindowless_xcb.cpp @@ -23,45 +23,44 @@ #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) { - 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; - } - - /* Get the first screen */ - m_screen = xcb_setup_roots_iterator(setup).data; } VlcWindowlessXCB::~VlcWindowlessXCB() { - xcb_disconnect(m_conn); +} + +bool VlcWindowlessXCB::initXCB() +{ + NPSetWindowCallbackStruct *info = + static_cast<NPSetWindowCallbackStruct *>(npwindow.ws_info); + + if (!info) { + /* NPP_SetWindow has not been called yet */ + return false; + } + + m_conn = XGetXCBConnection(info->display); + m_colormap = info->colormap; + + 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 +94,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 4c84d35..19ee8f7 100644 --- a/npapi/vlcwindowless_xcb.h +++ b/npapi/vlcwindowless_xcb.h @@ -37,11 +37,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; }; _______________________________________________ vlc-commits mailing list [email protected] http://mailman.videolan.org/listinfo/vlc-commits
