Title: [295372] trunk/Source
Revision
295372
Author
[email protected]
Date
2022-06-07 20:48:18 -0700 (Tue, 07 Jun 2022)

Log Message

[GPU Process] [Filters] Make FilterImage allocate shared memory if it is created in GPUProcess
https://bugs.webkit.org/show_bug.cgi?id=240810
<rdar://problem/94118129>

Reviewed by Kimmo Kinnunen.

PixelBuffer will be sub-classed to a new class named 'ShareablePixelBuffer'. This
class will be backed by SharedMemory for the pixels.

ImageBufferShareableAllocator will call ShareablePixelBuffer::tryCreate() to
allocate PixelBuffe for software filters when they are applied in GPUProcess.

The plan is to attribute the handle of the underlying SharedMemory to WebProcess.

* Source/WebKit/GPUProcess/graphics/ImageBufferShareableAllocator.cpp:
(WebKit::ImageBufferShareableAllocator::createPixelBuffer const):
* Source/WebKit/GPUProcess/graphics/ShareablePixelBuffer.cpp: Copied from Source/WebKit/GPUProcess/graphics/ImageBufferShareableAllocator.cpp.
(WebKit::ShareablePixelBuffer::tryCreate):
(WebKit::ShareablePixelBuffer::ShareablePixelBuffer):
(WebKit::ShareablePixelBuffer::createScratchPixelBuffer const):
* Source/WebKit/GPUProcess/graphics/ShareablePixelBuffer.h: Added.
(WebKit::ShareablePixelBuffer::data const):
(WebKit::ShareablePixelBuffer::takeData):
* Source/WebKit/GPUProcess/webrtc/RemoteSampleBufferDisplayLayer.cpp:
* Source/WebKit/Sources.txt:
* Source/WebKit/WebKit.xcodeproj/project.pbxproj:

Canonical link: https://commits.webkit.org/251380@main

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/html/ImageData.cpp (295371 => 295372)


--- trunk/Source/WebCore/html/ImageData.cpp	2022-06-08 00:38:02 UTC (rev 295371)
+++ trunk/Source/WebCore/html/ImageData.cpp	2022-06-08 03:48:18 UTC (rev 295372)
@@ -53,7 +53,7 @@
 Ref<ImageData> ImageData::create(Ref<ByteArrayPixelBuffer>&& pixelBuffer)
 {
     auto colorSpace = toPredefinedColorSpace(pixelBuffer->format().colorSpace);
-    return adoptRef(*new ImageData(pixelBuffer->size(), pixelBuffer->takeData(), *colorSpace));
+    return adoptRef(*new ImageData(pixelBuffer->size(), ByteArrayPixelBuffer::data(WTFMove(pixelBuffer)), *colorSpace));
 }
 
 RefPtr<ImageData> ImageData::create(RefPtr<ByteArrayPixelBuffer>&& pixelBuffer)

Modified: trunk/Source/WebCore/platform/graphics/ByteArrayPixelBuffer.cpp (295371 => 295372)


--- trunk/Source/WebCore/platform/graphics/ByteArrayPixelBuffer.cpp	2022-06-08 00:38:02 UTC (rev 295371)
+++ trunk/Source/WebCore/platform/graphics/ByteArrayPixelBuffer.cpp	2022-06-08 03:48:18 UTC (rev 295372)
@@ -87,6 +87,13 @@
 {
 }
 
+Ref<JSC::Uint8ClampedArray> ByteArrayPixelBuffer::data(Ref<ByteArrayPixelBuffer> pixelBuffer)
+{
+    if (pixelBuffer->hasOneRef())
+        return WTFMove(pixelBuffer->m_data);
+    return pixelBuffer->m_data;
+}
+
 RefPtr<PixelBuffer> ByteArrayPixelBuffer::createScratchPixelBuffer(const IntSize& size) const
 {
     return ByteArrayPixelBuffer::tryCreate(m_format, size);

Modified: trunk/Source/WebCore/platform/graphics/ByteArrayPixelBuffer.h (295371 => 295372)


--- trunk/Source/WebCore/platform/graphics/ByteArrayPixelBuffer.h	2022-06-08 00:38:02 UTC (rev 295371)
+++ trunk/Source/WebCore/platform/graphics/ByteArrayPixelBuffer.h	2022-06-08 03:48:18 UTC (rev 295372)
@@ -38,7 +38,7 @@
     WEBCORE_EXPORT static RefPtr<ByteArrayPixelBuffer> tryCreate(const PixelBufferFormat&, const IntSize&, Ref<JSC::ArrayBuffer>&&);
 
     JSC::Uint8ClampedArray& data() const { return m_data.get(); }
-    Ref<JSC::Uint8ClampedArray>&& takeData() { return WTFMove(m_data); }
+    static Ref<JSC::Uint8ClampedArray> data(Ref<ByteArrayPixelBuffer>);
 
     RefPtr<PixelBuffer> createScratchPixelBuffer(const IntSize&) const override;
 

Modified: trunk/Source/WebKit/GPUProcess/graphics/ImageBufferShareableAllocator.cpp (295371 => 295372)


--- trunk/Source/WebKit/GPUProcess/graphics/ImageBufferShareableAllocator.cpp	2022-06-08 00:38:02 UTC (rev 295371)
+++ trunk/Source/WebKit/GPUProcess/graphics/ImageBufferShareableAllocator.cpp	2022-06-08 03:48:18 UTC (rev 295372)
@@ -27,6 +27,7 @@
 #include "ImageBufferShareableAllocator.h"
 
 #include "ImageBufferShareableBitmapBackend.h"
+#include "ShareablePixelBuffer.h"
 #include <WebCore/ConcreteImageBuffer.h>
 
 #if ENABLE(GPU_PROCESS)
@@ -61,8 +62,16 @@
 
 RefPtr<PixelBuffer> ImageBufferShareableAllocator::createPixelBuffer(const PixelBufferFormat& format, const IntSize& size) const
 {
-    // FIXME: Create a shareable PixelBuffer and transfer the ownership of its memory to WebProcess.
-    return ImageBufferAllocator::createPixelBuffer(format, size);
+    auto pixelBuffer = ShareablePixelBuffer::tryCreate(format, size);
+    if (!pixelBuffer)
+        return nullptr;
+
+    SharedMemory::Handle handle;
+    if (!pixelBuffer->data().createHandle(handle, SharedMemory::Protection::ReadOnly))
+        return nullptr;
+
+    transferMemoryOwnership(WTFMove(handle), pixelBuffer->sizeInBytes());
+    return pixelBuffer;
 }
 
 void ImageBufferShareableAllocator::transferMemoryOwnership(SharedMemory::Handle&&, size_t) const

Copied: trunk/Source/WebKit/GPUProcess/graphics/ShareablePixelBuffer.cpp (from rev 295371, trunk/Source/WebKit/GPUProcess/graphics/ImageBufferShareableAllocator.cpp) (0 => 295372)


--- trunk/Source/WebKit/GPUProcess/graphics/ShareablePixelBuffer.cpp	                        (rev 0)
+++ trunk/Source/WebKit/GPUProcess/graphics/ShareablePixelBuffer.cpp	2022-06-08 03:48:18 UTC (rev 295372)
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) 2022 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 "ShareablePixelBuffer.h"
+
+#include "SharedMemory.h"
+
+namespace WebKit {
+using namespace WebCore;
+
+RefPtr<ShareablePixelBuffer> ShareablePixelBuffer::tryCreate(const PixelBufferFormat& format, const IntSize& size)
+{
+    ASSERT(supportedPixelFormat(format.pixelFormat));
+
+    auto bufferSize = computeBufferSize(format, size);
+    if (bufferSize.hasOverflowed())
+        return nullptr;
+    if (bufferSize > std::numeric_limits<int32_t>::max())
+        return nullptr;
+
+    RefPtr<SharedMemory> sharedMemory = SharedMemory::allocate(bufferSize);
+    if (!sharedMemory)
+        return nullptr;
+
+    return adoptRef(new ShareablePixelBuffer(format, size, sharedMemory.releaseNonNull()));
+}
+
+ShareablePixelBuffer::ShareablePixelBuffer(const PixelBufferFormat& format, const IntSize& size, Ref<SharedMemory>&& data)
+    : PixelBuffer(format, size, static_cast<uint8_t*>(data->data()), data->size())
+    , m_data(WTFMove(data))
+{
+    RELEASE_ASSERT_WITH_SECURITY_IMPLICATION((m_size.area() * 4) <= sizeInBytes());
+}
+
+RefPtr<PixelBuffer> ShareablePixelBuffer::createScratchPixelBuffer(const IntSize& size) const
+{
+    return ShareablePixelBuffer::tryCreate(m_format, size);
+}
+
+} // namespace WebKit

Added: trunk/Source/WebKit/GPUProcess/graphics/ShareablePixelBuffer.h (0 => 295372)


--- trunk/Source/WebKit/GPUProcess/graphics/ShareablePixelBuffer.h	                        (rev 0)
+++ trunk/Source/WebKit/GPUProcess/graphics/ShareablePixelBuffer.h	2022-06-08 03:48:18 UTC (rev 295372)
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2022 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
+
+#include <WebCore/PixelBuffer.h>
+
+namespace WebKit {
+
+class SharedMemory;
+
+class ShareablePixelBuffer : public WebCore::PixelBuffer {
+public:
+    static RefPtr<ShareablePixelBuffer> tryCreate(const WebCore::PixelBufferFormat&, const WebCore::IntSize&);
+
+    SharedMemory& data() const { return m_data.get(); }
+
+    RefPtr<WebCore::PixelBuffer> createScratchPixelBuffer(const WebCore::IntSize&) const override;
+
+private:
+    ShareablePixelBuffer(const WebCore::PixelBufferFormat&, const WebCore::IntSize&, Ref<SharedMemory>&&);
+
+    Ref<SharedMemory> m_data;
+};
+
+} // namespace WebKit

Modified: trunk/Source/WebKit/GPUProcess/webrtc/RemoteSampleBufferDisplayLayer.cpp (295371 => 295372)


--- trunk/Source/WebKit/GPUProcess/webrtc/RemoteSampleBufferDisplayLayer.cpp	2022-06-08 00:38:02 UTC (rev 295371)
+++ trunk/Source/WebKit/GPUProcess/webrtc/RemoteSampleBufferDisplayLayer.cpp	2022-06-08 03:48:18 UTC (rev 295372)
@@ -28,6 +28,7 @@
 
 #if PLATFORM(COCOA) && ENABLE(GPU_PROCESS) && ENABLE(MEDIA_STREAM)
 
+#include "GPUConnectionToWebProcess.h"
 #include "IPCTester.h"
 #include "RemoteVideoFrameObjectHeap.h"
 #include "SampleBufferDisplayLayerMessages.h"

Modified: trunk/Source/WebKit/Sources.txt (295371 => 295372)


--- trunk/Source/WebKit/Sources.txt	2022-06-08 00:38:02 UTC (rev 295371)
+++ trunk/Source/WebKit/Sources.txt	2022-06-08 03:48:18 UTC (rev 295372)
@@ -31,6 +31,7 @@
 GPUProcess/graphics/RemoteResourceCache.cpp
 GPUProcess/graphics/ScopedRenderingResourcesRequest.cpp
 GPUProcess/graphics/ScopedWebGLRenderingResourcesRequest.cpp
+GPUProcess/graphics/ShareablePixelBuffer.cpp
 GPUProcess/graphics/WebGPU/RemoteAdapter.cpp
 GPUProcess/graphics/WebGPU/RemoteBindGroup.cpp
 GPUProcess/graphics/WebGPU/RemoteBindGroupLayout.cpp

Modified: trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj (295371 => 295372)


--- trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj	2022-06-08 00:38:02 UTC (rev 295371)
+++ trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj	2022-06-08 03:48:18 UTC (rev 295372)
@@ -5382,6 +5382,8 @@
 		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>"; };
+		72C11DB52849933700E826DD /* ShareablePixelBuffer.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = ShareablePixelBuffer.cpp; sourceTree = "<group>"; };
+		72C11DB62849933700E826DD /* ShareablePixelBuffer.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ShareablePixelBuffer.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>"; };
@@ -10444,6 +10446,8 @@
 				7BCF70CB2614935E00E4FB70 /* ScopedRenderingResourcesRequestCocoa.mm */,
 				7BCF70CC2614935F00E4FB70 /* ScopedWebGLRenderingResourcesRequest.cpp */,
 				7BCF70CE2614935F00E4FB70 /* ScopedWebGLRenderingResourcesRequest.h */,
+				72C11DB52849933700E826DD /* ShareablePixelBuffer.cpp */,
+				72C11DB62849933700E826DD /* ShareablePixelBuffer.h */,
 			);
 			path = graphics;
 			sourceTree = "<group>";
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to