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 20 matching lines...) Expand all Loading... |
31 ClipPaintPropertyNode* rootClipNode() { | 31 ClipPaintPropertyNode* rootClipNode() { |
32 DEFINE_STATIC_REF(ClipPaintPropertyNode, rootClip, | 32 DEFINE_STATIC_REF(ClipPaintPropertyNode, rootClip, |
33 (ClipPaintPropertyNode::create( | 33 (ClipPaintPropertyNode::create( |
34 nullptr, rootTransformNode(), | 34 nullptr, rootTransformNode(), |
35 FloatRoundedRect(LayoutRect::infiniteIntRect())))); | 35 FloatRoundedRect(LayoutRect::infiniteIntRect())))); |
36 return rootClip; | 36 return rootClip; |
37 } | 37 } |
38 | 38 |
39 EffectPaintPropertyNode* rootEffectNode() { | 39 EffectPaintPropertyNode* rootEffectNode() { |
40 DEFINE_STATIC_REF(EffectPaintPropertyNode, rootEffect, | 40 DEFINE_STATIC_REF(EffectPaintPropertyNode, rootEffect, |
41 (EffectPaintPropertyNode::create(nullptr, 1.0))); | 41 (EffectPaintPropertyNode::create( |
| 42 nullptr, rootTransformNode(), rootClipNode(), |
| 43 CompositorFilterOperations(), 1.0))); |
42 return rootEffect; | 44 return rootEffect; |
43 } | 45 } |
44 | 46 |
45 ScrollPaintPropertyNode* rootScrollNode() { | 47 ScrollPaintPropertyNode* rootScrollNode() { |
46 DEFINE_STATIC_REF( | 48 DEFINE_STATIC_REF( |
47 ScrollPaintPropertyNode, rootScroll, | 49 ScrollPaintPropertyNode, rootScroll, |
48 (ScrollPaintPropertyNode::create(nullptr, rootTransformNode(), IntSize(), | 50 (ScrollPaintPropertyNode::create(nullptr, rootTransformNode(), IntSize(), |
49 IntSize(), false, false))); | 51 IntSize(), false, false))); |
50 return rootScroll; | 52 return rootScroll; |
51 } | 53 } |
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 childrenFlattenInheritedTransform; | 352 childrenFlattenInheritedTransform; |
351 } else { | 353 } else { |
352 if (auto* properties = object.getMutableForPainting().paintProperties()) | 354 if (auto* properties = object.getMutableForPainting().paintProperties()) |
353 properties->clearTransform(); | 355 properties->clearTransform(); |
354 } | 356 } |
355 } | 357 } |
356 | 358 |
357 void PaintPropertyTreeBuilder::updateEffect( | 359 void PaintPropertyTreeBuilder::updateEffect( |
358 const LayoutObject& object, | 360 const LayoutObject& object, |
359 PaintPropertyTreeBuilderContext& context) { | 361 PaintPropertyTreeBuilderContext& context) { |
360 if (!object.styleRef().hasOpacity()) { | 362 const ComputedStyle& style = object.styleRef(); |
361 if (auto* properties = object.getMutableForPainting().paintProperties()) | 363 |
| 364 if (!style.isStackingContext()) { |
| 365 if (ObjectPaintProperties* properties = |
| 366 object.getMutableForPainting().paintProperties()) |
| 367 properties->clearEffect(); |
| 368 return; |
| 369 } |
| 370 |
| 371 // TODO(trchen): Can't omit effect node if we have 3D children. |
| 372 // TODO(trchen): Can't omit effect node if we have blending children. |
| 373 bool effectNodeNeeded = false; |
| 374 |
| 375 float opacity = style.opacity(); |
| 376 if (opacity != 1.0f) |
| 377 effectNodeNeeded = true; |
| 378 |
| 379 CompositorFilterOperations filter; |
| 380 if (object.isSVG() && !object.isSVGRoot()) { |
| 381 // TODO(trchen): SVG caches filters in SVGResources. Implement it. |
| 382 } else if (PaintLayer* layer = toLayoutBoxModelObject(object).layer()) { |
| 383 // TODO(trchen): Eliminate PaintLayer dependency. |
| 384 filter = layer->createCompositorFilterOperationsForFilter(style); |
| 385 } |
| 386 |
| 387 const ClipPaintPropertyNode* outputClip = rootClipNode(); |
| 388 // The CSS filter spec didn't specify how filters interact with overflow |
| 389 // clips. The implementation here mimics the old Blink/WebKit behavior for |
| 390 // backward compatibility. |
| 391 // Basically the output of the filter will be affected by clips that applies |
| 392 // to the current element. The descendants that paints into the input of the |
| 393 // filter ignores any clips collected so far. For example: |
| 394 // <div style="overflow:scroll"> |
| 395 // <div style="filter:blur(1px);"> |
| 396 // <div>A</div> |
| 397 // <div style="position:absolute;">B</div> |
| 398 // </div> |
| 399 // </div> |
| 400 // In this example "A" should be clipped if the filter was not present. |
| 401 // With the filter, "A" will be rastered without clipping, but instead |
| 402 // the blurred result will be clipped. |
| 403 // On the other hand, "B" should not be clipped because the overflow clip is |
| 404 // not in its containing block chain, but as the filter output will be |
| 405 // clipped, so a blurred "B" may still be invisible. |
| 406 if (!filter.isEmpty()) { |
| 407 effectNodeNeeded = true; |
| 408 outputClip = context.current.clip; |
| 409 |
| 410 // TODO(trchen): A filter may contain spatial operations such that an output |
| 411 // pixel may depend on an input pixel outside of the output clip. Need to |
| 412 // generate special clip node to hint how to expand clip / cull rect. |
| 413 const ClipPaintPropertyNode* expansionHint = context.current.clip; |
| 414 context.current.clip = context.absolutePosition.clip = |
| 415 context.fixedPosition.clip = expansionHint; |
| 416 } |
| 417 |
| 418 if (!effectNodeNeeded) { |
| 419 if (ObjectPaintProperties* properties = |
| 420 object.getMutableForPainting().paintProperties()) |
362 properties->clearEffect(); | 421 properties->clearEffect(); |
363 return; | 422 return; |
364 } | 423 } |
365 | 424 |
366 context.currentEffect = | 425 context.currentEffect = |
367 object.getMutableForPainting().ensurePaintProperties().updateEffect( | 426 object.getMutableForPainting().ensurePaintProperties().updateEffect( |
368 context.currentEffect, object.styleRef().opacity()); | 427 context.currentEffect, context.current.transform, outputClip, |
| 428 std::move(filter), opacity); |
369 } | 429 } |
370 | 430 |
371 void PaintPropertyTreeBuilder::updateCssClip( | 431 void PaintPropertyTreeBuilder::updateCssClip( |
372 const LayoutObject& object, | 432 const LayoutObject& object, |
373 PaintPropertyTreeBuilderContext& context) { | 433 PaintPropertyTreeBuilderContext& context) { |
374 if (object.hasClip()) { | 434 if (object.hasClip()) { |
375 // Create clip node for descendants that are not fixed position. | 435 // Create clip node for descendants that are not fixed position. |
376 // We don't have to setup context.absolutePosition.clip here because this | 436 // We don't have to setup context.absolutePosition.clip here because this |
377 // object must be a container for absolute position descendants, and will | 437 // object must be a container for absolute position descendants, and will |
378 // copy from in-flow context later at updateOutOfFlowContext() step. | 438 // copy from in-flow context later at updateOutOfFlowContext() step. |
(...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
803 return; | 863 return; |
804 | 864 |
805 updateOverflowClip(object, context); | 865 updateOverflowClip(object, context); |
806 updatePerspective(object, context); | 866 updatePerspective(object, context); |
807 updateSvgLocalToBorderBoxTransform(object, context); | 867 updateSvgLocalToBorderBoxTransform(object, context); |
808 updateScrollAndScrollTranslation(object, context); | 868 updateScrollAndScrollTranslation(object, context); |
809 updateOutOfFlowContext(object, context); | 869 updateOutOfFlowContext(object, context); |
810 } | 870 } |
811 | 871 |
812 } // namespace blink | 872 } // namespace blink |
OLD | NEW |