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

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 points
114 gfx::QuadF q = gfx::QuadF(srcRect); 116 quad[0] = srcRect.x();
115 HomogeneousCoordinate h1 = mapHomogeneousPoint(transform, gfx::Point3F(q.p1( ))); 117 quad[1] = srcRect.y();
116 HomogeneousCoordinate h2 = mapHomogeneousPoint(transform, gfx::Point3F(q.p2( ))); 118 quad[2] = srcRect.right();
117 HomogeneousCoordinate h3 = mapHomogeneousPoint(transform, gfx::Point3F(q.p3( ))); 119 quad[3] = srcRect.y();
118 HomogeneousCoordinate h4 = mapHomogeneousPoint(transform, gfx::Point3F(q.p4( ))); 120 quad[4] = srcRect.right();
121 quad[5] = srcRect.bottom();
122 quad[6] = srcRect.x();
123 quad[7] = srcRect.bottom();
119 124
120 return computeEnclosingClippedRect(h1, h2, h3, h4); 125 double result[4 * 4]; // output: 4 x 4D homogeneous points
126 transform.matrix().map2(quad, 4, result);
127
128 HomogeneousCoordinate hc0(result[0], result[1], result[2], result[3]);
129 HomogeneousCoordinate hc1(result[4], result[5], result[6], result[7]);
130 HomogeneousCoordinate hc2(result[8], result[9], result[10], result[11]);
131 HomogeneousCoordinate hc3(result[12], result[13], result[14], result[15]);
132 return computeEnclosingClippedRect(hc0, hc1, hc2, hc3);
121 } 133 }
122 134
123 gfx::RectF MathUtil::projectClippedRect(const gfx::Transform& transform, const g fx::RectF& srcRect) 135 gfx::RectF MathUtil::projectClippedRect(const gfx::Transform& transform, const g fx::RectF& srcRect)
124 { 136 {
125 if (transform.IsIdentityOrTranslation()) 137 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))); 138 return srcRect + gfx::Vector2dF(static_cast<float>(transform.matrix().ge tDouble(0, 3)), static_cast<float>(transform.matrix().getDouble(1, 3)));
127 139
128 // Perform the projection, but retain the result in homogeneous coordinates. 140 // Perform the projection, but retain the result in homogeneous coordinates.
129 gfx::QuadF q = gfx::QuadF(srcRect); 141 gfx::QuadF q = gfx::QuadF(srcRect);
130 HomogeneousCoordinate h1 = projectHomogeneousPoint(transform, q.p1()); 142 HomogeneousCoordinate h1 = projectHomogeneousPoint(transform, q.p1());
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after
482 matrix.setDouble(1, 0, b); 494 matrix.setDouble(1, 0, b);
483 matrix.setDouble(0, 1, c); 495 matrix.setDouble(0, 1, c);
484 matrix.setDouble(1, 1, d); 496 matrix.setDouble(1, 1, d);
485 matrix.setDouble(0, 3, e); 497 matrix.setDouble(0, 3, e);
486 matrix.setDouble(1, 3, f); 498 matrix.setDouble(1, 3, f);
487 499
488 return result; 500 return result;
489 } 501 }
490 502
491 } // namespace cc 503 } // 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