Update fontcache gm to actually stress font atlas
BUG=skia: Review URL: https://codereview.chromium.org/933313004
This commit is contained in:
parent
f99e961f55
commit
ce07afb8fa
@ -12,20 +12,6 @@
|
||||
|
||||
// GM to stress the GPU font cache
|
||||
|
||||
const char* gFamilyNames[] = {
|
||||
"sans-serif", "serif"
|
||||
};
|
||||
|
||||
const SkTypeface::Style gStyles[] = {
|
||||
SkTypeface::kNormal, SkTypeface::kItalic, SkTypeface::kBold
|
||||
};
|
||||
|
||||
const SkScalar gTextSizes[] = {
|
||||
192, 194, 196, 198, 200, 202, 204, 206
|
||||
};
|
||||
|
||||
#define TYPEFACE_COUNT (SK_ARRAY_COUNT(gFamilyNames)*SK_ARRAY_COUNT(gStyles))
|
||||
|
||||
static SkScalar draw_string(SkCanvas* canvas, const SkString& text, SkScalar x,
|
||||
SkScalar y, const SkPaint& paint) {
|
||||
canvas->drawText(text.c_str(), text.size(), x, y, paint);
|
||||
@ -35,15 +21,13 @@ static SkScalar draw_string(SkCanvas* canvas, const SkString& text, SkScalar x,
|
||||
class FontCacheGM : public skiagm::GM {
|
||||
public:
|
||||
FontCacheGM() {
|
||||
for (size_t i = 0; i < TYPEFACE_COUNT; ++i) {
|
||||
fTypefaces[i] = NULL;
|
||||
}
|
||||
fTypefaces[0] = NULL;
|
||||
fTypefaces[1] = NULL;
|
||||
}
|
||||
|
||||
virtual ~FontCacheGM() {
|
||||
for (size_t i = 0; i < TYPEFACE_COUNT; ++i) {
|
||||
SkSafeUnref(fTypefaces[i]);
|
||||
}
|
||||
SkSafeUnref(fTypefaces[0]);
|
||||
SkSafeUnref(fTypefaces[1]);
|
||||
}
|
||||
|
||||
protected:
|
||||
@ -56,40 +40,40 @@ protected:
|
||||
}
|
||||
|
||||
void onOnceBeforeDraw() SK_OVERRIDE {
|
||||
int typefaceCount = 0;
|
||||
for (size_t i = 0; i < SK_ARRAY_COUNT(gFamilyNames); ++i) {
|
||||
for (size_t j = 0; j < SK_ARRAY_COUNT(gStyles); ++j) {
|
||||
fTypefaces[typefaceCount++] = sk_tool_utils::create_portable_typeface(gFamilyNames[i],
|
||||
gStyles[j]);
|
||||
}
|
||||
}
|
||||
fTypefaces[0] = sk_tool_utils::create_portable_typeface("serif", SkTypeface::kItalic);
|
||||
fTypefaces[1] = sk_tool_utils::create_portable_typeface("sans-serif", SkTypeface::kItalic);
|
||||
}
|
||||
|
||||
void onDraw(SkCanvas* canvas) SK_OVERRIDE {
|
||||
SkScalar y = 32;
|
||||
SkPaint paint;
|
||||
paint.setAntiAlias(true);
|
||||
paint.setLCDRenderText(true);
|
||||
paint.setSubpixelText(true);
|
||||
paint.setTypeface(fTypefaces[0]);
|
||||
paint.setTextSize(192);
|
||||
|
||||
SkString text("H");
|
||||
|
||||
// draw enough to overflow the cache
|
||||
for (size_t i = 0; i < TYPEFACE_COUNT; ++i) {
|
||||
paint.setTypeface(fTypefaces[i]);
|
||||
SkScalar x = 20;
|
||||
|
||||
for (size_t j = 0; j < SK_ARRAY_COUNT(gTextSizes); ++j) {
|
||||
paint.setTextSize(gTextSizes[j]);
|
||||
x = draw_string(canvas, text, x, y, paint) + 10;
|
||||
}
|
||||
y += 128;
|
||||
}
|
||||
|
||||
SkScalar x = 20;
|
||||
SkScalar y = 128;
|
||||
SkString text("ABCDEFGHIJ");
|
||||
draw_string(canvas, text, x, y, paint);
|
||||
y += 100;
|
||||
SkString text2("KLMNOPQRS");
|
||||
draw_string(canvas, text2, x, y, paint);
|
||||
y += 100;
|
||||
SkString text3("TUVWXYZ012");
|
||||
draw_string(canvas, text3, x, y, paint);
|
||||
y += 100;
|
||||
paint.setTypeface(fTypefaces[1]);
|
||||
draw_string(canvas, text, x, y, paint);
|
||||
y += 100;
|
||||
draw_string(canvas, text2, x, y, paint);
|
||||
y += 100;
|
||||
draw_string(canvas, text3, x, y, paint);
|
||||
y += 100;
|
||||
}
|
||||
|
||||
private:
|
||||
SkTypeface* fTypefaces[TYPEFACE_COUNT];
|
||||
SkTypeface* fTypefaces[2];
|
||||
typedef GM INHERITED;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user