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

Side by Side Diff: cc/quads/draw_polygon.cc

Issue 1001833005: Update from https://crrev.com/320343 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Supress Created 5 years, 9 months 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
« no previous file with comments | « cc/quads/draw_polygon.h ('k') | cc/quads/draw_quad.cc » ('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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/quads/draw_polygon.h" 5 #include "cc/quads/draw_polygon.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "cc/output/bsp_compare_result.h" 9 #include "cc/output/bsp_compare_result.h"
10 #include "cc/quads/draw_quad.h" 10 #include "cc/quads/draw_quad.h"
11 11
12 namespace { 12 namespace {
13 // This allows for some imperfection in the normal comparison when checking if 13 // This allows for some imperfection in the normal comparison when checking if
14 // two pieces of geometry are coplanar. 14 // two pieces of geometry are coplanar.
15 static const float coplanar_dot_epsilon = 0.01f; 15 static const float coplanar_dot_epsilon = 0.001f;
16 // This threshold controls how "thick" a plane is. If a point's distance is 16 // This threshold controls how "thick" a plane is. If a point's distance is
17 // <= |compare_threshold|, then it is considered on the plane. Only when this 17 // <= |compare_threshold|, then it is considered on the plane. Only when this
18 // boundary is crossed do we consider doing splitting. 18 // boundary is crossed do we consider doing splitting.
19 static const float compare_threshold = 1.0f; 19 static const float compare_threshold = 1.0f;
20 // |split_threshold| is lower in this case because we want the points created 20 // |split_threshold| is lower in this case because we want the points created
21 // during splitting to be well within the range of |compare_threshold| for 21 // during splitting to be well within the range of |compare_threshold| for
22 // comparison purposes. The splitting operation will produce intersection points 22 // comparison purposes. The splitting operation will produce intersection points
23 // that fit within a tighter distance to the splitting plane as a result of this 23 // that fit within a tighter distance to the splitting plane as a result of this
24 // value. By using a value >= |compare_threshold| we run the risk of creating 24 // value. By using a value >= |compare_threshold| we run the risk of creating
25 // points that SHOULD be intersecting the "thick plane", but actually fail to 25 // points that SHOULD be intersecting the "thick plane", but actually fail to
26 // test positively for it because |split_threshold| allowed them to be outside 26 // test positively for it because |split_threshold| allowed them to be outside
27 // this range. 27 // this range.
28 // This is really supposd to be compare_threshold / 2.0f, but that would
29 // create another static initializer.
28 static const float split_threshold = 0.5f; 30 static const float split_threshold = 0.5f;
31
32 static const float normalized_threshold = 0.001f;
29 } // namespace 33 } // namespace
30 34
31 namespace cc { 35 namespace cc {
32 36
33 gfx::Vector3dF DrawPolygon::default_normal = gfx::Vector3dF(0.0f, 0.0f, -1.0f);
34
35 DrawPolygon::DrawPolygon() { 37 DrawPolygon::DrawPolygon() {
36 } 38 }
37 39
38 DrawPolygon::DrawPolygon(DrawQuad* original, 40 DrawPolygon::DrawPolygon(const DrawQuad* original,
39 const std::vector<gfx::Point3F>& in_points, 41 const std::vector<gfx::Point3F>& in_points,
40 const gfx::Vector3dF& normal, 42 const gfx::Vector3dF& normal,
41 int draw_order_index) 43 int draw_order_index)
42 : order_index_(draw_order_index), original_ref_(original) { 44 : order_index_(draw_order_index), original_ref_(original), is_split_(true) {
43 for (size_t i = 0; i < in_points.size(); i++) { 45 for (size_t i = 0; i < in_points.size(); i++) {
44 points_.push_back(in_points[i]); 46 points_.push_back(in_points[i]);
45 } 47 }
46 normal_ = normal; 48 normal_ = normal;
47 } 49 }
48 50
49 // This takes the original DrawQuad that this polygon should be based on, 51 // This takes the original DrawQuad that this polygon should be based on,
50 // a visible content rect to make the 4 corner points from, and a transformation 52 // a visible content rect to make the 4 corner points from, and a transformation
51 // to move it and its normal into screen space. 53 // to move it and its normal into screen space.
52 DrawPolygon::DrawPolygon(DrawQuad* original_ref, 54 DrawPolygon::DrawPolygon(const DrawQuad* original_ref,
53 const gfx::RectF& visible_content_rect, 55 const gfx::RectF& visible_content_rect,
54 const gfx::Transform& transform, 56 const gfx::Transform& transform,
55 int draw_order_index) 57 int draw_order_index)
56 : order_index_(draw_order_index), original_ref_(original_ref) { 58 : normal_(0.0f, 0.0f, 1.0f),
57 normal_ = default_normal; 59 order_index_(draw_order_index),
60 original_ref_(original_ref),
61 is_split_(false) {
58 gfx::Point3F points[8]; 62 gfx::Point3F points[8];
59 int num_vertices_in_clipped_quad; 63 int num_vertices_in_clipped_quad;
60 gfx::QuadF send_quad(visible_content_rect); 64 gfx::QuadF send_quad(visible_content_rect);
61 65
62 // Doing this mapping here is very important, since we can't just transform 66 // Doing this mapping here is very important, since we can't just transform
63 // the points without clipping and not run into strange geometry issues when 67 // the points without clipping and not run into strange geometry issues when
64 // crossing w = 0. At this point, in the constructor, we know that we're 68 // crossing w = 0. At this point, in the constructor, we know that we're
65 // working with a quad, so we can reuse the MathUtil::MapClippedQuad3d 69 // working with a quad, so we can reuse the MathUtil::MapClippedQuad3d
66 // function instead of writing a generic polygon version of it. 70 // function instead of writing a generic polygon version of it.
67 MathUtil::MapClippedQuad3d( 71 MathUtil::MapClippedQuad3d(
(...skipping 22 matching lines...) Expand all
90 float DrawPolygon::SignedPointDistance(const gfx::Point3F& point) const { 94 float DrawPolygon::SignedPointDistance(const gfx::Point3F& point) const {
91 return gfx::DotProduct(point - points_[0], normal_); 95 return gfx::DotProduct(point - points_[0], normal_);
92 } 96 }
93 97
94 // Checks whether or not shape a lies on the front or back side of b, or 98 // Checks whether or not shape a lies on the front or back side of b, or
95 // whether they should be considered coplanar. If on the back side, we 99 // whether they should be considered coplanar. If on the back side, we
96 // say A_BEFORE_B because it should be drawn in that order. 100 // say A_BEFORE_B because it should be drawn in that order.
97 // Assumes that layers are split and there are no intersecting planes. 101 // Assumes that layers are split and there are no intersecting planes.
98 BspCompareResult DrawPolygon::SideCompare(const DrawPolygon& a, 102 BspCompareResult DrawPolygon::SideCompare(const DrawPolygon& a,
99 const DrawPolygon& b) { 103 const DrawPolygon& b) {
104 // Let's make sure that both of these are normalized.
105 DCHECK_GE(normalized_threshold, std::abs(a.normal_.LengthSquared() - 1.0f));
106 DCHECK_GE(normalized_threshold, std::abs(b.normal_.LengthSquared() - 1.0f));
100 // Right away let's check if they're coplanar 107 // Right away let's check if they're coplanar
101 double dot = gfx::DotProduct(a.normal_, b.normal_); 108 double dot = gfx::DotProduct(a.normal_, b.normal_);
102 float sign = 0.0f; 109 float sign = 0.0f;
103 bool normal_match = false; 110 bool normal_match = false;
104 // This check assumes that the normals are normalized. 111 // This check assumes that the normals are normalized.
105 if (std::abs(dot) >= 1.0f - coplanar_dot_epsilon) { 112 if (std::abs(dot) >= 1.0f - coplanar_dot_epsilon) {
106 normal_match = true; 113 normal_match = true;
107 // The normals are matching enough that we only have to test one point. 114 // The normals are matching enough that we only have to test one point.
108 sign = gfx::DotProduct(a.points_[0] - b.points_[0], b.normal_); 115 sign = b.SignedPointDistance(a.points_[0]);
109 // Is it on either side of the splitter? 116 // Is it on either side of the splitter?
110 if (sign < -compare_threshold) { 117 if (sign < -compare_threshold) {
111 return BSP_BACK; 118 return BSP_BACK;
112 } 119 }
113 120
114 if (sign > compare_threshold) { 121 if (sign > compare_threshold) {
115 return BSP_FRONT; 122 return BSP_FRONT;
116 } 123 }
117 124
118 // No it wasn't, so the sign of the dot product of the normals 125 // No it wasn't, so the sign of the dot product of the normals
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 gfx::Point3F* intersection, 168 gfx::Point3F* intersection,
162 float distance_threshold) { 169 float distance_threshold) {
163 gfx::Vector3dF start_to_origin_vector = plane_origin - line_start; 170 gfx::Vector3dF start_to_origin_vector = plane_origin - line_start;
164 gfx::Vector3dF end_to_origin_vector = plane_origin - line_end; 171 gfx::Vector3dF end_to_origin_vector = plane_origin - line_end;
165 172
166 double start_distance = gfx::DotProduct(start_to_origin_vector, plane_normal); 173 double start_distance = gfx::DotProduct(start_to_origin_vector, plane_normal);
167 double end_distance = gfx::DotProduct(end_to_origin_vector, plane_normal); 174 double end_distance = gfx::DotProduct(end_to_origin_vector, plane_normal);
168 175
169 // The case where one vertex lies on the thick-plane and the other 176 // The case where one vertex lies on the thick-plane and the other
170 // is outside of it. 177 // is outside of it.
171 if (std::abs(start_distance) < distance_threshold && 178 if (std::abs(start_distance) <= distance_threshold &&
172 std::abs(end_distance) > distance_threshold) { 179 std::abs(end_distance) > distance_threshold) {
173 intersection->SetPoint(line_start.x(), line_start.y(), line_start.z()); 180 intersection->SetPoint(line_start.x(), line_start.y(), line_start.z());
174 return true; 181 return true;
175 } 182 }
176 183
177 // This is the case where we clearly cross the thick-plane. 184 // This is the case where we clearly cross the thick-plane.
178 if ((start_distance > distance_threshold && 185 if ((start_distance > distance_threshold &&
179 end_distance < -distance_threshold) || 186 end_distance < -distance_threshold) ||
180 (start_distance < -distance_threshold && 187 (start_distance < -distance_threshold &&
181 end_distance > distance_threshold)) { 188 end_distance > distance_threshold)) {
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 splitter.normal_, 270 splitter.normal_,
264 &intersections[current_intersection], 271 &intersections[current_intersection],
265 split_threshold)) { 272 split_threshold)) {
266 vertex_before[current_intersection] = current_vertex % points_size; 273 vertex_before[current_intersection] = current_vertex % points_size;
267 current_intersection++; 274 current_intersection++;
268 // We found both intersection points so we're done already. 275 // We found both intersection points so we're done already.
269 if (current_intersection == 2) { 276 if (current_intersection == 2) {
270 break; 277 break;
271 } 278 }
272 } 279 }
273 if (current_vertex++ > points_size) { 280 if (current_vertex++ > (points_size)) {
274 break; 281 break;
275 } 282 }
276 } 283 }
277 DCHECK_EQ(current_intersection, static_cast<size_t>(2)); 284 DCHECK_EQ(current_intersection, static_cast<size_t>(2));
278 285
279 // Since we found both the intersection points, we can begin building the 286 // Since we found both the intersection points, we can begin building the
280 // vertex set for both our new polygons. 287 // vertex set for both our new polygons.
281 size_t start1 = (vertex_before[0] + 1) % points_size; 288 size_t start1 = (vertex_before[0] + 1) % points_size;
282 size_t start2 = (vertex_before[1] + 1) % points_size; 289 size_t start2 = (vertex_before[1] + 1) % points_size;
283 size_t points_remaining = points_size; 290 size_t points_remaining = points_size;
284 291
285 // First polygon. 292 // First polygon.
286 out_points[0].push_back(intersections[0]); 293 out_points[0].push_back(intersections[0]);
294 DCHECK_GE(vertex_before[1], start1);
287 for (size_t i = start1; i <= vertex_before[1]; i++) { 295 for (size_t i = start1; i <= vertex_before[1]; i++) {
288 out_points[0].push_back(points_[i]); 296 out_points[0].push_back(points_[i]);
289 --points_remaining; 297 --points_remaining;
290 } 298 }
291 out_points[0].push_back(intersections[1]); 299 out_points[0].push_back(intersections[1]);
292 300
293 // Second polygon. 301 // Second polygon.
294 out_points[1].push_back(intersections[1]); 302 out_points[1].push_back(intersections[1]);
295 size_t index = start2; 303 size_t index = start2;
296 for (size_t i = 0; i < points_remaining; i++) { 304 for (size_t i = 0; i < points_remaining; i++) {
297 out_points[1].push_back(points_[index % points_size]); 305 out_points[1].push_back(points_[index % points_size]);
298 ++index; 306 ++index;
299 } 307 }
300 out_points[1].push_back(intersections[0]); 308 out_points[1].push_back(intersections[0]);
301 309
302 // Give both polygons the original splitting polygon's ID, so that they'll 310 // Give both polygons the original splitting polygon's ID, so that they'll
303 // still be sorted properly in co-planar instances. 311 // still be sorted properly in co-planar instances.
304 scoped_ptr<DrawPolygon> poly1( 312 scoped_ptr<DrawPolygon> poly1(
305 new DrawPolygon(original_ref_, out_points[0], normal_, order_index_)); 313 new DrawPolygon(original_ref_, out_points[0], normal_, order_index_));
306 scoped_ptr<DrawPolygon> poly2( 314 scoped_ptr<DrawPolygon> poly2(
307 new DrawPolygon(original_ref_, out_points[1], normal_, order_index_)); 315 new DrawPolygon(original_ref_, out_points[1], normal_, order_index_));
308 316
317 DCHECK_GE(poly1->points().size(), 3u);
318 DCHECK_GE(poly2->points().size(), 3u);
319
309 if (SideCompare(*poly1, splitter) == BSP_FRONT) { 320 if (SideCompare(*poly1, splitter) == BSP_FRONT) {
310 *front = poly1.Pass(); 321 *front = poly1.Pass();
311 *back = poly2.Pass(); 322 *back = poly2.Pass();
312 } else { 323 } else {
313 *front = poly2.Pass(); 324 *front = poly2.Pass();
314 *back = poly1.Pass(); 325 *back = poly1.Pass();
315 } 326 }
316 return true; 327 return true;
317 } 328 }
318 329
(...skipping 24 matching lines...) Expand all
343 quads->push_back( 354 quads->push_back(
344 gfx::QuadF(first, 355 gfx::QuadF(first,
345 gfx::PointF(points_[offset].x(), points_[offset].y()), 356 gfx::PointF(points_[offset].x(), points_[offset].y()),
346 gfx::PointF(points_[op1].x(), points_[op1].y()), 357 gfx::PointF(points_[op1].x(), points_[op1].y()),
347 gfx::PointF(points_[op2].x(), points_[op2].y()))); 358 gfx::PointF(points_[op2].x(), points_[op2].y())));
348 offset = op2; 359 offset = op2;
349 } 360 }
350 } 361 }
351 362
352 } // namespace cc 363 } // namespace cc
OLDNEW
« no previous file with comments | « cc/quads/draw_polygon.h ('k') | cc/quads/draw_quad.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698