mirror of
https://github.com/servo/servo.git
synced 2025-08-12 17:05:33 +01:00
Switch android to glutin.
This commit is contained in:
parent
80756a11d2
commit
9d192de63d
8 changed files with 268 additions and 91 deletions
|
@ -15,11 +15,11 @@ use compositing::windowing::{Forward, Back};
|
|||
use geom::point::{Point2D, TypedPoint2D};
|
||||
use geom::scale_factor::ScaleFactor;
|
||||
use geom::size::TypedSize2D;
|
||||
use gleam::gl;
|
||||
use layers::geometry::DevicePixel;
|
||||
use layers::platform::surface::NativeGraphicsMetadata;
|
||||
use msg::compositor_msg::{IdlePaintState, PaintState, PaintingPaintState};
|
||||
use msg::compositor_msg::{FinishedLoading, Blank, Loading, PerformingLayout, ReadyState};
|
||||
use msg::constellation_msg::LoadData;
|
||||
use std::cell::{Cell, RefCell};
|
||||
use std::rc::Rc;
|
||||
use time::{mod, Timespec};
|
||||
|
@ -28,14 +28,14 @@ use util::opts::{RenderApi, Mesa, OpenGL};
|
|||
use glutin;
|
||||
use NestedEventLoopListener;
|
||||
|
||||
#[cfg(not(target_os="android"))]
|
||||
use gleam::gl;
|
||||
|
||||
#[cfg(target_os="linux")]
|
||||
use std::ptr;
|
||||
|
||||
struct HeadlessContext {
|
||||
// Although currently unused, this context needs to be stored.
|
||||
// Otherwise, its drop() is called, deleting the mesa context
|
||||
// before it can be used.
|
||||
_context: glutin::HeadlessContext,
|
||||
context: glutin::HeadlessContext,
|
||||
size: TypedSize2D<DevicePixel, uint>,
|
||||
}
|
||||
|
||||
|
@ -72,6 +72,28 @@ pub struct Window {
|
|||
last_title_set_time: Cell<Timespec>,
|
||||
}
|
||||
|
||||
#[cfg(not(target_os="android"))]
|
||||
fn load_gl_functions(glutin: &WindowHandle) {
|
||||
match glutin {
|
||||
&Windowed(ref window) => gl::load_with(|s| window.get_proc_address(s)),
|
||||
&Headless(ref headless) => gl::load_with(|s| headless.context.get_proc_address(s)),
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(target_os="android")]
|
||||
fn load_gl_functions(_glutin: &WindowHandle) {
|
||||
}
|
||||
|
||||
#[cfg(not(target_os="android"))]
|
||||
fn gl_version() -> (uint, uint) {
|
||||
(3, 0)
|
||||
}
|
||||
|
||||
#[cfg(target_os="android")]
|
||||
fn gl_version() -> (uint, uint) {
|
||||
(2, 0)
|
||||
}
|
||||
|
||||
impl Window {
|
||||
/// Creates a new window.
|
||||
pub fn new(is_foreground: bool, size: TypedSize2D<DevicePixel, uint>, render_api: RenderApi)
|
||||
|
@ -85,14 +107,12 @@ impl Window {
|
|||
let glutin_window = glutin::WindowBuilder::new()
|
||||
.with_title("Servo [glutin]".to_string())
|
||||
.with_dimensions(window_size.width, window_size.height)
|
||||
.with_gl_version((3, 0))
|
||||
.with_gl_version(gl_version())
|
||||
.with_visibility(is_foreground)
|
||||
.build()
|
||||
.unwrap();
|
||||
unsafe { glutin_window.make_current() };
|
||||
|
||||
gl::load_with(|s| glutin_window.get_proc_address(s));
|
||||
|
||||
Windowed(glutin_window)
|
||||
}
|
||||
Mesa => {
|
||||
|
@ -101,15 +121,15 @@ impl Window {
|
|||
let headless_context = headless_builder.build().unwrap();
|
||||
unsafe { headless_context.make_current() };
|
||||
|
||||
gl::load_with(|s| headless_context.get_proc_address(s));
|
||||
|
||||
Headless(HeadlessContext {
|
||||
_context: headless_context,
|
||||
context: headless_context,
|
||||
size: size,
|
||||
})
|
||||
}
|
||||
};
|
||||
|
||||
load_gl_functions(&glutin);
|
||||
|
||||
let window = Window {
|
||||
glutin: glutin,
|
||||
event_queue: RefCell::new(vec!()),
|
||||
|
@ -184,6 +204,22 @@ impl WindowMethods for Window {
|
|||
ScaleFactor(1.0)
|
||||
}
|
||||
|
||||
fn set_page_title(&self, _: Option<String>) {
|
||||
// TODO(gw)
|
||||
}
|
||||
|
||||
fn set_page_load_data(&self, _: LoadData) {
|
||||
// TODO(gw)
|
||||
}
|
||||
|
||||
fn load_end(&self) {
|
||||
// TODO(gw)
|
||||
}
|
||||
|
||||
fn prepare_for_composite(&self) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
#[cfg(target_os="linux")]
|
||||
fn native_metadata(&self) -> NativeGraphicsMetadata {
|
||||
match self.glutin {
|
||||
|
@ -209,6 +245,14 @@ impl WindowMethods for Window {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(target_os="android")]
|
||||
fn native_metadata(&self) -> NativeGraphicsMetadata {
|
||||
use egl::egl::GetCurrentDisplay;
|
||||
NativeGraphicsMetadata {
|
||||
display: GetCurrentDisplay(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Window {
|
||||
|
@ -416,7 +460,7 @@ impl Window {
|
|||
match self.glutin {
|
||||
Windowed(ref window) => {
|
||||
let mut close_event = false;
|
||||
for event in window.poll_events() {
|
||||
for event in window.wait_events() {
|
||||
close_event = self.handle_window_event(event);
|
||||
if close_event {
|
||||
break;
|
||||
|
@ -453,3 +497,48 @@ impl CompositorProxy for GlutinCompositorProxy {
|
|||
} as Box<CompositorProxy+Send>
|
||||
}
|
||||
}
|
||||
|
||||
// These functions aren't actually called. They are here as a link
|
||||
// hack because Skia references them.
|
||||
|
||||
#[allow(non_snake_case)]
|
||||
#[no_mangle]
|
||||
pub extern "C" fn glBindVertexArrayOES(_array: uint)
|
||||
{
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
#[allow(non_snake_case)]
|
||||
#[no_mangle]
|
||||
pub extern "C" fn glDeleteVertexArraysOES(_n: int, _arrays: *const ())
|
||||
{
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
#[allow(non_snake_case)]
|
||||
#[no_mangle]
|
||||
pub extern "C" fn glGenVertexArraysOES(_n: int, _arrays: *const ())
|
||||
{
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
#[allow(non_snake_case)]
|
||||
#[no_mangle]
|
||||
pub extern "C" fn glRenderbufferStorageMultisampleIMG(_: int, _: int, _: int, _: int, _: int)
|
||||
{
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
#[allow(non_snake_case)]
|
||||
#[no_mangle]
|
||||
pub extern "C" fn glFramebufferTexture2DMultisampleIMG(_: int, _: int, _: int, _: int, _: int, _: int)
|
||||
{
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
#[allow(non_snake_case)]
|
||||
#[no_mangle]
|
||||
pub extern "C" fn glDiscardFramebufferEXT(_: int, _: int, _: *const ())
|
||||
{
|
||||
unimplemented!()
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue