blob: 997e08e30f84a36733805cafc66385e6bd1b0c1f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
// Copyright 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "cc/test/layer_test_common.h"
#include "cc/base/math_util.h"
#include "cc/base/region.h"
#include "cc/quads/draw_quad.h"
#include "cc/quads/render_pass.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/gfx/point_conversions.h"
#include "ui/gfx/rect.h"
#include "ui/gfx/rect_conversions.h"
#include "ui/gfx/size_conversions.h"
namespace cc {
namespace LayerTestCommon {
// Align with expected and actual output
const char* quadString = " Quad: ";
bool canRectFBeSafelyRoundedToRect(const gfx::RectF& r)
{
// Ensure that range of float values is not beyond integer range.
if (!r.IsExpressibleAsRect())
return false;
// Ensure that the values are actually integers.
if (gfx::ToFlooredPoint(r.origin()) == r.origin() && gfx::ToFlooredSize(r.size()) == r.size())
return true;
return false;
}
void verifyQuadsExactlyCoverRect(const cc::QuadList& quads,
const gfx::Rect& rect) {
cc::Region remaining = rect;
for (size_t i = 0; i < quads.size(); ++i) {
cc::DrawQuad* quad = quads[i];
gfx::RectF quadRectF = cc::MathUtil::MapClippedRect(quad->quadTransform(), gfx::RectF(quad->rect));
// Before testing for exact coverage in the integer world, assert that rounding
// will not round the rect incorrectly.
ASSERT_TRUE(canRectFBeSafelyRoundedToRect(quadRectF));
gfx::Rect quadRect = gfx::ToEnclosingRect(quadRectF);
EXPECT_TRUE(rect.Contains(quadRect)) << quadString << i;
EXPECT_TRUE(remaining.Contains(quadRect)) << quadString << i;
remaining.Subtract(quadRect);
}
EXPECT_TRUE(remaining.IsEmpty());
}
} // namespace LayerTestCommon
} // namespace cc
|