Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(271)

Side by Side Diff: cc/math_util.cc

Issue 11442020: optimize computing bounds by calling SkMatrix44::map2() (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "cc/math_util.h" 5 #include "cc/math_util.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 #include <limits> 8 #include <limits>
9 9
10 #include "ui/gfx/quad_f.h" 10 #include "ui/gfx/quad_f.h"
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 102
103 gfx::Rect MathUtil::mapClippedRect(const gfx::Transform& transform, const gfx::R ect& srcRect) 103 gfx::Rect MathUtil::mapClippedRect(const gfx::Transform& transform, const gfx::R ect& srcRect)
104 { 104 {
105 return gfx::ToEnclosingRect(mapClippedRect(transform, gfx::RectF(srcRect))); 105 return gfx::ToEnclosingRect(mapClippedRect(transform, gfx::RectF(srcRect)));
106 } 106 }
107 107
108 gfx::RectF MathUtil::mapClippedRect(const gfx::Transform& transform, const gfx:: RectF& srcRect) 108 gfx::RectF MathUtil::mapClippedRect(const gfx::Transform& transform, const gfx:: RectF& srcRect)
109 { 109 {
110 if (transform.IsIdentityOrTranslation()) 110 if (transform.IsIdentityOrTranslation())
111 return srcRect + gfx::Vector2dF(static_cast<float>(transform.matrix().ge tDouble(0, 3)), static_cast<float>(transform.matrix().getDouble(1, 3))); 111 return srcRect + gfx::Vector2dF(static_cast<float>(transform.matrix().ge tDouble(0, 3)), static_cast<float>(transform.matrix().getDouble(1, 3)));
112
113 // Apply the transform, but retain the result in homogeneous coordinates.
112 114
113 // Apply the transform, but retain the result in homogeneous coordinates. 115 double quad[4 * 2]; // input: 4 x 2D point
114 gfx::QuadF q = gfx::QuadF(srcRect); 116 quad[0] = srcRect.x(); quad[1] = srcRect.y();
shawnsingh 2012/12/06 03:00:55 nit: point --> points
reed1 2012/12/06 05:50:20 Done.
115 HomogeneousCoordinate h1 = mapHomogeneousPoint(transform, gfx::Point3F(q.p1( ))); 117 quad[2] = srcRect.right(); quad[3] = srcRect.y();
116 HomogeneousCoordinate h2 = mapHomogeneousPoint(transform, gfx::Point3F(q.p2( ))); 118 quad[4] = srcRect.x(); quad[5] = srcRect.bottom();
117 HomogeneousCoordinate h3 = mapHomogeneousPoint(transform, gfx::Point3F(q.p3( ))); 119 quad[6] = srcRect.right(); quad[7] = srcRect.bottom();
118 HomogeneousCoordinate h4 = mapHomogeneousPoint(transform, gfx::Point3F(q.p4( )));
119 120
120 return computeEnclosingClippedRect(h1, h2, h3, h4); 121 double result[4 * 4]; // output: 4 x 4D homogeneous point
122 transform.matrix().map2(quad, 4, result);
123
124 if (!(transform.matrix().getType() & SkMatrix44::kPerspective_Mask)) {
125 const SkPoint pts[] = {
126 { result[0], result[1] }, { result[4], result[5] },
127 { result[8], result[8] }, { result[12], result[13] },
128 };
129 SkRect r;
130 r.set(pts, 4);
131 return gfx::RectF(r.x(), r.y(), r.width(), r.height());
132 }
133
134 return computeEnclosingClippedRect(*(const HomogeneousCoordinate*)&result[0] ,
135 *(const HomogeneousCoordinate*)&result[4] ,
136 *(const HomogeneousCoordinate*)&result[8] ,
137 *(const HomogeneousCoordinate*)&result[12 ]);
121 } 138 }
122 139
123 gfx::RectF MathUtil::projectClippedRect(const gfx::Transform& transform, const g fx::RectF& srcRect) 140 gfx::RectF MathUtil::projectClippedRect(const gfx::Transform& transform, const g fx::RectF& srcRect)
124 { 141 {
125 if (transform.IsIdentityOrTranslation()) 142 if (transform.IsIdentityOrTranslation())
126 return srcRect + gfx::Vector2dF(static_cast<float>(transform.matrix().ge tDouble(0, 3)), static_cast<float>(transform.matrix().getDouble(1, 3))); 143 return srcRect + gfx::Vector2dF(static_cast<float>(transform.matrix().ge tDouble(0, 3)), static_cast<float>(transform.matrix().getDouble(1, 3)));
127 144
128 // Perform the projection, but retain the result in homogeneous coordinates. 145 // Perform the projection, but retain the result in homogeneous coordinates.
129 gfx::QuadF q = gfx::QuadF(srcRect); 146 gfx::QuadF q = gfx::QuadF(srcRect);
130 HomogeneousCoordinate h1 = projectHomogeneousPoint(transform, q.p1()); 147 HomogeneousCoordinate h1 = projectHomogeneousPoint(transform, q.p1());
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after
482 matrix.setDouble(1, 0, b); 499 matrix.setDouble(1, 0, b);
483 matrix.setDouble(0, 1, c); 500 matrix.setDouble(0, 1, c);
484 matrix.setDouble(1, 1, d); 501 matrix.setDouble(1, 1, d);
485 matrix.setDouble(0, 3, e); 502 matrix.setDouble(0, 3, e);
486 matrix.setDouble(1, 3, f); 503 matrix.setDouble(1, 3, f);
487 504
488 return result; 505 return result;
489 } 506 }
490 507
491 } // namespace cc 508 } // namespace cc
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698