2015-09-18 19:09:43 +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 "SkGlyphCache.h"
|
|
|
|
|
|
|
|
#include "Benchmark.h"
|
|
|
|
#include "SkCanvas.h"
|
2018-04-16 20:42:08 +00:00
|
|
|
#include "SkStrikeCache.h"
|
2015-09-18 19:09:43 +00:00
|
|
|
#include "SkGraphics.h"
|
|
|
|
#include "SkTaskGroup.h"
|
|
|
|
#include "SkTypeface.h"
|
|
|
|
#include "sk_tool_utils.h"
|
|
|
|
|
|
|
|
|
2018-11-28 15:28:07 +00:00
|
|
|
static void do_font_stuff(SkFont* font) {
|
|
|
|
SkPaint defaultPaint;
|
2015-09-18 19:09:43 +00:00
|
|
|
for (SkScalar i = 8; i < 64; i++) {
|
2018-11-28 15:28:07 +00:00
|
|
|
font->setSize(i);
|
2018-04-18 15:36:12 +00:00
|
|
|
auto cache = SkStrikeCache::FindOrCreateStrikeExclusive(
|
2018-11-28 15:28:07 +00:00
|
|
|
*font, defaultPaint, SkSurfaceProps(0, kUnknown_SkPixelGeometry),
|
2018-11-08 21:40:26 +00:00
|
|
|
SkScalerContextFlags::kNone, SkMatrix::I());
|
2015-09-18 19:09:43 +00:00
|
|
|
uint16_t glyphs['z'];
|
|
|
|
for (int c = ' '; c < 'z'; c++) {
|
|
|
|
glyphs[c] = cache->unicharToGlyph(c);
|
|
|
|
}
|
|
|
|
for (int lookups = 0; lookups < 10; lookups++) {
|
|
|
|
for (int c = ' '; c < 'z'; c++) {
|
|
|
|
const SkGlyph& g = cache->getGlyphIDMetrics(glyphs[c]);
|
|
|
|
cache->findImage(g);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class SkGlyphCacheBasic : public Benchmark {
|
|
|
|
public:
|
|
|
|
explicit SkGlyphCacheBasic(size_t cacheSize) : fCacheSize(cacheSize) { }
|
|
|
|
|
|
|
|
protected:
|
|
|
|
const char* onGetName() override {
|
|
|
|
fName.printf("SkGlyphCacheBasic%dK", (int)(fCacheSize >> 10));
|
|
|
|
return fName.c_str();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isSuitableFor(Backend backend) override {
|
|
|
|
return backend == kNonRendering_Backend;
|
|
|
|
}
|
|
|
|
|
2015-10-01 16:43:39 +00:00
|
|
|
void onDraw(int loops, SkCanvas*) override {
|
2015-09-18 19:09:43 +00:00
|
|
|
size_t oldCacheLimitSize = SkGraphics::GetFontCacheLimit();
|
|
|
|
SkGraphics::SetFontCacheLimit(fCacheSize);
|
2018-11-28 15:28:07 +00:00
|
|
|
SkFont font;
|
|
|
|
font.setEdging(SkFont::Edging::kAntiAlias);
|
|
|
|
font.setSubpixel(true);
|
|
|
|
font.setTypeface(sk_tool_utils::create_portable_typeface("serif", SkFontStyle::Italic()));
|
2015-09-18 19:09:43 +00:00
|
|
|
|
|
|
|
for (int work = 0; work < loops; work++) {
|
2018-11-28 15:28:07 +00:00
|
|
|
do_font_stuff(&font);
|
2015-09-18 19:09:43 +00:00
|
|
|
}
|
|
|
|
SkGraphics::SetFontCacheLimit(oldCacheLimitSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
typedef Benchmark INHERITED;
|
|
|
|
const size_t fCacheSize;
|
|
|
|
SkString fName;
|
|
|
|
};
|
|
|
|
|
|
|
|
class SkGlyphCacheStressTest : public Benchmark {
|
|
|
|
public:
|
|
|
|
explicit SkGlyphCacheStressTest(int cacheSize) : fCacheSize(cacheSize) { }
|
|
|
|
|
|
|
|
protected:
|
|
|
|
const char* onGetName() override {
|
|
|
|
fName.printf("SkGlyphCacheStressTest%dK", (int)(fCacheSize >> 10));
|
|
|
|
return fName.c_str();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isSuitableFor(Backend backend) override {
|
|
|
|
return backend == kNonRendering_Backend;
|
|
|
|
}
|
|
|
|
|
2015-10-01 16:43:39 +00:00
|
|
|
void onDraw(int loops, SkCanvas*) override {
|
2015-09-18 19:09:43 +00:00
|
|
|
size_t oldCacheLimitSize = SkGraphics::GetFontCacheLimit();
|
|
|
|
SkGraphics::SetFontCacheLimit(fCacheSize);
|
2016-05-12 17:09:30 +00:00
|
|
|
sk_sp<SkTypeface> typefaces[] =
|
2017-07-27 14:45:29 +00:00
|
|
|
{sk_tool_utils::create_portable_typeface("serif", SkFontStyle::Italic()),
|
|
|
|
sk_tool_utils::create_portable_typeface("sans-serif", SkFontStyle::Italic())};
|
2015-09-18 19:09:43 +00:00
|
|
|
|
|
|
|
for (int work = 0; work < loops; work++) {
|
2016-01-05 03:13:19 +00:00
|
|
|
SkTaskGroup().batch(16, [&](int threadIndex) {
|
2018-11-28 15:28:07 +00:00
|
|
|
SkFont font;
|
|
|
|
font.setEdging(SkFont::Edging::kAntiAlias);
|
|
|
|
font.setSubpixel(true);
|
|
|
|
font.setTypeface(typefaces[threadIndex % 2]);
|
|
|
|
do_font_stuff(&font);
|
2015-09-18 19:09:43 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
SkGraphics::SetFontCacheLimit(oldCacheLimitSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
typedef Benchmark INHERITED;
|
|
|
|
const size_t fCacheSize;
|
|
|
|
SkString fName;
|
|
|
|
};
|
|
|
|
|
|
|
|
DEF_BENCH( return new SkGlyphCacheBasic(256 * 1024); )
|
|
|
|
DEF_BENCH( return new SkGlyphCacheBasic(32 * 1024 * 1024); )
|
|
|
|
DEF_BENCH( return new SkGlyphCacheStressTest(256 * 1024); )
|
|
|
|
DEF_BENCH( return new SkGlyphCacheStressTest(32 * 1024 * 1024); )
|