From 2a021fb7bd80168ce79e328f7c6e85de471b13d1 Mon Sep 17 00:00:00 2001 From: "thildebr@chromium.org" Date: Sat, 2 Aug 2014 07:53:49 +0000 Subject: BSP Tree perf tests to match LayerSorter perf tests The BspTree perf tests should ideally perform equally or better than the current LayerSorter tests do in the same tests (i.e. "rubik" vs. "rubik"). Performance results on Z600: layer_sort_cubes= 3.547ms layer_sort_rubik= 0.634ms bsp_tree_cubes= 1.485ms bsp_tree_rubik= 0.136ms bsp_tree_cubes_2= 2.915ms (2x duplicated layers) bsp_tree_cubes_4= 5.667ms (4x duplicated layers) BUG=230833 Review URL: https://codereview.chromium.org/416273002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@287182 0039d316-1c4b-4281-b951-d872f2087c98 --- cc/base/math_util.cc | 119 +++++++++++++++++++++++++++++++++++++++++++++++++++ cc/base/math_util.h | 9 ++++ 2 files changed, 128 insertions(+) (limited to 'cc/base') diff --git a/cc/base/math_util.cc b/cc/base/math_util.cc index fd8e796..2504924 100644 --- a/cc/base/math_util.cc +++ b/cc/base/math_util.cc @@ -111,6 +111,13 @@ static inline void AddVertexToClippedQuad(const gfx::PointF& new_vertex, (*num_vertices_in_clipped_quad)++; } +static inline void AddVertexToClippedQuad3d(const gfx::Point3F& new_vertex, + gfx::Point3F clipped_quad[8], + int* num_vertices_in_clipped_quad) { + clipped_quad[*num_vertices_in_clipped_quad] = new_vertex; + (*num_vertices_in_clipped_quad)++; +} + gfx::Rect MathUtil::MapEnclosingClippedRect(const gfx::Transform& transform, const gfx::Rect& src_rect) { if (transform.IsIdentityOrIntegerTranslation()) { @@ -253,6 +260,76 @@ void MathUtil::MapClippedQuad(const gfx::Transform& transform, DCHECK_LE(*num_vertices_in_clipped_quad, 8); } +bool MathUtil::MapClippedQuad3d(const gfx::Transform& transform, + const gfx::QuadF& src_quad, + gfx::Point3F clipped_quad[8], + int* num_vertices_in_clipped_quad) { + HomogeneousCoordinate h1 = + MapHomogeneousPoint(transform, gfx::Point3F(src_quad.p1())); + HomogeneousCoordinate h2 = + MapHomogeneousPoint(transform, gfx::Point3F(src_quad.p2())); + HomogeneousCoordinate h3 = + MapHomogeneousPoint(transform, gfx::Point3F(src_quad.p3())); + HomogeneousCoordinate h4 = + MapHomogeneousPoint(transform, gfx::Point3F(src_quad.p4())); + + // The order of adding the vertices to the array is chosen so that + // clockwise / counter-clockwise orientation is retained. + + *num_vertices_in_clipped_quad = 0; + + if (!h1.ShouldBeClipped()) { + AddVertexToClippedQuad3d( + h1.CartesianPoint3d(), clipped_quad, num_vertices_in_clipped_quad); + } + + if (h1.ShouldBeClipped() ^ h2.ShouldBeClipped()) { + AddVertexToClippedQuad3d( + ComputeClippedPointForEdge(h1, h2).CartesianPoint3d(), + clipped_quad, + num_vertices_in_clipped_quad); + } + + if (!h2.ShouldBeClipped()) { + AddVertexToClippedQuad3d( + h2.CartesianPoint3d(), clipped_quad, num_vertices_in_clipped_quad); + } + + if (h2.ShouldBeClipped() ^ h3.ShouldBeClipped()) { + AddVertexToClippedQuad3d( + ComputeClippedPointForEdge(h2, h3).CartesianPoint3d(), + clipped_quad, + num_vertices_in_clipped_quad); + } + + if (!h3.ShouldBeClipped()) { + AddVertexToClippedQuad3d( + h3.CartesianPoint3d(), clipped_quad, num_vertices_in_clipped_quad); + } + + if (h3.ShouldBeClipped() ^ h4.ShouldBeClipped()) { + AddVertexToClippedQuad3d( + ComputeClippedPointForEdge(h3, h4).CartesianPoint3d(), + clipped_quad, + num_vertices_in_clipped_quad); + } + + if (!h4.ShouldBeClipped()) { + AddVertexToClippedQuad3d( + h4.CartesianPoint3d(), clipped_quad, num_vertices_in_clipped_quad); + } + + if (h4.ShouldBeClipped() ^ h1.ShouldBeClipped()) { + AddVertexToClippedQuad3d( + ComputeClippedPointForEdge(h4, h1).CartesianPoint3d(), + clipped_quad, + num_vertices_in_clipped_quad); + } + + DCHECK_LE(*num_vertices_in_clipped_quad, 8); + return (*num_vertices_in_clipped_quad >= 4); +} + gfx::RectF MathUtil::ComputeEnclosingRectOfVertices( const gfx::PointF vertices[], int num_vertices) { @@ -386,6 +463,48 @@ gfx::QuadF MathUtil::MapQuad(const gfx::Transform& transform, h4.CartesianPoint2d()); } +gfx::QuadF MathUtil::MapQuad3d(const gfx::Transform& transform, + const gfx::QuadF& q, + gfx::Point3F* p, + bool* clipped) { + if (transform.IsIdentityOrTranslation()) { + gfx::QuadF mapped_quad(q); + mapped_quad += + gfx::Vector2dF(SkMScalarToFloat(transform.matrix().get(0, 3)), + SkMScalarToFloat(transform.matrix().get(1, 3))); + *clipped = false; + p[0] = gfx::Point3F(mapped_quad.p1().x(), mapped_quad.p1().y(), 0.0f); + p[1] = gfx::Point3F(mapped_quad.p2().x(), mapped_quad.p2().y(), 0.0f); + p[2] = gfx::Point3F(mapped_quad.p3().x(), mapped_quad.p3().y(), 0.0f); + p[3] = gfx::Point3F(mapped_quad.p4().x(), mapped_quad.p4().y(), 0.0f); + return mapped_quad; + } + + HomogeneousCoordinate h1 = + MapHomogeneousPoint(transform, gfx::Point3F(q.p1())); + HomogeneousCoordinate h2 = + MapHomogeneousPoint(transform, gfx::Point3F(q.p2())); + HomogeneousCoordinate h3 = + MapHomogeneousPoint(transform, gfx::Point3F(q.p3())); + HomogeneousCoordinate h4 = + MapHomogeneousPoint(transform, gfx::Point3F(q.p4())); + + *clipped = h1.ShouldBeClipped() || h2.ShouldBeClipped() || + h3.ShouldBeClipped() || h4.ShouldBeClipped(); + + // Result will be invalid if clipped == true. But, compute it anyway just in + // case, to emulate existing behavior. + p[0] = h1.CartesianPoint3d(); + p[1] = h2.CartesianPoint3d(); + p[2] = h3.CartesianPoint3d(); + p[3] = h4.CartesianPoint3d(); + + return gfx::QuadF(h1.CartesianPoint2d(), + h2.CartesianPoint2d(), + h3.CartesianPoint2d(), + h4.CartesianPoint2d()); +} + gfx::PointF MathUtil::MapPoint(const gfx::Transform& transform, const gfx::PointF& p, bool* clipped) { diff --git a/cc/base/math_util.h b/cc/base/math_util.h index 4301add..cf18b53 100644 --- a/cc/base/math_util.h +++ b/cc/base/math_util.h @@ -7,6 +7,7 @@ #include #include +#include #include "base/logging.h" #include "base/memory/scoped_ptr.h" @@ -123,6 +124,10 @@ class CC_EXPORT MathUtil { const gfx::QuadF& src_quad, gfx::PointF clipped_quad[8], int* num_vertices_in_clipped_quad); + static bool MapClippedQuad3d(const gfx::Transform& transform, + const gfx::QuadF& src_quad, + gfx::Point3F clipped_quad[8], + int* num_vertices_in_clipped_quad); static gfx::RectF ComputeEnclosingRectOfVertices(const gfx::PointF vertices[], int num_vertices); @@ -137,6 +142,10 @@ class CC_EXPORT MathUtil { static gfx::QuadF MapQuad(const gfx::Transform& transform, const gfx::QuadF& quad, bool* clipped); + static gfx::QuadF MapQuad3d(const gfx::Transform& transform, + const gfx::QuadF& q, + gfx::Point3F* p, + bool* clipped); static gfx::PointF MapPoint(const gfx::Transform& transform, const gfx::PointF& point, bool* clipped); -- cgit v1.1