mirror of
https://github.com/servo/servo.git
synced 2025-08-11 16:35:33 +01:00
Auto merge of #23696 - servo:hl, r=jdm
Add UWP port - bis
This is #23658 with some fixes:
- removed nspr from DLL dependencies (was breaking VS build)
- exclude symbols from header file (was breaking VS build)
- rebased
Before merging:
- please check the rebased commit that introduces the `--uwp` option (things moved around since 7c85dc09b5
)
- should we wait until the WR fix lands upstream?
<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/23696)
<!-- Reviewable:end -->
This commit is contained in:
commit
b32bff3b97
43 changed files with 1670 additions and 86 deletions
|
@ -30,6 +30,7 @@ ProductName = "Servo"
|
|||
canvas2d-azure = ["libservo/canvas2d-azure"]
|
||||
canvas2d-raqote = ["libservo/canvas2d-raqote"]
|
||||
default = ["webdriver", "max_log_level"]
|
||||
egl = ["libservo/egl"]
|
||||
energy-profiling = ["libservo/energy-profiling"]
|
||||
debugmozjs = ["libservo/debugmozjs"]
|
||||
js_backtrace = ["libservo/js_backtrace"]
|
||||
|
|
|
@ -15,6 +15,7 @@ bench = false
|
|||
[features]
|
||||
canvas2d-azure = ["simpleservo/canvas2d-azure"]
|
||||
canvas2d-raqote = ["simpleservo/canvas2d-raqote"]
|
||||
egl = ["simpleservo/egl"]
|
||||
|
||||
[dependencies]
|
||||
libservo = { path = "../../components/servo", features = ["no_static_freetype"] }
|
||||
|
|
|
@ -30,6 +30,7 @@ canvas2d-azure = ["libservo/canvas2d-azure"]
|
|||
canvas2d-raqote = ["libservo/canvas2d-raqote"]
|
||||
default = ["webdriver", "max_log_level"]
|
||||
debugmozjs = ["libservo/debugmozjs"]
|
||||
egl = ["libservo/egl"]
|
||||
energy-profiling = ["libservo/energy-profiling"]
|
||||
googlevr = ["libservo/googlevr"]
|
||||
js_backtrace = ["libservo/js_backtrace"]
|
||||
|
|
|
@ -15,16 +15,19 @@ fn main() {
|
|||
// For now, we only support EGL, and only on Windows and Android.
|
||||
if target.contains("android") || target.contains("windows") {
|
||||
let mut file = File::create(&dest.join("egl_bindings.rs")).unwrap();
|
||||
if target.contains("android") {
|
||||
Registry::new(Api::Egl, (1, 5), Profile::Core, Fallbacks::All, [])
|
||||
.write_bindings(gl_generator::StaticStructGenerator, &mut file)
|
||||
.unwrap();
|
||||
}
|
||||
Registry::new(Api::Egl, (1, 5), Profile::Core, Fallbacks::All, [])
|
||||
.write_bindings(gl_generator::StaticStructGenerator, &mut file)
|
||||
.unwrap();
|
||||
|
||||
// Historically, Android builds have succeeded with rust-link-lib=EGL.
|
||||
// On Windows when relying on %LIBS% to contain libEGL.lib, however,
|
||||
// we must explicitly use rustc-link-lib=libEGL or rustc will attempt
|
||||
// to link EGL.lib instead.
|
||||
if target.contains("windows") {
|
||||
Registry::new(Api::Egl, (1, 5), Profile::Core, Fallbacks::All, [])
|
||||
.write_bindings(gl_generator::StructGenerator, &mut file)
|
||||
.unwrap();
|
||||
};
|
||||
println!("cargo:rustc-link-lib=libEGL");
|
||||
} else {
|
||||
println!("cargo:rust-link-lib=EGL");
|
||||
}
|
||||
}
|
||||
|
||||
if target.contains("linux") ||
|
||||
|
|
|
@ -11,20 +11,9 @@ pub type ServoGl = std::rc::Rc<dyn servo::gl::Gl>;
|
|||
pub mod egl {
|
||||
use servo::gl::GlesFns;
|
||||
use std::ffi::CString;
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
use std::os::raw::c_void;
|
||||
#[cfg(target_os = "windows")]
|
||||
use winapi::um::libloaderapi::{GetProcAddress, LoadLibraryA};
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
pub type EGLNativeWindowType = winapi::shared::windef::HWND;
|
||||
#[cfg(target_os = "linux")]
|
||||
pub type EGLNativeWindowType = *const libc::c_void;
|
||||
#[cfg(target_os = "android")]
|
||||
pub type EGLNativeWindowType = *const libc::c_void;
|
||||
#[cfg(any(target_os = "dragonfly", target_os = "freebsd", target_os = "openbsd"))]
|
||||
pub type EGLNativeWindowType = *const libc::c_void;
|
||||
|
||||
pub type khronos_utime_nanoseconds_t = khronos_uint64_t;
|
||||
pub type khronos_uint64_t = libc::uint64_t;
|
||||
pub type khronos_ssize_t = libc::c_long;
|
||||
|
@ -37,7 +26,6 @@ pub mod egl {
|
|||
|
||||
include!(concat!(env!("OUT_DIR"), "/egl_bindings.rs"));
|
||||
|
||||
#[cfg(target_os = "android")]
|
||||
pub fn init() -> Result<crate::gl_glue::ServoGl, &'static str> {
|
||||
info!("Loading EGL...");
|
||||
unsafe {
|
||||
|
@ -54,27 +42,6 @@ pub mod egl {
|
|||
Ok(egl)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
pub fn init() -> Result<crate::gl_glue::ServoGl, &'static str> {
|
||||
info!("Loading EGL...");
|
||||
|
||||
let dll = b"libEGL.dll\0" as &[u8];
|
||||
let dll = unsafe { LoadLibraryA(dll.as_ptr() as *const _) };
|
||||
if dll.is_null() {
|
||||
Err("Can't find libEGL.dll")
|
||||
} else {
|
||||
unsafe {
|
||||
let egl = GlesFns::load_with(|addr| {
|
||||
let addr = CString::new(addr.as_bytes()).unwrap();
|
||||
let addr = addr.as_ptr();
|
||||
GetProcAddress(dll, addr) as *const _
|
||||
});
|
||||
info!("EGL loaded");
|
||||
Ok(egl)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
|
|
|
@ -25,6 +25,7 @@ canvas2d-azure = ["simpleservo/canvas2d-azure"]
|
|||
canvas2d-raqote = ["simpleservo/canvas2d-raqote"]
|
||||
debugmozjs = ["simpleservo/debugmozjs"]
|
||||
default = ["webdriver", "max_log_level"]
|
||||
egl = ["simpleservo/egl"]
|
||||
energy-profiling = ["simpleservo/energy-profiling"]
|
||||
googlevr = ["simpleservo/googlevr"]
|
||||
js_backtrace = ["simpleservo/js_backtrace"]
|
||||
|
|
|
@ -12,6 +12,7 @@ fn main() {
|
|||
cbindgen::Builder::new()
|
||||
.with_crate(crate_dir)
|
||||
.with_language(cbindgen::Language::C)
|
||||
.exclude_item("OutputDebugStringA")
|
||||
.generate()
|
||||
.expect("Unable to generate bindings")
|
||||
.write_to_file(dest);
|
||||
|
|
|
@ -5,6 +5,10 @@
|
|||
#[macro_use]
|
||||
extern crate log;
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
mod vslogger;
|
||||
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
use env_logger;
|
||||
use simpleservo::{self, gl_glue, ServoGlue, SERVO};
|
||||
use simpleservo::{Coordinates, EventLoopWaker, HostTrait, InitOptions, VRInitOptions};
|
||||
|
@ -69,13 +73,33 @@ pub extern "C" fn servo_version() -> *const c_char {
|
|||
ptr
|
||||
}
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
fn init_logger() {
|
||||
use log::LevelFilter;
|
||||
use std::sync::Once;
|
||||
use vslogger::VSLogger;
|
||||
|
||||
static LOGGER: VSLogger = VSLogger;
|
||||
static LOGGER_INIT: Once = Once::new();
|
||||
LOGGER_INIT.call_once(|| {
|
||||
log::set_logger(&LOGGER)
|
||||
.map(|_| log::set_max_level(LevelFilter::Debug))
|
||||
.unwrap();
|
||||
});
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
fn init_logger() {
|
||||
crate::env_logger::init();
|
||||
}
|
||||
|
||||
fn init(
|
||||
opts: CInitOptions,
|
||||
gl: gl_glue::ServoGl,
|
||||
wakeup: extern "C" fn(),
|
||||
callbacks: CHostCallbacks,
|
||||
) {
|
||||
crate::env_logger::init();
|
||||
init_logger();
|
||||
|
||||
let args = if !opts.args.is_null() {
|
||||
let args = unsafe { CStr::from_ptr(opts.args) };
|
||||
|
@ -119,6 +143,7 @@ pub extern "C" fn init_with_egl(
|
|||
wakeup: extern "C" fn(),
|
||||
callbacks: CHostCallbacks,
|
||||
) {
|
||||
init_logger();
|
||||
let gl = gl_glue::egl::init().unwrap();
|
||||
init(opts, gl, wakeup, callbacks)
|
||||
}
|
||||
|
@ -130,6 +155,7 @@ pub extern "C" fn init_with_gl(
|
|||
wakeup: extern "C" fn(),
|
||||
callbacks: CHostCallbacks,
|
||||
) {
|
||||
init_logger();
|
||||
let gl = gl_glue::gl::init().unwrap();
|
||||
init(opts, gl, wakeup, callbacks)
|
||||
}
|
||||
|
|
28
ports/libsimpleservo/capi/src/vslogger.rs
Normal file
28
ports/libsimpleservo/capi/src/vslogger.rs
Normal file
|
@ -0,0 +1,28 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* 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 log::{self, Level, Metadata, Record};
|
||||
|
||||
extern "C" {
|
||||
fn OutputDebugStringA(s: *const u8);
|
||||
}
|
||||
|
||||
pub struct VSLogger;
|
||||
|
||||
impl log::Log for VSLogger {
|
||||
fn enabled(&self, metadata: &Metadata) -> bool {
|
||||
metadata.level() <= Level::Warn
|
||||
}
|
||||
|
||||
fn log(&self, record: &Record) {
|
||||
if self.enabled(record.metadata()) {
|
||||
let log = format!("RUST: {} - {}\r\n\0", record.level(), record.args());
|
||||
unsafe {
|
||||
OutputDebugStringA(log.as_ptr());
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
fn flush(&self) {}
|
||||
}
|
|
@ -30,6 +30,7 @@ canvas2d-azure = ["simpleservo/canvas2d-azure"]
|
|||
canvas2d-raqote = ["simpleservo/canvas2d-raqote"]
|
||||
debugmozjs = ["simpleservo/debugmozjs"]
|
||||
default = ["webdriver", "max_log_level"]
|
||||
egl = ["simpleservo/egl"]
|
||||
energy-profiling = ["simpleservo/energy-profiling"]
|
||||
googlevr = ["simpleservo/googlevr"]
|
||||
js_backtrace = ["simpleservo/js_backtrace"]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue