blob: ca437da4edc0775da27c0df171116ce364112de1 [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;
48 GrPathRenderer::DrawPathArgs args;
49 args.fPaint = &paint;
50 args.fUserStencilSettings = &GrUserStencilSettings::kUnused;
Brian Osman11052242016-10-27 14:47:55 -040051 args.fRenderTargetContext = renderTargetContext;
bsalomon6d6b6ad2016-07-13 14:45:28 -070052 args.fClip = &noClip;
53 args.fResourceProvider = rp;
54 args.fViewMatrix = &matrix;
55 args.fShape = &shape;
Brian Salomon0e8fc8b2016-12-09 15:10:07 -050056 args.fAAType = GrAAType::kCoverage;
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 }
Brian Osman11052242016-10-27 14:47:55 -040066 sk_sp<GrRenderTargetContext> rtc(ctxInfo.grContext()->makeRenderTargetContext(
67 SkBackingFit::kApprox,
68 800, 800,
69 kRGBA_8888_GrPixelConfig,
70 nullptr,
71 0,
72 kTopLeft_GrSurfaceOrigin));
73 if (!rtc) {
bsalomon6d6b6ad2016-07-13 14:45:28 -070074 return;
75 }
76
77 GrAADistanceFieldPathRenderer dfpr;
78 GrTestTarget tt;
Brian Osman11052242016-10-27 14:47:55 -040079 ctxInfo.grContext()->getTestTarget(&tt, rtc);
bsalomon6d6b6ad2016-07-13 14:45:28 -070080 GrResourceProvider* rp = tt.resourceProvider();
81
Brian Osman11052242016-10-27 14:47:55 -040082 test_far_from_origin(rtc.get(), &dfpr, rp);
bsalomon6d6b6ad2016-07-13 14:45:28 -070083 ctxInfo.grContext()->flush();
84}
85#endif