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 "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_vector.h" 11 #include "cc/base/ref_counted_managed.h" 12 #include "cc/resources/managed_tile_state.h" 13 #include "cc/resources/picture_pile_impl.h" 14 #include "cc/resources/raster_mode.h" 15 #include "cc/resources/tile_priority.h" 16 #include "ui/gfx/rect.h" 17 #include "ui/gfx/size.h" 18 19 namespace cc { 20 21 class CC_EXPORT Tile : public RefCountedManaged<Tile> { 22 public: 23 enum TileRasterFlags { USE_PICTURE_ANALYSIS = 1 << 0 }; 24 25 typedef uint64 Id; 26 27 Id id() const { 28 return id_; 29 } 30 31 PicturePileImpl* picture_pile() { 32 return picture_pile_.get(); 33 } 34 35 const PicturePileImpl* picture_pile() const { 36 return picture_pile_.get(); 37 } 38 39 const TilePriority& priority(WhichTree tree) const { 40 return priority_[tree]; 41 } 42 43 TilePriority priority_for_tree_priority(TreePriority tree_priority) const { 44 switch (tree_priority) { 45 case SMOOTHNESS_TAKES_PRIORITY: 46 return priority_[ACTIVE_TREE]; 47 case NEW_CONTENT_TAKES_PRIORITY: 48 return priority_[PENDING_TREE]; 49 case SAME_PRIORITY_FOR_BOTH_TREES: 50 return combined_priority(); 51 } 52 NOTREACHED(); 53 return TilePriority(); 54 } 55 56 TilePriority combined_priority() const { 57 return TilePriority(priority_[ACTIVE_TREE], 58 priority_[PENDING_TREE]); 59 } 60 61 void SetPriority(WhichTree tree, const TilePriority& priority); 62 63 void MarkRequiredForActivation(); 64 65 bool required_for_activation() const { 66 return priority_[PENDING_TREE].required_for_activation; 67 } 68 69 bool use_picture_analysis() const { 70 return !!(flags_ & USE_PICTURE_ANALYSIS); 71 } 72 73 bool NeedsRasterForMode(RasterMode mode) const { 74 return !managed_state_.tile_versions[mode].IsReadyToDraw(); 75 } 76 77 bool HasResources() const { 78 for (int mode = 0; mode < NUM_RASTER_MODES; ++mode) { 79 if (managed_state_.tile_versions[mode].has_resource()) 80 return true; 81 } 82 return false; 83 } 84 85 scoped_ptr<base::Value> AsValue() const; 86 87 inline bool IsReadyToDraw() const { 88 for (int mode = 0; mode < NUM_RASTER_MODES; ++mode) { 89 if (managed_state_.tile_versions[mode].IsReadyToDraw()) 90 return true; 91 } 92 return false; 93 } 94 95 const ManagedTileState::TileVersion& GetTileVersionForDrawing() const { 96 for (int mode = 0; mode < NUM_RASTER_MODES; ++mode) { 97 if (managed_state_.tile_versions[mode].IsReadyToDraw()) 98 return managed_state_.tile_versions[mode]; 99 } 100 return managed_state_.tile_versions[HIGH_QUALITY_RASTER_MODE]; 101 } 102 103 gfx::Rect opaque_rect() const { return opaque_rect_; } 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_picture_pile(scoped_refptr<PicturePileImpl> pile) { 112 DCHECK(pile->CanRaster(contents_scale_, content_rect_)); 113 picture_pile_ = pile; 114 } 115 116 size_t GPUMemoryUsageInBytes() const; 117 118 gfx::Size size() const { return tile_size_.size(); } 119 120 RasterMode DetermineRasterModeForTree(WhichTree tree) const; 121 RasterMode DetermineOverallRasterMode() const; 122 123 // Functionality used in tests. 124 RasterMode GetRasterModeForTesting() const { 125 return managed_state().raster_mode; 126 } 127 ManagedTileState::TileVersion& GetTileVersionForTesting(RasterMode mode) { 128 return managed_state_.tile_versions[mode]; 129 } 130 131 private: 132 friend class TileManager; 133 friend class PrioritizedTileSet; 134 friend class FakeTileManager; 135 friend class BinComparator; 136 friend class FakePictureLayerImpl; 137 138 // Methods called by by tile manager. 139 Tile(TileManager* tile_manager, 140 PicturePileImpl* picture_pile, 141 const gfx::Size& tile_size, 142 const gfx::Rect& content_rect, 143 const gfx::Rect& opaque_rect, 144 float contents_scale, 145 int layer_id, 146 int source_frame_number, 147 int flags); 148 ~Tile(); 149 150 ManagedTileState& managed_state() { return managed_state_; } 151 const ManagedTileState& managed_state() const { return managed_state_; } 152 RasterMode DetermineRasterModeForResolution(TileResolution resolution) const; 153 154 TileManager* tile_manager_; 155 scoped_refptr<PicturePileImpl> picture_pile_; 156 gfx::Rect tile_size_; 157 gfx::Rect content_rect_; 158 float contents_scale_; 159 gfx::Rect opaque_rect_; 160 161 TilePriority priority_[NUM_TREES]; 162 ManagedTileState managed_state_; 163 int layer_id_; 164 int source_frame_number_; 165 int flags_; 166 167 Id id_; 168 static Id s_next_id_; 169 170 DISALLOW_COPY_AND_ASSIGN(Tile); 171 }; 172 173 } // namespace cc 174 175 #endif // CC_RESOURCES_TILE_H_ 176