1 // Copyright 2013 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.
5 #include "cc/resources/prioritized_tile_set.h"
9 #include "cc/resources/managed_tile_state.h"
10 #include "cc/resources/tile.h"
16 bool operator()(const Tile
* a
,
17 const Tile
* b
) const {
18 const ManagedTileState
& ams
= a
->managed_state();
19 const ManagedTileState
& bms
= b
->managed_state();
21 if (ams
.priority_bin
!= bms
.priority_bin
)
22 return ams
.priority_bin
< bms
.priority_bin
;
24 if (ams
.required_for_activation
!= bms
.required_for_activation
)
25 return ams
.required_for_activation
;
27 if (ams
.resolution
!= bms
.resolution
)
28 return ams
.resolution
< bms
.resolution
;
30 if (ams
.distance_to_visible
!= bms
.distance_to_visible
)
31 return ams
.distance_to_visible
< bms
.distance_to_visible
;
33 gfx::Rect a_rect
= a
->content_rect();
34 gfx::Rect b_rect
= b
->content_rect();
35 if (a_rect
.y() != b_rect
.y())
36 return a_rect
.y() < b_rect
.y();
37 return a_rect
.x() < b_rect
.x();
43 typedef std::vector
<Tile
*> TileVector
;
45 void SortBinTiles(ManagedTileBin bin
, TileVector
* tiles
) {
47 case NOW_AND_READY_TO_DRAW_BIN
:
52 case EVENTUALLY_AND_ACTIVE_BIN
:
54 case AT_LAST_AND_ACTIVE_BIN
:
56 std::sort(tiles
->begin(), tiles
->end(), BinComparator());
65 PrioritizedTileSet::PrioritizedTileSet() {
66 for (int bin
= 0; bin
< NUM_BINS
; ++bin
)
67 bin_sorted_
[bin
] = true;
70 PrioritizedTileSet::~PrioritizedTileSet() {}
72 void PrioritizedTileSet::InsertTile(Tile
* tile
, ManagedTileBin bin
) {
73 tiles_
[bin
].push_back(tile
);
74 bin_sorted_
[bin
] = false;
77 void PrioritizedTileSet::Clear() {
78 for (int bin
= 0; bin
< NUM_BINS
; ++bin
) {
80 bin_sorted_
[bin
] = true;
84 void PrioritizedTileSet::SortBinIfNeeded(ManagedTileBin bin
) {
85 if (!bin_sorted_
[bin
]) {
86 SortBinTiles(bin
, &tiles_
[bin
]);
87 bin_sorted_
[bin
] = true;
91 PrioritizedTileSet::Iterator::Iterator(
92 PrioritizedTileSet
* tile_set
, bool use_priority_ordering
)
93 : tile_set_(tile_set
),
94 current_bin_(NOW_AND_READY_TO_DRAW_BIN
),
95 use_priority_ordering_(use_priority_ordering
) {
96 if (use_priority_ordering_
)
97 tile_set_
->SortBinIfNeeded(current_bin_
);
98 iterator_
= tile_set
->tiles_
[current_bin_
].begin();
99 if (iterator_
== tile_set_
->tiles_
[current_bin_
].end())
103 PrioritizedTileSet::Iterator::~Iterator() {}
105 void PrioritizedTileSet::Iterator::DisablePriorityOrdering() {
106 use_priority_ordering_
= false;
109 PrioritizedTileSet::Iterator
&
110 PrioritizedTileSet::Iterator::operator++() {
111 // We can't increment past the end of the tiles.
112 DCHECK(iterator_
!= tile_set_
->tiles_
[current_bin_
].end());
115 if (iterator_
== tile_set_
->tiles_
[current_bin_
].end())
120 Tile
* PrioritizedTileSet::Iterator::operator*() {
121 DCHECK(iterator_
!= tile_set_
->tiles_
[current_bin_
].end());
125 void PrioritizedTileSet::Iterator::AdvanceList() {
126 DCHECK(iterator_
== tile_set_
->tiles_
[current_bin_
].end());
128 while (current_bin_
!= NEVER_BIN
) {
129 current_bin_
= static_cast<ManagedTileBin
>(current_bin_
+ 1);
131 if (use_priority_ordering_
)
132 tile_set_
->SortBinIfNeeded(current_bin_
);
134 iterator_
= tile_set_
->tiles_
[current_bin_
].begin();
135 if (iterator_
!= tile_set_
->tiles_
[current_bin_
].end())