2013-10-09 18:12:23 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2013 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "gm.h"
|
|
|
|
#include "SkCanvas.h"
|
|
|
|
#include "SkGraphics.h"
|
|
|
|
#include "SkTypeface.h"
|
|
|
|
|
2013-10-10 07:01:40 +00:00
|
|
|
// GM to stress the GPU font cache
|
2013-10-09 18:12:23 +00:00
|
|
|
|
|
|
|
const char* gFamilyNames[] = {
|
2014-09-03 15:44:59 +00:00
|
|
|
"sans-serif", "serif"
|
2013-10-09 18:12:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const SkTypeface::Style gStyles[] = {
|
2014-09-03 15:44:59 +00:00
|
|
|
SkTypeface::kNormal, SkTypeface::kItalic, SkTypeface::kBold
|
2013-10-09 18:12:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const SkScalar gTextSizes[] = {
|
2014-09-03 15:44:59 +00:00
|
|
|
192, 194, 196, 198, 200, 202, 204, 206
|
2013-10-09 18:12:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#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);
|
|
|
|
return x + paint.measureText(text.c_str(), text.size());
|
|
|
|
}
|
|
|
|
|
|
|
|
class FontCacheGM : public skiagm::GM {
|
|
|
|
public:
|
|
|
|
FontCacheGM() {
|
|
|
|
for (size_t i = 0; i < TYPEFACE_COUNT; ++i) {
|
|
|
|
fTypefaces[i] = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~FontCacheGM() {
|
|
|
|
for (size_t i = 0; i < TYPEFACE_COUNT; ++i) {
|
|
|
|
SkSafeUnref(fTypefaces[i]);
|
|
|
|
}
|
|
|
|
}
|
2013-10-10 07:01:40 +00:00
|
|
|
|
2013-10-09 18:12:23 +00:00
|
|
|
protected:
|
|
|
|
virtual SkString onShortName() SK_OVERRIDE {
|
2013-10-09 18:53:35 +00:00
|
|
|
return SkString("fontcache");
|
2013-10-09 18:12:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual SkISize onISize() SK_OVERRIDE {
|
2014-09-03 15:44:59 +00:00
|
|
|
return SkISize::Make(1280, 640);
|
2013-10-09 18:12:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual 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) {
|
2014-07-31 12:58:44 +00:00
|
|
|
fTypefaces[typefaceCount++] = sk_tool_utils::create_portable_typeface(gFamilyNames[i],
|
|
|
|
gStyles[j]);
|
2013-10-09 18:12:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-10-10 07:01:40 +00:00
|
|
|
|
2013-10-09 18:12:23 +00:00
|
|
|
virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
|
|
|
|
SkScalar y = 32;
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setAntiAlias(true);
|
|
|
|
paint.setLCDRenderText(true);
|
|
|
|
paint.setSubpixelText(true);
|
|
|
|
|
2014-09-03 15:44:59 +00:00
|
|
|
SkString text("H");
|
2013-10-09 18:12:23 +00:00
|
|
|
|
2014-09-03 15:44:59 +00:00
|
|
|
// draw enough to overflow the cache
|
2013-10-09 18:12:23 +00:00
|
|
|
for (size_t i = 0; i < TYPEFACE_COUNT; ++i) {
|
|
|
|
paint.setTypeface(fTypefaces[i]);
|
|
|
|
SkScalar x = 20;
|
2013-10-10 07:01:40 +00:00
|
|
|
|
2013-10-09 18:12:23 +00:00
|
|
|
for (size_t j = 0; j < SK_ARRAY_COUNT(gTextSizes); ++j) {
|
|
|
|
paint.setTextSize(gTextSizes[j]);
|
2014-09-03 15:44:59 +00:00
|
|
|
x = draw_string(canvas, text, x, y, paint) + 10;
|
2013-10-09 18:12:23 +00:00
|
|
|
}
|
2014-09-03 15:44:59 +00:00
|
|
|
y += 128;
|
2013-10-09 18:12:23 +00:00
|
|
|
}
|
2014-08-29 14:03:59 +00:00
|
|
|
|
2013-10-09 18:12:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual uint32_t onGetFlags() const SK_OVERRIDE {
|
|
|
|
// this GM is meant only for the GPU
|
|
|
|
return kGPUOnly_Flag;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
SkTypeface* fTypefaces[TYPEFACE_COUNT];
|
|
|
|
typedef GM INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
DEF_GM( return SkNEW(FontCacheGM); )
|