From 1293692ef8874f4d810f9a08114bcbfe11d4ac8f Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Fri, 7 Sep 2018 10:40:30 +0200 Subject: [PATCH] Simplify WebGLBuffer::buffer_data There is no need to pass the target to that buffer method, given the buffer has been retrieved by looking up the one bound to that target in the context. --- components/script/dom/webglbuffer.rs | 13 ++----------- .../script/dom/webglrenderingcontext.rs | 19 +++++-------------- 2 files changed, 7 insertions(+), 25 deletions(-) diff --git a/components/script/dom/webglbuffer.rs b/components/script/dom/webglbuffer.rs index d874cc7a73a..138c34130a3 100644 --- a/components/script/dom/webglbuffer.rs +++ b/components/script/dom/webglbuffer.rs @@ -62,10 +62,7 @@ impl WebGLBuffer { self.id } - pub fn buffer_data(&self, target: u32, data: T, usage: u32) -> WebGLResult<()> - where - T: Into>, - { + pub fn buffer_data(&self, data: Vec, usage: u32) -> WebGLResult<()> { match usage { WebGLRenderingContextConstants::STREAM_DRAW | WebGLRenderingContextConstants::STATIC_DRAW | @@ -73,17 +70,11 @@ impl WebGLBuffer { _ => return Err(WebGLError::InvalidEnum), } - if let Some(previous_target) = self.target.get() { - if target != previous_target { - return Err(WebGLError::InvalidOperation); - } - } - let data = data.into(); self.capacity.set(data.len()); self.usage.set(usage); self.upcast::() .context() - .send_command(WebGLCommand::BufferData(target, data.into(), usage)); + .send_command(WebGLCommand::BufferData(self.target.get().unwrap(), data.into(), usage)); Ok(()) } diff --git a/components/script/dom/webglrenderingcontext.rs b/components/script/dom/webglrenderingcontext.rs index 647ff441e3e..82bf6d46e91 100644 --- a/components/script/dom/webglrenderingcontext.rs +++ b/components/script/dom/webglrenderingcontext.rs @@ -1859,21 +1859,15 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext { }; let bound_buffer = handle_potential_webgl_error!(self, self.bound_buffer(target), return); - let bound_buffer = match bound_buffer { - Some(bound_buffer) => bound_buffer, - None => return self.webgl_error(InvalidOperation), - }; + let bound_buffer = handle_potential_webgl_error!(self, bound_buffer.ok_or(InvalidOperation), return); - handle_potential_webgl_error!(self, bound_buffer.buffer_data(target, data, usage)); + handle_potential_webgl_error!(self, bound_buffer.buffer_data(data, usage)); } // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.5 fn BufferData_(&self, target: u32, size: i64, usage: u32) { let bound_buffer = handle_potential_webgl_error!(self, self.bound_buffer(target), return); - let bound_buffer = match bound_buffer { - Some(bound_buffer) => bound_buffer, - None => return self.webgl_error(InvalidOperation), - }; + let bound_buffer = handle_potential_webgl_error!(self, bound_buffer.ok_or(InvalidOperation), return); if size < 0 { return self.webgl_error(InvalidValue); @@ -1882,7 +1876,7 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext { // FIXME: Allocating a buffer based on user-requested size is // not great, but we don't have a fallible allocation to try. let data = vec![0u8; size as usize]; - handle_potential_webgl_error!(self, bound_buffer.buffer_data(target, data, usage)); + handle_potential_webgl_error!(self, bound_buffer.buffer_data(data, usage)); } // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.5 @@ -1894,10 +1888,7 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext { }; let bound_buffer = handle_potential_webgl_error!(self, self.bound_buffer(target), return); - let bound_buffer = match bound_buffer { - Some(bound_buffer) => bound_buffer, - None => return self.webgl_error(InvalidOperation), - }; + let bound_buffer = handle_potential_webgl_error!(self, bound_buffer.ok_or(InvalidOperation), return); if offset < 0 { return self.webgl_error(InvalidValue);