Romain Guy | 9f5dab3 | 2012-09-04 12:55:44 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Derek Sollenberger | ca79cf6 | 2012-08-14 16:44:52 -0400 | [diff] [blame] | 17 | #include <SkGlyph.h> |
Romain Guy | 9f5dab3 | 2012-09-04 12:55:44 -0700 | [diff] [blame] | 18 | |
Romain Guy | 9f5dab3 | 2012-09-04 12:55:44 -0700 | [diff] [blame] | 19 | #include "CacheTexture.h" |
Romain Guy | 8aa195d | 2013-06-04 18:00:09 -0700 | [diff] [blame] | 20 | #include "../Caches.h" |
Romain Guy | 0908764 | 2013-04-04 12:27:54 -0700 | [diff] [blame] | 21 | #include "../Debug.h" |
Romain Guy | cf51a41 | 2013-04-08 19:40:31 -0700 | [diff] [blame] | 22 | #include "../Extensions.h" |
| 23 | #include "../PixelBuffer.h" |
Romain Guy | 9f5dab3 | 2012-09-04 12:55:44 -0700 | [diff] [blame] | 24 | |
| 25 | namespace android { |
| 26 | namespace uirenderer { |
| 27 | |
| 28 | /////////////////////////////////////////////////////////////////////////////// |
| 29 | // CacheBlock |
| 30 | /////////////////////////////////////////////////////////////////////////////// |
| 31 | |
| 32 | /** |
| 33 | * Insert new block into existing linked list of blocks. Blocks are sorted in increasing-width |
| 34 | * order, except for the final block (the remainder space at the right, since we fill from the |
| 35 | * left). |
| 36 | */ |
Romain Guy | e43f785 | 2012-09-04 18:58:46 -0700 | [diff] [blame] | 37 | CacheBlock* CacheBlock::insertBlock(CacheBlock* head, CacheBlock* newBlock) { |
Romain Guy | 9f5dab3 | 2012-09-04 12:55:44 -0700 | [diff] [blame] | 38 | #if DEBUG_FONT_RENDERER |
| 39 | ALOGD("insertBlock: this, x, y, w, h = %p, %d, %d, %d, %d", |
| 40 | newBlock, newBlock->mX, newBlock->mY, |
| 41 | newBlock->mWidth, newBlock->mHeight); |
| 42 | #endif |
Romain Guy | 9b1204b | 2012-09-04 15:22:57 -0700 | [diff] [blame] | 43 | |
Romain Guy | e43f785 | 2012-09-04 18:58:46 -0700 | [diff] [blame] | 44 | CacheBlock* currBlock = head; |
| 45 | CacheBlock* prevBlock = NULL; |
Romain Guy | 9b1204b | 2012-09-04 15:22:57 -0700 | [diff] [blame] | 46 | |
Romain Guy | 9f5dab3 | 2012-09-04 12:55:44 -0700 | [diff] [blame] | 47 | while (currBlock && currBlock->mY != TEXTURE_BORDER_SIZE) { |
| 48 | if (newBlock->mWidth < currBlock->mWidth) { |
| 49 | newBlock->mNext = currBlock; |
| 50 | newBlock->mPrev = prevBlock; |
| 51 | currBlock->mPrev = newBlock; |
Romain Guy | 9b1204b | 2012-09-04 15:22:57 -0700 | [diff] [blame] | 52 | |
Romain Guy | 9f5dab3 | 2012-09-04 12:55:44 -0700 | [diff] [blame] | 53 | if (prevBlock) { |
| 54 | prevBlock->mNext = newBlock; |
| 55 | return head; |
| 56 | } else { |
| 57 | return newBlock; |
| 58 | } |
| 59 | } |
Romain Guy | 9b1204b | 2012-09-04 15:22:57 -0700 | [diff] [blame] | 60 | |
Romain Guy | 9f5dab3 | 2012-09-04 12:55:44 -0700 | [diff] [blame] | 61 | prevBlock = currBlock; |
| 62 | currBlock = currBlock->mNext; |
| 63 | } |
Romain Guy | 9b1204b | 2012-09-04 15:22:57 -0700 | [diff] [blame] | 64 | |
Romain Guy | 9f5dab3 | 2012-09-04 12:55:44 -0700 | [diff] [blame] | 65 | // new block larger than all others - insert at end (but before the remainder space, if there) |
| 66 | newBlock->mNext = currBlock; |
| 67 | newBlock->mPrev = prevBlock; |
Romain Guy | 9b1204b | 2012-09-04 15:22:57 -0700 | [diff] [blame] | 68 | |
Romain Guy | 9f5dab3 | 2012-09-04 12:55:44 -0700 | [diff] [blame] | 69 | if (currBlock) { |
| 70 | currBlock->mPrev = newBlock; |
| 71 | } |
Romain Guy | 9b1204b | 2012-09-04 15:22:57 -0700 | [diff] [blame] | 72 | |
Romain Guy | 9f5dab3 | 2012-09-04 12:55:44 -0700 | [diff] [blame] | 73 | if (prevBlock) { |
| 74 | prevBlock->mNext = newBlock; |
| 75 | return head; |
| 76 | } else { |
| 77 | return newBlock; |
| 78 | } |
| 79 | } |
| 80 | |
Romain Guy | e43f785 | 2012-09-04 18:58:46 -0700 | [diff] [blame] | 81 | CacheBlock* CacheBlock::removeBlock(CacheBlock* head, CacheBlock* blockToRemove) { |
Romain Guy | 9f5dab3 | 2012-09-04 12:55:44 -0700 | [diff] [blame] | 82 | #if DEBUG_FONT_RENDERER |
| 83 | ALOGD("removeBlock: this, x, y, w, h = %p, %d, %d, %d, %d", |
| 84 | blockToRemove, blockToRemove->mX, blockToRemove->mY, |
| 85 | blockToRemove->mWidth, blockToRemove->mHeight); |
| 86 | #endif |
Romain Guy | 9b1204b | 2012-09-04 15:22:57 -0700 | [diff] [blame] | 87 | |
Romain Guy | 9f5dab3 | 2012-09-04 12:55:44 -0700 | [diff] [blame] | 88 | CacheBlock* newHead = head; |
| 89 | CacheBlock* nextBlock = blockToRemove->mNext; |
| 90 | CacheBlock* prevBlock = blockToRemove->mPrev; |
Romain Guy | 9b1204b | 2012-09-04 15:22:57 -0700 | [diff] [blame] | 91 | |
Romain Guy | 9f5dab3 | 2012-09-04 12:55:44 -0700 | [diff] [blame] | 92 | if (prevBlock) { |
| 93 | prevBlock->mNext = nextBlock; |
| 94 | } else { |
| 95 | newHead = nextBlock; |
| 96 | } |
Romain Guy | 9b1204b | 2012-09-04 15:22:57 -0700 | [diff] [blame] | 97 | |
Romain Guy | 9f5dab3 | 2012-09-04 12:55:44 -0700 | [diff] [blame] | 98 | if (nextBlock) { |
| 99 | nextBlock->mPrev = prevBlock; |
| 100 | } |
Romain Guy | 9b1204b | 2012-09-04 15:22:57 -0700 | [diff] [blame] | 101 | |
Romain Guy | 9f5dab3 | 2012-09-04 12:55:44 -0700 | [diff] [blame] | 102 | delete blockToRemove; |
Romain Guy | 9b1204b | 2012-09-04 15:22:57 -0700 | [diff] [blame] | 103 | |
Romain Guy | 9f5dab3 | 2012-09-04 12:55:44 -0700 | [diff] [blame] | 104 | return newHead; |
| 105 | } |
| 106 | |
| 107 | /////////////////////////////////////////////////////////////////////////////// |
| 108 | // CacheTexture |
| 109 | /////////////////////////////////////////////////////////////////////////////// |
| 110 | |
Victoria Lease | 1e54681 | 2013-06-25 14:25:17 -0700 | [diff] [blame] | 111 | CacheTexture::CacheTexture(uint16_t width, uint16_t height, GLenum format, uint32_t maxQuadCount) : |
| 112 | mTexture(NULL), mTextureId(0), mWidth(width), mHeight(height), mFormat(format), |
Romain Guy | 661a87e | 2013-03-19 15:24:36 -0700 | [diff] [blame] | 113 | mLinearFiltering(false), mDirty(false), mNumGlyphs(0), |
Romain Guy | 8aa195d | 2013-06-04 18:00:09 -0700 | [diff] [blame] | 114 | mMesh(NULL), mCurrentQuad(0), mMaxQuadCount(maxQuadCount), |
| 115 | mCaches(Caches::getInstance()) { |
Romain Guy | 661a87e | 2013-03-19 15:24:36 -0700 | [diff] [blame] | 116 | mCacheBlocks = new CacheBlock(TEXTURE_BORDER_SIZE, TEXTURE_BORDER_SIZE, |
| 117 | mWidth - TEXTURE_BORDER_SIZE, mHeight - TEXTURE_BORDER_SIZE, true); |
Romain Guy | cf51a41 | 2013-04-08 19:40:31 -0700 | [diff] [blame] | 118 | |
| 119 | // OpenGL ES 3.0+ lets us specify the row length for unpack operations such |
| 120 | // as glTexSubImage2D(). This allows us to upload a sub-rectangle of a texture. |
| 121 | // With OpenGL ES 2.0 we have to upload entire stripes instead. |
Romain Guy | 318ae7b | 2013-09-24 18:44:54 -0700 | [diff] [blame] | 122 | mHasUnpackRowLength = Extensions::getInstance().hasUnpackRowLength(); |
Romain Guy | 661a87e | 2013-03-19 15:24:36 -0700 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | CacheTexture::~CacheTexture() { |
| 126 | releaseMesh(); |
| 127 | releaseTexture(); |
| 128 | reset(); |
| 129 | } |
| 130 | |
| 131 | void CacheTexture::reset() { |
| 132 | // Delete existing cache blocks |
| 133 | while (mCacheBlocks != NULL) { |
| 134 | CacheBlock* tmpBlock = mCacheBlocks; |
| 135 | mCacheBlocks = mCacheBlocks->mNext; |
| 136 | delete tmpBlock; |
| 137 | } |
| 138 | mNumGlyphs = 0; |
| 139 | mCurrentQuad = 0; |
| 140 | } |
| 141 | |
| 142 | void CacheTexture::init() { |
| 143 | // reset, then create a new remainder space to start again |
| 144 | reset(); |
| 145 | mCacheBlocks = new CacheBlock(TEXTURE_BORDER_SIZE, TEXTURE_BORDER_SIZE, |
| 146 | mWidth - TEXTURE_BORDER_SIZE, mHeight - TEXTURE_BORDER_SIZE, true); |
| 147 | } |
| 148 | |
| 149 | void CacheTexture::releaseMesh() { |
| 150 | delete[] mMesh; |
| 151 | } |
| 152 | |
| 153 | void CacheTexture::releaseTexture() { |
| 154 | if (mTexture) { |
Romain Guy | cf51a41 | 2013-04-08 19:40:31 -0700 | [diff] [blame] | 155 | delete mTexture; |
Romain Guy | 661a87e | 2013-03-19 15:24:36 -0700 | [diff] [blame] | 156 | mTexture = NULL; |
| 157 | } |
| 158 | if (mTextureId) { |
Romain Guy | be1b127 | 2013-06-06 14:02:54 -0700 | [diff] [blame] | 159 | mCaches.deleteTexture(mTextureId); |
Romain Guy | 661a87e | 2013-03-19 15:24:36 -0700 | [diff] [blame] | 160 | mTextureId = 0; |
| 161 | } |
| 162 | mDirty = false; |
| 163 | mCurrentQuad = 0; |
| 164 | } |
| 165 | |
Romain Guy | cf51a41 | 2013-04-08 19:40:31 -0700 | [diff] [blame] | 166 | void CacheTexture::setLinearFiltering(bool linearFiltering, bool bind) { |
| 167 | if (linearFiltering != mLinearFiltering) { |
| 168 | mLinearFiltering = linearFiltering; |
| 169 | |
| 170 | const GLenum filtering = linearFiltering ? GL_LINEAR : GL_NEAREST; |
Romain Guy | 8aa195d | 2013-06-04 18:00:09 -0700 | [diff] [blame] | 171 | if (bind) mCaches.bindTexture(getTextureId()); |
Romain Guy | cf51a41 | 2013-04-08 19:40:31 -0700 | [diff] [blame] | 172 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filtering); |
| 173 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filtering); |
| 174 | } |
| 175 | } |
| 176 | |
Romain Guy | 661a87e | 2013-03-19 15:24:36 -0700 | [diff] [blame] | 177 | void CacheTexture::allocateMesh() { |
| 178 | if (!mMesh) { |
| 179 | mMesh = new TextureVertex[mMaxQuadCount * 4]; |
| 180 | } |
| 181 | } |
| 182 | |
| 183 | void CacheTexture::allocateTexture() { |
| 184 | if (!mTexture) { |
Victoria Lease | 1e54681 | 2013-06-25 14:25:17 -0700 | [diff] [blame] | 185 | mTexture = PixelBuffer::create(mFormat, mWidth, mHeight); |
Romain Guy | 661a87e | 2013-03-19 15:24:36 -0700 | [diff] [blame] | 186 | } |
| 187 | |
| 188 | if (!mTextureId) { |
| 189 | glGenTextures(1, &mTextureId); |
| 190 | |
Romain Guy | 8aa195d | 2013-06-04 18:00:09 -0700 | [diff] [blame] | 191 | mCaches.bindTexture(mTextureId); |
Romain Guy | 661a87e | 2013-03-19 15:24:36 -0700 | [diff] [blame] | 192 | glPixelStorei(GL_UNPACK_ALIGNMENT, 1); |
| 193 | // Initialize texture dimensions |
Victoria Lease | 1e54681 | 2013-06-25 14:25:17 -0700 | [diff] [blame] | 194 | glTexImage2D(GL_TEXTURE_2D, 0, mFormat, mWidth, mHeight, 0, |
| 195 | mFormat, GL_UNSIGNED_BYTE, 0); |
Romain Guy | 661a87e | 2013-03-19 15:24:36 -0700 | [diff] [blame] | 196 | |
| 197 | const GLenum filtering = getLinearFiltering() ? GL_LINEAR : GL_NEAREST; |
| 198 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filtering); |
| 199 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filtering); |
| 200 | |
| 201 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 202 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| 203 | } |
| 204 | } |
| 205 | |
Romain Guy | cf51a41 | 2013-04-08 19:40:31 -0700 | [diff] [blame] | 206 | bool CacheTexture::upload() { |
| 207 | const Rect& dirtyRect = mDirtyRect; |
| 208 | |
Romain Guy | 318ae7b | 2013-09-24 18:44:54 -0700 | [diff] [blame] | 209 | uint32_t x = mHasUnpackRowLength ? dirtyRect.left : 0; |
Romain Guy | cf51a41 | 2013-04-08 19:40:31 -0700 | [diff] [blame] | 210 | uint32_t y = dirtyRect.top; |
Romain Guy | 318ae7b | 2013-09-24 18:44:54 -0700 | [diff] [blame] | 211 | uint32_t width = mHasUnpackRowLength ? dirtyRect.getWidth() : mWidth; |
Romain Guy | cf51a41 | 2013-04-08 19:40:31 -0700 | [diff] [blame] | 212 | uint32_t height = dirtyRect.getHeight(); |
| 213 | |
| 214 | // The unpack row length only needs to be specified when a new |
| 215 | // texture is bound |
Romain Guy | 318ae7b | 2013-09-24 18:44:54 -0700 | [diff] [blame] | 216 | if (mHasUnpackRowLength) { |
Romain Guy | cf51a41 | 2013-04-08 19:40:31 -0700 | [diff] [blame] | 217 | glPixelStorei(GL_UNPACK_ROW_LENGTH, mWidth); |
| 218 | } |
| 219 | |
Victoria Lease | 1e54681 | 2013-06-25 14:25:17 -0700 | [diff] [blame] | 220 | mTexture->upload(x, y, width, height); |
Romain Guy | cf51a41 | 2013-04-08 19:40:31 -0700 | [diff] [blame] | 221 | setDirty(false); |
| 222 | |
Romain Guy | 318ae7b | 2013-09-24 18:44:54 -0700 | [diff] [blame] | 223 | return mHasUnpackRowLength; |
Romain Guy | cf51a41 | 2013-04-08 19:40:31 -0700 | [diff] [blame] | 224 | } |
| 225 | |
| 226 | void CacheTexture::setDirty(bool dirty) { |
| 227 | mDirty = dirty; |
| 228 | if (!dirty) { |
| 229 | mDirtyRect.setEmpty(); |
| 230 | } |
| 231 | } |
| 232 | |
Romain Guy | e43f785 | 2012-09-04 18:58:46 -0700 | [diff] [blame] | 233 | bool CacheTexture::fitBitmap(const SkGlyph& glyph, uint32_t* retOriginX, uint32_t* retOriginY) { |
Victoria Lease | 1e54681 | 2013-06-25 14:25:17 -0700 | [diff] [blame] | 234 | switch (glyph.fMaskFormat) { |
| 235 | case SkMask::kA8_Format: |
Victoria Lease | 723b2fe | 2013-08-12 14:38:44 -0700 | [diff] [blame] | 236 | case SkMask::kBW_Format: |
Victoria Lease | 1e54681 | 2013-06-25 14:25:17 -0700 | [diff] [blame] | 237 | if (mFormat != GL_ALPHA) { |
| 238 | #if DEBUG_FONT_RENDERER |
Victoria Lease | 723b2fe | 2013-08-12 14:38:44 -0700 | [diff] [blame] | 239 | ALOGD("fitBitmap: texture format %x is inappropriate for monochromatic glyphs", |
| 240 | mFormat); |
Victoria Lease | 1e54681 | 2013-06-25 14:25:17 -0700 | [diff] [blame] | 241 | #endif |
| 242 | return false; |
| 243 | } |
| 244 | break; |
| 245 | case SkMask::kARGB32_Format: |
| 246 | if (mFormat != GL_RGBA) { |
| 247 | #if DEBUG_FONT_RENDERER |
Victoria Lease | 723b2fe | 2013-08-12 14:38:44 -0700 | [diff] [blame] | 248 | ALOGD("fitBitmap: texture format %x is inappropriate for colour glyphs", mFormat); |
Victoria Lease | 1e54681 | 2013-06-25 14:25:17 -0700 | [diff] [blame] | 249 | #endif |
| 250 | return false; |
| 251 | } |
| 252 | break; |
| 253 | default: |
| 254 | #if DEBUG_FONT_RENDERER |
| 255 | ALOGD("fitBitmap: unknown glyph format %x encountered", glyph.fMaskFormat); |
| 256 | #endif |
| 257 | return false; |
| 258 | } |
| 259 | |
Romain Guy | e43f785 | 2012-09-04 18:58:46 -0700 | [diff] [blame] | 260 | if (glyph.fHeight + TEXTURE_BORDER_SIZE * 2 > mHeight) { |
Romain Guy | 9f5dab3 | 2012-09-04 12:55:44 -0700 | [diff] [blame] | 261 | return false; |
| 262 | } |
| 263 | |
| 264 | uint16_t glyphW = glyph.fWidth + TEXTURE_BORDER_SIZE; |
| 265 | uint16_t glyphH = glyph.fHeight + TEXTURE_BORDER_SIZE; |
Romain Guy | 9b1204b | 2012-09-04 15:22:57 -0700 | [diff] [blame] | 266 | |
Romain Guy | 9f5dab3 | 2012-09-04 12:55:44 -0700 | [diff] [blame] | 267 | // roundedUpW equals glyphW to the next multiple of CACHE_BLOCK_ROUNDING_SIZE. |
| 268 | // This columns for glyphs that are close but not necessarily exactly the same size. It trades |
| 269 | // off the loss of a few pixels for some glyphs against the ability to store more glyphs |
| 270 | // of varying sizes in one block. |
Romain Guy | e43f785 | 2012-09-04 18:58:46 -0700 | [diff] [blame] | 271 | uint16_t roundedUpW = (glyphW + CACHE_BLOCK_ROUNDING_SIZE - 1) & -CACHE_BLOCK_ROUNDING_SIZE; |
Romain Guy | 9b1204b | 2012-09-04 15:22:57 -0700 | [diff] [blame] | 272 | |
Romain Guy | e43f785 | 2012-09-04 18:58:46 -0700 | [diff] [blame] | 273 | CacheBlock* cacheBlock = mCacheBlocks; |
Romain Guy | 9f5dab3 | 2012-09-04 12:55:44 -0700 | [diff] [blame] | 274 | while (cacheBlock) { |
| 275 | // Store glyph in this block iff: it fits the block's remaining space and: |
| 276 | // it's the remainder space (mY == 0) or there's only enough height for this one glyph |
| 277 | // or it's within ROUNDING_SIZE of the block width |
| 278 | if (roundedUpW <= cacheBlock->mWidth && glyphH <= cacheBlock->mHeight && |
| 279 | (cacheBlock->mY == TEXTURE_BORDER_SIZE || |
| 280 | (cacheBlock->mWidth - roundedUpW < CACHE_BLOCK_ROUNDING_SIZE))) { |
| 281 | if (cacheBlock->mHeight - glyphH < glyphH) { |
| 282 | // Only enough space for this glyph - don't bother rounding up the width |
| 283 | roundedUpW = glyphW; |
| 284 | } |
Romain Guy | 9b1204b | 2012-09-04 15:22:57 -0700 | [diff] [blame] | 285 | |
Romain Guy | 9f5dab3 | 2012-09-04 12:55:44 -0700 | [diff] [blame] | 286 | *retOriginX = cacheBlock->mX; |
| 287 | *retOriginY = cacheBlock->mY; |
Romain Guy | 9b1204b | 2012-09-04 15:22:57 -0700 | [diff] [blame] | 288 | |
Romain Guy | 9f5dab3 | 2012-09-04 12:55:44 -0700 | [diff] [blame] | 289 | // If this is the remainder space, create a new cache block for this column. Otherwise, |
| 290 | // adjust the info about this column. |
| 291 | if (cacheBlock->mY == TEXTURE_BORDER_SIZE) { |
| 292 | uint16_t oldX = cacheBlock->mX; |
| 293 | // Adjust remainder space dimensions |
| 294 | cacheBlock->mWidth -= roundedUpW; |
| 295 | cacheBlock->mX += roundedUpW; |
Romain Guy | 9b1204b | 2012-09-04 15:22:57 -0700 | [diff] [blame] | 296 | |
Romain Guy | 9f5dab3 | 2012-09-04 12:55:44 -0700 | [diff] [blame] | 297 | if (mHeight - glyphH >= glyphH) { |
| 298 | // There's enough height left over to create a new CacheBlock |
Romain Guy | e43f785 | 2012-09-04 18:58:46 -0700 | [diff] [blame] | 299 | CacheBlock* newBlock = new CacheBlock(oldX, glyphH + TEXTURE_BORDER_SIZE, |
Romain Guy | 9f5dab3 | 2012-09-04 12:55:44 -0700 | [diff] [blame] | 300 | roundedUpW, mHeight - glyphH - TEXTURE_BORDER_SIZE); |
| 301 | #if DEBUG_FONT_RENDERER |
| 302 | ALOGD("fitBitmap: Created new block: this, x, y, w, h = %p, %d, %d, %d, %d", |
| 303 | newBlock, newBlock->mX, newBlock->mY, |
| 304 | newBlock->mWidth, newBlock->mHeight); |
| 305 | #endif |
| 306 | mCacheBlocks = CacheBlock::insertBlock(mCacheBlocks, newBlock); |
| 307 | } |
| 308 | } else { |
| 309 | // Insert into current column and adjust column dimensions |
| 310 | cacheBlock->mY += glyphH; |
| 311 | cacheBlock->mHeight -= glyphH; |
| 312 | #if DEBUG_FONT_RENDERER |
| 313 | ALOGD("fitBitmap: Added to existing block: this, x, y, w, h = %p, %d, %d, %d, %d", |
| 314 | cacheBlock, cacheBlock->mX, cacheBlock->mY, |
| 315 | cacheBlock->mWidth, cacheBlock->mHeight); |
| 316 | #endif |
| 317 | } |
Romain Guy | 9b1204b | 2012-09-04 15:22:57 -0700 | [diff] [blame] | 318 | |
Romain Guy | 9f5dab3 | 2012-09-04 12:55:44 -0700 | [diff] [blame] | 319 | if (cacheBlock->mHeight < fmin(glyphH, glyphW)) { |
| 320 | // If remaining space in this block is too small to be useful, remove it |
| 321 | mCacheBlocks = CacheBlock::removeBlock(mCacheBlocks, cacheBlock); |
| 322 | } |
Romain Guy | 9b1204b | 2012-09-04 15:22:57 -0700 | [diff] [blame] | 323 | |
Romain Guy | 9f5dab3 | 2012-09-04 12:55:44 -0700 | [diff] [blame] | 324 | mDirty = true; |
Chet Haase | b92d8f7 | 2012-09-21 08:40:46 -0700 | [diff] [blame] | 325 | const Rect r(*retOriginX - TEXTURE_BORDER_SIZE, *retOriginY - TEXTURE_BORDER_SIZE, |
| 326 | *retOriginX + glyphW, *retOriginY + glyphH); |
| 327 | mDirtyRect.unionWith(r); |
Romain Guy | 9b1204b | 2012-09-04 15:22:57 -0700 | [diff] [blame] | 328 | mNumGlyphs++; |
| 329 | |
Romain Guy | 9f5dab3 | 2012-09-04 12:55:44 -0700 | [diff] [blame] | 330 | #if DEBUG_FONT_RENDERER |
| 331 | ALOGD("fitBitmap: current block list:"); |
| 332 | mCacheBlocks->output(); |
| 333 | #endif |
Romain Guy | 9b1204b | 2012-09-04 15:22:57 -0700 | [diff] [blame] | 334 | |
Romain Guy | 9f5dab3 | 2012-09-04 12:55:44 -0700 | [diff] [blame] | 335 | return true; |
| 336 | } |
| 337 | cacheBlock = cacheBlock->mNext; |
| 338 | } |
| 339 | #if DEBUG_FONT_RENDERER |
| 340 | ALOGD("fitBitmap: returning false for glyph of size %d, %d", glyphW, glyphH); |
| 341 | #endif |
| 342 | return false; |
| 343 | } |
| 344 | |
| 345 | }; // namespace uirenderer |
| 346 | }; // namespace android |