aboutsummaryrefslogtreecommitdiffstats
path: root/components/script
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2018-04-16 12:43:33 -0400
committerGitHub <noreply@github.com>2018-04-16 12:43:33 -0400
commit441f1cd231b2471039e2d08b951b32f3ca06d38e (patch)
treea242ced11d160fbe41090e13baabb53bd549928c /components/script
parent11733d3d8a10353338a40da4cea4b4a2763308c4 (diff)
parentd16a73001fa937734f4e96b693f9e36627f4ac38 (diff)
downloadservo-441f1cd231b2471039e2d08b951b32f3ca06d38e.tar.gz
servo-441f1cd231b2471039e2d08b951b32f3ca06d38e.zip
Auto merge of #20646 - servo:webgl, r=emilio
Some drive-by error condition fix for gl.drawElements <!-- 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/20646) <!-- Reviewable:end -->
Diffstat (limited to 'components/script')
-rw-r--r--components/script/dom/webglrenderingcontext.rs44
1 files changed, 23 insertions, 21 deletions
diff --git a/components/script/dom/webglrenderingcontext.rs b/components/script/dom/webglrenderingcontext.rs
index 5deace85746..ce09fda8943 100644
--- a/components/script/dom/webglrenderingcontext.rs
+++ b/components/script/dom/webglrenderingcontext.rs
@@ -2143,6 +2143,14 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.11
fn DrawElements(&self, mode: u32, count: i32, type_: u32, offset: i64) {
+ match mode {
+ constants::POINTS | constants::LINE_STRIP |
+ constants::LINE_LOOP | constants::LINES |
+ constants::TRIANGLE_STRIP | constants::TRIANGLE_FAN |
+ constants::TRIANGLES => {},
+ _ => return self.webgl_error(InvalidEnum),
+ }
+
// From the GLES 2.0.25 spec, page 21:
//
// "type must be one of UNSIGNED_BYTE or UNSIGNED_SHORT"
@@ -2175,35 +2183,29 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
return self.webgl_error(InvalidOperation);
}
- if let Some(array_buffer) = self.bound_buffer_element_array.get() {
- // WebGL Spec: check buffer overflows, must be a valid multiple of the size.
- let val = offset as u64 + (count as u64 * type_size as u64);
- if val > array_buffer.capacity() as u64 {
+ if count > 0 {
+ if let Some(array_buffer) = self.bound_buffer_element_array.get() {
+ // WebGL Spec: check buffer overflows, must be a valid multiple of the size.
+ let val = offset as u64 + (count as u64 * type_size as u64);
+ if val > array_buffer.capacity() as u64 {
+ return self.webgl_error(InvalidOperation);
+ }
+ } else {
+ // From the WebGL spec
+ //
+ // a non-null WebGLBuffer must be bound to the ELEMENT_ARRAY_BUFFER binding point
+ // or an INVALID_OPERATION error will be generated.
+ //
return self.webgl_error(InvalidOperation);
}
- } else {
- // From the WebGL spec
- //
- // a non-null WebGLBuffer must be bound to the ELEMENT_ARRAY_BUFFER binding point
- // or an INVALID_OPERATION error will be generated.
- //
- return self.webgl_error(InvalidOperation);
}
if !self.validate_framebuffer_complete() {
return;
}
- match mode {
- constants::POINTS | constants::LINE_STRIP |
- constants::LINE_LOOP | constants::LINES |
- constants::TRIANGLE_STRIP | constants::TRIANGLE_FAN |
- constants::TRIANGLES => {
- self.send_command(WebGLCommand::DrawElements(mode, count, type_, offset));
- self.mark_as_dirty();
- },
- _ => self.webgl_error(InvalidEnum),
- }
+ self.send_command(WebGLCommand::DrawElements(mode, count, type_, offset));
+ self.mark_as_dirty();
}
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10