2018-12-18 16:04:37 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2018 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
// GM to stress TextBlob regeneration and the GPU font cache
|
|
|
|
// It's not necessary to run this with CPU configs
|
|
|
|
//
|
|
|
|
// The point here is to draw a set of text that will fit in one Plot, and then some large
|
|
|
|
// text. After a flush we draw the first set of text again with a slightly different color,
|
|
|
|
// and then enough new large text to spill the entire atlas. What *should* happen is that
|
|
|
|
// the Plot with the first set of text will not get overwritten by the new large text.
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "gm/gm.h"
|
|
|
|
#include "include/core/SkCanvas.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkColor.h"
|
|
|
|
#include "include/core/SkFont.h"
|
2019-11-14 18:42:06 +00:00
|
|
|
#include "include/core/SkFontMgr.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkFontStyle.h"
|
|
|
|
#include "include/core/SkFontTypes.h"
|
|
|
|
#include "include/core/SkPaint.h"
|
|
|
|
#include "include/core/SkRefCnt.h"
|
|
|
|
#include "include/core/SkScalar.h"
|
|
|
|
#include "include/core/SkSize.h"
|
|
|
|
#include "include/core/SkString.h"
|
|
|
|
#include "include/core/SkTextBlob.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkTypeface.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkTypes.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/gpu/GrContextOptions.h"
|
2020-07-01 16:55:01 +00:00
|
|
|
#include "include/gpu/GrDirectContext.h"
|
|
|
|
#include "include/gpu/GrRecordingContext.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/private/GrTypesPriv.h"
|
|
|
|
#include "include/private/SkTemplates.h"
|
2020-10-14 15:23:11 +00:00
|
|
|
#include "src/gpu/GrDirectContextPriv.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "tools/ToolUtils.h"
|
2018-12-18 16:04:37 +00:00
|
|
|
|
2020-12-09 21:37:04 +00:00
|
|
|
class GrSurfaceDrawContext;
|
2019-05-01 21:28:53 +00:00
|
|
|
|
2018-12-18 16:04:37 +00:00
|
|
|
static sk_sp<SkTextBlob> make_blob(const SkString& text, const SkFont& font) {
|
|
|
|
size_t len = text.size();
|
|
|
|
SkAutoTArray<SkScalar> pos(len);
|
|
|
|
SkAutoTArray<SkGlyphID> glyphs(len);
|
|
|
|
|
|
|
|
font.textToGlyphs(text.c_str(), len, SkTextEncoding::kUTF8, glyphs.get(), len);
|
|
|
|
font.getXPos(glyphs.get(), len, pos.get());
|
|
|
|
return SkTextBlob::MakeFromPosTextH(text.c_str(), len, pos.get(), 0, font);
|
|
|
|
}
|
|
|
|
|
2019-02-07 22:23:36 +00:00
|
|
|
class FontRegenGM : public skiagm::GpuGM {
|
2018-12-18 16:04:37 +00:00
|
|
|
|
|
|
|
void modifyGrContextOptions(GrContextOptions* options) override {
|
|
|
|
options->fGlyphCacheTextureMaximumBytes = 0;
|
|
|
|
options->fAllowMultipleGlyphCacheTextures = GrContextOptions::Enable::kNo;
|
|
|
|
}
|
|
|
|
|
2019-07-18 16:36:54 +00:00
|
|
|
SkString onShortName() override { return SkString("fontregen"); }
|
2018-12-18 16:04:37 +00:00
|
|
|
|
2019-07-18 16:36:54 +00:00
|
|
|
SkISize onISize() override { return {kSize, kSize}; }
|
2018-12-18 16:04:37 +00:00
|
|
|
|
|
|
|
void onOnceBeforeDraw() override {
|
2019-07-18 16:36:54 +00:00
|
|
|
this->setBGColor(SK_ColorLTGRAY);
|
|
|
|
|
2019-03-20 16:12:10 +00:00
|
|
|
auto tf = ToolUtils::create_portable_typeface("sans-serif", SkFontStyle::Normal());
|
2018-12-18 16:04:37 +00:00
|
|
|
|
|
|
|
static const SkString kTexts[] = {
|
|
|
|
SkString("abcdefghijklmnopqrstuvwxyz"),
|
|
|
|
SkString("ABCDEFGHI"),
|
|
|
|
SkString("NOPQRSTUV")
|
|
|
|
};
|
|
|
|
|
|
|
|
SkFont font;
|
|
|
|
font.setEdging(SkFont::Edging::kAntiAlias);
|
|
|
|
font.setSubpixel(false);
|
|
|
|
font.setSize(80);
|
|
|
|
font.setTypeface(tf);
|
|
|
|
|
|
|
|
fBlobs[0] = make_blob(kTexts[0], font);
|
|
|
|
font.setSize(162);
|
|
|
|
fBlobs[1] = make_blob(kTexts[1], font);
|
|
|
|
fBlobs[2] = make_blob(kTexts[2], font);
|
|
|
|
}
|
|
|
|
|
2020-12-09 21:37:04 +00:00
|
|
|
void onDraw(GrRecordingContext* context, GrSurfaceDrawContext*, SkCanvas* canvas) override {
|
2020-07-01 15:11:18 +00:00
|
|
|
auto direct = context->asDirectContext();
|
2020-06-29 19:36:12 +00:00
|
|
|
if (!direct) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-12-18 16:04:37 +00:00
|
|
|
SkPaint paint;
|
|
|
|
paint.setColor(SK_ColorBLACK);
|
|
|
|
canvas->drawTextBlob(fBlobs[0], 10, 80, paint);
|
|
|
|
canvas->drawTextBlob(fBlobs[1], 10, 225, paint);
|
2020-06-29 19:36:12 +00:00
|
|
|
direct->flushAndSubmit();
|
2018-12-18 16:04:37 +00:00
|
|
|
|
|
|
|
paint.setColor(0xFF010101);
|
|
|
|
canvas->drawTextBlob(fBlobs[0], 10, 305, paint);
|
|
|
|
canvas->drawTextBlob(fBlobs[2], 10, 465, paint);
|
|
|
|
|
|
|
|
// Debugging tool for GPU.
|
|
|
|
static const bool kShowAtlas = false;
|
|
|
|
if (kShowAtlas) {
|
2020-06-29 19:36:12 +00:00
|
|
|
auto img = direct->priv().testingOnly_getFontAtlasImage(kA8_GrMaskFormat);
|
2019-03-05 17:51:52 +00:00
|
|
|
canvas->drawImage(img, 200, 0);
|
2018-12-18 16:04:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2019-07-18 16:36:54 +00:00
|
|
|
static constexpr int kSize = 512;
|
2018-12-18 16:04:37 +00:00
|
|
|
|
|
|
|
sk_sp<SkTextBlob> fBlobs[3];
|
2020-09-03 02:42:33 +00:00
|
|
|
using INHERITED = GM;
|
2018-12-18 16:04:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
DEF_GM(return new FontRegenGM())
|
2019-11-14 18:42:06 +00:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
class BadAppleGM : public skiagm::GpuGM {
|
|
|
|
|
|
|
|
SkString onShortName() override { return SkString("badapple"); }
|
|
|
|
|
|
|
|
SkISize onISize() override { return {kSize, kSize}; }
|
|
|
|
|
|
|
|
void onOnceBeforeDraw() override {
|
|
|
|
this->setBGColor(SK_ColorWHITE);
|
|
|
|
auto fm = SkFontMgr::RefDefault();
|
|
|
|
|
|
|
|
static const SkString kTexts[] = {
|
|
|
|
SkString("Meet"),
|
|
|
|
SkString("iPad Pro"),
|
|
|
|
};
|
|
|
|
|
|
|
|
SkFont font;
|
|
|
|
font.setEdging(SkFont::Edging::kSubpixelAntiAlias);
|
|
|
|
font.setSubpixel(true);
|
|
|
|
font.setSize(256);
|
|
|
|
|
|
|
|
fBlobs[0] = make_blob(kTexts[0], font);
|
|
|
|
fBlobs[1] = make_blob(kTexts[1], font);
|
|
|
|
}
|
|
|
|
|
2020-12-09 21:37:04 +00:00
|
|
|
void onDraw(GrRecordingContext* context, GrSurfaceDrawContext*, SkCanvas* canvas) override {
|
2019-11-14 18:42:06 +00:00
|
|
|
SkPaint paint;
|
|
|
|
paint.setColor(0xFF111111);
|
|
|
|
canvas->drawTextBlob(fBlobs[0], 10, 260, paint);
|
|
|
|
canvas->drawTextBlob(fBlobs[1], 10, 500, paint);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
static constexpr int kSize = 512;
|
|
|
|
|
|
|
|
sk_sp<SkTextBlob> fBlobs[3];
|
2020-09-03 02:42:33 +00:00
|
|
|
using INHERITED = GM;
|
2019-11-14 18:42:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
DEF_GM(return new BadAppleGM())
|