From 40252675372df45241a0d80c03939631afec269b Mon Sep 17 00:00:00 2001 From: Gary Qian Date: Wed, 19 Jul 2017 17:25:11 -0700 Subject: [PATCH] Use SkCanvasAutoRestore. Change-Id: I35a7c65303e17132af86f552a657d226d9576850 --- .../src/flutter/benchmarks/paragraph_benchmarks.cc | 14 +++++++++----- engine/src/flutter/src/paragraph.cc | 3 +-- engine/src/flutter/src/paragraph.h | 2 ++ 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/engine/src/flutter/benchmarks/paragraph_benchmarks.cc b/engine/src/flutter/benchmarks/paragraph_benchmarks.cc index e92715ff1a..ca547764b7 100644 --- a/engine/src/flutter/benchmarks/paragraph_benchmarks.cc +++ b/engine/src/flutter/benchmarks/paragraph_benchmarks.cc @@ -141,7 +141,7 @@ static void BM_ParagraphJustifyLayout(benchmark::State& state) { BENCHMARK(BM_ParagraphJustifyLayout); static void BM_ParagraphManyStylesLayout(benchmark::State& state) { - const char* text = "A short sentence. "; + const char* text = "-"; auto icu_text = icu::UnicodeString::fromUTF8(text); std::u16string u16_text(icu_text.getBuffer(), icu_text.getBuffer() + icu_text.length()); @@ -189,7 +189,7 @@ static void BM_ParagraphTextBigO(benchmark::State& state) { BENCHMARK(BM_ParagraphTextBigO) ->RangeMultiplier(10) ->Range(1 << 6, 1 << 14) - ->Complexity(benchmark::oN); + ->Complexity(benchmark::oNSquared); static void BM_ParagraphStylesBigO(benchmark::State& state) { const char* text = "A short sentence. "; @@ -217,7 +217,7 @@ static void BM_ParagraphStylesBigO(benchmark::State& state) { BENCHMARK(BM_ParagraphStylesBigO) ->RangeMultiplier(20) ->Range(1 << 4, 1 << 12) - ->Complexity(benchmark::oN); + ->Complexity(benchmark::oNSquared); // ----------------------------------------------------------------------------- // @@ -228,7 +228,7 @@ BENCHMARK(BM_ParagraphStylesBigO) static void BM_ParagraphMinikinDoLayout(benchmark::State& state) { std::vector text; - for (uint16_t i = 0; i < 100; ++i) { + for (uint16_t i = 0; i < state.range(0); ++i) { text.push_back(i); } minikin::FontStyle font; @@ -250,8 +250,12 @@ static void BM_ParagraphMinikinDoLayout(benchmark::State& state) { layout.doLayout(text.data(), 0, 50, text.size(), 0, font, paint, collection); } + state.SetComplexityN(state.range(0)); } -BENCHMARK(BM_ParagraphMinikinDoLayout); +BENCHMARK(BM_ParagraphMinikinDoLayout) + ->RangeMultiplier(10) + ->Range(1 << 7, 1 << 14) + ->Complexity(benchmark::oN); static void BM_ParagraphSkTextBlobAlloc(benchmark::State& state) { SkPaint paint; diff --git a/engine/src/flutter/src/paragraph.cc b/engine/src/flutter/src/paragraph.cc index 1ca9d12be9..d7cd417c5f 100644 --- a/engine/src/flutter/src/paragraph.cc +++ b/engine/src/flutter/src/paragraph.cc @@ -292,7 +292,6 @@ void Paragraph::Layout(double width, bool force) { letter_spacing_offset -= run.style.letter_spacing; size_t layout_start = run.start; - // Layout until the end of the run or too many lines. while (layout_start < run.end && lines_ < paragraph_style_.max_lines) { const size_t next_break = (break_index > breaks_count - 1) @@ -605,6 +604,7 @@ void Paragraph::SetFontCollection(FontCollection* font_collection) { // The x,y coordinates will be the very top left corner of the rendered // paragraph. void Paragraph::Paint(SkCanvas* canvas, double x, double y) { + SkAutoCanvasRestore canvas_restore(canvas, true); canvas->translate(x, y); for (size_t index = 0; index < records_.size(); ++index) { PaintRecord& record = records_[index]; @@ -614,7 +614,6 @@ void Paragraph::Paint(SkCanvas* canvas, double x, double y) { canvas->drawTextBlob(record.text(), offset.x(), offset.y(), paint); PaintDecorations(canvas, offset.x(), offset.y(), index); } - canvas->translate(-x, -y); } void Paragraph::PaintDecorations(SkCanvas* canvas, diff --git a/engine/src/flutter/src/paragraph.h b/engine/src/flutter/src/paragraph.h index 3b0f4683a5..bc2281ca21 100644 --- a/engine/src/flutter/src/paragraph.h +++ b/engine/src/flutter/src/paragraph.h @@ -45,6 +45,8 @@ class Paragraph { void Layout(double width, bool force = false); + // Paints the Laid out text onto the supplied SkCanvas at (x, y) offset from + // the origin. Only valid after Layout() is called. void Paint(SkCanvas* canvas, double x, double y); const ParagraphStyle& GetParagraphStyle() const;