commit-bot@chromium.org | 19dd017 | 2013-08-05 13:28:55 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2013 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 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 8 | #include "SkTypes.h" |
| 9 | |
commit-bot@chromium.org | 19dd017 | 2013-08-05 13:28:55 +0000 | [diff] [blame] | 10 | #if SK_SUPPORT_GPU |
| 11 | |
| 12 | #include "GrContext.h" |
| 13 | #include "GrContextFactory.h" |
fmalita | 3b44448 | 2015-11-19 07:28:50 -0800 | [diff] [blame^] | 14 | #include "GrPath.h" |
| 15 | #include "GrStrokeInfo.h" |
commit-bot@chromium.org | 19dd017 | 2013-08-05 13:28:55 +0000 | [diff] [blame] | 16 | #include "SkBitmap.h" |
| 17 | #include "SkCanvas.h" |
| 18 | #include "SkColor.h" |
commit-bot@chromium.org | 19dd017 | 2013-08-05 13:28:55 +0000 | [diff] [blame] | 19 | #include "SkPaint.h" |
fmalita | fbe1c11 | 2015-11-18 20:12:56 -0800 | [diff] [blame] | 20 | #include "SkPath.h" |
| 21 | #include "SkDashPathEffect.h" |
commit-bot@chromium.org | 19dd017 | 2013-08-05 13:28:55 +0000 | [diff] [blame] | 22 | #include "SkRRect.h" |
tfarina@chromium.org | 8f6884a | 2014-01-24 20:56:26 +0000 | [diff] [blame] | 23 | #include "SkRect.h" |
reed | 69f6f00 | 2014-09-18 06:09:44 -0700 | [diff] [blame] | 24 | #include "SkSurface.h" |
commit-bot@chromium.org | 19dd017 | 2013-08-05 13:28:55 +0000 | [diff] [blame] | 25 | #include "Test.h" |
| 26 | |
tfarina@chromium.org | 4ee16bf | 2014-01-10 22:08:27 +0000 | [diff] [blame] | 27 | static void test_drawPathEmpty(skiatest::Reporter*, SkCanvas* canvas) { |
commit-bot@chromium.org | 19dd017 | 2013-08-05 13:28:55 +0000 | [diff] [blame] | 28 | // Filling an empty path should not crash. |
| 29 | SkPaint paint; |
fmalita | fbe1c11 | 2015-11-18 20:12:56 -0800 | [diff] [blame] | 30 | SkRect emptyRect = SkRect::MakeEmpty(); |
| 31 | canvas->drawRect(emptyRect, paint); |
commit-bot@chromium.org | 19dd017 | 2013-08-05 13:28:55 +0000 | [diff] [blame] | 32 | canvas->drawPath(SkPath(), paint); |
fmalita | fbe1c11 | 2015-11-18 20:12:56 -0800 | [diff] [blame] | 33 | canvas->drawOval(emptyRect, paint); |
| 34 | canvas->drawRect(emptyRect, paint); |
| 35 | canvas->drawRRect(SkRRect::MakeRect(emptyRect), paint); |
commit-bot@chromium.org | 19dd017 | 2013-08-05 13:28:55 +0000 | [diff] [blame] | 36 | |
| 37 | // Stroking an empty path should not crash. |
| 38 | paint.setAntiAlias(true); |
| 39 | paint.setStyle(SkPaint::kStroke_Style); |
| 40 | paint.setColor(SK_ColorGRAY); |
| 41 | paint.setStrokeWidth(SkIntToScalar(20)); |
| 42 | paint.setStrokeJoin(SkPaint::kRound_Join); |
fmalita | fbe1c11 | 2015-11-18 20:12:56 -0800 | [diff] [blame] | 43 | canvas->drawRect(emptyRect, paint); |
commit-bot@chromium.org | 19dd017 | 2013-08-05 13:28:55 +0000 | [diff] [blame] | 44 | canvas->drawPath(SkPath(), paint); |
fmalita | fbe1c11 | 2015-11-18 20:12:56 -0800 | [diff] [blame] | 45 | canvas->drawOval(emptyRect, paint); |
| 46 | canvas->drawRect(emptyRect, paint); |
| 47 | canvas->drawRRect(SkRRect::MakeRect(emptyRect), paint); |
commit-bot@chromium.org | 19dd017 | 2013-08-05 13:28:55 +0000 | [diff] [blame] | 48 | } |
| 49 | |
fmalita | fbe1c11 | 2015-11-18 20:12:56 -0800 | [diff] [blame] | 50 | static void fill_and_stroke(SkCanvas* canvas, const SkPath& p1, const SkPath& p2, |
| 51 | SkPathEffect* effect) { |
| 52 | SkPaint paint; |
| 53 | paint.setAntiAlias(true); |
| 54 | paint.setPathEffect(effect); |
| 55 | |
| 56 | canvas->drawPath(p1, paint); |
| 57 | canvas->drawPath(p2, paint); |
| 58 | |
| 59 | paint.setStyle(SkPaint::kStroke_Style); |
| 60 | canvas->drawPath(p1, paint); |
| 61 | canvas->drawPath(p2, paint); |
| 62 | } |
| 63 | |
| 64 | static void test_drawSameRectOvals(skiatest::Reporter*, SkCanvas* canvas) { |
| 65 | // Drawing ovals with similar bounds but different points order should not crash. |
| 66 | |
| 67 | SkPath oval1, oval2; |
| 68 | const SkRect rect = SkRect::MakeWH(100, 50); |
| 69 | oval1.addOval(rect, SkPath::kCW_Direction); |
| 70 | oval2.addOval(rect, SkPath::kCCW_Direction); |
| 71 | |
| 72 | fill_and_stroke(canvas, oval1, oval2, nullptr); |
| 73 | |
| 74 | const SkScalar intervals[] = { 1, 1 }; |
| 75 | SkAutoTUnref<SkPathEffect> dashEffect(SkDashPathEffect::Create(intervals, 2, 0)); |
| 76 | fill_and_stroke(canvas, oval1, oval2, dashEffect); |
| 77 | } |
commit-bot@chromium.org | 19dd017 | 2013-08-05 13:28:55 +0000 | [diff] [blame] | 78 | |
tfarina@chromium.org | 4ee16bf | 2014-01-10 22:08:27 +0000 | [diff] [blame] | 79 | DEF_GPUTEST(GpuDrawPath, reporter, factory) { |
fmalita | fbe1c11 | 2015-11-18 20:12:56 -0800 | [diff] [blame] | 80 | // https://bugs.chromium.org/p/skia/issues/detail?id=4581 |
stephana | 1ac3f40 | 2015-11-18 18:35:56 -0800 | [diff] [blame] | 81 | return; |
| 82 | |
commit-bot@chromium.org | 19dd017 | 2013-08-05 13:28:55 +0000 | [diff] [blame] | 83 | for (int type = 0; type < GrContextFactory::kLastGLContextType; ++type) { |
| 84 | GrContextFactory::GLContextType glType = static_cast<GrContextFactory::GLContextType>(type); |
| 85 | |
| 86 | GrContext* grContext = factory->get(glType); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 87 | if (nullptr == grContext) { |
commit-bot@chromium.org | 19dd017 | 2013-08-05 13:28:55 +0000 | [diff] [blame] | 88 | continue; |
| 89 | } |
| 90 | static const int sampleCounts[] = { 0, 4, 16 }; |
| 91 | |
| 92 | for (size_t i = 0; i < SK_ARRAY_COUNT(sampleCounts); ++i) { |
reed | 69f6f00 | 2014-09-18 06:09:44 -0700 | [diff] [blame] | 93 | SkImageInfo info = SkImageInfo::MakeN32Premul(255, 255); |
| 94 | |
bsalomon | afe3005 | 2015-01-16 07:32:33 -0800 | [diff] [blame] | 95 | SkAutoTUnref<SkSurface> surface( |
| 96 | SkSurface::NewRenderTarget(grContext, SkSurface::kNo_Budgeted, info, |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 97 | sampleCounts[i], nullptr)); |
reed | 69f6f00 | 2014-09-18 06:09:44 -0700 | [diff] [blame] | 98 | test_drawPathEmpty(reporter, surface->getCanvas()); |
commit-bot@chromium.org | 19dd017 | 2013-08-05 13:28:55 +0000 | [diff] [blame] | 99 | } |
| 100 | } |
| 101 | } |
| 102 | |
fmalita | fbe1c11 | 2015-11-18 20:12:56 -0800 | [diff] [blame] | 103 | DEF_GPUTEST(GpuDrawPathSameRectOvals, reporter, factory) { |
| 104 | GrContext* grContext = factory->get(GrContextFactory::kNVPR_GLContextType); |
| 105 | if (!grContext) { |
| 106 | return; |
| 107 | } |
| 108 | |
| 109 | SkAutoTUnref<SkSurface> surface( |
| 110 | SkSurface::NewRenderTarget(grContext, SkSurface::kNo_Budgeted, |
| 111 | SkImageInfo::MakeN32Premul(255, 255), 4)); |
| 112 | test_drawSameRectOvals(reporter, surface->getCanvas()); |
| 113 | } |
| 114 | |
fmalita | 3b44448 | 2015-11-19 07:28:50 -0800 | [diff] [blame^] | 115 | DEF_TEST(GrPathKeys, reporter) { |
| 116 | // Keys should not ignore conic weights. |
| 117 | SkPath path1, path2; |
| 118 | path1.setIsVolatile(true); |
| 119 | path2.setIsVolatile(true); |
| 120 | SkPoint p0 = SkPoint::Make(100, 0); |
| 121 | SkPoint p1 = SkPoint::Make(100, 100); |
| 122 | |
| 123 | path1.conicTo(p0, p1, .5f); |
| 124 | path2.conicTo(p0, p1, .7f); |
| 125 | |
| 126 | bool isVolatile; |
| 127 | GrUniqueKey key1, key2; |
| 128 | GrStrokeInfo stroke(SkStrokeRec::kFill_InitStyle); |
| 129 | GrPath::ComputeKey(path1, stroke, &key1, &isVolatile); |
| 130 | GrPath::ComputeKey(path2, stroke, &key2, &isVolatile); |
| 131 | |
| 132 | // https://bugs.chromium.org/p/skia/issues/detail?id=4580 |
| 133 | // REPORTER_ASSERT(reporter, key1 != key2); |
| 134 | } |
| 135 | |
commit-bot@chromium.org | 19dd017 | 2013-08-05 13:28:55 +0000 | [diff] [blame] | 136 | #endif |