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 "config.h" | 5 #include "config.h" |
6 | 6 |
7 #include "cc/test/layer_test_common.h" | 7 #include "cc/test/layer_test_common.h" |
8 | 8 |
| 9 #include "Region.h" |
9 #include "cc/draw_quad.h" | 10 #include "cc/draw_quad.h" |
10 #include "cc/math_util.h" | 11 #include "cc/math_util.h" |
| 12 #include "cc/render_pass.h" |
11 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 14 #include "ui/gfx/rect.h" |
| 15 #include "ui/gfx/rect_conversions.h" |
| 16 #include "ui/gfx/safe_integer_conversions.h" |
12 | 17 |
13 namespace LayerTestCommon { | 18 namespace LayerTestCommon { |
14 | 19 |
15 // Align with expected and actual output | 20 // Align with expected and actual output |
16 const char* quadString = " Quad: "; | 21 const char* quadString = " Quad: "; |
17 | 22 |
18 bool floatRectCanBeSafelyRoundedToIntRect(const cc::FloatRect& r) | 23 bool canRectFBeSafelyRoundedToRect(const gfx::RectF& r) |
19 { | 24 { |
20 // Ensure that range of float values is not beyond integer range. | 25 // Ensure that range of float values is not beyond integer range. |
21 if (!r.isExpressibleAsIntRect()) | 26 if (!cc::FloatRect(r).isExpressibleAsIntRect()) |
22 return false; | 27 return false; |
23 | 28 |
24 // Ensure that the values are actually integers. | 29 // Ensure that the values are actually integers. |
25 if (floorf(r.x()) == r.x() | 30 // TODO(danakj) Can shorten this with gfx::ToFlooredPoint and gfx::ToFloored
Size |
26 && floorf(r.y()) == r.y() | 31 if (gfx::ToFlooredInt(r.x()) == r.x() |
27 && floorf(r.width()) == r.width() | 32 && gfx::ToFlooredInt(r.y()) == r.y() |
28 && floorf(r.height()) == r.height()) | 33 && gfx::ToFlooredInt(r.width()) == r.width() |
| 34 && gfx::ToFlooredInt(r.height()) == r.height()) |
29 return true; | 35 return true; |
30 | 36 |
31 return false; | 37 return false; |
32 } | 38 } |
33 | 39 |
34 void verifyQuadsExactlyCoverRect(const cc::QuadList& quads, | 40 void verifyQuadsExactlyCoverRect(const cc::QuadList& quads, |
35 const cc::IntRect& rect) { | 41 const gfx::Rect& rect) { |
36 cc::Region remaining(rect); | 42 cc::Region remaining = cc::IntRect(rect); |
37 | 43 |
38 for (size_t i = 0; i < quads.size(); ++i) { | 44 for (size_t i = 0; i < quads.size(); ++i) { |
39 cc::DrawQuad* quad = quads[i]; | 45 cc::DrawQuad* quad = quads[i]; |
40 cc::FloatRect floatQuadRect = cc::MathUtil::mapClippedRect(quad->sharedQ
uadState()->quadTransform, cc::FloatRect(quad->quadRect())); | 46 gfx::RectF quadRectF = cc::MathUtil::mapClippedRect(quad->sharedQuadStat
e()->quadTransform, gfx::RectF(quad->quadRect())); |
41 | 47 |
42 // Before testing for exact coverage in the integer world, assert that r
ounding | 48 // Before testing for exact coverage in the integer world, assert that r
ounding |
43 // will not round the rect incorrectly. | 49 // will not round the rect incorrectly. |
44 ASSERT_TRUE(floatRectCanBeSafelyRoundedToIntRect(floatQuadRect)); | 50 ASSERT_TRUE(canRectFBeSafelyRoundedToRect(quadRectF)); |
45 | 51 |
46 cc::IntRect quadRect = enclosingIntRect(floatQuadRect); | 52 gfx::Rect quadRect = gfx::ToEnclosingRect(quadRectF); |
47 | 53 |
48 EXPECT_TRUE(rect.contains(quadRect)) << quadString << i; | 54 EXPECT_TRUE(rect.Contains(quadRect)) << quadString << i; |
49 EXPECT_TRUE(remaining.contains(quadRect)) << quadString << i; | 55 EXPECT_TRUE(remaining.contains(cc::IntRect(quadRect))) << quadString <<
i; |
50 remaining.subtract(cc::Region(quadRect)); | 56 remaining.subtract(cc::IntRect(quadRect)); |
51 } | 57 } |
52 | 58 |
53 EXPECT_TRUE(remaining.isEmpty()); | 59 EXPECT_TRUE(remaining.isEmpty()); |
54 } | 60 } |
55 | 61 |
56 } // namespace LayerTestCommon | 62 } // namespace LayerTestCommon |
OLD | NEW |