cc: Adding DidFinishImplFrame to LTHI.
[chromium-blink-merge.git] / cc / resources / picture_layer_tiling_set.h
blobe51d7ecd8bacff21eb43ffcb1d3a3f1f9ad59af2
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_RESOURCES_PICTURE_LAYER_TILING_SET_H_
6 #define CC_RESOURCES_PICTURE_LAYER_TILING_SET_H_
8 #include <set>
9 #include <vector>
11 #include "cc/base/region.h"
12 #include "cc/base/scoped_ptr_vector.h"
13 #include "cc/resources/picture_layer_tiling.h"
14 #include "ui/gfx/geometry/size.h"
16 namespace base {
17 namespace trace_event {
18 class TracedValue;
22 namespace cc {
24 class CC_EXPORT PictureLayerTilingSet {
25 public:
26 enum TilingRangeType {
27 HIGHER_THAN_HIGH_RES,
28 HIGH_RES,
29 BETWEEN_HIGH_AND_LOW_RES,
30 LOW_RES,
31 LOWER_THAN_LOW_RES
33 struct TilingRange {
34 TilingRange(int start, int end) : start(start), end(end) {}
36 int start;
37 int end;
40 static scoped_ptr<PictureLayerTilingSet> Create(
41 WhichTree tree,
42 PictureLayerTilingClient* client,
43 size_t max_tiles_for_interest_area,
44 float skewport_target_time_in_seconds,
45 int skewport_extrapolation_limit_in_content);
47 ~PictureLayerTilingSet();
49 const PictureLayerTilingClient* client() const { return client_; }
51 void CleanUpTilings(float min_acceptable_high_res_scale,
52 float max_acceptable_high_res_scale,
53 const std::vector<PictureLayerTiling*>& needed_tilings,
54 bool should_have_low_res,
55 PictureLayerTilingSet* twin_set,
56 PictureLayerTilingSet* recycled_twin_set);
57 void RemoveNonIdealTilings();
59 // This function is called on the active tree during activation.
60 void UpdateTilingsToCurrentRasterSourceForActivation(
61 scoped_refptr<RasterSource> raster_source,
62 const PictureLayerTilingSet* pending_twin_set,
63 const Region& layer_invalidation,
64 float minimum_contents_scale,
65 float maximum_contents_scale);
67 // This function is called on the sync tree during commit.
68 void UpdateTilingsToCurrentRasterSourceForCommit(
69 scoped_refptr<RasterSource> raster_source,
70 const Region& layer_invalidation,
71 float minimum_contents_scale,
72 float maximum_contents_scale);
74 // This function is called on the sync tree right after commit.
75 void UpdateRasterSourceDueToLCDChange(
76 const scoped_refptr<RasterSource>& raster_source,
77 const Region& layer_invalidation);
79 PictureLayerTiling* AddTiling(float contents_scale,
80 scoped_refptr<RasterSource> raster_source);
81 size_t num_tilings() const { return tilings_.size(); }
82 int NumHighResTilings() const;
83 PictureLayerTiling* tiling_at(size_t idx) { return tilings_[idx]; }
84 const PictureLayerTiling* tiling_at(size_t idx) const {
85 return tilings_[idx];
87 WhichTree tree() const { return tree_; }
89 PictureLayerTiling* FindTilingWithScale(float scale) const;
90 PictureLayerTiling* FindTilingWithResolution(TileResolution resolution) const;
92 void MarkAllTilingsNonIdeal();
94 // If a tiling exists whose scale is within |snap_to_existing_tiling_ratio|
95 // ratio of |start_scale|, then return that tiling's scale. Otherwise, return
96 // |start_scale|. If multiple tilings match the criteria, return the one with
97 // the least ratio to |start_scale|.
98 float GetSnappedContentsScale(float start_scale,
99 float snap_to_existing_tiling_ratio) const;
101 // Returns the maximum contents scale of all tilings, or 0 if no tilings
102 // exist.
103 float GetMaximumContentsScale() const;
105 // Removes all tilings with a contents scale < |minimum_scale|.
106 void RemoveTilingsBelowScale(float minimum_scale);
108 // Removes all tilings with a contents scale > |maximum_scale|.
109 void RemoveTilingsAboveScale(float maximum_scale);
111 // Remove all tilings.
112 void RemoveAllTilings();
114 // Remove all tiles; keep all tilings.
115 void RemoveAllTiles();
117 // Update the rects and priorities for tiles based on the given information.
118 bool UpdateTilePriorities(const gfx::Rect& required_rect_in_layer_space,
119 float ideal_contents_scale,
120 double current_frame_time_in_seconds,
121 const Occlusion& occlusion_in_layer_space,
122 bool can_require_tiles_for_activation);
124 void GetAllTilesAndPrioritiesForTracing(
125 std::map<const Tile*, TilePriority>* tile_map) const;
127 // For a given rect, iterates through tiles that can fill it. If no
128 // set of tiles with resources can fill the rect, then it will iterate
129 // through null tiles with valid geometry_rect() until the rect is full.
130 // If all tiles have resources, the union of all geometry_rects will
131 // exactly fill rect with no overlap.
132 class CC_EXPORT CoverageIterator {
133 public:
134 CoverageIterator(const PictureLayerTilingSet* set,
135 float contents_scale,
136 const gfx::Rect& content_rect,
137 float ideal_contents_scale);
138 ~CoverageIterator();
140 // Visible rect (no borders), always in the space of rect,
141 // regardless of the relative contents scale of the tiling.
142 gfx::Rect geometry_rect() const;
143 // Texture rect (in texels) for geometry_rect
144 gfx::RectF texture_rect() const;
146 Tile* operator->() const;
147 Tile* operator*() const;
149 CoverageIterator& operator++();
150 operator bool() const;
152 TileResolution resolution() const;
153 PictureLayerTiling* CurrentTiling() const;
155 private:
156 int NextTiling() const;
158 const PictureLayerTilingSet* set_;
159 float contents_scale_;
160 float ideal_contents_scale_;
161 PictureLayerTiling::CoverageIterator tiling_iter_;
162 int current_tiling_;
163 int ideal_tiling_;
165 Region current_region_;
166 Region missing_region_;
167 Region::Iterator region_iter_;
170 void AsValueInto(base::trace_event::TracedValue* array) const;
171 size_t GPUMemoryUsageInBytes() const;
173 TilingRange GetTilingRange(TilingRangeType type) const;
175 private:
176 explicit PictureLayerTilingSet(
177 WhichTree tree,
178 PictureLayerTilingClient* client,
179 size_t max_tiles_for_interest_area,
180 float skewport_target_time_in_seconds,
181 int skewport_extrapolation_limit_in_content_pixels);
183 void CopyTilingsAndPropertiesFromPendingTwin(
184 const PictureLayerTilingSet* pending_twin_set,
185 const scoped_refptr<RasterSource>& raster_source,
186 const Region& layer_invalidation);
188 // Remove one tiling.
189 void Remove(PictureLayerTiling* tiling);
190 void VerifyTilings(const PictureLayerTilingSet* pending_twin_set) const;
192 ScopedPtrVector<PictureLayerTiling> tilings_;
194 const size_t max_tiles_for_interest_area_;
195 const float skewport_target_time_in_seconds_;
196 const int skewport_extrapolation_limit_in_content_pixels_;
197 WhichTree tree_;
198 PictureLayerTilingClient* client_;
200 friend class Iterator;
201 DISALLOW_COPY_AND_ASSIGN(PictureLayerTilingSet);
204 } // namespace cc
206 #endif // CC_RESOURCES_PICTURE_LAYER_TILING_SET_H_