OLD | NEW |
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 Loading... |
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 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
362 content_rect, | 360 content_rect, |
363 contents_opaque() ? content_rect : gfx::Rect(), | 361 contents_opaque() ? content_rect : gfx::Rect(), |
364 tiling->contents_scale(), | 362 tiling->contents_scale(), |
365 id())); | 363 id())); |
366 } | 364 } |
367 | 365 |
368 void PictureLayerImpl::UpdatePile(Tile* tile) { | 366 void PictureLayerImpl::UpdatePile(Tile* tile) { |
369 tile->set_picture_pile(pile_); | 367 tile->set_picture_pile(pile_); |
370 } | 368 } |
371 | 369 |
| 370 const Region* PictureLayerImpl::GetInvalidation() { |
| 371 return &invalidation_; |
| 372 } |
| 373 |
| 374 const PictureLayerTiling* PictureLayerImpl::GetTwinTiling( |
| 375 const PictureLayerTiling* tiling) { |
| 376 |
| 377 const PictureLayerImpl* other_layer = layer_tree_impl()->IsActiveTree() ? |
| 378 PendingTwin() : ActiveTwin(); |
| 379 if (!other_layer) |
| 380 return NULL; |
| 381 for (size_t i = 0; i < other_layer->tilings_->num_tilings(); ++i) |
| 382 if (other_layer->tilings_->tiling_at(i)->contents_scale() == |
| 383 tiling->contents_scale()) |
| 384 return other_layer->tilings_->tiling_at(i); |
| 385 return NULL; |
| 386 } |
| 387 |
372 gfx::Size PictureLayerImpl::CalculateTileSize( | 388 gfx::Size PictureLayerImpl::CalculateTileSize( |
373 gfx::Size current_tile_size, | |
374 gfx::Size content_bounds) { | 389 gfx::Size content_bounds) { |
375 if (is_mask_) { | 390 if (is_mask_) { |
376 int max_size = layer_tree_impl()->MaxTextureSize(); | 391 int max_size = layer_tree_impl()->MaxTextureSize(); |
377 return gfx::Size( | 392 return gfx::Size( |
378 std::min(max_size, content_bounds.width()), | 393 std::min(max_size, content_bounds.width()), |
379 std::min(max_size, content_bounds.height())); | 394 std::min(max_size, content_bounds.height())); |
380 } | 395 } |
381 | 396 |
382 gfx::Size default_tile_size = layer_tree_impl()->settings().default_tile_size; | 397 gfx::Size default_tile_size = layer_tree_impl()->settings().default_tile_size; |
383 gfx::Size max_untiled_content_size = | 398 gfx::Size max_untiled_content_size = |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
452 for (int y = 0; y < pile_->num_tiles_y(); ++y) { | 467 for (int y = 0; y < pile_->num_tiles_y(); ++y) { |
453 bool previously_had = other->pile_->HasRecordingAt(x, y); | 468 bool previously_had = other->pile_->HasRecordingAt(x, y); |
454 bool now_has = pile_->HasRecordingAt(x, y); | 469 bool now_has = pile_->HasRecordingAt(x, y); |
455 if (now_has || !previously_had) | 470 if (now_has || !previously_had) |
456 continue; | 471 continue; |
457 gfx::Rect layer_rect = pile_->tile_bounds(x, y); | 472 gfx::Rect layer_rect = pile_->tile_bounds(x, y); |
458 invalidation_.Union(layer_rect); | 473 invalidation_.Union(layer_rect); |
459 } | 474 } |
460 } | 475 } |
461 | 476 |
462 tilings_->CloneAll(*other->tilings_, invalidation_, MinimumContentsScale()); | 477 // Union in the other newly exposed regions as invalid. |
463 DCHECK(bounds() == tilings_->LayerBounds()); | 478 Region difference_region = Region(gfx::Rect(bounds())); |
| 479 difference_region.Subtract(gfx::Rect(other->bounds())); |
| 480 invalidation_.Union(difference_region); |
464 | 481 |
465 // It's a sad but unfortunate fact that PicturePile tiling edges do not line | 482 tilings_->CloneAll(*other->tilings_, MinimumContentsScale()); |
466 // up with PictureLayerTiling edges. Tiles can only be added if they are | 483 DCHECK(bounds() == tilings_->layer_bounds()); |
467 // entirely covered by recordings (that may come from multiple PicturePile | |
468 // tiles). This check happens in this class's CreateTile() call. | |
469 for (int x = 0; x < pile_->num_tiles_x(); ++x) { | |
470 for (int y = 0; y < pile_->num_tiles_y(); ++y) { | |
471 bool previously_had = other->pile_->HasRecordingAt(x, y); | |
472 bool now_has = pile_->HasRecordingAt(x, y); | |
473 if (!now_has || previously_had) | |
474 continue; | |
475 gfx::Rect layer_rect = pile_->tile_bounds(x, y); | |
476 tilings_->CreateTilesFromLayerRect(layer_rect); | |
477 } | |
478 } | |
479 } | 484 } |
480 | 485 |
481 void PictureLayerImpl::SyncTiling( | 486 void PictureLayerImpl::SyncTiling( |
482 const PictureLayerTiling* tiling, | 487 const PictureLayerTiling* tiling) { |
483 const Region& pending_layer_invalidation) { | |
484 if (!DrawsContent() || tiling->contents_scale() < MinimumContentsScale()) | 488 if (!DrawsContent() || tiling->contents_scale() < MinimumContentsScale()) |
485 return; | 489 return; |
486 tilings_->Clone(tiling, pending_layer_invalidation); | 490 tilings_->Clone(tiling); |
487 } | 491 } |
488 | 492 |
489 void PictureLayerImpl::SetIsMask(bool is_mask) { | 493 void PictureLayerImpl::SetIsMask(bool is_mask) { |
490 if (is_mask_ == is_mask) | 494 if (is_mask_ == is_mask) |
491 return; | 495 return; |
492 is_mask_ = is_mask; | 496 is_mask_ = is_mask; |
493 if (tilings_) | 497 if (tilings_) |
494 tilings_->RemoveAllTiles(); | 498 tilings_->RemoveAllTiles(); |
495 } | 499 } |
496 | 500 |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
576 } | 580 } |
577 | 581 |
578 PictureLayerTiling* PictureLayerImpl::AddTiling(float contents_scale) { | 582 PictureLayerTiling* PictureLayerImpl::AddTiling(float contents_scale) { |
579 DCHECK(contents_scale >= MinimumContentsScale()); | 583 DCHECK(contents_scale >= MinimumContentsScale()); |
580 | 584 |
581 PictureLayerTiling* tiling = tilings_->AddTiling(contents_scale); | 585 PictureLayerTiling* tiling = tilings_->AddTiling(contents_scale); |
582 | 586 |
583 const Region& recorded = pile_->recorded_region(); | 587 const Region& recorded = pile_->recorded_region(); |
584 DCHECK(!recorded.IsEmpty()); | 588 DCHECK(!recorded.IsEmpty()); |
585 | 589 |
586 for (Region::Iterator iter(recorded); iter.has_rect(); iter.next()) | |
587 tiling->CreateTilesFromLayerRect(iter.rect()); | |
588 | |
589 PictureLayerImpl* twin = | 590 PictureLayerImpl* twin = |
590 layer_tree_impl()->IsPendingTree() ? ActiveTwin() : PendingTwin(); | 591 layer_tree_impl()->IsPendingTree() ? ActiveTwin() : PendingTwin(); |
591 if (!twin) | 592 if (twin) |
592 return tiling; | 593 twin->SyncTiling(tiling); |
593 | |
594 if (layer_tree_impl()->IsPendingTree()) | |
595 twin->SyncTiling(tiling, invalidation_); | |
596 else | |
597 twin->SyncTiling(tiling, twin->invalidation_); | |
598 | 594 |
599 return tiling; | 595 return tiling; |
600 } | 596 } |
601 | 597 |
602 void PictureLayerImpl::RemoveTiling(float contents_scale) { | 598 void PictureLayerImpl::RemoveTiling(float contents_scale) { |
603 for (size_t i = 0; i < tilings_->num_tilings(); ++i) { | 599 for (size_t i = 0; i < tilings_->num_tilings(); ++i) { |
604 PictureLayerTiling* tiling = tilings_->tiling_at(i); | 600 PictureLayerTiling* tiling = tilings_->tiling_at(i); |
605 if (tiling->contents_scale() == contents_scale) { | 601 if (tiling->contents_scale() == contents_scale) { |
606 tilings_->Remove(tiling); | 602 tilings_->Remove(tiling); |
607 break; | 603 break; |
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
885 scoped_ptr<base::Value> PictureLayerImpl::AsValue() const { | 881 scoped_ptr<base::Value> PictureLayerImpl::AsValue() const { |
886 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue()); | 882 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue()); |
887 LayerImpl::AsValueInto(state.get()); | 883 LayerImpl::AsValueInto(state.get()); |
888 | 884 |
889 state->SetDouble("ideal_contents_scale", ideal_contents_scale_); | 885 state->SetDouble("ideal_contents_scale", ideal_contents_scale_); |
890 state->Set("tilings", tilings_->AsValue().release()); | 886 state->Set("tilings", tilings_->AsValue().release()); |
891 return state.PassAs<base::Value>(); | 887 return state.PassAs<base::Value>(); |
892 } | 888 } |
893 | 889 |
894 } // namespace cc | 890 } // namespace cc |
OLD | NEW |