From a18609ae0da3d0d3353a6492bf16a2af3b8dff83 Mon Sep 17 00:00:00 2001 From: Gary Qian Date: Fri, 10 May 2019 09:58:53 -0700 Subject: [PATCH] Prevent redundant layouts when floor(width) is the same (flutter/engine#8867) --- engine/src/flutter/third_party/txt/src/txt/paragraph.cc | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/engine/src/flutter/third_party/txt/src/txt/paragraph.cc b/engine/src/flutter/third_party/txt/src/txt/paragraph.cc index 23981c41ef5..296609f29c1 100644 --- a/engine/src/flutter/third_party/txt/src/txt/paragraph.cc +++ b/engine/src/flutter/third_party/txt/src/txt/paragraph.cc @@ -477,13 +477,15 @@ void Paragraph::ComputeStrut(StrutMetrics* strut, SkFont& font) { } void Paragraph::Layout(double width, bool force) { + double rounded_width = floor(width); // Do not allow calling layout multiple times without changing anything. - if (!needs_layout_ && width == width_ && !force) { + if (!needs_layout_ && rounded_width == width_ && !force) { return; } - needs_layout_ = false; - width_ = floor(width); + width_ = rounded_width; + + needs_layout_ = false; if (!ComputeLineBreaks()) return;