Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Functions
hittestpath.cpp File Reference
#include "gm/gm.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkColor.h"
#include "include/core/SkPaint.h"
#include "include/core/SkPathBuilder.h"
#include "include/core/SkRect.h"
#include "include/core/SkScalar.h"
#include "include/core/SkTypes.h"
#include "src/base/SkRandom.h"

Go to the source code of this file.

Functions

static void test_hittest (SkCanvas *canvas, const SkPath &path)
 
 DEF_SIMPLE_GM_CAN_FAIL (hittestpath, canvas, errorMsg, 700, 460)
 

Function Documentation

◆ DEF_SIMPLE_GM_CAN_FAIL()

DEF_SIMPLE_GM_CAN_FAIL ( hittestpath  ,
canvas  ,
errorMsg  ,
700  ,
460   
)

Definition at line 37 of file hittestpath.cpp.

37 {
38 if (canvas->recordingContext() || canvas->recorder()) {
39 // GPU rasterization results vary greatly from platform to platform. We can't use them as
40 // an expected result for our internal SkPath::contains().
41 *errorMsg = "This test is for CPU configs only.";
43 }
44
46 SkRandom rand;
47
48 int scale = 300;
49 for (int i = 0; i < 4; ++i) {
50 // get the random values deterministically
51 SkScalar randoms[12];
52 for (int index = 0; index < (int) std::size(randoms); ++index) {
53 randoms[index] = rand.nextUScalar1();
54 }
55 b.lineTo(randoms[0] * scale, randoms[1] * scale)
56 .quadTo(randoms[2] * scale, randoms[3] * scale,
57 randoms[4] * scale, randoms[5] * scale)
58 .cubicTo(randoms[6] * scale, randoms[7] * scale,
59 randoms[8] * scale, randoms[9] * scale,
60 randoms[10] * scale, randoms[11] * scale);
61 }
62
63 b.setFillType(SkPathFillType::kEvenOdd);
64 b.offset(SkIntToScalar(20), SkIntToScalar(20));
65
66 SkPath path = b.detach();
67
68 test_hittest(canvas, path);
69
70 canvas->translate(SkIntToScalar(scale), 0);
71 path.setFillType(SkPathFillType::kWinding);
72
73 test_hittest(canvas, path);
75}
#define SkIntToScalar(x)
Definition SkScalar.h:57
Type::kYUV Type::kRGBA() int(0.7 *637)
SkScalar nextUScalar1()
Definition SkRandom.h:101
float SkScalar
Definition extension.cpp:12
static bool b
static void test_hittest(SkCanvas *canvas, const SkPath &path)
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
const Scalar scale

◆ test_hittest()

static void test_hittest ( SkCanvas canvas,
const SkPath path 
)
static

Definition at line 18 of file hittestpath.cpp.

18 {
20 SkRect r = path.getBounds();
21
22 paint.setColor(SK_ColorRED);
23 canvas->drawPath(path, paint);
24
25 const SkScalar MARGIN = SkIntToScalar(4);
26
27 paint.setColor(0x800000FF);
28 for (SkScalar y = r.fTop + SK_ScalarHalf - MARGIN; y < r.fBottom + MARGIN; y += SK_Scalar1) {
29 for (SkScalar x = r.fLeft + SK_ScalarHalf - MARGIN; x < r.fRight + MARGIN; x += SK_Scalar1) {
30 if (path.contains(x, y)) {
31 canvas->drawPoint(x, y, paint);
32 }
33 }
34 }
35}
constexpr SkColor SK_ColorRED
Definition SkColor.h:126
#define SK_Scalar1
Definition SkScalar.h:18
#define SK_ScalarHalf
Definition SkScalar.h:19
void drawPoint(SkScalar x, SkScalar y, const SkPaint &paint)
void drawPath(const SkPath &path, const SkPaint &paint)
const Paint & paint
#define MARGIN
double y
double x
SkScalar fBottom
larger y-axis bounds
Definition extension.cpp:17
SkScalar fLeft
smaller x-axis bounds
Definition extension.cpp:14
SkScalar fRight
larger x-axis bounds
Definition extension.cpp:16
SkScalar fTop
smaller y-axis bounds
Definition extension.cpp:15