| 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 "config.h" | 5 #include "config.h" |
| 6 #include "core/paint/SVGFilterPainter.h" | 6 #include "core/paint/SVGFilterPainter.h" |
| 7 | 7 |
| 8 #include "core/layout/svg/LayoutSVGResourceFilter.h" | 8 #include "core/layout/svg/LayoutSVGResourceFilter.h" |
| 9 #include "core/layout/svg/SVGLayoutSupport.h" | 9 #include "core/layout/svg/SVGLayoutSupport.h" |
| 10 #include "core/paint/CompositingRecorder.h" | 10 #include "core/paint/CompositingRecorder.h" |
| 11 #include "core/paint/LayoutObjectDrawingRecorder.h" | 11 #include "core/paint/LayoutObjectDrawingRecorder.h" |
| 12 #include "core/paint/TransformRecorder.h" | 12 #include "core/paint/TransformRecorder.h" |
| 13 #include "platform/graphics/filters/SkiaImageFilterBuilder.h" | 13 #include "platform/graphics/filters/SkiaImageFilterBuilder.h" |
| 14 #include "platform/graphics/filters/SourceGraphic.h" | 14 #include "platform/graphics/filters/SourceGraphic.h" |
| 15 #include "platform/graphics/paint/CompositingDisplayItem.h" | 15 #include "platform/graphics/paint/CompositingDisplayItem.h" |
| 16 #include "platform/graphics/paint/DisplayItemList.h" | 16 #include "platform/graphics/paint/DisplayItemList.h" |
| 17 #include "platform/graphics/paint/DrawingDisplayItem.h" | 17 #include "platform/graphics/paint/DrawingDisplayItem.h" |
| 18 | 18 |
| 19 #define CHECK_CTM_FOR_TRANSFORMED_IMAGEFILTER | 19 #define CHECK_CTM_FOR_TRANSFORMED_IMAGEFILTER |
| 20 | 20 |
| 21 namespace blink { | 21 namespace blink { |
| 22 | 22 |
| 23 static GraphicsContext* beginRecordingContent(GraphicsContext* context, FilterDa
ta* filterData) | 23 GraphicsContext* SVGFilterRecordingContext::beginContent(FilterData* filterData) |
| 24 { | 24 { |
| 25 ASSERT(filterData->m_state == FilterData::Initial); | 25 ASSERT(filterData->m_state == FilterData::Initial); |
| 26 | 26 |
| 27 GraphicsContext* context = paintingContext(); |
| 28 |
| 27 // For slimming paint we need to create a new context so the contents of the | 29 // For slimming paint we need to create a new context so the contents of the |
| 28 // filter can be drawn and cached. | 30 // filter can be drawn and cached. |
| 29 if (RuntimeEnabledFeatures::slimmingPaintEnabled()) { | 31 if (RuntimeEnabledFeatures::slimmingPaintEnabled()) { |
| 30 filterData->m_displayItemList = DisplayItemList::create(); | 32 m_displayItemList = DisplayItemList::create(); |
| 31 filterData->m_context = adoptPtr(new GraphicsContext(filterData->m_displ
ayItemList.get())); | 33 m_context = adoptPtr(new GraphicsContext(m_displayItemList.get())); |
| 32 context = filterData->m_context.get(); | 34 context = m_context.get(); |
| 33 } else { | 35 } else { |
| 34 context->beginRecording(filterData->filter->filterRegion()); | 36 context->beginRecording(filterData->filter->filterRegion()); |
| 35 } | 37 } |
| 36 | 38 |
| 37 filterData->m_state = FilterData::RecordingContent; | 39 filterData->m_state = FilterData::RecordingContent; |
| 38 return context; | 40 return context; |
| 39 } | 41 } |
| 40 | 42 |
| 41 static void endRecordingContent(GraphicsContext* context, FilterData* filterData
) | 43 void SVGFilterRecordingContext::endContent(FilterData* filterData) |
| 42 { | 44 { |
| 43 ASSERT(filterData->m_state == FilterData::RecordingContent); | 45 ASSERT(filterData->m_state == FilterData::RecordingContent); |
| 44 | 46 |
| 45 // FIXME: maybe filterData should just hold onto SourceGraphic after creatio
n? | 47 // FIXME: maybe filterData should just hold onto SourceGraphic after creatio
n? |
| 46 SourceGraphic* sourceGraphic = static_cast<SourceGraphic*>(filterData->build
er->getEffectById(SourceGraphic::effectName())); | 48 SourceGraphic* sourceGraphic = static_cast<SourceGraphic*>(filterData->build
er->getEffectById(SourceGraphic::effectName())); |
| 47 ASSERT(sourceGraphic); | 49 ASSERT(sourceGraphic); |
| 48 | 50 |
| 51 GraphicsContext* context = paintingContext(); |
| 52 |
| 49 // For slimming paint we need to use the context that contains the filtered | 53 // For slimming paint we need to use the context that contains the filtered |
| 50 // content. | 54 // content. |
| 51 if (RuntimeEnabledFeatures::slimmingPaintEnabled()) { | 55 if (RuntimeEnabledFeatures::slimmingPaintEnabled()) { |
| 52 ASSERT(filterData->m_displayItemList); | 56 ASSERT(m_displayItemList); |
| 53 ASSERT(filterData->m_context); | 57 ASSERT(m_context); |
| 54 context = filterData->m_context.get(); | 58 context = m_context.get(); |
| 55 context->beginRecording(filterData->filter->filterRegion()); | 59 context->beginRecording(filterData->filter->filterRegion()); |
| 56 filterData->m_displayItemList->commitNewDisplayItemsAndReplay(*context); | 60 m_displayItemList->commitNewDisplayItemsAndReplay(*context); |
| 57 } | 61 } |
| 58 | 62 |
| 59 sourceGraphic->setPicture(context->endRecording()); | 63 sourceGraphic->setPicture(context->endRecording()); |
| 60 | 64 |
| 61 // Content is cached by the source graphic so temporaries can be freed. | 65 // Content is cached by the source graphic so temporaries can be freed. |
| 62 if (RuntimeEnabledFeatures::slimmingPaintEnabled()) { | 66 if (RuntimeEnabledFeatures::slimmingPaintEnabled()) { |
| 63 filterData->m_displayItemList = nullptr; | 67 m_displayItemList = nullptr; |
| 64 filterData->m_context = nullptr; | 68 m_context = nullptr; |
| 65 } | 69 } |
| 66 | 70 |
| 67 filterData->m_state = FilterData::ReadyToPaint; | 71 filterData->m_state = FilterData::ReadyToPaint; |
| 68 } | 72 } |
| 69 | 73 |
| 70 static void paintFilteredContent(LayoutObject& object, GraphicsContext* context,
FilterData* filterData, SVGFilterElement* filterElement) | 74 static void paintFilteredContent(LayoutObject& object, GraphicsContext* context,
FilterData* filterData) |
| 71 { | 75 { |
| 72 ASSERT(filterData->m_state == FilterData::ReadyToPaint); | 76 ASSERT(filterData->m_state == FilterData::ReadyToPaint); |
| 73 ASSERT(filterData->builder->getEffectById(SourceGraphic::effectName())); | 77 ASSERT(filterData->builder->getEffectById(SourceGraphic::effectName())); |
| 74 | 78 |
| 75 filterData->m_state = FilterData::PaintingFilter; | 79 filterData->m_state = FilterData::PaintingFilter; |
| 76 | 80 |
| 77 SkiaImageFilterBuilder builder; | 81 SkiaImageFilterBuilder builder; |
| 78 RefPtr<SkImageFilter> imageFilter = builder.build(filterData->builder->lastE
ffect(), ColorSpaceDeviceRGB); | 82 RefPtr<SkImageFilter> imageFilter = builder.build(filterData->builder->lastE
ffect(), ColorSpaceDeviceRGB); |
| 79 FloatRect boundaries = filterData->filter->filterRegion(); | 83 FloatRect boundaries = filterData->filter->filterRegion(); |
| 80 context->save(); | 84 context->save(); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 102 } | 106 } |
| 103 #endif | 107 #endif |
| 104 | 108 |
| 105 context->beginLayer(1, SkXfermode::kSrcOver_Mode, &boundaries, ColorFilterNo
ne, imageFilter.get()); | 109 context->beginLayer(1, SkXfermode::kSrcOver_Mode, &boundaries, ColorFilterNo
ne, imageFilter.get()); |
| 106 context->endLayer(); | 110 context->endLayer(); |
| 107 context->restore(); | 111 context->restore(); |
| 108 | 112 |
| 109 filterData->m_state = FilterData::ReadyToPaint; | 113 filterData->m_state = FilterData::ReadyToPaint; |
| 110 } | 114 } |
| 111 | 115 |
| 112 GraphicsContext* SVGFilterPainter::prepareEffect(LayoutObject& object, GraphicsC
ontext* context) | 116 GraphicsContext* SVGFilterPainter::prepareEffect(LayoutObject& object, SVGFilter
RecordingContext& recordingContext) |
| 113 { | 117 { |
| 114 ASSERT(context); | 118 ASSERT(recordingContext.paintingContext()); |
| 115 | 119 |
| 116 m_filter.clearInvalidationMask(); | 120 m_filter.clearInvalidationMask(); |
| 117 | 121 |
| 118 if (FilterData* filterData = m_filter.getFilterDataForLayoutObject(&object))
{ | 122 if (FilterData* filterData = m_filter.getFilterDataForLayoutObject(&object))
{ |
| 119 // If the filterData already exists we do not need to record the content | 123 // If the filterData already exists we do not need to record the content |
| 120 // to be filtered. This can occur if the content was previously recorded | 124 // to be filtered. This can occur if the content was previously recorded |
| 121 // or we are in a cycle. | 125 // or we are in a cycle. |
| 122 if (filterData->m_state == FilterData::PaintingFilter) | 126 if (filterData->m_state == FilterData::PaintingFilter) |
| 123 filterData->m_state = FilterData::PaintingFilterCycleDetected; | 127 filterData->m_state = FilterData::PaintingFilterCycleDetected; |
| 124 | 128 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 148 return nullptr; | 152 return nullptr; |
| 149 | 153 |
| 150 FilterEffect* lastEffect = filterData->builder->lastEffect(); | 154 FilterEffect* lastEffect = filterData->builder->lastEffect(); |
| 151 if (!lastEffect) | 155 if (!lastEffect) |
| 152 return nullptr; | 156 return nullptr; |
| 153 | 157 |
| 154 lastEffect->determineFilterPrimitiveSubregion(ClipToFilterRegion); | 158 lastEffect->determineFilterPrimitiveSubregion(ClipToFilterRegion); |
| 155 | 159 |
| 156 FilterData* data = filterData.get(); | 160 FilterData* data = filterData.get(); |
| 157 m_filter.setFilterDataForLayoutObject(&object, filterData.release()); | 161 m_filter.setFilterDataForLayoutObject(&object, filterData.release()); |
| 158 return beginRecordingContent(context, data); | 162 return recordingContext.beginContent(data); |
| 159 } | 163 } |
| 160 | 164 |
| 161 void SVGFilterPainter::finishEffect(LayoutObject& object, GraphicsContext* conte
xt) | 165 void SVGFilterPainter::finishEffect(LayoutObject& object, SVGFilterRecordingCont
ext& recordingContext) |
| 162 { | 166 { |
| 163 ASSERT(context); | |
| 164 | |
| 165 FilterData* filterData = m_filter.getFilterDataForLayoutObject(&object); | 167 FilterData* filterData = m_filter.getFilterDataForLayoutObject(&object); |
| 166 if (filterData) { | 168 if (filterData) { |
| 167 // A painting cycle can occur when an FeImage references a source that | 169 // A painting cycle can occur when an FeImage references a source that |
| 168 // makes use of the FeImage itself. This is the first place we would hit | 170 // makes use of the FeImage itself. This is the first place we would hit |
| 169 // the cycle so we reset the state and continue. | 171 // the cycle so we reset the state and continue. |
| 170 if (filterData->m_state == FilterData::PaintingFilterCycleDetected) | 172 if (filterData->m_state == FilterData::PaintingFilterCycleDetected) |
| 171 filterData->m_state = FilterData::PaintingFilter; | 173 filterData->m_state = FilterData::PaintingFilter; |
| 172 | 174 |
| 173 // Check for RecordingContent here because we may can be re-painting | 175 // Check for RecordingContent here because we may can be re-painting |
| 174 // without re-recording the contents to be filtered. | 176 // without re-recording the contents to be filtered. |
| 175 if (filterData->m_state == FilterData::RecordingContent) | 177 if (filterData->m_state == FilterData::RecordingContent) |
| 176 endRecordingContent(context, filterData); | 178 recordingContext.endContent(filterData); |
| 177 | 179 |
| 178 if (filterData->m_state == FilterData::RecordingContentCycleDetected) | 180 if (filterData->m_state == FilterData::RecordingContentCycleDetected) |
| 179 filterData->m_state = FilterData::RecordingContent; | 181 filterData->m_state = FilterData::RecordingContent; |
| 180 } | 182 } |
| 181 | 183 |
| 184 GraphicsContext* context = recordingContext.paintingContext(); |
| 185 ASSERT(context); |
| 186 |
| 182 LayoutObjectDrawingRecorder recorder(*context, object, DisplayItem::SVGFilte
r, LayoutRect::infiniteIntRect()); | 187 LayoutObjectDrawingRecorder recorder(*context, object, DisplayItem::SVGFilte
r, LayoutRect::infiniteIntRect()); |
| 183 if (recorder.canUseCachedDrawing()) | 188 if (recorder.canUseCachedDrawing()) |
| 184 return; | 189 return; |
| 185 | 190 |
| 186 if (filterData && filterData->m_state == FilterData::ReadyToPaint) | 191 if (filterData && filterData->m_state == FilterData::ReadyToPaint) |
| 187 paintFilteredContent(object, context, filterData, toSVGFilterElement(m_f
ilter.element())); | 192 paintFilteredContent(object, context, filterData); |
| 188 } | 193 } |
| 189 | 194 |
| 190 } | 195 } |
| OLD | NEW |