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 #22168
Closed
PrayaniSingh0106
wants to merge
13
commits into
servo:master
from
PrayaniSingh0106:OffscreenCanvasAPI
+231
−1
Closed
OffscreenCanvas API #22168
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
03a45c5
added prefrences for OffscreenCanvas
maharsh312 893ae3b
Added webidl file for OffscreenCanvas
Chiaggs 2e37c91
New .webidl file added
PrayaniSingh0106 e81319d
Merge branch 'master' of https://github.com/PrayaniSingh0106/servo
Chiaggs 447cac6
Merge pull request #1 from PrayaniSingh0106/ServoOSS
PrayaniSingh0106 5e865b8
Merge branch 'master' of https://github.com/PrayaniSingh0106/servo
Chiaggs fd57e91
Offscreen canvas
PrayaniSingh0106 b7d443e
Merge branch 'master' into ServoOSS
PrayaniSingh0106 84e9bd2
Merge pull request #2 from PrayaniSingh0106/ServoOSS
PrayaniSingh0106 6efbc8d
added offscreencanvas
maharsh312 555af4f
added a file
Chiaggs a51bb61
Fixed few errors following Josh's review
PrayaniSingh0106 595b537
Merge pull request #5 from PrayaniSingh0106/master
PrayaniSingh0106 File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.
| @@ -0,0 +1,147 @@ | ||
| /* 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::{OffscreenCanvasMethods, Wrap as OffscreenCanvasWrap}; | ||
| use dom::bindings::codegen::Bindings::OffscreenCanvasBinding; | ||
| use dom::bindings::codegen::UnionTypes; | ||
| use dom::bindings::error::{Error, Fallible}; | ||
| use dom::bindings::reflector::{DomObject, Reflector, reflect_dom_object}; | ||
| use std::ptr; | ||
| use dom::bindings::root::{DomRoot, Dom}; | ||
| use std::cell::Ref; | ||
| use dom::bindings::str::DOMString; | ||
| use dom::globalscope::GlobalScope; | ||
| use dom::htmlcanvaselement::{CanvasContext, HTMLCanvasElement}; | ||
| use dom_struct::dom_struct; | ||
| use dom::bindings::cell::DomRefCell; | ||
| use ref_filter_map; | ||
| use dom::offscreencanvasrenderingcontext2d::OffscreenCanvasRenderingContext2D; | ||
| use dom::webglrenderingcontext::WebGLRenderingContext; | ||
| use dom::webgl2renderingcontext::WebGL2RenderingContext; | ||
| use js::rust::HandleValue; | ||
| use js::jsapi::JSContext; | ||
| use dom::bindings::trace::RootedTraceableBox; | ||
| use dom::node::{Node, window_from_node}; | ||
| use dom::bindings::codegen::UnionTypes::OffscreenCanvasRenderingContext2DOrWebGLRenderingContextOrWebGL2RenderingContext; | ||
| use dom::eventtarget::EventTarget; | ||
|
|
||
| #[derive(JSTraceable, MallocSizeOf)] | ||
| pub enum OffscreenRenderingContext { | ||
| Context2D(Dom<OffscreenCanvasRenderingContext2D>), | ||
| WebGL(Dom<WebGLRenderingContext>), | ||
| WebGL2(Dom<WebGL2RenderingContext>), | ||
| } | ||
|
|
||
| #[dom_struct] | ||
| pub struct OffscreenCanvas{ | ||
| eventtarget: EventTarget, | ||
| height: u64, | ||
| width: u64, | ||
| context: DomRefCell<Option<OffscreenRenderingContext>>, | ||
| placeholder: Option<Dom<HTMLCanvasElement>>, | ||
| } | ||
|
|
||
| impl OffscreenCanvas{ | ||
| pub fn new_inherited(height: u64, width: u64, placeholder: Option<&HTMLCanvasElement>) -> OffscreenCanvas { | ||
| OffscreenCanvas { | ||
| eventtarget: EventTarget::new_inherited(), | ||
| height: height, | ||
| width: 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>> { | ||
| //step 1 | ||
| let offscreencanvas = OffscreenCanvas::new(global,height,width,None); | ||
| //step 2 | ||
| if offscreencanvas.context.borrow().is_some() { | ||
| return Err(Error::InvalidState); | ||
| } | ||
|
|
||
| offscreencanvas.height = height; | ||
| offscreencanvas.width = width; | ||
|
|
||
| offscreencanvas.placeholder = None; | ||
|
|
||
| //step 3 | ||
| Ok(offscreencanvas) | ||
| } | ||
|
|
||
| pub fn context(&self) -> Option<Ref<OffscreenRenderingContext>> { | ||
| ref_filter_map::ref_filter_map(self.context.borrow(), |ctx| ctx.as_ref()) | ||
| } | ||
|
|
||
| fn get_or_init_2d_context(&self) -> Option<DomRoot<OffscreenCanvasRenderingContext2D>> { | ||
| if let Some(ctx) = self.context() { | ||
| return match *ctx { | ||
| OffscreenRenderingContext::Context2D(ref ctx) => Some(DomRoot::from_ref(ctx)), | ||
| _ => None, | ||
| }; | ||
| } | ||
| //let window = window_from_node(self); | ||
| //let size = self.get_size(); | ||
| let context = OffscreenCanvasRenderingContext2D::new(self); | ||
| *self.context.borrow_mut() = Some(OffscreenRenderingContext::Context2D(Dom::from_ref(&*context))); | ||
| Some(context) | ||
| } | ||
|
|
||
| } | ||
|
|
||
|
|
||
| impl OffscreenCanvasMethods for OffscreenCanvas{ | ||
| #[allow(unsafe_code)] | ||
| unsafe fn GetContext(&self,cx: *mut JSContext, contextID: DOMString, options: HandleValue) -> Option<OffscreenCanvasRenderingContext2DOrWebGLRenderingContextOrWebGL2RenderingContext> { | ||
|
|
||
| //let options = | ||
| /*if !options.is_object() { | ||
| options = HandleValue::null(); | ||
| }*/ | ||
|
|
||
|
|
||
|
|
||
|
|
||
| if contextID == "2d" | ||
| { | ||
| self.get_or_init_2d_context(); | ||
| } | ||
|
|
||
|
|
||
| /* match &*contextID { | ||
| "2d" => self.get_or_init_2d_context(), | ||
| "webgl" | "experimental-webgl" => self | ||
| .map(CanvasRenderingContext::WebGLRenderingContext), | ||
| "webgl2" | "experimental-webgl2" => self | ||
| .map(CanvasRenderingContext::WebGL2RenderingContext) | ||
| _ => None, | ||
| } */ | ||
|
|
||
| } | ||
|
|
||
|
|
||
|
|
||
| fn Width(&self) -> u64 { | ||
| return self.width; | ||
| } | ||
| fn SetWidth(&self, value: u64) -> () { | ||
| self.width = value; | ||
| } | ||
| fn Height(&self) -> u64 { | ||
| return self.height; | ||
| } | ||
| fn SetHeight(&self, value: u64) -> () { | ||
| self.height = value; | ||
| } | ||
| } |
| @@ -0,0 +1,31 @@ | ||
| /* 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_struct::dom_struct; | ||
| use dom::bindings::codegen::Bindings::OffscreenCanvasRenderingContext2DBinding; | ||
| use dom::bindings::codegen::Bindings::OffscreenCanvasRenderingContext2DBinding::{Wrap as OffscreenCanvasRenderingContext2DWrap}; | ||
| use dom::offscreencanvas::{OffscreenRenderingContext,OffscreenCanvas}; | ||
| use dom::bindings::root::DomRoot; | ||
| use dom::globalscope::GlobalScope; | ||
| use dom::bindings::reflector::{DomObject, Reflector, reflect_dom_object}; | ||
| use dom::bindings::root::Dom; | ||
|
|
||
| #[dom_struct] | ||
| pub struct OffscreenCanvasRenderingContext2D{ | ||
| reflector_: Reflector, | ||
| canvas: Option<Dom<OffscreenCanvas>>, | ||
| } | ||
|
|
||
| impl OffscreenCanvasRenderingContext2D { | ||
| pub fn new_inherited(canvas: Option<&OffscreenCanvas>) -> OffscreenCanvasRenderingContext2D { | ||
| OffscreenCanvasRenderingContext2D { | ||
| reflector_: Reflector::new(), | ||
| canvas: canvas.map(Dom::from_ref), | ||
| } | ||
| } | ||
|
|
||
| pub fn new(canvas: Option<&OffscreenCanvas>) -> DomRoot<OffscreenCanvasRenderingContext2D> { | ||
| reflect_dom_object(Box::new(OffscreenCanvasRenderingContext2D::new_inherited(canvas)), OffscreenCanvasRenderingContext2DWrap) | ||
| } | ||
| } |
| @@ -0,0 +1,28 @@ | ||
| /* 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/. */ | ||
|
|
||
|
|
||
|
|
||
| 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,21 @@ | ||
| [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; | ||
ProTip!
Use n and p to navigate between commits in a pull request.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
TravisCI doesn't like that this file is named
OffscreenCanvasRenderingContext2d.webidl, while the interface is namedOffscreenCanvasRenderingContext2D. The filename should match the interface name (ie.2D, not2d).