WebKit icon indicating copy to clipboard operation
WebKit copied to clipboard

[Filters] Do not cache the result FilterImages of the SVGFilter if they will take too much memory

Open shallawa opened this issue 2 years ago โ€ข 3 comments

4f98e765b8cd500e857ba7f2562209206bd45cce

[Filters] Do not cache the result FilterImages of the SVGFilter if they will take too much memory
https://bugs.webkit.org/show_bug.cgi?id=245230

Reviewed by NOBODY (OOPS!).

Make all the filter apply() function take an optional FilterResults input. Allow
caching the results only if the total estimated memory size is less than 100 MB.

To better manage the life cycle of the ImageBufferAllocator when it is owned by
FilterImage, FilterImage will now own a std::unique_ptr<ImageBufferAllocator>
instead of owning a ImageBufferAllocator&. Creating a new ImageBufferAllocator
for every FilterImage should very minimal impact on the allocated memory.

Because FilterResults is now optional, we need to move the ImageBufferAllocator
from FilterResults. Se we are adding an ImageBufferAllocatorFactory to Filter.

ImageBufferAllocatorFactory can create createAllocator() which can be moved to
the FilterImage when creating it.

* LayoutTests/svg/filters/repeated-drop-shadow-effects-expected.svg: Added.
* LayoutTests/svg/filters/repeated-drop-shadow-effects.svg: Added.
* Source/WebCore/WebCore.xcodeproj/project.pbxproj:
* Source/WebCore/platform/graphics/GraphicsContext.cpp:
(WebCore::GraphicsContext::drawFilteredImageBuffer):
* Source/WebCore/platform/graphics/GraphicsContext.h:
* Source/WebCore/platform/graphics/ImageBuffer.cpp:
(WebCore::ImageBuffer::filteredImage):
* Source/WebCore/platform/graphics/ImageBufferAllocator.h:
(WebCore::ImageBufferAllocatorFactory::createAllocator const):
* Source/WebCore/platform/graphics/displaylists/DisplayListItems.cpp:
(WebCore::DisplayList::DrawFilteredImageBuffer::apply):
* Source/WebCore/platform/graphics/displaylists/DisplayListItems.h:
* Source/WebCore/platform/graphics/displaylists/DisplayListRecorder.cpp:
(WebCore::DisplayList::Recorder::drawFilteredImageBuffer):
* Source/WebCore/platform/graphics/displaylists/DisplayListRecorder.h:
* Source/WebCore/platform/graphics/filters/Filter.cpp:
(WebCore::Filter::apply):
* Source/WebCore/platform/graphics/filters/Filter.h:
(WebCore::Filter::setAllocatorFactory):
(WebCore::Filter::createAllocator const):
* Source/WebCore/platform/graphics/filters/FilterEffect.cpp:
(WebCore::FilterEffect::apply):
* Source/WebCore/platform/graphics/filters/FilterEffect.h:
* Source/WebCore/platform/graphics/filters/FilterEffectCollection.h: Renamed from Source/WebCore/platform/graphics/filters/FilterEffectVector.h.
* Source/WebCore/platform/graphics/filters/FilterFunction.h:
(WebCore::FilterFunction::apply):
* Source/WebCore/platform/graphics/filters/FilterImage.cpp:
(WebCore::FilterImage::create):
(WebCore::FilterImage::FilterImage):
(WebCore::FilterImage::imageBufferFromPixelBuffer):
(WebCore::FilterImage::pixelBuffer):
(WebCore::FilterImage::getPixelBuffer):
(WebCore::FilterImage::copyPixelBuffer):
* Source/WebCore/platform/graphics/filters/FilterImage.h:
* Source/WebCore/platform/graphics/filters/FilterResults.cpp:
(WebCore::FilterResults::FilterResults): Deleted.
* Source/WebCore/platform/graphics/filters/FilterResults.h:
(WebCore::FilterResults::allocator const): Deleted.
* Source/WebCore/rendering/CSSFilter.cpp:
(WebCore::CSSFilter::apply):
* Source/WebCore/rendering/CSSFilter.h:
* Source/WebCore/rendering/RenderLayerFilters.cpp:
(WebCore::RenderLayerFilters::applyFilterEffect):
* Source/WebCore/rendering/svg/RenderSVGResourceFilter.cpp:
(WebCore::RenderSVGResourceFilter::postApplyResource):
* Source/WebCore/svg/graphics/filters/SVGFilter.cpp:
(WebCore::SVGFilter::buildExpression):
(WebCore::SVGFilter::effectsOfType const):
(WebCore::SVGFilter::canCacheResults const):
(WebCore::SVGFilter::apply):
* Source/WebCore/svg/graphics/filters/SVGFilter.h:
* Source/WebKit/GPUProcess/graphics/ImageBufferShareableAllocator.h:
(WebKit::ImageBufferShareableAllocatorFactory::ImageBufferShareableAllocatorFactory):
* Source/WebKit/GPUProcess/graphics/RemoteDisplayListRecorder.cpp:
(WebKit::RemoteDisplayListRecorder::drawFilteredImageBuffer):
* Source/WebKit/Platform/IPC/FilterReference.h:

https://github.com/WebKit/WebKit/commit/4f98e765b8cd500e857ba7f2562209206bd45cce

Misc iOS, tvOS & watchOS macOS Linux Windows
โœ… ๐Ÿงช style โœ… ๐Ÿ›  ios โœ… ๐Ÿ›  mac โœ… ๐Ÿ›  wpe โœ… ๐Ÿ›  ๐Ÿงช win
โœ… ๐Ÿงช bindings โœ… ๐Ÿ›  ios-sim โœ… ๐Ÿ›  mac-debug โœ… ๐Ÿ›  gtk โœ… ๐Ÿ›  wincairo
โœ… ๐Ÿงช webkitperl โœ… ๐Ÿงช ios-wk2 โœ… ๐Ÿ›  mac-AS-debug โœ… ๐Ÿงช gtk-wk2
โœ… ๐Ÿงช api-ios โœ… ๐Ÿงช api-mac โœ… ๐Ÿงช api-gtk
โœ… ๐Ÿ›  tv โœ… ๐Ÿงช mac-wk1
โœ… ๐Ÿ›  tv-sim โœ… ๐Ÿงช mac-wk2
โœ… ๐Ÿ›  watch โœ… ๐Ÿงช mac-AS-debug-wk2
โœ… ๐Ÿ›  watch-sim โœ… ๐Ÿงช mac-wk2-stress

shallawa avatar Sep 15 '22 17:09 shallawa

@shallawa - Was just digging through old bugs to reproduce and notice this bug with PR and noticed that this passes all test but didn't landed. It would need rebase but just wanted to confirm that it is intentionally held back for other bits?

Ahmad-S792 avatar Jan 21 '23 22:01 Ahmad-S792

Committed 264807@main (93ee37d30632): https://commits.webkit.org/264807@main

Reviewed commits have been landed. Closing PR #4390 and removing active labels.

webkit-commit-queue avatar Jun 01 '23 21:06 webkit-commit-queue