blob: 7fb8c8a12010325b3caf9fb5a0da87e67f6dcb5e [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"
bsalomon6d6b6ad2016-07-13 14:45:28 -070013#include "SkPath.h"
Brian Salomon89527432016-12-16 09:52:16 -050014#include "ops/GrAADistanceFieldPathRenderer.h"
bsalomon6d6b6ad2016-07-13 14:45:28 -070015
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.
Brian Osman11052242016-10-27 14:47:55 -040020static void test_far_from_origin(GrRenderTargetContext* renderTargetContext, GrPathRenderer* pr,
bsalomon6d6b6ad2016-07-13 14:45:28 -070021 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;
Brian Salomona1633922017-01-09 11:46:10 -050045 paint.setXPFactory(GrPorterDuffXPFactory::Get(SkBlendMode::kSrc));
bsalomon6d6b6ad2016-07-13 14:45:28 -070046
47 GrNoClip noClip;
Brian Salomon82f44312017-01-11 13:42:54 -050048 GrPathRenderer::DrawPathArgs args{rp,
49 std::move(paint),
50 &GrUserStencilSettings::kUnused,
51 renderTargetContext,
52 &noClip,
53 &matrix,
54 &shape,
55 GrAAType::kCoverage,
56 false};
bsalomon6d6b6ad2016-07-13 14:45:28 -070057 pr->drawPath(args);
58}
59
60DEF_GPUTEST_FOR_ALL_GL_CONTEXTS(AADistanceFieldPathRenderer, reporter, ctxInfo) {
61 // The DF PR only works with contexts that support derivatives
62 if (!ctxInfo.grContext()->caps()->shaderCaps()->shaderDerivativeSupport()) {
63 return;
64 }
Brian Osman11052242016-10-27 14:47:55 -040065 sk_sp<GrRenderTargetContext> rtc(ctxInfo.grContext()->makeRenderTargetContext(
66 SkBackingFit::kApprox,
67 800, 800,
68 kRGBA_8888_GrPixelConfig,
69 nullptr,
70 0,
71 kTopLeft_GrSurfaceOrigin));
72 if (!rtc) {
bsalomon6d6b6ad2016-07-13 14:45:28 -070073 return;
74 }
75
76 GrAADistanceFieldPathRenderer dfpr;
77 GrTestTarget tt;
Brian Osman11052242016-10-27 14:47:55 -040078 ctxInfo.grContext()->getTestTarget(&tt, rtc);
bsalomon6d6b6ad2016-07-13 14:45:28 -070079 GrResourceProvider* rp = tt.resourceProvider();
80
Brian Osman11052242016-10-27 14:47:55 -040081 test_far_from_origin(rtc.get(), &dfpr, rp);
bsalomon6d6b6ad2016-07-13 14:45:28 -070082 ctxInfo.grContext()->flush();
83}
84#endif