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. 4 5 #include "cc/test/layer_test_common.h" 6 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" 16 17 namespace cc { 18 19 // Align with expected and actual output. 20 const char* LayerTestCommon::quad_string = " Quad: "; 21 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; 26 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; 31 32 return false; 33 } 34 35 void LayerTestCommon::VerifyQuadsExactlyCoverRect(const cc::QuadList& quads, 36 gfx::Rect rect) { 37 cc::Region remaining = rect; 38 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)); 44 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)); 48 49 gfx::Rect quad_rect = gfx::ToEnclosingRect(quad_rectf); 50 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); 54 } 55 56 EXPECT_TRUE(remaining.IsEmpty()); 57 } 58 59 } // namespace cc 60