Flutter Engine
The Flutter Engine
AtlasTextOpTools.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2024 Google LLC
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
9
10#include "include/core/SkFont.h"
17#include "src/text/GlyphRun.h"
20
21#if defined(GR_TEST_UTILS)
22#include "src/base/SkRandom.h"
24#endif
25
26namespace skgpu::ganesh {
27
29 const SkPaint& skPaint,
30 const SkFont& font,
31 const SkMatrix& ctm,
32 const char* text,
33 int x,
34 int y) {
35 size_t textLen = (int)strlen(text);
36
37 SkMatrix drawMatrix = ctm;
38 drawMatrix.preTranslate(x, y);
39 auto drawOrigin = SkPoint::Make(x, y);
41 auto glyphRunList = builder.textToGlyphRunList(font, skPaint, text, textLen, drawOrigin);
42 if (glyphRunList.empty()) {
43 return nullptr;
44 }
45
46 auto rContext = sdc->recordingContext();
48 rContext->priv().getSDFTControl(sdc->surfaceProps().isUseDeviceIndependentFonts());
49
50 SkStrikeDeviceInfo strikeDeviceInfo{
52
54 sktext::gpu::TextBlob::Make(glyphRunList,
55 skPaint,
56 drawMatrix,
57 strikeDeviceInfo,
59
61 if (!subRun) {
62 return nullptr;
63 }
64
65 GrOp::Owner op;
66 std::tie(std::ignore, op) =
67 subRun->makeAtlasTextOp(nullptr, ctm, glyphRunList.origin(), skPaint, blob, sdc);
68 return op;
69}
70
71} // namespace skgpu::ganesh
72
73#if defined(GR_TEST_UTILS)
74GR_DRAW_OP_TEST_DEFINE(AtlasTextOp) {
75 SkMatrix ctm = GrTest::TestMatrixInvertible(random);
76
77 SkPaint skPaint;
78 skPaint.setColor(random->nextU());
79
81 if (random->nextBool()) {
83 } else {
84 font.setEdging(random->nextBool() ? SkFont::Edging::kAntiAlias : SkFont::Edging::kAlias);
85 }
86 font.setSubpixel(random->nextBool());
87
88 const char* text = "The quick brown fox jumps over the lazy dog.";
89
90 // create some random x/y offsets, including negative offsets
91 static const int kMaxTrans = 1024;
92 int xPos = (random->nextU() % 2) * 2 - 1;
93 int yPos = (random->nextU() % 2) * 2 - 1;
94 int xInt = (random->nextU() % kMaxTrans) * xPos;
95 int yInt = (random->nextU() % kMaxTrans) * yPos;
96
97 return skgpu::ganesh::AtlasTextOpTools::CreateOp(sdc, skPaint, font, ctm, text, xInt, yInt);
98}
99#endif
std::unique_ptr< GrOp > Owner
Definition: GrOp.h:72
Definition: SkFont.h:35
@ kAntiAlias
may have transparent pixels on glyph edges
@ kAlias
no transparent pixels on glyph edges
@ kSubpixelAntiAlias
glyph positioned in pixel using transparency
SkMatrix & preTranslate(SkScalar dx, SkScalar dy)
Definition: SkMatrix.cpp:263
void setColor(SkColor color)
Definition: SkPaint.cpp:119
static SkStrikeCache * GlobalStrikeCache()
bool isUseDeviceIndependentFonts() const
T * get() const
Definition: SkRefCnt.h:303
static GrOp::Owner CreateOp(SurfaceDrawContext *, const SkPaint &, const SkFont &, const SkMatrix &, const char *text, int x, int y)
GrRecordingContext * recordingContext() const
const SkSurfaceProps & surfaceProps() const
static const AtlasSubRun * FirstSubRun(const TextBlob *)
static sk_sp< TextBlob > Make(const sktext::GlyphRunList &glyphRunList, const SkPaint &paint, const SkMatrix &positionMatrix, SkStrikeDeviceInfo strikeDeviceInfo, StrikeForGPUCacheInterface *strikeCache)
Definition: TextBlob.cpp:194
std::u16string text
double y
double x
font
Font Metadata and Metrics.
static constexpr SkPoint Make(float x, float y)
Definition: SkPoint_impl.h:173