Skip to content

Commit

Permalink
[WebGPU] Give a ConvertToBackingContext to SurfaceImpl and SwapChainImpl
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=250964
rdar://104522936

Reviewed by Kimmo Kinnunen.

SurfaceImpl and SwapChainImpl don't actually need a ConvertToBackingContext right now, but
most of the other ***Impl classes need one and have one, so I think it's just generally a
good idea to be consistent with the pattern and give one to all the ***Impl classes. In the
future, when we're developing, I don't think we should have to remember which classes have
a ConvertToBackingContext and which don't.

* Source/WebCore/PAL/pal/graphics/WebGPU/Impl/WebGPUSurfaceImpl.cpp:
(PAL::WebGPU::SurfaceImpl::SurfaceImpl):
(PAL::WebGPU::SurfaceImpl::setLabelInternal):
* Source/WebCore/PAL/pal/graphics/WebGPU/Impl/WebGPUSurfaceImpl.h:
* Source/WebCore/PAL/pal/graphics/WebGPU/Impl/WebGPUSwapChainImpl.cpp:
(PAL::WebGPU::SwapChainImpl::SwapChainImpl):
* Source/WebCore/PAL/pal/graphics/WebGPU/Impl/WebGPUSwapChainImpl.h:

Canonical link: https://commits.webkit.org/259235@main
  • Loading branch information
litherum committed Jan 23, 2023
1 parent 703601b commit db1acf9
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 17 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2021-2022 Apple Inc. All rights reserved.
* Copyright (C) 2021-2023 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
Expand Down Expand Up @@ -188,7 +188,7 @@ Ref<Surface> DeviceImpl::createSurface(const SurfaceDescriptor& descriptor)
label.data()
};

return SurfaceImpl::create(wgpuInstanceCreateSurface(nullptr, &surfaceDescriptor));
return SurfaceImpl::create(wgpuInstanceCreateSurface(nullptr, &surfaceDescriptor), m_convertToBackingContext);
}

Ref<SwapChain> DeviceImpl::createSwapChain(const Surface& surface, const SwapChainDescriptor& descriptor)
Expand All @@ -208,7 +208,7 @@ Ref<SwapChain> DeviceImpl::createSwapChain(const Surface& surface, const SwapCha
};

WGPUSurface wgpuSurface = m_convertToBackingContext->convertToBacking(surface);
return SwapChainImpl::create(wgpuSurface, wgpuDeviceCreateSwapChain(backing(), wgpuSurface, &backingDescriptor));
return SwapChainImpl::create(wgpuSurface, wgpuDeviceCreateSwapChain(backing(), wgpuSurface, &backingDescriptor), m_convertToBackingContext);
}

Ref<Sampler> DeviceImpl::createSampler(const SamplerDescriptor& descriptor)
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2022 Apple Inc. All rights reserved.
* Copyright (C) 2022-2023 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
Expand Down Expand Up @@ -36,8 +36,9 @@

namespace PAL::WebGPU {

SurfaceImpl::SurfaceImpl(WGPUSurface surface)
SurfaceImpl::SurfaceImpl(WGPUSurface surface, ConvertToBackingContext& convertToBackingContext)
: m_backing(surface)
, m_convertToBackingContext(convertToBackingContext)
{
}

Expand All @@ -51,9 +52,8 @@ void SurfaceImpl::destroy()
wgpuSurfaceRelease(m_backing);
}

void SurfaceImpl::setLabelInternal(const String& label)
void SurfaceImpl::setLabelInternal(const String&)
{
UNUSED_PARAM(label);
}

IOSurfaceRef SurfaceImpl::drawingBuffer() const
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2022 Apple Inc. All rights reserved.
* Copyright (C) 2022-2023 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
Expand Down Expand Up @@ -41,9 +41,9 @@ class ConvertToBackingContext;
class SurfaceImpl final : public Surface {
WTF_MAKE_FAST_ALLOCATED;
public:
static Ref<SurfaceImpl> create(WGPUSurface surface)
static Ref<SurfaceImpl> create(WGPUSurface surface, ConvertToBackingContext& convertToBackingContext)
{
return adoptRef(*new SurfaceImpl(surface));
return adoptRef(*new SurfaceImpl(surface, convertToBackingContext));
}

virtual ~SurfaceImpl();
Expand All @@ -54,7 +54,7 @@ class SurfaceImpl final : public Surface {
private:
friend class DowncastConvertToBackingContext;

SurfaceImpl(WGPUSurface);
SurfaceImpl(WGPUSurface, ConvertToBackingContext&);

SurfaceImpl(const SurfaceImpl&) = delete;
SurfaceImpl(SurfaceImpl&&) = delete;
Expand All @@ -66,6 +66,7 @@ class SurfaceImpl final : public Surface {
void setLabelInternal(const String&) final;

WGPUSurface m_backing { nullptr };
Ref<ConvertToBackingContext> m_convertToBackingContext;
};

} // namespace PAL::WebGPU
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2022 Apple Inc. All rights reserved.
* Copyright (C) 2022-2023 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
Expand Down Expand Up @@ -36,9 +36,10 @@

namespace PAL::WebGPU {

SwapChainImpl::SwapChainImpl(WGPUSurface surface, WGPUSwapChain swapChain)
SwapChainImpl::SwapChainImpl(WGPUSurface surface, WGPUSwapChain swapChain, ConvertToBackingContext& convertToBackingContext)
: m_backing(swapChain)
, m_surface(surface)
, m_convertToBackingContext(convertToBackingContext)
{
}

Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2021 Apple Inc. All rights reserved.
* Copyright (C) 2021-2023 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
Expand Down Expand Up @@ -34,20 +34,22 @@

namespace PAL::WebGPU {

class ConvertToBackingContext;

class SwapChainImpl final : public SwapChain {
WTF_MAKE_FAST_ALLOCATED;
public:
static Ref<SwapChainImpl> create(WGPUSurface surface, WGPUSwapChain swapChain)
static Ref<SwapChainImpl> create(WGPUSurface surface, WGPUSwapChain swapChain, ConvertToBackingContext& convertToBackingContext)
{
return adoptRef(*new SwapChainImpl(surface, swapChain));
return adoptRef(*new SwapChainImpl(surface, swapChain, convertToBackingContext));
}

virtual ~SwapChainImpl();

private:
friend class DowncastConvertToBackingContext;

SwapChainImpl(WGPUSurface, WGPUSwapChain);
SwapChainImpl(WGPUSurface, WGPUSwapChain, ConvertToBackingContext&);

SwapChainImpl(const SwapChainImpl&) = delete;
SwapChainImpl(SwapChainImpl&&) = delete;
Expand All @@ -65,6 +67,7 @@ class SwapChainImpl final : public SwapChain {

WGPUSwapChain m_backing { nullptr };
WGPUSurface m_surface { nullptr };
Ref<ConvertToBackingContext> m_convertToBackingContext;
};

} // namespace PAL::WebGPU
Expand Down

0 comments on commit db1acf9

Please sign in to comment.