Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(54)

Side by Side Diff: cc/layers/picture_layer_impl.cc

Issue 12954006: Let AreVisibleResourcesReady return correct value for PictureImageLayerImpl (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix nits Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « cc/layers/picture_layer_impl.h ('k') | cc/layers/picture_layer_impl_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "base/time.h" 7 #include "base/time.h"
8 #include "cc/base/math_util.h" 8 #include "cc/base/math_util.h"
9 #include "cc/base/util.h" 9 #include "cc/base/util.h"
10 #include "cc/debug/debug_colors.h" 10 #include "cc/debug/debug_colors.h"
(...skipping 11 matching lines...) Expand all
22 namespace { 22 namespace {
23 const float kMaxScaleRatioDuringPinch = 2.0f; 23 const float kMaxScaleRatioDuringPinch = 2.0f;
24 } 24 }
25 25
26 namespace cc { 26 namespace cc {
27 27
28 PictureLayerImpl::PictureLayerImpl(LayerTreeImpl* tree_impl, int id) 28 PictureLayerImpl::PictureLayerImpl(LayerTreeImpl* tree_impl, int id)
29 : LayerImpl(tree_impl, id), 29 : LayerImpl(tree_impl, id),
30 pile_(PicturePileImpl::Create(true)), 30 pile_(PicturePileImpl::Create(true)),
31 last_content_scale_(0), 31 last_content_scale_(0),
32 ideal_contents_scale_(0),
33 is_mask_(false), 32 is_mask_(false),
34 ideal_page_scale_(0.f), 33 ideal_page_scale_(0.f),
35 ideal_device_scale_(0.f), 34 ideal_device_scale_(0.f),
36 ideal_source_scale_(0.f), 35 ideal_source_scale_(0.f),
36 ideal_contents_scale_(0.f),
37 raster_page_scale_(0.f), 37 raster_page_scale_(0.f),
38 raster_device_scale_(0.f), 38 raster_device_scale_(0.f),
39 raster_source_scale_(0.f), 39 raster_source_scale_(0.f),
40 raster_contents_scale_(0.f),
41 low_res_raster_contents_scale_(0.f),
40 raster_source_scale_was_animating_(false), 42 raster_source_scale_was_animating_(false),
41 is_using_lcd_text_(true) { 43 is_using_lcd_text_(true) {
42 } 44 }
43 45
44 PictureLayerImpl::~PictureLayerImpl() { 46 PictureLayerImpl::~PictureLayerImpl() {
45 } 47 }
46 48
47 const char* PictureLayerImpl::LayerTypeAsString() const { 49 const char* PictureLayerImpl::LayerTypeAsString() const {
48 return "PictureLayer"; 50 return "PictureLayer";
49 } 51 }
(...skipping 23 matching lines...) Expand all
73 PictureLayerImpl* layer_impl = static_cast<PictureLayerImpl*>(base_layer); 75 PictureLayerImpl* layer_impl = static_cast<PictureLayerImpl*>(base_layer);
74 76
75 layer_impl->SetIsMask(is_mask_); 77 layer_impl->SetIsMask(is_mask_);
76 layer_impl->TransferTilingSet(tilings_.Pass()); 78 layer_impl->TransferTilingSet(tilings_.Pass());
77 layer_impl->pile_ = pile_; 79 layer_impl->pile_ = pile_;
78 pile_ = PicturePileImpl::Create(is_using_lcd_text_); 80 pile_ = PicturePileImpl::Create(is_using_lcd_text_);
79 81
80 layer_impl->raster_page_scale_ = raster_page_scale_; 82 layer_impl->raster_page_scale_ = raster_page_scale_;
81 layer_impl->raster_device_scale_ = raster_device_scale_; 83 layer_impl->raster_device_scale_ = raster_device_scale_;
82 layer_impl->raster_source_scale_ = raster_source_scale_; 84 layer_impl->raster_source_scale_ = raster_source_scale_;
85 layer_impl->raster_contents_scale_ = raster_contents_scale_;
86 layer_impl->low_res_raster_contents_scale_ = low_res_raster_contents_scale_;
83 layer_impl->is_using_lcd_text_ = is_using_lcd_text_; 87 layer_impl->is_using_lcd_text_ = is_using_lcd_text_;
84 } 88 }
85 89
86 90
87 void PictureLayerImpl::AppendQuads(QuadSink* quad_sink, 91 void PictureLayerImpl::AppendQuads(QuadSink* quad_sink,
88 AppendQuadsData* append_quads_data) { 92 AppendQuadsData* append_quads_data) {
89 const gfx::Rect& rect = visible_content_rect(); 93 const gfx::Rect& rect = visible_content_rect();
90 gfx::Rect content_rect(content_bounds()); 94 gfx::Rect content_rect(content_bounds());
91 95
92 SharedQuadState* shared_quad_state = 96 SharedQuadState* shared_quad_state =
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 return default_tile_size; 394 return default_tile_size;
391 } 395 }
392 396
393 void PictureLayerImpl::SyncFromActiveLayer() { 397 void PictureLayerImpl::SyncFromActiveLayer() {
394 DCHECK(layer_tree_impl()->IsPendingTree()); 398 DCHECK(layer_tree_impl()->IsPendingTree());
395 399
396 if (!DrawsContent()) { 400 if (!DrawsContent()) {
397 raster_page_scale_ = 0; 401 raster_page_scale_ = 0;
398 raster_device_scale_ = 0; 402 raster_device_scale_ = 0;
399 raster_source_scale_ = 0; 403 raster_source_scale_ = 0;
404 raster_contents_scale_ = 0;
405 low_res_raster_contents_scale_ = 0;
400 return; 406 return;
401 } 407 }
402 408
403 // If there is an active tree version of this layer, get a copy of its 409 // If there is an active tree version of this layer, get a copy of its
404 // tiles. This needs to be done last, after setting invalidation and the 410 // tiles. This needs to be done last, after setting invalidation and the
405 // pile. 411 // pile.
406 if (PictureLayerImpl* active_twin = ActiveTwin()) 412 if (PictureLayerImpl* active_twin = ActiveTwin())
407 SyncFromActiveLayer(active_twin); 413 SyncFromActiveLayer(active_twin);
408 } 414 }
409 415
410 void PictureLayerImpl::SyncFromActiveLayer(const PictureLayerImpl* other) { 416 void PictureLayerImpl::SyncFromActiveLayer(const PictureLayerImpl* other) {
411 raster_page_scale_ = other->raster_page_scale_; 417 raster_page_scale_ = other->raster_page_scale_;
412 raster_device_scale_ = other->raster_device_scale_; 418 raster_device_scale_ = other->raster_device_scale_;
413 raster_source_scale_ = other->raster_source_scale_; 419 raster_source_scale_ = other->raster_source_scale_;
420 raster_contents_scale_ = other->raster_contents_scale_;
421 low_res_raster_contents_scale_ = other->low_res_raster_contents_scale_;
414 is_using_lcd_text_ = other->is_using_lcd_text_; 422 is_using_lcd_text_ = other->is_using_lcd_text_;
415 423
416 // Add synthetic invalidations for any recordings that were dropped. As 424 // Add synthetic invalidations for any recordings that were dropped. As
417 // tiles are updated to point to this new pile, this will force the dropping 425 // tiles are updated to point to this new pile, this will force the dropping
418 // of tiles that can no longer be rastered. This is not ideal, but is a 426 // of tiles that can no longer be rastered. This is not ideal, but is a
419 // trade-off for memory (use the same pile as much as possible, by switching 427 // trade-off for memory (use the same pile as much as possible, by switching
420 // during DidBecomeActive) and for time (don't bother checking every tile 428 // during DidBecomeActive) and for time (don't bother checking every tile
421 // during activation to see if the new pile can still raster it). 429 // during activation to see if the new pile can still raster it).
422 // 430 //
423 // TODO(enne): Clean up this double loop. 431 // TODO(enne): Clean up this double loop.
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
487 } 495 }
488 return 0; 496 return 0;
489 } 497 }
490 498
491 bool PictureLayerImpl::AreVisibleResourcesReady() const { 499 bool PictureLayerImpl::AreVisibleResourcesReady() const {
492 DCHECK(layer_tree_impl()->IsPendingTree()); 500 DCHECK(layer_tree_impl()->IsPendingTree());
493 DCHECK(ideal_contents_scale_); 501 DCHECK(ideal_contents_scale_);
494 502
495 const gfx::Rect& rect = visible_content_rect(); 503 const gfx::Rect& rect = visible_content_rect();
496 504
497 float raster_contents_scale =
498 raster_page_scale_ *
499 raster_device_scale_ *
500 raster_source_scale_;
501
502 float min_acceptable_scale = 505 float min_acceptable_scale =
503 std::min(raster_contents_scale, ideal_contents_scale_); 506 std::min(raster_contents_scale_, ideal_contents_scale_);
504 507
505 TreePriority tree_priority = 508 TreePriority tree_priority =
506 layer_tree_impl()->tile_manager()->GlobalState().tree_priority; 509 layer_tree_impl()->tile_manager()->GlobalState().tree_priority;
507 bool should_force_uploads = 510 bool should_force_uploads =
508 tree_priority != SMOOTHNESS_TAKES_PRIORITY && 511 tree_priority != SMOOTHNESS_TAKES_PRIORITY &&
509 layer_tree_impl()->animationRegistrar()-> 512 layer_tree_impl()->animationRegistrar()->
510 active_animation_controllers().empty(); 513 active_animation_controllers().empty();
511 514
512 if (PictureLayerImpl* twin = ActiveTwin()) { 515 if (PictureLayerImpl* twin = ActiveTwin()) {
513 float twin_raster_contents_scale =
514 twin->raster_page_scale_ *
515 twin->raster_device_scale_ *
516 twin->raster_source_scale_;
517
518 min_acceptable_scale = std::min( 516 min_acceptable_scale = std::min(
519 min_acceptable_scale, 517 min_acceptable_scale,
520 std::min(twin->ideal_contents_scale_, twin_raster_contents_scale)); 518 std::min(twin->ideal_contents_scale_, twin->raster_contents_scale_));
521 } 519 }
522 520
523 Region missing_region = rect; 521 Region missing_region = rect;
524 for (size_t i = 0; i < tilings_->num_tilings(); ++i) { 522 for (size_t i = 0; i < tilings_->num_tilings(); ++i) {
525 PictureLayerTiling* tiling = tilings_->tiling_at(i); 523 PictureLayerTiling* tiling = tilings_->tiling_at(i);
526 524
527 if (tiling->contents_scale() < min_acceptable_scale) 525 if (tiling->contents_scale() < min_acceptable_scale)
528 continue; 526 continue;
529 527
530 for (PictureLayerTiling::Iterator iter(tiling, contents_scale_x(), rect); 528 for (PictureLayerTiling::Iterator iter(tiling, contents_scale_x(), rect);
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
597 595
598 void PictureLayerImpl::ManageTilings(bool animating_transform_to_screen) { 596 void PictureLayerImpl::ManageTilings(bool animating_transform_to_screen) {
599 DCHECK(ideal_contents_scale_); 597 DCHECK(ideal_contents_scale_);
600 DCHECK(ideal_page_scale_); 598 DCHECK(ideal_page_scale_);
601 DCHECK(ideal_device_scale_); 599 DCHECK(ideal_device_scale_);
602 DCHECK(ideal_source_scale_); 600 DCHECK(ideal_source_scale_);
603 601
604 if (pile_->recorded_region().IsEmpty()) 602 if (pile_->recorded_region().IsEmpty())
605 return; 603 return;
606 604
607 bool is_active_layer = layer_tree_impl()->IsActiveTree(); 605 bool change_target_tiling =
608 bool is_pinching = layer_tree_impl()->PinchGestureActive(); 606 !raster_page_scale_ || !raster_device_scale_ || !raster_source_scale_ ||
607 ShouldAdjustRasterScale(animating_transform_to_screen);
609 608
610 bool change_target_tiling = false; 609 if (layer_tree_impl()->IsActiveTree()) {
611 610 // Store the value for the next time ShouldAdjustRasterScale is called.
612 if (!raster_page_scale_ || !raster_device_scale_ || !raster_source_scale_)
613 change_target_tiling = true;
614
615 // TODO(danakj): Adjust raster_source_scale_ closer to ideal_source_scale_ at
616 // a throttled rate. Possibly make use of invalidation_.IsEmpty() on pending
617 // tree. This will allow CSS scale changes to get re-rastered at an
618 // appropriate rate.
619
620 if (is_active_layer) {
621 if (raster_source_scale_was_animating_ && !animating_transform_to_screen)
622 change_target_tiling = true;
623 raster_source_scale_was_animating_ = animating_transform_to_screen; 611 raster_source_scale_was_animating_ = animating_transform_to_screen;
624 } 612 }
625 613
626 if (is_active_layer && is_pinching && raster_page_scale_) {
627 // If the page scale diverges too far during pinch, change raster target to
628 // the current page scale.
629 float ratio = PositiveRatio(ideal_page_scale_, raster_page_scale_);
630 if (ratio >= kMaxScaleRatioDuringPinch)
631 change_target_tiling = true;
632 }
633
634 if (!is_pinching) {
635 // When not pinching, match the ideal page scale factor.
636 if (raster_page_scale_ != ideal_page_scale_)
637 change_target_tiling = true;
638 }
639
640 // Always match the ideal device scale factor.
641 if (raster_device_scale_ != ideal_device_scale_)
642 change_target_tiling = true;
643
644 if (!change_target_tiling) 614 if (!change_target_tiling)
645 return; 615 return;
646 616
647 raster_page_scale_ = ideal_page_scale_; 617 raster_page_scale_ = ideal_page_scale_;
648 raster_device_scale_ = ideal_device_scale_; 618 raster_device_scale_ = ideal_device_scale_;
649 raster_source_scale_ = ideal_source_scale_; 619 raster_source_scale_ = ideal_source_scale_;
650 620
651 float raster_contents_scale;
652 float low_res_raster_contents_scale;
653 CalculateRasterContentsScale(animating_transform_to_screen, 621 CalculateRasterContentsScale(animating_transform_to_screen,
654 &raster_contents_scale, 622 &raster_contents_scale_,
655 &low_res_raster_contents_scale); 623 &low_res_raster_contents_scale_);
656 624
657 PictureLayerTiling* high_res = NULL; 625 PictureLayerTiling* high_res = NULL;
658 PictureLayerTiling* low_res = NULL; 626 PictureLayerTiling* low_res = NULL;
659 627
660 for (size_t i = 0; i < tilings_->num_tilings(); ++i) { 628 for (size_t i = 0; i < tilings_->num_tilings(); ++i) {
661 PictureLayerTiling* tiling = tilings_->tiling_at(i); 629 PictureLayerTiling* tiling = tilings_->tiling_at(i);
662 if (tiling->contents_scale() == raster_contents_scale) 630 if (tiling->contents_scale() == raster_contents_scale_)
663 high_res = tiling; 631 high_res = tiling;
664 if (tiling->contents_scale() == low_res_raster_contents_scale) 632 if (tiling->contents_scale() == low_res_raster_contents_scale_)
665 low_res = tiling; 633 low_res = tiling;
666 634
667 // Reset all tilings to non-ideal until the end of this function. 635 // Reset all tilings to non-ideal until the end of this function.
668 tiling->set_resolution(NON_IDEAL_RESOLUTION); 636 tiling->set_resolution(NON_IDEAL_RESOLUTION);
669 } 637 }
670 638
671 if (!high_res) { 639 if (!high_res) {
672 high_res = AddTiling(raster_contents_scale); 640 high_res = AddTiling(raster_contents_scale_);
673 if (raster_contents_scale == low_res_raster_contents_scale) 641 if (raster_contents_scale_ == low_res_raster_contents_scale_)
674 low_res = high_res; 642 low_res = high_res;
675 } 643 }
676 if (!low_res && low_res != high_res) 644 if (!low_res && low_res != high_res)
677 low_res = AddTiling(low_res_raster_contents_scale); 645 low_res = AddTiling(low_res_raster_contents_scale_);
678 646
679 if (high_res) 647 if (high_res)
680 high_res->set_resolution(HIGH_RESOLUTION); 648 high_res->set_resolution(HIGH_RESOLUTION);
681 if (low_res && low_res != high_res) 649 if (low_res && low_res != high_res)
682 low_res->set_resolution(LOW_RESOLUTION); 650 low_res->set_resolution(LOW_RESOLUTION);
683 } 651 }
684 652
653 bool PictureLayerImpl::ShouldAdjustRasterScale(
654 bool animating_transform_to_screen) const {
655 // TODO(danakj): Adjust raster source scale closer to ideal source scale at
656 // a throttled rate. Possibly make use of invalidation_.IsEmpty() on pending
657 // tree. This will allow CSS scale changes to get re-rastered at an
658 // appropriate rate.
659
660 bool is_active_layer = layer_tree_impl()->IsActiveTree();
661 if (is_active_layer && raster_source_scale_was_animating_ &&
662 !animating_transform_to_screen)
663 return true;
664
665 bool is_pinching = layer_tree_impl()->PinchGestureActive();
666 if (is_active_layer && is_pinching && raster_page_scale_) {
667 // If the page scale diverges too far during pinch, change raster target to
668 // the current page scale.
669 float ratio = PositiveRatio(ideal_page_scale_, raster_page_scale_);
670 if (ratio >= kMaxScaleRatioDuringPinch)
671 return true;
672 }
673
674 if (!is_pinching) {
675 // When not pinching, match the ideal page scale factor.
676 if (raster_page_scale_ != ideal_page_scale_)
677 return true;
678 }
679
680 // Always match the ideal device scale factor.
681 if (raster_device_scale_ != ideal_device_scale_)
682 return true;
683
684 return false;
685 }
686
685 void PictureLayerImpl::CalculateRasterContentsScale( 687 void PictureLayerImpl::CalculateRasterContentsScale(
686 bool animating_transform_to_screen, 688 bool animating_transform_to_screen,
687 float* raster_contents_scale, 689 float* raster_contents_scale,
688 float* low_res_raster_contents_scale) { 690 float* low_res_raster_contents_scale) const {
689 *raster_contents_scale = ideal_contents_scale_; 691 *raster_contents_scale = ideal_contents_scale_;
690 692
691 // Don't allow animating CSS scales to drop below 1. 693 // Don't allow animating CSS scales to drop below 1.
692 if (animating_transform_to_screen) { 694 if (animating_transform_to_screen) {
693 *raster_contents_scale = std::max( 695 *raster_contents_scale = std::max(
694 *raster_contents_scale, 1.f * ideal_page_scale_ * ideal_device_scale_); 696 *raster_contents_scale, 1.f * ideal_page_scale_ * ideal_device_scale_);
695 } 697 }
696 698
697 float low_res_factor = 699 float low_res_factor =
698 layer_tree_impl()->settings().low_res_contents_scale_factor; 700 layer_tree_impl()->settings().low_res_contents_scale_factor;
699 *low_res_raster_contents_scale = std::max( 701 *low_res_raster_contents_scale = std::max(
700 *raster_contents_scale * low_res_factor, 702 *raster_contents_scale * low_res_factor,
701 MinimumContentsScale()); 703 MinimumContentsScale());
702 } 704 }
703 705
704 void PictureLayerImpl::CleanUpTilingsOnActiveLayer( 706 void PictureLayerImpl::CleanUpTilingsOnActiveLayer(
705 std::vector<PictureLayerTiling*> used_tilings) { 707 std::vector<PictureLayerTiling*> used_tilings) {
706 DCHECK(layer_tree_impl()->IsActiveTree()); 708 DCHECK(layer_tree_impl()->IsActiveTree());
707 709
708 float raster_contents_scale =
709 raster_page_scale_ * raster_device_scale_ * raster_source_scale_;
710
711 float min_acceptable_high_res_scale = std::min( 710 float min_acceptable_high_res_scale = std::min(
712 raster_contents_scale, ideal_contents_scale_); 711 raster_contents_scale_, ideal_contents_scale_);
713 float max_acceptable_high_res_scale = std::max( 712 float max_acceptable_high_res_scale = std::max(
714 raster_contents_scale, ideal_contents_scale_); 713 raster_contents_scale_, ideal_contents_scale_);
715 714
716 PictureLayerImpl* twin = PendingTwin(); 715 PictureLayerImpl* twin = PendingTwin();
717 if (twin) { 716 if (twin) {
718 float twin_raster_contents_scale =
719 twin->raster_page_scale_ *
720 twin->raster_device_scale_ *
721 twin->raster_source_scale_;
722
723 min_acceptable_high_res_scale = std::min( 717 min_acceptable_high_res_scale = std::min(
724 min_acceptable_high_res_scale, 718 min_acceptable_high_res_scale,
725 std::min(twin_raster_contents_scale, twin->ideal_contents_scale_)); 719 std::min(twin->raster_contents_scale_, twin->ideal_contents_scale_));
726 max_acceptable_high_res_scale = std::max( 720 max_acceptable_high_res_scale = std::max(
727 max_acceptable_high_res_scale, 721 max_acceptable_high_res_scale,
728 std::max(twin_raster_contents_scale, twin->ideal_contents_scale_)); 722 std::max(twin->raster_contents_scale_, twin->ideal_contents_scale_));
729 } 723 }
730 724
731 float low_res_factor = 725 float low_res_factor =
732 layer_tree_impl()->settings().low_res_contents_scale_factor; 726 layer_tree_impl()->settings().low_res_contents_scale_factor;
733 727
734 float min_acceptable_low_res_scale = 728 float min_acceptable_low_res_scale =
735 low_res_factor * min_acceptable_high_res_scale; 729 low_res_factor * min_acceptable_high_res_scale;
736 float max_acceptable_low_res_scale = 730 float max_acceptable_low_res_scale =
737 low_res_factor * max_acceptable_high_res_scale; 731 low_res_factor * max_acceptable_high_res_scale;
738 732
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
846 scoped_ptr<base::Value> PictureLayerImpl::AsValue() const { 840 scoped_ptr<base::Value> PictureLayerImpl::AsValue() const {
847 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue()); 841 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue());
848 LayerImpl::AsValueInto(state.get()); 842 LayerImpl::AsValueInto(state.get());
849 843
850 state->SetDouble("ideal_contents_scale", ideal_contents_scale_); 844 state->SetDouble("ideal_contents_scale", ideal_contents_scale_);
851 state->Set("tilings", tilings_->AsValue().release()); 845 state->Set("tilings", tilings_->AsValue().release());
852 return state.PassAs<base::Value>(); 846 return state.PassAs<base::Value>();
853 } 847 }
854 848
855 } // namespace cc 849 } // namespace cc
OLDNEW
« no previous file with comments | « cc/layers/picture_layer_impl.h ('k') | cc/layers/picture_layer_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698