Commit 1879494b authored by Andy Leiserson's avatar Andy Leiserson Committed by egubler@mozilla.com
Browse files

Bug 1967612 - Implement `GPUCanvasContext.getConfiguration`...

Bug 1967612 - Implement `GPUCanvasContext.getConfiguration` r=webgpu-reviewers,ErichDonGubler,webidl,smaug,nical

Differential Revision: https://phabricator.services.mozilla.com/D250572
parent cfa39f78
Loading
Loading
Loading
Loading
+10 −1
Original line number Diff line number Diff line
@@ -201,9 +201,18 @@ NS_IMETHODIMP CanvasContext::SetDimensions(int32_t aWidth, int32_t aHeight) {
  return NS_OK;
}

void CanvasContext::GetConfiguration(
    dom::Nullable<dom::GPUCanvasConfiguration>& aRv) {
  if (mConfiguration) {
    aRv.SetValue(*mConfiguration);
  } else {
    aRv.SetNull();
  }
}

RefPtr<Texture> CanvasContext::GetCurrentTexture(ErrorResult& aRv) {
  if (!mCurrentTexture) {
    aRv.ThrowOperationError("Canvas not configured");
    aRv.ThrowInvalidStateError("Canvas not configured");
    return nullptr;
  }

+1 −0
Original line number Diff line number Diff line
@@ -92,6 +92,7 @@ class CanvasContext final : public nsICanvasRenderingContextInternal,
  void Configure(const dom::GPUCanvasConfiguration& aConfig, ErrorResult& aRv);
  void Unconfigure();

  void GetConfiguration(dom::Nullable<dom::GPUCanvasConfiguration>& aRv);
  RefPtr<Texture> GetCurrentTexture(ErrorResult& aRv);
  void MaybeQueueSwapChainPresent();
  Maybe<layers::SurfaceDescriptor> SwapChainPresent();
+35 −5
Original line number Diff line number Diff line
@@ -13,16 +13,45 @@
      );

      async function testBody() {
        const adapter = await navigator.gpu.requestAdapter({});
        const device = await adapter.requestDevice({});
        const canvas = document.createElement("canvas");
        const context = canvas.getContext("webgpu");

        // The first two tests here are redundant with the CTS test
        // webgpu:web_platform,canvas,configure:device:*, but when
        // they were added, that CTS test had additional checks that
        // were still failing.
        let expectedError;
        try {
          context.configure({});
        } catch (error) {
          expectedError = error;
        }
        is(
          expectedError?.name,
          "TypeError",
          "Canvas configure without a device should generate a TypeError."
        );

        const adapter = await navigator.gpu.requestAdapter({});
        const device = await adapter.requestDevice({});
        const format = navigator.gpu.getPreferredCanvasFormat(adapter);

        expectedError = undefined;
        try {
          context.getCurrentTexture();
        } catch (error) {
          expectedError = error;
        }
        is(
          expectedError?.name,
          "InvalidStateError",
          "getCurrentTexture on unconfigured canvas should generate an InvalidStateError."
        );

        // Attempt to configure with a too-large canvas, which should
        // fail due to device texture limits.
        canvas.width = 1970696937;
        let expectedError;
        expectedError = undefined;
        try {
          context.configure({
            device,
@@ -31,9 +60,10 @@
        } catch (error) {
          expectedError = error;
        }
        // Bug 1864904: This should become an "is".
        // Bug 1967833: This should become an "is". Or possibly it
        // should expect a validation error (asynchronously) instead.
        todo_is(
          typeof expectedError,
          expectedError?.name,
          "TypeError",
          "Failed configure should generate a TypeError."
        );
+3 −1
Original line number Diff line number Diff line
@@ -1261,6 +1261,7 @@ interface GPUCanvasContext {
    undefined configure(GPUCanvasConfiguration configuration);
    undefined unconfigure();

    GPUCanvasConfiguration? getConfiguration();
    [Throws]
    GPUTexture getCurrentTexture();
};
@@ -1275,7 +1276,8 @@ dictionary GPUCanvasConfiguration {
    required GPUTextureFormat format;
    GPUTextureUsageFlags usage = 0x10;  // GPUTextureUsage.RENDER_ATTACHMENT
    sequence<GPUTextureFormat> viewFormats = [];
    //GPUPredefinedColorSpace colorSpace = "srgb"; //TODO
    //GPUPredefinedColorSpace colorSpace = "srgb"; //TODO bug 1834395
    //GPUCanvasToneMapping toneMapping = {}; //TODO bug 1834395
    GPUCanvasAlphaMode alphaMode = "opaque";
};

+0 −7
Original line number Diff line number Diff line
[cts.https.html?q=webgpu:web_platform,canvas,configure:alpha_mode:*]
  implementation-status: backlog
  [:canvasType="offscreen"]
    expected: FAIL

  [:canvasType="onscreen"]
    expected: FAIL


[cts.https.html?q=webgpu:web_platform,canvas,configure:defaults:*]
@@ -112,7 +109,6 @@
  [:canvasType="offscreen";format="bc7-rgba-unorm-srgb"]

  [:canvasType="offscreen";format="bgra8unorm"]
    expected: FAIL

  [:canvasType="offscreen";format="bgra8unorm-srgb"]

@@ -214,7 +210,6 @@
  [:canvasType="offscreen";format="rgba8uint"]

  [:canvasType="offscreen";format="rgba8unorm"]
    expected: FAIL

  [:canvasType="offscreen";format="rgba8unorm-srgb"]

@@ -305,7 +300,6 @@
  [:canvasType="onscreen";format="bc7-rgba-unorm-srgb"]

  [:canvasType="onscreen";format="bgra8unorm"]
    expected: FAIL

  [:canvasType="onscreen";format="bgra8unorm-srgb"]

@@ -407,7 +401,6 @@
  [:canvasType="onscreen";format="rgba8uint"]

  [:canvasType="onscreen";format="rgba8unorm"]
    expected: FAIL

  [:canvasType="onscreen";format="rgba8unorm-srgb"]