| reed@google.com | dceecc7 | 2012-02-23 19:20:19 +0000 | [diff] [blame] | 1 | /* | 
|  | 2 | * Copyright 2012 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 | #include "SkBitmap.h" | 
|  | 10 | #include "SkCanvas.h" | 
| reed@google.com | 1df888b | 2012-04-24 22:47:21 +0000 | [diff] [blame] | 11 | #include "SkDashPathEffect.h" | 
| reed@google.com | dceecc7 | 2012-02-23 19:20:19 +0000 | [diff] [blame] | 12 |  | 
|  | 13 | static SkCanvas* create(SkBitmap::Config config, int w, int h, int rb, | 
|  | 14 | void* addr = NULL) { | 
|  | 15 | SkBitmap bm; | 
|  | 16 | bm.setConfig(config, w, h, rb); | 
|  | 17 | if (addr) { | 
|  | 18 | bm.setPixels(addr); | 
|  | 19 | } else { | 
|  | 20 | bm.allocPixels(); | 
|  | 21 | } | 
|  | 22 | return new SkCanvas(bm); | 
|  | 23 | } | 
|  | 24 |  | 
| mike@reedtribe.org | 6093e65 | 2012-04-14 12:55:17 +0000 | [diff] [blame] | 25 | static SkCanvas* new_canvas(int w, int h) { | 
|  | 26 | return create(SkBitmap::kARGB_8888_Config, w, h, 0, NULL); | 
|  | 27 | } | 
|  | 28 |  | 
| reed@google.com | a90aa53 | 2012-04-16 16:27:09 +0000 | [diff] [blame] | 29 | /////////////////////////////////////////////////////////////////////////////// | 
|  | 30 |  | 
| reed@google.com | 9d5f76a | 2012-05-01 14:49:28 +0000 | [diff] [blame^] | 31 | // Need to exercise drawing an inverse-path whose bounds intersect the clip, | 
|  | 32 | // but whose edges do not (since its a quad which draws only in the bottom half | 
|  | 33 | // of its bounds). | 
|  | 34 | // In the debug build, we used to assert in this case, until it was fixed. | 
|  | 35 | // | 
|  | 36 | static void test_inversepathwithclip(skiatest::Reporter* reporter) { | 
|  | 37 | SkPath path; | 
|  | 38 |  | 
|  | 39 | path.moveTo(0, SkIntToScalar(20)); | 
|  | 40 | path.quadTo(SkIntToScalar(10), SkIntToScalar(10), | 
|  | 41 | SkIntToScalar(20), SkIntToScalar(20)); | 
|  | 42 | path.toggleInverseFillType(); | 
|  | 43 |  | 
|  | 44 | SkPaint paint; | 
|  | 45 |  | 
|  | 46 | SkAutoTUnref<SkCanvas> canvas(new_canvas(640, 480)); | 
|  | 47 | canvas.get()->save(); | 
|  | 48 | canvas.get()->clipRect(SkRect::MakeWH(SkIntToScalar(19), SkIntToScalar(11))); | 
|  | 49 |  | 
|  | 50 | paint.setAntiAlias(false); | 
|  | 51 | canvas.get()->drawPath(path, paint); | 
|  | 52 | paint.setAntiAlias(true); | 
|  | 53 | canvas.get()->drawPath(path, paint); | 
|  | 54 |  | 
|  | 55 | canvas.get()->restore(); | 
|  | 56 |  | 
|  | 57 | // Now do the test again, with the path flipped, so we only draw in the | 
|  | 58 | // top half of our bounds, and have the clip intersect our bounds at the | 
|  | 59 | // bottom. | 
|  | 60 | path.reset();   // preserves our filltype | 
|  | 61 | path.moveTo(0, SkIntToScalar(10)); | 
|  | 62 | path.quadTo(SkIntToScalar(10), SkIntToScalar(20), | 
|  | 63 | SkIntToScalar(20), SkIntToScalar(10)); | 
|  | 64 | canvas.get()->clipRect(SkRect::MakeXYWH(SkIntToScalar(0), SkIntToScalar(19), | 
|  | 65 | SkIntToScalar(19), SkIntToScalar(11))); | 
|  | 66 |  | 
|  | 67 | paint.setAntiAlias(false); | 
|  | 68 | canvas.get()->drawPath(path, paint); | 
|  | 69 | paint.setAntiAlias(true); | 
|  | 70 | canvas.get()->drawPath(path, paint); | 
|  | 71 | } | 
|  | 72 |  | 
| mike@reedtribe.org | 6093e65 | 2012-04-14 12:55:17 +0000 | [diff] [blame] | 73 | static void test_bug533(skiatest::Reporter* reporter) { | 
|  | 74 | #ifdef SK_SCALAR_IS_FLOAT | 
|  | 75 | /* | 
|  | 76 | http://code.google.com/p/skia/issues/detail?id=533 | 
|  | 77 | This particular test/bug only applies to the float case, where the | 
|  | 78 | coordinates are very large. | 
|  | 79 | */ | 
|  | 80 | SkPath path; | 
|  | 81 | path.moveTo(64, 3); | 
|  | 82 | path.quadTo(-329936, -100000000, 1153, 330003); | 
|  | 83 |  | 
|  | 84 | SkPaint paint; | 
|  | 85 | paint.setAntiAlias(true); | 
|  | 86 |  | 
|  | 87 | SkAutoTUnref<SkCanvas> canvas(new_canvas(640, 480)); | 
|  | 88 | canvas.get()->drawPath(path, paint); | 
|  | 89 | #endif | 
|  | 90 | } | 
|  | 91 |  | 
| reed@google.com | 1df888b | 2012-04-24 22:47:21 +0000 | [diff] [blame] | 92 | static void test_crbug_124652(skiatest::Reporter* reporter) { | 
|  | 93 | #ifdef SK_SCALAR_IS_FLOAT | 
|  | 94 | /* | 
|  | 95 | http://code.google.com/p/chromium/issues/detail?id=124652 | 
|  | 96 | This particular test/bug only applies to the float case, where | 
|  | 97 | large values can "swamp" small ones. | 
|  | 98 | */ | 
|  | 99 | SkScalar intervals[2] = {837099584, 33450}; | 
|  | 100 | SkAutoTUnref<SkDashPathEffect> dash( | 
|  | 101 | new SkDashPathEffect(intervals, 2, -10, false)); | 
|  | 102 | #endif | 
|  | 103 | } | 
|  | 104 |  | 
| reed@google.com | a90aa53 | 2012-04-16 16:27:09 +0000 | [diff] [blame] | 105 | static void test_bigcubic(skiatest::Reporter* reporter) { | 
|  | 106 | #ifdef SK_SCALAR_IS_FLOAT | 
|  | 107 | SkPath path; | 
|  | 108 | path.moveTo(64, 3); | 
|  | 109 | path.cubicTo(-329936, -100000000, -329936, 100000000, 1153, 330003); | 
|  | 110 |  | 
|  | 111 | SkPaint paint; | 
|  | 112 | paint.setAntiAlias(true); | 
|  | 113 |  | 
|  | 114 | SkAutoTUnref<SkCanvas> canvas(new_canvas(640, 480)); | 
|  | 115 | canvas.get()->drawPath(path, paint); | 
|  | 116 | #endif | 
|  | 117 | } | 
|  | 118 |  | 
| reed@google.com | dceecc7 | 2012-02-23 19:20:19 +0000 | [diff] [blame] | 119 | // we used to assert if the bounds of the device (clip) was larger than 32K | 
|  | 120 | // even when the path itself was smaller. We just draw and hope in the debug | 
|  | 121 | // version to not assert. | 
|  | 122 | static void test_giantaa(skiatest::Reporter* reporter) { | 
|  | 123 | const int W = 400; | 
|  | 124 | const int H = 400; | 
| mike@reedtribe.org | 6093e65 | 2012-04-14 12:55:17 +0000 | [diff] [blame] | 125 | SkAutoTUnref<SkCanvas> canvas(new_canvas(33000, 10)); | 
|  | 126 | canvas.get()->clear(0); | 
| reed@google.com | dceecc7 | 2012-02-23 19:20:19 +0000 | [diff] [blame] | 127 |  | 
|  | 128 | SkPaint paint; | 
|  | 129 | paint.setAntiAlias(true); | 
|  | 130 | SkPath path; | 
|  | 131 | path.addOval(SkRect::MakeXYWH(-10, -10, 20 + W, 20 + H)); | 
| mike@reedtribe.org | 6093e65 | 2012-04-14 12:55:17 +0000 | [diff] [blame] | 132 | canvas.get()->drawPath(path, paint); | 
| reed@google.com | dceecc7 | 2012-02-23 19:20:19 +0000 | [diff] [blame] | 133 | } | 
|  | 134 |  | 
|  | 135 | static void TestDrawPath(skiatest::Reporter* reporter) { | 
|  | 136 | test_giantaa(reporter); | 
| mike@reedtribe.org | 6093e65 | 2012-04-14 12:55:17 +0000 | [diff] [blame] | 137 | test_bug533(reporter); | 
| reed@google.com | a90aa53 | 2012-04-16 16:27:09 +0000 | [diff] [blame] | 138 | test_bigcubic(reporter); | 
| reed@google.com | 1df888b | 2012-04-24 22:47:21 +0000 | [diff] [blame] | 139 | test_crbug_124652(reporter); | 
| reed@google.com | 9d5f76a | 2012-05-01 14:49:28 +0000 | [diff] [blame^] | 140 | test_inversepathwithclip(reporter); | 
| reed@google.com | dceecc7 | 2012-02-23 19:20:19 +0000 | [diff] [blame] | 141 | } | 
|  | 142 |  | 
|  | 143 | #include "TestClassDef.h" | 
|  | 144 | DEFINE_TESTCLASS("DrawPath", TestDrawPathClass, TestDrawPath) |