Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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);
76 oval1.addOval(rect, SkPathDirection::kCW);
77 oval2.addOval(rect, SkPathDirection::kCCW);
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
static void test_drawSameRectOvals(skiatest::Reporter *, SkCanvas *canvas)
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
#define DEF_GANESH_TEST_FOR_GL_CONTEXT(name, reporter, context_info, ctsEnforcement)
Definition Test.h:442
#define DEF_GANESH_TEST_FOR_ALL_CONTEXTS(name, reporter, context_info, ctsEnforcement)
Definition Test.h:431
void drawRect(const SkRect &rect, const SkPaint &paint)
void drawOval(const SkRect &oval, const SkPaint &paint)
void drawRRect(const SkRRect &rrect, const SkPaint &paint)
void drawPath(const SkPath &path, const SkPaint &paint)
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
SkPath & addOval(const SkRect &oval, SkPathDirection dir=SkPathDirection::kCW)
Definition SkPath.cpp:1101
static SkRRect MakeRect(const SkRect &r)
Definition SkRRect.h:149
const Paint & paint
VkSurfaceKHR surface
Definition main.cc:49
float SkScalar
Definition extension.cpp:12
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)
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