blob: ced13f3ac59e62ad3bef63b1a082240bb01a9ad2 [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
Jim Van Verthc9f4b8c2017-02-16 11:44:52 -050016#if 0
bsalomon6d6b6ad2016-07-13 14:45:28 -070017// 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 Phillips77505da2017-01-20 09:11:37 -050021static void test_far_from_origin(GrResourceProvider* rp,
22 GrRenderTargetContext* renderTargetContext,
23 GrPathRenderer* pr) {
bsalomon6d6b6ad2016-07-13 14:45:28 -070024 SkPath path;
25 path.lineTo(49.0255089839f, 0.473541f);
bsalomon0ae36a22016-07-18 07:31:13 -070026 // 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);
bsalomon6d6b6ad2016-07-13 14:45:28 -070029 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 Salomona1633922017-01-09 11:46:10 -050047 paint.setXPFactory(GrPorterDuffXPFactory::Get(SkBlendMode::kSrc));
bsalomon6d6b6ad2016-07-13 14:45:28 -070048
49 GrNoClip noClip;
Brian Salomon82f44312017-01-11 13:42:54 -050050 GrPathRenderer::DrawPathArgs args{rp,
51 std::move(paint),
52 &GrUserStencilSettings::kUnused,
53 renderTargetContext,
54 &noClip,
55 &matrix,
56 &shape,
57 GrAAType::kCoverage,
58 false};
bsalomon6d6b6ad2016-07-13 14:45:28 -070059 pr->drawPath(args);
60}
61
62DEF_GPUTEST_FOR_ALL_GL_CONTEXTS(AADistanceFieldPathRenderer, reporter, ctxInfo) {
Robert Phillips77505da2017-01-20 09:11:37 -050063 GrContext* ctx = ctxInfo.grContext();
bsalomon6d6b6ad2016-07-13 14:45:28 -070064 // The DF PR only works with contexts that support derivatives
Robert Phillips77505da2017-01-20 09:11:37 -050065 if (!ctx->caps()->shaderCaps()->shaderDerivativeSupport()) {
bsalomon6d6b6ad2016-07-13 14:45:28 -070066 return;
67 }
Robert Phillips77505da2017-01-20 09:11:37 -050068 sk_sp<GrRenderTargetContext> rtc(ctx->makeRenderTargetContext(SkBackingFit::kApprox,
69 800, 800,
70 kRGBA_8888_GrPixelConfig,
71 nullptr,
72 0,
73 kTopLeft_GrSurfaceOrigin));
Brian Osman11052242016-10-27 14:47:55 -040074 if (!rtc) {
bsalomon6d6b6ad2016-07-13 14:45:28 -070075 return;
76 }
77
78 GrAADistanceFieldPathRenderer dfpr;
bsalomon6d6b6ad2016-07-13 14:45:28 -070079
Robert Phillips77505da2017-01-20 09:11:37 -050080 ctx->flush();
81 test_far_from_origin(ctx->resourceProvider(), rtc.get(), &dfpr);
82 ctx->flush();
bsalomon6d6b6ad2016-07-13 14:45:28 -070083}
84#endif
Jim Van Verthc9f4b8c2017-02-16 11:44:52 -050085#endif