[M108 Migration][VD] Avoid pending frame counter becoming negative
[platform/framework/web/chromium-efl.git] / cc / tiles / tile.h
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.
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/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"
23
24 namespace cc {
25
26 class PictureLayerTiling;
27 class TileManager;
28
29 class CC_EXPORT Tile {
30  public:
31   struct CreateInfo {
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;
39   };
40
41   enum TileRasterFlags { USE_PICTURE_ANALYSIS = 1 << 0, IS_OPAQUE = 1 << 1 };
42
43   typedef uint64_t Id;
44
45   Tile(const Tile&) = delete;
46   ~Tile();
47
48   Tile& operator=(const Tile&) = delete;
49
50   Id id() const {
51     return id_;
52   }
53
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;
58   }
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;
62   }
63
64   bool is_prepaint() const {
65     return !required_for_activation() && !required_for_draw();
66   }
67
68   bool use_picture_analysis() const {
69     return !!(flags_ & USE_PICTURE_ANALYSIS);
70   }
71
72   bool is_opaque() const { return !!(flags_ & IS_OPAQUE); }
73
74   void AsValueInto(base::trace_event::TracedValue* value) const;
75
76   const TileDrawInfo& draw_info() const { return draw_info_; }
77   TileDrawInfo& draw_info() { return draw_info_; }
78
79   float contents_scale_key() const {
80     const gfx::Vector2dF& scale = raster_transform_.scale();
81     return std::max(scale.x(), scale.y());
82   }
83   const gfx::AxisTransform2d& raster_transform() const {
84     return raster_transform_;
85   }
86   const gfx::Rect& content_rect() const { return content_rect_; }
87   const gfx::Rect& enclosing_layer_rect() const {
88     return enclosing_layer_rect_;
89   }
90
91   int layer_id() const { return layer_id_; }
92
93   int source_frame_number() const { return source_frame_number_; }
94
95   size_t GPUMemoryUsageInBytes() const;
96
97   const gfx::Size& desired_texture_size() const { return content_rect_.size(); }
98
99   int tiling_i_index() const { return tiling_i_index_; }
100   int tiling_j_index() const { return tiling_j_index_; }
101
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;
106   }
107
108   Id invalidated_id() const { return invalidated_id_; }
109   const gfx::Rect& invalidated_content_rect() const {
110     return invalidated_content_rect_;
111   }
112
113   bool HasRasterTask() const { return !!raster_task_.get(); }
114
115   bool HasMissingLCPCandidateImages() const;
116
117   void set_solid_color_analysis_performed(bool performed) {
118     is_solid_color_analysis_performed_ = performed;
119   }
120   bool is_solid_color_analysis_performed() const {
121     return is_solid_color_analysis_performed_;
122   }
123   bool can_use_lcd_text() const { return can_use_lcd_text_; }
124
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;
129   }
130   bool raster_task_scheduled_with_checker_images() const {
131     return raster_task_scheduled_with_checker_images_;
132   }
133
134   const PictureLayerTiling* tiling() const { return tiling_; }
135   void set_tiling(const PictureLayerTiling* tiling) { tiling_ = tiling; }
136
137  private:
138   friend class TileManager;
139   friend class FakeTileManager;
140   friend class FakePictureLayerImpl;
141
142   // Methods called by by tile manager.
143   Tile(TileManager* tile_manager,
144        const CreateInfo& info,
145        int layer_id,
146        int source_frame_number,
147        int flags);
148
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_;
154
155   TileDrawInfo draw_info_;
156
157   const int layer_id_;
158   const int source_frame_number_;
159   const int flags_;
160   const int tiling_i_index_;
161   const int tiling_j_index_;
162
163   // The |id_| of the Tile that was invalidated and replaced by this tile.
164   Id invalidated_id_ = 0;
165
166   unsigned scheduled_priority_ = 0;
167
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;
172
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;
176
177   Id id_;
178
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>>
182       raster_rects_;
183
184   // The rect bounding the changes in this Tile vs the previous tile it
185   // replaced.
186   gfx::Rect invalidated_content_rect_;
187
188   scoped_refptr<TileTask> raster_task_;
189 };
190
191 }  // namespace cc
192
193 #endif  // CC_TILES_TILE_H_