Skip to content

Commit

Permalink
Auto merge of #24176 - jdm:no-gleam, r=<try>
Browse files Browse the repository at this point in the history
Replace use of gleam in webgl with sparkle.

Rely on https://github.com/servo/sparkle for the GL bindings required to implement Servo's WebGL stack. This does not touch the GL usage in the compositor or webrender, which continue to rely on https://github.com/servo/gleam. This means that any breaking changes to the public GL bindings interface (such as required by #24111) only require updating rust-offscreen-rendering-context and rust-webvr, rather than many other crates that are out of our direct control.

---
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] There are tests for these changes

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/24176)
<!-- Reviewable:end -->
  • Loading branch information
bors-servo committed Sep 10, 2019
2 parents ec1da1d + 0fb0c00 commit c6b3829
Show file tree
Hide file tree
Showing 17 changed files with 110 additions and 75 deletions.
78 changes: 55 additions & 23 deletions Cargo.lock

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions Cargo.toml
Expand Up @@ -28,3 +28,6 @@ opt-level = 3
# Those are here to dedupe winapi since mio is still using winapi 0.2.
mio = { git = "https://github.com/servo/mio.git", branch = "servo" }
iovec = { git = "https://github.com/servo/iovec.git", branch = "servo" }
rust-webvr = { git = "https://github.com/servo/rust-webvr", branch = "shine" }
rust-webvr-api = { git = "https://github.com/servo/rust-webvr", branch = "shine" }
offscreen_gl_context = { git = "https://github.com/jdm/rust-offscreen-rendering-context", branch = "no-gleam" }
3 changes: 2 additions & 1 deletion components/canvas/Cargo.toml
Expand Up @@ -29,11 +29,12 @@ half = "1"
ipc-channel = "0.12"
log = "0.4"
num-traits = "0.2"
offscreen_gl_context = {version = "0.23", features = ["serde", "osmesa"]}
offscreen_gl_context = {version = "0.25", features = ["serde", "osmesa"]}
raqote = {git = "https://github.com/jrmuizel/raqote", optional = true}
pixels = {path = "../pixels"}
serde_bytes = "0.10"
servo_config = {path = "../config"}
sparkle = "0.1"
webrender = {git = "https://github.com/servo/webrender"}
webrender_api = {git = "https://github.com/servo/webrender", features = ["ipc"]}
webrender_traits = {path = "../webrender_traits"}
Expand Down
8 changes: 4 additions & 4 deletions components/canvas/gl_context.rs
Expand Up @@ -7,14 +7,14 @@ use canvas_traits::webgl::{
GLContextAttributes, GLLimits, WebGLCommand, WebGLCommandBacktrace, WebGLVersion,
};
use euclid::default::Size2D;
use gleam::gl;
use offscreen_gl_context::{
ColorAttachmentType, DrawBuffer, GLContext, GLContextAttributes as RawGLContextAttributes,
GLContextDispatcher,
};
use offscreen_gl_context::{GLLimits as RawGLLimits, GLVersion};
use offscreen_gl_context::{NativeGLContext, NativeGLContextHandle, NativeGLContextMethods};
use offscreen_gl_context::{OSMesaContext, OSMesaContextHandle};
use sparkle::gl;

pub trait CloneableDispatcher: GLContextDispatcher {
fn clone(&self) -> Box<dyn GLContextDispatcher>;
Expand Down Expand Up @@ -84,7 +84,7 @@ impl GLContextFactory {
size.to_i32(),
attributes,
ColorAttachmentType::Texture,
gl::GlType::default(),
gl::GlType::Gl,
Self::gl_version(webgl_version),
Some(handle),
None,
Expand Down Expand Up @@ -120,7 +120,7 @@ impl GLContextFactory {
size.to_i32(),
attributes,
ColorAttachmentType::Texture,
gl::GlType::default(),
gl::GlType::Gl,
Self::gl_version(webgl_version),
None,
None,
Expand Down Expand Up @@ -171,7 +171,7 @@ impl GLContextWrapper {
}
}

pub fn gl(&self) -> &dyn gl::Gl {
pub fn gl(&self) -> &gl::Gl {
match *self {
GLContextWrapper::Native(ref ctx) => ctx.gl(),
GLContextWrapper::OSMesa(ref ctx) => ctx.gl(),
Expand Down
45 changes: 20 additions & 25 deletions components/canvas/webgl_thread.rs
Expand Up @@ -8,12 +8,12 @@ use canvas_traits::webgl::*;
use embedder_traits::EventLoopWaker;
use euclid::default::Size2D;
use fnv::FnvHashMap;
use gleam::gl;
use half::f16;
use ipc_channel::ipc::{self, OpaqueIpcMessage};
use ipc_channel::router::ROUTER;
use offscreen_gl_context::{DrawBuffer, GLContext, NativeGLContextMethods};
use pixels::{self, PixelFormat};
use sparkle::gl;
use std::borrow::Cow;
use std::cell::Cell;
use std::cell::RefCell;
Expand Down Expand Up @@ -1573,7 +1573,7 @@ impl WebGLImpl {
}

fn initialize_framebuffer(
gl: &dyn gl::Gl,
gl: &gl::Gl,
state: &GLState,
color: bool,
depth: bool,
Expand Down Expand Up @@ -1633,7 +1633,7 @@ impl WebGLImpl {
}

#[allow(unsafe_code)]
fn link_program(gl: &dyn gl::Gl, program: WebGLProgramId) -> ProgramLinkInfo {
fn link_program(gl: &gl::Gl, program: WebGLProgramId) -> ProgramLinkInfo {
gl.link_program(program.get());
let mut linked = [0];
unsafe {
Expand Down Expand Up @@ -1706,13 +1706,13 @@ impl WebGLImpl {
}
}

fn finish(gl: &dyn gl::Gl, chan: &WebGLSender<()>) {
fn finish(gl: &gl::Gl, chan: &WebGLSender<()>) {
gl.finish();
chan.send(()).unwrap();
}

fn shader_precision_format(
gl: &dyn gl::Gl,
gl: &gl::Gl,
shader_type: u32,
precision_type: u32,
chan: &WebGLSender<(i32, i32, i32)>,
Expand All @@ -1722,7 +1722,7 @@ impl WebGLImpl {
}

#[allow(unsafe_code)]
fn get_extensions(gl: &dyn gl::Gl, chan: &WebGLSender<String>) {
fn get_extensions(gl: &gl::Gl, chan: &WebGLSender<String>) {
let mut ext_count = [0];
unsafe {
gl.get_integer_v(gl::NUM_EXTENSIONS, &mut ext_count);
Expand All @@ -1743,7 +1743,7 @@ impl WebGLImpl {

// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.6
fn get_framebuffer_attachment_parameter(
gl: &dyn gl::Gl,
gl: &gl::Gl,
target: u32,
attachment: u32,
pname: u32,
Expand All @@ -1754,18 +1754,13 @@ impl WebGLImpl {
}

// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.7
fn get_renderbuffer_parameter(
gl: &dyn gl::Gl,
target: u32,
pname: u32,
chan: &WebGLSender<i32>,
) {
fn get_renderbuffer_parameter(gl: &gl::Gl, target: u32, pname: u32, chan: &WebGLSender<i32>) {
let parameter = gl.get_renderbuffer_parameter_iv(target, pname);
chan.send(parameter).unwrap();
}

fn uniform_location(
gl: &dyn gl::Gl,
gl: &gl::Gl,
program_id: WebGLProgramId,
name: &str,
chan: &WebGLSender<i32>,
Expand All @@ -1775,18 +1770,18 @@ impl WebGLImpl {
chan.send(location).unwrap();
}

fn shader_info_log(gl: &dyn gl::Gl, shader_id: WebGLShaderId, chan: &WebGLSender<String>) {
fn shader_info_log(gl: &gl::Gl, shader_id: WebGLShaderId, chan: &WebGLSender<String>) {
let log = gl.get_shader_info_log(shader_id.get());
chan.send(log).unwrap();
}

fn program_info_log(gl: &dyn gl::Gl, program_id: WebGLProgramId, chan: &WebGLSender<String>) {
fn program_info_log(gl: &gl::Gl, program_id: WebGLProgramId, chan: &WebGLSender<String>) {
let log = gl.get_program_info_log(program_id.get());
chan.send(log).unwrap();
}

#[allow(unsafe_code)]
fn create_buffer(gl: &dyn gl::Gl, chan: &WebGLSender<Option<WebGLBufferId>>) {
fn create_buffer(gl: &gl::Gl, chan: &WebGLSender<Option<WebGLBufferId>>) {
let buffer = gl.gen_buffers(1)[0];
let buffer = if buffer == 0 {
None
Expand All @@ -1797,7 +1792,7 @@ impl WebGLImpl {
}

#[allow(unsafe_code)]
fn create_framebuffer(gl: &dyn gl::Gl, chan: &WebGLSender<Option<WebGLFramebufferId>>) {
fn create_framebuffer(gl: &gl::Gl, chan: &WebGLSender<Option<WebGLFramebufferId>>) {
let framebuffer = gl.gen_framebuffers(1)[0];
let framebuffer = if framebuffer == 0 {
None
Expand All @@ -1808,7 +1803,7 @@ impl WebGLImpl {
}

#[allow(unsafe_code)]
fn create_renderbuffer(gl: &dyn gl::Gl, chan: &WebGLSender<Option<WebGLRenderbufferId>>) {
fn create_renderbuffer(gl: &gl::Gl, chan: &WebGLSender<Option<WebGLRenderbufferId>>) {
let renderbuffer = gl.gen_renderbuffers(1)[0];
let renderbuffer = if renderbuffer == 0 {
None
Expand All @@ -1819,7 +1814,7 @@ impl WebGLImpl {
}

#[allow(unsafe_code)]
fn create_texture(gl: &dyn gl::Gl, chan: &WebGLSender<Option<WebGLTextureId>>) {
fn create_texture(gl: &gl::Gl, chan: &WebGLSender<Option<WebGLTextureId>>) {
let texture = gl.gen_textures(1)[0];
let texture = if texture == 0 {
None
Expand All @@ -1830,7 +1825,7 @@ impl WebGLImpl {
}

#[allow(unsafe_code)]
fn create_program(gl: &dyn gl::Gl, chan: &WebGLSender<Option<WebGLProgramId>>) {
fn create_program(gl: &gl::Gl, chan: &WebGLSender<Option<WebGLProgramId>>) {
let program = gl.create_program();
let program = if program == 0 {
None
Expand All @@ -1841,7 +1836,7 @@ impl WebGLImpl {
}

#[allow(unsafe_code)]
fn create_shader(gl: &dyn gl::Gl, shader_type: u32, chan: &WebGLSender<Option<WebGLShaderId>>) {
fn create_shader(gl: &gl::Gl, shader_type: u32, chan: &WebGLSender<Option<WebGLShaderId>>) {
let shader = gl.create_shader(shader_type);
let shader = if shader == 0 {
None
Expand All @@ -1852,7 +1847,7 @@ impl WebGLImpl {
}

#[allow(unsafe_code)]
fn create_vertex_array(gl: &dyn gl::Gl, chan: &WebGLSender<Option<WebGLVertexArrayId>>) {
fn create_vertex_array(gl: &gl::Gl, chan: &WebGLSender<Option<WebGLVertexArrayId>>) {
let vao = gl.gen_vertex_arrays(1)[0];
let vao = if vao == 0 {
None
Expand All @@ -1864,7 +1859,7 @@ impl WebGLImpl {

#[inline]
fn bind_framebuffer<Native: NativeGLContextMethods>(
gl: &dyn gl::Gl,
gl: &gl::Gl,
target: u32,
request: WebGLFramebufferBindingRequest,
ctx: &GLContext<Native>,
Expand All @@ -1880,7 +1875,7 @@ impl WebGLImpl {
}

#[inline]
fn compile_shader(gl: &dyn gl::Gl, shader_id: WebGLShaderId, source: &str) {
fn compile_shader(gl: &gl::Gl, shader_id: WebGLShaderId, source: &str) {
gl.shader_source(shader_id.get(), &[source.as_bytes()]);
gl.compile_shader(shader_id.get());
}
Expand Down
2 changes: 1 addition & 1 deletion components/canvas_traits/Cargo.toml
Expand Up @@ -17,14 +17,14 @@ webgl_backtrace = []
cssparser = "0.25"
euclid = "0.20"
ipc-channel = "0.12"
gleam = "0.6.7"
lazy_static = "1"
malloc_size_of = { path = "../malloc_size_of" }
malloc_size_of_derive = "0.1"
pixels = {path = "../pixels"}
serde = "1.0"
serde_bytes = "0.10"
servo_config = {path = "../config"}
sparkle = "0.1"
typetag = "0.1"
webrender_api = {git = "https://github.com/servo/webrender", features = ["ipc"]}
webvr_traits = {path = "../webvr_traits"}
Expand Down
10 changes: 5 additions & 5 deletions components/canvas_traits/webgl.rs
Expand Up @@ -3,10 +3,10 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */

use euclid::default::{Rect, Size2D};
use gleam::gl;
use gleam::gl::Gl;
use ipc_channel::ipc::{IpcBytesReceiver, IpcBytesSender, IpcSharedMemory};
use pixels::PixelFormat;
use sparkle::gl;
use sparkle::gl::Gl;
use std::borrow::Cow;
use std::fmt;
use std::num::NonZeroU32;
Expand Down Expand Up @@ -549,7 +549,7 @@ pub enum WebVRCommand {
// Trait object that handles WebVR commands.
// Receives the texture id and size associated to the WebGLContext.
pub trait WebVRRenderHandler: Send {
fn handle(&mut self, gl: &dyn Gl, command: WebVRCommand, texture: Option<(u32, Size2D<i32>)>);
fn handle(&mut self, gl: &Gl, command: WebVRCommand, texture: Option<(u32, Size2D<i32>)>);
}

/// WebGL commands required to implement DOMToTexture feature.
Expand Down Expand Up @@ -758,9 +758,9 @@ macro_rules! gl_enums {
}
}

// FIXME: These should come from gleam
// FIXME: These should come from sparkle
mod gl_ext_constants {
use gleam::gl::types::GLenum;
use sparkle::gl::types::GLenum;

pub const COMPRESSED_RGB_S3TC_DXT1_EXT: GLenum = 0x83F0;
pub const COMPRESSED_RGBA_S3TC_DXT1_EXT: GLenum = 0x83F1;
Expand Down
3 changes: 2 additions & 1 deletion components/script/Cargo.toml
Expand Up @@ -52,7 +52,7 @@ encoding_rs = "0.8"
enum-iterator = "0.2.0"
euclid = "0.20"
fnv = "1.0"
gleam = "0.6"
#gleam = "0.6"
headers = "0.2"
html5ever = "0.23"
http = "0.1"
Expand Down Expand Up @@ -100,6 +100,7 @@ servo_geometry = {path = "../geometry" }
servo-media = {git = "https://github.com/servo/media"}
servo_rand = {path = "../rand"}
servo_url = {path = "../url"}
sparkle = "0.1"
smallvec = { version = "0.6", features = ["std", "union"] }
style = {path = "../style", features = ["servo"]}
style_traits = {path = "../style_traits"}
Expand Down
2 changes: 1 addition & 1 deletion components/script/dom/webgl_extensions/extensions.rs
Expand Up @@ -20,9 +20,9 @@ use crate::dom::webglrenderingcontext::WebGLRenderingContext;
use crate::dom::webgltexture::TexCompression;
use canvas_traits::webgl::{GlType, WebGLVersion};
use fnv::{FnvHashMap, FnvHashSet};
use gleam::gl::{self, GLenum};
use js::jsapi::JSObject;
use malloc_size_of::MallocSizeOf;
use sparkle::gl::{self, GLenum};
use std::collections::HashMap;
use std::iter::FromIterator;
use std::ptr::NonNull;
Expand Down
3 changes: 2 additions & 1 deletion components/servo/Cargo.toml
Expand Up @@ -62,7 +62,7 @@ media = {path = "../media"}
msg = {path = "../msg"}
net = {path = "../net"}
net_traits = {path = "../net_traits"}
offscreen_gl_context = "0.23"
offscreen_gl_context = "0.25"
profile = {path = "../profile"}
profile_traits = {path = "../profile_traits"}
script = {path = "../script"}
Expand All @@ -72,6 +72,7 @@ servo_config = {path = "../config"}
servo_geometry = {path = "../geometry"}
servo-media = {git = "https://github.com/servo/media"}
servo_url = {path = "../url"}
sparkle = "0.1"
style = {path = "../style", features = ["servo"]}
style_traits = {path = "../style_traits", features = ["servo"]}
webrender = {git = "https://github.com/servo/webrender"}
Expand Down
6 changes: 5 additions & 1 deletion components/servo/lib.rs
Expand Up @@ -412,7 +412,11 @@ where
} else {
let dispatcher =
Box::new(MainThreadDispatcher::new(compositor_proxy.clone())) as Box<_>;
GLContextFactory::current_native_handle(dispatcher, window.gl().get_type())
let gl_type = match window.gl().get_type() {
gl::GlType::Gl => sparkle::gl::GlType::Gl,
gl::GlType::Gles => sparkle::gl::GlType::Gles,
};
GLContextFactory::current_native_handle(dispatcher, gl_type)
};

let (external_image_handlers, external_images) = WebrenderExternalImageHandlers::new();
Expand Down
5 changes: 3 additions & 2 deletions components/webvr/Cargo.toml
Expand Up @@ -22,8 +22,9 @@ gleam = "0.6"
ipc-channel = "0.12"
log = "0.4"
msg = {path = "../msg"}
rust-webvr = { version = "0.14.2", features = ["mock", "openvr", "vrexternal"] }
rust-webvr-api = "0.14"
rust-webvr = {version = "0.16", features = ["mock", "openvr", "vrexternal"]}
rust-webvr-api = "0.16"
script_traits = {path = "../script_traits"}
servo_config = {path = "../config"}
sparkle = "0.1"
webvr_traits = {path = "../webvr_traits" }
9 changes: 2 additions & 7 deletions components/webvr/webvr_thread.rs
Expand Up @@ -5,13 +5,13 @@
use canvas_traits::webgl;
use crossbeam_channel::{unbounded, Receiver, Sender};
use euclid::default::Size2D;
use gleam::gl::Gl;
use ipc_channel::ipc;
use ipc_channel::ipc::{IpcReceiver, IpcSender};
use msg::constellation_msg::PipelineId;
use rust_webvr::VRServiceManager;
use script_traits::ConstellationMsg;
use servo_config::pref;
use sparkle::gl::Gl;
use std::collections::hash_map::Entry;
use std::collections::{HashMap, HashSet};
use std::sync::mpsc;
Expand Down Expand Up @@ -429,12 +429,7 @@ impl WebVRCompositorHandler {

impl webgl::WebVRRenderHandler for WebVRCompositorHandler {
#[allow(unsafe_code)]
fn handle(
&mut self,
gl: &dyn Gl,
cmd: webgl::WebVRCommand,
texture: Option<(u32, Size2D<i32>)>,
) {
fn handle(&mut self, gl: &Gl, cmd: webgl::WebVRCommand, texture: Option<(u32, Size2D<i32>)>) {
match cmd {
webgl::WebVRCommand::Create(compositor_id) => {
if let Some(compositor) = self.create_compositor(compositor_id) {
Expand Down

0 comments on commit c6b3829

Please sign in to comment.