diff options
| -rw-r--r-- | libs/hwui/OpenGLRenderer.cpp | 9 | ||||
| -rw-r--r-- | libs/hwui/PathCache.cpp | 3 | ||||
| -rw-r--r-- | libs/hwui/PathCache.h | 3 | ||||
| -rw-r--r-- | libs/hwui/Texture.h | 22 | ||||
| -rw-r--r-- | libs/hwui/TextureCache.cpp | 4 |
5 files changed, 38 insertions, 3 deletions
diff --git a/libs/hwui/OpenGLRenderer.cpp b/libs/hwui/OpenGLRenderer.cpp index a72045b44b2f..db8c8637aa67 100644 --- a/libs/hwui/OpenGLRenderer.cpp +++ b/libs/hwui/OpenGLRenderer.cpp @@ -436,6 +436,8 @@ void OpenGLRenderer::drawBitmap(SkBitmap* bitmap, float left, float top, const S } const Texture* texture = mTextureCache.get(bitmap); + const AutoTexture autoCleanup(texture); + drawTextureRect(left, top, right, bottom, texture, paint); } @@ -449,6 +451,8 @@ void OpenGLRenderer::drawBitmap(SkBitmap* bitmap, const SkMatrix* matrix, const } const Texture* texture = mTextureCache.get(bitmap); + const AutoTexture autoCleanup(texture); + drawTextureRect(r.left, r.top, r.right, r.bottom, texture, paint); } @@ -461,6 +465,7 @@ void OpenGLRenderer::drawBitmap(SkBitmap* bitmap, } const Texture* texture = mTextureCache.get(bitmap); + const AutoTexture autoCleanup(texture); const float width = texture->width; const float height = texture->height; @@ -484,6 +489,7 @@ void OpenGLRenderer::drawPatch(SkBitmap* bitmap, Res_png_9patch* patch, } const Texture* texture = mTextureCache.get(bitmap); + const AutoTexture autoCleanup(texture); int alpha; SkXfermode::Mode mode; @@ -610,7 +616,8 @@ void OpenGLRenderer::drawPath(SkPath* path, SkPaint* paint) { GLuint textureUnit = 0; glActiveTexture(gTextureUnits[textureUnit]); - PathTexture* texture = mPathCache.get(path, paint); + const PathTexture* texture = mPathCache.get(path, paint); + const AutoTexture autoCleanup(texture); int alpha; SkXfermode::Mode mode; diff --git a/libs/hwui/PathCache.cpp b/libs/hwui/PathCache.cpp index 67a5f923d598..fa6ea2591cc8 100644 --- a/libs/hwui/PathCache.cpp +++ b/libs/hwui/PathCache.cpp @@ -88,7 +88,6 @@ PathTexture* PathCache::get(SkPath* path, SkPaint* paint) { texture = addTexture(entry, path, paint); } - // TODO: Do something to destroy the texture object if it's too big for the cache return texture; } @@ -129,6 +128,8 @@ PathTexture* PathCache::addTexture(const PathCacheEntry& entry, if (size < mMaxSize) { mSize += size; mCache.put(entry, texture); + } else { + texture->cleanup = true; } return texture; diff --git a/libs/hwui/PathCache.h b/libs/hwui/PathCache.h index 87a9141c8d96..206fb49ca4e7 100644 --- a/libs/hwui/PathCache.h +++ b/libs/hwui/PathCache.h @@ -71,6 +71,9 @@ struct PathCacheEntry { * Alpha texture used to represent a path. */ struct PathTexture: public Texture { + PathTexture(): Texture() { + } + /** * Left coordinate of the path bounds. */ diff --git a/libs/hwui/Texture.h b/libs/hwui/Texture.h index d37013d683ba..90f548b5621d 100644 --- a/libs/hwui/Texture.h +++ b/libs/hwui/Texture.h @@ -26,6 +26,10 @@ namespace uirenderer { * Represents an OpenGL texture. */ struct Texture { + Texture() { + cleanup = false; + } + /** * Name of the texture. */ @@ -46,8 +50,26 @@ struct Texture { * Height of the backing bitmap. */ uint32_t height; + /** + * Indicates whether this texture should be cleaned up after use. + */ + bool cleanup; }; // struct Texture +class AutoTexture { +public: + AutoTexture(const Texture* texture): mTexture(texture) { } + ~AutoTexture() { + if (mTexture && mTexture->cleanup) { + glDeleteTextures(1, &mTexture->id); + delete mTexture; + } + } + +private: + const Texture* mTexture; +}; // class AutoTexture + }; // namespace uirenderer }; // namespace android diff --git a/libs/hwui/TextureCache.cpp b/libs/hwui/TextureCache.cpp index 4975edb46789..59903b70a6a1 100644 --- a/libs/hwui/TextureCache.cpp +++ b/libs/hwui/TextureCache.cpp @@ -93,11 +93,13 @@ Texture* TextureCache::get(SkBitmap* bitmap) { if (size < mMaxSize) { mSize += size; mCache.put(bitmap, texture); + } else { + texture->cleanup = true; } } else if (bitmap->getGenerationID() != texture->generation) { generateTexture(bitmap, texture, true); } - // TODO: Do something to destroy the texture object if it's too big for the cache + return texture; } |