[webkit-changes] [WebKit/WebKit] 98c763: [UnifiedPDF] Introduce AsyncPDFRenderer

Simon Fraser noreply at github.com
Wed Feb 14 13:57:16 PST 2024


  Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 98c763e246170ff480978642d91f27ff6bff79e8
      https://github.com/WebKit/WebKit/commit/98c763e246170ff480978642d91f27ff6bff79e8
  Author: Simon Fraser <simon.fraser at apple.com>
  Date:   2024-02-14 (Wed, 14 Feb 2024)

  Changed paths:
    M Source/WebKit/Platform/Logging.h
    M Source/WebKit/SourcesCocoa.txt
    M Source/WebKit/WebKit.xcodeproj/project.pbxproj
    M Source/WebKit/WebProcess/Plugins/PDF/PDFPluginBase.h
    A Source/WebKit/WebProcess/Plugins/PDF/UnifiedPDF/AsyncPDFRenderer.h
    A Source/WebKit/WebProcess/Plugins/PDF/UnifiedPDF/AsyncPDFRenderer.mm
    M Source/WebKit/WebProcess/Plugins/PDF/UnifiedPDF/UnifiedPDFPlugin.h

  Log Message:
  -----------
  [UnifiedPDF] Introduce AsyncPDFRenderer
https://bugs.webkit.org/show_bug.cgi?id=269368
rdar://122950491

Reviewed by Tim Horton.

This is the first step to rendering PDF content off the main thread.

AsyncPDFRenderer is a TiledBackingClient, so gets notified when the TileBacking needs
to repaint a tile. This causes it to enqueue a request to render a tile (identified by
a grid index/tile index pair in `TileForGrid`) on a workqueue (currently serial, but likely
concurrent in future). The tile rendering request includes a `PDFPageCoverage`, which
describes the set of PDF pages and their geometry which will go into this tile.

Rendering a tile on the work queue involves allocating an in-process ImageBuffer, calling
PDFDocument for the PDFPages for this tile, and drawing them (without selection). That
ImageBuffer is then transferred back to the main thread, and put into a cache, again
keyed by `TileForGrid`.

When a tile render is complete, we need to trigger a repaint so we can paint the tile
in the normal painting code path. There's a little trickiness to avoid continual repaints,
which is handled by `AsyncPDFRenderer::willRepaintTile()`.

* Source/WebKit/Platform/Logging.h:
* Source/WebKit/SourcesCocoa.txt:
* Source/WebKit/WebKit.xcodeproj/project.pbxproj:
* Source/WebKit/WebProcess/Plugins/PDF/PDFPluginBase.h:
(WebKit::PDFPluginBase::pdfDocument const):
* Source/WebKit/WebProcess/Plugins/PDF/UnifiedPDF/AsyncPDFRenderer.h: Added.
(WTF::TileForGridHash::hash):
(WTF::TileForGridHash::equal):
(WTF::HashTraits<WebKit::TileForGrid>::emptyValue):
(WTF::HashTraits<WebKit::TileForGrid>::deletedValue):
(WTF::HashTraits<WebKit::TileForGrid>::constructDeletedValue):
(WTF::HashTraits<WebKit::TileForGrid>::isDeletedValue):
(WebKit::AsyncPDFRenderer::paintingWorkQueue const):
* Source/WebKit/WebProcess/Plugins/PDF/UnifiedPDF/AsyncPDFRenderer.mm: Added.
(WebKit::AsyncPDFRenderer::create):
(WebKit::AsyncPDFRenderer::AsyncPDFRenderer):
(WebKit::AsyncPDFRenderer::~AsyncPDFRenderer):
(WebKit::AsyncPDFRenderer::setupWithLayer):
(WebKit::AsyncPDFRenderer::willRepaintTile):
(WebKit::AsyncPDFRenderer::willRemoveTile):
(WebKit::AsyncPDFRenderer::willRepaintAllTiles):
(WebKit::AsyncPDFRenderer::clearCachedTiles):
(WebKit::AsyncPDFRenderer::enqueuePaintWithClip):
(WebKit::AsyncPDFRenderer::paintTileOnWorkQueue):
(WebKit::AsyncPDFRenderer::paintPDFIntoBuffer):
(WebKit::AsyncPDFRenderer::transferBufferToMainThread):
(WebKit::AsyncPDFRenderer::paintTileForClip):
* Source/WebKit/WebProcess/Plugins/PDF/UnifiedPDF/UnifiedPDFPlugin.h:

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




More information about the webkit-changes mailing list