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

Side by Side Diff: cc/layer_sorter.cc

Issue 11264056: cc: Use gfx:: Geometry types for positions, bounds, and related things. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: ScaleAsVector Created 8 years, 1 month 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 | « cc/layer_sorter.h ('k') | cc/layer_tiling_data.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 The Chromium Authors. All rights reserved. 1 // Copyright 2011 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 "config.h" 5 #include "config.h"
6 6
7 #include "cc/layer_sorter.h" 7 #include "cc/layer_sorter.h"
8 8
9 #include <deque> 9 #include <deque>
10 #include <limits> 10 #include <limits>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "cc/math_util.h" 14 #include "cc/math_util.h"
15 #include "cc/render_surface_impl.h" 15 #include "cc/render_surface_impl.h"
16 #include <public/WebTransformationMatrix.h> 16 #include <public/WebTransformationMatrix.h>
17 17
18 using namespace std; 18 using namespace std;
19 using WebKit::WebTransformationMatrix; 19 using WebKit::WebTransformationMatrix;
20 20
21 namespace cc { 21 namespace cc {
22 22
23 inline static float perpProduct(const FloatSize& u, const FloatSize& v) 23 inline static float perpProduct(const gfx::Vector2dF& u, const gfx::Vector2dF& v )
24 { 24 {
25 return u.width() * v.height() - u.height() * v.width(); 25 return u.x() * v.y() - u.y() * v.x();
26 } 26 }
27 27
28 // Tests if two edges defined by their endpoints (a,b) and (c,d) intersect. Retu rns true and the 28 // Tests if two edges defined by their endpoints (a,b) and (c,d) intersect. Retu rns true and the
29 // point of intersection if they do and false otherwise. 29 // point of intersection if they do and false otherwise.
30 static bool edgeEdgeTest(const FloatPoint& a, const FloatPoint& b, const FloatPo int& c, const FloatPoint& d, FloatPoint& r) 30 static bool edgeEdgeTest(const gfx::PointF& a, const gfx::PointF& b, const gfx:: PointF& c, const gfx::PointF& d, gfx::PointF& r)
31 { 31 {
32 FloatSize u = b - a; 32 gfx::Vector2dF u = b - a;
33 FloatSize v = d - c; 33 gfx::Vector2dF v = d - c;
34 FloatSize w = a - c; 34 gfx::Vector2dF w = a - c;
35 35
36 float denom = perpProduct(u, v); 36 float denom = perpProduct(u, v);
37 37
38 // If denom == 0 then the edges are parallel. While they could be overlappin g 38 // If denom == 0 then the edges are parallel. While they could be overlappin g
39 // we don't bother to check here as the we'll find their intersections from the 39 // we don't bother to check here as the we'll find their intersections from the
40 // corner to quad tests. 40 // corner to quad tests.
41 if (!denom) 41 if (!denom)
42 return false; 42 return false;
43 43
44 float s = perpProduct(v, w) / denom; 44 float s = perpProduct(v, w) / denom;
45 if (s < 0 || s > 1) 45 if (s < 0 || s > 1)
46 return false; 46 return false;
47 47
48 float t = perpProduct(u, w) / denom; 48 float t = perpProduct(u, w) / denom;
49 if (t < 0 || t > 1) 49 if (t < 0 || t > 1)
50 return false; 50 return false;
51 51
52 u.scale(s); 52 u.Scale(s);
53 r = a + u; 53 r = a + u;
54 return true; 54 return true;
55 } 55 }
56 56
57 GraphNode::GraphNode(LayerImpl* layerImpl) 57 GraphNode::GraphNode(LayerImpl* layerImpl)
58 : layer(layerImpl) 58 : layer(layerImpl)
59 , incomingEdgeWeight(0) 59 , incomingEdgeWeight(0)
60 { 60 {
61 } 61 }
62 62
(...skipping 11 matching lines...) Expand all
74 } 74 }
75 75
76 // Checks whether layer "a" draws on top of layer "b". The weight value returned is an indication of 76 // Checks whether layer "a" draws on top of layer "b". The weight value returned is an indication of
77 // the maximum z-depth difference between the layers or zero if the layers are f ound to be intesecting 77 // the maximum z-depth difference between the layers or zero if the layers are f ound to be intesecting
78 // (some features are in front and some are behind). 78 // (some features are in front and some are behind).
79 LayerSorter::ABCompareResult LayerSorter::checkOverlap(LayerShape* a, LayerShape * b, float zThreshold, float& weight) 79 LayerSorter::ABCompareResult LayerSorter::checkOverlap(LayerShape* a, LayerShape * b, float zThreshold, float& weight)
80 { 80 {
81 weight = 0; 81 weight = 0;
82 82
83 // Early out if the projected bounds don't overlap. 83 // Early out if the projected bounds don't overlap.
84 if (!a->projectedBounds.intersects(b->projectedBounds)) 84 if (!a->projectedBounds.Intersects(b->projectedBounds))
85 return None; 85 return None;
86 86
87 FloatPoint aPoints[4] = {a->projectedQuad.p1(), a->projectedQuad.p2(), a->pr ojectedQuad.p3(), a->projectedQuad.p4() }; 87 gfx::PointF aPoints[4] = {a->projectedQuad.p1(), a->projectedQuad.p2(), a->p rojectedQuad.p3(), a->projectedQuad.p4() };
88 FloatPoint bPoints[4] = {b->projectedQuad.p1(), b->projectedQuad.p2(), b->pr ojectedQuad.p3(), b->projectedQuad.p4() }; 88 gfx::PointF bPoints[4] = {b->projectedQuad.p1(), b->projectedQuad.p2(), b->p rojectedQuad.p3(), b->projectedQuad.p4() };
89 89
90 // Make a list of points that inside both layer quad projections. 90 // Make a list of points that inside both layer quad projections.
91 std::vector<FloatPoint> overlapPoints; 91 std::vector<gfx::PointF> overlapPoints;
92 92
93 // Check all four corners of one layer against the other layer's quad. 93 // Check all four corners of one layer against the other layer's quad.
94 for (int i = 0; i < 4; ++i) { 94 for (int i = 0; i < 4; ++i) {
95 if (a->projectedQuad.containsPoint(bPoints[i])) 95 if (a->projectedQuad.containsPoint(bPoints[i]))
96 overlapPoints.push_back(bPoints[i]); 96 overlapPoints.push_back(bPoints[i]);
97 if (b->projectedQuad.containsPoint(aPoints[i])) 97 if (b->projectedQuad.containsPoint(aPoints[i]))
98 overlapPoints.push_back(aPoints[i]); 98 overlapPoints.push_back(aPoints[i]);
99 } 99 }
100 100
101 // Check all the edges of one layer for intersection with the other layer's edges. 101 // Check all the edges of one layer for intersection with the other layer's edges.
102 FloatPoint r; 102 gfx::PointF r;
103 for (int ea = 0; ea < 4; ++ea) 103 for (int ea = 0; ea < 4; ++ea)
104 for (int eb = 0; eb < 4; ++eb) 104 for (int eb = 0; eb < 4; ++eb)
105 if (edgeEdgeTest(aPoints[ea], aPoints[(ea + 1) % 4], 105 if (edgeEdgeTest(aPoints[ea], aPoints[(ea + 1) % 4],
106 bPoints[eb], bPoints[(eb + 1) % 4], 106 bPoints[eb], bPoints[(eb + 1) % 4],
107 r)) 107 r))
108 overlapPoints.push_back(r); 108 overlapPoints.push_back(r);
109 109
110 if (overlapPoints.empty()) 110 if (overlapPoints.empty())
111 return None; 111 return None;
112 112
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 LayerShape::LayerShape() 146 LayerShape::LayerShape()
147 { 147 {
148 } 148 }
149 149
150 LayerShape::LayerShape(float width, float height, const WebTransformationMatrix& drawTransform) 150 LayerShape::LayerShape(float width, float height, const WebTransformationMatrix& drawTransform)
151 { 151 {
152 FloatQuad layerQuad(FloatRect(0, 0, width, height)); 152 FloatQuad layerQuad(FloatRect(0, 0, width, height));
153 153
154 // Compute the projection of the layer quad onto the z = 0 plane. 154 // Compute the projection of the layer quad onto the z = 0 plane.
155 155
156 FloatPoint clippedQuad[8]; 156 gfx::PointF clippedQuad[8];
157 int numVerticesInClippedQuad; 157 int numVerticesInClippedQuad;
158 MathUtil::mapClippedQuad(drawTransform, layerQuad, clippedQuad, numVerticesI nClippedQuad); 158 MathUtil::mapClippedQuad(drawTransform, layerQuad, clippedQuad, numVerticesI nClippedQuad);
159 159
160 if (numVerticesInClippedQuad < 3) { 160 if (numVerticesInClippedQuad < 3) {
161 projectedBounds = FloatRect(); 161 projectedBounds = FloatRect();
162 return; 162 return;
163 } 163 }
164 164
165 projectedBounds = MathUtil::computeEnclosingRectOfVertices(clippedQuad, numV erticesInClippedQuad); 165 projectedBounds = MathUtil::computeEnclosingRectOfVertices(clippedQuad, numV erticesInClippedQuad);
166 166
(...skipping 16 matching lines...) Expand all
183 FloatPoint3D c2 = MathUtil::mapPoint(drawTransform, FloatPoint3D(0, 1, 0), c lipped); 183 FloatPoint3D c2 = MathUtil::mapPoint(drawTransform, FloatPoint3D(0, 1, 0), c lipped);
184 FloatPoint3D c3 = MathUtil::mapPoint(drawTransform, FloatPoint3D(1, 0, 0), c lipped); 184 FloatPoint3D c3 = MathUtil::mapPoint(drawTransform, FloatPoint3D(1, 0, 0), c lipped);
185 // FIXME: Deal with clipping. 185 // FIXME: Deal with clipping.
186 FloatPoint3D c12 = c2 - c1; 186 FloatPoint3D c12 = c2 - c1;
187 FloatPoint3D c13 = c3 - c1; 187 FloatPoint3D c13 = c3 - c1;
188 layerNormal = c13.cross(c12); 188 layerNormal = c13.cross(c12);
189 189
190 transformOrigin = c1; 190 transformOrigin = c1;
191 } 191 }
192 192
193 LayerShape::~LayerShape()
194 {
195 }
196
193 // Returns the Z coordinate of a point on the layer that projects 197 // Returns the Z coordinate of a point on the layer that projects
194 // to point p which lies on the z = 0 plane. It does it by computing the 198 // to point p which lies on the z = 0 plane. It does it by computing the
195 // intersection of a line starting from p along the Z axis and the plane 199 // intersection of a line starting from p along the Z axis and the plane
196 // of the layer. 200 // of the layer.
197 float LayerShape::layerZFromProjectedPoint(const FloatPoint& p) const 201 float LayerShape::layerZFromProjectedPoint(const gfx::PointF& p) const
198 { 202 {
199 const FloatPoint3D zAxis(0, 0, 1); 203 const FloatPoint3D zAxis(0, 0, 1);
200 FloatPoint3D w = FloatPoint3D(p) - transformOrigin; 204 FloatPoint3D w = FloatPoint3D(cc::FloatPoint(p)) - transformOrigin;
201 205
202 float d = layerNormal.dot(zAxis); 206 float d = layerNormal.dot(zAxis);
203 float n = -layerNormal.dot(w); 207 float n = -layerNormal.dot(w);
204 208
205 // Check if layer is parallel to the z = 0 axis which will make it 209 // Check if layer is parallel to the z = 0 axis which will make it
206 // invisible and hence returning zero is fine. 210 // invisible and hence returning zero is fine.
207 if (!d) 211 if (!d)
208 return 0; 212 return 0;
209 213
210 // The intersection point would be given by: 214 // The intersection point would be given by:
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 *it = sortedList[count++]->layer; 407 *it = sortedList[count++]->layer;
404 408
405 DVLOG(2) << "Sorting end ----"; 409 DVLOG(2) << "Sorting end ----";
406 410
407 m_nodes.clear(); 411 m_nodes.clear();
408 m_edges.clear(); 412 m_edges.clear();
409 m_activeEdges.clear(); 413 m_activeEdges.clear();
410 } 414 }
411 415
412 } 416 }
OLDNEW
« no previous file with comments | « cc/layer_sorter.h ('k') | cc/layer_tiling_data.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698