WR update: remove dependency on icon_loading feature

This commit is contained in:
Paul Rouget 2019-03-07 15:14:18 +01:00
parent a20455fd6b
commit 92a1336264
4 changed files with 58 additions and 69 deletions

33
Cargo.lock generated
View file

@ -1993,23 +1993,6 @@ dependencies = [
"unicode-normalization 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "image"
version = "0.20.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"byteorder 1.2.7 (registry+https://github.com/rust-lang/crates.io-index)",
"gif 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)",
"jpeg-decoder 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)",
"lzw 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)",
"num-iter 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)",
"num-rational 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"num-traits 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)",
"png 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
"scoped_threadpool 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
"tiff 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "image"
version = "0.21.0"
@ -3164,17 +3147,6 @@ dependencies = [
"num-traits 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "png"
version = "0.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
"deflate 0.7.19 (registry+https://github.com/rust-lang/crates.io-index)",
"inflate 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
"num-iter 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "png"
version = "0.14.0"
@ -3726,6 +3698,7 @@ dependencies = [
"euclid 0.19.5 (registry+https://github.com/rust-lang/crates.io-index)",
"gleam 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)",
"glutin 0.19.0 (registry+https://github.com/rust-lang/crates.io-index)",
"image 0.21.0 (registry+https://github.com/rust-lang/crates.io-index)",
"keyboard-types 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.44 (registry+https://github.com/rust-lang/crates.io-index)",
@ -3737,7 +3710,6 @@ dependencies = [
"sig 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"tinyfiledialogs 3.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
"winit 0.18.0 (registry+https://github.com/rust-lang/crates.io-index)",
"winres 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
"x11 2.17.3 (registry+https://github.com/rust-lang/crates.io-index)",
]
@ -5033,7 +5005,6 @@ dependencies = [
"cocoa 0.18.4 (registry+https://github.com/rust-lang/crates.io-index)",
"core-foundation 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)",
"core-graphics 0.17.3 (registry+https://github.com/rust-lang/crates.io-index)",
"image 0.20.1 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.44 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)",
@ -5344,7 +5315,6 @@ dependencies = [
"checksum hyper_serde 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "af6cd576f3bf6d7dabc34828c16a08c99e71dca01c87e4a5d754c6ea3995f3d9"
"checksum ident_case 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3c9826188e666f2ed92071d2dadef6edc430b11b158b5b2b3f4babbcc891eaaa"
"checksum idna 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "014b298351066f1512874135335d62a789ffe78a9974f94b43ed5621951eaf7d"
"checksum image 0.20.1 (registry+https://github.com/rust-lang/crates.io-index)" = "44665b4395d1844c96e7dc8ed5754782a1cdfd9ef458a80bbe45702681450504"
"checksum image 0.21.0 (registry+https://github.com/rust-lang/crates.io-index)" = "52fb0666a1273dac46f9725aa4859bcd5595fc3554cf3495051b4de8db745e7d"
"checksum immeta 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7371aa3c98fad60de2d9b517e2e1ed45593c32b0c77249310fa507749a2a318b"
"checksum indexmap 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7e81a7c05f79578dbc15793d8b619db9ba32b4577003ef3af1a91c416798c58d"
@ -5437,7 +5407,6 @@ dependencies = [
"checksum phf_shared 0.7.23 (registry+https://github.com/rust-lang/crates.io-index)" = "b539898d22d4273ded07f64a05737649dc69095d92cb87c7097ec68e3f150b93"
"checksum pkg-config 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)" = "676e8eb2b1b4c9043511a9b7bea0915320d7e502b0a079fb03f9635a5252b18c"
"checksum plane-split 0.13.7 (registry+https://github.com/rust-lang/crates.io-index)" = "9760bb0546502fcfae6d2d1d638fac6b9272027a3efae34060218152d0ce8387"
"checksum png 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f54b9600d584d3b8a739e1662a595fab051329eff43f20e7d8cc22872962145b"
"checksum png 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9adebf7fb91ccf5eac9da1a8e00e83cb8ae882c3e8d8e4ad59da73cb8c82a2c9"
"checksum podio 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "780fb4b6698bbf9cf2444ea5d22411cef2953f0824b98f33cf454ec5615645bd"
"checksum precomputed-hash 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c"

View file

@ -53,7 +53,9 @@ libc = "0.2"
log = "0.4"
rust-webvr = { version = "0.10.2", features = ["glwindow"] }
tinyfiledialogs = "3.0"
winit = {version = "0.18", features = ["icon_loading"]}
[target.'cfg(any(target_os = "linux", target_os = "windows"))'.dependencies]
image = "0.21"
[target.'cfg(any(target_os = "linux", target_os = "macos"))'.dependencies]
osmesa-sys = "0.1.2"

View file

@ -3,7 +3,7 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
use keyboard_types::{Code, Key, KeyboardEvent, KeyState, Modifiers, Location};
use winit::{ElementState, KeyboardInput, ModifiersState, VirtualKeyCode};
use glutin::{ElementState, KeyboardInput, ModifiersState, VirtualKeyCode};
// Some shortcuts use Cmd on Mac and Control on other systems.
#[cfg(target_os = "macos")]
@ -18,7 +18,7 @@ pub const CMD_OR_ALT: Modifiers = Modifiers::META;
pub const CMD_OR_ALT: Modifiers = Modifiers::ALT;
fn get_servo_key_from_winit_key(key: Option<VirtualKeyCode>) -> Key {
use winit::VirtualKeyCode::*;
use glutin::VirtualKeyCode::*;
// TODO: figure out how to map NavigateForward, NavigateBackward
// TODO: map the remaining keys if possible
let key = if let Some(key) = key {
@ -127,7 +127,7 @@ fn get_servo_key_from_winit_key(key: Option<VirtualKeyCode>) -> Key {
}
fn get_servo_location_from_winit_key(key: Option<VirtualKeyCode>) -> Location {
use winit::VirtualKeyCode::*;
use glutin::VirtualKeyCode::*;
// TODO: add more numpad keys
let key = if let Some(key) = key {
key

View file

@ -7,6 +7,8 @@
use euclid::{TypedPoint2D, TypedVector2D, TypedScale, TypedSize2D};
use gleam::gl;
use glutin::{Api, ContextBuilder, GlContext, GlRequest, GlWindow};
#[cfg(any(target_os = "linux", target_os = "windows"))]
use image;
use keyboard_types::{Key, KeyboardEvent, KeyState};
use rust_webvr::GlWindowVRService;
use servo::compositing::windowing::{AnimationState, MouseWindowEvent, WindowEvent};
@ -32,10 +34,12 @@ use std::time;
use super::keyutils::keyboard_event_from_winit;
#[cfg(target_os = "windows")]
use winapi;
use winit::{ElementState, Event, MouseButton, MouseScrollDelta, TouchPhase, KeyboardInput};
use winit::dpi::{LogicalPosition, LogicalSize, PhysicalSize};
use glutin::{ElementState, Event, MouseButton, MouseScrollDelta, TouchPhase, KeyboardInput};
#[cfg(any(target_os = "linux", target_os = "windows"))]
use glutin::Icon;
use glutin::dpi::{LogicalPosition, LogicalSize, PhysicalSize};
#[cfg(target_os = "macos")]
use winit::os::macos::{ActivationPolicy, WindowBuilderExt};
use glutin::os::macos::{ActivationPolicy, WindowBuilderExt};
// This should vary by zoom level and maybe actual text size (focused or under cursor)
pub const LINE_HEIGHT: f32 = 38.0;
@ -43,7 +47,7 @@ pub const LINE_HEIGHT: f32 = 38.0;
const MULTISAMPLES: u16 = 16;
#[cfg(target_os = "macos")]
fn builder_with_platform_options(mut builder: winit::WindowBuilder) -> winit::WindowBuilder {
fn builder_with_platform_options(mut builder: glutin::WindowBuilder) -> glutin::WindowBuilder {
if opts::get().headless || opts::get().output_file.is_some() {
// Prevent the window from showing in Dock.app, stealing focus,
// or appearing at all when running in headless mode or generating an
@ -54,7 +58,7 @@ fn builder_with_platform_options(mut builder: winit::WindowBuilder) -> winit::Wi
}
#[cfg(not(target_os = "macos"))]
fn builder_with_platform_options(builder: winit::WindowBuilder) -> winit::WindowBuilder {
fn builder_with_platform_options(builder: glutin::WindowBuilder) -> glutin::WindowBuilder {
builder
}
@ -132,7 +136,7 @@ impl HeadlessContext {
}
enum WindowKind {
Window(GlWindow, RefCell<winit::EventsLoop>),
Window(GlWindow, RefCell<glutin::EventsLoop>),
Headless(HeadlessContext),
}
@ -141,7 +145,7 @@ pub struct Window {
kind: WindowKind,
screen_size: TypedSize2D<u32, DeviceIndependentPixel>,
inner_size: Cell<TypedSize2D<u32, DeviceIndependentPixel>>,
mouse_down_button: Cell<Option<winit::MouseButton>>,
mouse_down_button: Cell<Option<glutin::MouseButton>>,
mouse_down_point: Cell<TypedPoint2D<i32, DevicePixel>>,
event_queue: RefCell<Vec<WindowEvent>>,
mouse_pos: Cell<TypedPoint2D<i32, DevicePixel>>,
@ -187,8 +191,8 @@ impl Window {
inner_size = TypedSize2D::new(width as u32, height as u32);
WindowKind::Headless(HeadlessContext::new(width as u32, height as u32))
} else {
let events_loop = winit::EventsLoop::new();
let mut window_builder = winit::WindowBuilder::new()
let events_loop = glutin::EventsLoop::new();
let mut window_builder = glutin::WindowBuilder::new()
.with_title("Servo".to_string())
.with_decorations(!opts::get().no_native_titlebar)
.with_transparency(opts::get().no_native_titlebar)
@ -196,13 +200,6 @@ impl Window {
.with_visibility(visible)
.with_multitouch();
#[cfg(any(target_os = "linux", target_os = "windows"))]
{
let icon_bytes = include_bytes!("../../../resources/servo64.png");
let icon = Some(winit::Icon::from_bytes(icon_bytes).expect("Failed to open icon"));
window_builder = window_builder.with_window_icon(icon);
}
window_builder = builder_with_platform_options(window_builder);
let mut context_builder = ContextBuilder::new()
@ -216,6 +213,12 @@ impl Window {
let glutin_window = GlWindow::new(window_builder, context_builder, &events_loop)
.expect("Failed to create window.");
#[cfg(any(target_os = "linux", target_os = "windows"))]
{
let icon_bytes = include_bytes!("../../../resources/servo64.png");
glutin_window.set_window_icon(Some(load_icon(icon_bytes)));
}
unsafe {
glutin_window
.context()
@ -362,9 +365,9 @@ impl Window {
}
}
if stop || self.is_animating() {
winit::ControlFlow::Break
glutin::ControlFlow::Break
} else {
winit::ControlFlow::Continue
glutin::ControlFlow::Continue
}
});
}
@ -442,7 +445,7 @@ impl Window {
}
}
fn winit_event_to_servo_event(&self, event: winit::Event) {
fn winit_event_to_servo_event(&self, event: glutin::Event) {
if let WindowKind::Window(ref window, _) = self.kind {
if let Event::WindowEvent { window_id, .. } = event {
if window.id() != window_id {
@ -452,19 +455,19 @@ impl Window {
}
match event {
Event::WindowEvent {
event: winit::WindowEvent::ReceivedCharacter(ch),
event: glutin::WindowEvent::ReceivedCharacter(ch),
..
} => self.handle_received_character(ch),
Event::WindowEvent {
event:
winit::WindowEvent::KeyboardInput {
glutin::WindowEvent::KeyboardInput {
input,
..
},
..
} => self.handle_keyboard_input(input),
Event::WindowEvent {
event: winit::WindowEvent::MouseInput { state, button, .. },
event: glutin::WindowEvent::MouseInput { state, button, .. },
..
} => {
if button == MouseButton::Left || button == MouseButton::Right {
@ -472,7 +475,7 @@ impl Window {
}
},
Event::WindowEvent {
event: winit::WindowEvent::CursorMoved { position, .. },
event: glutin::WindowEvent::CursorMoved { position, .. },
..
} => {
let pos = position.to_physical(self.device_hidpi_factor().get() as f64);
@ -485,7 +488,7 @@ impl Window {
)));
},
Event::WindowEvent {
event: winit::WindowEvent::MouseWheel { delta, phase, .. },
event: glutin::WindowEvent::MouseWheel { delta, phase, .. },
..
} => {
let (mut dx, mut dy) = match delta {
@ -510,7 +513,7 @@ impl Window {
self.event_queue.borrow_mut().push(event);
},
Event::WindowEvent {
event: winit::WindowEvent::Touch(touch),
event: glutin::WindowEvent::Touch(touch),
..
} => {
use servo::script_traits::TouchId;
@ -526,17 +529,17 @@ impl Window {
.push(WindowEvent::Touch(phase, id, point));
},
Event::WindowEvent {
event: winit::WindowEvent::Refresh,
event: glutin::WindowEvent::Refresh,
..
} => self.event_queue.borrow_mut().push(WindowEvent::Refresh),
Event::WindowEvent {
event: winit::WindowEvent::CloseRequested,
event: glutin::WindowEvent::CloseRequested,
..
} => {
self.event_queue.borrow_mut().push(WindowEvent::Quit);
},
Event::WindowEvent {
event: winit::WindowEvent::Resized(size),
event: glutin::WindowEvent::Resized(size),
..
} => {
// size is DeviceIndependentPixel.
@ -569,8 +572,8 @@ impl Window {
/// Helper function to handle a click
fn handle_mouse(
&self,
button: winit::MouseButton,
action: winit::ElementState,
button: glutin::MouseButton,
action: glutin::ElementState,
coords: TypedPoint2D<i32, DevicePixel>,
) {
use servo::script_traits::MouseButton;
@ -629,7 +632,7 @@ impl Window {
pub fn set_cursor(&self, cursor: Cursor) {
match self.kind {
WindowKind::Window(ref window, ..) => {
use winit::MouseCursor;
use glutin::MouseCursor;
let winit_cursor = match cursor {
Cursor::Default => MouseCursor::Default,
@ -741,7 +744,7 @@ impl WindowMethods for Window {
fn create_event_loop_waker(&self) -> Box<dyn EventLoopWaker> {
struct GlutinEventLoopWaker {
proxy: Option<Arc<winit::EventsLoopProxy>>,
proxy: Option<Arc<glutin::EventsLoopProxy>>,
}
impl GlutinEventLoopWaker {
fn new(window: &Window) -> GlutinEventLoopWaker {
@ -799,7 +802,7 @@ impl WindowMethods for Window {
let name = String::from("Test VR Display");
let size = self.inner_size.get().to_f64();
let size = LogicalSize::new(size.width, size.height);
let mut window_builder = winit::WindowBuilder::new()
let mut window_builder = glutin::WindowBuilder::new()
.with_title(name.clone())
.with_dimensions(size)
.with_visibility(false)
@ -828,3 +831,18 @@ fn winit_phase_to_touch_event_type(phase: TouchPhase) -> TouchEventType {
TouchPhase::Cancelled => TouchEventType::Cancel,
}
}
#[cfg(any(target_os = "linux", target_os = "windows"))]
fn load_icon(icon_bytes: &[u8]) -> Icon {
let (icon_rgba, icon_width, icon_height) = {
use image::{GenericImageView, Pixel};
let image = image::load_from_memory(icon_bytes).expect("Failed to load icon");;
let (width, height) = image.dimensions();
let mut rgba = Vec::with_capacity((width * height) as usize * 4);
for (_, _, pixel) in image.pixels() {
rgba.extend_from_slice(&pixel.to_rgba().data);
}
(rgba, width, height)
};
Icon::from_rgba(icon_rgba, icon_width, icon_height).expect("Failed to load icon")
}