Use SkCanvasAutoRestore.

Change-Id: I35a7c65303e17132af86f552a657d226d9576850
This commit is contained in:
Gary Qian
2017-07-19 17:25:11 -07:00
parent 61418fd845
commit 4025267537
3 changed files with 12 additions and 7 deletions

View File

@@ -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<uint16_t> 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;

View File

@@ -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,

View File

@@ -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;