Enable right clicking on the applist doodle web contents and log the data.
[chromium-blink-merge.git] / cc / resources / picture_layer_tiling_set.h
blobfc1e581f5e88ba458a270881abd5367ca1b27bb0
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(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 PictureLayerTilingClient* client,
42 size_t max_tiles_for_interest_area,
43 float skewport_target_time_in_seconds,
44 int skewport_extrapolation_limit_in_content);
46 ~PictureLayerTilingSet();
48 const PictureLayerTilingClient* client() const { return client_; }
50 void CleanUpTilings(float min_acceptable_high_res_scale,
51 float max_acceptable_high_res_scale,
52 const std::vector<PictureLayerTiling*>& needed_tilings,
53 bool should_have_low_res,
54 PictureLayerTilingSet* twin_set,
55 PictureLayerTilingSet* recycled_twin_set);
56 void RemoveNonIdealTilings();
58 void UpdateTilingsToCurrentRasterSource(
59 scoped_refptr<RasterSource> raster_source,
60 const PictureLayerTilingSet* twin_set,
61 const Region& layer_invalidation,
62 float minimum_contents_scale,
63 float maximum_contents_scale);
65 PictureLayerTiling* AddTiling(float contents_scale,
66 scoped_refptr<RasterSource> raster_source);
67 size_t num_tilings() const { return tilings_.size(); }
68 int NumHighResTilings() const;
69 PictureLayerTiling* tiling_at(size_t idx) { return tilings_[idx]; }
70 const PictureLayerTiling* tiling_at(size_t idx) const {
71 return tilings_[idx];
74 PictureLayerTiling* FindTilingWithScale(float scale) const;
75 PictureLayerTiling* FindTilingWithResolution(TileResolution resolution) const;
77 void MarkAllTilingsNonIdeal();
79 // If a tiling exists whose scale is within |snap_to_existing_tiling_ratio|
80 // ratio of |start_scale|, then return that tiling's scale. Otherwise, return
81 // |start_scale|. If multiple tilings match the criteria, return the one with
82 // the least ratio to |start_scale|.
83 float GetSnappedContentsScale(float start_scale,
84 float snap_to_existing_tiling_ratio) const;
86 // Returns the maximum contents scale of all tilings, or 0 if no tilings
87 // exist.
88 float GetMaximumContentsScale() const;
90 // Removes all tilings with a contents scale < |minimum_scale|.
91 void RemoveTilingsBelowScale(float minimum_scale);
93 // Removes all tilings with a contents scale > |maximum_scale|.
94 void RemoveTilingsAboveScale(float maximum_scale);
96 // Remove all tilings.
97 void RemoveAllTilings();
99 // Remove all tiles; keep all tilings.
100 void RemoveAllTiles();
102 // Update the rects and priorities for tiles based on the given information.
103 bool UpdateTilePriorities(const gfx::Rect& required_rect_in_layer_space,
104 float ideal_contents_scale,
105 double current_frame_time_in_seconds,
106 const Occlusion& occlusion_in_layer_space,
107 bool can_require_tiles_for_activation);
109 void GetAllTilesForTracing(std::set<const Tile*>* tiles) const;
111 // For a given rect, iterates through tiles that can fill it. If no
112 // set of tiles with resources can fill the rect, then it will iterate
113 // through null tiles with valid geometry_rect() until the rect is full.
114 // If all tiles have resources, the union of all geometry_rects will
115 // exactly fill rect with no overlap.
116 class CC_EXPORT CoverageIterator {
117 public:
118 CoverageIterator(const PictureLayerTilingSet* set,
119 float contents_scale,
120 const gfx::Rect& content_rect,
121 float ideal_contents_scale);
122 ~CoverageIterator();
124 // Visible rect (no borders), always in the space of rect,
125 // regardless of the relative contents scale of the tiling.
126 gfx::Rect geometry_rect() const;
127 // Texture rect (in texels) for geometry_rect
128 gfx::RectF texture_rect() const;
130 Tile* operator->() const;
131 Tile* operator*() const;
133 CoverageIterator& operator++();
134 operator bool() const;
136 TileResolution resolution() const;
137 PictureLayerTiling* CurrentTiling() const;
139 private:
140 int NextTiling() const;
142 const PictureLayerTilingSet* set_;
143 float contents_scale_;
144 float ideal_contents_scale_;
145 PictureLayerTiling::CoverageIterator tiling_iter_;
146 int current_tiling_;
147 int ideal_tiling_;
149 Region current_region_;
150 Region missing_region_;
151 Region::Iterator region_iter_;
154 void AsValueInto(base::trace_event::TracedValue* array) const;
155 size_t GPUMemoryUsageInBytes() const;
157 TilingRange GetTilingRange(TilingRangeType type) const;
159 private:
160 explicit PictureLayerTilingSet(
161 PictureLayerTilingClient* client,
162 size_t max_tiles_for_interest_area,
163 float skewport_target_time_in_seconds,
164 int skewport_extrapolation_limit_in_content_pixels);
166 // Remove one tiling.
167 void Remove(PictureLayerTiling* tiling);
169 ScopedPtrVector<PictureLayerTiling> tilings_;
171 const size_t max_tiles_for_interest_area_;
172 const float skewport_target_time_in_seconds_;
173 const int skewport_extrapolation_limit_in_content_pixels_;
174 PictureLayerTilingClient* client_;
176 friend class Iterator;
177 DISALLOW_COPY_AND_ASSIGN(PictureLayerTilingSet);
180 } // namespace cc
182 #endif // CC_RESOURCES_PICTURE_LAYER_TILING_SET_H_