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_
11 #include "base/memory/ref_counted.h"
12 #include "cc/paint/draw_image.h"
13 #include "cc/raster/tile_task.h"
14 #include "cc/tiles/tile_draw_info.h"
15 #include "ui/gfx/geometry/axis_transform2d.h"
16 #include "ui/gfx/geometry/rect.h"
17 #include "ui/gfx/geometry/size.h"
21 class PictureLayerTiling;
24 class CC_EXPORT Tile {
26 class CC_EXPORT CreateInfo {
28 const PictureLayerTiling* tiling;
31 gfx::Rect enclosing_layer_rect;
32 gfx::Rect content_rect;
33 gfx::AxisTransform2d raster_transform;
35 CreateInfo(const PictureLayerTiling* tiling,
38 const gfx::Rect& enclosing_layer_rect,
39 const gfx::Rect& content_rect,
40 const gfx::AxisTransform2d& raster_transform)
42 tiling_i_index(tiling_i_index),
43 tiling_j_index(tiling_j_index),
44 enclosing_layer_rect(enclosing_layer_rect),
45 content_rect(content_rect),
46 raster_transform(raster_transform) {}
49 enum TileRasterFlags { USE_PICTURE_ANALYSIS = 1 << 0, IS_OPAQUE = 1 << 1 };
53 Tile(const Tile&) = delete;
56 Tile& operator=(const Tile&) = delete;
62 // TODO(vmpstr): Move this to the iterators.
63 bool required_for_activation() const { return required_for_activation_; }
64 void set_required_for_activation(bool is_required) {
65 required_for_activation_ = is_required;
67 bool required_for_draw() const { return required_for_draw_; }
68 void set_required_for_draw(bool is_required) {
69 required_for_draw_ = is_required;
72 bool is_prepaint() const {
73 return !required_for_activation() && !required_for_draw();
76 bool use_picture_analysis() const {
77 return !!(flags_ & USE_PICTURE_ANALYSIS);
80 bool is_opaque() const { return !!(flags_ & IS_OPAQUE); }
82 void AsValueInto(base::trace_event::TracedValue* value) const;
84 const TileDrawInfo& draw_info() const { return draw_info_; }
85 TileDrawInfo& draw_info() { return draw_info_; }
87 float contents_scale_key() const { return raster_transform_.scale(); }
88 const gfx::AxisTransform2d& raster_transform() const {
89 return raster_transform_;
91 const gfx::Rect& content_rect() const { return content_rect_; }
92 const gfx::Rect& enclosing_layer_rect() const {
93 return enclosing_layer_rect_;
96 int layer_id() const { return layer_id_; }
98 int source_frame_number() const { return source_frame_number_; }
100 size_t GPUMemoryUsageInBytes() const;
102 const gfx::Size& desired_texture_size() const { return content_rect_.size(); }
104 int tiling_i_index() const { return tiling_i_index_; }
105 int tiling_j_index() const { return tiling_j_index_; }
107 void SetInvalidated(const gfx::Rect& invalid_content_rect,
108 Id previous_tile_id) {
109 invalidated_content_rect_ = invalid_content_rect;
110 invalidated_id_ = previous_tile_id;
113 Id invalidated_id() const { return invalidated_id_; }
114 const gfx::Rect& invalidated_content_rect() const {
115 return invalidated_content_rect_;
118 bool HasRasterTask() const { return !!raster_task_.get(); }
120 void set_solid_color_analysis_performed(bool performed) {
121 is_solid_color_analysis_performed_ = performed;
123 bool is_solid_color_analysis_performed() const {
124 return is_solid_color_analysis_performed_;
126 bool can_use_lcd_text() const { return can_use_lcd_text_; }
128 bool set_raster_task_scheduled_with_checker_images(bool has_checker_images) {
129 bool previous_value = raster_task_scheduled_with_checker_images_;
130 raster_task_scheduled_with_checker_images_ = has_checker_images;
131 return previous_value;
133 bool raster_task_scheduled_with_checker_images() const {
134 return raster_task_scheduled_with_checker_images_;
137 const PictureLayerTiling* tiling() const { return tiling_; }
138 void set_tiling(const PictureLayerTiling* tiling) { tiling_ = tiling; }
141 friend class TileManager;
142 friend class FakeTileManager;
143 friend class FakePictureLayerImpl;
145 // Methods called by by tile manager.
146 Tile(TileManager* tile_manager,
147 const CreateInfo& info,
149 int source_frame_number,
151 bool can_use_lcd_text);
153 TileManager* const tile_manager_;
154 const PictureLayerTiling* tiling_;
155 const gfx::Rect content_rect_;
156 const gfx::Rect enclosing_layer_rect_;
157 const gfx::AxisTransform2d raster_transform_;
159 TileDrawInfo draw_info_;
162 const int source_frame_number_;
164 const int tiling_i_index_;
165 const int tiling_j_index_;
166 bool required_for_activation_ : 1;
167 bool required_for_draw_ : 1;
168 bool is_solid_color_analysis_performed_ : 1;
169 const bool can_use_lcd_text_ : 1;
173 // The rect bounding the changes in this Tile vs the previous tile it
175 gfx::Rect invalidated_content_rect_;
176 // The |id_| of the Tile that was invalidated and replaced by this tile.
179 unsigned scheduled_priority_;
181 // Set to true if there is a raster task scheduled for this tile that will
182 // rasterize a resource with checker images.
183 bool raster_task_scheduled_with_checker_images_ = false;
184 scoped_refptr<TileTask> raster_task_;
189 #endif // CC_TILES_TILE_H_