2015-04-03 15:07:26 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2015 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "Benchmark.h"
|
|
|
|
#include "Resources.h"
|
|
|
|
#include "SkCanvas.h"
|
|
|
|
#include "SkPaint.h"
|
|
|
|
#include "SkRandom.h"
|
|
|
|
#include "SkStream.h"
|
|
|
|
#include "SkString.h"
|
|
|
|
#include "SkTemplates.h"
|
|
|
|
#include "SkTextBlob.h"
|
|
|
|
#include "SkTypeface.h"
|
|
|
|
|
|
|
|
#include "sk_tool_utils.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* A trivial test which benchmarks the performance of a textblob with a single run.
|
|
|
|
*/
|
|
|
|
class TextBlobBench : public Benchmark {
|
|
|
|
public:
|
2016-05-12 17:09:30 +00:00
|
|
|
TextBlobBench() {}
|
2015-05-21 13:15:28 +00:00
|
|
|
|
|
|
|
protected:
|
2015-09-30 19:11:07 +00:00
|
|
|
void onDelayedSetup() override {
|
2016-05-31 18:42:36 +00:00
|
|
|
fTypeface = sk_tool_utils::create_portable_typeface("serif", SkFontStyle());
|
2015-04-03 15:07:26 +00:00
|
|
|
// make textblob
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setTypeface(fTypeface);
|
|
|
|
const char* text = "Hello blob!";
|
|
|
|
SkTDArray<uint16_t> glyphs;
|
|
|
|
size_t len = strlen(text);
|
2015-08-27 14:41:13 +00:00
|
|
|
glyphs.append(paint.textToGlyphs(text, len, nullptr));
|
2015-04-03 15:07:26 +00:00
|
|
|
paint.textToGlyphs(text, len, glyphs.begin());
|
|
|
|
|
|
|
|
SkTextBlobBuilder builder;
|
|
|
|
|
|
|
|
paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
|
|
|
|
const SkTextBlobBuilder::RunBuffer& run = builder.allocRun(paint, glyphs.count(), 10, 10,
|
2015-08-27 14:41:13 +00:00
|
|
|
nullptr);
|
2015-04-03 15:07:26 +00:00
|
|
|
memcpy(run.glyphs, glyphs.begin(), glyphs.count() * sizeof(uint16_t));
|
|
|
|
|
2016-09-13 17:00:23 +00:00
|
|
|
fBlob = builder.make();
|
2015-04-03 15:07:26 +00:00
|
|
|
}
|
|
|
|
|
2015-07-13 13:18:39 +00:00
|
|
|
const char* onGetName() override {
|
2015-04-03 15:07:26 +00:00
|
|
|
return "TextBlobBench";
|
|
|
|
}
|
|
|
|
|
2015-10-01 16:43:39 +00:00
|
|
|
void onDraw(int loops, SkCanvas* canvas) override {
|
2015-04-03 15:07:26 +00:00
|
|
|
SkPaint paint;
|
|
|
|
|
|
|
|
// To ensure maximum caching, we just redraw the blob at the same place everytime
|
|
|
|
for (int i = 0; i < loops; i++) {
|
|
|
|
canvas->drawTextBlob(fBlob, 0, 0, paint);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
2016-09-13 17:00:23 +00:00
|
|
|
sk_sp<SkTextBlob> fBlob;
|
|
|
|
SkTDArray<uint16_t> fGlyphs;
|
|
|
|
sk_sp<SkTypeface> fTypeface;
|
2015-04-03 15:07:26 +00:00
|
|
|
|
|
|
|
typedef Benchmark INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
DEF_BENCH( return new TextBlobBench(); )
|