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

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: Use a single switch with string values 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().rasterization_site) {
462 case LayerTreeSettings::CpuRasterization:
463 return false;
464 case LayerTreeSettings::HybridRasterization:
465 return has_gpu_rasterization_hint_;
466 case LayerTreeSettings::GpuRasterization:
467 return true;
459 } 468 }
469 NOTREACHED();
470 return false;
460 } 471 }
461 472
462 scoped_refptr<Tile> PictureLayerImpl::CreateTile(PictureLayerTiling* tiling, 473 scoped_refptr<Tile> PictureLayerImpl::CreateTile(PictureLayerTiling* tiling,
463 const gfx::Rect& content_rect) { 474 const gfx::Rect& content_rect) {
464 if (!pile_->CanRaster(tiling->contents_scale(), content_rect)) 475 if (!pile_->CanRaster(tiling->contents_scale(), content_rect))
465 return scoped_refptr<Tile>(); 476 return scoped_refptr<Tile>();
466 477
467 int flags = 0; 478 int flags = 0;
468 if (is_using_lcd_text_) 479 if (is_using_lcd_text_)
469 flags |= Tile::USE_LCD_TEXT; 480 flags |= Tile::USE_LCD_TEXT;
470 if (should_use_gpu_rasterization()) 481 if (ShouldUseGpuRasterization())
471 flags |= Tile::USE_GPU_RASTERIZATION; 482 flags |= Tile::USE_GPU_RASTERIZATION;
472 return layer_tree_impl()->tile_manager()->CreateTile( 483 return layer_tree_impl()->tile_manager()->CreateTile(
473 pile_.get(), 484 pile_.get(),
474 content_rect.size(), 485 content_rect.size(),
475 content_rect, 486 content_rect,
476 contents_opaque() ? content_rect : gfx::Rect(), 487 contents_opaque() ? content_rect : gfx::Rect(),
477 tiling->contents_scale(), 488 tiling->contents_scale(),
478 id(), 489 id(),
479 layer_tree_impl()->source_frame_number(), 490 layer_tree_impl()->source_frame_number(),
480 flags); 491 flags);
481 } 492 }
482 493
483 void PictureLayerImpl::UpdatePile(Tile* tile) { 494 void PictureLayerImpl::UpdatePile(Tile* tile) {
484 tile->set_picture_pile(pile_); 495 tile->set_picture_pile(pile_);
485 } 496 }
486 497
487 const Region* PictureLayerImpl::GetInvalidation() { 498 const Region* PictureLayerImpl::GetInvalidation() {
488 return &invalidation_; 499 return &invalidation_;
489 } 500 }
490 501
491 const PictureLayerTiling* PictureLayerImpl::GetTwinTiling( 502 const PictureLayerTiling* PictureLayerImpl::GetTwinTiling(
492 const PictureLayerTiling* tiling) const { 503 const PictureLayerTiling* tiling) const {
493 504
494 if (!twin_layer_ || twin_layer_->should_use_gpu_rasterization() != 505 if (!twin_layer_ ||
495 should_use_gpu_rasterization()) 506 twin_layer_->ShouldUseGpuRasterization() != ShouldUseGpuRasterization())
496 return NULL; 507 return NULL;
497 for (size_t i = 0; i < twin_layer_->tilings_->num_tilings(); ++i) 508 for (size_t i = 0; i < twin_layer_->tilings_->num_tilings(); ++i)
498 if (twin_layer_->tilings_->tiling_at(i)->contents_scale() == 509 if (twin_layer_->tilings_->tiling_at(i)->contents_scale() ==
499 tiling->contents_scale()) 510 tiling->contents_scale())
500 return twin_layer_->tilings_->tiling_at(i); 511 return twin_layer_->tilings_->tiling_at(i);
501 return NULL; 512 return NULL;
502 } 513 }
503 514
504 size_t PictureLayerImpl::GetMaxTilesForInterestArea() const { 515 size_t PictureLayerImpl::GetMaxTilesForInterestArea() const {
505 return layer_tree_impl()->settings().max_tiles_for_interest_area; 516 return layer_tree_impl()->settings().max_tiles_for_interest_area;
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after
834 845
835 PictureLayerTiling* PictureLayerImpl::AddTiling(float contents_scale) { 846 PictureLayerTiling* PictureLayerImpl::AddTiling(float contents_scale) {
836 DCHECK(CanHaveTilingWithScale(contents_scale)) << 847 DCHECK(CanHaveTilingWithScale(contents_scale)) <<
837 "contents_scale: " << contents_scale; 848 "contents_scale: " << contents_scale;
838 849
839 PictureLayerTiling* tiling = tilings_->AddTiling(contents_scale); 850 PictureLayerTiling* tiling = tilings_->AddTiling(contents_scale);
840 851
841 const Region& recorded = pile_->recorded_region(); 852 const Region& recorded = pile_->recorded_region();
842 DCHECK(!recorded.IsEmpty()); 853 DCHECK(!recorded.IsEmpty());
843 854
844 if (twin_layer_ && twin_layer_->should_use_gpu_rasterization() == 855 if (twin_layer_ &&
845 should_use_gpu_rasterization()) 856 twin_layer_->ShouldUseGpuRasterization() == ShouldUseGpuRasterization())
846 twin_layer_->SyncTiling(tiling); 857 twin_layer_->SyncTiling(tiling);
847 858
848 return tiling; 859 return tiling;
849 } 860 }
850 861
851 void PictureLayerImpl::RemoveTiling(float contents_scale) { 862 void PictureLayerImpl::RemoveTiling(float contents_scale) {
852 for (size_t i = 0; i < tilings_->num_tilings(); ++i) { 863 for (size_t i = 0; i < tilings_->num_tilings(); ++i) {
853 PictureLayerTiling* tiling = tilings_->tiling_at(i); 864 PictureLayerTiling* tiling = tilings_->tiling_at(i);
854 if (tiling->contents_scale() == contents_scale) { 865 if (tiling->contents_scale() == contents_scale) {
855 tilings_->Remove(tiling); 866 tilings_->Remove(tiling);
856 break; 867 break;
857 } 868 }
858 } 869 }
859 if (tilings_->num_tilings() == 0) 870 if (tilings_->num_tilings() == 0)
860 ResetRasterScale(); 871 ResetRasterScale();
861 SanityCheckTilingState(); 872 SanityCheckTilingState();
862 } 873 }
863 874
864 void PictureLayerImpl::RemoveAllTilings() { 875 void PictureLayerImpl::RemoveAllTilings() {
865 tilings_->RemoveAllTilings(); 876 if (tilings_)
877 tilings_->RemoveAllTilings();
866 // If there are no tilings, then raster scales are no longer meaningful. 878 // If there are no tilings, then raster scales are no longer meaningful.
867 ResetRasterScale(); 879 ResetRasterScale();
868 } 880 }
869 881
870 namespace { 882 namespace {
871 883
872 inline float PositiveRatio(float float1, float float2) { 884 inline float PositiveRatio(float float1, float float2) {
873 DCHECK_GT(float1, 0); 885 DCHECK_GT(float1, 0);
874 DCHECK_GT(float2, 0); 886 DCHECK_GT(float2, 0);
875 return float1 > float2 ? float1 / float2 : float2 / float1; 887 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); 1222 scoped_ptr<base::DictionaryValue> tile_data(new base::DictionaryValue);
1211 tile_data->Set("geometry_rect", 1223 tile_data->Set("geometry_rect",
1212 MathUtil::AsValue(iter.geometry_rect()).release()); 1224 MathUtil::AsValue(iter.geometry_rect()).release());
1213 if (*iter) 1225 if (*iter)
1214 tile_data->Set("tile", TracedValue::CreateIDRef(*iter).release()); 1226 tile_data->Set("tile", TracedValue::CreateIDRef(*iter).release());
1215 1227
1216 coverage_tiles->Append(tile_data.release()); 1228 coverage_tiles->Append(tile_data.release());
1217 } 1229 }
1218 state->Set("coverage_tiles", coverage_tiles.release()); 1230 state->Set("coverage_tiles", coverage_tiles.release());
1219 state->SetBoolean("is_using_lcd_text", is_using_lcd_text_); 1231 state->SetBoolean("is_using_lcd_text", is_using_lcd_text_);
1232 state->SetBoolean("using_gpu_rasterization", ShouldUseGpuRasterization());
1220 } 1233 }
1221 1234
1222 size_t PictureLayerImpl::GPUMemoryUsageInBytes() const { 1235 size_t PictureLayerImpl::GPUMemoryUsageInBytes() const {
1223 const_cast<PictureLayerImpl*>(this)->DoPostCommitInitializationIfNeeded(); 1236 const_cast<PictureLayerImpl*>(this)->DoPostCommitInitializationIfNeeded();
1224 return tilings_->GPUMemoryUsageInBytes(); 1237 return tilings_->GPUMemoryUsageInBytes();
1225 } 1238 }
1226 1239
1227 void PictureLayerImpl::RunMicroBenchmark(MicroBenchmarkImpl* benchmark) { 1240 void PictureLayerImpl::RunMicroBenchmark(MicroBenchmarkImpl* benchmark) {
1228 benchmark->RunOnLayer(this); 1241 benchmark->RunOnLayer(this);
1229 } 1242 }
1230 1243
1231 } // namespace cc 1244 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698