Bug 1097877. Move GLBlitTextureImageHelper from gfx/gl to gfx/layers/opengl. r=nical
authorJeff Muizelaar <jmuizelaar@mozilla.com>
Mon, 10 Nov 2014 14:49:05 -0500
changeset 231870 63eace116946532e669949f1ea88ea1a7c98b906
parent 231869 5dfdebf9cc796e449c2a512a9393df3657fb8b6c
child 231871 c9e1814d648d006db6da926266cd060d003043e9
push id7326
push userbhearsum@mozilla.com
push dateFri, 28 Nov 2014 15:58:42 +0000
treeherdermozilla-aurora@d3a3b2a0f2f8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnical
bugs1097877
milestone36.0a1
Bug 1097877. Move GLBlitTextureImageHelper from gfx/gl to gfx/layers/opengl. r=nical The only user is in layers/opengl. This is needed to do better state tracking in the compositor.
gfx/gl/GLBlitTextureImageHelper.cpp
gfx/gl/GLBlitTextureImageHelper.h
gfx/gl/GLContext.cpp
gfx/gl/GLContext.h
gfx/gl/moz.build
gfx/layers/moz.build
gfx/layers/opengl/CompositorOGL.cpp
gfx/layers/opengl/CompositorOGL.h
gfx/layers/opengl/GLBlitTextureImageHelper.cpp
gfx/layers/opengl/GLBlitTextureImageHelper.h
gfx/layers/opengl/TextureHostOGL.cpp
gfx/layers/opengl/TextureHostOGL.h
--- a/gfx/gl/GLContext.cpp
+++ b/gfx/gl/GLContext.cpp
@@ -6,17 +6,16 @@
 
 #include <algorithm>
 #include <stdio.h>
 #include <string.h>
 #include <ctype.h>
 
 #include "GLContext.h"
 #include "GLBlitHelper.h"
-#include "GLBlitTextureImageHelper.h"
 #include "GLReadTexImageHelper.h"
 
 #include "gfxCrashReporterUtils.h"
 #include "gfxUtils.h"
 #include "GLContextProvider.h"
 #include "GLTextureImage.h"
 #include "nsPrintfCString.h"
 #include "nsThreadUtils.h"
@@ -2085,17 +2084,16 @@ GLContext::MarkDestroyed()
 {
     if (IsDestroyed())
         return;
 
     if (MakeCurrent()) {
         DestroyScreenBuffer();
 
         mBlitHelper = nullptr;
-        mBlitTextureImageHelper = nullptr;
         mReadTexImageHelper = nullptr;
 
         mTexGarbageBin->GLContextTeardown();
     } else {
         NS_WARNING("MakeCurrent() failed during MarkDestroyed! Skipping GL object teardown.");
     }
 
     mSymbols.Zero();
@@ -2408,26 +2406,16 @@ GLContext::BlitHelper()
 {
     if (!mBlitHelper) {
         mBlitHelper = MakeUnique<GLBlitHelper>(this);
     }
 
     return mBlitHelper.get();
 }
 
-GLBlitTextureImageHelper*
-GLContext::BlitTextureImageHelper()
-{
-    if (!mBlitTextureImageHelper) {
-        mBlitTextureImageHelper = MakeUnique<GLBlitTextureImageHelper>(this);
-    }
-
-    return mBlitTextureImageHelper.get();
-}
-
 GLReadTexImageHelper*
 GLContext::ReadTexImageHelper()
 {
     if (!mReadTexImageHelper) {
         mReadTexImageHelper = MakeUnique<GLReadTexImageHelper>(this);
     }
 
     return mReadTexImageHelper.get();
--- a/gfx/gl/GLContext.h
+++ b/gfx/gl/GLContext.h
@@ -3413,17 +3413,16 @@ protected:
     // to a GLContext that isn't current on the current
     // thread.
     // Store the current context when binding to thread local
     // storage to support DebugMode on an arbitrary thread.
     static unsigned sCurrentGLContextTLS;
 #endif
 
     UniquePtr<GLBlitHelper> mBlitHelper;
-    UniquePtr<GLBlitTextureImageHelper> mBlitTextureImageHelper;
     UniquePtr<GLReadTexImageHelper> mReadTexImageHelper;
 
 public:
     GLBlitHelper* BlitHelper();
     GLBlitTextureImageHelper* BlitTextureImageHelper();
     GLReadTexImageHelper* ReadTexImageHelper();
 
     // Assumes shares are created by all sharing with the same global context.
--- a/gfx/gl/moz.build
+++ b/gfx/gl/moz.build
@@ -28,17 +28,16 @@ if CONFIG['MOZ_GL_PROVIDER']:
 EXPORTS += [
     'AndroidNativeWindow.h',
     'AndroidSurfaceTexture.h',
     'DecomposeIntoNoRepeatTriangles.h',
     'EGLUtils.h',
     'ForceDiscreteGPUHelperCGL.h',
     'GfxTexturesReporter.h',
     'GLBlitHelper.h',
-    'GLBlitTextureImageHelper.h',
     'GLConsts.h',
     'GLContext.h',
     'GLContextEGL.h',
     'GLContextProvider.h',
     'GLContextProviderImpl.h',
     'GLContextSymbols.h',
     'GLContextTypes.h',
     'GLDefs.h',
@@ -117,17 +116,16 @@ else:
 
 UNIFIED_SOURCES += [
     'AndroidNativeWindow.cpp',
     'AndroidSurfaceTexture.cpp',
     'DecomposeIntoNoRepeatTriangles.cpp',
     'EGLUtils.cpp',
     'GfxTexturesReporter.cpp',
     'GLBlitHelper.cpp',
-    'GLBlitTextureImageHelper.cpp',
     'GLContext.cpp',
     'GLContextFeatures.cpp',
     'GLContextTypes.cpp',
     'GLDebugUtils.cpp',
     'GLLibraryEGL.cpp',
     'GLLibraryLoader.cpp',
     'GLReadTexImageHelper.cpp',
     'GLScreenBuffer.cpp',
--- a/gfx/layers/moz.build
+++ b/gfx/layers/moz.build
@@ -308,16 +308,17 @@ UNIFIED_SOURCES += [
     'ipc/SharedBufferManagerParent.cpp',
     'ipc/SharedPlanarYCbCrImage.cpp',
     'ipc/SharedRGBImage.cpp',
     'LayerScope.cpp',
     'LayersLogging.cpp',
     'LayerSorter.cpp',
     'opengl/CompositingRenderTargetOGL.cpp',
     'opengl/CompositorOGL.cpp',
+    'opengl/GLBlitTextureImageHelper.cpp',
     'opengl/OGLShaderProgram.cpp',
     'opengl/TextureClientOGL.cpp',
     'opengl/TextureHostOGL.cpp',
     'opengl/TexturePoolOGL.cpp',
     'protobuf/LayerScopePacket.pb.cc',
     'ReadbackProcessor.cpp',
     'RenderTrace.cpp',
     'RotatedBuffer.cpp',
--- a/gfx/layers/opengl/CompositorOGL.cpp
+++ b/gfx/layers/opengl/CompositorOGL.cpp
@@ -34,16 +34,17 @@
 #include "nsIWidget.h"                  // for nsIWidget
 #include "nsLiteralString.h"            // for NS_LITERAL_STRING
 #include "nsMathUtils.h"                // for NS_roundf
 #include "nsRect.h"                     // for nsIntRect
 #include "nsServiceManagerUtils.h"      // for do_GetService
 #include "nsString.h"                   // for nsString, nsAutoCString, etc
 #include "ScopedGLHelpers.h"
 #include "GLReadTexImageHelper.h"
+#include "GLBlitTextureImageHelper.h"
 #include "TiledLayerBuffer.h"           // for TiledLayerComposer
 #include "HeapCopyOfStackArray.h"
 
 #if MOZ_WIDGET_ANDROID
 #include "TexturePoolOGL.h"
 #endif
 
 #ifdef XP_MACOSX
@@ -169,16 +170,19 @@ CompositorOGL::CleanupResources()
   ctx->fBindFramebuffer(LOCAL_GL_FRAMEBUFFER, 0);
 
   if (mQuadVBO) {
     ctx->fDeleteBuffers(1, &mQuadVBO);
     mQuadVBO = 0;
   }
 
   mGLContext->MakeCurrent();
+
+  mBlitTextureImageHelper = nullptr;
+
   mContextStateTracker.DestroyOGL(mGLContext);
 
   // On the main thread the Widget will be destroyed soon and calling MakeCurrent
   // after that could cause a crash (at least with GLX, see bug 1059793), unless
   // context is marked as destroyed.
   // There may be some textures still alive that will try to call MakeCurrent on
   // the context so let's make sure it is marked destroyed now.
   mGLContext->MarkDestroyed();
@@ -1378,17 +1382,17 @@ CompositorOGL::Resume()
 #endif
   return true;
 }
 
 TemporaryRef<DataTextureSource>
 CompositorOGL::CreateDataTextureSource(TextureFlags aFlags)
 {
   RefPtr<DataTextureSource> result =
-    new TextureImageTextureSourceOGL(mGLContext, aFlags);
+    new TextureImageTextureSourceOGL(this, aFlags);
   return result;
 }
 
 bool
 CompositorOGL::SupportsPartialTextureUpdate()
 {
   return CanUploadSubTextures(mGLContext);
 }
@@ -1434,16 +1438,28 @@ CompositorOGL::BindAndDrawQuads(ShaderPr
     aProg->SetTextureRects(aTextureRects);
   }
 
   // We are using GL_TRIANGLES here because the Mac Intel drivers fail to properly
   // process uniform arrays with GL_TRIANGLE_STRIP. Go figure.
   mGLContext->fDrawArrays(LOCAL_GL_TRIANGLES, 0, 6 * aQuads);
 }
 
+GLBlitTextureImageHelper*
+CompositorOGL::BlitTextureImageHelper()
+{
+    if (!mBlitTextureImageHelper) {
+        mBlitTextureImageHelper = MakeUnique<GLBlitTextureImageHelper>(this);
+    }
+
+    return mBlitTextureImageHelper.get();
+}
+
+
+
 GLuint
 CompositorOGL::GetTemporaryTexture(GLenum aTarget, GLenum aUnit)
 {
   if (!mTexturePool) {
 #ifdef MOZ_WIDGET_GONK
     mTexturePool = new PerFrameTexturePoolOGL(gl());
 #else
     mTexturePool = new PerUnitTexturePoolOGL(gl());
--- a/gfx/layers/opengl/CompositorOGL.h
+++ b/gfx/layers/opengl/CompositorOGL.h
@@ -49,17 +49,17 @@ namespace layers {
 
 class CompositingRenderTarget;
 class CompositingRenderTargetOGL;
 class DataTextureSource;
 class GLManagerCompositor;
 class TextureSource;
 struct Effect;
 struct EffectChain;
-
+class GLBlitTextureImageHelper;
 /**
  * Interface for pools of temporary gl textures for the compositor.
  * The textures are fully owned by the pool, so the latter is responsible
  * calling fDeleteTextures accordingly.
  * Users of GetTexture receive a texture that is only valid for the duration
  * of the current frame.
  * This is primarily intended for direct texturing APIs that need to attach
  * shared objects (such as an EGLImage) to a gl texture.
@@ -254,16 +254,18 @@ public:
 
   virtual nsIWidget* GetWidget() const MOZ_OVERRIDE { return mWidget; }
 
   GLContext* gl() const { return mGLContext; }
   gfx::SurfaceFormat GetFBOFormat() const {
     return gfx::SurfaceFormat::R8G8B8A8;
   }
 
+  GLBlitTextureImageHelper* BlitTextureImageHelper();
+
   /**
    * The compositor provides with temporary textures for use with direct
    * textruing like gralloc texture.
    * Doing so lets us use gralloc the way it has been designed to be used
    * (see https://wiki.mozilla.org/Platform/GFX/Gralloc)
    */
   GLuint GetTemporaryTexture(GLenum aTarget, GLenum aUnit);
 
@@ -275,16 +277,17 @@ private:
   {
     return gfx::ToIntSize(mWidgetSize);
   }
 
   /** Widget associated with this compositor */
   nsIWidget *mWidget;
   nsIntSize mWidgetSize;
   nsRefPtr<GLContext> mGLContext;
+  UniquePtr<GLBlitTextureImageHelper> mBlitTextureImageHelper;
   gfx::Matrix4x4 mProjMatrix;
 
   /** The size of the surface we are rendering to */
   nsIntSize mSurfaceSize;
 
   ScreenPoint mRenderOffset;
 
   already_AddRefed<mozilla::gl::GLContext> CreateContext();
rename from gfx/gl/GLBlitTextureImageHelper.cpp
rename to gfx/layers/opengl/GLBlitTextureImageHelper.cpp
--- a/gfx/gl/GLBlitTextureImageHelper.cpp
+++ b/gfx/layers/opengl/GLBlitTextureImageHelper.cpp
@@ -3,54 +3,60 @@
 /* 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 "GLBlitTextureImageHelper.h"
 #include "GLUploadHelpers.h"
 #include "DecomposeIntoNoRepeatTriangles.h"
 #include "GLContext.h"
+#include "GLTextureImage.h"
 #include "ScopedGLHelpers.h"
 #include "nsRect.h"
 #include "gfx2DGlue.h"
 #include "gfxUtils.h"
+#include "CompositorOGL.h"
+
+using namespace mozilla::gl;
 
 namespace mozilla {
-namespace gl {
+namespace layers {
 
-GLBlitTextureImageHelper::GLBlitTextureImageHelper(GLContext* gl)
-    : mGL(gl)
+GLBlitTextureImageHelper::GLBlitTextureImageHelper(CompositorOGL* aCompositor)
+    : mCompositor(aCompositor)
     , mBlitProgram(0)
     , mBlitFramebuffer(0)
 
 {
 }
 
 GLBlitTextureImageHelper::~GLBlitTextureImageHelper()
 {
+    GLContext *gl = mCompositor->gl();
     // Likely used by OGL Layers.
-    mGL->fDeleteProgram(mBlitProgram);
-    mGL->fDeleteFramebuffers(1, &mBlitFramebuffer);
+    gl->fDeleteProgram(mBlitProgram);
+    gl->fDeleteFramebuffers(1, &mBlitFramebuffer);
 }
 
 void
 GLBlitTextureImageHelper::BlitTextureImage(TextureImage *aSrc, const nsIntRect& aSrcRect,
                                            TextureImage *aDst, const nsIntRect& aDstRect)
 {
+    GLContext *gl = mCompositor->gl();
     NS_ASSERTION(!aSrc->InUpdate(), "Source texture is in update!");
     NS_ASSERTION(!aDst->InUpdate(), "Destination texture is in update!");
 
     if (!aSrc || !aDst || aSrcRect.IsEmpty() || aDstRect.IsEmpty())
         return;
 
     int savedFb = 0;
-    mGL->fGetIntegerv(LOCAL_GL_FRAMEBUFFER_BINDING, &savedFb);
+    gl->fGetIntegerv(LOCAL_GL_FRAMEBUFFER_BINDING, &savedFb);
 
-    ScopedGLState scopedScissorTestState(mGL, LOCAL_GL_SCISSOR_TEST, false);
-    ScopedGLState scopedBlendState(mGL, LOCAL_GL_BLEND, false);
+    ScopedGLState scopedScissorTestState(gl, LOCAL_GL_SCISSOR_TEST, false);
+    ScopedGLState scopedBlendState(gl, LOCAL_GL_BLEND, false);
 
     // 2.0 means scale up by two
     float blitScaleX = float(aDstRect.width) / float(aSrcRect.width);
     float blitScaleY = float(aDstRect.height) / float(aSrcRect.height);
 
     // We start iterating over all destination tiles
     aDst->BeginBigImageIteration();
     do {
@@ -108,22 +114,22 @@ GLBlitTextureImageHelper::BlitTextureIma
             nsIntSize dstSize = dstTextureRect.Size();
             srcSubRect.MoveBy(-srcTextureRect.x, -srcTextureRect.y);
             srcSubInDstRect.MoveBy(-dstTextureRect.x, -dstTextureRect.y);
 
             float dx0 = 2.0f * float(srcSubInDstRect.x) / float(dstSize.width) - 1.0f;
             float dy0 = 2.0f * float(srcSubInDstRect.y) / float(dstSize.height) - 1.0f;
             float dx1 = 2.0f * float(srcSubInDstRect.x + srcSubInDstRect.width) / float(dstSize.width) - 1.0f;
             float dy1 = 2.0f * float(srcSubInDstRect.y + srcSubInDstRect.height) / float(dstSize.height) - 1.0f;
-            ScopedViewportRect autoViewportRect(mGL, 0, 0, dstSize.width, dstSize.height);
+            ScopedViewportRect autoViewportRect(gl, 0, 0, dstSize.width, dstSize.height);
 
             RectTriangles rects;
 
             nsIntSize realTexSize = srcSize;
-            if (!CanUploadNonPowerOfTwo(mGL)) {
+            if (!CanUploadNonPowerOfTwo(gl)) {
                 realTexSize = nsIntSize(gfx::NextPowerOfTwo(srcSize.width),
                                         gfx::NextPowerOfTwo(srcSize.height));
             }
 
             if (aSrc->GetWrapMode() == LOCAL_GL_REPEAT) {
                 rects.addRect(/* dest rectangle */
                         dx0, dy0, dx1, dy1,
                         /* tex coords */
@@ -139,131 +145,133 @@ GLBlitTextureImageHelper::BlitTextureIma
                 InfallibleTArray<RectTriangles::coord>& coords = rects.vertCoords();
 
                 for (unsigned int i = 0; i < coords.Length(); ++i) {
                     coords[i].x = (coords[i].x * (dx1 - dx0)) + dx0;
                     coords[i].y = (coords[i].y * (dy1 - dy0)) + dy0;
                 }
             }
 
-            ScopedBindTextureUnit autoTexUnit(mGL, LOCAL_GL_TEXTURE0);
-            ScopedBindTexture autoTex(mGL, aSrc->GetTextureID());
-            ScopedVertexAttribPointer autoAttrib0(mGL, 0, 2, LOCAL_GL_FLOAT, LOCAL_GL_FALSE, 0, 0, rects.vertCoords().Elements());
-            ScopedVertexAttribPointer autoAttrib1(mGL, 1, 2, LOCAL_GL_FLOAT, LOCAL_GL_FALSE, 0, 0, rects.texCoords().Elements());
+            ScopedBindTextureUnit autoTexUnit(gl, LOCAL_GL_TEXTURE0);
+            ScopedBindTexture autoTex(gl, aSrc->GetTextureID());
+            ScopedVertexAttribPointer autoAttrib0(gl, 0, 2, LOCAL_GL_FLOAT, LOCAL_GL_FALSE, 0, 0, rects.vertCoords().Elements());
+            ScopedVertexAttribPointer autoAttrib1(gl, 1, 2, LOCAL_GL_FLOAT, LOCAL_GL_FALSE, 0, 0, rects.texCoords().Elements());
 
-            mGL->fDrawArrays(LOCAL_GL_TRIANGLES, 0, rects.elements());
+            gl->fDrawArrays(LOCAL_GL_TRIANGLES, 0, rects.elements());
 
         } while (aSrc->NextTile());
     } while (aDst->NextTile());
 
     // unbind the previous texture from the framebuffer
     SetBlitFramebufferForDestTexture(0);
 
-    mGL->fBindFramebuffer(LOCAL_GL_FRAMEBUFFER, savedFb);
+    gl->fBindFramebuffer(LOCAL_GL_FRAMEBUFFER, savedFb);
 }
 
 void
 GLBlitTextureImageHelper::SetBlitFramebufferForDestTexture(GLuint aTexture)
 {
+    GLContext *gl = mCompositor->gl();
     if (!mBlitFramebuffer) {
-        mGL->fGenFramebuffers(1, &mBlitFramebuffer);
+        gl->fGenFramebuffers(1, &mBlitFramebuffer);
     }
 
-    mGL->fBindFramebuffer(LOCAL_GL_FRAMEBUFFER, mBlitFramebuffer);
-    mGL->fFramebufferTexture2D(LOCAL_GL_FRAMEBUFFER,
+    gl->fBindFramebuffer(LOCAL_GL_FRAMEBUFFER, mBlitFramebuffer);
+    gl->fFramebufferTexture2D(LOCAL_GL_FRAMEBUFFER,
                                LOCAL_GL_COLOR_ATTACHMENT0,
                                LOCAL_GL_TEXTURE_2D,
                                aTexture,
                                0);
 
-    GLenum result = mGL->fCheckFramebufferStatus(LOCAL_GL_FRAMEBUFFER);
+    GLenum result = gl->fCheckFramebufferStatus(LOCAL_GL_FRAMEBUFFER);
     if (aTexture && (result != LOCAL_GL_FRAMEBUFFER_COMPLETE)) {
         nsAutoCString msg;
         msg.AppendLiteral("Framebuffer not complete -- error 0x");
         msg.AppendInt(result, 16);
         // Note: if you are hitting this, it is likely that
         // your texture is not texture complete -- that is, you
         // allocated a texture name, but didn't actually define its
         // size via a call to TexImage2D.
         NS_RUNTIMEABORT(msg.get());
     }
 }
 
 void
 GLBlitTextureImageHelper::UseBlitProgram()
 {
+    GLContext *gl = mCompositor->gl();
     if (mBlitProgram) {
-        mGL->fUseProgram(mBlitProgram);
+        gl->fUseProgram(mBlitProgram);
         return;
     }
 
-    mBlitProgram = mGL->fCreateProgram();
+    mBlitProgram = gl->fCreateProgram();
 
     GLuint shaders[2];
-    shaders[0] = mGL->fCreateShader(LOCAL_GL_VERTEX_SHADER);
-    shaders[1] = mGL->fCreateShader(LOCAL_GL_FRAGMENT_SHADER);
+    shaders[0] = gl->fCreateShader(LOCAL_GL_VERTEX_SHADER);
+    shaders[1] = gl->fCreateShader(LOCAL_GL_FRAGMENT_SHADER);
 
     const char *blitVSSrc =
         "attribute vec2 aVertex;"
         "attribute vec2 aTexCoord;"
         "varying vec2 vTexCoord;"
         "void main() {"
         "  vTexCoord = aTexCoord;"
         "  gl_Position = vec4(aVertex, 0.0, 1.0);"
         "}";
     const char *blitFSSrc = "#ifdef GL_ES\nprecision mediump float;\n#endif\n"
         "uniform sampler2D uSrcTexture;"
         "varying vec2 vTexCoord;"
         "void main() {"
         "  gl_FragColor = texture2D(uSrcTexture, vTexCoord);"
         "}";
 
-    mGL->fShaderSource(shaders[0], 1, (const GLchar**) &blitVSSrc, nullptr);
-    mGL->fShaderSource(shaders[1], 1, (const GLchar**) &blitFSSrc, nullptr);
+    gl->fShaderSource(shaders[0], 1, (const GLchar**) &blitVSSrc, nullptr);
+    gl->fShaderSource(shaders[1], 1, (const GLchar**) &blitFSSrc, nullptr);
 
     for (int i = 0; i < 2; ++i) {
         GLint success, len = 0;
 
-        mGL->fCompileShader(shaders[i]);
-        mGL->fGetShaderiv(shaders[i], LOCAL_GL_COMPILE_STATUS, &success);
+        gl->fCompileShader(shaders[i]);
+        gl->fGetShaderiv(shaders[i], LOCAL_GL_COMPILE_STATUS, &success);
         NS_ASSERTION(success, "Shader compilation failed!");
 
         if (!success) {
             nsAutoCString log;
-            mGL->fGetShaderiv(shaders[i], LOCAL_GL_INFO_LOG_LENGTH, (GLint*) &len);
+            gl->fGetShaderiv(shaders[i], LOCAL_GL_INFO_LOG_LENGTH, (GLint*) &len);
             log.SetCapacity(len);
-            mGL->fGetShaderInfoLog(shaders[i], len, (GLint*) &len, (char*) log.BeginWriting());
+            gl->fGetShaderInfoLog(shaders[i], len, (GLint*) &len, (char*) log.BeginWriting());
             log.SetLength(len);
 
             printf_stderr("Shader %d compilation failed:\n%s\n", i, log.get());
             return;
         }
 
-        mGL->fAttachShader(mBlitProgram, shaders[i]);
-        mGL->fDeleteShader(shaders[i]);
+        gl->fAttachShader(mBlitProgram, shaders[i]);
+        gl->fDeleteShader(shaders[i]);
     }
 
-    mGL->fBindAttribLocation(mBlitProgram, 0, "aVertex");
-    mGL->fBindAttribLocation(mBlitProgram, 1, "aTexCoord");
+    gl->fBindAttribLocation(mBlitProgram, 0, "aVertex");
+    gl->fBindAttribLocation(mBlitProgram, 1, "aTexCoord");
 
-    mGL->fLinkProgram(mBlitProgram);
+    gl->fLinkProgram(mBlitProgram);
 
     GLint success, len = 0;
-    mGL->fGetProgramiv(mBlitProgram, LOCAL_GL_LINK_STATUS, &success);
+    gl->fGetProgramiv(mBlitProgram, LOCAL_GL_LINK_STATUS, &success);
     NS_ASSERTION(success, "Shader linking failed!");
 
     if (!success) {
         nsAutoCString log;
-        mGL->fGetProgramiv(mBlitProgram, LOCAL_GL_INFO_LOG_LENGTH, (GLint*) &len);
+        gl->fGetProgramiv(mBlitProgram, LOCAL_GL_INFO_LOG_LENGTH, (GLint*) &len);
         log.SetCapacity(len);
-        mGL->fGetProgramInfoLog(mBlitProgram, len, (GLint*) &len, (char*) log.BeginWriting());
+        gl->fGetProgramInfoLog(mBlitProgram, len, (GLint*) &len, (char*) log.BeginWriting());
         log.SetLength(len);
 
         printf_stderr("Program linking failed:\n%s\n", log.get());
         return;
     }
 
-    mGL->fUseProgram(mBlitProgram);
-    mGL->fUniform1i(mGL->fGetUniformLocation(mBlitProgram, "uSrcTexture"), 0);
+    gl->fUseProgram(mBlitProgram);
+    gl->fUniform1i(gl->fGetUniformLocation(mBlitProgram, "uSrcTexture"), 0);
 }
 
 }
 }
rename from gfx/gl/GLBlitTextureImageHelper.h
rename to gfx/layers/opengl/GLBlitTextureImageHelper.h
--- a/gfx/gl/GLBlitTextureImageHelper.h
+++ b/gfx/layers/opengl/GLBlitTextureImageHelper.h
@@ -10,33 +10,36 @@
 #include "mozilla/Attributes.h"
 #include "GLContextTypes.h"
 #include "GLConsts.h"
 
 struct nsIntRect;
 
 namespace mozilla {
 namespace gl {
+    class GLContext;
+    class TextureImage;
+}
+namespace layers {
 
-class GLContext;
-class TextureImage;
+class CompositorOGL;
 
 class GLBlitTextureImageHelper MOZ_FINAL
 {
     // The GLContext is the sole owner of the GLBlitTextureImageHelper.
-    GLContext* mGL;
+    CompositorOGL* mCompositor;
 
     // lazy-initialized things
     GLuint mBlitProgram, mBlitFramebuffer;
     void UseBlitProgram();
     void SetBlitFramebufferForDestTexture(GLuint aTexture);
 
 public:
 
-    explicit GLBlitTextureImageHelper(GLContext *gl);
+    explicit GLBlitTextureImageHelper(CompositorOGL *gl);
     ~GLBlitTextureImageHelper();
 
     /**
      * Copy a rectangle from one TextureImage into another.  The
      * source and destination are given in integer coordinates, and
      * will be converted to texture coordinates.
      *
      * For the source texture, the wrap modes DO apply -- it's valid
@@ -54,16 +57,16 @@ public:
      *   - viewport
      *   - blend state (will be enabled at end)
      *   - scissor state (will be enabled at end)
      *   - vertex attrib 0 and 1 (pointer and enable state [enable state will be disabled at exit])
      *   - array buffer binding (will be 0)
      *   - active texture (will be 0)
      *   - texture 0 binding
      */
-    void BlitTextureImage(TextureImage *aSrc, const nsIntRect& aSrcRect,
-                          TextureImage *aDst, const nsIntRect& aDstRect);
+    void BlitTextureImage(gl::TextureImage *aSrc, const nsIntRect& aSrcRect,
+                          gl::TextureImage *aDst, const nsIntRect& aDstRect);
 };
 
 }
 }
 
 #endif // GLBLITTEXTUREIMAGEHELPER_H_
--- a/gfx/layers/opengl/TextureHostOGL.cpp
+++ b/gfx/layers/opengl/TextureHostOGL.cpp
@@ -204,48 +204,49 @@ TextureHostOGL::WaitAcquireFenceSyncComp
 
 #endif
 
 bool
 TextureImageTextureSourceOGL::Update(gfx::DataSourceSurface* aSurface,
                                      nsIntRegion* aDestRegion,
                                      gfx::IntPoint* aSrcOffset)
 {
-  MOZ_ASSERT(mGL);
-  if (!mGL) {
+  GLContext *gl = mCompositor->gl();
+  MOZ_ASSERT(gl);
+  if (!gl) {
     NS_WARNING("trying to update TextureImageTextureSourceOGL without a GLContext");
     return false;
   }
   MOZ_ASSERT(aSurface);
 
   IntSize size = aSurface->GetSize();
   if (!mTexImage ||
       (mTexImage->GetSize() != size && !aSrcOffset) ||
       mTexImage->GetContentType() != gfx::ContentForFormat(aSurface->GetFormat())) {
     if (mFlags & TextureFlags::DISALLOW_BIGIMAGE) {
       GLint maxTextureSize;
-      mGL->fGetIntegerv(LOCAL_GL_MAX_TEXTURE_SIZE, &maxTextureSize);
+      gl->fGetIntegerv(LOCAL_GL_MAX_TEXTURE_SIZE, &maxTextureSize);
       if (size.width > maxTextureSize || size.height > maxTextureSize) {
         NS_WARNING("Texture exceeds maximum texture size, refusing upload");
         return false;
       }
       // Explicitly use CreateBasicTextureImage instead of CreateTextureImage,
       // because CreateTextureImage might still choose to create a tiled
       // texture image.
-      mTexImage = CreateBasicTextureImage(mGL, size,
+      mTexImage = CreateBasicTextureImage(gl, size,
                                           gfx::ContentForFormat(aSurface->GetFormat()),
                                           LOCAL_GL_CLAMP_TO_EDGE,
                                           FlagsToGLFlags(mFlags),
                                           SurfaceFormatToImageFormat(aSurface->GetFormat()));
     } else {
       // XXX - clarify which size we want to use. IncrementalContentHost will
       // require the size of the destination surface to be different from
       // the size of aSurface.
       // See bug 893300 (tracks the implementation of ContentHost for new textures).
-      mTexImage = CreateTextureImage(mGL,
+      mTexImage = CreateTextureImage(gl,
                                      size,
                                      gfx::ContentForFormat(aSurface->GetFormat()),
                                      LOCAL_GL_CLAMP_TO_EDGE,
                                      FlagsToGLFlags(mFlags),
                                      SurfaceFormatToImageFormat(aSurface->GetFormat()));
     }
     ClearCachedFilter();
 
@@ -270,17 +271,17 @@ TextureImageTextureSourceOGL::Update(gfx
 
 void
 TextureImageTextureSourceOGL::EnsureBuffer(const nsIntSize& aSize,
                                            gfxContentType aContentType)
 {
   if (!mTexImage ||
       mTexImage->GetSize() != aSize.ToIntSize() ||
       mTexImage->GetContentType() != aContentType) {
-    mTexImage = CreateTextureImage(mGL,
+    mTexImage = CreateTextureImage(mCompositor->gl(),
                                    aSize.ToIntSize(),
                                    aContentType,
                                    LOCAL_GL_CLAMP_TO_EDGE,
                                    FlagsToGLFlags(mFlags));
   }
   mTexImage->Resize(aSize.ToIntSize());
 }
 
@@ -289,29 +290,29 @@ TextureImageTextureSourceOGL::CopyTo(con
                                      DataTextureSource *aDest,
                                      const nsIntRect& aDestRect)
 {
   MOZ_ASSERT(aDest->AsSourceOGL(), "Incompatible destination type!");
   TextureImageTextureSourceOGL *dest =
     aDest->AsSourceOGL()->AsTextureImageTextureSource();
   MOZ_ASSERT(dest, "Incompatible destination type!");
 
-  mGL->BlitTextureImageHelper()->BlitTextureImage(mTexImage, aSourceRect,
+  mCompositor->BlitTextureImageHelper()->BlitTextureImage(mTexImage, aSourceRect,
                                                   dest->mTexImage, aDestRect);
   dest->mTexImage->MarkValid();
 }
 
 void
 TextureImageTextureSourceOGL::SetCompositor(Compositor* aCompositor)
 {
   CompositorOGL* glCompositor = static_cast<CompositorOGL*>(aCompositor);
 
-  if (!glCompositor || (mGL != glCompositor->gl())) {
+  if (!glCompositor || (mCompositor != glCompositor)) {
     DeallocateDeviceData();
-    mGL = glCompositor ? glCompositor->gl() : nullptr;
+    mCompositor = glCompositor;
   }
 }
 
 gfx::IntSize
 TextureImageTextureSourceOGL::GetSize() const
 {
   if (mTexImage) {
     if (mIterating) {
@@ -339,17 +340,17 @@ nsIntRect TextureImageTextureSourceOGL::
 }
 
 void
 TextureImageTextureSourceOGL::BindTexture(GLenum aTextureUnit, gfx::Filter aFilter)
 {
   MOZ_ASSERT(mTexImage,
     "Trying to bind a TextureSource that does not have an underlying GL texture.");
   mTexImage->BindTexture(aTextureUnit);
-  SetFilter(mGL, aFilter);
+  SetFilter(mCompositor->gl(), aFilter);
 }
 
 ////////////////////////////////////////////////////////////////////////
 // GLTextureSource
 
 GLTextureSource::GLTextureSource(CompositorOGL* aCompositor,
                                  GLuint aTextureHandle,
                                  GLenum aTarget,
--- a/gfx/layers/opengl/TextureHostOGL.h
+++ b/gfx/layers/opengl/TextureHostOGL.h
@@ -184,19 +184,19 @@ protected:
  * This TextureSource can be used without a TextureHost and manage it's own
  * GL texture(s).
  */
 class TextureImageTextureSourceOGL MOZ_FINAL : public DataTextureSource
                                              , public TextureSourceOGL
                                              , public BigImageIterator
 {
 public:
-  explicit TextureImageTextureSourceOGL(gl::GLContext* aGL,
+  explicit TextureImageTextureSourceOGL(CompositorOGL *aCompositor,
                                         TextureFlags aFlags = TextureFlags::DEFAULT)
-    : mGL(aGL)
+    : mCompositor(aCompositor)
     , mFlags(aFlags)
     , mIterating(false)
   {}
 
   // DataTextureSource
 
   virtual bool Update(gfx::DataSourceSurface* aSurface,
                       nsIntRegion* aDestRegion = nullptr,
@@ -260,17 +260,17 @@ public:
 
   virtual bool NextTile() MOZ_OVERRIDE
   {
     return mTexImage->NextTile();
   }
 
 protected:
   nsRefPtr<gl::TextureImage> mTexImage;
-  gl::GLContext* mGL;
+  RefPtr<CompositorOGL> mCompositor;
   TextureFlags mFlags;
   bool mIterating;
 };
 
 /**
  * A texture source for GL textures.
  *
  * It does not own any GL texture, and attaches its shared handle to one of