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_
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"
17 namespace trace_event
{
24 class CC_EXPORT PictureLayerTilingSet
{
26 enum TilingRangeType
{
29 BETWEEN_HIGH_AND_LOW_RES
,
34 TilingRange(size_t start
, size_t end
) : start(start
), end(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 // This function can be called on both the active and pending tree.
59 // |pending_twin_set| represents the current pending twin. In situations where
60 // this is called on the active tree in two trees situations,
61 // |pending_twin_set| represents the tiling set from the pending twin layer.
62 // In situations where this is called on the sync tree (whether it's pending
63 // or active in cases of one tree), |pending_twin_set| should be nullptr.
64 void UpdateTilingsToCurrentRasterSource(
65 scoped_refptr
<RasterSource
> raster_source
,
66 const PictureLayerTilingSet
* pending_twin_set
,
67 const Region
& layer_invalidation
,
68 float minimum_contents_scale
,
69 float maximum_contents_scale
);
71 PictureLayerTiling
* AddTiling(float contents_scale
,
72 scoped_refptr
<RasterSource
> raster_source
);
73 size_t num_tilings() const { return tilings_
.size(); }
74 int NumHighResTilings() const;
75 PictureLayerTiling
* tiling_at(size_t idx
) { return tilings_
[idx
]; }
76 const PictureLayerTiling
* tiling_at(size_t idx
) const {
80 PictureLayerTiling
* FindTilingWithScale(float scale
) const;
81 PictureLayerTiling
* FindTilingWithResolution(TileResolution resolution
) const;
83 void MarkAllTilingsNonIdeal();
85 // If a tiling exists whose scale is within |snap_to_existing_tiling_ratio|
86 // ratio of |start_scale|, then return that tiling's scale. Otherwise, return
87 // |start_scale|. If multiple tilings match the criteria, return the one with
88 // the least ratio to |start_scale|.
89 float GetSnappedContentsScale(float start_scale
,
90 float snap_to_existing_tiling_ratio
) const;
92 // Returns the maximum contents scale of all tilings, or 0 if no tilings
94 float GetMaximumContentsScale() const;
96 // Removes all tilings with a contents scale < |minimum_scale|.
97 void RemoveTilingsBelowScale(float minimum_scale
);
99 // Removes all tilings with a contents scale > |maximum_scale|.
100 void RemoveTilingsAboveScale(float maximum_scale
);
102 // Remove all tilings.
103 void RemoveAllTilings();
105 // Remove all tiles; keep all tilings.
106 void RemoveAllTiles();
108 // Update the rects and priorities for tiles based on the given information.
109 bool UpdateTilePriorities(const gfx::Rect
& required_rect_in_layer_space
,
110 float ideal_contents_scale
,
111 double current_frame_time_in_seconds
,
112 const Occlusion
& occlusion_in_layer_space
,
113 bool can_require_tiles_for_activation
);
115 void GetAllTilesAndPrioritiesForTracing(
116 std::map
<const Tile
*, TilePriority
>* tile_map
) const;
118 // For a given rect, iterates through tiles that can fill it. If no
119 // set of tiles with resources can fill the rect, then it will iterate
120 // through null tiles with valid geometry_rect() until the rect is full.
121 // If all tiles have resources, the union of all geometry_rects will
122 // exactly fill rect with no overlap.
123 class CC_EXPORT CoverageIterator
{
125 CoverageIterator(const PictureLayerTilingSet
* set
,
126 float contents_scale
,
127 const gfx::Rect
& content_rect
,
128 float ideal_contents_scale
);
131 // Visible rect (no borders), always in the space of rect,
132 // regardless of the relative contents scale of the tiling.
133 gfx::Rect
geometry_rect() const;
134 // Texture rect (in texels) for geometry_rect
135 gfx::RectF
texture_rect() const;
137 Tile
* operator->() const;
138 Tile
* operator*() const;
140 CoverageIterator
& operator++();
141 operator bool() const;
143 TileResolution
resolution() const;
144 PictureLayerTiling
* CurrentTiling() const;
147 int NextTiling() const;
149 const PictureLayerTilingSet
* set_
;
150 float contents_scale_
;
151 float ideal_contents_scale_
;
152 PictureLayerTiling::CoverageIterator tiling_iter_
;
156 Region current_region_
;
157 Region missing_region_
;
158 Region::Iterator region_iter_
;
161 void AsValueInto(base::trace_event::TracedValue
* array
) const;
162 size_t GPUMemoryUsageInBytes() const;
164 TilingRange
GetTilingRange(TilingRangeType type
) const;
167 explicit PictureLayerTilingSet(
168 PictureLayerTilingClient
* client
,
169 size_t max_tiles_for_interest_area
,
170 float skewport_target_time_in_seconds
,
171 int skewport_extrapolation_limit_in_content_pixels
);
173 void CopyTilingsFromPendingTwin(
174 const PictureLayerTilingSet
* pending_twin_set
,
175 const scoped_refptr
<RasterSource
>& raster_source
);
177 // Remove one tiling.
178 void Remove(PictureLayerTiling
* tiling
);
180 ScopedPtrVector
<PictureLayerTiling
> tilings_
;
182 const size_t max_tiles_for_interest_area_
;
183 const float skewport_target_time_in_seconds_
;
184 const int skewport_extrapolation_limit_in_content_pixels_
;
185 PictureLayerTilingClient
* client_
;
187 friend class Iterator
;
188 DISALLOW_COPY_AND_ASSIGN(PictureLayerTilingSet
);
193 #endif // CC_RESOURCES_PICTURE_LAYER_TILING_SET_H_