1 // Copyright 2012 The Chromium Authors
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/raw_ptr.h"
16 #include "base/memory/ref_counted.h"
17 #include "cc/paint/draw_image.h"
18 #include "cc/raster/tile_task.h"
19 #include "cc/tiles/tile_draw_info.h"
20 #include "ui/gfx/geometry/axis_transform2d.h"
21 #include "ui/gfx/geometry/rect.h"
22 #include "ui/gfx/geometry/size.h"
26 class PictureLayerTiling;
29 class CC_EXPORT Tile {
32 raw_ptr<const PictureLayerTiling> tiling = nullptr;
33 int tiling_i_index = 0;
34 int tiling_j_index = 0;
35 gfx::Rect enclosing_layer_rect;
36 gfx::Rect content_rect;
37 gfx::AxisTransform2d raster_transform;
38 bool can_use_lcd_text = false;
41 enum TileRasterFlags { USE_PICTURE_ANALYSIS = 1 << 0, IS_OPAQUE = 1 << 1 };
45 Tile(const Tile&) = delete;
48 Tile& operator=(const Tile&) = delete;
54 // TODO(vmpstr): Move this to the iterators.
55 bool required_for_activation() const { return required_for_activation_; }
56 void set_required_for_activation(bool is_required) {
57 required_for_activation_ = is_required;
59 bool required_for_draw() const { return required_for_draw_; }
60 void set_required_for_draw(bool is_required) {
61 required_for_draw_ = is_required;
64 bool is_prepaint() const {
65 return !required_for_activation() && !required_for_draw();
68 bool use_picture_analysis() const {
69 return !!(flags_ & USE_PICTURE_ANALYSIS);
72 bool is_opaque() const { return !!(flags_ & IS_OPAQUE); }
74 void AsValueInto(base::trace_event::TracedValue* value) const;
76 const TileDrawInfo& draw_info() const { return draw_info_; }
77 TileDrawInfo& draw_info() { return draw_info_; }
79 float contents_scale_key() const {
80 const gfx::Vector2dF& scale = raster_transform_.scale();
81 return std::max(scale.x(), scale.y());
83 const gfx::AxisTransform2d& raster_transform() const {
84 return raster_transform_;
86 const gfx::Rect& content_rect() const { return content_rect_; }
87 const gfx::Rect& enclosing_layer_rect() const {
88 return enclosing_layer_rect_;
91 int layer_id() const { return layer_id_; }
93 int source_frame_number() const { return source_frame_number_; }
95 size_t GPUMemoryUsageInBytes() const;
97 const gfx::Size& desired_texture_size() const { return content_rect_.size(); }
99 int tiling_i_index() const { return tiling_i_index_; }
100 int tiling_j_index() const { return tiling_j_index_; }
102 void SetInvalidated(const gfx::Rect& invalid_content_rect,
103 Id previous_tile_id) {
104 invalidated_content_rect_ = invalid_content_rect;
105 invalidated_id_ = previous_tile_id;
108 Id invalidated_id() const { return invalidated_id_; }
109 const gfx::Rect& invalidated_content_rect() const {
110 return invalidated_content_rect_;
113 bool HasRasterTask() const { return !!raster_task_.get(); }
115 bool HasMissingLCPCandidateImages() const;
117 void set_solid_color_analysis_performed(bool performed) {
118 is_solid_color_analysis_performed_ = performed;
120 bool is_solid_color_analysis_performed() const {
121 return is_solid_color_analysis_performed_;
123 bool can_use_lcd_text() const { return can_use_lcd_text_; }
125 bool set_raster_task_scheduled_with_checker_images(bool has_checker_images) {
126 bool previous_value = raster_task_scheduled_with_checker_images_;
127 raster_task_scheduled_with_checker_images_ = has_checker_images;
128 return previous_value;
130 bool raster_task_scheduled_with_checker_images() const {
131 return raster_task_scheduled_with_checker_images_;
134 const PictureLayerTiling* tiling() const { return tiling_; }
135 void set_tiling(const PictureLayerTiling* tiling) { tiling_ = tiling; }
138 friend class TileManager;
139 friend class FakeTileManager;
140 friend class FakePictureLayerImpl;
142 // Methods called by by tile manager.
143 Tile(TileManager* tile_manager,
144 const CreateInfo& info,
146 int source_frame_number,
149 const raw_ptr<TileManager> tile_manager_;
150 raw_ptr<const PictureLayerTiling> tiling_;
151 const gfx::Rect content_rect_;
152 const gfx::Rect enclosing_layer_rect_;
153 const gfx::AxisTransform2d raster_transform_;
155 TileDrawInfo draw_info_;
158 const int source_frame_number_;
160 const int tiling_i_index_;
161 const int tiling_j_index_;
163 // The |id_| of the Tile that was invalidated and replaced by this tile.
164 Id invalidated_id_ = 0;
166 unsigned scheduled_priority_ = 0;
168 bool required_for_activation_ : 1;
169 bool required_for_draw_ : 1;
170 bool is_solid_color_analysis_performed_ : 1;
171 const bool can_use_lcd_text_ : 1;
173 // Set to true if there is a raster task scheduled for this tile that will
174 // rasterize a resource with checker images.
175 bool raster_task_scheduled_with_checker_images_ : 1;
179 // List of Rect-Transform pairs, representing unoccluded parts of the
180 // tile, to support raster culling. See Bug: 1071932
181 std::vector<std::pair<const gfx::Rect, const gfx::AxisTransform2d>>
184 // The rect bounding the changes in this Tile vs the previous tile it
186 gfx::Rect invalidated_content_rect_;
188 scoped_refptr<TileTask> raster_task_;
193 #endif // CC_TILES_TILE_H_