Bunch of fixes.

Fixes memory leak, fixes multiple context support, fix 3d transforms.

Change-Id: I7462cfbc57857dbd4de4e76b9d4cba58a1bce77b
diff --git a/libs/hwui/Snapshot.h b/libs/hwui/Snapshot.h
index 399ae68..342e5b1 100644
--- a/libs/hwui/Snapshot.h
+++ b/libs/hwui/Snapshot.h
@@ -96,9 +96,14 @@
     bool clip(float left, float top, float right, float bottom, SkRegion::Op op) {
         bool clipped = false;
 
-        Rect r(left, top, right, bottom);
-        transform.mapRect(r);
+        SkRect sr;
+        sr.set(left, top, right, bottom);
 
+        SkMatrix m;
+        transform.copyTo(m);
+        m.mapRect(&sr);
+
+        Rect r(sr.fLeft, sr.fTop, sr.fRight, sr.fBottom);
         switch (op) {
             case SkRegion::kDifference_Op:
                 break;
@@ -137,8 +142,16 @@
         if (flags & Snapshot::kFlagDirtyLocalClip) {
             mat4 inverse;
             inverse.loadInverse(transform);
-            localClip.set(clipRect);
-            inverse.mapRect(localClip);
+
+            SkRect sr;
+            sr.set(clipRect.left, clipRect.top, clipRect.right, clipRect.bottom);
+
+            SkMatrix m;
+            inverse.copyTo(m);
+            m.mapRect(&sr);
+
+            localClip.set(sr.fLeft, sr.fTop, sr.fRight, sr.fBottom);
+
             flags &= ~Snapshot::kFlagDirtyLocalClip;
         }
         return localClip;