summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Reck <jreck@google.com>2015-01-29 10:17:57 -0800
committerJohn Reck <jreck@google.com>2015-01-29 10:17:57 -0800
commit57998017ff137f7d4ec33df21b6596141f8c4547 (patch)
treeed9786692ee5727eacea084f12ea417b1d0f7915
parent8514766a0a388c3598eaa64709edc634f8edccb1 (diff)
downloadframeworks_base-57998017ff137f7d4ec33df21b6596141f8c4547.zip
frameworks_base-57998017ff137f7d4ec33df21b6596141f8c4547.tar.gz
frameworks_base-57998017ff137f7d4ec33df21b6596141f8c4547.tar.bz2
Allow ~Layer() to happen after onGLContextDestroyed
Bug: 19146354 Change-Id: I9e885936168bd541bfbed4064ad67ab524f58e32
-rw-r--r--libs/hwui/Caches.cpp2
-rw-r--r--libs/hwui/Layer.cpp14
-rw-r--r--libs/hwui/Layer.h6
-rw-r--r--libs/hwui/RenderState.cpp5
-rw-r--r--libs/hwui/RenderState.h6
5 files changed, 26 insertions, 7 deletions
diff --git a/libs/hwui/Caches.cpp b/libs/hwui/Caches.cpp
index 4bbe6ed..cdf8150 100644
--- a/libs/hwui/Caches.cpp
+++ b/libs/hwui/Caches.cpp
@@ -273,7 +273,7 @@ void Caches::dumpMemoryUsage(String8 &log) {
layerCache.getSize(), layerCache.getMaxSize(), layerCache.getCount());
if (mRenderState) {
int memused = 0;
- for (std::set<const Layer*>::iterator it = mRenderState->mActiveLayers.begin();
+ for (std::set<Layer*>::iterator it = mRenderState->mActiveLayers.begin();
it != mRenderState->mActiveLayers.end(); it++) {
const Layer* layer = *it;
log.appendFormat(" Layer size %dx%d; isTextureLayer()=%d; texid=%u fbo=%u; refs=%d\n",
diff --git a/libs/hwui/Layer.cpp b/libs/hwui/Layer.cpp
index 9aa29ca..05259ff 100644
--- a/libs/hwui/Layer.cpp
+++ b/libs/hwui/Layer.cpp
@@ -69,17 +69,25 @@ Layer::Layer(Type layerType, RenderState& renderState, const uint32_t layerWidth
}
Layer::~Layer() {
- renderState.requireGLContext();
renderState.unregisterLayer(this);
SkSafeUnref(colorFilter);
- removeFbo();
- deleteTexture();
+
+ if (stencil || fbo || texture.id) {
+ renderState.requireGLContext();
+ removeFbo();
+ deleteTexture();
+ }
delete[] mesh;
delete deferredList;
delete renderer;
}
+void Layer::onGlContextLost() {
+ removeFbo();
+ deleteTexture();
+}
+
uint32_t Layer::computeIdealWidth(uint32_t layerWidth) {
return uint32_t(ceilf(layerWidth / float(LAYER_SIZE)) * LAYER_SIZE);
}
diff --git a/libs/hwui/Layer.h b/libs/hwui/Layer.h
index 64d1d12..e196cb1 100644
--- a/libs/hwui/Layer.h
+++ b/libs/hwui/Layer.h
@@ -286,6 +286,12 @@ public:
void postDecStrong();
/**
+ * Lost the GL context but the layer is still around, mark it invalid internally
+ * so the dtor knows not to do any GL work
+ */
+ void onGlContextLost();
+
+ /**
* Bounds of the layer.
*/
Rect layer;
diff --git a/libs/hwui/RenderState.cpp b/libs/hwui/RenderState.cpp
index d1f5f4e..ca640e5 100644
--- a/libs/hwui/RenderState.cpp
+++ b/libs/hwui/RenderState.cpp
@@ -41,6 +41,10 @@ void RenderState::onGLContextCreated() {
mCaches->textureCache.setAssetAtlas(&mAssetAtlas);
}
+static void layerLostGlContext(Layer* layer) {
+ layer->onGlContextLost();
+}
+
void RenderState::onGLContextDestroyed() {
/*
size_t size = mActiveLayers.size();
@@ -73,6 +77,7 @@ void RenderState::onGLContextDestroyed() {
LOG_ALWAYS_FATAL("%d layers have survived gl context destruction", size);
}
*/
+ std::for_each(mActiveLayers.begin(), mActiveLayers.end(), layerLostGlContext);
mAssetAtlas.terminate();
}
diff --git a/libs/hwui/RenderState.h b/libs/hwui/RenderState.h
index 1ecfb1c..9ac9356 100644
--- a/libs/hwui/RenderState.h
+++ b/libs/hwui/RenderState.h
@@ -53,10 +53,10 @@ public:
void debugOverdraw(bool enable, bool clear);
- void registerLayer(const Layer* layer) {
+ void registerLayer(Layer* layer) {
mActiveLayers.insert(layer);
}
- void unregisterLayer(const Layer* layer) {
+ void unregisterLayer(Layer* layer) {
mActiveLayers.erase(layer);
}
@@ -90,7 +90,7 @@ private:
renderthread::RenderThread& mRenderThread;
Caches* mCaches;
AssetAtlas mAssetAtlas;
- std::set<const Layer*> mActiveLayers;
+ std::set<Layer*> mActiveLayers;
std::set<renderthread::CanvasContext*> mRegisteredContexts;
GLsizei mViewportWidth;