[webkit-changes] [WebKit/WebKit] 75ce30: [visionOS] Web process hangs under createDragImage...

Wenson Hsieh noreply at github.com
Mon Feb 3 10:17:27 PST 2025


  Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 75ce30b7aa9189dbf22f9fee5ae9d0a581e0dd84
      https://github.com/WebKit/WebKit/commit/75ce30b7aa9189dbf22f9fee5ae9d0a581e0dd84
  Author: Wenson Hsieh <wenson_hsieh at apple.com>
  Date:   2025-02-03 (Mon, 03 Feb 2025)

  Changed paths:
    M Source/WebCore/dom/DataTransfer.cpp
    M Source/WebCore/dom/DataTransfer.h
    M Source/WebCore/dom/DataTransferMac.mm
    M Source/WebCore/page/DragController.cpp
    M Source/WebCore/platform/DragImage.cpp
    M Source/WebCore/platform/DragImage.h
    M Source/WebCore/platform/cocoa/DragImageCocoa.mm
    M Source/WebCore/platform/gtk/DragImageGtk.cpp
    M Source/WebCore/platform/ios/DragImageIOS.mm
    M Source/WebCore/platform/win/DragImageWin.cpp
    M Source/WebCore/platform/win/cairo/DragImageWinCairo.cpp

  Log Message:
  -----------
  [visionOS] Web process hangs under createDragImageFor{Link|Selection} when starting a drag for the first time
https://bugs.webkit.org/show_bug.cgi?id=286819
rdar://141448897

Reviewed by Abrar Rahman Protyasha.

On visionOS, when starting a drag for the first time on a webpage, we end up spending a large amount
of time underneath `+[UIScreen initialize]` within the web process, while trying to render the drag
image using the helpers in `DragImageIOS.mm` (which instantiate `UIGraphicsImageRenderer`). This
causes the web process to hang briefly, which in turn may cause the drag to fail entirely.

To mitigate this, we refactor these helpers such that they no longer rely (indirectly) on
instantiating `UIScreen` via `UIGraphicsImageRenderer`, and instead use `WebCore::ImageBuffer` and
`sinkIntoNativeImage`. See below for more details.

* Source/WebCore/dom/DataTransfer.cpp:
(WebCore::DataTransfer::setDragImage):
(WebCore::DataTransfer::updateDragImage):
(WebCore::DataTransfer::createDragImage const):
(WebCore::DragImageLoader::DragImageLoader):
(WebCore::DragImageLoader::imageChanged):
* Source/WebCore/dom/DataTransfer.h:
* Source/WebCore/dom/DataTransferMac.mm:
(WebCore::DataTransfer::createDragImage const):

Plumb the `Document` through here, so that we can get the `deviceScaleFactor` / `HostWindow` and
pass them through to `createDragImageFromImage`.

* Source/WebCore/page/DragController.cpp:
(WebCore::DragController::startDrag):
(WebCore::DragController::doImageDrag):

Pass the device scale factor and host window into `createDragImageFromImage`.

* Source/WebCore/platform/DragImage.cpp:
(WebCore::createDragImageFromImage):
* Source/WebCore/platform/DragImage.h:
* Source/WebCore/platform/cocoa/DragImageCocoa.mm:
(WebCore::createDragImageFromImage):
* Source/WebCore/platform/gtk/DragImageGtk.cpp:
(WebCore::createDragImageFromImage):
* Source/WebCore/platform/ios/DragImageIOS.mm:
(WebCore::scaleDragImage):

Make this helper function a no-op. This logic was actually unnecessary from the start, since the
drag image will always perform lift and cancel animations using targeted previews which scale to fit
the bounds of the dragged element. As such, there's no need to artificially clamp the drag image to
an arbitrary maximum size of 400x400.

(WebCore::createDragImageFromImage):

Make this take both a device scale factor and `HostWindow`, which allows us to create a new
`ImageBuffer`, paint the given image into the buffer (scaling down if needed), and finally extract
a native image from the image buffer. This avoids the need for `UIGraphicsImageRenderer` entirely.

(WebCore::deleteDragImage):
(WebCore::cgImageFromTextIndicator):
(WebCore::createDragImageForLink):

Remove logic for creating a drag image representing a link (URL) platter. This has been unnecessary
ever since we (1) adopted `+[UIDragPreview previewForURL:title:]`, and (2) use text indicator for
the lift preview. Instead, just return the content image of the text indicator here.

(WebCore::createDragImageForSelection):

Adjust these helper methods, so that they simply return the content image of the text indicator.
Note that we just use the text indicator itself for the targeted preview anyways, so this image is
effectively unused. In a future patch, we should refactor `DragController` to not bail if the drag
image's `image` is `nullptr` (but the `DragImage` is instead backed by a `TextIndicator`), which
would allow us to avoid some of this extra work.

(WebCore::cascadeForSystemFont): Deleted.
* Source/WebCore/platform/win/DragImageWin.cpp:
(WebCore::createDragImageFromImage):
* Source/WebCore/platform/win/cairo/DragImageWinCairo.cpp:
(WebCore::createDragImageFromImage):

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



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


More information about the webkit-changes mailing list