LCOV - code coverage report
Current view: top level - lunchbox/compressor - compressor.cpp (source / functions) Hit Total Coverage
Test: lcov2.info Lines: 64 93 68.8 %
Date: 2014-08-05 Functions: 17 24 70.8 %

          Line data    Source code
       1             : 
       2             : /* Copyright (c) 2009-2010, Cedric Stalder <cedric.stalder@gmail.com>
       3             :  *               2009-2014, Stefan Eilemann <eile@equalizergraphics.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             : #include "compressor.h"
      20             : 
      21             : namespace lunchbox
      22             : {
      23             : namespace plugin
      24             : {
      25             : namespace
      26             : {
      27             : typedef std::vector< Compressor::Functions > Compressors;
      28             : static Compressors* _functions;
      29             : 
      30         608 : const Compressor::Functions& _findFunctions( const unsigned name )
      31             : {
      32        8208 :     BOOST_FOREACH( const Compressor::Functions& functions, *_functions )
      33        8208 :         if( functions.name == name )
      34         608 :             return functions;
      35             : 
      36           0 :     assert( 0 ); // UNREACHABLE
      37             :     return _functions->front();
      38             : }
      39             : }
      40             : 
      41         152 : Compressor::Compressor()
      42         152 :     : _nResults( 0 )
      43         152 : {}
      44             : 
      45         304 : Compressor::~Compressor()
      46             : {
      47         718 :     for ( size_t i = 0; i < _results.size(); i++ )
      48         566 :         delete ( _results[i] );
      49             : 
      50         152 :     _results.clear();
      51         152 : }
      52             : 
      53        1131 : Compressor::Functions::Functions( const unsigned name_,
      54             :                                   GetInfo_t getInfo_,
      55             :                                   NewCompressor_t newCompressor_,
      56             :                                   NewCompressor_t newDecompressor_,
      57             :                                   Decompress_t decompress_,
      58             :                                   IsCompatible_t isCompatible_ )
      59             :         : name( name_ )
      60             :         , getInfo( getInfo_ )
      61             :         , newCompressor( newCompressor_ )
      62             :         , newDecompressor( newDecompressor_ )
      63             :         , decompress( decompress_ )
      64        1131 :         , isCompatible( isCompatible_ )
      65        1131 : {}
      66             : 
      67        1131 : void Compressor::registerEngine( const Compressor::Functions& functions )
      68             : {
      69        1131 :     if( !_functions ) // resolve 'static initialization order fiasco'
      70          29 :         _functions = new Compressors;
      71        1131 :     _functions->push_back( functions );
      72        1131 : }
      73             : 
      74         304 : void Compressor::compress( const void* const inData, const eq_uint64_t* inDims,
      75             :                            const eq_uint64_t flags )
      76             : {
      77         304 :     const bool useAlpha = !(flags & EQ_COMPRESSOR_IGNORE_ALPHA);
      78         304 :     const eq_uint64_t nPixels = (flags & EQ_COMPRESSOR_DATA_1D) ?
      79         304 :                                   inDims[1]: inDims[1] * inDims[3];
      80             : 
      81         304 :     compress( inData, nPixels, useAlpha );
      82         304 : }
      83             : 
      84             : }
      85             : }
      86             : 
      87           1 : size_t EqCompressorGetNumCompressors()
      88             : {
      89           1 :     if( !lunchbox::plugin::_functions )
      90           0 :         lunchbox::plugin::_functions = new lunchbox::plugin::Compressors;
      91           1 :     return lunchbox::plugin::_functions->size();
      92             : }
      93             : 
      94          39 : void EqCompressorGetInfo( const size_t n, EqCompressorInfo* const info )
      95             : {
      96          39 :     assert( lunchbox::plugin::_functions->size() > n );
      97          39 :     (*lunchbox::plugin::_functions)[ n ].getInfo( info );
      98          39 : }
      99             : 
     100         152 : void* EqCompressorNewCompressor( const unsigned name )
     101             : {
     102             :     const lunchbox::plugin::Compressor::Functions& functions =
     103         152 :         lunchbox::plugin::_findFunctions( name );
     104             : 
     105         152 :     return functions.newCompressor( name );
     106             : }
     107             : 
     108         152 : void EqCompressorDeleteCompressor( void* const compressor )
     109             : {
     110         152 :     delete reinterpret_cast< lunchbox::plugin::Compressor* >( compressor );
     111         152 : }
     112             : 
     113         152 : void* EqCompressorNewDecompressor( const unsigned name )
     114             : {
     115             :     const lunchbox::plugin::Compressor::Functions& functions =
     116         152 :         lunchbox::plugin::_findFunctions( name );
     117             : 
     118         152 :     return functions.newDecompressor( name );
     119             : }
     120             : 
     121           0 : void EqCompressorDeleteDecompressor( void* const decompressor )
     122             : {
     123           0 :     delete reinterpret_cast< lunchbox::plugin::Compressor* >( decompressor );
     124           0 : }
     125             : 
     126         304 : void EqCompressorCompress( void* const ptr, const unsigned, void* const in,
     127             :                            const eq_uint64_t* inDims, const eq_uint64_t flags )
     128             : {
     129         304 :     assert( ptr );
     130             :     reinterpret_cast< lunchbox::plugin::Compressor* >( ptr )->
     131         304 :         compress( in, inDims, flags );
     132         304 : }
     133             : 
     134         152 : unsigned EqCompressorGetNumResults( void* const ptr, const unsigned )
     135             : {
     136         152 :     assert( ptr );
     137             :     lunchbox::plugin::Compressor* compressor =
     138         152 :         reinterpret_cast< lunchbox::plugin::Compressor* >( ptr );
     139         152 :     return compressor->getNResults();
     140             : }
     141             : 
     142         566 : void EqCompressorGetResult( void* const ptr, const unsigned, const unsigned i,
     143             :                             void** const out, eq_uint64_t* const outSize )
     144             : {
     145         566 :     assert( ptr );
     146             :     lunchbox::plugin::Compressor* compressor =
     147         566 :         reinterpret_cast< lunchbox::plugin::Compressor* >( ptr );
     148         566 :     lunchbox::plugin::Compressor::Result* result = compressor->getResults()[ i ];
     149             : 
     150         566 :     *out = result->getData();
     151         566 :     *outSize = result->getSize();
     152         566 :     assert( result->getMaxSize() >= result->getSize( ));
     153         566 :     assert( *outSize != 0 );
     154         566 : }
     155             : 
     156             : 
     157         304 : void EqCompressorDecompress( void* const decompressor, const unsigned name,
     158             :                              const void* const* in,
     159             :                              const eq_uint64_t* const inSizes,
     160             :                              const unsigned nInputs,
     161             :                              void* const out, eq_uint64_t* const outDims,
     162             :                              const eq_uint64_t flags )
     163             : {
     164             :     const lunchbox::plugin::Compressor::Functions& functions =
     165         304 :         lunchbox::plugin::_findFunctions( name );
     166             :     functions.decompress( in, inSizes, nInputs, out, outDims, flags,
     167         304 :                           decompressor );
     168         304 : }
     169             : 
     170           0 : bool EqCompressorIsCompatible( const unsigned     name,
     171             :                                const GLEWContext* glewContext )
     172             : {
     173             :     const lunchbox::plugin::Compressor::Functions& functions =
     174           0 :         lunchbox::plugin::_findFunctions( name );
     175             : 
     176           0 :     if ( functions.isCompatible == 0 )
     177             :     {
     178           0 :         assert( false );
     179             :         return false;
     180             :     }
     181             : 
     182           0 :     return functions.isCompatible( glewContext );
     183             : }
     184             : 
     185           0 : void EqCompressorDownload( void* const ptr, const unsigned,
     186             :                            const GLEWContext* glewContext,
     187             :                            const eq_uint64_t inDims[4], const unsigned source,
     188             :                            const eq_uint64_t flags, eq_uint64_t outDims[4],
     189             :                            void** out )
     190             : {
     191           0 :     assert( ptr );
     192             :     lunchbox::plugin::Compressor* compressor =
     193           0 :         reinterpret_cast< lunchbox::plugin::Compressor* >( ptr );
     194           0 :     compressor->download( glewContext, inDims, source, flags, outDims, out );
     195           0 : }
     196             : 
     197             : 
     198           0 : void EqCompressorUpload( void* const ptr, const unsigned,
     199             :                          const GLEWContext* glewContext, const void* buffer,
     200             :                          const eq_uint64_t inDims[4], const eq_uint64_t flags,
     201             :                          const eq_uint64_t outDims[4],
     202             :                          const unsigned destination )
     203             : {
     204           0 :     assert( ptr );
     205             :     lunchbox::plugin::Compressor* compressor =
     206           0 :         reinterpret_cast< lunchbox::plugin::Compressor* >( ptr );
     207             :     compressor->upload( glewContext, buffer, inDims, flags, outDims,
     208           0 :                         destination );
     209           0 : }
     210             : 
     211             : 
     212           0 : void EqCompressorStartDownload( void* const ptr, const unsigned /*name*/,
     213             :                                 const GLEWContext* glewContext,
     214             :                                 const eq_uint64_t inDims[4],
     215             :                                 const unsigned source, const eq_uint64_t flags )
     216             : {
     217           0 :     assert( ptr );
     218             :     lunchbox::plugin::Compressor* compressor =
     219           0 :         reinterpret_cast< lunchbox::plugin::Compressor* >( ptr );
     220           0 :     compressor->startDownload( glewContext, inDims, source, flags );
     221           0 : }
     222             : 
     223           0 : void EqCompressorFinishDownload( void* const ptr, const unsigned /*name*/,
     224             :                                  const GLEWContext* glewContext,
     225             :                                  const eq_uint64_t inDims[4],
     226             :                                  const unsigned source, const eq_uint64_t flags,
     227             :                                  eq_uint64_t outDims[4], void** out )
     228             : {
     229           0 :     assert( ptr );
     230             :     lunchbox::plugin::Compressor* compressor =
     231           0 :         reinterpret_cast< lunchbox::plugin::Compressor* >( ptr );
     232             :     compressor->finishDownload( glewContext, inDims, source, flags, outDims,
     233           0 :                                out );
     234          87 : }

Generated by: LCOV version 1.10