Make WebGLRenderingContext::new take a &GlobalScope

This commit is contained in:
Anthony Ramine 2016-10-01 21:23:41 +02:00
parent 20bacbf42e
commit 22252605af
2 changed files with 7 additions and 9 deletions

View file

@ -12,7 +12,6 @@ use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLContext
use dom::bindings::codegen::UnionTypes::CanvasRenderingContext2DOrWebGLRenderingContext; use dom::bindings::codegen::UnionTypes::CanvasRenderingContext2DOrWebGLRenderingContext;
use dom::bindings::conversions::ConversionResult; use dom::bindings::conversions::ConversionResult;
use dom::bindings::error::{Error, Fallible}; use dom::bindings::error::{Error, Fallible};
use dom::bindings::global::GlobalRef;
use dom::bindings::inheritance::Castable; use dom::bindings::inheritance::Castable;
use dom::bindings::js::{HeapGCValue, JS, LayoutJS, Root}; use dom::bindings::js::{HeapGCValue, JS, LayoutJS, Root};
use dom::bindings::num::Finite; use dom::bindings::num::Finite;
@ -178,7 +177,7 @@ impl HTMLCanvasElement {
GLContextAttributes::default() GLContextAttributes::default()
}; };
let maybe_ctx = WebGLRenderingContext::new(GlobalRef::Window(window.r()), self, size, attrs); let maybe_ctx = WebGLRenderingContext::new(window.upcast(), self, size, attrs);
*self.context.borrow_mut() = maybe_ctx.map( |ctx| CanvasContext::WebGL(JS::from_ref(&*ctx))); *self.context.borrow_mut() = maybe_ctx.map( |ctx| CanvasContext::WebGL(JS::from_ref(&*ctx)));
} }

View file

@ -10,12 +10,12 @@ use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLRenderi
use dom::bindings::codegen::UnionTypes::ImageDataOrHTMLImageElementOrHTMLCanvasElementOrHTMLVideoElement; use dom::bindings::codegen::UnionTypes::ImageDataOrHTMLImageElementOrHTMLCanvasElementOrHTMLVideoElement;
use dom::bindings::conversions::{ToJSValConvertible, array_buffer_view_data, array_buffer_view_data_checked}; use dom::bindings::conversions::{ToJSValConvertible, array_buffer_view_data, array_buffer_view_data_checked};
use dom::bindings::conversions::{array_buffer_view_to_vec, array_buffer_view_to_vec_checked}; use dom::bindings::conversions::{array_buffer_view_to_vec, array_buffer_view_to_vec_checked};
use dom::bindings::global::GlobalRef;
use dom::bindings::inheritance::Castable; use dom::bindings::inheritance::Castable;
use dom::bindings::js::{JS, LayoutJS, MutNullableHeap, Root}; use dom::bindings::js::{JS, LayoutJS, MutNullableHeap, Root};
use dom::bindings::reflector::{Reflectable, Reflector, reflect_dom_object}; use dom::bindings::reflector::{Reflectable, Reflector, reflect_dom_object};
use dom::bindings::str::DOMString; use dom::bindings::str::DOMString;
use dom::event::{Event, EventBubbles, EventCancelable}; use dom::event::{Event, EventBubbles, EventCancelable};
use dom::globalscope::GlobalScope;
use dom::htmlcanvaselement::HTMLCanvasElement; use dom::htmlcanvaselement::HTMLCanvasElement;
use dom::htmlcanvaselement::utils as canvas_utils; use dom::htmlcanvaselement::utils as canvas_utils;
use dom::node::{Node, NodeDamage, window_from_node}; use dom::node::{Node, NodeDamage, window_from_node};
@ -127,13 +127,13 @@ pub struct WebGLRenderingContext {
} }
impl WebGLRenderingContext { impl WebGLRenderingContext {
fn new_inherited(global: GlobalRef, fn new_inherited(global: &GlobalScope,
canvas: &HTMLCanvasElement, canvas: &HTMLCanvasElement,
size: Size2D<i32>, size: Size2D<i32>,
attrs: GLContextAttributes) attrs: GLContextAttributes)
-> Result<WebGLRenderingContext, String> { -> Result<WebGLRenderingContext, String> {
let (sender, receiver) = ipc::channel().unwrap(); let (sender, receiver) = ipc::channel().unwrap();
let constellation_chan = global.as_global_scope().constellation_chan(); let constellation_chan = global.constellation_chan();
constellation_chan.send(ConstellationMsg::CreateWebGLPaintThread(size, attrs, sender)) constellation_chan.send(ConstellationMsg::CreateWebGLPaintThread(size, attrs, sender))
.unwrap(); .unwrap();
let result = receiver.recv().unwrap(); let result = receiver.recv().unwrap();
@ -159,14 +159,13 @@ impl WebGLRenderingContext {
} }
#[allow(unrooted_must_root)] #[allow(unrooted_must_root)]
pub fn new(global: GlobalRef, canvas: &HTMLCanvasElement, size: Size2D<i32>, attrs: GLContextAttributes) pub fn new(global: &GlobalScope, canvas: &HTMLCanvasElement, size: Size2D<i32>, attrs: GLContextAttributes)
-> Option<Root<WebGLRenderingContext>> { -> Option<Root<WebGLRenderingContext>> {
match WebGLRenderingContext::new_inherited(global, canvas, size, attrs) { match WebGLRenderingContext::new_inherited(global, canvas, size, attrs) {
Ok(ctx) => Some(reflect_dom_object(box ctx, global.as_global_scope(), Ok(ctx) => Some(reflect_dom_object(box ctx, global, WebGLRenderingContextBinding::Wrap)),
WebGLRenderingContextBinding::Wrap)),
Err(msg) => { Err(msg) => {
error!("Couldn't create WebGLRenderingContext: {}", msg); error!("Couldn't create WebGLRenderingContext: {}", msg);
let event = WebGLContextEvent::new(global.as_global_scope(), let event = WebGLContextEvent::new(global,
atom!("webglcontextcreationerror"), atom!("webglcontextcreationerror"),
EventBubbles::DoesNotBubble, EventBubbles::DoesNotBubble,
EventCancelable::Cancelable, EventCancelable::Cancelable,