aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/webglrenderingcontext.rs
diff options
context:
space:
mode:
authorbors-servo <metajack+bors@gmail.com>2015-06-01 08:37:48 -0500
committerbors-servo <metajack+bors@gmail.com>2015-06-01 08:37:48 -0500
commit0de09b936e5e37c15b7865157a98ad78b1077659 (patch)
treedff9058ec210d968aae1031632dede080456db88 /components/script/dom/webglrenderingcontext.rs
parent2a8d5952892e050a3d604741dd1007e3bd563315 (diff)
parentb3ac3467494377569997126103005382793d8081 (diff)
downloadservo-0de09b936e5e37c15b7865157a98ad78b1077659.tar.gz
servo-0de09b936e5e37c15b7865157a98ad78b1077659.zip
Auto merge of #6183 - ecoal95:webglcontextattributes, r=nox
r? @jdm I couldn't add the `getContextAttributes` method since `CodegenRust` doesn't know how to return a dictionary value, I'll take a look at it ASAP. I think the helper functions can return directly the renderer, since they're used just for that, but I wanted to hear your opinions about this. By the way I'm interested in adding more serious tests for WebGL, and I think the [khronos conformance suit](https://github.com/KhronosGroup/WebGL/tree/master/conformance-suites/1.0.3) should be the best option. Should I try to integrate it in wpt, or making a `tests/webgl` directory (or similar) inside the servo tree? (Maybe this question should be for @Ms2ger) <!-- Reviewable:start --> [<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/6183) <!-- Reviewable:end -->
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 {