Title: [260946] trunk/Source
Revision
260946
Author
[email protected]
Date
2020-04-30 05:58:53 -0700 (Thu, 30 Apr 2020)

Log Message

[GTK4][X11] Add support for rendering web view contents
https://bugs.webkit.org/show_bug.cgi?id=211189

Reviewed by Adrian Perez de Castro.

Source/WebCore:

Add PlatformDisplayX11::visual() to get the X visual used for rendering.

* platform/graphics/x11/PlatformDisplayX11.cpp:
(WebCore::PlatformDisplayX11::visual const):
* platform/graphics/x11/PlatformDisplayX11.h:

Source/WebKit:

Use GdkDisplayX11::xevent signal instead of filtering events that is no longer available in GTK4. GdkVisual no
longer exists either, so we get the X visual from the PlatformDisplay.

* UIProcess/gtk/AcceleratedBackingStoreX11.cpp:
(WebKit::XDamageNotifier::add):
(WebKit::XDamageNotifier::remove):
(WebKit::XDamageNotifier::filterXDamageEvent):
(WebKit::AcceleratedBackingStoreX11::~AcceleratedBackingStoreX11):
(WebKit::AcceleratedBackingStoreX11::update):
(WebKit::AcceleratedBackingStoreX11::snapshot):
* WebProcess/WebPage/gtk/AcceleratedSurfaceX11.cpp:
(WebKit::AcceleratedSurfaceX11::AcceleratedSurfaceX11):
(WebKit::AcceleratedSurfaceX11::createPixmap):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (260945 => 260946)


--- trunk/Source/WebCore/ChangeLog	2020-04-30 12:57:00 UTC (rev 260945)
+++ trunk/Source/WebCore/ChangeLog	2020-04-30 12:58:53 UTC (rev 260946)
@@ -1,3 +1,16 @@
+2020-04-30  Carlos Garcia Campos  <[email protected]>
+
+        [GTK4][X11] Add support for rendering web view contents
+        https://bugs.webkit.org/show_bug.cgi?id=211189
+
+        Reviewed by Adrian Perez de Castro.
+
+        Add PlatformDisplayX11::visual() to get the X visual used for rendering.
+
+        * platform/graphics/x11/PlatformDisplayX11.cpp:
+        (WebCore::PlatformDisplayX11::visual const):
+        * platform/graphics/x11/PlatformDisplayX11.h:
+
 2020-04-30  Andres Gonzalez  <[email protected]>
 
         Add logging of AXIsolatedTree and AXNotifications.

Modified: trunk/Source/WebCore/platform/graphics/x11/PlatformDisplayX11.cpp (260945 => 260946)


--- trunk/Source/WebCore/platform/graphics/x11/PlatformDisplayX11.cpp	2020-04-30 12:57:00 UTC (rev 260945)
+++ trunk/Source/WebCore/platform/graphics/x11/PlatformDisplayX11.cpp	2020-04-30 12:58:53 UTC (rev 260946)
@@ -124,6 +124,31 @@
     return m_supportsXDamage.value();
 }
 
+void* PlatformDisplayX11::visual() const
+{
+    if (m_visual)
+        return m_visual;
+
+    XVisualInfo visualTemplate;
+    visualTemplate.screen = DefaultScreen(m_display);
+
+    int visualCount = 0;
+    XVisualInfo* visualInfo = XGetVisualInfo(m_display, VisualScreenMask, &visualTemplate, &visualCount);
+    for (int i = 0; i < visualCount; ++i) {
+        auto& info = visualInfo[i];
+        if (info.depth == 32 && info.red_mask == 0xff0000 && info.green_mask == 0x00ff00 && info.blue_mask == 0x0000ff) {
+            m_visual = info.visual;
+            break;
+        }
+    }
+    XFree(visualInfo);
+
+    if (!m_visual)
+        m_visual = DefaultVisual(m_display, DefaultScreen(m_display));
+
+    return m_visual;
+}
+
 } // namespace WebCore
 
 #endif // PLATFORM(X11)

Modified: trunk/Source/WebCore/platform/graphics/x11/PlatformDisplayX11.h (260945 => 260946)


--- trunk/Source/WebCore/platform/graphics/x11/PlatformDisplayX11.h	2020-04-30 12:57:00 UTC (rev 260945)
+++ trunk/Source/WebCore/platform/graphics/x11/PlatformDisplayX11.h	2020-04-30 12:58:53 UTC (rev 260946)
@@ -23,8 +23,7 @@
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#ifndef PlatformDisplayX11_h
-#define PlatformDisplayX11_h
+#pragma once
 
 #if PLATFORM(X11)
 
@@ -33,6 +32,10 @@
 
 typedef struct _XDisplay Display;
 
+// It's not possible to forward declare Visual, and including xlib in headers is problematic,
+// so we use void* for Visual and provide this macro to get the visual easily.
+#define WK_XVISUAL(platformDisplay) (static_cast<Visual*>(platformDisplay.visual()))
+
 namespace WebCore {
 
 class PlatformDisplayX11 final : public PlatformDisplay {
@@ -43,6 +46,7 @@
     virtual ~PlatformDisplayX11();
 
     Display* native() const { return m_display; }
+    void* visual() const;
     bool supportsXComposite() const;
     bool supportsXDamage(Optional<int>& damageEventBase, Optional<int>& damageErrorBase) const;
 
@@ -60,6 +64,7 @@
     mutable Optional<bool> m_supportsXDamage;
     mutable Optional<int> m_damageEventBase;
     mutable Optional<int> m_damageErrorBase;
+    mutable void* m_visual { nullptr };
 };
 
 } // namespace WebCore
@@ -67,5 +72,3 @@
 SPECIALIZE_TYPE_TRAITS_PLATFORM_DISPLAY(PlatformDisplayX11, X11)
 
 #endif // PLATFORM(X11)
-
-#endif // PlatformDisplayX11

Modified: trunk/Source/WebKit/ChangeLog (260945 => 260946)


--- trunk/Source/WebKit/ChangeLog	2020-04-30 12:57:00 UTC (rev 260945)
+++ trunk/Source/WebKit/ChangeLog	2020-04-30 12:58:53 UTC (rev 260946)
@@ -1,5 +1,26 @@
 2020-04-30  Carlos Garcia Campos  <[email protected]>
 
+        [GTK4][X11] Add support for rendering web view contents
+        https://bugs.webkit.org/show_bug.cgi?id=211189
+
+        Reviewed by Adrian Perez de Castro.
+
+        Use GdkDisplayX11::xevent signal instead of filtering events that is no longer available in GTK4. GdkVisual no
+        longer exists either, so we get the X visual from the PlatformDisplay.
+
+        * UIProcess/gtk/AcceleratedBackingStoreX11.cpp:
+        (WebKit::XDamageNotifier::add):
+        (WebKit::XDamageNotifier::remove):
+        (WebKit::XDamageNotifier::filterXDamageEvent):
+        (WebKit::AcceleratedBackingStoreX11::~AcceleratedBackingStoreX11):
+        (WebKit::AcceleratedBackingStoreX11::update):
+        (WebKit::AcceleratedBackingStoreX11::snapshot):
+        * WebProcess/WebPage/gtk/AcceleratedSurfaceX11.cpp:
+        (WebKit::AcceleratedSurfaceX11::AcceleratedSurfaceX11):
+        (WebKit::AcceleratedSurfaceX11::createPixmap):
+
+2020-04-30  Carlos Garcia Campos  <[email protected]>
+
         [GTK4] Add support click events
         https://bugs.webkit.org/show_bug.cgi?id=211175
 

Modified: trunk/Source/WebKit/UIProcess/gtk/AcceleratedBackingStoreX11.cpp (260945 => 260946)


--- trunk/Source/WebKit/UIProcess/gtk/AcceleratedBackingStoreX11.cpp	2020-04-30 12:57:00 UTC (rev 260945)
+++ trunk/Source/WebKit/UIProcess/gtk/AcceleratedBackingStoreX11.cpp	2020-04-30 12:58:53 UTC (rev 260946)
@@ -52,7 +52,6 @@
 static Optional<int> s_damageEventBase;
 static Optional<int> s_damageErrorBase;
 
-#if !USE(GTK4)
 class XDamageNotifier {
     WTF_MAKE_NONCOPYABLE(XDamageNotifier);
     friend NeverDestroyed<XDamageNotifier>;
@@ -65,8 +64,13 @@
 
     void add(Damage damage, WTF::Function<void()>&& notifyFunction)
     {
-        if (m_notifyFunctions.isEmpty())
+        if (m_notifyFunctions.isEmpty()) {
+#if USE(GTK4)
+            g_signal_connect(gdk_display_get_default(), "xevent", G_CALLBACK(filterXDamageEvent), this);
+#else
             gdk_window_add_filter(nullptr, reinterpret_cast<GdkFilterFunc>(&filterXDamageEvent), this);
+#endif
+        }
         m_notifyFunctions.add(damage, WTFMove(notifyFunction));
     }
 
@@ -73,13 +77,33 @@
     void remove(Damage damage)
     {
         m_notifyFunctions.remove(damage);
-        if (m_notifyFunctions.isEmpty())
+        if (m_notifyFunctions.isEmpty()) {
+#if USE(GTK4)
+            g_signal_handlers_disconnect_by_data(gdk_display_get_default(), this);
+#else
             gdk_window_remove_filter(nullptr, reinterpret_cast<GdkFilterFunc>(&filterXDamageEvent), this);
+#endif
+        }
     }
 
 private:
     XDamageNotifier() = default;
 
+#if USE(GTK4)
+    static gboolean filterXDamageEvent(GdkDisplay*, XEvent* xEvent, XDamageNotifier* notifier)
+    {
+        if (xEvent->type != s_damageEventBase.value() + XDamageNotify)
+            return GDK_EVENT_PROPAGATE;
+
+        auto* damageEvent = reinterpret_cast<XDamageNotifyEvent*>(xEvent);
+        if (notifier->notify(damageEvent->damage)) {
+            XDamageSubtract(xEvent->xany.display, damageEvent->damage, None, None);
+            return GDK_EVENT_STOP;
+        }
+
+        return GDK_EVENT_PROPAGATE;
+    }
+#else
     static GdkFilterReturn filterXDamageEvent(GdkXEvent* event, GdkEvent*, XDamageNotifier* notifier)
     {
         auto* xEvent = static_cast<XEvent*>(event);
@@ -94,6 +118,7 @@
 
         return GDK_FILTER_CONTINUE;
     }
+#endif
 
     bool notify(Damage damage) const
     {
@@ -107,7 +132,6 @@
 
     HashMap<Damage, WTF::Function<void()>> m_notifyFunctions;
 };
-#endif
 
 bool AcceleratedBackingStoreX11::checkRequirements()
 {
@@ -137,7 +161,6 @@
     if (!m_surface && !m_damage)
         return;
 
-#if !USE(GTK4)
     Display* display = downcast<PlatformDisplayX11>(PlatformDisplay::sharedDisplay()).native();
     XErrorTrapper trapper(display, XErrorTrapper::Policy::Crash, { BadDrawable, xDamageErrorCode(BadDamage) });
     if (m_damage) {
@@ -145,7 +168,6 @@
         m_damage.reset();
         XSync(display, False);
     }
-#endif
 }
 
 void AcceleratedBackingStoreX11::update(const LayerTreeContext& layerTreeContext)
@@ -157,7 +179,6 @@
     Display* display = downcast<PlatformDisplayX11>(PlatformDisplay::sharedDisplay()).native();
 
     if (m_surface) {
-#if !USE(GTK4)
         XErrorTrapper trapper(display, XErrorTrapper::Policy::Crash, { BadDrawable, xDamageErrorCode(BadDamage) });
         if (m_damage) {
             XDamageNotifier::singleton().remove(m_damage.get());
@@ -164,7 +185,6 @@
             m_damage.reset();
             XSync(display, False);
         }
-#endif
         m_surface = nullptr;
     }
 
@@ -178,13 +198,18 @@
     IntSize size = drawingArea->size();
     float deviceScaleFactor = m_webPage.deviceScaleFactor();
     size.scale(deviceScaleFactor);
-#if !USE(GTK4)
+
     XErrorTrapper trapper(display, XErrorTrapper::Policy::Crash, { BadDrawable, xDamageErrorCode(BadDamage) });
-    ASSERT(downcast<PlatformDisplayX11>(PlatformDisplay::sharedDisplay()).native() == GDK_DISPLAY_XDISPLAY(gdk_display_get_default()));
-    GdkVisual* visual = gdk_screen_get_rgba_visual(gdk_screen_get_default());
-    if (!visual)
-        visual = gdk_screen_get_system_visual(gdk_screen_get_default());
-    m_surface = adoptRef(cairo_xlib_surface_create(display, pixmap, GDK_VISUAL_XVISUAL(visual), size.width(), size.height()));
+    ASSERT(downcast<PlatformDisplayX11>(PlatformDisplay::sharedDisplay()).native() == gdk_x11_display_get_xdisplay(gdk_display_get_default()));
+#if USE(GTK4)
+    auto* visual = WK_XVISUAL(downcast<PlatformDisplayX11>(PlatformDisplay::sharedDisplay()));
+#else
+    GdkVisual* gdkVisual = gdk_screen_get_rgba_visual(gdk_screen_get_default());
+    if (!gdkVisual)
+        gdkVisual = gdk_screen_get_system_visual(gdk_screen_get_default());
+    auto* visual = GDK_VISUAL_XVISUAL(gdkVisual);
+#endif
+    m_surface = adoptRef(cairo_xlib_surface_create(display, pixmap, visual, size.width(), size.height()));
     cairoSurfaceSetDeviceScale(m_surface.get(), deviceScaleFactor, deviceScaleFactor);
     m_damage = XDamageCreate(display, pixmap, XDamageReportNonEmpty);
     XDamageNotifier::singleton().add(m_damage.get(), [this] {
@@ -192,13 +217,26 @@
             gtk_widget_queue_draw(m_webPage.viewWidget());
     });
     XSync(display, False);
-#endif
 }
 
 #if USE(GTK4)
-void AcceleratedBackingStoreX11::snapshot(GtkSnapshot*)
+void AcceleratedBackingStoreX11::snapshot(GtkSnapshot* gtkSnapshot)
 {
-    // FIXME: Implement this.
+    if (!m_surface)
+        return;
+
+    // The surface can be modified by the web process at any time, so we mark it
+    // as dirty to ensure we always render the updated contents as soon as possible.
+    cairo_surface_mark_dirty(m_surface.get());
+
+    FloatSize viewSize(gtk_widget_get_width(m_webPage.viewWidget()), gtk_widget_get_height(m_webPage.viewWidget()));
+    graphene_rect_t rect = GRAPHENE_RECT_INIT(0, 0, viewSize.width(), viewSize.height());
+    RefPtr<cairo_t> cr = adoptRef(gtk_snapshot_append_cairo(gtkSnapshot, &rect));
+    cairo_set_source_surface(cr.get(), m_surface.get(), 0, 0);
+    cairo_set_operator(cr.get(), CAIRO_OPERATOR_OVER);
+    cairo_paint(cr.get());
+
+    cairo_surface_flush(m_surface.get());
 }
 #else
 bool AcceleratedBackingStoreX11::paint(cairo_t* cr, const IntRect& clipRect)

Modified: trunk/Source/WebKit/WebProcess/WebPage/gtk/AcceleratedSurfaceX11.cpp (260945 => 260946)


--- trunk/Source/WebKit/WebProcess/WebPage/gtk/AcceleratedSurfaceX11.cpp	2020-04-30 12:57:00 UTC (rev 260945)
+++ trunk/Source/WebKit/WebProcess/WebPage/gtk/AcceleratedSurfaceX11.cpp	2020-04-30 12:58:53 UTC (rev 260946)
@@ -64,14 +64,19 @@
     : AcceleratedSurface(webPage, client)
     , m_display(downcast<PlatformDisplayX11>(PlatformDisplay::sharedDisplay()).native())
 {
-#if !USE(GTK4)
     Screen* screen = DefaultScreenOfDisplay(m_display);
 
     ASSERT(downcast<PlatformDisplayX11>(PlatformDisplay::sharedDisplay()).native() == m_display);
 
-    GdkVisual* visual = defaultVisual();
-    XUniqueColormap colormap(XCreateColormap(m_display, RootWindowOfScreen(screen), GDK_VISUAL_XVISUAL(visual), AllocNone));
+#if USE(GTK4)
+    auto* visual = WK_XVISUAL(downcast<PlatformDisplayX11>(PlatformDisplay::sharedDisplay()));
+#else
+    auto* visual = GDK_VISUAL_XVISUAL(defaultVisual());
+#endif
+    XUniqueColormap colormap(XCreateColormap(m_display, RootWindowOfScreen(screen), visual, AllocNone));
 
+    int depth = visual == screen->root_visual ? screen->root_depth : 32;
+
     XSetWindowAttributes windowAttributes;
     windowAttributes.override_redirect = True;
     windowAttributes.colormap = colormap.get();
@@ -84,9 +89,9 @@
         RootWindowOfScreen(screen),
         -1, -1, 1, 1,
         0,
-        gdk_visual_get_depth(visual),
+        depth,
         InputOutput,
-        GDK_VISUAL_XVISUAL(visual),
+        visual,
         CWOverrideRedirect | CWColormap | CWBorderPixel,
         &windowAttributes);
     XMapWindow(m_display, m_parentWindow.get());
@@ -117,7 +122,6 @@
     XSelectInput(m_display, m_window.get(), NoEventMask);
     XCompositeRedirectWindow(m_display, m_window.get(), CompositeRedirectManual);
     createPixmap();
-#endif
 }
 
 AcceleratedSurfaceX11::~AcceleratedSurfaceX11()
@@ -133,14 +137,17 @@
 
 void AcceleratedSurfaceX11::createPixmap()
 {
-#if !USE(GTK4)
     m_pixmap = XCompositeNameWindowPixmap(m_display, m_window.get());
-    RefPtr<cairo_surface_t> surface = adoptRef(cairo_xlib_surface_create(m_display, m_pixmap.get(), GDK_VISUAL_XVISUAL(defaultVisual()), m_size.width(), m_size.height()));
+#if USE(GTK4)
+    auto* visual = WK_XVISUAL(downcast<PlatformDisplayX11>(PlatformDisplay::sharedDisplay()));
+#else
+    auto* visual = GDK_VISUAL_XVISUAL(defaultVisual());
+#endif
+    RefPtr<cairo_surface_t> surface = adoptRef(cairo_xlib_surface_create(m_display, m_pixmap.get(), visual, m_size.width(), m_size.height()));
     RefPtr<cairo_t> cr = adoptRef(cairo_create(surface.get()));
     cairo_set_operator(cr.get(), CAIRO_OPERATOR_CLEAR);
     cairo_paint(cr.get());
     XSync(m_display, False);
-#endif
 }
 
 bool AcceleratedSurfaceX11::hostResize(const IntSize& size)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to