[whatwg] Splitting CanvasRenderingContext2D

Hi whatwg,

(public-houdini@w3.org cc'd)

For the CSS Paint API[1] work in Houdini we would like to split up the
current CanvasRenderingContext2D to remove references to the DOM and pixel
readback.

Additionally OffscreenCanvas[2] needs a similar reduced subset of the
CanvasRenderingContext2D api (remove references to the DOM on Workers).

There are a couple of ways to split up the CanvasRenderingContext2D API,
namely adding inheritance + [NoInterfaceObject] to superclasses (as to not
change prototype chain, maybe not a large web compat concern), or to create
additional interfaces and get *RenderingContext2D to implement.

The following gist has a "split into interfaces" version:
https://gist.github.com/bfgeek/72c2b26c2ccc8f728daf [see below for TL;DR
version]

Thoughts on this as a PR to the HTML spec?
If so any preferences for how this is done?

Additionally, if this is too premature to add to the HTML spec people have
suggested moving this to the WICG.

Thanks,
Ian

[1] https://drafts.css-houdini.org/css-paint-api/
[2] https://wiki.whatwg.org/wiki/OffscreenCanvas

TL;DR version (could be made more granular):
interface CanvasRenderingContext2D {

  // back-reference to the canvas
  readonly attribute HTMLCanvasElement canvas;

  void drawFocusIfNeeded(Element element);

  // hit regions
  void addHitRegion(HitRegionOptions options);
  void removeHitRegion(DOMString id);
  void clearHitRegions();
};
CanvasRenderingContext2D implements CanvasDrawingStyles;
CanvasRenderingContext2D implements CanvasImageDataMethods;
CanvasRenderingContext2D implements CanvasMethods;
CanvasRenderingContext2D implements CanvasPathMethods;

// TODO bikeshed name.
interface OffscreenCanvasRenderingContext2D {
};
OffscreenCanvasRenderingContext2D implements CanvasDrawingStyles;
OffscreenCanvasRenderingContext2D implements CanvasImageDataMethods;
OffscreenCanvasRenderingContext2D implements CanvasMethods;
OffscreenCanvasRenderingContext2D implements CanvasPathMethods;

// TODO bikeshed name (would go in CSS Paint API spec).
interface HoudiniCanvasRenderingContext2D {
};
HoudiniCanvasRenderingContext2D implements CanvasDrawingStyles;
HoudiniCanvasRenderingContext2D implements CanvasMethods;
HoudiniCanvasRenderingContext2D implements CanvasPathMethods;

[NoInterfaceObject]
interface CanvasImageDataMethods {
  ImageData createImageData(unrestricted double sw, unrestricted double sh);
  ImageData createImageData(ImageData imagedata);
  ImageData getImageData(double sx, double sy, double sw, double sh); //
NOTE arguably only getImageData should be here.
  void putImageData(ImageData imagedata, double dx, double dy);
  void putImageData(ImageData imagedata, double dx, double dy, double
dirtyX, double dirtyY, double dirtyWidth, double dirtyHeight);
};

// "write-only" methods should go here, i.e. no methods which would force a
raster.
[NoInterfaceObject]
interface CanvasMethods {
  // etc;
};

Received on Monday, 30 November 2015 23:40:45 UTC