aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/webglrenderingcontext.rs
diff options
context:
space:
mode:
authorecoal95 <ecoal95@gmail.com>2015-07-06 22:56:42 +0200
committerecoal95 <ecoal95@gmail.com>2015-07-06 23:02:51 +0200
commit8438db89e151ed07b32a5b37fd4c4f903605c126 (patch)
tree1b4450f01ca313b31b536af8eb19d21bb67de036 /components/script/dom/webglrenderingcontext.rs
parent9b306aced6f8649e606a5c9377df9219b914adcd (diff)
downloadservo-8438db89e151ed07b32a5b37fd4c4f903605c126.tar.gz
servo-8438db89e151ed07b32a5b37fd4c4f903605c126.zip
address review comments
Diffstat (limited to 'components/script/dom/webglrenderingcontext.rs')
-rw-r--r--components/script/dom/webglrenderingcontext.rs34
1 files changed, 18 insertions, 16 deletions
diff --git a/components/script/dom/webglrenderingcontext.rs b/components/script/dom/webglrenderingcontext.rs
index c87b901d391..123c1e200c3 100644
--- a/components/script/dom/webglrenderingcontext.rs
+++ b/components/script/dom/webglrenderingcontext.rs
@@ -34,7 +34,7 @@ use std::sync::mpsc::{channel, Sender};
use util::str::DOMString;
use offscreen_gl_context::GLContextAttributes;
-pub const MAX_UNIFORM_AND_ATTRIBUTE_LEN : usize = 256;
+pub const MAX_UNIFORM_AND_ATTRIBUTE_LEN: usize = 256;
macro_rules! handle_potential_webgl_error {
($context:ident, $call:expr, $return_on_error:expr) => {
@@ -54,7 +54,7 @@ pub struct WebGLRenderingContext {
global: GlobalField,
renderer: Sender<CanvasMsg>,
canvas: JS<HTMLCanvasElement>,
- last_error: Cell<WebGLError>,
+ last_error: Cell<Option<WebGLError>>,
}
impl WebGLRenderingContext {
@@ -69,7 +69,7 @@ impl WebGLRenderingContext {
reflector_: Reflector::new(),
global: GlobalField::from_rooted(&global),
renderer: chan,
- last_error: Cell::new(WebGLError::NoError),
+ last_error: Cell::new(None),
canvas: JS::from_ref(canvas),
})
}
@@ -134,15 +134,18 @@ impl<'a> WebGLRenderingContextMethods for &'a WebGLRenderingContext {
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.3
fn GetError(self) -> u32 {
- let error_code = match self.last_error.get() {
- WebGLError::NoError => constants::NO_ERROR,
- WebGLError::InvalidEnum => constants::INVALID_ENUM,
- WebGLError::InvalidValue => constants::INVALID_VALUE,
- WebGLError::InvalidOperation => constants::INVALID_OPERATION,
- WebGLError::OutOfMemory => constants::OUT_OF_MEMORY,
- WebGLError::ContextLost => constants::CONTEXT_LOST_WEBGL,
+ let error_code = if let Some(error) = self.last_error.get() {
+ match error {
+ WebGLError::InvalidEnum => constants::INVALID_ENUM,
+ WebGLError::InvalidValue => constants::INVALID_VALUE,
+ WebGLError::InvalidOperation => constants::INVALID_OPERATION,
+ WebGLError::OutOfMemory => constants::OUT_OF_MEMORY,
+ WebGLError::ContextLost => constants::CONTEXT_LOST_WEBGL,
+ }
+ } else {
+ constants::NO_ERROR
};
- self.last_error.set(WebGLError::NoError);
+ self.last_error.set(None);
error_code
}
@@ -231,9 +234,8 @@ impl<'a> WebGLRenderingContextMethods for &'a WebGLRenderingContext {
framebuffer.bind(target)
} else {
// Bind the default framebuffer
- self.renderer.send(
- CanvasMsg::WebGL(
- CanvasWebGLMsg::BindFramebuffer(target, WebGLFramebufferBindingRequest::Default))).unwrap()
+ let cmd = CanvasWebGLMsg::BindFramebuffer(target, WebGLFramebufferBindingRequest::Default);
+ self.renderer.send(CanvasMsg::WebGL(cmd)).unwrap();
}
}
@@ -502,8 +504,8 @@ impl<'a> WebGLRenderingContextHelpers for &'a WebGLRenderingContext {
fn handle_webgl_error(&self, err: WebGLError) {
// If an error has been detected no further errors must be
// recorded until `getError` has been called
- if self.last_error.get() == WebGLError::NoError {
- self.last_error.set(err);
+ if self.last_error.get().is_none() {
+ self.last_error.set(Some(err));
}
}
}