Track texture memory globally
Also mostly consolidates texture creation
Change-Id: Ifea01303afda531dcec99b8fe2a0f64cf2f24420
diff --git a/libs/hwui/Layer.h b/libs/hwui/Layer.h
index e90f055b..e00ae66 100644
--- a/libs/hwui/Layer.h
+++ b/libs/hwui/Layer.h
@@ -24,6 +24,7 @@
#include <memory>
#include <GLES2/gl2.h>
+#include <GpuMemoryTracker.h>
#include <ui/Region.h>
@@ -54,7 +55,7 @@
/**
* A layer has dimensions and is backed by an OpenGL texture or FBO.
*/
-class Layer : public VirtualLightRefBase {
+class Layer : public VirtualLightRefBase, GpuMemoryTracker {
public:
enum class Type {
Texture,
@@ -94,8 +95,8 @@
regionRect.set(bounds.leftTop().x, bounds.leftTop().y,
bounds.rightBottom().x, bounds.rightBottom().y);
- const float texX = 1.0f / float(texture.width);
- const float texY = 1.0f / float(texture.height);
+ const float texX = 1.0f / float(texture.mWidth);
+ const float texY = 1.0f / float(texture.mHeight);
const float height = layer.getHeight();
texCoords.set(
regionRect.left * texX, (height - regionRect.top) * texY,
@@ -112,11 +113,11 @@
void updateDeferred(RenderNode* renderNode, int left, int top, int right, int bottom);
inline uint32_t getWidth() const {
- return texture.width;
+ return texture.mWidth;
}
inline uint32_t getHeight() const {
- return texture.height;
+ return texture.mHeight;
}
/**
@@ -131,8 +132,7 @@
bool resize(const uint32_t width, const uint32_t height);
void setSize(uint32_t width, uint32_t height) {
- texture.width = width;
- texture.height = height;
+ texture.updateSize(width, height, texture.format());
}
ANDROID_API void setPaint(const SkPaint* paint);
@@ -201,7 +201,7 @@
}
inline GLuint getTextureId() const {
- return texture.id;
+ return texture.id();
}
inline Texture& getTexture() {
@@ -263,7 +263,6 @@
void bindTexture() const;
void generateTexture();
void allocateTexture();
- void deleteTexture();
/**
* When the caller frees the texture itself, the caller