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

Side by Side Diff: cc/tile_manager.h

Issue 12471007: Part 8 of cc/ directory shuffles: resources (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 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
« no previous file with comments | « cc/tile.cc ('k') | cc/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
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef CC_TILE_MANAGER_H_
6 #define CC_TILE_MANAGER_H_
7
8 #include <list>
9 #include <queue>
10 #include <set>
11 #include <vector>
12
13 #include "base/hash_tables.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "base/values.h"
16 #include "cc/base/worker_pool.h"
17 #include "cc/debug/rendering_stats.h"
18 #include "cc/memory_history.h"
19 #include "cc/picture_pile_impl.h"
20 #include "cc/resource_pool.h"
21 #include "cc/tile_priority.h"
22
23 namespace cc {
24 class RasterWorkerPool;
25 class ResourceProvider;
26 class Tile;
27 class TileVersion;
28
29 class CC_EXPORT TileManagerClient {
30 public:
31 virtual void ScheduleManageTiles() = 0;
32 virtual void DidInitializeVisibleTile() = 0;
33
34 protected:
35 virtual ~TileManagerClient() {}
36 };
37
38 // Tile manager classifying tiles into a few basic
39 // bins:
40 enum TileManagerBin {
41 NOW_BIN = 0, // Needed ASAP.
42 SOON_BIN = 1, // Impl-side version of prepainting.
43 EVENTUALLY_BIN = 2, // Nice to have, if we've got memory and time.
44 NEVER_BIN = 3, // Dont bother.
45 NUM_BINS = 4
46 // Be sure to update TileManagerBinAsValue when adding new fields.
47 };
48 scoped_ptr<base::Value> TileManagerBinAsValue(
49 TileManagerBin bin);
50
51 enum TileManagerBinPriority {
52 HIGH_PRIORITY_BIN = 0,
53 LOW_PRIORITY_BIN = 1,
54 NUM_BIN_PRIORITIES = 2
55 };
56 scoped_ptr<base::Value> TileManagerBinPriorityAsValue(
57 TileManagerBinPriority bin);
58
59 enum TileRasterState {
60 IDLE_STATE = 0,
61 WAITING_FOR_RASTER_STATE = 1,
62 RASTER_STATE = 2,
63 UPLOAD_STATE = 3,
64 FORCED_UPLOAD_COMPLETION_STATE = 4,
65 NUM_STATES = 5
66 };
67 scoped_ptr<base::Value> TileRasterStateAsValue(
68 TileRasterState bin);
69
70 // This class manages tiles, deciding which should get rasterized and which
71 // should no longer have any memory assigned to them. Tile objects are "owned"
72 // by layers; they automatically register with the manager when they are
73 // created, and unregister from the manager when they are deleted.
74 class CC_EXPORT TileManager : public WorkerPoolClient {
75 public:
76 TileManager(TileManagerClient* client,
77 ResourceProvider *resource_provider,
78 size_t num_raster_threads,
79 bool use_cheapess_estimator,
80 bool use_color_estimator,
81 bool prediction_benchmarking);
82 virtual ~TileManager();
83
84 const GlobalStateThatImpactsTilePriority& GlobalState() const {
85 return global_state_;
86 }
87 void SetGlobalState(const GlobalStateThatImpactsTilePriority& state);
88
89 void ManageTiles();
90 void CheckForCompletedTileUploads();
91 void AbortPendingTileUploads();
92 void ForceTileUploadToComplete(Tile* tile);
93 void DidCompleteFrame();
94
95 scoped_ptr<base::Value> BasicStateAsValue() const;
96 scoped_ptr<base::Value> AllTilesAsValue() const;
97 void GetMemoryStats(size_t* memoryRequiredBytes,
98 size_t* memoryNiceToHaveBytes,
99 size_t* memoryUsedBytes) const;
100 void SetRecordRenderingStats(bool record_rendering_stats);
101 void GetRenderingStats(RenderingStats* stats);
102 bool HasPendingWorkScheduled(WhichTree tree) const;
103
104 const MemoryHistory::Entry& memory_stats_from_last_assign() const {
105 return memory_stats_from_last_assign_;
106 }
107
108 // Overridden from WorkerPoolClient:
109 virtual void DidFinishDispatchingWorkerPoolCompletionCallbacks() OVERRIDE;
110
111 protected:
112 // Methods called by Tile
113 friend class Tile;
114 void RegisterTile(Tile* tile);
115 void UnregisterTile(Tile* tile);
116 void WillModifyTilePriority(
117 Tile* tile, WhichTree tree, const TilePriority& new_priority) {
118 // TODO(nduca): Do something smarter if reprioritization turns out to be
119 // costly.
120 ScheduleManageTiles();
121 }
122
123 private:
124
125 // Data that is passed to raster tasks.
126 struct RasterTaskMetadata {
127 bool prediction_benchmarking;
128 bool is_tile_in_pending_tree_now_bin;
129 TileResolution tile_resolution;
130 int layer_id;
131 };
132
133 RasterTaskMetadata GetRasterTaskMetadata(const Tile& tile) const;
134
135 void SortTiles();
136 void AssignGpuMemoryToTiles();
137 void FreeResourcesForTile(Tile* tile);
138 void ScheduleManageTiles() {
139 if (manage_tiles_pending_)
140 return;
141 client_->ScheduleManageTiles();
142 manage_tiles_pending_ = true;
143 }
144 void DispatchMoreTasks();
145 void AnalyzeTile(Tile* tile);
146 void GatherPixelRefsForTile(Tile* tile);
147 void DispatchImageDecodeTasksForTile(Tile* tile);
148 void DispatchOneImageDecodeTask(
149 scoped_refptr<Tile> tile, skia::LazyPixelRef* pixel_ref);
150 void OnImageDecodeTaskCompleted(
151 scoped_refptr<Tile> tile,
152 uint32_t pixel_ref_id);
153 bool CanDispatchRasterTask(Tile* tile) const;
154 scoped_ptr<ResourcePool::Resource> PrepareTileForRaster(Tile* tile);
155 void DispatchOneRasterTask(scoped_refptr<Tile> tile);
156 void OnRasterTaskCompleted(
157 scoped_refptr<Tile> tile,
158 scoped_ptr<ResourcePool::Resource> resource,
159 int manage_tiles_call_count_when_dispatched);
160 void DidFinishTileInitialization(Tile* tile);
161 void DidTileRasterStateChange(Tile* tile, TileRasterState state);
162 void DidTileTreeBinChange(Tile* tile,
163 TileManagerBin new_tree_bin,
164 WhichTree tree);
165 scoped_ptr<Value> GetMemoryRequirementsAsValue() const;
166
167 static void RunRasterTask(uint8* buffer,
168 const gfx::Rect& rect,
169 float contents_scale,
170 const RasterTaskMetadata& metadata,
171 PicturePileImpl* picture_pile,
172 RenderingStats* stats);
173 static void RunImageDecodeTask(skia::LazyPixelRef* pixel_ref,
174 RenderingStats* stats);
175
176 static void RecordCheapnessPredictorResults(bool is_predicted_cheap,
177 bool is_actually_cheap);
178 static void RecordSolidColorPredictorResults(const SkColor* actual_colors,
179 size_t color_count,
180 bool is_predicted_solid,
181 SkColor predicted_color,
182 bool is_predicted_transparent);
183
184 TileManagerClient* client_;
185 scoped_ptr<ResourcePool> resource_pool_;
186 scoped_ptr<RasterWorkerPool> raster_worker_pool_;
187 bool manage_tiles_pending_;
188 int manage_tiles_call_count_;
189
190 GlobalStateThatImpactsTilePriority global_state_;
191
192 typedef std::vector<Tile*> TileVector;
193 typedef std::set<Tile*> TileSet;
194 TileSet all_tiles_;
195 TileVector live_or_allocated_tiles_;
196 TileVector tiles_that_need_to_be_rasterized_;
197
198 typedef std::list<Tile*> TileList;
199 // Tiles with image decoding tasks. These tiles need to be rasterized
200 // when all the image decoding tasks finish.
201 TileList tiles_with_image_decoding_tasks_;
202
203 typedef base::hash_map<uint32_t, skia::LazyPixelRef*> PixelRefMap;
204 PixelRefMap pending_decode_tasks_;
205
206 typedef std::queue<scoped_refptr<Tile> > TileQueue;
207 TileQueue tiles_with_pending_upload_;
208 size_t bytes_pending_upload_;
209 bool has_performed_uploads_since_last_flush_;
210 bool ever_exceeded_memory_budget_;
211 MemoryHistory::Entry memory_stats_from_last_assign_;
212
213 bool record_rendering_stats_;
214 RenderingStats rendering_stats_;
215
216 bool use_cheapness_estimator_;
217 bool use_color_estimator_;
218 bool did_schedule_cheap_tasks_;
219 bool allow_cheap_tasks_;
220 int raster_state_count_[NUM_STATES][NUM_TREES][NUM_BINS];
221 bool prediction_benchmarking_;
222
223 size_t pending_tasks_;
224 size_t max_pending_tasks_;
225
226 DISALLOW_COPY_AND_ASSIGN(TileManager);
227 };
228
229 } // namespace cc
230
231 #endif // CC_TILE_MANAGER_H_
OLDNEW
« no previous file with comments | « cc/tile.cc ('k') | cc/tile_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698