Repository navigation
[Remote Snapshotting] Add GraphicsContextCGDelegate and use it for PDF content - #77390
Draft
szewai wants to merge 1 commit into
Conversation
Collaborator
|
EWS run on previous version of this PR (hash ac75594) Details
|
…F content https://bugs.webkit.org/show_bug.cgi?id=327949 rdar://190314999 Reviewed by NOBODY (OOPS!). With remote snapshotting, the web process records drawing into a GraphicsContext that has no CGContext, and the GPU process draws the recording. PDFKit can only draw a page into a CGContext, so UnifiedPDFPlugin::paintPDFContent() currently draws each page into a local bitmap and records that image. As a result, the PDF content in printed or PDF-snapshotted pages is rasterized: text can't be selected and the output is blurry when zoomed in. This patch adds GraphicsContextCGDelegate, a CGContextDelegate that translates the CoreGraphics drawing callbacks back into calls on a WebCore GraphicsContext. PDFKit draws into the CGContext that the delegate creates, and every drawing callback maps the CG gstate (CTM, clip stack, alpha, composite operation and blend mode, antialiasing, colors and line parameters) onto the target within a save()/restore() pair. Because the recorded drawing is plain GraphicsContext drawing, the GPU process writes it to the PDF as vectors. This patch covers the core of the delegate: the queries CG makes (bounds, transform, color space), fills and strokes of rects, lines, arcs and paths, clip stacks of rects and paths, and the clear/erase/flush operations. When the target is a PDF document, the CGContext is a PostScript type context, because PDFKit draws annotations as it does for printing only in PDF and PostScript contexts; otherwise open popup annotations that local printing omits would be drawn. Images, text, gradients, shadings, transparency layers, CG display lists, soft masks, mask clips and pattern colors are not implemented yet and will be added by follow-up patches. Some callbacks are intentionally not implemented: BeginPage / EndPage (the target isn't paginated, and bitmap contexts don't implement them either), DrawWindowContents (window server content can't be represented in a GraphicsContext), CreateImage / GetBitmapContextInfo (there is no backing store to read back) and SerializeDisplayList (only meaningful for display list delegates). The delegate is used only for remote snapshots. The UI process uses remote snapshotting only when RemoteSnapshottingEnabled is on and the frame tree is hosted by multiple processes (WebPageProxy::shouldUseRemoteSnapshotting()); the web process then records into a RemoteSnapshotRecorderProxy, whose rendering mode is DisplayList or PDFDocument. UnifiedPDFPlugin checks for such a context, rather than only for the lack of a platform context, so that other recording contexts (like the remote context of a layer backing store) are not drawn through the delegate. Since the delegate can't draw most PDFs correctly yet, it's also gated by the new internal preference RemoteSnapshottingUnifiedPDFVectorDrawingEnabled, which is off by default. Without it, remote snapshots keep drawing PDF content into a bitmap. Tests: UnifiedPDF.PrintEmbeddedPDFWithRemoteSnapshotting UnifiedPDF.PrintEmbeddedPDFPathsAndStrokesWithRemoteSnapshotting UnifiedPDF.PrintEmbeddedPDFOpenPopupAnnotationWithRemoteSnapshotting * Source/WTF/Scripts/Preferences/UnifiedWebPreferences.yaml: * Source/WebCore/PAL/pal/spi/cg/CoreGraphicsSPI.h: * Source/WebCore/PlatformCocoa.cmake: * Source/WebCore/SourcesCocoa.txt: * Source/WebCore/WebCore.xcodeproj/project.pbxproj: * Source/WebCore/platform/graphics/cg/GraphicsContextCGDelegate.cpp: Added. (WebCore::GStateScope::GStateScope): (WebCore::GStateScope::shouldDraw const): (WebCore::GStateScope::target const): (WebCore::GStateScope::ctm const): (WebCore::interpolationQuality): (WebCore::compositeMode): (WebCore::lineCap): (WebCore::lineJoin): (WebCore::clampPathCoordinates): (WebCore::pathFromCGPath): (WebCore::GStateScope::initialize): (WebCore::GStateScope::~GStateScope): (WebCore::GStateScope::paintForDrawingMode): (WebCore::GStateScope::windRuleForDrawingMode): (WebCore::GStateScope::applyClipStack): (WebCore::GStateScope::applyCompositeOperation): (WebCore::GStateScope::applyLineParameters): (WebCore::GStateScope::applyBrush): (WebCore::GraphicsContextCGDelegate::createCGContext): (WebCore::GraphicsContextCGDelegate::GraphicsContextCGDelegate): (WebCore::GraphicsContextCGDelegate::fromDelegate): (WebCore::GraphicsContextCGDelegate::installCallbacks): (WebCore::GraphicsContextCGDelegate::logUnimplementedCallback): (WebCore::GraphicsContextCGDelegate::finalize): (WebCore::GraphicsContextCGDelegate::getColorTransform): (WebCore::GraphicsContextCGDelegate::getTransform): (WebCore::GraphicsContextCGDelegate::getBounds): (WebCore::GraphicsContextCGDelegate::deviceBounds const): (WebCore::GraphicsContextCGDelegate::getColorSpace): (WebCore::GraphicsContextCGDelegate::getName): (WebCore::drawPathWithMode): (WebCore::GraphicsContextCGDelegate::drawLines): (WebCore::GraphicsContextCGDelegate::drawRects): (WebCore::GraphicsContextCGDelegate::drawPath): (WebCore::GraphicsContextCGDelegate::drawPathDirect): (WebCore::GraphicsContextCGDelegate::strokeArc): (WebCore::GraphicsContextCGDelegate::operation): * Source/WebCore/platform/graphics/cg/GraphicsContextCGDelegate.h: Added. (WebCore::GraphicsContextCGDelegate::target const): * Source/WebKit/WebProcess/Plugins/PDF/UnifiedPDF/UnifiedPDFPlugin.h: * Source/WebKit/WebProcess/Plugins/PDF/UnifiedPDF/UnifiedPDFPlugin.mm: (WebKit::UnifiedPDFPlugin::shouldDrawPDFContentThroughCGDelegate const): (WebKit::UnifiedPDFPlugin::paintPDFContent): * Tools/TestWebKitAPI/Tests/WebKit/WKWebView/WKPrinting.mm: (TestWebKitAPI::configurationForPrintingUnifiedPDF): (TestWebKitAPI::printMainFrameToPDF): (TestWebKitAPI::createPDFDocument): (TestWebKitAPI::renderPrintedPage): (TestWebKitAPI::colorsAreClose): (TestWebKitAPI::countPixelsCloseTo): (TestWebKitAPI::countDifferentPixels): (TestWebKitAPI::countPDFResources): (TestWebKitAPI::countPDFResourcesOfPage): (TestWebKitAPI::countPDFResourcesOfFirstPage): (TestWebKitAPI::waitForRequests): (TestWebKitAPI::loadPageForPrinting): (TestWebKitAPI::createPDFData): (TestWebKitAPI::createPDFDataWithObjects): (TestWebKitAPI::solidPDFColor): (TestWebKitAPI::createPDFDataWithSolidFill): (TestWebKitAPI::printDocumentWithEmbeddedPDFs): (TestWebKitAPI::UNIFIED_PDF_TEST): (TestWebKitAPI::printEmbeddedPDFData): (TestWebKitAPI::createPDFDataWithPathsAndStrokes): (TestWebKitAPI::createPDFDataWithOpenPopupAnnotation): (TestWebKitAPI::countYellowPixelsInPopup):
szewai
force-pushed
the
eng/Add-GraphicsContextCGDelegate-and-use-it-for-PDF-content-in-remote-snapshots
branch
from
October 17, 2026 18:21
ac75594 to
ec7e31f
Compare
Collaborator
|
EWS run on current version of this PR (hash ec7e31f) Details
|
Contributor
|
This seems like it is going to have a lot of overlap with the infrastructure in DrawGlyphsRecorder. What effort has been made to reuse that work first? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ec7e31f
ec7e31f