| 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/DrawingDisplayItem.h" | 16 #include "platform/graphics/paint/DrawingDisplayItem.h" |
| 17 #include "platform/graphics/paint/PaintController.h" | 17 #include "platform/graphics/paint/PaintController.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 GraphicsContext* SVGFilterRecordingContext::beginContent(FilterData* 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(); | 27 GraphicsContext* context = &paintingContext(); |
| 28 | 28 |
| 29 // Create a new context so the contents of the filter can be drawn and cache
d. | 29 // Create a new context so the contents of the filter can be drawn and cache
d. |
| 30 m_paintController = PaintController::create(); | 30 m_paintController = PaintController::create(); |
| 31 m_context = adoptPtr(new GraphicsContext(*m_paintController)); | 31 m_context = adoptPtr(new GraphicsContext(*m_paintController)); |
| 32 context = m_context.get(); | 32 context = m_context.get(); |
| 33 | 33 |
| 34 filterData->m_state = FilterData::RecordingContent; | 34 filterData->m_state = FilterData::RecordingContent; |
| 35 return context; | 35 return context; |
| 36 } | 36 } |
| 37 | 37 |
| 38 void SVGFilterRecordingContext::endContent(FilterData* filterData) | 38 void SVGFilterRecordingContext::endContent(FilterData* filterData) |
| 39 { | 39 { |
| 40 ASSERT(filterData->m_state == FilterData::RecordingContent); | 40 ASSERT(filterData->m_state == FilterData::RecordingContent); |
| 41 | 41 |
| 42 SourceGraphic* sourceGraphic = filterData->filter->sourceGraphic(); | 42 SourceGraphic* sourceGraphic = filterData->filter->sourceGraphic(); |
| 43 ASSERT(sourceGraphic); | 43 ASSERT(sourceGraphic); |
| 44 | 44 |
| 45 GraphicsContext* context = paintingContext(); | 45 GraphicsContext* context = &paintingContext(); |
| 46 | 46 |
| 47 // Use the context that contains the filtered content. | 47 // Use the context that contains the filtered content. |
| 48 ASSERT(m_paintController); | 48 ASSERT(m_paintController); |
| 49 ASSERT(m_context); | 49 ASSERT(m_context); |
| 50 context = m_context.get(); | 50 context = m_context.get(); |
| 51 context->beginRecording(filterData->filter->filterRegion()); | 51 context->beginRecording(filterData->filter->filterRegion()); |
| 52 m_paintController->commitNewDisplayItems(); | 52 m_paintController->commitNewDisplayItems(); |
| 53 m_paintController->paintArtifact().replay(*context); | 53 m_paintController->paintArtifact().replay(*context); |
| 54 | 54 |
| 55 sourceGraphic->setPicture(context->endRecording()); | 55 sourceGraphic->setPicture(context->endRecording()); |
| 56 | 56 |
| 57 // Content is cached by the source graphic so temporaries can be freed. | 57 // Content is cached by the source graphic so temporaries can be freed. |
| 58 m_paintController = nullptr; | 58 m_paintController = nullptr; |
| 59 m_context = nullptr; | 59 m_context = nullptr; |
| 60 | 60 |
| 61 filterData->m_state = FilterData::ReadyToPaint; | 61 filterData->m_state = FilterData::ReadyToPaint; |
| 62 } | 62 } |
| 63 | 63 |
| 64 static void paintFilteredContent(const LayoutObject& object, GraphicsContext* co
ntext, FilterData* filterData) | 64 static void paintFilteredContent(const LayoutObject& object, GraphicsContext& co
ntext, FilterData* filterData) |
| 65 { | 65 { |
| 66 ASSERT(filterData->m_state == FilterData::ReadyToPaint); | 66 ASSERT(filterData->m_state == FilterData::ReadyToPaint); |
| 67 ASSERT(filterData->filter->sourceGraphic()); | 67 ASSERT(filterData->filter->sourceGraphic()); |
| 68 | 68 |
| 69 filterData->m_state = FilterData::PaintingFilter; | 69 filterData->m_state = FilterData::PaintingFilter; |
| 70 | 70 |
| 71 SkiaImageFilterBuilder builder; | 71 SkiaImageFilterBuilder builder; |
| 72 RefPtr<SkImageFilter> imageFilter = builder.build(filterData->filter->lastEf
fect(), ColorSpaceDeviceRGB); | 72 RefPtr<SkImageFilter> imageFilter = builder.build(filterData->filter->lastEf
fect(), ColorSpaceDeviceRGB); |
| 73 FloatRect boundaries = filterData->filter->filterRegion(); | 73 FloatRect boundaries = filterData->filter->filterRegion(); |
| 74 context->save(); | 74 context.save(); |
| 75 | 75 |
| 76 // Clip drawing of filtered image to the minimum required paint rect. | 76 // Clip drawing of filtered image to the minimum required paint rect. |
| 77 FilterEffect* lastEffect = filterData->filter->lastEffect(); | 77 FilterEffect* lastEffect = filterData->filter->lastEffect(); |
| 78 context->clipRect(lastEffect->determineAbsolutePaintRect(lastEffect->maxEffe
ctRect())); | 78 context.clipRect(lastEffect->determineAbsolutePaintRect(lastEffect->maxEffec
tRect())); |
| 79 | 79 |
| 80 #ifdef CHECK_CTM_FOR_TRANSFORMED_IMAGEFILTER | 80 #ifdef CHECK_CTM_FOR_TRANSFORMED_IMAGEFILTER |
| 81 // TODO: Remove this workaround once skew/rotation support is added in Skia | 81 // TODO: Remove this workaround once skew/rotation support is added in Skia |
| 82 // (https://code.google.com/p/skia/issues/detail?id=3288, crbug.com/446935). | 82 // (https://code.google.com/p/skia/issues/detail?id=3288, crbug.com/446935). |
| 83 // If the CTM contains rotation or shearing, apply the filter to | 83 // If the CTM contains rotation or shearing, apply the filter to |
| 84 // the unsheared/unrotated matrix, and do the shearing/rotation | 84 // the unsheared/unrotated matrix, and do the shearing/rotation |
| 85 // as a final pass. | 85 // as a final pass. |
| 86 AffineTransform ctm = SVGLayoutSupport::deprecatedCalculateTransformToLayer(
&object); | 86 AffineTransform ctm = SVGLayoutSupport::deprecatedCalculateTransformToLayer(
&object); |
| 87 if (ctm.b() || ctm.c()) { | 87 if (ctm.b() || ctm.c()) { |
| 88 AffineTransform scaleAndTranslate; | 88 AffineTransform scaleAndTranslate; |
| 89 scaleAndTranslate.translate(ctm.e(), ctm.f()); | 89 scaleAndTranslate.translate(ctm.e(), ctm.f()); |
| 90 scaleAndTranslate.scale(ctm.xScale(), ctm.yScale()); | 90 scaleAndTranslate.scale(ctm.xScale(), ctm.yScale()); |
| 91 ASSERT(scaleAndTranslate.isInvertible()); | 91 ASSERT(scaleAndTranslate.isInvertible()); |
| 92 AffineTransform shearAndRotate = scaleAndTranslate.inverse(); | 92 AffineTransform shearAndRotate = scaleAndTranslate.inverse(); |
| 93 shearAndRotate.multiply(ctm); | 93 shearAndRotate.multiply(ctm); |
| 94 context->concatCTM(shearAndRotate.inverse()); | 94 context.concatCTM(shearAndRotate.inverse()); |
| 95 imageFilter = builder.buildTransform(shearAndRotate, imageFilter.get()); | 95 imageFilter = builder.buildTransform(shearAndRotate, imageFilter.get()); |
| 96 } | 96 } |
| 97 #endif | 97 #endif |
| 98 | 98 |
| 99 context->beginLayer(1, SkXfermode::kSrcOver_Mode, &boundaries, ColorFilterNo
ne, imageFilter.get()); | 99 context.beginLayer(1, SkXfermode::kSrcOver_Mode, &boundaries, ColorFilterNon
e, imageFilter.get()); |
| 100 context->endLayer(); | 100 context.endLayer(); |
| 101 context->restore(); | 101 context.restore(); |
| 102 | 102 |
| 103 filterData->m_state = FilterData::ReadyToPaint; | 103 filterData->m_state = FilterData::ReadyToPaint; |
| 104 } | 104 } |
| 105 | 105 |
| 106 GraphicsContext* SVGFilterPainter::prepareEffect(const LayoutObject& object, SVG
FilterRecordingContext& recordingContext) | 106 GraphicsContext* SVGFilterPainter::prepareEffect(const LayoutObject& object, SVG
FilterRecordingContext& recordingContext) |
| 107 { | 107 { |
| 108 ASSERT(recordingContext.paintingContext()); | |
| 109 | |
| 110 m_filter.clearInvalidationMask(); | 108 m_filter.clearInvalidationMask(); |
| 111 | 109 |
| 112 if (FilterData* filterData = m_filter.getFilterDataForLayoutObject(&object))
{ | 110 if (FilterData* filterData = m_filter.getFilterDataForLayoutObject(&object))
{ |
| 113 // If the filterData already exists we do not need to record the content | 111 // If the filterData already exists we do not need to record the content |
| 114 // to be filtered. This can occur if the content was previously recorded | 112 // to be filtered. This can occur if the content was previously recorded |
| 115 // or we are in a cycle. | 113 // or we are in a cycle. |
| 116 if (filterData->m_state == FilterData::PaintingFilter) | 114 if (filterData->m_state == FilterData::PaintingFilter) |
| 117 filterData->m_state = FilterData::PaintingFilterCycleDetected; | 115 filterData->m_state = FilterData::PaintingFilterCycleDetected; |
| 118 | 116 |
| 119 if (filterData->m_state == FilterData::RecordingContent) | 117 if (filterData->m_state == FilterData::RecordingContent) |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 | 166 |
| 169 // Check for RecordingContent here because we may can be re-painting | 167 // Check for RecordingContent here because we may can be re-painting |
| 170 // without re-recording the contents to be filtered. | 168 // without re-recording the contents to be filtered. |
| 171 if (filterData->m_state == FilterData::RecordingContent) | 169 if (filterData->m_state == FilterData::RecordingContent) |
| 172 recordingContext.endContent(filterData); | 170 recordingContext.endContent(filterData); |
| 173 | 171 |
| 174 if (filterData->m_state == FilterData::RecordingContentCycleDetected) | 172 if (filterData->m_state == FilterData::RecordingContentCycleDetected) |
| 175 filterData->m_state = FilterData::RecordingContent; | 173 filterData->m_state = FilterData::RecordingContent; |
| 176 } | 174 } |
| 177 | 175 |
| 178 GraphicsContext* context = recordingContext.paintingContext(); | 176 GraphicsContext& context = recordingContext.paintingContext(); |
| 179 ASSERT(context); | 177 if (LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(context, object,
DisplayItem::SVGFilter, LayoutPoint())) |
| 180 if (LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(*context, object
, DisplayItem::SVGFilter, LayoutPoint())) | |
| 181 return; | 178 return; |
| 182 | 179 |
| 183 // TODO(chrishtr): stop using an infinite rect, and instead bound the filter
. | 180 // TODO(chrishtr): stop using an infinite rect, and instead bound the filter
. |
| 184 LayoutObjectDrawingRecorder recorder(*context, object, DisplayItem::SVGFilte
r, LayoutRect::infiniteIntRect(), LayoutPoint()); | 181 LayoutObjectDrawingRecorder recorder(context, object, DisplayItem::SVGFilter
, LayoutRect::infiniteIntRect(), LayoutPoint()); |
| 185 if (filterData && filterData->m_state == FilterData::ReadyToPaint) | 182 if (filterData && filterData->m_state == FilterData::ReadyToPaint) |
| 186 paintFilteredContent(object, context, filterData); | 183 paintFilteredContent(object, context, filterData); |
| 187 } | 184 } |
| 188 | 185 |
| 189 } | 186 } |
| OLD | NEW |