bsalomon | 6d6b6ad | 2016-07-13 14:45:28 -0700 | [diff] [blame] | 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 | #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. |
| 20 | static void test_far_from_origin(GrDrawContext* drawContext, GrPathRenderer* pr, |
| 21 | GrResourceProvider* rp) { |
| 22 | SkPath path; |
| 23 | path.lineTo(49.0255089839f, 0.473541f); |
bsalomon | 0ae36a2 | 2016-07-18 07:31:13 -0700 | [diff] [blame] | 24 | // 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); |
bsalomon | 6d6b6ad | 2016-07-13 14:45:28 -0700 | [diff] [blame] | 27 | 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; |
bsalomon | 0b30049 | 2016-07-18 10:09:41 -0700 | [diff] [blame] | 57 | args.fGammaCorrect = false; |
bsalomon | 6d6b6ad | 2016-07-13 14:45:28 -0700 | [diff] [blame] | 58 | pr->drawPath(args); |
| 59 | } |
| 60 | |
| 61 | DEF_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 | } |
robertphillips | 6738c70 | 2016-07-27 12:13:51 -0700 | [diff] [blame] | 66 | 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) { |
bsalomon | 6d6b6ad | 2016-07-13 14:45:28 -0700 | [diff] [blame] | 73 | return; |
| 74 | } |
| 75 | |
| 76 | GrAADistanceFieldPathRenderer dfpr; |
| 77 | GrTestTarget tt; |
robertphillips | 6738c70 | 2016-07-27 12:13:51 -0700 | [diff] [blame] | 78 | ctxInfo.grContext()->getTestTarget(&tt, dc); |
bsalomon | 6d6b6ad | 2016-07-13 14:45:28 -0700 | [diff] [blame] | 79 | GrResourceProvider* rp = tt.resourceProvider(); |
| 80 | |
robertphillips | 6738c70 | 2016-07-27 12:13:51 -0700 | [diff] [blame] | 81 | test_far_from_origin(dc.get(), &dfpr, rp); |
bsalomon | 6d6b6ad | 2016-07-13 14:45:28 -0700 | [diff] [blame] | 82 | ctxInfo.grContext()->flush(); |
| 83 | } |
| 84 | #endif |