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

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

Issue 62283012: cc: Added tile bundles (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review Created 7 years 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
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/containers/hash_tables.h" 12 #include "base/containers/hash_tables.h"
13 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "cc/base/cc_export.h" 14 #include "cc/base/cc_export.h"
15 #include "cc/base/region.h" 15 #include "cc/base/region.h"
16 #include "cc/base/tiling_data.h" 16 #include "cc/base/tiling_data.h"
17 #include "cc/resources/tile.h" 17 #include "cc/resources/tile.h"
18 #include "cc/resources/tile_bundle.h"
18 #include "cc/resources/tile_priority.h" 19 #include "cc/resources/tile_priority.h"
19 #include "ui/gfx/rect.h" 20 #include "ui/gfx/rect.h"
20 21
21 namespace cc { 22 namespace cc {
22 23
23 class PictureLayerTiling; 24 class PictureLayerTiling;
24 25
25 class CC_EXPORT PictureLayerTilingClient { 26 class CC_EXPORT PictureLayerTilingClient {
26 public: 27 public:
27 // 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
28 // 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.
29 virtual scoped_refptr<Tile> CreateTile( 30 virtual scoped_refptr<Tile> CreateTile(
30 PictureLayerTiling* tiling, 31 PictureLayerTiling* tiling,
31 gfx::Rect content_rect) = 0; 32 gfx::Rect content_rect) = 0;
33 virtual scoped_refptr<TileBundle> CreateTileBundle(gfx::Rect bundle_rect) = 0;
32 virtual void UpdatePile(Tile* tile) = 0; 34 virtual void UpdatePile(Tile* tile) = 0;
33 virtual gfx::Size CalculateTileSize( 35 virtual gfx::Size CalculateTileSize(
34 gfx::Size content_bounds) const = 0; 36 gfx::Size content_bounds) const = 0;
35 virtual const Region* GetInvalidation() = 0; 37 virtual const Region* GetInvalidation() = 0;
36 virtual const PictureLayerTiling* GetTwinTiling( 38 virtual const PictureLayerTiling* GetTwinTiling(
37 const PictureLayerTiling* tiling) const = 0; 39 const PictureLayerTiling* tiling) const = 0;
40 virtual bool IsActive() const = 0;
41 virtual bool IsPending() const = 0;
38 42
39 protected: 43 protected:
40 virtual ~PictureLayerTilingClient() {} 44 virtual ~PictureLayerTilingClient() {}
41 }; 45 };
42 46
43 class CC_EXPORT PictureLayerTiling { 47 class CC_EXPORT PictureLayerTiling {
44 public: 48 public:
45 ~PictureLayerTiling(); 49 ~PictureLayerTiling();
46 50
47 // Create a tiling with no tiles. CreateTiles must be called to add some. 51 // Create a tiling with no tiles. CreateTiles must be called to add some.
(...skipping 11 matching lines...) Expand all
59 void SetClient(PictureLayerTilingClient* client); 63 void SetClient(PictureLayerTilingClient* client);
60 void set_resolution(TileResolution resolution) { resolution_ = resolution; } 64 void set_resolution(TileResolution resolution) { resolution_ = resolution; }
61 TileResolution resolution() const { return resolution_; } 65 TileResolution resolution() const { return resolution_; }
62 66
63 gfx::Rect ContentRect() const; 67 gfx::Rect ContentRect() const;
64 gfx::SizeF ContentSizeF() const; 68 gfx::SizeF ContentSizeF() const;
65 gfx::Rect live_tiles_rect() const { return live_tiles_rect_; } 69 gfx::Rect live_tiles_rect() const { return live_tiles_rect_; }
66 gfx::Size tile_size() const { return tiling_data_.max_texture_size(); } 70 gfx::Size tile_size() const { return tiling_data_.max_texture_size(); }
67 float contents_scale() const { return contents_scale_; } 71 float contents_scale() const { return contents_scale_; }
68 72
73 Tile* TileAt(WhichTree tree, int, int) const;
74
69 void CreateAllTilesForTesting() { 75 void CreateAllTilesForTesting() {
70 SetLiveTilesRect(gfx::Rect(tiling_data_.total_size())); 76 SetLiveTilesRect(ACTIVE_TREE, gfx::Rect(tiling_data_.total_size()));
77 live_tiles_rect_ = gfx::Rect();
78 SetLiveTilesRect(PENDING_TREE, gfx::Rect(tiling_data_.total_size()));
79 }
80
81 void CreateAllPendingTilesForTesting() {
82 SetLiveTilesRect(PENDING_TREE, gfx::Rect(tiling_data_.total_size()));
83 }
84 void CreateAllActiveTilesForTesting() {
85 SetLiveTilesRect(ACTIVE_TREE, gfx::Rect(tiling_data_.total_size()));
71 } 86 }
72 87
73 std::vector<Tile*> AllTilesForTesting() const { 88 std::vector<Tile*> AllTilesForTesting() const {
74 std::vector<Tile*> all_tiles; 89 std::vector<Tile*> all_tiles;
75 for (TileMap::const_iterator it = tiles_.begin(); 90 for (TileBundleMap::const_iterator it = tile_bundles_.begin();
76 it != tiles_.end(); ++it) 91 it != tile_bundles_.end(); ++it) {
77 all_tiles.push_back(it->second.get()); 92 for (TileBundle::Iterator tile_it(it->second.get()); tile_it; ++tile_it)
93 all_tiles.push_back(*tile_it);
94 }
78 return all_tiles; 95 return all_tiles;
79 } 96 }
80 97
81 Tile* TileAt(int i, int j) const; 98 std::vector<TileBundle*> AllTileBundlesForTesting() const {
99 std::vector<TileBundle*> all_bundles;
100 for (TileBundleMap::const_iterator it = tile_bundles_.begin();
101 it != tile_bundles_.end(); ++it) {
102 all_bundles.push_back(it->second.get());
103 }
104 return all_bundles;
105 }
106
107 std::vector<Tile*> AllPendingTilesForTesting() const {
108 std::vector<Tile*> all_tiles;
109 for (TileBundleMap::const_iterator it = tile_bundles_.begin();
110 it != tile_bundles_.end(); ++it) {
111 for (TileBundle::Iterator tile_it(it->second.get()); tile_it; ++tile_it) {
112 if (!tile_it.active_tree_only_tile())
113 all_tiles.push_back(*tile_it);
114 }
115 }
116 return all_tiles;
117 }
118
119 std::vector<Tile*> AllActiveTilesForTesting() const {
120 std::vector<Tile*> all_tiles;
121 for (TileBundleMap::const_iterator it = tile_bundles_.begin();
122 it != tile_bundles_.end(); ++it) {
123 for (TileBundle::Iterator tile_it(it->second.get()); tile_it; ++tile_it) {
124 if (!tile_it.pending_tree_only_tile())
125 all_tiles.push_back(*tile_it);
126 }
127 }
128 return all_tiles;
129 }
82 130
83 // Iterate over all tiles to fill content_rect. Even if tiles are invalid 131 // Iterate over all tiles to fill content_rect. Even if tiles are invalid
84 // (i.e. no valid resource) this tiling should still iterate over them. 132 // (i.e. no valid resource) this tiling should still iterate over them.
85 // The union of all geometry_rect calls for each element iterated over should 133 // The union of all geometry_rect calls for each element iterated over should
86 // exactly equal content_rect and no two geometry_rects should intersect. 134 // exactly equal content_rect and no two geometry_rects should intersect.
87 class CC_EXPORT CoverageIterator { 135 class CC_EXPORT CoverageIterator {
88 public: 136 public:
89 CoverageIterator(); 137 CoverageIterator();
90 CoverageIterator(const PictureLayerTiling* tiling, 138 CoverageIterator(const PictureLayerTiling* tiling,
91 float dest_scale, 139 float dest_scale,
92 gfx::Rect rect); 140 gfx::Rect rect);
93 ~CoverageIterator(); 141 ~CoverageIterator();
94 142
95 // Visible rect (no borders), always in the space of content_rect, 143 // Visible rect (no borders), always in the space of content_rect,
96 // regardless of the contents scale of the tiling. 144 // regardless of the contents scale of the tiling.
97 gfx::Rect geometry_rect() const; 145 gfx::Rect geometry_rect() const;
98 // Texture rect (in texels) for geometry_rect 146 // Texture rect (in texels) for geometry_rect
99 gfx::RectF texture_rect() const; 147 gfx::RectF texture_rect() const;
100 gfx::Size texture_size() const; 148 gfx::Size texture_size() const;
101 149
102 // Full rect (including borders) of the current tile, always in the space 150 // Full rect (including borders) of the current tile, always in the space
103 // of content_rect, regardless of the contents scale of the tiling. 151 // of content_rect, regardless of the contents scale of the tiling.
104 gfx::Rect full_tile_geometry_rect() const; 152 gfx::Rect full_tile_geometry_rect() const;
105 153
106 Tile* operator->() const { return current_tile_; } 154 Tile* operator->() const { return current_tile_; }
107 Tile* operator*() const { return current_tile_; } 155 Tile* operator*() const { return current_tile_; }
108 156
157 TilePriority priority();
158 void SetPriorityForTesting(const TilePriority& priority);
159
109 CoverageIterator& operator++(); 160 CoverageIterator& operator++();
110 operator bool() const { return tile_j_ <= bottom_; } 161 operator bool() const { return tile_j_ <= bottom_; }
111 162
112 int i() const { return tile_i_; } 163 int i() const { return tile_i_; }
113 int j() const { return tile_j_; } 164 int j() const { return tile_j_; }
114 165
115 private: 166 private:
116 const PictureLayerTiling* tiling_; 167 const PictureLayerTiling* tiling_;
117 gfx::Rect dest_rect_; 168 gfx::Rect dest_rect_;
118 float dest_to_content_scale_; 169 float dest_to_content_scale_;
119 170
120 Tile* current_tile_; 171 Tile* current_tile_;
121 gfx::Rect current_geometry_rect_; 172 gfx::Rect current_geometry_rect_;
122 int tile_i_; 173 int tile_i_;
123 int tile_j_; 174 int tile_j_;
124 int left_; 175 int left_;
125 int top_; 176 int top_;
126 int right_; 177 int right_;
127 int bottom_; 178 int bottom_;
179 WhichTree tree_;
128 180
129 friend class PictureLayerTiling; 181 friend class PictureLayerTiling;
130 }; 182 };
131 183
132 Region OpaqueRegionInContentRect(gfx::Rect content_rect) const; 184 Region OpaqueRegionInContentRect(gfx::Rect content_rect) const;
133 185
134 void Reset(); 186 void Reset();
135 187
136 void UpdateTilePriorities( 188 void UpdateTilePriorities(
137 WhichTree tree, 189 WhichTree tree,
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 gfx::Rect starting_rect, 234 gfx::Rect starting_rect,
183 int64 target_area, 235 int64 target_area,
184 gfx::Rect bounding_rect, 236 gfx::Rect bounding_rect,
185 RectExpansionCache* cache); 237 RectExpansionCache* cache);
186 238
187 bool has_ever_been_updated() const { 239 bool has_ever_been_updated() const {
188 return last_impl_frame_time_in_seconds_ != 0.0; 240 return last_impl_frame_time_in_seconds_ != 0.0;
189 } 241 }
190 242
191 protected: 243 protected:
192 typedef std::pair<int, int> TileMapKey; 244 friend class TileBundle;
193 typedef base::hash_map<TileMapKey, scoped_refptr<Tile> > TileMap; 245
246 typedef std::pair<int, int> TileBundleMapKey;
247 typedef base::hash_map<TileBundleMapKey, scoped_refptr<TileBundle> >
248 TileBundleMap;
194 249
195 PictureLayerTiling(float contents_scale, 250 PictureLayerTiling(float contents_scale,
196 gfx::Size layer_bounds, 251 gfx::Size layer_bounds,
197 PictureLayerTilingClient* client); 252 PictureLayerTilingClient* client);
198 void SetLiveTilesRect(gfx::Rect live_tiles_rect); 253 void SetLiveTilesRect(WhichTree tree, gfx::Rect live_tiles_rect);
199 void CreateTile(int i, int j, const PictureLayerTiling* twin_tiling); 254 void CreateTile(WhichTree tree,
255 int i,
256 int j,
257 const PictureLayerTiling* twin_tiling);
258 bool RemoveTile(WhichTree tree, int i, int j);
259 void RemoveBundleIfEmptyContainingTileAt(int i, int j);
260 TileBundle* TileBundleContainingTileAt(int, int) const;
261 TileBundle* CreateBundleForTileAt(int,
262 int,
263 const PictureLayerTiling* twin_tiling);
264 TileBundle* TileBundleAt(int, int) const;
200 265
201 // Given properties. 266 // Given properties.
202 float contents_scale_; 267 float contents_scale_;
203 gfx::Size layer_bounds_; 268 gfx::Size layer_bounds_;
204 TileResolution resolution_; 269 TileResolution resolution_;
205 PictureLayerTilingClient* client_; 270 PictureLayerTilingClient* client_;
206 271
207 // Internal data. 272 // Internal data.
208 TilingData tiling_data_; 273 TilingData tiling_data_;
209 TileMap tiles_; // It is not legal to have a NULL tile in the tiles_ map. 274 TilingData bundle_tiling_data_;
275 TileBundleMap tile_bundles_; // It is not legal to have a NULL tile in the
276 // tiles_ map.
210 gfx::Rect live_tiles_rect_; 277 gfx::Rect live_tiles_rect_;
211 278
212 // State saved for computing velocities based upon finite differences. 279 // State saved for computing velocities based upon finite differences.
213 double last_impl_frame_time_in_seconds_; 280 double last_impl_frame_time_in_seconds_;
214 281
215 friend class CoverageIterator; 282 friend class CoverageIterator;
216 283
217 private: 284 private:
218 DISALLOW_ASSIGN(PictureLayerTiling); 285 DISALLOW_ASSIGN(PictureLayerTiling);
219 286
220 RectExpansionCache expansion_cache_; 287 RectExpansionCache expansion_cache_;
221 }; 288 };
222 289
223 } // namespace cc 290 } // namespace cc
224 291
225 #endif // CC_RESOURCES_PICTURE_LAYER_TILING_H_ 292 #endif // CC_RESOURCES_PICTURE_LAYER_TILING_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698