Loading libs/hwui/OpenGLRenderer.cpp +8 −1 Original line number Diff line number Diff line Loading @@ -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); } Loading @@ -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); } Loading @@ -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; Loading @@ -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; Loading Loading @@ -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; Loading libs/hwui/PathCache.cpp +2 −1 Original line number Diff line number Diff line Loading @@ -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; } Loading Loading @@ -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; Loading libs/hwui/PathCache.h +3 −0 Original line number Diff line number Diff line Loading @@ -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. */ Loading libs/hwui/Texture.h +22 −0 Original line number Diff line number Diff line Loading @@ -26,6 +26,10 @@ namespace uirenderer { * Represents an OpenGL texture. */ struct Texture { Texture() { cleanup = false; } /** * Name of the texture. */ Loading @@ -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 Loading libs/hwui/TextureCache.cpp +3 −1 Original line number Diff line number Diff line Loading @@ -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; } Loading Loading
libs/hwui/OpenGLRenderer.cpp +8 −1 Original line number Diff line number Diff line Loading @@ -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); } Loading @@ -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); } Loading @@ -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; Loading @@ -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; Loading Loading @@ -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; Loading
libs/hwui/PathCache.cpp +2 −1 Original line number Diff line number Diff line Loading @@ -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; } Loading Loading @@ -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; Loading
libs/hwui/PathCache.h +3 −0 Original line number Diff line number Diff line Loading @@ -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. */ Loading
libs/hwui/Texture.h +22 −0 Original line number Diff line number Diff line Loading @@ -26,6 +26,10 @@ namespace uirenderer { * Represents an OpenGL texture. */ struct Texture { Texture() { cleanup = false; } /** * Name of the texture. */ Loading @@ -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 Loading
libs/hwui/TextureCache.cpp +3 −1 Original line number Diff line number Diff line Loading @@ -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; } Loading