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/macros.h"
12 #include "base/memory/ref_counted.h"
13 #include "cc/paint/draw_image.h"
14 #include "cc/raster/tile_task.h"
15 #include "cc/tiles/tile_draw_info.h"
16 #include "ui/gfx/geometry/axis_transform2d.h"
17 #include "ui/gfx/geometry/rect.h"
18 #include "ui/gfx/geometry/size.h"
22 class PictureLayerTiling;
25 class CC_EXPORT Tile {
27 class CC_EXPORT CreateInfo {
29 const PictureLayerTiling* tiling;
32 gfx::Rect enclosing_layer_rect;
33 gfx::Rect content_rect;
34 gfx::AxisTransform2d raster_transform;
36 CreateInfo(const PictureLayerTiling* tiling,
39 const gfx::Rect& enclosing_layer_rect,
40 const gfx::Rect& content_rect,
41 const gfx::AxisTransform2d& raster_transform)
43 tiling_i_index(tiling_i_index),
44 tiling_j_index(tiling_j_index),
45 enclosing_layer_rect(enclosing_layer_rect),
46 content_rect(content_rect),
47 raster_transform(raster_transform) {}
50 enum TileRasterFlags { USE_PICTURE_ANALYSIS = 1 << 0, IS_OPAQUE = 1 << 1 };
60 // TODO(vmpstr): Move this to the iterators.
61 bool required_for_activation() const { return required_for_activation_; }
62 void set_required_for_activation(bool is_required) {
63 required_for_activation_ = is_required;
65 bool required_for_draw() const { return required_for_draw_; }
66 void set_required_for_draw(bool is_required) {
67 required_for_draw_ = is_required;
70 bool is_prepaint() const {
71 return !required_for_activation() && !required_for_draw();
74 bool use_picture_analysis() const {
75 return !!(flags_ & USE_PICTURE_ANALYSIS);
78 bool is_opaque() const { return !!(flags_ & IS_OPAQUE); }
80 void AsValueInto(base::trace_event::TracedValue* value) const;
82 const TileDrawInfo& draw_info() const { return draw_info_; }
83 TileDrawInfo& draw_info() { return draw_info_; }
85 float contents_scale_key() const { return raster_transform_.scale(); }
86 const gfx::AxisTransform2d& raster_transform() const {
87 return raster_transform_;
89 const gfx::Rect& content_rect() const { return content_rect_; }
90 const gfx::Rect& enclosing_layer_rect() const {
91 return enclosing_layer_rect_;
94 int layer_id() const { return layer_id_; }
96 int source_frame_number() const { return source_frame_number_; }
98 size_t GPUMemoryUsageInBytes() const;
100 const gfx::Size& desired_texture_size() const { return content_rect_.size(); }
102 int tiling_i_index() const { return tiling_i_index_; }
103 int tiling_j_index() const { return tiling_j_index_; }
105 void SetInvalidated(const gfx::Rect& invalid_content_rect,
106 Id previous_tile_id) {
107 invalidated_content_rect_ = invalid_content_rect;
108 invalidated_id_ = previous_tile_id;
111 Id invalidated_id() const { return invalidated_id_; }
112 const gfx::Rect& invalidated_content_rect() const {
113 return invalidated_content_rect_;
116 bool HasRasterTask() const { return !!raster_task_.get(); }
118 void set_solid_color_analysis_performed(bool performed) {
119 is_solid_color_analysis_performed_ = performed;
121 bool is_solid_color_analysis_performed() const {
122 return is_solid_color_analysis_performed_;
124 bool can_use_lcd_text() const { return can_use_lcd_text_; }
126 bool set_raster_task_scheduled_with_checker_images(bool has_checker_images) {
127 bool previous_value = raster_task_scheduled_with_checker_images_;
128 raster_task_scheduled_with_checker_images_ = has_checker_images;
129 return previous_value;
131 bool raster_task_scheduled_with_checker_images() const {
132 return raster_task_scheduled_with_checker_images_;
135 const PictureLayerTiling* tiling() const { return tiling_; }
136 void set_tiling(const PictureLayerTiling* tiling) { tiling_ = tiling; }
139 friend class TileManager;
140 friend class FakeTileManager;
141 friend class FakePictureLayerImpl;
143 // Methods called by by tile manager.
144 Tile(TileManager* tile_manager,
145 const CreateInfo& info,
147 int source_frame_number,
149 bool can_use_lcd_text);
151 TileManager* const tile_manager_;
152 const PictureLayerTiling* tiling_;
153 const gfx::Rect content_rect_;
154 const gfx::Rect enclosing_layer_rect_;
155 const gfx::AxisTransform2d raster_transform_;
157 TileDrawInfo draw_info_;
160 const int source_frame_number_;
162 const int tiling_i_index_;
163 const int tiling_j_index_;
164 bool required_for_activation_ : 1;
165 bool required_for_draw_ : 1;
166 bool is_solid_color_analysis_performed_ : 1;
167 const bool can_use_lcd_text_ : 1;
171 // The rect bounding the changes in this Tile vs the previous tile it
173 gfx::Rect invalidated_content_rect_;
174 // The |id_| of the Tile that was invalidated and replaced by this tile.
177 unsigned scheduled_priority_;
179 // Set to true if there is a raster task scheduled for this tile that will
180 // rasterize a resource with checker images.
181 bool raster_task_scheduled_with_checker_images_ = false;
182 scoped_refptr<TileTask> raster_task_;
184 DISALLOW_COPY_AND_ASSIGN(Tile);
189 #endif // CC_TILES_TILE_H_