Просмотр исходного кода

wallet: instantly show the window as priority

rsx 2 лет назад
Родитель
Сommit
633aeb447a
2 измененных файлов с 21 добавлено и 6 удалено
  1. 18 3
      bin/darkwallet/src/gfx.rs
  2. 3 3
      bin/darkwallet/src/main.rs

+ 18 - 3
bin/darkwallet/src/gfx.rs

@@ -163,6 +163,8 @@ struct Stage {
 
     method_recvr: mpsc::Receiver<(GraphicsMethodEvent, SceneNodeId, Vec<u8>, MethodResponseFn)>,
     method_sender: mpsc::SyncSender<(GraphicsMethodEvent, SceneNodeId, Vec<u8>, MethodResponseFn)>,
+
+    last_draw_time: Option<Instant>,
 }
 
 impl Stage {
@@ -266,8 +268,10 @@ impl Stage {
             font,
             method_recvr,
             method_sender,
+            last_draw_time: None
         };
         stage.setup_scene_graph_window();
+        debug!("Finished loading GUI");
         stage
     }
 
@@ -871,8 +875,17 @@ fn get_text_props(render_text: &SceneNode) -> Result<(String, f32, [f32; 4])> {
 
 impl EventHandler for Stage {
     fn update(&mut self) {
-        // Only block for 20 ms, process as much as we can during that time
-        let deadline = Instant::now() + Duration::from_millis(400);
+        if self.last_draw_time.is_none() {
+            return
+        }
+        // Only allow 20 ms, process as much as we can during that time
+        let elapsed_since_draw = self.last_draw_time.unwrap().elapsed();
+        if elapsed_since_draw > Duration::from_millis(20) {
+            return
+        }
+        let allowed_time = Duration::from_millis(20) - elapsed_since_draw;
+        let deadline = Instant::now() + allowed_time;
+
         loop {
             let Ok((event, node_id, arg_data, response_fn)) =
                 self.method_recvr.recv_deadline(deadline)
@@ -892,6 +905,8 @@ impl EventHandler for Stage {
 
     // Only do drawing here. Apps might not call this when minimized.
     fn draw(&mut self) {
+        self.last_draw_time = Some(Instant::now());
+
         let clear = PassAction::clear_color(0., 0., 0., 1.);
         self.ctx.begin_default_pass(clear);
         self.ctx.end_render_pass();
@@ -1276,7 +1291,7 @@ impl EventHandler for Stage {
     }
 }
 
-pub fn init_gui(scene_graph: SceneGraphPtr) {
+pub fn run_gui(scene_graph: SceneGraphPtr) {
     #[cfg(target_os = "android")]
     {
         android_logger::init_once(

+ 3 - 3
bin/darkwallet/src/main.rs

@@ -10,7 +10,7 @@ mod error;
 mod expr;
 
 mod gfx;
-use gfx::init_gui;
+use gfx::run_gui;
 
 mod net;
 use net::ZeroMQAdapter;
@@ -37,8 +37,8 @@ fn init_zmq(scene_graph: SceneGraphPtr) {
 
 fn main() {
     let scene_graph = Arc::new(Mutex::new(SceneGraph::new()));
-    init_zmq(scene_graph.clone());
-    init_gui(scene_graph);
+    //init_zmq(scene_graph.clone());
+    run_gui(scene_graph);
 }
 
 /*