-
-
Notifications
You must be signed in to change notification settings - Fork 481
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
Glutin0.23 android #1274
Closed
Closed
Glutin0.23 android #1274
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
[package] | ||
name = "android-examples" | ||
version = "0.1.0" | ||
authors = ["David Craven <david@craven.ch>"] | ||
edition = "2018" | ||
publish = false | ||
build = "../build.rs" | ||
|
||
[dependencies] | ||
glutin = { path = ".." } | ||
|
||
[build-dependencies] | ||
gl_generator = "0.14.0" | ||
|
||
[dev-dependencies] | ||
image = "0.22.4" | ||
ndk-glue = { path = "../../android-ndk-rs/ndk-glue" } | ||
simple_logger = "1.4.0" | ||
takeable-option = "0.5.0" | ||
winit = { path = "../../winit" } | ||
winit_types = { path = "../../winit_types" } | ||
|
||
[[example]] | ||
name = "window" | ||
path = "../examples/window.rs" | ||
crate-type = ["cdylib"] |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,45 +7,70 @@ use winit::event::{Event, WindowEvent}; | |
use winit::event_loop::{ControlFlow, EventLoop}; | ||
use winit::window::WindowBuilder; | ||
|
||
#[cfg(target_os = "android")] | ||
dvc94ch marked this conversation as resolved.
Show resolved
Hide resolved
|
||
ndk_glue::ndk_glue!(main); | ||
|
||
fn main() { | ||
simple_logger::init().unwrap(); | ||
let el = EventLoop::new(); | ||
let wb = WindowBuilder::new().with_title("A fantastic window!"); | ||
|
||
let confs = unsafe { ConfigsFinder::new().find(&*el).unwrap() }; | ||
let conf = &confs[0]; | ||
let conf = confs[0].clone(); | ||
println!("Configeration chosen: {:?}", conf); | ||
|
||
let ctx = unsafe { ContextBuilder::new().build(conf).unwrap() }; | ||
let (win, surf) = unsafe { Surface::new_window(conf, &*el, wb).unwrap() }; | ||
|
||
unsafe { ctx.make_current(&surf).unwrap() } | ||
let gl = support::Gl::load(|s| ctx.get_proc_address(s).unwrap()); | ||
let ctx = unsafe { ContextBuilder::new().build(&conf).unwrap() }; | ||
let win = unsafe { Surface::build_window(&conf, &*el, wb).unwrap() }; | ||
|
||
// On android the surface can only be created after the resume event | ||
// was received. | ||
let mut surf = None; | ||
dvc94ch marked this conversation as resolved.
Show resolved
Hide resolved
|
||
let mut gl = None; | ||
el.run(move |event, _, control_flow| { | ||
println!("{:?}", event); | ||
*control_flow = ControlFlow::Wait; | ||
|
||
match event { | ||
Event::LoopDestroyed => return, | ||
Event::MainEventsCleared => { | ||
win.request_redraw(); | ||
Event::Resumed => { | ||
dvc94ch marked this conversation as resolved.
Show resolved
Hide resolved
|
||
let surface = unsafe { Surface::new_from_existing_window(&conf, &win).unwrap() }; | ||
unsafe { | ||
ctx.make_current(&surface).unwrap(); | ||
} | ||
if gl.is_none() { | ||
gl = Some(support::Gl::load(|s| ctx.get_proc_address(s).unwrap())); | ||
} | ||
surf = Some(surface) | ||
} | ||
Event::Suspended => surf = None, | ||
Event::LoopDestroyed => return, | ||
Event::MainEventsCleared => win.request_redraw(), | ||
Event::RedrawRequested(_) => { | ||
gl.draw_frame([1.0, 0.5, 0.7, 1.0]); | ||
surf.swap_buffers().unwrap(); | ||
if let (Some(gl), Some(surf)) = (&gl, &surf) { | ||
gl.draw_frame([1.0, 0.5, 0.7, 1.0]); | ||
surf.swap_buffers().unwrap(); | ||
} | ||
} | ||
Event::WindowEvent { ref event, .. } => match event { | ||
WindowEvent::Resized(size) => { | ||
Event::WindowEvent { ref event, .. } => { | ||
let size = match event { | ||
WindowEvent::ScaleFactorChanged { | ||
new_inner_size: size, | ||
.. | ||
} => size, | ||
WindowEvent::Resized(size) => size, | ||
WindowEvent::CloseRequested => { | ||
*control_flow = ControlFlow::Exit; | ||
return; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are these returns necessary? |
||
} | ||
_ => return, | ||
}; | ||
if let (Some(gl), Some(surf)) = (&gl, &surf) { | ||
ctx.update_after_resize(); | ||
surf.update_after_resize(*size); | ||
unsafe { | ||
gl.gl.Viewport(0, 0, size.width as _, size.height as _); | ||
} | ||
} | ||
WindowEvent::CloseRequested => *control_flow = ControlFlow::Exit, | ||
_ => (), | ||
}, | ||
} | ||
_ => (), | ||
} | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,43 @@ | ||
#![cfg(any(target_os = "android"))] | ||
use crate::config::Config; | ||
use crate::context::Context; | ||
use crate::surface::{Surface, SurfaceTypeTrait}; | ||
use std::os::raw; | ||
|
||
use crate::platform::ContextTraitExt; | ||
use crate::{Context, ContextCurrentState}; | ||
use crate::{SupportsPBuffersTrait, SupportsSurfacelessTrait, SupportsWindowSurfacesTrait}; | ||
#[derive(Debug, Default, Clone, PartialEq, Eq)] | ||
pub struct ConfigPlatformAttributes; | ||
|
||
pub use glutin_egl_sys::EGLContext; | ||
pub trait ConfigExt { | ||
unsafe fn raw_config(&self) -> *const raw::c_void; | ||
unsafe fn raw_display(&self) -> *mut raw::c_void; | ||
} | ||
|
||
use std::os::raw; | ||
impl ConfigExt for Config { | ||
unsafe fn raw_config(&self) -> *const raw::c_void { | ||
self.config.raw_config() | ||
} | ||
|
||
unsafe fn raw_display(&self) -> *mut raw::c_void { | ||
self.config.raw_display() | ||
} | ||
} | ||
|
||
pub trait SurfaceExt { | ||
unsafe fn raw_surface(&self) -> *const raw::c_void; | ||
} | ||
|
||
impl< | ||
IC: ContextCurrentState, | ||
PBT: SupportsPBuffersTrait, | ||
WST: SupportsWindowSurfacesTrait, | ||
ST: SupportsSurfacelessTrait, | ||
> ContextTraitExt for Context<IC, PBT, WST, ST> | ||
{ | ||
type Handle = EGLContext; | ||
|
||
#[inline] | ||
unsafe fn raw_handle(&self) -> Self::Handle { | ||
self.context.raw_handle() | ||
impl<T: SurfaceTypeTrait> SurfaceExt for Surface<T> { | ||
unsafe fn raw_surface(&self) -> *const raw::c_void { | ||
self.0.raw_surface() | ||
} | ||
} | ||
|
||
pub trait ContextExt { | ||
unsafe fn raw_context(&self) -> *mut raw::c_void; | ||
} | ||
|
||
#[inline] | ||
unsafe fn get_egl_display(&self) -> Option<*const raw::c_void> { | ||
Some(self.context.get_egl_display()) | ||
impl ContextExt for Context { | ||
unsafe fn raw_context(&self) -> *mut raw::c_void { | ||
self.0.raw_context() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NOTE to self