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_TILES_TILE_H_
6 #define CC_TILES_TILE_H_
15 #include "base/memory/ref_counted.h"
16 #include "cc/paint/draw_image.h"
17 #include "cc/raster/tile_task.h"
18 #include "cc/tiles/tile_draw_info.h"
19 #include "ui/gfx/geometry/axis_transform2d.h"
20 #include "ui/gfx/geometry/rect.h"
21 #include "ui/gfx/geometry/size.h"
25 class PictureLayerTiling;
28 class CC_EXPORT Tile {
31 const PictureLayerTiling* tiling = nullptr;
32 int tiling_i_index = 0;
33 int tiling_j_index = 0;
34 gfx::Rect enclosing_layer_rect;
35 gfx::Rect content_rect;
36 gfx::AxisTransform2d raster_transform;
37 bool can_use_lcd_text = false;
40 enum TileRasterFlags { USE_PICTURE_ANALYSIS = 1 << 0, IS_OPAQUE = 1 << 1 };
44 Tile(const Tile&) = delete;
47 Tile& operator=(const Tile&) = delete;
53 // TODO(vmpstr): Move this to the iterators.
54 bool required_for_activation() const { return required_for_activation_; }
55 void set_required_for_activation(bool is_required) {
56 required_for_activation_ = is_required;
58 bool required_for_draw() const { return required_for_draw_; }
59 void set_required_for_draw(bool is_required) {
60 required_for_draw_ = is_required;
63 bool is_prepaint() const {
64 return !required_for_activation() && !required_for_draw();
67 bool use_picture_analysis() const {
68 return !!(flags_ & USE_PICTURE_ANALYSIS);
71 bool is_opaque() const { return !!(flags_ & IS_OPAQUE); }
73 void AsValueInto(base::trace_event::TracedValue* value) const;
75 const TileDrawInfo& draw_info() const { return draw_info_; }
76 TileDrawInfo& draw_info() { return draw_info_; }
78 float contents_scale_key() const {
79 const gfx::Vector2dF& scale = raster_transform_.scale();
80 return std::max(scale.x(), scale.y());
82 const gfx::AxisTransform2d& raster_transform() const {
83 return raster_transform_;
85 const gfx::Rect& content_rect() const { return content_rect_; }
86 const gfx::Rect& enclosing_layer_rect() const {
87 return enclosing_layer_rect_;
90 int layer_id() const { return layer_id_; }
92 int source_frame_number() const { return source_frame_number_; }
94 size_t GPUMemoryUsageInBytes() const;
96 const gfx::Size& desired_texture_size() const { return content_rect_.size(); }
98 int tiling_i_index() const { return tiling_i_index_; }
99 int tiling_j_index() const { return tiling_j_index_; }
101 void SetInvalidated(const gfx::Rect& invalid_content_rect,
102 Id previous_tile_id) {
103 invalidated_content_rect_ = invalid_content_rect;
104 invalidated_id_ = previous_tile_id;
107 Id invalidated_id() const { return invalidated_id_; }
108 const gfx::Rect& invalidated_content_rect() const {
109 return invalidated_content_rect_;
112 bool HasRasterTask() const { return !!raster_task_.get(); }
114 void set_solid_color_analysis_performed(bool performed) {
115 is_solid_color_analysis_performed_ = performed;
117 bool is_solid_color_analysis_performed() const {
118 return is_solid_color_analysis_performed_;
120 bool can_use_lcd_text() const { return can_use_lcd_text_; }
122 bool set_raster_task_scheduled_with_checker_images(bool has_checker_images) {
123 bool previous_value = raster_task_scheduled_with_checker_images_;
124 raster_task_scheduled_with_checker_images_ = has_checker_images;
125 return previous_value;
127 bool raster_task_scheduled_with_checker_images() const {
128 return raster_task_scheduled_with_checker_images_;
131 const PictureLayerTiling* tiling() const { return tiling_; }
132 void set_tiling(const PictureLayerTiling* tiling) { tiling_ = tiling; }
135 friend class TileManager;
136 friend class FakeTileManager;
137 friend class FakePictureLayerImpl;
139 // Methods called by by tile manager.
140 Tile(TileManager* tile_manager,
141 const CreateInfo& info,
143 int source_frame_number,
146 TileManager* const tile_manager_;
147 const PictureLayerTiling* tiling_;
148 const gfx::Rect content_rect_;
149 const gfx::Rect enclosing_layer_rect_;
150 const gfx::AxisTransform2d raster_transform_;
152 TileDrawInfo draw_info_;
155 const int source_frame_number_;
157 const int tiling_i_index_;
158 const int tiling_j_index_;
160 // The |id_| of the Tile that was invalidated and replaced by this tile.
161 Id invalidated_id_ = 0;
163 unsigned scheduled_priority_ = 0;
165 bool required_for_activation_ : 1;
166 bool required_for_draw_ : 1;
167 bool is_solid_color_analysis_performed_ : 1;
168 const bool can_use_lcd_text_ : 1;
170 // Set to true if there is a raster task scheduled for this tile that will
171 // rasterize a resource with checker images.
172 bool raster_task_scheduled_with_checker_images_ : 1;
176 // List of Rect-Transform pairs, representing unoccluded parts of the
177 // tile, to support raster culling. See Bug: 1071932
178 std::vector<std::pair<const gfx::Rect, const gfx::AxisTransform2d>>
181 // The rect bounding the changes in this Tile vs the previous tile it
183 gfx::Rect invalidated_content_rect_;
185 scoped_refptr<TileTask> raster_task_;
190 #endif // CC_TILES_TILE_H_