OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "config.h" |
| 6 #include "core/paint/FilterPainter.h" |
| 7 |
| 8 #include "core/paint/LayerPainter.h" |
| 9 #include "core/rendering/FilterEffectRenderer.h" |
| 10 #include "core/rendering/RenderLayer.h" |
| 11 #include "platform/graphics/GraphicsContext.h" |
| 12 #include "platform/graphics/filters/FilterEffect.h" |
| 13 #include "platform/graphics/filters/SkiaImageFilterBuilder.h" |
| 14 |
| 15 namespace blink { |
| 16 |
| 17 FilterPainter::FilterPainter(RenderLayer& renderLayer, GraphicsContext* context,
const FloatRect& filterBoxRect, const ClipRect& clipRect, const LayerPaintingIn
fo& paintingInfo, PaintLayerFlags paintFlags) |
| 18 : m_filterInProgress(false) |
| 19 , m_context(context) |
| 20 { |
| 21 SkiaImageFilterBuilder builder(context); |
| 22 RefPtr<FilterEffect> lastEffect = renderLayer.filterRenderer()->lastEffect()
; |
| 23 lastEffect->determineFilterPrimitiveSubregion(MapRectForward); |
| 24 RefPtr<ImageFilter> imageFilter = builder.build(lastEffect.get(), ColorSpace
DeviceRGB); |
| 25 if (!imageFilter) |
| 26 return; |
| 27 |
| 28 if (clipRect.rect() != paintingInfo.paintDirtyRect || clipRect.hasRadius())
{ |
| 29 m_clipRecorder = adoptPtr(new ClipRecorder(&renderLayer, context, Displa
yItem::ClipLayerFilter, clipRect)); |
| 30 if (clipRect.hasRadius()) |
| 31 LayerPainter::applyRoundedRectClips(renderLayer, paintingInfo, conte
xt, paintFlags, *m_clipRecorder); |
| 32 } |
| 33 |
| 34 context->save(); |
| 35 FloatRect boundaries = mapImageFilterRect(imageFilter.get(), filterBoxRect); |
| 36 context->translate(filterBoxRect.x(), filterBoxRect.y()); |
| 37 boundaries.move(-filterBoxRect.x(), -filterBoxRect.y()); |
| 38 context->beginLayer(1, CompositeSourceOver, &boundaries, ColorFilterNone, im
ageFilter.get()); |
| 39 context->translate(-filterBoxRect.x(), -filterBoxRect.y()); |
| 40 m_filterInProgress = true; |
| 41 } |
| 42 |
| 43 FilterPainter::~FilterPainter() |
| 44 { |
| 45 if (m_filterInProgress) { |
| 46 m_context->endLayer(); |
| 47 m_context->restore(); |
| 48 } |
| 49 } |
| 50 |
| 51 } // namespace blink |
OLD | NEW |