LCOV - code coverage report
Current view: top level - canvas/source/opengl - ogl_texturecache.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 0 46 0.0 %
Date: 2015-06-13 12:38:46 Functions: 0 5 0.0 %
Legend: Lines: hit not hit

          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             : 
      10             : #include "ogl_texturecache.hxx"
      11             : 
      12             : #include <com/sun/star/geometry/IntegerSize2D.hpp>
      13             : 
      14             : #include <GL/glew.h>
      15             : 
      16             : using namespace ::com::sun::star;
      17             : 
      18             : namespace oglcanvas
      19             : {
      20           0 :     TextureCache::TextureCache() :
      21             :         maCache(101),
      22             :         mnMissCount(0),
      23           0 :         mnHitCount(0)
      24           0 :     {}
      25             : 
      26           0 :     TextureCache::~TextureCache()
      27             :     {
      28           0 :         flush();
      29           0 :     }
      30             : 
      31           0 :     void TextureCache::flush()
      32             :     {
      33             :         // un-bind any texture
      34           0 :         glBindTexture(GL_TEXTURE_2D, 0);
      35             : 
      36             :         // delete all cached textures
      37           0 :         TextureCacheMapT::const_iterator aCurr=maCache.begin();
      38           0 :         const TextureCacheMapT::const_iterator aEnd=maCache.end();
      39           0 :         while( aCurr != aEnd )
      40             :         {
      41           0 :             glDeleteTextures(1, &aCurr->second.nTexture);
      42           0 :             ++aCurr;
      43             :         }
      44             : 
      45           0 :         maCache.clear();
      46           0 :         mnMissCount = 0;
      47           0 :         mnHitCount  = 0;
      48           0 :     }
      49             : 
      50           0 :     void TextureCache::prune()
      51             :     {
      52             :         // un-bind any texture
      53           0 :         glBindTexture(GL_TEXTURE_2D, 0);
      54             : 
      55             :         // delete already "old" textures, mark "new" entries "old"
      56           0 :         TextureCacheMapT::iterator aNext;
      57           0 :         TextureCacheMapT::iterator aCurr=maCache.begin();
      58           0 :         const TextureCacheMapT::iterator aEnd=maCache.end();
      59           0 :         while( aCurr != aEnd )
      60             :         {
      61           0 :             aNext=aCurr; ++aNext;
      62           0 :             if( aCurr->second.bOld )
      63             :             {
      64           0 :                 glDeleteTextures(1, &aCurr->second.nTexture);
      65           0 :                 maCache.erase(aCurr);
      66             :             }
      67             :             else
      68             :             {
      69           0 :                 aCurr->second.bOld = true;
      70             :             }
      71           0 :             aCurr=aNext;
      72             :         }
      73             : 
      74           0 :         mnMissCount = 0;
      75           0 :         mnHitCount  = 0;
      76           0 :     }
      77             : 
      78           0 :     unsigned int TextureCache::getTexture( const geometry::IntegerSize2D& rPixelSize,
      79             :                                            const sal_Int8*                pPixel,
      80             :                                            sal_uInt32                     nPixelCrc32) const
      81             :     {
      82           0 :         unsigned int nTexture(0);
      83             : 
      84             :         // texture already cached?
      85           0 :         TextureCacheMapT::iterator aCacheEntry;
      86           0 :         if( (aCacheEntry=maCache.find(nPixelCrc32)) == maCache.end() )
      87             :         {
      88             :             // nope, insert new entry
      89           0 :             glGenTextures(1, &nTexture);
      90           0 :             glBindTexture(GL_TEXTURE_2D, nTexture);
      91             : 
      92             :             // TODO(E3): handle limited texture sizes -
      93             :             // glGetIntegerv(GL_MAX_TEXTURE_SIZE)
      94             :             glTexImage2D(GL_TEXTURE_2D,
      95             :                          0,
      96             :                          4,
      97             :                          rPixelSize.Width,
      98             :                          rPixelSize.Height,
      99             :                          0,
     100             :                          GL_RGBA,
     101             :                          GL_UNSIGNED_INT_8_8_8_8_REV,
     102           0 :                          pPixel);
     103             : 
     104           0 :             maCache[nPixelCrc32].nTexture = nTexture;
     105           0 :             ++mnMissCount;
     106             : 
     107           0 :             return nTexture;
     108             :         }
     109             :         else
     110             :         {
     111           0 :             nTexture = aCacheEntry->second.nTexture;
     112           0 :             aCacheEntry->second.bOld = false;
     113           0 :             ++mnHitCount;
     114             :         }
     115             : 
     116           0 :         return nTexture;
     117             :     }
     118             : }
     119             : 
     120             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11