OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 "ui/compositor/layer.h" | 5 #include "ui/compositor/layer.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 639 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
650 nine_patch_layer_->SetBorder(border); | 650 nine_patch_layer_->SetBorder(border); |
651 } | 651 } |
652 | 652 |
653 void Layer::SetColor(SkColor color) { GetAnimator()->SetColor(color); } | 653 void Layer::SetColor(SkColor color) { GetAnimator()->SetColor(color); } |
654 | 654 |
655 bool Layer::SchedulePaint(const gfx::Rect& invalid_rect) { | 655 bool Layer::SchedulePaint(const gfx::Rect& invalid_rect) { |
656 if ((type_ == LAYER_SOLID_COLOR && !texture_layer_.get()) || | 656 if ((type_ == LAYER_SOLID_COLOR && !texture_layer_.get()) || |
657 type_ == LAYER_NINE_PATCH || (!delegate_ && !mailbox_.IsValid())) | 657 type_ == LAYER_NINE_PATCH || (!delegate_ && !mailbox_.IsValid())) |
658 return false; | 658 return false; |
659 | 659 |
660 damaged_region_.op(invalid_rect.x(), | 660 damaged_region_.Union(invalid_rect); |
661 invalid_rect.y(), | |
662 invalid_rect.right(), | |
663 invalid_rect.bottom(), | |
664 SkRegion::kUnion_Op); | |
665 ScheduleDraw(); | 661 ScheduleDraw(); |
666 return true; | 662 return true; |
667 } | 663 } |
668 | 664 |
669 void Layer::ScheduleDraw() { | 665 void Layer::ScheduleDraw() { |
670 Compositor* compositor = GetCompositor(); | 666 Compositor* compositor = GetCompositor(); |
671 if (compositor) | 667 if (compositor) |
672 compositor->ScheduleDraw(); | 668 compositor->ScheduleDraw(); |
673 } | 669 } |
674 | 670 |
675 void Layer::SendDamagedRects() { | 671 void Layer::SendDamagedRects() { |
676 if ((delegate_ || mailbox_.IsValid()) && !damaged_region_.isEmpty()) { | 672 if (damaged_region_.IsEmpty()) |
677 for (SkRegion::Iterator iter(damaged_region_); !iter.done(); iter.next()) { | 673 return; |
678 const SkIRect& sk_damaged = iter.rect(); | 674 if (!delegate_ && !mailbox_.IsValid()) |
679 gfx::Rect damaged( | 675 return; |
680 sk_damaged.x(), | 676 |
681 sk_damaged.y(), | 677 for (cc::Region::Iterator iter(damaged_region_); iter.has_rect(); iter.next()) |
682 sk_damaged.width(), | 678 cc_layer_->SetNeedsDisplayRect(iter.rect()); |
683 sk_damaged.height()); | 679 } |
684 cc_layer_->SetNeedsDisplayRect(damaged); | 680 |
685 } | 681 void Layer::ClearDamagedRects() { |
686 damaged_region_.setEmpty(); | 682 damaged_region_.Clear(); |
687 } | |
688 for (size_t i = 0; i < children_.size(); ++i) | |
689 children_[i]->SendDamagedRects(); | |
690 } | 683 } |
691 | 684 |
692 void Layer::CompleteAllAnimations() { | 685 void Layer::CompleteAllAnimations() { |
693 typedef std::vector<scoped_refptr<LayerAnimator> > LayerAnimatorVector; | 686 typedef std::vector<scoped_refptr<LayerAnimator> > LayerAnimatorVector; |
694 LayerAnimatorVector animators; | 687 LayerAnimatorVector animators; |
695 CollectAnimators(&animators); | 688 CollectAnimators(&animators); |
696 for (LayerAnimatorVector::const_iterator it = animators.begin(); | 689 for (LayerAnimatorVector::const_iterator it = animators.begin(); |
697 it != animators.end(); | 690 it != animators.end(); |
698 ++it) { | 691 ++it) { |
699 (*it)->StopAnimating(); | 692 (*it)->StopAnimating(); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
742 | 735 |
743 void Layer::PaintContents( | 736 void Layer::PaintContents( |
744 SkCanvas* sk_canvas, | 737 SkCanvas* sk_canvas, |
745 const gfx::Rect& clip, | 738 const gfx::Rect& clip, |
746 ContentLayerClient::PaintingControlSetting painting_control) { | 739 ContentLayerClient::PaintingControlSetting painting_control) { |
747 TRACE_EVENT1("ui", "Layer::PaintContents", "name", name_); | 740 TRACE_EVENT1("ui", "Layer::PaintContents", "name", name_); |
748 scoped_ptr<gfx::Canvas> canvas(gfx::Canvas::CreateCanvasWithoutScaling( | 741 scoped_ptr<gfx::Canvas> canvas(gfx::Canvas::CreateCanvasWithoutScaling( |
749 sk_canvas, device_scale_factor_)); | 742 sk_canvas, device_scale_factor_)); |
750 if (delegate_) | 743 if (delegate_) |
751 delegate_->OnPaintLayer(PaintContext(canvas.get(), clip)); | 744 delegate_->OnPaintLayer(PaintContext(canvas.get(), clip)); |
745 ClearDamagedRects(); | |
sky
2015/04/21 23:56:54
What happens if as part of painting something gets
piman
2015/04/22 03:32:13
Conversely, what happens if damage to the layer is
danakj
2015/04/22 16:32:21
It's possible, I wanted to think of that as a bug,
| |
752 } | 746 } |
753 | 747 |
754 void Layer::PaintContentsToDisplayList( | 748 void Layer::PaintContentsToDisplayList( |
755 cc::DisplayItemList* display_list, | 749 cc::DisplayItemList* display_list, |
756 const gfx::Rect& clip, | 750 const gfx::Rect& clip, |
757 ContentLayerClient::PaintingControlSetting painting_control) { | 751 ContentLayerClient::PaintingControlSetting painting_control) { |
758 TRACE_EVENT1("ui", "Layer::PaintContentsToDisplayList", "name", name_); | 752 TRACE_EVENT1("ui", "Layer::PaintContentsToDisplayList", "name", name_); |
759 if (delegate_) { | 753 if (delegate_) { |
760 // TODO(danakj): Save the invalidation on the layer and pass that down | 754 // TODO(danakj): Save the invalidation on the layer and pass that down |
761 // instead of the |clip| here. That will break everything until View | 755 // instead of the |clip| here. That will break everything until View |
762 // early-outs emit cached display items instead of nothing. | 756 // early-outs emit cached display items instead of nothing. |
763 gfx::Rect invalidation = clip; | 757 gfx::Rect invalidation = clip; |
764 DCHECK(clip.Contains(invalidation)); | 758 DCHECK(clip.Contains(invalidation)); |
765 delegate_->OnPaintLayer( | 759 delegate_->OnPaintLayer( |
766 PaintContext(display_list, device_scale_factor_, clip, invalidation)); | 760 PaintContext(display_list, device_scale_factor_, clip, invalidation)); |
767 } | 761 } |
762 ClearDamagedRects(); | |
768 } | 763 } |
769 | 764 |
770 bool Layer::FillsBoundsCompletely() const { return fills_bounds_completely_; } | 765 bool Layer::FillsBoundsCompletely() const { return fills_bounds_completely_; } |
771 | 766 |
772 bool Layer::PrepareTextureMailbox( | 767 bool Layer::PrepareTextureMailbox( |
773 cc::TextureMailbox* mailbox, | 768 cc::TextureMailbox* mailbox, |
774 scoped_ptr<cc::SingleReleaseCallback>* release_callback, | 769 scoped_ptr<cc::SingleReleaseCallback>* release_callback, |
775 bool use_shared_memory) { | 770 bool use_shared_memory) { |
776 if (!mailbox_release_callback_) | 771 if (!mailbox_release_callback_) |
777 return false; | 772 return false; |
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1091 children_.end(), | 1086 children_.end(), |
1092 std::bind2nd(std::mem_fun(&Layer::RemoveAnimatorsInTreeFromCollection), | 1087 std::bind2nd(std::mem_fun(&Layer::RemoveAnimatorsInTreeFromCollection), |
1093 collection)); | 1088 collection)); |
1094 } | 1089 } |
1095 | 1090 |
1096 bool Layer::IsAnimating() const { | 1091 bool Layer::IsAnimating() const { |
1097 return animator_.get() && animator_->is_animating(); | 1092 return animator_.get() && animator_->is_animating(); |
1098 } | 1093 } |
1099 | 1094 |
1100 } // namespace ui | 1095 } // namespace ui |
OLD | NEW |