Bug 913872 - Take nested enums out of gfxASurface - 3/3 : remove the now-useless inclusions of gfxASurface.h - r=jrmuizel
authorBenoit Jacob <bjacob@mozilla.com>
Tue, 24 Sep 2013 16:45:14 -0400
changeset 162309 7588ab535671ada2874b95a3a17a5f6f43579ade
parent 162308 0f86bf03656bac01716606e7dfe1a136208e6966
child 162310 94c5919f12c179716f06c2c80f23256118f49347
push id3066
push userakeybl@mozilla.com
push dateMon, 09 Dec 2013 19:58:46 +0000
treeherdermozilla-beta@a31a0dce83aa [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjrmuizel
bugs913872
milestone27.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 913872 - Take nested enums out of gfxASurface - 3/3 : remove the now-useless inclusions of gfxASurface.h - r=jrmuizel
dom/plugins/ipc/PluginBackgroundDestroyer.cpp
dom/plugins/ipc/PluginBackgroundDestroyer.h
dom/plugins/ipc/PluginInstanceChild.h
dom/plugins/ipc/PluginInstanceParent.h
dom/plugins/ipc/PluginSurfaceParent.cpp
dom/plugins/ipc/PluginSurfaceParent.h
dom/plugins/ipc/moz.build
gfx/gl/GLTextureImage.h
gfx/gl/SharedSurfaceGL.h
gfx/ipc/GfxMessageUtils.h
gfx/layers/CopyableCanvasLayer.cpp
gfx/layers/CopyableCanvasLayer.h
gfx/layers/GrallocImages.cpp
gfx/layers/Layers.h
gfx/layers/basic/AutoMaskData.h
gfx/layers/basic/BasicCompositor.h
gfx/layers/basic/BasicLayers.h
gfx/layers/basic/BasicLayersImpl.cpp
gfx/layers/basic/BasicLayersImpl.h
gfx/layers/basic/BasicThebesLayer.cpp
gfx/layers/client/ContentClient.h
gfx/layers/client/TextureClient.cpp
gfx/layers/client/TextureClient.h
gfx/layers/client/TiledContentClient.h
gfx/layers/composite/TextureHost.h
gfx/layers/d3d10/CanvasLayerD3D10.h
gfx/layers/d3d9/CanvasLayerD3D9.h
gfx/layers/ipc/CompositableForwarder.h
gfx/layers/ipc/ISurfaceAllocator.h
gfx/layers/ipc/ShadowLayers.h
gfx/layers/ipc/SharedRGBImage.h
gfx/layers/opengl/CanvasLayerOGL.cpp
gfx/layers/opengl/CanvasLayerOGL.h
gfx/layers/opengl/LayerManagerOGLProgram.h
gfx/layers/opengl/TextureClientOGL.h
gfx/layers/opengl/TextureHostOGL.h
gfx/thebes/gfxASurface.h
gfx/thebes/gfxPlatform.h
gfx/thebes/gfxTypes.h
image/decoders/nsPNGDecoder.h
image/src/FrameBlender.h
image/src/FrameSequence.h
widget/android/AndroidDirectTexture.h
widget/android/AndroidGraphicBuffer.h
widget/cocoa/nsNativeThemeCocoa.h
widget/gtk/nsWindow.h
widget/os2/nsWindow.h
widget/shared/nsShmImage.h
new file mode 100644
--- /dev/null
+++ b/dom/plugins/ipc/PluginBackgroundDestroyer.cpp
@@ -0,0 +1,40 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
+ * vim: sw=4 ts=8 et :
+ */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "PluginBackgroundDestroyer.h"
+#include "gfxSharedImageSurface.h"
+
+using namespace mozilla;
+using namespace plugins;
+
+PluginBackgroundDestroyerParent::PluginBackgroundDestroyerParent(gfxASurface* aDyingBackground)
+  : mDyingBackground(aDyingBackground)
+{
+}
+
+PluginBackgroundDestroyerParent::~PluginBackgroundDestroyerParent()
+{
+}
+
+void
+PluginBackgroundDestroyerParent::ActorDestroy(ActorDestroyReason why)
+{
+    switch(why) {
+    case Deletion:
+    case AncestorDeletion:
+        if (gfxSharedImageSurface::IsSharedImage(mDyingBackground)) {
+            gfxSharedImageSurface* s =
+                static_cast<gfxSharedImageSurface*>(mDyingBackground.get());
+            DeallocShmem(s->GetShmem());
+        }
+        break;
+    default:
+        // We're shutting down or crashed, let automatic cleanup
+        // take care of our shmem, if we have one.
+        break;
+    }
+}
--- a/dom/plugins/ipc/PluginBackgroundDestroyer.h
+++ b/dom/plugins/ipc/PluginBackgroundDestroyer.h
@@ -6,53 +6,36 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef dom_plugins_PluginBackgroundDestroyer
 #define dom_plugins_PluginBackgroundDestroyer
 
 #include "mozilla/plugins/PPluginBackgroundDestroyerChild.h"
 #include "mozilla/plugins/PPluginBackgroundDestroyerParent.h"
 
-#include "gfxASurface.h"
 #include "gfxSharedImageSurface.h"
 
+class gfxASurface;
+
 namespace mozilla {
 namespace plugins {
 
 /**
  * When instances of this class are destroyed, the old background goes
  * along with them, completing the destruction process (whether or not
  * the plugin stayed alive long enough to ack).
  */
 class PluginBackgroundDestroyerParent : public PPluginBackgroundDestroyerParent {
 public:
-    PluginBackgroundDestroyerParent(gfxASurface* aDyingBackground)
-      : mDyingBackground(aDyingBackground)
-    { }
+    PluginBackgroundDestroyerParent(gfxASurface* aDyingBackground);
 
-    virtual ~PluginBackgroundDestroyerParent() { }
+    virtual ~PluginBackgroundDestroyerParent();
 
 private:
-    virtual void ActorDestroy(ActorDestroyReason why) MOZ_OVERRIDE
-    {
-        switch(why) {
-        case Deletion:
-        case AncestorDeletion:
-            if (gfxSharedImageSurface::IsSharedImage(mDyingBackground)) {
-                gfxSharedImageSurface* s =
-                    static_cast<gfxSharedImageSurface*>(mDyingBackground.get());
-                DeallocShmem(s->GetShmem());
-            }
-            break;
-        default:
-            // We're shutting down or crashed, let automatic cleanup
-            // take care of our shmem, if we have one.
-            break;
-        }
-    }
+    virtual void ActorDestroy(ActorDestroyReason why) MOZ_OVERRIDE;
 
     nsRefPtr<gfxASurface> mDyingBackground;
 };
 
 /**
  * This class exists solely to instruct its instance to release its
  * current background, a new one may be coming.
  */
--- a/dom/plugins/ipc/PluginInstanceChild.h
+++ b/dom/plugins/ipc/PluginInstanceChild.h
@@ -25,24 +25,25 @@
 #include "npfunctions.h"
 #include "nsAutoPtr.h"
 #include "nsTArray.h"
 #include "ChildAsyncCall.h"
 #include "ChildTimer.h"
 #include "nsRect.h"
 #include "nsTHashtable.h"
 #include "mozilla/PaintTracker.h"
-#include "gfxASurface.h"
 
 #include <map>
 
 #if (MOZ_WIDGET_GTK == 2)
 #include "gtk2xtbin.h"
 #endif
 
+class gfxASurface;
+
 namespace mozilla {
 
 namespace layers {
 struct RemoteImageData;
 }
 
 namespace plugins {
 
--- a/dom/plugins/ipc/PluginInstanceParent.h
+++ b/dom/plugins/ipc/PluginInstanceParent.h
@@ -17,24 +17,25 @@
 #include "mozilla/gfx/QuartzSupport.h"
 #endif
 
 #include "npfunctions.h"
 #include "nsAutoPtr.h"
 #include "nsDataHashtable.h"
 #include "nsHashKeys.h"
 #include "nsRect.h"
-#include "gfxASurface.h"
 
 #ifdef MOZ_X11
 class gfxXlibSurface;
 #endif
 #include "nsGUIEvent.h"
 #include "mozilla/unused.h"
 
+class gfxASurface;
+
 namespace mozilla {
 namespace layers {
 class ImageContainer;
 class CompositionNotifySink;
 }
 namespace plugins {
 
 class PBrowserStreamParent;
--- a/dom/plugins/ipc/PluginSurfaceParent.cpp
+++ b/dom/plugins/ipc/PluginSurfaceParent.cpp
@@ -15,10 +15,14 @@ PluginSurfaceParent::PluginSurfaceParent
                                          const gfxIntSize& size,
                                          bool transparent)
 {
   SharedDIBSurface* dibsurf = new SharedDIBSurface();
   if (dibsurf->Attach(handle, size.width, size.height, transparent))
     mSurface = dibsurf;
 }
 
+PluginSurfaceParent::~PluginSurfaceParent()
+{
+}
+
 }
 }
--- a/dom/plugins/ipc/PluginSurfaceParent.h
+++ b/dom/plugins/ipc/PluginSurfaceParent.h
@@ -2,34 +2,35 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef dom_plugins_PluginSurfaceParent_h
 #define dom_plugins_PluginSurfaceParent_h
 
 #include "mozilla/plugins/PPluginSurfaceParent.h"
-#include "gfxASurface.h"
 #include "nsAutoPtr.h"
 #include "mozilla/plugins/PluginMessageUtils.h"
 
 #ifndef XP_WIN
 #error "This header is for Windows only."
 #endif
 
+class gfxASurface;
+
 namespace mozilla {
 namespace plugins {
 
 class PluginSurfaceParent : public PPluginSurfaceParent
 {
 public:
   PluginSurfaceParent(const WindowsSharedMemoryHandle& handle,
                       const gfxIntSize& size,
                       const bool transparent);
-  ~PluginSurfaceParent() { }
+  ~PluginSurfaceParent();
 
   gfxASurface* Surface() { return mSurface; }
 
 private:
   nsRefPtr<gfxASurface> mSurface;
 };
 
 } // namespace plugins
--- a/dom/plugins/ipc/moz.build
+++ b/dom/plugins/ipc/moz.build
@@ -66,16 +66,17 @@ if CONFIG['MOZ_ENABLE_QT']:
         'NestedLoopTimer.cpp',
     ]
 
 CPP_SOURCES += [
     'BrowserStreamChild.cpp',
     'BrowserStreamParent.cpp',
     'ChildAsyncCall.cpp',
     'ChildTimer.cpp',
+    'PluginBackgroundDestroyer.cpp',
     'PluginIdentifierChild.cpp',
     'PluginIdentifierParent.cpp',
     'PluginInstanceChild.cpp',
     'PluginInstanceParent.cpp',
     'PluginMessageUtils.cpp',
     'PluginModuleChild.cpp',
     'PluginModuleParent.cpp',
     'PluginProcessChild.cpp',
--- a/gfx/gl/GLTextureImage.h
+++ b/gfx/gl/GLTextureImage.h
@@ -4,21 +4,23 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef GLTEXTUREIMAGE_H_
 #define GLTEXTUREIMAGE_H_
 
 #include "nsAutoPtr.h"
 #include "nsRegion.h"
 #include "nsTArray.h"
-#include "gfxASurface.h"
+#include "gfxTypes.h"
 #include "GLContextTypes.h"
 #include "gfxPattern.h"
 #include "mozilla/gfx/Rect.h"
 
+class gfxASurface;
+
 namespace mozilla {
 namespace gfx {
 class DataSourceSurface;
 }
 }
 
 namespace mozilla {
 namespace gl {
--- a/gfx/gl/SharedSurfaceGL.h
+++ b/gfx/gl/SharedSurfaceGL.h
@@ -6,17 +6,17 @@
 #ifndef SHARED_SURFACE_GL_H_
 #define SHARED_SURFACE_GL_H_
 
 #include "SharedSurface.h"
 #include "SurfaceFactory.h"
 #include "SurfaceTypes.h"
 #include "GLContextTypes.h"
 #include "nsAutoPtr.h"
-#include "gfxASurface.h"
+#include "gfxTypes.h"
 #include "mozilla/Mutex.h"
 
 #include <queue>
 
 // Forwards:
 class gfxImageSurface;
 namespace mozilla {
     namespace gl {
--- a/gfx/ipc/GfxMessageUtils.h
+++ b/gfx/ipc/GfxMessageUtils.h
@@ -18,17 +18,17 @@
 #include "gfx3DMatrix.h"
 #include "gfxColor.h"
 #include "gfxMatrix.h"
 #include "gfxPattern.h"
 #include "gfxPoint.h"
 #include "gfxRect.h"
 #include "nsRect.h"
 #include "nsRegion.h"
-#include "gfxASurface.h"
+#include "gfxTypes.h"
 #include "mozilla/layers/LayersTypes.h"
 #include "mozilla/layers/CompositorTypes.h"
 #include "FrameMetrics.h"
 
 #ifdef _MSC_VER
 #pragma warning( disable : 4800 )
 #endif
 
--- a/gfx/layers/CopyableCanvasLayer.cpp
+++ b/gfx/layers/CopyableCanvasLayer.cpp
@@ -201,10 +201,33 @@ CopyableCanvasLayer::PaintWithOpacity(gf
     aContext->SetOperator(savedOp);
   }  
 
   if (mNeedsYFlip) {
     aContext->SetMatrix(m);
   }
 }
 
+gfxImageSurface*
+CopyableCanvasLayer::GetTempSurface(const gfxIntSize& aSize, const gfxImageFormat aFormat)
+{
+  if (!mCachedTempSurface ||
+      aSize.width != mCachedSize.width ||
+      aSize.height != mCachedSize.height ||
+      aFormat != mCachedFormat)
+  {
+    mCachedTempSurface = new gfxImageSurface(aSize, aFormat);
+    mCachedSize = aSize;
+    mCachedFormat = aFormat;
+  }
+
+  MOZ_ASSERT(mCachedTempSurface->Stride() == mCachedTempSurface->Width() * 4);
+  return mCachedTempSurface;
+}
+
+void
+CopyableCanvasLayer::DiscardTempSurface()
+{
+  mCachedTempSurface = nullptr;
+}
+
 }
 }
--- a/gfx/layers/CopyableCanvasLayer.h
+++ b/gfx/layers/CopyableCanvasLayer.h
@@ -6,17 +6,17 @@
 #ifndef GFX_COPYABLECANVASLAYER_H
 #define GFX_COPYABLECANVASLAYER_H
 
 #include <stdint.h>                     // for uint32_t
 #include "GLContextTypes.h"             // for GLContext
 #include "Layers.h"                     // for CanvasLayer, etc
 #include "gfxASurface.h"                // for gfxASurface
 #include "gfxContext.h"                 // for gfxContext, etc
-#include "gfxImageSurface.h"            // for gfxImageSurface
+#include "gfxTypes.h"
 #include "gfxPlatform.h"                // for gfxImageFormat
 #include "gfxPoint.h"                   // for gfxIntSize
 #include "mozilla/Assertions.h"         // for MOZ_ASSERT, etc
 #include "mozilla/Preferences.h"        // for Preferences
 #include "mozilla/RefPtr.h"             // for RefPtr
 #include "mozilla/gfx/2D.h"             // for DrawTarget
 #include "mozilla/mozalloc.h"           // for operator delete, etc
 #include "nsAutoPtr.h"                  // for nsRefPtr
@@ -59,34 +59,17 @@ protected:
   bool mIsGLAlphaPremult;
   bool mNeedsYFlip;
   bool mForceReadback;
 
   nsRefPtr<gfxImageSurface> mCachedTempSurface;
   gfxIntSize mCachedSize;
   gfxImageFormat mCachedFormat;
 
-  gfxImageSurface* GetTempSurface(const gfxIntSize& aSize, const gfxImageFormat aFormat)
-  {
-    if (!mCachedTempSurface ||
-        aSize.width != mCachedSize.width ||
-        aSize.height != mCachedSize.height ||
-        aFormat != mCachedFormat)
-    {
-      mCachedTempSurface = new gfxImageSurface(aSize, aFormat);
-      mCachedSize = aSize;
-      mCachedFormat = aFormat;
-    }
+  gfxImageSurface* GetTempSurface(const gfxIntSize& aSize, const gfxImageFormat aFormat);
 
-    MOZ_ASSERT(mCachedTempSurface->Stride() == mCachedTempSurface->Width() * 4);
-    return mCachedTempSurface;
-  }
-
-  void DiscardTempSurface()
-  {
-    mCachedTempSurface = nullptr;
-  }
+  void DiscardTempSurface();
 };
 
 }
 }
 
 #endif
--- a/gfx/layers/GrallocImages.cpp
+++ b/gfx/layers/GrallocImages.cpp
@@ -6,16 +6,17 @@
 
 #include "GrallocImages.h"
 #include <stddef.h>                     // for size_t
 #include <stdint.h>                     // for int8_t, uint8_t, uint32_t, etc
 #include "nsDebug.h"                    // for NS_WARNING, NS_PRECONDITION
 #include "mozilla/layers/ImageBridgeChild.h"
 #include "mozilla/layers/GrallocTextureClient.h"
 #include "gfx2DGlue.h"
+#include "gfxImageSurface.h"
 
 #include <OMX_IVCommon.h>
 #include <ColorConverter.h>
 
 using namespace mozilla::ipc;
 using namespace android;
 
 #define ALIGN(x, align) ((x + align - 1) & ~(align - 1))
--- a/gfx/layers/Layers.h
+++ b/gfx/layers/Layers.h
@@ -8,17 +8,17 @@
 
 #include <stdint.h>                     // for uint32_t, uint64_t, uint8_t
 #include <stdio.h>                      // for FILE
 #include <sys/types.h>                  // for int32_t, int64_t
 #include "FrameMetrics.h"               // for FrameMetrics
 #include "Units.h"                      // for LayerMargin, LayerPoint
 #include "gfx3DMatrix.h"                // for gfx3DMatrix
 #include "gfxContext.h"                 // for GraphicsOperator
-#include "gfxASurface.h"                // for gfxASurface, etc
+#include "gfxTypes.h"
 #include "gfxColor.h"                   // for gfxRGBA
 #include "gfxMatrix.h"                  // for gfxMatrix
 #include "gfxPattern.h"                 // for gfxPattern, etc
 #include "gfxPoint.h"                   // for gfxPoint, gfxIntSize
 #include "gfxRect.h"                    // for gfxRect
 #include "mozilla/Assertions.h"         // for MOZ_ASSERT_HELPER2, etc
 #include "mozilla/DebugOnly.h"          // for DebugOnly
 #include "mozilla/EventForwards.h"      // for nsPaintEvent
@@ -41,17 +41,17 @@
 #include "nsSize.h"                     // for nsIntSize
 #include "nsString.h"                   // for nsCString
 #include "nsStyleAnimation.h"           // for nsStyleAnimation::Value, etc
 #include "nsTArray.h"                   // for nsTArray
 #include "nsTArrayForwardDeclare.h"     // for InfallibleTArray
 #include "nscore.h"                     // for nsACString, nsAString
 #include "prlog.h"                      // for PRLogModuleInfo
 
-
+class gfxASurface;
 class gfxContext;
 
 extern uint8_t gLayerManagerLayerBuilder;
 
 namespace mozilla {
 
 class FrameLayerBuilder;
 class WebGLContext;
new file mode 100644
--- /dev/null
+++ b/gfx/layers/basic/AutoMaskData.h
@@ -0,0 +1,61 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef GFX_AUTOMASKDATA_H_
+#define GFX_AUTOMASKDATA_H_
+
+#include "gfxASurface.h"
+#include "mozilla/layers/LayersSurfaces.h"  // for SurfaceDescriptor
+
+namespace mozilla {
+namespace layers {
+
+/**
+ * Drawing with a mask requires a mask surface and a transform.
+ * Sometimes the mask surface is a direct gfxASurface, but other times
+ * it's a SurfaceDescriptor.  For SurfaceDescriptor, we need to use a
+ * scoped AutoOpenSurface to get a gfxASurface for the
+ * SurfaceDescriptor.
+ *
+ * This helper class manages the gfxASurface-or-SurfaceDescriptor
+ * logic.
+ */
+class MOZ_STACK_CLASS AutoMaskData {
+public:
+  AutoMaskData() { }
+  ~AutoMaskData() { }
+
+  /**
+   * Construct this out of either a gfxASurface or a
+   * SurfaceDescriptor.  Construct() must only be called once.
+   * GetSurface() and GetTransform() must not be called until this has
+   * been constructed.
+   */
+
+  void Construct(const gfxMatrix& aTransform,
+                 gfxASurface* aSurface);
+
+  void Construct(const gfxMatrix& aTransform,
+                 const SurfaceDescriptor& aSurface);
+
+  /** The returned surface can't escape the scope of |this|. */
+  gfxASurface* GetSurface();
+  const gfxMatrix& GetTransform();
+
+private:
+  bool IsConstructed();
+
+  gfxMatrix mTransform;
+  nsRefPtr<gfxASurface> mSurface;
+  Maybe<AutoOpenSurface> mSurfaceOpener;
+
+  AutoMaskData(const AutoMaskData&) MOZ_DELETE;
+  AutoMaskData& operator=(const AutoMaskData&) MOZ_DELETE;
+};
+
+}
+}
+
+#endif // GFX_AUTOMASKDATA_H_
\ No newline at end of file
--- a/gfx/layers/basic/BasicCompositor.h
+++ b/gfx/layers/basic/BasicCompositor.h
@@ -4,16 +4,19 @@
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef MOZILLA_GFX_BASICCOMPOSITOR_H
 #define MOZILLA_GFX_BASICCOMPOSITOR_H
 
 #include "mozilla/layers/Compositor.h"
 #include "mozilla/layers/TextureHost.h"
 #include "mozilla/gfx/2D.h"
+#include "nsAutoPtr.h"
+
+class gfxContext;
 
 namespace mozilla {
 namespace layers {
 
 class BasicCompositingRenderTarget : public CompositingRenderTarget
 {
 public:
   BasicCompositingRenderTarget(gfx::DrawTarget* aDrawTarget, const gfx::IntSize& aSize)
--- a/gfx/layers/basic/BasicLayers.h
+++ b/gfx/layers/basic/BasicLayers.h
@@ -3,17 +3,17 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef GFX_BASICLAYERS_H
 #define GFX_BASICLAYERS_H
 
 #include <stdint.h>                     // for INT32_MAX, int32_t
 #include "Layers.h"                     // for Layer (ptr only), etc
-#include "gfxASurface.h"                // for gfxASurface, etc
+#include "gfxTypes.h"
 #include "gfxCachedTempSurface.h"       // for gfxCachedTempSurface
 #include "gfxContext.h"                 // for gfxContext
 #include "mozilla/Attributes.h"         // for MOZ_OVERRIDE
 #include "mozilla/WidgetUtils.h"        // for ScreenRotation
 #include "mozilla/layers/LayersTypes.h"  // for BufferMode, LayersBackend, etc
 #include "nsAString.h"
 #include "nsAutoPtr.h"                  // for nsRefPtr
 #include "nsCOMPtr.h"                   // for already_AddRefed
--- a/gfx/layers/basic/BasicLayersImpl.cpp
+++ b/gfx/layers/basic/BasicLayersImpl.cpp
@@ -7,16 +7,17 @@
 #include <new>                          // for operator new
 #include "Layers.h"                     // for Layer, etc
 #include "basic/BasicImplData.h"        // for BasicImplData
 #include "gfx3DMatrix.h"                // for gfx3DMatrix
 #include "mozilla/Assertions.h"         // for MOZ_ASSERT, etc
 #include "mozilla/DebugOnly.h"          // for DebugOnly
 #include "mozilla/layers/CompositorTypes.h"
 #include "mozilla/layers/ISurfaceAllocator.h"
+#include "AutoMaskData.h"
 
 using namespace mozilla::gfx;
 
 namespace mozilla {
 namespace layers {
 
 void
 AutoMaskData::Construct(const gfxMatrix& aTransform,
--- a/gfx/layers/basic/BasicLayersImpl.h
+++ b/gfx/layers/basic/BasicLayersImpl.h
@@ -10,26 +10,26 @@
 #include "BasicLayers.h"                // for BasicLayerManager
 #include "ReadbackLayer.h"              // for ReadbackLayer
 #include "gfxASurface.h"                // for gfxASurface
 #include "gfxContext.h"                 // for gfxContext, etc
 #include "gfxMatrix.h"                  // for gfxMatrix
 #include "ipc/AutoOpenSurface.h"        // for AutoOpenSurface
 #include "mozilla/Attributes.h"         // for MOZ_DELETE, MOZ_STACK_CLASS
 #include "mozilla/Maybe.h"              // for Maybe
-#include "mozilla/layers/LayersSurfaces.h"  // for SurfaceDescriptor
 #include "nsAutoPtr.h"                  // for nsRefPtr
 #include "nsDebug.h"                    // for NS_ASSERTION
 #include "nsISupportsImpl.h"            // for gfxContext::Release, etc
 #include "nsRegion.h"                   // for nsIntRegion
 #include "nsTraceRefcnt.h"              // for MOZ_COUNT_CTOR, etc
 
 namespace mozilla {
 namespace layers {
 
+class AutoMaskData;
 class BasicContainerLayer;
 class Layer;
 
 class AutoSetOperator {
 public:
   AutoSetOperator(gfxContext* aContext, gfxContext::GraphicsOperator aOperator) {
     if (aOperator != gfxContext::OPERATOR_OVER) {
       aContext->SetOperator(aOperator);
@@ -69,59 +69,16 @@ public:
 
 protected:
   BasicLayerManager* BasicManager()
   {
     return static_cast<BasicLayerManager*>(mManager);
   }
 };
 
-/**
- * Drawing with a mask requires a mask surface and a transform.
- * Sometimes the mask surface is a direct gfxASurface, but other times
- * it's a SurfaceDescriptor.  For SurfaceDescriptor, we need to use a
- * scoped AutoOpenSurface to get a gfxASurface for the
- * SurfaceDescriptor.
- *
- * This helper class manages the gfxASurface-or-SurfaceDescriptor
- * logic.
- */
-class MOZ_STACK_CLASS AutoMaskData {
-public:
-  AutoMaskData() { }
-  ~AutoMaskData() { }
-
-  /**
-   * Construct this out of either a gfxASurface or a
-   * SurfaceDescriptor.  Construct() must only be called once.
-   * GetSurface() and GetTransform() must not be called until this has
-   * been constructed.
-   */
-
-  void Construct(const gfxMatrix& aTransform,
-                 gfxASurface* aSurface);
-
-  void Construct(const gfxMatrix& aTransform,
-                 const SurfaceDescriptor& aSurface);
-
-  /** The returned surface can't escape the scope of |this|. */
-  gfxASurface* GetSurface();
-  const gfxMatrix& GetTransform();
-
-private:
-  bool IsConstructed();
-
-  gfxMatrix mTransform;
-  nsRefPtr<gfxASurface> mSurface;
-  Maybe<AutoOpenSurface> mSurfaceOpener;
-
-  AutoMaskData(const AutoMaskData&) MOZ_DELETE;
-  AutoMaskData& operator=(const AutoMaskData&) MOZ_DELETE;
-};
-
 /*
  * Extract a mask surface for a mask layer
  * Returns true and through outparams a surface for the mask layer if
  * a mask layer is present and has a valid surface and transform;
  * false otherwise.
  * The transform for the layer will be put in aMaskData
  */
 bool
--- a/gfx/layers/basic/BasicThebesLayer.cpp
+++ b/gfx/layers/basic/BasicThebesLayer.cpp
@@ -21,16 +21,18 @@
 #include "mozilla/gfx/Types.h"          // for Float, etc
 #include "mozilla/layers/LayersTypes.h"
 #include "nsAutoPtr.h"                  // for nsRefPtr
 #include "nsCOMPtr.h"                   // for already_AddRefed
 #include "nsISupportsImpl.h"            // for gfxContext::Release, etc
 #include "nsPoint.h"                    // for nsIntPoint
 #include "nsRect.h"                     // for nsIntRect
 #include "nsTArray.h"                   // for nsTArray, nsTArray_Impl
+#include "AutoMaskData.h"
+
 struct gfxMatrix;
 
 using namespace mozilla::gfx;
 
 namespace mozilla {
 namespace layers {
 
 static nsIntRegion
--- a/gfx/layers/client/ContentClient.h
+++ b/gfx/layers/client/ContentClient.h
@@ -3,17 +3,17 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef MOZILLA_GFX_CONTENTCLIENT_H
 #define MOZILLA_GFX_CONTENTCLIENT_H
 
 #include <stdint.h>                     // for uint32_t
 #include "ThebesLayerBuffer.h"          // for ThebesLayerBuffer, etc
-#include "gfxASurface.h"                // for gfxASurface, etc
+#include "gfxTypes.h"
 #include "gfxPlatform.h"                // for gfxPlatform
 #include "mozilla/Assertions.h"         // for MOZ_CRASH
 #include "mozilla/Attributes.h"         // for MOZ_OVERRIDE
 #include "mozilla/RefPtr.h"             // for RefPtr, TemporaryRef
 #include "mozilla/gfx/Point.h"          // for IntSize
 #include "mozilla/layers/CompositableClient.h"  // for CompositableClient
 #include "mozilla/layers/CompositableForwarder.h"
 #include "mozilla/layers/CompositorTypes.h"  // for TextureInfo, etc
@@ -24,16 +24,17 @@
 #include "nsCOMPtr.h"                   // for already_AddRefed
 #include "nsPoint.h"                    // for nsIntPoint
 #include "nsRect.h"                     // for nsIntRect
 #include "nsRegion.h"                   // for nsIntRegion
 #include "nsTArray.h"                   // for nsTArray
 
 class gfxContext;
 struct gfxMatrix;
+class gfxASurface;
 
 namespace mozilla {
 namespace gfx {
 class DrawTarget;
 }
 
 namespace layers {
 
--- a/gfx/layers/client/TextureClient.cpp
+++ b/gfx/layers/client/TextureClient.cpp
@@ -378,16 +378,21 @@ DeprecatedTextureClient::~DeprecatedText
 }
 
 DeprecatedTextureClientShmem::DeprecatedTextureClientShmem(CompositableForwarder* aForwarder,
                                        const TextureInfo& aTextureInfo)
   : DeprecatedTextureClient(aForwarder, aTextureInfo)
 {
 }
 
+DeprecatedTextureClientShmem::~DeprecatedTextureClientShmem()
+{
+  ReleaseResources();
+}
+
 void
 DeprecatedTextureClientShmem::ReleaseResources()
 {
   if (mSurface) {
     mSurface = nullptr;
     mSurfaceAsImage = nullptr;
 
     ShadowLayerForwarder::CloseDescriptor(mDescriptor);
--- a/gfx/layers/client/TextureClient.h
+++ b/gfx/layers/client/TextureClient.h
@@ -7,33 +7,33 @@
 #define MOZILLA_GFX_TEXTURECLIENT_H
 
 #include <stddef.h>                     // for size_t
 #include <stdint.h>                     // for uint32_t, uint8_t, uint64_t
 #include "GLContextTypes.h"             // for GLContext (ptr only), etc
 #include "GLTextureImage.h"             // for TextureImage
 #include "ImageContainer.h"             // for PlanarYCbCrImage, etc
 #include "ImageTypes.h"                 // for StereoMode
-#include "gfxASurface.h"                // for gfxASurface, etc
-#include "gfxImageSurface.h"            // for gfxImageSurface
 #include "mozilla/Assertions.h"         // for MOZ_ASSERT, etc
 #include "mozilla/Attributes.h"         // for MOZ_OVERRIDE
 #include "mozilla/RefPtr.h"             // for RefPtr, RefCounted
 #include "mozilla/gfx/2D.h"             // for DrawTarget
 #include "mozilla/gfx/Point.h"          // for IntSize
 #include "mozilla/gfx/Types.h"          // for SurfaceFormat
 #include "mozilla/ipc/Shmem.h"          // for Shmem
 #include "mozilla/layers/CompositorTypes.h"  // for TextureFlags, etc
 #include "mozilla/layers/LayersSurfaces.h"  // for SurfaceDescriptor
 #include "mozilla/mozalloc.h"           // for operator delete
 #include "nsAutoPtr.h"                  // for nsRefPtr
 #include "nsCOMPtr.h"                   // for already_AddRefed
 #include "nsISupportsImpl.h"            // for TextureImage::AddRef, etc
 
 class gfxReusableSurfaceWrapper;
+class gfxASurface;
+class gfxImageSurface;
 
 namespace mozilla {
 namespace layers {
 
 class ContentClient;
 class CompositableForwarder;
 class ISurfaceAllocator;
 class CompositableClient;
@@ -485,18 +485,17 @@ protected:
   TextureInfo mTextureInfo;
   AccessMode mAccessMode;
 };
 
 class DeprecatedTextureClientShmem : public DeprecatedTextureClient
 {
 public:
   DeprecatedTextureClientShmem(CompositableForwarder* aForwarder, const TextureInfo& aTextureInfo);
-  ~DeprecatedTextureClientShmem() { ReleaseResources(); }
-
+  ~DeprecatedTextureClientShmem();
   virtual bool SupportsType(DeprecatedTextureClientType aType) MOZ_OVERRIDE
   {
     return aType == TEXTURE_SHMEM || aType == TEXTURE_CONTENT || aType == TEXTURE_FALLBACK;
   }
   virtual gfxImageSurface* LockImageSurface() MOZ_OVERRIDE;
   virtual gfxASurface* LockSurface() MOZ_OVERRIDE { return GetSurface(); }
   virtual gfx::DrawTarget* LockDrawTarget();
   virtual gfx::BackendType BackendType() MOZ_OVERRIDE
--- a/gfx/layers/client/TiledContentClient.h
+++ b/gfx/layers/client/TiledContentClient.h
@@ -8,34 +8,35 @@
 
 #include <stddef.h>                     // for size_t
 #include <stdint.h>                     // for uint16_t
 #include <algorithm>                    // for swap
 #include "Layers.h"                     // for LayerManager, etc
 #include "TiledLayerBuffer.h"           // for TiledLayerBuffer
 #include "Units.h"                      // for CSSPoint
 #include "gfx3DMatrix.h"                // for gfx3DMatrix
-#include "gfxASurface.h"                // for gfxASurface, etc
-#include "gfxImageSurface.h"            // for gfxImageSurface
+#include "gfxTypes.h"
 #include "gfxPoint.h"                   // for gfxSize
 #include "mozilla/Attributes.h"         // for MOZ_OVERRIDE
 #include "mozilla/RefPtr.h"             // for RefPtr
 #include "mozilla/layers/CompositableClient.h"  // for CompositableClient
 #include "mozilla/layers/CompositorTypes.h"  // for TextureInfo, etc
 #include "mozilla/layers/TextureClient.h"
 #include "mozilla/mozalloc.h"           // for operator delete
 #include "nsAutoPtr.h"                  // for nsRefPtr
 #include "nsPoint.h"                    // for nsIntPoint
 #include "nsRect.h"                     // for nsIntRect
 #include "nsRegion.h"                   // for nsIntRegion
 #include "nsTArray.h"                   // for nsTArray, nsTArray_Impl, etc
 #include "nsTraceRefcnt.h"              // for MOZ_COUNT_DTOR
 #include "mozilla/layers/ISurfaceAllocator.h"
 #include "gfxReusableSurfaceWrapper.h"
 
+class gfxImageSurface;
+
 namespace mozilla {
 namespace layers {
 
 class BasicTileDescriptor;
 
 /**
  * Represent a single tile in tiled buffer. The buffer keeps tiles,
  * each tile keeps a reference to a texture client. The texture client
--- a/gfx/layers/composite/TextureHost.h
+++ b/gfx/layers/composite/TextureHost.h
@@ -3,17 +3,17 @@
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef MOZILLA_GFX_TEXTUREHOST_H
 #define MOZILLA_GFX_TEXTUREHOST_H
 
 #include <stddef.h>                     // for size_t
 #include <stdint.h>                     // for uint64_t, uint32_t, uint8_t
-#include "gfxASurface.h"                // for gfxASurface, etc
+#include "gfxTypes.h"
 #include "mozilla/Assertions.h"         // for MOZ_ASSERT, etc
 #include "mozilla/Attributes.h"         // for MOZ_OVERRIDE
 #include "mozilla/RefPtr.h"             // for RefPtr, TemporaryRef, etc
 #include "mozilla/gfx/2D.h"             // for DataSourceSurface
 #include "mozilla/gfx/Point.h"          // for IntSize, IntPoint
 #include "mozilla/gfx/Types.h"          // for SurfaceFormat, etc
 #include "mozilla/layers/CompositorTypes.h"  // for TextureFlags, etc
 #include "mozilla/layers/LayersTypes.h"  // for LayerRenderState, etc
--- a/gfx/layers/d3d10/CanvasLayerD3D10.h
+++ b/gfx/layers/d3d10/CanvasLayerD3D10.h
@@ -2,20 +2,21 @@
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef GFX_CANVASLAYERD3D10_H
 #define GFX_CANVASLAYERD3D10_H
 
 #include "LayerManagerD3D10.h"
-#include "gfxASurface.h"
 
 #include "mozilla/Preferences.h"
 
+class gfxASurface;
+
 namespace mozilla {
 
 namespace gl {
 class GLContext;
 }
 
 namespace layers {
 
--- a/gfx/layers/d3d9/CanvasLayerD3D9.h
+++ b/gfx/layers/d3d9/CanvasLayerD3D9.h
@@ -3,17 +3,18 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef GFX_CANVASLAYERD3D9_H
 #define GFX_CANVASLAYERD3D9_H
 
 #include "LayerManagerD3D9.h"
 #include "GLContextTypes.h"
-#include "gfxASurface.h"
+
+class gfxASurface;
 
 namespace mozilla {
 namespace layers {
 
 
 class CanvasLayerD3D9 :
   public CanvasLayer,
   public LayerD3D9
--- a/gfx/layers/ipc/CompositableForwarder.h
+++ b/gfx/layers/ipc/CompositableForwarder.h
@@ -3,17 +3,17 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef MOZILLA_LAYERS_COMPOSITABLEFORWARDER
 #define MOZILLA_LAYERS_COMPOSITABLEFORWARDER
 
 #include <stdint.h>                     // for int32_t, uint64_t
-#include "gfxASurface.h"                // for gfxASurface, etc
+#include "gfxTypes.h"
 #include "mozilla/Attributes.h"         // for MOZ_OVERRIDE
 #include "mozilla/layers/CompositorTypes.h"
 #include "mozilla/layers/ISurfaceAllocator.h"  // for ISurfaceAllocator
 #include "mozilla/layers/LayersTypes.h"  // for LayersBackend
 #include "nsRegion.h"                   // for nsIntRegion
 
 struct nsIntPoint;
 struct nsIntRect;
--- a/gfx/layers/ipc/ISurfaceAllocator.h
+++ b/gfx/layers/ipc/ISurfaceAllocator.h
@@ -3,32 +3,31 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef GFX_LAYERS_ISURFACEDEALLOCATOR
 #define GFX_LAYERS_ISURFACEDEALLOCATOR
 
 #include <stddef.h>                     // for size_t
 #include <stdint.h>                     // for uint32_t
-#include "gfxASurface.h"                // for gfxASurface, etc
+#include "gfxTypes.h"
 #include "gfxPoint.h"                   // for gfxIntSize
 #include "mozilla/ipc/SharedMemory.h"   // for SharedMemory, etc
 
 /*
  * FIXME [bjacob] *** PURE CRAZYNESS WARNING ***
  *
  * This #define is actually needed here, because subclasses of ISurfaceAllocator,
  * namely ShadowLayerForwarder, will or will not override AllocGrallocBuffer
  * depending on whether MOZ_HAVE_SURFACEDESCRIPTORGRALLOC is defined.
  */
 #ifdef MOZ_WIDGET_GONK
 #define MOZ_HAVE_SURFACEDESCRIPTORGRALLOC
 #endif
 
-class gfxASurface;
 class gfxSharedImageSurface;
 
 namespace base {
 class Thread;
 }
 
 namespace mozilla {
 namespace ipc {
--- a/gfx/layers/ipc/ShadowLayers.h
+++ b/gfx/layers/ipc/ShadowLayers.h
@@ -5,30 +5,31 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozilla_layers_ShadowLayers_h
 #define mozilla_layers_ShadowLayers_h 1
 
 #include <stddef.h>                     // for size_t
 #include <stdint.h>                     // for uint64_t
-#include "gfxASurface.h"                // for gfxASurface, etc
+#include "gfxTypes.h"
 #include "gfxPoint.h"                   // for gfxIntSize
 #include "mozilla/Attributes.h"         // for MOZ_OVERRIDE
 #include "mozilla/WidgetUtils.h"        // for ScreenRotation
 #include "mozilla/dom/ScreenOrientation.h"  // for ScreenOrientation
 #include "mozilla/ipc/SharedMemory.h"   // for SharedMemory, etc
 #include "mozilla/layers/CompositableForwarder.h"
 #include "mozilla/layers/CompositorTypes.h"  // for OpenMode, etc
 #include "nsCOMPtr.h"                   // for already_AddRefed
 #include "nsRegion.h"                   // for nsIntRegion
 #include "nsTArrayForwardDeclare.h"     // for InfallibleTArray
  
 struct nsIntPoint;
 struct nsIntRect;
+class gfxASurface;
 
 namespace mozilla {
 namespace layers {
 
 class BasicTiledLayerBuffer;
 class CanvasClient;
 class CanvasLayerComposite;
 class CanvasSurface;
--- a/gfx/layers/ipc/SharedRGBImage.h
+++ b/gfx/layers/ipc/SharedRGBImage.h
@@ -3,24 +3,26 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef SHAREDRGBIMAGE_H_
 #define SHAREDRGBIMAGE_H_
 
 #include <stddef.h>                     // for size_t
 #include <stdint.h>                     // for uint8_t
 #include "ImageContainer.h"             // for ISharedImage, Image, etc
-#include "gfxASurface.h"                // for gfxASurface, etc
+#include "gfxTypes.h"
 #include "gfxPoint.h"                   // for gfxIntSize
 #include "mozilla/Attributes.h"         // for MOZ_OVERRIDE
 #include "mozilla/RefPtr.h"             // for RefPtr
 #include "mozilla/gfx/Point.h"          // for IntSize
 #include "mozilla/gfx/Types.h"          // for SurfaceFormat
 #include "nsCOMPtr.h"                   // for already_AddRefed
 
+class gfxASurface;
+
 namespace mozilla {
 namespace ipc {
 class Shmem;
 }
 
 namespace layers {
 
 class BufferTextureClient;
--- a/gfx/layers/opengl/CanvasLayerOGL.cpp
+++ b/gfx/layers/opengl/CanvasLayerOGL.cpp
@@ -41,16 +41,37 @@
 #include "gfxXlibSurface.h"
 #endif
 
 using namespace mozilla;
 using namespace mozilla::layers;
 using namespace mozilla::gl;
 using namespace mozilla::gfx;
 
+CanvasLayerOGL::CanvasLayerOGL(LayerManagerOGL *aManager)
+  : CanvasLayer(aManager, nullptr)
+  , LayerOGL(aManager)
+  , mLayerProgram(RGBALayerProgramType)
+  , mTexture(0)
+  , mTextureTarget(LOCAL_GL_TEXTURE_2D)
+  , mDelayedUpdates(false)
+  , mIsGLAlphaPremult(false)
+  , mUploadTexture(0)
+#if defined(GL_PROVIDER_GLX)
+  , mPixmap(0)
+#endif
+{
+  mImplData = static_cast<LayerOGL*>(this);
+  mForceReadback = Preferences::GetBool("webgl.force-layers-readback", false);
+}
+
+CanvasLayerOGL::~CanvasLayerOGL() {
+  Destroy();
+}
+
 static void
 MakeTextureIfNeeded(GLContext* gl, GLuint& aTexture)
 {
   if (aTexture != 0)
     return;
 
   gl->fGenTextures(1, &aTexture);
 
@@ -356,8 +377,25 @@ void
 CanvasLayerOGL::CleanupResources()
 {
   if (mUploadTexture) {
     gl()->MakeCurrent();
     gl()->fDeleteTextures(1, &mUploadTexture);
     mUploadTexture = 0;
   }
 }
+
+gfxImageSurface*
+CanvasLayerOGL::GetTempSurface(const gfxIntSize& aSize,
+                               const gfxImageFormat aFormat)
+{
+  if (!mCachedTempSurface ||
+      aSize.width != mCachedSize.width ||
+      aSize.height != mCachedSize.height ||
+      aFormat != mCachedFormat)
+  {
+    mCachedTempSurface = new gfxImageSurface(aSize, aFormat);
+    mCachedSize = aSize;
+    mCachedFormat = aFormat;
+  }
+
+  return mCachedTempSurface;
+}
--- a/gfx/layers/opengl/CanvasLayerOGL.h
+++ b/gfx/layers/opengl/CanvasLayerOGL.h
@@ -5,61 +5,43 @@
 
 #ifndef GFX_CANVASLAYEROGL_H
 #define GFX_CANVASLAYEROGL_H
 
 #include "GLContextTypes.h"             // for GLContext
 #include "GLDefs.h"                     // for GLuint, LOCAL_GL_TEXTURE_2D
 #include "LayerManagerOGL.h"            // for LayerOGL::GLContext, etc
 #include "Layers.h"                     // for CanvasLayer, etc
-#include "gfxASurface.h"                // for gfxASurface, etc
-#include "gfxImageSurface.h"            // for gfxImageSurface
+#include "gfxTypes.h"
 #include "gfxPoint.h"                   // for gfxIntSize
 #include "mozilla/Preferences.h"        // for Preferences
 #include "mozilla/RefPtr.h"             // for RefPtr
 #include "mozilla/gfx/2D.h"             // for DrawTarget
 #include "mozilla/mozalloc.h"           // for operator delete, etc
 #include "nsAutoPtr.h"                  // for nsRefPtr
 #include "opengl/LayerManagerOGLProgram.h"  // for ShaderProgramType, etc
 #if defined(GL_PROVIDER_GLX)
 #include "GLXLibrary.h"
 #include "mozilla/X11Util.h"
 #endif
 
 struct nsIntPoint;
-
+class gfxASurface;
+class gfxImageSurface;
 
 namespace mozilla {
 namespace layers {
 
 class CanvasLayerOGL :
   public CanvasLayer,
   public LayerOGL
 {
 public:
-  CanvasLayerOGL(LayerManagerOGL *aManager)
-    : CanvasLayer(aManager, nullptr)
-    , LayerOGL(aManager)
-    , mLayerProgram(RGBALayerProgramType)
-    , mTexture(0)
-    , mTextureTarget(LOCAL_GL_TEXTURE_2D)
-    , mDelayedUpdates(false)
-    , mIsGLAlphaPremult(false)
-    , mUploadTexture(0)
-#if defined(GL_PROVIDER_GLX)
-    , mPixmap(0)
-#endif
-  { 
-    mImplData = static_cast<LayerOGL*>(this);
-    mForceReadback = Preferences::GetBool("webgl.force-layers-readback", false);
-  }
-
-  ~CanvasLayerOGL() {
-    Destroy();
-  }
+  CanvasLayerOGL(LayerManagerOGL *aManager);
+  ~CanvasLayerOGL();
 
   // CanvasLayer implementation
   virtual void Initialize(const Data& aData);
 
   // LayerOGL implementation
   virtual void Destroy();
   virtual Layer* GetLayer() { return this; }
   virtual void RenderLayer(int aPreviousFrameBuffer,
@@ -86,30 +68,17 @@ protected:
   GLXPixmap mPixmap;
 #endif
 
   nsRefPtr<gfxImageSurface> mCachedTempSurface;
   gfxIntSize mCachedSize;
   gfxImageFormat mCachedFormat;
 
   gfxImageSurface* GetTempSurface(const gfxIntSize& aSize,
-                                  const gfxImageFormat aFormat)
-  {
-    if (!mCachedTempSurface ||
-        aSize.width != mCachedSize.width ||
-        aSize.height != mCachedSize.height ||
-        aFormat != mCachedFormat)
-    {
-      mCachedTempSurface = new gfxImageSurface(aSize, aFormat);
-      mCachedSize = aSize;
-      mCachedFormat = aFormat;
-    }
-
-    return mCachedTempSurface;
-  }
+                                  const gfxImageFormat aFormat);
 
   void DiscardTempSurface() {
     mCachedTempSurface = nullptr;
   }
 };
 
 } /* layers */
 } /* mozilla */
--- a/gfx/layers/opengl/LayerManagerOGLProgram.h
+++ b/gfx/layers/opengl/LayerManagerOGLProgram.h
@@ -3,17 +3,17 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef GFX_LAYERMANAGEROGLPROGRAM_H
 #define GFX_LAYERMANAGEROGLPROGRAM_H
 
 #include "GLDefs.h"                     // for GLint, GLenum, GLuint, etc
 #include "gfx3DMatrix.h"                // for gfx3DMatrix
-#include "gfxASurface.h"                // for gfxASurface, etc
+#include "gfxTypes.h"
 #include "mozilla/Assertions.h"         // for MOZ_ASSERT, etc
 #include "mozilla/RefPtr.h"             // for RefPtr
 #include "mozilla/gfx/Matrix.h"         // for Matrix4x4
 #include "mozilla/gfx/Rect.h"           // for Rect
 #include "mozilla/gfx/Types.h"
 #include "nsDebug.h"                    // for NS_ASSERTION
 #include "nsPoint.h"                    // for nsIntPoint
 #include "nsTArray.h"                   // for nsTArray
--- a/gfx/layers/opengl/TextureClientOGL.h
+++ b/gfx/layers/opengl/TextureClientOGL.h
@@ -2,17 +2,17 @@
 //  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef MOZILLA_GFX_TEXTURECLIENTOGL_H
 #define MOZILLA_GFX_TEXTURECLIENTOGL_H
 
 #include "GLContextTypes.h"             // for SharedTextureHandle, etc
-#include "gfxASurface.h"                // for gfxASurface, etc
+#include "gfxTypes.h"
 #include "mozilla/Attributes.h"         // for MOZ_OVERRIDE
 #include "mozilla/gfx/Point.h"          // for IntSize
 #include "mozilla/layers/CompositorTypes.h"
 #include "mozilla/layers/LayersSurfaces.h"  // for SurfaceDescriptor
 #include "mozilla/layers/TextureClient.h"  // for DeprecatedTextureClient, etc
 
 namespace mozilla {
 namespace layers {
--- a/gfx/layers/opengl/TextureHostOGL.h
+++ b/gfx/layers/opengl/TextureHostOGL.h
@@ -8,17 +8,17 @@
 
 #include <stddef.h>                     // for size_t
 #include <stdint.h>                     // for uint64_t
 #include "CompositableHost.h"
 #include "GLContextTypes.h"             // for GLContext
 #include "GLDefs.h"                     // for GLenum, LOCAL_GL_CLAMP_TO_EDGE, etc
 #include "GLTextureImage.h"             // for TextureImage
 #include "gfx3DMatrix.h"                // for gfx3DMatrix
-#include "gfxASurface.h"                // for gfxASurface, etc
+#include "gfxTypes.h"
 #include "mozilla/GfxMessageUtils.h"    // for gfxContentType
 #include "mozilla/Assertions.h"         // for MOZ_ASSERT, etc
 #include "mozilla/Attributes.h"         // for MOZ_OVERRIDE
 #include "mozilla/RefPtr.h"             // for RefPtr
 #include "mozilla/gfx/Point.h"          // for IntSize, IntPoint
 #include "mozilla/gfx/Types.h"          // for SurfaceFormat, etc
 #include "mozilla/layers/CompositorTypes.h"  // for TextureFlags
 #include "mozilla/layers/LayersSurfaces.h"  // for SurfaceDescriptor
--- a/gfx/thebes/gfxASurface.h
+++ b/gfx/thebes/gfxASurface.h
@@ -16,21 +16,16 @@
 #include "nscore.h"
 
 #ifdef MOZILLA_INTERNAL_API
 #include "nsStringFwd.h"
 #else
 #include "nsStringAPI.h"
 #endif
 
-typedef struct _cairo_surface cairo_surface_t;
-typedef struct _cairo_user_data_key cairo_user_data_key_t;
-
-typedef void (*thebes_destroy_func_t) (void *data);
-
 class gfxImageSurface;
 struct nsIntPoint;
 struct nsIntRect;
 struct gfxRect;
 struct gfxPoint;
 struct nsIntSize;
 
 template <typename T>
--- a/gfx/thebes/gfxPlatform.h
+++ b/gfx/thebes/gfxPlatform.h
@@ -9,33 +9,33 @@
 #include "prlog.h"
 #include "nsTArray.h"
 #include "nsString.h"
 #include "nsIObserver.h"
 #include "nsCOMPtr.h"
 #include "nsAutoPtr.h"
 
 #include "gfxTypes.h"
-#include "gfxASurface.h"
 #include "gfxColor.h"
 #include "nsRect.h"
 
 #include "qcms.h"
 
 #include "mozilla/gfx/2D.h"
 #include "gfx2DGlue.h"
 #include "mozilla/RefPtr.h"
 #include "GfxInfoCollector.h"
 
 #include "mozilla/layers/CompositorTypes.h"
 
 #ifdef XP_OS2
 #undef OS2EMX_PLAIN_CHAR
 #endif
 
+class gfxASurface;
 class gfxImageSurface;
 class gfxFont;
 class gfxFontGroup;
 struct gfxFontStyle;
 class gfxUserFontSet;
 class gfxFontEntry;
 class gfxProxyFontEntry;
 class gfxPlatformFontList;
--- a/gfx/thebes/gfxTypes.h
+++ b/gfx/thebes/gfxTypes.h
@@ -1,16 +1,21 @@
 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef GFX_TYPES_H
 #define GFX_TYPES_H
 
+typedef struct _cairo_surface cairo_surface_t;
+typedef struct _cairo_user_data_key cairo_user_data_key_t;
+
+typedef void (*thebes_destroy_func_t) (void *data);
+
 /**
  * Currently needs to be 'double' for Cairo compatibility. Could
  * become 'float', perhaps, in some configurations.
  */
 typedef double gfxFloat;
 
 /**
  * Priority of a line break opportunity.
--- a/image/decoders/nsPNGDecoder.h
+++ b/image/decoders/nsPNGDecoder.h
@@ -4,17 +4,17 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef nsPNGDecoder_h__
 #define nsPNGDecoder_h__
 
 #include "Decoder.h"
 
-#include "gfxASurface.h"
+#include "gfxTypes.h"
 
 #include "nsCOMPtr.h"
 
 #include "png.h"
 
 #include "qcms.h"
 
 namespace mozilla {
--- a/image/src/FrameBlender.h
+++ b/image/src/FrameBlender.h
@@ -3,17 +3,17 @@
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozilla_imagelib_FrameBlender_h_
 #define mozilla_imagelib_FrameBlender_h_
 
 #include "mozilla/MemoryReporting.h"
-#include "gfxASurface.h"
+#include "gfxTypes.h"
 #include "FrameSequence.h"
 #include "nsCOMPtr.h"
 
 class imgFrame;
 
 namespace mozilla {
 namespace image {
 
--- a/image/src/FrameSequence.h
+++ b/image/src/FrameSequence.h
@@ -4,17 +4,17 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozilla_imagelib_FrameSequence_h_
 #define mozilla_imagelib_FrameSequence_h_
 
 #include "nsTArray.h"
 #include "mozilla/MemoryReporting.h"
-#include "gfxASurface.h"
+#include "gfxTypes.h"
 #include "imgFrame.h"
 
 namespace mozilla {
 namespace image {
 
 /**
  * FrameDataPair is a slightly-smart tuple of (frame, raw frame data) where the
  * raw frame data is allowed to be (and is, initially) null.
--- a/widget/android/AndroidDirectTexture.h
+++ b/widget/android/AndroidDirectTexture.h
@@ -1,17 +1,17 @@
 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef AndroidDirectTexture_h_
 #define AndroidDirectTexture_h_
 
-#include "gfxASurface.h"
+#include "gfxTypes.h"
 #include "mozilla/Mutex.h"
 #include "AndroidGraphicBuffer.h"
 
 struct nsIntRect;
 
 namespace mozilla {
 
 /**
--- a/widget/android/AndroidGraphicBuffer.h
+++ b/widget/android/AndroidGraphicBuffer.h
@@ -1,17 +1,17 @@
 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef AndroidGraphicBuffer_h_
 #define AndroidGraphicBuffer_h_
 
-#include "gfxASurface.h"
+#include "gfxTypes.h"
 
 typedef void* EGLImageKHR;
 typedef void* EGLClientBuffer;
 
 struct nsIntRect;
 
 namespace mozilla {
 
--- a/widget/cocoa/nsNativeThemeCocoa.h
+++ b/widget/cocoa/nsNativeThemeCocoa.h
@@ -8,17 +8,16 @@
 
 #import <Carbon/Carbon.h>
 #import <Cocoa/Cocoa.h>
 
 #include "nsITheme.h"
 #include "nsCOMPtr.h"
 #include "nsIAtom.h"
 #include "nsNativeTheme.h"
-#include "gfxASurface.h"
 
 @class CellDrawView;
 @class NSProgressBarCell;
 @class ContextAwareSearchFieldCell;
 class nsDeviceContext;
 struct SegmentedControlRenderSettings;
 
 class nsNativeThemeCocoa : private nsNativeTheme,
--- a/widget/gtk/nsWindow.h
+++ b/widget/gtk/nsWindow.h
@@ -14,18 +14,16 @@
 
 #include "mozcontainer.h"
 #include "nsWeakReference.h"
 
 #include "nsIDragService.h"
 #include "nsITimer.h"
 #include "nsGkAtoms.h"
 
-#include "gfxASurface.h"
-
 #include "nsBaseWidget.h"
 #include "nsGUIEvent.h"
 #include <gdk/gdk.h>
 #include <gtk/gtk.h>
 
 #ifdef MOZ_X11
 #include <gdk/gdkx.h>
 #endif /* MOZ_X11 */
@@ -59,16 +57,17 @@ extern PRLogModuleInfo *gWidgetDrawLog;
 
 #define LOG(args)
 #define LOGFOCUS(args)
 #define LOGDRAG(args)
 #define LOGDRAW(args)
 
 #endif /* MOZ_LOGGING */
 
+class gfxASurface;
 class gfxPattern;
 class nsDragService;
 #if defined(MOZ_X11) && defined(MOZ_HAVE_SHAREDMEMORYSYSV)
 #  define MOZ_HAVE_SHMIMAGE
 
 class nsShmImage;
 #endif
 
--- a/widget/os2/nsWindow.h
+++ b/widget/os2/nsWindow.h
@@ -43,17 +43,17 @@
  *
  */
 //=============================================================================
 
 #ifndef _nswindow_h
 #define _nswindow_h
 
 #include "nsBaseWidget.h"
-#include "gfxASurface.h"
+#include "gfxTypes.h"
 
 #define INCL_DOS
 #define INCL_WIN
 #define INCL_NLS
 #define INCL_GPI
 #include <os2.h>
 #include <os2im.h>
 
@@ -67,16 +67,18 @@
 #ifndef WM_MOUSELEAVE
 #define WM_MOUSELEAVE   0x041F
 #endif
 
 #ifndef WM_FOCUSCHANGED
 #define WM_FOCUSCHANGED 0x000E
 #endif
 
+class gfxASurface;
+
 extern "C" {
   PVOID  APIENTRY WinQueryProperty(HWND hwnd, PCSZ pszNameOrAtom);
   PVOID  APIENTRY WinRemoveProperty(HWND hwnd, PCSZ pszNameOrAtom);
   BOOL   APIENTRY WinSetProperty(HWND hwnd, PCSZ pszNameOrAtom,
                                  PVOID pvData, ULONG ulFlags);
   APIRET APIENTRY DosQueryModFromEIP(HMODULE* phMod, ULONG* pObjNum,
                                      ULONG BuffLen,  PCHAR pBuff,
                                      ULONG* pOffset, ULONG Address);
--- a/widget/shared/nsShmImage.h
+++ b/widget/shared/nsShmImage.h
@@ -11,32 +11,33 @@
 
 #if defined(MOZ_X11) && defined(MOZ_HAVE_SHAREDMEMORYSYSV)
 #  define MOZ_HAVE_SHMIMAGE
 #endif
 
 #ifdef MOZ_HAVE_SHMIMAGE
 
 #include "nsIWidget.h"
-#include "gfxASurface.h"
+#include "gfxTypes.h"
 #include "nsAutoPtr.h"
 
 #include "mozilla/X11Util.h"
 #include <X11/Xlib.h>
 #include <X11/Xutil.h>
 #include <X11/extensions/XShm.h>
 
 #if defined(MOZ_WIDGET_GTK)
 #define DISPLAY gdk_x11_get_default_xdisplay
 #elif defined(MOZ_WIDGET_QT)
 #define DISPLAY mozilla::DefaultXDisplay
 #endif
 
 class QRect;
 class QWidget;
+class gfxASurface;
 
 class nsShmImage {
     NS_INLINE_DECL_REFCOUNTING(nsShmImage)
 
     typedef mozilla::ipc::SharedMemorySysV SharedMemorySysV;
 
 public:
     typedef gfxImageFormat Format;