Implement headless rendering
This commit is contained in:
parent
cfb0cb7001
commit
e565bfeb13
17 changed files with 791 additions and 518 deletions
|
|
@ -1,4 +1,10 @@
|
|||
use {Event, WindowBuilder};
|
||||
use Event;
|
||||
|
||||
#[cfg(feature = "window")]
|
||||
use WindowBuilder;
|
||||
|
||||
#[cfg(feature = "headless")]
|
||||
use HeadlessRendererBuilder;
|
||||
|
||||
use cocoa::base::{id, NSUInteger, nil};
|
||||
use cocoa::appkit::*;
|
||||
|
|
@ -11,6 +17,14 @@ pub struct Window {
|
|||
context: id,
|
||||
}
|
||||
|
||||
pub struct HeadlessContext(Window);
|
||||
|
||||
impl Deref<Window> for HeadlessContext {
|
||||
fn deref(&self) -> &Window {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
pub struct MonitorID;
|
||||
|
||||
pub fn get_available_monitors() -> Vec<MonitorID> {
|
||||
|
|
@ -31,14 +45,28 @@ impl MonitorID {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "window")]
|
||||
impl Window {
|
||||
pub fn new(_builder: WindowBuilder) -> Result<Window, String> {
|
||||
pub fn new(builder: WindowBuilder) -> Result<Window, String> {
|
||||
Window::new_impl(builder.dimensions, builder.title.as_slice(), true)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "headless")]
|
||||
impl HeadlessContext {
|
||||
pub fn new(builder: HeadlessRendererBuilder) -> Result<HeadlessContext, String> {
|
||||
Window::new_impl(Some(builder.dimensions), "", false)
|
||||
.map(|w| HeadlessContext(w))
|
||||
}
|
||||
}
|
||||
|
||||
impl Window {
|
||||
fn new_impl(dimensions: Option<(uint, uint)>, title: &str, visible: bool) -> Result<Window, String> {
|
||||
let app = match Window::create_app() {
|
||||
Some(app) => app,
|
||||
None => { return Err(format!("Couldn't create NSApplication")); },
|
||||
};
|
||||
let window = match Window::create_window(_builder.dimensions.unwrap_or((800, 600)), _builder.title.as_slice()) {
|
||||
let window = match Window::create_window(dimensions.unwrap_or((800, 600)), title) {
|
||||
Some(window) => window,
|
||||
None => { return Err(format!("Couldn't create NSWindow")); },
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue