Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Add a new DrawDecomposedGlyphs display list item to avoid repeatedly …
…sending glyphs when using the GlyphDisplayListCache https://bugs.webkit.org/show_bug.cgi?id=240497 <rdar://93387615> Reviewed by Simon Fraser. The GlyphDisplayListCache is used to record a display list for frequently painting text content. With GPU Process DOM rendering, there is significant overhead in sending the contents of these display lists over IPC. The contents of these display lists don't change if the text content in the document doesn't change, so we could greatly reduce the overhead by treating the data inside a display list item for glyph drawing as a remote resource. This commit adds: * a new display list item, DrawDecomposedGlyphs, to represent drawing a glyph list resource * a new class, DecomposedGlyphs, which is the resource type * a new struct, PositionedGlyphs, to provide a common place for the glyph drawing fields (the vector of glyph IDs, the anchor position, etc.) to live, so that we don't have duplication between DisplayList::DrawGlyphs and DecomposedGlyphs So that a DrawDecomposedGlyphs command can be replayed from a GlyphDisplayListCache's in-memory display list and recorded to a RemoteDisplayListRecorder, the GraphicsContext API gains a new drawDecomposedGlyphs function. A new argument to the DisplayList::RecordImpl constructor (and the DrawGlyphsRecorder) is added to represent how to record drawText commands: * DrawGlyphsMode::Normal, which records each GraphicsContext::drawText call with a single DrawText command * DrawGlyphsMode::DeconstructToDrawGlyphsCommands, which ensures different text layers get deconstructed into separate DrawText commands * DrawGlyphsMode::DeconstructToDrawDecomposedGlyphsCommands, which ensures different text layers get desconstructed into separate DrawDecomposedGlyphs commands FontCascade::displayListForTextRun is updated to use that last value. Additionally, GlyphDisplayListCache is extended to cache display lists keyed off TextRun values. This allows sharing of the same cached display list between different elements on the page that have the same text content. This sharing would not be valid if the two elements have different values for the color property, and the text contains COLRv0 glyphs that alternate painting of specific colors and the color fill color, since the recording would incorrectly record a setFillBrush command corresponding to the first element's fill color. Rather than extend the glyph recorder to parameterize the current fill (and stroke) colors, we detect when outlines are drawn with colors other than the context's initial colors, and prevent sharing. This is done by checking whether the recorded display list contains items that aren't known to be safe for sharing. Similarly, if the sharing would not be valid if the contains bitmap images (like those from emoji fonts) or SVG glyphs, both of which are captured as DrawNativeImage commands, if the text is drawn at different scales. This is because the size of the images is dependent on the scale. We detect and prevent reuse across different text runs if the scale is different, by checking the recorded display list for DrawNativeImage commands and by storing the context scale on the GlyphDisplayListCache::Entry. * LayoutTests/fast/text/glyph-display-lists/glyph-display-list-colr-unshared-expected.txt: Added. * LayoutTests/fast/text/glyph-display-lists/glyph-display-list-colr-unshared.html: Added. * LayoutTests/fast/text/glyph-display-lists/glyph-display-list-scaled-unshared-expected.txt: Added. * LayoutTests/fast/text/glyph-display-lists/glyph-display-list-scaled-unshared.html: Added. * LayoutTests/fast/text/glyph-display-lists/glyph-display-list-shadow-unshared-expected.txt: Added. * LayoutTests/fast/text/glyph-display-lists/glyph-display-list-shadow-unshared.html: Added. * LayoutTests/fast/text/glyph-display-lists/glyph-display-list-shared-expected.txt: Added. * LayoutTests/fast/text/glyph-display-lists/glyph-display-list-shared.html: Added. * LayoutTests/fast/text/glyph-display-lists/glyph-display-list-svg-unshared-expected.txt: Added. * LayoutTests/fast/text/glyph-display-lists/glyph-display-list-svg-unshared.html: Added. * Source/WebCore/Headers.cmake: * Source/WebCore/Sources.txt: * Source/WebCore/WebCore.xcodeproj/project.pbxproj: * Source/WebCore/platform/graphics/BifurcatedGraphicsContext.cpp: (WebCore::BifurcatedGraphicsContext::drawDecomposedGlyphs): * Source/WebCore/platform/graphics/BifurcatedGraphicsContext.h: * Source/WebCore/platform/graphics/DecomposedGlyphs.cpp: Added. (WebCore::DecomposedGlyphs::create): (WebCore::DecomposedGlyphs::DecomposedGlyphs): (WebCore::m_renderingResourceIdentifier): * Source/WebCore/platform/graphics/DecomposedGlyphs.h: Added. (WebCore::DecomposedGlyphs::positionedGlyphs const): (WebCore::DecomposedGlyphs::bounds const): (WebCore::DecomposedGlyphs::addObserver): (WebCore::DecomposedGlyphs::removeObserver): (WebCore::DecomposedGlyphs::renderingResourceIdentifier const): * Source/WebCore/platform/graphics/FontCascade.cpp: (WebCore::FontCascade::displayListForTextRun const): * Source/WebCore/platform/graphics/GraphicsContext.cpp: (WebCore::GraphicsContext::drawDecomposedGlyphs): * Source/WebCore/platform/graphics/GraphicsContext.h: (WebCore::GraphicsContext::drawGlyphsAndCacheResources): (WebCore::GraphicsContext::drawGlyphsAndCacheFont): Deleted. * Source/WebCore/platform/graphics/NullGraphicsContext.h: * Source/WebCore/platform/graphics/PositionedGlyphs.cpp: Copied from Source/WebCore/platform/graphics/win/DrawGlyphsRecorderWin.cpp. (WebCore::PositionedGlyphs::computeBounds const): * Source/WebCore/platform/graphics/PositionedGlyphs.h: Added. (WebCore::PositionedGlyphs::PositionedGlyphs): (WebCore::PositionedGlyphs::encode const): (WebCore::PositionedGlyphs::decode): * Source/WebCore/platform/graphics/TextRun.cpp: (WebCore::operator<<): * Source/WebCore/platform/graphics/TextRun.h: (WebCore::TextRun::TextRun): (WebCore::TextRun::isHashTableEmptyValue const): (WebCore::TextRun::isHashTableDeletedValue const): (WebCore::TextRun::cloneForStorage const): * Source/WebCore/platform/graphics/TextRunHash.h: Added. (WebCore::add): (WebCore::TextRun::operator== const): (WebCore::TextRunHash::hash): (WebCore::TextRunHash::equal): (WTF::HashTraits<WebCore::TextRun>::isDeletedValue): (WTF::HashTraits<WebCore::TextRun>::isEmptyValue): (WTF::HashTraits<WebCore::TextRun>::constructDeletedValue): (WTF::HashTraits<WebCore::TextRun>::emptyValue): * Source/WebCore/platform/graphics/cairo/GraphicsContextCairo.cpp: (WebCore::GraphicsContextCairo::drawDecomposedGlyphs): * Source/WebCore/platform/graphics/cairo/GraphicsContextCairo.h: * Source/WebCore/platform/graphics/coretext/DrawGlyphsRecorderCoreText.cpp: (WebCore::DrawGlyphsRecorder::createInternalContext): (WebCore::DrawGlyphsRecorder::updateCTM): (WebCore::DrawGlyphsRecorder::recordDrawGlyphs): * Source/WebCore/platform/graphics/displaylists/DisplayList.cpp: (WebCore::DisplayList::DisplayList::description const): (WebCore::DisplayList::DisplayList::append): * Source/WebCore/platform/graphics/displaylists/DisplayList.h: (WebCore::DisplayList::DisplayList::cacheDecomposedGlyphs): * Source/WebCore/platform/graphics/displaylists/DisplayListItemBuffer.cpp: (WebCore::DisplayList::ItemHandle::apply): (WebCore::DisplayList::ItemHandle::destroy): (WebCore::DisplayList::ItemHandle::safeCopy const): * Source/WebCore/platform/graphics/displaylists/DisplayListItemType.cpp: (WebCore::DisplayList::sizeOfItemInBytes): (WebCore::DisplayList::isDrawingItem): (WebCore::DisplayList::isInlineItem): * Source/WebCore/platform/graphics/displaylists/DisplayListItemType.h: * Source/WebCore/platform/graphics/displaylists/DisplayListItems.cpp: (WebCore::DisplayList::DrawGlyphs::DrawGlyphs): (WebCore::DisplayList::m_bounds): (WebCore::DisplayList::DrawGlyphs::apply const): (WebCore::DisplayList::DrawDecomposedGlyphs::apply const): (WebCore::DisplayList::operator<<): (WebCore::DisplayList::dumpItem): (WebCore::DisplayList::dumpItemHandle): (WebCore::DisplayList::DrawGlyphs::computeBounds): Deleted. * Source/WebCore/platform/graphics/displaylists/DisplayListItems.h: (WebCore::DisplayList::DrawGlyphs::localAnchor const): (WebCore::DisplayList::DrawGlyphs::anchorPoint const): (WebCore::DisplayList::DrawGlyphs::glyphs const): (WebCore::DisplayList::DrawGlyphs::encode const): (WebCore::DisplayList::DrawGlyphs::decode): (WebCore::DisplayList::DrawDecomposedGlyphs::DrawDecomposedGlyphs): (WebCore::DisplayList::DrawDecomposedGlyphs::fontIdentifier const): (WebCore::DisplayList::DrawDecomposedGlyphs::decomposedGlyphsIdentifier const): (WebCore::DisplayList::DrawDecomposedGlyphs::globalBounds const): (WebCore::DisplayList::DrawDecomposedGlyphs::localBounds const): * Source/WebCore/platform/graphics/displaylists/DisplayListRecorder.cpp: (WebCore::DisplayList::Recorder::Recorder): (WebCore::DisplayList::Recorder::shouldDeconstructDrawGlyphs const): (WebCore::DisplayList::Recorder::drawGlyphs): (WebCore::DisplayList::Recorder::drawDecomposedGlyphs): (WebCore::DisplayList::Recorder::drawGlyphsAndCacheResources): (WebCore::DisplayList::Recorder::drawGlyphsAndCacheFont): Deleted. * Source/WebCore/platform/graphics/displaylists/DisplayListRecorder.h: * Source/WebCore/platform/graphics/displaylists/DisplayListRecorderImpl.cpp: (WebCore::DisplayList::RecorderImpl::RecorderImpl): (WebCore::DisplayList::RecorderImpl::recordDrawDecomposedGlyphs): (WebCore::DisplayList::RecorderImpl::recordResourceUse): * Source/WebCore/platform/graphics/displaylists/DisplayListRecorderImpl.h: * Source/WebCore/platform/graphics/displaylists/DisplayListReplayer.cpp: (WebCore::DisplayList::applyDrawDecomposedGlyphs): (WebCore::DisplayList::Replayer::applyItem): (WebCore::DisplayList::Replayer::replay): * Source/WebCore/platform/graphics/displaylists/DisplayListReplayer.h: * Source/WebCore/platform/graphics/displaylists/DisplayListResourceHeap.h: (WebCore::DisplayList::LocalResourceHeap::add): * Source/WebCore/platform/graphics/harfbuzz/DrawGlyphsRecorderHarfBuzz.cpp: (WebCore::DrawGlyphsRecorder::drawGlyphs): * Source/WebCore/platform/graphics/nicosia/cairo/NicosiaCairoOperationRecorder.cpp: (Nicosia::CairoOperationRecorder::drawDecomposedGlyphs): * Source/WebCore/platform/graphics/nicosia/cairo/NicosiaCairoOperationRecorder.h: * Source/WebCore/platform/graphics/win/DrawGlyphsRecorderWin.cpp: (WebCore::DrawGlyphsRecorder::drawGlyphs): * Source/WebCore/platform/text/TextDirection.h: (WebCore::operator<<): * Source/WebCore/platform/text/TextFlags.cpp: (WebCore::operator<<): * Source/WebCore/platform/text/TextFlags.h: (WebCore::ExpansionBehavior::operator== const): * Source/WebCore/rendering/GlyphDisplayListCache.cpp: Added. (WebCore::GlyphDisplayListCacheBase::displayListSharing): * Source/WebCore/rendering/GlyphDisplayListCache.h: (WebCore::GlyphDisplayListCacheBase::size const): (WebCore::GlyphDisplayListCacheBase::sizeInBytes const): (WebCore::GlyphDisplayListCacheBase::Entry::create): (WebCore::GlyphDisplayListCacheBase::Entry::displayList): (WebCore::GlyphDisplayListCacheBase::Entry::relevantScaleFactor const): (WebCore::GlyphDisplayListCacheBase::Entry::Entry): (WebCore::GlyphDisplayListCache::get): (WebCore::GlyphDisplayListCache::getIfExists): (WebCore::GlyphDisplayListCache::remove): (WebCore::GlyphDisplayListCache::clear): (WebCore::GlyphDisplayListCache::size const): Deleted. (WebCore::GlyphDisplayListCache::sizeInBytes const): Deleted. * Source/WebCore/rendering/RenderLayerCompositor.cpp: * Source/WebCore/rendering/TextPainter.cpp: * Source/WebCore/testing/Internals.cpp: (WebCore::toDisplayListFlags): (WebCore::Internals::displayListForElement): (WebCore::Internals::replayDisplayListForElement): (WebCore::Internals::cachedGlyphDisplayListsForTextNode): * Source/WebCore/testing/Internals.h: * Source/WebCore/testing/Internals.idl: * Source/WebKit/GPUProcess/graphics/QualifiedResourceHeap.h: (WebKit::QualifiedResourceHeap::add): (WebKit::QualifiedResourceHeap::getDecomposedGlyphs const): (WebKit::QualifiedResourceHeap::removeDecomposedGlyphs): (WebKit::QualifiedResourceHeap::checkInvariants const): * Source/WebKit/GPUProcess/graphics/RemoteDisplayListRecorder.cpp: (WebKit::RemoteDisplayListRecorder::drawDecomposedGlyphs): (WebKit::RemoteDisplayListRecorder::drawDecomposedGlyphsWithQualifiedIdentifiers): * Source/WebKit/GPUProcess/graphics/RemoteDisplayListRecorder.h: * Source/WebKit/GPUProcess/graphics/RemoteDisplayListRecorder.messages.in: * Source/WebKit/GPUProcess/graphics/RemoteRenderingBackend.cpp: (WebKit::RemoteRenderingBackend::cacheFontWithQualifiedIdentifier): (WebKit::RemoteRenderingBackend::cacheDecomposedGlyphs): (WebKit::RemoteRenderingBackend::cacheDecomposedGlyphsWithQualifiedIdentifier): * Source/WebKit/GPUProcess/graphics/RemoteRenderingBackend.h: * Source/WebKit/GPUProcess/graphics/RemoteRenderingBackend.messages.in: * Source/WebKit/GPUProcess/graphics/RemoteResourceCache.cpp: (WebKit::RemoteResourceCache::cacheDecomposedGlyphs): (WebKit::RemoteResourceCache::cachedDecomposedGlyphs const): (WebKit::RemoteResourceCache::releaseRemoteResource): * Source/WebKit/GPUProcess/graphics/RemoteResourceCache.h: * Source/WebKit/Shared/WebCoreArgumentCoders.cpp: (IPC::ArgumentCoder<DecomposedGlyphs>::encode): (IPC::ArgumentCoder<DecomposedGlyphs>::decode): * Source/WebKit/Shared/WebCoreArgumentCoders.h: * Source/WebKit/WebKit.xcodeproj/project.pbxproj: * Source/WebKit/WebProcess/GPU/graphics/RemoteDisplayListRecorderProxy.cpp: (WebKit::RemoteDisplayListRecorderProxy::RemoteDisplayListRecorderProxy): (WebKit::RemoteDisplayListRecorderProxy::recordDrawDecomposedGlyphs): (WebKit::RemoteDisplayListRecorderProxy::recordResourceUse): * Source/WebKit/WebProcess/GPU/graphics/RemoteDisplayListRecorderProxy.h: * Source/WebKit/WebProcess/GPU/graphics/RemoteRenderingBackendProxy.cpp: (WebKit::RemoteRenderingBackendProxy::cacheDecomposedGlyphs): * Source/WebKit/WebProcess/GPU/graphics/RemoteRenderingBackendProxy.h: * Source/WebKit/WebProcess/GPU/graphics/RemoteResourceCacheProxy.cpp: (WebKit::RemoteResourceCacheProxy::~RemoteResourceCacheProxy): (WebKit::RemoteResourceCacheProxy::recordDecomposedGlyphsUse): (WebKit::RemoteResourceCacheProxy::releaseDecomposedGlyphs): (WebKit::RemoteResourceCacheProxy::clearDecomposedGlyphsMap): (WebKit::RemoteResourceCacheProxy::remoteResourceCacheWasDestroyed): * Source/WebKit/WebProcess/GPU/graphics/RemoteResourceCacheProxy.h: Canonical link: https://commits.webkit.org/251324@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@295278 268f45cc-cd09-0410-ab3c-d52691b4dbfc
- Loading branch information