#ifndef FilterEffectRenderer_h
#define FilterEffectRenderer_h
#include "core/svg/graphics/filters/SVGFilterBuilder.h"
#include "platform/geometry/FloatRect.h"
#include "platform/geometry/IntRectExtent.h"
#include "platform/geometry/LayoutRect.h"
#include "platform/graphics/GraphicsContext.h"
#include "platform/graphics/ImageBuffer.h"
#include "platform/graphics/filters/Filter.h"
#include "platform/graphics/filters/FilterEffect.h"
#include "platform/graphics/filters/FilterOperations.h"
#include "platform/graphics/filters/SourceGraphic.h"
#include "wtf/PassRefPtr.h"
#include "wtf/RefCounted.h"
#include "wtf/RefPtr.h"
namespace WebCore {
class ShaderResource;
class Document;
class GraphicsContext;
class RenderLayer;
class RenderObject;
class FilterEffectRendererHelper {
public:
FilterEffectRendererHelper(bool haveFilterEffect)
: m_savedGraphicsContext(0)
, m_renderLayer(0)
, m_haveFilterEffect(haveFilterEffect)
{
}
bool haveFilterEffect() const { return m_haveFilterEffect; }
bool hasStartedFilterEffect() const { return m_savedGraphicsContext; }
bool prepareFilterEffect(RenderLayer*, const LayoutRect& filterBoxRect, const LayoutRect& dirtyRect, const LayoutRect& layerRepaintRect);
GraphicsContext* beginFilterEffect(GraphicsContext* oldContext);
GraphicsContext* applyFilterEffect();
const LayoutRect& repaintRect() const { return m_repaintRect; }
private:
GraphicsContext* m_savedGraphicsContext;
RenderLayer* m_renderLayer;
LayoutRect m_repaintRect;
bool m_haveFilterEffect;
};
class FilterEffectRenderer FINAL : public Filter
{
WTF_MAKE_FAST_ALLOCATED;
public:
static PassRefPtr<FilterEffectRenderer> create()
{
return adoptRef(new FilterEffectRenderer());
}
void setSourceImageRect(const IntRect& sourceImageRect)
{
m_sourceDrawingRegion = sourceImageRect;
m_graphicsBufferAttached = false;
}
virtual IntRect sourceImageRect() const OVERRIDE { return m_sourceDrawingRegion; }
GraphicsContext* inputContext();
ImageBuffer* output() const { return lastEffect()->asImageBuffer(); }
bool build(RenderObject* renderer, const FilterOperations&);
bool updateBackingStoreRect(const FloatRect& filterRect);
void allocateBackingStoreIfNeeded();
void clearIntermediateResults();
void apply();
IntRect outputRect() const { return lastEffect()->hasResult() ? lastEffect()->absolutePaintRect() : IntRect(); }
bool hasFilterThatMovesPixels() const { return m_hasFilterThatMovesPixels; }
LayoutRect computeSourceImageRectForDirtyRect(const LayoutRect& filterBoxRect, const LayoutRect& dirtyRect);
bool hasCustomShaderFilter() const { return m_hasCustomShaderFilter; }
PassRefPtr<FilterEffect> lastEffect() const
{
return m_lastEffect;
}
private:
FilterEffectRenderer();
virtual ~FilterEffectRenderer();
IntRect m_sourceDrawingRegion;
RefPtr<SourceGraphic> m_sourceGraphic;
RefPtr<FilterEffect> m_lastEffect;
IntRectExtent m_outsets;
bool m_graphicsBufferAttached;
bool m_hasFilterThatMovesPixels;
bool m_hasCustomShaderFilter;
};
}
#endif