mirror of
https://github.com/servo/servo.git
synced 2025-08-08 06:55:31 +01:00
OHOS: Use native API to get most of the information needed for starting servoshell. (#37392)
Uses the native ohos-api crates to get the required information for starting servoshell. This increases the minimum API version requirement to API-14. Testing: Tested on device. --------- Signed-off-by: Narfinger <Narfinger@users.noreply.github.com> Co-authored-by: Jonathan Schwender <55576758+jschwe@users.noreply.github.com>
This commit is contained in:
parent
7a801f0ef5
commit
099fd10317
6 changed files with 95 additions and 47 deletions
|
@ -85,15 +85,17 @@ backtrace = { workspace = true }
|
|||
env_filter = "0.1.3"
|
||||
euclid = { workspace = true }
|
||||
hilog = "0.2.0"
|
||||
# force inprocess, until libc-rs 0.2.156 is released containing
|
||||
# https://github.com/rust-lang/libc/commit/9e248e212c5602cb4e98676e4c21ea0382663a12
|
||||
# force inprocess until we add multi-process support for ohos
|
||||
ipc-channel = { workspace = true, features = ["force-inprocess"] }
|
||||
napi-derive-ohos = "1.0.4"
|
||||
napi-ohos = "1.0.4"
|
||||
ohos-ime = "0.4.0"
|
||||
ohos-ime-sys = "0.2.0"
|
||||
ohos-deviceinfo = "0.1.0"
|
||||
ohos-abilitykit-sys = { version = "0.1.0", features = ["api-14"] }
|
||||
ohos-vsync = "0.1.3"
|
||||
xcomponent-sys = { version = "0.3.1", features = ["api-12", "keyboard-types"] }
|
||||
ohos-window-manager-sys = { version = "0.1", features = ["api-14"] }
|
||||
xcomponent-sys = { version = "0.3.1", features = ["api-14", "keyboard-types"] }
|
||||
|
||||
[target.'cfg(any(target_os = "android", target_env = "ohos"))'.dependencies]
|
||||
nix = { workspace = true, features = ["fs"] }
|
||||
|
|
|
@ -45,12 +45,8 @@ mod simpleservo;
|
|||
#[derive(Debug)]
|
||||
pub struct InitOpts {
|
||||
pub url: String,
|
||||
pub device_type: String,
|
||||
pub os_full_name: String,
|
||||
/// Path to application data bundled with the servo app, e.g. web-pages.
|
||||
pub resource_dir: String,
|
||||
pub cache_dir: String,
|
||||
pub display_density: f64,
|
||||
pub commandline_args: String,
|
||||
}
|
||||
|
||||
|
@ -626,10 +622,6 @@ pub fn register_prompt_toast_callback(callback: Function<String, ()>) -> napi_oh
|
|||
#[napi]
|
||||
pub fn init_servo(init_opts: InitOpts) -> napi_ohos::Result<()> {
|
||||
info!("Servo is being initialised with the following Options: ");
|
||||
info!(
|
||||
"Device Type: {}, DisplayDensity: {}",
|
||||
init_opts.device_type, init_opts.display_density
|
||||
);
|
||||
info!("Initial URL: {}", init_opts.url);
|
||||
let channel = if let Some(channel) = SERVO_CHANNEL.get() {
|
||||
channel
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
* 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::cell::RefCell;
|
||||
use std::ffi::{CString, c_char};
|
||||
use std::fs;
|
||||
use std::os::raw::c_void;
|
||||
use std::path::PathBuf;
|
||||
|
@ -9,7 +10,9 @@ use std::ptr::NonNull;
|
|||
use std::rc::Rc;
|
||||
|
||||
use dpi::PhysicalSize;
|
||||
use log::{debug, info, warn};
|
||||
use log::{debug, error, info, warn};
|
||||
use ohos_abilitykit_sys::runtime::application_context;
|
||||
use ohos_window_manager_sys::display_manager;
|
||||
use raw_window_handle::{
|
||||
DisplayHandle, OhosDisplayHandle, OhosNdkWindowHandle, RawDisplayHandle, RawWindowHandle,
|
||||
WindowHandle,
|
||||
|
@ -23,6 +26,46 @@ use crate::egl::ohos::InitOpts;
|
|||
use crate::egl::ohos::resources::ResourceReaderInstance;
|
||||
use crate::prefs::{ArgumentParsingResult, parse_command_line_arguments};
|
||||
|
||||
#[derive(Debug)]
|
||||
struct NativeValues {
|
||||
cache_dir: String,
|
||||
display_density: f32,
|
||||
device_type: ohos_deviceinfo::OhosDeviceType,
|
||||
os_full_name: String,
|
||||
}
|
||||
|
||||
/// Gets the resource and cache directory from the native c methods.
|
||||
fn get_native_values() -> NativeValues {
|
||||
let cache_dir = {
|
||||
const BUFFER_SIZE: i32 = 100;
|
||||
let mut buffer: Vec<u8> = Vec::with_capacity(BUFFER_SIZE as usize);
|
||||
let mut write_length = 0;
|
||||
unsafe {
|
||||
application_context::OH_AbilityRuntime_ApplicationContextGetCacheDir(
|
||||
buffer.as_mut_ptr().cast(),
|
||||
BUFFER_SIZE,
|
||||
&mut write_length,
|
||||
)
|
||||
.expect("Call to cache dir failed");
|
||||
buffer.set_len(write_length as usize);
|
||||
String::from_utf8(buffer).expect("UTF-8")
|
||||
}
|
||||
};
|
||||
let display_density = unsafe {
|
||||
let mut density: f32 = 0_f32;
|
||||
display_manager::OH_NativeDisplayManager_GetDefaultDisplayDensityPixels(&mut density)
|
||||
.expect("Could not get displaydensity");
|
||||
density
|
||||
};
|
||||
|
||||
NativeValues {
|
||||
cache_dir,
|
||||
display_density,
|
||||
device_type: ohos_deviceinfo::get_device_type(),
|
||||
os_full_name: String::from(ohos_deviceinfo::get_os_full_name().unwrap_or("Undefined")),
|
||||
}
|
||||
}
|
||||
|
||||
/// Initialize Servo. At that point, we need a valid GL context.
|
||||
/// In the future, this will be done in multiple steps.
|
||||
pub fn init(
|
||||
|
@ -34,6 +77,12 @@ pub fn init(
|
|||
) -> Result<Rc<RunningAppState>, &'static str> {
|
||||
info!("Entered simpleservo init function");
|
||||
crate::init_crypto();
|
||||
|
||||
let native_values = get_native_values();
|
||||
info!("Device Type {:?}", native_values.device_type);
|
||||
info!("OS Full Name {:?}", native_values.os_full_name);
|
||||
info!("ResourceDir {:?}", options.resource_dir);
|
||||
|
||||
let resource_dir = PathBuf::from(&options.resource_dir).join("servo");
|
||||
debug!("Resources are located at: {:?}", resource_dir);
|
||||
resources::set(Box::new(ResourceReaderInstance::new(resource_dir.clone())));
|
||||
|
@ -49,7 +98,7 @@ pub fn init(
|
|||
);
|
||||
debug!("Servo commandline args: {:?}", args);
|
||||
|
||||
let config_dir = PathBuf::from(&options.cache_dir).join("servo");
|
||||
let config_dir = PathBuf::from(&native_values.cache_dir).join("servo");
|
||||
debug!("Configs are located at: {:?}", config_dir);
|
||||
let _ = crate::prefs::DEFAULT_CONFIG_DIR
|
||||
.set(config_dir.clone())
|
||||
|
@ -133,7 +182,7 @@ pub fn init(
|
|||
|
||||
let app_state = RunningAppState::new(
|
||||
Some(options.url),
|
||||
options.display_density as f32,
|
||||
native_values.display_density as f32,
|
||||
rendering_context,
|
||||
servo,
|
||||
window_callbacks,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue