Update for cleanups in hwc interface

Also store the hwc_procs_t* into a dedicated field instead of one of
the hwc_composer_device_1_t::reserved_procs slots, which are supposed
to be NULL so the structure can be extended without breaking backwards
binary compatibility.

Change-Id: I11e6bc713958d854aba418242caa749cbcb21f1d
diff --git a/libhwcomposer/hwc.cpp b/libhwcomposer/hwc.cpp
index 00635c5..4a73c64 100644
--- a/libhwcomposer/hwc.cpp
+++ b/libhwcomposer/hwc.cpp
@@ -69,7 +69,10 @@
         ALOGE("%s: Invalid context", __FUNCTION__);
         return;
     }
-    ctx->device.reserved_proc[0] = (void*)procs;
+    ctx->proc = procs;
+
+    // don't start listening for events until we can do something with them
+    init_uevent_thread(ctx);
 }
 
 static int hwc_prepare(hwc_composer_device_1 *dev, size_t numDisplays,
@@ -230,21 +233,16 @@
         initContext(dev);
 
         //Setup HWC methods
-        hwc_methods_1_t *methods;
-        methods = (hwc_methods_1_t *) malloc(sizeof(*methods));
-        memset(methods, 0, sizeof(*methods));
-        methods->eventControl = hwc_eventControl;
-        methods->blank = hwc_blank;
-
         dev->device.common.tag     = HARDWARE_DEVICE_TAG;
         dev->device.common.version = HWC_DEVICE_API_VERSION_1_0;
         dev->device.common.module  = const_cast<hw_module_t*>(module);
         dev->device.common.close   = hwc_device_close;
         dev->device.prepare        = hwc_prepare;
         dev->device.set            = hwc_set;
-        dev->device.registerProcs  = hwc_registerProcs;
+        dev->device.eventControl   = hwc_eventControl;
+        dev->device.blank          = hwc_blank;
         dev->device.query          = hwc_query;
-        dev->device.methods        = methods;
+        dev->device.registerProcs  = hwc_registerProcs;
         *device                    = &dev->device.common;
         status = 0;
     }
diff --git a/libhwcomposer/hwc_external.cpp b/libhwcomposer/hwc_external.cpp
index c4a6a6a..d35a622 100644
--- a/libhwcomposer/hwc_external.cpp
+++ b/libhwcomposer/hwc_external.cpp
@@ -385,16 +385,9 @@
         const char* prop = (connected) ? "1" : "0";
         // set system property
         property_set("hw.hdmiON", prop);
-        //Invalidate
-        hwc_procs* proc = (hwc_procs*)ctx->device.reserved_proc[0];
-        if(!proc) {
-            ALOGE("%s: HWC proc not registered",
-                     __FUNCTION__);
-        } else {
-            /* Trigger redraw */
-            ALOGD_IF(DEBUG, "%s: Invalidate !!", __FUNCTION__);
-            proc->invalidate(proc);
-        }
+        /* Trigger redraw */
+        ALOGD_IF(DEBUG, "%s: Invalidate !!", __FUNCTION__);
+        ctx->proc->invalidate(ctx->proc);
     }
     return;
 }
diff --git a/libhwcomposer/hwc_mdpcomp.cpp b/libhwcomposer/hwc_mdpcomp.cpp
index aa59cbd..7eaea7f 100644
--- a/libhwcomposer/hwc_mdpcomp.cpp
+++ b/libhwcomposer/hwc_mdpcomp.cpp
@@ -114,15 +114,13 @@
         return;
     }
 
-    hwc_procs* proc = (hwc_procs*)ctx->device.reserved_proc[0];
-
-    if(!proc) {
+    if(!ctx->proc) {
         ALOGE("%s: HWC proc not registered", __FUNCTION__);
         return;
     }
     sIdleFallBack = true;
     /* Trigger SF to redraw the current frame */
-    proc->invalidate(proc);
+    ctx->proc->invalidate(ctx->proc);
 }
 
 void MDPComp::reset(hwc_context_t *ctx, hwc_display_contents_1_t* list ) {
diff --git a/libhwcomposer/hwc_uevents.cpp b/libhwcomposer/hwc_uevents.cpp
index e7ab629..8c833f7 100644
--- a/libhwcomposer/hwc_uevents.cpp
+++ b/libhwcomposer/hwc_uevents.cpp
@@ -40,7 +40,6 @@
     char* hdmi;
     int64_t timestamp = 0;
     const char *str = udata;
-    hwc_procs* proc = (hwc_procs*)ctx->device.reserved_proc[0];
     int hdmiconnected = ctx->mExtDisplay->getExternalDisplay();
 
     if(!strcasestr(str, "@/devices/virtual/graphics/fb")) {
@@ -60,7 +59,7 @@
             if (!strncmp(str, "VSYNC=", strlen("VSYNC="))) {
                 timestamp = strtoull(str + strlen("VSYNC="), NULL, 0);
                 //XXX: Handle vsync from multiple displays
-                proc->vsync(proc, (int)ctx->dpys[0], timestamp);
+                ctx->proc->vsync(ctx->proc, (int)ctx->dpys[0], timestamp);
             }
             str += strlen(str) + 1;
             if(str - udata >= len)
diff --git a/libhwcomposer/hwc_utils.cpp b/libhwcomposer/hwc_utils.cpp
index a2ba499..669cf17 100644
--- a/libhwcomposer/hwc_utils.cpp
+++ b/libhwcomposer/hwc_utils.cpp
@@ -50,8 +50,6 @@
     memset(ctx->dpys,(int)EGL_NO_DISPLAY, MAX_NUM_DISPLAYS);
     MDPComp::init(ctx);
 
-    init_uevent_thread(ctx);
-
     ALOGI("Initializing Qualcomm Hardware Composer");
     ALOGI("MDP version: %d", ctx->mMDP.version);
 }
@@ -82,10 +80,6 @@
         delete ctx->mExtDisplay;
         ctx->mExtDisplay = NULL;
     }
-
-
-    free(const_cast<hwc_methods_1_t *>(ctx->device.methods));
-
 }
 
 void dumpLayer(hwc_layer_1_t const* l)
diff --git a/libhwcomposer/hwc_utils.h b/libhwcomposer/hwc_utils.h
index 84309ac..b586fa8 100644
--- a/libhwcomposer/hwc_utils.h
+++ b/libhwcomposer/hwc_utils.h
@@ -124,6 +124,7 @@
 // This structure contains overall state
 struct hwc_context_t {
     hwc_composer_device_1_t device;
+    const hwc_procs_t* proc;
     int numHwLayers;
     int overlayInUse;
     hwc_display_t dpys[MAX_NUM_DISPLAYS];