mirror of
https://github.com/italicsjenga/winit-sonoma-fix.git
synced 2024-12-25 06:41:31 +11:00
Merge pull request #8 from tomaka/android-cleanup
Remove OpenGL from Android code
This commit is contained in:
commit
d4d4a6ffba
|
@ -5,6 +5,7 @@ extern crate android_glue;
|
|||
use libc;
|
||||
use std::ffi::{CString};
|
||||
use std::sync::mpsc::{Receiver, channel};
|
||||
use std::os::raw::c_void;
|
||||
use {CreationError, Event, MouseCursor};
|
||||
use CreationError::OsError;
|
||||
use events::ElementState::{Pressed, Released};
|
||||
|
@ -12,22 +13,12 @@ use events::{Touch, TouchPhase};
|
|||
|
||||
use std::collections::VecDeque;
|
||||
|
||||
use Api;
|
||||
use ContextError;
|
||||
use CursorState;
|
||||
use GlAttributes;
|
||||
use GlContext;
|
||||
use GlRequest;
|
||||
use PixelFormat;
|
||||
use PixelFormatRequirements;
|
||||
use WindowAttributes;
|
||||
use native_monitor::NativeMonitorId;
|
||||
|
||||
use api::egl;
|
||||
use api::egl::Context as EglContext;
|
||||
|
||||
pub struct Window {
|
||||
context: EglContext,
|
||||
native_window: *const c_void,
|
||||
event_rx: Receiver<android_glue::Event>,
|
||||
}
|
||||
|
||||
|
@ -120,8 +111,7 @@ impl<'a> Iterator for WaitEventsIterator<'a> {
|
|||
}
|
||||
|
||||
impl Window {
|
||||
pub fn new(win_attribs: &WindowAttributes, pf_reqs: &PixelFormatRequirements,
|
||||
opengl: &GlAttributes<&Window>, _: &PlatformSpecificWindowBuilderAttributes)
|
||||
pub fn new(win_attribs: &WindowAttributes, _: &PlatformSpecificWindowBuilderAttributes)
|
||||
-> Result<Window, CreationError>
|
||||
{
|
||||
use std::{mem, ptr};
|
||||
|
@ -130,27 +120,26 @@ impl Window {
|
|||
assert!(win_attribs.min_dimensions.is_none());
|
||||
assert!(win_attribs.max_dimensions.is_none());
|
||||
|
||||
let opengl = opengl.clone().map_sharing(|w| &w.context);
|
||||
|
||||
let native_window = unsafe { android_glue::get_native_window() };
|
||||
if native_window.is_null() {
|
||||
return Err(OsError(format!("Android's native window is null")));
|
||||
}
|
||||
|
||||
let context = try!(EglContext::new(egl::ffi::egl::Egl, pf_reqs, &opengl,
|
||||
egl::NativeDisplay::Android)
|
||||
.and_then(|p| p.finish(native_window as *const _)));
|
||||
|
||||
let (tx, rx) = channel();
|
||||
android_glue::add_sender(tx);
|
||||
android_glue::set_multitouch(win_attribs.multitouch);
|
||||
|
||||
Ok(Window {
|
||||
context: context,
|
||||
native_window: native_window,
|
||||
event_rx: rx,
|
||||
})
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn get_native_window(&self) -> *const c_void {
|
||||
self.native_window
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn is_closed(&self) -> bool {
|
||||
false
|
||||
|
@ -185,8 +174,8 @@ impl Window {
|
|||
None
|
||||
} else {
|
||||
Some((
|
||||
unsafe { ffi::ANativeWindow_getWidth(native_window) } as u32,
|
||||
unsafe { ffi::ANativeWindow_getHeight(native_window) } as u32
|
||||
unsafe { ffi::ANativeWindow_getWidth(native_window as *const _) } as u32,
|
||||
unsafe { ffi::ANativeWindow_getHeight(native_window as *const _) } as u32
|
||||
))
|
||||
}
|
||||
}
|
||||
|
@ -229,11 +218,6 @@ impl Window {
|
|||
unimplemented!()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn get_pixel_format(&self) -> PixelFormat {
|
||||
unimplemented!();
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn set_window_resize_callback(&mut self, _: Option<fn(u32, u32)>) {
|
||||
}
|
||||
|
@ -261,38 +245,6 @@ impl Window {
|
|||
unsafe impl Send for Window {}
|
||||
unsafe impl Sync for Window {}
|
||||
|
||||
impl GlContext for Window {
|
||||
#[inline]
|
||||
unsafe fn make_current(&self) -> Result<(), ContextError> {
|
||||
self.context.make_current()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn is_current(&self) -> bool {
|
||||
self.context.is_current()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn get_proc_address(&self, addr: &str) -> *const () {
|
||||
self.context.get_proc_address(addr)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn swap_buffers(&self) -> Result<(), ContextError> {
|
||||
self.context.swap_buffers()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn get_api(&self) -> Api {
|
||||
self.context.get_api()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn get_pixel_format(&self) -> PixelFormat {
|
||||
self.context.get_pixel_format()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct WindowProxy;
|
||||
|
||||
|
@ -302,55 +254,3 @@ impl WindowProxy {
|
|||
unimplemented!()
|
||||
}
|
||||
}
|
||||
|
||||
pub struct HeadlessContext(EglContext);
|
||||
|
||||
impl HeadlessContext {
|
||||
/// See the docs in the crate root file.
|
||||
pub fn new(dimensions: (u32, u32), pf_reqs: &PixelFormatRequirements,
|
||||
opengl: &GlAttributes<&HeadlessContext>,
|
||||
_: &PlatformSpecificHeadlessBuilderAttributes)
|
||||
-> Result<HeadlessContext, CreationError>
|
||||
{
|
||||
let opengl = opengl.clone().map_sharing(|c| &c.0);
|
||||
let context = try!(EglContext::new(egl::ffi::egl::Egl, pf_reqs, &opengl,
|
||||
egl::NativeDisplay::Android));
|
||||
let context = try!(context.finish_pbuffer(dimensions)); // TODO:
|
||||
Ok(HeadlessContext(context))
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl Send for HeadlessContext {}
|
||||
unsafe impl Sync for HeadlessContext {}
|
||||
|
||||
impl GlContext for HeadlessContext {
|
||||
#[inline]
|
||||
unsafe fn make_current(&self) -> Result<(), ContextError> {
|
||||
self.0.make_current()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn is_current(&self) -> bool {
|
||||
self.0.is_current()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn get_proc_address(&self, addr: &str) -> *const () {
|
||||
self.0.get_proc_address(addr)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn swap_buffers(&self) -> Result<(), ContextError> {
|
||||
self.0.swap_buffers()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn get_api(&self) -> Api {
|
||||
self.0.get_api()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn get_pixel_format(&self) -> PixelFormat {
|
||||
self.0.get_pixel_format()
|
||||
}
|
||||
}
|
||||
|
|
25
src/os/android.rs
Normal file
25
src/os/android.rs
Normal file
|
@ -0,0 +1,25 @@
|
|||
#![cfg(any(target_os = "android"))]
|
||||
|
||||
use std::os::raw::c_void;
|
||||
use Window;
|
||||
use WindowBuilder;
|
||||
|
||||
/// Additional methods on `Window` that are specific to Android.
|
||||
pub trait WindowExt {
|
||||
fn get_native_window(&self) -> *const c_void;
|
||||
}
|
||||
|
||||
impl WindowExt for Window {
|
||||
#[inline]
|
||||
fn get_native_window(&self) -> *const c_void {
|
||||
self.window.get_native_window()
|
||||
}
|
||||
}
|
||||
|
||||
/// Additional methods on `WindowBuilder` that are specific to Android.
|
||||
pub trait WindowBuilderExt {
|
||||
|
||||
}
|
||||
|
||||
impl WindowBuilderExt for WindowBuilder {
|
||||
}
|
|
@ -2,10 +2,12 @@
|
|||
//!
|
||||
//! Contains the follow modules:
|
||||
//!
|
||||
//! - `android`
|
||||
//! - `macos`
|
||||
//! - `unix`
|
||||
//! - `windows`
|
||||
//!
|
||||
pub mod android;
|
||||
pub mod macos;
|
||||
pub mod unix;
|
||||
pub mod windows;
|
||||
|
|
Loading…
Reference in a new issue