Improve WebGPU implementation, including using Metal Objective-C protocols more simpl...
authordarin@apple.com <darin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 26 Jul 2018 15:42:53 +0000 (15:42 +0000)
committerdarin@apple.com <darin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 26 Jul 2018 15:42:53 +0000 (15:42 +0000)
https://bugs.webkit.org/show_bug.cgi?id=187333

Reviewed by Sam Weinig.

Source/WebCore:

- Used a new OBJC_PROTOCOL macro to handle things in the Metal API that are protocols.
  The code previously had used OBJC_CLASS, but that created unrelated classes.
  Fixing this allows removing many typecasts that were in the existing code, makes it
  ARC-compatible, and also allowed the compiler to detect a couple mistakes where we
  were calling methods that don't exist.

- Eliminated use of separate heap-allocated, reference-counted objects to
  hold pointers to Metal objects.

- Reduced the use of the WebGPU wrappers to pass around arguments inside the code.
  They are now used only as part of the DOM binding; the inner GPU objects are used
  whenever possible. This cuts down the number of separate functions needed a bit,
  since we don't always need accessors for the things inside the wrappers.

- Used references rather than pointers in many cases.

- Took out three kinds of null checks: 1) Unneeded ones since Objective-C has the
  "do nothing and return 0" behavior for methods without return values and that return
  integer scalars. 2) Checks that aren't needed because the code has clear, invariant
  guarantees that the pointer won't be null. 3) The simplest variant of (2), checks
  that can be obviated by using reference types instead of pointer types.

- For Metal-specific functions and data members, used the function name metal() and
  the data member name m_metal rather than longer wordier names with the word "platform"
  in them. We could use "platform" if these objects were platform-specific objects used
  in a cross-platform way that needed a common name. But in this case it's clearer to
  call them "metal" since we are dropping down to the metal with Metal API, and
  shared platform-independent code will not be accessing these.

- Fixed the common mistake of using "unsigned long" in our C++ code to match IDL.
  The "unsigned long" type in IDL correponds to the "unsigned" type in WebKit code.

- Used "const" more in the GPU functions that are wrappers around Metal objects to
  reflect the fact that these have semantics of smart pointers; most operations can be
  done without changing which object is pointed to. This allows us to use const
  references to pass things around without reference count churn.

- Reduced includes.

- Added "explicit" keywords where appropriate.

- Removed unused functions. In particular, removed non-Metal stub versions of the
  functions in the GPU classes: the right way to start a new port is to clone the
  Metal-specific files and turn the into stubs if needed, it does not make it
  significantly more convenient to have stubs in the platform independent files,
  especially ones that are not compiled for any platform.

- Removed most the WEBCORE_EXPORT in the GPU headers; left only what's needed to
  support testing with TestWebKitAPI.

- Fixed two storage leaks in GPUDevice by adding missing adoptNS.

* PlatformMac.cmake: Moved files from platform/graphics/cocoa to platform/graphics/metal.
* SourcesCocoa.txt: Ditto.
* WebCore.xcodeproj/project.pbxproj: Ditto. Fixed paths on some files and groups/directories.
Made the platform files that abstract GPU all be "project" visible, not "private", since
they don't need to be visible outside WebCore. Removed reference to FontSelectionKeywordValues.h,
which does not seem to be a source file, a derived source file, or mentioned in any change log.

* bindings/js/JSWebGPURenderPassAttachmentDescriptorCustom.cpp:
(WebCore::toJSNewlyCreated): Create the correct wrapper for a
WebGPURenderPassDepthAttachmentDescriptor. The old code would instead
create a WebGPURenderPassAttachmentDescriptor wrapper, which can't be
used to access the clearDepth attribute.

* html/canvas/WebGPUBuffer.cpp:
(WebCore::WebGPUBuffer::create): Use more references rather than pointers for things
that are never null. Added comment about possibly returning null on failure in future.
(WebCore::WebGPUBuffer::WebGPUBuffer): Updated to store the GPUBuffer inside the class
instead of in a separate reference counted object.
* html/canvas/WebGPUBuffer.h: Ditto.

* html/canvas/WebGPUCommandBuffer.cpp:
(WebCore::WebGPUCommandBuffer::create): Use references and lower level types.
(WebCore::WebGPUCommandBuffer::WebGPUCommandBuffer): Store the GPUCommandBuffer
inside the class.
(WebCore::WebGPUCommandBuffer::commit): Removed unneeded null checks.
(WebCore::WebGPUCommandBuffer::presentDrawable): Ditto.
(WebCore::WebGPUCommandBuffer::createRenderCommandEncoderWithDescriptor):
Removed unneeded local variable.
(WebCore::WebGPUCommandBuffer::createComputeCommandEncoder): Ditto.
(WebCore::WebGPUCommandBuffer::completed): Store the DOMPromiseProxy in this
class, not in GPUCommandBuffer.
* html/canvas/WebGPUCommandBuffer.h: Ditto.

* html/canvas/WebGPUCommandQueue.cpp:
(WebCore::WebGPUCommandQueue::create): Use references and lower level types.
(WebCore::WebGPUCommandQueue::WebGPUCommandQueue): Store the GPUCommandQueue
inside the class.
(WebCore::WebGPUCommandQueue::createCommandBuffer): Ditto.
* html/canvas/WebGPUCommandQueue.h: Ditto.
* html/canvas/WebGPUCommandQueue.idl: The return value of createCommandBuffer
is no longer nullable.

* html/canvas/WebGPUComputeCommandEncoder.cpp:
(WebCore::WebGPUComputeCommandEncoder::create): More of the same.
(WebCore::WebGPUComputeCommandEncoder::WebGPUComputeCommandEncoder): Ditto.
(WebCore::WebGPUComputeCommandEncoder::setComputePipelineState): Ditto.
(WebCore::WebGPUComputeCommandEncoder::setBuffer): Ditto.
(WebCore::WebGPUComputeCommandEncoder::dispatch): Ditto.
(WebCore::WebGPUComputeCommandEncoder::endEncoding): Ditto.
* html/canvas/WebGPUComputeCommandEncoder.h: Ditto.

* html/canvas/WebGPUComputePipelineState.cpp:
(WebCore::WebGPUComputePipelineState::create): More of the same.
(WebCore::WebGPUComputePipelineState::WebGPUComputePipelineState): Ditto.
* html/canvas/WebGPUComputePipelineState.h: Ditto.

* html/canvas/WebGPUDepthStencilDescriptor.cpp:
(WebCore::WebGPUDepthStencilDescriptor::create): More of the same.
(WebCore::WebGPUDepthStencilDescriptor::depthWriteEnabled const): Ditto.
(WebCore::WebGPUDepthStencilDescriptor::setDepthWriteEnabled): Ditto.
(WebCore::WebGPUDepthStencilDescriptor::depthCompareFunction const): Ditto.
(WebCore::WebGPUDepthStencilDescriptor::setDepthCompareFunction): Ditto.
* html/canvas/WebGPUDepthStencilDescriptor.h: Ditto. Also fixed a bug
where m_depthCompareFunction was uninitialized in newly created objects.

* html/canvas/WebGPUDepthStencilState.cpp:
(WebCore::WebGPUDepthStencilState::create): More of the same.
(WebCore::WebGPUDepthStencilState::WebGPUDepthStencilState): Ditto.
(WebCore::WebGPUDepthStencilState::label const): Ditto.
(WebCore::WebGPUDepthStencilState::setLabel): Ditto.
* html/canvas/WebGPUDepthStencilState.h: Ditto.

* html/canvas/WebGPUDrawable.cpp:
(WebCore::WebGPUDrawable::create): More of the same.
(WebCore::WebGPUDrawable::WebGPUDrawable): Ditto.
* html/canvas/WebGPUDrawable.h: Ditto.

* html/canvas/WebGPUEnums.cpp: Removed some stray const.
* html/canvas/WebGPUEnums.h: Ditto.

* html/canvas/WebGPUFunction.cpp:
(WebCore::WebGPUFunction::create): More of the same.
(WebCore::WebGPUFunction::WebGPUFunction): Ditto.
* html/canvas/WebGPUFunction.h: Ditto.

* html/canvas/WebGPULibrary.cpp:
(WebCore::WebGPULibrary::create): More of the same.
(WebCore::WebGPULibrary::WebGPULibrary): Ditto.
(WebCore::WebGPULibrary::functionNames const): Ditto.
(WebCore::WebGPULibrary::functionWithName const): Ditto.
* html/canvas/WebGPULibrary.h: Ditto.

* html/canvas/WebGPUObject.cpp:
(WebCore::WebGPUObject::WebGPUObject):
(WebCore::WebGPUObject::deleteObject): Deleted this unused function.
We can bring it back later if we find we need it the way we did with the
WebGL implementation, but currently it's a never-called stub. Also
deleted the isDeleted and m_deleted for the same reason.
* html/canvas/WebGPUObject.h: Ditto.

* html/canvas/WebGPURenderCommandEncoder.cpp:
(WebCore::WebGPURenderCommandEncoder::create): More of the same.
(WebCore::WebGPURenderCommandEncoder::WebGPURenderCommandEncoder): Ditto.
(WebCore::WebGPURenderCommandEncoder::setRenderPipelineState): Ditto.
(WebCore::WebGPURenderCommandEncoder::setDepthStencilState): Ditto.
(WebCore::WebGPURenderCommandEncoder::setVertexBuffer): Ditto.
(WebCore::WebGPURenderCommandEncoder::setFragmentBuffer): Ditto.
(WebCore::WebGPURenderCommandEncoder::drawPrimitives): Ditto.
(WebCore::WebGPURenderCommandEncoder::endEncoding): Ditto.
* html/canvas/WebGPURenderCommandEncoder.h: Ditto.

* html/canvas/WebGPURenderPassAttachmentDescriptor.cpp:
(WebCore::WebGPURenderPassAttachmentDescriptor::WebGPURenderPassAttachmentDescriptor):
More of the same.
(WebCore::WebGPURenderPassAttachmentDescriptor::loadAction const): Ditto.
(WebCore::WebGPURenderPassAttachmentDescriptor::setLoadAction): Ditto.
(WebCore::WebGPURenderPassAttachmentDescriptor::storeAction const): Ditto.
(WebCore::WebGPURenderPassAttachmentDescriptor::setStoreAction): Ditto.
(WebCore::WebGPURenderPassAttachmentDescriptor::texture const): Ditto.
(WebCore::WebGPURenderPassAttachmentDescriptor::setTexture): Ditto.
* html/canvas/WebGPURenderPassAttachmentDescriptor.h: Ditto.

* html/canvas/WebGPURenderPassColorAttachmentDescriptor.cpp:
(WebCore::WebGPURenderPassColorAttachmentDescriptor::create): More of the same.
(WebCore::WebGPURenderPassColorAttachmentDescriptor::WebGPURenderPassColorAttachmentDescriptor): Ditto.
(WebCore::WebGPURenderPassColorAttachmentDescriptor::descriptor const): Ditto.
(WebCore::WebGPURenderPassColorAttachmentDescriptor::clearColor const): Ditto.
(WebCore::WebGPURenderPassColorAttachmentDescriptor::setClearColor): Ditto.
* html/canvas/WebGPURenderPassColorAttachmentDescriptor.h: Ditto.

* html/canvas/WebGPURenderPassDepthAttachmentDescriptor.cpp:
(WebCore::WebGPURenderPassDepthAttachmentDescriptor::create): More of the same.
(WebCore::WebGPURenderPassDepthAttachmentDescriptor::WebGPURenderPassDepthAttachmentDescriptor): Ditto.
(WebCore::WebGPURenderPassDepthAttachmentDescriptor::clearDepth const): Ditto.
(WebCore::WebGPURenderPassDepthAttachmentDescriptor::setClearDepth): Ditto.
(WebCore::WebGPURenderPassDepthAttachmentDescriptor::descriptor const): Ditto.
* html/canvas/WebGPURenderPassDepthAttachmentDescriptor.h: Ditto.

* html/canvas/WebGPURenderPassDescriptor.cpp:
(WebCore::WebGPURenderPassDescriptor::create): More of the same.
(WebCore::WebGPURenderPassDescriptor::depthAttachment): Ditto.
(WebCore::WebGPURenderPassDescriptor::colorAttachments): Ditto.
* html/canvas/WebGPURenderPassDescriptor.h: Ditto.

* html/canvas/WebGPURenderPipelineColorAttachmentDescriptor.cpp:
(WebCore::WebGPURenderPipelineColorAttachmentDescriptor::create): More of the same.
(WebCore::WebGPURenderPipelineColorAttachmentDescriptor::WebGPURenderPipelineColorAttachmentDescriptor): Ditto.
(WebCore::WebGPURenderPipelineColorAttachmentDescriptor::pixelFormat const): Ditto.
(WebCore::WebGPURenderPipelineColorAttachmentDescriptor::setPixelFormat): Ditto.
* html/canvas/WebGPURenderPipelineColorAttachmentDescriptor.h: Ditto.

* html/canvas/WebGPURenderPipelineDescriptor.cpp:
(WebCore::WebGPURenderPipelineDescriptor::create): More of the same.
(WebCore::WebGPURenderPipelineDescriptor::vertexFunction const): Ditto.
(WebCore::WebGPURenderPipelineDescriptor::setVertexFunction): Ditto.
(WebCore::WebGPURenderPipelineDescriptor::fragmentFunction const): Ditto.
(WebCore::WebGPURenderPipelineDescriptor::setFragmentFunction): Ditto.
(WebCore::WebGPURenderPipelineDescriptor::colorAttachments): Ditto.
(WebCore::WebGPURenderPipelineDescriptor::depthAttachmentPixelFormat const): Ditto.
(WebCore::WebGPURenderPipelineDescriptor::setDepthAttachmentPixelFormat): Ditto.
(WebCore::WebGPURenderPipelineDescriptor::reset): Ditto.
* html/canvas/WebGPURenderPipelineDescriptor.h: Ditto.

* html/canvas/WebGPURenderPipelineState.cpp:
(WebCore::WebGPURenderPipelineState::create): More of the same.
(WebCore::WebGPURenderPipelineState::WebGPURenderPipelineState): Ditto.
(WebCore::WebGPURenderPipelineState::label const): Ditto.
(WebCore::WebGPURenderPipelineState::setLabel): Ditto.
* html/canvas/WebGPURenderPipelineState.h: Ditto.

* html/canvas/WebGPURenderingContext.cpp:
(WebCore::WebGPURenderingContext::create): More of the same.
(WebCore::WebGPURenderingContext::WebGPURenderingContext): Ditto.
(WebCore::WebGPURenderingContext::initializeNewContext): Ditto.
(WebCore::WebGPURenderingContext::platformLayer const): Ditto.
(WebCore::WebGPURenderingContext::markLayerComposited): Ditto.
(WebCore::WebGPURenderingContext::reshape): Ditto.
(WebCore::WebGPURenderingContext::createLibrary): Ditto.
(WebCore::WebGPURenderingContext::createRenderPipelineState): Ditto.
(WebCore::WebGPURenderingContext::createDepthStencilState): Ditto.
(WebCore::WebGPURenderingContext::createComputePipelineState): Ditto.
(WebCore::WebGPURenderingContext::createCommandQueue): Ditto.
(WebCore::WebGPURenderingContext::nextDrawable): Ditto.
(WebCore::WebGPURenderingContext::createBuffer): Ditto.
(WebCore::WebGPURenderingContext::createTexture): Ditto.
* html/canvas/WebGPURenderingContext.h: Made many functions final and
private.
* html/canvas/WebGPURenderingContext.idl: The return value of most of
the create functions are no longer nullable.

* html/canvas/WebGPUSize.h: Use "unsigned" instead of "unsigned long".

* html/canvas/WebGPUTexture.cpp:
(WebCore::WebGPUTexture::createFromDrawableTexture): More of the same.
(WebCore::WebGPUTexture::create): Ditto.
(WebCore::WebGPUTexture::WebGPUTexture): Ditto.
* html/canvas/WebGPUTexture.h: Ditto.

* html/canvas/WebGPUTextureDescriptor.cpp:
(WebCore::WebGPUTextureDescriptor::create): More of the same.
(WebCore::WebGPUTextureDescriptor::WebGPUTextureDescriptor): Ditto.
(WebCore::WebGPUTextureDescriptor::width const): Ditto.
(WebCore::WebGPUTextureDescriptor::setWidth): Ditto.
(WebCore::WebGPUTextureDescriptor::height const): Ditto.
(WebCore::WebGPUTextureDescriptor::setHeight): Ditto.
(WebCore::WebGPUTextureDescriptor::sampleCount const): Ditto.
(WebCore::WebGPUTextureDescriptor::setSampleCount): Ditto.
(WebCore::WebGPUTextureDescriptor::textureType const): Ditto.
(WebCore::WebGPUTextureDescriptor::setTextureType): Ditto.
(WebCore::WebGPUTextureDescriptor::storageMode const): Ditto.
(WebCore::WebGPUTextureDescriptor::setStorageMode): Ditto.
(WebCore::WebGPUTextureDescriptor::usage const): Ditto.
(WebCore::WebGPUTextureDescriptor::setUsage): Ditto.
* html/canvas/WebGPUTextureDescriptor.h: Ditto.

* platform/graphics/metal/GPUBufferMetal.mm: Moved from "cocoa" directory.
(WebCore::GPUBuffer::GPUBuffer): Simplify code using references and the
"metal" naming.

* platform/graphics/metal/GPUCommandBufferMetal.mm:
(WebCore::GPUCommandBuffer::GPUCommandBuffer): Take a function to be called as the
completed handler and set it up.
(WebCore::GPUCommandBuffer::presentDrawable const): Ditto.
(WebCore::GPUCommandBuffer::commit const): Ditto.
(WebCore::GPUCommandBuffer::addCompletedHandler): Deleted.

* platform/graphics/metal/GPUCommandQueueMetal.mm:
(WebCore::GPUCommandQueue::GPUCommandQueue): Ditto. Also rewrote label handling a bit.
(WebCore::GPUCommandQueue::label const): Ditto.
(WebCore::GPUCommandQueue::setLabel const): Ditto.

* platform/graphics/metal/GPUComputeCommandEncoderMetal.mm:
(WebCore::GPUComputeCommandEncoder::GPUComputeCommandEncoder): Ditto.
(WebCore::GPUComputeCommandEncoder::setComputePipelineState const): Ditto.
(WebCore::GPUComputeCommandEncoder::setBuffer const): Ditto.
(WebCore::GPUComputeCommandEncoder::dispatch const): Ditto.
(WebCore::GPUComputeCommandEncoder::endEncoding const): Ditto.

* platform/graphics/metal/GPUComputePipelineStateMetal.mm:
(WebCore::GPUComputePipelineState::GPUComputePipelineState): Ditto.

* platform/graphics/metal/GPUDepthStencilDescriptorMetal.mm:
(WebCore::GPUDepthStencilDescriptor::GPUDepthStencilDescriptor): Ditto.
(WebCore::GPUDepthStencilDescriptor::depthWriteEnabled const): Ditto.
(WebCore::GPUDepthStencilDescriptor::setDepthWriteEnabled const): Ditto.
(WebCore::GPUDepthStencilDescriptor::depthCompareFunction const): Ditto.
(WebCore::GPUDepthStencilDescriptor::setDepthCompareFunction const): Ditto.

* platform/graphics/metal/GPUDepthStencilStateMetal.mm:
(WebCore::GPUDepthStencilState::GPUDepthStencilState): Ditto.
(WebCore::GPUDepthStencilState::label const): Ditto.
(WebCore::GPUDepthStencilState::setLabel const): Ditto. This is one of the
functions that was calling a method that does not exist. Added a comment.

* platform/graphics/metal/GPUDeviceMetal.mm:
(WebCore::GPUDevice::GPUDevice): Ditto. Also fixed two storage leaks where
we neglected to do adoptNS on the result of MTLCreateSystemDefaultDevice and
on the result of -[[WebGPULayer alloc] initWithGPUDevice:].
(WebCore::GPUDevice::reshape const): Ditto.
(WebCore::GPUDevice::platformLayer const): Ditto.
(WebCore::GPUDevice::operator! const): Ditto.

* platform/graphics/metal/GPUDrawableMetal.mm:
(WebCore::GPUDrawable::GPUDrawable): Ditto.
(WebCore::GPUDrawable::release): Ditto.
(WebCore::GPUDrawable::metal const): Ditto.
(WebCore::GPUDrawable::texture const): Ditto.

* platform/graphics/metal/GPUFunctionMetal.mm:
(WebCore::GPUFunction::GPUFunction): Ditto.
(WebCore::GPUFunction::name const): Ditto.
(WebCore::GPUFunction::metal const): Ditto.
(WebCore::GPUFunction::operator! const): Ditto.

* platform/graphics/metal/GPULibraryMetal.mm:
(WebCore::GPULibrary::GPULibrary): Ditto.
(WebCore::GPULibrary::label const): Ditto.
(WebCore::GPULibrary::setLabel const): Ditto.
(WebCore::GPULibrary::functionNames const): Ditto.
(WebCore::GPULibrary::metal const): Ditto.

* platform/graphics/metal/GPURenderCommandEncoderMetal.mm:
(WebCore::GPURenderCommandEncoder::GPURenderCommandEncoder): Ditto.
(WebCore::GPURenderCommandEncoder::setRenderPipelineState const): Ditto.
(WebCore::GPURenderCommandEncoder::setDepthStencilState const): Ditto.
(WebCore::GPURenderCommandEncoder::setVertexBuffer const): Ditto.
(WebCore::GPURenderCommandEncoder::setFragmentBuffer const): Ditto.
(WebCore::GPURenderCommandEncoder::drawPrimitives const): Ditto.
(WebCore::GPURenderCommandEncoder::endEncoding const): Ditto.

* platform/graphics/metal/GPURenderPassAttachmentDescriptorMetal.mm:
(WebCore::GPURenderPassAttachmentDescriptor::GPURenderPassAttachmentDescriptor): Ditto.
(WebCore::GPURenderPassAttachmentDescriptor::loadAction const): Ditto.
(WebCore::GPURenderPassAttachmentDescriptor::setLoadAction const): Ditto.
(WebCore::GPURenderPassAttachmentDescriptor::storeAction const): Ditto.
(WebCore::GPURenderPassAttachmentDescriptor::setStoreAction const): Ditto.
(WebCore::GPURenderPassAttachmentDescriptor::setTexture const): Ditto.

* platform/graphics/metal/GPURenderPassColorAttachmentDescriptorMetal.mm:
(WebCore::GPURenderPassColorAttachmentDescriptor::GPURenderPassColorAttachmentDescriptor): Ditto.
(WebCore::GPURenderPassColorAttachmentDescriptor::clearColor const): Ditto.
(WebCore::GPURenderPassColorAttachmentDescriptor::setClearColor const): Ditto.
(WebCore::GPURenderPassColorAttachmentDescriptor::metal const): Ditto.

* platform/graphics/metal/GPURenderPassDepthAttachmentDescriptorMetal.mm:
(WebCore::GPURenderPassDepthAttachmentDescriptor::GPURenderPassDepthAttachmentDescriptor): Ditto.
(WebCore::GPURenderPassDepthAttachmentDescriptor::clearDepth const): Ditto.
(WebCore::GPURenderPassDepthAttachmentDescriptor::setClearDepth const): Ditto.
(WebCore::GPURenderPassDepthAttachmentDescriptor::metal const): Ditto.

* platform/graphics/metal/GPURenderPassDescriptorMetal.mm:
(WebCore::GPURenderPassDescriptor::GPURenderPassDescriptor): Ditto.
(WebCore::GPURenderPassDescriptor::colorAttachments const): Ditto.
(WebCore::GPURenderPassDescriptor::depthAttachment const): Ditto.
(WebCore::GPURenderPassDescriptor::metal const): Ditto.

* platform/graphics/metal/GPURenderPipelineColorAttachmentDescriptorMetal.mm:
(WebCore::GPURenderPipelineColorAttachmentDescriptor::GPURenderPipelineColorAttachmentDescriptor): Ditto.
(WebCore::GPURenderPipelineColorAttachmentDescriptor::pixelFormat const): Ditto.
(WebCore::GPURenderPipelineColorAttachmentDescriptor::setPixelFormat const): Ditto.
(WebCore::GPURenderPipelineColorAttachmentDescriptor::metal const): Ditto.

* platform/graphics/metal/GPURenderPipelineDescriptorMetal.mm:
(WebCore::GPURenderPipelineDescriptor::GPURenderPipelineDescriptor): Ditto.
(WebCore::GPURenderPipelineDescriptor::depthAttachmentPixelFormat const): Ditto.
(WebCore::GPURenderPipelineDescriptor::setDepthAttachmentPixelFormat const): Ditto.
(WebCore::GPURenderPipelineDescriptor::setVertexFunction const): Ditto.
(WebCore::GPURenderPipelineDescriptor::setFragmentFunction const): Ditto.
(WebCore::GPURenderPipelineDescriptor::colorAttachments const): Ditto.
(WebCore::GPURenderPipelineDescriptor::reset const): Ditto.
(WebCore::GPURenderPipelineDescriptor::metal const): Ditto.

* platform/graphics/metal/GPURenderPipelineStateMetal.mm:
(WebCore::GPURenderPipelineState::GPURenderPipelineState): Ditto.
(WebCore::GPURenderPipelineState::label const): Ditto.
(WebCore::GPURenderPipelineState::setLabel const): Ditto. This is one of the
functions that was calling a method that does not exist. Added a comment.
(WebCore::GPURenderPipelineState::metal const): Ditto.

* platform/graphics/metal/GPUTextureDescriptorMetal.mm:
(WebCore::GPUTextureDescriptor::GPUTextureDescriptor): Ditto.
(WebCore::GPUTextureDescriptor::width const): Ditto.
(WebCore::GPUTextureDescriptor::setWidth const): Ditto.
(WebCore::GPUTextureDescriptor::height const): Ditto.
(WebCore::GPUTextureDescriptor::setHeight const): Ditto.
(WebCore::GPUTextureDescriptor::sampleCount const): Ditto.
(WebCore::GPUTextureDescriptor::setSampleCount const): Ditto.
(WebCore::GPUTextureDescriptor::textureType const): Ditto.
(WebCore::GPUTextureDescriptor::setTextureType const): Ditto.
(WebCore::GPUTextureDescriptor::storageMode const): Ditto.
(WebCore::GPUTextureDescriptor::setStorageMode const): Ditto.
(WebCore::GPUTextureDescriptor::usage const): Ditto.
(WebCore::GPUTextureDescriptor::setUsage const): Ditto.
(WebCore::GPUTextureDescriptor::metal const): Ditto.

* platform/graphics/metal/GPUTextureMetal.mm:
(WebCore::GPUTexture::GPUTexture): Ditto.
(WebCore::GPUTexture::width const): Ditto.
(WebCore::GPUTexture::height const): Ditto.
(WebCore::GPUTexture::metal const): Ditto.

* platform/graphics/gpu/GPUBuffer.cpp: Removed unused stubs.
(WebCore::GPUBuffer::length const): Moved this function here since it has
a useful platform-independent implementation.

* platform/graphics/gpu/GPUBuffer.h: Use OBJC_PROTOCOL for MTLBuffer.
Did the other thigs mentioned above: USE(METAL), remove WEBCORE_EXPORT,
no longer be RefCounted, etc.

* platform/graphics/gpu/GPUCommandBuffer.cpp: Ditto.
* platform/graphics/gpu/GPUCommandBuffer.h: Ditto. Use OBJC_PROTOCOL
for MTLCommandBuffer.

* platform/graphics/gpu/GPUCommandQueue.cpp: Ditto.
* platform/graphics/gpu/GPUCommandQueue.h: Ditto. Use OBJC_PROTOCOL for
MTLCommandQueue.

* platform/graphics/gpu/GPUComputeCommandEncoder.cpp: Ditto.
* platform/graphics/gpu/GPUComputeCommandEncoder.h: Ditto. Use OBJC_PROTOCOL for
MTLComputeCommandEncoder.

* platform/graphics/gpu/GPUComputePipelineState.cpp: Ditto.
* platform/graphics/gpu/GPUComputePipelineState.h: Ditto. Use OBJC_PROTOCOL for
MTLComputePipelineState.

* platform/graphics/gpu/GPUDepthStencilDescriptor.cpp: Ditto.
* platform/graphics/gpu/GPUDepthStencilDescriptor.h: Ditto.

* platform/graphics/gpu/GPUDepthStencilState.cpp: Ditto.
* platform/graphics/gpu/GPUDepthStencilState.h: Ditto. Use OBJC_PROTOCOL for
MTLDepthStencilState.

* platform/graphics/gpu/GPUDevice.cpp: Ditto.
* platform/graphics/gpu/GPUDevice.h: Ditto. Use OBJC_PROTOCOL for MTLDevice.

* platform/graphics/gpu/GPUDrawable.cpp: Ditto.
* platform/graphics/gpu/GPUDrawable.h: Ditto. Use OBJC_PROTOCOL for
MTLDrawable and MTLTexture.

* platform/graphics/gpu/GPUEnums.h: Tweaked formatting.

* platform/graphics/gpu/GPUFunction.cpp: Ditto.
* platform/graphics/gpu/GPUFunction.h: Ditto. Use OBJC_PROTOCOL for
MTLFunction.

* platform/graphics/gpu/GPULibrary.cpp: Ditto.
* platform/graphics/gpu/GPULibrary.h: Ditto. Use OBJC_PROTOCOL for
MTLLibrary.

* platform/graphics/gpu/GPURenderCommandEncoder.cpp: Ditto.
* platform/graphics/gpu/GPURenderCommandEncoder.h: Ditto.
Use OBJC_PROTOCOL for MTLRenderCommandEncoder.

* platform/graphics/gpu/GPURenderPassAttachmentDescriptor.cpp: Ditto.
* platform/graphics/gpu/GPURenderPassAttachmentDescriptor.h: Ditto.

* platform/graphics/gpu/GPURenderPassColorAttachmentDescriptor.cpp: Ditto.
* platform/graphics/gpu/GPURenderPassColorAttachmentDescriptor.h: Ditto.

* platform/graphics/gpu/GPURenderPassDepthAttachmentDescriptor.cpp: Ditto.
* platform/graphics/gpu/GPURenderPassDepthAttachmentDescriptor.h: Ditto.

* platform/graphics/gpu/GPURenderPassDescriptor.cpp: Ditto.
* platform/graphics/gpu/GPURenderPassDescriptor.h: Ditto.

* platform/graphics/gpu/GPURenderPipelineColorAttachmentDescriptor.cpp: Ditto.
* platform/graphics/gpu/GPURenderPipelineColorAttachmentDescriptor.h: Ditto.

* platform/graphics/gpu/GPURenderPipelineDescriptor.cpp: Ditto.
* platform/graphics/gpu/GPURenderPipelineDescriptor.h: Ditto.

* platform/graphics/gpu/GPURenderPipelineState.cpp: Ditto.
* platform/graphics/gpu/GPURenderPipelineState.h: Ditto. Use OBJC_PROTOCOL
for MTLRenderPipelineState.

* platform/graphics/gpu/GPUSize.h: Use "unsigned" instead of "unsigned long".

* platform/graphics/gpu/GPUTexture.cpp: Ditto.
* platform/graphics/gpu/GPUTexture.h: Ditto. Use OBJC_PROTOCOL for
MTLTexture.

* platform/graphics/gpu/GPUTextureDescriptor.cpp: Ditto.
* platform/graphics/gpu/GPUTextureDescriptor.h: Ditto.

Source/WTF:

* wtf/Compiler.h: Added OBJC_PROTOCOL, a macro for convieniently treating an
Objective-C protocol in a way that lets it be mentioned in a C++ source file.
This is the rough equivalent of OBJC_CLASS, but for protocols.

* wtf/Platform.h: Added USE(METAL), alongside USE(OPENGL) and the like.
Now used in the WebGPU platform layer to guard the Metal-specific code.

Tools:

* TestWebKitAPI/Tests/WebCore/mac/GPUBuffer.mm: Updated.
* TestWebKitAPI/Tests/WebCore/mac/GPUCommandQueue.mm: Updated.
* TestWebKitAPI/Tests/WebCore/mac/GPUDevice.mm: Updated.
* TestWebKitAPI/Tests/WebCore/mac/GPUFunction.mm: Updated.
* TestWebKitAPI/Tests/WebCore/mac/GPULibrary.mm: Updated.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@234258 268f45cc-cd09-0410-ab3c-d52691b4dbfc

133 files changed:
Source/WTF/ChangeLog
Source/WTF/wtf/Compiler.h
Source/WTF/wtf/Platform.h
Source/WebCore/ChangeLog
Source/WebCore/PlatformMac.cmake
Source/WebCore/SourcesCocoa.txt
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/bindings/js/JSWebGPURenderPassAttachmentDescriptorCustom.cpp
Source/WebCore/html/canvas/WebGPUBuffer.cpp
Source/WebCore/html/canvas/WebGPUBuffer.h
Source/WebCore/html/canvas/WebGPUCommandBuffer.cpp
Source/WebCore/html/canvas/WebGPUCommandBuffer.h
Source/WebCore/html/canvas/WebGPUCommandQueue.cpp
Source/WebCore/html/canvas/WebGPUCommandQueue.h
Source/WebCore/html/canvas/WebGPUCommandQueue.idl
Source/WebCore/html/canvas/WebGPUComputeCommandEncoder.cpp
Source/WebCore/html/canvas/WebGPUComputeCommandEncoder.h
Source/WebCore/html/canvas/WebGPUComputePipelineState.cpp
Source/WebCore/html/canvas/WebGPUComputePipelineState.h
Source/WebCore/html/canvas/WebGPUDepthStencilDescriptor.cpp
Source/WebCore/html/canvas/WebGPUDepthStencilDescriptor.h
Source/WebCore/html/canvas/WebGPUDepthStencilState.cpp
Source/WebCore/html/canvas/WebGPUDepthStencilState.h
Source/WebCore/html/canvas/WebGPUDrawable.cpp
Source/WebCore/html/canvas/WebGPUDrawable.h
Source/WebCore/html/canvas/WebGPUEnums.cpp
Source/WebCore/html/canvas/WebGPUEnums.h
Source/WebCore/html/canvas/WebGPUFunction.cpp
Source/WebCore/html/canvas/WebGPUFunction.h
Source/WebCore/html/canvas/WebGPULibrary.cpp
Source/WebCore/html/canvas/WebGPULibrary.h
Source/WebCore/html/canvas/WebGPUObject.cpp
Source/WebCore/html/canvas/WebGPUObject.h
Source/WebCore/html/canvas/WebGPURenderCommandEncoder.cpp
Source/WebCore/html/canvas/WebGPURenderCommandEncoder.h
Source/WebCore/html/canvas/WebGPURenderPassAttachmentDescriptor.cpp
Source/WebCore/html/canvas/WebGPURenderPassAttachmentDescriptor.h
Source/WebCore/html/canvas/WebGPURenderPassColorAttachmentDescriptor.cpp
Source/WebCore/html/canvas/WebGPURenderPassColorAttachmentDescriptor.h
Source/WebCore/html/canvas/WebGPURenderPassDepthAttachmentDescriptor.cpp
Source/WebCore/html/canvas/WebGPURenderPassDepthAttachmentDescriptor.h
Source/WebCore/html/canvas/WebGPURenderPassDescriptor.cpp
Source/WebCore/html/canvas/WebGPURenderPassDescriptor.h
Source/WebCore/html/canvas/WebGPURenderPipelineColorAttachmentDescriptor.cpp
Source/WebCore/html/canvas/WebGPURenderPipelineColorAttachmentDescriptor.h
Source/WebCore/html/canvas/WebGPURenderPipelineDescriptor.cpp
Source/WebCore/html/canvas/WebGPURenderPipelineDescriptor.h
Source/WebCore/html/canvas/WebGPURenderPipelineState.cpp
Source/WebCore/html/canvas/WebGPURenderPipelineState.h
Source/WebCore/html/canvas/WebGPURenderingContext.cpp
Source/WebCore/html/canvas/WebGPURenderingContext.h
Source/WebCore/html/canvas/WebGPURenderingContext.idl
Source/WebCore/html/canvas/WebGPUSize.h
Source/WebCore/html/canvas/WebGPUTexture.cpp
Source/WebCore/html/canvas/WebGPUTexture.h
Source/WebCore/html/canvas/WebGPUTextureDescriptor.cpp
Source/WebCore/html/canvas/WebGPUTextureDescriptor.h
Source/WebCore/platform/graphics/cocoa/GPUCommandBufferMetal.mm [deleted file]
Source/WebCore/platform/graphics/cocoa/GPURenderCommandEncoderMetal.mm [deleted file]
Source/WebCore/platform/graphics/cocoa/GPURenderPipelineDescriptorMetal.mm [deleted file]
Source/WebCore/platform/graphics/cocoa/GPUTextureDescriptorMetal.mm [deleted file]
Source/WebCore/platform/graphics/cocoa/WebCoreDecompressionSession.mm
Source/WebCore/platform/graphics/gpu/GPUBuffer.cpp
Source/WebCore/platform/graphics/gpu/GPUBuffer.h
Source/WebCore/platform/graphics/gpu/GPUCommandBuffer.cpp
Source/WebCore/platform/graphics/gpu/GPUCommandBuffer.h
Source/WebCore/platform/graphics/gpu/GPUCommandQueue.cpp
Source/WebCore/platform/graphics/gpu/GPUCommandQueue.h
Source/WebCore/platform/graphics/gpu/GPUComputeCommandEncoder.cpp
Source/WebCore/platform/graphics/gpu/GPUComputeCommandEncoder.h
Source/WebCore/platform/graphics/gpu/GPUComputePipelineState.cpp
Source/WebCore/platform/graphics/gpu/GPUComputePipelineState.h
Source/WebCore/platform/graphics/gpu/GPUDepthStencilDescriptor.cpp
Source/WebCore/platform/graphics/gpu/GPUDepthStencilDescriptor.h
Source/WebCore/platform/graphics/gpu/GPUDepthStencilState.cpp
Source/WebCore/platform/graphics/gpu/GPUDepthStencilState.h
Source/WebCore/platform/graphics/gpu/GPUDevice.cpp
Source/WebCore/platform/graphics/gpu/GPUDevice.h
Source/WebCore/platform/graphics/gpu/GPUDrawable.cpp
Source/WebCore/platform/graphics/gpu/GPUDrawable.h
Source/WebCore/platform/graphics/gpu/GPUEnums.h
Source/WebCore/platform/graphics/gpu/GPUFunction.cpp
Source/WebCore/platform/graphics/gpu/GPUFunction.h
Source/WebCore/platform/graphics/gpu/GPULibrary.cpp
Source/WebCore/platform/graphics/gpu/GPULibrary.h
Source/WebCore/platform/graphics/gpu/GPURenderCommandEncoder.cpp
Source/WebCore/platform/graphics/gpu/GPURenderCommandEncoder.h
Source/WebCore/platform/graphics/gpu/GPURenderPassAttachmentDescriptor.cpp
Source/WebCore/platform/graphics/gpu/GPURenderPassAttachmentDescriptor.h
Source/WebCore/platform/graphics/gpu/GPURenderPassColorAttachmentDescriptor.cpp
Source/WebCore/platform/graphics/gpu/GPURenderPassColorAttachmentDescriptor.h
Source/WebCore/platform/graphics/gpu/GPURenderPassDepthAttachmentDescriptor.cpp
Source/WebCore/platform/graphics/gpu/GPURenderPassDepthAttachmentDescriptor.h
Source/WebCore/platform/graphics/gpu/GPURenderPassDescriptor.cpp
Source/WebCore/platform/graphics/gpu/GPURenderPassDescriptor.h
Source/WebCore/platform/graphics/gpu/GPURenderPipelineColorAttachmentDescriptor.cpp
Source/WebCore/platform/graphics/gpu/GPURenderPipelineColorAttachmentDescriptor.h
Source/WebCore/platform/graphics/gpu/GPURenderPipelineDescriptor.cpp
Source/WebCore/platform/graphics/gpu/GPURenderPipelineDescriptor.h
Source/WebCore/platform/graphics/gpu/GPURenderPipelineState.cpp
Source/WebCore/platform/graphics/gpu/GPURenderPipelineState.h
Source/WebCore/platform/graphics/gpu/GPUSize.h
Source/WebCore/platform/graphics/gpu/GPUTexture.cpp
Source/WebCore/platform/graphics/gpu/GPUTexture.h
Source/WebCore/platform/graphics/gpu/GPUTextureDescriptor.cpp
Source/WebCore/platform/graphics/gpu/GPUTextureDescriptor.h
Source/WebCore/platform/graphics/metal/GPUBufferMetal.mm [moved from Source/WebCore/platform/graphics/cocoa/GPUBufferMetal.mm with 69% similarity]
Source/WebCore/platform/graphics/metal/GPUCommandBufferMetal.mm [new file with mode: 0644]
Source/WebCore/platform/graphics/metal/GPUCommandQueueMetal.mm [moved from Source/WebCore/platform/graphics/cocoa/GPUCommandQueueMetal.mm with 65% similarity]
Source/WebCore/platform/graphics/metal/GPUComputeCommandEncoderMetal.mm [moved from Source/WebCore/platform/graphics/cocoa/GPUComputeCommandEncoderMetal.mm with 56% similarity]
Source/WebCore/platform/graphics/metal/GPUComputePipelineStateMetal.mm [moved from Source/WebCore/platform/graphics/cocoa/GPUComputePipelineStateMetal.mm with 76% similarity]
Source/WebCore/platform/graphics/metal/GPUDepthStencilDescriptorMetal.mm [moved from Source/WebCore/platform/graphics/cocoa/GPUDepthStencilDescriptorMetal.mm with 70% similarity]
Source/WebCore/platform/graphics/metal/GPUDepthStencilStateMetal.mm [moved from Source/WebCore/platform/graphics/cocoa/GPUDepthStencilStateMetal.mm with 70% similarity]
Source/WebCore/platform/graphics/metal/GPUDeviceMetal.mm [moved from Source/WebCore/platform/graphics/cocoa/GPUDeviceMetal.mm with 75% similarity]
Source/WebCore/platform/graphics/metal/GPUDrawableMetal.mm [moved from Source/WebCore/platform/graphics/cocoa/GPUDrawableMetal.mm with 78% similarity]
Source/WebCore/platform/graphics/metal/GPUFunctionMetal.mm [moved from Source/WebCore/platform/graphics/cocoa/GPUFunctionMetal.mm with 82% similarity]
Source/WebCore/platform/graphics/metal/GPULibraryMetal.mm [moved from Source/WebCore/platform/graphics/cocoa/GPULibraryMetal.mm with 70% similarity]
Source/WebCore/platform/graphics/metal/GPURenderCommandEncoderMetal.mm [new file with mode: 0644]
Source/WebCore/platform/graphics/metal/GPURenderPassAttachmentDescriptorMetal.mm [moved from Source/WebCore/platform/graphics/cocoa/GPURenderPassAttachmentDescriptorMetal.mm with 57% similarity]
Source/WebCore/platform/graphics/metal/GPURenderPassColorAttachmentDescriptorMetal.mm [moved from Source/WebCore/platform/graphics/cocoa/GPURenderPassColorAttachmentDescriptorMetal.mm with 57% similarity]
Source/WebCore/platform/graphics/metal/GPURenderPassDepthAttachmentDescriptorMetal.mm [moved from Source/WebCore/platform/graphics/cocoa/GPURenderPassDepthAttachmentDescriptorMetal.mm with 66% similarity]
Source/WebCore/platform/graphics/metal/GPURenderPassDescriptorMetal.mm [moved from Source/WebCore/platform/graphics/cocoa/GPURenderPassDescriptorMetal.mm with 62% similarity]
Source/WebCore/platform/graphics/metal/GPURenderPipelineColorAttachmentDescriptorMetal.mm [moved from Source/WebCore/platform/graphics/cocoa/GPURenderPipelineColorAttachmentDescriptorMetal.mm with 64% similarity]
Source/WebCore/platform/graphics/metal/GPURenderPipelineDescriptorMetal.mm [new file with mode: 0644]
Source/WebCore/platform/graphics/metal/GPURenderPipelineStateMetal.mm [moved from Source/WebCore/platform/graphics/cocoa/GPURenderPipelineStateMetal.mm with 69% similarity]
Source/WebCore/platform/graphics/metal/GPUTextureDescriptorMetal.mm [new file with mode: 0644]
Source/WebCore/platform/graphics/metal/GPUTextureMetal.mm [moved from Source/WebCore/platform/graphics/cocoa/GPUTextureMetal.mm with 67% similarity]
Tools/ChangeLog
Tools/TestWebKitAPI/Tests/WebCore/mac/GPUBuffer.mm
Tools/TestWebKitAPI/Tests/WebCore/mac/GPUCommandQueue.mm
Tools/TestWebKitAPI/Tests/WebCore/mac/GPUDevice.mm
Tools/TestWebKitAPI/Tests/WebCore/mac/GPUFunction.mm
Tools/TestWebKitAPI/Tests/WebCore/mac/GPULibrary.mm

index 55e64b8..785244c 100644 (file)
@@ -1,3 +1,17 @@
+2018-07-04  Darin Adler  <darin@apple.com>
+
+        Improve WebGPU implementation, including using Metal Objective-C protocols more simply and correctly
+        https://bugs.webkit.org/show_bug.cgi?id=187333
+
+        Reviewed by Sam Weinig.
+
+        * wtf/Compiler.h: Added OBJC_PROTOCOL, a macro for convieniently treating an
+        Objective-C protocol in a way that lets it be mentioned in a C++ source file.
+        This is the rough equivalent of OBJC_CLASS, but for protocols.
+
+        * wtf/Platform.h: Added USE(METAL), alongside USE(OPENGL) and the like.
+        Now used in the WebGPU platform layer to guard the Metal-specific code.
+
 2018-07-26  Tomas Popela  <tpopela@redhat.com>
 
         [WTF] Coverity scan issues
index 77f271e..798c309 100644 (file)
 #define OBJC_CLASS class
 #endif
 
+/* OBJC_PROTOCOL */
+
+#if !defined(OBJC_PROTOCOL) && defined(__OBJC__)
+/* This forward-declares a protocol, then also creates a type of the same name based on NSObject.
+ * This allows us to use "NSObject<MyProtocol> *" or "MyProtocol *" more-or-less interchangably. */
+#define OBJC_PROTOCOL(protocolName) @protocol protocolName; using protocolName = NSObject<protocolName>
+#endif
+
+#if !defined(OBJC_PROTOCOL)
+#define OBJC_PROTOCOL(protocolName) class protocolName
+#endif
+
 /* PURE_FUNCTION */
 
 #if !defined(PURE_FUNCTION) && COMPILER(GCC_OR_CLANG)
index 18fa82f..8397fab 100644 (file)
 #endif
 #endif
 
+#define USE_METAL 1
+
 #if HAVE(ACCESSIBILITY)
 #define USE_ACCESSIBILITY_CONTEXT_MENUS 1
 #endif
index 15c3885..130967f 100644 (file)
@@ -1,3 +1,506 @@
+2018-07-04  Darin Adler  <darin@apple.com>
+
+        Improve WebGPU implementation, including using Metal Objective-C protocols more simply and correctly
+        https://bugs.webkit.org/show_bug.cgi?id=187333
+
+        Reviewed by Sam Weinig.
+
+        - Used a new OBJC_PROTOCOL macro to handle things in the Metal API that are protocols.
+          The code previously had used OBJC_CLASS, but that created unrelated classes.
+          Fixing this allows removing many typecasts that were in the existing code, makes it
+          ARC-compatible, and also allowed the compiler to detect a couple mistakes where we
+          were calling methods that don't exist.
+
+        - Eliminated use of separate heap-allocated, reference-counted objects to
+          hold pointers to Metal objects.
+
+        - Reduced the use of the WebGPU wrappers to pass around arguments inside the code.
+          They are now used only as part of the DOM binding; the inner GPU objects are used
+          whenever possible. This cuts down the number of separate functions needed a bit,
+          since we don't always need accessors for the things inside the wrappers.
+
+        - Used references rather than pointers in many cases.
+
+        - Took out three kinds of null checks: 1) Unneeded ones since Objective-C has the
+          "do nothing and return 0" behavior for methods without return values and that return
+          integer scalars. 2) Checks that aren't needed because the code has clear, invariant
+          guarantees that the pointer won't be null. 3) The simplest variant of (2), checks
+          that can be obviated by using reference types instead of pointer types.
+
+        - For Metal-specific functions and data members, used the function name metal() and
+          the data member name m_metal rather than longer wordier names with the word "platform"
+          in them. We could use "platform" if these objects were platform-specific objects used
+          in a cross-platform way that needed a common name. But in this case it's clearer to
+          call them "metal" since we are dropping down to the metal with Metal API, and
+          shared platform-independent code will not be accessing these.
+
+        - Fixed the common mistake of using "unsigned long" in our C++ code to match IDL.
+          The "unsigned long" type in IDL correponds to the "unsigned" type in WebKit code.
+
+        - Used "const" more in the GPU functions that are wrappers around Metal objects to
+          reflect the fact that these have semantics of smart pointers; most operations can be
+          done without changing which object is pointed to. This allows us to use const
+          references to pass things around without reference count churn.
+
+        - Reduced includes.
+
+        - Added "explicit" keywords where appropriate.
+
+        - Removed unused functions. In particular, removed non-Metal stub versions of the
+          functions in the GPU classes: the right way to start a new port is to clone the
+          Metal-specific files and turn the into stubs if needed, it does not make it
+          significantly more convenient to have stubs in the platform independent files,
+          especially ones that are not compiled for any platform.
+
+        - Removed most the WEBCORE_EXPORT in the GPU headers; left only what's needed to
+          support testing with TestWebKitAPI.
+
+        - Fixed two storage leaks in GPUDevice by adding missing adoptNS.
+
+        * PlatformMac.cmake: Moved files from platform/graphics/cocoa to platform/graphics/metal.
+        * SourcesCocoa.txt: Ditto.
+        * WebCore.xcodeproj/project.pbxproj: Ditto. Fixed paths on some files and groups/directories.
+        Made the platform files that abstract GPU all be "project" visible, not "private", since
+        they don't need to be visible outside WebCore. Removed reference to FontSelectionKeywordValues.h,
+        which does not seem to be a source file, a derived source file, or mentioned in any change log.
+
+        * bindings/js/JSWebGPURenderPassAttachmentDescriptorCustom.cpp:
+        (WebCore::toJSNewlyCreated): Create the correct wrapper for a
+        WebGPURenderPassDepthAttachmentDescriptor. The old code would instead
+        create a WebGPURenderPassAttachmentDescriptor wrapper, which can't be
+        used to access the clearDepth attribute.
+
+        * html/canvas/WebGPUBuffer.cpp:
+        (WebCore::WebGPUBuffer::create): Use more references rather than pointers for things
+        that are never null. Added comment about possibly returning null on failure in future.
+        (WebCore::WebGPUBuffer::WebGPUBuffer): Updated to store the GPUBuffer inside the class
+        instead of in a separate reference counted object.
+        * html/canvas/WebGPUBuffer.h: Ditto.
+
+        * html/canvas/WebGPUCommandBuffer.cpp:
+        (WebCore::WebGPUCommandBuffer::create): Use references and lower level types.
+        (WebCore::WebGPUCommandBuffer::WebGPUCommandBuffer): Store the GPUCommandBuffer
+        inside the class.
+        (WebCore::WebGPUCommandBuffer::commit): Removed unneeded null checks.
+        (WebCore::WebGPUCommandBuffer::presentDrawable): Ditto.
+        (WebCore::WebGPUCommandBuffer::createRenderCommandEncoderWithDescriptor):
+        Removed unneeded local variable.
+        (WebCore::WebGPUCommandBuffer::createComputeCommandEncoder): Ditto.
+        (WebCore::WebGPUCommandBuffer::completed): Store the DOMPromiseProxy in this
+        class, not in GPUCommandBuffer.
+        * html/canvas/WebGPUCommandBuffer.h: Ditto.
+
+        * html/canvas/WebGPUCommandQueue.cpp:
+        (WebCore::WebGPUCommandQueue::create): Use references and lower level types.
+        (WebCore::WebGPUCommandQueue::WebGPUCommandQueue): Store the GPUCommandQueue
+        inside the class.
+        (WebCore::WebGPUCommandQueue::createCommandBuffer): Ditto.
+        * html/canvas/WebGPUCommandQueue.h: Ditto.
+        * html/canvas/WebGPUCommandQueue.idl: The return value of createCommandBuffer
+        is no longer nullable.
+
+        * html/canvas/WebGPUComputeCommandEncoder.cpp:
+        (WebCore::WebGPUComputeCommandEncoder::create): More of the same.
+        (WebCore::WebGPUComputeCommandEncoder::WebGPUComputeCommandEncoder): Ditto.
+        (WebCore::WebGPUComputeCommandEncoder::setComputePipelineState): Ditto.
+        (WebCore::WebGPUComputeCommandEncoder::setBuffer): Ditto.
+        (WebCore::WebGPUComputeCommandEncoder::dispatch): Ditto.
+        (WebCore::WebGPUComputeCommandEncoder::endEncoding): Ditto.
+        * html/canvas/WebGPUComputeCommandEncoder.h: Ditto.
+
+        * html/canvas/WebGPUComputePipelineState.cpp:
+        (WebCore::WebGPUComputePipelineState::create): More of the same.
+        (WebCore::WebGPUComputePipelineState::WebGPUComputePipelineState): Ditto.
+        * html/canvas/WebGPUComputePipelineState.h: Ditto.
+
+        * html/canvas/WebGPUDepthStencilDescriptor.cpp:
+        (WebCore::WebGPUDepthStencilDescriptor::create): More of the same.
+        (WebCore::WebGPUDepthStencilDescriptor::depthWriteEnabled const): Ditto.
+        (WebCore::WebGPUDepthStencilDescriptor::setDepthWriteEnabled): Ditto.
+        (WebCore::WebGPUDepthStencilDescriptor::depthCompareFunction const): Ditto.
+        (WebCore::WebGPUDepthStencilDescriptor::setDepthCompareFunction): Ditto.
+        * html/canvas/WebGPUDepthStencilDescriptor.h: Ditto. Also fixed a bug
+        where m_depthCompareFunction was uninitialized in newly created objects.
+
+        * html/canvas/WebGPUDepthStencilState.cpp:
+        (WebCore::WebGPUDepthStencilState::create): More of the same.
+        (WebCore::WebGPUDepthStencilState::WebGPUDepthStencilState): Ditto.
+        (WebCore::WebGPUDepthStencilState::label const): Ditto.
+        (WebCore::WebGPUDepthStencilState::setLabel): Ditto.
+        * html/canvas/WebGPUDepthStencilState.h: Ditto.
+
+        * html/canvas/WebGPUDrawable.cpp:
+        (WebCore::WebGPUDrawable::create): More of the same.
+        (WebCore::WebGPUDrawable::WebGPUDrawable): Ditto.
+        * html/canvas/WebGPUDrawable.h: Ditto.
+
+        * html/canvas/WebGPUEnums.cpp: Removed some stray const.
+        * html/canvas/WebGPUEnums.h: Ditto.
+
+        * html/canvas/WebGPUFunction.cpp:
+        (WebCore::WebGPUFunction::create): More of the same.
+        (WebCore::WebGPUFunction::WebGPUFunction): Ditto.
+        * html/canvas/WebGPUFunction.h: Ditto.
+
+        * html/canvas/WebGPULibrary.cpp:
+        (WebCore::WebGPULibrary::create): More of the same.
+        (WebCore::WebGPULibrary::WebGPULibrary): Ditto.
+        (WebCore::WebGPULibrary::functionNames const): Ditto.
+        (WebCore::WebGPULibrary::functionWithName const): Ditto.
+        * html/canvas/WebGPULibrary.h: Ditto.
+
+        * html/canvas/WebGPUObject.cpp:
+        (WebCore::WebGPUObject::WebGPUObject):
+        (WebCore::WebGPUObject::deleteObject): Deleted this unused function.
+        We can bring it back later if we find we need it the way we did with the
+        WebGL implementation, but currently it's a never-called stub. Also
+        deleted the isDeleted and m_deleted for the same reason.
+        * html/canvas/WebGPUObject.h: Ditto.
+
+        * html/canvas/WebGPURenderCommandEncoder.cpp:
+        (WebCore::WebGPURenderCommandEncoder::create): More of the same.
+        (WebCore::WebGPURenderCommandEncoder::WebGPURenderCommandEncoder): Ditto.
+        (WebCore::WebGPURenderCommandEncoder::setRenderPipelineState): Ditto.
+        (WebCore::WebGPURenderCommandEncoder::setDepthStencilState): Ditto.
+        (WebCore::WebGPURenderCommandEncoder::setVertexBuffer): Ditto.
+        (WebCore::WebGPURenderCommandEncoder::setFragmentBuffer): Ditto.
+        (WebCore::WebGPURenderCommandEncoder::drawPrimitives): Ditto.
+        (WebCore::WebGPURenderCommandEncoder::endEncoding): Ditto.
+        * html/canvas/WebGPURenderCommandEncoder.h: Ditto.
+
+        * html/canvas/WebGPURenderPassAttachmentDescriptor.cpp:
+        (WebCore::WebGPURenderPassAttachmentDescriptor::WebGPURenderPassAttachmentDescriptor):
+        More of the same.
+        (WebCore::WebGPURenderPassAttachmentDescriptor::loadAction const): Ditto.
+        (WebCore::WebGPURenderPassAttachmentDescriptor::setLoadAction): Ditto.
+        (WebCore::WebGPURenderPassAttachmentDescriptor::storeAction const): Ditto.
+        (WebCore::WebGPURenderPassAttachmentDescriptor::setStoreAction): Ditto.
+        (WebCore::WebGPURenderPassAttachmentDescriptor::texture const): Ditto.
+        (WebCore::WebGPURenderPassAttachmentDescriptor::setTexture): Ditto.
+        * html/canvas/WebGPURenderPassAttachmentDescriptor.h: Ditto.
+
+        * html/canvas/WebGPURenderPassColorAttachmentDescriptor.cpp:
+        (WebCore::WebGPURenderPassColorAttachmentDescriptor::create): More of the same.
+        (WebCore::WebGPURenderPassColorAttachmentDescriptor::WebGPURenderPassColorAttachmentDescriptor): Ditto.
+        (WebCore::WebGPURenderPassColorAttachmentDescriptor::descriptor const): Ditto.
+        (WebCore::WebGPURenderPassColorAttachmentDescriptor::clearColor const): Ditto.
+        (WebCore::WebGPURenderPassColorAttachmentDescriptor::setClearColor): Ditto.
+        * html/canvas/WebGPURenderPassColorAttachmentDescriptor.h: Ditto.
+
+        * html/canvas/WebGPURenderPassDepthAttachmentDescriptor.cpp:
+        (WebCore::WebGPURenderPassDepthAttachmentDescriptor::create): More of the same.
+        (WebCore::WebGPURenderPassDepthAttachmentDescriptor::WebGPURenderPassDepthAttachmentDescriptor): Ditto.
+        (WebCore::WebGPURenderPassDepthAttachmentDescriptor::clearDepth const): Ditto.
+        (WebCore::WebGPURenderPassDepthAttachmentDescriptor::setClearDepth): Ditto.
+        (WebCore::WebGPURenderPassDepthAttachmentDescriptor::descriptor const): Ditto.
+        * html/canvas/WebGPURenderPassDepthAttachmentDescriptor.h: Ditto.
+
+        * html/canvas/WebGPURenderPassDescriptor.cpp:
+        (WebCore::WebGPURenderPassDescriptor::create): More of the same.
+        (WebCore::WebGPURenderPassDescriptor::depthAttachment): Ditto.
+        (WebCore::WebGPURenderPassDescriptor::colorAttachments): Ditto.
+        * html/canvas/WebGPURenderPassDescriptor.h: Ditto.
+
+        * html/canvas/WebGPURenderPipelineColorAttachmentDescriptor.cpp:
+        (WebCore::WebGPURenderPipelineColorAttachmentDescriptor::create): More of the same.
+        (WebCore::WebGPURenderPipelineColorAttachmentDescriptor::WebGPURenderPipelineColorAttachmentDescriptor): Ditto.
+        (WebCore::WebGPURenderPipelineColorAttachmentDescriptor::pixelFormat const): Ditto.
+        (WebCore::WebGPURenderPipelineColorAttachmentDescriptor::setPixelFormat): Ditto.
+        * html/canvas/WebGPURenderPipelineColorAttachmentDescriptor.h: Ditto.
+
+        * html/canvas/WebGPURenderPipelineDescriptor.cpp:
+        (WebCore::WebGPURenderPipelineDescriptor::create): More of the same.
+        (WebCore::WebGPURenderPipelineDescriptor::vertexFunction const): Ditto.
+        (WebCore::WebGPURenderPipelineDescriptor::setVertexFunction): Ditto.
+        (WebCore::WebGPURenderPipelineDescriptor::fragmentFunction const): Ditto.
+        (WebCore::WebGPURenderPipelineDescriptor::setFragmentFunction): Ditto.
+        (WebCore::WebGPURenderPipelineDescriptor::colorAttachments): Ditto.
+        (WebCore::WebGPURenderPipelineDescriptor::depthAttachmentPixelFormat const): Ditto.
+        (WebCore::WebGPURenderPipelineDescriptor::setDepthAttachmentPixelFormat): Ditto.
+        (WebCore::WebGPURenderPipelineDescriptor::reset): Ditto.
+        * html/canvas/WebGPURenderPipelineDescriptor.h: Ditto.
+
+        * html/canvas/WebGPURenderPipelineState.cpp:
+        (WebCore::WebGPURenderPipelineState::create): More of the same.
+        (WebCore::WebGPURenderPipelineState::WebGPURenderPipelineState): Ditto.
+        (WebCore::WebGPURenderPipelineState::label const): Ditto.
+        (WebCore::WebGPURenderPipelineState::setLabel): Ditto.
+        * html/canvas/WebGPURenderPipelineState.h: Ditto.
+
+        * html/canvas/WebGPURenderingContext.cpp:
+        (WebCore::WebGPURenderingContext::create): More of the same.
+        (WebCore::WebGPURenderingContext::WebGPURenderingContext): Ditto.
+        (WebCore::WebGPURenderingContext::initializeNewContext): Ditto.
+        (WebCore::WebGPURenderingContext::platformLayer const): Ditto.
+        (WebCore::WebGPURenderingContext::markLayerComposited): Ditto.
+        (WebCore::WebGPURenderingContext::reshape): Ditto.
+        (WebCore::WebGPURenderingContext::createLibrary): Ditto.
+        (WebCore::WebGPURenderingContext::createRenderPipelineState): Ditto.
+        (WebCore::WebGPURenderingContext::createDepthStencilState): Ditto.
+        (WebCore::WebGPURenderingContext::createComputePipelineState): Ditto.
+        (WebCore::WebGPURenderingContext::createCommandQueue): Ditto.
+        (WebCore::WebGPURenderingContext::nextDrawable): Ditto.
+        (WebCore::WebGPURenderingContext::createBuffer): Ditto.
+        (WebCore::WebGPURenderingContext::createTexture): Ditto.
+        * html/canvas/WebGPURenderingContext.h: Made many functions final and
+        private.
+        * html/canvas/WebGPURenderingContext.idl: The return value of most of
+        the create functions are no longer nullable.
+
+        * html/canvas/WebGPUSize.h: Use "unsigned" instead of "unsigned long".
+
+        * html/canvas/WebGPUTexture.cpp:
+        (WebCore::WebGPUTexture::createFromDrawableTexture): More of the same.
+        (WebCore::WebGPUTexture::create): Ditto.
+        (WebCore::WebGPUTexture::WebGPUTexture): Ditto.
+        * html/canvas/WebGPUTexture.h: Ditto.
+
+        * html/canvas/WebGPUTextureDescriptor.cpp:
+        (WebCore::WebGPUTextureDescriptor::create): More of the same.
+        (WebCore::WebGPUTextureDescriptor::WebGPUTextureDescriptor): Ditto.
+        (WebCore::WebGPUTextureDescriptor::width const): Ditto.
+        (WebCore::WebGPUTextureDescriptor::setWidth): Ditto.
+        (WebCore::WebGPUTextureDescriptor::height const): Ditto.
+        (WebCore::WebGPUTextureDescriptor::setHeight): Ditto.
+        (WebCore::WebGPUTextureDescriptor::sampleCount const): Ditto.
+        (WebCore::WebGPUTextureDescriptor::setSampleCount): Ditto.
+        (WebCore::WebGPUTextureDescriptor::textureType const): Ditto.
+        (WebCore::WebGPUTextureDescriptor::setTextureType): Ditto.
+        (WebCore::WebGPUTextureDescriptor::storageMode const): Ditto.
+        (WebCore::WebGPUTextureDescriptor::setStorageMode): Ditto.
+        (WebCore::WebGPUTextureDescriptor::usage const): Ditto.
+        (WebCore::WebGPUTextureDescriptor::setUsage): Ditto.
+        * html/canvas/WebGPUTextureDescriptor.h: Ditto.
+
+        * platform/graphics/metal/GPUBufferMetal.mm: Moved from "cocoa" directory.
+        (WebCore::GPUBuffer::GPUBuffer): Simplify code using references and the
+        "metal" naming.
+
+        * platform/graphics/metal/GPUCommandBufferMetal.mm:
+        (WebCore::GPUCommandBuffer::GPUCommandBuffer): Take a function to be called as the
+        completed handler and set it up.
+        (WebCore::GPUCommandBuffer::presentDrawable const): Ditto.
+        (WebCore::GPUCommandBuffer::commit const): Ditto.
+        (WebCore::GPUCommandBuffer::addCompletedHandler): Deleted.
+
+        * platform/graphics/metal/GPUCommandQueueMetal.mm:
+        (WebCore::GPUCommandQueue::GPUCommandQueue): Ditto. Also rewrote label handling a bit.
+        (WebCore::GPUCommandQueue::label const): Ditto.
+        (WebCore::GPUCommandQueue::setLabel const): Ditto.
+
+        * platform/graphics/metal/GPUComputeCommandEncoderMetal.mm:
+        (WebCore::GPUComputeCommandEncoder::GPUComputeCommandEncoder): Ditto.
+        (WebCore::GPUComputeCommandEncoder::setComputePipelineState const): Ditto.
+        (WebCore::GPUComputeCommandEncoder::setBuffer const): Ditto.
+        (WebCore::GPUComputeCommandEncoder::dispatch const): Ditto.
+        (WebCore::GPUComputeCommandEncoder::endEncoding const): Ditto.
+
+        * platform/graphics/metal/GPUComputePipelineStateMetal.mm:
+        (WebCore::GPUComputePipelineState::GPUComputePipelineState): Ditto.
+
+        * platform/graphics/metal/GPUDepthStencilDescriptorMetal.mm:
+        (WebCore::GPUDepthStencilDescriptor::GPUDepthStencilDescriptor): Ditto.
+        (WebCore::GPUDepthStencilDescriptor::depthWriteEnabled const): Ditto.
+        (WebCore::GPUDepthStencilDescriptor::setDepthWriteEnabled const): Ditto.
+        (WebCore::GPUDepthStencilDescriptor::depthCompareFunction const): Ditto.
+        (WebCore::GPUDepthStencilDescriptor::setDepthCompareFunction const): Ditto.
+
+        * platform/graphics/metal/GPUDepthStencilStateMetal.mm:
+        (WebCore::GPUDepthStencilState::GPUDepthStencilState): Ditto.
+        (WebCore::GPUDepthStencilState::label const): Ditto.
+        (WebCore::GPUDepthStencilState::setLabel const): Ditto. This is one of the
+        functions that was calling a method that does not exist. Added a comment.
+
+        * platform/graphics/metal/GPUDeviceMetal.mm:
+        (WebCore::GPUDevice::GPUDevice): Ditto. Also fixed two storage leaks where
+        we neglected to do adoptNS on the result of MTLCreateSystemDefaultDevice and
+        on the result of -[[WebGPULayer alloc] initWithGPUDevice:].
+        (WebCore::GPUDevice::reshape const): Ditto.
+        (WebCore::GPUDevice::platformLayer const): Ditto.
+        (WebCore::GPUDevice::operator! const): Ditto.
+
+        * platform/graphics/metal/GPUDrawableMetal.mm:
+        (WebCore::GPUDrawable::GPUDrawable): Ditto.
+        (WebCore::GPUDrawable::release): Ditto.
+        (WebCore::GPUDrawable::metal const): Ditto.
+        (WebCore::GPUDrawable::texture const): Ditto.
+
+        * platform/graphics/metal/GPUFunctionMetal.mm:
+        (WebCore::GPUFunction::GPUFunction): Ditto.
+        (WebCore::GPUFunction::name const): Ditto.
+        (WebCore::GPUFunction::metal const): Ditto.
+        (WebCore::GPUFunction::operator! const): Ditto.
+
+        * platform/graphics/metal/GPULibraryMetal.mm:
+        (WebCore::GPULibrary::GPULibrary): Ditto.
+        (WebCore::GPULibrary::label const): Ditto.
+        (WebCore::GPULibrary::setLabel const): Ditto.
+        (WebCore::GPULibrary::functionNames const): Ditto.
+        (WebCore::GPULibrary::metal const): Ditto.
+
+        * platform/graphics/metal/GPURenderCommandEncoderMetal.mm:
+        (WebCore::GPURenderCommandEncoder::GPURenderCommandEncoder): Ditto.
+        (WebCore::GPURenderCommandEncoder::setRenderPipelineState const): Ditto.
+        (WebCore::GPURenderCommandEncoder::setDepthStencilState const): Ditto.
+        (WebCore::GPURenderCommandEncoder::setVertexBuffer const): Ditto.
+        (WebCore::GPURenderCommandEncoder::setFragmentBuffer const): Ditto.
+        (WebCore::GPURenderCommandEncoder::drawPrimitives const): Ditto.
+        (WebCore::GPURenderCommandEncoder::endEncoding const): Ditto.
+
+        * platform/graphics/metal/GPURenderPassAttachmentDescriptorMetal.mm:
+        (WebCore::GPURenderPassAttachmentDescriptor::GPURenderPassAttachmentDescriptor): Ditto.
+        (WebCore::GPURenderPassAttachmentDescriptor::loadAction const): Ditto.
+        (WebCore::GPURenderPassAttachmentDescriptor::setLoadAction const): Ditto.
+        (WebCore::GPURenderPassAttachmentDescriptor::storeAction const): Ditto.
+        (WebCore::GPURenderPassAttachmentDescriptor::setStoreAction const): Ditto.
+        (WebCore::GPURenderPassAttachmentDescriptor::setTexture const): Ditto.
+
+        * platform/graphics/metal/GPURenderPassColorAttachmentDescriptorMetal.mm:
+        (WebCore::GPURenderPassColorAttachmentDescriptor::GPURenderPassColorAttachmentDescriptor): Ditto.
+        (WebCore::GPURenderPassColorAttachmentDescriptor::clearColor const): Ditto.
+        (WebCore::GPURenderPassColorAttachmentDescriptor::setClearColor const): Ditto.
+        (WebCore::GPURenderPassColorAttachmentDescriptor::metal const): Ditto.
+
+        * platform/graphics/metal/GPURenderPassDepthAttachmentDescriptorMetal.mm:
+        (WebCore::GPURenderPassDepthAttachmentDescriptor::GPURenderPassDepthAttachmentDescriptor): Ditto.
+        (WebCore::GPURenderPassDepthAttachmentDescriptor::clearDepth const): Ditto.
+        (WebCore::GPURenderPassDepthAttachmentDescriptor::setClearDepth const): Ditto.
+        (WebCore::GPURenderPassDepthAttachmentDescriptor::metal const): Ditto.
+
+        * platform/graphics/metal/GPURenderPassDescriptorMetal.mm:
+        (WebCore::GPURenderPassDescriptor::GPURenderPassDescriptor): Ditto.
+        (WebCore::GPURenderPassDescriptor::colorAttachments const): Ditto.
+        (WebCore::GPURenderPassDescriptor::depthAttachment const): Ditto.
+        (WebCore::GPURenderPassDescriptor::metal const): Ditto.
+
+        * platform/graphics/metal/GPURenderPipelineColorAttachmentDescriptorMetal.mm:
+        (WebCore::GPURenderPipelineColorAttachmentDescriptor::GPURenderPipelineColorAttachmentDescriptor): Ditto.
+        (WebCore::GPURenderPipelineColorAttachmentDescriptor::pixelFormat const): Ditto.
+        (WebCore::GPURenderPipelineColorAttachmentDescriptor::setPixelFormat const): Ditto.
+        (WebCore::GPURenderPipelineColorAttachmentDescriptor::metal const): Ditto.
+
+        * platform/graphics/metal/GPURenderPipelineDescriptorMetal.mm:
+        (WebCore::GPURenderPipelineDescriptor::GPURenderPipelineDescriptor): Ditto.
+        (WebCore::GPURenderPipelineDescriptor::depthAttachmentPixelFormat const): Ditto.
+        (WebCore::GPURenderPipelineDescriptor::setDepthAttachmentPixelFormat const): Ditto.
+        (WebCore::GPURenderPipelineDescriptor::setVertexFunction const): Ditto.
+        (WebCore::GPURenderPipelineDescriptor::setFragmentFunction const): Ditto.
+        (WebCore::GPURenderPipelineDescriptor::colorAttachments const): Ditto.
+        (WebCore::GPURenderPipelineDescriptor::reset const): Ditto.
+        (WebCore::GPURenderPipelineDescriptor::metal const): Ditto.
+
+        * platform/graphics/metal/GPURenderPipelineStateMetal.mm:
+        (WebCore::GPURenderPipelineState::GPURenderPipelineState): Ditto.
+        (WebCore::GPURenderPipelineState::label const): Ditto.
+        (WebCore::GPURenderPipelineState::setLabel const): Ditto. This is one of the
+        functions that was calling a method that does not exist. Added a comment.
+        (WebCore::GPURenderPipelineState::metal const): Ditto.
+
+        * platform/graphics/metal/GPUTextureDescriptorMetal.mm:
+        (WebCore::GPUTextureDescriptor::GPUTextureDescriptor): Ditto.
+        (WebCore::GPUTextureDescriptor::width const): Ditto.
+        (WebCore::GPUTextureDescriptor::setWidth const): Ditto.
+        (WebCore::GPUTextureDescriptor::height const): Ditto.
+        (WebCore::GPUTextureDescriptor::setHeight const): Ditto.
+        (WebCore::GPUTextureDescriptor::sampleCount const): Ditto.
+        (WebCore::GPUTextureDescriptor::setSampleCount const): Ditto.
+        (WebCore::GPUTextureDescriptor::textureType const): Ditto.
+        (WebCore::GPUTextureDescriptor::setTextureType const): Ditto.
+        (WebCore::GPUTextureDescriptor::storageMode const): Ditto.
+        (WebCore::GPUTextureDescriptor::setStorageMode const): Ditto.
+        (WebCore::GPUTextureDescriptor::usage const): Ditto.
+        (WebCore::GPUTextureDescriptor::setUsage const): Ditto.
+        (WebCore::GPUTextureDescriptor::metal const): Ditto.
+
+        * platform/graphics/metal/GPUTextureMetal.mm:
+        (WebCore::GPUTexture::GPUTexture): Ditto.
+        (WebCore::GPUTexture::width const): Ditto.
+        (WebCore::GPUTexture::height const): Ditto.
+        (WebCore::GPUTexture::metal const): Ditto.
+
+        * platform/graphics/gpu/GPUBuffer.cpp: Removed unused stubs.
+        (WebCore::GPUBuffer::length const): Moved this function here since it has
+        a useful platform-independent implementation.
+
+        * platform/graphics/gpu/GPUBuffer.h: Use OBJC_PROTOCOL for MTLBuffer.
+        Did the other thigs mentioned above: USE(METAL), remove WEBCORE_EXPORT,
+        no longer be RefCounted, etc.
+
+        * platform/graphics/gpu/GPUCommandBuffer.cpp: Ditto.
+        * platform/graphics/gpu/GPUCommandBuffer.h: Ditto. Use OBJC_PROTOCOL
+        for MTLCommandBuffer.
+
+        * platform/graphics/gpu/GPUCommandQueue.cpp: Ditto.
+        * platform/graphics/gpu/GPUCommandQueue.h: Ditto. Use OBJC_PROTOCOL for
+        MTLCommandQueue.
+
+        * platform/graphics/gpu/GPUComputeCommandEncoder.cpp: Ditto.
+        * platform/graphics/gpu/GPUComputeCommandEncoder.h: Ditto. Use OBJC_PROTOCOL for
+        MTLComputeCommandEncoder.
+
+        * platform/graphics/gpu/GPUComputePipelineState.cpp: Ditto.
+        * platform/graphics/gpu/GPUComputePipelineState.h: Ditto. Use OBJC_PROTOCOL for
+        MTLComputePipelineState.
+
+        * platform/graphics/gpu/GPUDepthStencilDescriptor.cpp: Ditto.
+        * platform/graphics/gpu/GPUDepthStencilDescriptor.h: Ditto.
+
+        * platform/graphics/gpu/GPUDepthStencilState.cpp: Ditto.
+        * platform/graphics/gpu/GPUDepthStencilState.h: Ditto. Use OBJC_PROTOCOL for
+        MTLDepthStencilState.
+
+        * platform/graphics/gpu/GPUDevice.cpp: Ditto.
+        * platform/graphics/gpu/GPUDevice.h: Ditto. Use OBJC_PROTOCOL for MTLDevice.
+
+        * platform/graphics/gpu/GPUDrawable.cpp: Ditto.
+        * platform/graphics/gpu/GPUDrawable.h: Ditto. Use OBJC_PROTOCOL for
+        MTLDrawable and MTLTexture.
+
+        * platform/graphics/gpu/GPUEnums.h: Tweaked formatting.
+
+        * platform/graphics/gpu/GPUFunction.cpp: Ditto.
+        * platform/graphics/gpu/GPUFunction.h: Ditto. Use OBJC_PROTOCOL for
+        MTLFunction.
+
+        * platform/graphics/gpu/GPULibrary.cpp: Ditto.
+        * platform/graphics/gpu/GPULibrary.h: Ditto. Use OBJC_PROTOCOL for
+        MTLLibrary.
+
+        * platform/graphics/gpu/GPURenderCommandEncoder.cpp: Ditto.
+        * platform/graphics/gpu/GPURenderCommandEncoder.h: Ditto.
+        Use OBJC_PROTOCOL for MTLRenderCommandEncoder.
+
+        * platform/graphics/gpu/GPURenderPassAttachmentDescriptor.cpp: Ditto.
+        * platform/graphics/gpu/GPURenderPassAttachmentDescriptor.h: Ditto.
+
+        * platform/graphics/gpu/GPURenderPassColorAttachmentDescriptor.cpp: Ditto.
+        * platform/graphics/gpu/GPURenderPassColorAttachmentDescriptor.h: Ditto.
+
+        * platform/graphics/gpu/GPURenderPassDepthAttachmentDescriptor.cpp: Ditto.
+        * platform/graphics/gpu/GPURenderPassDepthAttachmentDescriptor.h: Ditto.
+
+        * platform/graphics/gpu/GPURenderPassDescriptor.cpp: Ditto.
+        * platform/graphics/gpu/GPURenderPassDescriptor.h: Ditto.
+
+        * platform/graphics/gpu/GPURenderPipelineColorAttachmentDescriptor.cpp: Ditto.
+        * platform/graphics/gpu/GPURenderPipelineColorAttachmentDescriptor.h: Ditto.
+
+        * platform/graphics/gpu/GPURenderPipelineDescriptor.cpp: Ditto.
+        * platform/graphics/gpu/GPURenderPipelineDescriptor.h: Ditto.
+
+        * platform/graphics/gpu/GPURenderPipelineState.cpp: Ditto.
+        * platform/graphics/gpu/GPURenderPipelineState.h: Ditto. Use OBJC_PROTOCOL
+        for MTLRenderPipelineState.
+
+        * platform/graphics/gpu/GPUSize.h: Use "unsigned" instead of "unsigned long".
+
+        * platform/graphics/gpu/GPUTexture.cpp: Ditto.
+        * platform/graphics/gpu/GPUTexture.h: Ditto. Use OBJC_PROTOCOL for
+        MTLTexture.
+
+        * platform/graphics/gpu/GPUTextureDescriptor.cpp: Ditto.
+        * platform/graphics/gpu/GPUTextureDescriptor.h: Ditto.
+
 2018-07-26  Zalan Bujtas  <zalan@apple.com>
 
         [LFC][Floating] Add skeleton for basic positioning.
index 80520ab..f3d8d02 100644 (file)
@@ -293,27 +293,6 @@ list(APPEND WebCore_SOURCES
     platform/graphics/cg/TransformationMatrixCG.cpp
     platform/graphics/cg/UTIRegistry.cpp
 
-    platform/graphics/cocoa/GPUBufferMetal.mm
-    platform/graphics/cocoa/GPUCommandBufferMetal.mm
-    platform/graphics/cocoa/GPUCommandQueueMetal.mm
-    platform/graphics/cocoa/GPUComputeCommandEncoderMetal.mm
-    platform/graphics/cocoa/GPUComputePipelineStateMetal.mm
-    platform/graphics/cocoa/GPUDepthStencilDescriptorMetal.mm
-    platform/graphics/cocoa/GPUDepthStencilStateMetal.mm
-    platform/graphics/cocoa/GPUDeviceMetal.mm
-    platform/graphics/cocoa/GPUDrawableMetal.mm
-    platform/graphics/cocoa/GPUFunctionMetal.mm
-    platform/graphics/cocoa/GPULibraryMetal.mm
-    platform/graphics/cocoa/GPURenderCommandEncoderMetal.mm
-    platform/graphics/cocoa/GPURenderPassAttachmentDescriptorMetal.mm
-    platform/graphics/cocoa/GPURenderPassColorAttachmentDescriptorMetal.mm
-    platform/graphics/cocoa/GPURenderPassDepthAttachmentDescriptorMetal.mm
-    platform/graphics/cocoa/GPURenderPassDescriptorMetal.mm
-    platform/graphics/cocoa/GPURenderPipelineColorAttachmentDescriptorMetal.mm
-    platform/graphics/cocoa/GPURenderPipelineDescriptorMetal.mm
-    platform/graphics/cocoa/GPURenderPipelineStateMetal.mm
-    platform/graphics/cocoa/GPUTextureDescriptorMetal.mm
-    platform/graphics/cocoa/GPUTextureMetal.mm
     platform/graphics/cocoa/GraphicsContext3DCocoa.mm
     platform/graphics/cocoa/GraphicsContextCocoa.mm
     platform/graphics/cocoa/FontCacheCoreText.cpp
@@ -357,6 +336,28 @@ list(APPEND WebCore_SOURCES
     platform/graphics/mac/SimpleFontDataCoreText.cpp
     platform/graphics/mac/WebLayer.mm
 
+    platform/graphics/metal/GPUBufferMetal.mm
+    platform/graphics/metal/GPUCommandBufferMetal.mm
+    platform/graphics/metal/GPUCommandQueueMetal.mm
+    platform/graphics/metal/GPUComputeCommandEncoderMetal.mm
+    platform/graphics/metal/GPUComputePipelineStateMetal.mm
+    platform/graphics/metal/GPUDepthStencilDescriptorMetal.mm
+    platform/graphics/metal/GPUDepthStencilStateMetal.mm
+    platform/graphics/metal/GPUDeviceMetal.mm
+    platform/graphics/metal/GPUDrawableMetal.mm
+    platform/graphics/metal/GPUFunctionMetal.mm
+    platform/graphics/metal/GPULibraryMetal.mm
+    platform/graphics/metal/GPURenderCommandEncoderMetal.mm
+    platform/graphics/metal/GPURenderPassAttachmentDescriptorMetal.mm
+    platform/graphics/metal/GPURenderPassColorAttachmentDescriptorMetal.mm
+    platform/graphics/metal/GPURenderPassDepthAttachmentDescriptorMetal.mm
+    platform/graphics/metal/GPURenderPassDescriptorMetal.mm
+    platform/graphics/metal/GPURenderPipelineColorAttachmentDescriptorMetal.mm
+    platform/graphics/metal/GPURenderPipelineDescriptorMetal.mm
+    platform/graphics/metal/GPURenderPipelineStateMetal.mm
+    platform/graphics/metal/GPUTextureDescriptorMetal.mm
+    platform/graphics/metal/GPUTextureMetal.mm
+
     platform/graphics/opengl/Extensions3DOpenGL.cpp
     platform/graphics/opengl/Extensions3DOpenGLCommon.cpp
     platform/graphics/opengl/GraphicsContext3DOpenGL.cpp
index f0b8e94..e352e53 100644 (file)
@@ -292,27 +292,6 @@ platform/graphics/cg/SubimageCacheWithTimer.cpp
 platform/graphics/cg/TransformationMatrixCG.cpp
 platform/graphics/cg/UTIRegistry.cpp
 
-platform/graphics/cocoa/GPUBufferMetal.mm
-platform/graphics/cocoa/GPUCommandBufferMetal.mm
-platform/graphics/cocoa/GPUCommandQueueMetal.mm
-platform/graphics/cocoa/GPUComputeCommandEncoderMetal.mm
-platform/graphics/cocoa/GPUComputePipelineStateMetal.mm
-platform/graphics/cocoa/GPUDepthStencilDescriptorMetal.mm
-platform/graphics/cocoa/GPUDepthStencilStateMetal.mm
-platform/graphics/cocoa/GPUDeviceMetal.mm
-platform/graphics/cocoa/GPUDrawableMetal.mm
-platform/graphics/cocoa/GPUFunctionMetal.mm
-platform/graphics/cocoa/GPULibraryMetal.mm
-platform/graphics/cocoa/GPURenderCommandEncoderMetal.mm
-platform/graphics/cocoa/GPURenderPassAttachmentDescriptorMetal.mm
-platform/graphics/cocoa/GPURenderPassColorAttachmentDescriptorMetal.mm
-platform/graphics/cocoa/GPURenderPassDepthAttachmentDescriptorMetal.mm
-platform/graphics/cocoa/GPURenderPassDescriptorMetal.mm
-platform/graphics/cocoa/GPURenderPipelineColorAttachmentDescriptorMetal.mm
-platform/graphics/cocoa/GPURenderPipelineDescriptorMetal.mm
-platform/graphics/cocoa/GPURenderPipelineStateMetal.mm
-platform/graphics/cocoa/GPUTextureDescriptorMetal.mm
-platform/graphics/cocoa/GPUTextureMetal.mm
 platform/graphics/cocoa/GraphicsContext3DCocoa.mm
 platform/graphics/cocoa/GraphicsContextCocoa.mm
 platform/graphics/cocoa/FontCacheCoreText.cpp
@@ -360,6 +339,28 @@ platform/graphics/mac/SimpleFontDataCoreText.cpp
 platform/graphics/mac/WebLayer.mm
 platform/graphics/mac/WebKitNSImageExtras.mm
 
+platform/graphics/metal/GPUBufferMetal.mm
+platform/graphics/metal/GPUCommandBufferMetal.mm
+platform/graphics/metal/GPUCommandQueueMetal.mm
+platform/graphics/metal/GPUComputeCommandEncoderMetal.mm
+platform/graphics/metal/GPUComputePipelineStateMetal.mm
+platform/graphics/metal/GPUDepthStencilDescriptorMetal.mm
+platform/graphics/metal/GPUDepthStencilStateMetal.mm
+platform/graphics/metal/GPUDeviceMetal.mm
+platform/graphics/metal/GPUDrawableMetal.mm
+platform/graphics/metal/GPUFunctionMetal.mm
+platform/graphics/metal/GPULibraryMetal.mm
+platform/graphics/metal/GPURenderCommandEncoderMetal.mm
+platform/graphics/metal/GPURenderPassAttachmentDescriptorMetal.mm
+platform/graphics/metal/GPURenderPassColorAttachmentDescriptorMetal.mm
+platform/graphics/metal/GPURenderPassDepthAttachmentDescriptorMetal.mm
+platform/graphics/metal/GPURenderPassDescriptorMetal.mm
+platform/graphics/metal/GPURenderPipelineColorAttachmentDescriptorMetal.mm
+platform/graphics/metal/GPURenderPipelineDescriptorMetal.mm
+platform/graphics/metal/GPURenderPipelineStateMetal.mm
+platform/graphics/metal/GPUTextureDescriptorMetal.mm
+platform/graphics/metal/GPUTextureMetal.mm
+
 platform/graphics/opengl/Extensions3DOpenGL.cpp
 platform/graphics/opengl/Extensions3DOpenGLCommon.cpp
 platform/graphics/opengl/GraphicsContext3DOpenGL.cpp
index 49206e4..fc1fa1d 100644 (file)
                316BDB951E70C89700DE0D5A /* GPUFunction.h in Headers */ = {isa = PBXBuildFile; fileRef = 316BDB931E70C89700DE0D5A /* GPUFunction.h */; settings = {ATTRIBUTES = (Private, ); }; };
                316BDB9B1E70CBBF00DE0D5A /* GPULibrary.h in Headers */ = {isa = PBXBuildFile; fileRef = 316BDB991E70CBBF00DE0D5A /* GPULibrary.h */; settings = {ATTRIBUTES = (Private, ); }; };
                316BDBAA1E71FA9300DE0D5A /* GPUBuffer.h in Headers */ = {isa = PBXBuildFile; fileRef = 316BDBA81E71FA9300DE0D5A /* GPUBuffer.h */; settings = {ATTRIBUTES = (Private, ); }; };
-               316BDBB21E7354BB00DE0D5A /* GPUTexture.h in Headers */ = {isa = PBXBuildFile; fileRef = 316BDBB01E7354BB00DE0D5A /* GPUTexture.h */; settings = {ATTRIBUTES = (Private, ); }; };
-               316BDBB81E7357CB00DE0D5A /* GPUTextureDescriptor.h in Headers */ = {isa = PBXBuildFile; fileRef = 316BDBB61E7357CB00DE0D5A /* GPUTextureDescriptor.h */; settings = {ATTRIBUTES = (Private, ); }; };
+               316BDBB21E7354BB00DE0D5A /* GPUTexture.h in Headers */ = {isa = PBXBuildFile; fileRef = 316BDBB01E7354BB00DE0D5A /* GPUTexture.h */; };
+               316BDBB81E7357CB00DE0D5A /* GPUTextureDescriptor.h in Headers */ = {isa = PBXBuildFile; fileRef = 316BDBB61E7357CB00DE0D5A /* GPUTextureDescriptor.h */; };
                316BDBBC1E73880600DE0D5A /* GPUCommandQueue.h in Headers */ = {isa = PBXBuildFile; fileRef = 316BDBBA1E73880600DE0D5A /* GPUCommandQueue.h */; settings = {ATTRIBUTES = (Private, ); }; };
-               316BDBCD1E75F18400DE0D5A /* GPUDrawable.h in Headers */ = {isa = PBXBuildFile; fileRef = 316BDBCB1E75F17600DE0D5A /* GPUDrawable.h */; settings = {ATTRIBUTES = (Private, ); }; };
-               316BDBCE1E75F18A00DE0D5A /* GPUCommandBuffer.h in Headers */ = {isa = PBXBuildFile; fileRef = 316BDBC51E75EE2400DE0D5A /* GPUCommandBuffer.h */; settings = {ATTRIBUTES = (Private, ); }; };
-               316BDBD31E75F7B600DE0D5A /* GPURenderPassDescriptor.h in Headers */ = {isa = PBXBuildFile; fileRef = 316BDBD11E75F7AE00DE0D5A /* GPURenderPassDescriptor.h */; settings = {ATTRIBUTES = (Private, ); }; };
-               316BDBDB1E7612E200DE0D5A /* GPURenderPassColorAttachmentDescriptor.h in Headers */ = {isa = PBXBuildFile; fileRef = 316BDBD91E7612DB00DE0D5A /* GPURenderPassColorAttachmentDescriptor.h */; settings = {ATTRIBUTES = (Private, ); }; };
+               316BDBCD1E75F18400DE0D5A /* GPUDrawable.h in Headers */ = {isa = PBXBuildFile; fileRef = 316BDBCB1E75F17600DE0D5A /* GPUDrawable.h */; };
+               316BDBCE1E75F18A00DE0D5A /* GPUCommandBuffer.h in Headers */ = {isa = PBXBuildFile; fileRef = 316BDBC51E75EE2400DE0D5A /* GPUCommandBuffer.h */; };
+               316BDBD31E75F7B600DE0D5A /* GPURenderPassDescriptor.h in Headers */ = {isa = PBXBuildFile; fileRef = 316BDBD11E75F7AE00DE0D5A /* GPURenderPassDescriptor.h */; };
+               316BDBDB1E7612E200DE0D5A /* GPURenderPassColorAttachmentDescriptor.h in Headers */ = {isa = PBXBuildFile; fileRef = 316BDBD91E7612DB00DE0D5A /* GPURenderPassColorAttachmentDescriptor.h */; };
                316BDBDF1E76137500DE0D5A /* GPURenderPassAttachmentDescriptor.h in Headers */ = {isa = PBXBuildFile; fileRef = 316BDBDD1E76136C00DE0D5A /* GPURenderPassAttachmentDescriptor.h */; };
-               316BDBE41E761F0500DE0D5A /* GPURenderPassDepthAttachmentDescriptor.h in Headers */ = {isa = PBXBuildFile; fileRef = 316BDBE31E761EFF00DE0D5A /* GPURenderPassDepthAttachmentDescriptor.h */; settings = {ATTRIBUTES = (Private, ); }; };
-               316BDBEB1E76244D00DE0D5A /* GPURenderCommandEncoder.h in Headers */ = {isa = PBXBuildFile; fileRef = 316BDBE91E76244400DE0D5A /* GPURenderCommandEncoder.h */; settings = {ATTRIBUTES = (Private, ); }; };
-               316BDBF01E76292000DE0D5A /* GPUDepthStencilState.h in Headers */ = {isa = PBXBuildFile; fileRef = 316BDBEF1E76291B00DE0D5A /* GPUDepthStencilState.h */; settings = {ATTRIBUTES = (Private, ); }; };
-               316BDBF71E762AD500DE0D5A /* GPUDepthStencilDescriptor.h in Headers */ = {isa = PBXBuildFile; fileRef = 316BDBF51E762ACD00DE0D5A /* GPUDepthStencilDescriptor.h */; settings = {ATTRIBUTES = (Private, ); }; };
-               316BDBFB1E762D0400DE0D5A /* GPUEnums.h in Headers */ = {isa = PBXBuildFile; fileRef = 316BDBFA1E762D0400DE0D5A /* GPUEnums.h */; settings = {ATTRIBUTES = (Private, ); }; };
-               316BDC021E762F6400DE0D5A /* GPURenderPipelineDescriptor.h in Headers */ = {isa = PBXBuildFile; fileRef = 316BDBFD1E762F5700DE0D5A /* GPURenderPipelineDescriptor.h */; settings = {ATTRIBUTES = (Private, ); }; };
-               316BDC031E762F6900DE0D5A /* GPURenderPipelineState.h in Headers */ = {isa = PBXBuildFile; fileRef = 316BDBFF1E762F5700DE0D5A /* GPURenderPipelineState.h */; settings = {ATTRIBUTES = (Private, ); }; };
-               316BDC0D1E7634D200DE0D5A /* GPURenderPipelineColorAttachmentDescriptor.h in Headers */ = {isa = PBXBuildFile; fileRef = 316BDC091E76342700DE0D5A /* GPURenderPipelineColorAttachmentDescriptor.h */; settings = {ATTRIBUTES = (Private, ); }; };
+               316BDBE41E761F0500DE0D5A /* GPURenderPassDepthAttachmentDescriptor.h in Headers */ = {isa = PBXBuildFile; fileRef = 316BDBE31E761EFF00DE0D5A /* GPURenderPassDepthAttachmentDescriptor.h */; };
+               316BDBEB1E76244D00DE0D5A /* GPURenderCommandEncoder.h in Headers */ = {isa = PBXBuildFile; fileRef = 316BDBE91E76244400DE0D5A /* GPURenderCommandEncoder.h */; };
+               316BDBF01E76292000DE0D5A /* GPUDepthStencilState.h in Headers */ = {isa = PBXBuildFile; fileRef = 316BDBEF1E76291B00DE0D5A /* GPUDepthStencilState.h */; };
+               316BDBF71E762AD500DE0D5A /* GPUDepthStencilDescriptor.h in Headers */ = {isa = PBXBuildFile; fileRef = 316BDBF51E762ACD00DE0D5A /* GPUDepthStencilDescriptor.h */; };
+               316BDBFB1E762D0400DE0D5A /* GPUEnums.h in Headers */ = {isa = PBXBuildFile; fileRef = 316BDBFA1E762D0400DE0D5A /* GPUEnums.h */; };
+               316BDC021E762F6400DE0D5A /* GPURenderPipelineDescriptor.h in Headers */ = {isa = PBXBuildFile; fileRef = 316BDBFD1E762F5700DE0D5A /* GPURenderPipelineDescriptor.h */; };
+               316BDC031E762F6900DE0D5A /* GPURenderPipelineState.h in Headers */ = {isa = PBXBuildFile; fileRef = 316BDBFF1E762F5700DE0D5A /* GPURenderPipelineState.h */; };
+               316BDC0D1E7634D200DE0D5A /* GPURenderPipelineColorAttachmentDescriptor.h in Headers */ = {isa = PBXBuildFile; fileRef = 316BDC091E76342700DE0D5A /* GPURenderPipelineColorAttachmentDescriptor.h */; };
                316DCB201E78CA55001B5F87 /* JSRTCOfferAnswerOptions.h in Headers */ = {isa = PBXBuildFile; fileRef = 316DCB1A1E78CA55001B5F87 /* JSRTCOfferAnswerOptions.h */; };
                316DCB221E78CA55001B5F87 /* JSRTCRtpTransceiverDirection.h in Headers */ = {isa = PBXBuildFile; fileRef = 316DCB1C1E78CA55001B5F87 /* JSRTCRtpTransceiverDirection.h */; };
                316DCB4C1E7910A6001B5F87 /* JSRTCIceConnectionState.h in Headers */ = {isa = PBXBuildFile; fileRef = 316DCB461E7910A6001B5F87 /* JSRTCIceConnectionState.h */; };
                93A806171E03B51C008A1F26 /* LongRange.h in Headers */ = {isa = PBXBuildFile; fileRef = 93A806131E03B51C008A1F26 /* LongRange.h */; settings = {ATTRIBUTES = (Private, ); }; };
                93A8061E1E03B585008A1F26 /* JSDoubleRange.h in Headers */ = {isa = PBXBuildFile; fileRef = 93A8061A1E03B585008A1F26 /* JSDoubleRange.h */; };
                93A806201E03B585008A1F26 /* JSLongRange.h in Headers */ = {isa = PBXBuildFile; fileRef = 93A8061C1E03B585008A1F26 /* JSLongRange.h */; };
+               93A953B020EBD3C900A619F6 /* GPUComputePipelineState.h in Headers */ = {isa = PBXBuildFile; fileRef = 381E35EC1E8E23E40043E850 /* GPUComputePipelineState.h */; };
+               93A953B420EBD43200A619F6 /* GPUComputeCommandEncoder.h in Headers */ = {isa = PBXBuildFile; fileRef = 381E35EA1E8E20D90043E850 /* GPUComputeCommandEncoder.h */; };
+               93A953B520EC9C3F00A619F6 /* GPUSize.h in Headers */ = {isa = PBXBuildFile; fileRef = 381E35F61E8E4D0E0043E850 /* GPUSize.h */; };
                93B2D8160F9920D2006AE6B2 /* SuddenTermination.h in Headers */ = {isa = PBXBuildFile; fileRef = 93B2D8150F9920D2006AE6B2 /* SuddenTermination.h */; settings = {ATTRIBUTES = (Private, ); }; };
                93B6A0E60B0BCA5C00F5027A /* ContextMenu.h in Headers */ = {isa = PBXBuildFile; fileRef = 93B6A0E50B0BCA5C00F5027A /* ContextMenu.h */; settings = {ATTRIBUTES = (Private, ); }; };
                93B70D6409EB0C7C009D8468 /* JSDOMBinding.h in Headers */ = {isa = PBXBuildFile; fileRef = 93B70D4809EB0C7C009D8468 /* JSDOMBinding.h */; settings = {ATTRIBUTES = (Private, ); }; };
                0FDF45A81BD1C82500E4FA8C /* TimingFunction.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TimingFunction.cpp; sourceTree = "<group>"; };
                0FE5806119327A6200DE32EB /* ScrollingTreeMac.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ScrollingTreeMac.cpp; sourceTree = "<group>"; };
                0FE5806219327A6200DE32EB /* ScrollingTreeMac.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScrollingTreeMac.h; sourceTree = "<group>"; };
-               0FE5FBCA1C3DD51E0007A2CA /* DisplayList.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = DisplayList.cpp; path = displaylists/DisplayList.cpp; sourceTree = "<group>"; };
-               0FE5FBCB1C3DD51E0007A2CA /* DisplayList.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DisplayList.h; path = displaylists/DisplayList.h; sourceTree = "<group>"; };
-               0FE5FBCC1C3DD51E0007A2CA /* DisplayListItems.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = DisplayListItems.cpp; path = displaylists/DisplayListItems.cpp; sourceTree = "<group>"; };
-               0FE5FBCD1C3DD51E0007A2CA /* DisplayListItems.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DisplayListItems.h; path = displaylists/DisplayListItems.h; sourceTree = "<group>"; };
-               0FE5FBCE1C3DD51E0007A2CA /* DisplayListRecorder.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = DisplayListRecorder.cpp; path = displaylists/DisplayListRecorder.cpp; sourceTree = "<group>"; };
-               0FE5FBCF1C3DD51E0007A2CA /* DisplayListRecorder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DisplayListRecorder.h; path = displaylists/DisplayListRecorder.h; sourceTree = "<group>"; };
-               0FE5FBD01C3DD51E0007A2CA /* DisplayListReplayer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = DisplayListReplayer.cpp; path = displaylists/DisplayListReplayer.cpp; sourceTree = "<group>"; };
-               0FE5FBD11C3DD51E0007A2CA /* DisplayListReplayer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DisplayListReplayer.h; path = displaylists/DisplayListReplayer.h; sourceTree = "<group>"; };
+               0FE5FBCA1C3DD51E0007A2CA /* DisplayList.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DisplayList.cpp; sourceTree = "<group>"; };
+               0FE5FBCB1C3DD51E0007A2CA /* DisplayList.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DisplayList.h; sourceTree = "<group>"; };
+               0FE5FBCC1C3DD51E0007A2CA /* DisplayListItems.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DisplayListItems.cpp; sourceTree = "<group>"; };
+               0FE5FBCD1C3DD51E0007A2CA /* DisplayListItems.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DisplayListItems.h; sourceTree = "<group>"; };
+               0FE5FBCE1C3DD51E0007A2CA /* DisplayListRecorder.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DisplayListRecorder.cpp; sourceTree = "<group>"; };
+               0FE5FBCF1C3DD51E0007A2CA /* DisplayListRecorder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DisplayListRecorder.h; sourceTree = "<group>"; };
+               0FE5FBD01C3DD51E0007A2CA /* DisplayListReplayer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DisplayListReplayer.cpp; sourceTree = "<group>"; };
+               0FE5FBD11C3DD51E0007A2CA /* DisplayListReplayer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DisplayListReplayer.h; sourceTree = "<group>"; };
                0FE6C76B1FBFB7A60025C053 /* ColorUtilities.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = ColorUtilities.cpp; sourceTree = "<group>"; };
                0FE6C76C1FBFB7A60025C053 /* ColorUtilities.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ColorUtilities.h; sourceTree = "<group>"; };
                0FE71403142170B800DB33BA /* ScrollbarThemeMock.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ScrollbarThemeMock.cpp; sourceTree = "<group>"; };
                C280B3FD1EF4608900D35135 /* FontFamilySpecificationNull.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = FontFamilySpecificationNull.cpp; sourceTree = "<group>"; };
                C2AB0AF41E6B3C6C001348C5 /* FontSelectionAlgorithm.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = FontSelectionAlgorithm.cpp; sourceTree = "<group>"; };
                C2AB0AF51E6B3C6C001348C5 /* FontSelectionAlgorithm.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FontSelectionAlgorithm.h; sourceTree = "<group>"; };
-               C2AB0B021E6DE32B001348C5 /* FontSelectionKeywordValues.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FontSelectionKeywordValues.h; sourceTree = "<group>"; };
                C2AB0B031E6DE92C001348C5 /* FontSelectionValueInlines.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FontSelectionValueInlines.h; sourceTree = "<group>"; };
                C2C2CF551EF3761A004281A8 /* FontFamilySpecificationNull.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FontFamilySpecificationNull.h; sourceTree = "<group>"; };
                C2E38EFB1E8396FD00CA3ADF /* CSSFontStyleValue.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CSSFontStyleValue.cpp; sourceTree = "<group>"; };
                CD669D671D232E10004D1866 /* MediaSessionManagerMac.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MediaSessionManagerMac.h; sourceTree = "<group>"; };
                CD78A2EC1F75648600DE371B /* CDMInstanceFairPlayStreamingAVFObjC.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = CDMInstanceFairPlayStreamingAVFObjC.mm; sourceTree = "<group>"; };
                CD78A2EE1F75648600DE371B /* CDMInstanceFairPlayStreamingAVFObjC.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CDMInstanceFairPlayStreamingAVFObjC.h; sourceTree = "<group>"; };
-               CD7D33411C7A123F00041293 /* PixelBufferConformerCV.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = PixelBufferConformerCV.cpp; path = ../cv/PixelBufferConformerCV.cpp; sourceTree = "<group>"; };
-               CD7D33421C7A123F00041293 /* PixelBufferConformerCV.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = PixelBufferConformerCV.h; path = ../cv/PixelBufferConformerCV.h; sourceTree = "<group>"; };
+               CD7D33411C7A123F00041293 /* PixelBufferConformerCV.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PixelBufferConformerCV.cpp; sourceTree = "<group>"; };
+               CD7D33421C7A123F00041293 /* PixelBufferConformerCV.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PixelBufferConformerCV.h; sourceTree = "<group>"; };
                CD7D33451C7A16BF00041293 /* CoreVideoSoftLink.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CoreVideoSoftLink.cpp; sourceTree = "<group>"; };
                CD7D33461C7A16BF00041293 /* CoreVideoSoftLink.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CoreVideoSoftLink.h; sourceTree = "<group>"; };
                CD7DBB2618CA11FF00C11066 /* CSSGridLineNamesValue.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CSSGridLineNamesValue.cpp; sourceTree = "<group>"; };
                CD7DBB2718CA11FF00C11066 /* CSSGridLineNamesValue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CSSGridLineNamesValue.h; sourceTree = "<group>"; };
                CD7E05201651A84100C1201F /* WebCoreAVFResourceLoader.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WebCoreAVFResourceLoader.h; sourceTree = "<group>"; };
                CD7E05211651A84100C1201F /* WebCoreAVFResourceLoader.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = WebCoreAVFResourceLoader.mm; sourceTree = "<group>"; };
-               CD871C5C1FB52B6300F0B965 /* ISOSchemeTypeBox.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ISOSchemeTypeBox.h; path = platform/graphics/iso/ISOSchemeTypeBox.h; sourceTree = SOURCE_ROOT; };
-               CD871C5E1FB52B6400F0B965 /* ISOProtectionSchemeInfoBox.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ISOProtectionSchemeInfoBox.cpp; path = platform/graphics/iso/ISOProtectionSchemeInfoBox.cpp; sourceTree = SOURCE_ROOT; };
-               CD871C5F1FB52B6400F0B965 /* ISOSchemeTypeBox.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ISOSchemeTypeBox.cpp; path = platform/graphics/iso/ISOSchemeTypeBox.cpp; sourceTree = SOURCE_ROOT; };
-               CD871C601FB52B6500F0B965 /* ISOProtectionSchemeInfoBox.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ISOProtectionSchemeInfoBox.h; path = platform/graphics/iso/ISOProtectionSchemeInfoBox.h; sourceTree = SOURCE_ROOT; };
-               CD871C611FB52B6500F0B965 /* ISOTrackEncryptionBox.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ISOTrackEncryptionBox.cpp; path = platform/graphics/iso/ISOTrackEncryptionBox.cpp; sourceTree = SOURCE_ROOT; };
-               CD871C621FB52B6500F0B965 /* ISOBox.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ISOBox.h; path = platform/graphics/iso/ISOBox.h; sourceTree = SOURCE_ROOT; };
-               CD871C631FB52B6600F0B965 /* ISOSchemeInformationBox.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ISOSchemeInformationBox.cpp; path = platform/graphics/iso/ISOSchemeInformationBox.cpp; sourceTree = SOURCE_ROOT; };
-               CD871C641FB52B6700F0B965 /* ISOSchemeInformationBox.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ISOSchemeInformationBox.h; path = platform/graphics/iso/ISOSchemeInformationBox.h; sourceTree = SOURCE_ROOT; };
-               CD871C651FB52B6700F0B965 /* ISOVTTCue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ISOVTTCue.h; path = platform/graphics/iso/ISOVTTCue.h; sourceTree = SOURCE_ROOT; };
-               CD871C661FB52B6800F0B965 /* ISOTrackEncryptionBox.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ISOTrackEncryptionBox.h; path = platform/graphics/iso/ISOTrackEncryptionBox.h; sourceTree = SOURCE_ROOT; };
-               CD871C671FB52B6800F0B965 /* ISOOriginalFormatBox.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ISOOriginalFormatBox.h; path = platform/graphics/iso/ISOOriginalFormatBox.h; sourceTree = SOURCE_ROOT; };
-               CD871C681FB52B6900F0B965 /* ISOBox.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ISOBox.cpp; path = platform/graphics/iso/ISOBox.cpp; sourceTree = SOURCE_ROOT; };
-               CD871C691FB52B6900F0B965 /* ISOVTTCue.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ISOVTTCue.cpp; path = platform/graphics/iso/ISOVTTCue.cpp; sourceTree = SOURCE_ROOT; };
-               CD871C6A1FB52B6A00F0B965 /* ISOOriginalFormatBox.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ISOOriginalFormatBox.cpp; path = platform/graphics/iso/ISOOriginalFormatBox.cpp; sourceTree = SOURCE_ROOT; };
+               CD871C5C1FB52B6300F0B965 /* ISOSchemeTypeBox.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ISOSchemeTypeBox.h; sourceTree = "<group>"; };
+               CD871C5E1FB52B6400F0B965 /* ISOProtectionSchemeInfoBox.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ISOProtectionSchemeInfoBox.cpp; sourceTree = "<group>"; };
+               CD871C5F1FB52B6400F0B965 /* ISOSchemeTypeBox.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ISOSchemeTypeBox.cpp; sourceTree = "<group>"; };
+               CD871C601FB52B6500F0B965 /* ISOProtectionSchemeInfoBox.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ISOProtectionSchemeInfoBox.h; sourceTree = "<group>"; };
+               CD871C611FB52B6500F0B965 /* ISOTrackEncryptionBox.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ISOTrackEncryptionBox.cpp; sourceTree = "<group>"; };
+               CD871C621FB52B6500F0B965 /* ISOBox.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ISOBox.h; sourceTree = "<group>"; };
+               CD871C631FB52B6600F0B965 /* ISOSchemeInformationBox.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ISOSchemeInformationBox.cpp; sourceTree = "<group>"; };
+               CD871C641FB52B6700F0B965 /* ISOSchemeInformationBox.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ISOSchemeInformationBox.h; sourceTree = "<group>"; };
+               CD871C651FB52B6700F0B965 /* ISOVTTCue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ISOVTTCue.h; sourceTree = "<group>"; };
+               CD871C661FB52B6800F0B965 /* ISOTrackEncryptionBox.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ISOTrackEncryptionBox.h; sourceTree = "<group>"; };
+               CD871C671FB52B6800F0B965 /* ISOOriginalFormatBox.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ISOOriginalFormatBox.h; sourceTree = "<group>"; };
+               CD871C681FB52B6900F0B965 /* ISOBox.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ISOBox.cpp; sourceTree = "<group>"; };
+               CD871C691FB52B6900F0B965 /* ISOVTTCue.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ISOVTTCue.cpp; sourceTree = "<group>"; };
+               CD871C6A1FB52B6A00F0B965 /* ISOOriginalFormatBox.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ISOOriginalFormatBox.cpp; sourceTree = "<group>"; };
                CD8A7BB9197735FE00CBD643 /* AudioSourceProviderAVFObjC.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = AudioSourceProviderAVFObjC.mm; sourceTree = "<group>"; };
                CD8A7BBA197735FE00CBD643 /* AudioSourceProviderAVFObjC.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AudioSourceProviderAVFObjC.h; sourceTree = "<group>"; };
                CD8ACA861D237AA200ECC59E /* RemoteCommandListenerMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = RemoteCommandListenerMac.mm; sourceTree = "<group>"; };
                CD94A5D61F71CB6D00F525C5 /* CDMMessageType.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CDMMessageType.h; sourceTree = "<group>"; };
                CD94A5DA1F71CBB000F525C5 /* CDMClearKey.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CDMClearKey.h; sourceTree = "<group>"; };
                CD94A5DB1F71CBB000F525C5 /* CDMClearKey.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CDMClearKey.cpp; sourceTree = "<group>"; };
-               CD9D82731C7AE535006FF066 /* TextureCacheCV.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = TextureCacheCV.mm; path = ../cv/TextureCacheCV.mm; sourceTree = "<group>"; };
-               CD9D82741C7AE535006FF066 /* TextureCacheCV.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = TextureCacheCV.h; path = ../cv/TextureCacheCV.h; sourceTree = "<group>"; };
-               CD9D82771C7B8EE1006FF066 /* VideoTextureCopierCV.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = VideoTextureCopierCV.cpp; path = ../cv/VideoTextureCopierCV.cpp; sourceTree = "<group>"; };
-               CD9D82781C7B8EE1006FF066 /* VideoTextureCopierCV.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = VideoTextureCopierCV.h; path = ../cv/VideoTextureCopierCV.h; sourceTree = "<group>"; };
+               CD9D82731C7AE535006FF066 /* TextureCacheCV.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = TextureCacheCV.mm; sourceTree = "<group>"; };
+               CD9D82741C7AE535006FF066 /* TextureCacheCV.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TextureCacheCV.h; sourceTree = "<group>"; };
+               CD9D82771C7B8EE1006FF066 /* VideoTextureCopierCV.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = VideoTextureCopierCV.cpp; sourceTree = "<group>"; };
+               CD9D82781C7B8EE1006FF066 /* VideoTextureCopierCV.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VideoTextureCopierCV.h; sourceTree = "<group>"; };
                CD9DE17217AAC74C00EA386D /* JSMediaSource.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSMediaSource.cpp; sourceTree = "<group>"; };
                CD9DE17317AAC74C00EA386D /* JSMediaSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSMediaSource.h; sourceTree = "<group>"; };
                CD9DE17617AAC75B00EA386D /* JSSourceBuffer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSSourceBuffer.cpp; sourceTree = "<group>"; };
                                0FE5FBD01C3DD51E0007A2CA /* DisplayListReplayer.cpp */,
                                0FE5FBD11C3DD51E0007A2CA /* DisplayListReplayer.h */,
                        );
-                       name = displaylists;
+                       path = displaylists;
                        sourceTree = "<group>";
                };
                115CFA66208AF720001E6991 /* layout */ = {
                        path = filters;
                        sourceTree = "<group>";
                };
+               9368C49120F9B57200434D61 /* metal */ = {
+                       isa = PBXGroup;
+                       children = (
+                               316BDBA51E71FA6F00DE0D5A /* GPUBufferMetal.mm */,
+                               316BDBC61E75EE3D00DE0D5A /* GPUCommandBufferMetal.mm */,
+                               316BDBBD1E73881300DE0D5A /* GPUCommandQueueMetal.mm */,
+                               381E35E91E8E20AC0043E850 /* GPUComputeCommandEncoderMetal.mm */,
+                               381E35EE1E8E24CB0043E850 /* GPUComputePipelineStateMetal.mm */,
+                               316BDBF81E762BEF00DE0D5A /* GPUDepthStencilDescriptorMetal.mm */,
+                               316BDBF21E76293700DE0D5A /* GPUDepthStencilStateMetal.mm */,
+                               316BDB881E6E141C00DE0D5A /* GPUDeviceMetal.mm */,
+                               316BDBC91E75F16200DE0D5A /* GPUDrawableMetal.mm */,
+                               316BDB961E70CA2400DE0D5A /* GPUFunctionMetal.mm */,
+                               316BDB9C1E70CD9000DE0D5A /* GPULibraryMetal.mm */,
+                               316BDBEC1E76246B00DE0D5A /* GPURenderCommandEncoderMetal.mm */,
+                               316BDBE01E761CB500DE0D5A /* GPURenderPassAttachmentDescriptorMetal.mm */,
+                               316BDBD61E7612C400DE0D5A /* GPURenderPassColorAttachmentDescriptorMetal.mm */,
+                               316BDBE61E761F2700DE0D5A /* GPURenderPassDepthAttachmentDescriptorMetal.mm */,
+                               316BDBD41E75F7CA00DE0D5A /* GPURenderPassDescriptorMetal.mm */,
+                               316BDC0A1E76343600DE0D5A /* GPURenderPipelineColorAttachmentDescriptorMetal.mm */,
+                               316BDC041E762F7E00DE0D5A /* GPURenderPipelineDescriptorMetal.mm */,
+                               316BDC051E762F7E00DE0D5A /* GPURenderPipelineStateMetal.mm */,
+                               316BDBB31E7357B000DE0D5A /* GPUTextureDescriptorMetal.mm */,
+                               316BDBAD1E73549C00DE0D5A /* GPUTextureMetal.mm */,
+                       );
+                       path = metal;
+                       sourceTree = "<group>";
+               };
                93A1EAA20A5634D8006960A0 /* mac */ = {
                        isa = PBXGroup;
                        children = (
                                441AF0A70EBA7BBF0044ED4B /* ios */,
                                CD892F5A1FB52ACF009333D2 /* iso */,
                                B27535490B053814002CE64F /* mac */,
+                               9368C49120F9B57200434D61 /* metal */,
                                FBC220DD1237FBEB00BCF788 /* opengl */,
                                3721493318F0B6D600156EDC /* opentype */,
                                49E911B20EF86D27009D0CAF /* transforms */,
                                371F4FFA0D25E7F300ECE0D5 /* FontRanges.h */,
                                C2AB0AF41E6B3C6C001348C5 /* FontSelectionAlgorithm.cpp */,
                                C2AB0AF51E6B3C6C001348C5 /* FontSelectionAlgorithm.h */,
-                               C2AB0B021E6DE32B001348C5 /* FontSelectionKeywordValues.h */,
                                B2C3DA5A0D006CD600EF6F26 /* FontSelector.h */,
                                E419041E1CC6486B00C35F5D /* FontSelectorClient.h */,
                                4A6E9FC513C17D570046A7F8 /* FontTaggedSettings.cpp */,
                                1C12AC281EE778AE0079E0A0 /* FontFamilySpecificationCoreText.cpp */,
                                1C12AC291EE778AE0079E0A0 /* FontFamilySpecificationCoreText.h */,
                                B5320D6A122A24E9002D1440 /* FontPlatformDataCocoa.mm */,
-                               316BDBA51E71FA6F00DE0D5A /* GPUBufferMetal.mm */,
-                               316BDBC61E75EE3D00DE0D5A /* GPUCommandBufferMetal.mm */,
-                               316BDBBD1E73881300DE0D5A /* GPUCommandQueueMetal.mm */,
-                               381E35E91E8E20AC0043E850 /* GPUComputeCommandEncoderMetal.mm */,
-                               381E35EE1E8E24CB0043E850 /* GPUComputePipelineStateMetal.mm */,
-                               316BDBF81E762BEF00DE0D5A /* GPUDepthStencilDescriptorMetal.mm */,
-                               316BDBF21E76293700DE0D5A /* GPUDepthStencilStateMetal.mm */,
-                               316BDB881E6E141C00DE0D5A /* GPUDeviceMetal.mm */,
-                               316BDBC91E75F16200DE0D5A /* GPUDrawableMetal.mm */,
-                               316BDB961E70CA2400DE0D5A /* GPUFunctionMetal.mm */,
-                               316BDB9C1E70CD9000DE0D5A /* GPULibraryMetal.mm */,
-                               316BDBEC1E76246B00DE0D5A /* GPURenderCommandEncoderMetal.mm */,
-                               316BDBE01E761CB500DE0D5A /* GPURenderPassAttachmentDescriptorMetal.mm */,
-                               316BDBD61E7612C400DE0D5A /* GPURenderPassColorAttachmentDescriptorMetal.mm */,
-                               316BDBE61E761F2700DE0D5A /* GPURenderPassDepthAttachmentDescriptorMetal.mm */,
-                               316BDBD41E75F7CA00DE0D5A /* GPURenderPassDescriptorMetal.mm */,
-                               316BDC0A1E76343600DE0D5A /* GPURenderPipelineColorAttachmentDescriptorMetal.mm */,
-                               316BDC041E762F7E00DE0D5A /* GPURenderPipelineDescriptorMetal.mm */,
-                               316BDC051E762F7E00DE0D5A /* GPURenderPipelineStateMetal.mm */,
-                               316BDBB31E7357B000DE0D5A /* GPUTextureDescriptorMetal.mm */,
-                               316BDBAD1E73549C00DE0D5A /* GPUTextureMetal.mm */,
                                49FFBF1C11C8550E006A7118 /* GraphicsContext3DCocoa.mm */,
                                B277B4030B22F37C0004BEC6 /* GraphicsContextCocoa.mm */,
                                2D0B4AA918DA1CCD00434DE1 /* IOSurface.h */,
                                CD871C691FB52B6900F0B965 /* ISOVTTCue.cpp */,
                                CD871C651FB52B6700F0B965 /* ISOVTTCue.h */,
                        );
-                       name = iso;
-                       path = "New Group";
+                       path = iso;
                        sourceTree = "<group>";
                };
                CD94A5CB1F71CB4600F525C5 /* encryptedmedia */ = {
                                CD9D82771C7B8EE1006FF066 /* VideoTextureCopierCV.cpp */,
                                CD9D82781C7B8EE1006FF066 /* VideoTextureCopierCV.h */,
                        );
-                       name = cv;
-                       path = cg;
+                       path = cv;
                        sourceTree = "<group>";
                };
                CDA98DBD16014E0800FEA3B1 /* encryptedmedia */ = {
                                316BDBAA1E71FA9300DE0D5A /* GPUBuffer.h in Headers */,
                                316BDBCE1E75F18A00DE0D5A /* GPUCommandBuffer.h in Headers */,
                                316BDBBC1E73880600DE0D5A /* GPUCommandQueue.h in Headers */,
+                               93A953B420EBD43200A619F6 /* GPUComputeCommandEncoder.h in Headers */,
+                               93A953B020EBD3C900A619F6 /* GPUComputePipelineState.h in Headers */,
                                316BDBF71E762AD500DE0D5A /* GPUDepthStencilDescriptor.h in Headers */,
                                316BDBF01E76292000DE0D5A /* GPUDepthStencilState.h in Headers */,
                                316BDB861E6E0A2700DE0D5A /* GPUDevice.h in Headers */,
                                316BDC0D1E7634D200DE0D5A /* GPURenderPipelineColorAttachmentDescriptor.h in Headers */,
                                316BDC021E762F6400DE0D5A /* GPURenderPipelineDescriptor.h in Headers */,
                                316BDC031E762F6900DE0D5A /* GPURenderPipelineState.h in Headers */,
+                               93A953B520EC9C3F00A619F6 /* GPUSize.h in Headers */,
                                316BDBB21E7354BB00DE0D5A /* GPUTexture.h in Headers */,
                                316BDBB81E7357CB00DE0D5A /* GPUTextureDescriptor.h in Headers */,
                                BC53C5F50DA56B920021EB5D /* Gradient.h in Headers */,
index 965b3ec..7af6436 100644 (file)
 
 #include "JSDOMBinding.h"
 #include "JSWebGPURenderPassColorAttachmentDescriptor.h"
+#include "JSWebGPURenderPassDepthAttachmentDescriptor.h"
 #include "WebGPURenderPassColorAttachmentDescriptor.h"
-
+#include "WebGPURenderPassDepthAttachmentDescriptor.h"
 
 namespace WebCore {
-using namespace JSC;
 
 JSC::JSValue toJSNewlyCreated(JSC::ExecState*, JSDOMGlobalObject* globalObject, Ref<WebGPURenderPassAttachmentDescriptor>&& object)
 {
     if (object->isColorAttachmentDescriptor())
         return createWrapper<WebGPURenderPassColorAttachmentDescriptor>(globalObject, WTFMove(object));
-    return createWrapper<WebGPURenderPassAttachmentDescriptor>(globalObject, WTFMove(object));
+    return createWrapper<WebGPURenderPassDepthAttachmentDescriptor>(globalObject, WTFMove(object));
 }
 
 JSValue toJS(ExecState* state, JSDOMGlobalObject* globalObject, WebGPURenderPassAttachmentDescriptor& object)
index 536f556..75f9765 100644 (file)
 
 #if ENABLE(WEBGPU)
 
-#include "GPUBuffer.h"
 #include "WebGPURenderingContext.h"
-#include <JavaScriptCore/ArrayBuffer.h>
 
 namespace WebCore {
 
-Ref<WebGPUBuffer> WebGPUBuffer::create(WebGPURenderingContext* context, ArrayBufferView* data)
+RefPtr<WebGPUBuffer> WebGPUBuffer::create(WebGPURenderingContext& context, const JSC::ArrayBufferView& data)
 {
+    // FIXME: Consider returning null rather than a buffer with length 0 and contents null when creation fails.
     return adoptRef(*new WebGPUBuffer(context, data));
 }
 
-WebGPUBuffer::WebGPUBuffer(WebGPURenderingContext* context, ArrayBufferView* data)
-    : WebGPUObject(context)
+WebGPUBuffer::WebGPUBuffer(WebGPURenderingContext& context, const JSC::ArrayBufferView& data)
+    : WebGPUObject { &context }
+    , m_buffer { context.device(), data }
 {
-    m_buffer = context->device()->createBufferFromData(data);
-}
-
-WebGPUBuffer::~WebGPUBuffer() = default;
-
-unsigned long WebGPUBuffer::length() const
-{
-    if (!m_buffer)
-        return 0;
-
-    return m_buffer->length();
-}
-
-RefPtr<ArrayBuffer> WebGPUBuffer::contents() const
-{
-    if (!m_buffer)
-        return nullptr;
-
-    return m_buffer->contents();
 }
 
 } // namespace WebCore
index 68bcd30..ae59391 100644 (file)
 
 #if ENABLE(WEBGPU)
 
+#include "GPUBuffer.h"
 #include "WebGPUObject.h"
 
 namespace WebCore {
 
-class GPUBuffer;
-
 class WebGPUBuffer : public WebGPUObject {
 public:
-    virtual ~WebGPUBuffer();
-    static Ref<WebGPUBuffer> create(WebGPURenderingContext*, ArrayBufferView*);
+    static RefPtr<WebGPUBuffer> create(WebGPURenderingContext&, const JSC::ArrayBufferView&);
 
-    unsigned long length() const;
-    RefPtr<ArrayBuffer> contents() const;
+    unsigned length() const { return m_buffer.length(); }
+    JSC::ArrayBuffer& contents() const { return *m_buffer.contents(); }
 
-    GPUBuffer* buffer() { return m_buffer.get(); }
+    const GPUBuffer& buffer() const { return m_buffer; }
 
 private:
-    WebGPUBuffer(WebGPURenderingContext*, ArrayBufferView*);
-    RefPtr<GPUBuffer> m_buffer;
+    WebGPUBuffer(WebGPURenderingContext&, const JSC::ArrayBufferView&);
+
+    GPUBuffer m_buffer;
 };
 
 } // namespace WebCore
index 8e4ddbc..47bf010 100644 (file)
@@ -32,7 +32,6 @@
 #include "GPUCommandBuffer.h"
 #include "GPUCommandQueue.h"
 #include "Logging.h"
-#include "WebGPUCommandQueue.h"
 #include "WebGPUComputeCommandEncoder.h"
 #include "WebGPUDrawable.h"
 #include "WebGPURenderCommandEncoder.h"
 
 namespace WebCore {
 
-Ref<WebGPUCommandBuffer> WebGPUCommandBuffer::create(WebGPURenderingContext* context, WebGPUCommandQueue* queue)
+Ref<WebGPUCommandBuffer> WebGPUCommandBuffer::create(WebGPURenderingContext& context, const GPUCommandQueue& queue)
 {
     return adoptRef(*new WebGPUCommandBuffer(context, queue));
 }
 
-WebGPUCommandBuffer::WebGPUCommandBuffer(WebGPURenderingContext* context, WebGPUCommandQueue* queue)
-    : WebGPUObject(context)
+WebGPUCommandBuffer::WebGPUCommandBuffer(WebGPURenderingContext& context, const GPUCommandQueue& queue)
+    : WebGPUObject { &context }
+    , m_buffer { queue, [this] () { m_completed.resolve(); } }
 {
     LOG(WebGPU, "WebGPUCommandBuffer::WebGPUCommandBuffer()");
-    m_commandBuffer = queue->commandQueue()->createCommandBuffer();
 }
 
 WebGPUCommandBuffer::~WebGPUCommandBuffer()
@@ -61,36 +60,28 @@ WebGPUCommandBuffer::~WebGPUCommandBuffer()
 void WebGPUCommandBuffer::commit()
 {
     LOG(WebGPU, "WebGPUCommandBuffer::commit()");
-    if (!m_commandBuffer)
-        return;
-
-    return m_commandBuffer->commit();
+    m_buffer.commit();
 }
 
 void WebGPUCommandBuffer::presentDrawable(WebGPUDrawable& drawable)
 {
     LOG(WebGPU, "WebGPUCommandBuffer::presentDrawable()");
-    if (!m_commandBuffer)
-        return;
-
-    return m_commandBuffer->presentDrawable(drawable.drawable());
+    m_buffer.presentDrawable(drawable.drawable());
 }
 
-RefPtr<WebGPURenderCommandEncoder> WebGPUCommandBuffer::createRenderCommandEncoderWithDescriptor(WebGPURenderPassDescriptor& descriptor)
+Ref<WebGPURenderCommandEncoder> WebGPUCommandBuffer::createRenderCommandEncoderWithDescriptor(WebGPURenderPassDescriptor& descriptor)
 {
-    RefPtr<WebGPURenderCommandEncoder> commandEncoder = WebGPURenderCommandEncoder::create(this->context(), this, &descriptor);
-    return commandEncoder;
+    return WebGPURenderCommandEncoder::create(*context(), m_buffer, descriptor.descriptor());
 }
 
-RefPtr<WebGPUComputeCommandEncoder> WebGPUCommandBuffer::createComputeCommandEncoder()
+Ref<WebGPUComputeCommandEncoder> WebGPUCommandBuffer::createComputeCommandEncoder()
 {
-    RefPtr<WebGPUComputeCommandEncoder> commandEncoder = WebGPUComputeCommandEncoder::create(this->context(), this);
-    return commandEncoder;
+    return WebGPUComputeCommandEncoder::create(*context(), m_buffer);
 }
 
 DOMPromiseProxy<IDLVoid>& WebGPUCommandBuffer::completed()
 {
-    return m_commandBuffer->completed();
+    return m_completed;
 }
 
 } // namespace WebCore
index e8725db..9364505 100644 (file)
 #if ENABLE(WEBGPU)
 
 #include "DOMPromiseProxy.h"
+#include "GPUCommandBuffer.h"
 #include "WebGPUObject.h"
 
-#include <wtf/Vector.h>
-
 namespace WebCore {
 
-class GPUCommandBuffer;
-class WebGPUCommandQueue;
+class WebGPUComputeCommandEncoder;
 class WebGPUDrawable;
-class WebGPUFunction;
 class WebGPURenderCommandEncoder;
 class WebGPURenderPassDescriptor;
-class WebGPUComputeCommandEncoder;
 
 class WebGPUCommandBuffer : public WebGPUObject {
 public:
     virtual ~WebGPUCommandBuffer();
-    static Ref<WebGPUCommandBuffer> create(WebGPURenderingContext*, WebGPUCommandQueue*);
+    static Ref<WebGPUCommandBuffer> create(WebGPURenderingContext&, const GPUCommandQueue&);
 
     void commit();
     void presentDrawable(WebGPUDrawable&);
 
-    RefPtr<WebGPURenderCommandEncoder> createRenderCommandEncoderWithDescriptor(WebGPURenderPassDescriptor&);
-    RefPtr<WebGPUComputeCommandEncoder> createComputeCommandEncoder();
-
-    GPUCommandBuffer* commandBuffer() { return m_commandBuffer.get(); }
+    Ref<WebGPURenderCommandEncoder> createRenderCommandEncoderWithDescriptor(WebGPURenderPassDescriptor&);
+    Ref<WebGPUComputeCommandEncoder> createComputeCommandEncoder();
 
     DOMPromiseProxy<IDLVoid>& completed();
 
+    const GPUCommandBuffer& buffer() const { return m_buffer; }
+
 private:
-    WebGPUCommandBuffer(WebGPURenderingContext*, WebGPUCommandQueue*);
-    RefPtr<GPUCommandBuffer> m_commandBuffer;
+    WebGPUCommandBuffer(WebGPURenderingContext&, const GPUCommandQueue&);
+
+    GPUCommandBuffer m_buffer;
+    DOMPromiseProxy<IDLVoid> m_completed;
 };
 
 } // namespace WebCore
index 5fdd9df..ca6fdb2 100644 (file)
 
 #if ENABLE(WEBGPU)
 
-#include "GPUCommandQueue.h"
 #include "WebGPUCommandBuffer.h"
 #include "WebGPURenderingContext.h"
 
 namespace WebCore {
 
-Ref<WebGPUCommandQueue> WebGPUCommandQueue::create(WebGPURenderingContext* context)
+Ref<WebGPUCommandQueue> WebGPUCommandQueue::create(WebGPURenderingContext& context)
 {
     return adoptRef(*new WebGPUCommandQueue(context));
 }
 
-WebGPUCommandQueue::WebGPUCommandQueue(WebGPURenderingContext* context)
-    : WebGPUObject(context)
+WebGPUCommandQueue::WebGPUCommandQueue(WebGPURenderingContext& context)
+    : WebGPUObject { &context }
+    , m_queue { context.device() }
 {
-    m_commandQueue = context->device()->createCommandQueue();
 }
 
 WebGPUCommandQueue::~WebGPUCommandQueue() = default;
 
-String WebGPUCommandQueue::label() const
+Ref<WebGPUCommandBuffer> WebGPUCommandQueue::createCommandBuffer()
 {
-    if (!m_commandQueue)
-        return emptyString();
-
-    return m_commandQueue->label();
-}
-
-void WebGPUCommandQueue::setLabel(const String& label)
-{
-    if (!m_commandQueue)
-        return;
-
-    m_commandQueue->setLabel(label);
-}
-
-RefPtr<WebGPUCommandBuffer> WebGPUCommandQueue::createCommandBuffer()
-{
-    RefPtr<WebGPUCommandBuffer> buffer = WebGPUCommandBuffer::create(this->context(), this);
-    return buffer;
+    return WebGPUCommandBuffer::create(*context(), m_queue);
 }
 
 } // namespace WebCore
index b93b93c..a78fb96 100644 (file)
 
 #if ENABLE(WEBGPU)
 
+#include "GPUCommandQueue.h"
 #include "WebGPUObject.h"
 
-#include <wtf/Vector.h>
-
 namespace WebCore {
 
-class GPUCommandBuffer;
-class GPUCommandQueue;
 class WebGPUCommandBuffer;
 
 class WebGPUCommandQueue : public WebGPUObject {
 public:
     virtual ~WebGPUCommandQueue();
-    static Ref<WebGPUCommandQueue> create(WebGPURenderingContext*);
-
-    String label() const;
-    void setLabel(const String&);
+    static Ref<WebGPUCommandQueue> create(WebGPURenderingContext&);
 
-    RefPtr<WebGPUCommandBuffer> createCommandBuffer();
+    String label() const { return m_queue.label(); }
+    void setLabel(const String& label) { m_queue.setLabel(label); }
 
-    GPUCommandQueue* commandQueue() { return m_commandQueue.get(); }
+    Ref<WebGPUCommandBuffer> createCommandBuffer();
 
 private:
-    WebGPUCommandQueue(WebGPURenderingContext*);
+    explicit WebGPUCommandQueue(WebGPURenderingContext&);
 
-    RefPtr<GPUCommandQueue> m_commandQueue;
+    GPUCommandQueue m_queue;
 };
 
 } // namespace WebCore
index c1689b7..d63cbef 100644 (file)
@@ -30,6 +30,6 @@
 
     attribute DOMString label;
 
-    WebGPUCommandBuffer? createCommandBuffer();
+    WebGPUCommandBuffer createCommandBuffer();
 
 };
index 3d55ee5..297b4cc 100644 (file)
 #include "WebGPURenderingContext.h"
 
 namespace WebCore {
-    
-inline GPUSize GPUSizeMake(WebGPUSize size)
+
+static inline GPUSize GPUSizeMake(WebGPUSize size)
 {
-    return {size.width, size.height, size.depth};
+    return { size.width, size.height, size.depth };
 }
 
-Ref<WebGPUComputeCommandEncoder> WebGPUComputeCommandEncoder::create(WebGPURenderingContext* context, WebGPUCommandBuffer* buffer)
+Ref<WebGPUComputeCommandEncoder> WebGPUComputeCommandEncoder::create(WebGPURenderingContext& context, const GPUCommandBuffer& buffer)
 {
     return adoptRef(*new WebGPUComputeCommandEncoder(context, buffer));
 }
     
-WebGPUComputeCommandEncoder::WebGPUComputeCommandEncoder(WebGPURenderingContext* context, WebGPUCommandBuffer* buffer)
-    : WebGPUObject(context)
+WebGPUComputeCommandEncoder::WebGPUComputeCommandEncoder(WebGPURenderingContext& context, const GPUCommandBuffer& buffer)
+    : WebGPUObject { &context }
+    , m_encoder { buffer }
 {
-    m_computeCommandEncoder = buffer->commandBuffer()->createComputeCommandEncoder();
 }
-    
-WebGPUComputeCommandEncoder::~WebGPUComputeCommandEncoder() = default;
-    
+
 void WebGPUComputeCommandEncoder::setComputePipelineState(WebGPUComputePipelineState& pipelineState)
 {
-    if (!m_computeCommandEncoder)
-        return;
-    m_computeCommandEncoder->setComputePipelineState(pipelineState.computePipelineState());
+    m_encoder.setComputePipelineState(pipelineState.state());
 }
-    
+
 void WebGPUComputeCommandEncoder::setBuffer(WebGPUBuffer& buffer, unsigned offset, unsigned index)
 {
-    if (!m_computeCommandEncoder)
-        return;
-    m_computeCommandEncoder->setBuffer(buffer.buffer(), offset, index);
+    m_encoder.setBuffer(buffer.buffer(), offset, index);
 }
-    
+
 void WebGPUComputeCommandEncoder::dispatch(WebGPUSize threadgroupsPerGrid, WebGPUSize threadsPerThreadgroup)
 {
-    if (!m_computeCommandEncoder)
-        return;
-    m_computeCommandEncoder->dispatch(GPUSizeMake(threadgroupsPerGrid), GPUSizeMake(threadsPerThreadgroup));
+    m_encoder.dispatch(GPUSizeMake(threadgroupsPerGrid), GPUSizeMake(threadsPerThreadgroup));
 }
-    
+
 void WebGPUComputeCommandEncoder::endEncoding()
 {
-    if (!m_computeCommandEncoder)
-        return;
-    m_computeCommandEncoder->endEncoding();
+    m_encoder.endEncoding();
 }
-    
+
 } // namespace WebCore
 
 #endif
index 2f37e26..6a0c1b7 100644 (file)
 
 #pragma once
 
-#include "WebGPUSize.h"
-
 #if ENABLE(WEBGPU)
 
+#include "GPUComputeCommandEncoder.h"
 #include "WebGPUObject.h"
-
-#include <wtf/Vector.h>
+#include "WebGPUSize.h"
 
 namespace WebCore {
 
-class GPUComputeCommandEncoder;
 class WebGPUBuffer;
-class WebGPUCommandBuffer;
 class WebGPUComputePipelineState;
-class WebGPURenderingContext;
 
 class WebGPUComputeCommandEncoder : public WebGPUObject {
-
 public:
-    virtual ~WebGPUComputeCommandEncoder();
-    static Ref<WebGPUComputeCommandEncoder> create(WebGPURenderingContext*, WebGPUCommandBuffer*);
+    static Ref<WebGPUComputeCommandEncoder> create(WebGPURenderingContext&, const GPUCommandBuffer&);
 
     void setComputePipelineState(WebGPUComputePipelineState&);
     void setBuffer(WebGPUBuffer&, unsigned, unsigned);
     void dispatch(WebGPUSize, WebGPUSize);
     void endEncoding();
 
-    GPUComputeCommandEncoder* computeCommandEncoder() { return m_computeCommandEncoder.get(); }
-
 private:
-    WebGPUComputeCommandEncoder(WebGPURenderingContext*, WebGPUCommandBuffer*);
-    RefPtr<GPUComputeCommandEncoder> m_computeCommandEncoder;
+    WebGPUComputeCommandEncoder(WebGPURenderingContext&, const GPUCommandBuffer&);
+
+    GPUComputeCommandEncoder m_encoder;
 };
 
 } // namespace WebCore
index 57c03e7..a6e8d09 100644 (file)
 
 #if ENABLE(WEBGPU)
 
-#include "GPUComputePipelineState.h"
-#include "WebGPUFunction.h"
-#include "WebGPURenderingContext.h"
-
 namespace WebCore {
 
-Ref<WebGPUComputePipelineState> WebGPUComputePipelineState::create(WebGPURenderingContext* context, WebGPUFunction* function)
+Ref<WebGPUComputePipelineState> WebGPUComputePipelineState::create(WebGPURenderingContext& context, const GPUFunction& function)
 {
     return adoptRef(*new WebGPUComputePipelineState(context, function));
 }
 
-WebGPUComputePipelineState::WebGPUComputePipelineState(WebGPURenderingContext* context, WebGPUFunction* function)
-    : WebGPUObject(context)
+WebGPUComputePipelineState::WebGPUComputePipelineState(WebGPURenderingContext& context, const GPUFunction& function)
+    : WebGPUObject { &context }
+    , m_state { context.device(), function }
 {
-    if (!context || !function)
-        return;
-    m_computePipelineState = GPUComputePipelineState::create(context->device().get(), function->function());
 }
 
-WebGPUComputePipelineState::~WebGPUComputePipelineState() = default;
-
 } // namespace WebCore
 
 #endif
index 77596ff..c09ead0 100644 (file)
 
 #if ENABLE(WEBGPU)
 
+#include "GPUComputePipelineState.h"
 #include "WebGPUObject.h"
 
-#include <wtf/Vector.h>
-
 namespace WebCore {
 
-class GPUComputePipelineState;
 class WebGPUFunction;
 
 class WebGPUComputePipelineState : public WebGPUObject {
 public:
-    virtual ~WebGPUComputePipelineState();
-    static Ref<WebGPUComputePipelineState> create(WebGPURenderingContext*, WebGPUFunction*);
-    GPUComputePipelineState* computePipelineState() { return m_computePipelineState.get(); }
+    static Ref<WebGPUComputePipelineState> create(WebGPURenderingContext&, const GPUFunction&);
+
+    GPUComputePipelineState& state() { return m_state; }
 
 private:
-    WebGPUComputePipelineState(WebGPURenderingContext*, WebGPUFunction*);
-    RefPtr<GPUComputePipelineState> m_computePipelineState;
+    WebGPUComputePipelineState(WebGPURenderingContext&, const GPUFunction&);
+
+    GPUComputePipelineState m_state;
 };
 
 } // namespace WebCore
index 2b90145..3cb3599 100644 (file)
 
 #if ENABLE(WEBGPU)
 
-#include "GPUDepthStencilDescriptor.h"
 #include "WebGPURenderingContext.h"
 
 namespace WebCore {
 
 Ref<WebGPUDepthStencilDescriptor> WebGPUDepthStencilDescriptor::create()
 {
-    return adoptRef(*new WebGPUDepthStencilDescriptor());
+    return adoptRef(*new WebGPUDepthStencilDescriptor);
 }
 
-WebGPUDepthStencilDescriptor::WebGPUDepthStencilDescriptor()
-    : WebGPUObject()
-{
-    m_depthStencilDescriptor = GPUDepthStencilDescriptor::create();
-}
-
-WebGPUDepthStencilDescriptor::~WebGPUDepthStencilDescriptor() = default;
-
 bool WebGPUDepthStencilDescriptor::depthWriteEnabled() const
 {
-    if (!m_depthStencilDescriptor)
-        return false;
-
-    return m_depthStencilDescriptor->depthWriteEnabled();
+    return m_descriptor.depthWriteEnabled();
 }
 
 void WebGPUDepthStencilDescriptor::setDepthWriteEnabled(bool newDepthWriteEnabled)
 {
-    if (!m_depthStencilDescriptor)
-        return;
-
-    m_depthStencilDescriptor->setDepthWriteEnabled(newDepthWriteEnabled);
+    m_descriptor.setDepthWriteEnabled(newDepthWriteEnabled);
 }
 
-auto WebGPUDepthStencilDescriptor::depthCompareFunction() const -> WebGPUCompareFunction
+WebGPUCompareFunction WebGPUDepthStencilDescriptor::depthCompareFunction() const
 {
     return m_depthCompareFunction;
 }
@@ -70,7 +55,7 @@ auto WebGPUDepthStencilDescriptor::depthCompareFunction() const -> WebGPUCompare
 void WebGPUDepthStencilDescriptor::setDepthCompareFunction(CompareFunction newDepthCompareFunction)
 {
     m_depthCompareFunction = newDepthCompareFunction;
-    m_depthStencilDescriptor->setDepthCompareFunction(toGPUCompareFunction(m_depthCompareFunction));
+    m_descriptor.setDepthCompareFunction(toGPUCompareFunction(m_depthCompareFunction));
 }
 
 } // namespace WebCore
index 4cdb401..617474f 100644 (file)
 
 #if ENABLE(WEBGPU)
 
+#include "GPUDepthStencilDescriptor.h"
 #include "WebGPUEnums.h"
 #include "WebGPUObject.h"
 
-#include <wtf/Vector.h>
-
 namespace WebCore {
 
-class GPUDepthStencilDescriptor;
-
 class WebGPUDepthStencilDescriptor : public WebGPUObject {
 public:
-    virtual ~WebGPUDepthStencilDescriptor();
     static Ref<WebGPUDepthStencilDescriptor> create();
 
     bool depthWriteEnabled() const;
@@ -48,13 +44,18 @@ public:
     CompareFunction depthCompareFunction() const;
     void setDepthCompareFunction(CompareFunction);
 
-    GPUDepthStencilDescriptor* depthStencilDescriptor() { return m_depthStencilDescriptor.get(); }
+    GPUDepthStencilDescriptor& descriptor() { return m_descriptor; }
 
 private:
-    WebGPUDepthStencilDescriptor();
+    WebGPUDepthStencilDescriptor() = default;
+
+    // FIXME: The default value of "Always" is defined both here and in the
+    // GPUDepthStencilDescriptor class's implementation. Might be better to not
+    // store the compare function separately here, translate it instead, and then
+    // there would be no need for a default value here.
 
-    WebGPUCompareFunction m_depthCompareFunction;
-    RefPtr<GPUDepthStencilDescriptor> m_depthStencilDescriptor;
+    WebGPUCompareFunction m_depthCompareFunction { WebGPUCompareFunction::Always };
+    GPUDepthStencilDescriptor m_descriptor;
 };
 
 } // namespace WebCore
index 2de9cf6..e7289a3 100644 (file)
 
 #if ENABLE(WEBGPU)
 
-#include "GPUDepthStencilState.h"
 #include "WebGPUDepthStencilDescriptor.h"
 #include "WebGPURenderingContext.h"
 
 namespace WebCore {
 
-Ref<WebGPUDepthStencilState> WebGPUDepthStencilState::create(WebGPURenderingContext* context, WebGPUDepthStencilDescriptor* descriptor)
+Ref<WebGPUDepthStencilState> WebGPUDepthStencilState::create(WebGPURenderingContext& context, const GPUDepthStencilDescriptor& descriptor)
 {
     return adoptRef(*new WebGPUDepthStencilState(context, descriptor));
 }
 
-WebGPUDepthStencilState::WebGPUDepthStencilState(WebGPURenderingContext* context, WebGPUDepthStencilDescriptor* descriptor)
-    : WebGPUObject(context)
+WebGPUDepthStencilState::WebGPUDepthStencilState(WebGPURenderingContext& context, const GPUDepthStencilDescriptor& descriptor)
+    : WebGPUObject { &context }
+    , m_state { context.device(), descriptor }
 {
-    if (!context || !descriptor)
-        return;
-    m_depthStencilState = GPUDepthStencilState::create(context->device().get(), descriptor->depthStencilDescriptor());
 }
 
-WebGPUDepthStencilState::~WebGPUDepthStencilState() = default;
-
 String WebGPUDepthStencilState::label() const
 {
-    if (!m_depthStencilState)
-        return emptyString();
-
-    return m_depthStencilState->label();
+    return m_state.label();
 }
 
 void WebGPUDepthStencilState::setLabel(const String& label)
 {
-    if (!m_depthStencilState)
-        return;
-
-    m_depthStencilState->setLabel(label);
+    m_state.setLabel(label);
 }
 
 } // namespace WebCore
index ba97b86..9155c2d 100644 (file)
 
 #if ENABLE(WEBGPU)
 
+#include "GPUDepthStencilState.h"
 #include "WebGPUObject.h"
 
-#include <wtf/Vector.h>
-
 namespace WebCore {
 
-class GPUDepthStencilState;
-class WebGPUDepthStencilDescriptor;
-
 class WebGPUDepthStencilState : public WebGPUObject {
 public:
-    virtual ~WebGPUDepthStencilState();
-    static Ref<WebGPUDepthStencilState> create(WebGPURenderingContext*, WebGPUDepthStencilDescriptor*);
+    static Ref<WebGPUDepthStencilState> create(WebGPURenderingContext&, const GPUDepthStencilDescriptor&);
 
     String label() const;
     void setLabel(const String&);
 
-    GPUDepthStencilState* depthStencilState() { return m_depthStencilState.get(); }
+    GPUDepthStencilState& state() { return m_state; }
 
 private:
-    WebGPUDepthStencilState(WebGPURenderingContext*, WebGPUDepthStencilDescriptor*);
+    WebGPUDepthStencilState(WebGPURenderingContext&, const GPUDepthStencilDescriptor&);
 
-    RefPtr<GPUDepthStencilState> m_depthStencilState;
+    GPUDepthStencilState m_state;
 };
     
 } // namespace WebCore
index e1d12b9..913268d 100644 (file)
 
 #if ENABLE(WEBGPU)
 
-#include "GPUDrawable.h"
 #include "GPUTexture.h"
 #include "WebGPURenderingContext.h"
 #include "WebGPUTexture.h"
 
 namespace WebCore {
 
-Ref<WebGPUDrawable> WebGPUDrawable::create(WebGPURenderingContext* context)
+Ref<WebGPUDrawable> WebGPUDrawable::create(WebGPURenderingContext& context)
 {
     return adoptRef(*new WebGPUDrawable(context));
 }
 
-WebGPUDrawable::WebGPUDrawable(WebGPURenderingContext* context)
-    : WebGPUObject(context)
+WebGPUDrawable::WebGPUDrawable(WebGPURenderingContext& context)
+    : WebGPUObject { &context }
+    , m_drawable { context.device() }
+    , m_texture { WebGPUTexture::createFromDrawableTexture(context, GPUTexture { m_drawable }) }
 {
-    m_drawable = context->device()->getFramebuffer();
-    if (!m_drawable)
-        return;
-
-    auto drawableTexture = GPUTexture::createFromDrawable(m_drawable.get());
-    m_texture = WebGPUTexture::createFromDrawableTexture(context, WTFMove(drawableTexture));
 }
 
 WebGPUDrawable::~WebGPUDrawable() = default;
 
-WebGPUTexture* WebGPUDrawable::texture()
-{
-    if (!m_texture)
-        return nullptr;
-
-    return m_texture.get();
-}
-
 } // namespace WebCore
 
 #endif
index bcc1f8b..fc52055 100644 (file)
 
 #if ENABLE(WEBGPU)
 
+#include "GPUDrawable.h"
 #include "WebGPUObject.h"
 
 namespace WebCore {
 
-class GPUDrawable;
 class WebGPUTexture;
 
 class WebGPUDrawable : public WebGPUObject {
 public:
     virtual ~WebGPUDrawable();
-    static Ref<WebGPUDrawable> create(WebGPURenderingContext*);
+    static Ref<WebGPUDrawable> create(WebGPURenderingContext&);
 
-    WebGPUTexture* texture();
-
-    GPUDrawable* drawable() { return m_drawable.get(); }
+    GPUDrawable& drawable() { return m_drawable; }
+    WebGPUTexture& texture() { return m_texture.get(); }
 
 private:
-    WebGPUDrawable(WebGPURenderingContext*);
-    RefPtr<GPUDrawable> m_drawable;
-    RefPtr<WebGPUTexture> m_texture;
+    explicit WebGPUDrawable(WebGPURenderingContext&);
+
+    GPUDrawable m_drawable;
+    Ref<WebGPUTexture> m_texture;
 };
 
 } // namespace WebCore
index 2659014..46636ff 100644 (file)
@@ -55,7 +55,7 @@ std::optional<WebGPUCompareFunction> toWebGPUCompareFunction(const String& name)
     return std::nullopt;
 }
 
-String web3DCompareFunctionName(const WebGPUCompareFunction value)
+String web3DCompareFunctionName(WebGPUCompareFunction value)
 {
     if (value == WebGPUCompareFunction::Never)
         return "never"_s;
index 5f9faa5..43504e5 100644 (file)
@@ -27,8 +27,8 @@
 
 #if ENABLE(WEBGPU)
 
+#include <wtf/Forward.h>
 #include <wtf/Optional.h>
-#include <wtf/text/WTFString.h>
 
 namespace WebCore {
 
@@ -46,8 +46,8 @@ enum class WebGPUCompareFunction {
 };
 
 std::optional<WebGPUCompareFunction> toWebGPUCompareFunction(const String&);
-String web3DCompareFunctionName(const WebGPUCompareFunction);
-GPUCompareFunction toGPUCompareFunction(const WebGPUCompareFunction);
+String web3DCompareFunctionName(WebGPUCompareFunction);
+GPUCompareFunction toGPUCompareFunction(WebGPUCompareFunction);
 
 } // namespace WebCore
 
index a7aa406..8eab63c 100644 (file)
 
 #if ENABLE(WEBGPU)
 
-#include "GPUFunction.h"
-#include "GPULibrary.h"
 #include "WebGPULibrary.h"
 #include "WebGPURenderingContext.h"
 
 namespace WebCore {
 
-Ref<WebGPUFunction> WebGPUFunction::create(WebGPURenderingContext* context, WebGPULibrary* library, const String& name)
+Ref<WebGPUFunction> WebGPUFunction::create(WebGPURenderingContext& context, GPUFunction&& function)
 {
-    return adoptRef(*new WebGPUFunction(context, library, name));
+    return adoptRef(*new WebGPUFunction(context, WTFMove(function)));
 }
 
-WebGPUFunction::WebGPUFunction(WebGPURenderingContext* context, WebGPULibrary* library, const String& name)
-    : WebGPUObject(context)
+WebGPUFunction::WebGPUFunction(WebGPURenderingContext& context, GPUFunction&& function)
+    : WebGPUObject { &context }
+    , m_function { WTFMove(function) }
 {
-    m_function = library->library()->functionWithName(name);
-}
-
-WebGPUFunction::~WebGPUFunction() = default;
-
-String WebGPUFunction::name() const
-{
-    if (!m_function)
-        return emptyString();
-
-    return m_function->name();
 }
 
 } // namespace WebCore
index 9f17d48..153fc89 100644 (file)
 
 #if ENABLE(WEBGPU)
 
+#include "GPUFunction.h"
 #include "WebGPUObject.h"
 
 namespace WebCore {
 
-class GPUFunction;
-class WebGPULibrary;
-
 class WebGPUFunction : public WebGPUObject {
 public:
-    virtual ~WebGPUFunction();
-    static Ref<WebGPUFunction> create(WebGPURenderingContext*, WebGPULibrary*, const String& name);
-
-    String name() const;
+    static Ref<WebGPUFunction> create(WebGPURenderingContext&, GPUFunction&&);
 
-    GPUFunction* function() const { return m_function.get(); }
+    String name() const { return m_function.name(); }
+    const GPUFunction& function() const { return m_function; }
 
 private:
-    WebGPUFunction(WebGPURenderingContext*, WebGPULibrary*, const String& name);
+    WebGPUFunction(WebGPURenderingContext&, GPUFunction&&);
 
-    RefPtr<GPUFunction> m_function;
+    GPUFunction m_function;
 };
     
 } // namespace WebCore
index d198edb..6fa9e97 100644 (file)
 
 #if ENABLE(WEBGPU)
 
-#include "GPULibrary.h"
 #include "WebGPUFunction.h"
 #include "WebGPURenderingContext.h"
 
 namespace WebCore {
 
-Ref<WebGPULibrary> WebGPULibrary::create(WebGPURenderingContext* context, const String& sourceCode)
+Ref<WebGPULibrary> WebGPULibrary::create(WebGPURenderingContext& context, const String& sourceCode)
 {
     return adoptRef(*new WebGPULibrary(context, sourceCode));
 }
 
-WebGPULibrary::WebGPULibrary(WebGPURenderingContext* context, const String& sourceCode)
-    : WebGPUObject(context)
-    , m_sourceCode(sourceCode)
+WebGPULibrary::WebGPULibrary(WebGPURenderingContext& context, const String& sourceCode)
+    : WebGPUObject { &context }
+    , m_sourceCode { sourceCode }
+    , m_library { context.device(), sourceCode }
 {
-    m_library = context->device()->createLibrary(sourceCode);
 }
 
-WebGPULibrary::~WebGPULibrary() = default;
-
-String WebGPULibrary::label() const
-{
-    if (!m_library)
-        return emptyString();
-
-    return m_library->label();
-}
-
-void WebGPULibrary::setLabel(const String& label)
-{
-    if (!m_library)
-        return;
-
-    m_library->setLabel(label);
-}
-
-Vector<String> WebGPULibrary::functionNames()
+Vector<String> WebGPULibrary::functionNames() const
 {
-    if (!m_library)
-        return Vector<String>();
-
-    return m_library->functionNames();
+    return m_library.functionNames();
 }
 
-RefPtr<WebGPUFunction> WebGPULibrary::functionWithName(const String& name)
+RefPtr<WebGPUFunction> WebGPULibrary::functionWithName(const String& name) const
 {
-    if (!m_library)
-        return nullptr;
-
-    RefPtr<WebGPUFunction> function = WebGPUFunction::create(this->context(), this, name);
-    if (!function->function())
+    GPUFunction function { m_library, name };
+    if (!function)
         return nullptr;
-    return function;
+    return WebGPUFunction::create(*context(), WTFMove(function));
 }
 
 } // namespace WebCore
index b5ffab5..0d2a163 100644 (file)
 
 #if ENABLE(WEBGPU)
 
+#include "GPULibrary.h"
 #include "WebGPUObject.h"
 
-#include <wtf/Vector.h>
-#include <wtf/text/WTFString.h>
-
 namespace WebCore {
 
-class GPULibrary;
 class WebGPUFunction;
 
 class WebGPULibrary : public WebGPUObject {
 public:
-    virtual ~WebGPULibrary();
-    static Ref<WebGPULibrary> create(WebGPURenderingContext*, const String& sourceCode);
+    static Ref<WebGPULibrary> create(WebGPURenderingContext&, const String& sourceCode);
 
-    String sourceCode() const { return m_sourceCode; }
-    String label() const;
-    void setLabel(const String&);
+    const String& sourceCode() const { return m_sourceCode; }
 
-    Vector<String> functionNames();
+    String label() const { return m_library.label(); }
+    void setLabel(const String& label) { m_library.setLabel(label); }
 
-    RefPtr<WebGPUFunction> functionWithName(const String&);
+    Vector<String> functionNames() const;
 
-    GPULibrary* library() { return m_library.get(); }
+    RefPtr<WebGPUFunction> functionWithName(const String&) const;
 
 private:
-    WebGPULibrary(WebGPURenderingContext*, const String& sourceCode);
+    WebGPULibrary(WebGPURenderingContext&, const String& sourceCode);
 
     String m_sourceCode;
-    RefPtr<GPULibrary> m_library;
+    GPULibrary m_library;
 };
 
 } // namespace WebCore
index 1a68ca8..8acb81e 100644 (file)
 namespace WebCore {
 
 WebGPUObject::WebGPUObject(WebGPURenderingContext* context)
-    : m_context(context)
+    : m_context { context }
 {
 }
 
 WebGPUObject::~WebGPUObject() = default;
 
-void WebGPUObject::deleteObject(GPUDevice*)
-{
-    m_deleted = true;
-}
-
 }
 
 #endif
index de2a732..c913003 100644 (file)
@@ -27,9 +27,8 @@
 
 #if ENABLE(WEBGPU)
 
-#include "GPUDevice.h"
-
 #include <wtf/RefCounted.h>
+#include <wtf/RefPtr.h>
 
 namespace WebCore {
 
@@ -39,19 +38,15 @@ class WebGPUObject : public RefCounted<WebGPUObject> {
 public:
     virtual ~WebGPUObject();
 
-    void deleteObject(GPUDevice*);
-    bool isDeleted() const { return m_deleted; }
-
-    WebGPURenderingContext* context() { return m_context.get(); }
+    WebGPURenderingContext* context() const { return m_context.get(); }
 
 protected:
-    WebGPUObject(WebGPURenderingContext* = nullptr);
+    explicit WebGPUObject(WebGPURenderingContext* = nullptr);
 
     bool hasContext() const { return m_context; }
 
 private:
     RefPtr<WebGPURenderingContext> m_context;
-    bool m_deleted { false };
 };
     
 } // namespace WebCore
index 6ebd674..79ca782 100644 (file)
@@ -29,7 +29,6 @@
 #if ENABLE(WEBGPU)
 
 #include "GPUCommandBuffer.h"
-#include "GPURenderCommandEncoder.h"
 #include "GPURenderPassDescriptor.h"
 #include "WebGPUBuffer.h"
 #include "WebGPUCommandBuffer.h"
 
 namespace WebCore {
 
-Ref<WebGPURenderCommandEncoder> WebGPURenderCommandEncoder::create(WebGPURenderingContext* context, WebGPUCommandBuffer* buffer, WebGPURenderPassDescriptor* descriptor)
+Ref<WebGPURenderCommandEncoder> WebGPURenderCommandEncoder::create(WebGPURenderingContext& context, const GPUCommandBuffer& buffer, const GPURenderPassDescriptor& descriptor)
 {
     return adoptRef(*new WebGPURenderCommandEncoder(context, buffer, descriptor));
 }
 
-WebGPURenderCommandEncoder::WebGPURenderCommandEncoder(WebGPURenderingContext* context, WebGPUCommandBuffer* buffer, WebGPURenderPassDescriptor* descriptor)
-    : WebGPUObject(context)
+WebGPURenderCommandEncoder::WebGPURenderCommandEncoder(WebGPURenderingContext& context, const GPUCommandBuffer& buffer, const GPURenderPassDescriptor& descriptor)
+    : WebGPUObject { &context }
+    , m_encoder { buffer, descriptor }
 {
-    m_renderCommandEncoder = buffer->commandBuffer()->createRenderCommandEncoder(descriptor->renderPassDescriptor());
 }
 
 WebGPURenderCommandEncoder::~WebGPURenderCommandEncoder() = default;
 
 void WebGPURenderCommandEncoder::setRenderPipelineState(WebGPURenderPipelineState& pipelineState)
 {
-    if (!m_renderCommandEncoder)
-        return;
-
-    m_renderCommandEncoder->setRenderPipelineState(pipelineState.renderPipelineState());
+    m_encoder.setRenderPipelineState(pipelineState.state());
 }
 
 void WebGPURenderCommandEncoder::setDepthStencilState(WebGPUDepthStencilState& depthStencilState)
 {
-    if (!m_renderCommandEncoder)
-        return;
-
-    m_renderCommandEncoder->setDepthStencilState(depthStencilState.depthStencilState());
+    m_encoder.setDepthStencilState(depthStencilState.state());
 }
 
 void WebGPURenderCommandEncoder::setVertexBuffer(WebGPUBuffer& buffer, unsigned offset, unsigned index)
 {
-    if (!m_renderCommandEncoder)
-        return;
-
-    m_renderCommandEncoder->setVertexBuffer(buffer.buffer(), offset, index);
+    m_encoder.setVertexBuffer(buffer.buffer(), offset, index);
 }
 
 void WebGPURenderCommandEncoder::setFragmentBuffer(WebGPUBuffer& buffer, unsigned offset, unsigned index)
 {
-    if (!m_renderCommandEncoder)
-        return;
-
-    m_renderCommandEncoder->setFragmentBuffer(buffer.buffer(), offset, index);
+    m_encoder.setFragmentBuffer(buffer.buffer(), offset, index);
 }
 
 void WebGPURenderCommandEncoder::drawPrimitives(unsigned type, unsigned start, unsigned count)
 {
-    if (!m_renderCommandEncoder)
-        return;
-
-    m_renderCommandEncoder->drawPrimitives(type, start, count);
+    m_encoder.drawPrimitives(type, start, count);
 }
 
 void WebGPURenderCommandEncoder::endEncoding()
 {
-    if (!m_renderCommandEncoder)
-        return;
-    return m_renderCommandEncoder->endEncoding();
+    return m_encoder.endEncoding();
 }
 
 } // namespace WebCore
index 66cec59..f1c1aae 100644 (file)
 
 #if ENABLE(WEBGPU)
 
+#include "GPURenderCommandEncoder.h"
 #include "WebGPUObject.h"
 
-#include <wtf/Vector.h>
-
 namespace WebCore {
 
-class GPURenderCommandEncoder;
-class GPUBuffer;
-class GPURenderPipelineState;
-class GPUDepthStencilState;
-class WebGPUCommandBuffer;
 class WebGPUDepthStencilState;
-class WebGPURenderPassDescriptor;
-class WebGPUFunction;
 class WebGPURenderPipelineState;
 class WebGPUBuffer;
 
 class WebGPURenderCommandEncoder : public WebGPUObject {
 public:
     virtual ~WebGPURenderCommandEncoder();
-    static Ref<WebGPURenderCommandEncoder> create(WebGPURenderingContext*, WebGPUCommandBuffer*, WebGPURenderPassDescriptor*);
+    static Ref<WebGPURenderCommandEncoder> create(WebGPURenderingContext&, const GPUCommandBuffer&, const GPURenderPassDescriptor&);
 
     void setRenderPipelineState(WebGPURenderPipelineState&);
     void setDepthStencilState(WebGPUDepthStencilState&);
@@ -56,11 +48,12 @@ public:
     void drawPrimitives(unsigned type, unsigned start, unsigned count);
     void endEncoding();
 
-    GPURenderCommandEncoder* renderCommandEncoder() { return m_renderCommandEncoder.get(); }
+    GPURenderCommandEncoder& encoder() { return m_encoder; }
 
 private:
-    WebGPURenderCommandEncoder(WebGPURenderingContext*, WebGPUCommandBuffer*, WebGPURenderPassDescriptor*);
-    RefPtr<GPURenderCommandEncoder> m_renderCommandEncoder;
+    WebGPURenderCommandEncoder(WebGPURenderingContext&, const GPUCommandBuffer&, const GPURenderPassDescriptor&);
+
+    GPURenderCommandEncoder m_encoder;
 };
 
 } // namespace WebCore
index eab3320..58978c6 100644 (file)
 
 namespace WebCore {
 
-WebGPURenderPassAttachmentDescriptor::WebGPURenderPassAttachmentDescriptor(WebGPURenderingContext* context, GPURenderPassAttachmentDescriptor* descriptor)
-    : WebGPUObject(context)
-    , m_renderPassAttachmentDescriptor(descriptor)
+WebGPURenderPassAttachmentDescriptor::WebGPURenderPassAttachmentDescriptor(WebGPURenderingContext& context)
+    : WebGPUObject { &context }
 {
 }
 
 WebGPURenderPassAttachmentDescriptor::~WebGPURenderPassAttachmentDescriptor() = default;
 
-unsigned long WebGPURenderPassAttachmentDescriptor::loadAction() const
+unsigned WebGPURenderPassAttachmentDescriptor::loadAction() const
 {
-    if (!m_renderPassAttachmentDescriptor)
-        return 0; // FIXME: probably a real value for unknown
-
-    return m_renderPassAttachmentDescriptor->loadAction();
+    return descriptor().loadAction();
 }
 
-void WebGPURenderPassAttachmentDescriptor::setLoadAction(unsigned long newLoadAction)
+void WebGPURenderPassAttachmentDescriptor::setLoadAction(unsigned newLoadAction)
 {
-    if (!m_renderPassAttachmentDescriptor)
-        return;
-
-    m_renderPassAttachmentDescriptor->setLoadAction(newLoadAction);
+    descriptor().setLoadAction(newLoadAction);
 }
 
-unsigned long WebGPURenderPassAttachmentDescriptor::storeAction() const
+unsigned WebGPURenderPassAttachmentDescriptor::storeAction() const
 {
-    if (!m_renderPassAttachmentDescriptor)
-        return 0; // FIXME: probably a real value for unknown
-
-    return m_renderPassAttachmentDescriptor->storeAction();
+    return descriptor().storeAction();
 }
 
-void WebGPURenderPassAttachmentDescriptor::setStoreAction(unsigned long newStoreAction)
+void WebGPURenderPassAttachmentDescriptor::setStoreAction(unsigned newStoreAction)
 {
-    if (!m_renderPassAttachmentDescriptor)
-        return;
-
-    m_renderPassAttachmentDescriptor->setStoreAction(newStoreAction);
+    descriptor().setStoreAction(newStoreAction);
 }
 
-RefPtr<WebGPUTexture> WebGPURenderPassAttachmentDescriptor::texture() const
+WebGPUTexture* WebGPURenderPassAttachmentDescriptor::texture() const
 {
-    return m_texture;
+    return m_texture.get();
 }
 
-void WebGPURenderPassAttachmentDescriptor::setTexture(RefPtr<WebGPUTexture> newTexture)
+void WebGPURenderPassAttachmentDescriptor::setTexture(RefPtr<WebGPUTexture>&& newTexture)
 {
+    // FIXME: Why can't we set this to null?
     if (!newTexture)
         return;
     
-    m_texture = newTexture;
-    
-    if (m_renderPassAttachmentDescriptor)
-        m_renderPassAttachmentDescriptor->setTexture(newTexture->texture());
+    m_texture = WTFMove(newTexture);
+
+    descriptor().setTexture(m_texture->texture());
 }
 
 } // namespace WebCore
index a6253f4..a35a325 100644 (file)
@@ -29,8 +29,6 @@
 
 #include "WebGPUObject.h"
 
-#include <wtf/Vector.h>
-
 namespace WebCore {
 
 class GPURenderPassAttachmentDescriptor;
@@ -40,30 +38,26 @@ class WebGPURenderPassAttachmentDescriptor : public WebGPUObject {
 public:
     virtual ~WebGPURenderPassAttachmentDescriptor();
 
-    unsigned long loadAction() const;
-    void setLoadAction(unsigned long);
-
-    unsigned long storeAction() const;
-    void setStoreAction(unsigned long);
+    unsigned loadAction() const;
+    void setLoadAction(unsigned);
 
-    RefPtr<WebGPUTexture> texture() const;
-    void setTexture(RefPtr<WebGPUTexture>);
+    unsigned storeAction() const;
+    void setStoreAction(unsigned);
 
-    GPURenderPassAttachmentDescriptor* renderPassAttachmentDescriptor() const { return m_renderPassAttachmentDescriptor.get(); }
+    WebGPUTexture* texture() const;
+    void setTexture(RefPtr<WebGPUTexture>&&);
 
-    virtual bool isColorAttachmentDescriptor() const { return false; }
+    virtual bool isColorAttachmentDescriptor() const = 0;
 
 protected:
-
-    WebGPURenderPassAttachmentDescriptor(WebGPURenderingContext*, GPURenderPassAttachmentDescriptor*);
-
+    explicit WebGPURenderPassAttachmentDescriptor(WebGPURenderingContext&);
 
 private:
+    virtual const GPURenderPassAttachmentDescriptor& descriptor() const = 0;
 
-    RefPtr<GPURenderPassAttachmentDescriptor> m_renderPassAttachmentDescriptor;
     RefPtr<WebGPUTexture> m_texture;
 };
-    
+
 } // namespace WebCore
 
 #endif
index 83cdda6..3ec3d4f 100644 (file)
 
 #if ENABLE(WEBGPU)
 
-#include "GPURenderPassColorAttachmentDescriptor.h"
 #include "GPUTexture.h"
 #include "WebGPURenderingContext.h"
 #include "WebGPUTexture.h"
 
 namespace WebCore {
 
-Ref<WebGPURenderPassColorAttachmentDescriptor> WebGPURenderPassColorAttachmentDescriptor::create(WebGPURenderingContext* context, GPURenderPassColorAttachmentDescriptor* descriptor)
+Ref<WebGPURenderPassColorAttachmentDescriptor> WebGPURenderPassColorAttachmentDescriptor::create(WebGPURenderingContext& context, GPURenderPassColorAttachmentDescriptor&& descriptor)
 {
-    return adoptRef(*new WebGPURenderPassColorAttachmentDescriptor(context, descriptor));
+    return adoptRef(*new WebGPURenderPassColorAttachmentDescriptor(context, WTFMove(descriptor)));
 }
 
-WebGPURenderPassColorAttachmentDescriptor::WebGPURenderPassColorAttachmentDescriptor(WebGPURenderingContext* context, GPURenderPassColorAttachmentDescriptor* descriptor)
-    : WebGPURenderPassAttachmentDescriptor(context, descriptor)
+WebGPURenderPassColorAttachmentDescriptor::WebGPURenderPassColorAttachmentDescriptor(WebGPURenderingContext& context, GPURenderPassColorAttachmentDescriptor&& descriptor)
+    : WebGPURenderPassAttachmentDescriptor(context)
+    , m_descriptor(WTFMove(descriptor))
 {
 }
 
 WebGPURenderPassColorAttachmentDescriptor::~WebGPURenderPassColorAttachmentDescriptor() = default;
 
-GPURenderPassColorAttachmentDescriptor* WebGPURenderPassColorAttachmentDescriptor::renderPassColorAttachmentDescriptor() const
+const GPURenderPassAttachmentDescriptor& WebGPURenderPassColorAttachmentDescriptor::descriptor() const
 {
-    return static_cast<GPURenderPassColorAttachmentDescriptor*>(renderPassAttachmentDescriptor());
+    return m_descriptor;
 }
 
 Vector<float> WebGPURenderPassColorAttachmentDescriptor::clearColor() const
 {
-    RefPtr<GPURenderPassColorAttachmentDescriptor> descriptor = renderPassColorAttachmentDescriptor();
-    if (!descriptor) {
-        Vector<float> black = { 0.0, 0.0, 0.0, 1.0 };
-        return black;
-    }
-    return descriptor->clearColor();
+    return m_descriptor.clearColor();
 }
 
 void WebGPURenderPassColorAttachmentDescriptor::setClearColor(const Vector<float>& newClearColor)
 {
-    RefPtr<GPURenderPassColorAttachmentDescriptor> descriptor = renderPassColorAttachmentDescriptor();
-    if (!descriptor)
-        return;
-
-    descriptor->setClearColor(newClearColor);
+    m_descriptor.setClearColor(newClearColor);
 }
 
 } // namespace WebCore
index ee89716..5646faa 100644 (file)
 
 #if ENABLE(WEBGPU)
 
-#include "WebGPUObject.h"
+#include "GPURenderPassColorAttachmentDescriptor.h"
 #include "WebGPURenderPassAttachmentDescriptor.h"
 
-#include <wtf/Vector.h>
-
 namespace WebCore {
 
-class GPURenderPassColorAttachmentDescriptor;
-
 class WebGPURenderPassColorAttachmentDescriptor : public WebGPURenderPassAttachmentDescriptor {
 public:
     virtual ~WebGPURenderPassColorAttachmentDescriptor();
-    static Ref<WebGPURenderPassColorAttachmentDescriptor> create(WebGPURenderingContext*, GPURenderPassColorAttachmentDescriptor*);
+    static Ref<WebGPURenderPassColorAttachmentDescriptor> create(WebGPURenderingContext&, GPURenderPassColorAttachmentDescriptor&&);
 
     Vector<float> clearColor() const;
     void setClearColor(const Vector<float>&);
 
-    GPURenderPassColorAttachmentDescriptor* renderPassColorAttachmentDescriptor() const;
-
-    bool isColorAttachmentDescriptor() const override { return true; }
-
 private:
-    WebGPURenderPassColorAttachmentDescriptor(WebGPURenderingContext*, GPURenderPassColorAttachmentDescriptor*);
+    WebGPURenderPassColorAttachmentDescriptor(WebGPURenderingContext&, GPURenderPassColorAttachmentDescriptor&&);
+
+    const GPURenderPassAttachmentDescriptor& descriptor() const final;
+    bool isColorAttachmentDescriptor() const final { return true; }
 
+    GPURenderPassColorAttachmentDescriptor m_descriptor;
 };
     
 } // namespace WebCore
index 5c4f834..6921679 100644 (file)
 
 #if ENABLE(WEBGPU)
 
-#include "GPURenderPassDepthAttachmentDescriptor.h"
-#include "GPUTexture.h"
 #include "WebGPURenderingContext.h"
 #include "WebGPUTexture.h"
 
 namespace WebCore {
 
-Ref<WebGPURenderPassDepthAttachmentDescriptor> WebGPURenderPassDepthAttachmentDescriptor::create(WebGPURenderingContext* context, GPURenderPassDepthAttachmentDescriptor* descriptor)
+Ref<WebGPURenderPassDepthAttachmentDescriptor> WebGPURenderPassDepthAttachmentDescriptor::create(WebGPURenderingContext& context, GPURenderPassDepthAttachmentDescriptor&& descriptor)
 {
-    return adoptRef(*new WebGPURenderPassDepthAttachmentDescriptor(context, descriptor));
+    return adoptRef(*new WebGPURenderPassDepthAttachmentDescriptor(context, WTFMove(descriptor)));
 }
 
-WebGPURenderPassDepthAttachmentDescriptor::WebGPURenderPassDepthAttachmentDescriptor(WebGPURenderingContext* context, GPURenderPassDepthAttachmentDescriptor* descriptor)
-    : WebGPURenderPassAttachmentDescriptor(context, descriptor)
+WebGPURenderPassDepthAttachmentDescriptor::WebGPURenderPassDepthAttachmentDescriptor(WebGPURenderingContext& context, GPURenderPassDepthAttachmentDescriptor&& descriptor)
+    : WebGPURenderPassAttachmentDescriptor(context)
+    , m_descriptor(WTFMove(descriptor))
 {
 }
 
@@ -49,25 +48,17 @@ WebGPURenderPassDepthAttachmentDescriptor::~WebGPURenderPassDepthAttachmentDescr
 
 double WebGPURenderPassDepthAttachmentDescriptor::clearDepth() const
 {
-    RefPtr<GPURenderPassDepthAttachmentDescriptor> descriptor = renderPassDepthAttachmentDescriptor();
-    if (!descriptor)
-        return 0;
-
-    return descriptor->clearDepth();
+    return m_descriptor.clearDepth();
 }
 
 void WebGPURenderPassDepthAttachmentDescriptor::setClearDepth(double newClearDepth)
 {
-    RefPtr<GPURenderPassDepthAttachmentDescriptor> descriptor = renderPassDepthAttachmentDescriptor();
-    if (!descriptor)
-        return;
-    
-    descriptor->setClearDepth(newClearDepth);
+    m_descriptor.setClearDepth(newClearDepth);
 }
 
-GPURenderPassDepthAttachmentDescriptor* WebGPURenderPassDepthAttachmentDescriptor::renderPassDepthAttachmentDescriptor() const
+const GPURenderPassAttachmentDescriptor& WebGPURenderPassDepthAttachmentDescriptor::descriptor() const
 {
-    return static_cast<GPURenderPassDepthAttachmentDescriptor*>(renderPassAttachmentDescriptor());
+    return m_descriptor;
 }
 
 } // namespace WebCore
index 603154c..a419366 100644 (file)
 
 #if ENABLE(WEBGPU)
 
-#include "WebGPUObject.h"
+#include "GPURenderPassDepthAttachmentDescriptor.h"
 #include "WebGPURenderPassAttachmentDescriptor.h"
 
 namespace WebCore {
 
-class GPURenderPassDepthAttachmentDescriptor;
-
-class WebGPURenderPassDepthAttachmentDescriptor : public WebGPURenderPassAttachmentDescriptor {
+class WebGPURenderPassDepthAttachmentDescriptor final : public WebGPURenderPassAttachmentDescriptor {
 public:
     virtual ~WebGPURenderPassDepthAttachmentDescriptor();
-    static Ref<WebGPURenderPassDepthAttachmentDescriptor> create(WebGPURenderingContext*, GPURenderPassDepthAttachmentDescriptor*);
+    static Ref<WebGPURenderPassDepthAttachmentDescriptor> create(WebGPURenderingContext&, GPURenderPassDepthAttachmentDescriptor&&);
 
     double clearDepth() const;
     void setClearDepth(double);
 
-    GPURenderPassDepthAttachmentDescriptor* renderPassDepthAttachmentDescriptor() const;
-
 private:
-    WebGPURenderPassDepthAttachmentDescriptor(WebGPURenderingContext*, GPURenderPassDepthAttachmentDescriptor*);
+    WebGPURenderPassDepthAttachmentDescriptor(WebGPURenderingContext&, GPURenderPassDepthAttachmentDescriptor&&);
+
+    const GPURenderPassAttachmentDescriptor& descriptor() const final;
+    bool isColorAttachmentDescriptor() const final { return false; }
 
+    GPURenderPassDepthAttachmentDescriptor m_descriptor;
 };
     
 } // namespace WebCore
index e7bef85..4f5595a 100644 (file)
 
 #if ENABLE(WEBGPU)
 
-#include "GPURenderPassColorAttachmentDescriptor.h"
-#include "GPURenderPassDepthAttachmentDescriptor.h"
-#include "GPURenderPassDescriptor.h"
-#include "WebGPURenderPassColorAttachmentDescriptor.h"
-#include "WebGPURenderPassDepthAttachmentDescriptor.h"
-#include "WebGPURenderingContext.h"
-
 namespace WebCore {
 
 Ref<WebGPURenderPassDescriptor> WebGPURenderPassDescriptor::create()
 {
-    return adoptRef(*new WebGPURenderPassDescriptor());
+    return adoptRef(*new WebGPURenderPassDescriptor);
 }
 
-WebGPURenderPassDescriptor::WebGPURenderPassDescriptor()
-    : WebGPUObject()
-{
-    m_renderPassDescriptor = GPURenderPassDescriptor::create();
-}
+WebGPURenderPassDescriptor::WebGPURenderPassDescriptor() = default;
 
 WebGPURenderPassDescriptor::~WebGPURenderPassDescriptor() = default;
 
-RefPtr<WebGPURenderPassDepthAttachmentDescriptor> WebGPURenderPassDescriptor::depthAttachment()
+WebGPURenderPassDepthAttachmentDescriptor& WebGPURenderPassDescriptor::depthAttachment()
 {
-    if (!m_renderPassDescriptor)
-        return nullptr;
-
-    if (!m_depthAttachmentDescriptor) {
-        RefPtr<GPURenderPassDepthAttachmentDescriptor> platformDepthAttachment = m_renderPassDescriptor->depthAttachment();
-        m_depthAttachmentDescriptor = WebGPURenderPassDepthAttachmentDescriptor::create(this->context(), platformDepthAttachment.get());
-    }
-    return m_depthAttachmentDescriptor;
+    if (!m_depthAttachment)
+        m_depthAttachment = WebGPURenderPassDepthAttachmentDescriptor::create(*context(), m_descriptor.depthAttachment());
+    return *m_depthAttachment;
 }
 
-Vector<RefPtr<WebGPURenderPassColorAttachmentDescriptor>> WebGPURenderPassDescriptor::colorAttachments()
+const Vector<RefPtr<WebGPURenderPassColorAttachmentDescriptor>>& WebGPURenderPassDescriptor::colorAttachments()
 {
-    if (!m_renderPassDescriptor)
-        return Vector<RefPtr<WebGPURenderPassColorAttachmentDescriptor>>();
-
-    if (!m_colorAttachmentDescriptors.size()) {
-        Vector<RefPtr<GPURenderPassColorAttachmentDescriptor>> platformColorAttachments = m_renderPassDescriptor->colorAttachments();
-        for (auto& attachment : platformColorAttachments)
-            m_colorAttachmentDescriptors.append(WebGPURenderPassColorAttachmentDescriptor::create(this->context(), attachment.get()));
+    if (m_colorAttachments.isEmpty()) {
+        auto attachments = m_descriptor.colorAttachments();
+        ASSERT(!attachments.isEmpty());
+        m_colorAttachments.reserveInitialCapacity(attachments.size());
+        for (auto& attachment : attachments)
+            m_colorAttachments.uncheckedAppend(WebGPURenderPassColorAttachmentDescriptor::create(*context(), WTFMove(attachment)));
     }
-    return m_colorAttachmentDescriptors;
+    return m_colorAttachments;
 }
 
 } // namespace WebCore
index b9d1872..d135faf 100644 (file)
 
 #if ENABLE(WEBGPU)
 
+#include "GPURenderPassDescriptor.h"
 #include "WebGPUObject.h"
 #include "WebGPURenderPassColorAttachmentDescriptor.h"
 #include "WebGPURenderPassDepthAttachmentDescriptor.h"
-
 #include <wtf/Vector.h>
 
 namespace WebCore {
 
-class GPURenderPassDescriptor;
-class WebGPURenderPassColorAttachmentDescriptor;
-class WebGPURenderPassDepthAttachmentDescriptor;
-
 class WebGPURenderPassDescriptor : public WebGPUObject {
 public:
     virtual ~WebGPURenderPassDescriptor();
     static Ref<WebGPURenderPassDescriptor> create();
 
-    RefPtr<WebGPURenderPassDepthAttachmentDescriptor> depthAttachment();
-    Vector<RefPtr<WebGPURenderPassColorAttachmentDescriptor>> colorAttachments();
+    WebGPURenderPassDepthAttachmentDescriptor& depthAttachment();
+    const Vector<RefPtr<WebGPURenderPassColorAttachmentDescriptor>>& colorAttachments();
 
-    GPURenderPassDescriptor* renderPassDescriptor() { return m_renderPassDescriptor.get(); }
+    const GPURenderPassDescriptor& descriptor() const { return m_descriptor; }
 
 private:
     WebGPURenderPassDescriptor();
 
-    Vector<RefPtr<WebGPURenderPassColorAttachmentDescriptor>> m_colorAttachmentDescriptors;
-    RefPtr<WebGPURenderPassDepthAttachmentDescriptor> m_depthAttachmentDescriptor;
+    Vector<RefPtr<WebGPURenderPassColorAttachmentDescriptor>> m_colorAttachments;
+    RefPtr<WebGPURenderPassDepthAttachmentDescriptor> m_depthAttachment;
 
-    RefPtr<GPURenderPassDescriptor> m_renderPassDescriptor;
+    GPURenderPassDescriptor m_descriptor;
 };
     
 } // namespace WebCore
index f868882..9491196 100644 (file)
 
 #if ENABLE(WEBGPU)
 
-#include "GPURenderPipelineColorAttachmentDescriptor.h"
-#include "WebGPURenderingContext.h"
-
 namespace WebCore {
 
-Ref<WebGPURenderPipelineColorAttachmentDescriptor> WebGPURenderPipelineColorAttachmentDescriptor::create(WebGPURenderingContext* context, GPURenderPipelineColorAttachmentDescriptor* descriptor)
+Ref<WebGPURenderPipelineColorAttachmentDescriptor> WebGPURenderPipelineColorAttachmentDescriptor::create(WebGPURenderingContext& context, GPURenderPipelineColorAttachmentDescriptor&& descriptor)
 {
-    return adoptRef(*new WebGPURenderPipelineColorAttachmentDescriptor(context, descriptor));
+    return adoptRef(*new WebGPURenderPipelineColorAttachmentDescriptor(context, WTFMove(descriptor)));
 }
 
-WebGPURenderPipelineColorAttachmentDescriptor::WebGPURenderPipelineColorAttachmentDescriptor(WebGPURenderingContext* context, GPURenderPipelineColorAttachmentDescriptor* descriptor)
-    : WebGPUObject(context)
-    , m_renderPipelineColorAttachmentDescriptor(descriptor)
+WebGPURenderPipelineColorAttachmentDescriptor::WebGPURenderPipelineColorAttachmentDescriptor(WebGPURenderingContext& context, GPURenderPipelineColorAttachmentDescriptor&& descriptor)
+    : WebGPUObject { &context }
+    , m_descriptor { WTFMove(descriptor) }
 {
 }
 
-WebGPURenderPipelineColorAttachmentDescriptor::~WebGPURenderPipelineColorAttachmentDescriptor() = default;
-
-unsigned long WebGPURenderPipelineColorAttachmentDescriptor::pixelFormat() const
+unsigned WebGPURenderPipelineColorAttachmentDescriptor::pixelFormat() const
 {
-    if (!m_renderPipelineColorAttachmentDescriptor)
-        return 0; // FIXME: probably a real value for unknown
-
-    return m_renderPipelineColorAttachmentDescriptor->pixelFormat();
+    return m_descriptor.pixelFormat();
 }
 
-void WebGPURenderPipelineColorAttachmentDescriptor::setPixelFormat(unsigned long newPixelFormat)
+void WebGPURenderPipelineColorAttachmentDescriptor::setPixelFormat(unsigned newPixelFormat)
 {
-    if (!m_renderPipelineColorAttachmentDescriptor)
-        return;
-
-    m_renderPipelineColorAttachmentDescriptor->setPixelFormat(newPixelFormat);
+    m_descriptor.setPixelFormat(newPixelFormat);
 }
 
 } // namespace WebCore
index 7a4aaff..12e1859 100644 (file)
 
 #if ENABLE(WEBGPU)
 
+#include "GPURenderPipelineColorAttachmentDescriptor.h"
 #include "WebGPUObject.h"
 
-
 namespace WebCore {
 
-class GPURenderPipelineColorAttachmentDescriptor;
-
 class WebGPURenderPipelineColorAttachmentDescriptor : public WebGPUObject {
 public:
-    virtual ~WebGPURenderPipelineColorAttachmentDescriptor();
-    static Ref<WebGPURenderPipelineColorAttachmentDescriptor> create(WebGPURenderingContext*, GPURenderPipelineColorAttachmentDescriptor*);
-
-    unsigned long pixelFormat() const;
-    void setPixelFormat(unsigned long);
+    static Ref<WebGPURenderPipelineColorAttachmentDescriptor> create(WebGPURenderingContext&, GPURenderPipelineColorAttachmentDescriptor&&);
 
-    GPURenderPipelineColorAttachmentDescriptor* renderPipelineColorAttachmentDescriptor() { return m_renderPipelineColorAttachmentDescriptor.get(); }
+    unsigned pixelFormat() const;
+    void setPixelFormat(unsigned);
 
 private:
-    WebGPURenderPipelineColorAttachmentDescriptor(WebGPURenderingContext*, GPURenderPipelineColorAttachmentDescriptor*);
+    WebGPURenderPipelineColorAttachmentDescriptor(WebGPURenderingContext&, GPURenderPipelineColorAttachmentDescriptor&&);
 
-    RefPtr<GPURenderPipelineColorAttachmentDescriptor> m_renderPipelineColorAttachmentDescriptor;
+    GPURenderPipelineColorAttachmentDescriptor m_descriptor;
 };
     
 } // namespace WebCore
index be29c8b..9eff795 100644 (file)
@@ -30,7 +30,6 @@
 
 #include "GPUFunction.h"
 #include "GPURenderPipelineColorAttachmentDescriptor.h"
-#include "GPURenderPipelineDescriptor.h"
 #include "WebGPUFunction.h"
 #include "WebGPURenderPipelineColorAttachmentDescriptor.h"
 #include "WebGPURenderingContext.h"
@@ -39,83 +38,72 @@ namespace WebCore {
 
 Ref<WebGPURenderPipelineDescriptor> WebGPURenderPipelineDescriptor::create()
 {
-    return adoptRef(*new WebGPURenderPipelineDescriptor());
+    return adoptRef(*new WebGPURenderPipelineDescriptor);
 }
 
-WebGPURenderPipelineDescriptor::WebGPURenderPipelineDescriptor()
-    : WebGPUObject()
-{
-    m_renderPipelineDescriptor = GPURenderPipelineDescriptor::create();
-}
+WebGPURenderPipelineDescriptor::WebGPURenderPipelineDescriptor() = default;
 
 WebGPURenderPipelineDescriptor::~WebGPURenderPipelineDescriptor() = default;
 
-RefPtr<WebGPUFunction> WebGPURenderPipelineDescriptor::vertexFunction() const
+WebGPUFunction* WebGPURenderPipelineDescriptor::vertexFunction() const
 {
-    return m_vertexFunction;
+    return m_vertexFunction.get();
 }
 
-void WebGPURenderPipelineDescriptor::setVertexFunction(RefPtr<WebGPUFunction> newVertexFunction)
+void WebGPURenderPipelineDescriptor::setVertexFunction(RefPtr<WebGPUFunction>&& newVertexFunction)
 {
+    // FIXME: Why can't we set this to null?
     if (!newVertexFunction)
         return;
 
-    m_vertexFunction = newVertexFunction;
+    m_vertexFunction = WTFMove(newVertexFunction);
 
-    if (m_renderPipelineDescriptor)
-        m_renderPipelineDescriptor->setVertexFunction(newVertexFunction->function());
+    m_descriptor.setVertexFunction(m_vertexFunction->function());
 }
 
-RefPtr<WebGPUFunction> WebGPURenderPipelineDescriptor::fragmentFunction() const
+WebGPUFunction* WebGPURenderPipelineDescriptor::fragmentFunction() const
 {
-    return m_fragmentFunction;
+    return m_fragmentFunction.get();
 }
 
-void WebGPURenderPipelineDescriptor::setFragmentFunction(RefPtr<WebGPUFunction> newFragmentFunction)
+void WebGPURenderPipelineDescriptor::setFragmentFunction(RefPtr<WebGPUFunction>&& newFragmentFunction)
 {
+    // FIXME: Why can't we set this to null?
     if (!newFragmentFunction)
         return;
 
-    m_fragmentFunction = newFragmentFunction;
+    m_fragmentFunction = WTFMove(newFragmentFunction);
 
-    if (m_renderPipelineDescriptor)
-        m_renderPipelineDescriptor->setFragmentFunction(newFragmentFunction->function());
+    m_descriptor.setFragmentFunction(m_fragmentFunction->function());
 }
 
-Vector<RefPtr<WebGPURenderPipelineColorAttachmentDescriptor>> WebGPURenderPipelineDescriptor::colorAttachments()
+const Vector<RefPtr<WebGPURenderPipelineColorAttachmentDescriptor>>& WebGPURenderPipelineDescriptor::colorAttachments()
 {
-    if (!m_renderPipelineDescriptor)
-        return Vector<RefPtr<WebGPURenderPipelineColorAttachmentDescriptor>>();
-
-    if (!m_colorAttachmentDescriptors.size()) {
-        Vector<RefPtr<GPURenderPipelineColorAttachmentDescriptor>> platformColorAttachments = m_renderPipelineDescriptor->colorAttachments();
-        for (auto& attachment : platformColorAttachments)
-            m_colorAttachmentDescriptors.append(WebGPURenderPipelineColorAttachmentDescriptor::create(this->context(), attachment.get()));
+    if (!m_colorAttachments.size()) {
+        auto attachments = m_descriptor.colorAttachments();
+        m_colorAttachments.reserveInitialCapacity(attachments.size());
+        for (auto& attachment : attachments)
+            m_colorAttachments.uncheckedAppend(WebGPURenderPipelineColorAttachmentDescriptor::create(*context(), WTFMove(attachment)));
     }
-    return m_colorAttachmentDescriptors;
+    return m_colorAttachments;
 }
 
-unsigned long WebGPURenderPipelineDescriptor::depthAttachmentPixelFormat() const
+unsigned WebGPURenderPipelineDescriptor::depthAttachmentPixelFormat() const
 {
-    if (!m_renderPipelineDescriptor)
-        return 0; // FIXME: probably a real value for unknown
-
-    return m_renderPipelineDescriptor->depthAttachmentPixelFormat();
-
+    return m_descriptor.depthAttachmentPixelFormat();
 }
 
-void WebGPURenderPipelineDescriptor::setDepthAttachmentPixelFormat(unsigned long newPixelFormat)
+void WebGPURenderPipelineDescriptor::setDepthAttachmentPixelFormat(unsigned newPixelFormat)
 {
-    if (!m_renderPipelineDescriptor)
-        return;
-
-    m_renderPipelineDescriptor->setDepthAttachmentPixelFormat(newPixelFormat);
+    m_descriptor.setDepthAttachmentPixelFormat(newPixelFormat);
 }
 
 void WebGPURenderPipelineDescriptor::reset()
 {
     m_vertexFunction = nullptr;
     m_fragmentFunction = nullptr;
+
+    // FIXME: Why doesn't this clear out the functions on m_descriptor?
 }
 
 } // namespace WebCore
index 874e3df..c293492 100644 (file)
@@ -27,9 +27,9 @@
 
 #if ENABLE(WEBGPU)
 
+#include "GPURenderPipelineDescriptor.h"
 #include "WebGPUObject.h"
 #include "WebGPURenderPipelineColorAttachmentDescriptor.h"
-
 #include <wtf/Vector.h>
 
 namespace WebCore {
@@ -44,20 +44,20 @@ public:
     virtual ~WebGPURenderPipelineDescriptor();
     static Ref<WebGPURenderPipelineDescriptor> create();
 
-    RefPtr<WebGPUFunction> vertexFunction() const;
-    void setVertexFunction(RefPtr<WebGPUFunction>);
+    WebGPUFunction* vertexFunction() const;
+    void setVertexFunction(RefPtr<WebGPUFunction>&&);
 
-    RefPtr<WebGPUFunction> fragmentFunction() const;
-    void setFragmentFunction(RefPtr<WebGPUFunction>);
+    WebGPUFunction* fragmentFunction() const;
+    void setFragmentFunction(RefPtr<WebGPUFunction>&&);
 
-    Vector<RefPtr<WebGPURenderPipelineColorAttachmentDescriptor>> colorAttachments();
+    const Vector<RefPtr<WebGPURenderPipelineColorAttachmentDescriptor>>& colorAttachments();
 
-    unsigned long depthAttachmentPixelFormat() const;
-    void setDepthAttachmentPixelFormat(unsigned long);
+    unsigned depthAttachmentPixelFormat() const;
+    void setDepthAttachmentPixelFormat(unsigned);
 
     void reset();
 
-    GPURenderPipelineDescriptor* renderPipelineDescriptor() { return m_renderPipelineDescriptor.get(); }
+    const GPURenderPipelineDescriptor& descriptor() { return m_descriptor; }
 
 private:
     WebGPURenderPipelineDescriptor();
@@ -65,9 +65,9 @@ private:
     RefPtr<WebGPUFunction> m_vertexFunction;
     RefPtr<WebGPUFunction> m_fragmentFunction;
 
-    Vector<RefPtr<WebGPURenderPipelineColorAttachmentDescriptor>> m_colorAttachmentDescriptors;
+    Vector<RefPtr<WebGPURenderPipelineColorAttachmentDescriptor>> m_colorAttachments;
 
-    RefPtr<GPURenderPipelineDescriptor> m_renderPipelineDescriptor;
+    GPURenderPipelineDescriptor m_descriptor;
 };
 
 } // namespace WebCore
index e2b1afd..f3c713e 100644 (file)
 
 #if ENABLE(WEBGPU)
 
-#include "GPURenderPipelineState.h"
 #include "WebGPURenderPipelineDescriptor.h"
 #include "WebGPURenderingContext.h"
 
 namespace WebCore {
 
-Ref<WebGPURenderPipelineState> WebGPURenderPipelineState::create(WebGPURenderingContext* context, WebGPURenderPipelineDescriptor* descriptor)
+Ref<WebGPURenderPipelineState> WebGPURenderPipelineState::create(WebGPURenderingContext& context, const GPURenderPipelineDescriptor& descriptor)
 {
     return adoptRef(*new WebGPURenderPipelineState(context, descriptor));
 }
 
-WebGPURenderPipelineState::WebGPURenderPipelineState(WebGPURenderingContext* context, WebGPURenderPipelineDescriptor* descriptor)
-    : WebGPUObject(context)
+WebGPURenderPipelineState::WebGPURenderPipelineState(WebGPURenderingContext& context, const GPURenderPipelineDescriptor& descriptor)
+    : WebGPUObject { &context }
+    , m_state { context.device(), descriptor }
 {
-    if (!context || !descriptor)
-        return;
-    m_renderPipelineState = GPURenderPipelineState::create(context->device().get(), descriptor->renderPipelineDescriptor());
 }
 
-WebGPURenderPipelineState::~WebGPURenderPipelineState() = default;
-
 String WebGPURenderPipelineState::label() const
 {
-    if (!m_renderPipelineState)
-        return emptyString();
-
-    return m_renderPipelineState->label();
+    return m_state.label();
 }
 
 void WebGPURenderPipelineState::setLabel(const String& label)
 {
-    if (!m_renderPipelineState)
-        return;
-
-    m_renderPipelineState->setLabel(label);
+    m_state.setLabel(label);
 }
 
 } // namespace WebCore
index 464c064..f27dad8 100644 (file)
 
 #if ENABLE(WEBGPU)
 
+#include "GPURenderPipelineState.h"
 #include "WebGPUObject.h"
 
-#include <wtf/Vector.h>
-
 namespace WebCore {
 
-class GPURenderPipelineState;
-class WebGPURenderPipelineDescriptor;
-
 class WebGPURenderPipelineState : public WebGPUObject {
 public:
-    virtual ~WebGPURenderPipelineState();
-    static Ref<WebGPURenderPipelineState> create(WebGPURenderingContext*, WebGPURenderPipelineDescriptor*);
+    static Ref<WebGPURenderPipelineState> create(WebGPURenderingContext&, const GPURenderPipelineDescriptor&);
 
     String label() const;
     void setLabel(const String&);
 
-    GPURenderPipelineState* renderPipelineState() { return m_renderPipelineState.get(); }
+    const GPURenderPipelineState& state() const { return m_state; }
 
 private:
-    WebGPURenderPipelineState(WebGPURenderingContext*, WebGPURenderPipelineDescriptor*);
+    WebGPURenderPipelineState(WebGPURenderingContext&, const GPURenderPipelineDescriptor&);
 
-    RefPtr<GPURenderPipelineState> m_renderPipelineState;
+    GPURenderPipelineState m_state;
 };
     
 } // namespace WebCore
index c161aa8..fe74779 100644 (file)
@@ -46,7 +46,6 @@
 #include "WebGPURenderPipelineState.h"
 #include "WebGPUTexture.h"
 #include "WebGPUTextureDescriptor.h"
-
 #include <JavaScriptCore/ArrayBuffer.h>
 #include <JavaScriptCore/JSCInlines.h>
 #include <JavaScriptCore/TypedArrayInlines.h>
@@ -71,17 +70,16 @@ namespace WebCore {
 
 static const int kMaxTextureSize = 4096;
 
-
 std::unique_ptr<WebGPURenderingContext> WebGPURenderingContext::create(CanvasBase& canvas)
 {
-    RefPtr<GPUDevice> device(GPUDevice::create());
+    GPUDevice device;
 
     if (!device) {
         // FIXME: WebGPU - dispatch an event here for the failure.
         return nullptr;
     }
 
-    auto renderingContext = std::unique_ptr<WebGPURenderingContext>(new WebGPURenderingContext(canvas, device.releaseNonNull()));
+    auto renderingContext = std::unique_ptr<WebGPURenderingContext>(new WebGPURenderingContext(canvas, WTFMove(device)));
     renderingContext->suspendIfNeeded();
 
     InspectorInstrumentation::didCreateCanvasRenderingContext(*renderingContext);
@@ -89,7 +87,7 @@ std::unique_ptr<WebGPURenderingContext> WebGPURenderingContext::create(CanvasBas
     return renderingContext;
 }
 
-WebGPURenderingContext::WebGPURenderingContext(CanvasBase& canvas, Ref<GPUDevice>&& device)
+WebGPURenderingContext::WebGPURenderingContext(CanvasBase& canvas, GPUDevice&& device)
     : GPUBasedCanvasRenderingContext(canvas)
     , m_device(WTFMove(device))
 {
@@ -109,7 +107,7 @@ void WebGPURenderingContext::initializeNewContext()
     // FIXME: WebGPU - Maybe we should reset a bunch of stuff here.
 
     IntSize canvasSize = clampedCanvasSize();
-    m_device->reshape(canvasSize.width(), canvasSize.height());
+    m_device.reshape(canvasSize.width(), canvasSize.height());
 }
 
 IntSize WebGPURenderingContext::clampedCanvasSize() const
@@ -139,66 +137,58 @@ bool WebGPURenderingContext::canSuspendForDocumentSuspension() const
 
 PlatformLayer* WebGPURenderingContext::platformLayer() const
 {
-    return m_device->platformLayer();
+    return m_device.platformLayer();
 }
 
 void WebGPURenderingContext::markLayerComposited()
 {
-    m_device->markLayerComposited();
+    m_device.markLayerComposited();
 }
 
 void WebGPURenderingContext::reshape(int width, int height)
 {
     // FIXME: WebGPU - Do we need to reset stuff here?
-    m_device->reshape(width, height);
+    m_device.reshape(width, height);
 }
 
-RefPtr<WebGPULibrary> WebGPURenderingContext::createLibrary(const String sourceCode)
+Ref<WebGPULibrary> WebGPURenderingContext::createLibrary(const String& sourceCode)
 {
-    RefPtr<WebGPULibrary> library = WebGPULibrary::create(this, sourceCode);
-    return library;
+    return WebGPULibrary::create(*this, sourceCode);
 }
 
-RefPtr<WebGPURenderPipelineState> WebGPURenderingContext::createRenderPipelineState(WebGPURenderPipelineDescriptor& descriptor)
+Ref<WebGPURenderPipelineState> WebGPURenderingContext::createRenderPipelineState(WebGPURenderPipelineDescriptor& descriptor)
 {
-    RefPtr<WebGPURenderPipelineState> state = WebGPURenderPipelineState::create(this, &descriptor);
-    return state;
+    return WebGPURenderPipelineState::create(*this, descriptor.descriptor());
 }
 
-RefPtr<WebGPUDepthStencilState> WebGPURenderingContext::createDepthStencilState(WebGPUDepthStencilDescriptor& descriptor)
+Ref<WebGPUDepthStencilState> WebGPURenderingContext::createDepthStencilState(WebGPUDepthStencilDescriptor& descriptor)
 {
-    RefPtr<WebGPUDepthStencilState> state = WebGPUDepthStencilState::create(this, &descriptor);
-    return state;
+    return WebGPUDepthStencilState::create(*this, descriptor.descriptor());
 }
 
-RefPtr<WebGPUComputePipelineState> WebGPURenderingContext::createComputePipelineState(WebGPUFunction& function)
+Ref<WebGPUComputePipelineState> WebGPURenderingContext::createComputePipelineState(WebGPUFunction& function)
 {
-    RefPtr<WebGPUComputePipelineState> state = WebGPUComputePipelineState::create(this, &function);
-    return state;
+    return WebGPUComputePipelineState::create(*this, function.function());
 }
 
-RefPtr<WebGPUCommandQueue> WebGPURenderingContext::createCommandQueue()
+Ref<WebGPUCommandQueue> WebGPURenderingContext::createCommandQueue()
 {
-    RefPtr<WebGPUCommandQueue> queue = WebGPUCommandQueue::create(this);
-    return queue;
+    return WebGPUCommandQueue::create(*this);
 }
 
-RefPtr<WebGPUDrawable> WebGPURenderingContext::nextDrawable()
+Ref<WebGPUDrawable> WebGPURenderingContext::nextDrawable()
 {
-    RefPtr<WebGPUDrawable> drawable = WebGPUDrawable::create(this);
-    return drawable;
+    return WebGPUDrawable::create(*this);
 }
 
-RefPtr<WebGPUBuffer> WebGPURenderingContext::createBuffer(ArrayBufferView& data)
+RefPtr<WebGPUBuffer> WebGPURenderingContext::createBuffer(JSC::ArrayBufferView& data)
 {
-    RefPtr<WebGPUBuffer> buffer = WebGPUBuffer::create(this, &data);
-    return buffer;
+    return WebGPUBuffer::create(*this, data);
 }
 
-RefPtr<WebGPUTexture> WebGPURenderingContext::createTexture(WebGPUTextureDescriptor& descriptor)
+Ref<WebGPUTexture> WebGPURenderingContext::createTexture(WebGPUTextureDescriptor& descriptor)
 {
-    RefPtr<WebGPUTexture> texture = WebGPUTexture::create(this, &descriptor);
-    return texture;
+    return WebGPUTexture::create(*this, descriptor.descriptor());
 }
 
 } // namespace WebCore
index 33cd166..7565804 100644 (file)
 
 #include "GPUBasedCanvasRenderingContext.h"
 #include "GPUDevice.h"
-#include <JavaScriptCore/ArrayBuffer.h>
+
+namespace JSC {
+class ArrayBufferView;
+}
 
 namespace WebCore {
 
+class WebGPUBuffer;
 class WebGPUCommandQueue;
 class WebGPUComputePipelineState;
+class WebGPUDepthStencilDescriptor;
+class WebGPUDepthStencilState;
+class WebGPUDrawable;
 class WebGPUFunction;
 class WebGPULibrary;
 class WebGPURenderPipelineDescriptor;
 class WebGPURenderPipelineState;
-class WebGPUDepthStencilDescriptor;
-class WebGPUDepthStencilState;
-class WebGPURenderPassDescriptor;
-class WebGPUDrawable;
-class WebGPUBuffer;
 class WebGPUTexture;
 class WebGPUTextureDescriptor;
 
-class WebGPURenderingContext : public GPUBasedCanvasRenderingContext {
+class WebGPURenderingContext final : public GPUBasedCanvasRenderingContext {
 public:
     static std::unique_ptr<WebGPURenderingContext> create(CanvasBase&);
 
+    // FIXME: IDL file says this is not nullable, but this function can return null.
     HTMLCanvasElement* canvas() const;
 
-    bool isWebGPU() const final { return true; }
-
-    void reshape(int width, int height) final;
-
-    void markLayerComposited() final;
-
-    PlatformLayer* platformLayer() const override;
+    Ref<WebGPULibrary> createLibrary(const String&);
+    Ref<WebGPURenderPipelineState> createRenderPipelineState(WebGPURenderPipelineDescriptor&);
+    Ref<WebGPUDepthStencilState> createDepthStencilState(WebGPUDepthStencilDescriptor&);
+    Ref<WebGPUComputePipelineState> createComputePipelineState(WebGPUFunction&);
+    Ref<WebGPUCommandQueue> createCommandQueue();
+    Ref<WebGPUDrawable> nextDrawable();
+    RefPtr<WebGPUBuffer> createBuffer(JSC::ArrayBufferView&);
+    Ref<WebGPUTexture> createTexture(WebGPUTextureDescriptor&);
 
-    RefPtr<GPUDevice> device() { return m_device; }
+    const GPUDevice& device() const { return m_device; }
 
-    // WebGPU entry points
-
-    RefPtr<WebGPULibrary> createLibrary(const String);
-
-    RefPtr<WebGPURenderPipelineState> createRenderPipelineState(WebGPURenderPipelineDescriptor&);
-
-    RefPtr<WebGPUDepthStencilState> createDepthStencilState(WebGPUDepthStencilDescriptor&);
-
-    RefPtr<WebGPUComputePipelineState> createComputePipelineState(WebGPUFunction&);
-
-    RefPtr<WebGPUCommandQueue> createCommandQueue();
-
-    RefPtr<WebGPUDrawable> nextDrawable();
-
-    RefPtr<WebGPUBuffer> createBuffer(ArrayBufferView& data);
-
-    RefPtr<WebGPUTexture> createTexture(WebGPUTextureDescriptor&);
+private:
+    WebGPURenderingContext(CanvasBase&, GPUDevice&&);
 
-protected:
-    // ActiveDOMObject
-    bool hasPendingActivity() const override;
-    void stop() override;
-    const char* activeDOMObjectName() const override;
-    bool canSuspendForDocumentSuspension() const override;
+    bool hasPendingActivity() const final;
+    void stop() final;
+    const char* activeDOMObjectName() const final;
+    bool canSuspendForDocumentSuspension() const final;
 
     IntSize clampedCanvasSize() const;
     void initializeNewContext();
 
-private:
-    WebGPURenderingContext(CanvasBase&, Ref<GPUDevice>&&);
+    bool isWebGPU() const final { return true; }
+
+    void reshape(int width, int height) final;
+    void markLayerComposited() final;
+    PlatformLayer* platformLayer() const final;
 
-    RefPtr<GPUDevice> m_device;
+    GPUDevice m_device;
 };
 
 } // namespace WebCore
index 618ec04..f20454e 100644 (file)
 
     WebGPULibrary createLibrary(DOMString sourceCode);
 
-    WebGPURenderPipelineState? createRenderPipelineState(WebGPURenderPipelineDescriptor descriptor);
-    WebGPUDepthStencilState? createDepthStencilState(WebGPUDepthStencilDescriptor descriptor);
-    WebGPUComputePipelineState? createComputePipelineState(WebGPUFunction function);
+    WebGPURenderPipelineState createRenderPipelineState(WebGPURenderPipelineDescriptor descriptor);
+    WebGPUDepthStencilState createDepthStencilState(WebGPUDepthStencilDescriptor descriptor);
+    WebGPUComputePipelineState createComputePipelineState(WebGPUFunction function);
 
-    WebGPUCommandQueue? createCommandQueue();
+    WebGPUCommandQueue createCommandQueue();
 
-    WebGPUDrawable? nextDrawable();
+    WebGPUDrawable nextDrawable();
 
     WebGPUBuffer? createBuffer(ArrayBufferView data);
 
-    WebGPUTexture? createTexture(WebGPUTextureDescriptor descriptor);
+    WebGPUTexture createTexture(WebGPUTextureDescriptor descriptor);
 
 };
index 4dd4ea3..5c121c5 100644 (file)
@@ -30,9 +30,9 @@
 namespace WebCore {
     
 struct WebGPUSize {
-    unsigned long width;
-    unsigned long height;
-    unsigned long depth;
+    unsigned width;
+    unsigned height;
+    unsigned depth;
 };
     
 } // namespace WebCore
index 6588df8..9ec89f6 100644 (file)
 
 #if ENABLE(WEBGPU)
 
-#include "GPUTexture.h"
 #include "WebGPURenderingContext.h"
-#include "WebGPUTextureDescriptor.h"
 
 namespace WebCore {
 
-Ref<WebGPUTexture> WebGPUTexture::createFromDrawableTexture(WebGPURenderingContext* context, RefPtr<GPUTexture>&& drawableTexture)
+Ref<WebGPUTexture> WebGPUTexture::createFromDrawableTexture(WebGPURenderingContext& context, GPUTexture&& texture)
 {
-    return adoptRef(*new WebGPUTexture(context, WTFMove(drawableTexture)));
+    return adoptRef(*new WebGPUTexture(context, WTFMove(texture)));
 }
 
-Ref<WebGPUTexture> WebGPUTexture::create(WebGPURenderingContext* context, WebGPUTextureDescriptor* descriptor)
+Ref<WebGPUTexture> WebGPUTexture::create(WebGPURenderingContext& context, const GPUTextureDescriptor& descriptor)
 {
     return adoptRef(*new WebGPUTexture(context, descriptor));
 }
 
-WebGPUTexture::WebGPUTexture(WebGPURenderingContext* context, RefPtr<GPUTexture>&& drawableTexture)
-    : WebGPUObject(context)
-    , m_texture(WTFMove(drawableTexture))
+WebGPUTexture::WebGPUTexture(WebGPURenderingContext& context, GPUTexture&& texture)
+    : WebGPUObject { &context }
+    , m_texture { WTFMove(texture) }
 {
 }
 
-WebGPUTexture::WebGPUTexture(WebGPURenderingContext* context, WebGPUTextureDescriptor* descriptor)
-    : WebGPUObject(context)
+WebGPUTexture::WebGPUTexture(WebGPURenderingContext& context, const GPUTextureDescriptor& descriptor)
+    : WebGPUObject { &context }
+    , m_texture { context.device(), descriptor }
 {
-    m_texture = context->device()->createTexture(descriptor->textureDescriptor());
-}
-
-WebGPUTexture::~WebGPUTexture() = default;
-
-unsigned long WebGPUTexture::width() const
-{
-    if (!m_texture)
-        return 0;
-    
-    return m_texture->width();
-}
-
-unsigned long WebGPUTexture::height() const
-{
-    if (!m_texture)
-        return 0;
-
-    return m_texture->height();
 }
 
 } // namespace WebCore
index 30f2e4d..5740128 100644 (file)
 
 #if ENABLE(WEBGPU)
 
+#include "GPUTexture.h"
 #include "WebGPUObject.h"
 
 namespace WebCore {
 
-class GPUTexture;
-class WebGPUTextureDescriptor;
+class GPUTextureDescriptor;
 
 class WebGPUTexture : public WebGPUObject {
 public:
-    virtual ~WebGPUTexture();
-    static Ref<WebGPUTexture> createFromDrawableTexture(WebGPURenderingContext*, RefPtr<GPUTexture>&&);
-    static Ref<WebGPUTexture> create(WebGPURenderingContext*, WebGPUTextureDescriptor*);
+    static Ref<WebGPUTexture> createFromDrawableTexture(WebGPURenderingContext&, GPUTexture&&);
+    static Ref<WebGPUTexture> create(WebGPURenderingContext&, const GPUTextureDescriptor&);
 
-    unsigned long width() const;
-    unsigned long height() const;
+    unsigned width() const { return m_texture.width(); }
+    unsigned height() const { return m_texture.height(); }
 
-    GPUTexture* texture() const { return m_texture.get(); }
+    const GPUTexture& texture() const { return m_texture; }
 
 private:
-    WebGPUTexture(WebGPURenderingContext*, RefPtr<GPUTexture>&&);
-    WebGPUTexture(WebGPURenderingContext*, WebGPUTextureDescriptor*);
+    WebGPUTexture(WebGPURenderingContext&, GPUTexture&&);
+    WebGPUTexture(WebGPURenderingContext&, const GPUTextureDescriptor&);
 
-    RefPtr<GPUTexture> m_texture;
+    GPUTexture m_texture;
 };
     
 } // namespace WebCore
index f7a33c6..b8d735b 100644 (file)
 
 #if ENABLE(WEBGPU)
 
-#include "GPUTextureDescriptor.h"
-#include "WebGPURenderingContext.h"
-
 namespace WebCore {
 
-Ref<WebGPUTextureDescriptor> WebGPUTextureDescriptor::create(unsigned long pixelFormat, unsigned long width, unsigned long height, bool mipmapped)
+Ref<WebGPUTextureDescriptor> WebGPUTextureDescriptor::create(unsigned pixelFormat, unsigned width, unsigned height, bool mipmapped)
 {
     return adoptRef(*new WebGPUTextureDescriptor(pixelFormat, width, height, mipmapped));
 }
 
-WebGPUTextureDescriptor::WebGPUTextureDescriptor(unsigned long pixelFormat, unsigned long width, unsigned long height, bool mipmapped)
-    : WebGPUObject()
+WebGPUTextureDescriptor::WebGPUTextureDescriptor(unsigned pixelFormat, unsigned width, unsigned height, bool mipmapped)
+    : m_descriptor { pixelFormat, width, height, mipmapped }
 {
-    m_textureDescriptor = GPUTextureDescriptor::create(pixelFormat, width, height, mipmapped);
 }
 
-WebGPUTextureDescriptor::~WebGPUTextureDescriptor() = default;
-
-unsigned long WebGPUTextureDescriptor::width() const
+unsigned WebGPUTextureDescriptor::width() const
 {
-    if (!m_textureDescriptor)
-        return 0;
-
-    return m_textureDescriptor->width();
+    return m_descriptor.width();
 }
 
-void WebGPUTextureDescriptor::setWidth(unsigned long width)
+void WebGPUTextureDescriptor::setWidth(unsigned width)
 {
-    if (!m_textureDescriptor)
-        return;
-
-    m_textureDescriptor->setWidth(width);
+    m_descriptor.setWidth(width);
 }
 
-unsigned long WebGPUTextureDescriptor::height() const
+unsigned WebGPUTextureDescriptor::height() const
 {
-    if (!m_textureDescriptor)
-        return 0;
-
-    return m_textureDescriptor->height();
+    return m_descriptor.height();
 }
 
-void WebGPUTextureDescriptor::setHeight(unsigned long height)
+void WebGPUTextureDescriptor::setHeight(unsigned height)
 {
-    if (!m_textureDescriptor)
-        return;
-    
-    m_textureDescriptor->setHeight(height);
+    m_descriptor.setHeight(height);
 }
 
-unsigned long WebGPUTextureDescriptor::sampleCount() const
+unsigned WebGPUTextureDescriptor::sampleCount() const
 {
-    if (!m_textureDescriptor)
-        return 0;
-
-    return m_textureDescriptor->sampleCount();
+    return m_descriptor.sampleCount();
 }
 
-void WebGPUTextureDescriptor::setSampleCount(unsigned long sampleCount)
+void WebGPUTextureDescriptor::setSampleCount(unsigned sampleCount)
 {
-    if (!m_textureDescriptor)
-        return;
-    
-    m_textureDescriptor->setSampleCount(sampleCount);
+    m_descriptor.setSampleCount(sampleCount);
 }
 
-unsigned long WebGPUTextureDescriptor::textureType() const
+unsigned WebGPUTextureDescriptor::textureType() const
 {
-    if (!m_textureDescriptor)
-        return 0;
-
-    return m_textureDescriptor->textureType();
+    return m_descriptor.textureType();
 }
 
-void WebGPUTextureDescriptor::setTextureType(unsigned long textureType)
+void WebGPUTextureDescriptor::setTextureType(unsigned textureType)
 {
-    if (!m_textureDescriptor)
-        return;
-    
-    m_textureDescriptor->setTextureType(textureType);
+    m_descriptor.setTextureType(textureType);
 }
 
-unsigned long WebGPUTextureDescriptor::storageMode() const
+unsigned WebGPUTextureDescriptor::storageMode() const
 {
-    if (!m_textureDescriptor)
-        return 0;
-
-    return m_textureDescriptor->storageMode();
+    return m_descriptor.storageMode();
 }
 
-void WebGPUTextureDescriptor::setStorageMode(unsigned long storageMode)
+void WebGPUTextureDescriptor::setStorageMode(unsigned storageMode)
 {
-    if (!m_textureDescriptor)
-        return;
-    
-    m_textureDescriptor->setStorageMode(storageMode);
+    m_descriptor.setStorageMode(storageMode);
 }
 
-unsigned long WebGPUTextureDescriptor::usage() const
+unsigned WebGPUTextureDescriptor::usage() const
 {
-    if (!m_textureDescriptor)
-        return 0;
-
-    return m_textureDescriptor->usage();
+    return m_descriptor.usage();
 }
 
-void WebGPUTextureDescriptor::setUsage(unsigned long usage)
+void WebGPUTextureDescriptor::setUsage(unsigned usage)
 {
-    if (!m_textureDescriptor)
-        return;
-
-    m_textureDescriptor->setUsage(usage);
+    m_descriptor.setUsage(usage);
 }
     
 } // namespace WebCore
index 8ae264e..9b6b6c8 100644 (file)
 
 #if ENABLE(WEBGPU)
 
-#include "WebGPUEnums.h"
+#include "GPUTextureDescriptor.h"
 #include "WebGPUObject.h"
 
-#include <wtf/Vector.h>
-
 namespace WebCore {
 
-class GPUTextureDescriptor;
-
 class WebGPUTextureDescriptor : public WebGPUObject {
 public:
-    virtual ~WebGPUTextureDescriptor();
-    static Ref<WebGPUTextureDescriptor> create(unsigned long pixelFormat, unsigned long width, unsigned long height, bool mipmapped);
+    static Ref<WebGPUTextureDescriptor> create(unsigned pixelFormat, unsigned width, unsigned height, bool mipmapped);
 
-    unsigned long width() const;
-    void setWidth(unsigned long);
+    unsigned width() const;
+    void setWidth(unsigned);
 
-    unsigned long height() const;
-    void setHeight(unsigned long);
+    unsigned height() const;
+    void setHeight(unsigned);
 
-    unsigned long sampleCount() const;
-    void setSampleCount(unsigned long);
+    unsigned sampleCount() const;
+    void setSampleCount(unsigned);
 
-    unsigned long textureType() const;
-    void setTextureType(unsigned long);
+    unsigned textureType() const;
+    void setTextureType(unsigned);
 
-    unsigned long storageMode() const;
-    void setStorageMode(unsigned long);
+    unsigned storageMode() const;
+    void setStorageMode(unsigned);
 
-    unsigned long usage() const;
-    void setUsage(unsigned long);
+    unsigned usage() const;
+    void setUsage(unsigned);
 
-    GPUTextureDescriptor* textureDescriptor() { return m_textureDescriptor.get(); }
+    const GPUTextureDescriptor& descriptor() { return m_descriptor; }
 
 private:
-    WebGPUTextureDescriptor(unsigned long pixelFormat, unsigned long width, unsigned long height, bool mipmapped);
+    WebGPUTextureDescriptor(unsigned pixelFormat, unsigned width, unsigned height, bool mipmapped);
 
-    RefPtr<GPUTextureDescriptor> m_textureDescriptor;
+    GPUTextureDescriptor m_descriptor;
 };
 
 } // namespace WebCore
diff --git a/Source/WebCore/platform/graphics/cocoa/GPUCommandBufferMetal.mm b/Source/WebCore/platform/graphics/cocoa/GPUCommandBufferMetal.mm
deleted file mode 100644 (file)
index 12546f7..0000000
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * Copyright (C) 2017 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.
- */
-
-#import "config.h"
-#import "GPUCommandBuffer.h"
-
-#if ENABLE(WEBGPU)
-
-#import "GPUCommandQueue.h"
-#import "GPUDevice.h"
-#import "GPUDrawable.h"
-#import "Logging.h"
-
-#import <Metal/Metal.h>
-#import <wtf/BlockPtr.h>
-
-namespace WebCore {
-
-GPUCommandBuffer::GPUCommandBuffer(GPUCommandQueue* queue)
-{
-    LOG(WebGPU, "GPUCommandBuffer::GPUCommandBuffer()");
-
-    if (!queue || !queue->platformCommandQueue())
-        return;
-
-    m_commandBuffer = (MTLCommandBuffer *)[queue->platformCommandQueue() commandBuffer];
-}
-
-MTLCommandBuffer *GPUCommandBuffer::platformCommandBuffer()
-{
-    return m_commandBuffer.get();
-}
-
-void GPUCommandBuffer::presentDrawable(GPUDrawable* drawable)
-{
-    if (!m_commandBuffer || !drawable->platformDrawable())
-        return;
-
-    [m_commandBuffer presentDrawable:static_cast<id<MTLDrawable>>(drawable->platformDrawable())];
-    drawable->release();
-}
-
-void GPUCommandBuffer::commit()
-{
-    if (!m_commandBuffer)
-        return;
-
-    [m_commandBuffer commit];
-}
-
-DOMPromiseProxy<IDLVoid>& GPUCommandBuffer::completed()
-{
-    if (!m_commandBuffer)
-        return m_completedPromise;
-
-    [m_commandBuffer addCompletedHandler:BlockPtr<void (id<MTLCommandBuffer>)>::fromCallable([this, protectedThis = makeRef(*this)] (id<MTLCommandBuffer>) {
-        callOnMainThread([this, protectedThis = makeRef(*this)] {
-            this->m_completedPromise.resolve();
-        });
-    }).get()];
-    
-    return m_completedPromise;
-}
-
-} // namespace WebCore
-
-#endif
diff --git a/Source/WebCore/platform/graphics/cocoa/GPURenderCommandEncoderMetal.mm b/Source/WebCore/platform/graphics/cocoa/GPURenderCommandEncoderMetal.mm
deleted file mode 100644 (file)
index 23cb1aa..0000000
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- * Copyright (C) 2017 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.
- */
-
-#import "config.h"
-#import "GPURenderCommandEncoder.h"
-
-#if ENABLE(WEBGPU)
-
-#import "GPUBuffer.h"
-#import "GPUCommandBuffer.h"
-#import "GPUDepthStencilState.h"
-#import "GPURenderPassDescriptor.h"
-#import "GPURenderPipelineState.h"
-#import "Logging.h"
-
-#import <Metal/Metal.h>
-
-namespace WebCore {
-
-GPURenderCommandEncoder::GPURenderCommandEncoder(GPUCommandBuffer* buffer, GPURenderPassDescriptor* descriptor)
-{
-    LOG(WebGPU, "GPURenderCommandEncoder::GPURenderCommandEncoder()");
-
-    if (!buffer || !buffer->platformCommandBuffer() || !descriptor || !descriptor->platformRenderPassDescriptor())
-        return;
-
-    m_renderCommandEncoder = (MTLRenderCommandEncoder *)[buffer->platformCommandBuffer() renderCommandEncoderWithDescriptor:descriptor->platformRenderPassDescriptor()];
-}
-
-void GPURenderCommandEncoder::setRenderPipelineState(GPURenderPipelineState* renderPipelineState)
-{
-    if (!m_renderCommandEncoder || !renderPipelineState)
-        return;
-
-    // We need to cast to MTLRenderCommandEncoder explicitly because the compiler gets
-    // confused by a protocol with a similar signature.
-    [(id<MTLRenderCommandEncoder>)m_renderCommandEncoder.get() setRenderPipelineState:static_cast<id<MTLRenderPipelineState>>(renderPipelineState->platformRenderPipelineState())];
-}
-
-void GPURenderCommandEncoder::setDepthStencilState(GPUDepthStencilState* depthStencilState)
-{
-    if (!m_renderCommandEncoder || !depthStencilState)
-        return;
-
-    [m_renderCommandEncoder setDepthStencilState:static_cast<id<MTLDepthStencilState>>(depthStencilState->platformDepthStencilState())];
-}
-
-void GPURenderCommandEncoder::setVertexBuffer(GPUBuffer* buffer, unsigned offset, unsigned index)
-{
-    if (!m_renderCommandEncoder || !buffer)
-        return;
-
-    [m_renderCommandEncoder setVertexBuffer:static_cast<id<MTLBuffer>>(buffer->platformBuffer()) offset:offset atIndex:index];
-}
-
-void GPURenderCommandEncoder::setFragmentBuffer(GPUBuffer* buffer, unsigned offset, unsigned index)
-{
-    if (!m_renderCommandEncoder || !buffer)
-        return;
-
-    [m_renderCommandEncoder setFragmentBuffer:static_cast<id<MTLBuffer>>(buffer->platformBuffer()) offset:offset atIndex:index];
-}
-
-void GPURenderCommandEncoder::drawPrimitives(unsigned type, unsigned start, unsigned count)
-{
-    if (!m_renderCommandEncoder || !count)
-        return;
-
-    [m_renderCommandEncoder drawPrimitives:static_cast<MTLPrimitiveType>(type) vertexStart:start vertexCount:count];
-}
-
-void GPURenderCommandEncoder::endEncoding()
-{
-    [m_renderCommandEncoder endEncoding];
-}
-
-MTLRenderCommandEncoder *GPURenderCommandEncoder::platformRenderCommandEncoder()
-{
-    return m_renderCommandEncoder.get();
-}
-
-} // namespace WebCore
-
-#endif
diff --git a/Source/WebCore/platform/graphics/cocoa/GPURenderPipelineDescriptorMetal.mm b/Source/WebCore/platform/graphics/cocoa/GPURenderPipelineDescriptorMetal.mm
deleted file mode 100644 (file)
index 1e0b637..0000000
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- * Copyright (C) 2017 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.
- */
-
-#import "config.h"
-#import "GPURenderPipelineDescriptor.h"
-
-#if ENABLE(WEBGPU)
-
-#import "GPUFunction.h"
-#import "GPURenderPipelineColorAttachmentDescriptor.h"
-#import "Logging.h"
-
-#import <Metal/Metal.h>
-
-namespace WebCore {
-
-GPURenderPipelineDescriptor::GPURenderPipelineDescriptor()
-{
-    LOG(WebGPU, "GPURenderPipelineDescriptor::GPURenderPipelineDescriptor()");
-
-    m_renderPipelineDescriptor = adoptNS((MTLRenderPipelineDescriptor *)[MTLRenderPipelineDescriptor new]);
-}
-
-unsigned long GPURenderPipelineDescriptor::depthAttachmentPixelFormat() const
-{
-    if (!m_renderPipelineDescriptor)
-        return 0;
-    return [m_renderPipelineDescriptor depthAttachmentPixelFormat];
-}
-
-void GPURenderPipelineDescriptor::setDepthAttachmentPixelFormat(unsigned long newPixelFormat)
-{
-    ASSERT(m_renderPipelineDescriptor);
-    [m_renderPipelineDescriptor setDepthAttachmentPixelFormat:static_cast<MTLPixelFormat>(newPixelFormat)];
-}
-
-void GPURenderPipelineDescriptor::setVertexFunction(RefPtr<GPUFunction> newFunction)
-{
-    ASSERT(m_renderPipelineDescriptor);
-    [m_renderPipelineDescriptor setVertexFunction:(id<MTLFunction>)newFunction->platformFunction()];
-}
-
-void GPURenderPipelineDescriptor::setFragmentFunction(RefPtr<GPUFunction> newFunction)
-{
-    ASSERT(m_renderPipelineDescriptor);
-    [m_renderPipelineDescriptor setFragmentFunction:(id<MTLFunction>)newFunction->platformFunction()];
-}
-
-Vector<RefPtr<GPURenderPipelineColorAttachmentDescriptor>> GPURenderPipelineDescriptor::colorAttachments()
-{
-    if (!m_renderPipelineDescriptor)
-        return Vector<RefPtr<GPURenderPipelineColorAttachmentDescriptor>>();
-
-    Vector<RefPtr<GPURenderPipelineColorAttachmentDescriptor>> platformColorAttachments;
-    platformColorAttachments.append(GPURenderPipelineColorAttachmentDescriptor::create([[m_renderPipelineDescriptor colorAttachments] objectAtIndexedSubscript:0]));
-    return platformColorAttachments;
-}
-
-void GPURenderPipelineDescriptor::reset()
-{
-    if (!m_renderPipelineDescriptor)
-        return;
-
-    [m_renderPipelineDescriptor reset];
-}
-
-MTLRenderPipelineDescriptor *GPURenderPipelineDescriptor::platformRenderPipelineDescriptor()
-{
-    return m_renderPipelineDescriptor.get();
-}
-
-} // namespace WebCore
-
-#endif
diff --git a/Source/WebCore/platform/graphics/cocoa/GPUTextureDescriptorMetal.mm b/Source/WebCore/platform/graphics/cocoa/GPUTextureDescriptorMetal.mm
deleted file mode 100644 (file)
index a3877c7..0000000
+++ /dev/null
@@ -1,129 +0,0 @@
-/*
- * Copyright (C) 2017 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.
- */
-
-#import "config.h"
-#import "GPUTextureDescriptor.h"
-
-#if ENABLE(WEBGPU)
-
-#import "Logging.h"
-
-#import <Metal/Metal.h>
-
-namespace WebCore {
-
-GPUTextureDescriptor::GPUTextureDescriptor(unsigned long pixelFormat, unsigned long width, unsigned long height, bool mipmapped)
-{
-    LOG(WebGPU, "GPUTextureDescriptor::GPUTextureDescriptor()");
-
-    m_textureDescriptor = (MTLTextureDescriptor *)[MTLTextureDescriptor texture2DDescriptorWithPixelFormat:static_cast<MTLPixelFormat>(pixelFormat) width:width height:height mipmapped:mipmapped];
-}
-
-unsigned long GPUTextureDescriptor::width() const
-{
-    if (!m_textureDescriptor)
-        return 0;
-    return [m_textureDescriptor width];
-}
-
-void GPUTextureDescriptor::setWidth(unsigned long newWidth)
-{
-    ASSERT(m_textureDescriptor);
-    [m_textureDescriptor setWidth:newWidth];
-}
-
-unsigned long GPUTextureDescriptor::height() const
-{
-    if (!m_textureDescriptor)
-        return 0;
-    return [m_textureDescriptor height];
-}
-
-void GPUTextureDescriptor::setHeight(unsigned long newHeight)
-{
-    ASSERT(m_textureDescriptor);
-    [m_textureDescriptor setHeight:newHeight];
-}
-
-unsigned long GPUTextureDescriptor::sampleCount() const
-{
-    if (!m_textureDescriptor)
-        return 0;
-    return [m_textureDescriptor sampleCount];
-}
-
-void GPUTextureDescriptor::setSampleCount(unsigned long newSampleCount)
-{
-    ASSERT(m_textureDescriptor);
-    [m_textureDescriptor setSampleCount:newSampleCount];
-}
-
-unsigned long GPUTextureDescriptor::textureType() const
-{
-    if (!m_textureDescriptor)
-        return 0;
-    return [m_textureDescriptor textureType];
-}
-
-void GPUTextureDescriptor::setTextureType(unsigned long newTextureType)
-{
-    ASSERT(m_textureDescriptor);
-    [m_textureDescriptor setTextureType:static_cast<MTLTextureType>(newTextureType)];
-}
-
-unsigned long GPUTextureDescriptor::storageMode() const
-{
-    if (!m_textureDescriptor)
-        return 0;
-    return [m_textureDescriptor storageMode];
-}
-
-void GPUTextureDescriptor::setStorageMode(unsigned long newStorageMode)
-{
-    ASSERT(m_textureDescriptor);
-    [m_textureDescriptor setStorageMode:static_cast<MTLStorageMode>(newStorageMode)];
-}
-
-unsigned long GPUTextureDescriptor::usage() const
-{
-    if (!m_textureDescriptor)
-        return 0;
-    return [m_textureDescriptor usage];
-}
-
-void GPUTextureDescriptor::setUsage(unsigned long newUsage)
-{
-    ASSERT(m_textureDescriptor);
-    [m_textureDescriptor setUsage:newUsage];
-}
-
-MTLTextureDescriptor *GPUTextureDescriptor::platformTextureDescriptor()
-{
-    return m_textureDescriptor.get();
-}
-
-} // namespace WebCore
-
-#endif
index b762ea9..f0debc0 100644 (file)
 #import <CoreMedia/CMBufferQueue.h>
 #import <CoreMedia/CMFormatDescription.h>
 #import <pal/avfoundation/MediaTimeAVFoundation.h>
+#import <pal/cf/CoreMediaSoftLink.h>
 #import <wtf/MainThread.h>
 #import <wtf/MediaTime.h>
+#import <wtf/MonotonicTime.h>
 #import <wtf/StringPrintStream.h>
 #import <wtf/Vector.h>
 #import <wtf/cf/TypeCastsCF.h>
 
-#import <pal/cf/CoreMediaSoftLink.h>
 #import "CoreVideoSoftLink.h"
 #import "VideoToolboxSoftLink.h"
 
index 516156a..01b1ee7 100644 (file)
 
 #if ENABLE(WEBGPU)
 
-#include "GPUDevice.h"
 #include "Logging.h"
+#include <JavaScriptCore/ArrayBuffer.h>
 
 namespace WebCore {
 
-RefPtr<GPUBuffer> GPUBuffer::create(GPUDevice* device, ArrayBufferView* arrayBuffer)
-{
-    RefPtr<GPUBuffer> buffer = adoptRef(new GPUBuffer(device, arrayBuffer));
-    return buffer;
-}
-
 GPUBuffer::~GPUBuffer()
 {
     LOG(WebGPU, "GPUBuffer::~GPUBuffer()");
 }
 
-#if !PLATFORM(COCOA)
-unsigned long GPUBuffer::length() const
-{
-    return 0;
-}
-
-RefPtr<ArrayBuffer> GPUBuffer::contents()
+unsigned GPUBuffer::length() const
 {
-    if (m_contents)
-        return m_contents;
-
-    m_contents = ArrayBuffer::create(nullptr, 1);
-    return m_contents;
+    return m_contents ? m_contents->byteLength() : 0;
 }
-#endif
 
 } // namespace WebCore
 
index 5fab99a..b572133 100644 (file)
 
 #if ENABLE(WEBGPU)
 
-#include <JavaScriptCore/ArrayBufferView.h>
 #include <wtf/RefPtr.h>
 #include <wtf/RetainPtr.h>
 
-#if PLATFORM(COCOA)
-OBJC_CLASS MTLBuffer;
-#endif
+OBJC_PROTOCOL(MTLBuffer);
+
+namespace JSC {
+class ArrayBuffer;
+class ArrayBufferView;
+}
 
 namespace WebCore {
 
 class GPUDevice;
 
-class GPUBuffer : public RefCounted<GPUBuffer> {
+class GPUBuffer {
 public:
-    static RefPtr<GPUBuffer> create(GPUDevice*, ArrayBufferView*);
+    WEBCORE_EXPORT GPUBuffer(const GPUDevice&, const JSC::ArrayBufferView&);
     WEBCORE_EXPORT ~GPUBuffer();
 
-    WEBCORE_EXPORT unsigned long length() const;
-    WEBCORE_EXPORT RefPtr<ArrayBuffer> contents();
+    WEBCORE_EXPORT unsigned length() const;
+    JSC::ArrayBuffer* contents() const { return m_contents.get(); }
 
-#if PLATFORM(COCOA)
-    WEBCORE_EXPORT MTLBuffer *platformBuffer();
+#if USE(METAL)
+    MTLBuffer *metal() const { return m_metal.get(); }
 #endif
 
 private:
-    GPUBuffer(GPUDevice*, ArrayBufferView*);
-    
-#if PLATFORM(COCOA)
-    RetainPtr<MTLBuffer> m_buffer;
+#if USE(METAL)
+    RetainPtr<MTLBuffer> m_metal;
 #endif
-    RefPtr<ArrayBuffer> m_contents;
+    RefPtr<JSC::ArrayBuffer> m_contents;
 };
     
 } // namespace WebCore
+
 #endif
index 3b69360..282c829 100644 (file)
 
 #if ENABLE(WEBGPU)
 
-#include "GPUCommandQueue.h"
-#include "GPUComputeCommandEncoder.h"
-#include "GPUDevice.h"
-#include "GPURenderCommandEncoder.h"
-#include "GPURenderPassDescriptor.h"
 #include "Logging.h"
 
 namespace WebCore {
 
-RefPtr<GPUCommandBuffer> GPUCommandBuffer::create(GPUCommandQueue* queue)
-{
-    RefPtr<GPUCommandBuffer> buffer = adoptRef(new GPUCommandBuffer(queue));
-    return buffer;
-}
-
 GPUCommandBuffer::~GPUCommandBuffer()
 {
     LOG(WebGPU, "GPUCommandBuffer::~GPUCommandBuffer()");
 }
 
-RefPtr<GPURenderCommandEncoder> GPUCommandBuffer::createRenderCommandEncoder(GPURenderPassDescriptor* descriptor)
-{
-    return GPURenderCommandEncoder::create(this, descriptor);
-}
-
-RefPtr<GPUComputeCommandEncoder> GPUCommandBuffer::createComputeCommandEncoder()
-{
-    return GPUComputeCommandEncoder::create(this);
-}
-
-#if !PLATFORM(COCOA)
-void GPUCommandBuffer::presentDrawable(GPUDrawable*)
-{
-}
-
-DOMPromiseProxy<IDLVoid>& GPUCommandBuffer::completed();
-{
-    return m_completedPromise;
-}
-#endif
-
 } // namespace WebCore
 
 #endif
index dced276..456cf48 100644 (file)
 
 #if ENABLE(WEBGPU)
 
-#include "DOMPromiseProxy.h"
-#include <wtf/RefCounted.h>
-#include <wtf/RefPtr.h>
+#include <wtf/Function.h>
 #include <wtf/RetainPtr.h>
 
-#if PLATFORM(COCOA)
-OBJC_CLASS MTLCommandBuffer;
-#endif
+OBJC_PROTOCOL(MTLCommandBuffer);
 
 namespace WebCore {
 
 class GPUCommandQueue;
-class GPUComputeCommandEncoder;
 class GPUDrawable;
-class GPURenderCommandEncoder;
-class GPURenderPassDescriptor;
 
-class GPUCommandBuffer : public RefCounted<GPUCommandBuffer> {
+class GPUCommandBuffer {
 public:
-    static RefPtr<GPUCommandBuffer> create(GPUCommandQueue*);
-    WEBCORE_EXPORT ~GPUCommandBuffer();
-
-    WEBCORE_EXPORT void commit();
-    WEBCORE_EXPORT void presentDrawable(GPUDrawable*);
+    explicit GPUCommandBuffer(const GPUCommandQueue&, Function<void()>&& completedCallback);
+    ~GPUCommandBuffer();
 
-    WEBCORE_EXPORT RefPtr<GPURenderCommandEncoder> createRenderCommandEncoder(GPURenderPassDescriptor*);
-    WEBCORE_EXPORT RefPtr<GPUComputeCommandEncoder> createComputeCommandEncoder();
-    WEBCORE_EXPORT DOMPromiseProxy<IDLVoid>& completed();
+    void commit() const;
+    void presentDrawable(GPUDrawable&) const;
 
-#if PLATFORM(COCOA)
-    WEBCORE_EXPORT MTLCommandBuffer *platformCommandBuffer();
+#if USE(METAL)
+    MTLCommandBuffer *metal() const { return m_metal.get(); }
 #endif
 
+#if USE(METAL)
 private:
-    GPUCommandBuffer(GPUCommandQueue*);
-    
-#if PLATFORM(COCOA)
-    RetainPtr<MTLCommandBuffer> m_commandBuffer;
+    RetainPtr<MTLCommandBuffer> m_metal;
 #endif
-
-    DOMPromiseProxy<IDLVoid> m_completedPromise;
 };
     
 } // namespace WebCore
+
 #endif
index ee357b2..8222ace 100644 (file)
 
 #if ENABLE(WEBGPU)
 
-#include "GPUCommandBuffer.h"
-#include "GPUDevice.h"
 #include "Logging.h"
 
 namespace WebCore {
 
-RefPtr<GPUCommandQueue> GPUCommandQueue::create(GPUDevice* device)
-{
-    RefPtr<GPUCommandQueue> queue = adoptRef(new GPUCommandQueue(device));
-    return queue;
-}
-
 GPUCommandQueue::~GPUCommandQueue()
 {
     LOG(WebGPU, "GPUCommandQueue::~GPUCommandQueue()");
 }
 
-RefPtr<GPUCommandBuffer> GPUCommandQueue::createCommandBuffer()
-{
-    return GPUCommandBuffer::create(this);
-}
-
-#if !PLATFORM(COCOA)
-String GPUCommandQueue::label() const
-{
-    return emptyString();
-}
-
-void GPUCommandQueue::setLabel(const String&)
-{
-}
-#endif
-
 } // namespace WebCore
 
 #endif
index 2a19e72..e3d1e4c 100644 (file)
 
 #if ENABLE(WEBGPU)
 
-#include <wtf/RefCounted.h>
-#include <wtf/RefPtr.h>
 #include <wtf/RetainPtr.h>
-#include <wtf/text/WTFString.h>
 
-#if PLATFORM(COCOA)
-OBJC_CLASS MTLCommandQueue;
-#endif
+OBJC_PROTOCOL(MTLCommandQueue);
 
 namespace WebCore {
 
-class GPUCommandBuffer;
 class GPUDevice;
 
-class GPUCommandQueue : public RefCounted<GPUCommandQueue> {
+class GPUCommandQueue {
 public:
-    static RefPtr<GPUCommandQueue> create(GPUDevice*);
+    WEBCORE_EXPORT explicit GPUCommandQueue(const GPUDevice&);
     WEBCORE_EXPORT ~GPUCommandQueue();
 
     WEBCORE_EXPORT String label() const;
-    WEBCORE_EXPORT void setLabel(const String&);
-
-    WEBCORE_EXPORT RefPtr<GPUCommandBuffer> createCommandBuffer();
+    WEBCORE_EXPORT void setLabel(const String&) const;
 
-#if PLATFORM(COCOA)
-    WEBCORE_EXPORT MTLCommandQueue *platformCommandQueue();
+#if USE(METAL)
+    MTLCommandQueue *metal() const { return m_metal.get(); }
 #endif
 
+#if USE(METAL)
 private:
-    GPUCommandQueue(GPUDevice*);
-    
-#if PLATFORM(COCOA)
-    RetainPtr<MTLCommandQueue> m_commandQueue;
+    RetainPtr<MTLCommandQueue> m_metal;
 #endif
 };
     
 } // namespace WebCore
+
 #endif
index cb8591a..c1b8353 100644 (file)
 
 #if ENABLE(WEBGPU)
 
-#include "GPUBuffer.h"
-#include "GPUCommandBuffer.h"
-#include "GPUComputePipelineState.h"
 #include "Logging.h"
 
 namespace WebCore {
     
-RefPtr<GPUComputeCommandEncoder> GPUComputeCommandEncoder::create(GPUCommandBuffer* buffer)
-{
-    RefPtr<GPUComputeCommandEncoder> encoder = adoptRef(new GPUComputeCommandEncoder(buffer));
-    return encoder;
-}
-    
 GPUComputeCommandEncoder::~GPUComputeCommandEncoder()
 {
     LOG(WebGPU, "GPUComputeCommandEncoder::~GPUComputeCommandEncoder()");
 }
     
-#if !PLATFORM(COCOA)
-void GPUComputeCommandEncoder::setComputePipelineState(GPUComputePipelineState*)
-{
-}
-    
-void GPUComputeCommandEncoder::setBuffer(GPUBuffer*, unsigned, unsigned)
-{
-}
-    
-void GPUComputeCommandEncoder::dispatch(GPUSize threadgroupsPerGrid, GPUSize threadsPerThreadgroup);
-{
-}
-
-void GPUComputeCommandEncoder::endEncoding()
-{
-}
-#endif
-    
 } // namespace WebCore
 
 #endif
index c6cad32..cf167c3 100644 (file)
 
 #if ENABLE(WEBGPU)
 
-#include "GPUSize.h"
-#include <wtf/RefCounted.h>
-#include <wtf/RefPtr.h>
 #include <wtf/RetainPtr.h>
 
-#if PLATFORM(COCOA)
-OBJC_CLASS MTLComputeCommandEncoder;
-#endif
+OBJC_PROTOCOL(MTLComputeCommandEncoder);
 
 namespace WebCore {
     
@@ -42,27 +37,24 @@ class GPUBuffer;
 class GPUCommandBuffer;
 class GPUComputePipelineState;
 
-class GPUComputeCommandEncoder : public RefCounted<GPUComputeCommandEncoder> {
+struct GPUSize;
+
+class GPUComputeCommandEncoder {
 public:
-    static RefPtr<GPUComputeCommandEncoder> create(GPUCommandBuffer*);
-    WEBCORE_EXPORT ~GPUComputeCommandEncoder();
-        
-    WEBCORE_EXPORT void setComputePipelineState(GPUComputePipelineState*);
-    WEBCORE_EXPORT void setBuffer(GPUBuffer*, unsigned, unsigned);
-    WEBCORE_EXPORT void dispatch(GPUSize, GPUSize);
-    WEBCORE_EXPORT void endEncoding();
-        
-#if PLATFORM(COCOA)
-    WEBCORE_EXPORT MTLComputeCommandEncoder *platformComputeCommandEncoder();
-#endif
-        
+    explicit GPUComputeCommandEncoder(const GPUCommandBuffer&);
+    ~GPUComputeCommandEncoder();
+
+    void setComputePipelineState(const GPUComputePipelineState&) const;
+    void setBuffer(const GPUBuffer&, unsigned, unsigned) const;
+    void dispatch(GPUSize, GPUSize) const;
+    void endEncoding() const;
+
+#if USE(METAL)
 private:
-    GPUComputeCommandEncoder(GPUCommandBuffer*);
-        
-#if PLATFORM(COCOA)
-    RetainPtr<MTLComputeCommandEncoder> m_computeCommandEncoder;
+    RetainPtr<MTLComputeCommandEncoder> m_metal;
 #endif
 };
     
 } // namespace WebCore
+
 #endif
index 864e98f..c15829a 100644 (file)
 
 #if ENABLE(WEBGPU)
 
-#include "GPUDevice.h"
 #include "Logging.h"
 
 namespace WebCore {
     
-RefPtr<GPUComputePipelineState> GPUComputePipelineState::create(GPUDevice* device, GPUFunction* function)
-{
-    RefPtr<GPUComputePipelineState> state = adoptRef(new GPUComputePipelineState(device, function));
-    return state;
-}
-    
 GPUComputePipelineState::~GPUComputePipelineState()
 {
     LOG(WebGPU, "GPUComputePipelineState::~GPUComputePipelineState()");
index fe184c1..10e0b4d 100644 (file)
 
 #if ENABLE(WEBGPU)
 
-#include <wtf/RefCounted.h>
-#include <wtf/RefPtr.h>
 #include <wtf/RetainPtr.h>
-#include <wtf/text/WTFString.h>
 
-#if PLATFORM(COCOA)
-OBJC_CLASS MTLComputePipelineState;
-#endif
+OBJC_PROTOCOL(MTLComputePipelineState);
 
 namespace WebCore {
 
 class GPUDevice;
 class GPUFunction;
 
-class GPUComputePipelineState : public RefCounted<GPUComputePipelineState> {
+class GPUComputePipelineState {
 public:
-    static RefPtr<GPUComputePipelineState> create(GPUDevice*, GPUFunction*);
-    WEBCORE_EXPORT ~GPUComputePipelineState();
+    GPUComputePipelineState() = default;
+    GPUComputePipelineState(const GPUDevice&, const GPUFunction&);
+    ~GPUComputePipelineState();
 
-#if PLATFORM(COCOA)
-    WEBCORE_EXPORT MTLComputePipelineState *platformComputePipelineState();
+#if USE(METAL)
+    MTLComputePipelineState *metal() const { return m_metal.get(); }
 #endif
 
+#if USE(METAL)
 private:
-    GPUComputePipelineState(GPUDevice*, GPUFunction*);
-
-#if PLATFORM(COCOA)
-    RetainPtr<MTLComputePipelineState> m_computePipelineState;
+    RetainPtr<MTLComputePipelineState> m_metal;
 #endif
 };
 
 } // namespace WebCore
+
 #endif
index 202c65c..8525468 100644 (file)
 
 #if ENABLE(WEBGPU)
 
-#include "GPUTexture.h"
 #include "Logging.h"
 
 namespace WebCore {
 
-RefPtr<GPUDepthStencilDescriptor> GPUDepthStencilDescriptor::create()
-{
-    RefPtr<GPUDepthStencilDescriptor> descriptor = adoptRef(new GPUDepthStencilDescriptor());
-    return descriptor;
-}
-
 GPUDepthStencilDescriptor::~GPUDepthStencilDescriptor()
 {
     LOG(WebGPU, "GPUDepthStencilDescriptor::~GPUDepthStencilDescriptor()");
 }
 
-#if !PLATFORM(COCOA)
-bool GPUDepthStencilDescriptor::depthWriteEnabled() const
-{
-    return false;
-}
-
-void GPUDepthStencilDescriptor::setDepthWriteEnabled(bool)
-{
-}
-
-GPUCompareFunction GPUDepthStencilDescriptor::depthCompareFunction() const
-{
-}
-
-void GPUDepthStencilDescriptor::setDepthCompareFunction(GPUCompareFunction)
-{
-}
-#endif
-
 } // namespace WebCore
 
 #endif
index 89c4531..0579a66 100644 (file)
 
 #if ENABLE(WEBGPU)
 
-#include "GPUEnums.h"
-#include <wtf/RefCounted.h>
-#include <wtf/RefPtr.h>
 #include <wtf/RetainPtr.h>
 
-#if PLATFORM(COCOA)
 OBJC_CLASS MTLDepthStencilDescriptor;
-#endif
 
 namespace WebCore {
 
-class GPUDepthStencilDescriptor : public RefCounted<GPUDepthStencilDescriptor> {
+enum class GPUCompareFunction;
+
+class GPUDepthStencilDescriptor {
 public:
-    static RefPtr<GPUDepthStencilDescriptor> create();
-    WEBCORE_EXPORT ~GPUDepthStencilDescriptor();
+    GPUDepthStencilDescriptor();
+    ~GPUDepthStencilDescriptor();
 
-    WEBCORE_EXPORT bool depthWriteEnabled() const;
-    WEBCORE_EXPORT void setDepthWriteEnabled(bool);
+    bool depthWriteEnabled() const;
+    void setDepthWriteEnabled(bool) const;
 
-    WEBCORE_EXPORT GPUCompareFunction depthCompareFunction() const;
-    WEBCORE_EXPORT void setDepthCompareFunction(GPUCompareFunction);
+    GPUCompareFunction depthCompareFunction() const;
+    void setDepthCompareFunction(GPUCompareFunction) const;
 
-#if PLATFORM(COCOA)
-    WEBCORE_EXPORT MTLDepthStencilDescriptor *platformDepthStencilDescriptor();
+#if USE(METAL)
+    MTLDepthStencilDescriptor *metal() const { return m_metal.get(); }
 #endif
 
+#if USE(METAL)
 private:
-    GPUDepthStencilDescriptor();
-#if PLATFORM(COCOA)
-    RetainPtr<MTLDepthStencilDescriptor> m_depthStencilDescriptor;
+    RetainPtr<MTLDepthStencilDescriptor> m_metal;
 #endif
 };
     
 } // namespace WebCore
+
 #endif
index 6965d9d..571edae 100644 (file)
 
 #if ENABLE(WEBGPU)
 
-#include "GPUDepthStencilDescriptor.h"
-#include "GPUDevice.h"
 #include "Logging.h"
 
 namespace WebCore {
 
-RefPtr<GPUDepthStencilState> GPUDepthStencilState::create(GPUDevice* device, GPUDepthStencilDescriptor* descriptor)
-{
-    RefPtr<GPUDepthStencilState> state = adoptRef(new GPUDepthStencilState(device, descriptor));
-    return state;
-}
-
 GPUDepthStencilState::~GPUDepthStencilState()
 {
     LOG(WebGPU, "GPUDepthStencilState::~GPUDepthStencilState()");
 }
 
-#if !PLATFORM(COCOA)
-String GPUDepthStencilState::label() const
-{
-    return emptyString();
-}
-
-void GPUDepthStencilState::setLabel(const String&)
-{
-}
-#endif
-
 } // namespace WebCore
 
 #endif
index 98d4028..15b5cf8 100644 (file)
 
 #if ENABLE(WEBGPU)
 
-#include <wtf/RefCounted.h>
-#include <wtf/RefPtr.h>
 #include <wtf/RetainPtr.h>
-#include <wtf/text/WTFString.h>
 
-#if PLATFORM(COCOA)
-OBJC_CLASS MTLDepthStencilState;
-#endif
+OBJC_PROTOCOL(MTLDepthStencilState);
 
 namespace WebCore {
 
 class GPUDevice;
 class GPUDepthStencilDescriptor;
 
-class GPUDepthStencilState : public RefCounted<GPUDepthStencilState> {
+class GPUDepthStencilState {
 public:
-    static RefPtr<GPUDepthStencilState> create(GPUDevice*, GPUDepthStencilDescriptor*);
-    WEBCORE_EXPORT ~GPUDepthStencilState();
+    GPUDepthStencilState() = default;
+    GPUDepthStencilState(const GPUDevice&, const GPUDepthStencilDescriptor&);
+    ~GPUDepthStencilState();
 
-    WEBCORE_EXPORT String label() const;
-    WEBCORE_EXPORT void setLabel(const String&);
+    String label() const;
+    void setLabel(const String&) const;
 
-#if PLATFORM(COCOA)
-    WEBCORE_EXPORT MTLDepthStencilState *platformDepthStencilState();
+#if USE(METAL)
+    MTLDepthStencilState *metal() const { return m_metal.get(); }
 #endif
 
+#if USE(METAL)
 private:
-    GPUDepthStencilState(GPUDevice*, GPUDepthStencilDescriptor*);
-    
-#if PLATFORM(COCOA)
-    RetainPtr<MTLDepthStencilState> m_depthStencilState;
+    RetainPtr<MTLDepthStencilState> m_metal;
 #endif
 };
     
 } // namespace WebCore
+
 #endif
index a156522..5448fbc 100644 (file)
 
 #if ENABLE(WEBGPU)
 
-#include "GPUBuffer.h"
-#include "GPUCommandQueue.h"
-#include "GPUDrawable.h"
-#include "GPULibrary.h"
-#include "GPUTexture.h"
-#include "GPUTextureDescriptor.h"
 #include "Logging.h"
 
 namespace WebCore {
 
-RefPtr<GPUDevice> GPUDevice::create()
-{
-    RefPtr<GPUDevice> device = adoptRef(new GPUDevice());
-
-#if PLATFORM(COCOA)
-    if (!device->platformDevice()) {
-        LOG(WebGPU, "GPUDevice::create() was unable to create the low-level device");
-        return nullptr;
-    }
-#endif
-
-    LOG(WebGPU, "GPUDevice::create() device is %p", device.get());
-    return device;
-}
-
 GPUDevice::~GPUDevice()
 {
     LOG(WebGPU, "GPUDevice::~GPUDevice()");
+    disconnect();
 }
 
-RefPtr<GPUCommandQueue> GPUDevice::createCommandQueue()
-{
-    return GPUCommandQueue::create(this);
-}
-
-RefPtr<GPULibrary> GPUDevice::createLibrary(const String& sourceCode)
-{
-    return GPULibrary::create(this, sourceCode);
-}
-
-RefPtr<GPUBuffer> GPUDevice::createBufferFromData(ArrayBufferView* data)
-{
-    return GPUBuffer::create(this, data);
-}
-
-RefPtr<GPUTexture> GPUDevice::createTexture(GPUTextureDescriptor* descriptor)
-{
-    return GPUTexture::create(this, descriptor);
-}
-
-RefPtr<GPUDrawable> GPUDevice::getFramebuffer()
-{
-    return GPUDrawable::create(this);
-}
-
-#if !PLATFORM(COCOA)
-
-GPUDevice::GPUDevice()
-{
-
-}
-
-void GPUDevice::reshape(int, int)
-{
-}
-
-#endif
-
 } // namespace WebCore
 
 #endif
index df194eb..d9870f9 100644 (file)
 
 #if ENABLE(WEBGPU)
 
-#include "PlatformLayer.h"
-#include <JavaScriptCore/ArrayBufferView.h>
-#include <wtf/Forward.h>
-#include <wtf/RefCounted.h>
+#include <wtf/RetainPtr.h>
 
-#if USE(CA)
-#include "PlatformCALayer.h"
-#endif
-
-#if PLATFORM(COCOA)
-typedef struct objc_object* id;
 OBJC_CLASS CALayer;
 OBJC_CLASS WebGPULayer;
-#else
-class WebGPULayer;
-#endif
 
-namespace WebCore {
+OBJC_PROTOCOL(MTLDevice);
 
-class GPUBuffer;
-class GPUCommandQueue;
-class GPUDrawable;
-class GPULibrary;
-class GPUTexture;
-class GPUTextureDescriptor;
+namespace WebCore {
 
-class GPUDevice : public RefCounted<GPUDevice> {
+class GPUDevice {
 public:
-    WEBCORE_EXPORT static RefPtr<GPUDevice> create();
+    WEBCORE_EXPORT GPUDevice();
     WEBCORE_EXPORT ~GPUDevice();
 
-    void reshape(int width, int height);
-
-#if PLATFORM(COCOA)
-    WebGPULayer* layer() { return m_layer.get(); }
-    CALayer* platformLayer() const { return reinterpret_cast<CALayer*>(m_layer.get()); }
-    WEBCORE_EXPORT id platformDevice();
-#endif
+    WEBCORE_EXPORT bool operator!() const;
 
-    WEBCORE_EXPORT RefPtr<GPUCommandQueue> createCommandQueue();
-    WEBCORE_EXPORT RefPtr<GPULibrary> createLibrary(const String& sourceCode);
-    WEBCORE_EXPORT RefPtr<GPUBuffer> createBufferFromData(ArrayBufferView* data);
-    WEBCORE_EXPORT RefPtr<GPUTexture> createTexture(GPUTextureDescriptor*);
+    void reshape(int width, int height) const;
 
-    RefPtr<GPUDrawable> getFramebuffer();
+#if USE(METAL)
+    WebGPULayer *layer() const { return m_layer.get(); }
+    WEBCORE_EXPORT CALayer *platformLayer() const;
+    MTLDevice *metal() const { return m_metal.get(); }
+#endif
 
-    void markLayerComposited() { }
+    void markLayerComposited() const { }
 
 private:
-    GPUDevice();
+    void disconnect();
 
-#if PLATFORM(COCOA)
+#if USE(METAL)
     RetainPtr<WebGPULayer> m_layer;
-    RetainPtr<id> m_device;
+    RetainPtr<MTLDevice> m_metal;
 #endif
 };
 
index 563a75d..8d8ea4c 100644 (file)
 
 #if ENABLE(WEBGPU)
 
-#include "GPUCommandBuffer.h"
-#include "GPUDevice.h"
 #include "Logging.h"
 
 namespace WebCore {
 
-RefPtr<GPUDrawable> GPUDrawable::create(GPUDevice* device)
-{
-    RefPtr<GPUDrawable> drawable = adoptRef(new GPUDrawable(device));
-    return drawable;
-}
-
 GPUDrawable::~GPUDrawable()
 {
     LOG(WebGPU, "GPUDrawable::~GPUDrawable()");
 }
 
-#if !PLATFORM(COCOA)
-void GPUDrawable::release()
-{
-}
-#endif
-
 } // namespace WebCore
 
 #endif
index cca2bcf..6f43292 100644 (file)
 
 #if ENABLE(WEBGPU)
 
-#include <wtf/RefCounted.h>
-#include <wtf/RefPtr.h>
 #include <wtf/RetainPtr.h>
 
-#if PLATFORM(COCOA)
-OBJC_CLASS MTLDrawable;
-OBJC_CLASS MTLTexture;
-#endif
+OBJC_PROTOCOL(MTLDrawable);
+OBJC_PROTOCOL(MTLTexture);
 
 namespace WebCore {
 
-class GPUTexture;
 class GPUDevice;
 
-class GPUDrawable : public RefCounted<GPUDrawable> {
+class GPUDrawable {
 public:
-    static RefPtr<GPUDrawable> create(GPUDevice*);
-    WEBCORE_EXPORT ~GPUDrawable();
+    explicit GPUDrawable(const GPUDevice&);
+    ~GPUDrawable();
+
+    void release();
 
-    WEBCORE_EXPORT void release();
+#if USE(METAL)
+    MTLDrawable *metal() const;
 
-#if PLATFORM(COCOA)
-    WEBCORE_EXPORT MTLDrawable *platformDrawable();
     // FIXME: WebGPU - not all drawables should have this. Only the framebuffer.
-    WEBCORE_EXPORT MTLTexture *platformTexture();
+    MTLTexture *texture() const;
 #endif
 
+#if USE(METAL)
 private:
-    GPUDrawable(GPUDevice*);
-    
-#if PLATFORM(COCOA)
-    RetainPtr<MTLDrawable> m_drawable;
+    RetainPtr<MTLDrawable> m_metal;
 #endif
 };
     
index 3f27aef..0d0b399 100644 (file)
 
 #if ENABLE(WEBGPU)
 
-#include "GPULibrary.h"
 #include "Logging.h"
 
 namespace WebCore {
 
-RefPtr<GPUFunction> GPUFunction::create(GPULibrary* library, const String& name)
-{
-    RefPtr<GPUFunction> function = adoptRef(new GPUFunction(library, name));
-#if PLATFORM(COCOA)
-    if (!function->platformFunction())
-        return nullptr;
-#endif
-    return function;
-}
-
 GPUFunction::~GPUFunction()
 {
     LOG(WebGPU, "GPUFunction::~GPUFunction()");
 }
 
-#if !PLATFORM(COCOA)
-GPUFunction::GPUFunction(GPULibrary*, const String&)
-{
-    LOG(WebGPU, "GPUFunction::GPUFunction()");
-}
-
-String GPUFunction::name() const
-{
-    return emptyString();
-}
-#endif
-
-    
 } // namespace WebCore
 
 #endif
-
index 7d7fdf1..96fa492 100644 (file)
 
 #if ENABLE(WEBGPU)
 
-#include <wtf/RefCounted.h>
-#include <wtf/RefPtr.h>
-#include <wtf/Vector.h>
-#include <wtf/text/WTFString.h>
+#include <wtf/RetainPtr.h>
 
-#if PLATFORM(COCOA)
-OBJC_CLASS MTLFunction;
-#endif
+OBJC_PROTOCOL(MTLFunction);
 
 namespace WebCore {
 
 class GPULibrary;
 
-class GPUFunction : public RefCounted<GPUFunction> {
+class GPUFunction {
 public:
-    static RefPtr<GPUFunction> create(GPULibrary*, const String& name);
+    WEBCORE_EXPORT GPUFunction(const GPULibrary&, const String& name);
     WEBCORE_EXPORT ~GPUFunction();
 
+    bool operator!() const;
+
     WEBCORE_EXPORT String name() const;
 
-#if PLATFORM(COCOA)
-    WEBCORE_EXPORT MTLFunction *platformFunction();
+#if USE(METAL)
+    MTLFunction *metal() const { return m_metal.get(); }
 #endif
 
+#if USE(METAL)
 private:
-    GPUFunction(GPULibrary*, const String& name);
-
-#if PLATFORM(COCOA)
-    RetainPtr<MTLFunction> m_function;
+    RetainPtr<MTLFunction> m_metal;
 #endif
 };
     
index 17939c0..9062488 100644 (file)
 
 #if ENABLE(WEBGPU)
 
-#include "GPUDevice.h"
-#include "GPUFunction.h"
 #include "Logging.h"
 
 namespace WebCore {
 
-RefPtr<GPULibrary> GPULibrary::create(GPUDevice* device, const String& sourceCode)
-{
-    RefPtr<GPULibrary> library = adoptRef(new GPULibrary(device, sourceCode));
-    return library;
-}
-
 GPULibrary::~GPULibrary()
 {
     LOG(WebGPU, "GPULibrary::~GPULibrary()");
 }
 
-#if !PLATFORM(COCOA)
-
-String GPULibrary::label() const
-{
-    return emptyString();
-}
-
-void GPULibrary::setLabel(const String&)
-{
-}
-
-Vector<String> GPULibrary::functionNames()
-{
-    return { };
-}
-
-#endif
-
-RefPtr<GPUFunction> GPULibrary::functionWithName(const String& name)
-{
-    return GPUFunction::create(this, name);
-}
-    
 } // namespace WebCore
 
 #endif
index 985b96e..f35d5ba 100644 (file)
 
 #if ENABLE(WEBGPU)
 
-#include <wtf/RefCounted.h>
-#include <wtf/RefPtr.h>
-#include <wtf/Vector.h>
-#include <wtf/text/WTFString.h>
+#include <wtf/RetainPtr.h>
 
-#if PLATFORM(COCOA)
-OBJC_CLASS MTLLibrary;
-#endif
+OBJC_PROTOCOL(MTLLibrary);
 
 namespace WebCore {
 
 class GPUDevice;
-class GPUFunction;
 
-class GPULibrary : public RefCounted<GPULibrary> {
+class GPULibrary {
 public:
-    static RefPtr<GPULibrary> create(GPUDevice*, const String& sourceCode);
+    WEBCORE_EXPORT GPULibrary(const GPUDevice&, const String& sourceCode);
     WEBCORE_EXPORT ~GPULibrary();
 
     WEBCORE_EXPORT String label() const;
-    WEBCORE_EXPORT void setLabel(const String&);
-
-    WEBCORE_EXPORT Vector<String> functionNames();
+    WEBCORE_EXPORT void setLabel(const String&) const;
 
-    WEBCORE_EXPORT RefPtr<GPUFunction> functionWithName(const String&);
+    WEBCORE_EXPORT Vector<String> functionNames() const;
 
-#if PLATFORM(COCOA)
-    WEBCORE_EXPORT MTLLibrary *platformLibrary();
+#if USE(METAL)
+    MTLLibrary *metal() const { return m_metal.get(); }
 #endif
 
+#if USE(METAL)
 private:
-    GPULibrary(GPUDevice*, const String& sourceCode);
-    
-#if PLATFORM(COCOA)
-    RetainPtr<MTLLibrary> m_library;
+    RetainPtr<MTLLibrary> m_metal;
 #endif
 };
     
 } // namespace WebCore
+
 #endif
index 9d19044..6d1f53b 100644 (file)
 
 #if ENABLE(WEBGPU)
 
-#include "GPUCommandBuffer.h"
-#include "GPURenderPassDescriptor.h"
 #include "Logging.h"
 
 namespace WebCore {
 
-RefPtr<GPURenderCommandEncoder> GPURenderCommandEncoder::create(GPUCommandBuffer* buffer, GPURenderPassDescriptor* descriptor)
-{
-    RefPtr<GPURenderCommandEncoder> encoder = adoptRef(new GPURenderCommandEncoder(buffer, descriptor));
-    return encoder;
-}
-
 GPURenderCommandEncoder::~GPURenderCommandEncoder()
 {
     LOG(WebGPU, "GPURenderCommandEncoder::~GPURenderCommandEncoder()");
 }
 
-#if !PLATFORM(COCOA)
-void GPURenderCommandEncoder::setRenderPipelineState(GPURenderPipelineState*)
-{
-}
-
-void GPURenderCommandEncoder::setDepthStencilState(GPUDepthStencilState*)
-{
-}
-
-void GPURenderCommandEncoder::setVertexBuffer(GPUBuffer*, unsigned, unsigned)
-{
-}
-
-void GPURenderCommandEncoder::setFragmentBuffer(GPUBuffer*, unsigned, unsigned)
-{
-}
-
-void GPURenderCommandEncoder::drawPrimitives(unsigned, unsigned, unsigned)
-{
-}
-
-void GPURenderCommandEncoder::endEncoding()
-{
-}
-#endif
-
 } // namespace WebCore
 
 #endif
index 378edd2..f9053ce 100644 (file)
 
 #if ENABLE(WEBGPU)
 
-#include <wtf/RefCounted.h>
-#include <wtf/RefPtr.h>
 #include <wtf/RetainPtr.h>
 
-#if PLATFORM(COCOA)
-OBJC_CLASS MTLRenderCommandEncoder;
-#endif
+OBJC_PROTOCOL(MTLRenderCommandEncoder);
 
 namespace WebCore {
 
@@ -43,29 +39,24 @@ class GPUDepthStencilState;
 class GPURenderPassDescriptor;
 class GPURenderPipelineState;
 
-class GPURenderCommandEncoder : public RefCounted<GPURenderCommandEncoder> {
+class GPURenderCommandEncoder {
 public:
-    static RefPtr<GPURenderCommandEncoder> create(GPUCommandBuffer*, GPURenderPassDescriptor*);
-    WEBCORE_EXPORT ~GPURenderCommandEncoder();
-
-    WEBCORE_EXPORT void setRenderPipelineState(GPURenderPipelineState*);
-    WEBCORE_EXPORT void setDepthStencilState(GPUDepthStencilState*);
-    WEBCORE_EXPORT void setVertexBuffer(GPUBuffer*, unsigned offset, unsigned index);
-    WEBCORE_EXPORT void setFragmentBuffer(GPUBuffer*, unsigned offset, unsigned index);
-    WEBCORE_EXPORT void drawPrimitives(unsigned type, unsigned start, unsigned count);
-    WEBCORE_EXPORT void endEncoding();
+    GPURenderCommandEncoder(const GPUCommandBuffer&, const GPURenderPassDescriptor&);
+    ~GPURenderCommandEncoder();
 
-#if PLATFORM(COCOA)
-    WEBCORE_EXPORT MTLRenderCommandEncoder *platformRenderCommandEncoder();
-#endif
+    void setRenderPipelineState(const GPURenderPipelineState&) const;
+    void setDepthStencilState(const GPUDepthStencilState&) const;
+    void setVertexBuffer(const GPUBuffer&, unsigned offset, unsigned index) const;
+    void setFragmentBuffer(const GPUBuffer&, unsigned offset, unsigned index) const;
+    void drawPrimitives(unsigned type, unsigned start, unsigned count) const;
+    void endEncoding() const;
 
+#if USE(METAL)
 private:
-    GPURenderCommandEncoder(GPUCommandBuffer*, GPURenderPassDescriptor*);
-    
-#if PLATFORM(COCOA)
-    RetainPtr<MTLRenderCommandEncoder> m_renderCommandEncoder;
+    RetainPtr<MTLRenderCommandEncoder> m_metal;
 #endif
 };
     
 } // namespace WebCore
+
 #endif
index 599e377..75d89e9 100644 (file)
@@ -38,35 +38,6 @@ GPURenderPassAttachmentDescriptor::~GPURenderPassAttachmentDescriptor()
     LOG(WebGPU, "GPURenderPassAttachmentDescriptor::~GPURenderPassAttachmentDescriptor()");
 }
 
-#if !PLATFORM(COCOA)
-GPURenderPassAttachmentDescriptor::GPURenderPassAttachmentDescriptor()
-{
-    LOG(WebGPU, "GPURenderPassAttachmentDescriptor::GPURenderPassAttachmentDescriptor()");
-}
-
-unsigned long GPURenderPassAttachmentDescriptor::loadAction() const
-{
-    return 0;
-}
-
-void GPURenderPassAttachmentDescriptor::setLoadAction(unsigned long)
-{
-}
-
-unsigned long GPURenderPassAttachmentDescriptor::storeAction() const
-{
-    return 0;
-}
-
-void GPURenderPassAttachmentDescriptor::setStoreAction(unsigned long)
-{
-}
-
-void GPURenderPassAttachmentDescriptor::setTexture(RefPtr<GPUTexture>)
-{
-}
-#endif
-
 } // namespace WebCore
 
 #endif
index 3d48856..fef7094 100644 (file)
 
 #if ENABLE(WEBGPU)
 
-#include <wtf/RefCounted.h>
-#include <wtf/RefPtr.h>
 #include <wtf/RetainPtr.h>
 
-#if PLATFORM(COCOA)
 OBJC_CLASS MTLRenderPassAttachmentDescriptor;
-#endif
 
 namespace WebCore {
 
 class GPUTexture;
 
-class GPURenderPassAttachmentDescriptor : public RefCounted<GPURenderPassAttachmentDescriptor> {
+class GPURenderPassAttachmentDescriptor {
 public:
-    WEBCORE_EXPORT ~GPURenderPassAttachmentDescriptor();
+    ~GPURenderPassAttachmentDescriptor();
 
-    WEBCORE_EXPORT unsigned long loadAction() const;
-    WEBCORE_EXPORT void setLoadAction(unsigned long);
+    unsigned loadAction() const;
+    void setLoadAction(unsigned) const;
 
-    WEBCORE_EXPORT unsigned long storeAction() const;
-    WEBCORE_EXPORT void setStoreAction(unsigned long);
+    unsigned storeAction() const;
+    void setStoreAction(unsigned) const;
 
-    WEBCORE_EXPORT void setTexture(RefPtr<GPUTexture>);
+    void setTexture(const GPUTexture&) const;
 
-#if PLATFORM(COCOA)
-    WEBCORE_EXPORT MTLRenderPassAttachmentDescriptor *platformRenderPassAttachmentDescriptor();
+#if USE(METAL)
+    MTLRenderPassAttachmentDescriptor *metal() const;
 #endif
 
+#if USE(METAL)
 protected:
-#if PLATFORM(COCOA)
-    GPURenderPassAttachmentDescriptor(MTLRenderPassAttachmentDescriptor *);
-    RetainPtr<MTLRenderPassAttachmentDescriptor> m_renderPassAttachmentDescriptor;
-#else
-    GPURenderPassAttachmentDescriptor();
+    explicit GPURenderPassAttachmentDescriptor(MTLRenderPassAttachmentDescriptor *);
+
+private:
+    RetainPtr<MTLRenderPassAttachmentDescriptor> m_metal;
 #endif
 };
     
 } // namespace WebCore
+
 #endif
index 5c7152e..2f5ac78 100644 (file)
 
 #if ENABLE(WEBGPU)
 
-#include "GPURenderPassAttachmentDescriptor.h"
 #include "Logging.h"
 
 namespace WebCore {
 
-#if !PLATFORM(COCOA)
-RefPtr<GPURenderPassColorAttachmentDescriptor> GPURenderPassColorAttachmentDescriptor::create()
-{
-    RefPtr<GPURenderPassColorAttachmentDescriptor> descriptor = adoptRef(new GPURenderPassColorAttachmentDescriptor());
-    return descriptor;
-}
-
-GPURenderPassColorAttachmentDescriptor::GPURenderPassColorAttachmentDescriptor()
-    : GPURenderPassAttachmentDescriptor()
-{
-    LOG(WebGPU, "GPURenderPassColorAttachmentDescriptor::GPURenderPassColorAttachmentDescriptor()");
-}
-#endif
-
 GPURenderPassColorAttachmentDescriptor::~GPURenderPassColorAttachmentDescriptor()
 {
     LOG(WebGPU, "GPURenderPassColorAttachmentDescriptor::~GPURenderPassColorAttachmentDescriptor()");
 }
 
-#if !PLATFORM(COCOA)
-Vector<float> GPURenderPassColorAttachmentDescriptor::clearColor() const
-{
-    return Vector<float>();
-}
-
-void GPURenderPassColorAttachmentDescriptor::setClearColor(const Vector<float>&)
-{
-}
-#endif
-
 } // namespace WebCore
 
 #endif
index 7b07ab9..31aee8f 100644 (file)
 #if ENABLE(WEBGPU)
 
 #include "GPURenderPassAttachmentDescriptor.h"
-#include <wtf/RefCounted.h>
-#include <wtf/RefPtr.h>
-#include <wtf/RetainPtr.h>
-#include <wtf/Vector.h>
 
-#if PLATFORM(COCOA)
 OBJC_CLASS MTLRenderPassColorAttachmentDescriptor;
-#endif
 
 namespace WebCore {
 
 class GPURenderPassColorAttachmentDescriptor : public GPURenderPassAttachmentDescriptor {
 public:
-#if PLATFORM(COCOA)
-    static RefPtr<GPURenderPassColorAttachmentDescriptor> create(MTLRenderPassColorAttachmentDescriptor *);
-#else
-    static RefPtr<GPURenderPassColorAttachmentDescriptor> create();
+#if USE(METAL)
+    GPURenderPassColorAttachmentDescriptor(MTLRenderPassColorAttachmentDescriptor *);
 #endif
-    WEBCORE_EXPORT ~GPURenderPassColorAttachmentDescriptor();
-
-    WEBCORE_EXPORT Vector<float> clearColor() const;
-    WEBCORE_EXPORT void setClearColor(const Vector<float>&);
+    ~GPURenderPassColorAttachmentDescriptor();
 
-#if PLATFORM(COCOA)
-    WEBCORE_EXPORT MTLRenderPassColorAttachmentDescriptor *platformRenderPassColorAttachmentDescriptor();
-#endif
+    Vector<float> clearColor() const;
+    void setClearColor(const Vector<float>&) const;
 
-private:
-#if PLATFORM(COCOA)
-    GPURenderPassColorAttachmentDescriptor(MTLRenderPassColorAttachmentDescriptor *);
-#else
-    GPURenderPassColorAttachmentDescriptor();
+#if USE(METAL)
+    MTLRenderPassColorAttachmentDescriptor *metal() const;
 #endif
 };
     
 } // namespace WebCore
+
 #endif
index aa4e457..4c1ca67 100644 (file)
 
 #if ENABLE(WEBGPU)
 
-#include "GPURenderPassAttachmentDescriptor.h"
 #include "Logging.h"
 
 namespace WebCore {
 
-#if !PLATFORM(COCOA)
-RefPtr<GPURenderPassDepthAttachmentDescriptor> GPURenderPassDepthAttachmentDescriptor::create()
-{
-    RefPtr<GPURenderPassDepthAttachmentDescriptor> descriptor = adoptRef(new GPURenderPassDepthAttachmentDescriptor());
-    return descriptor;
-}
-
-GPURenderPassDepthAttachmentDescriptor::GPURenderPassDepthAttachmentDescriptor()
-    : GPURenderPassAttachmentDescriptor()
-{
-    LOG(WebGPU, "GPURenderPassDepthAttachmentDescriptor::GPURenderPassDepthAttachmentDescriptor()");
-}
-#endif
-
 GPURenderPassDepthAttachmentDescriptor::~GPURenderPassDepthAttachmentDescriptor()
 {
     LOG(WebGPU, "GPURenderPassDepthAttachmentDescriptor::~GPURenderPassDepthAttachmentDescriptor()");
 }
 
-#if !PLATFORM(COCOA)
-double GPURenderPassDepthAttachmentDescriptor::clearDepth() const
-{
-    return 0;
-}
-
-void GPURenderPassDepthAttachmentDescriptor::setClearDepth(double)
-{
-}
-#endif
-
 } // namespace WebCore
 
 #endif
index 8b0ecd4..b4c5172 100644 (file)
 #if ENABLE(WEBGPU)
 
 #include "GPURenderPassAttachmentDescriptor.h"
-#include <wtf/RefCounted.h>
-#include <wtf/RefPtr.h>
-#include <wtf/RetainPtr.h>
-#include <wtf/Vector.h>
 
-#if PLATFORM(COCOA)
 OBJC_CLASS MTLRenderPassDepthAttachmentDescriptor;
-#endif
 
 namespace WebCore {
 
 class GPURenderPassDepthAttachmentDescriptor : public GPURenderPassAttachmentDescriptor {
 public:
-#if PLATFORM(COCOA)
-    static RefPtr<GPURenderPassDepthAttachmentDescriptor> create(MTLRenderPassDepthAttachmentDescriptor *);
-#else
-    static RefPtr<GPURenderPassDepthAttachmentDescriptor> create();
+#if USE(METAL)
+    GPURenderPassDepthAttachmentDescriptor(MTLRenderPassDepthAttachmentDescriptor *);
 #endif
-    WEBCORE_EXPORT ~GPURenderPassDepthAttachmentDescriptor();
+    ~GPURenderPassDepthAttachmentDescriptor();
 
     double clearDepth() const;
-    void setClearDepth(double);
-
-#if PLATFORM(COCOA)
-    WEBCORE_EXPORT MTLRenderPassDepthAttachmentDescriptor *platformRenderPassDepthAttachmentDescriptor();
-#endif
+    void setClearDepth(double) const;
 
+#if USE(METAL)
 private:
-#if PLATFORM(COCOA)
-    GPURenderPassDepthAttachmentDescriptor(MTLRenderPassDepthAttachmentDescriptor *);
-#else
-    GPURenderPassDepthAttachmentDescriptor();
+    MTLRenderPassDepthAttachmentDescriptor *metal() const;
 #endif
 };
     
 } // namespace WebCore
+
 #endif
index f9f9963..fa4abc9 100644 (file)
 
 namespace WebCore {
 
-RefPtr<GPURenderPassDescriptor> GPURenderPassDescriptor::create()
-{
-    RefPtr<GPURenderPassDescriptor> descriptor = adoptRef(new GPURenderPassDescriptor());
-    return descriptor;
-}
-
 GPURenderPassDescriptor::~GPURenderPassDescriptor()
 {
     LOG(WebGPU, "GPURenderPassDescriptor::~GPURenderPassDescriptor()");
 }
 
-#if !PLATFORM(COCOA)
-RefPtr<GPURenderPassDepthAttachmentDescriptor> GPURenderPassDescriptor::depthAttachment()
-{
-    return nullptr;
-}
-#endif
-
 } // namespace WebCore
 
 #endif
index 36ac79b..54dae24 100644 (file)
 
 #if ENABLE(WEBGPU)
 
-#include <wtf/RefCounted.h>
-#include <wtf/RefPtr.h>
 #include <wtf/RetainPtr.h>
-#include <wtf/Vector.h>
 
-#if PLATFORM(COCOA)
 OBJC_CLASS MTLRenderPassDescriptor;
-#endif
 
 namespace WebCore {
 
 class GPURenderPassColorAttachmentDescriptor;
 class GPURenderPassDepthAttachmentDescriptor;
 
-class GPURenderPassDescriptor : public RefCounted<GPURenderPassDescriptor> {
+class GPURenderPassDescriptor {
 public:
-    static RefPtr<GPURenderPassDescriptor> create();
-    WEBCORE_EXPORT ~GPURenderPassDescriptor();
+    GPURenderPassDescriptor();
+    ~GPURenderPassDescriptor();
 
-    Vector<RefPtr<GPURenderPassColorAttachmentDescriptor>> colorAttachments();
-    RefPtr<GPURenderPassDepthAttachmentDescriptor> depthAttachment();
+    Vector<GPURenderPassColorAttachmentDescriptor> colorAttachments() const;
+    GPURenderPassDepthAttachmentDescriptor depthAttachment() const;
 
-#if PLATFORM(COCOA)
-    WEBCORE_EXPORT MTLRenderPassDescriptor *platformRenderPassDescriptor();
+#if USE(METAL)
+    MTLRenderPassDescriptor *metal() const;
 #endif
 
+#if USE(METAL)
 private:
-    GPURenderPassDescriptor();
-
-#if PLATFORM(COCOA)
-    RetainPtr<MTLRenderPassDescriptor> m_renderPassDescriptor;
+    RetainPtr<MTLRenderPassDescriptor> m_metal;
 #endif
-    RefPtr<GPURenderPassDepthAttachmentDescriptor> m_depthAttachment;
 };
     
 } // namespace WebCore
+
 #endif
index 6af4119..a758780 100644 (file)
@@ -28,7 +28,6 @@
 
 #if ENABLE(WEBGPU)
 
-#include "GPUTexture.h"
 #include "Logging.h"
 
 namespace WebCore {
@@ -38,22 +37,6 @@ GPURenderPipelineColorAttachmentDescriptor::~GPURenderPipelineColorAttachmentDes
     LOG(WebGPU, "GPURenderPipelineColorAttachmentDescriptor::~GPURenderPipelineColorAttachmentDescriptor()");
 }
 
-#if !PLATFORM(COCOA)
-GPURenderPipelineColorAttachmentDescriptor::GPURenderPipelineColorAttachmentDescriptor()
-{
-    LOG(WebGPU, "GPURenderPipelineColorAttachmentDescriptor::GPURenderPipelineColorAttachmentDescriptor()");
-}
-
-unsigned long GPURenderPipelineColorAttachmentDescriptor::pixelFormat() const
-{
-    return 0;
-}
-
-void GPURenderPipelineColorAttachmentDescriptor::setPixelFormat(unsigned long)
-{
-}
-#endif
-
 } // namespace WebCore
 
 #endif
index f1c1a70..a80a5d0 100644 (file)
 
 #if ENABLE(WEBGPU)
 
-#include <wtf/RefCounted.h>
-#include <wtf/RefPtr.h>
 #include <wtf/RetainPtr.h>
 
-#if PLATFORM(COCOA)
 OBJC_CLASS MTLRenderPipelineColorAttachmentDescriptor;
-#endif
 
 namespace WebCore {
 
-class GPUTexture;
-
-class GPURenderPipelineColorAttachmentDescriptor : public RefCounted<GPURenderPipelineColorAttachmentDescriptor> {
+class GPURenderPipelineColorAttachmentDescriptor {
 public:
-#if PLATFORM(COCOA)
-    static RefPtr<GPURenderPipelineColorAttachmentDescriptor> create(MTLRenderPipelineColorAttachmentDescriptor *);
-#else
-    static RefPtr<GPURenderPipelineColorAttachmentDescriptor> create();
+#if USE(METAL)
+    GPURenderPipelineColorAttachmentDescriptor(MTLRenderPipelineColorAttachmentDescriptor *);
 #endif
+    ~GPURenderPipelineColorAttachmentDescriptor();
 
-    WEBCORE_EXPORT ~GPURenderPipelineColorAttachmentDescriptor();
+    unsigned pixelFormat() const;
+    void setPixelFormat(unsigned) const;
 
-    WEBCORE_EXPORT unsigned long pixelFormat() const;
-    WEBCORE_EXPORT void setPixelFormat(unsigned long);
-
-#if PLATFORM(COCOA)
-    WEBCORE_EXPORT MTLRenderPipelineColorAttachmentDescriptor *platformRenderPipelineColorAttachmentDescriptor();
+#if USE(METAL)
+    MTLRenderPipelineColorAttachmentDescriptor *metal() const;
 #endif
 
-protected:
-#if PLATFORM(COCOA)
-    GPURenderPipelineColorAttachmentDescriptor(MTLRenderPipelineColorAttachmentDescriptor *);
-    RetainPtr<MTLRenderPipelineColorAttachmentDescriptor> m_renderPipelineColorAttachmentDescriptor;
-#else
-    GPURenderPipelineColorAttachmentDescriptor();
+#if USE(METAL)
+private:
+    RetainPtr<MTLRenderPipelineColorAttachmentDescriptor> m_metal;
 #endif
 };
     
 } // namespace WebCore
+
 #endif
index 7cc8984..968cc45 100644 (file)
 
 #if ENABLE(WEBGPU)
 
-#include "GPUFunction.h"
-#include "GPURenderPipelineColorAttachmentDescriptor.h"
-#include "GPUTexture.h"
 #include "Logging.h"
 
 namespace WebCore {
 
-RefPtr<GPURenderPipelineDescriptor> GPURenderPipelineDescriptor::create()
-{
-    RefPtr<GPURenderPipelineDescriptor> descriptor = adoptRef(new GPURenderPipelineDescriptor());
-    return descriptor;
-}
-
 GPURenderPipelineDescriptor::~GPURenderPipelineDescriptor()
 {
     LOG(WebGPU, "GPURenderPipelineDescriptor::~GPURenderPipelineDescriptor()");
 }
 
-#if !PLATFORM(COCOA)
-unsigned long GPURenderPipelineDescriptor::depthAttachmentPixelFormat() const
-{
-    return false;
-}
-
-void GPURenderPipelineDescriptor::setDepthAttachmentPixelFormat(unsigned long)
-{
-}
-
-void GPURenderPipelineDescriptor::setVertexFunction(RefPtr<GPUFunction>)
-{
-}
-
-void GPURenderPipelineDescriptor::setFragmentFunction(RefPtr<GPUFunction>)
-{
-}
-
-Vector<RefPtr<GPURenderPipelineColorAttachmentDescriptor>> GPURenderPipelineDescriptor::colorAttachments()
-{
-    return Vector<RefPtr<GPURenderPipelineColorAttachmentDescriptor>>();
-}
-#endif
-
 } // namespace WebCore
 
 #endif
index 302f1fc..1fde927 100644 (file)
 
 #if ENABLE(WEBGPU)
 
-#include "GPUEnums.h"
-#include <wtf/RefCounted.h>
-#include <wtf/RefPtr.h>
 #include <wtf/RetainPtr.h>
-#include <wtf/Vector.h>
 
-#if PLATFORM(COCOA)
 OBJC_CLASS MTLRenderPipelineDescriptor;
-#endif
 
 namespace WebCore {
 
 class GPUFunction;
 class GPURenderPipelineColorAttachmentDescriptor;
 
-class GPURenderPipelineDescriptor : public RefCounted<GPURenderPipelineDescriptor> {
+class GPURenderPipelineDescriptor {
 public:
-    static RefPtr<GPURenderPipelineDescriptor> create();
-    WEBCORE_EXPORT ~GPURenderPipelineDescriptor();
+    GPURenderPipelineDescriptor();
+    ~GPURenderPipelineDescriptor();
 
-    WEBCORE_EXPORT void setVertexFunction(RefPtr<GPUFunction>);
-    WEBCORE_EXPORT void setFragmentFunction(RefPtr<GPUFunction>);
+    void setVertexFunction(const GPUFunction&) const;
+    void setFragmentFunction(const GPUFunction&) const;
 
-    WEBCORE_EXPORT unsigned long depthAttachmentPixelFormat() const;
-    WEBCORE_EXPORT void setDepthAttachmentPixelFormat(unsigned long);
+    unsigned depthAttachmentPixelFormat() const;
+    void setDepthAttachmentPixelFormat(unsigned) const;
 
-    WEBCORE_EXPORT Vector<RefPtr<GPURenderPipelineColorAttachmentDescriptor>> colorAttachments();
+    Vector<GPURenderPipelineColorAttachmentDescriptor> colorAttachments() const;
 
-    WEBCORE_EXPORT void reset();
+    void reset() const;
 
-#if PLATFORM(COCOA)
-    WEBCORE_EXPORT MTLRenderPipelineDescriptor *platformRenderPipelineDescriptor();
+#if USE(METAL)
+    MTLRenderPipelineDescriptor *metal() const;
 #endif
 
+#if USE(METAL)
 private:
-    GPURenderPipelineDescriptor();
-#if PLATFORM(COCOA)
-    RetainPtr<MTLRenderPipelineDescriptor> m_renderPipelineDescriptor;
+    RetainPtr<MTLRenderPipelineDescriptor> m_metal;
 #endif
 };
-    
+
 } // namespace WebCore
+
 #endif
index 9fee38c..69dc410 100644 (file)
 
 #if ENABLE(WEBGPU)
 
-#include "GPUDevice.h"
-#include "GPURenderPipelineDescriptor.h"
 #include "Logging.h"
 
 namespace WebCore {
 
-RefPtr<GPURenderPipelineState> GPURenderPipelineState::create(GPUDevice* device, GPURenderPipelineDescriptor* descriptor)
-{
-    RefPtr<GPURenderPipelineState> state = adoptRef(new GPURenderPipelineState(device, descriptor));
-    return state;
-}
-
 GPURenderPipelineState::~GPURenderPipelineState()
 {
     LOG(WebGPU, "GPURenderPipelineState::~GPURenderPipelineState()");
 }
 
-#if !PLATFORM(COCOA)
-String GPURenderPipelineState::label() const
-{
-    return emptyString();
-}
-
-void GPURenderPipelineState::setLabel(const String&)
-{
-}
-#endif
-
 } // namespace WebCore
 
 #endif
index 3a7a63d..c883249 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2017 Apple Inc. All rights reserved.
+ * Copyright (C) 2017-2018 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
 
 #if ENABLE(WEBGPU)
 
-#include <wtf/RefCounted.h>
-#include <wtf/RefPtr.h>
 #include <wtf/RetainPtr.h>
-#include <wtf/text/WTFString.h>
 
-#if PLATFORM(COCOA)
-OBJC_CLASS MTLRenderPipelineState;
-#endif
+OBJC_PROTOCOL(MTLRenderPipelineState);
 
 namespace WebCore {
 
 class GPUDevice;
 class GPURenderPipelineDescriptor;
 
-class GPURenderPipelineState : public RefCounted<GPURenderPipelineState> {
+class GPURenderPipelineState {
 public:
-    static RefPtr<GPURenderPipelineState> create(GPUDevice*, GPURenderPipelineDescriptor*);
-    WEBCORE_EXPORT ~GPURenderPipelineState();
+    GPURenderPipelineState() = default;
+    GPURenderPipelineState(const GPUDevice&, const GPURenderPipelineDescriptor&);
+    ~GPURenderPipelineState();
 
-    WEBCORE_EXPORT String label() const;
-    WEBCORE_EXPORT void setLabel(const String&);
+    String label() const;
+    void setLabel(const String&) const;
 
-#if PLATFORM(COCOA)
-    WEBCORE_EXPORT MTLRenderPipelineState *platformRenderPipelineState();
+#if USE(METAL)
+    MTLRenderPipelineState *metal() const;
 #endif
 
+#if USE(METAL)
 private:
-    GPURenderPipelineState(GPUDevice*, GPURenderPipelineDescriptor*);
-    
-#if PLATFORM(COCOA)
-    RetainPtr<MTLRenderPipelineState> m_renderPipelineState;
+    RetainPtr<MTLRenderPipelineState> m_metal;
 #endif
 };
     
 } // namespace WebCore
+
 #endif
index f489f44..3958e83 100644 (file)
 namespace WebCore {
     
 struct GPUSize {
-    unsigned long width;
-    unsigned long height;
-    unsigned long depth;
+    unsigned width;
+    unsigned height;
+    unsigned depth;
 };
 
 } // namespace WebCore
+
 #endif
index 47714c1..bcc5e8a 100644 (file)
 
 #if ENABLE(WEBGPU)
 
-#include "GPUDevice.h"
-#include "GPUDrawable.h"
 #include "Logging.h"
 
 namespace WebCore {
 
-RefPtr<GPUTexture> GPUTexture::create(GPUDevice* device, GPUTextureDescriptor* descriptor)
-{
-    RefPtr<GPUTexture> texture = adoptRef(new GPUTexture(device, descriptor));
-    return texture;
-}
-
-RefPtr<GPUTexture> GPUTexture::createFromDrawable(GPUDrawable* other)
-{
-    RefPtr<GPUTexture> texture = adoptRef(new GPUTexture(other));
-    return texture;
-}
-
 GPUTexture::~GPUTexture()
 {
     LOG(WebGPU, "GPUTexture::~GPUTexture()");
 }
 
-#if !PLATFORM(COCOA)
-unsigned long GPUTexture::width() const
-{
-    return 0;
-}
-
-unsigned long GPUTexture::height() const
-{
-    return 0;
-}
-#endif
-
 } // namespace WebCore
 
 #endif
index 2894b4e..d036791 100644 (file)
 
 #if ENABLE(WEBGPU)
 
-#include <wtf/RefCounted.h>
-#include <wtf/RefPtr.h>
 #include <wtf/RetainPtr.h>
 
-#if PLATFORM(COCOA)
-OBJC_CLASS MTLTexture;
-#endif
+OBJC_PROTOCOL(MTLTexture);
 
 namespace WebCore {
 
@@ -41,28 +37,25 @@ class GPUDevice;
 class GPUDrawable;
 class GPUTextureDescriptor;
 
-class GPUTexture : public RefCounted<GPUTexture> {
+class GPUTexture {
 public:
-    static RefPtr<GPUTexture> create(GPUDevice*, GPUTextureDescriptor*);
-    static RefPtr<GPUTexture> createFromDrawable(GPUDrawable*);
-
-    WEBCORE_EXPORT ~GPUTexture();
+    GPUTexture(const GPUDevice&, const GPUTextureDescriptor&);
+    explicit GPUTexture(const GPUDrawable&);
+    ~GPUTexture();
 
-    WEBCORE_EXPORT unsigned long width() const;
-    WEBCORE_EXPORT unsigned long height() const;
+    unsigned width() const;
+    unsigned height() const;
 
-#if PLATFORM(COCOA)
-    WEBCORE_EXPORT MTLTexture *platformTexture();
+#if USE(METAL)
+    MTLTexture *metal() const;
 #endif
 
+#if USE(METAL)
 private:
-    GPUTexture(GPUDevice*, GPUTextureDescriptor*);
-    GPUTexture(GPUDrawable*);
-    
-#if PLATFORM(COCOA)
-    RetainPtr<MTLTexture> m_texture;
+    RetainPtr<MTLTexture> m_metal;
 #endif
 };
     
 } // namespace WebCore
+
 #endif
index 80ce12d..df675a4 100644 (file)
 
 namespace WebCore {
 
-RefPtr<GPUTextureDescriptor> GPUTextureDescriptor::create(unsigned long pixelFormat, unsigned long width, unsigned long height, bool mipmapped)
-{
-    RefPtr<GPUTextureDescriptor> descriptor = adoptRef(new GPUTextureDescriptor(pixelFormat, width, height, mipmapped));
-    return descriptor;
-}
-
 GPUTextureDescriptor::~GPUTextureDescriptor()
 {
     LOG(WebGPU, "GPUTextureDescriptor::~GPUTextureDescriptor()");
 }
 
-#if !PLATFORM(COCOA)
-unsigned long GPUTextureDescriptor::width() const
-{
-    return 0;
-}
-
-void GPUTextureDescriptor::setWidth(unsigned long)
-{
-}
-
-unsigned long GPUTextureDescriptor::height() const
-{
-    return 0;
-}
-
-void GPUTextureDescriptor::setHeight(unsigned long)
-{
-}
-
-unsigned long GPUTextureDescriptor::sampleCount() const
-{
-    return 0;
-}
-
-void GPUTextureDescriptor::setSampleCount(unsigned long)
-{
-}
-
-unsigned long GPUTextureDescriptor::textureType() const
-{
-    return 0;
-}
-
-void GPUTextureDescriptor::setTextureType(unsigned long)
-{
-}
-
-unsigned long GPUTextureDescriptor::storageMode() const
-{
-    return 0;
-}
-
-void GPUTextureDescriptor::setStorageMode(unsigned long)
-{
-}
-
-unsigned long GPUTextureDescriptor::usage() const
-{
-    return 0;
-}
-
-void GPUTextureDescriptor::setUsage(unsigned long)
-{
-}
-#endif
-
 } // namespace WebCore
 
 #endif
index 7e21ba2..24111fc 100644 (file)
 
 #if ENABLE(WEBGPU)
 
-#include <wtf/RefCounted.h>
-#include <wtf/RefPtr.h>
 #include <wtf/RetainPtr.h>
 
-#if PLATFORM(COCOA)
 OBJC_CLASS MTLTextureDescriptor;
-#endif
 
 namespace WebCore {
 
-class GPUTextureDescriptor : public RefCounted<GPUTextureDescriptor> {
+class GPUTextureDescriptor {
 public:
-    static RefPtr<GPUTextureDescriptor> create(unsigned long pixelFormat, unsigned long width, unsigned long height, bool mipmapped);
-    WEBCORE_EXPORT ~GPUTextureDescriptor();
+    GPUTextureDescriptor(unsigned pixelFormat, unsigned width, unsigned height, bool mipmapped);
+    ~GPUTextureDescriptor();
 
-    WEBCORE_EXPORT unsigned long width() const;
-    WEBCORE_EXPORT void setWidth(unsigned long);
+    unsigned width() const;
+    void setWidth(unsigned) const;
 
-    WEBCORE_EXPORT unsigned long height() const;
-    WEBCORE_EXPORT void setHeight(unsigned long);
+    unsigned height() const;
+    void setHeight(unsigned) const;
 
-    WEBCORE_EXPORT unsigned long sampleCount() const;
-    WEBCORE_EXPORT void setSampleCount(unsigned long);
+    unsigned sampleCount() const;
+    void setSampleCount(unsigned) const;
 
-    WEBCORE_EXPORT unsigned long textureType() const;
-    WEBCORE_EXPORT void setTextureType(unsigned long);
+    unsigned textureType() const;
+    void setTextureType(unsigned) const;
 
-    WEBCORE_EXPORT unsigned long storageMode() const;
-    WEBCORE_EXPORT void setStorageMode(unsigned long);
+    unsigned storageMode() const;
+    void setStorageMode(unsigned) const;
 
-    WEBCORE_EXPORT unsigned long usage() const;
-    WEBCORE_EXPORT void setUsage(unsigned long);
+    unsigned usage() const;
+    void setUsage(unsigned) const;
 
-#if PLATFORM(COCOA)
-    WEBCORE_EXPORT MTLTextureDescriptor *platformTextureDescriptor();
+#if USE(METAL)
+    MTLTextureDescriptor *metal() const;
 #endif
 
+#if USE(METAL)
 private:
-    GPUTextureDescriptor(unsigned long pixelFormat, unsigned long width, unsigned long height, bool mipmapped);
-
-#if PLATFORM(COCOA)
-    RetainPtr<MTLTextureDescriptor> m_textureDescriptor;
+    RetainPtr<MTLTextureDescriptor> m_metal;
 #endif
 };
     
 
 #import "GPUDevice.h"
 #import "Logging.h"
+#import <JavaScriptCore/ArrayBufferView.h>
 #import <Metal/Metal.h>
 #import <wtf/Gigacage.h>
 #import <wtf/PageBlock.h>
 
 namespace WebCore {
 
-GPUBuffer::GPUBuffer(GPUDevice* device, ArrayBufferView* data)
+GPUBuffer::GPUBuffer(const GPUDevice& device, const JSC::ArrayBufferView& data)
 {
     LOG(WebGPU, "GPUBuffer::GPUBuffer()");
 
-    if (!device || !device->platformDevice() || !data)
+    if (!device.metal())
         return;
     
     size_t pageSize = WTF::pageSize();
-    size_t pageAlignedSize = roundUpToMultipleOf(pageSize, data->byteLength());
+    size_t pageAlignedSize = roundUpToMultipleOf(pageSize, data.byteLength());
     void* pageAlignedCopy = Gigacage::tryAlignedMalloc(Gigacage::Primitive, pageSize, pageAlignedSize);
     if (!pageAlignedCopy)
         return;
-    memcpy(pageAlignedCopy, data->baseAddress(), data->byteLength());
-    m_contents = ArrayBuffer::createFromBytes(pageAlignedCopy, data->byteLength(), [] (void* ptr) { Gigacage::alignedFree(Gigacage::Primitive, ptr); });
+    memcpy(pageAlignedCopy, data.baseAddress(), data.byteLength());
+    m_contents = ArrayBuffer::createFromBytes(pageAlignedCopy, data.byteLength(), [] (void* ptr) {
+        Gigacage::alignedFree(Gigacage::Primitive, ptr);
+    });
     m_contents->ref();
     ArrayBuffer* capturedContents = m_contents.get();
-    m_buffer = adoptNS((MTLBuffer *)[device->platformDevice() newBufferWithBytesNoCopy:m_contents->data() length:pageAlignedSize options:MTLResourceOptionCPUCacheModeDefault deallocator:^(void*, NSUInteger) { capturedContents->deref(); }]);
-    if (!m_buffer) {
+    m_metal = adoptNS([device.metal() newBufferWithBytesNoCopy:m_contents->data() length:pageAlignedSize options:MTLResourceOptionCPUCacheModeDefault deallocator:^(void*, NSUInteger) {
+        capturedContents->deref();
+    }]);
+    if (!m_metal) {
         m_contents->deref();
         m_contents = nullptr;
     }
 }
 
-unsigned long GPUBuffer::length() const
-{
-    if (!m_buffer)
-        return 0;
-
-    return m_contents->byteLength();
-}
-
-RefPtr<ArrayBuffer> GPUBuffer::contents()
-{
-    return m_contents;
-}
-
-MTLBuffer *GPUBuffer::platformBuffer()
-{
-    return m_buffer.get();
-}
-
 } // namespace WebCore
 
 #endif
diff --git a/Source/WebCore/platform/graphics/metal/GPUCommandBufferMetal.mm b/Source/WebCore/platform/graphics/metal/GPUCommandBufferMetal.mm
new file mode 100644 (file)
index 0000000..6df6361
--- /dev/null
@@ -0,0 +1,66 @@
+/*
+ * Copyright (C) 2017 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.
+ */
+
+#import "config.h"
+#import "GPUCommandBuffer.h"
+
+#if ENABLE(WEBGPU)
+
+#import "GPUCommandQueue.h"
+#import "GPUDrawable.h"
+#import "Logging.h"
+#import <Metal/Metal.h>
+#import <wtf/BlockPtr.h>
+#import <wtf/MainThread.h>
+
+namespace WebCore {
+
+GPUCommandBuffer::GPUCommandBuffer(const GPUCommandQueue& queue, Function<void()>&& completedCallback)
+    : m_metal { [queue.metal() commandBuffer] }
+{
+    LOG(WebGPU, "GPUCommandBuffer::GPUCommandBuffer()");
+
+    [m_metal addCompletedHandler:BlockPtr<void (id<MTLCommandBuffer>)>::fromCallable([completedCallback = WTFMove(completedCallback)] (id<MTLCommandBuffer>) mutable {
+        callOnMainThread(WTFMove(completedCallback));
+    }).get()];
+}
+
+void GPUCommandBuffer::presentDrawable(GPUDrawable& drawable) const
+{
+    if (!m_metal || !drawable.metal())
+        return;
+
+    [m_metal presentDrawable:drawable.metal()];
+    drawable.release();
+}
+
+void GPUCommandBuffer::commit() const
+{
+    [m_metal commit];
+}
+
+} // namespace WebCore
+
+#endif
 
 #import "GPUDevice.h"
 #import "Logging.h"
-
 #import <Metal/Metal.h>
 
-static NSString *webkitPrefix = @"com.apple.WebKit";
-
 namespace WebCore {
 
-GPUCommandQueue::GPUCommandQueue(GPUDevice* device)
+static NSString * const commandQueueDefaultLabel = @"com.apple.WebKit";
+static NSString * const commandQueueLabelPrefix = @"com.apple.WebKit.";
+
+GPUCommandQueue::GPUCommandQueue(const GPUDevice& device)
+    : m_metal { adoptNS([device.metal() newCommandQueue]) }
 {
     LOG(WebGPU, "GPUCommandQueue::GPUCommandQueue()");
 
-    if (!device || !device->platformDevice())
-        return;
-
-    m_commandQueue = adoptNS((MTLCommandQueue *)[device->platformDevice() newCommandQueue]);
-    setLabel(emptyString());
+    [m_metal setLabel:commandQueueDefaultLabel];
 }
 
 String GPUCommandQueue::label() const
 {
-    if (!m_commandQueue)
+    if (!m_metal)
         return emptyString();
 
-    NSString *prefixedLabel = [m_commandQueue label];
+    NSString *prefixedLabel = [m_metal label];
 
-    if ([prefixedLabel isEqualToString:webkitPrefix])
+    if ([prefixedLabel isEqualToString:commandQueueDefaultLabel])
         return emptyString();
 
-    ASSERT(prefixedLabel.length >= (webkitPrefix.length + 1));
-    return [prefixedLabel substringFromIndex:(webkitPrefix.length + 1)];
+    ASSERT(prefixedLabel.length > commandQueueLabelPrefix.length);
+    return [prefixedLabel substringFromIndex:commandQueueLabelPrefix.length];
 }
 
-void GPUCommandQueue::setLabel(const String& label)
+void GPUCommandQueue::setLabel(const String& label) const
 {
-    ASSERT(m_commandQueue);
     if (label.isEmpty())
-        [m_commandQueue setLabel:webkitPrefix];
+        [m_metal setLabel:commandQueueDefaultLabel];
     else
-        [m_commandQueue setLabel:[NSString stringWithFormat:@"%@.%@", webkitPrefix, static_cast<NSString *>(label)]];
-}
-    
-MTLCommandQueue *GPUCommandQueue::platformCommandQueue()
-{
-    return m_commandQueue.get();
+        [m_metal setLabel:[commandQueueLabelPrefix stringByAppendingString:label]];
 }
 
 } // namespace WebCore
 #import "GPUComputePipelineState.h"
 #import "GPUSize.h"
 #import "Logging.h"
-
 #import <Metal/Metal.h>
 
 namespace WebCore {
-    
-inline MTLSize MTLSizeMake(GPUSize size)
+
+static inline MTLSize MTLSizeMake(GPUSize size)
 {
-    return {size.width, size.height, size.depth};
+    return { size.width, size.height, size.depth };
 }
-    
-GPUComputeCommandEncoder::GPUComputeCommandEncoder(GPUCommandBuffer* buffer)
+
+GPUComputeCommandEncoder::GPUComputeCommandEncoder(const GPUCommandBuffer& buffer)
+    : m_metal { [buffer.metal() computeCommandEncoder] }
 {
     LOG(WebGPU, "GPUComputeCommandEncoder::GPUComputeCommandEncoder()");
-
-    if (!buffer || !buffer->platformCommandBuffer())
-        return;
-
-    m_computeCommandEncoder = (MTLComputeCommandEncoder *)[buffer->platformCommandBuffer() computeCommandEncoder];
 }
-    
-void GPUComputeCommandEncoder::setComputePipelineState(GPUComputePipelineState* computePipelineState)
+
+void GPUComputeCommandEncoder::setComputePipelineState(const GPUComputePipelineState& computePipelineState) const
 {
-    if (!m_computeCommandEncoder || !computePipelineState)
+    if (!computePipelineState.metal())
         return;
-    
-    [m_computeCommandEncoder setComputePipelineState:static_cast<id<MTLComputePipelineState>>(computePipelineState->platformComputePipelineState())];
+
+    [m_metal setComputePipelineState:computePipelineState.metal()];
 }
     
-void GPUComputeCommandEncoder::setBuffer(GPUBuffer* buffer, unsigned offset, unsigned index)
+void GPUComputeCommandEncoder::setBuffer(const GPUBuffer& buffer, unsigned offset, unsigned index) const
 {
-    if (!m_computeCommandEncoder || !buffer)
+    if (!buffer.metal())
         return;
-    
-    [m_computeCommandEncoder setBuffer:static_cast<id<MTLBuffer>>(buffer->platformBuffer()) offset:offset atIndex:index];
+
+    [m_metal setBuffer:buffer.metal() offset:offset atIndex:index];
 }
     
-void GPUComputeCommandEncoder::dispatch(GPUSize threadgroupsPerGrid, GPUSize threadsPerThreadgroup)
+void GPUComputeCommandEncoder::dispatch(GPUSize threadgroupsPerGrid, GPUSize threadsPerThreadgroup) const
 {
-    if (!m_computeCommandEncoder)
-        return;
-    
-    [m_computeCommandEncoder dispatchThreadgroups:MTLSizeMake(threadgroupsPerGrid) threadsPerThreadgroup:MTLSizeMake(threadsPerThreadgroup)];
+    [m_metal dispatchThreadgroups:MTLSizeMake(threadgroupsPerGrid) threadsPerThreadgroup:MTLSizeMake(threadsPerThreadgroup)];
 }
 
-void GPUComputeCommandEncoder::endEncoding()
+void GPUComputeCommandEncoder::endEncoding() const
 {
-    [m_computeCommandEncoder endEncoding];
+    [m_metal endEncoding];
 }
-    
-MTLComputeCommandEncoder *GPUComputeCommandEncoder::platformComputeCommandEncoder()
-{
-    return m_computeCommandEncoder.get();
-}
-    
+
 } // namespace WebCore
 
 #endif
 #import "GPUDevice.h"
 #import "GPUFunction.h"
 #import "Logging.h"
-
 #import <Metal/Metal.h>
 
 namespace WebCore {
 
-GPUComputePipelineState::GPUComputePipelineState(GPUDevice* device, GPUFunction* function)
+GPUComputePipelineState::GPUComputePipelineState(const GPUDevice& device, const GPUFunction& function)
 {
     LOG(WebGPU, "GPUComputePipelineState::GPUComputePipelineState()");
 
-    if (!device || !device->platformDevice() || !function || !function->platformFunction())
+    if (!function.metal())
         return;
 
-    m_computePipelineState = adoptNS((MTLComputePipelineState *)[device->platformDevice() newComputePipelineStateWithFunction:(id<MTLFunction>)function->platformFunction() error:nil]);
-}
-
-MTLComputePipelineState *GPUComputePipelineState::platformComputePipelineState()
-{
-    return m_computePipelineState.get();
+    m_metal = adoptNS([device.metal() newComputePipelineStateWithFunction:function.metal() error:nil]);
 }
 
 } // namespace WebCore
 
 #import "GPUEnums.h"
 #import "Logging.h"
-
 #import <Metal/Metal.h>
 
 namespace WebCore {
 
 GPUDepthStencilDescriptor::GPUDepthStencilDescriptor()
+    : m_metal { adoptNS([MTLDepthStencilDescriptor new]) }
 {
     LOG(WebGPU, "GPUDepthStencilDescriptor::GPUDepthStencilDescriptor()");
-
-    m_depthStencilDescriptor = adoptNS((MTLDepthStencilDescriptor *)[MTLDepthStencilDescriptor new]);
 }
 
 bool GPUDepthStencilDescriptor::depthWriteEnabled() const
 {
-    if (!m_depthStencilDescriptor)
-        return false;
-
-    return [m_depthStencilDescriptor isDepthWriteEnabled];
+    return [m_metal isDepthWriteEnabled];
 }
 
-void GPUDepthStencilDescriptor::setDepthWriteEnabled(bool newDepthWriteEnabled)
+void GPUDepthStencilDescriptor::setDepthWriteEnabled(bool newDepthWriteEnabled) const
 {
-    ASSERT(m_depthStencilDescriptor);
-    [m_depthStencilDescriptor setDepthWriteEnabled:newDepthWriteEnabled];
+    [m_metal setDepthWriteEnabled:newDepthWriteEnabled];
 }
 
 GPUCompareFunction GPUDepthStencilDescriptor::depthCompareFunction() const
 {
-    if (!m_depthStencilDescriptor)
-        return GPUCompareFunction::Never;
-
-    return static_cast<GPUCompareFunction>([m_depthStencilDescriptor depthCompareFunction]);
-}
-
-void GPUDepthStencilDescriptor::setDepthCompareFunction(GPUCompareFunction newFunction)
-{
-    ASSERT(m_depthStencilDescriptor);
-    [m_depthStencilDescriptor setDepthCompareFunction:static_cast<MTLCompareFunction>(newFunction)];
+    return static_cast<GPUCompareFunction>([m_metal depthCompareFunction]);
 }
 
-MTLDepthStencilDescriptor *GPUDepthStencilDescriptor::platformDepthStencilDescriptor()
+void GPUDepthStencilDescriptor::setDepthCompareFunction(GPUCompareFunction newFunction) const
 {
-    return m_depthStencilDescriptor.get();
+    // FIXME: Do we need to check if the function value is in range before casting to MTLCompareFunction?
+    [m_metal setDepthCompareFunction:static_cast<MTLCompareFunction>(newFunction)];
 }
 
 } // namespace WebCore
 #import "GPUDepthStencilDescriptor.h"
 #import "GPUDevice.h"
 #import "Logging.h"
-
 #import <Metal/Metal.h>
+#import <wtf/text/WTFString.h>
 
 namespace WebCore {
 
-GPUDepthStencilState::GPUDepthStencilState(GPUDevice* device, GPUDepthStencilDescriptor* descriptor)
+GPUDepthStencilState::GPUDepthStencilState(const GPUDevice& device, const GPUDepthStencilDescriptor& descriptor)
+    : m_metal { adoptNS([device.metal() newDepthStencilStateWithDescriptor:descriptor.metal()]) }
 {
     LOG(WebGPU, "GPUDepthStencilState::GPUDepthStencilState()");
-
-    if (!device || !device->platformDevice() || !descriptor || !descriptor->platformDepthStencilDescriptor())
-        return;
-
-    m_depthStencilState = adoptNS((MTLDepthStencilState *)[device->platformDevice() newDepthStencilStateWithDescriptor:descriptor->platformDepthStencilDescriptor()]);
 }
 
 String GPUDepthStencilState::label() const
 {
-    if (!m_depthStencilState)
+    if (!m_metal)
         return emptyString();
 
-    return [m_depthStencilState label];
+    return [m_metal label];
 }
 
-void GPUDepthStencilState::setLabel(const String& label)
+void GPUDepthStencilState::setLabel(const String&) const
 {
-    ASSERT(m_depthStencilState);
-    [m_depthStencilState setLabel:label];
+    // FIXME: The MTLDepthStencilState protocol does not allow setting the label.
+    // The label has to be set on the descriptor when creating the state object.
+    // We should consider changing the WebGPU interface to not require this!
 }
     
-MTLDepthStencilState *GPUDepthStencilState::platformDepthStencilState()
-{
-    return m_depthStencilState.get();
-}
-
 } // namespace WebCore
 
 #endif
 #import "config.h"
 #import "GPUDevice.h"
 
+#if ENABLE(WEBGPU)
+
 #import "Logging.h"
 #import "WebGPULayer.h"
-
 #import <JavaScriptCore/ArrayBuffer.h>
 #import <Metal/Metal.h>
 #import <wtf/BlockObjCExceptions.h>
 
-#if ENABLE(WEBGPU)
-
 namespace WebCore {
 
 GPUDevice::GPUDevice()
+    : m_metal { adoptNS(MTLCreateSystemDefaultDevice()) }
 {
-    m_device = MTLCreateSystemDefaultDevice();
 
-    if (!m_device) {
+    if (!m_metal) {
         LOG(WebGPU, "GPUDevice::GPUDevice -- could not create the device. This usually means Metal is not available on this hardware.");
         return;
     }
 
-    LOG(WebGPU, "GPUDevice::GPUDevice Metal device is %p", m_device.get());
+    LOG(WebGPU, "GPUDevice::GPUDevice Metal device is %p", m_metal.get());
 
     BEGIN_BLOCK_OBJC_EXCEPTIONS
-    m_layer = [[WebGPULayer alloc] initWithGPUDevice:this];
+
+    m_layer = adoptNS([[WebGPULayer alloc] initWithGPUDevice:this]);
     [m_layer setOpaque:0];
     [m_layer setName:@"WebGPU Layer"];
 
     // FIXME: WebGPU - Should this be in the WebGPULayer initializer?
-    [m_layer setDevice:(id<MTLDevice>)m_device.get()];
+    [m_layer setDevice:m_metal.get()];
     [m_layer setPixelFormat:MTLPixelFormatBGRA8Unorm];
     [m_layer setFramebufferOnly:YES];
+
     END_BLOCK_OBJC_EXCEPTIONS
 }
 
-void GPUDevice::reshape(int width, int height)
+void GPUDevice::disconnect()
 {
-    if (!m_device)
-        return;
+    m_layer.get().context = nullptr;
+    // FIXME: Should we also clear out the device property, which has the MTLDevice?
+}
 
-    if (m_layer) {
-        [m_layer setBounds:CGRectMake(0, 0, width, height)];
-        [m_layer setDrawableSize:CGSizeMake(width, height)];
-    }
+void GPUDevice::reshape(int width, int height) const
+{
+    [m_layer setBounds:CGRectMake(0, 0, width, height)];
+    [m_layer setDrawableSize:CGSizeMake(width, height)];
 
     // FIXME: WebGPU - Lots of reshape stuff should go here. See GC3D.
 }
 
-id GPUDevice::platformDevice()
+CALayer *GPUDevice::platformLayer() const
+{
+    return m_layer.get();
+}
+
+bool GPUDevice::operator!() const
 {
-    return m_device.get();
+    return !m_metal;
 }
 
 } // namespace WebCore
 
 #import "GPUDevice.h"
 #import "Logging.h"
-
 #import <Metal/Metal.h>
 #import <QuartzCore/QuartzCore.h>
 
 namespace WebCore {
 
-GPUDrawable::GPUDrawable(GPUDevice* device)
+GPUDrawable::GPUDrawable(const GPUDevice& device)
+    : m_metal { [device.layer() nextDrawable] }
 {
     LOG(WebGPU, "GPUDrawable::GPUDrawable()");
-
-    if (!device || !device->platformDevice())
-        return;
-
-    m_drawable = (MTLDrawable *)[static_cast<CAMetalLayer*>(device->platformLayer()) nextDrawable];
 }
 
 void GPUDrawable::release()
 {
     LOG(WebGPU, "GPUDrawable::release()");
-    m_drawable = nullptr;
+    m_metal = nil;
 }
     
-MTLDrawable *GPUDrawable::platformDrawable()
+MTLDrawable *GPUDrawable::metal() const
 {
-    return m_drawable.get();
+    return m_metal.get();
 }
 
-MTLTexture *GPUDrawable::platformTexture()
+MTLTexture *GPUDrawable::texture() const
 {
-    if (!m_drawable)
-        return nullptr;
-    return (MTLTexture *)[(id<CAMetalDrawable>)m_drawable.get() texture];
+    if (![m_metal conformsToProtocol:@protocol(CAMetalDrawable)]) {
+        ASSERT(!m_metal);
+        return nil;
+    }
+    return [(id<CAMetalDrawable>)m_metal.get() texture];
 }
 
 } // namespace WebCore
 #import "GPULibrary.h"
 #import "Logging.h"
 #import <Metal/Metal.h>
+#import <wtf/text/WTFString.h>
 
 namespace WebCore {
 
-GPUFunction::GPUFunction(GPULibrary* library, const String& name)
+GPUFunction::GPUFunction(const GPULibrary& library, const String& name)
+    : m_metal { adoptNS([library.metal() newFunctionWithName:name]) }
 {
     LOG(WebGPU, "GPUFunction::GPUFunction()");
-
-    if (!library || !library->platformLibrary())
-        return;
-
-    m_function = adoptNS((MTLFunction *)[library->platformLibrary() newFunctionWithName:name]);
 }
 
 String GPUFunction::name() const
 {
-    if (!m_function)
+    if (!m_metal)
         return emptyString();
-    
-    return [m_function name];
+
+    return [m_metal name];
 }
 
-MTLFunction *GPUFunction::platformFunction()
+bool GPUFunction::operator!() const
 {
-    return m_function.get();
+    return !m_metal;
 }
 
 } // namespace WebCore
 
 #import "GPUDevice.h"
 #import "Logging.h"
-
 #import <Metal/Metal.h>
+#import <wtf/Vector.h>
+#import <wtf/text/WTFString.h>
 
 namespace WebCore {
 
-GPULibrary::GPULibrary(GPUDevice* device, const String& sourceCode)
+GPULibrary::GPULibrary(const GPUDevice& device, const String& sourceCode)
 {
     LOG(WebGPU, "GPULibrary::GPULibrary()");
 
-    if (!device || !device->platformDevice())
+    if (!device.metal())
         return;
 
     NSError *error = [NSError errorWithDomain:@"com.apple.WebKit.GPU" code:1 userInfo:nil];
-    m_library = adoptNS((MTLLibrary *)[device->platformDevice() newLibraryWithSource:sourceCode options:nil error:&error]);
-    if (!m_library)
+    m_metal = adoptNS([device.metal() newLibraryWithSource:sourceCode options:nil error:&error]);
+    if (!m_metal)
         LOG(WebGPU, "Compilation error: %s", [[error localizedDescription] UTF8String]);
 }
 
 String GPULibrary::label() const
 {
-    if (!m_library)
+    if (!m_metal)
         return emptyString();
 
-    return [m_library label];
-}
-
-void GPULibrary::setLabel(const String& label)
-{
-    ASSERT(m_library);
-    [m_library setLabel:label];
+    return [m_metal label];
 }
 
-Vector<String> GPULibrary::functionNames()
+void GPULibrary::setLabel(const String& label) const
 {
-    if (!m_library)
-        return Vector<String>();
-
-    Vector<String> names;
-
-    NSArray<NSString*> *functionNames = [m_library functionNames];
-    for (NSString *string in functionNames)
-        names.append(string);
-    
-    return names;
+    ASSERT(m_metal);
+    [m_metal setLabel:label];
 }
 
-MTLLibrary *GPULibrary::platformLibrary()
+Vector<String> GPULibrary::functionNames() const
 {
-    return m_library.get();
+    auto array = [m_metal functionNames];
+    Vector<String> vector;
+    vector.reserveInitialCapacity(array.count);
+    for (NSString *string in array)
+        vector.uncheckedAppend(string);
+    return vector;
 }
 
 } // namespace WebCore
diff --git a/Source/WebCore/platform/graphics/metal/GPURenderCommandEncoderMetal.mm b/Source/WebCore/platform/graphics/metal/GPURenderCommandEncoderMetal.mm
new file mode 100644 (file)
index 0000000..c1e62b3
--- /dev/null
@@ -0,0 +1,99 @@
+/*
+ * Copyright (C) 2017 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.
+ */
+
+#import "config.h"
+#import "GPURenderCommandEncoder.h"
+
+#if ENABLE(WEBGPU)
+
+#import "GPUBuffer.h"
+#import "GPUCommandBuffer.h"
+#import "GPUDepthStencilState.h"
+#import "GPURenderPassDescriptor.h"
+#import "GPURenderPipelineState.h"
+#import "Logging.h"
+#import <Metal/Metal.h>
+
+namespace WebCore {
+
+GPURenderCommandEncoder::GPURenderCommandEncoder(const GPUCommandBuffer& buffer, const GPURenderPassDescriptor& descriptor)
+{
+    LOG(WebGPU, "GPURenderCommandEncoder::GPURenderCommandEncoder()");
+
+    if (!descriptor.metal())
+        return;
+
+    m_metal = [buffer.metal() renderCommandEncoderWithDescriptor:descriptor.metal()];
+}
+
+void GPURenderCommandEncoder::setRenderPipelineState(const GPURenderPipelineState& renderPipelineState) const
+{
+    if (!renderPipelineState.metal())
+        return;
+
+    [m_metal setRenderPipelineState:renderPipelineState.metal()];
+}
+
+void GPURenderCommandEncoder::setDepthStencilState(const GPUDepthStencilState& depthStencilState) const
+{
+    if (!depthStencilState.metal())
+        return;
+
+    [m_metal setDepthStencilState:depthStencilState.metal()];
+}
+
+void GPURenderCommandEncoder::setVertexBuffer(const GPUBuffer& buffer, unsigned offset, unsigned index) const
+{
+    if (!buffer.metal())
+        return;
+
+    [m_metal setVertexBuffer:buffer.metal() offset:offset atIndex:index];
+}
+
+void GPURenderCommandEncoder::setFragmentBuffer(const GPUBuffer& buffer, unsigned offset, unsigned index) const
+{
+    if (!buffer.metal())
+        return;
+
+    [m_metal setFragmentBuffer:buffer.metal() offset:offset atIndex:index];
+}
+
+void GPURenderCommandEncoder::drawPrimitives(unsigned type, unsigned start, unsigned count) const
+{
+    // FIXME: Why do we need a specially optimized path for count of 0?
+    if (!count)
+        return;
+
+    [m_metal drawPrimitives:static_cast<MTLPrimitiveType>(type) vertexStart:start vertexCount:count];
+}
+
+void GPURenderCommandEncoder::endEncoding() const
+{
+    [m_metal endEncoding];
+}
+
+} // namespace WebCore
+
+#endif
 
 namespace WebCore {
 
-GPURenderPassAttachmentDescriptor::GPURenderPassAttachmentDescriptor(MTLRenderPassAttachmentDescriptor *attachmentDescriptor)
+GPURenderPassAttachmentDescriptor::GPURenderPassAttachmentDescriptor(MTLRenderPassAttachmentDescriptor *metal)
+    : m_metal { metal }
 {
     LOG(WebGPU, "GPURenderPassAttachmentDescriptor::GPURenderPassAttachmentDescriptor()");
-
-    m_renderPassAttachmentDescriptor = attachmentDescriptor;
 }
 
-unsigned long GPURenderPassAttachmentDescriptor::loadAction() const
+unsigned GPURenderPassAttachmentDescriptor::loadAction() const
 {
-    if (!m_renderPassAttachmentDescriptor)
-        return 0; // FIXME: WebGPU - There is probably a real value for this.
-
-    return [m_renderPassAttachmentDescriptor loadAction];
+    return [m_metal loadAction];
 }
 
-void GPURenderPassAttachmentDescriptor::setLoadAction(unsigned long newLoadAction)
+void GPURenderPassAttachmentDescriptor::setLoadAction(unsigned newLoadAction) const
 {
-    if (!m_renderPassAttachmentDescriptor)
-        return;
-
-    [m_renderPassAttachmentDescriptor setLoadAction:static_cast<MTLLoadAction>(newLoadAction)];
+    // FIXME: Should this range check for legitimate values?
+    [m_metal setLoadAction:static_cast<MTLLoadAction>(newLoadAction)];
 }
 
-unsigned long GPURenderPassAttachmentDescriptor::storeAction() const
+unsigned GPURenderPassAttachmentDescriptor::storeAction() const
 {
-    if (!m_renderPassAttachmentDescriptor)
-        return 0; // FIXME: WebGPU - There is probably a real value for this.
-
-    return [m_renderPassAttachmentDescriptor storeAction];
+    return [m_metal storeAction];
 }
 
-void GPURenderPassAttachmentDescriptor::setStoreAction(unsigned long newStoreAction)
+void GPURenderPassAttachmentDescriptor::setStoreAction(unsigned newStoreAction) const
 {
-    if (!m_renderPassAttachmentDescriptor)
-        return;
-
-    [m_renderPassAttachmentDescriptor setStoreAction:static_cast<MTLStoreAction>(newStoreAction)];
+    // FIXME: Should this range check for legitimate values?
+    [m_metal setStoreAction:static_cast<MTLStoreAction>(newStoreAction)];
 }
 
-void GPURenderPassAttachmentDescriptor::setTexture(RefPtr<GPUTexture> texture)
+void GPURenderPassAttachmentDescriptor::setTexture(const GPUTexture& texture) const
 {
-    if (!m_renderPassAttachmentDescriptor)
-        return;
-    
-    [m_renderPassAttachmentDescriptor setTexture:static_cast<id<MTLTexture>>(texture->platformTexture())];
+    [m_metal setTexture:texture.metal()];
 }
 
-MTLRenderPassAttachmentDescriptor *GPURenderPassAttachmentDescriptor::platformRenderPassAttachmentDescriptor()
+MTLRenderPassAttachmentDescriptor *GPURenderPassAttachmentDescriptor::metal() const
 {
-    return m_renderPassAttachmentDescriptor.get();
+    return m_metal.get();
 }
 
 } // namespace WebCore
 
 #if ENABLE(WEBGPU)
 
-#import "GPURenderPassAttachmentDescriptor.h"
+#import "FloatConversion.h"
 #import "Logging.h"
-
 #import <Metal/Metal.h>
+#import <wtf/Vector.h>
 
 namespace WebCore {
 
-RefPtr<GPURenderPassColorAttachmentDescriptor> GPURenderPassColorAttachmentDescriptor::create(MTLRenderPassColorAttachmentDescriptor *colorAttachmentDescriptor)
-{
-    RefPtr<GPURenderPassColorAttachmentDescriptor> descriptor = adoptRef(new GPURenderPassColorAttachmentDescriptor(colorAttachmentDescriptor));
-    return descriptor;
-}
-
-GPURenderPassColorAttachmentDescriptor::GPURenderPassColorAttachmentDescriptor(MTLRenderPassColorAttachmentDescriptor *attachmentDescriptor)
-    : GPURenderPassAttachmentDescriptor(attachmentDescriptor)
+GPURenderPassColorAttachmentDescriptor::GPURenderPassColorAttachmentDescriptor(MTLRenderPassColorAttachmentDescriptor *metal)
+    : GPURenderPassAttachmentDescriptor { metal }
 {
     LOG(WebGPU, "GPURenderPassColorAttachmentDescriptor::GPURenderPassColorAttachmentDescriptor()");
 }
 
 Vector<float> GPURenderPassColorAttachmentDescriptor::clearColor() const
 {
-    MTLRenderPassColorAttachmentDescriptor *colorAttachmentDescriptor = static_cast<MTLRenderPassColorAttachmentDescriptor *>(m_renderPassAttachmentDescriptor.get());
-    if (!colorAttachmentDescriptor)
-        return Vector<float>();
+    auto* metal = this->metal();
+    if (!metal)
+        return { };
 
-    MTLClearColor color = [colorAttachmentDescriptor clearColor];
-    return Vector<float>({static_cast<float>(color.red), static_cast<float>(color.green), static_cast<float>(color.blue), static_cast<float>(color.alpha)});
+    auto color = [metal clearColor];
+    return { narrowPrecisionToFloat(color.red), narrowPrecisionToFloat(color.green), narrowPrecisionToFloat(color.blue), narrowPrecisionToFloat(color.alpha) };
 }
 
-void GPURenderPassColorAttachmentDescriptor::setClearColor(const Vector<float>& newClearColor)
+void GPURenderPassColorAttachmentDescriptor::setClearColor(const Vector<float>& newClearColor) const
 {
-    MTLRenderPassColorAttachmentDescriptor *colorAttachmentDescriptor = platformRenderPassColorAttachmentDescriptor();
-    if (!colorAttachmentDescriptor || newClearColor.size() != 4)
+    if (newClearColor.size() != 4)
         return;
 
-    MTLClearColor clearColor = MTLClearColorMake(newClearColor[0], newClearColor[1], newClearColor[2], newClearColor[3]);
-    [colorAttachmentDescriptor setClearColor:clearColor];
+    [metal() setClearColor:MTLClearColorMake(newClearColor[0], newClearColor[1], newClearColor[2], newClearColor[3])];
 }
 
-MTLRenderPassColorAttachmentDescriptor *GPURenderPassColorAttachmentDescriptor::platformRenderPassColorAttachmentDescriptor()
+MTLRenderPassColorAttachmentDescriptor *GPURenderPassColorAttachmentDescriptor::metal() const
 {
-    return static_cast<MTLRenderPassColorAttachmentDescriptor *>(platformRenderPassAttachmentDescriptor());
+    return static_cast<MTLRenderPassColorAttachmentDescriptor *>(GPURenderPassAttachmentDescriptor::metal());
 }
 
 } // namespace WebCore