display: Enable vsync

* Use the vsync uevents from the kernel to start
surfaceflinger composition.
* This patch also does some code cleanup
    - Move copybit specific functions to copybit files.
    - Cleanup verbose logging.

Change-Id: I36936e4b0a082cfb0347d8ee7d2bc936e01808e6
diff --git a/libhwcomposer/hwc_utils.cpp b/libhwcomposer/hwc_utils.cpp
index ae5c526..870a758 100644
--- a/libhwcomposer/hwc_utils.cpp
+++ b/libhwcomposer/hwc_utils.cpp
@@ -15,26 +15,39 @@
  * limitations under the License.
  */
 
+#include <overlay.h>
 #include "hwc_utils.h"
 #include "mdp_version.h"
 #include "hwc_video.h"
-#include "hwc_ext_observer.h"
+#include "hwc_qbuf.h"
 #include "hwc_copybit.h"
+#include "hwc_external.h"
+
 namespace qhwc {
+
+// Opens Framebuffer device
+static void openFramebufferDevice(hwc_context_t *ctx)
+{
+    hw_module_t const *module;
+    if (hw_get_module(GRALLOC_HARDWARE_MODULE_ID, &module) == 0) {
+        framebuffer_open(module, &(ctx->mFbDev));
+    }
+}
+
 void initContext(hwc_context_t *ctx)
 {
-    //XXX: target specific initializations here
+    openFramebufferDevice(ctx);
     ctx->mOverlay = overlay::Overlay::getInstance();
     ctx->qbuf = new QueuedBufferStore();
     ctx->mdpVersion = qdutils::MDPVersion::getInstance().getMDPVersion();
     ctx->hasOverlay = qdutils::MDPVersion::getInstance().hasOverlay();
-    ALOGI("MDP version: %d",ctx->mdpVersion);
-
-    ctx->mExtDisplayObserver = ExtDisplayObserver::getInstance();
-    ctx->mExtDisplayObserver->setHwcContext(ctx);
-    ctx->mFbDevice = FbDevice::getInstance();
     ctx->mCopybitEngine = CopybitEngine::getInstance();
-    CopyBit::openEglLibAndGethandle();
+    ctx->mExtDisplay = new ExternalDisplay(ctx);
+
+    init_uevent_thread(ctx);
+
+    ALOGI("Initializing Qualcomm Hardware Composer");
+    ALOGI("MDP version: %d", ctx->mdpVersion);
 }
 
 void closeContext(hwc_context_t *ctx)
@@ -48,15 +61,25 @@
         delete ctx->mCopybitEngine;
         ctx->mCopybitEngine = NULL;
     }
-    if(ctx->mFbDevice) {
-        delete ctx->mFbDevice;
-        ctx->mFbDevice = NULL;
+
+    if(ctx->mFbDev) {
+        framebuffer_close(ctx->mFbDev);
+        ctx->mFbDev = NULL;
     }
+
     if(ctx->qbuf) {
         delete ctx->qbuf;
         ctx->qbuf = NULL;
     }
-    CopyBit::closeEglLib();
+
+    if(ctx->mExtDisplay) {
+        delete ctx->mExtDisplay;
+        ctx->mExtDisplay = NULL;
+    }
+
+
+    free(const_cast<hwc_methods_t *>(ctx->device.methods));
+
 }
 
 void dumpLayer(hwc_layer_t const* l)
@@ -163,33 +186,4 @@
     }
 }
 
-//FbDevice class functions
-FbDevice* FbDevice::sInstance = 0;;
-struct framebuffer_device_t* FbDevice::getFb() {
-   return sFb;
-}
-
-FbDevice* FbDevice::getInstance() {
-   if(sInstance == NULL)
-       sInstance = new FbDevice();
-   return sInstance;
-}
-
-FbDevice::FbDevice(){
-    hw_module_t const *module;
-    if (hw_get_module(GRALLOC_HARDWARE_MODULE_ID, &module) == 0) {
-        framebuffer_open(module, &sFb);
-    } else {
-       ALOGE("FATAL ERROR: framebuffer open failed.");
-    }
-}
-FbDevice::~FbDevice()
-{
-    if(sFb)
-    {
-       framebuffer_close(sFb);
-       sFb = NULL;
-    }
-}
-
 };//namespace