OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/FilterPainter.h" | 5 #include "core/paint/FilterPainter.h" |
6 | 6 |
7 #include "core/paint/FilterEffectBuilder.h" | 7 #include "core/paint/FilterEffectBuilder.h" |
8 #include "core/paint/LayerClipRecorder.h" | 8 #include "core/paint/LayerClipRecorder.h" |
9 #include "core/paint/PaintLayer.h" | 9 #include "core/paint/PaintLayer.h" |
10 #include "platform/RuntimeEnabledFeatures.h" | 10 #include "platform/RuntimeEnabledFeatures.h" |
11 #include "platform/graphics/CompositorFilterOperations.h" | 11 #include "platform/graphics/CompositorFilterOperations.h" |
12 #include "platform/graphics/GraphicsContext.h" | 12 #include "platform/graphics/GraphicsContext.h" |
13 #include "platform/graphics/GraphicsLayer.h" | 13 #include "platform/graphics/GraphicsLayer.h" |
14 #include "platform/graphics/filters/FilterEffect.h" | 14 #include "platform/graphics/filters/FilterEffect.h" |
15 #include "platform/graphics/filters/SkiaImageFilterBuilder.h" | 15 #include "platform/graphics/filters/SkiaImageFilterBuilder.h" |
16 #include "platform/graphics/paint/FilterDisplayItem.h" | 16 #include "platform/graphics/paint/FilterDisplayItem.h" |
17 #include "platform/graphics/paint/PaintController.h" | 17 #include "platform/graphics/paint/PaintController.h" |
18 #include "public/platform/Platform.h" | |
19 #include "public/platform/WebCompositorSupport.h" | |
20 #include "wtf/PtrUtil.h" | 18 #include "wtf/PtrUtil.h" |
21 #include <memory> | 19 #include <memory> |
22 | 20 |
23 namespace blink { | 21 namespace blink { |
24 | 22 |
25 FilterPainter::FilterPainter(PaintLayer& layer, GraphicsContext& context, const
LayoutPoint& offsetFromRoot, const ClipRect& clipRect, PaintLayerPaintingInfo& p
aintingInfo, PaintLayerFlags paintFlags, | 23 FilterPainter::FilterPainter(PaintLayer& layer, GraphicsContext& context, const
LayoutPoint& offsetFromRoot, const ClipRect& clipRect, PaintLayerPaintingInfo& p
aintingInfo, PaintLayerFlags paintFlags) |
26 LayoutRect& rootRelativeBounds, bool& rootRelativeBoundsComputed) | |
27 : m_filterInProgress(false) | 24 : m_filterInProgress(false) |
28 , m_context(context) | 25 , m_context(context) |
29 , m_layoutObject(layer.layoutObject()) | 26 , m_layoutObject(layer.layoutObject()) |
30 { | 27 { |
31 if (!layer.paintsWithFilters()) | 28 if (!layer.paintsWithFilters()) |
32 return; | 29 return; |
33 | 30 |
34 FilterEffect* lastEffect = layer.lastFilterEffect(); | 31 FilterEffect* lastEffect = layer.lastFilterEffect(); |
35 if (!lastEffect) | 32 if (!lastEffect) |
36 return; | 33 return; |
37 | 34 |
38 ASSERT(layer.filterInfo()); | 35 DCHECK(layer.filterInfo()); |
39 | 36 |
40 lastEffect->determineFilterPrimitiveSubregion(MapRectForward); | 37 lastEffect->determineFilterPrimitiveSubregion(MapRectForward); |
41 sk_sp<SkImageFilter> imageFilter = SkiaImageFilterBuilder::build(lastEffect,
ColorSpaceDeviceRGB); | 38 sk_sp<SkImageFilter> imageFilter = SkiaImageFilterBuilder::build(lastEffect,
ColorSpaceDeviceRGB); |
42 if (!imageFilter) | 39 if (!imageFilter) |
43 return; | 40 return; |
44 | 41 |
45 if (!rootRelativeBoundsComputed) { | |
46 rootRelativeBounds = layer.physicalBoundingBoxIncludingReflectionAndStac
kingChildren(offsetFromRoot); | |
47 rootRelativeBoundsComputed = true; | |
48 } | |
49 | |
50 // We'll handle clipping to the dirty rect before filter rasterization. | 42 // We'll handle clipping to the dirty rect before filter rasterization. |
51 // Filter processing will automatically expand the clip rect and the offscre
en to accommodate any filter outsets. | 43 // Filter processing will automatically expand the clip rect and the offscre
en to accommodate any filter outsets. |
52 // FIXME: It is incorrect to just clip to the damageRect here once multiple
fragments are involved. | 44 // FIXME: It is incorrect to just clip to the damageRect here once multiple
fragments are involved. |
53 | 45 |
54 // Subsequent code should not clip to the dirty rect, since we've already | 46 // Subsequent code should not clip to the dirty rect, since we've already |
55 // done it above, and doing it later will defeat the outsets. | 47 // done it above, and doing it later will defeat the outsets. |
56 paintingInfo.clipToDirtyRect = false; | 48 paintingInfo.clipToDirtyRect = false; |
57 | 49 |
58 if (clipRect.rect() != paintingInfo.paintDirtyRect || clipRect.hasRadius())
{ | 50 DCHECK(m_layoutObject); |
| 51 |
| 52 if (clipRect.rect() != paintingInfo.paintDirtyRect || clipRect.hasRadius()) |
59 m_clipRecorder = wrapUnique(new LayerClipRecorder(context, *layer.layout
Object(), DisplayItem::kClipLayerFilter, clipRect, &paintingInfo, LayoutPoint(),
paintFlags)); | 53 m_clipRecorder = wrapUnique(new LayerClipRecorder(context, *layer.layout
Object(), DisplayItem::kClipLayerFilter, clipRect, &paintingInfo, LayoutPoint(),
paintFlags)); |
60 } | |
61 | 54 |
62 ASSERT(m_layoutObject); | |
63 if (!context.getPaintController().displayItemConstructionIsDisabled()) { | 55 if (!context.getPaintController().displayItemConstructionIsDisabled()) { |
64 FilterOperations filterOperations(layer.computeFilterOperations(m_layout
Object->styleRef())); | 56 FilterOperations filterOperations(layer.computeFilterOperations(m_layout
Object->styleRef())); |
65 CompositorFilterOperations compositorFilterOperations; | 57 CompositorFilterOperations compositorFilterOperations; |
66 SkiaImageFilterBuilder::buildFilterOperations(filterOperations, &composi
torFilterOperations); | 58 SkiaImageFilterBuilder::buildFilterOperations(filterOperations, &composi
torFilterOperations); |
67 // FIXME: It's possible to have empty CompositorFilterOperations here ev
en | 59 // FIXME: It's possible to have empty CompositorFilterOperations here ev
en |
68 // though the SkImageFilter produced above is non-null, since the | 60 // though the SkImageFilter produced above is non-null, since the |
69 // layer's FilterEffectBuilder can have a stale representation of | 61 // layer's FilterEffectBuilder can have a stale representation of |
70 // the layer's filter. See crbug.com/502026. | 62 // the layer's filter. See crbug.com/502026. |
71 if (compositorFilterOperations.isEmpty()) | 63 if (compositorFilterOperations.isEmpty()) |
72 return; | 64 return; |
73 LayoutRect visualBounds(rootRelativeBounds); | 65 LayoutRect visualBounds(layer.physicalBoundingBoxIncludingReflectionAndS
tackingChildren(offsetFromRoot)); |
74 if (layer.enclosingPaginationLayer()) { | 66 if (layer.enclosingPaginationLayer()) { |
75 // Filters are set up before pagination, so we need to make the boun
ding box visual on our own. | 67 // Filters are set up before pagination, so we need to make the boun
ding box visual on our own. |
76 visualBounds.moveBy(-offsetFromRoot); | 68 visualBounds.moveBy(-offsetFromRoot); |
77 layer.convertFromFlowThreadToVisualBoundingBoxInAncestor(paintingInf
o.rootLayer, visualBounds); | 69 layer.convertFromFlowThreadToVisualBoundingBoxInAncestor(paintingInf
o.rootLayer, visualBounds); |
78 } | 70 } |
79 FloatPoint origin(offsetFromRoot); | 71 FloatPoint origin(offsetFromRoot); |
80 context.getPaintController().createAndAppend<BeginFilterDisplayItem>(*m_
layoutObject, std::move(imageFilter), FloatRect(visualBounds), origin, std::move
(compositorFilterOperations)); | 72 context.getPaintController().createAndAppend<BeginFilterDisplayItem>(*m_
layoutObject, std::move(imageFilter), FloatRect(visualBounds), origin, std::move
(compositorFilterOperations)); |
81 } | 73 } |
82 | 74 |
83 m_filterInProgress = true; | 75 m_filterInProgress = true; |
84 } | 76 } |
85 | 77 |
86 FilterPainter::~FilterPainter() | 78 FilterPainter::~FilterPainter() |
87 { | 79 { |
88 if (!m_filterInProgress) | 80 if (!m_filterInProgress) |
89 return; | 81 return; |
90 | 82 |
91 m_context.getPaintController().endItem<EndFilterDisplayItem>(*m_layoutObject
); | 83 m_context.getPaintController().endItem<EndFilterDisplayItem>(*m_layoutObject
); |
92 } | 84 } |
93 | 85 |
94 } // namespace blink | 86 } // namespace blink |
OLD | NEW |