1062963232
This reverts commit b07aba4214
.
Reason for revert: Changes GMs
Original change's description:
> Move remove ptr args to MakeRecAndEffects
>
> Move this conversion out through the transitive closure of calls. As you
> move up the stack, everything becomes refs instread of pointers.
>
> Reorder args of MakeRecAndEffects and setupCache to match the majority of other
> calls.
>
> Change-Id: I72baf457cd9140f76ee5f7122493284c4be5bcd0
> Reviewed-on: https://skia-review.googlesource.com/c/169765
> Reviewed-by: Ben Wagner <bungeman@google.com>
> Commit-Queue: Herb Derby <herb@google.com>
TBR=bungeman@google.com,herb@google.com
Change-Id: I29e54cea5b7b5709dd6db6816cb6556d73e003e0
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://skia-review.googlesource.com/c/170221
Reviewed-by: Herb Derby <herb@google.com>
Commit-Queue: Herb Derby <herb@google.com>
116 lines
3.5 KiB
C++
116 lines
3.5 KiB
C++
/*
|
|
* 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"
|
|
#include "SkStrikeCache.h"
|
|
#include "SkGraphics.h"
|
|
#include "SkTaskGroup.h"
|
|
#include "SkTypeface.h"
|
|
#include "sk_tool_utils.h"
|
|
|
|
|
|
static void do_font_stuff(SkPaint* paint) {
|
|
for (SkScalar i = 8; i < 64; i++) {
|
|
paint->setTextSize(i);
|
|
auto cache = SkStrikeCache::FindOrCreateStrikeExclusive(
|
|
*paint, nullptr, SkScalerContextFlags::kNone, nullptr);
|
|
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;
|
|
}
|
|
|
|
void onDraw(int loops, SkCanvas*) override {
|
|
size_t oldCacheLimitSize = SkGraphics::GetFontCacheLimit();
|
|
SkGraphics::SetFontCacheLimit(fCacheSize);
|
|
SkPaint paint;
|
|
paint.setAntiAlias(true);
|
|
paint.setSubpixelText(true);
|
|
paint.setTypeface(sk_tool_utils::create_portable_typeface("serif", SkFontStyle::Italic()));
|
|
|
|
for (int work = 0; work < loops; work++) {
|
|
do_font_stuff(&paint);
|
|
}
|
|
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;
|
|
}
|
|
|
|
void onDraw(int loops, SkCanvas*) override {
|
|
size_t oldCacheLimitSize = SkGraphics::GetFontCacheLimit();
|
|
SkGraphics::SetFontCacheLimit(fCacheSize);
|
|
sk_sp<SkTypeface> typefaces[] =
|
|
{sk_tool_utils::create_portable_typeface("serif", SkFontStyle::Italic()),
|
|
sk_tool_utils::create_portable_typeface("sans-serif", SkFontStyle::Italic())};
|
|
|
|
for (int work = 0; work < loops; work++) {
|
|
SkTaskGroup().batch(16, [&](int threadIndex) {
|
|
SkPaint paint;
|
|
paint.setAntiAlias(true);
|
|
paint.setSubpixelText(true);
|
|
paint.setTypeface(typefaces[threadIndex % 2]);
|
|
do_font_stuff(&paint);
|
|
});
|
|
}
|
|
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); )
|