Skip to content

Commit

Permalink
Split simpleservo into 3 crates for rust, c and jni apis
Browse files Browse the repository at this point in the history
  • Loading branch information
paulrouget committed Dec 28, 2018
1 parent 4434445 commit 16a00a1
Show file tree
Hide file tree
Showing 13 changed files with 174 additions and 105 deletions.
49 changes: 33 additions & 16 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
@@ -1,7 +1,8 @@
[workspace]
members = [
"ports/servo",
"ports/libsimpleservo/",
"ports/libsimpleservo/capi/",
"ports/libsimpleservo/jniapi/",
"ports/libmlservo/",
"tests/unit/*",
]
Expand Down
@@ -1,28 +1,16 @@
[package]
name = "libsimpleservo"
name = "simpleservo"
version = "0.0.1"
build = "build.rs"
authors = ["The Servo Project Developers"]
license = "MPL-2.0"
edition = "2018"
publish = false

[lib]
name = "simpleservo"
crate-type = ["cdylib"]
test = false
bench = false

[dependencies]
libservo = { path = "../../components/servo" }
libservo = { path = "../../../components/servo" }
log = "0.4"
serde_json = "1.0"

[target.'cfg(target_os = "android")'.dependencies]
android_injected_glue = "0.2"
android_logger = "0.7"
jni = "0.10.2"

[target.'cfg(not(target_os = "macos"))'.dependencies]
libc = "0.2"

Expand All @@ -31,7 +19,6 @@ winapi = "0.3.2"

[build-dependencies]
gl_generator = "0.10"
cc = "1.0"

[features]
default = ["unstable", "default-except-unstable"]
Expand Down
28 changes: 28 additions & 0 deletions ports/libsimpleservo/api/build.rs
@@ -0,0 +1,28 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* 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 gl_generator::{Api, Fallbacks, Profile, Registry};
use std::env;
use std::fs::File;
use std::path::Path;

fn main() {
let target = env::var("TARGET").unwrap();
// Generate GL bindings
// For now, we only support EGL, and only on Windows and Android.
if target.contains("android") || target.contains("windows") {
let dest = env::var("OUT_DIR").unwrap();
let mut file = File::create(&Path::new(&dest).join("egl_bindings.rs")).unwrap();
if target.contains("android") {
Registry::new(Api::Egl, (1, 5), Profile::Core, Fallbacks::All, [])
.write_bindings(gl_generator::StaticStructGenerator, &mut file)
.unwrap();
}
if target.contains("windows") {
Registry::new(Api::Egl, (1, 5), Profile::Core, Fallbacks::All, [])
.write_bindings(gl_generator::StructGenerator, &mut file)
.unwrap();
};
}
}
Expand Up @@ -2,14 +2,17 @@
* 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 std::rc::Rc;

pub type ServoGl = Rc<dyn servo::gl::Gl>;

#[cfg(any(target_os = "android", target_os = "windows"))]
#[allow(non_camel_case_types)]
pub mod egl {
use servo::gl::{Gl, GlesFns};
use servo::gl::GlesFns;
use std::ffi::CString;
#[cfg(not(target_os = "windows"))]
use std::os::raw::c_void;
use std::rc::Rc;
#[cfg(target_os = "windows")]
use winapi::um::libloaderapi::{GetProcAddress, LoadLibraryA};

Expand Down Expand Up @@ -39,7 +42,7 @@ pub mod egl {
include!(concat!(env!("OUT_DIR"), "/egl_bindings.rs"));

#[cfg(target_os = "android")]
pub fn init() -> Result<Rc<Gl>, &'static str> {
pub fn init() -> Result<crate::gl_glue::ServoGl, &'static str> {
info!("Loading EGL...");
unsafe {
let egl = Egl;
Expand Down Expand Up @@ -84,9 +87,7 @@ pub mod egl {
target_os = "macos"
))]
pub mod gl {
use servo::gl::Gl;
use std::rc::Rc;
pub fn init() -> Result<Rc<dyn Gl>, &'static str> {
pub fn init() -> Result<crate::gl_glue::ServoGl, &'static str> {
// FIXME: Add an OpenGL version
unimplemented!()
}
Expand Down
Expand Up @@ -2,6 +2,11 @@
* 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/. */

#[macro_use]
extern crate log;

pub mod gl_glue;

use servo::compositing::windowing::{
AnimationState, EmbedderCoordinates, MouseWindowEvent, WindowEvent, WindowMethods,
};
Expand Down
31 changes: 31 additions & 0 deletions ports/libsimpleservo/capi/Cargo.toml
@@ -0,0 +1,31 @@
[package]
name = "simpleservo_capi"
version = "0.0.1"
authors = ["The Servo Project Developers"]
license = "MPL-2.0"
edition = "2018"
publish = false

[lib]
name = "simpleservo"
crate-type = ["cdylib"]
test = false
bench = false

[dependencies]
simpleservo = { path = "../api" }
log = "0.4"

[features]
default = ["unstable", "default-except-unstable"]
default-except-unstable = ["webdriver", "max_log_level"]
max_log_level = ["simpleservo/max_log_level"]
webdriver = ["simpleservo/webdriver"]
energy-profiling = ["simpleservo/energy-profiling"]
debugmozjs = ["simpleservo/debugmozjs"]
unstable = ["simpleservo/unstable"]
googlevr = ["simpleservo/googlevr"]
oculusvr = ["simpleservo/oculusvr"]
native-bluetooth = ["simpleservo/native-bluetooth"]
webgl_backtrace = ["simpleservo/webgl_backtrace"]
js_backtrace = ["simpleservo/js_backtrace"]
Expand Up @@ -2,13 +2,15 @@
* 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 crate::api::{self, EventLoopWaker, HostTrait, InitOptions, ReadFileTrait, ServoGlue, SERVO};
use crate::gl_glue;
use servo::gl;
#[macro_use]
extern crate log;

use simpleservo::{
self, gl_glue, EventLoopWaker, HostTrait, InitOptions, ReadFileTrait, ServoGlue, SERVO,
};
use std::ffi::{CStr, CString};
use std::mem;
use std::os::raw::c_char;
use std::rc::Rc;

fn call<F>(f: F)
where
Expand Down Expand Up @@ -55,7 +57,7 @@ pub struct CInitOptions {
/// The returned string is not freed. This will leak.
#[no_mangle]
pub extern "C" fn servo_version() -> *const c_char {
let v = api::servo_version();
let v = simpleservo::servo_version();
let text = CString::new(v).expect("Can't create string");
let ptr = text.as_ptr();
mem::forget(text);
Expand All @@ -64,7 +66,7 @@ pub extern "C" fn servo_version() -> *const c_char {

fn init(
opts: CInitOptions,
gl: Rc<dyn gl::Gl>,
gl: gl_glue::ServoGl,
wakeup: extern "C" fn(),
readfile: extern "C" fn(*const c_char) -> *const c_char,
callbacks: CHostCallbacks,
Expand All @@ -88,7 +90,7 @@ fn init(
let readfile = Box::new(ReadFileCallback::new(readfile));
let callbacks = Box::new(HostCallbacks::new(callbacks));

api::init(opts, gl, wakeup, readfile, callbacks).unwrap();
simpleservo::init(opts, gl, wakeup, readfile, callbacks).unwrap();
}

#[cfg(target_os = "windows")]
Expand Down Expand Up @@ -122,7 +124,7 @@ pub extern "C" fn init_with_gl(
#[no_mangle]
pub extern "C" fn deinit() {
debug!("deinit");
api::deinit();
simpleservo::deinit();
}

#[no_mangle]
Expand Down
39 changes: 39 additions & 0 deletions ports/libsimpleservo/jniapi/Cargo.toml
@@ -0,0 +1,39 @@
[package]
name = "simpleservo_jniapi"
version = "0.0.1"
build = "build.rs"
authors = ["The Servo Project Developers"]
license = "MPL-2.0"
edition = "2018"
publish = false

[lib]
name = "simpleservo"
crate-type = ["cdylib"]
test = false
bench = false

[dependencies]
android_injected_glue = "0.2"
android_logger = "0.7"
jni = "0.10.2"
log = "0.4"
simpleservo = { path = "../api" }
libc = "0.2"

[build-dependencies]
cc = "1.0"

[features]
default = ["unstable", "default-except-unstable"]
default-except-unstable = ["webdriver", "max_log_level"]
max_log_level = ["simpleservo/max_log_level"]
webdriver = ["simpleservo/webdriver"]
energy-profiling = ["simpleservo/energy-profiling"]
debugmozjs = ["simpleservo/debugmozjs"]
unstable = ["simpleservo/unstable"]
googlevr = ["simpleservo/googlevr"]
oculusvr = ["simpleservo/oculusvr"]
native-bluetooth = ["simpleservo/native-bluetooth"]
webgl_backtrace = ["simpleservo/webgl_backtrace"]
js_backtrace = ["simpleservo/js_backtrace"]
Expand Up @@ -2,20 +2,10 @@
* 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 gl_generator::{Api, Fallbacks, Profile, Registry};
use std::env;
use std::fs::File;
use std::path::Path;

fn main() {
let target = env::var("TARGET").unwrap();
if target.contains("android") {
android_main()
}
generate_gl_bindings(&target);
}

fn android_main() {
// Get the NDK path from NDK_HOME env.
let ndk_path =
env::var_os("ANDROID_NDK").expect("Please set the ANDROID_NDK environment variable");
Expand All @@ -41,21 +31,3 @@ fn android_main() {
println!("cargo:rustc-link-lib=log");
println!("cargo:rustc-link-lib=android");
}

fn generate_gl_bindings(target: &str) {
// For now, we only support EGL, and only on Windows and Android.
if target.contains("android") || target.contains("windows") {
let dest = env::var("OUT_DIR").unwrap();
let mut file = File::create(&Path::new(&dest).join("egl_bindings.rs")).unwrap();
if target.contains("android") {
Registry::new(Api::Egl, (1, 5), Profile::Core, Fallbacks::All, [])
.write_bindings(gl_generator::StaticStructGenerator, &mut file)
.unwrap();
}
if target.contains("windows") {
Registry::new(Api::Egl, (1, 5), Profile::Core, Fallbacks::All, [])
.write_bindings(gl_generator::StructGenerator, &mut file)
.unwrap();
};
}
}

0 comments on commit 16a00a1

Please sign in to comment.