OLD | NEW |
| (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_RESOURCES_TILE_H_ | |
6 #define CC_RESOURCES_TILE_H_ | |
7 | |
8 #include "base/memory/ref_counted.h" | |
9 #include "cc/base/ref_counted_managed.h" | |
10 #include "cc/resources/raster_source.h" | |
11 #include "cc/resources/tile_draw_info.h" | |
12 #include "cc/resources/tile_priority.h" | |
13 #include "ui/gfx/geometry/rect.h" | |
14 #include "ui/gfx/geometry/size.h" | |
15 | |
16 namespace cc { | |
17 | |
18 class TileManager; | |
19 | |
20 class CC_EXPORT Tile : public RefCountedManaged<Tile> { | |
21 public: | |
22 enum TileRasterFlags { USE_PICTURE_ANALYSIS = 1 << 0 }; | |
23 | |
24 typedef uint64 Id; | |
25 | |
26 Id id() const { | |
27 return id_; | |
28 } | |
29 | |
30 RasterSource* raster_source() { return raster_source_.get(); } | |
31 | |
32 const RasterSource* raster_source() const { return raster_source_.get(); } | |
33 | |
34 const TilePriority& priority(WhichTree tree) const { | |
35 return priority_[tree]; | |
36 } | |
37 | |
38 TilePriority priority_for_tree_priority(TreePriority tree_priority) const { | |
39 switch (tree_priority) { | |
40 case SMOOTHNESS_TAKES_PRIORITY: | |
41 return priority_[ACTIVE_TREE]; | |
42 case NEW_CONTENT_TAKES_PRIORITY: | |
43 return priority_[PENDING_TREE]; | |
44 case SAME_PRIORITY_FOR_BOTH_TREES: | |
45 return combined_priority(); | |
46 default: | |
47 NOTREACHED(); | |
48 return TilePriority(); | |
49 } | |
50 } | |
51 | |
52 TilePriority combined_priority() const { | |
53 return TilePriority(priority_[ACTIVE_TREE], | |
54 priority_[PENDING_TREE]); | |
55 } | |
56 | |
57 void SetPriority(WhichTree tree, const TilePriority& priority) { | |
58 priority_[tree] = priority; | |
59 } | |
60 | |
61 // TODO(vmpstr): Move this to the iterators. | |
62 void set_is_occluded(WhichTree tree, bool is_occluded) { | |
63 is_occluded_[tree] = is_occluded; | |
64 } | |
65 | |
66 bool is_occluded(WhichTree tree) const { return is_occluded_[tree]; } | |
67 | |
68 void set_shared(bool is_shared) { is_shared_ = is_shared; } | |
69 bool is_shared() const { return is_shared_; } | |
70 | |
71 bool is_occluded_combined() const { | |
72 return is_occluded_[ACTIVE_TREE] && is_occluded_[PENDING_TREE]; | |
73 } | |
74 | |
75 // TODO(vmpstr): Move this to the iterators. | |
76 bool required_for_activation() const { return required_for_activation_; } | |
77 void set_required_for_activation(bool is_required) { | |
78 required_for_activation_ = is_required; | |
79 } | |
80 bool required_for_draw() const { return required_for_draw_; } | |
81 void set_required_for_draw(bool is_required) { | |
82 required_for_draw_ = is_required; | |
83 } | |
84 | |
85 bool use_picture_analysis() const { | |
86 return !!(flags_ & USE_PICTURE_ANALYSIS); | |
87 } | |
88 | |
89 bool HasResource() const { return draw_info_.has_resource(); } | |
90 bool NeedsRaster() const { | |
91 return draw_info_.mode() == TileDrawInfo::OOM_MODE || | |
92 !draw_info_.IsReadyToDraw(); | |
93 } | |
94 | |
95 void AsValueWithPriorityInto(const TilePriority& priority, | |
96 base::trace_event::TracedValue* dict) const; | |
97 | |
98 inline bool IsReadyToDraw() const { return draw_info_.IsReadyToDraw(); } | |
99 | |
100 const TileDrawInfo& draw_info() const { return draw_info_; } | |
101 | |
102 TileDrawInfo& draw_info() { return draw_info_; } | |
103 | |
104 float contents_scale() const { return contents_scale_; } | |
105 gfx::Rect content_rect() const { return content_rect_; } | |
106 | |
107 int layer_id() const { return layer_id_; } | |
108 | |
109 int source_frame_number() const { return source_frame_number_; } | |
110 | |
111 void set_raster_source(scoped_refptr<RasterSource> raster_source) { | |
112 DCHECK(raster_source->CoversRect(content_rect_, contents_scale_)) | |
113 << "Recording rect: " | |
114 << gfx::ScaleToEnclosingRect(content_rect_, 1.f / contents_scale_) | |
115 .ToString(); | |
116 raster_source_ = raster_source; | |
117 } | |
118 | |
119 size_t GPUMemoryUsageInBytes() const; | |
120 | |
121 gfx::Size desired_texture_size() const { return desired_texture_size_; } | |
122 | |
123 void set_tiling_index(int i, int j) { | |
124 tiling_i_index_ = i; | |
125 tiling_j_index_ = j; | |
126 } | |
127 int tiling_i_index() const { return tiling_i_index_; } | |
128 int tiling_j_index() const { return tiling_j_index_; } | |
129 | |
130 private: | |
131 friend class TileManager; | |
132 friend class PrioritizedTileSet; | |
133 friend class FakeTileManager; | |
134 friend class BinComparator; | |
135 friend class FakePictureLayerImpl; | |
136 | |
137 // Methods called by by tile manager. | |
138 Tile(TileManager* tile_manager, | |
139 RasterSource* raster_source, | |
140 const gfx::Size& desired_texture_size, | |
141 const gfx::Rect& content_rect, | |
142 float contents_scale, | |
143 int layer_id, | |
144 int source_frame_number, | |
145 int flags); | |
146 ~Tile(); | |
147 | |
148 bool HasRasterTask() const { return !!raster_task_.get(); } | |
149 | |
150 scoped_refptr<RasterSource> raster_source_; | |
151 gfx::Size desired_texture_size_; | |
152 gfx::Rect content_rect_; | |
153 float contents_scale_; | |
154 bool is_occluded_[LAST_TREE + 1]; | |
155 | |
156 TilePriority priority_[LAST_TREE + 1]; | |
157 TileDrawInfo draw_info_; | |
158 | |
159 int layer_id_; | |
160 int source_frame_number_; | |
161 int flags_; | |
162 int tiling_i_index_; | |
163 int tiling_j_index_; | |
164 bool is_shared_ : 1; | |
165 bool required_for_activation_ : 1; | |
166 bool required_for_draw_ : 1; | |
167 | |
168 Id id_; | |
169 static Id s_next_id_; | |
170 | |
171 unsigned scheduled_priority_; | |
172 | |
173 scoped_refptr<RasterTask> raster_task_; | |
174 | |
175 DISALLOW_COPY_AND_ASSIGN(Tile); | |
176 }; | |
177 | |
178 } // namespace cc | |
179 | |
180 #endif // CC_RESOURCES_TILE_H_ | |
OLD | NEW |