Romain Guy | 694b519 | 2010-07-21 21:33:20 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 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 | |
Chris Craik | 96a5c4c | 2015-01-27 15:46:35 -0800 | [diff] [blame] | 17 | #include "FontRenderer.h" |
| 18 | |
Chris Craik | 5e00c7c | 2016-07-06 16:10:09 -0700 | [diff] [blame^] | 19 | #include "BakedOpDispatcher.h" |
| 20 | #include "BakedOpRenderer.h" |
| 21 | #include "BakedOpState.h" |
Chris Craik | 96a5c4c | 2015-01-27 15:46:35 -0800 | [diff] [blame] | 22 | #include "Caches.h" |
| 23 | #include "Debug.h" |
| 24 | #include "Extensions.h" |
Chris Craik | e2bb380 | 2015-03-13 15:07:52 -0700 | [diff] [blame] | 25 | #include "Glop.h" |
| 26 | #include "GlopBuilder.h" |
Chris Craik | 96a5c4c | 2015-01-27 15:46:35 -0800 | [diff] [blame] | 27 | #include "PixelBuffer.h" |
| 28 | #include "Rect.h" |
| 29 | #include "renderstate/RenderState.h" |
| 30 | #include "utils/Blur.h" |
| 31 | #include "utils/Timing.h" |
Romain Guy | 694b519 | 2010-07-21 21:33:20 -0700 | [diff] [blame] | 32 | |
Chris Craik | 9db58c0 | 2015-08-19 15:19:18 -0700 | [diff] [blame] | 33 | #include <algorithm> |
| 34 | #include <cutils/properties.h> |
Derek Sollenberger | ca79cf6 | 2012-08-14 16:44:52 -0400 | [diff] [blame] | 35 | #include <SkGlyph.h> |
Romain Guy | 694b519 | 2010-07-21 21:33:20 -0700 | [diff] [blame] | 36 | #include <SkUtils.h> |
Romain Guy | 51769a6 | 2010-07-23 00:28:00 -0700 | [diff] [blame] | 37 | #include <utils/Log.h> |
| 38 | |
Dan Morrill | e4d9a01 | 2013-03-28 18:10:43 -0700 | [diff] [blame] | 39 | #ifdef ANDROID_ENABLE_RENDERSCRIPT |
Romain Guy | 6e20040 | 2013-03-08 11:28:22 -0800 | [diff] [blame] | 40 | #include <RenderScript.h> |
Dan Morrill | e4d9a01 | 2013-03-28 18:10:43 -0700 | [diff] [blame] | 41 | #endif |
Chris Craik | f2d8ccc | 2013-02-13 16:14:17 -0800 | [diff] [blame] | 42 | |
Romain Guy | 694b519 | 2010-07-21 21:33:20 -0700 | [diff] [blame] | 43 | namespace android { |
| 44 | namespace uirenderer { |
| 45 | |
Chris Craik | f2d8ccc | 2013-02-13 16:14:17 -0800 | [diff] [blame] | 46 | // blur inputs smaller than this constant will bypass renderscript |
| 47 | #define RS_MIN_INPUT_CUTOFF 10000 |
| 48 | |
Romain Guy | 694b519 | 2010-07-21 21:33:20 -0700 | [diff] [blame] | 49 | /////////////////////////////////////////////////////////////////////////////// |
Victoria Lease | 1e54681 | 2013-06-25 14:25:17 -0700 | [diff] [blame] | 50 | // TextSetupFunctor |
| 51 | /////////////////////////////////////////////////////////////////////////////// |
Victoria Lease | 1e54681 | 2013-06-25 14:25:17 -0700 | [diff] [blame] | 52 | |
Chris Craik | 8284073 | 2015-04-03 09:37:49 -0700 | [diff] [blame] | 53 | void TextDrawFunctor::draw(CacheTexture& texture, bool linearFiltering) { |
Chris Craik | 53e51e4 | 2015-06-01 10:35:35 -0700 | [diff] [blame] | 54 | int textureFillFlags = TextureFillFlags::None; |
| 55 | if (texture.getFormat() == GL_ALPHA) { |
| 56 | textureFillFlags |= TextureFillFlags::IsAlphaMaskTexture; |
Chris Craik | e2bb380 | 2015-03-13 15:07:52 -0700 | [diff] [blame] | 57 | } |
Chris Craik | 53e51e4 | 2015-06-01 10:35:35 -0700 | [diff] [blame] | 58 | if (linearFiltering) { |
| 59 | textureFillFlags |= TextureFillFlags::ForceFilter; |
| 60 | } |
| 61 | int transformFlags = pureTranslate |
| 62 | ? TransformFlags::MeshIgnoresCanvasTransform : TransformFlags::None; |
Chris Craik | e2bb380 | 2015-03-13 15:07:52 -0700 | [diff] [blame] | 63 | Glop glop; |
Chris Craik | a171727 | 2015-11-19 13:02:43 -0800 | [diff] [blame] | 64 | GlopBuilder(renderer->renderState(), renderer->caches(), &glop) |
| 65 | .setRoundRectClipState(bakedState->roundRectClipState) |
| 66 | .setMeshTexturedIndexedQuads(texture.mesh(), texture.meshElementCount()) |
| 67 | .setFillTexturePaint(texture.getTexture(), textureFillFlags, paint, bakedState->alpha) |
| 68 | .setTransform(bakedState->computedState.transform, transformFlags) |
Chris Craik | f09ff5a | 2015-12-08 17:21:58 -0800 | [diff] [blame] | 69 | .setModelViewIdentityEmptyBounds() |
Chris Craik | a171727 | 2015-11-19 13:02:43 -0800 | [diff] [blame] | 70 | .build(); |
Chris Craik | 15c3f19 | 2015-12-03 12:16:56 -0800 | [diff] [blame] | 71 | // Note: don't pass dirty bounds here, so user must manage passing dirty bounds to renderer |
| 72 | renderer->renderGlop(nullptr, clip, glop); |
Victoria Lease | 1e54681 | 2013-06-25 14:25:17 -0700 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | /////////////////////////////////////////////////////////////////////////////// |
Romain Guy | 694b519 | 2010-07-21 21:33:20 -0700 | [diff] [blame] | 76 | // FontRenderer |
| 77 | /////////////////////////////////////////////////////////////////////////////// |
| 78 | |
Romain Guy | 514fb18 | 2011-01-19 14:38:29 -0800 | [diff] [blame] | 79 | static bool sLogFontRendererCreate = true; |
| 80 | |
Chris Craik | c08820f | 2015-09-22 14:22:29 -0700 | [diff] [blame] | 81 | FontRenderer::FontRenderer(const uint8_t* gammaTable) |
| 82 | : mGammaTable(gammaTable) |
Chris Craik | 083e733 | 2015-02-27 17:04:20 -0800 | [diff] [blame] | 83 | , mCurrentFont(nullptr) |
| 84 | , mActiveFonts(LruCache<Font::FontDescription, Font*>::kUnlimitedCapacity) |
| 85 | , mCurrentCacheTexture(nullptr) |
| 86 | , mUploadTexture(false) |
| 87 | , mFunctor(nullptr) |
| 88 | , mClip(nullptr) |
| 89 | , mBounds(nullptr) |
| 90 | , mDrawn(false) |
| 91 | , mInitialized(false) |
| 92 | , mLinearFiltering(false) { |
Romain Guy | e3a9b24 | 2013-01-08 11:15:30 -0800 | [diff] [blame] | 93 | |
Romain Guy | c9855a5 | 2011-01-21 21:14:15 -0800 | [diff] [blame] | 94 | if (sLogFontRendererCreate) { |
| 95 | INIT_LOGD("Creating FontRenderer"); |
| 96 | } |
Romain Guy | 51769a6 | 2010-07-23 00:28:00 -0700 | [diff] [blame] | 97 | |
Chris Craik | c08820f | 2015-09-22 14:22:29 -0700 | [diff] [blame] | 98 | mSmallCacheWidth = property_get_int32(PROPERTY_TEXT_SMALL_CACHE_WIDTH, |
| 99 | DEFAULT_TEXT_SMALL_CACHE_WIDTH); |
| 100 | mSmallCacheHeight = property_get_int32(PROPERTY_TEXT_SMALL_CACHE_HEIGHT, |
| 101 | DEFAULT_TEXT_SMALL_CACHE_HEIGHT); |
Romain Guy | 51769a6 | 2010-07-23 00:28:00 -0700 | [diff] [blame] | 102 | |
Chris Craik | c08820f | 2015-09-22 14:22:29 -0700 | [diff] [blame] | 103 | mLargeCacheWidth = property_get_int32(PROPERTY_TEXT_LARGE_CACHE_WIDTH, |
| 104 | DEFAULT_TEXT_LARGE_CACHE_WIDTH); |
| 105 | mLargeCacheHeight = property_get_int32(PROPERTY_TEXT_LARGE_CACHE_HEIGHT, |
| 106 | DEFAULT_TEXT_LARGE_CACHE_HEIGHT); |
Romain Guy | 9f5dab3 | 2012-09-04 12:55:44 -0700 | [diff] [blame] | 107 | |
| 108 | uint32_t maxTextureSize = (uint32_t) Caches::getInstance().maxTextureSize; |
Chris Craik | 083e733 | 2015-02-27 17:04:20 -0800 | [diff] [blame] | 109 | |
Chris Craik | 9db58c0 | 2015-08-19 15:19:18 -0700 | [diff] [blame] | 110 | mSmallCacheWidth = std::min(mSmallCacheWidth, maxTextureSize); |
| 111 | mSmallCacheHeight = std::min(mSmallCacheHeight, maxTextureSize); |
| 112 | mLargeCacheWidth = std::min(mLargeCacheWidth, maxTextureSize); |
| 113 | mLargeCacheHeight = std::min(mLargeCacheHeight, maxTextureSize); |
Romain Guy | 9f5dab3 | 2012-09-04 12:55:44 -0700 | [diff] [blame] | 114 | |
Chet Haase | eb32a49 | 2012-08-31 13:54:03 -0700 | [diff] [blame] | 115 | if (sLogFontRendererCreate) { |
| 116 | INIT_LOGD(" Text cache sizes, in pixels: %i x %i, %i x %i, %i x %i, %i x %i", |
| 117 | mSmallCacheWidth, mSmallCacheHeight, |
| 118 | mLargeCacheWidth, mLargeCacheHeight >> 1, |
| 119 | mLargeCacheWidth, mLargeCacheHeight >> 1, |
| 120 | mLargeCacheWidth, mLargeCacheHeight); |
Romain Guy | 51769a6 | 2010-07-23 00:28:00 -0700 | [diff] [blame] | 121 | } |
Romain Guy | 514fb18 | 2011-01-19 14:38:29 -0800 | [diff] [blame] | 122 | |
| 123 | sLogFontRendererCreate = false; |
Romain Guy | 694b519 | 2010-07-21 21:33:20 -0700 | [diff] [blame] | 124 | } |
| 125 | |
John Reck | 272a685 | 2015-07-29 16:48:58 -0700 | [diff] [blame] | 126 | void clearCacheTextures(std::vector<CacheTexture*>& cacheTextures) { |
Victoria Lease | 1e54681 | 2013-06-25 14:25:17 -0700 | [diff] [blame] | 127 | for (uint32_t i = 0; i < cacheTextures.size(); i++) { |
| 128 | delete cacheTextures[i]; |
Romain Guy | 694b519 | 2010-07-21 21:33:20 -0700 | [diff] [blame] | 129 | } |
Victoria Lease | 1e54681 | 2013-06-25 14:25:17 -0700 | [diff] [blame] | 130 | cacheTextures.clear(); |
| 131 | } |
| 132 | |
| 133 | FontRenderer::~FontRenderer() { |
| 134 | clearCacheTextures(mACacheTextures); |
| 135 | clearCacheTextures(mRGBACacheTextures); |
Romain Guy | 694b519 | 2010-07-21 21:33:20 -0700 | [diff] [blame] | 136 | |
Romain Guy | e3a9b24 | 2013-01-08 11:15:30 -0800 | [diff] [blame] | 137 | LruCache<Font::FontDescription, Font*>::Iterator it(mActiveFonts); |
| 138 | while (it.next()) { |
| 139 | delete it.value(); |
Romain Guy | 694b519 | 2010-07-21 21:33:20 -0700 | [diff] [blame] | 140 | } |
Romain Guy | e3a9b24 | 2013-01-08 11:15:30 -0800 | [diff] [blame] | 141 | mActiveFonts.clear(); |
Romain Guy | 694b519 | 2010-07-21 21:33:20 -0700 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | void FontRenderer::flushAllAndInvalidate() { |
Romain Guy | 661a87e | 2013-03-19 15:24:36 -0700 | [diff] [blame] | 145 | issueDrawCommand(); |
Romain Guy | 9d9758a | 2012-05-14 15:19:58 -0700 | [diff] [blame] | 146 | |
Romain Guy | e3a9b24 | 2013-01-08 11:15:30 -0800 | [diff] [blame] | 147 | LruCache<Font::FontDescription, Font*>::Iterator it(mActiveFonts); |
| 148 | while (it.next()) { |
| 149 | it.value()->invalidateTextureCache(); |
Romain Guy | 694b519 | 2010-07-21 21:33:20 -0700 | [diff] [blame] | 150 | } |
Romain Guy | 9d9758a | 2012-05-14 15:19:58 -0700 | [diff] [blame] | 151 | |
Victoria Lease | 1e54681 | 2013-06-25 14:25:17 -0700 | [diff] [blame] | 152 | for (uint32_t i = 0; i < mACacheTextures.size(); i++) { |
| 153 | mACacheTextures[i]->init(); |
| 154 | } |
| 155 | |
| 156 | for (uint32_t i = 0; i < mRGBACacheTextures.size(); i++) { |
| 157 | mRGBACacheTextures[i]->init(); |
Romain Guy | 694b519 | 2010-07-21 21:33:20 -0700 | [diff] [blame] | 158 | } |
chaochen | 1f61b19 | 2014-08-28 18:45:27 -0700 | [diff] [blame] | 159 | |
| 160 | mDrawn = false; |
Romain Guy | 694b519 | 2010-07-21 21:33:20 -0700 | [diff] [blame] | 161 | } |
| 162 | |
John Reck | 272a685 | 2015-07-29 16:48:58 -0700 | [diff] [blame] | 163 | void FontRenderer::flushLargeCaches(std::vector<CacheTexture*>& cacheTextures) { |
Chet Haase | 378e919 | 2012-08-15 15:54:54 -0700 | [diff] [blame] | 164 | // Start from 1; don't deallocate smallest/default texture |
Victoria Lease | 1e54681 | 2013-06-25 14:25:17 -0700 | [diff] [blame] | 165 | for (uint32_t i = 1; i < cacheTextures.size(); i++) { |
| 166 | CacheTexture* cacheTexture = cacheTextures[i]; |
Romain Guy | cf51a41 | 2013-04-08 19:40:31 -0700 | [diff] [blame] | 167 | if (cacheTexture->getPixelBuffer()) { |
Chet Haase | 378e919 | 2012-08-15 15:54:54 -0700 | [diff] [blame] | 168 | cacheTexture->init(); |
Romain Guy | e3a9b24 | 2013-01-08 11:15:30 -0800 | [diff] [blame] | 169 | LruCache<Font::FontDescription, Font*>::Iterator it(mActiveFonts); |
| 170 | while (it.next()) { |
| 171 | it.value()->invalidateTextureCache(cacheTexture); |
Chet Haase | e816bae | 2012-08-09 13:39:02 -0700 | [diff] [blame] | 172 | } |
Chris Craik | e2bb380 | 2015-03-13 15:07:52 -0700 | [diff] [blame] | 173 | cacheTexture->releasePixelBuffer(); |
Chet Haase | 9a82456 | 2011-12-16 15:44:59 -0800 | [diff] [blame] | 174 | } |
| 175 | } |
Chet Haase | 9a82456 | 2011-12-16 15:44:59 -0800 | [diff] [blame] | 176 | } |
| 177 | |
Victoria Lease | 1e54681 | 2013-06-25 14:25:17 -0700 | [diff] [blame] | 178 | void FontRenderer::flushLargeCaches() { |
| 179 | flushLargeCaches(mACacheTextures); |
| 180 | flushLargeCaches(mRGBACacheTextures); |
| 181 | } |
| 182 | |
John Reck | 272a685 | 2015-07-29 16:48:58 -0700 | [diff] [blame] | 183 | CacheTexture* FontRenderer::cacheBitmapInTexture(std::vector<CacheTexture*>& cacheTextures, |
Victoria Lease | 1e54681 | 2013-06-25 14:25:17 -0700 | [diff] [blame] | 184 | const SkGlyph& glyph, uint32_t* startX, uint32_t* startY) { |
| 185 | for (uint32_t i = 0; i < cacheTextures.size(); i++) { |
| 186 | if (cacheTextures[i]->fitBitmap(glyph, startX, startY)) { |
| 187 | return cacheTextures[i]; |
Chet Haase | 378e919 | 2012-08-15 15:54:54 -0700 | [diff] [blame] | 188 | } |
| 189 | } |
| 190 | // Could not fit glyph into current cache textures |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 191 | return nullptr; |
Chet Haase | 378e919 | 2012-08-15 15:54:54 -0700 | [diff] [blame] | 192 | } |
| 193 | |
Chet Haase | 7de0cb1 | 2011-12-05 16:35:38 -0800 | [diff] [blame] | 194 | void FontRenderer::cacheBitmap(const SkGlyph& glyph, CachedGlyphInfo* cachedGlyph, |
Chet Haase | f942cf1 | 2012-08-30 09:06:46 -0700 | [diff] [blame] | 195 | uint32_t* retOriginX, uint32_t* retOriginY, bool precaching) { |
Chet Haase | 2efd5c5 | 2012-08-15 13:15:16 -0700 | [diff] [blame] | 196 | checkInit(); |
Romain Guy | a4adcf0 | 2013-02-28 12:15:35 -0800 | [diff] [blame] | 197 | |
| 198 | // If the glyph bitmap is empty let's assum the glyph is valid |
| 199 | // so we can avoid doing extra work later on |
| 200 | if (glyph.fWidth == 0 || glyph.fHeight == 0) { |
| 201 | cachedGlyph->mIsValid = true; |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 202 | cachedGlyph->mCacheTexture = nullptr; |
Romain Guy | a4adcf0 | 2013-02-28 12:15:35 -0800 | [diff] [blame] | 203 | return; |
| 204 | } |
| 205 | |
Chet Haase | 7de0cb1 | 2011-12-05 16:35:38 -0800 | [diff] [blame] | 206 | cachedGlyph->mIsValid = false; |
Romain Guy | a4adcf0 | 2013-02-28 12:15:35 -0800 | [diff] [blame] | 207 | |
Victoria Lease | 1e54681 | 2013-06-25 14:25:17 -0700 | [diff] [blame] | 208 | // choose an appropriate cache texture list for this glyph format |
| 209 | SkMask::Format format = static_cast<SkMask::Format>(glyph.fMaskFormat); |
John Reck | 272a685 | 2015-07-29 16:48:58 -0700 | [diff] [blame] | 210 | std::vector<CacheTexture*>* cacheTextures = nullptr; |
Victoria Lease | 1e54681 | 2013-06-25 14:25:17 -0700 | [diff] [blame] | 211 | switch (format) { |
| 212 | case SkMask::kA8_Format: |
Victoria Lease | 723b2fe | 2013-08-12 14:38:44 -0700 | [diff] [blame] | 213 | case SkMask::kBW_Format: |
Victoria Lease | 1e54681 | 2013-06-25 14:25:17 -0700 | [diff] [blame] | 214 | cacheTextures = &mACacheTextures; |
| 215 | break; |
| 216 | case SkMask::kARGB32_Format: |
| 217 | cacheTextures = &mRGBACacheTextures; |
| 218 | break; |
| 219 | default: |
| 220 | #if DEBUG_FONT_RENDERER |
| 221 | ALOGD("getCacheTexturesForFormat: unknown SkMask format %x", format); |
| 222 | #endif |
| 223 | return; |
| 224 | } |
| 225 | |
Romain Guy | 694b519 | 2010-07-21 21:33:20 -0700 | [diff] [blame] | 226 | // If the glyph is too tall, don't cache it |
Chet Haase | 378e919 | 2012-08-15 15:54:54 -0700 | [diff] [blame] | 227 | if (glyph.fHeight + TEXTURE_BORDER_SIZE * 2 > |
Victoria Lease | 1e54681 | 2013-06-25 14:25:17 -0700 | [diff] [blame] | 228 | (*cacheTextures)[cacheTextures->size() - 1]->getHeight()) { |
Chet Haase | 2efd5c5 | 2012-08-15 13:15:16 -0700 | [diff] [blame] | 229 | ALOGE("Font size too large to fit in cache. width, height = %i, %i", |
| 230 | (int) glyph.fWidth, (int) glyph.fHeight); |
Chet Haase | 7de0cb1 | 2011-12-05 16:35:38 -0800 | [diff] [blame] | 231 | return; |
Romain Guy | 694b519 | 2010-07-21 21:33:20 -0700 | [diff] [blame] | 232 | } |
| 233 | |
| 234 | // Now copy the bitmap into the cache texture |
| 235 | uint32_t startX = 0; |
| 236 | uint32_t startY = 0; |
| 237 | |
Victoria Lease | 1e54681 | 2013-06-25 14:25:17 -0700 | [diff] [blame] | 238 | CacheTexture* cacheTexture = cacheBitmapInTexture(*cacheTextures, glyph, &startX, &startY); |
Romain Guy | 694b519 | 2010-07-21 21:33:20 -0700 | [diff] [blame] | 239 | |
Chet Haase | 378e919 | 2012-08-15 15:54:54 -0700 | [diff] [blame] | 240 | if (!cacheTexture) { |
Chet Haase | f942cf1 | 2012-08-30 09:06:46 -0700 | [diff] [blame] | 241 | if (!precaching) { |
| 242 | // If the new glyph didn't fit and we are not just trying to precache it, |
| 243 | // clear out the cache and try again |
| 244 | flushAllAndInvalidate(); |
Victoria Lease | 1e54681 | 2013-06-25 14:25:17 -0700 | [diff] [blame] | 245 | cacheTexture = cacheBitmapInTexture(*cacheTextures, glyph, &startX, &startY); |
Chet Haase | f942cf1 | 2012-08-30 09:06:46 -0700 | [diff] [blame] | 246 | } |
Romain Guy | 694b519 | 2010-07-21 21:33:20 -0700 | [diff] [blame] | 247 | |
Chet Haase | 378e919 | 2012-08-15 15:54:54 -0700 | [diff] [blame] | 248 | if (!cacheTexture) { |
Chet Haase | f942cf1 | 2012-08-30 09:06:46 -0700 | [diff] [blame] | 249 | // either the glyph didn't fit or we're precaching and will cache it when we draw |
Chet Haase | 7de0cb1 | 2011-12-05 16:35:38 -0800 | [diff] [blame] | 250 | return; |
Romain Guy | 694b519 | 2010-07-21 21:33:20 -0700 | [diff] [blame] | 251 | } |
| 252 | } |
| 253 | |
Chet Haase | 378e919 | 2012-08-15 15:54:54 -0700 | [diff] [blame] | 254 | cachedGlyph->mCacheTexture = cacheTexture; |
Chet Haase | 7de0cb1 | 2011-12-05 16:35:38 -0800 | [diff] [blame] | 255 | |
Romain Guy | 694b519 | 2010-07-21 21:33:20 -0700 | [diff] [blame] | 256 | *retOriginX = startX; |
| 257 | *retOriginY = startY; |
| 258 | |
| 259 | uint32_t endX = startX + glyph.fWidth; |
| 260 | uint32_t endY = startY + glyph.fHeight; |
| 261 | |
Romain Guy | 8087246 | 2012-09-04 16:42:01 -0700 | [diff] [blame] | 262 | uint32_t cacheWidth = cacheTexture->getWidth(); |
Romain Guy | 694b519 | 2010-07-21 21:33:20 -0700 | [diff] [blame] | 263 | |
Romain Guy | cf51a41 | 2013-04-08 19:40:31 -0700 | [diff] [blame] | 264 | if (!cacheTexture->getPixelBuffer()) { |
Chris Craik | 44eb2c0 | 2015-01-29 09:45:09 -0800 | [diff] [blame] | 265 | Caches::getInstance().textureState().activateTexture(0); |
Chet Haase | 7de0cb1 | 2011-12-05 16:35:38 -0800 | [diff] [blame] | 266 | // Large-glyph texture memory is allocated only as needed |
Chris Craik | e2bb380 | 2015-03-13 15:07:52 -0700 | [diff] [blame] | 267 | cacheTexture->allocatePixelBuffer(); |
Chet Haase | 7de0cb1 | 2011-12-05 16:35:38 -0800 | [diff] [blame] | 268 | } |
Romain Guy | 661a87e | 2013-03-19 15:24:36 -0700 | [diff] [blame] | 269 | if (!cacheTexture->mesh()) { |
| 270 | cacheTexture->allocateMesh(); |
| 271 | } |
Romain Guy | 9d9758a | 2012-05-14 15:19:58 -0700 | [diff] [blame] | 272 | |
Romain Guy | cf51a41 | 2013-04-08 19:40:31 -0700 | [diff] [blame] | 273 | uint8_t* cacheBuffer = cacheTexture->getPixelBuffer()->map(); |
Victoria Lease | 1e54681 | 2013-06-25 14:25:17 -0700 | [diff] [blame] | 274 | uint8_t* bitmapBuffer = (uint8_t*) glyph.fImage; |
| 275 | int srcStride = glyph.rowBytes(); |
Romain Guy | 33fa1f7 | 2012-08-07 19:09:57 -0700 | [diff] [blame] | 276 | |
Romain Guy | b969a0d | 2013-02-05 14:38:40 -0800 | [diff] [blame] | 277 | // Copy the glyph image, taking the mask format into account |
Romain Guy | b969a0d | 2013-02-05 14:38:40 -0800 | [diff] [blame] | 278 | switch (format) { |
| 279 | case SkMask::kA8_Format: { |
Victoria Lease | 1e54681 | 2013-06-25 14:25:17 -0700 | [diff] [blame] | 280 | uint32_t cacheX = 0, bX = 0, cacheY = 0, bY = 0; |
| 281 | uint32_t row = (startY - TEXTURE_BORDER_SIZE) * cacheWidth + startX |
| 282 | - TEXTURE_BORDER_SIZE; |
| 283 | // write leading border line |
| 284 | memset(&cacheBuffer[row], 0, glyph.fWidth + 2 * TEXTURE_BORDER_SIZE); |
| 285 | // write glyph data |
Romain Guy | b969a0d | 2013-02-05 14:38:40 -0800 | [diff] [blame] | 286 | if (mGammaTable) { |
Victoria Lease | 1e54681 | 2013-06-25 14:25:17 -0700 | [diff] [blame] | 287 | for (cacheY = startY, bY = 0; cacheY < endY; cacheY++, bY += srcStride) { |
Romain Guy | 0b58a3d | 2013-03-05 12:16:27 -0800 | [diff] [blame] | 288 | row = cacheY * cacheWidth; |
| 289 | cacheBuffer[row + startX - TEXTURE_BORDER_SIZE] = 0; |
Romain Guy | b969a0d | 2013-02-05 14:38:40 -0800 | [diff] [blame] | 290 | for (cacheX = startX, bX = 0; cacheX < endX; cacheX++, bX++) { |
| 291 | uint8_t tempCol = bitmapBuffer[bY + bX]; |
Romain Guy | 0b58a3d | 2013-03-05 12:16:27 -0800 | [diff] [blame] | 292 | cacheBuffer[row + cacheX] = mGammaTable[tempCol]; |
Romain Guy | b969a0d | 2013-02-05 14:38:40 -0800 | [diff] [blame] | 293 | } |
Romain Guy | 0b58a3d | 2013-03-05 12:16:27 -0800 | [diff] [blame] | 294 | cacheBuffer[row + endX + TEXTURE_BORDER_SIZE - 1] = 0; |
Romain Guy | b969a0d | 2013-02-05 14:38:40 -0800 | [diff] [blame] | 295 | } |
| 296 | } else { |
Victoria Lease | 1e54681 | 2013-06-25 14:25:17 -0700 | [diff] [blame] | 297 | for (cacheY = startY, bY = 0; cacheY < endY; cacheY++, bY += srcStride) { |
Romain Guy | 0b58a3d | 2013-03-05 12:16:27 -0800 | [diff] [blame] | 298 | row = cacheY * cacheWidth; |
| 299 | memcpy(&cacheBuffer[row + startX], &bitmapBuffer[bY], glyph.fWidth); |
| 300 | cacheBuffer[row + startX - TEXTURE_BORDER_SIZE] = 0; |
| 301 | cacheBuffer[row + endX + TEXTURE_BORDER_SIZE - 1] = 0; |
Romain Guy | b969a0d | 2013-02-05 14:38:40 -0800 | [diff] [blame] | 302 | } |
Romain Guy | b1d0a4e | 2012-07-13 18:25:35 -0700 | [diff] [blame] | 303 | } |
Victoria Lease | 1e54681 | 2013-06-25 14:25:17 -0700 | [diff] [blame] | 304 | // write trailing border line |
| 305 | row = (endY + TEXTURE_BORDER_SIZE - 1) * cacheWidth + startX - TEXTURE_BORDER_SIZE; |
| 306 | memset(&cacheBuffer[row], 0, glyph.fWidth + 2 * TEXTURE_BORDER_SIZE); |
| 307 | break; |
| 308 | } |
| 309 | case SkMask::kARGB32_Format: { |
| 310 | // prep data lengths |
| 311 | const size_t formatSize = PixelBuffer::formatSize(GL_RGBA); |
| 312 | const size_t borderSize = formatSize * TEXTURE_BORDER_SIZE; |
| 313 | size_t rowSize = formatSize * glyph.fWidth; |
| 314 | // prep advances |
| 315 | size_t dstStride = formatSize * cacheWidth; |
| 316 | // prep indices |
| 317 | // - we actually start one row early, and then increment before first copy |
| 318 | uint8_t* src = &bitmapBuffer[0 - srcStride]; |
| 319 | uint8_t* dst = &cacheBuffer[cacheTexture->getOffset(startX, startY - 1)]; |
| 320 | uint8_t* dstEnd = &cacheBuffer[cacheTexture->getOffset(startX, endY - 1)]; |
| 321 | uint8_t* dstL = dst - borderSize; |
| 322 | uint8_t* dstR = dst + rowSize; |
| 323 | // write leading border line |
| 324 | memset(dstL, 0, rowSize + 2 * borderSize); |
| 325 | // write glyph data |
| 326 | while (dst < dstEnd) { |
| 327 | memset(dstL += dstStride, 0, borderSize); // leading border column |
| 328 | memcpy(dst += dstStride, src += srcStride, rowSize); // glyph data |
| 329 | memset(dstR += dstStride, 0, borderSize); // trailing border column |
| 330 | } |
| 331 | // write trailing border line |
Victoria Lease | 16c8406 | 2013-09-19 15:38:21 -0700 | [diff] [blame] | 332 | memset(dstL += dstStride, 0, rowSize + 2 * borderSize); |
Romain Guy | b969a0d | 2013-02-05 14:38:40 -0800 | [diff] [blame] | 333 | break; |
Romain Guy | b1d0a4e | 2012-07-13 18:25:35 -0700 | [diff] [blame] | 334 | } |
Romain Guy | b969a0d | 2013-02-05 14:38:40 -0800 | [diff] [blame] | 335 | case SkMask::kBW_Format: { |
Andreas Gampe | 1e19674 | 2014-11-10 15:23:43 -0800 | [diff] [blame] | 336 | uint32_t cacheX = 0, cacheY = 0; |
Victoria Lease | 1e54681 | 2013-06-25 14:25:17 -0700 | [diff] [blame] | 337 | uint32_t row = (startY - TEXTURE_BORDER_SIZE) * cacheWidth + startX |
| 338 | - TEXTURE_BORDER_SIZE; |
Romain Guy | b969a0d | 2013-02-05 14:38:40 -0800 | [diff] [blame] | 339 | static const uint8_t COLORS[2] = { 0, 255 }; |
Victoria Lease | 1e54681 | 2013-06-25 14:25:17 -0700 | [diff] [blame] | 340 | // write leading border line |
| 341 | memset(&cacheBuffer[row], 0, glyph.fWidth + 2 * TEXTURE_BORDER_SIZE); |
| 342 | // write glyph data |
Romain Guy | b969a0d | 2013-02-05 14:38:40 -0800 | [diff] [blame] | 343 | for (cacheY = startY; cacheY < endY; cacheY++) { |
| 344 | cacheX = startX; |
Victoria Lease | 1e54681 | 2013-06-25 14:25:17 -0700 | [diff] [blame] | 345 | int rowBytes = srcStride; |
Romain Guy | b969a0d | 2013-02-05 14:38:40 -0800 | [diff] [blame] | 346 | uint8_t* buffer = bitmapBuffer; |
| 347 | |
Romain Guy | 0b58a3d | 2013-03-05 12:16:27 -0800 | [diff] [blame] | 348 | row = cacheY * cacheWidth; |
| 349 | cacheBuffer[row + startX - TEXTURE_BORDER_SIZE] = 0; |
Romain Guy | b969a0d | 2013-02-05 14:38:40 -0800 | [diff] [blame] | 350 | while (--rowBytes >= 0) { |
| 351 | uint8_t b = *buffer++; |
| 352 | for (int8_t mask = 7; mask >= 0 && cacheX < endX; mask--) { |
| 353 | cacheBuffer[cacheY * cacheWidth + cacheX++] = COLORS[(b >> mask) & 0x1]; |
| 354 | } |
| 355 | } |
Romain Guy | 0b58a3d | 2013-03-05 12:16:27 -0800 | [diff] [blame] | 356 | cacheBuffer[row + endX + TEXTURE_BORDER_SIZE - 1] = 0; |
Romain Guy | b969a0d | 2013-02-05 14:38:40 -0800 | [diff] [blame] | 357 | |
Victoria Lease | 1e54681 | 2013-06-25 14:25:17 -0700 | [diff] [blame] | 358 | bitmapBuffer += srcStride; |
Romain Guy | b1d0a4e | 2012-07-13 18:25:35 -0700 | [diff] [blame] | 359 | } |
Victoria Lease | 1e54681 | 2013-06-25 14:25:17 -0700 | [diff] [blame] | 360 | // write trailing border line |
| 361 | row = (endY + TEXTURE_BORDER_SIZE - 1) * cacheWidth + startX - TEXTURE_BORDER_SIZE; |
| 362 | memset(&cacheBuffer[row], 0, glyph.fWidth + 2 * TEXTURE_BORDER_SIZE); |
Romain Guy | b969a0d | 2013-02-05 14:38:40 -0800 | [diff] [blame] | 363 | break; |
Romain Guy | 694b519 | 2010-07-21 21:33:20 -0700 | [diff] [blame] | 364 | } |
Romain Guy | b969a0d | 2013-02-05 14:38:40 -0800 | [diff] [blame] | 365 | default: |
Victoria Lease | 1e54681 | 2013-06-25 14:25:17 -0700 | [diff] [blame] | 366 | ALOGW("Unknown glyph format: 0x%x", format); |
Romain Guy | b969a0d | 2013-02-05 14:38:40 -0800 | [diff] [blame] | 367 | break; |
Romain Guy | 694b519 | 2010-07-21 21:33:20 -0700 | [diff] [blame] | 368 | } |
Romain Guy | 9777173 | 2012-02-28 18:17:02 -0800 | [diff] [blame] | 369 | |
Chet Haase | 7de0cb1 | 2011-12-05 16:35:38 -0800 | [diff] [blame] | 370 | cachedGlyph->mIsValid = true; |
Romain Guy | 694b519 | 2010-07-21 21:33:20 -0700 | [diff] [blame] | 371 | } |
| 372 | |
Victoria Lease | 1e54681 | 2013-06-25 14:25:17 -0700 | [diff] [blame] | 373 | CacheTexture* FontRenderer::createCacheTexture(int width, int height, GLenum format, |
| 374 | bool allocate) { |
Chris Craik | 96a5c4c | 2015-01-27 15:46:35 -0800 | [diff] [blame] | 375 | CacheTexture* cacheTexture = new CacheTexture(width, height, format, kMaxNumberOfQuads); |
Romain Guy | 9d9758a | 2012-05-14 15:19:58 -0700 | [diff] [blame] | 376 | |
Chet Haase | 2a47c14 | 2011-12-14 15:22:56 -0800 | [diff] [blame] | 377 | if (allocate) { |
Chris Craik | 44eb2c0 | 2015-01-29 09:45:09 -0800 | [diff] [blame] | 378 | Caches::getInstance().textureState().activateTexture(0); |
Chris Craik | e2bb380 | 2015-03-13 15:07:52 -0700 | [diff] [blame] | 379 | cacheTexture->allocatePixelBuffer(); |
Romain Guy | 661a87e | 2013-03-19 15:24:36 -0700 | [diff] [blame] | 380 | cacheTexture->allocateMesh(); |
Chet Haase | 2a47c14 | 2011-12-14 15:22:56 -0800 | [diff] [blame] | 381 | } |
Romain Guy | 9d9758a | 2012-05-14 15:19:58 -0700 | [diff] [blame] | 382 | |
Chet Haase | 2a47c14 | 2011-12-14 15:22:56 -0800 | [diff] [blame] | 383 | return cacheTexture; |
Chet Haase | 7de0cb1 | 2011-12-05 16:35:38 -0800 | [diff] [blame] | 384 | } |
| 385 | |
| 386 | void FontRenderer::initTextTexture() { |
Victoria Lease | 1e54681 | 2013-06-25 14:25:17 -0700 | [diff] [blame] | 387 | clearCacheTextures(mACacheTextures); |
| 388 | clearCacheTextures(mRGBACacheTextures); |
Romain Guy | 9d9758a | 2012-05-14 15:19:58 -0700 | [diff] [blame] | 389 | |
Chet Haase | 7de0cb1 | 2011-12-05 16:35:38 -0800 | [diff] [blame] | 390 | mUploadTexture = false; |
John Reck | 272a685 | 2015-07-29 16:48:58 -0700 | [diff] [blame] | 391 | mACacheTextures.push_back(createCacheTexture(mSmallCacheWidth, mSmallCacheHeight, |
Victoria Lease | 1e54681 | 2013-06-25 14:25:17 -0700 | [diff] [blame] | 392 | GL_ALPHA, true)); |
John Reck | 272a685 | 2015-07-29 16:48:58 -0700 | [diff] [blame] | 393 | mACacheTextures.push_back(createCacheTexture(mLargeCacheWidth, mLargeCacheHeight >> 1, |
Victoria Lease | 1e54681 | 2013-06-25 14:25:17 -0700 | [diff] [blame] | 394 | GL_ALPHA, false)); |
John Reck | 272a685 | 2015-07-29 16:48:58 -0700 | [diff] [blame] | 395 | mACacheTextures.push_back(createCacheTexture(mLargeCacheWidth, mLargeCacheHeight >> 1, |
Victoria Lease | 1e54681 | 2013-06-25 14:25:17 -0700 | [diff] [blame] | 396 | GL_ALPHA, false)); |
John Reck | 272a685 | 2015-07-29 16:48:58 -0700 | [diff] [blame] | 397 | mACacheTextures.push_back(createCacheTexture(mLargeCacheWidth, mLargeCacheHeight, |
Victoria Lease | 1e54681 | 2013-06-25 14:25:17 -0700 | [diff] [blame] | 398 | GL_ALPHA, false)); |
John Reck | 272a685 | 2015-07-29 16:48:58 -0700 | [diff] [blame] | 399 | mRGBACacheTextures.push_back(createCacheTexture(mSmallCacheWidth, mSmallCacheHeight, |
Victoria Lease | 1e54681 | 2013-06-25 14:25:17 -0700 | [diff] [blame] | 400 | GL_RGBA, false)); |
John Reck | 272a685 | 2015-07-29 16:48:58 -0700 | [diff] [blame] | 401 | mRGBACacheTextures.push_back(createCacheTexture(mLargeCacheWidth, mLargeCacheHeight >> 1, |
Victoria Lease | 1e54681 | 2013-06-25 14:25:17 -0700 | [diff] [blame] | 402 | GL_RGBA, false)); |
| 403 | mCurrentCacheTexture = mACacheTextures[0]; |
Romain Guy | 694b519 | 2010-07-21 21:33:20 -0700 | [diff] [blame] | 404 | } |
| 405 | |
Romain Guy | 694b519 | 2010-07-21 21:33:20 -0700 | [diff] [blame] | 406 | // We don't want to allocate anything unless we actually draw text |
| 407 | void FontRenderer::checkInit() { |
| 408 | if (mInitialized) { |
| 409 | return; |
| 410 | } |
| 411 | |
| 412 | initTextTexture(); |
Romain Guy | 694b519 | 2010-07-21 21:33:20 -0700 | [diff] [blame] | 413 | |
| 414 | mInitialized = true; |
| 415 | } |
| 416 | |
John Reck | 272a685 | 2015-07-29 16:48:58 -0700 | [diff] [blame] | 417 | void checkTextureUpdateForCache(Caches& caches, std::vector<CacheTexture*>& cacheTextures, |
Victoria Lease | 1e54681 | 2013-06-25 14:25:17 -0700 | [diff] [blame] | 418 | bool& resetPixelStore, GLuint& lastTextureId) { |
| 419 | for (uint32_t i = 0; i < cacheTextures.size(); i++) { |
| 420 | CacheTexture* cacheTexture = cacheTextures[i]; |
| 421 | if (cacheTexture->isDirty() && cacheTexture->getPixelBuffer()) { |
| 422 | if (cacheTexture->getTextureId() != lastTextureId) { |
| 423 | lastTextureId = cacheTexture->getTextureId(); |
Chris Craik | 44eb2c0 | 2015-01-29 09:45:09 -0800 | [diff] [blame] | 424 | caches.textureState().activateTexture(0); |
| 425 | caches.textureState().bindTexture(lastTextureId); |
Victoria Lease | 1e54681 | 2013-06-25 14:25:17 -0700 | [diff] [blame] | 426 | } |
| 427 | |
| 428 | if (cacheTexture->upload()) { |
| 429 | resetPixelStore = true; |
| 430 | } |
| 431 | } |
| 432 | } |
| 433 | } |
| 434 | |
Alex Sakhartchouk | 9b9902d | 2010-07-23 14:45:49 -0700 | [diff] [blame] | 435 | void FontRenderer::checkTextureUpdate() { |
Sangkyu Lee | 7bb3cfe | 2012-11-16 00:03:17 +0900 | [diff] [blame] | 436 | if (!mUploadTexture) { |
Alex Sakhartchouk | 9b9902d | 2010-07-23 14:45:49 -0700 | [diff] [blame] | 437 | return; |
Romain Guy | 694b519 | 2010-07-21 21:33:20 -0700 | [diff] [blame] | 438 | } |
| 439 | |
Romain Guy | 2d4fd36 | 2011-12-13 22:00:19 -0800 | [diff] [blame] | 440 | Caches& caches = Caches::getInstance(); |
| 441 | GLuint lastTextureId = 0; |
Romain Guy | 0908764 | 2013-04-04 12:27:54 -0700 | [diff] [blame] | 442 | |
Romain Guy | cf51a41 | 2013-04-08 19:40:31 -0700 | [diff] [blame] | 443 | bool resetPixelStore = false; |
Romain Guy | 0908764 | 2013-04-04 12:27:54 -0700 | [diff] [blame] | 444 | |
Chet Haase | 378e919 | 2012-08-15 15:54:54 -0700 | [diff] [blame] | 445 | // Iterate over all the cache textures and see which ones need to be updated |
Victoria Lease | 1e54681 | 2013-06-25 14:25:17 -0700 | [diff] [blame] | 446 | checkTextureUpdateForCache(caches, mACacheTextures, resetPixelStore, lastTextureId); |
| 447 | checkTextureUpdateForCache(caches, mRGBACacheTextures, resetPixelStore, lastTextureId); |
Alex Sakhartchouk | 9b9902d | 2010-07-23 14:45:49 -0700 | [diff] [blame] | 448 | |
Romain Guy | cf51a41 | 2013-04-08 19:40:31 -0700 | [diff] [blame] | 449 | // Unbind any PBO we might have used to update textures |
Chris Craik | 44eb2c0 | 2015-01-29 09:45:09 -0800 | [diff] [blame] | 450 | caches.pixelBufferState().unbind(); |
Romain Guy | cf51a41 | 2013-04-08 19:40:31 -0700 | [diff] [blame] | 451 | |
Romain Guy | 0908764 | 2013-04-04 12:27:54 -0700 | [diff] [blame] | 452 | // Reset to default unpack row length to avoid affecting texture |
| 453 | // uploads in other parts of the renderer |
Romain Guy | cf51a41 | 2013-04-08 19:40:31 -0700 | [diff] [blame] | 454 | if (resetPixelStore) { |
Romain Guy | 0908764 | 2013-04-04 12:27:54 -0700 | [diff] [blame] | 455 | glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); |
| 456 | } |
| 457 | |
Alex Sakhartchouk | 9b9902d | 2010-07-23 14:45:49 -0700 | [diff] [blame] | 458 | mUploadTexture = false; |
| 459 | } |
| 460 | |
John Reck | 272a685 | 2015-07-29 16:48:58 -0700 | [diff] [blame] | 461 | void FontRenderer::issueDrawCommand(std::vector<CacheTexture*>& cacheTextures) { |
Chris Craik | 96a5c4c | 2015-01-27 15:46:35 -0800 | [diff] [blame] | 462 | if (!mFunctor) return; |
| 463 | |
Romain Guy | 661a87e | 2013-03-19 15:24:36 -0700 | [diff] [blame] | 464 | bool first = true; |
Victoria Lease | 1e54681 | 2013-06-25 14:25:17 -0700 | [diff] [blame] | 465 | for (uint32_t i = 0; i < cacheTextures.size(); i++) { |
| 466 | CacheTexture* texture = cacheTextures[i]; |
Romain Guy | 661a87e | 2013-03-19 15:24:36 -0700 | [diff] [blame] | 467 | if (texture->canDraw()) { |
| 468 | if (first) { |
Chris Craik | e2bb380 | 2015-03-13 15:07:52 -0700 | [diff] [blame] | 469 | checkTextureUpdate(); |
Romain Guy | 661a87e | 2013-03-19 15:24:36 -0700 | [diff] [blame] | 470 | first = false; |
Chris Craik | 083e733 | 2015-02-27 17:04:20 -0800 | [diff] [blame] | 471 | mDrawn = true; |
Romain Guy | 661a87e | 2013-03-19 15:24:36 -0700 | [diff] [blame] | 472 | } |
Chris Craik | 8284073 | 2015-04-03 09:37:49 -0700 | [diff] [blame] | 473 | |
Chris Craik | e2bb380 | 2015-03-13 15:07:52 -0700 | [diff] [blame] | 474 | mFunctor->draw(*texture, mLinearFiltering); |
Romain Guy | 661a87e | 2013-03-19 15:24:36 -0700 | [diff] [blame] | 475 | |
Romain Guy | 661a87e | 2013-03-19 15:24:36 -0700 | [diff] [blame] | 476 | texture->resetMesh(); |
Romain Guy | 115096f | 2013-03-19 11:32:41 -0700 | [diff] [blame] | 477 | } |
Sangkyu Lee | 7bb3cfe | 2012-11-16 00:03:17 +0900 | [diff] [blame] | 478 | } |
Victoria Lease | 1e54681 | 2013-06-25 14:25:17 -0700 | [diff] [blame] | 479 | } |
| 480 | |
| 481 | void FontRenderer::issueDrawCommand() { |
| 482 | issueDrawCommand(mACacheTextures); |
| 483 | issueDrawCommand(mRGBACacheTextures); |
Romain Guy | 694b519 | 2010-07-21 21:33:20 -0700 | [diff] [blame] | 484 | } |
| 485 | |
Romain Guy | 9777173 | 2012-02-28 18:17:02 -0800 | [diff] [blame] | 486 | void FontRenderer::appendMeshQuadNoClip(float x1, float y1, float u1, float v1, |
| 487 | float x2, float y2, float u2, float v2, float x3, float y3, float u3, float v3, |
Chet Haase | 7de0cb1 | 2011-12-05 16:35:38 -0800 | [diff] [blame] | 488 | float x4, float y4, float u4, float v4, CacheTexture* texture) { |
Chet Haase | 7de0cb1 | 2011-12-05 16:35:38 -0800 | [diff] [blame] | 489 | if (texture != mCurrentCacheTexture) { |
Chet Haase | 7de0cb1 | 2011-12-05 16:35:38 -0800 | [diff] [blame] | 490 | // Now use the new texture id |
| 491 | mCurrentCacheTexture = texture; |
| 492 | } |
Romain Guy | 09147fb | 2010-07-22 13:08:20 -0700 | [diff] [blame] | 493 | |
Romain Guy | 661a87e | 2013-03-19 15:24:36 -0700 | [diff] [blame] | 494 | mCurrentCacheTexture->addQuad(x1, y1, u1, v1, x2, y2, u2, v2, |
| 495 | x3, y3, u3, v3, x4, y4, u4, v4); |
Romain Guy | 9777173 | 2012-02-28 18:17:02 -0800 | [diff] [blame] | 496 | } |
| 497 | |
| 498 | void FontRenderer::appendMeshQuad(float x1, float y1, float u1, float v1, |
| 499 | float x2, float y2, float u2, float v2, float x3, float y3, float u3, float v3, |
| 500 | float x4, float y4, float u4, float v4, CacheTexture* texture) { |
| 501 | |
| 502 | if (mClip && |
| 503 | (x1 > mClip->right || y1 < mClip->top || x2 < mClip->left || y4 > mClip->bottom)) { |
| 504 | return; |
| 505 | } |
| 506 | |
| 507 | appendMeshQuadNoClip(x1, y1, u1, v1, x2, y2, u2, v2, x3, y3, u3, v3, x4, y4, u4, v4, texture); |
Romain Guy | 694b519 | 2010-07-21 21:33:20 -0700 | [diff] [blame] | 508 | |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 509 | if (mBounds) { |
Chris Craik | e6a15ee | 2015-07-07 18:42:17 -0700 | [diff] [blame] | 510 | mBounds->left = std::min(mBounds->left, x1); |
| 511 | mBounds->top = std::min(mBounds->top, y3); |
| 512 | mBounds->right = std::max(mBounds->right, x3); |
| 513 | mBounds->bottom = std::max(mBounds->bottom, y1); |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 514 | } |
| 515 | |
Romain Guy | 661a87e | 2013-03-19 15:24:36 -0700 | [diff] [blame] | 516 | if (mCurrentCacheTexture->endOfMesh()) { |
Romain Guy | 694b519 | 2010-07-21 21:33:20 -0700 | [diff] [blame] | 517 | issueDrawCommand(); |
Romain Guy | 694b519 | 2010-07-21 21:33:20 -0700 | [diff] [blame] | 518 | } |
| 519 | } |
| 520 | |
Romain Guy | 9777173 | 2012-02-28 18:17:02 -0800 | [diff] [blame] | 521 | void FontRenderer::appendRotatedMeshQuad(float x1, float y1, float u1, float v1, |
| 522 | float x2, float y2, float u2, float v2, float x3, float y3, float u3, float v3, |
| 523 | float x4, float y4, float u4, float v4, CacheTexture* texture) { |
| 524 | |
| 525 | appendMeshQuadNoClip(x1, y1, u1, v1, x2, y2, u2, v2, x3, y3, u3, v3, x4, y4, u4, v4, texture); |
| 526 | |
| 527 | if (mBounds) { |
Chris Craik | e6a15ee | 2015-07-07 18:42:17 -0700 | [diff] [blame] | 528 | mBounds->left = std::min(mBounds->left, std::min(x1, std::min(x2, std::min(x3, x4)))); |
| 529 | mBounds->top = std::min(mBounds->top, std::min(y1, std::min(y2, std::min(y3, y4)))); |
| 530 | mBounds->right = std::max(mBounds->right, std::max(x1, std::max(x2, std::max(x3, x4)))); |
| 531 | mBounds->bottom = std::max(mBounds->bottom, std::max(y1, std::max(y2, std::max(y3, y4)))); |
Romain Guy | 9777173 | 2012-02-28 18:17:02 -0800 | [diff] [blame] | 532 | } |
| 533 | |
Romain Guy | 661a87e | 2013-03-19 15:24:36 -0700 | [diff] [blame] | 534 | if (mCurrentCacheTexture->endOfMesh()) { |
Romain Guy | 9777173 | 2012-02-28 18:17:02 -0800 | [diff] [blame] | 535 | issueDrawCommand(); |
Romain Guy | 9777173 | 2012-02-28 18:17:02 -0800 | [diff] [blame] | 536 | } |
| 537 | } |
| 538 | |
Chris Craik | 59744b7 | 2014-07-01 17:56:52 -0700 | [diff] [blame] | 539 | void FontRenderer::setFont(const SkPaint* paint, const SkMatrix& matrix) { |
Romain Guy | e3a9b24 | 2013-01-08 11:15:30 -0800 | [diff] [blame] | 540 | mCurrentFont = Font::create(this, paint, matrix); |
Romain Guy | 694b519 | 2010-07-21 21:33:20 -0700 | [diff] [blame] | 541 | } |
Romain Guy | 7975fb6 | 2010-10-01 16:36:14 -0700 | [diff] [blame] | 542 | |
Chris Craik | e8c3c81 | 2016-02-05 20:10:50 -0800 | [diff] [blame] | 543 | FontRenderer::DropShadow FontRenderer::renderDropShadow(const SkPaint* paint, const glyph_t *glyphs, |
Chris Craik | a171727 | 2015-11-19 13:02:43 -0800 | [diff] [blame] | 544 | int numGlyphs, float radius, const float* positions) { |
Romain Guy | 1e45aae | 2010-08-13 19:39:53 -0700 | [diff] [blame] | 545 | checkInit(); |
| 546 | |
Romain Guy | cf51a41 | 2013-04-08 19:40:31 -0700 | [diff] [blame] | 547 | DropShadow image; |
| 548 | image.width = 0; |
| 549 | image.height = 0; |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 550 | image.image = nullptr; |
Romain Guy | cf51a41 | 2013-04-08 19:40:31 -0700 | [diff] [blame] | 551 | image.penX = 0; |
| 552 | image.penY = 0; |
| 553 | |
Romain Guy | 1e45aae | 2010-08-13 19:39:53 -0700 | [diff] [blame] | 554 | if (!mCurrentFont) { |
Romain Guy | 1e45aae | 2010-08-13 19:39:53 -0700 | [diff] [blame] | 555 | return image; |
| 556 | } |
Alex Sakhartchouk | f18136c | 2010-08-06 14:49:04 -0700 | [diff] [blame] | 557 | |
Romain Guy | 2d4fd36 | 2011-12-13 22:00:19 -0800 | [diff] [blame] | 558 | mDrawn = false; |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 559 | mClip = nullptr; |
| 560 | mBounds = nullptr; |
Romain Guy | ff98fa5 | 2011-11-28 09:35:09 -0800 | [diff] [blame] | 561 | |
Alex Sakhartchouk | f18136c | 2010-08-06 14:49:04 -0700 | [diff] [blame] | 562 | Rect bounds; |
Chris Craik | e8c3c81 | 2016-02-05 20:10:50 -0800 | [diff] [blame] | 563 | mCurrentFont->measure(paint, glyphs, numGlyphs, &bounds, positions); |
Romain Guy | ff98fa5 | 2011-11-28 09:35:09 -0800 | [diff] [blame] | 564 | |
Derek Sollenberger | e392c81 | 2014-05-21 11:25:22 -0400 | [diff] [blame] | 565 | uint32_t intRadius = Blur::convertRadiusToInt(radius); |
| 566 | uint32_t paddedWidth = (uint32_t) (bounds.right - bounds.left) + 2 * intRadius; |
| 567 | uint32_t paddedHeight = (uint32_t) (bounds.top - bounds.bottom) + 2 * intRadius; |
Romain Guy | ff98fa5 | 2011-11-28 09:35:09 -0800 | [diff] [blame] | 568 | |
Romain Guy | cf51a41 | 2013-04-08 19:40:31 -0700 | [diff] [blame] | 569 | uint32_t maxSize = Caches::getInstance().maxTextureSize; |
| 570 | if (paddedWidth > maxSize || paddedHeight > maxSize) { |
| 571 | return image; |
| 572 | } |
| 573 | |
Dan Morrill | e4d9a01 | 2013-03-28 18:10:43 -0700 | [diff] [blame] | 574 | #ifdef ANDROID_ENABLE_RENDERSCRIPT |
Chris Craik | f2d8ccc | 2013-02-13 16:14:17 -0800 | [diff] [blame] | 575 | // Align buffers for renderscript usage |
| 576 | if (paddedWidth & (RS_CPU_ALLOCATION_ALIGNMENT - 1)) { |
| 577 | paddedWidth += RS_CPU_ALLOCATION_ALIGNMENT - paddedWidth % RS_CPU_ALLOCATION_ALIGNMENT; |
Alex Sakhartchouk | f18136c | 2010-08-06 14:49:04 -0700 | [diff] [blame] | 578 | } |
Chris Craik | f2d8ccc | 2013-02-13 16:14:17 -0800 | [diff] [blame] | 579 | int size = paddedWidth * paddedHeight; |
Romain Guy | 6e20040 | 2013-03-08 11:28:22 -0800 | [diff] [blame] | 580 | uint8_t* dataBuffer = (uint8_t*) memalign(RS_CPU_ALLOCATION_ALIGNMENT, size); |
Dan Morrill | e4d9a01 | 2013-03-28 18:10:43 -0700 | [diff] [blame] | 581 | #else |
| 582 | int size = paddedWidth * paddedHeight; |
| 583 | uint8_t* dataBuffer = (uint8_t*) malloc(size); |
| 584 | #endif |
| 585 | |
Chris Craik | f2d8ccc | 2013-02-13 16:14:17 -0800 | [diff] [blame] | 586 | memset(dataBuffer, 0, size); |
| 587 | |
Derek Sollenberger | e392c81 | 2014-05-21 11:25:22 -0400 | [diff] [blame] | 588 | int penX = intRadius - bounds.left; |
| 589 | int penY = intRadius - bounds.bottom; |
Alex Sakhartchouk | f18136c | 2010-08-06 14:49:04 -0700 | [diff] [blame] | 590 | |
Chris Craik | dd8697c | 2013-02-22 10:41:36 -0800 | [diff] [blame] | 591 | if ((bounds.right > bounds.left) && (bounds.top > bounds.bottom)) { |
| 592 | // text has non-whitespace, so draw and blur to create the shadow |
| 593 | // NOTE: bounds.isEmpty() can't be used here, since vertical coordinates are inverted |
| 594 | // TODO: don't draw pure whitespace in the first place, and avoid needing this check |
Chris Craik | e8c3c81 | 2016-02-05 20:10:50 -0800 | [diff] [blame] | 595 | mCurrentFont->render(paint, glyphs, numGlyphs, penX, penY, |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 596 | Font::BITMAP, dataBuffer, paddedWidth, paddedHeight, nullptr, positions); |
Chris Craik | dd8697c | 2013-02-22 10:41:36 -0800 | [diff] [blame] | 597 | |
Romain Guy | cf51a41 | 2013-04-08 19:40:31 -0700 | [diff] [blame] | 598 | // Unbind any PBO we might have used |
Chris Craik | 44eb2c0 | 2015-01-29 09:45:09 -0800 | [diff] [blame] | 599 | Caches::getInstance().pixelBufferState().unbind(); |
Romain Guy | cf51a41 | 2013-04-08 19:40:31 -0700 | [diff] [blame] | 600 | |
Chris Craik | dd8697c | 2013-02-22 10:41:36 -0800 | [diff] [blame] | 601 | blurImage(&dataBuffer, paddedWidth, paddedHeight, radius); |
| 602 | } |
Alex Sakhartchouk | f18136c | 2010-08-06 14:49:04 -0700 | [diff] [blame] | 603 | |
Alex Sakhartchouk | f18136c | 2010-08-06 14:49:04 -0700 | [diff] [blame] | 604 | image.width = paddedWidth; |
| 605 | image.height = paddedHeight; |
| 606 | image.image = dataBuffer; |
| 607 | image.penX = penX; |
| 608 | image.penY = penY; |
Romain Guy | 2d4fd36 | 2011-12-13 22:00:19 -0800 | [diff] [blame] | 609 | |
Alex Sakhartchouk | f18136c | 2010-08-06 14:49:04 -0700 | [diff] [blame] | 610 | return image; |
| 611 | } |
Romain Guy | 694b519 | 2010-07-21 21:33:20 -0700 | [diff] [blame] | 612 | |
Chris Craik | 8284073 | 2015-04-03 09:37:49 -0700 | [diff] [blame] | 613 | void FontRenderer::initRender(const Rect* clip, Rect* bounds, TextDrawFunctor* functor) { |
Romain Guy | 694b519 | 2010-07-21 21:33:20 -0700 | [diff] [blame] | 614 | checkInit(); |
| 615 | |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 616 | mDrawn = false; |
| 617 | mBounds = bounds; |
Romain Guy | 257ae35 | 2013-03-20 16:31:12 -0700 | [diff] [blame] | 618 | mFunctor = functor; |
Romain Guy | 09147fb | 2010-07-22 13:08:20 -0700 | [diff] [blame] | 619 | mClip = clip; |
Romain Guy | 671d6cf | 2012-01-18 12:39:17 -0800 | [diff] [blame] | 620 | } |
Romain Guy | ff98fa5 | 2011-11-28 09:35:09 -0800 | [diff] [blame] | 621 | |
Romain Guy | 671d6cf | 2012-01-18 12:39:17 -0800 | [diff] [blame] | 622 | void FontRenderer::finishRender() { |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 623 | mBounds = nullptr; |
| 624 | mClip = nullptr; |
Romain Guy | 694b519 | 2010-07-21 21:33:20 -0700 | [diff] [blame] | 625 | |
Romain Guy | 661a87e | 2013-03-19 15:24:36 -0700 | [diff] [blame] | 626 | issueDrawCommand(); |
Romain Guy | 671d6cf | 2012-01-18 12:39:17 -0800 | [diff] [blame] | 627 | } |
| 628 | |
Chris Craik | e8c3c81 | 2016-02-05 20:10:50 -0800 | [diff] [blame] | 629 | void FontRenderer::precache(const SkPaint* paint, const glyph_t* glyphs, int numGlyphs, |
Chris Craik | 59744b7 | 2014-07-01 17:56:52 -0700 | [diff] [blame] | 630 | const SkMatrix& matrix) { |
Romain Guy | e3a9b24 | 2013-01-08 11:15:30 -0800 | [diff] [blame] | 631 | Font* font = Font::create(this, paint, matrix); |
Chris Craik | e8c3c81 | 2016-02-05 20:10:50 -0800 | [diff] [blame] | 632 | font->precache(paint, glyphs, numGlyphs); |
Chet Haase | e816bae | 2012-08-09 13:39:02 -0700 | [diff] [blame] | 633 | } |
| 634 | |
Romain Guy | cf51a41 | 2013-04-08 19:40:31 -0700 | [diff] [blame] | 635 | void FontRenderer::endPrecaching() { |
| 636 | checkTextureUpdate(); |
| 637 | } |
| 638 | |
Chris Craik | e8c3c81 | 2016-02-05 20:10:50 -0800 | [diff] [blame] | 639 | bool FontRenderer::renderPosText(const SkPaint* paint, const Rect* clip, const glyph_t* glyphs, |
Chris Craik | a171727 | 2015-11-19 13:02:43 -0800 | [diff] [blame] | 640 | int numGlyphs, int x, int y, const float* positions, |
| 641 | Rect* bounds, TextDrawFunctor* functor, bool forceFinish) { |
Romain Guy | 671d6cf | 2012-01-18 12:39:17 -0800 | [diff] [blame] | 642 | if (!mCurrentFont) { |
| 643 | ALOGE("No font set"); |
| 644 | return false; |
| 645 | } |
| 646 | |
Romain Guy | 257ae35 | 2013-03-20 16:31:12 -0700 | [diff] [blame] | 647 | initRender(clip, bounds, functor); |
Chris Craik | e8c3c81 | 2016-02-05 20:10:50 -0800 | [diff] [blame] | 648 | mCurrentFont->render(paint, glyphs, numGlyphs, x, y, positions); |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 649 | |
| 650 | if (forceFinish) { |
| 651 | finishRender(); |
| 652 | } |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 653 | |
| 654 | return mDrawn; |
Romain Guy | 694b519 | 2010-07-21 21:33:20 -0700 | [diff] [blame] | 655 | } |
| 656 | |
Chris Craik | e8c3c81 | 2016-02-05 20:10:50 -0800 | [diff] [blame] | 657 | bool FontRenderer::renderTextOnPath(const SkPaint* paint, const Rect* clip, const glyph_t* glyphs, |
Chris Craik | a171727 | 2015-11-19 13:02:43 -0800 | [diff] [blame] | 658 | int numGlyphs, const SkPath* path, float hOffset, float vOffset, |
| 659 | Rect* bounds, TextDrawFunctor* functor) { |
Romain Guy | 9777173 | 2012-02-28 18:17:02 -0800 | [diff] [blame] | 660 | if (!mCurrentFont) { |
| 661 | ALOGE("No font set"); |
| 662 | return false; |
| 663 | } |
| 664 | |
Victoria Lease | 1e54681 | 2013-06-25 14:25:17 -0700 | [diff] [blame] | 665 | initRender(clip, bounds, functor); |
Chris Craik | e8c3c81 | 2016-02-05 20:10:50 -0800 | [diff] [blame] | 666 | mCurrentFont->render(paint, glyphs, numGlyphs, path, hOffset, vOffset); |
Romain Guy | 9777173 | 2012-02-28 18:17:02 -0800 | [diff] [blame] | 667 | finishRender(); |
| 668 | |
| 669 | return mDrawn; |
| 670 | } |
| 671 | |
Derek Sollenberger | e392c81 | 2014-05-21 11:25:22 -0400 | [diff] [blame] | 672 | void FontRenderer::blurImage(uint8_t** image, int32_t width, int32_t height, float radius) { |
| 673 | uint32_t intRadius = Blur::convertRadiusToInt(radius); |
Dan Morrill | e4d9a01 | 2013-03-28 18:10:43 -0700 | [diff] [blame] | 674 | #ifdef ANDROID_ENABLE_RENDERSCRIPT |
Chris Craik | f3754a8 | 2016-04-19 18:13:21 -0700 | [diff] [blame] | 675 | if (width * height * intRadius >= RS_MIN_INPUT_CUTOFF && radius <= 25.0f) { |
Dan Morrill | e4d9a01 | 2013-03-28 18:10:43 -0700 | [diff] [blame] | 676 | uint8_t* outImage = (uint8_t*) memalign(RS_CPU_ALLOCATION_ALIGNMENT, width * height); |
Alex Sakhartchouk | 89a524a | 2010-08-02 17:52:30 -0700 | [diff] [blame] | 677 | |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 678 | if (mRs == nullptr) { |
Dan Morrill | e4d9a01 | 2013-03-28 18:10:43 -0700 | [diff] [blame] | 679 | mRs = new RSC::RS(); |
Tim Murray | abe55e9 | 2013-12-13 12:57:36 -0800 | [diff] [blame] | 680 | // a null path is OK because there are no custom kernels used |
| 681 | // hence nothing gets cached by RS |
| 682 | if (!mRs->init("", RSC::RS_INIT_LOW_LATENCY | RSC::RS_INIT_SYNCHRONOUS)) { |
Lu, Shenghua | ea42e01 | 2013-11-14 15:52:22 +0800 | [diff] [blame] | 683 | mRs.clear(); |
Dan Morrill | e4d9a01 | 2013-03-28 18:10:43 -0700 | [diff] [blame] | 684 | ALOGE("blur RS failed to init"); |
Lu, Shenghua | ea42e01 | 2013-11-14 15:52:22 +0800 | [diff] [blame] | 685 | } else { |
| 686 | mRsElement = RSC::Element::A_8(mRs); |
| 687 | mRsScript = RSC::ScriptIntrinsicBlur::create(mRs, mRsElement); |
Dan Morrill | e4d9a01 | 2013-03-28 18:10:43 -0700 | [diff] [blame] | 688 | } |
Chris Craik | f2d8ccc | 2013-02-13 16:14:17 -0800 | [diff] [blame] | 689 | } |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 690 | if (mRs != nullptr) { |
Lu, Shenghua | ea42e01 | 2013-11-14 15:52:22 +0800 | [diff] [blame] | 691 | RSC::sp<const RSC::Type> t = RSC::Type::create(mRs, mRsElement, width, height, 0); |
| 692 | RSC::sp<RSC::Allocation> ain = RSC::Allocation::createTyped(mRs, t, |
| 693 | RS_ALLOCATION_MIPMAP_NONE, |
| 694 | RS_ALLOCATION_USAGE_SCRIPT | RS_ALLOCATION_USAGE_SHARED, |
| 695 | *image); |
| 696 | RSC::sp<RSC::Allocation> aout = RSC::Allocation::createTyped(mRs, t, |
| 697 | RS_ALLOCATION_MIPMAP_NONE, |
| 698 | RS_ALLOCATION_USAGE_SCRIPT | RS_ALLOCATION_USAGE_SHARED, |
| 699 | outImage); |
Chris Craik | f2d8ccc | 2013-02-13 16:14:17 -0800 | [diff] [blame] | 700 | |
Lu, Shenghua | ea42e01 | 2013-11-14 15:52:22 +0800 | [diff] [blame] | 701 | mRsScript->setRadius(radius); |
| 702 | mRsScript->setInput(ain); |
| 703 | mRsScript->forEach(aout); |
Dan Morrill | e4d9a01 | 2013-03-28 18:10:43 -0700 | [diff] [blame] | 704 | |
Lu, Shenghua | ea42e01 | 2013-11-14 15:52:22 +0800 | [diff] [blame] | 705 | // replace the original image's pointer, avoiding a copy back to the original buffer |
| 706 | free(*image); |
| 707 | *image = outImage; |
Dan Morrill | e4d9a01 | 2013-03-28 18:10:43 -0700 | [diff] [blame] | 708 | |
Lu, Shenghua | ea42e01 | 2013-11-14 15:52:22 +0800 | [diff] [blame] | 709 | return; |
| 710 | } |
Chris Craik | f2d8ccc | 2013-02-13 16:14:17 -0800 | [diff] [blame] | 711 | } |
Dan Morrill | e4d9a01 | 2013-03-28 18:10:43 -0700 | [diff] [blame] | 712 | #endif |
Chris Craik | f2d8ccc | 2013-02-13 16:14:17 -0800 | [diff] [blame] | 713 | |
Chris Craik | 51d6a3d | 2014-12-22 17:16:56 -0800 | [diff] [blame] | 714 | std::unique_ptr<float[]> gaussian(new float[2 * intRadius + 1]); |
huanhuan.x.wang | a46ca5e | 2015-04-14 16:23:15 +0200 | [diff] [blame] | 715 | Blur::generateGaussianWeights(gaussian.get(), radius); |
Chris Craik | f2d8ccc | 2013-02-13 16:14:17 -0800 | [diff] [blame] | 716 | |
Chris Craik | 51d6a3d | 2014-12-22 17:16:56 -0800 | [diff] [blame] | 717 | std::unique_ptr<uint8_t[]> scratch(new uint8_t[width * height]); |
| 718 | Blur::horizontal(gaussian.get(), intRadius, *image, scratch.get(), width, height); |
| 719 | Blur::vertical(gaussian.get(), intRadius, scratch.get(), *image, width, height); |
Alex Sakhartchouk | 89a524a | 2010-08-02 17:52:30 -0700 | [diff] [blame] | 720 | } |
| 721 | |
John Reck | 272a685 | 2015-07-29 16:48:58 -0700 | [diff] [blame] | 722 | static uint32_t calculateCacheSize(const std::vector<CacheTexture*>& cacheTextures) { |
Romain Guy | cf51a41 | 2013-04-08 19:40:31 -0700 | [diff] [blame] | 723 | uint32_t size = 0; |
Victoria Lease | 1e54681 | 2013-06-25 14:25:17 -0700 | [diff] [blame] | 724 | for (uint32_t i = 0; i < cacheTextures.size(); i++) { |
| 725 | CacheTexture* cacheTexture = cacheTextures[i]; |
Romain Guy | cf51a41 | 2013-04-08 19:40:31 -0700 | [diff] [blame] | 726 | if (cacheTexture && cacheTexture->getPixelBuffer()) { |
| 727 | size += cacheTexture->getPixelBuffer()->getSize(); |
| 728 | } |
| 729 | } |
| 730 | return size; |
| 731 | } |
| 732 | |
Victoria Lease | 1e54681 | 2013-06-25 14:25:17 -0700 | [diff] [blame] | 733 | uint32_t FontRenderer::getCacheSize(GLenum format) const { |
| 734 | switch (format) { |
| 735 | case GL_ALPHA: { |
| 736 | return calculateCacheSize(mACacheTextures); |
| 737 | } |
| 738 | case GL_RGBA: { |
| 739 | return calculateCacheSize(mRGBACacheTextures); |
| 740 | } |
| 741 | default: { |
| 742 | return 0; |
| 743 | } |
| 744 | } |
| 745 | } |
| 746 | |
Romain Guy | 694b519 | 2010-07-21 21:33:20 -0700 | [diff] [blame] | 747 | }; // namespace uirenderer |
| 748 | }; // namespace android |