Flutter Engine
The Flutter Engine
gammatext.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2011 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"
11#include "include/core/SkFont.h"
15#include "include/core/SkRect.h"
19#include "include/core/SkSize.h"
26
28 const SkColor bw[] = { SK_ColorBLACK, SK_ColorWHITE };
29
30 return SkGradientShader::MakeLinear(pts, bw, nullptr, std::size(bw), SkTileMode::kClamp);
31}
32
33/**
34 Test a set of clipping problems discovered while writing blitAntiRect,
35 and test all the code paths through the clipping blitters.
36 Each region should show as a blue center surrounded by a 2px green
37 border, with no red.
38*/
39
40#define HEIGHT 480
41
42class GammaTextGM : public skiagm::GM {
43protected:
44 SkString getName() const override { return SkString("gammatext"); }
45
46 SkISize getISize() override { return SkISize::Make(1024, HEIGHT); }
47
48 static void drawGrad(SkCanvas* canvas) {
49 const SkPoint pts[] = { { 0, 0 }, { 0, SkIntToScalar(HEIGHT) } };
50
51 canvas->clear(SK_ColorRED);
53 paint.setShader(make_heatGradient(pts));
54 SkRect r = { 0, 0, SkIntToScalar(1024), SkIntToScalar(HEIGHT) };
55 canvas->drawRect(r, paint);
56 }
57
58 void onDraw(SkCanvas* canvas) override {
59 drawGrad(canvas);
60
61 const SkColor fg[] = {
62 0xFFFFFFFF,
63 0xFFFFFF00, 0xFFFF00FF, 0xFF00FFFF,
64 0xFFFF0000, 0xFF00FF00, 0xFF0000FF,
65 0xFF000000,
66 };
67
68 const char* text = "Hamburgefons";
69
72 font.setSize(16);
74
76 for (size_t i = 0; i < std::size(fg); ++i) {
77 paint.setColor(fg[i]);
78
81 while (y < stopy) {
82 canvas->drawString(text, x, y, font, paint);
83 y += font.getSize() * 2;
84 }
85 x += SkIntToScalar(1024) / std::size(fg);
86 }
87 }
88
89private:
90 using INHERITED = skiagm::GM;
91};
92
93DEF_GM( return new GammaTextGM; )
94
95//////////////////////////////////////////////////////////////////////////////
96
98 const SkPoint pts[] = { { 0, 0 }, { 240, 0 } };
99 SkColor colors[2];
100 colors[0] = c;
101 colors[1] = SkColorSetA(c, 0);
103}
104
105static void draw_pair(SkCanvas* canvas, const SkFont& font, SkColor color,
106 const sk_sp<SkShader>& shader) {
107 static const char text[] = "Now is the time for all good";
109 paint.setColor(color);
110 canvas->drawString(text, 10, 20, font, paint);
111 paint.setShader(SkShaders::Color(paint.getColor()));
112 canvas->drawString(text, 10, 40, font, paint);
113 paint.setShader(shader);
114 canvas->drawString(text, 10, 60, font, paint);
115}
116
118 sk_sp<SkShader> fShaders[3];
119 SkColor fColors[3];
120
121public:
124 for (size_t i = 0; i < std::size(fShaders); ++i) {
125 fColors[i] = colors[i];
126 }
127 }
128
129protected:
130 SkString getName() const override { return SkString("gammagradienttext"); }
131
132 SkISize getISize() override { return SkISize::Make(300, 300); }
133
134 void onOnceBeforeDraw() override {
135 for (size_t i = 0; i < std::size(fShaders); ++i) {
136 fShaders[i] = make_gradient(fColors[i]);
137 }
138 }
139
140 void onDraw(SkCanvas* canvas) override {
142 paint.setAntiAlias(true);
144 SkASSERT(tf);
145 SkFont font(tf, 18);
147
148 for (size_t i = 0; i < std::size(fShaders); ++i) {
149 draw_pair(canvas, font, fColors[i], fShaders[i]);
150 canvas->translate(0, 80);
151 }
152 }
153
154private:
155 using INHERITED = skiagm::GM;
156};
157
158DEF_GM( return new GammaShaderTextGM; )
159
160DEF_SIMPLE_GM_BG(gammatext_color_shader, canvas, 300, 275, SK_ColorGRAY) {
161 const char* kText = "ABCDEFG";
163 SkASSERT(tf);
164 SkFont font(tf, 18);
166
167 canvas->translate(10, 30);
168 for (int i = 0; i < 256; i += 20) {
171 paint.setColor(color);
172 canvas->drawString(kText, 0, 0, font, paint);
173 paint.setShader(SkShaders::Color(color));
174 canvas->drawString(kText, 100, 0, font, paint);
175 paint.setShader(SkShaders::Color(SkColor4f::FromColor(color), SkColorSpace::MakeSRGB()));
176 canvas->drawString(kText, 200, 0, font, paint);
177 canvas->translate(0, 20);
178 }
179}
#define SkASSERT(cond)
Definition: SkAssert.h:116
uint32_t SkColor
Definition: SkColor.h:37
#define SkColorSetRGB(r, g, b)
Definition: SkColor.h:57
constexpr SkColor SK_ColorGRAY
Definition: SkColor.h:113
constexpr SkColor SK_ColorBLUE
Definition: SkColor.h:135
static constexpr SkColor SkColorSetA(SkColor c, U8CPU a)
Definition: SkColor.h:82
constexpr SkColor SK_ColorRED
Definition: SkColor.h:126
constexpr SkColor SK_ColorBLACK
Definition: SkColor.h:103
constexpr SkColor SK_ColorWHITE
Definition: SkColor.h:122
#define SkIntToScalar(x)
Definition: SkScalar.h:57
SkString getName() const override
Definition: gammatext.cpp:130
void onOnceBeforeDraw() override
Definition: gammatext.cpp:134
SkISize getISize() override
Definition: gammatext.cpp:132
void onDraw(SkCanvas *canvas) override
Definition: gammatext.cpp:140
void onDraw(SkCanvas *canvas) override
Definition: gammatext.cpp:58
static void drawGrad(SkCanvas *canvas)
Definition: gammatext.cpp:48
SkISize getISize() override
Definition: gammatext.cpp:46
SkString getName() const override
Definition: gammatext.cpp:44
void drawRect(const SkRect &rect, const SkPaint &paint)
Definition: SkCanvas.cpp:1673
void translate(SkScalar dx, SkScalar dy)
Definition: SkCanvas.cpp:1278
void clear(SkColor color)
Definition: SkCanvas.h:1199
void drawString(const char str[], SkScalar x, SkScalar y, const SkFont &font, const SkPaint &paint)
Definition: SkCanvas.h:1803
static sk_sp< SkColorSpace > MakeSRGB()
static constexpr SkFontStyle Italic()
Definition: SkFontStyle.h:72
Definition: SkFont.h:35
@ kSubpixelAntiAlias
glyph positioned in pixel using transparency
static sk_sp< SkShader > MakeLinear(const SkPoint pts[2], const SkColor colors[], const SkScalar pos[], int count, SkTileMode mode, uint32_t flags=0, const SkMatrix *localMatrix=nullptr)
Definition: gm.h:110
const Paint & paint
Definition: color_source.cc:38
DlColor color
float SkScalar
Definition: extension.cpp:12
static sk_sp< SkShader > make_gradient(SkColor c)
Definition: gammatext.cpp:97
static sk_sp< SkShader > make_heatGradient(const SkPoint pts[2])
Definition: gammatext.cpp:27
static void draw_pair(SkCanvas *canvas, const SkFont &font, SkColor color, const sk_sp< SkShader > &shader)
Definition: gammatext.cpp:105
DEF_SIMPLE_GM_BG(gammatext_color_shader, canvas, 300, 275, SK_ColorGRAY)
Definition: gammatext.cpp:160
#define HEIGHT
Definition: gammatext.cpp:40
constexpr char kText[]
Definition: glyph_pos.cpp:28
#define DEF_GM(CODE)
Definition: gm.h:40
std::u16string text
double y
double x
PODArray< SkColor > colors
Definition: SkRecords.h:276
SK_API sk_sp< SkShader > Color(SkColor)
SkFont DefaultPortableFont()
sk_sp< SkTypeface > CreatePortableTypeface(const char *name, SkFontStyle style)
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259
font
Font Metadata and Metrics.
Definition: SkSize.h:16
static constexpr SkISize Make(int32_t w, int32_t h)
Definition: SkSize.h:20