| OLD | NEW |
| 1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 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/layer_impl.h" | 5 #include "cc/layer_impl.h" |
| 6 | 6 |
| 7 #include "base/debug/trace_event.h" | 7 #include "base/debug/trace_event.h" |
| 8 #include "base/stringprintf.h" | 8 #include "base/stringprintf.h" |
| 9 #include "cc/debug_border_draw_quad.h" | 9 #include "cc/debug_border_draw_quad.h" |
| 10 #include "cc/debug_colors.h" | 10 #include "cc/debug_colors.h" |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 { | 60 { |
| 61 #ifndef NDEBUG | 61 #ifndef NDEBUG |
| 62 DCHECK(!m_betweenWillDrawAndDidDraw); | 62 DCHECK(!m_betweenWillDrawAndDidDraw); |
| 63 #endif | 63 #endif |
| 64 } | 64 } |
| 65 | 65 |
| 66 void LayerImpl::addChild(scoped_ptr<LayerImpl> child) | 66 void LayerImpl::addChild(scoped_ptr<LayerImpl> child) |
| 67 { | 67 { |
| 68 child->setParent(this); | 68 child->setParent(this); |
| 69 m_children.append(child.Pass()); | 69 m_children.append(child.Pass()); |
| 70 if (m_layerTreeHostImpl) |
| 71 m_layerTreeHostImpl->setNeedsUpdateLayers(); |
| 70 } | 72 } |
| 71 | 73 |
| 72 void LayerImpl::removeFromParent() | 74 void LayerImpl::removeFromParent() |
| 73 { | 75 { |
| 74 if (!m_parent) | 76 if (!m_parent) |
| 75 return; | 77 return; |
| 76 | 78 |
| 77 LayerImpl* parent = m_parent; | 79 LayerImpl* parent = m_parent; |
| 78 m_parent = 0; | 80 m_parent = 0; |
| 79 | 81 |
| 80 for (size_t i = 0; i < parent->m_children.size(); ++i) { | 82 for (size_t i = 0; i < parent->m_children.size(); ++i) { |
| 81 if (parent->m_children[i] == this) { | 83 if (parent->m_children[i] == this) { |
| 82 parent->m_children.remove(i); | 84 parent->m_children.remove(i); |
| 85 if (m_layerTreeHostImpl) |
| 86 m_layerTreeHostImpl->setNeedsUpdateLayers(); |
| 83 return; | 87 return; |
| 84 } | 88 } |
| 85 } | 89 } |
| 86 } | 90 } |
| 87 | 91 |
| 88 void LayerImpl::removeAllChildren() | 92 void LayerImpl::removeAllChildren() |
| 89 { | 93 { |
| 90 while (m_children.size()) | 94 while (m_children.size()) |
| 91 m_children[0]->removeFromParent(); | 95 m_children[0]->removeFromParent(); |
| 92 } | 96 } |
| 93 | 97 |
| 94 void LayerImpl::clearChildList() | 98 void LayerImpl::clearChildList() |
| 95 { | 99 { |
| 96 m_children.clear(); | 100 m_children.clear(); |
| 101 if (m_layerTreeHostImpl) |
| 102 m_layerTreeHostImpl->setNeedsUpdateLayers(); |
| 97 } | 103 } |
| 98 | 104 |
| 99 void LayerImpl::createRenderSurface() | 105 void LayerImpl::createRenderSurface() |
| 100 { | 106 { |
| 101 DCHECK(!m_drawProperties.render_surface); | 107 DCHECK(!m_drawProperties.render_surface); |
| 102 m_drawProperties.render_surface = make_scoped_ptr(new RenderSurfaceImpl(this
)); | 108 m_drawProperties.render_surface = make_scoped_ptr(new RenderSurfaceImpl(this
)); |
| 103 m_drawProperties.render_target = this; | 109 m_drawProperties.render_target = this; |
| 104 } | 110 } |
| 105 | 111 |
| 106 int LayerImpl::descendantsDrawContent() | 112 int LayerImpl::descendantsDrawContent() |
| 107 { | 113 { |
| 108 int result = 0; | 114 int result = 0; |
| 109 for (size_t i = 0; i < m_children.size(); ++i) { | 115 for (size_t i = 0; i < m_children.size(); ++i) { |
| 110 if (m_children[i]->drawsContent()) | 116 if (m_children[i]->drawsContent()) |
| 111 ++result; | 117 ++result; |
| 112 result += m_children[i]->descendantsDrawContent(); | 118 result += m_children[i]->descendantsDrawContent(); |
| 113 if (result > 1) | 119 if (result > 1) |
| 114 return result; | 120 return result; |
| 115 } | 121 } |
| 116 return result; | 122 return result; |
| 117 } | 123 } |
| 118 | 124 |
| 125 void LayerImpl::setLayerTreeHostImpl(LayerTreeHostImpl* hostImpl) |
| 126 { |
| 127 if (m_layerTreeHostImpl == hostImpl) |
| 128 return; |
| 129 |
| 130 m_layerTreeHostImpl = hostImpl; |
| 131 |
| 132 if (m_layerTreeHostImpl) |
| 133 m_layerTreeHostImpl->setNeedsUpdateLayers(); |
| 134 } |
| 135 |
| 119 scoped_ptr<SharedQuadState> LayerImpl::createSharedQuadState() const | 136 scoped_ptr<SharedQuadState> LayerImpl::createSharedQuadState() const |
| 120 { | 137 { |
| 121 scoped_ptr<SharedQuadState> state = SharedQuadState::Create(); | 138 scoped_ptr<SharedQuadState> state = SharedQuadState::Create(); |
| 122 state->SetAll(m_drawProperties.target_space_transform, | 139 state->SetAll(m_drawProperties.target_space_transform, |
| 123 m_drawProperties.visible_content_rect, | 140 m_drawProperties.visible_content_rect, |
| 124 m_drawProperties.drawable_content_rect, | 141 m_drawProperties.drawable_content_rect, |
| 125 m_drawProperties.clip_rect, | 142 m_drawProperties.clip_rect, |
| 126 m_drawProperties.is_clipped, | 143 m_drawProperties.is_clipped, |
| 127 m_drawProperties.opacity); | 144 m_drawProperties.opacity); |
| 128 return state.Pass(); | 145 return state.Pass(); |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 368 LayerImpl* current = this->m_parent; | 385 LayerImpl* current = this->m_parent; |
| 369 while (current && !current->m_drawProperties.render_surface) { | 386 while (current && !current->m_drawProperties.render_surface) { |
| 370 if (current->m_layerSurfacePropertyChanged) | 387 if (current->m_layerSurfacePropertyChanged) |
| 371 return true; | 388 return true; |
| 372 current = current->m_parent; | 389 current = current->m_parent; |
| 373 } | 390 } |
| 374 | 391 |
| 375 return false; | 392 return false; |
| 376 } | 393 } |
| 377 | 394 |
| 395 void LayerImpl::noteLayerSurfacePropertyChanged() |
| 396 { |
| 397 m_layerSurfacePropertyChanged = true; |
| 398 if (m_layerTreeHostImpl) |
| 399 m_layerTreeHostImpl->setNeedsUpdateLayers(); |
| 400 } |
| 401 |
| 402 void LayerImpl::noteLayerPropertyChanged() |
| 403 { |
| 404 m_layerPropertyChanged = true; |
| 405 if (m_layerTreeHostImpl) |
| 406 m_layerTreeHostImpl->setNeedsUpdateLayers(); |
| 407 } |
| 408 |
| 378 void LayerImpl::noteLayerPropertyChangedForSubtree() | 409 void LayerImpl::noteLayerPropertyChangedForSubtree() |
| 379 { | 410 { |
| 380 m_layerPropertyChanged = true; | 411 noteLayerPropertyChanged(); |
| 381 noteLayerPropertyChangedForDescendants(); | 412 noteLayerPropertyChangedForDescendants(); |
| 382 } | 413 } |
| 383 | 414 |
| 384 void LayerImpl::noteLayerPropertyChangedForDescendants() | 415 void LayerImpl::noteLayerPropertyChangedForDescendants() |
| 385 { | 416 { |
| 386 for (size_t i = 0; i < m_children.size(); ++i) | 417 for (size_t i = 0; i < m_children.size(); ++i) { |
| 387 m_children[i]->noteLayerPropertyChangedForSubtree(); | 418 m_children[i]->noteLayerPropertyChangedForSubtree(); |
| 419 } |
| 388 } | 420 } |
| 389 | 421 |
| 390 const char* LayerImpl::layerTypeAsString() const | 422 const char* LayerImpl::layerTypeAsString() const |
| 391 { | 423 { |
| 392 return "Layer"; | 424 return "Layer"; |
| 393 } | 425 } |
| 394 | 426 |
| 395 void LayerImpl::resetAllChangeTrackingForSubtree() | 427 void LayerImpl::resetAllChangeTrackingForSubtree() |
| 396 { | 428 { |
| 397 m_layerPropertyChanged = false; | 429 m_layerPropertyChanged = false; |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 445 void LayerImpl::setBounds(const gfx::Size& bounds) | 477 void LayerImpl::setBounds(const gfx::Size& bounds) |
| 446 { | 478 { |
| 447 if (m_bounds == bounds) | 479 if (m_bounds == bounds) |
| 448 return; | 480 return; |
| 449 | 481 |
| 450 m_bounds = bounds; | 482 m_bounds = bounds; |
| 451 | 483 |
| 452 if (masksToBounds()) | 484 if (masksToBounds()) |
| 453 noteLayerPropertyChangedForSubtree(); | 485 noteLayerPropertyChangedForSubtree(); |
| 454 else | 486 else |
| 455 m_layerPropertyChanged = true; | 487 noteLayerPropertyChanged(); |
| 456 } | 488 } |
| 457 | 489 |
| 458 void LayerImpl::setMaskLayer(scoped_ptr<LayerImpl> maskLayer) | 490 void LayerImpl::setMaskLayer(scoped_ptr<LayerImpl> maskLayer) |
| 459 { | 491 { |
| 460 m_maskLayer = maskLayer.Pass(); | 492 m_maskLayer = maskLayer.Pass(); |
| 461 | 493 |
| 462 int newLayerId = m_maskLayer ? m_maskLayer->id() : -1; | 494 int newLayerId = m_maskLayer ? m_maskLayer->id() : -1; |
| 463 if (newLayerId == m_maskLayerId) | 495 if (newLayerId == m_maskLayerId) |
| 464 return; | 496 return; |
| 465 | 497 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 478 m_replicaLayerId = newLayerId; | 510 m_replicaLayerId = newLayerId; |
| 479 noteLayerPropertyChangedForSubtree(); | 511 noteLayerPropertyChangedForSubtree(); |
| 480 } | 512 } |
| 481 | 513 |
| 482 void LayerImpl::setDrawsContent(bool drawsContent) | 514 void LayerImpl::setDrawsContent(bool drawsContent) |
| 483 { | 515 { |
| 484 if (m_drawsContent == drawsContent) | 516 if (m_drawsContent == drawsContent) |
| 485 return; | 517 return; |
| 486 | 518 |
| 487 m_drawsContent = drawsContent; | 519 m_drawsContent = drawsContent; |
| 488 m_layerPropertyChanged = true; | 520 noteLayerPropertyChanged(); |
| 489 } | 521 } |
| 490 | 522 |
| 491 void LayerImpl::setAnchorPoint(const gfx::PointF& anchorPoint) | 523 void LayerImpl::setAnchorPoint(const gfx::PointF& anchorPoint) |
| 492 { | 524 { |
| 493 if (m_anchorPoint == anchorPoint) | 525 if (m_anchorPoint == anchorPoint) |
| 494 return; | 526 return; |
| 495 | 527 |
| 496 m_anchorPoint = anchorPoint; | 528 m_anchorPoint = anchorPoint; |
| 497 noteLayerPropertyChangedForSubtree(); | 529 noteLayerPropertyChangedForSubtree(); |
| 498 } | 530 } |
| 499 | 531 |
| 500 void LayerImpl::setAnchorPointZ(float anchorPointZ) | 532 void LayerImpl::setAnchorPointZ(float anchorPointZ) |
| 501 { | 533 { |
| 502 if (m_anchorPointZ == anchorPointZ) | 534 if (m_anchorPointZ == anchorPointZ) |
| 503 return; | 535 return; |
| 504 | 536 |
| 505 m_anchorPointZ = anchorPointZ; | 537 m_anchorPointZ = anchorPointZ; |
| 506 noteLayerPropertyChangedForSubtree(); | 538 noteLayerPropertyChangedForSubtree(); |
| 507 } | 539 } |
| 508 | 540 |
| 509 void LayerImpl::setBackgroundColor(SkColor backgroundColor) | 541 void LayerImpl::setBackgroundColor(SkColor backgroundColor) |
| 510 { | 542 { |
| 511 if (m_backgroundColor == backgroundColor) | 543 if (m_backgroundColor == backgroundColor) |
| 512 return; | 544 return; |
| 513 | 545 |
| 514 m_backgroundColor = backgroundColor; | 546 m_backgroundColor = backgroundColor; |
| 515 m_layerPropertyChanged = true; | 547 noteLayerPropertyChanged(); |
| 516 } | 548 } |
| 517 | 549 |
| 518 void LayerImpl::setFilters(const WebKit::WebFilterOperations& filters) | 550 void LayerImpl::setFilters(const WebKit::WebFilterOperations& filters) |
| 519 { | 551 { |
| 520 if (m_filters == filters) | 552 if (m_filters == filters) |
| 521 return; | 553 return; |
| 522 | 554 |
| 523 DCHECK(!m_filter); | 555 DCHECK(!m_filter); |
| 524 m_filters = filters; | 556 m_filters = filters; |
| 525 noteLayerPropertyChangedForSubtree(); | 557 noteLayerPropertyChangedForSubtree(); |
| 526 } | 558 } |
| 527 | 559 |
| 528 void LayerImpl::setBackgroundFilters(const WebKit::WebFilterOperations& backgrou
ndFilters) | 560 void LayerImpl::setBackgroundFilters(const WebKit::WebFilterOperations& backgrou
ndFilters) |
| 529 { | 561 { |
| 530 if (m_backgroundFilters == backgroundFilters) | 562 if (m_backgroundFilters == backgroundFilters) |
| 531 return; | 563 return; |
| 532 | 564 |
| 533 m_backgroundFilters = backgroundFilters; | 565 m_backgroundFilters = backgroundFilters; |
| 534 m_layerPropertyChanged = true; | 566 noteLayerPropertyChanged(); |
| 535 } | 567 } |
| 536 | 568 |
| 537 void LayerImpl::setFilter(const skia::RefPtr<SkImageFilter>& filter) | 569 void LayerImpl::setFilter(const skia::RefPtr<SkImageFilter>& filter) |
| 538 { | 570 { |
| 539 if (m_filter.get() == filter.get()) | 571 if (m_filter.get() == filter.get()) |
| 540 return; | 572 return; |
| 541 | 573 |
| 542 DCHECK(m_filters.isEmpty()); | 574 DCHECK(m_filters.isEmpty()); |
| 543 m_filter = filter; | 575 m_filter = filter; |
| 544 noteLayerPropertyChangedForSubtree(); | 576 noteLayerPropertyChangedForSubtree(); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 561 m_contentsOpaque = opaque; | 593 m_contentsOpaque = opaque; |
| 562 noteLayerPropertyChangedForSubtree(); | 594 noteLayerPropertyChangedForSubtree(); |
| 563 } | 595 } |
| 564 | 596 |
| 565 void LayerImpl::setOpacity(float opacity) | 597 void LayerImpl::setOpacity(float opacity) |
| 566 { | 598 { |
| 567 if (m_opacity == opacity) | 599 if (m_opacity == opacity) |
| 568 return; | 600 return; |
| 569 | 601 |
| 570 m_opacity = opacity; | 602 m_opacity = opacity; |
| 571 m_layerSurfacePropertyChanged = true; | 603 noteLayerSurfacePropertyChanged(); |
| 572 } | 604 } |
| 573 | 605 |
| 574 bool LayerImpl::opacityIsAnimating() const | 606 bool LayerImpl::opacityIsAnimating() const |
| 575 { | 607 { |
| 576 return m_layerAnimationController->isAnimatingProperty(ActiveAnimation::Opac
ity); | 608 return m_layerAnimationController->isAnimatingProperty(ActiveAnimation::Opac
ity); |
| 577 } | 609 } |
| 578 | 610 |
| 579 void LayerImpl::setPosition(const gfx::PointF& position) | 611 void LayerImpl::setPosition(const gfx::PointF& position) |
| 580 { | 612 { |
| 581 if (m_position == position) | 613 if (m_position == position) |
| (...skipping 21 matching lines...) Expand all Loading... |
| 603 // sublayer transform does not affect the current layer; it affects only its
children. | 635 // sublayer transform does not affect the current layer; it affects only its
children. |
| 604 noteLayerPropertyChangedForDescendants(); | 636 noteLayerPropertyChangedForDescendants(); |
| 605 } | 637 } |
| 606 | 638 |
| 607 void LayerImpl::setTransform(const gfx::Transform& transform) | 639 void LayerImpl::setTransform(const gfx::Transform& transform) |
| 608 { | 640 { |
| 609 if (m_transform == transform) | 641 if (m_transform == transform) |
| 610 return; | 642 return; |
| 611 | 643 |
| 612 m_transform = transform; | 644 m_transform = transform; |
| 613 m_layerSurfacePropertyChanged = true; | 645 noteLayerSurfacePropertyChanged(); |
| 614 } | 646 } |
| 615 | 647 |
| 616 bool LayerImpl::transformIsAnimating() const | 648 bool LayerImpl::transformIsAnimating() const |
| 617 { | 649 { |
| 618 return m_layerAnimationController->isAnimatingProperty(ActiveAnimation::Tran
sform); | 650 return m_layerAnimationController->isAnimatingProperty(ActiveAnimation::Tran
sform); |
| 619 } | 651 } |
| 620 | 652 |
| 621 void LayerImpl::setContentBounds(const gfx::Size& contentBounds) | 653 void LayerImpl::setContentBounds(const gfx::Size& contentBounds) |
| 622 { | 654 { |
| 623 if (m_contentBounds == contentBounds) | 655 if (m_contentBounds == contentBounds) |
| 624 return; | 656 return; |
| 625 | 657 |
| 626 m_contentBounds = contentBounds; | 658 m_contentBounds = contentBounds; |
| 627 m_layerPropertyChanged = true; | 659 noteLayerPropertyChanged(); |
| 628 } | 660 } |
| 629 | 661 |
| 630 void LayerImpl::setContentsScale(float contentsScaleX, float contentsScaleY) | 662 void LayerImpl::setContentsScale(float contentsScaleX, float contentsScaleY) |
| 631 { | 663 { |
| 632 if (m_contentsScaleX == contentsScaleX && m_contentsScaleY == contentsScaleY
) | 664 if (m_contentsScaleX == contentsScaleX && m_contentsScaleY == contentsScaleY
) |
| 633 return; | 665 return; |
| 634 | 666 |
| 635 m_contentsScaleX = contentsScaleX; | 667 m_contentsScaleX = contentsScaleX; |
| 636 m_contentsScaleY = contentsScaleY; | 668 m_contentsScaleY = contentsScaleY; |
| 637 m_layerPropertyChanged = true; | 669 noteLayerPropertyChanged(); |
| 638 } | 670 } |
| 639 | 671 |
| 640 void LayerImpl::setScrollOffset(gfx::Vector2d scrollOffset) | 672 void LayerImpl::setScrollOffset(gfx::Vector2d scrollOffset) |
| 641 { | 673 { |
| 642 if (m_scrollOffset == scrollOffset) | 674 if (m_scrollOffset == scrollOffset) |
| 643 return; | 675 return; |
| 644 | 676 |
| 645 m_scrollOffset = scrollOffset; | 677 m_scrollOffset = scrollOffset; |
| 646 noteLayerPropertyChangedForSubtree(); | 678 noteLayerPropertyChangedForSubtree(); |
| 647 } | 679 } |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 723 | 755 |
| 724 void LayerImpl::setVerticalScrollbarLayer(ScrollbarLayerImpl* scrollbarLayer) | 756 void LayerImpl::setVerticalScrollbarLayer(ScrollbarLayerImpl* scrollbarLayer) |
| 725 { | 757 { |
| 726 if (!m_scrollbarAnimationController) | 758 if (!m_scrollbarAnimationController) |
| 727 m_scrollbarAnimationController = ScrollbarAnimationController::create(th
is); | 759 m_scrollbarAnimationController = ScrollbarAnimationController::create(th
is); |
| 728 m_scrollbarAnimationController->setVerticalScrollbarLayer(scrollbarLayer); | 760 m_scrollbarAnimationController->setVerticalScrollbarLayer(scrollbarLayer); |
| 729 m_scrollbarAnimationController->updateScrollOffset(this); | 761 m_scrollbarAnimationController->updateScrollOffset(this); |
| 730 } | 762 } |
| 731 | 763 |
| 732 } // namespace cc | 764 } // namespace cc |
| OLD | NEW |