OLD | NEW |
---|---|
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "cc/resources/picture_layer_tiling.h" | 5 #include "cc/resources/picture_layer_tiling.h" |
6 | 6 |
7 #include "cc/test/fake_picture_layer_tiling_client.h" | 7 #include "cc/test/fake_picture_layer_tiling_client.h" |
8 #include "cc/test/geometry_test_utils.h" | |
8 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
9 #include "ui/gfx/rect_conversions.h" | 10 #include "ui/gfx/rect_conversions.h" |
10 #include "ui/gfx/size_conversions.h" | 11 #include "ui/gfx/size_conversions.h" |
11 | 12 |
12 namespace cc { | 13 namespace cc { |
13 namespace { | 14 namespace { |
14 | 15 |
15 class PictureLayerTilingIteratorTest : public testing::Test { | 16 class PictureLayerTilingIteratorTest : public testing::Test { |
16 public: | 17 public: |
17 PictureLayerTilingIteratorTest() {} | 18 PictureLayerTilingIteratorTest() {} |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
173 VerifyTilesCoverNonContainedRect(1.5f, gfx::Rect(-1000, 100, 2000, 100)); | 174 VerifyTilesCoverNonContainedRect(1.5f, gfx::Rect(-1000, 100, 2000, 100)); |
174 VerifyTilesCoverNonContainedRect(0.5f, gfx::Rect(-1000, 100, 2000, 100)); | 175 VerifyTilesCoverNonContainedRect(0.5f, gfx::Rect(-1000, 100, 2000, 100)); |
175 } | 176 } |
176 | 177 |
177 TEST(PictureLayerTilingTest, ExpandRectEqual) { | 178 TEST(PictureLayerTilingTest, ExpandRectEqual) { |
178 gfx::Rect in(40, 50, 100, 200); | 179 gfx::Rect in(40, 50, 100, 200); |
179 gfx::Rect bounds(-1000, -1000, 10000, 10000); | 180 gfx::Rect bounds(-1000, -1000, 10000, 10000); |
180 int64 target_area = 100 * 200; | 181 int64 target_area = 100 * 200; |
181 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( | 182 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( |
182 in, target_area, bounds); | 183 in, target_area, bounds); |
183 EXPECT_EQ(in.ToString(), out.ToString()); | 184 EXPECT_RECT_EQ(in, out); |
184 } | 185 } |
185 | 186 |
186 TEST(PictureLayerTilingTest, ExpandRectSmaller) { | 187 TEST(PictureLayerTilingTest, ExpandRectSmaller) { |
187 gfx::Rect in(40, 50, 100, 200); | 188 gfx::Rect in(40, 50, 100, 200); |
188 gfx::Rect bounds(-1000, -1000, 10000, 10000); | 189 gfx::Rect bounds(-1000, -1000, 10000, 10000); |
189 int64 target_area = 100 * 100; | 190 int64 target_area = 100 * 100; |
190 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( | 191 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( |
191 in, target_area, bounds); | 192 in, target_area, bounds); |
192 EXPECT_EQ(out.bottom() - in.bottom(), in.y() - out.y()); | 193 EXPECT_EQ(out.bottom() - in.bottom(), in.y() - out.y()); |
193 EXPECT_EQ(out.right() - in.right(), in.x() - out.x()); | 194 EXPECT_EQ(out.right() - in.right(), in.x() - out.x()); |
(...skipping 14 matching lines...) Expand all Loading... | |
208 EXPECT_NEAR(200 * 200, out.width() * out.height(), 100); | 209 EXPECT_NEAR(200 * 200, out.width() * out.height(), 100); |
209 EXPECT_TRUE(bounds.Contains(out)); | 210 EXPECT_TRUE(bounds.Contains(out)); |
210 } | 211 } |
211 | 212 |
212 TEST(PictureLayerTilingTest, ExpandRectBoundedSmaller) { | 213 TEST(PictureLayerTilingTest, ExpandRectBoundedSmaller) { |
213 gfx::Rect in(40, 50, 100, 200); | 214 gfx::Rect in(40, 50, 100, 200); |
214 gfx::Rect bounds(50, 60, 40, 30); | 215 gfx::Rect bounds(50, 60, 40, 30); |
215 int64 target_area = 200 * 200; | 216 int64 target_area = 200 * 200; |
216 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( | 217 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( |
217 in, target_area, bounds); | 218 in, target_area, bounds); |
218 EXPECT_EQ(bounds.ToString(), out.ToString()); | 219 EXPECT_RECT_EQ(bounds, out); |
219 } | 220 } |
220 | 221 |
221 TEST(PictureLayerTilingTest, ExpandRectBoundedEqual) { | 222 TEST(PictureLayerTilingTest, ExpandRectBoundedEqual) { |
222 gfx::Rect in(40, 50, 100, 200); | 223 gfx::Rect in(40, 50, 100, 200); |
223 gfx::Rect bounds = in; | 224 gfx::Rect bounds = in; |
224 int64 target_area = 200 * 200; | 225 int64 target_area = 200 * 200; |
225 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( | 226 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( |
226 in, target_area, bounds); | 227 in, target_area, bounds); |
227 EXPECT_EQ(bounds.ToString(), out.ToString()); | 228 EXPECT_RECT_EQ(bounds, out); |
228 } | 229 } |
229 | 230 |
230 TEST(PictureLayerTilingTest, ExpandRectBoundedSmallerStretchVertical) { | 231 TEST(PictureLayerTilingTest, ExpandRectBoundedSmallerStretchVertical) { |
231 gfx::Rect in(40, 50, 100, 200); | 232 gfx::Rect in(40, 50, 100, 200); |
232 gfx::Rect bounds(45, 0, 90, 300); | 233 gfx::Rect bounds(45, 0, 90, 300); |
233 int64 target_area = 200 * 200; | 234 int64 target_area = 200 * 200; |
234 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( | 235 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( |
235 in, target_area, bounds); | 236 in, target_area, bounds); |
236 EXPECT_EQ(bounds.ToString(), out.ToString()); | 237 EXPECT_RECT_EQ(bounds, out); |
237 } | 238 } |
238 | 239 |
239 TEST(PictureLayerTilingTest, ExpandRectBoundedEqualStretchVertical) { | 240 TEST(PictureLayerTilingTest, ExpandRectBoundedEqualStretchVertical) { |
240 gfx::Rect in(40, 50, 100, 200); | 241 gfx::Rect in(40, 50, 100, 200); |
241 gfx::Rect bounds(40, 0, 100, 300); | 242 gfx::Rect bounds(40, 0, 100, 300); |
242 int64 target_area = 200 * 200; | 243 int64 target_area = 200 * 200; |
243 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( | 244 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( |
244 in, target_area, bounds); | 245 in, target_area, bounds); |
245 EXPECT_EQ(bounds.ToString(), out.ToString()); | 246 EXPECT_RECT_EQ(bounds, out); |
246 } | 247 } |
247 | 248 |
248 TEST(PictureLayerTilingTest, ExpandRectBoundedSmallerStretchHorizontal) { | 249 TEST(PictureLayerTilingTest, ExpandRectBoundedSmallerStretchHorizontal) { |
249 gfx::Rect in(40, 50, 100, 200); | 250 gfx::Rect in(40, 50, 100, 200); |
250 gfx::Rect bounds(0, 55, 180, 190); | 251 gfx::Rect bounds(0, 55, 180, 190); |
251 int64 target_area = 200 * 200; | 252 int64 target_area = 200 * 200; |
252 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( | 253 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( |
253 in, target_area, bounds); | 254 in, target_area, bounds); |
254 EXPECT_EQ(bounds.ToString(), out.ToString()); | 255 EXPECT_RECT_EQ(bounds, out); |
255 } | 256 } |
256 | 257 |
257 TEST(PictureLayerTilingTest, ExpandRectBoundedEqualStretchHorizontal) { | 258 TEST(PictureLayerTilingTest, ExpandRectBoundedEqualStretchHorizontal) { |
258 gfx::Rect in(40, 50, 100, 200); | 259 gfx::Rect in(40, 50, 100, 200); |
259 gfx::Rect bounds(0, 50, 180, 200); | 260 gfx::Rect bounds(0, 50, 180, 200); |
260 int64 target_area = 200 * 200; | 261 int64 target_area = 200 * 200; |
261 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( | 262 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( |
262 in, target_area, bounds); | 263 in, target_area, bounds); |
263 EXPECT_EQ(bounds.ToString(), out.ToString()); | 264 EXPECT_RECT_EQ(bounds, out); |
danakj
2013/04/10 05:33:23
nit: please leave these as they were. ToString() g
Xianzhu
2013/04/10 16:19:55
EXPECT_RECT_EQ is provided to compare gfx::Rects.
danakj
2013/04/10 16:30:59
I agree, I've been using .ToString() in new code.
Xianzhu
2013/04/10 16:44:49
I'd like to bring this topic to the graphics-dev g
| |
264 } | 265 } |
265 | 266 |
266 TEST(PictureLayerTilingTest, ExpandRectBoundedLeft) { | 267 TEST(PictureLayerTilingTest, ExpandRectBoundedLeft) { |
267 gfx::Rect in(40, 50, 100, 200); | 268 gfx::Rect in(40, 50, 100, 200); |
268 gfx::Rect bounds(20, -1000, 10000, 10000); | 269 gfx::Rect bounds(20, -1000, 10000, 10000); |
269 int64 target_area = 200 * 200; | 270 int64 target_area = 200 * 200; |
270 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( | 271 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( |
271 in, target_area, bounds); | 272 in, target_area, bounds); |
272 EXPECT_EQ(out.bottom() - in.bottom(), in.y() - out.y()); | 273 EXPECT_EQ(out.bottom() - in.bottom(), in.y() - out.y()); |
273 EXPECT_EQ(out.bottom() - in.bottom(), out.right() - in.right()); | 274 EXPECT_EQ(out.bottom() - in.bottom(), out.right() - in.right()); |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
345 EXPECT_EQ(out.right() - in.right(), in.x() - out.x()); | 346 EXPECT_EQ(out.right() - in.right(), in.x() - out.x()); |
346 EXPECT_LE(out.width() * out.height(), target_area); | 347 EXPECT_LE(out.width() * out.height(), target_area); |
347 EXPECT_GT(out.width() * out.height(), | 348 EXPECT_GT(out.width() * out.height(), |
348 target_area - out.height() * 2); | 349 target_area - out.height() * 2); |
349 EXPECT_TRUE(bounds.Contains(out)); | 350 EXPECT_TRUE(bounds.Contains(out)); |
350 } | 351 } |
351 | 352 |
352 TEST(PictureLayerTilingTest, ExpandRectOutOfBounds) { | 353 TEST(PictureLayerTilingTest, ExpandRectOutOfBounds) { |
353 gfx::Rect in(40, 50, 100, 200); | 354 gfx::Rect in(40, 50, 100, 200); |
354 gfx::Rect bounds(0, 0, 10, 10); | 355 gfx::Rect bounds(0, 0, 10, 10); |
355 int64 target_area = 400 * 400; | 356 int64 target_area = 10 * 10; |
danakj
2013/04/10 05:33:23
nit: instead of changing this to be so small, can
Xianzhu
2013/04/10 16:19:55
Done.
| |
356 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( | 357 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( |
357 in, target_area, bounds); | 358 in, target_area, bounds); |
358 EXPECT_TRUE(out.IsEmpty()); | 359 EXPECT_TRUE(out.IsEmpty()); |
359 } | 360 } |
360 | 361 |
362 TEST(PictureLayerTilingTest, ExpandRectOutOfBoundsNonEmptyResult) { | |
363 gfx::Rect in(40, 50, 100, 100); | |
364 gfx::Rect bounds(0, 0, 10, 10); | |
danakj
2013/04/10 05:33:23
Can you have this bounds be large enough that the
Xianzhu
2013/04/10 16:19:55
Done. Now test both cases.
| |
365 int64 target_area = 400 * 400; | |
366 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( | |
367 in, target_area, bounds); | |
368 EXPECT_RECT_EQ(bounds, out); | |
danakj
2013/04/10 05:33:23
nit: compare with EXPECT_EQ and .ToString()
| |
369 } | |
370 | |
361 } // namespace | 371 } // namespace |
362 } // namespace cc | 372 } // namespace cc |
OLD | NEW |