blob: d36c16845e90222d49e2531393448f002e20b279 [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;
bsalomon0b300492016-07-18 10:09:41 -070057 args.fGammaCorrect = false;
bsalomon6d6b6ad2016-07-13 14:45:28 -070058 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 }
robertphillips6738c702016-07-27 12:13:51 -070066 sk_sp<GrDrawContext> dc(ctxInfo.grContext()->makeDrawContext(SkBackingFit::kApprox,
67 800, 800,
68 kSkia8888_GrPixelConfig,
69 nullptr,
70 0,
71 kTopLeft_GrSurfaceOrigin));
72 if (!dc) {
bsalomon6d6b6ad2016-07-13 14:45:28 -070073 return;
74 }
75
76 GrAADistanceFieldPathRenderer dfpr;
77 GrTestTarget tt;
robertphillips6738c702016-07-27 12:13:51 -070078 ctxInfo.grContext()->getTestTarget(&tt, dc);
bsalomon6d6b6ad2016-07-13 14:45:28 -070079 GrResourceProvider* rp = tt.resourceProvider();
80
robertphillips6738c702016-07-27 12:13:51 -070081 test_far_from_origin(dc.get(), &dfpr, rp);
bsalomon6d6b6ad2016-07-13 14:45:28 -070082 ctxInfo.grContext()->flush();
83}
84#endif