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 "cc/base/ref_counted_managed.h"
10 #include "cc/resources/managed_tile_state.h"
11 #include "cc/resources/raster_source.h"
12 #include "cc/resources/tile_priority.h"
13 #include "ui/gfx/geometry/rect.h"
14 #include "ui/gfx/geometry/size.h"
18 class CC_EXPORT Tile
: public RefCountedManaged
<Tile
> {
20 enum TileRasterFlags
{ USE_PICTURE_ANALYSIS
= 1 << 0 };
28 RasterSource
* raster_source() { return raster_source_
.get(); }
30 const RasterSource
* raster_source() const { return raster_source_
.get(); }
32 const TilePriority
& priority(WhichTree tree
) const {
33 return priority_
[tree
];
36 TilePriority
priority_for_tree_priority(TreePriority tree_priority
) const {
37 switch (tree_priority
) {
38 case SMOOTHNESS_TAKES_PRIORITY
:
39 return priority_
[ACTIVE_TREE
];
40 case NEW_CONTENT_TAKES_PRIORITY
:
41 return priority_
[PENDING_TREE
];
42 case SAME_PRIORITY_FOR_BOTH_TREES
:
43 return combined_priority();
46 return TilePriority();
50 TilePriority
combined_priority() const {
51 return TilePriority(priority_
[ACTIVE_TREE
],
52 priority_
[PENDING_TREE
]);
55 void SetPriority(WhichTree tree
, const TilePriority
& priority
) {
56 priority_
[tree
] = priority
;
59 // TODO(vmpstr): Move this to the iterators.
60 void set_is_occluded(WhichTree tree
, bool is_occluded
) {
61 is_occluded_
[tree
] = is_occluded
;
64 bool is_occluded(WhichTree tree
) const { return is_occluded_
[tree
]; }
66 void set_shared(bool is_shared
) { is_shared_
= is_shared
; }
67 bool is_shared() const { return is_shared_
; }
69 bool is_occluded_for_tree_priority(TreePriority tree_priority
) const {
70 switch (tree_priority
) {
71 case SMOOTHNESS_TAKES_PRIORITY
:
72 return is_occluded_
[ACTIVE_TREE
];
73 case NEW_CONTENT_TAKES_PRIORITY
:
74 return is_occluded_
[PENDING_TREE
];
75 case SAME_PRIORITY_FOR_BOTH_TREES
:
76 return is_occluded_
[ACTIVE_TREE
] && is_occluded_
[PENDING_TREE
];
83 // TODO(vmpstr): Move this to the iterators.
84 bool required_for_activation() const { return required_for_activation_
; }
85 void set_required_for_activation(bool is_required
) {
86 required_for_activation_
= is_required
;
88 bool required_for_draw() const { return required_for_draw_
; }
89 void set_required_for_draw(bool is_required
) {
90 required_for_draw_
= is_required
;
93 bool use_picture_analysis() const {
94 return !!(flags_
& USE_PICTURE_ANALYSIS
);
97 bool HasResources() const { return managed_state_
.draw_info
.has_resource(); }
98 bool NeedsRaster() const {
99 return managed_state_
.draw_info
.mode() ==
100 ManagedTileState::DrawInfo::PICTURE_PILE_MODE
||
101 !managed_state_
.draw_info
.IsReadyToDraw();
104 void AsValueInto(base::debug::TracedValue
* dict
) const;
106 inline bool IsReadyToDraw() const {
107 return managed_state_
.draw_info
.IsReadyToDraw();
110 const ManagedTileState::DrawInfo
& draw_info() const {
111 return managed_state_
.draw_info
;
114 ManagedTileState::DrawInfo
& draw_info() { return managed_state_
.draw_info
; }
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_raster_source(scoped_refptr
<RasterSource
> raster_source
) {
124 DCHECK(raster_source
->CoversRect(content_rect_
, contents_scale_
))
125 << "Recording rect: "
126 << gfx::ScaleToEnclosingRect(content_rect_
, 1.f
/ contents_scale_
)
128 raster_source_
= raster_source
;
131 size_t GPUMemoryUsageInBytes() const;
133 gfx::Size
size() const { return size_
; }
135 void set_tiling_index(int i
, int j
) {
139 int tiling_i_index() const { return tiling_i_index_
; }
140 int tiling_j_index() const { return tiling_j_index_
; }
143 friend class TileManager
;
144 friend class PrioritizedTileSet
;
145 friend class FakeTileManager
;
146 friend class BinComparator
;
147 friend class FakePictureLayerImpl
;
149 // Methods called by by tile manager.
150 Tile(TileManager
* tile_manager
,
151 RasterSource
* raster_source
,
152 const gfx::Size
& tile_size
,
153 const gfx::Rect
& content_rect
,
154 float contents_scale
,
156 int source_frame_number
,
160 ManagedTileState
& managed_state() { return managed_state_
; }
161 const ManagedTileState
& managed_state() const { return managed_state_
; }
163 bool HasRasterTask() const;
165 TileManager
* tile_manager_
;
166 scoped_refptr
<RasterSource
> raster_source_
;
168 gfx::Rect content_rect_
;
169 float contents_scale_
;
170 bool is_occluded_
[NUM_TREES
];
172 TilePriority priority_
[NUM_TREES
];
173 ManagedTileState managed_state_
;
175 int source_frame_number_
;
180 bool required_for_activation_
;
181 bool required_for_draw_
;
184 static Id s_next_id_
;
186 DISALLOW_COPY_AND_ASSIGN(Tile
);
191 #endif // CC_RESOURCES_TILE_H_