| Index: cc/quads/draw_polygon_unittest.cc
|
| diff --git a/cc/quads/draw_polygon_unittest.cc b/cc/quads/draw_polygon_unittest.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..3ee001ad558991f6f7c29cae0f394426021af3a3
|
| --- /dev/null
|
| +++ b/cc/quads/draw_polygon_unittest.cc
|
| @@ -0,0 +1,198 @@
|
| +// Copyright 2014 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/output/bsp_compare_result.h"
|
| +#include "cc/quads/draw_polygon.h"
|
| +#include "testing/gtest/include/gtest/gtest.h"
|
| +#include "ui/gfx/transform.h"
|
| +
|
| +namespace cc {
|
| +namespace {
|
| +
|
| +#define CREATE_NEW_DRAW_POLYGON(name, vertex_array, num_vertices, polygon_id) \
|
| + DrawPolygon name(NULL, vertex_array, num_vertices, polygon_id)
|
| +
|
| +// Two quads are definitely not touching and so no split should occur.
|
| +TEST(DrawPolygonSplitTest, NotTouchingNoSplit) {
|
| + gfx::Point3F vertices_a[4];
|
| + vertices_a[0] = gfx::Point3F(0.0f, 10.0f, 0.0f);
|
| + vertices_a[1] = gfx::Point3F(0.0f, 0.0f, 0.0f);
|
| + vertices_a[2] = gfx::Point3F(10.0f, 0.0f, 0.0f);
|
| + vertices_a[3] = gfx::Point3F(10.0f, 10.0f, 0.0f);
|
| + gfx::Point3F vertices_b[4];
|
| + vertices_b[0] = gfx::Point3F(5.0f, 10.0f, 5.0f);
|
| + vertices_b[1] = gfx::Point3F(5.0f, 0.0f, 15.0f);
|
| + vertices_b[2] = gfx::Point3F(5.0f, 0.0f, 15.0f);
|
| + vertices_b[3] = gfx::Point3F(5.0f, 10.0f, 5.0f);
|
| +
|
| + CREATE_NEW_DRAW_POLYGON(polygon_a, vertices_a, 4, 0);
|
| + CREATE_NEW_DRAW_POLYGON(polygon_b, vertices_b, 4, 1);
|
| +
|
| + EXPECT_EQ(DrawPolygon::SideCompare(
|
| + polygon_b, polygon_a, DrawPolygon::compare_threshold),
|
| + BSP_FRONT);
|
| +}
|
| +
|
| +// One quad is resting against another, but doesn't cross its plane so no split
|
| +// should occur.
|
| +TEST(DrawPolygonSplitTest, BarelyTouchingNoSplit) {
|
| + gfx::Point3F vertices_a[4];
|
| + vertices_a[0] = gfx::Point3F(0.0f, 10.0f, 0.0f);
|
| + vertices_a[1] = gfx::Point3F(0.0f, 0.0f, 0.0f);
|
| + vertices_a[2] = gfx::Point3F(10.0f, 0.0f, 0.0f);
|
| + vertices_a[3] = gfx::Point3F(10.0f, 10.0f, 0.0f);
|
| + gfx::Point3F vertices_b[4];
|
| + vertices_b[0] = gfx::Point3F(5.0f, 10.0f, 0.0f);
|
| + vertices_b[1] = gfx::Point3F(5.0f, 0.0f, -10.0f);
|
| + vertices_b[2] = gfx::Point3F(5.0f, 0.0f, -10.0f);
|
| + vertices_b[3] = gfx::Point3F(5.0f, 10.0f, 0.0f);
|
| +
|
| + CREATE_NEW_DRAW_POLYGON(polygon_a, vertices_a, 4, 0);
|
| + CREATE_NEW_DRAW_POLYGON(polygon_b, vertices_b, 4, 1);
|
| +
|
| + EXPECT_EQ(DrawPolygon::SideCompare(
|
| + polygon_b, polygon_a, DrawPolygon::compare_threshold),
|
| + BSP_BACK);
|
| +}
|
| +
|
| +// One quad intersects another and becomes two pieces.
|
| +TEST(DrawPolygonSplitTest, BasicSplit) {
|
| + gfx::Point3F vertices_a[4];
|
| + vertices_a[0] = gfx::Point3F(0.0f, 10.0f, 0.0f);
|
| + vertices_a[1] = gfx::Point3F(0.0f, 0.0f, 0.0f);
|
| + vertices_a[2] = gfx::Point3F(10.0f, 0.0f, 0.0f);
|
| + vertices_a[3] = gfx::Point3F(10.0f, 10.0f, 0.0f);
|
| + gfx::Point3F vertices_b[4];
|
| + vertices_b[0] = gfx::Point3F(5.0f, 10.0f, -5.0f);
|
| + vertices_b[1] = gfx::Point3F(5.0f, 0.0f, -5.0f);
|
| + vertices_b[2] = gfx::Point3F(5.0f, 0.0f, 5.0f);
|
| + vertices_b[3] = gfx::Point3F(5.0f, 10.0f, 5.0f);
|
| +
|
| + CREATE_NEW_DRAW_POLYGON(polygon_a, vertices_a, 4, 0);
|
| + CREATE_NEW_DRAW_POLYGON(polygon_b, vertices_b, 4, 1);
|
| +
|
| + EXPECT_EQ(DrawPolygon::SideCompare(
|
| + polygon_b, polygon_a, DrawPolygon::compare_threshold),
|
| + BSP_SPLIT);
|
| +
|
| + scoped_ptr<DrawPolygon> front_polygon;
|
| + scoped_ptr<DrawPolygon> back_polygon;
|
| + polygon_b.Split(
|
| + polygon_a, DrawPolygon::split_threshold, &front_polygon, &back_polygon);
|
| + EXPECT_EQ(DrawPolygon::SideCompare(
|
| + *front_polygon, polygon_a, DrawPolygon::compare_threshold),
|
| + BSP_FRONT);
|
| + EXPECT_EQ(DrawPolygon::SideCompare(
|
| + *back_polygon, polygon_a, DrawPolygon::compare_threshold),
|
| + BSP_BACK);
|
| +}
|
| +
|
| +// A "wave" shape of points that do not make up those of a convex polygon
|
| +// crossing the boundaries of another polygon. This should not cause a problem
|
| +// and should still result in two different pieces of geometry on either side.
|
| +TEST(DrawPolygonSplitTest, NonConvexSplit) {
|
| + gfx::Point3F vertices_a[4];
|
| + vertices_a[0] = gfx::Point3F(0.0f, 10.0f, 0.0f);
|
| + vertices_a[1] = gfx::Point3F(0.0f, 0.0f, 0.0f);
|
| + vertices_a[2] = gfx::Point3F(10.0f, 0.0f, 0.0f);
|
| + vertices_a[3] = gfx::Point3F(10.0f, 10.0f, 0.0f);
|
| + gfx::Point3F vertices_b[4];
|
| + vertices_b[0] = gfx::Point3F(5.0f, 10.0f, -10.0f);
|
| + vertices_b[1] = gfx::Point3F(5.0f, 7.5f, -5.0f);
|
| + vertices_b[2] = gfx::Point3F(5.0f, 5.0f, 0.0f);
|
| + vertices_b[3] = gfx::Point3F(5.0f, 7.5f, 5.0f);
|
| + vertices_b[4] = gfx::Point3F(5.0f, 10.0f, 10.0f);
|
| +
|
| + CREATE_NEW_DRAW_POLYGON(polygon_a, vertices_a, 4, 0);
|
| + CREATE_NEW_DRAW_POLYGON(polygon_b, vertices_b, 5, 1);
|
| +
|
| + EXPECT_EQ(DrawPolygon::SideCompare(
|
| + polygon_b, polygon_a, DrawPolygon::compare_threshold),
|
| + BSP_SPLIT);
|
| +
|
| + scoped_ptr<DrawPolygon> front_polygon;
|
| + scoped_ptr<DrawPolygon> back_polygon;
|
| + polygon_b.Split(
|
| + polygon_a, DrawPolygon::split_threshold, &front_polygon, &back_polygon);
|
| + EXPECT_EQ(DrawPolygon::SideCompare(
|
| + *front_polygon, polygon_a, DrawPolygon::compare_threshold),
|
| + BSP_FRONT);
|
| + EXPECT_EQ(DrawPolygon::SideCompare(
|
| + *back_polygon, polygon_a, DrawPolygon::compare_threshold),
|
| + BSP_BACK);
|
| +}
|
| +
|
| +// In this test we cut the corner of a quad so that it creates a triangle and
|
| +// a pentagon as a result.
|
| +TEST(DrawPolygonSplitTest, AngledSplit) {
|
| + gfx::Point3F vertices_a[4];
|
| + vertices_a[0] = gfx::Point3F(0.0f, 0.0f, 0.0f);
|
| + vertices_a[1] = gfx::Point3F(0.0f, 0.0f, 10.0f);
|
| + vertices_a[2] = gfx::Point3F(10.0f, 0.0f, 10.0f);
|
| + vertices_a[3] = gfx::Point3F(10.0f, 0.0f, 0.0f);
|
| + gfx::Point3F vertices_b[4];
|
| + vertices_b[0] = gfx::Point3F(2.0f, 5.0f, 1.0f);
|
| + vertices_b[1] = gfx::Point3F(2.0f, -5.0f, 1.0f);
|
| + vertices_b[2] = gfx::Point3F(-1.0f, -5.0f, -2.0f);
|
| + vertices_b[3] = gfx::Point3F(-1.0f, 5.0f, -2.0f);
|
| +
|
| + CREATE_NEW_DRAW_POLYGON(polygon_a, vertices_a, 4, 0);
|
| + CREATE_NEW_DRAW_POLYGON(polygon_b, vertices_b, 4, 1);
|
| +
|
| + EXPECT_EQ(DrawPolygon::SideCompare(
|
| + polygon_a, polygon_b, DrawPolygon::compare_threshold),
|
| + BSP_SPLIT);
|
| +
|
| + scoped_ptr<DrawPolygon> front_polygon;
|
| + scoped_ptr<DrawPolygon> back_polygon;
|
| + polygon_a.Split(
|
| + polygon_b, DrawPolygon::split_threshold, &front_polygon, &back_polygon);
|
| + EXPECT_EQ(DrawPolygon::SideCompare(
|
| + *front_polygon, polygon_b, DrawPolygon::compare_threshold),
|
| + BSP_FRONT);
|
| + EXPECT_EQ(DrawPolygon::SideCompare(
|
| + *back_polygon, polygon_b, DrawPolygon::compare_threshold),
|
| + BSP_BACK);
|
| +
|
| + EXPECT_EQ(front_polygon->points.size(), static_cast<unsigned int>(3));
|
| + EXPECT_EQ(back_polygon->points.size(), static_cast<unsigned int>(5));
|
| +}
|
| +
|
| +// Testing the area calculation on a basic flat 10x10 quad.
|
| +TEST(DrawPolygonAreaTest, Basic) {
|
| + gfx::Point3F vertices_a[4];
|
| + vertices_a[0] = gfx::Point3F(0.0f, 10.0f, 0.0f);
|
| + vertices_a[1] = gfx::Point3F(0.0f, 0.0f, 0.0f);
|
| + vertices_a[2] = gfx::Point3F(10.0f, 0.0f, 0.0f);
|
| + vertices_a[3] = gfx::Point3F(10.0f, 10.0f, 0.0f);
|
| +
|
| + CREATE_NEW_DRAW_POLYGON(polygon_a, vertices_a, 4, 0);
|
| +
|
| + EXPECT_EQ(polygon_a.area, 100.0f);
|
| +}
|
| +
|
| +// Same quad as before, but with transformations applied to it. This shows that
|
| +// the area calculation works on arbitrarily transformed geometry.
|
| +TEST(DrawPolygonAreaTest, TransformedPolygon) {
|
| + gfx::Point3F vertices_a[4];
|
| + vertices_a[0] = gfx::Point3F(0.0f, 10.0f, 0.0f);
|
| + vertices_a[1] = gfx::Point3F(0.0f, 0.0f, 0.0f);
|
| + vertices_a[2] = gfx::Point3F(10.0f, 0.0f, 0.0f);
|
| + vertices_a[3] = gfx::Point3F(10.0f, 10.0f, 0.0f);
|
| +
|
| + gfx::Transform transform;
|
| + transform.RotateAboutXAxis(30.0);
|
| + transform.RotateAboutYAxis(40.0);
|
| + transform.RotateAboutZAxis(50.0);
|
| + for (int i = 0; i < 4; i++) {
|
| + transform.TransformPoint(&vertices_a[i]);
|
| + }
|
| +
|
| + CREATE_NEW_DRAW_POLYGON(polygon_a, vertices_a, 4, 0);
|
| +
|
| + EXPECT_EQ(polygon_a.area, 100.0f);
|
| +}
|
| +
|
| +} // namespace
|
| +} // namespace cc
|
|
|