1# `Source/modules/canvas`
2
3Contains canvas-related subdirectories.
4
5## Class structure of Canvas-related objects
6
7The classes on this structure are divided between all subdirectories that are
8used by canvas:
9
101. `htmlcanvas`
11
12   Contains context creation for HTML canvas element
13
142. `canvas2d`
15
16   Contains base class for 2D rendering contexts and `CanvasRenderingContext2D` related classes.
17
183. `offscreencanvas`
19
20   Contains offscreencanvas object.
21
224. `offscreencanvas2d`
23
24   Contains offscreencanvas 2D rendering context.
25
265. `imagebitmap`
27
28   Contains ImageBitmap rendering context.
29
30Canvas-related classes are also present in these directories in `core`:
31`core/html/canvas` and `core/html`.
32
33There are also some other directories in `modules` that are a bit related to
34canvas: `modules/webgl`, `modules/imagebitmap` and `modules/csspaint`.
35
36### Virtual classes
37
38`CanvasRenderingContextHost` : All elements that provides rendering contexts
39(`HTMLCanvasElement` and `OffscreenCanvas`) This is the main interface that a
40`CanvasRenderingContext` uses.
41
42`CanvasRenderingContext` - Base class for everything that exposes a rendering
43context API. This includes `2d`, `webgl`, `webgl2`, `imagebitmap` contexts.
44
45`BaseRenderingContext2D` - Class for `2D` canvas contexts. Implements most 2D
46rendering context API. Used by `CanvasRenderingContext2D`,
47`OffscreenCanvasRenderingContext2D` and `PaintRenderingContext2D`.
48
49`WebGLRenderingContextBase` - Base class for `webgl` contexts.
50
51### Final classes
52
53`CanvasRenderingContext2D` - 2D context for HTML Canvas element. [[spec](https://html.spec.whatwg.org/C/#2dcontext)]
54
55`OffscreenCanvasRenderingContext2D` - 2D context for OffscreenCanvas.
56[[spec](https://html.spec.whatwg.org/C/#the-offscreen-2d-rendering-context)]
57
58`WebGLRenderingContext` - WebGL context for both HTML and Offscreen canvas.
59[[spec](https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14)]
60
61`WebGL2RenderingContext` - WebGL2 context for both HTML and Offscreen canvas.
62[[spec](https://www.khronos.org/registry/webgl/specs/latest/2.0/#3.7)]
63
64`ImageBitmapRenderingContext` - The rendering context provided by `ImageBitmap`.
65[[spec](https://html.spec.whatwg.org/C/#the-imagebitmap-rendering-context)]
66
67`PaintRenderingContext2D` - Rendering context for CSS Painting.
68[[spec](https://www.w3.org/TR/css-paint-api-1/)]
69