OSDN Git Service

Fixing a bug in gl_env release surface
authorPannag Sanketi <psanketi@google.com>
Thu, 13 Oct 2011 01:06:41 +0000 (18:06 -0700)
committerPannag Sanketi <psanketi@google.com>
Thu, 13 Oct 2011 05:46:53 +0000 (22:46 -0700)
While recording in camera with the effects on, there was a bug in releasing
a surface. The possible memory corruption was due to erasing
the surface-window pair in the map before destroying the surface and its associated
window handle.
Also, fixed a bit of nomenclature in the related functions.

Related to bug: 5373197

Change-Id: Ie861e5ce87cde8909c5680897cdfddafeba5e507

mca/filterfw/native/core/gl_env.cpp

index b475795..b412ac5 100644 (file)
@@ -220,16 +220,16 @@ bool GLEnv::SwitchToSurfaceId(int surface_id) {
 
 bool GLEnv::ReleaseSurfaceId(int surface_id) {
   if (surface_id > 0) {
-    const SurfaceWindowPair* surface = FindOrNull(surfaces_, surface_id);
-    if (surface) {
-      surfaces_.erase(surface_id);
+    const SurfaceWindowPair* surface_window_pair = FindOrNull(surfaces_, surface_id);
+    if (surface_window_pair) {
       if (surface_id_ == surface_id)
         SwitchToSurfaceId(0);
-      eglDestroySurface(display(), surface->first);
-      if (surface->second) {
-        surface->second->Destroy();
-        delete surface->second;
+      eglDestroySurface(display(), surface_window_pair->first);
+      if (surface_window_pair->second) {
+        surface_window_pair->second->Destroy();
+        delete surface_window_pair->second;
       }
+      surfaces_.erase(surface_id);
       return true;
     }
   }
@@ -238,10 +238,11 @@ bool GLEnv::ReleaseSurfaceId(int surface_id) {
 
 bool GLEnv::SetSurfaceTimestamp(int64_t timestamp) {
   if (surface_id_ > 0) {
-    std::map<int, SurfaceWindowPair>::iterator surfacePair = surfaces_.find(surface_id_);
-    if (surfacePair != surfaces_.end()) {
-      SurfaceWindowPair &surface = surfacePair->second;
-      ANativeWindow *window = static_cast<ANativeWindow*>(surface.second->InternalHandle());
+    const SurfaceWindowPair* surface_window_pair = FindOrNull(surfaces_,
+            surface_id_);
+    if (surface_window_pair) {
+      ANativeWindow *window = static_cast<ANativeWindow*>(
+              surface_window_pair->second->InternalHandle());
       native_window_set_buffers_timestamp(window, timestamp);
       return true;
     }