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 "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"
21 class CC_EXPORT Tile : public RefCountedManaged<Tile> {
23 enum TileRasterFlags {
24 USE_LCD_TEXT = 1 << 0,
25 USE_GPU_RASTERIZATION = 1 << 1
34 PicturePileImpl* picture_pile() {
35 return picture_pile_.get();
38 const PicturePileImpl* picture_pile() const {
39 return picture_pile_.get();
42 const TilePriority& priority(WhichTree tree) const {
43 return priority_[tree];
46 TilePriority combined_priority() const {
47 return TilePriority(priority_[ACTIVE_TREE],
48 priority_[PENDING_TREE]);
51 void SetPriority(WhichTree tree, const TilePriority& priority);
53 void MarkRequiredForActivation();
55 bool required_for_activation() const {
56 return priority_[PENDING_TREE].required_for_activation;
59 void set_can_use_lcd_text(bool can_use_lcd_text) {
61 flags_ |= USE_LCD_TEXT;
63 flags_ &= ~USE_LCD_TEXT;
66 bool can_use_lcd_text() const {
67 return !!(flags_ & USE_LCD_TEXT);
70 void set_use_gpu_rasterization(bool use_gpu_rasterization) {
71 if (use_gpu_rasterization)
72 flags_ |= USE_GPU_RASTERIZATION;
74 flags_ &= ~USE_GPU_RASTERIZATION;
77 bool use_gpu_rasterization() const {
78 return !!(flags_ & USE_GPU_RASTERIZATION);
81 bool NeedsRasterForMode(RasterMode mode) const {
82 return !managed_state_.tile_versions[mode].IsReadyToDraw();
85 bool HasResources() const {
86 for (int mode = 0; mode < NUM_RASTER_MODES; ++mode) {
87 if (managed_state_.tile_versions[mode].has_resource())
93 scoped_ptr<base::Value> AsValue() const;
95 inline bool IsReadyToDraw() const {
96 for (int mode = 0; mode < NUM_RASTER_MODES; ++mode) {
97 if (managed_state_.tile_versions[mode].IsReadyToDraw())
103 const ManagedTileState::TileVersion& GetTileVersionForDrawing() const {
104 for (int mode = 0; mode < NUM_RASTER_MODES; ++mode) {
105 if (managed_state_.tile_versions[mode].IsReadyToDraw())
106 return managed_state_.tile_versions[mode];
108 return managed_state_.tile_versions[HIGH_QUALITY_RASTER_MODE];
111 gfx::Rect opaque_rect() const { return opaque_rect_; }
112 bool has_text(RasterMode mode) const {
113 return managed_state_.tile_versions[mode].has_text_;
116 float contents_scale() const { return contents_scale_; }
117 gfx::Rect content_rect() const { return content_rect_; }
119 int layer_id() const { return layer_id_; }
121 int source_frame_number() const { return source_frame_number_; }
123 void set_picture_pile(scoped_refptr<PicturePileImpl> pile) {
124 DCHECK(pile->CanRaster(contents_scale_, content_rect_));
125 picture_pile_ = pile;
128 size_t GPUMemoryUsageInBytes() const;
130 gfx::Size size() const { return tile_size_.size(); }
132 RasterMode DetermineRasterModeForTree(WhichTree tree) const;
133 RasterMode DetermineOverallRasterMode() const;
135 // Functionality used in tests.
136 RasterMode GetRasterModeForTesting() const {
137 return managed_state().raster_mode;
139 ManagedTileState::TileVersion& GetTileVersionForTesting(RasterMode mode) {
140 return managed_state_.tile_versions[mode];
144 friend class TileManager;
145 friend class PrioritizedTileSet;
146 friend class FakeTileManager;
147 friend class BinComparator;
148 friend class FakePictureLayerImpl;
150 // Methods called by by tile manager.
151 Tile(TileManager* tile_manager,
152 PicturePileImpl* picture_pile,
153 const gfx::Size& tile_size,
154 const gfx::Rect& content_rect,
155 const gfx::Rect& opaque_rect,
156 float contents_scale,
158 int source_frame_number,
162 ManagedTileState& managed_state() { return managed_state_; }
163 const ManagedTileState& managed_state() const { return managed_state_; }
164 RasterMode DetermineRasterModeForResolution(TileResolution resolution) const;
166 TileManager* tile_manager_;
167 scoped_refptr<PicturePileImpl> picture_pile_;
168 gfx::Rect tile_size_;
169 gfx::Rect content_rect_;
170 float contents_scale_;
171 gfx::Rect opaque_rect_;
173 TilePriority priority_[NUM_TREES];
174 ManagedTileState managed_state_;
176 int source_frame_number_;
180 static Id s_next_id_;
182 DISALLOW_COPY_AND_ASSIGN(Tile);
187 #endif // CC_RESOURCES_TILE_H_