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
3 // found in the LICENSE file.
5 #include "cc/test/layer_test_common.h"
7 #include "cc/base/math_util.h"
8 #include "cc/base/region.h"
9 #include "cc/quads/draw_quad.h"
10 #include "cc/quads/render_pass.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12 #include "ui/gfx/point_conversions.h"
13 #include "ui/gfx/rect.h"
14 #include "ui/gfx/rect_conversions.h"
15 #include "ui/gfx/size_conversions.h"
19 // Align with expected and actual output.
20 const char* LayerTestCommon::quad_string
= " Quad: ";
22 static bool CanRectFBeSafelyRoundedToRect(const gfx::RectF
& r
) {
23 // Ensure that range of float values is not beyond integer range.
24 if (!r
.IsExpressibleAsRect())
27 // Ensure that the values are actually integers.
28 if (gfx::ToFlooredPoint(r
.origin()) == r
.origin() &&
29 gfx::ToFlooredSize(r
.size()) == r
.size())
35 void LayerTestCommon::VerifyQuadsExactlyCoverRect(const QuadList
& quads
,
36 const gfx::Rect
& rect
) {
37 Region remaining
= rect
;
39 for (size_t i
= 0; i
< quads
.size(); ++i
) {
40 DrawQuad
* quad
= quads
[i
];
41 gfx::RectF quad_rectf
=
42 MathUtil::MapClippedRect(quad
->quadTransform(), gfx::RectF(quad
->rect
));
44 // Before testing for exact coverage in the integer world, assert that
45 // rounding will not round the rect incorrectly.
46 ASSERT_TRUE(CanRectFBeSafelyRoundedToRect(quad_rectf
));
48 gfx::Rect quad_rect
= gfx::ToEnclosingRect(quad_rectf
);
50 EXPECT_TRUE(rect
.Contains(quad_rect
)) << quad_string
<< i
;
51 EXPECT_TRUE(remaining
.Contains(quad_rect
)) << quad_string
<< i
;
52 remaining
.Subtract(quad_rect
);
55 EXPECT_TRUE(remaining
.IsEmpty());