1 /*
2  * Copyright 2016 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 "Test.h"
9 
10 #include "SkPath.h"
11 
12 #if SK_SUPPORT_GPU
13 #include "GrContext.h"
14 #include "ops/GrSmallPathRenderer.h"
15 
16 #if 0
17 // This test case including path coords and matrix taken from crbug.com/627443.
18 // Because of inaccuracies in large floating point values this causes the
19 // the path renderer to attempt to add a path DF to its atlas that is larger
20 // than the plot size which used to crash rather than fail gracefully.
21 static void test_far_from_origin(GrContext* ctx, GrRenderTargetContext* renderTargetContext,
22                                  GrPathRenderer* pr) {
23     SkPath path;
24     path.lineTo(49.0255089839f, 0.473541f);
25     // This extra line wasn't in the original bug but was added to fake out GrShape's special
26     // handling of single line segments.
27     path.rLineTo(0.015f, 0.015f);
28     static constexpr SkScalar mvals[] = {14.0348252854f, 2.13026182736f,
29                                          13.6122547187f, 118.309922702f,
30                                          1912337682.09f, 2105391889.87f};
31     SkMatrix matrix;
32     matrix.setAffine(mvals);
33     SkMatrix inverse;
34     SkAssertResult(matrix.invert(&inverse));
35     path.transform(inverse);
36 
37     SkStrokeRec rec(SkStrokeRec::kFill_InitStyle);
38     rec.setStrokeStyle(1.f);
39     rec.setStrokeParams(SkPaint::kRound_Cap, SkPaint::kRound_Join, 1.f);
40     GrStyle style(rec, nullptr);
41 
42     GrShape shape(path, style);
43     shape = shape.applyStyle(GrStyle::Apply::kPathEffectAndStrokeRec, 1.f);
44 
45     GrPaint paint;
46     paint.setXPFactory(GrPorterDuffXPFactory::Get(SkBlendMode::kSrc));
47 
48     GrNoClip noClip;
49     GrPathRenderer::DrawPathArgs args{ctx,
50                                       std::move(paint),
51                                       &GrUserStencilSettings::kUnused,
52                                       renderTargetContext,
53                                       &noClip,
54                                       &matrix,
55                                       &shape,
56                                       GrAAType::kCoverage,
57                                       false};
58     pr->drawPath(args);
59 }
60 
61 DEF_GPUTEST_FOR_ALL_GL_CONTEXTS(SmallPathRenderer, reporter, ctxInfo) {
62     GrContext* ctx = ctxInfo.grContext();
63     // The DF PR only works with contexts that support derivatives
64     if (!ctx->caps()->shaderCaps()->shaderDerivativeSupport()) {
65         return;
66     }
67     sk_sp<GrRenderTargetContext> rtc(ctx->makeRenderTargetContext(SkBackingFit::kApprox,
68                                                                   800, 800,
69                                                                   kRGBA_8888_GrPixelConfig,
70                                                                   nullptr,
71                                                                   0,
72                                                                   kTopLeft_GrSurfaceOrigin));
73     if (!rtc) {
74         return;
75     }
76 
77     GrSmallPathRenderer spr;
78 
79     ctx->flush();
80     test_far_from_origin(ctx, rtc.get(), &spr);
81     ctx->flush();
82 }
83 #endif
84 #endif
85