servo: Merge #20375 - Fall down the WebGL rabbit hole and fix some bugs there (from servo:webgl); r=emilio

Source-Repo: https://github.com/servo/servo
Source-Revision: c20d0c00d711cda61ad1b35f15f2fb563c042c5e

--HG--
extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear
extra : subtree_revision : 6e41661fca27ace97b3e6eaea9de5aeb7586bc09
This commit is contained in:
Anthony Ramine 2018-03-22 15:32:45 -04:00
Родитель bd50b6df06
Коммит a565ce6df3
6 изменённых файлов: 185 добавлений и 215 удалений

32
servo/Cargo.lock сгенерированный
Просмотреть файл

@ -269,7 +269,7 @@ dependencies = [
"cssparser 0.23.2 (registry+https://github.com/rust-lang/crates.io-index)",
"euclid 0.17.2 (registry+https://github.com/rust-lang/crates.io-index)",
"fnv 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
"gleam 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)",
"gleam 0.4.28 (registry+https://github.com/rust-lang/crates.io-index)",
"ipc-channel 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
"num-traits 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)",
@ -328,7 +328,7 @@ name = "cgl"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"gleam 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)",
"gleam 0.4.28 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.39 (registry+https://github.com/rust-lang/crates.io-index)",
]
@ -416,7 +416,7 @@ version = "0.0.1"
dependencies = [
"euclid 0.17.2 (registry+https://github.com/rust-lang/crates.io-index)",
"gfx_traits 0.0.1",
"gleam 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)",
"gleam 0.4.28 (registry+https://github.com/rust-lang/crates.io-index)",
"image 0.18.0 (registry+https://github.com/rust-lang/crates.io-index)",
"ipc-channel 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.39 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1076,7 +1076,7 @@ dependencies = [
[[package]]
name = "gleam"
version = "0.4.24"
version = "0.4.28"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"gl_generator 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1289,7 +1289,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"cgl 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"core-foundation 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
"gleam 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)",
"gleam 0.4.28 (registry+https://github.com/rust-lang/crates.io-index)",
"leaky-cow 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.39 (registry+https://github.com/rust-lang/crates.io-index)",
]
@ -1553,7 +1553,7 @@ dependencies = [
"euclid 0.17.2 (registry+https://github.com/rust-lang/crates.io-index)",
"gaol 0.0.1 (git+https://github.com/servo/gaol)",
"gfx 0.0.1",
"gleam 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)",
"gleam 0.4.28 (registry+https://github.com/rust-lang/crates.io-index)",
"ipc-channel 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)",
"layout_thread 0.0.1",
"log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1630,7 +1630,7 @@ dependencies = [
"cssparser 0.23.2 (registry+https://github.com/rust-lang/crates.io-index)",
"euclid 0.17.2 (registry+https://github.com/rust-lang/crates.io-index)",
"hashglobe 0.1.0",
"mozjs 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"mozjs 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
"selectors 0.19.0",
"servo_arc 0.1.1",
"smallbitvec 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1807,7 +1807,7 @@ dependencies = [
[[package]]
name = "mozjs"
version = "0.3.0"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"cmake 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)",
@ -2035,7 +2035,7 @@ dependencies = [
"core-foundation 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
"euclid 0.17.2 (registry+https://github.com/rust-lang/crates.io-index)",
"gl_generator 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
"gleam 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)",
"gleam 0.4.28 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"libloading 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
@ -2475,7 +2475,7 @@ dependencies = [
"encoding_rs 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
"euclid 0.17.2 (registry+https://github.com/rust-lang/crates.io-index)",
"fnv 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
"gleam 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)",
"gleam 0.4.28 (registry+https://github.com/rust-lang/crates.io-index)",
"half 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"html5ever 0.22.0 (registry+https://github.com/rust-lang/crates.io-index)",
"hyper 0.10.13 (registry+https://github.com/rust-lang/crates.io-index)",
@ -2493,7 +2493,7 @@ dependencies = [
"mime_guess 1.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
"mitochondria 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"mozangle 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
"mozjs 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"mozjs 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
"msg 0.0.1",
"net_traits 0.0.1",
"num-traits 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)",
@ -2693,7 +2693,7 @@ dependencies = [
"compositing 0.0.1",
"euclid 0.17.2 (registry+https://github.com/rust-lang/crates.io-index)",
"gdi32-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"gleam 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)",
"gleam 0.4.28 (registry+https://github.com/rust-lang/crates.io-index)",
"glutin 0.13.1 (registry+https://github.com/rust-lang/crates.io-index)",
"libservo 0.0.1",
"log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
@ -2760,7 +2760,7 @@ dependencies = [
"cmake 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)",
"euclid 0.17.2 (registry+https://github.com/rust-lang/crates.io-index)",
"expat-sys 2.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
"gleam 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)",
"gleam 0.4.28 (registry+https://github.com/rust-lang/crates.io-index)",
"glutin 0.13.1 (registry+https://github.com/rust-lang/crates.io-index)",
"glx 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
"io-surface 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -3522,7 +3522,7 @@ dependencies = [
"euclid 0.17.2 (registry+https://github.com/rust-lang/crates.io-index)",
"freetype 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"fxhash 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"gleam 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)",
"gleam 0.4.28 (registry+https://github.com/rust-lang/crates.io-index)",
"image 0.18.0 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
@ -3836,7 +3836,7 @@ dependencies = [
"checksum getopts 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)" = "d9047cfbd08a437050b363d35ef160452c5fe8ea5187ae0a624708c91581d685"
"checksum gif 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8a80d6fe9e52f637df9afd4779449a7be17c39cc9c35b01589bb833f956ba596"
"checksum gl_generator 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7a795170cbd85b5a7baa58d6d7525cae6a03e486859860c220f7ebbbdd379d0a"
"checksum gleam 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)" = "8d9997e65a2cfec0f3290a8378652e3aacdb3f19d29a7ca20c11e11ca550eec9"
"checksum gleam 0.4.28 (registry+https://github.com/rust-lang/crates.io-index)" = "0afb2d0a8283b336c9569b1dead35415f550dcf1d4f3b970b507f7373d0be626"
"checksum glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "8be18de09a56b60ed0edf84bc9df007e30040691af7acd1c41874faac5895bfb"
"checksum glutin 0.13.1 (registry+https://github.com/rust-lang/crates.io-index)" = "90de8e0391e57098acfbfe693b23065e9186255d370ebae12c933b7d77df8424"
"checksum glx 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "63a6e7c2846e12626455f45ebaff9d92161436dd0fa703d9d198012e528ca7b9"
@ -3893,7 +3893,7 @@ dependencies = [
"checksum miow 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f2f3b1cf331de6896aabf6e9d55dca90356cc9960cca7eaaf408a355ae919"
"checksum mitochondria 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9de3eca27871df31c33b807f834b94ef7d000956f57aa25c5aed9c5f0aae8f6f"
"checksum mozangle 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "1f0583e6792917f498bb3a7440f777a59353102063445ab7f5e9d1dc4ed593aa"
"checksum mozjs 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "53720714c395cbc3b8f31411ca855a97c51618c76fa5584654a0e3e2ecfc16cc"
"checksum mozjs 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "896b93aaf26a4cbdcd878b6a9e3b4b90ac018dccebaaac1fe67d2d0724f6a711"
"checksum mozjs_sys 0.50.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e61a792a125b1364c5ec50255ed8343ce02dc56098f8868dd209d472c8de006a"
"checksum mp3-metadata 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4ab5f1d2693586420208d1200ce5a51cd44726f055b635176188137aff42c7de"
"checksum mp4parse 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f821e3799bc0fd16d9b861fb02fa7ee1b5fba29f45ad591dade105c48ca9a1a0"

Просмотреть файл

@ -860,8 +860,12 @@ impl WebGLImpl {
ctx.gl().vertex_attrib_pointer_f32(attrib_id, size, normalized, stride, offset),
WebGLCommand::VertexAttribPointer(attrib_id, size, data_type, normalized, stride, offset) =>
ctx.gl().vertex_attrib_pointer(attrib_id, size, data_type, normalized, stride, offset),
WebGLCommand::Viewport(x, y, width, height) =>
ctx.gl().viewport(x, y, width, height),
WebGLCommand::GetViewport(sender) => {
sender.send(ctx.gl().get_viewport()).unwrap();
}
WebGLCommand::SetViewport(x, y, width, height) => {
ctx.gl().viewport(x, y, width, height);
}
WebGLCommand::TexImage2D(target, level, internal, width, height, format, data_type, data) =>
ctx.gl().tex_image_2d(target, level, internal, width, height,
/*border*/0, format, data_type, Some(&data)),
@ -1055,8 +1059,7 @@ impl WebGLImpl {
// Int32Array
gl::MAX_VIEWPORT_DIMS |
gl::SCISSOR_BOX |
gl::VIEWPORT => Err(WebGLError::InvalidEnum),
gl::SCISSOR_BOX => Err(WebGLError::InvalidEnum),
// Invalid parameters
_ => Err(WebGLError::InvalidEnum)

Просмотреть файл

@ -260,7 +260,8 @@ pub enum WebGLCommand {
VertexAttrib(u32, f32, f32, f32, f32),
VertexAttribPointer(u32, i32, u32, bool, i32, u32),
VertexAttribPointer2f(u32, i32, bool, i32, u32),
Viewport(i32, i32, i32, i32),
GetViewport(WebGLSender<(i32, i32, i32, i32)>),
SetViewport(i32, i32, i32, i32),
TexImage2D(u32, i32, i32, i32, i32, u32, u32, Vec<u8>),
TexParameteri(u32, u32, i32),
TexParameterf(u32, u32, f32),
@ -532,7 +533,8 @@ impl fmt::Debug for WebGLCommand {
VertexAttrib(..) => "VertexAttrib",
VertexAttribPointer2f(..) => "VertexAttribPointer2f",
VertexAttribPointer(..) => "VertexAttribPointer",
Viewport(..) => "Viewport",
GetViewport(..) => "GetViewport",
SetViewport(..) => "SetViewport",
TexImage2D(..) => "TexImage2D",
TexParameteri(..) => "TexParameteri",
TexParameterf(..) => "TexParameterf",

Просмотреть файл

@ -9,7 +9,7 @@ use dom::bindings::codegen::Bindings::WebGL2RenderingContextBinding::WebGL2Rende
use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLContextAttributes;
use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLRenderingContextMethods;
use dom::bindings::codegen::UnionTypes::ImageDataOrHTMLImageElementOrHTMLCanvasElementOrHTMLVideoElement;
use dom::bindings::error::Fallible;
use dom::bindings::error::{ErrorResult, Fallible};
use dom::bindings::reflector::{reflect_dom_object, Reflector};
use dom::bindings::root::{Dom, DomRoot, LayoutDom};
use dom::bindings::str::DOMString;
@ -329,7 +329,7 @@ impl WebGL2RenderingContextMethods for WebGL2RenderingContext {
}
/// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.9
fn CompileShader(&self, shader: Option<&WebGLShader>) {
fn CompileShader(&self, shader: &WebGLShader) {
self.base.CompileShader(shader)
}
@ -414,39 +414,39 @@ impl WebGL2RenderingContextMethods for WebGL2RenderingContext {
}
/// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10
fn GetActiveUniform(&self, program: Option<&WebGLProgram>, index: u32) -> Option<DomRoot<WebGLActiveInfo>> {
fn GetActiveUniform(&self, program: &WebGLProgram, index: u32) -> Option<DomRoot<WebGLActiveInfo>> {
self.base.GetActiveUniform(program, index)
}
/// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10
fn GetActiveAttrib(&self, program: Option<&WebGLProgram>, index: u32) -> Option<DomRoot<WebGLActiveInfo>> {
fn GetActiveAttrib(&self, program: &WebGLProgram, index: u32) -> Option<DomRoot<WebGLActiveInfo>> {
self.base.GetActiveAttrib(program, index)
}
/// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10
fn GetAttribLocation(&self, program: Option<&WebGLProgram>, name: DOMString) -> i32 {
fn GetAttribLocation(&self, program: &WebGLProgram, name: DOMString) -> i32 {
self.base.GetAttribLocation(program, name)
}
/// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.9
fn GetProgramInfoLog(&self, program: Option<&WebGLProgram>) -> Option<DOMString> {
fn GetProgramInfoLog(&self, program: &WebGLProgram) -> Option<DOMString> {
self.base.GetProgramInfoLog(program)
}
#[allow(unsafe_code)]
/// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.9
unsafe fn GetProgramParameter(&self, cx: *mut JSContext, program: Option<&WebGLProgram>, param_id: u32) -> JSVal {
unsafe fn GetProgramParameter(&self, cx: *mut JSContext, program: &WebGLProgram, param_id: u32) -> JSVal {
self.base.GetProgramParameter(cx, program, param_id)
}
/// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.9
fn GetShaderInfoLog(&self, shader: Option<&WebGLShader>) -> Option<DOMString> {
fn GetShaderInfoLog(&self, shader: &WebGLShader) -> Option<DOMString> {
self.base.GetShaderInfoLog(shader)
}
#[allow(unsafe_code)]
/// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.9
unsafe fn GetShaderParameter(&self, cx: *mut JSContext, shader: Option<&WebGLShader>, param_id: u32) -> JSVal {
unsafe fn GetShaderParameter(&self, cx: *mut JSContext, shader: &WebGLShader, param_id: u32) -> JSVal {
self.base.GetShaderParameter(cx, shader, param_id)
}
@ -459,9 +459,11 @@ impl WebGL2RenderingContextMethods for WebGL2RenderingContext {
}
/// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10
fn GetUniformLocation(&self,
program: Option<&WebGLProgram>,
name: DOMString) -> Option<DomRoot<WebGLUniformLocation>> {
fn GetUniformLocation(
&self,
program: &WebGLProgram,
name: DOMString,
) -> Option<DomRoot<WebGLUniformLocation>> {
self.base.GetUniformLocation(program, name)
}
@ -585,12 +587,12 @@ impl WebGL2RenderingContextMethods for WebGL2RenderingContext {
}
/// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.9
fn ShaderSource(&self, shader: Option<&WebGLShader>, source: DOMString) {
fn ShaderSource(&self, shader: &WebGLShader, source: DOMString) {
self.base.ShaderSource(shader, source)
}
/// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.9
fn GetShaderSource(&self, shader: Option<&WebGLShader>) -> Option<DOMString> {
fn GetShaderSource(&self, shader: &WebGLShader) -> Option<DOMString> {
self.base.GetShaderSource(shader)
}
@ -759,7 +761,7 @@ impl WebGL2RenderingContextMethods for WebGL2RenderingContext {
}
/// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.9
fn ValidateProgram(&self, program: Option<&WebGLProgram>) {
fn ValidateProgram(&self, program: &WebGLProgram) {
self.base.ValidateProgram(program)
}
@ -835,13 +837,15 @@ impl WebGL2RenderingContextMethods for WebGL2RenderingContext {
}
/// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.8
fn TexImage2D_(&self,
target: u32,
level: i32,
internal_format: u32,
format: u32,
data_type: u32,
source: Option<ImageDataOrHTMLImageElementOrHTMLCanvasElementOrHTMLVideoElement>) -> Fallible<()> {
fn TexImage2D_(
&self,
target: u32,
level: i32,
internal_format: u32,
format: u32,
data_type: u32,
source: ImageDataOrHTMLImageElementOrHTMLCanvasElementOrHTMLVideoElement,
) -> ErrorResult {
self.base.TexImage2D_(target, level, internal_format, format, data_type, source)
}
@ -875,15 +879,16 @@ impl WebGL2RenderingContextMethods for WebGL2RenderingContext {
}
/// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.8
fn TexSubImage2D_(&self,
target: u32,
level: i32,
xoffset: i32,
yoffset: i32,
format: u32,
data_type: u32,
source: Option<ImageDataOrHTMLImageElementOrHTMLCanvasElementOrHTMLVideoElement>)
-> Fallible<()> {
fn TexSubImage2D_(
&self,
target: u32,
level: i32,
xoffset: i32,
yoffset: i32,
format: u32,
data_type: u32,
source: ImageDataOrHTMLImageElementOrHTMLCanvasElementOrHTMLVideoElement,
) -> ErrorResult {
self.base.TexSubImage2D_(target, level, xoffset, yoffset, format, data_type, source)
}

Просмотреть файл

@ -16,7 +16,7 @@ use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLRenderi
use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLRenderingContextMethods;
use dom::bindings::codegen::UnionTypes::ImageDataOrHTMLImageElementOrHTMLCanvasElementOrHTMLVideoElement;
use dom::bindings::conversions::{ConversionResult, FromJSValConvertible, ToJSValConvertible};
use dom::bindings::error::{Error, Fallible};
use dom::bindings::error::{Error, ErrorResult, Fallible};
use dom::bindings::inheritance::Castable;
use dom::bindings::reflector::{DomObject, Reflector, reflect_dom_object};
use dom::bindings::root::{Dom, DomRoot, LayoutDom, MutNullableDom};
@ -471,7 +471,7 @@ impl WebGLRenderingContext {
}
fn vertex_attrib(&self, indx: u32, x: f32, y: f32, z: f32, w: f32) {
if indx > self.limits.max_vertex_attribs {
if indx >= self.limits.max_vertex_attribs {
return self.webgl_error(InvalidValue);
}
@ -763,14 +763,10 @@ impl WebGLRenderingContext {
}
}
fn get_image_pixels(&self,
source: Option<ImageDataOrHTMLImageElementOrHTMLCanvasElementOrHTMLVideoElement>)
-> ImagePixelResult {
let source = match source {
Some(s) => s,
None => return Err(()),
};
fn get_image_pixels(
&self,
source: ImageDataOrHTMLImageElementOrHTMLCanvasElementOrHTMLVideoElement,
) -> ImagePixelResult {
// NOTE: Getting the pixels probably can be short-circuited if some
// parameter is invalid.
//
@ -1273,6 +1269,9 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
match parameter {
constants::ARRAY_BUFFER_BINDING =>
return object_binding_to_js_or_null!(cx, &self.bound_buffer_array),
constants::CURRENT_PROGRAM => {
return object_binding_to_js_or_null!(cx, &self.current_program);
}
constants::ELEMENT_ARRAY_BUFFER_BINDING =>
return object_binding_to_js_or_null!(cx, &self.bound_buffer_element_array),
constants::FRAMEBUFFER_BINDING =>
@ -1306,6 +1305,14 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
return Int32Value(constants::UNSIGNED_BYTE as i32);
}
}
constants::VIEWPORT => {
let (sender, receiver) = webgl_channel().unwrap();
self.send_command(WebGLCommand::GetViewport(sender));
let (x, y, width, height) = receiver.recv().unwrap();
rooted!(in(cx) let mut rval = UndefinedValue());
[x, y, width, height].to_jsval(cx, rval.handle_mut());
return rval.get();
}
_ => {
if !self.extension_manager.is_get_parameter_name_enabled(parameter) {
self.webgl_error(WebGLError::InvalidEnum);
@ -1965,10 +1972,8 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
}
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.9
fn CompileShader(&self, shader: Option<&WebGLShader>) {
if let Some(shader) = shader {
shader.compile(self.webgl_version, self.glsl_version, &self.extension_manager)
}
fn CompileShader(&self, shader: &WebGLShader) {
shader.compile(self.webgl_version, self.glsl_version, &self.extension_manager)
}
// TODO(emilio): Probably in the future we should keep track of the
@ -2137,24 +2142,28 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
constants::POINTS | constants::LINE_STRIP |
constants::LINE_LOOP | constants::LINES |
constants::TRIANGLE_STRIP | constants::TRIANGLE_FAN |
constants::TRIANGLES => {
if self.current_program.get().is_none() {
return self.webgl_error(InvalidOperation);
}
if first < 0 || count < 0 {
return self.webgl_error(InvalidValue);
}
if !self.validate_framebuffer_complete() {
return;
}
self.send_command(WebGLCommand::DrawArrays(mode, first, count));
self.mark_as_dirty();
},
_ => self.webgl_error(InvalidEnum),
constants::TRIANGLES => {},
_ => {
return self.webgl_error(InvalidEnum);
}
}
if first < 0 || count < 0 {
return self.webgl_error(InvalidValue);
}
if self.current_program.get().is_none() {
return self.webgl_error(InvalidOperation);
}
if let Some(array_buffer) = self.bound_buffer_array.get() {
if count > 0 && (first as u64 + count as u64 > array_buffer.capacity() as u64) {
return self.webgl_error(InvalidOperation);
}
}
if !self.validate_framebuffer_complete() {
return;
}
self.send_command(WebGLCommand::DrawArrays(mode, first, count));
self.mark_as_dirty();
}
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.11
@ -2223,7 +2232,7 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10
fn EnableVertexAttribArray(&self, attrib_id: u32) {
if attrib_id > self.limits.max_vertex_attribs {
if attrib_id >= self.limits.max_vertex_attribs {
return self.webgl_error(InvalidValue);
}
@ -2232,7 +2241,7 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10
fn DisableVertexAttribArray(&self, attrib_id: u32) {
if attrib_id > self.limits.max_vertex_attribs {
if attrib_id >= self.limits.max_vertex_attribs {
return self.webgl_error(InvalidValue);
}
@ -2240,23 +2249,7 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
}
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10
fn GetActiveUniform(&self, program: Option<&WebGLProgram>, index: u32) -> Option<DomRoot<WebGLActiveInfo>> {
let program = match program {
Some(program) => program,
None => {
// Reasons to generate InvalidValue error
// From the GLES 2.0 spec
//
// "INVALID_VALUE is generated if index is greater than or equal
// to the number of active uniform variables in program"
//
// A null program has no uniforms so any index is always greater than the active uniforms
// WebGl conformance expects error with null programs. Check tests in get-active-test.html
self.webgl_error(InvalidValue);
return None;
}
};
fn GetActiveUniform(&self, program: &WebGLProgram, index: u32) -> Option<DomRoot<WebGLActiveInfo>> {
match program.get_active_uniform(index) {
Ok(ret) => Some(ret),
Err(e) => {
@ -2267,23 +2260,7 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
}
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10
fn GetActiveAttrib(&self, program: Option<&WebGLProgram>, index: u32) -> Option<DomRoot<WebGLActiveInfo>> {
let program = match program {
Some(program) => program,
None => {
// Reasons to generate InvalidValue error
// From the GLES 2.0 spec
//
// "INVALID_VALUE is generated if index is greater than or equal
// to the number of active attribute variables in program"
//
// A null program has no attributes so any index is always greater than the active uniforms
// WebGl conformance expects error with null programs. Check tests in get-active-test.html
self.webgl_error(InvalidValue);
return None;
}
};
fn GetActiveAttrib(&self, program: &WebGLProgram, index: u32) -> Option<DomRoot<WebGLActiveInfo>> {
match program.get_active_attrib(index) {
Ok(ret) => Some(ret),
Err(e) => {
@ -2294,12 +2271,8 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
}
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10
fn GetAttribLocation(&self, program: Option<&WebGLProgram>, name: DOMString) -> i32 {
if let Some(program) = program {
handle_potential_webgl_error!(self, program.get_attrib_location(name), None).unwrap_or(-1)
} else {
-1
}
fn GetAttribLocation(&self, program: &WebGLProgram, name: DOMString) -> i32 {
handle_potential_webgl_error!(self, program.get_attrib_location(name), None).unwrap_or(-1)
}
#[allow(unsafe_code)]
@ -2390,61 +2363,48 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
}
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.9
fn GetProgramInfoLog(&self, program: Option<&WebGLProgram>) -> Option<DOMString> {
if let Some(program) = program {
match program.get_info_log() {
Ok(value) => Some(DOMString::from(value)),
Err(e) => {
self.webgl_error(e);
None
}
fn GetProgramInfoLog(&self, program: &WebGLProgram) -> Option<DOMString> {
match program.get_info_log() {
Ok(value) => Some(DOMString::from(value)),
Err(e) => {
self.webgl_error(e);
None
}
} else {
self.webgl_error(WebGLError::InvalidValue);
None
}
}
#[allow(unsafe_code)]
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.9
unsafe fn GetProgramParameter(&self, _: *mut JSContext, program: Option<&WebGLProgram>, param_id: u32) -> JSVal {
if let Some(program) = program {
match handle_potential_webgl_error!(self, program.parameter(param_id), WebGLParameter::Invalid) {
WebGLParameter::Int(val) => Int32Value(val),
WebGLParameter::Bool(val) => BooleanValue(val),
WebGLParameter::String(_) => panic!("Program parameter should not be string"),
WebGLParameter::Float(_) => panic!("Program parameter should not be float"),
WebGLParameter::FloatArray(_) => {
panic!("Program paramenter should not be float array")
}
WebGLParameter::Invalid => NullValue(),
unsafe fn GetProgramParameter(&self, _: *mut JSContext, program: &WebGLProgram, param_id: u32) -> JSVal {
match handle_potential_webgl_error!(self, program.parameter(param_id), WebGLParameter::Invalid) {
WebGLParameter::Int(val) => Int32Value(val),
WebGLParameter::Bool(val) => BooleanValue(val),
WebGLParameter::String(_) => panic!("Program parameter should not be string"),
WebGLParameter::Float(_) => panic!("Program parameter should not be float"),
WebGLParameter::FloatArray(_) => {
panic!("Program paramenter should not be float array")
}
} else {
NullValue()
WebGLParameter::Invalid => NullValue(),
}
}
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.9
fn GetShaderInfoLog(&self, shader: Option<&WebGLShader>) -> Option<DOMString> {
shader.and_then(|s| s.info_log()).map(DOMString::from)
fn GetShaderInfoLog(&self, shader: &WebGLShader) -> Option<DOMString> {
shader.info_log().map(DOMString::from)
}
#[allow(unsafe_code)]
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.9
unsafe fn GetShaderParameter(&self, _: *mut JSContext, shader: Option<&WebGLShader>, param_id: u32) -> JSVal {
if let Some(shader) = shader {
match handle_potential_webgl_error!(self, shader.parameter(param_id), WebGLParameter::Invalid) {
WebGLParameter::Int(val) => Int32Value(val),
WebGLParameter::Bool(val) => BooleanValue(val),
WebGLParameter::String(_) => panic!("Shader parameter should not be string"),
WebGLParameter::Float(_) => panic!("Shader parameter should not be float"),
WebGLParameter::FloatArray(_) => {
panic!("Shader paramenter should not be float array")
}
WebGLParameter::Invalid => NullValue(),
unsafe fn GetShaderParameter(&self, _: *mut JSContext, shader: &WebGLShader, param_id: u32) -> JSVal {
match handle_potential_webgl_error!(self, shader.parameter(param_id), WebGLParameter::Invalid) {
WebGLParameter::Int(val) => Int32Value(val),
WebGLParameter::Bool(val) => BooleanValue(val),
WebGLParameter::String(_) => panic!("Shader parameter should not be string"),
WebGLParameter::Float(_) => panic!("Shader parameter should not be float"),
WebGLParameter::FloatArray(_) => {
panic!("Shader paramenter should not be float array")
}
} else {
NullValue()
WebGLParameter::Invalid => NullValue(),
}
}
@ -2477,12 +2437,13 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
}
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10
fn GetUniformLocation(&self,
program: Option<&WebGLProgram>,
name: DOMString) -> Option<DomRoot<WebGLUniformLocation>> {
program.and_then(|p| {
handle_potential_webgl_error!(self, p.get_uniform_location(name), None)
.map(|location| WebGLUniformLocation::new(self.global().as_window(), location, p.id()))
fn GetUniformLocation(
&self,
program: &WebGLProgram,
name: DOMString,
) -> Option<DomRoot<WebGLUniformLocation>> {
handle_potential_webgl_error!(self, program.get_uniform_location(name), None).map(|location| {
WebGLUniformLocation::new(self.global().as_window(), location, program.id())
})
}
@ -2859,15 +2820,13 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
}
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.9
fn ShaderSource(&self, shader: Option<&WebGLShader>, source: DOMString) {
if let Some(shader) = shader {
shader.set_source(source)
}
fn ShaderSource(&self, shader: &WebGLShader, source: DOMString) {
shader.set_source(source)
}
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.9
fn GetShaderSource(&self, shader: Option<&WebGLShader>) -> Option<DOMString> {
shader.and_then(|s| s.source())
fn GetShaderSource(&self, shader: &WebGLShader) -> Option<DOMString> {
shader.source()
}
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10
@ -3158,11 +3117,9 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
}
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.9
fn ValidateProgram(&self, program: Option<&WebGLProgram>) {
if let Some(program) = program {
if let Err(e) = program.validate() {
self.webgl_error(e);
}
fn ValidateProgram(&self, program: &WebGLProgram) {
if let Err(e) = program.validate() {
self.webgl_error(e);
}
}
@ -3238,7 +3195,7 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10
fn VertexAttribPointer(&self, attrib_id: u32, size: i32, data_type: u32,
normalized: bool, stride: i32, offset: i64) {
if attrib_id > self.limits.max_vertex_attribs {
if attrib_id >= self.limits.max_vertex_attribs {
return self.webgl_error(InvalidValue);
}
@ -3287,7 +3244,7 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
return self.webgl_error(InvalidValue)
}
self.send_command(WebGLCommand::Viewport(x, y, width, height))
self.send_command(WebGLCommand::SetViewport(x, y, width, height))
}
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.8
@ -3372,13 +3329,15 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
}
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.8
fn TexImage2D_(&self,
target: u32,
level: i32,
internal_format: u32,
format: u32,
data_type: u32,
source: Option<ImageDataOrHTMLImageElementOrHTMLCanvasElementOrHTMLVideoElement>) -> Fallible<()> {
fn TexImage2D_(
&self,
target: u32,
level: i32,
internal_format: u32,
format: u32,
data_type: u32,
source: ImageDataOrHTMLImageElementOrHTMLCanvasElementOrHTMLVideoElement,
) -> ErrorResult {
if !self.extension_manager.is_tex_type_enabled(data_type) {
return Ok(self.webgl_error(InvalidEnum));
}
@ -3533,15 +3492,16 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
}
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.8
fn TexSubImage2D_(&self,
target: u32,
level: i32,
xoffset: i32,
yoffset: i32,
format: u32,
data_type: u32,
source: Option<ImageDataOrHTMLImageElementOrHTMLCanvasElementOrHTMLVideoElement>)
-> Fallible<()> {
fn TexSubImage2D_(
&self,
target: u32,
level: i32,
xoffset: i32,
yoffset: i32,
format: u32,
data_type: u32,
source: ImageDataOrHTMLImageElementOrHTMLCanvasElementOrHTMLVideoElement,
) -> ErrorResult {
let (pixels, size, premultiplied) = match self.get_image_pixels(source) {
Ok((pixels, size, premultiplied)) => (pixels, size, premultiplied),
Err(_) => return Ok(()),

Просмотреть файл

@ -510,7 +510,7 @@ interface WebGLRenderingContextBase
void clearDepth(GLclampf depth);
void clearStencil(GLint s);
void colorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha);
void compileShader(WebGLShader? shader);
void compileShader(WebGLShader shader);
// FIXME(simartin) The Code generator doesn't handle ArrayBufferView so we're
// using 'object' in the meantime, and marking the function as Throws to
@ -578,11 +578,11 @@ interface WebGLRenderingContextBase
void generateMipmap(GLenum target);
WebGLActiveInfo? getActiveAttrib(WebGLProgram? program, GLuint index);
WebGLActiveInfo? getActiveUniform(WebGLProgram? program, GLuint index);
WebGLActiveInfo? getActiveAttrib(WebGLProgram program, GLuint index);
WebGLActiveInfo? getActiveUniform(WebGLProgram program, GLuint index);
//sequence<WebGLShader>? getAttachedShaders(WebGLProgram? program);
[WebGLHandlesContextLoss] GLint getAttribLocation(WebGLProgram? program, DOMString name);
[WebGLHandlesContextLoss] GLint getAttribLocation(WebGLProgram program, DOMString name);
any getBufferParameter(GLenum target, GLenum pname);
any getParameter(GLenum pname);
@ -591,20 +591,20 @@ interface WebGLRenderingContextBase
any getFramebufferAttachmentParameter(GLenum target, GLenum attachment,
GLenum pname);
any getProgramParameter(WebGLProgram? program, GLenum pname);
DOMString? getProgramInfoLog(WebGLProgram? program);
any getProgramParameter(WebGLProgram program, GLenum pname);
DOMString? getProgramInfoLog(WebGLProgram program);
//any getRenderbufferParameter(GLenum target, GLenum pname);
any getShaderParameter(WebGLShader? shader, GLenum pname);
any getShaderParameter(WebGLShader shader, GLenum pname);
WebGLShaderPrecisionFormat? getShaderPrecisionFormat(GLenum shadertype, GLenum precisiontype);
DOMString? getShaderInfoLog(WebGLShader? shader);
DOMString? getShaderInfoLog(WebGLShader shader);
DOMString? getShaderSource(WebGLShader? shader);
DOMString? getShaderSource(WebGLShader shader);
any getTexParameter(GLenum target, GLenum pname);
//any getUniform(WebGLProgram? program, WebGLUniformLocation? location);
//any getUniform(WebGLProgram program, WebGLUniformLocation location);
WebGLUniformLocation? getUniformLocation(WebGLProgram? program, DOMString name);
WebGLUniformLocation? getUniformLocation(WebGLProgram program, DOMString name);
any getVertexAttrib(GLuint index, GLenum pname);
@ -634,7 +634,7 @@ interface WebGLRenderingContextBase
void sampleCoverage(GLclampf value, GLboolean invert);
void scissor(GLint x, GLint y, GLsizei width, GLsizei height);
void shaderSource(WebGLShader? shader, DOMString source);
void shaderSource(WebGLShader shader, DOMString source);
void stencilFunc(GLenum func, GLint ref, GLuint mask);
void stencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask);
@ -653,7 +653,7 @@ interface WebGLRenderingContextBase
GLenum type, object? data);
[Throws]
void texImage2D(GLenum target, GLint level, GLenum internalformat,
GLenum format, GLenum type, TexImageSource? source); // May throw DOMException
GLenum format, GLenum type, TexImageSource source); // May throw DOMException
[Throws, Pref="dom.webgl.dom_to_texture.enabled"]
void texImageDOM(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height,
GLenum format, GLenum type, HTMLIFrameElement source); // May throw DOMException
@ -667,7 +667,7 @@ interface WebGLRenderingContextBase
GLenum format, GLenum type, object? data);
[Throws]
void texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset,
GLenum format, GLenum type, TexImageSource? source); // May throw DOMException
GLenum format, GLenum type, TexImageSource source); // May throw DOMException
void uniform1f(WebGLUniformLocation? location, GLfloat x);
//void uniform1fv(WebGLUniformLocation? location, Float32Array v);
@ -738,7 +738,7 @@ interface WebGLRenderingContextBase
object v);
void useProgram(WebGLProgram? program);
void validateProgram(WebGLProgram? program);
void validateProgram(WebGLProgram program);
// FIXME(dmarcos)
// The code generator doesn't handle Float32Array so we're using 'object'