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 | |
Jim Van Verth | c9f4b8c | 2017-02-16 11:44:52 -0500 | [diff] [blame^] | 16 | #if 0 |
bsalomon | 6d6b6ad | 2016-07-13 14:45:28 -0700 | [diff] [blame] | 17 | // This test case including path coords and matrix taken from crbug.com/627443. |
| 18 | // Because of inaccuracies in large floating point values this causes the |
| 19 | // the path renderer to attempt to add a path DF to its atlas that is larger |
| 20 | // than the plot size which used to crash rather than fail gracefully. |
Robert Phillips | 77505da | 2017-01-20 09:11:37 -0500 | [diff] [blame] | 21 | static void test_far_from_origin(GrResourceProvider* rp, |
| 22 | GrRenderTargetContext* renderTargetContext, |
| 23 | GrPathRenderer* pr) { |
bsalomon | 6d6b6ad | 2016-07-13 14:45:28 -0700 | [diff] [blame] | 24 | SkPath path; |
| 25 | path.lineTo(49.0255089839f, 0.473541f); |
bsalomon | 0ae36a2 | 2016-07-18 07:31:13 -0700 | [diff] [blame] | 26 | // This extra line wasn't in the original bug but was added to fake out GrShape's special |
| 27 | // handling of single line segments. |
| 28 | path.rLineTo(0.015f, 0.015f); |
bsalomon | 6d6b6ad | 2016-07-13 14:45:28 -0700 | [diff] [blame] | 29 | static constexpr SkScalar mvals[] = {14.0348252854f, 2.13026182736f, |
| 30 | 13.6122547187f, 118.309922702f, |
| 31 | 1912337682.09f, 2105391889.87f}; |
| 32 | SkMatrix matrix; |
| 33 | matrix.setAffine(mvals); |
| 34 | SkMatrix inverse; |
| 35 | SkAssertResult(matrix.invert(&inverse)); |
| 36 | path.transform(inverse); |
| 37 | |
| 38 | SkStrokeRec rec(SkStrokeRec::kFill_InitStyle); |
| 39 | rec.setStrokeStyle(1.f); |
| 40 | rec.setStrokeParams(SkPaint::kRound_Cap, SkPaint::kRound_Join, 1.f); |
| 41 | GrStyle style(rec, nullptr); |
| 42 | |
| 43 | GrShape shape(path, style); |
| 44 | shape = shape.applyStyle(GrStyle::Apply::kPathEffectAndStrokeRec, 1.f); |
| 45 | |
| 46 | GrPaint paint; |
Brian Salomon | a163392 | 2017-01-09 11:46:10 -0500 | [diff] [blame] | 47 | paint.setXPFactory(GrPorterDuffXPFactory::Get(SkBlendMode::kSrc)); |
bsalomon | 6d6b6ad | 2016-07-13 14:45:28 -0700 | [diff] [blame] | 48 | |
| 49 | GrNoClip noClip; |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 50 | GrPathRenderer::DrawPathArgs args{rp, |
| 51 | std::move(paint), |
| 52 | &GrUserStencilSettings::kUnused, |
| 53 | renderTargetContext, |
| 54 | &noClip, |
| 55 | &matrix, |
| 56 | &shape, |
| 57 | GrAAType::kCoverage, |
| 58 | false}; |
bsalomon | 6d6b6ad | 2016-07-13 14:45:28 -0700 | [diff] [blame] | 59 | pr->drawPath(args); |
| 60 | } |
| 61 | |
| 62 | DEF_GPUTEST_FOR_ALL_GL_CONTEXTS(AADistanceFieldPathRenderer, reporter, ctxInfo) { |
Robert Phillips | 77505da | 2017-01-20 09:11:37 -0500 | [diff] [blame] | 63 | GrContext* ctx = ctxInfo.grContext(); |
bsalomon | 6d6b6ad | 2016-07-13 14:45:28 -0700 | [diff] [blame] | 64 | // The DF PR only works with contexts that support derivatives |
Robert Phillips | 77505da | 2017-01-20 09:11:37 -0500 | [diff] [blame] | 65 | if (!ctx->caps()->shaderCaps()->shaderDerivativeSupport()) { |
bsalomon | 6d6b6ad | 2016-07-13 14:45:28 -0700 | [diff] [blame] | 66 | return; |
| 67 | } |
Robert Phillips | 77505da | 2017-01-20 09:11:37 -0500 | [diff] [blame] | 68 | sk_sp<GrRenderTargetContext> rtc(ctx->makeRenderTargetContext(SkBackingFit::kApprox, |
| 69 | 800, 800, |
| 70 | kRGBA_8888_GrPixelConfig, |
| 71 | nullptr, |
| 72 | 0, |
| 73 | kTopLeft_GrSurfaceOrigin)); |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 74 | if (!rtc) { |
bsalomon | 6d6b6ad | 2016-07-13 14:45:28 -0700 | [diff] [blame] | 75 | return; |
| 76 | } |
| 77 | |
| 78 | GrAADistanceFieldPathRenderer dfpr; |
bsalomon | 6d6b6ad | 2016-07-13 14:45:28 -0700 | [diff] [blame] | 79 | |
Robert Phillips | 77505da | 2017-01-20 09:11:37 -0500 | [diff] [blame] | 80 | ctx->flush(); |
| 81 | test_far_from_origin(ctx->resourceProvider(), rtc.get(), &dfpr); |
| 82 | ctx->flush(); |
bsalomon | 6d6b6ad | 2016-07-13 14:45:28 -0700 | [diff] [blame] | 83 | } |
| 84 | #endif |
Jim Van Verth | c9f4b8c | 2017-02-16 11:44:52 -0500 | [diff] [blame^] | 85 | #endif |