blob: 653db822f92cf01f15a9d1795d8a90baf78b840b [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"
Jim Van Verth83010462017-03-16 08:45:39 -040014#include "ops/GrSmallPathRenderer.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 Phillips256c37b2017-03-01 14:32:46 -050021static void test_far_from_origin(GrContext* ctx, GrRenderTargetContext* renderTargetContext,
Robert Phillips77505da2017-01-20 09:11:37 -050022 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;
Robert Phillips256c37b2017-03-01 14:32:46 -050049 GrPathRenderer::DrawPathArgs args{ctx,
Brian Salomon82f44312017-01-11 13:42:54 -050050 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
Jim Van Verth83010462017-03-16 08:45:39 -040061DEF_GPUTEST_FOR_ALL_GL_CONTEXTS(SmallPathRenderer, 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
Jim Van Verth83010462017-03-16 08:45:39 -040077 GrSmallPathRenderer spr;
bsalomon6d6b6ad2016-07-13 14:45:28 -070078
Robert Phillips77505da2017-01-20 09:11:37 -050079 ctx->flush();
Jim Van Verth83010462017-03-16 08:45:39 -040080 test_far_from_origin(ctx, rtc.get(), &spr);
Robert Phillips77505da2017-01-20 09:11:37 -050081 ctx->flush();
bsalomon6d6b6ad2016-07-13 14:45:28 -070082}
83#endif
Jim Van Verthc9f4b8c2017-02-16 11:44:52 -050084#endif