Don't show supervised user as "already on this device" while they're being imported.
[chromium-blink-merge.git] / cc / tiles / picture_layer_tiling_set.h
blob7e54411cd1ac71fafe3b87bb657e18b9241fcaca
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(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 float tiling_interest_area_viewport_multiplier,
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 void RemoveNonIdealTilings();
58 // This function is called on the active tree during activation.
59 void UpdateTilingsToCurrentRasterSourceForActivation(
60 scoped_refptr<RasterSource> raster_source,
61 const PictureLayerTilingSet* pending_twin_set,
62 const Region& layer_invalidation,
63 float minimum_contents_scale,
64 float maximum_contents_scale);
66 // This function is called on the sync tree during commit.
67 void UpdateTilingsToCurrentRasterSourceForCommit(
68 scoped_refptr<RasterSource> raster_source,
69 const Region& layer_invalidation,
70 float minimum_contents_scale,
71 float maximum_contents_scale);
73 // This function is called on the sync tree right after commit.
74 void UpdateRasterSourceDueToLCDChange(
75 const scoped_refptr<RasterSource>& raster_source,
76 const Region& layer_invalidation);
78 PictureLayerTiling* AddTiling(float contents_scale,
79 scoped_refptr<RasterSource> raster_source);
80 size_t num_tilings() const { return tilings_.size(); }
81 int NumHighResTilings() const;
82 PictureLayerTiling* tiling_at(size_t idx) { return tilings_[idx]; }
83 const PictureLayerTiling* tiling_at(size_t idx) const {
84 return tilings_[idx];
86 WhichTree tree() const { return tree_; }
88 PictureLayerTiling* FindTilingWithScale(float scale) const;
89 PictureLayerTiling* FindTilingWithResolution(TileResolution resolution) const;
91 void MarkAllTilingsNonIdeal();
93 // If a tiling exists whose scale is within |snap_to_existing_tiling_ratio|
94 // ratio of |start_scale|, then return that tiling's scale. Otherwise, return
95 // |start_scale|. If multiple tilings match the criteria, return the one with
96 // the least ratio to |start_scale|.
97 float GetSnappedContentsScale(float start_scale,
98 float snap_to_existing_tiling_ratio) const;
100 // Returns the maximum contents scale of all tilings, or 0 if no tilings
101 // exist.
102 float GetMaximumContentsScale() const;
104 // Removes all tilings with a contents scale < |minimum_scale|.
105 void RemoveTilingsBelowScale(float minimum_scale);
107 // Removes all tilings with a contents scale > |maximum_scale|.
108 void RemoveTilingsAboveScale(float maximum_scale);
110 // Remove all tilings.
111 void RemoveAllTilings();
113 // Remove all tiles; keep all tilings.
114 void RemoveAllTiles();
116 // Update the rects and priorities for tiles based on the given information.
117 bool UpdateTilePriorities(const gfx::Rect& required_rect_in_layer_space,
118 float ideal_contents_scale,
119 double current_frame_time_in_seconds,
120 const Occlusion& occlusion_in_layer_space,
121 bool can_require_tiles_for_activation);
123 void GetAllPrioritizedTilesForTracing(
124 std::vector<PrioritizedTile>* prioritized_tiles) const;
126 // For a given rect, iterates through tiles that can fill it. If no
127 // set of tiles with resources can fill the rect, then it will iterate
128 // through null tiles with valid geometry_rect() until the rect is full.
129 // If all tiles have resources, the union of all geometry_rects will
130 // exactly fill rect with no overlap.
131 class CC_EXPORT CoverageIterator {
132 public:
133 CoverageIterator(const PictureLayerTilingSet* set,
134 float contents_scale,
135 const gfx::Rect& content_rect,
136 float ideal_contents_scale);
137 ~CoverageIterator();
139 // Visible rect (no borders), always in the space of rect,
140 // regardless of the relative contents scale of the tiling.
141 gfx::Rect geometry_rect() const;
142 // Texture rect (in texels) for geometry_rect
143 gfx::RectF texture_rect() const;
145 Tile* operator->() const;
146 Tile* operator*() const;
148 CoverageIterator& operator++();
149 operator bool() const;
151 TileResolution resolution() const;
152 PictureLayerTiling* CurrentTiling() const;
154 private:
155 int NextTiling() const;
157 const PictureLayerTilingSet* set_;
158 float contents_scale_;
159 float ideal_contents_scale_;
160 PictureLayerTiling::CoverageIterator tiling_iter_;
161 int current_tiling_;
162 int ideal_tiling_;
164 Region current_region_;
165 Region missing_region_;
166 Region::Iterator region_iter_;
169 void AsValueInto(base::trace_event::TracedValue* array) const;
170 size_t GPUMemoryUsageInBytes() const;
172 TilingRange GetTilingRange(TilingRangeType type) const;
174 private:
175 explicit PictureLayerTilingSet(
176 WhichTree tree,
177 PictureLayerTilingClient* client,
178 float tiling_interest_area_viewport_multiplier,
179 float skewport_target_time_in_seconds,
180 int skewport_extrapolation_limit_in_content_pixels);
182 void CopyTilingsAndPropertiesFromPendingTwin(
183 const PictureLayerTilingSet* pending_twin_set,
184 const scoped_refptr<RasterSource>& raster_source,
185 const Region& layer_invalidation);
187 // Remove one tiling.
188 void Remove(PictureLayerTiling* tiling);
189 void VerifyTilings(const PictureLayerTilingSet* pending_twin_set) const;
191 ScopedPtrVector<PictureLayerTiling> tilings_;
193 const float tiling_interest_area_viewport_multiplier_;
194 const float skewport_target_time_in_seconds_;
195 const int skewport_extrapolation_limit_in_content_pixels_;
196 WhichTree tree_;
197 PictureLayerTilingClient* client_;
199 friend class Iterator;
200 DISALLOW_COPY_AND_ASSIGN(PictureLayerTilingSet);
203 } // namespace cc
205 #endif // CC_TILES_PICTURE_LAYER_TILING_SET_H_