| 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 #ifndef CC_OUTPUT_BSP_TREE_H_ | 5 #ifndef CC_OUTPUT_BSP_TREE_H_ |
| 6 #define CC_OUTPUT_BSP_TREE_H_ | 6 #define CC_OUTPUT_BSP_TREE_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include <deque> | 10 #include <deque> |
| 11 #include <memory> |
| 11 #include <vector> | 12 #include <vector> |
| 12 | 13 |
| 13 #include "base/memory/scoped_ptr.h" | |
| 14 #include "cc/output/bsp_compare_result.h" | 14 #include "cc/output/bsp_compare_result.h" |
| 15 #include "cc/quads/draw_polygon.h" | 15 #include "cc/quads/draw_polygon.h" |
| 16 | 16 |
| 17 namespace cc { | 17 namespace cc { |
| 18 | 18 |
| 19 struct BspNode { | 19 struct BspNode { |
| 20 // This represents the splitting plane. | 20 // This represents the splitting plane. |
| 21 scoped_ptr<DrawPolygon> node_data; | 21 std::unique_ptr<DrawPolygon> node_data; |
| 22 // This represents any coplanar geometry we found while building the BSP. | 22 // This represents any coplanar geometry we found while building the BSP. |
| 23 std::vector<scoped_ptr<DrawPolygon>> coplanars_front; | 23 std::vector<std::unique_ptr<DrawPolygon>> coplanars_front; |
| 24 std::vector<scoped_ptr<DrawPolygon>> coplanars_back; | 24 std::vector<std::unique_ptr<DrawPolygon>> coplanars_back; |
| 25 | 25 |
| 26 scoped_ptr<BspNode> back_child; | 26 std::unique_ptr<BspNode> back_child; |
| 27 scoped_ptr<BspNode> front_child; | 27 std::unique_ptr<BspNode> front_child; |
| 28 | 28 |
| 29 explicit BspNode(scoped_ptr<DrawPolygon> data); | 29 explicit BspNode(std::unique_ptr<DrawPolygon> data); |
| 30 ~BspNode(); | 30 ~BspNode(); |
| 31 }; | 31 }; |
| 32 | 32 |
| 33 class CC_EXPORT BspTree { | 33 class CC_EXPORT BspTree { |
| 34 public: | 34 public: |
| 35 explicit BspTree(std::deque<scoped_ptr<DrawPolygon>>* list); | 35 explicit BspTree(std::deque<std::unique_ptr<DrawPolygon>>* list); |
| 36 scoped_ptr<BspNode>& root() { return root_; } | 36 std::unique_ptr<BspNode>& root() { return root_; } |
| 37 | 37 |
| 38 template <typename ActionHandlerType> | 38 template <typename ActionHandlerType> |
| 39 void TraverseWithActionHandler(ActionHandlerType* action_handler) const { | 39 void TraverseWithActionHandler(ActionHandlerType* action_handler) const { |
| 40 if (root_) { | 40 if (root_) { |
| 41 WalkInOrderRecursion<ActionHandlerType>(action_handler, root_.get()); | 41 WalkInOrderRecursion<ActionHandlerType>(action_handler, root_.get()); |
| 42 } | 42 } |
| 43 } | 43 } |
| 44 | 44 |
| 45 ~BspTree(); | 45 ~BspTree(); |
| 46 | 46 |
| 47 private: | 47 private: |
| 48 scoped_ptr<BspNode> root_; | 48 std::unique_ptr<BspNode> root_; |
| 49 | 49 |
| 50 void FromList(std::vector<scoped_ptr<DrawPolygon>>* list); | 50 void FromList(std::vector<std::unique_ptr<DrawPolygon>>* list); |
| 51 void BuildTree(BspNode* node, std::deque<scoped_ptr<DrawPolygon>>* data); | 51 void BuildTree(BspNode* node, std::deque<std::unique_ptr<DrawPolygon>>* data); |
| 52 | 52 |
| 53 template <typename ActionHandlerType> | 53 template <typename ActionHandlerType> |
| 54 void WalkInOrderAction(ActionHandlerType* action_handler, | 54 void WalkInOrderAction(ActionHandlerType* action_handler, |
| 55 DrawPolygon* item) const { | 55 DrawPolygon* item) const { |
| 56 (*action_handler)(item); | 56 (*action_handler)(item); |
| 57 } | 57 } |
| 58 | 58 |
| 59 template <typename ActionHandlerType> | 59 template <typename ActionHandlerType> |
| 60 void WalkInOrderVisitNodes( | 60 void WalkInOrderVisitNodes( |
| 61 ActionHandlerType* action_handler, | 61 ActionHandlerType* action_handler, |
| 62 const BspNode* node, | 62 const BspNode* node, |
| 63 const BspNode* first_child, | 63 const BspNode* first_child, |
| 64 const BspNode* second_child, | 64 const BspNode* second_child, |
| 65 const std::vector<scoped_ptr<DrawPolygon>>& first_coplanars, | 65 const std::vector<std::unique_ptr<DrawPolygon>>& first_coplanars, |
| 66 const std::vector<scoped_ptr<DrawPolygon>>& second_coplanars) const { | 66 const std::vector<std::unique_ptr<DrawPolygon>>& second_coplanars) const { |
| 67 if (first_child) { | 67 if (first_child) { |
| 68 WalkInOrderRecursion(action_handler, first_child); | 68 WalkInOrderRecursion(action_handler, first_child); |
| 69 } | 69 } |
| 70 for (size_t i = 0; i < first_coplanars.size(); i++) { | 70 for (size_t i = 0; i < first_coplanars.size(); i++) { |
| 71 WalkInOrderAction(action_handler, first_coplanars[i].get()); | 71 WalkInOrderAction(action_handler, first_coplanars[i].get()); |
| 72 } | 72 } |
| 73 WalkInOrderAction(action_handler, node->node_data.get()); | 73 WalkInOrderAction(action_handler, node->node_data.get()); |
| 74 for (size_t i = 0; i < second_coplanars.size(); i++) { | 74 for (size_t i = 0; i < second_coplanars.size(); i++) { |
| 75 WalkInOrderAction(action_handler, second_coplanars[i].get()); | 75 WalkInOrderAction(action_handler, second_coplanars[i].get()); |
| 76 } | 76 } |
| (...skipping 29 matching lines...) Expand all Loading... |
| 106 static BspCompareResult GetNodePositionRelative(const DrawPolygon& node_a, | 106 static BspCompareResult GetNodePositionRelative(const DrawPolygon& node_a, |
| 107 const DrawPolygon& node_b); | 107 const DrawPolygon& node_b); |
| 108 // Returns whether or not our viewer is in front of or behind the plane | 108 // Returns whether or not our viewer is in front of or behind the plane |
| 109 // defined by this polygon/node | 109 // defined by this polygon/node |
| 110 static BspCompareResult GetCameraPositionRelative(const DrawPolygon& node); | 110 static BspCompareResult GetCameraPositionRelative(const DrawPolygon& node); |
| 111 }; | 111 }; |
| 112 | 112 |
| 113 } // namespace cc | 113 } // namespace cc |
| 114 | 114 |
| 115 #endif // CC_OUTPUT_BSP_TREE_H_ | 115 #endif // CC_OUTPUT_BSP_TREE_H_ |
| OLD | NEW |