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