@@ -540,9 +540,11 @@ void FontRenderer::flushAllAndInvalidate() {
540540 issueDrawCommand ();
541541 mCurrentQuadIndex = 0 ;
542542 }
543+
543544 for (uint32_t i = 0 ; i < mActiveFonts .size (); i++) {
544545 mActiveFonts [i]->invalidateTextureCache ();
545546 }
547+
546548 for (uint32_t i = 0 ; i < mCacheLines .size (); i++) {
547549 mCacheLines [i]->mCurrentCol = 0 ;
548550 }
@@ -551,7 +553,7 @@ void FontRenderer::flushAllAndInvalidate() {
551553void FontRenderer::deallocateTextureMemory (CacheTexture *cacheTexture) {
552554 if (cacheTexture && cacheTexture->mTexture ) {
553555 glDeleteTextures (1 , &cacheTexture->mTextureId );
554- delete cacheTexture->mTexture ;
556+ delete[] cacheTexture->mTexture ;
555557 cacheTexture->mTexture = NULL ;
556558 }
557559}
@@ -582,11 +584,13 @@ void FontRenderer::flushLargeCaches() {
582584 deallocateTextureMemory (mCacheTexture512 );
583585}
584586
585- void FontRenderer::allocateTextureMemory (CacheTexture * cacheTexture) {
587+ void FontRenderer::allocateTextureMemory (CacheTexture* cacheTexture) {
586588 int width = cacheTexture->mWidth ;
587589 int height = cacheTexture->mHeight ;
590+
588591 cacheTexture->mTexture = new uint8_t [width * height];
589592 memset (cacheTexture->mTexture , 0 , width * height * sizeof (uint8_t ));
593+
590594 glBindTexture (GL_TEXTURE_2D, cacheTexture->mTextureId );
591595 glPixelStorei (GL_UNPACK_ALIGNMENT, 1 );
592596 // Initialize texture dimensions
@@ -654,11 +658,12 @@ void FontRenderer::cacheBitmap(const SkGlyph& glyph, CachedGlyphInfo* cachedGlyp
654658
655659 uint32_t cacheWidth = cacheLine->mMaxWidth ;
656660
657- CacheTexture * cacheTexture = cacheLine->mCacheTexture ;
658- if (cacheTexture->mTexture == NULL ) {
661+ CacheTexture* cacheTexture = cacheLine->mCacheTexture ;
662+ if (! cacheTexture->mTexture ) {
659663 // Large-glyph texture memory is allocated only as needed
660664 allocateTextureMemory (cacheTexture);
661665 }
666+
662667 uint8_t * cacheBuffer = cacheTexture->mTexture ;
663668 uint8_t * bitmapBuffer = (uint8_t *) glyph.fImage ;
664669 unsigned int stride = glyph.rowBytes ();
@@ -677,32 +682,40 @@ void FontRenderer::cacheBitmap(const SkGlyph& glyph, CachedGlyphInfo* cachedGlyp
677682CacheTexture* FontRenderer::createCacheTexture (int width, int height, bool allocate) {
678683 GLuint textureId;
679684 glGenTextures (1 , &textureId);
680- uint8_t * textureMemory = NULL ;
681685
686+ uint8_t * textureMemory = NULL ;
682687 CacheTexture* cacheTexture = new CacheTexture (textureMemory, textureId, width, height);
688+
683689 if (allocate) {
684690 allocateTextureMemory (cacheTexture);
685691 }
692+
686693 return cacheTexture;
687694}
688695
689696void FontRenderer::initTextTexture () {
697+ for (uint32_t i = 0 ; i < mCacheLines .size (); i++) {
698+ delete mCacheLines [i];
699+ }
690700 mCacheLines .clear ();
691701
702+ if (mCacheTextureSmall ) {
703+ delete mCacheTextureSmall ;
704+ delete mCacheTexture128 ;
705+ delete mCacheTexture256 ;
706+ delete mCacheTexture512 ;
707+ }
708+
692709 // Next, use other, separate caches for large glyphs.
693710 uint16_t maxWidth = 0 ;
694711 if (Caches::hasInstance ()) {
695712 maxWidth = Caches::getInstance ().maxTextureSize ;
696713 }
714+
697715 if (maxWidth > MAX_TEXT_CACHE_WIDTH || maxWidth == 0 ) {
698716 maxWidth = MAX_TEXT_CACHE_WIDTH;
699717 }
700- if (mCacheTextureSmall != NULL ) {
701- delete mCacheTextureSmall ;
702- delete mCacheTexture128 ;
703- delete mCacheTexture256 ;
704- delete mCacheTexture512 ;
705- }
718+
706719 mCacheTextureSmall = createCacheTexture (mSmallCacheWidth , mSmallCacheHeight , true );
707720 mCacheTexture128 = createCacheTexture (maxWidth, 256 , false );
708721 mCacheTexture256 = createCacheTexture (maxWidth, 256 , false );
0 commit comments