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

Replace usage of glutin with winit where it is possible #2772

Merged
merged 2 commits into from May 27, 2018
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Large diffs are not rendered by default.

@@ -10,4 +10,4 @@ gleam = "0.5"
mozangle = {version = "0.1", features = ["egl"]}
webrender = {path = "../webrender"}
winapi = {version = "0.3", features = ["winerror", "d3d11", "dcomp"]}
winit = "0.11"
winit = "0.13"
@@ -49,7 +49,7 @@ fn main() {
events_loop.run_forever(|event| {
if let winit::Event::WindowEvent { event, .. } = event {
match event {
winit::WindowEvent::Closed => {
winit::WindowEvent::CloseRequested => {
return winit::ControlFlow::Break
}
winit::WindowEvent::MouseWheel { delta, .. } => {
@@ -64,7 +64,8 @@ optional = true
mozangle = "0.1"
env_logger = "0.5"
rand = "0.3" # for the benchmarks
glutin = "0.13" # for the example apps
glutin = "0.15" # for the example apps
winit = "0.13" # for the example apps

[target.'cfg(any(target_os = "android", all(unix, not(target_os = "macos"))))'.dependencies]
freetype = { version = "0.4", default-features = false }
@@ -6,6 +6,7 @@ extern crate euclid;
extern crate gleam;
extern crate glutin;
extern crate webrender;
extern crate winit;

#[path = "common/boilerplate.rs"]
mod boilerplate;
@@ -51,25 +52,25 @@ impl Example for App {

fn on_event(
&mut self,
event: glutin::WindowEvent,
event: winit::WindowEvent,
_api: &RenderApi,
_document_id: DocumentId
) -> bool {
match event {
glutin::WindowEvent::KeyboardInput {
input: glutin::KeyboardInput {
state: glutin::ElementState::Pressed,
winit::WindowEvent::KeyboardInput {
input: winit::KeyboardInput {
state: winit::ElementState::Pressed,
virtual_keycode: Some(key),
..
},
..
} => {
match key {
glutin::VirtualKeyCode::Right => {
winit::VirtualKeyCode::Right => {
self.rect_count += 1;
println!("rects = {}", self.rect_count);
}
glutin::VirtualKeyCode::Left => {
winit::VirtualKeyCode::Left => {
self.rect_count = cmp::max(self.rect_count, 1) - 1;
println!("rects = {}", self.rect_count);
}
@@ -14,6 +14,7 @@ extern crate euclid;
extern crate gleam;
extern crate glutin;
extern crate webrender;
extern crate winit;

#[path = "common/boilerplate.rs"]
mod boilerplate;
@@ -74,25 +75,25 @@ impl Example for App {
builder.pop_stacking_context();
}

fn on_event(&mut self, win_event: glutin::WindowEvent, api: &RenderApi, document_id: DocumentId) -> bool {
fn on_event(&mut self, win_event: winit::WindowEvent, api: &RenderApi, document_id: DocumentId) -> bool {
match win_event {
glutin::WindowEvent::KeyboardInput {
input: glutin::KeyboardInput {
state: glutin::ElementState::Pressed,
winit::WindowEvent::KeyboardInput {
input: winit::KeyboardInput {
state: winit::ElementState::Pressed,
virtual_keycode: Some(key),
..
},
..
} => {
let (offset_x, offset_y, angle, delta_opacity) = match key {
glutin::VirtualKeyCode::Down => (0.0, 10.0, 0.0, 0.0),
glutin::VirtualKeyCode::Up => (0.0, -10.0, 0.0, 0.0),
glutin::VirtualKeyCode::Right => (10.0, 0.0, 0.0, 0.0),
glutin::VirtualKeyCode::Left => (-10.0, 0.0, 0.0, 0.0),
glutin::VirtualKeyCode::Comma => (0.0, 0.0, 0.1, 0.0),
glutin::VirtualKeyCode::Period => (0.0, 0.0, -0.1, 0.0),
glutin::VirtualKeyCode::Z => (0.0, 0.0, 0.0, -0.1),
glutin::VirtualKeyCode::X => (0.0, 0.0, 0.0, 0.1),
winit::VirtualKeyCode::Down => (0.0, 10.0, 0.0, 0.0),
winit::VirtualKeyCode::Up => (0.0, -10.0, 0.0, 0.0),
winit::VirtualKeyCode::Right => (10.0, 0.0, 0.0, 0.0),
winit::VirtualKeyCode::Left => (-10.0, 0.0, 0.0, 0.0),
winit::VirtualKeyCode::Comma => (0.0, 0.0, 0.1, 0.0),
winit::VirtualKeyCode::Period => (0.0, 0.0, -0.1, 0.0),
winit::VirtualKeyCode::Z => (0.0, 0.0, 0.0, -0.1),
winit::VirtualKeyCode::X => (0.0, 0.0, 0.0, 0.1),
_ => return false,
};
// Update the transform based on the keyboard input and push it to
@@ -7,13 +7,14 @@ extern crate euclid;
extern crate gleam;
extern crate glutin;
extern crate webrender;
extern crate winit;

#[path = "common/boilerplate.rs"]
mod boilerplate;

use boilerplate::{Example, HandyDandyRectBuilder};
use euclid::vec2;
use glutin::TouchPhase;
use winit::TouchPhase;
use std::collections::HashMap;
use webrender::api::*;

@@ -85,7 +86,7 @@ impl TouchState {
}
}

fn handle_event(&mut self, touch: glutin::Touch) -> TouchResult {
fn handle_event(&mut self, touch: winit::Touch) -> TouchResult {
match touch.phase {
TouchPhase::Started => {
debug_assert!(!self.active_touches.contains_key(&touch.id));
@@ -274,10 +275,10 @@ impl Example for App {
builder.pop_stacking_context();
}

fn on_event(&mut self, event: glutin::WindowEvent, api: &RenderApi, document_id: DocumentId) -> bool {
fn on_event(&mut self, event: winit::WindowEvent, api: &RenderApi, document_id: DocumentId) -> bool {
let mut txn = Transaction::new();
match event {
glutin::WindowEvent::Touch(touch) => match self.touch_state.handle_event(touch) {
winit::WindowEvent::Touch(touch) => match self.touch_state.handle_event(touch) {
TouchResult::Pan(pan) => {
txn.set_pan(pan);
}
@@ -6,6 +6,7 @@ extern crate gleam;
extern crate glutin;
extern crate rayon;
extern crate webrender;
extern crate winit;

#[path = "common/boilerplate.rs"]
mod boilerplate;
@@ -10,14 +10,15 @@ use glutin::{self, GlContext};
use std::env;
use std::path::PathBuf;
use webrender;
use winit;
use webrender::api::*;

struct Notifier {
events_proxy: glutin::EventsLoopProxy,
events_proxy: winit::EventsLoopProxy,
}

impl Notifier {
fn new(events_proxy: glutin::EventsLoopProxy) -> Notifier {
fn new(events_proxy: winit::EventsLoopProxy) -> Notifier {
Notifier { events_proxy }
}
}
@@ -76,7 +77,7 @@ pub trait Example {
pipeline_id: PipelineId,
document_id: DocumentId,
);
fn on_event(&mut self, glutin::WindowEvent, &RenderApi, DocumentId) -> bool {
fn on_event(&mut self, winit::WindowEvent, &RenderApi, DocumentId) -> bool {
false
}
fn get_image_handlers(
@@ -103,13 +104,13 @@ pub fn main_wrapper<E: Example>(
None
};

let mut events_loop = glutin::EventsLoop::new();
let mut events_loop = winit::EventsLoop::new();
let context_builder = glutin::ContextBuilder::new()
.with_gl(glutin::GlRequest::GlThenGles {
opengl_version: (3, 2),
opengles_version: (3, 0),
});
let window_builder = glutin::WindowBuilder::new()
let window_builder = winit::WindowBuilder::new()
.with_title(E::TITLE)
.with_multitouch()
.with_dimensions(E::WIDTH, E::HEIGHT);
@@ -196,39 +197,42 @@ pub fn main_wrapper<E: Example>(
let mut custom_event = true;

match global_event {
glutin::Event::WindowEvent { event: glutin::WindowEvent::Closed, .. } => return glutin::ControlFlow::Break,
glutin::Event::WindowEvent {
event: glutin::WindowEvent::KeyboardInput {
input: glutin::KeyboardInput {
state: glutin::ElementState::Pressed,
winit::Event::WindowEvent {
event: winit::WindowEvent::CloseRequested,
..
} => return winit::ControlFlow::Break,
winit::Event::WindowEvent {
event: winit::WindowEvent::KeyboardInput {
input: winit::KeyboardInput {
state: winit::ElementState::Pressed,
virtual_keycode: Some(key),
..
},
..
},
..
} => match key {
glutin::VirtualKeyCode::Escape => return glutin::ControlFlow::Break,
glutin::VirtualKeyCode::P => renderer.toggle_debug_flags(webrender::DebugFlags::PROFILER_DBG),
glutin::VirtualKeyCode::O => renderer.toggle_debug_flags(webrender::DebugFlags::RENDER_TARGET_DBG),
glutin::VirtualKeyCode::I => renderer.toggle_debug_flags(webrender::DebugFlags::TEXTURE_CACHE_DBG),
glutin::VirtualKeyCode::S => renderer.toggle_debug_flags(webrender::DebugFlags::COMPACT_PROFILER),
glutin::VirtualKeyCode::Q => renderer.toggle_debug_flags(
winit::VirtualKeyCode::Escape => return winit::ControlFlow::Break,
winit::VirtualKeyCode::P => renderer.toggle_debug_flags(webrender::DebugFlags::PROFILER_DBG),
winit::VirtualKeyCode::O => renderer.toggle_debug_flags(webrender::DebugFlags::RENDER_TARGET_DBG),
winit::VirtualKeyCode::I => renderer.toggle_debug_flags(webrender::DebugFlags::TEXTURE_CACHE_DBG),
winit::VirtualKeyCode::S => renderer.toggle_debug_flags(webrender::DebugFlags::COMPACT_PROFILER),
winit::VirtualKeyCode::Q => renderer.toggle_debug_flags(
webrender::DebugFlags::GPU_TIME_QUERIES | webrender::DebugFlags::GPU_SAMPLE_QUERIES
),
glutin::VirtualKeyCode::Key1 => txn.set_window_parameters(
winit::VirtualKeyCode::Key1 => txn.set_window_parameters(
framebuffer_size,
DeviceUintRect::new(DeviceUintPoint::zero(), framebuffer_size),
1.0
),
glutin::VirtualKeyCode::Key2 => txn.set_window_parameters(
winit::VirtualKeyCode::Key2 => txn.set_window_parameters(
framebuffer_size,
DeviceUintRect::new(DeviceUintPoint::zero(), framebuffer_size),
2.0
),
glutin::VirtualKeyCode::M => api.notify_memory_pressure(),
winit::VirtualKeyCode::M => api.notify_memory_pressure(),
#[cfg(feature = "capture")]
glutin::VirtualKeyCode::C => {
winit::VirtualKeyCode::C => {
let path: PathBuf = "../captures/example".into();
//TODO: switch between SCENE/FRAME capture types
// based on "shift" modifier, when `glutin` is updated.
@@ -237,14 +241,14 @@ pub fn main_wrapper<E: Example>(
},
_ => {
let win_event = match global_event {
glutin::Event::WindowEvent { event, .. } => event,
winit::Event::WindowEvent { event, .. } => event,
_ => unreachable!()
};
custom_event = example.on_event(win_event, &api, document_id)
},
},
glutin::Event::WindowEvent { event, .. } => custom_event = example.on_event(event, &api, document_id),
_ => return glutin::ControlFlow::Continue,
winit::Event::WindowEvent { event, .. } => custom_event = example.on_event(event, &api, document_id),
_ => return winit::ControlFlow::Continue,
};

if custom_event {
@@ -275,7 +279,7 @@ pub fn main_wrapper<E: Example>(
example.draw_custom(&*gl);
window.swap_buffers().ok();

glutin::ControlFlow::Continue
winit::ControlFlow::Continue
});

renderer.deinit();
@@ -6,6 +6,7 @@ extern crate euclid;
extern crate gleam;
extern crate glutin;
extern crate webrender;
extern crate winit;

#[path = "common/boilerplate.rs"]
mod boilerplate;
@@ -6,6 +6,7 @@ extern crate euclid;
extern crate gleam;
extern crate glutin;
extern crate webrender;
extern crate winit;

#[path = "common/boilerplate.rs"]
mod boilerplate;
@@ -5,6 +5,7 @@
extern crate gleam;
extern crate glutin;
extern crate webrender;
extern crate winit;

#[path = "common/boilerplate.rs"]
mod boilerplate;
@@ -5,6 +5,7 @@
extern crate gleam;
extern crate glutin;
extern crate webrender;
extern crate winit;

#[path = "common/boilerplate.rs"]
mod boilerplate;
@@ -80,12 +81,12 @@ impl Example for App {
builder.pop_stacking_context();
}

fn on_event(&mut self, event: glutin::WindowEvent, api: &RenderApi, document_id: DocumentId) -> bool {
fn on_event(&mut self, event: winit::WindowEvent, api: &RenderApi, document_id: DocumentId) -> bool {
match event {
glutin::WindowEvent::KeyboardInput {
input: glutin::KeyboardInput {
state: glutin::ElementState::Pressed,
virtual_keycode: Some(glutin::VirtualKeyCode::Space),
winit::WindowEvent::KeyboardInput {
input: winit::KeyboardInput {
state: winit::ElementState::Pressed,
virtual_keycode: Some(winit::VirtualKeyCode::Space),
..
},
..
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.