aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosh Matthews <josh@joshmatthews.net>2018-11-14 18:06:35 -0500
committerJosh Matthews <josh@joshmatthews.net>2019-03-07 09:27:36 -0500
commit3121f42d52feeb17f911e29d8ef5dd31f9f2769c (patch)
treefc98b3d78fdd86d0894cfe5b2268c17faaa3a14c
parent0f3108ce79a1eaefe99559a1910fcbc52effa93e (diff)
downloadservo-3121f42d52feeb17f911e29d8ef5dd31f9f2769c.tar.gz
servo-3121f42d52feeb17f911e29d8ef5dd31f9f2769c.zip
Remove offscreen_gl_context dependency from canvas_traits and script.
-rw-r--r--Cargo.lock2
-rw-r--r--components/canvas/gl_context.rs52
-rw-r--r--components/canvas/webgl_thread.rs12
-rw-r--r--components/canvas_traits/Cargo.toml1
-rw-r--r--components/canvas_traits/webgl.rs25
-rw-r--r--components/script/Cargo.toml1
-rw-r--r--components/script/dom/bindings/trace.rs2
-rw-r--r--components/script/dom/htmlcanvaselement.rs3
-rw-r--r--components/script/dom/webgl2renderingcontext.rs3
-rw-r--r--components/script/dom/webglrenderingcontext.rs10
-rw-r--r--components/script/dom/webglshader.rs3
11 files changed, 85 insertions, 29 deletions
diff --git a/Cargo.lock b/Cargo.lock
index bc7eb3b2151..9679e5083a8 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -438,7 +438,6 @@ dependencies = [
"lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"malloc_size_of 0.0.1",
"malloc_size_of_derive 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
- "offscreen_gl_context 0.22.0 (registry+https://github.com/rust-lang/crates.io-index)",
"pixels 0.0.1",
"serde 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_bytes 0.10.4 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -3453,7 +3452,6 @@ dependencies = [
"msg 0.0.1",
"net_traits 0.0.1",
"num-traits 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)",
- "offscreen_gl_context 0.22.0 (registry+https://github.com/rust-lang/crates.io-index)",
"parking_lot 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)",
"phf 0.7.23 (registry+https://github.com/rust-lang/crates.io-index)",
"phf_codegen 0.7.23 (registry+https://github.com/rust-lang/crates.io-index)",
diff --git a/components/canvas/gl_context.rs b/components/canvas/gl_context.rs
index 281c78b7f3b..46434c24e81 100644
--- a/components/canvas/gl_context.rs
+++ b/components/canvas/gl_context.rs
@@ -3,14 +3,17 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
use super::webgl_thread::{GLState, WebGLImpl};
-use canvas_traits::webgl::{WebGLCommand, WebGLCommandBacktrace, WebGLVersion};
+use canvas_traits::webgl::{
+ GLContextAttributes, GLLimits, WebGLCommand, WebGLCommandBacktrace, WebGLVersion,
+};
use compositing::compositor_thread::{self, CompositorProxy};
use euclid::Size2D;
use gleam::gl;
use offscreen_gl_context::{
- ColorAttachmentType, DrawBuffer, GLContext, GLContextAttributes, GLContextDispatcher,
+ ColorAttachmentType, DrawBuffer, GLContext, GLContextAttributes as RawGLContextAttributes,
+ GLContextDispatcher,
};
-use offscreen_gl_context::{GLLimits, GLVersion};
+use offscreen_gl_context::{GLLimits as RawGLLimits, GLVersion};
use offscreen_gl_context::{NativeGLContext, NativeGLContextHandle, NativeGLContextMethods};
use offscreen_gl_context::{OSMesaContext, OSMesaContextHandle};
use std::sync::{Arc, Mutex};
@@ -52,6 +55,7 @@ impl GLContextFactory {
size: Size2D<u32>,
attributes: GLContextAttributes,
) -> Result<GLContextWrapper, &'static str> {
+ let attributes = map_attrs(attributes);
Ok(match *self {
GLContextFactory::Native(ref handle, ref dispatcher) => {
let dispatcher = dispatcher.as_ref().map(|d| Box::new(d.clone()) as Box<_>);
@@ -88,6 +92,7 @@ impl GLContextFactory {
size: Size2D<u32>,
attributes: GLContextAttributes,
) -> Result<GLContextWrapper, &'static str> {
+ let attributes = map_attrs(attributes);
Ok(match *self {
GLContextFactory::Native(..) => {
GLContextWrapper::Native(GLContext::new_shared_with_dispatcher(
@@ -189,7 +194,7 @@ impl GLContextWrapper {
let limits = ctx.borrow_limits().clone();
- (real_size, texture_id, limits)
+ (real_size, texture_id, map_limits(limits))
},
GLContextWrapper::OSMesa(ref ctx) => {
let (real_size, texture_id) = {
@@ -202,7 +207,7 @@ impl GLContextWrapper {
let limits = ctx.borrow_limits().clone();
- (real_size, texture_id, limits)
+ (real_size, texture_id, map_limits(limits))
},
}
}
@@ -243,3 +248,40 @@ impl GLContextDispatcher for MainThreadDispatcher {
.send(compositor_thread::Msg::Dispatch(f));
}
}
+
+fn map_limits(limits: RawGLLimits) -> GLLimits {
+ GLLimits {
+ max_vertex_attribs: limits.max_vertex_attribs,
+ max_tex_size: limits.max_tex_size,
+ max_cube_map_tex_size: limits.max_cube_map_tex_size,
+ max_combined_texture_image_units: limits.max_combined_texture_image_units,
+ max_fragment_uniform_vectors: limits.max_fragment_uniform_vectors,
+ max_renderbuffer_size: limits.max_renderbuffer_size,
+ max_texture_image_units: limits.max_texture_image_units,
+ max_varying_vectors: limits.max_varying_vectors,
+ max_vertex_texture_image_units: limits.max_vertex_texture_image_units,
+ max_vertex_uniform_vectors: limits.max_vertex_uniform_vectors,
+ }
+}
+
+pub fn map_attrs(attrs: GLContextAttributes) -> RawGLContextAttributes {
+ RawGLContextAttributes {
+ alpha: attrs.alpha,
+ depth: attrs.depth,
+ stencil: attrs.stencil,
+ antialias: attrs.antialias,
+ premultiplied_alpha: attrs.premultiplied_alpha,
+ preserve_drawing_buffer: attrs.preserve_drawing_buffer,
+ }
+}
+
+pub fn map_attrs_to_script_attrs(attrs: RawGLContextAttributes) -> GLContextAttributes {
+ GLContextAttributes {
+ alpha: attrs.alpha,
+ depth: attrs.depth,
+ stencil: attrs.stencil,
+ antialias: attrs.antialias,
+ premultiplied_alpha: attrs.premultiplied_alpha,
+ preserve_drawing_buffer: attrs.preserve_drawing_buffer,
+ }
+}
diff --git a/components/canvas/webgl_thread.rs b/components/canvas/webgl_thread.rs
index 7447b4c6b55..57fb99a56db 100644
--- a/components/canvas/webgl_thread.rs
+++ b/components/canvas/webgl_thread.rs
@@ -2,16 +2,14 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
-use super::gl_context::{GLContextFactory, GLContextWrapper};
+use super::gl_context::{map_attrs_to_script_attrs, GLContextFactory, GLContextWrapper};
use byteorder::{ByteOrder, NativeEndian, WriteBytesExt};
use canvas_traits::webgl::*;
use euclid::Size2D;
use fnv::FnvHashMap;
use gleam::gl;
use half::f16;
-use offscreen_gl_context::{
- DrawBuffer, GLContext, GLContextAttributes, GLLimits, NativeGLContextMethods,
-};
+use offscreen_gl_context::{DrawBuffer, GLContext, NativeGLContextMethods};
use pixels::{self, PixelFormat};
use std::borrow::Cow;
use std::thread;
@@ -795,9 +793,9 @@ impl WebGLImpl {
_backtrace: WebGLCommandBacktrace,
) {
match command {
- WebGLCommand::GetContextAttributes(ref sender) => {
- sender.send(*ctx.borrow_attributes()).unwrap()
- },
+ WebGLCommand::GetContextAttributes(ref sender) => sender
+ .send(map_attrs_to_script_attrs(*ctx.borrow_attributes()))
+ .unwrap(),
WebGLCommand::ActiveTexture(target) => ctx.gl().active_texture(target),
WebGLCommand::AttachShader(program_id, shader_id) => {
ctx.gl().attach_shader(program_id.get(), shader_id.get())
diff --git a/components/canvas_traits/Cargo.toml b/components/canvas_traits/Cargo.toml
index 298e1d4740a..6334f4f53ca 100644
--- a/components/canvas_traits/Cargo.toml
+++ b/components/canvas_traits/Cargo.toml
@@ -21,7 +21,6 @@ gleam = "0.6.7"
lazy_static = "1"
malloc_size_of = { path = "../malloc_size_of" }
malloc_size_of_derive = "0.1"
-offscreen_gl_context = {version = "0.22", features = ["serde"]}
pixels = {path = "../pixels"}
serde = "1.0"
serde_bytes = "0.10"
diff --git a/components/canvas_traits/webgl.rs b/components/canvas_traits/webgl.rs
index d3b16f59c78..474ae4b603b 100644
--- a/components/canvas_traits/webgl.rs
+++ b/components/canvas_traits/webgl.rs
@@ -6,7 +6,6 @@ use euclid::{Rect, Size2D};
use gleam::gl;
use gleam::gl::Gl;
use ipc_channel::ipc::{IpcBytesReceiver, IpcBytesSender, IpcSharedMemory};
-use offscreen_gl_context::{GLContextAttributes, GLLimits};
use pixels::PixelFormat;
use std::borrow::Cow;
use std::fmt;
@@ -811,3 +810,27 @@ pub enum YAxisTreatment {
AsIs,
Flipped,
}
+
+#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
+pub struct GLContextAttributes {
+ pub alpha: bool,
+ pub depth: bool,
+ pub stencil: bool,
+ pub antialias: bool,
+ pub premultiplied_alpha: bool,
+ pub preserve_drawing_buffer: bool,
+}
+
+#[derive(Clone, Debug, Deserialize, Serialize)]
+pub struct GLLimits {
+ pub max_vertex_attribs: u32,
+ pub max_tex_size: u32,
+ pub max_cube_map_tex_size: u32,
+ pub max_combined_texture_image_units: u32,
+ pub max_fragment_uniform_vectors: u32,
+ pub max_renderbuffer_size: u32,
+ pub max_texture_image_units: u32,
+ pub max_varying_vectors: u32,
+ pub max_vertex_texture_image_units: u32,
+ pub max_vertex_uniform_vectors: u32,
+}
diff --git a/components/script/Cargo.toml b/components/script/Cargo.toml
index 4ece839fdc6..b73a1bee28c 100644
--- a/components/script/Cargo.toml
+++ b/components/script/Cargo.toml
@@ -77,7 +77,6 @@ mime_guess = "2.0.0-alpha.6"
msg = {path = "../msg"}
net_traits = {path = "../net_traits"}
num-traits = "0.2"
-offscreen_gl_context = {version = "0.22", features = ["serde"]}
parking_lot = "0.6"
phf = "0.7.18"
pixels = {path = "../pixels"}
diff --git a/components/script/dom/bindings/trace.rs b/components/script/dom/bindings/trace.rs
index 115ea0d4b28..8216d8c6a71 100644
--- a/components/script/dom/bindings/trace.rs
+++ b/components/script/dom/bindings/trace.rs
@@ -45,6 +45,7 @@ use canvas_traits::canvas::{
CanvasGradientStop, CanvasId, LinearGradientStyle, RadialGradientStyle,
};
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::{WebGLBufferId, WebGLChan, WebGLContextShareMode, WebGLError};
use canvas_traits::webgl::{WebGLFramebufferId, WebGLMsgSender, WebGLPipeline, WebGLProgramId};
@@ -82,7 +83,6 @@ use net_traits::response::HttpsState;
use net_traits::response::{Response, ResponseBody};
use net_traits::storage_thread::StorageType;
use net_traits::{Metadata, NetworkError, ReferrerPolicy, ResourceFetchTiming, ResourceThreads};
-use offscreen_gl_context::GLLimits;
use profile_traits::mem::ProfilerChan as MemProfilerChan;
use profile_traits::time::ProfilerChan as TimeProfilerChan;
use script_layout_interface::rpc::LayoutRPC;
diff --git a/components/script/dom/htmlcanvaselement.rs b/components/script/dom/htmlcanvaselement.rs
index f0f3f446157..c9ccdd9ad56 100644
--- a/components/script/dom/htmlcanvaselement.rs
+++ b/components/script/dom/htmlcanvaselement.rs
@@ -30,7 +30,7 @@ use crate::dom::webglrenderingcontext::{
};
use base64;
use canvas_traits::canvas::{CanvasId, CanvasMsg, FromScriptMsg};
-use canvas_traits::webgl::WebGLVersion;
+use canvas_traits::webgl::{GLContextAttributes, WebGLVersion};
use dom_struct::dom_struct;
use euclid::{Rect, Size2D};
use html5ever::{LocalName, Prefix};
@@ -40,7 +40,6 @@ use ipc_channel::ipc::IpcSharedMemory;
use js::error::throw_type_error;
use js::jsapi::JSContext;
use js::rust::HandleValue;
-use offscreen_gl_context::GLContextAttributes;
use profile_traits::ipc;
use script_layout_interface::{HTMLCanvasData, HTMLCanvasDataSource};
use servo_config::prefs::PREFS;
diff --git a/components/script/dom/webgl2renderingcontext.rs b/components/script/dom/webgl2renderingcontext.rs
index 2196ae4f693..98056104848 100644
--- a/components/script/dom/webgl2renderingcontext.rs
+++ b/components/script/dom/webgl2renderingcontext.rs
@@ -30,14 +30,13 @@ use crate::dom::webgltexture::WebGLTexture;
use crate::dom::webgluniformlocation::WebGLUniformLocation;
use crate::dom::window::Window;
/// https://www.khronos.org/registry/webgl/specs/latest/2.0/webgl.idl
-use canvas_traits::webgl::WebGLVersion;
+use canvas_traits::webgl::{GLContextAttributes, WebGLVersion};
use dom_struct::dom_struct;
use euclid::Size2D;
use js::jsapi::{JSContext, JSObject};
use js::jsval::JSVal;
use js::rust::CustomAutoRooterGuard;
use js::typedarray::ArrayBufferView;
-use offscreen_gl_context::GLContextAttributes;
use script_layout_interface::HTMLCanvasDataSource;
use std::ptr::NonNull;
diff --git a/components/script/dom/webglrenderingcontext.rs b/components/script/dom/webglrenderingcontext.rs
index 413d4d5a8cd..022f78a4644 100644
--- a/components/script/dom/webglrenderingcontext.rs
+++ b/components/script/dom/webglrenderingcontext.rs
@@ -50,10 +50,11 @@ use crate::dom::window::Window;
use backtrace::Backtrace;
use canvas_traits::webgl::WebGLError::*;
use canvas_traits::webgl::{
- webgl_channel, AlphaTreatment, DOMToTextureCommand, Parameter, TexDataType, TexFormat,
- TexParameter, WebGLCommand, WebGLCommandBacktrace, WebGLContextShareMode, WebGLError,
- WebGLFramebufferBindingRequest, WebGLMsg, WebGLMsgSender, WebGLProgramId, WebGLResult,
- WebGLSLVersion, WebGLSender, WebGLVersion, WebVRCommand, YAxisTreatment,
+ webgl_channel, AlphaTreatment, DOMToTextureCommand, GLContextAttributes, GLLimits, Parameter,
+ TexDataType, TexFormat, TexParameter, WebGLCommand, WebGLCommandBacktrace,
+ WebGLContextShareMode, WebGLError, WebGLFramebufferBindingRequest, WebGLMsg, WebGLMsgSender,
+ WebGLProgramId, WebGLResult, WebGLSLVersion, WebGLSender, WebGLVersion, WebVRCommand,
+ YAxisTreatment,
};
use dom_struct::dom_struct;
use euclid::{Point2D, Rect, Size2D};
@@ -67,7 +68,6 @@ use js::typedarray::{
};
use js::typedarray::{TypedArray, TypedArrayElementCreator};
use net_traits::image_cache::ImageResponse;
-use offscreen_gl_context::{GLContextAttributes, GLLimits};
use pixels::{self, PixelFormat};
use script_layout_interface::HTMLCanvasDataSource;
use serde::{Deserialize, Serialize};
diff --git a/components/script/dom/webglshader.rs b/components/script/dom/webglshader.rs
index 8f53267b50b..9ee44bb8be9 100644
--- a/components/script/dom/webglshader.rs
+++ b/components/script/dom/webglshader.rs
@@ -15,11 +15,10 @@ 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::{WebGLCommand, WebGLError};
+use canvas_traits::webgl::{GLLimits, WebGLCommand, WebGLError};
use canvas_traits::webgl::{WebGLResult, WebGLSLVersion, WebGLShaderId};
use dom_struct::dom_struct;
use mozangle::shaders::{BuiltInResources, Output, ShaderValidator};
-use offscreen_gl_context::GLLimits;
use std::cell::Cell;
use std::os::raw::c_int;
use std::sync::{Once, ONCE_INIT};