Bug 877115 - [Moz2Dify] Part 3. Change gfxIntSize to gfx::IntSize in GLContext::OffscreenSize and dependendent classes. r=nical
☠☠ backed out by 2dc6642eba5d ☠ ☠
authorAndreas Pehrson <pehrsons@gmail.com>
Tue, 10 Dec 2013 17:11:58 +0100
changeset 161079 4488ec28910eee8aadb9b1557382094eb196d1de
parent 161078 45f8859c6fd6a01d4264b5edd89f925a679814d7
child 161080 290ad58636151001326b02acef73b03126cfd152
push id270
push userpvanderbeken@mozilla.com
push dateThu, 06 Mar 2014 09:24:21 +0000
reviewersnical
bugs877115
milestone29.0a1
Bug 877115 - [Moz2Dify] Part 3. Change gfxIntSize to gfx::IntSize in GLContext::OffscreenSize and dependendent classes. r=nical
gfx/gl/GLBlitHelper.cpp
gfx/gl/GLBlitHelper.h
gfx/gl/GLContext.cpp
gfx/gl/GLContext.h
gfx/gl/GLScreenBuffer.cpp
gfx/gl/GLScreenBuffer.h
gfx/gl/GLUploadHelpers.h
gfx/gl/SharedSurface.h
gfx/gl/SharedSurfaceANGLE.cpp
gfx/gl/SharedSurfaceANGLE.h
gfx/gl/SharedSurfaceEGL.cpp
gfx/gl/SharedSurfaceEGL.h
gfx/gl/SharedSurfaceGL.cpp
gfx/gl/SharedSurfaceGL.h
gfx/gl/SharedSurfaceGralloc.cpp
gfx/gl/SharedSurfaceGralloc.h
gfx/gl/SharedSurfaceIO.cpp
gfx/gl/SharedSurfaceIO.h
gfx/gl/SurfaceFactory.h
gfx/layers/CopyableCanvasLayer.cpp
gfx/layers/d3d10/CanvasLayerD3D10.cpp
gfx/layers/d3d9/CanvasLayerD3D9.cpp
gfx/layers/opengl/TextureHostOGL.cpp
--- a/gfx/gl/GLBlitHelper.cpp
+++ b/gfx/gl/GLBlitHelper.cpp
@@ -9,34 +9,34 @@
 #include "ScopedGLHelpers.h"
 #include "mozilla/Preferences.h"
 
 namespace mozilla {
 namespace gl {
 
 static void
 RenderbufferStorageBySamples(GLContext* aGL, GLsizei aSamples,
-                             GLenum aInternalFormat, const gfxIntSize& aSize)
+                             GLenum aInternalFormat, const gfx::IntSize& aSize)
 {
     if (aSamples) {
         aGL->fRenderbufferStorageMultisample(LOCAL_GL_RENDERBUFFER,
                                              aSamples,
                                              aInternalFormat,
                                              aSize.width, aSize.height);
     } else {
         aGL->fRenderbufferStorage(LOCAL_GL_RENDERBUFFER,
                                   aInternalFormat,
                                   aSize.width, aSize.height);
     }
 }
 
 
 GLuint
 CreateTexture(GLContext* aGL, GLenum aInternalFormat, GLenum aFormat,
-              GLenum aType, const gfxIntSize& aSize)
+              GLenum aType, const gfx::IntSize& aSize)
 {
     GLuint tex = 0;
     aGL->fGenTextures(1, &tex);
     ScopedBindTexture autoTex(aGL, tex);
 
     aGL->fTexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_MIN_FILTER, LOCAL_GL_LINEAR);
     aGL->fTexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_MAG_FILTER, LOCAL_GL_LINEAR);
     aGL->fTexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_WRAP_S, LOCAL_GL_CLAMP_TO_EDGE);
@@ -52,47 +52,47 @@ CreateTexture(GLContext* aGL, GLenum aIn
                      nullptr);
 
     return tex;
 }
 
 
 GLuint
 CreateTextureForOffscreen(GLContext* aGL, const GLFormats& aFormats,
-                          const gfxIntSize& aSize)
+                          const gfx::IntSize& aSize)
 {
     MOZ_ASSERT(aFormats.color_texInternalFormat);
     MOZ_ASSERT(aFormats.color_texFormat);
     MOZ_ASSERT(aFormats.color_texType);
 
     return CreateTexture(aGL,
                          aFormats.color_texInternalFormat,
                          aFormats.color_texFormat,
                          aFormats.color_texType,
                          aSize);
 }
 
 
 GLuint
 CreateRenderbuffer(GLContext* aGL, GLenum aFormat, GLsizei aSamples,
-                   const gfxIntSize& aSize)
+                   const gfx::IntSize& aSize)
 {
     GLuint rb = 0;
     aGL->fGenRenderbuffers(1, &rb);
     ScopedBindRenderbuffer autoRB(aGL, rb);
 
     RenderbufferStorageBySamples(aGL, aSamples, aFormat, aSize);
 
     return rb;
 }
 
 
 void
 CreateRenderbuffersForOffscreen(GLContext* aGL, const GLFormats& aFormats,
-                                const gfxIntSize& aSize, bool aMultisample,
+                                const gfx::IntSize& aSize, bool aMultisample,
                                 GLuint* aColorMSRB, GLuint* aDepthRB,
                                 GLuint* aStencilRB)
 {
     GLsizei samples = aMultisample ? aFormats.samples : 0;
     if (aColorMSRB) {
         MOZ_ASSERT(aFormats.samples > 0);
         MOZ_ASSERT(aFormats.color_rbFormat);
 
@@ -346,17 +346,17 @@ GLBlitHelper::InitTexQuadProgram(GLenum 
                               LOCAL_GL_FLOAT,
                               false,
                               0,
                               nullptr);
     return true;
 }
 
 bool
-GLBlitHelper::UseTexQuadProgram(GLenum target, const gfxIntSize& srcSize)
+GLBlitHelper::UseTexQuadProgram(GLenum target, const gfx::IntSize& srcSize)
 {
     if (!InitTexQuadProgram(target)) {
         return false;
     }
 
     if (target == LOCAL_GL_TEXTURE_RECTANGLE_ARB) {
         GLint texCoordMultLoc = mGL->fGetUniformLocation(mTex2DRectBlit_Program, "uTexCoordMult");
         MOZ_ASSERT(texCoordMultLoc != -1, "uniform not found");
@@ -392,18 +392,18 @@ GLBlitHelper::DeleteTexBlitProgram()
     if (mTex2DRectBlit_Program) {
         mGL->fDeleteProgram(mTex2DRectBlit_Program);
         mTex2DRectBlit_Program = 0;
     }
 }
 
 void
 GLBlitHelper::BlitFramebufferToFramebuffer(GLuint srcFB, GLuint destFB,
-                                        const gfxIntSize& srcSize,
-                                        const gfxIntSize& destSize)
+                                        const gfx::IntSize& srcSize,
+                                        const gfx::IntSize& destSize)
 {
     MOZ_ASSERT(!srcFB || mGL->fIsFramebuffer(srcFB));
     MOZ_ASSERT(!destFB || mGL->fIsFramebuffer(destFB));
 
     MOZ_ASSERT(mGL->IsSupported(GLFeature::framebuffer_blit));
 
     ScopedBindFramebuffer boundFB(mGL);
     ScopedGLState scissor(mGL, LOCAL_GL_SCISSOR_TEST, false);
@@ -414,18 +414,18 @@ GLBlitHelper::BlitFramebufferToFramebuff
     mGL->fBlitFramebuffer(0, 0,  srcSize.width,  srcSize.height,
                           0, 0, destSize.width, destSize.height,
                           LOCAL_GL_COLOR_BUFFER_BIT,
                           LOCAL_GL_NEAREST);
 }
 
 void
 GLBlitHelper::BlitFramebufferToFramebuffer(GLuint srcFB, GLuint destFB,
-                                        const gfxIntSize& srcSize,
-                                        const gfxIntSize& destSize,
+                                        const gfx::IntSize& srcSize,
+                                        const gfx::IntSize& destSize,
                                         const GLFormats& srcFormats)
 {
     MOZ_ASSERT(!srcFB || mGL->fIsFramebuffer(srcFB));
     MOZ_ASSERT(!destFB || mGL->fIsFramebuffer(destFB));
 
     if (mGL->IsSupported(GLFeature::framebuffer_blit)) {
         BlitFramebufferToFramebuffer(srcFB, destFB,
                                      srcSize, destSize);
@@ -438,18 +438,18 @@ GLBlitHelper::BlitFramebufferToFramebuff
     BlitFramebufferToTexture(srcFB, tex, srcSize, srcSize);
     BlitTextureToFramebuffer(tex, destFB, srcSize, destSize);
 
     mGL->fDeleteTextures(1, &tex);
 }
 
 void
 GLBlitHelper::BlitTextureToFramebuffer(GLuint srcTex, GLuint destFB,
-                                    const gfxIntSize& srcSize,
-                                    const gfxIntSize& destSize,
+                                    const gfx::IntSize& srcSize,
+                                    const gfx::IntSize& destSize,
                                     GLenum srcTarget)
 {
     MOZ_ASSERT(mGL->fIsTexture(srcTex));
     MOZ_ASSERT(!destFB || mGL->fIsFramebuffer(destFB));
 
     if (mGL->IsSupported(GLFeature::framebuffer_blit)) {
         ScopedFramebufferForTexture srcWrapper(mGL, srcTex, srcTarget);
         MOZ_ASSERT(srcWrapper.IsComplete());
@@ -558,18 +558,18 @@ GLBlitHelper::BlitTextureToFramebuffer(G
 
     mGL->fBindBuffer(LOCAL_GL_ARRAY_BUFFER, boundBuffer);
 
     mGL->fUseProgram(boundProgram);
 }
 
 void
 GLBlitHelper::BlitFramebufferToTexture(GLuint srcFB, GLuint destTex,
-                                    const gfxIntSize& srcSize,
-                                    const gfxIntSize& destSize,
+                                    const gfx::IntSize& srcSize,
+                                    const gfx::IntSize& destSize,
                                     GLenum destTarget)
 {
     MOZ_ASSERT(!srcFB || mGL->fIsFramebuffer(srcFB));
     MOZ_ASSERT(mGL->fIsTexture(destTex));
 
     if (mGL->IsSupported(GLFeature::framebuffer_blit)) {
         ScopedFramebufferForTexture destWrapper(mGL, destTex, destTarget);
 
@@ -585,18 +585,18 @@ GLBlitHelper::BlitFramebufferToTexture(G
     mGL->fCopyTexSubImage2D(destTarget, 0,
                        0, 0,
                        0, 0,
                        srcSize.width, srcSize.height);
 }
 
 void
 GLBlitHelper::BlitTextureToTexture(GLuint srcTex, GLuint destTex,
-                                const gfxIntSize& srcSize,
-                                const gfxIntSize& destSize,
+                                const gfx::IntSize& srcSize,
+                                const gfx::IntSize& destSize,
                                 GLenum srcTarget, GLenum destTarget)
 {
     MOZ_ASSERT(mGL->fIsTexture(srcTex));
     MOZ_ASSERT(mGL->fIsTexture(destTex));
 
     // Generally, just use the CopyTexSubImage path
     ScopedFramebufferForTexture srcWrapper(mGL, srcTex, srcTarget);
 
--- a/gfx/gl/GLBlitHelper.h
+++ b/gfx/gl/GLBlitHelper.h
@@ -6,62 +6,61 @@
 
 #ifndef GLBLITHELPER_H_
 #define GLBLITHELPER_H_
 
 #include "GLContextTypes.h"
 #include "GLConsts.h"
 #include "nsSize.h"
 #include "mozilla/Attributes.h"
-
-struct nsIntSize;
+#include "mozilla/gfx/Point.h"
 
 namespace mozilla {
 namespace gl {
 
 class GLContext;
 
 /**
  * Helper function that creates a 2D texture aSize.width x aSize.height with
  * storage type specified by aFormats. Returns GL texture object id.
  *
  * See mozilla::gl::CreateTexture.
  */
 GLuint CreateTextureForOffscreen(GLContext* aGL, const GLFormats& aFormats,
-                                 const gfxIntSize& aSize);
+                                 const gfx::IntSize& aSize);
 
 /**
  * Helper function that creates a 2D texture aSize.width x aSize.height with
  * storage type aInternalFormat. Returns GL texture object id.
  *
  * Initialize textyre parameters to:
  *    GL_TEXTURE_MIN_FILTER = GL_LINEAR
  *    GL_TEXTURE_MAG_FILTER = GL_LINEAR
  *    GL_TEXTURE_WRAP_S = GL_CLAMP_TO_EDGE
  *    GL_TEXTURE_WRAP_T = GL_CLAMP_TO_EDGE
  */
 GLuint CreateTexture(GLContext* aGL, GLenum aInternalFormat, GLenum aFormat,
-                     GLenum aType, const gfxIntSize& aSize);
+                     GLenum aType, const gfx::IntSize& aSize);
 
 /**
  * Helper function to create, potentially, multisample render buffers suitable
  * for offscreen rendering. Buffers of size aSize.width x aSize.height with
  * storage specified by aFormat. returns GL render buffer object id.
  */
 GLuint CreateRenderbuffer(GLContext* aGL, GLenum aFormat, GLsizei aSamples,
-                          const gfxIntSize& aSize);
+                          const gfx::IntSize& aSize);
 
 /**
  * Helper function to create, potentially, multisample render buffers suitable
  * for offscreen rendering. Buffers of size aSize.width x aSize.height with
  * storage specified by aFormats. GL render buffer object ids are returned via
  * aColorMSRB, aDepthRB, and aStencilRB
  */
 void CreateRenderbuffersForOffscreen(GLContext* aGL, const GLFormats& aFormats,
-                                     const gfxIntSize& aSize, bool aMultisample,
+                                     const gfx::IntSize& aSize, bool aMultisample,
                                      GLuint* aColorMSRB, GLuint* aDepthRB,
                                      GLuint* aStencilRB);
 
 
 /** Buffer blitting helper */
 class GLBlitHelper MOZ_FINAL
 {
     // The GLContext is the sole owner of the GLBlitHelper.
@@ -72,46 +71,46 @@ class GLBlitHelper MOZ_FINAL
     GLuint mTex2DBlit_FragShader;
     GLuint mTex2DRectBlit_FragShader;
     GLuint mTex2DBlit_Program;
     GLuint mTex2DRectBlit_Program;
 
     void UseBlitProgram();
     void SetBlitFramebufferForDestTexture(GLuint aTexture);
 
-    bool UseTexQuadProgram(GLenum target, const nsIntSize& srcSize);
+    bool UseTexQuadProgram(GLenum target, const gfx::IntSize& srcSize);
     bool InitTexQuadProgram(GLenum target = LOCAL_GL_TEXTURE_2D);
     void DeleteTexBlitProgram();
 
 public:
 
     GLBlitHelper(GLContext* gl);
     ~GLBlitHelper();
 
     // If you don't have |srcFormats| for the 2nd definition,
     // then you'll need the framebuffer_blit extensions to use
     // the first BlitFramebufferToFramebuffer.
     void BlitFramebufferToFramebuffer(GLuint srcFB, GLuint destFB,
-                                      const nsIntSize& srcSize,
-                                      const nsIntSize& destSize);
+                                      const gfx::IntSize& srcSize,
+                                      const gfx::IntSize& destSize);
     void BlitFramebufferToFramebuffer(GLuint srcFB, GLuint destFB,
-                                      const nsIntSize& srcSize,
-                                      const nsIntSize& destSize,
+                                      const gfx::IntSize& srcSize,
+                                      const gfx::IntSize& destSize,
                                       const GLFormats& srcFormats);
     void BlitTextureToFramebuffer(GLuint srcTex, GLuint destFB,
-                                  const nsIntSize& srcSize,
-                                  const nsIntSize& destSize,
+                                  const gfx::IntSize& srcSize,
+                                  const gfx::IntSize& destSize,
                                   GLenum srcTarget = LOCAL_GL_TEXTURE_2D);
     void BlitFramebufferToTexture(GLuint srcFB, GLuint destTex,
-                                  const nsIntSize& srcSize,
-                                  const nsIntSize& destSize,
+                                  const gfx::IntSize& srcSize,
+                                  const gfx::IntSize& destSize,
                                   GLenum destTarget = LOCAL_GL_TEXTURE_2D);
     void BlitTextureToTexture(GLuint srcTex, GLuint destTex,
-                              const nsIntSize& srcSize,
-                              const nsIntSize& destSize,
+                              const gfx::IntSize& srcSize,
+                              const gfx::IntSize& destSize,
                               GLenum srcTarget = LOCAL_GL_TEXTURE_2D,
                               GLenum destTarget = LOCAL_GL_TEXTURE_2D);
 };
 
 }
 }
 
 #endif // GLBLITHELPER_H_
--- a/gfx/gl/GLContext.cpp
+++ b/gfx/gl/GLContext.cpp
@@ -1490,17 +1490,17 @@ GLContext::AssembleOffscreenFBs(const GL
 
 
 
 bool
 GLContext::PublishFrame()
 {
     MOZ_ASSERT(mScreen);
 
-    if (!mScreen->PublishFrame(OffscreenSize()))
+    if (!mScreen->PublishFrame(ThebesIntSize(OffscreenSize())))
         return false;
 
     return true;
 }
 
 SharedSurface*
 GLContext::RequestFrame()
 {
@@ -2454,17 +2454,17 @@ void
 GLContext::GuaranteeResolve()
 {
     if (mScreen) {
         mScreen->AssureBlitted();
     }
     fFinish();
 }
 
-const gfxIntSize&
+const gfx::IntSize&
 GLContext::OffscreenSize() const
 {
     MOZ_ASSERT(IsOffscreen());
     return mScreen->Size();
 }
 
 bool
 GLContext::CreateScreenBufferImpl(const gfxIntSize& size, const SurfaceCaps& caps)
--- a/gfx/gl/GLContext.h
+++ b/gfx/gl/GLContext.h
@@ -2497,17 +2497,17 @@ public:
         return ResizeScreenBuffer(ThebesIntSize(size));
     }
 
     /*
      * Return size of this offscreen context.
      *
      * Only valid if IsOffscreen() returns true.
      */
-    const gfxIntSize& OffscreenSize() const;
+    const gfx::IntSize& OffscreenSize() const;
 
     void BindFB(GLuint fb) {
         fBindFramebuffer(LOCAL_GL_FRAMEBUFFER, fb);
         MOZ_ASSERT(!fb || fIsFramebuffer(fb));
     }
 
     void BindDrawFB(GLuint fb) {
         fBindFramebuffer(LOCAL_GL_DRAW_FRAMEBUFFER_EXT, fb);
--- a/gfx/gl/GLScreenBuffer.cpp
+++ b/gfx/gl/GLScreenBuffer.cpp
@@ -334,26 +334,26 @@ GLScreenBuffer::AssureBlitted()
 
     if (mDraw) {
         GLuint drawFB = DrawFB();
         GLuint readFB = ReadFB();
 
         MOZ_ASSERT(drawFB != 0);
         MOZ_ASSERT(drawFB != readFB);
         MOZ_ASSERT(mGL->IsSupported(GLFeature::framebuffer_blit));
-        MOZ_ASSERT(mDraw->Size() == mRead->Size());
+        MOZ_ASSERT(ToIntSize(mDraw->Size()) == mRead->Size());
 
         ScopedBindFramebuffer boundFB(mGL);
         ScopedGLState scissor(mGL, LOCAL_GL_SCISSOR_TEST, false);
 
         BindReadFB_Internal(drawFB);
         BindDrawFB_Internal(readFB);
 
-        const gfxIntSize&  srcSize = mDraw->Size();
-        const gfxIntSize& destSize = mRead->Size();
+        const gfxIntSize&    srcSize = mDraw->Size();
+        const gfx::IntSize& destSize = mRead->Size();
 
         mGL->raw_fBlitFramebuffer(0, 0,  srcSize.width,  srcSize.height,
                                   0, 0, destSize.width, destSize.height,
                                   LOCAL_GL_COLOR_BUFFER_BIT,
                                   LOCAL_GL_NEAREST);
         // Done!
     }
 
@@ -388,17 +388,17 @@ GLScreenBuffer::Attach(SharedSurface* su
     SharedSurface_GL* surf = SharedSurface_GL::Cast(surface);
     if (mRead && SharedSurf())
         SharedSurf()->UnlockProd();
 
     surf->LockProd();
 
     if (mRead &&
         surf->AttachType() == SharedSurf()->AttachType() &&
-        size == Size())
+        ToIntSize(size) == Size())
     {
         // Same size, same type, ready for reuse!
         mRead->Attach(surf);
     } else {
         // Else something changed, so resize:
         DrawBuffer* draw = CreateDraw(size);  // Can be null.
         ReadBuffer* read = CreateRead(surf);
         MOZ_ASSERT(read); // Should never fail if SwapProd succeeded.
@@ -477,17 +477,17 @@ GLScreenBuffer::CreateRead(SharedSurface
     return ReadBuffer::Create(gl, caps, formats, surf);
 }
 
 
 void
 GLScreenBuffer::Readback(SharedSurface_GL* src, gfxImageSurface* dest)
 {
     MOZ_ASSERT(src && dest);
-    MOZ_ASSERT(dest->GetSize() == src->Size());
+    MOZ_ASSERT(ToIntSize(dest->GetSize()) == src->Size());
     MOZ_ASSERT(dest->Format() == (src->HasAlpha() ? gfxImageFormatARGB32
                                                   : gfxImageFormatRGB24));
 
     mGL->MakeCurrent();
 
     bool needsSwap = src != SharedSurf();
     if (needsSwap) {
         SharedSurf()->UnlockProd();
@@ -676,16 +676,16 @@ ReadBuffer::Attach(SharedSurface_GL* sur
         mGL->AttachBuffersToFB(colorTex, colorRB, 0, 0, mFB, target);
         mGL->mFBOMapping[mFB] = surf;
         MOZ_ASSERT(mGL->IsFramebufferComplete(mFB));
     }
 
     mSurf = surf;
 }
 
-const gfxIntSize&
+const gfx::IntSize&
 ReadBuffer::Size() const
 {
     return mSurf->Size();
 }
 
 } /* namespace gl */
 } /* namespace mozilla */
--- a/gfx/gl/GLScreenBuffer.h
+++ b/gfx/gl/GLScreenBuffer.h
@@ -13,17 +13,17 @@
 */
 
 #ifndef SCREEN_BUFFER_H_
 #define SCREEN_BUFFER_H_
 
 #include "SurfaceTypes.h"
 #include "GLContextTypes.h"
 #include "GLDefs.h"
-#include "gfxPoint.h"
+#include "gfx2DGlue.h"
 
 // Forwards:
 class gfxImageSurface;
 
 namespace mozilla {
     namespace gfx {
         class SurfaceStream;
         class SharedSurface;
@@ -119,17 +119,17 @@ protected:
     {}
 
 public:
     virtual ~ReadBuffer();
 
     // Cannot attach a surf of a different AttachType or Size than before.
     void Attach(SharedSurface_GL* surf);
 
-    const gfxIntSize& Size() const;
+    const gfx::IntSize& Size() const;
 
     GLuint FB() const {
         return mFB;
     }
 
     SharedSurface_GL* SharedSurf() const {
         return mSurf;
     }
@@ -226,19 +226,19 @@ public:
     }
 
     GLuint ReadFB() const {
         return mRead->FB();
     }
 
     void DeletingFB(GLuint fb);
 
-    const gfxIntSize& Size() const {
+    const gfx::IntSize& Size() const {
         MOZ_ASSERT(mRead);
-        MOZ_ASSERT(!mDraw || mDraw->Size() == mRead->Size());
+        MOZ_ASSERT(!mDraw || ToIntSize(mDraw->Size()) == mRead->Size());
         return mRead->Size();
     }
 
     void BindAsFramebuffer(GLContext* const gl, GLenum target) const;
 
     void RequireBlit();
     void AssureBlitted();
     void AfterDrawCall();
--- a/gfx/gl/GLUploadHelpers.h
+++ b/gfx/gl/GLUploadHelpers.h
@@ -84,21 +84,21 @@ UploadSurfaceToTexture(GLContext* gl,
 /**
   * Convenience wrapper around UploadImageDataToTexture for gfx::DataSourceSurface's.
   */
 gfx::SurfaceFormat
 UploadSurfaceToTexture(GLContext* gl,
                        gfx::DataSourceSurface *aSurface,
                        const nsIntRegion& aDstRegion,
                        GLuint& aTexture,
-                       bool aOverwrite,
-                       const nsIntPoint& aSrcPoint,
-                       bool aPixelBuffer,
-                       GLenum aTextureUnit,
-                       GLenum aTextureTarget);
+                       bool aOverwrite = false,
+                       const nsIntPoint& aSrcPoint = nsIntPoint(0, 0),
+                       bool aPixelBuffer = false,
+                       GLenum aTextureUnit = LOCAL_GL_TEXTURE0,
+                       GLenum aTextureTarget = LOCAL_GL_TEXTURE_2D);
 
 bool CanUploadSubTextures(GLContext* gl);
 bool CanUploadNonPowerOfTwo(GLContext* gl);
 
 }
 }
 
 #endif
--- a/gfx/gl/SharedSurface.h
+++ b/gfx/gl/SharedSurface.h
@@ -13,38 +13,38 @@
  */
 
 #ifndef SHARED_SURFACE_H_
 #define SHARED_SURFACE_H_
 
 #include <stdint.h>
 #include "mozilla/Attributes.h"
 #include "GLDefs.h"
-#include "gfxPoint.h"
+#include "mozilla/gfx/Point.h"
 #include "SurfaceTypes.h"
 
 namespace mozilla {
 namespace gfx {
 
 class SurfaceFactory;
 
 class SharedSurface
 {
 protected:
     const SharedSurfaceType mType;
     const APITypeT mAPI;
     const AttachmentType mAttachType;
-    const gfxIntSize mSize;
+    const gfx::IntSize mSize;
     const bool mHasAlpha;
     bool mIsLocked;
 
     SharedSurface(SharedSurfaceType type,
                   APITypeT api,
                   AttachmentType attachType,
-                  const gfxIntSize& size,
+                  const gfx::IntSize& size,
                   bool hasAlpha)
         : mType(type)
         , mAPI(api)
         , mAttachType(attachType)
         , mSize(size)
         , mHasAlpha(hasAlpha)
         , mIsLocked(false)
     {
@@ -88,17 +88,17 @@ public:
     APITypeT APIType() const {
         return mAPI;
     }
 
     AttachmentType AttachType() const {
         return mAttachType;
     }
 
-    const gfxIntSize& Size() const {
+    const gfx::IntSize& Size() const {
         return mSize;
     }
 
     bool HasAlpha() const {
         return mHasAlpha;
     }
 
 
--- a/gfx/gl/SharedSurfaceANGLE.cpp
+++ b/gfx/gl/SharedSurfaceANGLE.cpp
@@ -171,33 +171,33 @@ ChooseConfig(GLContext* gl,
     return config;
 }
 
 
 // Returns EGL_NO_SURFACE on error.
 static EGLSurface CreatePBufferSurface(GLLibraryEGL* egl,
                                        EGLDisplay display,
                                        EGLConfig config,
-                                       const gfxIntSize& size)
+                                       const gfx::IntSize& size)
 {
     EGLint attribs[] = {
         LOCAL_EGL_WIDTH, size.width,
         LOCAL_EGL_HEIGHT, size.height,
         LOCAL_EGL_NONE
     };
 
     EGLSurface surface = egl->fCreatePbufferSurface(display, config, attribs);
 
     return surface;
 }
 
 SharedSurface_ANGLEShareHandle*
 SharedSurface_ANGLEShareHandle::Create(GLContext* gl, ID3D10Device1* d3d,
                                        EGLContext context, EGLConfig config,
-                                       const gfxIntSize& size, bool hasAlpha)
+                                       const gfx::IntSize& size, bool hasAlpha)
 {
     GLLibraryEGL* egl = gl->GetLibraryEGL();
     MOZ_ASSERT(egl);
     MOZ_ASSERT(egl->IsExtensionSupported(
                GLLibraryEGL::ANGLE_surface_d3d_texture_2d_share_handle));
 
     if (!context || !config)
         return nullptr;
--- a/gfx/gl/SharedSurfaceANGLE.h
+++ b/gfx/gl/SharedSurfaceANGLE.h
@@ -20,17 +20,17 @@ namespace gl {
 class GLContext;
 
 class SharedSurface_ANGLEShareHandle
     : public SharedSurface_GL
 {
 public:
     static SharedSurface_ANGLEShareHandle* Create(GLContext* gl, ID3D10Device1* d3d,
                                                   EGLContext context, EGLConfig config,
-                                                  const gfxIntSize& size,
+                                                  const gfx::IntSize& size,
                                                   bool hasAlpha);
 
     static SharedSurface_ANGLEShareHandle* Cast(SharedSurface* surf) {
         MOZ_ASSERT(surf->Type() == SharedSurfaceType::EGLSurfaceANGLE);
 
         return (SharedSurface_ANGLEShareHandle*)surf;
     }
 
@@ -38,17 +38,17 @@ protected:
     GLLibraryEGL* const mEGL;
     const EGLContext mContext;
     const EGLSurface mPBuffer;
     nsRefPtr<ID3D10Texture2D> mTexture;
     nsRefPtr<ID3D10ShaderResourceView> mSRV;
 
     SharedSurface_ANGLEShareHandle(GLContext* gl,
                                    GLLibraryEGL* egl,
-                                   const gfxIntSize& size,
+                                   const gfx::IntSize& size,
                                    bool hasAlpha,
                                    EGLContext context,
                                    EGLSurface pbuffer,
                                    ID3D10Texture2D* texture,
                                    ID3D10ShaderResourceView* srv)
         : SharedSurface_GL(SharedSurfaceType::EGLSurfaceANGLE,
                            AttachmentType::Screen,
                            gl,
@@ -96,17 +96,17 @@ public:
                                                    const SurfaceCaps& caps);
 
 protected:
     SurfaceFactory_ANGLEShareHandle(GLContext* gl,
                                     GLLibraryEGL* egl,
                                     ID3D10Device1* d3d,
                                     const SurfaceCaps& caps);
 
-    virtual SharedSurface* CreateShared(const gfxIntSize& size) {
+    virtual SharedSurface* CreateShared(const gfx::IntSize& size) {
         bool hasAlpha = mReadCaps.alpha;
         return SharedSurface_ANGLEShareHandle::Create(mProdGL, mConsD3D,
                                                       mContext, mConfig,
                                                       size, hasAlpha);
     }
 };
 
 } /* namespace gfx */
--- a/gfx/gl/SharedSurfaceEGL.cpp
+++ b/gfx/gl/SharedSurfaceEGL.cpp
@@ -16,17 +16,17 @@
 using namespace mozilla::gfx;
 
 namespace mozilla {
 namespace gl {
 
 SharedSurface_EGLImage*
 SharedSurface_EGLImage::Create(GLContext* prodGL,
                                const GLFormats& formats,
-                               const gfxIntSize& size,
+                               const gfx::IntSize& size,
                                bool hasAlpha,
                                EGLContext context)
 {
     GLLibraryEGL* egl = prodGL->GetLibraryEGL();
     MOZ_ASSERT(egl);
 
     if (!HasExtensions(egl, prodGL))
         return nullptr;
@@ -47,17 +47,17 @@ SharedSurface_EGLImage::HasExtensions(GL
 {
     return egl->HasKHRImageBase() &&
            egl->IsExtensionSupported(GLLibraryEGL::KHR_gl_texture_2D_image) &&
            gl->IsExtensionSupported(GLContext::OES_EGL_image);
 }
 
 SharedSurface_EGLImage::SharedSurface_EGLImage(GLContext* gl,
                                                GLLibraryEGL* egl,
-                                               const gfxIntSize& size,
+                                               const gfx::IntSize& size,
                                                bool hasAlpha,
                                                const GLFormats& formats,
                                                GLuint prodTex)
     : SharedSurface_GL(SharedSurfaceType::EGLImageShare,
                         AttachmentType::GLTexture,
                         gl,
                         size,
                         hasAlpha)
@@ -118,17 +118,17 @@ SharedSurface_EGLImage::LockProdImpl()
     mGL->fDeleteTextures(1, &mProdTex);
     mProdTex = mProdTexForPipe;
     mProdTexForPipe = 0;
     mPipeActive = true;
 }
 
 static bool
 CreateTexturePipe(GLLibraryEGL* const egl, GLContext* const gl,
-                  const GLFormats& formats, const gfxIntSize& size,
+                  const GLFormats& formats, const gfx::IntSize& size,
                   GLuint* const out_tex, EGLImage* const out_image)
 {
     MOZ_ASSERT(out_tex && out_image);
     *out_tex = 0;
     *out_image = 0;
 
     GLuint tex = CreateTextureForOffscreen(gl, formats, size);
     if (!tex)
@@ -168,17 +168,17 @@ SharedSurface_EGLImage::Fence()
                 mPipeFailed = true;
             }
         }
 
         if (!mPixels) {
             gfxImageFormat format =
                   HasAlpha() ? gfxImageFormatARGB32
                              : gfxImageFormatRGB24;
-            mPixels = new gfxImageSurface(Size(), format);
+            mPixels = new gfxImageSurface(ThebesIntSize(Size()), format);
         }
 
         mPixels->Flush();
         mGL->ReadScreenIntoImageSurface(mPixels);
         mPixels->MarkDirty();
         return;
     }
     MOZ_ASSERT(mPipeActive);
--- a/gfx/gl/SharedSurfaceEGL.h
+++ b/gfx/gl/SharedSurfaceEGL.h
@@ -19,20 +19,20 @@ namespace gl {
 class GLContext;
 class TextureGarbageBin;
 
 class SharedSurface_EGLImage
     : public SharedSurface_GL
 {
 public:
     static SharedSurface_EGLImage* Create(GLContext* prodGL,
-                                                  const GLFormats& formats,
-                                                  const gfxIntSize& size,
-                                                  bool hasAlpha,
-                                                  EGLContext context);
+                                          const GLFormats& formats,
+                                          const gfx::IntSize& size,
+                                          bool hasAlpha,
+                                          EGLContext context);
 
     static SharedSurface_EGLImage* Cast(SharedSurface* surf) {
         MOZ_ASSERT(surf->Type() == SharedSurfaceType::EGLImageShare);
 
         return (SharedSurface_EGLImage*)surf;
     }
 
 protected:
@@ -48,17 +48,17 @@ protected:
     nsRefPtr<TextureGarbageBin> mGarbageBin;
     EGLSync mSync;
     bool mPipeFailed;   // Pipe creation failed, and has been abandoned.
     bool mPipeComplete; // Pipe connects (mPipeActive ? mProdTex : mProdTexForPipe) to mConsTex.
     bool mPipeActive;   // Pipe is complete and in use for production.
 
     SharedSurface_EGLImage(GLContext* gl,
                            GLLibraryEGL* egl,
-                           const gfxIntSize& size,
+                           const gfx::IntSize& size,
                            bool hasAlpha,
                            const GLFormats& formats,
                            GLuint prodTex);
 
     EGLDisplay Display() const;
 
     static bool HasExtensions(GLLibraryEGL* egl, GLContext* gl);
 
@@ -101,17 +101,17 @@ protected:
     SurfaceFactory_EGLImage(GLContext* prodGL,
                             EGLContext context,
                             const SurfaceCaps& caps)
         : SurfaceFactory_GL(prodGL, SharedSurfaceType::EGLImageShare, caps)
         , mContext(context)
     {}
 
 public:
-    virtual SharedSurface* CreateShared(const gfxIntSize& size) {
+    virtual SharedSurface* CreateShared(const gfx::IntSize& size) {
         bool hasAlpha = mReadCaps.alpha;
         return SharedSurface_EGLImage::Create(mGL, mFormats, size, hasAlpha, mContext);
     }
 };
 
 } /* namespace gfx */
 } /* namespace mozilla */
 
--- a/gfx/gl/SharedSurfaceGL.cpp
+++ b/gfx/gl/SharedSurfaceGL.cpp
@@ -3,16 +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/. */
 
 #include "SharedSurfaceGL.h"
 #include "GLContext.h"
 #include "GLBlitHelper.h"
 #include "ScopedGLHelpers.h"
 #include "gfxImageSurface.h"
+#include "mozilla/gfx/2D.h"
 
 using namespace mozilla::gfx;
 
 namespace mozilla {
 namespace gl {
 
 // |src| must begin and end locked, though we may
 // temporarily unlock it if we need to.
@@ -238,57 +239,57 @@ SurfaceFactory_GL::ChooseBufferBits(cons
         readCaps = screenCaps;
     }
 }
 
 
 SharedSurface_Basic*
 SharedSurface_Basic::Create(GLContext* gl,
                             const GLFormats& formats,
-                            const gfxIntSize& size,
+                            const IntSize& size,
                             bool hasAlpha)
 {
     gl->MakeCurrent();
     GLuint tex = CreateTexture(gl, formats.color_texInternalFormat,
                                formats.color_texFormat,
                                formats.color_texType,
                                size);
 
-    gfxImageFormat format = gfxImageFormatRGB24;
+    SurfaceFormat format = FORMAT_B8G8R8X8;
     switch (formats.color_texInternalFormat) {
     case LOCAL_GL_RGB:
     case LOCAL_GL_RGB8:
         if (formats.color_texType == LOCAL_GL_UNSIGNED_SHORT_5_6_5)
-            format = gfxImageFormatRGB16_565;
+            format = FORMAT_R5G6B5;
         else
-            format = gfxImageFormatRGB24;
+            format = FORMAT_B8G8R8X8;
         break;
     case LOCAL_GL_RGBA:
     case LOCAL_GL_RGBA8:
-        format = gfxImageFormatARGB32;
+        format = FORMAT_B8G8R8A8;
         break;
     default:
         MOZ_CRASH("Unhandled Tex format.");
     }
     return new SharedSurface_Basic(gl, size, hasAlpha, format, tex);
 }
 
 SharedSurface_Basic::SharedSurface_Basic(GLContext* gl,
-                                         const gfxIntSize& size,
+                                         const IntSize& size,
                                          bool hasAlpha,
-                                         gfxImageFormat format,
+                                         SurfaceFormat format,
                                          GLuint tex)
     : SharedSurface_GL(SharedSurfaceType::Basic,
                        AttachmentType::GLTexture,
                        gl,
                        size,
                        hasAlpha)
     , mTex(tex)
 {
-    mData = new gfxImageSurface(size, format);
+    mData = Factory::CreateDataSourceSurface(size, format);
 }
 
 SharedSurface_Basic::~SharedSurface_Basic()
 {
     if (!mGL->MakeCurrent())
         return;
 
     GLuint tex = mTex;
@@ -296,29 +297,33 @@ SharedSurface_Basic::~SharedSurface_Basi
 }
 
 void
 SharedSurface_Basic::Fence()
 {
     MOZ_ASSERT(mData->GetSize() == mGL->OffscreenSize());
 
     mGL->MakeCurrent();
-    mData->Flush();
-    mGL->ReadScreenIntoImageSurface(mData);
+    nsRefPtr<gfxImageSurface> wrappedData =
+      new gfxImageSurface(mData->GetData(),
+                          ThebesIntSize(mData->GetSize()),
+                          mData->Stride(),
+                          SurfaceFormatToImageFormat(mData->GetFormat()));
+    mGL->ReadScreenIntoImageSurface(wrappedData);
     mData->MarkDirty();
 }
 
 
 
 SharedSurface_GLTexture*
 SharedSurface_GLTexture::Create(GLContext* prodGL,
-                             GLContext* consGL,
-                             const GLFormats& formats,
-                             const gfxIntSize& size,
-                             bool hasAlpha)
+                                GLContext* consGL,
+                                const GLFormats& formats,
+                                const gfx::IntSize& size,
+                                bool hasAlpha)
 {
     MOZ_ASSERT(prodGL);
     MOZ_ASSERT(!consGL || prodGL->SharesWith(consGL));
 
     prodGL->MakeCurrent();
     GLuint tex = CreateTextureForOffscreen(prodGL, formats, size);
 
     return new SharedSurface_GLTexture(prodGL, consGL, size, hasAlpha, tex);
--- a/gfx/gl/SharedSurfaceGL.h
+++ b/gfx/gl/SharedSurfaceGL.h
@@ -17,16 +17,19 @@
 #include <queue>
 
 // Forwards:
 class gfxImageSurface;
 namespace mozilla {
     namespace gl {
         class GLContext;
     }
+    namespace gfx {
+        class DataSourceSurface;
+    }
 }
 
 namespace mozilla {
 namespace gl {
 
 class SurfaceFactory_GL;
 
 class SharedSurface_GL
@@ -38,17 +41,17 @@ protected:
     typedef gfx::APITypeT APITypeT;
     typedef gfx::AttachmentType AttachmentType;
 
     GLContext* const mGL;
 
     SharedSurface_GL(SharedSurfaceType type,
                      AttachmentType attachType,
                      GLContext* gl,
-                     const gfxIntSize& size,
+                     const gfx::IntSize& size,
                      bool hasAlpha)
         : SharedSurface(type, APITypeT::OpenGL, attachType, size, hasAlpha)
         , mGL(gl)
     {}
 
 public:
     static void Copy(SharedSurface_GL* src, SharedSurface_GL* dest,
                      SurfaceFactory_GL* factory);
@@ -116,33 +119,33 @@ public:
 
 // For readback and bootstrapping:
 class SharedSurface_Basic
     : public SharedSurface_GL
 {
 public:
     static SharedSurface_Basic* Create(GLContext* gl,
                                        const GLFormats& formats,
-                                       const gfxIntSize& size,
+                                       const gfx::IntSize& size,
                                        bool hasAlpha);
 
     static SharedSurface_Basic* Cast(SharedSurface* surf) {
         MOZ_ASSERT(surf->Type() == SharedSurfaceType::Basic);
 
         return (SharedSurface_Basic*)surf;
     }
 
 protected:
     const GLuint mTex;
-    nsRefPtr<gfxImageSurface> mData;
+    RefPtr<gfx::DataSourceSurface> mData;
 
     SharedSurface_Basic(GLContext* gl,
-                        const gfxIntSize& size,
+                        const gfx::IntSize& size,
                         bool hasAlpha,
-                        gfxImageFormat format,
+                        gfx::SurfaceFormat format,
                         GLuint tex);
 
 public:
     virtual ~SharedSurface_Basic();
 
     virtual void LockProdImpl() {}
     virtual void UnlockProdImpl() {}
 
@@ -155,62 +158,62 @@ public:
     }
 
 
     virtual GLuint Texture() const {
         return mTex;
     }
 
     // Implementation-specific functions below:
-    gfxImageSurface* GetData() {
+    gfx::DataSourceSurface* GetData() {
         return mData;
     }
 };
 
 class SurfaceFactory_Basic
     : public SurfaceFactory_GL
 {
 public:
     SurfaceFactory_Basic(GLContext* gl, const SurfaceCaps& caps)
         : SurfaceFactory_GL(gl, SharedSurfaceType::Basic, caps)
     {}
 
-    virtual SharedSurface* CreateShared(const gfxIntSize& size) {
+    virtual SharedSurface* CreateShared(const gfx::IntSize& size) {
         bool hasAlpha = mReadCaps.alpha;
         return SharedSurface_Basic::Create(mGL, mFormats, size, hasAlpha);
     }
 };
 
 
 // Using shared GL textures:
 class SharedSurface_GLTexture
     : public SharedSurface_GL
 {
 public:
     static SharedSurface_GLTexture* Create(GLContext* prodGL,
                                            GLContext* consGL,
                                            const GLFormats& formats,
-                                           const gfxIntSize& size,
+                                           const gfx::IntSize& size,
                                            bool hasAlpha);
 
     static SharedSurface_GLTexture* Cast(SharedSurface* surf) {
         MOZ_ASSERT(surf->Type() == SharedSurfaceType::GLTextureShare);
 
         return (SharedSurface_GLTexture*)surf;
     }
 
 protected:
     GLContext* mConsGL;
     const GLuint mTex;
     GLsync mSync;
     mutable Mutex mMutex;
 
     SharedSurface_GLTexture(GLContext* prodGL,
                             GLContext* consGL,
-                            const gfxIntSize& size,
+                            const gfx::IntSize& size,
                             bool hasAlpha,
                             GLuint tex)
         : SharedSurface_GL(SharedSurfaceType::GLTextureShare,
                            AttachmentType::GLTexture,
                            prodGL,
                            size,
                            hasAlpha)
         , mConsGL(consGL)
@@ -253,17 +256,17 @@ public:
                              GLContext* consGL,
                              const SurfaceCaps& caps)
         : SurfaceFactory_GL(prodGL, SharedSurfaceType::GLTextureShare, caps)
         , mConsGL(consGL)
     {
         MOZ_ASSERT(consGL != prodGL);
     }
 
-    virtual SharedSurface* CreateShared(const gfxIntSize& size) {
+    virtual SharedSurface* CreateShared(const gfx::IntSize& size) {
         bool hasAlpha = mReadCaps.alpha;
         return SharedSurface_GLTexture::Create(mGL, mConsGL, mFormats, size, hasAlpha);
     }
 };
 
 } /* namespace gfx */
 } /* namespace mozilla */
 
--- a/gfx/gl/SharedSurfaceGralloc.cpp
+++ b/gfx/gl/SharedSurfaceGralloc.cpp
@@ -12,16 +12,18 @@
 #include "SurfaceFactory.h"
 #include "GLLibraryEGL.h"
 #include "mozilla/layers/ShadowLayers.h"
 
 #include "ui/GraphicBuffer.h"
 #include "../layers/ipc/ShadowLayers.h"
 #include "ScopedGLHelpers.h"
 
+#include "gfx2DGlue.h"
+
 #define DEBUG_GRALLOC
 #ifdef DEBUG_GRALLOC
 #define DEBUG_PRINT(...) do { printf_stderr(__VA_ARGS__); } while (0)
 #else
 #define DEBUG_PRINT(...) do { } while (0)
 #endif
 
 using namespace mozilla;
@@ -45,17 +47,17 @@ SurfaceFactory_Gralloc::SurfaceFactory_G
     MOZ_ASSERT(allocator);
 
     mAllocator = allocator;
 }
 
 SharedSurface_Gralloc*
 SharedSurface_Gralloc::Create(GLContext* prodGL,
                               const GLFormats& formats,
-                              const gfxIntSize& size,
+                              const gfx::IntSize& size,
                               bool hasAlpha,
                               ISurfaceAllocator* allocator)
 {
     static bool runOnce = true;
     if (runOnce) {
         sForceReadPixelsToFence = false;
         mozilla::Preferences::AddBoolVarCache(&sForceReadPixelsToFence,
                                               "gfx.gralloc.fence-with-readpixels");
@@ -70,17 +72,17 @@ SharedSurface_Gralloc::Create(GLContext*
     if (!HasExtensions(egl, prodGL))
         return nullptr;
 
     SurfaceDescriptor baseDesc;
     SurfaceDescriptorGralloc desc;
 
     gfxContentType type = hasAlpha ? GFX_CONTENT_COLOR_ALPHA
                                                 : GFX_CONTENT_COLOR;
-    if (!allocator->AllocSurfaceDescriptorWithCaps(size, type, USING_GL_RENDERING_ONLY, &baseDesc))
+    if (!allocator->AllocSurfaceDescriptorWithCaps(ThebesIntSize(size), type, USING_GL_RENDERING_ONLY, &baseDesc))
         return false;
 
     if (baseDesc.type() != SurfaceDescriptor::TSurfaceDescriptorGralloc) {
         allocator->DestroySharedSurface(&baseDesc);
         return false;
     }
 
     desc = baseDesc.get_SurfaceDescriptorGralloc();
--- a/gfx/gl/SharedSurfaceGralloc.h
+++ b/gfx/gl/SharedSurfaceGralloc.h
@@ -21,17 +21,17 @@ class GLContext;
 class GLLibraryEGL;
 
 class SharedSurface_Gralloc
     : public SharedSurface_GL
 {
 public:
     static SharedSurface_Gralloc* Create(GLContext* prodGL,
                                          const GLFormats& formats,
-                                         const gfxIntSize& size,
+                                         const gfx::IntSize& size,
                                          bool hasAlpha,
                                          layers::ISurfaceAllocator* allocator);
 
     static SharedSurface_Gralloc* Cast(SharedSurface* surf) {
         MOZ_ASSERT(surf->Type() == SharedSurfaceType::Gralloc);
 
         return (SharedSurface_Gralloc*)surf;
     }
@@ -47,17 +47,17 @@ protected:
     // actor) it in the destructor of this class.  This is okay to do
     // on the client, but is very bad to do on the server (because on
     // the client, the actor has no chance of going away unless the
     // whole app died).
     layers::SurfaceDescriptorGralloc mDesc;
     const GLuint mProdTex;
 
     SharedSurface_Gralloc(GLContext* prodGL,
-                          const gfxIntSize& size,
+                          const gfx::IntSize& size,
                           bool hasAlpha,
                           GLLibraryEGL* egl,
                           layers::ISurfaceAllocator* allocator,
                           layers::SurfaceDescriptorGralloc& desc,
                           GLuint prodTex)
         : SharedSurface_GL(SharedSurfaceType::Gralloc,
                            AttachmentType::GLTexture,
                            prodGL,
@@ -95,17 +95,17 @@ class SurfaceFactory_Gralloc
 protected:
     RefPtr<layers::ISurfaceAllocator> mAllocator;
 
 public:
     SurfaceFactory_Gralloc(GLContext* prodGL,
                            const SurfaceCaps& caps,
                            layers::ISurfaceAllocator* allocator = nullptr);
 
-    virtual SharedSurface* CreateShared(const gfxIntSize& size) {
+    virtual SharedSurface* CreateShared(const gfx::IntSize& size) {
         bool hasAlpha = mReadCaps.alpha;
         if (!mAllocator) {
             return nullptr;
         }
         return SharedSurface_Gralloc::Create(mGL, mFormats, size, hasAlpha, mAllocator);
     }
 };
 
--- a/gfx/gl/SharedSurfaceIO.cpp
+++ b/gfx/gl/SharedSurfaceIO.cpp
@@ -16,17 +16,17 @@ namespace gl {
 using namespace gfx;
 
 /* static */ SharedSurface_IOSurface*
 SharedSurface_IOSurface::Create(MacIOSurface* surface, GLContext *gl, bool hasAlpha)
 {
     MOZ_ASSERT(surface);
     MOZ_ASSERT(gl);
 
-    gfxIntSize size(surface->GetWidth(), surface->GetHeight());
+    gfx::IntSize size(surface->GetWidth(), surface->GetHeight());
     return new SharedSurface_IOSurface(surface, gl, size, hasAlpha);
 }
 
 void
 SharedSurface_IOSurface::Fence()
 {
     mGL->MakeCurrent();
     mGL->fFlush();
@@ -52,17 +52,17 @@ SharedSurface_IOSurface::ReadPixels(GLin
     ScopedBindFramebuffer bindFB(mGL, fb.FB());
 
     mGL->fReadPixels(0, 0, width, height, format, type, pixels);
     return true;
 }
 
 SharedSurface_IOSurface::SharedSurface_IOSurface(MacIOSurface* surface,
                                                  GLContext* gl,
-                                                 const gfxIntSize& size,
+                                                 const gfx::IntSize& size,
                                                  bool hasAlpha)
   : SharedSurface_GL(SharedSurfaceType::IOSurface, AttachmentType::GLTexture, gl, size, hasAlpha)
   , mSurface(surface)
 {
     mGL->MakeCurrent();
     mGL->fGenTextures(1, &mTexture);
 
     ScopedBindTexture texture(mGL, mTexture, LOCAL_GL_TEXTURE_RECTANGLE_ARB);
@@ -91,17 +91,17 @@ SharedSurface_IOSurface::~SharedSurface_
     if (mTexture) {
         DebugOnly<bool> success = mGL->MakeCurrent();
         MOZ_ASSERT(success);
         mGL->fDeleteTextures(1, &mTexture);
     }
 }
 
 SharedSurface*
-SurfaceFactory_IOSurface::CreateShared(const gfxIntSize& size)
+SurfaceFactory_IOSurface::CreateShared(const gfx::IntSize& size)
 {
     bool hasAlpha = mReadCaps.alpha;
     RefPtr<MacIOSurface> surf =
         MacIOSurface::CreateIOSurface(size.width, size.height, 1.0, hasAlpha);
 
     if (!surf) {
         NS_WARNING("Failed to create MacIOSurface.");
         return nullptr;
--- a/gfx/gl/SharedSurfaceIO.h
+++ b/gfx/gl/SharedSurfaceIO.h
@@ -43,32 +43,32 @@ public:
     {
         MOZ_ASSERT(surf->Type() == SharedSurfaceType::IOSurface);
         return static_cast<SharedSurface_IOSurface*>(surf);
     }
 
     MacIOSurface* GetIOSurface() { return mSurface; }
 
 private:
-    SharedSurface_IOSurface(MacIOSurface* surface, GLContext* gl, const gfxIntSize& size, bool hasAlpha);
+    SharedSurface_IOSurface(MacIOSurface* surface, GLContext* gl, const gfx::IntSize& size, bool hasAlpha);
 
     RefPtr<MacIOSurface> mSurface;
     nsRefPtr<gfxImageSurface> mImageSurface;
     GLuint mTexture;
 };
 
 class SurfaceFactory_IOSurface : public SurfaceFactory_GL
 {
 public:
     SurfaceFactory_IOSurface(GLContext* gl,
                              const SurfaceCaps& caps)
         : SurfaceFactory_GL(gl, SharedSurfaceType::IOSurface, caps)
     {
     }
 
 protected:
-    virtual SharedSurface* CreateShared(const gfxIntSize& size) MOZ_OVERRIDE;
+    virtual SharedSurface* CreateShared(const gfx::IntSize& size) MOZ_OVERRIDE;
 };
 
 } /* namespace gfx */
 } /* namespace mozilla */
 
 #endif /* SHARED_SURFACEIO_H_ */
--- a/gfx/gl/SurfaceFactory.h
+++ b/gfx/gl/SurfaceFactory.h
@@ -25,17 +25,17 @@ protected:
         : mCaps(caps)
         , mType(type)
     {}
 
 public:
     virtual ~SurfaceFactory();
 
 protected:
-    virtual SharedSurface* CreateShared(const gfxIntSize& size) = 0;
+    virtual SharedSurface* CreateShared(const gfx::IntSize& size) = 0;
 
     std::queue<SharedSurface*> mScraps;
 
 public:
     SharedSurface* NewSharedSurface(const gfxIntSize& size);
 
     // Auto-deletes surfs of the wrong type.
     void Recycle(SharedSurface*& surf);
--- a/gfx/layers/CopyableCanvasLayer.cpp
+++ b/gfx/layers/CopyableCanvasLayer.cpp
@@ -11,16 +11,17 @@
 #include "SharedSurfaceGL.h"            // for SharedSurface_GL, etc
 #include "SurfaceTypes.h"               // for APITypeT, APITypeT::OpenGL, etc
 #include "gfxImageSurface.h"            // for gfxImageSurface
 #include "gfxMatrix.h"                  // for gfxMatrix
 #include "gfxPattern.h"                 // for gfxPattern, etc
 #include "gfxPlatform.h"                // for gfxPlatform, gfxImageFormat
 #include "gfxRect.h"                    // for gfxRect
 #include "gfxUtils.h"                   // for gfxUtils
+#include "gfx2DGlue.h"                  // for ThebesIntSize, etc
 #include "mozilla/gfx/BaseSize.h"       // for BaseSize
 #include "nsDebug.h"                    // for NS_ASSERTION, NS_WARNING, etc
 #include "nsISupportsImpl.h"            // for gfxContext::AddRef, etc
 #include "nsRect.h"                     // for nsIntRect
 #include "nsSize.h"                     // for nsIntSize
 
 using namespace mozilla::gfx;
 using namespace mozilla::gl;
@@ -92,25 +93,26 @@ CopyableCanvasLayer::UpdateSurface(gfxAS
     nsRefPtr<gfxContext> tmpCtx = new gfxContext(aDestSurface);
     tmpCtx->SetOperator(gfxContext::OPERATOR_SOURCE);
     CopyableCanvasLayer::PaintWithOpacity(tmpCtx, 1.0f, aMaskLayer);
     return;
   }
 
   if (mGLContext) {
     nsRefPtr<gfxImageSurface> readSurf;
+    RefPtr<DataSourceSurface> readDSurf;
     nsRefPtr<gfxASurface> resultSurf;
 
     SharedSurface* sharedSurf = mGLContext->RequestFrame();
     if (!sharedSurf) {
       NS_WARNING("Null frame received.");
       return;
     }
 
-    gfxIntSize readSize(sharedSurf->Size());
+    gfxIntSize readSize(ThebesIntSize(sharedSurf->Size()));
     gfxImageFormat format = (GetContentFlags() & CONTENT_OPAQUE)
                             ? gfxImageFormatRGB24
                             : gfxImageFormatARGB32;
 
     if (aDestSurface) {
       resultSurf = aDestSurface;
     } else {
       resultSurf = GetTempSurface(readSize, format);
@@ -120,18 +122,24 @@ CopyableCanvasLayer::UpdateSurface(gfxAS
       MOZ_ASSERT(false, "Bad resultSurf->CairoStatus().");
       return;
     }
 
     MOZ_ASSERT(sharedSurf->APIType() == APITypeT::OpenGL);
     SharedSurface_GL* surfGL = SharedSurface_GL::Cast(sharedSurf);
 
     if (surfGL->Type() == SharedSurfaceType::Basic) {
+      // sharedSurf_Basic->mData must outlive readSurf and readDSurf. Alas,
+      // readSurf and readDSurf may not leave the scope they were declared in.
       SharedSurface_Basic* sharedSurf_Basic = SharedSurface_Basic::Cast(surfGL);
-      readSurf = sharedSurf_Basic->GetData();
+      readDSurf = sharedSurf_Basic->GetData();
+      readSurf = new gfxImageSurface(readDSurf->GetData(),
+                                     ThebesIntSize(readDSurf->GetSize()),
+                                     readDSurf->Stride(),
+                                     SurfaceFormatToImageFormat(readDSurf->GetFormat()));
     } else {
       if (resultSurf->GetSize() != readSize ||
           !(readSurf = resultSurf->GetAsImageSurface()) ||
           readSurf->Format() != format)
       {
         readSurf = GetTempSurface(readSize, format);
       }
 
--- a/gfx/layers/d3d10/CanvasLayerD3D10.cpp
+++ b/gfx/layers/d3d10/CanvasLayerD3D10.cpp
@@ -154,31 +154,27 @@ CanvasLayerD3D10::UpdateSurface()
 
         HRESULT hr = mTexture->Map(0, D3D10_MAP_WRITE_DISCARD, 0, &map);
 
         if (FAILED(hr)) {
           NS_WARNING("Failed to map CanvasLayer texture.");
           return;
         }
 
-        gfxImageSurface* frameData = shareSurf->GetData();
-        // Scope for gfxContext, so it's destroyed before Unmap.
+        gfx::DataSourceSurface* frameData = shareSurf->GetData();
+        // Scope for DrawTarget, so it's destroyed before Unmap.
         {
-          nsRefPtr<gfxImageSurface> mapSurf = 
-              new gfxImageSurface((uint8_t*)map.pData,
-                                  shareSurf->Size(),
-                                  map.RowPitch,
-                                  gfxImageFormatARGB32);
-
-          nsRefPtr<gfxContext> ctx = new gfxContext(mapSurf);
-          ctx->SetOperator(gfxContext::OPERATOR_SOURCE);
-          ctx->SetSource(frameData);
-          ctx->Paint();
-
-          mapSurf->Flush();
+          RefPtr<DrawTarget> dt = Factory::CreateDrawTargetForData(BACKEND_CAIRO,
+                                                                   (uint8_t*)map.pData,
+                                                                   shareSurf->Size(),
+                                                                   map.RowPitch,
+                                                                   FORMAT_B8G8R8A8);
+          Rect drawRect(0, 0, shareSurf->Size().width, shareSurf->Size().height);
+          dt->DrawSurface(frameData, drawRect, drawRect);
+          dt->Flush();
         }
 
         mTexture->Unmap(0);
         mSRView = mUploadSRView;
         break;
       }
 
       default:
--- a/gfx/layers/d3d9/CanvasLayerD3D9.cpp
+++ b/gfx/layers/d3d9/CanvasLayerD3D9.cpp
@@ -96,31 +96,27 @@ CanvasLayerD3D9::UpdateSurface()
     LockTextureRectD3D9 textureLock(mTexture);
     if (!textureLock.HasLock()) {
       NS_WARNING("Failed to lock CanvasLayer texture.");
       return;
     }
 
     D3DLOCKED_RECT rect = textureLock.GetLockRect();
 
-    gfxImageSurface* frameData = shareSurf->GetData();
-    // Scope for gfxContext, so it's destroyed early.
+    gfx::DataSourceSurface* frameData = shareSurf->GetData();
+    // Scope for DrawTarget, so it's destroyed early.
     {
-      nsRefPtr<gfxImageSurface> mapSurf =
-          new gfxImageSurface((uint8_t*)rect.pBits,
-                              shareSurf->Size(),
-                              rect.Pitch,
-                              gfxImageFormatARGB32);
-
-      gfxContext ctx(mapSurf);
-      ctx.SetOperator(gfxContext::OPERATOR_SOURCE);
-      ctx.SetSource(frameData);
-      ctx.Paint();
-
-      mapSurf->Flush();
+      RefPtr<DrawTarget> mapDt = Factory::CreateDrawTargetForData(BACKEND_CAIRO,
+                                                                  (uint8_t*)rect.pBits,
+                                                                  shareSurf->Size(),
+                                                                  rect.Pitch,
+                                                                  FORMAT_B8G8R8A8);
+      Rect drawRect(0, 0, shareSurf->Size().width, shareSurf->Size().height);
+      mapDt->DrawSurface(frameData, drawRect, drawRect);
+      mapDt->Flush();
     }
   } else {
     RECT r;
     r.left = mBounds.x;
     r.top = mBounds.y;
     r.right = mBounds.XMost();
     r.bottom = mBounds.YMost();
 
--- a/gfx/layers/opengl/TextureHostOGL.cpp
+++ b/gfx/layers/opengl/TextureHostOGL.cpp
@@ -478,17 +478,18 @@ StreamTextureSourceOGL::RetrieveTextureF
     // We don't have a valid surf to show yet.
     return false;
   }
 
   gl()->MakeCurrent();
 
   mSize = IntSize(sharedSurf->Size().width, sharedSurf->Size().height);
 
-  gfxImageSurface* toUpload = nullptr;
+  gfxImageSurface* deprecatedToUpload = nullptr;
+  gfx::DataSourceSurface* toUpload = nullptr;
   switch (sharedSurf->Type()) {
     case SharedSurfaceType::GLTextureShare: {
       SharedSurface_GLTexture* glTexSurf = SharedSurface_GLTexture::Cast(sharedSurf);
       glTexSurf->SetConsumerGL(gl());
       mTextureHandle = glTexSurf->Texture();
       mTextureTarget = glTexSurf->TextureTarget();
       MOZ_ASSERT(mTextureHandle);
       mFormat = sharedSurf->HasAlpha() ? FORMAT_R8G8B8A8
@@ -497,18 +498,18 @@ StreamTextureSourceOGL::RetrieveTextureF
     }
     case SharedSurfaceType::EGLImageShare: {
       SharedSurface_EGLImage* eglImageSurf =
           SharedSurface_EGLImage::Cast(sharedSurf);
 
       mTextureHandle = eglImageSurf->AcquireConsumerTexture(gl());
       mTextureTarget = eglImageSurf->TextureTarget();
       if (!mTextureHandle) {
-        toUpload = eglImageSurf->GetPixels();
-        MOZ_ASSERT(toUpload);
+        deprecatedToUpload = eglImageSurf->GetPixels();
+        MOZ_ASSERT(deprecatedToUpload);
       } else {
         mFormat = sharedSurf->HasAlpha() ? FORMAT_R8G8B8A8
                                          : FORMAT_R8G8B8X8;
       }
       break;
     }
 #ifdef XP_MACOSX
     case SharedSurfaceType::IOSurface: {
@@ -525,19 +526,33 @@ StreamTextureSourceOGL::RetrieveTextureF
       toUpload = SharedSurface_Basic::Cast(sharedSurf)->GetData();
       MOZ_ASSERT(toUpload);
       break;
     }
     default:
       MOZ_CRASH("Invalid SharedSurface type.");
   }
 
+  if (deprecatedToUpload) {
+    // FIXME Remove this whole block when deprecatedToUpload gets deleted
+    // mBounds seems to end up as (0,0,0,0) a lot, so don't use it?
+    nsIntSize size(deprecatedToUpload->GetSize());
+    nsIntRect rect(nsIntPoint(0,0), size);
+    nsIntRegion bounds(rect);
+    mFormat = UploadSurfaceToTexture(gl(),
+                                     deprecatedToUpload,
+                                     bounds,
+                                     mUploadTexture,
+                                     true);
+    mTextureHandle = mUploadTexture;
+    mTextureTarget = LOCAL_GL_TEXTURE_2D;
+  }
   if (toUpload) {
     // mBounds seems to end up as (0,0,0,0) a lot, so don't use it?
-    nsIntSize size(toUpload->GetSize());
+    nsIntSize size(ThebesIntSize(toUpload->GetSize()));
     nsIntRect rect(nsIntPoint(0,0), size);
     nsIntRegion bounds(rect);
     mFormat = UploadSurfaceToTexture(gl(),
                                      toUpload,
                                      bounds,
                                      mUploadTexture,
                                      true);
     mTextureHandle = mUploadTexture;
@@ -944,17 +959,18 @@ SurfaceStreamHostOGL::Lock()
     // We don't have a valid surf to show yet.
     return false;
   }
 
   mGL->MakeCurrent();
 
   mSize = IntSize(sharedSurf->Size().width, sharedSurf->Size().height);
 
-  gfxImageSurface* toUpload = nullptr;
+  gfxImageSurface* deprecatedToUpload = nullptr;
+  DataSourceSurface* toUpload = nullptr;
   switch (sharedSurf->Type()) {
     case SharedSurfaceType::GLTextureShare: {
       SharedSurface_GLTexture* glTexSurf = SharedSurface_GLTexture::Cast(sharedSurf);
       glTexSurf->SetConsumerGL(mGL);
       mTextureHandle = glTexSurf->Texture();
       mTextureTarget = glTexSurf->TextureTarget();
       MOZ_ASSERT(mTextureHandle);
       mFormat = sharedSurf->HasAlpha() ? FORMAT_R8G8B8A8
@@ -963,18 +979,18 @@ SurfaceStreamHostOGL::Lock()
     }
     case SharedSurfaceType::EGLImageShare: {
       SharedSurface_EGLImage* eglImageSurf =
           SharedSurface_EGLImage::Cast(sharedSurf);
 
       mTextureHandle = eglImageSurf->AcquireConsumerTexture(mGL);
       mTextureTarget = eglImageSurf->TextureTarget();
       if (!mTextureHandle) {
-        toUpload = eglImageSurf->GetPixels();
-        MOZ_ASSERT(toUpload);
+        deprecatedToUpload = eglImageSurf->GetPixels();
+        MOZ_ASSERT(deprecatedToUpload);
       } else {
         mFormat = sharedSurf->HasAlpha() ? FORMAT_R8G8B8A8
                                          : FORMAT_R8G8B8X8;
       }
       break;
     }
 #ifdef XP_MACOSX
     case SharedSurfaceType::IOSurface: {
@@ -991,19 +1007,33 @@ SurfaceStreamHostOGL::Lock()
       toUpload = SharedSurface_Basic::Cast(sharedSurf)->GetData();
       MOZ_ASSERT(toUpload);
       break;
     }
     default:
       MOZ_CRASH("Invalid SharedSurface type.");
   }
 
+  if (deprecatedToUpload) {
+    // FIXME Remove this whole block when deprecatedToUpload gets deleted
+    // mBounds seems to end up as (0,0,0,0) a lot, so don't use it?
+    nsIntSize size(deprecatedToUpload->GetSize());
+    nsIntRect rect(nsIntPoint(0,0), size);
+    nsIntRegion bounds(rect);
+    mFormat = UploadSurfaceToTexture(mGL,
+                                     deprecatedToUpload,
+                                     bounds,
+                                     mUploadTexture,
+                                     true);
+    mTextureHandle = mUploadTexture;
+    mTextureTarget = LOCAL_GL_TEXTURE_2D;
+  }
   if (toUpload) {
     // mBounds seems to end up as (0,0,0,0) a lot, so don't use it?
-    nsIntSize size(toUpload->GetSize());
+    nsIntSize size(ThebesIntSize(toUpload->GetSize()));
     nsIntRect rect(nsIntPoint(0,0), size);
     nsIntRegion bounds(rect);
     mFormat = UploadSurfaceToTexture(mGL,
                                      toUpload,
                                      bounds,
                                      mUploadTexture,
                                      true);
     mTextureHandle = mUploadTexture;