Skip to content
This repository has been archived by the owner on Jul 10, 2023. It is now read-only.

Commit

Permalink
Auto merge of #94 - servo:shine, r=asajeffrey
Browse files Browse the repository at this point in the history
Replace use of gleam in public API

Also clean up some warnings that appear in the nightly compiler.
  • Loading branch information
bors-servo committed Sep 11, 2019
2 parents bbe6e42 + 7ccc50f commit b9e0f20
Show file tree
Hide file tree
Showing 13 changed files with 37 additions and 35 deletions.
4 changes: 2 additions & 2 deletions rust-webvr-api/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "rust-webvr-api"
version = "0.15.0"
version = "0.16.0"
authors = ["The Servo Project Developers"]

homepage = "https://github.com/servo/rust-webvr"
Expand All @@ -20,10 +20,10 @@ serde-serialization = ["serde", "serde_derive"]
ipc = ["serde-serialization", "ipc-channel"]

[dependencies]
gleam = "0.7"
ipc-channel = { version = "0.12", optional = true }
serde = { version = "1.0", optional = true }
serde_derive = { version = "1.0", optional = true }
sparkle = "0.1"
time = { version = "0.1", optional = true }

[target.'cfg(target_os = "android")'.dependencies]
Expand Down
2 changes: 1 addition & 1 deletion rust-webvr-api/src/lib.rs
Expand Up @@ -21,7 +21,7 @@ extern crate serde_derive;
#[cfg(feature = "ipc")]
extern crate ipc_channel;

extern crate gleam;
extern crate sparkle;


pub mod mock;
Expand Down
4 changes: 2 additions & 2 deletions rust-webvr-api/src/utils.rs
Expand Up @@ -23,7 +23,7 @@ pub fn timestamp() -> f64 {
// Multiply 4x4 matrices
#[allow(dead_code)]
pub fn multiply_matrix(a: &[f32; 16], b: &[f32; 16], out: &mut [f32; 16]) {
let mut tmp: [f32; 16] = unsafe { mem::uninitialized() };
let mut tmp: [f32; 16] = [0.; 16];

tmp[0] = b[0] * a[0] + b[1] * a[4] + b[2] * a[8] + b[3] * a[12];
tmp[1] = b[0] * a[1] + b[1] * a[5] + b[2] * a[9] + b[3] * a[13];
Expand Down Expand Up @@ -65,7 +65,7 @@ pub fn inverse_matrix(m: &[f32; 16], out: &mut [f32; 16]) -> bool {

#[allow(dead_code)]
pub fn adjoint_matrix(m: &[f32; 16], out: &mut [f32; 16]) {
let mut tmp: [f32; 16] = unsafe { mem::uninitialized() };
let mut tmp: [f32; 16] = [0.; 16];

tmp[0] = determinant3x3(m[5], m[9], m[13], m[6], m[10], m[14], m[7], m[11], m[15]);
tmp[4] = - determinant3x3(m[4], m[8], m[12], m[6], m[10], m[14], m[7], m[11], m[15]);
Expand Down
8 changes: 4 additions & 4 deletions rust-webvr-api/src/vr_display.rs
@@ -1,8 +1,8 @@
use {VRDisplayData, VRFramebuffer, VRFramebufferAttributes, VRFrameData, VRFutureFrameData, VRGamepadPtr, VRLayer};
use gleam::gl::Gl;
use sparkle::gl::Gl;
use std::sync::Arc;
use std::cell::RefCell;
pub type VRDisplayPtr = Arc<RefCell<VRDisplay>>;
pub type VRDisplayPtr = Arc<RefCell<dyn VRDisplay>>;

/// The VRDisplay traits forms the base of all VR device implementations
pub trait VRDisplay: Send + Sync {
Expand Down Expand Up @@ -79,8 +79,8 @@ pub trait VRDisplay: Send + Sync {
fn stop_present(&mut self) {}
}

impl PartialEq for VRDisplay {
fn eq(&self, other: &VRDisplay) -> bool {
impl PartialEq for dyn VRDisplay {
fn eq(&self, other: &dyn VRDisplay) -> bool {
self.id() == other.id()
}
}
11 changes: 5 additions & 6 deletions rust-webvr-api/src/vr_frame_data.rs
Expand Up @@ -44,21 +44,20 @@ impl VRFrameData {
pub fn to_bytes(&self) -> Vec<u8> {
let mut vec = vec![0u8; mem::size_of::<VRFrameData>()];
unsafe {
ptr::copy_nonoverlapping(mem::transmute(self),
vec.as_mut_ptr(),
ptr::copy_nonoverlapping(self,
vec.as_mut_ptr() as *mut VRFrameData,
mem::size_of::<VRFrameData>());
}
vec
}

pub fn from_bytes(bytes: &[u8]) -> VRFrameData {
unsafe {
let mut result: VRFrameData = mem::uninitialized();
let mut result = mem::MaybeUninit::uninit();
ptr::copy_nonoverlapping(bytes.as_ptr(),
mem::transmute(&mut result),
result.as_mut_ptr() as *mut u8,
mem::size_of::<VRFrameData>());

result
result.assume_init()
}
}
}
2 changes: 1 addition & 1 deletion rust-webvr-api/src/vr_gamepad.rs
Expand Up @@ -2,7 +2,7 @@ use std::sync::Arc;
use std::cell::RefCell;
use VRPose;

pub type VRGamepadPtr = Arc<RefCell<VRGamepad>>;
pub type VRGamepadPtr = Arc<RefCell<dyn VRGamepad>>;

pub trait VRGamepad {
fn id(&self) -> u32;
Expand Down
4 changes: 2 additions & 2 deletions rust-webvr-api/src/vr_service.rs
Expand Up @@ -15,5 +15,5 @@ pub trait VRService: Send {
}

pub trait VRServiceCreator {
fn new_service(&self) -> Box<VRService>;
}
fn new_service(&self) -> Box<dyn VRService>;
}
11 changes: 6 additions & 5 deletions rust-webvr/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "rust-webvr"
version = "0.15.0"
version = "0.16.0"
authors = ["The Servo Project Developers"]

homepage = "https://github.com/servo/rust-webvr"
Expand All @@ -21,22 +21,23 @@ build = "build.rs"
[features]
default = ["vrexternal", "openvr", "mock"]
vrexternal = []
glwindow = ["euclid", "gleam", "glutin"]
glwindow = ["euclid", "gleam", "sparkle", "glutin"]
openvr = ["libloading"]
mock = []
googlevr = ["gvr-sys"]
oculusvr = ["ovr-mobile-sys"]
magicleap = ["euclid", "gleam"]
magicleap = ["euclid", "gleam", "sparkle"]

[dependencies]
rust-webvr-api = { path = "../rust-webvr-api", version = "0.15" }
rust-webvr-api = { path = "../rust-webvr-api", version = "0.16" }
log = "0.4"
gvr-sys = { version = "0.7", optional = true }
ovr-mobile-sys = { version = "0.4", optional = true }
libc = "0.2"
euclid = { version = "0.20", optional = true }
gleam = { version = "0.7", optional = true }
gleam = { version = "0.6", optional = true }
glutin = { version = "0.21", optional = true }
sparkle = { version = "0.1", optional = true }

[target.'cfg(target_os="windows")'.dependencies]
libloading = { version = "0.5", optional = true, default-features = false }
Expand Down
4 changes: 2 additions & 2 deletions rust-webvr/src/api/glwindow/display.rs
Expand Up @@ -2,8 +2,6 @@ use euclid::Angle;
use euclid::default::RigidTransform3D;
use euclid::Trig;
use euclid::Vector3D;
use gleam::gl;
use gleam::gl::Gl;
use rust_webvr_api::utils;
use rust_webvr_api::VRDisplay;
use rust_webvr_api::VRDisplayCapabilities;
Expand All @@ -17,6 +15,8 @@ use rust_webvr_api::VRFramebufferAttributes;
use rust_webvr_api::VRGamepadPtr;
use rust_webvr_api::VRLayer;
use rust_webvr_api::VRViewport;
use sparkle::gl;
use sparkle::gl::Gl;
use std::cell::RefCell;
use std::sync::Arc;
use std::sync::mpsc::Sender;
Expand Down
8 changes: 4 additions & 4 deletions rust-webvr/src/api/magicleap/display.rs
@@ -1,7 +1,3 @@
use gleam::gl;
use gleam::gl::Gl;
use gleam::gl::types::GLint;
use gleam::gl::types::GLuint;
use rust_webvr_api::VRDisplay;
use rust_webvr_api::VRDisplayData;
use rust_webvr_api::VRFrameData;
Expand All @@ -10,6 +6,10 @@ use rust_webvr_api::VRFramebuffer;
use rust_webvr_api::VRFramebufferAttributes;
use rust_webvr_api::VRGamepadPtr;
use rust_webvr_api::VRLayer;
use sparkle::gl;
use sparkle::gl::Gl;
use sparkle::gl::types::GLint;
use sparkle::gl::types::GLuint;
use std::cell::RefCell;
use std::sync::Arc;
use std::sync::mpsc::Sender;
Expand Down
6 changes: 3 additions & 3 deletions rust-webvr/src/api/mock/mod.rs
Expand Up @@ -7,19 +7,19 @@ use std::sync::mpsc::{channel, Sender};
pub struct MockServiceCreator;

impl MockServiceCreator {
pub fn new() -> Box<VRServiceCreator> {
pub fn new() -> Box<dyn VRServiceCreator> {
Box::new(MockServiceCreator)
}

pub fn new_service_with_remote(init: MockVRInit) -> (Box<VRService>, Sender<MockVRControlMsg>) {
pub fn new_service_with_remote(init: MockVRInit) -> (Box<dyn VRService>, Sender<MockVRControlMsg>) {
let (send, rcv) = channel();
let service = service::MockVRService::new_with_receiver(rcv, init);
(Box::new(service), send)
}
}

impl VRServiceCreator for MockServiceCreator {
fn new_service(&self) -> Box<VRService> {
fn new_service(&self) -> Box<dyn VRService> {
Box::new(service::MockVRService::new(Default::default()))
}
}
2 changes: 2 additions & 0 deletions rust-webvr/src/lib.rs
Expand Up @@ -17,6 +17,8 @@ extern crate gleam;
extern crate glutin;
#[cfg(feature = "serde-serialization")]
#[macro_use] extern crate serde_derive;
#[cfg(any(feature = "magicleap", feature = "glwindow"))]
extern crate sparkle;

#[cfg(any(feature = "googlevr", feature= "oculusvr"))]
mod gl {
Expand Down
6 changes: 3 additions & 3 deletions rust-webvr/src/vr_manager.rs
Expand Up @@ -30,7 +30,7 @@ use api::VRExternalServiceCreator;
// Single entry point all the VRServices and displays
pub struct VRServiceManager {
initialized: bool,
services: Vec<Box<VRService>>,
services: Vec<Box<dyn VRService>>,
displays: HashMap<u32, VRDisplayPtr>,
gamepads: HashMap<u32, VRGamepadPtr>
}
Expand All @@ -57,7 +57,7 @@ impl VRServiceManager {

// Register default VR services specified in crate's features
pub fn register_defaults(&mut self) {
let creators: Vec<Box<VRServiceCreator>> = vec!(
let creators: Vec<Box<dyn VRServiceCreator>> = vec!(
#[cfg(target_os = "windows")]
#[cfg(feature = "openvr")]
OpenVRServiceCreator::new(),
Expand Down Expand Up @@ -107,7 +107,7 @@ impl VRServiceManager {
}

// Register a new VR service
pub fn register(&mut self, service: Box<VRService>) {
pub fn register(&mut self, service: Box<dyn VRService>) {
self.services.push(service);
}

Expand Down

0 comments on commit b9e0f20

Please sign in to comment.