OLD | NEW |
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/output/bsp_tree.h" | 5 #include "cc/output/bsp_tree.h" |
6 | 6 |
| 7 #include <memory> |
7 #include <vector> | 8 #include <vector> |
8 | 9 |
9 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/ptr_util.h" |
10 #include "cc/base/container_util.h" | 11 #include "cc/base/container_util.h" |
11 #include "cc/output/bsp_compare_result.h" | 12 #include "cc/output/bsp_compare_result.h" |
12 #include "cc/quads/draw_polygon.h" | 13 #include "cc/quads/draw_polygon.h" |
13 | 14 |
14 namespace cc { | 15 namespace cc { |
15 | 16 |
16 BspNode::BspNode(scoped_ptr<DrawPolygon> data) : node_data(std::move(data)) {} | 17 BspNode::BspNode(std::unique_ptr<DrawPolygon> data) |
| 18 : node_data(std::move(data)) {} |
17 | 19 |
18 BspNode::~BspNode() { | 20 BspNode::~BspNode() { |
19 } | 21 } |
20 | 22 |
21 BspTree::BspTree(std::deque<scoped_ptr<DrawPolygon>>* list) { | 23 BspTree::BspTree(std::deque<std::unique_ptr<DrawPolygon>>* list) { |
22 if (list->size() == 0) | 24 if (list->size() == 0) |
23 return; | 25 return; |
24 | 26 |
25 root_ = make_scoped_ptr(new BspNode(PopFront(list))); | 27 root_ = base::WrapUnique(new BspNode(PopFront(list))); |
26 BuildTree(root_.get(), list); | 28 BuildTree(root_.get(), list); |
27 } | 29 } |
28 | 30 |
29 // The idea behind using a deque for BuildTree's input is that we want to be | 31 // The idea behind using a deque for BuildTree's input is that we want to be |
30 // able to place polygons that we've decided aren't splitting plane candidates | 32 // able to place polygons that we've decided aren't splitting plane candidates |
31 // at the back of the queue while moving the candidate splitting planes to the | 33 // at the back of the queue while moving the candidate splitting planes to the |
32 // front when the heuristic decides that they're a better choice. This way we | 34 // front when the heuristic decides that they're a better choice. This way we |
33 // can always simply just take from the front of the deque for our node's | 35 // can always simply just take from the front of the deque for our node's |
34 // data. | 36 // data. |
35 void BspTree::BuildTree(BspNode* node, | 37 void BspTree::BuildTree( |
36 std::deque<scoped_ptr<DrawPolygon>>* polygon_list) { | 38 BspNode* node, |
37 std::deque<scoped_ptr<DrawPolygon>> front_list; | 39 std::deque<std::unique_ptr<DrawPolygon>>* polygon_list) { |
38 std::deque<scoped_ptr<DrawPolygon>> back_list; | 40 std::deque<std::unique_ptr<DrawPolygon>> front_list; |
| 41 std::deque<std::unique_ptr<DrawPolygon>> back_list; |
39 | 42 |
40 // We take in a list of polygons at this level of the tree, and have to | 43 // We take in a list of polygons at this level of the tree, and have to |
41 // find a splitting plane, then classify polygons as either in front of | 44 // find a splitting plane, then classify polygons as either in front of |
42 // or behind that splitting plane. | 45 // or behind that splitting plane. |
43 while (!polygon_list->empty()) { | 46 while (!polygon_list->empty()) { |
44 // Is this particular polygon in front of or behind our splitting polygon. | 47 // Is this particular polygon in front of or behind our splitting polygon. |
45 BspCompareResult comparer_result = | 48 BspCompareResult comparer_result = |
46 GetNodePositionRelative(*polygon_list->front(), *(node->node_data)); | 49 GetNodePositionRelative(*polygon_list->front(), *(node->node_data)); |
47 | 50 |
48 // If it's clearly behind or in front of the splitting plane, we use the | 51 // If it's clearly behind or in front of the splitting plane, we use the |
49 // heuristic to decide whether or not we should put it at the back | 52 // heuristic to decide whether or not we should put it at the back |
50 // or front of the list. | 53 // or front of the list. |
51 switch (comparer_result) { | 54 switch (comparer_result) { |
52 case BSP_FRONT: | 55 case BSP_FRONT: |
53 front_list.push_back(PopFront(polygon_list)); | 56 front_list.push_back(PopFront(polygon_list)); |
54 break; | 57 break; |
55 case BSP_BACK: | 58 case BSP_BACK: |
56 back_list.push_back(PopFront(polygon_list)); | 59 back_list.push_back(PopFront(polygon_list)); |
57 break; | 60 break; |
58 case BSP_SPLIT: | 61 case BSP_SPLIT: |
59 { | 62 { |
60 scoped_ptr<DrawPolygon> polygon; | 63 std::unique_ptr<DrawPolygon> polygon; |
61 scoped_ptr<DrawPolygon> new_front; | 64 std::unique_ptr<DrawPolygon> new_front; |
62 scoped_ptr<DrawPolygon> new_back; | 65 std::unique_ptr<DrawPolygon> new_back; |
63 // Time to split this geometry, *it needs to be split by node_data. | 66 // Time to split this geometry, *it needs to be split by node_data. |
64 polygon = PopFront(polygon_list); | 67 polygon = PopFront(polygon_list); |
65 bool split_result = | 68 bool split_result = |
66 polygon->Split(*(node->node_data), &new_front, &new_back); | 69 polygon->Split(*(node->node_data), &new_front, &new_back); |
67 DCHECK(split_result); | 70 DCHECK(split_result); |
68 if (!split_result) { | 71 if (!split_result) { |
69 break; | 72 break; |
70 } | 73 } |
71 front_list.push_back(std::move(new_front)); | 74 front_list.push_back(std::move(new_front)); |
72 back_list.push_back(std::move(new_back)); | 75 back_list.push_back(std::move(new_back)); |
73 break; | 76 break; |
74 } | 77 } |
75 case BSP_COPLANAR_FRONT: | 78 case BSP_COPLANAR_FRONT: |
76 node->coplanars_front.push_back(PopFront(polygon_list)); | 79 node->coplanars_front.push_back(PopFront(polygon_list)); |
77 break; | 80 break; |
78 case BSP_COPLANAR_BACK: | 81 case BSP_COPLANAR_BACK: |
79 node->coplanars_back.push_back(PopFront(polygon_list)); | 82 node->coplanars_back.push_back(PopFront(polygon_list)); |
80 break; | 83 break; |
81 default: | 84 default: |
82 NOTREACHED(); | 85 NOTREACHED(); |
83 break; | 86 break; |
84 } | 87 } |
85 } | 88 } |
86 | 89 |
87 // Build the back subtree using the front of the back_list as our splitter. | 90 // Build the back subtree using the front of the back_list as our splitter. |
88 if (back_list.size() > 0) { | 91 if (back_list.size() > 0) { |
89 node->back_child = make_scoped_ptr(new BspNode(PopFront(&back_list))); | 92 node->back_child = base::WrapUnique(new BspNode(PopFront(&back_list))); |
90 BuildTree(node->back_child.get(), &back_list); | 93 BuildTree(node->back_child.get(), &back_list); |
91 } | 94 } |
92 | 95 |
93 // Build the front subtree using the front of the front_list as our splitter. | 96 // Build the front subtree using the front of the front_list as our splitter. |
94 if (front_list.size() > 0) { | 97 if (front_list.size() > 0) { |
95 node->front_child = make_scoped_ptr(new BspNode(PopFront(&front_list))); | 98 node->front_child = base::WrapUnique(new BspNode(PopFront(&front_list))); |
96 BuildTree(node->front_child.get(), &front_list); | 99 BuildTree(node->front_child.get(), &front_list); |
97 } | 100 } |
98 } | 101 } |
99 | 102 |
100 BspCompareResult BspTree::GetNodePositionRelative(const DrawPolygon& node_a, | 103 BspCompareResult BspTree::GetNodePositionRelative(const DrawPolygon& node_a, |
101 const DrawPolygon& node_b) { | 104 const DrawPolygon& node_b) { |
102 return DrawPolygon::SideCompare(node_a, node_b); | 105 return DrawPolygon::SideCompare(node_a, node_b); |
103 } | 106 } |
104 | 107 |
105 // The base comparer with 0,0,0 as camera position facing forward | 108 // The base comparer with 0,0,0 as camera position facing forward |
106 BspCompareResult BspTree::GetCameraPositionRelative(const DrawPolygon& node) { | 109 BspCompareResult BspTree::GetCameraPositionRelative(const DrawPolygon& node) { |
107 if (node.normal().z() > 0.0f) { | 110 if (node.normal().z() > 0.0f) { |
108 return BSP_FRONT; | 111 return BSP_FRONT; |
109 } | 112 } |
110 return BSP_BACK; | 113 return BSP_BACK; |
111 } | 114 } |
112 | 115 |
113 BspTree::~BspTree() { | 116 BspTree::~BspTree() { |
114 } | 117 } |
115 | 118 |
116 } // namespace cc | 119 } // namespace cc |
OLD | NEW |