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

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

Issue 181063022: cc: Trigger GPU rasterization based on a per-layer hint (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 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
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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 ideal_contents_scale_(0.f), 47 ideal_contents_scale_(0.f),
48 raster_page_scale_(0.f), 48 raster_page_scale_(0.f),
49 raster_device_scale_(0.f), 49 raster_device_scale_(0.f),
50 raster_source_scale_(0.f), 50 raster_source_scale_(0.f),
51 raster_contents_scale_(0.f), 51 raster_contents_scale_(0.f),
52 low_res_raster_contents_scale_(0.f), 52 low_res_raster_contents_scale_(0.f),
53 raster_source_scale_was_animating_(false), 53 raster_source_scale_was_animating_(false),
54 is_using_lcd_text_(tree_impl->settings().can_use_lcd_text), 54 is_using_lcd_text_(tree_impl->settings().can_use_lcd_text),
55 needs_post_commit_initialization_(true), 55 needs_post_commit_initialization_(true),
56 should_update_tile_priorities_(false), 56 should_update_tile_priorities_(false),
57 should_use_gpu_rasterization_(tree_impl->settings().gpu_rasterization) {} 57 has_gpu_rasterization_hint_(false) {}
58 58
59 PictureLayerImpl::~PictureLayerImpl() {} 59 PictureLayerImpl::~PictureLayerImpl() {}
60 60
61 const char* PictureLayerImpl::LayerTypeAsString() const { 61 const char* PictureLayerImpl::LayerTypeAsString() const {
62 return "cc::PictureLayerImpl"; 62 return "cc::PictureLayerImpl";
63 } 63 }
64 64
65 scoped_ptr<LayerImpl> PictureLayerImpl::CreateLayerImpl( 65 scoped_ptr<LayerImpl> PictureLayerImpl::CreateLayerImpl(
66 LayerTreeImpl* tree_impl) { 66 LayerTreeImpl* tree_impl) {
67 return PictureLayerImpl::Create(tree_impl, id()).PassAs<LayerImpl>(); 67 return PictureLayerImpl::Create(tree_impl, id()).PassAs<LayerImpl>();
(...skipping 16 matching lines...) Expand all
84 84
85 LayerImpl::PushPropertiesTo(base_layer); 85 LayerImpl::PushPropertiesTo(base_layer);
86 86
87 // When the pending tree pushes to the active tree, the pending twin 87 // When the pending tree pushes to the active tree, the pending twin
88 // disappears. 88 // disappears.
89 layer_impl->twin_layer_ = NULL; 89 layer_impl->twin_layer_ = NULL;
90 twin_layer_ = NULL; 90 twin_layer_ = NULL;
91 91
92 layer_impl->SetIsMask(is_mask_); 92 layer_impl->SetIsMask(is_mask_);
93 layer_impl->pile_ = pile_; 93 layer_impl->pile_ = pile_;
94 layer_impl->SetHasGpuRasterizationHint(has_gpu_rasterization_hint_);
94 95
95 // Tilings would be expensive to push, so we swap. This optimization requires 96 // Tilings would be expensive to push, so we swap. This optimization requires
96 // an extra invalidation in SyncFromActiveLayer. 97 // an extra invalidation in SyncFromActiveLayer.
97 layer_impl->tilings_.swap(tilings_); 98 layer_impl->tilings_.swap(tilings_);
98 layer_impl->tilings_->SetClient(layer_impl); 99 layer_impl->tilings_->SetClient(layer_impl);
99 if (tilings_) 100 if (tilings_)
100 tilings_->SetClient(this); 101 tilings_->SetClient(this);
101 102
102 layer_impl->raster_page_scale_ = raster_page_scale_; 103 layer_impl->raster_page_scale_ = raster_page_scale_;
103 layer_impl->raster_device_scale_ = raster_device_scale_; 104 layer_impl->raster_device_scale_ = raster_device_scale_;
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 *contents_scale_x = max_contents_scale; 443 *contents_scale_x = max_contents_scale;
443 *contents_scale_y = max_contents_scale; 444 *contents_scale_y = max_contents_scale;
444 *content_bounds = gfx::ToCeiledSize( 445 *content_bounds = gfx::ToCeiledSize(
445 gfx::ScaleSize(bounds(), max_contents_scale, max_contents_scale)); 446 gfx::ScaleSize(bounds(), max_contents_scale, max_contents_scale));
446 } 447 }
447 448
448 skia::RefPtr<SkPicture> PictureLayerImpl::GetPicture() { 449 skia::RefPtr<SkPicture> PictureLayerImpl::GetPicture() {
449 return pile_->GetFlattenedPicture(); 450 return pile_->GetFlattenedPicture();
450 } 451 }
451 452
452 void PictureLayerImpl::SetShouldUseGpuRasterization( 453 void PictureLayerImpl::SetHasGpuRasterizationHint(bool has_hint) {
453 bool should_use_gpu_rasterization) { 454 bool old_should_use_gpu_rasterization = ShouldUseGpuRasterization();
454 if (should_use_gpu_rasterization != should_use_gpu_rasterization_) { 455 has_gpu_rasterization_hint_ = has_hint;
455 should_use_gpu_rasterization_ = should_use_gpu_rasterization; 456 if (ShouldUseGpuRasterization() != old_should_use_gpu_rasterization)
456 RemoveAllTilings(); 457 RemoveAllTilings();
457 } else { 458 }
458 should_use_gpu_rasterization_ = should_use_gpu_rasterization; 459
460 bool PictureLayerImpl::ShouldUseGpuRasterization() const {
461 switch (layer_tree_impl()->settings().gpu_rasterization_state) {
462 case LayerTreeSettings::SoftwareRasterization:
463 return false;
464 case LayerTreeSettings::HybridGpuRasterization:
465 return has_gpu_rasterization_hint_;
466 case LayerTreeSettings::UniversalGpuRasterization:
467 return true;
459 } 468 }
460 } 469 }
461 470
462 scoped_refptr<Tile> PictureLayerImpl::CreateTile(PictureLayerTiling* tiling, 471 scoped_refptr<Tile> PictureLayerImpl::CreateTile(PictureLayerTiling* tiling,
463 const gfx::Rect& content_rect) { 472 const gfx::Rect& content_rect) {
464 if (!pile_->CanRaster(tiling->contents_scale(), content_rect)) 473 if (!pile_->CanRaster(tiling->contents_scale(), content_rect))
465 return scoped_refptr<Tile>(); 474 return scoped_refptr<Tile>();
466 475
467 int flags = 0; 476 int flags = 0;
468 if (is_using_lcd_text_) 477 if (is_using_lcd_text_)
469 flags |= Tile::USE_LCD_TEXT; 478 flags |= Tile::USE_LCD_TEXT;
470 if (should_use_gpu_rasterization()) 479 if (ShouldUseGpuRasterization())
471 flags |= Tile::USE_GPU_RASTERIZATION; 480 flags |= Tile::USE_GPU_RASTERIZATION;
472 return layer_tree_impl()->tile_manager()->CreateTile( 481 return layer_tree_impl()->tile_manager()->CreateTile(
473 pile_.get(), 482 pile_.get(),
474 content_rect.size(), 483 content_rect.size(),
475 content_rect, 484 content_rect,
476 contents_opaque() ? content_rect : gfx::Rect(), 485 contents_opaque() ? content_rect : gfx::Rect(),
477 tiling->contents_scale(), 486 tiling->contents_scale(),
478 id(), 487 id(),
479 layer_tree_impl()->source_frame_number(), 488 layer_tree_impl()->source_frame_number(),
480 flags); 489 flags);
481 } 490 }
482 491
483 void PictureLayerImpl::UpdatePile(Tile* tile) { 492 void PictureLayerImpl::UpdatePile(Tile* tile) {
484 tile->set_picture_pile(pile_); 493 tile->set_picture_pile(pile_);
485 } 494 }
486 495
487 const Region* PictureLayerImpl::GetInvalidation() { 496 const Region* PictureLayerImpl::GetInvalidation() {
488 return &invalidation_; 497 return &invalidation_;
489 } 498 }
490 499
491 const PictureLayerTiling* PictureLayerImpl::GetTwinTiling( 500 const PictureLayerTiling* PictureLayerImpl::GetTwinTiling(
492 const PictureLayerTiling* tiling) const { 501 const PictureLayerTiling* tiling) const {
493 502
494 if (!twin_layer_ || twin_layer_->should_use_gpu_rasterization() != 503 if (!twin_layer_ ||
495 should_use_gpu_rasterization()) 504 twin_layer_->ShouldUseGpuRasterization() != ShouldUseGpuRasterization())
496 return NULL; 505 return NULL;
497 for (size_t i = 0; i < twin_layer_->tilings_->num_tilings(); ++i) 506 for (size_t i = 0; i < twin_layer_->tilings_->num_tilings(); ++i)
498 if (twin_layer_->tilings_->tiling_at(i)->contents_scale() == 507 if (twin_layer_->tilings_->tiling_at(i)->contents_scale() ==
499 tiling->contents_scale()) 508 tiling->contents_scale())
500 return twin_layer_->tilings_->tiling_at(i); 509 return twin_layer_->tilings_->tiling_at(i);
501 return NULL; 510 return NULL;
502 } 511 }
503 512
504 size_t PictureLayerImpl::GetMaxTilesForInterestArea() const { 513 size_t PictureLayerImpl::GetMaxTilesForInterestArea() const {
505 return layer_tree_impl()->settings().max_tiles_for_interest_area; 514 return layer_tree_impl()->settings().max_tiles_for_interest_area;
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after
834 843
835 PictureLayerTiling* PictureLayerImpl::AddTiling(float contents_scale) { 844 PictureLayerTiling* PictureLayerImpl::AddTiling(float contents_scale) {
836 DCHECK(CanHaveTilingWithScale(contents_scale)) << 845 DCHECK(CanHaveTilingWithScale(contents_scale)) <<
837 "contents_scale: " << contents_scale; 846 "contents_scale: " << contents_scale;
838 847
839 PictureLayerTiling* tiling = tilings_->AddTiling(contents_scale); 848 PictureLayerTiling* tiling = tilings_->AddTiling(contents_scale);
840 849
841 const Region& recorded = pile_->recorded_region(); 850 const Region& recorded = pile_->recorded_region();
842 DCHECK(!recorded.IsEmpty()); 851 DCHECK(!recorded.IsEmpty());
843 852
844 if (twin_layer_ && twin_layer_->should_use_gpu_rasterization() == 853 if (twin_layer_ &&
845 should_use_gpu_rasterization()) 854 twin_layer_->ShouldUseGpuRasterization() == ShouldUseGpuRasterization())
846 twin_layer_->SyncTiling(tiling); 855 twin_layer_->SyncTiling(tiling);
847 856
848 return tiling; 857 return tiling;
849 } 858 }
850 859
851 void PictureLayerImpl::RemoveTiling(float contents_scale) { 860 void PictureLayerImpl::RemoveTiling(float contents_scale) {
852 for (size_t i = 0; i < tilings_->num_tilings(); ++i) { 861 for (size_t i = 0; i < tilings_->num_tilings(); ++i) {
853 PictureLayerTiling* tiling = tilings_->tiling_at(i); 862 PictureLayerTiling* tiling = tilings_->tiling_at(i);
854 if (tiling->contents_scale() == contents_scale) { 863 if (tiling->contents_scale() == contents_scale) {
855 tilings_->Remove(tiling); 864 tilings_->Remove(tiling);
856 break; 865 break;
857 } 866 }
858 } 867 }
859 if (tilings_->num_tilings() == 0) 868 if (tilings_->num_tilings() == 0)
860 ResetRasterScale(); 869 ResetRasterScale();
861 SanityCheckTilingState(); 870 SanityCheckTilingState();
862 } 871 }
863 872
864 void PictureLayerImpl::RemoveAllTilings() { 873 void PictureLayerImpl::RemoveAllTilings() {
865 tilings_->RemoveAllTilings(); 874 if (tilings_)
enne (OOO) 2014/03/06 21:28:46 When can this be NULL?
ajuma 2014/03/06 21:44:28 One situation is during the initial commit. During
875 tilings_->RemoveAllTilings();
866 // If there are no tilings, then raster scales are no longer meaningful. 876 // If there are no tilings, then raster scales are no longer meaningful.
867 ResetRasterScale(); 877 ResetRasterScale();
868 } 878 }
869 879
870 namespace { 880 namespace {
871 881
872 inline float PositiveRatio(float float1, float float2) { 882 inline float PositiveRatio(float float1, float float2) {
873 DCHECK_GT(float1, 0); 883 DCHECK_GT(float1, 0);
874 DCHECK_GT(float2, 0); 884 DCHECK_GT(float2, 0);
875 return float1 > float2 ? float1 / float2 : float2 / float1; 885 return float1 > float2 ? float1 / float2 : float2 / float1;
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after
1210 scoped_ptr<base::DictionaryValue> tile_data(new base::DictionaryValue); 1220 scoped_ptr<base::DictionaryValue> tile_data(new base::DictionaryValue);
1211 tile_data->Set("geometry_rect", 1221 tile_data->Set("geometry_rect",
1212 MathUtil::AsValue(iter.geometry_rect()).release()); 1222 MathUtil::AsValue(iter.geometry_rect()).release());
1213 if (*iter) 1223 if (*iter)
1214 tile_data->Set("tile", TracedValue::CreateIDRef(*iter).release()); 1224 tile_data->Set("tile", TracedValue::CreateIDRef(*iter).release());
1215 1225
1216 coverage_tiles->Append(tile_data.release()); 1226 coverage_tiles->Append(tile_data.release());
1217 } 1227 }
1218 state->Set("coverage_tiles", coverage_tiles.release()); 1228 state->Set("coverage_tiles", coverage_tiles.release());
1219 state->SetBoolean("is_using_lcd_text", is_using_lcd_text_); 1229 state->SetBoolean("is_using_lcd_text", is_using_lcd_text_);
1230 state->SetBoolean("using_gpu_rasterization", ShouldUseGpuRasterization());
1220 } 1231 }
1221 1232
1222 size_t PictureLayerImpl::GPUMemoryUsageInBytes() const { 1233 size_t PictureLayerImpl::GPUMemoryUsageInBytes() const {
1223 const_cast<PictureLayerImpl*>(this)->DoPostCommitInitializationIfNeeded(); 1234 const_cast<PictureLayerImpl*>(this)->DoPostCommitInitializationIfNeeded();
1224 return tilings_->GPUMemoryUsageInBytes(); 1235 return tilings_->GPUMemoryUsageInBytes();
1225 } 1236 }
1226 1237
1227 void PictureLayerImpl::RunMicroBenchmark(MicroBenchmarkImpl* benchmark) { 1238 void PictureLayerImpl::RunMicroBenchmark(MicroBenchmarkImpl* benchmark) {
1228 benchmark->RunOnLayer(this); 1239 benchmark->RunOnLayer(this);
1229 } 1240 }
1230 1241
1231 } // namespace cc 1242 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698