Bug 1442825 - Remove ScopedGLWrapper base class. r=lsalzman

Differential Revision: https://phabricator.services.mozilla.com/D35138

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Jeff Gilbert 2019-06-17 06:40:27 +00:00
Родитель db77aa9495
Коммит 7ac9159761
5 изменённых файлов: 175 добавлений и 273 удалений

Просмотреть файл

@ -1923,59 +1923,62 @@ uint64_t IndexedBufferBinding::ByteCount() const {
////////////////////////////////////////
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->mPixelStore_UnpackAlignment != 4) gl->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->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) mGL->fBindBuffer(LOCAL_GL_PIXEL_UNPACK_BUFFER, 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);
gl->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 );
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;
}
mGL->fBindBuffer(LOCAL_GL_PIXEL_UNPACK_BUFFER, pbo);
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));
}
}
@ -1992,17 +1995,15 @@ static GLenum TargetIfLazy(GLenum target) {
}
}
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);
}

Просмотреть файл

@ -2095,44 +2095,33 @@ bool ValidateTexImageTarget(WebGLContext* webgl, uint8_t funcDims,
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();
};
////

Просмотреть файл

@ -1727,25 +1727,25 @@ ScopedCopyTexImageSource::ScopedCopyTexImageSource(
// 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->fGenFramebuffers(1, &rgbaFB);
gl->fBindFramebuffer(LOCAL_GL_FRAMEBUFFER, rgbaFB);
gl->fFramebufferRenderbuffer(LOCAL_GL_FRAMEBUFFER, LOCAL_GL_COLOR_ATTACHMENT0,
LOCAL_GL_RENDERBUFFER, rgbaRB);
{
gl->fGenRenderbuffers(1, &rgbaRB);
gl::ScopedBindRenderbuffer scopedRB(gl, rgbaRB);
gl->fRenderbufferStorage(LOCAL_GL_RENDERBUFFER, sizedFormat, srcWidth,
srcHeight);
const GLenum status = gl->fCheckFramebufferStatus(LOCAL_GL_FRAMEBUFFER);
if (status != LOCAL_GL_FRAMEBUFFER_COMPLETE) {
MOZ_CRASH("GFX: Temp framebuffer is not complete.");
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.");
}
}
// Restore RB binding.
scopedRB.Unwrap(); // This function should really have a better name.
// Draw-blit rgbaTex into rgbaFB.
const gfx::IntSize srcSize(srcWidth, srcHeight);
{
@ -1754,10 +1754,6 @@ ScopedCopyTexImageSource::ScopedCopyTexImageSource(
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;

Просмотреть файл

@ -15,7 +15,7 @@ namespace gl {
// 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.
@ -29,11 +29,11 @@ ScopedGLState::ScopedGLState(GLContext* aGL, GLenum aCapability, bool aNewState)
}
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 {
@ -53,18 +53,17 @@ void ScopedBindFramebuffer::Init() {
}
}
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 {
@ -76,42 +75,43 @@ void ScopedBindFramebuffer::UnwrapImpl() {
/* 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 **********************************************************/
@ -153,13 +153,11 @@ static GLuint GetBoundTexture(GLContext* gl, GLenum texTarget) {
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 *****************************************************/
@ -168,18 +166,17 @@ void ScopedBindRenderbuffer::Init() {
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);
}
@ -187,9 +184,7 @@ void ScopedBindRenderbuffer::UnwrapImpl() {
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,
@ -204,7 +199,7 @@ ScopedFramebufferForTexture::ScopedFramebufferForTexture(GLContext* aGL,
}
}
void ScopedFramebufferForTexture::UnwrapImpl() {
ScopedFramebufferForTexture::~ScopedFramebufferForTexture() {
if (!mFB) return;
mGL->fDeleteFramebuffers(1, &mFB);
@ -215,9 +210,7 @@ void ScopedFramebufferForTexture::UnwrapImpl() {
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,
@ -233,7 +226,7 @@ ScopedFramebufferForRenderbuffer::ScopedFramebufferForRenderbuffer(
}
}
void ScopedFramebufferForRenderbuffer::UnwrapImpl() {
ScopedFramebufferForRenderbuffer::~ScopedFramebufferForRenderbuffer() {
if (!mFB) return;
mGL->fDeleteFramebuffers(1, &mFB);
@ -244,12 +237,12 @@ void ScopedFramebufferForRenderbuffer::UnwrapImpl() {
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]);
}
@ -258,17 +251,16 @@ void ScopedViewportRect::UnwrapImpl() {
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]);
}
@ -279,7 +271,7 @@ 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),
@ -296,7 +288,7 @@ ScopedVertexAttribPointer::ScopedVertexAttribPointer(
ScopedVertexAttribPointer::ScopedVertexAttribPointer(GLContext* aGL,
GLuint index)
: ScopedGLWrapper<ScopedVertexAttribPointer>(aGL),
: mGL(aGL),
mAttribEnabled(0),
mAttribSize(0),
mAttribStride(0),
@ -349,7 +341,7 @@ void ScopedVertexAttribPointer::WrapImpl(GLuint index) {
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);
@ -364,7 +356,7 @@ void ScopedVertexAttribPointer::UnwrapImpl() {
// ScopedPackState
ScopedPackState::ScopedPackState(GLContext* gl)
: ScopedGLWrapper<ScopedPackState>(gl),
: mGL(gl),
mAlignment(0),
mPixelBuffer(0),
mRowLength(0),
@ -403,7 +395,7 @@ bool ScopedPackState::SetForWidthAndStrideRGBA(GLsizei aWidth,
return false;
}
void ScopedPackState::UnwrapImpl() {
ScopedPackState::~ScopedPackState() {
mGL->fPixelStorei(LOCAL_GL_PACK_ALIGNMENT, mAlignment);
if (!mGL->HasPBOState()) return;
@ -418,7 +410,7 @@ void ScopedPackState::UnwrapImpl() {
// ResetUnpackState
ResetUnpackState::ResetUnpackState(GLContext* gl)
: ScopedGLWrapper<ResetUnpackState>(gl),
: mGL(gl),
mAlignment(0),
mPBO(0),
mRowLength(0),
@ -448,7 +440,7 @@ ResetUnpackState::ResetUnpackState(GLContext* gl)
fnReset(LOCAL_GL_UNPACK_SKIP_IMAGES, 0, &mSkipImages);
}
void ResetUnpackState::UnwrapImpl() {
ResetUnpackState::~ResetUnpackState() {
mGL->fPixelStorei(LOCAL_GL_UNPACK_ALIGNMENT, mAlignment);
if (!mGL->HasPBOState()) return;
@ -486,11 +478,9 @@ static GLuint GetPBOBinding(GLContext* gl, GLenum target) {
}
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);

Просмотреть файл

@ -18,40 +18,10 @@ class GLContext;
bool IsContextCurrent(GLContext* gl);
#endif
// RAII via CRTP!
template <class Derived>
struct ScopedGLWrapper {
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:
struct ScopedGLState final {
private:
GLContext* const mGL;
const GLenum mCapability;
bool mOldState;
@ -61,106 +31,88 @@ struct ScopedGLState : public ScopedGLWrapper<ScopedGLState> {
// 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:
@ -168,24 +120,20 @@ struct ScopedBindRenderbuffer : public ScopedGLWrapper<ScopedBindRenderbuffer> {
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; }
@ -193,64 +141,51 @@ struct ScopedFramebufferForTexture
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;
@ -267,16 +202,15 @@ struct ScopedVertexAttribPointer
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;
@ -286,18 +220,15 @@ struct ScopedPackState : public ScopedGLWrapper<ScopedPackState> {
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;
@ -309,23 +240,18 @@ struct ResetUnpackState : public ScopedGLWrapper<ResetUnpackState> {
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 */