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> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
10 #include "cc/layer.h" | 10 #include "cc/layer.h" |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
49 // If the layer doesn't fill up the entire surface, then find the part of | 49 // If the layer doesn't fill up the entire surface, then find the part of |
50 // the surface rect where the layer could be visible. This avoids trying to | 50 // the surface rect where the layer could be visible. This avoids trying to |
51 // project surface rect points that are behind the projection point. | 51 // project surface rect points that are behind the projection point. |
52 gfx::Rect minimalSurfaceRect = targetSurfaceRect; | 52 gfx::Rect minimalSurfaceRect = targetSurfaceRect; |
53 minimalSurfaceRect.Intersect(layerRectInTargetSpace); | 53 minimalSurfaceRect.Intersect(layerRectInTargetSpace); |
54 | 54 |
55 // Project the corners of the target surface rect into the layer space. | 55 // Project the corners of the target surface rect into the layer space. |
56 // This bounding rectangle may be larger than it needs to be (being | 56 // This bounding rectangle may be larger than it needs to be (being |
57 // axis-aligned), but is a reasonable filter on the space to consider. | 57 // axis-aligned), but is a reasonable filter on the space to consider. |
58 // Non-invertible transforms will create an empty rect here. | 58 // Non-invertible transforms will create an empty rect here. |
59 const gfx::Transform surfaceToLayer = MathUtil::inverse(transform); | 59 gfx::Transform surfaceToLayer(gfx::Transform::kSkipInitialization); |
60 transform.GetInverse(&surfaceToLayer); | |
danakj
2012/12/19 05:23:06
If it's not invertible, should we return layerBoun
| |
60 gfx::Rect layerRect = gfx::ToEnclosingRect(MathUtil::projectClippedRect(surf aceToLayer, gfx::RectF(minimalSurfaceRect))); | 61 gfx::Rect layerRect = gfx::ToEnclosingRect(MathUtil::projectClippedRect(surf aceToLayer, gfx::RectF(minimalSurfaceRect))); |
61 layerRect.Intersect(layerBoundRect); | 62 layerRect.Intersect(layerBoundRect); |
62 return layerRect; | 63 return layerRect; |
63 } | 64 } |
64 | 65 |
65 gfx::Rect LayerTreeHostCommon::calculateVisibleRect(const gfx::Rect& targetSurfa ceRect, const gfx::Rect& layerBoundRect, const gfx::Transform& transform) | 66 gfx::Rect LayerTreeHostCommon::calculateVisibleRect(const gfx::Rect& targetSurfa ceRect, const gfx::Rect& layerBoundRect, const gfx::Transform& transform) |
66 { | 67 { |
67 gfx::Rect layerInSurfaceSpace = MathUtil::mapClippedRect(transform, layerBou ndRect); | 68 gfx::Rect layerInSurfaceSpace = MathUtil::mapClippedRect(transform, layerBou ndRect); |
68 return calculateVisibleRectWithCachedLayerRect(targetSurfaceRect, layerBound Rect, layerInSurfaceSpace, transform); | 69 return calculateVisibleRectWithCachedLayerRect(targetSurfaceRect, layerBound Rect, layerInSurfaceSpace, transform); |
69 } | 70 } |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
314 // These steps create a matrix that both start and end in targetSurfaceSpace . So this matrix can | 315 // These steps create a matrix that both start and end in targetSurfaceSpace . So this matrix can |
315 // pre-multiply any fixed-position layer's drawTransform to undo the scrollD eltas -- as long as | 316 // pre-multiply any fixed-position layer's drawTransform to undo the scrollD eltas -- as long as |
316 // that fixed position layer is fixed onto the same renderTarget as this scr ollingLayer. | 317 // that fixed position layer is fixed onto the same renderTarget as this scr ollingLayer. |
317 // | 318 // |
318 | 319 |
319 gfx::Transform partialLayerOriginTransform = parentMatrix; | 320 gfx::Transform partialLayerOriginTransform = parentMatrix; |
320 partialLayerOriginTransform.PreconcatTransform(scrollingLayer->implTransform ()); | 321 partialLayerOriginTransform.PreconcatTransform(scrollingLayer->implTransform ()); |
321 | 322 |
322 gfx::Transform scrollCompensationForThisLayer = partialLayerOriginTransform; // Step 3 | 323 gfx::Transform scrollCompensationForThisLayer = partialLayerOriginTransform; // Step 3 |
323 scrollCompensationForThisLayer.Translate(scrollingLayer->scrollDelta().x(), scrollingLayer->scrollDelta().y()); // Step 2 | 324 scrollCompensationForThisLayer.Translate(scrollingLayer->scrollDelta().x(), scrollingLayer->scrollDelta().y()); // Step 2 |
324 scrollCompensationForThisLayer.PreconcatTransform(MathUtil::inverse(partialL ayerOriginTransform)); // Step 1 | 325 gfx::Transform inversePartialLayerOriginTransform(gfx::Transform::kSkipIniti alization); |
326 partialLayerOriginTransform.GetInverse(&inversePartialLayerOriginTransform); | |
danakj
2012/12/19 05:23:06
DCHECK the return value?
| |
327 scrollCompensationForThisLayer.PreconcatTransform(inversePartialLayerOriginT ransform); // Step 1 | |
325 return scrollCompensationForThisLayer; | 328 return scrollCompensationForThisLayer; |
326 } | 329 } |
327 | 330 |
328 gfx::Transform computeScrollCompensationMatrixForChildren(Layer* currentLayer, c onst gfx::Transform& currentParentMatrix, const gfx::Transform& currentScrollCom pensation) | 331 gfx::Transform computeScrollCompensationMatrixForChildren(Layer* currentLayer, c onst gfx::Transform& currentParentMatrix, const gfx::Transform& currentScrollCom pensation) |
329 { | 332 { |
330 // The main thread (i.e. Layer) does not need to worry about scroll compensa tion. | 333 // The main thread (i.e. Layer) does not need to worry about scroll compensa tion. |
331 // So we can just return an identity matrix here. | 334 // So we can just return an identity matrix here. |
332 return gfx::Transform(); | 335 return gfx::Transform(); |
333 } | 336 } |
334 | 337 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
366 if (!layer->scrollDelta().IsZero()) { | 369 if (!layer->scrollDelta().IsZero()) { |
367 gfx::Transform scrollCompensationForThisLayer = computeScrollCompensatio nForThisLayer(layer, parentMatrix); | 370 gfx::Transform scrollCompensationForThisLayer = computeScrollCompensatio nForThisLayer(layer, parentMatrix); |
368 nextScrollCompensationMatrix.PreconcatTransform(scrollCompensationForThi sLayer); | 371 nextScrollCompensationMatrix.PreconcatTransform(scrollCompensationForThi sLayer); |
369 } | 372 } |
370 | 373 |
371 // If the layer created its own renderSurface, we have to adjust nextScrollC ompensationMatrix. | 374 // If the layer created its own renderSurface, we have to adjust nextScrollC ompensationMatrix. |
372 // The adjustment allows us to continue using the scrollCompensation on the next surface. | 375 // The adjustment allows us to continue using the scrollCompensation on the next surface. |
373 // Step 1 (right-most in the math): transform from the new surface to the o riginal ancestor surface | 376 // Step 1 (right-most in the math): transform from the new surface to the o riginal ancestor surface |
374 // Step 2: apply the scroll compensation | 377 // Step 2: apply the scroll compensation |
375 // Step 3: transform back to the new surface. | 378 // Step 3: transform back to the new surface. |
376 if (layer->renderSurface() && !nextScrollCompensationMatrix.IsIdentity()) | 379 if (layer->renderSurface() && !nextScrollCompensationMatrix.IsIdentity()) { |
377 nextScrollCompensationMatrix = MathUtil::inverse(layer->renderSurface()- >drawTransform()) * nextScrollCompensationMatrix * layer->renderSurface()->drawT ransform(); | 380 gfx::Transform inverseSurfaceDrawTransform(gfx::Transform::kSkipInitiali zation); |
381 layer->renderSurface()->drawTransform().GetInverse(&inverseSurfaceDrawTr ansform); | |
danakj
2012/12/19 05:23:06
DCHECK the return value? Or should we do something
| |
382 nextScrollCompensationMatrix = inverseSurfaceDrawTransform * nextScrollC ompensationMatrix * layer->renderSurface()->drawTransform(); | |
383 } | |
378 | 384 |
379 return nextScrollCompensationMatrix; | 385 return nextScrollCompensationMatrix; |
380 } | 386 } |
381 | 387 |
382 static inline void updateLayerContentsScale(LayerImpl* layer, const gfx::Transfo rm& combinedTransform, float deviceScaleFactor, float pageScaleFactor, bool anim atingTransformToScreen) | 388 static inline void updateLayerContentsScale(LayerImpl* layer, const gfx::Transfo rm& combinedTransform, float deviceScaleFactor, float pageScaleFactor, bool anim atingTransformToScreen) |
383 { | 389 { |
384 } | 390 } |
385 | 391 |
386 static inline void updateLayerContentsScale(Layer* layer, const gfx::Transform& combinedTransform, float deviceScaleFactor, float pageScaleFactor, bool animatin gTransformToScreen) | 392 static inline void updateLayerContentsScale(Layer* layer, const gfx::Transform& combinedTransform, float deviceScaleFactor, float pageScaleFactor, bool animatin gTransformToScreen) |
387 { | 393 { |
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
729 | 735 |
730 // FIXME: make this smarter for the SkImageFilter case (check for | 736 // FIXME: make this smarter for the SkImageFilter case (check for |
731 // pixel-moving filters) | 737 // pixel-moving filters) |
732 if (layer->filters().hasFilterThatMovesPixels() || layer->filter()) | 738 if (layer->filters().hasFilterThatMovesPixels() || layer->filter()) |
733 nearestAncestorThatMovesPixels = renderSurface; | 739 nearestAncestorThatMovesPixels = renderSurface; |
734 | 740 |
735 // The render surface clipRect is expressed in the space where this surf ace draws, i.e. the same space as clipRectFromAncestor. | 741 // The render surface clipRect is expressed in the space where this surf ace draws, i.e. the same space as clipRectFromAncestor. |
736 renderSurface->setIsClipped(ancestorClipsSubtree); | 742 renderSurface->setIsClipped(ancestorClipsSubtree); |
737 if (ancestorClipsSubtree) { | 743 if (ancestorClipsSubtree) { |
738 renderSurface->setClipRect(clipRectFromAncestor); | 744 renderSurface->setClipRect(clipRectFromAncestor); |
739 clipRectForSubtreeInDescendantSpace = gfx::ToEnclosingRect(MathUtil: :projectClippedRect(MathUtil::inverse(renderSurface->drawTransform()), renderSur face->clipRect())); | 745 gfx::Transform inverseSurfaceDrawTransform(gfx::Transform::kSkipInit ialization); |
746 renderSurface->drawTransform().GetInverse(&inverseSurfaceDrawTransfo rm); | |
danakj
2012/12/19 05:23:06
DCHECK the return value?
| |
747 clipRectForSubtreeInDescendantSpace = gfx::ToEnclosingRect(MathUtil: :projectClippedRect(inverseSurfaceDrawTransform, renderSurface->clipRect())); | |
740 } else { | 748 } else { |
741 renderSurface->setClipRect(gfx::Rect()); | 749 renderSurface->setClipRect(gfx::Rect()); |
742 clipRectForSubtreeInDescendantSpace = clipRectFromAncestorInDescenda ntSpace; | 750 clipRectForSubtreeInDescendantSpace = clipRectFromAncestorInDescenda ntSpace; |
743 } | 751 } |
744 | 752 |
745 renderSurface->setNearestAncestorThatMovesPixels(nearestAncestorThatMove sPixels); | 753 renderSurface->setNearestAncestorThatMovesPixels(nearestAncestorThatMove sPixels); |
746 | 754 |
747 // If the new render surface is drawn translucent or with a non-integral translation | 755 // If the new render surface is drawn translucent or with a non-integral translation |
748 // then the subtree that gets drawn on this render surface cannot use LC D text. | 756 // then the subtree that gets drawn on this render surface cannot use LC D text. |
749 subtreeCanUseLCDText = layerCanUseLCDText; | 757 subtreeCanUseLCDText = layerCanUseLCDText; |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
991 | 999 |
992 // The dummy layer list should not have been used. | 1000 // The dummy layer list should not have been used. |
993 DCHECK(dummyLayerList.size() == 0); | 1001 DCHECK(dummyLayerList.size() == 0); |
994 // A root layer renderSurface should always exist after calculateDrawPropert ies. | 1002 // A root layer renderSurface should always exist after calculateDrawPropert ies. |
995 DCHECK(rootLayer->renderSurface()); | 1003 DCHECK(rootLayer->renderSurface()); |
996 } | 1004 } |
997 | 1005 |
998 static bool pointHitsRect(const gfx::PointF& screenSpacePoint, const gfx::Transf orm& localSpaceToScreenSpaceTransform, gfx::RectF localSpaceRect) | 1006 static bool pointHitsRect(const gfx::PointF& screenSpacePoint, const gfx::Transf orm& localSpaceToScreenSpaceTransform, gfx::RectF localSpaceRect) |
999 { | 1007 { |
1000 // If the transform is not invertible, then assume that this point doesn't h it this rect. | 1008 // If the transform is not invertible, then assume that this point doesn't h it this rect. |
1001 if (!localSpaceToScreenSpaceTransform.IsInvertible()) | 1009 gfx::Transform inverseLocalSpaceToScreenSpace(gfx::Transform::kSkipInitializ ation); |
1010 if (!localSpaceToScreenSpaceTransform.GetInverse(&inverseLocalSpaceToScreenS pace)) | |
1002 return false; | 1011 return false; |
1003 | 1012 |
1004 // Transform the hit test point from screen space to the local space of the given rect. | 1013 // Transform the hit test point from screen space to the local space of the given rect. |
1005 bool clipped = false; | 1014 bool clipped = false; |
1006 gfx::PointF hitTestPointInLocalSpace = MathUtil::projectPoint(MathUtil::inve rse(localSpaceToScreenSpaceTransform), screenSpacePoint, clipped); | 1015 gfx::PointF hitTestPointInLocalSpace = MathUtil::projectPoint(inverseLocalSp aceToScreenSpace, screenSpacePoint, clipped); |
1007 | 1016 |
1008 // If projectPoint could not project to a valid value, then we assume that t his point doesn't hit this rect. | 1017 // If projectPoint could not project to a valid value, then we assume that t his point doesn't hit this rect. |
1009 if (clipped) | 1018 if (clipped) |
1010 return false; | 1019 return false; |
1011 | 1020 |
1012 return localSpaceRect.Contains(hitTestPointInLocalSpace); | 1021 return localSpaceRect.Contains(hitTestPointInLocalSpace); |
1013 } | 1022 } |
1014 | 1023 |
1015 static bool pointHitsRegion(gfx::PointF screenSpacePoint, const gfx::Transform& screenSpaceTransform, const Region& layerSpaceRegion, float layerContentScaleX, float layerContentScaleY) | 1024 static bool pointHitsRegion(gfx::PointF screenSpacePoint, const gfx::Transform& screenSpaceTransform, const Region& layerSpaceRegion, float layerContentScaleX, float layerContentScaleY) |
1016 { | 1025 { |
1017 // If the transform is not invertible, then assume that this point doesn't h it this region. | 1026 // If the transform is not invertible, then assume that this point doesn't h it this region. |
1018 if (!screenSpaceTransform.IsInvertible()) | 1027 gfx::Transform inverseScreenSpaceTransform(gfx::Transform::kSkipInitializati on); |
1028 if (!screenSpaceTransform.GetInverse(&inverseScreenSpaceTransform)) | |
1019 return false; | 1029 return false; |
1020 | 1030 |
1021 // Transform the hit test point from screen space to the local space of the given region. | 1031 // Transform the hit test point from screen space to the local space of the given region. |
1022 bool clipped = false; | 1032 bool clipped = false; |
1023 gfx::PointF hitTestPointInContentSpace = MathUtil::projectPoint(MathUtil::in verse(screenSpaceTransform), screenSpacePoint, clipped); | 1033 gfx::PointF hitTestPointInContentSpace = MathUtil::projectPoint(inverseScree nSpaceTransform, screenSpacePoint, clipped); |
1024 gfx::PointF hitTestPointInLayerSpace = gfx::ScalePoint(hitTestPointInContent Space, 1 / layerContentScaleX, 1 / layerContentScaleY); | 1034 gfx::PointF hitTestPointInLayerSpace = gfx::ScalePoint(hitTestPointInContent Space, 1 / layerContentScaleX, 1 / layerContentScaleY); |
1025 | 1035 |
1026 // If projectPoint could not project to a valid value, then we assume that t his point doesn't hit this region. | 1036 // If projectPoint could not project to a valid value, then we assume that t his point doesn't hit this region. |
1027 if (clipped) | 1037 if (clipped) |
1028 return false; | 1038 return false; |
1029 | 1039 |
1030 return layerSpaceRegion.Contains(gfx::ToRoundedPoint(hitTestPointInLayerSpac e)); | 1040 return layerSpaceRegion.Contains(gfx::ToRoundedPoint(hitTestPointInLayerSpac e)); |
1031 } | 1041 } |
1032 | 1042 |
1033 static bool pointIsClippedBySurfaceOrClipRect(const gfx::PointF& screenSpacePoin t, LayerImpl* layer) | 1043 static bool pointIsClippedBySurfaceOrClipRect(const gfx::PointF& screenSpacePoin t, LayerImpl* layer) |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1118 | 1128 |
1119 // At this point, we think the point does hit the touch event handler region o n the layer, but we need to walk up | 1129 // At this point, we think the point does hit the touch event handler region o n the layer, but we need to walk up |
1120 // the parents to ensure that the layer was not clipped in such a way that the | 1130 // the parents to ensure that the layer was not clipped in such a way that the |
1121 // hit point actually should not hit the layer. | 1131 // hit point actually should not hit the layer. |
1122 if (pointIsClippedBySurfaceOrClipRect(screenSpacePoint, layerImpl)) | 1132 if (pointIsClippedBySurfaceOrClipRect(screenSpacePoint, layerImpl)) |
1123 return false; | 1133 return false; |
1124 | 1134 |
1125 return true; | 1135 return true; |
1126 } | 1136 } |
1127 } // namespace cc | 1137 } // namespace cc |
OLD | NEW |