Title: [260123] trunk/Source/WebCore
Revision
260123
Author
[email protected]
Date
2020-04-15 06:08:25 -0700 (Wed, 15 Apr 2020)

Log Message

[GTK4] Adapt to cursor API changes
https://bugs.webkit.org/show_bug.cgi?id=210453

Reviewed by Carlos Garcia Campos.

No new tests needed.

* platform/gtk/CursorGtk.cpp:
(WebCore::fallbackCursor): Utility function which returns the "default" cursor for GTK4.
(WebCore::createNamedCursor): Adapt to the changes in the gdk_cursor_new_from_name().
(WebCore::createCustomCursor): Create a GdkTexture directly when the given Cairo surface is
in one of the pixel formats supported by gdk_memory_texture_new(), otherwise convert first;
then create a GdkCursor from the GdkTexture.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (260122 => 260123)


--- trunk/Source/WebCore/ChangeLog	2020-04-15 12:28:39 UTC (rev 260122)
+++ trunk/Source/WebCore/ChangeLog	2020-04-15 13:08:25 UTC (rev 260123)
@@ -1,3 +1,19 @@
+2020-04-15  Adrian Perez de Castro  <[email protected]>
+
+        [GTK4] Adapt to cursor API changes
+        https://bugs.webkit.org/show_bug.cgi?id=210453
+
+        Reviewed by Carlos Garcia Campos.
+
+        No new tests needed.
+
+        * platform/gtk/CursorGtk.cpp:
+        (WebCore::fallbackCursor): Utility function which returns the "default" cursor for GTK4.
+        (WebCore::createNamedCursor): Adapt to the changes in the gdk_cursor_new_from_name().
+        (WebCore::createCustomCursor): Create a GdkTexture directly when the given Cairo surface is
+        in one of the pixel formats supported by gdk_memory_texture_new(), otherwise convert first;
+        then create a GdkCursor from the GdkTexture.
+
 2020-04-14  Simon Fraser  <[email protected]>
 
         [Async overflow scroll] Backgrounds missing on gmail sometimes

Modified: trunk/Source/WebCore/platform/gtk/CursorGtk.cpp (260122 => 260123)


--- trunk/Source/WebCore/platform/gtk/CursorGtk.cpp	2020-04-15 12:28:39 UTC (rev 260122)
+++ trunk/Source/WebCore/platform/gtk/CursorGtk.cpp	2020-04-15 13:08:25 UTC (rev 260123)
@@ -32,12 +32,25 @@
 #include "Image.h"
 #include "IntPoint.h"
 #include <gdk/gdk.h>
+#include <wtf/NeverDestroyed.h>
 
 namespace WebCore {
 
+#if USE(GTK4)
+static GRefPtr<GdkCursor> fallbackCursor()
+{
+    static WTF::NeverDestroyed<GRefPtr<GdkCursor>> cursor(adoptGRef(gdk_cursor_new_from_name("default", nullptr)));
+    return cursor;
+}
+#endif // USE(GTK4)
+
 static GRefPtr<GdkCursor> createNamedCursor(const char* name)
 {
+#if USE(GTK4)
+    return adoptGRef(gdk_cursor_new_from_name(name, fallbackCursor().get()));
+#else
     return adoptGRef(gdk_cursor_new_from_name(gdk_display_get_default(), name));
+#endif // USE(GTK4)
 }
 
 static GRefPtr<GdkCursor> createCustomCursor(Image* image, const IntPoint& hotSpot)
@@ -47,7 +60,14 @@
         return nullptr;
 
     IntPoint effectiveHotSpot = determineHotSpot(image, hotSpot);
+
+#if USE(GTK4)
+    ASSERT(cairo_image_surface_get_format(surface.get()) == CAIRO_FORMAT_ARGB32);
+    auto texture = adoptGRef(gdk_memory_texture_new(cairo_image_surface_get_width(surface.get()), cairo_image_surface_get_height(surface.get()), GDK_MEMORY_A8R8G8B8_PREMULTIPLIED, cairo_image_surface_get_stride(surface.get())));
+    return adoptGRef(gdk_cursor_new_from_texture(texture.get(), effectiveHotSpot.x(), effectiveHotSpot.y(), fallbackCursor().get()));
+#else
     return adoptGRef(gdk_cursor_new_from_surface(gdk_display_get_default(), surface.get(), effectiveHotSpot.x(), effectiveHotSpot.y()));
+#endif // USE(GTK4)
 }
 
 void Cursor::ensurePlatformCursor() const
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to