Flutter Engine
The Flutter Engine
GpuDrawPathTest.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2013 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#include "tests/Test.h"
8
14#include "include/core/SkPath.h"
18#include "include/core/SkRect.h"
26#include "include/gpu/GrTypes.h"
29
30#include <initializer_list>
31
32struct GrContextOptions;
33
35 // Filling an empty path should not crash.
37 SkRect emptyRect = SkRect::MakeEmpty();
38 canvas->drawRect(emptyRect, paint);
39 canvas->drawPath(SkPath(), paint);
40 canvas->drawOval(emptyRect, paint);
41 canvas->drawRect(emptyRect, paint);
42 canvas->drawRRect(SkRRect::MakeRect(emptyRect), paint);
43
44 // Stroking an empty path should not crash.
45 paint.setAntiAlias(true);
47 paint.setColor(SK_ColorGRAY);
48 paint.setStrokeWidth(SkIntToScalar(20));
49 paint.setStrokeJoin(SkPaint::kRound_Join);
50 canvas->drawRect(emptyRect, paint);
51 canvas->drawPath(SkPath(), paint);
52 canvas->drawOval(emptyRect, paint);
53 canvas->drawRect(emptyRect, paint);
54 canvas->drawRRect(SkRRect::MakeRect(emptyRect), paint);
55}
56
57static void fill_and_stroke(SkCanvas* canvas, const SkPath& p1, const SkPath& p2,
58 sk_sp<SkPathEffect> effect) {
60 paint.setAntiAlias(true);
61 paint.setPathEffect(effect);
62
63 canvas->drawPath(p1, paint);
64 canvas->drawPath(p2, paint);
65
67 canvas->drawPath(p1, paint);
68 canvas->drawPath(p2, paint);
69}
70
72 // Drawing ovals with similar bounds but different points order should not crash.
73
74 SkPath oval1, oval2;
75 const SkRect rect = SkRect::MakeWH(100, 50);
78
79 fill_and_stroke(canvas, oval1, oval2, nullptr);
80
81 const SkScalar intervals[] = { 1, 1 };
82 fill_and_stroke(canvas, oval1, oval2, SkDashPathEffect::Make(intervals, 2, 0));
83}
84
86 for (auto& test_func : { &test_drawPathEmpty, &test_drawSameRectOvals }) {
87 for (auto& sampleCount : {1, 4, 16}) {
90 ctxInfo.directContext(), skgpu::Budgeted::kNo, info, sampleCount, nullptr));
91 if (!surface) {
92 continue;
93 }
94 test_func(reporter, surface->getCanvas());
95 }
96 }
97}
98
100 reporter,
101 ctxInfo,
103 // From https://bugs.fuchsia.dev/p/fuchsia/issues/detail?id=37330, it's possible for a convex
104 // path to be accepted by AAConvexPathRenderer, then be transformed to something without a
105 // computable first direction by a perspective matrix.
107 auto dContext = ctxInfo.directContext();
109
111 paint.setAntiAlias(true);
112
113 SkPath path;
114 path.moveTo(0, 0);
115 path.lineTo(50, 0);
116 path.lineTo(0, 50);
117 path.close();
118
119 SkMatrix m;
120 m.setAll( 0.966006875f , -0.125156224f , 72.0899811f,
121 -0.00885376986f , -0.112347461f , 64.7121124f,
122 -8.94321693e-06f, -0.00173384184f, 0.998692870f);
123 surface->getCanvas()->setMatrix(m);
124 surface->getCanvas()->drawPath(path, paint);
125 dContext->flushAndSubmit(surface.get(), GrSyncCpu::kNo);
126}
127
129 reporter,
130 ctxInfo,
132 // AAHairlinePathRenderer chops this path to quads that include infinities (and then NaNs).
133 // It used to trigger asserts, now the degenerate quad segments should cause it to be rejected.
135 auto dContext = ctxInfo.directContext();
137
139 paint.setAntiAlias(true);
141
142 SkPath path;
143 path.moveTo(9.0072E15f, 60);
144 path.cubicTo(0, 3.40282e+38f, 0, 3.40282e+38f, 0, 0);
145
146 surface->getCanvas()->drawPath(path, paint);
147 dContext->flushAndSubmit(surface.get(), GrSyncCpu::kNo);
148}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
reporter
Definition: FontMgrTest.cpp:39
static void test_drawSameRectOvals(skiatest::Reporter *, SkCanvas *canvas)
DEF_GANESH_TEST_FOR_ALL_CONTEXTS(GrDrawCollapsedPath, reporter, ctxInfo, CtsEnforcement::kApiLevel_T)
DEF_GANESH_TEST_FOR_GL_CONTEXT(GpuDrawPath, reporter, ctxInfo, CtsEnforcement::kNever)
static void fill_and_stroke(SkCanvas *canvas, const SkPath &p1, const SkPath &p2, sk_sp< SkPathEffect > effect)
static void test_drawPathEmpty(skiatest::Reporter *, SkCanvas *canvas)
constexpr SkColor SK_ColorGRAY
Definition: SkColor.h:113
#define SkIntToScalar(x)
Definition: SkScalar.h:57
void drawRect(const SkRect &rect, const SkPaint &paint)
Definition: SkCanvas.cpp:1673
void drawOval(const SkRect &oval, const SkPaint &paint)
Definition: SkCanvas.cpp:1698
void drawRRect(const SkRRect &rrect, const SkPaint &paint)
Definition: SkCanvas.cpp:1705
void drawPath(const SkPath &path, const SkPaint &paint)
Definition: SkCanvas.cpp:1747
static sk_sp< SkPathEffect > Make(const SkScalar intervals[], int count, SkScalar phase)
@ kStroke_Style
set to stroke geometry
Definition: SkPaint.h:194
@ kRound_Join
adds circle
Definition: SkPaint.h:360
Definition: SkPath.h:59
SkPath & addOval(const SkRect &oval, SkPathDirection dir=SkPathDirection::kCW)
Definition: SkPath.cpp:1106
static SkRRect MakeRect(const SkRect &r)
Definition: SkRRect.h:149
const Paint & paint
Definition: color_source.cc:38
VkSurfaceKHR surface
Definition: main.cc:49
float SkScalar
Definition: extension.cpp:12
sk_sp< SkBlender > blender SkRect rect
Definition: SkRecords.h:350
SK_API sk_sp< SkSurface > RenderTarget(GrRecordingContext *context, skgpu::Budgeted budgeted, const SkImageInfo &imageInfo, int sampleCount, GrSurfaceOrigin surfaceOrigin, const SkSurfaceProps *surfaceProps, bool shouldCreateWithMips=false, bool isProtected=false)
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 SkImageInfo MakeN32Premul(int width, int height)
static constexpr SkRect MakeEmpty()
Definition: SkRect.h:595
static constexpr SkRect MakeWH(float w, float h)
Definition: SkRect.h:609