linux: work around the mutex locks for request_frame and resize
This commit is contained in:
parent
74fde5967b
commit
503ac7a251
4 changed files with 40 additions and 25 deletions
|
@ -33,7 +33,16 @@ impl BladeRenderer {
|
||||||
self.gpu.destroy_command_encoder(&mut self.command_encoder);
|
self.gpu.destroy_command_encoder(&mut self.command_encoder);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn wait_for_gpu(&mut self) {
|
||||||
|
if let Some(last_sp) = self.last_sync_point.take() {
|
||||||
|
if !self.gpu.wait_for(&last_sp, MAX_FRAME_TIME_MS) {
|
||||||
|
panic!("GPU hung");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn resize(&mut self, size: blade::Extent) {
|
pub fn resize(&mut self, size: blade::Extent) {
|
||||||
|
self.wait_for_gpu();
|
||||||
self.gpu.resize(blade::SurfaceConfig {
|
self.gpu.resize(blade::SurfaceConfig {
|
||||||
size,
|
size,
|
||||||
usage: blade::TextureUsage::TARGET,
|
usage: blade::TextureUsage::TARGET,
|
||||||
|
@ -44,15 +53,12 @@ impl BladeRenderer {
|
||||||
pub fn draw(&mut self, scene: &Scene) {
|
pub fn draw(&mut self, scene: &Scene) {
|
||||||
let frame = self.gpu.acquire_frame();
|
let frame = self.gpu.acquire_frame();
|
||||||
self.command_encoder.start();
|
self.command_encoder.start();
|
||||||
|
self.command_encoder.init_texture(frame.texture());
|
||||||
|
|
||||||
self.command_encoder.present(frame);
|
self.command_encoder.present(frame);
|
||||||
|
|
||||||
let sync_point = self.gpu.submit(&mut self.command_encoder);
|
let sync_point = self.gpu.submit(&mut self.command_encoder);
|
||||||
if let Some(ref last_sp) = self.last_sync_point {
|
self.wait_for_gpu();
|
||||||
if !self.gpu.wait_for(last_sp, MAX_FRAME_TIME_MS) {
|
|
||||||
panic!("GPU hung");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
self.last_sync_point = Some(sync_point);
|
self.last_sync_point = Some(sync_point);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -114,16 +114,14 @@ impl Platform for LinuxPlatform {
|
||||||
}
|
}
|
||||||
xcb::Event::X(x::Event::ResizeRequest(ev)) => {
|
xcb::Event::X(x::Event::ResizeRequest(ev)) => {
|
||||||
let this = self.0.lock();
|
let this = self.0.lock();
|
||||||
let mut window = this.windows[&ev.window()].lock();
|
LinuxWindowState::resize(&this.windows[&ev.window()], ev.width(), ev.height());
|
||||||
window.resize(ev.width(), ev.height());
|
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(x_window) = repaint_x_window {
|
if let Some(x_window) = repaint_x_window {
|
||||||
let this = self.0.lock();
|
let this = self.0.lock();
|
||||||
let mut window = this.windows[&x_window].lock();
|
LinuxWindowState::request_frame(&this.windows[&x_window]);
|
||||||
window.request_frame();
|
|
||||||
this.xcb_connection.flush();
|
this.xcb_connection.flush();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,7 +64,7 @@ impl PlatformTextSystem for LinuxTextSystem {
|
||||||
Vec::new()
|
Vec::new()
|
||||||
}
|
}
|
||||||
fn font_id(&self, descriptor: &Font) -> Result<FontId> {
|
fn font_id(&self, descriptor: &Font) -> Result<FontId> {
|
||||||
unimplemented!()
|
Ok(FontId(0)) //TODO
|
||||||
}
|
}
|
||||||
fn font_metrics(&self, font_id: FontId) -> FontMetrics {
|
fn font_metrics(&self, font_id: FontId) -> FontMetrics {
|
||||||
unimplemented!()
|
unimplemented!()
|
||||||
|
@ -89,7 +89,7 @@ impl PlatformTextSystem for LinuxTextSystem {
|
||||||
unimplemented!()
|
unimplemented!()
|
||||||
}
|
}
|
||||||
fn layout_line(&self, text: &str, font_size: Pixels, runs: &[FontRun]) -> LineLayout {
|
fn layout_line(&self, text: &str, font_size: Pixels, runs: &[FontRun]) -> LineLayout {
|
||||||
unimplemented!()
|
LineLayout::default() //TODO
|
||||||
}
|
}
|
||||||
fn wrap_line(
|
fn wrap_line(
|
||||||
&self,
|
&self,
|
||||||
|
|
|
@ -166,30 +166,41 @@ impl LinuxWindowState {
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn resize(&mut self, width: u16, height: u16) {
|
pub fn destroy(&mut self) {
|
||||||
self.content_size = Size {
|
self.sprite_atlas.destroy();
|
||||||
|
self.renderer.destroy();
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn resize(self_ptr: &LinuxWindowStatePtr, width: u16, height: u16) {
|
||||||
|
let content_size = Size {
|
||||||
width: Pixels(width as f32),
|
width: Pixels(width as f32),
|
||||||
height: Pixels(height as f32),
|
height: Pixels(height as f32),
|
||||||
};
|
};
|
||||||
self.renderer.resize(blade::Extent {
|
|
||||||
|
let mut fun = match self_ptr.lock().callbacks.resize.take() {
|
||||||
|
Some(fun) => fun,
|
||||||
|
None => return,
|
||||||
|
};
|
||||||
|
fun(content_size, 1.0);
|
||||||
|
|
||||||
|
let mut this = self_ptr.lock();
|
||||||
|
this.callbacks.resize = Some(fun);
|
||||||
|
this.content_size = content_size;
|
||||||
|
this.renderer.resize(blade::Extent {
|
||||||
width: width as u32,
|
width: width as u32,
|
||||||
height: height as u32,
|
height: height as u32,
|
||||||
depth: 1,
|
depth: 1,
|
||||||
});
|
});
|
||||||
if let Some(ref mut fun) = self.callbacks.resize {
|
|
||||||
fun(self.content_size, 1.0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn request_frame(&mut self) {
|
pub fn request_frame(self_ptr: &LinuxWindowStatePtr) {
|
||||||
if let Some(ref mut fun) = self.callbacks.request_frame {
|
let mut fun = match self_ptr.lock().callbacks.request_frame.take() {
|
||||||
fun();
|
Some(fun) => fun,
|
||||||
}
|
None => return,
|
||||||
}
|
};
|
||||||
|
fun();
|
||||||
|
|
||||||
pub fn destroy(&mut self) {
|
self_ptr.lock().callbacks.request_frame = Some(fun);
|
||||||
self.sprite_atlas.destroy();
|
|
||||||
self.renderer.destroy();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue