OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "cc/layers/picture_layer_impl.h" | 5 #include "cc/layers/picture_layer_impl.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 | 9 |
10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
11 #include "cc/base/math_util.h" | 11 #include "cc/base/math_util.h" |
12 #include "cc/base/util.h" | 12 #include "cc/base/util.h" |
13 #include "cc/debug/debug_colors.h" | 13 #include "cc/debug/debug_colors.h" |
14 #include "cc/debug/micro_benchmark_impl.h" | 14 #include "cc/debug/micro_benchmark_impl.h" |
15 #include "cc/debug/traced_value.h" | 15 #include "cc/debug/traced_value.h" |
16 #include "cc/layers/append_quads_data.h" | 16 #include "cc/layers/append_quads_data.h" |
17 #include "cc/layers/quad_sink.h" | |
18 #include "cc/quads/checkerboard_draw_quad.h" | 17 #include "cc/quads/checkerboard_draw_quad.h" |
19 #include "cc/quads/debug_border_draw_quad.h" | 18 #include "cc/quads/debug_border_draw_quad.h" |
20 #include "cc/quads/picture_draw_quad.h" | 19 #include "cc/quads/picture_draw_quad.h" |
21 #include "cc/quads/solid_color_draw_quad.h" | 20 #include "cc/quads/solid_color_draw_quad.h" |
22 #include "cc/quads/tile_draw_quad.h" | 21 #include "cc/quads/tile_draw_quad.h" |
23 #include "cc/resources/tile_manager.h" | 22 #include "cc/resources/tile_manager.h" |
24 #include "cc/trees/layer_tree_impl.h" | 23 #include "cc/trees/layer_tree_impl.h" |
| 24 #include "cc/trees/occlusion_tracker.h" |
25 #include "ui/gfx/quad_f.h" | 25 #include "ui/gfx/quad_f.h" |
26 #include "ui/gfx/rect_conversions.h" | 26 #include "ui/gfx/rect_conversions.h" |
27 #include "ui/gfx/size_conversions.h" | 27 #include "ui/gfx/size_conversions.h" |
28 | 28 |
29 namespace { | 29 namespace { |
30 const float kMaxScaleRatioDuringPinch = 2.0f; | 30 const float kMaxScaleRatioDuringPinch = 2.0f; |
31 | 31 |
32 // When creating a new tiling during pinch, snap to an existing | 32 // When creating a new tiling during pinch, snap to an existing |
33 // tiling's scale if the desired scale is within this ratio. | 33 // tiling's scale if the desired scale is within this ratio. |
34 const float kSnapToExistingTilingRatio = 1.2f; | 34 const float kSnapToExistingTilingRatio = 1.2f; |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 // in case push properties is skipped. | 128 // in case push properties is skipped. |
129 layer_impl->invalidation_.Swap(&invalidation_); | 129 layer_impl->invalidation_.Swap(&invalidation_); |
130 invalidation_.Clear(); | 130 invalidation_.Clear(); |
131 needs_post_commit_initialization_ = true; | 131 needs_post_commit_initialization_ = true; |
132 | 132 |
133 // We always need to push properties. | 133 // We always need to push properties. |
134 // See http://crbug.com/303943 | 134 // See http://crbug.com/303943 |
135 needs_push_properties_ = true; | 135 needs_push_properties_ = true; |
136 } | 136 } |
137 | 137 |
138 void PictureLayerImpl::AppendQuads(QuadSink* quad_sink, | 138 void PictureLayerImpl::AppendQuads( |
139 AppendQuadsData* append_quads_data) { | 139 RenderPass* render_pass, |
| 140 const OcclusionTracker<LayerImpl>& occlusion_tracker, |
| 141 AppendQuadsData* append_quads_data) { |
140 DCHECK(!needs_post_commit_initialization_); | 142 DCHECK(!needs_post_commit_initialization_); |
141 | 143 |
142 float max_contents_scale = MaximumTilingContentsScale(); | 144 float max_contents_scale = MaximumTilingContentsScale(); |
143 gfx::Transform scaled_draw_transform = draw_transform(); | 145 gfx::Transform scaled_draw_transform = draw_transform(); |
144 scaled_draw_transform.Scale(SK_MScalar1 / max_contents_scale, | 146 scaled_draw_transform.Scale(SK_MScalar1 / max_contents_scale, |
145 SK_MScalar1 / max_contents_scale); | 147 SK_MScalar1 / max_contents_scale); |
146 gfx::Size scaled_content_bounds = | 148 gfx::Size scaled_content_bounds = |
147 gfx::ToCeiledSize(gfx::ScaleSize(content_bounds(), max_contents_scale)); | 149 gfx::ToCeiledSize(gfx::ScaleSize(content_bounds(), max_contents_scale)); |
148 | 150 |
149 gfx::Rect scaled_visible_content_rect = | 151 gfx::Rect scaled_visible_content_rect = |
150 gfx::ScaleToEnclosingRect(visible_content_rect(), max_contents_scale); | 152 gfx::ScaleToEnclosingRect(visible_content_rect(), max_contents_scale); |
151 scaled_visible_content_rect.Intersect(gfx::Rect(scaled_content_bounds)); | 153 scaled_visible_content_rect.Intersect(gfx::Rect(scaled_content_bounds)); |
152 | 154 |
153 SharedQuadState* shared_quad_state = quad_sink->CreateSharedQuadState(); | 155 SharedQuadState* shared_quad_state = |
| 156 render_pass->CreateAndAppendSharedQuadState(); |
| 157 PopulateSharedQuadState(shared_quad_state); |
154 shared_quad_state->SetAll(scaled_draw_transform, | 158 shared_quad_state->SetAll(scaled_draw_transform, |
155 scaled_content_bounds, | 159 scaled_content_bounds, |
156 scaled_visible_content_rect, | 160 scaled_visible_content_rect, |
157 draw_properties().clip_rect, | 161 draw_properties().clip_rect, |
158 draw_properties().is_clipped, | 162 draw_properties().is_clipped, |
159 draw_properties().opacity, | 163 draw_properties().opacity, |
160 blend_mode(), | 164 blend_mode(), |
161 sorting_context_id_); | 165 sorting_context_id_); |
162 | 166 |
163 gfx::Rect rect = scaled_visible_content_rect; | 167 gfx::Rect rect = scaled_visible_content_rect; |
164 | 168 |
165 if (current_draw_mode_ == DRAW_MODE_RESOURCELESS_SOFTWARE) { | 169 if (current_draw_mode_ == DRAW_MODE_RESOURCELESS_SOFTWARE) { |
166 AppendDebugBorderQuad( | 170 AppendDebugBorderQuad( |
167 quad_sink, | 171 render_pass, |
168 scaled_content_bounds, | 172 scaled_content_bounds, |
169 shared_quad_state, | 173 shared_quad_state, |
170 append_quads_data, | 174 append_quads_data, |
171 DebugColors::DirectPictureBorderColor(), | 175 DebugColors::DirectPictureBorderColor(), |
172 DebugColors::DirectPictureBorderWidth(layer_tree_impl())); | 176 DebugColors::DirectPictureBorderWidth(layer_tree_impl())); |
173 | 177 |
174 gfx::Rect geometry_rect = rect; | 178 gfx::Rect geometry_rect = rect; |
175 gfx::Rect opaque_rect = contents_opaque() ? geometry_rect : gfx::Rect(); | 179 gfx::Rect opaque_rect = contents_opaque() ? geometry_rect : gfx::Rect(); |
176 gfx::Rect visible_geometry_rect = | 180 gfx::Rect visible_geometry_rect = occlusion_tracker.UnoccludedContentRect( |
177 quad_sink->UnoccludedContentRect(geometry_rect, draw_transform()); | 181 geometry_rect, draw_transform()); |
178 if (visible_geometry_rect.IsEmpty()) | 182 if (visible_geometry_rect.IsEmpty()) |
179 return; | 183 return; |
180 | 184 |
181 gfx::Size texture_size = rect.size(); | 185 gfx::Size texture_size = rect.size(); |
182 gfx::RectF texture_rect = gfx::RectF(texture_size); | 186 gfx::RectF texture_rect = gfx::RectF(texture_size); |
183 gfx::Rect quad_content_rect = rect; | 187 gfx::Rect quad_content_rect = rect; |
184 | 188 |
185 scoped_ptr<PictureDrawQuad> quad = PictureDrawQuad::Create(); | 189 scoped_ptr<PictureDrawQuad> quad = PictureDrawQuad::Create(); |
186 quad->SetNew(shared_quad_state, | 190 quad->SetNew(shared_quad_state, |
187 geometry_rect, | 191 geometry_rect, |
188 opaque_rect, | 192 opaque_rect, |
189 visible_geometry_rect, | 193 visible_geometry_rect, |
190 texture_rect, | 194 texture_rect, |
191 texture_size, | 195 texture_size, |
192 RGBA_8888, | 196 RGBA_8888, |
193 quad_content_rect, | 197 quad_content_rect, |
194 max_contents_scale, | 198 max_contents_scale, |
195 pile_); | 199 pile_); |
196 quad_sink->Append(quad.PassAs<DrawQuad>()); | 200 render_pass->AppendDrawQuad(quad.PassAs<DrawQuad>()); |
197 append_quads_data->num_missing_tiles++; | 201 append_quads_data->num_missing_tiles++; |
198 return; | 202 return; |
199 } | 203 } |
200 | 204 |
201 AppendDebugBorderQuad( | 205 AppendDebugBorderQuad( |
202 quad_sink, scaled_content_bounds, shared_quad_state, append_quads_data); | 206 render_pass, scaled_content_bounds, shared_quad_state, append_quads_data); |
203 | 207 |
204 if (ShowDebugBorders()) { | 208 if (ShowDebugBorders()) { |
205 for (PictureLayerTilingSet::CoverageIterator iter( | 209 for (PictureLayerTilingSet::CoverageIterator iter( |
206 tilings_.get(), max_contents_scale, rect, ideal_contents_scale_); | 210 tilings_.get(), max_contents_scale, rect, ideal_contents_scale_); |
207 iter; | 211 iter; |
208 ++iter) { | 212 ++iter) { |
209 SkColor color; | 213 SkColor color; |
210 float width; | 214 float width; |
211 if (*iter && iter->IsReadyToDraw()) { | 215 if (*iter && iter->IsReadyToDraw()) { |
212 ManagedTileState::TileVersion::Mode mode = | 216 ManagedTileState::TileVersion::Mode mode = |
(...skipping 24 matching lines...) Expand all Loading... |
237 | 241 |
238 scoped_ptr<DebugBorderDrawQuad> debug_border_quad = | 242 scoped_ptr<DebugBorderDrawQuad> debug_border_quad = |
239 DebugBorderDrawQuad::Create(); | 243 DebugBorderDrawQuad::Create(); |
240 gfx::Rect geometry_rect = iter.geometry_rect(); | 244 gfx::Rect geometry_rect = iter.geometry_rect(); |
241 gfx::Rect visible_geometry_rect = geometry_rect; | 245 gfx::Rect visible_geometry_rect = geometry_rect; |
242 debug_border_quad->SetNew(shared_quad_state, | 246 debug_border_quad->SetNew(shared_quad_state, |
243 geometry_rect, | 247 geometry_rect, |
244 visible_geometry_rect, | 248 visible_geometry_rect, |
245 color, | 249 color, |
246 width); | 250 width); |
247 quad_sink->Append(debug_border_quad.PassAs<DrawQuad>()); | 251 render_pass->AppendDrawQuad(debug_border_quad.PassAs<DrawQuad>()); |
248 } | 252 } |
249 } | 253 } |
250 | 254 |
251 // Keep track of the tilings that were used so that tilings that are | 255 // Keep track of the tilings that were used so that tilings that are |
252 // unused can be considered for removal. | 256 // unused can be considered for removal. |
253 std::vector<PictureLayerTiling*> seen_tilings; | 257 std::vector<PictureLayerTiling*> seen_tilings; |
254 | 258 |
255 size_t missing_tile_count = 0u; | 259 size_t missing_tile_count = 0u; |
256 size_t on_demand_missing_tile_count = 0u; | 260 size_t on_demand_missing_tile_count = 0u; |
257 for (PictureLayerTilingSet::CoverageIterator iter( | 261 for (PictureLayerTilingSet::CoverageIterator iter( |
258 tilings_.get(), max_contents_scale, rect, ideal_contents_scale_); | 262 tilings_.get(), max_contents_scale, rect, ideal_contents_scale_); |
259 iter; | 263 iter; |
260 ++iter) { | 264 ++iter) { |
261 gfx::Rect geometry_rect = iter.geometry_rect(); | 265 gfx::Rect geometry_rect = iter.geometry_rect(); |
262 gfx::Rect visible_geometry_rect = | 266 gfx::Rect visible_geometry_rect = occlusion_tracker.UnoccludedContentRect( |
263 quad_sink->UnoccludedContentRect(geometry_rect, draw_transform()); | 267 geometry_rect, draw_transform()); |
264 if (visible_geometry_rect.IsEmpty()) | 268 if (visible_geometry_rect.IsEmpty()) |
265 continue; | 269 continue; |
266 | 270 |
267 append_quads_data->visible_content_area += | 271 append_quads_data->visible_content_area += |
268 visible_geometry_rect.width() * visible_geometry_rect.height(); | 272 visible_geometry_rect.width() * visible_geometry_rect.height(); |
269 | 273 |
270 scoped_ptr<DrawQuad> draw_quad; | 274 scoped_ptr<DrawQuad> draw_quad; |
271 if (*iter && iter->IsReadyToDraw()) { | 275 if (*iter && iter->IsReadyToDraw()) { |
272 const ManagedTileState::TileVersion& tile_version = | 276 const ManagedTileState::TileVersion& tile_version = |
273 iter->GetTileVersionForDrawing(); | 277 iter->GetTileVersionForDrawing(); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
334 } | 338 } |
335 } | 339 } |
336 } | 340 } |
337 | 341 |
338 if (!draw_quad) { | 342 if (!draw_quad) { |
339 if (draw_checkerboard_for_missing_tiles()) { | 343 if (draw_checkerboard_for_missing_tiles()) { |
340 scoped_ptr<CheckerboardDrawQuad> quad = CheckerboardDrawQuad::Create(); | 344 scoped_ptr<CheckerboardDrawQuad> quad = CheckerboardDrawQuad::Create(); |
341 SkColor color = DebugColors::DefaultCheckerboardColor(); | 345 SkColor color = DebugColors::DefaultCheckerboardColor(); |
342 quad->SetNew( | 346 quad->SetNew( |
343 shared_quad_state, geometry_rect, visible_geometry_rect, color); | 347 shared_quad_state, geometry_rect, visible_geometry_rect, color); |
344 quad_sink->Append(quad.PassAs<DrawQuad>()); | 348 render_pass->AppendDrawQuad(quad.PassAs<DrawQuad>()); |
345 } else { | 349 } else { |
346 SkColor color = SafeOpaqueBackgroundColor(); | 350 SkColor color = SafeOpaqueBackgroundColor(); |
347 scoped_ptr<SolidColorDrawQuad> quad = SolidColorDrawQuad::Create(); | 351 scoped_ptr<SolidColorDrawQuad> quad = SolidColorDrawQuad::Create(); |
348 quad->SetNew(shared_quad_state, | 352 quad->SetNew(shared_quad_state, |
349 geometry_rect, | 353 geometry_rect, |
350 visible_geometry_rect, | 354 visible_geometry_rect, |
351 color, | 355 color, |
352 false); | 356 false); |
353 quad_sink->Append(quad.PassAs<DrawQuad>()); | 357 render_pass->AppendDrawQuad(quad.PassAs<DrawQuad>()); |
354 } | 358 } |
355 | 359 |
356 append_quads_data->num_missing_tiles++; | 360 append_quads_data->num_missing_tiles++; |
357 append_quads_data->had_incomplete_tile = true; | 361 append_quads_data->had_incomplete_tile = true; |
358 append_quads_data->approximated_visible_content_area += | 362 append_quads_data->approximated_visible_content_area += |
359 visible_geometry_rect.width() * visible_geometry_rect.height(); | 363 visible_geometry_rect.width() * visible_geometry_rect.height(); |
360 ++missing_tile_count; | 364 ++missing_tile_count; |
361 continue; | 365 continue; |
362 } | 366 } |
363 | 367 |
364 quad_sink->Append(draw_quad.Pass()); | 368 render_pass->AppendDrawQuad(draw_quad.Pass()); |
365 | 369 |
366 if (iter->priority(ACTIVE_TREE).resolution != HIGH_RESOLUTION) { | 370 if (iter->priority(ACTIVE_TREE).resolution != HIGH_RESOLUTION) { |
367 append_quads_data->approximated_visible_content_area += | 371 append_quads_data->approximated_visible_content_area += |
368 visible_geometry_rect.width() * visible_geometry_rect.height(); | 372 visible_geometry_rect.width() * visible_geometry_rect.height(); |
369 } | 373 } |
370 | 374 |
371 if (seen_tilings.empty() || seen_tilings.back() != iter.CurrentTiling()) | 375 if (seen_tilings.empty() || seen_tilings.back() != iter.CurrentTiling()) |
372 seen_tilings.push_back(iter.CurrentTiling()); | 376 seen_tilings.push_back(iter.CurrentTiling()); |
373 } | 377 } |
374 | 378 |
(...skipping 1240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1615 return iterator_index_ < iterators_.size(); | 1619 return iterator_index_ < iterators_.size(); |
1616 } | 1620 } |
1617 | 1621 |
1618 bool PictureLayerImpl::LayerEvictionTileIterator::IsCorrectType( | 1622 bool PictureLayerImpl::LayerEvictionTileIterator::IsCorrectType( |
1619 PictureLayerTiling::TilingEvictionTileIterator* it) const { | 1623 PictureLayerTiling::TilingEvictionTileIterator* it) const { |
1620 return it->get_type() == iteration_stage_ && | 1624 return it->get_type() == iteration_stage_ && |
1621 (**it)->required_for_activation() == required_for_activation_; | 1625 (**it)->required_for_activation() == required_for_activation_; |
1622 } | 1626 } |
1623 | 1627 |
1624 } // namespace cc | 1628 } // namespace cc |
OLD | NEW |