joshualitt | e4cee1f | 2015-05-11 13:04:28 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #include "gm.h" |
Mike Klein | 33d2055 | 2017-03-22 13:47:51 -0400 | [diff] [blame] | 9 | #include "sk_tool_utils.h" |
joshualitt | e4cee1f | 2015-05-11 13:04:28 -0700 | [diff] [blame] | 10 | |
| 11 | #include "SkCanvas.h" |
| 12 | #include "SkSurface.h" |
| 13 | #include "SkTextBlob.h" |
| 14 | |
| 15 | // This tests that we don't try to reuse textblobs from the GPU textblob cache across pixel geometry |
| 16 | // changes when we have LCD. crbug/486744 |
| 17 | namespace skiagm { |
| 18 | class TextBlobGeometryChange : public GM { |
| 19 | public: |
| 20 | TextBlobGeometryChange() { } |
| 21 | |
| 22 | protected: |
| 23 | SkString onShortName() override { |
| 24 | return SkString("textblobgeometrychange"); |
| 25 | } |
| 26 | |
| 27 | SkISize onISize() override { |
| 28 | return SkISize::Make(kWidth, kHeight); |
| 29 | } |
| 30 | |
| 31 | void onDraw(SkCanvas* canvas) override { |
| 32 | const char text[] = "Hamburgefons"; |
| 33 | |
Mike Reed | 28bd882 | 2018-12-22 22:29:45 -0500 | [diff] [blame] | 34 | SkFont font(sk_tool_utils::create_portable_typeface(), 20); |
| 35 | font.setEdging(SkFont::Edging::kSubpixelAntiAlias); |
joshualitt | e4cee1f | 2015-05-11 13:04:28 -0700 | [diff] [blame] | 36 | |
| 37 | SkTextBlobBuilder builder; |
| 38 | |
Mike Reed | 28bd882 | 2018-12-22 22:29:45 -0500 | [diff] [blame] | 39 | sk_tool_utils::add_to_text_blob(&builder, text, font, 10, 10); |
joshualitt | e4cee1f | 2015-05-11 13:04:28 -0700 | [diff] [blame] | 40 | |
fmalita | 37283c2 | 2016-09-13 10:00:23 -0700 | [diff] [blame] | 41 | sk_sp<SkTextBlob> blob(builder.make()); |
joshualitt | e4cee1f | 2015-05-11 13:04:28 -0700 | [diff] [blame] | 42 | |
brianosman | 0e22eb8 | 2016-08-30 07:07:59 -0700 | [diff] [blame] | 43 | SkImageInfo info = SkImageInfo::MakeN32Premul(200, 200); |
brianosman | 3a0dbde | 2016-07-26 11:36:05 -0700 | [diff] [blame] | 44 | SkSurfaceProps props(0, kUnknown_SkPixelGeometry); |
Cary Clark | a24712e | 2018-09-05 18:41:40 +0000 | [diff] [blame] | 45 | auto surface = sk_tool_utils::makeSurface(canvas, info, &props); |
mtklein | 9e65f93 | 2016-04-06 13:57:38 -0700 | [diff] [blame] | 46 | SkCanvas* c = surface->getCanvas(); |
| 47 | |
| 48 | // LCD text on white background |
| 49 | SkRect rect = SkRect::MakeLTRB(0.f, 0.f, SkIntToScalar(kWidth), kHeight / 2.f); |
| 50 | SkPaint rectPaint; |
| 51 | rectPaint.setColor(0xffffffff); |
| 52 | canvas->drawRect(rect, rectPaint); |
Mike Reed | 28bd882 | 2018-12-22 22:29:45 -0500 | [diff] [blame] | 53 | canvas->drawTextBlob(blob, 10, 50, SkPaint()); |
mtklein | 9e65f93 | 2016-04-06 13:57:38 -0700 | [diff] [blame] | 54 | |
| 55 | // This should not look garbled since we should disable LCD text in this case |
| 56 | // (i.e., unknown pixel geometry) |
| 57 | c->clear(0x00ffffff); |
Mike Reed | 28bd882 | 2018-12-22 22:29:45 -0500 | [diff] [blame] | 58 | c->drawTextBlob(blob, 10, 150, SkPaint()); |
mtklein | 9e65f93 | 2016-04-06 13:57:38 -0700 | [diff] [blame] | 59 | surface->draw(canvas, 0, 0, nullptr); |
joshualitt | e4cee1f | 2015-05-11 13:04:28 -0700 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | private: |
mtklein | dbfd7ab | 2016-09-01 11:24:54 -0700 | [diff] [blame] | 63 | static constexpr int kWidth = 200; |
| 64 | static constexpr int kHeight = 200; |
joshualitt | e4cee1f | 2015-05-11 13:04:28 -0700 | [diff] [blame] | 65 | |
| 66 | typedef GM INHERITED; |
| 67 | }; |
| 68 | |
| 69 | ////////////////////////////////////////////////////////////////////////////// |
| 70 | |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 71 | DEF_GM(return new TextBlobGeometryChange;) |
joshualitt | e4cee1f | 2015-05-11 13:04:28 -0700 | [diff] [blame] | 72 | } |