OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 #include "Test.h" | 8 #include "Test.h" |
9 #include "SkPath.h" | 9 #include "SkPath.h" |
10 #include "SkLineClipper.h" | 10 #include "SkLineClipper.h" |
11 #include "SkEdgeClipper.h" | 11 #include "SkEdgeClipper.h" |
12 | 12 |
13 #include "SkCanvas.h" | 13 #include "SkCanvas.h" |
14 static void test_hairclipping(skiatest::Reporter* reporter) { | 14 static void test_hairclipping(skiatest::Reporter* reporter) { |
15 SkBitmap bm; | 15 SkBitmap bm; |
16 bm.setConfig(SkBitmap::kARGB_8888_Config, 4, 4); | 16 bm.setConfig(SkBitmap::kARGB_8888_Config, 4, 4); |
17 bm.allocPixels(); | 17 bm.allocPixels(); |
18 bm.eraseColor(SK_ColorWHITE); | 18 bm.eraseColor(SK_ColorWHITE); |
19 | 19 |
20 SkPaint paint; | 20 SkPaint paint; |
21 paint.setAntiAlias(true); | 21 paint.setAntiAlias(true); |
22 | 22 |
23 SkCanvas canvas(bm); | 23 SkCanvas canvas(bm); |
24 canvas.clipRect(SkRect::MakeWH(SkIntToScalar(4), SkIntToScalar(2))); | 24 canvas.clipRect(SkRect::MakeWH(SkIntToScalar(4), SkIntToScalar(2))); |
25 canvas.drawLine(SkFloatToScalar(1.5f), SkFloatToScalar(1.5f), | 25 canvas.drawLine(1.5f, 1.5f, |
26 SkFloatToScalar(3.5f), SkFloatToScalar(3.5f), paint); | 26 3.5f, 3.5f, paint); |
27 | 27 |
28 /** | 28 /** |
29 * We had a bug where we misinterpreted the bottom of the clip, and | 29 * We had a bug where we misinterpreted the bottom of the clip, and |
30 * would draw another pixel (to the right in this case) on the same | 30 * would draw another pixel (to the right in this case) on the same |
31 * last scanline. i.e. we would draw to [2,1], even though this hairline | 31 * last scanline. i.e. we would draw to [2,1], even though this hairline |
32 * should just draw to [1,1], [2,2], [3,3] modulo the clip. | 32 * should just draw to [1,1], [2,2], [3,3] modulo the clip. |
33 * | 33 * |
34 * The result of this entire draw should be that we only draw to [1,1] | 34 * The result of this entire draw should be that we only draw to [1,1] |
35 * | 35 * |
36 * Fixed in rev. 3366 | 36 * Fixed in rev. 3366 |
37 */ | 37 */ |
38 for (int y = 0; y < 4; ++y) { | 38 for (int y = 0; y < 4; ++y) { |
39 for (int x = 0; x < 4; ++x) { | 39 for (int x = 0; x < 4; ++x) { |
40 bool nonWhite = (1 == y) && (1 == x); | 40 bool nonWhite = (1 == y) && (1 == x); |
41 SkPMColor c = *bm.getAddr32(x, y); | 41 SkPMColor c = *bm.getAddr32(x, y); |
42 if (nonWhite) { | 42 if (nonWhite) { |
43 REPORTER_ASSERT(reporter, 0xFFFFFFFF != c); | 43 REPORTER_ASSERT(reporter, 0xFFFFFFFF != c); |
44 } else { | 44 } else { |
45 REPORTER_ASSERT(reporter, 0xFFFFFFFF == c); | 45 REPORTER_ASSERT(reporter, 0xFFFFFFFF == c); |
46 } | 46 } |
47 } | 47 } |
48 } | 48 } |
49 } | 49 } |
50 | 50 |
51 static void test_edgeclipper() { | 51 static void test_edgeclipper() { |
52 SkEdgeClipper clipper; | 52 SkEdgeClipper clipper; |
53 | 53 |
54 const SkPoint pts[] = { | 54 const SkPoint pts[] = { |
55 { SkFloatToScalar(3.0995476e+010f), SkFloatToScalar(42.929779f) }, | 55 { 3.0995476e+010f, 42.929779f }, |
56 { SkFloatToScalar(-3.0995163e+010f), SkFloatToScalar(51.050385f) }, | 56 { -3.0995163e+010f, 51.050385f }, |
57 { SkFloatToScalar(-3.0995157e+010f), SkFloatToScalar(51.050392f) }, | 57 { -3.0995157e+010f, 51.050392f }, |
58 { SkFloatToScalar(-3.0995134e+010f), SkFloatToScalar(51.050400f) }, | 58 { -3.0995134e+010f, 51.050400f }, |
59 }; | 59 }; |
60 | 60 |
61 const SkRect clip = { 0, 0, SkIntToScalar(300), SkIntToScalar(200) }; | 61 const SkRect clip = { 0, 0, SkIntToScalar(300), SkIntToScalar(200) }; |
62 | 62 |
63 // this should not assert, even though our choppers do a poor numerical | 63 // this should not assert, even though our choppers do a poor numerical |
64 // job when computing their t values. | 64 // job when computing their t values. |
65 // http://code.google.com/p/skia/issues/detail?id=444 | 65 // http://code.google.com/p/skia/issues/detail?id=444 |
66 clipper.clipCubic(pts, clip); | 66 clipper.clipCubic(pts, clip); |
67 } | 67 } |
68 | 68 |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 } | 145 } |
146 | 146 |
147 static void TestClipper(skiatest::Reporter* reporter) { | 147 static void TestClipper(skiatest::Reporter* reporter) { |
148 test_intersectline(reporter); | 148 test_intersectline(reporter); |
149 test_edgeclipper(); | 149 test_edgeclipper(); |
150 test_hairclipping(reporter); | 150 test_hairclipping(reporter); |
151 } | 151 } |
152 | 152 |
153 #include "TestClassDef.h" | 153 #include "TestClassDef.h" |
154 DEFINE_TESTCLASS("Clipper", TestClipperClass, TestClipper) | 154 DEFINE_TESTCLASS("Clipper", TestClipperClass, TestClipper) |
OLD | NEW |