Bug 1182371 - Misc WebGL cleanup. - r=kamidphish
authorJeff Gilbert <jgilbert@mozilla.com>
Tue, 14 Jul 2015 17:37:28 -0700
changeset 252892 2e3bce121f7cfc0e334da9f8a1c4fc99a0eea879
parent 252891 3056e4aa89d83ad8d2e44ffcfcc6ee26b91d20a1
child 252893 bbf6fa4325a42e1239369aea5715b0c627db4dae
push id62269
push userjgilbert@mozilla.com
push dateWed, 15 Jul 2015 00:37:42 +0000
treeherdermozilla-inbound@2e3bce121f7c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskamidphish
bugs1182371
milestone42.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 1182371 - Misc WebGL cleanup. - r=kamidphish
dom/canvas/CanvasRenderingContext2D.cpp
dom/canvas/CanvasRenderingContext2D.h
dom/canvas/WebGL1Context.cpp
dom/canvas/WebGL1Context.h
dom/canvas/WebGL1ContextBuffers.cpp
dom/canvas/WebGL2Context.cpp
dom/canvas/WebGL2Context.h
dom/canvas/WebGL2ContextBuffers.cpp
dom/canvas/WebGL2ContextDraw.cpp
dom/canvas/WebGL2ContextFramebuffers.cpp
dom/canvas/WebGL2ContextMRTs.cpp
dom/canvas/WebGL2ContextSamplers.cpp
dom/canvas/WebGL2ContextState.cpp
dom/canvas/WebGL2ContextSync.cpp
dom/canvas/WebGL2ContextTextures.cpp
dom/canvas/WebGL2ContextTransformFeedback.cpp
dom/canvas/WebGL2ContextUniforms.cpp
dom/canvas/WebGLActiveInfo.cpp
dom/canvas/WebGLActiveInfo.h
dom/canvas/WebGLBuffer.cpp
dom/canvas/WebGLBuffer.h
dom/canvas/WebGLContext.cpp
dom/canvas/WebGLContext.h
dom/canvas/WebGLContextDraw.cpp
dom/canvas/WebGLContextExtensions.cpp
dom/canvas/WebGLContextFramebufferOperations.cpp
dom/canvas/WebGLContextGL.cpp
dom/canvas/WebGLContextReporter.cpp
dom/canvas/WebGLContextState.cpp
dom/canvas/WebGLContextUtils.cpp
dom/canvas/WebGLContextUtils.h
dom/canvas/WebGLContextValidate.cpp
dom/canvas/WebGLContextVertices.cpp
dom/canvas/WebGLExtensionBase.cpp
dom/canvas/WebGLExtensions.h
dom/canvas/WebGLFormats.cpp
dom/canvas/WebGLFramebuffer.cpp
dom/canvas/WebGLFramebuffer.h
dom/canvas/WebGLFramebufferAttachable.cpp
dom/canvas/WebGLFramebufferAttachable.h
dom/canvas/WebGLMemoryTracker.cpp
dom/canvas/WebGLMemoryTracker.h
dom/canvas/WebGLObjectModel.h
dom/canvas/WebGLProgram.cpp
dom/canvas/WebGLProgram.h
dom/canvas/WebGLQuery.cpp
dom/canvas/WebGLQuery.h
dom/canvas/WebGLRenderbuffer.cpp
dom/canvas/WebGLRenderbuffer.h
dom/canvas/WebGLSampler.cpp
dom/canvas/WebGLSampler.h
dom/canvas/WebGLShader.cpp
dom/canvas/WebGLShader.h
dom/canvas/WebGLShaderPrecisionFormat.cpp
dom/canvas/WebGLShaderPrecisionFormat.h
dom/canvas/WebGLStrongTypes.h
dom/canvas/WebGLSync.cpp
dom/canvas/WebGLSync.h
dom/canvas/WebGLTexture.cpp
dom/canvas/WebGLTexture.h
dom/canvas/WebGLTimerQuery.cpp
dom/canvas/WebGLTimerQuery.h
dom/canvas/WebGLTransformFeedback.cpp
dom/canvas/WebGLTransformFeedback.h
dom/canvas/WebGLUniformLocation.cpp
dom/canvas/WebGLUniformLocation.h
dom/canvas/WebGLVertexArray.cpp
dom/canvas/WebGLVertexArray.h
dom/canvas/WebGLVertexArrayObject.cpp
dom/canvas/compiledtest/TestWebGLElementArrayCache.cpp
dom/canvas/moz.build
dom/canvas/nsICanvasRenderingContextInternal.h
gfx/gl/GLBlitHelper.cpp
gfx/gl/GLContext.cpp
gfx/gl/GLContext.h
gfx/gl/SharedSurface.cpp
toolkit/components/telemetry/Telemetry.h
--- a/dom/canvas/CanvasRenderingContext2D.cpp
+++ b/dom/canvas/CanvasRenderingContext2D.cpp
@@ -111,16 +111,17 @@
 #include "SVGContentUtils.h"
 #include "SVGImageContext.h"
 #include "nsIScreenManager.h"
 #include "nsFilterInstance.h"
 #include "nsSVGLength2.h"
 #include "nsDeviceContext.h"
 #include "nsFontMetrics.h"
 #include "Units.h"
+#include "CanvasUtils.h"
 
 #undef free // apparently defined by some windows header, clashing with a free()
             // method in SkTypes.h
 #include "SkiaGLGlue.h"
 #ifdef USE_SKIA
 #include "SurfaceTypes.h"
 #include "GLBlitHelper.h"
 #endif
@@ -5272,22 +5273,22 @@ CanvasRenderingContext2D::PutImageData_e
     return NS_ERROR_FAILURE;
   }
 
   uint32_t copyX = dirtyRect.x - x;
   uint32_t copyY = dirtyRect.y - y;
   //uint8_t *src = aArray->Data();
   uint8_t *dst = imgsurf->Data();
   uint8_t* srcLine = aArray->Data() + copyY * (w * 4) + copyX * 4;
-#if 0  
+#if 0
   printf("PutImageData_explicit: dirty x=%d y=%d w=%d h=%d copy x=%d y=%d w=%d h=%d ext x=%d y=%d w=%d h=%d\n",
 	     dirtyRect.x, dirtyRect.y, copyWidth, copyHeight,
 	     copyX, copyY, copyWidth, copyHeight,
 	     x, y, w, h);
-#endif	     
+#endif
   for (uint32_t j = 0; j < copyHeight; j++) {
     uint8_t *src = srcLine;
     for (uint32_t i = 0; i < copyWidth; i++) {
       uint8_t r = *src++;
       uint8_t g = *src++;
       uint8_t b = *src++;
       uint8_t a = *src++;
 
--- a/dom/canvas/CanvasRenderingContext2D.h
+++ b/dom/canvas/CanvasRenderingContext2D.h
@@ -8,17 +8,16 @@
 #include "mozilla/Attributes.h"
 #include <vector>
 #include "nsIDOMCanvasRenderingContext2D.h"
 #include "nsICanvasRenderingContextInternal.h"
 #include "mozilla/RefPtr.h"
 #include "nsColor.h"
 #include "mozilla/dom/HTMLCanvasElement.h"
 #include "mozilla/dom/HTMLVideoElement.h"
-#include "CanvasUtils.h"
 #include "gfxTextRun.h"
 #include "mozilla/ErrorResult.h"
 #include "mozilla/dom/CanvasGradient.h"
 #include "mozilla/dom/CanvasRenderingContext2DBinding.h"
 #include "mozilla/dom/CanvasPattern.h"
 #include "mozilla/gfx/Rect.h"
 #include "mozilla/gfx/2D.h"
 #include "gfx2DGlue.h"
--- a/dom/canvas/WebGL1Context.cpp
+++ b/dom/canvas/WebGL1Context.cpp
@@ -23,19 +23,19 @@ WebGL1Context::WebGL1Context()
     mFormatUsage = Move(webgl::FormatUsageAuthority::CreateForWebGL1());
 }
 
 WebGL1Context::~WebGL1Context()
 {
 }
 
 JSObject*
-WebGL1Context::WrapObject(JSContext* cx, JS::Handle<JSObject*> aGivenProto)
+WebGL1Context::WrapObject(JSContext* cx, JS::Handle<JSObject*> givenProto)
 {
-    return dom::WebGLRenderingContextBinding::Wrap(cx, this, aGivenProto);
+    return dom::WebGLRenderingContextBinding::Wrap(cx, this, givenProto);
 }
 
 bool
 WebGL1Context::ValidateQueryTarget(GLenum target, const char* info)
 {
     // TODO: Implement this for EXT_disjoint_timer
     return false;
 }
--- a/dom/canvas/WebGL1Context.h
+++ b/dom/canvas/WebGL1Context.h
@@ -22,17 +22,17 @@ private:
 public:
     virtual ~WebGL1Context();
 
     virtual bool IsWebGL2() const override {
         return false;
     }
 
     // nsWrapperCache
-    virtual JSObject* WrapObject(JSContext* cx, JS::Handle<JSObject*> aGivenProto) override;
+    virtual JSObject* WrapObject(JSContext* cx, JS::Handle<JSObject*> givenProto) override;
 
 private:
     virtual bool ValidateAttribPointerType(bool integerMode, GLenum type, GLsizei* alignment, const char* info) override;
     virtual bool ValidateBufferTarget(GLenum target, const char* info) override;
     virtual bool ValidateBufferIndexedTarget(GLenum target, const char* info) override;
     virtual bool ValidateBufferUsageEnum(GLenum usage, const char* info) override;
     virtual bool ValidateQueryTarget(GLenum target, const char* info) override;
     virtual bool ValidateUniformMatrixTranspose(bool transpose, const char* info) override;
--- a/dom/canvas/WebGL1ContextBuffers.cpp
+++ b/dom/canvas/WebGL1ContextBuffers.cpp
@@ -1,19 +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 "WebGL1Context.h"
-#include "WebGLBuffer.h"
-#include "GLContext.h"
 
-using namespace mozilla;
-using namespace mozilla::dom;
+namespace mozilla {
 
 // -------------------------------------------------------------------------
 // Buffer objects
 
 /** Target validation for BindBuffer, etc */
 bool
 WebGL1Context::ValidateBufferTarget(GLenum target, const char* info)
 {
@@ -45,8 +42,10 @@ WebGL1Context::ValidateBufferUsageEnum(G
         return true;
     default:
         break;
     }
 
     ErrorInvalidEnumInfo(info, usage);
     return false;
 }
+
+} // namespace mozilla
--- a/dom/canvas/WebGL2Context.cpp
+++ b/dom/canvas/WebGL2Context.cpp
@@ -38,19 +38,19 @@ WebGL2Context::IsSupported()
 
 /*static*/ WebGL2Context*
 WebGL2Context::Create()
 {
     return new WebGL2Context();
 }
 
 JSObject*
-WebGL2Context::WrapObject(JSContext* cx, JS::Handle<JSObject*> aGivenProto)
+WebGL2Context::WrapObject(JSContext* cx, JS::Handle<JSObject*> givenProto)
 {
-    return dom::WebGL2RenderingContextBinding::Wrap(cx, this, aGivenProto);
+    return dom::WebGL2RenderingContextBinding::Wrap(cx, this, givenProto);
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 // WebGL 2 initialisation
 
 // These WebGL 1 extensions are natively supported by WebGL 2.
 static const WebGLExtensionID kNativelySupportedExtensions[] = {
     WebGLExtensionID::ANGLE_instanced_arrays,
--- a/dom/canvas/WebGL2Context.h
+++ b/dom/canvas/WebGL2Context.h
@@ -33,17 +33,17 @@ public:
     virtual bool IsWebGL2() const override
     {
         return true;
     }
 
     // -------------------------------------------------------------------------
     // IMPLEMENT nsWrapperCache
 
-    virtual JSObject* WrapObject(JSContext* cx, JS::Handle<JSObject*> aGivenProto) override;
+    virtual JSObject* WrapObject(JSContext* cx, JS::Handle<JSObject*> givenProto) override;
 
     // -------------------------------------------------------------------------
     // Buffer objects - WebGL2ContextBuffers.cpp
 
     void CopyBufferSubData(GLenum readTarget, GLenum writeTarget,
                            GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size);
     void GetBufferSubData(GLenum target, GLintptr offset,
                           const dom::Nullable<dom::ArrayBuffer>& maybeData);
@@ -53,39 +53,39 @@ public:
     // Framebuffer objects - WebGL2ContextFramebuffers.cpp
 
     void BlitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1,
                          GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,
                          GLbitfield mask, GLenum filter);
     void FramebufferTextureLayer(GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer);
     void GetInternalformatParameter(JSContext*, GLenum target, GLenum internalformat, GLenum pname, JS::MutableHandleValue retval);
     void InvalidateFramebuffer(GLenum target, const dom::Sequence<GLenum>& attachments,
-                               ErrorResult& aRv);
+                               ErrorResult& rv);
     void InvalidateSubFramebuffer (GLenum target, const dom::Sequence<GLenum>& attachments, GLint x, GLint y,
-                                   GLsizei width, GLsizei height, ErrorResult& aRv);
+                                   GLsizei width, GLsizei height, ErrorResult& rv);
     void ReadBuffer(GLenum mode);
     void RenderbufferStorageMultisample(GLenum target, GLsizei samples, GLenum internalformat,
                                         GLsizei width, GLsizei height);
 
 
     // -------------------------------------------------------------------------
     // Texture objects - WebGL2ContextTextures.cpp
 
     void TexStorage2D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height);
     void TexStorage3D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height,
                       GLsizei depth);
     void TexImage3D(GLenum target, GLint level, GLenum internalformat,
                     GLsizei width, GLsizei height, GLsizei depth,
                     GLint border, GLenum format, GLenum type,
-                    const Nullable<dom::ArrayBufferView> &pixels,
+                    const dom::Nullable<dom::ArrayBufferView>& pixels,
                     ErrorResult& rv);
     void TexSubImage3D(GLenum target, GLint level,
                        GLint xoffset, GLint yoffset, GLint zoffset,
                        GLsizei width, GLsizei height, GLsizei depth,
-                       GLenum format, GLenum type, const Nullable<dom::ArrayBufferView>& pixels,
+                       GLenum format, GLenum type, const dom::Nullable<dom::ArrayBufferView>& pixels,
                        ErrorResult& rv);
     void TexSubImage3D(GLenum target, GLint level,
                        GLint xoffset, GLint yoffset, GLint zoffset,
                        GLenum format, GLenum type, dom::ImageData* data,
                        ErrorResult& rv);
     template<class ElementType>
     void TexSubImage3D(GLenum target, GLint level,
                        GLint xoffset, GLint yoffset, GLint zoffset,
--- a/dom/canvas/WebGL2ContextBuffers.cpp
+++ b/dom/canvas/WebGL2ContextBuffers.cpp
@@ -2,19 +2,19 @@
 /* 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 "WebGLBuffer.h"
+#include "WebGLTransformFeedback.h"
 
-using namespace mozilla;
-using namespace mozilla::dom;
+namespace mozilla {
 
 bool
 WebGL2Context::ValidateBufferTarget(GLenum target, const char* info)
 {
     switch (target) {
     case LOCAL_GL_ARRAY_BUFFER:
     case LOCAL_GL_COPY_READ_BUFFER:
     case LOCAL_GL_COPY_WRITE_BUFFER:
@@ -219,8 +219,10 @@ WebGL2Context::GetBufferSubData(GLenum t
     void* ptr = gl->fMapBufferRange(target, offset, data.Length(), LOCAL_GL_MAP_READ_BIT);
     memcpy(data.Data(), ptr, data.Length());
     gl->fUnmapBuffer(target);
 
     if (target == LOCAL_GL_TRANSFORM_FEEDBACK_BUFFER && currentTF) {
         BindTransformFeedback(LOCAL_GL_TRANSFORM_FEEDBACK, currentTF);
     }
 }
+
+} // namespace mozilla
--- a/dom/canvas/WebGL2ContextDraw.cpp
+++ b/dom/canvas/WebGL2ContextDraw.cpp
@@ -1,19 +1,19 @@
 /* -*- 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 "WebGL2Context.h"
-#include "GLContext.h"
 
-using namespace mozilla;
-using namespace mozilla::dom;
+namespace mozilla {
 
 // -------------------------------------------------------------------------
 // Writing to the drawing buffer
 
 void
 WebGL2Context::DrawRangeElements(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, GLintptr offset)
 {
     MOZ_CRASH("Not Implemented.");
 }
+
+} // namespace mozilla
--- a/dom/canvas/WebGL2ContextFramebuffers.cpp
+++ b/dom/canvas/WebGL2ContextFramebuffers.cpp
@@ -1,20 +1,21 @@
 /* -*- 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 "WebGL2Context.h"
 
 #include "GLContext.h"
+#include "GLScreenBuffer.h"
 #include "WebGLContextUtils.h"
+#include "WebGLFramebuffer.h"
 
-using namespace mozilla;
-using namespace mozilla::dom;
+namespace mozilla {
 
 // Returns one of FLOAT, INT, UNSIGNED_INT.
 // Fixed-points (normalized ints) are considered FLOAT.
 static GLenum
 ValueTypeForFormat(GLenum internalFormat)
 {
     switch (internalFormat) {
     // Fixed-point
@@ -369,17 +370,17 @@ TranslateDefaultAttachments(const dom::S
     }
 
     return true;
 }
 
 void
 WebGL2Context::InvalidateFramebuffer(GLenum target,
                                      const dom::Sequence<GLenum>& attachments,
-                                     ErrorResult& aRv)
+                                     ErrorResult& rv)
 {
     if (IsContextLost())
         return;
 
     MakeContextCurrent();
 
     if (!ValidateFramebufferTarget(target, "framebufferRenderbuffer"))
         return;
@@ -415,30 +416,30 @@ WebGL2Context::InvalidateFramebuffer(GLe
     // drivers.
     static bool invalidateFBSupported = gl->IsSupported(gl::GLFeature::invalidate_framebuffer);
     if (!invalidateFBSupported)
         return;
 
     if (!fb && !isDefaultFB) {
         dom::Sequence<GLenum> tmpAttachments;
         if (!TranslateDefaultAttachments(attachments, &tmpAttachments)) {
-            aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
+            rv.Throw(NS_ERROR_OUT_OF_MEMORY);
             return;
         }
 
         gl->fInvalidateFramebuffer(target, tmpAttachments.Length(), tmpAttachments.Elements());
     } else {
         gl->fInvalidateFramebuffer(target, attachments.Length(), attachments.Elements());
     }
 }
 
 void
 WebGL2Context::InvalidateSubFramebuffer(GLenum target, const dom::Sequence<GLenum>& attachments,
                                         GLint x, GLint y, GLsizei width, GLsizei height,
-                                        ErrorResult& aRv)
+                                        ErrorResult& rv)
 {
     if (IsContextLost())
         return;
 
     MakeContextCurrent();
 
     if (!ValidateFramebufferTarget(target, "framebufferRenderbuffer"))
         return;
@@ -474,17 +475,17 @@ WebGL2Context::InvalidateSubFramebuffer(
     // drivers.
     static bool invalidateFBSupported = gl->IsSupported(gl::GLFeature::invalidate_framebuffer);
     if (!invalidateFBSupported)
         return;
 
     if (!fb && !isDefaultFB) {
         dom::Sequence<GLenum> tmpAttachments;
         if (!TranslateDefaultAttachments(attachments, &tmpAttachments)) {
-            aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
+            rv.Throw(NS_ERROR_OUT_OF_MEMORY);
             return;
         }
 
         gl->fInvalidateSubFramebuffer(target, tmpAttachments.Length(), tmpAttachments.Elements(),
                                       x, y, width, height);
     } else {
         gl->fInvalidateSubFramebuffer(target, attachments.Length(), attachments.Elements(),
                                       x, y, width, height);
@@ -531,8 +532,10 @@ WebGL2Context::ReadBuffer(GLenum mode)
 void
 WebGL2Context::RenderbufferStorageMultisample(GLenum target, GLsizei samples,
                                               GLenum internalFormat,
                                               GLsizei width, GLsizei height)
 {
     RenderbufferStorage_base("renderbufferStorageMultisample", target, samples,
                               internalFormat, width, height);
 }
+
+} // namespace mozilla
--- a/dom/canvas/WebGL2ContextMRTs.cpp
+++ b/dom/canvas/WebGL2ContextMRTs.cpp
@@ -1,18 +1,17 @@
 /* -*- 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 "WebGL2Context.h"
 #include "GLContext.h"
 
-using namespace mozilla;
-using namespace mozilla::dom;
+namespace mozilla {
 
 bool WebGL2Context::ValidateClearBuffer(const char* info, GLenum buffer, GLint drawbuffer, size_t elemCount)
 {
     size_t requiredElements = -1;
     GLint maxDrawbuffer = -1;
     switch (buffer) {
       case LOCAL_GL_COLOR:
       case LOCAL_GL_FRONT:
@@ -135,8 +134,10 @@ void
 WebGL2Context::ClearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
 {
     if (buffer != LOCAL_GL_DEPTH_STENCIL) {
         return ErrorInvalidEnumInfo("clearBufferfi: buffer", buffer);
     }
     MakeContextCurrent();
     gl->fClearBufferfi(buffer, drawbuffer, depth, stencil);
 }
+
+} // namespace mozilla
--- a/dom/canvas/WebGL2ContextSamplers.cpp
+++ b/dom/canvas/WebGL2ContextSamplers.cpp
@@ -2,18 +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 "WebGL2Context.h"
 #include "WebGLSampler.h"
 #include "GLContext.h"
 
-using namespace mozilla;
-using namespace mozilla::dom;
+namespace mozilla {
 
 already_AddRefed<WebGLSampler>
 WebGL2Context::CreateSampler()
 {
     if (IsContextLost())
         return nullptr;
 
     GLuint sampler;
@@ -220,8 +219,10 @@ WebGL2Context::GetSamplerParameter(JSCon
 
     case LOCAL_GL_TEXTURE_MIN_LOD:
     case LOCAL_GL_TEXTURE_MAX_LOD:
         retval.set(JS::Float32Value(
             WebGLContextUnchecked::GetSamplerParameterfv(sampler, pname)));
         return;
     }
 }
+
+} // namespace mozilla
--- a/dom/canvas/WebGL2ContextState.cpp
+++ b/dom/canvas/WebGL2ContextState.cpp
@@ -1,16 +1,23 @@
 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
 /* 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 "WebGLBuffer.h"
 #include "WebGLContextUtils.h"
+#include "WebGLFramebuffer.h"
+#include "WebGLSampler.h"
+#include "WebGLTransformFeedback.h"
+#include "WebGLVertexArray.h"
 
 namespace mozilla {
 
 JS::Value
 WebGL2Context::GetParameter(JSContext* cx, GLenum pname, ErrorResult& rv)
 {
   // The following cases are handled in WebGLContext::GetParameter():
   //     case LOCAL_GL_MAX_COLOR_ATTACHMENTS:
--- a/dom/canvas/WebGL2ContextSync.cpp
+++ b/dom/canvas/WebGL2ContextSync.cpp
@@ -3,18 +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 "WebGL2Context.h"
 
 #include "GLContext.h"
 #include "WebGLSync.h"
 
-using namespace mozilla;
-using namespace mozilla::dom;
+namespace mozilla {
 
 // -------------------------------------------------------------------------
 // Sync objects
 
 already_AddRefed<WebGLSync>
 WebGL2Context::FenceSync(GLenum condition, GLbitfield flags)
 {
    if (IsContextLost())
@@ -126,8 +125,10 @@ WebGL2Context::GetSyncParameter(JSContex
         MakeContextCurrent();
         gl->fGetSynciv(sync->mGLName, pname, 1, nullptr, &result);
         retval.set(JS::Int32Value(result));
         break;
     }
 
     ErrorInvalidEnum("getSyncParameter: Invalid pname 0x%04x", pname);
 }
+
+} // namespace mozilla
--- a/dom/canvas/WebGL2ContextTextures.cpp
+++ b/dom/canvas/WebGL2ContextTextures.cpp
@@ -1,19 +1,19 @@
 /* -*- 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 "GLContext.h"
 #include "WebGL2Context.h"
 #include "WebGLContextUtils.h"
-#include "GLContext.h"
+#include "WebGLTexture.h"
 
-using namespace mozilla;
-using namespace mozilla::dom;
+namespace mozilla {
 
 bool
 WebGL2Context::ValidateSizedInternalFormat(GLenum internalformat, const char* info)
 {
     switch (internalformat) {
         // Sized Internal Formats
         // https://www.khronos.org/opengles/sdk/docs/man3/html/glTexStorage2D.xhtml
     case LOCAL_GL_R8:
@@ -200,31 +200,31 @@ WebGL2Context::TexStorage3D(GLenum targe
         d = std::max(1, d >> 1);
     }
 }
 
 void
 WebGL2Context::TexImage3D(GLenum target, GLint level, GLenum internalformat,
                           GLsizei width, GLsizei height, GLsizei depth,
                           GLint border, GLenum format, GLenum type,
-                          const Nullable<dom::ArrayBufferView> &pixels,
+                          const dom::Nullable<dom::ArrayBufferView> &pixels,
                           ErrorResult& rv)
 {
     if (IsContextLost())
         return;
 
     void* data;
     size_t dataLength;
     js::Scalar::Type jsArrayType;
     if (pixels.IsNull()) {
         data = nullptr;
         dataLength = 0;
         jsArrayType = js::Scalar::MaxTypedArrayViewType;
     } else {
-        const ArrayBufferView& view = pixels.Value();
+        const dom::ArrayBufferView& view = pixels.Value();
         view.ComputeLengthAndData();
 
         data = view.Data();
         dataLength = view.Length();
         jsArrayType = view.Type();
     }
 
     const WebGLTexImageFunc func = WebGLTexImageFunc::TexImage;
@@ -313,26 +313,27 @@ WebGL2Context::TexImage3D(GLenum target,
                       data ? WebGLImageDataStatus::InitializedImageData
                            : WebGLImageDataStatus::UninitializedImageData);
 }
 
 void
 WebGL2Context::TexSubImage3D(GLenum rawTarget, GLint level,
                              GLint xoffset, GLint yoffset, GLint zoffset,
                              GLsizei width, GLsizei height, GLsizei depth,
-                             GLenum format, GLenum type, const Nullable<dom::ArrayBufferView>& pixels,
+                             GLenum format, GLenum type,
+                             const dom::Nullable<dom::ArrayBufferView>& pixels,
                              ErrorResult& rv)
 {
     if (IsContextLost())
         return;
 
     if (pixels.IsNull())
         return ErrorInvalidValue("texSubImage3D: pixels must not be null!");
 
-    const ArrayBufferView& view = pixels.Value();
+    const dom::ArrayBufferView& view = pixels.Value();
     view.ComputeLengthAndData();
 
     const WebGLTexImageFunc func = WebGLTexImageFunc::TexSubImage;
     const WebGLTexDimensions dims = WebGLTexDimensions::Tex3D;
 
     if (!ValidateTexImageTarget(rawTarget, func, dims))
         return;
 
@@ -484,8 +485,10 @@ WebGL2Context::GetTexParameterInternal(c
             GLfloat f = 0.0f;
             gl->fGetTexParameterfv(target.get(), pname, &f);
             return JS::NumberValue(float(f));
         }
     }
 
     return WebGLContext::GetTexParameterInternal(target, pname);
 }
+
+} // namespace mozilla
--- a/dom/canvas/WebGL2ContextTransformFeedback.cpp
+++ b/dom/canvas/WebGL2ContextTransformFeedback.cpp
@@ -4,18 +4,17 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "WebGL2Context.h"
 #include "WebGLActiveInfo.h"
 #include "WebGLProgram.h"
 #include "WebGLTransformFeedback.h"
 #include "GLContext.h"
 
-using namespace mozilla;
-using namespace mozilla::dom;
+namespace mozilla {
 
 // -------------------------------------------------------------------------
 // Transform Feedback
 
 already_AddRefed<WebGLTransformFeedback>
 WebGL2Context::CreateTransformFeedback()
 {
     if (IsContextLost())
@@ -211,8 +210,10 @@ WebGL2Context::GetTransformFeedbackVaryi
     if (IsContextLost())
         return nullptr;
 
     if (!ValidateObject("getTransformFeedbackVarying: program", program))
         return nullptr;
 
     return program->GetTransformFeedbackVarying(index);
 }
+
+} // namespace mozilla
--- a/dom/canvas/WebGL2ContextUniforms.cpp
+++ b/dom/canvas/WebGL2ContextUniforms.cpp
@@ -1,20 +1,23 @@
 /* -*- 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 "WebGL2Context.h"
+
 #include "GLContext.h"
+#include "mozilla/dom/WebGL2RenderingContextBinding.h"
+#include "nsRefPtr.h"
+#include "WebGLBuffer.h"
 #include "WebGLContext.h"
 #include "WebGLProgram.h"
 #include "WebGLVertexArray.h"
 #include "WebGLVertexAttribData.h"
-#include "mozilla/dom/WebGL2RenderingContextBinding.h"
 
 namespace mozilla {
 
 typedef union { GLint i; GLfloat f; GLuint u; } fi_t;
 
 static inline
 GLfloat PuntToFloat(GLint i)
 {
@@ -538,17 +541,17 @@ WebGL2Context::GetUniformBlockIndex(WebG
         return 0;
 
     return program->GetUniformBlockIndex(uniformBlockName);
 }
 
 void
 WebGL2Context::GetActiveUniformBlockParameter(JSContext* cx, WebGLProgram* program,
                                               GLuint uniformBlockIndex, GLenum pname,
-                                              Nullable<dom::OwningUnsignedLongOrUint32ArrayOrBoolean>& retval,
+                                              dom::Nullable<dom::OwningUnsignedLongOrUint32ArrayOrBoolean>& retval,
                                               ErrorResult& rv)
 {
     retval.SetNull();
     if (IsContextLost())
         return;
 
     if (!ValidateObject("getActiveUniformBlockParameter: program", program))
         return;
--- a/dom/canvas/WebGLActiveInfo.cpp
+++ b/dom/canvas/WebGLActiveInfo.cpp
@@ -86,19 +86,19 @@ WebGLActiveInfo::WebGLActiveInfo(WebGLCo
     , mIsArray(isArray)
     , mElemSize(ElemSizeFromType(elemType))
     , mBaseMappedName(baseMappedName)
 { }
 
 ////////////////////////////////////////////////////////////////////////////////
 
 JSObject*
-WebGLActiveInfo::WrapObject(JSContext* js, JS::Handle<JSObject*> aGivenProto)
+WebGLActiveInfo::WrapObject(JSContext* js, JS::Handle<JSObject*> givenProto)
 {
-    return dom::WebGLActiveInfoBinding::Wrap(js, this, aGivenProto);
+    return dom::WebGLActiveInfoBinding::Wrap(js, this, givenProto);
 }
 
 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_0(WebGLActiveInfo)
 
 NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(WebGLActiveInfo, AddRef)
 NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(WebGLActiveInfo, Release)
 
 } // namespace mozilla
--- a/dom/canvas/WebGLActiveInfo.h
+++ b/dom/canvas/WebGLActiveInfo.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 WEBGL_ACTIVE_INFO_H_
 #define WEBGL_ACTIVE_INFO_H_
 
 #include "GLDefs.h"
-#include "js/TypeDecls.h"
 #include "mozilla/Attributes.h"
 #include "nsCycleCollectionParticipant.h" // NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS
 #include "nsISupportsImpl.h" // NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING
 #include "nsString.h"
 #include "nsWrapperCache.h"
 
 namespace mozilla {
 
@@ -20,17 +19,17 @@ class WebGLContext;
 
 class WebGLActiveInfo final
     : public nsWrapperCache
 {
 public:
     NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(WebGLActiveInfo)
     NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(WebGLActiveInfo)
 
-    virtual JSObject* WrapObject(JSContext* js, JS::Handle<JSObject*> aGivenProto) override;
+    virtual JSObject* WrapObject(JSContext* js, JS::Handle<JSObject*> givenProto) override;
 
     WebGLContext* GetParentObject() const {
         return mWebGL;
     }
 
 
     WebGLContext* const mWebGL;
 
--- a/dom/canvas/WebGLBuffer.cpp
+++ b/dom/canvas/WebGLBuffer.cpp
@@ -99,19 +99,19 @@ WebGLBuffer::Validate(GLenum type, uint3
 
 bool
 WebGLBuffer::IsElementArrayUsedWithMultipleTypes() const
 {
     return mCache->BeenUsedWithMultipleTypes();
 }
 
 JSObject*
-WebGLBuffer::WrapObject(JSContext* cx, JS::Handle<JSObject*> aGivenProto)
+WebGLBuffer::WrapObject(JSContext* cx, JS::Handle<JSObject*> givenProto)
 {
-    return dom::WebGLBufferBinding::Wrap(cx, this, aGivenProto);
+    return dom::WebGLBufferBinding::Wrap(cx, this, givenProto);
 }
 
 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_0(WebGLBuffer)
 
 NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(WebGLBuffer, AddRef)
 NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(WebGLBuffer, Release)
 
 } // namespace mozilla
--- a/dom/canvas/WebGLBuffer.h
+++ b/dom/canvas/WebGLBuffer.h
@@ -3,20 +3,20 @@
  * 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 WEBGL_BUFFER_H_
 #define WEBGL_BUFFER_H_
 
 #include "GLDefs.h"
 #include "mozilla/LinkedList.h"
-#include "mozilla/MemoryReporting.h"
+#include "nsAutoPtr.h"
 #include "nsWrapperCache.h"
+
 #include "WebGLObjectModel.h"
-#include "WebGLStrongTypes.h"
 #include "WebGLTypes.h"
 
 namespace mozilla {
 
 class WebGLElementArrayCache;
 
 class WebGLBuffer final
     : public nsWrapperCache
@@ -53,17 +53,17 @@ public:
                   uint32_t* const out_upperBound);
 
     bool IsElementArrayUsedWithMultipleTypes() const;
 
     WebGLContext* GetParentObject() const {
         return Context();
     }
 
-    virtual JSObject* WrapObject(JSContext* cx, JS::Handle<JSObject*> aGivenProto) override;
+    virtual JSObject* WrapObject(JSContext* cx, JS::Handle<JSObject*> givenProto) override;
 
     const GLenum mGLName;
 
     NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(WebGLBuffer)
     NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(WebGLBuffer)
 
 protected:
     ~WebGLBuffer();
--- a/dom/canvas/WebGLContext.cpp
+++ b/dom/canvas/WebGLContext.cpp
@@ -1,73 +1,84 @@
 /* -*- 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 <queue>
+
 #include "AccessCheck.h"
-#include "CanvasUtils.h"
 #include "gfxContext.h"
 #include "gfxCrashReporterUtils.h"
 #include "gfxPattern.h"
 #include "gfxPrefs.h"
 #include "gfxUtils.h"
 #include "GLBlitHelper.h"
 #include "GLContext.h"
 #include "GLContextProvider.h"
 #include "GLReadTexImageHelper.h"
+#include "GLScreenBuffer.h"
 #include "ImageContainer.h"
 #include "ImageEncoder.h"
 #include "Layers.h"
 #include "mozilla/dom/BindingUtils.h"
 #include "mozilla/dom/HTMLVideoElement.h"
 #include "mozilla/dom/ImageData.h"
-#include "mozilla/dom/WebGLRenderingContextBinding.h"
 #include "mozilla/EnumeratedArrayCycleCollection.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/ProcessPriorityManager.h"
 #include "mozilla/Services.h"
 #include "mozilla/Telemetry.h"
 #include "nsContentUtils.h"
 #include "nsDisplayList.h"
 #include "nsError.h"
 #include "nsIClassInfoImpl.h"
 #include "nsIConsoleService.h"
+#include "nsIDOMEvent.h"
 #include "nsIGfxInfo.h"
 #include "nsIObserverService.h"
-#include "nsIDOMEvent.h"
 #include "nsIVariant.h"
 #include "nsIWidget.h"
 #include "nsIXPConnect.h"
 #include "nsServiceManagerUtils.h"
 #include "nsSVGEffects.h"
 #include "prenv.h"
-#include <queue>
 #include "ScopedGLHelpers.h"
+
+#ifdef MOZ_WIDGET_GONK
+#include "mozilla/layers/ShadowLayers.h"
+#endif
+
+// Local
+#include "CanvasUtils.h"
 #include "WebGL1Context.h"
+#include "WebGLActiveInfo.h"
 #include "WebGLBuffer.h"
 #include "WebGLContextLossHandler.h"
 #include "WebGLContextUtils.h"
 #include "WebGLExtensions.h"
 #include "WebGLFramebuffer.h"
 #include "WebGLMemoryTracker.h"
 #include "WebGLObjectModel.h"
+#include "WebGLProgram.h"
 #include "WebGLQuery.h"
 #include "WebGLSampler.h"
+#include "WebGLShader.h"
 #include "WebGLTransformFeedback.h"
 #include "WebGLVertexArray.h"
 #include "WebGLVertexAttribData.h"
 
-#ifdef MOZ_WIDGET_GONK
-#include "mozilla/layers/ShadowLayers.h"
-#endif
+// Generated
+#include "mozilla/dom/WebGLRenderingContextBinding.h"
 
-using namespace mozilla;
+
+namespace mozilla {
+
 using namespace mozilla::dom;
 using namespace mozilla::gfx;
 using namespace mozilla::gl;
 using namespace mozilla::layers;
 
 WebGLObserver::WebGLObserver(WebGLContext* webgl)
     : mWebGL(webgl)
 {
@@ -903,17 +914,17 @@ WebGLContext::SetDimensions(int32_t sign
         return NS_ERROR_FAILURE;
     }
 
     nsCOMPtr<nsIGfxInfo> gfxInfo = do_GetService("@mozilla.org/gfx/info;1");
     bool failIfMajorPerformanceCaveat =
                     !gfxPrefs::WebGLDisableFailIfMajorPerformanceCaveat() &&
                     !HasAcceleratedLayers(gfxInfo);
     if (failIfMajorPerformanceCaveat) {
-        Nullable<dom::WebGLContextAttributes> contextAttributes;
+        dom::Nullable<dom::WebGLContextAttributes> contextAttributes;
         this->GetContextAttributes(contextAttributes);
         if (contextAttributes.Value().mFailIfMajorPerformanceCaveat) {
             return NS_ERROR_FAILURE;
         }
     }
 
     // Alright, now let's start trying.
     bool forceEnabled = Preferences::GetBool("webgl.force-enabled", false);
@@ -1177,18 +1188,16 @@ WebGLContext::UpdateLastUseIndex()
     if (!sIndex.isValid())
         NS_RUNTIMEABORT("Can't believe it's been 2^64 transactions already!");
 
     mLastUseIndex = sIndex.value();
 }
 
 static uint8_t gWebGLLayerUserData;
 
-namespace mozilla {
-
 class WebGLContextUserData : public LayerUserData
 {
 public:
     explicit WebGLContextUserData(HTMLCanvasElement* canvas)
         : mCanvas(canvas)
     {}
 
     /* PreTransactionCallback gets called by the Layers code every time the
@@ -1217,18 +1226,16 @@ public:
 
         webgl->UpdateLastUseIndex();
     }
 
 private:
     nsRefPtr<HTMLCanvasElement> mCanvas;
 };
 
-} // end namespace mozilla
-
 already_AddRefed<layers::CanvasLayer>
 WebGLContext::GetCanvasLayer(nsDisplayListBuilder* builder,
                              CanvasLayer* oldLayer,
                              LayerManager* manager)
 {
     if (IsContextLost())
         return nullptr;
 
@@ -1278,17 +1285,17 @@ WebGLContext::GetCanvasLayer(nsDisplayLi
     canvasLayer->Updated();
 
     mResetLayer = false;
 
     return canvasLayer.forget();
 }
 
 void
-WebGLContext::GetContextAttributes(Nullable<dom::WebGLContextAttributes>& retval)
+WebGLContext::GetContextAttributes(dom::Nullable<dom::WebGLContextAttributes>& retval)
 {
     retval.SetNull();
     if (IsContextLost())
         return;
 
     dom::WebGLContextAttributes& result = retval.SetValue();
 
     result.mAlpha.Construct(mOptions.alpha);
@@ -1897,17 +1904,79 @@ WebGLContext::TexImageFromVideoElement(c
                           srcImage->GetSize().height, 1,
                           effectiveInternalFormat,
                           WebGLImageDataStatus::InitializedImageData);
         tex->Bind(TexImageTargetToTexTarget(texImageTarget));
     }
     return ok;
 }
 
-size_t mozilla::RoundUpToMultipleOf(size_t value, size_t multiple)
+void
+WebGLContext::TexSubImage2D(GLenum rawTexImageTarget, GLint level, GLint xoffset,
+                            GLint yoffset, GLenum format, GLenum type,
+                            dom::Element* elt, ErrorResult* const out_rv)
+{
+    // TODO: Consolidate all the parameter validation
+    // checks. Instead of spreading out the cheks in multple
+    // places, consolidate into one spot.
+
+    if (IsContextLost())
+        return;
+
+    if (!ValidateTexImageTarget(rawTexImageTarget,
+                                WebGLTexImageFunc::TexSubImage,
+                                WebGLTexDimensions::Tex2D))
+    {
+        ErrorInvalidEnumInfo("texSubImage2D: target", rawTexImageTarget);
+        return;
+    }
+
+    const TexImageTarget texImageTarget(rawTexImageTarget);
+
+    if (level < 0)
+        return ErrorInvalidValue("texSubImage2D: level is negative");
+
+    const int32_t maxLevel = MaxTextureLevelForTexImageTarget(texImageTarget);
+    if (level > maxLevel) {
+        ErrorInvalidValue("texSubImage2D: level %d is too large, max is %d",
+                          level, maxLevel);
+        return;
+    }
+
+    WebGLTexture* tex = ActiveBoundTextureForTexImageTarget(texImageTarget);
+    if (!tex)
+        return ErrorInvalidOperation("texSubImage2D: no texture bound on active texture unit");
+
+    const WebGLTexture::ImageInfo& imageInfo = tex->ImageInfoAt(texImageTarget, level);
+    const TexInternalFormat internalFormat = imageInfo.EffectiveInternalFormat();
+
+    // Trying to handle the video by GPU directly first
+    if (TexImageFromVideoElement(texImageTarget, level,
+                                 internalFormat.get(), format, type, *elt))
+    {
+        return;
+    }
+
+    RefPtr<gfx::DataSourceSurface> data;
+    WebGLTexelFormat srcFormat;
+    nsLayoutUtils::SurfaceFromElementResult res = SurfaceFromElement(*elt);
+    *out_rv = SurfaceFromElementResultToImageSurface(res, data, &srcFormat);
+    if (out_rv->Failed() || !data)
+        return;
+
+    gfx::IntSize size = data->GetSize();
+    uint32_t byteLength = data->Stride() * size.height;
+    TexSubImage2D_base(texImageTarget.get(), level, xoffset, yoffset, size.width,
+                       size.height, data->Stride(), format, type, data->GetData(),
+                       byteLength, js::Scalar::MaxTypedArrayViewType, srcFormat,
+                       mPixelStorePremultiplyAlpha);
+}
+
+size_t
+RoundUpToMultipleOf(size_t value, size_t multiple)
 {
     size_t overshoot = value + multiple - 1;
     return overshoot - (overshoot % multiple);
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 
 WebGLContext::ScopedMaskWorkaround::ScopedMaskWorkaround(WebGLContext& webgl)
@@ -1972,8 +2041,10 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(
     NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
     NS_INTERFACE_MAP_ENTRY(nsIDOMWebGLRenderingContext)
     NS_INTERFACE_MAP_ENTRY(nsICanvasRenderingContextInternal)
     NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
     // If the exact way we cast to nsISupports here ever changes, fix our
     // ToSupports() method.
     NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMWebGLRenderingContext)
 NS_INTERFACE_MAP_END
+
+} // namespace mozilla
--- a/dom/canvas/WebGLContext.h
+++ b/dom/canvas/WebGLContext.h
@@ -1,55 +1,50 @@
 /* -*- 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/. */
 
 #ifndef WEBGLCONTEXT_H_
 #define WEBGLCONTEXT_H_
 
+#include <stdarg.h>
+
+#include "GLDefs.h"
 #include "mozilla/Attributes.h"
 #include "mozilla/CheckedInt.h"
+#include "mozilla/dom/HTMLCanvasElement.h"
+#include "mozilla/dom/TypedArray.h"
 #include "mozilla/EnumeratedArray.h"
+#include "mozilla/ErrorResult.h"
+#include "mozilla/gfx/2D.h"
 #include "mozilla/LinkedList.h"
 #include "mozilla/UniquePtr.h"
 #include "mozilla/WeakPtr.h"
-
-#include "GLDefs.h"
-#include "WebGLActiveInfo.h"
-#include "WebGLContextUnchecked.h"
-#include "WebGLFormats.h"
-#include "WebGLObjectModel.h"
-#include "WebGLRenderbuffer.h"
-#include "WebGLTexture.h"
-#include "WebGLShaderValidator.h"
-#include "WebGLStrongTypes.h"
-#include <stdarg.h>
-
+#include "nsCycleCollectionNoteChild.h"
+#include "nsICanvasRenderingContextInternal.h"
+#include "nsLayoutUtils.h"
 #include "nsTArray.h"
-#include "nsCycleCollectionNoteChild.h"
-
-#include "nsIDOMWebGLRenderingContext.h"
-#include "nsICanvasRenderingContextInternal.h"
-#include "mozilla/dom/HTMLCanvasElement.h"
 #include "nsWrapperCache.h"
-#include "nsIObserver.h"
-#include "nsIDOMEventListener.h"
-#include "nsLayoutUtils.h"
-
-#include "GLContextProvider.h"
-
-#include "mozilla/gfx/2D.h"
 
 #ifdef XP_MACOSX
 #include "ForceDiscreteGPUHelperCGL.h"
 #endif
 
-#include "mozilla/dom/TypedArray.h"
-#include "mozilla/ErrorResult.h"
+// Local
+#include "WebGLContextUnchecked.h"
+#include "WebGLFormats.h"
+#include "WebGLObjectModel.h"
+#include "WebGLStrongTypes.h"
+
+// Generated
+#include "nsIDOMEventListener.h"
+#include "nsIDOMWebGLRenderingContext.h"
+#include "nsIObserver.h"
+
 
 class nsIDocShell;
 
 /*
  * Minimum value constants defined in 6.2 State Tables of OpenGL ES - 2.0.25
  *   https://bugzilla.mozilla.org/show_bug.cgi?id=686732
  *
  * Exceptions: some of the following values are set to higher values than in the spec because
@@ -103,16 +98,17 @@ template<typename> struct Nullable;
 } // namespace dom
 
 namespace gfx {
 class SourceSurface;
 } // namespace gfx
 
 namespace webgl {
 struct LinkedProgramInfo;
+class ShaderValidator;
 } // namespace webgl
 
 WebGLTexelFormat GetWebGLTexelFormat(TexInternalFormat format);
 
 void AssertUintParamCorrect(gl::GLContext* gl, GLenum pname, GLuint shadow);
 
 struct WebGLContextOptions
 {
@@ -196,24 +192,28 @@ class WebGLContext
         BROWSER_DEFAULT_WEBGL = 0x9244,
         UNMASKED_VENDOR_WEBGL = 0x9245,
         UNMASKED_RENDERER_WEBGL = 0x9246
     };
 
 public:
     WebGLContext();
 
+protected:
+    virtual ~WebGLContext();
+
+public:
     MOZ_DECLARE_WEAKREFERENCE_TYPENAME(WebGLContext)
 
     NS_DECL_CYCLE_COLLECTING_ISUPPORTS
 
     NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(WebGLContext,
                                                            nsIDOMWebGLRenderingContext)
 
-    virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override = 0;
+    virtual JSObject* WrapObject(JSContext* cx, JS::Handle<JSObject*> givenProto) override = 0;
 
     NS_DECL_NSIDOMWEBGLRENDERINGCONTEXT
 
     // nsICanvasRenderingContextInternal
 #ifdef DEBUG
     virtual int32_t GetWidth() const override;
     virtual int32_t GetHeight() const override;
 #endif
@@ -537,17 +537,17 @@ public:
     bool IsTexture(WebGLTexture* tex);
     bool IsVertexArray(WebGLVertexArray* vao);
     void LineWidth(GLfloat width);
     void LinkProgram(WebGLProgram* prog);
     void PixelStorei(GLenum pname, GLint param);
     void PolygonOffset(GLfloat factor, GLfloat units);
     void ReadPixels(GLint x, GLint y, GLsizei width, GLsizei height,
                     GLenum format, GLenum type,
-                    const Nullable<dom::ArrayBufferView>& pixels,
+                    const dom::Nullable<dom::ArrayBufferView>& pixels,
                     ErrorResult& rv);
     void RenderbufferStorage(GLenum target, GLenum internalFormat,
                              GLsizei width, GLsizei height);
 protected:
     void RenderbufferStorage_base(const char* funcName, GLenum target,
                                   GLsizei samples, GLenum internalformat,
                                   GLsizei width, GLsizei height);
 public:
@@ -558,17 +558,17 @@ public:
     void StencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask);
     void StencilMask(GLuint mask);
     void StencilMaskSeparate(GLenum face, GLuint mask);
     void StencilOp(GLenum sfail, GLenum dpfail, GLenum dppass);
     void StencilOpSeparate(GLenum face, GLenum sfail, GLenum dpfail,
                            GLenum dppass);
     void TexImage2D(GLenum texImageTarget, GLint level, GLenum internalFormat,
                     GLsizei width, GLsizei height, GLint border, GLenum format,
-                    GLenum type, const Nullable<dom::ArrayBufferView>& pixels,
+                    GLenum type, const dom::Nullable<dom::ArrayBufferView>& pixels,
                     ErrorResult& rv);
     void TexImage2D(GLenum texImageTarget, GLint level, GLenum internalFormat,
                     GLenum format, GLenum type, dom::ImageData* pixels,
                     ErrorResult& rv);
     // Allow whatever element types the bindings are willing to pass
     // us in TexImage2D
     bool TexImageFromVideoElement(TexImageTarget texImageTarget, GLint level,
                                   GLenum internalFormat, GLenum format,
@@ -635,83 +635,35 @@ public:
     }
     void TexParameteri(GLenum target, GLenum pname, GLint param) {
         TexParameter_base(target, pname, &param, nullptr);
     }
 
     void TexSubImage2D(GLenum texImageTarget, GLint level, GLint xoffset,
                        GLint yoffset, GLsizei width, GLsizei height,
                        GLenum format, GLenum type,
-                       const Nullable<dom::ArrayBufferView>& pixels,
+                       const dom::Nullable<dom::ArrayBufferView>& pixels,
                        ErrorResult& rv);
     void TexSubImage2D(GLenum texImageTarget, GLint level, GLint xoffset,
                        GLint yoffset, GLenum format, GLenum type,
                        dom::ImageData* pixels, ErrorResult& rv);
+
+    void TexSubImage2D(GLenum rawTexImageTarget, GLint level, GLint xoffset,
+                       GLint yoffset, GLenum format, GLenum type,
+                       dom::Element* elt, ErrorResult* const out_rv);
+
     // Allow whatever element types the bindings are willing to pass
     // us in TexSubImage2D
     template<class ElementType>
     void TexSubImage2D(GLenum rawTexImageTarget, GLint level, GLint xoffset,
                        GLint yoffset, GLenum format, GLenum type,
-                       ElementType& elt, ErrorResult& rv)
+                       ElementType& elt, ErrorResult& out_rv)
     {
-        // TODO: Consolidate all the parameter validation
-        // checks. Instead of spreading out the cheks in multple
-        // places, consolidate into one spot.
-
-        if (IsContextLost())
-            return;
-
-        if (!ValidateTexImageTarget(rawTexImageTarget,
-                                    WebGLTexImageFunc::TexSubImage,
-                                    WebGLTexDimensions::Tex2D))
-        {
-            ErrorInvalidEnumInfo("texSubImage2D: target", rawTexImageTarget);
-            return;
-        }
-
-        const TexImageTarget texImageTarget(rawTexImageTarget);
-
-        if (level < 0)
-            return ErrorInvalidValue("texSubImage2D: level is negative");
-
-        const int32_t maxLevel = MaxTextureLevelForTexImageTarget(texImageTarget);
-        if (level > maxLevel) {
-            ErrorInvalidValue("texSubImage2D: level %d is too large, max is %d",
-                              level, maxLevel);
-            return;
-        }
-
-        WebGLTexture* tex = ActiveBoundTextureForTexImageTarget(texImageTarget);
-        if (!tex)
-            return ErrorInvalidOperation("texSubImage2D: no texture bound on active texture unit");
-
-        const WebGLTexture::ImageInfo& imageInfo = tex->ImageInfoAt(texImageTarget, level);
-        const TexInternalFormat internalFormat = imageInfo.EffectiveInternalFormat();
-
-        // Trying to handle the video by GPU directly first
-        if (TexImageFromVideoElement(texImageTarget, level,
-                                     internalFormat.get(), format, type, elt))
-        {
-            return;
-        }
-
-        RefPtr<gfx::DataSourceSurface> data;
-        WebGLTexelFormat srcFormat;
-        nsLayoutUtils::SurfaceFromElementResult res = SurfaceFromElement(elt);
-        rv = SurfaceFromElementResultToImageSurface(res, data, &srcFormat);
-        if (rv.Failed() || !data)
-            return;
-
-        gfx::IntSize size = data->GetSize();
-        uint32_t byteLength = data->Stride() * size.height;
-        return TexSubImage2D_base(texImageTarget.get(), level, xoffset, yoffset,
-                                  size.width, size.height, data->Stride(),
-                                  format, type, data->GetData(), byteLength,
-                                  js::Scalar::MaxTypedArrayViewType, srcFormat,
-                                  mPixelStorePremultiplyAlpha);
+        TexSubImage2D(rawTexImageTarget, level, xoffset, yoffset, format, type, &elt,
+                      &out_rv);
     }
 
     void Uniform1i(WebGLUniformLocation* loc, GLint x);
     void Uniform2i(WebGLUniformLocation* loc, GLint x, GLint y);
     void Uniform3i(WebGLUniformLocation* loc, GLint x, GLint y, GLint z);
     void Uniform4i(WebGLUniformLocation* loc, GLint x, GLint y, GLint z,
                    GLint w);
 
@@ -912,28 +864,28 @@ public:
 private:
     void BufferDataUnchecked(GLenum target, GLsizeiptr size, const GLvoid* data, GLenum usage);
     void BufferData(GLenum target, WebGLsizeiptr size, void* data, GLenum usage);
 
 public:
     void BufferData(GLenum target, WebGLsizeiptr size, GLenum usage);
     void BufferData(GLenum target, const dom::ArrayBufferView& data,
                     GLenum usage);
-    void BufferData(GLenum target, const Nullable<dom::ArrayBuffer>& maybeData,
+    void BufferData(GLenum target, const dom::Nullable<dom::ArrayBuffer>& maybeData,
                     GLenum usage);
 
 private:
     void BufferSubDataUnchecked(GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid* data);
     void BufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid* data);
 
 public:
     void BufferSubData(GLenum target, WebGLsizeiptr byteOffset,
                        const dom::ArrayBufferView& data);
     void BufferSubData(GLenum target, WebGLsizeiptr byteOffset,
-                       const Nullable<dom::ArrayBuffer>& maybeData);
+                       const dom::Nullable<dom::ArrayBuffer>& maybeData);
     already_AddRefed<WebGLBuffer> CreateBuffer();
     void DeleteBuffer(WebGLBuffer* buf);
     bool IsBuffer(WebGLBuffer* buf);
 
 protected:
     // bound buffer state
     WebGLRefPtr<WebGLBuffer> mBoundArrayBuffer;
     WebGLRefPtr<WebGLBuffer> mBoundCopyReadBuffer;
@@ -1082,18 +1034,16 @@ private:
                               const GLfloat* ptr);
 
     bool ValidateBufferFetching(const char* info);
     bool BindArrayAttribToLocation0(WebGLProgram* prog);
 
 // -----------------------------------------------------------------------------
 // PROTECTED
 protected:
-    virtual ~WebGLContext();
-
     void SetFakeBlackStatus(WebGLContextFakeBlackStatus x) {
         mFakeBlackStatus = x;
     }
     // Returns the current fake-black-status, except if it was Unknown,
     // in which case this function resolves it first, so it never returns Unknown.
     WebGLContextFakeBlackStatus ResolvedFakeBlackStatus();
 
     void BindFakeBlackTextures();
--- a/dom/canvas/WebGLContextDraw.cpp
+++ b/dom/canvas/WebGLContextDraw.cpp
@@ -12,19 +12,17 @@
 #include "WebGLFramebuffer.h"
 #include "WebGLProgram.h"
 #include "WebGLRenderbuffer.h"
 #include "WebGLShader.h"
 #include "WebGLTexture.h"
 #include "WebGLVertexArray.h"
 #include "WebGLVertexAttribData.h"
 
-using namespace mozilla;
-using namespace mozilla::dom;
-using namespace mozilla::gl;
+namespace mozilla {
 
 // For a Tegra workaround.
 static const int MAX_DRAW_CALLS_SINCE_FLUSH = 100;
 
 bool
 WebGLContext::DrawInstanced_check(const char* info)
 {
     // This restriction was removed in GLES3, so WebGL2 shouldn't have it.
@@ -743,17 +741,17 @@ WebGLContext::UnbindFakeBlackTextures()
             gl->fActiveTexture(LOCAL_GL_TEXTURE0 + i);
             gl->fBindTexture(LOCAL_GL_TEXTURE_CUBE_MAP, mBoundCubeMapTextures[i]->mGLName);
         }
     }
 
     gl->fActiveTexture(LOCAL_GL_TEXTURE0 + mActiveTexture);
 }
 
-WebGLContext::FakeBlackTexture::FakeBlackTexture(GLContext* gl, TexTarget target, GLenum format)
+WebGLContext::FakeBlackTexture::FakeBlackTexture(gl::GLContext* gl, TexTarget target, GLenum format)
     : mGL(gl)
     , mGLName(0)
 {
   MOZ_ASSERT(format == LOCAL_GL_RGB || format == LOCAL_GL_RGBA);
 
   mGL->MakeCurrent();
   GLuint formerBinding = 0;
   gl->GetUIntegerv(target == LOCAL_GL_TEXTURE_2D
@@ -783,8 +781,10 @@ WebGLContext::FakeBlackTexture::FakeBlac
 
 WebGLContext::FakeBlackTexture::~FakeBlackTexture()
 {
   if (mGL) {
       mGL->MakeCurrent();
       mGL->fDeleteTextures(1, &mGLName);
   }
 }
+
+} // namespace mozilla
--- a/dom/canvas/WebGLContextExtensions.cpp
+++ b/dom/canvas/WebGLContextExtensions.cpp
@@ -388,17 +388,17 @@ WebGLContext::EnableExtension(WebGLExten
         MOZ_ASSERT(false, "should not get there.");
     }
 
     mExtensions[ext] = obj;
 }
 
 void
 WebGLContext::GetSupportedExtensions(JSContext* cx,
-                                     Nullable< nsTArray<nsString> >& retval)
+                                     dom::Nullable< nsTArray<nsString> >& retval)
 {
     retval.SetNull();
     if (IsContextLost())
         return;
 
     nsTArray<nsString>& arr = retval.SetValue();
 
     for (size_t i = 0; i < size_t(WebGLExtensionID::Max); i++) {
--- a/dom/canvas/WebGLContextFramebufferOperations.cpp
+++ b/dom/canvas/WebGLContextFramebufferOperations.cpp
@@ -4,17 +4,17 @@
  * 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;
+namespace mozilla {
 
 void
 WebGLContext::Clear(GLbitfield mask)
 {
     if (IsContextLost())
         return;
 
     MakeContextCurrent();
@@ -245,11 +245,9 @@ WebGLContext::StencilMaskSeparate(GLenum
             mStencilWriteMaskBack = mask;
             break;
     }
 
     MakeContextCurrent();
     gl->fStencilMaskSeparate(face, mask);
 }
 
-
-
-
+} // namespace mozilla
--- a/dom/canvas/WebGLContextGL.cpp
+++ b/dom/canvas/WebGLContextGL.cpp
@@ -1,30 +1,33 @@
 /* -*- 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 "WebGLActiveInfo.h"
 #include "WebGLContextUtils.h"
 #include "WebGLBuffer.h"
 #include "WebGLVertexAttribData.h"
 #include "WebGLShader.h"
 #include "WebGLProgram.h"
 #include "WebGLUniformLocation.h"
 #include "WebGLFramebuffer.h"
 #include "WebGLRenderbuffer.h"
 #include "WebGLShaderPrecisionFormat.h"
 #include "WebGLTexture.h"
 #include "WebGLExtensions.h"
 #include "WebGLVertexArray.h"
 
-#include "nsString.h"
 #include "nsDebug.h"
 #include "nsReadableUtils.h"
+#include "../../xpcom/base/nsRefPtr.h"
+#include "nsString.h"
 
 #include "gfxContext.h"
 #include "gfxPlatform.h"
 #include "GLContext.h"
 
 #include "nsContentUtils.h"
 #include "nsError.h"
 #include "nsLayoutUtils.h"
@@ -44,17 +47,18 @@
 #endif
 
 #include "mozilla/DebugOnly.h"
 #include "mozilla/dom/BindingUtils.h"
 #include "mozilla/dom/ImageData.h"
 #include "mozilla/dom/ToJSValue.h"
 #include "mozilla/Endian.h"
 
-using namespace mozilla;
+namespace mozilla {
+
 using namespace mozilla::dom;
 using namespace mozilla::gfx;
 using namespace mozilla::gl;
 
 static const WebGLRectangleObject*
 CurValidFBRectObject(const WebGLContext* webgl,
                      const WebGLFramebuffer* boundFB)
 {
@@ -1018,17 +1022,17 @@ WebGLContext::GetActiveUniform(WebGLProg
     if (!ValidateObject("getActiveUniform: program", prog))
         return nullptr;
 
     return prog->GetActiveUniform(index);
 }
 
 void
 WebGLContext::GetAttachedShaders(WebGLProgram* prog,
-                                 Nullable<nsTArray<nsRefPtr<WebGLShader>>>& retval)
+                                 dom::Nullable<nsTArray<nsRefPtr<WebGLShader>>>& retval)
 {
     retval.SetNull();
     if (IsContextLost())
         return;
 
     if (!prog) {
         ErrorInvalidValue("getAttachedShaders: Invalid program.");
         return;
@@ -1135,17 +1139,17 @@ WebGLContext::GetFramebufferAttachmentPa
         attachment >= LOCAL_GL_COLOR_ATTACHMENT0 &&
         attachment <= LOCAL_GL_COLOR_ATTACHMENT15)
     {
         fb->EnsureColorAttachPoints(attachment - LOCAL_GL_COLOR_ATTACHMENT0);
     }
 
     MakeContextCurrent();
 
-    const WebGLFramebuffer::AttachPoint& fba = fb->GetAttachPoint(attachment);
+    const WebGLFBAttachPoint& fba = fb->GetAttachPoint(attachment);
 
     if (fba.Renderbuffer()) {
         switch (pname) {
             case LOCAL_GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING_EXT:
                 if (IsExtensionEnabled(WebGLExtensionID::EXT_sRGB)) {
                     const GLenum internalFormat = fba.Renderbuffer()->InternalFormat();
                     return (internalFormat == LOCAL_GL_SRGB_EXT ||
                             internalFormat == LOCAL_GL_SRGB_ALPHA_EXT ||
@@ -1967,17 +1971,17 @@ IsFormatAndTypeUnpackable(GLenum format,
     default:
         return false;
     }
 }
 
 void
 WebGLContext::ReadPixels(GLint x, GLint y, GLsizei width,
                          GLsizei height, GLenum format,
-                         GLenum type, const Nullable<ArrayBufferView> &pixels,
+                         GLenum type, const dom::Nullable<ArrayBufferView>& pixels,
                          ErrorResult& rv)
 {
     if (IsContextLost())
         return;
 
     if (mCanvasElement->IsWriteOnly() && !nsContentUtils::IsCallerChrome()) {
         GenerateWarning("readPixels: Not allowed");
         return rv.Throw(NS_ERROR_DOM_SECURITY_ERR);
@@ -2082,19 +2086,19 @@ WebGLContext::ReadPixels(GLint x, GLint 
 
     bool isSourceTypeFloat;
     if (mBoundReadFramebuffer) {
         TexInternalFormat srcFormat;
         if (!mBoundReadFramebuffer->ValidateForRead("readPixels", &srcFormat))
             return;
 
         MOZ_ASSERT(srcFormat != LOCAL_GL_NONE);
-        TexType type = TypeFromInternalFormat(srcFormat);
-        isSourceTypeFloat = (type == LOCAL_GL_FLOAT ||
-                             type == LOCAL_GL_HALF_FLOAT);
+        TexType texType = TypeFromInternalFormat(srcFormat);
+        isSourceTypeFloat = (texType == LOCAL_GL_FLOAT ||
+                             texType == LOCAL_GL_HALF_FLOAT);
     } else {
         ClearBackbufferIfNeeded();
 
         isSourceTypeFloat = false;
     }
 
     // Check the format and type params to assure they are an acceptable pair (as per spec)
 
@@ -3402,17 +3406,18 @@ WebGLContext::TexImage2D_base(TexImageTa
     tex->SetImageInfo(texImageTarget, level, width, height, 1,
                       effectiveInternalFormat, imageInfoStatusIfSuccess);
 }
 
 void
 WebGLContext::TexImage2D(GLenum rawTarget, GLint level,
                          GLenum internalformat, GLsizei width,
                          GLsizei height, GLint border, GLenum format,
-                         GLenum type, const Nullable<ArrayBufferView> &pixels, ErrorResult& rv)
+                         GLenum type, const dom::Nullable<ArrayBufferView>& pixels,
+                         ErrorResult& rv)
 {
     if (IsContextLost())
         return;
 
     void* data;
     uint32_t length;
     js::Scalar::Type jsArrayType;
     if (pixels.IsNull()) {
@@ -3603,17 +3608,17 @@ WebGLContext::TexSubImage2D_base(GLenum 
     gl->fTexSubImage2D(texImageTarget.get(), level, xoffset, yoffset, width, height, driverFormat, driverType, pixels);
 }
 
 void
 WebGLContext::TexSubImage2D(GLenum rawTarget, GLint level,
                             GLint xoffset, GLint yoffset,
                             GLsizei width, GLsizei height,
                             GLenum format, GLenum type,
-                            const Nullable<ArrayBufferView> &pixels,
+                            const dom::Nullable<ArrayBufferView>& pixels,
                             ErrorResult& rv)
 {
     if (IsContextLost())
         return;
 
     if (pixels.IsNull())
         return ErrorInvalidValue("texSubImage2D: pixels must not be null!");
 
@@ -3679,17 +3684,17 @@ WebGLContext::RestoreContext()
 
     if (!mAllowContextRestore)
         return ErrorInvalidOperation("restoreContext: Context cannot be restored.");
 
     ForceRestoreContext();
 }
 
 WebGLTexelFormat
-mozilla::GetWebGLTexelFormat(TexInternalFormat effectiveInternalFormat)
+GetWebGLTexelFormat(TexInternalFormat effectiveInternalFormat)
 {
     switch (effectiveInternalFormat.get()) {
         case LOCAL_GL_RGBA8:                  return WebGLTexelFormat::RGBA8;
         case LOCAL_GL_SRGB8_ALPHA8:           return WebGLTexelFormat::RGBA8;
         case LOCAL_GL_RGB8:                   return WebGLTexelFormat::RGB8;
         case LOCAL_GL_SRGB8:                  return WebGLTexelFormat::RGB8;
         case LOCAL_GL_ALPHA8:                 return WebGLTexelFormat::A8;
         case LOCAL_GL_LUMINANCE8:             return WebGLTexelFormat::R8;
@@ -3763,8 +3768,10 @@ WebGLContext::PolygonOffset(GLfloat fact
 
 void
 WebGLContext::SampleCoverage(GLclampf value, WebGLboolean invert) {
     if (IsContextLost())
         return;
     MakeContextCurrent();
     gl->fSampleCoverage(value, invert);
 }
+
+} // namespace mozilla
--- a/dom/canvas/WebGLContextReporter.cpp
+++ b/dom/canvas/WebGLContextReporter.cpp
@@ -1,17 +1,18 @@
 /* -*- 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 "WebGLMemoryTracker.h"
 
-using namespace mozilla;
+namespace mozilla {
 
 NS_IMPL_ISUPPORTS(WebGLObserver, nsIObserver)
 
 NS_IMETHODIMP
 WebGLMemoryTracker::CollectReports(nsIHandleReportCallback* handleReport,
                                    nsISupports* data, bool)
 {
 #define REPORT(_path, _kind, _units, _amount, _desc)                         \
@@ -146,8 +147,10 @@ WebGLMemoryTracker::GetShaderSize()
              shader;
              shader = shader->getNext())
         {
             result += shader->SizeOfIncludingThis(WebGLShaderMallocSizeOf);
         }
     }
     return result;
 }
+
+} // namespace mozilla
--- a/dom/canvas/WebGLContextState.cpp
+++ b/dom/canvas/WebGLContextState.cpp
@@ -10,18 +10,17 @@
 #include "WebGLProgram.h"
 #include "WebGLFramebuffer.h"
 #include "WebGLRenderbuffer.h"
 #include "WebGLTexture.h"
 #include "WebGLVertexArray.h"
 #include "GLContext.h"
 #include "mozilla/dom/ToJSValue.h"
 
-using namespace mozilla;
-using namespace dom;
+namespace mozilla {
 
 void
 WebGLContext::Disable(GLenum cap)
 {
     if (IsContextLost())
         return;
 
     if (!ValidateCapabilityEnum(cap, "disable"))
@@ -348,17 +347,18 @@ WebGLContext::GetParameter(JSContext* cx
 
         case LOCAL_GL_MAX_VARYING_VECTORS:
             return JS::Int32Value(mGLMaxVaryingVectors);
 
         case LOCAL_GL_NUM_COMPRESSED_TEXTURE_FORMATS:
             return JS::Int32Value(0);
         case LOCAL_GL_COMPRESSED_TEXTURE_FORMATS: {
             uint32_t length = mCompressedTextureFormats.Length();
-            JSObject* obj = Uint32Array::Create(cx, this, length, mCompressedTextureFormats.Elements());
+            JSObject* obj = dom::Uint32Array::Create(cx, this, length,
+                                                     mCompressedTextureFormats.Elements());
             if (!obj) {
                 rv = NS_ERROR_OUT_OF_MEMORY;
             }
             return JS::ObjectOrNullValue(obj);
         }
 
         // unsigned int. here we may have to return very large values like 2^32-1 that can't be represented as
         // javascript integer values. We just return them as doubles and javascript doesn't care.
@@ -414,66 +414,66 @@ WebGLContext::GetParameter(JSContext* cx
         // Complex values
 
         // 2 floats
         case LOCAL_GL_DEPTH_RANGE:
         case LOCAL_GL_ALIASED_POINT_SIZE_RANGE:
         case LOCAL_GL_ALIASED_LINE_WIDTH_RANGE: {
             GLfloat fv[2] = { 0 };
             gl->fGetFloatv(pname, fv);
-            JSObject* obj = Float32Array::Create(cx, this, 2, fv);
+            JSObject* obj = dom::Float32Array::Create(cx, this, 2, fv);
             if (!obj) {
                 rv = NS_ERROR_OUT_OF_MEMORY;
             }
             return JS::ObjectOrNullValue(obj);
         }
 
         // 4 floats
         case LOCAL_GL_COLOR_CLEAR_VALUE:
         case LOCAL_GL_BLEND_COLOR: {
             GLfloat fv[4] = { 0 };
             gl->fGetFloatv(pname, fv);
-            JSObject* obj = Float32Array::Create(cx, this, 4, fv);
+            JSObject* obj = dom::Float32Array::Create(cx, this, 4, fv);
             if (!obj) {
                 rv = NS_ERROR_OUT_OF_MEMORY;
             }
             return JS::ObjectOrNullValue(obj);
         }
 
         // 2 ints
         case LOCAL_GL_MAX_VIEWPORT_DIMS: {
             GLint iv[2] = { 0 };
             gl->fGetIntegerv(pname, iv);
-            JSObject* obj = Int32Array::Create(cx, this, 2, iv);
+            JSObject* obj = dom::Int32Array::Create(cx, this, 2, iv);
             if (!obj) {
                 rv = NS_ERROR_OUT_OF_MEMORY;
             }
             return JS::ObjectOrNullValue(obj);
         }
 
         // 4 ints
         case LOCAL_GL_SCISSOR_BOX:
         case LOCAL_GL_VIEWPORT: {
             GLint iv[4] = { 0 };
             gl->fGetIntegerv(pname, iv);
-            JSObject* obj = Int32Array::Create(cx, this, 4, iv);
+            JSObject* obj = dom::Int32Array::Create(cx, this, 4, iv);
             if (!obj) {
                 rv = NS_ERROR_OUT_OF_MEMORY;
             }
             return JS::ObjectOrNullValue(obj);
         }
 
         // 4 bools
         case LOCAL_GL_COLOR_WRITEMASK: {
             realGLboolean gl_bv[4] = { 0 };
             gl->fGetBooleanv(pname, gl_bv);
             bool vals[4] = { bool(gl_bv[0]), bool(gl_bv[1]),
                              bool(gl_bv[2]), bool(gl_bv[3]) };
             JS::Rooted<JS::Value> arr(cx);
-            if (!ToJSValue(cx, vals, &arr)) {
+            if (!dom::ToJSValue(cx, vals, &arr)) {
                 rv = NS_ERROR_OUT_OF_MEMORY;
             }
             return arr;
         }
 
         case LOCAL_GL_ARRAY_BUFFER_BINDING: {
             return WebGLObjectAsJSValue(cx, mBoundArrayBuffer.get(), rv);
         }
@@ -588,8 +588,10 @@ WebGLContext::GetStateTrackingSlot(GLenu
         case LOCAL_GL_SCISSOR_TEST:
             return &mScissorTestEnabled;
         case LOCAL_GL_STENCIL_TEST:
             return &mStencilTestEnabled;
     }
 
     return nullptr;
 }
+
+} // namespace mozilla
--- a/dom/canvas/WebGLContextUtils.cpp
+++ b/dom/canvas/WebGLContextUtils.cpp
@@ -22,18 +22,16 @@
 #include "WebGLFramebuffer.h"
 #include "WebGLProgram.h"
 #include "WebGLTexture.h"
 #include "WebGLVertexArray.h"
 #include "WebGLContextUtils.h"
 
 namespace mozilla {
 
-using namespace gl;
-
 bool
 IsGLDepthFormat(TexInternalFormat internalformat)
 {
     TexInternalFormat unsizedformat = UnsizedInternalFormatFromInternalFormat(internalformat);
     return unsizedformat == LOCAL_GL_DEPTH_COMPONENT;
 }
 
 bool
@@ -491,17 +489,17 @@ WebGLContext::GenerateWarning(const char
     PR_vsnprintf(buf, 1024, fmt, ap);
 
     // no need to print to stderr, as JS_ReportWarning takes care of this for us.
 
     if (!mCanvasElement) {
         return;
     }
 
-    AutoJSAPI api;
+    dom::AutoJSAPI api;
     if (!api.Init(mCanvasElement->OwnerDoc()->GetScopeObject())) {
         return;
     }
 
     JSContext* cx = api.cx();
     JS_ReportWarning(cx, "WebGL: %s", buf);
     if (!ShouldGenerateWarnings()) {
         JS_ReportWarning(cx,
--- a/dom/canvas/WebGLContextUtils.h
+++ b/dom/canvas/WebGLContextUtils.h
@@ -2,20 +2,22 @@
 /* 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 WEBGL_CONTEXT_UTILS_H_
 #define WEBGL_CONTEXT_UTILS_H_
 
 #include "WebGLContext.h"
-#include "WebGLStrongTypes.h"
+
 #include "mozilla/Assertions.h"
 #include "mozilla/dom/BindingUtils.h"
 
+#include "WebGLStrongTypes.h"
+
 namespace mozilla {
 
 bool IsGLDepthFormat(TexInternalFormat webGLFormat);
 bool IsGLDepthStencilFormat(TexInternalFormat webGLFormat);
 bool FormatHasAlpha(TexInternalFormat webGLFormat);
 
 void
 DriverFormatsFromEffectiveInternalFormat(gl::GLContext* gl,
--- a/dom/canvas/WebGLContextValidate.cpp
+++ b/dom/canvas/WebGLContextValidate.cpp
@@ -9,21 +9,23 @@
 #include "angle/ShaderLang.h"
 #include "CanvasUtils.h"
 #include "GLContext.h"
 #include "jsfriendapi.h"
 #include "mozilla/CheckedInt.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/Services.h"
 #include "nsIObserverService.h"
+#include "WebGLActiveInfo.h"
 #include "WebGLBuffer.h"
 #include "WebGLContextUtils.h"
 #include "WebGLFramebuffer.h"
 #include "WebGLProgram.h"
 #include "WebGLRenderbuffer.h"
+#include "WebGLSampler.h"
 #include "WebGLShader.h"
 #include "WebGLTexture.h"
 #include "WebGLUniformLocation.h"
 #include "WebGLValidateStrings.h"
 #include "WebGLVertexArray.h"
 #include "WebGLVertexAttribData.h"
 
 #if defined(MOZ_WIDGET_COCOA)
--- a/dom/canvas/WebGLContextVertices.cpp
+++ b/dom/canvas/WebGLContextVertices.cpp
@@ -11,18 +11,17 @@
 #include "WebGLFramebuffer.h"
 #include "WebGLProgram.h"
 #include "WebGLRenderbuffer.h"
 #include "WebGLShader.h"
 #include "WebGLTexture.h"
 #include "WebGLVertexArray.h"
 #include "WebGLVertexAttribData.h"
 
-using namespace mozilla;
-using namespace dom;
+namespace mozilla {
 
 void
 WebGLContext::VertexAttrib1f(GLuint index, GLfloat x0)
 {
     if (IsContextLost())
         return;
 
     if (!ValidateAttribIndex(index, "vertexAttrib1f"))
@@ -301,17 +300,17 @@ WebGLContext::GetVertexAttrib(JSContext*
             if (index) {
                 gl->fGetVertexAttribfv(index, LOCAL_GL_CURRENT_VERTEX_ATTRIB, &vec[0]);
             } else {
                 vec[0] = mVertexAttrib0Vector[0];
                 vec[1] = mVertexAttrib0Vector[1];
                 vec[2] = mVertexAttrib0Vector[2];
                 vec[3] = mVertexAttrib0Vector[3];
             }
-            JSObject* obj = Float32Array::Create(cx, this, 4, vec);
+            JSObject* obj = dom::Float32Array::Create(cx, this, 4, vec);
             if (!obj) {
                 rv.Throw(NS_ERROR_OUT_OF_MEMORY);
             }
             return JS::ObjectOrNullValue(obj);
         }
 
         case LOCAL_GL_VERTEX_ATTRIB_ARRAY_ENABLED:
         {
@@ -405,8 +404,10 @@ WebGLContext::VertexAttribDivisor(GLuint
     vd.divisor = divisor;
 
     InvalidateBufferFetching();
 
     MakeContextCurrent();
 
     gl->fVertexAttribDivisor(index, divisor);
 }
+
+} // namespace mozilla
--- a/dom/canvas/WebGLExtensionBase.cpp
+++ b/dom/canvas/WebGLExtensionBase.cpp
@@ -1,17 +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 "WebGLExtensions.h"
 
-using namespace mozilla;
+namespace mozilla {
 
 WebGLExtensionBase::WebGLExtensionBase(WebGLContext* context)
     : WebGLContextBoundObject(context)
     , mIsLost(false)
 {
 }
 
 WebGLExtensionBase::~WebGLExtensionBase()
@@ -23,8 +22,10 @@ WebGLExtensionBase::MarkLost()
 {
     mIsLost = true;
 }
 
 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_0(WebGLExtensionBase)
 
 NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(WebGLExtensionBase, AddRef)
 NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(WebGLExtensionBase, Release)
+
+} // namespace mozilla
--- a/dom/canvas/WebGLExtensions.h
+++ b/dom/canvas/WebGLExtensions.h
@@ -1,24 +1,30 @@
 /* -*- 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 WEBGL_EXTENSIONS_H_
 #define WEBGL_EXTENSIONS_H_
 
-#include "jsapi.h"
+#include "mozilla/AlreadyAddRefed.h"
 #include "mozilla/Attributes.h"
 #include "nsWrapperCache.h"
+
 #include "WebGLObjectModel.h"
 #include "WebGLTypes.h"
 
 namespace mozilla {
 
+namespace dom {
+template<typename T>
+class Sequence;
+} // namespace dom
+
 class WebGLContext;
 class WebGLShader;
 class WebGLQuery;
 class WebGLTimerQuery;
 class WebGLVertexArray;
 
 class WebGLExtensionBase
     : public nsWrapperCache
@@ -38,22 +44,22 @@ public:
 
 protected:
     virtual ~WebGLExtensionBase();
 
     bool mIsLost;
 };
 
 #define DECL_WEBGL_EXTENSION_GOOP \
-    virtual JSObject* WrapObject(JSContext* cx, JS::Handle<JSObject*> aGivenProto) override;
+    virtual JSObject* WrapObject(JSContext* cx, JS::Handle<JSObject*> givenProto) override;
 
 #define IMPL_WEBGL_EXTENSION_GOOP(WebGLExtensionType, WebGLBindingType)\
     JSObject*                                                    \
-    WebGLExtensionType::WrapObject(JSContext* cx, JS::Handle<JSObject*> aGivenProto) {              \
-        return dom::WebGLBindingType##Binding::Wrap(cx, this, aGivenProto); \
+    WebGLExtensionType::WrapObject(JSContext* cx, JS::Handle<JSObject*> givenProto) {              \
+        return dom::WebGLBindingType##Binding::Wrap(cx, this, givenProto); \
     }
 
 class WebGLExtensionCompressedTextureATC
     : public WebGLExtensionBase
 {
 public:
     explicit WebGLExtensionCompressedTextureATC(WebGLContext*);
     virtual ~WebGLExtensionCompressedTextureATC();
--- a/dom/canvas/WebGLFormats.cpp
+++ b/dom/canvas/WebGLFormats.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 "WebGLFormats.h"
 
+#include "GLDefs.h"
 #include "mozilla/StaticMutex.h"
 
 namespace mozilla {
 namespace webgl {
 
 //////////////////////////////////////////////////////////////////////////////////////////
 
 std::map<EffectiveFormat, const CompressedFormatInfo> gCompressedFormatInfoMap;
--- a/dom/canvas/WebGLFramebuffer.cpp
+++ b/dom/canvas/WebGLFramebuffer.cpp
@@ -10,46 +10,46 @@
 #include "WebGLContext.h"
 #include "WebGLContextUtils.h"
 #include "WebGLExtensions.h"
 #include "WebGLRenderbuffer.h"
 #include "WebGLTexture.h"
 
 namespace mozilla {
 
-WebGLFramebuffer::AttachPoint::AttachPoint(WebGLFramebuffer* fb,
-                                           FBAttachment attachmentPoint)
+WebGLFBAttachPoint::WebGLFBAttachPoint(WebGLFramebuffer* fb,
+                                       FBAttachment attachmentPoint)
     : mFB(fb)
     , mAttachmentPoint(attachmentPoint)
     , mTexImageTarget(LOCAL_GL_NONE)
 { }
 
-WebGLFramebuffer::AttachPoint::~AttachPoint()
+WebGLFBAttachPoint::~WebGLFBAttachPoint()
 {
     MOZ_ASSERT(!mRenderbufferPtr);
     MOZ_ASSERT(!mTexturePtr);
 }
 
 bool
-WebGLFramebuffer::AttachPoint::IsDeleteRequested() const
+WebGLFBAttachPoint::IsDeleteRequested() const
 {
     return Texture() ? Texture()->IsDeleteRequested()
          : Renderbuffer() ? Renderbuffer()->IsDeleteRequested()
          : false;
 }
 
 bool
-WebGLFramebuffer::AttachPoint::IsDefined() const
+WebGLFBAttachPoint::IsDefined() const
 {
     return Renderbuffer() ||
            (Texture() && Texture()->HasImageInfoAt(ImageTarget(), 0));
 }
 
 bool
-WebGLFramebuffer::AttachPoint::HasAlpha() const
+WebGLFBAttachPoint::HasAlpha() const
 {
     MOZ_ASSERT(HasImage());
 
     if (Texture() &&
         Texture()->HasImageInfoAt(mTexImageTarget, mTexImageLevel))
     {
         return FormatHasAlpha(Texture()->ImageInfoAt(mTexImageTarget,
                                                      mTexImageLevel).EffectiveInternalFormat());
@@ -57,17 +57,17 @@ WebGLFramebuffer::AttachPoint::HasAlpha(
 
     if (Renderbuffer())
         return FormatHasAlpha(Renderbuffer()->InternalFormat());
 
     return false;
 }
 
 GLenum
-WebGLFramebuffer::GetFormatForAttachment(const WebGLFramebuffer::AttachPoint& attachment) const
+WebGLFramebuffer::GetFormatForAttachment(const WebGLFBAttachPoint& attachment) const
 {
     MOZ_ASSERT(attachment.IsDefined());
     MOZ_ASSERT(attachment.Texture() || attachment.Renderbuffer());
 
     if (attachment.Texture()) {
         const WebGLTexture& tex = *attachment.Texture();
         MOZ_ASSERT(tex.HasImageInfoAt(attachment.ImageTarget(), 0));
 
@@ -78,86 +78,86 @@ WebGLFramebuffer::GetFormatForAttachment
 
     if (attachment.Renderbuffer())
         return attachment.Renderbuffer()->InternalFormat();
 
     return LOCAL_GL_NONE;
 }
 
 TexInternalFormat
-WebGLFramebuffer::AttachPoint::EffectiveInternalFormat() const
+WebGLFBAttachPoint::EffectiveInternalFormat() const
 {
     const WebGLTexture* tex = Texture();
     if (tex && tex->HasImageInfoAt(mTexImageTarget, mTexImageLevel)) {
         return tex->ImageInfoAt(mTexImageTarget,
                                 mTexImageLevel).EffectiveInternalFormat();
     }
 
     const WebGLRenderbuffer* rb = Renderbuffer();
     if (rb)
         return rb->InternalFormat();
 
     return LOCAL_GL_NONE;
 }
 
 bool
-WebGLFramebuffer::AttachPoint::IsReadableFloat() const
+WebGLFBAttachPoint::IsReadableFloat() const
 {
     TexInternalFormat internalformat = EffectiveInternalFormat();
     MOZ_ASSERT(internalformat != LOCAL_GL_NONE);
     TexType type = TypeFromInternalFormat(internalformat);
     return type == LOCAL_GL_FLOAT ||
            type == LOCAL_GL_HALF_FLOAT_OES ||
            type == LOCAL_GL_HALF_FLOAT;
 }
 
 static void
-UnmarkAttachment(WebGLFramebuffer::AttachPoint& attachment)
+UnmarkAttachment(WebGLFBAttachPoint& attachment)
 {
     WebGLFramebufferAttachable* maybe = attachment.Texture();
     if (!maybe)
         maybe = attachment.Renderbuffer();
 
     if (maybe)
         maybe->UnmarkAttachment(attachment);
 }
 
 void
-WebGLFramebuffer::AttachPoint::SetTexImage(WebGLTexture* tex, TexImageTarget target,
+WebGLFBAttachPoint::SetTexImage(WebGLTexture* tex, TexImageTarget target,
                                           GLint level)
 {
     mFB->InvalidateFramebufferStatus();
 
     UnmarkAttachment(*this);
 
     mTexturePtr = tex;
     mRenderbufferPtr = nullptr;
     mTexImageTarget = target;
     mTexImageLevel = level;
 
     if (tex)
         tex->MarkAttachment(*this);
 }
 
 void
-WebGLFramebuffer::AttachPoint::SetRenderbuffer(WebGLRenderbuffer* rb)
+WebGLFBAttachPoint::SetRenderbuffer(WebGLRenderbuffer* rb)
 {
     mFB->InvalidateFramebufferStatus();
 
     UnmarkAttachment(*this);
 
     mTexturePtr = nullptr;
     mRenderbufferPtr = rb;
 
     if (rb)
         rb->MarkAttachment(*this);
 }
 
 bool
-WebGLFramebuffer::AttachPoint::HasUninitializedImageData() const
+WebGLFBAttachPoint::HasUninitializedImageData() const
 {
     if (!HasImage())
         return false;
 
     if (Renderbuffer())
         return Renderbuffer()->HasUninitializedImageData();
 
     if (Texture()) {
@@ -166,17 +166,17 @@ WebGLFramebuffer::AttachPoint::HasUninit
                                       mTexImageLevel).HasUninitializedImageData();
     }
 
     MOZ_ASSERT(false, "Should not get here.");
     return false;
 }
 
 void
-WebGLFramebuffer::AttachPoint::SetImageDataStatus(WebGLImageDataStatus newStatus)
+WebGLFBAttachPoint::SetImageDataStatus(WebGLImageDataStatus newStatus)
 {
     if (!HasImage())
         return;
 
     if (Renderbuffer()) {
         Renderbuffer()->SetImageDataStatus(newStatus);
         return;
     }
@@ -186,29 +186,29 @@ WebGLFramebuffer::AttachPoint::SetImageD
                                       newStatus);
         return;
     }
 
     MOZ_ASSERT(false, "Should not get here.");
 }
 
 bool
-WebGLFramebuffer::AttachPoint::HasImage() const
+WebGLFBAttachPoint::HasImage() const
 {
     if (Texture() && Texture()->HasImageInfoAt(mTexImageTarget, mTexImageLevel))
         return true;
 
     if (Renderbuffer())
         return true;
 
     return false;
 }
 
 const WebGLRectangleObject&
-WebGLFramebuffer::AttachPoint::RectangleObject() const
+WebGLFBAttachPoint::RectangleObject() const
 {
     MOZ_ASSERT(HasImage(),
                "Make sure it has an image before requesting the rectangle.");
 
     if (Texture()) {
         MOZ_ASSERT(Texture()->HasImageInfoAt(mTexImageTarget, mTexImageLevel));
         return Texture()->ImageInfoAt(mTexImageTarget, mTexImageLevel);
     }
@@ -280,17 +280,17 @@ WebGLContext::IsFormatValidForFB(GLenum 
     case LOCAL_GL_RGBA16F:
         return IsExtensionEnabled(WebGLExtensionID::EXT_color_buffer_half_float);
     }
 
     return false;
 }
 
 bool
-WebGLFramebuffer::AttachPoint::IsComplete() const
+WebGLFBAttachPoint::IsComplete() const
 {
     if (!HasImage())
         return false;
 
     const WebGLRectangleObject& rect = RectangleObject();
 
     if (!rect.Width() ||
         !rect.Height())
@@ -348,17 +348,17 @@ WebGLFramebuffer::AttachPoint::IsComplet
         MOZ_ASSERT(false, "Invalid WebGL attachment point?");
         return false;
     }
     MOZ_ASSERT(false, "Should not get here.");
     return false;
 }
 
 void
-WebGLFramebuffer::AttachPoint::FinalizeAttachment(gl::GLContext* gl,
+WebGLFBAttachPoint::FinalizeAttachment(gl::GLContext* gl,
                                                  FBAttachment attachmentLoc) const
 {
     if (!HasImage()) {
         switch (attachmentLoc.get()) {
         case LOCAL_GL_DEPTH_ATTACHMENT:
         case LOCAL_GL_STENCIL_ATTACHMENT:
         case LOCAL_GL_DEPTH_STENCIL_ATTACHMENT:
             break;
@@ -449,17 +449,17 @@ WebGLFramebuffer::FramebufferRenderbuffe
 {
     MOZ_ASSERT(mContext->mBoundDrawFramebuffer == this ||
                mContext->mBoundReadFramebuffer == this);
 
     if (!mContext->ValidateObjectAllowNull("framebufferRenderbuffer: renderbuffer", rb))
         return;
 
     // `attachPoint` is validated by ValidateFramebufferAttachment().
-    AttachPoint& attachPoint = GetAttachPoint(attachPointEnum);
+    WebGLFBAttachPoint& attachPoint = GetAttachPoint(attachPointEnum);
     attachPoint.SetRenderbuffer(rb);
 
     InvalidateFramebufferStatus();
 }
 
 void
 WebGLFramebuffer::FramebufferTexture2D(FBAttachment attachPointEnum,
                                        TexImageTarget texImageTarget,
@@ -476,23 +476,23 @@ WebGLFramebuffer::FramebufferTexture2D(F
         bool isTexTarget2D = texImageTarget == LOCAL_GL_TEXTURE_2D;
         if (isTexture2D != isTexTarget2D) {
             mContext->ErrorInvalidOperation("framebufferTexture2D: Mismatched"
                                             " texture and texture target.");
             return;
         }
     }
 
-    AttachPoint& attachPoint = GetAttachPoint(attachPointEnum);
+    WebGLFBAttachPoint& attachPoint = GetAttachPoint(attachPointEnum);
     attachPoint.SetTexImage(tex, texImageTarget, level);
 
     InvalidateFramebufferStatus();
 }
 
-WebGLFramebuffer::AttachPoint&
+WebGLFBAttachPoint&
 WebGLFramebuffer::GetAttachPoint(FBAttachment attachPoint)
 {
     switch (attachPoint.get()) {
     case LOCAL_GL_COLOR_ATTACHMENT0:
         return mColorAttachment0;
 
     case LOCAL_GL_DEPTH_STENCIL_ATTACHMENT:
         return mDepthStencilAttachment;
@@ -576,17 +576,17 @@ WebGLFramebuffer::HasDefinedAttachments(
     for (size_t i = 0; i < moreColorAttachmentCount; i++) {
         hasAttachments |= mMoreColorAttachments[i].IsDefined();
     }
 
     return hasAttachments;
 }
 
 static bool
-IsIncomplete(const WebGLFramebuffer::AttachPoint& cur)
+IsIncomplete(const WebGLFBAttachPoint& cur)
 {
     return cur.IsDefined() && !cur.IsComplete();
 }
 
 bool
 WebGLFramebuffer::HasIncompleteAttachments() const
 {
     bool hasIncomplete = false;
@@ -626,17 +626,17 @@ WebGLFramebuffer::GetAnyRectObject() con
         if (mMoreColorAttachments[i].HasImage())
             return mMoreColorAttachments[i].RectangleObject();
     }
 
     MOZ_CRASH("Should not get here.");
 }
 
 static bool
-RectsMatch(const WebGLFramebuffer::AttachPoint& attachment,
+RectsMatch(const WebGLFBAttachPoint& attachment,
            const WebGLRectangleObject& rect)
 {
     return attachment.RectangleObject().HasSameDimensionsAs(rect);
 }
 
 bool
 WebGLFramebuffer::AllImageRectsMatch() const
 {
@@ -834,17 +834,17 @@ void WebGLFramebuffer::EnsureColorAttach
 {
     MOZ_ASSERT(colorAttachmentId < WebGLContext::kMaxColorAttachments);
 
     if (colorAttachmentId < ColorAttachmentCount())
         return;
 
     while (ColorAttachmentCount() < WebGLContext::kMaxColorAttachments) {
         GLenum nextAttachPoint = LOCAL_GL_COLOR_ATTACHMENT0 + ColorAttachmentCount();
-        mMoreColorAttachments.AppendElement(AttachPoint(this, nextAttachPoint));
+        mMoreColorAttachments.AppendElement(WebGLFBAttachPoint(this, nextAttachPoint));
     }
 
     MOZ_ASSERT(ColorAttachmentCount() == WebGLContext::kMaxColorAttachments);
 }
 
 static void
 FinalizeDrawAndReadBuffers(gl::GLContext* gl, bool isColorBufferDefined)
 {
@@ -936,30 +936,30 @@ WebGLFramebuffer::ValidateForRead(const 
     *out_format = attachPoint.EffectiveInternalFormat();
     return true;
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 // Goop.
 
 JSObject*
-WebGLFramebuffer::WrapObject(JSContext* cx, JS::Handle<JSObject*> aGivenProto)
+WebGLFramebuffer::WrapObject(JSContext* cx, JS::Handle<JSObject*> givenProto)
 {
-    return dom::WebGLFramebufferBinding::Wrap(cx, this, aGivenProto);
+    return dom::WebGLFramebufferBinding::Wrap(cx, this, givenProto);
 }
 
 inline void
-ImplCycleCollectionUnlink(mozilla::WebGLFramebuffer::AttachPoint& field)
+ImplCycleCollectionUnlink(mozilla::WebGLFBAttachPoint& field)
 {
     field.Unlink();
 }
 
 inline void
 ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& callback,
-                            mozilla::WebGLFramebuffer::AttachPoint& field,
+                            mozilla::WebGLFBAttachPoint& field,
                             const char* name,
                             uint32_t flags = 0)
 {
     CycleCollectionNoteChild(callback, field.Texture(), name, flags);
     CycleCollectionNoteChild(callback, field.Renderbuffer(), name, flags);
 }
 
 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(WebGLFramebuffer,
--- a/dom/canvas/WebGLFramebuffer.h
+++ b/dom/canvas/WebGLFramebuffer.h
@@ -2,120 +2,125 @@
 /* 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 WEBGL_FRAMEBUFFER_H_
 #define WEBGL_FRAMEBUFFER_H_
 
 #include "mozilla/LinkedList.h"
+#include "mozilla/WeakPtr.h"
 #include "nsWrapperCache.h"
+
 #include "WebGLObjectModel.h"
 #include "WebGLStrongTypes.h"
+#include "WebGLRenderbuffer.h"
+#include "WebGLTexture.h"
 
 namespace mozilla {
 
+class WebGLFramebuffer;
 class WebGLRenderbuffer;
 class WebGLTexture;
 
 namespace gl {
     class GLContext;
 } // namespace gl
 
+class WebGLFBAttachPoint
+{
+public:
+    WebGLFramebuffer* const mFB;
+private:
+    WebGLRefPtr<WebGLTexture> mTexturePtr;
+    WebGLRefPtr<WebGLRenderbuffer> mRenderbufferPtr;
+    FBAttachment mAttachmentPoint;
+    TexImageTarget mTexImageTarget;
+    GLint mTexImageLevel;
+
+public:
+    WebGLFBAttachPoint(WebGLFramebuffer* fb, FBAttachment attachmentPoint);
+    ~WebGLFBAttachPoint();
+
+    void Unlink() {
+        mRenderbufferPtr = nullptr;
+        mTexturePtr = nullptr;
+    }
+
+    bool IsDefined() const;
+    bool IsDeleteRequested() const;
+
+    TexInternalFormat EffectiveInternalFormat() const;
+
+    bool HasAlpha() const;
+    bool IsReadableFloat() const;
+
+    void Clear() {
+        SetRenderbuffer(nullptr);
+    }
+
+    void SetTexImage(WebGLTexture* tex, TexImageTarget target, GLint level);
+    void SetRenderbuffer(WebGLRenderbuffer* rb);
+
+    const WebGLTexture* Texture() const {
+        return mTexturePtr;
+    }
+    WebGLTexture* Texture() {
+        return mTexturePtr;
+    }
+    const WebGLRenderbuffer* Renderbuffer() const {
+        return mRenderbufferPtr;
+    }
+    WebGLRenderbuffer* Renderbuffer() {
+        return mRenderbufferPtr;
+    }
+    TexImageTarget ImageTarget() const {
+        return mTexImageTarget;
+    }
+    GLint MipLevel() const {
+        return mTexImageLevel;
+    }
+
+    bool HasUninitializedImageData() const;
+    void SetImageDataStatus(WebGLImageDataStatus x);
+
+    const WebGLRectangleObject& RectangleObject() const;
+
+    bool HasImage() const;
+    bool IsComplete() const;
+
+    void FinalizeAttachment(gl::GLContext* gl,
+                            FBAttachment attachmentLoc) const;
+};
+
 class WebGLFramebuffer final
     : public nsWrapperCache
     , public WebGLRefCountedObject<WebGLFramebuffer>
     , public LinkedListElement<WebGLFramebuffer>
     , public WebGLContextBoundObject
     , public SupportsWeakPtr<WebGLFramebuffer>
 {
     friend class WebGLContext;
 
 public:
     MOZ_DECLARE_WEAKREFERENCE_TYPENAME(WebGLFramebuffer)
 
-    class AttachPoint
-    {
-    public:
-        WebGLFramebuffer* const mFB;
-    private:
-        WebGLRefPtr<WebGLTexture> mTexturePtr;
-        WebGLRefPtr<WebGLRenderbuffer> mRenderbufferPtr;
-        FBAttachment mAttachmentPoint;
-        TexImageTarget mTexImageTarget;
-        GLint mTexImageLevel;
-
-    public:
-        AttachPoint(WebGLFramebuffer* fb, FBAttachment attachmentPoint);
-        ~AttachPoint();
-
-        void Unlink() {
-            mRenderbufferPtr = nullptr;
-            mTexturePtr = nullptr;
-        }
-
-        bool IsDefined() const;
-        bool IsDeleteRequested() const;
-
-        TexInternalFormat EffectiveInternalFormat() const;
-
-        bool HasAlpha() const;
-        bool IsReadableFloat() const;
-
-        void Clear() {
-            SetRenderbuffer(nullptr);
-        }
-
-        void SetTexImage(WebGLTexture* tex, TexImageTarget target, GLint level);
-        void SetRenderbuffer(WebGLRenderbuffer* rb);
-
-        const WebGLTexture* Texture() const {
-            return mTexturePtr;
-        }
-        WebGLTexture* Texture() {
-            return mTexturePtr;
-        }
-        const WebGLRenderbuffer* Renderbuffer() const {
-            return mRenderbufferPtr;
-        }
-        WebGLRenderbuffer* Renderbuffer() {
-            return mRenderbufferPtr;
-        }
-        TexImageTarget ImageTarget() const {
-            return mTexImageTarget;
-        }
-        GLint MipLevel() const {
-            return mTexImageLevel;
-        }
-
-        bool HasUninitializedImageData() const;
-        void SetImageDataStatus(WebGLImageDataStatus x);
-
-        const WebGLRectangleObject& RectangleObject() const;
-
-        bool HasImage() const;
-        bool IsComplete() const;
-
-        void FinalizeAttachment(gl::GLContext* gl,
-                                FBAttachment attachmentLoc) const;
-    };
-
     const GLuint mGLName;
 
 private:
     mutable GLenum mStatus;
 
     GLenum mReadBufferMode;
 
     // No need to chase pointers for the oft-used color0.
-    AttachPoint mColorAttachment0;
-    AttachPoint mDepthAttachment;
-    AttachPoint mStencilAttachment;
-    AttachPoint mDepthStencilAttachment;
-    nsTArray<AttachPoint> mMoreColorAttachments;
+    WebGLFBAttachPoint mColorAttachment0;
+    WebGLFBAttachPoint mDepthAttachment;
+    WebGLFBAttachPoint mStencilAttachment;
+    WebGLFBAttachPoint mDepthStencilAttachment;
+    nsTArray<WebGLFBAttachPoint> mMoreColorAttachments;
 
 #ifdef ANDROID
     // Bug 1140459: Some drivers (including our test slaves!) don't
     // give reasonable answers for IsRenderbuffer, maybe others.
     // This shows up on Android 2.3 emulator.
     //
     // So we track the `is a Framebuffer` state ourselves.
     bool mIsFB;
@@ -143,60 +148,60 @@ public:
 
     bool HasDefinedAttachments() const;
     bool HasIncompleteAttachments() const;
     bool AllImageRectsMatch() const;
     FBStatus PrecheckFramebufferStatus() const;
     FBStatus CheckFramebufferStatus() const;
 
     GLenum
-    GetFormatForAttachment(const WebGLFramebuffer::AttachPoint& attachment) const;
+    GetFormatForAttachment(const WebGLFBAttachPoint& attachment) const;
 
     bool HasDepthStencilConflict() const {
         return int(mDepthAttachment.IsDefined()) +
                int(mStencilAttachment.IsDefined()) +
                int(mDepthStencilAttachment.IsDefined()) >= 2;
     }
 
     size_t ColorAttachmentCount() const {
         return 1 + mMoreColorAttachments.Length();
     }
-    const AttachPoint& ColorAttachment(size_t colorAttachmentId) const {
+    const WebGLFBAttachPoint& ColorAttachment(size_t colorAttachmentId) const {
         MOZ_ASSERT(colorAttachmentId < ColorAttachmentCount());
         return colorAttachmentId ? mMoreColorAttachments[colorAttachmentId - 1]
                                  : mColorAttachment0;
     }
 
-    const AttachPoint& DepthAttachment() const {
+    const WebGLFBAttachPoint& DepthAttachment() const {
         return mDepthAttachment;
     }
 
-    const AttachPoint& StencilAttachment() const {
+    const WebGLFBAttachPoint& StencilAttachment() const {
         return mStencilAttachment;
     }
 
-    const AttachPoint& DepthStencilAttachment() const {
+    const WebGLFBAttachPoint& DepthStencilAttachment() const {
         return mDepthStencilAttachment;
     }
 
-    AttachPoint& GetAttachPoint(FBAttachment attachPointEnum);
+    WebGLFBAttachPoint& GetAttachPoint(FBAttachment attachPointEnum);
 
     void DetachTexture(const WebGLTexture* tex);
 
     void DetachRenderbuffer(const WebGLRenderbuffer* rb);
 
     const WebGLRectangleObject& RectangleObject() const;
 
     WebGLContext* GetParentObject() const {
         return Context();
     }
 
     void FinalizeAttachments() const;
 
-    virtual JSObject* WrapObject(JSContext* cx, JS::Handle<JSObject*> aGivenProto) override;
+    virtual JSObject* WrapObject(JSContext* cx, JS::Handle<JSObject*> givenProto) override;
 
     NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(WebGLFramebuffer)
     NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(WebGLFramebuffer)
 
     // mask mirrors glClear.
     bool HasCompletePlanes(GLbitfield mask);
 
     bool CheckAndInitializeAttachments();
--- a/dom/canvas/WebGLFramebufferAttachable.cpp
+++ b/dom/canvas/WebGLFramebufferAttachable.cpp
@@ -1,33 +1,30 @@
 /* -*- 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 "WebGLFramebufferAttachable.h"
 
-#include "WebGLContext.h"
 #include "WebGLFramebuffer.h"
-#include "WebGLRenderbuffer.h"
-#include "WebGLTexture.h"
 
 namespace mozilla {
 
 void
-WebGLFramebufferAttachable::MarkAttachment(const WebGLFramebuffer::AttachPoint& attachment)
+WebGLFramebufferAttachable::MarkAttachment(const WebGLFBAttachPoint& attachment)
 {
     if (mAttachmentPoints.Contains(&attachment))
         return; // Already attached. Ignore.
 
     mAttachmentPoints.AppendElement(&attachment);
 }
 
 void
-WebGLFramebufferAttachable::UnmarkAttachment(const WebGLFramebuffer::AttachPoint& attachment)
+WebGLFramebufferAttachable::UnmarkAttachment(const WebGLFBAttachPoint& attachment)
 {
     const size_t i = mAttachmentPoints.IndexOf(&attachment);
     if (i == mAttachmentPoints.NoIndex) {
         MOZ_ASSERT(false, "Is not attached to FB");
         return;
     }
 
     mAttachmentPoints.RemoveElementAt(i);
--- a/dom/canvas/WebGLFramebufferAttachable.h
+++ b/dom/canvas/WebGLFramebufferAttachable.h
@@ -1,30 +1,27 @@
 /* -*- 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/. */
 
 #ifndef WEBGL_FRAMEBUFFER_ATTACHABLE_H_
 #define WEBGL_FRAMEBUFFER_ATTACHABLE_H_
 
-#include "GLDefs.h"
-#include "mozilla/WeakPtr.h"
 #include "nsTArray.h"
-#include "WebGLFramebuffer.h"
-#include "WebGLStrongTypes.h"
 
 namespace mozilla {
+class WebGLFBAttachPoint;
 
 class WebGLFramebufferAttachable
 {
-    nsTArray<const WebGLFramebuffer::AttachPoint*> mAttachmentPoints;
+    nsTArray<const WebGLFBAttachPoint*> mAttachmentPoints;
 
 public:
     // Track FBO/Attachment combinations
-    void MarkAttachment(const WebGLFramebuffer::AttachPoint& attachment);
-    void UnmarkAttachment(const WebGLFramebuffer::AttachPoint& attachment);
+    void MarkAttachment(const WebGLFBAttachPoint& attachment);
+    void UnmarkAttachment(const WebGLFBAttachPoint& attachment);
     void InvalidateStatusOfAttachedFBs() const;
 };
 
 } // namespace mozilla
 
 #endif // !WEBGLFRAMEBUFFERATTACHABLE_H_
new file mode 100644
--- /dev/null
+++ b/dom/canvas/WebGLMemoryTracker.cpp
@@ -0,0 +1,275 @@
+/* -*- 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 "WebGLMemoryTracker.h"
+
+#include "WebGLBuffer.h"
+#include "WebGLContext.h"
+#include "WebGLVertexAttribData.h"
+#include "WebGLProgram.h"
+#include "WebGLRenderbuffer.h"
+#include "WebGLShader.h"
+#include "WebGLTexture.h"
+#include "WebGLUniformLocation.h"
+
+namespace mozilla {
+
+NS_IMPL_ISUPPORTS(WebGLObserver, nsIObserver)
+
+NS_IMETHODIMP
+WebGLMemoryTracker::CollectReports(nsIHandleReportCallback* handleReport,
+                                   nsISupports* data, bool)
+{
+#define REPORT(_path, _kind, _units, _amount, _desc)                         \
+    do {                                                                     \
+      nsresult rv;                                                           \
+      rv = handleReport->Callback(EmptyCString(), NS_LITERAL_CSTRING(_path), \
+                                   _kind, _units, _amount,                   \
+                                   NS_LITERAL_CSTRING(_desc), data);         \
+      NS_ENSURE_SUCCESS(rv, rv);                                             \
+    } while (0)
+
+    REPORT("webgl-texture-memory",
+           KIND_OTHER, UNITS_BYTES, GetTextureMemoryUsed(),
+           "Memory used by WebGL textures.The OpenGL"
+           " implementation is free to store these textures in either video"
+           " memory or main memory. This measurement is only a lower bound,"
+           " actual memory usage may be higher for example if the storage"
+           " is strided.");
+
+    REPORT("webgl-texture-count",
+           KIND_OTHER, UNITS_COUNT, GetTextureCount(),
+           "Number of WebGL textures.");
+
+    REPORT("webgl-buffer-memory",
+           KIND_OTHER, UNITS_BYTES, GetBufferMemoryUsed(),
+           "Memory used by WebGL buffers. The OpenGL"
+           " implementation is free to store these buffers in either video"
+           " memory or main memory. This measurement is only a lower bound,"
+           " actual memory usage may be higher for example if the storage"
+           " is strided.");
+
+    REPORT("explicit/webgl/buffer-cache-memory",
+           KIND_HEAP, UNITS_BYTES, GetBufferCacheMemoryUsed(),
+           "Memory used by WebGL buffer caches. The WebGL"
+           " implementation caches the contents of element array buffers"
+           " only.This adds up with the webgl-buffer-memory value, but"
+           " contrary to it, this one represents bytes on the heap,"
+           " not managed by OpenGL.");
+
+    REPORT("webgl-buffer-count",
+           KIND_OTHER, UNITS_COUNT, GetBufferCount(),
+           "Number of WebGL buffers.");
+
+    REPORT("webgl-renderbuffer-memory",
+           KIND_OTHER, UNITS_BYTES, GetRenderbufferMemoryUsed(),
+           "Memory used by WebGL renderbuffers. The OpenGL"
+           " implementation is free to store these renderbuffers in either"
+           " video memory or main memory. This measurement is only a lower"
+           " bound, actual memory usage may be higher for example if the"
+           " storage is strided.");
+
+    REPORT("webgl-renderbuffer-count",
+           KIND_OTHER, UNITS_COUNT, GetRenderbufferCount(),
+           "Number of WebGL renderbuffers.");
+
+    REPORT("explicit/webgl/shader",
+           KIND_HEAP, UNITS_BYTES, GetShaderSize(),
+           "Combined size of WebGL shader ASCII sources and translation"
+           " logs cached on the heap.");
+
+    REPORT("webgl-shader-count",
+           KIND_OTHER, UNITS_COUNT, GetShaderCount(),
+           "Number of WebGL shaders.");
+
+    REPORT("webgl-context-count",
+           KIND_OTHER, UNITS_COUNT, GetContextCount(),
+           "Number of WebGL contexts.");
+
+#undef REPORT
+
+    return NS_OK;
+}
+
+NS_IMPL_ISUPPORTS(WebGLMemoryTracker, nsIMemoryReporter)
+
+StaticRefPtr<WebGLMemoryTracker> WebGLMemoryTracker::sUniqueInstance;
+
+WebGLMemoryTracker*
+WebGLMemoryTracker::UniqueInstance()
+{
+    if (!sUniqueInstance) {
+        sUniqueInstance = new WebGLMemoryTracker;
+        sUniqueInstance->InitMemoryReporter();
+    }
+    return sUniqueInstance;
+}
+
+WebGLMemoryTracker::WebGLMemoryTracker()
+{
+}
+
+void
+WebGLMemoryTracker::InitMemoryReporter()
+{
+    RegisterWeakMemoryReporter(this);
+}
+
+WebGLMemoryTracker::~WebGLMemoryTracker()
+{
+    UnregisterWeakMemoryReporter(this);
+}
+
+MOZ_DEFINE_MALLOC_SIZE_OF(WebGLBufferMallocSizeOf)
+
+int64_t
+WebGLMemoryTracker::GetBufferCacheMemoryUsed()
+{
+    const ContextsArrayType& contexts = Contexts();
+    int64_t result = 0;
+    for(size_t i = 0; i < contexts.Length(); ++i) {
+        for (const WebGLBuffer* buffer = contexts[i]->mBuffers.getFirst();
+             buffer;
+             buffer = buffer->getNext())
+        {
+            if (buffer->Content() == WebGLBuffer::Kind::ElementArray) {
+                result += buffer->SizeOfIncludingThis(WebGLBufferMallocSizeOf);
+            }
+        }
+    }
+    return result;
+}
+
+MOZ_DEFINE_MALLOC_SIZE_OF(WebGLShaderMallocSizeOf)
+
+int64_t
+WebGLMemoryTracker::GetShaderSize()
+{
+    const ContextsArrayType& contexts = Contexts();
+    int64_t result = 0;
+    for(size_t i = 0; i < contexts.Length(); ++i) {
+        for (const WebGLShader* shader = contexts[i]->mShaders.getFirst();
+             shader;
+             shader = shader->getNext())
+        {
+            result += shader->SizeOfIncludingThis(WebGLShaderMallocSizeOf);
+        }
+    }
+    return result;
+}
+
+/*static*/ int64_t
+WebGLMemoryTracker::GetTextureMemoryUsed()
+{
+    const ContextsArrayType & contexts = Contexts();
+    int64_t result = 0;
+    for(size_t i = 0; i < contexts.Length(); ++i) {
+        for (const WebGLTexture* texture = contexts[i]->mTextures.getFirst();
+             texture;
+             texture = texture->getNext())
+        {
+            result += texture->MemoryUsage();
+        }
+    }
+    return result;
+}
+
+/*static*/ int64_t
+WebGLMemoryTracker::GetTextureCount()
+{
+    const ContextsArrayType & contexts = Contexts();
+    int64_t result = 0;
+    for(size_t i = 0; i < contexts.Length(); ++i) {
+        for (const WebGLTexture* texture = contexts[i]->mTextures.getFirst();
+             texture;
+             texture = texture->getNext())
+        {
+            result++;
+        }
+    }
+    return result;
+}
+
+/*static*/ int64_t
+WebGLMemoryTracker::GetBufferMemoryUsed()
+{
+    const ContextsArrayType & contexts = Contexts();
+    int64_t result = 0;
+    for(size_t i = 0; i < contexts.Length(); ++i) {
+        for (const WebGLBuffer* buffer = contexts[i]->mBuffers.getFirst();
+             buffer;
+             buffer = buffer->getNext())
+        {
+            result += buffer->ByteLength();
+        }
+    }
+    return result;
+}
+
+/*static*/ int64_t
+WebGLMemoryTracker::GetBufferCount()
+{
+    const ContextsArrayType & contexts = Contexts();
+    int64_t result = 0;
+    for(size_t i = 0; i < contexts.Length(); ++i) {
+        for (const WebGLBuffer* buffer = contexts[i]->mBuffers.getFirst();
+             buffer;
+             buffer = buffer->getNext())
+        {
+            result++;
+        }
+    }
+    return result;
+}
+
+/*static*/ int64_t
+WebGLMemoryTracker::GetRenderbufferMemoryUsed()
+{
+    const ContextsArrayType & contexts = Contexts();
+    int64_t result = 0;
+    for(size_t i = 0; i < contexts.Length(); ++i) {
+        for (const WebGLRenderbuffer* rb = contexts[i]->mRenderbuffers.getFirst();
+             rb;
+             rb = rb->getNext())
+        {
+            result += rb->MemoryUsage();
+        }
+    }
+    return result;
+}
+
+/*static*/ int64_t
+WebGLMemoryTracker::GetRenderbufferCount()
+{
+    const ContextsArrayType & contexts = Contexts();
+    int64_t result = 0;
+    for(size_t i = 0; i < contexts.Length(); ++i) {
+        for (const WebGLRenderbuffer* rb = contexts[i]->mRenderbuffers.getFirst();
+             rb;
+             rb = rb->getNext())
+        {
+            result++;
+        }
+    }
+    return result;
+}
+
+/*static*/ int64_t
+WebGLMemoryTracker::GetShaderCount()
+{
+    const ContextsArrayType & contexts = Contexts();
+    int64_t result = 0;
+    for(size_t i = 0; i < contexts.Length(); ++i) {
+        for (const WebGLShader* shader = contexts[i]->mShaders.getFirst();
+             shader;
+             shader = shader->getNext())
+        {
+            result++;
+        }
+    }
+    return result;
+}
+
+} // namespace mozilla
--- a/dom/canvas/WebGLMemoryTracker.h
+++ b/dom/canvas/WebGLMemoryTracker.h
@@ -3,27 +3,21 @@
  * 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 WEBGL_MEMORY_TRACKER_H_
 #define WEBGL_MEMORY_TRACKER_H_
 
 #include "mozilla/StaticPtr.h"
 #include "nsIMemoryReporter.h"
-#include "WebGLBuffer.h"
-#include "WebGLContext.h"
-#include "WebGLVertexAttribData.h"
-#include "WebGLProgram.h"
-#include "WebGLRenderbuffer.h"
-#include "WebGLShader.h"
-#include "WebGLTexture.h"
-#include "WebGLUniformLocation.h"
 
 namespace mozilla {
 
+class WebGLContext;
+
 class WebGLMemoryTracker : public nsIMemoryReporter
 {
     NS_DECL_THREADSAFE_ISUPPORTS
     NS_DECL_NSIMEMORYREPORTER
 
     WebGLMemoryTracker();
     static StaticRefPtr<WebGLMemoryTracker> sUniqueInstance;
 
@@ -53,117 +47,33 @@ class WebGLMemoryTracker : public nsIMem
         if (contexts.IsEmpty()) {
             sUniqueInstance = nullptr;
         }
     }
 
   private:
     virtual ~WebGLMemoryTracker();
 
-    static int64_t GetTextureMemoryUsed() {
-        const ContextsArrayType & contexts = Contexts();
-        int64_t result = 0;
-        for(size_t i = 0; i < contexts.Length(); ++i) {
-            for (const WebGLTexture* texture = contexts[i]->mTextures.getFirst();
-                 texture;
-                 texture = texture->getNext())
-            {
-                result += texture->MemoryUsage();
-            }
-        }
-        return result;
-    }
+    static int64_t GetTextureMemoryUsed();
 
-    static int64_t GetTextureCount() {
-        const ContextsArrayType & contexts = Contexts();
-        int64_t result = 0;
-        for(size_t i = 0; i < contexts.Length(); ++i) {
-            for (const WebGLTexture* texture = contexts[i]->mTextures.getFirst();
-                 texture;
-                 texture = texture->getNext())
-            {
-                result++;
-            }
-        }
-        return result;
-    }
+    static int64_t GetTextureCount();
 
-    static int64_t GetBufferMemoryUsed() {
-        const ContextsArrayType & contexts = Contexts();
-        int64_t result = 0;
-        for(size_t i = 0; i < contexts.Length(); ++i) {
-            for (const WebGLBuffer* buffer = contexts[i]->mBuffers.getFirst();
-                 buffer;
-                 buffer = buffer->getNext())
-            {
-                result += buffer->ByteLength();
-            }
-        }
-        return result;
-    }
+    static int64_t GetBufferMemoryUsed();
 
     static int64_t GetBufferCacheMemoryUsed();
 
-    static int64_t GetBufferCount() {
-        const ContextsArrayType & contexts = Contexts();
-        int64_t result = 0;
-        for(size_t i = 0; i < contexts.Length(); ++i) {
-            for (const WebGLBuffer* buffer = contexts[i]->mBuffers.getFirst();
-                 buffer;
-                 buffer = buffer->getNext())
-            {
-                result++;
-            }
-        }
-        return result;
-    }
+    static int64_t GetBufferCount();
 
-    static int64_t GetRenderbufferMemoryUsed() {
-        const ContextsArrayType & contexts = Contexts();
-        int64_t result = 0;
-        for(size_t i = 0; i < contexts.Length(); ++i) {
-            for (const WebGLRenderbuffer* rb = contexts[i]->mRenderbuffers.getFirst();
-                 rb;
-                 rb = rb->getNext())
-            {
-                result += rb->MemoryUsage();
-            }
-        }
-        return result;
-    }
+    static int64_t GetRenderbufferMemoryUsed();
 
-    static int64_t GetRenderbufferCount() {
-        const ContextsArrayType & contexts = Contexts();
-        int64_t result = 0;
-        for(size_t i = 0; i < contexts.Length(); ++i) {
-            for (const WebGLRenderbuffer* rb = contexts[i]->mRenderbuffers.getFirst();
-                 rb;
-                 rb = rb->getNext())
-            {
-                result++;
-            }
-        }
-        return result;
-    }
+    static int64_t GetRenderbufferCount();
 
     static int64_t GetShaderSize();
 
-    static int64_t GetShaderCount() {
-        const ContextsArrayType & contexts = Contexts();
-        int64_t result = 0;
-        for(size_t i = 0; i < contexts.Length(); ++i) {
-            for (const WebGLShader* shader = contexts[i]->mShaders.getFirst();
-                 shader;
-                 shader = shader->getNext())
-            {
-                result++;
-            }
-        }
-        return result;
-    }
+    static int64_t GetShaderCount();
 
     static int64_t GetContextCount() {
         return Contexts().Length();
     }
 };
 
 } // namespace mozilla
 
--- a/dom/canvas/WebGLObjectModel.h
+++ b/dom/canvas/WebGLObjectModel.h
@@ -2,17 +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/. */
 
 #ifndef WEBGLOBJECTMODEL_H_
 #define WEBGLOBJECTMODEL_H_
 
 #include "nsCycleCollectionNoteChild.h"
-#include "nsICanvasRenderingContextInternal.h"
+
 #include "WebGLTypes.h"
 
 namespace mozilla {
 
 class WebGLContext;
 
 /* Each WebGL object class WebGLFoo wants to:
  *  - inherit WebGLRefCountedObject<WebGLFoo>
--- a/dom/canvas/WebGLProgram.cpp
+++ b/dom/canvas/WebGLProgram.cpp
@@ -1,17 +1,21 @@
 /* -*- 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 "WebGLProgram.h"
 
 #include "GLContext.h"
+#include "mozilla/CheckedInt.h"
+#include "mozilla/dom/WebGL2RenderingContextBinding.h"
 #include "mozilla/dom/WebGLRenderingContextBinding.h"
+#include "nsRefPtr.h"
+#include "WebGLActiveInfo.h"
 #include "WebGLContext.h"
 #include "WebGLShader.h"
 #include "WebGLUniformLocation.h"
 #include "WebGLValidateStrings.h"
 
 namespace mozilla {
 
 /* If `name`: "foo[3]"
@@ -62,22 +66,22 @@ ParseName(const nsCString& name, nsCStri
     *out_isArray = true;
     *out_arrayIndex = indexNum;
     return true;
 }
 
 static void
 AddActiveInfo(WebGLContext* webgl, GLint elemCount, GLenum elemType, bool isArray,
               const nsACString& baseUserName, const nsACString& baseMappedName,
-              std::vector<nsRefPtr<WebGLActiveInfo>>* activeInfoList,
+              std::vector<RefPtr<WebGLActiveInfo>>* activeInfoList,
               std::map<nsCString, const WebGLActiveInfo*>* infoLocMap)
 {
-    nsRefPtr<WebGLActiveInfo> info = new WebGLActiveInfo(webgl, elemCount, elemType,
-                                                         isArray, baseUserName,
-                                                         baseMappedName);
+    RefPtr<WebGLActiveInfo> info = new WebGLActiveInfo(webgl, elemCount, elemType,
+                                                       isArray, baseUserName,
+                                                       baseMappedName);
     activeInfoList->push_back(info);
 
     infoLocMap->insert(std::make_pair(info->mBaseUserName, info.get()));
 }
 
 static void
 AddActiveBlockInfo(const nsACString& baseUserName,
                    const nsACString& baseMappedName,
@@ -197,20 +201,20 @@ QueryProgramInfo(WebGLProgram* prog, gl:
         nsAutoCString baseUserName;
         if (!prog->FindUniformByMappedName(baseMappedName, &baseUserName, &isArray)) {
             baseUserName = baseMappedName;
 
             if (needsCheckForArrays && !isArray) {
                 // By GLES 3, GetUniformLocation("foo[0]") should return -1 if `foo` is
                 // not an array. Our current linux Try slaves return the location of `foo`
                 // anyways, though.
-                std::string mappedName = baseMappedName.BeginReading();
-                mappedName += "[0]";
+                std::string mappedNameStr = baseMappedName.BeginReading();
+                mappedNameStr += "[0]";
 
-                GLint loc = gl->fGetUniformLocation(prog->mGLName, mappedName.c_str());
+                GLint loc = gl->fGetUniformLocation(prog->mGLName, mappedNameStr.c_str());
                 if (loc != -1)
                     isArray = true;
             }
         }
 
 #ifdef DUMP_SHADERVAR_MAPPINGS
         printf_stderr("[uniform %i] %s/%i/%s/%s\n", i, mappedName.BeginReading(),
                       (int)isArray, baseMappedName.BeginReading(),
@@ -241,24 +245,27 @@ QueryProgramInfo(WebGLProgram* prog, gl:
 
             nsAutoCString baseMappedName;
             bool isArray;
             size_t arrayIndex;
             if (!ParseName(mappedName, &baseMappedName, &isArray, &arrayIndex))
                 MOZ_CRASH("Failed to parse `mappedName` received from driver.");
 
             nsAutoCString baseUserName;
-            if (!prog->FindUniformBlockByMappedName(baseMappedName, &baseUserName, &isArray)) {
+            if (!prog->FindUniformBlockByMappedName(baseMappedName, &baseUserName,
+                                                    &isArray))
+            {
                 baseUserName = baseMappedName;
 
                 if (needsCheckForArrays && !isArray) {
-                    std::string mappedName = baseMappedName.BeginReading();
-                    mappedName += "[0]";
+                    std::string mappedNameStr = baseMappedName.BeginReading();
+                    mappedNameStr += "[0]";
 
-                    GLuint loc = gl->fGetUniformBlockIndex(prog->mGLName, mappedName.c_str());
+                    GLuint loc = gl->fGetUniformBlockIndex(prog->mGLName,
+                                                           mappedNameStr.c_str());
                     if (loc != LOCAL_GL_INVALID_INDEX)
                         isArray = true;
                 }
             }
 
 #ifdef DUMP_SHADERVAR_MAPPINGS
             printf_stderr("[uniform block %i] %s/%i/%s/%s\n", i, mappedName.BeginReading(),
                           (int)isArray, baseMappedName.BeginReading(),
@@ -272,18 +279,18 @@ QueryProgramInfo(WebGLProgram* prog, gl:
     }
 
     return info.forget();
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 
 
-webgl::LinkedProgramInfo::LinkedProgramInfo(WebGLProgram* aProg)
-    : prog(aProg)
+webgl::LinkedProgramInfo::LinkedProgramInfo(WebGLProgram* prog)
+    : prog(prog)
     , fragDataMap(nullptr)
 { }
 
 ////////////////////////////////////////////////////////////////////////////////
 // WebGLProgram
 
 static GLuint
 CreateProgram(gl::GLContext* gl)
@@ -295,16 +302,21 @@ CreateProgram(gl::GLContext* gl)
 WebGLProgram::WebGLProgram(WebGLContext* webgl)
     : WebGLContextBoundObject(webgl)
     , mGLName(CreateProgram(webgl->GL()))
     , mTransformFeedbackBufferMode(LOCAL_GL_NONE)
 {
     mContext->mPrograms.insertBack(this);
 }
 
+WebGLProgram::~WebGLProgram()
+{
+    DeleteOnce();
+}
+
 void
 WebGLProgram::Delete()
 {
     gl::GLContext* gl = mContext->GL();
 
     gl->MakeCurrent();
     gl->fDeleteProgram(mGLName);
 
@@ -420,17 +432,17 @@ WebGLProgram::GetActiveAttrib(GLuint ind
     const auto& activeList = mMostRecentLinkInfo->activeAttribs;
 
     if (index >= activeList.size()) {
         mContext->ErrorInvalidValue("`index` (%i) must be less than %s (%i).",
                                     index, "ACTIVE_ATTRIBS", activeList.size());
         return nullptr;
     }
 
-    nsRefPtr<WebGLActiveInfo> ret =  activeList[index];
+    RefPtr<WebGLActiveInfo> ret = activeList[index];
     return ret.forget();
 }
 
 already_AddRefed<WebGLActiveInfo>
 WebGLProgram::GetActiveUniform(GLuint index) const
 {
     if (!mMostRecentLinkInfo) {
         // According to the spec, this can return null.
@@ -441,17 +453,17 @@ WebGLProgram::GetActiveUniform(GLuint in
     const auto& activeList = mMostRecentLinkInfo->activeUniforms;
 
     if (index >= activeList.size()) {
         mContext->ErrorInvalidValue("`index` (%i) must be less than %s (%i).",
                                     index, "ACTIVE_UNIFORMS", activeList.size());
         return nullptr;
     }
 
-    nsRefPtr<WebGLActiveInfo> ret = activeList[index];
+    RefPtr<WebGLActiveInfo> ret = activeList[index];
     return ret.forget();
 }
 
 void
 WebGLProgram::GetAttachedShaders(nsTArray<nsRefPtr<WebGLShader>>* const out) const
 {
     out->TruncateLength(0);
 
@@ -622,17 +634,17 @@ WebGLProgram::GetActiveUniformBlockName(
 
     const webgl::UniformBlockInfo* blockInfo = linkInfo->uniformBlocks[uniformBlockIndex];
 
     retval.Assign(NS_ConvertASCIItoUTF16(blockInfo->mBaseUserName));
 }
 
 void
 WebGLProgram::GetActiveUniformBlockParam(GLuint uniformBlockIndex, GLenum pname,
-                                         Nullable<dom::OwningUnsignedLongOrUint32ArrayOrBoolean>& retval) const
+                                         dom::Nullable<dom::OwningUnsignedLongOrUint32ArrayOrBoolean>& retval) const
 {
     retval.SetNull();
     if (!IsLinked()) {
         mContext->ErrorInvalidOperation("getActiveUniformBlockParameter: `program` must be linked.");
         return;
     }
 
     const webgl::LinkedProgramInfo* linkInfo = LinkInfo();
@@ -658,17 +670,17 @@ WebGLProgram::GetActiveUniformBlockParam
         gl->fGetActiveUniformBlockiv(mGLName, uniformBlockIndex, pname, &param);
         retval.SetValue().SetAsUnsignedLong() = param;
         return;
     }
 }
 
 void
 WebGLProgram::GetActiveUniformBlockActiveUniforms(JSContext* cx, GLuint uniformBlockIndex,
-                                                  Nullable<dom::OwningUnsignedLongOrUint32ArrayOrBoolean>& retval,
+                                                  dom::Nullable<dom::OwningUnsignedLongOrUint32ArrayOrBoolean>& retval,
                                                   ErrorResult& rv) const
 {
     if (!IsLinked()) {
         mContext->ErrorInvalidOperation("getActiveUniformBlockParameter: `program` must be linked.");
         return;
     }
 
     const webgl::LinkedProgramInfo* linkInfo = LinkInfo();
@@ -1008,17 +1020,17 @@ WebGLProgram::GetTransformFeedbackVaryin
     }
 
     const nsCString& varyingUserName = mTransformFeedbackVaryings[index];
 
     WebGLActiveInfo* info;
     LinkInfo()->FindAttrib(varyingUserName, (const WebGLActiveInfo**) &info);
     MOZ_ASSERT(info);
 
-    nsRefPtr<WebGLActiveInfo> ret(info);
+    RefPtr<WebGLActiveInfo> ret(info);
     return ret.forget();
 }
 
 bool
 WebGLProgram::FindUniformBlockByMappedName(const nsACString& mappedName,
                                            nsCString* const out_userName,
                                            bool* const out_isArray) const
 {
@@ -1029,19 +1041,19 @@ WebGLProgram::FindUniformBlockByMappedNa
         return true;
 
     return false;
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 
 JSObject*
-WebGLProgram::WrapObject(JSContext* js, JS::Handle<JSObject*> aGivenProto)
+WebGLProgram::WrapObject(JSContext* js, JS::Handle<JSObject*> givenProto)
 {
-    return dom::WebGLProgramBinding::Wrap(js, this, aGivenProto);
+    return dom::WebGLProgramBinding::Wrap(js, this, givenProto);
 }
 
 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(WebGLProgram, mVertShader, mFragShader)
 
 NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(WebGLProgram, AddRef)
 NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(WebGLProgram, Release)
 
 } // namespace mozilla
--- a/dom/canvas/WebGLProgram.h
+++ b/dom/canvas/WebGLProgram.h
@@ -2,32 +2,43 @@
 /* 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 WEBGL_PROGRAM_H_
 #define WEBGL_PROGRAM_H_
 
 #include <map>
-#include "mozilla/CheckedInt.h"
-#include "mozilla/LinkedList.h"
-#include "mozilla/dom/WebGL2RenderingContextBinding.h"
-#include "nsString.h"
-#include "nsWrapperCache.h"
 #include <set>
 #include <vector>
+
+#include "mozilla/LinkedList.h"
+#include "mozilla/RefPtr.h"
+#include "mozilla/WeakPtr.h"
+#include "nsString.h"
+#include "nsWrapperCache.h"
+
 #include "WebGLObjectModel.h"
-#include "WebGLShader.h"
+
+
+template<class> class nsRefPtr;
 
 namespace mozilla {
-
+class ErrorResult;
 class WebGLActiveInfo;
 class WebGLProgram;
+class WebGLShader;
 class WebGLUniformLocation;
 
+namespace dom {
+template<typename> struct Nullable;
+class OwningUnsignedLongOrUint32ArrayOrBoolean;
+template<typename> class Sequence;
+} // namespace dom
+
 namespace webgl {
 
 struct UniformBlockInfo final
     : public RefCounted<UniformBlockInfo>
 {
     MOZ_DECLARE_REFCOUNTED_TYPENAME(UniformBlockInfo);
 
     const nsCString mBaseUserName;
@@ -43,31 +54,31 @@ struct UniformBlockInfo final
 struct LinkedProgramInfo final
     : public RefCounted<LinkedProgramInfo>
     , public SupportsWeakPtr<LinkedProgramInfo>
 {
     MOZ_DECLARE_REFCOUNTED_TYPENAME(LinkedProgramInfo)
     MOZ_DECLARE_WEAKREFERENCE_TYPENAME(LinkedProgramInfo)
 
     WebGLProgram* const prog;
-    std::vector<nsRefPtr<WebGLActiveInfo>> activeAttribs;
-    std::vector<nsRefPtr<WebGLActiveInfo>> activeUniforms;
+    std::vector<RefPtr<WebGLActiveInfo>> activeAttribs;
+    std::vector<RefPtr<WebGLActiveInfo>> activeUniforms;
 
     // Needed for Get{Attrib,Uniform}Location. The keys for these are non-mapped
     // user-facing `GLActiveInfo::name`s, without any final "[0]".
     std::map<nsCString, const WebGLActiveInfo*> attribMap;
     std::map<nsCString, const WebGLActiveInfo*> uniformMap;
     std::map<nsCString, const nsCString>* fragDataMap;
 
     std::vector<RefPtr<UniformBlockInfo>> uniformBlocks;
 
     // Needed for draw call validation.
     std::set<GLuint> activeAttribLocs;
 
-    explicit LinkedProgramInfo(WebGLProgram* aProg);
+    explicit LinkedProgramInfo(WebGLProgram* prog);
 
     bool FindAttrib(const nsCString& baseUserName,
                     const WebGLActiveInfo** const out_activeInfo) const
     {
         auto itr = attribMap.find(baseUserName);
         if (itr == attribMap.end())
             return false;
 
@@ -114,20 +125,16 @@ struct LinkedProgramInfo final
     bool HasActiveAttrib(GLuint loc) const {
         auto itr = activeAttribLocs.find(loc);
         return itr != activeAttribLocs.end();
     }
 };
 
 } // namespace webgl
 
-class WebGLShader;
-
-typedef nsDataHashtable<nsCStringHashKey, nsCString> CStringMap;
-
 class WebGLProgram final
     : public nsWrapperCache
     , public WebGLRefCountedObject<WebGLProgram>
     , public LinkedListElement<WebGLProgram>
     , public WebGLContextBoundObject
 {
 public:
     NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(WebGLProgram)
@@ -146,19 +153,19 @@ public:
     void GetAttachedShaders(nsTArray<nsRefPtr<WebGLShader>>* const out) const;
     GLint GetAttribLocation(const nsAString& name) const;
     GLint GetFragDataLocation(const nsAString& name) const;
     void GetProgramInfoLog(nsAString* const out) const;
     JS::Value GetProgramParameter(GLenum pname) const;
     GLuint GetUniformBlockIndex(const nsAString& name) const;
     void GetActiveUniformBlockName(GLuint uniformBlockIndex, nsAString& name) const;
     void GetActiveUniformBlockParam(GLuint uniformBlockIndex, GLenum pname,
-                                    Nullable<dom::OwningUnsignedLongOrUint32ArrayOrBoolean>& retval) const;
+                                    dom::Nullable<dom::OwningUnsignedLongOrUint32ArrayOrBoolean>& retval) const;
     void GetActiveUniformBlockActiveUniforms(JSContext* cx, GLuint uniformBlockIndex,
-                                             Nullable<dom::OwningUnsignedLongOrUint32ArrayOrBoolean>& retval,
+                                             dom::Nullable<dom::OwningUnsignedLongOrUint32ArrayOrBoolean>& retval,
                                              ErrorResult& rv) const;
     already_AddRefed<WebGLUniformLocation> GetUniformLocation(const nsAString& name) const;
     void UniformBlockBinding(GLuint uniformBlockIndex, GLuint uniformBlockBinding) const;
 
     bool LinkProgram();
     bool UseProgram() const;
     void ValidateProgram() const;
 
@@ -182,22 +189,20 @@ public:
     const webgl::LinkedProgramInfo* LinkInfo() const {
         return mMostRecentLinkInfo.get();
     }
 
     WebGLContext* GetParentObject() const {
         return Context();
     }
 
-    virtual JSObject* WrapObject(JSContext* js, JS::Handle<JSObject*> aGivenProto) override;
+    virtual JSObject* WrapObject(JSContext* js, JS::Handle<JSObject*> givenProto) override;
 
 private:
-    ~WebGLProgram() {
-        DeleteOnce();
-    }
+    ~WebGLProgram();
 
     bool LinkAndUpdate();
 
 public:
     const GLuint mGLName;
 
 private:
     WebGLRefPtr<WebGLShader> mVertShader;
--- a/dom/canvas/WebGLQuery.cpp
+++ b/dom/canvas/WebGLQuery.cpp
@@ -8,19 +8,19 @@
 #include "GLContext.h"
 #include "mozilla/dom/WebGL2RenderingContextBinding.h"
 #include "nsContentUtils.h"
 #include "WebGLContext.h"
 
 namespace mozilla {
 
 JSObject*
-WebGLQuery::WrapObject(JSContext* cx, JS::Handle<JSObject*> aGivenProto)
+WebGLQuery::WrapObject(JSContext* cx, JS::Handle<JSObject*> givenProto)
 {
-    return dom::WebGLQueryBinding::Wrap(cx, this, aGivenProto);
+    return dom::WebGLQueryBinding::Wrap(cx, this, givenProto);
 }
 
 WebGLQuery::WebGLQuery(WebGLContext* webgl)
     : WebGLContextBoundObject(webgl)
     , mGLName(0)
     , mType(0)
 {
     mContext->mQueries.insertBack(this);
--- a/dom/canvas/WebGLQuery.h
+++ b/dom/canvas/WebGLQuery.h
@@ -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/. */
 
 #ifndef WEBGL_QUERY_H_
 #define WEBGL_QUERY_H_
 
 #include "mozilla/LinkedList.h"
 #include "nsWrapperCache.h"
+
 #include "WebGLObjectModel.h"
 
 namespace mozilla {
 
 class WebGLQuery final
     : public nsWrapperCache
     , public WebGLRefCountedObject<WebGLQuery>
     , public LinkedListElement<WebGLQuery>
@@ -31,17 +32,17 @@ public:
     void Delete();
 
     // nsWrapperCache
     WebGLContext* GetParentObject() const {
         return Context();
     }
 
     // NS
-    virtual JSObject* WrapObject(JSContext* cx, JS::Handle<JSObject*> aGivenProto) override;
+    virtual JSObject* WrapObject(JSContext* cx, JS::Handle<JSObject*> givenProto) override;
 
     NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(WebGLQuery)
     NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(WebGLQuery)
 
 
 private:
     ~WebGLQuery() {
         DeleteOnce();
--- a/dom/canvas/WebGLRenderbuffer.cpp
+++ b/dom/canvas/WebGLRenderbuffer.cpp
@@ -4,16 +4,17 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "WebGLRenderbuffer.h"
 
 #include "GLContext.h"
 #include "mozilla/dom/WebGLRenderingContextBinding.h"
 #include "ScopedGLHelpers.h"
 #include "WebGLContext.h"
+#include "WebGLStrongTypes.h"
 #include "WebGLTexture.h"
 
 namespace mozilla {
 
 static GLenum
 DepthStencilDepthFormat(gl::GLContext* gl)
 {
     // We might not be able to get 24-bit, so let's pretend!
@@ -36,19 +37,19 @@ NeedsDepthStencilEmu(gl::GLContext* gl, 
     MOZ_ASSERT(internalFormat != LOCAL_GL_DEPTH_STENCIL);
     if (internalFormat != LOCAL_GL_DEPTH24_STENCIL8)
         return false;
 
     return !SupportsDepthStencil(gl);
 }
 
 JSObject*
-WebGLRenderbuffer::WrapObject(JSContext* cx, JS::Handle<JSObject*> aGivenProto)
+WebGLRenderbuffer::WrapObject(JSContext* cx, JS::Handle<JSObject*> givenProto)
 {
-    return dom::WebGLRenderbufferBinding::Wrap(cx, this, aGivenProto);
+    return dom::WebGLRenderbufferBinding::Wrap(cx, this, givenProto);
 }
 
 WebGLRenderbuffer::WebGLRenderbuffer(WebGLContext* webgl)
     : WebGLContextBoundObject(webgl)
     , mPrimaryRB(0)
     , mSecondaryRB(0)
     , mInternalFormat(0)
     , mInternalFormatForGL(0)
--- a/dom/canvas/WebGLRenderbuffer.h
+++ b/dom/canvas/WebGLRenderbuffer.h
@@ -3,18 +3,20 @@
  * 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 WEBGL_RENDERBUFFER_H_
 #define WEBGL_RENDERBUFFER_H_
 
 #include "mozilla/LinkedList.h"
 #include "nsWrapperCache.h"
+
 #include "WebGLFramebufferAttachable.h"
 #include "WebGLObjectModel.h"
+#include "WebGLStrongTypes.h"
 
 namespace mozilla {
 
 class WebGLRenderbuffer final
     : public nsWrapperCache
     , public WebGLRefCountedObject<WebGLRenderbuffer>
     , public LinkedListElement<WebGLRenderbuffer>
     , public WebGLRectangleObject
@@ -59,17 +61,17 @@ public:
 
     void BindRenderbuffer() const;
     void RenderbufferStorage(GLsizei samples, GLenum internalFormat,
                              GLsizei width, GLsizei height) const;
     void FramebufferRenderbuffer(FBAttachment attachment) const;
     // Only handles a subset of `pname`s.
     GLint GetRenderbufferParameter(RBTarget target, RBParam pname) const;
 
-    virtual JSObject* WrapObject(JSContext* cx, JS::Handle<JSObject*> aGivenProto) override;
+    virtual JSObject* WrapObject(JSContext* cx, JS::Handle<JSObject*> givenProto) override;
 
     NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(WebGLRenderbuffer)
     NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(WebGLRenderbuffer)
 
 protected:
     ~WebGLRenderbuffer() {
         DeleteOnce();
     }
--- a/dom/canvas/WebGLSampler.cpp
+++ b/dom/canvas/WebGLSampler.cpp
@@ -34,19 +34,19 @@ WebGLSampler::Delete()
 
 WebGLContext*
 WebGLSampler::GetParentObject() const
 {
     return Context();
 }
 
 JSObject*
-WebGLSampler::WrapObject(JSContext* cx, JS::Handle<JSObject*> aGivenProto)
+WebGLSampler::WrapObject(JSContext* cx, JS::Handle<JSObject*> givenProto)
 {
-    return dom::WebGLSamplerBinding::Wrap(cx, this, aGivenProto);
+    return dom::WebGLSamplerBinding::Wrap(cx, this, givenProto);
 }
 
 
 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_0(WebGLSampler)
 NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(WebGLSampler, AddRef)
 NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(WebGLSampler, Release)
 
 } // namespace mozilla
--- a/dom/canvas/WebGLSampler.h
+++ b/dom/canvas/WebGLSampler.h
@@ -23,17 +23,17 @@ class WebGLSampler final
 public:
     explicit WebGLSampler(WebGLContext* webgl, GLuint sampler);
 
     const GLuint mGLName;
 
     void Delete();
     WebGLContext* GetParentObject() const;
 
-    virtual JSObject* WrapObject(JSContext* cx, JS::Handle<JSObject*> aGivenProto) override;
+    virtual JSObject* WrapObject(JSContext* cx, JS::Handle<JSObject*> givenProto) override;
 
 private:
 
     NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(WebGLSampler)
     NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(WebGLSampler)
 
 private:
     ~WebGLSampler();
--- a/dom/canvas/WebGLShader.cpp
+++ b/dom/canvas/WebGLShader.cpp
@@ -398,19 +398,19 @@ WebGLShader::ApplyTransformFeedbackVaryi
 
     out_mappedVaryings->swap(mappedVaryings);
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 // Boilerplate
 
 JSObject*
-WebGLShader::WrapObject(JSContext* js, JS::Handle<JSObject*> aGivenProto)
+WebGLShader::WrapObject(JSContext* js, JS::Handle<JSObject*> givenProto)
 {
-    return dom::WebGLShaderBinding::Wrap(js, this, aGivenProto);
+    return dom::WebGLShaderBinding::Wrap(js, this, givenProto);
 }
 
 size_t
 WebGLShader::SizeOfIncludingThis(MallocSizeOf mallocSizeOf) const
 {
     size_t validatorSize = mValidator ? mallocSizeOf(mValidator.get())
                                       : 0;
     return mallocSizeOf(this) +
--- a/dom/canvas/WebGLShader.h
+++ b/dom/canvas/WebGLShader.h
@@ -1,20 +1,25 @@
 /* -*- 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/. */
 
 #ifndef WEBGL_SHADER_H_
 #define WEBGL_SHADER_H_
 
+#include <string>
+#include <vector>
+
 #include "GLDefs.h"
 #include "mozilla/LinkedList.h"
 #include "mozilla/MemoryReporting.h"
+#include "nsString.h"
 #include "nsWrapperCache.h"
+
 #include "WebGLObjectModel.h"
 
 namespace mozilla {
 
 namespace webgl {
 class ShaderValidator;
 } // namespace webgl
 
@@ -60,22 +65,22 @@ public:
     }
 
     void ApplyTransformFeedbackVaryings(GLuint prog,
                                         const std::vector<nsCString>& varyings,
                                         GLenum bufferMode,
                                         std::vector<std::string>* out_mappedVaryings) const;
 
     // Other funcs
-    size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
+    size_t SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf) const;
     void Delete();
 
     WebGLContext* GetParentObject() const { return Context(); }
 
-    virtual JSObject* WrapObject(JSContext* js, JS::Handle<JSObject*> aGivenProto) override;
+    virtual JSObject* WrapObject(JSContext* js, JS::Handle<JSObject*> givenProto) override;
 
     NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(WebGLShader)
     NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(WebGLShader)
 
 public:
     const GLuint mGLName;
     const GLenum mType;
 protected:
--- a/dom/canvas/WebGLShaderPrecisionFormat.cpp
+++ b/dom/canvas/WebGLShaderPrecisionFormat.cpp
@@ -6,16 +6,16 @@
 #include "WebGLShaderPrecisionFormat.h"
 
 #include "mozilla/dom/WebGLRenderingContextBinding.h"
 #include "WebGLContext.h"
 
 namespace mozilla {
 
 bool
-WebGLShaderPrecisionFormat::WrapObject(JSContext* aCx,
-                                       JS::Handle<JSObject*> aGivenProto,
-                                       JS::MutableHandle<JSObject*> aReflector)
+WebGLShaderPrecisionFormat::WrapObject(JSContext* cx,
+                                       JS::Handle<JSObject*> givenProto,
+                                       JS::MutableHandle<JSObject*> reflector)
 {
-    return dom::WebGLShaderPrecisionFormatBinding::Wrap(aCx, this, aGivenProto, aReflector);
+    return dom::WebGLShaderPrecisionFormatBinding::Wrap(cx, this, givenProto, reflector);
 }
 
 } // namespace mozilla
--- a/dom/canvas/WebGLShaderPrecisionFormat.h
+++ b/dom/canvas/WebGLShaderPrecisionFormat.h
@@ -17,17 +17,17 @@ public:
     WebGLShaderPrecisionFormat(WebGLContext* context, GLint rangeMin,
                                GLint rangeMax, GLint precision)
         : WebGLContextBoundObject(context)
         , mRangeMin(rangeMin)
         , mRangeMax(rangeMax)
         , mPrecision(precision)
     { }
 
-    bool WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector);
+    bool WrapObject(JSContext* cx, JS::Handle<JSObject*> givenProto, JS::MutableHandle<JSObject*> reflector);
 
     // WebIDL WebGLShaderPrecisionFormat API
     GLint RangeMin() const {
         return mRangeMin;
     }
 
     GLint RangeMax() const {
         return mRangeMax;
--- a/dom/canvas/WebGLStrongTypes.h
+++ b/dom/canvas/WebGLStrongTypes.h
@@ -1,16 +1,18 @@
 /* -*- 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/. */
 
 #ifndef WEBGL_STRONG_TYPES_H_
 #define WEBGL_STRONG_TYPES_H_
 
+#include <algorithm>
+
 #include "GLDefs.h"
 #include "mozilla/ArrayUtils.h"
 #include "mozilla/Assertions.h"
 #include "mozilla/Attributes.h"
 
 /* Usage:
  * ===========
  *
--- a/dom/canvas/WebGLSync.cpp
+++ b/dom/canvas/WebGLSync.cpp
@@ -1,16 +1,18 @@
 /* -*- 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 "WebGLSync.h"
 
+#include "GLContext.h"
 #include "mozilla/dom/WebGL2RenderingContextBinding.h"
+#include "WebGLContext.h"
 
 namespace mozilla {
 
 WebGLSync::WebGLSync(WebGLContext* webgl, GLenum condition, GLbitfield flags)
     : WebGLContextBoundObject(webgl)
 {
    mGLName = mContext->gl->fFenceSync(condition, flags);
 }
@@ -33,18 +35,18 @@ WebGLContext*
 WebGLSync::GetParentObject() const
 {
     return Context();
 }
 
 // -------------------------------------------------------------------------
 // IMPLEMENT NS
 JSObject*
-WebGLSync::WrapObject(JSContext* cx, JS::Handle<JSObject*> aGivenProto)
+WebGLSync::WrapObject(JSContext* cx, JS::Handle<JSObject*> givenProto)
 {
-    return dom::WebGLSyncBinding::Wrap(cx, this, aGivenProto);
+    return dom::WebGLSyncBinding::Wrap(cx, this, givenProto);
 }
 
 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_0(WebGLSync)
 NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(WebGLSync, AddRef)
 NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(WebGLSync, Release);
 
 } // namespace mozilla
--- a/dom/canvas/WebGLSync.h
+++ b/dom/canvas/WebGLSync.h
@@ -21,17 +21,17 @@ class WebGLSync final
     friend class WebGL2Context;
 
 public:
     WebGLSync(WebGLContext* webgl, GLenum condition, GLbitfield flags);
 
     void Delete();
     WebGLContext* GetParentObject() const;
 
-    virtual JSObject* WrapObject(JSContext* cx, JS::Handle<JSObject*> aGivenProto) override;
+    virtual JSObject* WrapObject(JSContext* cx, JS::Handle<JSObject*> givenProto) override;
 
     NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(WebGLSync)
     NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(WebGLSync)
 
 private:
     ~WebGLSync();
 
     GLsync mGLName;
--- a/dom/canvas/WebGLTexture.cpp
+++ b/dom/canvas/WebGLTexture.cpp
@@ -14,18 +14,18 @@
 #include "WebGLContext.h"
 #include "WebGLContextUtils.h"
 #include "WebGLTexelConversions.h"
 #include "mozilla/gfx/Logging.h"
 
 namespace mozilla {
 
 JSObject*
-WebGLTexture::WrapObject(JSContext* cx, JS::Handle<JSObject*> aGivenProto) {
-    return dom::WebGLTextureBinding::Wrap(cx, this, aGivenProto);
+WebGLTexture::WrapObject(JSContext* cx, JS::Handle<JSObject*> givenProto) {
+    return dom::WebGLTextureBinding::Wrap(cx, this, givenProto);
 }
 
 WebGLTexture::WebGLTexture(WebGLContext* webgl, GLuint tex)
     : WebGLContextBoundObject(webgl)
     , mGLName(tex)
     , mTarget(LOCAL_GL_NONE)
     , mMinFilter(LOCAL_GL_NEAREST_MIPMAP_LINEAR)
     , mMagFilter(LOCAL_GL_LINEAR)
--- a/dom/canvas/WebGLTexture.h
+++ b/dom/canvas/WebGLTexture.h
@@ -2,21 +2,22 @@
 /* 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 WEBGL_TEXTURE_H_
 #define WEBGL_TEXTURE_H_
 
 #include <algorithm>
+
 #include "mozilla/Assertions.h"
 #include "mozilla/CheckedInt.h"
 #include "mozilla/LinkedList.h"
-#include "nsAlgorithm.h"
 #include "nsWrapperCache.h"
+
 #include "WebGLFramebufferAttachable.h"
 #include "WebGLObjectModel.h"
 #include "WebGLStrongTypes.h"
 
 namespace mozilla {
 
 // Zero is not an integer power of two.
 inline bool
@@ -42,17 +43,17 @@ public:
 
     bool HasEverBeenBound() const { return mTarget != LOCAL_GL_NONE; }
     GLenum Target() const { return mTarget; }
 
     WebGLContext* GetParentObject() const {
         return Context();
     }
 
-    virtual JSObject* WrapObject(JSContext* cx, JS::Handle<JSObject*> aGivenProto) override;
+    virtual JSObject* WrapObject(JSContext* cx, JS::Handle<JSObject*> givenProto) override;
 
     NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(WebGLTexture)
     NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(WebGLTexture)
 
 protected:
     ~WebGLTexture() {
         DeleteOnce();
     }
--- a/dom/canvas/WebGLTimerQuery.cpp
+++ b/dom/canvas/WebGLTimerQuery.cpp
@@ -9,24 +9,24 @@
 #include "GLContext.h"
 #include "mozilla/dom/WebGLRenderingContextBinding.h"
 #include "nsContentUtils.h"
 #include "WebGLContext.h"
 
 namespace mozilla {
 
 JSObject*
-WebGLTimerQuery::WrapObject(JSContext* cx, JS::Handle<JSObject*> aGivenProto)
+WebGLTimerQuery::WrapObject(JSContext* cx, JS::Handle<JSObject*> givenProto)
 {
-  return dom::WebGLTimerQueryEXTBinding::Wrap(cx, this, aGivenProto);
+  return dom::WebGLTimerQueryEXTBinding::Wrap(cx, this, givenProto);
 }
 
-WebGLTimerQuery::WebGLTimerQuery(WebGLContext* webgl, GLuint aName)
+WebGLTimerQuery::WebGLTimerQuery(WebGLContext* webgl, GLuint name)
   : WebGLContextBoundObject(webgl)
-  , mGLName(aName)
+  , mGLName(name)
   , mTarget(LOCAL_GL_NONE)
 {
 }
 
 WebGLTimerQuery::~WebGLTimerQuery()
 {
   DeleteOnce();
 }
--- a/dom/canvas/WebGLTimerQuery.h
+++ b/dom/canvas/WebGLTimerQuery.h
@@ -24,25 +24,25 @@ public:
   void Delete();
 
   bool HasEverBeenBound() const { return mTarget != LOCAL_GL_NONE; }
   GLenum Target() const { return mTarget; }
 
   WebGLContext* GetParentObject() const;
 
   // NS
-  virtual JSObject* WrapObject(JSContext* cx, JS::Handle<JSObject*> aGivenProto) override;
+  virtual JSObject* WrapObject(JSContext* cx, JS::Handle<JSObject*> givenProto) override;
 
   const GLenum mGLName;
 
   NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(WebGLTimerQuery)
   NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(WebGLTimerQuery)
 
 private:
-  explicit WebGLTimerQuery(WebGLContext* webgl, GLuint aName);
+  explicit WebGLTimerQuery(WebGLContext* webgl, GLuint name);
   ~WebGLTimerQuery();
 
   GLenum mTarget;
 
   friend class WebGLExtensionDisjointTimerQuery;
 };
 
 } // namespace mozilla
--- a/dom/canvas/WebGLTransformFeedback.cpp
+++ b/dom/canvas/WebGLTransformFeedback.cpp
@@ -40,19 +40,19 @@ WebGLTransformFeedback::Delete()
 
 WebGLContext*
 WebGLTransformFeedback::GetParentObject() const
 {
     return Context();
 }
 
 JSObject*
-WebGLTransformFeedback::WrapObject(JSContext* cx, JS::Handle<JSObject*> aGivenProto)
+WebGLTransformFeedback::WrapObject(JSContext* cx, JS::Handle<JSObject*> givenProto)
 {
-    return dom::WebGLTransformFeedbackBinding::Wrap(cx, this, aGivenProto);
+    return dom::WebGLTransformFeedbackBinding::Wrap(cx, this, givenProto);
 }
 
 
 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_0(WebGLTransformFeedback)
 NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(WebGLTransformFeedback, AddRef)
 NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(WebGLTransformFeedback, Release)
 
 } // namespace mozilla
--- a/dom/canvas/WebGLTransformFeedback.h
+++ b/dom/canvas/WebGLTransformFeedback.h
@@ -21,17 +21,17 @@ class WebGLTransformFeedback final
     friend class WebGLContext;
     friend class WebGL2Context;
 
 public:
     explicit WebGLTransformFeedback(WebGLContext* webgl, GLuint tf);
 
     void Delete();
     WebGLContext* GetParentObject() const;
-    virtual JSObject* WrapObject(JSContext* cx, JS::Handle<JSObject*> aGivenProto) override;
+    virtual JSObject* WrapObject(JSContext* cx, JS::Handle<JSObject*> givenProto) override;
 
     const GLuint mGLName;
 
     NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(WebGLTransformFeedback)
     NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(WebGLTransformFeedback)
 
 private:
     ~WebGLTransformFeedback();
--- a/dom/canvas/WebGLUniformLocation.cpp
+++ b/dom/canvas/WebGLUniformLocation.cpp
@@ -316,19 +316,19 @@ WebGLUniformLocation::GetUniform(JSConte
     default:
         MOZ_CRASH("Invalid elemType.");
     }
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 
 JSObject*
-WebGLUniformLocation::WrapObject(JSContext* js, JS::Handle<JSObject*> aGivenProto)
+WebGLUniformLocation::WrapObject(JSContext* js, JS::Handle<JSObject*> givenProto)
 {
-    return dom::WebGLUniformLocationBinding::Wrap(js, this, aGivenProto);
+    return dom::WebGLUniformLocationBinding::Wrap(js, this, givenProto);
 }
 
 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_0(WebGLUniformLocation)
 
 NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(WebGLUniformLocation, AddRef)
 NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(WebGLUniformLocation, Release)
 
 } // namespace mozilla
--- a/dom/canvas/WebGLUniformLocation.h
+++ b/dom/canvas/WebGLUniformLocation.h
@@ -6,16 +6,17 @@
 #ifndef WEBGL_UNIFORM_LOCATION_H_
 #define WEBGL_UNIFORM_LOCATION_H_
 
 #include "GLDefs.h"
 #include "mozilla/WeakPtr.h"
 #include "nsCycleCollectionParticipant.h" // NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS
 #include "nsISupportsImpl.h" // NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING
 #include "nsWrapperCache.h"
+
 #include "WebGLObjectModel.h"
 
 struct JSContext;
 
 namespace mozilla {
 class WebGLActiveInfo;
 class WebGLContext;
 class WebGLProgram;
@@ -27,23 +28,22 @@ struct LinkedProgramInfo;
 class WebGLUniformLocation final
     : public nsWrapperCache
     , public WebGLContextBoundObject
 {
 public:
     NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(WebGLUniformLocation)
     NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(WebGLUniformLocation)
 
-    virtual JSObject* WrapObject(JSContext* js, JS::Handle<JSObject*> aGivenProto) override;
+    virtual JSObject* WrapObject(JSContext* js, JS::Handle<JSObject*> givenProto) override;
 
     WebGLContext* GetParentObject() const {
         return mContext;
     }
 
-
     const WeakPtr<const webgl::LinkedProgramInfo> mLinkInfo;
     const GLuint mLoc;
     const WebGLActiveInfo* const mActiveInfo;
 
     WebGLUniformLocation(WebGLContext* webgl, const webgl::LinkedProgramInfo* linkInfo,
                          GLuint loc, const WebGLActiveInfo* activeInfo);
 
     bool ValidateForProgram(WebGLProgram* prog, WebGLContext* webgl,
--- a/dom/canvas/WebGLVertexArray.cpp
+++ b/dom/canvas/WebGLVertexArray.cpp
@@ -10,19 +10,19 @@
 #include "WebGLBuffer.h"
 #include "WebGLContext.h"
 #include "WebGLVertexArrayGL.h"
 #include "WebGLVertexArrayFake.h"
 
 namespace mozilla {
 
 JSObject*
-WebGLVertexArray::WrapObject(JSContext* cx, JS::Handle<JSObject*> aGivenProto)
+WebGLVertexArray::WrapObject(JSContext* cx, JS::Handle<JSObject*> givenProto)
 {
-    return dom::WebGLVertexArrayObjectOESBinding::Wrap(cx, this, aGivenProto);
+    return dom::WebGLVertexArrayObjectOESBinding::Wrap(cx, this, givenProto);
 }
 
 WebGLVertexArray::WebGLVertexArray(WebGLContext* webgl)
     : WebGLContextBoundObject(webgl)
     , mGLName(0)
 {
     mContext->mVertexArrays.insertBack(this);
 }
--- a/dom/canvas/WebGLVertexArray.h
+++ b/dom/canvas/WebGLVertexArray.h
@@ -1,18 +1,20 @@
 /* -*- 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/. */
 
 #ifndef WEBGL_VERTEX_ARRAY_H_
 #define WEBGL_VERTEX_ARRAY_H_
 
+#include "nsTArray.h"
 #include "mozilla/LinkedList.h"
 #include "nsWrapperCache.h"
+
 #include "WebGLBuffer.h"
 #include "WebGLObjectModel.h"
 #include "WebGLStrongTypes.h"
 #include "WebGLVertexAttribData.h"
 
 namespace mozilla {
 
 class WebGLVertexArrayFake;
@@ -43,17 +45,17 @@ public:
     // Implement parent classes:
     void Delete();
     bool IsVertexArray();
 
     WebGLContext* GetParentObject() const {
         return Context();
     }
 
-    virtual JSObject* WrapObject(JSContext* cx, JS::Handle<JSObject*> aGivenProto) override;
+    virtual JSObject* WrapObject(JSContext* cx, JS::Handle<JSObject*> givenProto) override;
 
     NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(WebGLVertexArray)
     NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(WebGLVertexArray)
 
     GLuint GLName() const { return mGLName; }
 
 protected:
     explicit WebGLVertexArray(WebGLContext* webgl);
--- a/dom/canvas/WebGLVertexArrayObject.cpp
+++ b/dom/canvas/WebGLVertexArrayObject.cpp
@@ -1,17 +1,19 @@
 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
 /* 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 "WebGLVertexArrayObject.h"
 
+#include "GLContext.h"
 #include "mozilla/dom/WebGL2RenderingContextBinding.h"
+#include "WebGLContext.h"
 
 namespace mozilla {
 namespace dom {
 
 WebGLVertexArray*
 WebGLVertexArrayObject::Create(WebGLContext* webgl)
 {
   // WebGL 2: This is core in GL ES 3. If support is missing something
--- a/dom/canvas/compiledtest/TestWebGLElementArrayCache.cpp
+++ b/dom/canvas/compiledtest/TestWebGLElementArrayCache.cpp
@@ -8,18 +8,16 @@
 
 #include "WebGLElementArrayCache.cpp"
 
 #include <cstdlib>
 #include <iostream>
 #include "nscore.h"
 #include "nsTArray.h"
 
-using namespace mozilla;
-
 int gTestsPassed = 0;
 
 void
 VerifyImplFunction(bool condition, const char* file, int line)
 {
   if (condition) {
     gTestsPassed++;
   } else {
@@ -60,32 +58,33 @@ GLType()
   case 1:  return LOCAL_GL_UNSIGNED_BYTE;
   default:
     VERIFY(false);
     return 0;
   }
 }
 
 void
-CheckValidate(bool expectSuccess, WebGLElementArrayCache& c, GLenum type,
+CheckValidate(bool expectSuccess, mozilla::WebGLElementArrayCache& c, GLenum type,
               uint32_t maxAllowed, size_t first, size_t count)
 {
   uint32_t out_upperBound = 0;
   const bool success = c.Validate(type, maxAllowed, first, count, &out_upperBound);
   VERIFY(success == expectSuccess);
   if (success) {
     VERIFY(out_upperBound <= maxAllowed);
   } else {
     VERIFY(out_upperBound > maxAllowed);
   }
 }
 
 template<typename T>
 void
-CheckValidateOneTypeVariousBounds(WebGLElementArrayCache& c, size_t firstByte, size_t countBytes)
+CheckValidateOneTypeVariousBounds(mozilla::WebGLElementArrayCache& c, size_t firstByte,
+                                  size_t countBytes)
 {
   size_t first = firstByte / sizeof(T);
   size_t count = countBytes / sizeof(T);
 
   GLenum type = GLType<T>();
 
   T max = 0;
   for (size_t i = 0; i < count; i++)
@@ -96,17 +95,18 @@ CheckValidateOneTypeVariousBounds(WebGLE
   CheckValidate(true, c, type, T(-1), first, count);
   if (T(max + 1)) CheckValidate(true, c, type, T(max + 1), first, count);
   if (max > 0) {
     CheckValidate(false, c, type, max - 1, first, count);
     CheckValidate(false, c, type, 0, first, count);
   }
 }
 
-void CheckValidateAllTypes(WebGLElementArrayCache& c, size_t firstByte, size_t countBytes)
+void CheckValidateAllTypes(mozilla::WebGLElementArrayCache& c, size_t firstByte,
+                           size_t countBytes)
 {
   CheckValidateOneTypeVariousBounds<uint8_t>(c, firstByte, countBytes);
   CheckValidateOneTypeVariousBounds<uint16_t>(c, firstByte, countBytes);
   CheckValidateOneTypeVariousBounds<uint32_t>(c, firstByte, countBytes);
 }
 
 template<typename T>
 void
@@ -115,17 +115,17 @@ CheckSanity()
   const size_t numElems = 64; // should be significantly larger than tree leaf size to
                         // ensure we exercise some nontrivial tree-walking
   T data[numElems] = {1,0,3,1,2,6,5,4}; // intentionally specify only 8 elements for now
   size_t numBytes = numElems * sizeof(T);
   MOZ_RELEASE_ASSERT(numBytes == sizeof(data));
 
   GLenum type = GLType<T>();
 
-  WebGLElementArrayCache c;
+  mozilla::WebGLElementArrayCache c;
   c.BufferData(data, numBytes);
   CheckValidate(true,  c, type, 6, 0, 8);
   CheckValidate(false, c, type, 5, 0, 8);
   CheckValidate(true,  c, type, 3, 0, 3);
   CheckValidate(false, c, type, 2, 0, 3);
   CheckValidate(true,  c, type, 6, 2, 4);
   CheckValidate(false, c, type, 5, 2, 4);
 
@@ -156,17 +156,17 @@ CheckUintOverflow()
   const size_t numElems = 64; // should be significantly larger than tree leaf size to
                               // ensure we exercise some nontrivial tree-walking
   T data[numElems];
   size_t numBytes = numElems * sizeof(T);
   MOZ_RELEASE_ASSERT(numBytes == sizeof(data));
 
   GLenum type = GLType<T>();
 
-  WebGLElementArrayCache c;
+  mozilla::WebGLElementArrayCache c;
 
   for(size_t i = 0; i < numElems; i++)
     data[i] = numElems - i;
   c.BufferData(data, numBytes);
 
   // bug 825205
   uint32_t bigValWrappingToZero = uint32_t(T(-1)) + 1;
   CheckValidate(true,  c, type, bigValWrappingToZero,     0, numElems);
@@ -182,17 +182,17 @@ main(int argc, char* argv[])
   CheckSanity<uint8_t>();
   CheckSanity<uint16_t>();
   CheckSanity<uint32_t>();
 
   CheckUintOverflow<uint8_t>();
   CheckUintOverflow<uint16_t>();
 
   nsTArray<uint8_t> v, vsub;
-  WebGLElementArrayCache b;
+  mozilla::WebGLElementArrayCache b;
 
   for (int maxBufferSize = 1; maxBufferSize <= 4096; maxBufferSize *= 2) {
     // See bug 800612. We originally had | repeat = min(maxBufferSize, 20) |
     // and a real bug was only caught on Windows and not on Linux due to rand()
     // producing different values. In that case, the minimum value by which to replace
     // this 20 to reproduce the bug on Linux, was 25. Replacing it with 64 should give
     // us some comfort margin.
     int repeat = std::min(maxBufferSize, 64);
@@ -224,8 +224,9 @@ main(int argc, char* argv[])
         } // bufferSubDataCalls
       } // j
     } // i
   } // maxBufferSize
 
   std::cerr << argv[0] << ": all " << gTestsPassed << " tests passed" << std::endl;
   return 0;
 }
+
--- a/dom/canvas/moz.build
+++ b/dom/canvas/moz.build
@@ -71,17 +71,16 @@ UNIFIED_SOURCES += [
     'WebGLBuffer.cpp',
     'WebGLContext.cpp',
     'WebGLContextBuffers.cpp',
     'WebGLContextDraw.cpp',
     'WebGLContextExtensions.cpp',
     'WebGLContextFramebufferOperations.cpp',
     'WebGLContextGL.cpp',
     'WebGLContextLossHandler.cpp',
-    'WebGLContextReporter.cpp',
     'WebGLContextState.cpp',
     'WebGLContextUnchecked.cpp',
     'WebGLContextUtils.cpp',
     'WebGLContextValidate.cpp',
     'WebGLContextVertexArray.cpp',
     'WebGLContextVertices.cpp',
     'WebGLElementArrayCache.cpp',
     'WebGLExtensionBase.cpp',
@@ -108,16 +107,17 @@ UNIFIED_SOURCES += [
     'WebGLExtensionTextureFloat.cpp',
     'WebGLExtensionTextureFloatLinear.cpp',
     'WebGLExtensionTextureHalfFloat.cpp',
     'WebGLExtensionTextureHalfFloatLinear.cpp',
     'WebGLExtensionVertexArray.cpp',
     'WebGLFormats.cpp',
     'WebGLFramebuffer.cpp',
     'WebGLFramebufferAttachable.cpp',
+    'WebGLMemoryTracker.cpp',
     'WebGLObjectModel.cpp',
     'WebGLProgram.cpp',
     'WebGLQuery.cpp',
     'WebGLRenderbuffer.cpp',
     'WebGLSampler.cpp',
     'WebGLShader.cpp',
     'WebGLShaderPrecisionFormat.cpp',
     'WebGLShaderValidator.cpp',
@@ -128,17 +128,19 @@ UNIFIED_SOURCES += [
     'WebGLTransformFeedback.cpp',
     'WebGLUniformLocation.cpp',
     'WebGLValidateStrings.cpp',
     'WebGLVertexArray.cpp',
     'WebGLVertexArrayFake.cpp',
     'WebGLVertexArrayGL.cpp',
     'WebGLVertexArrayObject.cpp',
 ]
+
 LOCAL_INCLUDES += [
+    '../..', # Support `#include "mfbt/RefPtr.h"`
     '/js/xpconnect/wrappers',
 ]
 
 FAIL_ON_WARNINGS = True
 
 include('/ipc/chromium/chromium-config.mozbuild')
 
 FINAL_LIBRARY = 'xul'
--- a/dom/canvas/nsICanvasRenderingContextInternal.h
+++ b/dom/canvas/nsICanvasRenderingContextInternal.h
@@ -37,20 +37,20 @@ class nsICanvasRenderingContextInternal 
   public nsAPostRefreshObserver
 {
 public:
   typedef mozilla::layers::CanvasLayer CanvasLayer;
   typedef mozilla::layers::LayerManager LayerManager;
 
   NS_DECLARE_STATIC_IID_ACCESSOR(NS_ICANVASRENDERINGCONTEXTINTERNAL_IID)
 
-  void SetCanvasElement(mozilla::dom::HTMLCanvasElement* aParentCanvas)
+  void SetCanvasElement(mozilla::dom::HTMLCanvasElement* parentCanvas)
   {
     RemovePostRefreshObserver();
-    mCanvasElement = aParentCanvas;
+    mCanvasElement = parentCanvas;
     AddPostRefreshObserverIfNecessary();
   }
 
   virtual nsIPresShell *GetPresShell() {
     if (mCanvasElement) {
       return mCanvasElement->OwnerDoc()->GetShell();
     }
     return nullptr;
@@ -88,69 +88,69 @@ public:
 
   // Sets the dimensions of the canvas, in pixels.  Called
   // whenever the size of the element changes.
   NS_IMETHOD SetDimensions(int32_t width, int32_t height) = 0;
 
   NS_IMETHOD InitializeWithSurface(nsIDocShell *docShell, gfxASurface *surface, int32_t width, int32_t height) = 0;
 
   // Creates an image buffer. Returns null on failure.
-  virtual void GetImageBuffer(uint8_t** aImageBuffer, int32_t* aFormat) = 0;
+  virtual void GetImageBuffer(uint8_t** imageBuffer, int32_t* format) = 0;
 
   // Gives you a stream containing the image represented by this context.
-  // The format is given in aMimeTime, for example "image/png".
+  // The format is given in mimeTime, for example "image/png".
   //
-  // If the image format does not support transparency or aIncludeTransparency
+  // If the image format does not support transparency or includeTransparency
   // is false, alpha will be discarded and the result will be the image
   // composited on black.
-  NS_IMETHOD GetInputStream(const char *aMimeType,
-                            const char16_t *aEncoderOptions,
-                            nsIInputStream **aStream) = 0;
-  
+  NS_IMETHOD GetInputStream(const char *mimeType,
+                            const char16_t *encoderOptions,
+                            nsIInputStream **stream) = 0;
+
   // This gets an Azure SourceSurface for the canvas, this will be a snapshot
   // of the canvas at the time it was called.
-  // If aPremultAlpha is provided, then it assumed the callee can handle
-  // un-premultiplied surfaces, and *aPremultAlpha will be set to false
+  // If premultAlpha is provided, then it assumed the callee can handle
+  // un-premultiplied surfaces, and *premultAlpha will be set to false
   // if one is returned.
-  virtual already_AddRefed<mozilla::gfx::SourceSurface> GetSurfaceSnapshot(bool* aPremultAlpha = nullptr) = 0;
+  virtual already_AddRefed<mozilla::gfx::SourceSurface> GetSurfaceSnapshot(bool* premultAlpha = nullptr) = 0;
 
   // If this context is opaque, the backing store of the canvas should
   // be created as opaque; all compositing operators should assume the
   // dst alpha is always 1.0.  If this is never called, the context
   // defaults to false (not opaque).
   NS_IMETHOD SetIsOpaque(bool isOpaque) = 0;
   virtual bool GetIsOpaque() = 0;
 
   // Invalidate this context and release any held resources, in preperation
   // for possibly reinitializing with SetDimensions/InitializeWithSurface.
   NS_IMETHOD Reset() = 0;
 
   // Return the CanvasLayer for this context, creating
   // one for the given layer manager if not available.
-  virtual already_AddRefed<CanvasLayer> GetCanvasLayer(nsDisplayListBuilder* aBuilder,
-                                                       CanvasLayer *aOldLayer,
-                                                       LayerManager *aManager) = 0;
+  virtual already_AddRefed<CanvasLayer> GetCanvasLayer(nsDisplayListBuilder* builder,
+                                                       CanvasLayer *oldLayer,
+                                                       LayerManager *manager) = 0;
 
   // Return true if the canvas should be forced to be "inactive" to ensure
   // it can be drawn to the screen even if it's too large to be blitted by
   // an accelerated CanvasLayer.
-  virtual bool ShouldForceInactiveLayer(LayerManager *aManager) { return false; }
+  virtual bool ShouldForceInactiveLayer(LayerManager *manager) { return false; }
 
   virtual void MarkContextClean() = 0;
 
   // Redraw the dirty rectangle of this canvas.
   NS_IMETHOD Redraw(const gfxRect &dirty) = 0;
 
-  NS_IMETHOD SetContextOptions(JSContext* aCx, JS::Handle<JS::Value> aOptions) { return NS_OK; }
+  NS_IMETHOD SetContextOptions(JSContext* cx, JS::Handle<JS::Value> options) { return NS_OK; }
 
   // return true and fills in the bounding rect if elementis a child and has a hit region.
-  virtual bool GetHitRegionRect(mozilla::dom::Element* aElement, nsRect& aRect) { return false; }
+  virtual bool GetHitRegionRect(mozilla::dom::Element* element, nsRect& rect) { return false; }
 
   // Given a point, return hit region ID if it exists or an empty string if it doesn't
-  virtual nsString GetHitRegion(const mozilla::gfx::Point& aPoint) { return nsString(); }
+  virtual nsString GetHitRegion(const mozilla::gfx::Point& point) { return nsString(); }
 
   //
   // shmem support
   //
 
   // If this context can be set to use Mozilla's Shmem segments as its backing
   // store, this will set it to that state. Note that if you have drawn
   // anything into this canvas before changing the shmem state, it will be
--- a/gfx/gl/GLBlitHelper.cpp
+++ b/gfx/gl/GLBlitHelper.cpp
@@ -1,16 +1,17 @@
 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
 /* vim: set ts=8 sts=4 et sw=4 tw=80: */
 /* 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 "GLBlitHelper.h"
 #include "GLContext.h"
+#include "GLScreenBuffer.h"
 #include "ScopedGLHelpers.h"
 #include "mozilla/Preferences.h"
 #include "ImageContainer.h"
 #include "HeapCopyOfStackArray.h"
 #include "mozilla/gfx/Matrix.h"
 
 #ifdef MOZ_WIDGET_GONK
 #include "GrallocImages.h"
--- a/gfx/gl/GLContext.cpp
+++ b/gfx/gl/GLContext.cpp
@@ -1,23 +1,25 @@
 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
 /* vim: set ts=8 sts=4 et sw=4 tw=80: */
 /* 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 <algorithm>
 #include <stdio.h>
 #include <string.h>
 #include <ctype.h>
 #include <vector>
 
-#include "GLContext.h"
 #include "GLBlitHelper.h"
 #include "GLReadTexImageHelper.h"
+#include "GLScreenBuffer.h"
 
 #include "gfxCrashReporterUtils.h"
 #include "gfxUtils.h"
 #include "GLContextProvider.h"
 #include "GLTextureImage.h"
 #include "nsPrintfCString.h"
 #include "nsThreadUtils.h"
 #include "prenv.h"
@@ -2602,10 +2604,246 @@ GLContext::Readback(SharedSurface* src, 
 
     if (needsSwap) {
         src->UnlockProd();
         if (prev)
             prev->LockProd();
     }
 }
 
+// Do whatever tear-down is necessary after drawing to our offscreen FBO,
+// if it's bound.
+void
+GLContext::AfterGLDrawCall()
+{
+    if (mScreen) {
+        mScreen->AfterDrawCall();
+    }
+    mHeavyGLCallsSinceLastFlush = true;
+}
+
+// Do whatever setup is necessary to read from our offscreen FBO, if it's
+// bound.
+void
+GLContext::BeforeGLReadCall()
+{
+    if (mScreen)
+        mScreen->BeforeReadCall();
+}
+
+void
+GLContext::fBindFramebuffer(GLenum target, GLuint framebuffer)
+{
+    if (!mScreen) {
+        raw_fBindFramebuffer(target, framebuffer);
+        return;
+    }
+
+    switch (target) {
+        case LOCAL_GL_DRAW_FRAMEBUFFER_EXT:
+            mScreen->BindDrawFB(framebuffer);
+            return;
+
+        case LOCAL_GL_READ_FRAMEBUFFER_EXT:
+            mScreen->BindReadFB(framebuffer);
+            return;
+
+        case LOCAL_GL_FRAMEBUFFER:
+            mScreen->BindFB(framebuffer);
+            return;
+
+        default:
+            // Nothing we care about, likely an error.
+            break;
+    }
+
+    raw_fBindFramebuffer(target, framebuffer);
+}
+
+void
+GLContext::fCopyTexImage2D(GLenum target, GLint level, GLenum internalformat, GLint x,
+                           GLint y, GLsizei width, GLsizei height, GLint border)
+{
+    if (!IsTextureSizeSafeToPassToDriver(target, width, height)) {
+        // pass wrong values to cause the GL to generate GL_INVALID_VALUE.
+        // See bug 737182 and the comment in IsTextureSizeSafeToPassToDriver.
+        level = -1;
+        width = -1;
+        height = -1;
+        border = -1;
+    }
+
+    BeforeGLReadCall();
+    bool didCopyTexImage2D = false;
+    if (mScreen) {
+        didCopyTexImage2D = mScreen->CopyTexImage2D(target, level, internalformat, x,
+                                                    y, width, height, border);
+    }
+
+    if (!didCopyTexImage2D) {
+        raw_fCopyTexImage2D(target, level, internalformat, x, y, width, height,
+                            border);
+    }
+    AfterGLReadCall();
+}
+
+void
+GLContext::fGetIntegerv(GLenum pname, GLint* params)
+{
+    switch (pname) {
+        // LOCAL_GL_FRAMEBUFFER_BINDING is equal to
+        // LOCAL_GL_DRAW_FRAMEBUFFER_BINDING_EXT,
+        // so we don't need two cases.
+        case LOCAL_GL_DRAW_FRAMEBUFFER_BINDING_EXT:
+            if (mScreen) {
+                *params = mScreen->GetDrawFB();
+            } else {
+                raw_fGetIntegerv(pname, params);
+            }
+            break;
+
+        case LOCAL_GL_READ_FRAMEBUFFER_BINDING_EXT:
+            if (mScreen) {
+                *params = mScreen->GetReadFB();
+            } else {
+                raw_fGetIntegerv(pname, params);
+            }
+            break;
+
+        case LOCAL_GL_MAX_TEXTURE_SIZE:
+            MOZ_ASSERT(mMaxTextureSize>0);
+            *params = mMaxTextureSize;
+            break;
+
+        case LOCAL_GL_MAX_CUBE_MAP_TEXTURE_SIZE:
+            MOZ_ASSERT(mMaxCubeMapTextureSize>0);
+            *params = mMaxCubeMapTextureSize;
+            break;
+
+        case LOCAL_GL_MAX_RENDERBUFFER_SIZE:
+            MOZ_ASSERT(mMaxRenderbufferSize>0);
+            *params = mMaxRenderbufferSize;
+            break;
+
+        case LOCAL_GL_VIEWPORT:
+            for (size_t i = 0; i < 4; i++) {
+                params[i] = mViewportRect[i];
+            }
+            break;
+
+        case LOCAL_GL_SCISSOR_BOX:
+            for (size_t i = 0; i < 4; i++) {
+                params[i] = mScissorRect[i];
+            }
+            break;
+
+        default:
+            raw_fGetIntegerv(pname, params);
+            break;
+    }
+}
+
+void
+GLContext::fReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format,
+                       GLenum type, GLvoid* pixels)
+{
+    BeforeGLReadCall();
+
+    bool didReadPixels = false;
+    if (mScreen) {
+        didReadPixels = mScreen->ReadPixels(x, y, width, height, format, type, pixels);
+    }
+
+    if (!didReadPixels) {
+        raw_fReadPixels(x, y, width, height, format, type, pixels);
+    }
+
+    AfterGLReadCall();
+}
+
+void
+GLContext::fDeleteFramebuffers(GLsizei n, const GLuint* names)
+{
+    if (mScreen) {
+        // Notify mScreen which framebuffers we're deleting.
+        // Otherwise, we will get framebuffer binding mispredictions.
+        for (int i = 0; i < n; i++) {
+            mScreen->DeletingFB(names[i]);
+        }
+    }
+
+    if (n == 1 && *names == 0) {
+        // Deleting framebuffer 0 causes hangs on the DROID. See bug 623228.
+    } else {
+        raw_fDeleteFramebuffers(n, names);
+    }
+    TRACKING_CONTEXT(DeletedFramebuffers(this, n, names));
+}
+
+
+GLuint
+GLContext::GetDrawFB()
+{
+    if (mScreen)
+        return mScreen->GetDrawFB();
+
+    GLuint ret = 0;
+    GetUIntegerv(LOCAL_GL_DRAW_FRAMEBUFFER_BINDING_EXT, &ret);
+    return ret;
+}
+
+GLuint
+GLContext::GetReadFB()
+{
+    if (mScreen)
+        return mScreen->GetReadFB();
+
+    GLenum bindEnum = IsSupported(GLFeature::framebuffer_blit)
+                        ? LOCAL_GL_READ_FRAMEBUFFER_BINDING_EXT
+                        : LOCAL_GL_FRAMEBUFFER_BINDING;
+
+    GLuint ret = 0;
+    GetUIntegerv(bindEnum, &ret);
+    return ret;
+}
+
+GLuint
+GLContext::GetFB()
+{
+    if (mScreen) {
+        // This has a very important extra assert that checks that we're
+        // not accidentally ignoring a situation where the draw and read
+        // FBs differ.
+        return mScreen->GetFB();
+    }
+
+    GLuint ret = 0;
+    GetUIntegerv(LOCAL_GL_FRAMEBUFFER_BINDING, &ret);
+    return ret;
+}
+
+bool
+GLContext::InitOffscreen(const gfx::IntSize& size, const SurfaceCaps& caps)
+{
+    if (!CreateScreenBuffer(size, caps))
+        return false;
+
+    MakeCurrent();
+    fBindFramebuffer(LOCAL_GL_FRAMEBUFFER, 0);
+    fScissor(0, 0, size.width, size.height);
+    fViewport(0, 0, size.width, size.height);
+
+    mCaps = mScreen->mCaps;
+    MOZ_ASSERT(!mCaps.any);
+
+    UpdateGLFormats(mCaps);
+
+    return true;
+}
+
+bool
+GLContext::IsDrawingToDefaultFramebuffer()
+{
+    return Screen()->IsDrawFramebufferDefault();
+}
+
 } /* namespace gl */
 } /* namespace mozilla */
--- a/gfx/gl/GLContext.h
+++ b/gfx/gl/GLContext.h
@@ -27,29 +27,27 @@
 #endif
 
 // Define MOZ_GL_DEBUG unconditionally to enable GL debugging in opt
 // builds.
 #ifdef DEBUG
 #define MOZ_GL_DEBUG 1
 #endif
 
-#include "mozilla/UniquePtr.h"
+#include "../../mfbt/RefPtr.h"
+#include "../../mfbt/UniquePtr.h"
 
 #include "GLDefs.h"
 #include "GLLibraryLoader.h"
 #include "nsISupportsImpl.h"
 #include "plstr.h"
-#include "nsDataHashtable.h"
-#include "nsHashKeys.h"
 #include "nsAutoPtr.h"
 #include "GLContextTypes.h"
-#include "GLTextureImage.h"
+//#include "GLTextureImage.h"
 #include "SurfaceTypes.h"
-#include "GLScreenBuffer.h"
 #include "GLContextSymbols.h"
 #include "base/platform_thread.h"       // for PlatformThreadId
 #include "mozilla/GenericRefCounted.h"
 #include "gfx2DGlue.h"
 #include "GeckoProfiler.h"
 
 namespace android {
     class GraphicBuffer;
@@ -57,23 +55,24 @@ namespace android {
 
 namespace mozilla {
     namespace gfx {
         class DataSourceSurface;
         class SourceSurface;
     } // namespace gfx
 
     namespace gl {
+        class GLBlitHelper;
+        class GLBlitTextureImageHelper;
         class GLContext;
         class GLLibraryEGL;
+        class GLReadTexImageHelper;
         class GLScreenBuffer;
+        class SharedSurface;
         class TextureGarbageBin;
-        class GLBlitHelper;
-        class GLBlitTextureImageHelper;
-        class GLReadTexImageHelper;
         struct SurfaceCaps;
     } // namespace gl
 
     namespace layers {
         class ColorTextureLayerProgram;
     } // namespace layers
 } // namespace mozilla
 
@@ -787,41 +786,29 @@ private:
                 if (MOZ_UNLIKELY(!mSymbols.func)) {\
                     printf_stderr("RUNTIME ASSERT: Uninitialized GL function: %s\n", #func);\
                     MOZ_CRASH();\
                 }\
             } while (0)
 
     // Do whatever setup is necessary to draw to our offscreen FBO, if it's
     // bound.
-    void BeforeGLDrawCall() {
-    }
+    void BeforeGLDrawCall() { }
 
     // Do whatever tear-down is necessary after drawing to our offscreen FBO,
     // if it's bound.
-    void AfterGLDrawCall()
-    {
-        if (mScreen) {
-            mScreen->AfterDrawCall();
-        }
-        mHeavyGLCallsSinceLastFlush = true;
-    }
+    void AfterGLDrawCall();
 
     // Do whatever setup is necessary to read from our offscreen FBO, if it's
     // bound.
-    void BeforeGLReadCall()
-    {
-        if (mScreen)
-            mScreen->BeforeReadCall();
-    }
+    void BeforeGLReadCall();
 
     // Do whatever tear-down is necessary after reading from our offscreen FBO,
     // if it's bound.
-    void AfterGLReadCall() {
-    }
+    void AfterGLReadCall() { }
 
 
 // -----------------------------------------------------------------------------
 // GL official entry points
 public:
 
     void fActiveTexture(GLenum texture) {
         BEFORE_GL_CALL;
@@ -849,42 +836,17 @@ public:
     }
 
     void fBindBuffer(GLenum target, GLuint buffer) {
         BEFORE_GL_CALL;
         mSymbols.fBindBuffer(target, buffer);
         AFTER_GL_CALL;
     }
 
-    void fBindFramebuffer(GLenum target, GLuint framebuffer) {
-        if (!mScreen) {
-            raw_fBindFramebuffer(target, framebuffer);
-            return;
-        }
-
-        switch (target) {
-            case LOCAL_GL_DRAW_FRAMEBUFFER_EXT:
-                mScreen->BindDrawFB(framebuffer);
-                return;
-
-            case LOCAL_GL_READ_FRAMEBUFFER_EXT:
-                mScreen->BindReadFB(framebuffer);
-                return;
-
-            case LOCAL_GL_FRAMEBUFFER:
-                mScreen->BindFB(framebuffer);
-                return;
-
-            default:
-                // Nothing we care about, likely an error.
-                break;
-        }
-
-        raw_fBindFramebuffer(target, framebuffer);
-    }
+    void fBindFramebuffer(GLenum target, GLuint framebuffer);
 
     void fInvalidateFramebuffer(GLenum target, GLsizei numAttachments, const GLenum* attachments) {
         BEFORE_GL_CALL;
         ASSERT_SYMBOL_PRESENT(fInvalidateFramebuffer);
         mSymbols.fInvalidateFramebuffer(target, numAttachments, attachments);
         AFTER_GL_CALL;
     }
 
@@ -1036,39 +998,18 @@ public:
     void fCompressedTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const GLvoid *pixels) {
         ASSERT_NOT_PASSING_STACK_BUFFER_TO_GL(pixels);
         BEFORE_GL_CALL;
         mSymbols.fCompressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, imageSize, pixels);
         AFTER_GL_CALL;
         mHeavyGLCallsSinceLastFlush = true;
     }
 
-    void fCopyTexImage2D(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border) {
-        if (!IsTextureSizeSafeToPassToDriver(target, width, height)) {
-            // pass wrong values to cause the GL to generate GL_INVALID_VALUE.
-            // See bug 737182 and the comment in IsTextureSizeSafeToPassToDriver.
-            level = -1;
-            width = -1;
-            height = -1;
-            border = -1;
-        }
-
-        BeforeGLReadCall();
-        bool didCopyTexImage2D = false;
-        if (mScreen) {
-            didCopyTexImage2D = mScreen->CopyTexImage2D(target, level, internalformat, x,
-                                                        y, width, height, border);
-        }
-
-        if (!didCopyTexImage2D) {
-            raw_fCopyTexImage2D(target, level, internalformat, x, y, width, height,
-                                border);
-        }
-        AfterGLReadCall();
-    }
+    void fCopyTexImage2D(GLenum target, GLint level, GLenum internalformat, GLint x,
+                         GLint y, GLsizei width, GLsizei height, GLint border);
 
     void fCopyTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height) {
         BeforeGLReadCall();
         raw_fCopyTexSubImage2D(target, level, xoffset, yoffset,
                                x, y, width, height);
         AfterGLReadCall();
     }
 
@@ -1233,90 +1174,37 @@ public:
     GLint fGetAttribLocation(GLuint program, const GLchar* name) {
         BEFORE_GL_CALL;
         GLint retval = mSymbols.fGetAttribLocation(program, name);
         AFTER_GL_CALL;
         return retval;
     }
 
 private:
-    void raw_fGetIntegerv(GLenum pname, GLint *params) {
+    void raw_fGetIntegerv(GLenum pname, GLint* params) {
         BEFORE_GL_CALL;
         mSymbols.fGetIntegerv(pname, params);
         AFTER_GL_CALL;
     }
 
 public:
 
-    void fGetIntegerv(GLenum pname, GLint *params) {
-        switch (pname)
-        {
-            // LOCAL_GL_FRAMEBUFFER_BINDING is equal to
-            // LOCAL_GL_DRAW_FRAMEBUFFER_BINDING_EXT,
-            // so we don't need two cases.
-            case LOCAL_GL_DRAW_FRAMEBUFFER_BINDING_EXT:
-                if (mScreen) {
-                    *params = mScreen->GetDrawFB();
-                } else {
-                    raw_fGetIntegerv(pname, params);
-                }
-                break;
-
-            case LOCAL_GL_READ_FRAMEBUFFER_BINDING_EXT:
-                if (mScreen) {
-                    *params = mScreen->GetReadFB();
-                } else {
-                    raw_fGetIntegerv(pname, params);
-                }
-                break;
-
-            case LOCAL_GL_MAX_TEXTURE_SIZE:
-                MOZ_ASSERT(mMaxTextureSize>0);
-                *params = mMaxTextureSize;
-                break;
-
-            case LOCAL_GL_MAX_CUBE_MAP_TEXTURE_SIZE:
-                MOZ_ASSERT(mMaxCubeMapTextureSize>0);
-                *params = mMaxCubeMapTextureSize;
-                break;
-
-            case LOCAL_GL_MAX_RENDERBUFFER_SIZE:
-                MOZ_ASSERT(mMaxRenderbufferSize>0);
-                *params = mMaxRenderbufferSize;
-                break;
-
-            case LOCAL_GL_VIEWPORT:
-                for (size_t i = 0; i < 4; i++) {
-                    params[i] = mViewportRect[i];
-                }
-                break;
-
-            case LOCAL_GL_SCISSOR_BOX:
-                for (size_t i = 0; i < 4; i++) {
-                    params[i] = mScissorRect[i];
-                }
-                break;
-
-            default:
-                raw_fGetIntegerv(pname, params);
-                break;
-        }
-    }
+    void fGetIntegerv(GLenum pname, GLint* params);
 
     void GetUIntegerv(GLenum pname, GLuint *params) {
         fGetIntegerv(pname, reinterpret_cast<GLint*>(params));
     }
 
-    void fGetFloatv(GLenum pname, GLfloat *params) {
+    void fGetFloatv(GLenum pname, GLfloat* params) {
         BEFORE_GL_CALL;
         mSymbols.fGetFloatv(pname, params);
         AFTER_GL_CALL;
     }
 
-    void fGetBooleanv(GLenum pname, realGLboolean *params) {
+    void fGetBooleanv(GLenum pname, realGLboolean* params) {
         BEFORE_GL_CALL;
         mSymbols.fGetBooleanv(pname, params);
         AFTER_GL_CALL;
     }
 
     void fGetBufferParameteriv(GLenum target, GLenum pname, GLint* params) {
         BEFORE_GL_CALL;
         mSymbols.fGetBufferParameteriv(target, pname, params);
@@ -1599,30 +1487,18 @@ public:
     void raw_fReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels) {
         ASSERT_NOT_PASSING_STACK_BUFFER_TO_GL(pixels);
         BEFORE_GL_CALL;
         mSymbols.fReadPixels(x, y, width, height, format, type, pixels);
         AFTER_GL_CALL;
         mHeavyGLCallsSinceLastFlush = true;
     }
 
-    void fReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels) {
-        BeforeGLReadCall();
-
-        bool didReadPixels = false;
-        if (mScreen) {
-            didReadPixels = mScreen->ReadPixels(x, y, width, height, format, type, pixels);
-        }
-
-        if (!didReadPixels) {
-            raw_fReadPixels(x, y, width, height, format, type, pixels);
-        }
-
-        AfterGLReadCall();
-    }
+    void fReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format,
+                     GLenum type, GLvoid* pixels);
 
 public:
     void fSampleCoverage(GLclampf value, realGLboolean invert) {
         BEFORE_GL_CALL;
         mSymbols.fSampleCoverage(value, invert);
         AFTER_GL_CALL;
     }
 
@@ -2284,32 +2160,17 @@ public:
         TRACKING_CONTEXT(DeletedShader(this, shader));
     }
 
     void fDeleteBuffers(GLsizei n, const GLuint* names) {
         raw_fDeleteBuffers(n, names);
         TRACKING_CONTEXT(DeletedBuffers(this, n, names));
     }
 
-    void fDeleteFramebuffers(GLsizei n, const GLuint* names) {
-        if (mScreen) {
-            // Notify mScreen which framebuffers we're deleting.
-            // Otherwise, we will get framebuffer binding mispredictions.
-            for (int i = 0; i < n; i++) {
-                mScreen->DeletingFB(names[i]);
-            }
-        }
-
-        if (n == 1 && *names == 0) {
-            // Deleting framebuffer 0 causes hangs on the DROID. See bug 623228.
-        } else {
-            raw_fDeleteFramebuffers(n, names);
-        }
-        TRACKING_CONTEXT(DeletedFramebuffers(this, n, names));
-    }
+    void fDeleteFramebuffers(GLsizei n, const GLuint* names);
 
     void fDeleteRenderbuffers(GLsizei n, const GLuint* names) {
         raw_fDeleteRenderbuffers(n, names);
         TRACKING_CONTEXT(DeletedRenderbuffers(this, n, names));
     }
 
     void fDeleteTextures(GLsizei n, const GLuint* names) {
         raw_fDeleteTextures(n, names);
@@ -3354,50 +3215,21 @@ public:
     void BindDrawFB(GLuint fb) {
         fBindFramebuffer(LOCAL_GL_DRAW_FRAMEBUFFER_EXT, fb);
     }
 
     void BindReadFB(GLuint fb) {
         fBindFramebuffer(LOCAL_GL_READ_FRAMEBUFFER_EXT, fb);
     }
 
-    GLuint GetDrawFB() {
-        if (mScreen)
-            return mScreen->GetDrawFB();
-
-        GLuint ret = 0;
-        GetUIntegerv(LOCAL_GL_DRAW_FRAMEBUFFER_BINDING_EXT, &ret);
-        return ret;
-    }
-
-    GLuint GetReadFB() {
-        if (mScreen)
-            return mScreen->GetReadFB();
-
-        GLenum bindEnum = IsSupported(GLFeature::framebuffer_blit)
-                            ? LOCAL_GL_READ_FRAMEBUFFER_BINDING_EXT
-                            : LOCAL_GL_FRAMEBUFFER_BINDING;
-
-        GLuint ret = 0;
-        GetUIntegerv(bindEnum, &ret);
-        return ret;
-    }
-
-    GLuint GetFB() {
-        if (mScreen) {
-            // This has a very important extra assert that checks that we're
-            // not accidentally ignoring a situation where the draw and read
-            // FBs differ.
-            return mScreen->GetFB();
-        }
-
-        GLuint ret = 0;
-        GetUIntegerv(LOCAL_GL_FRAMEBUFFER_BINDING, &ret);
-        return ret;
-    }
+    GLuint GetDrawFB();
+
+    GLuint GetReadFB();
+
+    GLuint GetFB();
 
 private:
     void GetShaderPrecisionFormatNonES2(GLenum shadertype, GLenum precisiontype, GLint* range, GLint* precision) {
         switch (precisiontype) {
             case LOCAL_GL_LOW_FLOAT:
             case LOCAL_GL_MEDIUM_FLOAT:
             case LOCAL_GL_HIGH_FLOAT:
                 // Assume IEEE 754 precision
@@ -3447,17 +3279,17 @@ public:
 #ifdef MOZ_GL_DEBUG
         return sDebugMode;
 #else
         return 0;
 #endif
     }
 
 protected:
-    nsRefPtr<GLContext> mSharedContext;
+    RefPtr<GLContext> mSharedContext;
 
     // The thread id which this context was created.
     PlatformThreadId mOwningThreadId;
 
     GLContextSymbols mSymbols;
 
 #ifdef MOZ_GL_DEBUG
     // GLDebugMode will check that we don't send call
@@ -3487,32 +3319,17 @@ public:
         const GLContext* thisShared = this->mSharedContext ? this->mSharedContext
                                                            : this;
         const GLContext* otherShared = other->mSharedContext ? other->mSharedContext
                                                              : other;
 
         return thisShared == otherShared;
     }
 
-    bool InitOffscreen(const gfx::IntSize& size, const SurfaceCaps& caps) {
-        if (!CreateScreenBuffer(size, caps))
-            return false;
-
-        MakeCurrent();
-        fBindFramebuffer(LOCAL_GL_FRAMEBUFFER, 0);
-        fScissor(0, 0, size.width, size.height);
-        fViewport(0, 0, size.width, size.height);
-
-        mCaps = mScreen->mCaps;
-        MOZ_ASSERT(!mCaps.any);
-
-        UpdateGLFormats(mCaps);
-
-        return true;
-    }
+    bool InitOffscreen(const gfx::IntSize& size, const SurfaceCaps& caps);
 
 protected:
     // Note that it does -not- clear the resized buffers.
     bool CreateScreenBuffer(const gfx::IntSize& size, const SurfaceCaps& caps) {
         if (!IsOffscreenSizeAllowed(size))
             return false;
 
        return CreateScreenBufferImpl(size, caps);
@@ -3593,22 +3410,20 @@ public:
     /* Clear to transparent black, with 0 depth and stencil,
      * while preserving current ClearColor etc. values.
      * Useful for resizing offscreen buffers.
      */
     void ClearSafely();
 
     bool WorkAroundDriverBugs() const { return mWorkAroundDriverBugs; }
 
-    bool IsDrawingToDefaultFramebuffer() {
-        return Screen()->IsDrawFramebufferDefault();
-    }
+    bool IsDrawingToDefaultFramebuffer();
 
 protected:
-    nsRefPtr<TextureGarbageBin> mTexGarbageBin;
+    RefPtr<TextureGarbageBin> mTexGarbageBin;
 
 public:
     TextureGarbageBin* TexGarbageBin() {
         MOZ_ASSERT(mTexGarbageBin);
         return mTexGarbageBin;
     }
 
     void EmptyTexGarbageBin();
--- a/gfx/gl/SharedSurface.cpp
+++ b/gfx/gl/SharedSurface.cpp
@@ -4,16 +4,17 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "SharedSurface.h"
 
 #include "../2d/2D.h"
 #include "GLBlitHelper.h"
 #include "GLContext.h"
 #include "GLReadTexImageHelper.h"
+#include "GLScreenBuffer.h"
 #include "nsThreadUtils.h"
 #include "ScopedGLHelpers.h"
 #include "SharedSurfaceGL.h"
 #include "mozilla/layers/CompositorTypes.h"
 #include "mozilla/layers/TextureClientSharedSurface.h"
 #include "mozilla/unused.h"
 
 namespace mozilla {
--- a/toolkit/components/telemetry/Telemetry.h
+++ b/toolkit/components/telemetry/Telemetry.h
@@ -17,17 +17,17 @@ namespace base {
 } // namespace base
 
 namespace mozilla {
 namespace HangMonitor {
   class HangAnnotations;
 } // namespace HangMonitor
 namespace Telemetry {
 
-#include "TelemetryHistogramEnums.h"
+#include "mozilla/TelemetryHistogramEnums.h"
 
 enum TimerResolution {
   Millisecond,
   Microsecond
 };
 
 /**
  * Initialize the Telemetry service on the main thread at startup.