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

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: update 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 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 float width; 208 float width;
211 if (*iter && iter->IsReadyToDraw()) { 209 if (*iter && iter->IsReadyToDraw()) {
212 ManagedTileState::TileVersion::Mode mode = 210 ManagedTileState::TileVersion::Mode mode =
213 iter->GetTileVersionForDrawing().mode(); 211 iter->GetTileVersionForDrawing().mode();
214 if (mode == ManagedTileState::TileVersion::SOLID_COLOR_MODE) { 212 if (mode == ManagedTileState::TileVersion::SOLID_COLOR_MODE) {
215 color = DebugColors::SolidColorTileBorderColor(); 213 color = DebugColors::SolidColorTileBorderColor();
216 width = DebugColors::SolidColorTileBorderWidth(layer_tree_impl()); 214 width = DebugColors::SolidColorTileBorderWidth(layer_tree_impl());
217 } else if (mode == ManagedTileState::TileVersion::PICTURE_PILE_MODE) { 215 } else if (mode == ManagedTileState::TileVersion::PICTURE_PILE_MODE) {
218 color = DebugColors::PictureTileBorderColor(); 216 color = DebugColors::PictureTileBorderColor();
219 width = DebugColors::PictureTileBorderWidth(layer_tree_impl()); 217 width = DebugColors::PictureTileBorderWidth(layer_tree_impl());
220 } else if (iter->priority(ACTIVE_TREE).resolution == HIGH_RESOLUTION) { 218 } else if (iter.resolution() == HIGH_RESOLUTION) {
221 color = DebugColors::HighResTileBorderColor(); 219 color = DebugColors::HighResTileBorderColor();
222 width = DebugColors::HighResTileBorderWidth(layer_tree_impl()); 220 width = DebugColors::HighResTileBorderWidth(layer_tree_impl());
223 } else if (iter->priority(ACTIVE_TREE).resolution == LOW_RESOLUTION) { 221 } else if (iter.resolution() == LOW_RESOLUTION) {
224 color = DebugColors::LowResTileBorderColor(); 222 color = DebugColors::LowResTileBorderColor();
225 width = DebugColors::LowResTileBorderWidth(layer_tree_impl()); 223 width = DebugColors::LowResTileBorderWidth(layer_tree_impl());
226 } else if (iter->contents_scale() > max_contents_scale) { 224 } else if (iter->contents_scale() > max_contents_scale) {
227 color = DebugColors::ExtraHighResTileBorderColor(); 225 color = DebugColors::ExtraHighResTileBorderColor();
228 width = DebugColors::ExtraHighResTileBorderWidth(layer_tree_impl()); 226 width = DebugColors::ExtraHighResTileBorderWidth(layer_tree_impl());
229 } else { 227 } else {
230 color = DebugColors::ExtraLowResTileBorderColor(); 228 color = DebugColors::ExtraLowResTileBorderColor();
231 width = DebugColors::ExtraLowResTileBorderWidth(layer_tree_impl()); 229 width = DebugColors::ExtraLowResTileBorderWidth(layer_tree_impl());
232 } 230 }
233 } else { 231 } else {
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 } 350 }
353 351
354 append_quads_data->num_missing_tiles++; 352 append_quads_data->num_missing_tiles++;
355 append_quads_data->had_incomplete_tile = true; 353 append_quads_data->had_incomplete_tile = true;
356 append_quads_data->approximated_visible_content_area += 354 append_quads_data->approximated_visible_content_area +=
357 visible_geometry_rect.width() * visible_geometry_rect.height(); 355 visible_geometry_rect.width() * visible_geometry_rect.height();
358 ++missing_tile_count; 356 ++missing_tile_count;
359 continue; 357 continue;
360 } 358 }
361 359
362 if (iter->priority(ACTIVE_TREE).resolution != HIGH_RESOLUTION) { 360 if (iter.resolution() != HIGH_RESOLUTION) {
363 append_quads_data->approximated_visible_content_area += 361 append_quads_data->approximated_visible_content_area +=
364 visible_geometry_rect.width() * visible_geometry_rect.height(); 362 visible_geometry_rect.width() * visible_geometry_rect.height();
365 } 363 }
366 364
367 if (seen_tilings.empty() || seen_tilings.back() != iter.CurrentTiling()) 365 if (seen_tilings.empty() || seen_tilings.back() != iter.CurrentTiling())
368 seen_tilings.push_back(iter.CurrentTiling()); 366 seen_tilings.push_back(iter.CurrentTiling());
369 } 367 }
370 368
371 if (missing_tile_count) { 369 if (missing_tile_count) {
372 TRACE_EVENT_INSTANT2("cc", 370 TRACE_EVENT_INSTANT2("cc",
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
428 DCHECK(raster_source_scale_); 426 DCHECK(raster_source_scale_);
429 DCHECK(raster_contents_scale_); 427 DCHECK(raster_contents_scale_);
430 DCHECK(low_res_raster_contents_scale_); 428 DCHECK(low_res_raster_contents_scale_);
431 429
432 was_screen_space_transform_animating_ = 430 was_screen_space_transform_animating_ =
433 draw_properties().screen_space_transform_is_animating; 431 draw_properties().screen_space_transform_is_animating;
434 432
435 should_update_tile_priorities_ = true; 433 should_update_tile_priorities_ = true;
436 434
437 UpdateTilePriorities(occlusion_tracker); 435 UpdateTilePriorities(occlusion_tracker);
438
439 if (layer_tree_impl()->IsPendingTree())
440 MarkVisibleResourcesAsRequired();
441 } 436 }
442 437
443 void PictureLayerImpl::UpdateTilePriorities( 438 void PictureLayerImpl::UpdateTilePriorities(
444 const OcclusionTracker<LayerImpl>* occlusion_tracker) { 439 const OcclusionTracker<LayerImpl>* occlusion_tracker) {
445 TRACE_EVENT0("cc", "PictureLayerImpl::UpdateTilePriorities"); 440 TRACE_EVENT0("cc", "PictureLayerImpl::UpdateTilePriorities");
446 441
447 double current_frame_time_in_seconds = 442 double current_frame_time_in_seconds =
448 (layer_tree_impl()->CurrentFrameTimeTicks() - 443 (layer_tree_impl()->CurrentFrameTimeTicks() -
449 base::TimeTicks()).InSecondsF(); 444 base::TimeTicks()).InSecondsF();
450 445
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
593 layer_tree_impl()->begin_impl_frame_interval().InSecondsF() * 588 layer_tree_impl()->begin_impl_frame_interval().InSecondsF() *
594 layer_tree_impl()->settings().skewport_target_time_multiplier; 589 layer_tree_impl()->settings().skewport_target_time_multiplier;
595 } 590 }
596 591
597 int PictureLayerImpl::GetSkewportExtrapolationLimitInContentPixels() const { 592 int PictureLayerImpl::GetSkewportExtrapolationLimitInContentPixels() const {
598 return layer_tree_impl() 593 return layer_tree_impl()
599 ->settings() 594 ->settings()
600 .skewport_extrapolation_limit_in_content_pixels; 595 .skewport_extrapolation_limit_in_content_pixels;
601 } 596 }
602 597
598 bool PictureLayerImpl::RequiresHighResToDraw() const {
599 const PictureLayerImpl* layer = this;
600 if (GetTree() == PENDING_TREE)
601 layer = twin_layer_;
602
603 if (layer)
604 return layer->layer_tree_impl()->RequiresHighResToDraw();
605 return false;
606 }
607
603 gfx::Size PictureLayerImpl::CalculateTileSize( 608 gfx::Size PictureLayerImpl::CalculateTileSize(
604 const gfx::Size& content_bounds) const { 609 const gfx::Size& content_bounds) const {
605 if (is_mask_) { 610 if (is_mask_) {
606 int max_size = layer_tree_impl()->MaxTextureSize(); 611 int max_size = layer_tree_impl()->MaxTextureSize();
607 return gfx::Size( 612 return gfx::Size(
608 std::min(max_size, content_bounds.width()), 613 std::min(max_size, content_bounds.width()),
609 std::min(max_size, content_bounds.height())); 614 std::min(max_size, content_bounds.height()));
610 } 615 }
611 616
612 int max_texture_size = 617 int max_texture_size =
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
747 752
748 const ManagedTileState::TileVersion& tile_version = 753 const ManagedTileState::TileVersion& tile_version =
749 iter->GetTileVersionForDrawing(); 754 iter->GetTileVersionForDrawing();
750 if (!tile_version.IsReadyToDraw() || 755 if (!tile_version.IsReadyToDraw() ||
751 tile_version.mode() != ManagedTileState::TileVersion::RESOURCE_MODE) 756 tile_version.mode() != ManagedTileState::TileVersion::RESOURCE_MODE)
752 return 0; 757 return 0;
753 758
754 return tile_version.get_resource_id(); 759 return tile_version.get_resource_id();
755 } 760 }
756 761
757 void PictureLayerImpl::MarkVisibleResourcesAsRequired() const {
758 DCHECK(layer_tree_impl()->IsPendingTree());
759 DCHECK(ideal_contents_scale_);
760 DCHECK_GT(tilings_->num_tilings(), 0u);
761
762 // The goal of this function is to find the minimum set of tiles that need to
763 // be ready to draw in order to activate without flashing content from a
764 // higher res on the active tree to a lower res on the pending tree.
765
766 // First, early out for layers with no visible content.
767 if (visible_content_rect().IsEmpty())
768 return;
769
770 gfx::Rect rect(visible_content_rect());
771
772 float min_acceptable_scale =
773 std::min(raster_contents_scale_, ideal_contents_scale_);
774
775 if (PictureLayerImpl* twin = twin_layer_) {
776 float twin_min_acceptable_scale =
777 std::min(twin->ideal_contents_scale_, twin->raster_contents_scale_);
778 // Ignore 0 scale in case CalculateContentsScale() has never been
779 // called for active twin.
780 if (twin_min_acceptable_scale != 0.0f) {
781 min_acceptable_scale =
782 std::min(min_acceptable_scale, twin_min_acceptable_scale);
783 }
784 }
785
786 PictureLayerTiling* high_res = NULL;
787 PictureLayerTiling* low_res = NULL;
788
789 // First pass: ready to draw tiles in acceptable but non-ideal tilings are
790 // marked as required for activation so that their textures are not thrown
791 // away; any non-ready tiles are not marked as required.
792 Region missing_region = rect;
793 for (size_t i = 0; i < tilings_->num_tilings(); ++i) {
794 PictureLayerTiling* tiling = tilings_->tiling_at(i);
795 DCHECK(tiling->has_ever_been_updated());
796
797 if (tiling->resolution() == LOW_RESOLUTION) {
798 DCHECK(!low_res) << "There can only be one low res tiling";
799 low_res = tiling;
800 }
801 if (tiling->contents_scale() < min_acceptable_scale)
802 continue;
803 if (tiling->resolution() == HIGH_RESOLUTION) {
804 DCHECK(!high_res) << "There can only be one high res tiling";
805 high_res = tiling;
806 continue;
807 }
808 for (PictureLayerTiling::CoverageIterator iter(tiling,
809 contents_scale_x(),
810 rect);
811 iter;
812 ++iter) {
813 if (!*iter || !iter->IsReadyToDraw())
814 continue;
815
816 missing_region.Subtract(iter.geometry_rect());
817 iter->MarkRequiredForActivation();
818 }
819 }
820 DCHECK(high_res) << "There must be one high res tiling";
821
822 // If these pointers are null (because no twin, no matching tiling, or the
823 // simpification just below), then high res tiles will be required to fill any
824 // holes left by the first pass above. If the pointers are valid, then this
825 // layer is allowed to skip any tiles that are not ready on its twin.
826 const PictureLayerTiling* twin_high_res = NULL;
827 const PictureLayerTiling* twin_low_res = NULL;
828
829 if (twin_layer_) {
830 // As a simplification, only allow activating to skip twin tiles that the
831 // active layer is also missing when both this layer and its twin have
832 // "simple" sets of tilings: only 2 tilings (high and low) or only 1 high
833 // res tiling. This avoids having to iterate/track coverage of non-ideal
834 // tilings during the last draw call on the active layer.
835 if (tilings_->num_tilings() <= 2 &&
836 twin_layer_->tilings_->num_tilings() <= tilings_->num_tilings()) {
837 twin_low_res = low_res ? GetTwinTiling(low_res) : NULL;
838 twin_high_res = high_res ? GetTwinTiling(high_res) : NULL;
839 }
840
841 // If this layer and its twin have different transforms, then don't compare
842 // them and only allow activating to high res tiles, since tiles on each
843 // layer will be in different places on screen.
844 if (twin_layer_->layer_tree_impl()->RequiresHighResToDraw() ||
845 bounds() != twin_layer_->bounds() ||
846 draw_properties().screen_space_transform !=
847 twin_layer_->draw_properties().screen_space_transform) {
848 twin_high_res = NULL;
849 twin_low_res = NULL;
850 }
851 }
852
853 // As a second pass, mark as required any visible high res tiles not filled in
854 // by acceptable non-ideal tiles from the first pass.
855 if (MarkVisibleTilesAsRequired(
856 high_res, twin_high_res, contents_scale_x(), rect, missing_region)) {
857 // As an optional third pass, if a high res tile was skipped because its
858 // twin was also missing, then fall back to mark low res tiles as required
859 // in case the active twin is substituting those for missing high res
860 // content. Only suitable, when low res is enabled.
861 if (low_res) {
862 MarkVisibleTilesAsRequired(
863 low_res, twin_low_res, contents_scale_x(), rect, missing_region);
864 }
865 }
866 }
867
868 bool PictureLayerImpl::MarkVisibleTilesAsRequired(
869 PictureLayerTiling* tiling,
870 const PictureLayerTiling* optional_twin_tiling,
871 float contents_scale,
872 const gfx::Rect& rect,
873 const Region& missing_region) const {
874 bool twin_had_missing_tile = false;
875 for (PictureLayerTiling::CoverageIterator iter(tiling,
876 contents_scale,
877 rect);
878 iter;
879 ++iter) {
880 Tile* tile = *iter;
881 // A null tile (i.e. missing recording) can just be skipped.
882 if (!tile)
883 continue;
884
885 // If the tile is occluded, don't mark it as required for activation.
886 if (tile->is_occluded(PENDING_TREE))
887 continue;
888
889 // If the missing region doesn't cover it, this tile is fully
890 // covered by acceptable tiles at other scales.
891 if (!missing_region.Intersects(iter.geometry_rect()))
892 continue;
893
894 // If the twin tile doesn't exist (i.e. missing recording or so far away
895 // that it is outside the visible tile rect) or this tile is shared between
896 // with the twin, then this tile isn't required to prevent flashing.
897 if (optional_twin_tiling) {
898 Tile* twin_tile = optional_twin_tiling->TileAt(iter.i(), iter.j());
899 if (!twin_tile || twin_tile == tile) {
900 twin_had_missing_tile = true;
901 continue;
902 }
903 }
904
905 tile->MarkRequiredForActivation();
906 }
907 return twin_had_missing_tile;
908 }
909
910 void PictureLayerImpl::DoPostCommitInitialization() { 762 void PictureLayerImpl::DoPostCommitInitialization() {
911 DCHECK(needs_post_commit_initialization_); 763 DCHECK(needs_post_commit_initialization_);
912 DCHECK(layer_tree_impl()->IsPendingTree()); 764 DCHECK(layer_tree_impl()->IsPendingTree());
913 765
914 if (!tilings_) 766 if (!tilings_)
915 tilings_.reset(new PictureLayerTilingSet(this, bounds())); 767 tilings_.reset(new PictureLayerTilingSet(this, bounds()));
916 768
917 DCHECK(!twin_layer_); 769 DCHECK(!twin_layer_);
918 twin_layer_ = static_cast<PictureLayerImpl*>( 770 twin_layer_ = static_cast<PictureLayerImpl*>(
919 layer_tree_impl()->FindActiveTreeLayerById(id())); 771 layer_tree_impl()->FindActiveTreeLayerById(id()));
(...skipping 717 matching lines...) Expand 10 before | Expand all | Expand 10 after
1637 return iterator_index_ < iterators_.size(); 1489 return iterator_index_ < iterators_.size();
1638 } 1490 }
1639 1491
1640 bool PictureLayerImpl::LayerEvictionTileIterator::IsCorrectType( 1492 bool PictureLayerImpl::LayerEvictionTileIterator::IsCorrectType(
1641 PictureLayerTiling::TilingEvictionTileIterator* it) const { 1493 PictureLayerTiling::TilingEvictionTileIterator* it) const {
1642 return it->get_type() == iteration_stage_ && 1494 return it->get_type() == iteration_stage_ &&
1643 (**it)->required_for_activation() == required_for_activation_; 1495 (**it)->required_for_activation() == required_for_activation_;
1644 } 1496 }
1645 1497
1646 } // namespace cc 1498 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698