diff options
author | ioctaptceb <yulia.startsev@gmail.com> | 2017-01-08 13:39:49 +0100 |
---|---|---|
committer | ioctaptceb <yulia.startsev@gmail.com> | 2017-01-11 20:59:03 +0100 |
commit | f3d65505e9344541007a908e80ca23f34561ffba (patch) | |
tree | 99cba6ee3dd9f1482a2db0ade6afdcddbebde62b /components/script/dom | |
parent | d1bc1a4f1b66ab9f63fa37f649eaf79035e12f8e (diff) | |
download | servo-f3d65505e9344541007a908e80ca23f34561ffba.tar.gz servo-f3d65505e9344541007a908e80ca23f34561ffba.zip |
Add a check to BlendFunc for invalid constant
combinations
Diffstat (limited to 'components/script/dom')
-rw-r--r-- | components/script/dom/webglrenderingcontext.rs | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/components/script/dom/webglrenderingcontext.rs b/components/script/dom/webglrenderingcontext.rs index 92771d6ef53..5d61d5c483e 100644 --- a/components/script/dom/webglrenderingcontext.rs +++ b/components/script/dom/webglrenderingcontext.rs @@ -103,6 +103,15 @@ macro_rules! object_binding_to_js_or_null { }; } +fn has_invalid_blend_constants(arg1: u32, arg2: u32) -> bool { + match (arg1, arg2) { + (constants::CONSTANT_COLOR, constants::CONSTANT_ALPHA) => true, + (constants::ONE_MINUS_CONSTANT_COLOR, constants::ONE_MINUS_CONSTANT_ALPHA) => true, + (constants::ONE_MINUS_CONSTANT_COLOR, constants::CONSTANT_ALPHA) => true, + (constants::CONSTANT_COLOR, constants::ONE_MINUS_CONSTANT_ALPHA) => true, + (_, _) => false + } +} /// Set of bitflags for texture unpacking (texImage2d, etc...) bitflags! { #[derive(HeapSizeOf, JSTraceable)] @@ -808,6 +817,18 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext { // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.3 fn BlendFunc(&self, src_factor: u32, dest_factor: u32) { + // From the WebGL 1.0 spec, 6.13: Viewport Depth Range: + // + // A call to blendFunc will generate an INVALID_OPERATION error if one of the two + // factors is set to CONSTANT_COLOR or ONE_MINUS_CONSTANT_COLOR and the other to + // CONSTANT_ALPHA or ONE_MINUS_CONSTANT_ALPHA. + if has_invalid_blend_constants(src_factor, dest_factor) { + return self.webgl_error(InvalidOperation); + } + if has_invalid_blend_constants(dest_factor, src_factor) { + return self.webgl_error(InvalidOperation); + } + self.ipc_renderer .send(CanvasMsg::WebGL(WebGLCommand::BlendFunc(src_factor, dest_factor))) .unwrap(); @@ -815,6 +836,18 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext { // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.3 fn BlendFuncSeparate(&self, src_rgb: u32, dest_rgb: u32, src_alpha: u32, dest_alpha: u32) { + // From the WebGL 1.0 spec, 6.13: Viewport Depth Range: + // + // A call to blendFuncSeparate will generate an INVALID_OPERATION error if srcRGB is + // set to CONSTANT_COLOR or ONE_MINUS_CONSTANT_COLOR and dstRGB is set to + // CONSTANT_ALPHA or ONE_MINUS_CONSTANT_ALPHA or vice versa. + if has_invalid_blend_constants(src_rgb, dest_rgb) { + return self.webgl_error(InvalidOperation); + } + if has_invalid_blend_constants(dest_rgb, src_rgb) { + return self.webgl_error(InvalidOperation); + } + self.ipc_renderer.send( CanvasMsg::WebGL(WebGLCommand::BlendFuncSeparate(src_rgb, dest_rgb, src_alpha, dest_alpha))).unwrap(); } |