Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move WebGL validation #20369

Merged
merged 4 commits into from Mar 21, 2018
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

@@ -1066,21 +1066,8 @@ impl WebGLImpl {
fn get_tex_parameter(gl: &gl::Gl,
target: u32,
pname: u32,
chan: WebGLSender<WebGLResult<WebGLParameter>> ) {
let result = match pname {
gl::TEXTURE_MAG_FILTER |
gl::TEXTURE_MIN_FILTER |
gl::TEXTURE_WRAP_S |
gl::TEXTURE_WRAP_T => {
let parameter = gl.get_tex_parameter_iv(target, pname);
if parameter == 0 {

This comment has been minimized.

@gootorov

gootorov Mar 20, 2018

Author Contributor

Note: I didn't find in the spec that it shouldn't be 0. Can we double check that?

This comment has been minimized.

@emilio

emilio Mar 20, 2018

Member

Can you file a separate issue for this? Let's keep this PR for the refactor I'd say, that makes it more straight-forward to land :)

This comment has been minimized.

@gootorov

gootorov Mar 20, 2018

Author Contributor

Sure!

Ok(WebGLParameter::Invalid)
} else {
Ok(WebGLParameter::Int(parameter))
}
}
_ => Err(WebGLError::InvalidEnum)
};
chan: WebGLSender<i32> ) {
let result = gl.get_tex_parameter_iv(target, pname);
chan.send(result).unwrap();
}

@@ -1117,25 +1104,16 @@ impl WebGLImpl {
fn vertex_attrib_offset(gl: &gl::Gl,
index: u32,
pname: u32,
chan: WebGLSender<WebGLResult<isize>>) {
let result = match pname {
gl::VERTEX_ATTRIB_ARRAY_POINTER => Ok(gl.get_vertex_attrib_pointer_v(index, pname)),
_ => Err(WebGLError::InvalidEnum),
};

chan: WebGLSender<isize>) {
let result = gl.get_vertex_attrib_pointer_v(index, pname);
chan.send(result).unwrap();
}

fn buffer_parameter(gl: &gl::Gl,
target: u32,
param_id: u32,
chan: WebGLSender<WebGLResult<WebGLParameter>>) {
let result = match param_id {
gl::BUFFER_SIZE |
gl::BUFFER_USAGE =>
Ok(WebGLParameter::Int(gl.get_buffer_parameter_iv(target, param_id))),
_ => Err(WebGLError::InvalidEnum),
};
chan: WebGLSender<i32>) {
let result = gl.get_buffer_parameter_iv(target, param_id);

chan.send(result).unwrap();
}
@@ -1178,21 +1156,8 @@ impl WebGLImpl {
fn shader_precision_format(gl: &gl::Gl,
shader_type: u32,
precision_type: u32,
chan: WebGLSender<WebGLResult<(i32, i32, i32)>>) {
let result = match precision_type {
gl::LOW_FLOAT |
gl::MEDIUM_FLOAT |
gl::HIGH_FLOAT |
gl::LOW_INT |
gl::MEDIUM_INT |
gl::HIGH_INT => {
Ok(gl.get_shader_precision_format(shader_type, precision_type))
},
_=> {
Err(WebGLError::InvalidEnum)
}
};

chan: WebGLSender<(i32, i32, i32)>) {
let result = gl.get_shader_precision_format(shader_type, precision_type);
chan.send(result).unwrap();
}

@@ -204,19 +204,19 @@ pub enum WebGLCommand {
EnableVertexAttribArray(u32),
FramebufferRenderbuffer(u32, u32, u32, Option<WebGLRenderbufferId>),
FramebufferTexture2D(u32, u32, u32, Option<WebGLTextureId>, i32),
GetBufferParameter(u32, u32, WebGLSender<WebGLResult<WebGLParameter>>),
GetBufferParameter(u32, u32, WebGLSender<i32>),
GetExtensions(WebGLSender<String>),
GetParameter(u32, WebGLSender<WebGLResult<WebGLParameter>>),
GetTexParameter(u32, u32, WebGLSender<WebGLResult<WebGLParameter>>),
GetTexParameter(u32, u32, WebGLSender<i32>),
GetProgramParameter(WebGLProgramId, u32, WebGLSender<WebGLResult<WebGLParameter>>),
GetShaderParameter(WebGLShaderId, u32, WebGLSender<WebGLResult<WebGLParameter>>),
GetShaderPrecisionFormat(u32, u32, WebGLSender<WebGLResult<(i32, i32, i32)>>),
GetShaderPrecisionFormat(u32, u32, WebGLSender<(i32, i32, i32)>),
GetActiveAttrib(WebGLProgramId, u32, WebGLSender<WebGLResult<(i32, u32, String)>>),
GetActiveUniform(WebGLProgramId, u32, WebGLSender<WebGLResult<(i32, u32, String)>>),
GetAttribLocation(WebGLProgramId, String, WebGLSender<Option<i32>>),
GetUniformLocation(WebGLProgramId, String, WebGLSender<Option<i32>>),
GetVertexAttrib(u32, u32, WebGLSender<WebGLResult<WebGLParameter>>),
GetVertexAttribOffset(u32, u32, WebGLSender<WebGLResult<isize>>),
GetVertexAttribOffset(u32, u32, WebGLSender<isize>),
GetShaderInfoLog(WebGLShaderId, WebGLSender<String>),
GetProgramInfoLog(WebGLProgramId, WebGLSender<String>),
PolygonOffset(f32, f32),
@@ -1246,17 +1246,21 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
#[allow(unsafe_code)]
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.5
unsafe fn GetBufferParameter(&self, _cx: *mut JSContext, target: u32, parameter: u32) -> JSVal {
let parameter_matches = match parameter {
constants::BUFFER_SIZE |
constants::BUFFER_USAGE => true,
_ => false,
};

if !parameter_matches {
self.webgl_error(InvalidEnum);
return NullValue();
}

let (sender, receiver) = webgl_channel().unwrap();
self.send_command(WebGLCommand::GetBufferParameter(target, parameter, sender));

match handle_potential_webgl_error!(self, receiver.recv().unwrap(), WebGLParameter::Invalid) {
WebGLParameter::Int(val) => Int32Value(val),
WebGLParameter::Bool(_) => panic!("Buffer parameter should not be bool"),
WebGLParameter::Float(_) => panic!("Buffer parameter should not be float"),
WebGLParameter::FloatArray(_) => panic!("Buffer parameter should not be float array"),
WebGLParameter::String(_) => panic!("Buffer parameter should not be string"),
WebGLParameter::Invalid => NullValue(),
}
Int32Value(receiver.recv().unwrap())
}

#[allow(unsafe_code)]
@@ -1342,31 +1346,39 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
#[allow(unsafe_code)]
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.8
unsafe fn GetTexParameter(&self, _cx: *mut JSContext, target: u32, pname: u32) -> JSVal {
let texture = match target {
let target_matches = match target {
constants::TEXTURE_2D |
constants::TEXTURE_CUBE_MAP => self.bound_texture(target),
constants::TEXTURE_CUBE_MAP => true,
_ => false,
};

let pname_matches = match pname {
constants::TEXTURE_MAG_FILTER |
constants::TEXTURE_MIN_FILTER |
constants::TEXTURE_WRAP_S |
constants::TEXTURE_WRAP_T => true,
_ => false,
};

if !target_matches || !pname_matches {
self.webgl_error(InvalidEnum);
return NullValue();
}

if self.bound_texture(target).is_none() {
self.webgl_error(InvalidOperation);
return NullValue();
}

let (sender, receiver) = webgl_channel().unwrap();
self.send_command(WebGLCommand::GetTexParameter(target, pname, sender));

match receiver.recv().unwrap() {
value if value != 0 => Int32Value(value),
_ => {
self.webgl_error(InvalidEnum);
return NullValue();
}
};
if texture.is_some() {
let (sender, receiver) = webgl_channel().unwrap();
self.send_command(WebGLCommand::GetTexParameter(target, pname, sender));
match handle_potential_webgl_error!(self, receiver.recv().unwrap(), WebGLParameter::Invalid) {
WebGLParameter::Int(val) => Int32Value(val),
WebGLParameter::Bool(_) => panic!("Texture parameter should not be bool"),
WebGLParameter::Float(_) => panic!("Texture parameter should not be float"),
WebGLParameter::FloatArray(_) => panic!("Texture parameter should not be float array"),
WebGLParameter::String(_) => panic!("Texture parameter should not be string"),
WebGLParameter::Invalid => {
self.webgl_error(InvalidEnum);
NullValue()
}
NullValue()
}
} else {
self.webgl_error(InvalidOperation);
NullValue()
}
}

@@ -2345,24 +2357,31 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
}

// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.9
fn GetShaderPrecisionFormat(&self,
shader_type: u32,
precision_type: u32)
-> Option<DomRoot<WebGLShaderPrecisionFormat>> {
fn GetShaderPrecisionFormat(
&self,
shader_type: u32,
precision_type: u32
) -> Option<DomRoot<WebGLShaderPrecisionFormat>> {
match precision_type {
constants::LOW_FLOAT |
constants::MEDIUM_FLOAT |
constants::HIGH_FLOAT |
constants::LOW_INT |
constants::MEDIUM_INT |
constants::HIGH_INT => (),
_ => {
self.webgl_error(InvalidEnum);
return None;
},
}

let (sender, receiver) = webgl_channel().unwrap();
self.send_command(WebGLCommand::GetShaderPrecisionFormat(shader_type,
precision_type,
sender));

match receiver.recv().unwrap() {
Ok((range_min, range_max, precision)) => {
Some(WebGLShaderPrecisionFormat::new(self.global().as_window(), range_min, range_max, precision))
},
Err(error) => {
self.webgl_error(error);
None
}
}
let (range_min, range_max, precision) = receiver.recv().unwrap();
Some(WebGLShaderPrecisionFormat::new(self.global().as_window(), range_min, range_max, precision))
}

// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10
@@ -2413,10 +2432,14 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {

// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10
fn GetVertexAttribOffset(&self, index: u32, pname: u32) -> i64 {
if pname != constants::VERTEX_ATTRIB_ARRAY_POINTER {
self.webgl_error(InvalidEnum);
return 0;
}
let (sender, receiver) = webgl_channel().unwrap();
self.send_command(WebGLCommand::GetVertexAttribOffset(index, pname, sender));

handle_potential_webgl_error!(self, receiver.recv().unwrap(), 0) as i64
receiver.recv().unwrap() as i64
}

// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.3
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.