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

Update canvas_nanovg example #466

Merged
merged 1 commit into from
Jun 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions examples/canvas_nanovg/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,11 @@ path = "../../resources"
path = "../../simd"

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

[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]
jemallocator = "0.3"
24 changes: 14 additions & 10 deletions examples/canvas_nanovg/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ use std::sync::Arc;
use std::time::Instant;
use surfman::{Connection, ContextAttributeFlags, ContextAttributes, GLVersion as SurfmanGLVersion};
use surfman::{SurfaceAccess, SurfaceType};

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))]
use jemallocator;
Expand Down Expand Up @@ -1465,14 +1467,14 @@ impl DemoData {

fn main() {
// 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 logical_size = LogicalSize::new(window_size.width as f64, window_size.height as f64);
let window = WindowBuilder::new().with_title("NanoVG example port")
.with_dimensions(logical_size)
.with_inner_size(logical_size)
.build(&event_loop)
.unwrap();
window.show();
// window.show();

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

// Make the OpenGL context via `surfman`, and load OpenGL functions.
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)
.unwrap();
device.bind_surface_to_context(&mut gl_context, surface).unwrap();
device.make_context_current(&gl_context).unwrap();
gl::load_with(|symbol_name| device.get_proc_address(&gl_context, symbol_name));

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

// Load demo data.
let resources = FilesystemResourceLoader::locate();
Expand Down Expand Up @@ -1591,7 +1593,7 @@ fn main() {
gpu_graph.push(gpu_time);
}

event_loop.poll_events(|event| {
event_loop.run_return(|event,_, control| {
match event {
Event::WindowEvent { event: WindowEvent::CloseRequested, .. } |
Event::WindowEvent {
Expand All @@ -1604,7 +1606,9 @@ fn main() {
Event::WindowEvent { event: WindowEvent::CursorMoved { position, .. }, .. } => {
mouse_position = vec2f(position.x as f32, position.y as f32);
}
_ => {}
_ => {
*control = ControlFlow::Exit;
}
}
});
}
Expand Down