8000 [WebGPU] Virtualize PresentationContext · WebKit/WebKit@6c91a81 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6c91a81

Browse files
committed
[WebGPU] Virtualize PresentationContext
https://bugs.webkit.org/show_bug.cgi?id=250632 rdar://104270153 Reviewed by Tadeu Zagallo. PresentationContext is how we composite results into a window. Its implementation in https://bugs.webkit.org/show_bug.cgi?id=247587 is set up only for WebKit's compositing using IOSurfaces. However, it's convenient if we could have another implementation of them that could use CAMetalLayer directly, so that we could develop WebGPU without having to build all of WebCore. This patch turns PresentationContext into a base class with virtual methods, and provides two implementations of them: One for IOSurfaces, that WebKit will use, and one for CAMetalLayer. The IOSurface implementation isn't modified at all; it's simply moved from the existing implementation. This patch doesn't actually implement the CAMetalLayer implementation; this patch is already quite large without it, and I want to keep my patches small to aid reviewing. I will implement getCurrentTextureView() and present() in my next patch. No test because there is no behavior change. * Source/WebGPU/WebGPU.xcodeproj/project.pbxproj: * Source/WebGPU/WebGPU/Device.h: * Source/WebGPU/WebGPU/PresentationContext.h: (WebGPU::PresentationContext::createInvalid): (WebGPU::PresentationContext::isPresentationContextIOSurface const): (WebGPU::PresentationContext::isPresentationContextCoreAnimation const): (WebGPU::PresentationContext::create): Deleted. (WebGPU::PresentationContext::displayBuffer const): Deleted. (WebGPU::PresentationContext::drawingBuffer const): Deleted. * Source/WebGPU/WebGPU/PresentationContext.mm: (WebGPU::PresentationContext::create): (WebGPU::PresentationContext::getPreferredFormat): (WebGPU::PresentationContext::present): (WebGPU::optionsFor32BitSurface): Deleted. (WebGPU::createIOSurface): Deleted. (WebGPU::createSurfaceFromDescriptor): Deleted. (WebGPU::Device::createSurface): Deleted. (WebGPU::PresentationContext::PresentationContext): Deleted. (WebGPU::PresentationContext::nextDrawable): Deleted. (wgpuSurfaceCocoaCustomSurfaceGetDisplayBuffer): Deleted. (wgpuSurfaceCocoaCustomSurfaceGetDrawingBuffer): Deleted. * Source/WebGPU/WebGPU/PresentationContextCoreAnimation.h: Copied from Source/WebGPU/WebGPU/PresentationContext.h. (WebGPU::PresentationContextCoreAnimation::create): * Source/WebGPU/WebGPU/PresentationContextCoreAnimation.mm: Copied from Source/WebGPU/WebGPU/PresentationContext.h. (WebGPU::PresentationContextCoreAnimation::PresentationContextCoreAnimation): (WebGPU::PresentationContextCoreAnimation::configure): (WebGPU::PresentationContextCoreAnimation::present): (WebGPU::PresentationContextCoreAnimation::getCurrentTextureView): * Source/WebGPU/WebGPU/PresentationContextIOSurface.h: Copied from Source/WebGPU/WebGPU/PresentationContext.h. (WebGPU::PresentationContextIOSurface::create): (WebGPU::PresentationContextIOSurface::displayBuffer const): (WebGPU::PresentationContextIOSurface::drawingBuffer const): * Source/WebGPU/WebGPU/PresentationContextIOSurface.mm: Copied from Source/WebGPU/WebGPU/PresentationContext.mm. (WebGPU::optionsFor32BitSurface): (WebGPU::createIOSurface): (WebGPU::createSurfaceFromDescriptor): (WebGPU::PresentationContextIOSurface::PresentationContextIOSurface): (WebGPU::PresentationContextIOSurface::configure): (WebGPU::PresentationContextIOSurface::present): (WebGPU::PresentationContextIOSurface::getCurrentTextureView): (WebGPU::PresentationContextIOSurface::nextDrawable): (wgpuSurfaceCocoaCustomSurfaceGetDisplayBuffer): (wgpuSurfaceCocoaCustomSurfaceGetDrawingBuffer): Canonical link: https://commits.webkit.org/259022@main
1 parent 32d01bb commit 6c91a81

8 files changed

+362
-118
lines changed

Source/WebGPU/WebGPU.xcodeproj/project.pbxproj

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,9 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10-
0D4D2E81294A89CF0000A1AB /* BindableResource.h in Headers */ = {isa = PBXBuildFile; fileRef = 0D4D2E80294A89CF0000A1AB /* BindableResource.h */; };
1110
1C0F41EE280940650005886D /* HardwareCapabilities.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1C0F41EC280940650005886D /* HardwareCapabilities.mm */; };
12-
1C0F41EF280940650005886D /* HardwareCapabilities.h in Headers */ = {isa = PBXBuildFile; fileRef = 1C0F41ED280940650005886D /* HardwareCapabilities.h */; };
1311
1C2CEDEE271E8A7300EDC16F /* Metal.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1C2CEDED271E8A7300EDC16F /* Metal.framework */; };
14-
1C33755F27FA23B8002F1644 /* IsValidToUseWith.h in Headers */ = {isa = PBXBuildFile; fileRef = 1C33755D27FA23B8002F1644 /* IsValidToUseWith.h */; };
1512
1C582FF927E04131009B40F0 /* CommandsMixin.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1C582FF727E04131009B40F0 /* CommandsMixin.mm */; };
16-
1C582FFA27E04131009B40F0 /* CommandsMixin.h in Headers */ = {isa = PBXBuildFile; fileRef = 1C582FF827E04131009B40F0 /* CommandsMixin.h */; };
17-
1C58301827E16823009B40F0 /* APIConversions.h in Headers */ = {isa = PBXBuildFile; fileRef = 1C58301727E16823009B40F0 /* APIConversions.h */; };
1813
1C5ACA94273A41C20095F8D5 /* Instance.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1C5ACA92273A41C20095F8D5 /* Instance.mm */; };
1914
1C5ACAB6273A426D0095F8D5 /* RenderPipeline.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1C5ACA98273A426D0095F8D5 /* RenderPipeline.mm */; };
2015
1C5ACABB273A426D0095F8D5 /* Buffer.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1C5ACA9D273A426D0095F8D5 /* Buffer.mm */; };
@@ -30,7 +25,6 @@
3025
1C5ACACE273A426E0095F8D5 /* ShaderModule.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1C5ACAB0273A426D0095F8D5 /* ShaderModule.mm */; };
3126
1C5ACACF273A426E0095F8D5 /* Texture.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1C5ACAB1273A426D0095F8D5 /* Texture.mm */; };
3227
1C5ACAD3273A4C860095F8D5 /* WebGPUExt.h in Headers */ = {isa = PBXBuildFile; fileRef = 1C5ACAD2273A4C860095F8D5 /* WebGPUExt.h */; settings = {ATTRIBUTES = (Public, ); }; };
33-
1C5ACAD7273A4D700095F8D5 /* BindGroup.h in Headers */ = {isa = PBXBuildFile; fileRef = 1C5ACAD5273A4D700095F8D5 /* BindGroup.h */; };
3428
1C5ACADF273A55AF0095F8D5 /* BindGroup.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1C5ACADE273A55AF0095F8D5 /* BindGroup.mm */; };
3529
1C5ACAE1273A55C10095F8D5 /* BindGroupLayout.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1C5ACAE0273A55C10095F8D5 /* BindGroupLayout.mm */; };
3630
1C5ACAE3273A55CD0095F8D5 /* CommandBuffer.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1C5ACAE2273A55CD0095F8D5 /* CommandBuffer.mm */; };
@@ -39,8 +33,9 @@
3933
1C5ACAE9273A55FD0095F8D5 /* Sampler.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1C5ACAE8273A55FD0095F8D5 /* Sampler.mm */; };
4034
1C5ACAEB273A560D0095F8D5 /* TextureView.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1C5ACAEA273A560D0095F8D5 /* TextureView.mm */; };
4135
1C9F7CDF29762F51006B5BE9 /* PresentationContext.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1C9F7CDD29762F51006B5BE9 /* PresentationContext.mm */; };
42-
1C9F7CE029762F51006B5BE9 /* PresentationContext.h in Headers */ = {isa = PBXBuildFile; fileRef = 1C9F7CDE29762F51006B5BE9 /* PresentationContext.h */; };
4336
1CBAB0922718CCA0006080BB /* JavaScriptCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1CBAB0912718CCA0006080BB /* JavaScriptCore.framework */; };
37+
1CBD2E972977DAC900BBF52C /* PresentationContextCoreAnimation.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1CBD2E932977DAC900BBF52C /* PresentationContextCoreAnimation.mm */; };
38+
1CBD2E992977DAC900BBF52C /* PresentationContextIOSurface.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1CBD2E952977DAC900BBF52C /* PresentationContextIOSurface.mm */; };
4439
1CEBD7E72716AFBA00A5254D /* WebGPU.h in Headers */ = {isa = PBXBuildFile; fileRef = 1CEBD7E62716AFBA00A5254D /* WebGPU.h */; settings = {ATTRIBUTES = (Public, ); }; };
4540
1CEBD7F82716B34400A5254D /* WGSL.h in Headers */ = {isa = PBXBuildFile; fileRef = 1CEBD7F72716B34400A5254D /* WGSL.h */; settings = {ATTRIBUTES = (Public, ); }; };
4641
1CEBD8032716BF8200A5254D /* WGSL.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1CEBD8022716BF8200A5254D /* WGSL.cpp */; };
@@ -262,6 +257,10 @@
262257
1CAB8D3C2866DA0E00347F21 /* NSSet.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = NSSet.hpp; sourceTree = "<group>"; };
263258
1CAB8D3D2866DA2D00347F21 /* CAMetalLayer.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = CAMetalLayer.hpp; sourceTree = "<group>"; };
264259
1CBAB0912718CCA0006080BB /* JavaScriptCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = JavaScriptCore.framework; sourceTree = BUILT_PRODUCTS_DIR; };
260+
1CBD2E922977DAC900BBF52C /* PresentationContextCoreAnimation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PresentationContextCoreAnimation.h; sourceTree = "<group>"; };
261+
1CBD2E932977DAC900BBF52C /* PresentationContextCoreAnimation.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = PresentationContextCoreAnimation.mm; sourceTree = "<group>"; };
262+
1CBD2E942977DAC900BBF52C /* PresentationContextIOSurface.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PresentationContextIOSurface.h; sourceTree = "<group>"; };
263+
1CBD2E952977DAC900BBF52C /* PresentationContextIOSurface.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = PresentationContextIOSurface.mm; sourceTree = "<group>"; };
265264
1CC0C8C9273A7D8900D0B481 /* WebGPU.modulemap */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.module-map"; path = WebGPU.modulemap; sourceTree = "<group>"; };
266265
1CEBD7E32716AFBA00A5254D /* WebGPU.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = WebGPU.framework; sourceTree = BUILT_PRODUCTS_DIR; };
267266
1CEBD7E62716AFBA00A5254D /* WebGPU.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WebGPU.h; sourceTree = "<group>"; };
@@ -562,6 +561,10 @@
562561
1C5ACAE4273A55DD0095F8D5 /* PipelineLayout.mm */,
563562
1C9F7CDE29762F51006B5BE9 /* PresentationContext.h */,
564563
1C9F7CDD29762F51006B5BE9 /* PresentationContext.mm */,
564+
1CBD2E922977DAC900BBF52C /* PresentationContextCoreAnimation.h */,
565+
1CBD2E932977DAC900BBF52C /* PresentationContextCoreAnimation.mm */,
566+
1CBD2E942977DAC900BBF52C /* PresentationContextIOSurface.h */,
567+
1CBD2E952977DAC900BBF52C /* PresentationContextIOSurface.mm */,
565568
1C5ACAAC273A426D0095F8D5 /* QuerySet.h */,
566569
1C5ACA9F273A426D0095F8D5 /* QuerySet.mm */,
567570
1C5ACA9C273A426D0095F8D5 /* Queue.h */,
@@ -683,13 +686,6 @@
683686
isa = PBXHeadersBuildPhase;
684687
buildActionMask = 2147483647;
685688
files = (
686-
1C58301827E16823009B40F0 /* APIConversions.h in Headers */,
687-
0D4D2E81294A89CF0000A1AB /* BindableResource.h in Headers */,
688-
1C5ACAD7273A4D700095F8D5 /* BindGroup.h in Headers */,
689-
1C582FFA27E04131009B40F0 /* CommandsMixin.h in Headers */,
690 C608 -
1C0F41EF280940650005886D /* HardwareCapabilities.h in Headers */,
691-
1C33755F27FA23B8002F1644 /* IsValidToUseWith.h in Headers */,
692-
1C9F7CE029762F51006B5BE9 /* PresentationContext.h in Headers */,
693689
1CEBD7E72716AFBA00A5254D /* WebGPU.h in Headers */,
694690
1C5ACAD3273A4C860095F8D5 /* WebGPUExt.h in Headers */,
695691
);
@@ -907,6 +903,8 @@
907903
1C5ACA94273A41C20095F8D5 /* Instance.mm in Sources */,
908904
1C5ACAE5273A55DD0095F8D5 /* PipelineLayout.mm in Sources */,
909905
1C9F7CDF29762F51006B5BE9 /* PresentationContext.mm in Sources */,
906+
1CBD2E972977DAC900BBF52C /* PresentationContextCoreAnimation.mm in Sources */,
907+
1CBD2E992977DAC900BBF52C /* PresentationContextIOSurface.mm in Sources */,
910908
1C5ACABD273A426D0095F8D5 /* QuerySet.mm in Sources */,
911909
1C5ACACB273A426E0095F8D5 /* Queue.mm in Sources */,
912910
1C5ACAE7273A55EF0095F8D5 /* RenderBundle.mm in Sources */,

Source/WebGPU/WebGPU/Device.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ class Device : public WGPUDeviceImpl, public ThreadSafeRefCountedAndCanMakeThrea
8383
void createRenderPipelineAsync(const WGPURenderPipelineDescriptor&, CompletionHandler<void(WGPUCreatePipelineAsyncStatus, Ref<RenderPipeline>&&, String&& message)>&& callback);
8484
Ref<Sampler> createSampler(const WGPUSamplerDescriptor&);
8585
Ref<ShaderModule> createShaderModule(const WGPUShaderModuleDescriptor&);
86-
Ref<PresentationContext> createSurface(const WGPUSurfaceDescriptor&);
8786
Ref<PresentationContext> createSwapChain(PresentationContext&, const WGPUSwapChainDescriptor&);
8887
Ref<Texture> createTexture(const WGPUTextureDescriptor&);
8988
void destroy();

Source/WebGPU/WebGPU/PresentationContext.h

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#import <wtf/Ref.h>
3030
#import <wtf/RefCounted.h>
3131
#import <wtf/RetainPtr.h>
32+
#import <wtf/TypeCasts.h>
3233

3334
struct WGPUSurfaceImpl {
3435
};
@@ -45,30 +46,31 @@ class TextureView;
4546
class PresentationContext : public WGPUSurfaceImpl, public WGPUSwapChainImpl, public RefCounted<PresentationContext> {
4647
WTF_MAKE_FAST_ALLOCATED;
4748
public:
48-
static Ref<PresentationContext> create(const WGPUSurfaceDescriptor& descriptor)
49+
static Ref<PresentationContext> create(const WGPUSurfaceDescriptor&);
50+
static Ref<PresentationContext> createInvalid()
4951
{
50-
return adoptRef(*new PresentationContext(descriptor));
52+
return adoptRef(*new PresentationContext());
5153
}
5254

53-
~PresentationContext();
55+
virtual ~PresentationContext();
5456

5557
WGPUTextureFormat getPreferredFormat(const Adapter&);
5658

57-
void configure(Device&, const WGPUSwapChainDescriptor&);
59+
virtual void configure(Device&, const WGPUSwapChainDescriptor&);
5860

59-
void present();
60-
TextureView* getCurrentTextureView(); // FIXME: This should return a TextureView&.
61+
virtual void present();
62+
virtual TextureView* getCurrentTextureView(); // FIXME: This should return a TextureView&.
6163

62-
RetainPtr<IOSurfaceRef> displayBuffer() const { return m_displayBuffer; }
63-
RetainPtr<IOSurfaceRef> drawingBuffer() const { return m_drawingBuffer; }
64-
RetainPtr<IOSurfaceRef> nextDrawable();
64+
virtual bool isPresentationContextIOSurface() const { return false; }
65+
virtual bool isPresentationContextCoreAnimation() const { return false; }
6566

66-
private:
67-
PresentationContext(const WGPUSurfaceDescriptor&);
68-
PresentationContext(int, int);
69-
70-
RetainPtr<IOSurfaceRef> m_displayBuffer;
71-
RetainPtr<IOSurfaceRef> m_drawingBuffer;
67+
protected:
68+
PresentationContext();
7269
};
7370

7471
} // namespace WebGPU
72+
73+
#define SPECIALIZE_TYPE_TRAITS_WEBGPU_PRESENTATION_CONTEXT(ToValueTypeName, predicate) \
74+
SPECIALIZE_TYPE_TRAITS_BEGIN(WebGPU::ToValueTypeName) \
75+
static bool isType(const WebGPU::PresentationContext& presentationContext) { return presentationContext.predicate; } \
76+
SPECIALIZE_TYPE_TRAITS_END()

Source/WebGPU/WebGPU/PresentationContext.mm

Lines changed: 17 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -28,88 +28,38 @@
2828

2929
#import " C608 APIConversions.h"
3030
#import "Adapter.h"
31-
32-
#import <WebGPU/WebGPUExt.h>
33-
34-
// borrowed from pal/spi/cocoa/IOTypesSPI.h
35-
#if PLATFORM(MAC) || USE(APPLE_INTERNAL_SDK)
36-
#include <IOKit/IOTypes.h>
37-
#else
38-
39-
enum {
40-
kIOWriteCombineCache = 4,
41-
};
42-
43-
enum {
44-
kIOMapCacheShift = 8,
45-
kIOMapWriteCombineCache = kIOWriteCombineCache << kIOMapCacheShift,
46-
};
47-
#endif
31+
#import "PresentationContextCoreAnimation.h"
32+
#import "PresentationContextIOSurface.h"
4833

4934
namespace WebGPU {
5035

51-
static NSDictionary *optionsFor32BitSurface(int width, int height, unsigned pixelFormat)
52-
{
53-
unsigned bytesPerElement = 4;
54-
unsigned bytesPerPixel = 4;
55-
56-
size_t bytesPerRow = IOSurfaceAlignProperty(kIOSurfaceBytesPerRow, width * bytesPerPixel);
57-
ASSERT(bytesPerRow);
58-
59-
size_t totalBytes = IOSurfaceAlignProperty(kIOSurfaceAllocSize, height * bytesPerRow);
60-
ASSERT(totalBytes);
61-
62-
return @{
63-
(id)kIOSurfaceWidth: @(width),
64-
(id)kIOSurfaceHeight: @(height),
65-
(id)kIOSurfacePixelFormat: @(pixelFormat),
66-
(id)kIOSurfaceBytesPerElement: @(bytesPerElement),
67-
(id)kIOSurfaceBytesPerRow: @(bytesPerRow),
68-
(id)kIOSurfaceAllocSize: @(totalBytes),
69-
#if PLATFORM(IOS_FAMILY)
70-
(id)kIOSurfaceCacheMode: @(kIOMapWriteCombineCache),
71-
#endif
72-
(id)kIOSurfaceElementHeight: @(1)
73-
};
74-
}
75-
76-
static RetainPtr<IOSurfaceRef> createIOSurface(int width, int height)
77-
{
78-
NSDictionary *options = optionsFor32BitSurface(width, height, 'BGRA');
79-
return adoptCF(IOSurfaceCreate((CFDictionaryRef)options));
80-
}
81-
82-
static RetainPtr<IOSurfaceRef> createSurfaceFromDescriptor(const WGPUSurfaceDescriptor& descriptor)
83-
{
84-
if (!descriptor.nextInChain || descriptor.nextInChain->sType != static_cast<WGPUSType>(WGPUSTypeExtended_SurfaceDescriptorCocoaSurfaceBacking))
85-
return nullptr;
86-
87-
auto widthHeight = ((const WGPUSurfaceDescriptorCocoaCustomSurface*)descriptor.nextInChain);
88-
return createIOSurface(widthHeight->width, widthHeight->height);
89-
}
90-
91-
Ref<PresentationContext> Device::createSurface(const WGPUSurfaceDescriptor& descriptor)
92-
{
93-
return PresentationContext::create(descriptor);
94-
}
95-
9636
Ref<PresentationContext> Device::createSwapChain(PresentationContext& presentationContext, const WGPUSwapChainDescriptor& descriptor)
9737
{
9838
presentationContext.configure(*this, descriptor);
9939
return presentationContext;
10040
}
10141

102-
PresentationContext::PresentationContext(const WGPUSurfaceDescriptor& descriptor)
103-
: m_displayBuffer(createSurfaceFromDescriptor(descriptor))
104-
, m_drawingBuffer(createSurfaceFromDescriptor(descriptor))
42+
Ref<PresentationContext> PresentationContext::create(const WGPUSurfaceDescriptor& descriptor)
10543
{
44+
if (!descriptor.nextInChain || descriptor.nextInChain->next)
45+
return PresentationContext::createInvalid();
46+
47+
switch (static_cast<unsigned>(descriptor.nextInChain->sType)) {
48+
case WGPUSTypeExtended_SurfaceDescriptorCocoaSurfaceBacking:
49+
return PresentationContextIOSurface::create(descriptor);
50+
case WGPUSType_SurfaceDescriptorFromMetalLayer:
51+
return PresentationContextCoreAnimation::create(descriptor);
52+
default:
53+
return PresentationContext::createInvalid();
54+
}
10655
}
10756

57+
PresentationContext::PresentationContext() = default;
58+
10859
PresentationContext::~PresentationContext() = default;
10960

110-
WGPUTextureFormat PresentationContext::getPreferredFormat(const Adapter& adapter)
61+
WGPUTextureFormat PresentationContext::getPreferredFormat(const Adapter&)
11162
{
112-
UNUSED_PARAM(adapter);
11363
return WGPUTextureFormat_BGRA8Unorm;
11464
}
11565

@@ -119,24 +69,13 @@
11969

12070
void PresentationContext::present()
12171
{
122-
nextDrawable();
12372
}
12473

12574
TextureView* PresentationContext::getCurrentTextureView()
12675
{
12776
return nullptr;
12877
}
12978

130-
RetainPtr<IOSurfaceRef> PresentationContext::nextDrawable()
131-
{
132-
// FIXME: wait until a buffer is available
133-
auto nextBuffer = m_drawingBuffer;
134-
m_drawingBuffer = m_displayBuffer;
135-
m_displayBuffer = nextBuffer;
136-
137-
return m_drawingBuffer;
138-
}
139-
14079
} // namespace WebGPU
14180

14281
#pragma mark WGPU Stubs
@@ -156,16 +95,6 @@ WGPUTextureFormat wgpuSurfaceGetPreferredFormat(WGPUSurface surface, WGPUAdapter
15695
return WebGPU::fromAPI(surface).getPreferredFormat(WebGPU::fromAPI(adapter));
15796
}
15897

159-
IOSurfaceRef wgpuSurfaceCocoaCustomSurfaceGetDisplayBuffer(WGPUSurface surface)
160-
{
161-
return WebGPU::fromAPI(surface).displayBuffer().get();
162-
}
163-
164-
IOSurfaceRef wgpuSurfaceCocoaCustomSurfaceGetDrawingBuffer(WGPUSurface surface)
165-
{
166-
return WebGPU::fromAPI(surface).drawingBuffer().get();
167-
}
168-
16998
WGPUTextureView wgpuSwapChainGetCurrentTextureView(WGPUSwapChain swapChain)
17099
{
171100
return WebGPU::fromAPI(swapChain).getCurrentTextureView();
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Copyright (c) 2021-2022 Apple Inc. All rights reserved.
3+
*
4+
* Redistribution and use in source and binary forms, with or without
5+
* modification, are permitted provided that the following conditions
6+
* are met:
7+
* 1. Redistributions of source code must retain the above copyright
8+
* notice, this list of conditions and the following disclaimer.
9+
* 2. Redistributions in binary form must reproduce the above copyright
10+
* notice, this list of conditions and the following disclaimer in the
11+
* documentation and/or other materials provided with the distribution.
12+
*
13+
* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14+
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16+
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17+
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18+
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19+
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20+
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21+
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24+
*/
25+
26+
#pragma once
27+
28+
#import "PresentationContext.h"
29+
30+
namespace WebGPU {
31+
32+
class Device;
33+
class TextureView;
34+
35+
class PresentationContextCoreAnimation : public PresentationContext {
36+
WTF_MAKE_FAST_ALLOCATED;
37+
public:
38+
static Ref<PresentationContextCoreAnimation> create(const WGPUSurfaceDescriptor& descriptor)
39+
{
40+
return adoptRef(*new PresentationContextCoreAnimation(descriptor));
41+
}
42+
43+
virtual ~PresentationContextCoreAnimation();
44+
45+
void configure(Device&, const WGPUSwapChainDescriptor&) override;
46+
47+
void present() override;
48+
TextureView* getCurrentTextureView() override; // FIXME: This should return a TextureView&.
49+
50+
bool isPresentationContextCoreAnimation() const override { return true; }
51+
52+
private:
53+
PresentationContextCoreAnimation(const WGPUSurfaceDescriptor&);
54+
};
55+
56+
} // namespace WebGPU
57+
58+
SPECIALIZE_TYPE_TRAITS_WEBGPU_PRESENTATION_CONTEXT(PresentationContextCoreAnimation, isPresentationContextCoreAnimation());

0 commit comments

Comments
 (0)
0