diff options
author | 2017-11-06 10:36:57 -0500 | |
---|---|---|
committer | 2017-11-06 16:06:09 +0000 | |
commit | 9f545bc18a1fdff64d40104028c6d8449e660a6e (patch) | |
tree | 3f2b5eb9124f53d4fd9610445ceb5d374ae7d424 /gm | |
parent | 97f0bc6a1a0d14fd7b9041c39449966535f9f431 (diff) |
Modify fontcache GM to actually spill atlas.
Adds an option to GrDrawOpAtlas to disable multitexturing.
Adds option to GrContextOptions to disable multitexturing for glyph atlases.
Change-Id: If413ab7061538fa0e75628d252be4fd14215b6ba
Reviewed-on: https://skia-review.googlesource.com/67802
Reviewed-by: Jim Van Verth <jvanverth@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
Diffstat (limited to 'gm')
-rw-r--r-- | gm/fontcache.cpp | 105 |
1 files changed, 72 insertions, 33 deletions
diff --git a/gm/fontcache.cpp b/gm/fontcache.cpp index a8c5b768c3..b93cc3f031 100644 --- a/gm/fontcache.cpp +++ b/gm/fontcache.cpp @@ -5,11 +5,14 @@ * found in the LICENSE file. */ -#include "gm.h" -#include "sk_tool_utils.h" +#include "GrContext.h" +#include "GrContextOptions.h" #include "SkCanvas.h" #include "SkGraphics.h" +#include "SkImage.h" #include "SkTypeface.h" +#include "gm.h" +#include "sk_tool_utils.h" // GM to stress the GPU font cache @@ -21,58 +24,94 @@ static SkScalar draw_string(SkCanvas* canvas, const SkString& text, SkScalar x, class FontCacheGM : public skiagm::GM { public: - FontCacheGM() {} + FontCacheGM() { this->setBGColor(SK_ColorLTGRAY); } + + void modifyGrContextOptions(GrContextOptions* options) override { + options->fGlyphCacheTextureMaximumBytes = 0; + options->fAllowMultipleGlyphCacheTextures = GrContextOptions::Enable::kNo; + } protected: SkString onShortName() override { return SkString("fontcache"); } - SkISize onISize() override { - return SkISize::Make(1280, 640); - } + SkISize onISize() override { return SkISize::Make(kSize, kSize); } void onOnceBeforeDraw() override { fTypefaces[0] = sk_tool_utils::create_portable_typeface("serif", SkFontStyle::Italic()); fTypefaces[1] = sk_tool_utils::create_portable_typeface("sans-serif",SkFontStyle::Italic()); + fTypefaces[2] = sk_tool_utils::create_portable_typeface("serif", SkFontStyle::Normal()); + fTypefaces[3] = + sk_tool_utils::create_portable_typeface("sans-serif", SkFontStyle::Normal()); + fTypefaces[4] = sk_tool_utils::create_portable_typeface("serif", SkFontStyle::Bold()); + fTypefaces[5] = sk_tool_utils::create_portable_typeface("sans-serif", SkFontStyle::Bold()); } void onDraw(SkCanvas* canvas) override { + canvas->clear(SK_ColorLTGRAY); + this->drawText(canvas); + // Debugging tool for GPU. + static const bool kShowAtlas = false; + if (kShowAtlas) { + if (auto ctx = canvas->getGrContext()) { + auto img = ctx->getFontAtlasImage_ForTesting(kA8_GrMaskFormat); + canvas->drawImage(img, 0, 0); + } + } + } + +private: + void drawText(SkCanvas* canvas) { + static const int kSizes[] = {8, 9, 10, 11, 12, 13, 18, 20, 25}; + + static const SkString kTexts[] = {SkString("ABCDEFGHIJKLMNOPQRSTUVWXYZ"), + SkString("abcdefghijklmnopqrstuvwxyz"), + SkString("0123456789"), + SkString("!@#$%^&*()<>[]{}")}; SkPaint paint; paint.setAntiAlias(true); - paint.setLCDRenderText(true); + paint.setLCDRenderText(false); paint.setSubpixelText(true); - paint.setTypeface(fTypefaces[0]); - paint.setTextSize(192); - - // Make sure the nul character does not cause problems. - paint.measureText("\0", 1); - - 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; + + static const SkScalar kSubPixelInc = 1 / 2.f; + SkScalar x = 0; + SkScalar y = 10; + SkScalar subpixelX = 0; + SkScalar subpixelY = 0; + bool offsetX = true; + + do { + for (auto s : kSizes) { + auto size = 2 * s; + paint.setTextSize(size); + for (const auto& typeface : fTypefaces) { + paint.setTypeface(typeface); + for (const auto& text : kTexts) { + x = size + draw_string(canvas, text, x + subpixelX, y + subpixelY, paint); + x = SkScalarCeilToScalar(x); + if (x + 100 > kSize) { + x = 0; + y += SkScalarCeilToScalar(size + 3); + if (y > kSize) { + return; + } + } + } + } + (offsetX ? subpixelX : subpixelY) += kSubPixelInc; + offsetX = !offsetX; + } + } while (true); } -private: - sk_sp<SkTypeface> fTypefaces[2]; + static constexpr SkScalar kSize = 1280; + + sk_sp<SkTypeface> fTypefaces[6]; typedef GM INHERITED; }; +constexpr SkScalar FontCacheGM::kSize; ////////////////////////////////////////////////////////////////////////////// |