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.
5 #ifndef CC_TILES_TILING_SET_RASTER_QUEUE_ALL_H_
6 #define CC_TILES_TILING_SET_RASTER_QUEUE_ALL_H_
8 #include "base/containers/stack_container.h"
9 #include "cc/base/cc_export.h"
10 #include "cc/tiles/picture_layer_tiling_set.h"
11 #include "cc/tiles/prioritized_tile.h"
12 #include "cc/tiles/tile.h"
13 #include "cc/tiles/tile_priority.h"
17 // This queue returns all tiles required to be rasterized from HIGH_RESOLUTION
18 // and LOW_RESOLUTION tilings.
19 class CC_EXPORT TilingSetRasterQueueAll
{
21 TilingSetRasterQueueAll(PictureLayerTilingSet
* tiling_set
,
22 bool prioritize_low_res
);
23 ~TilingSetRasterQueueAll();
25 const PrioritizedTile
& Top() const;
30 // Helper base class for individual region iterators.
31 class OnePriorityRectIterator
{
33 OnePriorityRectIterator();
34 OnePriorityRectIterator(
35 PictureLayerTiling
* tiling
,
36 TilingData
* tiling_data
,
37 PictureLayerTiling::PriorityRectType priority_rect_type
);
39 bool done() const { return !current_tile_
.tile(); }
40 const PrioritizedTile
& operator*() const { return current_tile_
; }
43 ~OnePriorityRectIterator() = default;
44 bool TileNeedsRaster(const Tile
* tile
) const {
45 return tile
->draw_info().NeedsRaster() && !tiling_
->IsTileOccluded(tile
);
48 template <typename TilingIteratorType
>
49 void AdvanceToNextTile(TilingIteratorType
* iterator
);
50 template <typename TilingIteratorType
>
51 bool GetFirstTileAndCheckIfValid(TilingIteratorType
* iterator
);
52 bool IsTileValid(const Tile
* tile
) const;
54 PrioritizedTile current_tile_
;
55 PictureLayerTiling
* tiling_
;
56 TilingData
* tiling_data_
;
57 PictureLayerTiling::PriorityRectType priority_rect_type_
;
58 gfx::Rect pending_visible_rect_
;
61 // Iterates over visible rect only, left to right top to bottom order.
62 class VisibleTilingIterator
: public OnePriorityRectIterator
{
64 VisibleTilingIterator() = default;
65 VisibleTilingIterator(PictureLayerTiling
* tiling
, TilingData
* tiling_data
);
67 VisibleTilingIterator
& operator++();
70 TilingData::Iterator iterator_
;
73 class PendingVisibleTilingIterator
: public OnePriorityRectIterator
{
75 PendingVisibleTilingIterator() = default;
76 PendingVisibleTilingIterator(PictureLayerTiling
* tiling
,
77 TilingData
* tiling_data
);
79 PendingVisibleTilingIterator
& operator++();
82 TilingData::DifferenceIterator iterator_
;
85 // Iterates over skewport only, spiral around the visible rect.
86 class SkewportTilingIterator
: public OnePriorityRectIterator
{
88 SkewportTilingIterator() = default;
89 SkewportTilingIterator(PictureLayerTiling
* tiling
, TilingData
* tiling_data
);
91 SkewportTilingIterator
& operator++();
94 TilingData::SpiralDifferenceIterator iterator_
;
97 // Iterates over soon border only, spiral around the visible rect.
98 class SoonBorderTilingIterator
: public OnePriorityRectIterator
{
100 SoonBorderTilingIterator() = default;
101 SoonBorderTilingIterator(PictureLayerTiling
* tiling
,
102 TilingData
* tiling_data
);
104 SoonBorderTilingIterator
& operator++();
107 TilingData::SpiralDifferenceIterator iterator_
;
110 // Iterates over eventually rect only, spiral around the soon rect.
111 class EventuallyTilingIterator
: public OnePriorityRectIterator
{
113 EventuallyTilingIterator() = default;
114 EventuallyTilingIterator(PictureLayerTiling
* tiling
,
115 TilingData
* tiling_data
);
117 EventuallyTilingIterator
& operator++();
120 TilingData::SpiralDifferenceIterator iterator_
;
123 // Iterates over all of the above phases in the following order: visible,
124 // skewport, soon border, eventually.
125 class TilingIterator
{
128 explicit TilingIterator(PictureLayerTiling
* tiling
,
129 TilingData
* tiling_data
);
132 bool done() const { return !current_tile_
.tile(); }
133 const PrioritizedTile
& operator*() const { return current_tile_
; }
134 TilePriority::PriorityBin
type() const {
136 case Phase::VISIBLE_RECT
:
137 return TilePriority::NOW
;
138 case Phase::PENDING_VISIBLE_RECT
:
139 case Phase::SKEWPORT_RECT
:
140 case Phase::SOON_BORDER_RECT
:
141 return TilePriority::SOON
;
142 case Phase::EVENTUALLY_RECT
:
143 return TilePriority::EVENTUALLY
;
146 return TilePriority::EVENTUALLY
;
149 TilingIterator
& operator++();
152 using Phase
= PictureLayerTiling::PriorityRectType
;
156 PictureLayerTiling
* tiling_
;
157 TilingData
* tiling_data_
;
161 PrioritizedTile current_tile_
;
162 VisibleTilingIterator visible_iterator_
;
163 PendingVisibleTilingIterator pending_visible_iterator_
;
164 SkewportTilingIterator skewport_iterator_
;
165 SoonBorderTilingIterator soon_border_iterator_
;
166 EventuallyTilingIterator eventually_iterator_
;
172 ACTIVE_NON_IDEAL_PENDING_HIGH_RES
,
176 void MakeTilingIterator(IteratorType type
, PictureLayerTiling
* tiling
);
177 void AdvanceToNextStage();
179 PictureLayerTilingSet
* tiling_set_
;
181 struct IterationStage
{
182 IterationStage(IteratorType type
, TilePriority::PriorityBin bin
);
183 IteratorType iterator_type
;
184 TilePriority::PriorityBin tile_type
;
187 size_t current_stage_
;
189 // The max number of stages is 6: 1 low res, 3 high res, and 2 active non
190 // ideal pending high res.
191 base::StackVector
<IterationStage
, 6> stages_
;
192 TilingIterator iterators_
[NUM_ITERATORS
];
194 DISALLOW_COPY_AND_ASSIGN(TilingSetRasterQueueAll
);
199 #endif // CC_TILES_TILING_SET_RASTER_QUEUE_ALL_H_