Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CC_MATH_UTIL_H_ | 5 #ifndef CC_MATH_UTIL_H_ |
| 6 #define CC_MATH_UTIL_H_ | 6 #define CC_MATH_UTIL_H_ |
| 7 | 7 |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "cc/cc_export.h" | 9 #include "cc/cc_export.h" |
| 10 #include "ui/gfx/point_f.h" | 10 #include "ui/gfx/point_f.h" |
| 11 #include "ui/gfx/point3_f.h" | 11 #include "ui/gfx/point3_f.h" |
| 12 #include "ui/gfx/transform.h" | 12 #include "ui/gfx/transform.h" |
| 13 | 13 |
| 14 namespace WebKit { | |
| 15 class WebTransformationMatrix; | |
| 16 } | |
| 17 | |
| 18 namespace gfx { | 14 namespace gfx { |
| 19 class QuadF; | 15 class QuadF; |
| 20 class Rect; | 16 class Rect; |
| 21 class RectF; | 17 class RectF; |
| 18 class Transform; | |
| 22 class Vector2dF; | 19 class Vector2dF; |
| 23 } | 20 } |
| 24 | 21 |
| 25 namespace cc { | 22 namespace cc { |
| 26 | 23 |
| 27 struct HomogeneousCoordinate { | 24 struct HomogeneousCoordinate { |
| 28 HomogeneousCoordinate(double newX, double newY, double newZ, double newW) | 25 HomogeneousCoordinate(double newX, double newY, double newZ, double newW) |
| 29 : x(newX) | 26 : x(newX) |
| 30 , y(newY) | 27 , y(newY) |
| 31 , z(newZ) | 28 , z(newZ) |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 71 static const double PI_DOUBLE; | 68 static const double PI_DOUBLE; |
| 72 static const float PI_FLOAT; | 69 static const float PI_FLOAT; |
| 73 static const double EPSILON; | 70 static const double EPSILON; |
| 74 | 71 |
| 75 static double Deg2Rad(double deg) { return deg * PI_DOUBLE / 180; } | 72 static double Deg2Rad(double deg) { return deg * PI_DOUBLE / 180; } |
| 76 static double Rad2Deg(double rad) { return rad * 180 / PI_DOUBLE; } | 73 static double Rad2Deg(double rad) { return rad * 180 / PI_DOUBLE; } |
| 77 | 74 |
| 78 static float Deg2Rad(float deg) { return deg * PI_FLOAT / 180; } | 75 static float Deg2Rad(float deg) { return deg * PI_FLOAT / 180; } |
| 79 static float Rad2Deg(float rad) { return rad * 180 / PI_FLOAT; } | 76 static float Rad2Deg(float rad) { return rad * 180 / PI_FLOAT; } |
| 80 | 77 |
| 81 // Background: WebTransformationMatrix code in WebCore does not do the right thing in | 78 // Background: Transform code in WebCore does not do the right thing in |
|
danakj
2012/11/24 02:34:54
Guess this comment is now a bit out of date.
| |
| 82 // mapRect / mapQuad / projectQuad when there is a perspective projection th at causes | 79 // mapRect / mapQuad / projectQuad when there is a perspective projection th at causes |
| 83 // one of the transformed vertices to go to w < 0. In those cases, it is nec essary to | 80 // one of the transformed vertices to go to w < 0. In those cases, it is nec essary to |
| 84 // perform clipping in homogeneous coordinates, after applying the transform , before | 81 // perform clipping in homogeneous coordinates, after applying the transform , before |
| 85 // dividing-by-w to convert to cartesian coordinates. | 82 // dividing-by-w to convert to cartesian coordinates. |
| 86 // | 83 // |
| 87 // These functions return the axis-aligned rect that encloses the correctly clipped, | 84 // These functions return the axis-aligned rect that encloses the correctly clipped, |
| 88 // transformed polygon. | 85 // transformed polygon. |
| 89 static gfx::Rect mapClippedRect(const WebKit::WebTransformationMatrix&, cons t gfx::Rect&); | 86 static gfx::Rect mapClippedRect(const gfx::Transform&, const gfx::Rect&); |
| 90 static gfx::RectF mapClippedRect(const WebKit::WebTransformationMatrix&, con st gfx::RectF&); | 87 static gfx::RectF mapClippedRect(const gfx::Transform&, const gfx::RectF&); |
| 91 static gfx::RectF projectClippedRect(const WebKit::WebTransformationMatrix&, const gfx::RectF&); | 88 static gfx::RectF projectClippedRect(const gfx::Transform&, const gfx::RectF &); |
| 92 | 89 |
| 93 // Returns an array of vertices that represent the clipped polygon. After re turning, indexes from | 90 // Returns an array of vertices that represent the clipped polygon. After re turning, indexes from |
| 94 // 0 to numVerticesInClippedQuad are valid in the clippedQuad array. Note th at | 91 // 0 to numVerticesInClippedQuad are valid in the clippedQuad array. Note th at |
| 95 // numVerticesInClippedQuad may be zero, which means the entire quad was cli pped, and | 92 // numVerticesInClippedQuad may be zero, which means the entire quad was cli pped, and |
| 96 // none of the vertices in the array are valid. | 93 // none of the vertices in the array are valid. |
| 97 static void mapClippedQuad(const WebKit::WebTransformationMatrix&, const gfx ::QuadF& srcQuad, gfx::PointF clippedQuad[8], int& numVerticesInClippedQuad); | 94 static void mapClippedQuad(const gfx::Transform&, const gfx::QuadF& srcQuad, gfx::PointF clippedQuad[8], int& numVerticesInClippedQuad); |
| 98 | 95 |
| 99 static gfx::RectF computeEnclosingRectOfVertices(gfx::PointF vertices[], int numVertices); | 96 static gfx::RectF computeEnclosingRectOfVertices(gfx::PointF vertices[], int numVertices); |
| 100 static gfx::RectF computeEnclosingClippedRect(const HomogeneousCoordinate& h 1, const HomogeneousCoordinate& h2, const HomogeneousCoordinate& h3, const Homog eneousCoordinate& h4); | 97 static gfx::RectF computeEnclosingClippedRect(const HomogeneousCoordinate& h 1, const HomogeneousCoordinate& h2, const HomogeneousCoordinate& h3, const Homog eneousCoordinate& h4); |
| 101 | 98 |
| 102 // NOTE: These functions do not do correct clipping against w = 0 plane, but they | 99 // NOTE: These functions do not do correct clipping against w = 0 plane, but they |
| 103 // correctly detect the clipped condition via the boolean clipped. | 100 // correctly detect the clipped condition via the boolean clipped. |
| 104 static gfx::QuadF mapQuad(const WebKit::WebTransformationMatrix&, const gfx: :QuadF&, bool& clipped); | 101 static gfx::QuadF mapQuad(const gfx::Transform&, const gfx::QuadF&, bool& cl ipped); |
| 105 static gfx::PointF mapPoint(const WebKit::WebTransformationMatrix&, const gf x::PointF&, bool& clipped); | 102 static gfx::PointF mapPoint(const gfx::Transform&, const gfx::PointF&, bool& clipped); |
| 106 static gfx::Point3F mapPoint(const WebKit::WebTransformationMatrix&, const g fx::Point3F&, bool& clipped); | 103 static gfx::Point3F mapPoint(const gfx::Transform&, const gfx::Point3F&, boo l& clipped); |
| 107 static gfx::QuadF projectQuad(const WebKit::WebTransformationMatrix&, const gfx::QuadF&, bool& clipped); | 104 static gfx::QuadF projectQuad(const gfx::Transform&, const gfx::QuadF&, bool & clipped); |
| 108 static gfx::PointF projectPoint(const WebKit::WebTransformationMatrix&, cons t gfx::PointF&, bool& clipped); | 105 static gfx::PointF projectPoint(const gfx::Transform&, const gfx::PointF&, b ool& clipped); |
| 109 | 106 |
| 110 static void flattenTransformTo2d(WebKit::WebTransformationMatrix&); | 107 static void flattenTransformTo2d(gfx::Transform&); |
| 111 | 108 |
| 112 static gfx::Vector2dF computeTransform2dScaleComponents(const WebKit::WebTra nsformationMatrix&); | 109 static gfx::Vector2dF computeTransform2dScaleComponents(const gfx::Transform &); |
| 113 | 110 |
| 114 // Returns the smallest angle between the given two vectors in degrees. Neit her vector is | 111 // Returns the smallest angle between the given two vectors in degrees. Neit her vector is |
| 115 // assumed to be normalized. | 112 // assumed to be normalized. |
| 116 static float smallestAngleBetweenVectors(gfx::Vector2dF, gfx::Vector2dF); | 113 static float smallestAngleBetweenVectors(gfx::Vector2dF, gfx::Vector2dF); |
| 117 | 114 |
| 118 // Projects the |source| vector onto |destination|. Neither vector is assume d to be normalized. | 115 // Projects the |source| vector onto |destination|. Neither vector is assume d to be normalized. |
| 119 static gfx::Vector2dF projectVector(gfx::Vector2dF source, gfx::Vector2dF de stination); | 116 static gfx::Vector2dF projectVector(gfx::Vector2dF source, gfx::Vector2dF de stination); |
| 120 | 117 |
| 121 // Temporary API to ease migration from WebKit::WebTransformationMatrix | 118 // Temporary API to ease migration from gfx::Transform |
|
danakj
2012/11/24 02:34:54
Heh, undo the change on this line.
| |
| 122 // to gfx::Transform. | 119 // to gfx::Transform. |
| 123 // | 120 // |
| 124 // TODO(shawnsingh, vollick) we should phase out as much as possible of | 121 // TODO(shawnsingh, vollick) we should phase out as much as possible of |
| 125 // these temporary functions, putting functionality into gfx::Transform. | 122 // these temporary functions, putting functionality into gfx::Transform. |
| 126 static bool isInvertible(const gfx::Transform&); | |
| 127 static bool isBackFaceVisible(const gfx::Transform&); | 123 static bool isBackFaceVisible(const gfx::Transform&); |
| 128 static bool isIdentity(const gfx::Transform&); | |
| 129 static bool isIdentityOrTranslation(const gfx::Transform&); | 124 static bool isIdentityOrTranslation(const gfx::Transform&); |
| 130 static bool hasPerspective(const gfx::Transform&); | 125 static bool hasPerspective(const gfx::Transform&); |
| 131 static void makeIdentity(gfx::Transform*); | |
| 132 static void rotateEulerAngles(gfx::Transform*, double eulerX, double eulerY, double eulerZ); | 126 static void rotateEulerAngles(gfx::Transform*, double eulerX, double eulerY, double eulerZ); |
| 133 static void rotateAxisAngle(gfx::Transform*, double i, double j, double k, d ouble degrees); | 127 static void rotateAxisAngle(gfx::Transform*, double i, double j, double k, d ouble degrees); |
| 134 static gfx::Transform inverse(const gfx::Transform&); | 128 static gfx::Transform inverse(const gfx::Transform&); |
| 135 static gfx::Transform to2dTransform(const gfx::Transform&); | 129 static gfx::Transform to2dTransform(const gfx::Transform&); |
| 136 // Note carefully: the args here are labeled as per Webcore indexing convent ions. | 130 // Note carefully: the args here are labeled as per Webcore indexing convent ions. |
| 137 static gfx::Transform createGfxTransform(double m11, double m12, double m13, double m14, | 131 static gfx::Transform createGfxTransform(double m11, double m12, double m13, double m14, |
| 138 double m21, double m22, double m23, double m24, | 132 double m21, double m22, double m23, double m24, |
| 139 double m31, double m32, double m33, double m34, | 133 double m31, double m32, double m33, double m34, |
| 140 double m41, double m42, double m43, double m44); | 134 double m41, double m42, double m43, double m44); |
| 141 | 135 |
| 142 static gfx::Transform createGfxTransform(double a, double b, double c, | 136 static gfx::Transform createGfxTransform(double a, double b, double c, |
| 143 double d, double e, double f); | 137 double d, double e, double f); |
| 144 }; | 138 }; |
| 145 | 139 |
| 146 // TODO(shawnsingh, vollick) this is a temporary home, should eventually | 140 // TODO(shawnsingh, vollick) this is a temporary home, should eventually |
| 147 // be phased out in favor of gfx::Transform API. | 141 // be phased out in favor of gfx::Transform API. |
| 148 gfx::Transform CC_EXPORT operator*(const gfx::Transform&, const gfx::Transform&) ; | 142 gfx::Transform CC_EXPORT operator*(const gfx::Transform&, const gfx::Transform&) ; |
| 149 | 143 |
| 150 } // namespace cc | 144 } // namespace cc |
| 151 | 145 |
| 152 #endif // CC_MATH_UTIL_H_ | 146 #endif // CC_MATH_UTIL_H_ |
| OLD | NEW |