blob: a6163994066b3f7a11b398a495add46dfbcead95 [file] [log] [blame]
bsalomon6d6b6ad2016-07-13 14:45:28 -07001/*
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#if SK_SUPPORT_GPU
11#include "GrContext.h"
12#include "GrTest.h"
13#include "batches/GrAADistanceFieldPathRenderer.h"
14#include "SkPath.h"
15
16// This test case including path coords and matrix taken from crbug.com/627443.
17// Because of inaccuracies in large floating point values this causes the
18// the path renderer to attempt to add a path DF to its atlas that is larger
19// than the plot size which used to crash rather than fail gracefully.
20static void test_far_from_origin(GrDrawContext* drawContext, GrPathRenderer* pr,
21 GrResourceProvider* rp) {
22 SkPath path;
23 path.lineTo(49.0255089839f, 0.473541f);
bsalomon0ae36a22016-07-18 07:31:13 -070024 // This extra line wasn't in the original bug but was added to fake out GrShape's special
25 // handling of single line segments.
26 path.rLineTo(0.015f, 0.015f);
bsalomon6d6b6ad2016-07-13 14:45:28 -070027 static constexpr SkScalar mvals[] = {14.0348252854f, 2.13026182736f,
28 13.6122547187f, 118.309922702f,
29 1912337682.09f, 2105391889.87f};
30 SkMatrix matrix;
31 matrix.setAffine(mvals);
32 SkMatrix inverse;
33 SkAssertResult(matrix.invert(&inverse));
34 path.transform(inverse);
35
36 SkStrokeRec rec(SkStrokeRec::kFill_InitStyle);
37 rec.setStrokeStyle(1.f);
38 rec.setStrokeParams(SkPaint::kRound_Cap, SkPaint::kRound_Join, 1.f);
39 GrStyle style(rec, nullptr);
40
41 GrShape shape(path, style);
42 shape = shape.applyStyle(GrStyle::Apply::kPathEffectAndStrokeRec, 1.f);
43
44 GrPaint paint;
45 paint.setXPFactory(GrPorterDuffXPFactory::Make(SkXfermode::kSrc_Mode));
46
47 GrNoClip noClip;
48 GrPathRenderer::DrawPathArgs args;
49 args.fPaint = &paint;
50 args.fUserStencilSettings = &GrUserStencilSettings::kUnused;
51 args.fDrawContext = drawContext;
52 args.fClip = &noClip;
53 args.fResourceProvider = rp;
54 args.fViewMatrix = &matrix;
55 args.fShape = &shape;
56 args.fAntiAlias = true;
57
58 pr->drawPath(args);
59}
60
61DEF_GPUTEST_FOR_ALL_GL_CONTEXTS(AADistanceFieldPathRenderer, reporter, ctxInfo) {
62 // The DF PR only works with contexts that support derivatives
63 if (!ctxInfo.grContext()->caps()->shaderCaps()->shaderDerivativeSupport()) {
64 return;
65 }
66 sk_sp<GrDrawContext> drawContext(ctxInfo.grContext()->newDrawContext(SkBackingFit::kApprox,
67 800, 800,
68 kSkia8888_GrPixelConfig,
69 0,
70 kTopLeft_GrSurfaceOrigin));
71 if (!drawContext) {
72 return;
73 }
74
75 GrAADistanceFieldPathRenderer dfpr;
76 GrTestTarget tt;
77 ctxInfo.grContext()->getTestTarget(&tt, drawContext);
78 GrResourceProvider* rp = tt.resourceProvider();
79
80 test_far_from_origin(drawContext.get(), &dfpr, rp);
81 ctxInfo.grContext()->flush();
82}
83#endif