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

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

Issue 192973002: Add a GPU rasterization hint to cc::PictureLayer (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased 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
« no previous file with comments | « cc/layers/picture_layer_impl.h ('k') | cc/layers/picture_layer_impl_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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().rasterization_site == 57 has_gpu_rasterization_hint_(false) {}
58 LayerTreeSettings::GpuRasterization) {}
59 58
60 PictureLayerImpl::~PictureLayerImpl() {} 59 PictureLayerImpl::~PictureLayerImpl() {}
61 60
62 const char* PictureLayerImpl::LayerTypeAsString() const { 61 const char* PictureLayerImpl::LayerTypeAsString() const {
63 return "cc::PictureLayerImpl"; 62 return "cc::PictureLayerImpl";
64 } 63 }
65 64
66 scoped_ptr<LayerImpl> PictureLayerImpl::CreateLayerImpl( 65 scoped_ptr<LayerImpl> PictureLayerImpl::CreateLayerImpl(
67 LayerTreeImpl* tree_impl) { 66 LayerTreeImpl* tree_impl) {
68 return PictureLayerImpl::Create(tree_impl, id()).PassAs<LayerImpl>(); 67 return PictureLayerImpl::Create(tree_impl, id()).PassAs<LayerImpl>();
(...skipping 16 matching lines...) Expand all
85 84
86 LayerImpl::PushPropertiesTo(base_layer); 85 LayerImpl::PushPropertiesTo(base_layer);
87 86
88 // 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
89 // disappears. 88 // disappears.
90 layer_impl->twin_layer_ = NULL; 89 layer_impl->twin_layer_ = NULL;
91 twin_layer_ = NULL; 90 twin_layer_ = NULL;
92 91
93 layer_impl->SetIsMask(is_mask_); 92 layer_impl->SetIsMask(is_mask_);
94 layer_impl->pile_ = pile_; 93 layer_impl->pile_ = pile_;
94 layer_impl->SetHasGpuRasterizationHint(has_gpu_rasterization_hint_);
95 95
96 // 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
97 // an extra invalidation in SyncFromActiveLayer. 97 // an extra invalidation in SyncFromActiveLayer.
98 layer_impl->tilings_.swap(tilings_); 98 layer_impl->tilings_.swap(tilings_);
99 layer_impl->tilings_->SetClient(layer_impl); 99 layer_impl->tilings_->SetClient(layer_impl);
100 if (tilings_) 100 if (tilings_)
101 tilings_->SetClient(this); 101 tilings_->SetClient(this);
102 102
103 layer_impl->raster_page_scale_ = raster_page_scale_; 103 layer_impl->raster_page_scale_ = raster_page_scale_;
104 layer_impl->raster_device_scale_ = raster_device_scale_; 104 layer_impl->raster_device_scale_ = raster_device_scale_;
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after
459 *contents_scale_x = max_contents_scale; 459 *contents_scale_x = max_contents_scale;
460 *contents_scale_y = max_contents_scale; 460 *contents_scale_y = max_contents_scale;
461 *content_bounds = gfx::ToCeiledSize( 461 *content_bounds = gfx::ToCeiledSize(
462 gfx::ScaleSize(bounds(), max_contents_scale, max_contents_scale)); 462 gfx::ScaleSize(bounds(), max_contents_scale, max_contents_scale));
463 } 463 }
464 464
465 skia::RefPtr<SkPicture> PictureLayerImpl::GetPicture() { 465 skia::RefPtr<SkPicture> PictureLayerImpl::GetPicture() {
466 return pile_->GetFlattenedPicture(); 466 return pile_->GetFlattenedPicture();
467 } 467 }
468 468
469 void PictureLayerImpl::SetShouldUseGpuRasterization( 469 void PictureLayerImpl::SetHasGpuRasterizationHint(bool has_hint) {
470 bool should_use_gpu_rasterization) { 470 bool old_should_use_gpu_rasterization = ShouldUseGpuRasterization();
471 if (should_use_gpu_rasterization != should_use_gpu_rasterization_) { 471 has_gpu_rasterization_hint_ = has_hint;
472 should_use_gpu_rasterization_ = should_use_gpu_rasterization; 472 if (ShouldUseGpuRasterization() != old_should_use_gpu_rasterization)
473 RemoveAllTilings(); 473 RemoveAllTilings();
474 } else { 474 }
475 should_use_gpu_rasterization_ = should_use_gpu_rasterization; 475
476 bool PictureLayerImpl::ShouldUseGpuRasterization() const {
477 switch (layer_tree_impl()->settings().rasterization_site) {
478 case LayerTreeSettings::CpuRasterization:
479 return false;
480 case LayerTreeSettings::HybridRasterization:
481 return has_gpu_rasterization_hint_;
482 case LayerTreeSettings::GpuRasterization:
483 return true;
476 } 484 }
485 NOTREACHED();
486 return false;
477 } 487 }
478 488
479 scoped_refptr<Tile> PictureLayerImpl::CreateTile(PictureLayerTiling* tiling, 489 scoped_refptr<Tile> PictureLayerImpl::CreateTile(PictureLayerTiling* tiling,
480 const gfx::Rect& content_rect) { 490 const gfx::Rect& content_rect) {
481 if (!pile_->CanRaster(tiling->contents_scale(), content_rect)) 491 if (!pile_->CanRaster(tiling->contents_scale(), content_rect))
482 return scoped_refptr<Tile>(); 492 return scoped_refptr<Tile>();
483 493
484 int flags = 0; 494 int flags = 0;
485 if (is_using_lcd_text_) 495 if (is_using_lcd_text_)
486 flags |= Tile::USE_LCD_TEXT; 496 flags |= Tile::USE_LCD_TEXT;
487 if (should_use_gpu_rasterization()) 497 if (ShouldUseGpuRasterization())
488 flags |= Tile::USE_GPU_RASTERIZATION; 498 flags |= Tile::USE_GPU_RASTERIZATION;
489 return layer_tree_impl()->tile_manager()->CreateTile( 499 return layer_tree_impl()->tile_manager()->CreateTile(
490 pile_.get(), 500 pile_.get(),
491 content_rect.size(), 501 content_rect.size(),
492 content_rect, 502 content_rect,
493 contents_opaque() ? content_rect : gfx::Rect(), 503 contents_opaque() ? content_rect : gfx::Rect(),
494 tiling->contents_scale(), 504 tiling->contents_scale(),
495 id(), 505 id(),
496 layer_tree_impl()->source_frame_number(), 506 layer_tree_impl()->source_frame_number(),
497 flags); 507 flags);
498 } 508 }
499 509
500 void PictureLayerImpl::UpdatePile(Tile* tile) { 510 void PictureLayerImpl::UpdatePile(Tile* tile) {
501 tile->set_picture_pile(pile_); 511 tile->set_picture_pile(pile_);
502 } 512 }
503 513
504 const Region* PictureLayerImpl::GetInvalidation() { 514 const Region* PictureLayerImpl::GetInvalidation() {
505 return &invalidation_; 515 return &invalidation_;
506 } 516 }
507 517
508 const PictureLayerTiling* PictureLayerImpl::GetTwinTiling( 518 const PictureLayerTiling* PictureLayerImpl::GetTwinTiling(
509 const PictureLayerTiling* tiling) const { 519 const PictureLayerTiling* tiling) const {
510 520
511 if (!twin_layer_ || twin_layer_->should_use_gpu_rasterization() != 521 if (!twin_layer_ ||
512 should_use_gpu_rasterization()) 522 twin_layer_->ShouldUseGpuRasterization() != ShouldUseGpuRasterization())
513 return NULL; 523 return NULL;
514 for (size_t i = 0; i < twin_layer_->tilings_->num_tilings(); ++i) 524 for (size_t i = 0; i < twin_layer_->tilings_->num_tilings(); ++i)
515 if (twin_layer_->tilings_->tiling_at(i)->contents_scale() == 525 if (twin_layer_->tilings_->tiling_at(i)->contents_scale() ==
516 tiling->contents_scale()) 526 tiling->contents_scale())
517 return twin_layer_->tilings_->tiling_at(i); 527 return twin_layer_->tilings_->tiling_at(i);
518 return NULL; 528 return NULL;
519 } 529 }
520 530
521 size_t PictureLayerImpl::GetMaxTilesForInterestArea() const { 531 size_t PictureLayerImpl::GetMaxTilesForInterestArea() const {
522 return layer_tree_impl()->settings().max_tiles_for_interest_area; 532 return layer_tree_impl()->settings().max_tiles_for_interest_area;
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after
851 861
852 PictureLayerTiling* PictureLayerImpl::AddTiling(float contents_scale) { 862 PictureLayerTiling* PictureLayerImpl::AddTiling(float contents_scale) {
853 DCHECK(CanHaveTilingWithScale(contents_scale)) << 863 DCHECK(CanHaveTilingWithScale(contents_scale)) <<
854 "contents_scale: " << contents_scale; 864 "contents_scale: " << contents_scale;
855 865
856 PictureLayerTiling* tiling = tilings_->AddTiling(contents_scale); 866 PictureLayerTiling* tiling = tilings_->AddTiling(contents_scale);
857 867
858 const Region& recorded = pile_->recorded_region(); 868 const Region& recorded = pile_->recorded_region();
859 DCHECK(!recorded.IsEmpty()); 869 DCHECK(!recorded.IsEmpty());
860 870
861 if (twin_layer_ && twin_layer_->should_use_gpu_rasterization() == 871 if (twin_layer_ &&
862 should_use_gpu_rasterization()) 872 twin_layer_->ShouldUseGpuRasterization() == ShouldUseGpuRasterization())
863 twin_layer_->SyncTiling(tiling); 873 twin_layer_->SyncTiling(tiling);
864 874
865 return tiling; 875 return tiling;
866 } 876 }
867 877
868 void PictureLayerImpl::RemoveTiling(float contents_scale) { 878 void PictureLayerImpl::RemoveTiling(float contents_scale) {
869 for (size_t i = 0; i < tilings_->num_tilings(); ++i) { 879 for (size_t i = 0; i < tilings_->num_tilings(); ++i) {
870 PictureLayerTiling* tiling = tilings_->tiling_at(i); 880 PictureLayerTiling* tiling = tilings_->tiling_at(i);
871 if (tiling->contents_scale() == contents_scale) { 881 if (tiling->contents_scale() == contents_scale) {
872 tilings_->Remove(tiling); 882 tilings_->Remove(tiling);
873 break; 883 break;
874 } 884 }
875 } 885 }
876 if (tilings_->num_tilings() == 0) 886 if (tilings_->num_tilings() == 0)
877 ResetRasterScale(); 887 ResetRasterScale();
878 SanityCheckTilingState(); 888 SanityCheckTilingState();
879 } 889 }
880 890
881 void PictureLayerImpl::RemoveAllTilings() { 891 void PictureLayerImpl::RemoveAllTilings() {
882 tilings_->RemoveAllTilings(); 892 if (tilings_)
893 tilings_->RemoveAllTilings();
883 // If there are no tilings, then raster scales are no longer meaningful. 894 // If there are no tilings, then raster scales are no longer meaningful.
884 ResetRasterScale(); 895 ResetRasterScale();
885 } 896 }
886 897
887 namespace { 898 namespace {
888 899
889 inline float PositiveRatio(float float1, float float2) { 900 inline float PositiveRatio(float float1, float float2) {
890 DCHECK_GT(float1, 0); 901 DCHECK_GT(float1, 0);
891 DCHECK_GT(float2, 0); 902 DCHECK_GT(float2, 0);
892 return float1 > float2 ? float1 / float2 : float2 / float1; 903 return float1 > float2 ? float1 / float2 : float2 / float1;
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after
1227 scoped_ptr<base::DictionaryValue> tile_data(new base::DictionaryValue); 1238 scoped_ptr<base::DictionaryValue> tile_data(new base::DictionaryValue);
1228 tile_data->Set("geometry_rect", 1239 tile_data->Set("geometry_rect",
1229 MathUtil::AsValue(iter.geometry_rect()).release()); 1240 MathUtil::AsValue(iter.geometry_rect()).release());
1230 if (*iter) 1241 if (*iter)
1231 tile_data->Set("tile", TracedValue::CreateIDRef(*iter).release()); 1242 tile_data->Set("tile", TracedValue::CreateIDRef(*iter).release());
1232 1243
1233 coverage_tiles->Append(tile_data.release()); 1244 coverage_tiles->Append(tile_data.release());
1234 } 1245 }
1235 state->Set("coverage_tiles", coverage_tiles.release()); 1246 state->Set("coverage_tiles", coverage_tiles.release());
1236 state->SetBoolean("is_using_lcd_text", is_using_lcd_text_); 1247 state->SetBoolean("is_using_lcd_text", is_using_lcd_text_);
1248 state->SetBoolean("using_gpu_rasterization", ShouldUseGpuRasterization());
1237 } 1249 }
1238 1250
1239 size_t PictureLayerImpl::GPUMemoryUsageInBytes() const { 1251 size_t PictureLayerImpl::GPUMemoryUsageInBytes() const {
1240 const_cast<PictureLayerImpl*>(this)->DoPostCommitInitializationIfNeeded(); 1252 const_cast<PictureLayerImpl*>(this)->DoPostCommitInitializationIfNeeded();
1241 return tilings_->GPUMemoryUsageInBytes(); 1253 return tilings_->GPUMemoryUsageInBytes();
1242 } 1254 }
1243 1255
1244 void PictureLayerImpl::RunMicroBenchmark(MicroBenchmarkImpl* benchmark) { 1256 void PictureLayerImpl::RunMicroBenchmark(MicroBenchmarkImpl* benchmark) {
1245 benchmark->RunOnLayer(this); 1257 benchmark->RunOnLayer(this);
1246 } 1258 }
1247 1259
1248 } // namespace cc 1260 } // namespace cc
OLDNEW
« no previous file with comments | « cc/layers/picture_layer_impl.h ('k') | cc/layers/picture_layer_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698