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_DRAWTARGETDUAL_H_ michael@0: #define MOZILLA_GFX_DRAWTARGETDUAL_H_ michael@0: michael@0: #include michael@0: #include michael@0: michael@0: #include "SourceSurfaceDual.h" michael@0: michael@0: #include "2D.h" michael@0: #include "Filters.h" michael@0: michael@0: namespace mozilla { michael@0: namespace gfx { michael@0: michael@0: #define FORWARD_FUNCTION(funcName) \ michael@0: virtual void funcName() { mA->funcName(); mB->funcName(); } michael@0: #define FORWARD_FUNCTION1(funcName, var1Type, var1Name) \ michael@0: virtual void funcName(var1Type var1Name) { mA->funcName(var1Name); mB->funcName(var1Name); } michael@0: michael@0: /* This is a special type of DrawTarget. It duplicates all drawing calls michael@0: * accross two drawtargets. An exception to this is when a snapshot of another michael@0: * dual DrawTarget is used as the source for any surface data. In this case michael@0: * the snapshot of the first source DrawTarget is used as a source for the call michael@0: * to the first destination DrawTarget (mA) and the snapshot of the second michael@0: * source DrawTarget is used at the source for the second destination michael@0: * DrawTarget (mB). This class facilitates black-background/white-background michael@0: * drawing for per-component alpha extraction for backends which do not support michael@0: * native component alpha. michael@0: */ michael@0: class DrawTargetDual : public DrawTarget michael@0: { michael@0: public: michael@0: MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(DrawTargetDual) michael@0: DrawTargetDual(DrawTarget *aA, DrawTarget *aB) michael@0: : mA(aA) michael@0: , mB(aB) michael@0: { michael@0: mFormat = aA->GetFormat(); michael@0: } michael@0: michael@0: virtual BackendType GetType() const { return mA->GetType(); } michael@0: virtual TemporaryRef Snapshot() { return new SourceSurfaceDual(mA, mB); } michael@0: virtual IntSize GetSize() { return mA->GetSize(); } michael@0: michael@0: FORWARD_FUNCTION(Flush) michael@0: FORWARD_FUNCTION1(PushClip, const Path *, aPath) michael@0: FORWARD_FUNCTION1(PushClipRect, const Rect &, aRect) michael@0: FORWARD_FUNCTION(PopClip) michael@0: FORWARD_FUNCTION1(ClearRect, const Rect &, aRect) michael@0: michael@0: virtual void SetTransform(const Matrix &aTransform) { michael@0: mTransform = aTransform; michael@0: mA->SetTransform(aTransform); michael@0: mB->SetTransform(aTransform); michael@0: } michael@0: michael@0: virtual void DrawSurface(SourceSurface *aSurface, const Rect &aDest, const Rect & aSource, michael@0: const DrawSurfaceOptions &aSurfOptions, const DrawOptions &aOptions); michael@0: michael@0: virtual void DrawFilter(FilterNode *aNode, michael@0: const Rect &aSourceRect, michael@0: const Point &aDestPoint, michael@0: const DrawOptions &aOptions = DrawOptions()) michael@0: { michael@0: mA->DrawFilter(aNode, aSourceRect, aDestPoint, aOptions); michael@0: mB->DrawFilter(aNode, aSourceRect, aDestPoint, aOptions); michael@0: } michael@0: michael@0: virtual void MaskSurface(const Pattern &aSource, michael@0: SourceSurface *aMask, michael@0: Point aOffset, michael@0: const DrawOptions &aOptions = DrawOptions()); michael@0: michael@0: virtual void DrawSurfaceWithShadow(SourceSurface *aSurface, const Point &aDest, michael@0: const Color &aColor, const Point &aOffset, michael@0: Float aSigma, CompositionOp aOp); michael@0: michael@0: virtual void CopySurface(SourceSurface *aSurface, const IntRect &aSourceRect, michael@0: const IntPoint &aDestination); michael@0: michael@0: virtual void FillRect(const Rect &aRect, const Pattern &aPattern, const DrawOptions &aOptions); michael@0: michael@0: virtual void StrokeRect(const Rect &aRect, const Pattern &aPattern, michael@0: const StrokeOptions &aStrokeOptions, const DrawOptions &aOptions); michael@0: michael@0: virtual void StrokeLine(const Point &aStart, const Point &aEnd, const Pattern &aPattern, michael@0: const StrokeOptions &aStrokeOptions, const DrawOptions &aOptions); michael@0: michael@0: virtual void Stroke(const Path *aPath, const Pattern &aPattern, michael@0: const StrokeOptions &aStrokeOptions, const DrawOptions &aOptions); michael@0: michael@0: virtual void Fill(const Path *aPath, const Pattern &aPattern, const DrawOptions &aOptions); michael@0: michael@0: virtual void FillGlyphs(ScaledFont *aScaledFont, const GlyphBuffer &aBuffer, michael@0: const Pattern &aPattern, const DrawOptions &aOptions, michael@0: const GlyphRenderingOptions *aRenderingOptions); michael@0: michael@0: virtual void Mask(const Pattern &aSource, const Pattern &aMask, const DrawOptions &aOptions); michael@0: michael@0: virtual TemporaryRef michael@0: CreateSourceSurfaceFromData(unsigned char *aData, michael@0: const IntSize &aSize, michael@0: int32_t aStride, michael@0: SurfaceFormat aFormat) const michael@0: { michael@0: return mA->CreateSourceSurfaceFromData(aData, aSize, aStride, aFormat); michael@0: } michael@0: michael@0: virtual TemporaryRef OptimizeSourceSurface(SourceSurface *aSurface) const michael@0: { michael@0: return mA->OptimizeSourceSurface(aSurface); michael@0: } michael@0: michael@0: virtual TemporaryRef michael@0: CreateSourceSurfaceFromNativeSurface(const NativeSurface &aSurface) const michael@0: { michael@0: return mA->CreateSourceSurfaceFromNativeSurface(aSurface); michael@0: } michael@0: michael@0: virtual TemporaryRef michael@0: CreateSimilarDrawTarget(const IntSize &aSize, SurfaceFormat aFormat) const; michael@0: michael@0: virtual TemporaryRef CreatePathBuilder(FillRule aFillRule = FillRule::FILL_WINDING) const michael@0: { michael@0: return mA->CreatePathBuilder(aFillRule); michael@0: } michael@0: michael@0: virtual TemporaryRef michael@0: CreateGradientStops(GradientStop *aStops, michael@0: uint32_t aNumStops, michael@0: ExtendMode aExtendMode = ExtendMode::CLAMP) const michael@0: { michael@0: return mA->CreateGradientStops(aStops, aNumStops, aExtendMode); michael@0: } michael@0: michael@0: virtual TemporaryRef CreateFilter(FilterType aType) michael@0: { michael@0: return mA->CreateFilter(aType); michael@0: } michael@0: michael@0: virtual void *GetNativeSurface(NativeSurfaceType aType) michael@0: { michael@0: return nullptr; michael@0: } michael@0: michael@0: virtual bool IsDualDrawTarget() michael@0: { michael@0: return true; michael@0: } michael@0: michael@0: private: michael@0: RefPtr mA; michael@0: RefPtr mB; michael@0: }; michael@0: michael@0: } michael@0: } michael@0: michael@0: #endif /* MOZILLA_GFX_DRAWTARGETDUAL_H_ */