2 * Copyright (C) 2011 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 #ifndef FilterEffectRenderer_h
27 #define FilterEffectRenderer_h
29 #include "core/svg/graphics/filters/SVGFilterBuilder.h"
30 #include "platform/geometry/FloatRect.h"
31 #include "platform/geometry/IntRectExtent.h"
32 #include "platform/geometry/LayoutRect.h"
33 #include "platform/graphics/ImageBuffer.h"
34 #include "platform/graphics/filters/Filter.h"
35 #include "platform/graphics/filters/FilterEffect.h"
36 #include "platform/graphics/filters/FilterOperations.h"
37 #include "platform/graphics/filters/SourceGraphic.h"
38 #include "wtf/PassRefPtr.h"
39 #include "wtf/RefCounted.h"
40 #include "wtf/RefPtr.h"
44 class GraphicsContext;
48 class FilterEffectRendererHelper {
50 FilterEffectRendererHelper(bool haveFilterEffect)
51 : m_savedGraphicsContext(0)
53 , m_haveFilterEffect(haveFilterEffect)
57 bool haveFilterEffect() const { return m_haveFilterEffect; }
58 bool hasStartedFilterEffect() const { return m_savedGraphicsContext; }
60 bool prepareFilterEffect(RenderLayer*, const LayoutRect& filterBoxRect, const LayoutRect& dirtyRect);
61 GraphicsContext* beginFilterEffect(GraphicsContext* oldContext);
62 GraphicsContext* applyFilterEffect();
64 const LayoutRect& repaintRect() const { return m_repaintRect; }
66 GraphicsContext* m_savedGraphicsContext;
67 RenderLayer* m_renderLayer;
69 LayoutRect m_repaintRect;
70 bool m_haveFilterEffect;
73 class FilterEffectRenderer FINAL : public Filter
75 WTF_MAKE_FAST_ALLOCATED;
77 static PassRefPtr<FilterEffectRenderer> create()
79 return adoptRef(new FilterEffectRenderer());
82 void setSourceImageRect(const IntRect& sourceImageRect)
84 m_sourceDrawingRegion = sourceImageRect;
85 m_graphicsBufferAttached = false;
87 virtual IntRect sourceImageRect() const OVERRIDE { return m_sourceDrawingRegion; }
89 GraphicsContext* inputContext();
90 ImageBuffer* output() const { return lastEffect()->asImageBuffer(); }
92 bool build(RenderObject* renderer, const FilterOperations&);
93 bool updateBackingStoreRect(const FloatRect& filterRect);
94 void allocateBackingStoreIfNeeded();
95 void clearIntermediateResults();
98 IntRect outputRect() const { return lastEffect()->hasResult() ? lastEffect()->absolutePaintRect() : IntRect(); }
100 bool hasFilterThatMovesPixels() const { return m_hasFilterThatMovesPixels; }
101 LayoutRect computeSourceImageRectForDirtyRect(const LayoutRect& filterBoxRect, const LayoutRect& dirtyRect);
103 PassRefPtr<FilterEffect> lastEffect() const
109 FilterEffectRenderer();
110 virtual ~FilterEffectRenderer();
112 IntRect m_sourceDrawingRegion;
114 RefPtr<SourceGraphic> m_sourceGraphic;
115 RefPtr<FilterEffect> m_lastEffect;
117 bool m_graphicsBufferAttached;
118 bool m_hasFilterThatMovesPixels;
124 #endif // FilterEffectRenderer_h