diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2018-03-20 19:58:58 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-03-20 19:58:58 -0400 |
commit | f92f0809f89593d4b70eb0f507f6ca4409c9ed91 (patch) | |
tree | af37bf22b48e220d745252d6ee61770dbefb11ba /components/script/dom/webglrenderingcontext.rs | |
parent | 730bd5ec807fec0ed65bbf85afebe3bbca64b32c (diff) | |
parent | bdd53f35af0da13ea4a94cd5780cabeaa84d6477 (diff) | |
download | servo-f92f0809f89593d4b70eb0f507f6ca4409c9ed91.tar.gz servo-f92f0809f89593d4b70eb0f507f6ca4409c9ed91.zip |
Auto merge of #20369 - gootorov:move-validation, r=emilio
Move WebGL validation
This moves validation from `canvas/webgl_thread` to `dom/webglrenderingcontext` for consistency and speed and simplifies it where it is possible.
---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [ ] These changes fix #__ (github issue number if applicable).
<!-- Either: -->
- [ ] There are tests for these changes OR
- [x] These changes do not require tests because: refactoring
<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->
<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/20369)
<!-- Reviewable:end -->
Diffstat (limited to 'components/script/dom/webglrenderingcontext.rs')
-rw-r--r-- | components/script/dom/webglrenderingcontext.rs | 109 |
1 files changed, 66 insertions, 43 deletions
diff --git a/components/script/dom/webglrenderingcontext.rs b/components/script/dom/webglrenderingcontext.rs index 0145d84ffd8..64990da1504 100644 --- a/components/script/dom/webglrenderingcontext.rs +++ b/components/script/dom/webglrenderingcontext.rs @@ -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 |