diff options
-rw-r--r-- | Cargo.lock | 2 | ||||
-rw-r--r-- | ports/libmlservo/src/lib.rs | 17 | ||||
-rw-r--r-- | ports/libsimpleservo/api/Cargo.toml | 1 | ||||
-rw-r--r-- | ports/libsimpleservo/api/src/lib.rs | 9 | ||||
-rw-r--r-- | ports/libsimpleservo/capi/src/lib.rs | 7 | ||||
-rw-r--r-- | ports/libsimpleservo/jniapi/Cargo.toml | 3 | ||||
-rw-r--r-- | ports/libsimpleservo/jniapi/src/lib.rs | 9 | ||||
-rw-r--r-- | support/magicleap/Servo2D/code/inc/Servo2D.h | 3 | ||||
-rw-r--r-- | support/magicleap/Servo2D/code/src/Servo2D.cpp | 7 | ||||
-rw-r--r-- | support/magicleap/Servo2D/code/src/main.cpp | 4 |
10 files changed, 45 insertions, 17 deletions
diff --git a/Cargo.lock b/Cargo.lock index aeb8120e189..12e726fe777 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4179,7 +4179,6 @@ dependencies = [ "libloading 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "libservo 0.0.1", "log 0.4.6 (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)", ] @@ -4203,6 +4202,7 @@ dependencies = [ "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.6 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_json 1.0.13 (registry+https://github.com/rust-lang/crates.io-index)", "simpleservo 0.0.1", ] diff --git a/ports/libmlservo/src/lib.rs b/ports/libmlservo/src/lib.rs index 5f27e3f2b58..271d1c748d3 100644 --- a/ports/libmlservo/src/lib.rs +++ b/ports/libmlservo/src/lib.rs @@ -69,7 +69,7 @@ pub enum MLKeyType { } #[repr(transparent)] -#[derive(Copy, Clone)] +#[derive(Clone, Copy)] pub struct MLLogger(extern "C" fn(MLLogLevel, *const c_char)); #[repr(transparent)] @@ -108,6 +108,7 @@ pub unsafe extern "C" fn init_servo( url_update: MLURLUpdate, keyboard: MLKeyboard, url: *const c_char, + args: *const c_char, width: u32, height: u32, hidpi: f32, @@ -127,8 +128,20 @@ pub unsafe extern "C" fn init_servo( width as i32, height as i32, ); + let args = if args.is_null() { + vec![] + } else { + CStr::from_ptr(args) + .to_str() + .unwrap_or("") + .split(' ') + .map(|s| s.to_owned()) + .collect() + }; + info!("got args: {:?}", args); + let opts = InitOptions { - args: None, + args, url: Some(url.to_string()), density: hidpi, enable_subpixel_text_antialiasing: false, diff --git a/ports/libsimpleservo/api/Cargo.toml b/ports/libsimpleservo/api/Cargo.toml index a656314b0a2..1490b6d1f37 100644 --- a/ports/libsimpleservo/api/Cargo.toml +++ b/ports/libsimpleservo/api/Cargo.toml @@ -9,7 +9,6 @@ publish = false [dependencies] libservo = { path = "../../../components/servo" } log = "0.4" -serde_json = "1.0" [target.'cfg(not(target_os = "macos"))'.dependencies] libc = "0.2" diff --git a/ports/libsimpleservo/api/src/lib.rs b/ports/libsimpleservo/api/src/lib.rs index 2df9da4fd76..baafef8aa63 100644 --- a/ports/libsimpleservo/api/src/lib.rs +++ b/ports/libsimpleservo/api/src/lib.rs @@ -41,7 +41,7 @@ thread_local! { pub use servo::embedder_traits::EventLoopWaker; pub struct InitOptions { - pub args: Option<String>, + pub args: Vec<String>, pub url: Option<String>, pub coordinates: Coordinates, pub density: f32, @@ -135,16 +135,15 @@ pub fn servo_version() -> String { /// Initialize Servo. At that point, we need a valid GL context. /// In the future, this will be done in multiple steps. pub fn init( - init_opts: InitOptions, + mut init_opts: InitOptions, gl: Rc<dyn gl::Gl>, waker: Box<dyn EventLoopWaker>, callbacks: Box<dyn HostTrait>, ) -> Result<(), &'static str> { resources::set(Box::new(ResourceReaderInstance::new())); - if let Some(args) = init_opts.args { - let mut args: Vec<String> = serde_json::from_str(&args) - .map_err(|_| "Invalid arguments. Servo arguments must be formatted as a JSON array")?; + let mut args = mem::replace(&mut init_opts.args, vec![]); + if !args.is_empty() { // opts::from_cmdline_args expects the first argument to be the binary name. args.insert(0, "servo".to_string()); diff --git a/ports/libsimpleservo/capi/src/lib.rs b/ports/libsimpleservo/capi/src/lib.rs index aa23dfda602..50af7a4d284 100644 --- a/ports/libsimpleservo/capi/src/lib.rs +++ b/ports/libsimpleservo/capi/src/lib.rs @@ -76,7 +76,12 @@ fn init( crate::env_logger::init(); let args = unsafe { CStr::from_ptr(opts.args) }; - let args = args.to_str().map(|s| s.to_string()).ok(); + let args = args + .to_str() + .unwrap_or("") + .split(' ') + .map(|s| s.to_owned()) + .collect(); let url = unsafe { CStr::from_ptr(opts.url) }; let url = url.to_str().map(|s| s.to_string()).ok(); diff --git a/ports/libsimpleservo/jniapi/Cargo.toml b/ports/libsimpleservo/jniapi/Cargo.toml index 498ac05f055..d2fafd86dc2 100644 --- a/ports/libsimpleservo/jniapi/Cargo.toml +++ b/ports/libsimpleservo/jniapi/Cargo.toml @@ -17,9 +17,10 @@ bench = false android_injected_glue = "0.2" android_logger = "0.7" jni = "0.10.2" +libc = "0.2" log = "0.4" +serde_json = "1.0" simpleservo = { path = "../api" } -libc = "0.2" [build-dependencies] cc = "1.0" diff --git a/ports/libsimpleservo/jniapi/src/lib.rs b/ports/libsimpleservo/jniapi/src/lib.rs index 99210c7a0bb..d4a88b44421 100644 --- a/ports/libsimpleservo/jniapi/src/lib.rs +++ b/ports/libsimpleservo/jniapi/src/lib.rs @@ -683,8 +683,15 @@ fn get_options(env: &JNIEnv, opts: JObject) -> Result<(InitOptions, bool, Option .l() .map_err(|_| "coordinates is not an object")?; let coordinates = jni_coords_to_rust_coords(&env, coordinates)?; + + let args = match args { + Some(args) => serde_json::from_str(&args) + .map_err(|_| "Invalid arguments. Servo arguments must be formatted as a JSON array")?, + None => None, + }; + let opts = InitOptions { - args, + args: args.unwrap_or(vec![]), url, coordinates, density, diff --git a/support/magicleap/Servo2D/code/inc/Servo2D.h b/support/magicleap/Servo2D/code/inc/Servo2D.h index 61f1ee333e3..1e526bb2b94 100644 --- a/support/magicleap/Servo2D/code/inc/Servo2D.h +++ b/support/magicleap/Servo2D/code/inc/Servo2D.h @@ -29,7 +29,7 @@ public: /** * Constructs the Landscape Application. */ - Servo2D(const char* uri); + Servo2D(const char* uri, const char* args); /** * Destroys the Landscape Application. @@ -145,4 +145,5 @@ private: bool controller_trigger_down_ = false; // Is the controller trigger currently down? ServoInstance* servo_ = nullptr; // the servo instance we're embedding const char* uri_ = nullptr; + const char* args_ = nullptr; }; diff --git a/support/magicleap/Servo2D/code/src/Servo2D.cpp b/support/magicleap/Servo2D/code/src/Servo2D.cpp index 6d7ddb8df9e..a1859c6411d 100644 --- a/support/magicleap/Servo2D/code/src/Servo2D.cpp +++ b/support/magicleap/Servo2D/code/src/Servo2D.cpp @@ -68,7 +68,7 @@ void keyboard(Servo2D* app, bool visible) { // The functions Servo provides for hooking up to the ML. extern "C" ServoInstance* init_servo(EGLContext, EGLSurface, EGLDisplay, Servo2D*, MLLogger, MLHistoryUpdate, MLURLUpdate, MLKeyboard, - const char* url, int width, int height, float hidpi); + const char* url, const char* args, int width, int height, float hidpi); extern "C" void heartbeat_servo(ServoInstance*); extern "C" void keyboard_servo(ServoInstance*, char32_t code, lumin::ui::KeyType keyType); extern "C" void trigger_servo(ServoInstance*, float x, float y, bool down); @@ -78,8 +78,9 @@ extern "C" void navigate_servo(ServoInstance*, const char* text); extern "C" void discard_servo(ServoInstance*); // Create a Servo2D instance -Servo2D::Servo2D(const char* uri) +Servo2D::Servo2D(const char* uri, const char* args) : uri_(uri ? uri : HOME_PAGE) +, args_(args) { ML_LOG(Debug, "Servo2D Constructor."); } @@ -173,7 +174,7 @@ int Servo2D::init() { EGLDisplay dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY); // Hook into servo - servo_ = init_servo(ctx, surf, dpy, this, logger, history, url, keyboard, uri_, VIEWPORT_W, VIEWPORT_H, HIDPI); + servo_ = init_servo(ctx, surf, dpy, this, logger, history, url, keyboard, uri_, args_, VIEWPORT_W, VIEWPORT_H, HIDPI); if (!servo_) { ML_LOG(Error, "Servo2D Failed to init servo instance"); abort(); diff --git a/support/magicleap/Servo2D/code/src/main.cpp b/support/magicleap/Servo2D/code/src/main.cpp index 9daa85e4eda..a93c692e364 100644 --- a/support/magicleap/Servo2D/code/src/main.cpp +++ b/support/magicleap/Servo2D/code/src/main.cpp @@ -26,7 +26,9 @@ int main(int argc, char **argv) } } - Servo2D myApp(uri); + const char* args = getenv("SERVO_ARGS"); + + Servo2D myApp(uri, args); int rv = myApp.run(); MLLifecycleFreeInitArgList(&list); |