1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/2d/DrawTargetDual.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,164 @@ 1.4 +/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- 1.5 + * This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#ifndef MOZILLA_GFX_DRAWTARGETDUAL_H_ 1.10 +#define MOZILLA_GFX_DRAWTARGETDUAL_H_ 1.11 + 1.12 +#include <vector> 1.13 +#include <sstream> 1.14 + 1.15 +#include "SourceSurfaceDual.h" 1.16 + 1.17 +#include "2D.h" 1.18 +#include "Filters.h" 1.19 + 1.20 +namespace mozilla { 1.21 +namespace gfx { 1.22 + 1.23 +#define FORWARD_FUNCTION(funcName) \ 1.24 + virtual void funcName() { mA->funcName(); mB->funcName(); } 1.25 +#define FORWARD_FUNCTION1(funcName, var1Type, var1Name) \ 1.26 + virtual void funcName(var1Type var1Name) { mA->funcName(var1Name); mB->funcName(var1Name); } 1.27 + 1.28 +/* This is a special type of DrawTarget. It duplicates all drawing calls 1.29 + * accross two drawtargets. An exception to this is when a snapshot of another 1.30 + * dual DrawTarget is used as the source for any surface data. In this case 1.31 + * the snapshot of the first source DrawTarget is used as a source for the call 1.32 + * to the first destination DrawTarget (mA) and the snapshot of the second 1.33 + * source DrawTarget is used at the source for the second destination 1.34 + * DrawTarget (mB). This class facilitates black-background/white-background 1.35 + * drawing for per-component alpha extraction for backends which do not support 1.36 + * native component alpha. 1.37 + */ 1.38 +class DrawTargetDual : public DrawTarget 1.39 +{ 1.40 +public: 1.41 + MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(DrawTargetDual) 1.42 + DrawTargetDual(DrawTarget *aA, DrawTarget *aB) 1.43 + : mA(aA) 1.44 + , mB(aB) 1.45 + { 1.46 + mFormat = aA->GetFormat(); 1.47 + } 1.48 + 1.49 + virtual BackendType GetType() const { return mA->GetType(); } 1.50 + virtual TemporaryRef<SourceSurface> Snapshot() { return new SourceSurfaceDual(mA, mB); } 1.51 + virtual IntSize GetSize() { return mA->GetSize(); } 1.52 + 1.53 + FORWARD_FUNCTION(Flush) 1.54 + FORWARD_FUNCTION1(PushClip, const Path *, aPath) 1.55 + FORWARD_FUNCTION1(PushClipRect, const Rect &, aRect) 1.56 + FORWARD_FUNCTION(PopClip) 1.57 + FORWARD_FUNCTION1(ClearRect, const Rect &, aRect) 1.58 + 1.59 + virtual void SetTransform(const Matrix &aTransform) { 1.60 + mTransform = aTransform; 1.61 + mA->SetTransform(aTransform); 1.62 + mB->SetTransform(aTransform); 1.63 + } 1.64 + 1.65 + virtual void DrawSurface(SourceSurface *aSurface, const Rect &aDest, const Rect & aSource, 1.66 + const DrawSurfaceOptions &aSurfOptions, const DrawOptions &aOptions); 1.67 + 1.68 + virtual void DrawFilter(FilterNode *aNode, 1.69 + const Rect &aSourceRect, 1.70 + const Point &aDestPoint, 1.71 + const DrawOptions &aOptions = DrawOptions()) 1.72 + { 1.73 + mA->DrawFilter(aNode, aSourceRect, aDestPoint, aOptions); 1.74 + mB->DrawFilter(aNode, aSourceRect, aDestPoint, aOptions); 1.75 + } 1.76 + 1.77 + virtual void MaskSurface(const Pattern &aSource, 1.78 + SourceSurface *aMask, 1.79 + Point aOffset, 1.80 + const DrawOptions &aOptions = DrawOptions()); 1.81 + 1.82 + virtual void DrawSurfaceWithShadow(SourceSurface *aSurface, const Point &aDest, 1.83 + const Color &aColor, const Point &aOffset, 1.84 + Float aSigma, CompositionOp aOp); 1.85 + 1.86 + virtual void CopySurface(SourceSurface *aSurface, const IntRect &aSourceRect, 1.87 + const IntPoint &aDestination); 1.88 + 1.89 + virtual void FillRect(const Rect &aRect, const Pattern &aPattern, const DrawOptions &aOptions); 1.90 + 1.91 + virtual void StrokeRect(const Rect &aRect, const Pattern &aPattern, 1.92 + const StrokeOptions &aStrokeOptions, const DrawOptions &aOptions); 1.93 + 1.94 + virtual void StrokeLine(const Point &aStart, const Point &aEnd, const Pattern &aPattern, 1.95 + const StrokeOptions &aStrokeOptions, const DrawOptions &aOptions); 1.96 + 1.97 + virtual void Stroke(const Path *aPath, const Pattern &aPattern, 1.98 + const StrokeOptions &aStrokeOptions, const DrawOptions &aOptions); 1.99 + 1.100 + virtual void Fill(const Path *aPath, const Pattern &aPattern, const DrawOptions &aOptions); 1.101 + 1.102 + virtual void FillGlyphs(ScaledFont *aScaledFont, const GlyphBuffer &aBuffer, 1.103 + const Pattern &aPattern, const DrawOptions &aOptions, 1.104 + const GlyphRenderingOptions *aRenderingOptions); 1.105 + 1.106 + virtual void Mask(const Pattern &aSource, const Pattern &aMask, const DrawOptions &aOptions); 1.107 + 1.108 + virtual TemporaryRef<SourceSurface> 1.109 + CreateSourceSurfaceFromData(unsigned char *aData, 1.110 + const IntSize &aSize, 1.111 + int32_t aStride, 1.112 + SurfaceFormat aFormat) const 1.113 + { 1.114 + return mA->CreateSourceSurfaceFromData(aData, aSize, aStride, aFormat); 1.115 + } 1.116 + 1.117 + virtual TemporaryRef<SourceSurface> OptimizeSourceSurface(SourceSurface *aSurface) const 1.118 + { 1.119 + return mA->OptimizeSourceSurface(aSurface); 1.120 + } 1.121 + 1.122 + virtual TemporaryRef<SourceSurface> 1.123 + CreateSourceSurfaceFromNativeSurface(const NativeSurface &aSurface) const 1.124 + { 1.125 + return mA->CreateSourceSurfaceFromNativeSurface(aSurface); 1.126 + } 1.127 + 1.128 + virtual TemporaryRef<DrawTarget> 1.129 + CreateSimilarDrawTarget(const IntSize &aSize, SurfaceFormat aFormat) const; 1.130 + 1.131 + virtual TemporaryRef<PathBuilder> CreatePathBuilder(FillRule aFillRule = FillRule::FILL_WINDING) const 1.132 + { 1.133 + return mA->CreatePathBuilder(aFillRule); 1.134 + } 1.135 + 1.136 + virtual TemporaryRef<GradientStops> 1.137 + CreateGradientStops(GradientStop *aStops, 1.138 + uint32_t aNumStops, 1.139 + ExtendMode aExtendMode = ExtendMode::CLAMP) const 1.140 + { 1.141 + return mA->CreateGradientStops(aStops, aNumStops, aExtendMode); 1.142 + } 1.143 + 1.144 + virtual TemporaryRef<FilterNode> CreateFilter(FilterType aType) 1.145 + { 1.146 + return mA->CreateFilter(aType); 1.147 + } 1.148 + 1.149 + virtual void *GetNativeSurface(NativeSurfaceType aType) 1.150 + { 1.151 + return nullptr; 1.152 + } 1.153 + 1.154 + virtual bool IsDualDrawTarget() 1.155 + { 1.156 + return true; 1.157 + } 1.158 + 1.159 +private: 1.160 + RefPtr<DrawTarget> mA; 1.161 + RefPtr<DrawTarget> mB; 1.162 +}; 1.163 + 1.164 +} 1.165 +} 1.166 + 1.167 +#endif /* MOZILLA_GFX_DRAWTARGETDUAL_H_ */