blob: b80104e61eb3d3a88dbf8eb4df4651a495366716 [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"
Kevin Lubicke836c3a2023-10-20 06:55:35 -040023#include "tools/fonts/FontToolUtils.h"
joshualitte4cee1f2015-05-11 13:04:28 -070024
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
27namespace skiagm {
28class TextBlobGeometryChange : public GM {
29public:
30 TextBlobGeometryChange() { }
31
32protected:
Leandro Lovisolo24fa2112023-08-15 19:05:17 +000033 SkString getName() const override { return SkString("textblobgeometrychange"); }
joshualitte4cee1f2015-05-11 13:04:28 -070034
Leandro Lovisolo8f023882023-08-15 21:13:52 +000035 SkISize getISize() override { return SkISize::Make(kWidth, kHeight); }
joshualitte4cee1f2015-05-11 13:04:28 -070036
37 void onDraw(SkCanvas* canvas) override {
38 const char text[] = "Hamburgefons";
39
Kevin Lubicke836c3a2023-10-20 06:55:35 -040040 SkFont font(ToolUtils::DefaultPortableTypeface(), 20);
Mike Reed28bd8822018-12-22 22:29:45 -050041 font.setEdging(SkFont::Edging::kSubpixelAntiAlias);
joshualitte4cee1f2015-05-11 13:04:28 -070042
43 SkTextBlobBuilder builder;
44
Mike Kleinea3f0142019-03-20 11:12:10 -050045 ToolUtils::add_to_text_blob(&builder, text, font, 10, 10);
joshualitte4cee1f2015-05-11 13:04:28 -070046
fmalita37283c22016-09-13 10:00:23 -070047 sk_sp<SkTextBlob> blob(builder.make());
joshualitte4cee1f2015-05-11 13:04:28 -070048
brianosman0e22eb82016-08-30 07:07:59 -070049 SkImageInfo info = SkImageInfo::MakeN32Premul(200, 200);
brianosman3a0dbde2016-07-26 11:36:05 -070050 SkSurfaceProps props(0, kUnknown_SkPixelGeometry);
Mike Kleinea3f0142019-03-20 11:12:10 -050051 auto surface = ToolUtils::makeSurface(canvas, info, &props);
mtklein9e65f932016-04-06 13:57:38 -070052 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);
Mike Reed28bd8822018-12-22 22:29:45 -050059 canvas->drawTextBlob(blob, 10, 50, SkPaint());
mtklein9e65f932016-04-06 13:57:38 -070060
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);
Mike Reed28bd8822018-12-22 22:29:45 -050064 c->drawTextBlob(blob, 10, 150, SkPaint());
Mike Reedb746b1f2021-01-06 08:43:51 -050065 surface->draw(canvas, 0, 0);
joshualitte4cee1f2015-05-11 13:04:28 -070066 }
67
68private:
Brian Salomon9fa47cc2021-10-08 18:48:26 -040069 inline static constexpr int kWidth = 200;
70 inline static constexpr int kHeight = 200;
joshualitte4cee1f2015-05-11 13:04:28 -070071
John Stiles7571f9e2020-09-02 22:42:33 -040072 using INHERITED = GM;
joshualitte4cee1f2015-05-11 13:04:28 -070073};
74
75//////////////////////////////////////////////////////////////////////////////
76
halcanary385fe4d2015-08-26 13:07:48 -070077DEF_GM(return new TextBlobGeometryChange;)
John Stilesa6841be2020-08-06 14:11:56 -040078} // namespace skiagm