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
bug-217596-20201021204903.patch (text/plain), 123.38 KB, created by
Said Abou-Hallawa
on 2020-10-21 20:49:04 PDT
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
Said Abou-Hallawa
Created:
2020-10-21 20:49:04 PDT
Size:
123.38 KB
patch
obsolete
>Subversion Revision: 268711 >diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog >index 0faeb9117dd81ac95f2e0d0bcedfe798ee3975d1..91ebdefa068387010556f53fda98fba1d7762fdc 100644 >--- a/Source/WebCore/ChangeLog >+++ b/Source/WebCore/ChangeLog >@@ -1,3 +1,166 @@ >+2020-10-21 Said Abou-Hallawa <said@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. For the details about the life cycle of the cached NativeImages, >+ see the WebKit ChangeLog. >+ >+ * 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: >+ We need the CachedImage to be sent along with the NativeImage to >+ GraphicsContext::drawNativeImage(). >+ >+ (WebCore::CachedImageClient::nativeImageWillBeDestroyed): >+ RemoteResourceCacheProxy is a superclass of CachedImageClient. It will be >+ called for any NativeImage before it is deleted. >+ >+ * platform/graphics/BitmapImage.cpp: >+ (WebCore::drawNativeImage): >+ (WebCore::BitmapImage::draw): >+ (WebCore::BitmapImage::subsamplingLevelForScaleFactor): >+ * platform/graphics/GraphicsContext.cpp: >+ (WebCore::GraphicsContext::drawNativeImage): >+ (WebCore::GraphicsContext::drawImage): >+ (WebCore::GraphicsContext::drawTiledImage): >+ * platform/graphics/GraphicsContext.h: >+ (WebCore::GraphicsContext::drawNativeImage): >+ * platform/graphics/GraphicsContextImpl.h: >+ * platform/graphics/ImageObserver.h: >+ * platform/graphics/ImageSource.cpp: >+ (WebCore::ImageSource::destroyDecodedData): >+ Notify the CachedImageClients before destroying the NativeImage. >+ >+ * platform/graphics/cairo/GraphicsContextImplCairo.cpp: >+ (WebCore::GraphicsContextImplCairo::drawNativeImage): >+ * platform/graphics/cairo/GraphicsContextImplCairo.h: >+ * platform/graphics/displaylists/DisplayListItems.cpp: >+ (WebCore::DisplayList::DrawNativeImage::DrawNativeImage): >+ (WebCore::DisplayList::DrawNativeImage::apply const): >+ DrawNativeImage can hold a NativeImagePtr or RemoteResourceIdentifier. >+ Only the one with the NativeImagePtr will be replayed back here. The one >+ with RemoteResourceIdentifier (which is RemoteImageBuffer right now) is >+ responsible for replaying it back. >+ >+ * platform/graphics/displaylists/DisplayListItems.h: >+ (WebCore::DisplayList::DrawNativeImage::create): >+ (WebCore::DisplayList::DrawNativeImage::remoteResourceIdentifier const): >+ (WebCore::DisplayList::DrawNativeImage::nativeImagePtr const): >+ (WebCore::DisplayList::DrawNativeImage::imageSize const): >+ (WebCore::DisplayList::DrawNativeImage::options const): >+ (WebCore::DisplayList::DrawNativeImage::decode): >+ Allow DrawNativeImage to hold RemoteResourceIdentifier. In this case, it >+ will be sent to the GPU process to be replayed back. >+ >+ * platform/graphics/displaylists/DisplayListRecorder.cpp: >+ (WebCore::DisplayList::Recorder::drawNativeImage): >+ * platform/graphics/displaylists/DisplayListRecorder.h: >+ (WebCore::DisplayList::Recorder::Delegate::lockRemoteNativeImage): >+ * platform/graphics/nicosia/cairo/NicosiaCairoOperationRecorder.cpp: >+ (Nicosia::CairoOperationRecorder::drawNativeImage): >+ * platform/graphics/nicosia/cairo/NicosiaCairoOperationRecorder.h: >+ >+ >+2020-10-20 Said Abou-Hallawa <said@apple.com> >+ >+ [GPU Process]: Implement DisplayList::DrawImageBuffer item >+ https://bugs.webkit.org/show_bug.cgi?id=217566 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ Add the DrawImageBuffer DisplayList item. It will be used only for GPU >+ rendering. The remoteResourceIdentifier of the source ImageBuffer will >+ be recorded. For details on how drawing an ImageBuffer to another >+ ImageBuffer works see the WebKit ChangeLog. >+ >+ * platform/graphics/GraphicsContext.cpp: >+ (WebCore::GraphicsContext::drawImageBuffer): >+ * platform/graphics/GraphicsContextImpl.h: >+ * platform/graphics/cairo/GraphicsContextImplCairo.cpp: >+ (WebCore::GraphicsContextImplCairo::drawImageBuffer): >+ * platform/graphics/cairo/GraphicsContextImplCairo.h: >+ * platform/graphics/displaylists/DisplayList.h: >+ * platform/graphics/displaylists/DisplayListItems.cpp: >+ (WebCore::DisplayList::Item::sizeInBytes): >+ (WebCore::DisplayList::DrawImageBuffer::DrawImageBuffer): >+ (WebCore::DisplayList::DrawImageBuffer::apply const): >+ (WebCore::DisplayList::operator<<): >+ * platform/graphics/displaylists/DisplayListItems.h: >+ (WebCore::DisplayList::DrawImageBuffer::create): >+ (WebCore::DisplayList::DrawImageBuffer::remoteResourceIdentifier const): >+ (WebCore::DisplayList::DrawImageBuffer::source const): >+ (WebCore::DisplayList::DrawImageBuffer::destinationRect const): >+ (WebCore::DisplayList::DrawImageBuffer::options const): >+ (WebCore::DisplayList::DrawImageBuffer::encode const): >+ (WebCore::DisplayList::DrawImageBuffer::decode): >+ (WebCore::DisplayList::Item::encode const): >+ (WebCore::DisplayList::Item::decode): >+ * platform/graphics/displaylists/DisplayListRecorder.cpp: >+ (WebCore::DisplayList::Recorder::Recorder): >+ (WebCore::DisplayList::Recorder::drawImageBuffer): >+ * platform/graphics/displaylists/DisplayListRecorder.h: >+ (WebCore::DisplayList::Recorder::Delegate::lockRemoteImageBuffer): >+ * platform/graphics/nicosia/cairo/NicosiaCairoOperationRecorder.cpp: >+ (Nicosia::CairoOperationRecorder::drawImageBuffer): >+ * platform/graphics/nicosia/cairo/NicosiaCairoOperationRecorder.h: >+ >+2020-10-19 Said Abou-Hallawa <sabouhallawa@apple.com> >+ >+ [GPU Process]: Introduce RemoteResourceCacheProxy to manage the remote resources in Web Process >+ https://bugs.webkit.org/show_bug.cgi?id=217558 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ Rename Recorder::Observer to Recorder::Delegate because it will be responsible >+ for creating DisplayListItems in future patches. So it will not be just >+ an observer. Also do not make DisplayList::ImageBuffer a superclass of it. >+ RemoteImageBufferProxy, which is a superclass of DisplayList::ImageBuffer, >+ will be the superclass of Recorder::Delegate. >+ >+ Make ImageBufferBackend::isAccelerated a static member instead of a virtual >+ method. RemoteRenderingBackendProxy would want to know whether the backend >+ of an ImageBuffer isAccelerated or not without having to create it. >+ ImageBufferBackend::isAccelerated will be set to false and >+ ImageBufferIOSurfaceBackend::isAccelerated will be set to true. >+ >+ * platform/graphics/ConcreteImageBuffer.h: >+ * platform/graphics/ImageBuffer.h: >+ (WebCore::ImageBuffer::remoteResourceIdentifier const): >+ * platform/graphics/ImageBufferBackend.h: >+ (WebCore::ImageBufferBackend::isAccelerated const): Deleted. >+ * platform/graphics/RemoteResourceIdentifier.h: >+ * platform/graphics/cg/ImageBufferIOSurfaceBackend.cpp: >+ (WebCore::ImageBufferIOSurfaceBackend::isAccelerated const): Deleted. >+ * platform/graphics/cg/ImageBufferIOSurfaceBackend.h: >+ * platform/graphics/displaylists/DisplayListDrawingContext.cpp: >+ (WebCore::DisplayList::DrawingContext::DrawingContext): >+ * platform/graphics/displaylists/DisplayListDrawingContext.h: >+ (WebCore::DisplayList::DrawingContext::DrawingContext): >+ * platform/graphics/displaylists/DisplayListImageBuffer.h: >+ (WebCore::DisplayList::ImageBuffer::ImageBuffer): >+ * platform/graphics/displaylists/DisplayListRecorder.cpp: >+ (WebCore::DisplayList::Recorder::Recorder): >+ (WebCore::DisplayList::Recorder::willAppendItem): >+ * platform/graphics/displaylists/DisplayListRecorder.h: >+ (WebCore::DisplayList::Recorder::Delegate::~Delegate): >+ (WebCore::DisplayList::Recorder::Observer::~Observer): Deleted. >+ (WebCore::DisplayList::Recorder::Observer::willAppendItem): Deleted. >+ > 2020-10-19 Alexey Shvayka <shvaikalesh@gmail.com> > > [WebIDL] %Interface%.prototype.constructor should be defined on [[Set]] receiver >diff --git a/Source/WebKit/ChangeLog b/Source/WebKit/ChangeLog >index d7d684bcc0d76b173378092a27977ed27e0b7716..8c3f5d151f1516bed76beaac879a5b8ae6a42617 100644 >--- a/Source/WebKit/ChangeLog >+++ b/Source/WebKit/ChangeLog >@@ -1,3 +1,177 @@ >+2020-10-21 Said Abou-Hallawa <said@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!). >+ >+ This is the drawing sequence of a BitmapImage frame in the Web Process: >+ >+ 1) BitmapImage::draw() calls ImageObserver::drawNativeImage(). >+ 2) CachedImage::CachedImageObserver::drawNativeImage() finds the associated >+ CachedImage and calls GraphicsContext::drawNativeImage(). >+ 3) Recorder::drawNativeImage() calls the lockRemoteNativeImage() of its >+ delegate which is RemoteImageBufferPorxy in the case of 2D canvas. >+ 4) RemoteImageBufferPorxy calls lockRemoteNativeImageForRemoteClient() of >+ the RemoteResourceCacheProxy of its RemoteRenderingBackendProxy. >+ 5) RemoteResourceCacheProxy finds the NativeImage of the given CachedImage >+ in its cache. If it does not find it, it adds it to the cache, assigns >+ a RemoteResourceIdentifier to it and asks the GPU Process to cache it >+ also, mark the cached NativeImage a locked resource for the >+ RemoteResourceCacheProxy and returns the RemoteResourceIdentifier. >+ >+ The drawing sequence in the GPU Process is the following: >+ >+ 1) When flushing a DisplyList happens, DisplayList::Replayer::reply() >+ calls apply() of its delegate (which is RemoteImageBuffer). >+ 2) RemoteImageBuffer::apply() calls RemoteRenderingBackend::applyResourceItem() >+ which will check if the type of the Item is DrawNativeImage. >+ 3) If it is a DrawNativeImage, RemoteRenderingBackend finds the cached >+ NativeImage in its RemoteResourceCache given the RemoteResourceIdentifier >+ and draws it to the context of the RemoteImageBuffer. >+ >+ 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 RemoteResourceCacheProxy registers itself as a CachedImageClient >+ of this CachedImage, RemoteResourceCacheProxy::nativeImageWillBeDestroyed() >+ will be called. >+ 5) The cached NativeImage will be removed 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) RemoteResourceCache::releaseRemoteResource releases the cached >+ NativeImage via RemoteRenderingBackend. >+ >+ * GPUProcess/graphics/RemoteImageBuffer.h: >+ (WebKit::RemoteImageBuffer::apply): Deleted. >+ * GPUProcess/graphics/RemoteRenderingBackend.cpp: >+ (WebKit::RemoteRenderingBackend::applyResourceItem): >+ (WebKit::RemoteRenderingBackend::applyMediaItem): >+ (WebKit::RemoteRenderingBackend::cacheNativeImage): >+ * GPUProcess/graphics/RemoteRenderingBackend.h: >+ * GPUProcess/graphics/RemoteRenderingBackend.messages.in: >+ * GPUProcess/graphics/RemoteResourceCache.cpp: >+ (WebKit::RemoteResourceCache::cacheNativeImage): >+ (WebKit::RemoteResourceCache::cachedNativeImage): >+ (WebKit::RemoteResourceCache::releaseRemoteResource): >+ * GPUProcess/graphics/RemoteResourceCache.h: >+ * WebProcess/GPU/graphics/RemoteImageBufferProxy.h: >+ * WebProcess/GPU/graphics/RemoteRenderingBackendProxy.cpp: >+ (WebKit::RemoteRenderingBackendProxy::cacheNativeImage): >+ * WebProcess/GPU/graphics/RemoteRenderingBackendProxy.h: >+ * WebProcess/GPU/graphics/RemoteResourceCacheProxy.cpp: >+ (WebKit::RemoteResourceCacheProxy::nativeImageWillBeDestroyed): >+ (WebKit::RemoteResourceCacheProxy::lockRemoteNativeImageForRemoteClient): >+ * WebProcess/GPU/graphics/RemoteResourceCacheProxy.h: >+ >+2020-10-20 Said Abou-Hallawa <said@apple.com> >+ >+ [GPU Process]: Implement DisplayList::DrawImageBuffer item >+ https://bugs.webkit.org/show_bug.cgi?id=217566 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ The sequence in the Web Process is the following: >+ >+ -- GraphicsContext::drawImageBuffer() uses DisplayList::Recorder to check >+ whether it is appropriate to create a DrawImageBuffer item or not. >+ >+ -- DisplayList::Recorder::drawImageBuffer() uses the delegate to see if >+ the ImageBuffer is remote or not and whether it can be locked till >+ replaying back the DisplayList in the GPU side. >+ >+ -- RemoteImageBufferProxy inherits DisplayList::Recorder::Delegate. So its >+ lockRemoteImageBuffer() is called. >+ >+ -- If the ImageBuffer can be locked, a DrawImageBufferItem is created with >+ the ImageBuffer::remoteResourceIdentifier(). >+ >+ The sequence in the GPU Process is the following: >+ >+ -- When replaying back the DisplayList, DisplayList::Replayer will call >+ its delegate to check if it wants to apply the DrawImageBuffer. >+ >+ -- Because RemoteImageBuffer inherits DisplayList::Replayer::Delegate, >+ RemoteImageBuffer::apply() will be called. >+ >+ -- RemoteImageBuffer will call RemoteRenderingBackend::applyResourceItem() >+ which will check whether the item's remoteResourceIdentifier is one of >+ the ImageBuffers in its RemoteResourceCache or not. >+ >+ -- If there is a cached ImageBuffer, RemoteRenderingBackend::applyResourceItem() >+ will draw to GraphicsContext. >+ >+ * GPUProcess/graphics/RemoteImageBuffer.h: >+ * GPUProcess/graphics/RemoteRenderingBackend.cpp: >+ (WebKit::RemoteRenderingBackend::applyResourceItem): >+ * GPUProcess/graphics/RemoteRenderingBackend.h: >+ * WebProcess/GPU/graphics/RemoteImageBufferProxy.h: >+ * WebProcess/GPU/graphics/RemoteResourceCacheProxy.cpp: >+ (WebKit::RemoteResourceCacheProxy::releaseImageBuffer): >+ (WebKit::RemoteResourceCacheProxy::lockRemoteImageBufferForRemoteClient): >+ (WebKit::RemoteResourceCacheProxy::lockRemoteResourceForRemoteClient): >+ (WebKit::RemoteResourceCacheProxy::releaseRemoteResource): >+ (WebKit::RemoteResourceCacheProxy::unlockRemoteResourcesForRemoteClient): >+ * WebProcess/GPU/graphics/RemoteResourceCacheProxy.h: >+ >+2020-10-19 Said Abou-Hallawa <sabouhallawa@apple.com> >+ >+ [GPU Process]: Introduce RemoteResourceCacheProxy to manage the remote resources in Web Process >+ https://bugs.webkit.org/show_bug.cgi?id=217558 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ Remove RemoteImageBufferMessageHandlerProxy and move sending the messages >+ to RemoteRenderingBackendProxy. >+ >+ To allow casting ImageBuffer to RemoteImageBufferProxy, a new method named >+ remoteResourceIdentifier() is added to IamgeBuffer and it is only overridden >+ by RemoteImageBufferProxy. This method is used in SPECIALIZE_TYPE_TRAITS >+ macros along with IamgeBuffer::isAccelerated(). >+ >+ Introduce RemoteResourceCacheProxy which will manage caching and releasing >+ the RemoteImageBufferProxy. Caching NativeImage will be added to it in >+ future patches. More about controlling the life cycles of remote resources >+ will be added with supporting drawing remote resources to remote client. >+ >+ * Sources.txt: >+ * WebKit.xcodeproj/project.pbxproj: >+ * WebProcess/GPU/graphics/PlatformRemoteImageBufferProxy.h: >+ (isType): >+ * WebProcess/GPU/graphics/RemoteImageBufferMessageHandlerProxy.cpp: Removed. >+ * WebProcess/GPU/graphics/RemoteImageBufferMessageHandlerProxy.h: Removed. >+ * WebProcess/GPU/graphics/RemoteImageBufferProxy.h: >+ (WebKit::RemoteImageBufferProxy::create): >+ (WebKit::RemoteImageBufferProxy::~RemoteImageBufferProxy): >+ (WebKit::RemoteImageBufferProxy::createBackend): >+ (WebKit::RemoteImageBufferProxy::commitFlushDisplayList): >+ (WebKit::RemoteImageBufferProxy::RemoteImageBufferProxy): >+ (WebKit::RemoteImageBufferProxy::isPendingFlush const): >+ * WebProcess/GPU/graphics/RemoteRenderingBackendProxy.cpp: >+ (WebKit::RemoteRenderingBackendProxy::createImageBuffer): >+ (WebKit::RemoteRenderingBackendProxy::getImageData): >+ (WebKit::RemoteRenderingBackendProxy::flushDisplayList): >+ (WebKit::RemoteRenderingBackendProxy::flushDisplayListAndCommit): >+ (WebKit::RemoteRenderingBackendProxy::releaseRemoteResource): >+ (WebKit::RemoteRenderingBackendProxy::imageBufferBackendWasCreated): >+ (WebKit::RemoteRenderingBackendProxy::flushDisplayListWasCommitted): >+ * WebProcess/GPU/graphics/RemoteRenderingBackendProxy.h: >+ (WebKit::RemoteRenderingBackendProxy::remoteResourceCacheProxy): >+ (WebKit::RemoteRenderingBackendProxy::renderingBackendIdentifier const): Deleted. >+ * WebProcess/GPU/graphics/RemoteResourceCacheProxy.cpp: Copied from Source/WebCore/platform/graphics/RemoteResourceIdentifier.h. >+ (WebKit::RemoteResourceCacheProxy::RemoteResourceCacheProxy): >+ (WebKit::RemoteResourceCacheProxy::cacheImageBuffer): >+ (WebKit::RemoteResourceCacheProxy::cachedImageBuffer): >+ (WebKit::RemoteResourceCacheProxy::releaseImageBuffer): >+ * WebProcess/GPU/graphics/RemoteResourceCacheProxy.h: Copied from Source/WebKit/WebProcess/GPU/graphics/PlatformRemoteImageBufferProxy.h. >+ > 2020-10-19 Peng Liu <peng.liu6@apple.com> > > Two feature flag names are incorrect >diff --git a/Source/WebCore/html/ImageBitmap.cpp b/Source/WebCore/html/ImageBitmap.cpp >index ba1298e4f747c3bdb38fae80928268896bee9ef9..129dddd02dee83a13b09f4f2de134708e6ef7457 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 5cc933832574dcbebed82c2c0bce8f00c2bca72e..fea92925558bf5b384ce0267a04e18757fc9175d 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(*this, 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 72d59c1ff4845c23275920bc8d12f2734327f72c..8679832a4cc10bc64f7a3e54b259be53fa7128ff 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 ba6445b7ea7ed963d61bff30f28a9a4ed7f9c136..b92e79ce4e435a5840f05cd9e50aefa71b8cbad5 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(CachedImage&, 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 b1ed4e4e847997b59c7dfd3d26107566cca4713f..0af6c3d8b2318517789b072345f96743b1d7f6ee 100644 >--- a/Source/WebCore/platform/graphics/BitmapImage.cpp >+++ b/Source/WebCore/platform/graphics/BitmapImage.cpp >@@ -205,10 +205,10 @@ bool BitmapImage::notSolidColor() > } > #endif // ASSERT_ENABLED > >-static inline void drawNativeImage(const NativeImagePtr& image, 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(image); >+ IntSize subsampledImageSize = nativeImageSize(nativeImage); > if (options.orientation().usesWidthAsHeight()) > subsampledImageSize = subsampledImageSize.transposedSize(); > >@@ -217,7 +217,10 @@ static inline void drawNativeImage(const NativeImagePtr& image, GraphicsContext& > if (subsampledImageSize != srcSize) > adjustedSrcRect = mapRect(srcRect, FloatRect({ }, srcSize), FloatRect({ }, subsampledImageSize)); > >- context.drawNativeImage(image, 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/ConcreteImageBuffer.h b/Source/WebCore/platform/graphics/ConcreteImageBuffer.h >index c6c19e1289f48b020ea78bce39d106c3db93b07d..8697395fa4c8d0851c7b7790406e61c918fcea50 100644 >--- a/Source/WebCore/platform/graphics/ConcreteImageBuffer.h >+++ b/Source/WebCore/platform/graphics/ConcreteImageBuffer.h >@@ -50,13 +50,8 @@ public: > return nullptr; > return std::unique_ptr<ImageBufferType>(new ImageBufferType(WTFMove(backend), std::forward<Arguments>(arguments)...)); > } >- >- bool isAccelerated() const override >- { >- if (auto* backend = ensureBackendCreated()) >- return backend->isAccelerated(); >- return false; >- } >+ >+ bool isAccelerated() const override { return BackendType::isAccelerated; } > > protected: > ConcreteImageBuffer(std::unique_ptr<BackendType>&& backend) >diff --git a/Source/WebCore/platform/graphics/GraphicsContext.cpp b/Source/WebCore/platform/graphics/GraphicsContext.cpp >index 0dc0557b0d4f072edb98bc58c129b421a808f06d..7113d7f64e1a7628981fc0996fd68d868526b3d0 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; > } > >@@ -760,7 +760,7 @@ ImageDrawResult GraphicsContext::drawImage(Image& image, const FloatRect& destin > if (paintingDisabled()) > return ImageDrawResult::DidNothing; > >- if (m_impl) >+ if (m_impl && image.isPDFDocumentImage()) > return m_impl->drawImage(image, destination, source, options); > > InterpolationQualityMaintainer interpolationQualityForThisScope(*this, options.interpolationQuality()); >@@ -772,7 +772,7 @@ ImageDrawResult GraphicsContext::drawTiledImage(Image& image, const FloatRect& d > if (paintingDisabled()) > return ImageDrawResult::DidNothing; > >- if (m_impl) >+ if (m_impl && image.isPDFDocumentImage()) > return m_impl->drawTiledImage(image, destination, source, tileSize, spacing, options); > > InterpolationQualityMaintainer interpolationQualityForThisScope(*this, options.interpolationQuality()); >@@ -785,7 +785,7 @@ ImageDrawResult GraphicsContext::drawTiledImage(Image& image, const FloatRect& d > if (paintingDisabled()) > return ImageDrawResult::DidNothing; > >- if (m_impl) >+ if (m_impl && image.isPDFDocumentImage()) > return m_impl->drawTiledImage(image, destination, source, tileScaleFactor, hRule, vRule, options); > > if (hRule == Image::StretchTile && vRule == Image::StretchTile) { >@@ -812,6 +812,9 @@ void GraphicsContext::drawImageBuffer(ImageBuffer& image, const FloatRect& desti > if (paintingDisabled()) > return; > >+ if (m_impl && m_impl->drawImageBuffer(image, destination, source, options)) >+ return; >+ > InterpolationQualityMaintainer interpolationQualityForThisScope(*this, options.interpolationQuality()); > image.draw(*this, destination, source, options); > } >diff --git a/Source/WebCore/platform/graphics/GraphicsContext.h b/Source/WebCore/platform/graphics/GraphicsContext.h >index 0d1ca92d6045eb37a78d3e1897c26f42b9c76f3a..2519d7bea1821987f71ba70f441f2ffb05d2bf01 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 c2cafe336cc56995dc40ded40167e683b42a57f7..6d085ed8c42c65610c3b393ee27f869c86473d96 100644 >--- a/Source/WebCore/platform/graphics/GraphicsContextImpl.h >+++ b/Source/WebCore/platform/graphics/GraphicsContextImpl.h >@@ -73,7 +73,8 @@ public: > 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; > >- virtual void drawNativeImage(const NativeImagePtr&, const FloatSize& selfSize, const FloatRect& destRect, const FloatRect& srcRect, const ImagePaintingOptions&) = 0; >+ virtual bool drawImageBuffer(ImageBuffer&, const FloatRect& destination, const FloatRect& source, const ImagePaintingOptions&) = 0; >+ virtual void drawNativeImage(const NativeImagePtr&, const FloatSize& selfSize, const FloatRect& destRect, const FloatRect& srcRect, const ImagePaintingOptions&, CachedImage*) = 0; > virtual void drawPattern(Image&, const FloatRect& destRect, const FloatRect& srcRect, const AffineTransform&, const FloatPoint& phase, const FloatSize& spacing, const ImagePaintingOptions&) = 0; > > virtual void drawRect(const FloatRect&, float borderThickness) = 0; >diff --git a/Source/WebCore/platform/graphics/ImageBuffer.h b/Source/WebCore/platform/graphics/ImageBuffer.h >index 0ae9fcbd0588d4c4e1ef5af3cc7f12b612bf78da..8b94f91d9ba9146244f01b703cb347a8a9d7d198 100644 >--- a/Source/WebCore/platform/graphics/ImageBuffer.h >+++ b/Source/WebCore/platform/graphics/ImageBuffer.h >@@ -28,6 +28,7 @@ > #pragma once > > #include "ImageBufferBackend.h" >+#include "RemoteResourceIdentifier.h" > #include "RenderingMode.h" > > namespace WebCore { >@@ -60,6 +61,9 @@ public: > > WEBCORE_EXPORT virtual ~ImageBuffer() = default; > >+ virtual bool isAccelerated() const = 0; >+ virtual RemoteResourceIdentifier remoteResourceIdentifier() const { return { }; } >+ > virtual GraphicsContext& context() const = 0; > virtual void flushContext() = 0; > >@@ -104,8 +108,6 @@ public: > virtual bool copyToPlatformTexture(GraphicsContextGLOpenGL&, GCGLenum, PlatformGLObject, GCGLenum, bool, bool) const = 0; > virtual PlatformLayer* platformLayer() const = 0; > >- virtual bool isAccelerated() const = 0; >- > protected: > ImageBuffer() = default; > >diff --git a/Source/WebCore/platform/graphics/ImageBufferBackend.h b/Source/WebCore/platform/graphics/ImageBufferBackend.h >index 58fc14836d92aa20019f20feedc5571e9ab5e95c..cb5872567f0883b5bd02e0eecb8cefdbe710a8ec 100644 >--- a/Source/WebCore/platform/graphics/ImageBufferBackend.h >+++ b/Source/WebCore/platform/graphics/ImageBufferBackend.h >@@ -101,7 +101,7 @@ public: > virtual bool copyToPlatformTexture(GraphicsContextGLOpenGL&, GCGLenum, PlatformGLObject, GCGLenum, bool, bool) const { return false; } > > static constexpr bool isOriginAtUpperLeftCorner = false; >- virtual bool isAccelerated() const { return false; } >+ static constexpr bool isAccelerated = false; > > protected: > WEBCORE_EXPORT ImageBufferBackend(const FloatSize& logicalSize, const IntSize& backendSize, float resolutionScale, ColorSpace); >diff --git a/Source/WebCore/platform/graphics/ImageObserver.h b/Source/WebCore/platform/graphics/ImageObserver.h >index 8b089e594c1afccee4ffb50711597874695cb2de..b4d710ac6730c85dfeea75eab0f3db6676f60f2e 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 775032239a5d5abaa763f7a263ed7cb245982652..45515c59a1ff284cd8d2803837b085b5022d6c09 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/RemoteResourceIdentifier.h b/Source/WebCore/platform/graphics/RemoteResourceIdentifier.h >index 2af542dfec847abc371aa2f1e8e4b8dd9fb110e5..6690becdc8b4aae8524b3f6810fb9264c85c499c 100644 >--- a/Source/WebCore/platform/graphics/RemoteResourceIdentifier.h >+++ b/Source/WebCore/platform/graphics/RemoteResourceIdentifier.h >@@ -25,8 +25,6 @@ > > #pragma once > >-#if ENABLE(GPU_PROCESS) >- > #include <wtf/ObjectIdentifier.h> > > namespace WebCore { >@@ -35,5 +33,3 @@ enum RemoteResourceIdentifierType { }; > using RemoteResourceIdentifier = ObjectIdentifier<RemoteResourceIdentifierType>; > > } // namespace WebCore >- >-#endif // ENABLE(GPU_PROCESS) >diff --git a/Source/WebCore/platform/graphics/cairo/GraphicsContextImplCairo.cpp b/Source/WebCore/platform/graphics/cairo/GraphicsContextImplCairo.cpp >index b65b4d64406beb76c409d3e8c654975ca9f7eb63..8c8a1013baffdbe9e440a4212da591fb4dcbe89c 100644 >--- a/Source/WebCore/platform/graphics/cairo/GraphicsContextImplCairo.cpp >+++ b/Source/WebCore/platform/graphics/cairo/GraphicsContextImplCairo.cpp >@@ -279,7 +279,13 @@ 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) >+bool GraphicsContextImplCairo::drawImageBuffer(ImageBuffer&, const FloatRect&, const FloatRect&, const ImagePaintingOptions&) >+{ >+ // FIXME: Not implemented. >+ return false; >+} >+ >+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 e5e20748c6d7620f10cf2156628ef7e0be601c7b..f768f862023073dd661d6a9f75d8890656c6d9f8 100644 >--- a/Source/WebCore/platform/graphics/cairo/GraphicsContextImplCairo.h >+++ b/Source/WebCore/platform/graphics/cairo/GraphicsContextImplCairo.h >@@ -74,7 +74,9 @@ public: > ImageDrawResult drawImage(Image&, const FloatRect&, const FloatRect&, const ImagePaintingOptions&) override; > 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; >+ >+ bool drawImageBuffer(ImageBuffer&, const FloatRect&, const FloatRect&, const ImagePaintingOptions&) override; >+ void drawNativeImage(const NativeImagePtr&, const FloatSize&, const FloatRect&, const FloatRect&, const ImagePaintingOptions&, CachedImage*) override; > void drawPattern(Image&, const FloatRect&, const FloatRect&, const AffineTransform&, const FloatPoint&, const FloatSize&, const ImagePaintingOptions&) override; > > void drawRect(const FloatRect&, float) override; >diff --git a/Source/WebCore/platform/graphics/cg/ImageBufferIOSurfaceBackend.cpp b/Source/WebCore/platform/graphics/cg/ImageBufferIOSurfaceBackend.cpp >index c8065a9ec2514644f7405f9a5413f62235627154..dbc3b7eb8b3d1ad88d0ab3f0eef90a7c8d85e030 100644 >--- a/Source/WebCore/platform/graphics/cg/ImageBufferIOSurfaceBackend.cpp >+++ b/Source/WebCore/platform/graphics/cg/ImageBufferIOSurfaceBackend.cpp >@@ -190,11 +190,6 @@ IOSurface* ImageBufferIOSurfaceBackend::surface() > return m_surface.get(); > } > >-bool ImageBufferIOSurfaceBackend::isAccelerated() const >-{ >- return true; >-} >- > } // namespace WebCore > > #endif // HAVE(IOSURFACE) >diff --git a/Source/WebCore/platform/graphics/cg/ImageBufferIOSurfaceBackend.h b/Source/WebCore/platform/graphics/cg/ImageBufferIOSurfaceBackend.h >index 2418f1d45d53d45933b3904a288c6101f14bcc31..323094ea795c5d2483c884403124a9040cc740fb 100644 >--- a/Source/WebCore/platform/graphics/cg/ImageBufferIOSurfaceBackend.h >+++ b/Source/WebCore/platform/graphics/cg/ImageBufferIOSurfaceBackend.h >@@ -62,9 +62,9 @@ public: > RefPtr<ImageData> getImageData(AlphaPremultiplication outputFormat, const IntRect&) const override; > void putImageData(AlphaPremultiplication inputFormat, const ImageData&, const IntRect& srcRect, const IntPoint& destPoint, AlphaPremultiplication destFormat) override; > IOSurface* surface(); >- bool isAccelerated() const override; > > static constexpr bool isOriginAtUpperLeftCorner = true; >+ static constexpr bool isAccelerated = true; > > protected: > static RetainPtr<CGColorSpaceRef> contextColorSpace(const GraphicsContext&); >diff --git a/Source/WebCore/platform/graphics/displaylists/DisplayList.h b/Source/WebCore/platform/graphics/displaylists/DisplayList.h >index 506dabab0b8b4b731476bdf9f3095672b912ef19..322ecc1c1c415cef059fccfbaf508f93a59212ac 100644 >--- a/Source/WebCore/platform/graphics/displaylists/DisplayList.h >+++ b/Source/WebCore/platform/graphics/displaylists/DisplayList.h >@@ -64,6 +64,7 @@ enum class ItemType : uint8_t { > DrawImage, > DrawTiledImage, > DrawTiledScaledImage, >+ DrawImageBuffer, > DrawNativeImage, > DrawPattern, > DrawRect, >diff --git a/Source/WebCore/platform/graphics/displaylists/DisplayListDrawingContext.cpp b/Source/WebCore/platform/graphics/displaylists/DisplayListDrawingContext.cpp >index 23cc07e8ae442bdcea0d3674a5a8551c65cfdc87..d4617d3516f4f3e51d75d64434a6a39457a0001f 100644 >--- a/Source/WebCore/platform/graphics/displaylists/DisplayListDrawingContext.cpp >+++ b/Source/WebCore/platform/graphics/displaylists/DisplayListDrawingContext.cpp >@@ -33,9 +33,9 @@ > namespace WebCore { > namespace DisplayList { > >-DrawingContext::DrawingContext(const FloatSize& logicalSize, const AffineTransform& initialCTM, Recorder::Observer* observer) >+DrawingContext::DrawingContext(const FloatSize& logicalSize, const AffineTransform& initialCTM, Recorder::Delegate* delegate) > : m_context([&](GraphicsContext& displayListContext) { >- return makeUnique<Recorder>(displayListContext, m_displayList, GraphicsContextState(), FloatRect({ }, logicalSize), initialCTM, observer); >+ return makeUnique<Recorder>(displayListContext, m_displayList, GraphicsContextState(), FloatRect({ }, logicalSize), initialCTM, delegate); > }) > { > } >diff --git a/Source/WebCore/platform/graphics/displaylists/DisplayListDrawingContext.h b/Source/WebCore/platform/graphics/displaylists/DisplayListDrawingContext.h >index 7b673f32ad815a50081b7e7ab108131717fde543..22ed256e80ad293a052069b743088a1351f47cc0 100644 >--- a/Source/WebCore/platform/graphics/displaylists/DisplayListDrawingContext.h >+++ b/Source/WebCore/platform/graphics/displaylists/DisplayListDrawingContext.h >@@ -35,7 +35,7 @@ namespace DisplayList { > class DrawingContext { > WTF_MAKE_FAST_ALLOCATED; > public: >- WEBCORE_EXPORT DrawingContext(const FloatSize& logicalSize, const AffineTransform& initialCTM = { }, Recorder::Observer* = nullptr); >+ WEBCORE_EXPORT DrawingContext(const FloatSize& logicalSize, const AffineTransform& initialCTM = { }, Recorder::Delegate* = nullptr); > > GraphicsContext& context() const { return const_cast<DrawingContext&>(*this).m_context; } > WEBCORE_EXPORT Recorder& recorder(); >diff --git a/Source/WebCore/platform/graphics/displaylists/DisplayListImageBuffer.h b/Source/WebCore/platform/graphics/displaylists/DisplayListImageBuffer.h >index 6fd912dfb8fe11c098dd6126a8c878ac6ba7ae02..32599e062d7cf59d1dc2ead01e760d66e3f7ec3c 100644 >--- a/Source/WebCore/platform/graphics/displaylists/DisplayListImageBuffer.h >+++ b/Source/WebCore/platform/graphics/displaylists/DisplayListImageBuffer.h >@@ -32,7 +32,7 @@ namespace WebCore { > namespace DisplayList { > > template<typename BackendType> >-class ImageBuffer : public ConcreteImageBuffer<BackendType>, public Recorder::Observer { >+class ImageBuffer : public ConcreteImageBuffer<BackendType> { > using BaseConcreteImageBuffer = ConcreteImageBuffer<BackendType>; > > public: >@@ -48,12 +48,12 @@ public: > > ImageBuffer(std::unique_ptr<BackendType>&& dataBackend, const FloatSize& size) > : BaseConcreteImageBuffer(WTFMove(dataBackend)) >- , m_drawingContext(size, initialDrawingContextCTM(size), this) >+ , m_drawingContext(size, initialDrawingContextCTM(size)) > { > } > >- ImageBuffer(const FloatSize& size) >- : m_drawingContext(size, initialDrawingContextCTM(size), this) >+ ImageBuffer(const FloatSize& size, Recorder::Delegate* delegate = nullptr) >+ : m_drawingContext(size, initialDrawingContextCTM(size), delegate) > { > } > >diff --git a/Source/WebCore/platform/graphics/displaylists/DisplayListItems.cpp b/Source/WebCore/platform/graphics/displaylists/DisplayListItems.cpp >index 8d8b28193875c3166f81ed08e3d929961f7b8716..30035a02452d0a2ad1b4cc4db155d91b73b64fd3 100644 >--- a/Source/WebCore/platform/graphics/displaylists/DisplayListItems.cpp >+++ b/Source/WebCore/platform/graphics/displaylists/DisplayListItems.cpp >@@ -110,6 +110,8 @@ size_t Item::sizeInBytes(const Item& item) > return sizeof(downcast<DrawTiledImage>(item)); > case ItemType::DrawTiledScaledImage: > return sizeof(downcast<DrawTiledScaledImage>(item)); >+ case ItemType::DrawImageBuffer: >+ return sizeof(downcast<DrawImageBuffer>(item)); > case ItemType::DrawNativeImage: > return sizeof(downcast<DrawNativeImage>(item)); > case ItemType::DrawPattern: >@@ -738,7 +740,33 @@ 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) >+DrawImageBuffer::DrawImageBuffer(RemoteResourceIdentifier remoteResourceIdentifier, const FloatRect& destRect, const FloatRect& srcRect, const ImagePaintingOptions& options) >+ : DrawingItem(ItemType::DrawImageBuffer) >+ , m_remoteResourceIdentifier(remoteResourceIdentifier) >+ , m_destinationRect(destRect) >+ , m_srcRect(srcRect) >+ , m_options(options) >+{ >+} >+ >+DrawImageBuffer::~DrawImageBuffer() = default; >+ >+void DrawImageBuffer::apply(GraphicsContext&) const >+{ >+ // Should be handled by the delegate. >+ ASSERT_NOT_REACHED(); >+} >+ >+static TextStream& operator<<(TextStream& ts, const DrawImageBuffer& item) >+{ >+ ts << static_cast<const DrawingItem&>(item); >+ ts.dumpProperty("remote-resource-identifier", item.remoteResourceIdentifier()); >+ ts.dumpProperty("source-rect", item.source()); >+ ts.dumpProperty("dest-rect", item.destinationRect()); >+ return ts; >+} >+ >+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) >@@ -752,7 +780,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) >@@ -1496,6 +1525,7 @@ static TextStream& operator<<(TextStream& ts, const ItemType& type) > case ItemType::DrawImage: ts << "draw-image"; break; > case ItemType::DrawTiledImage: ts << "draw-tiled-image"; break; > case ItemType::DrawTiledScaledImage: ts << "draw-tiled-scaled-image"; break; >+ case ItemType::DrawImageBuffer: ts << "draw-image-buffer"; break; > case ItemType::DrawNativeImage: ts << "draw-native-image"; break; > case ItemType::DrawPattern: ts << "draw-pattern"; break; > case ItemType::DrawRect: ts << "draw-rect"; break; >@@ -1602,6 +1632,9 @@ TextStream& operator<<(TextStream& ts, const Item& item) > case ItemType::DrawTiledScaledImage: > ts << downcast<DrawTiledScaledImage>(item); > break; >+ case ItemType::DrawImageBuffer: >+ ts << downcast<DrawImageBuffer>(item); >+ break; > case ItemType::DrawNativeImage: > ts << downcast<DrawNativeImage>(item); > break; >diff --git a/Source/WebCore/platform/graphics/displaylists/DisplayListItems.h b/Source/WebCore/platform/graphics/displaylists/DisplayListItems.h >index d4ca98e648451b26cbf649835b1da2f3c23b4aff..2784199572572a80f4e69eae106d084a0932ce6b 100644 >--- a/Source/WebCore/platform/graphics/displaylists/DisplayListItems.h >+++ b/Source/WebCore/platform/graphics/displaylists/DisplayListItems.h >@@ -35,6 +35,7 @@ > #include "ImageData.h" > #include "MediaPlayerIdentifier.h" > #include "Pattern.h" >+#include "RemoteResourceIdentifier.h" > #include "SharedBuffer.h" > #include <wtf/TypeCasts.h> > >@@ -1533,29 +1534,112 @@ Optional<Ref<DrawTiledScaledImage>> DrawTiledScaledImage::decode(Decoder& decode > return DrawTiledScaledImage::create(*imageHandle->image, *destination, *source, *tileScaleFactor, hRule, vRule, *imagePaintingOptions); > } > >+class DrawImageBuffer : public DrawingItem { >+public: >+ static Ref<DrawImageBuffer> create(RemoteResourceIdentifier remoteResourceIdentifier, const FloatRect& destination, const FloatRect& source, const ImagePaintingOptions& options) >+ { >+ return adoptRef(*new DrawImageBuffer(remoteResourceIdentifier, destination, source, options)); >+ } >+ >+ WEBCORE_EXPORT virtual ~DrawImageBuffer(); >+ >+ RemoteResourceIdentifier remoteResourceIdentifier() const { return m_remoteResourceIdentifier; } >+ 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<DrawImageBuffer>> decode(Decoder&); >+ >+private: >+ WEBCORE_EXPORT DrawImageBuffer(RemoteResourceIdentifier, const FloatRect& destination, const FloatRect& source, const ImagePaintingOptions&); >+ >+ void apply(GraphicsContext&) const override; >+ >+ Optional<FloatRect> localBounds(const GraphicsContext&) const override { return m_destinationRect; } >+ >+ RemoteResourceIdentifier m_remoteResourceIdentifier; >+ FloatRect m_destinationRect; >+ FloatRect m_srcRect; >+ ImagePaintingOptions m_options; >+}; >+ >+template<class Encoder> >+void DrawImageBuffer::encode(Encoder& encoder) const >+{ >+ encoder << m_remoteResourceIdentifier; >+ encoder << m_destinationRect; >+ encoder << m_srcRect; >+ encoder << m_options; >+} >+ >+template<class Decoder> >+Optional<Ref<DrawImageBuffer>> DrawImageBuffer::decode(Decoder& decoder) >+{ >+ Optional<RemoteResourceIdentifier> remoteResourceIdentifier; >+ decoder >> remoteResourceIdentifier; >+ if (!remoteResourceIdentifier) >+ return WTF::nullopt; >+ >+ Optional<FloatRect> destination; >+ decoder >> destination; >+ if (!destination) >+ return WTF::nullopt; >+ >+ Optional<FloatRect> source; >+ decoder >> source; >+ if (!source) >+ return WTF::nullopt; >+ >+ Optional<ImagePaintingOptions> options; >+ decoder >> options; >+ if (!options) >+ return WTF::nullopt; >+ >+ return DrawImageBuffer::create(*remoteResourceIdentifier, *destination, *source, *options); >+} >+ > class DrawNativeImage : public DrawingItem { > public: >- static Ref<DrawNativeImage> create(const NativeImagePtr& image, const FloatSize& imageSize, const FloatRect& destRect, const FloatRect& srcRect, const ImagePaintingOptions& options) >+ using NativeImageType = Variant<NativeImagePtr, RemoteResourceIdentifier>; >+ >+ 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(); > >+ RemoteResourceIdentifier remoteResourceIdentifier() const >+ { >+ if (auto result = WTF::get_if<RemoteResourceIdentifier>(m_image)) >+ return *result; >+ return { }; >+ } >+ >+ NativeImagePtr nativeImagePtr() const >+ { >+ if (auto result = WTF::get_if<NativeImagePtr>(m_image)) >+ return *result; >+ return nullptr; >+ } >+ >+ 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; >@@ -1575,7 +1659,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; >@@ -3066,6 +3150,9 @@ void Item::encode(Encoder& encoder) const > case ItemType::DrawTiledScaledImage: > encoder << downcast<DrawTiledScaledImage>(*this); > break; >+ case ItemType::DrawImageBuffer: >+ encoder << downcast<DrawImageBuffer>(*this); >+ break; > case ItemType::DrawNativeImage: > encoder << downcast<DrawNativeImage>(*this); > break; >@@ -3263,6 +3350,10 @@ Optional<Ref<Item>> Item::decode(Decoder& decoder) > if (auto item = DrawTiledScaledImage::decode(decoder)) > return static_reference_cast<Item>(WTFMove(*item)); > break; >+ case ItemType::DrawImageBuffer: >+ if (auto item = DrawImageBuffer::decode(decoder)) >+ return static_reference_cast<Item>(WTFMove(*item)); >+ break; > case ItemType::DrawNativeImage: > if (auto item = DrawNativeImage::decode(decoder)) > return static_reference_cast<Item>(WTFMove(*item)); >@@ -3425,6 +3516,7 @@ SPECIALIZE_TYPE_TRAITS_DISPLAYLIST_ITEM(DrawGlyphs) > SPECIALIZE_TYPE_TRAITS_DISPLAYLIST_ITEM(DrawImage) > SPECIALIZE_TYPE_TRAITS_DISPLAYLIST_ITEM(DrawTiledImage) > SPECIALIZE_TYPE_TRAITS_DISPLAYLIST_ITEM(DrawTiledScaledImage) >+SPECIALIZE_TYPE_TRAITS_DISPLAYLIST_ITEM(DrawImageBuffer) > SPECIALIZE_TYPE_TRAITS_DISPLAYLIST_ITEM(DrawNativeImage) > SPECIALIZE_TYPE_TRAITS_DISPLAYLIST_ITEM(DrawPattern) > SPECIALIZE_TYPE_TRAITS_DISPLAYLIST_ITEM(DrawRect) >@@ -3487,6 +3579,7 @@ template<> struct EnumTraits<WebCore::DisplayList::ItemType> { > WebCore::DisplayList::ItemType::DrawImage, > WebCore::DisplayList::ItemType::DrawTiledImage, > WebCore::DisplayList::ItemType::DrawTiledScaledImage, >+ WebCore::DisplayList::ItemType::DrawImageBuffer, > WebCore::DisplayList::ItemType::DrawNativeImage, > WebCore::DisplayList::ItemType::DrawPattern, > WebCore::DisplayList::ItemType::DrawRect, >diff --git a/Source/WebCore/platform/graphics/displaylists/DisplayListRecorder.cpp b/Source/WebCore/platform/graphics/displaylists/DisplayListRecorder.cpp >index 68d2f680515eae558a0d4fbef6ab1a27e0a09eb4..533f020c5e312c7bb183b3a7283f61ff2de7efec 100644 >--- a/Source/WebCore/platform/graphics/displaylists/DisplayListRecorder.cpp >+++ b/Source/WebCore/platform/graphics/displaylists/DisplayListRecorder.cpp >@@ -30,6 +30,7 @@ > #include "DisplayListDrawingContext.h" > #include "DisplayListItems.h" > #include "GraphicsContext.h" >+#include "ImageBuffer.h" > #include "Logging.h" > #include <wtf/MathExtras.h> > #include <wtf/text/TextStream.h> >@@ -37,10 +38,10 @@ > namespace WebCore { > namespace DisplayList { > >-Recorder::Recorder(GraphicsContext& context, DisplayList& displayList, const GraphicsContextState& state, const FloatRect& initialClip, const AffineTransform& initialCTM, Observer* observer) >+Recorder::Recorder(GraphicsContext& context, DisplayList& displayList, const GraphicsContextState& state, const FloatRect& initialClip, const AffineTransform& initialCTM, Delegate* delegate) > : GraphicsContextImpl(context, initialClip, AffineTransform()) > , m_displayList(displayList) >- , m_observer(observer) >+ , m_delegate(delegate) > { > LOG_WITH_STREAM(DisplayLists, stream << "\nRecording with clip " << initialClip); > m_stateStack.append({ state, initialCTM, initialClip }); >@@ -93,8 +94,8 @@ static Ref<Item> createStateChangeItem(const GraphicsContextStateChange& changes > > void Recorder::willAppendItem(const Item& item) > { >- if (m_observer) >- m_observer->willAppendItem(item); >+ if (m_delegate) >+ m_delegate->willAppendItem(item); > > if (item.isDrawingItem() > #if USE(CG) >@@ -166,8 +167,23 @@ 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) >+bool Recorder::drawImageBuffer(WebCore::ImageBuffer& imageBuffer, const FloatRect& destRect, const FloatRect& srcRect, const ImagePaintingOptions& options) > { >+ if (!m_delegate || !m_delegate->lockRemoteImageBuffer(imageBuffer)) >+ return false; >+ >+ appendItemAndUpdateExtent(DrawImageBuffer::create(imageBuffer.remoteResourceIdentifier(), destRect, srcRect, options)); >+ return true; >+} >+ >+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 remoteResourceIdentifer = m_delegate->lockRemoteNativeImage(*cachedImage, image)) { >+ appendItemAndUpdateExtent(DrawNativeImage::create(remoteResourceIdentifer, imageSize, destRect, srcRect, options)); >+ 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 1b24c26c67288f817273a2d2aef2b4bc96e35c75..430da87ada363f8e5a88a1137bab6136ea7ee828 100644 >--- a/Source/WebCore/platform/graphics/displaylists/DisplayListRecorder.h >+++ b/Source/WebCore/platform/graphics/displaylists/DisplayListRecorder.h >@@ -28,12 +28,14 @@ > #include "DisplayList.h" > #include "GraphicsContextImpl.h" > #include "Image.h" // For Image::TileRule. >+#include "RemoteResourceIdentifier.h" > #include "TextFlags.h" > #include <wtf/Noncopyable.h> > > namespace WebCore { > > enum class AlphaPremultiplication : uint8_t; >+class CachedImage; > class FloatPoint; > class FloatRect; > class GlyphBuffer; >@@ -53,8 +55,8 @@ class Recorder : public GraphicsContextImpl { > WTF_MAKE_FAST_ALLOCATED; > WTF_MAKE_NONCOPYABLE(Recorder); > public: >- class Observer; >- WEBCORE_EXPORT Recorder(GraphicsContext&, DisplayList&, const GraphicsContextState&, const FloatRect& initialClip, const AffineTransform&, Observer* = nullptr); >+ class Delegate; >+ WEBCORE_EXPORT Recorder(GraphicsContext&, DisplayList&, const GraphicsContextState&, const FloatRect& initialClip, const AffineTransform&, Delegate* = nullptr); > WEBCORE_EXPORT virtual ~Recorder(); > > WEBCORE_EXPORT void putImageData(AlphaPremultiplication inputFormat, const ImageData&, const IntRect& srcRect, const IntPoint& destPoint, AlphaPremultiplication destFormat); >@@ -63,10 +65,12 @@ public: > > void appendItemAndUpdateExtent(Ref<DrawingItem>&&); > >- class Observer { >+ class Delegate { > public: >- virtual ~Observer() { } >+ virtual ~Delegate() { } > virtual void willAppendItem(const Item&) { }; >+ virtual bool lockRemoteImageBuffer(WebCore::ImageBuffer&) { return false; } >+ virtual RemoteResourceIdentifier lockRemoteNativeImage(CachedImage&, const WebCore::NativeImagePtr&) { return { }; } > }; > > private: >@@ -105,7 +109,8 @@ 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; >+ bool drawImageBuffer(WebCore::ImageBuffer&, const FloatRect& destination, const FloatRect& source, const ImagePaintingOptions&) override; >+ void drawNativeImage(const NativeImagePtr&, const FloatSize& selfSize, const FloatRect& destRect, const FloatRect& srcRect, const ImagePaintingOptions&, CachedImage*) override; > void drawPattern(Image&, const FloatRect& destRect, const FloatRect& srcRect, const AffineTransform&, const FloatPoint& phase, const FloatSize& spacing, const ImagePaintingOptions&) override; > > void drawRect(const FloatRect&, float borderThickness) override; >@@ -187,7 +192,7 @@ private: > ContextState& currentState(); > > DisplayList& m_displayList; >- Observer* m_observer; >+ Delegate* m_delegate; > > Vector<ContextState, 32> m_stateStack; > }; >diff --git a/Source/WebCore/platform/graphics/nicosia/cairo/NicosiaCairoOperationRecorder.cpp b/Source/WebCore/platform/graphics/nicosia/cairo/NicosiaCairoOperationRecorder.cpp >index 304facbab1521791daa86db1531753e38671084d..2cf72e77e22f094dd609f9b78197c429e32bcfec 100644 >--- a/Source/WebCore/platform/graphics/nicosia/cairo/NicosiaCairoOperationRecorder.cpp >+++ b/Source/WebCore/platform/graphics/nicosia/cairo/NicosiaCairoOperationRecorder.cpp >@@ -549,7 +549,13 @@ 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) >+bool CairoOperationRecorder::drawImageBuffer(ImageBuffer&, const FloatRect&, const FloatRect&, const ImagePaintingOptions&) >+{ >+ // FIXME: Not implemented. >+ return false; >+} >+ >+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 572ff2166f6e973a763b67cb6bb96f43f26a8d50..1d49013c89cf1014ec9b2b9207deceeb913c3859 100644 >--- a/Source/WebCore/platform/graphics/nicosia/cairo/NicosiaCairoOperationRecorder.h >+++ b/Source/WebCore/platform/graphics/nicosia/cairo/NicosiaCairoOperationRecorder.h >@@ -67,7 +67,9 @@ private: > WebCore::ImageDrawResult drawImage(WebCore::Image&, const WebCore::FloatRect&, const WebCore::FloatRect&, const WebCore::ImagePaintingOptions&) override; > WebCore::ImageDrawResult drawTiledImage(WebCore::Image&, const WebCore::FloatRect&, const WebCore::FloatPoint&, const WebCore::FloatSize&, const WebCore::FloatSize&, const WebCore::ImagePaintingOptions&) override; > WebCore::ImageDrawResult drawTiledImage(WebCore::Image&, const WebCore::FloatRect&, const WebCore::FloatRect&, const WebCore::FloatSize&, WebCore::Image::TileRule, WebCore::Image::TileRule, const WebCore::ImagePaintingOptions&) override; >- void drawNativeImage(const WebCore::NativeImagePtr&, const WebCore::FloatSize&, const WebCore::FloatRect&, const WebCore::FloatRect&, 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&, 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/GPUProcess/graphics/RemoteImageBuffer.h b/Source/WebKit/GPUProcess/graphics/RemoteImageBuffer.h >index 78d82f8c44bc37d213a80884abe84fcf02a04f2b..001febb6c936ee24574608cb748eebae522a4dff 100644 >--- a/Source/WebKit/GPUProcess/graphics/RemoteImageBuffer.h >+++ b/Source/WebKit/GPUProcess/graphics/RemoteImageBuffer.h >@@ -78,31 +78,12 @@ private: > return true; > } > >- if (item.type() == WebCore::DisplayList::ItemType::PaintFrameForMedia) { >- apply(static_cast<WebCore::DisplayList::PaintFrameForMedia&>(item), context); >+ if (m_remoteRenderingBackend.applyResourceItem(item, context)) > return true; >- } >- >- return false; >+ >+ return m_remoteRenderingBackend.applyMediaItem(item, context); > } > >- void apply(WebCore::DisplayList::PaintFrameForMedia& item, WebCore::GraphicsContext& context) >- { >- auto process = m_remoteRenderingBackend.gpuConnectionToWebProcess(); >- if (!process) >- return; >- >- auto playerProxy = process->remoteMediaPlayerManagerProxy().getProxy(item.identifier()); >- if (!playerProxy) >- return; >- >- auto player = playerProxy->mediaPlayer(); >- if (!player) >- return; >- >- context.paintFrameForMedia(*player, item.destination()); >- } >- > RemoteRenderingBackend& m_remoteRenderingBackend; > }; > >diff --git a/Source/WebKit/GPUProcess/graphics/RemoteRenderingBackend.cpp b/Source/WebKit/GPUProcess/graphics/RemoteRenderingBackend.cpp >index 1ef28ee2f2521dca554f480502f7274c9cc29b38..22e1ca338b71ee1e526c8144b9e2af5701e5a3e7 100644 >--- a/Source/WebKit/GPUProcess/graphics/RemoteRenderingBackend.cpp >+++ b/Source/WebKit/GPUProcess/graphics/RemoteRenderingBackend.cpp >@@ -72,6 +72,54 @@ uint64_t RemoteRenderingBackend::messageSenderDestinationID() const > return m_renderingBackendIdentifier.toUInt64(); > } > >+bool RemoteRenderingBackend::applyResourceItem(const DisplayList::Item& item, GraphicsContext& context) >+{ >+ if (item.type() == DisplayList::ItemType::DrawImageBuffer) { >+ auto& drawItem = static_cast<const DisplayList::DrawImageBuffer&>(item); >+ auto imageBuffer = m_remoteResourceCache.cachedImageBuffer(drawItem.remoteResourceIdentifier()); >+ if (!imageBuffer) >+ return false; >+ >+ imageBuffer->draw(context, drawItem.destinationRect(), drawItem.source(), drawItem.options()); >+ return true; >+ } >+ >+ if (item.type() == DisplayList::ItemType::DrawNativeImage) { >+ auto& drawItem = static_cast<const DisplayList::DrawNativeImage&>(item); >+ auto image = m_remoteResourceCache.cachedNativeImage(drawItem.remoteResourceIdentifier()); >+ if (!image) >+ return false; >+ >+ context.drawNativeImage(image, drawItem.imageSize(), drawItem.destinationRect(), drawItem.source(), drawItem.options()); >+ return true; >+ } >+ >+ return false; >+} >+ >+bool RemoteRenderingBackend::applyMediaItem(const DisplayList::Item& item, GraphicsContext& context) >+{ >+ if (item.type() != WebCore::DisplayList::ItemType::PaintFrameForMedia) >+ return false; >+ >+ auto& mediaItem = static_cast<const DisplayList::PaintFrameForMedia&>(item); >+ >+ auto process = gpuConnectionToWebProcess(); >+ if (!process) >+ return false; >+ >+ auto playerProxy = process->remoteMediaPlayerManagerProxy().getProxy(mediaItem.identifier()); >+ if (!playerProxy) >+ return false; >+ >+ auto player = playerProxy->mediaPlayer(); >+ if (!player) >+ return false; >+ >+ context.paintFrameForMedia(*player, mediaItem.destination()); >+ return true; >+} >+ > void RemoteRenderingBackend::imageBufferBackendWasCreated(const FloatSize& logicalSize, const IntSize& backendSize, float resolutionScale, ColorSpace colorSpace, ImageBufferBackendHandle handle, RemoteResourceIdentifier remoteResourceIdentifier) > { > send(Messages::RemoteRenderingBackendProxy::ImageBufferBackendWasCreated(logicalSize, backendSize, resolutionScale, colorSpace, WTFMove(handle), remoteResourceIdentifier), m_renderingBackendIdentifier); >@@ -124,6 +172,10 @@ void RemoteRenderingBackend::getImageData(WebCore::AlphaPremultiplication output > imageData = imageBuffer->getImageData(outputFormat, srcRect); > completionHandler(IPC::ImageDataReference(WTFMove(imageData))); > } >+void RemoteRenderingBackend::cacheNativeImage(const NativeImagePtr& image, RemoteResourceIdentifier remoteResourceIdentifier) >+{ >+ m_remoteResourceCache.cacheNativeImage(image, remoteResourceIdentifier); >+} > > void RemoteRenderingBackend::releaseRemoteResource(RemoteResourceIdentifier remoteResourceIdentifier) > { >diff --git a/Source/WebKit/GPUProcess/graphics/RemoteRenderingBackend.h b/Source/WebKit/GPUProcess/graphics/RemoteRenderingBackend.h >index effba449b188ea2b54d362c2ac54c28fc0ccb3ed..3eb4b7d1ab10593e3a8a098088d9e96e3c5f3ca0 100644 >--- a/Source/WebKit/GPUProcess/graphics/RemoteRenderingBackend.h >+++ b/Source/WebKit/GPUProcess/graphics/RemoteRenderingBackend.h >@@ -42,6 +42,7 @@ > namespace WebCore { > namespace DisplayList { > class DisplayList; >+class Item; > } > class FloatSize; > enum class ColorSpace : uint8_t; >@@ -61,6 +62,10 @@ public: > > GPUConnectionToWebProcess* gpuConnectionToWebProcess() const; > >+ // Rendering operations. >+ bool applyResourceItem(const WebCore::DisplayList::Item&, WebCore::GraphicsContext&); >+ bool applyMediaItem(const WebCore::DisplayList::Item&, WebCore::GraphicsContext&); >+ > // Messages to be sent. > void imageBufferBackendWasCreated(const WebCore::FloatSize& logicalSize, const WebCore::IntSize& backendSize, float resolutionScale, WebCore::ColorSpace, ImageBufferBackendHandle, WebCore::RemoteResourceIdentifier); > void flushDisplayListWasCommitted(DisplayListFlushIdentifier, WebCore::RemoteResourceIdentifier); >@@ -81,6 +86,7 @@ private: > void flushDisplayList(const WebCore::DisplayList::DisplayList&, WebCore::RemoteResourceIdentifier); > void flushDisplayListAndCommit(const WebCore::DisplayList::DisplayList&, DisplayListFlushIdentifier, 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); > > RemoteResourceCache m_remoteResourceCache; >diff --git a/Source/WebKit/GPUProcess/graphics/RemoteRenderingBackend.messages.in b/Source/WebKit/GPUProcess/graphics/RemoteRenderingBackend.messages.in >index 035d6bb462c1ac2c9266120035852757678c303a..96c19e908be63a2502452241e82d735dcfaf4d69 100644 >--- a/Source/WebKit/GPUProcess/graphics/RemoteRenderingBackend.messages.in >+++ b/Source/WebKit/GPUProcess/graphics/RemoteRenderingBackend.messages.in >@@ -27,6 +27,7 @@ messages -> RemoteRenderingBackend NotRefCounted { > void FlushDisplayList(WebCore::DisplayList::DisplayList displayList, WebCore::RemoteResourceIdentifier remoteResourceIdentifier) > void FlushDisplayListAndCommit(WebCore::DisplayList::DisplayList displayList, WebKit::DisplayListFlushIdentifier 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/RemoteResourceCache.cpp b/Source/WebKit/GPUProcess/graphics/RemoteResourceCache.cpp >index ad047262521967946494c8ac7a5490310a7d7b12..2ef4c02d6582dfa7dab4459b08601feb42505b2e 100644 >--- a/Source/WebKit/GPUProcess/graphics/RemoteResourceCache.cpp >+++ b/Source/WebKit/GPUProcess/graphics/RemoteResourceCache.cpp >@@ -37,15 +37,28 @@ void RemoteResourceCache::cacheImageBuffer(RemoteResourceIdentifier remoteResour > ASSERT_UNUSED(addResult, addResult.isNewEntry); > } > >-WebCore::ImageBuffer* RemoteResourceCache::cachedImageBuffer(RemoteResourceIdentifier remoteResourceIdentifier) >+ImageBuffer* RemoteResourceCache::cachedImageBuffer(RemoteResourceIdentifier remoteResourceIdentifier) > { > return m_imageBuffers.get(remoteResourceIdentifier); > } > >+void RemoteResourceCache::cacheNativeImage(const NativeImagePtr& image, RemoteResourceIdentifier remoteResourceIdentifier) >+{ >+ auto addResult = m_nativeImages.add(remoteResourceIdentifier, image); >+ ASSERT_UNUSED(addResult, addResult.isNewEntry); >+} >+ >+NativeImagePtr RemoteResourceCache::cachedNativeImage(RemoteResourceIdentifier remoteResourceIdentifier) >+{ >+ return m_nativeImages.get(remoteResourceIdentifier); >+} >+ > void RemoteResourceCache::releaseRemoteResource(RemoteResourceIdentifier remoteResourceIdentifier) > { > if (m_imageBuffers.remove(remoteResourceIdentifier)) > return; >+ if (m_nativeImages.remove(remoteResourceIdentifier)) >+ return; > // Caching the remote resource should have happened before releasing it. > ASSERT_NOT_REACHED(); > } >diff --git a/Source/WebKit/GPUProcess/graphics/RemoteResourceCache.h b/Source/WebKit/GPUProcess/graphics/RemoteResourceCache.h >index 4ed8ce0acc15df3731c7f1a684c3dd0896c5608f..716c13d194aa7bf8f7be3af58bcc3bbd382e4ead 100644 >--- a/Source/WebKit/GPUProcess/graphics/RemoteResourceCache.h >+++ b/Source/WebKit/GPUProcess/graphics/RemoteResourceCache.h >@@ -44,12 +44,16 @@ public: > > void cacheImageBuffer(WebCore::RemoteResourceIdentifier, std::unique_ptr<WebCore::ImageBuffer>&&); > WebCore::ImageBuffer* cachedImageBuffer(WebCore::RemoteResourceIdentifier); >+ void cacheNativeImage(const WebCore::NativeImagePtr&, WebCore::RemoteResourceIdentifier); >+ WebCore::NativeImagePtr cachedNativeImage(WebCore::RemoteResourceIdentifier); > void releaseRemoteResource(WebCore::RemoteResourceIdentifier); > > private: > using RemoteImageBufferHashMap = HashMap<WebCore::RemoteResourceIdentifier, std::unique_ptr<WebCore::ImageBuffer>>; >+ using RemoteNativeImageHashMap = HashMap<WebCore::RemoteResourceIdentifier, WebCore::NativeImagePtr>; > > RemoteImageBufferHashMap m_imageBuffers; >+ RemoteNativeImageHashMap m_nativeImages; > }; > > } // namespace WebKit >diff --git a/Source/WebKit/Sources.txt b/Source/WebKit/Sources.txt >index 796db6996eedfe5b7e928001372054cf69c38046..7a3b2300b7c36890ffc253bba0554af20362f5d5 100644 >--- a/Source/WebKit/Sources.txt >+++ b/Source/WebKit/Sources.txt >@@ -557,8 +557,8 @@ WebProcess/MediaStream/UserMediaPermissionRequestManager.cpp > > WebProcess/GPU/GPUProcessConnection.cpp > WebProcess/GPU/graphics/ImageBufferShareableBitmapBackend.cpp >-WebProcess/GPU/graphics/RemoteImageBufferMessageHandlerProxy.cpp > WebProcess/GPU/graphics/RemoteRenderingBackendProxy.cpp >+WebProcess/GPU/graphics/RemoteResourceCacheProxy.cpp > WebProcess/GPU/media/AudioTrackPrivateRemote.cpp > WebProcess/GPU/media/MediaPlayerPrivateRemote.cpp > WebProcess/GPU/media/RemoteAudioDestinationProxy.cpp >diff --git a/Source/WebKit/WebKit.xcodeproj/project.pbxproj b/Source/WebKit/WebKit.xcodeproj/project.pbxproj >index 6bd9ac45f31ac43c2fc0964af5fdde4a78e68487..7486903488ca63a154a1e9c016e58fcc8e8bea89 100644 >--- a/Source/WebKit/WebKit.xcodeproj/project.pbxproj >+++ b/Source/WebKit/WebKit.xcodeproj/project.pbxproj >@@ -4224,8 +4224,6 @@ > 71A676A522C62318007D6295 /* WKTouchActionGestureRecognizer.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = WKTouchActionGestureRecognizer.mm; path = ios/WKTouchActionGestureRecognizer.mm; sourceTree = "<group>"; }; > 71FB810A2260627A00323677 /* WebsiteSimulatedMouseEventsDispatchPolicy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebsiteSimulatedMouseEventsDispatchPolicy.h; sourceTree = "<group>"; }; > 7227800B2408BD7D007D376B /* PlatformRemoteImageBufferProxy.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PlatformRemoteImageBufferProxy.h; sourceTree = "<group>"; }; >- 7227800C24097A02007D376B /* RemoteImageBufferMessageHandlerProxy.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = RemoteImageBufferMessageHandlerProxy.cpp; sourceTree = "<group>"; }; >- 7227800D24097A02007D376B /* RemoteImageBufferMessageHandlerProxy.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RemoteImageBufferMessageHandlerProxy.h; sourceTree = "<group>"; }; > 726D56DD253A64810002EF90 /* RemoteResourceCache.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = RemoteResourceCache.cpp; sourceTree = "<group>"; }; > 726D56DE253A64810002EF90 /* RemoteResourceCache.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RemoteResourceCache.h; sourceTree = "<group>"; }; > 727A7F342407857D004D2931 /* ImageBufferShareableIOSurfaceBackend.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ImageBufferShareableIOSurfaceBackend.cpp; sourceTree = "<group>"; }; >@@ -4237,6 +4235,8 @@ > 727A7F492408AEE6004D2931 /* RemoteImageBufferProxy.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RemoteImageBufferProxy.h; sourceTree = "<group>"; }; > 728E86EF1795188C0087879E /* WebColorPickerMac.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebColorPickerMac.h; sourceTree = "<group>"; }; > 728E86F01795188C0087879E /* WebColorPickerMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebColorPickerMac.mm; sourceTree = "<group>"; }; >+ 72B53157253C1E4D0049295A /* RemoteResourceCacheProxy.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = RemoteResourceCacheProxy.cpp; sourceTree = "<group>"; }; >+ 72B53158253C1E4D0049295A /* RemoteResourceCacheProxy.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RemoteResourceCacheProxy.h; sourceTree = "<group>"; }; > 75A8D2C4187CCF9F00C39C9E /* WKWebsiteDataStore.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKWebsiteDataStore.h; sourceTree = "<group>"; }; > 75A8D2C5187CCF9F00C39C9E /* WKWebsiteDataStore.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKWebsiteDataStore.mm; sourceTree = "<group>"; }; > 75A8D2D4187D1C0100C39C9E /* WKWebsiteDataStoreInternal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKWebsiteDataStoreInternal.h; sourceTree = "<group>"; }; >@@ -8138,12 +8138,12 @@ > 727A7F36240788F0004D2931 /* ImageBufferShareableBitmapBackend.h */, > 727A7F38240788F0004D2931 /* PlatformImageBufferShareableBackend.h */, > 7227800B2408BD7D007D376B /* PlatformRemoteImageBufferProxy.h */, >- 7227800C24097A02007D376B /* RemoteImageBufferMessageHandlerProxy.cpp */, >- 7227800D24097A02007D376B /* RemoteImageBufferMessageHandlerProxy.h */, > 727A7F492408AEE6004D2931 /* RemoteImageBufferProxy.h */, > 5506409D2407160900AAE045 /* RemoteRenderingBackendProxy.cpp */, > 5506409E2407160900AAE045 /* RemoteRenderingBackendProxy.h */, > 550640A0240719E100AAE045 /* RemoteRenderingBackendProxy.messages.in */, >+ 72B53157253C1E4D0049295A /* RemoteResourceCacheProxy.cpp */, >+ 72B53158253C1E4D0049295A /* RemoteResourceCacheProxy.h */, > 5506409F2407196A00AAE045 /* RenderingBackendIdentifier.h */, > ); > path = graphics; >diff --git a/Source/WebKit/WebProcess/GPU/graphics/PlatformRemoteImageBufferProxy.h b/Source/WebKit/WebProcess/GPU/graphics/PlatformRemoteImageBufferProxy.h >index 9aff088e37ca76a7f864ae7e42bbb7004f1f1523..00060ec101c254e2b58a7646a4a424f3d02449e3 100644 >--- a/Source/WebKit/WebProcess/GPU/graphics/PlatformRemoteImageBufferProxy.h >+++ b/Source/WebKit/WebProcess/GPU/graphics/PlatformRemoteImageBufferProxy.h >@@ -37,4 +37,14 @@ using AcceleratedRemoteImageBufferProxy = RemoteImageBufferProxy<AcceleratedImag > > } // namespace WebKit > >+SPECIALIZE_TYPE_TRAITS_BEGIN(WebKit::UnacceleratedRemoteImageBufferProxy) >+ static bool isType(const WebCore::ImageBuffer& imageBuffer) { return imageBuffer.remoteResourceIdentifier() && !imageBuffer.isAccelerated(); } >+SPECIALIZE_TYPE_TRAITS_END() >+ >+#if HAVE(IOSURFACE) >+SPECIALIZE_TYPE_TRAITS_BEGIN(WebKit::AcceleratedRemoteImageBufferProxy) >+ static bool isType(const WebCore::ImageBuffer& imageBuffer) { return imageBuffer.remoteResourceIdentifier() && imageBuffer.isAccelerated(); } >+SPECIALIZE_TYPE_TRAITS_END() >+#endif >+ > #endif // ENABLE(GPU_PROCESS) >diff --git a/Source/WebKit/WebProcess/GPU/graphics/RemoteImageBufferMessageHandlerProxy.cpp b/Source/WebKit/WebProcess/GPU/graphics/RemoteImageBufferMessageHandlerProxy.cpp >deleted file mode 100644 >index e9562a368e69e4230e7262c2636df286d746eac5..0000000000000000000000000000000000000000 >--- a/Source/WebKit/WebProcess/GPU/graphics/RemoteImageBufferMessageHandlerProxy.cpp >+++ /dev/null >@@ -1,103 +0,0 @@ >-/* >- * Copyright (C) 2020 Apple Inc. All rights reserved. >- * >- * Redistribution and use in source and binary forms, with or without >- * modification, are permitted provided that the following conditions >- * are met: >- * 1. Redistributions of source code must retain the above copyright >- * notice, this list of conditions and the following disclaimer. >- * 2. Redistributions in binary form must reproduce the above copyright >- * notice, this list of conditions and the following disclaimer in the >- * documentation and/or other materials provided with the distribution. >- * >- * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' >- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, >- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR >- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS >- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR >- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF >- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS >- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN >- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) >- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF >- * THE POSSIBILITY OF SUCH DAMAGE. >- */ >- >-#include "config.h" >-#include "RemoteImageBufferMessageHandlerProxy.h" >- >-#if ENABLE(GPU_PROCESS) >- >-#include "ImageDataReference.h" >-#include "RemoteRenderingBackendMessages.h" >-#include "RemoteRenderingBackendProxy.h" >-#include <WebCore/DisplayListItems.h> >-#include <wtf/SystemTracing.h> >- >-namespace WebKit { >-using namespace WebCore; >- >-RemoteImageBufferMessageHandlerProxy::RemoteImageBufferMessageHandlerProxy(const FloatSize& size, RenderingMode renderingMode, float resolutionScale, ColorSpace colorSpace, RemoteRenderingBackendProxy& remoteRenderingBackendProxy) >- : m_remoteRenderingBackendProxy(makeWeakPtr(remoteRenderingBackendProxy)) >-{ >- // Create the RemoteImageBufferProxy. >- m_remoteRenderingBackendProxy->send(Messages::RemoteRenderingBackend::CreateImageBuffer(size, renderingMode, resolutionScale, colorSpace, m_remoteResourceIdentifier), m_remoteRenderingBackendProxy->renderingBackendIdentifier()); >-} >- >-RemoteImageBufferMessageHandlerProxy::~RemoteImageBufferMessageHandlerProxy() >-{ >- // Release the RemoteImageBufferProxy. >- if (!m_remoteRenderingBackendProxy) >- return; >- m_remoteRenderingBackendProxy->send(Messages::RemoteRenderingBackend::ReleaseRemoteResource(m_remoteResourceIdentifier), m_remoteRenderingBackendProxy->renderingBackendIdentifier()); >-} >- >-RefPtr<ImageData> RemoteImageBufferMessageHandlerProxy::getImageData(AlphaPremultiplication outputFormat, const IntRect& srcRect) const >-{ >- IPC::ImageDataReference imageDataReference; >- m_remoteRenderingBackendProxy->sendSync(Messages::RemoteRenderingBackend::GetImageData(outputFormat, srcRect, m_remoteResourceIdentifier), Messages::RemoteRenderingBackend::GetImageData::Reply(imageDataReference), m_remoteRenderingBackendProxy->renderingBackendIdentifier(), 1_s); >- return imageDataReference.buffer(); >-} >- >-void RemoteImageBufferMessageHandlerProxy::waitForImageBufferBackendWasCreated() >-{ >- if (m_remoteRenderingBackendProxy && !isBackendCreated()) >- m_remoteRenderingBackendProxy->waitForImageBufferBackendWasCreated(); >-} >- >-void RemoteImageBufferMessageHandlerProxy::waitForFlushDisplayListWasCommitted() >-{ >- if (m_remoteRenderingBackendProxy && isPendingFlush()) >- m_remoteRenderingBackendProxy->waitForFlushDisplayListWasCommitted(); >-} >- >-void RemoteImageBufferMessageHandlerProxy::flushDisplayList(WebCore::DisplayList::DisplayList& displayList) >-{ >- if (!m_remoteRenderingBackendProxy) >- return; >- >- TraceScope tracingScope(FlushRemoteImageBufferStart, FlushRemoteImageBufferEnd); >- m_remoteRenderingBackendProxy->send(Messages::RemoteRenderingBackend::FlushDisplayList(displayList, m_remoteResourceIdentifier), m_remoteRenderingBackendProxy->renderingBackendIdentifier()); >- displayList.clear(); >-} >- >-void RemoteImageBufferMessageHandlerProxy::flushDisplayListAndWaitCommit(WebCore::DisplayList::DisplayList& displayList) >-{ >- if (!m_remoteRenderingBackendProxy) >- return; >- >- TraceScope tracingScope(FlushRemoteImageBufferStart, FlushRemoteImageBufferEnd, 1); >- m_sentFlushIdentifier = DisplayListFlushIdentifier::generate(); >- m_remoteRenderingBackendProxy->send(Messages::RemoteRenderingBackend::FlushDisplayListAndCommit(displayList, m_sentFlushIdentifier, m_remoteResourceIdentifier), m_remoteRenderingBackendProxy->renderingBackendIdentifier()); >- displayList.clear(); >- waitForFlushDisplayListWasCommitted(); >-} >- >-void RemoteImageBufferMessageHandlerProxy::commitFlushContext(DisplayListFlushIdentifier flushIdentifier) >-{ >- m_receivedFlushIdentifier = flushIdentifier; >-} >- >-} // namespace WebKit >- >-#endif // ENABLE(GPU_PROCESS) >diff --git a/Source/WebKit/WebProcess/GPU/graphics/RemoteImageBufferMessageHandlerProxy.h b/Source/WebKit/WebProcess/GPU/graphics/RemoteImageBufferMessageHandlerProxy.h >deleted file mode 100644 >index b9a026a81298796e7bd35fa96eee904de4bfb5fd..0000000000000000000000000000000000000000 >--- a/Source/WebKit/WebProcess/GPU/graphics/RemoteImageBufferMessageHandlerProxy.h >+++ /dev/null >@@ -1,83 +0,0 @@ >-/* >- * Copyright (C) 2020 Apple Inc. All rights reserved. >- * >- * Redistribution and use in source and binary forms, with or without >- * modification, are permitted provided that the following conditions >- * are met: >- * 1. Redistributions of source code must retain the above copyright >- * notice, this list of conditions and the following disclaimer. >- * 2. Redistributions in binary form must reproduce the above copyright >- * notice, this list of conditions and the following disclaimer in the >- * documentation and/or other materials provided with the distribution. >- * >- * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY >- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE >- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR >- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR >- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, >- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, >- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR >- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY >- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT >- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE >- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. >- */ >- >-#pragma once >- >-#if ENABLE(GPU_PROCESS) >- >-#include "DisplayListFlushIdentifier.h" >-#include "ImageBufferBackendHandle.h" >-#include <WebCore/ColorSpace.h> >-#include <WebCore/DisplayList.h> >-#include <WebCore/FloatSize.h> >-#include <WebCore/RemoteResourceIdentifier.h> >-#include <WebCore/RenderingMode.h> >- >-namespace WebCore { >-class ImageData; >-enum class AlphaPremultiplication : uint8_t; >-} >- >-namespace WebKit { >- >-class RemoteRenderingBackendProxy; >- >-class RemoteImageBufferMessageHandlerProxy { >-public: >- virtual ~RemoteImageBufferMessageHandlerProxy(); >- >- WebCore::RemoteResourceIdentifier remoteResourceIdentifier() const { return m_remoteResourceIdentifier; } >- >- // Messages to be received. See RemoteRenderingBackend.messages.in. >- virtual void createBackend(const WebCore::FloatSize& logicalSize, const WebCore::IntSize& backendSize, float resolutionScale, WebCore::ColorSpace, ImageBufferBackendHandle) = 0; >- >- void commitFlushContext(DisplayListFlushIdentifier); >- >-protected: >- RemoteImageBufferMessageHandlerProxy(const WebCore::FloatSize&, WebCore::RenderingMode, float resolutionScale, WebCore::ColorSpace, RemoteRenderingBackendProxy&); >- >- virtual bool isBackendCreated() const = 0; >- bool isPendingFlush() const { return m_sentFlushIdentifier != m_receivedFlushIdentifier; } >- >- RefPtr<WebCore::ImageData> getImageData(WebCore::AlphaPremultiplication outputFormat, const WebCore::IntRect& srcRect) const; >- >- void waitForImageBufferBackendWasCreated(); >- void waitForFlushDisplayListWasCommitted(); >- >- // Messages to be sent. See RemoteRenderingBackendProxy.messages.in. >- void flushDisplayList(WebCore::DisplayList::DisplayList&); >- void flushDisplayListAndWaitCommit(WebCore::DisplayList::DisplayList&); >- >-private: >- WeakPtr<RemoteRenderingBackendProxy> m_remoteRenderingBackendProxy; >- WebCore::RemoteResourceIdentifier m_remoteResourceIdentifier { WebCore::RemoteResourceIdentifier::generate() }; >- >- DisplayListFlushIdentifier m_sentFlushIdentifier; >- DisplayListFlushIdentifier m_receivedFlushIdentifier; >-}; >- >-} // namespace WebKit >- >-#endif // ENABLE(GPU_PROCESS) >diff --git a/Source/WebKit/WebProcess/GPU/graphics/RemoteImageBufferProxy.h b/Source/WebKit/WebProcess/GPU/graphics/RemoteImageBufferProxy.h >index 20fbf81c982552ef76bb6cd15dc3a1e9d3880ec3..9116edf6a4d4562c712e0f2bd593adfd976f3a07 100644 >--- a/Source/WebKit/WebProcess/GPU/graphics/RemoteImageBufferProxy.h >+++ b/Source/WebKit/WebProcess/GPU/graphics/RemoteImageBufferProxy.h >@@ -27,7 +27,6 @@ > > #if ENABLE(GPU_PROCESS) > >-#include "RemoteImageBufferMessageHandlerProxy.h" > #include <WebCore/DisplayListImageBuffer.h> > #include <WebCore/DisplayListItems.h> > #include <WebCore/DisplayListRecorder.h> >@@ -37,54 +36,71 @@ namespace WebKit { > class RemoteRenderingBackend; > > template<typename BackendType> >-class RemoteImageBufferProxy : public WebCore::DisplayList::ImageBuffer<BackendType>, public RemoteImageBufferMessageHandlerProxy { >+class RemoteImageBufferProxy : public WebCore::DisplayList::ImageBuffer<BackendType>, public WebCore::DisplayList::Recorder::Delegate { > using BaseDisplayListImageBuffer = WebCore::DisplayList::ImageBuffer<BackendType>; > using BaseDisplayListImageBuffer::m_backend; > using BaseDisplayListImageBuffer::m_drawingContext; > > public: >- static std::unique_ptr<RemoteImageBufferProxy> create(const WebCore::FloatSize& size, WebCore::RenderingMode renderingMode, float resolutionScale, WebCore::ColorSpace colorSpace, RemoteRenderingBackendProxy& remoteRenderingBackendProxy) >+ static std::unique_ptr<RemoteImageBufferProxy> create(const WebCore::FloatSize& size, float resolutionScale, RemoteRenderingBackendProxy& remoteRenderingBackendProxy) > { > if (BackendType::calculateBackendSize(size, resolutionScale).isEmpty()) > return nullptr; > >- return std::unique_ptr<RemoteImageBufferProxy>(new RemoteImageBufferProxy(size, renderingMode, resolutionScale, colorSpace, remoteRenderingBackendProxy)); >+ return std::unique_ptr<RemoteImageBufferProxy>(new RemoteImageBufferProxy(size, remoteRenderingBackendProxy)); > } > > ~RemoteImageBufferProxy() > { >+ if (!m_remoteRenderingBackendProxy) >+ return; > flushDrawingContext(); >+ m_remoteRenderingBackendProxy->remoteResourceCacheProxy().releaseImageBuffer(m_remoteResourceIdentifier); > } > >-protected: >- RemoteImageBufferProxy(const WebCore::FloatSize& size, WebCore::RenderingMode renderingMode, float resolutionScale, WebCore::ColorSpace colorSpace, RemoteRenderingBackendProxy& remoteRenderingBackendProxy) >- : BaseDisplayListImageBuffer(size) >- , RemoteImageBufferMessageHandlerProxy(size, renderingMode, resolutionScale, colorSpace, remoteRenderingBackendProxy) >- { >- } >+ WebCore::RemoteResourceIdentifier remoteResourceIdentifier() const override { return m_remoteResourceIdentifier; } > >- void createBackend(const WebCore::FloatSize& logicalSize, const WebCore::IntSize& backendSize, float resolutionScale, WebCore::ColorSpace colorSpace, ImageBufferBackendHandle handle) override >+ void createBackend(const WebCore::FloatSize& logicalSize, const WebCore::IntSize& backendSize, float resolutionScale, WebCore::ColorSpace colorSpace, ImageBufferBackendHandle handle) > { > ASSERT(!m_backend); > m_backend = BackendType::create(logicalSize, backendSize, resolutionScale, colorSpace, WTFMove(handle)); > } >- >- bool isBackendCreated() const override { return m_backend.get(); } >+ >+ void commitFlushDisplayList(DisplayListFlushIdentifier flushIdentifier) >+ { >+ m_receivedFlushIdentifier = flushIdentifier; >+ } >+ >+protected: >+ RemoteImageBufferProxy(const WebCore::FloatSize& size, RemoteRenderingBackendProxy& remoteRenderingBackendProxy) >+ : BaseDisplayListImageBuffer(size, this) >+ , m_remoteRenderingBackendProxy(makeWeakPtr(remoteRenderingBackendProxy)) >+ { >+ ASSERT(m_remoteRenderingBackendProxy); >+ } >+ >+ bool isPendingFlush() const { return m_sentFlushIdentifier != m_receivedFlushIdentifier; } > > BackendType* ensureBackendCreated() const override > { >- if (!m_backend) >- const_cast<RemoteImageBufferProxy&>(*this).RemoteImageBufferMessageHandlerProxy::waitForImageBufferBackendWasCreated(); >+ if (!m_backend && m_remoteRenderingBackendProxy) >+ m_remoteRenderingBackendProxy->waitForImageBufferBackendWasCreated(); > return m_backend.get(); > } > > RefPtr<WebCore::ImageData> getImageData(WebCore::AlphaPremultiplication outputFormat, const WebCore::IntRect& srcRect) const override > { >+ if (!m_remoteRenderingBackendProxy) >+ return nullptr; >+ > auto& displayList = const_cast<RemoteImageBufferProxy*>(this)->m_drawingContext.displayList(); >- const_cast<RemoteImageBufferProxy*>(this)->RemoteImageBufferMessageHandlerProxy::flushDisplayList(displayList); >- auto result = const_cast<RemoteImageBufferProxy*>(this)->RemoteImageBufferMessageHandlerProxy::getImageData(outputFormat, srcRect); >+ if (displayList.itemCount()) { >+ const_cast<RemoteImageBufferProxy&>(*this).flushDisplayList(displayList); >+ displayList.clear(); >+ } >+ > // getImageData is synchronous, which means we've already received the CommitImageBufferFlushContext message. >- return result; >+ return m_remoteRenderingBackendProxy->getImageData(outputFormat, srcRect, m_remoteResourceIdentifier); > } > > void putImageData(WebCore::AlphaPremultiplication inputFormat, const WebCore::ImageData& imageData, const WebCore::IntRect& srcRect, const WebCore::IntPoint& destPoint = { }, WebCore::AlphaPremultiplication destFormat = WebCore::AlphaPremultiplication::Premultiplied) override >@@ -104,17 +120,60 @@ protected: > void flushDrawingContext() override > { > auto& displayList = m_drawingContext.displayList(); >- if (displayList.itemCount()) >- RemoteImageBufferMessageHandlerProxy::flushDisplayListAndWaitCommit(displayList); >+ if (!displayList.itemCount() || !m_remoteRenderingBackendProxy) >+ return; >+ >+ TraceScope tracingScope(FlushRemoteImageBufferStart, FlushRemoteImageBufferEnd, 1); >+ m_sentFlushIdentifier = m_remoteRenderingBackendProxy->flushDisplayListAndCommit(displayList, m_remoteResourceIdentifier); >+ >+ // Wait for our DisplayList to be flushed but do not hang. >+ static constexpr unsigned maxWaitingFlush = 3; >+ for (unsigned numWaitingFlush = 0; numWaitingFlush < maxWaitingFlush && isPendingFlush(); ++numWaitingFlush) >+ m_remoteRenderingBackendProxy->waitForFlushDisplayListWasCommitted(); >+ >+ m_remoteRenderingBackendProxy->remoteResourceCacheProxy().unlockRemoteResourcesForRemoteClient(m_remoteResourceIdentifier); >+ displayList.clear(); >+ } >+ >+ void flushDisplayList(const WebCore::DisplayList::DisplayList& displayList) override >+ { >+ if (!displayList.itemCount() || !m_remoteRenderingBackendProxy) >+ return; >+ >+ TraceScope tracingScope(FlushRemoteImageBufferStart, FlushRemoteImageBufferEnd); >+ m_remoteRenderingBackendProxy->flushDisplayList(displayList, m_remoteResourceIdentifier); >+ m_remoteRenderingBackendProxy->remoteResourceCacheProxy().unlockRemoteResourcesForRemoteClient(m_remoteResourceIdentifier); > } >- >+ > void willAppendItem(const WebCore::DisplayList::Item&) override > { > constexpr size_t DisplayListBatchSize = 512; > auto& displayList = m_drawingContext.displayList(); >- if (displayList.itemCount() >= DisplayListBatchSize) >- RemoteImageBufferMessageHandlerProxy::flushDisplayList(displayList); >+ if (displayList.itemCount() < DisplayListBatchSize || !m_remoteRenderingBackendProxy) >+ return; >+ >+ flushDisplayList(displayList); >+ displayList.clear(); > } >+ >+ bool lockRemoteImageBuffer(WebCore::ImageBuffer& imageBuffer) override >+ { >+ if (!m_remoteRenderingBackendProxy) >+ return false; >+ return m_remoteRenderingBackendProxy->remoteResourceCacheProxy().lockRemoteImageBufferForRemoteClient(imageBuffer, m_remoteResourceIdentifier); >+ } >+ >+ WebCore::RemoteResourceIdentifier lockRemoteNativeImage(WebCore::CachedImage& cachedImage, const WebCore::NativeImagePtr& image) override >+ { >+ if (!m_remoteRenderingBackendProxy) >+ return { }; >+ return m_remoteRenderingBackendProxy->remoteResourceCacheProxy().lockRemoteNativeImageForRemoteClient(cachedImage, image, m_remoteResourceIdentifier); >+ } >+ >+ DisplayListFlushIdentifier m_sentFlushIdentifier; >+ DisplayListFlushIdentifier m_receivedFlushIdentifier; >+ WebCore::RemoteResourceIdentifier m_remoteResourceIdentifier { WebCore::RemoteResourceIdentifier::generate() }; >+ WeakPtr<RemoteRenderingBackendProxy> m_remoteRenderingBackendProxy; > }; > > } // namespace WebKit >diff --git a/Source/WebKit/WebProcess/GPU/graphics/RemoteRenderingBackendProxy.cpp b/Source/WebKit/WebProcess/GPU/graphics/RemoteRenderingBackendProxy.cpp >index b1461b482148d2b75b40f098d940cde10ab4ffce..ad7f088c9273d3b8281611f4d0b98bfd15af192a 100644 >--- a/Source/WebKit/WebProcess/GPU/graphics/RemoteRenderingBackendProxy.cpp >+++ b/Source/WebKit/WebProcess/GPU/graphics/RemoteRenderingBackendProxy.cpp >@@ -30,6 +30,7 @@ > > #include "GPUConnectionToWebProcess.h" > #include "GPUProcessConnection.h" >+#include "ImageDataReference.h" > #include "PlatformRemoteImageBufferProxy.h" > #include "RemoteRenderingBackendMessages.h" > #include "RemoteRenderingBackendProxyMessages.h" >@@ -88,38 +89,80 @@ bool RemoteRenderingBackendProxy::waitForFlushDisplayListWasCommitted() > > std::unique_ptr<ImageBuffer> RemoteRenderingBackendProxy::createImageBuffer(const FloatSize& size, ShouldAccelerate shouldAccelerate, float resolutionScale, ColorSpace colorSpace) > { >+ RenderingMode renderingMode; >+ std::unique_ptr<WebCore::ImageBuffer> imageBuffer; >+ > if (shouldAccelerate == ShouldAccelerate::Yes) { >- if (auto imageBuffer = AcceleratedRemoteImageBufferProxy::create(size, RenderingMode::RemoteAccelerated, resolutionScale, colorSpace, *this)) { >- m_imageBufferMessageHandlerMap.add(imageBuffer->remoteResourceIdentifier(), imageBuffer.get()); >- return imageBuffer; >- } >+ renderingMode = RenderingMode::RemoteAccelerated; >+ imageBuffer = AcceleratedRemoteImageBufferProxy::create(size, resolutionScale, *this); >+ } >+ >+ if (!imageBuffer) { >+ renderingMode = RenderingMode::RemoteUnaccelerated; >+ imageBuffer = UnacceleratedRemoteImageBufferProxy::create(size, resolutionScale, *this); > } > >- if (auto imageBuffer = UnacceleratedRemoteImageBufferProxy::create(size, RenderingMode::RemoteUnaccelerated, resolutionScale, colorSpace, *this)) { >- m_imageBufferMessageHandlerMap.add(imageBuffer->remoteResourceIdentifier(), imageBuffer.get()); >+ if (imageBuffer) { >+ send(Messages::RemoteRenderingBackend::CreateImageBuffer(size, renderingMode, resolutionScale, colorSpace, imageBuffer->remoteResourceIdentifier()), m_renderingBackendIdentifier); >+ m_remoteResourceCacheProxy.cacheImageBuffer(imageBuffer->remoteResourceIdentifier(), imageBuffer.get()); > return imageBuffer; > } > >+ ASSERT_NOT_REACHED(); > return nullptr; > } > >+RefPtr<ImageData> RemoteRenderingBackendProxy::getImageData(AlphaPremultiplication outputFormat, const IntRect& srcRect, RemoteResourceIdentifier remoteResourceIdentifier) >+{ >+ IPC::ImageDataReference imageDataReference; >+ sendSync(Messages::RemoteRenderingBackend::GetImageData(outputFormat, srcRect, remoteResourceIdentifier), Messages::RemoteRenderingBackend::GetImageData::Reply(imageDataReference), m_renderingBackendIdentifier, 1_s); >+ return imageDataReference.buffer(); >+} >+ >+void RemoteRenderingBackendProxy::flushDisplayList(const DisplayList::DisplayList& displayList, RemoteResourceIdentifier remoteResourceIdentifier) >+{ >+ send(Messages::RemoteRenderingBackend::FlushDisplayList(displayList, remoteResourceIdentifier), m_renderingBackendIdentifier); >+} >+ >+DisplayListFlushIdentifier RemoteRenderingBackendProxy::flushDisplayListAndCommit(const DisplayList::DisplayList& displayList, RemoteResourceIdentifier remoteResourceIdentifier) >+{ >+ DisplayListFlushIdentifier sentFlushIdentifier = DisplayListFlushIdentifier::generate(); >+ send(Messages::RemoteRenderingBackend::FlushDisplayListAndCommit(displayList, sentFlushIdentifier, remoteResourceIdentifier), m_renderingBackendIdentifier); >+ return sentFlushIdentifier; >+} >+ >+void RemoteRenderingBackendProxy::cacheNativeImage(const WebCore::NativeImagePtr& image, WebCore::RemoteResourceIdentifier remoteResourceIdentifier) >+{ >+ send(Messages::RemoteRenderingBackend::CacheNativeImage(image, remoteResourceIdentifier), m_renderingBackendIdentifier); >+} >+ > void RemoteRenderingBackendProxy::releaseRemoteResource(RemoteResourceIdentifier remoteResourceIdentifier) > { >- // CreateImageBuffer message should have been received before this one. >- bool found = m_imageBufferMessageHandlerMap.remove(remoteResourceIdentifier); >- ASSERT_UNUSED(found, found); >+ send(Messages::RemoteRenderingBackend::ReleaseRemoteResource(remoteResourceIdentifier), m_renderingBackendIdentifier); > } > > void RemoteRenderingBackendProxy::imageBufferBackendWasCreated(const FloatSize& logicalSize, const IntSize& backendSize, float resolutionScale, ColorSpace colorSpace, ImageBufferBackendHandle handle, RemoteResourceIdentifier remoteResourceIdentifier) > { >- if (auto imageBuffer = m_imageBufferMessageHandlerMap.get(remoteResourceIdentifier)) >- imageBuffer->createBackend(logicalSize, backendSize, resolutionScale, colorSpace, WTFMove(handle)); >+ auto imageBuffer = m_remoteResourceCacheProxy.cachedImageBuffer(remoteResourceIdentifier); >+ if (!imageBuffer) >+ return; >+ >+ if (imageBuffer->isAccelerated()) >+ downcast<AcceleratedRemoteImageBufferProxy>(*imageBuffer).createBackend(logicalSize, backendSize, resolutionScale, colorSpace, WTFMove(handle)); >+ else >+ downcast<UnacceleratedRemoteImageBufferProxy>(*imageBuffer).createBackend(logicalSize, backendSize, resolutionScale, colorSpace, WTFMove(handle)); > } > > void RemoteRenderingBackendProxy::flushDisplayListWasCommitted(DisplayListFlushIdentifier flushIdentifier, RemoteResourceIdentifier remoteResourceIdentifier) > { >- if (auto imageBuffer = m_imageBufferMessageHandlerMap.get(remoteResourceIdentifier)) >- imageBuffer->commitFlushContext(flushIdentifier); >+ auto imageBuffer = m_remoteResourceCacheProxy.cachedImageBuffer(remoteResourceIdentifier); >+ if (!imageBuffer) >+ return; >+ >+ if (imageBuffer->isAccelerated()) >+ downcast<AcceleratedRemoteImageBufferProxy>(*imageBuffer).commitFlushDisplayList(flushIdentifier); >+ else >+ downcast<UnacceleratedRemoteImageBufferProxy>(*imageBuffer).commitFlushDisplayList(flushIdentifier); > } > > } // namespace WebKit >diff --git a/Source/WebKit/WebProcess/GPU/graphics/RemoteRenderingBackendProxy.h b/Source/WebKit/WebProcess/GPU/graphics/RemoteRenderingBackendProxy.h >index 9d290023d49721ead6cb98799d26f5a8d0ed4dbe..bdb180989003bf07a559e1c98a0eeb8be28953c5 100644 >--- a/Source/WebKit/WebProcess/GPU/graphics/RemoteRenderingBackendProxy.h >+++ b/Source/WebKit/WebProcess/GPU/graphics/RemoteRenderingBackendProxy.h >@@ -31,16 +31,24 @@ > #include "ImageBufferBackendHandle.h" > #include "MessageReceiver.h" > #include "MessageSender.h" >-#include "RemoteImageBufferMessageHandlerProxy.h" >+#include "RemoteResourceCacheProxy.h" > #include "RenderingBackendIdentifier.h" >-#include <WebCore/ColorSpace.h> >-#include <WebCore/DisplayList.h> >-#include <WebCore/FloatSize.h> > #include <WebCore/RemoteResourceIdentifier.h> >-#include <WebCore/RenderingMode.h> >-#include <wtf/HashMap.h> > #include <wtf/WeakPtr.h> > >+namespace WebCore { >+namespace DisplayList { >+class DisplayList; >+class Item; >+} >+class FloatSize; >+class ImageData; >+enum class AlphaPremultiplication : uint8_t; >+enum class ColorSpace : uint8_t; >+enum class RenderingMode : uint8_t; >+enum class ShouldAccelerate : bool; >+} >+ > namespace WebKit { > > class RemoteRenderingBackendProxy >@@ -52,7 +60,7 @@ public: > > ~RemoteRenderingBackendProxy(); > >- RenderingBackendIdentifier renderingBackendIdentifier() const { return m_renderingBackendIdentifier; } >+ RemoteResourceCacheProxy& remoteResourceCacheProxy() { return m_remoteResourceCacheProxy; } > > // IPC::MessageSender. > IPC::Connection* messageSenderConnection() const override; >@@ -61,7 +69,12 @@ public: > // IPC::MessageReceiver > void didReceiveMessage(IPC::Connection&, IPC::Decoder&) override; > >+ // Messages to be sent. > std::unique_ptr<WebCore::ImageBuffer> createImageBuffer(const WebCore::FloatSize&, WebCore::ShouldAccelerate, float resolutionScale, WebCore::ColorSpace); >+ RefPtr<WebCore::ImageData> getImageData(WebCore::AlphaPremultiplication outputFormat, const WebCore::IntRect& srcRect, WebCore::RemoteResourceIdentifier); >+ void flushDisplayList(const WebCore::DisplayList::DisplayList&, WebCore::RemoteResourceIdentifier); >+ DisplayListFlushIdentifier flushDisplayListAndCommit(const WebCore::DisplayList::DisplayList&, WebCore::RemoteResourceIdentifier); >+ void cacheNativeImage(const WebCore::NativeImagePtr&, WebCore::RemoteResourceIdentifier); > void releaseRemoteResource(WebCore::RemoteResourceIdentifier); > > bool waitForImageBufferBackendWasCreated(); >@@ -74,8 +87,7 @@ private: > void imageBufferBackendWasCreated(const WebCore::FloatSize& logicalSize, const WebCore::IntSize& backendSize, float resolutionScale, WebCore::ColorSpace, ImageBufferBackendHandle, WebCore::RemoteResourceIdentifier); > void flushDisplayListWasCommitted(DisplayListFlushIdentifier, WebCore::RemoteResourceIdentifier); > >- using ImageBufferMessageHandlerMap = HashMap<WebCore::RemoteResourceIdentifier, RemoteImageBufferMessageHandlerProxy*>; >- ImageBufferMessageHandlerMap m_imageBufferMessageHandlerMap; >+ RemoteResourceCacheProxy m_remoteResourceCacheProxy { *this }; > RenderingBackendIdentifier m_renderingBackendIdentifier { RenderingBackendIdentifier::generate() }; > }; > >diff --git a/Source/WebKit/WebProcess/GPU/graphics/RemoteResourceCacheProxy.cpp b/Source/WebKit/WebProcess/GPU/graphics/RemoteResourceCacheProxy.cpp >new file mode 100644 >index 0000000000000000000000000000000000000000..8d5c8fc3ea379556cdc6a1250d51c62f5e702eb4 >--- /dev/null >+++ b/Source/WebKit/WebProcess/GPU/graphics/RemoteResourceCacheProxy.cpp >@@ -0,0 +1,168 @@ >+/* >+ * Copyright (C) 2020 Apple Inc. All rights reserved. >+ * >+ * Redistribution and use in source and binary forms, with or without >+ * modification, are permitted provided that the following conditions >+ * are met: >+ * 1. Redistributions of source code must retain the above copyright >+ * notice, this list of conditions and the following disclaimer. >+ * 2. Redistributions in binary form must reproduce the above copyright >+ * notice, this list of conditions and the following disclaimer in the >+ * documentation and/or other materials provided with the distribution. >+ * >+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' >+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, >+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR >+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS >+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR >+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF >+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS >+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN >+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) >+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF >+ * THE POSSIBILITY OF SUCH DAMAGE. >+ */ >+ >+#include "config.h" >+#include "RemoteResourceCacheProxy.h" >+ >+#if ENABLE(GPU_PROCESS) >+ >+#include "RemoteRenderingBackendProxy.h" >+#include <WebCore/CachedImage.h> >+ >+namespace WebKit { >+using namespace WebCore; >+ >+RemoteResourceCacheProxy::RemoteResourceCacheProxy(RemoteRenderingBackendProxy& remoteRenderingBackendProxy) >+ : m_remoteRenderingBackendProxy(remoteRenderingBackendProxy) >+{ >+} >+ >+void RemoteResourceCacheProxy::cacheImageBuffer(RemoteResourceIdentifier identifier, ImageBuffer* imageBuffer) >+{ >+ auto addResult = m_imageBuffers.add(identifier, imageBuffer); >+ ASSERT_UNUSED(addResult, addResult.isNewEntry); >+} >+ >+ImageBuffer* RemoteResourceCacheProxy::cachedImageBuffer(RemoteResourceIdentifier identifier) >+{ >+ return m_imageBuffers.get(identifier); >+} >+ >+void RemoteResourceCacheProxy::releaseImageBuffer(RemoteResourceIdentifier remoteResourceIdentifier) >+{ >+ bool found = m_imageBuffers.remove(remoteResourceIdentifier); >+ ASSERT_UNUSED(found, found); >+ >+ // Tell the GPU process to remove this resource unless it's pending replaying back. >+ releaseRemoteResource(remoteResourceIdentifier); >+} >+ >+void RemoteResourceCacheProxy::nativeImageWillBeDestroyed(WebCore::CachedImage& cachedImage, const NativeImagePtr& image) >+{ >+ auto iter = m_cachedImages.find(&cachedImage); >+ if (iter == m_cachedImages.end()) >+ return; >+ >+ // Remove the resource from the cache. >+ auto remoteResourceIdentifier = iter->value.take(image); >+ if (!remoteResourceIdentifier) >+ return; >+ >+ // Tell the GPU process to remove this resource unless it's pending replaying back. >+ releaseRemoteResource(remoteResourceIdentifier); >+ >+ // Remove *this* from being a client of achedImage, if there is no NativeImages cached for it. >+ if (iter->value.isEmpty()) { >+ iter->key->removeClient(*this); >+ m_cachedImages.remove(iter); >+ } >+} >+ >+bool RemoteResourceCacheProxy::lockRemoteImageBufferForRemoteClient(ImageBuffer& imageBuffer, RemoteResourceIdentifier remoteClientIdentifier) >+{ >+ if (!imageBuffer.remoteResourceIdentifier()) >+ return false; >+ >+ if (cachedImageBuffer(imageBuffer.remoteResourceIdentifier()) != &imageBuffer) { >+ ASSERT_NOT_REACHED(); >+ return false; >+ } >+ >+ lockRemoteResourceForRemoteClient(imageBuffer.remoteResourceIdentifier(), remoteClientIdentifier); >+ return true; >+} >+ >+RemoteResourceIdentifier RemoteResourceCacheProxy::lockRemoteNativeImageForRemoteClient(WebCore::CachedImage& cachedImage, const NativeImagePtr& image, RemoteResourceIdentifier remoteClientIdentifier) >+{ >+ auto& nativeImages = m_cachedImages.ensure(&cachedImage, [&] { >+ cachedImage.addClient(*this); >+ return RemoteNativeImageHashMap(); >+ }).iterator->value; >+ >+ auto remoteResourceIdentifier = nativeImages.ensure(image, [&] { >+ auto remoteResourceIdentifier = RemoteResourceIdentifier::generate(); >+ m_remoteRenderingBackendProxy.cacheNativeImage(image, remoteResourceIdentifier); >+ return remoteResourceIdentifier; >+ }).iterator->value; >+ >+ lockRemoteResourceForRemoteClient(remoteResourceIdentifier, remoteClientIdentifier); >+ return remoteResourceIdentifier; >+} >+ >+void RemoteResourceCacheProxy::lockRemoteResourceForRemoteClient(RemoteResourceIdentifier remoteResourceIdentifier, RemoteResourceIdentifier remoteClientIdentifier) >+{ >+ // Add the "resource -> client" dependency in m_lockedRemoteResourceForRemoteClients. >+ auto& clients = m_lockedRemoteResourceForRemoteClients.ensure(remoteResourceIdentifier, [&] { >+ return RemoteClientsHashSet(); >+ }).iterator->value; >+ >+ clients.add(remoteClientIdentifier); >+} >+ >+void RemoteResourceCacheProxy::releaseRemoteResource(RemoteResourceIdentifier remoteResourceIdentifier) >+{ >+ ASSERT(!m_pendingUnlockRemoteResourceForRemoteClients.contains(remoteResourceIdentifier)); >+ >+ // If we have recorded resource -> client dependency before in m_lockedRemoteResourceForRemoteClients, move this >+ // dependency to m_pendingUnlockRemoteResourceForRemoteClients. Otherwise remove the resource in the GPU Process. >+ if (m_lockedRemoteResourceForRemoteClients.contains(remoteResourceIdentifier)) >+ m_pendingUnlockRemoteResourceForRemoteClients.add(remoteResourceIdentifier, m_lockedRemoteResourceForRemoteClients.take(remoteResourceIdentifier)); >+ else >+ m_remoteRenderingBackendProxy.releaseRemoteResource(remoteResourceIdentifier); >+} >+ >+void RemoteResourceCacheProxy::unlockRemoteResourcesForRemoteClient(RemoteResourceIdentifier remoteClientIdentifier) >+{ >+ auto removeRemoteClient = [&](RemoteResourceClientsHashMap& remoteResourceForRemoteClients, RemoteResourceIdentifier remoteClientIdentifier) { >+ Vector<RemoteResourceIdentifier> remoteResourceClientsToBeRemoved; >+ >+ // Remove all the resource -> client dependencies from remoteResourceClientsHashMap. >+ for (auto& pair : remoteResourceForRemoteClients) { >+ pair.value.remove(remoteClientIdentifier); >+ if (pair.value.isEmpty()) >+ remoteResourceClientsToBeRemoved.append(pair.key); >+ } >+ >+ // Return a list of the unreferenced resources. >+ return remoteResourceClientsToBeRemoved; >+ }; >+ >+ // Remove all the resource -> client dependencies from m_lockedRemoteResourceForRemoteClients. >+ for (auto remoteResourceIdentifier : removeRemoteClient(m_lockedRemoteResourceForRemoteClients, remoteClientIdentifier)) >+ m_lockedRemoteResourceForRemoteClients.remove(remoteResourceIdentifier); >+ >+ // Remove all the resource -> client dependencies from m_pendingUnlockRemoteResourceForRemoteClients. >+ for (auto remoteResourceIdentifier : removeRemoteClient(m_pendingUnlockRemoteResourceForRemoteClients, remoteClientIdentifier)) { >+ // Remove the unreferenced resources from m_remoteResourceClientsPendingReleaseHashMap. >+ m_pendingUnlockRemoteResourceForRemoteClients.remove(remoteResourceIdentifier); >+ >+ // Tell the GPU process to remove this resource. >+ m_remoteRenderingBackendProxy.releaseRemoteResource(remoteResourceIdentifier); >+ } >+} >+ >+} // namespace WebKit >+ >+#endif // ENABLE(GPU_PROCESS) >diff --git a/Source/WebKit/WebProcess/GPU/graphics/RemoteResourceCacheProxy.h b/Source/WebKit/WebProcess/GPU/graphics/RemoteResourceCacheProxy.h >new file mode 100644 >index 0000000000000000000000000000000000000000..d4601961e91de459f04af1d90ec833601982c9e1 >--- /dev/null >+++ b/Source/WebKit/WebProcess/GPU/graphics/RemoteResourceCacheProxy.h >@@ -0,0 +1,76 @@ >+/* >+ * Copyright (C) 2020 Apple Inc. All rights reserved. >+ * >+ * Redistribution and use in source and binary forms, with or without >+ * modification, are permitted provided that the following conditions >+ * are met: >+ * 1. Redistributions of source code must retain the above copyright >+ * notice, this list of conditions and the following disclaimer. >+ * 2. Redistributions in binary form must reproduce the above copyright >+ * notice, this list of conditions and the following disclaimer in the >+ * documentation and/or other materials provided with the distribution. >+ * >+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY >+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE >+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR >+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR >+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, >+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, >+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR >+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY >+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT >+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE >+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. >+ */ >+ >+#pragma once >+ >+#if ENABLE(GPU_PROCESS) >+ >+#include <WebCore/CachedImageClient.h> >+#include <WebCore/RemoteResourceIdentifier.h> >+#include <wtf/HashMap.h> >+ >+namespace WebCore { >+class CachedImage; >+class ImageBuffer; >+} >+ >+namespace WebKit { >+ >+class RemoteRenderingBackendProxy; >+ >+class RemoteResourceCacheProxy : public WebCore::CachedImageClient { >+public: >+ RemoteResourceCacheProxy(RemoteRenderingBackendProxy&); >+ >+ void cacheImageBuffer(WebCore::RemoteResourceIdentifier, WebCore::ImageBuffer*); >+ WebCore::ImageBuffer* cachedImageBuffer(WebCore::RemoteResourceIdentifier); >+ void releaseImageBuffer(WebCore::RemoteResourceIdentifier); >+ >+ bool lockRemoteImageBufferForRemoteClient(WebCore::ImageBuffer&, WebCore::RemoteResourceIdentifier remoteClientIdentifier); >+ WebCore::RemoteResourceIdentifier lockRemoteNativeImageForRemoteClient(WebCore::CachedImage&, const WebCore::NativeImagePtr&, WebCore::RemoteResourceIdentifier remoteClientIdentifier); >+ void unlockRemoteResourcesForRemoteClient(WebCore::RemoteResourceIdentifier remoteClientIdentifier); >+ >+private: >+ using RemoteClientsHashSet = HashSet<WebCore::RemoteResourceIdentifier>; >+ using RemoteResourceClientsHashMap = HashMap<WebCore::RemoteResourceIdentifier, RemoteClientsHashSet>; >+ using RemoteImageBufferProxyHashMap = HashMap<WebCore::RemoteResourceIdentifier, WebCore::ImageBuffer*>; >+ using RemoteNativeImageHashMap = HashMap<WebCore::NativeImagePtr, WebCore::RemoteResourceIdentifier>; >+ using RemoteCachedImageHashMap = HashMap<WebCore::CachedImage*, RemoteNativeImageHashMap>; >+ >+ void nativeImageWillBeDestroyed(WebCore::CachedImage&, const WebCore::NativeImagePtr&) override; >+ >+ void lockRemoteResourceForRemoteClient(WebCore::RemoteResourceIdentifier, WebCore::RemoteResourceIdentifier remoteClientIdentifier); >+ void releaseRemoteResource(WebCore::RemoteResourceIdentifier); >+ >+ RemoteImageBufferProxyHashMap m_imageBuffers; >+ RemoteResourceClientsHashMap m_lockedRemoteResourceForRemoteClients; >+ RemoteResourceClientsHashMap m_pendingUnlockRemoteResourceForRemoteClients; >+ RemoteCachedImageHashMap m_cachedImages; >+ RemoteRenderingBackendProxy& m_remoteRenderingBackendProxy; >+}; >+ >+} // namespace WebKit >+ >+#endif // ENABLE(GPU_PROCESS)
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