OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "Test.h" | 8 #include "Test.h" |
9 #include "SkBitmapDevice.h" | 9 #include "SkBitmapDevice.h" |
10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 { | 79 { |
80 SkBitmapDevice device(store); | 80 SkBitmapDevice device(store); |
81 MockCanvas mockCanvas(&device); | 81 MockCanvas mockCanvas(&device); |
82 picture.draw(&mockCanvas); | 82 picture.draw(&mockCanvas); |
83 REPORTER_ASSERT(reporter, 1 == mockCanvas.fRects.count()); | 83 REPORTER_ASSERT(reporter, 1 == mockCanvas.fRects.count()); |
84 REPORTER_ASSERT(reporter, rect1 == mockCanvas.fRects[0]); | 84 REPORTER_ASSERT(reporter, rect1 == mockCanvas.fRects[0]); |
85 } | 85 } |
86 { | 86 { |
87 SkBitmapDevice device(store); | 87 SkBitmapDevice device(store); |
88 MockCanvas mockCanvas(&device); | 88 MockCanvas mockCanvas(&device); |
89 mockCanvas.translate(SkFloatToScalar(-7.99f), SkFloatToScalar(-7.99f
)); | 89 mockCanvas.translate(-7.99f, -7.99f); |
90 picture.draw(&mockCanvas); | 90 picture.draw(&mockCanvas); |
91 REPORTER_ASSERT(reporter, 1 == mockCanvas.fRects.count()); | 91 REPORTER_ASSERT(reporter, 1 == mockCanvas.fRects.count()); |
92 REPORTER_ASSERT(reporter, rect1 == mockCanvas.fRects[0]); | 92 REPORTER_ASSERT(reporter, rect1 == mockCanvas.fRects[0]); |
93 } | 93 } |
94 // Corner overlap | 94 // Corner overlap |
95 { | 95 { |
96 SkBitmapDevice device(store); | 96 SkBitmapDevice device(store); |
97 MockCanvas mockCanvas(&device); | 97 MockCanvas mockCanvas(&device); |
98 mockCanvas.translate(SkFloatToScalar(-9.5f), SkFloatToScalar(-9.5f))
; | 98 mockCanvas.translate(-9.5f, -9.5f); |
99 picture.draw(&mockCanvas); | 99 picture.draw(&mockCanvas); |
100 REPORTER_ASSERT(reporter, 2 == mockCanvas.fRects.count()); | 100 REPORTER_ASSERT(reporter, 2 == mockCanvas.fRects.count()); |
101 REPORTER_ASSERT(reporter, rect1 == mockCanvas.fRects[0]); | 101 REPORTER_ASSERT(reporter, rect1 == mockCanvas.fRects[0]); |
102 REPORTER_ASSERT(reporter, rect2 == mockCanvas.fRects[1]); | 102 REPORTER_ASSERT(reporter, rect2 == mockCanvas.fRects[1]); |
103 } | 103 } |
104 // Intersect bottom right tile, but does not overlap rect 2 | 104 // Intersect bottom right tile, but does not overlap rect 2 |
105 { | 105 { |
106 SkBitmapDevice device(store); | 106 SkBitmapDevice device(store); |
107 MockCanvas mockCanvas(&device); | 107 MockCanvas mockCanvas(&device); |
108 mockCanvas.translate(SkFloatToScalar(-16.0f), SkFloatToScalar(-16.0f
)); | 108 mockCanvas.translate(-16.0f, -16.0f); |
109 picture.draw(&mockCanvas); | 109 picture.draw(&mockCanvas); |
110 REPORTER_ASSERT(reporter, 1 == mockCanvas.fRects.count()); | 110 REPORTER_ASSERT(reporter, 1 == mockCanvas.fRects.count()); |
111 REPORTER_ASSERT(reporter, rect2 == mockCanvas.fRects[0]); | 111 REPORTER_ASSERT(reporter, rect2 == mockCanvas.fRects[0]); |
112 } | 112 } |
113 // Out of bounds queries, snap to border tiles | 113 // Out of bounds queries, snap to border tiles |
114 { | 114 { |
115 SkBitmapDevice device(store); | 115 SkBitmapDevice device(store); |
116 MockCanvas mockCanvas(&device); | 116 MockCanvas mockCanvas(&device); |
117 mockCanvas.translate(SkFloatToScalar(2.0f), SkFloatToScalar(0.0f)); | 117 mockCanvas.translate(2.0f, 0.0f); |
118 picture.draw(&mockCanvas); | 118 picture.draw(&mockCanvas); |
119 REPORTER_ASSERT(reporter, 1 == mockCanvas.fRects.count()); | 119 REPORTER_ASSERT(reporter, 1 == mockCanvas.fRects.count()); |
120 REPORTER_ASSERT(reporter, rect1 == mockCanvas.fRects[0]); | 120 REPORTER_ASSERT(reporter, rect1 == mockCanvas.fRects[0]); |
121 } | 121 } |
122 { | 122 { |
123 SkBitmapDevice device(store); | 123 SkBitmapDevice device(store); |
124 MockCanvas mockCanvas(&device); | 124 MockCanvas mockCanvas(&device); |
125 mockCanvas.translate(SkFloatToScalar(0.0f), SkFloatToScalar(2.0f)); | 125 mockCanvas.translate(0.0f, 2.0f); |
126 picture.draw(&mockCanvas); | 126 picture.draw(&mockCanvas); |
127 REPORTER_ASSERT(reporter, 1 == mockCanvas.fRects.count()); | 127 REPORTER_ASSERT(reporter, 1 == mockCanvas.fRects.count()); |
128 REPORTER_ASSERT(reporter, rect1 == mockCanvas.fRects[0]); | 128 REPORTER_ASSERT(reporter, rect1 == mockCanvas.fRects[0]); |
129 } | 129 } |
130 { | 130 { |
131 SkBitmapDevice device(store); | 131 SkBitmapDevice device(store); |
132 MockCanvas mockCanvas(&device); | 132 MockCanvas mockCanvas(&device); |
133 mockCanvas.translate(SkFloatToScalar(-22.0f), SkFloatToScalar(-16.0f
)); | 133 mockCanvas.translate(-22.0f, -16.0f); |
134 picture.draw(&mockCanvas); | 134 picture.draw(&mockCanvas); |
135 REPORTER_ASSERT(reporter, 1 == mockCanvas.fRects.count()); | 135 REPORTER_ASSERT(reporter, 1 == mockCanvas.fRects.count()); |
136 REPORTER_ASSERT(reporter, rect2 == mockCanvas.fRects[0]); | 136 REPORTER_ASSERT(reporter, rect2 == mockCanvas.fRects[0]); |
137 } | 137 } |
138 { | 138 { |
139 SkBitmapDevice device(store); | 139 SkBitmapDevice device(store); |
140 MockCanvas mockCanvas(&device); | 140 MockCanvas mockCanvas(&device); |
141 mockCanvas.translate(SkFloatToScalar(-16.0f), SkFloatToScalar(-22.0f
)); | 141 mockCanvas.translate(-16.0f, -22.0f); |
142 picture.draw(&mockCanvas); | 142 picture.draw(&mockCanvas); |
143 REPORTER_ASSERT(reporter, 1 == mockCanvas.fRects.count()); | 143 REPORTER_ASSERT(reporter, 1 == mockCanvas.fRects.count()); |
144 REPORTER_ASSERT(reporter, rect2 == mockCanvas.fRects[0]); | 144 REPORTER_ASSERT(reporter, rect2 == mockCanvas.fRects[0]); |
145 } | 145 } |
146 } | 146 } |
147 | 147 |
148 static void TestOverlapOffsetQueryAlignment(skiatest::Reporter* reporter) { | 148 static void TestOverlapOffsetQueryAlignment(skiatest::Reporter* reporter) { |
149 // Use SkTileGridPicture to generate a SkTileGrid with a helper | 149 // Use SkTileGridPicture to generate a SkTileGrid with a helper |
150 SkTileGridPicture::TileGridInfo info; | 150 SkTileGridPicture::TileGridInfo info; |
151 info.fMargin.set(1, 1); | 151 info.fMargin.set(1, 1); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 SkBitmapDevice device(tileBitmap); | 204 SkBitmapDevice device(tileBitmap); |
205 MockCanvas mockCanvas(&device); | 205 MockCanvas mockCanvas(&device); |
206 mockCanvas.translate(SkIntToScalar(-8), SkIntToScalar(-8)); | 206 mockCanvas.translate(SkIntToScalar(-8), SkIntToScalar(-8)); |
207 picture.draw(&mockCanvas); | 207 picture.draw(&mockCanvas); |
208 REPORTER_ASSERT(reporter, 1 == mockCanvas.fRects.count()); | 208 REPORTER_ASSERT(reporter, 1 == mockCanvas.fRects.count()); |
209 REPORTER_ASSERT(reporter, rect2 == mockCanvas.fRects[0]); | 209 REPORTER_ASSERT(reporter, rect2 == mockCanvas.fRects[0]); |
210 } | 210 } |
211 { | 211 { |
212 SkBitmapDevice device(tileBitmap); | 212 SkBitmapDevice device(tileBitmap); |
213 MockCanvas mockCanvas(&device); | 213 MockCanvas mockCanvas(&device); |
214 mockCanvas.translate(SkFloatToScalar(-7.9f), SkFloatToScalar(-7.9f))
; | 214 mockCanvas.translate(-7.9f, -7.9f); |
215 picture.draw(&mockCanvas); | 215 picture.draw(&mockCanvas); |
216 REPORTER_ASSERT(reporter, 2 == mockCanvas.fRects.count()); | 216 REPORTER_ASSERT(reporter, 2 == mockCanvas.fRects.count()); |
217 REPORTER_ASSERT(reporter, rect1 == mockCanvas.fRects[0]); | 217 REPORTER_ASSERT(reporter, rect1 == mockCanvas.fRects[0]); |
218 REPORTER_ASSERT(reporter, rect2 == mockCanvas.fRects[1]); | 218 REPORTER_ASSERT(reporter, rect2 == mockCanvas.fRects[1]); |
219 } | 219 } |
220 { | 220 { |
221 SkBitmapDevice device(tileBitmap); | 221 SkBitmapDevice device(tileBitmap); |
222 MockCanvas mockCanvas(&device); | 222 MockCanvas mockCanvas(&device); |
223 mockCanvas.translate(SkFloatToScalar(-8.1f), SkFloatToScalar(-8.1f))
; | 223 mockCanvas.translate(-8.1f, -8.1f); |
224 picture.draw(&mockCanvas); | 224 picture.draw(&mockCanvas); |
225 REPORTER_ASSERT(reporter, 2 == mockCanvas.fRects.count()); | 225 REPORTER_ASSERT(reporter, 2 == mockCanvas.fRects.count()); |
226 REPORTER_ASSERT(reporter, rect2 == mockCanvas.fRects[0]); | 226 REPORTER_ASSERT(reporter, rect2 == mockCanvas.fRects[0]); |
227 REPORTER_ASSERT(reporter, rect3 == mockCanvas.fRects[1]); | 227 REPORTER_ASSERT(reporter, rect3 == mockCanvas.fRects[1]); |
228 } | 228 } |
229 { | 229 { |
230 // Regression test for crbug.com/234688 | 230 // Regression test for crbug.com/234688 |
231 // Once the 2x2 device region is inset by margin, it yields an empty | 231 // Once the 2x2 device region is inset by margin, it yields an empty |
232 // adjusted region, sitting right on top of the tile boundary. | 232 // adjusted region, sitting right on top of the tile boundary. |
233 SkBitmapDevice device(tinyBitmap); | 233 SkBitmapDevice device(tinyBitmap); |
234 MockCanvas mockCanvas(&device); | 234 MockCanvas mockCanvas(&device); |
235 mockCanvas.translate(SkFloatToScalar(-8.0f), SkFloatToScalar(-8.0f))
; | 235 mockCanvas.translate(-8.0f, -8.0f); |
236 picture.draw(&mockCanvas); | 236 picture.draw(&mockCanvas); |
237 // This test passes by not asserting. We do not validate the rects r
ecorded | 237 // This test passes by not asserting. We do not validate the rects r
ecorded |
238 // because the result is numerically unstable (floating point equali
ty). | 238 // because the result is numerically unstable (floating point equali
ty). |
239 // The content of any one of the four tiles of the tilegrid would be
a valid | 239 // The content of any one of the four tiles of the tilegrid would be
a valid |
240 // result since any bbox that covers the center point of the canvas
will be | 240 // result since any bbox that covers the center point of the canvas
will be |
241 // recorded in all four tiles. | 241 // recorded in all four tiles. |
242 } | 242 } |
243 } | 243 } |
244 | 244 |
245 static void Test(skiatest::Reporter* reporter) { | 245 static void Test(skiatest::Reporter* reporter) { |
(...skipping 24 matching lines...) Expand all Loading... |
270 verifyTileHits(reporter, SkIRect::MakeXYWH(5, 5, 10, 10), kAll_Tile); | 270 verifyTileHits(reporter, SkIRect::MakeXYWH(5, 5, 10, 10), kAll_Tile); |
271 verifyTileHits(reporter, SkIRect::MakeXYWH(-10, -10, 40, 40), kAll_Tile
); | 271 verifyTileHits(reporter, SkIRect::MakeXYWH(-10, -10, 40, 40), kAll_Tile
); |
272 | 272 |
273 TestUnalignedQuery(reporter); | 273 TestUnalignedQuery(reporter); |
274 TestOverlapOffsetQueryAlignment(reporter); | 274 TestOverlapOffsetQueryAlignment(reporter); |
275 } | 275 } |
276 }; | 276 }; |
277 | 277 |
278 #include "TestClassDef.h" | 278 #include "TestClassDef.h" |
279 DEFINE_TESTCLASS("TileGrid", TileGridTestClass, TileGridTest::Test) | 279 DEFINE_TESTCLASS("TileGrid", TileGridTestClass, TileGridTest::Test) |
OLD | NEW |