Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Functions
skbug_257.cpp File Reference
#include "gm/gm.h"
#include "include/core/SkBitmap.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkColor.h"
#include "include/core/SkFont.h"
#include "include/core/SkFontTypes.h"
#include "include/core/SkMatrix.h"
#include "include/core/SkPaint.h"
#include "include/core/SkPoint.h"
#include "include/core/SkRRect.h"
#include "include/core/SkRect.h"
#include "include/core/SkScalar.h"
#include "include/core/SkShader.h"
#include "include/core/SkTextBlob.h"
#include "include/core/SkTileMode.h"
#include "include/core/SkTypeface.h"
#include "tools/ToolUtils.h"
#include "tools/fonts/FontToolUtils.h"
#include <string.h>

Go to the source code of this file.

Functions

static void rotated_checkerboard_shader (SkPaint *paint, SkColor c1, SkColor c2, int size)
 
static void exercise_draw_pos_text (SkCanvas *canvas, const char *text, SkScalar x, SkScalar y, const SkFont &font, const SkPaint &paint)
 
static void exercise_draw_pos_text_h (SkCanvas *canvas, const char *text, SkScalar x, SkScalar y, const SkFont &font, const SkPaint &paint)
 
static void test_text (SkCanvas *canvas, SkScalar size, SkColor color, SkScalar Y)
 
 DEF_SIMPLE_GM (skbug_257, canvas, 512, 512)
 

Function Documentation

◆ DEF_SIMPLE_GM()

DEF_SIMPLE_GM ( skbug_257  ,
canvas  ,
512  ,
512   
)

Definition at line 86 of file skbug_257.cpp.

86 {
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).
134 SkPaint stroke;
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}
static const int points[]
constexpr SkColor SK_ColorCYAN
Definition SkColor.h:143
constexpr SkColor SK_ColorBLACK
Definition SkColor.h:103
constexpr SkColor SK_ColorWHITE
Definition SkColor.h:122
@ kLines_PointMode
draw each pair of points as a line segment
Definition SkCanvas.h:1242
@ kRound_Cap
adds circle
Definition SkPaint.h:335
void setStyle(Style style)
Definition SkPaint.cpp:105
void setColor(SkColor color)
Definition SkPaint.cpp:119
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
float SkScalar
Definition extension.cpp:12
SkRRect rrect
Definition SkRecords.h:232
sk_sp< SkBlender > blender SkRect rect
Definition SkRecords.h:350
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
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
const Scalar scale
static constexpr SkRect MakeLTRB(float l, float t, float r, float b)
Definition SkRect.h:646

◆ exercise_draw_pos_text()

static void exercise_draw_pos_text ( SkCanvas canvas,
const char *  text,
SkScalar  x,
SkScalar  y,
const SkFont font,
const SkPaint paint 
)
static

Definition at line 45 of file skbug_257.cpp.

48 {
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}
int count
@ kUTF8
uses bytes to represent UTF-8 or ASCII
void drawTextBlob(const SkTextBlob *blob, SkScalar x, SkScalar y, const SkPaint &paint)
const Paint & paint
std::u16string text
font
Font Metadata and Metrics.

◆ exercise_draw_pos_text_h()

static void exercise_draw_pos_text_h ( SkCanvas canvas,
const char *  text,
SkScalar  x,
SkScalar  y,
const SkFont font,
const SkPaint paint 
)
static

Definition at line 57 of file skbug_257.cpp.

60 {
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}
double y
double x

◆ rotated_checkerboard_shader()

static void rotated_checkerboard_shader ( SkPaint paint,
SkColor  c1,
SkColor  c2,
int  size 
)
static

Definition at line 29 of file skbug_257.cpp.

32 {
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);
42 SkSamplingOptions(), matrix));
43}
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
unsigned useCenter Optional< SkMatrix > matrix
Definition SkRecords.h:258
static constexpr SkIRect MakeLTRB(int32_t l, int32_t t, int32_t r, int32_t b)
Definition SkRect.h:91

◆ test_text()

static void test_text ( SkCanvas canvas,
SkScalar  size,
SkColor  color,
SkScalar  Y 
)
static

Definition at line 69 of file skbug_257.cpp.

70 {
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}
SkColor4f color
static const SkScalar Y
void drawSimpleText(const void *text, size_t byteLength, SkTextEncoding encoding, SkScalar x, SkScalar y, const SkFont &font, const SkPaint &paint)
@ kAlias
no transparent pixels on glyph edges
sk_sp< SkTypeface > DefaultPortableTypeface()
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