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
This commit is contained in:
Jonathan Kew 2023-07-25 18:37:34 +00:00
Родитель d1525c4575
Коммит 2231ef7c87
4 изменённых файлов: 24 добавлений и 21 удалений

Просмотреть файл

@ -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;

Просмотреть файл

@ -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;

Просмотреть файл

@ -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;

Просмотреть файл

@ -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