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