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

Side by Side Diff: cc/resources/picture_layer_tiling.h

Issue 183663003: cc: Add tiling raster tile iterators. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 9 months 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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 #ifndef CC_RESOURCES_PICTURE_LAYER_TILING_H_ 5 #ifndef CC_RESOURCES_PICTURE_LAYER_TILING_H_
6 #define CC_RESOURCES_PICTURE_LAYER_TILING_H_ 6 #define CC_RESOURCES_PICTURE_LAYER_TILING_H_
7 7
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 27 matching lines...) Expand all
38 virtual size_t GetMaxTilesForInterestArea() const = 0; 38 virtual size_t GetMaxTilesForInterestArea() const = 0;
39 virtual float GetSkewportTargetTimeInSeconds() const = 0; 39 virtual float GetSkewportTargetTimeInSeconds() const = 0;
40 virtual int GetSkewportExtrapolationLimitInContentPixels() const = 0; 40 virtual int GetSkewportExtrapolationLimitInContentPixels() const = 0;
41 41
42 protected: 42 protected:
43 virtual ~PictureLayerTilingClient() {} 43 virtual ~PictureLayerTilingClient() {}
44 }; 44 };
45 45
46 class CC_EXPORT PictureLayerTiling { 46 class CC_EXPORT PictureLayerTiling {
47 public: 47 public:
48 class CC_EXPORT TilingRasterTileIterator {
epennerAtGoogle 2014/03/05 00:16:03 Cool. One thing I didn't see in here is whether we
vmpstr 2014/03/05 00:37:21 Not really... See my comment in the unittests. I t
49 public:
50 enum Type { VISIBLE, SKEWPORT, EVENTUALLY };
51
52 TilingRasterTileIterator();
53 explicit TilingRasterTileIterator(PictureLayerTiling* tiling);
54 ~TilingRasterTileIterator();
55
56 operator bool() const { return !!current_tile_; }
57 Tile* operator*() { return current_tile_; }
58 Type get_type() const { return type_; }
59
60 TilingRasterTileIterator& operator++();
61
62 bool HasVisibleTiles() const { return type_ == VISIBLE; }
63
64 gfx::Rect TileBounds() const {
65 DCHECK(*this);
66 if (type_ == VISIBLE) {
67 return tiling_->tiling_data_.TileBounds(visible_iterator_.index_x(),
68 visible_iterator_.index_y());
69 }
70 return tiling_->tiling_data_.TileBounds(spiral_iterator_.index_x(),
71 spiral_iterator_.index_y());
72 }
73
74 private:
75 void AdvancePhase();
76
77 PictureLayerTiling* tiling_;
78
79 Type type_;
80
81 Tile* current_tile_;
82 TilingData::Iterator visible_iterator_;
83 TilingData::SpiralDifferenceIterator spiral_iterator_;
84 };
85
48 ~PictureLayerTiling(); 86 ~PictureLayerTiling();
49 87
50 // Create a tiling with no tiles. CreateTiles must be called to add some. 88 // Create a tiling with no tiles. CreateTiles must be called to add some.
51 static scoped_ptr<PictureLayerTiling> Create( 89 static scoped_ptr<PictureLayerTiling> Create(
52 float contents_scale, 90 float contents_scale,
53 const gfx::Size& layer_bounds, 91 const gfx::Size& layer_bounds,
54 PictureLayerTilingClient* client); 92 PictureLayerTilingClient* client);
55 gfx::Size layer_bounds() const { return layer_bounds_; } 93 gfx::Size layer_bounds() const { return layer_bounds_; }
56 void SetLayerBounds(const gfx::Size& layer_bounds); 94 void SetLayerBounds(const gfx::Size& layer_bounds);
57 void Invalidate(const Region& layer_region); 95 void Invalidate(const Region& layer_region);
58 void CreateMissingTilesInLiveTilesRect(); 96 void CreateMissingTilesInLiveTilesRect();
59 97
60 void SetCanUseLCDText(bool can_use_lcd_text); 98 void SetCanUseLCDText(bool can_use_lcd_text);
61 99
62 void SetClient(PictureLayerTilingClient* client); 100 void SetClient(PictureLayerTilingClient* client);
63 void set_resolution(TileResolution resolution) { resolution_ = resolution; } 101 void set_resolution(TileResolution resolution) { resolution_ = resolution; }
64 TileResolution resolution() const { return resolution_; } 102 TileResolution resolution() const { return resolution_; }
65 103
66 gfx::Rect ContentRect() const; 104 gfx::Rect ContentRect() const;
67 gfx::SizeF ContentSizeF() const; 105 gfx::SizeF ContentSizeF() const;
68 gfx::Rect live_tiles_rect() const { return live_tiles_rect_; } 106 gfx::Rect live_tiles_rect() const { return live_tiles_rect_; }
69 gfx::Size tile_size() const { return tiling_data_.max_texture_size(); } 107 gfx::Size tile_size() const { return tiling_data_.max_texture_size(); }
70 float contents_scale() const { return contents_scale_; } 108 float contents_scale() const { return contents_scale_; }
71 109
110 Tile* TileAt(int i, int j) const {
111 TileMap::const_iterator iter = tiles_.find(TileMapKey(i, j));
112 return (iter == tiles_.end()) ? NULL : iter->second.get();
113 }
114
72 void CreateAllTilesForTesting() { 115 void CreateAllTilesForTesting() {
73 SetLiveTilesRect(gfx::Rect(tiling_data_.total_size())); 116 SetLiveTilesRect(gfx::Rect(tiling_data_.total_size()));
74 } 117 }
75 118
76 std::vector<Tile*> AllTilesForTesting() const { 119 std::vector<Tile*> AllTilesForTesting() const {
77 std::vector<Tile*> all_tiles; 120 std::vector<Tile*> all_tiles;
78 for (TileMap::const_iterator it = tiles_.begin(); 121 for (TileMap::const_iterator it = tiles_.begin();
79 it != tiles_.end(); ++it) 122 it != tiles_.end(); ++it)
80 all_tiles.push_back(it->second.get()); 123 all_tiles.push_back(it->second.get());
81 return all_tiles; 124 return all_tiles;
82 } 125 }
83 126
84 Tile* TileAt(int i, int j) const;
85
86 // Iterate over all tiles to fill content_rect. Even if tiles are invalid 127 // Iterate over all tiles to fill content_rect. Even if tiles are invalid
87 // (i.e. no valid resource) this tiling should still iterate over them. 128 // (i.e. no valid resource) this tiling should still iterate over them.
88 // The union of all geometry_rect calls for each element iterated over should 129 // The union of all geometry_rect calls for each element iterated over should
89 // exactly equal content_rect and no two geometry_rects should intersect. 130 // exactly equal content_rect and no two geometry_rects should intersect.
90 class CC_EXPORT CoverageIterator { 131 class CC_EXPORT CoverageIterator {
91 public: 132 public:
92 CoverageIterator(); 133 CoverageIterator();
93 CoverageIterator(const PictureLayerTiling* tiling, 134 CoverageIterator(const PictureLayerTiling* tiling,
94 float dest_scale, 135 float dest_scale,
95 const gfx::Rect& rect); 136 const gfx::Rect& rect);
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 // be called before DidBecomeActive, as it resets the active priority 193 // be called before DidBecomeActive, as it resets the active priority
153 // while DidBecomeActive promotes pending priority on a similar set of tiles. 194 // while DidBecomeActive promotes pending priority on a similar set of tiles.
154 void DidBecomeRecycled(); 195 void DidBecomeRecycled();
155 196
156 void UpdateTilesToCurrentPile(); 197 void UpdateTilesToCurrentPile();
157 198
158 bool NeedsUpdateForFrameAtTime(double frame_time_in_seconds) { 199 bool NeedsUpdateForFrameAtTime(double frame_time_in_seconds) {
159 return frame_time_in_seconds != last_impl_frame_time_in_seconds_; 200 return frame_time_in_seconds != last_impl_frame_time_in_seconds_;
160 } 201 }
161 202
203 size_t RequiredGPUMemoryInBytes() const;
204
162 scoped_ptr<base::Value> AsValue() const; 205 scoped_ptr<base::Value> AsValue() const;
163 size_t GPUMemoryUsageInBytes() const; 206 size_t GPUMemoryUsageInBytes() const;
164 207
165 struct RectExpansionCache { 208 struct RectExpansionCache {
166 RectExpansionCache(); 209 RectExpansionCache();
167 210
168 gfx::Rect previous_start; 211 gfx::Rect previous_start;
169 gfx::Rect previous_bounds; 212 gfx::Rect previous_bounds;
170 gfx::Rect previous_result; 213 gfx::Rect previous_result;
171 int64 previous_target; 214 int64 previous_target;
172 }; 215 };
173 216
174 static 217 static
175 gfx::Rect ExpandRectEquallyToAreaBoundedBy( 218 gfx::Rect ExpandRectEquallyToAreaBoundedBy(
176 const gfx::Rect& starting_rect, 219 const gfx::Rect& starting_rect,
177 int64 target_area, 220 int64 target_area,
178 const gfx::Rect& bounding_rect, 221 const gfx::Rect& bounding_rect,
179 RectExpansionCache* cache); 222 RectExpansionCache* cache);
180 223
181 bool has_ever_been_updated() const { 224 bool has_ever_been_updated() const {
182 return last_impl_frame_time_in_seconds_ != 0.0; 225 return last_impl_frame_time_in_seconds_ != 0.0;
183 } 226 }
184 227
185 protected: 228 protected:
229 friend class TilingRasterTileIterator;
230 friend class TilingEvictionTileIterator;
231
186 typedef std::pair<int, int> TileMapKey; 232 typedef std::pair<int, int> TileMapKey;
187 typedef base::hash_map<TileMapKey, scoped_refptr<Tile> > TileMap; 233 typedef base::hash_map<TileMapKey, scoped_refptr<Tile> > TileMap;
188 234
189 PictureLayerTiling(float contents_scale, 235 PictureLayerTiling(float contents_scale,
190 const gfx::Size& layer_bounds, 236 const gfx::Size& layer_bounds,
191 PictureLayerTilingClient* client); 237 PictureLayerTilingClient* client);
192 void SetLiveTilesRect(const gfx::Rect& live_tiles_rect); 238 void SetLiveTilesRect(const gfx::Rect& live_tiles_rect);
193 void CreateTile(int i, int j, const PictureLayerTiling* twin_tiling); 239 void CreateTile(int i, int j, const PictureLayerTiling* twin_tiling);
194 240
195 // Computes a skewport. The calculation extrapolates the last visible 241 // Computes a skewport. The calculation extrapolates the last visible
(...skipping 10 matching lines...) Expand all
206 TileResolution resolution_; 252 TileResolution resolution_;
207 PictureLayerTilingClient* client_; 253 PictureLayerTilingClient* client_;
208 254
209 // Internal data. 255 // Internal data.
210 TilingData tiling_data_; 256 TilingData tiling_data_;
211 TileMap tiles_; // It is not legal to have a NULL tile in the tiles_ map. 257 TileMap tiles_; // It is not legal to have a NULL tile in the tiles_ map.
212 gfx::Rect live_tiles_rect_; 258 gfx::Rect live_tiles_rect_;
213 259
214 // State saved for computing velocities based upon finite differences. 260 // State saved for computing velocities based upon finite differences.
215 double last_impl_frame_time_in_seconds_; 261 double last_impl_frame_time_in_seconds_;
216 gfx::RectF last_visible_rect_in_content_space_; 262 gfx::Rect last_visible_rect_in_content_space_;
263
264 gfx::Rect current_visible_rect_in_content_space_;
265 gfx::Rect current_skewport_;
266 gfx::Rect current_eventually_rect_;
267
268 WhichTree last_update_tree_;
217 269
218 friend class CoverageIterator; 270 friend class CoverageIterator;
219 271
220 private: 272 private:
221 DISALLOW_ASSIGN(PictureLayerTiling); 273 DISALLOW_ASSIGN(PictureLayerTiling);
222 274
223 RectExpansionCache expansion_cache_; 275 RectExpansionCache expansion_cache_;
224 }; 276 };
225 277
226 } // namespace cc 278 } // namespace cc
227 279
228 #endif // CC_RESOURCES_PICTURE_LAYER_TILING_H_ 280 #endif // CC_RESOURCES_PICTURE_LAYER_TILING_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698