Romain Guy | ce0537b | 2010-06-29 21:05:21 -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 | |
Romain Guy | 121e2242 | 2010-07-01 18:26:52 -0700 | [diff] [blame] | 17 | #define LOG_TAG "OpenGLRenderer" |
| 18 | |
Romain Guy | ce0537b | 2010-06-29 21:05:21 -0700 | [diff] [blame] | 19 | #include <GLES2/gl2.h> |
| 20 | |
Romain Guy | 7adaf3d | 2010-10-05 14:58:09 -0700 | [diff] [blame] | 21 | #include <SkCanvas.h> |
| 22 | |
Romain Guy | 9aaa826 | 2010-09-08 15:15:43 -0700 | [diff] [blame] | 23 | #include <utils/threads.h> |
| 24 | |
Romain Guy | ce0537b | 2010-06-29 21:05:21 -0700 | [diff] [blame] | 25 | #include "TextureCache.h" |
Romain Guy | fb8b763 | 2010-08-23 21:05:08 -0700 | [diff] [blame] | 26 | #include "Properties.h" |
Romain Guy | ce0537b | 2010-06-29 21:05:21 -0700 | [diff] [blame] | 27 | |
| 28 | namespace android { |
| 29 | namespace uirenderer { |
| 30 | |
Romain Guy | 121e2242 | 2010-07-01 18:26:52 -0700 | [diff] [blame] | 31 | /////////////////////////////////////////////////////////////////////////////// |
| 32 | // Constructors/destructor |
| 33 | /////////////////////////////////////////////////////////////////////////////// |
| 34 | |
Romain Guy | fb8b763 | 2010-08-23 21:05:08 -0700 | [diff] [blame] | 35 | TextureCache::TextureCache(): |
| 36 | mCache(GenerationCache<SkBitmap*, Texture*>::kUnlimitedCapacity), |
Romain Guy | eca0ca2 | 2011-11-04 15:12:29 -0700 | [diff] [blame] | 37 | mSize(0), mMaxSize(MB(DEFAULT_TEXTURE_CACHE_SIZE)), |
| 38 | mFlushRate(DEFAULT_TEXTURE_CACHE_FLUSH_RATE) { |
Romain Guy | fb8b763 | 2010-08-23 21:05:08 -0700 | [diff] [blame] | 39 | char property[PROPERTY_VALUE_MAX]; |
| 40 | if (property_get(PROPERTY_TEXTURE_CACHE_SIZE, property, NULL) > 0) { |
Romain Guy | c9855a5 | 2011-01-21 21:14:15 -0800 | [diff] [blame] | 41 | INIT_LOGD(" Setting texture cache size to %sMB", property); |
Romain Guy | fb8b763 | 2010-08-23 21:05:08 -0700 | [diff] [blame] | 42 | setMaxSize(MB(atof(property))); |
| 43 | } else { |
Romain Guy | c9855a5 | 2011-01-21 21:14:15 -0800 | [diff] [blame] | 44 | INIT_LOGD(" Using default texture cache size of %.2fMB", DEFAULT_TEXTURE_CACHE_SIZE); |
Romain Guy | fb8b763 | 2010-08-23 21:05:08 -0700 | [diff] [blame] | 45 | } |
| 46 | |
Romain Guy | eca0ca2 | 2011-11-04 15:12:29 -0700 | [diff] [blame] | 47 | if (property_get(PROPERTY_TEXTURE_CACHE_FLUSH_RATE, property, NULL) > 0) { |
| 48 | float flushRate = atof(property); |
| 49 | INIT_LOGD(" Setting texture cache flush rate to %.2f%%", flushRate * 100.0f); |
| 50 | setFlushRate(flushRate); |
| 51 | } else { |
| 52 | INIT_LOGD(" Using default texture cache flush rate of %.2f%%", |
| 53 | DEFAULT_TEXTURE_CACHE_FLUSH_RATE * 100.0f); |
| 54 | } |
| 55 | |
Romain Guy | fb8b763 | 2010-08-23 21:05:08 -0700 | [diff] [blame] | 56 | init(); |
| 57 | } |
| 58 | |
Romain Guy | 7d139ba | 2010-07-02 11:20:34 -0700 | [diff] [blame] | 59 | TextureCache::TextureCache(uint32_t maxByteSize): |
Romain Guy | 6c81893 | 2010-07-07 15:15:32 -0700 | [diff] [blame] | 60 | mCache(GenerationCache<SkBitmap*, Texture*>::kUnlimitedCapacity), |
Romain Guy | 121e2242 | 2010-07-01 18:26:52 -0700 | [diff] [blame] | 61 | mSize(0), mMaxSize(maxByteSize) { |
Romain Guy | fb8b763 | 2010-08-23 21:05:08 -0700 | [diff] [blame] | 62 | init(); |
Romain Guy | ce0537b | 2010-06-29 21:05:21 -0700 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | TextureCache::~TextureCache() { |
| 66 | mCache.clear(); |
| 67 | } |
| 68 | |
Romain Guy | fb8b763 | 2010-08-23 21:05:08 -0700 | [diff] [blame] | 69 | void TextureCache::init() { |
| 70 | mCache.setOnEntryRemovedListener(this); |
| 71 | |
| 72 | glGetIntegerv(GL_MAX_TEXTURE_SIZE, &mMaxTextureSize); |
Romain Guy | f683447 | 2011-01-23 13:32:12 -0800 | [diff] [blame] | 73 | INIT_LOGD(" Maximum texture dimension is %d pixels", mMaxTextureSize); |
Romain Guy | e190aa6 | 2010-11-10 19:01:29 -0800 | [diff] [blame] | 74 | |
| 75 | mDebugEnabled = readDebugLevel() & kDebugCaches; |
Romain Guy | fb8b763 | 2010-08-23 21:05:08 -0700 | [diff] [blame] | 76 | } |
| 77 | |
Romain Guy | 121e2242 | 2010-07-01 18:26:52 -0700 | [diff] [blame] | 78 | /////////////////////////////////////////////////////////////////////////////// |
| 79 | // Size management |
| 80 | /////////////////////////////////////////////////////////////////////////////// |
| 81 | |
Romain Guy | 7d139ba | 2010-07-02 11:20:34 -0700 | [diff] [blame] | 82 | uint32_t TextureCache::getSize() { |
Romain Guy | 121e2242 | 2010-07-01 18:26:52 -0700 | [diff] [blame] | 83 | return mSize; |
| 84 | } |
| 85 | |
Romain Guy | 7d139ba | 2010-07-02 11:20:34 -0700 | [diff] [blame] | 86 | uint32_t TextureCache::getMaxSize() { |
Romain Guy | 121e2242 | 2010-07-01 18:26:52 -0700 | [diff] [blame] | 87 | return mMaxSize; |
| 88 | } |
| 89 | |
Romain Guy | 7d139ba | 2010-07-02 11:20:34 -0700 | [diff] [blame] | 90 | void TextureCache::setMaxSize(uint32_t maxSize) { |
Romain Guy | 121e2242 | 2010-07-01 18:26:52 -0700 | [diff] [blame] | 91 | mMaxSize = maxSize; |
| 92 | while (mSize > mMaxSize) { |
| 93 | mCache.removeOldest(); |
Romain Guy | ce0537b | 2010-06-29 21:05:21 -0700 | [diff] [blame] | 94 | } |
| 95 | } |
| 96 | |
Romain Guy | eca0ca2 | 2011-11-04 15:12:29 -0700 | [diff] [blame] | 97 | void TextureCache::setFlushRate(float flushRate) { |
| 98 | mFlushRate = fmaxf(0.0f, fminf(1.0f, flushRate)); |
| 99 | } |
| 100 | |
Romain Guy | 121e2242 | 2010-07-01 18:26:52 -0700 | [diff] [blame] | 101 | /////////////////////////////////////////////////////////////////////////////// |
| 102 | // Callbacks |
| 103 | /////////////////////////////////////////////////////////////////////////////// |
| 104 | |
Romain Guy | dda57020 | 2010-07-06 11:39:32 -0700 | [diff] [blame] | 105 | void TextureCache::operator()(SkBitmap*& bitmap, Texture*& texture) { |
Romain Guy | 9aaa826 | 2010-09-08 15:15:43 -0700 | [diff] [blame] | 106 | // This will be called already locked |
Romain Guy | 121e2242 | 2010-07-01 18:26:52 -0700 | [diff] [blame] | 107 | if (texture) { |
Romain Guy | 9aaa826 | 2010-09-08 15:15:43 -0700 | [diff] [blame] | 108 | mSize -= texture->bitmapSize; |
Romain Guy | 9e10841 | 2010-11-09 14:35:20 -0800 | [diff] [blame] | 109 | TEXTURE_LOGD("TextureCache::callback: name, removed size, mSize = %d, %d, %d", |
| 110 | texture->id, texture->bitmapSize, mSize); |
Romain Guy | e190aa6 | 2010-11-10 19:01:29 -0800 | [diff] [blame] | 111 | if (mDebugEnabled) { |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 112 | ALOGD("Texture deleted, size = %d", texture->bitmapSize); |
Romain Guy | e190aa6 | 2010-11-10 19:01:29 -0800 | [diff] [blame] | 113 | } |
Romain Guy | 121e2242 | 2010-07-01 18:26:52 -0700 | [diff] [blame] | 114 | glDeleteTextures(1, &texture->id); |
| 115 | delete texture; |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | /////////////////////////////////////////////////////////////////////////////// |
| 120 | // Caching |
| 121 | /////////////////////////////////////////////////////////////////////////////// |
| 122 | |
Romain Guy | ce0537b | 2010-06-29 21:05:21 -0700 | [diff] [blame] | 123 | Texture* TextureCache::get(SkBitmap* bitmap) { |
| 124 | Texture* texture = mCache.get(bitmap); |
Romain Guy | a2341a9 | 2010-09-08 18:04:33 -0700 | [diff] [blame] | 125 | |
Romain Guy | ce0537b | 2010-06-29 21:05:21 -0700 | [diff] [blame] | 126 | if (!texture) { |
Romain Guy | 9cccc2b9 | 2010-08-07 23:46:15 -0700 | [diff] [blame] | 127 | if (bitmap->width() > mMaxTextureSize || bitmap->height() > mMaxTextureSize) { |
Steve Block | 8564c8d | 2012-01-05 23:22:43 +0000 | [diff] [blame^] | 128 | ALOGW("Bitmap too large to be uploaded into a texture (%dx%d, max=%dx%d)", |
Romain Guy | 8f9a9f6 | 2011-12-05 11:53:26 -0800 | [diff] [blame] | 129 | bitmap->width(), bitmap->height(), mMaxTextureSize, mMaxTextureSize); |
Romain Guy | 9cccc2b9 | 2010-08-07 23:46:15 -0700 | [diff] [blame] | 130 | return NULL; |
| 131 | } |
| 132 | |
Romain Guy | 7d139ba | 2010-07-02 11:20:34 -0700 | [diff] [blame] | 133 | const uint32_t size = bitmap->rowBytes() * bitmap->height(); |
Romain Guy | 121e2242 | 2010-07-01 18:26:52 -0700 | [diff] [blame] | 134 | // Don't even try to cache a bitmap that's bigger than the cache |
| 135 | if (size < mMaxSize) { |
| 136 | while (mSize + size > mMaxSize) { |
| 137 | mCache.removeOldest(); |
| 138 | } |
| 139 | } |
| 140 | |
Romain Guy | 364703c | 2010-06-30 15:51:03 -0700 | [diff] [blame] | 141 | texture = new Texture; |
Romain Guy | 9aaa826 | 2010-09-08 15:15:43 -0700 | [diff] [blame] | 142 | texture->bitmapSize = size; |
Romain Guy | c1396e9 | 2010-06-30 17:56:19 -0700 | [diff] [blame] | 143 | generateTexture(bitmap, texture, false); |
Romain Guy | 121e2242 | 2010-07-01 18:26:52 -0700 | [diff] [blame] | 144 | |
| 145 | if (size < mMaxSize) { |
| 146 | mSize += size; |
Romain Guy | 9e10841 | 2010-11-09 14:35:20 -0800 | [diff] [blame] | 147 | TEXTURE_LOGD("TextureCache::get: create texture(%p): name, size, mSize = %d, %d, %d", |
| 148 | bitmap, texture->id, size, mSize); |
Romain Guy | e190aa6 | 2010-11-10 19:01:29 -0800 | [diff] [blame] | 149 | if (mDebugEnabled) { |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 150 | ALOGD("Texture created, size = %d", size); |
Romain Guy | e190aa6 | 2010-11-10 19:01:29 -0800 | [diff] [blame] | 151 | } |
Romain Guy | 121e2242 | 2010-07-01 18:26:52 -0700 | [diff] [blame] | 152 | mCache.put(bitmap, texture); |
Romain Guy | 22158e1 | 2010-08-06 11:18:34 -0700 | [diff] [blame] | 153 | } else { |
| 154 | texture->cleanup = true; |
Romain Guy | 121e2242 | 2010-07-01 18:26:52 -0700 | [diff] [blame] | 155 | } |
Romain Guy | fe88094 | 2010-06-30 16:05:32 -0700 | [diff] [blame] | 156 | } else if (bitmap->getGenerationID() != texture->generation) { |
| 157 | generateTexture(bitmap, texture, true); |
Romain Guy | ce0537b | 2010-06-29 21:05:21 -0700 | [diff] [blame] | 158 | } |
Romain Guy | 22158e1 | 2010-08-06 11:18:34 -0700 | [diff] [blame] | 159 | |
Romain Guy | ce0537b | 2010-06-29 21:05:21 -0700 | [diff] [blame] | 160 | return texture; |
| 161 | } |
| 162 | |
Romain Guy | 121e2242 | 2010-07-01 18:26:52 -0700 | [diff] [blame] | 163 | void TextureCache::remove(SkBitmap* bitmap) { |
| 164 | mCache.remove(bitmap); |
Romain Guy | ce0537b | 2010-06-29 21:05:21 -0700 | [diff] [blame] | 165 | } |
| 166 | |
Romain Guy | fe48f65 | 2010-11-11 15:36:56 -0800 | [diff] [blame] | 167 | void TextureCache::removeDeferred(SkBitmap* bitmap) { |
Romain Guy | 9aaa826 | 2010-09-08 15:15:43 -0700 | [diff] [blame] | 168 | Mutex::Autolock _l(mLock); |
Romain Guy | fe48f65 | 2010-11-11 15:36:56 -0800 | [diff] [blame] | 169 | mGarbage.push(bitmap); |
| 170 | } |
| 171 | |
| 172 | void TextureCache::clearGarbage() { |
| 173 | Mutex::Autolock _l(mLock); |
| 174 | size_t count = mGarbage.size(); |
| 175 | for (size_t i = 0; i < count; i++) { |
| 176 | mCache.remove(mGarbage.itemAt(i)); |
| 177 | } |
| 178 | mGarbage.clear(); |
| 179 | } |
| 180 | |
| 181 | void TextureCache::clear() { |
Romain Guy | ce0537b | 2010-06-29 21:05:21 -0700 | [diff] [blame] | 182 | mCache.clear(); |
Romain Guy | 912a7b3 | 2011-07-26 18:57:28 -0700 | [diff] [blame] | 183 | TEXTURE_LOGD("TextureCache:clear(), mSize = %d", mSize); |
Romain Guy | ce0537b | 2010-06-29 21:05:21 -0700 | [diff] [blame] | 184 | } |
| 185 | |
Romain Guy | eca0ca2 | 2011-11-04 15:12:29 -0700 | [diff] [blame] | 186 | void TextureCache::flush() { |
| 187 | if (mFlushRate >= 1.0f || mCache.size() == 0) return; |
| 188 | if (mFlushRate <= 0.0f) { |
| 189 | clear(); |
| 190 | return; |
| 191 | } |
| 192 | |
| 193 | uint32_t targetSize = uint32_t(mSize * mFlushRate); |
| 194 | TEXTURE_LOGD("TextureCache::flush: target size: %d", targetSize); |
| 195 | |
| 196 | while (mSize > targetSize) { |
| 197 | mCache.removeOldest(); |
| 198 | } |
| 199 | } |
| 200 | |
Romain Guy | fe88094 | 2010-06-30 16:05:32 -0700 | [diff] [blame] | 201 | void TextureCache::generateTexture(SkBitmap* bitmap, Texture* texture, bool regenerate) { |
Romain Guy | c1396e9 | 2010-06-30 17:56:19 -0700 | [diff] [blame] | 202 | SkAutoLockPixels alp(*bitmap); |
Romain Guy | 9aaa826 | 2010-09-08 15:15:43 -0700 | [diff] [blame] | 203 | |
Romain Guy | c1396e9 | 2010-06-30 17:56:19 -0700 | [diff] [blame] | 204 | if (!bitmap->readyToDraw()) { |
| 205 | LOGE("Cannot generate texture from bitmap"); |
| 206 | return; |
| 207 | } |
| 208 | |
Romain Guy | 29d8997 | 2010-09-22 16:10:57 -0700 | [diff] [blame] | 209 | const bool resize = !regenerate || bitmap->width() != int(texture->width) || |
| 210 | bitmap->height() != int(texture->height); |
Romain Guy | ce0537b | 2010-06-29 21:05:21 -0700 | [diff] [blame] | 211 | |
Romain Guy | 8c749f8 | 2010-09-22 14:13:32 -0700 | [diff] [blame] | 212 | if (!regenerate) { |
Romain Guy | fe88094 | 2010-06-30 16:05:32 -0700 | [diff] [blame] | 213 | glGenTextures(1, &texture->id); |
| 214 | } |
| 215 | |
Romain Guy | 8c749f8 | 2010-09-22 14:13:32 -0700 | [diff] [blame] | 216 | texture->generation = bitmap->getGenerationID(); |
| 217 | texture->width = bitmap->width(); |
| 218 | texture->height = bitmap->height(); |
| 219 | |
Romain Guy | ce0537b | 2010-06-29 21:05:21 -0700 | [diff] [blame] | 220 | glBindTexture(GL_TEXTURE_2D, texture->id); |
Romain Guy | d21b6e1 | 2011-11-30 20:21:23 -0800 | [diff] [blame] | 221 | if (!regenerate) { |
| 222 | glPixelStorei(GL_UNPACK_ALIGNMENT, bitmap->bytesPerPixel()); |
| 223 | } |
Romain Guy | c1396e9 | 2010-06-30 17:56:19 -0700 | [diff] [blame] | 224 | |
| 225 | switch (bitmap->getConfig()) { |
Romain Guy | bd0e6aa | 2010-07-22 18:50:12 -0700 | [diff] [blame] | 226 | case SkBitmap::kA8_Config: |
Romain Guy | d21b6e1 | 2011-11-30 20:21:23 -0800 | [diff] [blame] | 227 | if (!regenerate) { |
| 228 | glPixelStorei(GL_UNPACK_ALIGNMENT, 1); |
| 229 | } |
Romain Guy | 8c749f8 | 2010-09-22 14:13:32 -0700 | [diff] [blame] | 230 | uploadToTexture(resize, GL_ALPHA, bitmap->rowBytesAsPixels(), texture->height, |
| 231 | GL_UNSIGNED_BYTE, bitmap->getPixels()); |
| 232 | texture->blend = true; |
Romain Guy | bd0e6aa | 2010-07-22 18:50:12 -0700 | [diff] [blame] | 233 | break; |
Romain Guy | c1396e9 | 2010-06-30 17:56:19 -0700 | [diff] [blame] | 234 | case SkBitmap::kRGB_565_Config: |
Romain Guy | 8c749f8 | 2010-09-22 14:13:32 -0700 | [diff] [blame] | 235 | uploadToTexture(resize, GL_RGB, bitmap->rowBytesAsPixels(), texture->height, |
| 236 | GL_UNSIGNED_SHORT_5_6_5, bitmap->getPixels()); |
Romain Guy | c1396e9 | 2010-06-30 17:56:19 -0700 | [diff] [blame] | 237 | texture->blend = false; |
Romain Guy | c1396e9 | 2010-06-30 17:56:19 -0700 | [diff] [blame] | 238 | break; |
| 239 | case SkBitmap::kARGB_8888_Config: |
Romain Guy | 8c749f8 | 2010-09-22 14:13:32 -0700 | [diff] [blame] | 240 | uploadToTexture(resize, GL_RGBA, bitmap->rowBytesAsPixels(), texture->height, |
| 241 | GL_UNSIGNED_BYTE, bitmap->getPixels()); |
Romain Guy | e9e7fd0 | 2010-08-19 14:45:42 -0700 | [diff] [blame] | 242 | // Do this after calling getPixels() to make sure Skia's deferred |
| 243 | // decoding happened |
| 244 | texture->blend = !bitmap->isOpaque(); |
Romain Guy | c1396e9 | 2010-06-30 17:56:19 -0700 | [diff] [blame] | 245 | break; |
Romain Guy | b37cbec | 2011-02-24 17:21:29 -0800 | [diff] [blame] | 246 | case SkBitmap::kARGB_4444_Config: |
Romain Guy | 7adaf3d | 2010-10-05 14:58:09 -0700 | [diff] [blame] | 247 | case SkBitmap::kIndex8_Config: |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 248 | uploadLoFiTexture(resize, bitmap, texture->width, texture->height); |
Romain Guy | b37cbec | 2011-02-24 17:21:29 -0800 | [diff] [blame] | 249 | texture->blend = !bitmap->isOpaque(); |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 250 | break; |
Romain Guy | c1396e9 | 2010-06-30 17:56:19 -0700 | [diff] [blame] | 251 | default: |
Steve Block | 8564c8d | 2012-01-05 23:22:43 +0000 | [diff] [blame^] | 252 | ALOGW("Unsupported bitmap config: %d", bitmap->getConfig()); |
Romain Guy | c1396e9 | 2010-06-30 17:56:19 -0700 | [diff] [blame] | 253 | break; |
| 254 | } |
Romain Guy | ce0537b | 2010-06-29 21:05:21 -0700 | [diff] [blame] | 255 | |
Romain Guy | d21b6e1 | 2011-11-30 20:21:23 -0800 | [diff] [blame] | 256 | if (!regenerate) { |
| 257 | texture->setFilter(GL_NEAREST); |
| 258 | texture->setWrap(GL_CLAMP_TO_EDGE); |
| 259 | } |
Romain Guy | ce0537b | 2010-06-29 21:05:21 -0700 | [diff] [blame] | 260 | } |
| 261 | |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 262 | void TextureCache::uploadLoFiTexture(bool resize, SkBitmap* bitmap, |
Romain Guy | 7adaf3d | 2010-10-05 14:58:09 -0700 | [diff] [blame] | 263 | uint32_t width, uint32_t height) { |
| 264 | SkBitmap rgbaBitmap; |
| 265 | rgbaBitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height); |
| 266 | rgbaBitmap.allocPixels(); |
| 267 | rgbaBitmap.eraseColor(0); |
Romain Guy | b37cbec | 2011-02-24 17:21:29 -0800 | [diff] [blame] | 268 | rgbaBitmap.setIsOpaque(bitmap->isOpaque()); |
Romain Guy | 7adaf3d | 2010-10-05 14:58:09 -0700 | [diff] [blame] | 269 | |
| 270 | SkCanvas canvas(rgbaBitmap); |
| 271 | canvas.drawBitmap(*bitmap, 0.0f, 0.0f, NULL); |
| 272 | |
| 273 | uploadToTexture(resize, GL_RGBA, rgbaBitmap.rowBytesAsPixels(), height, |
| 274 | GL_UNSIGNED_BYTE, rgbaBitmap.getPixels()); |
| 275 | } |
| 276 | |
Romain Guy | 8c749f8 | 2010-09-22 14:13:32 -0700 | [diff] [blame] | 277 | void TextureCache::uploadToTexture(bool resize, GLenum format, GLsizei width, GLsizei height, |
| 278 | GLenum type, const GLvoid * data) { |
| 279 | if (resize) { |
| 280 | glTexImage2D(GL_TEXTURE_2D, 0, format, width, height, 0, format, type, data); |
| 281 | } else { |
| 282 | glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, format, type, data); |
| 283 | } |
| 284 | } |
| 285 | |
Romain Guy | ce0537b | 2010-06-29 21:05:21 -0700 | [diff] [blame] | 286 | }; // namespace uirenderer |
| 287 | }; // namespace android |