| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 "ui/gfx/compositor/layer.h" | 5 #include "ui/gfx/compositor/layer.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 void Layer::SetOpacity(float opacity) { | 127 void Layer::SetOpacity(float opacity) { |
| 128 StopAnimatingIfNecessary(LayerAnimator::OPACITY); | 128 StopAnimatingIfNecessary(LayerAnimator::OPACITY); |
| 129 if (animator_.get() && animator_->IsRunning()) { | 129 if (animator_.get() && animator_->IsRunning()) { |
| 130 animator_->AnimateOpacity(opacity); | 130 animator_->AnimateOpacity(opacity); |
| 131 return; | 131 return; |
| 132 } | 132 } |
| 133 SetOpacityImmediately(opacity); | 133 SetOpacityImmediately(opacity); |
| 134 } | 134 } |
| 135 | 135 |
| 136 void Layer::SetVisible(bool visible) { | 136 void Layer::SetVisible(bool visible) { |
| 137 if (visible_ == visible) |
| 138 return; |
| 139 |
| 140 bool was_drawn = IsDrawn(); |
| 137 visible_ = visible; | 141 visible_ = visible; |
| 138 if (!visible_) | 142 bool is_drawn = IsDrawn(); |
| 143 if (was_drawn == is_drawn) |
| 144 return; |
| 145 |
| 146 if (!is_drawn) |
| 139 DropTextures(); | 147 DropTextures(); |
| 140 if (parent_) | 148 if (parent_) |
| 141 parent_->RecomputeHole(); | 149 parent_->RecomputeHole(); |
| 142 } | 150 } |
| 143 | 151 |
| 152 bool Layer::IsDrawn() const { |
| 153 const Layer* layer = this; |
| 154 while (layer && layer->visible_) |
| 155 layer = layer->parent_; |
| 156 return layer == NULL; |
| 157 } |
| 158 |
| 144 bool Layer::ShouldDraw() { | 159 bool Layer::ShouldDraw() { |
| 145 return type_ == LAYER_HAS_TEXTURE && GetCombinedOpacity() > 0.0f && | 160 return type_ == LAYER_HAS_TEXTURE && GetCombinedOpacity() > 0.0f && |
| 146 !hole_rect_.Contains(gfx::Rect(gfx::Point(0, 0), bounds_.size())); | 161 !hole_rect_.Contains(gfx::Rect(gfx::Point(0, 0), bounds_.size())); |
| 147 } | 162 } |
| 148 | 163 |
| 149 // static | 164 // static |
| 150 void Layer::ConvertPointToLayer(const Layer* source, | 165 void Layer::ConvertPointToLayer(const Layer* source, |
| 151 const Layer* target, | 166 const Layer* target, |
| 152 gfx::Point* point) { | 167 gfx::Point* point) { |
| 153 const Layer* inner = NULL; | 168 const Layer* inner = NULL; |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 283 | 298 |
| 284 void Layer::RecomputeHole() { | 299 void Layer::RecomputeHole() { |
| 285 if (type_ == LAYER_HAS_NO_TEXTURE) | 300 if (type_ == LAYER_HAS_NO_TEXTURE) |
| 286 return; | 301 return; |
| 287 | 302 |
| 288 // Reset to default. | 303 // Reset to default. |
| 289 hole_rect_ = gfx::Rect(); | 304 hole_rect_ = gfx::Rect(); |
| 290 | 305 |
| 291 // 1) We cannot do any hole punching if any child has a transform. | 306 // 1) We cannot do any hole punching if any child has a transform. |
| 292 for (size_t i = 0; i < children_.size(); ++i) { | 307 for (size_t i = 0; i < children_.size(); ++i) { |
| 293 if (children_[i]->transform().HasChange() && children_[i]->visible()) | 308 if (children_[i]->transform().HasChange() && children_[i]->visible_) |
| 294 return; | 309 return; |
| 295 } | 310 } |
| 296 | 311 |
| 297 // 2) Find the largest hole. | 312 // 2) Find the largest hole. |
| 298 for (size_t i = 0; i < children_.size(); ++i) { | 313 for (size_t i = 0; i < children_.size(); ++i) { |
| 299 // Ignore non-opaque and hidden children. | 314 // Ignore non-opaque and hidden children. |
| 300 if (!children_[i]->IsCompletelyOpaque() || !children_[i]->visible()) | 315 if (!children_[i]->IsCompletelyOpaque() || !children_[i]->visible_) |
| 301 continue; | 316 continue; |
| 302 | 317 |
| 303 if (children_[i]->bounds().size().GetArea() > hole_rect_.size().GetArea()) { | 318 if (children_[i]->bounds().size().GetArea() > hole_rect_.size().GetArea()) { |
| 304 hole_rect_ = children_[i]->bounds(); | 319 hole_rect_ = children_[i]->bounds(); |
| 305 } | 320 } |
| 306 } | 321 } |
| 307 | 322 |
| 308 // 3) Make sure hole does not intersect with non-opaque children. | 323 // 3) Make sure hole does not intersect with non-opaque children. |
| 309 for (size_t i = 0; i < children_.size(); ++i) { | 324 for (size_t i = 0; i < children_.size(); ++i) { |
| 310 // Ignore opaque and hidden children. | 325 // Ignore opaque and hidden children. |
| 311 if (children_[i]->IsCompletelyOpaque() || !children_[i]->visible()) | 326 if (children_[i]->IsCompletelyOpaque() || !children_[i]->visible_) |
| 312 continue; | 327 continue; |
| 313 | 328 |
| 314 // Ignore non-intersecting children. | 329 // Ignore non-intersecting children. |
| 315 if (!hole_rect_.Intersects(children_[i]->bounds())) | 330 if (!hole_rect_.Intersects(children_[i]->bounds())) |
| 316 continue; | 331 continue; |
| 317 | 332 |
| 318 // Compute surrounding fragments. | 333 // Compute surrounding fragments. |
| 319 std::vector<gfx::Rect> fragments; | 334 std::vector<gfx::Rect> fragments; |
| 320 PunchHole(hole_rect_, children_[i]->bounds(), &fragments); | 335 PunchHole(hole_rect_, children_[i]->bounds(), &fragments); |
| 321 | 336 |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 478 | 493 |
| 479 void Layer::SetTransformFromAnimator(const Transform& transform) { | 494 void Layer::SetTransformFromAnimator(const Transform& transform) { |
| 480 SetTransformImmediately(transform); | 495 SetTransformImmediately(transform); |
| 481 } | 496 } |
| 482 | 497 |
| 483 void Layer::SetOpacityFromAnimator(float opacity) { | 498 void Layer::SetOpacityFromAnimator(float opacity) { |
| 484 SetOpacityImmediately(opacity); | 499 SetOpacityImmediately(opacity); |
| 485 } | 500 } |
| 486 | 501 |
| 487 } // namespace ui | 502 } // namespace ui |
| OLD | NEW |