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 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 {
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
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 GetAllTilesAndPrioritiesForTracing(
123 std::map
<const Tile
*, TilePriority
>* tile_map
) 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
{
132 CoverageIterator(const PictureLayerTilingSet
* set
,
133 float contents_scale
,
134 const gfx::Rect
& content_rect
,
135 float ideal_contents_scale
);
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;
154 int NextTiling() const;
156 const PictureLayerTilingSet
* set_
;
157 float contents_scale_
;
158 float ideal_contents_scale_
;
159 PictureLayerTiling::CoverageIterator tiling_iter_
;
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;
174 explicit PictureLayerTilingSet(
175 PictureLayerTilingClient
* client
,
176 size_t max_tiles_for_interest_area
,
177 float skewport_target_time_in_seconds
,
178 int skewport_extrapolation_limit_in_content_pixels
);
180 void CopyTilingsAndPropertiesFromPendingTwin(
181 const PictureLayerTilingSet
* pending_twin_set
,
182 const scoped_refptr
<RasterSource
>& raster_source
);
184 // Remove one tiling.
185 void Remove(PictureLayerTiling
* tiling
);
186 void VerifyTilings(const PictureLayerTilingSet
* pending_twin_set
) const;
188 ScopedPtrVector
<PictureLayerTiling
> tilings_
;
190 const size_t max_tiles_for_interest_area_
;
191 const float skewport_target_time_in_seconds_
;
192 const int skewport_extrapolation_limit_in_content_pixels_
;
193 PictureLayerTilingClient
* client_
;
195 friend class Iterator
;
196 DISALLOW_COPY_AND_ASSIGN(PictureLayerTilingSet
);
201 #endif // CC_RESOURCES_PICTURE_LAYER_TILING_SET_H_