087fad7900
* Remove GetTypefaceOrDefault from SkPaint and SkFont * Remove RefTypefaceOrDefault from SkPaint and SkFont Change-Id: I04ae777142c2bdec849508b611b844418bbaedff Reviewed-on: https://skia-review.googlesource.com/c/185781 Reviewed-by: Mike Reed <reed@google.com> Reviewed-by: Ben Wagner <bungeman@google.com> Commit-Queue: Herb Derby <herb@google.com>
94 lines
2.8 KiB
C++
94 lines
2.8 KiB
C++
/*
|
|
* Copyright 2013 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 "SkCanvas.h"
|
|
#include "SkFont.h"
|
|
#include "SkTypeface.h"
|
|
|
|
enum {
|
|
NGLYPHS = 100
|
|
};
|
|
|
|
typedef void (*TypefaceProc)(int loops, const SkFont&, const void* text, size_t len,
|
|
int glyphCount);
|
|
|
|
static void containsText_proc(int loops, const SkFont& font, const void* text, size_t len,
|
|
int glyphCount) {
|
|
for (int i = 0; i < loops; ++i) {
|
|
font.containsText(text, len, kUTF8_SkTextEncoding);
|
|
}
|
|
}
|
|
|
|
static void textToGlyphs_proc(int loops, const SkFont& font, const void* text, size_t len,
|
|
int glyphCount) {
|
|
uint16_t glyphs[NGLYPHS];
|
|
SkASSERT(glyphCount <= NGLYPHS);
|
|
|
|
for (int i = 0; i < loops; ++i) {
|
|
font.textToGlyphs(text, len, kUTF8_SkTextEncoding, glyphs, NGLYPHS);
|
|
}
|
|
}
|
|
|
|
static void charsToGlyphs_proc(int loops, const SkFont& font, const void* text,
|
|
size_t len, int glyphCount) {
|
|
uint16_t glyphs[NGLYPHS];
|
|
SkASSERT(glyphCount <= NGLYPHS);
|
|
|
|
SkTypeface* face = font.getTypefaceOrDefault();
|
|
for (int i = 0; i < loops; ++i) {
|
|
face->charsToGlyphs(text, SkTypeface::kUTF8_Encoding, glyphs, glyphCount);
|
|
}
|
|
}
|
|
|
|
static void charsToGlyphsNull_proc(int loops, const SkFont& font, const void* text,
|
|
size_t len, int glyphCount) {
|
|
SkTypeface* face = font.getTypefaceOrDefault();
|
|
for (int i = 0; i < loops; ++i) {
|
|
face->charsToGlyphs(text, SkTypeface::kUTF8_Encoding, nullptr, glyphCount);
|
|
}
|
|
}
|
|
|
|
class CMAPBench : public Benchmark {
|
|
TypefaceProc fProc;
|
|
SkString fName;
|
|
char fText[NGLYPHS];
|
|
SkFont fFont;
|
|
|
|
public:
|
|
CMAPBench(TypefaceProc proc, const char name[]) {
|
|
fProc = proc;
|
|
fName.printf("cmap_%s", name);
|
|
|
|
for (int i = 0; i < NGLYPHS; ++i) {
|
|
// we're jamming values into utf8, so we must keep it legal utf8
|
|
fText[i] = 'A' + (i & 31);
|
|
}
|
|
fFont.setTypeface(SkTypeface::MakeDefault());
|
|
}
|
|
|
|
protected:
|
|
const char* onGetName() override {
|
|
return fName.c_str();
|
|
}
|
|
|
|
void onDraw(int loops, SkCanvas* canvas) override {
|
|
fProc(loops, fFont, fText, sizeof(fText), NGLYPHS);
|
|
}
|
|
|
|
private:
|
|
|
|
typedef Benchmark INHERITED;
|
|
};
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
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"); )
|