blob: 3b8a9a46c156332c2394f6b4130c94cacf6aaeb6 [file] [log] [blame]
Romain Guyce0537b2010-06-29 21:05:21 -07001/*
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 Guy121e2242010-07-01 18:26:52 -070017#define LOG_TAG "OpenGLRenderer"
John Reckec4cefc2014-07-29 09:49:13 -070018#define ATRACE_TAG ATRACE_TAG_VIEW
Romain Guy121e2242010-07-01 18:26:52 -070019
Romain Guyce0537b2010-06-29 21:05:21 -070020#include <GLES2/gl2.h>
21
Romain Guy7adaf3d2010-10-05 14:58:09 -070022#include <SkCanvas.h>
23
Romain Guyca89e2a2013-03-08 17:44:20 -080024#include <utils/Mutex.h>
Romain Guy9aaa8262010-09-08 15:15:43 -070025
Romain Guy713e1bb2012-10-16 18:44:09 -070026#include "Caches.h"
Romain Guyce0537b2010-06-29 21:05:21 -070027#include "TextureCache.h"
Romain Guyfb8b7632010-08-23 21:05:08 -070028#include "Properties.h"
Romain Guyce0537b2010-06-29 21:05:21 -070029
30namespace android {
31namespace uirenderer {
32
Romain Guy121e2242010-07-01 18:26:52 -070033///////////////////////////////////////////////////////////////////////////////
34// Constructors/destructor
35///////////////////////////////////////////////////////////////////////////////
36
Romain Guyfb8b7632010-08-23 21:05:08 -070037TextureCache::TextureCache():
Leon Scroggins IIId1ad5e62014-05-05 12:50:38 -040038 mCache(LruCache<const SkPixelRef*, Texture*>::kUnlimitedCapacity),
Romain Guyeca0ca22011-11-04 15:12:29 -070039 mSize(0), mMaxSize(MB(DEFAULT_TEXTURE_CACHE_SIZE)),
40 mFlushRate(DEFAULT_TEXTURE_CACHE_FLUSH_RATE) {
Romain Guyfb8b7632010-08-23 21:05:08 -070041 char property[PROPERTY_VALUE_MAX];
42 if (property_get(PROPERTY_TEXTURE_CACHE_SIZE, property, NULL) > 0) {
Romain Guyc9855a52011-01-21 21:14:15 -080043 INIT_LOGD(" Setting texture cache size to %sMB", property);
Romain Guyfb8b7632010-08-23 21:05:08 -070044 setMaxSize(MB(atof(property)));
45 } else {
Romain Guyc9855a52011-01-21 21:14:15 -080046 INIT_LOGD(" Using default texture cache size of %.2fMB", DEFAULT_TEXTURE_CACHE_SIZE);
Romain Guyfb8b7632010-08-23 21:05:08 -070047 }
48
Romain Guyeca0ca22011-11-04 15:12:29 -070049 if (property_get(PROPERTY_TEXTURE_CACHE_FLUSH_RATE, property, NULL) > 0) {
50 float flushRate = atof(property);
51 INIT_LOGD(" Setting texture cache flush rate to %.2f%%", flushRate * 100.0f);
52 setFlushRate(flushRate);
53 } else {
54 INIT_LOGD(" Using default texture cache flush rate of %.2f%%",
55 DEFAULT_TEXTURE_CACHE_FLUSH_RATE * 100.0f);
56 }
57
Romain Guyfb8b7632010-08-23 21:05:08 -070058 init();
59}
60
Romain Guy7d139ba2010-07-02 11:20:34 -070061TextureCache::TextureCache(uint32_t maxByteSize):
Leon Scroggins IIId1ad5e62014-05-05 12:50:38 -040062 mCache(LruCache<const SkPixelRef*, Texture*>::kUnlimitedCapacity),
Romain Guy121e2242010-07-01 18:26:52 -070063 mSize(0), mMaxSize(maxByteSize) {
Romain Guyfb8b7632010-08-23 21:05:08 -070064 init();
Romain Guyce0537b2010-06-29 21:05:21 -070065}
66
67TextureCache::~TextureCache() {
68 mCache.clear();
69}
70
Romain Guyfb8b7632010-08-23 21:05:08 -070071void TextureCache::init() {
72 mCache.setOnEntryRemovedListener(this);
73
74 glGetIntegerv(GL_MAX_TEXTURE_SIZE, &mMaxTextureSize);
Romain Guyf6834472011-01-23 13:32:12 -080075 INIT_LOGD(" Maximum texture dimension is %d pixels", mMaxTextureSize);
Romain Guye190aa62010-11-10 19:01:29 -080076
77 mDebugEnabled = readDebugLevel() & kDebugCaches;
Romain Guyfb8b7632010-08-23 21:05:08 -070078}
79
Romain Guy121e2242010-07-01 18:26:52 -070080///////////////////////////////////////////////////////////////////////////////
81// Size management
82///////////////////////////////////////////////////////////////////////////////
83
Romain Guy7d139ba2010-07-02 11:20:34 -070084uint32_t TextureCache::getSize() {
Romain Guy121e2242010-07-01 18:26:52 -070085 return mSize;
86}
87
Romain Guy7d139ba2010-07-02 11:20:34 -070088uint32_t TextureCache::getMaxSize() {
Romain Guy121e2242010-07-01 18:26:52 -070089 return mMaxSize;
90}
91
Romain Guy7d139ba2010-07-02 11:20:34 -070092void TextureCache::setMaxSize(uint32_t maxSize) {
Romain Guy121e2242010-07-01 18:26:52 -070093 mMaxSize = maxSize;
94 while (mSize > mMaxSize) {
95 mCache.removeOldest();
Romain Guyce0537b2010-06-29 21:05:21 -070096 }
97}
98
Romain Guyeca0ca22011-11-04 15:12:29 -070099void TextureCache::setFlushRate(float flushRate) {
100 mFlushRate = fmaxf(0.0f, fminf(1.0f, flushRate));
101}
102
Romain Guy121e2242010-07-01 18:26:52 -0700103///////////////////////////////////////////////////////////////////////////////
104// Callbacks
105///////////////////////////////////////////////////////////////////////////////
106
Leon Scroggins IIId1ad5e62014-05-05 12:50:38 -0400107void TextureCache::operator()(const SkPixelRef*&, Texture*& texture) {
Romain Guy9aaa8262010-09-08 15:15:43 -0700108 // This will be called already locked
Romain Guy121e2242010-07-01 18:26:52 -0700109 if (texture) {
Romain Guy9aaa8262010-09-08 15:15:43 -0700110 mSize -= texture->bitmapSize;
Romain Guy9e108412010-11-09 14:35:20 -0800111 TEXTURE_LOGD("TextureCache::callback: name, removed size, mSize = %d, %d, %d",
112 texture->id, texture->bitmapSize, mSize);
Romain Guye190aa62010-11-10 19:01:29 -0800113 if (mDebugEnabled) {
Steve Block5baa3a62011-12-20 16:23:08 +0000114 ALOGD("Texture deleted, size = %d", texture->bitmapSize);
Romain Guye190aa62010-11-10 19:01:29 -0800115 }
Romain Guybe1b1272013-06-06 14:02:54 -0700116 texture->deleteTexture();
Romain Guy121e2242010-07-01 18:26:52 -0700117 delete texture;
118 }
119}
120
121///////////////////////////////////////////////////////////////////////////////
122// Caching
123///////////////////////////////////////////////////////////////////////////////
124
John Reck860d1552014-04-11 19:15:05 -0700125void TextureCache::resetMarkInUse() {
Leon Scroggins IIId1ad5e62014-05-05 12:50:38 -0400126 LruCache<const SkPixelRef*, Texture*>::Iterator iter(mCache);
John Reck860d1552014-04-11 19:15:05 -0700127 while (iter.next()) {
128 iter.value()->isInUse = false;
129 }
130}
131
132bool TextureCache::canMakeTextureFromBitmap(const SkBitmap* bitmap) {
133 if (bitmap->width() > mMaxTextureSize || bitmap->height() > mMaxTextureSize) {
134 ALOGW("Bitmap too large to be uploaded into a texture (%dx%d, max=%dx%d)",
135 bitmap->width(), bitmap->height(), mMaxTextureSize, mMaxTextureSize);
136 return false;
137 }
138 return true;
139}
140
141// Returns a prepared Texture* that either is already in the cache or can fit
142// in the cache (and is thus added to the cache)
143Texture* TextureCache::getCachedTexture(const SkBitmap* bitmap) {
Leon Scroggins IIId1ad5e62014-05-05 12:50:38 -0400144 Texture* texture = mCache.get(bitmap->pixelRef());
Romain Guya2341a92010-09-08 18:04:33 -0700145
Romain Guyce0537b2010-06-29 21:05:21 -0700146 if (!texture) {
John Reck860d1552014-04-11 19:15:05 -0700147 if (!canMakeTextureFromBitmap(bitmap)) {
Romain Guy9cccc2b2010-08-07 23:46:15 -0700148 return NULL;
149 }
150
Romain Guy7d139ba2010-07-02 11:20:34 -0700151 const uint32_t size = bitmap->rowBytes() * bitmap->height();
John Reck860d1552014-04-11 19:15:05 -0700152 bool canCache = size < mMaxSize;
Romain Guy121e2242010-07-01 18:26:52 -0700153 // Don't even try to cache a bitmap that's bigger than the cache
John Reck860d1552014-04-11 19:15:05 -0700154 while (canCache && mSize + size > mMaxSize) {
155 Texture* oldest = mCache.peekOldestValue();
156 if (oldest && !oldest->isInUse) {
Romain Guy121e2242010-07-01 18:26:52 -0700157 mCache.removeOldest();
John Reck860d1552014-04-11 19:15:05 -0700158 } else {
159 canCache = false;
Romain Guy121e2242010-07-01 18:26:52 -0700160 }
161 }
162
John Reck860d1552014-04-11 19:15:05 -0700163 if (canCache) {
164 texture = new Texture();
165 texture->bitmapSize = size;
166 generateTexture(bitmap, texture, false);
Romain Guy121e2242010-07-01 18:26:52 -0700167
Romain Guy121e2242010-07-01 18:26:52 -0700168 mSize += size;
Romain Guy9e108412010-11-09 14:35:20 -0800169 TEXTURE_LOGD("TextureCache::get: create texture(%p): name, size, mSize = %d, %d, %d",
170 bitmap, texture->id, size, mSize);
Romain Guye190aa62010-11-10 19:01:29 -0800171 if (mDebugEnabled) {
Steve Block5baa3a62011-12-20 16:23:08 +0000172 ALOGD("Texture created, size = %d", size);
Romain Guye190aa62010-11-10 19:01:29 -0800173 }
Leon Scroggins IIId1ad5e62014-05-05 12:50:38 -0400174 mCache.put(bitmap->pixelRef(), texture);
Romain Guy121e2242010-07-01 18:26:52 -0700175 }
John Reck860d1552014-04-11 19:15:05 -0700176 } else if (!texture->isInUse && bitmap->getGenerationID() != texture->generation) {
177 // Texture was in the cache but is dirty, re-upload
178 // TODO: Re-adjust the cache size if the bitmap's dimensions have changed
Romain Guyfe880942010-06-30 16:05:32 -0700179 generateTexture(bitmap, texture, true);
Romain Guyce0537b2010-06-29 21:05:21 -0700180 }
Romain Guy22158e12010-08-06 11:18:34 -0700181
Romain Guyce0537b2010-06-29 21:05:21 -0700182 return texture;
183}
184
John Reck860d1552014-04-11 19:15:05 -0700185bool TextureCache::prefetchAndMarkInUse(const SkBitmap* bitmap) {
186 Texture* texture = getCachedTexture(bitmap);
187 if (texture) {
188 texture->isInUse = true;
189 }
190 return texture;
191}
192
193Texture* TextureCache::get(const SkBitmap* bitmap) {
194 Texture* texture = getCachedTexture(bitmap);
195
196 if (!texture) {
197 if (!canMakeTextureFromBitmap(bitmap)) {
198 return NULL;
199 }
200
201 const uint32_t size = bitmap->rowBytes() * bitmap->height();
202 texture = new Texture();
203 texture->bitmapSize = size;
204 generateTexture(bitmap, texture, false);
205 texture->cleanup = true;
206 }
207
208 return texture;
209}
210
Chris Craikd218a922014-01-02 17:13:34 -0800211Texture* TextureCache::getTransient(const SkBitmap* bitmap) {
Romain Guy8aa195d2013-06-04 18:00:09 -0700212 Texture* texture = new Texture();
Romain Guye651cc62012-05-14 19:44:40 -0700213 texture->bitmapSize = bitmap->rowBytes() * bitmap->height();
214 texture->cleanup = true;
215
216 generateTexture(bitmap, texture, false);
217
218 return texture;
219}
220
Chris Craikd218a922014-01-02 17:13:34 -0800221void TextureCache::remove(const SkBitmap* bitmap) {
Leon Scroggins IIId1ad5e62014-05-05 12:50:38 -0400222 mCache.remove(bitmap->pixelRef());
Romain Guyce0537b2010-06-29 21:05:21 -0700223}
224
Chris Craikd218a922014-01-02 17:13:34 -0800225void TextureCache::removeDeferred(const SkBitmap* bitmap) {
Romain Guy9aaa8262010-09-08 15:15:43 -0700226 Mutex::Autolock _l(mLock);
Romain Guyfe48f652010-11-11 15:36:56 -0800227 mGarbage.push(bitmap);
228}
229
230void TextureCache::clearGarbage() {
231 Mutex::Autolock _l(mLock);
232 size_t count = mGarbage.size();
233 for (size_t i = 0; i < count; i++) {
Sangkyu Lee36fad8f2014-01-09 14:11:57 +0900234 const SkBitmap* bitmap = mGarbage.itemAt(i);
Leon Scroggins IIId1ad5e62014-05-05 12:50:38 -0400235 mCache.remove(bitmap->pixelRef());
Sangkyu Lee36fad8f2014-01-09 14:11:57 +0900236 delete bitmap;
Romain Guyfe48f652010-11-11 15:36:56 -0800237 }
238 mGarbage.clear();
239}
240
241void TextureCache::clear() {
Romain Guyce0537b2010-06-29 21:05:21 -0700242 mCache.clear();
Romain Guy912a7b32011-07-26 18:57:28 -0700243 TEXTURE_LOGD("TextureCache:clear(), mSize = %d", mSize);
Romain Guyce0537b2010-06-29 21:05:21 -0700244}
245
Romain Guyeca0ca22011-11-04 15:12:29 -0700246void TextureCache::flush() {
247 if (mFlushRate >= 1.0f || mCache.size() == 0) return;
248 if (mFlushRate <= 0.0f) {
249 clear();
250 return;
251 }
252
253 uint32_t targetSize = uint32_t(mSize * mFlushRate);
254 TEXTURE_LOGD("TextureCache::flush: target size: %d", targetSize);
255
256 while (mSize > targetSize) {
257 mCache.removeOldest();
258 }
259}
260
Chris Craikd218a922014-01-02 17:13:34 -0800261void TextureCache::generateTexture(const SkBitmap* bitmap, Texture* texture, bool regenerate) {
Romain Guyc1396e92010-06-30 17:56:19 -0700262 SkAutoLockPixels alp(*bitmap);
Romain Guy9aaa8262010-09-08 15:15:43 -0700263
Romain Guyc1396e92010-06-30 17:56:19 -0700264 if (!bitmap->readyToDraw()) {
Steve Block3762c312012-01-06 19:20:56 +0000265 ALOGE("Cannot generate texture from bitmap");
Romain Guyc1396e92010-06-30 17:56:19 -0700266 return;
267 }
268
John Reckec4cefc2014-07-29 09:49:13 -0700269 ATRACE_CALL();
270
Romain Guy52439572012-10-17 12:14:11 -0700271 // We could also enable mipmapping if both bitmap dimensions are powers
272 // of 2 but we'd have to deal with size changes. Let's keep this simple
Romain Guy3bbacf22013-02-06 16:51:04 -0800273 const bool canMipMap = Extensions::getInstance().hasNPot();
Romain Guy52439572012-10-17 12:14:11 -0700274
Romain Guy713e1bb2012-10-16 18:44:09 -0700275 // If the texture had mipmap enabled but not anymore,
276 // force a glTexImage2D to discard the mipmap levels
Romain Guy29d89972010-09-22 16:10:57 -0700277 const bool resize = !regenerate || bitmap->width() != int(texture->width) ||
Romain Guy713e1bb2012-10-16 18:44:09 -0700278 bitmap->height() != int(texture->height) ||
Romain Guy52439572012-10-17 12:14:11 -0700279 (regenerate && canMipMap && texture->mipMap && !bitmap->hasHardwareMipMap());
Romain Guyce0537b2010-06-29 21:05:21 -0700280
Romain Guy8c749f82010-09-22 14:13:32 -0700281 if (!regenerate) {
Romain Guyfe880942010-06-30 16:05:32 -0700282 glGenTextures(1, &texture->id);
283 }
284
Romain Guy8c749f82010-09-22 14:13:32 -0700285 texture->generation = bitmap->getGenerationID();
286 texture->width = bitmap->width();
287 texture->height = bitmap->height();
288
Romain Guy8aa195d2013-06-04 18:00:09 -0700289 Caches::getInstance().bindTexture(texture->id);
Romain Guyc1396e92010-06-30 17:56:19 -0700290
Mike Reed1103b322014-07-08 12:36:44 -0400291 switch (bitmap->colorType()) {
292 case kAlpha_8_SkColorType:
Romain Guyd43b22d2012-10-16 11:25:06 -0700293 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
Lu, Shenghuac5e0a292013-11-27 20:16:43 +0800294 uploadToTexture(resize, GL_ALPHA, bitmap->rowBytesAsPixels(), bitmap->bytesPerPixel(),
Romain Guy318ae7b2013-09-24 18:44:54 -0700295 texture->width, texture->height, GL_UNSIGNED_BYTE, bitmap->getPixels());
Romain Guy8c749f82010-09-22 14:13:32 -0700296 texture->blend = true;
Romain Guybd0e6aa2010-07-22 18:50:12 -0700297 break;
Mike Reed1103b322014-07-08 12:36:44 -0400298 case kRGB_565_SkColorType:
Romain Guyd43b22d2012-10-16 11:25:06 -0700299 glPixelStorei(GL_UNPACK_ALIGNMENT, bitmap->bytesPerPixel());
Lu, Shenghuac5e0a292013-11-27 20:16:43 +0800300 uploadToTexture(resize, GL_RGB, bitmap->rowBytesAsPixels(), bitmap->bytesPerPixel(),
Romain Guy318ae7b2013-09-24 18:44:54 -0700301 texture->width, texture->height, GL_UNSIGNED_SHORT_5_6_5, bitmap->getPixels());
Romain Guyc1396e92010-06-30 17:56:19 -0700302 texture->blend = false;
Romain Guyc1396e92010-06-30 17:56:19 -0700303 break;
Mike Reed1103b322014-07-08 12:36:44 -0400304 case kN32_SkColorType:
Romain Guyd43b22d2012-10-16 11:25:06 -0700305 glPixelStorei(GL_UNPACK_ALIGNMENT, bitmap->bytesPerPixel());
Lu, Shenghuac5e0a292013-11-27 20:16:43 +0800306 uploadToTexture(resize, GL_RGBA, bitmap->rowBytesAsPixels(), bitmap->bytesPerPixel(),
Romain Guy318ae7b2013-09-24 18:44:54 -0700307 texture->width, texture->height, GL_UNSIGNED_BYTE, bitmap->getPixels());
Romain Guye9e7fd02010-08-19 14:45:42 -0700308 // Do this after calling getPixels() to make sure Skia's deferred
309 // decoding happened
310 texture->blend = !bitmap->isOpaque();
Romain Guyc1396e92010-06-30 17:56:19 -0700311 break;
Mike Reed1103b322014-07-08 12:36:44 -0400312 case kARGB_4444_SkColorType:
313 case kIndex_8_SkColorType:
Romain Guyd43b22d2012-10-16 11:25:06 -0700314 glPixelStorei(GL_UNPACK_ALIGNMENT, bitmap->bytesPerPixel());
Romain Guy5b3b3522010-10-27 18:57:51 -0700315 uploadLoFiTexture(resize, bitmap, texture->width, texture->height);
Romain Guyb37cbec2011-02-24 17:21:29 -0800316 texture->blend = !bitmap->isOpaque();
Romain Guy5b3b3522010-10-27 18:57:51 -0700317 break;
Romain Guyc1396e92010-06-30 17:56:19 -0700318 default:
Mike Reed1103b322014-07-08 12:36:44 -0400319 ALOGW("Unsupported bitmap colorType: %d", bitmap->colorType());
Romain Guyc1396e92010-06-30 17:56:19 -0700320 break;
321 }
Romain Guyce0537b2010-06-29 21:05:21 -0700322
Romain Guy52439572012-10-17 12:14:11 -0700323 if (canMipMap) {
Romain Guy713e1bb2012-10-16 18:44:09 -0700324 texture->mipMap = bitmap->hasHardwareMipMap();
325 if (texture->mipMap) {
326 glGenerateMipmap(GL_TEXTURE_2D);
327 }
328 }
329
Romain Guyd21b6e12011-11-30 20:21:23 -0800330 if (!regenerate) {
331 texture->setFilter(GL_NEAREST);
332 texture->setWrap(GL_CLAMP_TO_EDGE);
333 }
Romain Guyce0537b2010-06-29 21:05:21 -0700334}
335
Chris Craikd218a922014-01-02 17:13:34 -0800336void TextureCache::uploadLoFiTexture(bool resize, const SkBitmap* bitmap,
Romain Guy7adaf3d2010-10-05 14:58:09 -0700337 uint32_t width, uint32_t height) {
338 SkBitmap rgbaBitmap;
Mike Reedb9330552014-06-16 17:31:48 -0400339 rgbaBitmap.allocPixels(SkImageInfo::MakeN32(width, height, bitmap->alphaType()));
Romain Guy7adaf3d2010-10-05 14:58:09 -0700340 rgbaBitmap.eraseColor(0);
341
342 SkCanvas canvas(rgbaBitmap);
343 canvas.drawBitmap(*bitmap, 0.0f, 0.0f, NULL);
344
Lu, Shenghuac5e0a292013-11-27 20:16:43 +0800345 uploadToTexture(resize, GL_RGBA, rgbaBitmap.rowBytesAsPixels(), rgbaBitmap.bytesPerPixel(),
346 width, height, GL_UNSIGNED_BYTE, rgbaBitmap.getPixels());
Romain Guy7adaf3d2010-10-05 14:58:09 -0700347}
348
Lu, Shenghuac5e0a292013-11-27 20:16:43 +0800349void TextureCache::uploadToTexture(bool resize, GLenum format, GLsizei stride, GLsizei bpp,
Romain Guy318ae7b2013-09-24 18:44:54 -0700350 GLsizei width, GLsizei height, GLenum type, const GLvoid * data) {
Romain Guy318ae7b2013-09-24 18:44:54 -0700351 const bool useStride = stride != width && Extensions::getInstance().hasUnpackRowLength();
Lu, Shenghuac5e0a292013-11-27 20:16:43 +0800352 if ((stride == width) || useStride) {
353 if (useStride) {
354 glPixelStorei(GL_UNPACK_ROW_LENGTH, stride);
355 }
Romain Guy318ae7b2013-09-24 18:44:54 -0700356
Lu, Shenghuac5e0a292013-11-27 20:16:43 +0800357 if (resize) {
358 glTexImage2D(GL_TEXTURE_2D, 0, format, width, height, 0, format, type, data);
359 } else {
360 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, format, type, data);
361 }
362
363 if (useStride) {
364 glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
365 }
Romain Guy8c749f82010-09-22 14:13:32 -0700366 } else {
Lu, Shenghuac5e0a292013-11-27 20:16:43 +0800367 // With OpenGL ES 2.0 we need to copy the bitmap in a temporary buffer
368 // if the stride doesn't match the width
Romain Guy318ae7b2013-09-24 18:44:54 -0700369
Lu, Shenghuac5e0a292013-11-27 20:16:43 +0800370 GLvoid * temp = (GLvoid *) malloc(width * height * bpp);
371 if (!temp) return;
372
373 uint8_t * pDst = (uint8_t *)temp;
374 uint8_t * pSrc = (uint8_t *)data;
375 for (GLsizei i = 0; i < height; i++) {
376 memcpy(pDst, pSrc, width * bpp);
377 pDst += width * bpp;
378 pSrc += stride * bpp;
379 }
380
381 if (resize) {
382 glTexImage2D(GL_TEXTURE_2D, 0, format, width, height, 0, format, type, temp);
383 } else {
384 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, format, type, temp);
385 }
386
387 free(temp);
Romain Guy318ae7b2013-09-24 18:44:54 -0700388 }
Romain Guy8c749f82010-09-22 14:13:32 -0700389}
390
Romain Guyce0537b2010-06-29 21:05:21 -0700391}; // namespace uirenderer
392}; // namespace android