Bug 1250710 - Update scoped pack/unpack helpers. - r=jrmuizel
authorJeff Gilbert <jgilbert@mozilla.com>
Tue, 14 Jun 2016 10:07:55 -0700
changeset 305269 f99eeb83698292a803c379b6067df6bbc358080f
parent 305268 057ec3ca368097a2594d34cef36e7151353297c9
child 305270 4423ce67bfb77ef8085afbb1f5159e4e0732d566
push id79535
push userjgilbert@mozilla.com
push dateMon, 18 Jul 2016 04:46:14 +0000
treeherdermozilla-inbound@b658098634b8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjrmuizel
bugs1250710
milestone50.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 1250710 - Update scoped pack/unpack helpers. - r=jrmuizel MozReview-Commit-ID: 1WHVAAb4V00
gfx/gl/ScopedGLHelpers.cpp
gfx/gl/ScopedGLHelpers.h
--- a/gfx/gl/ScopedGLHelpers.cpp
+++ b/gfx/gl/ScopedGLHelpers.cpp
@@ -513,66 +513,103 @@ ScopedGLDrawState::~ScopedGLDrawState()
                               attrib0_pointer);
 
     mGL->fBindBuffer(LOCAL_GL_ARRAY_BUFFER, boundBuffer);
 
     mGL->fUseProgram(boundProgram);
 }
 
 ////////////////////////////////////////////////////////////////////////
-// ScopedPackAlignment
+// ScopedPackState
 
-ScopedPackAlignment::ScopedPackAlignment(GLContext* gl, GLint scopedVal)
-    : ScopedGLWrapper<ScopedPackAlignment>(gl)
+static bool
+HasPBOState(const GLContext* gl)
+{
+    return (!gl->IsGLES() || gl->Version() >= 300);
+}
+
+ScopedPackState::ScopedPackState(GLContext* gl)
+    : ScopedGLWrapper<ScopedPackState>(gl)
 {
-    MOZ_ASSERT(scopedVal == 1 ||
-               scopedVal == 2 ||
-               scopedVal == 4 ||
-               scopedVal == 8);
+    mGL->fGetIntegerv(LOCAL_GL_PACK_ALIGNMENT, &mAlignment);
 
-    gl->fGetIntegerv(LOCAL_GL_PACK_ALIGNMENT, &mOldVal);
+    if (mAlignment != 4) mGL->fPixelStorei(LOCAL_GL_PACK_ALIGNMENT, 4);
+
+    if (!HasPBOState(mGL))
+        return;
 
-    if (scopedVal != mOldVal) {
-        gl->fPixelStorei(LOCAL_GL_PACK_ALIGNMENT, scopedVal);
-    } else {
-      // Don't try to re-set it during unwrap.
-        mOldVal = 0;
-    }
+    mGL->fGetIntegerv(LOCAL_GL_PIXEL_PACK_BUFFER_BINDING, (GLint*)&mPixelBuffer);
+    mGL->fGetIntegerv(LOCAL_GL_PACK_ROW_LENGTH, &mRowLength);
+    mGL->fGetIntegerv(LOCAL_GL_PACK_SKIP_PIXELS, &mSkipPixels);
+    mGL->fGetIntegerv(LOCAL_GL_PACK_SKIP_ROWS, &mSkipRows);
+
+    if (mPixelBuffer != 0) mGL->fBindBuffer(LOCAL_GL_PIXEL_PACK_BUFFER, 0);
+    if (mRowLength != 0)   mGL->fPixelStorei(LOCAL_GL_PACK_ROW_LENGTH, 0);
+    if (mSkipPixels != 0)  mGL->fPixelStorei(LOCAL_GL_PACK_SKIP_PIXELS, 0);
+    if (mSkipRows != 0)    mGL->fPixelStorei(LOCAL_GL_PACK_SKIP_ROWS, 0);
 }
 
 void
-ScopedPackAlignment::UnwrapImpl() {
+ScopedPackState::UnwrapImpl()
+{
     // Check that we're not falling out of scope after the current context changed.
     MOZ_ASSERT(mGL->IsCurrent());
 
-    if (mOldVal) {
-        mGL->fPixelStorei(LOCAL_GL_PACK_ALIGNMENT, mOldVal);
-    }
+    mGL->fPixelStorei(LOCAL_GL_PACK_ALIGNMENT, mAlignment);
+
+    if (!HasPBOState(mGL))
+        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);
 }
 
 ////////////////////////////////////////////////////////////////////////
-// ScopedUnpackAlignment
+// ScopedUnpackState
 
-ScopedUnpackAlignment::ScopedUnpackAlignment(GLContext* gl, GLint scopedVal)
-    : ScopedGLWrapper<ScopedUnpackAlignment>(gl)
+ScopedUnpackState::ScopedUnpackState(GLContext* gl)
+    : ScopedGLWrapper<ScopedUnpackState>(gl)
 {
-    MOZ_ASSERT(scopedVal == 1 ||
-               scopedVal == 2 ||
-               scopedVal == 4 ||
-               scopedVal == 8);
+    mGL->fGetIntegerv(LOCAL_GL_UNPACK_ALIGNMENT, &mAlignment);
+
+    if (mAlignment != 4) mGL->fPixelStorei(LOCAL_GL_UNPACK_ALIGNMENT, 4);
+
+    if (!HasPBOState(mGL))
+        return;
 
-    gl->fGetIntegerv(LOCAL_GL_UNPACK_ALIGNMENT, &mOldVal);
+    mGL->fGetIntegerv(LOCAL_GL_PIXEL_UNPACK_BUFFER_BINDING, (GLint*)&mPixelBuffer);
+    mGL->fGetIntegerv(LOCAL_GL_UNPACK_IMAGE_HEIGHT, &mImageHeight);
+    mGL->fGetIntegerv(LOCAL_GL_UNPACK_ROW_LENGTH, &mRowLength);
+    mGL->fGetIntegerv(LOCAL_GL_UNPACK_SKIP_IMAGES, &mSkipImages);
+    mGL->fGetIntegerv(LOCAL_GL_UNPACK_SKIP_PIXELS, &mSkipPixels);
+    mGL->fGetIntegerv(LOCAL_GL_UNPACK_SKIP_ROWS, &mSkipRows);
 
-    if (scopedVal != mOldVal) {
-        gl->fPixelStorei(LOCAL_GL_UNPACK_ALIGNMENT, scopedVal);
-    }
+    if (mPixelBuffer != 0) mGL->fBindBuffer(LOCAL_GL_PIXEL_UNPACK_BUFFER, 0);
+    if (mImageHeight != 0) mGL->fPixelStorei(LOCAL_GL_UNPACK_IMAGE_HEIGHT, 0);
+    if (mRowLength != 0)   mGL->fPixelStorei(LOCAL_GL_UNPACK_ROW_LENGTH, 0);
+    if (mSkipImages != 0)  mGL->fPixelStorei(LOCAL_GL_UNPACK_SKIP_IMAGES, 0);
+    if (mSkipPixels != 0)  mGL->fPixelStorei(LOCAL_GL_UNPACK_SKIP_PIXELS, 0);
+    if (mSkipRows != 0)    mGL->fPixelStorei(LOCAL_GL_UNPACK_SKIP_ROWS, 0);
 }
 
 void
-ScopedUnpackAlignment::UnwrapImpl() {
+ScopedUnpackState::UnwrapImpl()
+{
     // Check that we're not falling out of scope after the current context changed.
     MOZ_ASSERT(mGL->IsCurrent());
 
-    mGL->fPixelStorei(LOCAL_GL_UNPACK_ALIGNMENT, mOldVal);
+    mGL->fPixelStorei(LOCAL_GL_UNPACK_ALIGNMENT, mAlignment);
+
+    if (!HasPBOState(mGL))
+        return;
+
+    mGL->fBindBuffer(LOCAL_GL_PIXEL_UNPACK_BUFFER, mPixelBuffer);
+    mGL->fPixelStorei(LOCAL_GL_UNPACK_IMAGE_HEIGHT, mImageHeight);
+    mGL->fPixelStorei(LOCAL_GL_UNPACK_ROW_LENGTH, mRowLength);
+    mGL->fPixelStorei(LOCAL_GL_UNPACK_SKIP_IMAGES, mSkipImages);
+    mGL->fPixelStorei(LOCAL_GL_UNPACK_SKIP_PIXELS, mSkipPixels);
+    mGL->fPixelStorei(LOCAL_GL_UNPACK_SKIP_ROWS, mSkipRows);
 }
 
 } /* namespace gl */
 } /* namespace mozilla */
--- a/gfx/gl/ScopedGLHelpers.h
+++ b/gfx/gl/ScopedGLHelpers.h
@@ -337,42 +337,54 @@ struct ScopedGLDrawState {
 
     realGLboolean colorMask[4];
     GLint viewport[4];
     GLint scissorBox[4];
     GLContext* const mGL;
     GLuint packAlign;
 };
 
-struct ScopedPackAlignment
-    : public ScopedGLWrapper<ScopedPackAlignment>
+struct ScopedPackState
+    : public ScopedGLWrapper<ScopedPackState>
 {
-    friend struct ScopedGLWrapper<ScopedPackAlignment>;
+    friend struct ScopedGLWrapper<ScopedPackState>;
 
 protected:
-    GLint mOldVal;
+    GLint mAlignment;
+
+    GLuint mPixelBuffer;
+    GLint mRowLength;
+    GLint mSkipPixels;
+    GLint mSkipRows;
 
 public:
-    ScopedPackAlignment(GLContext* aGL, GLint scopedVal);
+    explicit ScopedPackState(GLContext* gl);
 
 protected:
     void UnwrapImpl();
 };
 
 
-struct ScopedUnpackAlignment
-    : public ScopedGLWrapper<ScopedUnpackAlignment>
+struct ScopedUnpackState
+    : public ScopedGLWrapper<ScopedUnpackState>
 {
-    friend struct ScopedGLWrapper<ScopedUnpackAlignment>;
+    friend struct ScopedGLWrapper<ScopedUnpackState>;
 
 protected:
-    GLint mOldVal;
+    GLint mAlignment;
+
+    GLuint mPixelBuffer;
+    GLint mImageHeight;
+    GLint mRowLength;
+    GLint mSkipImages;
+    GLint mSkipPixels;
+    GLint mSkipRows;
 
 public:
-    ScopedUnpackAlignment(GLContext* gl, GLint scopedVal);
+    explicit ScopedUnpackState(GLContext* gl);
 
 protected:
     void UnwrapImpl();
 };
 
 } /* namespace gl */
 } /* namespace mozilla */