Auto merge of #466 - laptou:master, r=jdm
Update canvas_nanovg example The `canvas_nanovg` example would not run on my Linux machine due to the bug in `winit` 0.19 (rust-windowing/winit#1773) In this PR, I updated `winit` and `surfman` and made the minimum necessary changes so that the example would compile and run.
This commit is contained in:
commit
62fbfcc91c
|
@ -51,12 +51,11 @@ path = "../../resources"
|
||||||
path = "../../simd"
|
path = "../../simd"
|
||||||
|
|
||||||
[dependencies.surfman]
|
[dependencies.surfman]
|
||||||
git = "https://github.com/servo/surfman"
|
version = "^0.4"
|
||||||
rev = "f3df871ac8c3926fe9106d86a3e51e20aa50d3cc"
|
|
||||||
features = ["sm-winit", "sm-x11"]
|
features = ["sm-winit", "sm-x11"]
|
||||||
|
|
||||||
[dependencies.winit]
|
[dependencies.winit]
|
||||||
version = "<0.19.4" # 0.19.4 causes build errors https://github.com/rust-windowing/winit/pull/1105
|
version = "^0.24" # 0.19.4 causes build errors https://github.com/rust-windowing/winit/pull/1105
|
||||||
|
|
||||||
[target.'cfg(not(windows))'.dependencies]
|
[target.'cfg(not(windows))'.dependencies]
|
||||||
jemallocator = "0.3"
|
jemallocator = "0.3"
|
||||||
|
|
|
@ -43,8 +43,10 @@ use std::sync::Arc;
|
||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
use surfman::{Connection, ContextAttributeFlags, ContextAttributes, GLVersion as SurfmanGLVersion};
|
use surfman::{Connection, ContextAttributeFlags, ContextAttributes, GLVersion as SurfmanGLVersion};
|
||||||
use surfman::{SurfaceAccess, SurfaceType};
|
use surfman::{SurfaceAccess, SurfaceType};
|
||||||
|
|
||||||
use winit::dpi::LogicalSize;
|
use winit::dpi::LogicalSize;
|
||||||
use winit::{Event, EventsLoop, KeyboardInput, VirtualKeyCode, WindowBuilder, WindowEvent};
|
use winit::platform::run_return::EventLoopExtRunReturn;
|
||||||
|
use winit::{event::{Event, WindowEvent, KeyboardInput, VirtualKeyCode}, window::WindowBuilder, event_loop::{EventLoop, ControlFlow}};
|
||||||
|
|
||||||
#[cfg(not(windows))]
|
#[cfg(not(windows))]
|
||||||
use jemallocator;
|
use jemallocator;
|
||||||
|
@ -1465,14 +1467,14 @@ impl DemoData {
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
// Open a window.
|
// Open a window.
|
||||||
let mut event_loop = EventsLoop::new();
|
let mut event_loop = EventLoop::new();
|
||||||
let window_size = Size2D::new(WINDOW_WIDTH, WINDOW_HEIGHT);
|
let window_size = Size2D::new(WINDOW_WIDTH, WINDOW_HEIGHT);
|
||||||
let logical_size = LogicalSize::new(window_size.width as f64, window_size.height as f64);
|
let logical_size = LogicalSize::new(window_size.width as f64, window_size.height as f64);
|
||||||
let window = WindowBuilder::new().with_title("NanoVG example port")
|
let window = WindowBuilder::new().with_title("NanoVG example port")
|
||||||
.with_dimensions(logical_size)
|
.with_inner_size(logical_size)
|
||||||
.build(&event_loop)
|
.build(&event_loop)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
window.show();
|
// window.show();
|
||||||
|
|
||||||
// Create a `surfman` device. On a multi-GPU system, we'll request the low-power integrated
|
// Create a `surfman` device. On a multi-GPU system, we'll request the low-power integrated
|
||||||
// GPU.
|
// GPU.
|
||||||
|
@ -1490,7 +1492,7 @@ fn main() {
|
||||||
|
|
||||||
// Make the OpenGL context via `surfman`, and load OpenGL functions.
|
// Make the OpenGL context via `surfman`, and load OpenGL functions.
|
||||||
let surface_type = SurfaceType::Widget { native_widget };
|
let surface_type = SurfaceType::Widget { native_widget };
|
||||||
let mut gl_context = device.create_context(&context_descriptor).unwrap();
|
let mut gl_context = device.create_context(&context_descriptor, None).unwrap();
|
||||||
let surface = device.create_surface(&gl_context, SurfaceAccess::GPUOnly, surface_type)
|
let surface = device.create_surface(&gl_context, SurfaceAccess::GPUOnly, surface_type)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
device.bind_surface_to_context(&mut gl_context, surface).unwrap();
|
device.bind_surface_to_context(&mut gl_context, surface).unwrap();
|
||||||
|
@ -1498,9 +1500,9 @@ fn main() {
|
||||||
gl::load_with(|symbol_name| device.get_proc_address(&gl_context, symbol_name));
|
gl::load_with(|symbol_name| device.get_proc_address(&gl_context, symbol_name));
|
||||||
|
|
||||||
// Get the real size of the window, taking HiDPI into account.
|
// Get the real size of the window, taking HiDPI into account.
|
||||||
let hidpi_factor = window.get_current_monitor().get_hidpi_factor();
|
let hidpi_factor = window.current_monitor().unwrap().scale_factor();
|
||||||
let physical_size = logical_size.to_physical(hidpi_factor);
|
let physical_size = logical_size.to_physical::<i32>(hidpi_factor);
|
||||||
let framebuffer_size = vec2i(physical_size.width as i32, physical_size.height as i32);
|
let framebuffer_size = vec2i(physical_size.width, physical_size.height);
|
||||||
|
|
||||||
// Load demo data.
|
// Load demo data.
|
||||||
let resources = FilesystemResourceLoader::locate();
|
let resources = FilesystemResourceLoader::locate();
|
||||||
|
@ -1591,7 +1593,7 @@ fn main() {
|
||||||
gpu_graph.push(gpu_time);
|
gpu_graph.push(gpu_time);
|
||||||
}
|
}
|
||||||
|
|
||||||
event_loop.poll_events(|event| {
|
event_loop.run_return(|event,_, control| {
|
||||||
match event {
|
match event {
|
||||||
Event::WindowEvent { event: WindowEvent::CloseRequested, .. } |
|
Event::WindowEvent { event: WindowEvent::CloseRequested, .. } |
|
||||||
Event::WindowEvent {
|
Event::WindowEvent {
|
||||||
|
@ -1604,7 +1606,9 @@ fn main() {
|
||||||
Event::WindowEvent { event: WindowEvent::CursorMoved { position, .. }, .. } => {
|
Event::WindowEvent { event: WindowEvent::CursorMoved { position, .. }, .. } => {
|
||||||
mouse_position = vec2f(position.x as f32, position.y as f32);
|
mouse_position = vec2f(position.x as f32, position.y as f32);
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {
|
||||||
|
*control = ControlFlow::Exit;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue