Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright (C) 2009 The Android Open Source Project |
| 4 | * |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at |
| 8 | * |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | * |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | */ |
| 17 | |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 18 | #include "rsContext.h" |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 19 | |
| 20 | #include "rsFont.h" |
| 21 | #include "rsProgramFragment.h" |
Alex Sakhartchouk | 3bf3ea0 | 2010-10-01 15:20:41 -0700 | [diff] [blame] | 22 | #include <cutils/properties.h> |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 23 | #include FT_BITMAP_H |
| 24 | |
| 25 | #include <GLES/gl.h> |
| 26 | #include <GLES/glext.h> |
| 27 | #include <GLES2/gl2.h> |
| 28 | #include <GLES2/gl2ext.h> |
| 29 | |
| 30 | using namespace android; |
| 31 | using namespace android::renderscript; |
| 32 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 33 | Font::Font(Context *rsc) : ObjectBase(rsc), mCachedGlyphs(NULL) { |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 34 | mInitialized = false; |
| 35 | mHasKerning = false; |
Alex Sakhartchouk | b6b3489 | 2010-06-30 16:53:43 -0700 | [diff] [blame] | 36 | mFace = NULL; |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 37 | } |
| 38 | |
Alex Sakhartchouk | b0253ea | 2011-01-07 11:12:08 -0800 | [diff] [blame] | 39 | bool Font::init(const char *name, float fontSize, uint32_t dpi, const void *data, uint32_t dataLen) { |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 40 | if (mInitialized) { |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 41 | LOGE("Reinitialization of fonts not supported"); |
| 42 | return false; |
| 43 | } |
| 44 | |
Alex Sakhartchouk | b0253ea | 2011-01-07 11:12:08 -0800 | [diff] [blame] | 45 | FT_Error error = 0; |
| 46 | if (data != NULL && dataLen > 0) { |
| 47 | error = FT_New_Memory_Face(mRSC->mStateFont.getLib(), (const FT_Byte*)data, dataLen, 0, &mFace); |
| 48 | } else { |
| 49 | error = FT_New_Face(mRSC->mStateFont.getLib(), name, 0, &mFace); |
| 50 | } |
| 51 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 52 | if (error) { |
Alex Sakhartchouk | e27cdee | 2010-12-17 11:41:08 -0800 | [diff] [blame] | 53 | LOGE("Unable to initialize font %s", name); |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 54 | return false; |
| 55 | } |
| 56 | |
| 57 | mFontName = name; |
| 58 | mFontSize = fontSize; |
| 59 | mDpi = dpi; |
| 60 | |
Alex Sakhartchouk | e27cdee | 2010-12-17 11:41:08 -0800 | [diff] [blame] | 61 | error = FT_Set_Char_Size(mFace, (FT_F26Dot6)(fontSize * 64.0f), 0, dpi, 0); |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 62 | if (error) { |
Alex Sakhartchouk | e27cdee | 2010-12-17 11:41:08 -0800 | [diff] [blame] | 63 | LOGE("Unable to set font size on %s", name); |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 64 | return false; |
| 65 | } |
| 66 | |
| 67 | mHasKerning = FT_HAS_KERNING(mFace); |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 68 | |
| 69 | mInitialized = true; |
| 70 | return true; |
| 71 | } |
| 72 | |
Jason Sams | 38f8d9d | 2011-01-27 00:14:13 -0800 | [diff] [blame] | 73 | void Font::preDestroy() const { |
| 74 | for (uint32_t ct = 0; ct < mRSC->mStateFont.mActiveFonts.size(); ct++) { |
| 75 | if (mRSC->mStateFont.mActiveFonts[ct] == this) { |
| 76 | mRSC->mStateFont.mActiveFonts.removeAt(ct); |
| 77 | break; |
| 78 | } |
| 79 | } |
| 80 | } |
| 81 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 82 | void Font::invalidateTextureCache() { |
| 83 | for (uint32_t i = 0; i < mCachedGlyphs.size(); i ++) { |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 84 | mCachedGlyphs.valueAt(i)->mIsValid = false; |
| 85 | } |
| 86 | } |
| 87 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 88 | void Font::drawCachedGlyph(CachedGlyphInfo *glyph, int32_t x, int32_t y) { |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 89 | FontState *state = &mRSC->mStateFont; |
| 90 | |
Alex Sakhartchouk | 10825a0 | 2010-10-05 11:33:27 -0700 | [diff] [blame] | 91 | int32_t nPenX = x + glyph->mBitmapLeft; |
| 92 | int32_t nPenY = y - glyph->mBitmapTop + glyph->mBitmapHeight; |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 93 | |
Alex Sakhartchouk | 10825a0 | 2010-10-05 11:33:27 -0700 | [diff] [blame] | 94 | float u1 = glyph->mBitmapMinU; |
| 95 | float u2 = glyph->mBitmapMaxU; |
| 96 | float v1 = glyph->mBitmapMinV; |
| 97 | float v2 = glyph->mBitmapMaxV; |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 98 | |
Alex Sakhartchouk | 10825a0 | 2010-10-05 11:33:27 -0700 | [diff] [blame] | 99 | int32_t width = (int32_t) glyph->mBitmapWidth; |
| 100 | int32_t height = (int32_t) glyph->mBitmapHeight; |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 101 | |
Alex Sakhartchouk | 10825a0 | 2010-10-05 11:33:27 -0700 | [diff] [blame] | 102 | state->appendMeshQuad(nPenX, nPenY, 0, u1, v2, |
| 103 | nPenX + width, nPenY, 0, u2, v2, |
| 104 | nPenX + width, nPenY - height, 0, u2, v1, |
| 105 | nPenX, nPenY - height, 0, u1, v1); |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 106 | } |
| 107 | |
Alex Sakhartchouk | 10825a0 | 2010-10-05 11:33:27 -0700 | [diff] [blame] | 108 | void Font::drawCachedGlyph(CachedGlyphInfo* glyph, int32_t x, int32_t y, |
| 109 | uint8_t* bitmap, uint32_t bitmapW, uint32_t bitmapH) { |
| 110 | int32_t nPenX = x + glyph->mBitmapLeft; |
| 111 | int32_t nPenY = y + glyph->mBitmapTop; |
| 112 | |
| 113 | uint32_t endX = glyph->mBitmapMinX + glyph->mBitmapWidth; |
| 114 | uint32_t endY = glyph->mBitmapMinY + glyph->mBitmapHeight; |
| 115 | |
| 116 | FontState *state = &mRSC->mStateFont; |
| 117 | uint32_t cacheWidth = state->getCacheTextureType()->getDimX(); |
| 118 | const uint8_t* cacheBuffer = state->getTextTextureData(); |
| 119 | |
| 120 | uint32_t cacheX = 0, cacheY = 0; |
| 121 | int32_t bX = 0, bY = 0; |
| 122 | for (cacheX = glyph->mBitmapMinX, bX = nPenX; cacheX < endX; cacheX++, bX++) { |
| 123 | for (cacheY = glyph->mBitmapMinY, bY = nPenY; cacheY < endY; cacheY++, bY++) { |
| 124 | if (bX < 0 || bY < 0 || bX >= (int32_t) bitmapW || bY >= (int32_t) bitmapH) { |
| 125 | LOGE("Skipping invalid index"); |
| 126 | continue; |
| 127 | } |
| 128 | uint8_t tempCol = cacheBuffer[cacheY * cacheWidth + cacheX]; |
| 129 | bitmap[bY * bitmapW + bX] = tempCol; |
| 130 | } |
| 131 | } |
Alex Sakhartchouk | 10825a0 | 2010-10-05 11:33:27 -0700 | [diff] [blame] | 132 | } |
| 133 | |
| 134 | void Font::measureCachedGlyph(CachedGlyphInfo *glyph, int32_t x, int32_t y, Rect *bounds) { |
| 135 | int32_t nPenX = x + glyph->mBitmapLeft; |
| 136 | int32_t nPenY = y - glyph->mBitmapTop + glyph->mBitmapHeight; |
| 137 | |
| 138 | int32_t width = (int32_t) glyph->mBitmapWidth; |
| 139 | int32_t height = (int32_t) glyph->mBitmapHeight; |
| 140 | |
Alex Sakhartchouk | b0253ea | 2011-01-07 11:12:08 -0800 | [diff] [blame] | 141 | // 0, 0 is top left, so bottom is a positive number |
| 142 | if (bounds->bottom < nPenY) { |
Alex Sakhartchouk | 10825a0 | 2010-10-05 11:33:27 -0700 | [diff] [blame] | 143 | bounds->bottom = nPenY; |
| 144 | } |
| 145 | if (bounds->left > nPenX) { |
| 146 | bounds->left = nPenX; |
| 147 | } |
| 148 | if (bounds->right < nPenX + width) { |
| 149 | bounds->right = nPenX + width; |
| 150 | } |
Alex Sakhartchouk | b0253ea | 2011-01-07 11:12:08 -0800 | [diff] [blame] | 151 | if (bounds->top > nPenY - height) { |
| 152 | bounds->top = nPenY - height; |
Alex Sakhartchouk | 10825a0 | 2010-10-05 11:33:27 -0700 | [diff] [blame] | 153 | } |
| 154 | } |
| 155 | |
| 156 | void Font::renderUTF(const char *text, uint32_t len, int32_t x, int32_t y, |
| 157 | uint32_t start, int32_t numGlyphs, |
| 158 | RenderMode mode, Rect *bounds, |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 159 | uint8_t *bitmap, uint32_t bitmapW, uint32_t bitmapH) { |
| 160 | if (!mInitialized || numGlyphs == 0 || text == NULL || len == 0) { |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 161 | return; |
| 162 | } |
| 163 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 164 | if (mode == Font::MEASURE) { |
Alex Sakhartchouk | 10825a0 | 2010-10-05 11:33:27 -0700 | [diff] [blame] | 165 | if (bounds == NULL) { |
| 166 | LOGE("No return rectangle provided to measure text"); |
| 167 | return; |
| 168 | } |
| 169 | // Reset min and max of the bounding box to something large |
Alex Sakhartchouk | b0253ea | 2011-01-07 11:12:08 -0800 | [diff] [blame] | 170 | bounds->set(1e6, -1e6, 1e6, -1e6); |
Alex Sakhartchouk | 10825a0 | 2010-10-05 11:33:27 -0700 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | int32_t penX = x, penY = y; |
| 174 | int32_t glyphsLeft = 1; |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 175 | if (numGlyphs > 0) { |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 176 | glyphsLeft = numGlyphs; |
| 177 | } |
| 178 | |
| 179 | size_t index = start; |
| 180 | size_t nextIndex = 0; |
| 181 | |
| 182 | while (glyphsLeft > 0) { |
| 183 | |
Kenny Root | 300ba68 | 2010-11-09 14:37:23 -0800 | [diff] [blame] | 184 | int32_t utfChar = utf32_from_utf8_at(text, len, index, &nextIndex); |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 185 | |
| 186 | // Reached the end of the string or encountered |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 187 | if (utfChar < 0) { |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 188 | break; |
| 189 | } |
| 190 | |
| 191 | // Move to the next character in the array |
| 192 | index = nextIndex; |
| 193 | |
Alex Sakhartchouk | 94bbccc | 2010-08-17 11:09:49 -0700 | [diff] [blame] | 194 | CachedGlyphInfo *cachedGlyph = getCachedUTFChar(utfChar); |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 195 | |
| 196 | // If it's still not valid, we couldn't cache it, so we shouldn't draw garbage |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 197 | if (cachedGlyph->mIsValid) { |
| 198 | switch (mode) { |
Alex Sakhartchouk | 10825a0 | 2010-10-05 11:33:27 -0700 | [diff] [blame] | 199 | case FRAMEBUFFER: |
| 200 | drawCachedGlyph(cachedGlyph, penX, penY); |
| 201 | break; |
| 202 | case BITMAP: |
| 203 | drawCachedGlyph(cachedGlyph, penX, penY, bitmap, bitmapW, bitmapH); |
| 204 | break; |
| 205 | case MEASURE: |
| 206 | measureCachedGlyph(cachedGlyph, penX, penY, bounds); |
| 207 | break; |
| 208 | } |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | penX += (cachedGlyph->mAdvance.x >> 6); |
| 212 | |
| 213 | // If we were given a specific number of glyphs, decrement |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 214 | if (numGlyphs > 0) { |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 215 | glyphsLeft --; |
| 216 | } |
| 217 | } |
| 218 | } |
| 219 | |
Alex Sakhartchouk | 94bbccc | 2010-08-17 11:09:49 -0700 | [diff] [blame] | 220 | Font::CachedGlyphInfo* Font::getCachedUTFChar(int32_t utfChar) { |
| 221 | |
| 222 | CachedGlyphInfo *cachedGlyph = mCachedGlyphs.valueFor((uint32_t)utfChar); |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 223 | if (cachedGlyph == NULL) { |
Alex Sakhartchouk | 94bbccc | 2010-08-17 11:09:49 -0700 | [diff] [blame] | 224 | cachedGlyph = cacheGlyph((uint32_t)utfChar); |
| 225 | } |
| 226 | // Is the glyph still in texture cache? |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 227 | if (!cachedGlyph->mIsValid) { |
Alex Sakhartchouk | 94bbccc | 2010-08-17 11:09:49 -0700 | [diff] [blame] | 228 | updateGlyphCache(cachedGlyph); |
| 229 | } |
| 230 | |
| 231 | return cachedGlyph; |
| 232 | } |
| 233 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 234 | void Font::updateGlyphCache(CachedGlyphInfo *glyph) { |
Alex Sakhartchouk | 071508d | 2010-06-30 12:49:27 -0700 | [diff] [blame] | 235 | FT_Error error = FT_Load_Glyph( mFace, glyph->mGlyphIndex, FT_LOAD_RENDER ); |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 236 | if (error) { |
Alex Sakhartchouk | 071508d | 2010-06-30 12:49:27 -0700 | [diff] [blame] | 237 | LOGE("Couldn't load glyph."); |
| 238 | return; |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 239 | } |
| 240 | |
Alex Sakhartchouk | 071508d | 2010-06-30 12:49:27 -0700 | [diff] [blame] | 241 | glyph->mAdvance = mFace->glyph->advance; |
| 242 | glyph->mBitmapLeft = mFace->glyph->bitmap_left; |
| 243 | glyph->mBitmapTop = mFace->glyph->bitmap_top; |
| 244 | |
| 245 | FT_Bitmap *bitmap = &mFace->glyph->bitmap; |
| 246 | |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 247 | // Now copy the bitmap into the cache texture |
| 248 | uint32_t startX = 0; |
| 249 | uint32_t startY = 0; |
| 250 | |
| 251 | // Let the font state figure out where to put the bitmap |
| 252 | FontState *state = &mRSC->mStateFont; |
Alex Sakhartchouk | 071508d | 2010-06-30 12:49:27 -0700 | [diff] [blame] | 253 | glyph->mIsValid = state->cacheBitmap(bitmap, &startX, &startY); |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 254 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 255 | if (!glyph->mIsValid) { |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 256 | return; |
| 257 | } |
| 258 | |
Alex Sakhartchouk | 071508d | 2010-06-30 12:49:27 -0700 | [diff] [blame] | 259 | uint32_t endX = startX + bitmap->width; |
| 260 | uint32_t endY = startY + bitmap->rows; |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 261 | |
| 262 | glyph->mBitmapMinX = startX; |
| 263 | glyph->mBitmapMinY = startY; |
Alex Sakhartchouk | 071508d | 2010-06-30 12:49:27 -0700 | [diff] [blame] | 264 | glyph->mBitmapWidth = bitmap->width; |
| 265 | glyph->mBitmapHeight = bitmap->rows; |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 266 | |
| 267 | uint32_t cacheWidth = state->getCacheTextureType()->getDimX(); |
| 268 | uint32_t cacheHeight = state->getCacheTextureType()->getDimY(); |
| 269 | |
| 270 | glyph->mBitmapMinU = (float)startX / (float)cacheWidth; |
| 271 | glyph->mBitmapMinV = (float)startY / (float)cacheHeight; |
| 272 | glyph->mBitmapMaxU = (float)endX / (float)cacheWidth; |
| 273 | glyph->mBitmapMaxV = (float)endY / (float)cacheHeight; |
| 274 | } |
| 275 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 276 | Font::CachedGlyphInfo *Font::cacheGlyph(uint32_t glyph) { |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 277 | CachedGlyphInfo *newGlyph = new CachedGlyphInfo(); |
| 278 | mCachedGlyphs.add(glyph, newGlyph); |
| 279 | |
| 280 | newGlyph->mGlyphIndex = FT_Get_Char_Index(mFace, glyph); |
| 281 | newGlyph->mIsValid = false; |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 282 | |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 283 | updateGlyphCache(newGlyph); |
| 284 | |
| 285 | return newGlyph; |
| 286 | } |
| 287 | |
Alex Sakhartchouk | b0253ea | 2011-01-07 11:12:08 -0800 | [diff] [blame] | 288 | Font * Font::create(Context *rsc, const char *name, float fontSize, uint32_t dpi, |
| 289 | const void *data, uint32_t dataLen) { |
Alex Sakhartchouk | 27f5052 | 2010-08-18 15:46:43 -0700 | [diff] [blame] | 290 | rsc->mStateFont.checkInit(); |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 291 | Vector<Font*> &activeFonts = rsc->mStateFont.mActiveFonts; |
| 292 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 293 | for (uint32_t i = 0; i < activeFonts.size(); i ++) { |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 294 | Font *ithFont = activeFonts[i]; |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 295 | if (ithFont->mFontName == name && ithFont->mFontSize == fontSize && ithFont->mDpi == dpi) { |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 296 | return ithFont; |
| 297 | } |
| 298 | } |
| 299 | |
| 300 | Font *newFont = new Font(rsc); |
Alex Sakhartchouk | b0253ea | 2011-01-07 11:12:08 -0800 | [diff] [blame] | 301 | bool isInitialized = newFont->init(name, fontSize, dpi, data, dataLen); |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 302 | if (isInitialized) { |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 303 | activeFonts.push(newFont); |
Alex Sakhartchouk | 94bbccc | 2010-08-17 11:09:49 -0700 | [diff] [blame] | 304 | rsc->mStateFont.precacheLatin(newFont); |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 305 | return newFont; |
| 306 | } |
| 307 | |
Jason Sams | b38d534 | 2010-10-21 14:06:55 -0700 | [diff] [blame] | 308 | ObjectBase::checkDelete(newFont); |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 309 | return NULL; |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 310 | } |
| 311 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 312 | Font::~Font() { |
| 313 | if (mFace) { |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 314 | FT_Done_Face(mFace); |
| 315 | } |
| 316 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 317 | for (uint32_t i = 0; i < mCachedGlyphs.size(); i ++) { |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 318 | CachedGlyphInfo *glyph = mCachedGlyphs.valueAt(i); |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 319 | delete glyph; |
| 320 | } |
| 321 | } |
| 322 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 323 | FontState::FontState() { |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 324 | mInitialized = false; |
| 325 | mMaxNumberOfQuads = 1024; |
| 326 | mCurrentQuadIndex = 0; |
| 327 | mRSC = NULL; |
Alex Sakhartchouk | b6b3489 | 2010-06-30 16:53:43 -0700 | [diff] [blame] | 328 | mLibrary = NULL; |
Alex Sakhartchouk | 3bf3ea0 | 2010-10-01 15:20:41 -0700 | [diff] [blame] | 329 | |
| 330 | // Get the renderer properties |
| 331 | char property[PROPERTY_VALUE_MAX]; |
| 332 | |
| 333 | // Get the gamma |
| 334 | float gamma = DEFAULT_TEXT_GAMMA; |
| 335 | if (property_get(PROPERTY_TEXT_GAMMA, property, NULL) > 0) { |
Alex Sakhartchouk | 3bf3ea0 | 2010-10-01 15:20:41 -0700 | [diff] [blame] | 336 | gamma = atof(property); |
Alex Sakhartchouk | 3bf3ea0 | 2010-10-01 15:20:41 -0700 | [diff] [blame] | 337 | } |
| 338 | |
| 339 | // Get the black gamma threshold |
Alex Sakhartchouk | 10825a0 | 2010-10-05 11:33:27 -0700 | [diff] [blame] | 340 | int32_t blackThreshold = DEFAULT_TEXT_BLACK_GAMMA_THRESHOLD; |
Alex Sakhartchouk | 3bf3ea0 | 2010-10-01 15:20:41 -0700 | [diff] [blame] | 341 | if (property_get(PROPERTY_TEXT_BLACK_GAMMA_THRESHOLD, property, NULL) > 0) { |
Alex Sakhartchouk | 3bf3ea0 | 2010-10-01 15:20:41 -0700 | [diff] [blame] | 342 | blackThreshold = atoi(property); |
Alex Sakhartchouk | 3bf3ea0 | 2010-10-01 15:20:41 -0700 | [diff] [blame] | 343 | } |
| 344 | mBlackThreshold = (float)(blackThreshold) / 255.0f; |
| 345 | |
| 346 | // Get the white gamma threshold |
Alex Sakhartchouk | 10825a0 | 2010-10-05 11:33:27 -0700 | [diff] [blame] | 347 | int32_t whiteThreshold = DEFAULT_TEXT_WHITE_GAMMA_THRESHOLD; |
Alex Sakhartchouk | 3bf3ea0 | 2010-10-01 15:20:41 -0700 | [diff] [blame] | 348 | if (property_get(PROPERTY_TEXT_WHITE_GAMMA_THRESHOLD, property, NULL) > 0) { |
Alex Sakhartchouk | 3bf3ea0 | 2010-10-01 15:20:41 -0700 | [diff] [blame] | 349 | whiteThreshold = atoi(property); |
Alex Sakhartchouk | 3bf3ea0 | 2010-10-01 15:20:41 -0700 | [diff] [blame] | 350 | } |
| 351 | mWhiteThreshold = (float)(whiteThreshold) / 255.0f; |
| 352 | |
| 353 | // Compute the gamma tables |
| 354 | mBlackGamma = gamma; |
| 355 | mWhiteGamma = 1.0f / gamma; |
Alex Sakhartchouk | 960ae15 | 2010-10-12 14:15:17 -0700 | [diff] [blame] | 356 | |
| 357 | setFontColor(0.1f, 0.1f, 0.1f, 1.0f); |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 358 | } |
| 359 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 360 | FontState::~FontState() { |
| 361 | for (uint32_t i = 0; i < mCacheLines.size(); i ++) { |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 362 | delete mCacheLines[i]; |
| 363 | } |
| 364 | |
| 365 | rsAssert(!mActiveFonts.size()); |
| 366 | } |
| 367 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 368 | FT_Library FontState::getLib() { |
| 369 | if (!mLibrary) { |
Alex Sakhartchouk | 071508d | 2010-06-30 12:49:27 -0700 | [diff] [blame] | 370 | FT_Error error = FT_Init_FreeType(&mLibrary); |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 371 | if (error) { |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 372 | LOGE("Unable to initialize freetype"); |
Alex Sakhartchouk | 071508d | 2010-06-30 12:49:27 -0700 | [diff] [blame] | 373 | return NULL; |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 374 | } |
| 375 | } |
Alex Sakhartchouk | b6b3489 | 2010-06-30 16:53:43 -0700 | [diff] [blame] | 376 | |
Alex Sakhartchouk | 071508d | 2010-06-30 12:49:27 -0700 | [diff] [blame] | 377 | return mLibrary; |
| 378 | } |
| 379 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 380 | void FontState::init(Context *rsc) { |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 381 | mRSC = rsc; |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 382 | } |
| 383 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 384 | void FontState::flushAllAndInvalidate() { |
| 385 | if (mCurrentQuadIndex != 0) { |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 386 | issueDrawCommand(); |
| 387 | mCurrentQuadIndex = 0; |
| 388 | } |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 389 | for (uint32_t i = 0; i < mActiveFonts.size(); i ++) { |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 390 | mActiveFonts[i]->invalidateTextureCache(); |
| 391 | } |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 392 | for (uint32_t i = 0; i < mCacheLines.size(); i ++) { |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 393 | mCacheLines[i]->mCurrentCol = 0; |
| 394 | } |
| 395 | } |
| 396 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 397 | bool FontState::cacheBitmap(FT_Bitmap *bitmap, uint32_t *retOriginX, uint32_t *retOriginY) { |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 398 | // If the glyph is too tall, don't cache it |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 399 | if ((uint32_t)bitmap->rows > mCacheLines[mCacheLines.size()-1]->mMaxHeight) { |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 400 | LOGE("Font size to large to fit in cache. width, height = %i, %i", (int)bitmap->width, (int)bitmap->rows); |
| 401 | return false; |
| 402 | } |
| 403 | |
| 404 | // Now copy the bitmap into the cache texture |
| 405 | uint32_t startX = 0; |
| 406 | uint32_t startY = 0; |
| 407 | |
| 408 | bool bitmapFit = false; |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 409 | for (uint32_t i = 0; i < mCacheLines.size(); i ++) { |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 410 | bitmapFit = mCacheLines[i]->fitBitmap(bitmap, &startX, &startY); |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 411 | if (bitmapFit) { |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 412 | break; |
| 413 | } |
| 414 | } |
| 415 | |
| 416 | // If the new glyph didn't fit, flush the state so far and invalidate everything |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 417 | if (!bitmapFit) { |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 418 | flushAllAndInvalidate(); |
| 419 | |
| 420 | // Try to fit it again |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 421 | for (uint32_t i = 0; i < mCacheLines.size(); i ++) { |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 422 | bitmapFit = mCacheLines[i]->fitBitmap(bitmap, &startX, &startY); |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 423 | if (bitmapFit) { |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 424 | break; |
| 425 | } |
| 426 | } |
| 427 | |
| 428 | // if we still don't fit, something is wrong and we shouldn't draw |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 429 | if (!bitmapFit) { |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 430 | LOGE("Bitmap doesn't fit in cache. width, height = %i, %i", (int)bitmap->width, (int)bitmap->rows); |
| 431 | return false; |
| 432 | } |
| 433 | } |
| 434 | |
| 435 | *retOriginX = startX; |
| 436 | *retOriginY = startY; |
| 437 | |
| 438 | uint32_t endX = startX + bitmap->width; |
| 439 | uint32_t endY = startY + bitmap->rows; |
| 440 | |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 441 | uint32_t cacheWidth = getCacheTextureType()->getDimX(); |
| 442 | |
Alex Sakhartchouk | 10825a0 | 2010-10-05 11:33:27 -0700 | [diff] [blame] | 443 | uint8_t *cacheBuffer = (uint8_t*)mTextTexture->getPtr(); |
| 444 | uint8_t *bitmapBuffer = bitmap->buffer; |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 445 | |
| 446 | uint32_t cacheX = 0, bX = 0, cacheY = 0, bY = 0; |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 447 | for (cacheX = startX, bX = 0; cacheX < endX; cacheX ++, bX ++) { |
| 448 | for (cacheY = startY, bY = 0; cacheY < endY; cacheY ++, bY ++) { |
Alex Sakhartchouk | 10825a0 | 2010-10-05 11:33:27 -0700 | [diff] [blame] | 449 | uint8_t tempCol = bitmapBuffer[bY * bitmap->width + bX]; |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 450 | cacheBuffer[cacheY*cacheWidth + cacheX] = tempCol; |
| 451 | } |
| 452 | } |
| 453 | |
| 454 | // This will dirty the texture and the shader so next time |
| 455 | // we draw it will upload the data |
Jason Sams | 6d8eb26 | 2010-12-15 01:41:00 -0800 | [diff] [blame] | 456 | mTextTexture->syncAll(mRSC, RS_ALLOCATION_USAGE_SCRIPT); |
Alex Sakhartchouk | b89aaac | 2010-09-23 16:16:33 -0700 | [diff] [blame] | 457 | mFontShaderF->bindTexture(mRSC, 0, mTextTexture.get()); |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 458 | |
| 459 | // Some debug code |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 460 | /*for (uint32_t i = 0; i < mCacheLines.size(); i ++) { |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 461 | LOGE("Cache Line: H: %u Empty Space: %f", |
| 462 | mCacheLines[i]->mMaxHeight, |
| 463 | (1.0f - (float)mCacheLines[i]->mCurrentCol/(float)mCacheLines[i]->mMaxWidth)*100.0f); |
| 464 | |
| 465 | }*/ |
| 466 | |
| 467 | return true; |
| 468 | } |
| 469 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 470 | void FontState::initRenderState() { |
Alex Sakhartchouk | d209163 | 2010-10-06 11:15:01 -0700 | [diff] [blame] | 471 | String8 shaderString("varying vec2 varTex0;\n"); |
Alex Sakhartchouk | c984dd7 | 2010-09-14 09:50:43 -0700 | [diff] [blame] | 472 | shaderString.append("void main() {\n"); |
| 473 | shaderString.append(" lowp vec4 col = UNI_Color;\n"); |
| 474 | shaderString.append(" col.a = texture2D(UNI_Tex0, varTex0.xy).a;\n"); |
Alex Sakhartchouk | 3bf3ea0 | 2010-10-01 15:20:41 -0700 | [diff] [blame] | 475 | shaderString.append(" col.a = pow(col.a, UNI_Gamma);\n"); |
Alex Sakhartchouk | c984dd7 | 2010-09-14 09:50:43 -0700 | [diff] [blame] | 476 | shaderString.append(" gl_FragColor = col;\n"); |
| 477 | shaderString.append("}\n"); |
| 478 | |
| 479 | const Element *colorElem = Element::create(mRSC, RS_TYPE_FLOAT_32, RS_KIND_USER, false, 4); |
Alex Sakhartchouk | 3bf3ea0 | 2010-10-01 15:20:41 -0700 | [diff] [blame] | 480 | const Element *gammaElem = Element::create(mRSC, RS_TYPE_FLOAT_32, RS_KIND_USER, false, 1); |
Alex Sakhartchouk | c984dd7 | 2010-09-14 09:50:43 -0700 | [diff] [blame] | 481 | mRSC->mStateElement.elementBuilderBegin(); |
| 482 | mRSC->mStateElement.elementBuilderAdd(colorElem, "Color", 1); |
Alex Sakhartchouk | 3bf3ea0 | 2010-10-01 15:20:41 -0700 | [diff] [blame] | 483 | mRSC->mStateElement.elementBuilderAdd(gammaElem, "Gamma", 1); |
Alex Sakhartchouk | c984dd7 | 2010-09-14 09:50:43 -0700 | [diff] [blame] | 484 | const Element *constInput = mRSC->mStateElement.elementBuilderCreate(mRSC); |
| 485 | |
Jason Sams | 31a7e42 | 2010-10-26 13:09:17 -0700 | [diff] [blame] | 486 | Type *inputType = Type::getType(mRSC, constInput, 1, 0, 0, false, false); |
Alex Sakhartchouk | c984dd7 | 2010-09-14 09:50:43 -0700 | [diff] [blame] | 487 | |
| 488 | uint32_t tmp[4]; |
| 489 | tmp[0] = RS_PROGRAM_PARAM_CONSTANT; |
| 490 | tmp[1] = (uint32_t)inputType; |
Alex Sakhartchouk | 67f2e44 | 2010-11-18 15:22:43 -0800 | [diff] [blame] | 491 | tmp[2] = RS_PROGRAM_PARAM_TEXTURE_TYPE; |
| 492 | tmp[3] = RS_TEXTURE_2D; |
Alex Sakhartchouk | c984dd7 | 2010-09-14 09:50:43 -0700 | [diff] [blame] | 493 | |
Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 494 | mFontShaderFConstant.set(new Allocation(mRSC, inputType, |
| 495 | RS_ALLOCATION_USAGE_SCRIPT | RS_ALLOCATION_USAGE_GRAPHICS_CONSTANTS)); |
Alex Sakhartchouk | c984dd7 | 2010-09-14 09:50:43 -0700 | [diff] [blame] | 496 | ProgramFragment *pf = new ProgramFragment(mRSC, shaderString.string(), |
| 497 | shaderString.length(), tmp, 4); |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 498 | mFontShaderF.set(pf); |
Alex Sakhartchouk | b89aaac | 2010-09-23 16:16:33 -0700 | [diff] [blame] | 499 | mFontShaderF->bindAllocation(mRSC, mFontShaderFConstant.get(), 0); |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 500 | |
| 501 | Sampler *sampler = new Sampler(mRSC, RS_SAMPLER_NEAREST, RS_SAMPLER_NEAREST, |
| 502 | RS_SAMPLER_CLAMP, RS_SAMPLER_CLAMP, RS_SAMPLER_CLAMP); |
| 503 | mFontSampler.set(sampler); |
Alex Sakhartchouk | b89aaac | 2010-09-23 16:16:33 -0700 | [diff] [blame] | 504 | mFontShaderF->bindSampler(mRSC, 0, sampler); |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 505 | |
| 506 | ProgramStore *fontStore = new ProgramStore(mRSC); |
| 507 | mFontProgramStore.set(fontStore); |
| 508 | mFontProgramStore->setDepthFunc(RS_DEPTH_FUNC_ALWAYS); |
| 509 | mFontProgramStore->setBlendFunc(RS_BLEND_SRC_SRC_ALPHA, RS_BLEND_DST_ONE_MINUS_SRC_ALPHA); |
| 510 | mFontProgramStore->setDitherEnable(false); |
| 511 | mFontProgramStore->setDepthMask(false); |
| 512 | } |
| 513 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 514 | void FontState::initTextTexture() { |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 515 | const Element *alphaElem = Element::create(mRSC, RS_TYPE_UNSIGNED_8, RS_KIND_PIXEL_A, true, 1); |
| 516 | |
| 517 | // We will allocate a texture to initially hold 32 character bitmaps |
Jason Sams | 31a7e42 | 2010-10-26 13:09:17 -0700 | [diff] [blame] | 518 | Type *texType = Type::getType(mRSC, alphaElem, 1024, 256, 0, false, false); |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 519 | |
Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 520 | Allocation *cacheAlloc = new Allocation(mRSC, texType, RS_ALLOCATION_USAGE_SCRIPT | RS_ALLOCATION_USAGE_GRAPHICS_TEXTURE); |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 521 | mTextTexture.set(cacheAlloc); |
Jason Sams | 6d8eb26 | 2010-12-15 01:41:00 -0800 | [diff] [blame] | 522 | mTextTexture->syncAll(mRSC, RS_ALLOCATION_USAGE_SCRIPT); |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 523 | |
| 524 | // Split up our cache texture into lines of certain widths |
Alex Sakhartchouk | 10825a0 | 2010-10-05 11:33:27 -0700 | [diff] [blame] | 525 | int32_t nextLine = 0; |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 526 | mCacheLines.push(new CacheTextureLine(16, texType->getDimX(), nextLine, 0)); |
| 527 | nextLine += mCacheLines.top()->mMaxHeight; |
| 528 | mCacheLines.push(new CacheTextureLine(24, texType->getDimX(), nextLine, 0)); |
| 529 | nextLine += mCacheLines.top()->mMaxHeight; |
Alex Sakhartchouk | 94bbccc | 2010-08-17 11:09:49 -0700 | [diff] [blame] | 530 | mCacheLines.push(new CacheTextureLine(24, texType->getDimX(), nextLine, 0)); |
| 531 | nextLine += mCacheLines.top()->mMaxHeight; |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 532 | mCacheLines.push(new CacheTextureLine(32, texType->getDimX(), nextLine, 0)); |
| 533 | nextLine += mCacheLines.top()->mMaxHeight; |
| 534 | mCacheLines.push(new CacheTextureLine(32, texType->getDimX(), nextLine, 0)); |
| 535 | nextLine += mCacheLines.top()->mMaxHeight; |
| 536 | mCacheLines.push(new CacheTextureLine(40, texType->getDimX(), nextLine, 0)); |
| 537 | nextLine += mCacheLines.top()->mMaxHeight; |
| 538 | mCacheLines.push(new CacheTextureLine(texType->getDimY() - nextLine, texType->getDimX(), nextLine, 0)); |
| 539 | } |
| 540 | |
| 541 | // Avoid having to reallocate memory and render quad by quad |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 542 | void FontState::initVertexArrayBuffers() { |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 543 | // Now lets write index data |
| 544 | const Element *indexElem = Element::create(mRSC, RS_TYPE_UNSIGNED_16, RS_KIND_USER, false, 1); |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 545 | uint32_t numIndicies = mMaxNumberOfQuads * 6; |
Jason Sams | 31a7e42 | 2010-10-26 13:09:17 -0700 | [diff] [blame] | 546 | Type *indexType = Type::getType(mRSC, indexElem, numIndicies, 0, 0, false, false); |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 547 | |
Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 548 | Allocation *indexAlloc = new Allocation(mRSC, indexType, RS_ALLOCATION_USAGE_SCRIPT | RS_ALLOCATION_USAGE_GRAPHICS_VERTEX); |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 549 | uint16_t *indexPtr = (uint16_t*)indexAlloc->getPtr(); |
| 550 | |
| 551 | // Four verts, two triangles , six indices per quad |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 552 | for (uint32_t i = 0; i < mMaxNumberOfQuads; i ++) { |
Alex Sakhartchouk | 10825a0 | 2010-10-05 11:33:27 -0700 | [diff] [blame] | 553 | int32_t i6 = i * 6; |
| 554 | int32_t i4 = i * 4; |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 555 | |
| 556 | indexPtr[i6 + 0] = i4 + 0; |
| 557 | indexPtr[i6 + 1] = i4 + 1; |
| 558 | indexPtr[i6 + 2] = i4 + 2; |
| 559 | |
| 560 | indexPtr[i6 + 3] = i4 + 0; |
| 561 | indexPtr[i6 + 4] = i4 + 2; |
| 562 | indexPtr[i6 + 5] = i4 + 3; |
| 563 | } |
| 564 | |
| 565 | indexAlloc->deferedUploadToBufferObject(mRSC); |
| 566 | mIndexBuffer.set(indexAlloc); |
| 567 | |
| 568 | const Element *posElem = Element::create(mRSC, RS_TYPE_FLOAT_32, RS_KIND_USER, false, 3); |
| 569 | const Element *texElem = Element::create(mRSC, RS_TYPE_FLOAT_32, RS_KIND_USER, false, 2); |
| 570 | |
Alex Sakhartchouk | 98bfe5d | 2010-10-18 17:18:50 -0700 | [diff] [blame] | 571 | mRSC->mStateElement.elementBuilderBegin(); |
| 572 | mRSC->mStateElement.elementBuilderAdd(posElem, "position", 1); |
| 573 | mRSC->mStateElement.elementBuilderAdd(texElem, "texture0", 1); |
| 574 | const Element *vertexDataElem = mRSC->mStateElement.elementBuilderCreate(mRSC); |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 575 | |
Jason Sams | 31a7e42 | 2010-10-26 13:09:17 -0700 | [diff] [blame] | 576 | Type *vertexDataType = Type::getType(mRSC, vertexDataElem, |
| 577 | mMaxNumberOfQuads * 4, |
| 578 | 0, 0, false, false); |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 579 | |
Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 580 | Allocation *vertexAlloc = new Allocation(mRSC, vertexDataType, RS_ALLOCATION_USAGE_SCRIPT | RS_ALLOCATION_USAGE_GRAPHICS_VERTEX); |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 581 | mTextMeshPtr = (float*)vertexAlloc->getPtr(); |
| 582 | |
| 583 | mVertexArray.set(vertexAlloc); |
| 584 | } |
| 585 | |
| 586 | // We don't want to allocate anything unless we actually draw text |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 587 | void FontState::checkInit() { |
| 588 | if (mInitialized) { |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 589 | return; |
| 590 | } |
| 591 | |
| 592 | initTextTexture(); |
| 593 | initRenderState(); |
| 594 | |
| 595 | initVertexArrayBuffers(); |
| 596 | |
Alex Sakhartchouk | 27f5052 | 2010-08-18 15:46:43 -0700 | [diff] [blame] | 597 | // We store a string with letters in a rough frequency of occurrence |
| 598 | mLatinPrecache = String8(" eisarntolcdugpmhbyfvkwzxjq"); |
| 599 | mLatinPrecache += String8("EISARNTOLCDUGPMHBYFVKWZXJQ"); |
| 600 | mLatinPrecache += String8(",.?!()-+@;:`'"); |
| 601 | mLatinPrecache += String8("0123456789"); |
| 602 | |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 603 | mInitialized = true; |
| 604 | } |
| 605 | |
| 606 | void FontState::issueDrawCommand() { |
Jason Sams | a17af04 | 2010-11-17 15:29:32 -0800 | [diff] [blame] | 607 | Context::PushState ps(mRSC); |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 608 | |
Jason Sams | a17af04 | 2010-11-17 15:29:32 -0800 | [diff] [blame] | 609 | mRSC->setProgramVertex(mRSC->getDefaultProgramVertex()); |
| 610 | mRSC->setProgramRaster(mRSC->getDefaultProgramRaster()); |
| 611 | mRSC->setProgramFragment(mFontShaderF.get()); |
| 612 | mRSC->setProgramStore(mFontProgramStore.get()); |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 613 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 614 | if (mConstantsDirty) { |
Jason Sams | 49a05d7 | 2010-12-29 14:31:29 -0800 | [diff] [blame] | 615 | mFontShaderFConstant->data(mRSC, 0, 0, 1, &mConstants, sizeof(mConstants)); |
Alex Sakhartchouk | 3bf3ea0 | 2010-10-01 15:20:41 -0700 | [diff] [blame] | 616 | mConstantsDirty = false; |
Alex Sakhartchouk | 55e8198 | 2010-08-05 11:24:14 -0700 | [diff] [blame] | 617 | } |
| 618 | |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 619 | if (!mRSC->setupCheck()) { |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 620 | return; |
| 621 | } |
| 622 | |
| 623 | float *vtx = (float*)mVertexArray->getPtr(); |
| 624 | float *tex = vtx + 3; |
| 625 | |
Alex Sakhartchouk | 9d71e21 | 2010-11-08 15:10:52 -0800 | [diff] [blame] | 626 | VertexArray::Attrib attribs[2]; |
| 627 | attribs[0].set(GL_FLOAT, 3, 20, false, (uint32_t)vtx, "ATTRIB_position"); |
| 628 | attribs[1].set(GL_FLOAT, 2, 20, false, (uint32_t)tex, "ATTRIB_texture0"); |
| 629 | VertexArray va(attribs, 2); |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 630 | va.setupGL2(mRSC, &mRSC->mStateVertexArray, &mRSC->mShaderCache); |
| 631 | |
| 632 | mIndexBuffer->uploadCheck(mRSC); |
| 633 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mIndexBuffer->getBufferObjectID()); |
| 634 | glDrawElements(GL_TRIANGLES, mCurrentQuadIndex * 6, GL_UNSIGNED_SHORT, (uint16_t *)(0)); |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 635 | } |
| 636 | |
| 637 | void FontState::appendMeshQuad(float x1, float y1, float z1, |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 638 | float u1, float v1, |
| 639 | float x2, float y2, float z2, |
| 640 | float u2, float v2, |
| 641 | float x3, float y3, float z3, |
| 642 | float u3, float v3, |
| 643 | float x4, float y4, float z4, |
| 644 | float u4, float v4) { |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 645 | const uint32_t vertsPerQuad = 4; |
| 646 | const uint32_t floatsPerVert = 5; |
| 647 | float *currentPos = mTextMeshPtr + mCurrentQuadIndex * vertsPerQuad * floatsPerVert; |
| 648 | |
| 649 | // Cull things that are off the screen |
| 650 | float width = (float)mRSC->getWidth(); |
| 651 | float height = (float)mRSC->getHeight(); |
| 652 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 653 | if (x1 > width || y1 < 0.0f || x2 < 0 || y4 > height) { |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 654 | return; |
| 655 | } |
| 656 | |
| 657 | /*LOGE("V0 x: %f y: %f z: %f", x1, y1, z1); |
| 658 | LOGE("V1 x: %f y: %f z: %f", x2, y2, z2); |
| 659 | LOGE("V2 x: %f y: %f z: %f", x3, y3, z3); |
| 660 | LOGE("V3 x: %f y: %f z: %f", x4, y4, z4);*/ |
| 661 | |
| 662 | (*currentPos++) = x1; |
| 663 | (*currentPos++) = y1; |
| 664 | (*currentPos++) = z1; |
| 665 | (*currentPos++) = u1; |
| 666 | (*currentPos++) = v1; |
| 667 | |
| 668 | (*currentPos++) = x2; |
| 669 | (*currentPos++) = y2; |
| 670 | (*currentPos++) = z2; |
| 671 | (*currentPos++) = u2; |
| 672 | (*currentPos++) = v2; |
| 673 | |
| 674 | (*currentPos++) = x3; |
| 675 | (*currentPos++) = y3; |
| 676 | (*currentPos++) = z3; |
| 677 | (*currentPos++) = u3; |
| 678 | (*currentPos++) = v3; |
| 679 | |
| 680 | (*currentPos++) = x4; |
| 681 | (*currentPos++) = y4; |
| 682 | (*currentPos++) = z4; |
| 683 | (*currentPos++) = u4; |
| 684 | (*currentPos++) = v4; |
| 685 | |
| 686 | mCurrentQuadIndex ++; |
| 687 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 688 | if (mCurrentQuadIndex == mMaxNumberOfQuads) { |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 689 | issueDrawCommand(); |
| 690 | mCurrentQuadIndex = 0; |
| 691 | } |
| 692 | } |
| 693 | |
Alex Sakhartchouk | 94bbccc | 2010-08-17 11:09:49 -0700 | [diff] [blame] | 694 | uint32_t FontState::getRemainingCacheCapacity() { |
| 695 | uint32_t remainingCapacity = 0; |
Alex Sakhartchouk | 27f5052 | 2010-08-18 15:46:43 -0700 | [diff] [blame] | 696 | uint32_t totalPixels = 0; |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 697 | for (uint32_t i = 0; i < mCacheLines.size(); i ++) { |
Alex Sakhartchouk | 94bbccc | 2010-08-17 11:09:49 -0700 | [diff] [blame] | 698 | remainingCapacity += (mCacheLines[i]->mMaxWidth - mCacheLines[i]->mCurrentCol); |
| 699 | totalPixels += mCacheLines[i]->mMaxWidth; |
| 700 | } |
| 701 | remainingCapacity = (remainingCapacity * 100) / totalPixels; |
| 702 | return remainingCapacity; |
| 703 | } |
| 704 | |
| 705 | void FontState::precacheLatin(Font *font) { |
| 706 | // Remaining capacity is measured in % |
| 707 | uint32_t remainingCapacity = getRemainingCacheCapacity(); |
| 708 | uint32_t precacheIdx = 0; |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 709 | while (remainingCapacity > 25 && precacheIdx < mLatinPrecache.size()) { |
Alex Sakhartchouk | 94bbccc | 2010-08-17 11:09:49 -0700 | [diff] [blame] | 710 | font->getCachedUTFChar((int32_t)mLatinPrecache[precacheIdx]); |
| 711 | remainingCapacity = getRemainingCacheCapacity(); |
| 712 | precacheIdx ++; |
| 713 | } |
| 714 | } |
| 715 | |
| 716 | |
Alex Sakhartchouk | 10825a0 | 2010-10-05 11:33:27 -0700 | [diff] [blame] | 717 | void FontState::renderText(const char *text, uint32_t len, int32_t x, int32_t y, |
| 718 | uint32_t startIndex, int32_t numGlyphs, |
| 719 | Font::RenderMode mode, |
| 720 | Font::Rect *bounds, |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 721 | uint8_t *bitmap, uint32_t bitmapW, uint32_t bitmapH) { |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 722 | checkInit(); |
| 723 | |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 724 | // Render code here |
| 725 | Font *currentFont = mRSC->getFont(); |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 726 | if (!currentFont) { |
| 727 | if (!mDefault.get()) { |
Alex Sakhartchouk | e27cdee | 2010-12-17 11:41:08 -0800 | [diff] [blame] | 728 | String8 fontsDir("/fonts/DroidSans.ttf"); |
| 729 | String8 fullPath(getenv("ANDROID_ROOT")); |
| 730 | fullPath += fontsDir; |
| 731 | |
| 732 | mDefault.set(Font::create(mRSC, fullPath.string(), 16, 96)); |
Alex Sakhartchouk | 071508d | 2010-06-30 12:49:27 -0700 | [diff] [blame] | 733 | } |
| 734 | currentFont = mDefault.get(); |
| 735 | } |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 736 | if (!currentFont) { |
Alex Sakhartchouk | b6b3489 | 2010-06-30 16:53:43 -0700 | [diff] [blame] | 737 | LOGE("Unable to initialize any fonts"); |
| 738 | return; |
| 739 | } |
| 740 | |
Alex Sakhartchouk | 10825a0 | 2010-10-05 11:33:27 -0700 | [diff] [blame] | 741 | currentFont->renderUTF(text, len, x, y, startIndex, numGlyphs, |
| 742 | mode, bounds, bitmap, bitmapW, bitmapH); |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 743 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 744 | if (mCurrentQuadIndex != 0) { |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 745 | issueDrawCommand(); |
| 746 | mCurrentQuadIndex = 0; |
| 747 | } |
| 748 | } |
| 749 | |
Alex Sakhartchouk | 10825a0 | 2010-10-05 11:33:27 -0700 | [diff] [blame] | 750 | void FontState::measureText(const char *text, uint32_t len, Font::Rect *bounds) { |
| 751 | renderText(text, len, 0, 0, 0, -1, Font::MEASURE, bounds); |
Alex Sakhartchouk | b0253ea | 2011-01-07 11:12:08 -0800 | [diff] [blame] | 752 | bounds->bottom = - bounds->bottom; |
| 753 | bounds->top = - bounds->top; |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 754 | } |
| 755 | |
Alex Sakhartchouk | fb10c16 | 2010-08-04 14:45:48 -0700 | [diff] [blame] | 756 | void FontState::setFontColor(float r, float g, float b, float a) { |
Alex Sakhartchouk | 3bf3ea0 | 2010-10-01 15:20:41 -0700 | [diff] [blame] | 757 | mConstants.mFontColor[0] = r; |
| 758 | mConstants.mFontColor[1] = g; |
| 759 | mConstants.mFontColor[2] = b; |
| 760 | mConstants.mFontColor[3] = a; |
| 761 | |
| 762 | mConstants.mGamma = 1.0f; |
Alex Sakhartchouk | 76322af | 2010-10-05 13:23:55 -0700 | [diff] [blame] | 763 | const float luminance = (r * 2.0f + g * 5.0f + b) / 8.0f; |
Alex Sakhartchouk | 3bf3ea0 | 2010-10-01 15:20:41 -0700 | [diff] [blame] | 764 | if (luminance <= mBlackThreshold) { |
| 765 | mConstants.mGamma = mBlackGamma; |
| 766 | } else if (luminance >= mWhiteThreshold) { |
| 767 | mConstants.mGamma = mWhiteGamma; |
| 768 | } |
Alex Sakhartchouk | 960ae15 | 2010-10-12 14:15:17 -0700 | [diff] [blame] | 769 | |
Alex Sakhartchouk | 3bf3ea0 | 2010-10-01 15:20:41 -0700 | [diff] [blame] | 770 | mConstantsDirty = true; |
Alex Sakhartchouk | fb10c16 | 2010-08-04 14:45:48 -0700 | [diff] [blame] | 771 | } |
| 772 | |
Alex Sakhartchouk | 55e8198 | 2010-08-05 11:24:14 -0700 | [diff] [blame] | 773 | void FontState::getFontColor(float *r, float *g, float *b, float *a) const { |
Alex Sakhartchouk | 3bf3ea0 | 2010-10-01 15:20:41 -0700 | [diff] [blame] | 774 | *r = mConstants.mFontColor[0]; |
| 775 | *g = mConstants.mFontColor[1]; |
| 776 | *b = mConstants.mFontColor[2]; |
| 777 | *a = mConstants.mFontColor[3]; |
Alex Sakhartchouk | 55e8198 | 2010-08-05 11:24:14 -0700 | [diff] [blame] | 778 | } |
| 779 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 780 | void FontState::deinit(Context *rsc) { |
Alex Sakhartchouk | 071508d | 2010-06-30 12:49:27 -0700 | [diff] [blame] | 781 | mInitialized = false; |
| 782 | |
Stephen Hines | 01f0ad7 | 2010-09-28 15:45:45 -0700 | [diff] [blame] | 783 | mFontShaderFConstant.clear(); |
| 784 | |
Alex Sakhartchouk | 071508d | 2010-06-30 12:49:27 -0700 | [diff] [blame] | 785 | mIndexBuffer.clear(); |
| 786 | mVertexArray.clear(); |
| 787 | |
| 788 | mFontShaderF.clear(); |
| 789 | mFontSampler.clear(); |
| 790 | mFontProgramStore.clear(); |
| 791 | |
| 792 | mTextTexture.clear(); |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 793 | for (uint32_t i = 0; i < mCacheLines.size(); i ++) { |
Alex Sakhartchouk | 071508d | 2010-06-30 12:49:27 -0700 | [diff] [blame] | 794 | delete mCacheLines[i]; |
| 795 | } |
| 796 | mCacheLines.clear(); |
| 797 | |
| 798 | mDefault.clear(); |
| 799 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 800 | if (mLibrary) { |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 801 | FT_Done_FreeType( mLibrary ); |
Alex Sakhartchouk | b6b3489 | 2010-06-30 16:53:43 -0700 | [diff] [blame] | 802 | mLibrary = NULL; |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 803 | } |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 804 | } |
| 805 | |
| 806 | namespace android { |
| 807 | namespace renderscript { |
| 808 | |
Alex Sakhartchouk | e27cdee | 2010-12-17 11:41:08 -0800 | [diff] [blame] | 809 | RsFont rsi_FontCreateFromFile(Context *rsc, char const *name, float fontSize, uint32_t dpi) { |
Alex Sakhartchouk | 071508d | 2010-06-30 12:49:27 -0700 | [diff] [blame] | 810 | Font *newFont = Font::create(rsc, name, fontSize, dpi); |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 811 | if (newFont) { |
Alex Sakhartchouk | 071508d | 2010-06-30 12:49:27 -0700 | [diff] [blame] | 812 | newFont->incUserRef(); |
| 813 | } |
| 814 | return newFont; |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 815 | } |
| 816 | |
Alex Sakhartchouk | b0253ea | 2011-01-07 11:12:08 -0800 | [diff] [blame] | 817 | RsFont rsi_FontCreateFromMemory(Context *rsc, char const *name, float fontSize, uint32_t dpi, const void *data, uint32_t dataLen) { |
| 818 | Font *newFont = Font::create(rsc, name, fontSize, dpi, data, dataLen); |
| 819 | if (newFont) { |
| 820 | newFont->incUserRef(); |
| 821 | } |
| 822 | return newFont; |
| 823 | } |
| 824 | |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 825 | } // renderscript |
| 826 | } // android |