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

wallet: chatview only send draw calls for visible meshes

darkfi 1 год назад
Родитель
Сommit
eac775accf
2 измененных файлов с 21 добавлено и 15 удалено
  1. 8 8
      bin/darkwallet/src/ui/chatview/mod.rs
  2. 13 7
      bin/darkwallet/src/ui/chatview/page.rs

+ 8 - 8
bin/darkwallet/src/ui/chatview/mod.rs

@@ -577,8 +577,11 @@ impl ChatView {
         let iter = match msgbuf.oldest_timestamp() {
             Some(oldest_timest) => {
                 // iterate from there
-                let key = oldest_timest.to_be_bytes();
-                debug!(target: "ui::chatview", "preloading from {key:?}");
+                debug!(target: "ui::chatview", "preloading from {oldest_timest}");
+                let timest = (oldest_timest - 1).to_be_bytes();
+                let mut key = [0u8; 8 + 32];
+                key[..8].clone_from_slice(&timest);
+
                 let iter = self.tree.range(..key).rev();
                 iter
             }
@@ -706,9 +709,8 @@ impl ChatView {
         let mut total_height = msgbuf.calc_total_height(line_height, baseline);
         // Load pages until we run out or we have enough
         while total_height < nonneg_scroll + rect_h {
-            debug!(target: "ui::chatview", "set_adjusted_scroll() loading more pages");
-
             let n_loaded_pages = self.preload_msgs(msgbuf).await;
+            debug!(target: "ui::chatview", "set_adjusted_scroll() loaded until {:?}", msgbuf.oldest_timestamp());
 
             // We need this value after so first update it
             total_height = msgbuf.calc_total_height(line_height, baseline);
@@ -773,13 +775,13 @@ impl ChatView {
             .await;
 
         let mut current_height = 0.;
-        for (i, (height, mesh)) in enumerate(meshes) {
+        for (i, (y_pos, mesh)) in enumerate(meshes) {
             // Apply scroll and scissor
             // We use the scissor for scrolling
             // Because we use the scissor, our actual rect is now rect instead of parent_rect
             let off_x = 0.;
             // This calc decides whether scroll is in terms of pages or pixels
-            let off_y = (scroll + start_pos - current_height) / rect.h;
+            let off_y = (scroll + start_pos - y_pos) / rect.h;
             let scale_x = 1. / rect.w;
             let scale_y = 1. / rect.h;
             let model = glam::Mat4::from_translation(glam::Vec3::new(off_x, off_y, 0.)) *
@@ -789,8 +791,6 @@ impl ChatView {
 
             instrs.push(DrawInstruction::Draw(mesh));
             //debug!(target: "ui::chatview", "mesh-{i}: {height} {current_height}");
-
-            current_height += height;
         }
 
         let freed = std::mem::take(&mut msgbuf.freed);

+ 13 - 7
bin/darkwallet/src/ui/chatview/page.rs

@@ -587,11 +587,19 @@ impl MessageBuffer {
         let mut meshes = vec![];
 
         let descent = line_height - baseline;
-        let mut current_height = descent;
+        let mut current_pos = descent;
         for msg in &mut self.msgs {
-            if current_height > scroll + rect.h {
+            let mesh_height = msg.height(line_height);
+            let msg_bottom = current_pos;
+            let msg_top = current_pos + mesh_height;
+
+            if msg_bottom > scroll + rect.h {
                 break
             }
+            if msg_top < scroll {
+                current_pos += mesh_height;
+                continue
+            }
 
             let mesh = msg
                 .gen_mesh(
@@ -606,13 +614,11 @@ impl MessageBuffer {
                 )
                 .await;
 
-            let mesh_height = msg.height(line_height);
-
-            meshes.push((mesh_height, mesh));
-
-            current_height += mesh_height;
+            meshes.push((current_pos, mesh));
+            current_pos += mesh_height;
         }
 
+        //debug!("gen_meshes() returning {} meshes", meshes.len());
         meshes
     }