blob: 0cd120a581da96c67b08f95f7dba15feecd56aeb [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"
Tom Hudson2dc236b2014-10-15 15:46:42 -040027#include "Texture.h"
Romain Guyce0537b2010-06-29 21:05:21 -070028#include "TextureCache.h"
Romain Guyfb8b7632010-08-23 21:05:08 -070029#include "Properties.h"
Romain Guyce0537b2010-06-29 21:05:21 -070030
31namespace android {
32namespace uirenderer {
33
Romain Guy121e2242010-07-01 18:26:52 -070034///////////////////////////////////////////////////////////////////////////////
35// Constructors/destructor
36///////////////////////////////////////////////////////////////////////////////
37
Romain Guyfb8b7632010-08-23 21:05:08 -070038TextureCache::TextureCache():
Leon Scroggins IIId1ad5e62014-05-05 12:50:38 -040039 mCache(LruCache<const SkPixelRef*, Texture*>::kUnlimitedCapacity),
Romain Guyeca0ca22011-11-04 15:12:29 -070040 mSize(0), mMaxSize(MB(DEFAULT_TEXTURE_CACHE_SIZE)),
41 mFlushRate(DEFAULT_TEXTURE_CACHE_FLUSH_RATE) {
Romain Guyfb8b7632010-08-23 21:05:08 -070042 char property[PROPERTY_VALUE_MAX];
43 if (property_get(PROPERTY_TEXTURE_CACHE_SIZE, property, NULL) > 0) {
Romain Guyc9855a52011-01-21 21:14:15 -080044 INIT_LOGD(" Setting texture cache size to %sMB", property);
Romain Guyfb8b7632010-08-23 21:05:08 -070045 setMaxSize(MB(atof(property)));
46 } else {
Romain Guyc9855a52011-01-21 21:14:15 -080047 INIT_LOGD(" Using default texture cache size of %.2fMB", DEFAULT_TEXTURE_CACHE_SIZE);
Romain Guyfb8b7632010-08-23 21:05:08 -070048 }
49
Romain Guyeca0ca22011-11-04 15:12:29 -070050 if (property_get(PROPERTY_TEXTURE_CACHE_FLUSH_RATE, property, NULL) > 0) {
51 float flushRate = atof(property);
52 INIT_LOGD(" Setting texture cache flush rate to %.2f%%", flushRate * 100.0f);
53 setFlushRate(flushRate);
54 } else {
55 INIT_LOGD(" Using default texture cache flush rate of %.2f%%",
56 DEFAULT_TEXTURE_CACHE_FLUSH_RATE * 100.0f);
57 }
58
Romain Guyfb8b7632010-08-23 21:05:08 -070059 init();
60}
61
Romain Guy7d139ba2010-07-02 11:20:34 -070062TextureCache::TextureCache(uint32_t maxByteSize):
Leon Scroggins IIId1ad5e62014-05-05 12:50:38 -040063 mCache(LruCache<const SkPixelRef*, Texture*>::kUnlimitedCapacity),
Romain Guy121e2242010-07-01 18:26:52 -070064 mSize(0), mMaxSize(maxByteSize) {
Romain Guyfb8b7632010-08-23 21:05:08 -070065 init();
Romain Guyce0537b2010-06-29 21:05:21 -070066}
67
68TextureCache::~TextureCache() {
69 mCache.clear();
70}
71
Romain Guyfb8b7632010-08-23 21:05:08 -070072void TextureCache::init() {
73 mCache.setOnEntryRemovedListener(this);
74
75 glGetIntegerv(GL_MAX_TEXTURE_SIZE, &mMaxTextureSize);
Romain Guyf6834472011-01-23 13:32:12 -080076 INIT_LOGD(" Maximum texture dimension is %d pixels", mMaxTextureSize);
Romain Guye190aa62010-11-10 19:01:29 -080077
78 mDebugEnabled = readDebugLevel() & kDebugCaches;
Romain Guyfb8b7632010-08-23 21:05:08 -070079}
80
Romain Guy121e2242010-07-01 18:26:52 -070081///////////////////////////////////////////////////////////////////////////////
82// Size management
83///////////////////////////////////////////////////////////////////////////////
84
Romain Guy7d139ba2010-07-02 11:20:34 -070085uint32_t TextureCache::getSize() {
Romain Guy121e2242010-07-01 18:26:52 -070086 return mSize;
87}
88
Romain Guy7d139ba2010-07-02 11:20:34 -070089uint32_t TextureCache::getMaxSize() {
Romain Guy121e2242010-07-01 18:26:52 -070090 return mMaxSize;
91}
92
Romain Guy7d139ba2010-07-02 11:20:34 -070093void TextureCache::setMaxSize(uint32_t maxSize) {
Romain Guy121e2242010-07-01 18:26:52 -070094 mMaxSize = maxSize;
95 while (mSize > mMaxSize) {
96 mCache.removeOldest();
Romain Guyce0537b2010-06-29 21:05:21 -070097 }
98}
99
Romain Guyeca0ca22011-11-04 15:12:29 -0700100void TextureCache::setFlushRate(float flushRate) {
101 mFlushRate = fmaxf(0.0f, fminf(1.0f, flushRate));
102}
103
Romain Guy121e2242010-07-01 18:26:52 -0700104///////////////////////////////////////////////////////////////////////////////
105// Callbacks
106///////////////////////////////////////////////////////////////////////////////
107
Leon Scroggins IIId1ad5e62014-05-05 12:50:38 -0400108void TextureCache::operator()(const SkPixelRef*&, Texture*& texture) {
Romain Guy9aaa8262010-09-08 15:15:43 -0700109 // This will be called already locked
Romain Guy121e2242010-07-01 18:26:52 -0700110 if (texture) {
Romain Guy9aaa8262010-09-08 15:15:43 -0700111 mSize -= texture->bitmapSize;
Romain Guy9e108412010-11-09 14:35:20 -0800112 TEXTURE_LOGD("TextureCache::callback: name, removed size, mSize = %d, %d, %d",
113 texture->id, texture->bitmapSize, mSize);
Romain Guye190aa62010-11-10 19:01:29 -0800114 if (mDebugEnabled) {
Steve Block5baa3a62011-12-20 16:23:08 +0000115 ALOGD("Texture deleted, size = %d", texture->bitmapSize);
Romain Guye190aa62010-11-10 19:01:29 -0800116 }
Romain Guybe1b1272013-06-06 14:02:54 -0700117 texture->deleteTexture();
Romain Guy121e2242010-07-01 18:26:52 -0700118 delete texture;
119 }
120}
121
122///////////////////////////////////////////////////////////////////////////////
123// Caching
124///////////////////////////////////////////////////////////////////////////////
125
John Reck860d1552014-04-11 19:15:05 -0700126void TextureCache::resetMarkInUse() {
Leon Scroggins IIId1ad5e62014-05-05 12:50:38 -0400127 LruCache<const SkPixelRef*, Texture*>::Iterator iter(mCache);
John Reck860d1552014-04-11 19:15:05 -0700128 while (iter.next()) {
129 iter.value()->isInUse = false;
130 }
131}
132
133bool TextureCache::canMakeTextureFromBitmap(const SkBitmap* bitmap) {
134 if (bitmap->width() > mMaxTextureSize || bitmap->height() > mMaxTextureSize) {
135 ALOGW("Bitmap too large to be uploaded into a texture (%dx%d, max=%dx%d)",
136 bitmap->width(), bitmap->height(), mMaxTextureSize, mMaxTextureSize);
137 return false;
138 }
139 return true;
140}
141
142// Returns a prepared Texture* that either is already in the cache or can fit
143// in the cache (and is thus added to the cache)
144Texture* TextureCache::getCachedTexture(const SkBitmap* bitmap) {
Leon Scroggins IIId1ad5e62014-05-05 12:50:38 -0400145 Texture* texture = mCache.get(bitmap->pixelRef());
Romain Guya2341a92010-09-08 18:04:33 -0700146
Romain Guyce0537b2010-06-29 21:05:21 -0700147 if (!texture) {
John Reck860d1552014-04-11 19:15:05 -0700148 if (!canMakeTextureFromBitmap(bitmap)) {
Romain Guy9cccc2b2010-08-07 23:46:15 -0700149 return NULL;
150 }
151
Romain Guy7d139ba2010-07-02 11:20:34 -0700152 const uint32_t size = bitmap->rowBytes() * bitmap->height();
John Reck860d1552014-04-11 19:15:05 -0700153 bool canCache = size < mMaxSize;
Romain Guy121e2242010-07-01 18:26:52 -0700154 // Don't even try to cache a bitmap that's bigger than the cache
John Reck860d1552014-04-11 19:15:05 -0700155 while (canCache && mSize + size > mMaxSize) {
156 Texture* oldest = mCache.peekOldestValue();
157 if (oldest && !oldest->isInUse) {
Romain Guy121e2242010-07-01 18:26:52 -0700158 mCache.removeOldest();
John Reck860d1552014-04-11 19:15:05 -0700159 } else {
160 canCache = false;
Romain Guy121e2242010-07-01 18:26:52 -0700161 }
162 }
163
John Reck860d1552014-04-11 19:15:05 -0700164 if (canCache) {
165 texture = new Texture();
166 texture->bitmapSize = size;
167 generateTexture(bitmap, texture, false);
Romain Guy121e2242010-07-01 18:26:52 -0700168
Romain Guy121e2242010-07-01 18:26:52 -0700169 mSize += size;
Romain Guy9e108412010-11-09 14:35:20 -0800170 TEXTURE_LOGD("TextureCache::get: create texture(%p): name, size, mSize = %d, %d, %d",
171 bitmap, texture->id, size, mSize);
Romain Guye190aa62010-11-10 19:01:29 -0800172 if (mDebugEnabled) {
Steve Block5baa3a62011-12-20 16:23:08 +0000173 ALOGD("Texture created, size = %d", size);
Romain Guye190aa62010-11-10 19:01:29 -0800174 }
Leon Scroggins IIId1ad5e62014-05-05 12:50:38 -0400175 mCache.put(bitmap->pixelRef(), texture);
Romain Guy121e2242010-07-01 18:26:52 -0700176 }
John Reck860d1552014-04-11 19:15:05 -0700177 } else if (!texture->isInUse && bitmap->getGenerationID() != texture->generation) {
178 // Texture was in the cache but is dirty, re-upload
179 // TODO: Re-adjust the cache size if the bitmap's dimensions have changed
Romain Guyfe880942010-06-30 16:05:32 -0700180 generateTexture(bitmap, texture, true);
Romain Guyce0537b2010-06-29 21:05:21 -0700181 }
Romain Guy22158e12010-08-06 11:18:34 -0700182
Romain Guyce0537b2010-06-29 21:05:21 -0700183 return texture;
184}
185
John Reck860d1552014-04-11 19:15:05 -0700186bool TextureCache::prefetchAndMarkInUse(const SkBitmap* bitmap) {
187 Texture* texture = getCachedTexture(bitmap);
188 if (texture) {
189 texture->isInUse = true;
190 }
191 return texture;
192}
193
194Texture* TextureCache::get(const SkBitmap* bitmap) {
195 Texture* texture = getCachedTexture(bitmap);
196
197 if (!texture) {
198 if (!canMakeTextureFromBitmap(bitmap)) {
199 return NULL;
200 }
201
202 const uint32_t size = bitmap->rowBytes() * bitmap->height();
203 texture = new Texture();
204 texture->bitmapSize = size;
205 generateTexture(bitmap, texture, false);
206 texture->cleanup = true;
207 }
208
209 return texture;
210}
211
Chris Craikd218a922014-01-02 17:13:34 -0800212Texture* TextureCache::getTransient(const SkBitmap* bitmap) {
Romain Guy8aa195d2013-06-04 18:00:09 -0700213 Texture* texture = new Texture();
Romain Guye651cc62012-05-14 19:44:40 -0700214 texture->bitmapSize = bitmap->rowBytes() * bitmap->height();
215 texture->cleanup = true;
216
217 generateTexture(bitmap, texture, false);
218
219 return texture;
220}
221
Chris Craikd218a922014-01-02 17:13:34 -0800222void TextureCache::remove(const SkBitmap* bitmap) {
Leon Scroggins IIId1ad5e62014-05-05 12:50:38 -0400223 mCache.remove(bitmap->pixelRef());
Romain Guyce0537b2010-06-29 21:05:21 -0700224}
225
Chris Craikd218a922014-01-02 17:13:34 -0800226void TextureCache::removeDeferred(const SkBitmap* bitmap) {
Romain Guy9aaa8262010-09-08 15:15:43 -0700227 Mutex::Autolock _l(mLock);
Romain Guyfe48f652010-11-11 15:36:56 -0800228 mGarbage.push(bitmap);
229}
230
231void TextureCache::clearGarbage() {
232 Mutex::Autolock _l(mLock);
233 size_t count = mGarbage.size();
234 for (size_t i = 0; i < count; i++) {
Sangkyu Lee36fad8f2014-01-09 14:11:57 +0900235 const SkBitmap* bitmap = mGarbage.itemAt(i);
Leon Scroggins IIId1ad5e62014-05-05 12:50:38 -0400236 mCache.remove(bitmap->pixelRef());
Sangkyu Lee36fad8f2014-01-09 14:11:57 +0900237 delete bitmap;
Romain Guyfe48f652010-11-11 15:36:56 -0800238 }
239 mGarbage.clear();
240}
241
242void TextureCache::clear() {
Romain Guyce0537b2010-06-29 21:05:21 -0700243 mCache.clear();
Romain Guy912a7b32011-07-26 18:57:28 -0700244 TEXTURE_LOGD("TextureCache:clear(), mSize = %d", mSize);
Romain Guyce0537b2010-06-29 21:05:21 -0700245}
246
Romain Guyeca0ca22011-11-04 15:12:29 -0700247void TextureCache::flush() {
248 if (mFlushRate >= 1.0f || mCache.size() == 0) return;
249 if (mFlushRate <= 0.0f) {
250 clear();
251 return;
252 }
253
254 uint32_t targetSize = uint32_t(mSize * mFlushRate);
255 TEXTURE_LOGD("TextureCache::flush: target size: %d", targetSize);
256
257 while (mSize > targetSize) {
258 mCache.removeOldest();
259 }
260}
261
Chris Craikd218a922014-01-02 17:13:34 -0800262void TextureCache::generateTexture(const SkBitmap* bitmap, Texture* texture, bool regenerate) {
Romain Guyc1396e92010-06-30 17:56:19 -0700263 SkAutoLockPixels alp(*bitmap);
Romain Guy9aaa8262010-09-08 15:15:43 -0700264
Romain Guyc1396e92010-06-30 17:56:19 -0700265 if (!bitmap->readyToDraw()) {
Steve Block3762c312012-01-06 19:20:56 +0000266 ALOGE("Cannot generate texture from bitmap");
Romain Guyc1396e92010-06-30 17:56:19 -0700267 return;
268 }
269
John Reckec4cefc2014-07-29 09:49:13 -0700270 ATRACE_CALL();
271
Romain Guy52439572012-10-17 12:14:11 -0700272 // We could also enable mipmapping if both bitmap dimensions are powers
273 // of 2 but we'd have to deal with size changes. Let's keep this simple
Romain Guy3bbacf22013-02-06 16:51:04 -0800274 const bool canMipMap = Extensions::getInstance().hasNPot();
Romain Guy52439572012-10-17 12:14:11 -0700275
Romain Guy713e1bb2012-10-16 18:44:09 -0700276 // If the texture had mipmap enabled but not anymore,
277 // force a glTexImage2D to discard the mipmap levels
Romain Guy29d89972010-09-22 16:10:57 -0700278 const bool resize = !regenerate || bitmap->width() != int(texture->width) ||
Romain Guy713e1bb2012-10-16 18:44:09 -0700279 bitmap->height() != int(texture->height) ||
Romain Guy52439572012-10-17 12:14:11 -0700280 (regenerate && canMipMap && texture->mipMap && !bitmap->hasHardwareMipMap());
Romain Guyce0537b2010-06-29 21:05:21 -0700281
Romain Guy8c749f82010-09-22 14:13:32 -0700282 if (!regenerate) {
Romain Guyfe880942010-06-30 16:05:32 -0700283 glGenTextures(1, &texture->id);
284 }
285
Romain Guy8c749f82010-09-22 14:13:32 -0700286 texture->generation = bitmap->getGenerationID();
287 texture->width = bitmap->width();
288 texture->height = bitmap->height();
289
Romain Guy8aa195d2013-06-04 18:00:09 -0700290 Caches::getInstance().bindTexture(texture->id);
Romain Guyc1396e92010-06-30 17:56:19 -0700291
Mike Reed1103b322014-07-08 12:36:44 -0400292 switch (bitmap->colorType()) {
293 case kAlpha_8_SkColorType:
Romain Guyd43b22d2012-10-16 11:25:06 -0700294 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
Lu, Shenghuac5e0a292013-11-27 20:16:43 +0800295 uploadToTexture(resize, GL_ALPHA, bitmap->rowBytesAsPixels(), bitmap->bytesPerPixel(),
Romain Guy318ae7b2013-09-24 18:44:54 -0700296 texture->width, texture->height, GL_UNSIGNED_BYTE, bitmap->getPixels());
Romain Guy8c749f82010-09-22 14:13:32 -0700297 texture->blend = true;
Romain Guybd0e6aa2010-07-22 18:50:12 -0700298 break;
Mike Reed1103b322014-07-08 12:36:44 -0400299 case kRGB_565_SkColorType:
Romain Guyd43b22d2012-10-16 11:25:06 -0700300 glPixelStorei(GL_UNPACK_ALIGNMENT, bitmap->bytesPerPixel());
Lu, Shenghuac5e0a292013-11-27 20:16:43 +0800301 uploadToTexture(resize, GL_RGB, bitmap->rowBytesAsPixels(), bitmap->bytesPerPixel(),
Romain Guy318ae7b2013-09-24 18:44:54 -0700302 texture->width, texture->height, GL_UNSIGNED_SHORT_5_6_5, bitmap->getPixels());
Romain Guyc1396e92010-06-30 17:56:19 -0700303 texture->blend = false;
Romain Guyc1396e92010-06-30 17:56:19 -0700304 break;
Mike Reed1103b322014-07-08 12:36:44 -0400305 case kN32_SkColorType:
Romain Guyd43b22d2012-10-16 11:25:06 -0700306 glPixelStorei(GL_UNPACK_ALIGNMENT, bitmap->bytesPerPixel());
Lu, Shenghuac5e0a292013-11-27 20:16:43 +0800307 uploadToTexture(resize, GL_RGBA, bitmap->rowBytesAsPixels(), bitmap->bytesPerPixel(),
Romain Guy318ae7b2013-09-24 18:44:54 -0700308 texture->width, texture->height, GL_UNSIGNED_BYTE, bitmap->getPixels());
Romain Guye9e7fd02010-08-19 14:45:42 -0700309 // Do this after calling getPixels() to make sure Skia's deferred
310 // decoding happened
311 texture->blend = !bitmap->isOpaque();
Romain Guyc1396e92010-06-30 17:56:19 -0700312 break;
Mike Reed1103b322014-07-08 12:36:44 -0400313 case kARGB_4444_SkColorType:
314 case kIndex_8_SkColorType:
Romain Guyd43b22d2012-10-16 11:25:06 -0700315 glPixelStorei(GL_UNPACK_ALIGNMENT, bitmap->bytesPerPixel());
Romain Guy5b3b3522010-10-27 18:57:51 -0700316 uploadLoFiTexture(resize, bitmap, texture->width, texture->height);
Romain Guyb37cbec2011-02-24 17:21:29 -0800317 texture->blend = !bitmap->isOpaque();
Romain Guy5b3b3522010-10-27 18:57:51 -0700318 break;
Romain Guyc1396e92010-06-30 17:56:19 -0700319 default:
Mike Reed1103b322014-07-08 12:36:44 -0400320 ALOGW("Unsupported bitmap colorType: %d", bitmap->colorType());
Romain Guyc1396e92010-06-30 17:56:19 -0700321 break;
322 }
Romain Guyce0537b2010-06-29 21:05:21 -0700323
Romain Guy52439572012-10-17 12:14:11 -0700324 if (canMipMap) {
Romain Guy713e1bb2012-10-16 18:44:09 -0700325 texture->mipMap = bitmap->hasHardwareMipMap();
326 if (texture->mipMap) {
327 glGenerateMipmap(GL_TEXTURE_2D);
328 }
329 }
330
Romain Guyd21b6e12011-11-30 20:21:23 -0800331 if (!regenerate) {
332 texture->setFilter(GL_NEAREST);
333 texture->setWrap(GL_CLAMP_TO_EDGE);
334 }
Romain Guyce0537b2010-06-29 21:05:21 -0700335}
336
Chris Craikd218a922014-01-02 17:13:34 -0800337void TextureCache::uploadLoFiTexture(bool resize, const SkBitmap* bitmap,
Romain Guy7adaf3d2010-10-05 14:58:09 -0700338 uint32_t width, uint32_t height) {
339 SkBitmap rgbaBitmap;
Mike Reedb9330552014-06-16 17:31:48 -0400340 rgbaBitmap.allocPixels(SkImageInfo::MakeN32(width, height, bitmap->alphaType()));
Romain Guy7adaf3d2010-10-05 14:58:09 -0700341 rgbaBitmap.eraseColor(0);
342
343 SkCanvas canvas(rgbaBitmap);
344 canvas.drawBitmap(*bitmap, 0.0f, 0.0f, NULL);
345
Lu, Shenghuac5e0a292013-11-27 20:16:43 +0800346 uploadToTexture(resize, GL_RGBA, rgbaBitmap.rowBytesAsPixels(), rgbaBitmap.bytesPerPixel(),
347 width, height, GL_UNSIGNED_BYTE, rgbaBitmap.getPixels());
Romain Guy7adaf3d2010-10-05 14:58:09 -0700348}
349
Lu, Shenghuac5e0a292013-11-27 20:16:43 +0800350void TextureCache::uploadToTexture(bool resize, GLenum format, GLsizei stride, GLsizei bpp,
Romain Guy318ae7b2013-09-24 18:44:54 -0700351 GLsizei width, GLsizei height, GLenum type, const GLvoid * data) {
Romain Guy318ae7b2013-09-24 18:44:54 -0700352 const bool useStride = stride != width && Extensions::getInstance().hasUnpackRowLength();
Lu, Shenghuac5e0a292013-11-27 20:16:43 +0800353 if ((stride == width) || useStride) {
354 if (useStride) {
355 glPixelStorei(GL_UNPACK_ROW_LENGTH, stride);
356 }
Romain Guy318ae7b2013-09-24 18:44:54 -0700357
Lu, Shenghuac5e0a292013-11-27 20:16:43 +0800358 if (resize) {
359 glTexImage2D(GL_TEXTURE_2D, 0, format, width, height, 0, format, type, data);
360 } else {
361 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, format, type, data);
362 }
363
364 if (useStride) {
365 glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
366 }
Romain Guy8c749f82010-09-22 14:13:32 -0700367 } else {
Lu, Shenghuac5e0a292013-11-27 20:16:43 +0800368 // With OpenGL ES 2.0 we need to copy the bitmap in a temporary buffer
369 // if the stride doesn't match the width
Romain Guy318ae7b2013-09-24 18:44:54 -0700370
Lu, Shenghuac5e0a292013-11-27 20:16:43 +0800371 GLvoid * temp = (GLvoid *) malloc(width * height * bpp);
372 if (!temp) return;
373
374 uint8_t * pDst = (uint8_t *)temp;
375 uint8_t * pSrc = (uint8_t *)data;
376 for (GLsizei i = 0; i < height; i++) {
377 memcpy(pDst, pSrc, width * bpp);
378 pDst += width * bpp;
379 pSrc += stride * bpp;
380 }
381
382 if (resize) {
383 glTexImage2D(GL_TEXTURE_2D, 0, format, width, height, 0, format, type, temp);
384 } else {
385 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, format, type, temp);
386 }
387
388 free(temp);
Romain Guy318ae7b2013-09-24 18:44:54 -0700389 }
Romain Guy8c749f82010-09-22 14:13:32 -0700390}
391
Romain Guyce0537b2010-06-29 21:05:21 -0700392}; // namespace uirenderer
393}; // namespace android