LCOV - code coverage report
Current view: top level - eq/fabric - subPixel.h (source / functions) Hit Total Coverage
Test: lcov2.info Lines: 20 28 71.4 %
Date: 2014-06-18 Functions: 8 9 88.9 %

          Line data    Source code
       1             : 
       2             : /* Copyright (c) 2009-2014, Stefan Eilemann <eile@equalizergraphics.com>
       3             :  *                    2009, Sarah Amsellem <sarah.amsellem@gmail.com>
       4             :  *
       5             :  * This library is free software; you can redistribute it and/or modify it under
       6             :  * the terms of the GNU Lesser General Public License version 2.1 as published
       7             :  * by the Free Software Foundation.
       8             :  *
       9             :  * This library is distributed in the hope that it will be useful, but WITHOUT
      10             :  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
      11             :  * FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
      12             :  * details.
      13             :  *
      14             :  * You should have received a copy of the GNU Lesser General Public License
      15             :  * along with this library; if not, write to the Free Software Foundation, Inc.,
      16             :  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
      17             :  */
      18             : 
      19             : #ifndef EQFABRIC_SUBPIXEL_H
      20             : #define EQFABRIC_SUBPIXEL_H
      21             : 
      22             : #include <eq/fabric/api.h>
      23             : #include <eq/fabric/types.h>
      24             : #include <lunchbox/bitOperation.h>
      25             : #include <lunchbox/log.h>
      26             : #include <lunchbox/types.h>
      27             : 
      28             : namespace eq
      29             : {
      30             : namespace fabric
      31             : {
      32             :     std::ostream& operator << ( std::ostream& os, const SubPixel& subPixel );
      33             : 
      34             :     /**
      35             :      * Holds a subpixel decomposition specification along with some methods for
      36             :      * manipulation.
      37             :      *
      38             :      * The index represents the contributor ID within the subpixel
      39             :      * decomposition.  The size determines how many contributors are performing
      40             :      * anti-aliasing or any other subpixel decomposition.
      41             :      */
      42             :     class SubPixel
      43             :     {
      44             :     public:
      45             :         /** @name Constructors */
      46             :         //@{
      47             :         /** Construct an empty subpixel specification. @version 1.0 */
      48       11579 :         SubPixel() : index( 0 ), size( 1 )  {}
      49             : 
      50             :         /**
      51             :          * Construct a subpixel specification with default values.
      52             :          * @version 1.0
      53             :          */
      54          33 :         SubPixel( const uint32_t index_, const uint32_t size_ )
      55          33 :                 : index( index_ ), size( size_ ) {}
      56             :         //@}
      57             : 
      58             :         /** Apply (accumulate) another subpixel specification. @internal */
      59        1164 :         void apply( const SubPixel& rhs )
      60             :         {
      61        1164 :             if( !isValid() || !rhs.isValid( ))
      62        1164 :                 return;
      63             : 
      64        1164 :             index = index * rhs.size + rhs.index;
      65        1164 :             size  *= rhs.size;
      66             :         }
      67             : 
      68             :         /**
      69             :          * @return true if the two subpixel specifications are identical.
      70             :          * @version 1.0
      71             :          */
      72          25 :         bool operator == ( const SubPixel& rhs ) const
      73             :         {
      74          25 :             return index==rhs.index && size==rhs.size;
      75             :         }
      76             : 
      77             :         /**
      78             :          * @return true if the two subpixel specifications are not identical.
      79             :          * @version 1.0
      80             :          */
      81        1876 :         bool operator != ( const SubPixel& rhs ) const
      82             :         {
      83        1876 :             return index != rhs.index || size != rhs.size;
      84             :         }
      85             : 
      86             :         /** Make the subpixel specification invalid. @internal */
      87             :         void invalidate() { index = size = 0; }
      88             : 
      89             :         /** Make the subpixel specification valid. @internal */
      90        1363 :         void validate()
      91             :         {
      92        2726 :             if( isValid( )) return;
      93           0 :             LBWARN << "Invalid " << *this << std::endl;
      94           0 :             if( index >= size ) index = 0;
      95           0 :             if( size == 0 )     size = 1;
      96           0 :             LBWARN << "Corrected " << *this << std::endl;
      97             :         }
      98             : 
      99             :         /** @return true if the pixel specification is valid. @internal */
     100        5578 :         bool isValid() const { return ( index < size ); }
     101             : 
     102             :         uint32_t index; //!< The contributor id
     103             :         uint32_t size;  //!< Total number of contributors
     104             : 
     105             :         EQFABRIC_API static const SubPixel ALL;
     106             :     };
     107             : 
     108          11 :     inline std::ostream& operator << ( std::ostream& os,
     109             :                                        const SubPixel& subPixel )
     110             :     {
     111          11 :         if( subPixel.isValid( ))
     112          11 :             os << "subpixel  [ " << subPixel.index << ' ' << subPixel.size
     113          11 :                << " ]";
     114          11 :         return os;
     115             :     }
     116             : }
     117             : }
     118             : 
     119             : namespace lunchbox
     120             : {
     121           0 : template<> inline void byteswap( eq::fabric::SubPixel& value )
     122             : {
     123           0 :     byteswap( value.index );
     124           0 :     byteswap( value.size );
     125           0 : }
     126             : }
     127             : #endif // EQFABRIC_SUBPIXEL_H

Generated by: LCOV version 1.10