浏览代码

optimize _paintCell

xuty 4 年之前
父节点
当前提交
25fecd5137
共有 1 个文件被更改,包括 10 次插入3 次删除
  1. 10 3
      lib/frontend/terminal_view.dart

+ 10 - 3
lib/frontend/terminal_view.dart

@@ -427,6 +427,13 @@ class TerminalPainter extends CustomPainter {
       return;
     }
 
+    final cellHash = hashValues(cell.codePoint, attr);
+    var tp = textLayoutCache.getLayoutFromCache(cellHash);
+    if (tp != null) {
+      tp.paint(canvas, Offset(offsetX, offsetY));
+      return;
+    }
+
     final cellColor = attr.inverse
         ? attr.bgColor ?? terminal.theme.background
         : attr.fgColor ?? terminal.theme.foreground;
@@ -454,7 +461,8 @@ class TerminalPainter extends CustomPainter {
             decoration:
                 attr.underline ? TextDecoration.underline : TextDecoration.none,
             fontFamily: 'monospace',
-            fontFamilyFallback: view.style.fontFamily);
+            fontFamilyFallback: view.style.fontFamily,
+          );
 
     final span = TextSpan(
       text: String.fromCharCode(cell.codePoint!),
@@ -463,8 +471,7 @@ class TerminalPainter extends CustomPainter {
     );
 
     // final tp = textLayoutCache.getOrPerformLayout(span);
-    final tp = textLayoutCacheV2.getOrPerformLayout(
-        span, hashValues(cell.codePoint, attr));
+    tp = textLayoutCache.performAndCacheLayout(span, cellHash);
 
     tp.paint(canvas, Offset(offsetX, offsetY));
   }