Upload upstream chromium 94.0.4606.31
[platform/framework/web/chromium-efl.git] / cc / tiles / tile.h
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.
4
5 #ifndef CC_TILES_TILE_H_
6 #define CC_TILES_TILE_H_
7
8 #include <stddef.h>
9 #include <stdint.h>
10
11 #include <algorithm>
12 #include <utility>
13 #include <vector>
14
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"
22
23 namespace cc {
24
25 class PictureLayerTiling;
26 class TileManager;
27
28 class CC_EXPORT Tile {
29  public:
30   struct CreateInfo {
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;
38   };
39
40   enum TileRasterFlags { USE_PICTURE_ANALYSIS = 1 << 0, IS_OPAQUE = 1 << 1 };
41
42   typedef uint64_t Id;
43
44   Tile(const Tile&) = delete;
45   ~Tile();
46
47   Tile& operator=(const Tile&) = delete;
48
49   Id id() const {
50     return id_;
51   }
52
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;
57   }
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;
61   }
62
63   bool is_prepaint() const {
64     return !required_for_activation() && !required_for_draw();
65   }
66
67   bool use_picture_analysis() const {
68     return !!(flags_ & USE_PICTURE_ANALYSIS);
69   }
70
71   bool is_opaque() const { return !!(flags_ & IS_OPAQUE); }
72
73   void AsValueInto(base::trace_event::TracedValue* value) const;
74
75   const TileDrawInfo& draw_info() const { return draw_info_; }
76   TileDrawInfo& draw_info() { return draw_info_; }
77
78   float contents_scale_key() const {
79     const gfx::Vector2dF& scale = raster_transform_.scale();
80     return std::max(scale.x(), scale.y());
81   }
82   const gfx::AxisTransform2d& raster_transform() const {
83     return raster_transform_;
84   }
85   const gfx::Rect& content_rect() const { return content_rect_; }
86   const gfx::Rect& enclosing_layer_rect() const {
87     return enclosing_layer_rect_;
88   }
89
90   int layer_id() const { return layer_id_; }
91
92   int source_frame_number() const { return source_frame_number_; }
93
94   size_t GPUMemoryUsageInBytes() const;
95
96   const gfx::Size& desired_texture_size() const { return content_rect_.size(); }
97
98   int tiling_i_index() const { return tiling_i_index_; }
99   int tiling_j_index() const { return tiling_j_index_; }
100
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;
105   }
106
107   Id invalidated_id() const { return invalidated_id_; }
108   const gfx::Rect& invalidated_content_rect() const {
109     return invalidated_content_rect_;
110   }
111
112   bool HasRasterTask() const { return !!raster_task_.get(); }
113
114   void set_solid_color_analysis_performed(bool performed) {
115     is_solid_color_analysis_performed_ = performed;
116   }
117   bool is_solid_color_analysis_performed() const {
118     return is_solid_color_analysis_performed_;
119   }
120   bool can_use_lcd_text() const { return can_use_lcd_text_; }
121
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;
126   }
127   bool raster_task_scheduled_with_checker_images() const {
128     return raster_task_scheduled_with_checker_images_;
129   }
130
131   const PictureLayerTiling* tiling() const { return tiling_; }
132   void set_tiling(const PictureLayerTiling* tiling) { tiling_ = tiling; }
133
134  private:
135   friend class TileManager;
136   friend class FakeTileManager;
137   friend class FakePictureLayerImpl;
138
139   // Methods called by by tile manager.
140   Tile(TileManager* tile_manager,
141        const CreateInfo& info,
142        int layer_id,
143        int source_frame_number,
144        int flags);
145
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_;
151
152   TileDrawInfo draw_info_;
153
154   const int layer_id_;
155   const int source_frame_number_;
156   const int flags_;
157   const int tiling_i_index_;
158   const int tiling_j_index_;
159
160   // The |id_| of the Tile that was invalidated and replaced by this tile.
161   Id invalidated_id_ = 0;
162
163   unsigned scheduled_priority_ = 0;
164
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;
169
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;
173
174   Id id_;
175
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>>
179       raster_rects_;
180
181   // The rect bounding the changes in this Tile vs the previous tile it
182   // replaced.
183   gfx::Rect invalidated_content_rect_;
184
185   scoped_refptr<TileTask> raster_task_;
186 };
187
188 }  // namespace cc
189
190 #endif  // CC_TILES_TILE_H_