Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
hittestpath.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2011 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"
13#include "include/core/SkRect.h"
16#include "src/base/SkRandom.h"
17
18static void test_hittest(SkCanvas* canvas, const SkPath& path) {
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}
36
37DEF_SIMPLE_GM_CAN_FAIL(hittestpath, canvas, errorMsg, 700, 460) {
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}
constexpr SkColor SK_ColorRED
Definition SkColor.h:126
#define SK_Scalar1
Definition SkScalar.h:18
#define SK_ScalarHalf
Definition SkScalar.h:19
#define SkIntToScalar(x)
Definition SkScalar.h:57
Type::kYUV Type::kRGBA() int(0.7 *637)
void drawPoint(SkScalar x, SkScalar y, const SkPaint &paint)
void drawPath(const SkPath &path, const SkPaint &paint)
SkScalar nextUScalar1()
Definition SkRandom.h:101
const Paint & paint
#define MARGIN
float SkScalar
Definition extension.cpp:12
static bool b
#define DEF_SIMPLE_GM_CAN_FAIL(NAME, CANVAS, ERR_MSG, W, H)
Definition gm.h:62
static void test_hittest(SkCanvas *canvas, const SkPath &path)
double y
double x
const Scalar scale
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