Skip to content

Commit 62fbfcc

Browse files
authored
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.
2 parents db84359 + 4744587 commit 62fbfcc

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

examples/canvas_nanovg/Cargo.toml

+2-3
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,11 @@ path = "../../resources"
5151
path = "../../simd"
5252

5353
[dependencies.surfman]
54-
git = "https://github.com/servo/surfman"
55-
rev = "f3df871ac8c3926fe9106d86a3e51e20aa50d3cc"
54+
version = "^0.4"
5655
features = ["sm-winit", "sm-x11"]
5756

5857
[dependencies.winit]
59-
version = "<0.19.4" # 0.19.4 causes build errors https://github.com/rust-windowing/winit/pull/1105
58+
version = "^0.24" # 0.19.4 causes build errors https://github.com/rust-windowing/winit/pull/1105
6059

6160
[target.'cfg(not(windows))'.dependencies]
6261
jemallocator = "0.3"

examples/canvas_nanovg/src/main.rs

+14-10
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,10 @@ use std::sync::Arc;
4343
use std::time::Instant;
4444
use surfman::{Connection, ContextAttributeFlags, ContextAttributes, GLVersion as SurfmanGLVersion};
4545
use surfman::{SurfaceAccess, SurfaceType};
46+
4647
use winit::dpi::LogicalSize;
47-
use winit::{Event, EventsLoop, KeyboardInput, VirtualKeyCode, WindowBuilder, WindowEvent};
48+
use winit::platform::run_return::EventLoopExtRunReturn;
49+
use winit::{event::{Event, WindowEvent, KeyboardInput, VirtualKeyCode}, window::WindowBuilder, event_loop::{EventLoop, ControlFlow}};
4850

4951
#[cfg(not(windows))]
5052
use jemallocator;
@@ -1465,14 +1467,14 @@ impl DemoData {
14651467

14661468
fn main() {
14671469
// Open a window.
1468-
let mut event_loop = EventsLoop::new();
1470+
let mut event_loop = EventLoop::new();
14691471
let window_size = Size2D::new(WINDOW_WIDTH, WINDOW_HEIGHT);
14701472
let logical_size = LogicalSize::new(window_size.width as f64, window_size.height as f64);
14711473
let window = WindowBuilder::new().with_title("NanoVG example port")
1472-
.with_dimensions(logical_size)
1474+
.with_inner_size(logical_size)
14731475
.build(&event_loop)
14741476
.unwrap();
1475-
window.show();
1477+
// window.show();
14761478

14771479
// Create a `surfman` device. On a multi-GPU system, we'll request the low-power integrated
14781480
// GPU.
@@ -1490,17 +1492,17 @@ fn main() {
14901492

14911493
// Make the OpenGL context via `surfman`, and load OpenGL functions.
14921494
let surface_type = SurfaceType::Widget { native_widget };
1493-
let mut gl_context = device.create_context(&context_descriptor).unwrap();
1495+
let mut gl_context = device.create_context(&context_descriptor, None).unwrap();
14941496
let surface = device.create_surface(&gl_context, SurfaceAccess::GPUOnly, surface_type)
14951497
.unwrap();
14961498
device.bind_surface_to_context(&mut gl_context, surface).unwrap();
14971499
device.make_context_current(&gl_context).unwrap();
14981500
gl::load_with(|symbol_name| device.get_proc_address(&gl_context, symbol_name));
14991501

15001502
// Get the real size of the window, taking HiDPI into account.
1501-
let hidpi_factor = window.get_current_monitor().get_hidpi_factor();
1502-
let physical_size = logical_size.to_physical(hidpi_factor);
1503-
let framebuffer_size = vec2i(physical_size.width as i32, physical_size.height as i32);
1503+
let hidpi_factor = window.current_monitor().unwrap().scale_factor();
1504+
let physical_size = logical_size.to_physical::<i32>(hidpi_factor);
1505+
let framebuffer_size = vec2i(physical_size.width, physical_size.height);
15041506

15051507
// Load demo data.
15061508
let resources = FilesystemResourceLoader::locate();
@@ -1591,7 +1593,7 @@ fn main() {
15911593
gpu_graph.push(gpu_time);
15921594
}
15931595

1594-
event_loop.poll_events(|event| {
1596+
event_loop.run_return(|event,_, control| {
15951597
match event {
15961598
Event::WindowEvent { event: WindowEvent::CloseRequested, .. } |
15971599
Event::WindowEvent {
@@ -1604,7 +1606,9 @@ fn main() {
16041606
Event::WindowEvent { event: WindowEvent::CursorMoved { position, .. }, .. } => {
16051607
mouse_position = vec2f(position.x as f32, position.y as f32);
16061608
}
1607-
_ => {}
1609+
_ => {
1610+
*control = ControlFlow::Exit;
1611+
}
16081612
}
16091613
});
16101614
}

0 commit comments

Comments
 (0)