display: Store and restore the current eglContext

Tone mapper engine setting the current eglContext and never
restored it.  With multiple eglContexts used in same thread
by SurfaceFlinger and GPU Tonemapper, it lead to incorrect
eglContexts being used, hence always store the restore the
eglContext in each GPUTonemapper call.

CRs-Fixed: 2009259
Change-Id: Ic9fe73818ddfe3881e5fa82f7853dce130bba24e
diff --git a/gpu_tonemapper/Tonemapper.cpp b/gpu_tonemapper/Tonemapper.cpp
index 38b4fe2..c6646f6 100644
--- a/gpu_tonemapper/Tonemapper.cpp
+++ b/gpu_tonemapper/Tonemapper.cpp
@@ -45,6 +45,7 @@
 Tonemapper::~Tonemapper()
 //-----------------------------------------------------------------------------
 {
+  void* caller_context = engine_backup();
   engine_bind(engineContext);
   engine_deleteInputBuffer(tonemapTexture);
   engine_deleteInputBuffer(lutXformTexture);
@@ -57,6 +58,9 @@
   }
 
   engine_shutdown(engineContext);
+  // restore the caller context
+  engine_bind(caller_context);
+  engine_free_backup(caller_context);
 }
 
 //-----------------------------------------------------------------------------
@@ -74,6 +78,7 @@
 
   tonemapper->engineContext = engine_initialize();
 
+  void* caller_context = engine_backup();
   engine_bind(tonemapper->engineContext);
 
   // load the 3d lut
@@ -112,6 +117,10 @@
   tonemapper->programID =
       engine_loadProgram(1, &fullscreen_vertex_shader, fragmentShaderCount, fragmentShaders);
 
+  // restore the caller context
+  engine_bind(caller_context);
+  engine_free_backup(caller_context);
+
   return tonemapper;
 }
 
@@ -119,6 +128,7 @@
 int Tonemapper::blit(const void *dst, const void *src, int srcFenceFd)
 //-----------------------------------------------------------------------------
 {
+  void* caller_context = engine_backup();
   // make current
   engine_bind(engineContext);
 
@@ -149,5 +159,10 @@
   // perform
   int fenceFD = engine_blit(srcFenceFd);
 
+  // restore the caller context
+  engine_bind(caller_context);
+  engine_free_backup(caller_context);
+
+
   return fenceFD;
 }