diff options
author | ecoal95 <ecoal95@gmail.com> | 2015-06-20 20:37:44 +0200 |
---|---|---|
committer | ecoal95 <ecoal95@gmail.com> | 2015-07-06 19:55:48 +0200 |
commit | 9b306aced6f8649e606a5c9377df9219b914adcd (patch) | |
tree | ae543a5a10b116d19b10ad1de824ec1bb54451b8 /components/script/dom/webglrenderingcontext.rs | |
parent | 42bd43a696939c3259284a01b8ef64aa13a9939c (diff) | |
download | servo-9b306aced6f8649e606a5c9377df9219b914adcd.tar.gz servo-9b306aced6f8649e606a5c9377df9219b914adcd.zip |
webgl: implement getError
Diffstat (limited to 'components/script/dom/webglrenderingcontext.rs')
-rw-r--r-- | components/script/dom/webglrenderingcontext.rs | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/components/script/dom/webglrenderingcontext.rs b/components/script/dom/webglrenderingcontext.rs index 23090a73cfb..c87b901d391 100644 --- a/components/script/dom/webglrenderingcontext.rs +++ b/components/script/dom/webglrenderingcontext.rs @@ -26,6 +26,7 @@ use euclid::size::Size2D; use js::jsapi::{JSContext, JSObject, RootedValue}; use js::jsapi::{JS_GetFloat32ArrayData, JS_GetObjectAsArrayBufferView}; use js::jsval::{JSVal, UndefinedValue, NullValue, Int32Value, BooleanValue}; +use std::cell::Cell; use std::mem; use std::ptr; use std::slice; @@ -53,6 +54,7 @@ pub struct WebGLRenderingContext { global: GlobalField, renderer: Sender<CanvasMsg>, canvas: JS<HTMLCanvasElement>, + last_error: Cell<WebGLError>, } impl WebGLRenderingContext { @@ -67,6 +69,7 @@ impl WebGLRenderingContext { reflector_: Reflector::new(), global: GlobalField::from_rooted(&global), renderer: chan, + last_error: Cell::new(WebGLError::NoError), canvas: JS::from_ref(canvas), }) } @@ -129,6 +132,20 @@ impl<'a> WebGLRenderingContextMethods for &'a WebGLRenderingContext { rval.ptr } + // 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, + }; + self.last_error.set(WebGLError::NoError); + error_code + } + // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.2 fn GetContextAttributes(self) -> Option<WebGLContextAttributes> { let (sender, receiver) = channel(); @@ -482,9 +499,12 @@ pub trait WebGLRenderingContextHelpers { } impl<'a> WebGLRenderingContextHelpers for &'a WebGLRenderingContext { - fn handle_webgl_error(&self, _: WebGLError) { - debug!("WebGL error received"); - // ignore for now + 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); + } } } |