Bug 956154 - 1/2 - Remove GLContext's viewport stack - r=jgilbert

This commit is contained in:
Benoit Jacob 2014-01-07 15:02:18 -05:00
parent e9a9d5ea27
commit 49cebff464
6 changed files with 37 additions and 52 deletions

View File

@ -113,7 +113,7 @@ GLBlitTextureImageHelper::BlitTextureImage(TextureImage *aSrc, const nsIntRect&
float dy0 = 2.0f * float(srcSubInDstRect.y) / float(dstSize.height) - 1.0f;
float dx1 = 2.0f * float(srcSubInDstRect.x + srcSubInDstRect.width) / float(dstSize.width) - 1.0f;
float dy1 = 2.0f * float(srcSubInDstRect.y + srcSubInDstRect.height) / float(dstSize.height) - 1.0f;
mGL->PushViewportRect(nsIntRect(0, 0, dstSize.width, dstSize.height));
ScopedViewportRect autoViewportRect(mGL, 0, 0, dstSize.width, dstSize.height);
RectTriangles rects;
@ -160,7 +160,6 @@ GLBlitTextureImageHelper::BlitTextureImage(TextureImage *aSrc, const nsIntRect&
mGL->fDisableVertexAttribArray(0);
mGL->fDisableVertexAttribArray(1);
mGL->PopViewportRect();
} while (aSrc->NextTile());
} while (aDst->NextTile());

View File

@ -1028,9 +1028,6 @@ GLContext::InitWithPrefix(const char *prefix, bool trygl)
fGetIntegerv(LOCAL_GL_SCISSOR_BOX, v);
mScissorStack.AppendElement(nsIntRect(v[0], v[1], v[2], v[3]));
fGetIntegerv(LOCAL_GL_VIEWPORT, v);
mViewportStack.AppendElement(nsIntRect(v[0], v[1], v[2], v[3]));
raw_fGetIntegerv(LOCAL_GL_MAX_TEXTURE_SIZE, &mMaxTextureSize);
raw_fGetIntegerv(LOCAL_GL_MAX_CUBE_MAP_TEXTURE_SIZE, &mMaxCubeMapTextureSize);
raw_fGetIntegerv(LOCAL_GL_MAX_RENDERBUFFER_SIZE, &mMaxRenderbufferSize);
@ -1542,7 +1539,6 @@ GLContext::ClearSafely()
// prepare GL state for clearing
fDisable(LOCAL_GL_SCISSOR_TEST);
fDisable(LOCAL_GL_DITHER);
PushViewportRect(nsIntRect(0, 0, OffscreenSize().width, OffscreenSize().height));
fColorMask(1, 1, 1, 1);
fClearColor(0.f, 0.f, 0.f, 0.f);
@ -1575,8 +1571,6 @@ GLContext::ClearSafely()
fStencilMaskSeparate(LOCAL_GL_BACK, stencilWriteMaskBack);
fClearStencil(stencilClearValue);
PopViewportRect();
if (ditherEnabled)
fEnable(LOCAL_GL_DITHER);
else

View File

@ -2784,7 +2784,6 @@ protected:
void InitExtensions();
nsTArray<nsIntRect> mViewportStack;
nsTArray<nsIntRect> mScissorStack;
GLint mMaxTextureSize;
@ -2850,51 +2849,12 @@ public:
}
}
/*** Viewport functions ***/
private:
// only does the glViewport call, no ViewportRect business
void raw_fViewport(GLint x, GLint y, GLsizei width, GLsizei height) {
void fViewport(GLint x, GLint y, GLsizei width, GLsizei height) {
BEFORE_GL_CALL;
mSymbols.fViewport(x, y, width, height);
AFTER_GL_CALL;
}
public:
void fViewport(GLint x, GLint y, GLsizei width, GLsizei height) {
ViewportRect().SetRect(x, y, width, height);
raw_fViewport(x, y, width, height);
}
nsIntRect& ViewportRect() {
return mViewportStack[mViewportStack.Length()-1];
}
void PushViewportRect() {
nsIntRect copy(ViewportRect());
mViewportStack.AppendElement(copy);
}
void PushViewportRect(const nsIntRect& aRect) {
mViewportStack.AppendElement(aRect);
raw_fViewport(aRect.x, aRect.y, aRect.width, aRect.height);
}
void PopViewportRect() {
if (mViewportStack.Length() < 2) {
NS_WARNING("PopViewportRect with Length < 2!");
return;
}
nsIntRect thisRect = ViewportRect();
mViewportStack.TruncateLength(mViewportStack.Length() - 1);
if (!thisRect.IsEqualInterior(ViewportRect())) {
raw_fViewport(ViewportRect().x, ViewportRect().y,
ViewportRect().width, ViewportRect().height);
}
}
#undef ASSERT_SYMBOL_PRESENT
#ifdef MOZ_ENABLE_GL_TRACKING

View File

@ -529,7 +529,7 @@ GLReadTexImageHelper::ReadTexImage(GLuint aTextureId,
mGL->fDisable(LOCAL_GL_BLEND);
mGL->fDisable(LOCAL_GL_SCISSOR_TEST);
mGL->PushViewportRect(nsIntRect(0, 0, aSize.width, aSize.height));
ScopedViewportRect(mGL, 0, 0, aSize.width, aSize.height);
/* Setup renderbuffer */
mGL->fGenRenderbuffers(1, &rb);
@ -633,8 +633,6 @@ GLReadTexImageHelper::ReadTexImage(GLuint aTextureId,
if (oldTexUnit != LOCAL_GL_TEXTURE0)
mGL->fActiveTexture(oldTexUnit);
mGL->PopViewportRect();
return isurf.forget();
}

View File

@ -240,5 +240,24 @@ ScopedFramebufferForRenderbuffer::UnwrapImpl()
mFB = 0;
}
/* ScopedViewportRect *********************************************************/
ScopedViewportRect::ScopedViewportRect(GLContext* aGL,
GLint x, GLint y,
GLsizei width, GLsizei height)
: ScopedGLWrapper<ScopedViewportRect>(aGL)
{
mGL->fGetIntegerv(LOCAL_GL_VIEWPORT, mSavedViewportRect);
mGL->fViewport(x, y, width, height);
}
void ScopedViewportRect::UnwrapImpl()
{
mGL->fViewport(mSavedViewportRect[0],
mSavedViewportRect[1],
mSavedViewportRect[2],
mSavedViewportRect[3]);
}
} /* namespace gl */
} /* namespace mozilla */

View File

@ -209,6 +209,21 @@ protected:
void UnwrapImpl();
};
struct ScopedViewportRect
: public ScopedGLWrapper<ScopedViewportRect>
{
friend struct ScopedGLWrapper<ScopedViewportRect>;
protected:
GLint mSavedViewportRect[4];
public:
ScopedViewportRect(GLContext* aGL, GLint x, GLint y, GLsizei width, GLsizei height);
protected:
void UnwrapImpl();
};
} /* namespace gl */
} /* namespace mozilla */