Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor WebGL implementation to move logic inside the DOM interfaces #6380

Merged
merged 4 commits into from Jul 6, 2015
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

webgl: implement getError

  • Loading branch information
emilio committed Jul 6, 2015
commit 9b306aced6f8649e606a5c9377df9219b914adcd
@@ -129,8 +129,9 @@ pub enum CanvasWebGLMsg {
DrawingBufferHeight(Sender<i32>),
}

#[derive(Clone)]
#[derive(Clone, Copy, PartialEq)]
pub enum WebGLError {
NoError,
InvalidEnum,
InvalidOperation,
InvalidValue,
@@ -36,6 +36,7 @@ use script_task::ScriptChan;

use canvas_traits::{CanvasGradientStop, LinearGradientStyle, RadialGradientStyle};
use canvas_traits::{LineCapStyle, LineJoinStyle, CompositionOrBlending, RepetitionStyle};
use canvas_traits::WebGLError;
use cssparser::RGBA;
use encoding::types::EncodingRef;
use euclid::matrix2d::Matrix2D;
@@ -297,6 +298,7 @@ no_jsmanaged_fields!(StorageType);
no_jsmanaged_fields!(CanvasGradientStop, LinearGradientStyle, RadialGradientStyle);
no_jsmanaged_fields!(LineCapStyle, LineJoinStyle, CompositionOrBlending);
no_jsmanaged_fields!(RepetitionStyle);
no_jsmanaged_fields!(WebGLError);

impl JSTraceable for Box<ScriptChan+Send> {
#[inline]
@@ -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);
}
}
}

@@ -558,7 +558,7 @@ interface WebGLRenderingContextBase
//any getBufferParameter(GLenum target, GLenum pname);
any getParameter(GLenum pname);

//[WebGLHandlesContextLoss] GLenum getError();
[WebGLHandlesContextLoss] GLenum getError();

//any getFramebufferAttachmentParameter(GLenum target, GLenum attachment,
// GLenum pname);
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.