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/gm.h" 9 #include "include/core/SkCanvas.h" 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" 18 #include "include/core/SkSurface.h" 19 #include "include/core/SkSurfaceProps.h" 20 #include "include/core/SkTextBlob.h" 21 #include "include/core/SkTypeface.h" 22 #include "tools/ToolUtils.h" 23 #include "tools/fonts/FontToolUtils.h" 24 25 // This tests that we don't try to reuse textblobs from the GPU textblob cache across pixel geometry 26 // changes when we have LCD. crbug/486744 27 namespace skiagm { 28 class TextBlobGeometryChange : public GM { 29 public: TextBlobGeometryChange()30 TextBlobGeometryChange() { } 31 32 protected: getName() const33 SkString getName() const override { return SkString("textblobgeometrychange"); } 34 getISize()35 SkISize getISize() override { return SkISize::Make(kWidth, kHeight); } 36 onDraw(SkCanvas * canvas)37 void onDraw(SkCanvas* canvas) override { 38 const char text[] = "Hamburgefons"; 39 40 SkFont font(ToolUtils::DefaultPortableTypeface(), 20); 41 font.setEdging(SkFont::Edging::kSubpixelAntiAlias); 42 43 SkTextBlobBuilder builder; 44 45 ToolUtils::add_to_text_blob(&builder, text, font, 10, 10); 46 47 sk_sp<SkTextBlob> blob(builder.make()); 48 49 SkImageInfo info = SkImageInfo::MakeN32Premul(200, 200); 50 SkSurfaceProps props(0, kUnknown_SkPixelGeometry); 51 auto surface = ToolUtils::makeSurface(canvas, info, &props); 52 SkCanvas* c = surface->getCanvas(); 53 54 // LCD text on white background 55 SkRect rect = SkRect::MakeLTRB(0.f, 0.f, SkIntToScalar(kWidth), kHeight / 2.f); 56 SkPaint rectPaint; 57 rectPaint.setColor(0xffffffff); 58 canvas->drawRect(rect, rectPaint); 59 canvas->drawTextBlob(blob, 10, 50, SkPaint()); 60 61 // This should not look garbled since we should disable LCD text in this case 62 // (i.e., unknown pixel geometry) 63 c->clear(0x00ffffff); 64 c->drawTextBlob(blob, 10, 150, SkPaint()); 65 surface->draw(canvas, 0, 0); 66 } 67 68 private: 69 inline static constexpr int kWidth = 200; 70 inline static constexpr int kHeight = 200; 71 72 using INHERITED = GM; 73 }; 74 75 ////////////////////////////////////////////////////////////////////////////// 76 77 DEF_GM(return new TextBlobGeometryChange;) 78 } // namespace skiagm 79