Add Window::on_present_notify to ack about drawing

That's a way to communicate to winit that you'll present to the window.
While it's a no-op for now, it'll be used to throttle drawing.
This commit is contained in:
Kirill Chibisov 2023-06-22 08:08:53 +04:00
parent 189a0080a6
commit 38f28d5836
12 changed files with 71 additions and 6 deletions

View file

@ -813,6 +813,8 @@ impl Window {
self.redraw_requester.request_redraw()
}
pub fn pre_present_notify(&self) {}
pub fn inner_position(&self) -> Result<PhysicalPosition<i32>, error::NotSupportedError> {
Err(error::NotSupportedError::new())
}

View file

@ -74,6 +74,8 @@ impl Inner {
}
}
pub fn pre_present_notify(&self) {}
pub fn inner_position(&self) -> Result<PhysicalPosition<i32>, NotSupportedError> {
unsafe {
let safe_area = self.safe_area_screen_space();

View file

@ -555,12 +555,7 @@ impl Window {
}
}
pub fn request_user_attention(&self, request_type: Option<UserAttentionType>) {
match self {
#[cfg(x11_platform)]
Window::X(ref w) => w.request_user_attention(request_type),
#[cfg(wayland_platform)]
Window::Wayland(ref w) => w.request_user_attention(request_type),
}
x11_or_wayland!(match self; Window(w) => w.request_user_attention(request_type))
}
#[inline]
@ -568,6 +563,11 @@ impl Window {
x11_or_wayland!(match self; Window(w) => w.request_redraw())
}
#[inline]
pub fn pre_present_notify(&self) {
x11_or_wayland!(match self; Window(w) => w.pre_present_notify())
}
#[inline]
pub fn current_monitor(&self) -> Option<MonitorHandle> {
match self {

View file

@ -293,6 +293,11 @@ impl Window {
self.event_loop_awakener.ping();
}
#[inline]
pub fn pre_present_notify(&self) {
// TODO
}
#[inline]
pub fn outer_size(&self) -> PhysicalSize<u32> {
let window_state = self.window_state.lock().unwrap();

View file

@ -1731,6 +1731,11 @@ impl UnownedWindow {
.unwrap();
}
#[inline]
pub fn pre_present_notify(&self) {
// TODO timer
}
#[inline]
pub fn raw_window_handle(&self) -> RawWindowHandle {
let mut window_handle = XlibWindowHandle::empty();

View file

@ -569,6 +569,9 @@ impl WinitWindow {
AppState::queue_redraw(RootWindowId(self.id()));
}
#[inline]
pub fn pre_present_notify(&self) {}
pub fn outer_position(&self) -> Result<PhysicalPosition<i32>, NotSupportedError> {
let frame_rect = self.frame();
let position = LogicalPosition::new(

View file

@ -166,6 +166,9 @@ impl Window {
}
}
#[inline]
pub fn pre_present_notify(&self) {}
#[inline]
pub fn reset_dead_keys(&self) {
// TODO?

View file

@ -114,6 +114,8 @@ impl Window {
.dispatch(|inner| (inner.register_redraw_request)());
}
pub fn pre_present_notify(&self) {}
pub fn outer_position(&self) -> Result<PhysicalPosition<i32>, NotSupportedError> {
self.inner.queue(|inner| {
Ok(inner

View file

@ -142,6 +142,9 @@ impl Window {
}
}
#[inline]
pub fn pre_present_notify(&self) {}
#[inline]
pub fn outer_position(&self) -> Result<PhysicalPosition<i32>, NotSupportedError> {
util::WindowArea::Outer.get_rect(self.hwnd())