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

Conflicts resolved in conflicting files. OffscreenCanvas ready to be merged. #19067

Closed
wants to merge 11 commits into from
Next

Fixed changes made in 'just commiting' commit

New interfaces added and stub methods implemented for OffscreenCanvas API

OffscreenCanvas implementaion - 25 bugs removed towards a successful build.

OffscreenCanvas API Implemented with stub methods, build successful

Conflicts removed from master, OffscreenCanvas changes ready for merge

Revert "Conflicts removed from master, OffscreenCanvas changes ready for merge"
Will rebase branch and resolve conflicts.
This reverts commit 7357f2e.

Changes reverted in conflicting files. OffscreenCanvas API ready to be merged.
  • Loading branch information
Gauraang Khurana authored and gauraangkhurana committed Nov 8, 2017
commit 6867786f32e2387921d202885a2a3ffc434a6baa
@@ -78,6 +78,7 @@ use dom::htmlulistelement::HTMLUListElement;
use dom::htmlunknownelement::HTMLUnknownElement;
use dom::htmlvideoelement::HTMLVideoElement;
use dom::svgsvgelement::SVGSVGElement;
use dom::offscreencanvas::OffscreenCanvas;
use html5ever::{LocalName, Prefix, QualName};
use js::jsapi::JSAutoCompartment;
use script_thread::ScriptThread;
@@ -41,6 +41,7 @@ use dom::htmlanchorelement::HTMLAnchorElement;
use dom::htmlbodyelement::{HTMLBodyElement, HTMLBodyElementLayoutHelpers};
use dom::htmlbuttonelement::HTMLButtonElement;
use dom::htmlcanvaselement::{HTMLCanvasElement, LayoutHTMLCanvasElementHelpers};
use dom::offscreencanvas::{OffscreenCanvas, LayoutOffscreenCanvasHelpers};
use dom::htmlcollection::HTMLCollection;
use dom::htmlelement::HTMLElement;
use dom::htmlfieldsetelement::HTMLFieldSetElement;
@@ -392,6 +392,8 @@ pub mod navigatorinfo;
pub mod node;
pub mod nodeiterator;
pub mod nodelist;
pub mod offscreencanvas;
pub mod offscreencanvasrenderingcontext2d;
pub mod pagetransitionevent;
pub mod paintrenderingcontext2d;
pub mod paintsize;
@@ -0,0 +1,156 @@
/* 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 dom::bindings::codegen::Bindings::OffscreenCanvasBinding;
use dom::bindings::error::{Error, Fallible, report_pending_exception};
use dom::bindings::codegen::Bindings::OffscreenCanvasBinding::OffscreenCanvasMethods;
use dom::webglrenderingcontext::{LayoutCanvasWebGLRenderingContextHelpers, WebGLRenderingContext};
use dom::offscreencanvasrenderingcontext2d::{OffscreenCanvasRenderingContext2D, LayoutOffscreenCanvasRenderingContext2DHelpers};
use dom::htmlelement::HTMLElement;
use dom::globalscope::GlobalScope;
use dom::element::{Element, RawLayoutElementHelpers};
use dom::bindings::cell::DomRefCell;
use dom::bindings::reflector::{Reflector, reflect_dom_object};
use dom::bindings::root::{Dom, DomRoot, LayoutDom};
use dom::bindings::inheritance::Castable;
use script_layout_interface::{HTMLCanvasData, HTMLCanvasDataSource};
use dom::node::{Node, window_from_node};
use html5ever::{LocalName, Prefix};
use dom::bindings::root::Root;
use dom::document::Document;
use style::attr::{AttrValue, LengthOrPercentageOrAuto};


use dom_struct::dom_struct;

const DEFAULT_WIDTH: u32 = 300;
const DEFAULT_HEIGHT: u32 = 150;

#[must_root]
#[derive(Clone, JSTraceable, MallocSizeOf)]
pub enum CanvasContext {
Context2d(Dom<OffscreenCanvasRenderingContext2D>),
WebGL(Dom<WebGLRenderingContext>),
}

pub trait LayoutOffscreenCanvasHelpers {
fn data(&self) -> HTMLCanvasData;
// fn get_width(&self) -> LengthOrPercentageOrAuto;
// fn get_height(&self) -> LengthOrPercentageOrAuto;

}

#[dom_struct]
pub struct OffscreenCanvas {
htmlelement: HTMLElement,

This comment has been minimized.

Copy link
@jdm

jdm Nov 7, 2017

Member

This should be reflector_: Reflector instead, since an OffscreenCanvas is not an HTML element.

context: DomRefCell<Option<CanvasContext>>,
}

impl OffscreenCanvas {

fn new_inherited(local_name: LocalName,
prefix: Option<Prefix>,

This comment has been minimized.

Copy link
@jdm

jdm Nov 7, 2017

Member

local_name and prefix are not needed for OffscreenCanvas.

document: &Document) -> OffscreenCanvas {
OffscreenCanvas {
htmlelement: HTMLElement::new_inherited(local_name, prefix, document),
context: DomRefCell::new(None),
}
}


pub fn Constructor(global : &GlobalScope, width: u64,
height: u64) -> Result<DomRoot<OffscreenCanvas>, Error> {

unimplemented!()

This comment has been minimized.

Copy link
@jdm

jdm Nov 7, 2017

Member

This method should return a new instance of OffscreenCanvas that is set up according to https://html.spec.whatwg.org/multipage/canvas.html#dom-offscreencanvas .

This comment has been minimized.

Copy link
@jaga4494

jaga4494 Nov 9, 2017

Is it something like below:
pub fn Constructor(global : &GlobalScope, width: u64,
height: u64) -> Result<DomRoot, Error> {
let context = match canvas.get_or_init_2d_context() {
Some(context) => context,
None => return Err(Error::InvalidState),
};
Ok(OffscreenCanvas::new(global, x, y, width, height))
}

This comment has been minimized.

Copy link
@jdm

jdm Nov 9, 2017

Member

Yes, except:

  • that code desn't use context (so no need for it)
  • where are x and y coming from? what are they for?

This comment has been minimized.

Copy link
@jaga4494

jaga4494 Nov 9, 2017

Ohh, yeah. so first we need to set the attributes (width and height) to the OffscreenCanvas object and then pass a single parameter -"global" to the fn new that looks like:

Ok(OffscreenCanvas::new(global))

This comment has been minimized.

Copy link
@jdm

jdm Nov 9, 2017

Member

No; OffscreenCanvas::new is the method that invokes OffscreenCanvas::new_inherited, which is the method that actually creates an instance of OffscreenCanvas. Traditionally we pass in to new_inherited the initial values that can be controlled by arguments to the constructor.


}

}

impl OffscreenCanvasMethods for OffscreenCanvas {
fn Width(&self) -> u64 {
let width: u64 = 300;
width
}
fn SetHeight(&self, height : u64) -> (){

}
fn SetWidth(&self, width : u64) -> () {

}
fn Height(&self) -> u64 {
let height: u64 = 300;
height
}

// #[allow(unsafe_code)]
// https://html.spec.whatwg.org/multipage/#dom-offscreencanvas-getcontext
/* unsafe fn GetContext(&self,
cx: *mut JSContext,
id: DOMString,
attributes: Vec<HandleValue>)
-> Option<CanvasRenderingContext2DOrWebGLRenderingContext> {
match &*id {
"2d" => {
self.get_or_init_2d_context()
.map(CanvasRenderingContext2DOrWebGLRenderingContext::CanvasRenderingContext2D)
}
"webgl" => {
self.get_or_init_webgl_context(cx, attributes.get(0).cloned())
.map(CanvasRenderingContext2DOrWebGLRenderingContext::WebGLRenderingContext)
}
_ => None
}
}
*/
}

impl LayoutOffscreenCanvasHelpers for LayoutDom<OffscreenCanvas> {
#[allow(unsafe_code)]
fn data(&self) -> HTMLCanvasData {
unsafe {
let canvas = &*self.unsafe_get();
let source = match canvas.context.borrow_for_layout().as_ref() {
Some(&CanvasContext::Context2d(ref context)) => {
HTMLCanvasDataSource::Image(Some(context.to_layout().get_ipc_renderer()))
},
Some(&CanvasContext::WebGL(ref context)) => {
context.to_layout().canvas_data_source()
},
None => {
HTMLCanvasDataSource::Image(None)
}
};

// let width_attr = canvas.upcast::<Element>().get_attr_for_layout(&ns!(), &local_name!("width"));
// let height_attr = canvas.upcast::<Element>().get_attr_for_layout(&ns!(), &local_name!("height"));
HTMLCanvasData {
source: source,
width: DEFAULT_WIDTH,
height: DEFAULT_HEIGHT,
}
}
}

// #[allow(unsafe_code)]
/*fn get_width(&self) -> LengthOrPercentageOrAuto {
unsafe {
(&*self.upcast::<Element>().unsafe_get())
.get_attr_for_layout(&ns!(), &local_name!("width"))
.map(AttrValue::as_uint_px_dimension)
.unwrap_or(LengthOrPercentageOrAuto::Auto)
}
}*/
/*
#[allow(unsafe_code)]
fn get_height(&self) -> LengthOrPercentageOrAuto {
unsafe {
(&*self.upcast::<Element>().unsafe_get())
.get_attr_for_layout(&ns!(), &local_name!("height"))
.map(AttrValue::as_uint_px_dimension)
.unwrap_or(LengthOrPercentageOrAuto::Auto)
}
} */
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.