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

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

Issue 12865017: Makes tile-creation lazy (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fixing unit tests and an optimization to CreateTile Created 7 years, 8 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 14 matching lines...) Expand all
25 25
26 class PictureLayerTilingClient { 26 class PictureLayerTilingClient {
27 public: 27 public:
28 // Create a tile at the given content_rect (in the contents scale of the 28 // Create a tile at the given content_rect (in the contents scale of the
29 // tiling) This might return null if the client cannot create such a tile. 29 // tiling) This might return null if the client cannot create such a tile.
30 virtual scoped_refptr<Tile> CreateTile( 30 virtual scoped_refptr<Tile> CreateTile(
31 PictureLayerTiling* tiling, 31 PictureLayerTiling* tiling,
32 gfx::Rect content_rect) = 0; 32 gfx::Rect content_rect) = 0;
33 virtual void UpdatePile(Tile* tile) = 0; 33 virtual void UpdatePile(Tile* tile) = 0;
34 virtual gfx::Size CalculateTileSize( 34 virtual gfx::Size CalculateTileSize(
35 gfx::Size current_tile_size,
36 gfx::Size content_bounds) = 0; 35 gfx::Size content_bounds) = 0;
36 virtual const Region* GetInvalidation() = 0;
37 virtual const PictureLayerTiling* GetTwinTiling(
38 const PictureLayerTiling* tiling) = 0;
37 39
38 protected: 40 protected:
39 virtual ~PictureLayerTilingClient() {} 41 virtual ~PictureLayerTilingClient() {}
40 }; 42 };
41 43
42 class CC_EXPORT PictureLayerTiling { 44 class CC_EXPORT PictureLayerTiling {
43 public: 45 public:
44 ~PictureLayerTiling(); 46 ~PictureLayerTiling();
45 47
46 // Create a tiling with no tiles. CreateTiles must be called to add some. 48 // Create a tiling with no tiles. CreateTiles must be called to add some.
47 static scoped_ptr<PictureLayerTiling> Create(float contents_scale); 49 static scoped_ptr<PictureLayerTiling> Create(
48 scoped_ptr<PictureLayerTiling> Clone() const; 50 float contents_scale,
49 51 gfx::Size layer_bounds,
52 PictureLayerTilingClient* client);
53 scoped_ptr<PictureLayerTiling> Clone(gfx::Size layer_bounds,
54 PictureLayerTilingClient* client) const;
50 gfx::Size layer_bounds() const { return layer_bounds_; } 55 gfx::Size layer_bounds() const { return layer_bounds_; }
51 void SetLayerBounds(gfx::Size layer_bounds);
52 void Invalidate(const Region& layer_invalidation);
53 56
54 // Add any tiles that intersect with |layer_rect|. If any tiles already 57 // Add any tiles that intersect with |layer_rect|. If any tiles already
55 // exist, then this leaves them as-is. 58 // exist, then this leaves them as-is.
56 void CreateTilesFromLayerRect(gfx::Rect layer_rect);
57 59
58 void SetClient(PictureLayerTilingClient* client); 60 void SetClient(PictureLayerTilingClient* client);
59 void set_resolution(TileResolution resolution) { resolution_ = resolution; } 61 void set_resolution(TileResolution resolution) { resolution_ = resolution; }
60 TileResolution resolution() const { return resolution_; } 62 TileResolution resolution() const { return resolution_; }
61 63
62 gfx::Rect ContentRect() const; 64 gfx::Rect ContentRect() const;
63 gfx::SizeF ContentSizeF() const; 65 gfx::SizeF ContentSizeF() const;
64 float contents_scale() const { return contents_scale_; } 66 float contents_scale() const { return contents_scale_; }
65 67
66 std::vector<Tile*> AllTilesForTesting() const { 68 std::vector<Tile*> AllTilesForTesting() {
69 SetLiveTilesRect(gfx::Rect(tiling_data_.total_size()));
70
67 std::vector<Tile*> all_tiles; 71 std::vector<Tile*> all_tiles;
68 for (TileMap::const_iterator it = tiles_.begin(); 72 for (TileMap::const_iterator it = tiles_.begin();
69 it != tiles_.end(); ++it) 73 it != tiles_.end(); ++it)
70 all_tiles.push_back(it->second); 74 all_tiles.push_back(it->second);
71 return all_tiles; 75 return all_tiles;
72 } 76 }
73 77
74 static gfx::Rect ExpandRectEquallyToAreaBoundedBy(
75 gfx::Rect starting_rect,
76 int64 target_area,
77 gfx::Rect bounding_rect);
78
79 // Iterate over all tiles to fill content_rect. Even if tiles are invalid 78 // Iterate over all tiles to fill content_rect. Even if tiles are invalid
80 // (i.e. no valid resource) this tiling should still iterate over them. 79 // (i.e. no valid resource) this tiling should still iterate over them.
81 // The union of all geometry_rect calls for each element iterated over should 80 // The union of all geometry_rect calls for each element iterated over should
82 // exactly equal content_rect and no two geometry_rects should intersect. 81 // exactly equal content_rect and no two geometry_rects should intersect.
83 class CC_EXPORT Iterator { 82 class CC_EXPORT Iterator {
84 public: 83 public:
85 Iterator(); 84 Iterator();
86 Iterator(const PictureLayerTiling* tiling, 85 Iterator(const PictureLayerTiling* tiling,
87 float dest_scale, 86 float dest_scale,
88 gfx::Rect rect); 87 gfx::Rect rect);
(...skipping 28 matching lines...) Expand all
117 int left_; 116 int left_;
118 int top_; 117 int top_;
119 int right_; 118 int right_;
120 int bottom_; 119 int bottom_;
121 120
122 friend class PictureLayerTiling; 121 friend class PictureLayerTiling;
123 }; 122 };
124 123
125 Region OpaqueRegionInContentRect(const gfx::Rect&) const; 124 Region OpaqueRegionInContentRect(const gfx::Rect&) const;
126 125
127 void Reset() { return tiles_.clear(); } 126 void Reset();
128 127
129 void UpdateTilePriorities( 128 void UpdateTilePriorities(
130 WhichTree tree, 129 WhichTree tree,
131 gfx::Size device_viewport, 130 gfx::Size device_viewport,
132 const gfx::RectF& viewport_in_layer_space, 131 const gfx::RectF& viewport_in_layer_space,
133 gfx::Size last_layer_bounds, 132 gfx::Size last_layer_bounds,
134 gfx::Size current_layer_bounds, 133 gfx::Size current_layer_bounds,
135 float last_layer_contents_scale, 134 float last_layer_contents_scale,
136 float current_layer_contents_scale, 135 float current_layer_contents_scale,
137 const gfx::Transform& last_screen_transform, 136 const gfx::Transform& last_screen_transform,
138 const gfx::Transform& current_screen_transform, 137 const gfx::Transform& current_screen_transform,
139 int current_source_frame_number, 138 int current_source_frame_number,
140 double current_frame_time, 139 double current_frame_time,
141 bool store_screen_space_quads_on_tiles, 140 bool store_screen_space_quads_on_tiles,
142 size_t max_tiles_for_interest_area); 141 size_t max_tiles_for_interest_area);
143 142
144 // Copies the src_tree priority into the dst_tree priority for all tiles. 143 // Copies the src_tree priority into the dst_tree priority for all tiles.
145 // The src_tree priority is reset to the lowest priority possible. This 144 // The src_tree priority is reset to the lowest priority possible. This
146 // also updates the pile on each tile to be the current client's pile. 145 // also updates the pile on each tile to be the current client's pile.
147 void DidBecomeActive(); 146 void DidBecomeActive();
148 147
149 scoped_ptr<base::Value> AsValue() const; 148 scoped_ptr<base::Value> AsValue() const;
150 149
150 static gfx::Rect ExpandRectEquallyToAreaBoundedBy(
151 gfx::Rect starting_rect,
152 int64 target_area,
153 gfx::Rect bounding_rect);
154
155 gfx::Size tile_bounds() const {
156 return tiling_data_.max_texture_size();
157 }
158
151 protected: 159 protected:
152 typedef std::pair<int, int> TileMapKey; 160 typedef std::pair<int, int> TileMapKey;
153 typedef base::hash_map<TileMapKey, scoped_refptr<Tile> > TileMap; 161 typedef base::hash_map<TileMapKey, scoped_refptr<Tile> > TileMap;
154 162
155 explicit PictureLayerTiling(float contents_scale); 163 PictureLayerTiling(float contents_scale,
164 gfx::Size layer_bounds,
165 PictureLayerTilingClient* client);
166
156 Tile* TileAt(int, int) const; 167 Tile* TileAt(int, int) const;
157 void CreateTilesFromContentRect(gfx::Rect layer_rect);
158 void CreateTile(int i, int j); 168 void CreateTile(int i, int j);
159 169
160 PictureLayerTilingClient* client_; 170 // Given properties.
161 float contents_scale_; 171 float contents_scale_;
162 gfx::Size layer_bounds_; 172 gfx::Size layer_bounds_;
163 gfx::Rect last_prioritized_rect_; 173 TileResolution resolution_;
164 // It is not legal to have a NULL tile in the tiles_ map. 174 PictureLayerTilingClient* client_;
165 TileMap tiles_; 175
176 // Internal data.
166 TilingData tiling_data_; 177 TilingData tiling_data_;
167 TileResolution resolution_; 178 TileMap tiles_; // It is not legal to have a NULL tile in the tiles_ map.
179 gfx::Rect live_tiles_rect_;
180
181 // State saved for computing velocities based upon finite differences.
168 int last_source_frame_number_; 182 int last_source_frame_number_;
169 double last_impl_frame_time_; 183 double last_impl_frame_time_;
170 184
171 friend class Iterator; 185 friend class Iterator;
172 186
187 void SetLiveTilesRect(const gfx::Rect& live_tiles_rect);
188
173 private: 189 private:
174 DISALLOW_ASSIGN(PictureLayerTiling); 190 DISALLOW_ASSIGN(PictureLayerTiling);
175 }; 191 };
176 192
177 } // namespace cc 193 } // namespace cc
178 194
179 #endif // CC_RESOURCES_PICTURE_LAYER_TILING_H_ 195 #endif // CC_RESOURCES_PICTURE_LAYER_TILING_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698