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