OLD | NEW |
(Empty) | |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "webkit/compositor_bindings/web_layer_impl_fixed_bounds.h" |
| 6 |
| 7 #include "cc/layer.h" |
| 8 #include "third_party/WebKit/Source/Platform/chromium/public/WebFloatPoint.h" |
| 9 #include "third_party/WebKit/Source/Platform/chromium/public/WebSize.h" |
| 10 #include "third_party/WebKit/Source/Platform/chromium/public/WebTransformationMa
trix.h" |
| 11 #include "third_party/skia/include/utils/SkMatrix44.h" |
| 12 #include "webkit/compositor_bindings/web_transformation_matrix_util.h" |
| 13 |
| 14 using cc::Layer; |
| 15 using webkit::WebTransformationMatrixUtil; |
| 16 |
| 17 namespace WebKit { |
| 18 |
| 19 WebLayerImplFixedBounds::WebLayerImplFixedBounds() { |
| 20 } |
| 21 |
| 22 WebLayerImplFixedBounds::WebLayerImplFixedBounds(scoped_refptr<Layer> layer) |
| 23 : WebLayerImpl(layer) { |
| 24 } |
| 25 |
| 26 |
| 27 WebLayerImplFixedBounds::~WebLayerImplFixedBounds() { |
| 28 } |
| 29 |
| 30 void WebLayerImplFixedBounds::invalidateRect(const WebFloatRect& rect) { |
| 31 // Partial invalidations seldom occur for such layers. |
| 32 // Simply invalidate the whole layer to avoid transformation of coordinates. |
| 33 invalidate(); |
| 34 } |
| 35 |
| 36 void WebLayerImplFixedBounds::setAnchorPoint( |
| 37 const WebFloatPoint& anchor_point) { |
| 38 if (anchor_point != this->anchorPoint()) { |
| 39 m_layer->setAnchorPoint(anchor_point); |
| 40 UpdateLayerBoundsAndTransform(); |
| 41 } |
| 42 } |
| 43 |
| 44 void WebLayerImplFixedBounds::setBounds(const WebSize& bounds) { |
| 45 if (original_bounds_ != gfx::Size(bounds)) { |
| 46 original_bounds_ = bounds; |
| 47 UpdateLayerBoundsAndTransform(); |
| 48 } |
| 49 } |
| 50 |
| 51 WebSize WebLayerImplFixedBounds::bounds() const { |
| 52 return original_bounds_; |
| 53 } |
| 54 |
| 55 void WebLayerImplFixedBounds::setSublayerTransform(const SkMatrix44& matrix) { |
| 56 gfx::Transform transform; |
| 57 transform.matrix() = matrix; |
| 58 SetSublayerTransformInternal(transform); |
| 59 } |
| 60 |
| 61 void WebLayerImplFixedBounds::setSublayerTransform( |
| 62 const WebTransformationMatrix& matrix) { |
| 63 SetSublayerTransformInternal( |
| 64 WebTransformationMatrixUtil::ToTransform(matrix)); |
| 65 } |
| 66 |
| 67 SkMatrix44 WebLayerImplFixedBounds::sublayerTransform() const { |
| 68 return original_sublayer_transform_.matrix(); |
| 69 } |
| 70 |
| 71 void WebLayerImplFixedBounds::setTransform(const SkMatrix44& matrix) { |
| 72 gfx::Transform transform; |
| 73 transform.matrix() = matrix; |
| 74 SetTransformInternal(transform); |
| 75 } |
| 76 |
| 77 void WebLayerImplFixedBounds::setTransform( |
| 78 const WebTransformationMatrix& matrix) { |
| 79 SetTransformInternal(WebTransformationMatrixUtil::ToTransform(matrix)); |
| 80 } |
| 81 |
| 82 SkMatrix44 WebLayerImplFixedBounds::transform() const { |
| 83 return original_transform_.matrix(); |
| 84 } |
| 85 |
| 86 void WebLayerImplFixedBounds::SetFixedBounds(const gfx::Size& fixed_bounds) { |
| 87 if (fixed_bounds_ != fixed_bounds) { |
| 88 fixed_bounds_ = fixed_bounds; |
| 89 UpdateLayerBoundsAndTransform(); |
| 90 } |
| 91 } |
| 92 |
| 93 void WebLayerImplFixedBounds::SetSublayerTransformInternal( |
| 94 const gfx::Transform& transform) { |
| 95 if (original_sublayer_transform_ != transform) { |
| 96 original_sublayer_transform_ = transform; |
| 97 UpdateLayerBoundsAndTransform(); |
| 98 } |
| 99 } |
| 100 |
| 101 void WebLayerImplFixedBounds::SetTransformInternal( |
| 102 const gfx::Transform& transform) { |
| 103 if (original_transform_ != transform) { |
| 104 original_transform_ = transform; |
| 105 UpdateLayerBoundsAndTransform(); |
| 106 } |
| 107 } |
| 108 |
| 109 void WebLayerImplFixedBounds::UpdateLayerBoundsAndTransform() |
| 110 { |
| 111 if (fixed_bounds_.IsEmpty() || original_bounds_.IsEmpty() || |
| 112 fixed_bounds_ == original_bounds_ || |
| 113 // For now fall back to non-fixed bounds for non-zero anchor point. |
| 114 // TODO(wangxianzhu): Support non-zero anchor point for fixed bounds. |
| 115 anchorPoint().x || anchorPoint().y) { |
| 116 m_layer->setBounds(original_bounds_); |
| 117 m_layer->setTransform(original_transform_); |
| 118 m_layer->setSublayerTransform(original_sublayer_transform_); |
| 119 return; |
| 120 } |
| 121 |
| 122 m_layer->setBounds(fixed_bounds_); |
| 123 |
| 124 // Apply bounds scale (bounds/fixedBounds) over original transform. |
| 125 gfx::Transform transform_with_bounds_scale(original_transform_); |
| 126 float boundsScaleX = |
| 127 static_cast<float>(original_bounds_.width()) / fixed_bounds_.width(); |
| 128 float boundsScaleY = |
| 129 static_cast<float>(original_bounds_.height()) / fixed_bounds_.height(); |
| 130 transform_with_bounds_scale.Scale(boundsScaleX, boundsScaleY); |
| 131 m_layer->setTransform(transform_with_bounds_scale); |
| 132 |
| 133 // As we apply extra scale transform on this layer which will propagate to the |
| 134 // sublayers, here undo the scale on sublayers. |
| 135 gfx::Transform sublayer_transform_with_inverse_bounds_scale; |
| 136 sublayer_transform_with_inverse_bounds_scale.Scale(1.f / boundsScaleX, |
| 137 1.f / boundsScaleY); |
| 138 sublayer_transform_with_inverse_bounds_scale.PreconcatTransform( |
| 139 original_sublayer_transform_); |
| 140 m_layer->setSublayerTransform(sublayer_transform_with_inverse_bounds_scale); |
| 141 } |
| 142 |
| 143 } // namespace WebKit |
OLD | NEW |