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 | |
23 WebLayerImplFixedBounds::WebLayerImplFixedBounds(scoped_refptr<Layer> layer) | |
24 : WebLayerImpl(layer) | |
25 { | |
26 } | |
27 | |
28 | |
29 WebLayerImplFixedBounds::~WebLayerImplFixedBounds() | |
30 { | |
31 } | |
32 | |
33 void WebLayerImplFixedBounds::invalidateRect(const WebFloatRect& rect) | |
34 { | |
35 // Partial invalidations seldom occur for such layers. | |
36 // Simply invalidate the whole layer to avoid transformation of coordinates. | |
37 invalidate(); | |
38 } | |
39 | |
40 void WebLayerImplFixedBounds::setAnchorPoint(const WebFloatPoint& anchorPoint) | |
41 { | |
42 if (anchorPoint != this->anchorPoint()) { | |
43 m_layer->setAnchorPoint(anchorPoint); | |
44 updateLayerBoundsAndTransform(); | |
45 } | |
46 } | |
47 | |
48 void WebLayerImplFixedBounds::setBounds(const WebSize& bounds) | |
49 { | |
50 if (m_originalBounds != gfx::Size(bounds)) { | |
51 m_originalBounds = bounds; | |
52 updateLayerBoundsAndTransform(); | |
53 } | |
54 } | |
55 | |
56 WebSize WebLayerImplFixedBounds::bounds() const | |
57 { | |
58 return m_originalBounds; | |
59 } | |
60 | |
61 void WebLayerImplFixedBounds::setSublayerTransform(const SkMatrix44& matrix) | |
62 { | |
63 gfx::Transform transform; | |
64 transform.matrix() = matrix; | |
65 setSublayerTransformInternal(transform); | |
66 } | |
67 | |
68 void WebLayerImplFixedBounds::setSublayerTransform(const WebTransformationMatrix & matrix) | |
69 { | |
70 setSublayerTransformInternal(WebTransformationMatrixUtil::ToTransform(matrix )); | |
71 } | |
72 | |
73 SkMatrix44 WebLayerImplFixedBounds::sublayerTransform() const | |
74 { | |
75 return m_originalSublayerTransform.matrix(); | |
76 } | |
77 | |
78 void WebLayerImplFixedBounds::setTransform(const SkMatrix44& matrix) | |
79 { | |
80 gfx::Transform transform; | |
81 transform.matrix() = matrix; | |
82 setTransformInternal(transform); | |
83 } | |
84 | |
85 void WebLayerImplFixedBounds::setTransform(const WebTransformationMatrix& matrix ) | |
86 { | |
87 setTransformInternal(WebTransformationMatrixUtil::ToTransform(matrix)); | |
88 } | |
89 | |
90 SkMatrix44 WebLayerImplFixedBounds::transform() const | |
91 { | |
92 return m_originalTransform.matrix(); | |
93 } | |
94 | |
95 void WebLayerImplFixedBounds::setFixedBounds(const gfx::Size& fixedBounds) | |
96 { | |
97 if (m_fixedBounds != fixedBounds) { | |
98 m_fixedBounds = fixedBounds; | |
99 updateLayerBoundsAndTransform(); | |
100 } | |
101 } | |
102 | |
103 void WebLayerImplFixedBounds::setSublayerTransformInternal(const gfx::Transform& transform) | |
104 { | |
105 if (m_originalSublayerTransform != transform) { | |
106 m_originalSublayerTransform = transform; | |
107 updateLayerBoundsAndTransform(); | |
108 } | |
109 } | |
110 | |
111 void WebLayerImplFixedBounds::setTransformInternal(const gfx::Transform& transfo rm) | |
112 { | |
113 if (m_originalTransform != transform) { | |
114 m_originalTransform = transform; | |
115 updateLayerBoundsAndTransform(); | |
116 } | |
117 } | |
118 | |
119 void WebLayerImplFixedBounds::updateLayerBoundsAndTransform() | |
120 { | |
121 if (m_fixedBounds.IsEmpty() || m_originalBounds.IsEmpty() || m_fixedBounds = = m_originalBounds | |
122 // Fall back to non-fixed bounds for non-zero anchor point. | |
enne (OOO)
2013/02/22 23:53:32
Can you make this a TODO, so that it's clear that
Xianzhu
2013/02/23 00:56:19
Done.
| |
123 || anchorPoint().x || anchorPoint().y) { | |
124 m_layer->setBounds(m_originalBounds); | |
125 m_layer->setTransform(m_originalTransform); | |
126 m_layer->setSublayerTransform(m_originalSublayerTransform); | |
127 return; | |
128 } | |
129 | |
130 m_layer->setBounds(m_fixedBounds); | |
131 | |
132 // Apply bounds scale (bounds/fixedBounds) over original transform. | |
133 gfx::Transform transformWithBoundsScale(m_originalTransform); | |
134 float boundsScaleX = static_cast<float>(m_originalBounds.width()) / m_fixedB ounds.width(); | |
135 float boundsScaleY = static_cast<float>(m_originalBounds.height()) / m_fixed Bounds.height(); | |
136 transformWithBoundsScale.Scale(boundsScaleX, boundsScaleY); | |
137 m_layer->setTransform(transformWithBoundsScale); | |
138 | |
139 // As we apply extra scale transform on this layer which will propagate to t he sublayers, | |
140 // here undo the scale on sublayers. | |
141 gfx::Transform sublayerTransformWithInverseBoundsScale; | |
142 sublayerTransformWithInverseBoundsScale.Scale(1.f / boundsScaleX, 1.f / boun dsScaleY); | |
143 sublayerTransformWithInverseBoundsScale.PreconcatTransform(m_originalSublaye rTransform); | |
144 m_layer->setSublayerTransform(sublayerTransformWithInverseBoundsScale); | |
145 } | |
146 | |
147 } // namespace WebKit | |
OLD | NEW |