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 <cmath> | 8 #include <cmath> |
9 #include <limits> | 9 #include <limits> |
10 #include <set> | 10 #include <set> |
11 | 11 |
12 #include "base/debug/trace_event_argument.h" | |
13 #include "base/time/time.h" | 12 #include "base/time/time.h" |
| 13 #include "base/trace_event/trace_event_argument.h" |
14 #include "cc/base/math_util.h" | 14 #include "cc/base/math_util.h" |
15 #include "cc/base/util.h" | 15 #include "cc/base/util.h" |
16 #include "cc/debug/debug_colors.h" | 16 #include "cc/debug/debug_colors.h" |
17 #include "cc/debug/micro_benchmark_impl.h" | 17 #include "cc/debug/micro_benchmark_impl.h" |
18 #include "cc/debug/traced_value.h" | 18 #include "cc/debug/traced_value.h" |
19 #include "cc/layers/append_quads_data.h" | 19 #include "cc/layers/append_quads_data.h" |
20 #include "cc/layers/solid_color_layer_impl.h" | 20 #include "cc/layers/solid_color_layer_impl.h" |
21 #include "cc/output/begin_frame_args.h" | 21 #include "cc/output/begin_frame_args.h" |
22 #include "cc/quads/checkerboard_draw_quad.h" | 22 #include "cc/quads/checkerboard_draw_quad.h" |
23 #include "cc/quads/debug_border_draw_quad.h" | 23 #include "cc/quads/debug_border_draw_quad.h" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 } | 58 } |
59 | 59 |
60 PictureLayerImpl::Pair::Pair(PictureLayerImpl* active_layer, | 60 PictureLayerImpl::Pair::Pair(PictureLayerImpl* active_layer, |
61 PictureLayerImpl* pending_layer) | 61 PictureLayerImpl* pending_layer) |
62 : active(active_layer), pending(pending_layer) { | 62 : active(active_layer), pending(pending_layer) { |
63 } | 63 } |
64 | 64 |
65 PictureLayerImpl::Pair::~Pair() { | 65 PictureLayerImpl::Pair::~Pair() { |
66 } | 66 } |
67 | 67 |
68 PictureLayerImpl::PictureLayerImpl(LayerTreeImpl* tree_impl, | 68 PictureLayerImpl::PictureLayerImpl( |
69 int id, | 69 LayerTreeImpl* tree_impl, |
70 bool is_mask) | 70 int id, |
71 : LayerImpl(tree_impl, id), | 71 bool is_mask, |
| 72 scoped_refptr<SyncedScrollOffset> scroll_offset) |
| 73 : LayerImpl(tree_impl, id, scroll_offset), |
72 twin_layer_(nullptr), | 74 twin_layer_(nullptr), |
73 tilings_(CreatePictureLayerTilingSet()), | 75 tilings_(CreatePictureLayerTilingSet()), |
74 ideal_page_scale_(0.f), | 76 ideal_page_scale_(0.f), |
75 ideal_device_scale_(0.f), | 77 ideal_device_scale_(0.f), |
76 ideal_source_scale_(0.f), | 78 ideal_source_scale_(0.f), |
77 ideal_contents_scale_(0.f), | 79 ideal_contents_scale_(0.f), |
78 raster_page_scale_(0.f), | 80 raster_page_scale_(0.f), |
79 raster_device_scale_(0.f), | 81 raster_device_scale_(0.f), |
80 raster_source_scale_(0.f), | 82 raster_source_scale_(0.f), |
81 raster_contents_scale_(0.f), | 83 raster_contents_scale_(0.f), |
(...skipping 11 matching lines...) Expand all Loading... |
93 twin_layer_->twin_layer_ = nullptr; | 95 twin_layer_->twin_layer_ = nullptr; |
94 layer_tree_impl()->UnregisterPictureLayerImpl(this); | 96 layer_tree_impl()->UnregisterPictureLayerImpl(this); |
95 } | 97 } |
96 | 98 |
97 const char* PictureLayerImpl::LayerTypeAsString() const { | 99 const char* PictureLayerImpl::LayerTypeAsString() const { |
98 return "cc::PictureLayerImpl"; | 100 return "cc::PictureLayerImpl"; |
99 } | 101 } |
100 | 102 |
101 scoped_ptr<LayerImpl> PictureLayerImpl::CreateLayerImpl( | 103 scoped_ptr<LayerImpl> PictureLayerImpl::CreateLayerImpl( |
102 LayerTreeImpl* tree_impl) { | 104 LayerTreeImpl* tree_impl) { |
103 return PictureLayerImpl::Create(tree_impl, id(), is_mask_); | 105 return PictureLayerImpl::Create(tree_impl, id(), is_mask_, |
| 106 synced_scroll_offset()); |
104 } | 107 } |
105 | 108 |
106 void PictureLayerImpl::PushPropertiesTo(LayerImpl* base_layer) { | 109 void PictureLayerImpl::PushPropertiesTo(LayerImpl* base_layer) { |
107 PictureLayerImpl* layer_impl = static_cast<PictureLayerImpl*>(base_layer); | 110 PictureLayerImpl* layer_impl = static_cast<PictureLayerImpl*>(base_layer); |
108 DCHECK_EQ(layer_impl->is_mask_, is_mask_); | 111 DCHECK_EQ(layer_impl->is_mask_, is_mask_); |
109 | 112 |
110 LayerImpl::PushPropertiesTo(base_layer); | 113 LayerImpl::PushPropertiesTo(base_layer); |
111 | 114 |
112 // Twin relationships should never change once established. | 115 // Twin relationships should never change once established. |
113 DCHECK_IMPLIES(twin_layer_, twin_layer_ == layer_impl); | 116 DCHECK_IMPLIES(twin_layer_, twin_layer_ == layer_impl); |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
269 debug_border_quad->SetNew(shared_quad_state, | 272 debug_border_quad->SetNew(shared_quad_state, |
270 geometry_rect, | 273 geometry_rect, |
271 visible_geometry_rect, | 274 visible_geometry_rect, |
272 color, | 275 color, |
273 width); | 276 width); |
274 } | 277 } |
275 } | 278 } |
276 | 279 |
277 // Keep track of the tilings that were used so that tilings that are | 280 // Keep track of the tilings that were used so that tilings that are |
278 // unused can be considered for removal. | 281 // unused can be considered for removal. |
279 std::vector<PictureLayerTiling*> seen_tilings; | 282 last_append_quads_tilings_.clear(); |
280 | 283 |
281 // Ignore missing tiles outside of viewport for tile priority. This is | 284 // Ignore missing tiles outside of viewport for tile priority. This is |
282 // normally the same as draw viewport but can be independently overridden by | 285 // normally the same as draw viewport but can be independently overridden by |
283 // embedders like Android WebView with SetExternalDrawConstraints. | 286 // embedders like Android WebView with SetExternalDrawConstraints. |
284 gfx::Rect scaled_viewport_for_tile_priority = gfx::ScaleToEnclosingRect( | 287 gfx::Rect scaled_viewport_for_tile_priority = gfx::ScaleToEnclosingRect( |
285 viewport_rect_for_tile_priority_in_content_space_, max_contents_scale); | 288 viewport_rect_for_tile_priority_in_content_space_, max_contents_scale); |
286 | 289 |
287 size_t missing_tile_count = 0u; | 290 size_t missing_tile_count = 0u; |
288 size_t on_demand_missing_tile_count = 0u; | 291 size_t on_demand_missing_tile_count = 0u; |
289 only_used_low_res_last_append_quads_ = true; | 292 only_used_low_res_last_append_quads_ = true; |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
396 if (iter.resolution() != HIGH_RESOLUTION) { | 399 if (iter.resolution() != HIGH_RESOLUTION) { |
397 append_quads_data->approximated_visible_content_area += | 400 append_quads_data->approximated_visible_content_area += |
398 visible_geometry_rect.width() * visible_geometry_rect.height(); | 401 visible_geometry_rect.width() * visible_geometry_rect.height(); |
399 } | 402 } |
400 | 403 |
401 // If we have a draw quad, but it's not low resolution, then | 404 // If we have a draw quad, but it's not low resolution, then |
402 // mark that we've used something other than low res to draw. | 405 // mark that we've used something other than low res to draw. |
403 if (iter.resolution() != LOW_RESOLUTION) | 406 if (iter.resolution() != LOW_RESOLUTION) |
404 only_used_low_res_last_append_quads_ = false; | 407 only_used_low_res_last_append_quads_ = false; |
405 | 408 |
406 if (seen_tilings.empty() || seen_tilings.back() != iter.CurrentTiling()) | 409 if (last_append_quads_tilings_.empty() || |
407 seen_tilings.push_back(iter.CurrentTiling()); | 410 last_append_quads_tilings_.back() != iter.CurrentTiling()) { |
| 411 last_append_quads_tilings_.push_back(iter.CurrentTiling()); |
| 412 } |
408 } | 413 } |
409 | 414 |
410 if (missing_tile_count) { | 415 if (missing_tile_count) { |
411 TRACE_EVENT_INSTANT2("cc", | 416 TRACE_EVENT_INSTANT2("cc", |
412 "PictureLayerImpl::AppendQuads checkerboard", | 417 "PictureLayerImpl::AppendQuads checkerboard", |
413 TRACE_EVENT_SCOPE_THREAD, | 418 TRACE_EVENT_SCOPE_THREAD, |
414 "missing_tile_count", | 419 "missing_tile_count", |
415 missing_tile_count, | 420 missing_tile_count, |
416 "on_demand_missing_tile_count", | 421 "on_demand_missing_tile_count", |
417 on_demand_missing_tile_count); | 422 on_demand_missing_tile_count); |
418 } | 423 } |
419 | 424 |
420 // Aggressively remove any tilings that are not seen to save memory. Note | 425 // Aggressively remove any tilings that are not seen to save memory. Note |
421 // that this is at the expense of doing cause more frequent re-painting. A | 426 // that this is at the expense of doing cause more frequent re-painting. A |
422 // better scheme would be to maintain a tighter visible_content_rect for the | 427 // better scheme would be to maintain a tighter visible_content_rect for the |
423 // finer tilings. | 428 // finer tilings. |
424 CleanUpTilingsOnActiveLayer(seen_tilings); | 429 CleanUpTilingsOnActiveLayer(last_append_quads_tilings_); |
425 } | 430 } |
426 | 431 |
427 bool PictureLayerImpl::UpdateTiles(const Occlusion& occlusion_in_content_space, | 432 bool PictureLayerImpl::UpdateTiles(const Occlusion& occlusion_in_content_space, |
428 bool resourceless_software_draw) { | 433 bool resourceless_software_draw) { |
429 DCHECK_EQ(1.f, contents_scale_x()); | 434 DCHECK_EQ(1.f, contents_scale_x()); |
430 DCHECK_EQ(1.f, contents_scale_y()); | 435 DCHECK_EQ(1.f, contents_scale_y()); |
431 | 436 |
432 if (!resourceless_software_draw) { | 437 if (!resourceless_software_draw) { |
433 visible_rect_for_tile_priority_ = visible_content_rect(); | 438 visible_rect_for_tile_priority_ = visible_content_rect(); |
434 } | 439 } |
435 | 440 |
436 if (!CanHaveTilings()) { | 441 if (!CanHaveTilings()) { |
437 ideal_page_scale_ = 0.f; | 442 ideal_page_scale_ = 0.f; |
438 ideal_device_scale_ = 0.f; | 443 ideal_device_scale_ = 0.f; |
439 ideal_contents_scale_ = 0.f; | 444 ideal_contents_scale_ = 0.f; |
440 ideal_source_scale_ = 0.f; | 445 ideal_source_scale_ = 0.f; |
441 SanityCheckTilingState(); | 446 SanityCheckTilingState(); |
442 return false; | 447 return false; |
443 } | 448 } |
444 | 449 |
| 450 // Remove any non-ideal tilings that were not used last time we generated |
| 451 // quads to save memory and processing time. Note that pending tree should |
| 452 // only have one or two tilings (high and low res), so only clean up the |
| 453 // active layer. This cleans it up here in case AppendQuads didn't run. |
| 454 // If it did run, this would not remove any additional tilings. |
| 455 if (GetTree() == ACTIVE_TREE) |
| 456 CleanUpTilingsOnActiveLayer(last_append_quads_tilings_); |
| 457 |
445 UpdateIdealScales(); | 458 UpdateIdealScales(); |
446 | 459 |
447 if (!raster_contents_scale_ || ShouldAdjustRasterScale()) { | 460 if (!raster_contents_scale_ || ShouldAdjustRasterScale()) { |
448 RecalculateRasterScales(); | 461 RecalculateRasterScales(); |
449 AddTilingsForRasterScale(); | 462 AddTilingsForRasterScale(); |
450 } | 463 } |
451 | 464 |
452 DCHECK(raster_page_scale_); | 465 DCHECK(raster_page_scale_); |
453 DCHECK(raster_device_scale_); | 466 DCHECK(raster_device_scale_); |
454 DCHECK(raster_source_scale_); | 467 DCHECK(raster_source_scale_); |
455 DCHECK(raster_contents_scale_); | 468 DCHECK(raster_contents_scale_); |
456 DCHECK(low_res_raster_contents_scale_); | 469 DCHECK(low_res_raster_contents_scale_); |
457 | 470 |
458 was_screen_space_transform_animating_ = | 471 was_screen_space_transform_animating_ = |
459 draw_properties().screen_space_transform_is_animating; | 472 draw_properties().screen_space_transform_is_animating; |
460 | 473 |
461 if (draw_transform_is_animating()) | 474 if (draw_transform_is_animating()) |
462 raster_source_->SetShouldAttemptToUseDistanceFieldText(); | 475 raster_source_->SetShouldAttemptToUseDistanceFieldText(); |
463 | |
464 return UpdateTilePriorities(occlusion_in_content_space); | 476 return UpdateTilePriorities(occlusion_in_content_space); |
465 } | 477 } |
466 | 478 |
467 bool PictureLayerImpl::UpdateTilePriorities( | 479 bool PictureLayerImpl::UpdateTilePriorities( |
468 const Occlusion& occlusion_in_content_space) { | 480 const Occlusion& occlusion_in_content_space) { |
469 DCHECK_IMPLIES(raster_source_->IsSolidColor(), tilings_->num_tilings() == 0); | 481 DCHECK_IMPLIES(raster_source_->IsSolidColor(), tilings_->num_tilings() == 0); |
470 | 482 |
471 double current_frame_time_in_seconds = | 483 double current_frame_time_in_seconds = |
472 (layer_tree_impl()->CurrentBeginFrameArgs().frame_time - | 484 (layer_tree_impl()->CurrentBeginFrameArgs().frame_time - |
473 base::TimeTicks()).InSecondsF(); | 485 base::TimeTicks()).InSecondsF(); |
(...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
985 float low_res_factor = | 997 float low_res_factor = |
986 layer_tree_impl()->settings().low_res_contents_scale_factor; | 998 layer_tree_impl()->settings().low_res_contents_scale_factor; |
987 low_res_raster_contents_scale_ = | 999 low_res_raster_contents_scale_ = |
988 std::max(raster_contents_scale_ * low_res_factor, MinimumContentsScale()); | 1000 std::max(raster_contents_scale_ * low_res_factor, MinimumContentsScale()); |
989 DCHECK_LE(low_res_raster_contents_scale_, raster_contents_scale_); | 1001 DCHECK_LE(low_res_raster_contents_scale_, raster_contents_scale_); |
990 DCHECK_GE(low_res_raster_contents_scale_, MinimumContentsScale()); | 1002 DCHECK_GE(low_res_raster_contents_scale_, MinimumContentsScale()); |
991 DCHECK_LE(low_res_raster_contents_scale_, MaximumContentsScale()); | 1003 DCHECK_LE(low_res_raster_contents_scale_, MaximumContentsScale()); |
992 } | 1004 } |
993 | 1005 |
994 void PictureLayerImpl::CleanUpTilingsOnActiveLayer( | 1006 void PictureLayerImpl::CleanUpTilingsOnActiveLayer( |
995 std::vector<PictureLayerTiling*> used_tilings) { | 1007 const std::vector<PictureLayerTiling*>& used_tilings) { |
996 DCHECK(layer_tree_impl()->IsActiveTree()); | 1008 DCHECK(layer_tree_impl()->IsActiveTree()); |
997 if (tilings_->num_tilings() == 0) | 1009 if (tilings_->num_tilings() == 0) |
998 return; | 1010 return; |
999 | 1011 |
1000 float min_acceptable_high_res_scale = std::min( | 1012 float min_acceptable_high_res_scale = std::min( |
1001 raster_contents_scale_, ideal_contents_scale_); | 1013 raster_contents_scale_, ideal_contents_scale_); |
1002 float max_acceptable_high_res_scale = std::max( | 1014 float max_acceptable_high_res_scale = std::max( |
1003 raster_contents_scale_, ideal_contents_scale_); | 1015 raster_contents_scale_, ideal_contents_scale_); |
1004 | 1016 |
1005 PictureLayerImpl* twin = GetPendingOrActiveTwinLayer(); | 1017 PictureLayerImpl* twin = GetPendingOrActiveTwinLayer(); |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1215 } | 1227 } |
1216 | 1228 |
1217 bool PictureLayerImpl::IsOnActiveOrPendingTree() const { | 1229 bool PictureLayerImpl::IsOnActiveOrPendingTree() const { |
1218 return !layer_tree_impl()->IsRecycleTree(); | 1230 return !layer_tree_impl()->IsRecycleTree(); |
1219 } | 1231 } |
1220 | 1232 |
1221 bool PictureLayerImpl::HasValidTilePriorities() const { | 1233 bool PictureLayerImpl::HasValidTilePriorities() const { |
1222 return IsOnActiveOrPendingTree() && IsDrawnRenderSurfaceLayerListMember(); | 1234 return IsOnActiveOrPendingTree() && IsDrawnRenderSurfaceLayerListMember(); |
1223 } | 1235 } |
1224 | 1236 |
1225 bool PictureLayerImpl::AllTilesRequiredAreReadyToDraw( | |
1226 TileRequirementCheck is_tile_required_callback) const { | |
1227 if (!HasValidTilePriorities()) | |
1228 return true; | |
1229 | |
1230 if (!tilings_) | |
1231 return true; | |
1232 | |
1233 if (visible_rect_for_tile_priority_.IsEmpty()) | |
1234 return true; | |
1235 | |
1236 gfx::Rect rect = viewport_rect_for_tile_priority_in_content_space_; | |
1237 rect.Intersect(visible_rect_for_tile_priority_); | |
1238 | |
1239 // The high resolution tiling is the only tiling that can mark tiles as | |
1240 // requiring either draw or activation. There is an explicit check in those | |
1241 // callbacks to return false if they are not high resolution tilings. This | |
1242 // check needs to remain since there are other callers of that function that | |
1243 // rely on it. However, for the purposes of this function, we don't have to | |
1244 // check other tilings. | |
1245 PictureLayerTiling* tiling = | |
1246 tilings_->FindTilingWithResolution(HIGH_RESOLUTION); | |
1247 if (!tiling) | |
1248 return true; | |
1249 | |
1250 for (PictureLayerTiling::CoverageIterator iter(tiling, 1.f, rect); iter; | |
1251 ++iter) { | |
1252 const Tile* tile = *iter; | |
1253 // A null tile (i.e. missing recording) can just be skipped. | |
1254 // TODO(vmpstr): Verify this is true if we create tiles in raster | |
1255 // iterators. | |
1256 if (!tile) | |
1257 continue; | |
1258 | |
1259 // We can't check tile->required_for_activation, because that value might | |
1260 // be out of date. It is updated in the raster/eviction iterators. | |
1261 // TODO(vmpstr): Remove the comment once you can't access this information | |
1262 // from the tile. | |
1263 if ((tiling->*is_tile_required_callback)(tile) && !tile->IsReadyToDraw()) { | |
1264 TRACE_EVENT_INSTANT0("cc", "Tile required, but not ready to draw.", | |
1265 TRACE_EVENT_SCOPE_THREAD); | |
1266 return false; | |
1267 } | |
1268 } | |
1269 | |
1270 return true; | |
1271 } | |
1272 | |
1273 bool PictureLayerImpl::AllTilesRequiredForActivationAreReadyToDraw() const { | |
1274 if (!layer_tree_impl()->IsPendingTree()) | |
1275 return true; | |
1276 | |
1277 return AllTilesRequiredAreReadyToDraw( | |
1278 &PictureLayerTiling::IsTileRequiredForActivationIfVisible); | |
1279 } | |
1280 | |
1281 bool PictureLayerImpl::AllTilesRequiredForDrawAreReadyToDraw() const { | |
1282 if (!layer_tree_impl()->IsActiveTree()) | |
1283 return true; | |
1284 | |
1285 return AllTilesRequiredAreReadyToDraw( | |
1286 &PictureLayerTiling::IsTileRequiredForDrawIfVisible); | |
1287 } | |
1288 | |
1289 } // namespace cc | 1237 } // namespace cc |
OLD | NEW |