Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Skia] Fix support for custom cursors with GTK #26388

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
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