Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / cc / tiles / picture_layer_tiling_set.h
blobb3e22fe34af4b3442d2f1c935a2fa7a06d6254c6
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_PICTURE_LAYER_TILING_SET_H_
6 #define CC_TILES_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/tiles/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(size_t start, size_t end) : start(start), end(end) {}
36 size_t start;
37 size_t end;
40 static scoped_ptr<PictureLayerTilingSet> Create(
41 WhichTree tree,
42 PictureLayerTilingClient* client,
43 size_t tiling_interest_area_padding,
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 PictureLayerTilingSet* twin_set);
55 void RemoveNonIdealTilings();
57 // This function is called on the active tree during activation.
58 void UpdateTilingsToCurrentRasterSourceForActivation(
59 scoped_refptr<RasterSource> raster_source,
60 const PictureLayerTilingSet* pending_twin_set,
61 const Region& layer_invalidation,
62 float minimum_contents_scale,
63 float maximum_contents_scale);
65 // This function is called on the sync tree during commit.
66 void UpdateTilingsToCurrentRasterSourceForCommit(
67 scoped_refptr<RasterSource> raster_source,
68 const Region& layer_invalidation,
69 float minimum_contents_scale,
70 float maximum_contents_scale);
72 // This function is called on the sync tree right after commit.
73 void UpdateRasterSourceDueToLCDChange(
74 const scoped_refptr<RasterSource>& raster_source,
75 const Region& layer_invalidation);
77 PictureLayerTiling* AddTiling(float contents_scale,
78 scoped_refptr<RasterSource> raster_source);
79 size_t num_tilings() const { return tilings_.size(); }
80 int NumHighResTilings() const;
81 PictureLayerTiling* tiling_at(size_t idx) { return tilings_[idx]; }
82 const PictureLayerTiling* tiling_at(size_t idx) const {
83 return tilings_[idx];
85 WhichTree tree() const { return tree_; }
87 PictureLayerTiling* FindTilingWithScale(float scale) const;
88 PictureLayerTiling* FindTilingWithResolution(TileResolution resolution) const;
90 void MarkAllTilingsNonIdeal();
92 // If a tiling exists whose scale is within |snap_to_existing_tiling_ratio|
93 // ratio of |start_scale|, then return that tiling's scale. Otherwise, return
94 // |start_scale|. If multiple tilings match the criteria, return the one with
95 // the least ratio to |start_scale|.
96 float GetSnappedContentsScale(float start_scale,
97 float snap_to_existing_tiling_ratio) const;
99 // Returns the maximum contents scale of all tilings, or 0 if no tilings
100 // exist.
101 float GetMaximumContentsScale() const;
103 // Removes all tilings with a contents scale < |minimum_scale|.
104 void RemoveTilingsBelowScale(float minimum_scale);
106 // Removes all tilings with a contents scale > |maximum_scale|.
107 void RemoveTilingsAboveScale(float maximum_scale);
109 // Remove all tilings.
110 void RemoveAllTilings();
112 // Remove all tiles; keep all tilings.
113 void RemoveAllTiles();
115 // Update the rects and priorities for tiles based on the given information.
116 bool UpdateTilePriorities(const gfx::Rect& required_rect_in_layer_space,
117 float ideal_contents_scale,
118 double current_frame_time_in_seconds,
119 const Occlusion& occlusion_in_layer_space,
120 bool can_require_tiles_for_activation);
122 void GetAllPrioritizedTilesForTracing(
123 std::vector<PrioritizedTile>* prioritized_tiles) const;
125 // For a given rect, iterates through tiles that can fill it. If no
126 // set of tiles with resources can fill the rect, then it will iterate
127 // through null tiles with valid geometry_rect() until the rect is full.
128 // If all tiles have resources, the union of all geometry_rects will
129 // exactly fill rect with no overlap.
130 class CC_EXPORT CoverageIterator {
131 public:
132 CoverageIterator(const PictureLayerTilingSet* set,
133 float contents_scale,
134 const gfx::Rect& content_rect,
135 float ideal_contents_scale);
136 ~CoverageIterator();
138 // Visible rect (no borders), always in the space of rect,
139 // regardless of the relative contents scale of the tiling.
140 gfx::Rect geometry_rect() const;
141 // Texture rect (in texels) for geometry_rect
142 gfx::RectF texture_rect() const;
144 Tile* operator->() const;
145 Tile* operator*() const;
147 CoverageIterator& operator++();
148 operator bool() const;
150 TileResolution resolution() const;
151 PictureLayerTiling* CurrentTiling() const;
153 private:
154 size_t NextTiling() const;
156 const PictureLayerTilingSet* set_;
157 float contents_scale_;
158 float ideal_contents_scale_;
159 PictureLayerTiling::CoverageIterator tiling_iter_;
160 size_t current_tiling_;
161 size_t ideal_tiling_;
163 Region current_region_;
164 Region missing_region_;
165 Region::Iterator region_iter_;
168 void AsValueInto(base::trace_event::TracedValue* array) const;
169 size_t GPUMemoryUsageInBytes() const;
171 TilingRange GetTilingRange(TilingRangeType type) const;
173 private:
174 explicit PictureLayerTilingSet(
175 WhichTree tree,
176 PictureLayerTilingClient* client,
177 size_t tiling_interest_area_padding,
178 float skewport_target_time_in_seconds,
179 int skewport_extrapolation_limit_in_content_pixels);
181 void CopyTilingsAndPropertiesFromPendingTwin(
182 const PictureLayerTilingSet* pending_twin_set,
183 const scoped_refptr<RasterSource>& raster_source,
184 const Region& layer_invalidation);
186 // Remove one tiling.
187 void Remove(PictureLayerTiling* tiling);
188 void VerifyTilings(const PictureLayerTilingSet* pending_twin_set) const;
190 ScopedPtrVector<PictureLayerTiling> tilings_;
192 const size_t tiling_interest_area_padding_;
193 const float skewport_target_time_in_seconds_;
194 const int skewport_extrapolation_limit_in_content_pixels_;
195 WhichTree tree_;
196 PictureLayerTilingClient* client_;
198 friend class Iterator;
199 DISALLOW_COPY_AND_ASSIGN(PictureLayerTilingSet);
202 } // namespace cc
204 #endif // CC_TILES_PICTURE_LAYER_TILING_SET_H_