OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "core/paint/PaintPropertyTreeBuilder.h" | 5 #include "core/paint/PaintPropertyTreeBuilder.h" |
6 | 6 |
7 #include "core/frame/FrameView.h" | 7 #include "core/frame/FrameView.h" |
8 #include "core/frame/LocalFrame.h" | 8 #include "core/frame/LocalFrame.h" |
9 #include "core/frame/Settings.h" | 9 #include "core/frame/Settings.h" |
10 #include "core/layout/LayoutInline.h" | 10 #include "core/layout/LayoutInline.h" |
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 } | 298 } |
299 } | 299 } |
300 | 300 |
301 if (object.paintProperties() && object.paintProperties()->transform()) { | 301 if (object.paintProperties() && object.paintProperties()->transform()) { |
302 context.current.transform = object.paintProperties()->transform(); | 302 context.current.transform = object.paintProperties()->transform(); |
303 context.current.shouldFlattenInheritedTransform = false; | 303 context.current.shouldFlattenInheritedTransform = false; |
304 context.current.renderingContextID = 0; | 304 context.current.renderingContextID = 0; |
305 } | 305 } |
306 } | 306 } |
307 | 307 |
308 static CompositingReasons compositingReasonsForTransform( | 308 static CompositingReasons compositingReasonsForTransform(const LayoutBox& box) { |
309 const LayoutObject& object) { | 309 const ComputedStyle& style = box.styleRef(); |
310 CompositingReasons compositingReasons = CompositingReasonNone; | 310 CompositingReasons compositingReasons = CompositingReasonNone; |
311 if (CompositingReasonFinder::requiresCompositingForTransform(object)) | 311 if (CompositingReasonFinder::requiresCompositingForTransform(box)) |
312 compositingReasons |= CompositingReason3DTransform; | 312 compositingReasons |= CompositingReason3DTransform; |
313 | 313 |
314 if (CompositingReasonFinder::requiresCompositingForTransformAnimation( | 314 if (CompositingReasonFinder::requiresCompositingForTransformAnimation(style)) |
315 object.styleRef())) | |
316 compositingReasons |= CompositingReasonActiveAnimation; | 315 compositingReasons |= CompositingReasonActiveAnimation; |
317 | 316 |
318 if (object.styleRef().hasWillChangeCompositingHint() && | 317 if (style.hasWillChangeCompositingHint() && |
319 !object.styleRef().subtreeWillChangeContents()) | 318 !style.subtreeWillChangeContents()) |
320 compositingReasons |= CompositingReasonWillChangeCompositingHint; | 319 compositingReasons |= CompositingReasonWillChangeCompositingHint; |
321 | 320 |
322 if (object.isBoxModelObject()) { | 321 if (box.hasLayer() && |
323 const LayoutBoxModelObject* box = toLayoutBoxModelObject(&object); | 322 (style.hasPerspective() || |
324 if (box->hasLayer()) { | 323 style.usedTransformStyle3D() == TransformStyle3DPreserve3D) && |
325 // TODO(chrishtr): move this to the descendant-dependent flags recursion | 324 box.layer()->has3DTransformedDescendant()) |
326 // PaintLayer::updateDescendantDependentFlags. | 325 compositingReasons |= CompositingReason3DTransform; |
327 box->layer()->update3DTransformedDescendantStatus(); | |
328 | |
329 if (box->layer()->has3DTransformedDescendant()) | |
330 compositingReasons |= CompositingReason3DTransform; | |
331 } | |
332 } | |
333 | 326 |
334 return compositingReasons; | 327 return compositingReasons; |
335 } | 328 } |
336 | 329 |
337 static FloatPoint3D transformOrigin(const LayoutBox& box) { | 330 static FloatPoint3D transformOrigin(const LayoutBox& box) { |
338 const ComputedStyle& style = box.styleRef(); | 331 const ComputedStyle& style = box.styleRef(); |
339 // Transform origin has no effect without a transform or motion path. | 332 // Transform origin has no effect without a transform or motion path. |
340 if (!style.hasTransform()) | 333 if (!style.hasTransform()) |
341 return FloatPoint3D(); | 334 return FloatPoint3D(); |
342 FloatSize borderBoxSize(box.size()); | 335 FloatSize borderBoxSize(box.size()); |
343 return FloatPoint3D( | 336 return FloatPoint3D( |
344 floatValueForLength(style.transformOriginX(), borderBoxSize.width()), | 337 floatValueForLength(style.transformOriginX(), borderBoxSize.width()), |
345 floatValueForLength(style.transformOriginY(), borderBoxSize.height()), | 338 floatValueForLength(style.transformOriginY(), borderBoxSize.height()), |
346 style.transformOriginZ()); | 339 style.transformOriginZ()); |
347 } | 340 } |
348 | 341 |
349 void PaintPropertyTreeBuilder::updateTransform( | 342 void PaintPropertyTreeBuilder::updateTransform( |
350 const LayoutObject& object, | 343 const LayoutObject& object, |
351 PaintPropertyTreeBuilderContext& context) { | 344 PaintPropertyTreeBuilderContext& context) { |
352 if (object.isSVG() && !object.isSVGRoot()) { | 345 if (object.isSVG() && !object.isSVGRoot()) { |
353 updateTransformForNonRootSVG(object, context); | 346 updateTransformForNonRootSVG(object, context); |
354 return; | 347 return; |
355 } | 348 } |
356 | 349 |
357 if (object.needsPaintPropertyUpdate() || context.forceSubtreeUpdate) { | 350 if (object.needsPaintPropertyUpdate() || context.forceSubtreeUpdate) { |
358 const ComputedStyle& style = object.styleRef(); | 351 const ComputedStyle& style = object.styleRef(); |
359 | 352 |
360 CompositingReasons compositingReasons = | |
361 compositingReasonsForTransform(object); | |
362 | |
363 // A transform node is allocated for transforms, preserves-3d and any | 353 // A transform node is allocated for transforms, preserves-3d and any |
364 // direct compositing reason. The latter is required because this is the | 354 // direct compositing reason. The latter is required because this is the |
365 // only way to represent compositing both an element and its stacking | 355 // only way to represent compositing both an element and its stacking |
366 // descendants. | 356 // descendants. |
367 if (object.isBox() && (style.hasTransform() || style.preserves3D() || | 357 bool hasTransform = false; |
368 compositingReasons != CompositingReasonNone)) { | 358 if (object.isBox()) { |
369 auto& box = toLayoutBox(object); | 359 auto& box = toLayoutBox(object); |
370 TransformationMatrix matrix; | |
371 style.applyTransform( | |
372 matrix, box.size(), ComputedStyle::ExcludeTransformOrigin, | |
373 ComputedStyle::IncludeMotionPath, | |
374 ComputedStyle::IncludeIndependentTransformProperties); | |
375 | 360 |
376 // TODO(trchen): transform-style should only be respected if a PaintLayer | 361 CompositingReasons compositingReasons = |
377 // is created. | 362 compositingReasonsForTransform(box); |
378 // If a node with transform-style: preserve-3d does not exist in an | |
379 // existing rendering context, it establishes a new one. | |
380 unsigned renderingContextID = context.current.renderingContextID; | |
381 if (style.preserves3D() && !renderingContextID) | |
382 renderingContextID = PtrHash<const LayoutObject>::hash(&object); | |
383 | 363 |
384 auto& properties = object.getMutableForPainting().ensurePaintProperties(); | 364 if (style.hasTransform() || style.preserves3D() || |
385 context.forceSubtreeUpdate |= properties.updateTransform( | 365 compositingReasons != CompositingReasonNone) { |
386 context.current.transform, matrix, transformOrigin(box), | 366 TransformationMatrix matrix; |
387 context.current.shouldFlattenInheritedTransform, renderingContextID, | 367 style.applyTransform( |
388 compositingReasons); | 368 matrix, box.size(), ComputedStyle::ExcludeTransformOrigin, |
389 } else { | 369 ComputedStyle::IncludeMotionPath, |
| 370 ComputedStyle::IncludeIndependentTransformProperties); |
| 371 |
| 372 // TODO(trchen): transform-style should only be respected if a |
| 373 // PaintLayer |
| 374 // is created. |
| 375 // If a node with transform-style: preserve-3d does not exist in an |
| 376 // existing rendering context, it establishes a new one. |
| 377 unsigned renderingContextID = context.current.renderingContextID; |
| 378 if (style.preserves3D() && !renderingContextID) |
| 379 renderingContextID = PtrHash<const LayoutObject>::hash(&object); |
| 380 |
| 381 auto& properties = |
| 382 object.getMutableForPainting().ensurePaintProperties(); |
| 383 context.forceSubtreeUpdate |= properties.updateTransform( |
| 384 context.current.transform, matrix, transformOrigin(box), |
| 385 context.current.shouldFlattenInheritedTransform, renderingContextID, |
| 386 compositingReasons); |
| 387 hasTransform = true; |
| 388 } |
| 389 } |
| 390 if (!hasTransform) { |
390 if (auto* properties = object.getMutableForPainting().paintProperties()) | 391 if (auto* properties = object.getMutableForPainting().paintProperties()) |
391 context.forceSubtreeUpdate |= properties->clearTransform(); | 392 context.forceSubtreeUpdate |= properties->clearTransform(); |
392 } | 393 } |
393 } | 394 } |
394 | 395 |
395 const auto* properties = object.paintProperties(); | 396 const auto* properties = object.paintProperties(); |
396 if (properties && properties->transform()) { | 397 if (properties && properties->transform()) { |
397 context.current.transform = properties->transform(); | 398 context.current.transform = properties->transform(); |
398 if (object.styleRef().preserves3D()) { | 399 if (object.styleRef().preserves3D()) { |
399 context.current.renderingContextID = | 400 context.current.renderingContextID = |
(...skipping 588 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
988 updateOverflowClip(object, context); | 989 updateOverflowClip(object, context); |
989 updatePerspective(object, context); | 990 updatePerspective(object, context); |
990 updateSvgLocalToBorderBoxTransform(object, context); | 991 updateSvgLocalToBorderBoxTransform(object, context); |
991 updateScrollAndScrollTranslation(object, context); | 992 updateScrollAndScrollTranslation(object, context); |
992 updateOutOfFlowContext(object, context); | 993 updateOutOfFlowContext(object, context); |
993 | 994 |
994 context.forceSubtreeUpdate |= object.subtreeNeedsPaintPropertyUpdate(); | 995 context.forceSubtreeUpdate |= object.subtreeNeedsPaintPropertyUpdate(); |
995 } | 996 } |
996 | 997 |
997 } // namespace blink | 998 } // namespace blink |
OLD | NEW |