Skip to content

Commit

Permalink
[Skia] Fix support for custom cursors
Browse files Browse the repository at this point in the history
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
  • Loading branch information
TingPing committed Mar 5, 2024
1 parent 5612088 commit 1853a76
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 6 deletions.
17 changes: 12 additions & 5 deletions Source/WebCore/platform/graphics/skia/ShareableBitmapSkia.cpp
Expand Up @@ -69,14 +69,21 @@ void ShareableBitmap::paint(GraphicsContext&, float /*scaleFactor*/, const IntPo

RefPtr<Image> 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<SkData> pixelData;
if (backingStoreCopy == BackingStoreCopy::CopyBackingStore)
pixelData = SkData::MakeWithCopy(data(), sizeInBytes());
else {
ref();
pixelData = SkData::MakeWithProc(data(), sizeInBytes(), [](const void*, void* bitmap) -> void {
static_cast<ShareableBitmap*>(bitmap)->deref();
}, this);
}
return SkImages::RasterFromData(m_configuration.imageInfo(), pixelData, bytesPerRow());
}

void ShareableBitmap::setOwnershipOfMemory(const ProcessIdentity&)
Expand Down
22 changes: 21 additions & 1 deletion Source/WebKit/UIProcess/API/wpe/WPEWebView.cpp
Expand Up @@ -53,6 +53,12 @@
#include <cairo.h>
#endif

#if USE(SKIA)
IGNORE_CLANG_WARNINGS_BEGIN("cast-align")
#include <skia/core/SkPixmap.h>
IGNORE_CLANG_WARNINGS_END
#endif

#if ENABLE(WPE_PLATFORM)
#include "ScreenManager.h"
#include <wpe/wpe-platform.h>
Expand Down Expand Up @@ -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<GBytes> bytes = adoptGRef(g_bytes_new_with_free_func(pixmap.addr(), pixmap.computeByteSize(), [](gpointer data) {
static_cast<SkImage*>(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);
Expand Down

0 comments on commit 1853a76

Please sign in to comment.