2 * Copyright 2015 Google Inc.
4 * Use of this source code is governed by a BD-style license that can be
5 * found in the LICENSE file.
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"
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
27 class TextBlobGeometryChange : public GM {
29 TextBlobGeometryChange() { }
32 SkString onShortName() override {
33 return SkString("textblobgeometrychange");
36 SkISize onISize() override {
37 return SkISize::Make(kWidth, kHeight);
40 void onDraw(SkCanvas* canvas) override {
41 const char text[] = "Hamburgefons";
43 SkFont font(ToolUtils::create_portable_typeface(), 20);
44 font.setEdging(SkFont::Edging::kSubpixelAntiAlias);
46 SkTextBlobBuilder builder;
48 ToolUtils::add_to_text_blob(&builder, text, font, 10, 10);
50 sk_sp<SkTextBlob> blob(builder.make());
52 SkImageInfo info = SkImageInfo::MakeN32Premul(200, 200);
53 SkSurfaceProps props(0, kUnknown_SkPixelGeometry);
54 auto surface = ToolUtils::makeSurface(canvas, info, &props);
55 SkCanvas* c = surface->getCanvas();
57 // LCD text on white background
58 SkRect rect = SkRect::MakeLTRB(0.f, 0.f, SkIntToScalar(kWidth), kHeight / 2.f);
60 rectPaint.setColor(0xffffffff);
61 canvas->drawRect(rect, rectPaint);
62 canvas->drawTextBlob(blob, 10, 50, SkPaint());
64 // This should not look garbled since we should disable LCD text in this case
65 // (i.e., unknown pixel geometry)
67 c->drawTextBlob(blob, 10, 150, SkPaint());
68 surface->draw(canvas, 0, 0);
72 inline static constexpr int kWidth = 200;
73 inline static constexpr int kHeight = 200;
78 //////////////////////////////////////////////////////////////////////////////
80 DEF_GM(return new TextBlobGeometryChange;)