mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Add WebGLContextAttributes support
This commit also: * Allows to return non-rootable dictionaries from Codegen. * Merges the two context types in an enum type.
This commit is contained in:
parent
b1a773a15b
commit
b3ac346749
16 changed files with 255 additions and 80 deletions
|
@ -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 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue