Skip to content

Commit

Permalink
[Skia] Fix support for custom cursors with GTK
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=271613

Reviewed by Adrian Perez de Castro.

* Source/WebCore/platform/graphics/gtk/GdkSkiaUtilities.cpp:
(WebCore::skiaImageToGdkPixbuf):
* Source/WebCore/platform/graphics/gtk/GdkSkiaUtilities.h:
* Source/WebCore/platform/graphics/gtk/ImageAdapterGtk.cpp:
(WebCore::ImageAdapter::gdkPixbuf):
(WebCore::ImageAdapter::gdkTexture):
* Source/WebCore/platform/gtk/CursorGtk.cpp:
(WebCore::createCustomCursor):

destroy notify was not being called.

* Source/WebCore/platform/graphics/skia/GraphicsContextSkia.cpp:
(WebCore::GraphicsContextSkia::~GraphicsContextSkia):

Canonical link: https://commits.webkit.org/276737@main
  • Loading branch information
TingPing committed Mar 27, 2024
1 parent 5209f3c commit ee489d2
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 22 deletions.
17 changes: 17 additions & 0 deletions Source/WebCore/platform/graphics/gtk/GdkSkiaUtilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,23 @@ RefPtr<cairo_surface_t> skiaImageToCairoSurface(SkImage& image)
}
#endif

GRefPtr<GdkPixbuf> skiaImageToGdkPixbuf(SkImage& image)
{
#if USE(GTK4)
auto texture = skiaImageToGdkTexture(image);
if (!texture)
return { };

return adoptGRef(gdk_pixbuf_get_from_texture(texture.get()));
#else
RefPtr surface = skiaImageToCairoSurface(image);
if (!surface)
return { };

return adoptGRef(gdk_pixbuf_get_from_surface(surface.get(), 0, 0, cairo_image_surface_get_width(surface.get()), cairo_image_surface_get_height(surface.get())));
#endif
}

} // namespace WebCore

#endif // #if USE(SKIA)
7 changes: 4 additions & 3 deletions Source/WebCore/platform/graphics/gtk/GdkSkiaUtilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,11 @@

#if USE(SKIA)

#include <gdk/gdk.h>
#include <skia/core/SkImage.h>
#include <wtf/glib/GRefPtr.h>

#if USE(GTK4)
#include <gdk/gdk.h>
#else
#if !USE(GTK4)
#include <cairo.h>
#endif

Expand All @@ -44,6 +43,8 @@ GRefPtr<GdkTexture> skiaImageToGdkTexture(SkImage&);
RefPtr<cairo_surface_t> skiaImageToCairoSurface(SkImage&);
#endif

GRefPtr<GdkPixbuf> skiaImageToGdkPixbuf(SkImage&);

}

#endif // USE(SKIA)
12 changes: 5 additions & 7 deletions Source/WebCore/platform/graphics/gtk/ImageAdapterGtk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

#include "BitmapImage.h"
#include "GdkCairoUtilities.h"
#include "NotImplemented.h"
#include "GdkSkiaUtilities.h"
#include "SharedBuffer.h"
#include <cairo.h>
#include <gdk/gdk.h>
Expand Down Expand Up @@ -61,12 +61,11 @@ GRefPtr<GdkPixbuf> ImageAdapter::gdkPixbuf()
if (!nativeImage)
return nullptr;

#if USE(CAIRO)
auto& surface = nativeImage->platformImage();
#if USE(CAIRO)
return cairoSurfaceToGdkPixbuf(surface.get());
#elif USE(SKIA)
notImplemented();
return nullptr;
return skiaImageToGdkPixbuf(*surface.get());
#endif
}

Expand All @@ -77,12 +76,11 @@ GRefPtr<GdkTexture> ImageAdapter::gdkTexture()
if (!nativeImage)
return nullptr;

#if USE(CAIRO)
auto& surface = nativeImage->platformImage();
#if USE(CAIRO)
return cairoSurfaceToGdkTexture(surface.get());
#elif USE(SKIA)
notImplemented();
return nullptr;
return skiaImageToGdkTexture(*surface.get());
#endif
}
#endif
Expand Down
7 changes: 5 additions & 2 deletions Source/WebCore/platform/graphics/skia/GraphicsContextSkia.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,11 @@ GraphicsContextSkia::GraphicsContextSkia(SkCanvas& canvas, RenderingMode renderi
{
}

GraphicsContextSkia::~GraphicsContextSkia() = default;

GraphicsContextSkia::~GraphicsContextSkia()
{
if (m_destroyNotify)
m_destroyNotify();
}

bool GraphicsContextSkia::hasPlatformContext() const
{
Expand Down
13 changes: 3 additions & 10 deletions Source/WebCore/platform/gtk/CursorGtk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,12 @@ static GRefPtr<GdkCursor> createCustomCursor(Image* image, const IntPoint& hotSp
IntPoint effectiveHotSpot = determineHotSpot(image, hotSpot);
return adoptGRef(gdk_cursor_new_from_texture(texture.get(), effectiveHotSpot.x(), effectiveHotSpot.y(), fallbackCursor().get()));
#else
auto nativeImage = image->nativeImageForCurrentFrame();
if (!nativeImage)
auto pixbuf = image->adapter().gdkPixbuf();
if (!pixbuf)
return nullptr;

#if USE(CAIRO)
auto& surface = nativeImage->platformImage();
IntPoint effectiveHotSpot = determineHotSpot(image, hotSpot);
return adoptGRef(gdk_cursor_new_from_surface(gdk_display_get_default(), surface.get(), effectiveHotSpot.x(), effectiveHotSpot.y()));
#elif USE(SKIA)
UNUSED_PARAM(hotSpot);
notImplemented();
return nullptr;
#endif
return adoptGRef(gdk_cursor_new_from_pixbuf(gdk_display_get_default(), pixbuf.get(), effectiveHotSpot.x(), effectiveHotSpot.y()));
#endif // USE(GTK4)
}

Expand Down

0 comments on commit ee489d2

Please sign in to comment.