summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLouis-Francis Ratté-Boulianne <lfrb@collabora.com>2014-11-22 08:07:47 -0500
committerLouis-Francis Ratté-Boulianne <lfrb@collabora.com>2014-11-22 08:07:47 -0500
commit6563a9071d6da2cc92f4967da7be5f6f67154081 (patch)
tree4ecf2297dd67a0c0807b3858733f2c0e38fb1a8e
parent385dd7da3aa1c202ec70e2c3213b6b70ab772108 (diff)
vcl: Track the GL context's clip region and update before drawing when needed
Change-Id: Ibec92851dc87f6696ee55a8db10fe160cd97d09c
-rw-r--r--include/vcl/opengl/OpenGLContext.hxx1
-rw-r--r--vcl/inc/openglgdiimpl.hxx2
-rw-r--r--vcl/opengl/gdiimpl.cxx59
3 files changed, 34 insertions, 28 deletions
diff --git a/include/vcl/opengl/OpenGLContext.hxx b/include/vcl/opengl/OpenGLContext.hxx
index b790453a55f7..9be9c593b362 100644
--- a/include/vcl/opengl/OpenGLContext.hxx
+++ b/include/vcl/opengl/OpenGLContext.hxx
@@ -230,6 +230,7 @@ private:
#endif
public:
+ vcl::Region maClipRegion;
int mnPainting;
OpenGLContext* mpPrevContext;
diff --git a/vcl/inc/openglgdiimpl.hxx b/vcl/inc/openglgdiimpl.hxx
index 74469032db07..a6495b71bc6f 100644
--- a/vcl/inc/openglgdiimpl.hxx
+++ b/vcl/inc/openglgdiimpl.hxx
@@ -38,6 +38,7 @@ protected:
OpenGLContext* mpContext;
// clipping
+ vcl::Region maClipRegion;
bool mbUseScissor;
bool mbUseStencil;
@@ -91,6 +92,7 @@ protected:
GLuint mnRadialGradientEndColorUniform;
GLuint mnRadialGradientCenterUniform;
+ void ImplInitClipRegion();
void ImplSetClipBit( const vcl::Region& rClip, GLuint nMask );
bool CheckOffscreenTexture();
diff --git a/vcl/opengl/gdiimpl.cxx b/vcl/opengl/gdiimpl.cxx
index 1151b730cc5c..f7b8bdfa45f5 100644
--- a/vcl/opengl/gdiimpl.cxx
+++ b/vcl/opengl/gdiimpl.cxx
@@ -213,13 +213,7 @@ void OpenGLSalGraphicsImpl::PreDraw()
if( mbOffscreen )
CheckOffscreenTexture();
glViewport( 0, 0, GetWidth(), GetHeight() );
- if( mbUseScissor )
- glEnable( GL_SCISSOR_TEST );
- if( mbUseStencil )
- {
- glStencilFunc( GL_EQUAL, 1, 0x1 );
- glEnable( GL_STENCIL_TEST );
- }
+ ImplInitClipRegion();
CHECK_GL_ERROR();
}
@@ -263,36 +257,44 @@ void OpenGLSalGraphicsImpl::ImplSetClipBit( const vcl::Region& rClip, GLuint nMa
CHECK_GL_ERROR();
}
-bool OpenGLSalGraphicsImpl::setClipRegion( const vcl::Region& rClip )
+void OpenGLSalGraphicsImpl::ImplInitClipRegion()
{
- SAL_INFO( "vcl.opengl", "::setClipRegion " << rClip );
-
- if( rClip.IsEmpty() )
+ // make sure the context has the right clipping set
+ if( maClipRegion != mpContext->maClipRegion )
{
- ResetClipRegion();
- return true;
+ mpContext->maClipRegion = maClipRegion;
+ if( maClipRegion.IsRectangle() )
+ {
+ Rectangle aRect( maClipRegion.GetBoundRect() );
+ glScissor( aRect.Left(), GetHeight() - aRect.Bottom() - 1, aRect.GetWidth() + 1, aRect.GetHeight() + 1 );
+ }
+ else if( !maClipRegion.IsEmpty() )
+ {
+ ImplSetClipBit( maClipRegion, 0x01 );
+ }
}
- if( rClip.IsRectangle() )
+ if( mbUseScissor )
+ glEnable( GL_SCISSOR_TEST );
+ if( mbUseStencil )
{
- Rectangle aRect( rClip.GetBoundRect() );
+ glStencilFunc( GL_EQUAL, 1, 0x1 );
+ glEnable( GL_STENCIL_TEST );
+ }
+}
+
+bool OpenGLSalGraphicsImpl::setClipRegion( const vcl::Region& rClip )
+{
+ SAL_INFO( "vcl.opengl", "::setClipRegion " << rClip );
+ maClipRegion = rClip;
- mbUseStencil = false;
+ mbUseStencil = false;
+ mbUseScissor = false;
+ if( maClipRegion.IsRectangle() )
mbUseScissor = true;
- maContext.makeCurrent();
- glViewport( 0, 0, GetWidth(), GetHeight() );
- glScissor( aRect.Left(), GetHeight() - aRect.Bottom() - 1, aRect.GetWidth(), aRect.GetHeight() );
- }
- else
- {
+ else if ( !maClipRegion.IsEmpty() )
mbUseStencil = true;
- mbUseScissor = false;
- maContext.makeCurrent();
- glViewport( 0, 0, GetWidth(), GetHeight() );
- ImplSetClipBit( rClip, 0x01 );
- }
- CHECK_GL_ERROR();
return true;
}
@@ -300,6 +302,7 @@ bool OpenGLSalGraphicsImpl::setClipRegion( const vcl::Region& rClip )
void OpenGLSalGraphicsImpl::ResetClipRegion()
{
SAL_INFO( "vcl.opengl", "::ResetClipRegion" );
+ maClipRegion.SetEmpty();
mbUseScissor = false;
mbUseStencil = false;
}