DeviceOrientation.absolute should return false when it was not initialized.
[framework/web/webkit-efl.git] / Source / WebCore / rendering / FilterEffectRenderer.h
1 /*
2  * Copyright (C) 2011 Apple Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
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.
12  *
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. 
24  */
25
26 #ifndef FilterEffectRenderer_h
27 #define FilterEffectRenderer_h
28
29 #if ENABLE(CSS_FILTERS)
30
31 #include "Filter.h"
32 #include "FilterEffect.h"
33 #include "FilterOperations.h"
34 #include "FloatRect.h"
35 #include "GraphicsContext.h"
36 #include "ImageBuffer.h"
37 #include "SVGFilterBuilder.h"
38 #include "SourceGraphic.h"
39
40 #include <wtf/PassRefPtr.h>
41 #include <wtf/RefCounted.h>
42 #include <wtf/RefPtr.h>
43
44 namespace WebCore {
45
46 typedef Vector<RefPtr<FilterEffect> > FilterEffectList;
47 class CachedShader;
48 class CustomFilterProgram;
49 class Document;
50 class GraphicsContext;
51 class RenderLayer;
52
53 class FilterEffectRendererHelper {
54 public:
55     FilterEffectRendererHelper(bool haveFilterEffect)
56         : m_savedGraphicsContext(0)
57         , m_renderLayer(0)
58         , m_haveFilterEffect(haveFilterEffect)
59     {
60     }
61     
62     bool haveFilterEffect() const { return m_haveFilterEffect; }
63     bool hasStartedFilterEffect() const { return m_savedGraphicsContext; }
64
65     bool prepareFilterEffect(RenderLayer*, const LayoutRect& filterBoxRect, const LayoutRect& dirtyRect, const LayoutRect& layerRepaintRect);
66     GraphicsContext* beginFilterEffect(GraphicsContext* oldContext);
67     GraphicsContext* applyFilterEffect();
68
69     const LayoutRect& repaintRect() const { return m_repaintRect; }
70 private:
71     GraphicsContext* m_savedGraphicsContext;
72     RenderLayer* m_renderLayer;
73     LayoutPoint m_paintOffset;
74     LayoutRect m_repaintRect;
75     bool m_haveFilterEffect;
76 };
77
78 class FilterEffectRenderer : public Filter
79 {
80     WTF_MAKE_FAST_ALLOCATED;
81 public:
82     static PassRefPtr<FilterEffectRenderer> create()
83     {
84         return adoptRef(new FilterEffectRenderer());
85     }
86
87     virtual void setSourceImageRect(const FloatRect& sourceImageRect)
88     { 
89         m_sourceDrawingRegion = sourceImageRect;
90         setMaxEffectRects(sourceImageRect);
91         setFilterRegion(sourceImageRect);
92         m_graphicsBufferAttached = false;
93     }
94     virtual FloatRect sourceImageRect() const { return m_sourceDrawingRegion; }
95
96     virtual void setFilterRegion(const FloatRect& filterRegion) { m_filterRegion = filterRegion; }
97     virtual FloatRect filterRegion() const { return m_filterRegion; }
98
99     GraphicsContext* inputContext();
100     ImageBuffer* output() const { return lastEffect()->asImageBuffer(); }
101
102     bool build(Document*, const FilterOperations&);
103     PassRefPtr<FilterEffect> buildReferenceFilter(Document*, PassRefPtr<FilterEffect> previousEffect, ReferenceFilterOperation*);
104     bool updateBackingStoreRect(const FloatRect& filterRect);
105     void allocateBackingStoreIfNeeded();
106     void clearIntermediateResults();
107     void apply();
108     
109     IntRect outputRect() const { return lastEffect()->hasResult() ? lastEffect()->requestedRegionOfInputImageData(IntRect(m_filterRegion)) : IntRect(); }
110
111     bool hasFilterThatMovesPixels() const { return m_hasFilterThatMovesPixels; }
112     LayoutRect computeSourceImageRectForDirtyRect(const LayoutRect& filterBoxRect, const LayoutRect& dirtyRect);
113
114 #if ENABLE(CSS_SHADERS)
115     bool hasCustomShaderFilter() const { return m_hasCustomShaderFilter; }
116 #endif
117 private:
118     void setMaxEffectRects(const FloatRect& effectRect)
119     {
120         for (size_t i = 0; i < m_effects.size(); ++i) {
121             RefPtr<FilterEffect> effect = m_effects.at(i);
122             effect->setMaxEffectRect(effectRect);
123         }
124     }
125     PassRefPtr<FilterEffect> lastEffect() const
126     {
127         if (m_effects.size() > 0)
128             return m_effects.last();
129         return 0;
130     }
131
132     FilterEffectRenderer();
133     virtual ~FilterEffectRenderer();
134     
135     FloatRect m_sourceDrawingRegion;
136     FloatRect m_filterRegion;
137     
138     FilterEffectList m_effects;
139     RefPtr<SourceGraphic> m_sourceGraphic;
140     
141     int m_topOutset;
142     int m_rightOutset;
143     int m_bottomOutset;
144     int m_leftOutset;
145     
146     bool m_graphicsBufferAttached;
147     bool m_hasFilterThatMovesPixels;
148 #if ENABLE(CSS_SHADERS)
149     bool m_hasCustomShaderFilter;
150 #endif
151 };
152
153 } // namespace WebCore
154
155 #endif // ENABLE(CSS_FILTERS)
156
157 #endif // FilterEffectRenderer_h