Chromium Code Reviews| 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/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 24 #include "cc/output/delegated_frame_data.h" | 24 #include "cc/output/delegated_frame_data.h" |
| 25 #include "cc/output/filter_operation.h" | 25 #include "cc/output/filter_operation.h" |
| 26 #include "cc/output/filter_operations.h" | 26 #include "cc/output/filter_operations.h" |
| 27 #include "cc/resources/transferable_resource.h" | 27 #include "cc/resources/transferable_resource.h" |
| 28 #include "ui/compositor/compositor_switches.h" | 28 #include "ui/compositor/compositor_switches.h" |
| 29 #include "ui/compositor/dip_util.h" | 29 #include "ui/compositor/dip_util.h" |
| 30 #include "ui/compositor/layer_animator.h" | 30 #include "ui/compositor/layer_animator.h" |
| 31 #include "ui/gfx/animation/animation.h" | 31 #include "ui/gfx/animation/animation.h" |
| 32 #include "ui/gfx/canvas.h" | 32 #include "ui/gfx/canvas.h" |
| 33 #include "ui/gfx/display.h" | 33 #include "ui/gfx/display.h" |
| 34 #include "ui/gfx/geometry/dip_util.h" | |
| 34 #include "ui/gfx/geometry/point3_f.h" | 35 #include "ui/gfx/geometry/point3_f.h" |
| 35 #include "ui/gfx/geometry/point_conversions.h" | 36 #include "ui/gfx/geometry/point_conversions.h" |
| 36 #include "ui/gfx/geometry/size_conversions.h" | 37 #include "ui/gfx/geometry/size_conversions.h" |
| 37 #include "ui/gfx/interpolated_transform.h" | 38 #include "ui/gfx/interpolated_transform.h" |
| 38 | 39 |
| 39 namespace { | 40 namespace { |
| 40 | 41 |
| 41 const ui::Layer* GetRoot(const ui::Layer* layer) { | 42 const ui::Layer* GetRoot(const ui::Layer* layer) { |
| 42 while (layer->parent()) | 43 while (layer->parent()) |
| 43 layer = layer->parent(); | 44 layer = layer->parent(); |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 70 layer_brightness_(0.0f), | 71 layer_brightness_(0.0f), |
| 71 layer_grayscale_(0.0f), | 72 layer_grayscale_(0.0f), |
| 72 layer_inverted_(false), | 73 layer_inverted_(false), |
| 73 layer_mask_(NULL), | 74 layer_mask_(NULL), |
| 74 layer_mask_back_link_(NULL), | 75 layer_mask_back_link_(NULL), |
| 75 zoom_(1), | 76 zoom_(1), |
| 76 zoom_inset_(0), | 77 zoom_inset_(0), |
| 77 delegate_(NULL), | 78 delegate_(NULL), |
| 78 owner_(NULL), | 79 owner_(NULL), |
| 79 cc_layer_(NULL), | 80 cc_layer_(NULL), |
| 80 device_scale_factor_(1.0f) { | 81 device_scale_factor_(1.0f), |
| 82 nine_patch_layer_bitmap_scale_factor_(1.0f) { | |
|
oshima
2015/03/14 05:42:55
Why you need this? You should just use device_scal
hshi1
2015/03/16 16:50:48
Done.
| |
| 81 CreateCcLayer(); | 83 CreateCcLayer(); |
| 82 } | 84 } |
| 83 | 85 |
| 84 Layer::Layer(LayerType type) | 86 Layer::Layer(LayerType type) |
| 85 : type_(type), | 87 : type_(type), |
| 86 compositor_(NULL), | 88 compositor_(NULL), |
| 87 parent_(NULL), | 89 parent_(NULL), |
| 88 visible_(true), | 90 visible_(true), |
| 89 force_render_surface_(false), | 91 force_render_surface_(false), |
| 90 fills_bounds_opaquely_(true), | 92 fills_bounds_opaquely_(true), |
| 91 fills_bounds_completely_(false), | 93 fills_bounds_completely_(false), |
| 92 background_blur_radius_(0), | 94 background_blur_radius_(0), |
| 93 layer_saturation_(0.0f), | 95 layer_saturation_(0.0f), |
| 94 layer_brightness_(0.0f), | 96 layer_brightness_(0.0f), |
| 95 layer_grayscale_(0.0f), | 97 layer_grayscale_(0.0f), |
| 96 layer_inverted_(false), | 98 layer_inverted_(false), |
| 97 layer_mask_(NULL), | 99 layer_mask_(NULL), |
| 98 layer_mask_back_link_(NULL), | 100 layer_mask_back_link_(NULL), |
| 99 zoom_(1), | 101 zoom_(1), |
| 100 zoom_inset_(0), | 102 zoom_inset_(0), |
| 101 delegate_(NULL), | 103 delegate_(NULL), |
| 102 owner_(NULL), | 104 owner_(NULL), |
| 103 cc_layer_(NULL), | 105 cc_layer_(NULL), |
| 104 device_scale_factor_(1.0f) { | 106 device_scale_factor_(1.0f), |
| 107 nine_patch_layer_bitmap_scale_factor_(1.0f) { | |
| 105 CreateCcLayer(); | 108 CreateCcLayer(); |
| 106 } | 109 } |
| 107 | 110 |
| 108 Layer::~Layer() { | 111 Layer::~Layer() { |
| 109 // Destroying the animator may cause observers to use the layer (and | 112 // Destroying the animator may cause observers to use the layer (and |
| 110 // indirectly the WebLayer). Destroy the animator first so that the WebLayer | 113 // indirectly the WebLayer). Destroy the animator first so that the WebLayer |
| 111 // is still around. | 114 // is still around. |
| 112 if (animator_.get()) | 115 if (animator_.get()) |
| 113 animator_->SetDelegate(NULL); | 116 animator_->SetDelegate(NULL); |
| 114 animator_ = NULL; | 117 animator_ = NULL; |
| (...skipping 498 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 613 solid_color_layer_ = new_layer; | 616 solid_color_layer_ = new_layer; |
| 614 | 617 |
| 615 mailbox_ = cc::TextureMailbox(); | 618 mailbox_ = cc::TextureMailbox(); |
| 616 if (mailbox_release_callback_) { | 619 if (mailbox_release_callback_) { |
| 617 mailbox_release_callback_->Run(0, false); | 620 mailbox_release_callback_->Run(0, false); |
| 618 mailbox_release_callback_.reset(); | 621 mailbox_release_callback_.reset(); |
| 619 } | 622 } |
| 620 RecomputeDrawsContentAndUVRect(); | 623 RecomputeDrawsContentAndUVRect(); |
| 621 } | 624 } |
| 622 | 625 |
| 623 void Layer::UpdateNinePatchLayerBitmap(const SkBitmap& bitmap) { | 626 void Layer::UpdateNinePatchLayerImage(const gfx::ImageSkia& image) { |
| 624 DCHECK(type_ == LAYER_NINE_PATCH && nine_patch_layer_.get()); | 627 DCHECK(type_ == LAYER_NINE_PATCH && nine_patch_layer_.get()); |
| 628 nine_patch_layer_bitmap_scale_factor_ = device_scale_factor_; | |
| 629 SkBitmap bitmap = image.GetRepresentation( | |
| 630 nine_patch_layer_bitmap_scale_factor_).sk_bitmap(); | |
| 625 SkBitmap bitmap_copy; | 631 SkBitmap bitmap_copy; |
| 626 if (bitmap.isImmutable()) { | 632 if (bitmap.isImmutable()) { |
| 627 bitmap_copy = bitmap; | 633 bitmap_copy = bitmap; |
| 628 } else { | 634 } else { |
| 629 // UIResourceBitmap requires an immutable copy of the input |bitmap|. | 635 // UIResourceBitmap requires an immutable copy of the input |bitmap|. |
| 630 bitmap.copyTo(&bitmap_copy); | 636 bitmap.copyTo(&bitmap_copy); |
| 631 bitmap_copy.setImmutable(); | 637 bitmap_copy.setImmutable(); |
| 632 } | 638 } |
| 633 nine_patch_layer_->SetBitmap(bitmap_copy); | 639 nine_patch_layer_->SetBitmap(bitmap_copy); |
| 634 } | 640 } |
| 635 | 641 |
| 636 void Layer::UpdateNinePatchLayerAperture(const gfx::Rect& aperture) { | 642 void Layer::UpdateNinePatchLayerAperture(const gfx::Rect& aperture) { |
| 637 DCHECK(type_ == LAYER_NINE_PATCH && nine_patch_layer_.get()); | 643 DCHECK(type_ == LAYER_NINE_PATCH && nine_patch_layer_.get()); |
| 638 nine_patch_layer_->SetAperture(aperture); | 644 gfx::Rect aperture_in_pixel = |
| 645 gfx::ConvertRectToPixel(nine_patch_layer_bitmap_scale_factor_, aperture); | |
| 646 nine_patch_layer_->SetAperture(aperture_in_pixel); | |
| 639 } | 647 } |
| 640 | 648 |
| 641 void Layer::UpdateNinePatchLayerBorder(const gfx::Rect& border) { | 649 void Layer::UpdateNinePatchLayerBorder(const gfx::Rect& border) { |
| 642 DCHECK(type_ == LAYER_NINE_PATCH && nine_patch_layer_.get()); | 650 DCHECK(type_ == LAYER_NINE_PATCH && nine_patch_layer_.get()); |
| 643 nine_patch_layer_->SetBorder(border); | 651 nine_patch_layer_->SetBorder(border); |
| 644 } | 652 } |
| 645 | 653 |
| 646 void Layer::SetColor(SkColor color) { GetAnimator()->SetColor(color); } | 654 void Layer::SetColor(SkColor color) { GetAnimator()->SetColor(color); } |
| 647 | 655 |
| 648 bool Layer::SchedulePaint(const gfx::Rect& invalid_rect) { | 656 bool Layer::SchedulePaint(const gfx::Rect& invalid_rect) { |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 699 delegate_ = NULL; | 707 delegate_ = NULL; |
| 700 for (size_t i = 0; i < children_.size(); ++i) | 708 for (size_t i = 0; i < children_.size(); ++i) |
| 701 children_[i]->SuppressPaint(); | 709 children_[i]->SuppressPaint(); |
| 702 } | 710 } |
| 703 | 711 |
| 704 void Layer::OnDeviceScaleFactorChanged(float device_scale_factor) { | 712 void Layer::OnDeviceScaleFactorChanged(float device_scale_factor) { |
| 705 if (device_scale_factor_ == device_scale_factor) | 713 if (device_scale_factor_ == device_scale_factor) |
| 706 return; | 714 return; |
| 707 if (animator_.get()) | 715 if (animator_.get()) |
| 708 animator_->StopAnimatingProperty(LayerAnimationElement::TRANSFORM); | 716 animator_->StopAnimatingProperty(LayerAnimationElement::TRANSFORM); |
| 709 device_scale_factor_ = device_scale_factor; | 717 device_scale_factor_ = device_scale_factor; |
|
oshima
2015/03/14 05:42:55
you need to update the image here.
hshi1
2015/03/16 16:50:47
Done.
| |
| 710 RecomputeDrawsContentAndUVRect(); | 718 RecomputeDrawsContentAndUVRect(); |
| 711 RecomputePosition(); | 719 RecomputePosition(); |
| 712 SchedulePaint(gfx::Rect(bounds_.size())); | 720 SchedulePaint(gfx::Rect(bounds_.size())); |
| 713 if (delegate_) | 721 if (delegate_) |
| 714 delegate_->OnDeviceScaleFactorChanged(device_scale_factor); | 722 delegate_->OnDeviceScaleFactorChanged(device_scale_factor); |
| 715 for (size_t i = 0; i < children_.size(); ++i) | 723 for (size_t i = 0; i < children_.size(); ++i) |
| 716 children_[i]->OnDeviceScaleFactorChanged(device_scale_factor); | 724 children_[i]->OnDeviceScaleFactorChanged(device_scale_factor); |
| 717 if (layer_mask_) | 725 if (layer_mask_) |
| 718 layer_mask_->OnDeviceScaleFactorChanged(device_scale_factor); | 726 layer_mask_->OnDeviceScaleFactorChanged(device_scale_factor); |
| 719 } | 727 } |
| (...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1071 children_.end(), | 1079 children_.end(), |
| 1072 std::bind2nd(std::mem_fun(&Layer::RemoveAnimatorsInTreeFromCollection), | 1080 std::bind2nd(std::mem_fun(&Layer::RemoveAnimatorsInTreeFromCollection), |
| 1073 collection)); | 1081 collection)); |
| 1074 } | 1082 } |
| 1075 | 1083 |
| 1076 bool Layer::IsAnimating() const { | 1084 bool Layer::IsAnimating() const { |
| 1077 return animator_.get() && animator_->is_animating(); | 1085 return animator_.get() && animator_->is_animating(); |
| 1078 } | 1086 } |
| 1079 | 1087 |
| 1080 } // namespace ui | 1088 } // namespace ui |
| OLD | NEW |