blob: e4d87a20493247b24cc22fba1167dda9e1d2914a [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
Robert Phillips77505da2017-01-20 09:11:37 -050010#include "SkPath.h"
11
bsalomon6d6b6ad2016-07-13 14:45:28 -070012#if SK_SUPPORT_GPU
13#include "GrContext.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.
Robert Phillips77505da2017-01-20 09:11:37 -050020static void test_far_from_origin(GrResourceProvider* rp,
21 GrRenderTargetContext* renderTargetContext,
22 GrPathRenderer* pr) {
bsalomon6d6b6ad2016-07-13 14:45:28 -070023 SkPath path;
24 path.lineTo(49.0255089839f, 0.473541f);
bsalomon0ae36a22016-07-18 07:31:13 -070025 // 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);
bsalomon6d6b6ad2016-07-13 14:45:28 -070028 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 Salomona1633922017-01-09 11:46:10 -050046 paint.setXPFactory(GrPorterDuffXPFactory::Get(SkBlendMode::kSrc));
bsalomon6d6b6ad2016-07-13 14:45:28 -070047
48 GrNoClip noClip;
Brian Salomon82f44312017-01-11 13:42:54 -050049 GrPathRenderer::DrawPathArgs args{rp,
50 std::move(paint),
51 &GrUserStencilSettings::kUnused,
52 renderTargetContext,
53 &noClip,
54 &matrix,
55 &shape,
56 GrAAType::kCoverage,
57 false};
bsalomon6d6b6ad2016-07-13 14:45:28 -070058 pr->drawPath(args);
59}
60
61DEF_GPUTEST_FOR_ALL_GL_CONTEXTS(AADistanceFieldPathRenderer, reporter, ctxInfo) {
Robert Phillips77505da2017-01-20 09:11:37 -050062 GrContext* ctx = ctxInfo.grContext();
bsalomon6d6b6ad2016-07-13 14:45:28 -070063 // The DF PR only works with contexts that support derivatives
Robert Phillips77505da2017-01-20 09:11:37 -050064 if (!ctx->caps()->shaderCaps()->shaderDerivativeSupport()) {
bsalomon6d6b6ad2016-07-13 14:45:28 -070065 return;
66 }
Robert Phillips77505da2017-01-20 09:11:37 -050067 sk_sp<GrRenderTargetContext> rtc(ctx->makeRenderTargetContext(SkBackingFit::kApprox,
68 800, 800,
69 kRGBA_8888_GrPixelConfig,
70 nullptr,
71 0,
72 kTopLeft_GrSurfaceOrigin));
Brian Osman11052242016-10-27 14:47:55 -040073 if (!rtc) {
bsalomon6d6b6ad2016-07-13 14:45:28 -070074 return;
75 }
76
77 GrAADistanceFieldPathRenderer dfpr;
bsalomon6d6b6ad2016-07-13 14:45:28 -070078
Robert Phillips77505da2017-01-20 09:11:37 -050079 ctx->flush();
80 test_far_from_origin(ctx->resourceProvider(), rtc.get(), &dfpr);
81 ctx->flush();
bsalomon6d6b6ad2016-07-13 14:45:28 -070082}
83#endif