Implement ApplicationHandler::can_create|destroy_surfaces() (#3765)
This commit is contained in:
parent
a0d69c782a
commit
75ce71f05a
21 changed files with 178 additions and 114 deletions
|
|
@ -176,10 +176,10 @@ impl EventLoop {
|
|||
|
||||
match event {
|
||||
MainEvent::InitWindow { .. } => {
|
||||
app.resumed(self.window_target());
|
||||
app.can_create_surfaces(self.window_target());
|
||||
},
|
||||
MainEvent::TerminateWindow { .. } => {
|
||||
app.suspended(self.window_target());
|
||||
app.destroy_surfaces(self.window_target());
|
||||
},
|
||||
MainEvent::WindowResized { .. } => resized = true,
|
||||
MainEvent::RedrawNeeded { .. } => pending_redraw = true,
|
||||
|
|
|
|||
|
|
@ -314,9 +314,9 @@ impl ApplicationDelegate {
|
|||
/// dispatch `NewEvents(Init)` + `Resumed`
|
||||
pub fn dispatch_init_events(&self) {
|
||||
self.with_handler(|app, event_loop| app.new_events(event_loop, StartCause::Init));
|
||||
// NB: For consistency all platforms must emit a 'resumed' event even though macOS
|
||||
// applications don't themselves have a formal suspend/resume lifecycle.
|
||||
self.with_handler(|app, event_loop| app.resumed(event_loop));
|
||||
// NB: For consistency all platforms must call `can_create_surfaces` even though macOS
|
||||
// applications don't themselves have a formal surface destroy/create lifecycle.
|
||||
self.with_handler(|app, event_loop| app.can_create_surfaces(event_loop));
|
||||
}
|
||||
|
||||
// Called by RunLoopObserver after finishing waiting for new events
|
||||
|
|
|
|||
|
|
@ -496,8 +496,12 @@ pub fn did_finish_launching(mtm: MainThreadMarker) {
|
|||
|
||||
let (windows, events) = AppState::get_mut(mtm).did_finish_launching_transition();
|
||||
|
||||
let events = std::iter::once(EventWrapper::StaticEvent(Event::NewEvents(StartCause::Init)))
|
||||
.chain(events);
|
||||
let events = [
|
||||
EventWrapper::StaticEvent(Event::NewEvents(StartCause::Init)),
|
||||
EventWrapper::StaticEvent(Event::CreateSurfaces),
|
||||
]
|
||||
.into_iter()
|
||||
.chain(events);
|
||||
handle_nonuser_events(mtm, events);
|
||||
|
||||
// the above window dance hack, could possibly trigger new windows to be created.
|
||||
|
|
|
|||
|
|
@ -130,6 +130,7 @@ fn map_user_event<A: ApplicationHandler>(
|
|||
},
|
||||
Event::Suspended => app.suspended(window_target),
|
||||
Event::Resumed => app.resumed(window_target),
|
||||
Event::CreateSurfaces => app.can_create_surfaces(window_target),
|
||||
Event::AboutToWait => app.about_to_wait(window_target),
|
||||
Event::LoopExiting => app.exiting(window_target),
|
||||
Event::MemoryWarning => app.memory_warning(window_target),
|
||||
|
|
|
|||
|
|
@ -301,10 +301,10 @@ impl EventLoop {
|
|||
|
||||
app.new_events(&self.window_target, cause);
|
||||
|
||||
// NB: For consistency all platforms must emit a 'resumed' event even though Wayland
|
||||
// applications don't themselves have a formal suspend/resume lifecycle.
|
||||
// NB: For consistency all platforms must call `can_create_surfaces` even though Wayland
|
||||
// applications don't themselves have a formal surface destroy/create lifecycle.
|
||||
if cause == StartCause::Init {
|
||||
app.resumed(&self.window_target);
|
||||
app.can_create_surfaces(&self.window_target);
|
||||
}
|
||||
|
||||
// Indicate user wake up.
|
||||
|
|
|
|||
|
|
@ -505,10 +505,10 @@ impl EventLoop {
|
|||
fn single_iteration<A: ApplicationHandler>(&mut self, app: &mut A, cause: StartCause) {
|
||||
app.new_events(&self.event_processor.target, cause);
|
||||
|
||||
// NB: For consistency all platforms must emit a 'resumed' event even though X11
|
||||
// applications don't themselves have a formal suspend/resume lifecycle.
|
||||
// NB: For consistency all platforms must call `can_create_surfaces` even though X11
|
||||
// applications don't themselves have a formal surface destroy/create lifecycle.
|
||||
if cause == StartCause::Init {
|
||||
app.resumed(&self.event_processor.target)
|
||||
app.can_create_surfaces(&self.event_processor.target)
|
||||
}
|
||||
|
||||
// Process all pending events
|
||||
|
|
|
|||
|
|
@ -507,7 +507,7 @@ impl EventLoop {
|
|||
app.new_events(&self.window_target, start_cause);
|
||||
|
||||
if start_cause == StartCause::Init {
|
||||
app.resumed(&self.window_target);
|
||||
app.can_create_surfaces(&self.window_target);
|
||||
}
|
||||
|
||||
// Handle window creates.
|
||||
|
|
|
|||
|
|
@ -87,6 +87,7 @@ fn handle_event<A: ApplicationHandler>(app: &mut A, target: &RootActiveEventLoop
|
|||
Event::UserWakeUp => app.proxy_wake_up(target),
|
||||
Event::Suspended => app.suspended(target),
|
||||
Event::Resumed => app.resumed(target),
|
||||
Event::CreateSurfaces => app.can_create_surfaces(target),
|
||||
Event::AboutToWait => app.about_to_wait(target),
|
||||
Event::LoopExiting => app.exiting(target),
|
||||
Event::MemoryWarning => app.memory_warning(target),
|
||||
|
|
|
|||
|
|
@ -441,9 +441,11 @@ impl Shared {
|
|||
}
|
||||
|
||||
pub fn init(&self) {
|
||||
// NB: For consistency all platforms must emit a 'resumed' event even though web
|
||||
// applications don't themselves have a formal suspend/resume lifecycle.
|
||||
self.run_until_cleared([Event::NewEvents(StartCause::Init), Event::Resumed].into_iter());
|
||||
// NB: For consistency all platforms must call `can_create_surfaces` even though web
|
||||
// applications don't themselves have a formal surface destroy/create lifecycle.
|
||||
self.run_until_cleared(
|
||||
[Event::NewEvents(StartCause::Init), Event::CreateSurfaces].into_iter(),
|
||||
);
|
||||
}
|
||||
|
||||
// Run the polling logic for the Poll ControlFlow, which involves clearing the queue
|
||||
|
|
|
|||
|
|
@ -216,6 +216,7 @@ impl EventLoop {
|
|||
Event::UserWakeUp => app.proxy_wake_up(event_loop_windows_ref),
|
||||
Event::Suspended => app.suspended(event_loop_windows_ref),
|
||||
Event::Resumed => app.resumed(event_loop_windows_ref),
|
||||
Event::CreateSurfaces => app.can_create_surfaces(event_loop_windows_ref),
|
||||
Event::AboutToWait => app.about_to_wait(event_loop_windows_ref),
|
||||
Event::LoopExiting => app.exiting(event_loop_windows_ref),
|
||||
Event::MemoryWarning => app.memory_warning(event_loop_windows_ref),
|
||||
|
|
@ -281,6 +282,7 @@ impl EventLoop {
|
|||
Event::UserWakeUp => app.proxy_wake_up(event_loop_windows_ref),
|
||||
Event::Suspended => app.suspended(event_loop_windows_ref),
|
||||
Event::Resumed => app.resumed(event_loop_windows_ref),
|
||||
Event::CreateSurfaces => app.can_create_surfaces(event_loop_windows_ref),
|
||||
Event::AboutToWait => app.about_to_wait(event_loop_windows_ref),
|
||||
Event::LoopExiting => app.exiting(event_loop_windows_ref),
|
||||
Event::MemoryWarning => app.memory_warning(event_loop_windows_ref),
|
||||
|
|
|
|||
|
|
@ -345,10 +345,10 @@ impl EventLoopRunner {
|
|||
},
|
||||
};
|
||||
self.call_event_handler(Event::NewEvents(start_cause));
|
||||
// NB: For consistency all platforms must emit a 'resumed' event even though Windows
|
||||
// applications don't themselves have a formal suspend/resume lifecycle.
|
||||
// NB: For consistency all platforms must call `can_create_surfaces` even though Windows
|
||||
// applications don't themselves have a formal surface destroy/create lifecycle.
|
||||
if init {
|
||||
self.call_event_handler(Event::Resumed);
|
||||
self.call_event_handler(Event::CreateSurfaces);
|
||||
}
|
||||
self.dispatch_buffered_events();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue