Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(57)

Side by Side Diff: cc/layer_tree_host_common.cc

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

Powered by Google App Engine
This is Rietveld 408576698