Bug 740815 - Part 1: Add DrawTargetDual to Azure for Component Alpha drawing. r=jrmuizel
authorBas Schouten <bschouten@mozilla.com>
Tue, 03 Apr 2012 22:25:52 +0200
changeset 90915 3dd886d95c55d36646d5a284fa399e3bc8290649
parent 90914 c95b597b5f0823d311d6e56a68e2ff657222ba49
child 90916 e36fabc31211b8bdb069a7d2a2e66681501ec2e3
push id7919
push userbschouten@mozilla.com
push dateTue, 03 Apr 2012 20:26:24 +0000
treeherdermozilla-inbound@9fa58c6060c5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjrmuizel
bugs740815
milestone14.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 740815 - Part 1: Add DrawTargetDual to Azure for Component Alpha drawing. r=jrmuizel
gfx/2d/2D.h
gfx/2d/DrawTargetDual.cpp
gfx/2d/DrawTargetDual.h
gfx/2d/Factory.cpp
gfx/2d/Makefile.in
gfx/2d/SourceSurfaceDual.h
gfx/2d/Tools.h
gfx/2d/Types.h
--- a/gfx/2d/2D.h
+++ b/gfx/2d/2D.h
@@ -824,16 +824,21 @@ public:
    * surface.
    */
   static TemporaryRef<DataSourceSurface>
     CreateDataSourceSurfaceFromData(unsigned char *aData, int32_t aStride,
                                     const IntSize &aSize, SurfaceFormat aFormat);
 
 #ifdef WIN32
   static TemporaryRef<DrawTarget> CreateDrawTargetForD3D10Texture(ID3D10Texture2D *aTexture, SurfaceFormat aFormat);
+  static TemporaryRef<DrawTarget>
+    CreateDualDrawTargetForD3D10Textures(ID3D10Texture2D *aTextureA,
+                                         ID3D10Texture2D *aTextureB,
+                                         SurfaceFormat aFormat);
+
   static void SetDirect3D10Device(ID3D10Device1 *aDevice);
   static ID3D10Device1 *GetDirect3D10Device();
 
   static TemporaryRef<GlyphRenderingOptions>
     CreateDWriteGlyphRenderingOptions(IDWriteRenderingParams *aParams);
 
 private:
   static ID3D10Device1 *mD3D10Device;
new file mode 100644
--- /dev/null
+++ b/gfx/2d/DrawTargetDual.cpp
@@ -0,0 +1,213 @@
+/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
+  * ***** BEGIN LICENSE BLOCK *****
+  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+  *
+  * The contents of this file are subject to the Mozilla Public License Version
+  * 1.1 (the "License"); you may not use this file except in compliance with
+  * the License. You may obtain a copy of the License at
+  * http://www.mozilla.org/MPL/
+  *
+  * Software distributed under the License is distributed on an "AS IS" basis,
+  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+  * for the specific language governing rights and limitations under the
+  * License.
+  *
+  * The Original Code is Mozilla Corporation code.
+  *
+  * The Initial Developer of the Original Code is Mozilla Foundation.
+  * Portions created by the Initial Developer are Copyright (C) 2011
+  * the Initial Developer. All Rights Reserved.
+  *
+  * Contributor(s):
+  *   Bas Schouten <bschouten@mozilla.com>
+  *
+  * Alternatively, the contents of this file may be used under the terms of
+  * either the GNU General Public License Version 2 or later (the "GPL"), or
+  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+  * in which case the provisions of the GPL or the LGPL are applicable instead
+  * of those above. If you wish to allow use of your version of this file only
+  * under the terms of either the GPL or the LGPL, and not to allow others to
+  * use your version of this file under the terms of the MPL, indicate your
+  * decision by deleting the provisions above and replace them with the notice
+  * and other provisions required by the GPL or the LGPL. If you do not delete
+  * the provisions above, a recipient may use your version of this file under
+  * the terms of any one of the MPL, the GPL or the LGPL.
+  *
+  * ***** END LICENSE BLOCK ***** */
+     
+#include "DrawTargetDual.h"
+#include "Tools.h"
+
+namespace mozilla {
+namespace gfx {
+
+class DualSurface
+{
+public:
+  inline DualSurface(SourceSurface *aSurface)
+  {
+    if (aSurface->GetType() != SURFACE_DUAL_DT) {
+      mA = mB = aSurface;
+      return;
+    }
+
+    SourceSurfaceDual *ssDual =
+      static_cast<SourceSurfaceDual*>(aSurface);
+    mA = ssDual->mA;
+    mB = ssDual->mB;
+  }
+
+  SourceSurface *mA;
+  SourceSurface *mB;
+};
+
+/* This only needs to split patterns up for SurfacePatterns. Only in that
+ * case can we be dealing with a 'dual' source (SourceSurfaceDual) and do
+ * we need to pass separate patterns into our destination DrawTargets.
+ */
+class DualPattern
+{
+public:
+  inline DualPattern(const Pattern &aPattern)
+    : mPatternsInitialized(false)
+  {
+    if (aPattern.GetType() != PATTERN_SURFACE) {
+      mA = mB = &aPattern;
+      return;
+    }
+
+    const SurfacePattern *surfPat =
+      static_cast<const SurfacePattern*>(&aPattern);
+
+    if (surfPat->mSurface->GetType() != SURFACE_DUAL_DT) {
+      mA = mB = &aPattern;
+      return;
+    }
+
+    const SourceSurfaceDual *ssDual =
+      static_cast<const SourceSurfaceDual*>(surfPat->mSurface.get());
+    mA = new (mSurfPatA.addr()) SurfacePattern(ssDual->mA, surfPat->mExtendMode,
+                                               surfPat->mMatrix, surfPat->mFilter);
+    mB = new (mSurfPatB.addr()) SurfacePattern(ssDual->mB, surfPat->mExtendMode,
+                                               surfPat->mMatrix, surfPat->mFilter);
+    mPatternsInitialized = true;
+  }
+
+  inline ~DualPattern()
+  {
+    if (mPatternsInitialized) {
+      mA->~Pattern();
+      mB->~Pattern();
+    }
+  }
+
+  ClassStorage<SurfacePattern> mSurfPatA;
+  ClassStorage<SurfacePattern> mSurfPatB;
+
+  const Pattern *mA;
+  const Pattern *mB;
+
+  bool mPatternsInitialized;
+};
+
+void
+DrawTargetDual::DrawSurface(SourceSurface *aSurface, const Rect &aDest, const Rect &aSource,
+                            const DrawSurfaceOptions &aSurfOptions, const DrawOptions &aOptions)
+{
+  DualSurface surface(aSurface);
+  mA->DrawSurface(surface.mA, aDest, aSource, aSurfOptions, aOptions);
+  mB->DrawSurface(surface.mB, aDest, aSource, aSurfOptions, aOptions);
+}
+
+void
+DrawTargetDual::DrawSurfaceWithShadow(SourceSurface *aSurface, const Point &aDest,
+                                      const Color &aColor, const Point &aOffset,
+                                      Float aSigma, CompositionOp aOp)
+{
+  DualSurface surface(aSurface);
+  mA->DrawSurfaceWithShadow(surface.mA, aDest, aColor, aOffset, aSigma, aOp);
+  mB->DrawSurfaceWithShadow(surface.mB, aDest, aColor, aOffset, aSigma, aOp);
+}
+
+void
+DrawTargetDual::CopySurface(SourceSurface *aSurface, const IntRect &aSourceRect,
+                            const IntPoint &aDestination)
+{
+  DualSurface surface(aSurface);
+  mA->CopySurface(surface.mA, aSourceRect, aDestination);
+  mB->CopySurface(surface.mB, aSourceRect, aDestination);
+}
+
+void
+DrawTargetDual::FillRect(const Rect &aRect, const Pattern &aPattern, const DrawOptions &aOptions)
+{
+  DualPattern pattern(aPattern);
+  mA->FillRect(aRect, *pattern.mA, aOptions);
+  mB->FillRect(aRect, *pattern.mB, aOptions);
+}
+
+void
+DrawTargetDual::StrokeRect(const Rect &aRect, const Pattern &aPattern,
+                           const StrokeOptions &aStrokeOptions, const DrawOptions &aOptions)
+{
+  DualPattern pattern(aPattern);
+  mA->StrokeRect(aRect, *pattern.mA, aStrokeOptions, aOptions);
+  mB->StrokeRect(aRect, *pattern.mB, aStrokeOptions, aOptions);
+}
+
+void
+DrawTargetDual::StrokeLine(const Point &aStart, const Point &aEnd, const Pattern &aPattern,
+                           const StrokeOptions &aStrokeOptions, const DrawOptions &aOptions)
+{
+  DualPattern pattern(aPattern);
+  mA->StrokeLine(aStart, aEnd, *pattern.mA, aStrokeOptions, aOptions);
+  mB->StrokeLine(aStart, aEnd, *pattern.mB, aStrokeOptions, aOptions);
+}
+
+void
+DrawTargetDual::Stroke(const Path *aPath, const Pattern &aPattern,
+                       const StrokeOptions &aStrokeOptions, const DrawOptions &aOptions)
+{
+  DualPattern pattern(aPattern);
+  mA->Stroke(aPath, *pattern.mA, aStrokeOptions, aOptions);
+  mB->Stroke(aPath, *pattern.mB, aStrokeOptions, aOptions);
+}
+
+void
+DrawTargetDual::Fill(const Path *aPath, const Pattern &aPattern, const DrawOptions &aOptions)
+{
+  DualPattern pattern(aPattern);
+  mA->Fill(aPath, *pattern.mA, aOptions);
+  mB->Fill(aPath, *pattern.mB, aOptions);
+}
+
+void
+DrawTargetDual::FillGlyphs(ScaledFont *aScaledFont, const GlyphBuffer &aBuffer,
+                           const Pattern &aPattern, const DrawOptions &aOptions,
+                           const GlyphRenderingOptions *aRenderingOptions)
+{
+  DualPattern pattern(aPattern);
+  mA->FillGlyphs(aScaledFont, aBuffer, *pattern.mA, aOptions, aRenderingOptions);
+  mB->FillGlyphs(aScaledFont, aBuffer, *pattern.mB, aOptions, aRenderingOptions);
+}
+
+void
+DrawTargetDual::Mask(const Pattern &aSource, const Pattern &aMask, const DrawOptions &aOptions)
+{
+  DualPattern source(aSource);
+  DualPattern mask(aMask);
+  mA->Mask(*source.mA, *mask.mA, aOptions);
+  mB->Mask(*source.mB, *mask.mB, aOptions);
+}
+
+TemporaryRef<DrawTarget>
+DrawTargetDual::CreateSimilarDrawTarget(const IntSize &aSize, SurfaceFormat aFormat) const
+{
+  RefPtr<DrawTarget> dtA = mA->CreateSimilarDrawTarget(aSize, aFormat);
+  RefPtr<DrawTarget> dtB = mB->CreateSimilarDrawTarget(aSize, aFormat);
+
+  return new DrawTargetDual(dtA, dtB);
+}
+
+}
+}
new file mode 100644
--- /dev/null
+++ b/gfx/2d/DrawTargetDual.h
@@ -0,0 +1,170 @@
+/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
+  * ***** BEGIN LICENSE BLOCK *****
+  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+  *
+  * The contents of this file are subject to the Mozilla Public License Version
+  * 1.1 (the "License"); you may not use this file except in compliance with
+  * the License. You may obtain a copy of the License at
+  * http://www.mozilla.org/MPL/
+  *
+  * Software distributed under the License is distributed on an "AS IS" basis,
+  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+  * for the specific language governing rights and limitations under the
+  * License.
+  *
+  * The Original Code is Mozilla Corporation code.
+  *
+  * The Initial Developer of the Original Code is Mozilla Foundation.
+  * Portions created by the Initial Developer are Copyright (C) 2011
+  * the Initial Developer. All Rights Reserved.
+  *
+  * Contributor(s):
+  *   Bas Schouten <bschouten@mozilla.com>
+  *
+  * Alternatively, the contents of this file may be used under the terms of
+  * either the GNU General Public License Version 2 or later (the "GPL"), or
+  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+  * in which case the provisions of the GPL or the LGPL are applicable instead
+  * of those above. If you wish to allow use of your version of this file only
+  * under the terms of either the GPL or the LGPL, and not to allow others to
+  * use your version of this file under the terms of the MPL, indicate your
+  * decision by deleting the provisions above and replace them with the notice
+  * and other provisions required by the GPL or the LGPL. If you do not delete
+  * the provisions above, a recipient may use your version of this file under
+  * the terms of any one of the MPL, the GPL or the LGPL.
+  *
+  * ***** END LICENSE BLOCK ***** */
+     
+#ifndef MOZILLA_GFX_DRAWTARGETDUAL_H_
+#define MOZILLA_GFX_DRAWTARGETDUAL_H_
+     
+#include <vector>
+#include <sstream>
+
+#include "SourceSurfaceDual.h"
+     
+#include "2D.h"
+     
+namespace mozilla {
+namespace gfx {
+     
+#define FORWARD_FUNCTION(funcName) \
+  virtual void funcName() { mA->funcName(); mB->funcName(); }
+#define FORWARD_FUNCTION1(funcName, var1Type, var1Name) \
+  virtual void funcName(var1Type var1Name) { mA->funcName(var1Name); mB->funcName(var1Name); }
+
+/* This is a special type of DrawTarget. It duplicates all drawing calls
+ * accross two drawtargets. An exception to this is when a snapshot of another
+ * dual DrawTarget is used as the source for any surface data. In this case
+ * the snapshot of the first source DrawTarget is used as a source for the call
+ * to the first destination DrawTarget (mA) and the snapshot of the second
+ * source DrawTarget is used at the source for the second destination
+ * DrawTarget (mB). This class facilitates black-background/white-background
+ * drawing for per-component alpha extraction for backends which do not support
+ * native component alpha.
+ */
+class DrawTargetDual : public DrawTarget
+{
+public:
+  DrawTargetDual(DrawTarget *aA, DrawTarget *aB)
+    : mA(aA)
+    , mB(aB)
+  { 
+    mFormat = aA->GetFormat();
+  }
+     
+  virtual BackendType GetType() const { return mA->GetType(); }
+  virtual TemporaryRef<SourceSurface> Snapshot() { return new SourceSurfaceDual(mA, mB); }
+  virtual IntSize GetSize() { return mA->GetSize(); }
+     
+  FORWARD_FUNCTION(Flush)
+  FORWARD_FUNCTION1(PushClip, const Path *, aPath)
+  FORWARD_FUNCTION1(PushClipRect, const Rect &, aRect)
+  FORWARD_FUNCTION(PopClip)
+  FORWARD_FUNCTION1(ClearRect, const Rect &, aRect)
+
+  virtual void SetTransform(const Matrix &aTransform) {
+    mTransform = aTransform;
+    mA->SetTransform(aTransform);
+    mB->SetTransform(aTransform);
+  }
+
+  virtual void DrawSurface(SourceSurface *aSurface, const Rect &aDest, const Rect & aSource,
+                           const DrawSurfaceOptions &aSurfOptions, const DrawOptions &aOptions);
+  
+  virtual void DrawSurfaceWithShadow(SourceSurface *aSurface, const Point &aDest,
+                                     const Color &aColor, const Point &aOffset,
+                                     Float aSigma, CompositionOp aOp);
+
+  virtual void CopySurface(SourceSurface *aSurface, const IntRect &aSourceRect,
+                           const IntPoint &aDestination);
+
+  virtual void FillRect(const Rect &aRect, const Pattern &aPattern, const DrawOptions &aOptions);
+
+  virtual void StrokeRect(const Rect &aRect, const Pattern &aPattern,
+                          const StrokeOptions &aStrokeOptions, const DrawOptions &aOptions);
+
+  virtual void StrokeLine(const Point &aStart, const Point &aEnd, const Pattern &aPattern,
+                          const StrokeOptions &aStrokeOptions, const DrawOptions &aOptions);
+
+  virtual void Stroke(const Path *aPath, const Pattern &aPattern,
+                      const StrokeOptions &aStrokeOptions, const DrawOptions &aOptions);
+
+  virtual void Fill(const Path *aPath, const Pattern &aPattern, const DrawOptions &aOptions);
+
+  virtual void FillGlyphs(ScaledFont *aScaledFont, const GlyphBuffer &aBuffer,
+                          const Pattern &aPattern, const DrawOptions &aOptions,
+                          const GlyphRenderingOptions *aRenderingOptions);
+  
+  virtual void Mask(const Pattern &aSource, const Pattern &aMask, const DrawOptions &aOptions);
+     
+  virtual TemporaryRef<SourceSurface>
+    CreateSourceSurfaceFromData(unsigned char *aData,
+                                const IntSize &aSize,
+                                int32_t aStride,
+                                SurfaceFormat aFormat) const
+  {
+    return mA->CreateSourceSurfaceFromData(aData, aSize, aStride, aFormat);
+  }
+     
+  virtual TemporaryRef<SourceSurface> OptimizeSourceSurface(SourceSurface *aSurface) const
+  {
+    return mA->OptimizeSourceSurface(aSurface);
+  }
+     
+  virtual TemporaryRef<SourceSurface>
+    CreateSourceSurfaceFromNativeSurface(const NativeSurface &aSurface) const
+  {
+    return mA->CreateSourceSurfaceFromNativeSurface(aSurface);
+  }
+     
+  virtual TemporaryRef<DrawTarget>
+    CreateSimilarDrawTarget(const IntSize &aSize, SurfaceFormat aFormat) const;
+     
+  virtual TemporaryRef<PathBuilder> CreatePathBuilder(FillRule aFillRule = FILL_WINDING) const
+  {
+    return mA->CreatePathBuilder(aFillRule);
+  }
+     
+  virtual TemporaryRef<GradientStops>
+    CreateGradientStops(GradientStop *aStops,
+                        uint32_t aNumStops,
+                        ExtendMode aExtendMode = EXTEND_CLAMP) const
+  {
+    return mA->CreateGradientStops(aStops, aNumStops, aExtendMode);
+  }
+     
+  virtual void *GetNativeSurface(NativeSurfaceType aType)
+  {
+    return NULL;
+  }
+     
+private:
+  RefPtr<DrawTarget> mA;
+  RefPtr<DrawTarget> mB;
+};
+     
+}
+}
+     
+#endif /* MOZILLA_GFX_DRAWTARGETDUAL_H_ */ 
\ No newline at end of file
--- a/gfx/2d/Factory.cpp
+++ b/gfx/2d/Factory.cpp
@@ -62,16 +62,17 @@
 #endif
 
 #ifdef WIN32
 #include "DrawTargetD2D.h"
 #include "ScaledFontDWrite.h"
 #include <d3d10_1.h>
 #endif
 
+#include "DrawTargetDual.h"
 
 #include "Logging.h"
 
 #ifdef PR_LOGGING
 PRLogModuleInfo *sGFX2DLog = PR_NewLogModule("gfx2d");
 #endif
 
 namespace mozilla {
@@ -227,16 +228,42 @@ Factory::CreateDrawTargetForD3D10Texture
   }
 
   gfxWarning() << "Failed to create draw target for D3D10 texture.";
 
   // Failed
   return NULL;
 }
 
+TemporaryRef<DrawTarget>
+Factory::CreateDualDrawTargetForD3D10Textures(ID3D10Texture2D *aTextureA,
+                                              ID3D10Texture2D *aTextureB,
+                                              SurfaceFormat aFormat)
+{
+  RefPtr<DrawTargetD2D> newTargetA;
+  RefPtr<DrawTargetD2D> newTargetB;
+
+  newTargetA = new DrawTargetD2D();
+  if (!newTargetA->Init(aTextureA, aFormat)) {
+    gfxWarning() << "Failed to create draw target for D3D10 texture.";
+    return NULL;
+  }
+
+  newTargetB = new DrawTargetD2D();
+  if (!newTargetB->Init(aTextureB, aFormat)) {
+    gfxWarning() << "Failed to create draw target for D3D10 texture.";
+    return NULL;
+  }
+
+  RefPtr<DrawTarget> newTarget =
+    new DrawTargetDual(newTargetA, newTargetB);
+
+  return newTarget;
+}
+
 void
 Factory::SetDirect3D10Device(ID3D10Device1 *aDevice)
 {
   mD3D10Device = aDevice;
 }
 
 ID3D10Device1*
 Factory::GetDirect3D10Device()
--- a/gfx/2d/Makefile.in
+++ b/gfx/2d/Makefile.in
@@ -68,16 +68,17 @@ EXPORTS_mozilla/gfx	= \
 CPPSRCS	= \
 	Factory.cpp \
         Matrix.cpp \
         DrawTargetCairo.cpp \
         SourceSurfaceCairo.cpp \
         PathCairo.cpp \
         Blur.cpp \
         ScaledFontBase.cpp \
+        DrawTargetDual.cpp \
         $(NULL)
 
 ifeq (cocoa,$(MOZ_WIDGET_TOOLKIT))
 CPPSRCS	+= \
 	   SourceSurfaceCG.cpp \
 	   DrawTargetCG.cpp \
 	   PathCG.cpp \
 	   $(NULL)
new file mode 100644
--- /dev/null
+++ b/gfx/2d/SourceSurfaceDual.h
@@ -0,0 +1,74 @@
+/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
+  * ***** BEGIN LICENSE BLOCK *****
+  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+  *
+  * The contents of this file are subject to the Mozilla Public License Version
+  * 1.1 (the "License"); you may not use this file except in compliance with
+  * the License. You may obtain a copy of the License at
+  * http://www.mozilla.org/MPL/
+  *
+  * Software distributed under the License is distributed on an "AS IS" basis,
+  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+  * for the specific language governing rights and limitations under the
+  * License.
+  *
+  * The Original Code is Mozilla Corporation code.
+  *
+  * The Initial Developer of the Original Code is Mozilla Foundation.
+  * Portions created by the Initial Developer are Copyright (C) 2011
+  * the Initial Developer. All Rights Reserved.
+  *
+  * Contributor(s):
+  *   Bas Schouten <bschouten@mozilla.com>
+  *
+  * Alternatively, the contents of this file may be used under the terms of
+  * either the GNU General Public License Version 2 or later (the "GPL"), or
+  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+  * in which case the provisions of the GPL or the LGPL are applicable instead
+  * of those above. If you wish to allow use of your version of this file only
+  * under the terms of either the GPL or the LGPL, and not to allow others to
+  * use your version of this file under the terms of the MPL, indicate your
+  * decision by deleting the provisions above and replace them with the notice
+  * and other provisions required by the GPL or the LGPL. If you do not delete
+  * the provisions above, a recipient may use your version of this file under
+  * the terms of any one of the MPL, the GPL or the LGPL.
+  *
+  * ***** END LICENSE BLOCK ***** */
+     
+#ifndef MOZILLA_GFX_SOURCESURFACEDUAL_H_
+#define MOZILLA_GFX_SOURCESURFACEDUAL_H_
+     
+#include "2D.h"
+     
+namespace mozilla {
+namespace gfx {
+
+class DualSurface;
+class DualPattern;
+
+class SourceSurfaceDual : public SourceSurface
+{
+public:
+  SourceSurfaceDual(DrawTarget *aDTA, DrawTarget *aDTB)
+    : mA(aDTA->Snapshot())
+    , mB(aDTB->Snapshot())
+  { }
+
+  virtual SurfaceType GetType() const { return SURFACE_DUAL_DT; }
+  virtual IntSize GetSize() const { return mA->GetSize(); }
+  virtual SurfaceFormat GetFormat() const { return mA->GetFormat(); }
+
+  /* Readback from this surface type is not supported! */
+  virtual TemporaryRef<DataSourceSurface> GetDataSurface() { return NULL; }
+private:
+  friend class DualSurface;
+  friend class DualPattern;
+
+  RefPtr<SourceSurface> mA;
+  RefPtr<SourceSurface> mB;
+};
+
+}
+}
+
+#endif /* MOZILLA_GFX_SOURCESURFACEDUAL_H_ */
--- a/gfx/2d/Tools.h
+++ b/gfx/2d/Tools.h
@@ -52,12 +52,21 @@ IsOperatorBoundByMask(CompositionOp aOp)
   case OP_DEST_ATOP:
   case OP_SOURCE:
     return false;
   default:
     return true;
   }
 }
 
+template <class T>
+struct ClassStorage
+{
+  char bytes[sizeof(T)];
+
+  const T *addr() const { return (const T *)bytes; }
+  T *addr() { return (T *)(void *)bytes; }
+};
+
 }
 }
 
 #endif /* MOZILLA_GFX_TOOLS_H_ */
--- a/gfx/2d/Types.h
+++ b/gfx/2d/Types.h
@@ -51,17 +51,18 @@ enum SurfaceType
 {
   SURFACE_DATA, /* Data surface - bitmap in memory */
   SURFACE_D2D1_BITMAP, /* Surface wrapping a ID2D1Bitmap */
   SURFACE_D2D1_DRAWTARGET, /* Surface made from a D2D draw target */
   SURFACE_CAIRO, /* Surface wrapping a cairo surface */
   SURFACE_CAIRO_IMAGE, /* Data surface wrapping a cairo image surface */
   SURFACE_COREGRAPHICS_IMAGE, /* Surface wrapping a CoreGraphics Image */
   SURFACE_COREGRAPHICS_CGCONTEXT, /* Surface wrapping a CG context */
-  SURFACE_SKIA /* Surface wrapping a Skia bitmap */
+  SURFACE_SKIA, /* Surface wrapping a Skia bitmap */
+  SURFACE_DUAL_DT /* Snapshot of a dual drawtarget */
 };
 
 enum SurfaceFormat
 {
   FORMAT_B8G8R8A8,
   FORMAT_B8G8R8X8,
   FORMAT_R5G6B5,
   FORMAT_A8