gpu_tonemapper: Clear EGLImage mappings in Tonemapper

Tonemapper does not clear the eglImage/fd mappings in the destructor,
which leads to incorrect usage of those fds, when a tone map session
gets deleted and a new session gets created, leading to artifcats.

CRs-Fixed: 1104823
Change-Id: I9697eff93f9e5f150796a582f471246bca3b2816
diff --git a/gpu_tonemapper/Tonemapper.cpp b/gpu_tonemapper/Tonemapper.cpp
index 957c133..5f2f974 100644
--- a/gpu_tonemapper/Tonemapper.cpp
+++ b/gpu_tonemapper/Tonemapper.cpp
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2016-2017, The Linux Foundation. All rights reserved.
  * Not a Contribution.
  *
  * Copyright 2015 The Android Open Source Project
@@ -32,6 +32,7 @@
   tonemapTexture = 0;
   lutXformTexture = 0;
   programID = 0;
+  eglImageWrapper = new EGLImageWrapper();
 }
 
 //-----------------------------------------------------------------------------
@@ -41,6 +42,13 @@
   engine_deleteInputBuffer(tonemapTexture);
   engine_deleteInputBuffer(lutXformTexture);
   engine_deleteProgram(programID);
+
+  // clear EGLImage mappings
+  if (eglImageWrapper != 0) {
+    eglImageWrapper->destroy();
+    delete eglImageWrapper;
+    eglImageWrapper = 0;
+  }
 }
 
 //-----------------------------------------------------------------------------
@@ -95,8 +103,8 @@
   engine_bind();
 
   // create eglimages if required
-  EGLImageBuffer *dst_buffer = EGLImageWrapper::wrap(dst);
-  EGLImageBuffer *src_buffer = EGLImageWrapper::wrap(src);
+  EGLImageBuffer *dst_buffer = eglImageWrapper->wrap(dst);
+  EGLImageBuffer *src_buffer = eglImageWrapper->wrap(src);
 
   // bind the program
   engine_setProgram(programID);