Flutter Engine
The Flutter Engine
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
textblobshader.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2014 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"
18#include "include/core/SkSize.h"
26#include "tools/ToolUtils.h"
28
29#include <math.h>
30#include <string.h>
31
32// This GM exercises drawTextBlob offset vs. shader space behavior.
34public:
36
37private:
38 void onOnceBeforeDraw() override {
39 {
41 const char* txt = "Blobber";
42 size_t txtLen = strlen(txt);
43 fGlyphs.append(font.countText(txt, txtLen, SkTextEncoding::kUTF8));
44 font.textToGlyphs(txt, txtLen, SkTextEncoding::kUTF8, fGlyphs.begin(), fGlyphs.size());
45 }
46
48 font.setSubpixel(true);
50 font.setSize(30);
51
53 int glyphCount = fGlyphs.size();
55
56 run = &builder.allocRun(font, glyphCount, 10, 10, nullptr);
57 memcpy(run->glyphs, fGlyphs.begin(), glyphCount * sizeof(uint16_t));
58
59 run = &builder.allocRunPosH(font, glyphCount, 80, nullptr);
60 memcpy(run->glyphs, fGlyphs.begin(), glyphCount * sizeof(uint16_t));
61 for (int i = 0; i < glyphCount; ++i) {
62 run->pos[i] = font.getSize() * i * .75f;
63 }
64
65 run = &builder.allocRunPos(font, glyphCount, nullptr);
66 memcpy(run->glyphs, fGlyphs.begin(), glyphCount * sizeof(uint16_t));
67 for (int i = 0; i < glyphCount; ++i) {
68 run->pos[i * 2] = font.getSize() * i * .75f;
69 run->pos[i * 2 + 1] = 150 + 5 * sinf((float)i * 8 / glyphCount);
70 }
71
72 fBlob = builder.make();
73
74 SkColor colors[2];
77
79 for (unsigned i = 0; i < std::size(pos); ++i) {
80 pos[i] = (float)i / (std::size(pos) - 1);
81 }
82
83 SkISize sz = this->getISize();
85 SkIntToScalar(sz.height() / 2)),
86 sz.width() * .66f, colors, pos,
89 }
90
91 SkString getName() const override { return SkString("textblobshader"); }
92
93 SkISize getISize() override { return SkISize::Make(640, 480); }
94
95 void onDraw(SkCanvas* canvas) override {
96 SkPaint p;
97 p.setAntiAlias(true);
98 p.setStyle(SkPaint::kFill_Style);
99 p.setShader(fShader);
100
101 SkISize sz = this->getISize();
102 constexpr int kXCount = 4;
103 constexpr int kYCount = 3;
104 for (int i = 0; i < kXCount; ++i) {
105 for (int j = 0; j < kYCount; ++j) {
106 canvas->drawTextBlob(fBlob,
107 SkIntToScalar(i * sz.width() / kXCount),
108 SkIntToScalar(j * sz.height() / kYCount),
109 p);
110 }
111 }
112 }
113
114 SkTDArray<uint16_t> fGlyphs;
115 sk_sp<SkTextBlob> fBlob;
116 sk_sp<SkShader> fShader;
117
118 using INHERITED = skiagm::GM;
119};
120
121DEF_GM(return new TextBlobShaderGM;)
SkPoint pos
uint32_t SkColor
Definition: SkColor.h:37
constexpr SkColor SK_ColorRED
Definition: SkColor.h:126
constexpr SkColor SK_ColorGREEN
Definition: SkColor.h:131
@ kUTF8
uses bytes to represent UTF-8 or ASCII
#define SkIntToScalar(x)
Definition: SkScalar.h:57
void drawTextBlob(const SkTextBlob *blob, SkScalar x, SkScalar y, const SkPaint &paint)
Definition: SkCanvas.cpp:2484
Definition: SkFont.h:35
@ kAntiAlias
may have transparent pixels on glyph edges
static sk_sp< SkShader > MakeRadial(const SkPoint &center, SkScalar radius, const SkColor colors[], const SkScalar pos[], int count, SkTileMode mode, uint32_t flags=0, const SkMatrix *localMatrix=nullptr)
@ kFill_Style
set to fill geometry
Definition: SkPaint.h:193
int size() const
Definition: SkTDArray.h:138
T * begin()
Definition: SkTDArray.h:150
T * append()
Definition: SkTDArray.h:191
Definition: gm.h:110
float SkScalar
Definition: extension.cpp:12
#define DEF_GM(CODE)
Definition: gm.h:40
PODArray< SkColor > colors
Definition: SkRecords.h:276
SkFont DefaultPortableFont()
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: run.py:1
def run(cmd)
Definition: run.py:14
Definition: SkSize.h:16
static constexpr SkISize Make(int32_t w, int32_t h)
Definition: SkSize.h:20
constexpr int32_t width() const
Definition: SkSize.h:36
constexpr int32_t height() const
Definition: SkSize.h:37
static constexpr SkPoint Make(float x, float y)
Definition: SkPoint_impl.h:173