aboutsummaryrefslogtreecommitdiffhomepage
path: root/gm/fontcache.cpp
diff options
context:
space:
mode:
authorGravatar jvanverth <jvanverth@google.com>2015-02-19 08:28:02 -0800
committerGravatar Commit bot <commit-bot@chromium.org>2015-02-19 08:28:02 -0800
commitce07afb8fad3dd29f6d253ce83744853c10069c7 (patch)
tree5d1b0f79d66e858bbf1128944793137a5331a35f /gm/fontcache.cpp
parentf99e961f55bb603d099c8cb57d05a2ae52a4e9ca (diff)
Update fontcache gm to actually stress font atlas
Diffstat (limited to 'gm/fontcache.cpp')
-rw-r--r--gm/fontcache.cpp72
1 files changed, 28 insertions, 44 deletions
diff --git a/gm/fontcache.cpp b/gm/fontcache.cpp
index 2aa70115dd..d5ead8c121 100644
--- a/gm/fontcache.cpp
+++ b/gm/fontcache.cpp
@@ -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);
-
- 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;
- }
-
+ paint.setTypeface(fTypefaces[0]);
+ paint.setTextSize(192);
+
+ 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;
};