Flutter Engine
The Flutter Engine
Functions | Variables
path_stroke_with_zero_length.cpp File Reference
#include "gm/gm.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkColor.h"
#include "include/core/SkColorPriv.h"
#include "include/core/SkImage.h"
#include "include/core/SkImageInfo.h"
#include "include/core/SkPaint.h"
#include "include/core/SkPath.h"
#include "include/core/SkRect.h"
#include "include/core/SkRefCnt.h"
#include "include/core/SkScalar.h"
#include "include/core/SkString.h"
#include "include/core/SkSurface.h"
#include "include/core/SkTypes.h"
#include "include/gpu/GrDirectContext.h"
#include "include/utils/SkParsePath.h"
#include "src/core/SkAutoPixmapStorage.h"

Go to the source code of this file.

Functions

static void draw_path_cell (SkCanvas *canvas, SkSurface *surface, int expectedCaps)
 
static skiagm::DrawResult draw_zero_length_capped_paths (SkCanvas *canvas, bool aa, SkString *errorMsg)
 
 DEF_SIMPLE_GM_BG_CAN_FAIL (zero_length_paths_aa, canvas, errorMsg, kTotalWidth, kTotalHeight, SK_ColorBLACK)
 
 DEF_SIMPLE_GM_BG_CAN_FAIL (zero_length_paths_bw, canvas, errorMsg, kTotalWidth, kTotalHeight, SK_ColorBLACK)
 
static skiagm::DrawResult draw_zero_length_capped_paths_dbl_contour (SkCanvas *canvas, bool aa, SkString *errorMsg)
 
 DEF_SIMPLE_GM_BG_CAN_FAIL (zero_length_paths_dbl_aa, canvas, errorMsg, kDblContourTotalWidth, kTotalHeight, SK_ColorBLACK)
 
 DEF_SIMPLE_GM_BG_CAN_FAIL (zero_length_paths_dbl_bw, canvas, errorMsg, kDblContourTotalWidth, kTotalHeight, SK_ColorBLACK)
 

Variables

static const SkPaint::Cap kCaps []
 
static const SkScalar kWidths [] = { 0.0f, 0.9f, 1.0f, 1.1f, 15.0f, 25.0f }
 
static const char * kAllVerbs []
 
static const char * kSomeVerbs []
 
static const int kCellWidth = 50
 
static const int kCellHeight = 20
 
static const int kCellPad = 2
 
static const int kNumRows = std::size(kCaps) * std::size(kWidths)
 
static const int kNumColumns = std::size(kAllVerbs)
 
static const int kTotalWidth = kNumColumns * (kCellWidth + kCellPad) + kCellPad
 
static const int kTotalHeight = kNumRows * (kCellHeight + kCellPad) + kCellPad
 
static const int kDblContourNumColums = std::size(kSomeVerbs) * std::size(kSomeVerbs)
 
static const int kDblContourTotalWidth = kDblContourNumColums * (kCellWidth + kCellPad) + kCellPad
 

Function Documentation

◆ DEF_SIMPLE_GM_BG_CAN_FAIL() [1/4]

DEF_SIMPLE_GM_BG_CAN_FAIL ( zero_length_paths_aa  ,
canvas  ,
errorMsg  ,
kTotalWidth  ,
kTotalHeight  ,
SK_ColorBLACK   
)

Definition at line 180 of file path_stroke_with_zero_length.cpp.

181 {
182 return draw_zero_length_capped_paths(canvas, true, errorMsg);
183}
static skiagm::DrawResult draw_zero_length_capped_paths(SkCanvas *canvas, bool aa, SkString *errorMsg)

◆ DEF_SIMPLE_GM_BG_CAN_FAIL() [2/4]

DEF_SIMPLE_GM_BG_CAN_FAIL ( zero_length_paths_bw  ,
canvas  ,
errorMsg  ,
kTotalWidth  ,
kTotalHeight  ,
SK_ColorBLACK   
)

Definition at line 185 of file path_stroke_with_zero_length.cpp.

186 {
187 return draw_zero_length_capped_paths(canvas, false, errorMsg);
188}

◆ DEF_SIMPLE_GM_BG_CAN_FAIL() [3/4]

DEF_SIMPLE_GM_BG_CAN_FAIL ( zero_length_paths_dbl_aa  ,
canvas  ,
errorMsg  ,
kDblContourTotalWidth  ,
kTotalHeight  ,
SK_ColorBLACK   
)

Definition at line 256 of file path_stroke_with_zero_length.cpp.

257 {
258 return draw_zero_length_capped_paths_dbl_contour(canvas, true, errorMsg);
259}
static skiagm::DrawResult draw_zero_length_capped_paths_dbl_contour(SkCanvas *canvas, bool aa, SkString *errorMsg)

◆ DEF_SIMPLE_GM_BG_CAN_FAIL() [4/4]

DEF_SIMPLE_GM_BG_CAN_FAIL ( zero_length_paths_dbl_bw  ,
canvas  ,
errorMsg  ,
kDblContourTotalWidth  ,
kTotalHeight  ,
SK_ColorBLACK   
)

Definition at line 261 of file path_stroke_with_zero_length.cpp.

262 {
263 return draw_zero_length_capped_paths_dbl_contour(canvas, false, errorMsg);
264}

◆ draw_path_cell()

static void draw_path_cell ( SkCanvas canvas,
SkSurface surface,
int  expectedCaps 
)
static

Definition at line 38 of file path_stroke_with_zero_length.cpp.

40 {
41 static const SkColor kFailureRed = 0x7F7F0000;
42 static const SkColor kFailureYellow = 0x7F7F7F00;
43 static const SkColor kSuccessGreen = 0x7F007f00;
44
45 int w = surface->width(), h = surface->height();
46
47 // Read the pixels back
50 pmap.alloc(info);
51 if (!surface->readPixels(pmap, 0, 0)) {
52 return;
53 }
54
55 // To account for rasterization differences, we scan the middle two rows [y, y+1] of the image
56 SkASSERT(h % 2 == 0);
57 int y = (h - 1) / 2;
58
59 bool inBlob = false;
60 int numBlobs = 0;
61 for (int x = 0; x < w; ++x) {
62 // We drew white-on-black. We can look for any non-zero value. Just check red.
63 // And we care if either row is non-zero, so just add them to simplify everything.
64 uint32_t v = SkGetPackedR32(*pmap.addr32(x, y)) + SkGetPackedR32(*pmap.addr32(x, y + 1));
65
66 if (!inBlob && v) {
67 ++numBlobs;
68 }
69 inBlob = SkToBool(v);
70 }
71
73
74 if (numBlobs == expectedCaps) {
75 result.setColor(kSuccessGreen); // Green
76 } else if (numBlobs > expectedCaps) {
77 result.setColor(kFailureYellow); // Yellow -- more geometry than expected
78 } else {
79 result.setColor(kFailureRed); // Red -- missing some geometry
80 }
81
82 auto img = surface->makeImageSnapshot();
83 canvas->drawImage(img, 0, 0);
84 canvas->drawRect(SkRect::MakeWH(w, h), result);
85}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
#define SkASSERT(cond)
Definition: SkAssert.h:116
#define SkGetPackedR32(packed)
Definition: SkColorPriv.h:93
uint32_t SkColor
Definition: SkColor.h:37
static constexpr bool SkToBool(const T &x)
Definition: SkTo.h:35
void alloc(const SkImageInfo &)
void drawRect(const SkRect &rect, const SkPaint &paint)
Definition: SkCanvas.cpp:1673
void drawImage(const SkImage *image, SkScalar left, SkScalar top)
Definition: SkCanvas.h:1528
const uint32_t * addr32() const
Definition: SkPixmap.h:352
VkSurfaceKHR surface
Definition: main.cc:49
GAsyncResult * result
double y
double x
SkScalar w
SkScalar h
static SkImageInfo MakeN32Premul(int width, int height)
static constexpr SkRect MakeWH(float w, float h)
Definition: SkRect.h:609

◆ draw_zero_length_capped_paths()

static skiagm::DrawResult draw_zero_length_capped_paths ( SkCanvas canvas,
bool  aa,
SkString errorMsg 
)
static

Definition at line 131 of file path_stroke_with_zero_length.cpp.

132 {
133 canvas->translate(kCellPad, kCellPad);
134
136 auto surface = canvas->makeSurface(info);
137 if (!surface) {
139 }
140
142 paint.setColor(SK_ColorWHITE);
143 paint.setAntiAlias(aa);
145
146 for (auto cap : kCaps) {
147 for (auto width : kWidths) {
148 paint.setStrokeCap(cap);
149 paint.setStrokeWidth(width);
150 canvas->save();
151
152 for (auto verb : kAllVerbs) {
153 SkString pathStr;
154 pathStr.appendf("M %f %f ", (kCellWidth - 1) * 0.5f, (kCellHeight - 1) * 0.5f);
155 if (verb) {
156 pathStr.append(verb);
157 }
158
159 SkPath path;
161
162 surface->getCanvas()->clear(SK_ColorTRANSPARENT);
163 surface->getCanvas()->drawPath(path, paint);
164
165 // All cases should draw one cap, except for butt capped, and dangling moves
166 // (without a verb or close), which shouldn't draw anything.
167 int expectedCaps = ((SkPaint::kButt_Cap == cap) || !verb) ? 0 : 1;
168
169 draw_path_cell(canvas, surface.get(), expectedCaps);
170 canvas->translate(kCellWidth + kCellPad, 0);
171 }
172 canvas->restore();
173 canvas->translate(0, kCellHeight + kCellPad);
174 }
175 }
176
178}
constexpr SkColor SK_ColorTRANSPARENT
Definition: SkColor.h:99
constexpr SkColor SK_ColorWHITE
Definition: SkColor.h:122
void restore()
Definition: SkCanvas.cpp:461
void translate(SkScalar dx, SkScalar dy)
Definition: SkCanvas.cpp:1278
sk_sp< SkSurface > makeSurface(const SkImageInfo &info, const SkSurfaceProps *props=nullptr)
Definition: SkCanvas.cpp:1195
int save()
Definition: SkCanvas.cpp:447
SkImageInfo imageInfo() const
Definition: SkCanvas.cpp:1206
@ kButt_Cap
no stroke extension
Definition: SkPaint.h:334
@ kStroke_Style
set to stroke geometry
Definition: SkPaint.h:194
static bool FromSVGString(const char str[], SkPath *)
Definition: SkPath.h:59
void append(const char text[])
Definition: SkString.h:203
const char * c_str() const
Definition: SkString.h:133
void void void appendf(const char format[],...) SK_PRINTF_LIKE(2
Definition: SkString.cpp:550
const Paint & paint
Definition: color_source.cc:38
SK_API sk_sp< SkSurface > Raster(const SkImageInfo &imageInfo, size_t rowBytes, const SkSurfaceProps *surfaceProps)
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition: switches.h:57
static const SkPaint::Cap kCaps[]
static const char * kAllVerbs[]
static const int kCellWidth
static const SkScalar kWidths[]
static const int kCellHeight
static void draw_path_cell(SkCanvas *canvas, SkSurface *surface, int expectedCaps)
static const int kCellPad
int32_t width
SkImageInfo makeWH(int newWidth, int newHeight) const
Definition: SkImageInfo.h:444

◆ draw_zero_length_capped_paths_dbl_contour()

static skiagm::DrawResult draw_zero_length_capped_paths_dbl_contour ( SkCanvas canvas,
bool  aa,
SkString errorMsg 
)
static

Definition at line 190 of file path_stroke_with_zero_length.cpp.

191 {
192 auto rContext = canvas->recordingContext();
193 auto dContext = GrAsDirectContext(rContext);
194
195 if (!dContext && rContext) {
196 *errorMsg = "Not supported in DDL mode";
198 }
199 canvas->translate(kCellPad, kCellPad);
200
202 auto surface = canvas->makeSurface(info);
203 if (!surface) {
205 }
206
208 paint.setColor(SK_ColorWHITE);
209 paint.setAntiAlias(aa);
211
212 for (auto cap : kCaps) {
213 for (auto width : kWidths) {
214 paint.setStrokeCap(cap);
215 paint.setStrokeWidth(width);
216 canvas->save();
217
218 for (auto firstVerb : kSomeVerbs) {
219 for (auto secondVerb : kSomeVerbs) {
220 int expectedCaps = 0;
221
222 SkString pathStr;
223 pathStr.append("M 9.5 9.5 ");
224 if (firstVerb) {
225 pathStr.append(firstVerb);
226 ++expectedCaps;
227 }
228 pathStr.append("M 40.5 9.5 ");
229 if (secondVerb) {
230 pathStr.append(secondVerb);
231 ++expectedCaps;
232 }
233
234 SkPath path;
236
237 surface->getCanvas()->clear(SK_ColorTRANSPARENT);
238 surface->getCanvas()->drawPath(path, paint);
239
240 if (SkPaint::kButt_Cap == cap) {
241 expectedCaps = 0;
242 }
243
244 draw_path_cell(canvas, surface.get(), expectedCaps);
245 canvas->translate(kCellWidth + kCellPad, 0);
246 }
247 }
248 canvas->restore();
249 canvas->translate(0, kCellHeight + kCellPad);
250 }
251 }
252
254}
static GrDirectContext * GrAsDirectContext(GrContext_Base *base)
virtual GrRecordingContext * recordingContext() const
Definition: SkCanvas.cpp:1637
static const char * kSomeVerbs[]

Variable Documentation

◆ kAllVerbs

const char* kAllVerbs[]
static
Initial value:
= {
nullptr,
"z ",
"l 0 0 ",
"l 0 0 z ",
"q 0 0 0 0 ",
"q 0 0 0 0 z ",
"c 0 0 0 0 0 0 ",
"c 0 0 0 0 0 0 z ",
"a 0 0 0 0 0 0 0 ",
"a 0 0 0 0 0 0 0 z "
}

Definition at line 96 of file path_stroke_with_zero_length.cpp.

◆ kCaps

const SkPaint::Cap kCaps[]
static
Initial value:
= {
}
@ kRound_Cap
adds circle
Definition: SkPaint.h:335
@ kSquare_Cap
adds square
Definition: SkPaint.h:336

Definition at line 87 of file path_stroke_with_zero_length.cpp.

◆ kCellHeight

const int kCellHeight = 20
static

Definition at line 120 of file path_stroke_with_zero_length.cpp.

◆ kCellPad

const int kCellPad = 2
static

Definition at line 121 of file path_stroke_with_zero_length.cpp.

◆ kCellWidth

const int kCellWidth = 50
static

Definition at line 119 of file path_stroke_with_zero_length.cpp.

◆ kDblContourNumColums

const int kDblContourNumColums = std::size(kSomeVerbs) * std::size(kSomeVerbs)
static

Definition at line 128 of file path_stroke_with_zero_length.cpp.

◆ kDblContourTotalWidth

const int kDblContourTotalWidth = kDblContourNumColums * (kCellWidth + kCellPad) + kCellPad
static

Definition at line 129 of file path_stroke_with_zero_length.cpp.

◆ kNumColumns

const int kNumColumns = std::size(kAllVerbs)
static

Definition at line 124 of file path_stroke_with_zero_length.cpp.

◆ kNumRows

const int kNumRows = std::size(kCaps) * std::size(kWidths)
static

Definition at line 123 of file path_stroke_with_zero_length.cpp.

◆ kSomeVerbs

const char* kSomeVerbs[]
static
Initial value:
= {
nullptr,
"z ",
"l 0 0 ",
"l 0 0 z ",
"q 0 0 0 0 ",
"q 0 0 0 0 z ",
}

Definition at line 110 of file path_stroke_with_zero_length.cpp.

◆ kTotalHeight

const int kTotalHeight = kNumRows * (kCellHeight + kCellPad) + kCellPad
static

Definition at line 126 of file path_stroke_with_zero_length.cpp.

◆ kTotalWidth

const int kTotalWidth = kNumColumns * (kCellWidth + kCellPad) + kCellPad
static

Definition at line 125 of file path_stroke_with_zero_length.cpp.

◆ kWidths

const SkScalar kWidths[] = { 0.0f, 0.9f, 1.0f, 1.1f, 15.0f, 25.0f }
static

Definition at line 93 of file path_stroke_with_zero_length.cpp.