From 99a0cddd77c19c8873b0d46de8e00077f674b640 Mon Sep 17 00:00:00 2001 From: Hugo Pereira Da Costa Date: Wed, 14 Apr 2010 22:21:08 +0000 Subject: [PATCH] Reduce cache size and truncate opacity settings for shadow focus transition, based on the animation durations. For default duration (200msec), this reduces the size of the cache by about a factor 10, and still corresponds to a 120Hz frame rate. BUG: 234187 svn path=/trunk/KDE/kdebase/workspace/; revision=1114935 --- clients/oxygen/oxygen.cpp | 28 +++++++++++++++- clients/oxygen/oxygen.h | 2 -- clients/oxygen/oxygenclient.cpp | 3 +- clients/oxygen/oxygenconfiguration.cpp | 3 +- clients/oxygen/oxygenconfiguration.h | 28 ++++++++++++++++ clients/oxygen/oxygenshadowcache.cpp | 14 ++++---- clients/oxygen/oxygenshadowcache.h | 45 ++++++++++++++++++++++++-- 7 files changed, 108 insertions(+), 15 deletions(-) diff --git a/clients/oxygen/oxygen.cpp b/clients/oxygen/oxygen.cpp index b6d3dba63b..6de28b39e0 100644 --- a/clients/oxygen/oxygen.cpp +++ b/clients/oxygen/oxygen.cpp @@ -48,7 +48,7 @@ namespace Oxygen OxygenFactory::OxygenFactory(): initialized_( false ), helper_( "oxygenDeco" ), - shadowCache_( helper_, maxAnimationIndex) + shadowCache_( helper_ ) { readConfig(); setInitialized( true ); @@ -109,6 +109,32 @@ namespace Oxygen changed = true; } + // initialize shadow cache + switch( defaultConfiguration().shadowCacheMode() ) + { + case OxygenConfiguration::CacheDisabled: + { + shadowCache_.setEnabled( false ); + break; + } + + default: + case OxygenConfiguration::CacheVariable: + { + shadowCache_.setEnabled( true ); + shadowCache_.setMaxIndex( qMin( 256, int( 120*defaultConfiguration().animationsDuration()/1000 ) ) ); + break; + } + + case OxygenConfiguration::CacheMaximum: + { + shadowCache_.setEnabled( true ); + shadowCache_.setMaxIndex( 256 ); + break; + } + + } + // read exceptionsreadConfig OxygenExceptionList exceptions( config ); if( !( exceptions == exceptions_ ) ) diff --git a/clients/oxygen/oxygen.h b/clients/oxygen/oxygen.h index aba8d228b9..c2ad3c2657 100644 --- a/clients/oxygen/oxygen.h +++ b/clients/oxygen/oxygen.h @@ -68,8 +68,6 @@ namespace Oxygen enum { - //! maximum index/frame used for animations - maxAnimationIndex = 256, //! this is the top title bar edge TFRAMESIZE = 3, diff --git a/clients/oxygen/oxygenclient.cpp b/clients/oxygen/oxygenclient.cpp index 92d092d333..dadddee006 100644 --- a/clients/oxygen/oxygenclient.cpp +++ b/clients/oxygen/oxygenclient.cpp @@ -1345,8 +1345,7 @@ namespace Oxygen if( configuration().useOxygenShadows() && glowIsAnimated() && !isForcedActive() ) { - int frame = maxAnimationIndex*glowIntensity(); - tileSet = shadowCache().tileSet( this, frame ); + tileSet = shadowCache().tileSet( this, glowIntensity() ); } else tileSet = shadowCache().tileSet( this ); diff --git a/clients/oxygen/oxygenconfiguration.cpp b/clients/oxygen/oxygenconfiguration.cpp index 573a1a17c9..63d94e27e6 100644 --- a/clients/oxygen/oxygenconfiguration.cpp +++ b/clients/oxygen/oxygenconfiguration.cpp @@ -46,7 +46,8 @@ namespace Oxygen animateTitleChange_( true ), animationsDuration_( 150 ), tabsEnabled_( true ), - useNarrowButtonSpacing_( false ) + useNarrowButtonSpacing_( false ), + shadowCacheMode_( CacheVariable ) {} //__________________________________________________ diff --git a/clients/oxygen/oxygenconfiguration.h b/clients/oxygen/oxygenconfiguration.h index 46ed4e5a2d..8a2fb0b1c3 100644 --- a/clients/oxygen/oxygenconfiguration.h +++ b/clients/oxygen/oxygenconfiguration.h @@ -93,6 +93,20 @@ namespace Oxygen SizeGripWhenNeeded }; + //! cache mode + enum ShadowCacheMode + { + // no shadow cache + CacheDisabled, + + // shadow cache depends + // on animation duration + CacheVariable, + + // shadow cache has maximum size + CacheMaximum + }; + //! default constructor OxygenConfiguration( void ); @@ -156,6 +170,17 @@ namespace Oxygen //@} + //!@name cache mode + //@{ + + void setShadowCacheMode( ShadowCacheMode mode ) + { shadowCacheMode_ = mode; } + + ShadowCacheMode shadowCacheMode( void ) const + { return shadowCacheMode_; } + + //@] + //!@name frame border //@{ @@ -339,6 +364,9 @@ namespace Oxygen //! narrow button spacing bool useNarrowButtonSpacing_; + //! cache mode + ShadowCacheMode shadowCacheMode_; + }; } diff --git a/clients/oxygen/oxygenshadowcache.cpp b/clients/oxygen/oxygenshadowcache.cpp index 17dd77a3c0..206a874541 100644 --- a/clients/oxygen/oxygenshadowcache.cpp +++ b/clients/oxygen/oxygenshadowcache.cpp @@ -32,19 +32,21 @@ #include #include #include +#include namespace Oxygen { //_______________________________________________________ - OxygenShadowCache::OxygenShadowCache( OxygenDecoHelper& helper, int maxIndex ): + OxygenShadowCache::OxygenShadowCache( OxygenDecoHelper& helper ): helper_( helper ), - maxIndex_( maxIndex ), activeShadowConfiguration_( OxygenShadowConfiguration( QPalette::Active ) ), inactiveShadowConfiguration_( OxygenShadowConfiguration( QPalette::Inactive ) ) { - shadowCache_.setMaxCost( 1<<6 ); - animatedShadowCache_.setMaxCost( maxIndex_<<6 ); + + setEnabled( true ); + setMaxIndex( 256 ); + } //_______________________________________________________ @@ -81,9 +83,10 @@ namespace Oxygen } //_______________________________________________________ - TileSet* OxygenShadowCache::tileSet( const OxygenClient* client, int index ) + TileSet* OxygenShadowCache::tileSet( const OxygenClient* client, qreal opacity ) { + int index( opacity*maxIndex_ ); assert( index <= maxIndex_ ); // construct key @@ -96,7 +99,6 @@ namespace Oxygen // create shadow and tileset otherwise qreal size( shadowSize() ); - qreal opacity( qreal(index)/qreal(maxIndex_) ); QPixmap shadow( size*2, size*2 ); shadow.fill( Qt::transparent ); diff --git a/clients/oxygen/oxygenshadowcache.h b/clients/oxygen/oxygenshadowcache.h index 09a4d2b641..a032fee49b 100644 --- a/clients/oxygen/oxygenshadowcache.h +++ b/clients/oxygen/oxygenshadowcache.h @@ -44,12 +44,48 @@ namespace Oxygen public: //! constructor - OxygenShadowCache( OxygenDecoHelper& helper, int maxIndex ); + OxygenShadowCache( OxygenDecoHelper& helper ); //! destructor virtual ~OxygenShadowCache( void ) {} + //! cache size + void setEnabled( bool enabled ) + { + enabled_ = enabled; + if( enabled ) + { + + shadowCache_.setMaxCost( 1<<6 ); + animatedShadowCache_.setMaxCost( maxIndex_<<6 ); + + } else { + + shadowCache_.setMaxCost( 1 ); + animatedShadowCache_.setMaxCost( 1 ); + + } + } + + //! max animation index + int maxIndex( void ) const + { return maxIndex_; } + + //! max animation index + void setMaxIndex( int value ) + { + maxIndex_ = value; + if( enabled_ ) + { + + shadowCache_.setMaxCost( 1<<6 ); + animatedShadowCache_.setMaxCost( maxIndex_<<6 ); + + } + + } + //! invalidate caches void invalidateCaches( void ) { @@ -86,8 +122,8 @@ namespace Oxygen //! get shadow matching client TileSet* tileSet( const OxygenClient* ); - //! get shadow matching client and animation index - TileSet* tileSet( const OxygenClient*, int ); + //! get shadow matching client and opacity + TileSet* tileSet( const OxygenClient*, qreal ); //! Key class to be used into QCache /*! class is entirely inline for optimization */ @@ -168,6 +204,9 @@ namespace Oxygen //! helper OxygenDecoHelper& helper_; + //! caching enable state + bool enabled_; + //! max index /*! it is used to set caches max cost, and calculate animation opacity */ int maxIndex_;