Don't track TextureLayer lifecycles in RenderState
bug:17208461
They are destroyed via finalizer-enqueued destroy method, so it's not
valid to check that they've been destroyed at gl context destruction
time.
Change-Id: I670f69825547facd5f31d44acb406418881fee00
diff --git a/libs/hwui/Layer.cpp b/libs/hwui/Layer.cpp
index 25caae3..91c4aee 100644
--- a/libs/hwui/Layer.cpp
+++ b/libs/hwui/Layer.cpp
@@ -29,15 +29,15 @@
namespace android {
namespace uirenderer {
-Layer::Layer(RenderState& renderState, const uint32_t layerWidth, const uint32_t layerHeight)
+Layer::Layer(Type layerType, RenderState& renderState, const uint32_t layerWidth, const uint32_t layerHeight)
: caches(Caches::getInstance())
, renderState(renderState)
- , texture(caches) {
+ , texture(caches)
+ , type(layerType) {
mesh = NULL;
meshElementCount = 0;
cacheable = true;
dirty = false;
- textureLayer = false;
renderTarget = GL_TEXTURE_2D;
texture.width = layerWidth;
texture.height = layerHeight;
@@ -55,11 +55,17 @@
caches.resourceCache.incrementRefcount(this);
rendererLightPosDirty = true;
wasBuildLayered = false;
- renderState.registerLayer(this);
+ if (!isTextureLayer()) {
+ // track only non-texture layer lifecycles in renderstate,
+ // because texture layers are destroyed via finalizer
+ renderState.registerLayer(this);
+ }
}
Layer::~Layer() {
- renderState.unregisterLayer(this);
+ if (!isTextureLayer()) {
+ renderState.unregisterLayer(this);
+ }
SkSafeUnref(colorFilter);
removeFbo();
deleteTexture();
diff --git a/libs/hwui/Layer.h b/libs/hwui/Layer.h
index 911b99880..36a4ed1 100644
--- a/libs/hwui/Layer.h
+++ b/libs/hwui/Layer.h
@@ -54,7 +54,12 @@
*/
class Layer {
public:
- Layer(RenderState& renderState, const uint32_t layerWidth, const uint32_t layerHeight);
+ enum Type {
+ kType_Texture,
+ kType_DisplayList,
+ };
+
+ Layer(Type type, RenderState& renderState, const uint32_t layerWidth, const uint32_t layerHeight);
~Layer();
static uint32_t computeIdealWidth(uint32_t layerWidth);
@@ -219,11 +224,7 @@
}
inline bool isTextureLayer() const {
- return textureLayer;
- }
-
- inline void setTextureLayer(bool textureLayer) {
- this->textureLayer = textureLayer;
+ return type == kType_Texture;
}
inline SkColorFilter* getColorFilter() const {
@@ -343,10 +344,9 @@
bool cacheable;
/**
- * When set to true, this layer must be treated as a texture
- * layer.
+ * Denotes whether the layer is a DisplayList, or Texture layer.
*/
- bool textureLayer;
+ const Type type;
/**
* When set to true, this layer is dirty and should be cleared
diff --git a/libs/hwui/LayerCache.cpp b/libs/hwui/LayerCache.cpp
index efa30ac..d49daf6 100644
--- a/libs/hwui/LayerCache.cpp
+++ b/libs/hwui/LayerCache.cpp
@@ -112,7 +112,7 @@
} else {
LAYER_LOGD("Creating new layer %dx%d", entry.mWidth, entry.mHeight);
- layer = new Layer(renderState, entry.mWidth, entry.mHeight);
+ layer = new Layer(Layer::kType_DisplayList, renderState, entry.mWidth, entry.mHeight);
layer->setBlend(true);
layer->setEmpty(true);
layer->setFbo(0);
diff --git a/libs/hwui/LayerRenderer.cpp b/libs/hwui/LayerRenderer.cpp
index e3b0daf..103c843 100644
--- a/libs/hwui/LayerRenderer.cpp
+++ b/libs/hwui/LayerRenderer.cpp
@@ -272,9 +272,8 @@
Layer* LayerRenderer::createTextureLayer(RenderState& renderState) {
LAYER_RENDERER_LOGD("Creating new texture layer");
- Layer* layer = new Layer(renderState, 0, 0);
+ Layer* layer = new Layer(Layer::kType_Texture, renderState, 0, 0);
layer->setCacheable(false);
- layer->setTextureLayer(true);
layer->setEmpty(true);
layer->setFbo(0);
layer->setAlpha(255, SkXfermode::kSrcOver_Mode);