OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "cc/resources/tiling_set_raster_queue_required.h" | |
6 | |
7 #include <utility> | |
8 | |
9 #include "cc/resources/picture_layer_tiling_set.h" | |
10 #include "cc/resources/tile.h" | |
11 #include "cc/resources/tile_priority.h" | |
12 | |
13 namespace cc { | |
14 | |
15 TilingSetRasterQueueRequired::TilingSetRasterQueueRequired( | |
16 PictureLayerTilingSet* tiling_set, | |
17 RasterTilePriorityQueue::Type type) | |
18 : type_(type) { | |
19 DCHECK_NE(static_cast<int>(type), | |
20 static_cast<int>(RasterTilePriorityQueue::Type::ALL)); | |
21 | |
22 // Required tiles should only come from HIGH_RESOLUTION tilings. However, if | |
23 // we want required for activation tiles on the active tree, then it will come | |
24 // from tilings whose pending twin is high resolution. | |
25 PictureLayerTiling* tiling = nullptr; | |
26 if (type == RasterTilePriorityQueue::Type::REQUIRED_FOR_ACTIVATION && | |
27 tiling_set->tree() == ACTIVE_TREE) { | |
28 for (size_t i = 0; i < tiling_set->num_tilings(); ++i) { | |
29 PictureLayerTiling* active_tiling = tiling_set->tiling_at(i); | |
30 const PictureLayerTiling* pending_twin = | |
31 tiling_set->client()->GetPendingOrActiveTwinTiling(active_tiling); | |
32 if (pending_twin && pending_twin->resolution() == HIGH_RESOLUTION) { | |
33 tiling = active_tiling; | |
34 break; | |
35 } | |
36 } | |
37 } else { | |
38 tiling = tiling_set->FindTilingWithResolution(HIGH_RESOLUTION); | |
39 } | |
40 | |
41 // If we don't have a tiling, then this queue will yield no tiles. See | |
42 // PictureLayerImpl::CanHaveTilings for examples of when a HIGH_RESOLUTION | |
43 // tiling would not be generated. | |
44 if (!tiling) | |
45 return; | |
46 | |
47 if (type == RasterTilePriorityQueue::Type::REQUIRED_FOR_ACTIVATION) { | |
48 iterator_ = TilingIterator(tiling, &tiling->tiling_data_, | |
49 tiling->pending_visible_rect()); | |
50 } else { | |
51 iterator_ = TilingIterator(tiling, &tiling->tiling_data_, | |
52 tiling->current_visible_rect()); | |
53 } | |
54 | |
55 while (!iterator_.done() && !IsTileRequired(*iterator_)) | |
56 ++iterator_; | |
57 } | |
58 | |
59 TilingSetRasterQueueRequired::~TilingSetRasterQueueRequired() { | |
60 } | |
61 | |
62 bool TilingSetRasterQueueRequired::IsEmpty() const { | |
63 return iterator_.done(); | |
64 } | |
65 | |
66 void TilingSetRasterQueueRequired::Pop() { | |
67 DCHECK(!IsEmpty()); | |
68 ++iterator_; | |
69 while (!iterator_.done() && !IsTileRequired(*iterator_)) | |
70 ++iterator_; | |
71 } | |
72 | |
73 const PrioritizedTile& TilingSetRasterQueueRequired::Top() const { | |
74 DCHECK(!IsEmpty()); | |
75 return *iterator_; | |
76 } | |
77 | |
78 bool TilingSetRasterQueueRequired::IsTileRequired( | |
79 const PrioritizedTile& prioritized_tile) const { | |
80 return (type_ == RasterTilePriorityQueue::Type::REQUIRED_FOR_ACTIVATION && | |
81 prioritized_tile.tile()->required_for_activation()) || | |
82 (type_ == RasterTilePriorityQueue::Type::REQUIRED_FOR_DRAW && | |
83 prioritized_tile.tile()->required_for_draw()); | |
84 } | |
85 | |
86 TilingSetRasterQueueRequired::TilingIterator::TilingIterator() | |
87 : tiling_(nullptr) { | |
88 } | |
89 | |
90 TilingSetRasterQueueRequired::TilingIterator::TilingIterator( | |
91 PictureLayerTiling* tiling, | |
92 TilingData* tiling_data, | |
93 const gfx::Rect& rect) | |
94 : tiling_(tiling), tiling_data_(tiling_data) { | |
95 visible_iterator_ = | |
96 TilingData::Iterator(tiling_data_, rect, false /* include_borders */); | |
97 if (!visible_iterator_) | |
98 return; | |
99 | |
100 Tile* tile = | |
101 tiling_->TileAt(visible_iterator_.index_x(), visible_iterator_.index_y()); | |
102 // If this is a valid tile, return it. Note that we have to use a tiling check | |
103 // for occlusion, since the tile's internal state has not yet been updated. | |
104 if (tile && tile->draw_info().NeedsRaster() && | |
105 !tiling_->IsTileOccluded(tile)) { | |
106 tiling_->UpdateRequiredStatesOnTile(tile); | |
107 current_tile_ = tiling_->MakePrioritizedTile( | |
108 tile, tiling_->ComputePriorityRectTypeForTile(tile)); | |
109 return; | |
110 } | |
111 ++(*this); | |
112 } | |
113 | |
114 TilingSetRasterQueueRequired::TilingIterator::~TilingIterator() { | |
115 } | |
116 | |
117 TilingSetRasterQueueRequired::TilingIterator& | |
118 TilingSetRasterQueueRequired::TilingIterator:: | |
119 operator++() { | |
120 Tile* tile = nullptr; | |
121 while (true) { | |
122 ++visible_iterator_; | |
123 if (!visible_iterator_) { | |
124 current_tile_ = PrioritizedTile(); | |
125 return *this; | |
126 } | |
127 std::pair<int, int> next_index = visible_iterator_.index(); | |
128 tile = tiling_->TileAt(next_index.first, next_index.second); | |
129 // If the tile doesn't exist or if it exists but doesn't need raster work, | |
130 // we can move on to the next tile. | |
131 if (!tile || !tile->draw_info().NeedsRaster()) | |
132 continue; | |
133 | |
134 // If the tile is occluded, we also can skip it. Note that we use the tiling | |
135 // check for occlusion, since tile's internal state has not yet been updated | |
136 // (by UpdateTilePriority). The tiling check does not rely on tile's | |
137 // internal state (it is, in fact, used to determine the tile's state). | |
138 if (tiling_->IsTileOccluded(tile)) | |
139 continue; | |
140 | |
141 // If we get here, that means we have a valid tile that needs raster and is | |
142 // in the NOW bin, which means that it can be required. | |
143 break; | |
144 } | |
145 | |
146 tiling_->UpdateRequiredStatesOnTile(tile); | |
147 current_tile_ = tiling_->MakePrioritizedTile( | |
148 tile, tiling_->ComputePriorityRectTypeForTile(tile)); | |
149 return *this; | |
150 } | |
151 | |
152 } // namespace cc | |
OLD | NEW |