Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add UWP port #23658

Closed
wants to merge 7 commits into from
Closed

Add UWP port #23658

Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Next

implement Visual Studio logs

  • Loading branch information
paulrouget authored and jdm committed Jul 2, 2019
commit a46ca86a50e4538aaa4f700f6dd107429cd5da37
@@ -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};
@@ -66,13 +70,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) };
@@ -116,6 +140,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)
}
@@ -127,6 +152,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)
}
@@ -0,0 +1,24 @@
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) {}
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.