WebKit Bugzilla
New
Browse
Search+
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
[patch]
Patch for review
resource-cache-6.patch (text/plain), 53.11 KB, created by
Said Abou-Hallawa
on 2020-10-12 09:58:56 PDT
(
hide
)
Description:
Patch for review
Filename:
MIME Type:
Creator:
Said Abou-Hallawa
Created:
2020-10-12 09:58:56 PDT
Size:
53.11 KB
patch
obsolete
>diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog >index c4d19def1c8c..8b3be52d67af 100644 >--- a/Source/WebCore/ChangeLog >+++ b/Source/WebCore/ChangeLog >@@ -1,3 +1,102 @@ >+2020-10-11 Said Abou-Hallawa <sabouhallawa@apple.com> >+ >+ [GPU Process] Cache the BitmapImage frame in GPU Process and allow referencing it with its RemoteResourceIdentifier >+ https://bugs.webkit.org/show_bug.cgi?id=217596 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ Only the frames of the BitmapImage will be cached in the GPU side. The >+ frames of BitmapImage have a well defined life cycle in the Web Process. >+ The counterpart frames in the GPU Process will have a similar life cycle. >+ When the frame is drawn for the first time it will be transfered from Web >+ Process via a ShareableBitmap to the GPU Process and cached under a unique >+ RemoteResourceIdentifier which will be used to record the NativeDrawImage >+ item. When the BitmapImage decides to destroy its decoded frame, a message >+ will be sent from the Web Process to the GPU Process to remove the cached >+ frame. Here is the sequence in more detail: >+ >+ The drawing sequence in the Web Process is the following: >+ >+ 1) BitmapImage::draw() calls ImageObserver::drawNativeImage(). >+ 2) CachedImage::CachedImageObserver::drawNativeImage() finds the associated >+ CachedImage and calls GraphicsContext::drawNativeImage(). >+ 3) Recorder::drawNativeImage() calls the createDrawNativeImageItem() of >+ its delegate which is RemoteImageBuffer in the case of 2D canvas. >+ 4) RemoteImageBuffer calls the RemoteRenderingBacked which calls its >+ RemoteResourceCache::createDrawNativeImageItem(). >+ 5) RemoteResourceCache calls its findNativeImageForClient() which caches >+ the NativeImage in the cache, resisters RemoteResourceCache as a client >+ of the CachedImage, asks the GPU Process to cache it also and returns >+ the RemoteResourceIdentifier. RemoteResourceCache then creates the >+ DrawNativeImage item with this RemoteResourceIdentifier. >+ >+ The drawing sequence in the GPU Process is the following: >+ >+ 1) When flushing the DrawingContext happens, the DisplayList items are >+ replayed back. DisplayList::Replayer::reply() calls apply() of its >+ delegate. >+ 2) In the case of 2D canvas, the replayer delegate is RemoteImageBufferProxy. >+ Its apply() will call RemoteResourceCacheProxy::applyResourceItem() through >+ the RemoteRenderingBackendProxy. >+ 3) RemoteResourceCacheProxy::drawNativeImageItem() searches for the NativeImage >+ whose identifier is the remoteResourceIdentifier() of the DrawNativeImage. >+ 4) Once the NativeImage is found, it will be drawn using the reset of the >+ arguments of DrawNativeImage. >+ >+ The release sequence in the Web Process is the following: >+ >+ 1) ImageSource::destroyDecodedData() calls the ImageObserver when a decoded >+ frame is about to be destroyed. >+ 2) CachedImage::CachedImageObserver::nativeImageWillBeDestroyed() finds >+ the associated CachedImage and calls CachedImage::nativeImageWillBeDestroyed(). >+ 3) CachedImage calls all the CachedImageClients to notify them. >+ 4) Because RemoteResourceCache registers itself as a CachedImageClient of >+ this CachedImage, RemoteResourceCache::nativeImageWillBeDestroyed() >+ will be called. >+ 5) The cached NativeImage will be removes from the cache and a message will >+ be sent to the GPU Process when no remote client is referencing this >+ NativeImage. >+ >+ The release sequence in the GPU Process is the following: >+ >+ 1) RemoteResourceCacheProxy::releaseRemoteResource releases the cached >+ NativeImage via RemoteRenderingBackendProxy. >+ >+ * html/ImageBitmap.cpp: >+ * loader/cache/CachedImage.cpp: >+ (WebCore::CachedImage::CachedImageObserver::drawNativeImage): >+ (WebCore::CachedImage::CachedImageObserver::nativeImageWillBeDestroyed): >+ (WebCore::CachedImage::nativeImageWillBeDestroyed): >+ * loader/cache/CachedImage.h: >+ * loader/cache/CachedImageClient.h: >+ (WebCore::CachedImageClient::nativeImageWillBeDestroyed): >+ * platform/graphics/BitmapImage.cpp: >+ (WebCore::drawNativeImage): >+ (WebCore::BitmapImage::draw): >+ (WebCore::BitmapImage::subsamplingLevelForScaleFactor): >+ * platform/graphics/GraphicsContext.cpp: >+ (WebCore::GraphicsContext::drawNativeImage): >+ * platform/graphics/GraphicsContext.h: >+ (WebCore::GraphicsContext::drawNativeImage): >+ * platform/graphics/GraphicsContextImpl.h: >+ * platform/graphics/ImageObserver.h: >+ * platform/graphics/ImageSource.cpp: >+ (WebCore::ImageSource::destroyDecodedData): >+ * platform/graphics/displaylists/DisplayListItems.cpp: >+ (WebCore::DisplayList::DrawNativeImage::DrawNativeImage): >+ (WebCore::DisplayList::DrawNativeImage::apply const): >+ * platform/graphics/displaylists/DisplayListItems.h: >+ (WebCore::DisplayList::DrawNativeImage::remoteResourceIdentifier const): >+ (WebCore::DisplayList::DrawNativeImage::nativeImagePtr const): >+ (WebCore::DisplayList::DrawNativeImage::create): >+ (WebCore::DisplayList::DrawNativeImage::imageSize const): >+ (WebCore::DisplayList::DrawNativeImage::options const): >+ (WebCore::DisplayList::DrawNativeImage::decode): >+ * platform/graphics/displaylists/DisplayListRecorder.cpp: >+ (WebCore::DisplayList::Recorder::drawNativeImage): >+ * platform/graphics/displaylists/DisplayListRecorder.h: >+ (WebCore::DisplayList::Recorder::Delegate::createDrawNativeImageItem): >+ > 2020-10-11 Said Abou-Hallawa <sabouhallawa@apple.com> > > [GPU Process] Clean the DisplayList recording of the NativeImage >diff --git a/Source/WebCore/html/ImageBitmap.cpp b/Source/WebCore/html/ImageBitmap.cpp >index 439b6a9d7d81..62f59d692b7f 100644 >--- a/Source/WebCore/html/ImageBitmap.cpp >+++ b/Source/WebCore/html/ImageBitmap.cpp >@@ -601,10 +601,17 @@ public: > > void decodedSizeChanged(const Image&, long long) override { } > >+ void drawNativeImage(const Image&, GraphicsContext& context, const NativeImagePtr& nativeImage, const FloatSize& imageSize, const FloatRect& destRect, const FloatRect& srcRect, const ImagePaintingOptions& options) override >+ { >+ context.drawNativeImage(nativeImage, imageSize, destRect, srcRect, options); >+ } >+ > void didDraw(const Image&) override { } > > bool canDestroyDecodedData(const Image&) override { return true; } > void imageFrameAvailable(const Image&, ImageAnimatingState, const IntRect* = nullptr, DecodingStatus = DecodingStatus::Invalid) override { } >+ void nativeImageWillBeDestroyed(const Image&, const NativeImagePtr&) override { } >+ > void changedInRect(const Image&, const IntRect* = nullptr) override { } > void scheduleRenderingUpdate(const Image&) override { } > >diff --git a/Source/WebCore/loader/cache/CachedImage.cpp b/Source/WebCore/loader/cache/CachedImage.cpp >index 5cc933832574..82d2919c83ca 100644 >--- a/Source/WebCore/loader/cache/CachedImage.cpp >+++ b/Source/WebCore/loader/cache/CachedImage.cpp >@@ -411,6 +411,17 @@ void CachedImage::CachedImageObserver::decodedSizeChanged(const Image& image, lo > cachedImage->decodedSizeChanged(image, delta); > } > >+void CachedImage::CachedImageObserver::drawNativeImage(const Image& image, GraphicsContext& context, const NativeImagePtr& nativeImage, const FloatSize& imageSize, const FloatRect& destRect, const FloatRect& srcRect, const ImagePaintingOptions& options) >+{ >+ for (auto cachedImage : m_cachedImages) { >+ if (&image != cachedImage->image()) >+ continue; >+ context.drawNativeImage(nativeImage, imageSize, destRect, srcRect, options, cachedImage); >+ return; >+ } >+ context.drawNativeImage(nativeImage, imageSize, destRect, srcRect, options); >+} >+ > void CachedImage::CachedImageObserver::didDraw(const Image& image) > { > for (auto cachedImage : m_cachedImages) >@@ -434,6 +445,12 @@ void CachedImage::CachedImageObserver::imageFrameAvailable(const Image& image, I > cachedImage->imageFrameAvailable(image, animatingState, changeRect, decodingStatus); > } > >+void CachedImage::CachedImageObserver::nativeImageWillBeDestroyed(const Image& image, const NativeImagePtr& nativeImage) >+{ >+ for (auto cachedImage : m_cachedImages) >+ cachedImage->nativeImageWillBeDestroyed(image, nativeImage); >+} >+ > void CachedImage::CachedImageObserver::changedInRect(const Image& image, const IntRect* rect) > { > for (auto cachedImage : m_cachedImages) >@@ -689,6 +706,16 @@ void CachedImage::imageFrameAvailable(const Image& image, ImageAnimatingState an > m_clientsWaitingForAsyncDecoding.clear(); > } > >+void CachedImage::nativeImageWillBeDestroyed(const Image& image, const NativeImagePtr& nativeImage) >+{ >+ if (&image != m_image) >+ return; >+ >+ CachedResourceClientWalker<CachedImageClient> clientWalker(m_clients); >+ while (CachedImageClient* client = clientWalker.next()) >+ client->nativeImageWillBeDestroyed(nativeImage); >+} >+ > void CachedImage::changedInRect(const Image& image, const IntRect* rect) > { > if (&image != m_image) >diff --git a/Source/WebCore/loader/cache/CachedImage.h b/Source/WebCore/loader/cache/CachedImage.h >index 72d59c1ff484..8679832a4cc1 100644 >--- a/Source/WebCore/loader/cache/CachedImage.h >+++ b/Source/WebCore/loader/cache/CachedImage.h >@@ -149,10 +149,14 @@ private: > > void encodedDataStatusChanged(const Image&, EncodedDataStatus) final; > void decodedSizeChanged(const Image&, long long delta) final; >+ >+ void drawNativeImage(const Image&, GraphicsContext&, const NativeImagePtr&, const FloatSize& imageSize, const FloatRect& destRect, const FloatRect& srcRect, const ImagePaintingOptions&) final; > void didDraw(const Image&) final; > > bool canDestroyDecodedData(const Image&) final; > void imageFrameAvailable(const Image&, ImageAnimatingState, const IntRect* changeRect = nullptr, DecodingStatus = DecodingStatus::Invalid) final; >+ void nativeImageWillBeDestroyed(const Image&, const NativeImagePtr&) final; >+ > void changedInRect(const Image&, const IntRect*) final; > void scheduleRenderingUpdate(const Image&) final; > >@@ -164,6 +168,7 @@ private: > void didDraw(const Image&); > bool canDestroyDecodedData(const Image&); > void imageFrameAvailable(const Image&, ImageAnimatingState, const IntRect* changeRect = nullptr, DecodingStatus = DecodingStatus::Invalid); >+ void nativeImageWillBeDestroyed(const Image&, const NativeImagePtr&); > void changedInRect(const Image&, const IntRect*); > void scheduleRenderingUpdate(const Image&); > >diff --git a/Source/WebCore/loader/cache/CachedImageClient.h b/Source/WebCore/loader/cache/CachedImageClient.h >index ba6445b7ea7e..21aaf07f1bb5 100644 >--- a/Source/WebCore/loader/cache/CachedImageClient.h >+++ b/Source/WebCore/loader/cache/CachedImageClient.h >@@ -24,6 +24,7 @@ > > #include "CachedResourceClient.h" > #include "ImageTypes.h" >+#include "NativeImagePtr.h" > > namespace WebCore { > >@@ -47,6 +48,8 @@ public: > // Called when a new decoded frame for a large image is available or when an animated image is ready to advance to the next frame. > virtual VisibleInViewportState imageFrameAvailable(CachedImage& image, ImageAnimatingState, const IntRect* changeRect) { imageChanged(&image, changeRect); return VisibleInViewportState::No; } > >+ virtual void nativeImageWillBeDestroyed(const NativeImagePtr&) { } >+ > virtual void didRemoveCachedImageClient(CachedImage&) { } > > virtual void scheduleRenderingUpdateForImage(CachedImage&) { } >diff --git a/Source/WebCore/platform/graphics/BitmapImage.cpp b/Source/WebCore/platform/graphics/BitmapImage.cpp >index 704c43a28878..0af6c3d8b231 100644 >--- a/Source/WebCore/platform/graphics/BitmapImage.cpp >+++ b/Source/WebCore/platform/graphics/BitmapImage.cpp >@@ -205,7 +205,7 @@ bool BitmapImage::notSolidColor() > } > #endif // ASSERT_ENABLED > >-static inline void drawNativeImage(const NativeImagePtr& nativeImage, GraphicsContext& context, const FloatRect& destRect, const FloatRect& srcRect, const IntSize& srcSize, const ImagePaintingOptions& options) >+static inline void drawNativeImage(BitmapImage& image, GraphicsContext& context, const NativeImagePtr& nativeImage, const FloatRect& destRect, const FloatRect& srcRect, const IntSize& srcSize, const ImagePaintingOptions& options) > { > // Subsampling may have given us an image that is smaller than size(). > IntSize subsampledImageSize = nativeImageSize(nativeImage); >@@ -217,7 +217,10 @@ static inline void drawNativeImage(const NativeImagePtr& nativeImage, GraphicsCo > if (subsampledImageSize != srcSize) > adjustedSrcRect = mapRect(srcRect, FloatRect({ }, srcSize), FloatRect({ }, subsampledImageSize)); > >- context.drawNativeImage(nativeImage, subsampledImageSize, destRect, adjustedSrcRect, options); >+ if (image.imageObserver()) >+ image.imageObserver()->drawNativeImage(image, context, nativeImage, subsampledImageSize, destRect, adjustedSrcRect, options); >+ else >+ context.drawNativeImage(nativeImage, subsampledImageSize, destRect, adjustedSrcRect, options); > } > > ImageDrawResult BitmapImage::draw(GraphicsContext& context, const FloatRect& destRect, const FloatRect& srcRect, const ImagePaintingOptions& options) >@@ -308,9 +311,9 @@ ImageDrawResult BitmapImage::draw(GraphicsContext& context, const FloatRect& des > auto orientation = options.orientation(); > if (orientation == ImageOrientation::FromImage) { > orientation = frameOrientationAtIndex(m_currentFrame); >- drawNativeImage(image, context, destRect, srcRect, IntSize(size(orientation)), { options, orientation }); >+ drawNativeImage(*this, context, image, destRect, srcRect, IntSize(size(orientation)), { options, orientation }); > } else >- drawNativeImage(image, context, destRect, srcRect, IntSize(size(orientation)), options); >+ drawNativeImage(*this, context, image, destRect, srcRect, IntSize(size(orientation)), options); > > m_currentFrameDecodingStatus = frameDecodingStatusAtIndex(m_currentFrame); > >@@ -395,7 +398,7 @@ SubsamplingLevel BitmapImage::subsamplingLevelForScaleFactor(GraphicsContext& co > { > #if USE(CG) > // Never use subsampled images for drawing into PDF contexts. >- if (CGContextGetType(context.platformContext()) == kCGContextTypePDF) >+ if (context.hasPlatformContext() && CGContextGetType(context.platformContext()) == kCGContextTypePDF) > return SubsamplingLevel::Default; > > float scale = std::min(float(1), std::max(scaleFactor.width(), scaleFactor.height())); >diff --git a/Source/WebCore/platform/graphics/GraphicsContext.cpp b/Source/WebCore/platform/graphics/GraphicsContext.cpp >index e730b89ca0cd..7113d7f64e1a 100644 >--- a/Source/WebCore/platform/graphics/GraphicsContext.cpp >+++ b/Source/WebCore/platform/graphics/GraphicsContext.cpp >@@ -731,13 +731,13 @@ void GraphicsContext::drawBidiText(const FontCascade& font, const TextRun& run, > bidiRuns.clear(); > } > >-void GraphicsContext::drawNativeImage(const NativeImagePtr& image, const FloatSize& imageSize, const FloatRect& destRect, const FloatRect& srcRect, const ImagePaintingOptions& options) >+void GraphicsContext::drawNativeImage(const NativeImagePtr& image, const FloatSize& imageSize, const FloatRect& destRect, const FloatRect& srcRect, const ImagePaintingOptions& options, CachedImage* cachedImage) > { > if (paintingDisabled()) > return; > > if (m_impl) { >- m_impl->drawNativeImage(image, imageSize, destRect, srcRect, options); >+ m_impl->drawNativeImage(image, imageSize, destRect, srcRect, options, cachedImage); > return; > } > >diff --git a/Source/WebCore/platform/graphics/GraphicsContext.h b/Source/WebCore/platform/graphics/GraphicsContext.h >index 0d1ca92d6045..2519d7bea182 100644 >--- a/Source/WebCore/platform/graphics/GraphicsContext.h >+++ b/Source/WebCore/platform/graphics/GraphicsContext.h >@@ -86,6 +86,7 @@ class GlyphBuffer; > #endif > > class AffineTransform; >+class CachedImage; > class FloatRoundedRect; > class Gradient; > class GraphicsContextImpl; >@@ -379,7 +380,7 @@ public: > > WEBCORE_EXPORT void strokeRect(const FloatRect&, float lineWidth); > >- WEBCORE_EXPORT void drawNativeImage(const NativeImagePtr&, const FloatSize& selfSize, const FloatRect& destRect, const FloatRect& srcRect, const ImagePaintingOptions& = { }); >+ WEBCORE_EXPORT void drawNativeImage(const NativeImagePtr&, const FloatSize& selfSize, const FloatRect& destRect, const FloatRect& srcRect, const ImagePaintingOptions& = { }, CachedImage* = nullptr); > > WEBCORE_EXPORT ImageDrawResult drawImage(Image&, const FloatPoint& destination, const ImagePaintingOptions& = { ImageOrientation::FromImage }); > WEBCORE_EXPORT ImageDrawResult drawImage(Image&, const FloatRect& destination, const ImagePaintingOptions& = { ImageOrientation::FromImage }); >diff --git a/Source/WebCore/platform/graphics/GraphicsContextImpl.h b/Source/WebCore/platform/graphics/GraphicsContextImpl.h >index 040920a8cfdc..f44d9e543a39 100644 >--- a/Source/WebCore/platform/graphics/GraphicsContextImpl.h >+++ b/Source/WebCore/platform/graphics/GraphicsContextImpl.h >@@ -72,9 +72,8 @@ public: > virtual ImageDrawResult drawImage(Image&, const FloatRect& destination, const FloatRect& source, const ImagePaintingOptions&) = 0; > virtual ImageDrawResult drawTiledImage(Image&, const FloatRect& destination, const FloatPoint& source, const FloatSize& tileSize, const FloatSize& spacing, const ImagePaintingOptions&) = 0; > virtual ImageDrawResult drawTiledImage(Image&, const FloatRect& destination, const FloatRect& source, const FloatSize& tileScaleFactor, Image::TileRule hRule, Image::TileRule vRule, const ImagePaintingOptions&) = 0; >-#if USE(CG) || USE(CAIRO) || USE(DIRECT2D) >- virtual void drawNativeImage(const NativeImagePtr&, const FloatSize& selfSize, const FloatRect& destRect, const FloatRect& srcRect, const ImagePaintingOptions&) = 0; >-#endif >+ >+ virtual void drawNativeImage(const NativeImagePtr&, const FloatSize& selfSize, const FloatRect& destRect, const FloatRect& srcRect, const ImagePaintingOptions&, CachedImage*) = 0; > virtual bool drawImageBuffer(ImageBuffer&, const FloatRect& destination, const FloatRect& source, const ImagePaintingOptions&) = 0; > virtual void drawPattern(Image&, const FloatRect& destRect, const FloatRect& srcRect, const AffineTransform&, const FloatPoint& phase, const FloatSize& spacing, const ImagePaintingOptions&) = 0; > >diff --git a/Source/WebCore/platform/graphics/ImageObserver.h b/Source/WebCore/platform/graphics/ImageObserver.h >index 8b089e594c1a..b4d710ac6730 100644 >--- a/Source/WebCore/platform/graphics/ImageObserver.h >+++ b/Source/WebCore/platform/graphics/ImageObserver.h >@@ -45,10 +45,13 @@ public: > virtual void encodedDataStatusChanged(const Image&, EncodedDataStatus) { }; > virtual void decodedSizeChanged(const Image&, long long delta) = 0; > >+ virtual void drawNativeImage(const Image&, GraphicsContext&, const NativeImagePtr&, const FloatSize& imageSize, const FloatRect& destRect, const FloatRect& srcRect, const ImagePaintingOptions&) = 0; > virtual void didDraw(const Image&) = 0; > > virtual bool canDestroyDecodedData(const Image&) = 0; > virtual void imageFrameAvailable(const Image&, ImageAnimatingState, const IntRect* changeRect = nullptr, DecodingStatus = DecodingStatus::Invalid) = 0; >+ virtual void nativeImageWillBeDestroyed(const Image&, const NativeImagePtr&) = 0; >+ > virtual void changedInRect(const Image&, const IntRect* changeRect = nullptr) = 0; > virtual void scheduleRenderingUpdate(const Image&) = 0; > }; >diff --git a/Source/WebCore/platform/graphics/ImageSource.cpp b/Source/WebCore/platform/graphics/ImageSource.cpp >index 775032239a5d..45515c59a1ff 100644 >--- a/Source/WebCore/platform/graphics/ImageSource.cpp >+++ b/Source/WebCore/platform/graphics/ImageSource.cpp >@@ -130,8 +130,10 @@ void ImageSource::destroyDecodedData(size_t frameCount, size_t excludeFrame) > ASSERT(frameCount <= m_frames.size()); > > for (size_t index = 0; index < frameCount; ++index) { >- if (index == excludeFrame) >+ if (index == excludeFrame || !m_frames[index].nativeImage()) > continue; >+ if (m_image && m_image->imageObserver()) >+ m_image->imageObserver()->nativeImageWillBeDestroyed(*m_image, m_frames[index].nativeImage()); > decodedSize += m_frames[index].clearImage(); > } > >diff --git a/Source/WebCore/platform/graphics/cairo/GraphicsContextImplCairo.cpp b/Source/WebCore/platform/graphics/cairo/GraphicsContextImplCairo.cpp >index 048642851f9d..fe9049527afe 100644 >--- a/Source/WebCore/platform/graphics/cairo/GraphicsContextImplCairo.cpp >+++ b/Source/WebCore/platform/graphics/cairo/GraphicsContextImplCairo.cpp >@@ -279,7 +279,7 @@ ImageDrawResult GraphicsContextImplCairo::drawTiledImage(Image& image, const Flo > return GraphicsContextImpl::drawTiledImageImpl(graphicsContext(), image, destination, source, tileScaleFactor, hRule, vRule, imagePaintingOptions); > } > >-void GraphicsContextImplCairo::drawNativeImage(const NativeImagePtr& image, const FloatSize& imageSize, const FloatRect& destRect, const FloatRect& srcRect, const ImagePaintingOptions& options) >+void GraphicsContextImplCairo::drawNativeImage(const NativeImagePtr& image, const FloatSize& imageSize, const FloatRect& destRect, const FloatRect& srcRect, const ImagePaintingOptions& options, CachedImage*) > { > UNUSED_PARAM(imageSize); > auto& state = graphicsContext().state(); >diff --git a/Source/WebCore/platform/graphics/cairo/GraphicsContextImplCairo.h b/Source/WebCore/platform/graphics/cairo/GraphicsContextImplCairo.h >index d30bf869d746..2c1c70154c1f 100644 >--- a/Source/WebCore/platform/graphics/cairo/GraphicsContextImplCairo.h >+++ b/Source/WebCore/platform/graphics/cairo/GraphicsContextImplCairo.h >@@ -75,7 +75,7 @@ public: > ImageDrawResult drawTiledImage(Image&, const FloatRect&, const FloatPoint&, const FloatSize&, const FloatSize&, const ImagePaintingOptions&) override; > ImageDrawResult drawTiledImage(Image&, const FloatRect&, const FloatRect&, const FloatSize&, Image::TileRule, Image::TileRule, const ImagePaintingOptions&) override; > >- void drawNativeImage(const NativeImagePtr&, const FloatSize&, const FloatRect&, const FloatRect&, const ImagePaintingOptions&) override; >+ void drawNativeImage(const NativeImagePtr&, const FloatSize&, const FloatRect&, const FloatRect&, const ImagePaintingOptions&, CachedImage*) override; > bool drawImageBuffer(ImageBuffer&, const FloatRect&, const FloatRect&, const ImagePaintingOptions&) override; > void drawPattern(Image&, const FloatRect&, const FloatRect&, const AffineTransform&, const FloatPoint&, const FloatSize&, const ImagePaintingOptions&) override; > >diff --git a/Source/WebCore/platform/graphics/displaylists/DisplayListItems.cpp b/Source/WebCore/platform/graphics/displaylists/DisplayListItems.cpp >index 78c75b9d5ca9..f15c770e1da4 100644 >--- a/Source/WebCore/platform/graphics/displaylists/DisplayListItems.cpp >+++ b/Source/WebCore/platform/graphics/displaylists/DisplayListItems.cpp >@@ -704,7 +704,7 @@ static TextStream& operator<<(TextStream& ts, const DrawTiledScaledImage& item) > return ts; > } > >-DrawNativeImage::DrawNativeImage(const NativeImagePtr& image, const FloatSize& imageSize, const FloatRect& destRect, const FloatRect& srcRect, const ImagePaintingOptions& options) >+DrawNativeImage::DrawNativeImage(const NativeImageType& image, const FloatSize& imageSize, const FloatRect& destRect, const FloatRect& srcRect, const ImagePaintingOptions& options) > : DrawingItem(ItemType::DrawNativeImage) > , m_image(image) > , m_imageSize(imageSize) >@@ -718,7 +718,8 @@ DrawNativeImage::~DrawNativeImage() = default; > > void DrawNativeImage::apply(GraphicsContext& context) const > { >- context.drawNativeImage(m_image, m_imageSize, m_destinationRect, m_srcRect, m_options); >+ ASSERT(nativeImagePtr()); >+ context.drawNativeImage(nativeImagePtr(), m_imageSize, m_destinationRect, m_srcRect, m_options); > } > > static TextStream& operator<<(TextStream& ts, const DrawNativeImage& item) >diff --git a/Source/WebCore/platform/graphics/displaylists/DisplayListItems.h b/Source/WebCore/platform/graphics/displaylists/DisplayListItems.h >index 2e38d74a5c9c..3b64d3ba3407 100644 >--- a/Source/WebCore/platform/graphics/displaylists/DisplayListItems.h >+++ b/Source/WebCore/platform/graphics/displaylists/DisplayListItems.h >@@ -1435,27 +1435,50 @@ Optional<Ref<DrawTiledScaledImage>> DrawTiledScaledImage::decode(Decoder& decode > > class DrawNativeImage : public DrawingItem { > public: >- static Ref<DrawNativeImage> create(const NativeImagePtr& image, const FloatSize& imageSize, const FloatRect& destRect, const FloatRect& srcRect, const ImagePaintingOptions& options) >+#if ENABLE(GPU_PROCESS) >+ using NativeImageType = Variant<NativeImagePtr, RemoteResourceIdentifier>; >+ >+ RemoteResourceIdentifier remoteResourceIdentifier() const >+ { >+ if (!WTF::holds_alternative<RemoteResourceIdentifier>(m_image)) >+ return { }; >+ return WTF::get<RemoteResourceIdentifier>(m_image); >+ } >+ >+ NativeImagePtr nativeImagePtr() const >+ { >+ if (!WTF::holds_alternative<NativeImagePtr>(m_image)) >+ return nullptr; >+ return WTF::get<NativeImagePtr>(m_image); >+ } >+#else >+ using NativeImageType = NativeImagePtr; >+ >+ NativeImagePtr nativeImagePtr() const { return m_image; } >+#endif >+ static Ref<DrawNativeImage> create(const NativeImageType& image, const FloatSize& imageSize, const FloatRect& destRect, const FloatRect& srcRect, const ImagePaintingOptions& options) > { > return adoptRef(*new DrawNativeImage(image, imageSize, destRect, srcRect, options)); > } > > WEBCORE_EXPORT virtual ~DrawNativeImage(); > >+ FloatSize imageSize() const { return m_imageSize; } > FloatRect source() const { return m_srcRect; } > FloatRect destinationRect() const { return m_destinationRect; } >+ ImagePaintingOptions options() const { return m_options; } > > template<class Encoder> void encode(Encoder&) const; > template<class Decoder> static Optional<Ref<DrawNativeImage>> decode(Decoder&); > > private: >- WEBCORE_EXPORT DrawNativeImage(const NativeImagePtr&, const FloatSize& selfSize, const FloatRect& destRect, const FloatRect& srcRect, const ImagePaintingOptions&); >+ WEBCORE_EXPORT DrawNativeImage(const NativeImageType&, const FloatSize& imageSize, const FloatRect& destRect, const FloatRect& srcRect, const ImagePaintingOptions&); > > void apply(GraphicsContext&) const override; > > Optional<FloatRect> localBounds(const GraphicsContext&) const override { return m_destinationRect; } > >- NativeImagePtr m_image; >+ NativeImageType m_image; > FloatSize m_imageSize; > FloatRect m_destinationRect; > FloatRect m_srcRect; >@@ -1475,7 +1498,7 @@ void DrawNativeImage::encode(Encoder& encoder) const > template<class Decoder> > Optional<Ref<DrawNativeImage>> DrawNativeImage::decode(Decoder& decoder) > { >- Optional<NativeImagePtr> image; >+ Optional<NativeImageType> image; > decoder >> image; > if (!image) > return WTF::nullopt; >diff --git a/Source/WebCore/platform/graphics/displaylists/DisplayListRecorder.cpp b/Source/WebCore/platform/graphics/displaylists/DisplayListRecorder.cpp >index 9358f6ec7590..95575d0f414c 100644 >--- a/Source/WebCore/platform/graphics/displaylists/DisplayListRecorder.cpp >+++ b/Source/WebCore/platform/graphics/displaylists/DisplayListRecorder.cpp >@@ -132,8 +132,14 @@ ImageDrawResult Recorder::drawTiledImage(Image& image, const FloatRect& destinat > return ImageDrawResult::DidRecord; > } > >-void Recorder::drawNativeImage(const NativeImagePtr& image, const FloatSize& imageSize, const FloatRect& destRect, const FloatRect& srcRect, const ImagePaintingOptions& options) >+void Recorder::drawNativeImage(const NativeImagePtr& image, const FloatSize& imageSize, const FloatRect& destRect, const FloatRect& srcRect, const ImagePaintingOptions& options, CachedImage* cachedImage) > { >+ if (m_delegate && cachedImage) { >+ if (auto item = m_delegate->createDrawNativeImageItem(image, imageSize, destRect, srcRect, options, *cachedImage)) { >+ appendItemAndUpdateExtent(static_reference_cast<DrawingItem>(item.releaseNonNull())); >+ return; >+ } >+ } > appendItemAndUpdateExtent(DrawNativeImage::create(image, imageSize, destRect, srcRect, options)); > } > >diff --git a/Source/WebCore/platform/graphics/displaylists/DisplayListRecorder.h b/Source/WebCore/platform/graphics/displaylists/DisplayListRecorder.h >index fe1b90062149..e140be11d7d6 100644 >--- a/Source/WebCore/platform/graphics/displaylists/DisplayListRecorder.h >+++ b/Source/WebCore/platform/graphics/displaylists/DisplayListRecorder.h >@@ -35,6 +35,7 @@ > namespace WebCore { > > enum class AlphaPremultiplication : uint8_t; >+class CachedImage; > class FloatPoint; > class FloatRect; > class GlyphBuffer; >@@ -68,6 +69,7 @@ public: > public: > virtual ~Delegate() { } > virtual RefPtr<Item> createDrawImageBufferItem(ImageBuffer&, const FloatRect&, const FloatRect&, const ImagePaintingOptions&) { return nullptr; } >+ virtual RefPtr<Item> createDrawNativeImageItem(const NativeImagePtr&, const FloatSize&, const FloatRect&, const FloatRect&, const ImagePaintingOptions&, CachedImage&) { return nullptr; } > virtual void willAppendItem(const Item&) { }; > }; > >@@ -107,7 +109,7 @@ private: > ImageDrawResult drawTiledImage(Image&, const FloatRect& destination, const FloatPoint& source, const FloatSize& tileSize, const FloatSize& spacing, const ImagePaintingOptions&) override; > ImageDrawResult drawTiledImage(Image&, const FloatRect& destination, const FloatRect& source, const FloatSize& tileScaleFactor, Image::TileRule hRule, Image::TileRule vRule, const ImagePaintingOptions&) override; > >- void drawNativeImage(const NativeImagePtr&, const FloatSize& selfSize, const FloatRect& destRect, const FloatRect& srcRect, const ImagePaintingOptions&) override; >+ void drawNativeImage(const NativeImagePtr&, const FloatSize& selfSize, const FloatRect& destRect, const FloatRect& srcRect, const ImagePaintingOptions&, CachedImage*) override; > bool drawImageBuffer(ImageBuffer&, const FloatRect& destination, const FloatRect& source, const ImagePaintingOptions&) override; > void drawPattern(Image&, const FloatRect& destRect, const FloatRect& srcRect, const AffineTransform&, const FloatPoint& phase, const FloatSize& spacing, const ImagePaintingOptions&) override; > >diff --git a/Source/WebCore/platform/graphics/nicosia/cairo/NicosiaCairoOperationRecorder.cpp b/Source/WebCore/platform/graphics/nicosia/cairo/NicosiaCairoOperationRecorder.cpp >index 4e24eebadb65..7c14f3e7ee33 100644 >--- a/Source/WebCore/platform/graphics/nicosia/cairo/NicosiaCairoOperationRecorder.cpp >+++ b/Source/WebCore/platform/graphics/nicosia/cairo/NicosiaCairoOperationRecorder.cpp >@@ -549,7 +549,7 @@ ImageDrawResult CairoOperationRecorder::drawTiledImage(Image& image, const Float > return GraphicsContextImpl::drawTiledImageImpl(graphicsContext(), image, destination, source, tileScaleFactor, hRule, vRule, imagePaintingOptions); > } > >-void CairoOperationRecorder::drawNativeImage(const NativeImagePtr& image, const FloatSize& imageSize, const FloatRect& destRect, const FloatRect& srcRect, const ImagePaintingOptions& options) >+void CairoOperationRecorder::drawNativeImage(const NativeImagePtr& image, const FloatSize& imageSize, const FloatRect& destRect, const FloatRect& srcRect, const ImagePaintingOptions& options, CachedImage*) > { > struct DrawNativeImage final : PaintingOperation, OperationData<RefPtr<cairo_surface_t>, FloatRect, FloatRect, ImagePaintingOptions, float, Cairo::ShadowState> { > virtual ~DrawNativeImage() = default; >diff --git a/Source/WebCore/platform/graphics/nicosia/cairo/NicosiaCairoOperationRecorder.h b/Source/WebCore/platform/graphics/nicosia/cairo/NicosiaCairoOperationRecorder.h >index 38093d4135b4..1d49013c89cf 100644 >--- a/Source/WebCore/platform/graphics/nicosia/cairo/NicosiaCairoOperationRecorder.h >+++ b/Source/WebCore/platform/graphics/nicosia/cairo/NicosiaCairoOperationRecorder.h >@@ -69,7 +69,7 @@ private: > WebCore::ImageDrawResult drawTiledImage(WebCore::Image&, const WebCore::FloatRect&, const WebCore::FloatRect&, const WebCore::FloatSize&, WebCore::Image::TileRule, WebCore::Image::TileRule, const WebCore::ImagePaintingOptions&) override; > > bool drawImageBuffer(WebCore::ImageBuffer&, const WebCore::FloatRect& destination, const WebCore::FloatRect& source, const WebCore::ImagePaintingOptions&) override; >- void drawNativeImage(const WebCore::NativeImagePtr&, const WebCore::FloatSize&, const WebCore::FloatRect&, const WebCore::FloatRect&, const WebCore::ImagePaintingOptions&) override; >+ void drawNativeImage(const WebCore::NativeImagePtr&, const WebCore::FloatSize&, const WebCore::FloatRect&, const WebCore::FloatRect&, const WebCore::ImagePaintingOptions&, WebCore::CachedImage*) override; > void drawPattern(WebCore::Image&, const WebCore::FloatRect&, const WebCore::FloatRect&, const WebCore::AffineTransform&, const WebCore::FloatPoint&, const WebCore::FloatSize&, const WebCore::ImagePaintingOptions&) override; > > void drawRect(const WebCore::FloatRect&, float) override; >diff --git a/Source/WebKit/ChangeLog b/Source/WebKit/ChangeLog >index 63bab7e24f2b..28c12319031d 100644 >--- a/Source/WebKit/ChangeLog >+++ b/Source/WebKit/ChangeLog >@@ -1,3 +1,31 @@ >+2020-10-11 Said Abou-Hallawa <sabouhallawa@apple.com> >+ >+ [GPU Process] Cache the BitmapImage frame in GPU Process and allow referencing it with its RemoteResourceIdentifier >+ https://bugs.webkit.org/show_bug.cgi?id=217596 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ * GPUProcess/graphics/RemoteRenderingBackendProxy.cpp: >+ (WebKit::RemoteRenderingBackendProxy::cacheNativeImage): >+ * GPUProcess/graphics/RemoteRenderingBackendProxy.h: >+ * GPUProcess/graphics/RemoteRenderingBackendProxy.messages.in: >+ * GPUProcess/graphics/RemoteResourceCacheProxy.cpp: >+ (WebKit::RemoteResourceCacheProxy::cacheNativeImage): >+ (WebKit::RemoteResourceCacheProxy::drawNativeImageItem const): >+ (WebKit::RemoteResourceCacheProxy::applyResourceItem const): >+ (WebKit::RemoteResourceCacheProxy::releaseRemoteResource): >+ * GPUProcess/graphics/RemoteResourceCacheProxy.h: >+ * WebProcess/GPU/graphics/RemoteImageBuffer.h: >+ * WebProcess/GPU/graphics/RemoteRenderingBackend.cpp: >+ (WebKit::RemoteRenderingBackend::createDrawNativeImageItem): >+ (WebKit::RemoteRenderingBackend::remoteCacheNativeImage): >+ * WebProcess/GPU/graphics/RemoteRenderingBackend.h: >+ * WebProcess/GPU/graphics/RemoteResourceCache.cpp: >+ (WebKit::RemoteResourceCache::createDrawNativeImageItem): >+ (WebKit::RemoteResourceCache::releaseNativeImage): >+ (WebKit::RemoteResourceCache::findNativeImageForClient): >+ * WebProcess/GPU/graphics/RemoteResourceCache.h: >+ > 2020-10-11 Said Abou-Hallawa <sabouhallawa@apple.com> > > [GPU Process] Clean the DisplayList recording of the NativeImage >diff --git a/Source/WebKit/GPUProcess/graphics/RemoteRenderingBackendProxy.cpp b/Source/WebKit/GPUProcess/graphics/RemoteRenderingBackendProxy.cpp >index ca3262432177..c1a31cbc94b6 100644 >--- a/Source/WebKit/GPUProcess/graphics/RemoteRenderingBackendProxy.cpp >+++ b/Source/WebKit/GPUProcess/graphics/RemoteRenderingBackendProxy.cpp >@@ -103,6 +103,11 @@ void RemoteRenderingBackendProxy::getImageData(WebCore::AlphaPremultiplication o > completionHandler(IPC::ImageDataReference(WTFMove(imageData))); > } > >+void RemoteRenderingBackendProxy::cacheNativeImage(const NativeImagePtr& image, RemoteResourceIdentifier remoteResourceIdentifier) >+{ >+ m_remoteResourceCacheProxy.cacheNativeImage(image, remoteResourceIdentifier); >+} >+ > void RemoteRenderingBackendProxy::releaseRemoteResource(RemoteResourceIdentifier remoteResourceIdentifier) > { > m_remoteResourceCacheProxy.releaseRemoteResource(remoteResourceIdentifier); >diff --git a/Source/WebKit/GPUProcess/graphics/RemoteRenderingBackendProxy.h b/Source/WebKit/GPUProcess/graphics/RemoteRenderingBackendProxy.h >index 9f68f2b4737e..af96262dc307 100644 >--- a/Source/WebKit/GPUProcess/graphics/RemoteRenderingBackendProxy.h >+++ b/Source/WebKit/GPUProcess/graphics/RemoteRenderingBackendProxy.h >@@ -81,6 +81,7 @@ private: > void flushImageBufferDrawingContext(const WebCore::DisplayList::DisplayList&, WebCore::RemoteResourceIdentifier); > void flushImageBufferDrawingContextAndCommit(const WebCore::DisplayList::DisplayList&, ImageBufferFlushIdentifier, WebCore::RemoteResourceIdentifier); > void getImageData(WebCore::AlphaPremultiplication outputFormat, WebCore::IntRect srcRect, WebCore::RemoteResourceIdentifier, CompletionHandler<void(IPC::ImageDataReference&&)>&&); >+ void cacheNativeImage(const WebCore::NativeImagePtr&, WebCore::RemoteResourceIdentifier); > void releaseRemoteResource(WebCore::RemoteResourceIdentifier); > > RemoteResourceCacheProxy m_remoteResourceCacheProxy { *this }; >diff --git a/Source/WebKit/GPUProcess/graphics/RemoteRenderingBackendProxy.messages.in b/Source/WebKit/GPUProcess/graphics/RemoteRenderingBackendProxy.messages.in >index 26cf1361fdab..b31cc673e8a3 100644 >--- a/Source/WebKit/GPUProcess/graphics/RemoteRenderingBackendProxy.messages.in >+++ b/Source/WebKit/GPUProcess/graphics/RemoteRenderingBackendProxy.messages.in >@@ -27,6 +27,7 @@ messages -> RemoteRenderingBackendProxy NotRefCounted { > void FlushImageBufferDrawingContext(WebCore::DisplayList::DisplayList displayList, WebCore::RemoteResourceIdentifier remoteResourceIdentifier) > void FlushImageBufferDrawingContextAndCommit(WebCore::DisplayList::DisplayList displayList, WebKit::ImageBufferFlushIdentifier flushIdentifier, WebCore::RemoteResourceIdentifier remoteResourceIdentifier) > GetImageData(enum:uint8_t WebCore::AlphaPremultiplication outputFormat, WebCore::IntRect srcRect, WebCore::RemoteResourceIdentifier remoteResourceIdentifier) -> (IPC::ImageDataReference imageData) Synchronous >+ void CacheNativeImage(WebCore::NativeImagePtr image, WebCore::RemoteResourceIdentifier remoteResourceIdentifier) > void ReleaseRemoteResource(WebCore::RemoteResourceIdentifier remoteResourceIdentifier) > } > >diff --git a/Source/WebKit/GPUProcess/graphics/RemoteResourceCacheProxy.cpp b/Source/WebKit/GPUProcess/graphics/RemoteResourceCacheProxy.cpp >index 9e9b84c670e9..60af59695c4f 100644 >--- a/Source/WebKit/GPUProcess/graphics/RemoteResourceCacheProxy.cpp >+++ b/Source/WebKit/GPUProcess/graphics/RemoteResourceCacheProxy.cpp >@@ -86,10 +86,35 @@ RefPtr<ImageData> RemoteResourceCacheProxy::getImageData(AlphaPremultiplication > return nullptr; > } > >+void RemoteResourceCacheProxy::cacheNativeImage(const NativeImagePtr& image, RemoteResourceIdentifier remoteResourceIdentifier) >+{ >+ auto addResult = m_remoteNativeImageHashMap.add(remoteResourceIdentifier, image); >+ ASSERT_UNUSED(addResult, addResult.isNewEntry); >+} >+ >+bool RemoteResourceCacheProxy::drawNativeImageItem(const DisplayList::Item& item, GraphicsContext& context) const >+{ >+ auto& drawItem = static_cast<const DisplayList::DrawNativeImage&>(item); >+ auto remoteResourceIdentifier = drawItem.remoteResourceIdentifier(); >+ if (!remoteResourceIdentifier) >+ return false; >+ >+ auto image = m_remoteNativeImageHashMap.get(remoteResourceIdentifier); >+ if (!image) >+ return false; >+ >+ context.drawNativeImage(image, drawItem.imageSize(), drawItem.destinationRect(), drawItem.source(), drawItem.options()); >+ return true; >+} >+ > bool RemoteResourceCacheProxy::drawImageBufferItem(const DisplayList::Item& item, GraphicsContext& context) const > { > auto& drawItem = static_cast<const DisplayList::DrawImageBuffer&>(item); >- auto image = m_remoteImageBufferHashMap.get(drawItem.remoteResourceIdentifier()); >+ auto remoteResourceIdentifier = drawItem.remoteResourceIdentifier(); >+ if (!remoteResourceIdentifier) >+ return false; >+ >+ auto image = m_remoteImageBufferHashMap.get(remoteResourceIdentifier); > if (!image) > return false; > >@@ -101,6 +126,8 @@ bool RemoteResourceCacheProxy::applyResourceItem(const DisplayList::Item& item, > { > if (item.type() == DisplayList::ItemType::DrawImageBuffer) > return drawImageBufferItem(item, context); >+ if (item.type() == DisplayList::ItemType::DrawNativeImage) >+ return drawNativeImageItem(item, context); > return false; > } > >@@ -108,6 +135,8 @@ void RemoteResourceCacheProxy::releaseRemoteResource(RemoteResourceIdentifier re > { > if (m_remoteImageBufferHashMap.remove(remoteResourceIdentifier)) > return; >+ if (m_remoteNativeImageHashMap.remove(remoteResourceIdentifier)) >+ return; > // Caching the remote resource should have happened before releasing it. > ASSERT_NOT_REACHED(); > } >diff --git a/Source/WebKit/GPUProcess/graphics/RemoteResourceCacheProxy.h b/Source/WebKit/GPUProcess/graphics/RemoteResourceCacheProxy.h >index 2c5301d02eee..23e422c8aadc 100644 >--- a/Source/WebKit/GPUProcess/graphics/RemoteResourceCacheProxy.h >+++ b/Source/WebKit/GPUProcess/graphics/RemoteResourceCacheProxy.h >@@ -50,16 +50,21 @@ public: > WebCore::ImageBuffer* flushDrawingContextAndCommit(const WebCore::DisplayList::DisplayList&, WebCore::RemoteResourceIdentifier); > RefPtr<WebCore::ImageData> getImageData(WebCore::AlphaPremultiplication outputFormat, const WebCore::IntRect& srcRect, WebCore::RemoteResourceIdentifier) const; > >+ void cacheNativeImage(const WebCore::NativeImagePtr&, WebCore::RemoteResourceIdentifier); >+ > bool applyResourceItem(const WebCore::DisplayList::Item&, WebCore::GraphicsContext&) const; > > void releaseRemoteResource(WebCore::RemoteResourceIdentifier); > > private: > using RemoteImageBufferHashMap = HashMap<WebCore::RemoteResourceIdentifier, std::unique_ptr<WebCore::ImageBuffer>>; >+ using RemoteNativeImageHashMap = HashMap<WebCore::RemoteResourceIdentifier, WebCore::NativeImagePtr>; > > bool drawImageBufferItem(const WebCore::DisplayList::Item&, WebCore::GraphicsContext&) const; >+ bool drawNativeImageItem(const WebCore::DisplayList::Item&, WebCore::GraphicsContext&) const; > > RemoteImageBufferHashMap m_remoteImageBufferHashMap; >+ RemoteNativeImageHashMap m_remoteNativeImageHashMap; > RemoteRenderingBackendProxy& m_remoteRenderingBackendProxy; > }; > >diff --git a/Source/WebKit/WebProcess/GPU/graphics/RemoteImageBuffer.h b/Source/WebKit/WebProcess/GPU/graphics/RemoteImageBuffer.h >index 08a1deaea0a6..e851dd038b77 100644 >--- a/Source/WebKit/WebProcess/GPU/graphics/RemoteImageBuffer.h >+++ b/Source/WebKit/WebProcess/GPU/graphics/RemoteImageBuffer.h >@@ -136,6 +136,13 @@ protected: > return m_remoteRenderingBackend->createDrawImageBufferItem(image, destRect, srcRect, options, m_remoteResourceIdentifier); > } > >+ RefPtr<WebCore::DisplayList::Item> createDrawNativeImageItem(const WebCore::NativeImagePtr& image, const WebCore::FloatSize& imageSize, const WebCore::FloatRect& destRect, const WebCore::FloatRect& srcRect, const WebCore::ImagePaintingOptions& options, WebCore::CachedImage& cachedImage) override >+ { >+ if (!m_remoteRenderingBackend) >+ return nullptr; >+ return m_remoteRenderingBackend->createDrawNativeImageItem(image, imageSize, destRect, srcRect, options, cachedImage, m_remoteResourceIdentifier); >+ } >+ > void willAppendItem(const WebCore::DisplayList::Item&) override > { > constexpr size_t DisplayListBatchSize = 512; >diff --git a/Source/WebKit/WebProcess/GPU/graphics/RemoteRenderingBackend.cpp b/Source/WebKit/WebProcess/GPU/graphics/RemoteRenderingBackend.cpp >index 1a04a9e45a9d..06578142c6ae 100644 >--- a/Source/WebKit/WebProcess/GPU/graphics/RemoteRenderingBackend.cpp >+++ b/Source/WebKit/WebProcess/GPU/graphics/RemoteRenderingBackend.cpp >@@ -101,6 +101,11 @@ RefPtr<DisplayList::Item> RemoteRenderingBackend::createDrawImageBufferItem(Imag > return m_remoteResourceCache.createDrawImageBufferItem(image, destRect, srcRect, options, remoteClientIdentifier); > } > >+RefPtr<DisplayList::Item> RemoteRenderingBackend::createDrawNativeImageItem(const NativeImagePtr& image, const FloatSize& imageSize, const FloatRect& destRect, const FloatRect& srcRect, const ImagePaintingOptions& options, CachedImage& cachedImage, RemoteResourceIdentifier remoteClientIdentifier) >+{ >+ return m_remoteResourceCache.createDrawNativeImageItem(image, imageSize, destRect, srcRect, options, cachedImage, remoteClientIdentifier); >+} >+ > void RemoteRenderingBackend::releaseRemoteClient(RemoteResourceIdentifier remoteClientIdentifier) > { > m_remoteResourceCache.releaseRemoteClient(remoteClientIdentifier); >@@ -132,6 +137,13 @@ ImageBufferFlushIdentifier RemoteRenderingBackend::remoteFlushDrawingContextAndC > return sentFlushIdentifier; > } > >+RemoteResourceIdentifier RemoteRenderingBackend::remoteCacheNativeImage(const NativeImagePtr& image) >+{ >+ RemoteResourceIdentifier remoteResourceIdentifier = RemoteResourceIdentifier::generate(); >+ send(Messages::RemoteRenderingBackendProxy::CacheNativeImage(image, remoteResourceIdentifier), m_renderingBackendIdentifier); >+ return remoteResourceIdentifier; >+} >+ > void RemoteRenderingBackend::remoteReleaseRemoteResource(RemoteResourceIdentifier remoteResourceIdentifier) > { > send(Messages::RemoteRenderingBackendProxy::ReleaseRemoteResource(remoteResourceIdentifier), m_renderingBackendIdentifier); >diff --git a/Source/WebKit/WebProcess/GPU/graphics/RemoteRenderingBackend.h b/Source/WebKit/WebProcess/GPU/graphics/RemoteRenderingBackend.h >index 96efe7c754ff..e93330e75ac8 100644 >--- a/Source/WebKit/WebProcess/GPU/graphics/RemoteRenderingBackend.h >+++ b/Source/WebKit/WebProcess/GPU/graphics/RemoteRenderingBackend.h >@@ -72,6 +72,7 @@ public: > std::unique_ptr<WebCore::ImageBuffer> createImageBuffer(const WebCore::FloatSize&, WebCore::ShouldAccelerate, float resolutionScale, WebCore::ColorSpace); > void releaseImageBuffer(WebCore::ImageBuffer&); > RefPtr<WebCore::DisplayList::Item> createDrawImageBufferItem(WebCore::ImageBuffer&, const WebCore::FloatRect& destRect, const WebCore::FloatRect& srcRect, const WebCore::ImagePaintingOptions&, WebCore::RemoteResourceIdentifier); >+ RefPtr<WebCore::DisplayList::Item> createDrawNativeImageItem(const WebCore::NativeImagePtr&, const WebCore::FloatSize& imageSize, const WebCore::FloatRect& destRect, const WebCore::FloatRect& srcRect, const WebCore::ImagePaintingOptions&, WebCore::CachedImage&, WebCore::RemoteResourceIdentifier); > void releaseRemoteClient(WebCore::RemoteResourceIdentifier); > > // Messages to be sent. >@@ -79,6 +80,7 @@ public: > RefPtr<WebCore::ImageData> remoteGetImageData(WebCore::AlphaPremultiplication outputFormat, const WebCore::IntRect& srcRect, WebCore::RemoteResourceIdentifier); > void remoteFlushDrawingContext(const WebCore::DisplayList::DisplayList&, WebCore::RemoteResourceIdentifier); > ImageBufferFlushIdentifier remoteFlushDrawingContextAndCommit(const WebCore::DisplayList::DisplayList&, WebCore::RemoteResourceIdentifier); >+ WebCore::RemoteResourceIdentifier remoteCacheNativeImage(const WebCore::NativeImagePtr&); > void remoteReleaseRemoteResource(WebCore::RemoteResourceIdentifier); > > private: >diff --git a/Source/WebKit/WebProcess/GPU/graphics/RemoteResourceCache.cpp b/Source/WebKit/WebProcess/GPU/graphics/RemoteResourceCache.cpp >index 0a86c17e3aea..63f972c10dd1 100644 >--- a/Source/WebKit/WebProcess/GPU/graphics/RemoteResourceCache.cpp >+++ b/Source/WebKit/WebProcess/GPU/graphics/RemoteResourceCache.cpp >@@ -84,6 +84,14 @@ RefPtr<WebCore::DisplayList::Item> RemoteResourceCache::createDrawImageBufferIte > return WebCore::DisplayList::DrawImageBuffer::create(remoteResourceIdentifier, destRect, srcRect, options); > } > >+RefPtr<WebCore::DisplayList::Item> RemoteResourceCache::createDrawNativeImageItem(const NativeImagePtr& image, const FloatSize& imageSize, const FloatRect& destRect, const FloatRect& srcRect, const ImagePaintingOptions& options, CachedImage& cachedImage, RemoteResourceIdentifier remoteClientIdentifier) >+{ >+ auto remoteResourceIdentifier = findNativeImageForClient(cachedImage, image, remoteClientIdentifier); >+ if (!remoteResourceIdentifier) >+ return nullptr; >+ return WebCore::DisplayList::DrawNativeImage::create(remoteResourceIdentifier, imageSize, destRect, srcRect, options); >+} >+ > RemoteResourceIdentifier RemoteResourceCache::releaseImageBuffer(ImageBuffer& image) > { > // Remove the resource from the cache. >@@ -99,6 +107,17 @@ RemoteResourceIdentifier RemoteResourceCache::releaseImageBuffer(ImageBuffer& im > return remoteResourceIdentifier; > } > >+RemoteResourceIdentifier RemoteResourceCache::releaseNativeImage(const WebCore::NativeImagePtr& image) >+{ >+ // Remove the resource from the cache. >+ auto remoteResourceIdentifier = m_remoteNativeImageHashMap.take(image); >+ >+ // Tell the GPU process to remove this resource unless it's pending replaying back. >+ if (remoteResourceIdentifier) >+ releaseRemoteResourcePendingRemoveClients(remoteResourceIdentifier); >+ return remoteResourceIdentifier; >+} >+ > RemoteResourceIdentifier RemoteResourceCache::findImageBufferForClient(ImageBuffer& image, RemoteResourceIdentifier remoteClientIdentifier) > { > auto remoteResourceIdentifier = m_remoteImageBufferHashMap.get(&image); >@@ -106,6 +125,17 @@ RemoteResourceIdentifier RemoteResourceCache::findImageBufferForClient(ImageBuff > return remoteResourceIdentifier; > } > >+RemoteResourceIdentifier RemoteResourceCache::findNativeImageForClient(WebCore::CachedImage& cachedImage, const NativeImagePtr& image, RemoteResourceIdentifier remoteClientIdentifier) >+{ >+ auto remoteResourceIdentifier = m_remoteNativeImageHashMap.ensure(image, [&] { >+ cachedImage.addClient(*this); >+ return m_remoteRenderingBackend.remoteCacheNativeImage(image); >+ }).iterator->value; >+ >+ addRemoteClient(remoteResourceIdentifier, remoteClientIdentifier); >+ return remoteResourceIdentifier; >+} >+ > void RemoteResourceCache::addRemoteClient(RemoteResourceIdentifier remoteResourceIdentifier, RemoteResourceIdentifier remoteClientIdentifier) > { > if (!remoteResourceIdentifier) >diff --git a/Source/WebKit/WebProcess/GPU/graphics/RemoteResourceCache.h b/Source/WebKit/WebProcess/GPU/graphics/RemoteResourceCache.h >index b48a954d8dc9..e17801151c6a 100644 >--- a/Source/WebKit/WebProcess/GPU/graphics/RemoteResourceCache.h >+++ b/Source/WebKit/WebProcess/GPU/graphics/RemoteResourceCache.h >@@ -29,6 +29,7 @@ > > #include "ImageBufferBackendHandle.h" > #include "ImageBufferFlushIdentifier.h" >+#include <WebCore/CachedImageClient.h> > #include <WebCore/ImageBuffer.h> > #include <WebCore/RemoteResourceIdentifier.h> > #include <wtf/HashMap.h> >@@ -49,7 +50,7 @@ namespace WebKit { > class RemoteImageBufferMessageHandler; > class RemoteRenderingBackend; > >-class RemoteResourceCache { >+class RemoteResourceCache : public WebCore::CachedImageClient { > public: > RemoteResourceCache(RemoteRenderingBackend&); > >@@ -58,23 +59,30 @@ public: > void commitImageBufferFlushContext(ImageBufferFlushIdentifier, WebCore::RemoteResourceIdentifier); > > RefPtr<WebCore::DisplayList::Item> createDrawImageBufferItem(WebCore::ImageBuffer&, const WebCore::FloatRect& destRect, const WebCore::FloatRect& srcRect, const WebCore::ImagePaintingOptions&, WebCore::RemoteResourceIdentifier); >+ RefPtr<WebCore::DisplayList::Item> createDrawNativeImageItem(const WebCore::NativeImagePtr&, const WebCore::FloatSize& imageSize, const WebCore::FloatRect& destRect, const WebCore::FloatRect& srcRect, const WebCore::ImagePaintingOptions&, WebCore::CachedImage&, WebCore::RemoteResourceIdentifier); > > WebCore::RemoteResourceIdentifier releaseImageBuffer(WebCore::ImageBuffer&); >+ WebCore::RemoteResourceIdentifier releaseNativeImage(const WebCore::NativeImagePtr&); > void releaseRemoteClient(WebCore::RemoteResourceIdentifier remoteClientIdentifier); > > private: > using RemoteClientsHashSet = HashSet<WebCore::RemoteResourceIdentifier>; > using RemoteImageBufferHashMap = HashMap<WebCore::ImageBuffer*, WebCore::RemoteResourceIdentifier>; >+ using RemoteNativeImageHashMap = HashMap<WebCore::NativeImagePtr, WebCore::RemoteResourceIdentifier>; > using RemoteResourceClientsHashMap = HashMap<WebCore::RemoteResourceIdentifier, RemoteClientsHashSet>; > using RemoteImageBufferMessageHandlerHashMap = HashMap<WebCore::RemoteResourceIdentifier, RemoteImageBufferMessageHandler*>; > >+ void nativeImageWillBeDestroyed(const WebCore::NativeImagePtr& image) override { releaseNativeImage(image); } >+ > WebCore::RemoteResourceIdentifier findImageBufferForClient(WebCore::ImageBuffer&, WebCore::RemoteResourceIdentifier); >+ WebCore::RemoteResourceIdentifier findNativeImageForClient(WebCore::CachedImage&, const WebCore::NativeImagePtr&, WebCore::RemoteResourceIdentifier remoteClientIdentifier); > > void addRemoteClient(WebCore::RemoteResourceIdentifier, WebCore::RemoteResourceIdentifier remoteClientIdentifier); > Vector<WebCore::RemoteResourceIdentifier> removeRemoteClient(RemoteResourceClientsHashMap&, WebCore::RemoteResourceIdentifier remoteClientIdentifier); > void releaseRemoteResourcePendingRemoveClients(WebCore::RemoteResourceIdentifier); > > RemoteImageBufferHashMap m_remoteImageBufferHashMap; >+ RemoteNativeImageHashMap m_remoteNativeImageHashMap; > RemoteResourceClientsHashMap m_remoteResourceClientsHashMap; > RemoteResourceClientsHashMap m_remoteResourceClientsPendingReleaseHashMap; > RemoteImageBufferMessageHandlerHashMap m_remoteImageBufferMessageHandlerHashMap;
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 217596
:
411086
|
411096
|
411098
|
411125
|
412064
|
412070
|
412586
|
412945
|
412947
|
413740
|
413742
|
413754
|
413761
|
413786
|
413842
|
413847
|
413875