Bug 1000640 - Use new StreamTextureClient/Host with OMTC. - r=mattwoodrow
☠☠ backed out by abf745ddb9fc ☠ ☠
authorJeff Gilbert <jgilbert@mozilla.com>
Wed, 04 Jun 2014 15:20:26 -0700
changeset 207017 3a764e34c3667a12d55172407383bf9cea82bf9f
parent 207016 cb1ea8162165ef9efc6aeb755b895f3a56ed3050
child 207018 fa44003a40408cb8ee8be5826dac297a71f54315
push id494
push userraliiev@mozilla.com
push dateMon, 25 Aug 2014 18:42:16 +0000
treeherdermozilla-release@a3cc3e46b571 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmattwoodrow
bugs1000640
milestone32.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1000640 - Use new StreamTextureClient/Host with OMTC. - r=mattwoodrow
content/canvas/src/WebGLContext.cpp
content/canvas/test/reftest/reftest.list
gfx/gl/SharedSurfaceIO.h
gfx/gl/SurfaceTypes.cpp
gfx/layers/CompositorTypes.h
gfx/layers/CopyableCanvasLayer.cpp
gfx/layers/CopyableCanvasLayer.h
gfx/layers/Effects.h
gfx/layers/Layers.h
gfx/layers/basic/BasicCompositor.cpp
gfx/layers/client/CanvasClient.cpp
gfx/layers/client/ClientCanvasLayer.cpp
gfx/layers/client/TextureClient.cpp
gfx/layers/client/TextureClient.h
gfx/layers/composite/ContainerLayerComposite.cpp
gfx/layers/composite/ContentHost.cpp
gfx/layers/composite/FPSCounter.cpp
gfx/layers/composite/ImageHost.cpp
gfx/layers/composite/TextureHost.cpp
gfx/layers/composite/TextureHost.h
gfx/layers/composite/TiledContentHost.cpp
gfx/layers/d3d11/TextureD3D11.cpp
gfx/layers/opengl/GrallocTextureClient.h
gfx/layers/opengl/TextureClientOGL.cpp
gfx/layers/opengl/TextureClientOGL.h
gfx/layers/opengl/TextureHostOGL.cpp
gfx/layers/opengl/TextureHostOGL.h
--- a/content/canvas/src/WebGLContext.cpp
+++ b/content/canvas/src/WebGLContext.cpp
@@ -890,17 +890,17 @@ WebGLContext::GetCanvasLayer(nsDisplayLi
               WebGLContextUserData::PreTransactionCallback, userData);
     }
     canvasLayer->SetUserData(&gWebGLLayerUserData, userData);
 
     CanvasLayer::Data data;
     data.mGLContext = gl;
     data.mSize = nsIntSize(mWidth, mHeight);
     data.mHasAlpha = gl->Caps().alpha;
-    data.mIsGLAlphaPremult = IsPremultAlpha();
+    data.mIsGLAlphaPremult = IsPremultAlpha() || !data.mHasAlpha;
 
     canvasLayer->Initialize(data);
     uint32_t flags = gl->Caps().alpha ? 0 : Layer::CONTENT_OPAQUE;
     canvasLayer->SetContentFlags(flags);
     canvasLayer->Updated();
 
     mResetLayer = false;
 
--- a/content/canvas/test/reftest/reftest.list
+++ b/content/canvas/test/reftest/reftest.list
@@ -144,20 +144,20 @@ random-if(Android&&AndroidVersion<15)  =
 
 fuzzy-if(B2G,256,83) random-if(Android&&AndroidVersion<15)  == webgl-color-alpha-test.html?colorVal=1.0&alphaVal=0.0        wrapper.html?colors.png
 random-if(Android&&AndroidVersion<15)  == webgl-color-alpha-test.html?colorVal=1.0&alphaVal=0.0&alpha  wrapper.html?white.png
 
 fuzzy(1,65536) fuzzy-if(B2G,256,83) fuzzy-if(Android||B2G,9,65536) random-if(Android&&AndroidVersion<15)  == webgl-color-alpha-test.html?colorVal=0.5&alphaVal=1.0  wrapper.html?half-colors.png
 
 # Test premult:
 # random-if(B2G) from bug 983650
-fuzzy(1,65536) random-if(gtk2Widget) random-if(B2G) fuzzy-if(Android,9,65536)                                random-if(Android&&AndroidVersion<15)  == webgl-color-alpha-test.html?colorVal=1.0&alphaVal=0.5&alpha          wrapper.html?colors-half-alpha.png
-fuzzy(1,65536) random-if(gtk2Widget) fails-if(B2G) fuzzy-if(Android,9,65536) fails-if(cocoaWidget||Android) random-if(Android&&AndroidVersion<15)  == webgl-color-alpha-test.html?colorVal=0.5&alphaVal=0.5&alpha          wrapper.html?half-colors-half-alpha.png
+fuzzy(1,65536) random-if(gtk2Widget) random-if(B2G) fuzzy-if(Android,9,65536) random-if(Android&&AndroidVersion<15)  == webgl-color-alpha-test.html?colorVal=1.0&alphaVal=0.5&alpha          wrapper.html?colors-half-alpha.png
+fuzzy(1,65536) random-if(gtk2Widget)                fuzzy-if(Android,9,65536) random-if(Android&&AndroidVersion<15)  == webgl-color-alpha-test.html?colorVal=0.5&alphaVal=0.5&alpha          wrapper.html?half-colors-half-alpha.png
 # random-if(B2G) from bug 983650
-fuzzy(1,65536) random-if(B2G) fuzzy-if(Android,9,65536)                                random-if(Android&&AndroidVersion<15)  == webgl-color-alpha-test.html?colorVal=0.5&alphaVal=0.5&alpha&premult  wrapper.html?colors-half-alpha.png
+fuzzy(1,65536)                       random-if(B2G) fuzzy-if(Android,9,65536) random-if(Android&&AndroidVersion<15)  == webgl-color-alpha-test.html?colorVal=0.5&alphaVal=0.5&alpha&premult  wrapper.html?colors-half-alpha.png
 
 # Check for hanging framebuffer bindings:
                                        random-if(Android&&AndroidVersion<15)  == webgl-hanging-fb-test.html?__&________  wrapper.html?green.png
                                        random-if(Android&&AndroidVersion<15)  == webgl-hanging-fb-test.html?aa&________  wrapper.html?green.png
 pref(webgl.force-layers-readback,true) random-if(Android&&AndroidVersion<15)  == webgl-hanging-fb-test.html?__&readback  wrapper.html?green.png
 pref(webgl.force-layers-readback,true) random-if(Android&&AndroidVersion<15)  == webgl-hanging-fb-test.html?aa&readback  wrapper.html?green.png
 
                                        random-if(Android&&AndroidVersion<15)  == webgl-hanging-scissor-test.html?__&________  wrapper.html?green.png
--- a/gfx/gl/SharedSurfaceIO.h
+++ b/gfx/gl/SharedSurfaceIO.h
@@ -45,16 +45,20 @@ public:
     }
 
     GLuint ConsTexture(GLContext* consGL);
 
     GLenum ConsTextureTarget() const {
         return LOCAL_GL_TEXTURE_RECTANGLE_ARB;
     }
 
+    MacIOSurface* GetIOSurface() const {
+        return mSurface;
+    }
+
 private:
     SharedSurface_IOSurface(MacIOSurface* surface, GLContext* gl, const gfx::IntSize& size, bool hasAlpha);
 
     RefPtr<MacIOSurface> mSurface;
     nsRefPtr<gfxImageSurface> mImageSurface;
     GLuint mProdTex;
     const GLContext* mCurConsGL;
     GLuint mConsTex;
--- a/gfx/gl/SurfaceTypes.cpp
+++ b/gfx/gl/SurfaceTypes.cpp
@@ -44,16 +44,14 @@ SurfaceCaps::Clear()
   bpp16 = false;
   depth = false;
   stencil = false;
   antialias = false;
   preserve = false;
   surfaceAllocator = nullptr;
 }
 
-
-
 SurfaceCaps::~SurfaceCaps()
 {
 }
 
 }
 }
--- a/gfx/layers/CompositorTypes.h
+++ b/gfx/layers/CompositorTypes.h
@@ -82,18 +82,21 @@ MOZ_BEGIN_ENUM_CLASS(TextureFlags, uint3
   IMMEDIATE_UPLOAD   = 1 << 15,
   // The texture is going to be used as part of a double
   // buffered pair, and so we can guarantee that the producer/consumer
   // won't be racing to access its contents.
   DOUBLE_BUFFERED    = 1 << 16,
   // We've previously tried a texture and it didn't work for some reason. If there
   // is a fallback available, try that.
   ALLOC_FALLBACK     = 1 << 17,
+  // Data in this texture has not been alpha-premultiplied.
+  NON_PREMULTIPLIED  = 1 << 18,
+
   // OR union of all valid bits
-  ALL_BITS           = (1 << 18) - 1,
+  ALL_BITS           = (1 << 19) - 1,
   // the default flags
   DEFAULT = FRONT
 MOZ_END_ENUM_CLASS(TextureFlags)
 MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(TextureFlags)
 
 static inline bool
 TextureRequiresLocking(TextureFlags aFlags)
 {
--- a/gfx/layers/CopyableCanvasLayer.cpp
+++ b/gfx/layers/CopyableCanvasLayer.cpp
@@ -28,16 +28,17 @@ namespace mozilla {
 namespace layers {
 
 using namespace mozilla::gfx;
 using namespace mozilla::gl;
 
 CopyableCanvasLayer::CopyableCanvasLayer(LayerManager* aLayerManager, void *aImplData) :
   CanvasLayer(aLayerManager, aImplData)
   , mStream(nullptr)
+  , mIsAlphaPremultiplied(true)
 {
   MOZ_COUNT_CTOR(CopyableCanvasLayer);
 }
 
 CopyableCanvasLayer::~CopyableCanvasLayer()
 {
   MOZ_COUNT_DTOR(CopyableCanvasLayer);
 }
@@ -45,17 +46,17 @@ CopyableCanvasLayer::~CopyableCanvasLaye
 void
 CopyableCanvasLayer::Initialize(const Data& aData)
 {
   NS_ASSERTION(mSurface == nullptr, "BasicCanvasLayer::Initialize called twice!");
 
   if (aData.mGLContext) {
     mGLContext = aData.mGLContext;
     mStream = aData.mStream;
-    mIsGLAlphaPremult = aData.mIsGLAlphaPremult;
+    mIsAlphaPremultiplied = aData.mIsGLAlphaPremult;
     mNeedsYFlip = true;
     MOZ_ASSERT(mGLContext->IsOffscreen(), "canvas gl context isn't offscreen");
 
     // [Basic Layers, non-OMTC] WebGL layer init.
     // `GLScreenBuffer::Morph`ing is only needed in BasicShadowableCanvasLayer.
   } else if (aData.mDrawTarget) {
     mDrawTarget = aData.mDrawTarget;
     mSurface = mDrawTarget->Snapshot();
@@ -108,17 +109,17 @@ CopyableCanvasLayer::UpdateTarget(DrawTa
       NS_WARNING("Null frame received.");
       return;
     }
 
     IntSize readSize(sharedSurf->Size());
     SurfaceFormat format = (GetContentFlags() & CONTENT_OPAQUE)
                             ? SurfaceFormat::B8G8R8X8
                             : SurfaceFormat::B8G8R8A8;
-    bool needsPremult = sharedSurf->HasAlpha() && !mIsGLAlphaPremult;
+    bool needsPremult = sharedSurf->HasAlpha() && !mIsAlphaPremultiplied;
 
     // Try to read back directly into aDestTarget's output buffer
     if (aDestTarget) {
       uint8_t* destData;
       IntSize destSize;
       int32_t destStride;
       SurfaceFormat destFormat;
       if (aDestTarget->LockBits(&destData, &destSize, &destStride, &destFormat)) {
--- a/gfx/layers/CopyableCanvasLayer.h
+++ b/gfx/layers/CopyableCanvasLayer.h
@@ -54,17 +54,17 @@ protected:
   RefPtr<gfx::SourceSurface> mSurface;
   nsRefPtr<mozilla::gl::GLContext> mGLContext;
   mozilla::RefPtr<mozilla::gfx::DrawTarget> mDrawTarget;
 
   RefPtr<gfx::SurfaceStream> mStream;
 
   uint32_t mCanvasFramebuffer;
 
-  bool mIsGLAlphaPremult;
+  bool mIsAlphaPremultiplied;
   bool mNeedsYFlip;
 
   RefPtr<gfx::DataSourceSurface> mCachedTempSurface;
 
   gfx::DataSourceSurface* GetTempSurface(const gfx::IntSize& aSize,
                                          const gfx::SurfaceFormat aFormat);
 
   void DiscardTempSurface();
--- a/gfx/layers/Effects.h
+++ b/gfx/layers/Effects.h
@@ -190,27 +190,28 @@ struct EffectChain
  * Note that aFormat can be different form aSource->GetFormat if, we are
  * creating an effect that takes several texture sources (like with YCBCR
  * where aFormat would be FOMRAT_YCBCR and each texture source would be
  * a one-channel A8 texture)
  */
 inline TemporaryRef<TexturedEffect>
 CreateTexturedEffect(gfx::SurfaceFormat aFormat,
                      TextureSource* aSource,
-                     const gfx::Filter& aFilter)
+                     const gfx::Filter& aFilter,
+                     bool isAlphaPremultiplied)
 {
   MOZ_ASSERT(aSource);
   RefPtr<TexturedEffect> result;
   switch (aFormat) {
   case gfx::SurfaceFormat::B8G8R8A8:
   case gfx::SurfaceFormat::B8G8R8X8:
   case gfx::SurfaceFormat::R8G8B8X8:
   case gfx::SurfaceFormat::R5G6B5:
   case gfx::SurfaceFormat::R8G8B8A8:
-    result = new EffectRGB(aSource, true, aFilter);
+    result = new EffectRGB(aSource, isAlphaPremultiplied, aFilter);
     break;
   case gfx::SurfaceFormat::YUV:
     result = new EffectYCbCr(aSource, aFilter);
     break;
   default:
     NS_WARNING("unhandled program type");
     break;
   }
@@ -222,37 +223,41 @@ CreateTexturedEffect(gfx::SurfaceFormat 
  * Create a textured effect based on aSource format and the presence of
  * aSourceOnWhite.
  *
  * aSourceOnWhite can be null.
  */
 inline TemporaryRef<TexturedEffect>
 CreateTexturedEffect(TextureSource* aSource,
                      TextureSource* aSourceOnWhite,
-                     const gfx::Filter& aFilter)
+                     const gfx::Filter& aFilter,
+                     bool isAlphaPremultiplied)
 {
   MOZ_ASSERT(aSource);
   if (aSourceOnWhite) {
     MOZ_ASSERT(aSource->GetFormat() == gfx::SurfaceFormat::R8G8B8X8 ||
                aSourceOnWhite->GetFormat() == gfx::SurfaceFormat::B8G8R8X8);
     return new EffectComponentAlpha(aSource, aSourceOnWhite, aFilter);
   }
 
-  return CreateTexturedEffect(aSource->GetFormat(), aSource, aFilter);
+  return CreateTexturedEffect(aSource->GetFormat(),
+                              aSource,
+                              aFilter,
+                              isAlphaPremultiplied);
 }
 
 /**
  * Create a textured effect based on aSource format.
  *
  * This version excudes the possibility of component alpha.
  */
 inline TemporaryRef<TexturedEffect>
 CreateTexturedEffect(TextureSource *aTexture,
                      const gfx::Filter& aFilter)
 {
-  return CreateTexturedEffect(aTexture, nullptr, aFilter);
+  return CreateTexturedEffect(aTexture, nullptr, aFilter, true);
 }
 
 
 } // namespace layers
 } // namespace mozilla
 
 #endif
--- a/gfx/layers/Layers.h
+++ b/gfx/layers/Layers.h
@@ -1865,21 +1865,21 @@ public:
   struct Data {
     Data()
       : mDrawTarget(nullptr)
       , mGLContext(nullptr)
       , mStream(nullptr)
       , mTexID(0)
       , mSize(0,0)
       , mHasAlpha(false)
-      , mIsGLAlphaPremult(false)
+      , mIsGLAlphaPremult(true)
     { }
 
     // One of these two must be specified for Canvas2D, but never both
-    mozilla::gfx::DrawTarget *mDrawTarget; // a DrawTarget for the canvas contents
+    mozilla::gfx::DrawTarget* mDrawTarget; // a DrawTarget for the canvas contents
     mozilla::gl::GLContext* mGLContext; // or this, for GL.
 
     // Canvas/SkiaGL uses this
     mozilla::gfx::SurfaceStream* mStream;
 
     // ID of the texture backing the canvas layer (defaults to 0)
     uint32_t mTexID;
 
--- a/gfx/layers/basic/BasicCompositor.cpp
+++ b/gfx/layers/basic/BasicCompositor.cpp
@@ -314,21 +314,35 @@ BasicCompositor::DrawQuad(const gfx::Rec
                        DrawOptions(aOpacity), sourceMask, &maskTransform);
       break;
     }
     case EffectTypes::RGB: {
       TexturedEffect* texturedEffect =
           static_cast<TexturedEffect*>(aEffectChain.mPrimaryEffect.get());
       TextureSourceBasic* source = texturedEffect->mTexture->AsSourceBasic();
 
-      DrawSurfaceWithTextureCoords(dest, aRect,
-                                   source->GetSurface(dest),
-                                   texturedEffect->mTextureCoords,
-                                   texturedEffect->mFilter,
-                                   aOpacity, sourceMask, &maskTransform);
+      if (texturedEffect->mPremultiplied) {
+          DrawSurfaceWithTextureCoords(dest, aRect,
+                                       source->GetSurface(dest),
+                                       texturedEffect->mTextureCoords,
+                                       texturedEffect->mFilter,
+                                       aOpacity, sourceMask, &maskTransform);
+      } else {
+          RefPtr<DataSourceSurface> srcData = source->GetSurface(dest)->GetDataSurface();
+
+          // Yes, we re-create the premultiplied data every time.
+          // This might be better with a cache, eventually.
+          RefPtr<DataSourceSurface> premultData = gfxUtils::CreatePremultipliedDataSurface(srcData);
+
+          DrawSurfaceWithTextureCoords(dest, aRect,
+                                       premultData,
+                                       texturedEffect->mTextureCoords,
+                                       texturedEffect->mFilter,
+                                       aOpacity, sourceMask, &maskTransform);
+      }
       break;
     }
     case EffectTypes::YCBCR: {
       NS_RUNTIMEABORT("Can't (easily) support component alpha with BasicCompositor!");
       break;
     }
     case EffectTypes::RENDER_TARGET: {
       EffectRenderTarget* effectRenderTarget =
--- a/gfx/layers/client/CanvasClient.cpp
+++ b/gfx/layers/client/CanvasClient.cpp
@@ -37,18 +37,17 @@ CanvasClient::CreateCanvasClient(CanvasC
                                  TextureFlags aFlags)
 {
 #ifndef MOZ_WIDGET_GONK
   if (XRE_GetProcessType() != GeckoProcessType_Default) {
     NS_WARNING("Most platforms still need an optimized way to share GL cross process.");
     return new CanvasClient2D(aForwarder, aFlags);
   }
 #endif
-  if (aType == CanvasClientGLContext &&
-      aForwarder->GetCompositorBackendType() == LayersBackend::LAYERS_OPENGL) {
+  if (aType == CanvasClientGLContext) {
     aFlags |= TextureFlags::DEALLOCATE_CLIENT;
     return new CanvasClientSurfaceStream(aForwarder, aFlags);
   }
   return new CanvasClient2D(aForwarder, aFlags);
 }
 
 void
 CanvasClient2D::Update(gfx::IntSize aSize, ClientCanvasLayer* aLayer)
@@ -185,28 +184,29 @@ CanvasClientSurfaceStream::Update(gfx::I
     }
     mBuffer = grallocTextureClient;
 #else
     printf_stderr("isCrossProcess, but not MOZ_WIDGET_GONK! Someone needs to write some code!");
     MOZ_ASSERT(false);
 #endif
   } else {
     if (!mBuffer) {
-      StreamTextureClientOGL* textureClient =
-        new StreamTextureClientOGL(mTextureInfo.mTextureFlags);
+      StreamTextureClient* textureClient =
+        new StreamTextureClient(mTextureInfo.mTextureFlags);
       textureClient->InitWith(stream);
       mBuffer = textureClient;
       bufferCreated = true;
     }
 
     if (bufferCreated && !AddTextureClient(mBuffer)) {
       mBuffer = nullptr;
     }
 
     if (mBuffer) {
+      GetForwarder()->UpdatedTexture(this, mBuffer, nullptr);
       GetForwarder()->UseTexture(this, mBuffer);
     }
   }
 
   aLayer->Painted();
 }
 
 }
--- a/gfx/layers/client/ClientCanvasLayer.cpp
+++ b/gfx/layers/client/ClientCanvasLayer.cpp
@@ -14,23 +14,29 @@
 #include "ClientLayerManager.h"         // for ClientLayerManager, etc
 #include "mozilla/gfx/Point.h"          // for IntSize
 #include "mozilla/layers/CompositorTypes.h"
 #include "mozilla/layers/LayersTypes.h"
 #include "nsCOMPtr.h"                   // for already_AddRefed
 #include "nsISupportsImpl.h"            // for Layer::AddRef, etc
 #include "nsRect.h"                     // for nsIntRect
 #include "nsXULAppAPI.h"                // for XRE_GetProcessType, etc
+#include "gfxPrefs.h"                   // for WebGLForceLayersReadback
+
+#ifdef XP_WIN
+#include "SharedSurfaceANGLE.h"         // for SurfaceFactory_ANGLEShareHandle
+#endif
+
 #ifdef MOZ_WIDGET_GONK
 #include "SharedSurfaceGralloc.h"
 #endif
+
 #ifdef XP_MACOSX
 #include "SharedSurfaceIO.h"
 #endif
-#include "gfxPrefs.h"                   // for WebGLForceLayersReadback
 
 using namespace mozilla::gfx;
 using namespace mozilla::gl;
 
 namespace mozilla {
 namespace layers {
 
 ClientCanvasLayer::~ClientCanvasLayer()
@@ -64,41 +70,55 @@ ClientCanvasLayer::Initialize(const Data
     }
     MOZ_ASSERT(caps.alpha == aData.mHasAlpha);
 
     SurfaceStreamType streamType =
         SurfaceStream::ChooseGLStreamType(SurfaceStream::OffMainThread,
                                           screen->PreserveBuffer());
     SurfaceFactory_GL* factory = nullptr;
     if (!gfxPrefs::WebGLForceLayersReadback()) {
-      if (ClientManager()->AsShadowForwarder()->GetCompositorBackendType() == mozilla::layers::LayersBackend::LAYERS_OPENGL) {
-        if (mGLContext->GetContextType() == GLContextType::EGL) {
-          bool isCrossProcess = !(XRE_GetProcessType() == GeckoProcessType_Default);
+      switch (ClientManager()->AsShadowForwarder()->GetCompositorBackendType()) {
+        case mozilla::layers::LayersBackend::LAYERS_OPENGL: {
+          if (mGLContext->GetContextType() == GLContextType::EGL) {
+            bool isCrossProcess = !(XRE_GetProcessType() == GeckoProcessType_Default);
 
-          if (!isCrossProcess) {
-            // [Basic/OGL Layers, OMTC] WebGL layer init.
-            factory = SurfaceFactory_EGLImage::Create(mGLContext, caps);
+            if (!isCrossProcess) {
+              // [Basic/OGL Layers, OMTC] WebGL layer init.
+              factory = SurfaceFactory_EGLImage::Create(mGLContext, caps);
+            } else {
+              // [Basic/OGL Layers, OOPC] WebGL layer init. (Out Of Process Compositing)
+#ifdef MOZ_WIDGET_GONK
+              factory = new SurfaceFactory_Gralloc(mGLContext, caps, ClientManager()->AsShadowForwarder());
+#else
+              // we could do readback here maybe
+              NS_NOTREACHED("isCrossProcess but not on native B2G!");
+#endif
+            }
           } else {
-            // [Basic/OGL Layers, OOPC] WebGL layer init. (Out Of Process Compositing)
-#ifdef MOZ_WIDGET_GONK
-            factory = new SurfaceFactory_Gralloc(mGLContext, caps, ClientManager()->AsShadowForwarder());
+            // [Basic Layers, OMTC] WebGL layer init.
+            // Well, this *should* work...
+#ifdef XP_MACOSX
+            factory = new SurfaceFactory_IOSurface(mGLContext, caps);
 #else
-            // we could do readback here maybe
-            NS_NOTREACHED("isCrossProcess but not on native B2G!");
+            factory = new SurfaceFactory_GLTexture(mGLContext, nullptr, caps);
 #endif
           }
-        } else {
-          // [Basic Layers, OMTC] WebGL layer init.
-          // Well, this *should* work...
-#ifdef XP_MACOSX
-          factory = new SurfaceFactory_IOSurface(mGLContext, caps);
-#else
-          factory = new SurfaceFactory_GLTexture(mGLContext, nullptr, caps);
+          break;
+        }
+        case mozilla::layers::LayersBackend::LAYERS_D3D10:
+        case mozilla::layers::LayersBackend::LAYERS_D3D11: {
+#ifdef XP_WIN
+          if (mGLContext->IsANGLE()) {
+            factory = SurfaceFactory_ANGLEShareHandle::Create(mGLContext, caps);
+          }
 #endif
+          break;
         }
+        default:
+          break;
       }
     }
 
     if (mStream) {
       // We're using a stream other than the one in the default screen
       mFactory = factory;
       if (!mFactory) {
         // Absolutely must have a factory here, so create a basic one
@@ -146,18 +166,24 @@ ClientCanvasLayer::RenderLayer()
     if (!mGLContext) {
       // We don't support locking for buffer surfaces currently
       flags |= TextureFlags::IMMEDIATE_UPLOAD;
     } else {
       // GLContext's SurfaceStream handles ownership itself,
       // and doesn't require layers to do any deallocation.
       flags |= TextureFlags::DEALLOCATE_CLIENT;
     }
+
+    if (!mIsAlphaPremultiplied) {
+      flags |= TextureFlags::NON_PREMULTIPLIED;
+    }
+
     mCanvasClient = CanvasClient::CreateCanvasClient(GetCanvasClientType(),
-                                                     ClientManager()->AsShadowForwarder(), flags);
+                                                     ClientManager()->AsShadowForwarder(),
+                                                     flags);
     if (!mCanvasClient) {
       return;
     }
     if (HasShadow()) {
       mCanvasClient->Connect();
       ClientManager()->AsShadowForwarder()->Attach(mCanvasClient, this);
     }
   }
--- a/gfx/layers/client/TextureClient.cpp
+++ b/gfx/layers/client/TextureClient.cpp
@@ -21,16 +21,18 @@
 #include "mozilla/layers/SharedPlanarYCbCrImage.h"
 #include "mozilla/layers/YCbCrImageDataSerializer.h"
 #include "nsDebug.h"                    // for NS_ASSERTION, NS_WARNING, etc
 #include "nsISupportsImpl.h"            // for MOZ_COUNT_CTOR, etc
 #include "ImageContainer.h"             // for PlanarYCbCrImage, etc
 #include "mozilla/gfx/2D.h"
 #include "mozilla/layers/TextureClientOGL.h"
 #include "mozilla/layers/PTextureChild.h"
+#include "SurfaceStream.h"
+#include "GLContext.h"
 
 #ifdef XP_WIN
 #include "mozilla/layers/TextureD3D9.h"
 #include "mozilla/layers/TextureD3D11.h"
 #include "gfxWindowsPlatform.h"
 #include "gfx2DGlue.h"
 #endif
 #ifdef MOZ_X11
@@ -394,17 +396,17 @@ void
 TextureClient::Finalize()
 {
   MOZ_ASSERT(!IsLocked());
   // Always make a temporary strong reference to the actor before we use it,
   // in case TextureChild::ActorDestroy might null mActor concurrently.
   RefPtr<TextureChild> actor = mActor;
 
   if (actor) {
-    // The actor has a raw pointer to us, actor->mTextureClient. 
+    // The actor has a raw pointer to us, actor->mTextureClient.
     // Null it before RemoveTexture calls to avoid invalid actor->mTextureClient
     // when calling TextureChild::ActorDestroy()
     actor->mTextureClient = nullptr;
     // this will call ForceRemove in the right thread, using a sync proxy if needed
     if (actor->GetForwarder()) {
       actor->GetForwarder()->RemoveTexture(this);
     }
   }
@@ -671,10 +673,68 @@ BufferTextureClient::AllocateForYCbCr(gf
   YCbCrImageDataSerializer serializer(GetBuffer(), GetBufferSize());
   serializer.InitializeBufferInfo(aYSize,
                                   aCbCrSize,
                                   aStereoMode);
   mSize = aYSize;
   return true;
 }
 
+////////////////////////////////////////////////////////////////////////
+// StreamTextureClient
+StreamTextureClient::StreamTextureClient(TextureFlags aFlags)
+  : TextureClient(aFlags)
+  , mIsLocked(false)
+{
+}
+
+StreamTextureClient::~StreamTextureClient()
+{
+  // the data is owned externally.
+}
+
+bool
+StreamTextureClient::Lock(OpenMode mode)
+{
+  MOZ_ASSERT(!mIsLocked);
+  if (!IsValid() || !IsAllocated()) {
+    return false;
+  }
+  mIsLocked = true;
+  return true;
+}
+
+void
+StreamTextureClient::Unlock()
+{
+  MOZ_ASSERT(mIsLocked);
+  mIsLocked = false;
+}
+
+bool
+StreamTextureClient::ToSurfaceDescriptor(SurfaceDescriptor& aOutDescriptor)
+{
+  if (!IsAllocated()) {
+    return false;
+  }
+
+  gfx::SurfaceStreamHandle handle = mStream->GetShareHandle();
+  aOutDescriptor = SurfaceStreamDescriptor(handle, false);
+  return true;
+}
+
+void
+StreamTextureClient::InitWith(gfx::SurfaceStream* aStream)
+{
+  MOZ_ASSERT(!IsAllocated());
+  mStream = aStream;
+  mGL = mStream->GLContext();
+}
+
+bool
+StreamTextureClient::IsAllocated() const
+{
+  return mStream != 0;
+}
+
+
 }
 }
--- a/gfx/layers/client/TextureClient.h
+++ b/gfx/layers/client/TextureClient.h
@@ -26,16 +26,24 @@
 #include "nsAutoPtr.h"                  // for nsRefPtr
 #include "nsCOMPtr.h"                   // for already_AddRefed
 #include "nsISupportsImpl.h"            // for TextureImage::AddRef, etc
 
 class gfxReusableSurfaceWrapper;
 class gfxImageSurface;
 
 namespace mozilla {
+namespace gfx {
+class SurfaceStream;
+}
+
+namespace gl {
+class GLContext;
+}
+
 namespace layers {
 
 class AsyncTransactionTracker;
 class ContentClient;
 class CompositableForwarder;
 class ISurfaceAllocator;
 class CompositableClient;
 class PlanarYCbCrImage;
@@ -476,16 +484,59 @@ public:
 
   virtual bool HasInternalBuffer() const MOZ_OVERRIDE { return true; }
 
 protected:
   uint8_t* mBuffer;
   size_t mBufSize;
 };
 
+/**
+ * A TextureClient implementation to share SurfaceStream.
+ */
+class StreamTextureClient : public TextureClient
+{
+public:
+  StreamTextureClient(TextureFlags aFlags);
+
+  ~StreamTextureClient();
+
+  virtual bool IsAllocated() const MOZ_OVERRIDE;
+
+  virtual bool Lock(OpenMode mode) MOZ_OVERRIDE;
+
+  virtual void Unlock() MOZ_OVERRIDE;
+
+  virtual bool IsLocked() const MOZ_OVERRIDE { return mIsLocked; }
+
+  virtual bool ToSurfaceDescriptor(SurfaceDescriptor& aOutDescriptor) MOZ_OVERRIDE;
+
+  virtual bool HasInternalBuffer() const MOZ_OVERRIDE { return false; }
+
+  void InitWith(gfx::SurfaceStream* aStream);
+
+  virtual gfx::IntSize GetSize() const { return gfx::IntSize(); }
+
+  virtual gfx::SurfaceFormat GetFormat() const MOZ_OVERRIDE
+  {
+    return gfx::SurfaceFormat::UNKNOWN;
+  }
+
+  virtual bool AllocateForSurface(gfx::IntSize aSize, TextureAllocationFlags aFlags) MOZ_OVERRIDE
+  {
+    MOZ_CRASH("Should never hit this.");
+    return false;
+  }
+
+protected:
+  bool mIsLocked;
+  RefPtr<gfx::SurfaceStream> mStream;
+  RefPtr<gl::GLContext> mGL; // Just for reference holding.
+};
+
 struct TextureClientAutoUnlock
 {
   TextureClient* mTexture;
 
   TextureClientAutoUnlock(TextureClient* aTexture)
   : mTexture(aTexture) {}
 
   ~TextureClientAutoUnlock()
--- a/gfx/layers/composite/ContainerLayerComposite.cpp
+++ b/gfx/layers/composite/ContainerLayerComposite.cpp
@@ -234,17 +234,20 @@ static void DrawVelGraph(const nsIntRect
   }
 
   RefPtr<DataTextureSource> textureSource = compositor->CreateDataTextureSource();
   RefPtr<SourceSurface> snapshot = dt->Snapshot();
   RefPtr<DataSourceSurface> data = snapshot->GetDataSurface();
   textureSource->Update(data);
 
   EffectChain effectChain;
-  effectChain.mPrimaryEffect = CreateTexturedEffect(SurfaceFormat::B8G8R8A8, textureSource, Filter::POINT);
+  effectChain.mPrimaryEffect = CreateTexturedEffect(SurfaceFormat::B8G8R8A8,
+                                                    textureSource,
+                                                    Filter::POINT,
+                                                    true);
 
   compositor->DrawQuad(graphRect,
                        clipRect,
                        effectChain,
                        1.0f,
                        transform);
 }
 
--- a/gfx/layers/composite/ContentHost.cpp
+++ b/gfx/layers/composite/ContentHost.cpp
@@ -74,17 +74,17 @@ ContentHostBase::Composite(EffectChain& 
 
   RefPtr<NewTextureSource> source = GetTextureSource();
   RefPtr<NewTextureSource> sourceOnWhite = GetTextureSourceOnWhite();
 
   if (!source) {
     return;
   }
   RefPtr<TexturedEffect> effect =
-    CreateTexturedEffect(source, sourceOnWhite, aFilter);
+    CreateTexturedEffect(source, sourceOnWhite, aFilter, true);
 
   if (!effect) {
     return;
   }
 
   aEffectChain.mPrimaryEffect = effect;
 
   nsIntRegion tmpRegion;
--- a/gfx/layers/composite/FPSCounter.cpp
+++ b/gfx/layers/composite/FPSCounter.cpp
@@ -430,17 +430,20 @@ void FPSState::DrawFPS(TimeStamp aNow,
    int bytesPerPixel = 4;
     RefPtr<DataSourceSurface> fpsSurface = Factory::CreateWrappingDataSourceSurface(
       reinterpret_cast<uint8_t*>(buf), w * bytesPerPixel, IntSize(w, h), SurfaceFormat::B8G8R8A8);
     mFPSTextureSource = aCompositor->CreateDataTextureSource();
     mFPSTextureSource->Update(fpsSurface);
   }
 
   EffectChain effectChain;
-  effectChain.mPrimaryEffect = CreateTexturedEffect(SurfaceFormat::B8G8R8A8, mFPSTextureSource, Filter::POINT);
+  effectChain.mPrimaryEffect = CreateTexturedEffect(SurfaceFormat::B8G8R8A8,
+                                                    mFPSTextureSource,
+                                                    Filter::POINT,
+                                                    true);
 
   unsigned int fps = unsigned(mCompositionFps.AddFrameAndGetFps(aNow));
   unsigned int txnFps = unsigned(mTransactionFps.GetFPS(aNow));
 
   DrawDigits(fps, aOffsetX + 0, aOffsetY, aCompositor, effectChain);
   DrawDigits(txnFps, aOffsetX + FontWidth * 4, aOffsetY, aCompositor, effectChain);
   DrawDigits(aFillRatio, aOffsetX + FontWidth * 8, aOffsetY, aCompositor, effectChain);
 }
--- a/gfx/layers/composite/ImageHost.cpp
+++ b/gfx/layers/composite/ImageHost.cpp
@@ -85,19 +85,25 @@ ImageHost::Composite(EffectChain& aEffec
   if (autoLock.Failed()) {
     NS_WARNING("failed to lock front buffer");
     return;
   }
   RefPtr<NewTextureSource> source = mFrontBuffer->GetTextureSources();
   if (!source) {
     return;
   }
+
+  bool isAlphaPremultiplied = true;
+  if (mFrontBuffer->GetFlags() & TextureFlags::NON_PREMULTIPLIED)
+    isAlphaPremultiplied = false;
+
   RefPtr<TexturedEffect> effect = CreateTexturedEffect(mFrontBuffer->GetFormat(),
                                                        source,
-                                                       aFilter);
+                                                       aFilter,
+                                                       isAlphaPremultiplied);
   if (!effect) {
     return;
   }
 
   aEffectChain.mPrimaryEffect = effect;
   IntSize textureSize = source->GetSize();
   gfx::Rect gfxPictureRect
     = mHasPictureRect ? gfx::Rect(0, 0, mPictureRect.width, mPictureRect.height)
--- a/gfx/layers/composite/TextureHost.cpp
+++ b/gfx/layers/composite/TextureHost.cpp
@@ -1,35 +1,61 @@
 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
-#include "mozilla/layers/TextureHost.h"
+#include "TextureHost.h"
+
 #include "CompositableHost.h"           // for CompositableHost
 #include "LayersLogging.h"              // for AppendToString
 #include "gfx2DGlue.h"                  // for ToIntSize
 #include "mozilla/gfx/2D.h"             // for DataSourceSurface, Factory
 #include "mozilla/ipc/Shmem.h"          // for Shmem
 #include "mozilla/layers/CompositableTransactionParent.h" // for CompositableParentManager
 #include "mozilla/layers/Compositor.h"  // for Compositor
 #include "mozilla/layers/ISurfaceAllocator.h"  // for ISurfaceAllocator
 #include "mozilla/layers/ImageDataSerializer.h"
 #include "mozilla/layers/LayersSurfaces.h"  // for SurfaceDescriptor, etc
 #include "mozilla/layers/TextureHostOGL.h"  // for TextureHostOGL
-#ifdef MOZ_X11
-#include "mozilla/layers/X11TextureHost.h"
-#endif
 #include "mozilla/layers/YCbCrImageDataSerializer.h"
 #include "nsAString.h"
 #include "nsAutoPtr.h"                  // for nsRefPtr
 #include "nsPrintfCString.h"            // for nsPrintfCString
 #include "mozilla/layers/PTextureParent.h"
 #include "mozilla/unused.h"
 #include <limits>
+#include "SharedSurface.h"
+#include "SharedSurfaceEGL.h"
+#include "SharedSurfaceGL.h"
+#include "SurfaceStream.h"
+#include "../opengl/CompositorOGL.h"
+
+#ifdef MOZ_ENABLE_D3D10_LAYER
+#include "../d3d11/CompositorD3D11.h"
+#endif
+
+#ifdef MOZ_WIDGET_GONK
+#include "../opengl/GrallocTextureClient.h"
+#include "../opengl/GrallocTextureHost.h"
+#include "SharedSurfaceGralloc.h"
+#endif
+
+#ifdef MOZ_X11
+#include "mozilla/layers/X11TextureHost.h"
+#endif
+
+#ifdef XP_MACOSX
+#include "SharedSurfaceIO.h"
+#include "../opengl/MacIOSurfaceTextureHostOGL.h"
+#endif
+
+#ifdef XP_WIN
+#include "SharedSurfaceANGLE.h"
+#endif
 
 #if 0
 #define RECYCLE_LOG(...) printf_stderr(__VA_ARGS__)
 #else
 #define RECYCLE_LOG(...) do { } while (0)
 #endif
 
 struct nsIntPoint;
@@ -171,37 +197,44 @@ TemporaryRef<TextureHost>
 TextureHost::Create(const SurfaceDescriptor& aDesc,
                     ISurfaceAllocator* aDeallocator,
                     TextureFlags aFlags)
 {
   switch (aDesc.type()) {
     case SurfaceDescriptor::TSurfaceDescriptorShmem:
     case SurfaceDescriptor::TSurfaceDescriptorMemory:
       return CreateBackendIndependentTextureHost(aDesc, aDeallocator, aFlags);
+
     case SurfaceDescriptor::TSharedTextureDescriptor:
     case SurfaceDescriptor::TNewSurfaceDescriptorGralloc:
+      return CreateTextureHostOGL(aDesc, aDeallocator, aFlags);
+
     case SurfaceDescriptor::TSurfaceStreamDescriptor:
-      return CreateTextureHostOGL(aDesc, aDeallocator, aFlags);
+      return new StreamTextureHost(aFlags, aDesc.get_SurfaceStreamDescriptor());
+
     case SurfaceDescriptor::TSurfaceDescriptorMacIOSurface:
       if (Compositor::GetBackend() == LayersBackend::LAYERS_OPENGL) {
         return CreateTextureHostOGL(aDesc, aDeallocator, aFlags);
       } else {
         return CreateTextureHostBasic(aDesc, aDeallocator, aFlags);
       }
+
 #ifdef MOZ_X11
     case SurfaceDescriptor::TSurfaceDescriptorX11: {
       const SurfaceDescriptorX11& desc = aDesc.get_SurfaceDescriptorX11();
       RefPtr<TextureHost> result = new X11TextureHost(aFlags, desc);
       return result;
     }
 #endif
+
 #ifdef XP_WIN
     case SurfaceDescriptor::TSurfaceDescriptorD3D9:
     case SurfaceDescriptor::TSurfaceDescriptorDIB:
       return CreateTextureHostD3D9(aDesc, aDeallocator, aFlags);
+
     case SurfaceDescriptor::TSurfaceDescriptorD3D10:
       if (Compositor::GetBackend() == LayersBackend::LAYERS_D3D9) {
         return CreateTextureHostD3D9(aDesc, aDeallocator, aFlags);
       } else {
         return CreateTextureHostD3D11(aDesc, aDeallocator, aFlags);
       }
 #endif
     default:
@@ -769,10 +802,220 @@ TextureParent::ClearTextureHost()
   // Clear recycle callback.
   mTextureHost->ClearRecycleCallback();
   mWaitForClientRecycle = nullptr;
 
   mTextureHost->mActor = nullptr;
   mTextureHost = nullptr;
 }
 
+////////////////////////////////////////////////////////////////////////
+// StreamTextureHost
+
+StreamTextureHost::StreamTextureHost(TextureFlags aFlags,
+                                     const SurfaceStreamDescriptor& aDesc)
+  : TextureHost(aFlags)
+{
+  mStream = gfx::SurfaceStream::FromHandle(aDesc.handle());
+  MOZ_ASSERT(mStream);
+}
+
+StreamTextureHost::~StreamTextureHost()
+{
+  // If need to deallocate textures, call DeallocateSharedData() before
+  // the destructor
+}
+
+bool
+StreamTextureHost::Lock()
+{
+  if (!mCompositor) {
+    return false;
+  }
+
+  gfx::SharedSurface* abstractSurf = mStream->SwapConsumer();
+
+  bool compositorSupportsShSurfType = false;
+  switch (mCompositor->GetBackendType()) {
+    case LayersBackend::LAYERS_BASIC:
+    case LayersBackend::LAYERS_D3D9:
+    case LayersBackend::LAYERS_D3D10:
+      switch (abstractSurf->Type()) {
+        case gfx::SharedSurfaceType::Basic:
+          compositorSupportsShSurfType = true;
+          break;
+        default:
+          break;
+      }
+      break;
+    case LayersBackend::LAYERS_OPENGL:
+      switch (abstractSurf->Type()) {
+        case gfx::SharedSurfaceType::Basic:
+        case gfx::SharedSurfaceType::GLTextureShare:
+        case gfx::SharedSurfaceType::EGLImageShare:
+        case gfx::SharedSurfaceType::Gralloc:
+        case gfx::SharedSurfaceType::IOSurface:
+          compositorSupportsShSurfType = true;
+          break;
+        default:
+          break;
+      }
+      break;
+    case LayersBackend::LAYERS_D3D11:
+      switch (abstractSurf->Type()) {
+        case gfx::SharedSurfaceType::Basic:
+        case gfx::SharedSurfaceType::EGLSurfaceANGLE:
+          compositorSupportsShSurfType = true;
+          break;
+        default:
+          break;
+      }
+      break;
+    default:
+      break;
+  }
+
+  RefPtr<NewTextureSource> newTexSource;
+  if (compositorSupportsShSurfType) {
+    gfx::SurfaceFormat format = abstractSurf->HasAlpha() ? gfx::SurfaceFormat::R8G8B8A8
+                                                         : gfx::SurfaceFormat::R8G8B8X8;
+
+    switch (abstractSurf->Type()) {
+      case gfx::SharedSurfaceType::Basic: {
+        gl::SharedSurface_Basic* surf = gl::SharedSurface_Basic::Cast(abstractSurf);
+
+        if (!this->mDataTextureSource) {
+          TextureFlags flags = TextureFlags::DEALLOCATE_CLIENT;
+          this->mDataTextureSource = mCompositor->CreateDataTextureSource(flags);
+        }
+        this->mDataTextureSource->Update(surf->GetData());
+
+        newTexSource = mDataTextureSource;
+        break;
+      }
+      case gfx::SharedSurfaceType::GLTextureShare: {
+        gl::SharedSurface_GLTexture* surf = gl::SharedSurface_GLTexture::Cast(abstractSurf);
+
+        MOZ_ASSERT(mCompositor->GetBackendType() == LayersBackend::LAYERS_OPENGL);
+        CompositorOGL* compositorOGL = static_cast<CompositorOGL*>(mCompositor);
+        gl::GLContext* gl = compositorOGL->gl();
+
+        GLenum target = surf->ConsTextureTarget();
+        GLuint tex = surf->ConsTexture(gl);
+        newTexSource = new GLTextureSource(compositorOGL,
+                                           tex,
+                                           format,
+                                           target,
+                                           surf->Size());
+        break;
+      }
+#ifdef MOZ_ENABLE_D3D10_LAYER
+      case gfx::SharedSurfaceType::EGLSurfaceANGLE: {
+        gl::SharedSurface_ANGLEShareHandle* surf = gl::SharedSurface_ANGLEShareHandle::Cast(abstractSurf);
+        HANDLE shareHandle = surf->GetShareHandle();
+
+        MOZ_ASSERT(mCompositor->GetBackendType() == LayersBackend::LAYERS_D3D11);
+        CompositorD3D11* compositorD3D11 = static_cast<CompositorD3D11*>(mCompositor);
+        ID3D11Device* d3d = compositorD3D11->GetDevice();
+
+        nsRefPtr<ID3D11Texture2D> tex;
+        HRESULT hr = d3d->OpenSharedResource(shareHandle,
+                                             __uuidof(ID3D11Texture2D),
+                                             getter_AddRefs(tex));
+        if (FAILED(hr)) {
+          NS_WARNING("Failed to open shared resource.");
+          break;
+        }
+        newTexSource = new DataTextureSourceD3D11(format, compositorD3D11, tex);
+        break;
+      }
+#endif
+      case gfx::SharedSurfaceType::EGLImageShare: {
+        gl::SharedSurface_EGLImage* surf = gl::SharedSurface_EGLImage::Cast(abstractSurf);
+
+        MOZ_ASSERT(mCompositor->GetBackendType() == LayersBackend::LAYERS_OPENGL);
+        CompositorOGL* compositorOGL = static_cast<CompositorOGL*>(mCompositor);
+        gl::GLContext* gl = compositorOGL->gl();
+        MOZ_ASSERT(gl->IsCurrent());
+
+        GLenum target = 0;
+        GLuint tex = 0;
+        surf->AcquireConsumerTexture(gl, &tex, &target);
+
+        newTexSource = new GLTextureSource(compositorOGL,
+                                           tex,
+                                           format,
+                                           target,
+                                           surf->Size());
+        break;
+      }
+#ifdef MOZ_WIDGET_GONK
+      case gfx::SharedSurfaceType::Gralloc: {
+        gl::SharedSurface_Gralloc* surf = gl::SharedSurface_Gralloc::Cast(abstractSurf);
+        GrallocTextureClientOGL* client = surf->GetTextureClient();
+        android::GraphicBuffer* graphicBuffer = client->GetGraphicBuffer().get();
+
+        MOZ_ASSERT(mCompositor->GetBackendType() == LayersBackend::LAYERS_OPENGL);
+        CompositorOGL* compositorOGL = static_cast<CompositorOGL*>(mCompositor);
+
+        newTexSource = new GrallocTextureSourceOGL(compositorOGL, graphicBuffer, format);
+        break;
+      }
+#endif
+#ifdef XP_MACOSX
+      case gfx::SharedSurfaceType::IOSurface: {
+        gl::SharedSurface_IOSurface* surf = gl::SharedSurface_IOSurface::Cast(abstractSurf);
+        MacIOSurface* ioSurf = surf->GetIOSurface();
+
+        MOZ_ASSERT(mCompositor->GetBackendType() == LayersBackend::LAYERS_OPENGL);
+        CompositorOGL* compositorOGL = static_cast<CompositorOGL*>(mCompositor);
+
+        newTexSource = new MacIOSurfaceTextureSourceOGL(compositorOGL,
+                                                        ioSurf);
+        break;
+      }
+#endif
+      default:
+        break;
+    }
+  } else {
+    // Do readback, and make a buffer view for it?
+    NS_WARNING("`!compositorSupportsShSurfType`.");
+    return false;
+  }
+
+  MOZ_ASSERT(newTexSource.get(), "TextureSource creation failed.");
+  if (!newTexSource)
+    return false;
+
+  mTextureSource = newTexSource;
+  return true;
+}
+
+void
+StreamTextureHost::Unlock()
+{
+}
+
+void
+StreamTextureHost::SetCompositor(Compositor* aCompositor)
+{
+  mCompositor = aCompositor;
+}
+
+gfx::SurfaceFormat
+StreamTextureHost::GetFormat() const
+{
+  MOZ_ASSERT(mTextureSource);
+  return mTextureSource->GetFormat();
+}
+
+gfx::IntSize
+StreamTextureHost::GetSize() const
+{
+  MOZ_ASSERT(mTextureSource);
+  return mTextureSource->GetSize();
+}
+
+////////////////////////////////////////////////////////////////////////
+
 } // namespace
 } // namespace
--- a/gfx/layers/composite/TextureHost.h
+++ b/gfx/layers/composite/TextureHost.h
@@ -28,27 +28,31 @@
 #include "mozilla/layers/AtomicRefCountedWithFinalize.h"
 
 class gfxReusableSurfaceWrapper;
 struct nsIntPoint;
 struct nsIntSize;
 struct nsIntRect;
 
 namespace mozilla {
+namespace gfx {
+class SurfaceStream;
+}
 namespace ipc {
 class Shmem;
 }
 
 namespace layers {
 
 class Compositor;
 class CompositableHost;
 class CompositableBackendSpecificData;
 class CompositableParentManager;
 class SurfaceDescriptor;
+class SurfaceStreamDescriptor;
 class ISurfaceAllocator;
 class TextureHostOGL;
 class TextureSourceOGL;
 class TextureSourceD3D9;
 class TextureSourceD3D11;
 class TextureSourceBasic;
 class DataTextureSource;
 class PTextureParent;
@@ -587,16 +591,60 @@ public:
   virtual size_t GetBufferSize() MOZ_OVERRIDE;
 
   virtual const char *Name() MOZ_OVERRIDE { return "MemoryTextureHost"; }
 
 protected:
   uint8_t* mBuffer;
 };
 
+/**
+ * A TextureHost for shared SurfaceStream
+ */
+class StreamTextureHost : public TextureHost
+{
+public:
+  StreamTextureHost(TextureFlags aFlags,
+                    const SurfaceStreamDescriptor& aDesc);
+
+  virtual ~StreamTextureHost();
+
+  virtual void DeallocateDeviceData() MOZ_OVERRIDE {};
+
+  virtual void SetCompositor(Compositor* aCompositor) MOZ_OVERRIDE;
+
+  virtual bool Lock() MOZ_OVERRIDE;
+
+  virtual void Unlock() MOZ_OVERRIDE;
+
+  virtual gfx::SurfaceFormat GetFormat() const MOZ_OVERRIDE;
+
+  virtual NewTextureSource* GetTextureSources() MOZ_OVERRIDE
+  {
+    return mTextureSource;
+  }
+
+  virtual TemporaryRef<gfx::DataSourceSurface> GetAsSurface() MOZ_OVERRIDE
+  {
+    return nullptr; // XXX - implement this (for MOZ_DUMP_PAINTING)
+  }
+
+  virtual gfx::IntSize GetSize() const MOZ_OVERRIDE;
+
+#ifdef MOZ_LAYERS_HAVE_LOG
+  virtual const char* Name() { return "StreamTextureHost"; }
+#endif
+
+protected:
+  Compositor* mCompositor;
+  gfx::SurfaceStream* mStream;
+  RefPtr<NewTextureSource> mTextureSource;
+  RefPtr<DataTextureSource> mDataTextureSource;
+};
+
 class MOZ_STACK_CLASS AutoLockTextureHost
 {
 public:
   AutoLockTextureHost(TextureHost* aTexture)
     : mTexture(aTexture)
   {
     mLocked = mTexture ? mTexture->Lock() : false;
   }
--- a/gfx/layers/composite/TiledContentHost.cpp
+++ b/gfx/layers/composite/TiledContentHost.cpp
@@ -355,18 +355,20 @@ TiledContentHost::RenderTile(const TileH
     NS_WARNING("Failed to lock tile");
     return;
   }
   RefPtr<NewTextureSource> source = aTile.mTextureHost->GetTextureSources();
   if (!source) {
     return;
   }
 
-  RefPtr<TexturedEffect> effect =
-    CreateTexturedEffect(aTile.mTextureHost->GetFormat(), source, aFilter);
+  RefPtr<TexturedEffect> effect = CreateTexturedEffect(aTile.mTextureHost->GetFormat(),
+                                                       source,
+                                                       aFilter,
+                                                       true);
   if (!effect) {
     return;
   }
 
   aEffectChain.mPrimaryEffect = effect;
 
   nsIntRegionRectIterator it(aScreenRegion);
   for (const nsIntRect* rect = it.Next(); rect != nullptr; rect = it.Next()) {
--- a/gfx/layers/d3d11/TextureD3D11.cpp
+++ b/gfx/layers/d3d11/TextureD3D11.cpp
@@ -133,16 +133,19 @@ CreateTextureHostD3D11(const SurfaceDesc
       result = CreateBackendIndependentTextureHost(aDesc, aDeallocator, aFlags);
       break;
     }
     case SurfaceDescriptor::TSurfaceDescriptorD3D10: {
       result = new DXGITextureHostD3D11(aFlags,
                                         aDesc.get_SurfaceDescriptorD3D10());
       break;
     }
+    case SurfaceDescriptor::TSurfaceStreamDescriptor: {
+      MOZ_CRASH("Should never hit this.");
+    }
     default: {
       NS_WARNING("Unsupported SurfaceDescriptor type");
     }
   }
   return result;
 }
 
 TextureClientD3D11::TextureClientD3D11(gfx::SurfaceFormat aFormat, TextureFlags aFlags)
--- a/gfx/layers/opengl/GrallocTextureClient.h
+++ b/gfx/layers/opengl/GrallocTextureClient.h
@@ -3,17 +3,17 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef MOZILLA_GFX_GRALLOCTEXTURECLIENT_H
 #define MOZILLA_GFX_GRALLOCTEXTURECLIENT_H
 #ifdef MOZ_WIDGET_GONK
 
 #include "mozilla/layers/TextureClient.h"
-#include "ISurfaceAllocator.h" // For IsSurfaceDescriptorValid
+#include "mozilla/layers/ISurfaceAllocator.h" // For IsSurfaceDescriptorValid
 #include "mozilla/layers/FenceUtils.h" // for FenceHandle
 #include "mozilla/layers/ShadowLayerUtilsGralloc.h"
 #include <ui/GraphicBuffer.h>
 
 
 namespace android {
 class MediaBuffer;
 };
--- a/gfx/layers/opengl/TextureClientOGL.cpp
+++ b/gfx/layers/opengl/TextureClientOGL.cpp
@@ -79,66 +79,10 @@ SharedTextureClientOGL::Unlock()
 }
 
 bool
 SharedTextureClientOGL::IsAllocated() const
 {
   return mHandle != 0;
 }
 
-StreamTextureClientOGL::StreamTextureClientOGL(TextureFlags aFlags)
-  : TextureClient(aFlags)
-  , mIsLocked(false)
-{
-}
-
-StreamTextureClientOGL::~StreamTextureClientOGL()
-{
-  // the data is owned externally.
-}
-
-bool
-StreamTextureClientOGL::Lock(OpenMode mode)
-{
-  MOZ_ASSERT(!mIsLocked);
-  if (!IsValid() || !IsAllocated()) {
-    return false;
-  }
-  mIsLocked = true;
-  return true;
-}
-
-void
-StreamTextureClientOGL::Unlock()
-{
-  MOZ_ASSERT(mIsLocked);
-  mIsLocked = false;
-}
-
-bool
-StreamTextureClientOGL::ToSurfaceDescriptor(SurfaceDescriptor& aOutDescriptor)
-{
-  if (!IsAllocated()) {
-    return false;
-  }
-
-  gfx::SurfaceStreamHandle handle = mStream->GetShareHandle();
-  aOutDescriptor = SurfaceStreamDescriptor(handle, false);
-  return true;
-}
-
-void
-StreamTextureClientOGL::InitWith(gfx::SurfaceStream* aStream)
-{
-  MOZ_ASSERT(!IsAllocated());
-  mStream = aStream;
-  mGL = mStream->GLContext();
-}
-
-bool
-StreamTextureClientOGL::IsAllocated() const
-{
-  return mStream != 0;
-}
-
-
 } // namespace
 } // namespace
--- a/gfx/layers/opengl/TextureClientOGL.h
+++ b/gfx/layers/opengl/TextureClientOGL.h
@@ -68,54 +68,12 @@ public:
 protected:
   gl::SharedTextureHandle mHandle;
   gfx::IntSize mSize;
   gl::SharedTextureShareType mShareType;
   bool mInverted;
   bool mIsLocked;
 };
 
-/**
- * A TextureClient implementation to share SurfaceStream.
- */
-class StreamTextureClientOGL : public TextureClient
-{
-public:
-  StreamTextureClientOGL(TextureFlags aFlags);
-
-  ~StreamTextureClientOGL();
-
-  virtual bool IsAllocated() const MOZ_OVERRIDE;
-
-  virtual bool Lock(OpenMode mode) MOZ_OVERRIDE;
-
-  virtual void Unlock() MOZ_OVERRIDE;
-
-  virtual bool IsLocked() const MOZ_OVERRIDE { return mIsLocked; }
-
-  virtual bool ToSurfaceDescriptor(SurfaceDescriptor& aOutDescriptor) MOZ_OVERRIDE;
-
-  virtual bool HasInternalBuffer() const MOZ_OVERRIDE { return false; }
-
-  void InitWith(gfx::SurfaceStream* aStream);
-
-  virtual gfx::IntSize GetSize() const { return gfx::IntSize(); }
-
-  virtual gfx::SurfaceFormat GetFormat() const MOZ_OVERRIDE
-  {
-    return gfx::SurfaceFormat::UNKNOWN;
-  }
-
-  virtual bool AllocateForSurface(gfx::IntSize aSize, TextureAllocationFlags aFlags) MOZ_OVERRIDE
-  {
-    return false;
-  }
-
-protected:
-  bool mIsLocked;
-  RefPtr<gfx::SurfaceStream> mStream;
-  RefPtr<gl::GLContext> mGL;
-};
-
 } // namespace
 } // namespace
 
 #endif
--- a/gfx/layers/opengl/TextureHostOGL.cpp
+++ b/gfx/layers/opengl/TextureHostOGL.cpp
@@ -3,21 +3,16 @@
 * 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 "TextureHostOGL.h"
 #include "GLContext.h"                  // for GLContext, etc
 #include "GLSharedHandleHelpers.h"
 #include "GLUploadHelpers.h"
 #include "GLReadTexImageHelper.h"
-#include "SharedSurface.h"              // for SharedSurface
-#include "SharedSurfaceEGL.h"           // for SharedSurface_EGLImage
-#include "SharedSurfaceGL.h"            // for SharedSurface_GLTexture, etc
-#include "SurfaceStream.h"              // for SurfaceStream
-#include "SurfaceTypes.h"               // for SharedSurfaceType, etc
 #include "gfx2DGlue.h"                  // for ContentForFormat, etc
 #include "gfxReusableSurfaceWrapper.h"  // for gfxReusableSurfaceWrapper
 #include "mozilla/gfx/2D.h"             // for DataSourceSurface
 #include "mozilla/gfx/BaseSize.h"       // for BaseSize
 #include "mozilla/layers/CompositorOGL.h"  // for CompositorOGL
 #ifdef MOZ_WIDGET_GONK
 # include "GrallocImages.h"  // for GrallocImage
 # include "EGLImageHelpers.h"
@@ -70,21 +65,16 @@ CreateTextureHostOGL(const SurfaceDescri
       const SharedTextureDescriptor& desc = aDesc.get_SharedTextureDescriptor();
       result = new SharedTextureHostOGL(aFlags,
                                         desc.shareType(),
                                         desc.handle(),
                                         desc.size(),
                                         desc.inverted());
       break;
     }
-    case SurfaceDescriptor::TSurfaceStreamDescriptor: {
-      const SurfaceStreamDescriptor& desc = aDesc.get_SurfaceStreamDescriptor();
-      result = new StreamTextureHostOGL(aFlags, desc);
-      break;
-    }
 #ifdef XP_MACOSX
     case SurfaceDescriptor::TSurfaceDescriptorMacIOSurface: {
       const SurfaceDescriptorMacIOSurface& desc =
         aDesc.get_SurfaceDescriptorMacIOSurface();
       result = new MacIOSurfaceTextureHostOGL(aFlags, desc);
       break;
     }
 #endif
@@ -420,16 +410,66 @@ SharedTextureSourceOGL::GetTextureTransf
   if (!GetSharedHandleDetails(gl(), mShareType, mSharedHandle, handleDetails)) {
     NS_WARNING("Could not get shared handle details");
     return gfx::Matrix4x4();
   }
 
   return handleDetails.mTextureTransform;
 }
 
+
+////////////////////////////////////////////////////////////////////////
+// GLTextureSource
+
+GLTextureSource::GLTextureSource(CompositorOGL* aCompositor,
+                                 GLuint aTex,
+                                 gfx::SurfaceFormat aFormat,
+                                 GLenum aTarget,
+                                 gfx::IntSize aSize)
+  : mSize(aSize)
+  , mCompositor(aCompositor)
+  , mTex(aTex)
+  , mFormat(aFormat)
+  , mTextureTarget(aTarget)
+{
+}
+
+void
+GLTextureSource::BindTexture(GLenum aTextureUnit, gfx::Filter aFilter)
+{
+  if (!gl()) {
+    NS_WARNING("Trying to bind a texture without a GLContext");
+    return;
+  }
+  gl()->fActiveTexture(aTextureUnit);
+  gl()->fBindTexture(mTextureTarget, mTex);
+  ApplyFilterToBoundTexture(gl(), aFilter, mTextureTarget);
+}
+
+void
+GLTextureSource::SetCompositor(Compositor* aCompositor)
+{
+  mCompositor = static_cast<CompositorOGL*>(aCompositor);
+}
+
+bool
+GLTextureSource::IsValid() const
+{
+  return !!gl();
+}
+
+gl::GLContext*
+GLTextureSource::gl() const
+{
+  return mCompositor ? mCompositor->gl() : nullptr;
+}
+
+////////////////////////////////////////////////////////////////////////
+// SharedTextureHostOGL
+
 SharedTextureHostOGL::SharedTextureHostOGL(TextureFlags aFlags,
                                            gl::SharedTextureShareType aShareType,
                                            gl::SharedTextureHandle aSharedHandle,
                                            gfx::IntSize aSize,
                                            bool inverted)
   : TextureHost(aFlags)
   , mSize(aSize)
   , mCompositor(nullptr)
@@ -499,185 +539,10 @@ SharedTextureHostOGL::SetCompositor(Comp
 
 gfx::SurfaceFormat
 SharedTextureHostOGL::GetFormat() const
 {
   MOZ_ASSERT(mTextureSource);
   return mTextureSource->GetFormat();
 }
 
-void
-StreamTextureSourceOGL::BindTexture(GLenum activetex, gfx::Filter aFilter)
-{
-  MOZ_ASSERT(gl());
-  gl()->fActiveTexture(activetex);
-  gl()->fBindTexture(mTextureTarget, mTextureHandle);
-  SetFilter(gl(), aFilter);
-}
-
-bool
-StreamTextureSourceOGL::RetrieveTextureFromStream()
-{
-  gl()->MakeCurrent();
-
-  SharedSurface* sharedSurf = mStream->SwapConsumer();
-  if (!sharedSurf) {
-    // We don't have a valid surf to show yet.
-    return false;
-  }
-
-  gl()->MakeCurrent();
-
-  mSize = IntSize(sharedSurf->Size().width, sharedSurf->Size().height);
-
-  DataSourceSurface* toUpload = nullptr;
-  switch (sharedSurf->Type()) {
-    case SharedSurfaceType::GLTextureShare: {
-      SharedSurface_GLTexture* glTexSurf = SharedSurface_GLTexture::Cast(sharedSurf);
-      mTextureHandle = glTexSurf->ConsTexture(gl());
-      mTextureTarget = glTexSurf->ConsTextureTarget();
-      MOZ_ASSERT(mTextureHandle);
-      mFormat = sharedSurf->HasAlpha() ? SurfaceFormat::R8G8B8A8
-                                       : SurfaceFormat::R8G8B8X8;
-      break;
-    }
-    case SharedSurfaceType::EGLImageShare: {
-      SharedSurface_EGLImage* eglImageSurf =
-          SharedSurface_EGLImage::Cast(sharedSurf);
-
-      eglImageSurf->AcquireConsumerTexture(gl(), &mTextureHandle, &mTextureTarget);
-      MOZ_ASSERT(mTextureHandle);
-      mFormat = sharedSurf->HasAlpha() ? SurfaceFormat::R8G8B8A8
-                                       : SurfaceFormat::R8G8B8X8;
-      break;
-    }
-#ifdef XP_MACOSX
-    case SharedSurfaceType::IOSurface: {
-      SharedSurface_IOSurface* glTexSurf = SharedSurface_IOSurface::Cast(sharedSurf);
-      mTextureHandle = glTexSurf->ConsTexture(gl());
-      mTextureTarget = glTexSurf->ConsTextureTarget();
-      MOZ_ASSERT(mTextureHandle);
-      mFormat = sharedSurf->HasAlpha() ? SurfaceFormat::R8G8B8A8
-                                       : SurfaceFormat::R8G8B8X8;
-      break;
-    }
-#endif
-    case SharedSurfaceType::Basic: {
-      toUpload = SharedSurface_Basic::Cast(sharedSurf)->GetData();
-      MOZ_ASSERT(toUpload);
-      break;
-    }
-    default:
-      MOZ_CRASH("Invalid SharedSurface type.");
-  }
-
-  if (toUpload) {
-    // mBounds seems to end up as (0,0,0,0) a lot, so don't use it?
-    nsIntSize size(ThebesIntSize(toUpload->GetSize()));
-    nsIntRect rect(nsIntPoint(0,0), size);
-    nsIntRegion bounds(rect);
-    mFormat = UploadSurfaceToTexture(gl(),
-                                     toUpload,
-                                     bounds,
-                                     mUploadTexture,
-                                     true);
-    mTextureHandle = mUploadTexture;
-    mTextureTarget = LOCAL_GL_TEXTURE_2D;
-  }
-
-  MOZ_ASSERT(mTextureHandle);
-  gl()->fBindTexture(mTextureTarget, mTextureHandle);
-  gl()->fTexParameteri(mTextureTarget,
-                      LOCAL_GL_TEXTURE_WRAP_S,
-                      LOCAL_GL_CLAMP_TO_EDGE);
-  gl()->fTexParameteri(mTextureTarget,
-                      LOCAL_GL_TEXTURE_WRAP_T,
-                      LOCAL_GL_CLAMP_TO_EDGE);
-
-  ClearCachedFilter();
-
-  return true;
-}
-
-void
-StreamTextureSourceOGL::DeallocateDeviceData()
-{
-  if (mUploadTexture) {
-    MOZ_ASSERT(gl());
-    gl()->MakeCurrent();
-    gl()->fDeleteTextures(1, &mUploadTexture);
-    mUploadTexture = 0;
-    mTextureHandle = 0;
-  }
-}
-
-gl::GLContext*
-StreamTextureSourceOGL::gl() const
-{
-  return mCompositor ? mCompositor->gl() : nullptr;
-}
-
-void
-StreamTextureSourceOGL::SetCompositor(Compositor* aCompositor)
-{
-  mCompositor = static_cast<CompositorOGL*>(aCompositor);
-}
-
-StreamTextureHostOGL::StreamTextureHostOGL(TextureFlags aFlags,
-                                           const SurfaceStreamDescriptor& aDesc)
-  : TextureHost(aFlags)
-{
-  mStream = SurfaceStream::FromHandle(aDesc.handle());
-  MOZ_ASSERT(mStream);
-}
-
-StreamTextureHostOGL::~StreamTextureHostOGL()
-{
-  // If need to deallocate textures, call DeallocateSharedData() before
-  // the destructor
-}
-
-bool
-StreamTextureHostOGL::Lock()
-{
-  if (!mCompositor) {
-    return false;
-  }
-
-  if (!mTextureSource) {
-    mTextureSource = new StreamTextureSourceOGL(mCompositor,
-                                                mStream);
-  }
-
-  return mTextureSource->RetrieveTextureFromStream();
-}
-
-void
-StreamTextureHostOGL::Unlock()
-{
-}
-
-void
-StreamTextureHostOGL::SetCompositor(Compositor* aCompositor)
-{
-  CompositorOGL* glCompositor = static_cast<CompositorOGL*>(aCompositor);
-  mCompositor = glCompositor;
-  if (mTextureSource) {
-    mTextureSource->SetCompositor(glCompositor);
-  }
-}
-
-gfx::SurfaceFormat
-StreamTextureHostOGL::GetFormat() const
-{
-  MOZ_ASSERT(mTextureSource);
-  return mTextureSource->GetFormat();
-}
-
-gfx::IntSize
-StreamTextureHostOGL::GetSize() const
-{
-  MOZ_ASSERT(mTextureSource);
-  return mTextureSource->GetSize();
-}
-
 } // namespace
 } // namespace
--- a/gfx/layers/opengl/TextureHostOGL.h
+++ b/gfx/layers/opengl/TextureHostOGL.h
@@ -313,17 +313,17 @@ public:
 
   virtual gfx::Matrix4x4 GetTextureTransform() MOZ_OVERRIDE;
 
   virtual GLenum GetTextureTarget() const { return mTextureTarget; }
 
   virtual GLenum GetWrapMode() const MOZ_OVERRIDE { return mWrapMode; }
 
   // SharedTextureSource doesn't own any gl texture
-  virtual void DeallocateDeviceData() {}
+  virtual void DeallocateDeviceData() MOZ_OVERRIDE {}
 
   void DetachSharedHandle();
 
   virtual void SetCompositor(Compositor* aCompositor) MOZ_OVERRIDE;
 
   gl::GLContext* gl() const;
 
 protected:
@@ -384,113 +384,59 @@ protected:
   CompositorOGL* mCompositor;
   gl::SharedTextureHandle mSharedHandle;
   gl::SharedTextureShareType mShareType;
 
   RefPtr<SharedTextureSourceOGL> mTextureSource;
 };
 
 /**
- * A texture source meant for use with StreamTextureHostOGL.
+ * A texture source meant for use with SharedTextureHostOGL.
+ *
+ * It does not own any GL texture, and attaches its shared handle to one of
+ * the compositor's temporary textures when binding.
  *
- * It does not own any texture, we get texture from SurfaceStream.
+ * The shared texture handle is owned by the TextureHost.
  */
-class StreamTextureSourceOGL : public NewTextureSource
-                             , public TextureSourceOGL
+class GLTextureSource : public NewTextureSource
+                      , public TextureSourceOGL
 {
 public:
-  StreamTextureSourceOGL(CompositorOGL* aCompositor,
-                         gfx::SurfaceStream* aStream)
-    : mCompositor(aCompositor)
-    , mStream(aStream)
-    , mTextureHandle(0)
-    , mTextureTarget(LOCAL_GL_TEXTURE_2D)
-    , mUploadTexture(0)
-    , mFormat(gfx::SurfaceFormat::UNKNOWN)
-  {
-    MOZ_COUNT_CTOR(StreamTextureSourceOGL);
-  }
+  typedef gl::SharedTextureShareType SharedTextureShareType;
 
-  ~StreamTextureSourceOGL()
-  {
-    MOZ_COUNT_DTOR(StreamTextureSourceOGL);
-  }
+  GLTextureSource(CompositorOGL* aCompositor,
+                  GLuint aTex,
+                  gfx::SurfaceFormat aFormat,
+                  GLenum aTarget,
+                  gfx::IntSize aSize);
 
-  virtual TextureSourceOGL* AsSourceOGL() { return this; }
+  virtual TextureSourceOGL* AsSourceOGL() MOZ_OVERRIDE { return this; }
 
   virtual void BindTexture(GLenum activetex, gfx::Filter aFilter) MOZ_OVERRIDE;
 
-  virtual bool IsValid() const MOZ_OVERRIDE { return !!gl(); }
+  virtual bool IsValid() const MOZ_OVERRIDE;
 
   virtual gfx::IntSize GetSize() const MOZ_OVERRIDE { return mSize; }
 
   virtual gfx::SurfaceFormat GetFormat() const MOZ_OVERRIDE { return mFormat; }
 
   virtual GLenum GetTextureTarget() const { return mTextureTarget; }
 
   virtual GLenum GetWrapMode() const MOZ_OVERRIDE { return LOCAL_GL_CLAMP_TO_EDGE; }
 
-  virtual void DeallocateDeviceData();
-
-  bool RetrieveTextureFromStream();
-
-  virtual void SetCompositor(Compositor* aCompositor) MOZ_OVERRIDE;
-
-protected:
-  gl::GLContext* gl() const;
-
-  CompositorOGL* mCompositor;
-  gfx::SurfaceStream* mStream;
-  GLuint mTextureHandle;
-  GLenum mTextureTarget;
-  GLuint mUploadTexture;
-  gfx::IntSize mSize;
-  gfx::SurfaceFormat mFormat;
-};
-
-/**
- * A TextureHost for shared SurfaceStream
- */
-class StreamTextureHostOGL : public TextureHost
-{
-public:
-  StreamTextureHostOGL(TextureFlags aFlags,
-                       const SurfaceStreamDescriptor& aDesc);
-
-  virtual ~StreamTextureHostOGL();
-
-  // SharedTextureHostOGL doesn't own any GL texture
   virtual void DeallocateDeviceData() MOZ_OVERRIDE {}
 
   virtual void SetCompositor(Compositor* aCompositor) MOZ_OVERRIDE;
 
-  virtual bool Lock() MOZ_OVERRIDE;
-
-  virtual void Unlock() MOZ_OVERRIDE;
-
-  virtual gfx::SurfaceFormat GetFormat() const MOZ_OVERRIDE;
-
-  virtual NewTextureSource* GetTextureSources() MOZ_OVERRIDE
-  {
-    return mTextureSource;
-  }
-
-  virtual TemporaryRef<gfx::DataSourceSurface> GetAsSurface() MOZ_OVERRIDE
-  {
-    return nullptr; // XXX - implement this (for MOZ_DUMP_PAINTING)
-  }
-
-  virtual gfx::IntSize GetSize() const MOZ_OVERRIDE;
-
-#ifdef MOZ_LAYERS_HAVE_LOG
-  virtual const char* Name() { return "StreamTextureHostOGL"; }
-#endif
+  gl::GLContext* gl() const;
 
 protected:
+  const gfx::IntSize mSize;
   CompositorOGL* mCompositor;
-  gfx::SurfaceStream* mStream;
-  RefPtr<StreamTextureSourceOGL> mTextureSource;
+  const GLuint mTex;
+  const gfx::SurfaceFormat mFormat;
+  const GLenum mTextureTarget;
 };
 
 } // namespace
 } // namespace
 
 #endif /* MOZILLA_GFX_TEXTUREOGL_H */