diff options
author | Josh Matthews <josh@joshmatthews.net> | 2019-07-10 17:34:16 -0400 |
---|---|---|
committer | Josh Matthews <josh@joshmatthews.net> | 2019-07-12 13:36:44 -0400 |
commit | dbaed5ed9276843ae3aa10f8671f65db839b7ffe (patch) | |
tree | 8493b7aa58d3e19cf558ebd5d346e5ea2ae897c4 /components | |
parent | 812bf8d816d29ecf132ff15a2da6a83c690e2e48 (diff) | |
download | servo-dbaed5ed9276843ae3aa10f8671f65db839b7ffe.tar.gz servo-dbaed5ed9276843ae3aa10f8671f65db839b7ffe.zip |
Make GL/GLES decisions based on the API in use.
Diffstat (limited to 'components')
-rw-r--r-- | components/canvas/gl_context.rs | 13 | ||||
-rw-r--r-- | components/canvas/webgl_thread.rs | 7 | ||||
-rw-r--r-- | components/canvas_traits/webgl.rs | 14 | ||||
-rw-r--r-- | components/script/dom/bindings/trace.rs | 4 | ||||
-rw-r--r-- | components/script/dom/webgl_extensions/ext/extshadertexturelod.rs | 4 | ||||
-rw-r--r-- | components/script/dom/webgl_extensions/ext/oeselementindexuint.rs | 4 | ||||
-rw-r--r-- | components/script/dom/webgl_extensions/ext/oesstandardderivatives.rs | 4 | ||||
-rw-r--r-- | components/script/dom/webgl_extensions/extensions.rs | 10 | ||||
-rw-r--r-- | components/script/dom/webglrenderbuffer.rs | 16 | ||||
-rw-r--r-- | components/script/dom/webglrenderingcontext.rs | 14 | ||||
-rw-r--r-- | components/script/dom/webglshader.rs | 7 | ||||
-rw-r--r-- | components/servo/lib.rs | 2 |
12 files changed, 65 insertions, 34 deletions
diff --git a/components/canvas/gl_context.rs b/components/canvas/gl_context.rs index 9d2a2c8c36c..84c907af617 100644 --- a/components/canvas/gl_context.rs +++ b/components/canvas/gl_context.rs @@ -27,6 +27,7 @@ pub enum GLContextFactory { Native( NativeGLContextHandle, Option<Box<dyn CloneableDispatcher + Send>>, + gl::GlType, ), OSMesa(OSMesaContextHandle), } @@ -35,6 +36,7 @@ impl GLContextFactory { /// Creates a new GLContextFactory that uses the currently bound GL context to create shared contexts. pub fn current_native_handle( dispatcher: Box<dyn CloneableDispatcher + Send>, + api_type: gl::GlType, ) -> Option<GLContextFactory> { let dispatcher = if cfg!(target_os = "windows") { // Used to dispatch functions from the GLContext thread to the main thread's @@ -46,7 +48,8 @@ impl GLContextFactory { // FIXME(emilio): This assumes a single GL backend per platform which is // not true on Linux, we probably need a third `Egl` variant or abstract // it a bit more... - NativeGLContext::current_handle().map(|handle| GLContextFactory::Native(handle, dispatcher)) + NativeGLContext::current_handle() + .map(|handle| GLContextFactory::Native(handle, dispatcher, api_type)) } /// Creates a new GLContextFactory that uses the currently bound OSMesa context to create shared contexts. @@ -63,13 +66,13 @@ impl GLContextFactory { ) -> Result<GLContextWrapper, &'static str> { let attributes = map_attrs(attributes); Ok(match *self { - GLContextFactory::Native(ref handle, ref dispatcher) => { + GLContextFactory::Native(ref handle, ref dispatcher, ref api_type) => { GLContextWrapper::Native(GLContext::new_shared_with_dispatcher( // FIXME(nox): Why are those i32 values? size.to_i32(), attributes, ColorAttachmentType::Texture, - gl::GlType::default(), + *api_type, Self::gl_version(webgl_version), Some(handle), dispatcher.as_ref().map(|d| (**d).clone()), @@ -99,13 +102,13 @@ impl GLContextFactory { ) -> Result<GLContextWrapper, &'static str> { let attributes = map_attrs(attributes); Ok(match *self { - GLContextFactory::Native(..) => { + GLContextFactory::Native(_, _, ref api_type) => { GLContextWrapper::Native(GLContext::new_shared_with_dispatcher( // FIXME(nox): Why are those i32 values? size.to_i32(), attributes, ColorAttachmentType::Texture, - gl::GlType::default(), + *api_type, Self::gl_version(webgl_version), None, None, diff --git a/components/canvas/webgl_thread.rs b/components/canvas/webgl_thread.rs index fa852949be2..b275e62bc7a 100644 --- a/components/canvas/webgl_thread.rs +++ b/components/canvas/webgl_thread.rs @@ -138,9 +138,13 @@ impl<VR: WebVRRenderHandler + 'static> WebGLThread<VR> { ) .expect("WebGLContext not found"); let glsl_version = Self::get_glsl_version(&data.ctx); + let api_type = match data.ctx.gl().get_type() { + gl::GlType::Gl => GlType::Gl, + gl::GlType::Gles => GlType::Gles, + }; // FIXME(nox): Should probably be done by offscreen_gl_context. - if !is_gles() { + if api_type != GlType::Gles { // Points sprites are enabled by default in OpenGL 3.2 core // and in GLES. Rather than doing version detection, it does // not hurt to enable them anyways. @@ -163,6 +167,7 @@ impl<VR: WebVRRenderHandler + 'static> WebGLThread<VR> { limits, share_mode, glsl_version, + api_type, } })) .unwrap(); diff --git a/components/canvas_traits/webgl.rs b/components/canvas_traits/webgl.rs index dc3c8530249..6ac103f629f 100644 --- a/components/canvas_traits/webgl.rs +++ b/components/canvas_traits/webgl.rs @@ -76,6 +76,12 @@ pub enum WebGLMsg { Exit, } +#[derive(Clone, Copy, Debug, Deserialize, MallocSizeOf, PartialEq, Serialize)] +pub enum GlType { + Gl, + Gles, +} + /// Contains the WebGLCommand sender and information about a WebGLContext #[derive(Clone, Debug, Deserialize, Serialize)] pub struct WebGLCreateContextResult { @@ -87,6 +93,8 @@ pub struct WebGLCreateContextResult { pub share_mode: WebGLContextShareMode, /// The GLSL version supported by the context. pub glsl_version: WebGLSLVersion, + /// The GL API used by the context. + pub api_type: GlType, } #[derive(Clone, Copy, Debug, Deserialize, MallocSizeOf, Serialize)] @@ -761,12 +769,6 @@ parameters! { } } -pub fn is_gles() -> bool { - // TODO: align this with the actual kind of graphics context in use, rather than - // making assumptions based on platform - cfg!(any(target_os = "android", target_os = "ios")) -} - #[macro_export] macro_rules! gl_enums { ($(pub enum $name:ident { $($variant:ident = $mod:ident::$constant:ident,)+ })*) => { diff --git a/components/script/dom/bindings/trace.rs b/components/script/dom/bindings/trace.rs index 9579ab99ad8..a0307413719 100644 --- a/components/script/dom/bindings/trace.rs +++ b/components/script/dom/bindings/trace.rs @@ -46,7 +46,7 @@ use canvas_traits::canvas::{ }; use canvas_traits::canvas::{CompositionOrBlending, LineCapStyle, LineJoinStyle, RepetitionStyle}; use canvas_traits::webgl::GLLimits; -use canvas_traits::webgl::{ActiveAttribInfo, ActiveUniformInfo, TexDataType, TexFormat}; +use canvas_traits::webgl::{ActiveAttribInfo, ActiveUniformInfo, GlType, TexDataType, TexFormat}; use canvas_traits::webgl::{WebGLBufferId, WebGLChan, WebGLContextShareMode, WebGLError}; use canvas_traits::webgl::{WebGLFramebufferId, WebGLMsgSender, WebGLPipeline, WebGLProgramId}; use canvas_traits::webgl::{WebGLReceiver, WebGLRenderbufferId, WebGLSLVersion, WebGLSender}; @@ -439,7 +439,7 @@ unsafe_no_jsmanaged_fields!(StorageType); unsafe_no_jsmanaged_fields!(CanvasGradientStop, LinearGradientStyle, RadialGradientStyle); unsafe_no_jsmanaged_fields!(LineCapStyle, LineJoinStyle, CompositionOrBlending); unsafe_no_jsmanaged_fields!(RepetitionStyle); -unsafe_no_jsmanaged_fields!(WebGLError, GLLimits); +unsafe_no_jsmanaged_fields!(WebGLError, GLLimits, GlType); unsafe_no_jsmanaged_fields!(TimeProfilerChan); unsafe_no_jsmanaged_fields!(MemProfilerChan); unsafe_no_jsmanaged_fields!(PseudoElement); diff --git a/components/script/dom/webgl_extensions/ext/extshadertexturelod.rs b/components/script/dom/webgl_extensions/ext/extshadertexturelod.rs index 33ea2aa67b8..3ace3673499 100644 --- a/components/script/dom/webgl_extensions/ext/extshadertexturelod.rs +++ b/components/script/dom/webgl_extensions/ext/extshadertexturelod.rs @@ -7,7 +7,7 @@ use crate::dom::bindings::codegen::Bindings::EXTShaderTextureLodBinding; use crate::dom::bindings::reflector::{reflect_dom_object, DomObject, Reflector}; use crate::dom::bindings::root::DomRoot; use crate::dom::webglrenderingcontext::WebGLRenderingContext; -use canvas_traits::webgl::{is_gles, WebGLVersion}; +use canvas_traits::webgl::WebGLVersion; use dom_struct::dom_struct; #[dom_struct] @@ -40,7 +40,7 @@ impl WebGLExtension for EXTShaderTextureLod { fn is_supported(ext: &WebGLExtensions) -> bool { // This extension is always available on desktop GL. - !is_gles() || ext.supports_gl_extension("GL_EXT_shader_texture_lod") + !ext.is_gles() || ext.supports_gl_extension("GL_EXT_shader_texture_lod") } fn enable(_ext: &WebGLExtensions) {} diff --git a/components/script/dom/webgl_extensions/ext/oeselementindexuint.rs b/components/script/dom/webgl_extensions/ext/oeselementindexuint.rs index 3182ed8699f..6d6112529b9 100644 --- a/components/script/dom/webgl_extensions/ext/oeselementindexuint.rs +++ b/components/script/dom/webgl_extensions/ext/oeselementindexuint.rs @@ -7,7 +7,7 @@ use crate::dom::bindings::codegen::Bindings::OESElementIndexUintBinding; use crate::dom::bindings::reflector::{reflect_dom_object, DomObject, Reflector}; use crate::dom::bindings::root::DomRoot; use crate::dom::webglrenderingcontext::WebGLRenderingContext; -use canvas_traits::webgl::{is_gles, WebGLVersion}; +use canvas_traits::webgl::WebGLVersion; use dom_struct::dom_struct; #[dom_struct] @@ -40,7 +40,7 @@ impl WebGLExtension for OESElementIndexUint { fn is_supported(ext: &WebGLExtensions) -> bool { // This extension is always available in desktop OpenGL. - !is_gles() || ext.supports_gl_extension("GL_OES_element_index_uint") + !ext.is_gles() || ext.supports_gl_extension("GL_OES_element_index_uint") } fn enable(ext: &WebGLExtensions) { diff --git a/components/script/dom/webgl_extensions/ext/oesstandardderivatives.rs b/components/script/dom/webgl_extensions/ext/oesstandardderivatives.rs index 5505deb543a..b6945123a12 100644 --- a/components/script/dom/webgl_extensions/ext/oesstandardderivatives.rs +++ b/components/script/dom/webgl_extensions/ext/oesstandardderivatives.rs @@ -8,7 +8,7 @@ use crate::dom::bindings::codegen::Bindings::OESStandardDerivativesBinding::OESS use crate::dom::bindings::reflector::{reflect_dom_object, DomObject, Reflector}; use crate::dom::bindings::root::DomRoot; use crate::dom::webglrenderingcontext::WebGLRenderingContext; -use canvas_traits::webgl::{is_gles, WebGLVersion}; +use canvas_traits::webgl::WebGLVersion; use dom_struct::dom_struct; #[dom_struct] @@ -40,7 +40,7 @@ impl WebGLExtension for OESStandardDerivatives { fn is_supported(ext: &WebGLExtensions) -> bool { // The standard derivatives are always available in desktop OpenGL. - !is_gles() || ext.supports_any_gl_extension(&["GL_OES_standard_derivatives"]) + !ext.is_gles() || ext.supports_any_gl_extension(&["GL_OES_standard_derivatives"]) } fn enable(ext: &WebGLExtensions) { diff --git a/components/script/dom/webgl_extensions/extensions.rs b/components/script/dom/webgl_extensions/extensions.rs index e71fcf7dac5..7beb3081374 100644 --- a/components/script/dom/webgl_extensions/extensions.rs +++ b/components/script/dom/webgl_extensions/extensions.rs @@ -18,7 +18,7 @@ use crate::dom::oestexturehalffloat::OESTextureHalfFloat; use crate::dom::webglcolorbufferfloat::WEBGLColorBufferFloat; use crate::dom::webglrenderingcontext::WebGLRenderingContext; use crate::dom::webgltexture::TexCompression; -use canvas_traits::webgl::WebGLVersion; +use canvas_traits::webgl::{GlType, WebGLVersion}; use fnv::{FnvHashMap, FnvHashSet}; use gleam::gl::{self, GLenum}; use js::jsapi::JSObject; @@ -146,14 +146,16 @@ pub struct WebGLExtensions { extensions: DomRefCell<HashMap<String, Box<dyn WebGLExtensionWrapper>>>, features: DomRefCell<WebGLExtensionFeatures>, webgl_version: WebGLVersion, + api_type: GlType, } impl WebGLExtensions { - pub fn new(webgl_version: WebGLVersion) -> WebGLExtensions { + pub fn new(webgl_version: WebGLVersion, api_type: GlType) -> WebGLExtensions { Self { extensions: DomRefCell::new(HashMap::new()), features: DomRefCell::new(WebGLExtensionFeatures::new(webgl_version)), webgl_version, + api_type, } } @@ -425,6 +427,10 @@ impl WebGLExtensions { } type_ } + + pub fn is_gles(&self) -> bool { + self.api_type == GlType::Gles + } } // Helper structs diff --git a/components/script/dom/webglrenderbuffer.rs b/components/script/dom/webglrenderbuffer.rs index d1387b277aa..459b76466e3 100644 --- a/components/script/dom/webglrenderbuffer.rs +++ b/components/script/dom/webglrenderbuffer.rs @@ -14,7 +14,7 @@ use crate::dom::bindings::root::DomRoot; use crate::dom::webglobject::WebGLObject; use crate::dom::webglrenderingcontext::WebGLRenderingContext; use canvas_traits::webgl::{ - is_gles, webgl_channel, WebGLCommand, WebGLError, WebGLRenderbufferId, WebGLResult, + webgl_channel, GlType, WebGLCommand, WebGLError, WebGLRenderbufferId, WebGLResult, }; use dom_struct::dom_struct; use std::cell::Cell; @@ -120,7 +120,15 @@ impl WebGLRenderbuffer { self.ever_bound.get() } - pub fn storage(&self, internal_format: u32, width: i32, height: i32) -> WebGLResult<()> { + pub fn storage( + &self, + api_type: GlType, + internal_format: u32, + width: i32, + height: i32, + ) -> WebGLResult<()> { + let is_gles = api_type == GlType::Gles; + // Validate the internal_format, and save it for completeness // validation. let actual_format = match internal_format { @@ -131,7 +139,7 @@ impl WebGLRenderbuffer { constants::DEPTH_STENCIL => WebGL2RenderingContextConstants::DEPTH24_STENCIL8, constants::RGB5_A1 => { // 16-bit RGBA formats are not supported on desktop GL. - if is_gles() { + if is_gles { constants::RGB5_A1 } else { WebGL2RenderingContextConstants::RGBA8 @@ -139,7 +147,7 @@ impl WebGLRenderbuffer { }, constants::RGB565 => { // RGB565 is not supported on desktop GL. - if is_gles() { + if is_gles { constants::RGB565 } else { WebGL2RenderingContextConstants::RGB8 diff --git a/components/script/dom/webglrenderingcontext.rs b/components/script/dom/webglrenderingcontext.rs index d138dc3952e..d413bd1ac71 100644 --- a/components/script/dom/webglrenderingcontext.rs +++ b/components/script/dom/webglrenderingcontext.rs @@ -52,8 +52,8 @@ use crate::dom::window::Window; use backtrace::Backtrace; use canvas_traits::webgl::WebGLError::*; use canvas_traits::webgl::{ - webgl_channel, AlphaTreatment, DOMToTextureCommand, GLContextAttributes, GLLimits, Parameter, - TexDataType, TexFormat, TexParameter, WebGLCommand, WebGLCommandBacktrace, + webgl_channel, AlphaTreatment, DOMToTextureCommand, GLContextAttributes, GLLimits, GlType, + Parameter, TexDataType, TexFormat, TexParameter, WebGLCommand, WebGLCommandBacktrace, WebGLContextShareMode, WebGLError, WebGLFramebufferBindingRequest, WebGLMsg, WebGLMsgSender, WebGLProgramId, WebGLResult, WebGLSLVersion, WebGLSender, WebGLVersion, WebVRCommand, YAxisTreatment, @@ -166,6 +166,7 @@ pub struct WebGLRenderingContext { default_vao: DomOnceCell<WebGLVertexArrayObjectOES>, current_vao: MutNullableDom<WebGLVertexArrayObjectOES>, textures: Textures, + api_type: GlType, } impl WebGLRenderingContext { @@ -216,11 +217,12 @@ impl WebGLRenderingContext { // what was requested size: Cell::new(size), current_clear_color: Cell::new((0.0, 0.0, 0.0, 0.0)), - extension_manager: WebGLExtensions::new(webgl_version), + extension_manager: WebGLExtensions::new(webgl_version, ctx_data.api_type), capabilities: Default::default(), default_vao: Default::default(), current_vao: Default::default(), textures: Textures::new(max_combined_texture_image_units), + api_type: ctx_data.api_type, } }) } @@ -2106,6 +2108,7 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext { handle_potential_webgl_error!( self, shader.compile( + self.api_type, self.webgl_version, self.glsl_version, &self.limits, @@ -4031,7 +4034,10 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext { self.bound_renderbuffer.get().ok_or(InvalidOperation), return ); - handle_potential_webgl_error!(self, rb.storage(internal_format, width, height)); + handle_potential_webgl_error!( + self, + rb.storage(self.api_type, internal_format, width, height) + ); if let Some(fb) = self.bound_framebuffer.get() { fb.invalidate_renderbuffer(&*rb); } diff --git a/components/script/dom/webglshader.rs b/components/script/dom/webglshader.rs index 9ee44bb8be9..bf63bdd3840 100644 --- a/components/script/dom/webglshader.rs +++ b/components/script/dom/webglshader.rs @@ -14,7 +14,7 @@ use crate::dom::webgl_extensions::ext::oesstandardderivatives::OESStandardDeriva use crate::dom::webgl_extensions::WebGLExtensions; use crate::dom::webglobject::WebGLObject; use crate::dom::webglrenderingcontext::WebGLRenderingContext; -use canvas_traits::webgl::{webgl_channel, WebGLVersion}; +use canvas_traits::webgl::{webgl_channel, GlType, WebGLVersion}; use canvas_traits::webgl::{GLLimits, WebGLCommand, WebGLError}; use canvas_traits::webgl::{WebGLResult, WebGLSLVersion, WebGLShaderId}; use dom_struct::dom_struct; @@ -93,6 +93,7 @@ impl WebGLShader { /// glCompileShader pub fn compile( &self, + api_type: GlType, webgl_version: WebGLVersion, glsl_version: WebGLSLVersion, limits: &GLLimits, @@ -122,7 +123,7 @@ impl WebGLShader { }; let validator = match webgl_version { WebGLVersion::WebGL1 => { - let output_format = if cfg!(any(target_os = "android", target_os = "ios")) { + let output_format = if api_type == GlType::Gles { Output::Essl } else { Output::Glsl @@ -130,7 +131,7 @@ impl WebGLShader { ShaderValidator::for_webgl(self.gl_type, output_format, ¶ms).unwrap() }, WebGLVersion::WebGL2 => { - let output_format = if cfg!(any(target_os = "android", target_os = "ios")) { + let output_format = if api_type == GlType::Gles { Output::Essl } else { match (glsl_version.major, glsl_version.minor) { diff --git a/components/servo/lib.rs b/components/servo/lib.rs index f31cc1fcd24..2f67d563991 100644 --- a/components/servo/lib.rs +++ b/components/servo/lib.rs @@ -747,7 +747,7 @@ fn create_constellation( GLContextFactory::current_osmesa_handle() } else { let dispatcher = Box::new(MainThreadDispatcher::new(compositor_proxy.clone())) as Box<_>; - GLContextFactory::current_native_handle(dispatcher) + GLContextFactory::current_native_handle(dispatcher, window_gl.get_type()) }; let (external_image_handlers, external_images) = WebrenderExternalImageHandlers::new(); |