From 1853a763ab9961b63d400a20f9f04f64eb2bf184 Mon Sep 17 00:00:00 2001 From: Patrick Griffis Date: Mon, 4 Mar 2024 17:33:44 -0800 Subject: [PATCH] [Skia] Fix support for custom cursors https://bugs.webkit.org/show_bug.cgi?id=270389 Reviewed by Carlos Garcia Campos. * Source/WebCore/platform/graphics/skia/ShareableBitmapSkia.cpp: (WebCore::ShareableBitmap::createImage): * Source/WebKit/UIProcess/API/wpe/WPEWebView.cpp: (WKWPE::View::setCursor): Canonical link: https://commits.webkit.org/275665@main --- .../graphics/skia/ShareableBitmapSkia.cpp | 17 +++++++++----- .../WebKit/UIProcess/API/wpe/WPEWebView.cpp | 22 ++++++++++++++++++- 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/Source/WebCore/platform/graphics/skia/ShareableBitmapSkia.cpp b/Source/WebCore/platform/graphics/skia/ShareableBitmapSkia.cpp index d897a1d80169..d6dc8f05ddbe 100644 --- a/Source/WebCore/platform/graphics/skia/ShareableBitmapSkia.cpp +++ b/Source/WebCore/platform/graphics/skia/ShareableBitmapSkia.cpp @@ -69,14 +69,21 @@ void ShareableBitmap::paint(GraphicsContext&, float /*scaleFactor*/, const IntPo RefPtr ShareableBitmap::createImage() { - notImplemented(); - return nullptr; + return BitmapImage::create(createPlatformImage(BackingStoreCopy::DontCopyBackingStore)); } -PlatformImagePtr ShareableBitmap::createPlatformImage(BackingStoreCopy, ShouldInterpolate) +PlatformImagePtr ShareableBitmap::createPlatformImage(BackingStoreCopy backingStoreCopy, ShouldInterpolate) { - notImplemented(); - return nullptr; + sk_sp pixelData; + if (backingStoreCopy == BackingStoreCopy::CopyBackingStore) + pixelData = SkData::MakeWithCopy(data(), sizeInBytes()); + else { + ref(); + pixelData = SkData::MakeWithProc(data(), sizeInBytes(), [](const void*, void* bitmap) -> void { + static_cast(bitmap)->deref(); + }, this); + } + return SkImages::RasterFromData(m_configuration.imageInfo(), pixelData, bytesPerRow()); } void ShareableBitmap::setOwnershipOfMemory(const ProcessIdentity&) diff --git a/Source/WebKit/UIProcess/API/wpe/WPEWebView.cpp b/Source/WebKit/UIProcess/API/wpe/WPEWebView.cpp index 7963c80c3455..9a682ff7309e 100644 --- a/Source/WebKit/UIProcess/API/wpe/WPEWebView.cpp +++ b/Source/WebKit/UIProcess/API/wpe/WPEWebView.cpp @@ -53,6 +53,12 @@ #include #endif +#if USE(SKIA) +IGNORE_CLANG_WARNINGS_BEGIN("cast-align") +#include +IGNORE_CLANG_WARNINGS_END +#endif + #if ENABLE(WPE_PLATFORM) #include "ScreenManager.h" #include @@ -952,7 +958,21 @@ void View::setCursor(const WebCore::Cursor& cursor) WebCore::IntPoint hotspot = WebCore::determineHotSpot(image.get(), cursor.hotSpot()); wpe_view_set_cursor_from_bytes(m_wpeView.get(), bytes.get(), width, height, stride, hotspot.x(), hotspot.y()); #elif USE(SKIA) - // FIXME: implement. + auto nativeImage = cursor.image()->nativeImageForCurrentFrame(); + if (!nativeImage) + return; + + SkPixmap pixmap; + auto platformImage = nativeImage->platformImage(); + ASSERT(platformImage->peekPixels(&pixmap)); + + platformImage->ref(); + GRefPtr bytes = adoptGRef(g_bytes_new_with_free_func(pixmap.addr(), pixmap.computeByteSize(), [](gpointer data) { + static_cast(data)->unref(); + }, platformImage.get())); + + WebCore::IntPoint hotspot = WebCore::determineHotSpot(cursor.image().get(), cursor.hotSpot()); + wpe_view_set_cursor_from_bytes(m_wpeView.get(), bytes.get(), pixmap.width(), pixmap.height(), pixmap.rowBytes(), hotspot.x(), hotspot.y()); #endif #else UNUSED_PARAM(cursor);