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

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

Issue 228173002: cc: Separate RasterWorkerPool interface from implementation details. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address review feedback Created 6 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
« no previous file with comments | « cc/resources/rasterizer_delegate.cc ('k') | cc/resources/tile_manager.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_TILE_MANAGER_H_ 5 #ifndef CC_RESOURCES_TILE_MANAGER_H_
6 #define CC_RESOURCES_TILE_MANAGER_H_ 6 #define CC_RESOURCES_TILE_MANAGER_H_
7 7
8 #include <queue> 8 #include <queue>
9 #include <set> 9 #include <set>
10 #include <utility> 10 #include <utility>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/containers/hash_tables.h" 13 #include "base/containers/hash_tables.h"
14 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
15 #include "base/values.h" 15 #include "base/values.h"
16 #include "cc/base/ref_counted_managed.h" 16 #include "cc/base/ref_counted_managed.h"
17 #include "cc/debug/rendering_stats_instrumentation.h" 17 #include "cc/debug/rendering_stats_instrumentation.h"
18 #include "cc/layers/picture_layer_impl.h" 18 #include "cc/layers/picture_layer_impl.h"
19 #include "cc/resources/managed_tile_state.h" 19 #include "cc/resources/managed_tile_state.h"
20 #include "cc/resources/memory_history.h" 20 #include "cc/resources/memory_history.h"
21 #include "cc/resources/picture_pile_impl.h" 21 #include "cc/resources/picture_pile_impl.h"
22 #include "cc/resources/prioritized_tile_set.h" 22 #include "cc/resources/prioritized_tile_set.h"
23 #include "cc/resources/raster_worker_pool.h" 23 #include "cc/resources/rasterizer.h"
24 #include "cc/resources/resource_pool.h" 24 #include "cc/resources/resource_pool.h"
25 #include "cc/resources/tile.h" 25 #include "cc/resources/tile.h"
26 26
27 namespace cc { 27 namespace cc {
28 class RasterWorkerPoolDelegate; 28 class RasterizerDelegate;
29 class ResourceProvider; 29 class ResourceProvider;
30 30
31 class CC_EXPORT TileManagerClient { 31 class CC_EXPORT TileManagerClient {
32 public: 32 public:
33 virtual void NotifyReadyToActivate() = 0; 33 virtual void NotifyReadyToActivate() = 0;
34 34
35 protected: 35 protected:
36 virtual ~TileManagerClient() {} 36 virtual ~TileManagerClient() {}
37 }; 37 };
38 38
39 struct RasterTaskCompletionStats { 39 struct RasterTaskCompletionStats {
40 RasterTaskCompletionStats(); 40 RasterTaskCompletionStats();
41 41
42 size_t completed_count; 42 size_t completed_count;
43 size_t canceled_count; 43 size_t canceled_count;
44 }; 44 };
45 scoped_ptr<base::Value> RasterTaskCompletionStatsAsValue( 45 scoped_ptr<base::Value> RasterTaskCompletionStatsAsValue(
46 const RasterTaskCompletionStats& stats); 46 const RasterTaskCompletionStats& stats);
47 47
48 // This class manages tiles, deciding which should get rasterized and which 48 // This class manages tiles, deciding which should get rasterized and which
49 // should no longer have any memory assigned to them. Tile objects are "owned" 49 // should no longer have any memory assigned to them. Tile objects are "owned"
50 // by layers; they automatically register with the manager when they are 50 // by layers; they automatically register with the manager when they are
51 // created, and unregister from the manager when they are deleted. 51 // created, and unregister from the manager when they are deleted.
52 class CC_EXPORT TileManager : public RasterWorkerPoolClient, 52 class CC_EXPORT TileManager : public RasterizerClient,
53 public RefCountedManager<Tile> { 53 public RefCountedManager<Tile> {
54 public: 54 public:
55 struct CC_EXPORT PairedPictureLayer { 55 struct CC_EXPORT PairedPictureLayer {
56 PairedPictureLayer(); 56 PairedPictureLayer();
57 ~PairedPictureLayer(); 57 ~PairedPictureLayer();
58 58
59 PictureLayerImpl* active_layer; 59 PictureLayerImpl* active_layer;
60 PictureLayerImpl* pending_layer; 60 PictureLayerImpl* pending_layer;
61 }; 61 };
62 62
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 102
103 std::vector<PairedPictureLayerIterator> paired_iterators_; 103 std::vector<PairedPictureLayerIterator> paired_iterators_;
104 std::vector<PairedPictureLayerIterator*> iterator_heap_; 104 std::vector<PairedPictureLayerIterator*> iterator_heap_;
105 TreePriority tree_priority_; 105 TreePriority tree_priority_;
106 RasterOrderComparator comparator_; 106 RasterOrderComparator comparator_;
107 }; 107 };
108 108
109 static scoped_ptr<TileManager> Create( 109 static scoped_ptr<TileManager> Create(
110 TileManagerClient* client, 110 TileManagerClient* client,
111 ResourceProvider* resource_provider, 111 ResourceProvider* resource_provider,
112 RasterWorkerPool* raster_worker_pool, 112 Rasterizer* rasterizer,
113 RasterWorkerPool* gpu_raster_worker_pool, 113 Rasterizer* gpu_rasterizer,
114 size_t max_raster_usage_bytes, 114 size_t max_raster_usage_bytes,
115 bool use_rasterize_on_demand, 115 bool use_rasterize_on_demand,
116 RenderingStatsInstrumentation* rendering_stats_instrumentation); 116 RenderingStatsInstrumentation* rendering_stats_instrumentation);
117 virtual ~TileManager(); 117 virtual ~TileManager();
118 118
119 void ManageTiles(const GlobalStateThatImpactsTilePriority& state); 119 void ManageTiles(const GlobalStateThatImpactsTilePriority& state);
120 120
121 // Returns true when visible tiles have been initialized. 121 // Returns true when visible tiles have been initialized.
122 bool UpdateVisibleTiles(); 122 bool UpdateVisibleTiles();
123 123
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 resource_pool_->SetResourceUsageLimits( 171 resource_pool_->SetResourceUsageLimits(
172 global_state_.soft_memory_limit_in_bytes, 172 global_state_.soft_memory_limit_in_bytes,
173 global_state_.unused_memory_limit_in_bytes, 173 global_state_.unused_memory_limit_in_bytes,
174 global_state_.num_resources_limit); 174 global_state_.num_resources_limit);
175 } 175 }
176 } 176 }
177 177
178 protected: 178 protected:
179 TileManager(TileManagerClient* client, 179 TileManager(TileManagerClient* client,
180 ResourceProvider* resource_provider, 180 ResourceProvider* resource_provider,
181 RasterWorkerPool* raster_worker_pool, 181 Rasterizer* rasterizer,
182 RasterWorkerPool* gpu_raster_worker_pool, 182 Rasterizer* gpu_rasterizer,
183 size_t max_raster_usage_bytes, 183 size_t max_raster_usage_bytes,
184 bool use_rasterize_on_demand, 184 bool use_rasterize_on_demand,
185 RenderingStatsInstrumentation* rendering_stats_instrumentation); 185 RenderingStatsInstrumentation* rendering_stats_instrumentation);
186 186
187 // Methods called by Tile 187 // Methods called by Tile
188 friend class Tile; 188 friend class Tile;
189 void DidChangeTilePriority(Tile* tile); 189 void DidChangeTilePriority(Tile* tile);
190 190
191 void CleanUpReleasedTiles(); 191 void CleanUpReleasedTiles();
192 192
193 // Overriden from RefCountedManager<Tile>: 193 // Overriden from RefCountedManager<Tile>:
194 virtual void Release(Tile* tile) OVERRIDE; 194 virtual void Release(Tile* tile) OVERRIDE;
195 195
196 // Overriden from RasterWorkerPoolClient: 196 // Overriden from RasterizerClient:
197 virtual bool ShouldForceTasksRequiredForActivationToComplete() const OVERRIDE; 197 virtual bool ShouldForceTasksRequiredForActivationToComplete() const OVERRIDE;
198 virtual void DidFinishRunningTasks() OVERRIDE; 198 virtual void DidFinishRunningTasks() OVERRIDE;
199 virtual void DidFinishRunningTasksRequiredForActivation() OVERRIDE; 199 virtual void DidFinishRunningTasksRequiredForActivation() OVERRIDE;
200 200
201 typedef std::vector<Tile*> TileVector; 201 typedef std::vector<Tile*> TileVector;
202 typedef std::set<Tile*> TileSet; 202 typedef std::set<Tile*> TileSet;
203 203
204 // Virtual for test 204 // Virtual for test
205 virtual void ScheduleTasks( 205 virtual void ScheduleTasks(
206 const TileVector& tiles_that_need_to_be_rasterized); 206 const TileVector& tiles_that_need_to_be_rasterized);
207 207
208 void AssignGpuMemoryToTiles(PrioritizedTileSet* tiles, 208 void AssignGpuMemoryToTiles(PrioritizedTileSet* tiles,
209 TileVector* tiles_that_need_to_be_rasterized); 209 TileVector* tiles_that_need_to_be_rasterized);
210 void GetTilesWithAssignedBins(PrioritizedTileSet* tiles); 210 void GetTilesWithAssignedBins(PrioritizedTileSet* tiles);
211 211
212 private: 212 private:
213 enum RasterWorkerPoolType { 213 enum RasterizerType {
214 RASTER_WORKER_POOL_TYPE_DEFAULT, 214 RASTERIZER_TYPE_DEFAULT,
215 RASTER_WORKER_POOL_TYPE_GPU, 215 RASTERIZER_TYPE_GPU,
216 NUM_RASTER_WORKER_POOL_TYPES 216 NUM_RASTERIZER_TYPES
217 }; 217 };
218 218
219 void OnImageDecodeTaskCompleted(int layer_id, 219 void OnImageDecodeTaskCompleted(int layer_id,
220 SkPixelRef* pixel_ref, 220 SkPixelRef* pixel_ref,
221 bool was_canceled); 221 bool was_canceled);
222 void OnRasterTaskCompleted(Tile::Id tile, 222 void OnRasterTaskCompleted(Tile::Id tile,
223 scoped_ptr<ScopedResource> resource, 223 scoped_ptr<ScopedResource> resource,
224 RasterMode raster_mode, 224 RasterMode raster_mode,
225 const PicturePileImpl::Analysis& analysis, 225 const PicturePileImpl::Analysis& analysis,
226 bool was_canceled); 226 bool was_canceled);
227 227
228 inline size_t BytesConsumedIfAllocated(const Tile* tile) const { 228 inline size_t BytesConsumedIfAllocated(const Tile* tile) const {
229 return Resource::MemorySizeBytes(tile->size(), resource_format_); 229 return Resource::MemorySizeBytes(tile->size(), resource_format_);
230 } 230 }
231 231
232 void FreeResourceForTile(Tile* tile, RasterMode mode); 232 void FreeResourceForTile(Tile* tile, RasterMode mode);
233 void FreeResourcesForTile(Tile* tile); 233 void FreeResourcesForTile(Tile* tile);
234 void FreeUnusedResourcesForTile(Tile* tile); 234 void FreeUnusedResourcesForTile(Tile* tile);
235 scoped_refptr<internal::WorkerPoolTask> CreateImageDecodeTask( 235 scoped_refptr<internal::ImageDecodeTask> CreateImageDecodeTask(
236 Tile* tile, 236 Tile* tile,
237 SkPixelRef* pixel_ref); 237 SkPixelRef* pixel_ref);
238 scoped_refptr<internal::RasterWorkerPoolTask> CreateRasterTask(Tile* tile); 238 scoped_refptr<internal::RasterTask> CreateRasterTask(Tile* tile);
239 scoped_ptr<base::Value> GetMemoryRequirementsAsValue() const; 239 scoped_ptr<base::Value> GetMemoryRequirementsAsValue() const;
240 void UpdatePrioritizedTileSetIfNeeded(); 240 void UpdatePrioritizedTileSetIfNeeded();
241 241
242 TileManagerClient* client_; 242 TileManagerClient* client_;
243 scoped_ptr<ResourcePool> resource_pool_; 243 scoped_ptr<ResourcePool> resource_pool_;
244 scoped_ptr<RasterWorkerPoolDelegate> raster_worker_pool_delegate_; 244 scoped_ptr<RasterizerDelegate> rasterizer_delegate_;
245 GlobalStateThatImpactsTilePriority global_state_; 245 GlobalStateThatImpactsTilePriority global_state_;
246 246
247 typedef base::hash_map<Tile::Id, Tile*> TileMap; 247 typedef base::hash_map<Tile::Id, Tile*> TileMap;
248 TileMap tiles_; 248 TileMap tiles_;
249 249
250 PrioritizedTileSet prioritized_tiles_; 250 PrioritizedTileSet prioritized_tiles_;
251 bool prioritized_tiles_dirty_; 251 bool prioritized_tiles_dirty_;
252 252
253 bool all_tiles_that_need_to_be_rasterized_have_memory_; 253 bool all_tiles_that_need_to_be_rasterized_have_memory_;
254 bool all_tiles_required_for_activation_have_memory_; 254 bool all_tiles_required_for_activation_have_memory_;
255 255
256 size_t memory_required_bytes_; 256 size_t memory_required_bytes_;
257 size_t memory_nice_to_have_bytes_; 257 size_t memory_nice_to_have_bytes_;
258 258
259 size_t bytes_releasable_; 259 size_t bytes_releasable_;
260 size_t resources_releasable_; 260 size_t resources_releasable_;
261 size_t max_raster_usage_bytes_; 261 size_t max_raster_usage_bytes_;
262 262
263 bool ever_exceeded_memory_budget_; 263 bool ever_exceeded_memory_budget_;
264 MemoryHistory::Entry memory_stats_from_last_assign_; 264 MemoryHistory::Entry memory_stats_from_last_assign_;
265 265
266 RenderingStatsInstrumentation* rendering_stats_instrumentation_; 266 RenderingStatsInstrumentation* rendering_stats_instrumentation_;
267 267
268 bool did_initialize_visible_tile_; 268 bool did_initialize_visible_tile_;
269 bool did_check_for_completed_tasks_since_last_schedule_tasks_; 269 bool did_check_for_completed_tasks_since_last_schedule_tasks_;
270 270
271 typedef base::hash_map<uint32_t, scoped_refptr<internal::WorkerPoolTask> > 271 typedef base::hash_map<uint32_t, scoped_refptr<internal::ImageDecodeTask> >
272 PixelRefTaskMap; 272 PixelRefTaskMap;
273 typedef base::hash_map<int, PixelRefTaskMap> LayerPixelRefTaskMap; 273 typedef base::hash_map<int, PixelRefTaskMap> LayerPixelRefTaskMap;
274 LayerPixelRefTaskMap image_decode_tasks_; 274 LayerPixelRefTaskMap image_decode_tasks_;
275 275
276 typedef base::hash_map<int, int> LayerCountMap; 276 typedef base::hash_map<int, int> LayerCountMap;
277 LayerCountMap used_layer_counts_; 277 LayerCountMap used_layer_counts_;
278 278
279 RasterTaskCompletionStats update_visible_tiles_stats_; 279 RasterTaskCompletionStats update_visible_tiles_stats_;
280 280
281 std::vector<Tile*> released_tiles_; 281 std::vector<Tile*> released_tiles_;
282 282
283 bool use_rasterize_on_demand_; 283 bool use_rasterize_on_demand_;
284 284
285 ResourceFormat resource_format_; 285 ResourceFormat resource_format_;
286 286
287 // Queues used when scheduling raster tasks. 287 // Queues used when scheduling raster tasks.
288 RasterTaskQueue raster_queue_[NUM_RASTER_WORKER_POOL_TYPES]; 288 RasterTaskQueue raster_queue_[NUM_RASTERIZER_TYPES];
289 289
290 std::vector<scoped_refptr<internal::Task> > orphan_raster_tasks_; 290 std::vector<scoped_refptr<internal::RasterTask> > orphan_raster_tasks_;
291 291
292 std::vector<PictureLayerImpl*> layers_; 292 std::vector<PictureLayerImpl*> layers_;
293 293
294 DISALLOW_COPY_AND_ASSIGN(TileManager); 294 DISALLOW_COPY_AND_ASSIGN(TileManager);
295 }; 295 };
296 296
297 } // namespace cc 297 } // namespace cc
298 298
299 #endif // CC_RESOURCES_TILE_MANAGER_H_ 299 #endif // CC_RESOURCES_TILE_MANAGER_H_
OLDNEW
« no previous file with comments | « cc/resources/rasterizer_delegate.cc ('k') | cc/resources/tile_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698