From 6d220051eb6f339a7618ca3e15de4f99427bb185 Mon Sep 17 00:00:00 2001 From: Mike Hommey Date: Tue, 5 Mar 2024 21:04:12 +0000 Subject: [PATCH] Bug 1883572 - Add enough support for iOS to webrender so that it builds. r=gfx-reviewers,gw Differential Revision: https://phabricator.services.mozilla.com/D203563 --- gfx/webrender_bindings/Cargo.toml | 2 +- gfx/webrender_bindings/src/bindings.rs | 8 +++---- gfx/webrender_bindings/src/lib.rs | 6 +++--- gfx/webrender_bindings/src/moz2d_renderer.rs | 14 ++++++------- gfx/wr/webrender/src/resource_cache.rs | 4 ++-- gfx/wr/webrender_api/src/font.rs | 22 ++++++++++---------- gfx/wr/wr_glyph_rasterizer/Cargo.toml | 4 ++-- gfx/wr/wr_glyph_rasterizer/src/gamma_lut.rs | 10 ++++----- gfx/wr/wr_glyph_rasterizer/src/lib.rs | 10 ++++----- 9 files changed, 40 insertions(+), 40 deletions(-) diff --git a/gfx/webrender_bindings/Cargo.toml b/gfx/webrender_bindings/Cargo.toml index f6b3fd637fe6..0f0c069e8787 100644 --- a/gfx/webrender_bindings/Cargo.toml +++ b/gfx/webrender_bindings/Cargo.toml @@ -33,7 +33,7 @@ features = ["capture", "serialize_program", "gecko", "sw_compositor"] dwrote = "0.11" winapi = "0.3" -[target.'cfg(target_os = "macos")'.dependencies] +[target.'cfg(any(target_os = "macos", target_os = "ios"))'.dependencies] core-foundation = "0.9" core-graphics = "0.23" foreign-types = "0.5.0" diff --git a/gfx/webrender_bindings/src/bindings.rs b/gfx/webrender_bindings/src/bindings.rs index 1f3bca644a94..047791c76bae 100644 --- a/gfx/webrender_bindings/src/bindings.rs +++ b/gfx/webrender_bindings/src/bindings.rs @@ -7,7 +7,7 @@ use gleam::gl; use std::cell::RefCell; -#[cfg(not(target_os = "macos"))] +#[cfg(not(any(target_os = "macos", target_os = "ios")))] use std::ffi::OsString; use std::ffi::{CStr, CString}; use std::io::Cursor; @@ -16,7 +16,7 @@ use std::ops::Range; #[cfg(target_os = "android")] use std::os::raw::c_int; use std::os::raw::{c_char, c_float, c_void}; -#[cfg(not(any(target_os = "macos", target_os = "windows")))] +#[cfg(not(any(target_os = "macos", target_os = "ios", target_os = "windows")))] use std::os::unix::ffi::OsStringExt; #[cfg(target_os = "windows")] use std::os::windows::ffi::OsStringExt; @@ -2326,7 +2326,7 @@ fn read_font_descriptor(bytes: &mut WrVecU8, index: u32) -> NativeFontHandle { } } -#[cfg(target_os = "macos")] +#[cfg(any(target_os = "macos", target_os = "ios"))] fn read_font_descriptor(bytes: &mut WrVecU8, index: u32) -> NativeFontHandle { // On macOS, the descriptor string is a concatenation of the PostScript name // and the font file path (to disambiguate cases where there are multiple @@ -2340,7 +2340,7 @@ fn read_font_descriptor(bytes: &mut WrVecU8, index: u32) -> NativeFontHandle { } } -#[cfg(not(any(target_os = "macos", target_os = "windows")))] +#[cfg(not(any(target_os = "macos", target_os = "ios", target_os = "windows")))] fn read_font_descriptor(bytes: &mut WrVecU8, index: u32) -> NativeFontHandle { let chars = bytes.flush_into_vec(); NativeFontHandle { diff --git a/gfx/webrender_bindings/src/lib.rs b/gfx/webrender_bindings/src/lib.rs index 9e94302e0f90..b3c6e6ac56b8 100644 --- a/gfx/webrender_bindings/src/lib.rs +++ b/gfx/webrender_bindings/src/lib.rs @@ -28,11 +28,11 @@ extern crate dwrote; #[cfg(target_os = "windows")] extern crate winapi; -#[cfg(target_os = "macos")] +#[cfg(any(target_os = "macos", target_os = "ios"))] extern crate core_foundation; -#[cfg(target_os = "macos")] +#[cfg(any(target_os = "macos", target_os = "ios"))] extern crate core_graphics; -#[cfg(target_os = "macos")] +#[cfg(any(target_os = "macos", target_os = "ios"))] extern crate foreign_types; mod program_cache; diff --git a/gfx/webrender_bindings/src/moz2d_renderer.rs b/gfx/webrender_bindings/src/moz2d_renderer.rs index 4c7a32c91298..ca1e76f96ffd 100644 --- a/gfx/webrender_bindings/src/moz2d_renderer.rs +++ b/gfx/webrender_bindings/src/moz2d_renderer.rs @@ -33,16 +33,16 @@ use std::sync::Arc; #[cfg(target_os = "windows")] use dwrote; -#[cfg(target_os = "macos")] +#[cfg(any(target_os = "macos", target_os = "ios"))] use core_foundation::string::CFString; -#[cfg(target_os = "macos")] +#[cfg(any(target_os = "macos", target_os = "ios"))] use core_graphics::font::CGFont; -#[cfg(target_os = "macos")] +#[cfg(any(target_os = "macos", target_os = "ios"))] use foreign_types::ForeignType; -#[cfg(not(any(target_os = "macos", target_os = "windows")))] +#[cfg(not(any(target_os = "macos", target_os = "ios", target_os = "windows")))] use std::ffi::CString; -#[cfg(not(any(target_os = "macos", target_os = "windows")))] +#[cfg(not(any(target_os = "macos", target_os = "ios", target_os = "windows")))] use std::os::unix::ffi::OsStrExt; /// Local print-debugging utility @@ -787,7 +787,7 @@ impl Moz2dBlobImageHandler { unsafe { AddNativeFontHandle(key, face.as_ptr() as *mut c_void, 0) }; } - #[cfg(target_os = "macos")] + #[cfg(any(target_os = "macos", target_os = "ios"))] fn process_native_font_handle(key: FontKey, handle: &NativeFontHandle) { let font = match CGFont::from_name(&CFString::new(&handle.name)) { Ok(font) => font, @@ -804,7 +804,7 @@ impl Moz2dBlobImageHandler { unsafe { AddNativeFontHandle(key, font.as_ptr() as *mut c_void, 0) }; } - #[cfg(not(any(target_os = "macos", target_os = "windows")))] + #[cfg(not(any(target_os = "macos", target_os = "ios", target_os = "windows")))] fn process_native_font_handle(key: FontKey, handle: &NativeFontHandle) { let cstr = CString::new(handle.path.as_os_str().as_bytes()).unwrap(); unsafe { AddNativeFontHandle(key, cstr.as_ptr() as *mut c_void, handle.index) }; diff --git a/gfx/wr/webrender/src/resource_cache.rs b/gfx/wr/webrender/src/resource_cache.rs index f8b05439b41c..349be25cb803 100644 --- a/gfx/wr/webrender/src/resource_cache.rs +++ b/gfx/wr/webrender/src/resource_cache.rs @@ -2087,14 +2087,14 @@ impl ResourceCache { index, } } - #[cfg(not(target_os = "macos"))] + #[cfg(not(any(target_os = "macos", target_os = "ios")))] FontTemplate::Native(native) => { PlainFontTemplate { data: native.path.to_string_lossy().to_string(), index: native.index, } } - #[cfg(target_os = "macos")] + #[cfg(any(target_os = "macos", target_os = "ios"))] FontTemplate::Native(native) => { PlainFontTemplate { data: native.name, diff --git a/gfx/wr/webrender_api/src/font.rs b/gfx/wr/webrender_api/src/font.rs index d4f3057a7cf1..fc245ddfab15 100644 --- a/gfx/wr/webrender_api/src/font.rs +++ b/gfx/wr/webrender_api/src/font.rs @@ -5,7 +5,7 @@ use peek_poke::PeekPoke; use std::cmp::Ordering; use std::hash::{Hash, Hasher}; -#[cfg(not(target_os = "macos"))] +#[cfg(not(any(target_os = "macos", target_os = "ios")))] use std::path::PathBuf; use std::sync::Arc; // local imports @@ -52,14 +52,14 @@ impl FontSize { pub fn to_f64_px(&self) -> f64 { self.0 as f64 } } -#[cfg(not(target_os = "macos"))] +#[cfg(not(any(target_os = "macos", target_os = "ios")))] #[derive(Clone, Debug, Hash, Eq, PartialEq, PartialOrd, Ord, Serialize, Deserialize)] pub struct NativeFontHandle { pub path: PathBuf, pub index: u32, } -#[cfg(target_os = "macos")] +#[cfg(any(target_os = "macos", target_os = "ios"))] #[derive(Clone, Debug, Hash, Eq, PartialEq, PartialOrd, Ord, Serialize, Deserialize)] pub struct NativeFontHandle { pub name: String, @@ -236,13 +236,13 @@ impl Default for FontInstanceFlags { FontInstanceFlags::SUBPIXEL_POSITION } - #[cfg(target_os = "macos")] + #[cfg(any(target_os = "macos", target_os = "ios"))] fn default() -> FontInstanceFlags { FontInstanceFlags::SUBPIXEL_POSITION | FontInstanceFlags::FONT_SMOOTHING } - #[cfg(not(any(target_os = "macos", target_os = "windows")))] + #[cfg(not(any(target_os = "macos", target_os = "ios", target_os = "windows")))] fn default() -> FontInstanceFlags { FontInstanceFlags::SUBPIXEL_POSITION } @@ -332,14 +332,14 @@ impl Default for FontInstancePlatformOptions { } } -#[cfg(target_os = "macos")] +#[cfg(any(target_os = "macos", target_os = "ios"))] #[repr(C)] #[derive(Clone, Copy, Debug, Deserialize, Hash, Eq, MallocSizeOf, PartialEq, PartialOrd, Ord, Serialize)] pub struct FontInstancePlatformOptions { pub unused: u32, } -#[cfg(target_os = "macos")] +#[cfg(any(target_os = "macos", target_os = "ios"))] impl Default for FontInstancePlatformOptions { fn default() -> FontInstancePlatformOptions { FontInstancePlatformOptions { @@ -348,7 +348,7 @@ impl Default for FontInstancePlatformOptions { } } -#[cfg(not(any(target_os = "macos", target_os = "windows")))] +#[cfg(not(any(target_os = "macos", target_os = "ios", target_os = "windows")))] #[repr(u8)] #[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, MallocSizeOf, PartialEq, PartialOrd, Ord, Serialize)] pub enum FontLCDFilter { @@ -358,7 +358,7 @@ pub enum FontLCDFilter { Legacy, } -#[cfg(not(any(target_os = "macos", target_os = "windows")))] +#[cfg(not(any(target_os = "macos", target_os = "ios", target_os = "windows")))] #[repr(u8)] #[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, MallocSizeOf, PartialEq, PartialOrd, Ord, Serialize)] pub enum FontHinting { @@ -369,7 +369,7 @@ pub enum FontHinting { LCD, } -#[cfg(not(any(target_os = "macos", target_os = "windows")))] +#[cfg(not(any(target_os = "macos", target_os = "ios", target_os = "windows")))] #[repr(C)] #[derive(Clone, Copy, Debug, Deserialize, Hash, Eq, MallocSizeOf, PartialEq, PartialOrd, Ord, Serialize)] pub struct FontInstancePlatformOptions { @@ -377,7 +377,7 @@ pub struct FontInstancePlatformOptions { pub hinting: FontHinting, } -#[cfg(not(any(target_os = "macos", target_os = "windows")))] +#[cfg(not(any(target_os = "macos", target_os = "ios", target_os = "windows")))] impl Default for FontInstancePlatformOptions { fn default() -> FontInstancePlatformOptions { FontInstancePlatformOptions { diff --git a/gfx/wr/wr_glyph_rasterizer/Cargo.toml b/gfx/wr/wr_glyph_rasterizer/Cargo.toml index 5e000b9458fa..0f2789641b55 100644 --- a/gfx/wr/wr_glyph_rasterizer/Cargo.toml +++ b/gfx/wr/wr_glyph_rasterizer/Cargo.toml @@ -37,14 +37,14 @@ glutin = "0.28" rayon = "1" winit = "0.26" -[target.'cfg(any(target_os = "android", all(unix, not(target_os = "macos"))))'.dependencies] +[target.'cfg(any(target_os = "android", all(unix, not(any(target_os = "macos", target_os = "ios")))))'.dependencies] freetype = { version = "0.7", default-features = false } libc = "0.2" [target.'cfg(target_os = "windows")'.dependencies] dwrote = "0.11" -[target.'cfg(target_os = "macos")'.dependencies] +[target.'cfg(any(target_os = "macos", target_os = "ios"))'.dependencies] core-foundation = "0.9.2" core-graphics = "0.23" core-text = { version = "20.1", default-features = false } diff --git a/gfx/wr/wr_glyph_rasterizer/src/gamma_lut.rs b/gfx/wr/wr_glyph_rasterizer/src/gamma_lut.rs index 15075bacbf52..82555c8a06d8 100644 --- a/gfx/wr/wr_glyph_rasterizer/src/gamma_lut.rs +++ b/gfx/wr/wr_glyph_rasterizer/src/gamma_lut.rs @@ -168,7 +168,7 @@ impl ColorLut for ColorU { // so we can get linear values. // CoreGraphics obscurely defaults to 2.0 as the smoothing gamma value. // The color space used does not appear to affect this choice. -#[cfg(target_os="macos")] +#[cfg(any(target_os="macos", target_os = "ios"))] fn get_inverse_gamma_table_coregraphics_smoothing() -> [u8; 256] { let mut table = [0u8; 256]; @@ -250,7 +250,7 @@ pub fn build_gamma_correcting_lut(table: &mut [u8; 256], src: u8, contrast: f32, pub struct GammaLut { tables: [[u8; 256]; 1 << LUM_BITS], - #[cfg(target_os="macos")] + #[cfg(any(target_os="macos", target_os="ios"))] cg_inverse_gamma: [u8; 256], } @@ -280,12 +280,12 @@ impl GammaLut { } pub fn new(contrast: f32, paint_gamma: f32, device_gamma: f32) -> GammaLut { - #[cfg(target_os="macos")] + #[cfg(any(target_os="macos", target_os="ios"))] let mut table = GammaLut { tables: [[0; 256]; 1 << LUM_BITS], cg_inverse_gamma: get_inverse_gamma_table_coregraphics_smoothing(), }; - #[cfg(not(target_os="macos"))] + #[cfg(not(any(target_os="macos", target_os="ios")))] let mut table = GammaLut { tables: [[0; 256]; 1 << LUM_BITS], }; @@ -337,7 +337,7 @@ impl GammaLut { } } - #[cfg(target_os="macos")] + #[cfg(any(target_os="macos", target_os="ios"))] pub fn coregraphics_convert_to_linear(&self, pixels: &mut [u8]) { for pixel in pixels.chunks_mut(4) { pixel[0] = self.cg_inverse_gamma[pixel[0] as usize]; diff --git a/gfx/wr/wr_glyph_rasterizer/src/lib.rs b/gfx/wr/wr_glyph_rasterizer/src/lib.rs index 27ceb7199219..3cf95d7c3119 100644 --- a/gfx/wr/wr_glyph_rasterizer/src/lib.rs +++ b/gfx/wr/wr_glyph_rasterizer/src/lib.rs @@ -9,7 +9,7 @@ //! ## Usage //! -#[cfg(any(target_os = "macos", target_os = "windows"))] +#[cfg(any(target_os = "macos", target_os = "ios", target_os = "windows"))] mod gamma_lut; mod rasterizer; mod telemetry; @@ -38,18 +38,18 @@ extern crate serde; extern crate malloc_size_of; pub mod platform { - #[cfg(target_os = "macos")] + #[cfg(any(target_os = "macos", target_os = "ios"))] pub use crate::platform::macos::font; - #[cfg(any(target_os = "android", all(unix, not(target_os = "macos"))))] + #[cfg(any(target_os = "android", all(unix, not(any(target_os = "ios", target_os = "macos")))))] pub use crate::platform::unix::font; #[cfg(target_os = "windows")] pub use crate::platform::windows::font; - #[cfg(target_os = "macos")] + #[cfg(any(target_os = "ios", target_os = "macos"))] pub mod macos { pub mod font; } - #[cfg(any(target_os = "android", all(unix, not(target_os = "macos"))))] + #[cfg(any(target_os = "android", all(unix, not(any(target_os = "macos", target_os = "ios")))))] pub mod unix { pub mod font; }