Bug 912042 - Avoid including GLContext.h in headers that don't need it - r=jrmuizel
authorBenoit Jacob <bjacob@mozilla.com>
Wed, 04 Sep 2013 08:14:52 -0400
changeset 145424 5c04fad82d85d30b88b11a72fab787b91d188d29
parent 145423 b8a27424be7fdba315c337a207ffc39af934e602
child 145425 39a388613446cdbb6b5b8256c3cfadd01248bb3c
push id33280
push userbjacob@mozilla.com
push dateWed, 04 Sep 2013 15:29:51 +0000
treeherdermozilla-inbound@36aacf27a24e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjrmuizel
bugs912042
milestone26.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 912042 - Avoid including GLContext.h in headers that don't need it - r=jrmuizel
content/canvas/src/CanvasRenderingContext2D.cpp
content/canvas/src/WebGL2Context.cpp
content/canvas/src/WebGLBuffer.cpp
content/canvas/src/WebGLContext.cpp
content/canvas/src/WebGLContext.h
content/canvas/src/WebGLContextAsyncQueries.cpp
content/canvas/src/WebGLContextBuffers.cpp
content/canvas/src/WebGLContextFramebufferOperations.cpp
content/canvas/src/WebGLContextGL.cpp
content/canvas/src/WebGLContextState.cpp
content/canvas/src/WebGLContextUtils.cpp
content/canvas/src/WebGLContextValidate.cpp
content/canvas/src/WebGLContextVertexArray.cpp
content/canvas/src/WebGLContextVertices.cpp
content/canvas/src/WebGLExtensionDrawBuffers.cpp
content/canvas/src/WebGLExtensionInstancedArrays.cpp
content/canvas/src/WebGLExtensionVertexArray.cpp
content/canvas/src/WebGLFramebuffer.cpp
content/canvas/src/WebGLProgram.cpp
content/canvas/src/WebGLProgram.h
content/canvas/src/WebGLQuery.cpp
content/canvas/src/WebGLQuery.h
content/canvas/src/WebGLRenderbuffer.cpp
content/canvas/src/WebGLShader.cpp
content/canvas/src/WebGLTexture.cpp
content/canvas/src/WebGLVertexArray.cpp
dom/ipc/TabChild.cpp
dom/plugins/base/android/ANPOpenGL.cpp
dom/plugins/base/nsNPAPIPluginInstance.cpp
dom/plugins/base/nsNPAPIPluginInstance.h
dom/plugins/base/nsPluginInstanceOwner.cpp
dom/plugins/ipc/PluginInstanceParent.cpp
dom/plugins/ipc/PluginModuleParent.h
gfx/gl/GLContext.cpp
gfx/gl/GLContext.h
gfx/gl/GLContextProvider.h
gfx/gl/GLContextProviderCGL.mm
gfx/gl/GLContextProviderEGL.cpp
gfx/gl/GLContextProviderGLX.cpp
gfx/gl/GLContextProviderImpl.h
gfx/gl/GLContextProviderNull.cpp
gfx/gl/GLContextProviderWGL.cpp
gfx/gl/GLContextTypes.h
gfx/gl/GLLibraryEGL.cpp
gfx/gl/GLLibraryEGL.h
gfx/gl/GLTypes.h
gfx/gl/GLXLibrary.h
gfx/gl/SharedSurfaceEGL.h
gfx/gl/SurfaceStream.h
gfx/gl/VBOArena.cpp
gfx/gl/VBOArena.h
gfx/gl/WGLLibrary.h
gfx/gl/moz.build
gfx/layers/SharedTextureImage.h
gfx/layers/client/TextureClient.h
gfx/layers/d3d10/CanvasLayerD3D10.cpp
gfx/layers/d3d10/CanvasLayerD3D10.h
gfx/layers/ipc/LayersSurfaces.ipdlh
gfx/layers/ipc/ShadowLayerUtils.h
gfx/layers/ipc/ShadowLayerUtilsGralloc.cpp
gfx/layers/moz.build
gfx/layers/opengl/CanvasLayerOGL.cpp
gfx/layers/opengl/CanvasLayerOGL.h
gfx/layers/opengl/CompositingRenderTargetOGL.cpp
gfx/layers/opengl/CompositingRenderTargetOGL.h
gfx/layers/opengl/CompositorOGL.cpp
gfx/layers/opengl/CompositorOGL.h
gfx/layers/opengl/ImageLayerOGL.h
gfx/layers/opengl/TextureClientOGL.cpp
gfx/layers/opengl/TextureClientOGL.h
gfx/layers/opengl/TextureHostOGL.cpp
gfx/layers/opengl/TextureHostOGL.h
gfx/layers/opengl/TexturePoolOGL.h
widget/cocoa/nsChildView.h
widget/cocoa/nsChildView.mm
widget/gonk/nsWindow.cpp
widget/gtk2/nsWindow.cpp
--- a/content/canvas/src/CanvasRenderingContext2D.cpp
+++ b/content/canvas/src/CanvasRenderingContext2D.cpp
@@ -869,17 +869,17 @@ CanvasRenderingContext2D::EnsureTarget()
 
         nsRefPtr<GLContext> glContext;
         nsCOMPtr<nsIGfxInfo> gfxInfo = do_GetService("@mozilla.org/gfx/info;1");
         nsString vendor;
 
         if (!mForceSoftware && CheckSizeForSkiaGL(size))
         {
           glContext = GLContextProvider::CreateOffscreen(gfxIntSize(size.width, size.height),
-                                                         caps, GLContext::ContextFlagsNone);
+                                                         caps, gl::ContextFlagsNone);
         }
 
         if (glContext) {
           SkAutoTUnref<GrGLInterface> i(CreateGrGLInterfaceFromGLContext(glContext));
           mTarget = Factory::CreateDrawTargetSkiaWithGLContextAndGrGLInterface(glContext, i, size, format);
           AddDemotableContext(this);
         } else {
           mTarget = layerManager->CreateDrawTarget(size, format);
--- a/content/canvas/src/WebGL2Context.cpp
+++ b/content/canvas/src/WebGL2Context.cpp
@@ -1,14 +1,15 @@
 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "WebGL2Context.h"
+#include "GLContext.h"
 #include "mozilla/dom/WebGL2RenderingContextBinding.h"
 
 #include "mozilla/Telemetry.h"
 
 using namespace mozilla;
 using namespace mozilla::gl;
 
 // -----------------------------------------------------------------------------
--- a/content/canvas/src/WebGLBuffer.cpp
+++ b/content/canvas/src/WebGLBuffer.cpp
@@ -1,15 +1,16 @@
 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "WebGLBuffer.h"
 #include "WebGLContext.h"
+#include "GLContext.h"
 #include "mozilla/dom/WebGLRenderingContextBinding.h"
 
 using namespace mozilla;
 
 WebGLBuffer::WebGLBuffer(WebGLContext *context)
     : WebGLContextBoundObject(context)
     , mHasEverBeenBound(false)
     , mByteLength(0)
--- a/content/canvas/src/WebGLContext.cpp
+++ b/content/canvas/src/WebGLContext.cpp
@@ -32,16 +32,17 @@
 #include "gfxContext.h"
 #include "gfxPattern.h"
 #include "gfxUtils.h"
 
 #include "CanvasUtils.h"
 #include "nsDisplayList.h"
 
 #include "GLContextProvider.h"
+#include "GLContext.h"
 
 #include "gfxCrashReporterUtils.h"
 
 #include "nsSVGEffects.h"
 
 #include "prenv.h"
 
 #include "mozilla/Preferences.h"
@@ -525,19 +526,19 @@ WebGLContext::SetDimensions(int32_t widt
             GenerateWarning("Error during ANGLE OpenGL ES initialization");
             return NS_ERROR_FAILURE;
         }
     }
 #endif
 
     // try the default provider, whatever that is
     if (!gl && useOpenGL) {
-        GLContext::ContextFlags flag = useMesaLlvmPipe
-                                       ? GLContext::ContextFlagsMesaLLVMPipe
-                                       : GLContext::ContextFlagsNone;
+        gl::ContextFlags flag = useMesaLlvmPipe
+                                ? gl::ContextFlagsMesaLLVMPipe
+                                : gl::ContextFlagsNone;
         gl = gl::GLContextProvider::CreateOffscreen(size, caps, flag);
         if (gl && !InitAndValidateGL()) {
             GenerateWarning("Error during %s initialization",
                             useMesaLlvmPipe ? "Mesa LLVMpipe" : "OpenGL");
             return NS_ERROR_FAILURE;
         }
     }
 
@@ -1238,17 +1239,17 @@ WebGLContext::RobustnessTimerCallback(ns
 
 void
 WebGLContext::MaybeRestoreContext()
 {
     // Don't try to handle it if we already know it's busted.
     if (mContextStatus != ContextNotLost || gl == nullptr)
         return;
 
-    bool isEGL = gl->GetContextType() == GLContext::ContextTypeEGL,
+    bool isEGL = gl->GetContextType() == gl::ContextTypeEGL,
          isANGLE = gl->IsANGLE();
 
     GLContext::ContextResetARB resetStatus = GLContext::CONTEXT_NO_ERROR;
     if (mHasRobustness) {
         gl->MakeCurrent();
         resetStatus = (GLContext::ContextResetARB) gl->fGetGraphicsResetStatus();
     } else if (isEGL) {
         // Simulate a ARB_robustness guilty context loss for when we
@@ -1306,16 +1307,19 @@ WebGLContext::ForceLoseContext()
 }
 
 void
 WebGLContext::ForceRestoreContext()
 {
     mContextStatus = ContextLostAwaitingRestore;
 }
 
+void
+WebGLContext::MakeContextCurrent() const { gl->MakeCurrent(); }
+
 //
 // XPCOM goop
 //
 
 NS_IMPL_CYCLE_COLLECTING_ADDREF(WebGLContext)
 NS_IMPL_CYCLE_COLLECTING_RELEASE(WebGLContext)
 
 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_12(WebGLContext,
--- a/content/canvas/src/WebGLContext.h
+++ b/content/canvas/src/WebGLContext.h
@@ -946,17 +946,17 @@ protected:
     bool ValidateCompressedTextureSize(GLenum target, GLint level, GLenum format, GLsizei width, GLsizei height, uint32_t byteLength, const char* info);
     bool ValidateLevelWidthHeightForTarget(GLenum target, GLint level, GLsizei width, GLsizei height, const char* info);
 
     static uint32_t GetBitsPerTexel(GLenum format, GLenum type);
 
     void Invalidate();
     void DestroyResourcesAndContext();
 
-    void MakeContextCurrent() const { gl->MakeCurrent(); }
+    void MakeContextCurrent() const;
 
     // helpers
     void TexImage2D_base(GLenum target, GLint level, GLenum internalformat,
                          GLsizei width, GLsizei height, GLsizei srcStrideOrZero, GLint border,
                          GLenum format, GLenum type,
                          void *data, uint32_t byteLength,
                          int jsArrayType,
                          WebGLTexelFormat srcFormat, bool srcPremultiplied);
--- a/content/canvas/src/WebGLContextAsyncQueries.cpp
+++ b/content/canvas/src/WebGLContextAsyncQueries.cpp
@@ -1,15 +1,16 @@
 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "WebGLContext.h"
 #include "WebGLQuery.h"
+#include "GLContext.h"
 
 using namespace mozilla;
 
 /*
  * We fake ANY_SAMPLES_PASSED and ANY_SAMPLES_PASSED_CONSERVATIVE with
  * SAMPLES_PASSED on desktop.
  *
  * OpenGL ES 3.0 spec 4.1.6
--- a/content/canvas/src/WebGLContextBuffers.cpp
+++ b/content/canvas/src/WebGLContextBuffers.cpp
@@ -1,14 +1,15 @@
 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "WebGLContext.h"
+#include "GLContext.h"
 #include "WebGLBuffer.h"
 #include "WebGLVertexArray.h"
 
 using namespace mozilla;
 using namespace mozilla::dom;
 
 void
 WebGLContext::BindBuffer(GLenum target, WebGLBuffer *buffer)
--- a/content/canvas/src/WebGLContextFramebufferOperations.cpp
+++ b/content/canvas/src/WebGLContextFramebufferOperations.cpp
@@ -2,16 +2,17 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "WebGLContext.h"
 #include "WebGLTexture.h"
 #include "WebGLRenderbuffer.h"
 #include "WebGLFramebuffer.h"
+#include "GLContext.h"
 
 using namespace mozilla;
 
 void
 WebGLContext::Clear(GLbitfield mask)
 {
     if (IsContextLost())
         return;
--- a/content/canvas/src/WebGLContextGL.cpp
+++ b/content/canvas/src/WebGLContextGL.cpp
@@ -18,16 +18,17 @@
 #include "WebGLVertexArray.h"
 
 #include "nsString.h"
 #include "nsDebug.h"
 
 #include "gfxImageSurface.h"
 #include "gfxContext.h"
 #include "gfxPlatform.h"
+#include "GLContext.h"
 
 #include "nsContentUtils.h"
 #include "nsError.h"
 #include "nsLayoutUtils.h"
 
 #include "CanvasUtils.h"
 
 #include "jsfriendapi.h"
--- a/content/canvas/src/WebGLContextState.cpp
+++ b/content/canvas/src/WebGLContextState.cpp
@@ -7,16 +7,17 @@
 #include "WebGLContextUtils.h"
 #include "WebGLBuffer.h"
 #include "WebGLShader.h"
 #include "WebGLProgram.h"
 #include "WebGLFramebuffer.h"
 #include "WebGLRenderbuffer.h"
 #include "WebGLTexture.h"
 #include "WebGLVertexArray.h"
+#include "GLContext.h"
 
 using namespace mozilla;
 using namespace dom;
 
 void
 WebGLContext::Disable(GLenum cap)
 {
     if (IsContextLost())
--- a/content/canvas/src/WebGLContextUtils.cpp
+++ b/content/canvas/src/WebGLContextUtils.cpp
@@ -1,16 +1,17 @@
 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include <stdarg.h>
 
 #include "WebGLContext.h"
+#include "GLContext.h"
 
 #include "prprf.h"
 
 #include "jsapi.h"
 #include "nsIScriptSecurityManager.h"
 #include "nsServiceManagerUtils.h"
 #include "nsIVariant.h"
 #include "nsCxPusher.h"
--- a/content/canvas/src/WebGLContextValidate.cpp
+++ b/content/canvas/src/WebGLContextValidate.cpp
@@ -8,16 +8,17 @@
 #include "WebGLVertexAttribData.h"
 #include "WebGLShader.h"
 #include "WebGLProgram.h"
 #include "WebGLUniformLocation.h"
 #include "WebGLFramebuffer.h"
 #include "WebGLRenderbuffer.h"
 #include "WebGLTexture.h"
 #include "WebGLVertexArray.h"
+#include "GLContext.h"
 
 #include "mozilla/CheckedInt.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/Services.h"
 
 #include "jsfriendapi.h"
 
 #include "angle/ShaderLang.h"
--- a/content/canvas/src/WebGLContextVertexArray.cpp
+++ b/content/canvas/src/WebGLContextVertexArray.cpp
@@ -2,16 +2,17 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "WebGLContext.h"
 #include "WebGLBuffer.h"
 #include "WebGLVertexAttribData.h"
 #include "WebGLVertexArray.h"
+#include "GLContext.h"
 
 using namespace mozilla;
 
 void
 WebGLContext::BindVertexArray(WebGLVertexArray *array)
 {
     if (IsContextLost())
         return;
--- a/content/canvas/src/WebGLContextVertices.cpp
+++ b/content/canvas/src/WebGLContextVertices.cpp
@@ -8,16 +8,17 @@
 #include "WebGLVertexAttribData.h"
 #include "WebGLVertexArray.h"
 #include "WebGLTexture.h"
 #include "WebGLRenderbuffer.h"
 #include "WebGLFramebuffer.h"
 #include "WebGLUniformInfo.h"
 #include "WebGLShader.h"
 #include "WebGLProgram.h"
+#include "GLContext.h"
 
 using namespace mozilla;
 using namespace dom;
 
 // For a Tegra workaround.
 static const int MAX_DRAW_CALLS_SINCE_FLUSH = 100;
 
 void
--- a/content/canvas/src/WebGLExtensionDrawBuffers.cpp
+++ b/content/canvas/src/WebGLExtensionDrawBuffers.cpp
@@ -3,16 +3,17 @@
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "WebGLContext.h"
 #include "WebGLExtensions.h"
 #include "mozilla/dom/WebGLRenderingContextBinding.h"
 #include "WebGLTexture.h"
 #include "WebGLRenderbuffer.h"
 #include "WebGLFramebuffer.h"
+#include "GLContext.h"
 
 #include <algorithm>
 
 using namespace mozilla;
 using namespace gl;
 
 WebGLExtensionDrawBuffers::WebGLExtensionDrawBuffers(WebGLContext* context)
     : WebGLExtensionBase(context)
--- a/content/canvas/src/WebGLExtensionInstancedArrays.cpp
+++ b/content/canvas/src/WebGLExtensionInstancedArrays.cpp
@@ -1,16 +1,17 @@
 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "WebGLContext.h"
 #include "WebGLExtensions.h"
 #include "mozilla/dom/WebGLRenderingContextBinding.h"
+#include "GLContext.h"
 
 using namespace mozilla;
 
 WebGLExtensionInstancedArrays::WebGLExtensionInstancedArrays(WebGLContext* context)
   : WebGLExtensionBase(context)
 {
     MOZ_ASSERT(IsSupported(context), "should not construct WebGLExtensionInstancedArrays: "
                                      "ANGLE_instanced_arrays unsupported.");
--- a/content/canvas/src/WebGLExtensionVertexArray.cpp
+++ b/content/canvas/src/WebGLExtensionVertexArray.cpp
@@ -3,16 +3,17 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "WebGLContext.h"
 #include "WebGLBuffer.h"
 #include "WebGLVertexArray.h"
 #include "WebGLExtensions.h"
 #include "mozilla/dom/WebGLRenderingContextBinding.h"
+#include "GLContext.h"
 
 using namespace mozilla;
 
 WebGLExtensionVertexArray::WebGLExtensionVertexArray(WebGLContext* context)
   : WebGLExtensionBase(context)
 {
     MOZ_ASSERT(IsSupported(context), "should not construct WebGLExtensionVertexArray :"
                                      "OES_vertex_array_object unsuported.");
--- a/content/canvas/src/WebGLFramebuffer.cpp
+++ b/content/canvas/src/WebGLFramebuffer.cpp
@@ -6,16 +6,17 @@
 #include "WebGLContext.h"
 #include "WebGLFramebuffer.h"
 #include "WebGLExtensions.h"
 #include "WebGLRenderbuffer.h"
 #include "WebGLTexture.h"
 #include "mozilla/dom/WebGLRenderingContextBinding.h"
 #include "WebGLTexture.h"
 #include "WebGLRenderbuffer.h"
+#include "GLContext.h"
 
 using namespace mozilla;
 
 JSObject*
 WebGLFramebuffer::WrapObject(JSContext *cx, JS::Handle<JSObject*> scope) {
     return dom::WebGLFramebufferBinding::Wrap(cx, scope, this);
 }
 
--- a/content/canvas/src/WebGLProgram.cpp
+++ b/content/canvas/src/WebGLProgram.cpp
@@ -2,16 +2,17 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "WebGLContext.h"
 #include "WebGLShader.h"
 #include "WebGLProgram.h"
 #include "mozilla/dom/WebGLRenderingContextBinding.h"
+#include "GLContext.h"
 
 using namespace mozilla;
 
 /** Takes an ASCII string like "foo[i]", turns it into "foo" and returns "[i]" in bracketPart
   * 
   * \param string input/output: the string to split, becomes the string without the bracket part
   * \param bracketPart output: gets the bracket part.
   * 
--- a/content/canvas/src/WebGLProgram.h
+++ b/content/canvas/src/WebGLProgram.h
@@ -7,16 +7,17 @@
 #define WEBGLPROGRAM_H_
 
 #include "WebGLObjectModel.h"
 
 #include "nsWrapperCache.h"
 
 #include "mozilla/LinkedList.h"
 #include "mozilla/CheckedInt.h"
+#include <map>
 
 namespace mozilla {
 
 class WebGLShader;
 class WebGLUniformInfo;
 
 typedef nsDataHashtable<nsCStringHashKey, nsCString> CStringMap;
 typedef nsDataHashtable<nsCStringHashKey, WebGLUniformInfo> CStringToUniformInfoMap;
--- a/content/canvas/src/WebGLQuery.cpp
+++ b/content/canvas/src/WebGLQuery.cpp
@@ -1,14 +1,15 @@
 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "WebGLContext.h"
+#include "GLContext.h"
 #include "WebGLQuery.h"
 #include "mozilla/dom/WebGL2RenderingContextBinding.h"
 #include "nsContentUtils.h"
 
 using namespace mozilla;
 
 JSObject*
 WebGLQuery::WrapObject(JSContext *cx, JS::Handle<JSObject*> scope) {
@@ -28,13 +29,22 @@ WebGLQuery::WebGLQuery(WebGLContext* con
 }
 
 void WebGLQuery::Delete() {
     mContext->MakeContextCurrent();
     mContext->gl->fDeleteQueries(1, &mGLName);
     LinkedListElement<WebGLQuery>::removeFrom(mContext->mQueries);
 }
 
+bool WebGLQuery::IsActive() const
+{
+    WebGLRefPtr<WebGLQuery>* targetSlot = mContext->GetQueryTargetSlot(mType, "WebGLQuery::IsActive()");
+
+    MOZ_ASSERT(targetSlot, "unknown query object's type");
+
+    return *targetSlot == this;
+}
+
 
 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_0(WebGLQuery)
 
 NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(WebGLQuery, AddRef)
 NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(WebGLQuery, Release)
--- a/content/canvas/src/WebGLQuery.h
+++ b/content/canvas/src/WebGLQuery.h
@@ -2,17 +2,16 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef WEBGLQUERY_H_
 #define WEBGLQUERY_H_
 
 #include "WebGLObjectModel.h"
-#include "WebGLContext.h"
 
 #include "nsWrapperCache.h"
 
 #include "mozilla/LinkedList.h"
 
 namespace mozilla {
 
 class WebGLQuery MOZ_FINAL
@@ -33,24 +32,17 @@ public:
     ~WebGLQuery() {
         DeleteOnce();
     };
 
 
     // -------------------------------------------------------------------------
     // MEMBER FUNCTIONS
 
-    bool IsActive() const
-    {
-        WebGLRefPtr<WebGLQuery>* targetSlot = mContext->GetQueryTargetSlot(mType, "WebGLQuery::IsActive()");
-
-        MOZ_ASSERT(targetSlot, "unknown query object's type");
-
-        return *targetSlot == this;
-    }
+    bool IsActive() const;
 
     bool HasEverBeenActive()
     {
         return mType != 0;
     }
 
 
     // -------------------------------------------------------------------------
--- a/content/canvas/src/WebGLRenderbuffer.cpp
+++ b/content/canvas/src/WebGLRenderbuffer.cpp
@@ -2,16 +2,17 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "WebGLContext.h"
 #include "WebGLRenderbuffer.h"
 #include "WebGLTexture.h"
 #include "mozilla/dom/WebGLRenderingContextBinding.h"
+#include "GLContext.h"
 
 using namespace mozilla;
 
 JSObject*
 WebGLRenderbuffer::WrapObject(JSContext *cx, JS::Handle<JSObject*> scope) {
     return dom::WebGLRenderbufferBinding::Wrap(cx, scope, this);
 }
 
--- a/content/canvas/src/WebGLShader.cpp
+++ b/content/canvas/src/WebGLShader.cpp
@@ -3,16 +3,17 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "WebGLObjectModel.h"
 #include "WebGLShader.h"
 #include "WebGLContext.h"
 #include "mozilla/MemoryReporting.h"
 #include "mozilla/dom/WebGLRenderingContextBinding.h"
+#include "GLContext.h"
 
 using namespace mozilla;
 
 JSObject*
 WebGLShader::WrapObject(JSContext *cx, JS::Handle<JSObject*> scope) {
     return dom::WebGLShaderBinding::Wrap(cx, scope, this);
 }
 
--- a/content/canvas/src/WebGLTexture.cpp
+++ b/content/canvas/src/WebGLTexture.cpp
@@ -1,15 +1,16 @@
 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "WebGLContext.h"
 #include "WebGLTexture.h"
+#include "GLContext.h"
 #include "mozilla/dom/WebGLRenderingContextBinding.h"
 #include <algorithm>
 
 using namespace mozilla;
 
 JSObject*
 WebGLTexture::WrapObject(JSContext *cx, JS::Handle<JSObject*> scope) {
     return dom::WebGLTextureBinding::Wrap(cx, scope, this);
--- a/content/canvas/src/WebGLVertexArray.cpp
+++ b/content/canvas/src/WebGLVertexArray.cpp
@@ -2,16 +2,17 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "WebGLContext.h"
 #include "WebGLBuffer.h"
 #include "WebGLVertexArray.h"
 #include "mozilla/dom/WebGLRenderingContextBinding.h"
+#include "GLContext.h"
 
 using namespace mozilla;
 
 JSObject*
 WebGLVertexArray::WrapObject(JSContext *cx, JS::Handle<JSObject*> scope) {
     return dom::WebGLVertexArrayBinding::Wrap(cx, scope, this);
 }
 
--- a/dom/ipc/TabChild.cpp
+++ b/dom/ipc/TabChild.cpp
@@ -7,16 +7,17 @@
 #include "base/basictypes.h"
 
 #include "TabChild.h"
 
 #include "Layers.h"
 #include "Blob.h"
 #include "ContentChild.h"
 #include "IndexedDBChild.h"
+#include "mozilla/Preferences.h"
 #include "mozilla/ClearOnShutdown.h"
 #include "mozilla/IntentionalCrash.h"
 #include "mozilla/docshell/OfflineCacheUpdateChild.h"
 #include "mozilla/dom/PContentChild.h"
 #include "mozilla/dom/PContentDialogChild.h"
 #include "mozilla/ipc/DocumentRendererChild.h"
 #include "mozilla/ipc/FileDescriptorUtils.h"
 #include "mozilla/layers/AsyncPanZoomController.h"
--- a/dom/plugins/base/android/ANPOpenGL.cpp
+++ b/dom/plugins/base/android/ANPOpenGL.cpp
@@ -5,16 +5,17 @@
 #include <dlfcn.h>
 #include <android/log.h>
 #include "AndroidBridge.h"
 #include "ANPBase.h"
 #include "GLContextProvider.h"
 #include "nsNPAPIPluginInstance.h"
 #include "nsPluginInstanceOwner.h"
 #include "GLContextProvider.h"
+#include "GLContext.h"
 
 #define LOG(args...)  __android_log_print(ANDROID_LOG_INFO, "GeckoPlugins" , ## args)
 #define ASSIGN(obj, name)   (obj)->name = anp_opengl_##name
 
 using namespace mozilla;
 using namespace mozilla::gl;
 
 typedef nsNPAPIPluginInstance::TextureInfo TextureInfo;
--- a/dom/plugins/base/nsNPAPIPluginInstance.cpp
+++ b/dom/plugins/base/nsNPAPIPluginInstance.cpp
@@ -45,16 +45,17 @@ using namespace mozilla;
 #include <android/log.h>
 #include "android_npapi.h"
 #include "mozilla/Mutex.h"
 #include "mozilla/CondVar.h"
 #include "AndroidBridge.h"
 #include "mozilla/dom/ScreenOrientation.h"
 #include "mozilla/Hal.h"
 #include "GLContextProvider.h"
+#include "GLContext.h"
 #include "TexturePoolOGL.h"
 
 using namespace mozilla::gl;
 
 typedef nsNPAPIPluginInstance::VideoInfo VideoInfo;
 
 class PluginEventRunnable : public nsRunnable
 {
@@ -130,19 +131,19 @@ public:
 
     if (!EnsureGLContext())
       return 0;
 
     if (mTextureInfo.mWidth == 0 || mTextureInfo.mHeight == 0)
       return 0;
 
     SharedTextureHandle handle =
-      sPluginContext->CreateSharedHandle(GLContext::SameProcess,
+      sPluginContext->CreateSharedHandle(gl::SameProcess,
                                          (void*)mTextureInfo.mTexture,
-                                         GLContext::TextureID);
+                                         gl::TextureID);
 
     // We want forget about this now, so delete the texture. Assigning it to zero
     // ensures that we create a new one in Lock()
     sPluginContext->fDeleteTextures(1, &mTextureInfo.mTexture);
     mTextureInfo.mTexture = 0;
     
     return handle;
   }
@@ -1008,19 +1009,19 @@ void* nsNPAPIPluginInstance::AcquireCont
 }
 
 SharedTextureHandle nsNPAPIPluginInstance::CreateSharedHandle()
 {
   if (mContentTexture) {
     return mContentTexture->CreateSharedHandle();
   } else if (mContentSurface) {
     EnsureGLContext();
-    return sPluginContext->CreateSharedHandle(GLContext::SameProcess,
+    return sPluginContext->CreateSharedHandle(gl::SameProcess,
                                               mContentSurface,
-                                              GLContext::SurfaceTexture);
+                                              gl::SurfaceTexture);
   } else return 0;
 }
 
 void* nsNPAPIPluginInstance::AcquireVideoWindow()
 {
   nsSurfaceTexture* surface = CreateSurfaceTexture();
   if (!surface)
     return nullptr;
--- a/dom/plugins/base/nsNPAPIPluginInstance.h
+++ b/dom/plugins/base/nsNPAPIPluginInstance.h
@@ -15,17 +15,17 @@
 #include "nsIChannel.h"
 #include "nsInterfaceHashtable.h"
 #include "nsHashKeys.h"
 #include <prinrval.h>
 #include "js/TypeDecls.h"
 #ifdef MOZ_WIDGET_ANDROID
 #include "nsAutoPtr.h"
 #include "nsIRunnable.h"
-#include "GLContext.h"
+#include "GLContextTypes.h"
 #include "nsSurfaceTexture.h"
 #include "AndroidBridge.h"
 #include <map>
 class PluginEventRunnable;
 class SharedPluginTexture;
 #endif
 
 #include "mozilla/TimeStamp.h"
--- a/dom/plugins/base/nsPluginInstanceOwner.cpp
+++ b/dom/plugins/base/nsPluginInstanceOwner.cpp
@@ -165,17 +165,17 @@ nsPluginInstanceOwner::GetImageContainer
   
   container = LayerManager::CreateImageContainer();
 
   ImageFormat format = ImageFormat::SHARED_TEXTURE;
   nsRefPtr<Image> img = container->CreateImage(&format, 1);
 
   SharedTextureImage::Data data;
   data.mHandle = mInstance->CreateSharedHandle();
-  data.mShareType = mozilla::gl::GLContext::SameProcess;
+  data.mShareType = mozilla::gl::SameProcess;
   data.mInverted = mInstance->Inverted();
 
   LayoutDeviceRect r = GetPluginRect();
   data.mSize = gfxIntSize(r.width, r.height);
 
   SharedTextureImage* pluginImage = static_cast<SharedTextureImage*>(img.get());
   pluginImage->SetData(data);
 
@@ -1676,20 +1676,20 @@ already_AddRefed<ImageContainer> nsPlugi
 {
   nsRefPtr<ImageContainer> container = LayerManager::CreateImageContainer();
 
   ImageFormat format = ImageFormat::SHARED_TEXTURE;
   nsRefPtr<Image> img = container->CreateImage(&format, 1);
 
   SharedTextureImage::Data data;
 
-  data.mShareType = gl::GLContext::SameProcess;
+  data.mShareType = gl::SameProcess;
   data.mHandle = mInstance->GLContext()->CreateSharedHandle(data.mShareType,
                                                             aVideoInfo->mSurfaceTexture,
-                                                            gl::GLContext::SurfaceTexture);
+                                                            gl::SurfaceTexture);
 
   // The logic below for Honeycomb is just a guess, but seems to work. We don't have a separate
   // inverted flag for video.
   data.mInverted = AndroidBridge::Bridge()->IsHoneycomb() ? true : mInstance->Inverted();
   data.mSize = gfxIntSize(aVideoInfo->mDimensions.width, aVideoInfo->mDimensions.height);
 
   SharedTextureImage* pluginImage = static_cast<SharedTextureImage*>(img.get());
   pluginImage->SetData(data);
--- a/dom/plugins/ipc/PluginInstanceParent.cpp
+++ b/dom/plugins/ipc/PluginInstanceParent.cpp
@@ -722,20 +722,20 @@ PluginInstanceParent::GetImageContainer(
         nsRefPtr<Image> image = container->CreateImage(&format, 1);
         if (!image) {
             return NS_ERROR_FAILURE;
         }
 
         NS_ASSERTION(image->GetFormat() == SHARED_TEXTURE, "Wrong format?");
 
         SharedTextureImage::Data data;
-        data.mShareType = GLContext::SameProcess;
+        data.mShareType = gl::SameProcess;
         data.mHandle = GLContextProviderCGL::CreateSharedHandle(data.mShareType,
                                                                 ioSurface,
-                                                                GLContext::IOSurface);
+                                                                gl::IOSurface);
         data.mInverted = false;
         // Use the device pixel size of the IOSurface, since layers handles resolution scaling
         // already.
         data.mSize = gfxIntSize(ioSurface->GetDevicePixelWidth(), ioSurface->GetDevicePixelHeight());
 
         SharedTextureImage* pluginImage = static_cast<SharedTextureImage*>(image.get());
         pluginImage->SetData(data);
 
--- a/dom/plugins/ipc/PluginModuleParent.h
+++ b/dom/plugins/ipc/PluginModuleParent.h
@@ -12,16 +12,17 @@
 #include "mozilla/PluginLibrary.h"
 #include "mozilla/plugins/PluginProcessParent.h"
 #include "mozilla/plugins/PPluginModuleParent.h"
 #include "npapi.h"
 #include "npfunctions.h"
 #include "nsAutoPtr.h"
 #include "nsDataHashtable.h"
 #include "nsHashKeys.h"
+#include "nsIObserver.h"
 
 #ifdef MOZ_CRASHREPORTER
 #include "nsExceptionHandler.h"
 #endif
 
 namespace mozilla {
 namespace dom {
 class PCrashReporterParent;
--- a/gfx/gl/GLContext.cpp
+++ b/gfx/gl/GLContext.cpp
@@ -1029,17 +1029,17 @@ GLContext::InitExtensions()
 
 #ifdef DEBUG
     static bool firstRun = true;
 #else
     // Non-DEBUG, so never spew.
     const bool firstRun = false;
 #endif
 
-    mAvailableExtensions.Load(extensions, sExtensionNames, firstRun && DebugMode());
+    InitializeExtensionsBitSet(mAvailableExtensions, extensions, sExtensionNames, firstRun && DebugMode());
 
     if (WorkAroundDriverBugs() &&
         Vendor() == VendorQualcomm) {
 
         // Some Adreno drivers do not report GL_OES_EGL_sync, but they really do support it.
         MarkExtensionSupported(OES_EGL_sync);
     }
 
--- a/gfx/gl/GLContext.h
+++ b/gfx/gl/GLContext.h
@@ -12,16 +12,17 @@
 #if defined(XP_UNIX)
 #include <stdint.h>
 #endif
 #include <string.h>
 #include <ctype.h>
 #include <set>
 #include <stack>
 #include <map>
+#include <bitset>
 
 #ifdef WIN32
 #include <windows.h>
 #endif
 
 #ifdef GetClassName
 #undef GetClassName
 #endif
@@ -113,27 +114,24 @@ namespace GLFeature {
         texture_float_linear,
         texture_non_power_of_two,
         transform_feedback,
         vertex_array_object,
         EnumMax
     };
 }
 
-typedef uintptr_t SharedTextureHandle;
-
 MOZ_BEGIN_ENUM_CLASS(ContextProfile, uint8_t)
     Unknown = 0,
     OpenGL, // only for IsAtLeast's <profile> parameter
     OpenGLCore,
     OpenGLCompatibility,
     OpenGLES
 MOZ_END_ENUM_CLASS(ContextProfile)
 
-
 class GLContext
     : public GLLibraryLoader
     , public GenericAtomicRefCounted
 {
 // -----------------------------------------------------------------------------
 // basic enums
 public:
 
@@ -153,30 +151,16 @@ public:
         RendererAdrenoTM205,
         RendererAdrenoTM320,
         RendererSGX530,
         RendererSGX540,
         RendererTegra,
         RendererOther
     };
 
-    enum ContextFlags {
-        ContextFlagsNone = 0x0,
-        ContextFlagsGlobal = 0x1,
-        ContextFlagsMesaLLVMPipe = 0x2
-    };
-
-    enum GLContextType {
-        ContextTypeUnknown,
-        ContextTypeWGL,
-        ContextTypeCGL,
-        ContextTypeGLX,
-        ContextTypeEGL
-    };
-
 
 // -----------------------------------------------------------------------------
 // basic getters
 public:
 
     /**
      * Returns true if the context is using ANGLE. This should only be overridden
      * for an ANGLE implementation.
@@ -433,76 +417,51 @@ public:
 
     void MarkExtensionSupported(GLExtensions aKnownExtension) {
         mAvailableExtensions[aKnownExtension] = 1;
     }
 
 
 public:
 
-    // this should just be a std::bitset, but that ended up breaking
-    // MacOS X builds; see bug 584919.  We can replace this with one
-    // later on.  This is handy to use in WebGL contexts as well,
-    // so making it public.
-    template<size_t Size>
-    struct ExtensionBitset
+    template<size_t N>
+    static void InitializeExtensionsBitSet(std::bitset<N>& extensionsBitset, const char* extStr, const char** extList, bool verbose = false)
     {
-        ExtensionBitset()
-        {
-            for (size_t i = 0; i < Size; ++i)
-                extensions[i] = false;
+        char* exts = strdup(extStr);
+
+        if (verbose)
+            printf_stderr("Extensions: %s\n", exts);
+
+        char* cur = exts;
+        bool done = false;
+        while (!done) {
+            char* space = strchr(cur, ' ');
+            if (space) {
+                *space = '\0';
+            } else {
+                done = true;
+            }
+
+            for (int i = 0; extList[i]; ++i) {
+                if (PL_strcasecmp(cur, extList[i]) == 0) {
+                    if (verbose)
+                        printf_stderr("Found extension %s\n", cur);
+                    extensionsBitset[i] = true;
+                }
+            }
+
+            cur = space + 1;
         }
 
-        void Load(const char* extStr, const char** extList, bool verbose = false)
-        {
-            char* exts = strdup(extStr);
-
-            if (verbose)
-                printf_stderr("Extensions: %s\n", exts);
-
-            char* cur = exts;
-            bool done = false;
-            while (!done) {
-                char* space = strchr(cur, ' ');
-                if (space) {
-                    *space = '\0';
-                } else {
-                    done = true;
-                }
-
-                for (int i = 0; extList[i]; ++i) {
-                    if (PL_strcasecmp(cur, extList[i]) == 0) {
-                        if (verbose)
-                            printf_stderr("Found extension %s\n", cur);
-                        extensions[i] = 1;
-                    }
-                }
-
-                cur = space + 1;
-            }
-
-            free(exts);
-        }
-
-        bool& operator[](size_t index) {
-            MOZ_ASSERT(index < Size, "out of range");
-            return extensions[index];
-        }
-
-        const bool& operator[](size_t index) const {
-            MOZ_ASSERT(index < Size, "out of range");
-            return extensions[index];
-        }
-
-        bool extensions[Size];
-    };
+        free(exts);
+    }
 
 
 protected:
-    ExtensionBitset<Extensions_Max> mAvailableExtensions;
+    std::bitset<Extensions_Max> mAvailableExtensions;
 
 
 // -----------------------------------------------------------------------------
 // Feature queries
 /*
  * This mecahnism introduces a new way to check if a OpenGL feature is
  * supported, regardless of whether it is supported by an extension or natively
  * by the context version/profile
@@ -511,17 +470,17 @@ public:
     bool IsSupported(GLFeature::Enum feature) const {
         return mAvailableFeatures[feature];
     }
 
     static const char* GetFeatureName(GLFeature::Enum feature);
 
 
 private:
-    ExtensionBitset<GLFeature::EnumMax> mAvailableFeatures;
+    std::bitset<GLFeature::EnumMax> mAvailableFeatures;
 
     /**
      * Init features regarding OpenGL extension and context version and profile
      */
     void InitFeatures();
 
     /**
      * Mark the feature and associated extensions as unsupported
@@ -616,16 +575,19 @@ private:
     GLenum mGLError;
 #endif // DEBUG
 
 
 // -----------------------------------------------------------------------------
 // MOZ_GL_DEBUG implementation
 private:
 
+#undef BEFORE_GL_CALL
+#undef AFTER_GL_CALL
+
 #ifdef DEBUG
 
 #ifndef MOZ_FUNCTION_NAME
 # ifdef __GNUC__
 #  define MOZ_FUNCTION_NAME __PRETTY_FUNCTION__
 # elif defined(_MSC_VER)
 #  define MOZ_FUNCTION_NAME __FUNCTION__
 # else
@@ -2586,32 +2548,16 @@ public:
 
     /*
      * Return size of this offscreen context.
      *
      * Only valid if IsOffscreen() returns true.
      */
     const gfxIntSize& OffscreenSize() const;
 
-
-    enum SharedTextureShareType {
-        SameProcess = 0,
-        CrossProcess
-    };
-
-    enum SharedTextureBufferType {
-        TextureID
-#ifdef MOZ_WIDGET_ANDROID
-        , SurfaceTexture
-#endif
-#ifdef XP_MACOSX
-        , IOSurface
-#endif
-    };
-
     /*
      * Create a new shared GLContext content handle, using the passed buffer as a source.
      * Must be released by ReleaseSharedHandle. UpdateSharedHandle will have no effect
      * on handles created with this method, as the caller owns the source (the passed buffer)
      * and is responsible for updating it accordingly.
      */
     virtual SharedTextureHandle CreateSharedHandle(SharedTextureShareType shareType,
                                                    void* buffer,
--- a/gfx/gl/GLContextProvider.h
+++ b/gfx/gl/GLContextProvider.h
@@ -1,17 +1,17 @@
 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef GLCONTEXTPROVIDER_H_
 #define GLCONTEXTPROVIDER_H_
 
-#include "GLContext.h"
+#include "GLContextTypes.h"
 #include "gfxTypes.h"
 #include "gfxPoint.h"
 #include "nsAutoPtr.h"
 #include "SurfaceTypes.h"
 
 class nsIWidget;
 class gfxASurface;
 
--- a/gfx/gl/GLContextProviderCGL.mm
+++ b/gfx/gl/GLContextProviderCGL.mm
@@ -1,14 +1,15 @@
 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "GLContextProvider.h"
+#include "GLContext.h"
 #include "nsDebug.h"
 #include "nsIWidget.h"
 #include "OpenGL/OpenGL.h"
 #include <OpenGL/gl.h>
 #include <AppKit/NSOpenGL.h>
 #include "gfxASurface.h"
 #include "gfxImageSurface.h"
 #include "gfxQuartzSurface.h"
@@ -513,33 +514,33 @@ GLContextProviderCGL::GetGlobalContext(c
 
         gGlobalContext->SetIsGlobalSharedContext(true);
     }
 
     return gGlobalContext;
 }
 
 SharedTextureHandle
-GLContextProviderCGL::CreateSharedHandle(GLContext::SharedTextureShareType shareType,
+GLContextProviderCGL::CreateSharedHandle(SharedTextureShareType shareType,
                                          void* buffer,
-                                         GLContext::SharedTextureBufferType bufferType)
+                                         SharedTextureBufferType bufferType)
 {
-    if (shareType != GLContext::SameProcess ||
-        bufferType != GLContext::IOSurface) {
+    if (shareType != SameProcess ||
+        bufferType != gl::IOSurface) {
         return 0;
     }
 
     MacIOSurface* surf = static_cast<MacIOSurface*>(buffer);
     surf->AddRef();
 
     return (SharedTextureHandle)surf;
 }
 
 already_AddRefed<gfxASurface>
-GLContextProviderCGL::GetSharedHandleAsSurface(GLContext::SharedTextureShareType shareType,
+GLContextProviderCGL::GetSharedHandleAsSurface(SharedTextureShareType shareType,
                                                SharedTextureHandle sharedHandle)
 {
   MacIOSurface* surf = reinterpret_cast<MacIOSurface*>(sharedHandle);
   surf->Lock();
   size_t bytesPerRow = surf->GetBytesPerRow();
   size_t ioWidth = surf->GetWidth();
   size_t ioHeight = surf->GetHeight();
 
--- a/gfx/gl/GLContextProviderEGL.cpp
+++ b/gfx/gl/GLContextProviderEGL.cpp
@@ -1,13 +1,14 @@
 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
+#include "GLContext.h"
 #include "mozilla/Util.h"
 // please add new includes below Qt, otherwise it break Qt build due malloc wrapper conflicts
 
 #if defined(XP_UNIX)
 
 #ifdef MOZ_WIDGET_GTK
 #include <gdk/gdkx.h>
 // we're using default display for now
@@ -731,22 +732,22 @@ protected:
             return nullptr;
         }
 
         return surface;
     }
 };
 
 
-typedef enum {
-    Image
+enum SharedHandleType {
+    SharedHandleType_Image
 #ifdef MOZ_WIDGET_ANDROID
-    , SurfaceTexture
+    , SharedHandleType_SurfaceTexture
 #endif
-} SharedHandleType;
+};
 
 class SharedTextureHandleWrapper
 {
 public:
     SharedTextureHandleWrapper(SharedHandleType aHandleType) : mHandleType(aHandleType)
     {
     }
 
@@ -760,17 +761,17 @@ public:
 };
 
 #ifdef MOZ_WIDGET_ANDROID
 
 class SurfaceTextureWrapper: public SharedTextureHandleWrapper
 {
 public:
     SurfaceTextureWrapper(nsSurfaceTexture* aSurfaceTexture) :
-        SharedTextureHandleWrapper(SharedHandleType::SurfaceTexture)
+        SharedTextureHandleWrapper(SharedHandleType_SurfaceTexture)
         , mSurfaceTexture(aSurfaceTexture)
     {
     }
 
     virtual ~SurfaceTextureWrapper() {
         mSurfaceTexture = nullptr;
     }
 
@@ -780,17 +781,17 @@ public:
 };
 
 #endif // MOZ_WIDGET_ANDROID
 
 class EGLTextureWrapper : public SharedTextureHandleWrapper
 {
 public:
     EGLTextureWrapper() :
-        SharedTextureHandleWrapper(SharedHandleType::Image)
+        SharedTextureHandleWrapper(SharedHandleType_Image)
         , mEGLImage(nullptr)
         , mSyncObject(nullptr)
     {
     }
 
     // Args are the active GL context, and a texture in that GL
     // context for which to create an EGLImage.  After the EGLImage
     // is created, the texture is unused by EGLTextureWrapper.
@@ -871,17 +872,17 @@ GLContextEGL::UpdateSharedHandle(SharedT
 {
     if (shareType != SameProcess) {
         NS_ERROR("Implementation not available for this sharing type");
         return;
     }
 
     SharedTextureHandleWrapper* wrapper = reinterpret_cast<SharedTextureHandleWrapper*>(sharedHandle);
 
-    NS_ASSERTION(wrapper->Type() == SharedHandleType::Image, "Expected EGLImage shared handle");
+    NS_ASSERTION(wrapper->Type() == SharedHandleType_Image, "Expected EGLImage shared handle");
     NS_ASSERTION(mShareWithEGLImage, "EGLImage not supported or disabled in runtime");
 
     EGLTextureWrapper* wrap = reinterpret_cast<EGLTextureWrapper*>(wrapper);
     // We need to copy the current GLContext drawing buffer to the texture
     // exported by the EGLImage.  Need to save both the read FBO and the texture
     // binding, because we're going to munge them to do this.
     ScopedBindTexture autoTex(this, mTemporaryEGLImageTexture);
     fEGLImageTargetTexture2D(LOCAL_GL_TEXTURE_2D, wrap->GetEGLImage());
@@ -945,22 +946,22 @@ void GLContextEGL::ReleaseSharedHandle(S
         NS_ERROR("Implementation not available for this sharing type");
         return;
     }
 
     SharedTextureHandleWrapper* wrapper = reinterpret_cast<SharedTextureHandleWrapper*>(sharedHandle);
 
     switch (wrapper->Type()) {
 #ifdef MOZ_WIDGET_ANDROID
-    case SharedHandleType::SurfaceTexture:
+    case SharedHandleType_SurfaceTexture:
         delete wrapper;
         break;
 #endif
     
-    case SharedHandleType::Image: {
+    case SharedHandleType_Image: {
         NS_ASSERTION(mShareWithEGLImage, "EGLImage not supported or disabled in runtime");
 
         EGLTextureWrapper* wrap = (EGLTextureWrapper*)sharedHandle;
         delete wrap;
         break;
     }
 
     default:
@@ -975,27 +976,27 @@ bool GLContextEGL::GetSharedHandleDetail
 {
     if (shareType != SameProcess)
         return false;
 
     SharedTextureHandleWrapper* wrapper = reinterpret_cast<SharedTextureHandleWrapper*>(sharedHandle);
 
     switch (wrapper->Type()) {
 #ifdef MOZ_WIDGET_ANDROID
-    case SharedHandleType::SurfaceTexture: {
+    case SharedHandleType_SurfaceTexture: {
         SurfaceTextureWrapper* surfaceWrapper = reinterpret_cast<SurfaceTextureWrapper*>(wrapper);
 
         details.mTarget = LOCAL_GL_TEXTURE_EXTERNAL;
         details.mTextureFormat = FORMAT_R8G8B8A8;
         surfaceWrapper->SurfaceTexture()->GetTransformMatrix(details.mTextureTransform);
         break;
     }
 #endif
 
-    case SharedHandleType::Image:
+    case SharedHandleType_Image:
         details.mTarget = LOCAL_GL_TEXTURE_2D;
         details.mTextureFormat = FORMAT_R8G8B8A8;
         break;
 
     default:
         NS_ERROR("Unknown shared handle type");
         return false;
     }
@@ -1008,17 +1009,17 @@ bool GLContextEGL::AttachSharedHandle(Sh
 {
     if (shareType != SameProcess)
         return false;
 
     SharedTextureHandleWrapper* wrapper = reinterpret_cast<SharedTextureHandleWrapper*>(sharedHandle);
 
     switch (wrapper->Type()) {
 #ifdef MOZ_WIDGET_ANDROID
-    case SharedHandleType::SurfaceTexture: {
+    case SharedHandleType_SurfaceTexture: {
 #ifndef DEBUG
         /**
          * NOTE: SurfaceTexture spams us if there are any existing GL errors, so we'll clear
          * them here in order to avoid that.
          */
         GetAndClearError();
 #endif
         SurfaceTextureWrapper* surfaceTextureWrapper = reinterpret_cast<SurfaceTextureWrapper*>(wrapper);
@@ -1026,17 +1027,17 @@ bool GLContextEGL::AttachSharedHandle(Sh
         // FIXME: SurfaceTexture provides a transform matrix which is supposed to
         // be applied to the texture coordinates. We should return that here
         // so we can render correctly. Bug 775083
         surfaceTextureWrapper->SurfaceTexture()->UpdateTexImage();
         break;
     }
 #endif // MOZ_WIDGET_ANDROID
 
-    case SharedHandleType::Image: {
+    case SharedHandleType_Image: {
         NS_ASSERTION(mShareWithEGLImage, "EGLImage not supported or disabled in runtime");
 
         EGLTextureWrapper* wrap = (EGLTextureWrapper*)sharedHandle;
         wrap->WaitSync();
         fEGLImageTargetTexture2D(LOCAL_GL_TEXTURE_2D, wrap->GetEGLImage());
         break;
     }
 
@@ -2007,35 +2008,35 @@ GLContextProviderEGL::CreateOffscreen(co
     glContext = GLContextEGL::CreateEGLPixmapOffscreenContext(dummySize);
 #else
     glContext = GLContextEGL::CreateEGLPBufferOffscreenContext(dummySize);
 #endif
 
     if (!glContext)
         return nullptr;
 
-    if (flags & GLContext::ContextFlagsGlobal)
+    if (flags & ContextFlagsGlobal)
         return glContext.forget();
 
     if (!glContext->InitOffscreen(size, caps))
         return nullptr;
 
     return glContext.forget();
 }
 
 SharedTextureHandle
-GLContextProviderEGL::CreateSharedHandle(GLContext::SharedTextureShareType shareType,
+GLContextProviderEGL::CreateSharedHandle(SharedTextureShareType shareType,
                                          void* buffer,
-                                         GLContext::SharedTextureBufferType bufferType)
+                                         SharedTextureBufferType bufferType)
 {
   return 0;
 }
 
 already_AddRefed<gfxASurface>
-GLContextProviderEGL::GetSharedHandleAsSurface(GLContext::SharedTextureShareType shareType,
+GLContextProviderEGL::GetSharedHandleAsSurface(SharedTextureShareType shareType,
                                                SharedTextureHandle sharedHandle)
 {
   return nullptr;
 }
 
 // Don't want a global context on Android as 1) share groups across 2 threads fail on many Tegra drivers (bug 759225)
 // and 2) some mobile devices have a very strict limit on global number of GL contexts (bug 754257)
 // and 3) each EGL context eats 750k on B2G (bug 813783)
--- a/gfx/gl/GLContextProviderGLX.cpp
+++ b/gfx/gl/GLContextProviderGLX.cpp
@@ -45,19 +45,19 @@ namespace gl {
 GLXLibrary sGLXLibrary[GLXLibrary::LIBS_MAX];
 GLXLibrary& sDefGLXLib = sGLXLibrary[GLXLibrary::OPENGL_LIB];
 
 typedef GLXLibrary::LibraryType LibType;
 
 static LibType gCurrLib = GLXLibrary::OPENGL_LIB;
 
 LibType
-GLXLibrary::SelectLibrary(const GLContext::ContextFlags& aFlags)
+GLXLibrary::SelectLibrary(const ContextFlags& aFlags)
 {
-  return (aFlags & GLContext::ContextFlagsMesaLLVMPipe)
+  return (aFlags & ContextFlagsMesaLLVMPipe)
           ? GLXLibrary::MESA_LLVMPIPE_LIB
           : GLXLibrary::OPENGL_LIB;
 }
 
 // Check that we have at least version aMajor.aMinor .
 bool 
 GLXLibrary::GLXVersionCheck(int aMajor, int aMinor)
 {
@@ -1155,17 +1155,17 @@ GLContextGLX::CreateTextureImage(const n
     fTexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_MAG_FILTER, texfilter);
     fTexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_WRAP_S, aWrapMode);
     fTexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_WRAP_T, aWrapMode);
 
     return teximage.forget();
 }
 
 static GLContextGLX *
-GetGlobalContextGLX(const GLContext::ContextFlags aFlags = GLContext::ContextFlagsNone)
+GetGlobalContextGLX(const ContextFlags aFlags = ContextFlagsNone)
 {
     return static_cast<GLContextGLX*>(GLContextProviderGLX::GetGlobalContext(aFlags));
 }
 
 static bool
 AreCompatibleVisuals(Visual *one, Visual *two)
 {
     if (one->c_class != two->c_class) {
@@ -1379,19 +1379,19 @@ CreateOffscreenPixmapContext(const gfxIn
 DONE_CREATING_PIXMAP:
 
     nsRefPtr<GLContextGLX> glContext;
     bool serverError = xErrorHandler.SyncAndGetError(display);
 
     if (!error && // earlier recorded error
         !serverError)
     {
-        GLContext::ContextFlags flag = libToUse == GLXLibrary::MESA_LLVMPIPE_LIB
-                                         ? GLContext::ContextFlagsMesaLLVMPipe
-                                         : GLContext::ContextFlagsNone;
+        ContextFlags flag = libToUse == GLXLibrary::MESA_LLVMPIPE_LIB
+                                         ? ContextFlagsMesaLLVMPipe
+                                         : ContextFlagsNone;
         // We might have an alpha channel, but it doesn't matter.
         SurfaceCaps dummyCaps = SurfaceCaps::Any();
         GLContextGLX* shareContext = GetGlobalContextGLX(flag);
 
         glContext = GLContextGLX::CreateGLContext(dummyCaps,
                                                   shareContext,
                                                   true,
                                                   display,
@@ -1422,25 +1422,25 @@ GLContextProviderGLX::CreateOffscreen(co
 
     if (!glContext->InitOffscreen(size, caps))
         return nullptr;
 
     return glContext.forget();
 }
 
 SharedTextureHandle
-GLContextProviderGLX::CreateSharedHandle(GLContext::SharedTextureShareType shareType,
+GLContextProviderGLX::CreateSharedHandle(SharedTextureShareType shareType,
                                          void* buffer,
-                                         GLContext::SharedTextureBufferType bufferType)
+                                         SharedTextureBufferType bufferType)
 {
   return 0;
 }
 
 already_AddRefed<gfxASurface>
-GLContextProviderGLX::GetSharedHandleAsSurface(GLContext::SharedTextureShareType shareType,
+GLContextProviderGLX::GetSharedHandleAsSurface(SharedTextureShareType shareType,
                                                SharedTextureHandle sharedHandle)
 {
   return nullptr;
 }
 
 static nsRefPtr<GLContext> gGlobalContext[GLXLibrary::LIBS_MAX];
 // TODO move that out of static initializaion
 static bool gUseContextSharing = getenv("MOZ_DISABLE_CONTEXT_SHARING_GLX") == 0;
--- a/gfx/gl/GLContextProviderImpl.h
+++ b/gfx/gl/GLContextProviderImpl.h
@@ -9,17 +9,16 @@
 
 #ifndef GL_CONTEXT_PROVIDER_NAME
 #error GL_CONTEXT_PROVIDER_NAME not defined
 #endif
 
 class GL_CONTEXT_PROVIDER_NAME
 {
 public:
-    typedef GLContext::ContextFlags ContextFlags;
     typedef gfx::SurfaceCaps SurfaceCaps;
     /**
      * Create a context that renders to the surface of the widget that is
      * passed in.  The context is always created with an RGB pixel format,
      * with no alpha, depth or stencil.  If any of those features are needed,
      * either use a framebuffer, or use CreateOffscreen.
      *
      * This context will attempt to share resources with all other window
@@ -56,35 +55,35 @@ public:
      * @param aSize The initial size of this offscreen context.
      * @param aFormat The ContextFormat for this offscreen context.
      *
      * @return Context to use for offscreen rendering
      */
     static already_AddRefed<GLContext>
     CreateOffscreen(const gfxIntSize& size,
                     const SurfaceCaps& caps,
-                    ContextFlags flags = GLContext::ContextFlagsNone);
+                    ContextFlags flags = ContextFlagsNone);
 
     /**
      * Get a pointer to the global context, creating it if it doesn't exist.
      */
     static GLContext*
-    GetGlobalContext(ContextFlags flags = GLContext::ContextFlagsNone);
+    GetGlobalContext(ContextFlags flags = ContextFlagsNone);
     
     /*
      * Create a new shared GLContext content handle, using the passed buffer as a source.
      * Must be released by ReleaseSharedHandle. UpdateSharedHandle will have no effect
      * on handles created with this method, as the caller owns the source (the passed buffer)
      * and is responsible for updating it accordingly.
      */
-    static SharedTextureHandle CreateSharedHandle(GLContext::SharedTextureShareType shareType,
+    static SharedTextureHandle CreateSharedHandle(SharedTextureShareType shareType,
                                                   void* buffer,
-                                                  GLContext::SharedTextureBufferType bufferType);
+                                                  SharedTextureBufferType bufferType);
 
-    static already_AddRefed<gfxASurface> GetSharedHandleAsSurface(GLContext::SharedTextureShareType shareType,
+    static already_AddRefed<gfxASurface> GetSharedHandleAsSurface(SharedTextureShareType shareType,
                                                                   SharedTextureHandle sharedHandle);
 
     /**
      * Free any resources held by this Context Provider.
      */
     static void
     Shutdown();
 };
--- a/gfx/gl/GLContextProviderNull.cpp
+++ b/gfx/gl/GLContextProviderNull.cpp
@@ -18,25 +18,25 @@ already_AddRefed<GLContext>
 GLContextProviderNull::CreateOffscreen(const gfxIntSize&,
                                        const SurfaceCaps&,
                                        ContextFlags)
 {
     return nullptr;
 }
 
 SharedTextureHandle
-GLContextProviderNull::CreateSharedHandle(GLContext::SharedTextureShareType shareType,
+GLContextProviderNull::CreateSharedHandle(SharedTextureShareType shareType,
                                           void* buffer,
-                                          GLContext::SharedTextureBufferType bufferType)
+                                          SharedTextureBufferType bufferType)
 {
   return 0;
 }
 
 already_AddRefed<gfxASurface>
-GLContextProviderNull::GetSharedHandleAsSurface(GLContext::SharedTextureShareType shareType,
+GLContextProviderNull::GetSharedHandleAsSurface(SharedTextureShareType shareType,
                                                SharedTextureHandle sharedHandle)
 {
   return nullptr;
 }
 
 GLContext*
 GLContextProviderNull::GetGlobalContext(ContextFlags)
 {
--- a/gfx/gl/GLContextProviderWGL.cpp
+++ b/gfx/gl/GLContextProviderWGL.cpp
@@ -25,19 +25,19 @@ using namespace mozilla::gfx;
 namespace mozilla {
 namespace gl {
 
 typedef WGLLibrary::LibraryType LibType;
 
 WGLLibrary sWGLLib[WGLLibrary::LIBS_MAX];
 
 LibType
-WGLLibrary::SelectLibrary(const GLContext::ContextFlags& aFlags)
+WGLLibrary::SelectLibrary(const ContextFlags& aFlags)
 {
-  return (aFlags & GLContext::ContextFlagsMesaLLVMPipe) 
+  return (aFlags & ContextFlagsMesaLLVMPipe) 
           ? WGLLibrary::MESA_LLVMPIPE_LIB
           : WGLLibrary::OPENGL_LIB;
 }
 
 HWND
 WGLLibrary::CreateDummyWindow(HDC *aWindowDC)
 {
     WNDCLASSW wc;
@@ -229,20 +229,20 @@ WGLLibrary::EnsureInitialized(bool aUseM
         if (!mWindowGLContext) {
             mHasRobustness = false;
             mWindowGLContext = fCreateContext(mWindowDC);
         }
     }
 
     mInitialized = true;
 
-    GLContext::ContextFlags flag = GLContext::ContextFlagsNone;
+    ContextFlags flag = ContextFlagsNone;
     if (aUseMesaLlvmPipe) {
       mLibType = WGLLibrary::MESA_LLVMPIPE_LIB;
-      flag = GLContext::ContextFlagsMesaLLVMPipe;
+      flag = ContextFlagsMesaLLVMPipe;
     }
 
     // Call this to create the global GLContext instance,
     // and to check for errors.  Note that this must happen /after/
     // setting mInitialized to TRUE, or an infinite loop results.
     if (GLContextProviderWGL::GetGlobalContext(flag) == nullptr) {
         mInitialized = false;
         return false;
@@ -434,17 +434,17 @@ IsValidSizeForFormat(HDC hDC, int format
 
 bool
 GLContextWGL::ResizeOffscreen(const gfxIntSize& aNewSize)
 {
     return ResizeScreenBuffer(aNewSize);
 }
 
 static GLContextWGL *
-GetGlobalContextWGL(const GLContext::ContextFlags aFlags = GLContext::ContextFlagsNone)
+GetGlobalContextWGL(const ContextFlags aFlags = ContextFlagsNone)
 {
     return static_cast<GLContextWGL*>(GLContextProviderWGL::GetGlobalContext(aFlags));
 }
 
 already_AddRefed<GLContext>
 GLContextProviderWGL::CreateForWindow(nsIWidget *aWidget)
 {
     LibType libToUse = WGLLibrary::OPENGL_LIB;
@@ -598,17 +598,17 @@ CreatePBufferOffscreenContext(const gfxI
                                                         context,
                                                         chosenFormat,
                                                         aLibToUse);
 
     return glContext.forget();
 }
 
 static already_AddRefed<GLContextWGL>
-CreateWindowOffscreenContext(GLContext::ContextFlags aFlags)
+CreateWindowOffscreenContext(ContextFlags aFlags)
 {
     // CreateWindowOffscreenContext must return a global-shared context
     GLContextWGL *shareContext = GetGlobalContextWGL(aFlags);
     if (!shareContext) {
         return nullptr;
     }
     
     LibType libToUse = WGLLibrary::SelectLibrary(aFlags);
@@ -688,25 +688,25 @@ GLContextProviderWGL::CreateOffscreen(co
 
     if (!glContext->InitOffscreen(size, caps))
         return nullptr;
 
     return glContext.forget();
 }
 
 SharedTextureHandle
-GLContextProviderWGL::CreateSharedHandle(GLContext::SharedTextureShareType shareType,
+GLContextProviderWGL::CreateSharedHandle(SharedTextureShareType shareType,
                                          void* buffer,
-                                         GLContext::SharedTextureBufferType bufferType)
+                                         SharedTextureBufferType bufferType)
 {
   return 0;
 }
 
 already_AddRefed<gfxASurface>
-GLContextProviderWGL::GetSharedHandleAsSurface(GLContext::SharedTextureShareType shareType,
+GLContextProviderWGL::GetSharedHandleAsSurface(SharedTextureShareType shareType,
                                                SharedTextureHandle sharedHandle)
 {
   return nullptr;
 }
 
 static nsRefPtr<GLContextWGL> gGlobalContext[WGLLibrary::LIBS_MAX];
 
 GLContext *
--- a/gfx/gl/GLContextTypes.h
+++ b/gfx/gl/GLContextTypes.h
@@ -1,25 +1,54 @@
 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef GLCONTEXT_TYPES_H_
 #define GLCONTEXT_TYPES_H_
 
-typedef unsigned int GLenum;
-typedef unsigned int GLbitfield;
-typedef unsigned int GLuint;
-typedef int GLint;
-typedef int GLsizei;
+#include "GLTypes.h"
 
 namespace mozilla {
 namespace gl {
 
+class GLContext;
+
+typedef uintptr_t SharedTextureHandle;
+
+enum SharedTextureShareType {
+    SameProcess = 0,
+    CrossProcess
+};
+
+enum SharedTextureBufferType {
+    TextureID
+#ifdef MOZ_WIDGET_ANDROID
+    , SurfaceTexture
+#endif
+#ifdef XP_MACOSX
+    , IOSurface
+#endif
+};
+
+enum ContextFlags {
+    ContextFlagsNone = 0x0,
+    ContextFlagsGlobal = 0x1,
+    ContextFlagsMesaLLVMPipe = 0x2
+};
+
+enum GLContextType {
+    ContextTypeUnknown,
+    ContextTypeWGL,
+    ContextTypeCGL,
+    ContextTypeGLX,
+    ContextTypeEGL
+};
+
 struct GLFormats
 {
     // Constructs a zeroed object:
     GLFormats();
 
     GLenum color_texInternalFormat;
     GLenum color_texFormat;
     GLenum color_texType;
--- a/gfx/gl/GLLibraryEGL.cpp
+++ b/gfx/gl/GLLibraryEGL.cpp
@@ -314,17 +314,17 @@ GLLibraryEGL::InitExtensions()
         debugMode = true;
 
     static bool firstRun = true;
 #else
     // Non-DEBUG, so never spew.
     const bool firstRun = false;
 #endif
 
-    mAvailableExtensions.Load(extensions, sExtensionNames, firstRun && debugMode);
+    GLContext::InitializeExtensionsBitSet(mAvailableExtensions, extensions, sExtensionNames, firstRun && debugMode);
 
 #ifdef DEBUG
     firstRun = false;
 #endif
 }
 
 void
 GLLibraryEGL::DumpEGLConfig(EGLConfig cfg)
@@ -391,11 +391,30 @@ GLLibraryEGL::DumpEGLConfigs()
     for (int i = 0; i < nc; ++i) {
         printf_stderr ("========= EGL Config %d ========\n", i);
         DumpEGLConfig(ec[i]);
     }
 
     delete [] ec;
 }
 
+#ifdef DEBUG
+/*static*/ void
+GLLibraryEGL::BeforeGLCall(const char* glFunction)
+{
+    if (GLContext::DebugMode()) {
+        if (GLContext::DebugMode() & GLContext::DebugTrace)
+            printf_stderr("[egl] > %s\n", glFunction);
+    }
+}
+
+/*static*/ void
+GLLibraryEGL::AfterGLCall(const char* glFunction)
+{
+    if (GLContext::DebugMode() & GLContext::DebugTrace) {
+        printf_stderr("[egl] < %s\n", glFunction);
+    }
+}
+#endif
+
 } /* namespace gl */
 } /* namespace mozilla */
 
--- a/gfx/gl/GLLibraryEGL.h
+++ b/gfx/gl/GLLibraryEGL.h
@@ -4,21 +4,21 @@
 
 #ifndef GLLIBRARYEGL_H_
 #define GLLIBRARYEGL_H_
 
 #if defined(MOZ_X11)
 #include "mozilla/X11Util.h"
 #endif
 
-#include "GLContext.h"
 #include "GLLibraryLoader.h"
 
 #include "nsIFile.h"
 
+#include <bitset>
 
 #if defined(XP_WIN)
 
 #ifndef WIN32_LEAN_AND_MEAN
 #define WIN32_LEAN_AND_MEAN 1
 #endif
 
 #include <windows.h>
@@ -55,46 +55,45 @@ typedef void *EGLNativeWindowType;
 #define EGL_DEFAULT_DISPLAY  ((EGLNativeDisplayType)mozilla::DefaultXDisplay())
 #else
 #define EGL_DEFAULT_DISPLAY  ((EGLNativeDisplayType)0)
 #endif
 
 namespace mozilla {
 namespace gl {
 
-#ifdef DEBUG
 #undef BEFORE_GL_CALL
 #undef AFTER_GL_CALL
 
+#ifdef DEBUG
+
+#ifndef MOZ_FUNCTION_NAME
+# ifdef __GNUC__
+#  define MOZ_FUNCTION_NAME __PRETTY_FUNCTION__
+# elif defined(_MSC_VER)
+#  define MOZ_FUNCTION_NAME __FUNCTION__
+# else
+#  define MOZ_FUNCTION_NAME __func__  // defined in C99, supported in various C++ compilers. Just raw function name.
+# endif
+#endif
+
 #define BEFORE_GL_CALL do {          \
     BeforeGLCall(MOZ_FUNCTION_NAME); \
 } while (0)
 
 #define AFTER_GL_CALL do {           \
     AfterGLCall(MOZ_FUNCTION_NAME);  \
 } while (0)
 // We rely on the fact that GLLibraryEGL.h #defines BEFORE_GL_CALL and
 // AFTER_GL_CALL to nothing if !defined(DEBUG).
+#else
+#define BEFORE_GL_CALL
+#define AFTER_GL_CALL
 #endif
 
-static inline void BeforeGLCall(const char* glFunction)
-{
-    if (GLContext::DebugMode()) {
-        if (GLContext::DebugMode() & GLContext::DebugTrace)
-            printf_stderr("[egl] > %s\n", glFunction);
-    }
-}
-
-static inline void AfterGLCall(const char* glFunction)
-{
-    if (GLContext::DebugMode() & GLContext::DebugTrace) {
-        printf_stderr("[egl] < %s\n", glFunction);
-    }
-}
-
 class GLLibraryEGL
 {
 public:
     GLLibraryEGL() 
         : mInitialized(false),
           mEGLLibrary(nullptr),
           mIsANGLE(false)
     {
@@ -121,21 +120,21 @@ public:
         Extensions_Max
     };
 
     bool IsExtensionSupported(EGLExtensions aKnownExtension) {
         return mAvailableExtensions[aKnownExtension];
     }
 
     void MarkExtensionUnsupported(EGLExtensions aKnownExtension) {
-        mAvailableExtensions[aKnownExtension] = 0;
+        mAvailableExtensions[aKnownExtension] = false;
     }
 
 protected:
-    GLContext::ExtensionBitset<Extensions_Max> mAvailableExtensions;
+    std::bitset<Extensions_Max> mAvailableExtensions;
 
 public:
 
     EGLDisplay fGetDisplay(void* display_id)
     {
         BEFORE_GL_CALL;
         EGLDisplay disp = mSymbols.fGetDisplay(display_id);
         AFTER_GL_CALL;
@@ -513,16 +512,21 @@ public:
         typedef EGLBoolean (GLAPIENTRY * pfnDestroySync)(EGLDisplay dpy, EGLSync sync);
         pfnDestroySync fDestroySync;
         typedef EGLint (GLAPIENTRY * pfnClientWaitSync)(EGLDisplay dpy, EGLSync sync, EGLint flags, EGLTime timeout);
         pfnClientWaitSync fClientWaitSync;
         typedef EGLBoolean (GLAPIENTRY * pfnGetSyncAttrib)(EGLDisplay dpy, EGLSync sync, EGLint attribute, EGLint *value);
         pfnGetSyncAttrib fGetSyncAttrib;
     } mSymbols;
 
+#ifdef DEBUG
+    static void BeforeGLCall(const char* glFunction);
+    static void AfterGLCall(const char* glFunction);
+#endif
+
 private:
     bool mInitialized;
     PRLibrary* mEGLLibrary;
     EGLDisplay mEGLDisplay;
 
     bool mIsANGLE;
 };
 
--- a/gfx/gl/GLTypes.h
+++ b/gfx/gl/GLTypes.h
@@ -1,28 +1,29 @@
 /* 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/. */
 
 #if !defined(GLTYPES_H_)
 #define GLTYPES_H_
 
+#include <stddef.h>
+#include <stdint.h>
+
+typedef int8_t realGLboolean;
+
 #if !defined(__gltypes_h_) && !defined(__gl_h_)
 #define __gltypes_h_
 #define __gl_h_
 
-#include <stddef.h>
-#include <stdint.h>
-
 typedef uint32_t GLenum;
 typedef uint32_t GLbitfield;
 typedef uint32_t GLuint;
 typedef int32_t GLint;
 typedef int32_t GLsizei;
-typedef int8_t realGLboolean;
 typedef int8_t GLbyte;
 typedef int16_t GLshort;
 typedef uint8_t GLubyte;
 typedef uint16_t GLushort;
 typedef float GLfloat;
 typedef float GLclampf;
 #ifndef GLdouble_defined
 typedef double GLdouble;
--- a/gfx/gl/GLXLibrary.h
+++ b/gfx/gl/GLXLibrary.h
@@ -1,20 +1,22 @@
 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef GFX_GLXLIBRARY_H
 #define GFX_GLXLIBRARY_H
 
-#include "GLContext.h"
+#include "GLContextTypes.h"
 typedef realGLboolean GLboolean;
 #include <GL/glx.h>
 
+struct PRLibrary;
+
 namespace mozilla {
 namespace gl {
 
 class GLXLibrary
 {
 public:
     GLXLibrary() : mInitialized(false), mTriedInitializing(false),
                    mUseTextureFromPixmap(false), mDebug(false),
@@ -94,17 +96,17 @@ public:
     void BindTexImage(GLXPixmap aPixmap);
     void ReleaseTexImage(GLXPixmap aPixmap);
 
     bool UseTextureFromPixmap() { return mUseTextureFromPixmap; }
     bool HasRobustness() { return mHasRobustness; }
     bool SupportsTextureFromPixmap(gfxASurface* aSurface);
     bool IsATI() { return mIsATI; }
     bool GLXVersionCheck(int aMajor, int aMinor);
-    static LibraryType SelectLibrary(const GLContext::ContextFlags& aFlags);
+    static LibraryType SelectLibrary(const ContextFlags& aFlags);
 
 private:
     
     typedef void (GLAPIENTRY * PFNGLXDESTROYCONTEXTPROC) (Display*,
                                                           GLXContext);
     PFNGLXDESTROYCONTEXTPROC xDestroyContextInternal;
     typedef Bool (GLAPIENTRY * PFNGLXMAKECURRENTPROC) (Display*,
                                                        GLXDrawable,
--- a/gfx/gl/SharedSurfaceEGL.h
+++ b/gfx/gl/SharedSurfaceEGL.h
@@ -12,16 +12,17 @@
 #include "SurfaceTypes.h"
 #include "mozilla/Attributes.h"
 #include "mozilla/Mutex.h"
 
 namespace mozilla {
 namespace gl {
 
 class GLContext;
+class TextureGarbageBin;
 
 class SharedSurface_EGLImage
     : public SharedSurface_GL
 {
 public:
     static SharedSurface_EGLImage* Create(GLContext* prodGL,
                                                   const GLFormats& formats,
                                                   const gfxIntSize& size,
--- a/gfx/gl/SurfaceStream.h
+++ b/gfx/gl/SurfaceStream.h
@@ -7,19 +7,23 @@
 #define SURFACESTREAM_H_
 
 #include <stack>
 #include <set>
 #include "mozilla/Monitor.h"
 #include "mozilla/Attributes.h"
 #include "gfxPoint.h"
 #include "SurfaceTypes.h"
-#include "GLContext.h"
 
 namespace mozilla {
+
+namespace gl {
+class GLContext;
+}
+
 namespace gfx {
 class SharedSurface;
 class SurfaceFactory;
 
 // Owned by: ScreenBuffer
 class SurfaceStream
 {
 public:
--- a/gfx/gl/VBOArena.cpp
+++ b/gfx/gl/VBOArena.cpp
@@ -1,14 +1,15 @@
 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "VBOArena.h"
+#include "GLContext.h"
 
 using namespace mozilla::gl;
 
 GLuint VBOArena::Allocate(GLContext *aGLContext)
 {
     if (!mAvailableVBOs.size()) {
         GLuint vbo;
         aGLContext->fGenBuffers(1, &vbo);
--- a/gfx/gl/VBOArena.h
+++ b/gfx/gl/VBOArena.h
@@ -1,22 +1,24 @@
 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef VBOARENA_H_
 #define VBOARENA_H_
 
-#include "GLContext.h"
+#include "GLTypes.h"
 #include <vector>
 
 namespace mozilla {
 namespace gl {
 
+class GLContext;
+
 class VBOArena {
 public:
     // Allocate a new VBO.
     GLuint Allocate(GLContext *aGLContext);
 
     // Re-use previously allocated VBOs.
     void Reset();
 
--- a/gfx/gl/WGLLibrary.h
+++ b/gfx/gl/WGLLibrary.h
@@ -1,14 +1,15 @@
 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
-#include "GLContext.h"
+#include "GLContextTypes.h"
+struct PRLibrary;
 
 namespace mozilla {
 namespace gl {
 
 class WGLLibrary
 {
 public:
     WGLLibrary() 
@@ -74,17 +75,17 @@ public:
     bool HasRobustness() const { return mHasRobustness; }
     bool IsInitialized() const { return mInitialized; }
     HWND GetWindow() const { return mWindow; }
     HDC GetWindowDC() const {return mWindowDC; }
     HGLRC GetWindowGLContext() const {return mWindowGLContext; }
     int GetWindowPixelFormat() const { return mWindowPixelFormat; }
     bool UseDoubleBufferedWindows() const { return mUseDoubleBufferedWindows; }
     LibraryType GetLibraryType() const { return mLibType; }
-    static LibraryType SelectLibrary(const GLContext::ContextFlags& aFlags);
+    static LibraryType SelectLibrary(const ContextFlags& aFlags);
     
 private:
     bool mInitialized;
     PRLibrary *mOGLLibrary;
     bool mHasRobustness;
 
     HWND mWindow;
     HDC mWindowDC;
--- a/gfx/gl/moz.build
+++ b/gfx/gl/moz.build
@@ -56,17 +56,16 @@ if CONFIG['MOZ_X11']:
 # Win32 is a special snowflake, for ANGLE
 if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'windows':
     EXPORTS += [
         'SharedSurfaceANGLE.h',
         'WGLLibrary.h',
     ]
     CPP_SOURCES += [
         'GLContextProviderEGL.cpp',
-        'GLLibraryEGL.cpp',
         'SharedSurfaceANGLE.cpp',
     ]
 if CONFIG['MOZ_ENABLE_SKIA_GPU']:
     EXPORTS += ['GLContextSkia.h']
     CPP_SOURCES += [
         'GLContextSkia.cpp',
     ]
 
@@ -84,30 +83,26 @@ if gl_provider == 'CGL':
     CPP_SOURCES += [
         'SharedSurfaceIO.cpp',
     ]
 else:
     CPP_SOURCES += [
         'GLContextProvider%s.cpp' % gl_provider,
     ]
 
-if gl_provider == 'EGL':
-    CPP_SOURCES += [
-        'GLLibraryEGL.cpp',
-    ]
-
 CPP_SOURCES += [
     'GLContext.cpp',
     'GLContextFeatures.cpp',
     'GLContextTypes.cpp',
     'GLContextUtils.cpp',
     'GLLibraryLoader.cpp',
     'GLScreenBuffer.cpp',
     'GLTextureImage.cpp',
     'SharedSurface.cpp',
+    'GLLibraryEGL.cpp',
     'SharedSurfaceEGL.cpp',
     'SharedSurfaceGL.cpp',
     'SurfaceFactory.cpp',
     'SurfaceStream.cpp',
     'VBOArena.cpp',
 ]
 
 FAIL_ON_WARNINGS = True
--- a/gfx/layers/SharedTextureImage.h
+++ b/gfx/layers/SharedTextureImage.h
@@ -22,17 +22,17 @@ class gfxASurface;
 namespace mozilla {
 
 namespace layers {
 
 class SharedTextureImage : public Image {
 public:
   struct Data {
     gl::SharedTextureHandle mHandle;
-    gl::GLContext::SharedTextureShareType mShareType;
+    gl::SharedTextureShareType mShareType;
     gfxIntSize mSize;
     bool mInverted;
   };
 
   void SetData(const Data& aData) { mData = aData; }
   const Data* GetData() { return &mData; }
 
   gfxIntSize GetSize() { return mData.mSize; }
--- a/gfx/layers/client/TextureClient.h
+++ b/gfx/layers/client/TextureClient.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_TEXTURECLIENT_H
 #define MOZILLA_GFX_TEXTURECLIENT_H
 
 #include <stddef.h>                     // for size_t
 #include <stdint.h>                     // for uint32_t, uint8_t, uint64_t
-#include "GLContext.h"                  // for GLContext (ptr only), etc
+#include "GLContextTypes.h"             // for GLContext (ptr only), etc
 #include "GLTextureImage.h"             // for TextureImage
 #include "ImageContainer.h"             // for PlanarYCbCrImage, etc
 #include "ImageTypes.h"                 // for StereoMode
 #include "gfxASurface.h"                // for gfxASurface, etc
 #include "gfxImageSurface.h"            // for gfxImageSurface
 #include "mozilla/Assertions.h"         // for MOZ_ASSERT, etc
 #include "mozilla/Attributes.h"         // for MOZ_OVERRIDE
 #include "mozilla/RefPtr.h"             // for RefPtr, RefCounted
--- a/gfx/layers/d3d10/CanvasLayerD3D10.cpp
+++ b/gfx/layers/d3d10/CanvasLayerD3D10.cpp
@@ -7,23 +7,35 @@
 
 #include "../d3d9/Nv3DVUtils.h"
 #include "gfxImageSurface.h"
 #include "gfxWindowsSurface.h"
 #include "gfxWindowsPlatform.h"
 #include "SurfaceStream.h"
 #include "SharedSurfaceANGLE.h"
 #include "gfxContext.h"
+#include "GLContext.h"
 
 using namespace mozilla::gl;
 using namespace mozilla::gfx;
 
 namespace mozilla {
 namespace layers {
 
+CanvasLayerD3D10::CanvasLayerD3D10(LayerManagerD3D10 *aManager)
+  : CanvasLayer(aManager, nullptr)
+  , LayerD3D10(aManager)
+  , mDataIsPremultiplied(false)
+  , mNeedsYFlip(false)
+  , mHasAlpha(true)
+{
+    mImplData = static_cast<LayerD3D10*>(this);
+    mForceReadback = Preferences::GetBool("webgl.force-layers-readback", false);
+}
+
 CanvasLayerD3D10::~CanvasLayerD3D10()
 {
 }
 
 void
 CanvasLayerD3D10::Initialize(const Data& aData)
 {
   NS_ASSERTION(mSurface == nullptr, "BasicCanvasLayer::Initialize called twice!");
--- a/gfx/layers/d3d10/CanvasLayerD3D10.h
+++ b/gfx/layers/d3d10/CanvasLayerD3D10.h
@@ -2,39 +2,33 @@
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef GFX_CANVASLAYERD3D10_H
 #define GFX_CANVASLAYERD3D10_H
 
 #include "LayerManagerD3D10.h"
-#include "GLContext.h"
 #include "gfxASurface.h"
 
 #include "mozilla/Preferences.h"
 
 namespace mozilla {
+
+namespace gl {
+class GLContext;
+}
+
 namespace layers {
 
 class CanvasLayerD3D10 : public CanvasLayer,
                          public LayerD3D10
 {
 public:
-  CanvasLayerD3D10(LayerManagerD3D10 *aManager)
-    : CanvasLayer(aManager, nullptr)
-    , LayerD3D10(aManager)
-    , mDataIsPremultiplied(false)
-    , mNeedsYFlip(false)
-    , mHasAlpha(true)
-  {
-      mImplData = static_cast<LayerD3D10*>(this);
-      mForceReadback = Preferences::GetBool("webgl.force-layers-readback", false);
-  }
-
+  CanvasLayerD3D10(LayerManagerD3D10 *aManager);
   ~CanvasLayerD3D10();
 
   // CanvasLayer implementation
   virtual void Initialize(const Data& aData);
 
   // LayerD3D10 implementation
   virtual Layer* GetLayer();
   virtual void RenderLayer();
--- a/gfx/layers/ipc/LayersSurfaces.ipdlh
+++ b/gfx/layers/ipc/LayersSurfaces.ipdlh
@@ -1,16 +1,17 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 include protocol PGrallocBuffer;
 
 include "gfxipc/ShadowLayerUtils.h";
 include "mozilla/gfx/Types.h";
+include "nsRegion.h";
 
 using gfx3DMatrix;
 using gfxIntSize;
 using gfxPoint;
 using gfxRGBA;
 using nsIntPoint;
 using nsIntRect;
 using nsIntRegion;
@@ -18,17 +19,17 @@ using nsIntSize;
 using mozilla::gfxContentType;
 using mozilla::GraphicsFilterType;
 using mozilla::layers::FrameMetrics;
 using mozilla::layers::MagicGrallocBufferHandle;
 using mozilla::layers::SurfaceDescriptorX11;
 using mozilla::null_t;
 using mozilla::WindowsHandle;
 using mozilla::gl::SharedTextureHandle;
-using mozilla::gl::GLContext::SharedTextureShareType;
+using mozilla::gl::SharedTextureShareType;
 using mozilla::gfx::SurfaceStreamHandle;
 using mozilla::gfx::SurfaceFormat;
 using mozilla::gfx::IntSize;
 
 namespace mozilla {
 namespace layers {
 
 union MaybeMagicGrallocBufferHandle {
--- a/gfx/layers/ipc/ShadowLayerUtils.h
+++ b/gfx/layers/ipc/ShadowLayerUtils.h
@@ -4,17 +4,18 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef IPC_ShadowLayerUtils_h
 #define IPC_ShadowLayerUtils_h
 
 #include "ipc/IPCMessageUtils.h"
-#include "GLContext.h"
+#include "GLContextTypes.h"
+#include "SurfaceTypes.h"
 #include "mozilla/WidgetUtils.h"
 
 #if defined(MOZ_ENABLE_D3D10_LAYER)
 # include "mozilla/layers/ShadowLayerUtilsD3D10.h"
 #endif
 
 #if defined(XP_MACOSX)
 #define MOZ_HAVE_PLATFORM_SPECIFIC_LAYER_BUFFERS
@@ -47,19 +48,19 @@ template <>
 struct ParamTraits<mozilla::layers::SurfaceDescriptorX11> {
   typedef mozilla::layers::SurfaceDescriptorX11 paramType;
   static void Write(Message*, const paramType&) {}
   static bool Read(const Message*, void**, paramType*) { return false; }
 };
 #endif  // !defined(MOZ_HAVE_XSURFACEDESCRIPTORX11)
 
 template<>
-struct ParamTraits<mozilla::gl::GLContext::SharedTextureShareType>
+struct ParamTraits<mozilla::gl::SharedTextureShareType>
 {
-  typedef mozilla::gl::GLContext::SharedTextureShareType paramType;
+  typedef mozilla::gl::SharedTextureShareType paramType;
 
   static void Write(Message* msg, const paramType& param)
   {
     static_assert(sizeof(paramType) <= sizeof(int32_t),
                   "TextureShareType assumes to be int32_t");
     WriteParam(msg, int32_t(param));
   }
 
--- a/gfx/layers/ipc/ShadowLayerUtilsGralloc.cpp
+++ b/gfx/layers/ipc/ShadowLayerUtilsGralloc.cpp
@@ -17,16 +17,17 @@
 #include "nsXULAppAPI.h"
 
 #include "ShadowLayerUtilsGralloc.h"
 
 #include "nsIMemoryReporter.h"
 
 #include "gfxImageSurface.h"
 #include "gfxPlatform.h"
+#include "GLContext.h"
 
 #include "GeckoProfiler.h"
 
 #include "cutils/properties.h"
 
 using namespace android;
 using namespace base;
 using namespace mozilla::layers;
--- a/gfx/layers/moz.build
+++ b/gfx/layers/moz.build
@@ -204,16 +204,17 @@ CPP_SOURCES += [
     'ClientLayerManager.cpp',
     'ClientThebesLayer.cpp',
     'ClientTiledThebesLayer.cpp',
     'ColorLayerComposite.cpp',
     'ColorLayerOGL.cpp',
     'CompositableClient.cpp',
     'CompositableHost.cpp',
     'CompositableTransactionParent.cpp',
+    'CompositingRenderTargetOGL.cpp',
     'Compositor.cpp',
     'CompositorChild.cpp',
     'CompositorCocoaWidgetHelper.cpp',
     'CompositorOGL.cpp',
     'CompositorParent.cpp',
     'ContainerLayerComposite.cpp',
     'ContainerLayerOGL.cpp',
     'ContentClient.cpp',
--- a/gfx/layers/opengl/CanvasLayerOGL.cpp
+++ b/gfx/layers/opengl/CanvasLayerOGL.cpp
@@ -1,14 +1,15 @@
 /* -*- 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 "CanvasLayerOGL.h"
+#include "GLContext.h"                  // for GLContext
 #include "GLScreenBuffer.h"             // for GLScreenBuffer
 #include "SharedSurface.h"              // for SharedSurface
 #include "SharedSurfaceGL.h"            // for SharedSurface_Basic, etc
 #include "SurfaceStream.h"              // for SurfaceStream, etc
 #include "SurfaceTypes.h"               // for SharedSurfaceType, etc
 #include "gfx3DMatrix.h"                // for gfx3DMatrix
 #include "gfxImageSurface.h"            // for gfxImageSurface
 #include "gfxPlatform.h"                // for gfxPlatform
--- a/gfx/layers/opengl/CanvasLayerOGL.h
+++ b/gfx/layers/opengl/CanvasLayerOGL.h
@@ -1,19 +1,18 @@
 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef GFX_CANVASLAYEROGL_H
 #define GFX_CANVASLAYEROGL_H
 
-#include "GLContext.h"                  // for GLContext
-#include "GLContextTypes.h"             // for GLuint, GLenum
-#include "GLDefs.h"                     // for LOCAL_GL_TEXTURE_2D
+#include "GLContextTypes.h"             // for GLContext
+#include "GLDefs.h"                     // for GLuint, LOCAL_GL_TEXTURE_2D
 #include "LayerManagerOGL.h"            // for LayerOGL::GLContext, etc
 #include "Layers.h"                     // for CanvasLayer, etc
 #include "gfxASurface.h"                // for gfxASurface, etc
 #include "gfxImageSurface.h"            // for gfxImageSurface
 #include "gfxPoint.h"                   // for gfxIntSize
 #include "mozilla/Preferences.h"        // for Preferences
 #include "mozilla/RefPtr.h"             // for RefPtr
 #include "mozilla/gfx/2D.h"             // for DrawTarget
new file mode 100644
--- /dev/null
+++ b/gfx/layers/opengl/CompositingRenderTargetOGL.cpp
@@ -0,0 +1,87 @@
+/* -*- 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 "CompositingRenderTargetOGL.h"
+#include "GLContext.h"
+
+using namespace mozilla;
+using namespace mozilla::layers;
+
+CompositingRenderTargetOGL::~CompositingRenderTargetOGL()
+{
+  mGL->fDeleteTextures(1, &mTextureHandle);
+  mGL->fDeleteFramebuffers(1, &mFBO);
+}
+
+void
+CompositingRenderTargetOGL::BindTexture(GLenum aTextureUnit, GLenum aTextureTarget)
+{
+  MOZ_ASSERT(mInitParams.mStatus == InitParams::INITIALIZED);
+  MOZ_ASSERT(mTextureHandle != 0);
+  mGL->fActiveTexture(aTextureUnit);
+  mGL->fBindTexture(aTextureTarget, mTextureHandle);
+}
+
+void
+CompositingRenderTargetOGL::BindRenderTarget()
+{
+  if (mInitParams.mStatus != InitParams::INITIALIZED) {
+    InitializeImpl();
+  } else {
+    MOZ_ASSERT(mInitParams.mStatus == InitParams::INITIALIZED);
+    mGL->fBindFramebuffer(LOCAL_GL_FRAMEBUFFER, mFBO);
+    GLenum result = mGL->fCheckFramebufferStatus(LOCAL_GL_FRAMEBUFFER);
+    if (result != LOCAL_GL_FRAMEBUFFER_COMPLETE) {
+      nsAutoCString msg;
+      msg.AppendPrintf("Framebuffer not complete -- error 0x%x, aFBOTextureTarget 0x%x, aRect.width %d, aRect.height %d",
+                        result, mInitParams.mFBOTextureTarget, mInitParams.mSize.width, mInitParams.mSize.height);
+      NS_WARNING(msg.get());
+    }
+
+    mCompositor->PrepareViewport(mInitParams.mSize, mTransform);
+  }
+}
+
+#ifdef MOZ_DUMP_PAINTING
+already_AddRefed<gfxImageSurface>
+CompositingRenderTargetOGL::Dump(Compositor* aCompositor)
+{
+  MOZ_ASSERT(mInitParams.mStatus == InitParams::INITIALIZED);
+  CompositorOGL* compositorOGL = static_cast<CompositorOGL*>(aCompositor);
+  return mGL->GetTexImage(mTextureHandle, true, compositorOGL->GetFBOFormat());
+}
+#endif
+
+void
+CompositingRenderTargetOGL::InitializeImpl()
+{
+  MOZ_ASSERT(mInitParams.mStatus == InitParams::READY);
+
+  mGL->fBindFramebuffer(LOCAL_GL_FRAMEBUFFER, mFBO);
+  mGL->fFramebufferTexture2D(LOCAL_GL_FRAMEBUFFER,
+                              LOCAL_GL_COLOR_ATTACHMENT0,
+                              mInitParams.mFBOTextureTarget,
+                              mTextureHandle,
+                              0);
+
+  // Making this call to fCheckFramebufferStatus prevents a crash on
+  // PowerVR. See bug 695246.
+  GLenum result = mGL->fCheckFramebufferStatus(LOCAL_GL_FRAMEBUFFER);
+  if (result != LOCAL_GL_FRAMEBUFFER_COMPLETE) {
+    nsAutoCString msg;
+    msg.AppendPrintf("Framebuffer not complete -- error 0x%x, aFBOTextureTarget 0x%x, mFBO %d, mTextureHandle %d, aRect.width %d, aRect.height %d",
+                      result, mInitParams.mFBOTextureTarget, mFBO, mTextureHandle, mInitParams.mSize.width, mInitParams.mSize.height);
+    NS_ERROR(msg.get());
+  }
+
+  mCompositor->PrepareViewport(mInitParams.mSize, mTransform);
+  mGL->fScissor(0, 0, mInitParams.mSize.width, mInitParams.mSize.height);
+  if (mInitParams.mInit == INIT_MODE_CLEAR) {
+    mGL->fClearColor(0.0, 0.0, 0.0, 0.0);
+    mGL->fClear(LOCAL_GL_COLOR_BUFFER_BIT);
+  }
+
+  mInitParams.mStatus = InitParams::INITIALIZED;
+}
--- a/gfx/layers/opengl/CompositingRenderTargetOGL.h
+++ b/gfx/layers/opengl/CompositingRenderTargetOGL.h
@@ -2,19 +2,18 @@
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef MOZILLA_GFX_COMPOSITINGRENDERTARGETOGL_H
 #define MOZILLA_GFX_COMPOSITINGRENDERTARGETOGL_H
 
 #include "mozilla-config.h"             // for MOZ_DUMP_PAINTING
-#include "GLContext.h"                  // for GLContext
-#include "GLContextTypes.h"             // for GLenum, GLuint
-#include "GLDefs.h"                     // for LOCAL_GL_FRAMEBUFFER, etc
+#include "GLContextTypes.h"             // for GLContext
+#include "GLDefs.h"                     // for GLenum, LOCAL_GL_FRAMEBUFFER, etc
 #include "gfxMatrix.h"                  // for gfxMatrix
 #include "mozilla/Assertions.h"         // for MOZ_ASSERT, etc
 #include "mozilla/Attributes.h"         // for MOZ_OVERRIDE
 #include "mozilla/RefPtr.h"             // for RefPtr, TemporaryRef
 #include "mozilla/gfx/Point.h"          // for IntSize, IntSizeTyped
 #include "mozilla/gfx/Types.h"          // for SurfaceFormat, etc
 #include "mozilla/layers/Compositor.h"  // for SurfaceInitMode, etc
 #include "mozilla/layers/TextureHost.h" // for CompositingRenderTarget
@@ -68,21 +67,17 @@ public:
     : mInitParams()
     , mTransform()
     , mCompositor(aCompositor)
     , mGL(aCompositor->gl())
     , mTextureHandle(aTexure)
     , mFBO(aFBO)
   {}
 
-  ~CompositingRenderTargetOGL()
-  {
-    mGL->fDeleteTextures(1, &mTextureHandle);
-    mGL->fDeleteFramebuffers(1, &mFBO);
-  }
+  ~CompositingRenderTargetOGL();
 
   /**
    * Create a render target around the default FBO, for rendering straight to
    * the window.
    */
   static TemporaryRef<CompositingRenderTargetOGL>
   RenderTargetForWindow(CompositorOGL* aCompositor,
                         const gfx::IntSize& aSize,
@@ -106,45 +101,22 @@ public:
                   GLenum aFBOTextureTarget,
                   SurfaceInitMode aInit)
   {
     MOZ_ASSERT(mInitParams.mStatus == InitParams::NO_PARAMS, "Initialized twice?");
     // postpone initialization until we actually want to use this render target
     mInitParams = InitParams(aSize, aFBOTextureTarget, aInit);
   }
 
-  void BindTexture(GLenum aTextureUnit, GLenum aTextureTarget)
-  {
-    MOZ_ASSERT(mInitParams.mStatus == InitParams::INITIALIZED);
-    MOZ_ASSERT(mTextureHandle != 0);
-    mGL->fActiveTexture(aTextureUnit);
-    mGL->fBindTexture(aTextureTarget, mTextureHandle);
-  }
+  void BindTexture(GLenum aTextureUnit, GLenum aTextureTarget);
 
   /**
    * Call when we want to draw into our FBO
    */
-  void BindRenderTarget()
-  {
-    if (mInitParams.mStatus != InitParams::INITIALIZED) {
-      InitializeImpl();
-    } else {
-      MOZ_ASSERT(mInitParams.mStatus == InitParams::INITIALIZED);
-      mGL->fBindFramebuffer(LOCAL_GL_FRAMEBUFFER, mFBO);
-      GLenum result = mGL->fCheckFramebufferStatus(LOCAL_GL_FRAMEBUFFER);
-      if (result != LOCAL_GL_FRAMEBUFFER_COMPLETE) {
-        nsAutoCString msg;
-        msg.AppendPrintf("Framebuffer not complete -- error 0x%x, aFBOTextureTarget 0x%x, aRect.width %d, aRect.height %d",
-                         result, mInitParams.mFBOTextureTarget, mInitParams.mSize.width, mInitParams.mSize.height);
-        NS_WARNING(msg.get());
-      }
-
-      mCompositor->PrepareViewport(mInitParams.mSize, mTransform);
-    }
-  }
+  void BindRenderTarget();
 
   GLuint GetFBO() const
   {
     MOZ_ASSERT(mInitParams.mStatus == InitParams::INITIALIZED);
     return mFBO;
   }
 
   GLuint GetTextureHandle() const
@@ -174,59 +146,25 @@ public:
     return gfx::FORMAT_UNKNOWN;
   }
 
   const gfxMatrix& GetTransform() {
     return mTransform;
   }
 
 #ifdef MOZ_DUMP_PAINTING
-  virtual already_AddRefed<gfxImageSurface> Dump(Compositor* aCompositor)
-  {
-    MOZ_ASSERT(mInitParams.mStatus == InitParams::INITIALIZED);
-    CompositorOGL* compositorOGL = static_cast<CompositorOGL*>(aCompositor);
-    return mGL->GetTexImage(mTextureHandle, true, compositorOGL->GetFBOFormat());
-  }
+  virtual already_AddRefed<gfxImageSurface> Dump(Compositor* aCompositor);
 #endif
 
 private:
   /**
    * Actually do the initialisation. Note that we leave our FBO bound, and so
    * calling this method is only suitable when about to use this render target.
    */
-  void InitializeImpl()
-  {
-    MOZ_ASSERT(mInitParams.mStatus == InitParams::READY);
-
-    mGL->fBindFramebuffer(LOCAL_GL_FRAMEBUFFER, mFBO);
-    mGL->fFramebufferTexture2D(LOCAL_GL_FRAMEBUFFER,
-                               LOCAL_GL_COLOR_ATTACHMENT0,
-                               mInitParams.mFBOTextureTarget,
-                               mTextureHandle,
-                               0);
-
-    // Making this call to fCheckFramebufferStatus prevents a crash on
-    // PowerVR. See bug 695246.
-    GLenum result = mGL->fCheckFramebufferStatus(LOCAL_GL_FRAMEBUFFER);
-    if (result != LOCAL_GL_FRAMEBUFFER_COMPLETE) {
-      nsAutoCString msg;
-      msg.AppendPrintf("Framebuffer not complete -- error 0x%x, aFBOTextureTarget 0x%x, mFBO %d, mTextureHandle %d, aRect.width %d, aRect.height %d",
-                       result, mInitParams.mFBOTextureTarget, mFBO, mTextureHandle, mInitParams.mSize.width, mInitParams.mSize.height);
-      NS_ERROR(msg.get());
-    }
-
-    mCompositor->PrepareViewport(mInitParams.mSize, mTransform);
-    mGL->fScissor(0, 0, mInitParams.mSize.width, mInitParams.mSize.height);
-    if (mInitParams.mInit == INIT_MODE_CLEAR) {
-      mGL->fClearColor(0.0, 0.0, 0.0, 0.0);
-      mGL->fClear(LOCAL_GL_COLOR_BUFFER_BIT);
-    }
-
-    mInitParams.mStatus = InitParams::INITIALIZED;
-  }
+  void InitializeImpl();
 
   InitParams mInitParams;
   gfxMatrix mTransform;
   CompositorOGL* mCompositor;
   GLContext* mGL;
   GLuint mTextureHandle;
   GLuint mFBO;
 };
--- a/gfx/layers/opengl/CompositorOGL.cpp
+++ b/gfx/layers/opengl/CompositorOGL.cpp
@@ -4,16 +4,17 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "CompositorOGL.h"
 #include <stddef.h>                     // for size_t
 #include <stdint.h>                     // for uint32_t, uint8_t
 #include <stdlib.h>                     // for free, malloc
 #include "FPSCounter.h"                 // for FPSState, FPSCounter
 #include "GLContextProvider.h"          // for GLContextProvider
+#include "GLContext.h"                  // for GLContext
 #include "LayerManagerOGL.h"            // for BUFFER_OFFSET
 #include "Layers.h"                     // for WriteSnapshotToDumpFile
 #include "gfx2DGlue.h"                  // for ThebesFilter
 #include "gfx3DMatrix.h"                // for gfx3DMatrix
 #include "gfxASurface.h"                // for gfxASurface, etc
 #include "gfxCrashReporterUtils.h"      // for ScopedGfxFeatureReporter
 #include "gfxImageSurface.h"            // for gfxImageSurface
 #include "gfxMatrix.h"                  // for gfxMatrix
@@ -1441,10 +1442,99 @@ TemporaryRef<DataTextureSource>
 CompositorOGL::CreateDataTextureSource(TextureFlags aFlags)
 {
   RefPtr<DataTextureSource> result =
     new TextureImageTextureSourceOGL(mGLContext,
                                      !(aFlags & TEXTURE_DISALLOW_BIGIMAGE));
   return result;
 }
 
+bool
+CompositorOGL::SupportsPartialTextureUpdate()
+{
+  return mGLContext->CanUploadSubTextures();
+}
+
+int32_t
+CompositorOGL::GetMaxTextureSize() const
+{
+  MOZ_ASSERT(mGLContext);
+  GLint texSize = 0;
+  mGLContext->fGetIntegerv(LOCAL_GL_MAX_TEXTURE_SIZE,
+                            &texSize);
+  MOZ_ASSERT(texSize != 0);
+  return texSize;
+}
+
+void
+CompositorOGL::MakeCurrent(MakeCurrentFlags aFlags) {
+  if (mDestroyed) {
+    NS_WARNING("Call on destroyed layer manager");
+    return;
+  }
+  mGLContext->MakeCurrent(aFlags & ForceMakeCurrent);
+}
+
+void
+CompositorOGL::BindQuadVBO() {
+  mGLContext->fBindBuffer(LOCAL_GL_ARRAY_BUFFER, mQuadVBO);
+}
+
+void
+CompositorOGL::QuadVBOVerticesAttrib(GLuint aAttribIndex) {
+  mGLContext->fVertexAttribPointer(aAttribIndex, 2,
+                                    LOCAL_GL_FLOAT, LOCAL_GL_FALSE, 0,
+                                    (GLvoid*) QuadVBOVertexOffset());
+}
+
+void
+CompositorOGL::QuadVBOTexCoordsAttrib(GLuint aAttribIndex) {
+  mGLContext->fVertexAttribPointer(aAttribIndex, 2,
+                                    LOCAL_GL_FLOAT, LOCAL_GL_FALSE, 0,
+                                    (GLvoid*) QuadVBOTexCoordOffset());
+}
+
+void
+CompositorOGL::QuadVBOFlippedTexCoordsAttrib(GLuint aAttribIndex) {
+  mGLContext->fVertexAttribPointer(aAttribIndex, 2,
+                                    LOCAL_GL_FLOAT, LOCAL_GL_FALSE, 0,
+                                    (GLvoid*) QuadVBOFlippedTexCoordOffset());
+}
+
+void
+CompositorOGL::BindAndDrawQuad(GLuint aVertAttribIndex,
+                               GLuint aTexCoordAttribIndex,
+                               bool aFlipped)
+{
+  BindQuadVBO();
+  QuadVBOVerticesAttrib(aVertAttribIndex);
+
+  if (aTexCoordAttribIndex != GLuint(-1)) {
+    if (aFlipped)
+      QuadVBOFlippedTexCoordsAttrib(aTexCoordAttribIndex);
+    else
+      QuadVBOTexCoordsAttrib(aTexCoordAttribIndex);
+
+    mGLContext->fEnableVertexAttribArray(aTexCoordAttribIndex);
+  }
+
+  mGLContext->fEnableVertexAttribArray(aVertAttribIndex);
+  mGLContext->fDrawArrays(LOCAL_GL_TRIANGLE_STRIP, 0, 4);
+  mGLContext->fDisableVertexAttribArray(aVertAttribIndex);
+
+  if (aTexCoordAttribIndex != GLuint(-1)) {
+    mGLContext->fDisableVertexAttribArray(aTexCoordAttribIndex);
+  }
+}
+
+void
+CompositorOGL::BindAndDrawQuad(ShaderProgramOGL *aProg,
+                               bool aFlipped)
+{
+  NS_ASSERTION(aProg->HasInitialized(), "Shader program not correctly initialized");
+  BindAndDrawQuad(aProg->AttribLocation(ShaderProgramOGL::VertexCoordAttrib),
+                  aProg->AttribLocation(ShaderProgramOGL::TexCoordAttrib),
+                  aFlipped);
+}
+
+
 } /* layers */
 } /* mozilla */
--- a/gfx/layers/opengl/CompositorOGL.h
+++ b/gfx/layers/opengl/CompositorOGL.h
@@ -2,19 +2,18 @@
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef MOZILLA_GFX_COMPOSITOROGL_H
 #define MOZILLA_GFX_COMPOSITOROGL_H
 
 #include "./../mozilla-config.h"        // for MOZ_DUMP_PAINTING
-#include "GLContext.h"                  // for GLContext
-#include "GLContextTypes.h"             // for GLuint, GLenum, GLint
-#include "GLDefs.h"                     // for GLintptr, GLvoid, etc
+#include "GLContextTypes.h"             // for GLContext, etc
+#include "GLDefs.h"                     // for GLuint, LOCAL_GL_TEXTURE_2D, etc
 #include "LayerManagerOGLProgram.h"     // for ShaderProgramOGL, etc
 #include "Units.h"                      // for ScreenPoint
 #include "gfxContext.h"                 // for gfxContext
 #include "gfxPoint.h"                   // for gfxIntSize
 #include "mozilla/Assertions.h"         // for MOZ_ASSERT, etc
 #include "mozilla/Attributes.h"         // for MOZ_OVERRIDE, MOZ_FINAL
 #include "mozilla/RefPtr.h"             // for TemporaryRef, RefPtr
 #include "mozilla/gfx/BaseSize.h"       // for BaseSize
@@ -101,56 +100,39 @@ public:
                         const EffectChain &aEffectChain,
                         gfx::Float aOpacity, const gfx::Matrix4x4 &aTransform,
                         const gfx::Point& aOffset) MOZ_OVERRIDE;
 
   virtual void EndFrame() MOZ_OVERRIDE;
   virtual void EndFrameForExternalComposition(const gfxMatrix& aTransform) MOZ_OVERRIDE;
   virtual void AbortFrame() MOZ_OVERRIDE;
 
-  virtual bool SupportsPartialTextureUpdate() MOZ_OVERRIDE
-  {
-    return mGLContext->CanUploadSubTextures();
-  }
+  virtual bool SupportsPartialTextureUpdate() MOZ_OVERRIDE;
 
   virtual bool CanUseCanvasLayerForSize(const gfxIntSize &aSize) MOZ_OVERRIDE
   {
     if (!mGLContext)
       return false;
     int32_t maxSize = GetMaxTextureSize();
     return aSize <= gfxIntSize(maxSize, maxSize);
   }
 
-  virtual int32_t GetMaxTextureSize() const MOZ_OVERRIDE
-  {
-    MOZ_ASSERT(mGLContext);
-    GLint texSize = 0;
-    mGLContext->fGetIntegerv(LOCAL_GL_MAX_TEXTURE_SIZE,
-                             &texSize);
-    MOZ_ASSERT(texSize != 0);
-    return texSize;
-  }
+  virtual int32_t GetMaxTextureSize() const MOZ_OVERRIDE;
 
   /**
    * Set the size of the EGL surface we're rendering to, if we're rendering to
    * an EGL surface.
    */
   virtual void SetDestinationSurfaceSize(const gfx::IntSize& aSize) MOZ_OVERRIDE;
 
   virtual void SetScreenRenderOffset(const ScreenPoint& aOffset) MOZ_OVERRIDE {
     mRenderOffset = aOffset;
   }
 
-  virtual void MakeCurrent(MakeCurrentFlags aFlags = 0) MOZ_OVERRIDE {
-    if (mDestroyed) {
-      NS_WARNING("Call on destroyed layer manager");
-      return;
-    }
-    mGLContext->MakeCurrent(aFlags & ForceMakeCurrent);
-  }
+  virtual void MakeCurrent(MakeCurrentFlags aFlags = 0) MOZ_OVERRIDE;
 
   virtual void SetTargetContext(gfxContext* aTarget) MOZ_OVERRIDE
   {
     mTarget = aTarget;
   }
 
   virtual void PrepareViewport(const gfx::IntSize& aSize,
                                const gfxMatrix& aWorldTransform) MOZ_OVERRIDE;
@@ -295,72 +277,25 @@ private:
   void CreateFBOWithTexture(const gfx::IntRect& aRect, SurfaceInitMode aInit,
                             GLuint aSourceFrameBuffer,
                             GLuint *aFBO, GLuint *aTexture);
 
   GLintptr QuadVBOVertexOffset() { return 0; }
   GLintptr QuadVBOTexCoordOffset() { return sizeof(float)*4*2; }
   GLintptr QuadVBOFlippedTexCoordOffset() { return sizeof(float)*8*2; }
 
-  void BindQuadVBO() {
-    mGLContext->fBindBuffer(LOCAL_GL_ARRAY_BUFFER, mQuadVBO);
-  }
-
-  void QuadVBOVerticesAttrib(GLuint aAttribIndex) {
-    mGLContext->fVertexAttribPointer(aAttribIndex, 2,
-                                     LOCAL_GL_FLOAT, LOCAL_GL_FALSE, 0,
-                                     (GLvoid*) QuadVBOVertexOffset());
-  }
-
-  void QuadVBOTexCoordsAttrib(GLuint aAttribIndex) {
-    mGLContext->fVertexAttribPointer(aAttribIndex, 2,
-                                     LOCAL_GL_FLOAT, LOCAL_GL_FALSE, 0,
-                                     (GLvoid*) QuadVBOTexCoordOffset());
-  }
-
-  void QuadVBOFlippedTexCoordsAttrib(GLuint aAttribIndex) {
-    mGLContext->fVertexAttribPointer(aAttribIndex, 2,
-                                     LOCAL_GL_FLOAT, LOCAL_GL_FALSE, 0,
-                                     (GLvoid*) QuadVBOFlippedTexCoordOffset());
-  }
-
+  void BindQuadVBO();
+  void QuadVBOVerticesAttrib(GLuint aAttribIndex);
+  void QuadVBOTexCoordsAttrib(GLuint aAttribIndex);
+  void QuadVBOFlippedTexCoordsAttrib(GLuint aAttribIndex);
   void BindAndDrawQuad(GLuint aVertAttribIndex,
                        GLuint aTexCoordAttribIndex,
-                       bool aFlipped = false)
-  {
-    BindQuadVBO();
-    QuadVBOVerticesAttrib(aVertAttribIndex);
-
-    if (aTexCoordAttribIndex != GLuint(-1)) {
-      if (aFlipped)
-        QuadVBOFlippedTexCoordsAttrib(aTexCoordAttribIndex);
-      else
-        QuadVBOTexCoordsAttrib(aTexCoordAttribIndex);
-
-      mGLContext->fEnableVertexAttribArray(aTexCoordAttribIndex);
-    }
-
-    mGLContext->fEnableVertexAttribArray(aVertAttribIndex);
-    mGLContext->fDrawArrays(LOCAL_GL_TRIANGLE_STRIP, 0, 4);
-    mGLContext->fDisableVertexAttribArray(aVertAttribIndex);
-
-    if (aTexCoordAttribIndex != GLuint(-1)) {
-      mGLContext->fDisableVertexAttribArray(aTexCoordAttribIndex);
-    }
-  }
-
+                       bool aFlipped = false);
   void BindAndDrawQuad(ShaderProgramOGL *aProg,
-                       bool aFlipped = false)
-  {
-    NS_ASSERTION(aProg->HasInitialized(), "Shader program not correctly initialized");
-    BindAndDrawQuad(aProg->AttribLocation(ShaderProgramOGL::VertexCoordAttrib),
-                    aProg->AttribLocation(ShaderProgramOGL::TexCoordAttrib),
-                    aFlipped);
-  }
-
+                       bool aFlipped = false);
   void BindAndDrawQuadWithTextureRect(ShaderProgramOGL *aProg,
                                       const gfx::Rect& aTexCoordRect,
                                       TextureSource *aTexture);
 
   void CleanupResources();
 
   /**
    * Copies the content of our backbuffer to the set transaction target.
--- a/gfx/layers/opengl/ImageLayerOGL.h
+++ b/gfx/layers/opengl/ImageLayerOGL.h
@@ -1,18 +1,17 @@
 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef GFX_IMAGELAYEROGL_H
 #define GFX_IMAGELAYEROGL_H
 
-#include "GLContext.h"                  // for GLContext
-#include "GLContextTypes.h"             // for GLuint
+#include "GLContextTypes.h"             // for GLContext, GLuint
 #include "ImageContainer.h"             // for ImageBackendData, etc
 #include "ImageLayers.h"                // for ImageLayer
 #include "LayerManagerOGL.h"            // for LayerOGL
 #include "gfxPoint.h"                   // for gfxIntSize
 #include "mozilla/Assertions.h"         // for MOZ_ASSERT_HELPER2
 #include "mozilla/Mutex.h"              // for Mutex
 #include "mozilla/mozalloc.h"           // for operator delete
 #include "nsAutoPtr.h"                  // for nsRefPtr
--- a/gfx/layers/opengl/TextureClientOGL.cpp
+++ b/gfx/layers/opengl/TextureClientOGL.cpp
@@ -40,17 +40,17 @@ SharedTextureClientOGL::ToSurfaceDescrip
   nsIntSize nsSize(mSize.width, mSize.height);
   aOutDescriptor = SharedTextureDescriptor(mShareType, mHandle, nsSize, mInverted);
   return true;
 }
 
 void
 SharedTextureClientOGL::InitWith(gl::SharedTextureHandle aHandle,
                                  gfx::IntSize aSize,
-                                 gl::GLContext::SharedTextureShareType aShareType,
+                                 gl::SharedTextureShareType aShareType,
                                  bool aInverted)
 {
   MOZ_ASSERT(!IsAllocated());
   mHandle = aHandle;
   mSize = aSize;
   mShareType = aShareType;
   mInverted = aInverted;
 }
--- a/gfx/layers/opengl/TextureClientOGL.h
+++ b/gfx/layers/opengl/TextureClientOGL.h
@@ -1,17 +1,17 @@
 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
 //  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef MOZILLA_GFX_TEXTURECLIENTOGL_H
 #define MOZILLA_GFX_TEXTURECLIENTOGL_H
 
-#include "GLContext.h"                  // for SharedTextureHandle, etc
+#include "GLContextTypes.h"             // for SharedTextureHandle, etc
 #include "gfxASurface.h"                // for gfxASurface, etc
 #include "mozilla/Attributes.h"         // for MOZ_OVERRIDE
 #include "mozilla/gfx/Point.h"          // for IntSize
 #include "mozilla/layers/CompositorTypes.h"
 #include "mozilla/layers/LayersSurfaces.h"  // for SurfaceDescriptor
 #include "mozilla/layers/TextureClient.h"  // for DeprecatedTextureClient, etc
 
 namespace mozilla {
@@ -31,25 +31,25 @@ public:
   ~SharedTextureClientOGL();
 
   virtual bool IsAllocated() const MOZ_OVERRIDE;
 
   virtual bool ToSurfaceDescriptor(SurfaceDescriptor& aOutDescriptor) MOZ_OVERRIDE;
 
   void InitWith(gl::SharedTextureHandle aHandle,
                 gfx::IntSize aSize,
-                gl::GLContext::SharedTextureShareType aShareType,
+                gl::SharedTextureShareType aShareType,
                 bool aInverted = false);
 
   virtual gfx::IntSize GetSize() const { return mSize; }
 
 protected:
   gl::SharedTextureHandle mHandle;
   gfx::IntSize mSize;
-  gl::GLContext::SharedTextureShareType mShareType;
+  gl::SharedTextureShareType mShareType;
   bool mInverted;
 };
 
 
 class DeprecatedTextureClientSharedOGL : public DeprecatedTextureClient
 {
 public:
   DeprecatedTextureClientSharedOGL(CompositableForwarder* aForwarder, const TextureInfo& aTextureInfo);
--- a/gfx/layers/opengl/TextureHostOGL.cpp
+++ b/gfx/layers/opengl/TextureHostOGL.cpp
@@ -287,17 +287,17 @@ SharedTextureSourceOGL::IsValid() const
 gl::GLContext*
 SharedTextureSourceOGL::gl() const
 {
   return mCompositor ? mCompositor->gl() : nullptr;
 }
 
 SharedTextureHostOGL::SharedTextureHostOGL(uint64_t aID,
                                            TextureFlags aFlags,
-                                           gl::GLContext::SharedTextureShareType aShareType,
+                                           gl::SharedTextureShareType aShareType,
                                            gl::SharedTextureHandle aSharedHandle,
                                            gfx::IntSize aSize,
                                            bool inverted)
   : TextureHost(aID, aFlags)
   , mSize(aSize)
   , mCompositor(nullptr)
   , mSharedHandle(aSharedHandle)
   , mShareType(aShareType)
@@ -736,16 +736,24 @@ SurfaceStreamHostOGL::Lock()
                       LOCAL_GL_TEXTURE_WRAP_S,
                       LOCAL_GL_CLAMP_TO_EDGE);
   mGL->fTexParameteri(mTextureTarget,
                       LOCAL_GL_TEXTURE_WRAP_T,
                       LOCAL_GL_CLAMP_TO_EDGE);
   return true;
 }
 
+void
+SurfaceStreamHostOGL::BindTexture(GLenum activetex)
+{
+  MOZ_ASSERT(mGL);
+  mGL->fActiveTexture(activetex);
+  mGL->fBindTexture(mTextureTarget, mTextureHandle);
+}
+
 
 void
 YCbCrDeprecatedTextureHostOGL::SetCompositor(Compositor* aCompositor)
 {
   CompositorOGL* glCompositor = static_cast<CompositorOGL*>(aCompositor);
   GLContext* newGL = glCompositor ? glCompositor->gl() : nullptr;
   if (mGL != newGL) {
     mGL = newGL;
@@ -821,16 +829,23 @@ YCbCrDeprecatedTextureHostOGL::Lock()
 }
 
 
 TiledDeprecatedTextureHostOGL::~TiledDeprecatedTextureHostOGL()
 {
   DeleteTextures();
 }
 
+void
+TiledDeprecatedTextureHostOGL::BindTexture(GLenum aTextureUnit)
+{
+  mGL->fActiveTexture(aTextureUnit);
+  mGL->fBindTexture(LOCAL_GL_TEXTURE_2D, mTextureHandle);
+}
+
 static void
 GetFormatAndTileForImageFormat(gfxASurface::gfxImageFormat aFormat,
                                GLenum& aOutFormat,
                                GLenum& aOutType)
 {
   if (aFormat == gfxASurface::ImageFormatRGB16_565) {
     aOutFormat = LOCAL_GL_RGB;
     aOutType = LOCAL_GL_UNSIGNED_SHORT_5_6_5;
--- a/gfx/layers/opengl/TextureHostOGL.h
+++ b/gfx/layers/opengl/TextureHostOGL.h
@@ -3,19 +3,18 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef MOZILLA_GFX_TEXTUREOGL_H
 #define MOZILLA_GFX_TEXTUREOGL_H
 
 #include <stddef.h>                     // for size_t
 #include <stdint.h>                     // for uint64_t
-#include "GLContext.h"                  // for GLContext, etc
-#include "GLContextTypes.h"             // for GLenum, GLuint
-#include "GLDefs.h"                     // for LOCAL_GL_CLAMP_TO_EDGE, etc
+#include "GLContextTypes.h"             // for GLContext
+#include "GLDefs.h"                     // for GLenum, LOCAL_GL_CLAMP_TO_EDGE, etc
 #include "GLTextureImage.h"             // for TextureImage
 #include "gfx3DMatrix.h"                // for gfx3DMatrix
 #include "gfxASurface.h"                // for gfxASurface, etc
 #include "mozilla/GfxMessageUtils.h"    // for gfxContentType
 #include "mozilla/Assertions.h"         // for MOZ_ASSERT, etc
 #include "mozilla/Attributes.h"         // for MOZ_OVERRIDE
 #include "mozilla/RefPtr.h"             // for RefPtr
 #include "mozilla/gfx/Point.h"          // for IntSize, IntPoint
@@ -214,17 +213,17 @@ protected:
  * the compositor's temporary textures when binding.
  *
  * The shared texture handle is owned by the TextureHost.
  */
 class SharedTextureSourceOGL : public NewTextureSource
                              , public TextureSourceOGL
 {
 public:
-  typedef gl::GLContext::SharedTextureShareType SharedTextureShareType;
+  typedef gl::SharedTextureShareType SharedTextureShareType;
 
   SharedTextureSourceOGL(CompositorOGL* aCompositor,
                          gl::SharedTextureHandle aHandle,
                          gfx::SurfaceFormat aFormat,
                          GLenum aTarget,
                          GLenum aWrapMode,
                          SharedTextureShareType aShareType,
                          gfx::IntSize aSize,
@@ -273,17 +272,17 @@ protected:
  *
  * Most of the logic actually happens in SharedTextureSourceOGL.
  */
 class SharedTextureHostOGL : public TextureHost
 {
 public:
   SharedTextureHostOGL(uint64_t aID,
                        TextureFlags aFlags,
-                       gl::GLContext::SharedTextureShareType aShareType,
+                       gl::SharedTextureShareType aShareType,
                        gl::SharedTextureHandle aSharedhandle,
                        gfx::IntSize aSize,
                        bool inverted);
 
   virtual ~SharedTextureHostOGL();
 
   // SharedTextureHostOGL doesn't own any GL texture
   virtual void DeallocateDeviceData() MOZ_OVERRIDE {}
@@ -313,17 +312,17 @@ public:
 #ifdef MOZ_LAYERS_HAVE_LOG
   virtual const char* Name() { return "SharedTextureHostOGL"; }
 #endif
 
 protected:
   gfx::IntSize mSize;
   CompositorOGL* mCompositor;
   gl::SharedTextureHandle mSharedHandle;
-  gl::GLContext::SharedTextureShareType mShareType;
+  gl::SharedTextureShareType mShareType;
 
   RefPtr<SharedTextureSourceOGL> mTextureSource;
 };
 
 /**
  * DeprecatedTextureHost implementation using a TextureImage as the underlying texture.
  */
 class TextureImageDeprecatedTextureHostOGL : public DeprecatedTextureHost
@@ -576,17 +575,17 @@ public:
   typedef mozilla::gl::GLContext GLContext;
   typedef mozilla::gl::TextureImage TextureImage;
 
   SharedDeprecatedTextureHostOGL()
     : mGL(nullptr)
     , mTextureHandle(0)
     , mWrapMode(LOCAL_GL_CLAMP_TO_EDGE)
     , mSharedHandle(0)
-    , mShareType(GLContext::SameProcess)
+    , mShareType(gl::SameProcess)
   {}
 
   virtual void SetCompositor(Compositor* aCompositor) MOZ_OVERRIDE;
 
   virtual ~SharedDeprecatedTextureHostOGL()
   {
     if (mSharedHandle || mTextureHandle) {
       DeleteTextures();
@@ -656,17 +655,17 @@ protected:
   void DeleteTextures();
 
   gfx::IntSize mSize;
   nsRefPtr<gl::GLContext> mGL;
   GLuint mTextureHandle;
   GLenum mWrapMode;
   GLenum mTextureTarget;
   gl::SharedTextureHandle mSharedHandle;
-  gl::GLContext::SharedTextureShareType mShareType;
+  gl::SharedTextureShareType mShareType;
 };
 
 class SurfaceStreamHostOGL : public DeprecatedTextureHost
                            , public TextureSourceOGL
 {
 public:
   typedef gfxASurface::gfxContentType ContentType;
   typedef mozilla::gl::GLContext GLContext;
@@ -711,21 +710,17 @@ public:
     return mSize;
   }
 
   virtual GLenum GetTextureTarget() const MOZ_OVERRIDE
   {
     return mTextureTarget;
   }
 
-  void BindTexture(GLenum activetex) MOZ_OVERRIDE {
-    MOZ_ASSERT(mGL);
-    mGL->fActiveTexture(activetex);
-    mGL->fBindTexture(mTextureTarget, mTextureHandle);
-  }
+  void BindTexture(GLenum activetex) MOZ_OVERRIDE;
 
   void UnbindTexture() MOZ_OVERRIDE {}
 
   GLuint GetTextureID() { return mTextureHandle; }
   ContentType GetContentType() {
     return (mFormat == gfx::FORMAT_B8G8R8A8) ?
              gfxASurface::CONTENT_COLOR_ALPHA :
              gfxASurface::CONTENT_COLOR;
@@ -779,21 +774,17 @@ public:
   virtual gfx::SurfaceFormat GetFormat() const MOZ_OVERRIDE
   {
     return DeprecatedTextureHost::GetFormat();
   }
 
   virtual TextureSourceOGL* AsSourceOGL() MOZ_OVERRIDE { return this; }
   virtual bool IsValid() const MOZ_OVERRIDE { return true; }
   virtual GLenum GetWrapMode() const MOZ_OVERRIDE { return LOCAL_GL_CLAMP_TO_EDGE; }
-  virtual void BindTexture(GLenum aTextureUnit) MOZ_OVERRIDE
-  {
-    mGL->fActiveTexture(aTextureUnit);
-    mGL->fBindTexture(LOCAL_GL_TEXTURE_2D, mTextureHandle);
-  }
+  virtual void BindTexture(GLenum aTextureUnit);
   virtual void UnbindTexture() MOZ_OVERRIDE {}
   virtual gfx::IntSize GetSize() const MOZ_OVERRIDE
   {
     return mSize;
   }
 
   virtual void SwapTexturesImpl(const SurfaceDescriptor& aImage,
                                 nsIntRegion* aRegion = nullptr)
--- a/gfx/layers/opengl/TexturePoolOGL.h
+++ b/gfx/layers/opengl/TexturePoolOGL.h
@@ -1,22 +1,20 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef GFX_TEXTUREPOOLOGL_H
 #define GFX_TEXTUREPOOLOGL_H
 
-#include "GLContextTypes.h"             // for GLuint
+#include "GLContextTypes.h"             // for GLContext, GLuint
 
 namespace mozilla {
 namespace gl {
 
-class GLContext;
-
 // A texture pool for for the on-screen GLContext. The main purpose of this class
 // is to provide the ability to easily allocate an on-screen texture from the
 // content thread. The unfortunate nature of the SurfaceTexture API (see nsSurfaceTexture)
 // necessitates this.
 class TexturePoolOGL
 {
 public:
   // Get a new texture from the pool. Will block
--- a/widget/cocoa/nsChildView.h
+++ b/widget/cocoa/nsChildView.h
@@ -17,17 +17,19 @@
 #include "nsISupports.h"
 #include "nsBaseWidget.h"
 #include "nsIPluginInstanceOwner.h"
 #include "nsIPluginWidget.h"
 #include "nsWeakPtr.h"
 #include "TextInputHandler.h"
 #include "nsCocoaUtils.h"
 #include "gfxQuartzSurface.h"
-#include "GLContext.h"
+#include "GLContextTypes.h"
+#include "mozilla/Mutex.h"
+#include "nsRegion.h"
 
 #include "nsString.h"
 #include "nsIDragService.h"
 
 #include "npapi.h"
 
 #import <Carbon/Carbon.h>
 #import <Cocoa/Cocoa.h>
--- a/widget/cocoa/nsChildView.mm
+++ b/widget/cocoa/nsChildView.mm
@@ -51,16 +51,17 @@
 #include "gfxUtils.h"
 #include "nsRegion.h"
 #include "Layers.h"
 #include "LayerManagerOGL.h"
 #include "ClientLayerManager.h"
 #include "mozilla/layers/LayerManagerComposite.h"
 #include "GLTextureImage.h"
 #include "GLContextProvider.h"
+#include "GLContext.h"
 #include "mozilla/layers/GLManager.h"
 #include "mozilla/layers/CompositorCocoaWidgetHelper.h"
 #include "mozilla/layers/CompositorOGL.h"
 #include "mozilla/layers/BasicCompositor.h"
 #include "gfxUtils.h"
 #include "mozilla/gfx/2D.h"
 #ifdef ACCESSIBILITY
 #include "nsAccessibilityService.h"
--- a/widget/gonk/nsWindow.cpp
+++ b/widget/gonk/nsWindow.cpp
@@ -24,16 +24,17 @@
 #include "mozilla/Preferences.h"
 #include "mozilla/FileUtils.h"
 #include "mozilla/ClearOnShutdown.h"
 #include "Framebuffer.h"
 #include "gfxContext.h"
 #include "gfxPlatform.h"
 #include "gfxUtils.h"
 #include "GLContextProvider.h"
+#include "GLContext.h"
 #include "LayerManagerOGL.h"
 #include "nsAutoPtr.h"
 #include "nsAppShell.h"
 #include "nsIdleService.h"
 #include "nsScreenManagerGonk.h"
 #include "nsTArray.h"
 #include "nsWindow.h"
 #include "nsIWidgetListener.h"
--- a/widget/gtk2/nsWindow.cpp
+++ b/widget/gtk2/nsWindow.cpp
@@ -62,16 +62,17 @@
 #include "nsIServiceManager.h"
 #include "nsIStringBundle.h"
 #include "nsGfxCIID.h"
 #include "nsGtkUtils.h"
 #include "nsIObserverService.h"
 #include "mozilla/layers/LayersTypes.h"
 #include "nsIIdleServiceInternal.h"
 #include "nsIPropertyBag2.h"
+#include "GLContext.h"
 
 #ifdef ACCESSIBILITY
 #include "mozilla/a11y/Accessible.h"
 #include "mozilla/a11y/Platform.h"
 #include "nsAccessibilityService.h"
 
 using namespace mozilla;
 using namespace mozilla::widget;