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"
|
2017-03-22 17:47:51 +00:00
|
|
|
#include "sk_tool_utils.h"
|
2013-10-09 18:12:23 +00:00
|
|
|
#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
|
|
|
|
|
|
|
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:
|
2016-05-12 17:09:30 +00:00
|
|
|
FontCacheGM() {}
|
2013-10-10 07:01:40 +00:00
|
|
|
|
2013-10-09 18:12:23 +00:00
|
|
|
protected:
|
2015-03-26 01:17:31 +00:00
|
|
|
SkString onShortName() override {
|
2013-10-09 18:53:35 +00:00
|
|
|
return SkString("fontcache");
|
2013-10-09 18:12:23 +00:00
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
SkISize onISize() override {
|
2014-09-03 15:44:59 +00:00
|
|
|
return SkISize::Make(1280, 640);
|
2013-10-09 18:12:23 +00:00
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void onOnceBeforeDraw() override {
|
2016-05-31 18:42:36 +00:00
|
|
|
fTypefaces[0] = sk_tool_utils::create_portable_typeface("serif",
|
|
|
|
SkFontStyle::FromOldStyle(SkTypeface::kItalic));
|
|
|
|
fTypefaces[1] = sk_tool_utils::create_portable_typeface("sans-serif",
|
|
|
|
SkFontStyle::FromOldStyle(SkTypeface::kItalic));
|
2013-10-09 18:12:23 +00:00
|
|
|
}
|
2013-10-10 07:01:40 +00:00
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void onDraw(SkCanvas* canvas) override {
|
2013-10-09 18:12:23 +00:00
|
|
|
SkPaint paint;
|
|
|
|
paint.setAntiAlias(true);
|
|
|
|
paint.setLCDRenderText(true);
|
|
|
|
paint.setSubpixelText(true);
|
2015-02-19 16:28:02 +00:00
|
|
|
paint.setTypeface(fTypefaces[0]);
|
|
|
|
paint.setTextSize(192);
|
|
|
|
|
2015-03-05 19:51:11 +00:00
|
|
|
// Make sure the nul character does not cause problems.
|
|
|
|
paint.measureText("\0", 1);
|
|
|
|
|
2015-02-19 16:28:02 +00:00
|
|
|
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;
|
2013-10-09 18:12:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2016-05-12 17:09:30 +00:00
|
|
|
sk_sp<SkTypeface> fTypefaces[2];
|
2013-10-09 18:12:23 +00:00
|
|
|
typedef GM INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2015-08-26 20:07:48 +00:00
|
|
|
DEF_GM(return new FontCacheGM;)
|