Skip to content

Commit

Permalink
[WebGPU] GPUTexture returned from GPUCanvasContext.getCurrentTexture(…
Browse files Browse the repository at this point in the history
…) has the wrong size

https://bugs.webkit.org/show_bug.cgi?id=269262
<radar://122847972>

Reviewed by Dan Glastonbury.

We were returning a GPUTexture instance that reported a
size of 1x1, which is incorrect.

* Source/WebCore/Modules/WebGPU/GPUPresentationContext.cpp:
(WebCore::GPUPresentationContext::configure):
(WebCore::GPUPresentationContext::getCurrentTexture):
* Source/WebCore/Modules/WebGPU/GPUPresentationContext.h:
* Source/WebCore/html/canvas/GPUCanvasContextCocoa.h:
* Source/WebCore/html/canvas/GPUCanvasContextCocoa.mm:
(WebCore::getCanvasWidth):
(WebCore::getCanvasHeight):
(WebCore::GPUCanvasContextCocoa::reshape):
(WebCore::GPUCanvasContextCocoa::configure):

Canonical link: https://commits.webkit.org/274571@main
  • Loading branch information
mwyrzykowski committed Feb 13, 2024
1 parent 5821ffe commit 60b6c37
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 17 deletions.
16 changes: 12 additions & 4 deletions Source/WebCore/Modules/WebGPU/GPUPresentationContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,20 @@

namespace WebCore {

void GPUPresentationContext::configure(const GPUCanvasConfiguration& canvasConfiguration)
void GPUPresentationContext::configure(const GPUCanvasConfiguration& canvasConfiguration, GPUIntegerCoordinate width, GPUIntegerCoordinate height)
{
m_device = canvasConfiguration.device;
m_backing->configure(canvasConfiguration.convertToBacking());
m_textureDescriptor = GPUTextureDescriptor {
{ "canvas backing"_s },
GPUExtent3DDict { width, height, 1 },
1,
1,
GPUTextureDimension::_2d,
GPUTextureFormat::Bgra8unorm,
canvasConfiguration.usage,
canvasConfiguration.viewFormats
};
}

void GPUPresentationContext::unconfigure()
Expand All @@ -48,9 +58,7 @@ RefPtr<GPUTexture> GPUPresentationContext::getCurrentTexture()
{
if (!m_currentTexture && m_device.get()) {
if (auto currentTexture = m_backing->getCurrentTexture()) {
GPUTextureDescriptor textureDescriptor;
textureDescriptor.format = GPUTextureFormat::Bgra8unorm;
m_currentTexture = GPUTexture::create(*currentTexture, textureDescriptor, *m_device.get()).ptr();
m_currentTexture = GPUTexture::create(*currentTexture, m_textureDescriptor, *m_device.get()).ptr();
}
}

Expand Down
4 changes: 3 additions & 1 deletion Source/WebCore/Modules/WebGPU/GPUPresentationContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#pragma once

#include "GPUTexture.h"
#include "GPUTextureDescriptor.h"
#include "WebGPUPresentationContext.h"
#include <wtf/CompletionHandler.h>
#include <wtf/Ref.h>
Expand All @@ -48,7 +49,7 @@ class GPUPresentationContext : public RefCounted<GPUPresentationContext> {
return adoptRef(*new GPUPresentationContext(WTFMove(backing)));
}

void configure(const GPUCanvasConfiguration&);
void configure(const GPUCanvasConfiguration&, GPUIntegerCoordinate, GPUIntegerCoordinate);
void unconfigure();

RefPtr<GPUTexture> getCurrentTexture();
Expand All @@ -66,6 +67,7 @@ class GPUPresentationContext : public RefCounted<GPUPresentationContext> {
Ref<WebGPU::PresentationContext> m_backing;
RefPtr<GPUTexture> m_currentTexture;
RefPtr<const GPUDevice> m_device;
GPUTextureDescriptor m_textureDescriptor;
};

}
4 changes: 2 additions & 2 deletions Source/WebCore/html/canvas/GPUCanvasContextCocoa.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ class GPUCanvasContextCocoa final : public GPUCanvasContext {
Ref<GPUPresentationContext> m_presentationContext;
RefPtr<GPUTexture> m_currentTexture;

int m_width { 0 };
int m_height { 0 };
GPUIntegerCoordinate m_width { 0 };
GPUIntegerCoordinate m_height { 0 };
bool m_compositingResultsNeedsUpdating { false };
};

Expand Down
20 changes: 10 additions & 10 deletions Source/WebCore/html/canvas/GPUCanvasContextCocoa.mm
Original file line number Diff line number Diff line change
Expand Up @@ -106,26 +106,26 @@ static GPUPresentationContextDescriptor presentationContextDescriptor(GPUComposi
};
}

static int getCanvasWidth(const GPUCanvasContext::CanvasType& canvas)
static GPUIntegerCoordinate getCanvasWidth(const GPUCanvasContext::CanvasType& canvas)
{
return WTF::switchOn(canvas, [](const RefPtr<HTMLCanvasElement>& htmlCanvas) -> int {
return WTF::switchOn(canvas, [](const RefPtr<HTMLCanvasElement>& htmlCanvas) -> GPUIntegerCoordinate {
return htmlCanvas->width();
}
#if ENABLE(OFFSCREEN_CANVAS)
, [](const RefPtr<OffscreenCanvas>& offscreenCanvas) -> int {
, [](const RefPtr<OffscreenCanvas>& offscreenCanvas) -> GPUIntegerCoordinate {
return offscreenCanvas->width();
}
#endif
);
}

static int getCanvasHeight(const GPUCanvasContext::CanvasType& canvas)
static GPUIntegerCoordinate getCanvasHeight(const GPUCanvasContext::CanvasType& canvas)
{
return WTF::switchOn(canvas, [](const RefPtr<HTMLCanvasElement>& htmlCanvas) -> int {
return WTF::switchOn(canvas, [](const RefPtr<HTMLCanvasElement>& htmlCanvas) -> GPUIntegerCoordinate {
return htmlCanvas->height();
}
#if ENABLE(OFFSCREEN_CANVAS)
, [](const RefPtr<OffscreenCanvas>& offscreenCanvas) -> int {
, [](const RefPtr<OffscreenCanvas>& offscreenCanvas) -> GPUIntegerCoordinate {
return offscreenCanvas->height();
}
#endif
Expand All @@ -151,11 +151,11 @@ static int getCanvasHeight(const GPUCanvasContext::CanvasType& canvas)

void GPUCanvasContextCocoa::reshape(int width, int height)
{
if (m_width == width && m_height == height)
if (width <= 0 || height <= 0 || (m_width == static_cast<GPUIntegerCoordinate>(width) && m_height == static_cast<GPUIntegerCoordinate>(height)))
return;

m_width = width;
m_height = height;
m_width = static_cast<GPUIntegerCoordinate>(width);
m_height = static_cast<GPUIntegerCoordinate>(height);

auto configuration = WTFMove(m_configuration);
m_configuration.reset();
Expand Down Expand Up @@ -212,7 +212,7 @@ static int getCanvasHeight(const GPUCanvasContext::CanvasType& canvas)
// FIXME: This ASSERT() is wrong. It's totally possible for the IPC to the GPU process to timeout if the GPUP is busy, and return nothing here.
ASSERT(!renderBuffers.isEmpty());

m_presentationContext->configure(configuration);
m_presentationContext->configure(configuration, m_width, m_height);

m_configuration = {
*configuration.device,
Expand Down

0 comments on commit 60b6c37

Please sign in to comment.