diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2013-07-12 18:51:26 +0200 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2013-07-12 18:51:26 +0200 |
commit | dd547e4a8c1895aa89e699810323c933d9ac415b (patch) | |
tree | 4419e9d099ac6f9199d916aa1ba764e3c7c52cec /vcl/generic | |
parent | 333b7fb38153ae90bcbcc1348c8db698ba207331 (diff) |
Fix headless mode glyph cache memory handling
...the original code was riddled with errors. It leaked memory, which if it
didn't it would have deleted multiple times.
Change-Id: Ic70b425fac02ef894e35b3dc15039d217f8870f5
Diffstat (limited to 'vcl/generic')
-rw-r--r-- | vcl/generic/glyphs/gcach_ftyp.cxx | 21 | ||||
-rw-r--r-- | vcl/generic/glyphs/gcach_rbmp.cxx | 25 | ||||
-rw-r--r-- | vcl/generic/glyphs/glyphcache.cxx | 6 |
3 files changed, 22 insertions, 30 deletions
diff --git a/vcl/generic/glyphs/gcach_ftyp.cxx b/vcl/generic/glyphs/gcach_ftyp.cxx index 29c88203517f..979be11377c5 100644 --- a/vcl/generic/glyphs/gcach_ftyp.cxx +++ b/vcl/generic/glyphs/gcach_ftyp.cxx @@ -650,7 +650,6 @@ ImplFontEntry* ImplFTSFontData::CreateFontInstance( FontSelectPattern& rFSD ) co ServerFont::ServerFont( const FontSelectPattern& rFSD, FtFontInfo* pFI ) : maGlyphList( 0), maFontSelData(rFSD), - mnExtInfo(0), mnRefCount(1), mnBytesUsed( sizeof(ServerFont) ), mpPrevGCFont( NULL ), @@ -1420,20 +1419,19 @@ bool ServerFont::GetGlyphBitmap1( int nGlyphIndex, RawBitmap& rRawBitmap ) const if( rRawBitmap.mnAllocated < nNeededSize ) { - delete[] rRawBitmap.mpBits; rRawBitmap.mnAllocated = 2*nNeededSize; - rRawBitmap.mpBits = new unsigned char[ rRawBitmap.mnAllocated ]; + rRawBitmap.mpBits.reset(new unsigned char[ rRawBitmap.mnAllocated ]); } if( !mbArtBold || pFTEmbolden ) { - memcpy( rRawBitmap.mpBits, rBitmapFT.buffer, nNeededSize ); + memcpy( rRawBitmap.mpBits.get(), rBitmapFT.buffer, nNeededSize ); } else { - memset( rRawBitmap.mpBits, 0, nNeededSize ); + memset( rRawBitmap.mpBits.get(), 0, nNeededSize ); const unsigned char* pSrcLine = rBitmapFT.buffer; - unsigned char* pDstLine = rRawBitmap.mpBits; + unsigned char* pDstLine = rRawBitmap.mpBits.get(); for( int h = rRawBitmap.mnHeight; --h >= 0; ) { memcpy( pDstLine, pSrcLine, rBitmapFT.pitch ); @@ -1441,7 +1439,7 @@ bool ServerFont::GetGlyphBitmap1( int nGlyphIndex, RawBitmap& rRawBitmap ) const pSrcLine += rBitmapFT.pitch; } - unsigned char* p = rRawBitmap.mpBits; + unsigned char* p = rRawBitmap.mpBits.get(); for( sal_uLong y=0; y < rRawBitmap.mnHeight; y++ ) { unsigned char nLastByte = 0; @@ -1549,13 +1547,12 @@ bool ServerFont::GetGlyphBitmap8( int nGlyphIndex, RawBitmap& rRawBitmap ) const const sal_uLong nNeededSize = rRawBitmap.mnScanlineSize * rRawBitmap.mnHeight; if( rRawBitmap.mnAllocated < nNeededSize ) { - delete[] rRawBitmap.mpBits; rRawBitmap.mnAllocated = 2*nNeededSize; - rRawBitmap.mpBits = new unsigned char[ rRawBitmap.mnAllocated ]; + rRawBitmap.mpBits.reset(new unsigned char[ rRawBitmap.mnAllocated ]); } const unsigned char* pSrc = rBitmapFT.buffer; - unsigned char* pDest = rRawBitmap.mpBits; + unsigned char* pDest = rRawBitmap.mpBits.get(); if( !bEmbedded ) { for( int y = rRawBitmap.mnHeight, x; --y >= 0 ; ) @@ -1585,7 +1582,7 @@ bool ServerFont::GetGlyphBitmap8( int nGlyphIndex, RawBitmap& rRawBitmap ) const if( mbArtBold && !pFTEmbolden ) { // overlay with glyph image shifted by one left pixel - unsigned char* p = rRawBitmap.mpBits; + unsigned char* p = rRawBitmap.mpBits.get(); for( sal_uLong y=0; y < rRawBitmap.mnHeight; y++ ) { unsigned char nLastByte = 0; @@ -1601,7 +1598,7 @@ bool ServerFont::GetGlyphBitmap8( int nGlyphIndex, RawBitmap& rRawBitmap ) const if( !bEmbedded && mbUseGamma ) { - unsigned char* p = rRawBitmap.mpBits; + unsigned char* p = rRawBitmap.mpBits.get(); for( sal_uLong y=0; y < rRawBitmap.mnHeight; y++ ) { for( sal_uLong x=0; x < rRawBitmap.mnWidth; x++ ) diff --git a/vcl/generic/glyphs/gcach_rbmp.cxx b/vcl/generic/glyphs/gcach_rbmp.cxx index 684f8869328d..0efe54cef3e0 100644 --- a/vcl/generic/glyphs/gcach_rbmp.cxx +++ b/vcl/generic/glyphs/gcach_rbmp.cxx @@ -23,16 +23,12 @@ RawBitmap::RawBitmap() -: mpBits(0), mnAllocated(0) +: mnAllocated(0) {} RawBitmap::~RawBitmap() -{ - delete[] mpBits; - mpBits = 0; - mnAllocated = 0; -} +{} // used by 90 and 270 degree rotations on 8 bit deep bitmaps @@ -171,7 +167,7 @@ bool RawBitmap::Rotate( int nAngle ) mnYOffset = -(mnYOffset + mnHeight); if( mnBitCount == 8 ) { - ImplRotate8_180( mpBits, mnWidth, mnHeight, mnScanlineSize-mnWidth ); + ImplRotate8_180( mpBits.get(), mnWidth, mnHeight, mnScanlineSize-mnWidth ); return true; } nNewWidth = mnWidth; @@ -203,7 +199,7 @@ bool RawBitmap::Rotate( int nAngle ) { case 1800: // rotate by 180 degrees // we know we only need to deal with 1 bit depth - ImplRotate1_180( pBuf, mpBits + mnHeight * mnScanlineSize, + ImplRotate1_180( pBuf, mpBits.get() + mnHeight * mnScanlineSize, mnWidth, mnHeight, mnScanlineSize - (mnWidth + 7) / 8 ); break; case +900: // rotate left by 90 degrees @@ -211,11 +207,11 @@ bool RawBitmap::Rotate( int nAngle ) mnXOffset = mnYOffset; mnYOffset = -nNewHeight - i; if( mnBitCount == 8 ) - ImplRotate8_90( pBuf, mpBits + mnWidth - 1, + ImplRotate8_90( pBuf, mpBits.get() + mnWidth - 1, nNewWidth, nNewHeight, +mnScanlineSize, -1-mnHeight*mnScanlineSize, nNewScanlineSize - nNewWidth ); else - ImplRotate1_90( pBuf, mpBits + (mnWidth - 1) / 8, + ImplRotate1_90( pBuf, mpBits.get() + (mnWidth - 1) / 8, nNewWidth, nNewHeight, +mnScanlineSize, (-mnWidth & 7), +1, nNewScanlineSize - (nNewWidth + 7) / 8 ); break; @@ -225,11 +221,11 @@ bool RawBitmap::Rotate( int nAngle ) mnXOffset = -(nNewWidth + mnYOffset); mnYOffset = i; if( mnBitCount == 8 ) - ImplRotate8_90( pBuf, mpBits + mnScanlineSize * (mnHeight-1), + ImplRotate8_90( pBuf, mpBits.get() + mnScanlineSize * (mnHeight-1), nNewWidth, nNewHeight, -mnScanlineSize, +1+mnHeight*mnScanlineSize, nNewScanlineSize - nNewWidth ); else - ImplRotate1_90( pBuf, mpBits + mnScanlineSize * (mnHeight-1), + ImplRotate1_90( pBuf, mpBits.get() + mnScanlineSize * (mnHeight-1), nNewWidth, nNewHeight, -mnScanlineSize, +7, -1, nNewScanlineSize - (nNewWidth + 7) / 8 ); break; @@ -241,13 +237,12 @@ bool RawBitmap::Rotate( int nAngle ) if( nBufSize < mnAllocated ) { - memcpy( mpBits, pBuf, nBufSize ); + memcpy( mpBits.get(), pBuf, nBufSize ); delete[] pBuf; } else { - delete[] mpBits; - mpBits = pBuf; + mpBits.reset(pBuf); mnAllocated = nBufSize; } diff --git a/vcl/generic/glyphs/glyphcache.cxx b/vcl/generic/glyphs/glyphcache.cxx index a32b88fd82a0..43c628dd1688 100644 --- a/vcl/generic/glyphs/glyphcache.cxx +++ b/vcl/generic/glyphs/glyphcache.cxx @@ -315,9 +315,9 @@ void GlyphCache::GrowNotify() } -inline void GlyphCache::RemovingGlyph( ServerFont& rSF, GlyphData& rGD, int nGlyphIndex ) +inline void GlyphCache::RemovingGlyph( GlyphData& rGD ) { - mrPeer.RemovingGlyph( rSF, rGD, nGlyphIndex ); + mrPeer.RemovingGlyph( rGD ); mnBytesUsed -= sizeof( GlyphData ); --mnGlyphCount; } @@ -372,7 +372,7 @@ void ServerFont::GarbageCollect( long nMinLruIndex ) { OSL_ASSERT( mnBytesUsed >= sizeof(GlyphData) ); mnBytesUsed -= sizeof( GlyphData ); - GlyphCache::GetInstance().RemovingGlyph( *this, rGD, it->first ); + GlyphCache::GetInstance().RemovingGlyph( rGD ); maGlyphList.erase( it ); it_next = maGlyphList.begin(); } |