LCOV - code coverage report
Current view: top level - canvas/source/tools - spriteredrawmanager.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 1 129 0.8 %
Date: 2012-08-25 Functions: 2 21 9.5 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 2 189 1.1 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : 
      30                 :            : #include <canvas/debug.hxx>
      31                 :            : #include <tools/diagnose_ex.h>
      32                 :            : #include <canvas/spriteredrawmanager.hxx>
      33                 :            : 
      34                 :            : #include <basegfx/range/b2drectangle.hxx>
      35                 :            : #include <basegfx/tools/canvastools.hxx>
      36                 :            : #include <basegfx/vector/b2dsize.hxx>
      37                 :            : 
      38                 :            : #include <algorithm>
      39                 :            : #include <o3tl/compat_functional.hxx>
      40                 :            : #include <boost/bind.hpp>
      41                 :            : 
      42                 :            : 
      43                 :            : namespace canvas
      44                 :            : {
      45                 :            :     namespace
      46                 :            :     {
      47                 :            :         /** Helper class to condense sprite updates into a single action
      48                 :            : 
      49                 :            :             This class tracks the sprite changes over the recorded
      50                 :            :             change list, and generates a single update action from
      51                 :            :             that (note that per screen update, several moves,
      52                 :            :             visibility changes and content updates might happen)
      53                 :            :          */
      54                 :          0 :         class SpriteTracer
      55                 :            :         {
      56                 :            :         public:
      57                 :          0 :             SpriteTracer( const Sprite::Reference& rAffectedSprite ) :
      58                 :            :                 mpAffectedSprite(rAffectedSprite),
      59                 :            :                 maMoveStartArea(),
      60                 :            :                 maMoveEndArea(),
      61                 :            :                 mbIsMove( false ),
      62 [ #  # ][ #  # ]:          0 :                 mbIsGenericUpdate( false )
      63                 :            :             {
      64                 :          0 :             }
      65                 :            : 
      66                 :          0 :             void operator()( const SpriteRedrawManager::SpriteChangeRecord& rSpriteRecord )
      67                 :            :             {
      68                 :            :                 // only deal with change events from the currently
      69                 :            :                 // affected sprite
      70         [ #  # ]:          0 :                 if( rSpriteRecord.mpAffectedSprite == mpAffectedSprite )
      71                 :            :                 {
      72      [ #  #  # ]:          0 :                     switch( rSpriteRecord.meChangeType )
      73                 :            :                     {
      74                 :            :                         case SpriteRedrawManager::SpriteChangeRecord::move:
      75         [ #  # ]:          0 :                             if( !mbIsMove )
      76                 :            :                             {
      77                 :            :                                 // no move yet - this must be the first one
      78                 :            :                                 maMoveStartArea = ::basegfx::B2DRectangle(
      79                 :            :                                     rSpriteRecord.maOldPos,
      80         [ #  # ]:          0 :                                     rSpriteRecord.maOldPos + rSpriteRecord.maUpdateArea.getRange() );
      81                 :          0 :                                 mbIsMove        = true;
      82                 :            :                             }
      83                 :            : 
      84                 :          0 :                             maMoveEndArea   = rSpriteRecord.maUpdateArea;
      85                 :          0 :                             break;
      86                 :            : 
      87                 :            :                         case SpriteRedrawManager::SpriteChangeRecord::update:
      88                 :            :                             // update end update area of the
      89                 :            :                             // sprite. Thus, every update() action
      90                 :            :                             // _after_ the last move will correctly
      91                 :            :                             // update the final repaint area. And this
      92                 :            :                             // does not interfere with subsequent
      93                 :            :                             // moves, because moves always perform a
      94                 :            :                             // hard set of maMoveEndArea to their
      95                 :            :                             // stored value
      96                 :          0 :                             maMoveEndArea.expand( rSpriteRecord.maUpdateArea );
      97                 :          0 :                             mbIsGenericUpdate = true;
      98                 :          0 :                             break;
      99                 :            : 
     100                 :            :                         default:
     101 [ #  # ][ #  # ]:          0 :                             ENSURE_OR_THROW( false,
                 [ #  # ]
     102                 :            :                                               "Unexpected case in SpriteUpdater::operator()" );
     103                 :            :                             break;
     104                 :            :                     }
     105                 :            :                 }
     106                 :          0 :             }
     107                 :            : 
     108                 :          0 :             void commit( SpriteRedrawManager::SpriteConnectedRanges& rUpdateCollector ) const
     109                 :            :             {
     110         [ #  # ]:          0 :                 if( mbIsMove )
     111                 :            :                 {
     112   [ #  #  #  # ]:          0 :                     if( !maMoveStartArea.isEmpty() ||
                 [ #  # ]
     113                 :          0 :                         !maMoveEndArea.isEmpty() )
     114                 :            :                     {
     115                 :            :                         // if mbIsGenericUpdate is false, this is a
     116                 :            :                         // pure move (i.e. no other update
     117                 :            :                         // operations). Pass that information on to
     118                 :            :                         // the SpriteInfo
     119                 :          0 :                         const bool bIsPureMove( !mbIsGenericUpdate );
     120                 :            : 
     121                 :            :                         // ignore the case that start and end update
     122                 :            :                         // area overlap - the b2dconnectedranges
     123                 :            :                         // handle that, anyway. doing it this way
     124                 :            :                         // ensures that we have both old and new area
     125                 :            :                         // stored
     126                 :            : 
     127                 :            :                         // round all given range up to enclosing
     128                 :            :                         // integer rectangle - since the whole thing
     129                 :            :                         // here is about
     130                 :            : 
     131                 :            :                         // first, draw the new sprite position
     132                 :            :                         rUpdateCollector.addRange(
     133                 :          0 :                             ::basegfx::unotools::b2DSurroundingIntegerRangeFromB2DRange( maMoveEndArea ),
     134                 :            :                             SpriteRedrawManager::SpriteInfo(
     135                 :            :                                 mpAffectedSprite,
     136                 :            :                                 maMoveEndArea,
     137                 :            :                                 true,
     138 [ #  # ][ #  # ]:          0 :                                 bIsPureMove ) );
     139                 :            : 
     140                 :            :                         // then, clear the old place (looks smoother
     141                 :            :                         // this way)
     142                 :            :                         rUpdateCollector.addRange(
     143                 :          0 :                             ::basegfx::unotools::b2DSurroundingIntegerRangeFromB2DRange( maMoveStartArea ),
     144                 :            :                             SpriteRedrawManager::SpriteInfo(
     145                 :            :                                 Sprite::Reference(),
     146                 :            :                                 maMoveStartArea,
     147                 :            :                                 true,
     148 [ #  # ][ #  # ]:          0 :                                 bIsPureMove ) );
         [ #  # ][ #  # ]
     149                 :            :                     }
     150                 :            :                 }
     151   [ #  #  #  # ]:          0 :                 else if( mbIsGenericUpdate &&
                 [ #  # ]
     152                 :          0 :                          !maMoveEndArea.isEmpty() )
     153                 :            :                 {
     154                 :            :                     rUpdateCollector.addRange(
     155                 :          0 :                         ::basegfx::unotools::b2DSurroundingIntegerRangeFromB2DRange( maMoveEndArea ),
     156                 :            :                         SpriteRedrawManager::SpriteInfo(
     157                 :            :                             mpAffectedSprite,
     158                 :            :                             maMoveEndArea,
     159 [ #  # ][ #  # ]:          0 :                             true ) );
     160                 :            :                 }
     161                 :          0 :             }
     162                 :            : 
     163                 :            :         private:
     164                 :            :             Sprite::Reference       mpAffectedSprite;
     165                 :            :             ::basegfx::B2DRectangle maMoveStartArea;
     166                 :            :             ::basegfx::B2DRectangle maMoveEndArea;
     167                 :            : 
     168                 :            :             /// True, if at least one move was encountered
     169                 :            :             bool                    mbIsMove;
     170                 :            : 
     171                 :            :             /// True, if at least one generic update was encountered
     172                 :            :             bool                    mbIsGenericUpdate;
     173                 :            :         };
     174                 :            : 
     175                 :            : 
     176                 :            :         /** SpriteChecker functor, which for every sprite checks the
     177                 :            :             given update vector for necessary screen updates
     178                 :            :          */
     179                 :            :         class SpriteUpdater
     180                 :            :         {
     181                 :            :         public:
     182                 :            :             /** Generate update area list
     183                 :            : 
     184                 :            :                 @param rUpdater
     185                 :            :                 Reference to an updater object, which will receive the
     186                 :            :                 update areas.
     187                 :            : 
     188                 :            :                 @param rChangeContainer
     189                 :            :                 Container with all sprite change requests
     190                 :            : 
     191                 :            :              */
     192                 :          0 :             SpriteUpdater( SpriteRedrawManager::SpriteConnectedRanges&          rUpdater,
     193                 :            :                            const SpriteRedrawManager::VectorOfChangeRecords&    rChangeContainer ) :
     194                 :            :                 mrUpdater( rUpdater ),
     195                 :          0 :                 mrChangeContainer( rChangeContainer )
     196                 :            :             {
     197                 :          0 :             }
     198                 :            : 
     199                 :            :             /** Call this method for every sprite on your screen
     200                 :            : 
     201                 :            :                 This method scans the change container, collecting all
     202                 :            :                 update info for the given sprite into one or two
     203                 :            :                 update operations, which in turn are inserted into the
     204                 :            :                 connected ranges processor.
     205                 :            : 
     206                 :            :                 @param rSprite
     207                 :            :                 Current sprite to collect update info for.
     208                 :            :              */
     209                 :          0 :             void operator()( const Sprite::Reference& rSprite )
     210                 :            :             {
     211                 :            :                 const SpriteTracer aSpriteTracer(
     212                 :            :                     ::std::for_each( mrChangeContainer.begin(),
     213                 :            :                                      mrChangeContainer.end(),
     214 [ #  # ][ #  # ]:          0 :                                      SpriteTracer( rSprite ) ) );
                 [ #  # ]
     215                 :            : 
     216 [ #  # ][ #  # ]:          0 :                 aSpriteTracer.commit( mrUpdater );
     217                 :          0 :             }
     218                 :            : 
     219                 :            :         private:
     220                 :            :             SpriteRedrawManager::SpriteConnectedRanges&         mrUpdater;
     221                 :            :             const SpriteRedrawManager::VectorOfChangeRecords&   mrChangeContainer;
     222                 :            :         };
     223                 :            :     }
     224                 :            : 
     225                 :          0 :     void SpriteRedrawManager::setupUpdateAreas( SpriteConnectedRanges& rUpdateAreas ) const
     226                 :            :     {
     227                 :            :         // TODO(T3): This is NOT thread safe at all. This only works
     228                 :            :         // under the assumption that NOBODY changes ANYTHING
     229                 :            :         // concurrently, while this method is on the stack. We should
     230                 :            :         // really rework the canvas::Sprite interface, in such a way
     231                 :            :         // that it dumps ALL its state with a single, atomic
     232                 :            :         // call. Then, we store that state locally. This prolly goes
     233                 :            :         // in line with the problem of having sprite state available
     234                 :            :         // for the frame before the last frame; plus, it avoids
     235                 :            :         // frequent locks of the object mutices
     236                 :            :         SpriteWeakOrder aSpriteComparator;
     237                 :            : 
     238                 :            :         // put all sprites that have changed content into update areas
     239                 :          0 :         ListOfSprites::const_iterator       aCurrSprite( maSprites.begin() );
     240                 :          0 :         const ListOfSprites::const_iterator aEndSprite ( maSprites.end() );
     241         [ #  # ]:          0 :         while( aCurrSprite != aEndSprite )
     242                 :            :         {
     243 [ #  # ][ #  # ]:          0 :             if( (*aCurrSprite)->isContentChanged() )
     244                 :          0 :                 const_cast<SpriteRedrawManager*>(this)->updateSprite( *aCurrSprite,
     245                 :          0 :                                                                       (*aCurrSprite)->getPosPixel(),
     246   [ #  #  #  #  :          0 :                                                                       (*aCurrSprite)->getUpdateArea() );
                   #  # ]
     247                 :          0 :             ++aCurrSprite;
     248                 :            :         }
     249                 :            : 
     250                 :            :         // sort sprites after prio
     251         [ #  # ]:          0 :         VectorOfSprites aSortedSpriteVector;
     252                 :            :         ::std::copy( maSprites.begin(),
     253                 :            :                      maSprites.end(),
     254         [ #  # ]:          0 :                      ::std::back_insert_iterator< VectorOfSprites >(aSortedSpriteVector) );
     255                 :            :         ::std::sort( aSortedSpriteVector.begin(),
     256                 :            :                      aSortedSpriteVector.end(),
     257         [ #  # ]:          0 :                      aSpriteComparator );
     258                 :            : 
     259                 :            :         // extract all referenced sprites from the maChangeRecords
     260                 :            :         // (copy sprites, make the list unique, regarding the
     261                 :            :         // sprite pointer). This assumes that, until this scope
     262                 :            :         // ends, nobody changes the maChangeRecords vector!
     263         [ #  # ]:          0 :         VectorOfSprites aUpdatableSprites;
     264                 :          0 :         VectorOfChangeRecords::const_iterator       aCurrRecord( maChangeRecords.begin() );
     265                 :          0 :         const VectorOfChangeRecords::const_iterator aEndRecords( maChangeRecords.end() );
     266 [ #  # ][ #  # ]:          0 :         while( aCurrRecord != aEndRecords )
     267                 :            :         {
     268 [ #  # ][ #  # ]:          0 :             const Sprite::Reference& rSprite( aCurrRecord->getSprite() );
     269         [ #  # ]:          0 :             if( rSprite.is() )
     270         [ #  # ]:          0 :                 aUpdatableSprites.push_back( rSprite );
     271         [ #  # ]:          0 :             ++aCurrRecord;
     272                 :          0 :         }
     273                 :            : 
     274                 :            :         ::std::sort( aUpdatableSprites.begin(),
     275                 :            :                      aUpdatableSprites.end(),
     276         [ #  # ]:          0 :                      aSpriteComparator );
     277                 :            : 
     278                 :            :         VectorOfSprites::iterator aEnd=
     279                 :            :             ::std::unique( aUpdatableSprites.begin(),
     280         [ #  # ]:          0 :                            aUpdatableSprites.end() );
     281                 :            : 
     282                 :            :         // for each unique sprite, check the change event vector,
     283                 :            :         // calculate the update operation from that, and add the
     284                 :            :         // result to the aUpdateArea.
     285                 :            :         ::std::for_each( aUpdatableSprites.begin(),
     286                 :            :                          aEnd,
     287                 :            :                          SpriteUpdater( rUpdateAreas,
     288         [ #  # ]:          0 :                                         maChangeRecords) );
     289                 :            : 
     290                 :            :         // TODO(P2): Implement your own output iterator adapter, to
     291                 :            :         // avoid that totally superfluous temp aUnchangedSprites
     292                 :            :         // vector.
     293                 :            : 
     294                 :            :         // add all sprites to rUpdateAreas, that are _not_ already
     295                 :            :         // contained in the uniquified vector of changed ones
     296                 :            :         // (i.e. the difference between aSortedSpriteVector and
     297                 :            :         // aUpdatableSprites).
     298         [ #  # ]:          0 :         VectorOfSprites aUnchangedSprites;
     299                 :            :         ::std::set_difference( aSortedSpriteVector.begin(),
     300                 :            :                                aSortedSpriteVector.end(),
     301                 :            :                                aUpdatableSprites.begin(),
     302                 :            :                                aEnd,
     303                 :            :                                ::std::back_insert_iterator< VectorOfSprites >(aUnchangedSprites),
     304         [ #  # ]:          0 :                                aSpriteComparator );
     305                 :            : 
     306                 :            :         // add each remaining unchanged sprite to connected ranges,
     307                 :            :         // marked as "don't need update"
     308         [ #  # ]:          0 :         VectorOfSprites::const_iterator         aCurr( aUnchangedSprites.begin() );
     309         [ #  # ]:          0 :         const VectorOfSprites::const_iterator   aEnd2( aUnchangedSprites.end() );
     310 [ #  # ][ #  # ]:          0 :         while( aCurr != aEnd2 )
     311                 :            :         {
     312         [ #  # ]:          0 :             const ::basegfx::B2DRange& rUpdateArea( (*aCurr)->getUpdateArea() );
     313                 :            :             rUpdateAreas.addRange(
     314                 :            :                 ::basegfx::unotools::b2DSurroundingIntegerRangeFromB2DRange( rUpdateArea ),
     315                 :          0 :                 SpriteInfo(*aCurr,
     316                 :            :                            rUpdateArea,
     317 [ #  # ][ #  # ]:          0 :                            false) );
         [ #  # ][ #  # ]
     318                 :          0 :             ++aCurr;
     319                 :          0 :         }
     320                 :          0 :     }
     321                 :            : 
     322                 :            : #if OSL_DEBUG_LEVEL > 0
     323                 :            :     bool impIsEqualB2DRange(const basegfx::B2DRange& rRangeA, const basegfx::B2DRange& rRangeB, double fSmallValue)
     324                 :            :     {
     325                 :            :         return fabs(rRangeB.getMinX() - rRangeA.getMinX()) <= fSmallValue
     326                 :            :             && fabs(rRangeB.getMinY() - rRangeA.getMinY()) <= fSmallValue
     327                 :            :             && fabs(rRangeB.getMaxX() - rRangeA.getMaxX()) <= fSmallValue
     328                 :            :             && fabs(rRangeB.getMaxY() - rRangeA.getMaxY()) <= fSmallValue;
     329                 :            :     }
     330                 :            : 
     331                 :            :     bool impIsEqualB2DVector(const basegfx::B2DVector& rVecA, const basegfx::B2DVector& rVecB, double fSmallValue)
     332                 :            :     {
     333                 :            :         return fabs(rVecB.getX() - rVecA.getX()) <= fSmallValue
     334                 :            :             && fabs(rVecB.getY() - rVecA.getY()) <= fSmallValue;
     335                 :            :     }
     336                 :            : #endif
     337                 :            : 
     338                 :          0 :     bool SpriteRedrawManager::isAreaUpdateScroll( ::basegfx::B2DRectangle&  o_rMoveStart,
     339                 :            :                                                   ::basegfx::B2DRectangle&  o_rMoveEnd,
     340                 :            :                                                   const UpdateArea&         rUpdateArea,
     341                 :            :                                                   ::std::size_t             nNumSprites ) const
     342                 :            :     {
     343                 :            :         // check for a solitary move, which consists of exactly two
     344                 :            :         // pure-move entries, the first with valid, the second with
     345                 :            :         // invalid sprite (see SpriteTracer::commit()).  Note that we
     346                 :            :         // cannot simply store some flag in SpriteTracer::commit()
     347                 :            :         // above and just check that here, since during the connected
     348                 :            :         // range calculations, other sprites might get merged into the
     349                 :            :         // same region (thus spoiling the scrolling move
     350                 :            :         // optimization).
     351         [ #  # ]:          0 :         if( nNumSprites != 2 )
     352                 :          0 :             return false;
     353                 :            : 
     354                 :            :         const SpriteConnectedRanges::ComponentListType::const_iterator aFirst(
     355                 :          0 :             rUpdateArea.maComponentList.begin() );
     356                 :            :         SpriteConnectedRanges::ComponentListType::const_iterator aSecond(
     357                 :          0 :             aFirst ); ++aSecond;
     358                 :            : 
     359   [ #  #  #  # ]:          0 :         if( !aFirst->second.isPureMove() ||
         [ #  # ][ #  #  
             #  #  #  # ]
     360                 :          0 :             !aSecond->second.isPureMove() ||
     361                 :          0 :             !aFirst->second.getSprite().is() ||
     362                 :            :             // use _true_ update area, not the rounded version
     363 [ #  # ][ #  # ]:          0 :             !aFirst->second.getSprite()->isAreaUpdateOpaque( aFirst->second.getUpdateArea() ) ||
                 [ #  # ]
     364                 :          0 :             aSecond->second.getSprite().is() )
     365                 :            :         {
     366                 :            :             // either no move update, or incorrect sprite, or sprite
     367                 :            :             // content not fully opaque over update region.
     368                 :          0 :             return false;
     369                 :            :         }
     370                 :            : 
     371                 :          0 :         o_rMoveStart      = aSecond->second.getUpdateArea();
     372                 :          0 :         o_rMoveEnd        = aFirst->second.getUpdateArea();
     373                 :            : 
     374                 :            : #if OSL_DEBUG_LEVEL > 0
     375                 :            :         ::basegfx::B2DRectangle aTotalBounds( o_rMoveStart );
     376                 :            :         aTotalBounds.expand( o_rMoveEnd );
     377                 :            : 
     378                 :            :         OSL_POSTCOND(impIsEqualB2DRange(rUpdateArea.maTotalBounds, basegfx::unotools::b2DSurroundingIntegerRangeFromB2DRange(aTotalBounds), 0.5),
     379                 :            :             "SpriteRedrawManager::isAreaUpdateScroll(): sprite area and total area mismatch");
     380                 :            :         OSL_POSTCOND(impIsEqualB2DVector(o_rMoveStart.getRange(), o_rMoveEnd.getRange(), 0.5),
     381                 :            :             "SpriteRedrawManager::isAreaUpdateScroll(): scroll start and end area have mismatching size");
     382                 :            : #endif
     383                 :            : 
     384                 :          0 :         return true;
     385                 :            :     }
     386                 :            : 
     387                 :          0 :     bool SpriteRedrawManager::isAreaUpdateNotOpaque( const ::basegfx::B2DRectangle& rUpdateRect,
     388                 :            :                                                      const AreaComponent&           rComponent ) const
     389                 :            :     {
     390                 :          0 :         const Sprite::Reference& pAffectedSprite( rComponent.second.getSprite() );
     391                 :            : 
     392         [ #  # ]:          0 :         if( !pAffectedSprite.is() )
     393                 :          0 :             return true; // no sprite, no opaque update!
     394                 :            : 
     395                 :          0 :         return !pAffectedSprite->isAreaUpdateOpaque( rUpdateRect );
     396                 :            :     }
     397                 :            : 
     398                 :          0 :     bool SpriteRedrawManager::isAreaUpdateOpaque( const UpdateArea& rUpdateArea,
     399                 :            :                                                   ::std::size_t     nNumSprites ) const
     400                 :            :     {
     401                 :            :         // check whether the sprites in the update area's list will
     402                 :            :         // fully cover the given area _and_ do that in an opaque way
     403                 :            :         // (i.e. no alpha, no non-rectangular sprite content).
     404                 :            : 
     405                 :            :         // TODO(P1): Come up with a smarter early-exit criterion here
     406                 :            :         // (though, I think, the case that _lots_ of sprites _fully_
     407                 :            :         // cover a rectangular area _without_ any holes is extremely
     408                 :            :         // improbable)
     409                 :            : 
     410                 :            :         // avoid checking large number of sprites (and probably fail,
     411                 :            :         // anyway). Note: the case nNumSprites < 1 should normally not
     412                 :            :         // happen, as handleArea() calls backgroundPaint() then.
     413 [ #  # ][ #  # ]:          0 :         if( nNumSprites > 3 || nNumSprites < 1 )
     414                 :          0 :             return false;
     415                 :            : 
     416                 :            :         // now, calc the _true_ update area, by merging all sprite's
     417                 :            :         // true update areas into one rectangle
     418                 :          0 :         ::basegfx::B2DRange aTrueArea( rUpdateArea.maComponentList.begin()->second.getUpdateArea() );
     419                 :            :         ::std::for_each( rUpdateArea.maComponentList.begin(),
     420                 :            :                          rUpdateArea.maComponentList.end(),
     421                 :            :                          ::boost::bind( (void (basegfx::B2DRange::*)(const basegfx::B2DRange&))(
     422                 :            :                                             &basegfx::B2DRange::expand),
     423                 :            :                                         aTrueArea,
     424                 :            :                                         ::boost::bind( &SpriteInfo::getUpdateArea,
     425                 :            :                                                        ::boost::bind( ::o3tl::select2nd<AreaComponent>(),
     426 [ #  # ][ #  # ]:          0 :                                                                       _1 ) ) ) );
         [ #  # ][ #  # ]
     427                 :            : 
     428                 :            :         const SpriteConnectedRanges::ComponentListType::const_iterator aEnd(
     429                 :          0 :             rUpdateArea.maComponentList.end() );
     430                 :            : 
     431                 :            :         // and check whether _any_ of the sprites tells that its area
     432                 :            :         // update will not be opaque.
     433                 :            :         return (::std::find_if( rUpdateArea.maComponentList.begin(),
     434                 :            :                                 aEnd,
     435                 :            :                                 ::boost::bind( &SpriteRedrawManager::isAreaUpdateNotOpaque,
     436                 :            :                                                this,
     437                 :            :                                                ::boost::cref(aTrueArea),
     438 [ #  # ][ #  # ]:          0 :                                                _1 ) ) == aEnd );
                 [ #  # ]
     439                 :            :     }
     440                 :            : 
     441                 :          0 :     bool SpriteRedrawManager::areSpritesChanged( const UpdateArea& rUpdateArea ) const
     442                 :            :     {
     443                 :            :         // check whether SpriteInfo::needsUpdate returns false for
     444                 :            :         // all elements of this area's contained sprites
     445                 :            :         //
     446                 :            :         // if not a single changed sprite found - just ignore this
     447                 :            :         // component (return false)
     448                 :            :         const SpriteConnectedRanges::ComponentListType::const_iterator aEnd(
     449                 :          0 :             rUpdateArea.maComponentList.end() );
     450                 :            :         return (::std::find_if( rUpdateArea.maComponentList.begin(),
     451                 :            :                                 aEnd,
     452                 :            :                                 ::boost::bind( &SpriteInfo::needsUpdate,
     453                 :            :                                                ::boost::bind(
     454                 :            :                                                    ::o3tl::select2nd<SpriteConnectedRanges::ComponentType>(),
     455 [ #  # ][ #  # ]:          0 :                                                    _1 ) ) ) != aEnd );
                 [ #  # ]
     456                 :            :     }
     457                 :            : 
     458                 :          0 :     SpriteRedrawManager::SpriteRedrawManager() :
     459                 :            :         maSprites(),
     460 [ #  # ][ #  # ]:          0 :         maChangeRecords()
     461                 :            :     {
     462                 :          0 :     }
     463                 :            : 
     464                 :          0 :     void SpriteRedrawManager::disposing()
     465                 :            :     {
     466                 :            :         // drop all references
     467                 :          0 :         maChangeRecords.clear();
     468                 :            : 
     469                 :            :         // dispose all sprites - the spritecanvas, and by delegation,
     470                 :            :         // this object, is the owner of the sprites. After all, a
     471                 :            :         // sprite without a canvas to render into makes not terribly
     472                 :            :         // much sense.
     473                 :            : 
     474                 :            :         // TODO(Q3): Once boost 1.33 is in, change back to for_each
     475                 :            :         // with ::boost::mem_fn. For the time being, explicit loop due
     476                 :            :         // to cdecl declaration of all UNO methods.
     477                 :          0 :         ListOfSprites::reverse_iterator aCurr( maSprites.rbegin() );
     478                 :          0 :         ListOfSprites::reverse_iterator aEnd( maSprites.rend() );
     479 [ #  # ][ #  # ]:          0 :         while( aCurr != aEnd )
     480 [ #  # ][ #  # ]:          0 :             (*aCurr++)->dispose();
                 [ #  # ]
     481                 :            : 
     482                 :          0 :         maSprites.clear();
     483                 :          0 :     }
     484                 :            : 
     485                 :          0 :     void SpriteRedrawManager::clearChangeRecords()
     486                 :            :     {
     487                 :          0 :         maChangeRecords.clear();
     488                 :          0 :     }
     489                 :            : 
     490                 :          0 :     void SpriteRedrawManager::showSprite( const Sprite::Reference& rSprite )
     491                 :            :     {
     492                 :          0 :         maSprites.push_back( rSprite );
     493                 :          0 :     }
     494                 :            : 
     495                 :          0 :     void SpriteRedrawManager::hideSprite( const Sprite::Reference& rSprite )
     496                 :            :     {
     497                 :          0 :         maSprites.remove( rSprite );
     498                 :          0 :     }
     499                 :            : 
     500                 :          0 :     void SpriteRedrawManager::moveSprite( const Sprite::Reference&      rSprite,
     501                 :            :                                           const ::basegfx::B2DPoint&    rOldPos,
     502                 :            :                                           const ::basegfx::B2DPoint&    rNewPos,
     503                 :            :                                           const ::basegfx::B2DVector&   rSpriteSize )
     504                 :            :     {
     505                 :            :         maChangeRecords.push_back( SpriteChangeRecord( rSprite,
     506                 :            :                                                        rOldPos,
     507                 :            :                                                        rNewPos,
     508         [ #  # ]:          0 :                                                        rSpriteSize ) );
     509                 :          0 :     }
     510                 :            : 
     511                 :          0 :     void SpriteRedrawManager::updateSprite( const Sprite::Reference&    rSprite,
     512                 :            :                                             const ::basegfx::B2DPoint&  rPos,
     513                 :            :                                             const ::basegfx::B2DRange&  rUpdateArea )
     514                 :            :     {
     515                 :            :         maChangeRecords.push_back( SpriteChangeRecord( rSprite,
     516                 :            :                                                        rPos,
     517         [ #  # ]:          0 :                                                        rUpdateArea ) );
     518                 :          0 :     }
     519                 :            : 
     520 [ +  - ][ +  - ]:        735 : }
     521                 :            : 
     522                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10