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

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 {
49 public:
50 enum Type { VISIBLE, SKEWPORT, EVENTUALLY };
51
52 TilingRasterTileIterator();
53 TilingRasterTileIterator(PictureLayerTiling* tiling, WhichTree tree);
54 ~TilingRasterTileIterator();
55
56 operator bool() const {
57 return current_tile_ && TileNeedsRaster(current_tile_);
58 }
59 Tile* operator*() { return current_tile_; }
60 Type get_type() const { return type_; }
61
62 TilingRasterTileIterator& operator++();
63
64 bool HasVisibleTiles() const { return type_ == VISIBLE; }
enne (OOO) 2014/03/06 02:30:45 unused?
vmpstr 2014/03/07 18:22:23 Removed.
65
66 gfx::Rect TileBounds() const {
67 DCHECK(*this);
68 if (type_ == VISIBLE) {
69 return tiling_->tiling_data_.TileBounds(visible_iterator_.index_x(),
70 visible_iterator_.index_y());
71 }
72 return tiling_->tiling_data_.TileBounds(spiral_iterator_.index_x(),
73 spiral_iterator_.index_y());
74 }
75
76 private:
77 void AdvancePhase();
78 bool TileNeedsRaster(Tile* tile) const {
79 RasterMode mode = tile->DetermineRasterModeForTree(tree_);
80 return tile->NeedsRasterForMode(mode);
81 };
82
83 PictureLayerTiling* tiling_;
84
85 Type type_;
86 WhichTree tree_;
87
88 Tile* current_tile_;
89 TilingData::Iterator visible_iterator_;
90 TilingData::SpiralDifferenceIterator spiral_iterator_;
91 };
92
48 ~PictureLayerTiling(); 93 ~PictureLayerTiling();
49 94
50 // Create a tiling with no tiles. CreateTiles must be called to add some. 95 // Create a tiling with no tiles. CreateTiles must be called to add some.
51 static scoped_ptr<PictureLayerTiling> Create( 96 static scoped_ptr<PictureLayerTiling> Create(
52 float contents_scale, 97 float contents_scale,
53 const gfx::Size& layer_bounds, 98 const gfx::Size& layer_bounds,
54 PictureLayerTilingClient* client); 99 PictureLayerTilingClient* client);
55 gfx::Size layer_bounds() const { return layer_bounds_; } 100 gfx::Size layer_bounds() const { return layer_bounds_; }
56 void SetLayerBounds(const gfx::Size& layer_bounds); 101 void SetLayerBounds(const gfx::Size& layer_bounds);
57 void Invalidate(const Region& layer_region); 102 void Invalidate(const Region& layer_region);
58 void CreateMissingTilesInLiveTilesRect(); 103 void CreateMissingTilesInLiveTilesRect();
59 104
60 void SetCanUseLCDText(bool can_use_lcd_text); 105 void SetCanUseLCDText(bool can_use_lcd_text);
61 106
62 void SetClient(PictureLayerTilingClient* client); 107 void SetClient(PictureLayerTilingClient* client);
63 void set_resolution(TileResolution resolution) { resolution_ = resolution; } 108 void set_resolution(TileResolution resolution) { resolution_ = resolution; }
64 TileResolution resolution() const { return resolution_; } 109 TileResolution resolution() const { return resolution_; }
65 110
66 gfx::Rect ContentRect() const; 111 gfx::Rect ContentRect() const;
67 gfx::SizeF ContentSizeF() const; 112 gfx::SizeF ContentSizeF() const;
68 gfx::Rect live_tiles_rect() const { return live_tiles_rect_; } 113 gfx::Rect live_tiles_rect() const { return live_tiles_rect_; }
69 gfx::Size tile_size() const { return tiling_data_.max_texture_size(); } 114 gfx::Size tile_size() const { return tiling_data_.max_texture_size(); }
70 float contents_scale() const { return contents_scale_; } 115 float contents_scale() const { return contents_scale_; }
71 116
117 Tile* TileAt(int i, int j) const {
118 TileMap::const_iterator iter = tiles_.find(TileMapKey(i, j));
119 return (iter == tiles_.end()) ? NULL : iter->second.get();
120 }
121
72 void CreateAllTilesForTesting() { 122 void CreateAllTilesForTesting() {
73 SetLiveTilesRect(gfx::Rect(tiling_data_.total_size())); 123 SetLiveTilesRect(gfx::Rect(tiling_data_.total_size()));
74 } 124 }
75 125
76 std::vector<Tile*> AllTilesForTesting() const { 126 std::vector<Tile*> AllTilesForTesting() const {
77 std::vector<Tile*> all_tiles; 127 std::vector<Tile*> all_tiles;
78 for (TileMap::const_iterator it = tiles_.begin(); 128 for (TileMap::const_iterator it = tiles_.begin();
79 it != tiles_.end(); ++it) 129 it != tiles_.end(); ++it)
80 all_tiles.push_back(it->second.get()); 130 all_tiles.push_back(it->second.get());
81 return all_tiles; 131 return all_tiles;
82 } 132 }
83 133
84 Tile* TileAt(int i, int j) const;
85
86 // Iterate over all tiles to fill content_rect. Even if tiles are invalid 134 // 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. 135 // (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 136 // 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. 137 // exactly equal content_rect and no two geometry_rects should intersect.
90 class CC_EXPORT CoverageIterator { 138 class CC_EXPORT CoverageIterator {
91 public: 139 public:
92 CoverageIterator(); 140 CoverageIterator();
93 CoverageIterator(const PictureLayerTiling* tiling, 141 CoverageIterator(const PictureLayerTiling* tiling,
94 float dest_scale, 142 float dest_scale,
95 const gfx::Rect& rect); 143 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 200 // be called before DidBecomeActive, as it resets the active priority
153 // while DidBecomeActive promotes pending priority on a similar set of tiles. 201 // while DidBecomeActive promotes pending priority on a similar set of tiles.
154 void DidBecomeRecycled(); 202 void DidBecomeRecycled();
155 203
156 void UpdateTilesToCurrentPile(); 204 void UpdateTilesToCurrentPile();
157 205
158 bool NeedsUpdateForFrameAtTime(double frame_time_in_seconds) { 206 bool NeedsUpdateForFrameAtTime(double frame_time_in_seconds) {
159 return frame_time_in_seconds != last_impl_frame_time_in_seconds_; 207 return frame_time_in_seconds != last_impl_frame_time_in_seconds_;
160 } 208 }
161 209
210 size_t RequiredGPUMemoryInBytes() const;
211
162 scoped_ptr<base::Value> AsValue() const; 212 scoped_ptr<base::Value> AsValue() const;
163 size_t GPUMemoryUsageInBytes() const; 213 size_t GPUMemoryUsageInBytes() const;
164 214
165 struct RectExpansionCache { 215 struct RectExpansionCache {
166 RectExpansionCache(); 216 RectExpansionCache();
167 217
168 gfx::Rect previous_start; 218 gfx::Rect previous_start;
169 gfx::Rect previous_bounds; 219 gfx::Rect previous_bounds;
170 gfx::Rect previous_result; 220 gfx::Rect previous_result;
171 int64 previous_target; 221 int64 previous_target;
172 }; 222 };
173 223
174 static 224 static
175 gfx::Rect ExpandRectEquallyToAreaBoundedBy( 225 gfx::Rect ExpandRectEquallyToAreaBoundedBy(
176 const gfx::Rect& starting_rect, 226 const gfx::Rect& starting_rect,
177 int64 target_area, 227 int64 target_area,
178 const gfx::Rect& bounding_rect, 228 const gfx::Rect& bounding_rect,
179 RectExpansionCache* cache); 229 RectExpansionCache* cache);
180 230
181 bool has_ever_been_updated() const { 231 bool has_ever_been_updated() const {
182 return last_impl_frame_time_in_seconds_ != 0.0; 232 return last_impl_frame_time_in_seconds_ != 0.0;
183 } 233 }
184 234
185 protected: 235 protected:
236 friend class TilingRasterTileIterator;
237 friend class TilingEvictionTileIterator;
238
186 typedef std::pair<int, int> TileMapKey; 239 typedef std::pair<int, int> TileMapKey;
187 typedef base::hash_map<TileMapKey, scoped_refptr<Tile> > TileMap; 240 typedef base::hash_map<TileMapKey, scoped_refptr<Tile> > TileMap;
188 241
189 PictureLayerTiling(float contents_scale, 242 PictureLayerTiling(float contents_scale,
190 const gfx::Size& layer_bounds, 243 const gfx::Size& layer_bounds,
191 PictureLayerTilingClient* client); 244 PictureLayerTilingClient* client);
192 void SetLiveTilesRect(const gfx::Rect& live_tiles_rect); 245 void SetLiveTilesRect(const gfx::Rect& live_tiles_rect);
193 void CreateTile(int i, int j, const PictureLayerTiling* twin_tiling); 246 Tile* CreateTile(int i, int j, const PictureLayerTiling* twin_tiling);
194 247
195 // Computes a skewport. The calculation extrapolates the last visible 248 // Computes a skewport. The calculation extrapolates the last visible
196 // rect and the current visible rect to expand the skewport to where it 249 // rect and the current visible rect to expand the skewport to where it
197 // would be in |skewport_target_time| seconds. Note that the skewport 250 // would be in |skewport_target_time| seconds. Note that the skewport
198 // is guaranteed to contain the current visible rect. 251 // is guaranteed to contain the current visible rect.
199 gfx::Rect ComputeSkewport(double current_frame_time_in_seconds, 252 gfx::Rect ComputeSkewport(double current_frame_time_in_seconds,
200 const gfx::Rect& visible_rect_in_content_space) 253 const gfx::Rect& visible_rect_in_content_space)
201 const; 254 const;
202 255
203 // Given properties. 256 // Given properties.
204 float contents_scale_; 257 float contents_scale_;
205 gfx::Size layer_bounds_; 258 gfx::Size layer_bounds_;
206 TileResolution resolution_; 259 TileResolution resolution_;
207 PictureLayerTilingClient* client_; 260 PictureLayerTilingClient* client_;
208 261
209 // Internal data. 262 // Internal data.
210 TilingData tiling_data_; 263 TilingData tiling_data_;
211 TileMap tiles_; // It is not legal to have a NULL tile in the tiles_ map. 264 TileMap tiles_; // It is not legal to have a NULL tile in the tiles_ map.
212 gfx::Rect live_tiles_rect_; 265 gfx::Rect live_tiles_rect_;
213 266
214 // State saved for computing velocities based upon finite differences. 267 // State saved for computing velocities based upon finite differences.
215 double last_impl_frame_time_in_seconds_; 268 double last_impl_frame_time_in_seconds_;
216 gfx::RectF last_visible_rect_in_content_space_; 269 gfx::Rect last_visible_rect_in_content_space_;
270
271 gfx::Rect current_visible_rect_in_content_space_;
enne (OOO) 2014/03/06 02:30:45 I think it'd be cleaner if you just passed them to
vmpstr 2014/03/07 18:22:23 The problem is that these are generated during Upd
enne (OOO) 2014/03/10 21:36:30 Can you get them off the tiling and pass them to t
272 gfx::Rect current_skewport_;
273 gfx::Rect current_eventually_rect_;
217 274
218 friend class CoverageIterator; 275 friend class CoverageIterator;
219 276
220 private: 277 private:
221 DISALLOW_ASSIGN(PictureLayerTiling); 278 DISALLOW_ASSIGN(PictureLayerTiling);
222 279
223 RectExpansionCache expansion_cache_; 280 RectExpansionCache expansion_cache_;
224 }; 281 };
225 282
226 } // namespace cc 283 } // namespace cc
227 284
228 #endif // CC_RESOURCES_PICTURE_LAYER_TILING_H_ 285 #endif // CC_RESOURCES_PICTURE_LAYER_TILING_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698