GPUCanvasContext.cpp [plain text]
#include "config.h"
#include "GPUCanvasContext.h"
#include "InspectorInstrumentation.h"
#include "Logging.h"
#include "WebGPUSwapChainDescriptor.h"
#if ENABLE(WEBGPU)
#include <wtf/IsoMallocInlines.h>
namespace WebCore {
WTF_MAKE_ISO_ALLOCATED_IMPL(GPUCanvasContext);
std::unique_ptr<GPUCanvasContext> GPUCanvasContext::create(CanvasBase& canvas)
{
auto context = std::unique_ptr<GPUCanvasContext>(new GPUCanvasContext(canvas));
context->suspendIfNeeded();
return context;
}
GPUCanvasContext::GPUCanvasContext(CanvasBase& canvas)
: GPUBasedCanvasRenderingContext(canvas)
{
}
Ref<WebGPUSwapChain> GPUCanvasContext::configureSwapChain(const WebGPUSwapChainDescriptor& descriptor)
{
auto gpuDescriptor = descriptor.asGPUSwapChainDescriptor();
if (!gpuDescriptor)
return WebGPUSwapChain::create(nullptr);
auto gpuSwapChain = GPUSwapChain::tryCreate(*gpuDescriptor, canvasBase().width(), canvasBase().height());
bool success = gpuSwapChain;
auto newSwapChain = WebGPUSwapChain::create(WTFMove(gpuSwapChain));
if (success) {
if (m_swapChain)
m_swapChain->destroy();
InspectorInstrumentation::willConfigureSwapChain(*this, newSwapChain.get());
m_swapChain = newSwapChain.copyRef();
notifyCanvasContentChanged();
}
return newSwapChain;
}
CALayer* GPUCanvasContext::platformLayer() const
{
if (m_swapChain && m_swapChain->swapChain())
return m_swapChain->swapChain()->platformLayer();
return nullptr;
}
void GPUCanvasContext::reshape(int width, int height)
{
if (m_swapChain && m_swapChain->swapChain())
m_swapChain->swapChain()->reshape(width, height);
notifyCanvasContentChanged();
}
void GPUCanvasContext::markLayerComposited()
{
if (m_swapChain && m_swapChain->swapChain())
m_swapChain->swapChain()->present();
}
}
#endif // ENABLE(WEBGPU)