merge in jb-mr1-factory-release history after reset to jb-mr1-dev
diff --git a/opengl/libs/Android.mk b/opengl/libs/Android.mk
index bbdef62..31bfcd7 100644
--- a/opengl/libs/Android.mk
+++ b/opengl/libs/Android.mk
@@ -126,10 +126,6 @@
 	GLES2/gl2.cpp.arm 	\
 #
 
-ifneq (,$(filter manta, $(TARGET_DEVICE)))
-       LOCAL_CFLAGS += -DIS_MANTA
-endif
-
 LOCAL_SHARED_LIBRARIES += libcutils libutils libEGL
 LOCAL_LDLIBS := -lpthread -ldl
 LOCAL_MODULE:= libGLESv2
diff --git a/opengl/libs/GLES2/gl2.cpp b/opengl/libs/GLES2/gl2.cpp
index cd70ac8..2d0045e 100644
--- a/opengl/libs/GLES2/gl2.cpp
+++ b/opengl/libs/GLES2/gl2.cpp
@@ -44,18 +44,10 @@
 #undef CALL_GL_API
 #undef CALL_GL_API_RETURN
 
-#ifdef IS_MANTA
-#define DEBUG_CALL_GL_API 1
-#else
 #define DEBUG_CALL_GL_API 0
-#endif
 #define DEBUG_PRINT_CALL_STACK_ON_ERROR 0
 #define SYSTRACE_CALL_GL_API 0
 
-#ifdef IS_MANTA
-#undef USE_FAST_TLS_KEY
-#endif
-
 #if USE_FAST_TLS_KEY
 
     #ifdef HAVE_ARM_TLS_REGISTER
@@ -99,7 +91,7 @@
         GLenum status = GL_NO_ERROR; \
         bool error = false; \
         while ((status = glGetError()) != GL_NO_ERROR) { \
-            ALOGD("GL Error: [" #_api "] 0x%x", status); \
+            ALOGD("[" #_api "] 0x%x", status); \
             error = true; \
         } \
         if (DEBUG_PRINT_CALL_STACK_ON_ERROR && error) { \
diff --git a/services/surfaceflinger/DisplayHardware/HWComposer.cpp b/services/surfaceflinger/DisplayHardware/HWComposer.cpp
index be4af51..d9bda11 100644
--- a/services/surfaceflinger/DisplayHardware/HWComposer.cpp
+++ b/services/surfaceflinger/DisplayHardware/HWComposer.cpp
@@ -696,6 +696,7 @@
         free(dd.list);
         dd.list = NULL;
         dd.framebufferTarget = NULL;    // points into dd.list
+        dd.fbTargetHandle = NULL;
     }
 }
 
diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp
index 17c67f9..492d1cf 100644
--- a/services/surfaceflinger/SurfaceFlinger.cpp
+++ b/services/surfaceflinger/SurfaceFlinger.cpp
@@ -772,8 +772,7 @@
         }
         setTransactionFlags(eDisplayTransactionNeeded);
 
-        // we should only receive DisplayDevice::DisplayType from the vsync callback
-        mEventThread->onHotplugReceived(type, connected);
+        // Defer EventThread notification until SF has updated mDisplays.
     }
 }
 
@@ -1130,6 +1129,7 @@
                         DisplayDevice::makeCurrent(mEGLDisplay, hw, mEGLContext);
                         mDisplays.removeItem(draw.keyAt(i));
                         getHwComposer().disconnectDisplay(draw[i].type);
+                        mEventThread->onHotplugReceived(draw[i].type, false);
                     } else {
                         ALOGW("trying to remove the main display");
                     }
@@ -1212,6 +1212,7 @@
                                 state.viewport, state.frame);
                         hw->setDisplayName(state.displayName);
                         mDisplays.add(display, hw);
+                        mEventThread->onHotplugReceived(state.type, true);
                     }
                 }
             }