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" |
| 11 | |
| 12 | static SkCanvas* create(SkBitmap::Config config, int w, int h, int rb, |
| 13 | void* addr = NULL) { |
| 14 | SkBitmap bm; |
| 15 | bm.setConfig(config, w, h, rb); |
| 16 | if (addr) { |
| 17 | bm.setPixels(addr); |
| 18 | } else { |
| 19 | bm.allocPixels(); |
| 20 | } |
| 21 | return new SkCanvas(bm); |
| 22 | } |
| 23 | |
mike@reedtribe.org | 6093e65 | 2012-04-14 12:55:17 +0000 | [diff] [blame] | 24 | static SkCanvas* new_canvas(int w, int h) { |
| 25 | return create(SkBitmap::kARGB_8888_Config, w, h, 0, NULL); |
| 26 | } |
| 27 | |
reed@google.com | a90aa53 | 2012-04-16 16:27:09 +0000 | [diff] [blame] | 28 | /////////////////////////////////////////////////////////////////////////////// |
| 29 | |
mike@reedtribe.org | 6093e65 | 2012-04-14 12:55:17 +0000 | [diff] [blame] | 30 | static void test_bug533(skiatest::Reporter* reporter) { |
| 31 | #ifdef SK_SCALAR_IS_FLOAT |
| 32 | /* |
| 33 | http://code.google.com/p/skia/issues/detail?id=533 |
| 34 | This particular test/bug only applies to the float case, where the |
| 35 | coordinates are very large. |
| 36 | */ |
| 37 | SkPath path; |
| 38 | path.moveTo(64, 3); |
| 39 | path.quadTo(-329936, -100000000, 1153, 330003); |
| 40 | |
| 41 | SkPaint paint; |
| 42 | paint.setAntiAlias(true); |
| 43 | |
| 44 | SkAutoTUnref<SkCanvas> canvas(new_canvas(640, 480)); |
| 45 | canvas.get()->drawPath(path, paint); |
| 46 | #endif |
| 47 | } |
| 48 | |
reed@google.com | a90aa53 | 2012-04-16 16:27:09 +0000 | [diff] [blame] | 49 | static void test_bigcubic(skiatest::Reporter* reporter) { |
| 50 | #ifdef SK_SCALAR_IS_FLOAT |
| 51 | SkPath path; |
| 52 | path.moveTo(64, 3); |
| 53 | path.cubicTo(-329936, -100000000, -329936, 100000000, 1153, 330003); |
| 54 | |
| 55 | SkPaint paint; |
| 56 | paint.setAntiAlias(true); |
| 57 | |
| 58 | SkAutoTUnref<SkCanvas> canvas(new_canvas(640, 480)); |
| 59 | canvas.get()->drawPath(path, paint); |
| 60 | #endif |
| 61 | } |
| 62 | |
reed@google.com | dceecc7 | 2012-02-23 19:20:19 +0000 | [diff] [blame] | 63 | // we used to assert if the bounds of the device (clip) was larger than 32K |
| 64 | // even when the path itself was smaller. We just draw and hope in the debug |
| 65 | // version to not assert. |
| 66 | static void test_giantaa(skiatest::Reporter* reporter) { |
| 67 | const int W = 400; |
| 68 | const int H = 400; |
mike@reedtribe.org | 6093e65 | 2012-04-14 12:55:17 +0000 | [diff] [blame] | 69 | SkAutoTUnref<SkCanvas> canvas(new_canvas(33000, 10)); |
| 70 | canvas.get()->clear(0); |
reed@google.com | dceecc7 | 2012-02-23 19:20:19 +0000 | [diff] [blame] | 71 | |
| 72 | SkPaint paint; |
| 73 | paint.setAntiAlias(true); |
| 74 | SkPath path; |
| 75 | path.addOval(SkRect::MakeXYWH(-10, -10, 20 + W, 20 + H)); |
mike@reedtribe.org | 6093e65 | 2012-04-14 12:55:17 +0000 | [diff] [blame] | 76 | canvas.get()->drawPath(path, paint); |
reed@google.com | dceecc7 | 2012-02-23 19:20:19 +0000 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | static void TestDrawPath(skiatest::Reporter* reporter) { |
| 80 | test_giantaa(reporter); |
mike@reedtribe.org | 6093e65 | 2012-04-14 12:55:17 +0000 | [diff] [blame] | 81 | test_bug533(reporter); |
reed@google.com | a90aa53 | 2012-04-16 16:27:09 +0000 | [diff] [blame] | 82 | test_bigcubic(reporter); |
reed@google.com | dceecc7 | 2012-02-23 19:20:19 +0000 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | #include "TestClassDef.h" |
| 86 | DEFINE_TESTCLASS("DrawPath", TestDrawPathClass, TestDrawPath) |