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/raster_source.h"
11 #include "cc/resources/tile_draw_info.h"
12 #include "cc/resources/tile_priority.h"
13 #include "ui/gfx/geometry/rect.h"
14 #include "ui/gfx/geometry/size.h"
20 class CC_EXPORT Tile
: public RefCountedManaged
<Tile
> {
22 enum TileRasterFlags
{ USE_PICTURE_ANALYSIS
= 1 << 0 };
30 RasterSource
* raster_source() { return raster_source_
.get(); }
32 const RasterSource
* raster_source() const { return raster_source_
.get(); }
34 const TilePriority
& priority(WhichTree tree
) const {
35 return priority_
[tree
];
38 TilePriority
priority_for_tree_priority(TreePriority tree_priority
) const {
39 switch (tree_priority
) {
40 case SMOOTHNESS_TAKES_PRIORITY
:
41 return priority_
[ACTIVE_TREE
];
42 case NEW_CONTENT_TAKES_PRIORITY
:
43 return priority_
[PENDING_TREE
];
44 case SAME_PRIORITY_FOR_BOTH_TREES
:
45 return combined_priority();
48 return TilePriority();
52 TilePriority
combined_priority() const {
53 return TilePriority(priority_
[ACTIVE_TREE
],
54 priority_
[PENDING_TREE
]);
57 void SetPriority(WhichTree tree
, const TilePriority
& priority
) {
58 priority_
[tree
] = priority
;
61 // TODO(vmpstr): Move this to the iterators.
62 void set_is_occluded(WhichTree tree
, bool is_occluded
) {
63 is_occluded_
[tree
] = is_occluded
;
66 bool is_occluded(WhichTree tree
) const { return is_occluded_
[tree
]; }
68 void set_shared(bool is_shared
) { is_shared_
= is_shared
; }
69 bool is_shared() const { return is_shared_
; }
71 bool is_occluded_combined() const {
72 return is_occluded_
[ACTIVE_TREE
] && is_occluded_
[PENDING_TREE
];
75 // TODO(vmpstr): Move this to the iterators.
76 bool required_for_activation() const { return required_for_activation_
; }
77 void set_required_for_activation(bool is_required
) {
78 required_for_activation_
= is_required
;
80 bool required_for_draw() const { return required_for_draw_
; }
81 void set_required_for_draw(bool is_required
) {
82 required_for_draw_
= is_required
;
85 bool use_picture_analysis() const {
86 return !!(flags_
& USE_PICTURE_ANALYSIS
);
89 bool HasResource() const { return draw_info_
.has_resource(); }
90 bool NeedsRaster() const {
91 return draw_info_
.mode() == TileDrawInfo::OOM_MODE
||
92 !draw_info_
.IsReadyToDraw();
95 void AsValueInto(base::trace_event::TracedValue
* dict
) const;
97 inline bool IsReadyToDraw() const { return draw_info_
.IsReadyToDraw(); }
99 const TileDrawInfo
& draw_info() const { return draw_info_
; }
101 TileDrawInfo
& draw_info() { return draw_info_
; }
103 float contents_scale() const { return contents_scale_
; }
104 gfx::Rect
content_rect() const { return content_rect_
; }
106 int layer_id() const { return layer_id_
; }
108 int source_frame_number() const { return source_frame_number_
; }
110 void set_raster_source(scoped_refptr
<RasterSource
> raster_source
) {
111 DCHECK(raster_source
->CoversRect(content_rect_
, contents_scale_
))
112 << "Recording rect: "
113 << gfx::ScaleToEnclosingRect(content_rect_
, 1.f
/ contents_scale_
)
115 raster_source_
= raster_source
;
118 size_t GPUMemoryUsageInBytes() const;
120 gfx::Size
desired_texture_size() const { return desired_texture_size_
; }
122 void set_tiling_index(int i
, int j
) {
126 int tiling_i_index() const { return tiling_i_index_
; }
127 int tiling_j_index() const { return tiling_j_index_
; }
130 friend class TileManager
;
131 friend class PrioritizedTileSet
;
132 friend class FakeTileManager
;
133 friend class BinComparator
;
134 friend class FakePictureLayerImpl
;
136 // Methods called by by tile manager.
137 Tile(TileManager
* tile_manager
,
138 RasterSource
* raster_source
,
139 const gfx::Size
& desired_texture_size
,
140 const gfx::Rect
& content_rect
,
141 float contents_scale
,
143 int source_frame_number
,
147 bool HasRasterTask() const { return !!raster_task_
.get(); }
149 scoped_refptr
<RasterSource
> raster_source_
;
150 gfx::Size desired_texture_size_
;
151 gfx::Rect content_rect_
;
152 float contents_scale_
;
153 bool is_occluded_
[LAST_TREE
+ 1];
155 TilePriority priority_
[LAST_TREE
+ 1];
156 TileDrawInfo draw_info_
;
159 int source_frame_number_
;
164 bool required_for_activation_
: 1;
165 bool required_for_draw_
: 1;
168 static Id s_next_id_
;
170 unsigned scheduled_priority_
;
172 scoped_refptr
<RasterTask
> raster_task_
;
174 DISALLOW_COPY_AND_ASSIGN(Tile
);
179 #endif // CC_RESOURCES_TILE_H_