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
{ USE_LCD_TEXT
= 1 << 0, USE_PICTURE_ANALYSIS
= 1 << 1 };
31 PicturePileImpl
* picture_pile() {
32 return picture_pile_
.get();
35 const PicturePileImpl
* picture_pile() const {
36 return picture_pile_
.get();
39 const TilePriority
& priority(WhichTree tree
) const {
40 return priority_
[tree
];
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();
53 return TilePriority();
56 TilePriority
combined_priority() const {
57 return TilePriority(priority_
[ACTIVE_TREE
],
58 priority_
[PENDING_TREE
]);
61 void SetPriority(WhichTree tree
, const TilePriority
& priority
);
63 void MarkRequiredForActivation();
65 bool required_for_activation() const {
66 return priority_
[PENDING_TREE
].required_for_activation
;
69 void set_can_use_lcd_text(bool can_use_lcd_text
) {
71 flags_
|= USE_LCD_TEXT
;
73 flags_
&= ~USE_LCD_TEXT
;
76 bool can_use_lcd_text() const {
77 return !!(flags_
& USE_LCD_TEXT
);
80 bool use_picture_analysis() const {
81 return !!(flags_
& USE_PICTURE_ANALYSIS
);
84 bool NeedsRasterForMode(RasterMode mode
) const {
85 return !managed_state_
.tile_versions
[mode
].IsReadyToDraw();
88 bool HasResources() const {
89 for (int mode
= 0; mode
< NUM_RASTER_MODES
; ++mode
) {
90 if (managed_state_
.tile_versions
[mode
].has_resource())
96 scoped_ptr
<base::Value
> AsValue() const;
98 inline bool IsReadyToDraw() const {
99 for (int mode
= 0; mode
< NUM_RASTER_MODES
; ++mode
) {
100 if (managed_state_
.tile_versions
[mode
].IsReadyToDraw())
106 const ManagedTileState::TileVersion
& GetTileVersionForDrawing() const {
107 for (int mode
= 0; mode
< NUM_RASTER_MODES
; ++mode
) {
108 if (managed_state_
.tile_versions
[mode
].IsReadyToDraw())
109 return managed_state_
.tile_versions
[mode
];
111 return managed_state_
.tile_versions
[HIGH_QUALITY_RASTER_MODE
];
114 gfx::Rect
opaque_rect() const { return opaque_rect_
; }
115 bool has_text(RasterMode mode
) const {
116 return managed_state_
.tile_versions
[mode
].has_text_
;
119 float contents_scale() const { return contents_scale_
; }
120 gfx::Rect
content_rect() const { return content_rect_
; }
122 int layer_id() const { return layer_id_
; }
124 int source_frame_number() const { return source_frame_number_
; }
126 void set_picture_pile(scoped_refptr
<PicturePileImpl
> pile
) {
127 DCHECK(pile
->CanRaster(contents_scale_
, content_rect_
));
128 picture_pile_
= pile
;
131 size_t GPUMemoryUsageInBytes() const;
133 gfx::Size
size() const { return tile_size_
.size(); }
135 RasterMode
DetermineRasterModeForTree(WhichTree tree
) const;
136 RasterMode
DetermineOverallRasterMode() const;
138 // Functionality used in tests.
139 RasterMode
GetRasterModeForTesting() const {
140 return managed_state().raster_mode
;
142 ManagedTileState::TileVersion
& GetTileVersionForTesting(RasterMode mode
) {
143 return managed_state_
.tile_versions
[mode
];
147 friend class TileManager
;
148 friend class PrioritizedTileSet
;
149 friend class FakeTileManager
;
150 friend class BinComparator
;
151 friend class FakePictureLayerImpl
;
153 // Methods called by by tile manager.
154 Tile(TileManager
* tile_manager
,
155 PicturePileImpl
* picture_pile
,
156 const gfx::Size
& tile_size
,
157 const gfx::Rect
& content_rect
,
158 const gfx::Rect
& opaque_rect
,
159 float contents_scale
,
161 int source_frame_number
,
165 ManagedTileState
& managed_state() { return managed_state_
; }
166 const ManagedTileState
& managed_state() const { return managed_state_
; }
167 RasterMode
DetermineRasterModeForResolution(TileResolution resolution
) const;
169 TileManager
* tile_manager_
;
170 scoped_refptr
<PicturePileImpl
> picture_pile_
;
171 gfx::Rect tile_size_
;
172 gfx::Rect content_rect_
;
173 float contents_scale_
;
174 gfx::Rect opaque_rect_
;
176 TilePriority priority_
[NUM_TREES
];
177 ManagedTileState managed_state_
;
179 int source_frame_number_
;
183 static Id s_next_id_
;
185 DISALLOW_COPY_AND_ASSIGN(Tile
);
190 #endif // CC_RESOURCES_TILE_H_