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

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

Issue 12865017: Makes tile-creation lazy (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fixing unit tests and an optimization to CreateTile Created 7 years, 8 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 8
9 #include "base/time.h" 9 #include "base/time.h"
10 #include "cc/base/math_util.h" 10 #include "cc/base/math_util.h"
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 } 54 }
55 55
56 scoped_ptr<LayerImpl> PictureLayerImpl::CreateLayerImpl( 56 scoped_ptr<LayerImpl> PictureLayerImpl::CreateLayerImpl(
57 LayerTreeImpl* tree_impl) { 57 LayerTreeImpl* tree_impl) {
58 return PictureLayerImpl::Create(tree_impl, id()).PassAs<LayerImpl>(); 58 return PictureLayerImpl::Create(tree_impl, id()).PassAs<LayerImpl>();
59 } 59 }
60 60
61 void PictureLayerImpl::CreateTilingSet() { 61 void PictureLayerImpl::CreateTilingSet() {
62 DCHECK(layer_tree_impl()->IsPendingTree()); 62 DCHECK(layer_tree_impl()->IsPendingTree());
63 DCHECK(!tilings_); 63 DCHECK(!tilings_);
64 tilings_.reset(new PictureLayerTilingSet(this)); 64 tilings_.reset(new PictureLayerTilingSet(this, bounds()));
65 tilings_->SetLayerBounds(bounds());
66 } 65 }
67 66
68 void PictureLayerImpl::TransferTilingSet( 67 void PictureLayerImpl::TransferTilingSet(
69 scoped_ptr<PictureLayerTilingSet> tilings) { 68 scoped_ptr<PictureLayerTilingSet> tilings) {
70 DCHECK(layer_tree_impl()->IsActiveTree()); 69 DCHECK(layer_tree_impl()->IsActiveTree());
71 tilings->SetClient(this); 70 tilings->SetClient(this);
72 tilings_ = tilings.Pass(); 71 tilings_ = tilings.Pass();
73 } 72 }
74 73
75 void PictureLayerImpl::PushPropertiesTo(LayerImpl* base_layer) { 74 void PictureLayerImpl::PushPropertiesTo(LayerImpl* base_layer) {
76 LayerImpl::PushPropertiesTo(base_layer); 75 LayerImpl::PushPropertiesTo(base_layer);
77 76
78 PictureLayerImpl* layer_impl = static_cast<PictureLayerImpl*>(base_layer); 77 PictureLayerImpl* layer_impl = static_cast<PictureLayerImpl*>(base_layer);
79 78
80 layer_impl->SetIsMask(is_mask_); 79 layer_impl->SetIsMask(is_mask_);
81 layer_impl->TransferTilingSet(tilings_.Pass()); 80 layer_impl->TransferTilingSet(tilings_.Pass());
82 layer_impl->pile_ = pile_; 81 layer_impl->pile_ = pile_;
83 pile_ = PicturePileImpl::Create(is_using_lcd_text_); 82 pile_ = PicturePileImpl::Create(is_using_lcd_text_);
84 83
85 layer_impl->raster_page_scale_ = raster_page_scale_; 84 layer_impl->raster_page_scale_ = raster_page_scale_;
86 layer_impl->raster_device_scale_ = raster_device_scale_; 85 layer_impl->raster_device_scale_ = raster_device_scale_;
87 layer_impl->raster_source_scale_ = raster_source_scale_; 86 layer_impl->raster_source_scale_ = raster_source_scale_;
88 layer_impl->raster_contents_scale_ = raster_contents_scale_; 87 layer_impl->raster_contents_scale_ = raster_contents_scale_;
89 layer_impl->low_res_raster_contents_scale_ = low_res_raster_contents_scale_; 88 layer_impl->low_res_raster_contents_scale_ = low_res_raster_contents_scale_;
90 layer_impl->is_using_lcd_text_ = is_using_lcd_text_; 89 layer_impl->is_using_lcd_text_ = is_using_lcd_text_;
91 } 90 }
92 91
93
94 void PictureLayerImpl::AppendQuads(QuadSink* quad_sink, 92 void PictureLayerImpl::AppendQuads(QuadSink* quad_sink,
95 AppendQuadsData* append_quads_data) { 93 AppendQuadsData* append_quads_data) {
96 const gfx::Rect& rect = visible_content_rect(); 94 const gfx::Rect& rect = visible_content_rect();
97 gfx::Rect content_rect(content_bounds()); 95 gfx::Rect content_rect(content_bounds());
98 96
99 SharedQuadState* shared_quad_state = 97 SharedQuadState* shared_quad_state =
100 quad_sink->UseSharedQuadState(CreateSharedQuadState()); 98 quad_sink->UseSharedQuadState(CreateSharedQuadState());
101 AppendDebugBorderQuad(quad_sink, shared_quad_state, append_quads_data); 99 AppendDebugBorderQuad(quad_sink, shared_quad_state, append_quads_data);
102 100
103 bool clipped = false; 101 bool clipped = false;
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 content_rect, 363 content_rect,
366 contents_opaque() ? content_rect : gfx::Rect(), 364 contents_opaque() ? content_rect : gfx::Rect(),
367 tiling->contents_scale(), 365 tiling->contents_scale(),
368 id())); 366 id()));
369 } 367 }
370 368
371 void PictureLayerImpl::UpdatePile(Tile* tile) { 369 void PictureLayerImpl::UpdatePile(Tile* tile) {
372 tile->set_picture_pile(pile_); 370 tile->set_picture_pile(pile_);
373 } 371 }
374 372
373 const Region* PictureLayerImpl::GetInvalidation() {
374 return &invalidation_;
375 }
376
377 const PictureLayerTiling* PictureLayerImpl::GetTwinTiling(
378 const PictureLayerTiling* tiling) {
379
380 const PictureLayerImpl* other_layer = layer_tree_impl()->IsActiveTree() ?
381 PendingTwin() : ActiveTwin();
382 if (!other_layer)
383 return NULL;
384 for (size_t i = 0; i < other_layer->tilings_->num_tilings(); ++i)
385 if (other_layer->tilings_->tiling_at(i)->contents_scale() ==
386 tiling->contents_scale())
387 return other_layer->tilings_->tiling_at(i);
388 return NULL;
389 }
390
375 gfx::Size PictureLayerImpl::CalculateTileSize( 391 gfx::Size PictureLayerImpl::CalculateTileSize(
376 gfx::Size current_tile_size,
377 gfx::Size content_bounds) { 392 gfx::Size content_bounds) {
378 if (is_mask_) { 393 if (is_mask_) {
379 int max_size = layer_tree_impl()->MaxTextureSize(); 394 int max_size = layer_tree_impl()->MaxTextureSize();
380 return gfx::Size( 395 return gfx::Size(
381 std::min(max_size, content_bounds.width()), 396 std::min(max_size, content_bounds.width()),
382 std::min(max_size, content_bounds.height())); 397 std::min(max_size, content_bounds.height()));
383 } 398 }
384 399
385 gfx::Size default_tile_size = layer_tree_impl()->settings().default_tile_size; 400 gfx::Size default_tile_size = layer_tree_impl()->settings().default_tile_size;
386 gfx::Size max_untiled_content_size = 401 gfx::Size max_untiled_content_size =
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
457 for (int y = 0; y < pile_->num_tiles_y(); ++y) { 472 for (int y = 0; y < pile_->num_tiles_y(); ++y) {
458 bool previously_had = other->pile_->HasRecordingAt(x, y); 473 bool previously_had = other->pile_->HasRecordingAt(x, y);
459 bool now_has = pile_->HasRecordingAt(x, y); 474 bool now_has = pile_->HasRecordingAt(x, y);
460 if (now_has || !previously_had) 475 if (now_has || !previously_had)
461 continue; 476 continue;
462 gfx::Rect layer_rect = pile_->tile_bounds(x, y); 477 gfx::Rect layer_rect = pile_->tile_bounds(x, y);
463 invalidation_.Union(layer_rect); 478 invalidation_.Union(layer_rect);
464 } 479 }
465 } 480 }
466 481
467 tilings_->CloneAll(*other->tilings_, invalidation_, MinimumContentsScale()); 482 // Union in the other newly exposed regions as invalid.
468 DCHECK(bounds() == tilings_->LayerBounds()); 483 Region difference_region = Region(gfx::Rect(bounds()));
484 difference_region.Subtract(gfx::Rect(other->bounds()));
485 invalidation_.Union(difference_region);
469 486
470 // It's a sad but unfortunate fact that PicturePile tiling edges do not line 487 tilings_->CloneAll(*other->tilings_, MinimumContentsScale());
471 // up with PictureLayerTiling edges. Tiles can only be added if they are 488 DCHECK(bounds() == tilings_->layer_bounds());
472 // entirely covered by recordings (that may come from multiple PicturePile
473 // tiles). This check happens in this class's CreateTile() call.
474 for (int x = 0; x < pile_->num_tiles_x(); ++x) {
475 for (int y = 0; y < pile_->num_tiles_y(); ++y) {
476 bool previously_had = other->pile_->HasRecordingAt(x, y);
477 bool now_has = pile_->HasRecordingAt(x, y);
478 if (!now_has || previously_had)
479 continue;
480 gfx::Rect layer_rect = pile_->tile_bounds(x, y);
481 tilings_->CreateTilesFromLayerRect(layer_rect);
482 }
483 }
484 } 489 }
485 490
486 void PictureLayerImpl::SyncTiling( 491 void PictureLayerImpl::SyncTiling(
487 const PictureLayerTiling* tiling, 492 const PictureLayerTiling* tiling) {
488 const Region& pending_layer_invalidation) {
489 if (!DrawsContent() || tiling->contents_scale() < MinimumContentsScale()) 493 if (!DrawsContent() || tiling->contents_scale() < MinimumContentsScale())
490 return; 494 return;
491 tilings_->Clone(tiling, pending_layer_invalidation); 495 tilings_->Clone(tiling);
492 } 496 }
493 497
494 void PictureLayerImpl::SetIsMask(bool is_mask) { 498 void PictureLayerImpl::SetIsMask(bool is_mask) {
495 if (is_mask_ == is_mask) 499 if (is_mask_ == is_mask)
496 return; 500 return;
497 is_mask_ = is_mask; 501 is_mask_ = is_mask;
498 if (tilings_) 502 if (tilings_)
499 tilings_->RemoveAllTiles(); 503 tilings_->RemoveAllTiles();
500 } 504 }
501 505
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
564 } 568 }
565 569
566 PictureLayerTiling* PictureLayerImpl::AddTiling(float contents_scale) { 570 PictureLayerTiling* PictureLayerImpl::AddTiling(float contents_scale) {
567 DCHECK(contents_scale >= MinimumContentsScale()); 571 DCHECK(contents_scale >= MinimumContentsScale());
568 572
569 PictureLayerTiling* tiling = tilings_->AddTiling(contents_scale); 573 PictureLayerTiling* tiling = tilings_->AddTiling(contents_scale);
570 574
571 const Region& recorded = pile_->recorded_region(); 575 const Region& recorded = pile_->recorded_region();
572 DCHECK(!recorded.IsEmpty()); 576 DCHECK(!recorded.IsEmpty());
573 577
574 for (Region::Iterator iter(recorded); iter.has_rect(); iter.next())
575 tiling->CreateTilesFromLayerRect(iter.rect());
576
577 PictureLayerImpl* twin = 578 PictureLayerImpl* twin =
578 layer_tree_impl()->IsPendingTree() ? ActiveTwin() : PendingTwin(); 579 layer_tree_impl()->IsPendingTree() ? ActiveTwin() : PendingTwin();
579 if (!twin) 580 if (twin)
580 return tiling; 581 twin->SyncTiling(tiling);
581
582 if (layer_tree_impl()->IsPendingTree())
583 twin->SyncTiling(tiling, invalidation_);
584 else
585 twin->SyncTiling(tiling, twin->invalidation_);
586 582
587 return tiling; 583 return tiling;
588 } 584 }
589 585
590 void PictureLayerImpl::RemoveTiling(float contents_scale) { 586 void PictureLayerImpl::RemoveTiling(float contents_scale) {
591 for (size_t i = 0; i < tilings_->num_tilings(); ++i) { 587 for (size_t i = 0; i < tilings_->num_tilings(); ++i) {
592 PictureLayerTiling* tiling = tilings_->tiling_at(i); 588 PictureLayerTiling* tiling = tilings_->tiling_at(i);
593 if (tiling->contents_scale() == contents_scale) { 589 if (tiling->contents_scale() == contents_scale) {
594 tilings_->Remove(tiling); 590 tilings_->Remove(tiling);
595 break; 591 break;
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
842 if (layer_tree_impl()->IsActiveTree() && 838 if (layer_tree_impl()->IsActiveTree() &&
843 pending_layer->is_using_lcd_text_ == is_using_lcd_text_) 839 pending_layer->is_using_lcd_text_ == is_using_lcd_text_)
844 return; 840 return;
845 841
846 // Further tiles created due to new tilings should be considered invalidated. 842 // Further tiles created due to new tilings should be considered invalidated.
847 pending_layer->invalidation_.Union(gfx::Rect(bounds())); 843 pending_layer->invalidation_.Union(gfx::Rect(bounds()));
848 pending_layer->is_using_lcd_text_ = is_using_lcd_text_; 844 pending_layer->is_using_lcd_text_ = is_using_lcd_text_;
849 pending_layer->pile_ = PicturePileImpl::CreateFromOther(pending_layer->pile_, 845 pending_layer->pile_ = PicturePileImpl::CreateFromOther(pending_layer->pile_,
850 is_using_lcd_text_); 846 is_using_lcd_text_);
851 847
852 // TODO(enne): if we tracked text regions, we could just invalidate those
853 // directly rather than tossing away every tile.
854 pending_layer->tilings_->Invalidate(gfx::Rect(bounds()));
enne (OOO) 2013/04/05 21:30:02 Where do tiles get recreated here because of this
whunt 2013/04/05 21:33:25 Whoops, forgot to handle this. I'll fix it.
855 } 848 }
856 849
857 void PictureLayerImpl::GetDebugBorderProperties( 850 void PictureLayerImpl::GetDebugBorderProperties(
858 SkColor* color, 851 SkColor* color,
859 float* width) const { 852 float* width) const {
860 *color = DebugColors::TiledContentLayerBorderColor(); 853 *color = DebugColors::TiledContentLayerBorderColor();
861 *width = DebugColors::TiledContentLayerBorderWidth(layer_tree_impl()); 854 *width = DebugColors::TiledContentLayerBorderWidth(layer_tree_impl());
862 } 855 }
863 856
864 scoped_ptr<base::Value> PictureLayerImpl::AsValue() const { 857 scoped_ptr<base::Value> PictureLayerImpl::AsValue() const {
865 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue()); 858 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue());
866 LayerImpl::AsValueInto(state.get()); 859 LayerImpl::AsValueInto(state.get());
867 860
868 state->SetDouble("ideal_contents_scale", ideal_contents_scale_); 861 state->SetDouble("ideal_contents_scale", ideal_contents_scale_);
869 state->Set("tilings", tilings_->AsValue().release()); 862 state->Set("tilings", tilings_->AsValue().release());
870 return state.PassAs<base::Value>(); 863 return state.PassAs<base::Value>();
871 } 864 }
872 865
873 } // namespace cc 866 } // 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