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/raster_mode.h"
14 #include "cc/resources/tile_priority.h"
15 #include "ui/gfx/rect.h"
16 #include "ui/gfx/size.h"
20 class PicturePileImpl
;
22 class CC_EXPORT Tile
: public RefCountedManaged
<Tile
> {
24 enum TileRasterFlags
{
25 USE_LCD_TEXT
= 1 << 0,
26 USE_GPU_RASTERIZATION
= 1 << 1
35 PicturePileImpl
* picture_pile() {
36 return picture_pile_
.get();
39 const PicturePileImpl
* picture_pile() const {
40 return picture_pile_
.get();
43 const TilePriority
& priority(WhichTree tree
) const {
44 return priority_
[tree
];
47 TilePriority
combined_priority() const {
48 return TilePriority(priority_
[ACTIVE_TREE
],
49 priority_
[PENDING_TREE
]);
52 void SetPriority(WhichTree tree
, const TilePriority
& priority
);
54 void MarkRequiredForActivation();
56 bool required_for_activation() const {
57 return priority_
[PENDING_TREE
].required_for_activation
;
60 void set_can_use_lcd_text(bool can_use_lcd_text
) {
62 flags_
|= USE_LCD_TEXT
;
64 flags_
&= ~USE_LCD_TEXT
;
67 bool can_use_lcd_text() const {
68 return !!(flags_
& USE_LCD_TEXT
);
71 void set_use_gpu_rasterization(bool use_gpu_rasterization
) {
72 if (use_gpu_rasterization
)
73 flags_
|= USE_GPU_RASTERIZATION
;
75 flags_
&= ~USE_GPU_RASTERIZATION
;
78 bool use_gpu_rasterization() const {
79 return !!(flags_
& USE_GPU_RASTERIZATION
);
82 scoped_ptr
<base::Value
> AsValue() const;
84 inline bool IsReadyToDraw() const {
85 for (int mode
= 0; mode
< NUM_RASTER_MODES
; ++mode
) {
86 if (managed_state_
.tile_versions
[mode
].IsReadyToDraw())
92 const ManagedTileState::TileVersion
& GetTileVersionForDrawing() const {
93 for (int mode
= 0; mode
< NUM_RASTER_MODES
; ++mode
) {
94 if (managed_state_
.tile_versions
[mode
].IsReadyToDraw())
95 return managed_state_
.tile_versions
[mode
];
97 return managed_state_
.tile_versions
[HIGH_QUALITY_RASTER_MODE
];
100 gfx::Rect
opaque_rect() const { return opaque_rect_
; }
101 bool has_text(RasterMode mode
) const {
102 return managed_state_
.tile_versions
[mode
].has_text_
;
105 float contents_scale() const { return contents_scale_
; }
106 gfx::Rect
content_rect() const { return content_rect_
; }
108 int layer_id() const { return layer_id_
; }
110 int source_frame_number() const { return source_frame_number_
; }
112 void set_picture_pile(scoped_refptr
<PicturePileImpl
> pile
) {
113 DCHECK(pile
->CanRaster(contents_scale_
, content_rect_
));
114 picture_pile_
= pile
;
117 size_t GPUMemoryUsageInBytes() const;
119 RasterMode
GetRasterModeForTesting() const {
120 return managed_state().raster_mode
;
122 ManagedTileState::TileVersion
& GetTileVersionForTesting(RasterMode mode
) {
123 return managed_state_
.tile_versions
[mode
];
126 gfx::Size
size() const { return tile_size_
.size(); }
129 friend class TileManager
;
130 friend class PrioritizedTileSet
;
131 friend class FakeTileManager
;
132 friend class BinComparator
;
133 friend class FakePictureLayerImpl
;
135 // Methods called by by tile manager.
136 Tile(TileManager
* tile_manager
,
137 PicturePileImpl
* picture_pile
,
138 const gfx::Size
& tile_size
,
139 const gfx::Rect
& content_rect
,
140 const gfx::Rect
& opaque_rect
,
141 float contents_scale
,
143 int source_frame_number
,
147 ManagedTileState
& managed_state() { return managed_state_
; }
148 const ManagedTileState
& managed_state() const { return managed_state_
; }
150 TileManager
* tile_manager_
;
151 scoped_refptr
<PicturePileImpl
> picture_pile_
;
152 gfx::Rect tile_size_
;
153 gfx::Rect content_rect_
;
154 float contents_scale_
;
155 gfx::Rect opaque_rect_
;
157 TilePriority priority_
[NUM_TREES
];
158 ManagedTileState managed_state_
;
160 int source_frame_number_
;
164 static Id s_next_id_
;
166 DISALLOW_COPY_AND_ASSIGN(Tile
);
171 #endif // CC_RESOURCES_TILE_H_