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

Side by Side Diff: cc/tiles/raster_tile_priority_queue_all.cc

Issue 1437413002: cc: Remove ScopedPtrVector and cc::remove_if. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: update Created 5 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/tiles/raster_tile_priority_queue_all.h" 5 #include "cc/tiles/raster_tile_priority_queue_all.h"
6 6
7 #include "cc/tiles/tiling_set_raster_queue_all.h" 7 #include "cc/tiles/tiling_set_raster_queue_all.h"
8 8
9 namespace cc { 9 namespace cc {
10 10
11 namespace { 11 namespace {
12 12
13 class RasterOrderComparator { 13 class RasterOrderComparator {
14 public: 14 public:
15 explicit RasterOrderComparator(TreePriority tree_priority) 15 explicit RasterOrderComparator(TreePriority tree_priority)
16 : tree_priority_(tree_priority) {} 16 : tree_priority_(tree_priority) {}
17 17
18 bool operator()(const TilingSetRasterQueueAll* a_queue, 18 bool operator()(const scoped_ptr<TilingSetRasterQueueAll>& a_queue,
19 const TilingSetRasterQueueAll* b_queue) const { 19 const scoped_ptr<TilingSetRasterQueueAll>& b_queue) const {
20 // Note that in this function, we have to return true if and only if 20 // Note that in this function, we have to return true if and only if
21 // a is strictly lower priority than b. 21 // a is strictly lower priority than b.
22 const TilePriority& a_priority = a_queue->Top().priority(); 22 const TilePriority& a_priority = a_queue->Top().priority();
23 const TilePriority& b_priority = b_queue->Top().priority(); 23 const TilePriority& b_priority = b_queue->Top().priority();
24 bool prioritize_low_res = tree_priority_ == SMOOTHNESS_TAKES_PRIORITY; 24 bool prioritize_low_res = tree_priority_ == SMOOTHNESS_TAKES_PRIORITY;
25 25
26 // If the bin is the same but the resolution is not, then the order will be 26 // If the bin is the same but the resolution is not, then the order will be
27 // determined by whether we prioritize low res or not. 27 // determined by whether we prioritize low res or not.
28 // TODO(vmpstr): Remove this when TilePriority is no longer a member of Tile 28 // TODO(vmpstr): Remove this when TilePriority is no longer a member of Tile
29 // class but instead produced by the iterators. 29 // class but instead produced by the iterators.
(...skipping 14 matching lines...) Expand all
44 return b_priority.IsHigherPriorityThan(a_priority); 44 return b_priority.IsHigherPriorityThan(a_priority);
45 } 45 }
46 46
47 private: 47 private:
48 TreePriority tree_priority_; 48 TreePriority tree_priority_;
49 }; 49 };
50 50
51 void CreateTilingSetRasterQueues( 51 void CreateTilingSetRasterQueues(
52 const std::vector<PictureLayerImpl*>& layers, 52 const std::vector<PictureLayerImpl*>& layers,
53 TreePriority tree_priority, 53 TreePriority tree_priority,
54 ScopedPtrVector<TilingSetRasterQueueAll>* queues) { 54 std::vector<scoped_ptr<TilingSetRasterQueueAll>>* queues) {
55 DCHECK(queues->empty()); 55 DCHECK(queues->empty());
56 56
57 for (auto* layer : layers) { 57 for (auto* layer : layers) {
58 if (!layer->HasValidTilePriorities()) 58 if (!layer->HasValidTilePriorities())
59 continue; 59 continue;
60 60
61 PictureLayerTilingSet* tiling_set = layer->picture_layer_tiling_set(); 61 PictureLayerTilingSet* tiling_set = layer->picture_layer_tiling_set();
62 bool prioritize_low_res = tree_priority == SMOOTHNESS_TAKES_PRIORITY; 62 bool prioritize_low_res = tree_priority == SMOOTHNESS_TAKES_PRIORITY;
63 scoped_ptr<TilingSetRasterQueueAll> tiling_set_queue = make_scoped_ptr( 63 scoped_ptr<TilingSetRasterQueueAll> tiling_set_queue = make_scoped_ptr(
64 new TilingSetRasterQueueAll(tiling_set, prioritize_low_res)); 64 new TilingSetRasterQueueAll(tiling_set, prioritize_low_res));
65 // Queues will only contain non empty tiling sets. 65 // Queues will only contain non empty tiling sets.
66 if (!tiling_set_queue->IsEmpty()) 66 if (!tiling_set_queue->IsEmpty())
67 queues->push_back(tiling_set_queue.Pass()); 67 queues->push_back(tiling_set_queue.Pass());
68 } 68 }
69 queues->make_heap(RasterOrderComparator(tree_priority)); 69 std::make_heap(queues->begin(), queues->end(),
70 RasterOrderComparator(tree_priority));
70 } 71 }
71 72
72 } // namespace 73 } // namespace
73 74
74 RasterTilePriorityQueueAll::RasterTilePriorityQueueAll() { 75 RasterTilePriorityQueueAll::RasterTilePriorityQueueAll() {
75 } 76 }
76 77
77 RasterTilePriorityQueueAll::~RasterTilePriorityQueueAll() { 78 RasterTilePriorityQueueAll::~RasterTilePriorityQueueAll() {
78 } 79 }
79 80
80 void RasterTilePriorityQueueAll::Build( 81 void RasterTilePriorityQueueAll::Build(
81 const std::vector<PictureLayerImpl*>& active_layers, 82 const std::vector<PictureLayerImpl*>& active_layers,
82 const std::vector<PictureLayerImpl*>& pending_layers, 83 const std::vector<PictureLayerImpl*>& pending_layers,
83 TreePriority tree_priority) { 84 TreePriority tree_priority) {
84 tree_priority_ = tree_priority; 85 tree_priority_ = tree_priority;
85 86
86 CreateTilingSetRasterQueues(active_layers, tree_priority_, &active_queues_); 87 CreateTilingSetRasterQueues(active_layers, tree_priority_, &active_queues_);
87 CreateTilingSetRasterQueues(pending_layers, tree_priority_, &pending_queues_); 88 CreateTilingSetRasterQueues(pending_layers, tree_priority_, &pending_queues_);
88 } 89 }
89 90
90 bool RasterTilePriorityQueueAll::IsEmpty() const { 91 bool RasterTilePriorityQueueAll::IsEmpty() const {
91 return active_queues_.empty() && pending_queues_.empty(); 92 return active_queues_.empty() && pending_queues_.empty();
92 } 93 }
93 94
94 const PrioritizedTile& RasterTilePriorityQueueAll::Top() const { 95 const PrioritizedTile& RasterTilePriorityQueueAll::Top() const {
95 DCHECK(!IsEmpty()); 96 DCHECK(!IsEmpty());
96 const ScopedPtrVector<TilingSetRasterQueueAll>& next_queues = GetNextQueues(); 97 const auto& next_queues = GetNextQueues();
97 return next_queues.front()->Top(); 98 return next_queues.front()->Top();
98 } 99 }
99 100
100 void RasterTilePriorityQueueAll::Pop() { 101 void RasterTilePriorityQueueAll::Pop() {
101 DCHECK(!IsEmpty()); 102 DCHECK(!IsEmpty());
102 103
103 ScopedPtrVector<TilingSetRasterQueueAll>& next_queues = GetNextQueues(); 104 auto& next_queues = GetNextQueues();
104 next_queues.pop_heap(RasterOrderComparator(tree_priority_)); 105 std::pop_heap(next_queues.begin(), next_queues.end(),
105 TilingSetRasterQueueAll* queue = next_queues.back(); 106 RasterOrderComparator(tree_priority_));
107 TilingSetRasterQueueAll* queue = next_queues.back().get();
106 queue->Pop(); 108 queue->Pop();
107 109
108 // Remove empty queues. 110 // Remove empty queues.
109 if (queue->IsEmpty()) 111 if (queue->IsEmpty()) {
110 next_queues.pop_back(); 112 next_queues.pop_back();
111 else 113 } else {
112 next_queues.push_heap(RasterOrderComparator(tree_priority_)); 114 std::push_heap(next_queues.begin(), next_queues.end(),
115 RasterOrderComparator(tree_priority_));
116 }
113 } 117 }
114 118
115 ScopedPtrVector<TilingSetRasterQueueAll>& 119 std::vector<scoped_ptr<TilingSetRasterQueueAll>>&
116 RasterTilePriorityQueueAll::GetNextQueues() { 120 RasterTilePriorityQueueAll::GetNextQueues() {
117 return const_cast<ScopedPtrVector<TilingSetRasterQueueAll>&>( 121 const auto* const_this = static_cast<const RasterTilePriorityQueueAll*>(this);
118 static_cast<const RasterTilePriorityQueueAll*>(this)->GetNextQueues()); 122 const auto& const_queues = const_this->GetNextQueues();
123 return const_cast<std::vector<scoped_ptr<TilingSetRasterQueueAll>>&>(
124 const_queues);
119 } 125 }
120 126
121 const ScopedPtrVector<TilingSetRasterQueueAll>& 127 const std::vector<scoped_ptr<TilingSetRasterQueueAll>>&
122 RasterTilePriorityQueueAll::GetNextQueues() const { 128 RasterTilePriorityQueueAll::GetNextQueues() const {
123 DCHECK(!IsEmpty()); 129 DCHECK(!IsEmpty());
124 130
125 // If we only have one queue with tiles, return it. 131 // If we only have one queue with tiles, return it.
126 if (active_queues_.empty()) 132 if (active_queues_.empty())
127 return pending_queues_; 133 return pending_queues_;
128 if (pending_queues_.empty()) 134 if (pending_queues_.empty())
129 return active_queues_; 135 return active_queues_;
130 136
131 const PrioritizedTile& active_tile = active_queues_.front()->Top(); 137 const PrioritizedTile& active_tile = active_queues_.front()->Top();
(...skipping 30 matching lines...) Expand all
162 return active_queues_; 168 return active_queues_;
163 return pending_queues_; 169 return pending_queues_;
164 } 170 }
165 default: 171 default:
166 NOTREACHED(); 172 NOTREACHED();
167 return active_queues_; 173 return active_queues_;
168 } 174 }
169 } 175 }
170 176
171 } // namespace cc 177 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698