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