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/resources/managed_tile_state.h"
12 #include "cc/resources/raster_mode.h"
13 #include "cc/resources/tile_priority.h"
14 #include "ui/gfx/rect.h"
15 #include "ui/gfx/size.h"
19 class PicturePileImpl
;
21 class CC_EXPORT Tile
: public base::RefCounted
<Tile
> {
25 Tile(TileManager
* tile_manager
,
26 PicturePileImpl
* picture_pile
,
28 gfx::Rect content_rect
,
29 gfx::Rect opaque_rect
,
32 int source_frame_number
,
33 bool can_use_lcd_text
);
39 PicturePileImpl
* picture_pile() {
40 return picture_pile_
.get();
43 const PicturePileImpl
* picture_pile() const {
44 return picture_pile_
.get();
47 const TilePriority
& priority(WhichTree tree
) const {
48 return priority_
[tree
];
51 TilePriority
combined_priority() const {
52 return TilePriority(priority_
[ACTIVE_TREE
],
53 priority_
[PENDING_TREE
]);
56 void SetPriority(WhichTree tree
, const TilePriority
& priority
);
58 void MarkRequiredForActivation();
60 bool required_for_activation() const {
61 return priority_
[PENDING_TREE
].required_for_activation
;
64 void set_can_use_lcd_text(bool can_use_lcd_text
) {
65 can_use_lcd_text_
= can_use_lcd_text
;
68 bool can_use_lcd_text() const {
69 return can_use_lcd_text_
;
72 scoped_ptr
<base::Value
> AsValue() const;
74 inline bool IsReadyToDraw() const {
75 for (int mode
= 0; mode
< NUM_RASTER_MODES
; ++mode
) {
76 if (managed_state_
.tile_versions
[mode
].IsReadyToDraw())
82 const ManagedTileState::TileVersion
& GetTileVersionForDrawing() const {
83 for (int mode
= 0; mode
< NUM_RASTER_MODES
; ++mode
) {
84 if (managed_state_
.tile_versions
[mode
].IsReadyToDraw())
85 return managed_state_
.tile_versions
[mode
];
87 return managed_state_
.tile_versions
[HIGH_QUALITY_RASTER_MODE
];
90 gfx::Rect
opaque_rect() const { return opaque_rect_
; }
91 bool has_text(RasterMode mode
) const {
92 return managed_state_
.tile_versions
[mode
].has_text_
;
95 float contents_scale() const { return contents_scale_
; }
96 gfx::Rect
content_rect() const { return content_rect_
; }
98 int layer_id() const { return layer_id_
; }
100 int source_frame_number() const { return source_frame_number_
; }
102 void set_picture_pile(scoped_refptr
<PicturePileImpl
> pile
) {
103 DCHECK(pile
->CanRaster(contents_scale_
, content_rect_
));
104 picture_pile_
= pile
;
107 size_t GPUMemoryUsageInBytes() const;
109 RasterMode
GetRasterModeForTesting() const {
110 return managed_state().raster_mode
;
112 ManagedTileState::TileVersion
& GetTileVersionForTesting(RasterMode mode
) {
113 return managed_state_
.tile_versions
[mode
];
117 // Methods called by by tile manager.
118 friend class TileManager
;
119 friend class PrioritizedTileSet
;
120 friend class FakeTileManager
;
121 friend class BinComparator
;
122 ManagedTileState
& managed_state() { return managed_state_
; }
123 const ManagedTileState
& managed_state() const { return managed_state_
; }
125 inline size_t bytes_consumed_if_allocated() const {
126 return 4 * tile_size_
.width() * tile_size_
.height();
129 // Normal private methods.
130 friend class base::RefCounted
<Tile
>;
133 TileManager
* tile_manager_
;
134 scoped_refptr
<PicturePileImpl
> picture_pile_
;
135 gfx::Rect tile_size_
;
136 gfx::Rect content_rect_
;
137 float contents_scale_
;
138 gfx::Rect opaque_rect_
;
140 TilePriority priority_
[NUM_TREES
];
141 ManagedTileState managed_state_
;
143 int source_frame_number_
;
144 bool can_use_lcd_text_
;
147 static Id s_next_id_
;
149 DISALLOW_COPY_AND_ASSIGN(Tile
);
154 #endif // CC_RESOURCES_TILE_H_