Flutter Engine
The Flutter Engine
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
void drawPoint(SkScalar x, SkScalar y, const SkPaint &paint)
Definition: SkCanvas.cpp:2695
void drawPath(const SkPath &path, const SkPaint &paint)
Definition: SkCanvas.cpp:1747
Definition: SkPath.h:59
SkScalar nextUScalar1()
Definition: SkRandom.h:101
const Paint & paint
Definition: color_source.cc:38
#define MARGIN
float SkScalar
Definition: extension.cpp:12
static bool b
static void test_hittest(SkCanvas *canvas, const SkPath &path)
Definition: hittestpath.cpp:18
DEF_SIMPLE_GM_CAN_FAIL(hittestpath, canvas, errorMsg, 700, 460)
Definition: hittestpath.cpp:37
double y
double x
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
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
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