Stop worker threads on memory trim & fix bad pointer access

Change-Id: I6fe7e31aeb6dd41fa65ab952caed97bc2da510d7
diff --git a/libs/hwui/PathCache.h b/libs/hwui/PathCache.h
index e6d92df..1467231 100644
--- a/libs/hwui/PathCache.h
+++ b/libs/hwui/PathCache.h
@@ -26,6 +26,7 @@
 #include "Debug.h"
 #include "Properties.h"
 #include "Texture.h"
+#include "utils/Pair.h"
 
 class SkBitmap;
 class SkCanvas;
@@ -215,10 +216,6 @@
     PathTexture* get(SkPath* path, SkPaint* paint);
 
     /**
-     * Removes an entry.
-     */
-    void remove(SkPath* path);
-    /**
      * Removes the specified path. This is meant to be called from threads
      * that are not the EGL context thread.
      */
@@ -251,6 +248,8 @@
             float& left, float& top, float& offset, uint32_t& width, uint32_t& height);
 
 private:
+    typedef Pair<SkPath*, SkPath*> path_pair_t;
+
     PathTexture* addTexture(const PathDescription& entry,
             const SkPath *path, const SkPaint* paint);
     PathTexture* addTexture(const PathDescription& entry, SkBitmap* bitmap);
@@ -261,6 +260,12 @@
     }
 
     /**
+     * Removes an entry.
+     * The pair must define first=path, second=sourcePath
+     */
+    void remove(const path_pair_t& pair);
+
+    /**
      * Ensures there is enough space in the cache for a texture of the specified
      * dimensions.
      */
@@ -318,7 +323,8 @@
     bool mDebugEnabled;
 
     sp<PathProcessor> mProcessor;
-    Vector<SkPath*> mGarbage;
+
+    Vector<path_pair_t> mGarbage;
     mutable Mutex mLock;
 }; // class PathCache