cc: Clean-up of ManageTileState
[chromium-blink-merge.git] / cc / resources / tile.h
bloba35cffe86f5fa0e59c6f4ee9a5566f8eed775e4e
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.
5 #ifndef CC_RESOURCES_TILE_H_
6 #define CC_RESOURCES_TILE_H_
8 #include "base/memory/ref_counted.h"
9 #include "cc/base/ref_counted_managed.h"
10 #include "cc/resources/managed_tile_state.h"
11 #include "cc/resources/raster_source.h"
12 #include "cc/resources/tile_priority.h"
13 #include "ui/gfx/geometry/rect.h"
14 #include "ui/gfx/geometry/size.h"
16 namespace cc {
18 class TileManager;
20 class CC_EXPORT Tile : public RefCountedManaged<Tile> {
21 public:
22 enum TileRasterFlags { USE_PICTURE_ANALYSIS = 1 << 0 };
24 typedef uint64 Id;
26 Id id() const {
27 return id_;
30 RasterSource* raster_source() { return raster_source_.get(); }
32 const RasterSource* raster_source() const { return raster_source_.get(); }
34 const TilePriority& priority(WhichTree tree) const {
35 return priority_[tree];
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();
52 TilePriority combined_priority() const {
53 return TilePriority(priority_[ACTIVE_TREE],
54 priority_[PENDING_TREE]);
57 void SetPriority(WhichTree tree, const TilePriority& priority) {
58 priority_[tree] = priority;
61 // TODO(vmpstr): Move this to the iterators.
62 void set_is_occluded(WhichTree tree, bool is_occluded) {
63 is_occluded_[tree] = is_occluded;
66 bool is_occluded(WhichTree tree) const { return is_occluded_[tree]; }
68 void set_shared(bool is_shared) { is_shared_ = is_shared; }
69 bool is_shared() const { return is_shared_; }
71 bool is_occluded_for_tree_priority(TreePriority tree_priority) const {
72 switch (tree_priority) {
73 case SMOOTHNESS_TAKES_PRIORITY:
74 return is_occluded_[ACTIVE_TREE];
75 case NEW_CONTENT_TAKES_PRIORITY:
76 return is_occluded_[PENDING_TREE];
77 case SAME_PRIORITY_FOR_BOTH_TREES:
78 return is_occluded_[ACTIVE_TREE] && is_occluded_[PENDING_TREE];
79 default:
80 NOTREACHED();
81 return false;
85 // TODO(vmpstr): Move this to the iterators.
86 bool required_for_activation() const { return required_for_activation_; }
87 void set_required_for_activation(bool is_required) {
88 required_for_activation_ = is_required;
90 bool required_for_draw() const { return required_for_draw_; }
91 void set_required_for_draw(bool is_required) {
92 required_for_draw_ = is_required;
95 bool use_picture_analysis() const {
96 return !!(flags_ & USE_PICTURE_ANALYSIS);
99 bool HasResources() const { return managed_state_.draw_info.has_resource(); }
100 bool NeedsRaster() const {
101 return managed_state_.draw_info.mode() ==
102 ManagedTileState::DrawInfo::PICTURE_PILE_MODE ||
103 !managed_state_.draw_info.IsReadyToDraw();
106 void AsValueInto(base::debug::TracedValue* dict) const;
108 inline bool IsReadyToDraw() const {
109 return managed_state_.draw_info.IsReadyToDraw();
112 const ManagedTileState::DrawInfo& draw_info() const {
113 return managed_state_.draw_info;
116 ManagedTileState::DrawInfo& draw_info() { return managed_state_.draw_info; }
118 float contents_scale() const { return contents_scale_; }
119 gfx::Rect content_rect() const { return content_rect_; }
121 int layer_id() const { return layer_id_; }
123 int source_frame_number() const { return source_frame_number_; }
125 void set_raster_source(scoped_refptr<RasterSource> raster_source) {
126 DCHECK(raster_source->CoversRect(content_rect_, contents_scale_))
127 << "Recording rect: "
128 << gfx::ScaleToEnclosingRect(content_rect_, 1.f / contents_scale_)
129 .ToString();
130 raster_source_ = raster_source;
133 size_t GPUMemoryUsageInBytes() const;
135 gfx::Size size() const { return size_; }
137 void set_tiling_index(int i, int j) {
138 tiling_i_index_ = i;
139 tiling_j_index_ = j;
141 int tiling_i_index() const { return tiling_i_index_; }
142 int tiling_j_index() const { return tiling_j_index_; }
144 private:
145 friend class TileManager;
146 friend class PrioritizedTileSet;
147 friend class FakeTileManager;
148 friend class BinComparator;
149 friend class FakePictureLayerImpl;
151 // Methods called by by tile manager.
152 Tile(TileManager* tile_manager,
153 RasterSource* raster_source,
154 const gfx::Size& tile_size,
155 const gfx::Rect& content_rect,
156 float contents_scale,
157 int layer_id,
158 int source_frame_number,
159 int flags);
160 ~Tile();
162 ManagedTileState& managed_state() { return managed_state_; }
163 const ManagedTileState& managed_state() const { return managed_state_; }
165 bool HasRasterTask() const;
167 TileManager* tile_manager_;
168 scoped_refptr<RasterSource> raster_source_;
169 gfx::Size size_;
170 gfx::Rect content_rect_;
171 float contents_scale_;
172 bool is_occluded_[NUM_TREES];
174 TilePriority priority_[NUM_TREES];
175 ManagedTileState managed_state_;
176 int layer_id_;
177 int source_frame_number_;
178 int flags_;
179 bool is_shared_;
180 int tiling_i_index_;
181 int tiling_j_index_;
182 bool required_for_activation_;
183 bool required_for_draw_;
185 Id id_;
186 static Id s_next_id_;
188 DISALLOW_COPY_AND_ASSIGN(Tile);
191 } // namespace cc
193 #endif // CC_RESOURCES_TILE_H_