@@ -127,68 +127,34 @@ void FontRenderer::flushAllAndInvalidate() {
127127 mCacheTextures [i]->init ();
128128 }
129129
130- #if DEBUG_FONT_RENDERER
130+ #if DEBUG_FONT_RENDERER
131131 uint16_t totalGlyphs = 0 ;
132132 for (uint32_t i = 0 ; i < mCacheTextures .size (); i++) {
133- totalGlyphs += mCacheTextures [i]->mNumGlyphs ;
133+ totalGlyphs += mCacheTextures [i]->getGlyphCount () ;
134134 // Erase caches, just as a debugging facility
135- if (mCacheTextures [i]->mTexture ) {
136- memset (mCacheTextures [i]->mTexture , 0 ,
137- mCacheTextures [i]->mWidth * mCacheTextures [i]->mHeight );
135+ if (mCacheTextures [i]->getTexture () ) {
136+ memset (mCacheTextures [i]->getTexture () , 0 ,
137+ mCacheTextures [i]->getWidth () * mCacheTextures [i]->getHeight () );
138138 }
139139 }
140140 ALOGD (" Flushing caches: glyphs cached = %d" , totalGlyphs);
141141#endif
142142}
143143
144- void FontRenderer::deallocateTextureMemory (CacheTexture *cacheTexture) {
145- if (cacheTexture && cacheTexture->mTexture ) {
146- glDeleteTextures (1 , &cacheTexture->mTextureId );
147- delete[] cacheTexture->mTexture ;
148- cacheTexture->mTexture = NULL ;
149- cacheTexture->mTextureId = 0 ;
150- }
151- }
152-
153144void FontRenderer::flushLargeCaches () {
154145 // Start from 1; don't deallocate smallest/default texture
155146 for (uint32_t i = 1 ; i < mCacheTextures .size (); i++) {
156147 CacheTexture* cacheTexture = mCacheTextures [i];
157- if (cacheTexture->mTexture != NULL ) {
148+ if (cacheTexture->getTexture () ) {
158149 cacheTexture->init ();
159150 for (uint32_t j = 0 ; j < mActiveFonts .size (); j++) {
160151 mActiveFonts [j]->invalidateTextureCache (cacheTexture);
161152 }
162- deallocateTextureMemory ( cacheTexture);
153+ cacheTexture-> releaseTexture ( );
163154 }
164155 }
165156}
166157
167- void FontRenderer::allocateTextureMemory (CacheTexture* cacheTexture) {
168- int width = cacheTexture->mWidth ;
169- int height = cacheTexture->mHeight ;
170-
171- cacheTexture->mTexture = new uint8_t [width * height];
172-
173- if (!cacheTexture->mTextureId ) {
174- glGenTextures (1 , &cacheTexture->mTextureId );
175- }
176-
177- Caches::getInstance ().activeTexture (0 );
178- glBindTexture (GL_TEXTURE_2D, cacheTexture->mTextureId );
179- glPixelStorei (GL_UNPACK_ALIGNMENT, 1 );
180- // Initialize texture dimensions
181- glTexImage2D (GL_TEXTURE_2D, 0 , GL_ALPHA, width, height, 0 ,
182- GL_ALPHA, GL_UNSIGNED_BYTE, 0 );
183-
184- const GLenum filtering = cacheTexture->mLinearFiltering ? GL_LINEAR : GL_NEAREST;
185- glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filtering);
186- glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filtering);
187-
188- glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
189- glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
190- }
191-
192158CacheTexture* FontRenderer::cacheBitmapInTexture (const SkGlyph& glyph,
193159 uint32_t * startX, uint32_t * startY) {
194160 for (uint32_t i = 0 ; i < mCacheTextures .size (); i++) {
@@ -206,7 +172,7 @@ void FontRenderer::cacheBitmap(const SkGlyph& glyph, CachedGlyphInfo* cachedGlyp
206172 cachedGlyph->mIsValid = false ;
207173 // If the glyph is too tall, don't cache it
208174 if (glyph.fHeight + TEXTURE_BORDER_SIZE * 2 >
209- mCacheTextures [mCacheTextures .size () - 1 ]->mHeight ) {
175+ mCacheTextures [mCacheTextures .size () - 1 ]->getHeight () ) {
210176 ALOGE (" Font size too large to fit in cache. width, height = %i, %i" ,
211177 (int ) glyph.fWidth , (int ) glyph.fHeight );
212178 return ;
@@ -240,14 +206,15 @@ void FontRenderer::cacheBitmap(const SkGlyph& glyph, CachedGlyphInfo* cachedGlyp
240206 uint32_t endX = startX + glyph.fWidth ;
241207 uint32_t endY = startY + glyph.fHeight ;
242208
243- uint32_t cacheWidth = cacheTexture->mWidth ;
209+ uint32_t cacheWidth = cacheTexture->getWidth () ;
244210
245- if (!cacheTexture->mTexture ) {
211+ if (!cacheTexture->getTexture ()) {
212+ Caches::getInstance ().activeTexture (0 );
246213 // Large-glyph texture memory is allocated only as needed
247- allocateTextureMemory ( cacheTexture);
214+ cacheTexture-> allocateTexture ( );
248215 }
249216
250- uint8_t * cacheBuffer = cacheTexture->mTexture ;
217+ uint8_t * cacheBuffer = cacheTexture->getTexture () ;
251218 uint8_t * bitmapBuffer = (uint8_t *) glyph.fImage ;
252219 unsigned int stride = glyph.rowBytes ();
253220
@@ -287,7 +254,8 @@ CacheTexture* FontRenderer::createCacheTexture(int width, int height, bool alloc
287254 CacheTexture* cacheTexture = new CacheTexture (width, height);
288255
289256 if (allocate) {
290- allocateTextureMemory (cacheTexture);
257+ Caches::getInstance ().activeTexture (0 );
258+ cacheTexture->allocateTexture ();
291259 }
292260
293261 return cacheTexture;
@@ -362,16 +330,16 @@ void FontRenderer::checkTextureUpdate() {
362330 // Iterate over all the cache textures and see which ones need to be updated
363331 for (uint32_t i = 0 ; i < mCacheTextures .size (); i++) {
364332 CacheTexture* cacheTexture = mCacheTextures [i];
365- if (cacheTexture->mDirty && cacheTexture->mTexture != NULL ) {
333+ if (cacheTexture->isDirty () && cacheTexture->getTexture () ) {
366334 uint32_t xOffset = 0 ;
367- uint32_t width = cacheTexture->mWidth ;
368- uint32_t height = cacheTexture->mHeight ;
369- void * textureData = cacheTexture->mTexture ;
335+ uint32_t width = cacheTexture->getWidth () ;
336+ uint32_t height = cacheTexture->getHeight () ;
337+ void * textureData = cacheTexture->getTexture () ;
370338
371- if (cacheTexture->mTextureId != lastTextureId) {
339+ if (cacheTexture->getTextureId () != lastTextureId) {
340+ lastTextureId = cacheTexture->getTextureId ();
372341 caches.activeTexture (0 );
373- glBindTexture (GL_TEXTURE_2D, cacheTexture->mTextureId );
374- lastTextureId = cacheTexture->mTextureId ;
342+ glBindTexture (GL_TEXTURE_2D, lastTextureId);
375343 }
376344#if DEBUG_FONT_RENDERER
377345 ALOGD (" glTextSubimage for cacheTexture %d: xOff, width height = %d, %d, %d" ,
@@ -380,18 +348,14 @@ void FontRenderer::checkTextureUpdate() {
380348 glTexSubImage2D (GL_TEXTURE_2D, 0 , xOffset, 0 , width, height,
381349 GL_ALPHA, GL_UNSIGNED_BYTE, textureData);
382350
383- cacheTexture->mDirty = false ;
351+ cacheTexture->setDirty ( false ) ;
384352 }
385353 }
386354
387355 caches.activeTexture (0 );
388- glBindTexture (GL_TEXTURE_2D, mCurrentCacheTexture ->mTextureId );
389- if (mLinearFiltering != mCurrentCacheTexture ->mLinearFiltering ) {
390- const GLenum filtering = mLinearFiltering ? GL_LINEAR : GL_NEAREST;
391- glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filtering);
392- glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filtering);
393- mCurrentCacheTexture ->mLinearFiltering = mLinearFiltering ;
394- }
356+ glBindTexture (GL_TEXTURE_2D, mCurrentCacheTexture ->getTextureId ());
357+
358+ mCurrentCacheTexture ->setLinearFiltering (mLinearFiltering , false );
395359 mLastCacheTexture = mCurrentCacheTexture ;
396360
397361 mUploadTexture = false ;
0 commit comments