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 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
379 content_rect, | 377 content_rect, |
380 contents_opaque() ? content_rect : gfx::Rect(), | 378 contents_opaque() ? content_rect : gfx::Rect(), |
381 tiling->contents_scale(), | 379 tiling->contents_scale(), |
382 id())); | 380 id())); |
383 } | 381 } |
384 | 382 |
385 void PictureLayerImpl::UpdatePile(Tile* tile) { | 383 void PictureLayerImpl::UpdatePile(Tile* tile) { |
386 tile->set_picture_pile(pile_); | 384 tile->set_picture_pile(pile_); |
387 } | 385 } |
388 | 386 |
| 387 const Region* PictureLayerImpl::GetInvalidation() { |
| 388 return &invalidation_; |
| 389 } |
| 390 |
| 391 const PictureLayerTiling* PictureLayerImpl::GetTwinTiling( |
| 392 const PictureLayerTiling* tiling) { |
| 393 |
| 394 const PictureLayerImpl* other_layer = layer_tree_impl()->IsActiveTree() ? |
| 395 PendingTwin() : ActiveTwin(); |
| 396 if (!other_layer) |
| 397 return NULL; |
| 398 for (size_t i = 0; i < other_layer->tilings_->num_tilings(); ++i) |
| 399 if (other_layer->tilings_->tiling_at(i)->contents_scale() == |
| 400 tiling->contents_scale()) |
| 401 return other_layer->tilings_->tiling_at(i); |
| 402 return NULL; |
| 403 } |
| 404 |
389 gfx::Size PictureLayerImpl::CalculateTileSize( | 405 gfx::Size PictureLayerImpl::CalculateTileSize( |
390 gfx::Size current_tile_size, | |
391 gfx::Size content_bounds) { | 406 gfx::Size content_bounds) { |
392 if (is_mask_) { | 407 if (is_mask_) { |
393 int max_size = layer_tree_impl()->MaxTextureSize(); | 408 int max_size = layer_tree_impl()->MaxTextureSize(); |
394 return gfx::Size( | 409 return gfx::Size( |
395 std::min(max_size, content_bounds.width()), | 410 std::min(max_size, content_bounds.width()), |
396 std::min(max_size, content_bounds.height())); | 411 std::min(max_size, content_bounds.height())); |
397 } | 412 } |
398 | 413 |
399 gfx::Size default_tile_size = layer_tree_impl()->settings().default_tile_size; | 414 gfx::Size default_tile_size = layer_tree_impl()->settings().default_tile_size; |
400 gfx::Size max_untiled_content_size = | 415 gfx::Size max_untiled_content_size = |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
469 for (int y = 0; y < pile_->num_tiles_y(); ++y) { | 484 for (int y = 0; y < pile_->num_tiles_y(); ++y) { |
470 bool previously_had = other->pile_->HasRecordingAt(x, y); | 485 bool previously_had = other->pile_->HasRecordingAt(x, y); |
471 bool now_has = pile_->HasRecordingAt(x, y); | 486 bool now_has = pile_->HasRecordingAt(x, y); |
472 if (now_has || !previously_had) | 487 if (now_has || !previously_had) |
473 continue; | 488 continue; |
474 gfx::Rect layer_rect = pile_->tile_bounds(x, y); | 489 gfx::Rect layer_rect = pile_->tile_bounds(x, y); |
475 invalidation_.Union(layer_rect); | 490 invalidation_.Union(layer_rect); |
476 } | 491 } |
477 } | 492 } |
478 | 493 |
479 tilings_->CloneAll(*other->tilings_, invalidation_, MinimumContentsScale()); | 494 // Union in the other newly exposed regions as invalid. |
480 DCHECK(bounds() == tilings_->LayerBounds()); | 495 Region difference_region = Region(gfx::Rect(bounds())); |
| 496 difference_region.Subtract(gfx::Rect(other->bounds())); |
| 497 invalidation_.Union(difference_region); |
481 | 498 |
482 // It's a sad but unfortunate fact that PicturePile tiling edges do not line | 499 tilings_->CloneAll(*other->tilings_, MinimumContentsScale()); |
483 // up with PictureLayerTiling edges. Tiles can only be added if they are | 500 DCHECK(bounds() == tilings_->layer_bounds()); |
484 // entirely covered by recordings (that may come from multiple PicturePile | |
485 // tiles). This check happens in this class's CreateTile() call. | |
486 for (int x = 0; x < pile_->num_tiles_x(); ++x) { | |
487 for (int y = 0; y < pile_->num_tiles_y(); ++y) { | |
488 bool previously_had = other->pile_->HasRecordingAt(x, y); | |
489 bool now_has = pile_->HasRecordingAt(x, y); | |
490 if (!now_has || previously_had) | |
491 continue; | |
492 gfx::Rect layer_rect = pile_->tile_bounds(x, y); | |
493 tilings_->CreateTilesFromLayerRect(layer_rect); | |
494 } | |
495 } | |
496 } | 501 } |
497 | 502 |
498 void PictureLayerImpl::SyncTiling( | 503 void PictureLayerImpl::SyncTiling( |
499 const PictureLayerTiling* tiling, | 504 const PictureLayerTiling* tiling) { |
500 const Region& pending_layer_invalidation) { | |
501 if (!DrawsContent() || tiling->contents_scale() < MinimumContentsScale()) | 505 if (!DrawsContent() || tiling->contents_scale() < MinimumContentsScale()) |
502 return; | 506 return; |
503 tilings_->Clone(tiling, pending_layer_invalidation); | 507 tilings_->Clone(tiling); |
504 } | 508 } |
505 | 509 |
506 void PictureLayerImpl::SetIsMask(bool is_mask) { | 510 void PictureLayerImpl::SetIsMask(bool is_mask) { |
507 if (is_mask_ == is_mask) | 511 if (is_mask_ == is_mask) |
508 return; | 512 return; |
509 is_mask_ = is_mask; | 513 is_mask_ = is_mask; |
510 if (tilings_) | 514 if (tilings_) |
511 tilings_->RemoveAllTiles(); | 515 tilings_->RemoveAllTiles(); |
512 } | 516 } |
513 | 517 |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
593 } | 597 } |
594 | 598 |
595 PictureLayerTiling* PictureLayerImpl::AddTiling(float contents_scale) { | 599 PictureLayerTiling* PictureLayerImpl::AddTiling(float contents_scale) { |
596 DCHECK(contents_scale >= MinimumContentsScale()); | 600 DCHECK(contents_scale >= MinimumContentsScale()); |
597 | 601 |
598 PictureLayerTiling* tiling = tilings_->AddTiling(contents_scale); | 602 PictureLayerTiling* tiling = tilings_->AddTiling(contents_scale); |
599 | 603 |
600 const Region& recorded = pile_->recorded_region(); | 604 const Region& recorded = pile_->recorded_region(); |
601 DCHECK(!recorded.IsEmpty()); | 605 DCHECK(!recorded.IsEmpty()); |
602 | 606 |
603 for (Region::Iterator iter(recorded); iter.has_rect(); iter.next()) | |
604 tiling->CreateTilesFromLayerRect(iter.rect()); | |
605 | |
606 PictureLayerImpl* twin = | 607 PictureLayerImpl* twin = |
607 layer_tree_impl()->IsPendingTree() ? ActiveTwin() : PendingTwin(); | 608 layer_tree_impl()->IsPendingTree() ? ActiveTwin() : PendingTwin(); |
608 if (!twin) | 609 if (twin) |
609 return tiling; | 610 twin->SyncTiling(tiling); |
610 | |
611 if (layer_tree_impl()->IsPendingTree()) | |
612 twin->SyncTiling(tiling, invalidation_); | |
613 else | |
614 twin->SyncTiling(tiling, twin->invalidation_); | |
615 | 611 |
616 return tiling; | 612 return tiling; |
617 } | 613 } |
618 | 614 |
619 void PictureLayerImpl::RemoveTiling(float contents_scale) { | 615 void PictureLayerImpl::RemoveTiling(float contents_scale) { |
620 for (size_t i = 0; i < tilings_->num_tilings(); ++i) { | 616 for (size_t i = 0; i < tilings_->num_tilings(); ++i) { |
621 PictureLayerTiling* tiling = tilings_->tiling_at(i); | 617 PictureLayerTiling* tiling = tilings_->tiling_at(i); |
622 if (tiling->contents_scale() == contents_scale) { | 618 if (tiling->contents_scale() == contents_scale) { |
623 tilings_->Remove(tiling); | 619 tilings_->Remove(tiling); |
624 break; | 620 break; |
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
902 scoped_ptr<base::Value> PictureLayerImpl::AsValue() const { | 898 scoped_ptr<base::Value> PictureLayerImpl::AsValue() const { |
903 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue()); | 899 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue()); |
904 LayerImpl::AsValueInto(state.get()); | 900 LayerImpl::AsValueInto(state.get()); |
905 | 901 |
906 state->SetDouble("ideal_contents_scale", ideal_contents_scale_); | 902 state->SetDouble("ideal_contents_scale", ideal_contents_scale_); |
907 state->Set("tilings", tilings_->AsValue().release()); | 903 state->Set("tilings", tilings_->AsValue().release()); |
908 return state.PassAs<base::Value>(); | 904 return state.PassAs<base::Value>(); |
909 } | 905 } |
910 | 906 |
911 } // namespace cc | 907 } // namespace cc |
OLD | NEW |