michael@0: /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef _MOZILLA_GFX_FILTERNODESOFTWARE_H_ michael@0: #define _MOZILLA_GFX_FILTERNODESOFTWARE_H_ michael@0: michael@0: #include "Filters.h" michael@0: #include michael@0: michael@0: namespace mozilla { michael@0: namespace gfx { michael@0: michael@0: class DataSourceSurface; michael@0: class DrawTarget; michael@0: struct DrawOptions; michael@0: class FilterNodeSoftware; michael@0: michael@0: /** michael@0: * Can be attached to FilterNodeSoftware instances using michael@0: * AddInvalidationListener. FilterInvalidated is called whenever the output of michael@0: * the observed filter may have changed; that is, whenever cached GetOutput() michael@0: * results (and results derived from them) need to discarded. michael@0: */ michael@0: class FilterInvalidationListener michael@0: { michael@0: public: michael@0: virtual void FilterInvalidated(FilterNodeSoftware* aFilter) = 0; michael@0: }; michael@0: michael@0: /** michael@0: * This is the base class for the software (i.e. pure CPU, non-accelerated) michael@0: * FilterNode implementation. The software implementation is backend-agnostic, michael@0: * so it can be used as a fallback for all DrawTarget implementations. michael@0: */ michael@0: class FilterNodeSoftware : public FilterNode, michael@0: public FilterInvalidationListener michael@0: { michael@0: public: michael@0: MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeSoftware) michael@0: virtual ~FilterNodeSoftware(); michael@0: michael@0: // Factory method, intended to be called from DrawTarget*::CreateFilter. michael@0: static TemporaryRef Create(FilterType aType); michael@0: michael@0: // Draw the filter, intended to be called by DrawTarget*::DrawFilter. michael@0: void Draw(DrawTarget* aDrawTarget, const Rect &aSourceRect, michael@0: const Point &aDestPoint, const DrawOptions &aOptions); michael@0: michael@0: virtual FilterBackend GetBackendType() MOZ_OVERRIDE { return FILTER_BACKEND_SOFTWARE; } michael@0: virtual void SetInput(uint32_t aIndex, SourceSurface *aSurface) MOZ_OVERRIDE; michael@0: virtual void SetInput(uint32_t aIndex, FilterNode *aFilter) MOZ_OVERRIDE; michael@0: michael@0: virtual const char* GetName() { return "Unknown"; } michael@0: michael@0: virtual void AddInvalidationListener(FilterInvalidationListener* aListener); michael@0: virtual void RemoveInvalidationListener(FilterInvalidationListener* aListener); michael@0: michael@0: // FilterInvalidationListener implementation michael@0: virtual void FilterInvalidated(FilterNodeSoftware* aFilter); michael@0: michael@0: protected: michael@0: michael@0: // The following methods are intended to be overriden by subclasses. michael@0: michael@0: /** michael@0: * Translates a *FilterInputs enum value into an index for the michael@0: * mInputFilters / mInputSurfaces arrays. Returns -1 for invalid inputs. michael@0: * If somebody calls SetInput(enumValue, input) with an enumValue for which michael@0: * InputIndex(enumValue) is -1, we abort. michael@0: */ michael@0: virtual int32_t InputIndex(uint32_t aInputEnumIndex) { return -1; } michael@0: michael@0: /** michael@0: * Every filter node has an output rect, which can also be infinite. The michael@0: * output rect can depend on the values of any set attributes and on the michael@0: * output rects of any input filters or surfaces. michael@0: * This method returns the intersection of the filter's output rect with michael@0: * aInRect. Filters with unconstrained output always return aInRect. michael@0: */ michael@0: virtual IntRect GetOutputRectInRect(const IntRect& aInRect) = 0; michael@0: michael@0: /** michael@0: * Return a surface with the rendered output which is of size aRect.Size(). michael@0: * aRect is required to be a subrect of this filter's output rect; in other michael@0: * words, aRect == GetOutputRectInRect(aRect) must always be true. michael@0: * May return nullptr in error conditions or for an empty aRect. michael@0: * Implementations are not required to allocate a new surface and may even michael@0: * pass through input surfaces unchanged. michael@0: * Callers need to treat the returned surface as immutable. michael@0: */ michael@0: virtual TemporaryRef Render(const IntRect& aRect) = 0; michael@0: michael@0: /** michael@0: * Call RequestRect (see below) on any input filters with the desired input michael@0: * rect, so that the input filter knows what to cache the next time it michael@0: * renders. michael@0: */ michael@0: virtual void RequestFromInputsForRect(const IntRect &aRect) {} michael@0: michael@0: /** michael@0: * This method provides a caching default implementation but can be overriden michael@0: * by subclasses that don't want to cache their output. Those classes should michael@0: * call Render(aRect) directly from here. michael@0: */ michael@0: virtual TemporaryRef GetOutput(const IntRect &aRect); michael@0: michael@0: // The following methods are non-virtual helper methods. michael@0: michael@0: /** michael@0: * Format hints for GetInputDataSourceSurface. Some callers of michael@0: * GetInputDataSourceSurface can handle both B8G8R8A8 and A8 surfaces, these michael@0: * should pass CAN_HANDLE_A8 in order to avoid unnecessary conversions. michael@0: * Callers that can only handle B8G8R8A8 surfaces pass NEED_COLOR_CHANNELS. michael@0: */ michael@0: enum FormatHint { michael@0: CAN_HANDLE_A8, michael@0: NEED_COLOR_CHANNELS michael@0: }; michael@0: michael@0: /** michael@0: * Returns SurfaceFormat::B8G8R8A8 or SurfaceFormat::A8, depending on the current surface michael@0: * format and the format hint. michael@0: */ michael@0: SurfaceFormat DesiredFormat(SurfaceFormat aCurrentFormat, michael@0: FormatHint aFormatHint); michael@0: michael@0: /** michael@0: * Intended to be called by FilterNodeSoftware::Render implementations. michael@0: * Returns a surface of size aRect.Size() or nullptr in error conditions. The michael@0: * returned surface contains the output of the specified input filter or michael@0: * input surface in aRect. If aRect extends beyond the input filter's output michael@0: * rect (or the input surface's dimensions), the remaining area is filled michael@0: * according to aEdgeMode: The default, EDGE_MODE_NONE, simply pads with michael@0: * transparent black. michael@0: * If non-null, the returned surface is guaranteed to be of SurfaceFormat::A8 or michael@0: * SurfaceFormat::B8G8R8A8. If aFormatHint is NEED_COLOR_CHANNELS, the returned michael@0: * surface is guaranteed to be of SurfaceFormat::B8G8R8A8 always. michael@0: * Each pixel row of the returned surface is guaranteed to be 16-byte aligned. michael@0: */ michael@0: TemporaryRef michael@0: GetInputDataSourceSurface(uint32_t aInputEnumIndex, const IntRect& aRect, michael@0: FormatHint aFormatHint = CAN_HANDLE_A8, michael@0: ConvolveMatrixEdgeMode aEdgeMode = EDGE_MODE_NONE, michael@0: const IntRect *aTransparencyPaddedSourceRect = nullptr); michael@0: michael@0: /** michael@0: * Returns the intersection of the input filter's or surface's output rect michael@0: * with aInRect. michael@0: */ michael@0: IntRect GetInputRectInRect(uint32_t aInputEnumIndex, const IntRect& aInRect); michael@0: michael@0: /** michael@0: * Calls RequestRect on the specified input, if it's a filter. michael@0: */ michael@0: void RequestInputRect(uint32_t aInputEnumIndex, const IntRect& aRect); michael@0: michael@0: /** michael@0: * Returns the number of set input filters or surfaces. Needed for filters michael@0: * which can have an arbitrary number of inputs. michael@0: */ michael@0: size_t NumberOfSetInputs(); michael@0: michael@0: /** michael@0: * Discard the cached surface that was stored in the GetOutput default michael@0: * implementation. Needs to be called whenever attributes or inputs are set michael@0: * that might change the result of a Render() call. michael@0: */ michael@0: void Invalidate(); michael@0: michael@0: /** michael@0: * Called in order to let this filter know what to cache during the next michael@0: * GetOutput call. Expected to call RequestRect on this filter's input michael@0: * filters. michael@0: */ michael@0: void RequestRect(const IntRect &aRect); michael@0: michael@0: /** michael@0: * Set input filter and clear input surface for this input index, or set michael@0: * input surface and clear input filter. One of aSurface and aFilter should michael@0: * be null. michael@0: */ michael@0: void SetInput(uint32_t aIndex, SourceSurface *aSurface, michael@0: FilterNodeSoftware *aFilter); michael@0: michael@0: protected: michael@0: /** michael@0: * mInputSurfaces / mInputFilters: For each input index, either a surface or michael@0: * a filter is set, and the other is null. michael@0: */ michael@0: std::vector > mInputSurfaces; michael@0: std::vector > mInputFilters; michael@0: michael@0: /** michael@0: * Weak pointers to our invalidation listeners, i.e. to those filters who michael@0: * have this filter as an input. Invalidation listeners are required to michael@0: * unsubscribe themselves from us when they let go of their reference to us. michael@0: * This ensures that the pointers in this array are never stale. michael@0: */ michael@0: std::vector mInvalidationListeners; michael@0: michael@0: /** michael@0: * Stores the rect which we want to render and cache on the next call to michael@0: * GetOutput. michael@0: */ michael@0: IntRect mRequestedRect; michael@0: michael@0: /** michael@0: * Stores our cached output. michael@0: */ michael@0: IntRect mCachedRect; michael@0: RefPtr mCachedOutput; michael@0: }; michael@0: michael@0: // Subclasses for specific filters. michael@0: michael@0: class FilterNodeTransformSoftware : public FilterNodeSoftware michael@0: { michael@0: public: michael@0: MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeTransformSoftware) michael@0: FilterNodeTransformSoftware(); michael@0: virtual const char* GetName() MOZ_OVERRIDE { return "Transform"; } michael@0: using FilterNodeSoftware::SetAttribute; michael@0: virtual void SetAttribute(uint32_t aIndex, uint32_t aGraphicsFilter) MOZ_OVERRIDE; michael@0: virtual void SetAttribute(uint32_t aIndex, const Matrix &aMatrix) MOZ_OVERRIDE; michael@0: michael@0: protected: michael@0: virtual TemporaryRef Render(const IntRect& aRect) MOZ_OVERRIDE; michael@0: virtual IntRect GetOutputRectInRect(const IntRect& aRect) MOZ_OVERRIDE; michael@0: virtual int32_t InputIndex(uint32_t aInputEnumIndex) MOZ_OVERRIDE; michael@0: virtual void RequestFromInputsForRect(const IntRect &aRect) MOZ_OVERRIDE; michael@0: IntRect SourceRectForOutputRect(const IntRect &aRect); michael@0: michael@0: private: michael@0: Matrix mMatrix; michael@0: Filter mFilter; michael@0: }; michael@0: michael@0: class FilterNodeBlendSoftware : public FilterNodeSoftware michael@0: { michael@0: public: michael@0: MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeBlendSoftware) michael@0: FilterNodeBlendSoftware(); michael@0: virtual const char* GetName() MOZ_OVERRIDE { return "Blend"; } michael@0: using FilterNodeSoftware::SetAttribute; michael@0: virtual void SetAttribute(uint32_t aIndex, uint32_t aBlendMode) MOZ_OVERRIDE; michael@0: michael@0: protected: michael@0: virtual TemporaryRef Render(const IntRect& aRect) MOZ_OVERRIDE; michael@0: virtual IntRect GetOutputRectInRect(const IntRect& aRect) MOZ_OVERRIDE; michael@0: virtual int32_t InputIndex(uint32_t aInputEnumIndex) MOZ_OVERRIDE; michael@0: virtual void RequestFromInputsForRect(const IntRect &aRect) MOZ_OVERRIDE; michael@0: michael@0: private: michael@0: BlendMode mBlendMode; michael@0: }; michael@0: michael@0: class FilterNodeMorphologySoftware : public FilterNodeSoftware michael@0: { michael@0: public: michael@0: MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeMorphologySoftware) michael@0: FilterNodeMorphologySoftware(); michael@0: virtual const char* GetName() MOZ_OVERRIDE { return "Morphology"; } michael@0: using FilterNodeSoftware::SetAttribute; michael@0: virtual void SetAttribute(uint32_t aIndex, const IntSize &aRadii) MOZ_OVERRIDE; michael@0: virtual void SetAttribute(uint32_t aIndex, uint32_t aOperator) MOZ_OVERRIDE; michael@0: michael@0: protected: michael@0: virtual TemporaryRef Render(const IntRect& aRect) MOZ_OVERRIDE; michael@0: virtual IntRect GetOutputRectInRect(const IntRect& aRect) MOZ_OVERRIDE; michael@0: virtual int32_t InputIndex(uint32_t aInputEnumIndex) MOZ_OVERRIDE; michael@0: virtual void RequestFromInputsForRect(const IntRect &aRect) MOZ_OVERRIDE; michael@0: michael@0: private: michael@0: IntSize mRadii; michael@0: MorphologyOperator mOperator; michael@0: }; michael@0: michael@0: class FilterNodeColorMatrixSoftware : public FilterNodeSoftware michael@0: { michael@0: public: michael@0: MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeColorMatrixSoftware) michael@0: virtual const char* GetName() MOZ_OVERRIDE { return "ColorMatrix"; } michael@0: using FilterNodeSoftware::SetAttribute; michael@0: virtual void SetAttribute(uint32_t aIndex, const Matrix5x4 &aMatrix) MOZ_OVERRIDE; michael@0: virtual void SetAttribute(uint32_t aIndex, uint32_t aAlphaMode) MOZ_OVERRIDE; michael@0: michael@0: protected: michael@0: virtual TemporaryRef Render(const IntRect& aRect) MOZ_OVERRIDE; michael@0: virtual IntRect GetOutputRectInRect(const IntRect& aRect) MOZ_OVERRIDE; michael@0: virtual int32_t InputIndex(uint32_t aInputEnumIndex) MOZ_OVERRIDE; michael@0: virtual void RequestFromInputsForRect(const IntRect &aRect) MOZ_OVERRIDE; michael@0: michael@0: private: michael@0: Matrix5x4 mMatrix; michael@0: AlphaMode mAlphaMode; michael@0: }; michael@0: michael@0: class FilterNodeFloodSoftware : public FilterNodeSoftware michael@0: { michael@0: public: michael@0: MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeFloodSoftware) michael@0: virtual const char* GetName() MOZ_OVERRIDE { return "Flood"; } michael@0: using FilterNodeSoftware::SetAttribute; michael@0: virtual void SetAttribute(uint32_t aIndex, const Color &aColor) MOZ_OVERRIDE; michael@0: michael@0: protected: michael@0: virtual TemporaryRef GetOutput(const IntRect &aRect) MOZ_OVERRIDE; michael@0: virtual TemporaryRef Render(const IntRect& aRect) MOZ_OVERRIDE; michael@0: virtual IntRect GetOutputRectInRect(const IntRect& aRect) MOZ_OVERRIDE; michael@0: michael@0: private: michael@0: Color mColor; michael@0: }; michael@0: michael@0: class FilterNodeTileSoftware : public FilterNodeSoftware michael@0: { michael@0: public: michael@0: MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeTileSoftware) michael@0: virtual const char* GetName() MOZ_OVERRIDE { return "Tile"; } michael@0: using FilterNodeSoftware::SetAttribute; michael@0: virtual void SetAttribute(uint32_t aIndex, const IntRect &aSourceRect) MOZ_OVERRIDE; michael@0: michael@0: protected: michael@0: virtual TemporaryRef Render(const IntRect& aRect) MOZ_OVERRIDE; michael@0: virtual IntRect GetOutputRectInRect(const IntRect& aRect) MOZ_OVERRIDE; michael@0: virtual int32_t InputIndex(uint32_t aInputEnumIndex) MOZ_OVERRIDE; michael@0: virtual void RequestFromInputsForRect(const IntRect &aRect) MOZ_OVERRIDE; michael@0: michael@0: private: michael@0: IntRect mSourceRect; michael@0: }; michael@0: michael@0: /** michael@0: * Baseclass for the four different component transfer filters. michael@0: */ michael@0: class FilterNodeComponentTransferSoftware : public FilterNodeSoftware michael@0: { michael@0: public: michael@0: MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeComponentTransferSoftware) michael@0: FilterNodeComponentTransferSoftware(); michael@0: michael@0: using FilterNodeSoftware::SetAttribute; michael@0: virtual void SetAttribute(uint32_t aIndex, bool aDisable) MOZ_OVERRIDE; michael@0: michael@0: protected: michael@0: virtual TemporaryRef Render(const IntRect& aRect) MOZ_OVERRIDE; michael@0: virtual IntRect GetOutputRectInRect(const IntRect& aRect) MOZ_OVERRIDE; michael@0: virtual int32_t InputIndex(uint32_t aInputEnumIndex) MOZ_OVERRIDE; michael@0: virtual void RequestFromInputsForRect(const IntRect &aRect) MOZ_OVERRIDE; michael@0: virtual void GenerateLookupTable(ptrdiff_t aComponent, uint8_t aTables[4][256], michael@0: bool aDisabled); michael@0: virtual void FillLookupTable(ptrdiff_t aComponent, uint8_t aTable[256]) = 0; michael@0: michael@0: bool mDisableR; michael@0: bool mDisableG; michael@0: bool mDisableB; michael@0: bool mDisableA; michael@0: }; michael@0: michael@0: class FilterNodeTableTransferSoftware : public FilterNodeComponentTransferSoftware michael@0: { michael@0: public: michael@0: MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeTableTransferSoftware) michael@0: virtual const char* GetName() MOZ_OVERRIDE { return "TableTransfer"; } michael@0: using FilterNodeComponentTransferSoftware::SetAttribute; michael@0: virtual void SetAttribute(uint32_t aIndex, const Float* aFloat, uint32_t aSize) MOZ_OVERRIDE; michael@0: michael@0: protected: michael@0: virtual void FillLookupTable(ptrdiff_t aComponent, uint8_t aTable[256]) MOZ_OVERRIDE; michael@0: michael@0: private: michael@0: void FillLookupTableImpl(std::vector& aTableValues, uint8_t aTable[256]); michael@0: michael@0: std::vector mTableR; michael@0: std::vector mTableG; michael@0: std::vector mTableB; michael@0: std::vector mTableA; michael@0: }; michael@0: michael@0: class FilterNodeDiscreteTransferSoftware : public FilterNodeComponentTransferSoftware michael@0: { michael@0: public: michael@0: MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeDiscreteTransferSoftware) michael@0: virtual const char* GetName() MOZ_OVERRIDE { return "DiscreteTransfer"; } michael@0: using FilterNodeComponentTransferSoftware::SetAttribute; michael@0: virtual void SetAttribute(uint32_t aIndex, const Float* aFloat, uint32_t aSize) MOZ_OVERRIDE; michael@0: michael@0: protected: michael@0: virtual void FillLookupTable(ptrdiff_t aComponent, uint8_t aTable[256]) MOZ_OVERRIDE; michael@0: michael@0: private: michael@0: void FillLookupTableImpl(std::vector& aTableValues, uint8_t aTable[256]); michael@0: michael@0: std::vector mTableR; michael@0: std::vector mTableG; michael@0: std::vector mTableB; michael@0: std::vector mTableA; michael@0: }; michael@0: michael@0: class FilterNodeLinearTransferSoftware : public FilterNodeComponentTransferSoftware michael@0: { michael@0: public: michael@0: MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeLinearTransformSoftware) michael@0: FilterNodeLinearTransferSoftware(); michael@0: virtual const char* GetName() MOZ_OVERRIDE { return "LinearTransfer"; } michael@0: using FilterNodeComponentTransferSoftware::SetAttribute; michael@0: virtual void SetAttribute(uint32_t aIndex, Float aValue) MOZ_OVERRIDE; michael@0: michael@0: protected: michael@0: virtual void FillLookupTable(ptrdiff_t aComponent, uint8_t aTable[256]) MOZ_OVERRIDE; michael@0: michael@0: private: michael@0: void FillLookupTableImpl(Float aSlope, Float aIntercept, uint8_t aTable[256]); michael@0: michael@0: Float mSlopeR; michael@0: Float mSlopeG; michael@0: Float mSlopeB; michael@0: Float mSlopeA; michael@0: Float mInterceptR; michael@0: Float mInterceptG; michael@0: Float mInterceptB; michael@0: Float mInterceptA; michael@0: }; michael@0: michael@0: class FilterNodeGammaTransferSoftware : public FilterNodeComponentTransferSoftware michael@0: { michael@0: public: michael@0: MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeGammaTransferSoftware) michael@0: FilterNodeGammaTransferSoftware(); michael@0: virtual const char* GetName() MOZ_OVERRIDE { return "GammaTransfer"; } michael@0: using FilterNodeComponentTransferSoftware::SetAttribute; michael@0: virtual void SetAttribute(uint32_t aIndex, Float aValue) MOZ_OVERRIDE; michael@0: michael@0: protected: michael@0: virtual void FillLookupTable(ptrdiff_t aComponent, uint8_t aTable[256]) MOZ_OVERRIDE; michael@0: michael@0: private: michael@0: void FillLookupTableImpl(Float aAmplitude, Float aExponent, Float aOffset, uint8_t aTable[256]); michael@0: michael@0: Float mAmplitudeR; michael@0: Float mAmplitudeG; michael@0: Float mAmplitudeB; michael@0: Float mAmplitudeA; michael@0: Float mExponentR; michael@0: Float mExponentG; michael@0: Float mExponentB; michael@0: Float mExponentA; michael@0: Float mOffsetR; michael@0: Float mOffsetG; michael@0: Float mOffsetB; michael@0: Float mOffsetA; michael@0: }; michael@0: michael@0: class FilterNodeConvolveMatrixSoftware : public FilterNodeSoftware michael@0: { michael@0: public: michael@0: MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeConvolveMatrixSoftware) michael@0: FilterNodeConvolveMatrixSoftware(); michael@0: virtual const char* GetName() MOZ_OVERRIDE { return "ConvolveMatrix"; } michael@0: using FilterNodeSoftware::SetAttribute; michael@0: virtual void SetAttribute(uint32_t aIndex, const IntSize &aKernelSize) MOZ_OVERRIDE; michael@0: virtual void SetAttribute(uint32_t aIndex, const Float* aMatrix, uint32_t aSize) MOZ_OVERRIDE; michael@0: virtual void SetAttribute(uint32_t aIndex, Float aValue) MOZ_OVERRIDE; michael@0: virtual void SetAttribute(uint32_t aIndex, const Size &aKernelUnitLength) MOZ_OVERRIDE; michael@0: virtual void SetAttribute(uint32_t aIndex, const IntRect &aSourceRect) MOZ_OVERRIDE; michael@0: virtual void SetAttribute(uint32_t aIndex, const IntPoint &aTarget) MOZ_OVERRIDE; michael@0: virtual void SetAttribute(uint32_t aIndex, uint32_t aEdgeMode) MOZ_OVERRIDE; michael@0: virtual void SetAttribute(uint32_t aIndex, bool aPreserveAlpha) MOZ_OVERRIDE; michael@0: michael@0: protected: michael@0: virtual TemporaryRef Render(const IntRect& aRect) MOZ_OVERRIDE; michael@0: virtual IntRect GetOutputRectInRect(const IntRect& aRect) MOZ_OVERRIDE; michael@0: virtual int32_t InputIndex(uint32_t aInputEnumIndex) MOZ_OVERRIDE; michael@0: virtual void RequestFromInputsForRect(const IntRect &aRect) MOZ_OVERRIDE; michael@0: michael@0: private: michael@0: template michael@0: TemporaryRef DoRender(const IntRect& aRect, michael@0: CoordType aKernelUnitLengthX, michael@0: CoordType aKernelUnitLengthY); michael@0: michael@0: IntRect InflatedSourceRect(const IntRect &aDestRect); michael@0: IntRect InflatedDestRect(const IntRect &aSourceRect); michael@0: michael@0: IntSize mKernelSize; michael@0: std::vector mKernelMatrix; michael@0: Float mDivisor; michael@0: Float mBias; michael@0: IntPoint mTarget; michael@0: IntRect mSourceRect; michael@0: ConvolveMatrixEdgeMode mEdgeMode; michael@0: Size mKernelUnitLength; michael@0: bool mPreserveAlpha; michael@0: }; michael@0: michael@0: class FilterNodeDisplacementMapSoftware : public FilterNodeSoftware michael@0: { michael@0: public: michael@0: MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeDisplacementMapSoftware) michael@0: FilterNodeDisplacementMapSoftware(); michael@0: virtual const char* GetName() MOZ_OVERRIDE { return "DisplacementMap"; } michael@0: using FilterNodeSoftware::SetAttribute; michael@0: virtual void SetAttribute(uint32_t aIndex, Float aScale) MOZ_OVERRIDE; michael@0: virtual void SetAttribute(uint32_t aIndex, uint32_t aValue) MOZ_OVERRIDE; michael@0: michael@0: protected: michael@0: virtual TemporaryRef Render(const IntRect& aRect) MOZ_OVERRIDE; michael@0: virtual IntRect GetOutputRectInRect(const IntRect& aRect) MOZ_OVERRIDE; michael@0: virtual int32_t InputIndex(uint32_t aInputEnumIndex) MOZ_OVERRIDE; michael@0: virtual void RequestFromInputsForRect(const IntRect &aRect) MOZ_OVERRIDE; michael@0: michael@0: private: michael@0: IntRect InflatedSourceOrDestRect(const IntRect &aDestOrSourceRect); michael@0: michael@0: Float mScale; michael@0: ColorChannel mChannelX; michael@0: ColorChannel mChannelY; michael@0: }; michael@0: michael@0: class FilterNodeTurbulenceSoftware : public FilterNodeSoftware michael@0: { michael@0: public: michael@0: MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeTurbulenceSoftware) michael@0: FilterNodeTurbulenceSoftware(); michael@0: virtual const char* GetName() MOZ_OVERRIDE { return "Turbulence"; } michael@0: using FilterNodeSoftware::SetAttribute; michael@0: virtual void SetAttribute(uint32_t aIndex, const Size &aSize) MOZ_OVERRIDE; michael@0: virtual void SetAttribute(uint32_t aIndex, const IntRect &aRenderRect) MOZ_OVERRIDE; michael@0: virtual void SetAttribute(uint32_t aIndex, bool aStitchable) MOZ_OVERRIDE; michael@0: virtual void SetAttribute(uint32_t aIndex, uint32_t aValue) MOZ_OVERRIDE; michael@0: michael@0: protected: michael@0: virtual TemporaryRef Render(const IntRect& aRect) MOZ_OVERRIDE; michael@0: virtual IntRect GetOutputRectInRect(const IntRect& aRect) MOZ_OVERRIDE; michael@0: virtual int32_t InputIndex(uint32_t aInputEnumIndex) MOZ_OVERRIDE; michael@0: michael@0: private: michael@0: IntRect mRenderRect; michael@0: Size mBaseFrequency; michael@0: uint32_t mNumOctaves; michael@0: uint32_t mSeed; michael@0: bool mStitchable; michael@0: TurbulenceType mType; michael@0: }; michael@0: michael@0: class FilterNodeArithmeticCombineSoftware : public FilterNodeSoftware michael@0: { michael@0: public: michael@0: MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeArithmeticCombineSoftware) michael@0: FilterNodeArithmeticCombineSoftware(); michael@0: virtual const char* GetName() MOZ_OVERRIDE { return "ArithmeticCombine"; } michael@0: using FilterNodeSoftware::SetAttribute; michael@0: virtual void SetAttribute(uint32_t aIndex, const Float* aFloat, uint32_t aSize) MOZ_OVERRIDE; michael@0: michael@0: protected: michael@0: virtual TemporaryRef Render(const IntRect& aRect) MOZ_OVERRIDE; michael@0: virtual IntRect GetOutputRectInRect(const IntRect& aRect) MOZ_OVERRIDE; michael@0: virtual int32_t InputIndex(uint32_t aInputEnumIndex) MOZ_OVERRIDE; michael@0: virtual void RequestFromInputsForRect(const IntRect &aRect) MOZ_OVERRIDE; michael@0: michael@0: private: michael@0: Float mK1; michael@0: Float mK2; michael@0: Float mK3; michael@0: Float mK4; michael@0: }; michael@0: michael@0: class FilterNodeCompositeSoftware : public FilterNodeSoftware michael@0: { michael@0: public: michael@0: MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeCompositeSoftware) michael@0: FilterNodeCompositeSoftware(); michael@0: virtual const char* GetName() MOZ_OVERRIDE { return "Composite"; } michael@0: using FilterNodeSoftware::SetAttribute; michael@0: virtual void SetAttribute(uint32_t aIndex, uint32_t aOperator) MOZ_OVERRIDE; michael@0: michael@0: protected: michael@0: virtual TemporaryRef Render(const IntRect& aRect) MOZ_OVERRIDE; michael@0: virtual IntRect GetOutputRectInRect(const IntRect& aRect) MOZ_OVERRIDE; michael@0: virtual int32_t InputIndex(uint32_t aInputEnumIndex) MOZ_OVERRIDE; michael@0: virtual void RequestFromInputsForRect(const IntRect &aRect) MOZ_OVERRIDE; michael@0: michael@0: private: michael@0: CompositeOperator mOperator; michael@0: }; michael@0: michael@0: // Base class for FilterNodeGaussianBlurSoftware and michael@0: // FilterNodeDirectionalBlurSoftware. michael@0: class FilterNodeBlurXYSoftware : public FilterNodeSoftware michael@0: { michael@0: public: michael@0: MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeBlurXYSoftware) michael@0: protected: michael@0: virtual TemporaryRef Render(const IntRect& aRect) MOZ_OVERRIDE; michael@0: virtual IntRect GetOutputRectInRect(const IntRect& aRect) MOZ_OVERRIDE; michael@0: virtual int32_t InputIndex(uint32_t aInputEnumIndex) MOZ_OVERRIDE; michael@0: IntRect InflatedSourceOrDestRect(const IntRect &aDestRect); michael@0: virtual void RequestFromInputsForRect(const IntRect &aRect) MOZ_OVERRIDE; michael@0: michael@0: // Implemented by subclasses. michael@0: virtual Size StdDeviationXY() = 0; michael@0: }; michael@0: michael@0: class FilterNodeGaussianBlurSoftware : public FilterNodeBlurXYSoftware michael@0: { michael@0: public: michael@0: MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeGaussianBlurSoftware) michael@0: FilterNodeGaussianBlurSoftware(); michael@0: virtual const char* GetName() MOZ_OVERRIDE { return "GaussianBlur"; } michael@0: using FilterNodeSoftware::SetAttribute; michael@0: virtual void SetAttribute(uint32_t aIndex, Float aStdDeviation) MOZ_OVERRIDE; michael@0: michael@0: protected: michael@0: virtual Size StdDeviationXY() MOZ_OVERRIDE; michael@0: michael@0: private: michael@0: Float mStdDeviation; michael@0: }; michael@0: michael@0: class FilterNodeDirectionalBlurSoftware : public FilterNodeBlurXYSoftware michael@0: { michael@0: public: michael@0: MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeDirectionalBlurSoftware) michael@0: FilterNodeDirectionalBlurSoftware(); michael@0: virtual const char* GetName() MOZ_OVERRIDE { return "DirectionalBlur"; } michael@0: using FilterNodeSoftware::SetAttribute; michael@0: virtual void SetAttribute(uint32_t aIndex, Float aStdDeviation) MOZ_OVERRIDE; michael@0: virtual void SetAttribute(uint32_t aIndex, uint32_t aBlurDirection) MOZ_OVERRIDE; michael@0: michael@0: protected: michael@0: virtual Size StdDeviationXY() MOZ_OVERRIDE; michael@0: michael@0: private: michael@0: Float mStdDeviation; michael@0: BlurDirection mBlurDirection; michael@0: }; michael@0: michael@0: class FilterNodeCropSoftware : public FilterNodeSoftware michael@0: { michael@0: public: michael@0: MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeCropSoftware) michael@0: virtual const char* GetName() MOZ_OVERRIDE { return "Crop"; } michael@0: using FilterNodeSoftware::SetAttribute; michael@0: virtual void SetAttribute(uint32_t aIndex, const Rect &aSourceRect) MOZ_OVERRIDE; michael@0: michael@0: protected: michael@0: virtual TemporaryRef Render(const IntRect& aRect) MOZ_OVERRIDE; michael@0: virtual IntRect GetOutputRectInRect(const IntRect& aRect) MOZ_OVERRIDE; michael@0: virtual int32_t InputIndex(uint32_t aInputEnumIndex) MOZ_OVERRIDE; michael@0: virtual void RequestFromInputsForRect(const IntRect &aRect) MOZ_OVERRIDE; michael@0: michael@0: private: michael@0: IntRect mCropRect; michael@0: }; michael@0: michael@0: class FilterNodePremultiplySoftware : public FilterNodeSoftware michael@0: { michael@0: public: michael@0: MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodePremultiplySoftware) michael@0: virtual const char* GetName() MOZ_OVERRIDE { return "Premultiply"; } michael@0: protected: michael@0: virtual TemporaryRef Render(const IntRect& aRect) MOZ_OVERRIDE; michael@0: virtual IntRect GetOutputRectInRect(const IntRect& aRect) MOZ_OVERRIDE; michael@0: virtual int32_t InputIndex(uint32_t aInputEnumIndex) MOZ_OVERRIDE; michael@0: virtual void RequestFromInputsForRect(const IntRect &aRect) MOZ_OVERRIDE; michael@0: }; michael@0: michael@0: class FilterNodeUnpremultiplySoftware : public FilterNodeSoftware michael@0: { michael@0: public: michael@0: MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeUnpremultiplySoftware) michael@0: virtual const char* GetName() MOZ_OVERRIDE { return "Unpremultiply"; } michael@0: protected: michael@0: virtual TemporaryRef Render(const IntRect& aRect) MOZ_OVERRIDE; michael@0: virtual IntRect GetOutputRectInRect(const IntRect& aRect) MOZ_OVERRIDE; michael@0: virtual int32_t InputIndex(uint32_t aInputEnumIndex) MOZ_OVERRIDE; michael@0: virtual void RequestFromInputsForRect(const IntRect &aRect) MOZ_OVERRIDE; michael@0: }; michael@0: michael@0: template michael@0: class FilterNodeLightingSoftware : public FilterNodeSoftware michael@0: { michael@0: public: michael@0: #if defined(MOZILLA_INTERNAL_API) && (defined(DEBUG) || defined(FORCE_BUILD_REFCNT_LOGGING)) michael@0: // Helpers for refcounted michael@0: virtual const char* typeName() const MOZ_OVERRIDE { return mTypeName; } michael@0: virtual size_t typeSize() const MOZ_OVERRIDE { return sizeof(*this); } michael@0: #endif michael@0: explicit FilterNodeLightingSoftware(const char* aTypeName); michael@0: virtual const char* GetName() MOZ_OVERRIDE { return "Lighting"; } michael@0: using FilterNodeSoftware::SetAttribute; michael@0: virtual void SetAttribute(uint32_t aIndex, Float) MOZ_OVERRIDE; michael@0: virtual void SetAttribute(uint32_t aIndex, const Size &) MOZ_OVERRIDE; michael@0: virtual void SetAttribute(uint32_t aIndex, const Point3D &) MOZ_OVERRIDE; michael@0: virtual void SetAttribute(uint32_t aIndex, const Color &) MOZ_OVERRIDE; michael@0: michael@0: protected: michael@0: virtual TemporaryRef Render(const IntRect& aRect) MOZ_OVERRIDE; michael@0: virtual IntRect GetOutputRectInRect(const IntRect& aRect) MOZ_OVERRIDE; michael@0: virtual int32_t InputIndex(uint32_t aInputEnumIndex) MOZ_OVERRIDE; michael@0: virtual void RequestFromInputsForRect(const IntRect &aRect) MOZ_OVERRIDE; michael@0: michael@0: private: michael@0: template michael@0: TemporaryRef DoRender(const IntRect& aRect, michael@0: CoordType aKernelUnitLengthX, michael@0: CoordType aKernelUnitLengthY); michael@0: michael@0: LightType mLight; michael@0: LightingType mLighting; michael@0: Float mSurfaceScale; michael@0: Size mKernelUnitLength; michael@0: Color mColor; michael@0: #if defined(MOZILLA_INTERNAL_API) && (defined(DEBUG) || defined(FORCE_BUILD_REFCNT_LOGGING)) michael@0: const char* mTypeName; michael@0: #endif michael@0: }; michael@0: michael@0: } michael@0: } michael@0: michael@0: #endif // _MOZILLA_GFX_FILTERNODESOFTWARE_H_