mirror of
https://github.com/servo/servo.git
synced 2025-06-06 00:25:37 +00:00
Split simpleservo into 3 crates for rust, c and jni apis
This commit is contained in:
parent
44344452e2
commit
16a00a107f
13 changed files with 174 additions and 105 deletions
49
Cargo.lock
generated
49
Cargo.lock
generated
|
@ -2173,22 +2173,6 @@ dependencies = [
|
|||
"webvr_traits 0.0.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libsimpleservo"
|
||||
version = "0.0.1"
|
||||
dependencies = [
|
||||
"android_injected_glue 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"android_logger 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"cc 1.0.18 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"gl_generator 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"jni 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.44 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libservo 0.0.1",
|
||||
"log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_json 1.0.13 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libz-sys"
|
||||
version = "1.0.18"
|
||||
|
@ -3719,6 +3703,39 @@ name = "signpost"
|
|||
version = "0.1.0"
|
||||
source = "git+https://github.com/pcwalton/signpost.git#7ed712507f343c38646b9d1fefd049166f9c9a18"
|
||||
|
||||
[[package]]
|
||||
name = "simpleservo"
|
||||
version = "0.0.1"
|
||||
dependencies = [
|
||||
"gl_generator 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.44 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libservo 0.0.1",
|
||||
"log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_json 1.0.13 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "simpleservo_capi"
|
||||
version = "0.0.1"
|
||||
dependencies = [
|
||||
"log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"simpleservo 0.0.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "simpleservo_jniapi"
|
||||
version = "0.0.1"
|
||||
dependencies = [
|
||||
"android_injected_glue 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"android_logger 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"cc 1.0.18 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"jni 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.44 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"simpleservo 0.0.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "siphasher"
|
||||
version = "0.2.2"
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
[workspace]
|
||||
members = [
|
||||
"ports/servo",
|
||||
"ports/libsimpleservo/",
|
||||
"ports/libsimpleservo/capi/",
|
||||
"ports/libsimpleservo/jniapi/",
|
||||
"ports/libmlservo/",
|
||||
"tests/unit/*",
|
||||
]
|
||||
|
|
|
@ -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"
|
||||
|
||||
|
@ -31,7 +19,6 @@ winapi = "0.3.2"
|
|||
|
||||
[build-dependencies]
|
||||
gl_generator = "0.10"
|
||||
cc = "1.0"
|
||||
|
||||
[features]
|
||||
default = ["unstable", "default-except-unstable"]
|
28
ports/libsimpleservo/api/build.rs
Normal file
28
ports/libsimpleservo/api/build.rs
Normal file
|
@ -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();
|
||||
};
|
||||
}
|
||||
}
|
|
@ -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};
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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!()
|
||||
}
|
|
@ -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,
|
||||
};
|
31
ports/libsimpleservo/capi/Cargo.toml
Normal file
31
ports/libsimpleservo/capi/Cargo.toml
Normal file
|
@ -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"]
|
|
@ -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
|
||||
|
@ -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);
|
||||
|
@ -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,
|
||||
|
@ -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")]
|
||||
|
@ -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]
|
39
ports/libsimpleservo/jniapi/Cargo.toml
Normal file
39
ports/libsimpleservo/jniapi/Cargo.toml
Normal file
|
@ -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"]
|
|
@ -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");
|
||||
|
@ -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();
|
||||
};
|
||||
}
|
||||
}
|
|
@ -4,14 +4,18 @@
|
|||
|
||||
#![allow(non_snake_case)]
|
||||
|
||||
#[macro_use]
|
||||
extern crate log;
|
||||
|
||||
use android_logger::{self, Filter};
|
||||
use crate::api::{self, EventLoopWaker, HostTrait, InitOptions, ReadFileTrait, ServoGlue, SERVO};
|
||||
use crate::gl_glue;
|
||||
use jni::objects::{GlobalRef, JClass, JObject, JString, JValue};
|
||||
use jni::sys::{jboolean, jfloat, jint, jstring, JNI_TRUE};
|
||||
use jni::{errors, JNIEnv, JavaVM};
|
||||
use libc::{dup2, pipe, read};
|
||||
use log::Level;
|
||||
use simpleservo::{
|
||||
self, gl_glue, EventLoopWaker, HostTrait, InitOptions, ReadFileTrait, ServoGlue, SERVO,
|
||||
};
|
||||
use std::os::raw::{c_char, c_int, c_void};
|
||||
use std::sync::{Arc, Mutex};
|
||||
use std::thread;
|
||||
|
@ -37,7 +41,7 @@ where
|
|||
|
||||
#[no_mangle]
|
||||
pub fn Java_org_mozilla_servoview_JNIServo_version(env: JNIEnv, _class: JClass) -> jstring {
|
||||
let v = api::servo_version();
|
||||
let v = simpleservo::servo_version();
|
||||
new_string(&env, &v).unwrap_or_else(|null| null)
|
||||
}
|
||||
|
||||
|
@ -62,8 +66,7 @@ pub fn Java_org_mozilla_servoview_JNIServo_init(
|
|||
// debug!() will only show in a debug build. Use info!() if logs
|
||||
// should show up in adb logcat with a release build.
|
||||
let filters = [
|
||||
"simpleservo::api",
|
||||
"simpleservo::jniapi",
|
||||
"simpleservo",
|
||||
"simpleservo::gl_glue::egl",
|
||||
// Show JS errors by default.
|
||||
"script::dom::bindings::error",
|
||||
|
@ -102,7 +105,7 @@ pub fn Java_org_mozilla_servoview_JNIServo_init(
|
|||
let callbacks = Box::new(HostCallbacks::new(callbacks_ref, &env));
|
||||
|
||||
if let Err(err) =
|
||||
gl_glue::egl::init().and_then(|gl| api::init(opts, gl, wakeup, readfile, callbacks))
|
||||
gl_glue::egl::init().and_then(|gl| simpleservo::init(opts, gl, wakeup, readfile, callbacks))
|
||||
{
|
||||
throw(&env, err)
|
||||
};
|
||||
|
@ -123,7 +126,7 @@ pub fn Java_org_mozilla_servoview_JNIServo_requestShutdown(env: JNIEnv, _class:
|
|||
#[no_mangle]
|
||||
pub fn Java_org_mozilla_servoview_JNIServo_deinit(_env: JNIEnv, _class: JClass) {
|
||||
debug!("deinit");
|
||||
api::deinit();
|
||||
simpleservo::deinit();
|
||||
}
|
||||
|
||||
#[no_mangle]
|
|
@ -1,21 +0,0 @@
|
|||
/* 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/. */
|
||||
|
||||
#[macro_use]
|
||||
extern crate log;
|
||||
|
||||
mod api;
|
||||
mod gl_glue;
|
||||
|
||||
// If not Android, expose the C-API
|
||||
#[cfg(not(target_os = "android"))]
|
||||
mod capi;
|
||||
#[cfg(not(target_os = "android"))]
|
||||
pub use crate::capi::*;
|
||||
|
||||
// If Android, expose the JNI-API
|
||||
#[cfg(target_os = "android")]
|
||||
mod jniapi;
|
||||
#[cfg(target_os = "android")]
|
||||
pub use crate::jniapi::*;
|
|
@ -716,7 +716,7 @@ install them, let us know by filing a bug!")
|
|||
def add_manifest_path(self, args, android=False, libsimpleservo=False):
|
||||
if "--manifest-path" not in args:
|
||||
if libsimpleservo or android:
|
||||
manifest = self.ports_libsimpleservo_manifest()
|
||||
manifest = self.ports_libsimpleservo_manifest(android)
|
||||
else:
|
||||
manifest = self.ports_servo_manifest()
|
||||
args.append("--manifest-path")
|
||||
|
@ -725,8 +725,12 @@ install them, let us know by filing a bug!")
|
|||
def ports_servo_manifest(self):
|
||||
return path.join(self.context.topdir, "ports", "servo", "Cargo.toml")
|
||||
|
||||
def ports_libsimpleservo_manifest(self):
|
||||
return path.join(self.context.topdir, "ports", "libsimpleservo", "Cargo.toml")
|
||||
def ports_libsimpleservo_manifest(self, android=False):
|
||||
if android:
|
||||
api = "jniapi"
|
||||
else:
|
||||
api = "capi"
|
||||
return path.join(self.context.topdir, "ports", "libsimpleservo", api, "Cargo.toml")
|
||||
|
||||
def servo_features(self):
|
||||
"""Return a list of optional features to enable for the Servo crate"""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue