OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 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. | |
4 | |
5 #include "cc/resources/pending_picture_layer_tiling.h" | |
6 | |
7 #include "ui/gfx/geometry/point_conversions.h" | |
8 #include "ui/gfx/geometry/rect_conversions.h" | |
9 #include "ui/gfx/geometry/safe_integer_conversions.h" | |
10 #include "ui/gfx/geometry/size_conversions.h" | |
11 | |
12 namespace cc { | |
13 | |
14 scoped_ptr<PictureLayerTiling> PendingPictureLayerTiling::Create( | |
15 float contents_scale, | |
16 scoped_refptr<RasterSource> raster_source, | |
17 PictureLayerTilingClient* client, | |
18 size_t max_tiles_for_interest_area, | |
19 float skewport_target_time_in_seconds, | |
20 int skewport_extrapolation_limit_in_content_pixels) { | |
21 return make_scoped_ptr(new PendingPictureLayerTiling( | |
22 contents_scale, raster_source, client, max_tiles_for_interest_area, | |
23 skewport_target_time_in_seconds, | |
24 skewport_extrapolation_limit_in_content_pixels)); | |
25 } | |
26 | |
27 PendingPictureLayerTiling::PendingPictureLayerTiling( | |
28 float contents_scale, | |
29 scoped_refptr<RasterSource> raster_source, | |
30 PictureLayerTilingClient* client, | |
31 size_t max_tiles_for_interest_area, | |
32 float skewport_target_time_in_seconds, | |
33 int skewport_extrapolation_limit_in_content_pixels) | |
34 : PictureLayerTiling(contents_scale, | |
35 raster_source, | |
36 client, | |
37 max_tiles_for_interest_area, | |
38 skewport_target_time_in_seconds, | |
39 skewport_extrapolation_limit_in_content_pixels) { | |
40 } | |
41 | |
42 PendingPictureLayerTiling::~PendingPictureLayerTiling() { | |
43 } | |
44 | |
45 void PendingPictureLayerTiling::SetRasterSourceAndResize( | |
46 const scoped_refptr<RasterSource> raster_source) { | |
47 DCHECK(!raster_source->IsSolidColor()); | |
48 gfx::Size old_layer_bounds = raster_source_->GetSize(); | |
49 raster_source_ = raster_source; | |
50 gfx::Size new_layer_bounds = raster_source_->GetSize(); | |
51 gfx::Size content_bounds = | |
52 gfx::ToCeiledSize(gfx::ScaleSize(new_layer_bounds, contents_scale_)); | |
53 gfx::Size tile_size = client_->CalculateTileSize(content_bounds); | |
54 | |
55 if (tile_size != tiling_data_.max_texture_size()) { | |
56 tiling_data_.SetTilingSize(content_bounds); | |
57 tiling_data_.SetMaxTextureSize(tile_size); | |
58 // When the tile size changes, the TilingData positions no longer work | |
59 // as valid keys to the TileMap, so just drop all tiles and clear the live | |
60 // tiles rect. | |
61 Reset(); | |
62 return; | |
63 } | |
64 | |
65 if (old_layer_bounds == new_layer_bounds) | |
66 return; | |
67 | |
68 // The SetLiveTilesRect() method would drop tiles outside the new bounds, | |
69 // but may do so incorrectly if resizing the tiling causes the number of | |
70 // tiles in the tiling_data_ to change. | |
71 gfx::Rect content_rect(content_bounds); | |
72 int before_left = tiling_data_.TileXIndexFromSrcCoord(live_tiles_rect_.x()); | |
73 int before_top = tiling_data_.TileYIndexFromSrcCoord(live_tiles_rect_.y()); | |
74 int before_right = | |
75 tiling_data_.TileXIndexFromSrcCoord(live_tiles_rect_.right() - 1); | |
76 int before_bottom = | |
77 tiling_data_.TileYIndexFromSrcCoord(live_tiles_rect_.bottom() - 1); | |
78 | |
79 // The live_tiles_rect_ is clamped to stay within the tiling size as we | |
80 // change it. | |
81 live_tiles_rect_.Intersect(content_rect); | |
82 tiling_data_.SetTilingSize(content_bounds); | |
83 | |
84 int after_right = -1; | |
85 int after_bottom = -1; | |
86 if (!live_tiles_rect_.IsEmpty()) { | |
87 after_right = | |
88 tiling_data_.TileXIndexFromSrcCoord(live_tiles_rect_.right() - 1); | |
89 after_bottom = | |
90 tiling_data_.TileYIndexFromSrcCoord(live_tiles_rect_.bottom() - 1); | |
91 } | |
92 | |
93 // There is no recycled twin since this is run on the pending tiling | |
94 // during commit, and on the active tree during activate. | |
95 // Drop tiles outside the new layer bounds if the layer shrank. | |
96 for (int i = after_right + 1; i <= before_right; ++i) { | |
97 for (int j = before_top; j <= before_bottom; ++j) | |
98 RemoveTileAt(i, j); | |
99 } | |
100 for (int i = before_left; i <= after_right; ++i) { | |
101 for (int j = after_bottom + 1; j <= before_bottom; ++j) | |
102 RemoveTileAt(i, j); | |
103 } | |
104 | |
105 if (after_right > before_right) { | |
106 DCHECK_EQ(after_right, before_right + 1); | |
107 for (int j = before_top; j <= after_bottom; ++j) | |
108 CreateTile(after_right, j); | |
109 } | |
110 if (after_bottom > before_bottom) { | |
111 DCHECK_EQ(after_bottom, before_bottom + 1); | |
112 for (int i = before_left; i <= before_right; ++i) | |
113 CreateTile(i, after_bottom); | |
114 } | |
115 } | |
116 | |
117 void PendingPictureLayerTiling::Invalidate(const Region& layer_invalidation) { | |
118 // Nothing to do here. | |
119 } | |
120 | |
121 void PendingPictureLayerTiling::SetRasterSourceOnTiles() { | |
122 // Nothing to do, but we can verify that the tiles already have the latest | |
123 // raster source. | |
124 #if DCHECK_IS_ON() | |
125 for (const auto& tile_pair : tiles_) | |
126 DCHECK_EQ(raster_source_.get(), tile_pair.second->raster_source()); | |
127 #endif | |
128 } | |
129 | |
130 bool PendingPictureLayerTiling::ShouldCreateTileAt(int i, int j) const { | |
131 const PictureLayerTiling* active_twin = | |
132 client_->GetPendingOrActiveTwinTiling(this); | |
133 if (!active_twin) | |
134 return true; | |
135 | |
136 if (!TilingMatchesTileIndecies(active_twin)) | |
enne (OOO)
2015/04/02 21:45:34
indices?
vmpstr
2015/04/02 22:33:27
Yup, poor spelling on my part.
| |
137 return true; | |
138 | |
139 gfx::Rect paint_rect = tiling_data_.TileBoundsWithBorder(i, j); | |
140 gfx::Rect tile_rect = paint_rect; | |
141 tile_rect.set_size(tiling_data_.max_texture_size()); | |
142 | |
143 if (!active_twin->raster_source()->CoversRect(tile_rect, contents_scale())) | |
144 return true; | |
145 | |
146 const Region* layer_invalidation = client_->GetPendingInvalidation(); | |
147 gfx::Rect layer_rect = | |
148 gfx::ScaleToEnclosingRect(tile_rect, 1.f / contents_scale()); | |
149 | |
150 if (layer_invalidation && layer_invalidation->Intersects(layer_rect)) | |
151 return true; | |
152 return false; | |
153 } | |
154 | |
155 void PendingPictureLayerTiling::CreateMissingTilesInLiveTilesRect() { | |
156 bool include_borders = false; | |
157 for (TilingData::Iterator iter(&tiling_data_, live_tiles_rect_, | |
158 include_borders); | |
159 iter; ++iter) { | |
160 TileMapKey key = iter.index(); | |
161 TileMap::iterator find = tiles_.find(key); | |
162 if (find != tiles_.end()) | |
163 continue; | |
164 | |
165 if (ShouldCreateTileAt(key.first, key.second)) | |
166 CreateTile(key.first, key.second); | |
167 } | |
168 VerifyLiveTilesRect(false); | |
169 } | |
170 | |
171 void PendingPictureLayerTiling::SetLiveTilesRect( | |
172 const gfx::Rect& new_live_tiles_rect) { | |
173 DCHECK(new_live_tiles_rect.IsEmpty() || | |
174 gfx::Rect(tiling_size()).Contains(new_live_tiles_rect)) | |
175 << "tiling_size: " << tiling_size().ToString() | |
176 << " new_live_tiles_rect: " << new_live_tiles_rect.ToString(); | |
177 if (live_tiles_rect_ == new_live_tiles_rect) | |
178 return; | |
179 | |
180 // Iterate to delete all tiles outside of our new live_tiles rect. | |
181 for (TilingData::DifferenceIterator iter(&tiling_data_, live_tiles_rect_, | |
182 new_live_tiles_rect); | |
183 iter; ++iter) { | |
184 RemoveTileAt(iter.index_x(), iter.index_y()); | |
185 } | |
186 | |
187 // Iterate to allocate new tiles for all regions with newly exposed area. | |
188 for (TilingData::DifferenceIterator iter(&tiling_data_, new_live_tiles_rect, | |
189 live_tiles_rect_); | |
190 iter; ++iter) { | |
191 TileMapKey key(iter.index()); | |
192 if (ShouldCreateTileAt(key.first, key.second)) | |
193 CreateTile(key.first, key.second); | |
194 } | |
195 | |
196 live_tiles_rect_ = new_live_tiles_rect; | |
197 VerifyLiveTilesRect(false); | |
198 } | |
199 | |
200 void PendingPictureLayerTiling::TakeTilesAndPropertiesFrom( | |
201 PictureLayerTiling* pending_twin) { | |
202 // This function should only be called on the active tree. | |
203 NOTREACHED(); | |
204 } | |
205 | |
206 bool PendingPictureLayerTiling::IsTileOccluded(const Tile* tile) const { | |
207 if (!current_occlusion_in_layer_space_.HasOcclusion()) | |
208 return false; | |
209 gfx::Rect tile_query_rect = | |
210 gfx::IntersectRects(tile->content_rect(), current_visible_rect_); | |
211 // Explicitly check if the tile is outside the viewport. If so, we need to | |
212 // return false, since occlusion for this tile is unknown. | |
213 if (tile_query_rect.IsEmpty()) | |
214 return false; | |
215 | |
216 if (contents_scale_ != 1.f) { | |
217 tile_query_rect = | |
218 gfx::ScaleToEnclosingRect(tile_query_rect, 1.f / contents_scale_); | |
219 } | |
220 return current_occlusion_in_layer_space_.IsOccluded(tile_query_rect); | |
221 } | |
222 | |
223 bool PendingPictureLayerTiling::IsTileRequiredForActivation( | |
224 const Tile* tile) const { | |
225 if (!can_require_tiles_for_activation_) | |
226 return false; | |
227 | |
228 if (resolution_ != HIGH_RESOLUTION) | |
229 return false; | |
230 | |
231 if (IsTileOccluded(tile)) | |
232 return false; | |
233 | |
234 return tile->content_rect().Intersects(current_visible_rect_); | |
235 } | |
236 | |
237 bool PendingPictureLayerTiling::IsTileRequiredForDraw(const Tile* tile) const { | |
238 return false; | |
239 } | |
240 | |
241 } // namespace cc | |
OLD | NEW |