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/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
127 } | 127 } |
128 | 128 |
129 void Layer::Add(Layer* child) { | 129 void Layer::Add(Layer* child) { |
130 DCHECK(!child->compositor_); | 130 DCHECK(!child->compositor_); |
131 if (child->parent_) | 131 if (child->parent_) |
132 child->parent_->Remove(child); | 132 child->parent_->Remove(child); |
133 child->parent_ = this; | 133 child->parent_ = this; |
134 children_.push_back(child); | 134 children_.push_back(child); |
135 cc_layer_->addChild(child->cc_layer_); | 135 cc_layer_->addChild(child->cc_layer_); |
136 child->OnDeviceScaleFactorChanged(device_scale_factor_); | 136 child->OnDeviceScaleFactorChanged(device_scale_factor_); |
137 child->OnParentIsDrawnChanged(IsDrawn(), true); | |
piman
2013/01/31 23:21:59
If we are going to propagate the information down,
ajuma
2013/02/01 16:04:06
Done.
| |
137 } | 138 } |
138 | 139 |
139 void Layer::Remove(Layer* child) { | 140 void Layer::Remove(Layer* child) { |
140 std::vector<Layer*>::iterator i = | 141 std::vector<Layer*>::iterator i = |
141 std::find(children_.begin(), children_.end(), child); | 142 std::find(children_.begin(), children_.end(), child); |
142 DCHECK(i != children_.end()); | 143 DCHECK(i != children_.end()); |
143 children_.erase(i); | 144 children_.erase(i); |
144 child->parent_ = NULL; | 145 child->parent_ = NULL; |
145 child->cc_layer_->removeFromParent(); | 146 child->cc_layer_->removeFromParent(); |
146 } | 147 } |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
366 return visible_; | 367 return visible_; |
367 } | 368 } |
368 | 369 |
369 bool Layer::IsDrawn() const { | 370 bool Layer::IsDrawn() const { |
370 const Layer* layer = this; | 371 const Layer* layer = this; |
371 while (layer && layer->visible_) | 372 while (layer && layer->visible_) |
372 layer = layer->parent_; | 373 layer = layer->parent_; |
373 return layer == NULL; | 374 return layer == NULL; |
374 } | 375 } |
375 | 376 |
377 void Layer::OnParentIsDrawnChanged(bool parent_is_drawn, bool force_update) { | |
378 if (!visible_ && !force_update) | |
379 return; | |
380 | |
381 cc_layer_->setIsDrawable( | |
382 visible_ && parent_is_drawn && type_ != LAYER_NOT_DRAWN); | |
383 | |
384 for (size_t i = 0; i < children_.size(); ++i) { | |
385 children_[i]->OnParentIsDrawnChanged(visible_ && parent_is_drawn, | |
386 force_update); | |
387 } | |
388 } | |
389 | |
376 bool Layer::ShouldDraw() const { | 390 bool Layer::ShouldDraw() const { |
377 return type_ != LAYER_NOT_DRAWN && GetCombinedOpacity() > 0.0f; | 391 return type_ != LAYER_NOT_DRAWN && GetCombinedOpacity() > 0.0f; |
378 } | 392 } |
379 | 393 |
380 // static | 394 // static |
381 void Layer::ConvertPointToLayer(const Layer* source, | 395 void Layer::ConvertPointToLayer(const Layer* source, |
382 const Layer* target, | 396 const Layer* target, |
383 gfx::Point* point) { | 397 gfx::Point* point) { |
384 if (source == target) | 398 if (source == target) |
385 return; | 399 return; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
431 parent_->cc_layer_->replaceChild(cc_layer_, new_layer); | 445 parent_->cc_layer_->replaceChild(cc_layer_, new_layer); |
432 } | 446 } |
433 cc_layer_= new_layer; | 447 cc_layer_= new_layer; |
434 cc_layer_is_accelerated_ = layer_updated_externally_; | 448 cc_layer_is_accelerated_ = layer_updated_externally_; |
435 for (size_t i = 0; i < children_.size(); ++i) { | 449 for (size_t i = 0; i < children_.size(); ++i) { |
436 DCHECK(children_[i]->cc_layer_); | 450 DCHECK(children_[i]->cc_layer_); |
437 cc_layer_->addChild(children_[i]->cc_layer_); | 451 cc_layer_->addChild(children_[i]->cc_layer_); |
438 } | 452 } |
439 cc_layer_->setAnchorPoint(gfx::PointF()); | 453 cc_layer_->setAnchorPoint(gfx::PointF()); |
440 cc_layer_->setContentsOpaque(fills_bounds_opaquely_); | 454 cc_layer_->setContentsOpaque(fills_bounds_opaquely_); |
441 cc_layer_->setOpacity(visible_ ? opacity_ : 0.f); | 455 cc_layer_->setOpacity(opacity_); |
442 cc_layer_->setForceRenderSurface(force_render_surface_); | 456 cc_layer_->setForceRenderSurface(force_render_surface_); |
443 cc_layer_->setIsDrawable(true); | 457 cc_layer_->setIsDrawable(IsDrawn()); |
444 RecomputeTransform(); | 458 RecomputeTransform(); |
445 } | 459 } |
446 RecomputeDrawsContentAndUVRect(); | 460 RecomputeDrawsContentAndUVRect(); |
447 } | 461 } |
448 | 462 |
449 void Layer::SetColor(SkColor color) { | 463 void Layer::SetColor(SkColor color) { |
450 GetAnimator()->SetColor(color); | 464 GetAnimator()->SetColor(color); |
451 } | 465 } |
452 | 466 |
453 bool Layer::SchedulePaint(const gfx::Rect& invalid_rect) { | 467 bool Layer::SchedulePaint(const gfx::Rect& invalid_rect) { |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
638 void Layer::SetTransformImmediately(const gfx::Transform& transform) { | 652 void Layer::SetTransformImmediately(const gfx::Transform& transform) { |
639 transform_ = transform; | 653 transform_ = transform; |
640 | 654 |
641 RecomputeTransform(); | 655 RecomputeTransform(); |
642 } | 656 } |
643 | 657 |
644 void Layer::SetOpacityImmediately(float opacity) { | 658 void Layer::SetOpacityImmediately(float opacity) { |
645 bool schedule_draw = (opacity != opacity_ && IsDrawn()); | 659 bool schedule_draw = (opacity != opacity_ && IsDrawn()); |
646 opacity_ = opacity; | 660 opacity_ = opacity; |
647 | 661 |
648 if (visible_) | 662 cc_layer_->setOpacity(opacity); |
649 cc_layer_->setOpacity(opacity); | |
650 if (schedule_draw) | 663 if (schedule_draw) |
651 ScheduleDraw(); | 664 ScheduleDraw(); |
652 } | 665 } |
653 | 666 |
654 void Layer::SetVisibilityImmediately(bool visible) { | 667 void Layer::SetVisibilityImmediately(bool visible) { |
655 if (visible_ == visible) | 668 if (visible_ == visible) |
656 return; | 669 return; |
657 | 670 |
658 visible_ = visible; | 671 visible_ = visible; |
659 // TODO(piman): Expose a visibility flag on WebLayer. | 672 |
660 cc_layer_->setOpacity(visible_ ? opacity_ : 0.f); | 673 if (parent_ && !parent_->IsDrawn()) |
674 return; | |
675 | |
676 cc_layer_->setIsDrawable(visible_ && type_ != LAYER_NOT_DRAWN); | |
677 for (size_t i = 0; i < children_.size(); ++i) | |
678 children_[i]->OnParentIsDrawnChanged(visible_, false); | |
piman
2013/01/31 23:21:59
Can we share that code with OnParentIsDrawnChanged
ajuma
2013/02/01 16:04:06
Done. The logic is now specified only in UpdateIsD
| |
661 } | 679 } |
662 | 680 |
663 void Layer::SetBrightnessImmediately(float brightness) { | 681 void Layer::SetBrightnessImmediately(float brightness) { |
664 layer_brightness_ = brightness; | 682 layer_brightness_ = brightness; |
665 SetLayerFilters(); | 683 SetLayerFilters(); |
666 } | 684 } |
667 | 685 |
668 void Layer::SetGrayscaleImmediately(float grayscale) { | 686 void Layer::SetGrayscaleImmediately(float grayscale) { |
669 layer_grayscale_ = grayscale; | 687 layer_grayscale_ = grayscale; |
670 SetLayerFilters(); | 688 SetLayerFilters(); |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
790 gfx::PointF uv_bottom_right( | 808 gfx::PointF uv_bottom_right( |
791 static_cast<float>(size.width())/texture_size.width(), | 809 static_cast<float>(size.width())/texture_size.width(), |
792 static_cast<float>(size.height())/texture_size.height()); | 810 static_cast<float>(size.height())/texture_size.height()); |
793 texture_layer_->setUV(uv_top_left, uv_bottom_right); | 811 texture_layer_->setUV(uv_top_left, uv_bottom_right); |
794 | 812 |
795 cc_layer_->setBounds(ConvertSizeToPixel(this, size)); | 813 cc_layer_->setBounds(ConvertSizeToPixel(this, size)); |
796 } | 814 } |
797 } | 815 } |
798 | 816 |
799 } // namespace ui | 817 } // namespace ui |
OLD | NEW |