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
|
// 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,
|
static SkScalar draw_string(SkCanvas* canvas, const SkString& text, SkScalar x,
|
||||||
SkScalar y, const SkPaint& paint) {
|
SkScalar y, const SkPaint& paint) {
|
||||||
canvas->drawText(text.c_str(), text.size(), x, y, 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 {
|
class FontCacheGM : public skiagm::GM {
|
||||||
public:
|
public:
|
||||||
FontCacheGM() {
|
FontCacheGM() {
|
||||||
for (size_t i = 0; i < TYPEFACE_COUNT; ++i) {
|
fTypefaces[0] = NULL;
|
||||||
fTypefaces[i] = NULL;
|
fTypefaces[1] = NULL;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual ~FontCacheGM() {
|
virtual ~FontCacheGM() {
|
||||||
for (size_t i = 0; i < TYPEFACE_COUNT; ++i) {
|
SkSafeUnref(fTypefaces[0]);
|
||||||
SkSafeUnref(fTypefaces[i]);
|
SkSafeUnref(fTypefaces[1]);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@ -56,40 +40,40 @@ protected:
|
|||||||
}
|
}
|
||||||
|
|
||||||
void onOnceBeforeDraw() SK_OVERRIDE {
|
void onOnceBeforeDraw() SK_OVERRIDE {
|
||||||
int typefaceCount = 0;
|
fTypefaces[0] = sk_tool_utils::create_portable_typeface("serif", SkTypeface::kItalic);
|
||||||
for (size_t i = 0; i < SK_ARRAY_COUNT(gFamilyNames); ++i) {
|
fTypefaces[1] = sk_tool_utils::create_portable_typeface("sans-serif", SkTypeface::kItalic);
|
||||||
for (size_t j = 0; j < SK_ARRAY_COUNT(gStyles); ++j) {
|
|
||||||
fTypefaces[typefaceCount++] = sk_tool_utils::create_portable_typeface(gFamilyNames[i],
|
|
||||||
gStyles[j]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void onDraw(SkCanvas* canvas) SK_OVERRIDE {
|
void onDraw(SkCanvas* canvas) SK_OVERRIDE {
|
||||||
SkScalar y = 32;
|
|
||||||
SkPaint paint;
|
SkPaint paint;
|
||||||
paint.setAntiAlias(true);
|
paint.setAntiAlias(true);
|
||||||
paint.setLCDRenderText(true);
|
paint.setLCDRenderText(true);
|
||||||
paint.setSubpixelText(true);
|
paint.setSubpixelText(true);
|
||||||
|
paint.setTypeface(fTypefaces[0]);
|
||||||
|
paint.setTextSize(192);
|
||||||
|
|
||||||
SkString text("H");
|
SkScalar x = 20;
|
||||||
|
SkScalar y = 128;
|
||||||
// draw enough to overflow the cache
|
SkString text("ABCDEFGHIJ");
|
||||||
for (size_t i = 0; i < TYPEFACE_COUNT; ++i) {
|
draw_string(canvas, text, x, y, paint);
|
||||||
paint.setTypeface(fTypefaces[i]);
|
y += 100;
|
||||||
SkScalar x = 20;
|
SkString text2("KLMNOPQRS");
|
||||||
|
draw_string(canvas, text2, x, y, paint);
|
||||||
for (size_t j = 0; j < SK_ARRAY_COUNT(gTextSizes); ++j) {
|
y += 100;
|
||||||
paint.setTextSize(gTextSizes[j]);
|
SkString text3("TUVWXYZ012");
|
||||||
x = draw_string(canvas, text, x, y, paint) + 10;
|
draw_string(canvas, text3, x, y, paint);
|
||||||
}
|
y += 100;
|
||||||
y += 128;
|
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:
|
private:
|
||||||
SkTypeface* fTypefaces[TYPEFACE_COUNT];
|
SkTypeface* fTypefaces[2];
|
||||||
typedef GM INHERITED;
|
typedef GM INHERITED;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user