avoid recreating effectframes/textures on setPosition; correct position after setAlignment

svn path=/trunk/KDE/kdebase/workspace/; revision=1203489
This commit is contained in:
Thomas Lübking 2010-12-04 10:01:57 +00:00
parent 874d06980d
commit 48447a3d26
5 changed files with 45 additions and 31 deletions

View file

@ -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 );
}

View file

@ -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;

View file

@ -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()

View file

@ -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;

View file

@ -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<float> 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 )