| 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 #include <memory> | 8 #include <memory> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 layer_brightness_(0.0f), | 60 layer_brightness_(0.0f), |
| 61 layer_grayscale_(0.0f), | 61 layer_grayscale_(0.0f), |
| 62 layer_inverted_(false), | 62 layer_inverted_(false), |
| 63 layer_mask_(NULL), | 63 layer_mask_(NULL), |
| 64 layer_mask_back_link_(NULL), | 64 layer_mask_back_link_(NULL), |
| 65 zoom_(1), | 65 zoom_(1), |
| 66 zoom_inset_(0), | 66 zoom_inset_(0), |
| 67 delegate_(NULL), | 67 delegate_(NULL), |
| 68 owner_(NULL), | 68 owner_(NULL), |
| 69 cc_layer_(NULL), | 69 cc_layer_(NULL), |
| 70 device_scale_factor_(1.0f), | 70 device_scale_factor_(1.0f) { |
| 71 texture_x_scale_(1.0f), | |
| 72 texture_y_scale_(1.0f) { | |
| 73 CreateCcLayer(); | 71 CreateCcLayer(); |
| 74 } | 72 } |
| 75 | 73 |
| 76 Layer::Layer(LayerType type) | 74 Layer::Layer(LayerType type) |
| 77 : type_(type), | 75 : type_(type), |
| 78 compositor_(NULL), | 76 compositor_(NULL), |
| 79 parent_(NULL), | 77 parent_(NULL), |
| 80 visible_(true), | 78 visible_(true), |
| 81 fills_bounds_opaquely_(true), | 79 fills_bounds_opaquely_(true), |
| 82 fills_bounds_completely_(false), | 80 fills_bounds_completely_(false), |
| 83 background_blur_radius_(0), | 81 background_blur_radius_(0), |
| 84 layer_saturation_(0.0f), | 82 layer_saturation_(0.0f), |
| 85 layer_brightness_(0.0f), | 83 layer_brightness_(0.0f), |
| 86 layer_grayscale_(0.0f), | 84 layer_grayscale_(0.0f), |
| 87 layer_inverted_(false), | 85 layer_inverted_(false), |
| 88 layer_mask_(NULL), | 86 layer_mask_(NULL), |
| 89 layer_mask_back_link_(NULL), | 87 layer_mask_back_link_(NULL), |
| 90 zoom_(1), | 88 zoom_(1), |
| 91 zoom_inset_(0), | 89 zoom_inset_(0), |
| 92 delegate_(NULL), | 90 delegate_(NULL), |
| 93 owner_(NULL), | 91 owner_(NULL), |
| 94 cc_layer_(NULL), | 92 cc_layer_(NULL), |
| 95 device_scale_factor_(1.0f), | 93 device_scale_factor_(1.0f) { |
| 96 texture_x_scale_(1.0f), | |
| 97 texture_y_scale_(1.0f) { | |
| 98 CreateCcLayer(); | 94 CreateCcLayer(); |
| 99 } | 95 } |
| 100 | 96 |
| 101 Layer::~Layer() { | 97 Layer::~Layer() { |
| 102 // Destroying the animator may cause observers to use the layer (and | 98 // Destroying the animator may cause observers to use the layer (and |
| 103 // indirectly the WebLayer). Destroy the animator first so that the WebLayer | 99 // indirectly the WebLayer). Destroy the animator first so that the WebLayer |
| 104 // is still around. | 100 // is still around. |
| 105 SetAnimator(nullptr); | 101 SetAnimator(nullptr); |
| 106 if (compositor_) | 102 if (compositor_) |
| 107 compositor_->SetRootLayer(NULL); | 103 compositor_->SetRootLayer(NULL); |
| (...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 564 void Layer::SetTextureFlipped(bool flipped) { | 560 void Layer::SetTextureFlipped(bool flipped) { |
| 565 DCHECK(texture_layer_.get()); | 561 DCHECK(texture_layer_.get()); |
| 566 texture_layer_->SetFlipped(flipped); | 562 texture_layer_->SetFlipped(flipped); |
| 567 } | 563 } |
| 568 | 564 |
| 569 bool Layer::TextureFlipped() const { | 565 bool Layer::TextureFlipped() const { |
| 570 DCHECK(texture_layer_.get()); | 566 DCHECK(texture_layer_.get()); |
| 571 return texture_layer_->flipped(); | 567 return texture_layer_->flipped(); |
| 572 } | 568 } |
| 573 | 569 |
| 574 void Layer::SetTextureAlpha(float alpha) { | |
| 575 DCHECK(texture_layer_.get()); | |
| 576 texture_layer_->SetVertexOpacity(alpha, alpha, alpha, alpha); | |
| 577 } | |
| 578 | |
| 579 void Layer::SetTextureCrop(const gfx::RectF& crop) { | |
| 580 DCHECK(texture_layer_.get()); | |
| 581 texture_crop_ = crop; | |
| 582 RecomputeDrawsContentAndUVRect(); | |
| 583 } | |
| 584 | |
| 585 void Layer::SetTextureScale(float x_scale, float y_scale) { | |
| 586 DCHECK(texture_layer_.get()); | |
| 587 texture_x_scale_ = x_scale; | |
| 588 texture_y_scale_ = y_scale; | |
| 589 RecomputeDrawsContentAndUVRect(); | |
| 590 } | |
| 591 | |
| 592 void Layer::SetShowSurface( | 570 void Layer::SetShowSurface( |
| 593 const cc::SurfaceId& surface_id, | 571 const cc::SurfaceId& surface_id, |
| 594 const cc::SurfaceLayer::SatisfyCallback& satisfy_callback, | 572 const cc::SurfaceLayer::SatisfyCallback& satisfy_callback, |
| 595 const cc::SurfaceLayer::RequireCallback& require_callback, | 573 const cc::SurfaceLayer::RequireCallback& require_callback, |
| 596 gfx::Size surface_size, | 574 gfx::Size surface_size, |
| 597 float scale, | 575 float scale, |
| 598 gfx::Size frame_size_in_dip) { | 576 gfx::Size frame_size_in_dip) { |
| 599 DCHECK(type_ == LAYER_TEXTURED || type_ == LAYER_SOLID_COLOR); | 577 DCHECK(type_ == LAYER_TEXTURED || type_ == LAYER_SOLID_COLOR); |
| 600 | 578 |
| 601 scoped_refptr<cc::SurfaceLayer> new_layer = | 579 scoped_refptr<cc::SurfaceLayer> new_layer = |
| (...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1039 gfx::Transform Layer::transform() const { | 1017 gfx::Transform Layer::transform() const { |
| 1040 return cc_layer_->transform(); | 1018 return cc_layer_->transform(); |
| 1041 } | 1019 } |
| 1042 | 1020 |
| 1043 void Layer::RecomputeDrawsContentAndUVRect() { | 1021 void Layer::RecomputeDrawsContentAndUVRect() { |
| 1044 DCHECK(cc_layer_); | 1022 DCHECK(cc_layer_); |
| 1045 gfx::Size size(bounds_.size()); | 1023 gfx::Size size(bounds_.size()); |
| 1046 if (texture_layer_.get()) { | 1024 if (texture_layer_.get()) { |
| 1047 size.SetToMin(frame_size_in_dip_); | 1025 size.SetToMin(frame_size_in_dip_); |
| 1048 gfx::PointF uv_top_left(0.f, 0.f); | 1026 gfx::PointF uv_top_left(0.f, 0.f); |
| 1049 gfx::PointF uv_bottom_right(1.f, 1.f); | 1027 gfx::PointF uv_bottom_right( |
| 1050 if (!texture_crop_.IsEmpty()) { | 1028 static_cast<float>(size.width()) / frame_size_in_dip_.width(), |
| 1051 uv_top_left = texture_crop_.origin(); | 1029 static_cast<float>(size.height()) / frame_size_in_dip_.height()); |
| 1052 uv_top_left.Scale(1.f / frame_size_in_dip_.width(), | |
| 1053 1.f / frame_size_in_dip_.height()); | |
| 1054 uv_bottom_right = texture_crop_.bottom_right(); | |
| 1055 uv_bottom_right.Scale(1.f / frame_size_in_dip_.width(), | |
| 1056 1.f / frame_size_in_dip_.height()); | |
| 1057 } | |
| 1058 float x_scale = texture_x_scale_ * static_cast<float>(size.width()) / | |
| 1059 frame_size_in_dip_.width(); | |
| 1060 float y_scale = texture_y_scale_ * static_cast<float>(size.height()) / | |
| 1061 frame_size_in_dip_.height(); | |
| 1062 uv_top_left.Scale(x_scale, y_scale); | |
| 1063 uv_bottom_right.Scale(x_scale, y_scale); | |
| 1064 texture_layer_->SetUV(uv_top_left, uv_bottom_right); | 1030 texture_layer_->SetUV(uv_top_left, uv_bottom_right); |
| 1065 } else if (surface_layer_.get()) { | 1031 } else if (surface_layer_.get()) { |
| 1066 size.SetToMin(frame_size_in_dip_); | 1032 size.SetToMin(frame_size_in_dip_); |
| 1067 } | 1033 } |
| 1068 cc_layer_->SetBounds(size); | 1034 cc_layer_->SetBounds(size); |
| 1069 } | 1035 } |
| 1070 | 1036 |
| 1071 void Layer::RecomputePosition() { | 1037 void Layer::RecomputePosition() { |
| 1072 cc_layer_->SetPosition(gfx::PointF(bounds_.origin()) + | 1038 cc_layer_->SetPosition(gfx::PointF(bounds_.origin()) + |
| 1073 subpixel_position_offset_); | 1039 subpixel_position_offset_); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1094 if (animator_) { | 1060 if (animator_) { |
| 1095 animator_->ResetCompositor(compositor); | 1061 animator_->ResetCompositor(compositor); |
| 1096 animator_->RemoveFromCollection(collection); | 1062 animator_->RemoveFromCollection(collection); |
| 1097 } | 1063 } |
| 1098 | 1064 |
| 1099 for (auto* child : children_) | 1065 for (auto* child : children_) |
| 1100 child->ResetCompositorForAnimatorsInTree(compositor); | 1066 child->ResetCompositorForAnimatorsInTree(compositor); |
| 1101 } | 1067 } |
| 1102 | 1068 |
| 1103 } // namespace ui | 1069 } // namespace ui |
| OLD | NEW |