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
This commit is contained in:
Mike Hommey 2024-03-05 21:04:12 +00:00
parent 700c39e80b
commit 6d220051eb
9 changed files with 40 additions and 40 deletions

View File

@ -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"

View File

@ -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 {

View File

@ -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;

View File

@ -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) };

View File

@ -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,

View File

@ -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 {

View File

@ -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 }

View File

@ -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];

View File

@ -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;
}