Home | History | Annotate | Download | only in test
      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 QuadList& quads,
     36                                                   gfx::Rect rect) {
     37   Region remaining = rect;
     38 
     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));
     43 
     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));
     47 
     48     gfx::Rect quad_rect = gfx::ToEnclosingRect(quad_rectf);
     49 
     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);
     53   }
     54 
     55   EXPECT_TRUE(remaining.IsEmpty());
     56 }
     57 
     58 }  // namespace cc
     59