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 | |
mike@reedtribe.org | 6093e65 | 2012-04-14 12:55:17 +0000 | [diff] [blame] | 31 | static void test_bug533(skiatest::Reporter* reporter) { |
| 32 | #ifdef SK_SCALAR_IS_FLOAT |
| 33 | /* |
| 34 | http://code.google.com/p/skia/issues/detail?id=533 |
| 35 | This particular test/bug only applies to the float case, where the |
| 36 | coordinates are very large. |
| 37 | */ |
| 38 | SkPath path; |
| 39 | path.moveTo(64, 3); |
| 40 | path.quadTo(-329936, -100000000, 1153, 330003); |
| 41 | |
| 42 | SkPaint paint; |
| 43 | paint.setAntiAlias(true); |
| 44 | |
| 45 | SkAutoTUnref<SkCanvas> canvas(new_canvas(640, 480)); |
| 46 | canvas.get()->drawPath(path, paint); |
| 47 | #endif |
| 48 | } |
| 49 | |
reed@google.com | 1df888b | 2012-04-24 22:47:21 +0000 | [diff] [blame^] | 50 | static void test_crbug_124652(skiatest::Reporter* reporter) { |
| 51 | #ifdef SK_SCALAR_IS_FLOAT |
| 52 | /* |
| 53 | http://code.google.com/p/chromium/issues/detail?id=124652 |
| 54 | This particular test/bug only applies to the float case, where |
| 55 | large values can "swamp" small ones. |
| 56 | */ |
| 57 | SkScalar intervals[2] = {837099584, 33450}; |
| 58 | SkAutoTUnref<SkDashPathEffect> dash( |
| 59 | new SkDashPathEffect(intervals, 2, -10, false)); |
| 60 | #endif |
| 61 | } |
| 62 | |
reed@google.com | a90aa53 | 2012-04-16 16:27:09 +0000 | [diff] [blame] | 63 | static void test_bigcubic(skiatest::Reporter* reporter) { |
| 64 | #ifdef SK_SCALAR_IS_FLOAT |
| 65 | SkPath path; |
| 66 | path.moveTo(64, 3); |
| 67 | path.cubicTo(-329936, -100000000, -329936, 100000000, 1153, 330003); |
| 68 | |
| 69 | SkPaint paint; |
| 70 | paint.setAntiAlias(true); |
| 71 | |
| 72 | SkAutoTUnref<SkCanvas> canvas(new_canvas(640, 480)); |
| 73 | canvas.get()->drawPath(path, paint); |
| 74 | #endif |
| 75 | } |
| 76 | |
reed@google.com | dceecc7 | 2012-02-23 19:20:19 +0000 | [diff] [blame] | 77 | // we used to assert if the bounds of the device (clip) was larger than 32K |
| 78 | // even when the path itself was smaller. We just draw and hope in the debug |
| 79 | // version to not assert. |
| 80 | static void test_giantaa(skiatest::Reporter* reporter) { |
| 81 | const int W = 400; |
| 82 | const int H = 400; |
mike@reedtribe.org | 6093e65 | 2012-04-14 12:55:17 +0000 | [diff] [blame] | 83 | SkAutoTUnref<SkCanvas> canvas(new_canvas(33000, 10)); |
| 84 | canvas.get()->clear(0); |
reed@google.com | dceecc7 | 2012-02-23 19:20:19 +0000 | [diff] [blame] | 85 | |
| 86 | SkPaint paint; |
| 87 | paint.setAntiAlias(true); |
| 88 | SkPath path; |
| 89 | path.addOval(SkRect::MakeXYWH(-10, -10, 20 + W, 20 + H)); |
mike@reedtribe.org | 6093e65 | 2012-04-14 12:55:17 +0000 | [diff] [blame] | 90 | canvas.get()->drawPath(path, paint); |
reed@google.com | dceecc7 | 2012-02-23 19:20:19 +0000 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | static void TestDrawPath(skiatest::Reporter* reporter) { |
| 94 | test_giantaa(reporter); |
mike@reedtribe.org | 6093e65 | 2012-04-14 12:55:17 +0000 | [diff] [blame] | 95 | test_bug533(reporter); |
reed@google.com | a90aa53 | 2012-04-16 16:27:09 +0000 | [diff] [blame] | 96 | test_bigcubic(reporter); |
reed@google.com | 1df888b | 2012-04-24 22:47:21 +0000 | [diff] [blame^] | 97 | test_crbug_124652(reporter); |
reed@google.com | dceecc7 | 2012-02-23 19:20:19 +0000 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | #include "TestClassDef.h" |
| 101 | DEFINE_TESTCLASS("DrawPath", TestDrawPathClass, TestDrawPath) |