Commit cc7ddda2 authored by Cheng Sun's avatar Cheng Sun Committed by Ludovic Fauvet

XCB windowless: use Display given rather than creating new xcb connection

Fixes compatibility with Chrome
Signed-off-by: Ludovic Fauvet's avatarLudovic Fauvet <etix@videolan.org>
parent 522ae24e
...@@ -248,24 +248,17 @@ dnl GTK+ for linux toolbar ...@@ -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]) AC_ARG_WITH([gtk], AS_HELP_STRING([--with-gtk], [Build the GTK+ toolbars in NPAPI plugin [default=auto]]),, [with_gtk=yes])
gtk_found=no gtk_found=no
AS_IF([ test "${SYS}" != "mingw32" -a "${SYS}" != "darwin" ], [ 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" ], AS_IF([ test "x$with_gtk" != "xno" ],
[ [
PKG_CHECK_MODULES(GTK, [gtk+-2.0], [gtk_found=yes]) 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" ], AS_IF([ test "x$gtk_found" = "xyes" ],
AC_DEFINE([USE_GTK], [1], [Define to 1 if using GTK+])) 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(WITH_GTK, [ test "x$gtk_found" = "xyes" ])
AM_CONDITIONAL(HAVE_XCB, [ test "x$xcb_found" = "xyes" ])
dnl dnl
dnl final flags for ActiveX dnl final flags for ActiveX
......
...@@ -58,36 +58,28 @@ if FETCH_NPAPI ...@@ -58,36 +58,28 @@ if FETCH_NPAPI
$(libvlcplugin_la_OBJECTS): npapi-sdk $(libvlcplugin_la_OBJECTS): npapi-sdk
endif endif
AM_CPPFLAGS += -DXP_UNIX -DDATA_PATH=\"$(pkgdatadir)\" AM_CPPFLAGS += -DXP_UNIX -DDATA_PATH=\"$(pkgdatadir)\" $(XCB_CFLAGS)
libvlcplugin_la_LIBADD += $(MOZILLA_LIBS) libvlcplugin_la_LIBADD += $(MOZILLA_LIBS) $(XCB_LIBS)
SOURCES_support = \ SOURCES_support = \
support/npunix.cpp support/npunix.cpp \
vlcwindowless_xcb.cpp \
vlcwindowless_xcb.h \
vlcwindowless_base.cpp \
vlcwindowless_base.h
if WITH_GTK if WITH_GTK
AM_CPPFLAGS += $(GTK_CFLAGS) AM_CPPFLAGS += $(GTK_CFLAGS)
libvlcplugin_la_LIBADD += $(GTK_LIBS) $(X_LIBS) $(X_PRE_LIBS) -lX11 libvlcplugin_la_LIBADD += $(GTK_LIBS)
SOURCES_support += \ SOURCES_support += \
vlcplugin_gtk.cpp \ vlcplugin_gtk.cpp \
vlcplugin_gtk.h vlcplugin_gtk.h
else # !WITH_GTK else # !WITH_GTK
AM_CPPFLAGS += $(XCB_CFLAGS)
libvlcplugin_la_LIBADD += $(XCB_LIBS)
SOURCES_support += \ SOURCES_support += \
vlcplugin_xcb.cpp \ vlcplugin_xcb.cpp \
vlcplugin_xcb.h vlcplugin_xcb.h
endif # !USE_GTK 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 else # Win32
# Under Win32|Mac, Mozilla plugins need to be named NP******.DLL, but under Unix # Under Win32|Mac, Mozilla plugins need to be named NP******.DLL, but under Unix
......
...@@ -36,10 +36,6 @@ ...@@ -36,10 +36,6 @@
#include "common.h" #include "common.h"
#if defined(XP_UNIX) && !defined(XP_MACOSX) #if defined(XP_UNIX) && !defined(XP_MACOSX)
# if defined(USE_XCB)
# include "vlcwindowless_xcb.h"
typedef VlcWindowlessXCB VlcWindowless;
# endif
# if defined(USE_GTK) # if defined(USE_GTK)
# include "vlcplugin_gtk.h" # include "vlcplugin_gtk.h"
typedef class VlcPluginGtk VlcPlugin; typedef class VlcPluginGtk VlcPlugin;
...@@ -47,6 +43,9 @@ ...@@ -47,6 +43,9 @@
# include "vlcplugin_xcb.h" # include "vlcplugin_xcb.h"
typedef class VlcPluginXcb VlcPlugin; typedef class VlcPluginXcb VlcPlugin;
# endif # endif
# include "vlcwindowless_xcb.h"
typedef VlcWindowlessXCB VlcWindowless;
#elif defined(XP_WIN) #elif defined(XP_WIN)
# include "vlcplugin_win.h" # include "vlcplugin_win.h"
typedef class VlcPluginWin VlcPlugin; typedef class VlcPluginWin VlcPlugin;
......
...@@ -23,45 +23,44 @@ ...@@ -23,45 +23,44 @@
#include "vlcwindowless_xcb.h" #include "vlcwindowless_xcb.h"
#include <X11/Xlib-xcb.h>
#include <xcb/xcb.h> #include <xcb/xcb.h>
#include <xcb/xproto.h> #include <xcb/xproto.h>
#include <cstring> #include <cstring>
#include <cstdlib> #include <cstdlib>
VlcWindowlessXCB::VlcWindowlessXCB(NPP instance, NPuint16_t mode) : 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() 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) void VlcWindowlessXCB::drawBackground(xcb_drawable_t drawable)
{ {
/* Obtain the background color */ /* Obtain the background color */
xcb_colormap_t colormap = m_screen->default_colormap;
unsigned r = 0, g = 0, b = 0; unsigned r = 0, g = 0, b = 0;
HTMLColor2RGB(get_options().get_bg_color().c_str(), &r, &g, &b); 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_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) r << 8,
(uint16_t) g << 8, (uint16_t) g << 8,
(uint16_t) b << 8), NULL); (uint16_t) b << 8), NULL);
...@@ -95,9 +94,9 @@ bool VlcWindowlessXCB::handle_event(void *event) ...@@ -95,9 +94,9 @@ bool VlcWindowlessXCB::handle_event(void *event)
xcb_generic_error_t *err; xcb_generic_error_t *err;
XGraphicsExposeEvent *xgeevent = reinterpret_cast<XGraphicsExposeEvent *>(xevent); XGraphicsExposeEvent *xgeevent = reinterpret_cast<XGraphicsExposeEvent *>(xevent);
/* Something went wrong during initialization */ /* Initialize xcb connection if necessary */
if (!m_conn || !m_screen) if (!m_conn)
break; if (!initXCB()) break;
drawBackground(xgeevent->drawable); drawBackground(xgeevent->drawable);
......
...@@ -37,11 +37,12 @@ public: ...@@ -37,11 +37,12 @@ public:
bool handle_event(void *event); bool handle_event(void *event);
protected: protected:
bool initXCB();
void drawBackground(xcb_drawable_t drawable); void drawBackground(xcb_drawable_t drawable);
private: private:
xcb_connection_t *m_conn; xcb_connection_t *m_conn;
xcb_screen_t *m_screen; xcb_colormap_t m_colormap;
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment