lock will now return the vaddr of the buffer. map/umap are gone.

- make sure to return an error if a buffer is locked twice or unlocked while not locked.
- added registerBuffer() and unregisterBuffer() to the gralloc module so that we can do some cleanup when a buffer is no longer needed. this became necessary after we removed map/unmap so we have a place to unmap buffers without the need of a kernel module.
- change the constants for GRALLOC_USAGE_SW_{READ|WRITE}_NEVER to 0, so that NOT specifying them means "NEVER".
diff --git a/modules/gralloc/gralloc.cpp b/modules/gralloc/gralloc.cpp
index abb8c96..5a38b33 100644
--- a/modules/gralloc/gralloc.cpp
+++ b/modules/gralloc/gralloc.cpp
@@ -53,19 +53,20 @@
 static int gralloc_device_open(const hw_module_t* module, const char* name,
         hw_device_t** device);
 
-extern int gralloc_map(gralloc_module_t const* module,
-        buffer_handle_t handle, void** vaddr);
-
-extern int gralloc_unmap(gralloc_module_t const* module, 
-        buffer_handle_t handle);
-
 extern int gralloc_lock(gralloc_module_t const* module,
         buffer_handle_t handle, int usage,
-        int l, int t, int w, int h);
+        int l, int t, int w, int h,
+        void** vaddr);
 
 extern int gralloc_unlock(gralloc_module_t const* module, 
         buffer_handle_t handle);
 
+extern int gralloc_register_buffer(gralloc_module_t const* module,
+        buffer_handle_t handle);
+
+extern int gralloc_unregister_buffer(gralloc_module_t const* module,
+        buffer_handle_t handle);
+
 /*****************************************************************************/
 
 static struct hw_module_methods_t gralloc_module_methods = {
@@ -83,8 +84,8 @@
             author: "The Android Open Source Project",
             methods: &gralloc_module_methods
         },
-        map: gralloc_map,
-        unmap: gralloc_unmap,
+        registerBuffer: gralloc_register_buffer,
+        unregisterBuffer: gralloc_unregister_buffer,
         lock: gralloc_lock,
         unlock: gralloc_unlock,
     },
@@ -98,12 +99,6 @@
 
 /*****************************************************************************/
 
-/*
- * This function creates a buffer_handle_t initialized with the given fd.
- * the offset passed in parameter is used to mmap() this fd later at this
- * offset.
- */
-
 static int gralloc_alloc_framebuffer_locked(alloc_device_t* dev,
         size_t size, int usage, buffer_handle_t* pHandle)
 {
@@ -112,18 +107,14 @@
 
     // allocate the framebuffer
     if (m->framebuffer == NULL) {
-        // initialize the framebuffer
+        // initialize the framebuffer, the framebuffer is mapped once
+        // and forever.
         int err = mapFrameBufferLocked(m);
         if (err < 0) {
             return err;
         }
     }
 
-    if (m->framebuffer->base == 0) {
-        void *vaddr;
-        m->base.map(&m->base, m->framebuffer, &vaddr);
-    }
-    
     const uint32_t bufferMask = m->bufferMask;
     const uint32_t numBuffers = m->numBuffers;
     const size_t bufferSize = m->finfo.line_length * m->info.yres;
@@ -258,11 +249,10 @@
         int index = (hnd->base - m->framebuffer->base) / bufferSize;
         m->bufferMask &= ~(1<<index); 
     }
-    
-    if (hnd->base) {
-        LOGW("handle %p still mapped at %p", hnd, hnd->base);
-        //gralloc_unmap((gralloc_module_t*) dev->common.module, handle);
-    }
+
+    gralloc_module_t* m = reinterpret_cast<gralloc_module_t*>(
+            dev->common.module);
+    gralloc_unregister_buffer(m, handle);
     
     close(hnd->fd);
     delete hnd;
@@ -276,16 +266,8 @@
     gralloc_context_t* ctx = reinterpret_cast<gralloc_context_t*>(dev);
     if (ctx) {
         /* TODO: keep a list of all buffer_handle_t created, and free them
-         * all here
+         * all here.
          */
-
-        private_module_t* m = reinterpret_cast<private_module_t*>(dev->module);
-        pthread_mutex_lock(&m->lock);
-        if (m->framebuffer) {
-            m->base.unmap(&m->base, m->framebuffer);
-        }
-        pthread_mutex_unlock(&m->lock);
-
         free(ctx);
     }
     return 0;