Chromium Code Reviews| 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/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 25 | 25 |
| 26 namespace { | 26 namespace { |
| 27 | 27 |
| 28 const float EPSILON = 1e-3f; | 28 const float EPSILON = 1e-3f; |
| 29 | 29 |
| 30 bool IsApproximateMultilpleOf(float value, float base) { | 30 bool IsApproximateMultilpleOf(float value, float base) { |
| 31 float remainder = fmod(fabs(value), base); | 31 float remainder = fmod(fabs(value), base); |
| 32 return remainder < EPSILON || base - remainder < EPSILON; | 32 return remainder < EPSILON || base - remainder < EPSILON; |
| 33 } | 33 } |
| 34 | 34 |
| 35 const ui::Layer* GetRoot(const ui::Layer* layer) { | |
| 36 return layer->parent() ? GetRoot(layer->parent()) : layer; | |
| 37 } | |
| 38 | |
| 35 } // namespace | 39 } // namespace |
| 36 | 40 |
| 37 namespace ui { | 41 namespace ui { |
| 38 | 42 |
| 39 Layer::Layer(Compositor* compositor) | 43 Layer::Layer() |
| 40 : type_(LAYER_HAS_TEXTURE), | 44 : type_(LAYER_HAS_TEXTURE), |
| 41 compositor_(compositor), | 45 compositor_(NULL), |
| 42 parent_(NULL), | 46 parent_(NULL), |
| 43 visible_(true), | 47 visible_(true), |
| 44 fills_bounds_opaquely_(true), | 48 fills_bounds_opaquely_(true), |
| 45 layer_updated_externally_(false), | 49 layer_updated_externally_(false), |
| 46 opacity_(1.0f), | 50 opacity_(1.0f), |
| 47 delegate_(NULL) { | 51 delegate_(NULL) { |
| 48 #if defined(USE_WEBKIT_COMPOSITOR) | 52 #if defined(USE_WEBKIT_COMPOSITOR) |
| 49 CreateWebLayer(); | 53 CreateWebLayer(); |
| 50 #endif | 54 #endif |
| 51 } | 55 } |
| 52 | 56 |
| 53 Layer::Layer(Compositor* compositor, LayerType type) | 57 Layer::Layer(LayerType type) |
| 54 : type_(type), | 58 : type_(type), |
| 55 compositor_(compositor), | 59 compositor_(NULL), |
| 56 parent_(NULL), | 60 parent_(NULL), |
| 57 visible_(true), | 61 visible_(true), |
| 58 fills_bounds_opaquely_(true), | 62 fills_bounds_opaquely_(true), |
| 59 layer_updated_externally_(false), | 63 layer_updated_externally_(false), |
| 60 opacity_(1.0f), | 64 opacity_(1.0f), |
| 61 delegate_(NULL) { | 65 delegate_(NULL) { |
| 62 #if defined(USE_WEBKIT_COMPOSITOR) | 66 #if defined(USE_WEBKIT_COMPOSITOR) |
| 63 CreateWebLayer(); | 67 CreateWebLayer(); |
| 64 #endif | 68 #endif |
| 65 } | 69 } |
| 66 | 70 |
| 67 Layer::~Layer() { | 71 Layer::~Layer() { |
| 68 if (parent_) | 72 if (parent_) |
| 69 parent_->Remove(this); | 73 parent_->Remove(this); |
| 70 for (size_t i = 0; i < children_.size(); ++i) | 74 for (size_t i = 0; i < children_.size(); ++i) |
| 71 children_[i]->parent_ = NULL; | 75 children_[i]->parent_ = NULL; |
| 72 #if defined(USE_WEBKIT_COMPOSITOR) | 76 #if defined(USE_WEBKIT_COMPOSITOR) |
| 73 web_layer_.removeFromParent(); | 77 web_layer_.removeFromParent(); |
| 74 #endif | 78 #endif |
| 75 } | 79 } |
| 76 | 80 |
| 77 Compositor* Layer::GetCompositor() { | 81 Compositor* Layer::GetCompositor() { |
| 78 return compositor_ ? compositor_ : parent_ ? parent_->GetCompositor() : NULL; | 82 return compositor_ ? compositor_ : parent_ ? parent_->GetCompositor() : NULL; |
|
sky
2011/11/15 04:57:04
Should this be updated to GetRoot(layer)->composit
piman
2011/11/15 22:06:33
Originally I didn't want to do that because the co
| |
| 79 } | 83 } |
| 80 | 84 |
| 81 void Layer::SetCompositor(Compositor* compositor) { | 85 void Layer::SetCompositor(Compositor* compositor) { |
| 82 // This function must only be called once, with a valid compositor, and only | 86 // This function must only be called to set the compositor on the root layer, |
| 83 // for the compositor's root layer. | 87 // or to reset it. |
| 84 DCHECK(!compositor_); | 88 DCHECK(!compositor || !compositor_); |
| 85 DCHECK(compositor); | 89 DCHECK(!compositor || compositor->root_layer() == this); |
| 86 DCHECK_EQ(compositor->root_layer(), this); | |
| 87 compositor_ = compositor; | 90 compositor_ = compositor; |
| 88 } | 91 } |
| 89 | 92 |
| 90 void Layer::Add(Layer* child) { | 93 void Layer::Add(Layer* child) { |
| 91 if (child->parent_) | 94 if (child->parent_) |
| 92 child->parent_->Remove(child); | 95 child->parent_->Remove(child); |
| 93 child->parent_ = this; | 96 child->parent_ = this; |
| 94 children_.push_back(child); | 97 children_.push_back(child); |
| 95 #if defined(USE_WEBKIT_COMPOSITOR) | 98 #if defined(USE_WEBKIT_COMPOSITOR) |
| 96 web_layer_.addChild(child->web_layer_); | 99 web_layer_.addChild(child->web_layer_); |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 223 !hole_rect_.Contains(gfx::Rect(gfx::Point(0, 0), bounds_.size())); | 226 !hole_rect_.Contains(gfx::Rect(gfx::Point(0, 0), bounds_.size())); |
| 224 } | 227 } |
| 225 | 228 |
| 226 // static | 229 // static |
| 227 void Layer::ConvertPointToLayer(const Layer* source, | 230 void Layer::ConvertPointToLayer(const Layer* source, |
| 228 const Layer* target, | 231 const Layer* target, |
| 229 gfx::Point* point) { | 232 gfx::Point* point) { |
| 230 if (source == target) | 233 if (source == target) |
| 231 return; | 234 return; |
| 232 | 235 |
| 233 const Layer* root_layer = source->compositor()->root_layer(); | 236 const Layer* root_layer = GetRoot(source); |
| 234 CHECK_EQ(root_layer, target->compositor()->root_layer()); | 237 CHECK_EQ(root_layer, GetRoot(target)); |
| 235 | 238 |
| 236 if (source != root_layer) | 239 if (source != root_layer) |
| 237 source->ConvertPointForAncestor(root_layer, point); | 240 source->ConvertPointForAncestor(root_layer, point); |
| 238 if (target != root_layer) | 241 if (target != root_layer) |
| 239 target->ConvertPointFromAncestor(root_layer, point); | 242 target->ConvertPointFromAncestor(root_layer, point); |
| 240 } | 243 } |
| 241 | 244 |
| 242 void Layer::SetFillsBoundsOpaquely(bool fills_bounds_opaquely) { | 245 void Layer::SetFillsBoundsOpaquely(bool fills_bounds_opaquely) { |
| 243 if (fills_bounds_opaquely_ == fills_bounds_opaquely) | 246 if (fills_bounds_opaquely_ == fills_bounds_opaquely) |
| 244 return; | 247 return; |
| (...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 678 #else | 681 #else |
| 679 unsigned int texture_id = 0; | 682 unsigned int texture_id = 0; |
| 680 #endif | 683 #endif |
| 681 web_layer_.to<WebKit::WebExternalTextureLayer>().setTextureId( | 684 web_layer_.to<WebKit::WebExternalTextureLayer>().setTextureId( |
| 682 should_draw ? texture_id : 0); | 685 should_draw ? texture_id : 0); |
| 683 } | 686 } |
| 684 } | 687 } |
| 685 #endif | 688 #endif |
| 686 | 689 |
| 687 } // namespace ui | 690 } // namespace ui |
| OLD | NEW |