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 <list> | 7 #include <list> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "cc/base/scoped_ptr_deque.h" | 11 #include "cc/base/scoped_ptr_deque.h" |
12 #include "cc/base/scoped_ptr_vector.h" | 12 #include "cc/base/scoped_ptr_vector.h" |
13 #include "cc/output/bsp_compare_result.h" | 13 #include "cc/output/bsp_compare_result.h" |
14 #include "cc/quads/draw_polygon.h" | 14 #include "cc/quads/draw_polygon.h" |
15 | 15 |
16 namespace cc { | 16 namespace cc { |
17 | 17 |
18 BspNode::BspNode(scoped_ptr<DrawPolygon> data) : node_data(data.Pass()) { | 18 BspNode::BspNode(scoped_ptr<DrawPolygon> data) : node_data(data.Pass()) { |
19 } | 19 } |
20 | 20 |
21 BspNode::~BspNode() { | 21 BspNode::~BspNode() { |
22 } | 22 } |
23 | 23 |
24 BspTree::BspTree(ScopedPtrDeque<DrawPolygon>* list) { | 24 BspTree::BspTree(ScopedPtrDeque<DrawPolygon>* list) { |
25 if (list->size() == 0) | 25 if (list->size() == 0) |
26 return; | 26 return; |
27 | 27 |
28 root_ = scoped_ptr<BspNode>(new BspNode(list->take_front())); | 28 root_ = make_scoped_ptr(new BspNode(list->take_front())); |
29 BuildTree(root_.get(), list); | 29 BuildTree(root_.get(), list); |
30 } | 30 } |
31 | 31 |
32 // The idea behind using a deque for BuildTree's input is that we want to be | 32 // The idea behind using a deque for BuildTree's input is that we want to be |
33 // able to place polygons that we've decided aren't splitting plane candidates | 33 // able to place polygons that we've decided aren't splitting plane candidates |
34 // at the back of the queue while moving the candidate splitting planes to the | 34 // at the back of the queue while moving the candidate splitting planes to the |
35 // front when the heuristic decides that they're a better choice. This way we | 35 // front when the heuristic decides that they're a better choice. This way we |
36 // can always simply just take from the front of the deque for our node's | 36 // can always simply just take from the front of the deque for our node's |
37 // data. | 37 // data. |
38 void BspTree::BuildTree(BspNode* node, | 38 void BspTree::BuildTree(BspNode* node, |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 node->coplanars_back.push_back(polygon_list->take_front()); | 83 node->coplanars_back.push_back(polygon_list->take_front()); |
84 break; | 84 break; |
85 default: | 85 default: |
86 NOTREACHED(); | 86 NOTREACHED(); |
87 break; | 87 break; |
88 } | 88 } |
89 } | 89 } |
90 | 90 |
91 // Build the back subtree using the front of the back_list as our splitter. | 91 // Build the back subtree using the front of the back_list as our splitter. |
92 if (back_list.size() > 0) { | 92 if (back_list.size() > 0) { |
93 node->back_child = scoped_ptr<BspNode>(new BspNode(back_list.take_front())); | 93 node->back_child = make_scoped_ptr(new BspNode(back_list.take_front())); |
94 BuildTree(node->back_child.get(), &back_list); | 94 BuildTree(node->back_child.get(), &back_list); |
95 } | 95 } |
96 | 96 |
97 // Build the front subtree using the front of the front_list as our splitter. | 97 // Build the front subtree using the front of the front_list as our splitter. |
98 if (front_list.size() > 0) { | 98 if (front_list.size() > 0) { |
99 node->front_child = | 99 node->front_child = |
100 scoped_ptr<BspNode>(new BspNode(front_list.take_front())); | 100 scoped_ptr<BspNode>(new BspNode(front_list.take_front())); |
101 BuildTree(node->front_child.get(), &front_list); | 101 BuildTree(node->front_child.get(), &front_list); |
102 } | 102 } |
103 } | 103 } |
104 | 104 |
105 BspCompareResult BspTree::GetNodePositionRelative(const DrawPolygon& node_a, | 105 BspCompareResult BspTree::GetNodePositionRelative(const DrawPolygon& node_a, |
106 const DrawPolygon& node_b) { | 106 const DrawPolygon& node_b) { |
107 return DrawPolygon::SideCompare(node_a, node_b); | 107 return DrawPolygon::SideCompare(node_a, node_b); |
108 } | 108 } |
109 | 109 |
110 // The base comparer with 0,0,0 as camera position facing forward | 110 // The base comparer with 0,0,0 as camera position facing forward |
111 BspCompareResult BspTree::GetCameraPositionRelative(const DrawPolygon& node) { | 111 BspCompareResult BspTree::GetCameraPositionRelative(const DrawPolygon& node) { |
112 if (node.normal().z() > 0.0f) { | 112 if (node.normal().z() > 0.0f) { |
113 return BSP_FRONT; | 113 return BSP_FRONT; |
114 } | 114 } |
115 return BSP_BACK; | 115 return BSP_BACK; |
116 } | 116 } |
117 | 117 |
118 BspTree::~BspTree() { | 118 BspTree::~BspTree() { |
119 } | 119 } |
120 | 120 |
121 } // namespace cc | 121 } // namespace cc |
OLD | NEW |