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

Side by Side Diff: cc/tile_manager.h

Issue 12082086: cc: Improve tile deletion and general tile manager performance. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Detach managed state from tiles Created 7 years, 10 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/tile.h ('k') | cc/tile_manager.cc » ('j') | cc/tile_manager.cc » ('J')
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_TILE_MANAGER_H_ 5 #ifndef CC_TILE_MANAGER_H_
6 #define CC_TILE_MANAGER_H_ 6 #define CC_TILE_MANAGER_H_
7 7
8 #include <list> 8 #include <list>
9 #include <queue> 9 #include <queue>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/hash_tables.h" 12 #include "base/hash_tables.h"
13 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "base/values.h" 14 #include "base/values.h"
15 #include "cc/memory_history.h" 15 #include "cc/memory_history.h"
16 #include "cc/rendering_stats.h" 16 #include "cc/rendering_stats.h"
17 #include "cc/resource_pool.h" 17 #include "cc/resource_pool.h"
18 #include "cc/tile_priority.h" 18 #include "cc/tile_priority.h"
19 19
20 namespace cc { 20 namespace cc {
21 class Tile;
22 } // namespace cc
23
24 #if defined(COMPILER_GCC)
25 namespace BASE_HASH_NAMESPACE {
26 template<>
27 struct hash<cc::Tile*> {
28 size_t operator()(cc::Tile* ptr) const {
29 return hash<size_t>()(reinterpret_cast<size_t>(ptr));
30 }
31 };
32 } // namespace BASE_HASH_NAMESPACE
33 #endif // COMPILER
34
35 namespace cc {
21 class RasterWorkerPool; 36 class RasterWorkerPool;
22 class ResourceProvider; 37 class ResourceProvider;
23 class Tile; 38 class TileManager;
24 class TileVersion; 39 class TileVersion;
25 40
26 class CC_EXPORT TileManagerClient { 41 class CC_EXPORT TileManagerClient {
27 public: 42 public:
28 virtual void ScheduleManageTiles() = 0; 43 virtual void ScheduleManageTiles() = 0;
29 virtual void DidUploadVisibleHighResolutionTile() = 0; 44 virtual void DidUploadVisibleHighResolutionTile() = 0;
30 45
31 protected: 46 protected:
32 virtual ~TileManagerClient() {} 47 virtual ~TileManagerClient() {}
33 }; 48 };
(...skipping 20 matching lines...) Expand all
54 enum TileRasterState { 69 enum TileRasterState {
55 IDLE_STATE = 0, 70 IDLE_STATE = 0,
56 WAITING_FOR_RASTER_STATE = 1, 71 WAITING_FOR_RASTER_STATE = 1,
57 RASTER_STATE = 2, 72 RASTER_STATE = 2,
58 SET_PIXELS_STATE = 3, 73 SET_PIXELS_STATE = 3,
59 NUM_STATES = 4 74 NUM_STATES = 4
60 }; 75 };
61 76
62 // This is state that is specific to a tile that is 77 // This is state that is specific to a tile that is
63 // managed by the TileManager. 78 // managed by the TileManager.
64 class CC_EXPORT ManagedTileState { 79 class CC_EXPORT ManagedTileState : public base::RefCounted<ManagedTileState> {
65 public: 80 public:
66 ManagedTileState(); 81 explicit ManagedTileState(TileManager* tile_manager);
67 ~ManagedTileState();
68 82
69 // Persisted state: valid all the time. 83 // Persisted state: valid all the time.
84 TileManager* tile_manager;
70 bool can_use_gpu_memory; 85 bool can_use_gpu_memory;
71 bool can_be_freed; 86 bool can_be_freed;
72 scoped_ptr<ResourcePool::Resource> resource; 87 scoped_ptr<ResourcePool::Resource> resource;
73 bool resource_is_being_initialized; 88 bool resource_is_being_initialized;
74 bool contents_swizzled; 89 bool contents_swizzled;
75 bool need_to_gather_pixel_refs; 90 bool need_to_gather_pixel_refs;
76 std::list<skia::LazyPixelRef*> pending_pixel_refs; 91 std::list<skia::LazyPixelRef*> pending_pixel_refs;
77 TileRasterState raster_state; 92 TileRasterState raster_state;
93 size_t bytes_consumed_if_allocated;
94 bool visible_high_resolution;
95 scoped_refptr<PicturePileImpl> picture_pile;
96 gfx::Rect content_rect;
97 float contents_scale;
98 gfx::Size tile_size;
99 GLenum format;
78 100
79 // Ephemeral state, valid only during Manage. 101 // Ephemeral state, valid only during Manage.
80 TileManagerBin bin[NUM_BIN_PRIORITIES]; 102 TileManagerBin bin[NUM_BIN_PRIORITIES];
81 TileManagerBin tree_bin[NUM_TREES]; 103 TileManagerBin tree_bin[NUM_TREES];
82 // The bin that the tile would have if the GPU memory manager had a maximally permissive policy, 104 // The bin that the tile would have if the GPU memory manager had a
83 // send to the GPU memory manager to determine policy. 105 // maximally permissive policy, send to the GPU memory manager to
106 // determine policy.
84 TileManagerBin gpu_memmgr_stats_bin; 107 TileManagerBin gpu_memmgr_stats_bin;
85 TileResolution resolution; 108 TileResolution resolution;
86 float time_to_needed_in_seconds; 109 float time_to_needed_in_seconds;
110
111 private:
112 friend class base::RefCounted<ManagedTileState>;
113
114 ~ManagedTileState();
87 }; 115 };
88 116
89 // This class manages tiles, deciding which should get rasterized and which 117 // This class manages tiles, deciding which should get rasterized and which
90 // should no longer have any memory assigned to them. Tile objects are "owned" 118 // should no longer have any memory assigned to them. Tile objects are "owned"
91 // by layers; they automatically register with the manager when they are 119 // by layers; they automatically register with the manager when they are
92 // created, and unregister from the manager when they are deleted. 120 // created, and unregister from the manager when they are deleted.
93 class CC_EXPORT TileManager { 121 class CC_EXPORT TileManager {
94 public: 122 public:
95 TileManager(TileManagerClient* client, 123 TileManager(TileManagerClient* client,
96 ResourceProvider *resource_provider, 124 ResourceProvider *resource_provider,
97 size_t num_raster_threads, 125 size_t num_raster_threads,
98 bool record_rendering_stats); 126 bool record_rendering_stats);
99 virtual ~TileManager(); 127 virtual ~TileManager();
100 128
101 const GlobalStateThatImpactsTilePriority& GlobalState() const { 129 const GlobalStateThatImpactsTilePriority& GlobalState() const {
102 return global_state_; 130 return global_state_;
103 } 131 }
104 void SetGlobalState(const GlobalStateThatImpactsTilePriority& state); 132 void SetGlobalState(const GlobalStateThatImpactsTilePriority& state);
105 133
106 void ManageTiles(); 134 void ManageTiles();
107 void CheckForCompletedTileUploads(); 135 void CheckForCompletedTileUploads();
108 136
109 scoped_ptr<base::Value> AsValue() const; 137 scoped_ptr<base::Value> AsValue() const;
110 void GetMemoryStats(size_t* memoryRequiredBytes, 138 void GetMemoryStats(size_t* memory_required_bytes,
111 size_t* memoryNiceToHaveBytes, 139 size_t* memory_nice_to_have_bytes,
112 size_t* memoryUsedBytes) const; 140 size_t* memory_used_bytes) const;
113 void GetRenderingStats(RenderingStats* stats); 141 void GetRenderingStats(RenderingStats* stats);
114 bool HasPendingWorkScheduled(WhichTree tree) const; 142 bool HasPendingWorkScheduled(WhichTree tree) const;
115 143
116 const MemoryHistory::Entry& memory_stats_from_last_assign() const { return mem ory_stats_from_last_assign_; } 144 const MemoryHistory::Entry& memory_stats_from_last_assign() const {
145 return memory_stats_from_last_assign_;
146 }
117 147
118 protected: 148 protected:
119 // Methods called by Tile 149 // Methods called by Tile
120 friend class Tile; 150 friend class Tile;
121 void RegisterTile(Tile* tile); 151 void RegisterTile(Tile* tile);
122 void UnregisterTile(Tile* tile); 152 void UnregisterTile(Tile* tile);
123 void WillModifyTilePriority( 153 void WillModifyTilePriority(
124 Tile* tile, WhichTree tree, const TilePriority& new_priority) { 154 Tile* tile, WhichTree tree, const TilePriority& new_priority) {
125 // TODO(nduca): Do something smarter if reprioritization turns out to be 155 // TODO(nduca): Do something smarter if reprioritization turns out to be
126 // costly. 156 // costly.
127 ScheduleManageTiles(); 157 ScheduleManageTiles();
128 } 158 }
129 159
130 private: 160 private:
161 friend class ManagedTileState;
162
163 // Methods called by ManagedTileState
164 void RegisterManagedTile(ManagedTileState* mts);
165 void UnregisterManagedTile(ManagedTileState* mts);
166
131 void SortTiles(); 167 void SortTiles();
132 void AssignGpuMemoryToTiles(); 168 void AssignGpuMemoryToTiles();
133 void FreeResourcesForTile(Tile* tile); 169 void FreeResourcesForTile(ManagedTileState* mts);
134 void ScheduleManageTiles() { 170 void ScheduleManageTiles() {
135 if (manage_tiles_pending_) 171 if (manage_tiles_pending_)
136 return; 172 return;
137 client_->ScheduleManageTiles(); 173 client_->ScheduleManageTiles();
138 manage_tiles_pending_ = true; 174 manage_tiles_pending_ = true;
139 } 175 }
140 void DispatchMoreTasks(); 176 void DispatchMoreTasks();
141 void GatherPixelRefsForTile(Tile* tile); 177 void GatherPixelRefsForTile(ManagedTileState* mts);
142 void DispatchImageDecodeTasksForTile(Tile* tile); 178 void DispatchImageDecodeTasksForTile(ManagedTileState* mts);
143 void DispatchOneImageDecodeTask( 179 void DispatchOneImageDecodeTask(
144 scoped_refptr<Tile> tile, skia::LazyPixelRef* pixel_ref); 180 scoped_refptr<ManagedTileState> mts, skia::LazyPixelRef* pixel_ref);
145 void OnImageDecodeTaskCompleted( 181 void OnImageDecodeTaskCompleted(
146 scoped_refptr<Tile> tile, uint32_t pixel_ref_id); 182 scoped_refptr<ManagedTileState> mts, uint32_t pixel_ref_id);
147 bool CanDispatchRasterTask(Tile* tile); 183 bool CanDispatchRasterTask(ManagedTileState* mts);
148 void DispatchOneRasterTask(scoped_refptr<Tile> tile); 184 void DispatchOneRasterTask(scoped_refptr<ManagedTileState> mts);
149 void OnRasterTaskCompleted( 185 void OnRasterTaskCompleted(
150 scoped_refptr<Tile> tile, 186 scoped_refptr<ManagedTileState> mts,
151 scoped_ptr<ResourcePool::Resource> resource, 187 scoped_ptr<ResourcePool::Resource> resource,
152 int manage_tiles_call_count_when_dispatched); 188 int manage_tiles_call_count_when_dispatched);
153 void DidFinishTileInitialization(Tile* tile); 189 void DidFinishTileInitialization(ManagedTileState* mts);
154 void DidTileRasterStateChange(Tile* tile, TileRasterState state); 190 void DidTileRasterStateChange(ManagedTileState* mts, TileRasterState state);
155 void DidTileBinChange(Tile* tile, 191 void DidTileBinChange(ManagedTileState* mts,
156 TileManagerBin bin, 192 TileManagerBin bin,
157 WhichTree tree); 193 WhichTree tree);
158 scoped_ptr<Value> GetMemoryRequirementsAsValue() const; 194 scoped_ptr<Value> GetMemoryRequirementsAsValue() const;
159 195
160 static void RunRasterTask(uint8* buffer, 196 static void RunRasterTask(uint8* buffer,
161 const gfx::Rect& rect, 197 const gfx::Rect& rect,
162 float contents_scale, 198 float contents_scale,
163 PicturePileImpl* picture_pile, 199 PicturePileImpl* picture_pile,
164 RenderingStats* stats); 200 RenderingStats* stats);
165 static void RunImageDecodeTask(skia::LazyPixelRef* pixel_ref, 201 static void RunImageDecodeTask(skia::LazyPixelRef* pixel_ref,
166 RenderingStats* stats); 202 RenderingStats* stats);
167 203
168 TileManagerClient* client_; 204 TileManagerClient* client_;
169 scoped_ptr<ResourcePool> resource_pool_; 205 scoped_ptr<ResourcePool> resource_pool_;
170 scoped_ptr<RasterWorkerPool> raster_worker_pool_; 206 scoped_ptr<RasterWorkerPool> raster_worker_pool_;
171 bool manage_tiles_pending_; 207 bool manage_tiles_pending_;
172 int manage_tiles_call_count_; 208 int manage_tiles_call_count_;
173 209
174 GlobalStateThatImpactsTilePriority global_state_; 210 GlobalStateThatImpactsTilePriority global_state_;
175 211
176 typedef std::vector<Tile*> TileVector; 212 typedef base::hash_set<Tile*> TileSet;
177 TileVector tiles_; 213 TileSet tiles_;
214
215 typedef std::vector<scoped_refptr<ManagedTileState> > ManagedTileVector;
216 ManagedTileVector managed_tiles_;
217
218 typedef std::vector<ManagedTileState*> TileVector;
178 TileVector tiles_that_need_to_be_rasterized_; 219 TileVector tiles_that_need_to_be_rasterized_;
179 220
180 typedef std::list<Tile*> TileList; 221 typedef std::list<ManagedTileState*> TileList;
181 // Tiles with image decoding tasks. These tiles need to be rasterized 222 // Tiles with image decoding tasks. These tiles need to be rasterized
182 // when all the image decoding tasks finish. 223 // when all the image decoding tasks finish.
183 TileList tiles_with_image_decoding_tasks_; 224 TileList tiles_with_image_decoding_tasks_;
184 225
185 typedef base::hash_map<uint32_t, skia::LazyPixelRef*> PixelRefMap; 226 typedef base::hash_map<uint32_t, skia::LazyPixelRef*> PixelRefMap;
186 PixelRefMap pending_decode_tasks_; 227 PixelRefMap pending_decode_tasks_;
187 228
188 typedef std::queue<scoped_refptr<Tile> > TileQueue; 229 typedef std::queue<scoped_refptr<ManagedTileState> > TileQueue;
189 TileQueue tiles_with_pending_set_pixels_; 230 TileQueue tiles_with_pending_set_pixels_;
190 size_t bytes_pending_set_pixels_; 231 size_t bytes_pending_set_pixels_;
191 bool ever_exceeded_memory_budget_; 232 bool ever_exceeded_memory_budget_;
192 MemoryHistory::Entry memory_stats_from_last_assign_; 233 MemoryHistory::Entry memory_stats_from_last_assign_;
193 234
194 bool record_rendering_stats_; 235 bool record_rendering_stats_;
195 RenderingStats rendering_stats_; 236 RenderingStats rendering_stats_;
196 237
197 int raster_state_count_[NUM_STATES][NUM_TREES][NUM_BINS]; 238 int raster_state_count_[NUM_STATES][NUM_TREES][NUM_BINS];
198 239
199 DISALLOW_COPY_AND_ASSIGN(TileManager); 240 DISALLOW_COPY_AND_ASSIGN(TileManager);
200 }; 241 };
201 242
202 } // namespace cc 243 } // namespace cc
203 244
204 #endif // CC_TILE_MANAGER_H_ 245 #endif // CC_TILE_MANAGER_H_
OLDNEW
« no previous file with comments | « cc/tile.h ('k') | cc/tile_manager.cc » ('j') | cc/tile_manager.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698