| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "SkTypes.h" | 8 #include "SkTypes.h" |
| 9 | 9 |
| 10 #if SK_SUPPORT_GPU | 10 #if SK_SUPPORT_GPU |
| 11 | 11 |
| 12 #include "GrContext.h" | 12 #include "GrContext.h" |
| 13 #include "GrContextFactory.h" | 13 #include "GrContextFactory.h" |
| 14 #include "SkBitmap.h" | 14 #include "SkBitmap.h" |
| 15 #include "SkCanvas.h" | 15 #include "SkCanvas.h" |
| 16 #include "SkColor.h" | 16 #include "SkColor.h" |
| 17 #include "SkPaint.h" | 17 #include "SkPaint.h" |
| 18 #include "SkPath.h" | |
| 19 #include "SkDashPathEffect.h" | |
| 20 #include "SkRRect.h" | 18 #include "SkRRect.h" |
| 21 #include "SkRect.h" | 19 #include "SkRect.h" |
| 22 #include "SkSurface.h" | 20 #include "SkSurface.h" |
| 23 #include "Test.h" | 21 #include "Test.h" |
| 24 | 22 |
| 25 static void test_drawPathEmpty(skiatest::Reporter*, SkCanvas* canvas) { | 23 static void test_drawPathEmpty(skiatest::Reporter*, SkCanvas* canvas) { |
| 26 // Filling an empty path should not crash. | 24 // Filling an empty path should not crash. |
| 27 SkPaint paint; | 25 SkPaint paint; |
| 28 SkRect emptyRect = SkRect::MakeEmpty(); | 26 canvas->drawRect(SkRect(), paint); |
| 29 canvas->drawRect(emptyRect, paint); | |
| 30 canvas->drawPath(SkPath(), paint); | 27 canvas->drawPath(SkPath(), paint); |
| 31 canvas->drawOval(emptyRect, paint); | 28 canvas->drawOval(SkRect(), paint); |
| 32 canvas->drawRect(emptyRect, paint); | 29 canvas->drawRect(SkRect(), paint); |
| 33 canvas->drawRRect(SkRRect::MakeRect(emptyRect), paint); | 30 canvas->drawRRect(SkRRect(), paint); |
| 34 | 31 |
| 35 // Stroking an empty path should not crash. | 32 // Stroking an empty path should not crash. |
| 36 paint.setAntiAlias(true); | 33 paint.setAntiAlias(true); |
| 37 paint.setStyle(SkPaint::kStroke_Style); | 34 paint.setStyle(SkPaint::kStroke_Style); |
| 38 paint.setColor(SK_ColorGRAY); | 35 paint.setColor(SK_ColorGRAY); |
| 39 paint.setStrokeWidth(SkIntToScalar(20)); | 36 paint.setStrokeWidth(SkIntToScalar(20)); |
| 40 paint.setStrokeJoin(SkPaint::kRound_Join); | 37 paint.setStrokeJoin(SkPaint::kRound_Join); |
| 41 canvas->drawRect(emptyRect, paint); | 38 canvas->drawRect(SkRect(), paint); |
| 42 canvas->drawPath(SkPath(), paint); | 39 canvas->drawPath(SkPath(), paint); |
| 43 canvas->drawOval(emptyRect, paint); | 40 canvas->drawOval(SkRect(), paint); |
| 44 canvas->drawRect(emptyRect, paint); | 41 canvas->drawRect(SkRect(), paint); |
| 45 canvas->drawRRect(SkRRect::MakeRect(emptyRect), paint); | 42 canvas->drawRRect(SkRRect(), paint); |
| 46 } | 43 } |
| 47 | 44 |
| 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 c
rash. | |
| 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 } | |
| 76 | 45 |
| 77 DEF_GPUTEST(GpuDrawPath, reporter, factory) { | 46 DEF_GPUTEST(GpuDrawPath, reporter, factory) { |
| 47 return; |
| 48 |
| 78 for (int type = 0; type < GrContextFactory::kLastGLContextType; ++type) { | 49 for (int type = 0; type < GrContextFactory::kLastGLContextType; ++type) { |
| 79 GrContextFactory::GLContextType glType = static_cast<GrContextFactory::G
LContextType>(type); | 50 GrContextFactory::GLContextType glType = static_cast<GrContextFactory::G
LContextType>(type); |
| 80 | 51 |
| 81 GrContext* grContext = factory->get(glType); | 52 GrContext* grContext = factory->get(glType); |
| 82 if (nullptr == grContext) { | 53 if (nullptr == grContext) { |
| 83 continue; | 54 continue; |
| 84 } | 55 } |
| 85 static const int sampleCounts[] = { 0, 4, 16 }; | 56 static const int sampleCounts[] = { 0, 4, 16 }; |
| 86 | 57 |
| 87 for (size_t i = 0; i < SK_ARRAY_COUNT(sampleCounts); ++i) { | 58 for (size_t i = 0; i < SK_ARRAY_COUNT(sampleCounts); ++i) { |
| 88 SkImageInfo info = SkImageInfo::MakeN32Premul(255, 255); | 59 SkImageInfo info = SkImageInfo::MakeN32Premul(255, 255); |
| 89 | 60 |
| 90 SkAutoTUnref<SkSurface> surface( | 61 SkAutoTUnref<SkSurface> surface( |
| 91 SkSurface::NewRenderTarget(grContext, SkSurface::kNo_Budgeted, i
nfo, | 62 SkSurface::NewRenderTarget(grContext, SkSurface::kNo_Budgeted, i
nfo, |
| 92 sampleCounts[i], nullptr)); | 63 sampleCounts[i], nullptr)); |
| 93 test_drawPathEmpty(reporter, surface->getCanvas()); | 64 test_drawPathEmpty(reporter, surface->getCanvas()); |
| 94 test_drawSameRectOvals(reporter, surface->getCanvas()); | |
| 95 } | 65 } |
| 96 } | 66 } |
| 97 } | 67 } |
| 98 | 68 |
| 99 #endif | 69 #endif |
| OLD | NEW |