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 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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()) |
346 nextScrollCompensationMatrix = layer->renderSurface()->drawTransform().i
nverse() * nextScrollCompensationMatrix * layer->renderSurface()->drawTransform(
); | 346 nextScrollCompensationMatrix = layer->renderSurface()->drawTransform().i
nverse() * nextScrollCompensationMatrix * layer->renderSurface()->drawTransform(
); |
347 | 347 |
348 return nextScrollCompensationMatrix; | 348 return nextScrollCompensationMatrix; |
349 } | 349 } |
350 | 350 |
351 // There is no contentsScale on impl thread. | 351 // There is no contentsScale on impl thread. |
352 static inline void updateLayerContentsScale(LayerImpl*, const WebTransformationM
atrix&, float, float) { } | 352 static inline void updateLayerContentsScale(LayerImpl*, const WebTransformationM
atrix&, float, float, bool) { } |
353 | 353 |
354 static inline void updateLayerContentsScale(Layer* layer, const WebTransformatio
nMatrix& combinedTransform, float deviceScaleFactor, float pageScaleFactor) | 354 static inline void updateLayerContentsScale(Layer* layer, const WebTransformatio
nMatrix& combinedTransform, float deviceScaleFactor, float pageScaleFactor, bool
animatingTransformToScreen) |
355 { | 355 { |
356 float rasterScale = layer->rasterScale(); | 356 float rasterScale = layer->rasterScale(); |
357 if (!rasterScale) { | 357 if (!rasterScale) { |
358 rasterScale = 1; | 358 rasterScale = 1; |
359 | 359 |
360 if (layer->automaticallyComputeRasterScale()) { | 360 if (!animatingTransformToScreen && layer->automaticallyComputeRasterScal
e()) { |
361 gfx::Vector2dF transformScale = MathUtil::computeTransform2dScaleCom
ponents(combinedTransform); | 361 gfx::Vector2dF transformScale = MathUtil::computeTransform2dScaleCom
ponents(combinedTransform); |
362 float combinedScale = std::max(transformScale.x(), transformScale.y(
)); | 362 float combinedScale = std::max(transformScale.x(), transformScale.y(
)); |
363 rasterScale = combinedScale / deviceScaleFactor; | 363 rasterScale = combinedScale / deviceScaleFactor; |
364 if (!layer->boundsContainPageScale()) | 364 if (!layer->boundsContainPageScale()) |
365 rasterScale /= pageScaleFactor; | 365 rasterScale /= pageScaleFactor; |
366 layer->setRasterScale(rasterScale); | 366 layer->setRasterScale(rasterScale); |
367 } | 367 } |
368 } | 368 } |
369 | 369 |
370 float contentsScale = rasterScale * deviceScaleFactor; | 370 float contentsScale = rasterScale * deviceScaleFactor; |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
482 gfx::Rect clipRectForSubtree; | 482 gfx::Rect clipRectForSubtree; |
483 bool subtreeShouldBeClipped = false; | 483 bool subtreeShouldBeClipped = false; |
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 bool animatingTransformToTarget = layer->transformIsAnimating(); |
| 493 bool animatingTransformToScreen = animatingTransformToTarget; |
| 494 if (layer->parent()) { |
| 495 animatingTransformToTarget |= layer->parent()->drawTransformIsAnimating(
); |
| 496 animatingTransformToScreen |= layer->parent()->screenSpaceTransformIsAni
mating(); |
| 497 } |
| 498 |
492 gfx::Size bounds = layer->bounds(); | 499 gfx::Size bounds = layer->bounds(); |
493 gfx::PointF anchorPoint = layer->anchorPoint(); | 500 gfx::PointF anchorPoint = layer->anchorPoint(); |
494 gfx::PointF position = layer->position() - layer->scrollDelta(); | 501 gfx::PointF position = layer->position() - layer->scrollDelta(); |
495 | 502 |
496 WebTransformationMatrix layerLocalTransform; | 503 WebTransformationMatrix layerLocalTransform; |
497 // LT = Tr[origin] * Tr[origin2anchor] | 504 // LT = Tr[origin] * Tr[origin2anchor] |
498 layerLocalTransform.translate3d(position.x() + anchorPoint.x() * bounds.widt
h(), position.y() + anchorPoint.y() * bounds.height(), layer->anchorPointZ()); | 505 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] | 506 // LT = Tr[origin] * Tr[origin2anchor] * M[layer] |
500 layerLocalTransform.multiply(layer->transform()); | 507 layerLocalTransform.multiply(layer->transform()); |
501 // LT = Tr[origin] * Tr[origin2anchor] * M[layer] * Tr[anchor2origin] | 508 // LT = Tr[origin] * Tr[origin2anchor] * M[layer] * Tr[anchor2origin] |
502 layerLocalTransform.translate3d(-anchorPoint.x() * bounds.width(), -anchorPo
int.y() * bounds.height(), -layer->anchorPointZ()); | 509 layerLocalTransform.translate3d(-anchorPoint.x() * bounds.width(), -anchorPo
int.y() * bounds.height(), -layer->anchorPointZ()); |
503 | 510 |
504 WebTransformationMatrix combinedTransform = parentMatrix; | 511 WebTransformationMatrix combinedTransform = parentMatrix; |
505 combinedTransform.multiply(layerLocalTransform); | 512 combinedTransform.multiply(layerLocalTransform); |
506 | 513 |
507 // The layer's contentsSize is determined from the combinedTransform, which
then informs the | 514 // The layer's contentsSize is determined from the combinedTransform, which
then informs the |
508 // layer's drawTransform. | 515 // layer's drawTransform. |
509 updateLayerContentsScale(layer, combinedTransform, deviceScaleFactor, pageSc
aleFactor); | 516 updateLayerContentsScale(layer, combinedTransform, deviceScaleFactor, pageSc
aleFactor, animatingTransformToScreen); |
510 | 517 |
511 // If there is a tranformation from the impl thread then it should be at the | 518 // If there is a tranformation from the impl thread then it should be at the |
512 // start of the combinedTransform, but we don't want it to affect the conten
tsScale. | 519 // start of the combinedTransform, but we don't want it to affect the conten
tsScale. |
513 combinedTransform = layer->implTransform() * combinedTransform; | 520 combinedTransform = layer->implTransform() * combinedTransform; |
514 | 521 |
515 if (layer->fixedToContainerLayer()) { | 522 if (layer->fixedToContainerLayer()) { |
516 // Special case: this layer is a composited fixed-position layer; we nee
d to | 523 // Special case: this layer is a composited fixed-position layer; we nee
d to |
517 // explicitly compensate for all ancestors' nonzero scrollDeltas to keep
this layer | 524 // explicitly compensate for all ancestors' nonzero scrollDeltas to keep
this layer |
518 // fixed correctly. | 525 // fixed correctly. |
519 combinedTransform = currentScrollCompensationMatrix * combinedTransform; | 526 combinedTransform = currentScrollCompensationMatrix * combinedTransform; |
520 } | 527 } |
521 | 528 |
522 // The drawTransform that gets computed below is effectively the layer's dra
wTransform, unless | 529 // The drawTransform that gets computed below is effectively the layer's dra
wTransform, unless |
523 // the layer itself creates a renderSurface. In that case, the renderSurface
re-parents the transforms. | 530 // the layer itself creates a renderSurface. In that case, the renderSurface
re-parents the transforms. |
524 WebTransformationMatrix drawTransform = combinedTransform; | 531 WebTransformationMatrix drawTransform = combinedTransform; |
525 if (!layer->contentBounds().IsEmpty() && !layer->bounds().IsEmpty()) { | 532 if (!layer->contentBounds().IsEmpty() && !layer->bounds().IsEmpty()) { |
526 // M[draw] = M[parent] * LT * S[layer2content] | 533 // M[draw] = M[parent] * LT * S[layer2content] |
527 drawTransform.scaleNonUniform(1.0 / layer->contentsScaleX(), | 534 drawTransform.scaleNonUniform(1.0 / layer->contentsScaleX(), |
528 1.0 / layer->contentsScaleY()); | 535 1.0 / layer->contentsScaleY()); |
529 } | 536 } |
530 | 537 |
531 // layerScreenSpaceTransform represents the transform between root layer's "
screen space" and local content space. | 538 // layerScreenSpaceTransform represents the transform between root layer's "
screen space" and local content space. |
532 WebTransformationMatrix layerScreenSpaceTransform = fullHierarchyMatrix; | 539 WebTransformationMatrix layerScreenSpaceTransform = fullHierarchyMatrix; |
533 if (!layer->preserves3D()) | 540 if (!layer->preserves3D()) |
534 MathUtil::flattenTransformTo2d(layerScreenSpaceTransform); | 541 MathUtil::flattenTransformTo2d(layerScreenSpaceTransform); |
535 layerScreenSpaceTransform.multiply(drawTransform); | 542 layerScreenSpaceTransform.multiply(drawTransform); |
536 layer->setScreenSpaceTransform(layerScreenSpaceTransform); | 543 layer->setScreenSpaceTransform(layerScreenSpaceTransform); |
537 | 544 |
538 bool animatingTransformToTarget = layer->transformIsAnimating(); | |
539 bool animatingTransformToScreen = animatingTransformToTarget; | |
540 if (layer->parent()) { | |
541 animatingTransformToTarget |= layer->parent()->drawTransformIsAnimating(
); | |
542 animatingTransformToScreen |= layer->parent()->screenSpaceTransformIsAni
mating(); | |
543 } | |
544 | |
545 gfx::RectF contentRect(gfx::PointF(), layer->contentBounds()); | 545 gfx::RectF contentRect(gfx::PointF(), layer->contentBounds()); |
546 | 546 |
547 // fullHierarchyMatrix is the matrix that transforms objects between screen
space (except projection matrix) and the most recent RenderSurfaceImpl's space. | 547 // 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. | 548 // nextHierarchyMatrix will only change if this layer uses a new RenderSurfa
ceImpl, otherwise remains the same. |
549 WebTransformationMatrix nextHierarchyMatrix = fullHierarchyMatrix; | 549 WebTransformationMatrix nextHierarchyMatrix = fullHierarchyMatrix; |
550 WebTransformationMatrix sublayerMatrix; | 550 WebTransformationMatrix sublayerMatrix; |
551 | 551 |
552 gfx::Vector2dF renderSurfaceSublayerScale = MathUtil::computeTransform2dScal
eComponents(combinedTransform); | 552 gfx::Vector2dF renderSurfaceSublayerScale = MathUtil::computeTransform2dScal
eComponents(combinedTransform); |
553 | 553 |
554 if (subtreeShouldRenderToSeparateSurface(layer, isScaleOrTranslation(combine
dTransform))) { | 554 if (subtreeShouldRenderToSeparateSurface(layer, isScaleOrTranslation(combine
dTransform))) { |
(...skipping 369 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 |