blob: fa8ce82c2abced645bec982d8f3072e5c6f8a407 [file] [log] [blame]
joshualitte4cee1f2015-05-11 13:04:28 -07001/*
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 Kleinc0bd9f92019-04-23 12:05:21 -05008#include "gm/gm.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -05009#include "include/core/SkCanvas.h"
Ben Wagner7fde8e12019-05-01 17:28:53 -040010#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 Kleinc0bd9f92019-04-23 12:05:21 -050018#include "include/core/SkSurface.h"
Ben Wagner7fde8e12019-05-01 17:28:53 -040019#include "include/core/SkSurfaceProps.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050020#include "include/core/SkTextBlob.h"
Ben Wagner7fde8e12019-05-01 17:28:53 -040021#include "include/core/SkTypeface.h"
22#include "tools/ToolUtils.h"
joshualitte4cee1f2015-05-11 13:04:28 -070023
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
26namespace skiagm {
27class TextBlobGeometryChange : public GM {
28public:
29 TextBlobGeometryChange() { }
30
31protected:
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 Kleinea3f0142019-03-20 11:12:10 -050043 SkFont font(ToolUtils::create_portable_typeface(), 20);
Mike Reed28bd8822018-12-22 22:29:45 -050044 font.setEdging(SkFont::Edging::kSubpixelAntiAlias);
joshualitte4cee1f2015-05-11 13:04:28 -070045
46 SkTextBlobBuilder builder;
47
Mike Kleinea3f0142019-03-20 11:12:10 -050048 ToolUtils::add_to_text_blob(&builder, text, font, 10, 10);
joshualitte4cee1f2015-05-11 13:04:28 -070049
fmalita37283c22016-09-13 10:00:23 -070050 sk_sp<SkTextBlob> blob(builder.make());
joshualitte4cee1f2015-05-11 13:04:28 -070051
brianosman0e22eb82016-08-30 07:07:59 -070052 SkImageInfo info = SkImageInfo::MakeN32Premul(200, 200);
brianosman3a0dbde2016-07-26 11:36:05 -070053 SkSurfaceProps props(0, kUnknown_SkPixelGeometry);
Mike Kleinea3f0142019-03-20 11:12:10 -050054 auto surface = ToolUtils::makeSurface(canvas, info, &props);
mtklein9e65f932016-04-06 13:57:38 -070055 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 Reed28bd8822018-12-22 22:29:45 -050062 canvas->drawTextBlob(blob, 10, 50, SkPaint());
mtklein9e65f932016-04-06 13:57:38 -070063
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 Reed28bd8822018-12-22 22:29:45 -050067 c->drawTextBlob(blob, 10, 150, SkPaint());
mtklein9e65f932016-04-06 13:57:38 -070068 surface->draw(canvas, 0, 0, nullptr);
joshualitte4cee1f2015-05-11 13:04:28 -070069 }
70
71private:
mtkleindbfd7ab2016-09-01 11:24:54 -070072 static constexpr int kWidth = 200;
73 static constexpr int kHeight = 200;
joshualitte4cee1f2015-05-11 13:04:28 -070074
75 typedef GM INHERITED;
76};
77
78//////////////////////////////////////////////////////////////////////////////
79
halcanary385fe4d2015-08-26 13:07:48 -070080DEF_GM(return new TextBlobGeometryChange;)
joshualitte4cee1f2015-05-11 13:04:28 -070081}