OLD | NEW |
1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "cc/layer_tree_host_common.h" | 5 #include "cc/layer_tree_host_common.h" |
6 | 6 |
| 7 #include <algorithm> |
| 8 |
7 #include "cc/layer.h" | 9 #include "cc/layer.h" |
8 #include "cc/layer_impl.h" | 10 #include "cc/layer_impl.h" |
9 #include "cc/layer_iterator.h" | 11 #include "cc/layer_iterator.h" |
10 #include "cc/layer_sorter.h" | 12 #include "cc/layer_sorter.h" |
11 #include "cc/math_util.h" | 13 #include "cc/math_util.h" |
12 #include "cc/render_surface.h" | 14 #include "cc/render_surface.h" |
13 #include "cc/render_surface_impl.h" | 15 #include "cc/render_surface_impl.h" |
14 #include "ui/gfx/point_conversions.h" | 16 #include "ui/gfx/point_conversions.h" |
15 #include "ui/gfx/rect_conversions.h" | 17 #include "ui/gfx/rect_conversions.h" |
16 #include <algorithm> | 18 #include "ui/gfx/transform.h" |
17 #include <public/WebTransformationMatrix.h> | |
18 | |
19 using WebKit::WebTransformationMatrix; | |
20 | 19 |
21 namespace cc { | 20 namespace cc { |
22 | 21 |
23 ScrollAndScaleSet::ScrollAndScaleSet() | 22 ScrollAndScaleSet::ScrollAndScaleSet() |
24 { | 23 { |
25 } | 24 } |
26 | 25 |
27 ScrollAndScaleSet::~ScrollAndScaleSet() | 26 ScrollAndScaleSet::~ScrollAndScaleSet() |
28 { | 27 { |
29 } | 28 } |
30 | 29 |
31 gfx::Rect LayerTreeHostCommon::calculateVisibleRect(const gfx::Rect& targetSurfa
ceRect, const gfx::Rect& layerBoundRect, const WebTransformationMatrix& transfor
m) | 30 gfx::Rect LayerTreeHostCommon::calculateVisibleRect(const gfx::Rect& targetSurfa
ceRect, const gfx::Rect& layerBoundRect, const gfx::Transform& transform) |
32 { | 31 { |
33 // Is this layer fully contained within the target surface? | 32 // Is this layer fully contained within the target surface? |
34 gfx::Rect layerInSurfaceSpace = MathUtil::mapClippedRect(transform, layerBou
ndRect); | 33 gfx::Rect layerInSurfaceSpace = MathUtil::mapClippedRect(transform, layerBou
ndRect); |
35 if (targetSurfaceRect.Contains(layerInSurfaceSpace)) | 34 if (targetSurfaceRect.Contains(layerInSurfaceSpace)) |
36 return layerBoundRect; | 35 return layerBoundRect; |
37 | 36 |
38 // If the layer doesn't fill up the entire surface, then find the part of | 37 // If the layer doesn't fill up the entire surface, then find the part of |
39 // the surface rect where the layer could be visible. This avoids trying to | 38 // the surface rect where the layer could be visible. This avoids trying to |
40 // project surface rect points that are behind the projection point. | 39 // project surface rect points that are behind the projection point. |
41 gfx::Rect minimalSurfaceRect = targetSurfaceRect; | 40 gfx::Rect minimalSurfaceRect = targetSurfaceRect; |
42 minimalSurfaceRect.Intersect(layerInSurfaceSpace); | 41 minimalSurfaceRect.Intersect(layerInSurfaceSpace); |
43 | 42 |
44 // Project the corners of the target surface rect into the layer space. | 43 // Project the corners of the target surface rect into the layer space. |
45 // This bounding rectangle may be larger than it needs to be (being | 44 // This bounding rectangle may be larger than it needs to be (being |
46 // axis-aligned), but is a reasonable filter on the space to consider. | 45 // axis-aligned), but is a reasonable filter on the space to consider. |
47 // Non-invertible transforms will create an empty rect here. | 46 // Non-invertible transforms will create an empty rect here. |
48 const WebTransformationMatrix surfaceToLayer = transform.inverse(); | 47 const gfx::Transform surfaceToLayer = MathUtil::inverse(transform); |
49 gfx::Rect layerRect = gfx::ToEnclosingRect(MathUtil::projectClippedRect(surf
aceToLayer, gfx::RectF(minimalSurfaceRect))); | 48 gfx::Rect layerRect = gfx::ToEnclosingRect(MathUtil::projectClippedRect(surf
aceToLayer, gfx::RectF(minimalSurfaceRect))); |
50 layerRect.Intersect(layerBoundRect); | 49 layerRect.Intersect(layerBoundRect); |
51 return layerRect; | 50 return layerRect; |
52 } | 51 } |
53 | 52 |
54 template <typename LayerType> | 53 template <typename LayerType> |
55 static inline bool isRootLayer(LayerType* layer) | 54 static inline bool isRootLayer(LayerType* layer) |
56 { | 55 { |
57 return !layer->parent(); | 56 return !layer->parent(); |
58 } | 57 } |
(...skipping 20 matching lines...) Expand all Loading... |
79 | 78 |
80 template<typename LayerType> | 79 template<typename LayerType> |
81 static bool isLayerBackFaceVisible(LayerType* layer) | 80 static bool isLayerBackFaceVisible(LayerType* layer) |
82 { | 81 { |
83 // The current W3C spec on CSS transforms says that backface visibility shou
ld be | 82 // The current W3C spec on CSS transforms says that backface visibility shou
ld be |
84 // determined differently depending on whether the layer is in a "3d renderi
ng | 83 // determined differently depending on whether the layer is in a "3d renderi
ng |
85 // context" or not. For Chromium code, we can determine whether we are in a
3d | 84 // context" or not. For Chromium code, we can determine whether we are in a
3d |
86 // rendering context by checking if the parent preserves 3d. | 85 // rendering context by checking if the parent preserves 3d. |
87 | 86 |
88 if (layerIsInExisting3DRenderingContext(layer)) | 87 if (layerIsInExisting3DRenderingContext(layer)) |
89 return layer->drawTransform().isBackFaceVisible(); | 88 return MathUtil::isBackFaceVisible(layer->drawTransform()); |
90 | 89 |
91 // In this case, either the layer establishes a new 3d rendering context, or
is not in | 90 // In this case, either the layer establishes a new 3d rendering context, or
is not in |
92 // a 3d rendering context at all. | 91 // a 3d rendering context at all. |
93 return layer->transform().isBackFaceVisible(); | 92 return MathUtil::isBackFaceVisible(layer->transform()); |
94 } | 93 } |
95 | 94 |
96 template<typename LayerType> | 95 template<typename LayerType> |
97 static bool isSurfaceBackFaceVisible(LayerType* layer, const WebTransformationMa
trix& drawTransform) | 96 static bool isSurfaceBackFaceVisible(LayerType* layer, const gfx::Transform& dra
wTransform) |
98 { | 97 { |
99 if (layerIsInExisting3DRenderingContext(layer)) | 98 if (layerIsInExisting3DRenderingContext(layer)) |
100 return drawTransform.isBackFaceVisible(); | 99 return MathUtil::isBackFaceVisible(drawTransform); |
101 | 100 |
102 if (isRootLayerOfNewRenderingContext(layer)) | 101 if (isRootLayerOfNewRenderingContext(layer)) |
103 return layer->transform().isBackFaceVisible(); | 102 return MathUtil::isBackFaceVisible(layer->transform()); |
104 | 103 |
105 // If the renderSurface is not part of a new or existing rendering context,
then the | 104 // If the renderSurface is not part of a new or existing rendering context,
then the |
106 // layers that contribute to this surface will decide back-face visibility f
or themselves. | 105 // layers that contribute to this surface will decide back-face visibility f
or themselves. |
107 return false; | 106 return false; |
108 } | 107 } |
109 | 108 |
110 template<typename LayerType> | 109 template<typename LayerType> |
111 static inline bool layerClipsSubtree(LayerType* layer) | 110 static inline bool layerClipsSubtree(LayerType* layer) |
112 { | 111 { |
113 return layer->masksToBounds() || layer->maskLayer(); | 112 return layer->masksToBounds() || layer->maskLayer(); |
(...skipping 10 matching lines...) Expand all Loading... |
124 | 123 |
125 gfx::Rect targetSurfaceClipRect; | 124 gfx::Rect targetSurfaceClipRect; |
126 | 125 |
127 // First, compute visible bounds in target surface space. | 126 // First, compute visible bounds in target surface space. |
128 if (layer->renderTarget()->renderSurface()->clipRect().IsEmpty()) | 127 if (layer->renderTarget()->renderSurface()->clipRect().IsEmpty()) |
129 targetSurfaceClipRect = layer->drawableContentRect(); | 128 targetSurfaceClipRect = layer->drawableContentRect(); |
130 else { | 129 else { |
131 // In this case the target surface does clip layers that contribute to i
t. So, we | 130 // In this case the target surface does clip layers that contribute to i
t. So, we |
132 // have convert the current surface's clipRect from its ancestor surface
space to | 131 // have convert the current surface's clipRect from its ancestor surface
space to |
133 // the current surface space. | 132 // the current surface space. |
134 targetSurfaceClipRect = gfx::ToEnclosingRect(MathUtil::projectClippedRec
t(layer->renderTarget()->renderSurface()->drawTransform().inverse(), layer->rend
erTarget()->renderSurface()->clipRect())); | 133 targetSurfaceClipRect = gfx::ToEnclosingRect(MathUtil::projectClippedRec
t(MathUtil::inverse(layer->renderTarget()->renderSurface()->drawTransform()), la
yer->renderTarget()->renderSurface()->clipRect())); |
135 targetSurfaceClipRect.Intersect(layer->drawableContentRect()); | 134 targetSurfaceClipRect.Intersect(layer->drawableContentRect()); |
136 } | 135 } |
137 | 136 |
138 if (targetSurfaceClipRect.IsEmpty()) | 137 if (targetSurfaceClipRect.IsEmpty()) |
139 return gfx::Rect(); | 138 return gfx::Rect(); |
140 | 139 |
141 return LayerTreeHostCommon::calculateVisibleRect(targetSurfaceClipRect, gfx:
:Rect(gfx::Point(), layer->contentBounds()), layer->drawTransform()); | 140 return LayerTreeHostCommon::calculateVisibleRect(targetSurfaceClipRect, gfx:
:Rect(gfx::Point(), layer->contentBounds()), layer->drawTransform()); |
142 } | 141 } |
143 | 142 |
144 static bool isScaleOrTranslation(const WebTransformationMatrix& m) | 143 static bool isScaleOrTranslation(const gfx::Transform& m) |
145 { | 144 { |
146 return !m.m12() && !m.m13() && !m.m14() | 145 return !m.matrix().getDouble(1, 0) && !m.matrix().getDouble(2, 0) && !m.matr
ix().getDouble(3, 0) |
147 && !m.m21() && !m.m23() && !m.m24() | 146 && !m.matrix().getDouble(0, 1) && !m.matrix().getDouble(2, 1) && !m.m
atrix().getDouble(3, 1) |
148 && !m.m31() && !m.m32() && !m.m43() | 147 && !m.matrix().getDouble(0, 2) && !m.matrix().getDouble(1, 2) && !m.m
atrix().getDouble(2, 3) |
149 && m.m44(); | 148 && m.matrix().getDouble(3, 3); |
150 } | 149 } |
151 | 150 |
152 static inline bool transformToParentIsKnown(LayerImpl*) | 151 static inline bool transformToParentIsKnown(LayerImpl*) |
153 { | 152 { |
154 return true; | 153 return true; |
155 } | 154 } |
156 | 155 |
157 static inline bool transformToParentIsKnown(Layer* layer) | 156 static inline bool transformToParentIsKnown(Layer* layer) |
158 { | 157 { |
159 return !layer->transformIsAnimating(); | 158 return !layer->transformIsAnimating(); |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 if (layerClipsSubtree(layer) && !axisAlignedWithRespectToParent && descendan
tDrawsContent) | 257 if (layerClipsSubtree(layer) && !axisAlignedWithRespectToParent && descendan
tDrawsContent) |
259 return true; | 258 return true; |
260 | 259 |
261 // If the layer has opacity != 1 and does not have a preserves-3d transform
style. | 260 // If the layer has opacity != 1 and does not have a preserves-3d transform
style. |
262 if (layer->opacity() != 1 && !layer->preserves3D() && descendantDrawsContent
) | 261 if (layer->opacity() != 1 && !layer->preserves3D() && descendantDrawsContent
) |
263 return true; | 262 return true; |
264 | 263 |
265 return false; | 264 return false; |
266 } | 265 } |
267 | 266 |
268 WebTransformationMatrix computeScrollCompensationForThisLayer(LayerImpl* scrolli
ngLayer, const WebTransformationMatrix& parentMatrix) | 267 gfx::Transform computeScrollCompensationForThisLayer(LayerImpl* scrollingLayer,
const gfx::Transform& parentMatrix) |
269 { | 268 { |
270 // For every layer that has non-zero scrollDelta, we have to compute a trans
form that can undo the | 269 // For every layer that has non-zero scrollDelta, we have to compute a trans
form that can undo the |
271 // scrollDelta translation. In particular, we want this matrix to premultipl
y a fixed-position layer's | 270 // scrollDelta translation. In particular, we want this matrix to premultipl
y a fixed-position layer's |
272 // parentMatrix, so we design this transform in three steps as follows. The
steps described here apply | 271 // parentMatrix, so we design this transform in three steps as follows. The
steps described here apply |
273 // from right-to-left, so Step 1 would be the right-most matrix: | 272 // from right-to-left, so Step 1 would be the right-most matrix: |
274 // | 273 // |
275 // Step 1. transform from target surface space to the exact space where
scrollDelta is actually applied. | 274 // Step 1. transform from target surface space to the exact space where
scrollDelta is actually applied. |
276 // -- this is inverse of the matrix in step 3 | 275 // -- this is inverse of the matrix in step 3 |
277 // Step 2. undo the scrollDelta | 276 // Step 2. undo the scrollDelta |
278 // -- this is just a translation by scrollDelta. | 277 // -- this is just a translation by scrollDelta. |
279 // Step 3. transform back to target surface space. | 278 // Step 3. transform back to target surface space. |
280 // -- this transform is the "partialLayerOriginTransform" = (paren
tMatrix * scale(layer->pageScaleDelta())); | 279 // -- this transform is the "partialLayerOriginTransform" = (paren
tMatrix * scale(layer->pageScaleDelta())); |
281 // | 280 // |
282 // These steps create a matrix that both start and end in targetSurfaceSpace
. So this matrix can | 281 // These steps create a matrix that both start and end in targetSurfaceSpace
. So this matrix can |
283 // pre-multiply any fixed-position layer's drawTransform to undo the scrollD
eltas -- as long as | 282 // pre-multiply any fixed-position layer's drawTransform to undo the scrollD
eltas -- as long as |
284 // that fixed position layer is fixed onto the same renderTarget as this scr
ollingLayer. | 283 // that fixed position layer is fixed onto the same renderTarget as this scr
ollingLayer. |
285 // | 284 // |
286 | 285 |
287 WebTransformationMatrix partialLayerOriginTransform = parentMatrix; | 286 gfx::Transform partialLayerOriginTransform = parentMatrix; |
288 partialLayerOriginTransform.multiply(scrollingLayer->implTransform()); | 287 partialLayerOriginTransform.PreconcatTransform(scrollingLayer->implTransform
()); |
289 | 288 |
290 WebTransformationMatrix scrollCompensationForThisLayer = partialLayerOriginT
ransform; // Step 3 | 289 gfx::Transform scrollCompensationForThisLayer = partialLayerOriginTransform;
// Step 3 |
291 scrollCompensationForThisLayer.translate(scrollingLayer->scrollDelta().x(),
scrollingLayer->scrollDelta().y()); // Step 2 | 290 scrollCompensationForThisLayer.Translate(scrollingLayer->scrollDelta().x(),
scrollingLayer->scrollDelta().y()); // Step 2 |
292 scrollCompensationForThisLayer.multiply(partialLayerOriginTransform.inverse(
)); // Step 1 | 291 scrollCompensationForThisLayer.PreconcatTransform(MathUtil::inverse(partialL
ayerOriginTransform)); // Step 1 |
293 return scrollCompensationForThisLayer; | 292 return scrollCompensationForThisLayer; |
294 } | 293 } |
295 | 294 |
296 WebTransformationMatrix computeScrollCompensationMatrixForChildren(Layer* curren
tLayer, const WebTransformationMatrix& currentParentMatrix, const WebTransformat
ionMatrix& currentScrollCompensation) | 295 gfx::Transform computeScrollCompensationMatrixForChildren(Layer* currentLayer, c
onst gfx::Transform& currentParentMatrix, const gfx::Transform& currentScrollCom
pensation) |
297 { | 296 { |
298 // The main thread (i.e. Layer) does not need to worry about scroll compensa
tion. | 297 // The main thread (i.e. Layer) does not need to worry about scroll compensa
tion. |
299 // So we can just return an identity matrix here. | 298 // So we can just return an identity matrix here. |
300 return WebTransformationMatrix(); | 299 return gfx::Transform(); |
301 } | 300 } |
302 | 301 |
303 WebTransformationMatrix computeScrollCompensationMatrixForChildren(LayerImpl* la
yer, const WebTransformationMatrix& parentMatrix, const WebTransformationMatrix&
currentScrollCompensationMatrix) | 302 gfx::Transform computeScrollCompensationMatrixForChildren(LayerImpl* layer, cons
t gfx::Transform& parentMatrix, const gfx::Transform& currentScrollCompensationM
atrix) |
304 { | 303 { |
305 // "Total scroll compensation" is the transform needed to cancel out all scr
ollDelta translations that | 304 // "Total scroll compensation" is the transform needed to cancel out all scr
ollDelta translations that |
306 // occurred since the nearest container layer, even if there are renderSurfa
ces in-between. | 305 // occurred since the nearest container layer, even if there are renderSurfa
ces in-between. |
307 // | 306 // |
308 // There are some edge cases to be aware of, that are not explicit in the co
de: | 307 // There are some edge cases to be aware of, that are not explicit in the co
de: |
309 // - A layer that is both a fixed-position and container should not be its
own container, instead, that means | 308 // - A layer that is both a fixed-position and container should not be its
own container, instead, that means |
310 // it is fixed to an ancestor, and is a container for any fixed-position
descendants. | 309 // it is fixed to an ancestor, and is a container for any fixed-position
descendants. |
311 // - A layer that is a fixed-position container and has a renderSurface sho
uld behave the same as a container | 310 // - A layer that is a fixed-position container and has a renderSurface sho
uld behave the same as a container |
312 // without a renderSurface, the renderSurface is irrelevant in that case. | 311 // without a renderSurface, the renderSurface is irrelevant in that case. |
313 // - A layer that does not have an explicit container is simply fixed to th
e viewport. | 312 // - A layer that does not have an explicit container is simply fixed to th
e viewport. |
314 // (i.e. the root renderSurface.) | 313 // (i.e. the root renderSurface.) |
315 // - If the fixed-position layer has its own renderSurface, then the render
Surface is | 314 // - If the fixed-position layer has its own renderSurface, then the render
Surface is |
316 // the one who gets fixed. | 315 // the one who gets fixed. |
317 // | 316 // |
318 // This function needs to be called AFTER layers create their own renderSurf
aces. | 317 // This function needs to be called AFTER layers create their own renderSurf
aces. |
319 // | 318 // |
320 | 319 |
321 // Avoid the overheads (including stack allocation and matrix initialization
/copy) if we know that the scroll compensation doesn't need to be reset or adjus
ted. | 320 // Avoid the overheads (including stack allocation and matrix initialization
/copy) if we know that the scroll compensation doesn't need to be reset or adjus
ted. |
322 if (!layer->isContainerForFixedPositionLayers() && layer->scrollDelta().IsZe
ro() && !layer->renderSurface()) | 321 if (!layer->isContainerForFixedPositionLayers() && layer->scrollDelta().IsZe
ro() && !layer->renderSurface()) |
323 return currentScrollCompensationMatrix; | 322 return currentScrollCompensationMatrix; |
324 | 323 |
325 // Start as identity matrix. | 324 // Start as identity matrix. |
326 WebTransformationMatrix nextScrollCompensationMatrix; | 325 gfx::Transform nextScrollCompensationMatrix; |
327 | 326 |
328 // If this layer is not a container, then it inherits the existing scroll co
mpensations. | 327 // If this layer is not a container, then it inherits the existing scroll co
mpensations. |
329 if (!layer->isContainerForFixedPositionLayers()) | 328 if (!layer->isContainerForFixedPositionLayers()) |
330 nextScrollCompensationMatrix = currentScrollCompensationMatrix; | 329 nextScrollCompensationMatrix = currentScrollCompensationMatrix; |
331 | 330 |
332 // If the current layer has a non-zero scrollDelta, then we should compute i
ts local scrollCompensation | 331 // If the current layer has a non-zero scrollDelta, then we should compute i
ts local scrollCompensation |
333 // and accumulate it to the nextScrollCompensationMatrix. | 332 // and accumulate it to the nextScrollCompensationMatrix. |
334 if (!layer->scrollDelta().IsZero()) { | 333 if (!layer->scrollDelta().IsZero()) { |
335 WebTransformationMatrix scrollCompensationForThisLayer = computeScrollCo
mpensationForThisLayer(layer, parentMatrix); | 334 gfx::Transform scrollCompensationForThisLayer = computeScrollCompensatio
nForThisLayer(layer, parentMatrix); |
336 nextScrollCompensationMatrix.multiply(scrollCompensationForThisLayer); | 335 nextScrollCompensationMatrix.PreconcatTransform(scrollCompensationForThi
sLayer); |
337 } | 336 } |
338 | 337 |
339 // If the layer created its own renderSurface, we have to adjust nextScrollC
ompensationMatrix. | 338 // If the layer created its own renderSurface, we have to adjust nextScrollC
ompensationMatrix. |
340 // The adjustment allows us to continue using the scrollCompensation on the
next surface. | 339 // The adjustment allows us to continue using the scrollCompensation on the
next surface. |
341 // Step 1 (right-most in the math): transform from the new surface to the o
riginal ancestor surface | 340 // Step 1 (right-most in the math): transform from the new surface to the o
riginal ancestor surface |
342 // Step 2: apply the scroll compensation | 341 // Step 2: apply the scroll compensation |
343 // Step 3: transform back to the new surface. | 342 // Step 3: transform back to the new surface. |
344 if (layer->renderSurface() && !nextScrollCompensationMatrix.isIdentity()) | 343 if (layer->renderSurface() && !nextScrollCompensationMatrix.IsIdentity()) |
345 nextScrollCompensationMatrix = layer->renderSurface()->drawTransform().i
nverse() * nextScrollCompensationMatrix * layer->renderSurface()->drawTransform(
); | 344 nextScrollCompensationMatrix = MathUtil::inverse(layer->renderSurface()-
>drawTransform()) * nextScrollCompensationMatrix * layer->renderSurface()->drawT
ransform(); |
346 | 345 |
347 return nextScrollCompensationMatrix; | 346 return nextScrollCompensationMatrix; |
348 } | 347 } |
349 | 348 |
350 // There is no contentsScale on impl thread. | 349 // There is no contentsScale on impl thread. |
351 static inline void updateLayerContentsScale(LayerImpl*, const WebTransformationM
atrix&, float, float, bool) { } | 350 static inline void updateLayerContentsScale(LayerImpl*, const gfx::Transform&, f
loat, float, bool) { } |
352 | 351 |
353 static inline void updateLayerContentsScale(Layer* layer, const WebTransformatio
nMatrix& combinedTransform, float deviceScaleFactor, float pageScaleFactor, bool
animatingTransformToScreen) | 352 static inline void updateLayerContentsScale(Layer* layer, const gfx::Transform&
combinedTransform, float deviceScaleFactor, float pageScaleFactor, bool animatin
gTransformToScreen) |
354 { | 353 { |
355 float rasterScale = layer->rasterScale(); | 354 float rasterScale = layer->rasterScale(); |
356 if (!rasterScale) { | 355 if (!rasterScale) { |
357 rasterScale = 1; | 356 rasterScale = 1; |
358 | 357 |
359 if (!animatingTransformToScreen && layer->automaticallyComputeRasterScal
e()) { | 358 if (!animatingTransformToScreen && layer->automaticallyComputeRasterScal
e()) { |
360 gfx::Vector2dF transformScale = MathUtil::computeTransform2dScaleCom
ponents(combinedTransform); | 359 gfx::Vector2dF transformScale = MathUtil::computeTransform2dScaleCom
ponents(combinedTransform); |
361 float combinedScale = std::max(transformScale.x(), transformScale.y(
)); | 360 float combinedScale = std::max(transformScale.x(), transformScale.y(
)); |
362 rasterScale = combinedScale / deviceScaleFactor; | 361 rasterScale = combinedScale / deviceScaleFactor; |
363 if (!layer->boundsContainPageScale()) | 362 if (!layer->boundsContainPageScale()) |
(...skipping 16 matching lines...) Expand all Loading... |
380 maskLayer->setContentsScale(contentsScale); | 379 maskLayer->setContentsScale(contentsScale); |
381 | 380 |
382 Layer* replicaMaskLayer = layer->replicaLayer() ? layer->replicaLayer()->mas
kLayer() : 0; | 381 Layer* replicaMaskLayer = layer->replicaLayer() ? layer->replicaLayer()->mas
kLayer() : 0; |
383 if (replicaMaskLayer) | 382 if (replicaMaskLayer) |
384 replicaMaskLayer->setContentsScale(contentsScale); | 383 replicaMaskLayer->setContentsScale(contentsScale); |
385 } | 384 } |
386 | 385 |
387 // Recursively walks the layer tree starting at the given node and computes all
the | 386 // Recursively walks the layer tree starting at the given node and computes all
the |
388 // necessary transformations, clipRects, render surfaces, etc. | 387 // necessary transformations, clipRects, render surfaces, etc. |
389 template<typename LayerType, typename LayerList, typename RenderSurfaceType, typ
ename LayerSorter> | 388 template<typename LayerType, typename LayerList, typename RenderSurfaceType, typ
ename LayerSorter> |
390 static void calculateDrawTransformsInternal(LayerType* layer, const WebTransform
ationMatrix& parentMatrix, | 389 static void calculateDrawTransformsInternal(LayerType* layer, const gfx::Transfo
rm& parentMatrix, |
391 const WebTransformationMatrix& fullHierarchyMatrix, const WebTransformationM
atrix& currentScrollCompensationMatrix, | 390 const gfx::Transform& fullHierarchyMatrix, const gfx::Transform& currentScro
llCompensationMatrix, |
392 const gfx::Rect& clipRectFromAncestor, bool ancestorClipsSubtree, | 391 const gfx::Rect& clipRectFromAncestor, bool ancestorClipsSubtree, |
393 RenderSurfaceType* nearestAncestorThatMovesPixels, LayerList& renderSurfaceL
ayerList, LayerList& layerList, | 392 RenderSurfaceType* nearestAncestorThatMovesPixels, LayerList& renderSurfaceL
ayerList, LayerList& layerList, |
394 LayerSorter* layerSorter, int maxTextureSize, float deviceScaleFactor, float
pageScaleFactor, gfx::Rect& drawableContentRectOfSubtree) | 393 LayerSorter* layerSorter, int maxTextureSize, float deviceScaleFactor, float
pageScaleFactor, gfx::Rect& drawableContentRectOfSubtree) |
395 { | 394 { |
396 // This function computes the new matrix transformations recursively for thi
s | 395 // This function computes the new matrix transformations recursively for thi
s |
397 // layer and all its descendants. It also computes the appropriate render su
rfaces. | 396 // layer and all its descendants. It also computes the appropriate render su
rfaces. |
398 // Some important points to remember: | 397 // Some important points to remember: |
399 // | 398 // |
400 // 0. Here, transforms are notated in Matrix x Vector order, and in words we
describe what | 399 // 0. Here, transforms are notated in Matrix x Vector order, and in words we
describe what |
401 // the transform does from left to right. | 400 // the transform does from left to right. |
402 // | 401 // |
403 // 1. In our terminology, the "layer origin" refers to the top-left corner o
f a layer, and the | 402 // 1. In our terminology, the "layer origin" refers to the top-left corner o
f a layer, and the |
404 // positive Y-axis points downwards. This interpretation is valid because
the orthographic | 403 // positive Y-axis points downwards. This interpretation is valid because
the orthographic |
405 // projection applied at draw time flips the Y axis appropriately. | 404 // projection applied at draw time flips the Y axis appropriately. |
406 // | 405 // |
407 // 2. The anchor point, when given as a PointF object, is specified in "unit
layer space", | 406 // 2. The anchor point, when given as a PointF object, is specified in "unit
layer space", |
408 // where the bounds of the layer map to [0, 1]. However, as a WebTransfor
mationMatrix object, | 407 // where the bounds of the layer map to [0, 1]. However, as a Transform o
bject, |
409 // the transform to the anchor point is specified in "layer space", where
the bounds | 408 // the transform to the anchor point is specified in "layer space", where
the bounds |
410 // of the layer map to [bounds.width(), bounds.height()]. | 409 // of the layer map to [bounds.width(), bounds.height()]. |
411 // | 410 // |
412 // 3. Definition of various transforms used: | 411 // 3. Definition of various transforms used: |
413 // M[parent] is the parent matrix, with respect to the nearest render
surface, passed down recursively. | 412 // M[parent] is the parent matrix, with respect to the nearest render
surface, passed down recursively. |
414 // M[root] is the full hierarchy, with respect to the root, passed do
wn recursively. | 413 // M[root] is the full hierarchy, with respect to the root, passed do
wn recursively. |
415 // Tr[origin] is the translation matrix from the parent's origin to t
his layer's origin. | 414 // Tr[origin] is the translation matrix from the parent's origin to t
his layer's origin. |
416 // Tr[origin2anchor] is the translation from the layer's origin to it
s anchor point | 415 // Tr[origin2anchor] is the translation from the layer's origin to it
s anchor point |
417 // Tr[origin2center] is the translation from the layer's origin to it
s center | 416 // Tr[origin2center] is the translation from the layer's origin to it
s center |
418 // M[layer] is the layer's matrix (applied at the anchor point) | 417 // M[layer] is the layer's matrix (applied at the anchor point) |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
451 // = M[parent] * Tr[layer->position() + anchor] *
M[layer] * Tr[anchor2origin] * compositeSublayerTransform | 450 // = M[parent] * Tr[layer->position() + anchor] *
M[layer] * Tr[anchor2origin] * compositeSublayerTransform |
452 // | 451 // |
453 // and a similar matrix for the full hierarchy with respect to the ro
ot. | 452 // and a similar matrix for the full hierarchy with respect to the ro
ot. |
454 // | 453 // |
455 // Finally, note that the final matrix used by the shader for the layer is P
* M[draw] * S . This final product | 454 // Finally, note that the final matrix used by the shader for the layer is P
* M[draw] * S . This final product |
456 // is computed in drawTexturedQuad(), where: | 455 // is computed in drawTexturedQuad(), where: |
457 // P is the projection matrix | 456 // P is the projection matrix |
458 // S is the scale adjustment (to scale up a canonical quad to the lay
er's size) | 457 // S is the scale adjustment (to scale up a canonical quad to the lay
er's size) |
459 // | 458 // |
460 // When a render surface has a replica layer, that layer's transform is used
to draw a second copy of the surface. | 459 // When a render surface has a replica layer, that layer's transform is used
to draw a second copy of the surface. |
461 // Transforms named here are relative to the surface, unless they specify th
ey are relative to the replica layer. | 460 // gfx::Transforms named here are relative to the surface, unless they speci
fy they are relative to the replica layer. |
462 // | 461 // |
463 // We will denote a scale by device scale S[deviceScale] | 462 // We will denote a scale by device scale S[deviceScale] |
464 // | 463 // |
465 // The render surface draw transform to its target surface origin is: | 464 // The render surface draw transform to its target surface origin is: |
466 // M[surfaceDraw] = M[owningLayer->Draw] | 465 // M[surfaceDraw] = M[owningLayer->Draw] |
467 // | 466 // |
468 // The render surface origin transform to its the root (screen space) origin
is: | 467 // The render surface origin transform to its the root (screen space) origin
is: |
469 // M[surface2root] = M[owningLayer->screenspace] * S[deviceScale].in
verse() | 468 // M[surface2root] = M[owningLayer->screenspace] * S[deviceScale].in
verse() |
470 // | 469 // |
471 // The replica draw transform to its target surface origin is: | 470 // The replica draw transform to its target surface origin is: |
(...skipping 24 matching lines...) Expand all Loading... |
496 bool animatingTransformToScreen = animatingTransformToTarget; | 495 bool animatingTransformToScreen = animatingTransformToTarget; |
497 if (layer->parent()) { | 496 if (layer->parent()) { |
498 animatingTransformToTarget |= layer->parent()->drawTransformIsAnimating(
); | 497 animatingTransformToTarget |= layer->parent()->drawTransformIsAnimating(
); |
499 animatingTransformToScreen |= layer->parent()->screenSpaceTransformIsAni
mating(); | 498 animatingTransformToScreen |= layer->parent()->screenSpaceTransformIsAni
mating(); |
500 } | 499 } |
501 | 500 |
502 gfx::Size bounds = layer->bounds(); | 501 gfx::Size bounds = layer->bounds(); |
503 gfx::PointF anchorPoint = layer->anchorPoint(); | 502 gfx::PointF anchorPoint = layer->anchorPoint(); |
504 gfx::PointF position = layer->position() - layer->scrollDelta(); | 503 gfx::PointF position = layer->position() - layer->scrollDelta(); |
505 | 504 |
506 WebTransformationMatrix layerLocalTransform; | 505 gfx::Transform layerLocalTransform; |
507 // LT = Tr[origin] * Tr[origin2anchor] | 506 // LT = Tr[origin] * Tr[origin2anchor] |
508 layerLocalTransform.translate3d(position.x() + anchorPoint.x() * bounds.widt
h(), position.y() + anchorPoint.y() * bounds.height(), layer->anchorPointZ()); | 507 layerLocalTransform.Translate3d(position.x() + anchorPoint.x() * bounds.widt
h(), position.y() + anchorPoint.y() * bounds.height(), layer->anchorPointZ()); |
509 // LT = Tr[origin] * Tr[origin2anchor] * M[layer] | 508 // LT = Tr[origin] * Tr[origin2anchor] * M[layer] |
510 layerLocalTransform.multiply(layer->transform()); | 509 layerLocalTransform.PreconcatTransform(layer->transform()); |
511 // LT = Tr[origin] * Tr[origin2anchor] * M[layer] * Tr[anchor2origin] | 510 // LT = Tr[origin] * Tr[origin2anchor] * M[layer] * Tr[anchor2origin] |
512 layerLocalTransform.translate3d(-anchorPoint.x() * bounds.width(), -anchorPo
int.y() * bounds.height(), -layer->anchorPointZ()); | 511 layerLocalTransform.Translate3d(-anchorPoint.x() * bounds.width(), -anchorPo
int.y() * bounds.height(), -layer->anchorPointZ()); |
513 | 512 |
514 WebTransformationMatrix combinedTransform = parentMatrix; | 513 gfx::Transform combinedTransform = parentMatrix; |
515 combinedTransform.multiply(layerLocalTransform); | 514 combinedTransform.PreconcatTransform(layerLocalTransform); |
516 | 515 |
517 // The layer's contentsSize is determined from the combinedTransform, which
then informs the | 516 // The layer's contentsSize is determined from the combinedTransform, which
then informs the |
518 // layer's drawTransform. | 517 // layer's drawTransform. |
519 updateLayerContentsScale(layer, combinedTransform, deviceScaleFactor, pageSc
aleFactor, animatingTransformToScreen); | 518 updateLayerContentsScale(layer, combinedTransform, deviceScaleFactor, pageSc
aleFactor, animatingTransformToScreen); |
520 | 519 |
521 // If there is a tranformation from the impl thread then it should be at the | 520 // If there is a tranformation from the impl thread then it should be at the |
522 // start of the combinedTransform, but we don't want it to affect the conten
tsScale. | 521 // start of the combinedTransform, but we don't want it to affect the conten
tsScale. |
523 combinedTransform = layer->implTransform() * combinedTransform; | 522 combinedTransform = layer->implTransform() * combinedTransform; |
524 | 523 |
525 if (layer->fixedToContainerLayer()) { | 524 if (layer->fixedToContainerLayer()) { |
526 // Special case: this layer is a composited fixed-position layer; we nee
d to | 525 // Special case: this layer is a composited fixed-position layer; we nee
d to |
527 // explicitly compensate for all ancestors' nonzero scrollDeltas to keep
this layer | 526 // explicitly compensate for all ancestors' nonzero scrollDeltas to keep
this layer |
528 // fixed correctly. | 527 // fixed correctly. |
529 combinedTransform = currentScrollCompensationMatrix * combinedTransform; | 528 combinedTransform = currentScrollCompensationMatrix * combinedTransform; |
530 } | 529 } |
531 | 530 |
532 // The drawTransform that gets computed below is effectively the layer's dra
wTransform, unless | 531 // The drawTransform that gets computed below is effectively the layer's dra
wTransform, unless |
533 // the layer itself creates a renderSurface. In that case, the renderSurface
re-parents the transforms. | 532 // the layer itself creates a renderSurface. In that case, the renderSurface
re-parents the transforms. |
534 WebTransformationMatrix drawTransform = combinedTransform; | 533 gfx::Transform drawTransform = combinedTransform; |
535 // M[draw] = M[parent] * LT * S[layer2content] | 534 // M[draw] = M[parent] * LT * S[layer2content] |
536 drawTransform.scaleNonUniform(1.0 / layer->contentsScaleX(), 1.0 / layer->co
ntentsScaleY()); | 535 drawTransform.Scale(1.0 / layer->contentsScaleX(), 1.0 / layer->contentsScal
eY()); |
537 | 536 |
538 // layerScreenSpaceTransform represents the transform between root layer's "
screen space" and local content space. | 537 // layerScreenSpaceTransform represents the transform between root layer's "
screen space" and local content space. |
539 WebTransformationMatrix layerScreenSpaceTransform = fullHierarchyMatrix; | 538 gfx::Transform layerScreenSpaceTransform = fullHierarchyMatrix; |
540 if (!layer->preserves3D()) | 539 if (!layer->preserves3D()) |
541 MathUtil::flattenTransformTo2d(layerScreenSpaceTransform); | 540 MathUtil::flattenTransformTo2d(layerScreenSpaceTransform); |
542 layerScreenSpaceTransform.multiply(drawTransform); | 541 layerScreenSpaceTransform.PreconcatTransform(drawTransform); |
543 layer->setScreenSpaceTransform(layerScreenSpaceTransform); | 542 layer->setScreenSpaceTransform(layerScreenSpaceTransform); |
544 | 543 |
545 gfx::RectF contentRect(gfx::PointF(), layer->contentBounds()); | 544 gfx::RectF contentRect(gfx::PointF(), layer->contentBounds()); |
546 | 545 |
547 // fullHierarchyMatrix is the matrix that transforms objects between screen
space (except projection matrix) and the most recent RenderSurfaceImpl's space. | 546 // fullHierarchyMatrix is the matrix that transforms objects between screen
space (except projection matrix) and the most recent RenderSurfaceImpl's space. |
548 // nextHierarchyMatrix will only change if this layer uses a new RenderSurfa
ceImpl, otherwise remains the same. | 547 // nextHierarchyMatrix will only change if this layer uses a new RenderSurfa
ceImpl, otherwise remains the same. |
549 WebTransformationMatrix nextHierarchyMatrix = fullHierarchyMatrix; | 548 gfx::Transform nextHierarchyMatrix = fullHierarchyMatrix; |
550 WebTransformationMatrix sublayerMatrix; | 549 gfx::Transform sublayerMatrix; |
551 | 550 |
552 gfx::Vector2dF renderSurfaceSublayerScale = MathUtil::computeTransform2dScal
eComponents(combinedTransform); | 551 gfx::Vector2dF renderSurfaceSublayerScale = MathUtil::computeTransform2dScal
eComponents(combinedTransform); |
553 | 552 |
554 if (subtreeShouldRenderToSeparateSurface(layer, isScaleOrTranslation(combine
dTransform))) { | 553 if (subtreeShouldRenderToSeparateSurface(layer, isScaleOrTranslation(combine
dTransform))) { |
555 // Check back-face visibility before continuing with this surface and it
s subtree | 554 // Check back-face visibility before continuing with this surface and it
s subtree |
556 if (!layer->doubleSided() && transformToParentIsKnown(layer) && isSurfac
eBackFaceVisible(layer, combinedTransform)) | 555 if (!layer->doubleSided() && transformToParentIsKnown(layer) && isSurfac
eBackFaceVisible(layer, combinedTransform)) |
557 return; | 556 return; |
558 | 557 |
559 if (!layer->renderSurface()) | 558 if (!layer->renderSurface()) |
560 layer->createRenderSurface(); | 559 layer->createRenderSurface(); |
561 | 560 |
562 RenderSurfaceType* renderSurface = layer->renderSurface(); | 561 RenderSurfaceType* renderSurface = layer->renderSurface(); |
563 renderSurface->clearLayerLists(); | 562 renderSurface->clearLayerLists(); |
564 | 563 |
565 // The owning layer's draw transform has a scale from content to layer s
pace which we need to undo and | 564 // The owning layer's draw transform has a scale from content to layer s
pace which we need to undo and |
566 // replace with a scale from the surface's subtree into layer space. | 565 // replace with a scale from the surface's subtree into layer space. |
567 drawTransform.scaleNonUniform(layer->contentsScaleX(), layer->contentsSc
aleY()); | 566 drawTransform.Scale(layer->contentsScaleX(), layer->contentsScaleY()); |
568 drawTransform.scaleNonUniform(1 / renderSurfaceSublayerScale.x(), 1 / re
nderSurfaceSublayerScale.y()); | 567 drawTransform.Scale(1 / renderSurfaceSublayerScale.x(), 1 / renderSurfac
eSublayerScale.y()); |
569 renderSurface->setDrawTransform(drawTransform); | 568 renderSurface->setDrawTransform(drawTransform); |
570 | 569 |
571 // The origin of the new surface is the upper left corner of the layer. | 570 // The origin of the new surface is the upper left corner of the layer. |
572 WebTransformationMatrix layerDrawTransform; | 571 gfx::Transform layerDrawTransform; |
573 layerDrawTransform.scaleNonUniform(renderSurfaceSublayerScale.x(), rende
rSurfaceSublayerScale.y()); | 572 layerDrawTransform.Scale(renderSurfaceSublayerScale.x(), renderSurfaceSu
blayerScale.y()); |
574 layerDrawTransform.scaleNonUniform(1.0 / layer->contentsScaleX(), 1.0 /
layer->contentsScaleY()); | 573 layerDrawTransform.Scale(1.0 / layer->contentsScaleX(), 1.0 / layer->con
tentsScaleY()); |
575 layer->setDrawTransform(layerDrawTransform); | 574 layer->setDrawTransform(layerDrawTransform); |
576 | 575 |
577 // Inside the surface's subtree, we scale everything to the owning layer
's scale. | 576 // Inside the surface's subtree, we scale everything to the owning layer
's scale. |
578 // The sublayer matrix transforms centered layer rects into target | 577 // The sublayer matrix transforms centered layer rects into target |
579 // surface content space. | 578 // surface content space. |
580 sublayerMatrix.makeIdentity(); | 579 sublayerMatrix.MakeIdentity(); |
581 sublayerMatrix.scaleNonUniform(renderSurfaceSublayerScale.x(), renderSur
faceSublayerScale.y()); | 580 sublayerMatrix.Scale(renderSurfaceSublayerScale.x(), renderSurfaceSublay
erScale.y()); |
582 | 581 |
583 // The opacity value is moved from the layer to its surface, so that the
entire subtree properly inherits opacity. | 582 // The opacity value is moved from the layer to its surface, so that the
entire subtree properly inherits opacity. |
584 renderSurface->setDrawOpacity(drawOpacity); | 583 renderSurface->setDrawOpacity(drawOpacity); |
585 renderSurface->setDrawOpacityIsAnimating(drawOpacityIsAnimating); | 584 renderSurface->setDrawOpacityIsAnimating(drawOpacityIsAnimating); |
586 layer->setDrawOpacity(1); | 585 layer->setDrawOpacity(1); |
587 layer->setDrawOpacityIsAnimating(false); | 586 layer->setDrawOpacityIsAnimating(false); |
588 | 587 |
589 renderSurface->setTargetSurfaceTransformsAreAnimating(animatingTransform
ToTarget); | 588 renderSurface->setTargetSurfaceTransformsAreAnimating(animatingTransform
ToTarget); |
590 renderSurface->setScreenSpaceTransformsAreAnimating(animatingTransformTo
Screen); | 589 renderSurface->setScreenSpaceTransformsAreAnimating(animatingTransformTo
Screen); |
591 animatingTransformToTarget = false; | 590 animatingTransformToTarget = false; |
592 layer->setDrawTransformIsAnimating(animatingTransformToTarget); | 591 layer->setDrawTransformIsAnimating(animatingTransformToTarget); |
593 layer->setScreenSpaceTransformIsAnimating(animatingTransformToScreen); | 592 layer->setScreenSpaceTransformIsAnimating(animatingTransformToScreen); |
594 | 593 |
595 // Update the aggregate hierarchy matrix to include the transform of the | 594 // Update the aggregate hierarchy matrix to include the transform of the |
596 // newly created RenderSurfaceImpl. | 595 // newly created RenderSurfaceImpl. |
597 nextHierarchyMatrix.multiply(renderSurface->drawTransform()); | 596 nextHierarchyMatrix.PreconcatTransform(renderSurface->drawTransform()); |
598 | 597 |
599 // The new renderSurface here will correctly clip the entire subtree. So
, we do | 598 // The new renderSurface here will correctly clip the entire subtree. So
, we do |
600 // not need to continue propagating the clipping state further down the
tree. This | 599 // not need to continue propagating the clipping state further down the
tree. This |
601 // way, we can avoid transforming clipRects from ancestor target surface
space to | 600 // way, we can avoid transforming clipRects from ancestor target surface
space to |
602 // current target surface space that could cause more w < 0 headaches. | 601 // current target surface space that could cause more w < 0 headaches. |
603 subtreeShouldBeClipped = false; | 602 subtreeShouldBeClipped = false; |
604 | 603 |
605 if (layer->maskLayer()) { | 604 if (layer->maskLayer()) { |
606 layer->maskLayer()->setRenderTarget(layer); | 605 layer->maskLayer()->setRenderTarget(layer); |
607 layer->maskLayer()->setVisibleContentRect(gfx::Rect(gfx::Point(), la
yer->contentBounds())); | 606 layer->maskLayer()->setVisibleContentRect(gfx::Rect(gfx::Point(), la
yer->contentBounds())); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
658 clipRectForSubtree.Intersect(rectInTargetSpace); | 657 clipRectForSubtree.Intersect(rectInTargetSpace); |
659 } else | 658 } else |
660 clipRectForSubtree = rectInTargetSpace; | 659 clipRectForSubtree = rectInTargetSpace; |
661 } | 660 } |
662 | 661 |
663 // Flatten to 2D if the layer doesn't preserve 3D. | 662 // Flatten to 2D if the layer doesn't preserve 3D. |
664 if (!layer->preserves3D()) | 663 if (!layer->preserves3D()) |
665 MathUtil::flattenTransformTo2d(sublayerMatrix); | 664 MathUtil::flattenTransformTo2d(sublayerMatrix); |
666 | 665 |
667 // Apply the sublayer transform at the center of the layer. | 666 // Apply the sublayer transform at the center of the layer. |
668 sublayerMatrix.translate(0.5 * bounds.width(), 0.5 * bounds.height()); | 667 sublayerMatrix.Translate(0.5 * bounds.width(), 0.5 * bounds.height()); |
669 sublayerMatrix.multiply(layer->sublayerTransform()); | 668 sublayerMatrix.PreconcatTransform(layer->sublayerTransform()); |
670 sublayerMatrix.translate(-0.5 * bounds.width(), -0.5 * bounds.height()); | 669 sublayerMatrix.Translate(-0.5 * bounds.width(), -0.5 * bounds.height()); |
671 | 670 |
672 LayerList& descendants = (layer->renderSurface() ? layer->renderSurface()->l
ayerList() : layerList); | 671 LayerList& descendants = (layer->renderSurface() ? layer->renderSurface()->l
ayerList() : layerList); |
673 | 672 |
674 // Any layers that are appended after this point are in the layer's subtree
and should be included in the sorting process. | 673 // Any layers that are appended after this point are in the layer's subtree
and should be included in the sorting process. |
675 unsigned sortingStartIndex = descendants.size(); | 674 unsigned sortingStartIndex = descendants.size(); |
676 | 675 |
677 if (!layerShouldBeSkipped(layer)) | 676 if (!layerShouldBeSkipped(layer)) |
678 descendants.push_back(layer); | 677 descendants.push_back(layer); |
679 | 678 |
680 WebTransformationMatrix nextScrollCompensationMatrix = computeScrollCompensa
tionMatrixForChildren(layer, parentMatrix, currentScrollCompensationMatrix);; | 679 gfx::Transform nextScrollCompensationMatrix = computeScrollCompensationMatri
xForChildren(layer, parentMatrix, currentScrollCompensationMatrix);; |
681 | 680 |
682 gfx::Rect accumulatedDrawableContentRectOfChildren; | 681 gfx::Rect accumulatedDrawableContentRectOfChildren; |
683 for (size_t i = 0; i < layer->children().size(); ++i) { | 682 for (size_t i = 0; i < layer->children().size(); ++i) { |
684 LayerType* child = LayerTreeHostCommon::getChildAsRawPtr(layer->children
(), i); | 683 LayerType* child = LayerTreeHostCommon::getChildAsRawPtr(layer->children
(), i); |
685 gfx::Rect drawableContentRectOfChildSubtree; | 684 gfx::Rect drawableContentRectOfChildSubtree; |
686 calculateDrawTransformsInternal<LayerType, LayerList, RenderSurfaceType,
LayerSorter>(child, sublayerMatrix, nextHierarchyMatrix, nextScrollCompensation
Matrix, | 685 calculateDrawTransformsInternal<LayerType, LayerList, RenderSurfaceType,
LayerSorter>(child, sublayerMatrix, nextHierarchyMatrix, nextScrollCompensation
Matrix, |
687
clipRectForSubtree, subtreeShouldBeClipped, nearestAncestorThatMov
esPixels, | 686
clipRectForSubtree, subtreeShouldBeClipped, nearestAncestorThatMov
esPixels, |
688
renderSurfaceLayerList, descendants, layerSorter, maxTextureSize,
deviceScaleFactor, pageScaleFactor, drawableContentRectOfChildSubtree); | 687
renderSurfaceLayerList, descendants, layerSorter, maxTextureSize,
deviceScaleFactor, pageScaleFactor, drawableContentRectOfChildSubtree); |
689 if (!drawableContentRectOfChildSubtree.IsEmpty()) { | 688 if (!drawableContentRectOfChildSubtree.IsEmpty()) { |
690 accumulatedDrawableContentRectOfChildren.Union(drawableContentRectOf
ChildSubtree); | 689 accumulatedDrawableContentRectOfChildren.Union(drawableContentRectOf
ChildSubtree); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
749 clippedContentRect.set_width(std::min(clippedContentRect.width(), maxTex
tureSize)); | 748 clippedContentRect.set_width(std::min(clippedContentRect.width(), maxTex
tureSize)); |
750 clippedContentRect.set_height(std::min(clippedContentRect.height(), maxT
extureSize)); | 749 clippedContentRect.set_height(std::min(clippedContentRect.height(), maxT
extureSize)); |
751 | 750 |
752 if (clippedContentRect.IsEmpty()) | 751 if (clippedContentRect.IsEmpty()) |
753 renderSurface->clearLayerLists(); | 752 renderSurface->clearLayerLists(); |
754 | 753 |
755 renderSurface->setContentRect(clippedContentRect); | 754 renderSurface->setContentRect(clippedContentRect); |
756 | 755 |
757 // The owning layer's screenSpaceTransform has a scale from content to l
ayer space which we need to undo and | 756 // The owning layer's screenSpaceTransform has a scale from content to l
ayer space which we need to undo and |
758 // replace with a scale from the surface's subtree into layer space. | 757 // replace with a scale from the surface's subtree into layer space. |
759 WebTransformationMatrix screenSpaceTransform = layer->screenSpaceTransfo
rm(); | 758 gfx::Transform screenSpaceTransform = layer->screenSpaceTransform(); |
760 screenSpaceTransform.scaleNonUniform(layer->contentsScaleX(), layer->con
tentsScaleY()); | 759 screenSpaceTransform.Scale(layer->contentsScaleX(), layer->contentsScale
Y()); |
761 screenSpaceTransform.scaleNonUniform(1 / renderSurfaceSublayerScale.x(),
1 / renderSurfaceSublayerScale.y()); | 760 screenSpaceTransform.Scale(1 / renderSurfaceSublayerScale.x(), 1 / rende
rSurfaceSublayerScale.y()); |
762 renderSurface->setScreenSpaceTransform(screenSpaceTransform); | 761 renderSurface->setScreenSpaceTransform(screenSpaceTransform); |
763 | 762 |
764 if (layer->replicaLayer()) { | 763 if (layer->replicaLayer()) { |
765 WebTransformationMatrix surfaceOriginToReplicaOriginTransform; | 764 gfx::Transform surfaceOriginToReplicaOriginTransform; |
766 surfaceOriginToReplicaOriginTransform.scaleNonUniform(renderSurfaceS
ublayerScale.x(), renderSurfaceSublayerScale.y()); | 765 surfaceOriginToReplicaOriginTransform.Scale(renderSurfaceSublayerSca
le.x(), renderSurfaceSublayerScale.y()); |
767 surfaceOriginToReplicaOriginTransform.translate(layer->replicaLayer(
)->position().x() + layer->replicaLayer()->anchorPoint().x() * bounds.width(), | 766 surfaceOriginToReplicaOriginTransform.Translate(layer->replicaLayer(
)->position().x() + layer->replicaLayer()->anchorPoint().x() * bounds.width(), |
768 layer->replicaLayer(
)->position().y() + layer->replicaLayer()->anchorPoint().y() * bounds.height()); | 767 layer->replicaLayer(
)->position().y() + layer->replicaLayer()->anchorPoint().y() * bounds.height()); |
769 surfaceOriginToReplicaOriginTransform.multiply(layer->replicaLayer()
->transform()); | 768 surfaceOriginToReplicaOriginTransform.PreconcatTransform(layer->repl
icaLayer()->transform()); |
770 surfaceOriginToReplicaOriginTransform.translate(-layer->replicaLayer
()->anchorPoint().x() * bounds.width(), -layer->replicaLayer()->anchorPoint().y(
) * bounds.height()); | 769 surfaceOriginToReplicaOriginTransform.Translate(-layer->replicaLayer
()->anchorPoint().x() * bounds.width(), -layer->replicaLayer()->anchorPoint().y(
) * bounds.height()); |
771 surfaceOriginToReplicaOriginTransform.scaleNonUniform(1 / renderSurf
aceSublayerScale.x(), 1 / renderSurfaceSublayerScale.y()); | 770 surfaceOriginToReplicaOriginTransform.Scale(1 / renderSurfaceSublaye
rScale.x(), 1 / renderSurfaceSublayerScale.y()); |
772 | 771 |
773 // Compute the replica's "originTransform" that maps from the replic
a's origin space to the target surface origin space. | 772 // Compute the replica's "originTransform" that maps from the replic
a's origin space to the target surface origin space. |
774 WebTransformationMatrix replicaOriginTransform = layer->renderSurfac
e()->drawTransform() * surfaceOriginToReplicaOriginTransform; | 773 gfx::Transform replicaOriginTransform = layer->renderSurface()->draw
Transform() * surfaceOriginToReplicaOriginTransform; |
775 renderSurface->setReplicaDrawTransform(replicaOriginTransform); | 774 renderSurface->setReplicaDrawTransform(replicaOriginTransform); |
776 | 775 |
777 // Compute the replica's "screenSpaceTransform" that maps from the r
eplica's origin space to the screen's origin space. | 776 // Compute the replica's "screenSpaceTransform" that maps from the r
eplica's origin space to the screen's origin space. |
778 WebTransformationMatrix replicaScreenSpaceTransform = layer->renderS
urface()->screenSpaceTransform() * surfaceOriginToReplicaOriginTransform; | 777 gfx::Transform replicaScreenSpaceTransform = layer->renderSurface()-
>screenSpaceTransform() * surfaceOriginToReplicaOriginTransform; |
779 renderSurface->setReplicaScreenSpaceTransform(replicaScreenSpaceTran
sform); | 778 renderSurface->setReplicaScreenSpaceTransform(replicaScreenSpaceTran
sform); |
780 } | 779 } |
781 | 780 |
782 // If a render surface has no layer list, then it and none of its childr
en needed to get drawn. | 781 // If a render surface has no layer list, then it and none of its childr
en needed to get drawn. |
783 if (!layer->renderSurface()->layerList().size()) { | 782 if (!layer->renderSurface()->layerList().size()) { |
784 // FIXME: Originally we asserted that this layer was already at the
end of the | 783 // FIXME: Originally we asserted that this layer was already at the
end of the |
785 // list, and only needed to remove that layer. For now, we re
move the | 784 // list, and only needed to remove that layer. For now, we re
move the |
786 // entire subtree of surfaces to fix a crash bug. The root ca
use is | 785 // entire subtree of surfaces to fix a crash bug. The root ca
use is |
787 // https://bugs.webkit.org/show_bug.cgi?id=74147 and we shoul
d be able | 786 // https://bugs.webkit.org/show_bug.cgi?id=74147 and we shoul
d be able |
788 // to put the original assert after fixing that. | 787 // to put the original assert after fixing that. |
(...skipping 23 matching lines...) Expand all Loading... |
812 else | 811 else |
813 drawableContentRectOfSubtree = localDrawableContentRectOfSubtree; | 812 drawableContentRectOfSubtree = localDrawableContentRectOfSubtree; |
814 | 813 |
815 if (layer->hasContributingDelegatedRenderPasses()) | 814 if (layer->hasContributingDelegatedRenderPasses()) |
816 layer->renderTarget()->renderSurface()->addContributingDelegatedRenderPa
ssLayer(layer); | 815 layer->renderTarget()->renderSurface()->addContributingDelegatedRenderPa
ssLayer(layer); |
817 } | 816 } |
818 | 817 |
819 void LayerTreeHostCommon::calculateDrawTransforms(Layer* rootLayer, const gfx::S
ize& deviceViewportSize, float deviceScaleFactor, float pageScaleFactor, int max
TextureSize, std::vector<scoped_refptr<Layer> >& renderSurfaceLayerList) | 818 void LayerTreeHostCommon::calculateDrawTransforms(Layer* rootLayer, const gfx::S
ize& deviceViewportSize, float deviceScaleFactor, float pageScaleFactor, int max
TextureSize, std::vector<scoped_refptr<Layer> >& renderSurfaceLayerList) |
820 { | 819 { |
821 gfx::Rect totalDrawableContentRect; | 820 gfx::Rect totalDrawableContentRect; |
822 WebTransformationMatrix identityMatrix; | 821 gfx::Transform identityMatrix; |
823 WebTransformationMatrix deviceScaleTransform; | 822 gfx::Transform deviceScaleTransform; |
824 deviceScaleTransform.scale(deviceScaleFactor); | 823 deviceScaleTransform.Scale(deviceScaleFactor, deviceScaleFactor); |
825 std::vector<scoped_refptr<Layer> > dummyLayerList; | 824 std::vector<scoped_refptr<Layer> > dummyLayerList; |
826 | 825 |
827 // The root layer's renderSurface should receive the deviceViewport as the i
nitial clipRect. | 826 // The root layer's renderSurface should receive the deviceViewport as the i
nitial clipRect. |
828 bool subtreeShouldBeClipped = true; | 827 bool subtreeShouldBeClipped = true; |
829 gfx::Rect deviceViewportRect(gfx::Point(), deviceViewportSize); | 828 gfx::Rect deviceViewportRect(gfx::Point(), deviceViewportSize); |
830 | 829 |
831 // This function should have received a root layer. | 830 // This function should have received a root layer. |
832 DCHECK(isRootLayer(rootLayer)); | 831 DCHECK(isRootLayer(rootLayer)); |
833 | 832 |
834 cc::calculateDrawTransformsInternal<Layer, std::vector<scoped_refptr<Layer>
>, RenderSurface, void>( | 833 cc::calculateDrawTransformsInternal<Layer, std::vector<scoped_refptr<Layer>
>, RenderSurface, void>( |
835 rootLayer, deviceScaleTransform, identityMatrix, identityMatrix, | 834 rootLayer, deviceScaleTransform, identityMatrix, identityMatrix, |
836 deviceViewportRect, subtreeShouldBeClipped, 0, renderSurfaceLayerList, | 835 deviceViewportRect, subtreeShouldBeClipped, 0, renderSurfaceLayerList, |
837 dummyLayerList, 0, maxTextureSize, | 836 dummyLayerList, 0, maxTextureSize, |
838 deviceScaleFactor, pageScaleFactor, totalDrawableContentRect); | 837 deviceScaleFactor, pageScaleFactor, totalDrawableContentRect); |
839 | 838 |
840 // The dummy layer list should not have been used. | 839 // The dummy layer list should not have been used. |
841 DCHECK(dummyLayerList.size() == 0); | 840 DCHECK(dummyLayerList.size() == 0); |
842 // A root layer renderSurface should always exist after calculateDrawTransfo
rms. | 841 // A root layer renderSurface should always exist after calculateDrawTransfo
rms. |
843 DCHECK(rootLayer->renderSurface()); | 842 DCHECK(rootLayer->renderSurface()); |
844 } | 843 } |
845 | 844 |
846 void LayerTreeHostCommon::calculateDrawTransforms(LayerImpl* rootLayer, const gf
x::Size& deviceViewportSize, float deviceScaleFactor, float pageScaleFactor, Lay
erSorter* layerSorter, int maxTextureSize, std::vector<LayerImpl*>& renderSurfac
eLayerList) | 845 void LayerTreeHostCommon::calculateDrawTransforms(LayerImpl* rootLayer, const gf
x::Size& deviceViewportSize, float deviceScaleFactor, float pageScaleFactor, Lay
erSorter* layerSorter, int maxTextureSize, std::vector<LayerImpl*>& renderSurfac
eLayerList) |
847 { | 846 { |
848 gfx::Rect totalDrawableContentRect; | 847 gfx::Rect totalDrawableContentRect; |
849 WebTransformationMatrix identityMatrix; | 848 gfx::Transform identityMatrix; |
850 WebTransformationMatrix deviceScaleTransform; | 849 gfx::Transform deviceScaleTransform; |
851 deviceScaleTransform.scale(deviceScaleFactor); | 850 deviceScaleTransform.Scale(deviceScaleFactor, deviceScaleFactor); |
852 std::vector<LayerImpl*> dummyLayerList; | 851 std::vector<LayerImpl*> dummyLayerList; |
853 | 852 |
854 // The root layer's renderSurface should receive the deviceViewport as the i
nitial clipRect. | 853 // The root layer's renderSurface should receive the deviceViewport as the i
nitial clipRect. |
855 bool subtreeShouldBeClipped = true; | 854 bool subtreeShouldBeClipped = true; |
856 gfx::Rect deviceViewportRect(gfx::Point(), deviceViewportSize); | 855 gfx::Rect deviceViewportRect(gfx::Point(), deviceViewportSize); |
857 | 856 |
858 // This function should have received a root layer. | 857 // This function should have received a root layer. |
859 DCHECK(isRootLayer(rootLayer)); | 858 DCHECK(isRootLayer(rootLayer)); |
860 | 859 |
861 cc::calculateDrawTransformsInternal<LayerImpl, std::vector<LayerImpl*>, Rend
erSurfaceImpl, LayerSorter>( | 860 cc::calculateDrawTransformsInternal<LayerImpl, std::vector<LayerImpl*>, Rend
erSurfaceImpl, LayerSorter>( |
862 rootLayer, deviceScaleTransform, identityMatrix, identityMatrix, | 861 rootLayer, deviceScaleTransform, identityMatrix, identityMatrix, |
863 deviceViewportRect, subtreeShouldBeClipped, 0, renderSurfaceLayerList, | 862 deviceViewportRect, subtreeShouldBeClipped, 0, renderSurfaceLayerList, |
864 dummyLayerList, layerSorter, maxTextureSize, | 863 dummyLayerList, layerSorter, maxTextureSize, |
865 deviceScaleFactor, pageScaleFactor, totalDrawableContentRect); | 864 deviceScaleFactor, pageScaleFactor, totalDrawableContentRect); |
866 | 865 |
867 // The dummy layer list should not have been used. | 866 // The dummy layer list should not have been used. |
868 DCHECK(dummyLayerList.size() == 0); | 867 DCHECK(dummyLayerList.size() == 0); |
869 // A root layer renderSurface should always exist after calculateDrawTransfo
rms. | 868 // A root layer renderSurface should always exist after calculateDrawTransfo
rms. |
870 DCHECK(rootLayer->renderSurface()); | 869 DCHECK(rootLayer->renderSurface()); |
871 } | 870 } |
872 | 871 |
873 static bool pointHitsRect(const gfx::PointF& screenSpacePoint, const WebTransfor
mationMatrix& localSpaceToScreenSpaceTransform, gfx::RectF localSpaceRect) | 872 static bool pointHitsRect(const gfx::PointF& screenSpacePoint, const gfx::Transf
orm& localSpaceToScreenSpaceTransform, gfx::RectF localSpaceRect) |
874 { | 873 { |
875 // If the transform is not invertible, then assume that this point doesn't h
it this rect. | 874 // If the transform is not invertible, then assume that this point doesn't h
it this rect. |
876 if (!localSpaceToScreenSpaceTransform.isInvertible()) | 875 if (!localSpaceToScreenSpaceTransform.IsInvertible()) |
877 return false; | 876 return false; |
878 | 877 |
879 // Transform the hit test point from screen space to the local space of the
given rect. | 878 // Transform the hit test point from screen space to the local space of the
given rect. |
880 bool clipped = false; | 879 bool clipped = false; |
881 gfx::PointF hitTestPointInLocalSpace = MathUtil::projectPoint(localSpaceToSc
reenSpaceTransform.inverse(), screenSpacePoint, clipped); | 880 gfx::PointF hitTestPointInLocalSpace = MathUtil::projectPoint(MathUtil::inve
rse(localSpaceToScreenSpaceTransform), screenSpacePoint, clipped); |
882 | 881 |
883 // If projectPoint could not project to a valid value, then we assume that t
his point doesn't hit this rect. | 882 // If projectPoint could not project to a valid value, then we assume that t
his point doesn't hit this rect. |
884 if (clipped) | 883 if (clipped) |
885 return false; | 884 return false; |
886 | 885 |
887 return localSpaceRect.Contains(hitTestPointInLocalSpace); | 886 return localSpaceRect.Contains(hitTestPointInLocalSpace); |
888 } | 887 } |
889 | 888 |
890 static bool pointHitsRegion(gfx::PointF screenSpacePoint, const WebTransformatio
nMatrix& screenSpaceTransform, const Region& layerSpaceRegion, float layerConten
tScaleX, float layerContentScaleY) | 889 static bool pointHitsRegion(gfx::PointF screenSpacePoint, const gfx::Transform&
screenSpaceTransform, const Region& layerSpaceRegion, float layerContentScaleX,
float layerContentScaleY) |
891 { | 890 { |
892 // If the transform is not invertible, then assume that this point doesn't h
it this region. | 891 // If the transform is not invertible, then assume that this point doesn't h
it this region. |
893 if (!screenSpaceTransform.isInvertible()) | 892 if (!screenSpaceTransform.IsInvertible()) |
894 return false; | 893 return false; |
895 | 894 |
896 // Transform the hit test point from screen space to the local space of the
given region. | 895 // Transform the hit test point from screen space to the local space of the
given region. |
897 bool clipped = false; | 896 bool clipped = false; |
898 gfx::PointF hitTestPointInContentSpace = MathUtil::projectPoint(screenSpaceT
ransform.inverse(), screenSpacePoint, clipped); | 897 gfx::PointF hitTestPointInContentSpace = MathUtil::projectPoint(MathUtil::in
verse(screenSpaceTransform), screenSpacePoint, clipped); |
899 gfx::PointF hitTestPointInLayerSpace = gfx::ScalePoint(hitTestPointInContent
Space, 1 / layerContentScaleX, 1 / layerContentScaleY); | 898 gfx::PointF hitTestPointInLayerSpace = gfx::ScalePoint(hitTestPointInContent
Space, 1 / layerContentScaleX, 1 / layerContentScaleY); |
900 | 899 |
901 // If projectPoint could not project to a valid value, then we assume that t
his point doesn't hit this region. | 900 // If projectPoint could not project to a valid value, then we assume that t
his point doesn't hit this region. |
902 if (clipped) | 901 if (clipped) |
903 return false; | 902 return false; |
904 | 903 |
905 return layerSpaceRegion.Contains(gfx::ToRoundedPoint(hitTestPointInLayerSpac
e)); | 904 return layerSpaceRegion.Contains(gfx::ToRoundedPoint(hitTestPointInLayerSpac
e)); |
906 } | 905 } |
907 | 906 |
908 static bool pointIsClippedBySurfaceOrClipRect(const gfx::PointF& screenSpacePoin
t, LayerImpl* layer) | 907 static bool pointIsClippedBySurfaceOrClipRect(const gfx::PointF& screenSpacePoin
t, LayerImpl* layer) |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
987 | 986 |
988 foundLayer = currentLayer; | 987 foundLayer = currentLayer; |
989 break; | 988 break; |
990 } | 989 } |
991 | 990 |
992 // This can potentially return 0, which means the screenSpacePoint did not s
uccessfully hit test any layers, not even the root layer. | 991 // This can potentially return 0, which means the screenSpacePoint did not s
uccessfully hit test any layers, not even the root layer. |
993 return foundLayer; | 992 return foundLayer; |
994 } | 993 } |
995 | 994 |
996 } // namespace cc | 995 } // namespace cc |
OLD | NEW |