Backed out 8 changesets (bug 959154) for various oranges.
authorRyan VanderMeulen <ryanvm@gmail.com>
Fri, 14 Feb 2014 13:30:39 -0500
changeset 168811 5749f2fc4f47631ef812d865b14d15996d2bf42c
parent 168810 06e17bc14749554e30139bb00b5f67229620465e
child 168812 4609a7efae4734bb0a579899025781e79b76fbea
push id39804
push userryanvm@gmail.com
push dateFri, 14 Feb 2014 18:38:01 +0000
treeherdermozilla-inbound@4609a7efae47 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs959154
milestone30.0a1
backs out00e465be0552d1e5099db9694729e1893bd45c06
0f9be8d2caaf567398b4054d01b087bf43c45de8
6ca9ba706c9441c582cacdd09d00c237b9b6e79e
c6ec9df2d729c17b1a83daae90c7bfa07e5947ce
53da6aef5629a9494007a91dad572d505414d5ce
88a6337fc8fbcd72423d444a476313be04690ac5
b2535f63d78e8566246fc8e992034f2afeb40c72
fffb200a94bcf686819f877526817218c11fd2ce
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
Backed out 8 changesets (bug 959154) for various oranges. Backed out changeset 00e465be0552 (bug 959154) Backed out changeset 0f9be8d2caaf (bug 959154) Backed out changeset 6ca9ba706c94 (bug 959154) Backed out changeset c6ec9df2d729 (bug 959154) Backed out changeset 53da6aef5629 (bug 959154) Backed out changeset 88a6337fc8fb (bug 959154) Backed out changeset b2535f63d78e (bug 959154) Backed out changeset fffb200a94bc (bug 959154)
gfx/gl/GLTextureImage.cpp
gfx/gl/GLTextureImage.h
gfx/gl/GLUploadHelpers.cpp
gfx/gl/GLUploadHelpers.h
gfx/gl/TextureImageEGL.cpp
gfx/gl/TextureImageEGL.h
gfx/layers/opengl/TextureHostOGL.cpp
--- a/gfx/gl/GLTextureImage.cpp
+++ b/gfx/gl/GLTextureImage.cpp
@@ -85,19 +85,24 @@ bool
 TextureImage::UpdateFromDataSource(gfx::DataSourceSurface *aSurface,
                                    const nsIntRegion* aDestRegion,
                                    const gfx::IntPoint* aSrcPoint)
 {
     nsIntRegion destRegion = aDestRegion ? *aDestRegion
                                          : nsIntRect(0, 0,
                                                      aSurface->GetSize().width,
                                                      aSurface->GetSize().height);
-    gfx::IntPoint srcPoint = aSrcPoint ? *aSrcPoint
-                                       : gfx::IntPoint(0, 0);
-    return DirectUpdate(aSurface, destRegion, srcPoint);
+    nsIntPoint thebesSrcPoint = aSrcPoint ? nsIntPoint(aSrcPoint->x, aSrcPoint->y)
+                                          : nsIntPoint(0, 0);
+    RefPtr<gfxASurface> thebesSurf
+        = new gfxImageSurface(aSurface->GetData(),
+                              ThebesIntSize(aSurface->GetSize()),
+                              aSurface->Stride(),
+                              SurfaceFormatToImageFormat(aSurface->GetFormat()));
+    return DirectUpdate(thebesSurf, destRegion, thebesSrcPoint);
 }
 
 gfx::IntRect TextureImage::GetTileRect() {
     return gfx::IntRect(gfx::IntPoint(0,0), mSize);
 }
 
 gfx::IntRect TextureImage::GetSrcTileRect() {
     return GetTileRect();
@@ -114,134 +119,144 @@ BasicTextureImage::~BasicTextureImage()
     // if we don't have a context (either real or shared),
     // then they went away when the contex was deleted, because it
     // was the only one that had access to it.
     if (ctx && ctx->MakeCurrent()) {
         ctx->fDeleteTextures(1, &mTexture);
     }
 }
 
-gfx::DrawTarget*
+gfxASurface*
 BasicTextureImage::BeginUpdate(nsIntRegion& aRegion)
 {
-    NS_ASSERTION(!mUpdateDrawTarget, "BeginUpdate() without EndUpdate()?");
+    NS_ASSERTION(!mUpdateSurface, "BeginUpdate() without EndUpdate()?");
 
     // determine the region the client will need to repaint
     if (CanUploadSubTextures(mGLContext)) {
         GetUpdateRegion(aRegion);
     } else {
         aRegion = nsIntRect(nsIntPoint(0, 0), gfx::ThebesIntSize(mSize));
     }
 
     mUpdateRegion = aRegion;
 
     nsIntRect rgnSize = mUpdateRegion.GetBounds();
     if (!nsIntRect(nsIntPoint(0, 0), gfx::ThebesIntSize(mSize)).Contains(rgnSize)) {
         NS_ERROR("update outside of image");
         return nullptr;
     }
 
-    gfx::SurfaceFormat format =
+    ImageFormat format =
         (GetContentType() == gfxContentType::COLOR) ?
-        gfx::SurfaceFormat::B8G8R8X8 : gfx::SurfaceFormat::B8G8R8A8;
-    mUpdateDrawTarget =
-        GetDrawTargetForUpdate(gfx::IntSize(rgnSize.width, rgnSize.height), format);
+        gfxImageFormat::RGB24 : gfxImageFormat::ARGB32;
+    mUpdateSurface =
+        GetSurfaceForUpdate(gfxIntSize(rgnSize.width, rgnSize.height), format);
 
-    return mUpdateDrawTarget;
+    if (!mUpdateSurface || mUpdateSurface->CairoStatus()) {
+        mUpdateSurface = nullptr;
+        return nullptr;
+    }
+
+    mUpdateSurface->SetDeviceOffset(gfxPoint(-rgnSize.x, -rgnSize.y));
+
+    return mUpdateSurface;
 }
 
 void
 BasicTextureImage::GetUpdateRegion(nsIntRegion& aForRegion)
 {
   // if the texture hasn't been initialized yet, or something important
   // changed, we need to recreate our backing surface and force the
   // client to paint everything
   if (mTextureState != Valid)
       aForRegion = nsIntRect(nsIntPoint(0, 0), gfx::ThebesIntSize(mSize));
 }
 
 void
 BasicTextureImage::EndUpdate()
 {
-    NS_ASSERTION(!!mUpdateDrawTarget, "EndUpdate() without BeginUpdate()?");
+    NS_ASSERTION(!!mUpdateSurface, "EndUpdate() without BeginUpdate()?");
 
     // FIXME: this is the slow boat.  Make me fast (with GLXPixmap?).
 
-    RefPtr<gfx::SourceSurface> updateSnapshot = mUpdateDrawTarget->Snapshot();
-    RefPtr<gfx::DataSourceSurface> updateData = updateSnapshot->GetDataSurface();
+    // Undo the device offset that BeginUpdate set; doesn't much matter for us here,
+    // but important if we ever do anything directly with the surface.
+    mUpdateSurface->SetDeviceOffset(gfxPoint(0, 0));
 
     bool relative = FinishedSurfaceUpdate();
 
     mTextureFormat =
         UploadSurfaceToTexture(mGLContext,
-                               updateData,
+                               mUpdateSurface,
                                mUpdateRegion,
                                mTexture,
                                mTextureState == Created,
                                mUpdateOffset,
                                relative);
     FinishedSurfaceUpload();
 
-    mUpdateDrawTarget = nullptr;
+    mUpdateSurface = nullptr;
     mTextureState = Valid;
 }
 
 void
 BasicTextureImage::BindTexture(GLenum aTextureUnit)
 {
     mGLContext->fActiveTexture(aTextureUnit);
     mGLContext->fBindTexture(LOCAL_GL_TEXTURE_2D, mTexture);
     mGLContext->fActiveTexture(LOCAL_GL_TEXTURE0);
 }
 
-TemporaryRef<gfx::DrawTarget>
-BasicTextureImage::GetDrawTargetForUpdate(const gfx::IntSize& aSize, gfx::SurfaceFormat aFmt)
+already_AddRefed<gfxASurface>
+BasicTextureImage::GetSurfaceForUpdate(const gfxIntSize& aSize, ImageFormat aFmt)
 {
-    return gfx::Factory::CreateDrawTarget(gfx::BackendType::CAIRO, aSize, aFmt);
+    return gfxPlatform::GetPlatform()->
+        CreateOffscreenSurface(aSize.ToIntSize(),
+                               gfxASurface::ContentFromFormat(aFmt));
 }
 
 bool
 BasicTextureImage::FinishedSurfaceUpdate()
 {
     return false;
 }
 
 void
 BasicTextureImage::FinishedSurfaceUpload()
 {
 }
 
 bool
-BasicTextureImage::DirectUpdate(gfx::DataSourceSurface* aSurf, const nsIntRegion& aRegion, const gfx::IntPoint& aFrom /* = gfx::IntPoint(0, 0) */)
+BasicTextureImage::DirectUpdate(gfxASurface* aSurf, const nsIntRegion& aRegion, const nsIntPoint& aFrom /* = nsIntPoint(0, 0) */)
 {
     nsIntRect bounds = aRegion.GetBounds();
     nsIntRegion region;
     if (mTextureState != Valid) {
         bounds = nsIntRect(0, 0, mSize.width, mSize.height);
         region = nsIntRegion(bounds);
     } else {
         region = aRegion;
     }
 
     mTextureFormat =
         UploadSurfaceToTexture(mGLContext,
                                aSurf,
                                region,
                                mTexture,
                                mTextureState == Created,
-                               bounds.TopLeft() + nsIntPoint(aFrom.x, aFrom.y),
+                               bounds.TopLeft() + aFrom,
                                false);
     mTextureState = Valid;
     return true;
 }
 
 void
 BasicTextureImage::Resize(const gfx::IntSize& aSize)
 {
-    NS_ASSERTION(!mUpdateDrawTarget, "Resize() while in update?");
+    NS_ASSERTION(!mUpdateSurface, "Resize() while in update?");
 
     mGLContext->fBindTexture(LOCAL_GL_TEXTURE_2D, mTexture);
 
     mGLContext->fTexImage2D(LOCAL_GL_TEXTURE_2D,
                             0,
                             LOCAL_GL_RGBA,
                             aSize.width,
                             aSize.height,
@@ -340,17 +355,17 @@ TiledTextureImage::TiledTextureImage(GLC
     }
 }
 
 TiledTextureImage::~TiledTextureImage()
 {
 }
 
 bool
-TiledTextureImage::DirectUpdate(gfx::DataSourceSurface* aSurf, const nsIntRegion& aRegion, const gfx::IntPoint& aFrom /* = gfx::IntPoint(0, 0) */)
+TiledTextureImage::DirectUpdate(gfxASurface* aSurf, const nsIntRegion& aRegion, const nsIntPoint& aFrom /* = nsIntPoint(0, 0) */)
 {
     if (mSize.width == 0 || mSize.height == 0) {
         return true;
     }
 
     nsIntRegion region;
 
     if (mTextureState != Valid) {
@@ -378,17 +393,17 @@ TiledTextureImage::DirectUpdate(gfx::Dat
           tileRegion.MoveBy(-xPos, -yPos); // translate into tile local space
         } else {
           // If sub-textures are unsupported, expand to tile boundaries
           tileRect.x = tileRect.y = 0;
           tileRegion = nsIntRegion(tileRect);
         }
 
         result &= mImages[mCurrentImage]->
-          DirectUpdate(aSurf, tileRegion, aFrom + gfx::IntPoint(xPos, yPos));
+          DirectUpdate(aSurf, tileRegion, aFrom + nsIntPoint(xPos, yPos));
 
         if (mCurrentImage == mImages.Length() - 1) {
             // We know we're done, but we still need to ensure that the callback
             // gets called (e.g. to update the uploaded region).
             NextTile();
             break;
         }
         // Override a callback cancelling iteration if the texture wasn't valid.
@@ -436,17 +451,17 @@ TiledTextureImage::GetUpdateRegion(nsInt
             // Add to the accumulated region
             newRegion.Or(newRegion, subRegion);
         }
     }
 
     aForRegion = newRegion;
 }
 
-gfx::DrawTarget*
+gfxASurface*
 TiledTextureImage::BeginUpdate(nsIntRegion& aRegion)
 {
     NS_ASSERTION(!mInUpdate, "nested update");
     mInUpdate = true;
 
     // Note, we don't call GetUpdateRegion here as if the updated region is
     // fully contained in a single tile, we get to avoid iterating through
     // the tiles again (and a little copying).
@@ -467,86 +482,84 @@ TiledTextureImage::BeginUpdate(nsIntRegi
           nsIntRegion(nsIntRect(nsIntPoint(xPos,yPos),
                                 ThebesIntSize(mImages[i]->GetSize())));
 
         // a single Image can handle this update request
         if (imageRegion.Contains(aRegion)) {
             // adjust for tile offset
             aRegion.MoveBy(-xPos, -yPos);
             // forward the actual call
-            RefPtr<gfx::DrawTarget> drawTarget = mImages[i]->BeginUpdate(aRegion);
+            nsRefPtr<gfxASurface> surface = mImages[i]->BeginUpdate(aRegion);
             // caller expects container space
             aRegion.MoveBy(xPos, yPos);
+            // Correct the device offset
+            gfxPoint offset = surface->GetDeviceOffset();
+            surface->SetDeviceOffset(gfxPoint(offset.x - xPos,
+                                              offset.y - yPos));
             // we don't have a temp surface
-            mUpdateDrawTarget = nullptr;
+            mUpdateSurface = nullptr;
             // remember which image to EndUpdate
             mCurrentImage = i;
-            return drawTarget.get();
+            return surface.get();
         }
     }
 
     // Get the real updated region, taking into account the capabilities of
     // each TextureImage tile
     GetUpdateRegion(aRegion);
     mUpdateRegion = aRegion;
     bounds = aRegion.GetBounds();
 
     // update covers multiple Images - create a temp surface to paint in
-    gfx::SurfaceFormat format =
+    gfxImageFormat format =
         (GetContentType() == gfxContentType::COLOR) ?
-        gfx::SurfaceFormat::B8G8R8X8: gfx::SurfaceFormat::B8G8R8A8;
-    mUpdateDrawTarget = gfx::Factory::CreateDrawTarget(gfx::BackendType::CAIRO,
-                                                       bounds.Size().ToIntSize(),
-                                                       format);
+        gfxImageFormat::RGB24 : gfxImageFormat::ARGB32;
+    mUpdateSurface = gfxPlatform::GetPlatform()->
+        CreateOffscreenSurface(bounds.Size().ToIntSize(),
+                               gfxASurface::ContentFromFormat(format));
+    mUpdateSurface->SetDeviceOffset(gfxPoint(-bounds.x, -bounds.y));
 
-    return mUpdateDrawTarget;;
+    return mUpdateSurface;
 }
 
 void
 TiledTextureImage::EndUpdate()
 {
     NS_ASSERTION(mInUpdate, "EndUpdate not in update");
-    if (!mUpdateDrawTarget) { // update was to a single TextureImage
+    if (!mUpdateSurface) { // update was to a single TextureImage
         mImages[mCurrentImage]->EndUpdate();
         mInUpdate = false;
         mTextureState = Valid;
         mTextureFormat = mImages[mCurrentImage]->GetTextureFormat();
         return;
     }
 
-    RefPtr<gfx::SourceSurface> updateSnapshot = mUpdateDrawTarget->Snapshot();
-    RefPtr<gfx::DataSourceSurface> updateData = updateSnapshot->GetDataSurface();
-    nsRefPtr<gfxASurface> updateSurface = new gfxImageSurface(updateData->GetData(),
-                                                              gfx::ThebesIntSize(updateData->GetSize()),
-                                                              updateData->Stride(),
-                                                              gfx::SurfaceFormatToImageFormat(updateData->GetFormat()));
-
     // upload tiles from temp surface
     for (unsigned i = 0; i < mImages.Length(); i++) {
         int xPos = (i % mColumns) * mTileSize;
         int yPos = (i / mColumns) * mTileSize;
         nsIntRect imageRect = nsIntRect(nsIntPoint(xPos,yPos),
                                         ThebesIntSize(mImages[i]->GetSize()));
 
         nsIntRegion subregion;
         subregion.And(mUpdateRegion, imageRect);
         if (subregion.IsEmpty())
             continue;
         subregion.MoveBy(-xPos, -yPos); // Tile-local space
-        // copy tile from temp target
-        gfx::DrawTarget* drawTarget = mImages[i]->BeginUpdate(subregion);
-        nsRefPtr<gfxContext> ctx = new gfxContext(drawTarget);
+        // copy tile from temp surface
+        gfxASurface* surf = mImages[i]->BeginUpdate(subregion);
+        nsRefPtr<gfxContext> ctx = new gfxContext(surf);
         gfxUtils::ClipToRegion(ctx, subregion);
         ctx->SetOperator(gfxContext::OPERATOR_SOURCE);
-        ctx->SetSource(updateSurface, gfxPoint(-xPos, -yPos));
+        ctx->SetSource(mUpdateSurface, gfxPoint(-xPos, -yPos));
         ctx->Paint();
         mImages[i]->EndUpdate();
     }
 
-    mUpdateDrawTarget = nullptr;
+    mUpdateSurface = nullptr;
     mInUpdate = false;
     mTextureFormat = mImages[0]->GetTextureFormat();
     mTextureState = Valid;
 }
 
 void TiledTextureImage::BeginTileIteration()
 {
     mCurrentImage = 0;
--- a/gfx/gl/GLTextureImage.h
+++ b/gfx/gl/GLTextureImage.h
@@ -8,24 +8,22 @@
 
 #include "nsAutoPtr.h"
 #include "nsRegion.h"
 #include "nsTArray.h"
 #include "gfxTypes.h"
 #include "GLContextTypes.h"
 #include "GraphicsFilter.h"
 #include "mozilla/gfx/Rect.h"
-#include "mozilla/RefPtr.h"
 
 class gfxASurface;
 
 namespace mozilla {
 namespace gfx {
 class DataSourceSurface;
-class DrawTarget;
 }
 }
 
 namespace mozilla {
 namespace gl {
 class GLContext;
 
 /**
@@ -97,17 +95,17 @@ public:
      * in undefined behavior.
      *
      * BeginUpdate() calls cannot be "nested", and each successful
      * BeginUpdate() must be followed by exactly one EndUpdate() (see
      * below).  Failure to do so can leave this in a possibly
      * inconsistent state.  Unsuccessful BeginUpdate()s must not be
      * followed by EndUpdate().
      */
-    virtual gfx::DrawTarget* BeginUpdate(nsIntRegion& aRegion) = 0;
+    virtual gfxASurface* BeginUpdate(nsIntRegion& aRegion) = 0;
     /**
      * Retrieves the region that will require updating, given a
      * region that needs to be updated. This can be used for
      * making decisions about updating before calling BeginUpdate().
      *
      * |aRegion| is an inout param.
      */
     virtual void GetUpdateRegion(nsIntRegion& aForRegion) {
@@ -173,17 +171,18 @@ public:
      */
     virtual void MarkValid() {}
 
     /**
      * aSurf - the source surface to update from
      * aRegion - the region in this image to update
      * aFrom - offset in the source to update from
      */
-    virtual bool DirectUpdate(gfx::DataSourceSurface* aSurf, const nsIntRegion& aRegion, const gfx::IntPoint& aFrom = gfx::IntPoint(0,0)) = 0;
+    virtual bool DirectUpdate(gfxASurface *aSurf, const nsIntRegion& aRegion, const nsIntPoint& aFrom = nsIntPoint(0,0)) = 0;
+    // Moz2D equivalent
     bool UpdateFromDataSource(gfx::DataSourceSurface *aSurf,
                               const nsIntRegion* aDstRegion = nullptr,
                               const gfx::IntPoint* aSrcOffset = nullptr);
 
     virtual void BindTexture(GLenum aTextureUnit) = 0;
 
     /**
      * Returns the image format of the texture. Only valid after a matching
@@ -275,43 +274,44 @@ public:
                       GLenum aWrapMode,
                       ContentType aContentType,
                       GLContext* aContext,
                       TextureImage::Flags aFlags = TextureImage::NoFlags,
                       TextureImage::ImageFormat aImageFormat = gfxImageFormat::Unknown);
 
     virtual void BindTexture(GLenum aTextureUnit);
 
-    virtual gfx::DrawTarget* BeginUpdate(nsIntRegion& aRegion);
+    virtual gfxASurface* BeginUpdate(nsIntRegion& aRegion);
     virtual void GetUpdateRegion(nsIntRegion& aForRegion);
     virtual void EndUpdate();
-    virtual bool DirectUpdate(gfx::DataSourceSurface* aSurf, const nsIntRegion& aRegion, const gfx::IntPoint& aFrom = gfx::IntPoint(0,0));
+    virtual bool DirectUpdate(gfxASurface* aSurf, const nsIntRegion& aRegion, const nsIntPoint& aFrom = nsIntPoint(0,0));
     virtual GLuint GetTextureID() { return mTexture; }
-    virtual TemporaryRef<gfx::DrawTarget>
-      GetDrawTargetForUpdate(const gfx::IntSize& aSize, gfx::SurfaceFormat aFmt);
+    // Returns a surface to draw into
+    virtual already_AddRefed<gfxASurface>
+      GetSurfaceForUpdate(const gfxIntSize& aSize, ImageFormat aFmt);
 
     virtual void MarkValid() { mTextureState = Valid; }
 
     // Call when drawing into the update surface is complete.
     // Returns true if textures should be upload with a relative
     // offset - See UploadSurfaceToTexture.
     virtual bool FinishedSurfaceUpdate();
 
     // Call after surface data has been uploaded to a texture.
     virtual void FinishedSurfaceUpload();
 
-    virtual bool InUpdate() const { return !!mUpdateDrawTarget; }
+    virtual bool InUpdate() const { return !!mUpdateSurface; }
 
     virtual void Resize(const gfx::IntSize& aSize);
 
 protected:
     GLuint mTexture;
     TextureState mTextureState;
     nsRefPtr<GLContext> mGLContext;
-    RefPtr<gfx::DrawTarget> mUpdateDrawTarget;
+    nsRefPtr<gfxASurface> mUpdateSurface;
     nsIntRegion mUpdateRegion;
 
     // The offset into the update surface at which the update rect is located.
     nsIntPoint mUpdateOffset;
 };
 
 /**
  * A container class that complements many sub TextureImages into a big TextureImage.
@@ -324,47 +324,47 @@ class TiledTextureImage
 public:
     TiledTextureImage(GLContext* aGL,
                       gfx::IntSize aSize,
                       TextureImage::ContentType,
                       TextureImage::Flags aFlags = TextureImage::NoFlags,
                       TextureImage::ImageFormat aImageFormat = gfxImageFormat::Unknown);
     ~TiledTextureImage();
     void DumpDiv();
-    virtual gfx::DrawTarget* BeginUpdate(nsIntRegion& aRegion);
+    virtual gfxASurface* BeginUpdate(nsIntRegion& aRegion);
     virtual void GetUpdateRegion(nsIntRegion& aForRegion);
     virtual void EndUpdate();
     virtual void Resize(const gfx::IntSize& aSize);
     virtual uint32_t GetTileCount();
     virtual void BeginTileIteration();
     virtual bool NextTile();
     virtual void SetIterationCallback(TileIterationCallback aCallback,
                                       void* aCallbackData);
     virtual gfx::IntRect GetTileRect();
     virtual GLuint GetTextureID() {
         return mImages[mCurrentImage]->GetTextureID();
     }
-    virtual bool DirectUpdate(gfx::DataSourceSurface* aSurf, const nsIntRegion& aRegion, const gfx::IntPoint& aFrom = gfx::IntPoint(0,0));
+    virtual bool DirectUpdate(gfxASurface* aSurf, const nsIntRegion& aRegion, const nsIntPoint& aFrom = nsIntPoint(0,0));
     virtual bool InUpdate() const { return mInUpdate; }
     virtual void BindTexture(GLenum);
 
 protected:
     virtual gfx::IntRect GetSrcTileRect();
 
     unsigned int mCurrentImage;
     TileIterationCallback mIterationCallback;
     void* mIterationCallbackData;
     nsTArray< nsRefPtr<TextureImage> > mImages;
     bool mInUpdate;
     gfx::IntSize mSize;
     unsigned int mTileSize;
     unsigned int mRows, mColumns;
     GLContext* mGL;
-    // A temporary draw target to faciliate cross-tile updates.
-    RefPtr<gfx::DrawTarget> mUpdateDrawTarget;
+    // A temporary surface to faciliate cross-tile updates.
+    nsRefPtr<gfxASurface> mUpdateSurface;
     // The region of update requested
     nsIntRegion mUpdateRegion;
     TextureState mTextureState;
     TextureImage::ImageFormat mImageFormat;
 };
 
 /**
  * Creates a TextureImage of the basic implementation, can be useful in cases
--- a/gfx/gl/GLUploadHelpers.cpp
+++ b/gfx/gl/GLUploadHelpers.cpp
@@ -2,64 +2,50 @@
 /* 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 "GLUploadHelpers.h"
 
 #include "GLContext.h"
 #include "mozilla/gfx/2D.h"
-#include "mozilla/gfx/Tools.h"  // For BytesPerPixel
+#include "gfxASurface.h"
+#include "gfxUtils.h"
+#include "gfxContext.h"
 #include "nsRegion.h"
 
 namespace mozilla {
 
-using namespace gfx;
+using gfx::SurfaceFormat;
 
 namespace gl {
 
-/* These two techniques are suggested by "Bit Twiddling Hacks"
- */
-
-/**
- * Returns true if |aNumber| is a power of two
- * 0 is incorreclty considered a power of two
- */
-static bool
-IsPowerOfTwo(int aNumber)
+static unsigned int
+DataOffset(const nsIntPoint &aPoint, int32_t aStride, gfxImageFormat aFormat)
 {
-    return (aNumber & (aNumber - 1)) == 0;
+  unsigned int data = aPoint.y * aStride;
+  data += aPoint.x * gfxASurface::BytePerPixelFromFormat(aFormat);
+  return data;
 }
 
-/**
- * Returns the first integer greater than |aNumber| which is a power of two
- * Undefined for |aNumber| < 0
- */
-static int
-NextPowerOfTwo(int aNumber)
+static gfxImageFormat
+ImageFormatForSurfaceFormat(gfx::SurfaceFormat aFormat)
 {
-#if defined(__arm__)
-    return 1 << (32 - __builtin_clz(aNumber - 1));
-#else
-    --aNumber;
-    aNumber |= aNumber >> 1;
-    aNumber |= aNumber >> 2;
-    aNumber |= aNumber >> 4;
-    aNumber |= aNumber >> 8;
-    aNumber |= aNumber >> 16;
-    return ++aNumber;
-#endif
-}
-
-static unsigned int
-DataOffset(const nsIntPoint &aPoint, int32_t aStride, SurfaceFormat aFormat)
-{
-  unsigned int data = aPoint.y * aStride;
-  data += aPoint.x * BytesPerPixel(aFormat);
-  return data;
+    switch (aFormat) {
+        case gfx::SurfaceFormat::B8G8R8A8:
+            return gfxImageFormat::ARGB32;
+        case gfx::SurfaceFormat::B8G8R8X8:
+            return gfxImageFormat::RGB24;
+        case gfx::SurfaceFormat::R5G6B5:
+            return gfxImageFormat::RGB16_565;
+        case gfx::SurfaceFormat::A8:
+            return gfxImageFormat::A8;
+        default:
+            return gfxImageFormat::Unknown;
+    }
 }
 
 static GLint GetAddressAlignment(ptrdiff_t aAddress)
 {
     if (!(aAddress & 0x7)) {
        return 8;
     } else if (!(aAddress & 0x3)) {
         return 4;
@@ -280,23 +266,23 @@ TexImage2DHelper(GLContext *gl,
 {
     if (gl->IsGLES2()) {
 
         NS_ASSERTION(format == (GLenum)internalformat,
                     "format and internalformat not the same for glTexImage2D on GLES2");
 
         if (!CanUploadNonPowerOfTwo(gl)
             && (stride != width * pixelsize
-            || !IsPowerOfTwo(width)
-            || !IsPowerOfTwo(height))) {
+            || !gfx::IsPowerOfTwo(width)
+            || !gfx::IsPowerOfTwo(height))) {
 
             // Pad out texture width and height to the next power of two
             // as we don't support/want non power of two texture uploads
-            GLsizei paddedWidth = NextPowerOfTwo(width);
-            GLsizei paddedHeight = NextPowerOfTwo(height);
+            GLsizei paddedWidth = gfx::NextPowerOfTwo(width);
+            GLsizei paddedHeight = gfx::NextPowerOfTwo(height);
 
             GLvoid* paddedPixels = new unsigned char[paddedWidth * paddedHeight * pixelsize];
 
             // Pad out texture data to be in a POT sized buffer for uploading to
             // a POT sized texture
             CopyAndPadTextureData(pixels, paddedPixels, width, height,
                                   paddedWidth, paddedHeight, stride, pixelsize);
 
@@ -378,17 +364,17 @@ TexImage2DHelper(GLContext *gl,
         gl->fPixelStorei(LOCAL_GL_UNPACK_ALIGNMENT, 4);
     }
 }
 
 SurfaceFormat
 UploadImageDataToTexture(GLContext* gl,
                          unsigned char* aData,
                          int32_t aStride,
-                         SurfaceFormat aFormat,
+                         gfxImageFormat aFormat,
                          const nsIntRegion& aDstRegion,
                          GLuint& aTexture,
                          bool aOverwrite,
                          bool aPixelBuffer,
                          GLenum aTextureUnit,
                          GLenum aTextureTarget)
 {
     bool textureInited = aOverwrite ? false : true;
@@ -420,64 +406,64 @@ UploadImageDataToTexture(GLContext* gl,
         paintRegion = nsIntRegion(aDstRegion.GetBounds());
     } else {
         paintRegion = aDstRegion;
     }
 
     GLenum format;
     GLenum internalFormat;
     GLenum type;
-    int32_t pixelSize = BytesPerPixel(aFormat);
+    int32_t pixelSize = gfxASurface::BytePerPixelFromFormat(aFormat);
     SurfaceFormat surfaceFormat;
 
     MOZ_ASSERT(gl->GetPreferredARGB32Format() == LOCAL_GL_BGRA ||
                gl->GetPreferredARGB32Format() == LOCAL_GL_RGBA);
     switch (aFormat) {
-        case SurfaceFormat::B8G8R8A8:
+        case gfxImageFormat::ARGB32:
             if (gl->GetPreferredARGB32Format() == LOCAL_GL_BGRA) {
               format = LOCAL_GL_BGRA;
-              surfaceFormat = SurfaceFormat::R8G8B8A8;
+              surfaceFormat = gfx::SurfaceFormat::R8G8B8A8;
               type = LOCAL_GL_UNSIGNED_INT_8_8_8_8_REV;
             } else {
               format = LOCAL_GL_RGBA;
-              surfaceFormat = SurfaceFormat::B8G8R8A8;
+              surfaceFormat = gfx::SurfaceFormat::B8G8R8A8;
               type = LOCAL_GL_UNSIGNED_BYTE;
             }
             internalFormat = LOCAL_GL_RGBA;
             break;
-        case SurfaceFormat::B8G8R8X8:
-            // Treat BGRX surfaces as BGRA except for the surface
+        case gfxImageFormat::RGB24:
+            // Treat RGB24 surfaces as RGBA32 except for the surface
             // format used.
             if (gl->GetPreferredARGB32Format() == LOCAL_GL_BGRA) {
               format = LOCAL_GL_BGRA;
-              surfaceFormat = SurfaceFormat::R8G8B8X8;
+              surfaceFormat = gfx::SurfaceFormat::R8G8B8X8;
               type = LOCAL_GL_UNSIGNED_INT_8_8_8_8_REV;
             } else {
               format = LOCAL_GL_RGBA;
-              surfaceFormat = SurfaceFormat::B8G8R8X8;
+              surfaceFormat = gfx::SurfaceFormat::B8G8R8X8;
               type = LOCAL_GL_UNSIGNED_BYTE;
             }
             internalFormat = LOCAL_GL_RGBA;
             break;
-        case SurfaceFormat::R5G6B5:
+        case gfxImageFormat::RGB16_565:
             internalFormat = format = LOCAL_GL_RGB;
             type = LOCAL_GL_UNSIGNED_SHORT_5_6_5;
-            surfaceFormat = SurfaceFormat::R5G6B5;
+            surfaceFormat = gfx::SurfaceFormat::R5G6B5;
             break;
-        case SurfaceFormat::A8:
+        case gfxImageFormat::A8:
             internalFormat = format = LOCAL_GL_LUMINANCE;
             type = LOCAL_GL_UNSIGNED_BYTE;
             // We don't have a specific luminance shader
-            surfaceFormat = SurfaceFormat::A8;
+            surfaceFormat = gfx::SurfaceFormat::A8;
             break;
         default:
             NS_ASSERTION(false, "Unhandled image surface format!");
             format = 0;
             type = 0;
-            surfaceFormat = SurfaceFormat::UNKNOWN;
+            surfaceFormat = gfx::SurfaceFormat::UNKNOWN;
     }
 
     nsIntRegionRectIterator iter(paintRegion);
     const nsIntRect *iterRect;
 
     // Top left point of the region's bounding rectangle.
     nsIntPoint topLeft = paintRegion.GetBounds().TopLeft();
 
@@ -521,28 +507,84 @@ UploadImageDataToTexture(GLContext* gl,
 
     }
 
     return surfaceFormat;
 }
 
 SurfaceFormat
 UploadSurfaceToTexture(GLContext* gl,
-                       DataSourceSurface *aSurface,
+                       gfxASurface *aSurface,
+                       const nsIntRegion& aDstRegion,
+                       GLuint& aTexture,
+                       bool aOverwrite,
+                       const nsIntPoint& aSrcPoint,
+                       bool aPixelBuffer,
+                       GLenum aTextureUnit,
+                       GLenum aTextureTarget)
+{
+
+    nsRefPtr<gfxImageSurface> imageSurface = aSurface->GetAsImageSurface();
+    unsigned char* data = nullptr;
+
+    if (!imageSurface ||
+        (imageSurface->Format() != gfxImageFormat::ARGB32 &&
+         imageSurface->Format() != gfxImageFormat::RGB24 &&
+         imageSurface->Format() != gfxImageFormat::RGB16_565 &&
+         imageSurface->Format() != gfxImageFormat::A8)) {
+        // We can't get suitable pixel data for the surface, make a copy
+        nsIntRect bounds = aDstRegion.GetBounds();
+        imageSurface =
+          new gfxImageSurface(gfxIntSize(bounds.width, bounds.height),
+                              gfxImageFormat::ARGB32);
+
+        nsRefPtr<gfxContext> context = new gfxContext(imageSurface);
+
+        context->Translate(-gfxPoint(aSrcPoint.x, aSrcPoint.y));
+        context->SetSource(aSurface);
+        context->Paint();
+        data = imageSurface->Data();
+        NS_ASSERTION(!aPixelBuffer,
+                     "Must be using an image compatible surface with pixel buffers!");
+    } else {
+        // If a pixel buffer is bound the data pointer parameter is relative
+        // to the start of the data block.
+        if (!aPixelBuffer) {
+              data = imageSurface->Data();
+        }
+        data += DataOffset(aSrcPoint, imageSurface->Stride(),
+                           imageSurface->Format());
+    }
+
+    MOZ_ASSERT(imageSurface);
+    imageSurface->Flush();
+
+    return UploadImageDataToTexture(gl,
+                                    data,
+                                    imageSurface->Stride(),
+                                    imageSurface->Format(),
+                                    aDstRegion, aTexture, aOverwrite,
+                                    aPixelBuffer, aTextureUnit, aTextureTarget);
+}
+
+SurfaceFormat
+UploadSurfaceToTexture(GLContext* gl,
+                       gfx::DataSourceSurface *aSurface,
                        const nsIntRegion& aDstRegion,
                        GLuint& aTexture,
                        bool aOverwrite,
                        const nsIntPoint& aSrcPoint,
                        bool aPixelBuffer,
                        GLenum aTextureUnit,
                        GLenum aTextureTarget)
 {
     unsigned char* data = aPixelBuffer ? nullptr : aSurface->GetData();
     int32_t stride = aSurface->Stride();
-    SurfaceFormat format = aSurface->GetFormat();
+    gfxImageFormat format =
+        ImageFormatForSurfaceFormat(aSurface->GetFormat());
     data += DataOffset(aSrcPoint, stride, format);
     return UploadImageDataToTexture(gl, data, stride, format,
                                     aDstRegion, aTexture, aOverwrite,
                                     aPixelBuffer, aTextureUnit,
                                     aTextureTarget);
 }
 
 bool
@@ -552,9 +594,9 @@ CanUploadNonPowerOfTwo(GLContext* gl)
         return true;
 
     // Some GPUs driver crash when uploading non power of two 565 textures.
     return gl->Renderer() != GLRenderer::Adreno200 &&
            gl->Renderer() != GLRenderer::Adreno205;
 }
 
 }
-}
+}
\ No newline at end of file
--- a/gfx/gl/GLUploadHelpers.h
+++ b/gfx/gl/GLUploadHelpers.h
@@ -2,19 +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 GLUploadHelpers_h_
 #define GLUploadHelpers_h_
 
 #include "GLDefs.h"
+#include "gfxTypes.h"
 #include "mozilla/gfx/Types.h"
 #include "nsPoint.h"
 
+class gfxASurface;
 class nsIntRegion;
 
 namespace mozilla {
 
 namespace gfx {
 class DataSourceSurface;
 }
 
@@ -52,25 +54,39 @@ class GLContext;
   *  the contents of this texture after this call or even on this
   *  texture unit being active.
   * \return Surface format of this texture.
   */
 gfx::SurfaceFormat
 UploadImageDataToTexture(GLContext* gl,
                          unsigned char* aData,
                          int32_t aStride,
-                         gfx::SurfaceFormat aFormat,
+                         gfxImageFormat aFormat,
                          const nsIntRegion& aDstRegion,
                          GLuint& aTexture,
                          bool aOverwrite = false,
                          bool aPixelBuffer = false,
                          GLenum aTextureUnit = LOCAL_GL_TEXTURE0,
                          GLenum aTextureTarget = LOCAL_GL_TEXTURE_2D);
 
 /**
+  * Convenience wrapper around UploadImageDataToTexture for gfxASurfaces.
+  */
+gfx::SurfaceFormat
+UploadSurfaceToTexture(GLContext* gl,
+                       gfxASurface *aSurface,
+                       const nsIntRegion& aDstRegion,
+                       GLuint& aTexture,
+                       bool aOverwrite = false,
+                       const nsIntPoint& aSrcPoint = nsIntPoint(0, 0),
+                       bool aPixelBuffer = false,
+                       GLenum aTextureUnit = LOCAL_GL_TEXTURE0,
+                       GLenum aTextureTarget = LOCAL_GL_TEXTURE_2D);
+
+/**
   * Convenience wrapper around UploadImageDataToTexture for gfx::DataSourceSurface's.
   */
 gfx::SurfaceFormat
 UploadSurfaceToTexture(GLContext* gl,
                        gfx::DataSourceSurface *aSurface,
                        const nsIntRegion& aDstRegion,
                        GLuint& aTexture,
                        bool aOverwrite = false,
--- a/gfx/gl/TextureImageEGL.cpp
+++ b/gfx/gl/TextureImageEGL.cpp
@@ -10,74 +10,77 @@
 #include "gfxPlatform.h"
 #include "gfx2DGlue.h"
 #include "mozilla/gfx/Types.h"
 
 namespace mozilla {
 namespace gl {
 
 static GLenum
-GLFormatForImage(gfx::SurfaceFormat aFormat)
+GLFormatForImage(gfxImageFormat aFormat)
 {
     switch (aFormat) {
-    case gfx::SurfaceFormat::B8G8R8A8:
-    case gfx::SurfaceFormat::B8G8R8X8:
+    case gfxImageFormat::ARGB32:
+    case gfxImageFormat::RGB24:
+        // Thebes only supports RGBX, not packed RGB.
         return LOCAL_GL_RGBA;
-    case gfx::SurfaceFormat::R5G6B5:
+    case gfxImageFormat::RGB16_565:
         return LOCAL_GL_RGB;
-    case gfx::SurfaceFormat::A8:
+    case gfxImageFormat::A8:
         return LOCAL_GL_LUMINANCE;
     default:
-        NS_WARNING("Unknown GL format for Surface format");
+        NS_WARNING("Unknown GL format for Image format");
     }
     return 0;
 }
 
 static GLenum
-GLTypeForImage(gfx::SurfaceFormat aFormat)
+GLTypeForImage(gfxImageFormat aFormat)
 {
     switch (aFormat) {
-    case gfx::SurfaceFormat::B8G8R8A8:
-    case gfx::SurfaceFormat::B8G8R8X8:
-    case gfx::SurfaceFormat::A8:
+    case gfxImageFormat::ARGB32:
+    case gfxImageFormat::RGB24:
+    case gfxImageFormat::A8:
         return LOCAL_GL_UNSIGNED_BYTE;
-    case gfx::SurfaceFormat::R5G6B5:
+    case gfxImageFormat::RGB16_565:
         return LOCAL_GL_UNSIGNED_SHORT_5_6_5;
     default:
-        NS_WARNING("Unknown GL format for Surface format");
+        NS_WARNING("Unknown GL format for Image format");
     }
     return 0;
 }
 
 TextureImageEGL::TextureImageEGL(GLuint aTexture,
                                  const nsIntSize& aSize,
                                  GLenum aWrapMode,
                                  ContentType aContentType,
                                  GLContext* aContext,
                                  Flags aFlags,
                                  TextureState aTextureState,
                                  TextureImage::ImageFormat aImageFormat)
     : TextureImage(aSize, aWrapMode, aContentType, aFlags)
     , mGLContext(aContext)
-    , mUpdateFormat(gfx::ImageFormatToSurfaceFormat(aImageFormat))
+    , mUpdateFormat(aImageFormat)
     , mEGLImage(nullptr)
     , mTexture(aTexture)
     , mSurface(nullptr)
     , mConfig(nullptr)
     , mTextureState(aTextureState)
     , mBound(false)
 {
-    if (mUpdateFormat == gfx::SurfaceFormat::UNKNOWN) {
-        mUpdateFormat = gfx::ImageFormatToSurfaceFormat(
-                gfxPlatform::GetPlatform()->OptimalFormatForContent(GetContentType()));
+    if (mUpdateFormat == gfxImageFormat::Unknown) {
+        mUpdateFormat = gfxPlatform::GetPlatform()->OptimalFormatForContent(GetContentType());
     }
 
-    if (mUpdateFormat == gfx::SurfaceFormat::R5G6B5) {
+    if (mUpdateFormat == gfxImageFormat::RGB16_565) {
         mTextureFormat = gfx::SurfaceFormat::R8G8B8X8;
-    } else if (mUpdateFormat == gfx::SurfaceFormat::B8G8R8X8) {
+    } else if (mUpdateFormat == gfxImageFormat::RGB24) {
+        // RGB24 means really RGBX for Thebes, which means we have to
+        // use the right shader and ignore the uninitialized alpha
+        // value.
         mTextureFormat = gfx::SurfaceFormat::B8G8R8X8;
     } else {
         mTextureFormat = gfx::SurfaceFormat::B8G8R8A8;
     }
 }
 
 TextureImageEGL::~TextureImageEGL()
 {
@@ -106,60 +109,66 @@ TextureImageEGL::GetUpdateRegion(nsIntRe
 
     // We can only draw a rectangle, not subregions due to
     // the way that our texture upload functions work.  If
     // needed, we /could/ do multiple texture uploads if we have
     // non-overlapping rects, but that's a tradeoff.
     aForRegion = nsIntRegion(aForRegion.GetBounds());
 }
 
-gfx::DrawTarget*
+gfxASurface*
 TextureImageEGL::BeginUpdate(nsIntRegion& aRegion)
 {
-    NS_ASSERTION(!mUpdateDrawTarget, "BeginUpdate() without EndUpdate()?");
+    NS_ASSERTION(!mUpdateSurface, "BeginUpdate() without EndUpdate()?");
 
     // determine the region the client will need to repaint
     GetUpdateRegion(aRegion);
     mUpdateRect = aRegion.GetBounds();
 
     //printf_stderr("BeginUpdate with updateRect [%d %d %d %d]\n", mUpdateRect.x, mUpdateRect.y, mUpdateRect.width, mUpdateRect.height);
     if (!nsIntRect(nsIntPoint(0, 0), gfx::ThebesIntSize(mSize)).Contains(mUpdateRect)) {
         NS_ERROR("update outside of image");
         return nullptr;
     }
 
     //printf_stderr("creating image surface %dx%d format %d\n", mUpdateRect.width, mUpdateRect.height, mUpdateFormat);
 
-    mUpdateDrawTarget = gfx::Factory::CreateDrawTarget(gfx::BackendType::CAIRO,
-                                                       gfx::IntSize(mUpdateRect.width, mUpdateRect.height),
-                                                       mUpdateFormat);
+    mUpdateSurface =
+        new gfxImageSurface(gfxIntSize(mUpdateRect.width, mUpdateRect.height),
+                            mUpdateFormat);
 
-    return mUpdateDrawTarget;
+    mUpdateSurface->SetDeviceOffset(gfxPoint(-mUpdateRect.x, -mUpdateRect.y));
+
+    return mUpdateSurface;
 }
 
 void
 TextureImageEGL::EndUpdate()
 {
-    NS_ASSERTION(!!mUpdateDrawTarget, "EndUpdate() without BeginUpdate()?");
+    NS_ASSERTION(!!mUpdateSurface, "EndUpdate() without BeginUpdate()?");
 
     //printf_stderr("EndUpdate: slow path");
 
     // This is the slower path -- we didn't have any way to set up
     // a fast mapping between our cairo target surface and the GL
     // texture, so we have to upload data.
 
-    RefPtr<gfx::SourceSurface> updateSurface = nullptr;
-    RefPtr<gfx::DataSourceSurface> uploadImage = nullptr;
-    gfx::IntSize updateSize(mUpdateRect.width, mUpdateRect.height);
+    // Undo the device offset that BeginUpdate set; doesn't much
+    // matter for us here, but important if we ever do anything
+    // directly with the surface.
+    mUpdateSurface->SetDeviceOffset(gfxPoint(0, 0));
 
-    NS_ASSERTION(mUpdateDrawTarget->GetSize() == updateSize,
-                  "Upload image is the wrong size!");
+    nsRefPtr<gfxImageSurface> uploadImage = nullptr;
+    gfxIntSize updateSize(mUpdateRect.width, mUpdateRect.height);
 
-    updateSurface = mUpdateDrawTarget->Snapshot();
-    uploadImage = updateSurface->GetDataSurface();
+    NS_ASSERTION(mUpdateSurface->GetType() == gfxSurfaceType::Image &&
+                  mUpdateSurface->GetSize() == updateSize,
+                  "Upload image isn't an image surface when one is expected, or is wrong size!");
+
+    uploadImage = static_cast<gfxImageSurface*>(mUpdateSurface.get());
 
     if (!uploadImage) {
         return;
     }
 
     mGLContext->MakeCurrent();
     mGLContext->fBindTexture(LOCAL_GL_TEXTURE_2D, mTexture);
 
@@ -169,38 +178,38 @@ TextureImageEGL::EndUpdate()
                       "Bad initial update on non-created texture!");
 
         mGLContext->fTexImage2D(LOCAL_GL_TEXTURE_2D,
                                 0,
                                 GLFormatForImage(mUpdateFormat),
                                 mUpdateRect.width,
                                 mUpdateRect.height,
                                 0,
-                                GLFormatForImage(uploadImage->GetFormat()),
-                                GLTypeForImage(uploadImage->GetFormat()),
-                                uploadImage->GetData());
+                                GLFormatForImage(uploadImage->Format()),
+                                GLTypeForImage(uploadImage->Format()),
+                                uploadImage->Data());
     } else {
         mGLContext->fTexSubImage2D(LOCAL_GL_TEXTURE_2D,
                                     0,
                                     mUpdateRect.x,
                                     mUpdateRect.y,
                                     mUpdateRect.width,
                                     mUpdateRect.height,
-                                    GLFormatForImage(uploadImage->GetFormat()),
-                                    GLTypeForImage(uploadImage->GetFormat()),
-                                    uploadImage->GetData());
+                                    GLFormatForImage(uploadImage->Format()),
+                                    GLTypeForImage(uploadImage->Format()),
+                                    uploadImage->Data());
     }
 
-    mUpdateDrawTarget = nullptr;
+    mUpdateSurface = nullptr;
     mTextureState = Valid;
     return;         // mTexture is bound
 }
 
 bool
-TextureImageEGL::DirectUpdate(gfx::DataSourceSurface* aSurf, const nsIntRegion& aRegion, const gfx::IntPoint& aFrom /* = gfx::IntPoint(0,0) */)
+TextureImageEGL::DirectUpdate(gfxASurface* aSurf, const nsIntRegion& aRegion, const nsIntPoint& aFrom /* = nsIntPoint(0, 0) */)
 {
     nsIntRect bounds = aRegion.GetBounds();
 
     nsIntRegion region;
     if (mTextureState != Valid) {
         bounds = nsIntRect(0, 0, mSize.width, mSize.height);
         region = nsIntRegion(bounds);
     } else {
@@ -208,17 +217,17 @@ TextureImageEGL::DirectUpdate(gfx::DataS
     }
 
     mTextureFormat =
       UploadSurfaceToTexture(mGLContext,
                              aSurf,
                              region,
                              mTexture,
                              mTextureState == Created,
-                             bounds.TopLeft() + nsIntPoint(aFrom.x, aFrom.y),
+                             bounds.TopLeft() + aFrom,
                              false);
 
     mTextureState = Valid;
     return true;
 }
 
 void
 TextureImageEGL::BindTexture(GLenum aTextureUnit)
@@ -231,17 +240,17 @@ TextureImageEGL::BindTexture(GLenum aTex
     mGLContext->fActiveTexture(aTextureUnit);
     mGLContext->fBindTexture(LOCAL_GL_TEXTURE_2D, mTexture);
     mGLContext->fActiveTexture(LOCAL_GL_TEXTURE0);
 }
 
 void
 TextureImageEGL::Resize(const gfx::IntSize& aSize)
 {
-    NS_ASSERTION(!mUpdateDrawTarget, "Resize() while in update?");
+    NS_ASSERTION(!mUpdateSurface, "Resize() while in update?");
 
     if (mSize == aSize && mTextureState != Created)
         return;
 
     mGLContext->fBindTexture(LOCAL_GL_TEXTURE_2D, mTexture);
 
     mGLContext->fTexImage2D(LOCAL_GL_TEXTURE_2D,
                             0,
--- a/gfx/gl/TextureImageEGL.h
+++ b/gfx/gl/TextureImageEGL.h
@@ -23,34 +23,34 @@ public:
                     Flags aFlags = TextureImage::NoFlags,
                     TextureState aTextureState = Created,
                     TextureImage::ImageFormat aImageFormat = gfxImageFormat::Unknown);
 
     virtual ~TextureImageEGL();
 
     virtual void GetUpdateRegion(nsIntRegion& aForRegion);
 
-    virtual gfx::DrawTarget* BeginUpdate(nsIntRegion& aRegion);
+    virtual gfxASurface* BeginUpdate(nsIntRegion& aRegion);
 
     virtual void EndUpdate();
 
-    virtual bool DirectUpdate(gfx::DataSourceSurface* aSurf, const nsIntRegion& aRegion, const gfx::IntPoint& aFrom = gfx::IntPoint(0,0));
+    virtual bool DirectUpdate(gfxASurface* aSurf, const nsIntRegion& aRegion, const nsIntPoint& aFrom /* = nsIntPoint(0, 0) */);
 
     virtual void BindTexture(GLenum aTextureUnit);
 
     virtual GLuint GetTextureID()
     {
         // Ensure the texture is allocated before it is used.
         if (mTextureState == Created) {
             Resize(mSize);
         }
         return mTexture;
     };
 
-    virtual bool InUpdate() const { return !!mUpdateDrawTarget; }
+    virtual bool InUpdate() const { return !!mUpdateSurface; }
 
     virtual void Resize(const gfx::IntSize& aSize);
 
     bool BindTexImage();
 
     bool ReleaseTexImage();
 
     virtual bool CreateEGLSurface(gfxASurface* aSurface)
@@ -61,18 +61,18 @@ public:
     virtual void DestroyEGLSurface(void);
 
 protected:
     typedef gfxImageFormat ImageFormat;
 
     GLContext* mGLContext;
 
     nsIntRect mUpdateRect;
-    gfx::SurfaceFormat mUpdateFormat;
-    RefPtr<gfx::DrawTarget> mUpdateDrawTarget;
+    ImageFormat mUpdateFormat;
+    nsRefPtr<gfxASurface> mUpdateSurface;
     EGLImage mEGLImage;
     GLuint mTexture;
     EGLSurface mSurface;
     EGLConfig mConfig;
     TextureState mTextureState;
 
     bool mBound;
 };
--- a/gfx/layers/opengl/TextureHostOGL.cpp
+++ b/gfx/layers/opengl/TextureHostOGL.cpp
@@ -735,28 +735,21 @@ TextureImageDeprecatedTextureHostOGL::Up
   // XXX this is always just ridiculously slow
   nsIntRegion updateRegion;
 
   if (!aRegion) {
     updateRegion = nsIntRegion(nsIntRect(0, 0, size.width, size.height));
   } else {
     updateRegion = *aRegion;
   }
-  gfx::IntPoint offset;
+  nsIntPoint offset;
   if (aOffset) {
-    offset.x = aOffset->x;
-    offset.y = aOffset->y;
+    offset = *aOffset;
   }
-  nsRefPtr<gfxImageSurface> thebesSurf = surf.GetAsImage();
-  RefPtr<DataSourceSurface> sourceSurf =
-    gfx::Factory::CreateWrappingDataSourceSurface(thebesSurf->Data(),
-                                                  thebesSurf->Stride(),
-                                                  ToIntSize(thebesSurf->GetSize()),
-                                                  ImageFormatToSurfaceFormat(thebesSurf->Format()));
-  mTexture->DirectUpdate(sourceSurf, updateRegion, offset);
+  mTexture->DirectUpdate(surf.Get(), updateRegion, offset);
   mFormat = mTexture->GetTextureFormat();
 
   if (mTexture->InUpdate()) {
     mTexture->EndUpdate();
   }
 }
 
 bool