aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/webglrenderingcontext.rs
diff options
context:
space:
mode:
authorecoal95 <ecoal95@gmail.com>2015-05-25 14:47:23 +0200
committerecoal95 <ecoal95@gmail.com>2015-06-01 15:29:38 +0200
commitb3ac3467494377569997126103005382793d8081 (patch)
treeeb0117a3dd980e6ff8b8657ecbab176faf229cb5 /components/script/dom/webglrenderingcontext.rs
parentb1a773a15bd2e022aa45c3672e51467e994badfe (diff)
downloadservo-b3ac3467494377569997126103005382793d8081.tar.gz
servo-b3ac3467494377569997126103005382793d8081.zip
Add WebGLContextAttributes support
This commit also: * Allows to return non-rootable dictionaries from Codegen. * Merges the two context types in an enum type.
Diffstat (limited to 'components/script/dom/webglrenderingcontext.rs')
-rw-r--r--components/script/dom/webglrenderingcontext.rs36
1 files changed, 31 insertions, 5 deletions
diff --git a/components/script/dom/webglrenderingcontext.rs b/components/script/dom/webglrenderingcontext.rs
index ee64fe73de0..462c3859d17 100644
--- a/components/script/dom/webglrenderingcontext.rs
+++ b/components/script/dom/webglrenderingcontext.rs
@@ -6,7 +6,7 @@ use canvas::webgl_paint_task::WebGLPaintTask;
use canvas_traits::{CanvasMsg, CanvasWebGLMsg, CanvasCommonMsg};
use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding;
use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::{
- WebGLRenderingContextMethods, WebGLRenderingContextConstants};
+ WebGLContextAttributes, WebGLRenderingContextMethods, WebGLRenderingContextConstants};
use dom::bindings::global::{GlobalRef, GlobalField};
use dom::bindings::js::{JS, JSRef, LayoutJS, Temporary};
use dom::bindings::utils::{Reflector, reflect_dom_object};
@@ -23,6 +23,7 @@ use std::mem;
use std::ptr;
use std::sync::mpsc::{channel, Sender};
use util::str::DOMString;
+use offscreen_gl_context::GLContextAttributes;
#[dom_struct]
pub struct WebGLRenderingContext {
@@ -33,9 +34,12 @@ pub struct WebGLRenderingContext {
}
impl WebGLRenderingContext {
- fn new_inherited(global: GlobalRef, canvas: JSRef<HTMLCanvasElement>, size: Size2D<i32>)
+ fn new_inherited(global: GlobalRef,
+ canvas: JSRef<HTMLCanvasElement>,
+ size: Size2D<i32>,
+ attrs: GLContextAttributes)
-> Result<WebGLRenderingContext, &'static str> {
- let chan = try!(WebGLPaintTask::start(size));
+ let chan = try!(WebGLPaintTask::start(size, attrs));
Ok(WebGLRenderingContext {
reflector_: Reflector::new(),
@@ -45,9 +49,9 @@ impl WebGLRenderingContext {
})
}
- pub fn new(global: GlobalRef, canvas: JSRef<HTMLCanvasElement>, size: Size2D<i32>)
+ pub fn new(global: GlobalRef, canvas: JSRef<HTMLCanvasElement>, size: Size2D<i32>, attrs: GLContextAttributes)
-> Option<Temporary<WebGLRenderingContext>> {
- match WebGLRenderingContext::new_inherited(global, canvas, size) {
+ match WebGLRenderingContext::new_inherited(global, canvas, size, attrs) {
Ok(ctx) => Some(reflect_dom_object(box ctx, global,
WebGLRenderingContextBinding::Wrap)),
Err(msg) => {
@@ -69,6 +73,28 @@ impl Drop for WebGLRenderingContext {
}
impl<'a> WebGLRenderingContextMethods for JSRef<'a, WebGLRenderingContext> {
+ // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.2
+ fn GetContextAttributes(self) -> Option<WebGLContextAttributes> {
+ let (sender, receiver) = channel();
+
+ // If the send does not succeed, assume context lost
+ if let Err(_) = self.renderer.send(CanvasMsg::WebGL(CanvasWebGLMsg::GetContextAttributes(sender))) {
+ return None;
+ }
+ let attrs = receiver.recv().unwrap();
+
+ Some(WebGLContextAttributes {
+ alpha: attrs.alpha,
+ antialias: attrs.antialias,
+ depth: attrs.depth,
+ failIfMajorPerformanceCaveat: false,
+ preferLowPowerToHighPerformance: false,
+ premultipliedAlpha: attrs.premultiplied_alpha,
+ preserveDrawingBuffer: attrs.preserve_drawing_buffer,
+ stencil: attrs.stencil
+ })
+ }
+
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.9
fn AttachShader(self, program: Option<JSRef<WebGLProgram>>, shader: Option<JSRef<WebGLShader>>) {
let program_id = match program {