Title: [206425] releases/WebKitGTK/webkit-2.14/Source/WebKit2
Revision
206425
Author
g...@gnome.org
Date
2016-09-27 02:10:30 -0700 (Tue, 27 Sep 2016)

Log Message

Merge 206424 - [GTK] Should check whether GDK can use GL before asking it to
https://bugs.webkit.org/show_bug.cgi?id=162598

Reviewed by Michael Catanzaro.

gdk_cairo_draw_from_gl can fail even when WebKit itself has been able to use GL (its
context creation code might be buggy, GL may have been disabled using GDK_GL=disable, …).
Unfortunately it does not have any error reporting other than a warning printed to
stderr, so we cannot fallback from it. We have to first check if GL can be used by GDK
by trying to create a context.

See https://bugzilla.redhat.com/show_bug.cgi?id=1378987

* UIProcess/gtk/AcceleratedBackingStoreWayland.cpp:
(WebKit::AcceleratedBackingStoreWayland::canGdkUseGL): decide whether GDK can use GL by
trying to create a context for a GdkWindow.
(WebKit::AcceleratedBackingStoreWayland::paint): fallback to glReadPixels if GDK cannot
use GL.
* UIProcess/gtk/AcceleratedBackingStoreWayland.h:

Modified Paths

Diff

Modified: releases/WebKitGTK/webkit-2.14/Source/WebKit2/ChangeLog (206424 => 206425)


--- releases/WebKitGTK/webkit-2.14/Source/WebKit2/ChangeLog	2016-09-27 09:06:41 UTC (rev 206424)
+++ releases/WebKitGTK/webkit-2.14/Source/WebKit2/ChangeLog	2016-09-27 09:10:30 UTC (rev 206425)
@@ -1,3 +1,25 @@
+2016-09-27  Gustavo Noronha Silva  <gustavo.noro...@collabora.co.uk>
+
+        [GTK] Should check whether GDK can use GL before asking it to
+        https://bugs.webkit.org/show_bug.cgi?id=162598
+
+        Reviewed by Michael Catanzaro.
+
+        gdk_cairo_draw_from_gl can fail even when WebKit itself has been able to use GL (its
+        context creation code might be buggy, GL may have been disabled using GDK_GL=disable, …).
+        Unfortunately it does not have any error reporting other than a warning printed to
+        stderr, so we cannot fallback from it. We have to first check if GL can be used by GDK
+        by trying to create a context.
+
+        See https://bugzilla.redhat.com/show_bug.cgi?id=1378987
+
+        * UIProcess/gtk/AcceleratedBackingStoreWayland.cpp:
+        (WebKit::AcceleratedBackingStoreWayland::canGdkUseGL): decide whether GDK can use GL by
+        trying to create a context for a GdkWindow.
+        (WebKit::AcceleratedBackingStoreWayland::paint): fallback to glReadPixels if GDK cannot
+        use GL.
+        * UIProcess/gtk/AcceleratedBackingStoreWayland.h:
+
 2016-09-21  Gustavo Noronha Silva  <gustavo.noro...@collabora.co.uk>
 
         Unreviewed, build fix.

Modified: releases/WebKitGTK/webkit-2.14/Source/WebKit2/UIProcess/gtk/AcceleratedBackingStoreWayland.cpp (206424 => 206425)


--- releases/WebKitGTK/webkit-2.14/Source/WebKit2/UIProcess/gtk/AcceleratedBackingStoreWayland.cpp	2016-09-27 09:06:41 UTC (rev 206424)
+++ releases/WebKitGTK/webkit-2.14/Source/WebKit2/UIProcess/gtk/AcceleratedBackingStoreWayland.cpp	2016-09-27 09:10:30 UTC (rev 206425)
@@ -61,6 +61,31 @@
     WaylandCompositor::singleton().unregisterWebPage(m_webPage);
 }
 
+#if GTK_CHECK_VERSION(3, 16, 0)
+bool AcceleratedBackingStoreWayland::canGdkUseGL() const
+{
+    static bool initialized = false;
+    static bool canCreateGLContext = false;
+
+    if (initialized)
+        return canCreateGLContext;
+
+    initialized = true;
+
+    GUniqueOutPtr<GError> error;
+    GdkWindow* gdkWindow = gtk_widget_get_window(m_webPage.viewWidget());
+    GRefPtr<GdkGLContext> gdkContext(gdk_window_create_gl_context(gdkWindow, &error.outPtr()));
+    if (!gdkContext) {
+        g_warning("GDK is not able to create a GL context, falling back to glReadPixels (slow!): %s", error->message);
+        return false;
+    }
+
+    canCreateGLContext = true;
+
+    return true;
+}
+#endif
+
 bool AcceleratedBackingStoreWayland::paint(cairo_t* cr, const IntRect& clipRect)
 {
     GLuint texture;
@@ -72,8 +97,13 @@
     AcceleratedBackingStore::paint(cr, clipRect);
 
 #if GTK_CHECK_VERSION(3, 16, 0)
-    gdk_cairo_draw_from_gl(cr, gtk_widget_get_window(m_webPage.viewWidget()), texture, GL_TEXTURE, m_webPage.deviceScaleFactor(), 0, 0, textureSize.width(), textureSize.height());
-#else
+    if (canGdkUseGL()) {
+        gdk_cairo_draw_from_gl(cr, gtk_widget_get_window(m_webPage.viewWidget()), texture, GL_TEXTURE, m_webPage.deviceScaleFactor(), 0, 0, textureSize.width(), textureSize.height());
+        cairo_restore(cr);
+        return true;
+    }
+#endif
+
     if (!m_surface || cairo_image_surface_get_width(m_surface.get()) != textureSize.width() || cairo_image_surface_get_height(m_surface.get()) != textureSize.height())
         m_surface = adoptRef(cairo_image_surface_create(CAIRO_FORMAT_ARGB32, textureSize.width(), textureSize.height()));
 
@@ -124,7 +154,6 @@
     cairo_set_source_surface(cr, m_surface.get(), 0, 0);
     cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
     cairo_fill(cr);
-#endif
 
     cairo_restore(cr);
 

Modified: releases/WebKitGTK/webkit-2.14/Source/WebKit2/UIProcess/gtk/AcceleratedBackingStoreWayland.h (206424 => 206425)


--- releases/WebKitGTK/webkit-2.14/Source/WebKit2/UIProcess/gtk/AcceleratedBackingStoreWayland.h	2016-09-27 09:06:41 UTC (rev 206424)
+++ releases/WebKitGTK/webkit-2.14/Source/WebKit2/UIProcess/gtk/AcceleratedBackingStoreWayland.h	2016-09-27 09:10:30 UTC (rev 206425)
@@ -30,6 +30,7 @@
 #if PLATFORM(WAYLAND)
 
 #include <WebCore/RefPtrCairo.h>
+#include <gtk/gtk.h>
 
 namespace WebKit {
 
@@ -41,6 +42,10 @@
     static std::unique_ptr<AcceleratedBackingStoreWayland> create(WebPageProxy&);
     ~AcceleratedBackingStoreWayland();
 
+#if GTK_CHECK_VERSION(3, 16, 0)
+    bool canGdkUseGL() const;
+#endif
+
 private:
     AcceleratedBackingStoreWayland(WebPageProxy&);
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to