void NetscapePlugin::platformPaint(GraphicsContext* context, const IntRect& dirtyRect, bool /*isSnapshot*/) { if (m_isWindowed) return; if (!m_isStarted) { // FIXME: we should paint a missing plugin icon. return; } if (context->paintingDisabled() || !m_drawable) return; XEvent xevent; memset(&xevent, 0, sizeof(XEvent)); XGraphicsExposeEvent& exposeEvent = xevent.xgraphicsexpose; exposeEvent.type = GraphicsExpose; exposeEvent.display = x11HostDisplay(); exposeEvent.drawable = m_drawable; IntRect exposedRect(dirtyRect); exposeEvent.x = exposedRect.x(); exposeEvent.y = exposedRect.y(); // Note: in transparent mode Flash thinks width is the right and height is the bottom. // We should take it into account if we want to support transparency. exposeEvent.width = exposedRect.width(); exposeEvent.height = exposedRect.height(); NPP_HandleEvent(&xevent); if (m_pluginDisplay != x11HostDisplay()) XSync(m_pluginDisplay, false); #if PLATFORM(GTK) || (PLATFORM(EFL) && USE(CAIRO)) RefPtr<cairo_surface_t> drawableSurface = adoptRef(cairo_xlib_surface_create(m_pluginDisplay, m_drawable, static_cast<NPSetWindowCallbackStruct*>(m_npWindow.ws_info)->visual, m_pluginSize.width(), m_pluginSize.height())); cairo_t* cr = context->platformContext()->cr(); cairo_save(cr); cairo_set_source_surface(cr, drawableSurface.get(), 0, 0); cairo_rectangle(cr, exposedRect.x(), exposedRect.y(), exposedRect.width(), exposedRect.height()); cairo_clip(cr); cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); cairo_paint(cr); cairo_restore(cr); #else notImplemented(); #endif }
void NetscapePlugin::platformGeometryDidChange() { if (m_isWindowed) { uint64_t windowID = 0; #if PLATFORM(GTK) windowID = static_cast<uint64_t>(GDK_WINDOW_XID(gtk_plug_get_socket_window(GTK_PLUG(m_platformPluginWidget)))); #endif IntRect clipRect(m_clipRect); clipRect.move(-m_frameRectInWindowCoordinates.x(), -m_frameRectInWindowCoordinates.y()); controller()->windowedPluginGeometryDidChange(m_frameRectInWindowCoordinates, clipRect, windowID); return; } Display* display = x11HostDisplay(); if (m_drawable) XFreePixmap(display, m_drawable); if (m_pluginSize.isEmpty()) { m_drawable = 0; return; } m_drawable = XCreatePixmap(display, rootWindowID(), m_pluginSize.width(), m_pluginSize.height(), displayDepth()); XSync(display, false); // Make sure that the server knows about the Drawable. }
bool NetscapePlugin::platformPostInitializeWindowless() { Display* display = x11HostDisplay(); m_npWindow.type = NPWindowTypeDrawable; m_npWindow.window = 0; int depth = displayDepth(); #if PLATFORM(QT) ASSERT(depth == 16 || depth == 24 || depth == 32); #endif NPSetWindowCallbackStruct* callbackStruct = static_cast<NPSetWindowCallbackStruct*>(m_npWindow.ws_info); callbackStruct->display = display; callbackStruct->depth = depth; XVisualInfo visualTemplate; visualTemplate.screen = x11Screen(); visualTemplate.depth = depth; visualTemplate.c_class = TrueColor; int numMatching; XVisualInfo* visualInfo = XGetVisualInfo(display, VisualScreenMask | VisualDepthMask | VisualClassMask, &visualTemplate, &numMatching); ASSERT(visualInfo); Visual* visual = visualInfo[0].visual; ASSERT(visual); XFree(visualInfo); callbackStruct->visual = visual; callbackStruct->colormap = XCreateColormap(display, rootWindowID(), visual, AllocNone); callSetWindow(); return true; }
NetscapePluginX11::NetscapePluginX11(NetscapePlugin& plugin, Display* display, uint64_t windowID) : m_plugin(plugin) , m_pluginDisplay(display) , m_windowID(windowID) { // It seems flash needs the socket to be in the same process, // I guess it uses gdk_window_lookup(), so we create a new socket here // containing a plug with the UI process socket embedded. m_platformPluginWidget = gtk_plug_new(static_cast<Window>(windowID)); // Hide the GtkPlug on delete-event since we assume the widget is valid while the plugin is active. // platformDestroy() will be called anyway right after the delete-event. g_signal_connect(m_platformPluginWidget, "delete-event", G_CALLBACK(gtk_widget_hide_on_delete), nullptr); GtkWidget* socket = gtk_socket_new(); // Do not show the plug widget until the socket is connected. g_signal_connect_swapped(socket, "plug-added", G_CALLBACK(gtk_widget_show), m_platformPluginWidget); g_signal_connect(socket, "plug-removed", G_CALLBACK(socketPlugRemovedCallback), nullptr); gtk_container_add(GTK_CONTAINER(m_platformPluginWidget), socket); gtk_widget_show(socket); Display* hostDisplay = x11HostDisplay(); m_npWindowID = gtk_socket_get_id(GTK_SOCKET(socket)); GdkWindow* window = gtk_widget_get_window(socket); m_setWindowCallbackStruct.display = GDK_WINDOW_XDISPLAY(window); m_setWindowCallbackStruct.visual = GDK_VISUAL_XVISUAL(gdk_window_get_visual(window)); m_setWindowCallbackStruct.depth = gdk_visual_get_depth(gdk_window_get_visual(window)); m_setWindowCallbackStruct.colormap = XCreateColormap(hostDisplay, GDK_ROOT_WINDOW(), m_setWindowCallbackStruct.visual, AllocNone); XFlush(hostDisplay); }
static inline void initializeXEvent(XEvent& event) { memset(&event, 0, sizeof(XEvent)); event.xany.serial = 0; event.xany.send_event = false; event.xany.display = x11HostDisplay(); event.xany.window = 0; }
void NetscapePluginX11::paint(GraphicsContext& context, const IntRect& dirtyRect) { ASSERT(!m_plugin.isWindowed()); if (context.paintingDisabled() || !m_drawable) return; XEvent xevent; memset(&xevent, 0, sizeof(XEvent)); XGraphicsExposeEvent& exposeEvent = xevent.xgraphicsexpose; exposeEvent.type = GraphicsExpose; exposeEvent.display = x11HostDisplay(); exposeEvent.drawable = m_drawable.get(); IntRect exposedRect(dirtyRect); exposeEvent.x = exposedRect.x(); exposeEvent.y = exposedRect.y(); // Note: in transparent mode Flash thinks width is the right and height is the bottom. // We should take it into account if we want to support transparency. exposeEvent.width = exposedRect.width(); exposeEvent.height = exposedRect.height(); m_plugin.NPP_HandleEvent(&xevent); if (m_pluginDisplay != x11HostDisplay()) XSync(m_pluginDisplay, false); #if PLATFORM(GTK) || (PLATFORM(EFL) && USE(CAIRO)) RefPtr<cairo_surface_t> drawableSurface = adoptRef(cairo_xlib_surface_create(m_pluginDisplay, m_drawable.get(), m_setWindowCallbackStruct.visual, m_plugin.size().width(), m_plugin.size().height())); cairo_t* cr = context.platformContext()->cr(); cairo_save(cr); cairo_set_source_surface(cr, drawableSurface.get(), 0, 0); cairo_rectangle(cr, exposedRect.x(), exposedRect.y(), exposedRect.width(), exposedRect.height()); cairo_clip(cr); cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); cairo_paint(cr); cairo_restore(cr); #else notImplemented(); #endif }
void NetscapePluginX11::geometryDidChange() { if (m_plugin.isWindowed()) { uint64_t windowID = 0; #if PLATFORM(GTK) windowID = static_cast<uint64_t>(GDK_WINDOW_XID(gtk_plug_get_socket_window(GTK_PLUG(m_platformPluginWidget)))); #endif m_plugin.controller()->windowedPluginGeometryDidChange(m_plugin.frameRectInWindowCoordinates(), m_plugin.clipRect(), windowID); return; } m_drawable.reset(); if (m_plugin.size().isEmpty()) return; m_drawable = XCreatePixmap(x11HostDisplay(), rootWindowID(), m_plugin.size().width(), m_plugin.size().height(), displayDepth()); XSync(x11HostDisplay(), false); // Make sure that the server knows about the Drawable. }
static inline int displayDepth() { #if PLATFORM(GTK) return gdk_visual_get_depth(gdk_screen_get_system_visual(gdk_screen_get_default())); #elif PLATFORM(EFL) && defined(HAVE_ECORE_X) return ecore_x_default_depth_get(x11HostDisplay(), ecore_x_default_screen_get()); #else return 0; #endif }
NetscapePluginX11::~NetscapePluginX11() { XFreeColormap(x11HostDisplay(), m_setWindowCallbackStruct.colormap); m_drawable.reset(); #if PLATFORM(GTK) if (m_platformPluginWidget) gtk_widget_destroy(m_platformPluginWidget); #endif }
void NetscapePlugin::platformDestroy() { NPSetWindowCallbackStruct* callbackStruct = static_cast<NPSetWindowCallbackStruct*>(m_npWindow.ws_info); Display* hostDisplay = x11HostDisplay(); XFreeColormap(hostDisplay, callbackStruct->colormap); delete callbackStruct; if (m_drawable) { XFreePixmap(hostDisplay, m_drawable); m_drawable = 0; } }
void NetscapePlugin::platformDestroy() { NPSetWindowCallbackStruct* callbackStruct = static_cast<NPSetWindowCallbackStruct*>(m_npWindow.ws_info); Display* hostDisplay = x11HostDisplay(); XFreeColormap(hostDisplay, callbackStruct->colormap); delete callbackStruct; if (m_drawable) { XFreePixmap(hostDisplay, m_drawable); m_drawable = 0; } #if PLATFORM(GTK) if (m_platformPluginWidget) { gtk_widget_destroy(m_platformPluginWidget); m_platformPluginWidget = 0; } #endif }
NetscapePluginX11::NetscapePluginX11(NetscapePlugin& plugin, Display* display) : m_plugin(plugin) , m_pluginDisplay(display) { Display* hostDisplay = x11HostDisplay(); int depth = displayDepth(); m_setWindowCallbackStruct.display = hostDisplay; m_setWindowCallbackStruct.depth = depth; XVisualInfo visualTemplate; visualTemplate.screen = x11Screen(); visualTemplate.depth = depth; visualTemplate.c_class = TrueColor; int numMatching; XUniquePtr<XVisualInfo> visualInfo(XGetVisualInfo(hostDisplay, VisualScreenMask | VisualDepthMask | VisualClassMask, &visualTemplate, &numMatching)); ASSERT(visualInfo); Visual* visual = visualInfo.get()[0].visual; ASSERT(visual); m_setWindowCallbackStruct.visual = visual; m_setWindowCallbackStruct.colormap = XCreateColormap(hostDisplay, rootWindowID(), visual, AllocNone); }
bool NetscapePlugin::platformPostInitializeWindowed(bool needsXEmbed, uint64_t windowID) { m_npWindow.type = NPWindowTypeWindow; if (!needsXEmbed) { notImplemented(); return false; } Display* display = x11HostDisplay(); #if PLATFORM(GTK) // It seems flash needs the socket to be in the same process, // I guess it uses gdk_window_lookup(), so we create a new socket here // containing a plug with the UI process socket embedded. m_platformPluginWidget = gtk_plug_new(static_cast<Window>(windowID)); GtkWidget* socket = gtk_socket_new(); // Do not show the plug widget until the socket is connected. g_signal_connect_swapped(socket, "plug-added", G_CALLBACK(gtk_widget_show), m_platformPluginWidget); g_signal_connect(socket, "plug-removed", G_CALLBACK(socketPlugRemovedCallback), nullptr); gtk_container_add(GTK_CONTAINER(m_platformPluginWidget), socket); gtk_widget_show(socket); m_npWindow.window = GINT_TO_POINTER(gtk_socket_get_id(GTK_SOCKET(socket))); GdkWindow* window = gtk_widget_get_window(socket); NPSetWindowCallbackStruct* callbackStruct = static_cast<NPSetWindowCallbackStruct*>(m_npWindow.ws_info); callbackStruct->display = GDK_WINDOW_XDISPLAY(window); callbackStruct->visual = GDK_VISUAL_XVISUAL(gdk_window_get_visual(window)); callbackStruct->depth = gdk_visual_get_depth(gdk_window_get_visual(window)); callbackStruct->colormap = XCreateColormap(display, GDK_ROOT_WINDOW(), callbackStruct->visual, AllocNone); #else UNUSED_PARAM(windowID); #endif XFlush(display); callSetWindow(); return true; }