Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 4897d5f7c57466f265cb84bf27b7bb0578df6f31
      
https://github.com/WebKit/WebKit/commit/4897d5f7c57466f265cb84bf27b7bb0578df6f31
  Author: Timothy Hatcher <[email protected]>
  Date:   2026-07-21 (Tue, 21 Jul 2026)

  Changed paths:
    M Source/WebCore/Headers.cmake
    M Source/WebCore/WebCore.xcodeproj/project.pbxproj
    M Source/WebCore/bindings/scripts/CodeGeneratorJS.pm
    M Source/WebCore/html/CanvasBase.h
    M Source/WebCore/html/HTMLPictureElement.h
    M Source/WebCore/html/ImageData.h
    M Source/WebCore/html/OffscreenCanvas.idl
    M Source/WebKit/WebProcess/WebPage/WebFrame.cpp
    M Source/WebKit/WebProcess/WebPage/WebFrame.h
    M Source/WebKit/WebProcess/WebPage/WebPage.cpp
    M Source/WebKit/WebProcess/WebPage/WebPage.h
    M Tools/TestWebKitAPI/Resources/cocoa/node-snapshotting.html
    M Tools/TestWebKitAPI/Tests/WebKit/WKWebView/WKWebViewSnapshot.mm

  Log Message:
  -----------
  WKWebView._takeSnapshotOfNode() should support ImageData and OffscreenCanvas.
https://webkit.org/b/319859
rdar://problem/182757589

Reviewed by Wenson Hsieh.

WKWebView._takeSnapshotOfNode() required the node to have a renderer and only 
accepted DOM nodes, so it couldn't
capture an off-screen or not-yet-painted image, nor an image source that isn't 
a node at all.

Snapshot the node, falling back to its own pixels when it has no renderer, and 
accept ImageData and
OffscreenCanvas handles by rasterizing them directly.

Test: Tools/TestWebKitAPI/Tests/WebKit/WKWebView/WKWebViewSnapshot.mm

* Source/WebCore/WebCore.xcodeproj/project.pbxproj: Export JSImageData.h and 
JSOffscreenCanvas.h as private
headers so WebKit can resolve those JS wrappers.
* Source/WebCore/html/CanvasBase.h: Export makeRenderingResultsAvailable() for 
reading a canvas backing store.
* Source/WebCore/html/OffscreenCanvas.idl: Export the generated bindings 
(ExportMacro) so WebKit can call
JSOffscreenCanvas::toWrapped().
* Source/WebKit/WebProcess/WebPage/WebFrame.cpp:
(WebKit::imageDataFromJSHandleIdentifier): Resolve a JS handle to an ImageData.
(WebKit::offscreenCanvasFromJSHandleIdentifier): Resolve a JS handle to an 
OffscreenCanvas.
(WebKit::shareableBitmapFromImageBuffer): Rasterize an ImageBuffer into a 
ShareableBitmap.
(WebKit::WebFrame::shareableBitmapFromImageData): Rasterize an ImageData's 
pixels into a ShareableBitmap.
(WebKit::WebFrame::shareableBitmapFromOffscreenCanvas): Rasterize an 
OffscreenCanvas's backing store into a
ShareableBitmap.
(WebKit::WebFrame::takeSnapshotOfNode): Resolve the handle to a node, 
ImageData, or OffscreenCanvas and build
a bitmap for each.
* Source/WebKit/WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::shareableBitmapForNodeIncludingOffscreen): Snapshot a node, 
falling back to an <img>'s
decoded data or a <canvas>'s backing store when it has no renderer; a <picture> 
resolves to its <img>.
* Source/WebKit/WebProcess/WebPage/WebPage.h: Declare 
shareableBitmapForNodeIncludingOffscreen.
* Tools/TestWebKitAPI/Resources/cocoa/node-snapshotting.html: Add an on-screen 
and off-screen canvas, an
off-screen image, and a picture for the new tests.
* Tools/TestWebKitAPI/Tests/WebKit/WKWebView/WKWebViewSnapshot.mm:
(TestWebKitAPI::TEST(WKWebView, SnapshotNodeByJSHandle)): Cover ImageData and 
OffscreenCanvas handles.
(TestWebKitAPI::TEST(WKWebView, SnapshotNodeIncludingOffscreen)): Added.

Canonical link: https://commits.webkit.org/317621@main



To unsubscribe from these emails, change your notification settings at 
https://github.com/WebKit/WebKit/settings/notifications

Reply via email to