2013-07-02 13:56:39 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2013 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2014-06-19 19:32:29 +00:00
|
|
|
#include "Benchmark.h"
|
2013-07-02 13:56:39 +00:00
|
|
|
#include "SkCanvas.h"
|
2018-11-23 20:27:51 +00:00
|
|
|
#include "SkFont.h"
|
2013-07-02 13:56:39 +00:00
|
|
|
#include "SkTypeface.h"
|
|
|
|
|
|
|
|
enum {
|
|
|
|
NGLYPHS = 100
|
|
|
|
};
|
|
|
|
|
2018-11-23 20:27:51 +00:00
|
|
|
typedef void (*TypefaceProc)(int loops, const SkFont&, const void* text, size_t len,
|
2013-07-02 13:56:39 +00:00
|
|
|
int glyphCount);
|
|
|
|
|
2018-11-23 20:27:51 +00:00
|
|
|
static void textToGlyphs_proc(int loops, const SkFont& font, const void* text, size_t len,
|
2013-07-02 13:56:39 +00:00
|
|
|
int glyphCount) {
|
|
|
|
uint16_t glyphs[NGLYPHS];
|
|
|
|
SkASSERT(glyphCount <= NGLYPHS);
|
|
|
|
|
2013-09-10 19:23:38 +00:00
|
|
|
for (int i = 0; i < loops; ++i) {
|
2018-11-23 20:27:51 +00:00
|
|
|
font.textToGlyphs(text, len, kUTF8_SkTextEncoding, glyphs, NGLYPHS);
|
2013-07-02 13:56:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-23 20:27:51 +00:00
|
|
|
static void charsToGlyphs_proc(int loops, const SkFont& font, const void* text,
|
2013-07-02 13:56:39 +00:00
|
|
|
size_t len, int glyphCount) {
|
|
|
|
uint16_t glyphs[NGLYPHS];
|
|
|
|
SkASSERT(glyphCount <= NGLYPHS);
|
2013-07-03 07:00:57 +00:00
|
|
|
|
2019-01-22 19:45:16 +00:00
|
|
|
SkTypeface* face = font.getTypefaceOrDefault();
|
2013-09-10 19:23:38 +00:00
|
|
|
for (int i = 0; i < loops; ++i) {
|
2018-11-23 20:27:51 +00:00
|
|
|
face->charsToGlyphs(text, SkTypeface::kUTF8_Encoding, glyphs, glyphCount);
|
2013-07-02 13:56:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-23 20:27:51 +00:00
|
|
|
static void charsToGlyphsNull_proc(int loops, const SkFont& font, const void* text,
|
2013-07-02 16:28:53 +00:00
|
|
|
size_t len, int glyphCount) {
|
2019-01-22 19:45:16 +00:00
|
|
|
SkTypeface* face = font.getTypefaceOrDefault();
|
2013-09-10 19:23:38 +00:00
|
|
|
for (int i = 0; i < loops; ++i) {
|
2018-11-23 20:27:51 +00:00
|
|
|
face->charsToGlyphs(text, SkTypeface::kUTF8_Encoding, nullptr, glyphCount);
|
2013-07-02 16:28:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-19 19:32:29 +00:00
|
|
|
class CMAPBench : public Benchmark {
|
2013-07-02 13:56:39 +00:00
|
|
|
TypefaceProc fProc;
|
|
|
|
SkString fName;
|
|
|
|
char fText[NGLYPHS];
|
2018-11-23 20:27:51 +00:00
|
|
|
SkFont fFont;
|
2013-07-02 13:56:39 +00:00
|
|
|
|
|
|
|
public:
|
2013-09-13 19:52:27 +00:00
|
|
|
CMAPBench(TypefaceProc proc, const char name[]) {
|
2013-07-02 13:56:39 +00:00
|
|
|
fProc = proc;
|
|
|
|
fName.printf("cmap_%s", name);
|
2013-07-03 07:00:57 +00:00
|
|
|
|
2013-07-02 13:56:39 +00:00
|
|
|
for (int i = 0; i < NGLYPHS; ++i) {
|
2013-07-02 20:06:00 +00:00
|
|
|
// we're jamming values into utf8, so we must keep it legal utf8
|
|
|
|
fText[i] = 'A' + (i & 31);
|
2013-07-02 13:56:39 +00:00
|
|
|
}
|
2018-11-23 20:27:51 +00:00
|
|
|
fFont.setTypeface(SkTypeface::MakeDefault());
|
2013-07-02 13:56:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2015-03-26 01:17:31 +00:00
|
|
|
const char* onGetName() override {
|
2013-07-02 13:56:39 +00:00
|
|
|
return fName.c_str();
|
|
|
|
}
|
|
|
|
|
2015-10-01 16:43:39 +00:00
|
|
|
void onDraw(int loops, SkCanvas* canvas) override {
|
2018-11-23 20:27:51 +00:00
|
|
|
fProc(loops, fFont, fText, sizeof(fText), NGLYPHS);
|
2013-07-02 13:56:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
2014-06-19 19:32:29 +00:00
|
|
|
typedef Benchmark INHERITED;
|
2013-07-02 13:56:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2013-09-13 19:52:27 +00:00
|
|
|
DEF_BENCH( return new CMAPBench(textToGlyphs_proc, "paint_textToGlyphs"); )
|
|
|
|
DEF_BENCH( return new CMAPBench(charsToGlyphs_proc, "face_charsToGlyphs"); )
|
|
|
|
DEF_BENCH( return new CMAPBench(charsToGlyphsNull_proc, "face_charsToGlyphs_null"); )
|