Chromium Code Reviews| 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 |
| 445 UpdateIdealScales(); | 448 UpdateIdealScales(); |
| 446 | 449 |
| 447 if (!raster_contents_scale_ || ShouldAdjustRasterScale()) { | 450 if (!raster_contents_scale_ || ShouldAdjustRasterScale()) { |
| 448 RecalculateRasterScales(); | 451 RecalculateRasterScales(); |
| 449 AddTilingsForRasterScale(); | 452 AddTilingsForRasterScale(); |
| 450 } | 453 } |
| 451 | 454 |
| 455 // Remove any non-ideal tilings that were not used last time we generated | |
| 456 // quads to save memory and processing time. Note that pending tree should | |
| 457 // only have one or two tilings (high and low res), so only clean up the | |
| 458 // active layer. Additionally, only clean up if AppendQuads didn't have | |
| 459 // a chance to do so, as inidicated by |need_tiling_cleanup_|. | |
|
danakj
2015/01/27 21:56:59
can you say why you only clean up if AppendQuads d
vmpstr
2015/01/27 22:53:58
You're right that it's okay, but you're also right
| |
| 460 if (need_tiling_cleanup_ && GetTree() == ACTIVE_TREE) | |
| 461 CleanUpTilingsOnActiveLayer(last_append_quads_tilings_); | |
| 462 | |
| 452 DCHECK(raster_page_scale_); | 463 DCHECK(raster_page_scale_); |
| 453 DCHECK(raster_device_scale_); | 464 DCHECK(raster_device_scale_); |
| 454 DCHECK(raster_source_scale_); | 465 DCHECK(raster_source_scale_); |
| 455 DCHECK(raster_contents_scale_); | 466 DCHECK(raster_contents_scale_); |
| 456 DCHECK(low_res_raster_contents_scale_); | 467 DCHECK(low_res_raster_contents_scale_); |
| 457 | 468 |
| 458 was_screen_space_transform_animating_ = | 469 was_screen_space_transform_animating_ = |
| 459 draw_properties().screen_space_transform_is_animating; | 470 draw_properties().screen_space_transform_is_animating; |
| 460 | 471 |
| 461 if (draw_transform_is_animating()) | 472 if (draw_transform_is_animating()) |
| 462 raster_source_->SetShouldAttemptToUseDistanceFieldText(); | 473 raster_source_->SetShouldAttemptToUseDistanceFieldText(); |
| 463 | |
| 464 return UpdateTilePriorities(occlusion_in_content_space); | 474 return UpdateTilePriorities(occlusion_in_content_space); |
| 465 } | 475 } |
| 466 | 476 |
| 467 bool PictureLayerImpl::UpdateTilePriorities( | 477 bool PictureLayerImpl::UpdateTilePriorities( |
| 468 const Occlusion& occlusion_in_content_space) { | 478 const Occlusion& occlusion_in_content_space) { |
| 469 DCHECK_IMPLIES(raster_source_->IsSolidColor(), tilings_->num_tilings() == 0); | 479 DCHECK_IMPLIES(raster_source_->IsSolidColor(), tilings_->num_tilings() == 0); |
| 470 | 480 |
| 471 double current_frame_time_in_seconds = | 481 double current_frame_time_in_seconds = |
| 472 (layer_tree_impl()->CurrentBeginFrameArgs().frame_time - | 482 (layer_tree_impl()->CurrentBeginFrameArgs().frame_time - |
| 473 base::TimeTicks()).InSecondsF(); | 483 base::TimeTicks()).InSecondsF(); |
| (...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 772 | 782 |
| 773 nearest_neighbor_ = nearest_neighbor; | 783 nearest_neighbor_ = nearest_neighbor; |
| 774 NoteLayerPropertyChanged(); | 784 NoteLayerPropertyChanged(); |
| 775 } | 785 } |
| 776 | 786 |
| 777 PictureLayerTiling* PictureLayerImpl::AddTiling(float contents_scale) { | 787 PictureLayerTiling* PictureLayerImpl::AddTiling(float contents_scale) { |
| 778 DCHECK(CanHaveTilings()); | 788 DCHECK(CanHaveTilings()); |
| 779 DCHECK_GE(contents_scale, MinimumContentsScale()); | 789 DCHECK_GE(contents_scale, MinimumContentsScale()); |
| 780 DCHECK_LE(contents_scale, MaximumContentsScale()); | 790 DCHECK_LE(contents_scale, MaximumContentsScale()); |
| 781 DCHECK(raster_source_->HasRecordings()); | 791 DCHECK(raster_source_->HasRecordings()); |
| 792 need_tiling_cleanup_ = true; | |
| 782 return tilings_->AddTiling(contents_scale, raster_source_); | 793 return tilings_->AddTiling(contents_scale, raster_source_); |
| 783 } | 794 } |
| 784 | 795 |
| 785 void PictureLayerImpl::RemoveAllTilings() { | 796 void PictureLayerImpl::RemoveAllTilings() { |
| 786 tilings_->RemoveAllTilings(); | 797 tilings_->RemoveAllTilings(); |
| 787 // If there are no tilings, then raster scales are no longer meaningful. | 798 // If there are no tilings, then raster scales are no longer meaningful. |
| 788 ResetRasterScale(); | 799 ResetRasterScale(); |
| 789 } | 800 } |
| 790 | 801 |
| 791 void PictureLayerImpl::AddTilingsForRasterScale() { | 802 void PictureLayerImpl::AddTilingsForRasterScale() { |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 985 float low_res_factor = | 996 float low_res_factor = |
| 986 layer_tree_impl()->settings().low_res_contents_scale_factor; | 997 layer_tree_impl()->settings().low_res_contents_scale_factor; |
| 987 low_res_raster_contents_scale_ = | 998 low_res_raster_contents_scale_ = |
| 988 std::max(raster_contents_scale_ * low_res_factor, MinimumContentsScale()); | 999 std::max(raster_contents_scale_ * low_res_factor, MinimumContentsScale()); |
| 989 DCHECK_LE(low_res_raster_contents_scale_, raster_contents_scale_); | 1000 DCHECK_LE(low_res_raster_contents_scale_, raster_contents_scale_); |
| 990 DCHECK_GE(low_res_raster_contents_scale_, MinimumContentsScale()); | 1001 DCHECK_GE(low_res_raster_contents_scale_, MinimumContentsScale()); |
| 991 DCHECK_LE(low_res_raster_contents_scale_, MaximumContentsScale()); | 1002 DCHECK_LE(low_res_raster_contents_scale_, MaximumContentsScale()); |
| 992 } | 1003 } |
| 993 | 1004 |
| 994 void PictureLayerImpl::CleanUpTilingsOnActiveLayer( | 1005 void PictureLayerImpl::CleanUpTilingsOnActiveLayer( |
| 995 std::vector<PictureLayerTiling*> used_tilings) { | 1006 const std::vector<PictureLayerTiling*>& used_tilings) { |
|
danakj
2015/01/27 21:56:59
why bother passing it in if it's a member on the c
vmpstr
2015/01/27 22:53:59
It makes it far easier to test this function.. I c
| |
| 996 DCHECK(layer_tree_impl()->IsActiveTree()); | 1007 DCHECK(layer_tree_impl()->IsActiveTree()); |
| 997 if (tilings_->num_tilings() == 0) | 1008 if (tilings_->num_tilings() == 0) |
| 998 return; | 1009 return; |
| 999 | 1010 |
| 1000 float min_acceptable_high_res_scale = std::min( | 1011 float min_acceptable_high_res_scale = std::min( |
| 1001 raster_contents_scale_, ideal_contents_scale_); | 1012 raster_contents_scale_, ideal_contents_scale_); |
| 1002 float max_acceptable_high_res_scale = std::max( | 1013 float max_acceptable_high_res_scale = std::max( |
| 1003 raster_contents_scale_, ideal_contents_scale_); | 1014 raster_contents_scale_, ideal_contents_scale_); |
| 1004 | 1015 |
| 1005 PictureLayerImpl* twin = GetPendingOrActiveTwinLayer(); | 1016 PictureLayerImpl* twin = GetPendingOrActiveTwinLayer(); |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 1017 PictureLayerTilingSet* recycled_twin_set = | 1028 PictureLayerTilingSet* recycled_twin_set = |
| 1018 recycled_twin ? recycled_twin->tilings_.get() : nullptr; | 1029 recycled_twin ? recycled_twin->tilings_.get() : nullptr; |
| 1019 | 1030 |
| 1020 tilings_->CleanUpTilings(min_acceptable_high_res_scale, | 1031 tilings_->CleanUpTilings(min_acceptable_high_res_scale, |
| 1021 max_acceptable_high_res_scale, used_tilings, | 1032 max_acceptable_high_res_scale, used_tilings, |
| 1022 layer_tree_impl()->create_low_res_tiling(), twin_set, | 1033 layer_tree_impl()->create_low_res_tiling(), twin_set, |
| 1023 recycled_twin_set); | 1034 recycled_twin_set); |
| 1024 | 1035 |
| 1025 if (recycled_twin_set && recycled_twin_set->num_tilings() == 0) | 1036 if (recycled_twin_set && recycled_twin_set->num_tilings() == 0) |
| 1026 recycled_twin->ResetRasterScale(); | 1037 recycled_twin->ResetRasterScale(); |
| 1038 need_tiling_cleanup_ = false; | |
| 1027 | 1039 |
| 1028 DCHECK_GT(tilings_->num_tilings(), 0u); | 1040 DCHECK_GT(tilings_->num_tilings(), 0u); |
| 1029 SanityCheckTilingState(); | 1041 SanityCheckTilingState(); |
| 1030 } | 1042 } |
| 1031 | 1043 |
| 1032 float PictureLayerImpl::MinimumContentsScale() const { | 1044 float PictureLayerImpl::MinimumContentsScale() const { |
| 1033 float setting_min = layer_tree_impl()->settings().minimum_contents_scale; | 1045 float setting_min = layer_tree_impl()->settings().minimum_contents_scale; |
| 1034 | 1046 |
| 1035 // If the contents scale is less than 1 / width (also for height), | 1047 // 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 | 1048 // 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 | 1292 |
| 1281 bool PictureLayerImpl::AllTilesRequiredForDrawAreReadyToDraw() const { | 1293 bool PictureLayerImpl::AllTilesRequiredForDrawAreReadyToDraw() const { |
| 1282 if (!layer_tree_impl()->IsActiveTree()) | 1294 if (!layer_tree_impl()->IsActiveTree()) |
| 1283 return true; | 1295 return true; |
| 1284 | 1296 |
| 1285 return AllTilesRequiredAreReadyToDraw( | 1297 return AllTilesRequiredAreReadyToDraw( |
| 1286 &PictureLayerTiling::IsTileRequiredForDrawIfVisible); | 1298 &PictureLayerTiling::IsTileRequiredForDrawIfVisible); |
| 1287 } | 1299 } |
| 1288 | 1300 |
| 1289 } // namespace cc | 1301 } // namespace cc |
| OLD | NEW |