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

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

Issue 367833003: cc: Start using raster/eviction iterators. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: perf test fix Created 6 years, 5 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
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 <algorithm> 7 #include <algorithm>
8 #include <limits> 8 #include <limits>
9 9
10 #include "base/time/time.h" 10 #include "base/time/time.h"
(...skipping 28 matching lines...) Expand all
39 // Don't pre-rasterize on the GPU (except for kBackflingGuardDistancePixels in 39 // Don't pre-rasterize on the GPU (except for kBackflingGuardDistancePixels in
40 // TileManager::BinFromTilePriority). 40 // TileManager::BinFromTilePriority).
41 const float kGpuSkewportTargetTimeInFrames = 0.0f; 41 const float kGpuSkewportTargetTimeInFrames = 0.0f;
42 42
43 // Minimum width/height of a layer that would require analysis for tiles. 43 // Minimum width/height of a layer that would require analysis for tiles.
44 const int kMinDimensionsForAnalysis = 256; 44 const int kMinDimensionsForAnalysis = 256;
45 } // namespace 45 } // namespace
46 46
47 namespace cc { 47 namespace cc {
48 48
49 PairedPictureLayer::PairedPictureLayer()
50 : active_layer(NULL), pending_layer(NULL) {
51 }
52
53 PairedPictureLayer::~PairedPictureLayer() {
54 }
55
49 PictureLayerImpl::PictureLayerImpl(LayerTreeImpl* tree_impl, int id) 56 PictureLayerImpl::PictureLayerImpl(LayerTreeImpl* tree_impl, int id)
50 : LayerImpl(tree_impl, id), 57 : LayerImpl(tree_impl, id),
51 twin_layer_(NULL), 58 twin_layer_(NULL),
52 pile_(PicturePileImpl::Create()), 59 pile_(PicturePileImpl::Create()),
53 is_mask_(false), 60 is_mask_(false),
54 ideal_page_scale_(0.f), 61 ideal_page_scale_(0.f),
55 ideal_device_scale_(0.f), 62 ideal_device_scale_(0.f),
56 ideal_source_scale_(0.f), 63 ideal_source_scale_(0.f),
57 ideal_contents_scale_(0.f), 64 ideal_contents_scale_(0.f),
58 raster_page_scale_(0.f), 65 raster_page_scale_(0.f),
(...skipping 20 matching lines...) Expand all
79 LayerTreeImpl* tree_impl) { 86 LayerTreeImpl* tree_impl) {
80 return PictureLayerImpl::Create(tree_impl, id()).PassAs<LayerImpl>(); 87 return PictureLayerImpl::Create(tree_impl, id()).PassAs<LayerImpl>();
81 } 88 }
82 89
83 void PictureLayerImpl::PushPropertiesTo(LayerImpl* base_layer) { 90 void PictureLayerImpl::PushPropertiesTo(LayerImpl* base_layer) {
84 // It's possible this layer was never drawn or updated (e.g. because it was 91 // It's possible this layer was never drawn or updated (e.g. because it was
85 // a descendant of an opacity 0 layer). 92 // a descendant of an opacity 0 layer).
86 DoPostCommitInitializationIfNeeded(); 93 DoPostCommitInitializationIfNeeded();
87 PictureLayerImpl* layer_impl = static_cast<PictureLayerImpl*>(base_layer); 94 PictureLayerImpl* layer_impl = static_cast<PictureLayerImpl*>(base_layer);
88 95
89 // We have already synced the important bits from the the active layer, and
90 // we will soon swap out its tilings and use them for recycling. However,
91 // there are now tiles in this layer's tilings that were unref'd and replaced
92 // with new tiles (due to invalidation). This resets all active priorities on
93 // the to-be-recycled tiling to ensure replaced tiles don't linger and take
94 // memory (due to a stale 'active' priority).
95 if (layer_impl->tilings_)
96 layer_impl->tilings_->DidBecomeRecycled();
97
98 LayerImpl::PushPropertiesTo(base_layer); 96 LayerImpl::PushPropertiesTo(base_layer);
99 97
100 // When the pending tree pushes to the active tree, the pending twin 98 // When the pending tree pushes to the active tree, the pending twin
101 // disappears. 99 // disappears.
102 layer_impl->twin_layer_ = NULL; 100 layer_impl->twin_layer_ = NULL;
103 twin_layer_ = NULL; 101 twin_layer_ = NULL;
104 102
105 layer_impl->SetIsMask(is_mask_); 103 layer_impl->SetIsMask(is_mask_);
106 layer_impl->pile_ = pile_; 104 layer_impl->pile_ = pile_;
107 105
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 float width; 212 float width;
215 if (*iter && iter->IsReadyToDraw()) { 213 if (*iter && iter->IsReadyToDraw()) {
216 ManagedTileState::TileVersion::Mode mode = 214 ManagedTileState::TileVersion::Mode mode =
217 iter->GetTileVersionForDrawing().mode(); 215 iter->GetTileVersionForDrawing().mode();
218 if (mode == ManagedTileState::TileVersion::SOLID_COLOR_MODE) { 216 if (mode == ManagedTileState::TileVersion::SOLID_COLOR_MODE) {
219 color = DebugColors::SolidColorTileBorderColor(); 217 color = DebugColors::SolidColorTileBorderColor();
220 width = DebugColors::SolidColorTileBorderWidth(layer_tree_impl()); 218 width = DebugColors::SolidColorTileBorderWidth(layer_tree_impl());
221 } else if (mode == ManagedTileState::TileVersion::PICTURE_PILE_MODE) { 219 } else if (mode == ManagedTileState::TileVersion::PICTURE_PILE_MODE) {
222 color = DebugColors::PictureTileBorderColor(); 220 color = DebugColors::PictureTileBorderColor();
223 width = DebugColors::PictureTileBorderWidth(layer_tree_impl()); 221 width = DebugColors::PictureTileBorderWidth(layer_tree_impl());
224 } else if (iter->priority(ACTIVE_TREE).resolution == HIGH_RESOLUTION) { 222 } else if (iter.resolution() == HIGH_RESOLUTION) {
225 color = DebugColors::HighResTileBorderColor(); 223 color = DebugColors::HighResTileBorderColor();
226 width = DebugColors::HighResTileBorderWidth(layer_tree_impl()); 224 width = DebugColors::HighResTileBorderWidth(layer_tree_impl());
227 } else if (iter->priority(ACTIVE_TREE).resolution == LOW_RESOLUTION) { 225 } else if (iter.resolution() == LOW_RESOLUTION) {
228 color = DebugColors::LowResTileBorderColor(); 226 color = DebugColors::LowResTileBorderColor();
229 width = DebugColors::LowResTileBorderWidth(layer_tree_impl()); 227 width = DebugColors::LowResTileBorderWidth(layer_tree_impl());
230 } else if (iter->contents_scale() > max_contents_scale) { 228 } else if (iter->contents_scale() > max_contents_scale) {
231 color = DebugColors::ExtraHighResTileBorderColor(); 229 color = DebugColors::ExtraHighResTileBorderColor();
232 width = DebugColors::ExtraHighResTileBorderWidth(layer_tree_impl()); 230 width = DebugColors::ExtraHighResTileBorderWidth(layer_tree_impl());
233 } else { 231 } else {
234 color = DebugColors::ExtraLowResTileBorderColor(); 232 color = DebugColors::ExtraLowResTileBorderColor();
235 width = DebugColors::ExtraLowResTileBorderWidth(layer_tree_impl()); 233 width = DebugColors::ExtraLowResTileBorderWidth(layer_tree_impl());
236 } 234 }
237 } else { 235 } else {
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 } 354 }
357 355
358 append_quads_data->num_missing_tiles++; 356 append_quads_data->num_missing_tiles++;
359 append_quads_data->had_incomplete_tile = true; 357 append_quads_data->had_incomplete_tile = true;
360 append_quads_data->approximated_visible_content_area += 358 append_quads_data->approximated_visible_content_area +=
361 visible_geometry_rect.width() * visible_geometry_rect.height(); 359 visible_geometry_rect.width() * visible_geometry_rect.height();
362 ++missing_tile_count; 360 ++missing_tile_count;
363 continue; 361 continue;
364 } 362 }
365 363
366 if (iter->priority(ACTIVE_TREE).resolution != HIGH_RESOLUTION) { 364 if (iter.resolution() != HIGH_RESOLUTION) {
367 append_quads_data->approximated_visible_content_area += 365 append_quads_data->approximated_visible_content_area +=
368 visible_geometry_rect.width() * visible_geometry_rect.height(); 366 visible_geometry_rect.width() * visible_geometry_rect.height();
369 } 367 }
370 368
371 if (seen_tilings.empty() || seen_tilings.back() != iter.CurrentTiling()) 369 if (seen_tilings.empty() || seen_tilings.back() != iter.CurrentTiling())
372 seen_tilings.push_back(iter.CurrentTiling()); 370 seen_tilings.push_back(iter.CurrentTiling());
373 } 371 }
374 372
375 if (missing_tile_count) { 373 if (missing_tile_count) {
376 TRACE_EVENT_INSTANT2("cc", 374 TRACE_EVENT_INSTANT2("cc",
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 DCHECK(raster_source_scale_); 430 DCHECK(raster_source_scale_);
433 DCHECK(raster_contents_scale_); 431 DCHECK(raster_contents_scale_);
434 DCHECK(low_res_raster_contents_scale_); 432 DCHECK(low_res_raster_contents_scale_);
435 433
436 was_screen_space_transform_animating_ = 434 was_screen_space_transform_animating_ =
437 draw_properties().screen_space_transform_is_animating; 435 draw_properties().screen_space_transform_is_animating;
438 436
439 should_update_tile_priorities_ = true; 437 should_update_tile_priorities_ = true;
440 438
441 UpdateTilePriorities(occlusion_tracker); 439 UpdateTilePriorities(occlusion_tracker);
442
443 if (layer_tree_impl()->IsPendingTree())
444 MarkVisibleResourcesAsRequired();
445 } 440 }
446 441
447 void PictureLayerImpl::UpdateTilePriorities( 442 void PictureLayerImpl::UpdateTilePriorities(
448 const OcclusionTracker<LayerImpl>* occlusion_tracker) { 443 const OcclusionTracker<LayerImpl>* occlusion_tracker) {
449 TRACE_EVENT0("cc", "PictureLayerImpl::UpdateTilePriorities"); 444 TRACE_EVENT0("cc", "PictureLayerImpl::UpdateTilePriorities");
450 445
451 double current_frame_time_in_seconds = 446 double current_frame_time_in_seconds =
452 (layer_tree_impl()->CurrentFrameTimeTicks() - 447 (layer_tree_impl()->CurrentFrameTimeTicks() -
453 base::TimeTicks()).InSecondsF(); 448 base::TimeTicks()).InSecondsF();
454 449
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
597 layer_tree_impl()->begin_impl_frame_interval().InSecondsF() * 592 layer_tree_impl()->begin_impl_frame_interval().InSecondsF() *
598 layer_tree_impl()->settings().skewport_target_time_multiplier; 593 layer_tree_impl()->settings().skewport_target_time_multiplier;
599 } 594 }
600 595
601 int PictureLayerImpl::GetSkewportExtrapolationLimitInContentPixels() const { 596 int PictureLayerImpl::GetSkewportExtrapolationLimitInContentPixels() const {
602 return layer_tree_impl() 597 return layer_tree_impl()
603 ->settings() 598 ->settings()
604 .skewport_extrapolation_limit_in_content_pixels; 599 .skewport_extrapolation_limit_in_content_pixels;
605 } 600 }
606 601
602 bool PictureLayerImpl::RequiresHighResToDraw() const {
603 const PictureLayerImpl* layer = this;
604 if (GetTree() == PENDING_TREE)
605 layer = twin_layer_;
606
607 if (layer)
608 return layer->layer_tree_impl()->RequiresHighResToDraw();
609 return false;
610 }
611
607 gfx::Size PictureLayerImpl::CalculateTileSize( 612 gfx::Size PictureLayerImpl::CalculateTileSize(
608 const gfx::Size& content_bounds) const { 613 const gfx::Size& content_bounds) const {
609 if (is_mask_) { 614 if (is_mask_) {
610 int max_size = layer_tree_impl()->MaxTextureSize(); 615 int max_size = layer_tree_impl()->MaxTextureSize();
611 return gfx::Size( 616 return gfx::Size(
612 std::min(max_size, content_bounds.width()), 617 std::min(max_size, content_bounds.width()),
613 std::min(max_size, content_bounds.height())); 618 std::min(max_size, content_bounds.height()));
614 } 619 }
615 620
616 int max_texture_size = 621 int max_texture_size =
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
746 751
747 const ManagedTileState::TileVersion& tile_version = 752 const ManagedTileState::TileVersion& tile_version =
748 iter->GetTileVersionForDrawing(); 753 iter->GetTileVersionForDrawing();
749 if (!tile_version.IsReadyToDraw() || 754 if (!tile_version.IsReadyToDraw() ||
750 tile_version.mode() != ManagedTileState::TileVersion::RESOURCE_MODE) 755 tile_version.mode() != ManagedTileState::TileVersion::RESOURCE_MODE)
751 return 0; 756 return 0;
752 757
753 return tile_version.get_resource_id(); 758 return tile_version.get_resource_id();
754 } 759 }
755 760
756 void PictureLayerImpl::MarkVisibleResourcesAsRequired() const {
757 DCHECK(layer_tree_impl()->IsPendingTree());
758 DCHECK(ideal_contents_scale_);
759 DCHECK_GT(tilings_->num_tilings(), 0u);
760
761 // The goal of this function is to find the minimum set of tiles that need to
762 // be ready to draw in order to activate without flashing content from a
763 // higher res on the active tree to a lower res on the pending tree.
764
765 // First, early out for layers with no visible content.
766 if (visible_content_rect().IsEmpty())
767 return;
768
769 gfx::Rect rect(visible_content_rect());
770
771 float min_acceptable_scale =
772 std::min(raster_contents_scale_, ideal_contents_scale_);
773
774 if (PictureLayerImpl* twin = twin_layer_) {
775 float twin_min_acceptable_scale =
776 std::min(twin->ideal_contents_scale_, twin->raster_contents_scale_);
777 // Ignore 0 scale in case CalculateContentsScale() has never been
778 // called for active twin.
779 if (twin_min_acceptable_scale != 0.0f) {
780 min_acceptable_scale =
781 std::min(min_acceptable_scale, twin_min_acceptable_scale);
782 }
783 }
784
785 PictureLayerTiling* high_res = NULL;
786 PictureLayerTiling* low_res = NULL;
787
788 // First pass: ready to draw tiles in acceptable but non-ideal tilings are
789 // marked as required for activation so that their textures are not thrown
790 // away; any non-ready tiles are not marked as required.
791 Region missing_region = rect;
792 for (size_t i = 0; i < tilings_->num_tilings(); ++i) {
793 PictureLayerTiling* tiling = tilings_->tiling_at(i);
794 DCHECK(tiling->has_ever_been_updated());
795
796 if (tiling->resolution() == LOW_RESOLUTION) {
797 DCHECK(!low_res) << "There can only be one low res tiling";
798 low_res = tiling;
799 }
800 if (tiling->contents_scale() < min_acceptable_scale)
801 continue;
802 if (tiling->resolution() == HIGH_RESOLUTION) {
803 DCHECK(!high_res) << "There can only be one high res tiling";
804 high_res = tiling;
805 continue;
806 }
807 for (PictureLayerTiling::CoverageIterator iter(tiling,
808 contents_scale_x(),
809 rect);
810 iter;
811 ++iter) {
812 if (!*iter || !iter->IsReadyToDraw())
813 continue;
814
815 missing_region.Subtract(iter.geometry_rect());
816 iter->MarkRequiredForActivation();
817 }
818 }
819 DCHECK(high_res) << "There must be one high res tiling";
820
821 // If these pointers are null (because no twin, no matching tiling, or the
822 // simpification just below), then high res tiles will be required to fill any
823 // holes left by the first pass above. If the pointers are valid, then this
824 // layer is allowed to skip any tiles that are not ready on its twin.
825 const PictureLayerTiling* twin_high_res = NULL;
826 const PictureLayerTiling* twin_low_res = NULL;
827
828 if (twin_layer_) {
829 // As a simplification, only allow activating to skip twin tiles that the
830 // active layer is also missing when both this layer and its twin have
831 // "simple" sets of tilings: only 2 tilings (high and low) or only 1 high
832 // res tiling. This avoids having to iterate/track coverage of non-ideal
833 // tilings during the last draw call on the active layer.
834 if (tilings_->num_tilings() <= 2 &&
835 twin_layer_->tilings_->num_tilings() <= tilings_->num_tilings()) {
836 twin_low_res = low_res ? GetTwinTiling(low_res) : NULL;
837 twin_high_res = high_res ? GetTwinTiling(high_res) : NULL;
838 }
839
840 // If this layer and its twin have different transforms, then don't compare
841 // them and only allow activating to high res tiles, since tiles on each
842 // layer will be in different places on screen.
843 if (twin_layer_->layer_tree_impl()->RequiresHighResToDraw() ||
844 bounds() != twin_layer_->bounds() ||
845 draw_properties().screen_space_transform !=
846 twin_layer_->draw_properties().screen_space_transform) {
847 twin_high_res = NULL;
848 twin_low_res = NULL;
849 }
850 }
851
852 // As a second pass, mark as required any visible high res tiles not filled in
853 // by acceptable non-ideal tiles from the first pass.
854 if (MarkVisibleTilesAsRequired(
855 high_res, twin_high_res, contents_scale_x(), rect, missing_region)) {
856 // As an optional third pass, if a high res tile was skipped because its
857 // twin was also missing, then fall back to mark low res tiles as required
858 // in case the active twin is substituting those for missing high res
859 // content. Only suitable, when low res is enabled.
860 if (low_res) {
861 MarkVisibleTilesAsRequired(
862 low_res, twin_low_res, contents_scale_x(), rect, missing_region);
863 }
864 }
865 }
866
867 bool PictureLayerImpl::MarkVisibleTilesAsRequired(
868 PictureLayerTiling* tiling,
869 const PictureLayerTiling* optional_twin_tiling,
870 float contents_scale,
871 const gfx::Rect& rect,
872 const Region& missing_region) const {
873 bool twin_had_missing_tile = false;
874 for (PictureLayerTiling::CoverageIterator iter(tiling,
875 contents_scale,
876 rect);
877 iter;
878 ++iter) {
879 Tile* tile = *iter;
880 // A null tile (i.e. missing recording) can just be skipped.
881 if (!tile)
882 continue;
883
884 // If the tile is occluded, don't mark it as required for activation.
885 if (tile->is_occluded(PENDING_TREE))
886 continue;
887
888 // If the missing region doesn't cover it, this tile is fully
889 // covered by acceptable tiles at other scales.
890 if (!missing_region.Intersects(iter.geometry_rect()))
891 continue;
892
893 // If the twin tile doesn't exist (i.e. missing recording or so far away
894 // that it is outside the visible tile rect) or this tile is shared between
895 // with the twin, then this tile isn't required to prevent flashing.
896 if (optional_twin_tiling) {
897 Tile* twin_tile = optional_twin_tiling->TileAt(iter.i(), iter.j());
898 if (!twin_tile || twin_tile == tile) {
899 twin_had_missing_tile = true;
900 continue;
901 }
902 }
903
904 tile->MarkRequiredForActivation();
905 }
906 return twin_had_missing_tile;
907 }
908
909 void PictureLayerImpl::DoPostCommitInitialization() { 761 void PictureLayerImpl::DoPostCommitInitialization() {
910 DCHECK(needs_post_commit_initialization_); 762 DCHECK(needs_post_commit_initialization_);
911 DCHECK(layer_tree_impl()->IsPendingTree()); 763 DCHECK(layer_tree_impl()->IsPendingTree());
912 764
913 if (!tilings_) 765 if (!tilings_)
914 tilings_.reset(new PictureLayerTilingSet(this, bounds())); 766 tilings_.reset(new PictureLayerTilingSet(this, bounds()));
915 767
916 DCHECK(!twin_layer_); 768 DCHECK(!twin_layer_);
917 twin_layer_ = static_cast<PictureLayerImpl*>( 769 twin_layer_ = static_cast<PictureLayerImpl*>(
918 layer_tree_impl()->FindActiveTreeLayerById(id())); 770 layer_tree_impl()->FindActiveTreeLayerById(id()));
(...skipping 717 matching lines...) Expand 10 before | Expand all | Expand 10 after
1636 return iterator_index_ < iterators_.size(); 1488 return iterator_index_ < iterators_.size();
1637 } 1489 }
1638 1490
1639 bool PictureLayerImpl::LayerEvictionTileIterator::IsCorrectType( 1491 bool PictureLayerImpl::LayerEvictionTileIterator::IsCorrectType(
1640 PictureLayerTiling::TilingEvictionTileIterator* it) const { 1492 PictureLayerTiling::TilingEvictionTileIterator* it) const {
1641 return it->get_type() == iteration_stage_ && 1493 return it->get_type() == iteration_stage_ &&
1642 (**it)->required_for_activation() == required_for_activation_; 1494 (**it)->required_for_activation() == required_for_activation_;
1643 } 1495 }
1644 1496
1645 } // namespace cc 1497 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698