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

Side by Side Diff: cc/layer_tree_host_common.cc

Issue 11264056: cc: Use gfx:: Geometry types for positions, bounds, and related things. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: some missed intstuff 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 "config.h" 5 #include "config.h"
6 6
7 #include "cc/layer_tree_host_common.h" 7 #include "cc/layer_tree_host_common.h"
8 8
9 #include "FloatQuad.h" 9 #include "FloatQuad.h"
10 #include "IntRect.h"
11 #include "cc/layer.h" 10 #include "cc/layer.h"
12 #include "cc/layer_impl.h" 11 #include "cc/layer_impl.h"
13 #include "cc/layer_iterator.h" 12 #include "cc/layer_iterator.h"
14 #include "cc/layer_sorter.h" 13 #include "cc/layer_sorter.h"
15 #include "cc/math_util.h" 14 #include "cc/math_util.h"
16 #include "cc/render_surface.h" 15 #include "cc/render_surface.h"
17 #include "cc/render_surface_impl.h" 16 #include "cc/render_surface_impl.h"
17 #include "ui/gfx/rect_conversions.h"
18 #include <algorithm> 18 #include <algorithm>
19 #include <public/WebTransformationMatrix.h> 19 #include <public/WebTransformationMatrix.h>
20 20
21 using WebKit::WebTransformationMatrix; 21 using WebKit::WebTransformationMatrix;
22 22
23 namespace cc { 23 namespace cc {
24 24
25 ScrollAndScaleSet::ScrollAndScaleSet() 25 ScrollAndScaleSet::ScrollAndScaleSet()
26 { 26 {
27 } 27 }
28 28
29 ScrollAndScaleSet::~ScrollAndScaleSet() 29 ScrollAndScaleSet::~ScrollAndScaleSet()
30 { 30 {
31 } 31 }
32 32
33 IntRect LayerTreeHostCommon::calculateVisibleRect(const IntRect& targetSurfaceRe ct, const IntRect& layerBoundRect, const WebTransformationMatrix& transform) 33 gfx::Rect LayerTreeHostCommon::calculateVisibleRect(const gfx::Rect& targetSurfa ceRect, const gfx::Rect& layerBoundRect, const WebTransformationMatrix& transfor m)
34 { 34 {
35 // Is this layer fully contained within the target surface? 35 // Is this layer fully contained within the target surface?
36 IntRect layerInSurfaceSpace = MathUtil::mapClippedRect(transform, layerBound Rect); 36 gfx::Rect layerInSurfaceSpace = MathUtil::mapClippedRect(transform, layerBou ndRect);
37 if (targetSurfaceRect.contains(layerInSurfaceSpace)) 37 if (targetSurfaceRect.Contains(layerInSurfaceSpace))
38 return layerBoundRect; 38 return layerBoundRect;
39 39
40 // If the layer doesn't fill up the entire surface, then find the part of 40 // If the layer doesn't fill up the entire surface, then find the part of
41 // the surface rect where the layer could be visible. This avoids trying to 41 // the surface rect where the layer could be visible. This avoids trying to
42 // project surface rect points that are behind the projection point. 42 // project surface rect points that are behind the projection point.
43 IntRect minimalSurfaceRect = targetSurfaceRect; 43 gfx::Rect minimalSurfaceRect = targetSurfaceRect;
44 minimalSurfaceRect.intersect(layerInSurfaceSpace); 44 minimalSurfaceRect.Intersect(layerInSurfaceSpace);
45 45
46 // Project the corners of the target surface rect into the layer space. 46 // Project the corners of the target surface rect into the layer space.
47 // This bounding rectangle may be larger than it needs to be (being 47 // This bounding rectangle may be larger than it needs to be (being
48 // axis-aligned), but is a reasonable filter on the space to consider. 48 // axis-aligned), but is a reasonable filter on the space to consider.
49 // Non-invertible transforms will create an empty rect here. 49 // Non-invertible transforms will create an empty rect here.
50 const WebTransformationMatrix surfaceToLayer = transform.inverse(); 50 const WebTransformationMatrix surfaceToLayer = transform.inverse();
51 IntRect layerRect = enclosingIntRect(MathUtil::projectClippedRect(surfaceToL ayer, FloatRect(minimalSurfaceRect))); 51 gfx::Rect layerRect = gfx::ToEnclosingRect(MathUtil::projectClippedRect(surf aceToLayer, gfx::RectF(minimalSurfaceRect)));
52 layerRect.intersect(layerBoundRect); 52 layerRect.Intersect(layerBoundRect);
53 return layerRect; 53 return layerRect;
54 } 54 }
55 55
56 template<typename LayerType> 56 template<typename LayerType>
57 static inline bool layerIsInExisting3DRenderingContext(LayerType* layer) 57 static inline bool layerIsInExisting3DRenderingContext(LayerType* layer)
58 { 58 {
59 // According to current W3C spec on CSS transforms, a layer is part of an es tablished 59 // According to current W3C spec on CSS transforms, a layer is part of an es tablished
60 // 3d rendering context if its parent has transform-style of preserves-3d. 60 // 3d rendering context if its parent has transform-style of preserves-3d.
61 return layer->parent() && layer->parent()->preserves3D(); 61 return layer->parent() && layer->parent()->preserves3D();
62 } 62 }
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 return false; 103 return false;
104 } 104 }
105 105
106 template<typename LayerType> 106 template<typename LayerType>
107 static inline bool layerClipsSubtree(LayerType* layer) 107 static inline bool layerClipsSubtree(LayerType* layer)
108 { 108 {
109 return layer->masksToBounds() || layer->maskLayer(); 109 return layer->masksToBounds() || layer->maskLayer();
110 } 110 }
111 111
112 template<typename LayerType> 112 template<typename LayerType>
113 static IntRect calculateVisibleContentRect(LayerType* layer) 113 static gfx::Rect calculateVisibleContentRect(LayerType* layer)
114 { 114 {
115 DCHECK(layer->renderTarget()); 115 DCHECK(layer->renderTarget());
116 116
117 // Nothing is visible if the layer bounds are empty. 117 // Nothing is visible if the layer bounds are empty.
118 if (!layer->drawsContent() || layer->contentBounds().isEmpty() || layer->dra wableContentRect().isEmpty()) 118 if (!layer->drawsContent() || layer->contentBounds().IsEmpty() || layer->dra wableContentRect().IsEmpty())
119 return IntRect(); 119 return gfx::Rect();
120 120
121 IntRect targetSurfaceClipRect; 121 gfx::Rect targetSurfaceClipRect;
122 122
123 // First, compute visible bounds in target surface space. 123 // First, compute visible bounds in target surface space.
124 if (layer->renderTarget()->renderSurface()->clipRect().isEmpty()) 124 if (layer->renderTarget()->renderSurface()->clipRect().IsEmpty())
125 targetSurfaceClipRect = layer->drawableContentRect(); 125 targetSurfaceClipRect = layer->drawableContentRect();
126 else { 126 else {
127 // In this case the target surface does clip layers that contribute to i t. So, we 127 // In this case the target surface does clip layers that contribute to i t. So, we
128 // have convert the current surface's clipRect from its ancestor surface space to 128 // have convert the current surface's clipRect from its ancestor surface space to
129 // the current surface space. 129 // the current surface space.
130 targetSurfaceClipRect = enclosingIntRect(MathUtil::projectClippedRect(la yer->renderTarget()->renderSurface()->drawTransform().inverse(), layer->renderTa rget()->renderSurface()->clipRect())); 130 targetSurfaceClipRect = gfx::ToEnclosingRect(MathUtil::projectClippedRec t(layer->renderTarget()->renderSurface()->drawTransform().inverse(), layer->rend erTarget()->renderSurface()->clipRect()));
131 targetSurfaceClipRect.intersect(layer->drawableContentRect()); 131 targetSurfaceClipRect.Intersect(layer->drawableContentRect());
132 } 132 }
133 133
134 if (targetSurfaceClipRect.isEmpty()) 134 if (targetSurfaceClipRect.IsEmpty())
135 return IntRect(); 135 return gfx::Rect();
136 136
137 return LayerTreeHostCommon::calculateVisibleRect(targetSurfaceClipRect, IntR ect(IntPoint(), layer->contentBounds()), layer->drawTransform()); 137 return LayerTreeHostCommon::calculateVisibleRect(targetSurfaceClipRect, gfx: :Rect(gfx::Point(), layer->contentBounds()), layer->drawTransform());
138 } 138 }
139 139
140 static bool isScaleOrTranslation(const WebTransformationMatrix& m) 140 static bool isScaleOrTranslation(const WebTransformationMatrix& m)
141 { 141 {
142 return !m.m12() && !m.m13() && !m.m14() 142 return !m.m12() && !m.m13() && !m.m14()
143 && !m.m21() && !m.m23() && !m.m24() 143 && !m.m21() && !m.m23() && !m.m24()
144 && !m.m31() && !m.m32() && !m.m43() 144 && !m.m31() && !m.m32() && !m.m43()
145 && m.m44(); 145 && m.m44();
146 } 146 }
147 147
(...skipping 27 matching lines...) Expand all
175 // - the layer is not double-sided, but its back face is visible. 175 // - the layer is not double-sided, but its back face is visible.
176 // 176 //
177 // Some additional conditions need to be computed at a later point after the recursion is finished. 177 // Some additional conditions need to be computed at a later point after the recursion is finished.
178 // - the intersection of render surface content and layer clipRect is empt y 178 // - the intersection of render surface content and layer clipRect is empt y
179 // - the visibleContentRect is empty 179 // - the visibleContentRect is empty
180 // 180 //
181 // Note, if the layer should not have been drawn due to being fully transpar ent, 181 // Note, if the layer should not have been drawn due to being fully transpar ent,
182 // we would have skipped the entire subtree and never made it into this func tion, 182 // we would have skipped the entire subtree and never made it into this func tion,
183 // so it is safe to omit this check here. 183 // so it is safe to omit this check here.
184 184
185 if (!layer->drawsContent() || layer->bounds().isEmpty()) 185 if (!layer->drawsContent() || layer->bounds().IsEmpty())
186 return true; 186 return true;
187 187
188 LayerType* backfaceTestLayer = layer; 188 LayerType* backfaceTestLayer = layer;
189 if (layer->useParentBackfaceVisibility()) { 189 if (layer->useParentBackfaceVisibility()) {
190 DCHECK(layer->parent()); 190 DCHECK(layer->parent());
191 DCHECK(!layer->parent()->useParentBackfaceVisibility()); 191 DCHECK(!layer->parent()->useParentBackfaceVisibility());
192 backfaceTestLayer = layer->parent(); 192 backfaceTestLayer = layer->parent();
193 } 193 }
194 194
195 // The layer should not be drawn if (1) it is not double-sided and (2) the b ack of the layer is known to be facing the screen. 195 // The layer should not be drawn if (1) it is not double-sided and (2) the b ack of the layer is known to be facing the screen.
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 // There is no contentsScale on impl thread. 347 // There is no contentsScale on impl thread.
348 static inline void updateLayerContentsScale(LayerImpl*, const WebTransformationM atrix&, float, float) { } 348 static inline void updateLayerContentsScale(LayerImpl*, const WebTransformationM atrix&, float, float) { }
349 349
350 static inline void updateLayerContentsScale(Layer* layer, const WebTransformatio nMatrix& combinedTransform, float deviceScaleFactor, float pageScaleFactor) 350 static inline void updateLayerContentsScale(Layer* layer, const WebTransformatio nMatrix& combinedTransform, float deviceScaleFactor, float pageScaleFactor)
351 { 351 {
352 float rasterScale = layer->rasterScale(); 352 float rasterScale = layer->rasterScale();
353 if (!rasterScale) { 353 if (!rasterScale) {
354 rasterScale = 1; 354 rasterScale = 1;
355 355
356 if (layer->automaticallyComputeRasterScale()) { 356 if (layer->automaticallyComputeRasterScale()) {
357 FloatPoint transformScale = MathUtil::computeTransform2dScaleCompone nts(combinedTransform); 357 gfx::PointF transformScale = MathUtil::computeTransform2dScaleCompon ents(combinedTransform);
358 float combinedScale = std::max(transformScale.x(), transformScale.y( )); 358 float combinedScale = std::max(transformScale.x(), transformScale.y( ));
359 rasterScale = combinedScale / deviceScaleFactor; 359 rasterScale = combinedScale / deviceScaleFactor;
360 if (!layer->boundsContainPageScale()) 360 if (!layer->boundsContainPageScale())
361 rasterScale /= pageScaleFactor; 361 rasterScale /= pageScaleFactor;
362 layer->setRasterScale(rasterScale); 362 layer->setRasterScale(rasterScale);
363 } 363 }
364 } 364 }
365 365
366 float contentsScale = rasterScale * deviceScaleFactor; 366 float contentsScale = rasterScale * deviceScaleFactor;
367 if (!layer->boundsContainPageScale()) 367 if (!layer->boundsContainPageScale())
368 contentsScale *= pageScaleFactor; 368 contentsScale *= pageScaleFactor;
369 layer->setContentsScale(contentsScale); 369 layer->setContentsScale(contentsScale);
370 370
371 Layer* maskLayer = layer->maskLayer(); 371 Layer* maskLayer = layer->maskLayer();
372 if (maskLayer) 372 if (maskLayer)
373 maskLayer->setContentsScale(contentsScale); 373 maskLayer->setContentsScale(contentsScale);
374 374
375 Layer* replicaMaskLayer = layer->replicaLayer() ? layer->replicaLayer()->mas kLayer() : 0; 375 Layer* replicaMaskLayer = layer->replicaLayer() ? layer->replicaLayer()->mas kLayer() : 0;
376 if (replicaMaskLayer) 376 if (replicaMaskLayer)
377 replicaMaskLayer->setContentsScale(contentsScale); 377 replicaMaskLayer->setContentsScale(contentsScale);
378 } 378 }
379 379
380 // Should be called just before the recursive calculateDrawTransformsInternal(). 380 // Should be called just before the recursive calculateDrawTransformsInternal().
381 template<typename LayerType, typename LayerList> 381 template<typename LayerType, typename LayerList>
382 void setupRootLayerAndSurfaceForRecursion(LayerType* rootLayer, LayerList& rende rSurfaceLayerList, const IntSize& deviceViewportSize) 382 void setupRootLayerAndSurfaceForRecursion(LayerType* rootLayer, LayerList& rende rSurfaceLayerList, const gfx::Size& deviceViewportSize)
383 { 383 {
384 if (!rootLayer->renderSurface()) 384 if (!rootLayer->renderSurface())
385 rootLayer->createRenderSurface(); 385 rootLayer->createRenderSurface();
386 386
387 rootLayer->renderSurface()->setContentRect(IntRect(IntPoint::zero(), deviceV iewportSize)); 387 rootLayer->renderSurface()->setContentRect(gfx::Rect(gfx::Point(), deviceVie wportSize));
388 rootLayer->renderSurface()->clearLayerLists(); 388 rootLayer->renderSurface()->clearLayerLists();
389 389
390 DCHECK(renderSurfaceLayerList.empty()); 390 DCHECK(renderSurfaceLayerList.empty());
391 renderSurfaceLayerList.push_back(rootLayer); 391 renderSurfaceLayerList.push_back(rootLayer);
392 } 392 }
393 393
394 // Recursively walks the layer tree starting at the given node and computes all the 394 // Recursively walks the layer tree starting at the given node and computes all the
395 // necessary transformations, clipRects, render surfaces, etc. 395 // necessary transformations, clipRects, render surfaces, etc.
396 template<typename LayerType, typename LayerList, typename RenderSurfaceType, typ ename LayerSorter> 396 template<typename LayerType, typename LayerList, typename RenderSurfaceType, typ ename LayerSorter>
397 static void calculateDrawTransformsInternal(LayerType* layer, LayerType* rootLay er, const WebTransformationMatrix& parentMatrix, 397 static void calculateDrawTransformsInternal(LayerType* layer, LayerType* rootLay er, const WebTransformationMatrix& parentMatrix,
398 const WebTransformationMatrix& fullHierarchyMatrix, const WebTransformationM atrix& currentScrollCompensationMatrix, 398 const WebTransformationMatrix& fullHierarchyMatrix, const WebTransformationM atrix& currentScrollCompensationMatrix,
399 const IntRect& clipRectFromAncestor, bool ancestorClipsSubtree, 399 const gfx::Rect& clipRectFromAncestor, bool ancestorClipsSubtree,
400 RenderSurfaceType* nearestAncestorThatMovesPixels, LayerList& renderSurfaceL ayerList, LayerList& layerList, 400 RenderSurfaceType* nearestAncestorThatMovesPixels, LayerList& renderSurfaceL ayerList, LayerList& layerList,
401 LayerSorter* layerSorter, int maxTextureSize, float deviceScaleFactor, float pageScaleFactor, IntRect& drawableContentRectOfSubtree) 401 LayerSorter* layerSorter, int maxTextureSize, float deviceScaleFactor, float pageScaleFactor, gfx::Rect& drawableContentRectOfSubtree)
402 { 402 {
403 // This function computes the new matrix transformations recursively for thi s 403 // This function computes the new matrix transformations recursively for thi s
404 // layer and all its descendants. It also computes the appropriate render su rfaces. 404 // layer and all its descendants. It also computes the appropriate render su rfaces.
405 // Some important points to remember: 405 // Some important points to remember:
406 // 406 //
407 // 0. Here, transforms are notated in Matrix x Vector order, and in words we describe what 407 // 0. Here, transforms are notated in Matrix x Vector order, and in words we describe what
408 // the transform does from left to right. 408 // the transform does from left to right.
409 // 409 //
410 // 1. In our terminology, the "layer origin" refers to the top-left corner o f a layer, and the 410 // 1. In our terminology, the "layer origin" refers to the top-left corner o f a layer, and the
411 // positive Y-axis points downwards. This interpretation is valid because the orthographic 411 // positive Y-axis points downwards. This interpretation is valid because the orthographic
412 // projection applied at draw time flips the Y axis appropriately. 412 // projection applied at draw time flips the Y axis appropriately.
413 // 413 //
414 // 2. The anchor point, when given as a FloatPoint object, is specified in " unit layer space", 414 // 2. The anchor point, when given as a PointF object, is specified in "unit layer space",
415 // where the bounds of the layer map to [0, 1]. However, as a WebTransfor mationMatrix object, 415 // where the bounds of the layer map to [0, 1]. However, as a WebTransfor mationMatrix object,
416 // the transform to the anchor point is specified in "layer space", where the bounds 416 // the transform to the anchor point is specified in "layer space", where the bounds
417 // of the layer map to [bounds.width(), bounds.height()]. 417 // of the layer map to [bounds.width(), bounds.height()].
418 // 418 //
419 // 3. Definition of various transforms used: 419 // 3. Definition of various transforms used:
420 // M[parent] is the parent matrix, with respect to the nearest render surface, passed down recursively. 420 // M[parent] is the parent matrix, with respect to the nearest render surface, passed down recursively.
421 // M[root] is the full hierarchy, with respect to the root, passed do wn recursively. 421 // M[root] is the full hierarchy, with respect to the root, passed do wn recursively.
422 // Tr[origin] is the translation matrix from the parent's origin to t his layer's origin. 422 // Tr[origin] is the translation matrix from the parent's origin to t his layer's origin.
423 // Tr[origin2anchor] is the translation from the layer's origin to it s anchor point 423 // Tr[origin2anchor] is the translation from the layer's origin to it s anchor point
424 // Tr[origin2center] is the translation from the layer's origin to it s center 424 // Tr[origin2center] is the translation from the layer's origin to it s center
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
476 // M[surface2root] = M[owningLayer->screenspace] * S[deviceScale].in verse() 476 // M[surface2root] = M[owningLayer->screenspace] * S[deviceScale].in verse()
477 // 477 //
478 // The replica draw transform to its target surface origin is: 478 // The replica draw transform to its target surface origin is:
479 // M[replicaDraw] = S[deviceScale] * M[surfaceDraw] * Tr[replica->pos ition() + replica->anchor()] * Tr[replica] * Tr[origin2anchor].inverse() * S[con tentsScale].inverse() 479 // M[replicaDraw] = S[deviceScale] * M[surfaceDraw] * Tr[replica->pos ition() + replica->anchor()] * Tr[replica] * Tr[origin2anchor].inverse() * S[con tentsScale].inverse()
480 // 480 //
481 // The replica draw transform to the root (screen space) origin is: 481 // The replica draw transform to the root (screen space) origin is:
482 // M[replica2root] = M[surface2root] * Tr[replica->position()] * Tr[r eplica] * Tr[origin2anchor].inverse() 482 // M[replica2root] = M[surface2root] * Tr[replica->position()] * Tr[r eplica] * Tr[origin2anchor].inverse()
483 // 483 //
484 484
485 // If we early-exit anywhere in this function, the drawableContentRect of th is subtree should be considered empty. 485 // If we early-exit anywhere in this function, the drawableContentRect of th is subtree should be considered empty.
486 drawableContentRectOfSubtree = IntRect(); 486 drawableContentRectOfSubtree = gfx::Rect();
487 487
488 if (subtreeShouldBeSkipped(layer)) 488 if (subtreeShouldBeSkipped(layer))
489 return; 489 return;
490 490
491 IntRect clipRectForSubtree; 491 gfx::Rect clipRectForSubtree;
492 bool subtreeShouldBeClipped = false; 492 bool subtreeShouldBeClipped = false;
493 493
494 float drawOpacity = layer->opacity(); 494 float drawOpacity = layer->opacity();
495 bool drawOpacityIsAnimating = layer->opacityIsAnimating(); 495 bool drawOpacityIsAnimating = layer->opacityIsAnimating();
496 if (layer->parent() && layer->parent()->preserves3D()) { 496 if (layer->parent() && layer->parent()->preserves3D()) {
497 drawOpacity *= layer->parent()->drawOpacity(); 497 drawOpacity *= layer->parent()->drawOpacity();
498 drawOpacityIsAnimating |= layer->parent()->drawOpacityIsAnimating(); 498 drawOpacityIsAnimating |= layer->parent()->drawOpacityIsAnimating();
499 } 499 }
500 500
501 IntSize bounds = layer->bounds(); 501 gfx::Size bounds = layer->bounds();
502 FloatPoint anchorPoint = layer->anchorPoint(); 502 gfx::PointF anchorPoint = layer->anchorPoint();
503 FloatPoint position = layer->position() - layer->scrollDelta(); 503 gfx::PointF position = layer->position() - gfx::Vector2d(layer->scrollDelta( ).width(), layer->scrollDelta().height());
504 504
505 WebTransformationMatrix layerLocalTransform; 505 WebTransformationMatrix layerLocalTransform;
506 // LT = Tr[origin] * Tr[origin2anchor] 506 // LT = Tr[origin] * Tr[origin2anchor]
507 layerLocalTransform.translate3d(position.x() + anchorPoint.x() * bounds.widt h(), position.y() + anchorPoint.y() * bounds.height(), layer->anchorPointZ()); 507 layerLocalTransform.translate3d(position.x() + anchorPoint.x() * bounds.widt h(), position.y() + anchorPoint.y() * bounds.height(), layer->anchorPointZ());
508 // LT = Tr[origin] * Tr[origin2anchor] * M[layer] 508 // LT = Tr[origin] * Tr[origin2anchor] * M[layer]
509 layerLocalTransform.multiply(layer->transform()); 509 layerLocalTransform.multiply(layer->transform());
510 // LT = Tr[origin] * Tr[origin2anchor] * M[layer] * Tr[anchor2origin] 510 // LT = Tr[origin] * Tr[origin2anchor] * M[layer] * Tr[anchor2origin]
511 layerLocalTransform.translate3d(-anchorPoint.x() * bounds.width(), -anchorPo int.y() * bounds.height(), -layer->anchorPointZ()); 511 layerLocalTransform.translate3d(-anchorPoint.x() * bounds.width(), -anchorPo int.y() * bounds.height(), -layer->anchorPointZ());
512 512
513 WebTransformationMatrix combinedTransform = parentMatrix; 513 WebTransformationMatrix combinedTransform = parentMatrix;
(...skipping 10 matching lines...) Expand all
524 if (layer->fixedToContainerLayer()) { 524 if (layer->fixedToContainerLayer()) {
525 // Special case: this layer is a composited fixed-position layer; we nee d to 525 // Special case: this layer is a composited fixed-position layer; we nee d to
526 // explicitly compensate for all ancestors' nonzero scrollDeltas to keep this layer 526 // explicitly compensate for all ancestors' nonzero scrollDeltas to keep this layer
527 // fixed correctly. 527 // fixed correctly.
528 combinedTransform = currentScrollCompensationMatrix * combinedTransform; 528 combinedTransform = currentScrollCompensationMatrix * combinedTransform;
529 } 529 }
530 530
531 // The drawTransform that gets computed below is effectively the layer's dra wTransform, unless 531 // The drawTransform that gets computed below is effectively the layer's dra wTransform, unless
532 // the layer itself creates a renderSurface. In that case, the renderSurface re-parents the transforms. 532 // the layer itself creates a renderSurface. In that case, the renderSurface re-parents the transforms.
533 WebTransformationMatrix drawTransform = combinedTransform; 533 WebTransformationMatrix drawTransform = combinedTransform;
534 if (!layer->contentBounds().isEmpty() && !layer->bounds().isEmpty()) { 534 if (!layer->contentBounds().IsEmpty() && !layer->bounds().IsEmpty()) {
535 // M[draw] = M[parent] * LT * S[layer2content] 535 // M[draw] = M[parent] * LT * S[layer2content]
536 drawTransform.scaleNonUniform(layer->bounds().width() / static_cast<doub le>(layer->contentBounds().width()), 536 drawTransform.scaleNonUniform(layer->bounds().width() / static_cast<doub le>(layer->contentBounds().width()),
537 layer->bounds().height() / static_cast<dou ble>(layer->contentBounds().height())); 537 layer->bounds().height() / static_cast<dou ble>(layer->contentBounds().height()));
538 } 538 }
539 539
540 // layerScreenSpaceTransform represents the transform between root layer's " screen space" and local content space. 540 // layerScreenSpaceTransform represents the transform between root layer's " screen space" and local content space.
541 WebTransformationMatrix layerScreenSpaceTransform = fullHierarchyMatrix; 541 WebTransformationMatrix layerScreenSpaceTransform = fullHierarchyMatrix;
542 if (!layer->preserves3D()) 542 if (!layer->preserves3D())
543 MathUtil::flattenTransformTo2d(layerScreenSpaceTransform); 543 MathUtil::flattenTransformTo2d(layerScreenSpaceTransform);
544 layerScreenSpaceTransform.multiply(drawTransform); 544 layerScreenSpaceTransform.multiply(drawTransform);
545 layer->setScreenSpaceTransform(layerScreenSpaceTransform); 545 layer->setScreenSpaceTransform(layerScreenSpaceTransform);
546 546
547 bool animatingTransformToTarget = layer->transformIsAnimating(); 547 bool animatingTransformToTarget = layer->transformIsAnimating();
548 bool animatingTransformToScreen = animatingTransformToTarget; 548 bool animatingTransformToScreen = animatingTransformToTarget;
549 if (layer->parent()) { 549 if (layer->parent()) {
550 animatingTransformToTarget |= layer->parent()->drawTransformIsAnimating( ); 550 animatingTransformToTarget |= layer->parent()->drawTransformIsAnimating( );
551 animatingTransformToScreen |= layer->parent()->screenSpaceTransformIsAni mating(); 551 animatingTransformToScreen |= layer->parent()->screenSpaceTransformIsAni mating();
552 } 552 }
553 553
554 FloatRect contentRect(FloatPoint(), layer->contentBounds()); 554 gfx::RectF contentRect(gfx::PointF(), layer->contentBounds());
555 555
556 // fullHierarchyMatrix is the matrix that transforms objects between screen space (except projection matrix) and the most recent RenderSurfaceImpl's space. 556 // fullHierarchyMatrix is the matrix that transforms objects between screen space (except projection matrix) and the most recent RenderSurfaceImpl's space.
557 // nextHierarchyMatrix will only change if this layer uses a new RenderSurfa ceImpl, otherwise remains the same. 557 // nextHierarchyMatrix will only change if this layer uses a new RenderSurfa ceImpl, otherwise remains the same.
558 WebTransformationMatrix nextHierarchyMatrix = fullHierarchyMatrix; 558 WebTransformationMatrix nextHierarchyMatrix = fullHierarchyMatrix;
559 WebTransformationMatrix sublayerMatrix; 559 WebTransformationMatrix sublayerMatrix;
560 560
561 FloatPoint renderSurfaceSublayerScale = MathUtil::computeTransform2dScaleCom ponents(combinedTransform); 561 gfx::PointF renderSurfaceSublayerScale = MathUtil::computeTransform2dScaleCo mponents(combinedTransform);
562 562
563 if (subtreeShouldRenderToSeparateSurface(layer, isScaleOrTranslation(combine dTransform))) { 563 if (subtreeShouldRenderToSeparateSurface(layer, isScaleOrTranslation(combine dTransform))) {
564 // Check back-face visibility before continuing with this surface and it s subtree 564 // Check back-face visibility before continuing with this surface and it s subtree
565 if (!layer->doubleSided() && transformToParentIsKnown(layer) && isSurfac eBackFaceVisible(layer, combinedTransform)) 565 if (!layer->doubleSided() && transformToParentIsKnown(layer) && isSurfac eBackFaceVisible(layer, combinedTransform))
566 return; 566 return;
567 567
568 if (!layer->renderSurface()) 568 if (!layer->renderSurface())
569 layer->createRenderSurface(); 569 layer->createRenderSurface();
570 570
571 RenderSurfaceType* renderSurface = layer->renderSurface(); 571 RenderSurfaceType* renderSurface = layer->renderSurface();
572 renderSurface->clearLayerLists(); 572 renderSurface->clearLayerLists();
573 573
574 // The owning layer's draw transform has a scale from content to layer s pace which we need to undo and 574 // The owning layer's draw transform has a scale from content to layer s pace which we need to undo and
575 // replace with a scale from the surface's subtree into layer space. 575 // replace with a scale from the surface's subtree into layer space.
576 if (!layer->contentBounds().isEmpty() && !layer->bounds().isEmpty()) { 576 if (!layer->contentBounds().IsEmpty() && !layer->bounds().IsEmpty()) {
577 drawTransform.scaleNonUniform(layer->contentBounds().width() / stati c_cast<double>(layer->bounds().width()), 577 drawTransform.scaleNonUniform(layer->contentBounds().width() / stati c_cast<double>(layer->bounds().width()),
578 layer->contentBounds().height() / stat ic_cast<double>(layer->bounds().height())); 578 layer->contentBounds().height() / stat ic_cast<double>(layer->bounds().height()));
579 } 579 }
580 drawTransform.scaleNonUniform(1 / renderSurfaceSublayerScale.x(), 1 / re nderSurfaceSublayerScale.y()); 580 drawTransform.scaleNonUniform(1 / renderSurfaceSublayerScale.x(), 1 / re nderSurfaceSublayerScale.y());
581 renderSurface->setDrawTransform(drawTransform); 581 renderSurface->setDrawTransform(drawTransform);
582 582
583 // The origin of the new surface is the upper left corner of the layer. 583 // The origin of the new surface is the upper left corner of the layer.
584 WebTransformationMatrix layerDrawTransform; 584 WebTransformationMatrix layerDrawTransform;
585 layerDrawTransform.scaleNonUniform(renderSurfaceSublayerScale.x(), rende rSurfaceSublayerScale.y()); 585 layerDrawTransform.scaleNonUniform(renderSurfaceSublayerScale.x(), rende rSurfaceSublayerScale.y());
586 if (!layer->contentBounds().isEmpty() && !layer->bounds().isEmpty()) { 586 if (!layer->contentBounds().IsEmpty() && !layer->bounds().IsEmpty()) {
587 layerDrawTransform.scaleNonUniform(layer->bounds().width() / static_ cast<double>(layer->contentBounds().width()), 587 layerDrawTransform.scaleNonUniform(layer->bounds().width() / static_ cast<double>(layer->contentBounds().width()),
588 layer->bounds().height() / static _cast<double>(layer->contentBounds().height())); 588 layer->bounds().height() / static _cast<double>(layer->contentBounds().height()));
589 } 589 }
590 layer->setDrawTransform(layerDrawTransform); 590 layer->setDrawTransform(layerDrawTransform);
591 591
592 // Inside the surface's subtree, we scale everything to the owning layer 's scale. 592 // Inside the surface's subtree, we scale everything to the owning layer 's scale.
593 // The sublayer matrix transforms centered layer rects into target 593 // The sublayer matrix transforms centered layer rects into target
594 // surface content space. 594 // surface content space.
595 sublayerMatrix.makeIdentity(); 595 sublayerMatrix.makeIdentity();
596 sublayerMatrix.scaleNonUniform(renderSurfaceSublayerScale.x(), renderSur faceSublayerScale.y()); 596 sublayerMatrix.scaleNonUniform(renderSurfaceSublayerScale.x(), renderSur faceSublayerScale.y());
(...skipping 15 matching lines...) Expand all
612 nextHierarchyMatrix.multiply(renderSurface->drawTransform()); 612 nextHierarchyMatrix.multiply(renderSurface->drawTransform());
613 613
614 // The new renderSurface here will correctly clip the entire subtree. So , we do 614 // The new renderSurface here will correctly clip the entire subtree. So , we do
615 // not need to continue propagating the clipping state further down the tree. This 615 // not need to continue propagating the clipping state further down the tree. This
616 // way, we can avoid transforming clipRects from ancestor target surface space to 616 // way, we can avoid transforming clipRects from ancestor target surface space to
617 // current target surface space that could cause more w < 0 headaches. 617 // current target surface space that could cause more w < 0 headaches.
618 subtreeShouldBeClipped = false; 618 subtreeShouldBeClipped = false;
619 619
620 if (layer->maskLayer()) { 620 if (layer->maskLayer()) {
621 layer->maskLayer()->setRenderTarget(layer); 621 layer->maskLayer()->setRenderTarget(layer);
622 layer->maskLayer()->setVisibleContentRect(IntRect(IntPoint(), layer- >contentBounds())); 622 layer->maskLayer()->setVisibleContentRect(gfx::Rect(gfx::Point(), la yer->contentBounds()));
623 } 623 }
624 624
625 if (layer->replicaLayer() && layer->replicaLayer()->maskLayer()) { 625 if (layer->replicaLayer() && layer->replicaLayer()->maskLayer()) {
626 layer->replicaLayer()->maskLayer()->setRenderTarget(layer); 626 layer->replicaLayer()->maskLayer()->setRenderTarget(layer);
627 layer->replicaLayer()->maskLayer()->setVisibleContentRect(IntRect(In tPoint(), layer->contentBounds())); 627 layer->replicaLayer()->maskLayer()->setVisibleContentRect(gfx::Rect( gfx::Point(), layer->contentBounds()));
628 } 628 }
629 629
630 // FIXME: make this smarter for the SkImageFilter case (check for 630 // FIXME: make this smarter for the SkImageFilter case (check for
631 // pixel-moving filters) 631 // pixel-moving filters)
632 if (layer->filters().hasFilterThatMovesPixels() || layer->filter()) 632 if (layer->filters().hasFilterThatMovesPixels() || layer->filter())
633 nearestAncestorThatMovesPixels = renderSurface; 633 nearestAncestorThatMovesPixels = renderSurface;
634 634
635 // The render surface clipRect is expressed in the space where this surf ace draws, i.e. the same space as clipRectFromAncestor. 635 // The render surface clipRect is expressed in the space where this surf ace draws, i.e. the same space as clipRectFromAncestor.
636 if (ancestorClipsSubtree) 636 if (ancestorClipsSubtree)
637 renderSurface->setClipRect(clipRectFromAncestor); 637 renderSurface->setClipRect(clipRectFromAncestor);
638 else 638 else
639 renderSurface->setClipRect(IntRect()); 639 renderSurface->setClipRect(gfx::Rect());
640 640
641 renderSurface->setNearestAncestorThatMovesPixels(nearestAncestorThatMove sPixels); 641 renderSurface->setNearestAncestorThatMovesPixels(nearestAncestorThatMove sPixels);
642 642
643 renderSurfaceLayerList.push_back(layer); 643 renderSurfaceLayerList.push_back(layer);
644 } else { 644 } else {
645 layer->setDrawTransform(drawTransform); 645 layer->setDrawTransform(drawTransform);
646 layer->setDrawTransformIsAnimating(animatingTransformToTarget); 646 layer->setDrawTransformIsAnimating(animatingTransformToTarget);
647 layer->setScreenSpaceTransformIsAnimating(animatingTransformToScreen); 647 layer->setScreenSpaceTransformIsAnimating(animatingTransformToScreen);
648 sublayerMatrix = combinedTransform; 648 sublayerMatrix = combinedTransform;
649 649
(...skipping 14 matching lines...) Expand all
664 } else { 664 } else {
665 // FIXME: This root layer special case code should eventually go awa y. https://bugs.webkit.org/show_bug.cgi?id=92290 665 // FIXME: This root layer special case code should eventually go awa y. https://bugs.webkit.org/show_bug.cgi?id=92290
666 DCHECK(!layer->parent()); 666 DCHECK(!layer->parent());
667 DCHECK(layer->renderSurface()); 667 DCHECK(layer->renderSurface());
668 DCHECK(ancestorClipsSubtree); 668 DCHECK(ancestorClipsSubtree);
669 layer->renderSurface()->setClipRect(clipRectFromAncestor); 669 layer->renderSurface()->setClipRect(clipRectFromAncestor);
670 subtreeShouldBeClipped = false; 670 subtreeShouldBeClipped = false;
671 } 671 }
672 } 672 }
673 673
674 IntRect rectInTargetSpace = enclosingIntRect(MathUtil::mapClippedRect(layer- >drawTransform(), contentRect)); 674 gfx::Rect rectInTargetSpace = ToEnclosingRect(MathUtil::mapClippedRect(layer ->drawTransform(), contentRect));
675 675
676 if (layerClipsSubtree(layer)) { 676 if (layerClipsSubtree(layer)) {
677 subtreeShouldBeClipped = true; 677 subtreeShouldBeClipped = true;
678 if (ancestorClipsSubtree && !layer->renderSurface()) { 678 if (ancestorClipsSubtree && !layer->renderSurface()) {
679 clipRectForSubtree = clipRectFromAncestor; 679 clipRectForSubtree = clipRectFromAncestor;
680 clipRectForSubtree.intersect(rectInTargetSpace); 680 clipRectForSubtree.Intersect(rectInTargetSpace);
681 } else 681 } else
682 clipRectForSubtree = rectInTargetSpace; 682 clipRectForSubtree = rectInTargetSpace;
683 } 683 }
684 684
685 // Flatten to 2D if the layer doesn't preserve 3D. 685 // Flatten to 2D if the layer doesn't preserve 3D.
686 if (!layer->preserves3D()) 686 if (!layer->preserves3D())
687 MathUtil::flattenTransformTo2d(sublayerMatrix); 687 MathUtil::flattenTransformTo2d(sublayerMatrix);
688 688
689 // Apply the sublayer transform at the center of the layer. 689 // Apply the sublayer transform at the center of the layer.
690 sublayerMatrix.translate(0.5 * bounds.width(), 0.5 * bounds.height()); 690 sublayerMatrix.translate(0.5 * bounds.width(), 0.5 * bounds.height());
691 sublayerMatrix.multiply(layer->sublayerTransform()); 691 sublayerMatrix.multiply(layer->sublayerTransform());
692 sublayerMatrix.translate(-0.5 * bounds.width(), -0.5 * bounds.height()); 692 sublayerMatrix.translate(-0.5 * bounds.width(), -0.5 * bounds.height());
693 693
694 LayerList& descendants = (layer->renderSurface() ? layer->renderSurface()->l ayerList() : layerList); 694 LayerList& descendants = (layer->renderSurface() ? layer->renderSurface()->l ayerList() : layerList);
695 695
696 // Any layers that are appended after this point are in the layer's subtree and should be included in the sorting process. 696 // Any layers that are appended after this point are in the layer's subtree and should be included in the sorting process.
697 unsigned sortingStartIndex = descendants.size(); 697 unsigned sortingStartIndex = descendants.size();
698 698
699 if (!layerShouldBeSkipped(layer)) 699 if (!layerShouldBeSkipped(layer))
700 descendants.push_back(layer); 700 descendants.push_back(layer);
701 701
702 WebTransformationMatrix nextScrollCompensationMatrix = computeScrollCompensa tionMatrixForChildren(layer, parentMatrix, currentScrollCompensationMatrix);; 702 WebTransformationMatrix nextScrollCompensationMatrix = computeScrollCompensa tionMatrixForChildren(layer, parentMatrix, currentScrollCompensationMatrix);;
703 703
704 IntRect accumulatedDrawableContentRectOfChildren; 704 gfx::Rect accumulatedDrawableContentRectOfChildren;
705 for (size_t i = 0; i < layer->children().size(); ++i) { 705 for (size_t i = 0; i < layer->children().size(); ++i) {
706 LayerType* child = LayerTreeHostCommon::getChildAsRawPtr(layer->children (), i); 706 LayerType* child = LayerTreeHostCommon::getChildAsRawPtr(layer->children (), i);
707 IntRect drawableContentRectOfChildSubtree; 707 gfx::Rect drawableContentRectOfChildSubtree;
708 calculateDrawTransformsInternal<LayerType, LayerList, RenderSurfaceType, LayerSorter>(child, rootLayer, sublayerMatrix, nextHierarchyMatrix, nextScrollC ompensationMatrix, 708 calculateDrawTransformsInternal<LayerType, LayerList, RenderSurfaceType, LayerSorter>(child, rootLayer, sublayerMatrix, nextHierarchyMatrix, nextScrollC ompensationMatrix,
709 clipRectForSubtree, subtreeShouldBeClipped, nearestAncestorThatMov esPixels, 709 clipRectForSubtree, subtreeShouldBeClipped, nearestAncestorThatMov esPixels,
710 renderSurfaceLayerList, descendants, layerSorter, maxTextureSize, deviceScaleFactor, pageScaleFactor, drawableContentRectOfChildSubtree); 710 renderSurfaceLayerList, descendants, layerSorter, maxTextureSize, deviceScaleFactor, pageScaleFactor, drawableContentRectOfChildSubtree);
711 if (!drawableContentRectOfChildSubtree.isEmpty()) { 711 if (!drawableContentRectOfChildSubtree.IsEmpty()) {
712 accumulatedDrawableContentRectOfChildren.unite(drawableContentRectOf ChildSubtree); 712 accumulatedDrawableContentRectOfChildren.Union(drawableContentRectOf ChildSubtree);
713 if (child->renderSurface()) 713 if (child->renderSurface())
714 descendants.push_back(child); 714 descendants.push_back(child);
715 } 715 }
716 } 716 }
717 717
718 // Compute the total drawableContentRect for this subtree (the rect is in ta rgetSurface space) 718 // Compute the total drawableContentRect for this subtree (the rect is in ta rgetSurface space)
719 IntRect localDrawableContentRectOfSubtree = accumulatedDrawableContentRectOf Children; 719 gfx::Rect localDrawableContentRectOfSubtree = accumulatedDrawableContentRect OfChildren;
720 if (layer->drawsContent()) 720 if (layer->drawsContent())
721 localDrawableContentRectOfSubtree.unite(rectInTargetSpace); 721 localDrawableContentRectOfSubtree.Union(rectInTargetSpace);
722 if (subtreeShouldBeClipped) 722 if (subtreeShouldBeClipped)
723 localDrawableContentRectOfSubtree.intersect(clipRectForSubtree); 723 localDrawableContentRectOfSubtree.Intersect(clipRectForSubtree);
724 724
725 // Compute the layer's drawable content rect (the rect is in targetSurface s pace) 725 // Compute the layer's drawable content rect (the rect is in targetSurface s pace)
726 IntRect drawableContentRectOfLayer = rectInTargetSpace; 726 gfx::Rect drawableContentRectOfLayer = rectInTargetSpace;
727 if (subtreeShouldBeClipped) 727 if (subtreeShouldBeClipped)
728 drawableContentRectOfLayer.intersect(clipRectForSubtree); 728 drawableContentRectOfLayer.Intersect(clipRectForSubtree);
729 layer->setDrawableContentRect(drawableContentRectOfLayer); 729 layer->setDrawableContentRect(drawableContentRectOfLayer);
730 730
731 // Compute the layer's visible content rect (the rect is in content space) 731 // Compute the layer's visible content rect (the rect is in content space)
732 IntRect visibleContentRectOfLayer = calculateVisibleContentRect(layer); 732 gfx::Rect visibleContentRectOfLayer = calculateVisibleContentRect(layer);
733 layer->setVisibleContentRect(visibleContentRectOfLayer); 733 layer->setVisibleContentRect(visibleContentRectOfLayer);
734 734
735 // Compute the remaining properties for the render surface, if the layer has one. 735 // Compute the remaining properties for the render surface, if the layer has one.
736 if (layer->renderSurface() && layer != rootLayer) { 736 if (layer->renderSurface() && layer != rootLayer) {
737 RenderSurfaceType* renderSurface = layer->renderSurface(); 737 RenderSurfaceType* renderSurface = layer->renderSurface();
738 IntRect clippedContentRect = localDrawableContentRectOfSubtree; 738 gfx::Rect clippedContentRect = localDrawableContentRectOfSubtree;
739 739
740 // Don't clip if the layer is reflected as the reflection shouldn't be 740 // Don't clip if the layer is reflected as the reflection shouldn't be
741 // clipped. If the layer is animating, then the surface's transform to 741 // clipped. If the layer is animating, then the surface's transform to
742 // its target is not known on the main thread, and we should not use it 742 // its target is not known on the main thread, and we should not use it
743 // to clip. 743 // to clip.
744 if (!layer->replicaLayer() && transformToParentIsKnown(layer)) { 744 if (!layer->replicaLayer() && transformToParentIsKnown(layer)) {
745 // Note, it is correct to use ancestorClipsSubtree here, because we are looking at this layer's renderSurface, not the layer itself. 745 // Note, it is correct to use ancestorClipsSubtree here, because we are looking at this layer's renderSurface, not the layer itself.
746 if (ancestorClipsSubtree && !clippedContentRect.isEmpty()) { 746 if (ancestorClipsSubtree && !clippedContentRect.IsEmpty()) {
747 IntRect surfaceClipRect = LayerTreeHostCommon::calculateVisibleR ect(renderSurface->clipRect(), clippedContentRect, renderSurface->drawTransform( )); 747 gfx::Rect surfaceClipRect = LayerTreeHostCommon::calculateVisibl eRect(renderSurface->clipRect(), clippedContentRect, renderSurface->drawTransfor m());
748 clippedContentRect.intersect(surfaceClipRect); 748 clippedContentRect.Intersect(surfaceClipRect);
749 } 749 }
750 } 750 }
751 751
752 // The RenderSurfaceImpl backing texture cannot exceed the maximum suppo rted 752 // The RenderSurfaceImpl backing texture cannot exceed the maximum suppo rted
753 // texture size. 753 // texture size.
754 clippedContentRect.setWidth(std::min(clippedContentRect.width(), maxText ureSize)); 754 clippedContentRect.set_width(std::min(clippedContentRect.width(), maxTex tureSize));
755 clippedContentRect.setHeight(std::min(clippedContentRect.height(), maxTe xtureSize)); 755 clippedContentRect.set_height(std::min(clippedContentRect.height(), maxT extureSize));
756 756
757 if (clippedContentRect.isEmpty()) 757 if (clippedContentRect.IsEmpty())
758 renderSurface->clearLayerLists(); 758 renderSurface->clearLayerLists();
759 759
760 renderSurface->setContentRect(clippedContentRect); 760 renderSurface->setContentRect(clippedContentRect);
761 761
762 // The owning layer's screenSpaceTransform has a scale from content to l ayer space which we need to undo and 762 // The owning layer's screenSpaceTransform has a scale from content to l ayer space which we need to undo and
763 // replace with a scale from the surface's subtree into layer space. 763 // replace with a scale from the surface's subtree into layer space.
764 WebTransformationMatrix screenSpaceTransform = layer->screenSpaceTransfo rm(); 764 WebTransformationMatrix screenSpaceTransform = layer->screenSpaceTransfo rm();
765 if (!layer->contentBounds().isEmpty() && !layer->bounds().isEmpty()) { 765 if (!layer->contentBounds().IsEmpty() && !layer->bounds().IsEmpty()) {
766 screenSpaceTransform.scaleNonUniform(layer->contentBounds().width() / static_cast<double>(layer->bounds().width()), 766 screenSpaceTransform.scaleNonUniform(layer->contentBounds().width() / static_cast<double>(layer->bounds().width()),
767 layer->contentBounds().height() / stat ic_cast<double>(layer->bounds().height())); 767 layer->contentBounds().height() / stat ic_cast<double>(layer->bounds().height()));
768 } 768 }
769 screenSpaceTransform.scaleNonUniform(1 / renderSurfaceSublayerScale.x(), 1 / renderSurfaceSublayerScale.y()); 769 screenSpaceTransform.scaleNonUniform(1 / renderSurfaceSublayerScale.x(), 1 / renderSurfaceSublayerScale.y());
770 renderSurface->setScreenSpaceTransform(screenSpaceTransform); 770 renderSurface->setScreenSpaceTransform(screenSpaceTransform);
771 771
772 if (layer->replicaLayer()) { 772 if (layer->replicaLayer()) {
773 WebTransformationMatrix surfaceOriginToReplicaOriginTransform; 773 WebTransformationMatrix surfaceOriginToReplicaOriginTransform;
774 surfaceOriginToReplicaOriginTransform.scaleNonUniform(renderSurfaceS ublayerScale.x(), renderSurfaceSublayerScale.y()); 774 surfaceOriginToReplicaOriginTransform.scaleNonUniform(renderSurfaceS ublayerScale.x(), renderSurfaceSublayerScale.y());
775 surfaceOriginToReplicaOriginTransform.translate(layer->replicaLayer( )->position().x() + layer->replicaLayer()->anchorPoint().x() * bounds.width(), 775 surfaceOriginToReplicaOriginTransform.translate(layer->replicaLayer( )->position().x() + layer->replicaLayer()->anchorPoint().x() * bounds.width(),
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
809 if (sortingStartIndex == descendants.size()) 809 if (sortingStartIndex == descendants.size())
810 return; 810 return;
811 811
812 // If preserves-3d then sort all the descendants in 3D so that they can be 812 // If preserves-3d then sort all the descendants in 3D so that they can be
813 // drawn from back to front. If the preserves-3d property is also set on the parent then 813 // drawn from back to front. If the preserves-3d property is also set on the parent then
814 // skip the sorting as the parent will sort all the descendants anyway. 814 // skip the sorting as the parent will sort all the descendants anyway.
815 if (descendants.size() && layer->preserves3D() && (!layer->parent() || !laye r->parent()->preserves3D())) 815 if (descendants.size() && layer->preserves3D() && (!layer->parent() || !laye r->parent()->preserves3D()))
816 sortLayers(descendants.begin() + sortingStartIndex, descendants.end(), l ayerSorter); 816 sortLayers(descendants.begin() + sortingStartIndex, descendants.end(), l ayerSorter);
817 817
818 if (layer->renderSurface()) 818 if (layer->renderSurface())
819 drawableContentRectOfSubtree = enclosingIntRect(layer->renderSurface()-> drawableContentRect()); 819 drawableContentRectOfSubtree = gfx::ToEnclosingRect(layer->renderSurface ()->drawableContentRect());
820 else 820 else
821 drawableContentRectOfSubtree = localDrawableContentRectOfSubtree; 821 drawableContentRectOfSubtree = localDrawableContentRectOfSubtree;
822 822
823 if (layer->hasContributingDelegatedRenderPasses()) 823 if (layer->hasContributingDelegatedRenderPasses())
824 layer->renderTarget()->renderSurface()->addContributingDelegatedRenderPa ssLayer(layer); 824 layer->renderTarget()->renderSurface()->addContributingDelegatedRenderPa ssLayer(layer);
825 } 825 }
826 826
827 void LayerTreeHostCommon::calculateDrawTransforms(Layer* rootLayer, const IntSiz e& deviceViewportSize, float deviceScaleFactor, float pageScaleFactor, int maxTe xtureSize, std::vector<scoped_refptr<Layer> >& renderSurfaceLayerList) 827 void LayerTreeHostCommon::calculateDrawTransforms(Layer* rootLayer, const gfx::S ize& deviceViewportSize, float deviceScaleFactor, float pageScaleFactor, int max TextureSize, std::vector<scoped_refptr<Layer> >& renderSurfaceLayerList)
828 { 828 {
829 IntRect totalDrawableContentRect; 829 gfx::Rect totalDrawableContentRect;
830 WebTransformationMatrix identityMatrix; 830 WebTransformationMatrix identityMatrix;
831 WebTransformationMatrix deviceScaleTransform; 831 WebTransformationMatrix deviceScaleTransform;
832 deviceScaleTransform.scale(deviceScaleFactor); 832 deviceScaleTransform.scale(deviceScaleFactor);
833 833
834 setupRootLayerAndSurfaceForRecursion<Layer, std::vector<scoped_refptr<Layer> > >(rootLayer, renderSurfaceLayerList, deviceViewportSize); 834 setupRootLayerAndSurfaceForRecursion<Layer, std::vector<scoped_refptr<Layer> > >(rootLayer, renderSurfaceLayerList, deviceViewportSize);
835 835
836 cc::calculateDrawTransformsInternal<Layer, std::vector<scoped_refptr<Layer> >, RenderSurface, void>( 836 cc::calculateDrawTransformsInternal<Layer, std::vector<scoped_refptr<Layer> >, RenderSurface, void>(
837 rootLayer, rootLayer, deviceScaleTransform, identityMatrix, identityMatr ix, 837 rootLayer, rootLayer, deviceScaleTransform, identityMatrix, identityMatr ix,
838 rootLayer->renderSurface()->contentRect(), true, 0, renderSurfaceLayerLi st, 838 rootLayer->renderSurface()->contentRect(), true, 0, renderSurfaceLayerLi st,
839 rootLayer->renderSurface()->layerList(), 0, maxTextureSize, 839 rootLayer->renderSurface()->layerList(), 0, maxTextureSize,
840 deviceScaleFactor, pageScaleFactor, totalDrawableContentRect); 840 deviceScaleFactor, pageScaleFactor, totalDrawableContentRect);
841 } 841 }
842 842
843 void LayerTreeHostCommon::calculateDrawTransforms(LayerImpl* rootLayer, const In tSize& deviceViewportSize, float deviceScaleFactor, float pageScaleFactor, Layer Sorter* layerSorter, int maxTextureSize, std::vector<LayerImpl*>& renderSurfaceL ayerList) 843 void LayerTreeHostCommon::calculateDrawTransforms(LayerImpl* rootLayer, const gf x::Size& deviceViewportSize, float deviceScaleFactor, float pageScaleFactor, Lay erSorter* layerSorter, int maxTextureSize, std::vector<LayerImpl*>& renderSurfac eLayerList)
844 { 844 {
845 IntRect totalDrawableContentRect; 845 gfx::Rect totalDrawableContentRect;
846 WebTransformationMatrix identityMatrix; 846 WebTransformationMatrix identityMatrix;
847 WebTransformationMatrix deviceScaleTransform; 847 WebTransformationMatrix deviceScaleTransform;
848 deviceScaleTransform.scale(deviceScaleFactor); 848 deviceScaleTransform.scale(deviceScaleFactor);
849 849
850 setupRootLayerAndSurfaceForRecursion<LayerImpl, std::vector<LayerImpl*> >(ro otLayer, renderSurfaceLayerList, deviceViewportSize); 850 setupRootLayerAndSurfaceForRecursion<LayerImpl, std::vector<LayerImpl*> >(ro otLayer, renderSurfaceLayerList, deviceViewportSize);
851 851
852 cc::calculateDrawTransformsInternal<LayerImpl, std::vector<LayerImpl*>, Rend erSurfaceImpl, LayerSorter>( 852 cc::calculateDrawTransformsInternal<LayerImpl, std::vector<LayerImpl*>, Rend erSurfaceImpl, LayerSorter>(
853 rootLayer, rootLayer, deviceScaleTransform, identityMatrix, identityMatr ix, 853 rootLayer, rootLayer, deviceScaleTransform, identityMatrix, identityMatr ix,
854 rootLayer->renderSurface()->contentRect(), true, 0, renderSurfaceLayerLi st, 854 rootLayer->renderSurface()->contentRect(), true, 0, renderSurfaceLayerLi st,
855 rootLayer->renderSurface()->layerList(), layerSorter, maxTextureSize, 855 rootLayer->renderSurface()->layerList(), layerSorter, maxTextureSize,
856 deviceScaleFactor, pageScaleFactor, totalDrawableContentRect); 856 deviceScaleFactor, pageScaleFactor, totalDrawableContentRect);
857 } 857 }
858 858
859 static bool pointHitsRect(const IntPoint& screenSpacePoint, const WebTransformat ionMatrix& localSpaceToScreenSpaceTransform, FloatRect localSpaceRect) 859 static bool pointHitsRect(const gfx::Point& screenSpacePoint, const WebTransform ationMatrix& localSpaceToScreenSpaceTransform, gfx::RectF localSpaceRect)
860 { 860 {
861 // If the transform is not invertible, then assume that this point doesn't h it this rect. 861 // If the transform is not invertible, then assume that this point doesn't h it this rect.
862 if (!localSpaceToScreenSpaceTransform.isInvertible()) 862 if (!localSpaceToScreenSpaceTransform.isInvertible())
863 return false; 863 return false;
864 864
865 // Transform the hit test point from screen space to the local space of the given rect. 865 // Transform the hit test point from screen space to the local space of the given rect.
866 bool clipped = false; 866 bool clipped = false;
867 FloatPoint hitTestPointInLocalSpace = MathUtil::projectPoint(localSpaceToScr eenSpaceTransform.inverse(), FloatPoint(screenSpacePoint), clipped); 867 gfx::PointF hitTestPointInLocalSpace = MathUtil::projectPoint(localSpaceToSc reenSpaceTransform.inverse(), gfx::PointF(screenSpacePoint), clipped);
868 868
869 // If projectPoint could not project to a valid value, then we assume that t his point doesn't hit this rect. 869 // If projectPoint could not project to a valid value, then we assume that t his point doesn't hit this rect.
870 if (clipped) 870 if (clipped)
871 return false; 871 return false;
872 872
873 return localSpaceRect.contains(hitTestPointInLocalSpace); 873 return localSpaceRect.Contains(hitTestPointInLocalSpace);
874 } 874 }
875 875
876 static bool pointIsClippedBySurfaceOrClipRect(const IntPoint& screenSpacePoint, LayerImpl* layer) 876 static bool pointIsClippedBySurfaceOrClipRect(const gfx::Point& screenSpacePoint , LayerImpl* layer)
877 { 877 {
878 LayerImpl* currentLayer = layer; 878 LayerImpl* currentLayer = layer;
879 879
880 // Walk up the layer tree and hit-test any renderSurfaces and any layer clip Rects that are active. 880 // Walk up the layer tree and hit-test any renderSurfaces and any layer clip Rects that are active.
881 while (currentLayer) { 881 while (currentLayer) {
882 if (currentLayer->renderSurface() && !pointHitsRect(screenSpacePoint, cu rrentLayer->renderSurface()->screenSpaceTransform(), currentLayer->renderSurface ()->contentRect())) 882 if (currentLayer->renderSurface() && !pointHitsRect(screenSpacePoint, cu rrentLayer->renderSurface()->screenSpaceTransform(), currentLayer->renderSurface ()->contentRect()))
883 return true; 883 return true;
884 884
885 // Note that drawableContentRects are actually in targetSurface space, s o the transform we 885 // Note that drawableContentRects are actually in targetSurface space, s o the transform we
886 // have to provide is the target surface's screenSpaceTransform. 886 // have to provide is the target surface's screenSpaceTransform.
887 LayerImpl* renderTarget = currentLayer->renderTarget(); 887 LayerImpl* renderTarget = currentLayer->renderTarget();
888 if (layerClipsSubtree(currentLayer) && !pointHitsRect(screenSpacePoint, renderTarget->renderSurface()->screenSpaceTransform(), currentLayer->drawableCon tentRect())) 888 if (layerClipsSubtree(currentLayer) && !pointHitsRect(screenSpacePoint, renderTarget->renderSurface()->screenSpaceTransform(), currentLayer->drawableCon tentRect()))
889 return true; 889 return true;
890 890
891 currentLayer = currentLayer->parent(); 891 currentLayer = currentLayer->parent();
892 } 892 }
893 893
894 // If we have finished walking all ancestors without having already exited, then the point is not clipped by any ancestors. 894 // If we have finished walking all ancestors without having already exited, then the point is not clipped by any ancestors.
895 return false; 895 return false;
896 } 896 }
897 897
898 LayerImpl* LayerTreeHostCommon::findLayerThatIsHitByPoint(const IntPoint& screen SpacePoint, std::vector<LayerImpl*>& renderSurfaceLayerList) 898 LayerImpl* LayerTreeHostCommon::findLayerThatIsHitByPoint(const gfx::Point& scre enSpacePoint, std::vector<LayerImpl*>& renderSurfaceLayerList)
899 { 899 {
900 LayerImpl* foundLayer = 0; 900 LayerImpl* foundLayer = 0;
901 901
902 typedef LayerIterator<LayerImpl, std::vector<LayerImpl*>, RenderSurfaceImpl, LayerIteratorActions::FrontToBack> LayerIteratorType; 902 typedef LayerIterator<LayerImpl, std::vector<LayerImpl*>, RenderSurfaceImpl, LayerIteratorActions::FrontToBack> LayerIteratorType;
903 LayerIteratorType end = LayerIteratorType::end(&renderSurfaceLayerList); 903 LayerIteratorType end = LayerIteratorType::end(&renderSurfaceLayerList);
904 904
905 for (LayerIteratorType it = LayerIteratorType::begin(&renderSurfaceLayerList ); it != end; ++it) { 905 for (LayerIteratorType it = LayerIteratorType::begin(&renderSurfaceLayerList ); it != end; ++it) {
906 // We don't want to consider renderSurfaces for hit testing. 906 // We don't want to consider renderSurfaces for hit testing.
907 if (!it.representsItself()) 907 if (!it.representsItself())
908 continue; 908 continue;
909 909
910 LayerImpl* currentLayer = (*it); 910 LayerImpl* currentLayer = (*it);
911 911
912 FloatRect contentRect(FloatPoint::zero(), currentLayer->contentBounds()) ; 912 gfx::RectF contentRect(gfx::PointF(), currentLayer->contentBounds());
913 if (!pointHitsRect(screenSpacePoint, currentLayer->screenSpaceTransform( ), contentRect)) 913 if (!pointHitsRect(screenSpacePoint, currentLayer->screenSpaceTransform( ), contentRect))
914 continue; 914 continue;
915 915
916 // At this point, we think the point does hit the layer, but we need to walk up 916 // At this point, we think the point does hit the layer, but we need to walk up
917 // the parents to ensure that the layer was not clipped in such a way th at the 917 // the parents to ensure that the layer was not clipped in such a way th at the
918 // hit point actually should not hit the layer. 918 // hit point actually should not hit the layer.
919 if (pointIsClippedBySurfaceOrClipRect(screenSpacePoint, currentLayer)) 919 if (pointIsClippedBySurfaceOrClipRect(screenSpacePoint, currentLayer))
920 continue; 920 continue;
921 921
922 foundLayer = currentLayer; 922 foundLayer = currentLayer;
923 break; 923 break;
924 } 924 }
925 925
926 // This can potentially return 0, which means the screenSpacePoint did not s uccessfully hit test any layers, not even the root layer. 926 // This can potentially return 0, which means the screenSpacePoint did not s uccessfully hit test any layers, not even the root layer.
927 return foundLayer; 927 return foundLayer;
928 } 928 }
929 929
930 } // namespace cc 930 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698