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

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

Issue 270823003: cc: Move gpu rasterization flag from LayerImpl to LayerTreeImpl. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 raster_device_scale_(0.f), 56 raster_device_scale_(0.f),
57 raster_source_scale_(0.f), 57 raster_source_scale_(0.f),
58 raster_contents_scale_(0.f), 58 raster_contents_scale_(0.f),
59 low_res_raster_contents_scale_(0.f), 59 low_res_raster_contents_scale_(0.f),
60 raster_source_scale_is_fixed_(false), 60 raster_source_scale_is_fixed_(false),
61 was_animating_transform_to_screen_(false), 61 was_animating_transform_to_screen_(false),
62 is_using_lcd_text_(tree_impl->settings().can_use_lcd_text), 62 is_using_lcd_text_(tree_impl->settings().can_use_lcd_text),
63 needs_post_commit_initialization_(true), 63 needs_post_commit_initialization_(true),
64 should_update_tile_priorities_(false), 64 should_update_tile_priorities_(false),
65 should_use_low_res_tiling_(tree_impl->settings().create_low_res_tiling), 65 should_use_low_res_tiling_(tree_impl->settings().create_low_res_tiling),
66 use_gpu_rasterization_(false),
67 layer_needs_to_register_itself_(true) { 66 layer_needs_to_register_itself_(true) {
68 } 67 }
69 68
70 PictureLayerImpl::~PictureLayerImpl() { 69 PictureLayerImpl::~PictureLayerImpl() {
71 if (!layer_needs_to_register_itself_) 70 if (!layer_needs_to_register_itself_)
72 layer_tree_impl()->tile_manager()->UnregisterPictureLayerImpl(this); 71 layer_tree_impl()->tile_manager()->UnregisterPictureLayerImpl(this);
73 } 72 }
74 73
75 const char* PictureLayerImpl::LayerTypeAsString() const { 74 const char* PictureLayerImpl::LayerTypeAsString() const {
76 return "cc::PictureLayerImpl"; 75 return "cc::PictureLayerImpl";
(...skipping 21 matching lines...) Expand all
98 97
99 LayerImpl::PushPropertiesTo(base_layer); 98 LayerImpl::PushPropertiesTo(base_layer);
100 99
101 // When the pending tree pushes to the active tree, the pending twin 100 // When the pending tree pushes to the active tree, the pending twin
102 // disappears. 101 // disappears.
103 layer_impl->twin_layer_ = NULL; 102 layer_impl->twin_layer_ = NULL;
104 twin_layer_ = NULL; 103 twin_layer_ = NULL;
105 104
106 layer_impl->SetIsMask(is_mask_); 105 layer_impl->SetIsMask(is_mask_);
107 layer_impl->pile_ = pile_; 106 layer_impl->pile_ = pile_;
108 layer_impl->use_gpu_rasterization_ = use_gpu_rasterization_;
109 107
110 // Tilings would be expensive to push, so we swap. 108 // Tilings would be expensive to push, so we swap.
111 layer_impl->tilings_.swap(tilings_); 109 layer_impl->tilings_.swap(tilings_);
112 110
113 // Ensure that we don't have any tiles that are out of date. 111 // Ensure that we don't have any tiles that are out of date.
114 if (tilings_) 112 if (tilings_)
115 tilings_->RemoveTilesInRegion(invalidation_); 113 tilings_->RemoveTilesInRegion(invalidation_);
116 114
117 layer_impl->tilings_->SetClient(layer_impl); 115 layer_impl->tilings_->SetClient(layer_impl);
118 if (tilings_) 116 if (tilings_)
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after
516 *contents_scale_x = max_contents_scale; 514 *contents_scale_x = max_contents_scale;
517 *contents_scale_y = max_contents_scale; 515 *contents_scale_y = max_contents_scale;
518 *content_bounds = gfx::ToCeiledSize( 516 *content_bounds = gfx::ToCeiledSize(
519 gfx::ScaleSize(bounds(), max_contents_scale, max_contents_scale)); 517 gfx::ScaleSize(bounds(), max_contents_scale, max_contents_scale));
520 } 518 }
521 519
522 skia::RefPtr<SkPicture> PictureLayerImpl::GetPicture() { 520 skia::RefPtr<SkPicture> PictureLayerImpl::GetPicture() {
523 return pile_->GetFlattenedPicture(); 521 return pile_->GetFlattenedPicture();
524 } 522 }
525 523
526 void PictureLayerImpl::SetUseGpuRasterization(bool use_gpu) {
527 if (use_gpu_rasterization_ == use_gpu)
528 return;
529
530 use_gpu_rasterization_ = use_gpu;
531 RemoveAllTilings();
532 }
533
534 scoped_refptr<Tile> PictureLayerImpl::CreateTile(PictureLayerTiling* tiling, 524 scoped_refptr<Tile> PictureLayerImpl::CreateTile(PictureLayerTiling* tiling,
535 const gfx::Rect& content_rect) { 525 const gfx::Rect& content_rect) {
536 if (!pile_->CanRaster(tiling->contents_scale(), content_rect)) 526 if (!pile_->CanRaster(tiling->contents_scale(), content_rect))
537 return scoped_refptr<Tile>(); 527 return scoped_refptr<Tile>();
538 528
539 int flags = 0; 529 int flags = 0;
540 if (is_using_lcd_text_) 530 if (is_using_lcd_text_)
541 flags |= Tile::USE_LCD_TEXT; 531 flags |= Tile::USE_LCD_TEXT;
542 if (ShouldUseGpuRasterization()) 532 if (UseGpuRasterization())
543 flags |= Tile::USE_GPU_RASTERIZATION; 533 flags |= Tile::USE_GPU_RASTERIZATION;
544 return layer_tree_impl()->tile_manager()->CreateTile( 534 return layer_tree_impl()->tile_manager()->CreateTile(
545 pile_.get(), 535 pile_.get(),
546 content_rect.size(), 536 content_rect.size(),
547 content_rect, 537 content_rect,
548 contents_opaque() ? content_rect : gfx::Rect(), 538 contents_opaque() ? content_rect : gfx::Rect(),
549 tiling->contents_scale(), 539 tiling->contents_scale(),
550 id(), 540 id(),
551 layer_tree_impl()->source_frame_number(), 541 layer_tree_impl()->source_frame_number(),
552 flags); 542 flags);
553 } 543 }
554 544
555 void PictureLayerImpl::UpdatePile(Tile* tile) { 545 void PictureLayerImpl::UpdatePile(Tile* tile) {
556 tile->set_picture_pile(pile_); 546 tile->set_picture_pile(pile_);
557 } 547 }
558 548
559 const Region* PictureLayerImpl::GetInvalidation() { 549 const Region* PictureLayerImpl::GetInvalidation() {
560 return &invalidation_; 550 return &invalidation_;
561 } 551 }
562 552
563 const PictureLayerTiling* PictureLayerImpl::GetTwinTiling( 553 const PictureLayerTiling* PictureLayerImpl::GetTwinTiling(
564 const PictureLayerTiling* tiling) const { 554 const PictureLayerTiling* tiling) const {
565
566 if (!twin_layer_ || 555 if (!twin_layer_ ||
567 twin_layer_->ShouldUseGpuRasterization() != ShouldUseGpuRasterization()) 556 twin_layer_->UseGpuRasterization() != UseGpuRasterization())
568 return NULL; 557 return NULL;
569 for (size_t i = 0; i < twin_layer_->tilings_->num_tilings(); ++i) 558 for (size_t i = 0; i < twin_layer_->tilings_->num_tilings(); ++i)
570 if (twin_layer_->tilings_->tiling_at(i)->contents_scale() == 559 if (twin_layer_->tilings_->tiling_at(i)->contents_scale() ==
571 tiling->contents_scale()) 560 tiling->contents_scale())
572 return twin_layer_->tilings_->tiling_at(i); 561 return twin_layer_->tilings_->tiling_at(i);
573 return NULL; 562 return NULL;
574 } 563 }
575 564
576 size_t PictureLayerImpl::GetMaxTilesForInterestArea() const { 565 size_t PictureLayerImpl::GetMaxTilesForInterestArea() const {
577 return layer_tree_impl()->settings().max_tiles_for_interest_area; 566 return layer_tree_impl()->settings().max_tiles_for_interest_area;
578 } 567 }
579 568
580 float PictureLayerImpl::GetSkewportTargetTimeInSeconds() const { 569 float PictureLayerImpl::GetSkewportTargetTimeInSeconds() const {
581 float skewport_target_time_in_frames = ShouldUseGpuRasterization() 570 float skewport_target_time_in_frames = UseGpuRasterization()
582 ? kGpuSkewportTargetTimeInFrames 571 ? kGpuSkewportTargetTimeInFrames
583 : kCpuSkewportTargetTimeInFrames; 572 : kCpuSkewportTargetTimeInFrames;
584 return skewport_target_time_in_frames * 573 return skewport_target_time_in_frames *
585 layer_tree_impl()->begin_impl_frame_interval().InSecondsF() * 574 layer_tree_impl()->begin_impl_frame_interval().InSecondsF() *
586 layer_tree_impl()->settings().skewport_target_time_multiplier; 575 layer_tree_impl()->settings().skewport_target_time_multiplier;
587 } 576 }
588 577
589 int PictureLayerImpl::GetSkewportExtrapolationLimitInContentPixels() const { 578 int PictureLayerImpl::GetSkewportExtrapolationLimitInContentPixels() const {
590 return layer_tree_impl() 579 return layer_tree_impl()
591 ->settings() 580 ->settings()
592 .skewport_extrapolation_limit_in_content_pixels; 581 .skewport_extrapolation_limit_in_content_pixels;
593 } 582 }
594 583
595 gfx::Size PictureLayerImpl::CalculateTileSize( 584 gfx::Size PictureLayerImpl::CalculateTileSize(
596 const gfx::Size& content_bounds) const { 585 const gfx::Size& content_bounds) const {
597 if (is_mask_) { 586 if (is_mask_) {
598 int max_size = layer_tree_impl()->MaxTextureSize(); 587 int max_size = layer_tree_impl()->MaxTextureSize();
599 return gfx::Size( 588 return gfx::Size(
600 std::min(max_size, content_bounds.width()), 589 std::min(max_size, content_bounds.width()),
601 std::min(max_size, content_bounds.height())); 590 std::min(max_size, content_bounds.height()));
602 } 591 }
603 592
604 int max_texture_size = 593 int max_texture_size =
605 layer_tree_impl()->resource_provider()->max_texture_size(); 594 layer_tree_impl()->resource_provider()->max_texture_size();
606 595
607 gfx::Size default_tile_size = layer_tree_impl()->settings().default_tile_size; 596 gfx::Size default_tile_size = layer_tree_impl()->settings().default_tile_size;
608 if (ShouldUseGpuRasterization()) { 597 if (UseGpuRasterization()) {
609 // TODO(ernstm) crbug.com/365877: We need a unified way to override the 598 // TODO(ernstm) crbug.com/365877: We need a unified way to override the
610 // default-tile-size. 599 // default-tile-size.
611 default_tile_size = 600 default_tile_size =
612 gfx::Size(layer_tree_impl()->device_viewport_size().width(), 601 gfx::Size(layer_tree_impl()->device_viewport_size().width(),
613 layer_tree_impl()->device_viewport_size().height() / 4); 602 layer_tree_impl()->device_viewport_size().height() / 4);
614 } 603 }
615 default_tile_size.SetToMin(gfx::Size(max_texture_size, max_texture_size)); 604 default_tile_size.SetToMin(gfx::Size(max_texture_size, max_texture_size));
616 605
617 gfx::Size max_untiled_content_size = 606 gfx::Size max_untiled_content_size =
618 layer_tree_impl()->settings().max_untiled_layer_size; 607 layer_tree_impl()->settings().max_untiled_layer_size;
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after
914 903
915 PictureLayerTiling* PictureLayerImpl::AddTiling(float contents_scale) { 904 PictureLayerTiling* PictureLayerImpl::AddTiling(float contents_scale) {
916 DCHECK(CanHaveTilingWithScale(contents_scale)) << 905 DCHECK(CanHaveTilingWithScale(contents_scale)) <<
917 "contents_scale: " << contents_scale; 906 "contents_scale: " << contents_scale;
918 907
919 PictureLayerTiling* tiling = tilings_->AddTiling(contents_scale); 908 PictureLayerTiling* tiling = tilings_->AddTiling(contents_scale);
920 909
921 DCHECK(pile_->HasRecordings()); 910 DCHECK(pile_->HasRecordings());
922 911
923 if (twin_layer_ && 912 if (twin_layer_ &&
924 twin_layer_->ShouldUseGpuRasterization() == ShouldUseGpuRasterization()) 913 twin_layer_->UseGpuRasterization() == UseGpuRasterization())
925 twin_layer_->SyncTiling(tiling); 914 twin_layer_->SyncTiling(tiling);
926 915
927 return tiling; 916 return tiling;
928 } 917 }
929 918
930 void PictureLayerImpl::RemoveTiling(float contents_scale) { 919 void PictureLayerImpl::RemoveTiling(float contents_scale) {
931 for (size_t i = 0; i < tilings_->num_tilings(); ++i) { 920 for (size_t i = 0; i < tilings_->num_tilings(); ++i) {
932 PictureLayerTiling* tiling = tilings_->tiling_at(i); 921 PictureLayerTiling* tiling = tilings_->tiling_at(i);
933 if (tiling->contents_scale() == contents_scale) { 922 if (tiling->contents_scale() == contents_scale) {
934 tilings_->Remove(tiling); 923 tilings_->Remove(tiling);
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
1032 1021
1033 SanityCheckTilingState(); 1022 SanityCheckTilingState();
1034 } 1023 }
1035 1024
1036 bool PictureLayerImpl::ShouldAdjustRasterScale( 1025 bool PictureLayerImpl::ShouldAdjustRasterScale(
1037 bool animating_transform_to_screen) const { 1026 bool animating_transform_to_screen) const {
1038 if (was_animating_transform_to_screen_ != animating_transform_to_screen) 1027 if (was_animating_transform_to_screen_ != animating_transform_to_screen)
1039 return true; 1028 return true;
1040 1029
1041 if (animating_transform_to_screen && 1030 if (animating_transform_to_screen &&
1042 raster_contents_scale_ != ideal_contents_scale_ && 1031 raster_contents_scale_ != ideal_contents_scale_ && UseGpuRasterization())
1043 ShouldUseGpuRasterization())
1044 return true; 1032 return true;
1045 1033
1046 bool is_pinching = layer_tree_impl()->PinchGestureActive(); 1034 bool is_pinching = layer_tree_impl()->PinchGestureActive();
1047 if (is_pinching && raster_page_scale_) { 1035 if (is_pinching && raster_page_scale_) {
1048 // We change our raster scale when it is: 1036 // We change our raster scale when it is:
1049 // - Higher than ideal (need a lower-res tiling available) 1037 // - Higher than ideal (need a lower-res tiling available)
1050 // - Too far from ideal (need a higher-res tiling available) 1038 // - Too far from ideal (need a higher-res tiling available)
1051 float ratio = ideal_page_scale_ / raster_page_scale_; 1039 float ratio = ideal_page_scale_ / raster_page_scale_;
1052 if (raster_page_scale_ > ideal_page_scale_ || 1040 if (raster_page_scale_ > ideal_page_scale_ ||
1053 ratio > kMaxScaleRatioDuringPinch) 1041 ratio > kMaxScaleRatioDuringPinch)
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
1133 raster_page_scale_ = 1121 raster_page_scale_ =
1134 raster_contents_scale_ / raster_device_scale_ / raster_source_scale_; 1122 raster_contents_scale_ / raster_device_scale_ / raster_source_scale_;
1135 } 1123 }
1136 1124
1137 raster_contents_scale_ = 1125 raster_contents_scale_ =
1138 std::max(raster_contents_scale_, MinimumContentsScale()); 1126 std::max(raster_contents_scale_, MinimumContentsScale());
1139 1127
1140 // If we're not re-rasterizing during animation, rasterize at the maximum 1128 // If we're not re-rasterizing during animation, rasterize at the maximum
1141 // scale that will occur during the animation, if the maximum scale is 1129 // scale that will occur during the animation, if the maximum scale is
1142 // known. 1130 // known.
1143 if (animating_transform_to_screen && !ShouldUseGpuRasterization()) { 1131 if (animating_transform_to_screen && !UseGpuRasterization()) {
1144 if (maximum_animation_contents_scale > 0.f) { 1132 if (maximum_animation_contents_scale > 0.f) {
1145 raster_contents_scale_ = 1133 raster_contents_scale_ =
1146 std::max(raster_contents_scale_, maximum_animation_contents_scale); 1134 std::max(raster_contents_scale_, maximum_animation_contents_scale);
1147 } else { 1135 } else {
1148 raster_contents_scale_ = 1136 raster_contents_scale_ =
1149 std::max(raster_contents_scale_, 1137 std::max(raster_contents_scale_,
1150 1.f * ideal_page_scale_ * ideal_device_scale_); 1138 1.f * ideal_page_scale_ * ideal_device_scale_);
1151 } 1139 }
1152 } 1140 }
1153 1141
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
1323 scoped_ptr<base::DictionaryValue> tile_data(new base::DictionaryValue); 1311 scoped_ptr<base::DictionaryValue> tile_data(new base::DictionaryValue);
1324 tile_data->Set("geometry_rect", 1312 tile_data->Set("geometry_rect",
1325 MathUtil::AsValue(iter.geometry_rect()).release()); 1313 MathUtil::AsValue(iter.geometry_rect()).release());
1326 if (*iter) 1314 if (*iter)
1327 tile_data->Set("tile", TracedValue::CreateIDRef(*iter).release()); 1315 tile_data->Set("tile", TracedValue::CreateIDRef(*iter).release());
1328 1316
1329 coverage_tiles->Append(tile_data.release()); 1317 coverage_tiles->Append(tile_data.release());
1330 } 1318 }
1331 state->Set("coverage_tiles", coverage_tiles.release()); 1319 state->Set("coverage_tiles", coverage_tiles.release());
1332 state->SetBoolean("is_using_lcd_text", is_using_lcd_text_); 1320 state->SetBoolean("is_using_lcd_text", is_using_lcd_text_);
1333 state->SetBoolean("using_gpu_rasterization", ShouldUseGpuRasterization()); 1321 state->SetBoolean("using_gpu_rasterization", UseGpuRasterization());
1334 } 1322 }
1335 1323
1336 size_t PictureLayerImpl::GPUMemoryUsageInBytes() const { 1324 size_t PictureLayerImpl::GPUMemoryUsageInBytes() const {
1337 const_cast<PictureLayerImpl*>(this)->DoPostCommitInitializationIfNeeded(); 1325 const_cast<PictureLayerImpl*>(this)->DoPostCommitInitializationIfNeeded();
1338 return tilings_->GPUMemoryUsageInBytes(); 1326 return tilings_->GPUMemoryUsageInBytes();
1339 } 1327 }
1340 1328
1341 void PictureLayerImpl::RunMicroBenchmark(MicroBenchmarkImpl* benchmark) { 1329 void PictureLayerImpl::RunMicroBenchmark(MicroBenchmarkImpl* benchmark) {
1342 benchmark->RunOnLayer(this); 1330 benchmark->RunOnLayer(this);
1343 } 1331 }
1344 1332
1345 WhichTree PictureLayerImpl::GetTree() const { 1333 WhichTree PictureLayerImpl::GetTree() const {
1346 return layer_tree_impl()->IsActiveTree() ? ACTIVE_TREE : PENDING_TREE; 1334 return layer_tree_impl()->IsActiveTree() ? ACTIVE_TREE : PENDING_TREE;
1347 } 1335 }
1348 1336
1349 bool PictureLayerImpl::IsOnActiveOrPendingTree() const { 1337 bool PictureLayerImpl::IsOnActiveOrPendingTree() const {
1350 return !layer_tree_impl()->IsRecycleTree(); 1338 return !layer_tree_impl()->IsRecycleTree();
1351 } 1339 }
1352 1340
1341 bool PictureLayerImpl::UseGpuRasterization() const {
1342 return layer_tree_impl()->use_gpu_rasterization();
1343 }
1344
1353 PictureLayerImpl::LayerRasterTileIterator::LayerRasterTileIterator() 1345 PictureLayerImpl::LayerRasterTileIterator::LayerRasterTileIterator()
1354 : layer_(NULL) {} 1346 : layer_(NULL) {}
1355 1347
1356 PictureLayerImpl::LayerRasterTileIterator::LayerRasterTileIterator( 1348 PictureLayerImpl::LayerRasterTileIterator::LayerRasterTileIterator(
1357 PictureLayerImpl* layer, 1349 PictureLayerImpl* layer,
1358 bool prioritize_low_res) 1350 bool prioritize_low_res)
1359 : layer_(layer), current_stage_(0) { 1351 : layer_(layer), current_stage_(0) {
1360 DCHECK(layer_); 1352 DCHECK(layer_);
1361 if (!layer_->tilings_ || !layer_->tilings_->num_tilings()) { 1353 if (!layer_->tilings_ || !layer_->tilings_->num_tilings()) {
1362 current_stage_ = arraysize(stages_); 1354 current_stage_ = arraysize(stages_);
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
1566 return iterator_index_ < iterators_.size(); 1558 return iterator_index_ < iterators_.size();
1567 } 1559 }
1568 1560
1569 bool PictureLayerImpl::LayerEvictionTileIterator::IsCorrectType( 1561 bool PictureLayerImpl::LayerEvictionTileIterator::IsCorrectType(
1570 PictureLayerTiling::TilingEvictionTileIterator* it) const { 1562 PictureLayerTiling::TilingEvictionTileIterator* it) const {
1571 return it->get_type() == iteration_stage_ && 1563 return it->get_type() == iteration_stage_ &&
1572 (**it)->required_for_activation() == required_for_activation_; 1564 (**it)->required_for_activation() == required_for_activation_;
1573 } 1565 }
1574 1566
1575 } // namespace cc 1567 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698