summaryrefslogtreecommitdiff
path: root/libs/hwui/Layer.cpp
diff options
context:
space:
mode:
authorJohn Reck <jreck@google.com>2015-11-10 12:19:17 -0800
committerJohn Reck <jreck@google.com>2016-01-14 13:42:12 -0800
commit38e0c32852e3b9d8ca4a9d3791577f52536419cb (patch)
tree72286f7531e094182b2bfe959015d7ed7f9c6abc /libs/hwui/Layer.cpp
parenta5abf801044c5e53349c2e67428fe011a2f6985f (diff)
Track texture memory globally
Also mostly consolidates texture creation Change-Id: Ifea01303afda531dcec99b8fe2a0f64cf2f24420
Diffstat (limited to 'libs/hwui/Layer.cpp')
-rw-r--r--libs/hwui/Layer.cpp35
1 files changed, 15 insertions, 20 deletions
diff --git a/libs/hwui/Layer.cpp b/libs/hwui/Layer.cpp
index 0fe20ad1b662..7a74b9825d80 100644
--- a/libs/hwui/Layer.cpp
+++ b/libs/hwui/Layer.cpp
@@ -36,7 +36,8 @@ namespace android {
namespace uirenderer {
Layer::Layer(Type layerType, RenderState& renderState, uint32_t layerWidth, uint32_t layerHeight)
- : state(State::Uncached)
+ : GpuMemoryTracker(GpuObjectType::Layer)
+ , state(State::Uncached)
, caches(Caches::getInstance())
, renderState(renderState)
, texture(caches)
@@ -45,8 +46,8 @@ Layer::Layer(Type layerType, RenderState& renderState, uint32_t layerWidth, uint
// preserves the old inc/dec ref locations. This should be changed...
incStrong(nullptr);
renderTarget = GL_TEXTURE_2D;
- texture.width = layerWidth;
- texture.height = layerHeight;
+ texture.mWidth = layerWidth;
+ texture.mHeight = layerHeight;
renderState.registerLayer(this);
}
@@ -54,10 +55,10 @@ Layer::~Layer() {
renderState.unregisterLayer(this);
SkSafeUnref(colorFilter);
- if (stencil || fbo || texture.id) {
+ if (stencil || fbo || texture.mId) {
renderState.requireGLContext();
removeFbo();
- deleteTexture();
+ texture.deleteTexture();
}
delete[] mesh;
@@ -65,7 +66,7 @@ Layer::~Layer() {
void Layer::onGlContextLost() {
removeFbo();
- deleteTexture();
+ texture.deleteTexture();
}
uint32_t Layer::computeIdealWidth(uint32_t layerWidth) {
@@ -179,8 +180,8 @@ void Layer::setColorFilter(SkColorFilter* filter) {
}
void Layer::bindTexture() const {
- if (texture.id) {
- caches.textureState().bindTexture(renderTarget, texture.id);
+ if (texture.mId) {
+ caches.textureState().bindTexture(renderTarget, texture.mId);
}
}
@@ -191,28 +192,22 @@ void Layer::bindStencilRenderBuffer() const {
}
void Layer::generateTexture() {
- if (!texture.id) {
- glGenTextures(1, &texture.id);
- }
-}
-
-void Layer::deleteTexture() {
- if (texture.id) {
- texture.deleteTexture();
- texture.id = 0;
+ if (!texture.mId) {
+ glGenTextures(1, &texture.mId);
}
}
void Layer::clearTexture() {
- caches.textureState().unbindTexture(texture.id);
- texture.id = 0;
+ caches.textureState().unbindTexture(texture.mId);
+ texture.mId = 0;
}
void Layer::allocateTexture() {
#if DEBUG_LAYERS
ALOGD(" Allocate layer: %dx%d", getWidth(), getHeight());
#endif
- if (texture.id) {
+ if (texture.mId) {
+ texture.updateSize(getWidth(), getHeight(), GL_RGBA);
glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
glTexImage2D(renderTarget, 0, GL_RGBA, getWidth(), getHeight(), 0,
GL_RGBA, GL_UNSIGNED_BYTE, nullptr);