one step toward fixing [2501808] sapphire: OOM in GPU Surface area

when a surface was returned from a remote process through the binder we
would leak its resources until a GC happened.

implement writeToParcel to release the source when PARCELABLE_WRITE_RETURN_VALUE
is set

Change-Id: I6a9fa369b0d164a9ca1229b8a2944d3c132a3720
diff --git a/core/jni/android_view_Surface.cpp b/core/jni/android_view_Surface.cpp
index 060ca50..ed26cbe 100644
--- a/core/jni/android_view_Surface.cpp
+++ b/core/jni/android_view_Surface.cpp
@@ -35,6 +35,11 @@
 
 namespace android {
 
+enum {
+    // should match Parcelable.java
+    PARCELABLE_WRITE_RETURN_VALUE = 0x0001
+};
+
 // ----------------------------------------------------------------------------
 
 static const char* const OutOfResourcesException =
@@ -612,6 +617,9 @@
 
     const sp<SurfaceControl>& control(getSurfaceControl(env, clazz));
     SurfaceControl::writeSurfaceToParcel(control, parcel);
+    if (flags & PARCELABLE_WRITE_RETURN_VALUE) {
+        setSurfaceControl(env, clazz, 0);
+    }
 }
 
 // ----------------------------------------------------------------------------