Flutter Engine
The Flutter Engine
textblobcolortrans.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2015 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"
14#include "include/core/SkRect.h"
17#include "include/core/SkSize.h"
22#include "tools/ToolUtils.h"
24
25#include <string.h>
26
27namespace skiagm {
28class TextBlobColorTrans : public GM {
29public:
30 // This gm tests that textblobs can be translated and have their colors regenerated
31 // correctly. With smaller atlas sizes, it can also trigger regeneration of texture coords on
32 // the GPU backend
34
35protected:
36 void onOnceBeforeDraw() override {
38
39 // make textblob
40 // Large text is used to trigger atlas eviction
43 const char* text = "AB";
44
46 font.measureText(text, strlen(text), SkTextEncoding::kUTF8, &bounds);
47
48 SkScalar yOffset = bounds.height();
49 ToolUtils::add_to_text_blob(&builder, text, font, 0, yOffset - 30);
50
51 // A8
52 font.setSize(28);
53 text = "The quick brown fox jumps over the lazy dog.";
54 font.measureText(text, strlen(text), SkTextEncoding::kUTF8, &bounds);
55 ToolUtils::add_to_text_blob(&builder, text, font, 0, yOffset - 8);
56
57 // build
58 fBlob = builder.make();
59 }
60
61 SkString getName() const override { return SkString("textblobcolortrans"); }
62
63 SkISize getISize() override { return SkISize::Make(kWidth, kHeight); }
64
65 void onDraw(SkCanvas* canvas) override {
66
67 canvas->drawColor(SK_ColorGRAY);
68
70 canvas->translate(10, 40);
71
72 SkRect bounds = fBlob->bounds();
73
74 // Colors were chosen to map to pairs of canonical colors. The GPU Backend will cache A8
75 // Texture Blobs based on the canonical color they map to. Canonical colors are used to
76 // create masks. For A8 there are 8 of them.
78
79 size_t count = std::size(colors);
80 size_t colorIndex = 0;
81 for (int y = 0; y + SkScalarFloorToInt(bounds.height()) < kHeight;
82 y += SkScalarFloorToInt(bounds.height())) {
83 paint.setColor(colors[colorIndex++ % count]);
84 canvas->save();
85 canvas->translate(0, SkIntToScalar(y));
86 canvas->drawTextBlob(fBlob, 0, 0, paint);
87 canvas->restore();
88 }
89 }
90
91private:
93
94 inline static constexpr int kWidth = 675;
95 inline static constexpr int kHeight = 1600;
96
97 using INHERITED = GM;
98};
99
100//////////////////////////////////////////////////////////////////////////////
101
102DEF_GM(return new TextBlobColorTrans;)
103} // namespace skiagm
int count
Definition: FontMgrTest.cpp:50
constexpr SkColor SK_ColorYELLOW
Definition: SkColor.h:139
constexpr SkColor SK_ColorLTGRAY
Definition: SkColor.h:118
uint32_t SkColor
Definition: SkColor.h:37
constexpr SkColor SK_ColorCYAN
Definition: SkColor.h:143
constexpr SkColor SK_ColorGRAY
Definition: SkColor.h:113
constexpr SkColor SK_ColorWHITE
Definition: SkColor.h:122
@ kUTF8
uses bytes to represent UTF-8 or ASCII
#define SkIntToScalar(x)
Definition: SkScalar.h:57
#define SkScalarFloorToInt(x)
Definition: SkScalar.h:35
void restore()
Definition: SkCanvas.cpp:461
void translate(SkScalar dx, SkScalar dy)
Definition: SkCanvas.cpp:1278
void drawColor(SkColor color, SkBlendMode mode=SkBlendMode::kSrcOver)
Definition: SkCanvas.h:1182
int save()
Definition: SkCanvas.cpp:447
void drawTextBlob(const SkTextBlob *blob, SkScalar x, SkScalar y, const SkPaint &paint)
Definition: SkCanvas.cpp:2484
Definition: SkFont.h:35
@ kAlias
no transparent pixels on glyph edges
const SkRect & bounds() const
Definition: SkTextBlob.h:53
Definition: gm.h:110
GM(SkColor backgroundColor=SK_ColorWHITE)
Definition: gm.cpp:81
void onDraw(SkCanvas *canvas) override
SkString getName() const override
const Paint & paint
Definition: color_source.cc:38
float SkScalar
Definition: extension.cpp:12
std::u16string text
double y
Optional< SkRect > bounds
Definition: SkRecords.h:189
PODArray< SkColor > colors
Definition: SkRecords.h:276
sk_sp< SkTypeface > DefaultPortableTypeface()
void add_to_text_blob(SkTextBlobBuilder *builder, const char *text, const SkFont &font, SkScalar x, SkScalar y)
Definition: ToolUtils.cpp:228
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.
DEF_GM(return F(C(clipbox), 0.0f, 0.0f, {})) DEF_GM(return F(C(clipbox)
Definition: SkSize.h:16
static constexpr SkISize Make(int32_t w, int32_t h)
Definition: SkSize.h:20