LCOV - code coverage report
Current view: top level - slideshow/source/engine/activities - discreteactivitybase.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 43 0.0 %
Date: 2012-08-25 Functions: 0 8 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*
       3                 :            :  * This file is part of the LibreOffice project.
       4                 :            :  *
       5                 :            :  * This Source Code Form is subject to the terms of the Mozilla Public
       6                 :            :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7                 :            :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8                 :            :  *
       9                 :            :  * This file incorporates work covered by the following license notice:
      10                 :            :  *
      11                 :            :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12                 :            :  *   contributor license agreements. See the NOTICE file distributed
      13                 :            :  *   with this work for additional information regarding copyright
      14                 :            :  *   ownership. The ASF licenses this file to you under the Apache
      15                 :            :  *   License, Version 2.0 (the "License"); you may not use this file
      16                 :            :  *   except in compliance with the License. You may obtain a copy of
      17                 :            :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18                 :            :  */
      19                 :            : 
      20                 :            : 
      21                 :            : // must be first
      22                 :            : #include <canvas/debug.hxx>
      23                 :            : #include <tools/diagnose_ex.h>
      24                 :            : #include <canvas/verbosetrace.hxx>
      25                 :            : 
      26                 :            : #include <discreteactivitybase.hxx>
      27                 :            : 
      28                 :            : 
      29                 :            : namespace slideshow
      30                 :            : {
      31                 :            :     namespace internal
      32                 :            :     {
      33                 :          0 :         DiscreteActivityBase::DiscreteActivityBase( const ActivityParameters& rParms ) :
      34                 :            :             ActivityBase( rParms ),
      35                 :            :             mpWakeupEvent( rParms.mpWakeupEvent ),
      36                 :            :             maDiscreteTimes( rParms.maDiscreteTimes ),
      37                 :            :             mnSimpleDuration( rParms.mnMinDuration ),
      38                 :          0 :             mnCurrPerformCalls( 0 )
      39                 :            :         {
      40                 :          0 :             ENSURE_OR_THROW( mpWakeupEvent,
      41                 :            :                               "DiscreteActivityBase::DiscreteActivityBase(): Invalid wakeup event" );
      42                 :            : 
      43                 :          0 :             ENSURE_OR_THROW( !maDiscreteTimes.empty(),
      44                 :            :                               "DiscreteActivityBase::DiscreteActivityBase(): time vector is empty, why do you create me?" );
      45                 :            : 
      46                 :            : #ifdef DBG_UTIL
      47                 :            :             // check parameters: rDiscreteTimes must be sorted in
      48                 :            :             // ascending order, and contain values only from the range
      49                 :            :             // [0,1]
      50                 :            :             for( ::std::size_t i=1, len=maDiscreteTimes.size(); i<len; ++i )
      51                 :            :             {
      52                 :            :                 if( maDiscreteTimes[i] < 0.0 ||
      53                 :            :                     maDiscreteTimes[i] > 1.0 ||
      54                 :            :                     maDiscreteTimes[i-1] < 0.0 ||
      55                 :            :                     maDiscreteTimes[i-1] > 1.0 )
      56                 :            :                 {
      57                 :            :                     ENSURE_OR_THROW( false, "DiscreteActivityBase::DiscreteActivityBase(): time values not within [0,1] range!" );
      58                 :            :                 }
      59                 :            : 
      60                 :            :                 if( maDiscreteTimes[i-1] > maDiscreteTimes[i] )
      61                 :            :                     ENSURE_OR_THROW( false, "DiscreteActivityBase::DiscreteActivityBase(): time vector is not sorted in ascending order!" );
      62                 :            :             }
      63                 :            : 
      64                 :            :             // TODO(E2): check this also in production code?
      65                 :            : #endif
      66                 :          0 :         }
      67                 :            : 
      68                 :          0 :         void DiscreteActivityBase::startAnimation()
      69                 :            :         {
      70                 :            :             // start timer on wakeup event
      71                 :          0 :             mpWakeupEvent->start();
      72                 :          0 :         }
      73                 :            : 
      74                 :          0 :         sal_uInt32 DiscreteActivityBase::calcFrameIndex( sal_uInt32     nCurrCalls,
      75                 :            :                                                          ::std::size_t  nVectorSize ) const
      76                 :            :         {
      77                 :          0 :             if( isAutoReverse() )
      78                 :            :             {
      79                 :            :                 // every full repeat run consists of one
      80                 :            :                 // forward and one backward traversal.
      81                 :          0 :                 sal_uInt32 nFrameIndex( nCurrCalls % (2*nVectorSize) );
      82                 :            : 
      83                 :            :                 // nFrameIndex values >= nVectorSize belong to
      84                 :            :                 // the backward traversal
      85                 :          0 :                 if( nFrameIndex >= nVectorSize )
      86                 :          0 :                     nFrameIndex = 2*nVectorSize - nFrameIndex; // invert sweep
      87                 :            : 
      88                 :          0 :                 return nFrameIndex;
      89                 :            :             }
      90                 :            :             else
      91                 :            :             {
      92                 :          0 :                 return nCurrCalls % nVectorSize ;
      93                 :            :             }
      94                 :            :         }
      95                 :            : 
      96                 :          0 :         sal_uInt32 DiscreteActivityBase::calcRepeatCount( sal_uInt32    nCurrCalls,
      97                 :            :                                                           ::std::size_t nVectorSize ) const
      98                 :            :         {
      99                 :          0 :             if( isAutoReverse() )
     100                 :          0 :                 return nCurrCalls / (2*nVectorSize); // we've got 2 cycles per repeat
     101                 :            :             else
     102                 :          0 :                 return nCurrCalls / nVectorSize;
     103                 :            :         }
     104                 :            : 
     105                 :          0 :         bool DiscreteActivityBase::perform()
     106                 :            :         {
     107                 :            :             // call base class, for start() calls and end handling
     108                 :          0 :             if( !ActivityBase::perform() )
     109                 :          0 :                 return false; // done, we're ended
     110                 :            : 
     111                 :          0 :             const ::std::size_t nVectorSize( maDiscreteTimes.size() );
     112                 :            : 
     113                 :            :             // actually perform something
     114                 :            :             // ==========================
     115                 :            : 
     116                 :            :             // TODO(Q3): Refactor this mess
     117                 :            : 
     118                 :            :             // call derived class with current frame index (modulo
     119                 :            :             // vector size, to cope with repeats)
     120                 :            :             perform( calcFrameIndex( mnCurrPerformCalls, nVectorSize ),
     121                 :          0 :                      calcRepeatCount( mnCurrPerformCalls, nVectorSize ) );
     122                 :            : 
     123                 :            :             // calc next index
     124                 :          0 :             ++mnCurrPerformCalls;
     125                 :            : 
     126                 :            :             // calc currently reached repeat count
     127                 :          0 :             double nCurrRepeat( double(mnCurrPerformCalls) / nVectorSize );
     128                 :            : 
     129                 :            :             // if auto-reverse is specified, halve the
     130                 :            :             // effective repeat count, since we pass every
     131                 :            :             // repeat run twice: once forward, once backward.
     132                 :          0 :             if( isAutoReverse() )
     133                 :          0 :                 nCurrRepeat /= 2.0;
     134                 :            : 
     135                 :            :             // schedule next frame, if either repeat is indefinite
     136                 :            :             // (repeat forever), or we've not yet reached the requested
     137                 :            :             // repeat count
     138                 :          0 :             if( !isRepeatCountValid() ||
     139                 :          0 :                 nCurrRepeat < getRepeatCount() )
     140                 :            :             {
     141                 :            :                 // add wake-up event to queue (modulo
     142                 :            :                 // vector size, to cope with repeats).
     143                 :            : 
     144                 :            :                 // repeat is handled locally, only apply acceleration/deceleration.
     145                 :            :                 // Scale time vector with simple duration, offset with full repeat
     146                 :            :                 // times.
     147                 :            :                 //
     148                 :            :                 // Somewhat condensed, the argument for setNextTimeout below could
     149                 :            :                 // be written as
     150                 :            :                 //
     151                 :            :                 // mnSimpleDuration*(nFullRepeats + calcAcceleratedTime( currentRepeatTime )),
     152                 :            :                 //
     153                 :            :                 // with currentRepeatTime = maDiscreteTimes[ currentRepeatIndex ]
     154                 :            :                 //
     155                 :            :                 // Note that calcAcceleratedTime() is only applied to the current repeat's value,
     156                 :            :                 // not to the total resulting time. This is in accordance with the SMIL spec.
     157                 :            :                 //
     158                 :            :                 mpWakeupEvent->setNextTimeout(
     159                 :            :                     mnSimpleDuration*(
     160                 :            :                         calcRepeatCount(
     161                 :            :                             mnCurrPerformCalls,
     162                 :          0 :                             nVectorSize ) +
     163                 :            :                         calcAcceleratedTime(
     164                 :            :                             maDiscreteTimes[
     165                 :            :                                 calcFrameIndex(
     166                 :            :                                     mnCurrPerformCalls,
     167                 :          0 :                                     nVectorSize ) ] ) ) );
     168                 :            : 
     169                 :          0 :                 getEventQueue().addEvent( mpWakeupEvent );
     170                 :            :             }
     171                 :            :             else
     172                 :            :             {
     173                 :            :                 // release event reference (relation to wakeup event
     174                 :            :                 // is circular!)
     175                 :          0 :                 mpWakeupEvent.reset();
     176                 :            : 
     177                 :            :                 // done with this activity
     178                 :          0 :                 endActivity();
     179                 :            :             }
     180                 :            : 
     181                 :          0 :             return false; // remove from queue, will be added back by the wakeup event.
     182                 :            :         }
     183                 :            : 
     184                 :          0 :         void DiscreteActivityBase::dispose()
     185                 :            :         {
     186                 :            :             // dispose event
     187                 :          0 :             if( mpWakeupEvent )
     188                 :          0 :                 mpWakeupEvent->dispose();
     189                 :            : 
     190                 :            :             // release references
     191                 :          0 :             mpWakeupEvent.reset();
     192                 :            : 
     193                 :          0 :             ActivityBase::dispose();
     194                 :          0 :         }
     195                 :            :     }
     196                 :          0 : }
     197                 :            : 
     198                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10