From 8927cc6bf5ba0684f839c72fc76c2fb9a8cf7c67 Mon Sep 17 00:00:00 2001 From: Christopher Cameron Date: Tue, 7 Jan 2025 22:22:34 +0000 Subject: [PATCH] Merge offscreen and onscreen CanvasRenderingContext2DSettings --- source | 253 ++++++++++++++++++++++++++++----------------------------- 1 file changed, 125 insertions(+), 128 deletions(-) diff --git a/source b/source index 0639bb4821c..f9fbcaea7f6 100644 --- a/source +++ b/source @@ -64640,8 +64640,9 @@ callback BlobCallback = undefined (Blob? blob);

The bitmaps of canvas elements, the bitmaps of ImageBitmap objects, as well as some of the bitmaps of rendering contexts, such as those described in the sections on - the CanvasRenderingContext2D and ImageBitmapRenderingContext objects - below, have an origin-clean flag, which can be + the CanvasRenderingContext2D, OffscreenCanvasRenderingContext2D, and + ImageBitmapRenderingContext objects below, + have an origin-clean flag, which can be set to true or false. Initially, when the canvas element or ImageBitmap object is created, its bitmap's origin-clean flag must be set to true.

@@ -65105,9 +65106,8 @@ enum ImageSmoothingQuality { "canvas; - - CanvasRenderingContext2DSettings getContextAttributes(); }; +CanvasRenderingContext2D includes CanvasBitmap; CanvasRenderingContext2D includes CanvasState; CanvasRenderingContext2D includes CanvasTransform; CanvasRenderingContext2D includes CanvasCompositing; @@ -65125,6 +65125,11 @@ interface CanvasRenderingContext2D { CanvasRenderingContext2D includes CanvasTextDrawingStyles; CanvasRenderingContext2D includes CanvasPath; +interface mixin CanvasBitmap { + // bitmap + CanvasRenderingContext2DSettings getContextAttributes(); +}; + interface mixin CanvasState { // state undefined save(); // push state on state stack @@ -65416,89 +65421,6 @@ interface Path2D {
-

A CanvasRenderingContext2D object has an output bitmap that - is initialized when the object is created.

- -

The output bitmap has an origin-clean flag, which can be set to true or false. - Initially, when one of these bitmaps is created, its origin-clean flag must be set to true.

- -

The CanvasRenderingContext2D object also has an alpha boolean. When a - CanvasRenderingContext2D object's alpha is false, then its alpha channel must be fixed to 1.0 - (fully opaque) for all pixels, and attempts to change the alpha component of any pixel must be - silently ignored.

- -

Thus, the bitmap of such a context starts off as opaque black instead - of transparent black; clearRect() - always results in opaque black pixels, every fourth byte from getImageData() is always 255, the putImageData() method effectively ignores every - fourth byte in its input, and so on. However, the alpha component of styles and images drawn - onto the canvas are still honoured up to the point where they would impact the output - bitmap's alpha channel; for instance, drawing a 50% transparent white square on a freshly - created output bitmap with its alpha set - to false will result in a fully-opaque gray square.

- -

The CanvasRenderingContext2D object also has a desynchronized boolean. When a - CanvasRenderingContext2D object's desynchronized is true, then the user agent may - optimize the rendering of the canvas to reduce the latency, as measured from input events to - rasterization, by desynchronizing the canvas paint cycle from the event loop, bypassing the - ordinary user agent rendering algorithm, or both. Insofar as this mode involves bypassing the - usual paint mechanisms, rasterization, or both, it might introduce visible tearing artifacts.

- -

The user agent usually renders on a buffer which is not being displayed, quickly - swapping it and the one being scanned out for presentation; the former buffer is called - back buffer and the latter front buffer. A popular technique for reducing latency is called - front buffer rendering, also known as single buffer rendering, where rendering happens in - parallel and racily with the scanning out process. This technique reduces the latency at the price - of potentially introducing tearing artifacts and can be used to implement in total or part of the - desynchronized boolean. - MULTIPLEBUFFERING

- -

The desynchronized boolean - can be useful when implementing certain kinds of applications, such as drawing applications, - where the latency between input and rasterization is critical.

- -

The CanvasRenderingContext2D object also has a will read frequently boolean. When a - CanvasRenderingContext2D object's will read frequently is true, the user agent - may optimize the canvas for readback operations.

- -

On most devices the user agent needs to decide whether to store the canvas's - output bitmap on the GPU (this is also called "hardware accelerated"), or on the CPU - (also called "software"). Most rendering operations are more performant for accelerated canvases, - with the major exception being readback with getImageData(), toDataURL(), or toBlob(). CanvasRenderingContext2D objects with - will read frequently equal to true tell - the user agent that the webpage is likely to perform many readback operations and that it is - advantageous to use a software canvas.

- -

The CanvasRenderingContext2D object also has a color space setting of type - PredefinedColorSpace. The CanvasRenderingContext2D object's color space indicates the color space for the - output bitmap.

- -

The getContextAttributes() method - steps are to return «[ "alpha" → - this's alpha, "desynchronized" → - this's desynchronized, "colorSpace" → this's - color space, "willReadFrequently" → - this's will read frequently - ]».

-

The CanvasRenderingContext2D 2D rendering context represents a flat linear @@ -65709,6 +65631,91 @@ context.fillRect(100,0,50,50); // only this square remains or to enable double buffering so that graphics updates, like page scrolling for example, can be processed concurrently while canvas draw commands are being executed.

+
The canvas bitmap
+ +

A CanvasBitmap object has an output bitmap that + is initialized when the object is created.

+ +

The output bitmap has an origin-clean flag, which can be set to true or false. + Initially, when one of these bitmaps is created, its origin-clean flag must be set to true.

+ +

The CanvasBitmap object also has an alpha boolean. When a + CanvasBitmap object's alpha is false, then its alpha channel must be fixed to 1.0 + (fully opaque) for all pixels, and attempts to change the alpha component of any pixel must be + silently ignored.

+ +

Thus, the bitmap of such a context starts off as opaque black instead + of transparent black; clearRect() + always results in opaque black pixels, every fourth byte from getImageData() is always 255, the putImageData() method effectively ignores every + fourth byte in its input, and so on. However, the alpha component of styles and images drawn + onto the canvas are still honoured up to the point where they would impact the output + bitmap's alpha channel; for instance, drawing a 50% transparent white square on a freshly + created output bitmap with its alpha set + to false will result in a fully-opaque gray square.

+ +

The CanvasBitmap object also has a desynchronized boolean. When a + CanvasBitmap object's desynchronized is true, then the user agent may + optimize the rendering of the canvas to reduce the latency, as measured from input events to + rasterization, by desynchronizing the canvas paint cycle from the event loop, bypassing the + ordinary user agent rendering algorithm, or both. Insofar as this mode involves bypassing the + usual paint mechanisms, rasterization, or both, it might introduce visible tearing artifacts.

+ +

The user agent usually renders on a buffer which is not being displayed, quickly + swapping it and the one being scanned out for presentation; the former buffer is called + back buffer and the latter front buffer. A popular technique for reducing latency is called + front buffer rendering, also known as single buffer rendering, where rendering happens in + parallel and racily with the scanning out process. This technique reduces the latency at the price + of potentially introducing tearing artifacts and can be used to implement in total or part of the + desynchronized boolean. + MULTIPLEBUFFERING

+ +

The desynchronized boolean + can be useful when implementing certain kinds of applications, such as drawing applications, + where the latency between input and rasterization is critical.

+ +

The CanvasBitmap object also has a will read frequently boolean. When a + CanvasBitmap object's will read frequently is true, the user agent + may optimize the canvas for readback operations.

+ +

On most devices the user agent needs to decide whether to store the canvas's + output bitmap on the GPU (this is also called "hardware accelerated"), or on the CPU + (also called "software"). Most rendering operations are more performant for accelerated canvases, + with the major exception being readback with getImageData(), toDataURL(), or toBlob(). CanvasBitmap objects with + will read frequently equal to true tell + the user agent that the webpage is likely to perform many readback operations and that it is + advantageous to use a software canvas.

+ +

The CanvasBitmap object also has a color space setting of type + PredefinedColorSpace. The CanvasBitmap object's color space indicates the color space for the + output bitmap.

+ +

The getContextAttributes() method + steps are to return «[ "alpha" → + this's alpha, "desynchronized" → + this's desynchronized, "colorSpace" → this's + color space, "willReadFrequently" → + this's will read frequently + ]».

+
The canvas state

Objects that implement the CanvasState interface maintain a stack of drawing @@ -71271,9 +71278,9 @@ interface OffscreenCanvas : EventTarget {

  • If this OffscreenCanvas object's context mode is 2d and the rendering context's bitmap's origin-clean flag is set to false, then return + data-x="offscreencanvas-context-2d">2d and the rendering context's + output bitmap's origin-clean flag + is set to false, then return a promise rejected with a "SecurityError" DOMException.

    @@ -71338,7 +71345,7 @@ interface OffscreenCanvas : EventTarget { data-x="offscreencanvas-bitmap">bitmap to reference a newly created bitmap of the same dimensions and color space as the previous bitmap, and with its pixels initialized to transparent black, or opaque black if the rendering context's alpha flag is set to false.

    + data-x="concept-canvas-alpha">alpha flag is set to false.

    This means that if the rendering context of this OffscreenCanvas is a WebGLRenderingContext, the value of OffscreenCanvasRenderingContext2D { readonly attribute OffscreenCanvas canvas; }; +OffscreenCanvasRenderingContext2D includes CanvasBitmap; OffscreenCanvasRenderingContext2D includes CanvasState; OffscreenCanvasRenderingContext2D includes CanvasTransform; OffscreenCanvasRenderingContext2D includes CanvasCompositing; @@ -71398,29 +71406,6 @@ interface OffscreenCanvasRenderingContext2D { OffscreenCanvas object rather than a canvas element;

  • -

    An OffscreenCanvasRenderingContext2D object has a bitmap that is initialized when the object is - created.

    - -

    The bitmap has an origin-clean flag, which can be set to true or - false. Initially, when one of these bitmaps is created, its origin-clean flag must be set to true.

    - -

    An OffscreenCanvasRenderingContext2D object also has an alpha flag, which can be set to true or false. Initially, - when the context is created, its alpha flag must be set to true. When an - OffscreenCanvasRenderingContext2D object has its alpha flag set to false, then its alpha channel must be - fixed to 1.0 (fully opaque) for all pixels, and attempts to change the alpha component of any pixel - must be silently ignored.

    - -

    An OffscreenCanvasRenderingContext2D object also has a color space setting of type - PredefinedColorSpace. The color space for the context's bitmap is set to the context's color space.

    -

    An OffscreenCanvasRenderingContext2D object has an associated OffscreenCanvas object, which is the OffscreenCanvas object from which the OffscreenCanvasRenderingContext2D object was created. @@ -71451,23 +71436,35 @@ interface OffscreenCanvasRenderingContext2D {

  • Set context's associated OffscreenCanvas object to target.

  • -
  • If settings["alpha"] is false, then set - context's alpha flag to false.

  • - -
  • Set context's color space - to settings["colorSpace"].

  • - -
  • Set context's bitmap to a newly +

  • Set context's alpha to + settings + ["alpha"]. +

  • + +
  • Set context's desynchronized to + settings + ["desynchronized"]. +

  • + +
  • Set context's color space + to settings + ["colorSpace"]. +

  • + +
  • Set context's will read frequently to + settings + ["willReadFrequently"]. +

  • + +
  • Set context's output bitmap to a newly created bitmap with the dimensions specified by the width and height attributes of target, and set target's bitmap to the same bitmap (so that they are shared).

  • -
  • If context's alpha flag is set - to true, initialize all the pixels of context's bitmap to transparent black. Otherwise, +

  • If context's alpha flag is set + to true, initialize all the pixels of context's output bitmap to + transparent black. Otherwise, initialize the pixels to opaque black.

  • Return context.

  • @@ -71719,8 +71716,8 @@ interface OffscreenCanvasRenderingContext2D { lossy operation on colors that are not fully opaque.

    A CanvasRenderingContext2D's output bitmap and an - OffscreenCanvasRenderingContext2D's bitmap must use premultiplied alpha to represent transparent colors.

    + OffscreenCanvasRenderingContext2D's output bitmap must use + premultiplied alpha to represent transparent colors.

    It is important for canvas bitmaps to represent colors using premultiplied alpha because it affects the range of representable colors. While additive colors cannot currently be