From f12071f77eef0612c16c0f297c29e95929218576 Mon Sep 17 00:00:00 2001 From: Martin Robinson Date: Wed, 30 Oct 2024 13:20:43 +0100 Subject: [PATCH] andrdoid: Fix some compiler warnings (#34070) This removes unused code in order to reduce the number of compiler warnings on the Android build. Some of this code might be used in the future and it can be restored from git commit history. Signed-off-by: Martin Robinson --- .../platform/freetype/android/font_list.rs | 4 -- .../fonts/platform/freetype/font_list.rs | 12 ++++- components/fonts/platform/freetype/mod.rs | 10 ---- .../fonts/platform/freetype/ohos/font_list.rs | 3 -- ports/servoshell/crash_handler.rs | 4 +- ports/servoshell/egl/android.rs | 14 +---- ports/servoshell/egl/android/simpleservo.rs | 52 ------------------- ports/servoshell/egl/servo_glue.rs | 1 - 8 files changed, 14 insertions(+), 86 deletions(-) diff --git a/components/fonts/platform/freetype/android/font_list.rs b/components/fonts/platform/freetype/android/font_list.rs index 35ad065a36e..b45cbf66946 100644 --- a/components/fonts/platform/freetype/android/font_list.rs +++ b/components/fonts/platform/freetype/android/font_list.rs @@ -2,15 +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/. */ -use std::fs::File; -use std::io::Read; use std::path::Path; use std::sync::LazyLock; use base::text::{is_cjk, UnicodeBlock, UnicodeBlockMethod}; use log::warn; -use malloc_size_of_derive::MallocSizeOf; -use serde::{Deserialize, Serialize}; use style::values::computed::font::GenericFontFamily; use style::values::computed::{ FontStretch as StyleFontStretch, FontStyle as StyleFontStyle, FontWeight as StyleFontWeight, diff --git a/components/fonts/platform/freetype/font_list.rs b/components/fonts/platform/freetype/font_list.rs index 9552b47ca6f..2387aedf5b8 100644 --- a/components/fonts/platform/freetype/font_list.rs +++ b/components/fonts/platform/freetype/font_list.rs @@ -2,7 +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::ffi::CString; +use std::ffi::{CStr, CString}; use std::ptr; use base::text::{UnicodeBlock, UnicodeBlockMethod}; @@ -26,7 +26,7 @@ use style::values::computed::{FontStretch, FontStyle, FontWeight}; use style::Atom; use unicode_script::Script; -use super::{c_str_to_string, LocalFontIdentifier}; +use super::LocalFontIdentifier; use crate::font::map_platform_values_to_style_values; use crate::font_template::{FontTemplate, FontTemplateDescriptor}; use crate::platform::add_noto_fallback_families; @@ -289,3 +289,11 @@ fn font_weight_from_fontconfig_pattern(pattern: *mut FcPattern) -> Option String { + std::str::from_utf8(CStr::from_ptr(s).to_bytes()) + .unwrap() + .to_owned() +} diff --git a/components/fonts/platform/freetype/mod.rs b/components/fonts/platform/freetype/mod.rs index 1ec918728cc..c507cf08184 100644 --- a/components/fonts/platform/freetype/mod.rs +++ b/components/fonts/platform/freetype/mod.rs @@ -3,26 +3,16 @@ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ use std::convert::TryInto; -use std::ffi::CStr; use std::fs::File; use std::path::{Path, PathBuf}; use std::str; -use libc::c_char; use malloc_size_of_derive::MallocSizeOf; use memmap2::Mmap; use serde::{Deserialize, Serialize}; use style::Atom; use webrender_api::NativeFontHandle; -/// Creates a String from the given null-terminated buffer. -/// Panics if the buffer does not contain UTF-8. -unsafe fn c_str_to_string(s: *const c_char) -> String { - str::from_utf8(CStr::from_ptr(s).to_bytes()) - .unwrap() - .to_owned() -} - pub mod font; #[cfg(all(target_os = "linux", not(target_env = "ohos"), not(ohos_mock)))] diff --git a/components/fonts/platform/freetype/ohos/font_list.rs b/components/fonts/platform/freetype/ohos/font_list.rs index 62d3b5145e1..cf8ba72e356 100644 --- a/components/fonts/platform/freetype/ohos/font_list.rs +++ b/components/fonts/platform/freetype/ohos/font_list.rs @@ -3,8 +3,6 @@ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ use std::collections::HashMap; use std::ffi::OsStr; -use std::fs::File; -use std::io::Read; use std::os::unix::ffi::OsStrExt; use std::path::{Path, PathBuf}; use std::sync::LazyLock; @@ -13,7 +11,6 @@ use std::{fs, io}; use base::text::{UnicodeBlock, UnicodeBlockMethod}; use log::{debug, error, warn}; use malloc_size_of_derive::MallocSizeOf; -use serde::{Deserialize, Serialize}; use style::values::computed::font::GenericFontFamily; use style::values::computed::{ FontStretch as StyleFontStretch, FontStyle as StyleFontStyle, FontWeight as StyleFontWeight, diff --git a/ports/servoshell/crash_handler.rs b/ports/servoshell/crash_handler.rs index 0644ee8a601..94c0b10f992 100644 --- a/ports/servoshell/crash_handler.rs +++ b/ports/servoshell/crash_handler.rs @@ -2,7 +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/. */ -#[cfg(not(any(target_os = "macos", target_os = "linux")))] +#[cfg(not(any(target_os = "macos", target_os = "linux", target_os = "android")))] pub fn install() {} #[cfg(any(target_os = "macos", target_os = "linux"))] @@ -49,7 +49,7 @@ pub fn install() { signal!(libc::SIGBUS, handler); // handle invalid memory access } -#[cfg(not(any(target_os = "macos", target_os = "linux")))] +#[cfg(not(any(target_os = "macos", target_os = "linux", target_os = "android")))] pub(crate) fn raise_signal_or_exit_with_error(_signal: i32) { std::process::exit(1); } diff --git a/ports/servoshell/egl/android.rs b/ports/servoshell/egl/android.rs index d3b09769627..951b3db8b86 100644 --- a/ports/servoshell/egl/android.rs +++ b/ports/servoshell/egl/android.rs @@ -13,7 +13,7 @@ use std::sync::Arc; use android_logger::{self, Config, FilterBuilder}; use jni::objects::{GlobalRef, JClass, JObject, JString, JValue, JValueOwned}; -use jni::sys::{jboolean, jfloat, jint, jobject, jstring, JNI_TRUE}; +use jni::sys::{jboolean, jfloat, jint, jobject, JNI_TRUE}; use jni::{JNIEnv, JavaVM}; use log::{debug, error, info, warn}; use simpleservo::{ @@ -59,7 +59,7 @@ where #[no_mangle] pub extern "C" fn Java_org_servo_servoview_JNIServo_version<'local>( - mut env: JNIEnv<'local>, + env: JNIEnv<'local>, _class: JClass<'local>, ) -> JString<'local> { let v = crate::servo_version(); @@ -711,16 +711,6 @@ fn throw(env: &mut JNIEnv, err: &str) { } } -fn new_string(env: &mut JNIEnv, s: &str) -> Result { - match env.new_string(s) { - Ok(s) => Ok(s.into_raw()), - Err(_) => { - throw(env, "Couldn't create Java string"); - Err("Couldn't create Java String") - }, - } -} - fn new_string_as_jvalue<'local>( env: &mut JNIEnv<'local>, input_string: &str, diff --git a/ports/servoshell/egl/android/simpleservo.rs b/ports/servoshell/egl/android/simpleservo.rs index 194203d9102..bf4dffc80bb 100644 --- a/ports/servoshell/egl/android/simpleservo.rs +++ b/ports/servoshell/egl/android/simpleservo.rs @@ -9,10 +9,8 @@ use std::os::raw::c_void; use std::rc::Rc; use getopts::Options; -use log::info; use servo::compositing::windowing::EmbedderEvent; use servo::compositing::CompositeTarget; -use servo::config::prefs::pref_map; pub use servo::config::prefs::{add_user_prefs, PrefValue}; use servo::embedder_traits::resources; /// The EventLoopWaker::wake function will be called from any thread. @@ -51,52 +49,6 @@ pub struct InitOptions { pub enum SurfmanIntegration { /// Render directly to a provided native widget (see surfman::NativeWidget). Widget(*mut c_void), - /// Render to an offscreen surface. - Surface, -} - -/// Test if a url is valid. -pub fn is_uri_valid(url: &str) -> bool { - info!("load_uri: {}", url); - ServoUrl::parse(url).is_ok() -} - -/// Retrieve a snapshot of the current preferences -pub fn get_prefs() -> HashMap { - pref_map() - .iter() - .map(|(key, value)| { - let is_default = pref_map().is_default(&key).unwrap(); - (key, (value, is_default)) - }) - .collect() -} - -/// Retrieve a preference. -pub fn get_pref(key: &str) -> (PrefValue, bool) { - if let Ok(is_default) = pref_map().is_default(&key) { - (pref_map().get(key), is_default) - } else { - (PrefValue::Missing, false) - } -} - -/// Restore a preference to its default value. -pub fn reset_pref(key: &str) -> bool { - pref_map().reset(key).is_ok() -} - -/// Restore all the preferences to their default values. -pub fn reset_all_prefs() { - pref_map().reset_all(); -} - -/// Change the value of a preference. -pub fn set_pref(key: &str, val: PrefValue) -> Result<(), &'static str> { - pref_map() - .set(key, val) - .map(|_| ()) - .map_err(|_| "Pref set failed") } /// Initialize Servo. At that point, we need a valid GL context. @@ -144,10 +96,6 @@ pub fn init( }; SurfaceType::Widget { native_widget } }, - SurfmanIntegration::Surface => { - let size = init_opts.coordinates.framebuffer.to_untyped(); - SurfaceType::Generic { size } - }, }; let rendering_context = RenderingContext::create(&connection, &adapter, surface_type) .or(Err("Failed to create surface manager"))?; diff --git a/ports/servoshell/egl/servo_glue.rs b/ports/servoshell/egl/servo_glue.rs index dd9816cbce8..d9b32401c34 100644 --- a/ports/servoshell/egl/servo_glue.rs +++ b/ports/servoshell/egl/servo_glue.rs @@ -23,7 +23,6 @@ use servo::keyboard_types::{Key, KeyState, KeyboardEvent}; use servo::script_traits::{ MediaSessionActionType, MouseButton, TouchEventType, TouchId, TraversalDirection, }; -use servo::servo_url::ServoUrl; use servo::style_traits::DevicePixel; use servo::webrender_api::units::DeviceIntRect; use servo::webrender_api::ScrollLocation;