| 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 | |
| 28 | static void test_bug533(skiatest::Reporter* reporter) { |
| 29 | #ifdef SK_SCALAR_IS_FLOAT |
| 30 | /* |
| 31 | http://code.google.com/p/skia/issues/detail?id=533 |
| 32 | This particular test/bug only applies to the float case, where the |
| 33 | coordinates are very large. |
| 34 | */ |
| 35 | SkPath path; |
| 36 | path.moveTo(64, 3); |
| 37 | path.quadTo(-329936, -100000000, 1153, 330003); |
| 38 | |
| 39 | SkPaint paint; |
| 40 | paint.setAntiAlias(true); |
| 41 | |
| 42 | SkAutoTUnref<SkCanvas> canvas(new_canvas(640, 480)); |
| 43 | canvas.get()->drawPath(path, paint); |
| 44 | #endif |
| 45 | } |
| 46 | |
| reed@google.com | dceecc7 | 2012-02-23 19:20:19 +0000 | [diff] [blame] | 47 | // we used to assert if the bounds of the device (clip) was larger than 32K |
| 48 | // even when the path itself was smaller. We just draw and hope in the debug |
| 49 | // version to not assert. |
| 50 | static void test_giantaa(skiatest::Reporter* reporter) { |
| 51 | const int W = 400; |
| 52 | const int H = 400; |
| mike@reedtribe.org | 6093e65 | 2012-04-14 12:55:17 +0000 | [diff] [blame^] | 53 | SkAutoTUnref<SkCanvas> canvas(new_canvas(33000, 10)); |
| 54 | canvas.get()->clear(0); |
| reed@google.com | dceecc7 | 2012-02-23 19:20:19 +0000 | [diff] [blame] | 55 | |
| 56 | SkPaint paint; |
| 57 | paint.setAntiAlias(true); |
| 58 | SkPath path; |
| 59 | path.addOval(SkRect::MakeXYWH(-10, -10, 20 + W, 20 + H)); |
| mike@reedtribe.org | 6093e65 | 2012-04-14 12:55:17 +0000 | [diff] [blame^] | 60 | canvas.get()->drawPath(path, paint); |
| reed@google.com | dceecc7 | 2012-02-23 19:20:19 +0000 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | static void TestDrawPath(skiatest::Reporter* reporter) { |
| 64 | test_giantaa(reporter); |
| mike@reedtribe.org | 6093e65 | 2012-04-14 12:55:17 +0000 | [diff] [blame^] | 65 | test_bug533(reporter); |
| reed@google.com | dceecc7 | 2012-02-23 19:20:19 +0000 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | #include "TestClassDef.h" |
| 69 | DEFINE_TESTCLASS("DrawPath", TestDrawPathClass, TestDrawPath) |