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

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: 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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
657 clipRectForSubtree.Intersect(rectInTargetSpace); 658 clipRectForSubtree.Intersect(rectInTargetSpace);
658 } else 659 } else
659 clipRectForSubtree = rectInTargetSpace; 660 clipRectForSubtree = rectInTargetSpace;
660 } 661 }
661 662
662 // Flatten to 2D if the layer doesn't preserve 3D. 663 // Flatten to 2D if the layer doesn't preserve 3D.
663 if (!layer->preserves3D()) 664 if (!layer->preserves3D())
664 MathUtil::flattenTransformTo2d(sublayerMatrix); 665 MathUtil::flattenTransformTo2d(sublayerMatrix);
665 666
666 // Apply the sublayer transform at the center of the layer. 667 // Apply the sublayer transform at the center of the layer.
667 sublayerMatrix.translate(0.5 * bounds.width(), 0.5 * bounds.height()); 668 sublayerMatrix.PreconcatTranslate(0.5 * bounds.width(), 0.5 * bounds.height( ));
668 sublayerMatrix.multiply(layer->sublayerTransform()); 669 sublayerMatrix.PreconcatTransform(layer->sublayerTransform());
669 sublayerMatrix.translate(-0.5 * bounds.width(), -0.5 * bounds.height()); 670 sublayerMatrix.PreconcatTranslate(-0.5 * bounds.width(), -0.5 * bounds.heigh t());
670 671
671 LayerList& descendants = (layer->renderSurface() ? layer->renderSurface()->l ayerList() : layerList); 672 LayerList& descendants = (layer->renderSurface() ? layer->renderSurface()->l ayerList() : layerList);
672 673
673 // Any layers that are appended after this point are in the layer's subtree and should be included in the sorting process. 674 // Any layers that are appended after this point are in the layer's subtree and should be included in the sorting process.
674 unsigned sortingStartIndex = descendants.size(); 675 unsigned sortingStartIndex = descendants.size();
675 676
676 if (!layerShouldBeSkipped(layer)) 677 if (!layerShouldBeSkipped(layer))
677 descendants.push_back(layer); 678 descendants.push_back(layer);
678 679
679 WebTransformationMatrix nextScrollCompensationMatrix = computeScrollCompensa tionMatrixForChildren(layer, parentMatrix, currentScrollCompensationMatrix);; 680 Transform nextScrollCompensationMatrix = computeScrollCompensationMatrixForC hildren(layer, parentMatrix, currentScrollCompensationMatrix);;
680 681
681 gfx::Rect accumulatedDrawableContentRectOfChildren; 682 gfx::Rect accumulatedDrawableContentRectOfChildren;
682 for (size_t i = 0; i < layer->children().size(); ++i) { 683 for (size_t i = 0; i < layer->children().size(); ++i) {
683 LayerType* child = LayerTreeHostCommon::getChildAsRawPtr(layer->children (), i); 684 LayerType* child = LayerTreeHostCommon::getChildAsRawPtr(layer->children (), i);
684 gfx::Rect drawableContentRectOfChildSubtree; 685 gfx::Rect drawableContentRectOfChildSubtree;
685 calculateDrawTransformsInternal<LayerType, LayerList, RenderSurfaceType, LayerSorter>(child, sublayerMatrix, nextHierarchyMatrix, nextScrollCompensation Matrix, 686 calculateDrawTransformsInternal<LayerType, LayerList, RenderSurfaceType, LayerSorter>(child, sublayerMatrix, nextHierarchyMatrix, nextScrollCompensation Matrix,
686 clipRectForSubtree, subtreeShouldBeClipped, nearestAncestorThatMov esPixels, 687 clipRectForSubtree, subtreeShouldBeClipped, nearestAncestorThatMov esPixels,
687 renderSurfaceLayerList, descendants, layerSorter, maxTextureSize, deviceScaleFactor, pageScaleFactor, drawableContentRectOfChildSubtree); 688 renderSurfaceLayerList, descendants, layerSorter, maxTextureSize, deviceScaleFactor, pageScaleFactor, drawableContentRectOfChildSubtree);
688 if (!drawableContentRectOfChildSubtree.IsEmpty()) { 689 if (!drawableContentRectOfChildSubtree.IsEmpty()) {
689 accumulatedDrawableContentRectOfChildren.Union(drawableContentRectOf ChildSubtree); 690 accumulatedDrawableContentRectOfChildren.Union(drawableContentRectOf ChildSubtree);
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
735 clippedContentRect.set_width(std::min(clippedContentRect.width(), maxTex tureSize)); 736 clippedContentRect.set_width(std::min(clippedContentRect.width(), maxTex tureSize));
736 clippedContentRect.set_height(std::min(clippedContentRect.height(), maxT extureSize)); 737 clippedContentRect.set_height(std::min(clippedContentRect.height(), maxT extureSize));
737 738
738 if (clippedContentRect.IsEmpty()) 739 if (clippedContentRect.IsEmpty())
739 renderSurface->clearLayerLists(); 740 renderSurface->clearLayerLists();
740 741
741 renderSurface->setContentRect(clippedContentRect); 742 renderSurface->setContentRect(clippedContentRect);
742 743
743 // The owning layer's screenSpaceTransform has a scale from content to l ayer space which we need to undo and 744 // The owning layer's screenSpaceTransform has a scale from content to l ayer space which we need to undo and
744 // replace with a scale from the surface's subtree into layer space. 745 // replace with a scale from the surface's subtree into layer space.
745 WebTransformationMatrix screenSpaceTransform = layer->screenSpaceTransfo rm(); 746 Transform screenSpaceTransform = layer->screenSpaceTransform();
746 screenSpaceTransform.scaleNonUniform(layer->contentsScaleX(), layer->con tentsScaleY()); 747 screenSpaceTransform.PreconcatScale(layer->contentsScaleX(), layer->cont entsScaleY());
747 screenSpaceTransform.scaleNonUniform(1 / renderSurfaceSublayerScale.x(), 1 / renderSurfaceSublayerScale.y()); 748 screenSpaceTransform.PreconcatScale(1 / renderSurfaceSublayerScale.x(), 1 / renderSurfaceSublayerScale.y());
748 renderSurface->setScreenSpaceTransform(screenSpaceTransform); 749 renderSurface->setScreenSpaceTransform(screenSpaceTransform);
749 750
750 if (layer->replicaLayer()) { 751 if (layer->replicaLayer()) {
751 WebTransformationMatrix surfaceOriginToReplicaOriginTransform; 752 Transform surfaceOriginToReplicaOriginTransform;
752 surfaceOriginToReplicaOriginTransform.scaleNonUniform(renderSurfaceS ublayerScale.x(), renderSurfaceSublayerScale.y()); 753 surfaceOriginToReplicaOriginTransform.PreconcatScale(renderSurfaceSu blayerScale.x(), renderSurfaceSublayerScale.y());
753 surfaceOriginToReplicaOriginTransform.translate(layer->replicaLayer( )->position().x() + layer->replicaLayer()->anchorPoint().x() * bounds.width(), 754 surfaceOriginToReplicaOriginTransform.PreconcatTranslate(layer->repl icaLayer()->position().x() + layer->replicaLayer()->anchorPoint().x() * bounds.w idth(),
754 layer->replicaLayer( )->position().y() + layer->replicaLayer()->anchorPoint().y() * bounds.height()); 755 layer->replicaLayer( )->position().y() + layer->replicaLayer()->anchorPoint().y() * bounds.height());
755 surfaceOriginToReplicaOriginTransform.multiply(layer->replicaLayer() ->transform()); 756 surfaceOriginToReplicaOriginTransform.PreconcatTransform(layer->repl icaLayer()->transform());
756 surfaceOriginToReplicaOriginTransform.translate(-layer->replicaLayer ()->anchorPoint().x() * bounds.width(), -layer->replicaLayer()->anchorPoint().y( ) * bounds.height()); 757 surfaceOriginToReplicaOriginTransform.PreconcatTranslate(-layer->rep licaLayer()->anchorPoint().x() * bounds.width(), -layer->replicaLayer()->anchorP oint().y() * bounds.height());
757 surfaceOriginToReplicaOriginTransform.scaleNonUniform(1 / renderSurf aceSublayerScale.x(), 1 / renderSurfaceSublayerScale.y()); 758 surfaceOriginToReplicaOriginTransform.PreconcatScale(1 / renderSurfa ceSublayerScale.x(), 1 / renderSurfaceSublayerScale.y());
758 759
759 // Compute the replica's "originTransform" that maps from the replic a's origin space to the target surface origin space. 760 // Compute the replica's "originTransform" that maps from the replic a's origin space to the target surface origin space.
760 WebTransformationMatrix replicaOriginTransform = layer->renderSurfac e()->drawTransform() * surfaceOriginToReplicaOriginTransform; 761 Transform replicaOriginTransform = layer->renderSurface()->drawTrans form() * surfaceOriginToReplicaOriginTransform;
761 renderSurface->setReplicaDrawTransform(replicaOriginTransform); 762 renderSurface->setReplicaDrawTransform(replicaOriginTransform);
762 763
763 // Compute the replica's "screenSpaceTransform" that maps from the r eplica's origin space to the screen's origin space. 764 // Compute the replica's "screenSpaceTransform" that maps from the r eplica's origin space to the screen's origin space.
764 WebTransformationMatrix replicaScreenSpaceTransform = layer->renderS urface()->screenSpaceTransform() * surfaceOriginToReplicaOriginTransform; 765 Transform replicaScreenSpaceTransform = layer->renderSurface()->scre enSpaceTransform() * surfaceOriginToReplicaOriginTransform;
765 renderSurface->setReplicaScreenSpaceTransform(replicaScreenSpaceTran sform); 766 renderSurface->setReplicaScreenSpaceTransform(replicaScreenSpaceTran sform);
766 } 767 }
767 768
768 // If a render surface has no layer list, then it and none of its childr en needed to get drawn. 769 // If a render surface has no layer list, then it and none of its childr en needed to get drawn.
769 if (!layer->renderSurface()->layerList().size()) { 770 if (!layer->renderSurface()->layerList().size()) {
770 // FIXME: Originally we asserted that this layer was already at the end of the 771 // FIXME: Originally we asserted that this layer was already at the end of the
771 // list, and only needed to remove that layer. For now, we re move the 772 // list, and only needed to remove that layer. For now, we re move the
772 // entire subtree of surfaces to fix a crash bug. The root ca use is 773 // entire subtree of surfaces to fix a crash bug. The root ca use is
773 // https://bugs.webkit.org/show_bug.cgi?id=74147 and we shoul d be able 774 // https://bugs.webkit.org/show_bug.cgi?id=74147 and we shoul d be able
774 // to put the original assert after fixing that. 775 // to put the original assert after fixing that.
(...skipping 23 matching lines...) Expand all
798 else 799 else
799 drawableContentRectOfSubtree = localDrawableContentRectOfSubtree; 800 drawableContentRectOfSubtree = localDrawableContentRectOfSubtree;
800 801
801 if (layer->hasContributingDelegatedRenderPasses()) 802 if (layer->hasContributingDelegatedRenderPasses())
802 layer->renderTarget()->renderSurface()->addContributingDelegatedRenderPa ssLayer(layer); 803 layer->renderTarget()->renderSurface()->addContributingDelegatedRenderPa ssLayer(layer);
803 } 804 }
804 805
805 void LayerTreeHostCommon::calculateDrawTransforms(Layer* rootLayer, const gfx::S ize& deviceViewportSize, float deviceScaleFactor, float pageScaleFactor, int max TextureSize, std::vector<scoped_refptr<Layer> >& renderSurfaceLayerList) 806 void LayerTreeHostCommon::calculateDrawTransforms(Layer* rootLayer, const gfx::S ize& deviceViewportSize, float deviceScaleFactor, float pageScaleFactor, int max TextureSize, std::vector<scoped_refptr<Layer> >& renderSurfaceLayerList)
806 { 807 {
807 gfx::Rect totalDrawableContentRect; 808 gfx::Rect totalDrawableContentRect;
808 WebTransformationMatrix identityMatrix; 809 Transform identityMatrix;
809 WebTransformationMatrix deviceScaleTransform; 810 Transform deviceScaleTransform;
810 deviceScaleTransform.scale(deviceScaleFactor); 811 deviceScaleTransform.PreconcatScale(deviceScaleFactor, deviceScaleFactor);
811 std::vector<scoped_refptr<Layer> > dummyLayerList; 812 std::vector<scoped_refptr<Layer> > dummyLayerList;
812 813
813 // The root layer's renderSurface should receive the deviceViewport as the i nitial clipRect. 814 // The root layer's renderSurface should receive the deviceViewport as the i nitial clipRect.
814 bool subtreeShouldBeClipped = true; 815 bool subtreeShouldBeClipped = true;
815 gfx::Rect deviceViewportRect(gfx::Point(), deviceViewportSize); 816 gfx::Rect deviceViewportRect(gfx::Point(), deviceViewportSize);
816 817
817 // This function should have received a root layer. 818 // This function should have received a root layer.
818 DCHECK(isRootLayer(rootLayer)); 819 DCHECK(isRootLayer(rootLayer));
819 820
820 cc::calculateDrawTransformsInternal<Layer, std::vector<scoped_refptr<Layer> >, RenderSurface, void>( 821 cc::calculateDrawTransformsInternal<Layer, std::vector<scoped_refptr<Layer> >, RenderSurface, void>(
821 rootLayer, deviceScaleTransform, identityMatrix, identityMatrix, 822 rootLayer, deviceScaleTransform, identityMatrix, identityMatrix,
822 deviceViewportRect, subtreeShouldBeClipped, 0, renderSurfaceLayerList, 823 deviceViewportRect, subtreeShouldBeClipped, 0, renderSurfaceLayerList,
823 dummyLayerList, 0, maxTextureSize, 824 dummyLayerList, 0, maxTextureSize,
824 deviceScaleFactor, pageScaleFactor, totalDrawableContentRect); 825 deviceScaleFactor, pageScaleFactor, totalDrawableContentRect);
825 826
826 // The dummy layer list should not have been used. 827 // The dummy layer list should not have been used.
827 DCHECK(dummyLayerList.size() == 0); 828 DCHECK(dummyLayerList.size() == 0);
828 // A root layer renderSurface should always exist after calculateDrawTransfo rms. 829 // A root layer renderSurface should always exist after calculateDrawTransfo rms.
829 DCHECK(rootLayer->renderSurface()); 830 DCHECK(rootLayer->renderSurface());
830 } 831 }
831 832
832 void LayerTreeHostCommon::calculateDrawTransforms(LayerImpl* rootLayer, const gf x::Size& deviceViewportSize, float deviceScaleFactor, float pageScaleFactor, Lay erSorter* layerSorter, int maxTextureSize, std::vector<LayerImpl*>& renderSurfac eLayerList) 833 void LayerTreeHostCommon::calculateDrawTransforms(LayerImpl* rootLayer, const gf x::Size& deviceViewportSize, float deviceScaleFactor, float pageScaleFactor, Lay erSorter* layerSorter, int maxTextureSize, std::vector<LayerImpl*>& renderSurfac eLayerList)
833 { 834 {
834 gfx::Rect totalDrawableContentRect; 835 gfx::Rect totalDrawableContentRect;
835 WebTransformationMatrix identityMatrix; 836 Transform identityMatrix;
836 WebTransformationMatrix deviceScaleTransform; 837 Transform deviceScaleTransform;
837 deviceScaleTransform.scale(deviceScaleFactor); 838 deviceScaleTransform.PreconcatScale(deviceScaleFactor, deviceScaleFactor);
838 std::vector<LayerImpl*> dummyLayerList; 839 std::vector<LayerImpl*> dummyLayerList;
839 840
840 // The root layer's renderSurface should receive the deviceViewport as the i nitial clipRect. 841 // The root layer's renderSurface should receive the deviceViewport as the i nitial clipRect.
841 bool subtreeShouldBeClipped = true; 842 bool subtreeShouldBeClipped = true;
842 gfx::Rect deviceViewportRect(gfx::Point(), deviceViewportSize); 843 gfx::Rect deviceViewportRect(gfx::Point(), deviceViewportSize);
843 844
844 // This function should have received a root layer. 845 // This function should have received a root layer.
845 DCHECK(isRootLayer(rootLayer)); 846 DCHECK(isRootLayer(rootLayer));
846 847
847 cc::calculateDrawTransformsInternal<LayerImpl, std::vector<LayerImpl*>, Rend erSurfaceImpl, LayerSorter>( 848 cc::calculateDrawTransformsInternal<LayerImpl, std::vector<LayerImpl*>, Rend erSurfaceImpl, LayerSorter>(
848 rootLayer, deviceScaleTransform, identityMatrix, identityMatrix, 849 rootLayer, deviceScaleTransform, identityMatrix, identityMatrix,
849 deviceViewportRect, subtreeShouldBeClipped, 0, renderSurfaceLayerList, 850 deviceViewportRect, subtreeShouldBeClipped, 0, renderSurfaceLayerList,
850 dummyLayerList, layerSorter, maxTextureSize, 851 dummyLayerList, layerSorter, maxTextureSize,
851 deviceScaleFactor, pageScaleFactor, totalDrawableContentRect); 852 deviceScaleFactor, pageScaleFactor, totalDrawableContentRect);
852 853
853 // The dummy layer list should not have been used. 854 // The dummy layer list should not have been used.
854 DCHECK(dummyLayerList.size() == 0); 855 DCHECK(dummyLayerList.size() == 0);
855 // A root layer renderSurface should always exist after calculateDrawTransfo rms. 856 // A root layer renderSurface should always exist after calculateDrawTransfo rms.
856 DCHECK(rootLayer->renderSurface()); 857 DCHECK(rootLayer->renderSurface());
857 } 858 }
858 859
859 static bool pointHitsRect(const gfx::PointF& screenSpacePoint, const WebTransfor mationMatrix& localSpaceToScreenSpaceTransform, gfx::RectF localSpaceRect) 860 static bool pointHitsRect(const gfx::PointF& screenSpacePoint, const Transform& localSpaceToScreenSpaceTransform, gfx::RectF localSpaceRect)
860 { 861 {
861 // If the transform is not invertible, then assume that this point doesn't h it this rect. 862 // If the transform is not invertible, then assume that this point doesn't h it this rect.
862 if (!localSpaceToScreenSpaceTransform.isInvertible()) 863 if (!localSpaceToScreenSpaceTransform.IsInvertible())
863 return false; 864 return false;
864 865
865 // Transform the hit test point from screen space to the local space of the given rect. 866 // Transform the hit test point from screen space to the local space of the given rect.
866 bool clipped = false; 867 bool clipped = false;
867 gfx::PointF hitTestPointInLocalSpace = MathUtil::projectPoint(localSpaceToSc reenSpaceTransform.inverse(), screenSpacePoint, clipped); 868 gfx::PointF hitTestPointInLocalSpace = MathUtil::projectPoint(MathUtil::inve rse(localSpaceToScreenSpaceTransform), screenSpacePoint, clipped);
868 869
869 // If projectPoint could not project to a valid value, then we assume that t his point doesn't hit this rect. 870 // If projectPoint could not project to a valid value, then we assume that t his point doesn't hit this rect.
870 if (clipped) 871 if (clipped)
871 return false; 872 return false;
872 873
873 return localSpaceRect.Contains(hitTestPointInLocalSpace); 874 return localSpaceRect.Contains(hitTestPointInLocalSpace);
874 } 875 }
875 876
876 static bool pointHitsRegion(gfx::PointF screenSpacePoint, const WebTransformatio nMatrix& screenSpaceTransform, const Region& layerSpaceRegion, float layerConten tScaleX, float layerContentScaleY) 877 static bool pointHitsRegion(gfx::PointF screenSpacePoint, const Transform& scree nSpaceTransform, const Region& layerSpaceRegion, float layerContentScaleX, float layerContentScaleY)
877 { 878 {
878 // If the transform is not invertible, then assume that this point doesn't h it this region. 879 // If the transform is not invertible, then assume that this point doesn't h it this region.
879 if (!screenSpaceTransform.isInvertible()) 880 if (!screenSpaceTransform.IsInvertible())
880 return false; 881 return false;
881 882
882 // Transform the hit test point from screen space to the local space of the given region. 883 // Transform the hit test point from screen space to the local space of the given region.
883 bool clipped = false; 884 bool clipped = false;
884 gfx::PointF hitTestPointInContentSpace = MathUtil::projectPoint(screenSpaceT ransform.inverse(), screenSpacePoint, clipped); 885 gfx::PointF hitTestPointInContentSpace = MathUtil::projectPoint(MathUtil::in verse(screenSpaceTransform), screenSpacePoint, clipped);
885 gfx::PointF hitTestPointInLayerSpace = gfx::ScalePoint(hitTestPointInContent Space, 1 / layerContentScaleX, 1 / layerContentScaleY); 886 gfx::PointF hitTestPointInLayerSpace = gfx::ScalePoint(hitTestPointInContent Space, 1 / layerContentScaleX, 1 / layerContentScaleY);
886 887
887 // If projectPoint could not project to a valid value, then we assume that t his point doesn't hit this region. 888 // If projectPoint could not project to a valid value, then we assume that t his point doesn't hit this region.
888 if (clipped) 889 if (clipped)
889 return false; 890 return false;
890 891
891 return layerSpaceRegion.Contains(gfx::ToRoundedPoint(hitTestPointInLayerSpac e)); 892 return layerSpaceRegion.Contains(gfx::ToRoundedPoint(hitTestPointInLayerSpac e));
892 } 893 }
893 894
894 static bool pointIsClippedBySurfaceOrClipRect(const gfx::PointF& screenSpacePoin t, LayerImpl* layer) 895 static bool pointIsClippedBySurfaceOrClipRect(const gfx::PointF& screenSpacePoin t, LayerImpl* layer)
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
973 974
974 foundLayer = currentLayer; 975 foundLayer = currentLayer;
975 break; 976 break;
976 } 977 }
977 978
978 // This can potentially return 0, which means the screenSpacePoint did not s uccessfully hit test any layers, not even the root layer. 979 // This can potentially return 0, which means the screenSpacePoint did not s uccessfully hit test any layers, not even the root layer.
979 return foundLayer; 980 return foundLayer;
980 } 981 }
981 982
982 } // namespace cc 983 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698