Debian Codegraph @

gm/crbug_478659067.cpp

raw
1 /*
2 * Copyright 2026 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-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/SkColor.h"
11 #include "include/core/SkColorSpace.h"
12 #include "include/core/SkFont.h"
13 #include "include/core/SkFontStyle.h"
14 #include "include/core/SkFontTypes.h"
15 #include "include/core/SkImageInfo.h"
16 #include "include/core/SkMatrix.h"
17 #include "include/core/SkPaint.h"
18 #include "include/core/SkPoint.h"
19 #include "include/core/SkRect.h"
20 #include "include/core/SkRefCnt.h"
21 #include "include/core/SkScalar.h"
22 #include "include/core/SkSize.h"
23 #include "include/core/SkString.h"
24 #include "include/core/SkSurface.h"
25 #include "include/core/SkSurfaceProps.h"
26 #include "include/core/SkTextBlob.h"
27 #include "include/core/SkTypeface.h"
28 #include "include/core/SkTypes.h"
29 #include "include/gpu/GpuTypes.h"
30 #include "include/private/base/SkTemplates.h"
31 #include "include/private/base/SkTo.h"
32 #include "tools/ToolUtils.h"
33 #include "tools/fonts/FontToolUtils.h"
34
35 #if defined(SK_GRAPHITE)
36 #include "include/gpu/graphite/Recorder.h"
37 #include "include/gpu/graphite/Surface.h"
38 #include "src/gpu/graphite/RecorderPriv.h"
39 #endif
40
41 #include <string.h>
42
43 using namespace skia_private;
44
45 class CrBug478659067GM : public skiagm::GM {
46 public:
47 CrBug478659067GM() {
48 this->setBGColor(0xFFFFFFFF);
49 }
50
51 protected:
52 SkString getName() const override { return SkString("crbug_478659067"); }
53
54 SkISize getISize() override { return SkISize::Make(1024, 1280); }
55
56 void onDraw(SkCanvas* canvas) override {
57 SkISize size = this->getISize();
58 if (!canvas->getBaseLayerSize().isEmpty()) {
59 size = canvas->getBaseLayerSize();
60 }
61 SkImageInfo info = SkImageInfo::MakeN32(size.width(), size.height(), kPremul_SkAlphaType,
62 canvas->imageInfo().refColorSpace());
63 SkSurfaceProps inputProps;
64 canvas->getProps(&inputProps);
65 SkSurfaceProps props(SkSurfaceProps::kUseDeviceIndependentFonts_Flag | inputProps.flags(),
66 inputProps.pixelGeometry());
67 sk_sp<SkSurface> surface;
68
69 SkScalar dfSize = 162;
70 #if defined(SK_GRAPHITE)
71 if (auto recorder = canvas->recorder()) {
72 surface = SkSurfaces::RenderTarget(recorder, info, skgpu::Mipmapped::kNo, &props);
73 }
74 dfSize = canvas->recorder()->priv().caps()->glyphsAsPathsFontSize();
75 #endif
76 // Effectively make this test graphite only
77 if (!surface) {
78 return;
79 }
80
81 // Create a new canvas with the DeviceIndepdentFonts flag enabled
82 canvas = surface->getCanvas();
83 canvas->clear(0xffffffff);
84
85 const char* dfText = "TheQuickBrownFoxJumpsOverTheLazyDog_0123456789";
86 const size_t dfLen = strlen(dfText);
87
88 SkScalar scale = canvas->getLocalToDeviceAs3x3().getMaxScale();
89 if (scale <= 0.0f) {
90 scale = 1.0f;
91 }
92
93 SkFont font(ToolUtils::CreatePortableTypeface("serif", SkFontStyle()));
94 font.setSize((dfSize - 64) / scale);
95 font.setEdging(SkFont::Edging::kSubpixelAntiAlias);
96 font.setSubpixel(true);
97
98 SkPaint paint;
99 paint.setColor(SK_ColorBLACK);
100
101 SkScalar lineSpacing = font.getSize();
102 for (int i = 1; i <= 6; ++i) {
103 SkAutoCanvasRestore acr(canvas, true);
104 canvas->translate(SkIntToScalar(10), (i * lineSpacing) - 10);
105 // We skew the font in order to prevent glyph reuse. This is needed to overflow the
106 // cache page
107 font.setSkewX(i * 0.05f);
108 canvas->drawSimpleText(dfText, dfLen, SkTextEncoding::kUTF8, 0, 0, font, paint);
109 }
110 }
111 };
112
113 DEF_GM(return new CrBug478659067GM;)