Re-land: C++ readability review
[chromium-blink-merge.git] / cc / resources / tile.h
blobdcc8566fe4b7692ec29a53ae0d9018f58c3b762c
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/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"
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_combined() const {
72 return is_occluded_[ACTIVE_TREE] && is_occluded_[PENDING_TREE];
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;
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;
85 bool use_picture_analysis() const {
86 return !!(flags_ & USE_PICTURE_ANALYSIS);
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();
95 void AsValueWithPriorityInto(const TilePriority& priority,
96 base::trace_event::TracedValue* dict) const;
98 inline bool IsReadyToDraw() const { return draw_info_.IsReadyToDraw(); }
100 const TileDrawInfo& draw_info() const { return draw_info_; }
102 TileDrawInfo& draw_info() { return draw_info_; }
104 float contents_scale() const { return contents_scale_; }
105 gfx::Rect content_rect() const { return content_rect_; }
107 int layer_id() const { return layer_id_; }
109 int source_frame_number() const { return source_frame_number_; }
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;
119 size_t GPUMemoryUsageInBytes() const;
121 gfx::Size desired_texture_size() const { return desired_texture_size_; }
123 void set_tiling_index(int i, int j) {
124 tiling_i_index_ = i;
125 tiling_j_index_ = j;
127 int tiling_i_index() const { return tiling_i_index_; }
128 int tiling_j_index() const { return tiling_j_index_; }
130 private:
131 friend class TileManager;
132 friend class PrioritizedTileSet;
133 friend class FakeTileManager;
134 friend class BinComparator;
135 friend class FakePictureLayerImpl;
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();
148 bool HasRasterTask() const { return !!raster_task_.get(); }
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];
156 TilePriority priority_[LAST_TREE + 1];
157 TileDrawInfo draw_info_;
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;
168 Id id_;
169 static Id s_next_id_;
171 unsigned scheduled_priority_;
173 scoped_refptr<RasterTask> raster_task_;
175 DISALLOW_COPY_AND_ASSIGN(Tile);
178 } // namespace cc
180 #endif // CC_RESOURCES_TILE_H_