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

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

Powered by Google App Engine
This is Rietveld 408576698