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> |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
77 ideal_contents_scale_(0.f), | 77 ideal_contents_scale_(0.f), |
78 raster_page_scale_(0.f), | 78 raster_page_scale_(0.f), |
79 raster_device_scale_(0.f), | 79 raster_device_scale_(0.f), |
80 raster_source_scale_(0.f), | 80 raster_source_scale_(0.f), |
81 raster_contents_scale_(0.f), | 81 raster_contents_scale_(0.f), |
82 low_res_raster_contents_scale_(0.f), | 82 low_res_raster_contents_scale_(0.f), |
83 raster_source_scale_is_fixed_(false), | 83 raster_source_scale_is_fixed_(false), |
84 was_screen_space_transform_animating_(false), | 84 was_screen_space_transform_animating_(false), |
85 only_used_low_res_last_append_quads_(false), | 85 only_used_low_res_last_append_quads_(false), |
86 is_mask_(is_mask), | 86 is_mask_(is_mask), |
87 nearest_neighbor_(false) { | 87 nearest_neighbor_(false), |
88 need_tiling_cleanup_(false) { | |
88 layer_tree_impl()->RegisterPictureLayerImpl(this); | 89 layer_tree_impl()->RegisterPictureLayerImpl(this); |
89 } | 90 } |
90 | 91 |
91 PictureLayerImpl::~PictureLayerImpl() { | 92 PictureLayerImpl::~PictureLayerImpl() { |
92 if (twin_layer_) | 93 if (twin_layer_) |
93 twin_layer_->twin_layer_ = nullptr; | 94 twin_layer_->twin_layer_ = nullptr; |
94 layer_tree_impl()->UnregisterPictureLayerImpl(this); | 95 layer_tree_impl()->UnregisterPictureLayerImpl(this); |
95 } | 96 } |
96 | 97 |
97 const char* PictureLayerImpl::LayerTypeAsString() const { | 98 const char* PictureLayerImpl::LayerTypeAsString() const { |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
269 debug_border_quad->SetNew(shared_quad_state, | 270 debug_border_quad->SetNew(shared_quad_state, |
270 geometry_rect, | 271 geometry_rect, |
271 visible_geometry_rect, | 272 visible_geometry_rect, |
272 color, | 273 color, |
273 width); | 274 width); |
274 } | 275 } |
275 } | 276 } |
276 | 277 |
277 // Keep track of the tilings that were used so that tilings that are | 278 // Keep track of the tilings that were used so that tilings that are |
278 // unused can be considered for removal. | 279 // unused can be considered for removal. |
279 std::vector<PictureLayerTiling*> seen_tilings; | 280 last_append_quads_tilings_.clear(); |
280 | 281 |
281 // Ignore missing tiles outside of viewport for tile priority. This is | 282 // Ignore missing tiles outside of viewport for tile priority. This is |
282 // normally the same as draw viewport but can be independently overridden by | 283 // normally the same as draw viewport but can be independently overridden by |
283 // embedders like Android WebView with SetExternalDrawConstraints. | 284 // embedders like Android WebView with SetExternalDrawConstraints. |
284 gfx::Rect scaled_viewport_for_tile_priority = gfx::ScaleToEnclosingRect( | 285 gfx::Rect scaled_viewport_for_tile_priority = gfx::ScaleToEnclosingRect( |
285 viewport_rect_for_tile_priority_in_content_space_, max_contents_scale); | 286 viewport_rect_for_tile_priority_in_content_space_, max_contents_scale); |
286 | 287 |
287 size_t missing_tile_count = 0u; | 288 size_t missing_tile_count = 0u; |
288 size_t on_demand_missing_tile_count = 0u; | 289 size_t on_demand_missing_tile_count = 0u; |
289 only_used_low_res_last_append_quads_ = true; | 290 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) { | 397 if (iter.resolution() != HIGH_RESOLUTION) { |
397 append_quads_data->approximated_visible_content_area += | 398 append_quads_data->approximated_visible_content_area += |
398 visible_geometry_rect.width() * visible_geometry_rect.height(); | 399 visible_geometry_rect.width() * visible_geometry_rect.height(); |
399 } | 400 } |
400 | 401 |
401 // If we have a draw quad, but it's not low resolution, then | 402 // 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. | 403 // mark that we've used something other than low res to draw. |
403 if (iter.resolution() != LOW_RESOLUTION) | 404 if (iter.resolution() != LOW_RESOLUTION) |
404 only_used_low_res_last_append_quads_ = false; | 405 only_used_low_res_last_append_quads_ = false; |
405 | 406 |
406 if (seen_tilings.empty() || seen_tilings.back() != iter.CurrentTiling()) | 407 if (last_append_quads_tilings_.empty() || |
407 seen_tilings.push_back(iter.CurrentTiling()); | 408 last_append_quads_tilings_.back() != iter.CurrentTiling()) { |
409 last_append_quads_tilings_.push_back(iter.CurrentTiling()); | |
410 } | |
408 } | 411 } |
409 | 412 |
410 if (missing_tile_count) { | 413 if (missing_tile_count) { |
411 TRACE_EVENT_INSTANT2("cc", | 414 TRACE_EVENT_INSTANT2("cc", |
412 "PictureLayerImpl::AppendQuads checkerboard", | 415 "PictureLayerImpl::AppendQuads checkerboard", |
413 TRACE_EVENT_SCOPE_THREAD, | 416 TRACE_EVENT_SCOPE_THREAD, |
414 "missing_tile_count", | 417 "missing_tile_count", |
415 missing_tile_count, | 418 missing_tile_count, |
416 "on_demand_missing_tile_count", | 419 "on_demand_missing_tile_count", |
417 on_demand_missing_tile_count); | 420 on_demand_missing_tile_count); |
418 } | 421 } |
419 | 422 |
420 // Aggressively remove any tilings that are not seen to save memory. Note | 423 // 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 | 424 // 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 | 425 // better scheme would be to maintain a tighter visible_content_rect for the |
423 // finer tilings. | 426 // finer tilings. |
424 CleanUpTilingsOnActiveLayer(seen_tilings); | 427 CleanUpTilingsOnActiveLayer(last_append_quads_tilings_); |
425 } | 428 } |
426 | 429 |
427 bool PictureLayerImpl::UpdateTiles(const Occlusion& occlusion_in_content_space, | 430 bool PictureLayerImpl::UpdateTiles(const Occlusion& occlusion_in_content_space, |
428 bool resourceless_software_draw) { | 431 bool resourceless_software_draw) { |
429 DCHECK_EQ(1.f, contents_scale_x()); | 432 DCHECK_EQ(1.f, contents_scale_x()); |
430 DCHECK_EQ(1.f, contents_scale_y()); | 433 DCHECK_EQ(1.f, contents_scale_y()); |
431 | 434 |
432 if (!resourceless_software_draw) { | 435 if (!resourceless_software_draw) { |
433 visible_rect_for_tile_priority_ = visible_content_rect(); | 436 visible_rect_for_tile_priority_ = visible_content_rect(); |
434 } | 437 } |
435 | 438 |
436 if (!CanHaveTilings()) { | 439 if (!CanHaveTilings()) { |
437 ideal_page_scale_ = 0.f; | 440 ideal_page_scale_ = 0.f; |
438 ideal_device_scale_ = 0.f; | 441 ideal_device_scale_ = 0.f; |
439 ideal_contents_scale_ = 0.f; | 442 ideal_contents_scale_ = 0.f; |
440 ideal_source_scale_ = 0.f; | 443 ideal_source_scale_ = 0.f; |
441 SanityCheckTilingState(); | 444 SanityCheckTilingState(); |
442 return false; | 445 return false; |
443 } | 446 } |
444 | 447 |
448 // Remove any non-ideal tilings that were not used last time we generated | |
449 // quads to save memory and processing time. Note that pending tree should | |
450 // only have one or two tilings (high and low res), so only clean up the | |
451 // active layer. Additionally, only clean up if AppendQuads didn't have | |
danakj
2015/01/27 23:02:28
This is just an optimization because it wouldn't a
| |
452 // a chance to do so, as inidicated by |need_tiling_cleanup_|. That is to say, | |
453 // if AppendQuads cleaned up tilings, then |need_tiling_cleanup_| would be set | |
454 // to false. | |
455 if (need_tiling_cleanup_ && 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 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
772 | 784 |
773 nearest_neighbor_ = nearest_neighbor; | 785 nearest_neighbor_ = nearest_neighbor; |
774 NoteLayerPropertyChanged(); | 786 NoteLayerPropertyChanged(); |
775 } | 787 } |
776 | 788 |
777 PictureLayerTiling* PictureLayerImpl::AddTiling(float contents_scale) { | 789 PictureLayerTiling* PictureLayerImpl::AddTiling(float contents_scale) { |
778 DCHECK(CanHaveTilings()); | 790 DCHECK(CanHaveTilings()); |
779 DCHECK_GE(contents_scale, MinimumContentsScale()); | 791 DCHECK_GE(contents_scale, MinimumContentsScale()); |
780 DCHECK_LE(contents_scale, MaximumContentsScale()); | 792 DCHECK_LE(contents_scale, MaximumContentsScale()); |
781 DCHECK(raster_source_->HasRecordings()); | 793 DCHECK(raster_source_->HasRecordings()); |
794 need_tiling_cleanup_ = true; | |
danakj
2015/01/27 23:02:28
What about when we UpdateRasterSource and clone th
| |
782 return tilings_->AddTiling(contents_scale, raster_source_); | 795 return tilings_->AddTiling(contents_scale, raster_source_); |
783 } | 796 } |
784 | 797 |
785 void PictureLayerImpl::RemoveAllTilings() { | 798 void PictureLayerImpl::RemoveAllTilings() { |
786 tilings_->RemoveAllTilings(); | 799 tilings_->RemoveAllTilings(); |
787 // If there are no tilings, then raster scales are no longer meaningful. | 800 // If there are no tilings, then raster scales are no longer meaningful. |
788 ResetRasterScale(); | 801 ResetRasterScale(); |
789 } | 802 } |
790 | 803 |
791 void PictureLayerImpl::AddTilingsForRasterScale() { | 804 void PictureLayerImpl::AddTilingsForRasterScale() { |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
985 float low_res_factor = | 998 float low_res_factor = |
986 layer_tree_impl()->settings().low_res_contents_scale_factor; | 999 layer_tree_impl()->settings().low_res_contents_scale_factor; |
987 low_res_raster_contents_scale_ = | 1000 low_res_raster_contents_scale_ = |
988 std::max(raster_contents_scale_ * low_res_factor, MinimumContentsScale()); | 1001 std::max(raster_contents_scale_ * low_res_factor, MinimumContentsScale()); |
989 DCHECK_LE(low_res_raster_contents_scale_, raster_contents_scale_); | 1002 DCHECK_LE(low_res_raster_contents_scale_, raster_contents_scale_); |
990 DCHECK_GE(low_res_raster_contents_scale_, MinimumContentsScale()); | 1003 DCHECK_GE(low_res_raster_contents_scale_, MinimumContentsScale()); |
991 DCHECK_LE(low_res_raster_contents_scale_, MaximumContentsScale()); | 1004 DCHECK_LE(low_res_raster_contents_scale_, MaximumContentsScale()); |
992 } | 1005 } |
993 | 1006 |
994 void PictureLayerImpl::CleanUpTilingsOnActiveLayer( | 1007 void PictureLayerImpl::CleanUpTilingsOnActiveLayer( |
995 std::vector<PictureLayerTiling*> used_tilings) { | 1008 const std::vector<PictureLayerTiling*>& used_tilings) { |
996 DCHECK(layer_tree_impl()->IsActiveTree()); | 1009 DCHECK(layer_tree_impl()->IsActiveTree()); |
997 if (tilings_->num_tilings() == 0) | 1010 if (tilings_->num_tilings() == 0) |
998 return; | 1011 return; |
999 | 1012 |
1000 float min_acceptable_high_res_scale = std::min( | 1013 float min_acceptable_high_res_scale = std::min( |
1001 raster_contents_scale_, ideal_contents_scale_); | 1014 raster_contents_scale_, ideal_contents_scale_); |
1002 float max_acceptable_high_res_scale = std::max( | 1015 float max_acceptable_high_res_scale = std::max( |
1003 raster_contents_scale_, ideal_contents_scale_); | 1016 raster_contents_scale_, ideal_contents_scale_); |
1004 | 1017 |
1005 PictureLayerImpl* twin = GetPendingOrActiveTwinLayer(); | 1018 PictureLayerImpl* twin = GetPendingOrActiveTwinLayer(); |
(...skipping 11 matching lines...) Expand all Loading... | |
1017 PictureLayerTilingSet* recycled_twin_set = | 1030 PictureLayerTilingSet* recycled_twin_set = |
1018 recycled_twin ? recycled_twin->tilings_.get() : nullptr; | 1031 recycled_twin ? recycled_twin->tilings_.get() : nullptr; |
1019 | 1032 |
1020 tilings_->CleanUpTilings(min_acceptable_high_res_scale, | 1033 tilings_->CleanUpTilings(min_acceptable_high_res_scale, |
1021 max_acceptable_high_res_scale, used_tilings, | 1034 max_acceptable_high_res_scale, used_tilings, |
1022 layer_tree_impl()->create_low_res_tiling(), twin_set, | 1035 layer_tree_impl()->create_low_res_tiling(), twin_set, |
1023 recycled_twin_set); | 1036 recycled_twin_set); |
1024 | 1037 |
1025 if (recycled_twin_set && recycled_twin_set->num_tilings() == 0) | 1038 if (recycled_twin_set && recycled_twin_set->num_tilings() == 0) |
1026 recycled_twin->ResetRasterScale(); | 1039 recycled_twin->ResetRasterScale(); |
1040 need_tiling_cleanup_ = false; | |
1027 | 1041 |
1028 DCHECK_GT(tilings_->num_tilings(), 0u); | 1042 DCHECK_GT(tilings_->num_tilings(), 0u); |
1029 SanityCheckTilingState(); | 1043 SanityCheckTilingState(); |
1030 } | 1044 } |
1031 | 1045 |
1032 float PictureLayerImpl::MinimumContentsScale() const { | 1046 float PictureLayerImpl::MinimumContentsScale() const { |
1033 float setting_min = layer_tree_impl()->settings().minimum_contents_scale; | 1047 float setting_min = layer_tree_impl()->settings().minimum_contents_scale; |
1034 | 1048 |
1035 // If the contents scale is less than 1 / width (also for height), | 1049 // If the contents scale is less than 1 / width (also for height), |
1036 // then it will end up having less than one pixel of content in that | 1050 // then it will end up having less than one pixel of content in that |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1280 | 1294 |
1281 bool PictureLayerImpl::AllTilesRequiredForDrawAreReadyToDraw() const { | 1295 bool PictureLayerImpl::AllTilesRequiredForDrawAreReadyToDraw() const { |
1282 if (!layer_tree_impl()->IsActiveTree()) | 1296 if (!layer_tree_impl()->IsActiveTree()) |
1283 return true; | 1297 return true; |
1284 | 1298 |
1285 return AllTilesRequiredAreReadyToDraw( | 1299 return AllTilesRequiredAreReadyToDraw( |
1286 &PictureLayerTiling::IsTileRequiredForDrawIfVisible); | 1300 &PictureLayerTiling::IsTileRequiredForDrawIfVisible); |
1287 } | 1301 } |
1288 | 1302 |
1289 } // namespace cc | 1303 } // namespace cc |
OLD | NEW |