CSC/ECE 517 Fall 2017/M1753 OffscreenCanvas API: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 57: Line 57:
== '''References''' ==
== '''References''' ==


1. https://html.spec.whatwg.org/multipage/canvas.html#the-offscreen-2d-rendering-context
1. https://html.spec.whatwg.org/multipage/canvas.html#the-offscreen-2d-rendering-context<br>
2. https://html.spec.whatwg.org/multipage/structured-data.html#transferable
2. https://html.spec.whatwg.org/multipage/structured-data.html#transferable<br>
3. https://html.spec.whatwg.org/multipage/canvas.html#the-offscreencanvas-interface
3. https://html.spec.whatwg.org/multipage/canvas.html#the-offscreencanvas-interface<br>
4. https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Using_web_workers
4. https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Using_web_workers<br>
5. https://developer.mozilla.org/en-US/docs/Web/API/Comment
5. https://developer.mozilla.org/en-US/docs/Web/API/Comment<br>
6. https://developer.mozilla.org/en-US/docs/Web/API/Comment/Comment
6. https://developer.mozilla.org/en-US/docs/Web/API/Comment/Comment<br>
7. https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/getContext
7. https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/getContext<br>
8. https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D
8. https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D<br>
9. http://doc.servo.org/script/dom/index.html#adding-a-new-dom-interface
9. http://doc.servo.org/script/dom/index.html#adding-a-new-dom-interface<br>

Revision as of 00:37, 27 October 2017

The HTML specification defines a <canvas> element that use a 2D or 3D rendering context and draw graphics. The biggest limitation of <canvas> is that all of the javascript that manipulates the <canvas> has to run on the main thread, as the applications we build increase in complexity, developers inadvertently hit the performance wall. A new specification was recently developed that defines a canvas that can be used without being associated with an in-page canvas element, allowing for more efficient rendering. The OffscreenCanvas API achieves pre-rendering that using a separate off-screen canvas to render temporary image, and then rendering the off-screen canvas back to the main thread.[1][2]

Background Introduction

Servo[3] is a modern web browser engine designed to maximize the benefits of multi-core-based parallel processing. Parallelism is undoubtedly the highlight feature of the servo, besides other characteristics like GPU rendering, embedding, modularity and memory safety are also stressed. Written in the Rust language, servo was aimed for the application on Android and ARM processors, but now its applicable scope has expanded to Linux, Mac OS X, Windows, Android and Firefox OS (also known as Gonk) and other operating systems[4].


Rust[5] is a programming language that emphasizes security, concurrency and speed. The three keywords, safety, control of memory layout, and concurrency are the core features of rust, and also the primary factors that distinguish rust from other programming languages. Rust performs most of its memory management and security checks at compile time, which makes it possible to predict the time and space requirements of the program and be embedded into low-level code , such as device driver and operating system.Rust is developed on GitHub/Git [6], and every commit to the source code is documented by the version control system.


The OffscreenCanvas API supports a canvas to be rendered off screen. The performance of a webpage can be limited by using <canvas> since all of the javascript that manipulates the <canvas> has to run on the main thread, situation is not optimistic when the canvas operations are complex. The OffscreenCanvas API provides a way to interact with the same canvas APIs but in a different thread. This allows rendering to progress no matter what is going on in the main thread [7].

Project Description

Implement the OffscreenCanvas API: Servo has an implementation of the HTML Canvas API. Our project is to implement the OffscreenCanvas API which provides a canvas that can be rendered off screen and is available in both the window and worker contexts.


Steps

  • Create the OffscreenCanvas and OffscreenCanvasRenderingContext2d interfaces.
  • Hide the new interfaces by default
  • Enable the existing automated tests for this feature
  • Implement the OffscreenCanvas constructor that creates a new canvas
  • Implement the OffscreenCanvas.getContext ignoring the WebGL requirements

Implementation

Create Interfaces

Create the OffscreenCanvas and OffscreenCanvasRenderingContext2d interfaces with stub method implementations.

  To add the interfaces, the following steps are to be followed: 
   * adding the new IDL file at components/script/dom/webidls/Foo.webidl;
   * creating components/script/dom/foo.rs;
   * listing foo.rs in components/script/dom/mod.rs;  
   * defining the DOM struct Foo with a #[dom_struct] attribute, a superclass or Reflector member, and other members as appropriate;
   * implementing the dom::bindings::codegen::Bindings::FooBindings::FooMethods trait for Foo;
   * adding/updating the match arm in create_element in components/script/dom/create.rs (only applicable to new types inheriting from HTMLElement)
  Hide newly created interfaces by default:
   * Add corresponding attribute to the interface file as well as resources/prefs.json
  Enable Tests:
   * Add 'offscreen-canvas' directory to tests folder.
   * Enable test preference for offscreen-canvas by adding '__dir__.ini' file to the newly created directory.
   * Run tests and change expected results.
  Implement OffscreenCanvas Constructor: 
    Syntax: 
      var offscreen = new OffscreenCanvas(256, 256);
   
  Implement the getContext() method for OffscreenCanvas element. 
    Syntax: 
       canvas.getContext(contextType, contextAttributes); 

Testing Details

Pull Request

Future Work

References

1. https://html.spec.whatwg.org/multipage/canvas.html#the-offscreen-2d-rendering-context
2. https://html.spec.whatwg.org/multipage/structured-data.html#transferable
3. https://html.spec.whatwg.org/multipage/canvas.html#the-offscreencanvas-interface
4. https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Using_web_workers
5. https://developer.mozilla.org/en-US/docs/Web/API/Comment
6. https://developer.mozilla.org/en-US/docs/Web/API/Comment/Comment
7. https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/getContext
8. https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D
9. http://doc.servo.org/script/dom/index.html#adding-a-new-dom-interface