Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OffscreenCanvas API #22495

Merged
merged 1 commit into from Jan 16, 2019
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
The table of contents is too big for display.

Always

Just for now

Initial Steps OffScreenCanvas API

  • Loading branch information
maharsh312 authored and jdm committed Jan 16, 2019
commit 0f17273276d7b3585fde5ca0e3888fafd250905a
@@ -407,6 +407,8 @@ pub mod nodeiterator;
pub mod nodelist;
pub mod offlineaudiocompletionevent;
pub mod offlineaudiocontext;
pub mod offscreencanvas;
pub mod offscreencanvasrenderingcontext2d;
pub mod oscillatornode;
pub mod pagetransitionevent;
pub mod paintrenderingcontext2d;
@@ -0,0 +1,146 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

use crate::dom::bindings::cell::DomRefCell;
use crate::dom::bindings::codegen::Bindings::OffscreenCanvasBinding::{
OffscreenCanvasMethods, OffscreenRenderingContext, Wrap as OffscreenCanvasWrap,
};
use crate::dom::bindings::error::Fallible;
use crate::dom::bindings::reflector::reflect_dom_object;
use crate::dom::bindings::reflector::DomObject;
use crate::dom::bindings::root::{Dom, DomRoot};
use crate::dom::bindings::str::DOMString;
use crate::dom::eventtarget::EventTarget;
use crate::dom::globalscope::GlobalScope;
use crate::dom::htmlcanvaselement::HTMLCanvasElement;
use crate::dom::offscreencanvasrenderingcontext2d::OffscreenCanvasRenderingContext2D;
use dom_struct::dom_struct;
use euclid::Size2D;
use js::jsapi::JSContext;
use js::rust::HandleValue;
use ref_filter_map;
use std::cell::Cell;
use std::cell::Ref;

#[must_root]
#[derive(Clone, JSTraceable, MallocSizeOf)]
pub enum OffscreenCanvasContext {
OffscreenContext2d(Dom<OffscreenCanvasRenderingContext2D>),
//WebGL(Dom<WebGLRenderingContext>),
//WebGL2(Dom<WebGL2RenderingContext>),
}

#[dom_struct]
pub struct OffscreenCanvas {
eventtarget: EventTarget,
height: Cell<u64>,
width: Cell<u64>,
context: DomRefCell<Option<OffscreenCanvasContext>>,
placeholder: Option<Dom<HTMLCanvasElement>>,
}

impl OffscreenCanvas {
pub fn new_inherited(
height: u64,
width: u64,
placeholder: Option<&HTMLCanvasElement>,
) -> OffscreenCanvas {
OffscreenCanvas {
eventtarget: EventTarget::new_inherited(),
height: Cell::new(height),
width: Cell::new(width),
context: DomRefCell::new(None),
placeholder: placeholder.map(Dom::from_ref),
}
}

pub fn new(
global: &GlobalScope,
height: u64,
width: u64,
placeholder: Option<&HTMLCanvasElement>,
) -> DomRoot<OffscreenCanvas> {
reflect_dom_object(
Box::new(OffscreenCanvas::new_inherited(height, width, placeholder)),
global,
OffscreenCanvasWrap,
)
}

pub fn Constructor(
global: &GlobalScope,
height: u64,
width: u64,
) -> Fallible<DomRoot<OffscreenCanvas>> {
let offscreencanvas = OffscreenCanvas::new(global, height, width, None);
Ok(offscreencanvas)
}

pub fn get_size(&self) -> Size2D<u64> {
Size2D::new(self.Width(), self.Height())
}

pub fn context(&self) -> Option<Ref<OffscreenCanvasContext>> {
ref_filter_map::ref_filter_map(self.context.borrow(), |ctx| ctx.as_ref())
}

#[allow(unsafe_code)]
fn get_or_init_2d_context(&self) -> Option<DomRoot<OffscreenCanvasRenderingContext2D>> {
if let Some(ctx) = self.context() {
return match *ctx {
OffscreenCanvasContext::OffscreenContext2d(ref ctx) => Some(DomRoot::from_ref(ctx)),
};
}
let size = self.get_size();
let context = OffscreenCanvasRenderingContext2D::new(&self.global(), self, size);
*self.context.borrow_mut() = Some(OffscreenCanvasContext::OffscreenContext2d(
Dom::from_ref(&*context),
));
Some(context)
}
}

impl OffscreenCanvasMethods for OffscreenCanvas {
// https://html.spec.whatwg.org/multipage/#dom-offscreencanvas-getcontext
#[allow(unsafe_code)]
unsafe fn GetContext(
&self,
_cx: *mut JSContext,
id: DOMString,
_options: HandleValue,
) -> Option<OffscreenRenderingContext> {
match &*id {
"2d" => self
.get_or_init_2d_context()
.map(OffscreenRenderingContext::OffscreenCanvasRenderingContext2D),
/*"webgl" | "experimental-webgl" => self
.get_or_init_webgl_context(cx, options)
.map(OffscreenRenderingContext::WebGLRenderingContext),
"webgl2" | "experimental-webgl2" => self
.get_or_init_webgl2_context(cx, options)
.map(OffscreenRenderingContext::WebGL2RenderingContext),*/
_ => None,
}
}

// https://html.spec.whatwg.org/multipage/#dom-offscreencanvas-width
fn Width(&self) -> u64 {
return self.width.get();
}

// https://html.spec.whatwg.org/multipage/#dom-offscreencanvas-width
fn SetWidth(&self, value: u64) {
self.width.set(value);
}

// https://html.spec.whatwg.org/multipage/#dom-offscreencanvas-height
fn Height(&self) -> u64 {
return self.height.get();
}

// https://html.spec.whatwg.org/multipage/#dom-offscreencanvas-height
fn SetHeight(&self, value: u64) {
self.height.set(value);
}
}
@@ -0,0 +1,55 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

use crate::dom::bindings::codegen::Bindings::OffscreenCanvasRenderingContext2DBinding;
use crate::dom::bindings::codegen::Bindings::OffscreenCanvasRenderingContext2DBinding::OffscreenCanvasRenderingContext2DMethods;
use crate::dom::bindings::reflector::{reflect_dom_object, Reflector};
use crate::dom::bindings::root::{Dom, DomRoot};
use crate::dom::globalscope::GlobalScope;
use crate::dom::offscreencanvas::OffscreenCanvas;
use dom_struct::dom_struct;
use euclid::Size2D;

#[dom_struct]
pub struct OffscreenCanvasRenderingContext2D {
reflector_: Reflector,
canvas: Option<Dom<OffscreenCanvas>>,
}

impl OffscreenCanvasRenderingContext2D {
pub fn new_inherited(
_global: &GlobalScope,
canvas: Option<&OffscreenCanvas>,
_size: Size2D<u64>,
) -> OffscreenCanvasRenderingContext2D {
OffscreenCanvasRenderingContext2D {
reflector_: Reflector::new(),
canvas: canvas.map(Dom::from_ref),
}
}

pub fn new(
_global: &GlobalScope,
canvas: &OffscreenCanvas,
_size: Size2D<u64>,
) -> DomRoot<OffscreenCanvasRenderingContext2D> {
let boxed = Box::new(OffscreenCanvasRenderingContext2D::new_inherited(
_global,
Some(canvas),
_size,
));
reflect_dom_object(
boxed,
_global,
OffscreenCanvasRenderingContext2DBinding::Wrap,
)
}
}

impl OffscreenCanvasRenderingContext2DMethods for OffscreenCanvasRenderingContext2D {
// https://html.spec.whatwg.org/multipage/offscreencontext2d-canvas
fn Canvas(&self) -> DomRoot<OffscreenCanvas> {
DomRoot::from_ref(self.canvas.as_ref().expect("No canvas."))
}
}
@@ -0,0 +1,25 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

// https://html.spec.whatwg.org/multipage/#the-offscreencanvas-interface
typedef (OffscreenCanvasRenderingContext2D or WebGLRenderingContext or WebGL2RenderingContext)
OffscreenRenderingContext;

dictionary ImageEncodeOptions {
DOMString type = "image/png";
unrestricted double quality = 1.0;
};

//enum OffscreenRenderingContextId { "2d", "webgl", "webgl2" };

[Constructor([EnforceRange] unsigned long long width, [EnforceRange] unsigned long long height),
Exposed=(Window,Worker)/*, Transferable*/, Pref="dom.offscreen_canvas.enabled"]
interface OffscreenCanvas : EventTarget {
attribute /*[EnforceRange]*/ unsigned long long width;
attribute /*[EnforceRange]*/ unsigned long long height;

OffscreenRenderingContext? getContext(DOMString contextId, optional any options = null);
//ImageBitmap transferToImageBitmap();
//Promise<Blob> convertToBlob(optional ImageEncodeOptions options);
};
@@ -0,0 +1,26 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

// https://html.spec.whatwg.org/multipage/#the-offscreen-2d-rendering-context
[Exposed=(Window,Worker), Pref="dom.offscreen_canvas.enabled"]
interface OffscreenCanvasRenderingContext2D {
//void commit();
readonly attribute OffscreenCanvas canvas;
};

//OffscreenCanvasRenderingContext2D includes CanvasState;
//OffscreenCanvasRenderingContext2D includes CanvasTransform;
//OffscreenCanvasRenderingContext2D includes CanvasCompositing;
//OffscreenCanvasRenderingContext2D includes CanvasImageSmoothing;
//OffscreenCanvasRenderingContext2D includes CanvasFillStrokeStyles;
//OffscreenCanvasRenderingContext2D includes CanvasShadowStyles;
//OffscreenCanvasRenderingContext2D includes CanvasFilters;
//OffscreenCanvasRenderingContext2D includes CanvasRect;
//OffscreenCanvasRenderingContext2D includes CanvasDrawPath;
//OffscreenCanvasRenderingContext2D includes CanvasText;
//OffscreenCanvasRenderingContext2D includes CanvasDrawImage;
//OffscreenCanvasRenderingContext2D includes CanvasImageData;
//OffscreenCanvasRenderingContext2D includes CanvasPathDrawingStyles;
//OffscreenCanvasRenderingContext2D includes CanvasTextDrawingStyles;
//OffscreenCanvasRenderingContext2D includes CanvasPath;
@@ -9,6 +9,7 @@
"dom.microdata.testing.enabled": true,
"dom.mouseevent.which.enabled": false,
"dom.mutation_observer.enabled": true,
"dom.offscreen_canvas.enabled": false,
"dom.permissions.enabled": false,
"dom.permissions.testing.allowed_in_nonsecure_contexts": false,
"dom.serviceworker.timeout_seconds": 60,
@@ -97,6 +97,8 @@ skip: true
skip: false
[navigation-timing]
skip: false
[offscreen-canvas]
skip: false
[old-tests]
skip: true
[submission]

This file was deleted.

@@ -1,2 +1,2 @@
[abspos-float-with-inline-container.html]
expected: FAIL
expected: TIMEOUT
@@ -0,0 +1,2 @@
[white-space-002.xht]
expected: FAIL
@@ -0,0 +1,2 @@
[line-height-204.html]
expected: FAIL
@@ -0,0 +1,2 @@
[mix-blend-mode-paragraph.html]
expected: FAIL
@@ -0,0 +1,2 @@
[background-repeat-round-roundup.xht]
expected: FAIL
@@ -182,9 +182,6 @@
[Matching font-style: 'oblique 20deg' should prefer 'oblique 40deg 50deg' over 'oblique 10deg']
expected: FAIL

[Matching font-style: 'oblique 20deg' should prefer 'oblique 10deg' over 'italic']
expected: FAIL

[Matching font-style: 'oblique 20deg' should prefer 'oblique 0deg' over 'oblique -50deg -20deg']
expected: FAIL

@@ -248,9 +245,6 @@
[Matching font-style: 'oblique 21deg' should prefer 'oblique 21deg' over 'oblique 30deg 60deg']
expected: FAIL

[Matching font-style: 'oblique 21deg' should prefer 'oblique 40deg 50deg' over 'oblique 20deg']
expected: FAIL

[Matching font-style: 'oblique -10deg' should prefer 'oblique -5deg' over 'oblique -1deg 0deg']
expected: FAIL

@@ -5,9 +5,6 @@
[Test @font-face matching for weight 470]
expected: FAIL

[Test @font-face matching for weight 500]
expected: FAIL

[Test @font-face matching for weight 600]
expected: FAIL

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

@@ -0,0 +1,2 @@
[word-break-keep-all-006.html]
expected: FAIL
@@ -74,3 +74,6 @@
[opacity end]
expected: FAIL

[border-top-width end]
expected: FAIL

@@ -1,2 +1,2 @@
[parser-sets-attributes-and-children.html]
expected: TIMEOUT
expected: CRASH
@@ -55,7 +55,7 @@
expected: FAIL

[windows-1252: iso_8859-1:1987 (XMLHttpRequest)]
expected: TIMEOUT
expected: FAIL

[windows-1254: iso_8859-9:1989 (XMLHttpRequest)]
expected: TIMEOUT
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.