Title: [258069] trunk/Source/WebKit
Revision
258069
Author
[email protected]
Date
2020-03-07 01:28:06 -0800 (Sat, 07 Mar 2020)

Log Message

[GPU Process] Implement CanvasRenderingContext2D.getImageData()
https://bugs.webkit.org/show_bug.cgi?id=208560
<rdar://problem/60060618>

Reviewed by Said Abou-Hallawa.

Adds a new synchronous message between the Web Process and the GPU Process.
Unfortunately, getImageData() synchronously returns results, and we don't
have the infrastructure to make _javascript_ interruptible, so this means that
the message has to be synchronous, at least until we add that infrastructure.

When the RemoteImageBuffer receives the getImageData() call, it first
asynchronously flushes the pending display list, doesn't wait for a response,
and then sends the synchronous getImageData() message. Because the GPU Process
receives messages in-order, the Web Process doesn't have to wait for the
response from the flush message.

After this patch, there are a few optimization opportunities we can exploit
where we use SharedBuffer directly instead of copying into and out of the
ImageData.

No new tests because there is no behavior change. We're just using the GPU
process now, instead of implementing the command locally in the Web Process.

* GPUProcess/graphics/RemoteImageBufferMessageHandlerProxy.h:
* GPUProcess/graphics/RemoteImageBufferProxy.h:
* GPUProcess/graphics/RemoteRenderingBackendProxy.cpp:
(WebKit::RemoteRenderingBackendProxy::getImageData):
* GPUProcess/graphics/RemoteRenderingBackendProxy.h:
* GPUProcess/graphics/RemoteRenderingBackendProxy.messages.in:
* Platform/IPC/ImageDataReference.h: Added.
(IPC::ImageDataReference::ImageDataReference):
(IPC::ImageDataReference::buffer):
(IPC::ImageDataReference::buffer const):
(IPC::ImageDataReference::encode const):
(IPC::ImageDataReference::decode):
* Platform/IPC/MessageSender.h:
(IPC::MessageSender::sendSync):
* Shared/WebCoreArgumentCoders.cpp:
(IPC::ArgumentCoder<RefPtr<WebCore::ImageData>>::encode):
(IPC::ArgumentCoder<RefPtr<WebCore::ImageData>>::decode):
* Shared/WebCoreArgumentCoders.h:
* WebKit.xcodeproj/project.pbxproj:
* WebProcess/GPU/graphics/RemoteImageBuffer.h:
* WebProcess/GPU/graphics/RemoteImageBufferMessageHandler.cpp:
(WebKit::RemoteImageBufferMessageHandler::getImageData const):
(WebKit::RemoteImageBufferMessageHandler::flushDrawingContext):
(WebKit::RemoteImageBufferMessageHandler::flushDrawingContextAndWaitCommit):
* WebProcess/GPU/graphics/RemoteImageBufferMessageHandler.h:

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (258068 => 258069)


--- trunk/Source/WebKit/ChangeLog	2020-03-07 09:17:01 UTC (rev 258068)
+++ trunk/Source/WebKit/ChangeLog	2020-03-07 09:28:06 UTC (rev 258069)
@@ -1,3 +1,55 @@
+2020-03-07  Myles C. Maxfield  <[email protected]>
+
+        [GPU Process] Implement CanvasRenderingContext2D.getImageData()
+        https://bugs.webkit.org/show_bug.cgi?id=208560
+        <rdar://problem/60060618>
+
+        Reviewed by Said Abou-Hallawa.
+
+        Adds a new synchronous message between the Web Process and the GPU Process.
+        Unfortunately, getImageData() synchronously returns results, and we don't
+        have the infrastructure to make _javascript_ interruptible, so this means that
+        the message has to be synchronous, at least until we add that infrastructure.
+
+        When the RemoteImageBuffer receives the getImageData() call, it first
+        asynchronously flushes the pending display list, doesn't wait for a response, 
+        and then sends the synchronous getImageData() message. Because the GPU Process
+        receives messages in-order, the Web Process doesn't have to wait for the
+        response from the flush message.
+
+        After this patch, there are a few optimization opportunities we can exploit
+        where we use SharedBuffer directly instead of copying into and out of the
+        ImageData.
+
+        No new tests because there is no behavior change. We're just using the GPU
+        process now, instead of implementing the command locally in the Web Process.
+
+        * GPUProcess/graphics/RemoteImageBufferMessageHandlerProxy.h:
+        * GPUProcess/graphics/RemoteImageBufferProxy.h:
+        * GPUProcess/graphics/RemoteRenderingBackendProxy.cpp:
+        (WebKit::RemoteRenderingBackendProxy::getImageData):
+        * GPUProcess/graphics/RemoteRenderingBackendProxy.h:
+        * GPUProcess/graphics/RemoteRenderingBackendProxy.messages.in:
+        * Platform/IPC/ImageDataReference.h: Added.
+        (IPC::ImageDataReference::ImageDataReference):
+        (IPC::ImageDataReference::buffer):
+        (IPC::ImageDataReference::buffer const):
+        (IPC::ImageDataReference::encode const):
+        (IPC::ImageDataReference::decode):
+        * Platform/IPC/MessageSender.h:
+        (IPC::MessageSender::sendSync):
+        * Shared/WebCoreArgumentCoders.cpp:
+        (IPC::ArgumentCoder<RefPtr<WebCore::ImageData>>::encode):
+        (IPC::ArgumentCoder<RefPtr<WebCore::ImageData>>::decode):
+        * Shared/WebCoreArgumentCoders.h:
+        * WebKit.xcodeproj/project.pbxproj:
+        * WebProcess/GPU/graphics/RemoteImageBuffer.h:
+        * WebProcess/GPU/graphics/RemoteImageBufferMessageHandler.cpp:
+        (WebKit::RemoteImageBufferMessageHandler::getImageData const):
+        (WebKit::RemoteImageBufferMessageHandler::flushDrawingContext):
+        (WebKit::RemoteImageBufferMessageHandler::flushDrawingContextAndWaitCommit):
+        * WebProcess/GPU/graphics/RemoteImageBufferMessageHandler.h:
+
 2020-03-07  chris fleizach  <[email protected]>
 
         Unreviewed, rolling out r258047.

Modified: trunk/Source/WebKit/GPUProcess/graphics/RemoteImageBufferMessageHandlerProxy.h (258068 => 258069)


--- trunk/Source/WebKit/GPUProcess/graphics/RemoteImageBufferMessageHandlerProxy.h	2020-03-07 09:17:01 UTC (rev 258068)
+++ trunk/Source/WebKit/GPUProcess/graphics/RemoteImageBufferMessageHandlerProxy.h	2020-03-07 09:28:06 UTC (rev 258069)
@@ -33,6 +33,11 @@
 #include <WebCore/DisplayList.h>
 #include <WebCore/FloatSize.h>
 
+namespace WebCore {
+enum class AlphaPremultiplication : uint8_t;
+class ImageData;
+}
+
 namespace WebKit {
 
 class RemoteRenderingBackendProxy;
@@ -43,6 +48,7 @@
 
     // Messages to be received. See RemoteRenderingBackendProxy.messages.in.
     virtual void flushDrawingContext(const WebCore::DisplayList::DisplayList&, ImageBufferFlushIdentifier) = 0;
+    virtual RefPtr<WebCore::ImageData> getImageData(WebCore::AlphaPremultiplication outputFormat, const WebCore::IntRect& srcRect) const = 0;
 
 protected:
     RemoteImageBufferMessageHandlerProxy(RemoteRenderingBackendProxy&, ImageBufferIdentifier);

Modified: trunk/Source/WebKit/GPUProcess/graphics/RemoteImageBufferProxy.h (258068 => 258069)


--- trunk/Source/WebKit/GPUProcess/graphics/RemoteImageBufferProxy.h	2020-03-07 09:17:01 UTC (rev 258068)
+++ trunk/Source/WebKit/GPUProcess/graphics/RemoteImageBufferProxy.h	2020-03-07 09:28:06 UTC (rev 258069)
@@ -65,6 +65,11 @@
         commitFlushContext(flushIdentifier);
     }
 
+    RefPtr<WebCore::ImageData> getImageData(WebCore::AlphaPremultiplication outputFormat, const WebCore::IntRect& srcRect) const override
+    {
+        return BaseConcreteImageBuffer::getImageData(outputFormat, srcRect);
+    }
+
     bool apply(DisplayList::Item& item, GraphicsContext&) override
     {
         if (item.type() != DisplayList::ItemType::PutImageData)

Modified: trunk/Source/WebKit/GPUProcess/graphics/RemoteRenderingBackendProxy.cpp (258068 => 258069)


--- trunk/Source/WebKit/GPUProcess/graphics/RemoteRenderingBackendProxy.cpp	2020-03-07 09:17:01 UTC (rev 258068)
+++ trunk/Source/WebKit/GPUProcess/graphics/RemoteRenderingBackendProxy.cpp	2020-03-07 09:28:06 UTC (rev 258069)
@@ -100,6 +100,14 @@
     ASSERT_UNUSED(found, found);
 }
 
+void RemoteRenderingBackendProxy::getImageData(WebCore::AlphaPremultiplication outputFormat, WebCore::IntRect srcRect, ImageBufferIdentifier imageBufferIdentifier, CompletionHandler<void(IPC::ImageDataReference&&)>&& completionHandler)
+{
+    if (auto imageBuffer = m_imageBufferMessageHandlerMap.get(imageBufferIdentifier)) {
+        auto imageData = imageBuffer->getImageData(outputFormat, srcRect);
+        completionHandler(IPC::ImageDataReference(WTFMove(imageData)));
+    }
+}
+
 void RemoteRenderingBackendProxy::flushImageBufferDrawingContext(const WebCore::DisplayList::DisplayList& displayList, ImageBufferFlushIdentifier flushIdentifier, ImageBufferIdentifier imageBufferIdentifier)
 {
     if (auto imageBuffer = m_imageBufferMessageHandlerMap.get(imageBufferIdentifier))

Modified: trunk/Source/WebKit/GPUProcess/graphics/RemoteRenderingBackendProxy.h (258068 => 258069)


--- trunk/Source/WebKit/GPUProcess/graphics/RemoteRenderingBackendProxy.h	2020-03-07 09:17:01 UTC (rev 258068)
+++ trunk/Source/WebKit/GPUProcess/graphics/RemoteRenderingBackendProxy.h	2020-03-07 09:28:06 UTC (rev 258069)
@@ -30,6 +30,7 @@
 #include "Connection.h"
 #include "ImageBufferFlushIdentifier.h"
 #include "ImageBufferIdentifier.h"
+#include "ImageDataReference.h"
 #include "MessageReceiver.h"
 #include "MessageSender.h"
 #include "RemoteImageBufferMessageHandlerProxy.h"
@@ -63,11 +64,13 @@
 
     // IPC::MessageReceiver
     void didReceiveMessage(IPC::Connection&, IPC::Decoder&) override;
+    void didReceiveSyncMessage(IPC::Connection&, IPC::Decoder&, std::unique_ptr<IPC::Encoder>&) override;
 
     // Messages to be received.
     void createImageBuffer(const WebCore::FloatSize& logicalSize, WebCore::RenderingMode, float resolutionScale, WebCore::ColorSpace, ImageBufferIdentifier);
     void releaseImageBuffer(ImageBufferIdentifier);
     void flushImageBufferDrawingContext(const WebCore::DisplayList::DisplayList&, ImageBufferFlushIdentifier, ImageBufferIdentifier);
+    void getImageData(WebCore::AlphaPremultiplication outputFormat, WebCore::IntRect srcRect, ImageBufferIdentifier, CompletionHandler<void(IPC::ImageDataReference&&)>&&);
 
     using ImageBufferMessageHandlerMap = HashMap<ImageBufferIdentifier, std::unique_ptr<RemoteImageBufferMessageHandlerProxy>>;
     ImageBufferMessageHandlerMap m_imageBufferMessageHandlerMap;

Modified: trunk/Source/WebKit/GPUProcess/graphics/RemoteRenderingBackendProxy.messages.in (258068 => 258069)


--- trunk/Source/WebKit/GPUProcess/graphics/RemoteRenderingBackendProxy.messages.in	2020-03-07 09:17:01 UTC (rev 258068)
+++ trunk/Source/WebKit/GPUProcess/graphics/RemoteRenderingBackendProxy.messages.in	2020-03-07 09:28:06 UTC (rev 258069)
@@ -26,6 +26,7 @@
     void CreateImageBuffer(WebCore::FloatSize logicalSize, WebCore::RenderingMode renderingMode, float resolutionScale, WebCore::ColorSpace colorSpace, WebKit::ImageBufferIdentifier imageBufferIdentifier)
     void ReleaseImageBuffer(WebKit::ImageBufferIdentifier imageBufferIdentifier)
     void FlushImageBufferDrawingContext(WebCore::DisplayList::DisplayList displayList, WebKit::ImageBufferFlushIdentifier flushIdentifier, WebKit::ImageBufferIdentifier imageBufferIdentifier)
+    GetImageData(enum:uint8_t WebCore::AlphaPremultiplication outputFormat, WebCore::IntRect srcRect, WebKit::ImageBufferIdentifier imageBufferIdentifier) -> (IPC::ImageDataReference imageData) Synchronous
 }
 
 #endif // ENABLE(GPU_PROCESS)

Added: trunk/Source/WebKit/Platform/IPC/ImageDataReference.h (0 => 258069)


--- trunk/Source/WebKit/Platform/IPC/ImageDataReference.h	                        (rev 0)
+++ trunk/Source/WebKit/Platform/IPC/ImageDataReference.h	2020-03-07 09:28:06 UTC (rev 258069)
@@ -0,0 +1,62 @@
+/*
+ * 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.
+ */
+
+#pragma once
+
+#include "WebCoreArgumentCoders.h"
+#include <WebCore/ImageBuffer.h>
+
+namespace IPC {
+
+class ImageDataReference {
+public:
+    ImageDataReference() = default;
+    ImageDataReference(RefPtr<WebCore::ImageData>&& imageData)
+        : m_imageData(WTFMove(imageData))
+    {
+    }
+
+    RefPtr<WebCore::ImageData>& buffer() { return m_imageData; }
+    const RefPtr<WebCore::ImageData>& buffer() const { return m_imageData; }
+
+    void encode(Encoder& encoder) const
+    {
+        encoder << m_imageData;
+    }
+
+    static Optional<ImageDataReference> decode(Decoder& decoder)
+    {
+        Optional<RefPtr<WebCore::ImageData>> imageData;
+        decoder >> imageData;
+        if (!imageData)
+            return WTF::nullopt;
+        return { WTFMove(*imageData) };
+    }
+
+private:
+    RefPtr<WebCore::ImageData> m_imageData;
+};
+
+}

Modified: trunk/Source/WebKit/Platform/IPC/MessageSender.h (258068 => 258069)


--- trunk/Source/WebKit/Platform/IPC/MessageSender.h	2020-03-07 09:17:01 UTC (rev 258068)
+++ trunk/Source/WebKit/Platform/IPC/MessageSender.h	2020-03-07 09:28:06 UTC (rev 258069)
@@ -71,6 +71,12 @@
         return messageSenderConnection()->sendSync(WTFMove(message), WTFMove(reply), destinationID, timeout, sendSyncOptions);
     }
 
+    template<typename U, typename T>
+    bool sendSync(U&& message, typename U::Reply&& reply, ObjectIdentifier<T> destinationID, Seconds timeout = Seconds::infinity(), OptionSet<SendSyncOption> sendSyncOptions = { })
+    {
+        return sendSync<U>(std::forward<U>(message), WTFMove(reply), destinationID.toUInt64(), timeout, sendSyncOptions);
+    }
+
     template<typename T, typename C>
     void sendWithAsyncReply(T&& message, C&& completionHandler, OptionSet<SendOption> sendOptions = { })
     {

Modified: trunk/Source/WebKit/Shared/WebCoreArgumentCoders.cpp (258068 => 258069)


--- trunk/Source/WebKit/Shared/WebCoreArgumentCoders.cpp	2020-03-07 09:17:01 UTC (rev 258068)
+++ trunk/Source/WebKit/Shared/WebCoreArgumentCoders.cpp	2020-03-07 09:28:06 UTC (rev 258069)
@@ -3342,4 +3342,30 @@
     return { imageData.releaseNonNull() };
 }
 
+void ArgumentCoder<RefPtr<WebCore::ImageData>>::encode(Encoder& encoder, const RefPtr<WebCore::ImageData>& imageData)
+{
+    if (!imageData) {
+        encoder << false;
+        return;
+    }
+
+    encoder << true;
+    ArgumentCoder<Ref<WebCore::ImageData>>::encode(encoder, imageData.copyRef().releaseNonNull());
+}
+
+Optional<RefPtr<WebCore::ImageData>> ArgumentCoder<RefPtr<WebCore::ImageData>>::decode(Decoder& decoder)
+{
+    bool isEngaged;
+    if (!decoder.decode(isEngaged))
+        return WTF::nullopt;
+
+    if (!isEngaged)
+        return RefPtr<WebCore::ImageData>();
+
+    auto result = ArgumentCoder<Ref<WebCore::ImageData>>::decode(decoder);
+    if (!result)
+        return WTF::nullopt;
+    return { WTFMove(*result) };
+}
+
 } // namespace IPC

Modified: trunk/Source/WebKit/Shared/WebCoreArgumentCoders.h (258068 => 258069)


--- trunk/Source/WebKit/Shared/WebCoreArgumentCoders.h	2020-03-07 09:17:01 UTC (rev 258068)
+++ trunk/Source/WebKit/Shared/WebCoreArgumentCoders.h	2020-03-07 09:28:06 UTC (rev 258069)
@@ -859,6 +859,11 @@
 };
 #endif
 
+template<> struct ArgumentCoder<RefPtr<WebCore::ImageData>> {
+    static void encode(Encoder&, const RefPtr<WebCore::ImageData>&);
+    static Optional<RefPtr<WebCore::ImageData>> decode(Decoder&);
+};
+
 template<> struct ArgumentCoder<Ref<WebCore::ImageData>> {
     static void encode(Encoder&, const Ref<WebCore::ImageData>&);
     static Optional<Ref<WebCore::ImageData>> decode(Decoder&);

Modified: trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj (258068 => 258069)


--- trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj	2020-03-07 09:17:01 UTC (rev 258068)
+++ trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj	2020-03-07 09:28:06 UTC (rev 258069)
@@ -2719,6 +2719,7 @@
 		1C8E2A311277852400BC7BD0 /* WebInspectorMessageReceiver.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = WebInspectorMessageReceiver.cpp; path = DerivedSources/WebKit2/WebInspectorMessageReceiver.cpp; sourceTree = BUILT_PRODUCTS_DIR; };
 		1C8E2A321277852400BC7BD0 /* WebInspectorMessages.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = WebInspectorMessages.h; path = DerivedSources/WebKit2/WebInspectorMessages.h; sourceTree = BUILT_PRODUCTS_DIR; };
 		1C8E2DAD1278C5B200BC7BD0 /* WebInspectorUIMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebInspectorUIMac.mm; sourceTree = "<group>"; };
+		1C9AF36124134D2300D3EC02 /* ImageDataReference.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ImageDataReference.h; sourceTree = "<group>"; };
 		1C9EBA5B2087E74E00054429 /* NativeWebMouseEventIOS.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = NativeWebMouseEventIOS.mm; path = ios/NativeWebMouseEventIOS.mm; sourceTree = "<group>"; };
 		1CA8B935127C774E00576C2B /* WebInspectorProxyMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebInspectorProxyMac.mm; sourceTree = "<group>"; };
 		1CA8B943127C882A00576C2B /* WebInspectorProxyMessageReceiver.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = WebInspectorProxyMessageReceiver.cpp; path = DerivedSources/WebKit2/WebInspectorProxyMessageReceiver.cpp; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -6314,6 +6315,7 @@
 				BC032DA010F437D10058C15A /* Encoder.h */,
 				4151E5C31FBB90A900E47E2D /* FormDataReference.h */,
 				C0CE72AC1247E78D00BC0EC4 /* HandleMessage.h */,
+				1C9AF36124134D2300D3EC02 /* ImageDataReference.h */,
 				1AC4C82816B876A90069DCCD /* MessageFlags.h */,
 				1A3EED11161A53D600AEB4F5 /* MessageReceiver.h */,
 				1A3EED0C161A535300AEB4F5 /* MessageReceiverMap.cpp */,

Modified: trunk/Source/WebKit/WebProcess/GPU/graphics/RemoteImageBuffer.h (258068 => 258069)


--- trunk/Source/WebKit/WebProcess/GPU/graphics/RemoteImageBuffer.h	2020-03-07 09:17:01 UTC (rev 258068)
+++ trunk/Source/WebKit/WebProcess/GPU/graphics/RemoteImageBuffer.h	2020-03-07 09:28:06 UTC (rev 258069)
@@ -73,6 +73,15 @@
         return m_backend.get();
     }
 
+    RefPtr<WebCore::ImageData> getImageData(WebCore::AlphaPremultiplication outputFormat, const WebCore::IntRect& srcRect) const override
+    {
+        auto& displayList = m_drawingContext.displayList();
+        const_cast<RemoteImageBuffer*>(this)->RemoteImageBufferMessageHandler::flushDrawingContext(displayList);
+        auto result = const_cast<RemoteImageBuffer*>(this)->RemoteImageBufferMessageHandler::getImageData(outputFormat, srcRect);
+        // getImageData is synchronous, which means we've already received the CommitImageBufferFlushContext message.
+        return result;
+    }
+
     void putImageData(WebCore::AlphaPremultiplication inputFormat, const WebCore::ImageData& imageData, const WebCore::IntRect& srcRect, const WebCore::IntPoint& destPoint = { }) override
     {
         // The math inside ImageData::create() doesn't agree with the math inside ImageBufferBackend::putImageData() about how m_resolutionScale interacts with the data in the ImageBuffer.
@@ -91,8 +100,7 @@
     {
         auto& displayList = m_drawingContext.displayList();
         if (displayList.itemCount()) {
-            RemoteImageBufferMessageHandler::flushDrawingContext(displayList);
-            RemoteImageBufferMessageHandler::waitForCommitImageBufferFlushContext();
+            RemoteImageBufferMessageHandler::flushDrawingContextAndWaitCommit(displayList);
             displayList.clear();
         }
     }

Modified: trunk/Source/WebKit/WebProcess/GPU/graphics/RemoteImageBufferMessageHandler.cpp (258068 => 258069)


--- trunk/Source/WebKit/WebProcess/GPU/graphics/RemoteImageBufferMessageHandler.cpp	2020-03-07 09:17:01 UTC (rev 258068)
+++ trunk/Source/WebKit/WebProcess/GPU/graphics/RemoteImageBufferMessageHandler.cpp	2020-03-07 09:28:06 UTC (rev 258069)
@@ -28,6 +28,7 @@
 
 #if ENABLE(GPU_PROCESS)
 
+#include "ImageDataReference.h"
 #include "RemoteRenderingBackend.h"
 #include "RemoteRenderingBackendProxyMessages.h"
 
@@ -49,6 +50,13 @@
     m_remoteRenderingBackend->send(Messages::RemoteRenderingBackendProxy::ReleaseImageBuffer(m_imageBufferIdentifier), m_remoteRenderingBackend->renderingBackendIdentifier());
 }
 
+RefPtr<ImageData> RemoteImageBufferMessageHandler::getImageData(AlphaPremultiplication outputFormat, const IntRect& srcRect) const
+{
+    IPC::ImageDataReference imageDataReference;
+    m_remoteRenderingBackend->sendSync(Messages::RemoteRenderingBackendProxy::GetImageData(outputFormat, srcRect, m_imageBufferIdentifier), Messages::RemoteRenderingBackendProxy::GetImageData::Reply(imageDataReference), m_remoteRenderingBackend->renderingBackendIdentifier(), 1_s);
+    return imageDataReference.buffer();
+}
+
 void RemoteImageBufferMessageHandler::waitForCreateImageBufferBackend()
 {
     if (m_remoteRenderingBackend && !isBackendCreated())
@@ -65,8 +73,16 @@
 {
     if (!m_remoteRenderingBackend)
         return;
+    m_remoteRenderingBackend->send(Messages::RemoteRenderingBackendProxy::FlushImageBufferDrawingContext(displayList, m_sentFlushIdentifier, m_imageBufferIdentifier), m_remoteRenderingBackend->renderingBackendIdentifier());
+}
+
+void RemoteImageBufferMessageHandler::flushDrawingContextAndWaitCommit(const WebCore::DisplayList::DisplayList& displayList)
+{
+    if (!m_remoteRenderingBackend)
+        return;
     m_sentFlushIdentifier = ImageBufferFlushIdentifier::generate();
     m_remoteRenderingBackend->send(Messages::RemoteRenderingBackendProxy::FlushImageBufferDrawingContext(displayList, m_sentFlushIdentifier, m_imageBufferIdentifier), m_remoteRenderingBackend->renderingBackendIdentifier());
+    waitForCommitImageBufferFlushContext();
 }
 
 void RemoteImageBufferMessageHandler::commitFlushContext(ImageBufferFlushIdentifier flushIdentifier)

Modified: trunk/Source/WebKit/WebProcess/GPU/graphics/RemoteImageBufferMessageHandler.h (258068 => 258069)


--- trunk/Source/WebKit/WebProcess/GPU/graphics/RemoteImageBufferMessageHandler.h	2020-03-07 09:17:01 UTC (rev 258068)
+++ trunk/Source/WebKit/WebProcess/GPU/graphics/RemoteImageBufferMessageHandler.h	2020-03-07 09:28:06 UTC (rev 258069)
@@ -34,6 +34,10 @@
 #include <WebCore/FloatSize.h>
 #include <WebCore/RenderingMode.h>
 
+namespace WebCore {
+enum class AlphaPremultiplication : uint8_t;
+}
+
 namespace WebKit {
 
 class RemoteRenderingBackend;
@@ -55,11 +59,14 @@
     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 waitForCreateImageBufferBackend();
     void waitForCommitImageBufferFlushContext();
 
     // Messages to be sent. See RemoteRenderingBackendProxy.messages.in.
     void flushDrawingContext(const WebCore::DisplayList::DisplayList&);
+    void flushDrawingContextAndWaitCommit(const WebCore::DisplayList::DisplayList&);
 
 private:
     WeakPtr<RemoteRenderingBackend> m_remoteRenderingBackend;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to