From fa832b7aa7854eef6136b1697845acff56ef8ef6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Tue, 20 Jul 2010 21:11:03 +0000 Subject: [PATCH] Cache the icon texture/picture in EffectFrame and use texture from pixmap to load the data in OpenGL mode. Yeah for less pixmap to image to gltexture conversations. Some effects (boxswitch and flipswitch) still need to be changed to not set the icon in each frame. svn path=/trunk/KDE/kdebase/workspace/; revision=1152367 --- effects.cpp | 2 ++ scene.h | 1 + scene_opengl.cpp | 24 +++++++++++++++++++----- scene_opengl.h | 2 ++ scene_xrender.cpp | 16 +++++++++++++--- scene_xrender.h | 2 ++ 6 files changed, 39 insertions(+), 8 deletions(-) diff --git a/effects.cpp b/effects.cpp index 991b8f9045..1a882a0120 100644 --- a/effects.cpp +++ b/effects.cpp @@ -1745,6 +1745,7 @@ void EffectFrameImpl::setIcon( const QPixmap& icon ) { setIconSize( m_icon.size() ); } + m_sceneFrame->freeIconFrame(); } const QSize& EffectFrameImpl::iconSize() const @@ -1760,6 +1761,7 @@ void EffectFrameImpl::setIconSize( const QSize& size ) } m_iconSize = size; autoResize(); + m_sceneFrame->freeIconFrame(); } void EffectFrameImpl::plasmaThemeChanged() diff --git a/scene.h b/scene.h index 870749e140..b302fbc7ce 100644 --- a/scene.h +++ b/scene.h @@ -221,6 +221,7 @@ class Scene::EffectFrame virtual ~EffectFrame(); virtual void render( QRegion region, double opacity, double frameOpacity ) = 0; virtual void free() = 0; + virtual void freeIconFrame() = 0; virtual void freeTextFrame() = 0; protected: diff --git a/scene_opengl.cpp b/scene_opengl.cpp index f6049b4b14..698e7d4482 100644 --- a/scene_opengl.cpp +++ b/scene_opengl.cpp @@ -1920,6 +1920,7 @@ SceneOpenGL::EffectFrame::EffectFrame( EffectFrameImpl* frame ) : Scene::EffectFrame( frame ) , m_texture( NULL ) , m_textTexture( NULL ) + , m_iconTexture( NULL ) { if( m_effectFrame->style() == Unstyled && !m_unstyledTexture ) { @@ -1931,6 +1932,7 @@ SceneOpenGL::EffectFrame::~EffectFrame() { delete m_texture; delete m_textTexture; + delete m_iconTexture; } void SceneOpenGL::EffectFrame::free() @@ -1939,6 +1941,14 @@ void SceneOpenGL::EffectFrame::free() m_texture = NULL; delete m_textTexture; m_textTexture = NULL; + delete m_iconTexture; + m_iconTexture = NULL; + } + +void SceneOpenGL::EffectFrame::freeIconFrame() + { + delete m_iconTexture; + m_iconTexture = NULL; } void SceneOpenGL::EffectFrame::freeTextFrame() @@ -2039,11 +2049,15 @@ void SceneOpenGL::EffectFrame::render( QRegion region, double opacity, double fr QPoint topLeft( m_effectFrame->geometry().x(), m_effectFrame->geometry().center().y() - m_effectFrame->iconSize().height() / 2 ); - GLTexture* icon = new GLTexture( m_effectFrame->icon() ); // TODO: Cache - icon->bind(); - icon->render( region, QRect( topLeft, m_effectFrame->iconSize() )); - icon->unbind(); - delete icon; + if( !m_iconTexture ) // lazy creation + { + m_iconTexture = new Texture( m_effectFrame->icon().handle(), + m_effectFrame->icon().size(), + m_effectFrame->icon().depth() ); + } + m_iconTexture->bind(); + m_iconTexture->render( region, QRect( topLeft, m_effectFrame->iconSize() )); + m_iconTexture->unbind(); } // Render text diff --git a/scene_opengl.h b/scene_opengl.h index 85de6eecf2..dab3dda060 100644 --- a/scene_opengl.h +++ b/scene_opengl.h @@ -174,6 +174,7 @@ class SceneOpenGL::EffectFrame virtual ~EffectFrame(); virtual void free(); + virtual void freeIconFrame(); virtual void freeTextFrame(); virtual void render(QRegion region, double opacity, double frameOpacity); @@ -186,6 +187,7 @@ class SceneOpenGL::EffectFrame GLTexture* m_texture; GLTexture* m_textTexture; + GLTexture* m_iconTexture; static GLTexture* m_unstyledTexture; static void updateUnstyledTexture(); // Update OpenGL unstyled frame texture diff --git a/scene_xrender.cpp b/scene_xrender.cpp index 537116b818..c998ccfe81 100644 --- a/scene_xrender.cpp +++ b/scene_xrender.cpp @@ -854,12 +854,14 @@ SceneXrender::EffectFrame::EffectFrame( EffectFrameImpl* frame ) { m_picture = NULL; m_textPicture = NULL; + m_iconPicture = NULL; } SceneXrender::EffectFrame::~EffectFrame() { delete m_picture; delete m_textPicture; + delete m_iconPicture; } void SceneXrender::EffectFrame::free() @@ -868,6 +870,14 @@ void SceneXrender::EffectFrame::free() m_picture = NULL; delete m_textPicture; m_textPicture = NULL; + delete m_iconPicture; + m_iconPicture = NULL; + } + +void SceneXrender::EffectFrame::freeIconFrame() + { + delete m_iconPicture; + m_iconPicture = NULL; } void SceneXrender::EffectFrame::freeTextFrame() @@ -907,11 +917,11 @@ void SceneXrender::EffectFrame::render( QRegion region, double opacity, double f { QPoint topLeft( m_effectFrame->geometry().x(), m_effectFrame->geometry().center().y() - m_effectFrame->iconSize().height() / 2 ); - XRenderPicture* icon = new XRenderPicture( m_effectFrame->icon() ); // TODO: Cache + if( !m_iconPicture ) // lazy creation + m_iconPicture = new XRenderPicture( m_effectFrame->icon() ); QRect geom = QRect( topLeft, m_effectFrame->iconSize() ); - XRenderComposite( display(), PictOpOver, *icon, fill, effects->xrenderBufferPicture(), + XRenderComposite( display(), PictOpOver, *m_iconPicture, fill, effects->xrenderBufferPicture(), 0, 0, 0, 0, geom.x(), geom.y(), geom.width(), geom.height() ); - delete icon; } // Render text diff --git a/scene_xrender.h b/scene_xrender.h index 6e6990e910..fa07462504 100644 --- a/scene_xrender.h +++ b/scene_xrender.h @@ -101,6 +101,7 @@ class SceneXrender::EffectFrame virtual ~EffectFrame(); virtual void free(); + virtual void freeIconFrame(); virtual void freeTextFrame(); virtual void render( QRegion region, double opacity, double frameOpacity ); @@ -110,6 +111,7 @@ class SceneXrender::EffectFrame XRenderPicture* m_picture; XRenderPicture* m_textPicture; + XRenderPicture* m_iconPicture; }; inline