Automatically cleanup textures that don't fit in the cache.
Change-Id: I4f29ed96ea11118b391fb957e1e4d1b8fcef1537
diff --git a/libs/hwui/Texture.h b/libs/hwui/Texture.h
index d37013d..90f548b 100644
--- a/libs/hwui/Texture.h
+++ b/libs/hwui/Texture.h
@@ -26,6 +26,10 @@
* Represents an OpenGL texture.
*/
struct Texture {
+ Texture() {
+ cleanup = false;
+ }
+
/**
* Name of the texture.
*/
@@ -46,8 +50,26 @@
* 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