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 | |
Robert Phillips | 77505da | 2017-01-20 09:11:37 -0500 | [diff] [blame^] | 10 | #include "SkPath.h" |
| 11 | |
bsalomon | 6d6b6ad | 2016-07-13 14:45:28 -0700 | [diff] [blame] | 12 | #if SK_SUPPORT_GPU |
| 13 | #include "GrContext.h" |
Brian Salomon | 8952743 | 2016-12-16 09:52:16 -0500 | [diff] [blame] | 14 | #include "ops/GrAADistanceFieldPathRenderer.h" |
bsalomon | 6d6b6ad | 2016-07-13 14:45:28 -0700 | [diff] [blame] | 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. |
Robert Phillips | 77505da | 2017-01-20 09:11:37 -0500 | [diff] [blame^] | 20 | static void test_far_from_origin(GrResourceProvider* rp, |
| 21 | GrRenderTargetContext* renderTargetContext, |
| 22 | GrPathRenderer* pr) { |
bsalomon | 6d6b6ad | 2016-07-13 14:45:28 -0700 | [diff] [blame] | 23 | SkPath path; |
| 24 | path.lineTo(49.0255089839f, 0.473541f); |
bsalomon | 0ae36a2 | 2016-07-18 07:31:13 -0700 | [diff] [blame] | 25 | // This extra line wasn't in the original bug but was added to fake out GrShape's special |
| 26 | // handling of single line segments. |
| 27 | path.rLineTo(0.015f, 0.015f); |
bsalomon | 6d6b6ad | 2016-07-13 14:45:28 -0700 | [diff] [blame] | 28 | static constexpr SkScalar mvals[] = {14.0348252854f, 2.13026182736f, |
| 29 | 13.6122547187f, 118.309922702f, |
| 30 | 1912337682.09f, 2105391889.87f}; |
| 31 | SkMatrix matrix; |
| 32 | matrix.setAffine(mvals); |
| 33 | SkMatrix inverse; |
| 34 | SkAssertResult(matrix.invert(&inverse)); |
| 35 | path.transform(inverse); |
| 36 | |
| 37 | SkStrokeRec rec(SkStrokeRec::kFill_InitStyle); |
| 38 | rec.setStrokeStyle(1.f); |
| 39 | rec.setStrokeParams(SkPaint::kRound_Cap, SkPaint::kRound_Join, 1.f); |
| 40 | GrStyle style(rec, nullptr); |
| 41 | |
| 42 | GrShape shape(path, style); |
| 43 | shape = shape.applyStyle(GrStyle::Apply::kPathEffectAndStrokeRec, 1.f); |
| 44 | |
| 45 | GrPaint paint; |
Brian Salomon | a163392 | 2017-01-09 11:46:10 -0500 | [diff] [blame] | 46 | paint.setXPFactory(GrPorterDuffXPFactory::Get(SkBlendMode::kSrc)); |
bsalomon | 6d6b6ad | 2016-07-13 14:45:28 -0700 | [diff] [blame] | 47 | |
| 48 | GrNoClip noClip; |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 49 | GrPathRenderer::DrawPathArgs args{rp, |
| 50 | std::move(paint), |
| 51 | &GrUserStencilSettings::kUnused, |
| 52 | renderTargetContext, |
| 53 | &noClip, |
| 54 | &matrix, |
| 55 | &shape, |
| 56 | GrAAType::kCoverage, |
| 57 | 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) { |
Robert Phillips | 77505da | 2017-01-20 09:11:37 -0500 | [diff] [blame^] | 62 | GrContext* ctx = ctxInfo.grContext(); |
bsalomon | 6d6b6ad | 2016-07-13 14:45:28 -0700 | [diff] [blame] | 63 | // The DF PR only works with contexts that support derivatives |
Robert Phillips | 77505da | 2017-01-20 09:11:37 -0500 | [diff] [blame^] | 64 | if (!ctx->caps()->shaderCaps()->shaderDerivativeSupport()) { |
bsalomon | 6d6b6ad | 2016-07-13 14:45:28 -0700 | [diff] [blame] | 65 | return; |
| 66 | } |
Robert Phillips | 77505da | 2017-01-20 09:11:37 -0500 | [diff] [blame^] | 67 | sk_sp<GrRenderTargetContext> rtc(ctx->makeRenderTargetContext(SkBackingFit::kApprox, |
| 68 | 800, 800, |
| 69 | kRGBA_8888_GrPixelConfig, |
| 70 | nullptr, |
| 71 | 0, |
| 72 | kTopLeft_GrSurfaceOrigin)); |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 73 | if (!rtc) { |
bsalomon | 6d6b6ad | 2016-07-13 14:45:28 -0700 | [diff] [blame] | 74 | return; |
| 75 | } |
| 76 | |
| 77 | GrAADistanceFieldPathRenderer dfpr; |
bsalomon | 6d6b6ad | 2016-07-13 14:45:28 -0700 | [diff] [blame] | 78 | |
Robert Phillips | 77505da | 2017-01-20 09:11:37 -0500 | [diff] [blame^] | 79 | ctx->flush(); |
| 80 | test_far_from_origin(ctx->resourceProvider(), rtc.get(), &dfpr); |
| 81 | ctx->flush(); |
bsalomon | 6d6b6ad | 2016-07-13 14:45:28 -0700 | [diff] [blame] | 82 | } |
| 83 | #endif |