1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/2d/DrawTargetDual.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,193 @@ 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 +#include "DrawTargetDual.h" 1.10 +#include "Tools.h" 1.11 + 1.12 +namespace mozilla { 1.13 +namespace gfx { 1.14 + 1.15 +class DualSurface 1.16 +{ 1.17 +public: 1.18 + inline DualSurface(SourceSurface *aSurface) 1.19 + { 1.20 + if (aSurface->GetType() != SurfaceType::DUAL_DT) { 1.21 + mA = mB = aSurface; 1.22 + return; 1.23 + } 1.24 + 1.25 + SourceSurfaceDual *ssDual = 1.26 + static_cast<SourceSurfaceDual*>(aSurface); 1.27 + mA = ssDual->mA; 1.28 + mB = ssDual->mB; 1.29 + } 1.30 + 1.31 + SourceSurface *mA; 1.32 + SourceSurface *mB; 1.33 +}; 1.34 + 1.35 +/* This only needs to split patterns up for SurfacePatterns. Only in that 1.36 + * case can we be dealing with a 'dual' source (SourceSurfaceDual) and do 1.37 + * we need to pass separate patterns into our destination DrawTargets. 1.38 + */ 1.39 +class DualPattern 1.40 +{ 1.41 +public: 1.42 + inline DualPattern(const Pattern &aPattern) 1.43 + : mPatternsInitialized(false) 1.44 + { 1.45 + if (aPattern.GetType() != PatternType::SURFACE) { 1.46 + mA = mB = &aPattern; 1.47 + return; 1.48 + } 1.49 + 1.50 + const SurfacePattern *surfPat = 1.51 + static_cast<const SurfacePattern*>(&aPattern); 1.52 + 1.53 + if (surfPat->mSurface->GetType() != SurfaceType::DUAL_DT) { 1.54 + mA = mB = &aPattern; 1.55 + return; 1.56 + } 1.57 + 1.58 + const SourceSurfaceDual *ssDual = 1.59 + static_cast<const SourceSurfaceDual*>(surfPat->mSurface.get()); 1.60 + mA = new (mSurfPatA.addr()) SurfacePattern(ssDual->mA, surfPat->mExtendMode, 1.61 + surfPat->mMatrix, surfPat->mFilter); 1.62 + mB = new (mSurfPatB.addr()) SurfacePattern(ssDual->mB, surfPat->mExtendMode, 1.63 + surfPat->mMatrix, surfPat->mFilter); 1.64 + mPatternsInitialized = true; 1.65 + } 1.66 + 1.67 + inline ~DualPattern() 1.68 + { 1.69 + if (mPatternsInitialized) { 1.70 + mA->~Pattern(); 1.71 + mB->~Pattern(); 1.72 + } 1.73 + } 1.74 + 1.75 + ClassStorage<SurfacePattern> mSurfPatA; 1.76 + ClassStorage<SurfacePattern> mSurfPatB; 1.77 + 1.78 + const Pattern *mA; 1.79 + const Pattern *mB; 1.80 + 1.81 + bool mPatternsInitialized; 1.82 +}; 1.83 + 1.84 +void 1.85 +DrawTargetDual::DrawSurface(SourceSurface *aSurface, const Rect &aDest, const Rect &aSource, 1.86 + const DrawSurfaceOptions &aSurfOptions, const DrawOptions &aOptions) 1.87 +{ 1.88 + DualSurface surface(aSurface); 1.89 + mA->DrawSurface(surface.mA, aDest, aSource, aSurfOptions, aOptions); 1.90 + mB->DrawSurface(surface.mB, aDest, aSource, aSurfOptions, aOptions); 1.91 +} 1.92 + 1.93 +void 1.94 +DrawTargetDual::DrawSurfaceWithShadow(SourceSurface *aSurface, const Point &aDest, 1.95 + const Color &aColor, const Point &aOffset, 1.96 + Float aSigma, CompositionOp aOp) 1.97 +{ 1.98 + DualSurface surface(aSurface); 1.99 + mA->DrawSurfaceWithShadow(surface.mA, aDest, aColor, aOffset, aSigma, aOp); 1.100 + mB->DrawSurfaceWithShadow(surface.mB, aDest, aColor, aOffset, aSigma, aOp); 1.101 +} 1.102 + 1.103 +void 1.104 +DrawTargetDual::MaskSurface(const Pattern &aSource, 1.105 + SourceSurface *aMask, 1.106 + Point aOffset, 1.107 + const DrawOptions &aOptions) 1.108 +{ 1.109 + DualPattern source(aSource); 1.110 + DualSurface mask(aMask); 1.111 + mA->MaskSurface(*source.mA, mask.mA, aOffset, aOptions); 1.112 + mB->MaskSurface(*source.mB, mask.mB, aOffset, aOptions); 1.113 +} 1.114 + 1.115 +void 1.116 +DrawTargetDual::CopySurface(SourceSurface *aSurface, const IntRect &aSourceRect, 1.117 + const IntPoint &aDestination) 1.118 +{ 1.119 + DualSurface surface(aSurface); 1.120 + mA->CopySurface(surface.mA, aSourceRect, aDestination); 1.121 + mB->CopySurface(surface.mB, aSourceRect, aDestination); 1.122 +} 1.123 + 1.124 +void 1.125 +DrawTargetDual::FillRect(const Rect &aRect, const Pattern &aPattern, const DrawOptions &aOptions) 1.126 +{ 1.127 + DualPattern pattern(aPattern); 1.128 + mA->FillRect(aRect, *pattern.mA, aOptions); 1.129 + mB->FillRect(aRect, *pattern.mB, aOptions); 1.130 +} 1.131 + 1.132 +void 1.133 +DrawTargetDual::StrokeRect(const Rect &aRect, const Pattern &aPattern, 1.134 + const StrokeOptions &aStrokeOptions, const DrawOptions &aOptions) 1.135 +{ 1.136 + DualPattern pattern(aPattern); 1.137 + mA->StrokeRect(aRect, *pattern.mA, aStrokeOptions, aOptions); 1.138 + mB->StrokeRect(aRect, *pattern.mB, aStrokeOptions, aOptions); 1.139 +} 1.140 + 1.141 +void 1.142 +DrawTargetDual::StrokeLine(const Point &aStart, const Point &aEnd, const Pattern &aPattern, 1.143 + const StrokeOptions &aStrokeOptions, const DrawOptions &aOptions) 1.144 +{ 1.145 + DualPattern pattern(aPattern); 1.146 + mA->StrokeLine(aStart, aEnd, *pattern.mA, aStrokeOptions, aOptions); 1.147 + mB->StrokeLine(aStart, aEnd, *pattern.mB, aStrokeOptions, aOptions); 1.148 +} 1.149 + 1.150 +void 1.151 +DrawTargetDual::Stroke(const Path *aPath, const Pattern &aPattern, 1.152 + const StrokeOptions &aStrokeOptions, const DrawOptions &aOptions) 1.153 +{ 1.154 + DualPattern pattern(aPattern); 1.155 + mA->Stroke(aPath, *pattern.mA, aStrokeOptions, aOptions); 1.156 + mB->Stroke(aPath, *pattern.mB, aStrokeOptions, aOptions); 1.157 +} 1.158 + 1.159 +void 1.160 +DrawTargetDual::Fill(const Path *aPath, const Pattern &aPattern, const DrawOptions &aOptions) 1.161 +{ 1.162 + DualPattern pattern(aPattern); 1.163 + mA->Fill(aPath, *pattern.mA, aOptions); 1.164 + mB->Fill(aPath, *pattern.mB, aOptions); 1.165 +} 1.166 + 1.167 +void 1.168 +DrawTargetDual::FillGlyphs(ScaledFont *aScaledFont, const GlyphBuffer &aBuffer, 1.169 + const Pattern &aPattern, const DrawOptions &aOptions, 1.170 + const GlyphRenderingOptions *aRenderingOptions) 1.171 +{ 1.172 + DualPattern pattern(aPattern); 1.173 + mA->FillGlyphs(aScaledFont, aBuffer, *pattern.mA, aOptions, aRenderingOptions); 1.174 + mB->FillGlyphs(aScaledFont, aBuffer, *pattern.mB, aOptions, aRenderingOptions); 1.175 +} 1.176 + 1.177 +void 1.178 +DrawTargetDual::Mask(const Pattern &aSource, const Pattern &aMask, const DrawOptions &aOptions) 1.179 +{ 1.180 + DualPattern source(aSource); 1.181 + DualPattern mask(aMask); 1.182 + mA->Mask(*source.mA, *mask.mA, aOptions); 1.183 + mB->Mask(*source.mB, *mask.mB, aOptions); 1.184 +} 1.185 + 1.186 +TemporaryRef<DrawTarget> 1.187 +DrawTargetDual::CreateSimilarDrawTarget(const IntSize &aSize, SurfaceFormat aFormat) const 1.188 +{ 1.189 + RefPtr<DrawTarget> dtA = mA->CreateSimilarDrawTarget(aSize, aFormat); 1.190 + RefPtr<DrawTarget> dtB = mB->CreateSimilarDrawTarget(aSize, aFormat); 1.191 + 1.192 + return new DrawTargetDual(dtA, dtB); 1.193 +} 1.194 + 1.195 +} 1.196 +}