Chromium Code Reviews| 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/resources/raster_tile_priority_queue.h" | 5 #include "cc/resources/raster_tile_priority_queue.h" |
| 6 | 6 |
| 7 namespace cc { | 7 namespace cc { |
| 8 | 8 |
| 9 namespace { | 9 namespace { |
| 10 | 10 |
| 11 class RasterOrderComparator { | 11 class RasterOrderComparator { |
| 12 public: | 12 public: |
| 13 explicit RasterOrderComparator(TreePriority tree_priority) | 13 explicit RasterOrderComparator(TreePriority tree_priority) |
| 14 : tree_priority_(tree_priority) {} | 14 : tree_priority_(tree_priority) {} |
| 15 | 15 |
| 16 bool operator()( | 16 bool operator()( |
| 17 const RasterTilePriorityQueue::PairedPictureLayerQueue& a, | 17 const RasterTilePriorityQueue::PairedPictureLayerQueue* a, |
| 18 const RasterTilePriorityQueue::PairedPictureLayerQueue& b) const { | 18 const RasterTilePriorityQueue::PairedPictureLayerQueue* b) const { |
| 19 if (a.IsEmpty()) | 19 if (a->IsEmpty()) |
| 20 return true; | 20 return true; |
| 21 | 21 |
| 22 if (b.IsEmpty()) | 22 if (b->IsEmpty()) |
| 23 return false; | 23 return false; |
| 24 | 24 |
| 25 WhichTree a_tree = a.NextTileIteratorTree(tree_priority_); | 25 WhichTree a_tree = a->NextTileIteratorTree(tree_priority_); |
| 26 const PictureLayerImpl::LayerRasterTileIterator* a_iterator = | 26 const PictureLayerImpl::LayerRasterTileIterator* a_iterator = |
| 27 a_tree == ACTIVE_TREE ? &a.active_iterator : &a.pending_iterator; | 27 a_tree == ACTIVE_TREE ? &a->active_iterator : &a->pending_iterator; |
| 28 | 28 |
| 29 WhichTree b_tree = b.NextTileIteratorTree(tree_priority_); | 29 WhichTree b_tree = b->NextTileIteratorTree(tree_priority_); |
| 30 const PictureLayerImpl::LayerRasterTileIterator* b_iterator = | 30 const PictureLayerImpl::LayerRasterTileIterator* b_iterator = |
| 31 b_tree == ACTIVE_TREE ? &b.active_iterator : &b.pending_iterator; | 31 b_tree == ACTIVE_TREE ? &b->active_iterator : &b->pending_iterator; |
| 32 | 32 |
| 33 const Tile* a_tile = **a_iterator; | 33 const Tile* a_tile = **a_iterator; |
| 34 const Tile* b_tile = **b_iterator; | 34 const Tile* b_tile = **b_iterator; |
| 35 | 35 |
| 36 const TilePriority& a_priority = | 36 const TilePriority& a_priority = |
| 37 a_tile->priority_for_tree_priority(tree_priority_); | 37 a_tile->priority_for_tree_priority(tree_priority_); |
| 38 const TilePriority& b_priority = | 38 const TilePriority& b_priority = |
| 39 b_tile->priority_for_tree_priority(tree_priority_); | 39 b_tile->priority_for_tree_priority(tree_priority_); |
| 40 bool prioritize_low_res = tree_priority_ == SMOOTHNESS_TAKES_PRIORITY; | 40 bool prioritize_low_res = tree_priority_ == SMOOTHNESS_TAKES_PRIORITY; |
| 41 | 41 |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 70 } // namespace | 70 } // namespace |
| 71 | 71 |
| 72 RasterTilePriorityQueue::RasterTilePriorityQueue() { | 72 RasterTilePriorityQueue::RasterTilePriorityQueue() { |
| 73 } | 73 } |
| 74 | 74 |
| 75 RasterTilePriorityQueue::~RasterTilePriorityQueue() { | 75 RasterTilePriorityQueue::~RasterTilePriorityQueue() { |
| 76 } | 76 } |
| 77 | 77 |
| 78 void RasterTilePriorityQueue::Build( | 78 void RasterTilePriorityQueue::Build( |
| 79 const std::vector<PictureLayerImpl::Pair>& paired_layers, | 79 const std::vector<PictureLayerImpl::Pair>& paired_layers, |
| 80 TreePriority tree_priority) { | 80 TreePriority tree_priority) { |
|
reveman
2014/07/30 16:04:09
That this function is not being faster makes me ve
vmpstr
2014/07/30 16:45:51
One possible explanation is that reallocations in
reveman
2014/07/31 03:05:19
Ok, let's start by fixing the perftests then.
| |
| 81 tree_priority_ = tree_priority; | 81 tree_priority_ = tree_priority; |
| 82 for (std::vector<PictureLayerImpl::Pair>::const_iterator it = | 82 for (std::vector<PictureLayerImpl::Pair>::const_iterator it = |
| 83 paired_layers.begin(); | 83 paired_layers.begin(); |
| 84 it != paired_layers.end(); | 84 it != paired_layers.end(); |
| 85 ++it) { | 85 ++it) { |
| 86 paired_queues_.push_back(PairedPictureLayerQueue(*it, tree_priority_)); | 86 paired_queues_.push_back(PairedPictureLayerQueue(*it, tree_priority_)); |
| 87 } | 87 } |
| 88 | 88 |
| 89 std::make_heap(paired_queues_.begin(), | 89 for (size_t i = 0; i < paired_queues_.size(); ++i) { |
| 90 paired_queues_.end(), | 90 paired_queues_heap_.push_back(&paired_queues_[i]); |
| 91 } | |
| 92 | |
| 93 std::make_heap(paired_queues_heap_.begin(), | |
| 94 paired_queues_heap_.end(), | |
| 91 RasterOrderComparator(tree_priority_)); | 95 RasterOrderComparator(tree_priority_)); |
| 92 } | 96 } |
| 93 | 97 |
| 94 void RasterTilePriorityQueue::Reset() { | 98 void RasterTilePriorityQueue::Reset() { |
| 95 paired_queues_.clear(); | 99 paired_queues_.clear(); |
| 100 paired_queues_heap_.clear(); | |
| 96 } | 101 } |
| 97 | 102 |
| 98 bool RasterTilePriorityQueue::IsEmpty() const { | 103 bool RasterTilePriorityQueue::IsEmpty() const { |
| 99 return paired_queues_.empty() || paired_queues_.front().IsEmpty(); | 104 return paired_queues_heap_.empty() || paired_queues_heap_.front()->IsEmpty(); |
| 100 } | 105 } |
| 101 | 106 |
| 102 Tile* RasterTilePriorityQueue::Top() { | 107 Tile* RasterTilePriorityQueue::Top() { |
| 103 DCHECK(!IsEmpty()); | 108 DCHECK(!IsEmpty()); |
| 104 return paired_queues_.front().Top(tree_priority_); | 109 return paired_queues_heap_.front()->Top(tree_priority_); |
| 105 } | 110 } |
| 106 | 111 |
| 107 void RasterTilePriorityQueue::Pop() { | 112 void RasterTilePriorityQueue::Pop() { |
| 108 DCHECK(!IsEmpty()); | 113 DCHECK(!IsEmpty()); |
| 109 | 114 |
| 110 std::pop_heap(paired_queues_.begin(), | 115 std::pop_heap(paired_queues_heap_.begin(), |
| 111 paired_queues_.end(), | 116 paired_queues_heap_.end(), |
| 112 RasterOrderComparator(tree_priority_)); | 117 RasterOrderComparator(tree_priority_)); |
| 113 PairedPictureLayerQueue& paired_queue = paired_queues_.back(); | 118 PairedPictureLayerQueue* paired_queue = paired_queues_heap_.back(); |
| 114 paired_queue.Pop(tree_priority_); | 119 paired_queue->Pop(tree_priority_); |
| 115 std::push_heap(paired_queues_.begin(), | 120 std::push_heap(paired_queues_heap_.begin(), |
| 116 paired_queues_.end(), | 121 paired_queues_heap_.end(), |
| 117 RasterOrderComparator(tree_priority_)); | 122 RasterOrderComparator(tree_priority_)); |
| 118 } | 123 } |
| 119 | 124 |
| 120 RasterTilePriorityQueue::PairedPictureLayerQueue::PairedPictureLayerQueue() { | 125 RasterTilePriorityQueue::PairedPictureLayerQueue::PairedPictureLayerQueue() { |
| 121 } | 126 } |
| 122 | 127 |
| 123 RasterTilePriorityQueue::PairedPictureLayerQueue::PairedPictureLayerQueue( | 128 RasterTilePriorityQueue::PairedPictureLayerQueue::PairedPictureLayerQueue( |
| 124 const PictureLayerImpl::Pair& layer_pair, | 129 const PictureLayerImpl::Pair& layer_pair, |
| 125 TreePriority tree_priority) | 130 TreePriority tree_priority) |
| 126 : active_iterator(layer_pair.active | 131 : active_iterator(layer_pair.active |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 220 default: | 225 default: |
| 221 NOTREACHED(); | 226 NOTREACHED(); |
| 222 } | 227 } |
| 223 | 228 |
| 224 NOTREACHED(); | 229 NOTREACHED(); |
| 225 // Keep the compiler happy. | 230 // Keep the compiler happy. |
| 226 return ACTIVE_TREE; | 231 return ACTIVE_TREE; |
| 227 } | 232 } |
| 228 | 233 |
| 229 } // namespace cc | 234 } // namespace cc |
| OLD | NEW |