diff options
author | Imanol Fernandez <mortimergoro@gmail.com> | 2017-10-26 18:04:13 +0200 |
---|---|---|
committer | Imanol Fernandez <mortimergoro@gmail.com> | 2017-10-27 12:53:11 +0200 |
commit | ddd6c86e992a45d6490b8ec6eb2bf7b3ecce9a03 (patch) | |
tree | e037a6f8ff7948f54d9db71224d45d1ea85757e5 /components/canvas | |
parent | fd4843a40ef7c000bbd747208fcf61267dbf157f (diff) | |
download | servo-ddd6c86e992a45d6490b8ec6eb2bf7b3ecce9a03.tar.gz servo-ddd6c86e992a45d6490b8ec6eb2bf7b3ecce9a03.zip |
Kick off WebGL 2.0 implementation
Diffstat (limited to 'components/canvas')
-rw-r--r-- | components/canvas/gl_context.rs | 35 | ||||
-rw-r--r-- | components/canvas/webgl_thread.rs | 9 |
2 files changed, 29 insertions, 15 deletions
diff --git a/components/canvas/gl_context.rs b/components/canvas/gl_context.rs index 8770e3d19d8..e0d686f622a 100644 --- a/components/canvas/gl_context.rs +++ b/components/canvas/gl_context.rs @@ -2,7 +2,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -use canvas_traits::webgl::WebGLCommand; +use canvas_traits::webgl::{WebGLCommand, WebGLVersion}; use compositing::compositor_thread::{CompositorProxy, self}; use euclid::Size2D; use gleam::gl; @@ -41,9 +41,12 @@ impl GLContextFactory { } /// Creates a new shared GLContext with the main GLContext - pub fn new_shared_context(&self, - size: Size2D<i32>, - attributes: GLContextAttributes) -> Result<GLContextWrapper, &'static str> { + pub fn new_shared_context( + &self, + webgl_version: WebGLVersion, + size: Size2D<i32>, + attributes: GLContextAttributes + ) -> Result<GLContextWrapper, &'static str> { match *self { GLContextFactory::Native(ref handle, ref dispatcher) => { let dispatcher = dispatcher.as_ref().map(|d| Box::new(d.clone()) as Box<_>); @@ -51,7 +54,7 @@ impl GLContextFactory { attributes, ColorAttachmentType::Texture, gl::GlType::default(), - GLVersion::Major(2), + Self::gl_version(webgl_version), Some(handle), dispatcher); ctx.map(GLContextWrapper::Native) @@ -61,7 +64,7 @@ impl GLContextFactory { attributes, ColorAttachmentType::Texture, gl::GlType::default(), - GLVersion::Major(2), + Self::gl_version(webgl_version), Some(handle), None); ctx.map(GLContextWrapper::OSMesa) @@ -70,16 +73,19 @@ impl GLContextFactory { } /// Creates a new non-shared GLContext - pub fn new_context(&self, - size: Size2D<i32>, - attributes: GLContextAttributes) -> Result<GLContextWrapper, &'static str> { + pub fn new_context( + &self, + webgl_version: WebGLVersion, + size: Size2D<i32>, + attributes: GLContextAttributes + ) -> Result<GLContextWrapper, &'static str> { match *self { GLContextFactory::Native(..) => { let ctx = GLContext::<NativeGLContext>::new_shared_with_dispatcher(size, attributes, ColorAttachmentType::Texture, gl::GlType::default(), - GLVersion::Major(2), + Self::gl_version(webgl_version), None, None); ctx.map(GLContextWrapper::Native) @@ -89,13 +95,20 @@ impl GLContextFactory { attributes, ColorAttachmentType::Texture, gl::GlType::default(), - GLVersion::Major(2), + Self::gl_version(webgl_version), None, None); ctx.map(GLContextWrapper::OSMesa) } } } + + fn gl_version(webgl_version: WebGLVersion) -> GLVersion { + match webgl_version { + WebGLVersion::WebGL1 => GLVersion::Major(2), + WebGLVersion::WebGL2 => GLVersion::Major(3), + } + } } diff --git a/components/canvas/webgl_thread.rs b/components/canvas/webgl_thread.rs index 76dfa752ade..383873ff7dc 100644 --- a/components/canvas/webgl_thread.rs +++ b/components/canvas/webgl_thread.rs @@ -89,8 +89,8 @@ impl<VR: WebVRRenderHandler + 'static, OB: WebGLThreadObserver> WebGLThread<VR, #[inline] fn handle_msg(&mut self, msg: WebGLMsg, webgl_chan: &WebGLChan) -> bool { match msg { - WebGLMsg::CreateContext(size, attributes, result_sender) => { - let result = self.create_webgl_context(size, attributes); + WebGLMsg::CreateContext(version, size, attributes, result_sender) => { + let result = self.create_webgl_context(version, size, attributes); result_sender.send(result.map(|(id, limits, share_mode)| WebGLCreateContextResult { sender: WebGLMsgSender::new(id, webgl_chan.clone()), @@ -179,15 +179,16 @@ impl<VR: WebVRRenderHandler + 'static, OB: WebGLThreadObserver> WebGLThread<VR, /// Creates a new WebGLContext fn create_webgl_context(&mut self, + version: WebGLVersion, size: Size2D<i32>, attributes: GLContextAttributes) -> Result<(WebGLContextId, GLLimits, WebGLContextShareMode), String> { // First try to create a shared context for the best performance. // Fallback to readback mode if the shared context creation fails. - let result = self.gl_factory.new_shared_context(size, attributes) + let result = self.gl_factory.new_shared_context(version, size, attributes) .map(|r| (r, WebGLContextShareMode::SharedTexture)) .or_else(|_| { - let ctx = self.gl_factory.new_context(size, attributes); + let ctx = self.gl_factory.new_context(version, size, attributes); ctx.map(|r| (r, WebGLContextShareMode::Readback)) }); |