Remove redundant height_ variable and add Paragraph::Paint Benchmark.
Change-Id: I82c4aee759f6ae8a869782f4fb9d979d1551eed9
This commit is contained in:
@@ -28,6 +28,8 @@
|
||||
#include "lib/txt/src/paragraph_builder.h"
|
||||
#include "lib/txt/src/text_align.h"
|
||||
#include "third_party/icu/source/common/unicode/unistr.h"
|
||||
#include "third_party/skia/include/core/SkBitmap.h"
|
||||
#include "third_party/skia/include/core/SkCanvas.h"
|
||||
#include "third_party/skia/include/core/SkColor.h"
|
||||
#include "utils.h"
|
||||
|
||||
@@ -223,6 +225,35 @@ BENCHMARK(BM_ParagraphStylesBigO)
|
||||
->Range(1 << 3, 1 << 12)
|
||||
->Complexity(benchmark::oN);
|
||||
|
||||
static void BM_ParagraphPaintSimple(benchmark::State& state) {
|
||||
const char* text = "Hello world! This is a simple sentence to test drawing.";
|
||||
auto icu_text = icu::UnicodeString::fromUTF8(text);
|
||||
std::u16string u16_text(icu_text.getBuffer(),
|
||||
icu_text.getBuffer() + icu_text.length());
|
||||
|
||||
txt::ParagraphStyle paragraph_style;
|
||||
|
||||
txt::TextStyle text_style;
|
||||
text_style.color = SK_ColorBLACK;
|
||||
auto font_collection = FontCollection::GetFontCollection(txt::GetFontDir());
|
||||
txt::ParagraphBuilder builder(paragraph_style, &font_collection);
|
||||
builder.PushStyle(text_style);
|
||||
builder.AddText(u16_text);
|
||||
auto paragraph = builder.Build();
|
||||
paragraph->Layout(300, true);
|
||||
|
||||
std::unique_ptr<SkBitmap> bitmap = std::make_unique<SkBitmap>();
|
||||
std::unique_ptr<SkCanvas> canvas = std::make_unique<SkCanvas>(*bitmap);
|
||||
bitmap->allocN32Pixels(1000, 1000);
|
||||
canvas->clear(SK_ColorWHITE);
|
||||
int offset = 0;
|
||||
while (state.KeepRunning()) {
|
||||
paragraph->Paint(canvas.get(), offset % 700, 10);
|
||||
offset++;
|
||||
}
|
||||
}
|
||||
BENCHMARK(BM_ParagraphPaintSimple);
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
//
|
||||
// The following benchmarks break down the layout function and attempts to time
|
||||
|
||||
@@ -221,7 +221,6 @@ void Paragraph::Layout(double width, bool force) {
|
||||
line_heights_ = std::vector<double>();
|
||||
line_heights_.push_back(0);
|
||||
records_ = std::vector<PaintRecord>();
|
||||
height_ = 0.0f;
|
||||
|
||||
// Set padding elements to have a minimum point.
|
||||
glyph_position_x_ = std::vector<std::vector<double>>();
|
||||
@@ -477,7 +476,6 @@ void Paragraph::Layout(double width, bool force) {
|
||||
}
|
||||
// Handle last line tasks.
|
||||
y += roundf(max_line_spacing + prev_max_descent);
|
||||
height_ = y + roundf(max_descent);
|
||||
postprocess_line();
|
||||
if (line_width != 0)
|
||||
line_widths_.push_back(line_width);
|
||||
@@ -589,7 +587,7 @@ size_t Paragraph::TextSize() const {
|
||||
}
|
||||
|
||||
double Paragraph::GetHeight() const {
|
||||
return height_;
|
||||
return line_heights_[line_heights_.size() - 2];
|
||||
}
|
||||
|
||||
double Paragraph::GetLayoutWidth() const {
|
||||
|
||||
@@ -187,7 +187,6 @@ class Paragraph {
|
||||
// The max width of the paragraph as provided in the most recent Layout()
|
||||
// call.
|
||||
double width_ = -1.0f;
|
||||
SkScalar height_ = 0.0f;
|
||||
size_t lines_ = 0;
|
||||
double max_intrinsic_width_ = 0;
|
||||
double min_intrinsic_width_ = 0;
|
||||
|
||||
Reference in New Issue
Block a user