Flutter Engine
The Flutter Engine
skbug_257.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"
12#include "include/core/SkFont.h"
18#include "include/core/SkRect.h"
24#include "tools/ToolUtils.h"
26
27#include <string.h>
28
30 SkColor c1,
31 SkColor c2,
32 int size) {
33 SkBitmap bm;
34 bm.allocN32Pixels(2 * size, 2 * size);
35 bm.eraseColor(c1);
36 bm.eraseArea(SkIRect::MakeLTRB(0, 0, size, size), c2);
37 bm.eraseArea(SkIRect::MakeLTRB(size, size, 2 * size, 2 * size), c2);
39 matrix.setScale(0.75f, 0.75f);
40 matrix.preRotate(30.0f);
43}
44
45static void exercise_draw_pos_text(SkCanvas* canvas,
46 const char* text,
48 const SkFont& font, const SkPaint& paint) {
49 const int count = font.countText(text, strlen(text), SkTextEncoding::kUTF8);
51 auto rec = builder.allocRunPos(font, count);
52 font.textToGlyphs(text, strlen(text), SkTextEncoding::kUTF8, rec.glyphs, count);
53 font.getPos(rec.glyphs, count, rec.points(), {x, y});
54 canvas->drawTextBlob(builder.make(), 0, 0, paint);
55}
56
58 const char* text,
60 const SkFont& font, const SkPaint& paint) {
61 const int count = font.countText(text, strlen(text), SkTextEncoding::kUTF8);
63 auto rec = builder.allocRunPosH(font, count, 0);
64 font.textToGlyphs(text, strlen(text), SkTextEncoding::kUTF8, rec.glyphs, count);
65 font.getXPos(rec.glyphs, count, rec.pos);
66 canvas->drawTextBlob(builder.make(), x, y, paint);
67}
68
69static void test_text(SkCanvas* canvas, SkScalar size,
74 type.setColor(color);
75 const char text[] = "HELLO WORLD";
76 canvas->drawSimpleText(text, strlen(text), SkTextEncoding::kUTF8, 32, size / 2 + Y,
77 font, type);
78 SkScalar lineSpacing = font.getSpacing();
79 exercise_draw_pos_text(canvas, text, 32, size / 2 + Y + lineSpacing, font, type);
81 size / 2 + Y + 2 * lineSpacing, font, type);
82}
83
84// If this GM works correctly, the cyan layer should be lined up with
85// the objects below it.
86DEF_SIMPLE_GM(skbug_257, canvas, 512, 512) {
87 const SkScalar size = 256;
88 SkAutoCanvasRestore autoCanvasRestore0(canvas, true);
89 const SkScalar scale = 1.00168f;
90 canvas->scale(scale, scale);
91 {
92 SkPaint checker;
94 checker.setAntiAlias(true);
95
96 SkAutoCanvasRestore autoCanvasRestore(canvas, true);
97 canvas->clear(0xFFCECFCE);
98 SkScalar translate = 225364.0f;
99 canvas->translate(0, -translate);
100
101 // Test rects
102 SkRect rect = SkRect::MakeLTRB(8, 8 + translate, size - 8,
103 size - 8 + translate);
104 canvas->drawRect(rect, checker);
105
106 // Test Paths
107 canvas->translate(size, 0);
109 SkVector radii[4] = {{40, 40}, {40, 40}, {40, 40}, {40, 40}};
110 rrect.setRectRadii(rect, radii);
111 canvas->drawRRect(rrect, checker);
112
113 // Test Points
114 canvas->translate(-size, size);
115 SkScalar delta = 1.0 / 64.0;
116 SkPoint points[8] = {{size / 2, 8 + translate},
117 {size / 2, 8 + translate + delta},
118 {8, size / 2 + translate},
119 {8, size / 2 + translate + delta},
120 {size / 2, size - 8 + translate},
121 {size / 2, size - 8 + translate + delta},
122 {size - 8, size / 2 + translate},
123 {size - 8, size / 2 + translate + delta}};
125 checker.setStrokeWidth(8);
127 canvas->drawPoints(SkCanvas::kLines_PointMode, 8, points, checker);
128
129 // Test Text
130 canvas->translate(size, 0);
131 test_text(canvas, size, SK_ColorBLACK, translate);
132 }
133 // reference points (without the huge translations).
136 stroke.setStrokeWidth(5);
137 stroke.setColor(SK_ColorCYAN);
138 canvas->drawCircle(size / 2, size / 2, size / 2 - 10, stroke);
139 canvas->drawCircle(3 * size / 2, size / 2, size / 2 - 10, stroke);
140 canvas->drawCircle(size / 2, 384, size / 2 - 10, stroke);
141 canvas->translate(size, size);
142 test_text(canvas, size, SK_ColorCYAN, 0.0f);
143}
int count
Definition: FontMgrTest.cpp:50
static const int points[]
uint32_t SkColor
Definition: SkColor.h:37
constexpr SkColor SK_ColorCYAN
Definition: SkColor.h:143
constexpr SkColor SK_ColorBLACK
Definition: SkColor.h:103
constexpr SkColor SK_ColorWHITE
Definition: SkColor.h:122
@ kUTF8
uses bytes to represent UTF-8 or ASCII
static const SkScalar Y
Definition: StrokeBench.cpp:55
GLenum type
void eraseArea(const SkIRect &area, SkColor c) const
Definition: SkBitmap.h:854
sk_sp< SkShader > makeShader(SkTileMode tmx, SkTileMode tmy, const SkSamplingOptions &, const SkMatrix *localMatrix=nullptr) const
Definition: SkBitmap.cpp:669
void allocN32Pixels(int width, int height, bool isOpaque=false)
Definition: SkBitmap.cpp:232
void eraseColor(SkColor4f) const
Definition: SkBitmap.cpp:442
void drawSimpleText(const void *text, size_t byteLength, SkTextEncoding encoding, SkScalar x, SkScalar y, const SkFont &font, const SkPaint &paint)
Definition: SkCanvas.cpp:2413
@ kLines_PointMode
draw each pair of points as a line segment
Definition: SkCanvas.h:1242
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
@ kRound_Cap
adds circle
Definition: SkPaint.h:335
void setStyle(Style style)
Definition: SkPaint.cpp:105
void setAntiAlias(bool aa)
Definition: SkPaint.h:170
void setStrokeCap(Cap cap)
Definition: SkPaint.cpp:179
@ kStroke_Style
set to stroke geometry
Definition: SkPaint.h:194
void setStrokeWidth(SkScalar width)
Definition: SkPaint.cpp:159
void setRectRadii(const SkRect &rect, const SkVector radii[4])
Definition: SkRRect.cpp:189
const Paint & paint
Definition: color_source.cc:38
DlColor color
float SkScalar
Definition: extension.cpp:12
std::u16string text
double y
double x
unsigned useCenter Optional< SkMatrix > matrix
Definition: SkRecords.h:258
SkRRect rrect
Definition: SkRecords.h:232
sk_sp< SkBlender > blender SkRect rect
Definition: SkRecords.h:350
sk_sp< SkTypeface > DefaultPortableTypeface()
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_SIMPLE_GM(skbug_257, canvas, 512, 512)
Definition: skbug_257.cpp:86
static void rotated_checkerboard_shader(SkPaint *paint, SkColor c1, SkColor c2, int size)
Definition: skbug_257.cpp:29
static void test_text(SkCanvas *canvas, SkScalar size, SkColor color, SkScalar Y)
Definition: skbug_257.cpp:69
static void exercise_draw_pos_text_h(SkCanvas *canvas, const char *text, SkScalar x, SkScalar y, const SkFont &font, const SkPaint &paint)
Definition: skbug_257.cpp:57
static void exercise_draw_pos_text(SkCanvas *canvas, const char *text, SkScalar x, SkScalar y, const SkFont &font, const SkPaint &paint)
Definition: skbug_257.cpp:45
const Scalar scale
static constexpr SkIRect MakeLTRB(int32_t l, int32_t t, int32_t r, int32_t b)
Definition: SkRect.h:91
static constexpr SkRect MakeLTRB(float l, float t, float r, float b)
Definition: SkRect.h:646