Crash instead of leaking layers/textures between GL contexts

bug:17208461
Change-Id: I4d58f301cf0f5e8145e808a5d6ade4de7801970b
diff --git a/libs/hwui/RenderState.h b/libs/hwui/RenderState.h
index f7116e2..cd71c73 100644
--- a/libs/hwui/RenderState.h
+++ b/libs/hwui/RenderState.h
@@ -16,6 +16,7 @@
 #ifndef RENDERSTATE_H
 #define RENDERSTATE_H
 
+#include <set>
 #include <GLES2/gl2.h>
 #include <GLES2/gl2ext.h>
 
@@ -37,6 +38,7 @@
     PREVENT_COPY_AND_ASSIGN(RenderState);
 public:
     void onGLContextCreated();
+    void onGLContextDestroyed();
 
     void setViewport(GLsizei width, GLsizei height);
     void getViewport(GLsizei* outWidth, GLsizei* outHeight);
@@ -48,6 +50,13 @@
 
     void debugOverdraw(bool enable, bool clear);
 
+    void registerLayer(const Layer* layer) {
+        mActiveLayers.insert(layer);
+    }
+    void unregisterLayer(const Layer* layer) {
+        mActiveLayers.erase(layer);
+    }
+
 private:
     friend class renderthread::RenderThread;
 
@@ -58,6 +67,7 @@
     ~RenderState();
 
     Caches* mCaches;
+    std::set<const Layer*> mActiveLayers;
 
     GLsizei mViewportWidth;
     GLsizei mViewportHeight;