From 7d640d62699387d23e79369714a8919dc4c2cecd Mon Sep 17 00:00:00 2001 From: Josh Matthews Date: Mon, 14 Jan 2019 09:38:47 -0500 Subject: [PATCH] Return the old draw buffer when resizing. --- Cargo.toml | 2 +- src/gl_context.rs | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 1178f82..4d1f851 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "offscreen_gl_context" license = "MIT / Apache-2.0" -version = "0.21.1" +version = "0.22.0" authors = ["Emilio Cobos Álvarez ", "The Servo Project Developers"] description = "Creation and manipulation of HW accelerated offscreen rendering contexts in multiple platforms. Originally intended for the Servo project's WebGL implementation." repository = "https://github.com/servo/rust-offscreen-rendering-context" diff --git a/src/gl_context.rs b/src/gl_context.rs index e15a382..81e9224 100644 --- a/src/gl_context.rs +++ b/src/gl_context.rs @@ -209,12 +209,12 @@ impl GLContext } // We resize just replacing the draw buffer, we don't perform size optimizations - // in order to keep this generic - pub fn resize(&mut self, size: Size2D) -> Result<(), &'static str> { - if self.draw_buffer.is_some() { - let color_attachment_type = - self.borrow_draw_buffer().unwrap().color_attachment_type(); - self.init_offscreen(size, color_attachment_type) + // in order to keep this generic. The old buffer is returned in case its resources + // are still in use. + pub fn resize(&mut self, size: Size2D) -> Result { + if let Some(draw_buffer) = self.draw_buffer.take() { + let color_attachment_type = draw_buffer.color_attachment_type(); + self.init_offscreen(size, color_attachment_type).map(|()| draw_buffer) } else { Err("No DrawBuffer found") }