Add signalSyncPoint to the WebGraphicsContext3D command buffer impls.
[chromium-blink-merge.git] / cc / test / layer_test_common.cc
blobfcd09d4585404e86673588c07c058b4aafb23b67
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"
17 namespace cc {
19 // Align with expected and actual output.
20 const char* LayerTestCommon::quad_string = " Quad: ";
22 static bool CanRectFBeSafelyRoundedToRect(gfx::RectF r) {
23 // Ensure that range of float values is not beyond integer range.
24 if (!r.IsExpressibleAsRect())
25 return false;
27 // Ensure that the values are actually integers.
28 if (gfx::ToFlooredPoint(r.origin()) == r.origin() &&
29 gfx::ToFlooredSize(r.size()) == r.size())
30 return true;
32 return false;
35 void LayerTestCommon::VerifyQuadsExactlyCoverRect(const cc::QuadList& quads,
36 gfx::Rect rect) {
37 cc::Region remaining = rect;
39 for (size_t i = 0; i < quads.size(); ++i) {
40 cc::DrawQuad* quad = quads[i];
41 gfx::RectF quad_rectf =
42 cc::MathUtil::MapClippedRect(quad->quadTransform(),
43 gfx::RectF(quad->rect));
45 // Before testing for exact coverage in the integer world, assert that
46 // rounding will not round the rect incorrectly.
47 ASSERT_TRUE(CanRectFBeSafelyRoundedToRect(quad_rectf));
49 gfx::Rect quad_rect = gfx::ToEnclosingRect(quad_rectf);
51 EXPECT_TRUE(rect.Contains(quad_rect)) << quad_string << i;
52 EXPECT_TRUE(remaining.Contains(quad_rect)) << quad_string << i;
53 remaining.Subtract(quad_rect);
56 EXPECT_TRUE(remaining.IsEmpty());
59 } // namespace cc