From 2231ef7c87170a00bb30c21e997b62d9ea670b99 Mon Sep 17 00:00:00 2001 From: Jonathan Kew Date: Tue, 25 Jul 2023 18:37:34 +0000 Subject: [PATCH] Bug 1517786 - Implement the getContextAttributes() method for CanvasRenderingContext2D. r=gfx-reviewers,lsalzman,emilio This has been in the HTML spec for a while now (see https://html.spec.whatwg.org/multipage/canvas.html#2dcontext), so we should probably go ahead and implement it. Differential Revision: https://phabricator.services.mozilla.com/D184499 --- dom/canvas/CanvasRenderingContext2D.cpp | 13 ++++++++++++- dom/canvas/CanvasRenderingContext2D.h | 2 ++ dom/webidl/CanvasRenderingContext2D.webidl | 13 ++++++++++--- .../getContextAttributes.html.ini | 17 ----------------- 4 files changed, 24 insertions(+), 21 deletions(-) delete mode 100644 testing/web-platform/meta/html/canvas/element/manual/context-attributes/getContextAttributes.html.ini diff --git a/dom/canvas/CanvasRenderingContext2D.cpp b/dom/canvas/CanvasRenderingContext2D.cpp index f82a3f4b2dd2..a1b4ae5c047f 100644 --- a/dom/canvas/CanvasRenderingContext2D.cpp +++ b/dom/canvas/CanvasRenderingContext2D.cpp @@ -1136,6 +1136,17 @@ JSObject* CanvasRenderingContext2D::WrapObject( return CanvasRenderingContext2D_Binding::Wrap(aCx, this, aGivenProto); } +void CanvasRenderingContext2D::GetContextAttributes( + CanvasRenderingContext2DSettings& aSettings) const { + aSettings = CanvasRenderingContext2DSettings(); + + aSettings.mAlpha = mContextAttributesHasAlpha; + aSettings.mWillReadFrequently = mWillReadFrequently; + + // We don't support the 'desynchronized' and 'colorSpace' attributes, so + // those just keep their default values. +} + CanvasRenderingContext2D::ColorStyleCacheEntry CanvasRenderingContext2D::ParseColorSlow(const nsACString& aString) { ColorStyleCacheEntry result{nsCString(aString)}; @@ -1881,7 +1892,7 @@ CanvasRenderingContext2D::SetContextOptions(JSContext* aCx, // drawtarget yet MOZ_ASSERT(!mTarget); - ContextAttributes2D attributes; + CanvasRenderingContext2DSettings attributes; if (!attributes.Init(aCx, aOptions)) { aRvForDictionaryInit.Throw(NS_ERROR_UNEXPECTED); return NS_ERROR_UNEXPECTED; diff --git a/dom/canvas/CanvasRenderingContext2D.h b/dom/canvas/CanvasRenderingContext2D.h index b975a7d9ac52..2a49c4137d62 100644 --- a/dom/canvas/CanvasRenderingContext2D.h +++ b/dom/canvas/CanvasRenderingContext2D.h @@ -96,6 +96,8 @@ class CanvasRenderingContext2D : public nsICanvasRenderingContextInternal, return mCanvasElement->GetOriginalCanvas(); } + void GetContextAttributes(CanvasRenderingContext2DSettings& aSettings) const; + void OnMemoryPressure() override; void OnBeforePaintTransaction() override; void OnDidPaintTransaction() override; diff --git a/dom/webidl/CanvasRenderingContext2D.webidl b/dom/webidl/CanvasRenderingContext2D.webidl index 3e5e9a0ec1b8..49b06be5ec06 100644 --- a/dom/webidl/CanvasRenderingContext2D.webidl +++ b/dom/webidl/CanvasRenderingContext2D.webidl @@ -24,11 +24,16 @@ enum CanvasFontVariantCaps { "normal", "small-caps", "all-small-caps", "petite-c enum CanvasTextRendering { "auto", "optimizeSpeed", "optimizeLegibility", "geometricPrecision" }; [GenerateInit] -dictionary ContextAttributes2D { - // whether or not we're planning to do a lot of readback operations - boolean willReadFrequently = false; +dictionary CanvasRenderingContext2DSettings { // signal if the canvas contains an alpha channel boolean alpha = true; + + boolean desynchronized = false; + + PredefinedColorSpace colorSpace = "srgb"; + + // whether or not we're planning to do a lot of readback operations + boolean willReadFrequently = false; }; dictionary HitRegionOptions { @@ -54,6 +59,8 @@ interface CanvasRenderingContext2D { // associated with a canvas. readonly attribute HTMLCanvasElement? canvas; + CanvasRenderingContext2DSettings getContextAttributes(); + // Show the caret if appropriate when drawing [Func="CanvasUtils::HasDrawWindowPrivilege"] const unsigned long DRAWWINDOW_DRAW_CARET = 0x01; diff --git a/testing/web-platform/meta/html/canvas/element/manual/context-attributes/getContextAttributes.html.ini b/testing/web-platform/meta/html/canvas/element/manual/context-attributes/getContextAttributes.html.ini deleted file mode 100644 index de1d33be8724..000000000000 --- a/testing/web-platform/meta/html/canvas/element/manual/context-attributes/getContextAttributes.html.ini +++ /dev/null @@ -1,17 +0,0 @@ -[getContextAttributes.html] - expected: - if (os == "android") and fission: [OK, TIMEOUT] - [Test context creation attributes alpha: true] - expected: FAIL - - [Test context creation attributes alpha: false] - expected: FAIL - - [Test default context creation attributes] - expected: FAIL - - [Test context creation attributes desynchronized: false] - expected: FAIL - - [Test context creation attributes willReadFrequently: true] - expected: FAIL