Bug 1442825 - Remove ScopedGLWrapper base class. r=lsalzman
authorJeff Gilbert <jgilbert@mozilla.com>
Mon, 17 Jun 2019 06:40:27 +0000
changeset 479090 40c99f4752f968db32f189243b4432b18d1b3471
parent 479089 a5eb3217248e4119e239ff9c16c1407690e41da6
child 479091 adc12b4c5a9d8f5139d182441f7fe2b672f08677
child 479092 d8ccc114a50fd185a8a2b9e7ec9967f2f418bb42
push id113460
push userbtara@mozilla.com
push dateMon, 17 Jun 2019 21:43:26 +0000
treeherdermozilla-inbound@40c99f4752f9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerslsalzman
bugs1442825
milestone69.0a1
first release with
nightly linux32
40c99f4752f9 / 69.0a1 / 20190617214029 / files
nightly linux64
40c99f4752f9 / 69.0a1 / 20190617214029 / files
nightly mac
40c99f4752f9 / 69.0a1 / 20190617214029 / files
nightly win32
40c99f4752f9 / 69.0a1 / 20190617214029 / files
nightly win64
40c99f4752f9 / 69.0a1 / 20190617214029 / files
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
releases
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1442825 - Remove ScopedGLWrapper base class. r=lsalzman Differential Revision: https://phabricator.services.mozilla.com/D35138
dom/canvas/WebGLContext.cpp
dom/canvas/WebGLContext.h
dom/canvas/WebGLTextureUpload.cpp
gfx/gl/ScopedGLHelpers.cpp
gfx/gl/ScopedGLHelpers.h
--- a/dom/canvas/WebGLContext.cpp
+++ b/dom/canvas/WebGLContext.cpp
@@ -1918,96 +1918,97 @@ uint64_t IndexedBufferBinding::ByteCount
   bufferSize -= mRangeStart;
 
   return std::min(bufferSize, mRangeSize);
 }
 
 ////////////////////////////////////////
 
 ScopedUnpackReset::ScopedUnpackReset(const WebGLContext* const webgl)
-    : ScopedGLWrapper<ScopedUnpackReset>(webgl->gl), mWebGL(webgl) {
+    : mWebGL(webgl) {
+  const auto& gl = mWebGL->gl;
   // clang-format off
-    if (mWebGL->mPixelStore_UnpackAlignment != 4) mGL->fPixelStorei(LOCAL_GL_UNPACK_ALIGNMENT, 4);
-
-    if (mWebGL->IsWebGL2()) {
-        if (mWebGL->mPixelStore_UnpackRowLength   != 0) mGL->fPixelStorei(LOCAL_GL_UNPACK_ROW_LENGTH  , 0);
-        if (mWebGL->mPixelStore_UnpackImageHeight != 0) mGL->fPixelStorei(LOCAL_GL_UNPACK_IMAGE_HEIGHT, 0);
-        if (mWebGL->mPixelStore_UnpackSkipPixels  != 0) mGL->fPixelStorei(LOCAL_GL_UNPACK_SKIP_PIXELS , 0);
-        if (mWebGL->mPixelStore_UnpackSkipRows    != 0) mGL->fPixelStorei(LOCAL_GL_UNPACK_SKIP_ROWS   , 0);
-        if (mWebGL->mPixelStore_UnpackSkipImages  != 0) mGL->fPixelStorei(LOCAL_GL_UNPACK_SKIP_IMAGES , 0);
-
-        if (mWebGL->mBoundPixelUnpackBuffer) mGL->fBindBuffer(LOCAL_GL_PIXEL_UNPACK_BUFFER, 0);
-    }
+  if (mWebGL->mPixelStore_UnpackAlignment != 4) gl->fPixelStorei(LOCAL_GL_UNPACK_ALIGNMENT, 4);
+
+  if (mWebGL->IsWebGL2()) {
+    if (mWebGL->mPixelStore_UnpackRowLength   != 0) gl->fPixelStorei(LOCAL_GL_UNPACK_ROW_LENGTH  , 0);
+    if (mWebGL->mPixelStore_UnpackImageHeight != 0) gl->fPixelStorei(LOCAL_GL_UNPACK_IMAGE_HEIGHT, 0);
+    if (mWebGL->mPixelStore_UnpackSkipPixels  != 0) gl->fPixelStorei(LOCAL_GL_UNPACK_SKIP_PIXELS , 0);
+    if (mWebGL->mPixelStore_UnpackSkipRows    != 0) gl->fPixelStorei(LOCAL_GL_UNPACK_SKIP_ROWS   , 0);
+    if (mWebGL->mPixelStore_UnpackSkipImages  != 0) gl->fPixelStorei(LOCAL_GL_UNPACK_SKIP_IMAGES , 0);
+
+    if (mWebGL->mBoundPixelUnpackBuffer) gl->fBindBuffer(LOCAL_GL_PIXEL_UNPACK_BUFFER, 0);
+  }
   // clang-format on
 }
 
-void ScopedUnpackReset::UnwrapImpl() {
+ScopedUnpackReset::~ScopedUnpackReset() {
+  const auto& gl = mWebGL->gl;
   // clang-format off
-    mGL->fPixelStorei(LOCAL_GL_UNPACK_ALIGNMENT, mWebGL->mPixelStore_UnpackAlignment);
-
-    if (mWebGL->IsWebGL2()) {
-        mGL->fPixelStorei(LOCAL_GL_UNPACK_ROW_LENGTH  , mWebGL->mPixelStore_UnpackRowLength  );
-        mGL->fPixelStorei(LOCAL_GL_UNPACK_IMAGE_HEIGHT, mWebGL->mPixelStore_UnpackImageHeight);
-        mGL->fPixelStorei(LOCAL_GL_UNPACK_SKIP_PIXELS , mWebGL->mPixelStore_UnpackSkipPixels );
-        mGL->fPixelStorei(LOCAL_GL_UNPACK_SKIP_ROWS   , mWebGL->mPixelStore_UnpackSkipRows   );
-        mGL->fPixelStorei(LOCAL_GL_UNPACK_SKIP_IMAGES , mWebGL->mPixelStore_UnpackSkipImages );
-
-        GLuint pbo = 0;
-        if (mWebGL->mBoundPixelUnpackBuffer) {
-            pbo = mWebGL->mBoundPixelUnpackBuffer->mGLName;
-        }
-
-        mGL->fBindBuffer(LOCAL_GL_PIXEL_UNPACK_BUFFER, pbo);
+  gl->fPixelStorei(LOCAL_GL_UNPACK_ALIGNMENT, mWebGL->mPixelStore_UnpackAlignment);
+
+  if (mWebGL->IsWebGL2()) {
+    gl->fPixelStorei(LOCAL_GL_UNPACK_ROW_LENGTH  , mWebGL->mPixelStore_UnpackRowLength  );
+    gl->fPixelStorei(LOCAL_GL_UNPACK_IMAGE_HEIGHT, mWebGL->mPixelStore_UnpackImageHeight);
+    gl->fPixelStorei(LOCAL_GL_UNPACK_SKIP_PIXELS , mWebGL->mPixelStore_UnpackSkipPixels );
+    gl->fPixelStorei(LOCAL_GL_UNPACK_SKIP_ROWS   , mWebGL->mPixelStore_UnpackSkipRows   );
+    gl->fPixelStorei(LOCAL_GL_UNPACK_SKIP_IMAGES , mWebGL->mPixelStore_UnpackSkipImages );
+
+    GLuint pbo = 0;
+    if (mWebGL->mBoundPixelUnpackBuffer) {
+        pbo = mWebGL->mBoundPixelUnpackBuffer->mGLName;
     }
+
+    gl->fBindBuffer(LOCAL_GL_PIXEL_UNPACK_BUFFER, pbo);
+  }
   // clang-format on
 }
 
 ////////////////////
 
-void ScopedFBRebinder::UnwrapImpl() {
+ScopedFBRebinder::~ScopedFBRebinder() {
   const auto fnName = [&](WebGLFramebuffer* fb) {
     return fb ? fb->mGLName : 0;
   };
 
+  const auto& gl = mWebGL->gl;
   if (mWebGL->IsWebGL2()) {
-    mGL->fBindFramebuffer(LOCAL_GL_DRAW_FRAMEBUFFER,
-                          fnName(mWebGL->mBoundDrawFramebuffer));
-    mGL->fBindFramebuffer(LOCAL_GL_READ_FRAMEBUFFER,
-                          fnName(mWebGL->mBoundReadFramebuffer));
+    gl->fBindFramebuffer(LOCAL_GL_DRAW_FRAMEBUFFER,
+                         fnName(mWebGL->mBoundDrawFramebuffer));
+    gl->fBindFramebuffer(LOCAL_GL_READ_FRAMEBUFFER,
+                         fnName(mWebGL->mBoundReadFramebuffer));
   } else {
     MOZ_ASSERT(mWebGL->mBoundDrawFramebuffer == mWebGL->mBoundReadFramebuffer);
-    mGL->fBindFramebuffer(LOCAL_GL_FRAMEBUFFER,
-                          fnName(mWebGL->mBoundDrawFramebuffer));
+    gl->fBindFramebuffer(LOCAL_GL_FRAMEBUFFER,
+                         fnName(mWebGL->mBoundDrawFramebuffer));
   }
 }
 
 ////////////////////
 
 static GLenum TargetIfLazy(GLenum target) {
   switch (target) {
     case LOCAL_GL_PIXEL_PACK_BUFFER:
     case LOCAL_GL_PIXEL_UNPACK_BUFFER:
       return target;
 
     default:
       return 0;
   }
 }
 
-ScopedLazyBind::ScopedLazyBind(gl::GLContext* gl, GLenum target,
+ScopedLazyBind::ScopedLazyBind(gl::GLContext* const gl, const GLenum target,
                                const WebGLBuffer* buf)
-    : ScopedGLWrapper<ScopedLazyBind>(gl),
-      mTarget(buf ? TargetIfLazy(target) : 0),
-      mBuf(buf) {
+    : mGL(gl), mTarget(buf ? TargetIfLazy(target) : 0), mBuf(buf) {
   if (mTarget) {
     mGL->fBindBuffer(mTarget, mBuf->mGLName);
   }
 }
 
-void ScopedLazyBind::UnwrapImpl() {
+ScopedLazyBind::~ScopedLazyBind() {
   if (mTarget) {
     mGL->fBindBuffer(mTarget, 0);
   }
 }
 
 ////////////////////////////////////////
 
 bool Intersect(const int32_t srcSize, const int32_t read0,
--- a/dom/canvas/WebGLContext.h
+++ b/dom/canvas/WebGLContext.h
@@ -2090,54 +2090,43 @@ std::string EnumString(GLenum val);
 bool ValidateTexTarget(WebGLContext* webgl, uint8_t funcDims,
                        GLenum rawTexTarget, TexTarget* const out_texTarget,
                        WebGLTexture** const out_tex);
 bool ValidateTexImageTarget(WebGLContext* webgl, uint8_t funcDims,
                             GLenum rawTexImageTarget,
                             TexImageTarget* const out_texImageTarget,
                             WebGLTexture** const out_tex);
 
-class ScopedUnpackReset final : public gl::ScopedGLWrapper<ScopedUnpackReset> {
-  friend struct gl::ScopedGLWrapper<ScopedUnpackReset>;
-
+class ScopedUnpackReset final {
  private:
   const WebGLContext* const mWebGL;
 
  public:
   explicit ScopedUnpackReset(const WebGLContext* webgl);
-
- private:
-  void UnwrapImpl();
+  ~ScopedUnpackReset();
 };
 
-class ScopedFBRebinder final : public gl::ScopedGLWrapper<ScopedFBRebinder> {
-  friend struct gl::ScopedGLWrapper<ScopedFBRebinder>;
-
+class ScopedFBRebinder final {
  private:
   const WebGLContext* const mWebGL;
 
  public:
-  explicit ScopedFBRebinder(const WebGLContext* const webgl)
-      : ScopedGLWrapper<ScopedFBRebinder>(webgl->gl), mWebGL(webgl) {}
-
- private:
-  void UnwrapImpl();
+  explicit ScopedFBRebinder(const WebGLContext* const webgl) : mWebGL(webgl) {}
+  ~ScopedFBRebinder();
 };
 
-class ScopedLazyBind final : public gl::ScopedGLWrapper<ScopedLazyBind> {
-  friend struct gl::ScopedGLWrapper<ScopedLazyBind>;
-
+class ScopedLazyBind final {
+ private:
+  gl::GLContext* const mGL;
   const GLenum mTarget;
   const WebGLBuffer* const mBuf;
 
  public:
   ScopedLazyBind(gl::GLContext* gl, GLenum target, const WebGLBuffer* buf);
-
- private:
-  void UnwrapImpl();
+  ~ScopedLazyBind();
 };
 
 ////
 
 bool Intersect(int32_t srcSize, int32_t read0, int32_t readSize,
                int32_t* out_intRead0, int32_t* out_intWrite0,
                int32_t* out_intSize);
 
--- a/dom/canvas/WebGLTextureUpload.cpp
+++ b/dom/canvas/WebGLTextureUpload.cpp
@@ -1722,47 +1722,43 @@ ScopedCopyTexImageSource::ScopedCopyTexI
                      blitSwizzle[3]);
 
   gl->fCopyTexImage2D(LOCAL_GL_TEXTURE_2D, 0, sizedFormat, 0, 0, srcWidth,
                       srcHeight, 0);
 
   // Now create the swizzled FB we'll be exposing.
 
   GLuint rgbaRB = 0;
-  gl->fGenRenderbuffers(1, &rgbaRB);
-  gl::ScopedBindRenderbuffer scopedRB(gl, rgbaRB);
-  gl->fRenderbufferStorage(LOCAL_GL_RENDERBUFFER, sizedFormat, srcWidth,
-                           srcHeight);
+  GLuint rgbaFB = 0;
+  {
+    gl->fGenRenderbuffers(1, &rgbaRB);
+    gl::ScopedBindRenderbuffer scopedRB(gl, rgbaRB);
+    gl->fRenderbufferStorage(LOCAL_GL_RENDERBUFFER, sizedFormat, srcWidth,
+                             srcHeight);
 
-  GLuint rgbaFB = 0;
-  gl->fGenFramebuffers(1, &rgbaFB);
-  gl->fBindFramebuffer(LOCAL_GL_FRAMEBUFFER, rgbaFB);
-  gl->fFramebufferRenderbuffer(LOCAL_GL_FRAMEBUFFER, LOCAL_GL_COLOR_ATTACHMENT0,
-                               LOCAL_GL_RENDERBUFFER, rgbaRB);
+    gl->fGenFramebuffers(1, &rgbaFB);
+    gl->fBindFramebuffer(LOCAL_GL_FRAMEBUFFER, rgbaFB);
+    gl->fFramebufferRenderbuffer(LOCAL_GL_FRAMEBUFFER,
+                                 LOCAL_GL_COLOR_ATTACHMENT0,
+                                 LOCAL_GL_RENDERBUFFER, rgbaRB);
 
-  const GLenum status = gl->fCheckFramebufferStatus(LOCAL_GL_FRAMEBUFFER);
-  if (status != LOCAL_GL_FRAMEBUFFER_COMPLETE) {
-    MOZ_CRASH("GFX: Temp framebuffer is not complete.");
+    const GLenum status = gl->fCheckFramebufferStatus(LOCAL_GL_FRAMEBUFFER);
+    if (status != LOCAL_GL_FRAMEBUFFER_COMPLETE) {
+      MOZ_CRASH("GFX: Temp framebuffer is not complete.");
+    }
   }
 
-  // Restore RB binding.
-  scopedRB.Unwrap();  // This function should really have a better name.
-
   // Draw-blit rgbaTex into rgbaFB.
   const gfx::IntSize srcSize(srcWidth, srcHeight);
   {
     const gl::ScopedBindFramebuffer bindFB(gl, rgbaFB);
     gl->BlitHelper()->DrawBlitTextureToFramebuffer(scopedTex.Texture(), srcSize,
                                                    srcSize);
   }
 
-  // Restore Tex2D binding and destroy the temp tex.
-  scopedBindTex.Unwrap();
-  scopedTex.Unwrap();
-
   // Leave RB and FB alive, and FB bound.
   mRB = rgbaRB;
   mFB = rgbaFB;
 }
 
 template <typename T>
 static inline GLenum ToGLHandle(const T& obj) {
   return (obj ? obj->mGLName : 0);
--- a/gfx/gl/ScopedGLHelpers.cpp
+++ b/gfx/gl/ScopedGLHelpers.cpp
@@ -10,35 +10,35 @@
 
 namespace mozilla {
 namespace gl {
 
 /* ScopedGLState - Wraps glEnable/glDisable. **********************************/
 
 // Use |newState = true| to enable, |false| to disable.
 ScopedGLState::ScopedGLState(GLContext* aGL, GLenum aCapability, bool aNewState)
-    : ScopedGLWrapper<ScopedGLState>(aGL), mCapability(aCapability) {
+    : mGL(aGL), mCapability(aCapability) {
   mOldState = mGL->fIsEnabled(mCapability);
 
   // Early out if we're already in the right state.
   if (aNewState == mOldState) return;
 
   if (aNewState) {
     mGL->fEnable(mCapability);
   } else {
     mGL->fDisable(mCapability);
   }
 }
 
 ScopedGLState::ScopedGLState(GLContext* aGL, GLenum aCapability)
-    : ScopedGLWrapper<ScopedGLState>(aGL), mCapability(aCapability) {
+    : mGL(aGL), mCapability(aCapability) {
   mOldState = mGL->fIsEnabled(mCapability);
 }
 
-void ScopedGLState::UnwrapImpl() {
+ScopedGLState::~ScopedGLState() {
   if (mOldState) {
     mGL->fEnable(mCapability);
   } else {
     mGL->fDisable(mCapability);
   }
 }
 
 /* ScopedBindFramebuffer - Saves and restores with GetUserBoundFB and
@@ -48,75 +48,75 @@ void ScopedBindFramebuffer::Init() {
   if (mGL->IsSupported(GLFeature::split_framebuffer)) {
     mOldReadFB = mGL->GetReadFB();
     mOldDrawFB = mGL->GetDrawFB();
   } else {
     mOldReadFB = mOldDrawFB = mGL->GetFB();
   }
 }
 
-ScopedBindFramebuffer::ScopedBindFramebuffer(GLContext* aGL)
-    : ScopedGLWrapper<ScopedBindFramebuffer>(aGL) {
+ScopedBindFramebuffer::ScopedBindFramebuffer(GLContext* aGL) : mGL(aGL) {
   Init();
 }
 
 ScopedBindFramebuffer::ScopedBindFramebuffer(GLContext* aGL, GLuint aNewFB)
-    : ScopedGLWrapper<ScopedBindFramebuffer>(aGL) {
+    : mGL(aGL) {
   Init();
   mGL->BindFB(aNewFB);
 }
 
-void ScopedBindFramebuffer::UnwrapImpl() {
+ScopedBindFramebuffer::~ScopedBindFramebuffer() {
   if (mOldReadFB == mOldDrawFB) {
     mGL->BindFB(mOldDrawFB);
   } else {
     mGL->BindDrawFB(mOldDrawFB);
     mGL->BindReadFB(mOldReadFB);
   }
 }
 
 /* ScopedBindTextureUnit ******************************************************/
 
 ScopedBindTextureUnit::ScopedBindTextureUnit(GLContext* aGL, GLenum aTexUnit)
-    : ScopedGLWrapper<ScopedBindTextureUnit>(aGL), mOldTexUnit(0) {
+    : mGL(aGL), mOldTexUnit(0) {
   MOZ_ASSERT(aTexUnit >= LOCAL_GL_TEXTURE0);
   mGL->GetUIntegerv(LOCAL_GL_ACTIVE_TEXTURE, &mOldTexUnit);
   mGL->fActiveTexture(aTexUnit);
 }
 
-void ScopedBindTextureUnit::UnwrapImpl() { mGL->fActiveTexture(mOldTexUnit); }
+ScopedBindTextureUnit::~ScopedBindTextureUnit() {
+  mGL->fActiveTexture(mOldTexUnit);
+}
 
 /* ScopedTexture **************************************************************/
 
-ScopedTexture::ScopedTexture(GLContext* aGL)
-    : ScopedGLWrapper<ScopedTexture>(aGL), mTexture(0) {
+ScopedTexture::ScopedTexture(GLContext* aGL) : mGL(aGL), mTexture(0) {
   mGL->fGenTextures(1, &mTexture);
 }
 
-void ScopedTexture::UnwrapImpl() { mGL->fDeleteTextures(1, &mTexture); }
+ScopedTexture::~ScopedTexture() { mGL->fDeleteTextures(1, &mTexture); }
 
 /* ScopedFramebuffer
  * **************************************************************/
 
-ScopedFramebuffer::ScopedFramebuffer(GLContext* aGL)
-    : ScopedGLWrapper<ScopedFramebuffer>(aGL), mFB(0) {
+ScopedFramebuffer::ScopedFramebuffer(GLContext* aGL) : mGL(aGL), mFB(0) {
   mGL->fGenFramebuffers(1, &mFB);
 }
 
-void ScopedFramebuffer::UnwrapImpl() { mGL->fDeleteFramebuffers(1, &mFB); }
+ScopedFramebuffer::~ScopedFramebuffer() { mGL->fDeleteFramebuffers(1, &mFB); }
 
 /* ScopedRenderbuffer
  * **************************************************************/
 
-ScopedRenderbuffer::ScopedRenderbuffer(GLContext* aGL)
-    : ScopedGLWrapper<ScopedRenderbuffer>(aGL), mRB(0) {
+ScopedRenderbuffer::ScopedRenderbuffer(GLContext* aGL) : mGL(aGL), mRB(0) {
   mGL->fGenRenderbuffers(1, &mRB);
 }
 
-void ScopedRenderbuffer::UnwrapImpl() { mGL->fDeleteRenderbuffers(1, &mRB); }
+ScopedRenderbuffer::~ScopedRenderbuffer() {
+  mGL->fDeleteRenderbuffers(1, &mRB);
+}
 
 /* ScopedBindTexture **********************************************************/
 
 static GLuint GetBoundTexture(GLContext* gl, GLenum texTarget) {
   GLenum bindingTarget;
   switch (texTarget) {
     case LOCAL_GL_TEXTURE_2D:
       bindingTarget = LOCAL_GL_TEXTURE_BINDING_2D;
@@ -148,160 +148,152 @@ static GLuint GetBoundTexture(GLContext*
 
   GLuint ret = 0;
   gl->GetUIntegerv(bindingTarget, &ret);
   return ret;
 }
 
 ScopedBindTexture::ScopedBindTexture(GLContext* aGL, GLuint aNewTex,
                                      GLenum aTarget)
-    : ScopedGLWrapper<ScopedBindTexture>(aGL),
-      mTarget(aTarget),
-      mOldTex(GetBoundTexture(aGL, aTarget)) {
+    : mGL(aGL), mTarget(aTarget), mOldTex(GetBoundTexture(aGL, aTarget)) {
   mGL->fBindTexture(mTarget, aNewTex);
 }
 
-void ScopedBindTexture::UnwrapImpl() { mGL->fBindTexture(mTarget, mOldTex); }
+ScopedBindTexture::~ScopedBindTexture() { mGL->fBindTexture(mTarget, mOldTex); }
 
 /* ScopedBindRenderbuffer *****************************************************/
 
 void ScopedBindRenderbuffer::Init() {
   mOldRB = 0;
   mGL->GetUIntegerv(LOCAL_GL_RENDERBUFFER_BINDING, &mOldRB);
 }
 
-ScopedBindRenderbuffer::ScopedBindRenderbuffer(GLContext* aGL)
-    : ScopedGLWrapper<ScopedBindRenderbuffer>(aGL) {
+ScopedBindRenderbuffer::ScopedBindRenderbuffer(GLContext* aGL) : mGL(aGL) {
   Init();
 }
 
 ScopedBindRenderbuffer::ScopedBindRenderbuffer(GLContext* aGL, GLuint aNewRB)
-    : ScopedGLWrapper<ScopedBindRenderbuffer>(aGL) {
+    : mGL(aGL) {
   Init();
   mGL->fBindRenderbuffer(LOCAL_GL_RENDERBUFFER, aNewRB);
 }
 
-void ScopedBindRenderbuffer::UnwrapImpl() {
+ScopedBindRenderbuffer::~ScopedBindRenderbuffer() {
   mGL->fBindRenderbuffer(LOCAL_GL_RENDERBUFFER, mOldRB);
 }
 
 /* ScopedFramebufferForTexture ************************************************/
 ScopedFramebufferForTexture::ScopedFramebufferForTexture(GLContext* aGL,
                                                          GLuint aTexture,
                                                          GLenum aTarget)
-    : ScopedGLWrapper<ScopedFramebufferForTexture>(aGL),
-      mComplete(false),
-      mFB(0) {
+    : mGL(aGL), mComplete(false), mFB(0) {
   mGL->fGenFramebuffers(1, &mFB);
   ScopedBindFramebuffer autoFB(aGL, mFB);
   mGL->fFramebufferTexture2D(LOCAL_GL_FRAMEBUFFER, LOCAL_GL_COLOR_ATTACHMENT0,
                              aTarget, aTexture, 0);
 
   GLenum status = mGL->fCheckFramebufferStatus(LOCAL_GL_FRAMEBUFFER);
   if (status == LOCAL_GL_FRAMEBUFFER_COMPLETE) {
     mComplete = true;
   } else {
     mGL->fDeleteFramebuffers(1, &mFB);
     mFB = 0;
   }
 }
 
-void ScopedFramebufferForTexture::UnwrapImpl() {
+ScopedFramebufferForTexture::~ScopedFramebufferForTexture() {
   if (!mFB) return;
 
   mGL->fDeleteFramebuffers(1, &mFB);
   mFB = 0;
 }
 
 /* ScopedFramebufferForRenderbuffer *******************************************/
 
 ScopedFramebufferForRenderbuffer::ScopedFramebufferForRenderbuffer(
     GLContext* aGL, GLuint aRB)
-    : ScopedGLWrapper<ScopedFramebufferForRenderbuffer>(aGL),
-      mComplete(false),
-      mFB(0) {
+    : mGL(aGL), mComplete(false), mFB(0) {
   mGL->fGenFramebuffers(1, &mFB);
   ScopedBindFramebuffer autoFB(aGL, mFB);
   mGL->fFramebufferRenderbuffer(LOCAL_GL_FRAMEBUFFER,
                                 LOCAL_GL_COLOR_ATTACHMENT0,
                                 LOCAL_GL_RENDERBUFFER, aRB);
 
   GLenum status = mGL->fCheckFramebufferStatus(LOCAL_GL_FRAMEBUFFER);
   if (status == LOCAL_GL_FRAMEBUFFER_COMPLETE) {
     mComplete = true;
   } else {
     mGL->fDeleteFramebuffers(1, &mFB);
     mFB = 0;
   }
 }
 
-void ScopedFramebufferForRenderbuffer::UnwrapImpl() {
+ScopedFramebufferForRenderbuffer::~ScopedFramebufferForRenderbuffer() {
   if (!mFB) return;
 
   mGL->fDeleteFramebuffers(1, &mFB);
   mFB = 0;
 }
 
 /* ScopedViewportRect *********************************************************/
 
 ScopedViewportRect::ScopedViewportRect(GLContext* aGL, GLint x, GLint y,
                                        GLsizei width, GLsizei height)
-    : ScopedGLWrapper<ScopedViewportRect>(aGL) {
+    : mGL(aGL) {
   mGL->fGetIntegerv(LOCAL_GL_VIEWPORT, mSavedViewportRect);
   mGL->fViewport(x, y, width, height);
 }
 
-void ScopedViewportRect::UnwrapImpl() {
+ScopedViewportRect::~ScopedViewportRect() {
   mGL->fViewport(mSavedViewportRect[0], mSavedViewportRect[1],
                  mSavedViewportRect[2], mSavedViewportRect[3]);
 }
 
 /* ScopedScissorRect **********************************************************/
 
 ScopedScissorRect::ScopedScissorRect(GLContext* aGL, GLint x, GLint y,
                                      GLsizei width, GLsizei height)
-    : ScopedGLWrapper<ScopedScissorRect>(aGL) {
+    : mGL(aGL) {
   mGL->fGetIntegerv(LOCAL_GL_SCISSOR_BOX, mSavedScissorRect);
   mGL->fScissor(x, y, width, height);
 }
 
-ScopedScissorRect::ScopedScissorRect(GLContext* aGL)
-    : ScopedGLWrapper<ScopedScissorRect>(aGL) {
+ScopedScissorRect::ScopedScissorRect(GLContext* aGL) : mGL(aGL) {
   mGL->fGetIntegerv(LOCAL_GL_SCISSOR_BOX, mSavedScissorRect);
 }
 
-void ScopedScissorRect::UnwrapImpl() {
+ScopedScissorRect::~ScopedScissorRect() {
   mGL->fScissor(mSavedScissorRect[0], mSavedScissorRect[1],
                 mSavedScissorRect[2], mSavedScissorRect[3]);
 }
 
 /* ScopedVertexAttribPointer **************************************************/
 
 ScopedVertexAttribPointer::ScopedVertexAttribPointer(
     GLContext* aGL, GLuint index, GLint size, GLenum type,
     realGLboolean normalized, GLsizei stride, GLuint buffer,
     const GLvoid* pointer)
-    : ScopedGLWrapper<ScopedVertexAttribPointer>(aGL),
+    : mGL(aGL),
       mAttribEnabled(0),
       mAttribSize(0),
       mAttribStride(0),
       mAttribType(0),
       mAttribNormalized(0),
       mAttribBufferBinding(0),
       mAttribPointer(nullptr),
       mBoundBuffer(0) {
   WrapImpl(index);
   mGL->fBindBuffer(LOCAL_GL_ARRAY_BUFFER, buffer);
   mGL->fVertexAttribPointer(index, size, type, normalized, stride, pointer);
   mGL->fEnableVertexAttribArray(index);
 }
 
 ScopedVertexAttribPointer::ScopedVertexAttribPointer(GLContext* aGL,
                                                      GLuint index)
-    : ScopedGLWrapper<ScopedVertexAttribPointer>(aGL),
+    : mGL(aGL),
       mAttribEnabled(0),
       mAttribSize(0),
       mAttribStride(0),
       mAttribType(0),
       mAttribNormalized(0),
       mAttribBufferBinding(0),
       mAttribPointer(nullptr),
       mBoundBuffer(0) {
@@ -344,32 +336,32 @@ void ScopedVertexAttribPointer::WrapImpl
       mAttribIndex, LOCAL_GL_VERTEX_ATTRIB_ARRAY_POINTER, &mAttribPointer);
 
   // Note that uniform values are program state, so we don't need to rebind
   // those.
 
   mGL->GetUIntegerv(LOCAL_GL_ARRAY_BUFFER_BINDING, &mBoundBuffer);
 }
 
-void ScopedVertexAttribPointer::UnwrapImpl() {
+ScopedVertexAttribPointer::~ScopedVertexAttribPointer() {
   mGL->fBindBuffer(LOCAL_GL_ARRAY_BUFFER, mAttribBufferBinding);
   mGL->fVertexAttribPointer(mAttribIndex, mAttribSize, mAttribType,
                             mAttribNormalized, mAttribStride, mAttribPointer);
   if (mAttribEnabled)
     mGL->fEnableVertexAttribArray(mAttribIndex);
   else
     mGL->fDisableVertexAttribArray(mAttribIndex);
   mGL->fBindBuffer(LOCAL_GL_ARRAY_BUFFER, mBoundBuffer);
 }
 
 ////////////////////////////////////////////////////////////////////////
 // ScopedPackState
 
 ScopedPackState::ScopedPackState(GLContext* gl)
-    : ScopedGLWrapper<ScopedPackState>(gl),
+    : mGL(gl),
       mAlignment(0),
       mPixelBuffer(0),
       mRowLength(0),
       mSkipPixels(0),
       mSkipRows(0) {
   mGL->fGetIntegerv(LOCAL_GL_PACK_ALIGNMENT, &mAlignment);
 
   if (mAlignment != 4) mGL->fPixelStorei(LOCAL_GL_PACK_ALIGNMENT, 4);
@@ -398,32 +390,32 @@ bool ScopedPackState::SetForWidthAndStri
   if (mGL->HasPBOState()) {
     // HasPBOState implies support for GL_PACK_ROW_LENGTH.
     mGL->fPixelStorei(LOCAL_GL_PACK_ROW_LENGTH, aStride / 4);
     return true;
   }
   return false;
 }
 
-void ScopedPackState::UnwrapImpl() {
+ScopedPackState::~ScopedPackState() {
   mGL->fPixelStorei(LOCAL_GL_PACK_ALIGNMENT, mAlignment);
 
   if (!mGL->HasPBOState()) return;
 
   mGL->fBindBuffer(LOCAL_GL_PIXEL_PACK_BUFFER, mPixelBuffer);
   mGL->fPixelStorei(LOCAL_GL_PACK_ROW_LENGTH, mRowLength);
   mGL->fPixelStorei(LOCAL_GL_PACK_SKIP_PIXELS, mSkipPixels);
   mGL->fPixelStorei(LOCAL_GL_PACK_SKIP_ROWS, mSkipRows);
 }
 
 ////////////////////////////////////////////////////////////////////////
 // ResetUnpackState
 
 ResetUnpackState::ResetUnpackState(GLContext* gl)
-    : ScopedGLWrapper<ResetUnpackState>(gl),
+    : mGL(gl),
       mAlignment(0),
       mPBO(0),
       mRowLength(0),
       mImageHeight(0),
       mSkipPixels(0),
       mSkipRows(0),
       mSkipImages(0) {
   const auto fnReset = [&](GLenum pname, GLuint val, GLuint* const out_old) {
@@ -443,17 +435,17 @@ ResetUnpackState::ResetUnpackState(GLCon
 
   fnReset(LOCAL_GL_UNPACK_ROW_LENGTH, 0, &mRowLength);
   fnReset(LOCAL_GL_UNPACK_IMAGE_HEIGHT, 0, &mImageHeight);
   fnReset(LOCAL_GL_UNPACK_SKIP_PIXELS, 0, &mSkipPixels);
   fnReset(LOCAL_GL_UNPACK_SKIP_ROWS, 0, &mSkipRows);
   fnReset(LOCAL_GL_UNPACK_SKIP_IMAGES, 0, &mSkipImages);
 }
 
-void ResetUnpackState::UnwrapImpl() {
+ResetUnpackState::~ResetUnpackState() {
   mGL->fPixelStorei(LOCAL_GL_UNPACK_ALIGNMENT, mAlignment);
 
   if (!mGL->HasPBOState()) return;
 
   mGL->fBindBuffer(LOCAL_GL_PIXEL_UNPACK_BUFFER, mPBO);
 
   mGL->fPixelStorei(LOCAL_GL_UNPACK_ROW_LENGTH, mRowLength);
   mGL->fPixelStorei(LOCAL_GL_UNPACK_IMAGE_HEIGHT, mImageHeight);
@@ -481,20 +473,18 @@ static GLuint GetPBOBinding(GLContext* g
     default:
       MOZ_CRASH();
   }
 
   return gl->GetIntAs<GLuint>(targetBinding);
 }
 
 ScopedBindPBO::ScopedBindPBO(GLContext* gl, GLenum target)
-    : ScopedGLWrapper<ScopedBindPBO>(gl),
-      mTarget(target),
-      mPBO(GetPBOBinding(mGL, mTarget)) {}
+    : mGL(gl), mTarget(target), mPBO(GetPBOBinding(mGL, mTarget)) {}
 
-void ScopedBindPBO::UnwrapImpl() {
+ScopedBindPBO::~ScopedBindPBO() {
   if (!mGL->HasPBOState()) return;
 
   mGL->fBindBuffer(mTarget, mPBO);
 }
 
 } /* namespace gl */
 } /* namespace mozilla */
--- a/gfx/gl/ScopedGLHelpers.h
+++ b/gfx/gl/ScopedGLHelpers.h
@@ -13,322 +13,248 @@ namespace mozilla {
 namespace gl {
 
 class GLContext;
 
 #ifdef DEBUG
 bool IsContextCurrent(GLContext* gl);
 #endif
 
-// RAII via CRTP!
-template <class Derived>
-struct ScopedGLWrapper {
+// Wraps glEnable/Disable.
+struct ScopedGLState final {
  private:
-  bool mIsUnwrapped;
-
- protected:
   GLContext* const mGL;
-
-  explicit ScopedGLWrapper(GLContext* gl) : mIsUnwrapped(false), mGL(gl) {
-    MOZ_ASSERT(&ScopedGLWrapper<Derived>::Unwrap == &Derived::Unwrap);
-    MOZ_ASSERT(&Derived::UnwrapImpl);
-  }
-
-  virtual ~ScopedGLWrapper() {
-    if (!mIsUnwrapped) Unwrap();
-  }
-
- public:
-  void Unwrap() {
-    MOZ_ASSERT(!mIsUnwrapped);
-
-    Derived* derived = static_cast<Derived*>(this);
-    derived->UnwrapImpl();
-
-    mIsUnwrapped = true;
-  }
-};
-
-// Wraps glEnable/Disable.
-struct ScopedGLState : public ScopedGLWrapper<ScopedGLState> {
-  friend struct ScopedGLWrapper<ScopedGLState>;
-
- protected:
   const GLenum mCapability;
   bool mOldState;
 
  public:
   // Use |newState = true| to enable, |false| to disable.
   ScopedGLState(GLContext* aGL, GLenum aCapability, bool aNewState);
   // variant that doesn't change state; simply records existing state to be
   // restored by the destructor
   ScopedGLState(GLContext* aGL, GLenum aCapability);
-
- protected:
-  void UnwrapImpl();
+  ~ScopedGLState();
 };
 
 // Saves and restores with GetUserBoundFB and BindUserFB.
-struct ScopedBindFramebuffer : public ScopedGLWrapper<ScopedBindFramebuffer> {
-  friend struct ScopedGLWrapper<ScopedBindFramebuffer>;
-
- protected:
+struct ScopedBindFramebuffer final {
+ private:
+  GLContext* const mGL;
   GLuint mOldReadFB;
   GLuint mOldDrawFB;
 
- private:
   void Init();
 
  public:
   explicit ScopedBindFramebuffer(GLContext* aGL);
   ScopedBindFramebuffer(GLContext* aGL, GLuint aNewFB);
-
- protected:
-  void UnwrapImpl();
+  ~ScopedBindFramebuffer();
 };
 
-struct ScopedBindTextureUnit : public ScopedGLWrapper<ScopedBindTextureUnit> {
-  friend struct ScopedGLWrapper<ScopedBindTextureUnit>;
-
- protected:
+struct ScopedBindTextureUnit final {
+ private:
+  GLContext* const mGL;
   GLenum mOldTexUnit;
 
  public:
   ScopedBindTextureUnit(GLContext* aGL, GLenum aTexUnit);
-
- protected:
-  void UnwrapImpl();
+  ~ScopedBindTextureUnit();
 };
 
-struct ScopedTexture : public ScopedGLWrapper<ScopedTexture> {
-  friend struct ScopedGLWrapper<ScopedTexture>;
-
- protected:
+struct ScopedTexture final {
+ private:
+  GLContext* const mGL;
   GLuint mTexture;
 
  public:
   explicit ScopedTexture(GLContext* aGL);
+  ~ScopedTexture();
 
   GLuint Texture() const { return mTexture; }
   operator GLuint() const { return mTexture; }
-
- protected:
-  void UnwrapImpl();
 };
 
-struct ScopedFramebuffer : public ScopedGLWrapper<ScopedFramebuffer> {
-  friend struct ScopedGLWrapper<ScopedFramebuffer>;
-
- protected:
+struct ScopedFramebuffer final {
+ private:
+  GLContext* const mGL;
   GLuint mFB;
 
  public:
   explicit ScopedFramebuffer(GLContext* aGL);
-  const auto& FB() const { return mFB; }
+  ~ScopedFramebuffer();
 
- protected:
-  void UnwrapImpl();
+  const auto& FB() const { return mFB; }
+  operator GLuint() const { return mFB; }
 };
 
-struct ScopedRenderbuffer : public ScopedGLWrapper<ScopedRenderbuffer> {
-  friend struct ScopedGLWrapper<ScopedRenderbuffer>;
-
- protected:
+struct ScopedRenderbuffer final {
+ private:
+  GLContext* const mGL;
   GLuint mRB;
 
  public:
   explicit ScopedRenderbuffer(GLContext* aGL);
-  GLuint RB() { return mRB; }
+  ~ScopedRenderbuffer();
 
- protected:
-  void UnwrapImpl();
+  GLuint RB() { return mRB; }
+  operator GLuint() const { return mRB; }
 };
 
-struct ScopedBindTexture : public ScopedGLWrapper<ScopedBindTexture> {
-  friend struct ScopedGLWrapper<ScopedBindTexture>;
-
- protected:
+struct ScopedBindTexture final {
+ private:
+  GLContext* const mGL;
   const GLenum mTarget;
   const GLuint mOldTex;
 
  public:
   ScopedBindTexture(GLContext* aGL, GLuint aNewTex,
                     GLenum aTarget = LOCAL_GL_TEXTURE_2D);
-
- protected:
-  void UnwrapImpl();
+  ~ScopedBindTexture();
 };
 
-struct ScopedBindRenderbuffer : public ScopedGLWrapper<ScopedBindRenderbuffer> {
-  friend struct ScopedGLWrapper<ScopedBindRenderbuffer>;
-
- protected:
+struct ScopedBindRenderbuffer final {
+ private:
+  GLContext* const mGL;
   GLuint mOldRB;
 
  private:
   void Init();
 
  public:
   explicit ScopedBindRenderbuffer(GLContext* aGL);
-
   ScopedBindRenderbuffer(GLContext* aGL, GLuint aNewRB);
-
- protected:
-  void UnwrapImpl();
+  ~ScopedBindRenderbuffer();
 };
 
-struct ScopedFramebufferForTexture
-    : public ScopedGLWrapper<ScopedFramebufferForTexture> {
-  friend struct ScopedGLWrapper<ScopedFramebufferForTexture>;
-
- protected:
+struct ScopedFramebufferForTexture final {
+ private:
+  GLContext* const mGL;
   bool mComplete;  // True if the framebuffer we create is complete.
   GLuint mFB;
 
  public:
   ScopedFramebufferForTexture(GLContext* aGL, GLuint aTexture,
                               GLenum aTarget = LOCAL_GL_TEXTURE_2D);
+  ~ScopedFramebufferForTexture();
 
   bool IsComplete() const { return mComplete; }
 
   GLuint FB() const {
     MOZ_GL_ASSERT(mGL, IsComplete());
     return mFB;
   }
-
- protected:
-  void UnwrapImpl();
 };
 
-struct ScopedFramebufferForRenderbuffer
-    : public ScopedGLWrapper<ScopedFramebufferForRenderbuffer> {
-  friend struct ScopedGLWrapper<ScopedFramebufferForRenderbuffer>;
-
- protected:
+struct ScopedFramebufferForRenderbuffer final {
+ private:
+  GLContext* const mGL;
   bool mComplete;  // True if the framebuffer we create is complete.
   GLuint mFB;
 
  public:
   ScopedFramebufferForRenderbuffer(GLContext* aGL, GLuint aRB);
+  ~ScopedFramebufferForRenderbuffer();
 
   bool IsComplete() const { return mComplete; }
-
-  GLuint FB() const { return mFB; }
-
- protected:
-  void UnwrapImpl();
+  GLuint FB() const {
+    MOZ_GL_ASSERT(mGL, IsComplete());
+    return mFB;
+  }
 };
 
-struct ScopedViewportRect : public ScopedGLWrapper<ScopedViewportRect> {
-  friend struct ScopedGLWrapper<ScopedViewportRect>;
-
- protected:
+struct ScopedViewportRect final {
+ private:
+  GLContext* const mGL;
   GLint mSavedViewportRect[4];
 
  public:
   ScopedViewportRect(GLContext* aGL, GLint x, GLint y, GLsizei width,
                      GLsizei height);
-
- protected:
-  void UnwrapImpl();
+  ~ScopedViewportRect();
 };
 
-struct ScopedScissorRect : public ScopedGLWrapper<ScopedScissorRect> {
-  friend struct ScopedGLWrapper<ScopedScissorRect>;
-
- protected:
+struct ScopedScissorRect final {
+ private:
+  GLContext* const mGL;
   GLint mSavedScissorRect[4];
 
  public:
   ScopedScissorRect(GLContext* aGL, GLint x, GLint y, GLsizei width,
                     GLsizei height);
   explicit ScopedScissorRect(GLContext* aGL);
-
- protected:
-  void UnwrapImpl();
+  ~ScopedScissorRect();
 };
 
-struct ScopedVertexAttribPointer
-    : public ScopedGLWrapper<ScopedVertexAttribPointer> {
-  friend struct ScopedGLWrapper<ScopedVertexAttribPointer>;
-
- protected:
+struct ScopedVertexAttribPointer final {
+ private:
+  GLContext* const mGL;
   GLuint mAttribIndex;
   GLint mAttribEnabled;
   GLint mAttribSize;
   GLint mAttribStride;
   GLint mAttribType;
   GLint mAttribNormalized;
   GLint mAttribBufferBinding;
   void* mAttribPointer;
   GLuint mBoundBuffer;
 
  public:
   ScopedVertexAttribPointer(GLContext* aGL, GLuint index, GLint size,
                             GLenum type, realGLboolean normalized,
                             GLsizei stride, GLuint buffer,
                             const GLvoid* pointer);
   explicit ScopedVertexAttribPointer(GLContext* aGL, GLuint index);
+  ~ScopedVertexAttribPointer();
 
- protected:
+ private:
   void WrapImpl(GLuint index);
-  void UnwrapImpl();
 };
 
-struct ScopedPackState : public ScopedGLWrapper<ScopedPackState> {
-  friend struct ScopedGLWrapper<ScopedPackState>;
-
- protected:
+struct ScopedPackState final {
+ private:
+  GLContext* const mGL;
   GLint mAlignment;
 
   GLuint mPixelBuffer;
   GLint mRowLength;
   GLint mSkipPixels;
   GLint mSkipRows;
 
  public:
   explicit ScopedPackState(GLContext* gl);
+  ~ScopedPackState();
 
   // Returns whether the stride was handled successfully.
   bool SetForWidthAndStrideRGBA(GLsizei aWidth, GLsizei aStride);
-
- protected:
-  void UnwrapImpl();
 };
 
-struct ResetUnpackState : public ScopedGLWrapper<ResetUnpackState> {
-  friend struct ScopedGLWrapper<ResetUnpackState>;
-
- protected:
+struct ResetUnpackState final {
+ private:
+  GLContext* const mGL;
   GLuint mAlignment;
 
   GLuint mPBO;
   GLuint mRowLength;
   GLuint mImageHeight;
   GLuint mSkipPixels;
   GLuint mSkipRows;
   GLuint mSkipImages;
 
  public:
   explicit ResetUnpackState(GLContext* gl);
-
- protected:
-  void UnwrapImpl();
+  ~ResetUnpackState();
 };
 
-struct ScopedBindPBO final : public ScopedGLWrapper<ScopedBindPBO> {
-  friend struct ScopedGLWrapper<ScopedBindPBO>;
-
- protected:
+struct ScopedBindPBO final {
+ private:
+  GLContext* const mGL;
   const GLenum mTarget;
   const GLuint mPBO;
 
  public:
   ScopedBindPBO(GLContext* gl, GLenum target);
-
- protected:
-  void UnwrapImpl();
+  ~ScopedBindPBO();
 };
 
 } /* namespace gl */
 } /* namespace mozilla */
 
 #endif /* SCOPEDGLHELPERS_H_ */