mirror of
https://github.com/servo/servo.git
synced 2025-08-25 23:28:21 +01:00
Use a test VRDisplay that renders to a GL window
This commit is contained in:
parent
de3d2f7495
commit
cc2d203151
12 changed files with 95 additions and 13 deletions
|
@ -18,7 +18,7 @@ use servo::script_traits::{MouseButton, TouchEventType, TouchId};
|
|||
use servo::servo_config::opts;
|
||||
use servo::servo_config::prefs::{PrefValue, PREFS};
|
||||
use servo::servo_url::ServoUrl;
|
||||
use servo::webvr::{VRExternalShmemPtr, VRServiceManager};
|
||||
use servo::webvr::{VRExternalShmemPtr, VRMainThreadHeartbeat, VRServiceManager};
|
||||
use servo::{self, gl, webrender_api, BrowserId, Servo};
|
||||
use std::cell::{Cell, RefCell};
|
||||
use std::mem;
|
||||
|
@ -536,7 +536,11 @@ impl WindowMethods for ServoCallbacks {
|
|||
}
|
||||
}
|
||||
|
||||
fn register_vr_services(&self, services: &mut VRServiceManager) {
|
||||
fn register_vr_services(
|
||||
&self,
|
||||
services: &mut VRServiceManager,
|
||||
_: &mut Vec<Box<VRMainThreadHeartbeat>>,
|
||||
) {
|
||||
if let Some(ptr) = self.vr_pointer {
|
||||
services.register_vrexternal(VRExternalShmemPtr::new(ptr));
|
||||
}
|
||||
|
|
|
@ -51,6 +51,7 @@ lazy_static = "1"
|
|||
libservo = {path = "../../components/servo"}
|
||||
libc = "0.2"
|
||||
log = "0.4"
|
||||
rust-webvr = { version = "0.10.2", features = ["glwindow"] }
|
||||
tinyfiledialogs = "3.0"
|
||||
winit = {version = "0.18", features = ["icon_loading"]}
|
||||
|
||||
|
|
|
@ -8,14 +8,18 @@ use euclid::{TypedPoint2D, TypedVector2D, TypedScale, TypedSize2D};
|
|||
use gleam::gl;
|
||||
use glutin::{Api, ContextBuilder, GlContext, GlRequest, GlWindow};
|
||||
use keyboard_types::{Key, KeyboardEvent, KeyState};
|
||||
use rust_webvr::GlWindowVRService;
|
||||
use servo::compositing::windowing::{AnimationState, MouseWindowEvent, WindowEvent};
|
||||
use servo::compositing::windowing::{EmbedderCoordinates, WindowMethods};
|
||||
use servo::embedder_traits::{Cursor, EventLoopWaker};
|
||||
use servo::script_traits::TouchEventType;
|
||||
use servo::servo_config::opts;
|
||||
use servo::servo_config::prefs::PREFS;
|
||||
use servo::servo_geometry::DeviceIndependentPixel;
|
||||
use servo::style_traits::DevicePixel;
|
||||
use servo::webrender_api::{DeviceIntPoint, DeviceIntRect, DeviceIntSize, ScrollLocation};
|
||||
use servo::webvr::VRServiceManager;
|
||||
use servo::webvr_traits::WebVRMainThreadHeartbeat;
|
||||
use std::cell::{Cell, RefCell};
|
||||
#[cfg(any(target_os = "linux", target_os = "macos"))]
|
||||
use std::ffi::CString;
|
||||
|
@ -440,6 +444,13 @@ impl Window {
|
|||
}
|
||||
|
||||
fn winit_event_to_servo_event(&self, event: winit::Event) {
|
||||
if let WindowKind::Window(ref window, _) = self.kind {
|
||||
if let Event::WindowEvent { window_id, .. } = event {
|
||||
if window.id() != window_id {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
match event {
|
||||
Event::WindowEvent {
|
||||
event: winit::WindowEvent::ReceivedCharacter(ch),
|
||||
|
@ -775,6 +786,39 @@ impl WindowMethods for Window {
|
|||
};
|
||||
true
|
||||
}
|
||||
|
||||
fn register_vr_services(
|
||||
&self,
|
||||
services: &mut VRServiceManager,
|
||||
heartbeats: &mut Vec<Box<WebVRMainThreadHeartbeat>>
|
||||
) {
|
||||
if PREFS.get("dom.webvr.test").as_boolean().unwrap_or(false) {
|
||||
warn!("Creating test VR display");
|
||||
// TODO: support dom.webvr.test in headless environments
|
||||
if let WindowKind::Window(_, ref events_loop) = self.kind {
|
||||
// This is safe, because register_vr_services is called from the main thread.
|
||||
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()
|
||||
.with_title(name.clone())
|
||||
.with_dimensions(size)
|
||||
.with_visibility(false)
|
||||
.with_multitouch();
|
||||
window_builder = builder_with_platform_options(window_builder);
|
||||
let context_builder = ContextBuilder::new()
|
||||
.with_gl(Window::gl_version())
|
||||
.with_vsync(false); // Assume the browser vsync is the same as the test VR window vsync
|
||||
let gl_window = GlWindow::new(window_builder, context_builder, &*events_loop.borrow())
|
||||
.expect("Failed to create window.");
|
||||
let gl = self.gl.clone();
|
||||
let (service, heartbeat) = GlWindowVRService::new(name, gl_window, gl);
|
||||
|
||||
services.register(Box::new(service));
|
||||
heartbeats.push(Box::new(heartbeat));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn winit_phase_to_touch_event_type(phase: TouchPhase) -> TouchEventType {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue