From 48447a3d26d31c54e98fdfa0eb04c362e5a4a4a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20L=C3=BCbking?= Date: Sat, 4 Dec 2010 10:01:57 +0000 Subject: [PATCH] avoid recreating effectframes/textures on setPosition; correct position after setAlignment svn path=/trunk/KDE/kdebase/workspace/; revision=1203489 --- effects.cpp | 46 ++++++++++++++++++++++++--------------------- effects.h | 2 +- lib/kwinglutils.cpp | 18 +++++++++++------- lib/kwinglutils.h | 2 +- scene_opengl.cpp | 8 +++++++- 5 files changed, 45 insertions(+), 31 deletions(-) diff --git a/effects.cpp b/effects.cpp index 3e28ee5da2..c9af32bb46 100644 --- a/effects.cpp +++ b/effects.cpp @@ -1837,20 +1837,38 @@ Qt::Alignment EffectFrameImpl::alignment() const return m_alignment; } + +void +EffectFrameImpl::align( QRect &geometry ) +{ + if( m_alignment & Qt::AlignLeft ) + geometry.moveLeft( m_point.x() ); + else if( m_alignment & Qt::AlignRight ) + geometry.moveLeft( m_point.x() - geometry.width() ); + else + geometry.moveLeft( m_point.x() - geometry.width() / 2 ); + if( m_alignment & Qt::AlignTop ) + geometry.moveTop( m_point.y() ); + else if( m_alignment & Qt::AlignBottom ) + geometry.moveTop( m_point.y() - geometry.height() ); + else + geometry.moveTop( m_point.y() - geometry.height() / 2 ); +} + + void EffectFrameImpl::setAlignment( Qt::Alignment alignment ) { m_alignment = alignment; + align( m_geometry ); + setGeometry( m_geometry ); } void EffectFrameImpl::setPosition( const QPoint& point ) { - if( m_point == point ) - { - return; - } m_point = point; - autoResize(); - free(); + QRect geometry = m_geometry; // this is important, setGeometry need call repaint for old & new geometry + align( geometry ); + setGeometry( geometry ); } const QString& EffectFrameImpl::text() const @@ -1898,7 +1916,6 @@ void EffectFrameImpl::autoResize() return; // Not automatically resizing QRect geometry; - // Set size if( !m_text.isEmpty() ) { @@ -1912,20 +1929,7 @@ void EffectFrameImpl::autoResize() geometry.setHeight( m_iconSize.height() ); } - // Set position - if( m_alignment & Qt::AlignLeft ) - geometry.moveLeft( m_point.x() ); - else if( m_alignment & Qt::AlignRight ) - geometry.moveLeft( m_point.x() - geometry.width() ); - else - geometry.moveLeft( m_point.x() - geometry.width() / 2 ); - if( m_alignment & Qt::AlignTop ) - geometry.moveTop( m_point.y() ); - else if( m_alignment & Qt::AlignBottom ) - geometry.moveTop( m_point.y() - geometry.height() ); - else - geometry.moveTop( m_point.y() - geometry.height() / 2 ); - + align( geometry ); setGeometry( geometry ); } diff --git a/effects.h b/effects.h index c224c52e12..aef751d939 100644 --- a/effects.h +++ b/effects.h @@ -374,7 +374,7 @@ class EffectFrameImpl private: Q_DISABLE_COPY( EffectFrameImpl ) // As we need to use Qt slots we cannot copy this class - + void align( QRect &geometry ); // positions geometry around m_point respecting m_alignment void autoResize(); // Auto-resize if not a static size EffectFrameStyle m_style; diff --git a/lib/kwinglutils.cpp b/lib/kwinglutils.cpp index 4b05764e9e..ecfe492136 100644 --- a/lib/kwinglutils.cpp +++ b/lib/kwinglutils.cpp @@ -434,19 +434,21 @@ void GLTexture::unbind() void GLTexture::render( QRegion region, const QRect& rect ) { - if( rect != m_cachedGeometry ) + if( rect.size() != m_cachedSize ) { - m_cachedGeometry = rect; + m_cachedSize = rect.size(); + QRect r(rect); + r.moveTo(0,0); if( !m_vbo ) { m_vbo = new GLVertexBuffer( KWin::GLVertexBuffer::Static ); } const float verts[ 4 * 2 ] = - { - rect.x(), rect.y(), - rect.x(), rect.y() + rect.height(), - rect.x() + rect.width(), rect.y(), - rect.x() + rect.width(), rect.y() + rect.height() + { // NOTICE: r.x/y could be replaced by "0", but that would make it unreadable... + r.x(), r.y(), + r.x(), r.y() + rect.height(), + r.x() + rect.width(), r.y(), + r.x() + rect.width(), r.y() + rect.height() }; const float texcoords[ 4 * 2 ] = { @@ -457,7 +459,9 @@ void GLTexture::render( QRegion region, const QRect& rect ) }; m_vbo->setData( 4, 2, verts, texcoords ); } + glTranslatef( rect.x(), rect.y(), 0.0f ); m_vbo->render( region, GL_TRIANGLE_STRIP ); + glTranslatef( -rect.x(), -rect.y(), 0.0f ); } void GLTexture::enableUnnormalizedTexCoords() diff --git a/lib/kwinglutils.h b/lib/kwinglutils.h index 6022bdcb60..d18ce2a9a2 100644 --- a/lib/kwinglutils.h +++ b/lib/kwinglutils.h @@ -198,7 +198,7 @@ class KWIN_EXPORT GLTexture int mUnnormalizeActive; // 0 - no, otherwise refcount int mNormalizeActive; // 0 - no, otherwise refcount GLVertexBuffer* m_vbo; - QRect m_cachedGeometry; + QSize m_cachedSize; static bool mNPOTTextureSupported; static bool mFramebufferObjectSupported; diff --git a/scene_opengl.cpp b/scene_opengl.cpp index dc0a2ed084..5fc5fc29af 100644 --- a/scene_opengl.cpp +++ b/scene_opengl.cpp @@ -2049,7 +2049,10 @@ void SceneOpenGL::EffectFrame::render( QRegion region, double opacity, double fr if( !m_unstyledVBO ) { m_unstyledVBO = new GLVertexBuffer( GLVertexBuffer::Static ); - const QRect& area = m_effectFrame->geometry().adjusted( -5, -5, 5, 5 ); + QRect area = m_effectFrame->geometry(); + area.moveTo(0,0); + area.adjust( -5, -5, 5, 5 ); + const int roundness = 5; QVector verts, texCoords; verts.reserve( 84 ); @@ -2156,7 +2159,10 @@ void SceneOpenGL::EffectFrame::render( QRegion region, double opacity, double fr glColor4f( 0.0, 0.0, 0.0, opacity * frameOpacity ); m_unstyledTexture->bind(); + const QPoint pt = m_effectFrame->geometry().topLeft(); + glTranslatef( pt.x(), pt.y(), 0.0f ); m_unstyledVBO->render( region, GL_TRIANGLES ); + glTranslatef( -pt.x(), -pt.y(), 0.0f ); m_unstyledTexture->unbind(); } else if( m_effectFrame->style() == EffectFrameStyled )