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 "config.h" | 5 #include "config.h" |
6 | 6 |
7 #include "cc/layer_tree_host_common.h" | 7 #include "cc/layer_tree_host_common.h" |
8 | 8 |
9 #include "cc/layer.h" | 9 #include "cc/layer.h" |
10 #include "cc/layer_impl.h" | 10 #include "cc/layer_impl.h" |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
282 // | 282 // |
283 // These steps create a matrix that both start and end in targetSurfaceSpace
. So this matrix can | 283 // These steps create a matrix that both start and end in targetSurfaceSpace
. So this matrix can |
284 // pre-multiply any fixed-position layer's drawTransform to undo the scrollD
eltas -- as long as | 284 // pre-multiply any fixed-position layer's drawTransform to undo the scrollD
eltas -- as long as |
285 // that fixed position layer is fixed onto the same renderTarget as this scr
ollingLayer. | 285 // that fixed position layer is fixed onto the same renderTarget as this scr
ollingLayer. |
286 // | 286 // |
287 | 287 |
288 WebTransformationMatrix partialLayerOriginTransform = parentMatrix; | 288 WebTransformationMatrix partialLayerOriginTransform = parentMatrix; |
289 partialLayerOriginTransform.multiply(scrollingLayer->implTransform()); | 289 partialLayerOriginTransform.multiply(scrollingLayer->implTransform()); |
290 | 290 |
291 WebTransformationMatrix scrollCompensationForThisLayer = partialLayerOriginT
ransform; // Step 3 | 291 WebTransformationMatrix scrollCompensationForThisLayer = partialLayerOriginT
ransform; // Step 3 |
292 scrollCompensationForThisLayer.translate(scrollingLayer->scrollDelta().width
(), scrollingLayer->scrollDelta().height()); // Step 2 | 292 scrollCompensationForThisLayer.translate(scrollingLayer->scrollDelta().x(),
scrollingLayer->scrollDelta().y()); // Step 2 |
293 scrollCompensationForThisLayer.multiply(partialLayerOriginTransform.inverse(
)); // Step 1 | 293 scrollCompensationForThisLayer.multiply(partialLayerOriginTransform.inverse(
)); // Step 1 |
294 return scrollCompensationForThisLayer; | 294 return scrollCompensationForThisLayer; |
295 } | 295 } |
296 | 296 |
297 WebTransformationMatrix computeScrollCompensationMatrixForChildren(Layer* curren
tLayer, const WebTransformationMatrix& currentParentMatrix, const WebTransformat
ionMatrix& currentScrollCompensation) | 297 WebTransformationMatrix computeScrollCompensationMatrixForChildren(Layer* curren
tLayer, const WebTransformationMatrix& currentParentMatrix, const WebTransformat
ionMatrix& currentScrollCompensation) |
298 { | 298 { |
299 // The main thread (i.e. Layer) does not need to worry about scroll compensa
tion. | 299 // The main thread (i.e. Layer) does not need to worry about scroll compensa
tion. |
300 // So we can just return an identity matrix here. | 300 // So we can just return an identity matrix here. |
301 return WebTransformationMatrix(); | 301 return WebTransformationMatrix(); |
302 } | 302 } |
(...skipping 10 matching lines...) Expand all Loading... |
313 // without a renderSurface, the renderSurface is irrelevant in that case. | 313 // without a renderSurface, the renderSurface is irrelevant in that case. |
314 // - A layer that does not have an explicit container is simply fixed to th
e viewport. | 314 // - A layer that does not have an explicit container is simply fixed to th
e viewport. |
315 // (i.e. the root renderSurface.) | 315 // (i.e. the root renderSurface.) |
316 // - If the fixed-position layer has its own renderSurface, then the render
Surface is | 316 // - If the fixed-position layer has its own renderSurface, then the render
Surface is |
317 // the one who gets fixed. | 317 // the one who gets fixed. |
318 // | 318 // |
319 // This function needs to be called AFTER layers create their own renderSurf
aces. | 319 // This function needs to be called AFTER layers create their own renderSurf
aces. |
320 // | 320 // |
321 | 321 |
322 // 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 // 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. |
323 if (!layer->isContainerForFixedPositionLayers() && layer->scrollDelta().isZe
ro() && !layer->renderSurface()) | 323 if (!layer->isContainerForFixedPositionLayers() && layer->scrollDelta().IsZe
ro() && !layer->renderSurface()) |
324 return currentScrollCompensationMatrix; | 324 return currentScrollCompensationMatrix; |
325 | 325 |
326 // Start as identity matrix. | 326 // Start as identity matrix. |
327 WebTransformationMatrix nextScrollCompensationMatrix; | 327 WebTransformationMatrix nextScrollCompensationMatrix; |
328 | 328 |
329 // If this layer is not a container, then it inherits the existing scroll co
mpensations. | 329 // If this layer is not a container, then it inherits the existing scroll co
mpensations. |
330 if (!layer->isContainerForFixedPositionLayers()) | 330 if (!layer->isContainerForFixedPositionLayers()) |
331 nextScrollCompensationMatrix = currentScrollCompensationMatrix; | 331 nextScrollCompensationMatrix = currentScrollCompensationMatrix; |
332 | 332 |
333 // If the current layer has a non-zero scrollDelta, then we should compute i
ts local scrollCompensation | 333 // If the current layer has a non-zero scrollDelta, then we should compute i
ts local scrollCompensation |
334 // and accumulate it to the nextScrollCompensationMatrix. | 334 // and accumulate it to the nextScrollCompensationMatrix. |
335 if (!layer->scrollDelta().isZero()) { | 335 if (!layer->scrollDelta().IsZero()) { |
336 WebTransformationMatrix scrollCompensationForThisLayer = computeScrollCo
mpensationForThisLayer(layer, parentMatrix); | 336 WebTransformationMatrix scrollCompensationForThisLayer = computeScrollCo
mpensationForThisLayer(layer, parentMatrix); |
337 nextScrollCompensationMatrix.multiply(scrollCompensationForThisLayer); | 337 nextScrollCompensationMatrix.multiply(scrollCompensationForThisLayer); |
338 } | 338 } |
339 | 339 |
340 // If the layer created its own renderSurface, we have to adjust nextScrollC
ompensationMatrix. | 340 // If the layer created its own renderSurface, we have to adjust nextScrollC
ompensationMatrix. |
341 // The adjustment allows us to continue using the scrollCompensation on the
next surface. | 341 // The adjustment allows us to continue using the scrollCompensation on the
next surface. |
342 // Step 1 (right-most in the math): transform from the new surface to the o
riginal ancestor surface | 342 // Step 1 (right-most in the math): transform from the new surface to the o
riginal ancestor surface |
343 // Step 2: apply the scroll compensation | 343 // Step 2: apply the scroll compensation |
344 // Step 3: transform back to the new surface. | 344 // Step 3: transform back to the new surface. |
345 if (layer->renderSurface() && !nextScrollCompensationMatrix.isIdentity()) | 345 if (layer->renderSurface() && !nextScrollCompensationMatrix.isIdentity()) |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
484 | 484 |
485 float drawOpacity = layer->opacity(); | 485 float drawOpacity = layer->opacity(); |
486 bool drawOpacityIsAnimating = layer->opacityIsAnimating(); | 486 bool drawOpacityIsAnimating = layer->opacityIsAnimating(); |
487 if (layer->parent() && layer->parent()->preserves3D()) { | 487 if (layer->parent() && layer->parent()->preserves3D()) { |
488 drawOpacity *= layer->parent()->drawOpacity(); | 488 drawOpacity *= layer->parent()->drawOpacity(); |
489 drawOpacityIsAnimating |= layer->parent()->drawOpacityIsAnimating(); | 489 drawOpacityIsAnimating |= layer->parent()->drawOpacityIsAnimating(); |
490 } | 490 } |
491 | 491 |
492 gfx::Size bounds = layer->bounds(); | 492 gfx::Size bounds = layer->bounds(); |
493 gfx::PointF anchorPoint = layer->anchorPoint(); | 493 gfx::PointF anchorPoint = layer->anchorPoint(); |
494 gfx::PointF position = layer->position() - gfx::Vector2d(layer->scrollDelta(
).width(), layer->scrollDelta().height()); | 494 gfx::PointF position = layer->position() - layer->scrollDelta(); |
495 | 495 |
496 WebTransformationMatrix layerLocalTransform; | 496 WebTransformationMatrix layerLocalTransform; |
497 // LT = Tr[origin] * Tr[origin2anchor] | 497 // LT = Tr[origin] * Tr[origin2anchor] |
498 layerLocalTransform.translate3d(position.x() + anchorPoint.x() * bounds.widt
h(), position.y() + anchorPoint.y() * bounds.height(), layer->anchorPointZ()); | 498 layerLocalTransform.translate3d(position.x() + anchorPoint.x() * bounds.widt
h(), position.y() + anchorPoint.y() * bounds.height(), layer->anchorPointZ()); |
499 // LT = Tr[origin] * Tr[origin2anchor] * M[layer] | 499 // LT = Tr[origin] * Tr[origin2anchor] * M[layer] |
500 layerLocalTransform.multiply(layer->transform()); | 500 layerLocalTransform.multiply(layer->transform()); |
501 // LT = Tr[origin] * Tr[origin2anchor] * M[layer] * Tr[anchor2origin] | 501 // LT = Tr[origin] * Tr[origin2anchor] * M[layer] * Tr[anchor2origin] |
502 layerLocalTransform.translate3d(-anchorPoint.x() * bounds.width(), -anchorPo
int.y() * bounds.height(), -layer->anchorPointZ()); | 502 layerLocalTransform.translate3d(-anchorPoint.x() * bounds.width(), -anchorPo
int.y() * bounds.height(), -layer->anchorPointZ()); |
503 | 503 |
504 WebTransformationMatrix combinedTransform = parentMatrix; | 504 WebTransformationMatrix combinedTransform = parentMatrix; |
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
924 | 924 |
925 foundLayer = currentLayer; | 925 foundLayer = currentLayer; |
926 break; | 926 break; |
927 } | 927 } |
928 | 928 |
929 // This can potentially return 0, which means the screenSpacePoint did not s
uccessfully hit test any layers, not even the root layer. | 929 // This can potentially return 0, which means the screenSpacePoint did not s
uccessfully hit test any layers, not even the root layer. |
930 return foundLayer; | 930 return foundLayer; |
931 } | 931 } |
932 | 932 |
933 } // namespace cc | 933 } // namespace cc |
OLD | NEW |