LCOV - code coverage report
Current view: top level - eq/compressor - compressor.cpp (source / functions) Hit Total Coverage
Test: Equalizer Lines: 57 95 60.0 %
Date: 2017-12-16 05:07:20 Functions: 16 23 69.6 %

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

Generated by: LCOV version 1.11