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"
|
|
|
|
#include "SkPaint.h"
|
|
|
|
#include "SkTypeface.h"
|
|
|
|
|
|
|
|
enum {
|
|
|
|
NGLYPHS = 100
|
|
|
|
};
|
|
|
|
|
|
|
|
static SkTypeface::Encoding paint2Encoding(const SkPaint& paint) {
|
|
|
|
SkPaint::TextEncoding enc = paint.getTextEncoding();
|
|
|
|
SkASSERT(SkPaint::kGlyphID_TextEncoding != enc);
|
|
|
|
return (SkTypeface::Encoding)enc;
|
|
|
|
}
|
|
|
|
|
2013-09-10 19:23:38 +00:00
|
|
|
typedef void (*TypefaceProc)(int loops, const SkPaint&, const void* text, size_t len,
|
2013-07-02 13:56:39 +00:00
|
|
|
int glyphCount);
|
|
|
|
|
2013-09-10 19:23:38 +00:00
|
|
|
static void containsText_proc(int loops, const SkPaint& paint, const void* text, size_t len,
|
2013-07-02 13:56:39 +00:00
|
|
|
int glyphCount) {
|
2013-09-10 19:23:38 +00:00
|
|
|
for (int i = 0; i < loops; ++i) {
|
2013-07-02 13:56:39 +00:00
|
|
|
paint.containsText(text, len);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-10 19:23:38 +00:00
|
|
|
static void textToGlyphs_proc(int loops, const SkPaint& paint, 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) {
|
2013-07-02 13:56:39 +00:00
|
|
|
paint.textToGlyphs(text, len, glyphs);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-10 19:23:38 +00:00
|
|
|
static void charsToGlyphs_proc(int loops, const SkPaint& paint, const void* text,
|
2013-07-02 13:56:39 +00:00
|
|
|
size_t len, int glyphCount) {
|
|
|
|
SkTypeface::Encoding encoding = paint2Encoding(paint);
|
|
|
|
uint16_t glyphs[NGLYPHS];
|
|
|
|
SkASSERT(glyphCount <= NGLYPHS);
|
2013-07-03 07:00:57 +00:00
|
|
|
|
2013-07-02 13:56:39 +00:00
|
|
|
SkTypeface* face = paint.getTypeface();
|
2013-09-10 19:23:38 +00:00
|
|
|
for (int i = 0; i < loops; ++i) {
|
2013-07-02 13:56:39 +00:00
|
|
|
face->charsToGlyphs(text, encoding, glyphs, glyphCount);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-10 19:23:38 +00:00
|
|
|
static void charsToGlyphsNull_proc(int loops, const SkPaint& paint, const void* text,
|
2013-07-02 16:28:53 +00:00
|
|
|
size_t len, int glyphCount) {
|
|
|
|
SkTypeface::Encoding encoding = paint2Encoding(paint);
|
2013-07-03 07:00:57 +00:00
|
|
|
|
2013-07-02 16:28:53 +00:00
|
|
|
SkTypeface* face = paint.getTypeface();
|
2013-09-10 19:23:38 +00:00
|
|
|
for (int i = 0; i < loops; ++i) {
|
2013-07-02 16:28:53 +00:00
|
|
|
face->charsToGlyphs(text, encoding, NULL, glyphCount);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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];
|
|
|
|
SkPaint fPaint;
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
fPaint.setTypeface(SkTypeface::RefDefault())->unref();
|
|
|
|
}
|
|
|
|
|
|
|
|
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-03-26 01:17:31 +00:00
|
|
|
void onDraw(const int loops, SkCanvas* canvas) override {
|
2013-12-03 18:17:16 +00:00
|
|
|
fProc(loops, fPaint, 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(containsText_proc, "paint_containsText"); )
|
|
|
|
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"); )
|