Diff
Modified: trunk/LayoutTests/ChangeLog (244506 => 244507)
--- trunk/LayoutTests/ChangeLog 2019-04-22 18:35:04 UTC (rev 244506)
+++ trunk/LayoutTests/ChangeLog 2019-04-22 18:41:16 UTC (rev 244507)
@@ -1,3 +1,17 @@
+2019-04-22 Justin Fan <justin_...@apple.com>
+
+ [WebGPU] Move swap chain methods from GPUDevice to GPUCanvasContext
+ https://bugs.webkit.org/show_bug.cgi?id=197126
+
+ Reviewed by Dean Jackson.
+
+ GPUSwapChains are now configured via GPUCanvasContext instead of GPUDevice.
+
+ * webgpu/blend-triangle-strip.html:
+ * webgpu/js/webgpu-functions.js:
+ (createBasicSwapChain):
+ * webgpu/whlsl.html:
+
2019-04-22 Carlos Garcia Campos <cgar...@igalia.com>
REGRESSION(r241289): [GTK] accessibility/removed-continuation-element-causes-crash.html and accessibility/removed-anonymous-block-child-causes-crash.html crashes
Modified: trunk/LayoutTests/webgpu/blend-triangle-strip.html (244506 => 244507)
--- trunk/LayoutTests/webgpu/blend-triangle-strip.html 2019-04-22 18:35:04 UTC (rev 244506)
+++ trunk/LayoutTests/webgpu/blend-triangle-strip.html 2019-04-22 18:41:16 UTC (rev 244507)
@@ -81,7 +81,7 @@
vertexBuffer.setSubData(0, vertexData.buffer);
const context = canvas.getContext("gpu");
- const swapChain = device.createSwapChain({ context: context, format: "bgra8unorm" });
+ const swapChain = context.configureSwapChain({ device: device, format: "bgra8unorm" });
const colorAttachment = {
attachment: swapChain.getCurrentTexture().createDefaultView(),
loadOp: "clear",
Modified: trunk/LayoutTests/webgpu/js/webgpu-functions.js (244506 => 244507)
--- trunk/LayoutTests/webgpu/js/webgpu-functions.js 2019-04-22 18:35:04 UTC (rev 244506)
+++ trunk/LayoutTests/webgpu/js/webgpu-functions.js 2019-04-22 18:41:16 UTC (rev 244507)
@@ -6,7 +6,7 @@
function createBasicSwapChain(canvas, device) {
const context = canvas.getContext("gpu");
- return device.createSwapChain({ context: context, format: "bgra8unorm" });
+ return context.configureSwapChain({ device: device, format: "bgra8unorm" });
}
function createBasicDepthStateDescriptor() {
Modified: trunk/LayoutTests/webgpu/whlsl.html (244506 => 244507)
--- trunk/LayoutTests/webgpu/whlsl.html 2019-04-22 18:35:04 UTC (rev 244506)
+++ trunk/LayoutTests/webgpu/whlsl.html 2019-04-22 18:41:16 UTC (rev 244507)
@@ -90,8 +90,8 @@
const canvas = document.getElementById("canvas");
const context = canvas.getContext("gpu");
- const swapChainDescriptor = {context, format: "bgra8unorm"};
- const swapChain = device.createSwapChain(swapChainDescriptor);
+ const swapChainDescriptor = {device, format: "bgra8unorm"};
+ const swapChain = context.configureSwapChain(swapChainDescriptor);
const outputTexture = swapChain.getCurrentTexture();
const outputTextureView = outputTexture.createDefaultView();
Modified: trunk/Source/WebCore/ChangeLog (244506 => 244507)
--- trunk/Source/WebCore/ChangeLog 2019-04-22 18:35:04 UTC (rev 244506)
+++ trunk/Source/WebCore/ChangeLog 2019-04-22 18:41:16 UTC (rev 244507)
@@ -1,3 +1,40 @@
+2019-04-22 Justin Fan <justin_...@apple.com>
+
+ [WebGPU] Move swap chain methods from GPUDevice to GPUCanvasContext
+ https://bugs.webkit.org/show_bug.cgi?id=197126
+
+ Reviewed by Dean Jackson.
+
+ GPUSwapChains are now configured via GPUCanvasContext instead of GPUDevice. Covers WebGPU API
+ pull request #262.
+
+ Existing WebGPU tests updated to match.
+
+ * Modules/webgpu/GPUCanvasContext.cpp:
+ (WebCore::GPUCanvasContext::configureSwapChain):
+ (WebCore::GPUCanvasContext::replaceSwapChain): Deleted.
+ * Modules/webgpu/GPUCanvasContext.h:
+ * Modules/webgpu/GPUCanvasContext.idl:
+ * Modules/webgpu/WebGPUDevice.cpp:
+ (WebCore::WebGPUDevice::createSwapChain const): Deleted.
+ * Modules/webgpu/WebGPUDevice.h:
+ (WebCore::WebGPUDevice::device):
+ * Modules/webgpu/WebGPUDevice.idl:
+ * Modules/webgpu/WebGPUSwapChainDescriptor.cpp: Copied from Source/WebCore/Modules/webgpu/WebGPUSwapChainDescriptor.h.
+ (WebCore::WebGPUSwapChainDescriptor::asGPUSwapChainDescriptor const):
+ * Modules/webgpu/WebGPUSwapChainDescriptor.h:
+ * Sources.txt:
+ * WebCore.xcodeproj/project.pbxproj:
+ * platform/graphics/gpu/GPUDevice.cpp:
+ (WebCore::GPUDevice::setSwapChain):
+ (WebCore::GPUDevice::tryCreateSwapChain const): Deleted.
+ * platform/graphics/gpu/GPUDevice.h:
+ * platform/graphics/gpu/GPUSwapChain.h:
+ * platform/graphics/gpu/GPUSwapChainDescriptor.h:
+ (WebCore::GPUSwapChainDescriptor::GPUSwapChainDescriptor):
+ * platform/graphics/gpu/cocoa/GPUSwapChainMetal.mm:
+ (WebCore::GPUSwapChain::tryCreate):
+
2019-04-22 Said Abou-Hallawa <s...@apple.com>
Mark SVGStringList properties '[SameObject]' in the IDL files
Modified: trunk/Source/WebCore/Modules/webgpu/GPUCanvasContext.cpp (244506 => 244507)
--- trunk/Source/WebCore/Modules/webgpu/GPUCanvasContext.cpp 2019-04-22 18:35:04 UTC (rev 244506)
+++ trunk/Source/WebCore/Modules/webgpu/GPUCanvasContext.cpp 2019-04-22 18:41:16 UTC (rev 244507)
@@ -25,8 +25,9 @@
#include "config.h"
#include "GPUCanvasContext.h"
-
#include "InspectorInstrumentation.h"
+#include "Logging.h"
+#include "WebGPUSwapChainDescriptor.h"
#if ENABLE(WEBGPU)
@@ -51,14 +52,26 @@
{
}
-void GPUCanvasContext::replaceSwapChain(Ref<WebGPUSwapChain>&& newSwapChain)
+Ref<WebGPUSwapChain> GPUCanvasContext::configureSwapChain(const WebGPUSwapChainDescriptor& descriptor)
{
- ASSERT(newSwapChain->swapChain());
-
- if (m_swapChain)
- m_swapChain->destroy();
-
- m_swapChain = WTFMove(newSwapChain);
+ auto gpuDescriptor = descriptor.asGPUSwapChainDescriptor();
+ if (!gpuDescriptor)
+ return WebGPUSwapChain::create(nullptr);
+
+ auto gpuSwapChain = GPUSwapChain::tryCreate(*gpuDescriptor, canvasBase().width(), canvasBase().height());
+ bool success = gpuSwapChain;
+ auto newSwapChain = WebGPUSwapChain::create(WTFMove(gpuSwapChain));
+
+ // Upon success, invalidate and replace any existing swap chain.
+ if (success) {
+ // FIXME: Test that this works as expected with error reporting.
+ if (m_swapChain)
+ m_swapChain->destroy();
+
+ m_swapChain = newSwapChain.copyRef();
+ }
+
+ return newSwapChain;
}
CALayer* GPUCanvasContext::platformLayer() const
Modified: trunk/Source/WebCore/Modules/webgpu/GPUCanvasContext.h (244506 => 244507)
--- trunk/Source/WebCore/Modules/webgpu/GPUCanvasContext.h 2019-04-22 18:35:04 UTC (rev 244506)
+++ trunk/Source/WebCore/Modules/webgpu/GPUCanvasContext.h 2019-04-22 18:41:16 UTC (rev 244507)
@@ -34,6 +34,8 @@
namespace WebCore {
+struct WebGPUSwapChainDescriptor;
+
class GPUCanvasContext final : public GPUBasedCanvasRenderingContext {
WTF_MAKE_ISO_ALLOCATED(GPUCanvasContext);
public:
@@ -41,7 +43,7 @@
HTMLCanvasElement& canvas() const { return downcast<HTMLCanvasElement>(canvasBase()); }
- void replaceSwapChain(Ref<WebGPUSwapChain>&&);
+ Ref<WebGPUSwapChain> configureSwapChain(const WebGPUSwapChainDescriptor&);
private:
GPUCanvasContext(CanvasBase&);
Modified: trunk/Source/WebCore/Modules/webgpu/GPUCanvasContext.idl (244506 => 244507)
--- trunk/Source/WebCore/Modules/webgpu/GPUCanvasContext.idl 2019-04-22 18:35:04 UTC (rev 244506)
+++ trunk/Source/WebCore/Modules/webgpu/GPUCanvasContext.idl 2019-04-22 18:41:16 UTC (rev 244507)
@@ -24,10 +24,29 @@
*/
// https://github.com/gpuweb/gpuweb/blob/master/design/sketch.webidl
+typedef unsigned long GPUTextureUsageFlags;
+
[
Conditional=WEBGPU,
+ EnabledAtRuntime=WebGPU,
+ ImplementedAs=WebGPUSwapChainDescriptor
+] dictionary WebGPUSwapChainDescriptor {
+ required WebGPUDevice device;
+ required GPUTextureFormat format;
+ GPUTextureUsageFlags usage; // FIXME: default is GPUTextureUsage.OUTPUT_ATTACHMENT.
+};
+
+[
+ Conditional=WEBGPU,
EnabledAtRuntime=WebGPU
] interface GPUCanvasContext {
// back-reference to the canvas
readonly attribute HTMLCanvasElement canvas;
+
+ // Calling configureSwapChain a second time invalidates the previous one,
+ // and all of the textures it’s produced.
+ WebGPUSwapChain configureSwapChain(WebGPUSwapChainDescriptor descriptor);
+
+ // Not implemented yet.
+ // Promise<GPUTextureFormat> getSwapChainPreferredFormat(GPUDevice device);
};
Modified: trunk/Source/WebCore/Modules/webgpu/WebGPUDevice.cpp (244506 => 244507)
--- trunk/Source/WebCore/Modules/webgpu/WebGPUDevice.cpp 2019-04-22 18:35:04 UTC (rev 244506)
+++ trunk/Source/WebCore/Modules/webgpu/WebGPUDevice.cpp 2019-04-22 18:41:16 UTC (rev 244507)
@@ -155,20 +155,6 @@
return WebGPUCommandEncoder::create(WTFMove(commandBuffer));
}
-Ref<WebGPUSwapChain> WebGPUDevice::createSwapChain(const WebGPUSwapChainDescriptor& descriptor) const
-{
- if (!descriptor.context) {
- LOG(WebGPU, "GPUSwapChain::create(): Invalid GPUCanvasContext!");
- return WebGPUSwapChain::create(nullptr);
- }
-
- auto gpuSwapChain = m_device->tryCreateSwapChain(descriptor, descriptor.context->canvasBase().width(), descriptor.context->canvasBase().height());
- auto newSwapChain = WebGPUSwapChain::create(gpuSwapChain.copyRef());
- if (gpuSwapChain)
- descriptor.context->replaceSwapChain(newSwapChain.copyRef());
- return newSwapChain;
-}
-
Ref<WebGPUQueue> WebGPUDevice::getQueue() const
{
if (!m_queue)
Modified: trunk/Source/WebCore/Modules/webgpu/WebGPUDevice.h (244506 => 244507)
--- trunk/Source/WebCore/Modules/webgpu/WebGPUDevice.h 2019-04-22 18:35:04 UTC (rev 244506)
+++ trunk/Source/WebCore/Modules/webgpu/WebGPUDevice.h 2019-04-22 18:41:16 UTC (rev 244507)
@@ -65,6 +65,7 @@
static RefPtr<WebGPUDevice> tryCreate(Ref<const WebGPUAdapter>&&);
const WebGPUAdapter& adapter() const { return m_adapter.get(); }
+ GPUDevice& device() { return m_device.get(); }
const GPUDevice& device() const { return m_device.get(); }
Ref<WebGPUBuffer> createBuffer(const GPUBufferDescriptor&) const;
@@ -81,8 +82,6 @@
Ref<WebGPUCommandEncoder> createCommandEncoder() const;
- Ref<WebGPUSwapChain> createSwapChain(const WebGPUSwapChainDescriptor&) const;
-
Ref<WebGPUQueue> getQueue() const;
private:
Modified: trunk/Source/WebCore/Modules/webgpu/WebGPUDevice.idl (244506 => 244507)
--- trunk/Source/WebCore/Modules/webgpu/WebGPUDevice.idl 2019-04-22 18:35:04 UTC (rev 244506)
+++ trunk/Source/WebCore/Modules/webgpu/WebGPUDevice.idl 2019-04-22 18:41:16 UTC (rev 244507)
@@ -24,21 +24,9 @@
*/
// https://github.com/gpuweb/gpuweb/blob/master/design/sketch.webidl
-typedef unsigned long GPUTextureUsageFlags;
-
[
Conditional=WEBGPU,
EnabledAtRuntime=WebGPU,
- ImplementedAs=WebGPUSwapChainDescriptor
-] dictionary WebGPUSwapChainDescriptor {
- required GPUCanvasContext context;
- required GPUTextureFormat format;
- GPUTextureUsageFlags usage = 16; // FIXME: How to set this to GPUTextureUsage.OUTPUT_ATTACHMENT in IDL?
-};
-
-[
- Conditional=WEBGPU,
- EnabledAtRuntime=WebGPU,
ImplementationLacksVTable
] interface WebGPUDevice {
readonly attribute WebGPUAdapter adapter;
@@ -58,8 +46,6 @@
// FIXME: Currently, GPUCommandEncoderDescriptor is an empty dictionary.
WebGPUCommandEncoder createCommandEncoder(/*GPUCommandEncoderDescriptor descriptor*/);
- WebGPUSwapChain createSwapChain(WebGPUSwapChainDescriptor descriptor);
-
WebGPUQueue getQueue();
// FIXME: Unimplemented.
Copied: trunk/Source/WebCore/Modules/webgpu/WebGPUSwapChainDescriptor.cpp (from rev 244506, trunk/Source/WebCore/Modules/webgpu/WebGPUSwapChainDescriptor.h) (0 => 244507)
--- trunk/Source/WebCore/Modules/webgpu/WebGPUSwapChainDescriptor.cpp (rev 0)
+++ trunk/Source/WebCore/Modules/webgpu/WebGPUSwapChainDescriptor.cpp 2019-04-22 18:41:16 UTC (rev 244507)
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2019 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 "WebGPUSwapChainDescriptor.h"
+
+#if ENABLE(WEBGPU)
+
+#include "Logging.h"
+
+namespace WebCore {
+
+Optional<GPUSwapChainDescriptor> WebGPUSwapChainDescriptor::asGPUSwapChainDescriptor() const
+{
+ if (!device) {
+ LOG(WebGPU, "GPUCanvasContext::configureSwapChain(): Invalid GPUDevice!");
+ return WTF::nullopt;
+ }
+
+ return GPUSwapChainDescriptor { makeRef(device->device()), *this };
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(WEBGPU)
Modified: trunk/Source/WebCore/Modules/webgpu/WebGPUSwapChainDescriptor.h (244506 => 244507)
--- trunk/Source/WebCore/Modules/webgpu/WebGPUSwapChainDescriptor.h 2019-04-22 18:35:04 UTC (rev 244506)
+++ trunk/Source/WebCore/Modules/webgpu/WebGPUSwapChainDescriptor.h 2019-04-22 18:41:16 UTC (rev 244507)
@@ -27,14 +27,17 @@
#if ENABLE(WEBGPU)
-#include "GPUCanvasContext.h"
#include "GPUSwapChainDescriptor.h"
+#include "WebGPUDevice.h"
+#include <wtf/Optional.h>
#include <wtf/RefPtr.h>
namespace WebCore {
-struct WebGPUSwapChainDescriptor : GPUSwapChainDescriptor {
- RefPtr<GPUCanvasContext> context;
+struct WebGPUSwapChainDescriptor : GPUSwapChainDescriptorBase {
+ Optional<GPUSwapChainDescriptor> asGPUSwapChainDescriptor() const;
+
+ RefPtr<WebGPUDevice> device;
};
} // namespace WebCore
Modified: trunk/Source/WebCore/Sources.txt (244506 => 244507)
--- trunk/Source/WebCore/Sources.txt 2019-04-22 18:35:04 UTC (rev 244506)
+++ trunk/Source/WebCore/Sources.txt 2019-04-22 18:41:16 UTC (rev 244507)
@@ -372,6 +372,7 @@
Modules/webgpu/WebGPUSampler.cpp
Modules/webgpu/WebGPUShaderModule.cpp
Modules/webgpu/WebGPUSwapChain.cpp
+Modules/webgpu/WebGPUSwapChainDescriptor.cpp
Modules/webgpu/WebGPUTexture.cpp
Modules/webgpu/WebGPUTextureView.cpp
Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (244506 => 244507)
--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2019-04-22 18:35:04 UTC (rev 244506)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2019-04-22 18:41:16 UTC (rev 244507)
@@ -13826,6 +13826,7 @@
D003288721C9A4E500622AA6 /* GPUPipelineLayout.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = GPUPipelineLayout.cpp; sourceTree = "<group>"; };
D003914122248D400098998C /* GPUProgrammablePassEncoder.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = GPUProgrammablePassEncoder.cpp; sourceTree = "<group>"; };
D00487D222457BEA00EED7D9 /* WebGPUPipelineLayoutDescriptor.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = WebGPUPipelineLayoutDescriptor.cpp; sourceTree = "<group>"; };
+ D00487E5226A634200EED7D9 /* WebGPUSwapChainDescriptor.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = WebGPUSwapChainDescriptor.cpp; sourceTree = "<group>"; };
D00D77FD2242ED450043F12C /* WebGPUComputePassEncoder.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WebGPUComputePassEncoder.h; sourceTree = "<group>"; };
D00D77FE2242ED450043F12C /* WebGPUComputePassEncoder.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = WebGPUComputePassEncoder.cpp; sourceTree = "<group>"; };
D00D77FF2242ED450043F12C /* WebGPUComputePassEncoder.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = WebGPUComputePassEncoder.idl; sourceTree = "<group>"; };
@@ -18239,6 +18240,7 @@
312FF8C021A4C2F200EB199D /* GPUShaderModuleDescriptor.h */,
D08AA032220D0D0B0058C502 /* GPUStoreOp.h */,
312FF8BA21A4C2EF00EB199D /* GPUSwapChain.h */,
+ D0ADB27F2232F17300A22935 /* GPUSwapChainDescriptor.h */,
312FF8C521A4C2F400EB199D /* GPUTexture.h */,
D026F48C220A5BAD00AC5F49 /* GPUTextureDescriptor.h */,
312FF8C321A4C2F300EB199D /* GPUTextureFormat.h */,
@@ -25791,7 +25793,6 @@
D0DE8FB8222E09E200882550 /* GPUShaderStageBit.h */,
D0DE8FB9222E09E200882550 /* GPUShaderStageBit.idl */,
D08AA031220D0CE60058C502 /* GPUStoreOp.idl */,
- D0ADB27F2232F17300A22935 /* GPUSwapChainDescriptor.h */,
D026F48B220A5B0B00AC5F49 /* GPUTextureDescriptor.idl */,
D0EACFAE219E30FD000FA75C /* GPUTextureFormat.idl */,
D026F483220A472F00AC5F49 /* GPUTextureUsage.idl */,
@@ -25878,6 +25879,7 @@
D0DA0BE5217930E2007FE2AC /* WebGPUSwapChain.cpp */,
D0DA0BE4217930E2007FE2AC /* WebGPUSwapChain.h */,
D0DA0BE6217930E2007FE2AC /* WebGPUSwapChain.idl */,
+ D00487E5226A634200EED7D9 /* WebGPUSwapChainDescriptor.cpp */,
D0ADB27E2232F0C000A22935 /* WebGPUSwapChainDescriptor.h */,
D0EACF852193B02E000FA75C /* WebGPUTexture.cpp */,
D0EACF842193B02E000FA75C /* WebGPUTexture.h */,
Modified: trunk/Source/WebCore/platform/graphics/gpu/GPUDevice.cpp (244506 => 244507)
--- trunk/Source/WebCore/platform/graphics/gpu/GPUDevice.cpp 2019-04-22 18:35:04 UTC (rev 244506)
+++ trunk/Source/WebCore/platform/graphics/gpu/GPUDevice.cpp 2019-04-22 18:41:16 UTC (rev 244507)
@@ -43,7 +43,6 @@
#include "GPUSamplerDescriptor.h"
#include "GPUShaderModule.h"
#include "GPUShaderModuleDescriptor.h"
-#include "GPUSwapChain.h"
#include "GPUSwapChainDescriptor.h"
#include "GPUTexture.h"
#include "GPUTextureDescriptor.h"
@@ -96,12 +95,6 @@
return GPUCommandBuffer::tryCreate(*this);
}
-RefPtr<GPUSwapChain> GPUDevice::tryCreateSwapChain(const GPUSwapChainDescriptor& descriptor, int width, int height) const
-{
- m_swapChain = GPUSwapChain::tryCreate(*this, descriptor, width, height);
- return m_swapChain;
-}
-
RefPtr<GPUQueue> GPUDevice::tryGetQueue() const
{
if (!m_queue)
@@ -109,6 +102,11 @@
return m_queue;
}
+
+void GPUDevice::setSwapChain(RefPtr<GPUSwapChain>&& swapChain)
+{
+ m_swapChain = WTFMove(swapChain);
+}
} // namespace WebCore
Modified: trunk/Source/WebCore/platform/graphics/gpu/GPUDevice.h (244506 => 244507)
--- trunk/Source/WebCore/platform/graphics/gpu/GPUDevice.h 2019-04-22 18:35:04 UTC (rev 244506)
+++ trunk/Source/WebCore/platform/graphics/gpu/GPUDevice.h 2019-04-22 18:41:16 UTC (rev 244507)
@@ -28,6 +28,7 @@
#if ENABLE(WEBGPU)
#include "GPUQueue.h"
+#include "GPUSwapChain.h"
#include <wtf/RefCounted.h>
#include <wtf/RetainPtr.h>
#include <wtf/WeakPtr.h>
@@ -44,7 +45,6 @@
class GPURenderPipeline;
class GPUSampler;
class GPUShaderModule;
-class GPUSwapChain;
class GPUTexture;
struct GPUBindGroupLayoutDescriptor;
@@ -78,11 +78,11 @@
RefPtr<GPUCommandBuffer> tryCreateCommandBuffer() const;
- RefPtr<GPUSwapChain> tryCreateSwapChain(const GPUSwapChainDescriptor&, int width, int height) const;
-
RefPtr<GPUQueue> tryGetQueue() const;
+
PlatformDevice* platformDevice() const { return m_platformDevice.get(); }
GPUSwapChain* swapChain() const { return m_swapChain.get(); }
+ void setSwapChain(RefPtr<GPUSwapChain>&&);
private:
explicit GPUDevice(PlatformDeviceSmartPtr&&);
@@ -89,7 +89,7 @@
PlatformDeviceSmartPtr m_platformDevice;
mutable RefPtr<GPUQueue> m_queue;
- mutable RefPtr<GPUSwapChain> m_swapChain;
+ RefPtr<GPUSwapChain> m_swapChain;
};
} // namespace WebCore
Modified: trunk/Source/WebCore/platform/graphics/gpu/GPUSwapChain.h (244506 => 244507)
--- trunk/Source/WebCore/platform/graphics/gpu/GPUSwapChain.h 2019-04-22 18:35:04 UTC (rev 244506)
+++ trunk/Source/WebCore/platform/graphics/gpu/GPUSwapChain.h 2019-04-22 18:41:16 UTC (rev 244507)
@@ -50,7 +50,7 @@
class GPUSwapChain : public RefCounted<GPUSwapChain> {
public:
- static RefPtr<GPUSwapChain> tryCreate(const GPUDevice&, const GPUSwapChainDescriptor&, int width, int height);
+ static RefPtr<GPUSwapChain> tryCreate(const GPUSwapChainDescriptor&, int width, int height);
RefPtr<GPUTexture> tryGetCurrentTexture();
Modified: trunk/Source/WebCore/platform/graphics/gpu/GPUSwapChainDescriptor.h (244506 => 244507)
--- trunk/Source/WebCore/platform/graphics/gpu/GPUSwapChainDescriptor.h 2019-04-22 18:35:04 UTC (rev 244506)
+++ trunk/Source/WebCore/platform/graphics/gpu/GPUSwapChainDescriptor.h 2019-04-22 18:41:16 UTC (rev 244507)
@@ -27,16 +27,27 @@
#if ENABLE(WEBGPU)
+#include "GPUDevice.h"
#include "GPUTextureFormat.h"
#include "GPUTextureUsage.h"
namespace WebCore {
-struct GPUSwapChainDescriptor {
+struct GPUSwapChainDescriptorBase {
GPUTextureFormat format;
GPUTextureUsageFlags usage { static_cast<GPUTextureUsageFlags>(GPUTextureUsage::Flags::OutputAttachment) };
};
+struct GPUSwapChainDescriptor : GPUSwapChainDescriptorBase {
+ GPUSwapChainDescriptor(Ref<GPUDevice>&& gpuDevice, const GPUSwapChainDescriptorBase& base)
+ : GPUSwapChainDescriptorBase(base)
+ , device(WTFMove(gpuDevice))
+ {
+ }
+
+ Ref<GPUDevice> device;
+};
+
} // namespace WebCore
#endif // ENABLE(WEBGPU)
Modified: trunk/Source/WebCore/platform/graphics/gpu/cocoa/GPUSwapChainMetal.mm (244506 => 244507)
--- trunk/Source/WebCore/platform/graphics/gpu/cocoa/GPUSwapChainMetal.mm 2019-04-22 18:35:04 UTC (rev 244506)
+++ trunk/Source/WebCore/platform/graphics/gpu/cocoa/GPUSwapChainMetal.mm 2019-04-22 18:41:16 UTC (rev 244507)
@@ -85,10 +85,10 @@
return layer;
}
-RefPtr<GPUSwapChain> GPUSwapChain::tryCreate(const GPUDevice& device, const GPUSwapChainDescriptor& descriptor, int width, int height)
+RefPtr<GPUSwapChain> GPUSwapChain::tryCreate(const GPUSwapChainDescriptor& descriptor, int width, int height)
{
- if (!device.platformDevice()) {
- LOG(WebGPU, "GPUSwapChain::setDevice(): Invalid GPUDevice!");
+ if (!descriptor.device->platformDevice()) {
+ LOG(WebGPU, "GPUSwapChain::tryCreate(): Invalid GPUDevice!");
return nullptr;
}
@@ -102,13 +102,15 @@
return nullptr;
}
- auto layer = tryCreateWebGPULayer(device.platformDevice(), *pixelFormat, usageOptions);
+ auto layer = tryCreateWebGPULayer(descriptor.device->platformDevice(), *pixelFormat, usageOptions);
if (!layer)
return nullptr;
setLayerShape(layer.get(), width, height);
- return adoptRef(new GPUSwapChain(WTFMove(layer), usageOptions));
+ auto swapChain = adoptRef(new GPUSwapChain(WTFMove(layer), usageOptions));
+ descriptor.device->setSwapChain(swapChain.copyRef());
+ return swapChain;
}
GPUSwapChain::GPUSwapChain(RetainPtr<WebGPULayer>&& platformLayer, OptionSet<GPUTextureUsage::Flags> usageOptions)