Move gralloc from vendor to here
authorRebecca Schultz Zavin <rebecca@android.com>
Tue, 14 Aug 2012 23:08:04 +0000 (16:08 -0700)
committerRebecca Schultz Zavin <rebecca@android.com>
Wed, 15 Aug 2012 16:33:19 +0000 (09:33 -0700)
Change-Id: I47bca624cfcbeaeb67321e17a2f755785da16aa5
Signed-off-by: Rebecca Schultz Zavin <rebecca@android.com>
Android.mk
gralloc/Android.mk [new file with mode: 0644]
gralloc/framebuffer.cpp [new file with mode: 0644]
gralloc/gr.h [new file with mode: 0644]
gralloc/gralloc.cpp [new file with mode: 0644]
gralloc/mapper.cpp [new file with mode: 0644]

index 399a89aee3e955e51058827498c7aa64e270bbdb..6d624737d9fe7ed504d2f76b3098c32ef59a2702 100644 (file)
@@ -30,7 +30,8 @@ exynos5_dirs := \
        libhwjpeg \
        libhwc \
        libcamera2 \
-       mobicore
+       mobicore \
+       gralloc
 
 BOARD_USE_V4L2 := true
 BOARD_USE_V4L2_ION := true
diff --git a/gralloc/Android.mk b/gralloc/Android.mk
new file mode 100644 (file)
index 0000000..012f9cc
--- /dev/null
@@ -0,0 +1,37 @@
+# Copyright (C) 2008 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+
+LOCAL_PATH := $(call my-dir)
+
+# HAL module implemenation stored in
+# hw/<OVERLAY_HARDWARE_MODULE_ID>.<ro.product.board>.so
+include $(CLEAR_VARS)
+
+LOCAL_MODULE_PATH := $(TARGET_OUT_VENDOR_SHARED_LIBRARIES)/hw
+LOCAL_SHARED_LIBRARIES := liblog libcutils libion libutils
+
+LOCAL_C_INCLUDES := hardware/samsung_slsi/exynos5/include
+
+LOCAL_SRC_FILES :=     \
+       gralloc.cpp     \
+       framebuffer.cpp \
+       mapper.cpp
+       
+LOCAL_MODULE := gralloc.exynos5
+LOCAL_CFLAGS:= -DLOG_TAG=\"gralloc\"
+LOCAL_MODULE_TAGS := optional
+LOCAL_MODULE_OWNER := samsung_arm
+
+include $(BUILD_SHARED_LIBRARY)
diff --git a/gralloc/framebuffer.cpp b/gralloc/framebuffer.cpp
new file mode 100644 (file)
index 0000000..c1d4ce9
--- /dev/null
@@ -0,0 +1,236 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <sys/mman.h>
+
+#include <dlfcn.h>
+
+#include <cutils/ashmem.h>
+#include <cutils/log.h>
+
+#include <hardware/hardware.h>
+#include <hardware/gralloc.h>
+
+#include <fcntl.h>
+#include <errno.h>
+#include <sys/ioctl.h>
+#include <string.h>
+#include <stdlib.h>
+
+#include <utils/Vector.h>
+
+#include <cutils/log.h>
+#include <cutils/atomic.h>
+
+#if HAVE_ANDROID_OS
+#include <linux/fb.h>
+#endif
+
+#include "gralloc_priv.h"
+#include "gr.h"
+
+/*****************************************************************************/
+
+// numbers of buffers for page flipping
+#define NUM_BUFFERS 2
+
+struct hwc_callback_entry 
+{
+    void (*callback)(void *, private_handle_t *);
+    void *data;
+};
+
+typedef android::Vector<struct hwc_callback_entry> hwc_callback_queue_t;
+
+struct fb_context_t {
+    framebuffer_device_t  device;
+};
+
+/*****************************************************************************/
+
+static int fb_setSwapInterval(struct framebuffer_device_t* dev,
+                              int interval)
+{
+    fb_context_t* ctx = (fb_context_t*)dev;
+    if (interval < dev->minSwapInterval || interval > dev->maxSwapInterval)
+        return -EINVAL;
+    // FIXME: implement fb_setSwapInterval
+    return 0;
+}
+
+static int fb_post(struct framebuffer_device_t* dev, buffer_handle_t buffer)
+{
+    if (private_handle_t::validate(buffer) < 0)
+        return -EINVAL;
+
+    private_handle_t const* hnd = reinterpret_cast<private_handle_t const*>(buffer);
+    private_module_t* m = reinterpret_cast<private_module_t*>(dev->common.module);
+
+    hwc_callback_queue_t *queue = reinterpret_cast<hwc_callback_queue_t *>(m->queue);
+    pthread_mutex_lock(&m->queue_lock);
+    if(queue->isEmpty())
+        pthread_mutex_unlock(&m->queue_lock);
+    else {
+        private_handle_t *hnd = private_handle_t::dynamicCast(buffer);
+        struct hwc_callback_entry entry = queue->top();
+        queue->pop();
+        pthread_mutex_unlock(&m->queue_lock);
+        entry.callback(entry.data, hnd);
+    }
+
+    return 0;
+}
+
+/*****************************************************************************/
+
+static int fb_close(struct hw_device_t *dev)
+{
+    fb_context_t* ctx = (fb_context_t*)dev;
+    if (ctx) {
+        free(ctx);
+    }
+    return 0;
+}
+
+int init_fb(struct private_module_t* module)
+{
+    char const * const device_template[] = {
+        "/dev/graphics/fb%u",
+        "/dev/fb%u",
+        NULL
+    };
+
+    int fd = -1;
+    int i = 0;
+    char name[64];
+
+    fd = open("/dev/graphics/fb0", O_RDWR);
+    if (fd < 0) {
+        ALOGE("/dev/graphics/fb0 Open fail");
+        return -errno;
+    }
+
+    struct fb_fix_screeninfo finfo;
+    if (ioctl(fd, FBIOGET_FSCREENINFO, &finfo) == -1) {
+        ALOGE("Fail to get FB Screen Info");
+        return -errno;
+    }
+
+    struct fb_var_screeninfo info;
+    if (ioctl(fd, FBIOGET_VSCREENINFO, &info) == -1) {
+        ALOGE("First, Fail to get FB VScreen Info");
+        return -errno;
+    }
+
+    int refreshRate = 1000000000000000LLU /
+        (
+         uint64_t( info.upper_margin + info.lower_margin + info.yres )
+         * ( info.left_margin  + info.right_margin + info.xres )
+         * info.pixclock
+        );
+
+    if (refreshRate == 0)
+        refreshRate = 60*1000;  /* 60 Hz */
+
+    float xdpi = (info.xres * 25.4f) / info.width;
+    float ydpi = (info.yres * 25.4f) / info.height;
+    float fps  = refreshRate / 1000.0f;
+
+    ALOGI("using (id=%s)\n"
+          "xres         = %d px\n"
+          "yres         = %d px\n"
+          "width        = %d mm (%f dpi)\n"
+          "height       = %d mm (%f dpi)\n"
+          "refresh rate = %.2f Hz\n",
+          finfo.id, info.xres, info.yres, info.width,  xdpi, info.height, ydpi,
+          fps);
+
+    module->xres = 2560;
+    module->yres = 1600;
+    module->line_length = 2560;
+    module->xdpi = xdpi;
+    module->ydpi = ydpi;
+    module->fps = fps;
+
+    return 0;
+}
+
+int fb_device_open(hw_module_t const* module, const char* name,
+                   hw_device_t** device)
+{
+    int status = -EINVAL;
+#ifdef GRALLOC_16_BITS
+    int bits_per_pixel = 16;
+    int format = HAL_PIXEL_FORMAT_RGB_565;
+#else
+    int bits_per_pixel = 32;
+    int format = HAL_PIXEL_FORMAT_RGBA_8888;
+#endif
+
+    alloc_device_t* gralloc_device;
+    status = gralloc_open(module, &gralloc_device);
+    if (status < 0) {
+        ALOGE("Fail to Open gralloc device");
+        return status;
+    }
+
+    framebuffer_device_t *dev = (framebuffer_device_t *)malloc(sizeof(framebuffer_device_t));
+    if (dev == NULL) {
+        ALOGE("Failed to allocate memory for dev");
+        gralloc_close(gralloc_device);
+        return status;
+    }
+
+    private_module_t* m = (private_module_t*)module;
+    status = init_fb(m);
+    if (status < 0) {
+        ALOGE("Fail to init framebuffer");
+        free(dev);
+        gralloc_close(gralloc_device);
+        return status;
+    }
+
+    /* initialize our state here */
+    memset(dev, 0, sizeof(*dev));
+
+    /* initialize the procs */
+    dev->common.tag = HARDWARE_DEVICE_TAG;
+    dev->common.version = 0;
+    dev->common.module = const_cast<hw_module_t*>(module);
+    dev->common.close = fb_close;
+    dev->setSwapInterval = 0;
+    dev->post = fb_post;
+    dev->setUpdateRect = 0;
+    dev->compositionComplete = 0;
+    m->queue = new hwc_callback_queue_t;
+    pthread_mutex_init(&m->queue_lock, NULL);
+
+    int stride = m->line_length / (bits_per_pixel >> 3);
+    const_cast<uint32_t&>(dev->flags) = 0;
+    const_cast<uint32_t&>(dev->width) = m->xres;
+    const_cast<uint32_t&>(dev->height) = m->yres;
+    const_cast<int&>(dev->stride) = stride;
+    const_cast<int&>(dev->format) = format;
+    const_cast<float&>(dev->xdpi) = m->xdpi;
+    const_cast<float&>(dev->ydpi) = m->ydpi;
+    const_cast<float&>(dev->fps) = m->fps;
+    const_cast<int&>(dev->minSwapInterval) = 1;
+    const_cast<int&>(dev->maxSwapInterval) = 1;
+    *device = &dev->common;
+    status = 0;
+
+    return status;
+}
diff --git a/gralloc/gr.h b/gralloc/gr.h
new file mode 100644 (file)
index 0000000..ad7047c
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef GR_H_
+#define GR_H_
+
+#include <stdint.h>
+#include <limits.h>
+#include <sys/cdefs.h>
+#include <hardware/gralloc.h>
+#include <pthread.h>
+#include <errno.h>
+
+#include <cutils/native_handle.h>
+
+/*****************************************************************************/
+
+struct private_module_t;
+struct private_handle_t;
+
+int grallocMap(gralloc_module_t const* module, private_handle_t *hnd);
+int grallocUnmap(gralloc_module_t const* module, private_handle_t *hnd);
+
+#endif /* GR_H_ */
diff --git a/gralloc/gralloc.cpp b/gralloc/gralloc.cpp
new file mode 100644 (file)
index 0000000..4937bbb
--- /dev/null
@@ -0,0 +1,317 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifdef HAVE_ANDROID_OS      // just want PAGE_SIZE define
+# include <asm/page.h>
+#else
+# include <sys/user.h>
+#endif
+#include <limits.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <pthread.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <sys/mman.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <sys/ioctl.h>
+
+#include <ion/ion.h>
+#include <linux/ion.h>
+#include <cutils/log.h>
+#include <cutils/atomic.h>
+
+#include <hardware/hardware.h>
+#include <hardware/gralloc.h>
+
+#include "gralloc_priv.h"
+#include "exynos_format.h"
+#include "gr.h"
+
+/*****************************************************************************/
+
+struct gralloc_context_t {
+    alloc_device_t  device;
+    /* our private data here */
+};
+
+static int gralloc_alloc_buffer(alloc_device_t* dev,
+                                size_t size, int usage, buffer_handle_t* pHandle);
+
+/*****************************************************************************/
+
+int fb_device_open(const hw_module_t* module, const char* name,
+                   hw_device_t** device);
+
+static int gralloc_device_open(const hw_module_t* module, const char* name,
+                               hw_device_t** device);
+
+extern int gralloc_lock(gralloc_module_t const* module,
+                        buffer_handle_t handle, int usage,
+                        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 = {
+open: gralloc_device_open
+};
+
+struct private_module_t HAL_MODULE_INFO_SYM = {
+base: {
+common: {
+tag: HARDWARE_MODULE_TAG,
+     version_major: 1,
+     version_minor: 0,
+     id: GRALLOC_HARDWARE_MODULE_ID,
+     name: "Graphics Memory Allocator Module",
+     author: "The Android Open Source Project",
+     methods: &gralloc_module_methods
+        },
+registerBuffer: gralloc_register_buffer,
+                unregisterBuffer: gralloc_unregister_buffer,
+                lock: gralloc_lock,
+                unlock: gralloc_unlock,
+      },
+framebuffer: 0,
+             flags: 0,
+             numBuffers: 0,
+             bufferMask: 0,
+             lock: PTHREAD_MUTEX_INITIALIZER,
+             currentBuffer: 0,
+             ionfd: -1,
+};
+
+/*****************************************************************************/
+
+#define ALIGN(x, a) (((x) + (a - 1)) & ~(a - 1))
+
+static int gralloc_alloc_rgb(int ionfd, int w, int h, int format, int flags,
+                             private_handle_t **hnd, int *stride)
+{
+    size_t size, bpr;
+    int bpp = 0, fd, err;
+    switch (format) {
+        case HAL_PIXEL_FORMAT_RGBA_8888:
+        case HAL_PIXEL_FORMAT_RGBX_8888:
+        case HAL_PIXEL_FORMAT_BGRA_8888:
+            bpp = 4;
+            break;
+        case HAL_PIXEL_FORMAT_RGB_888:
+            bpp = 3;
+            break;
+        case HAL_PIXEL_FORMAT_RGB_565:
+        case HAL_PIXEL_FORMAT_RGBA_5551:
+        case HAL_PIXEL_FORMAT_RGBA_4444:
+        case HAL_PIXEL_FORMAT_RAW_SENSOR:
+            bpp = 2;
+            break;
+        case HAL_PIXEL_FORMAT_BLOB:
+            bpp = 1;
+            break;
+        default:
+            return -EINVAL;
+    }
+    bpr = ALIGN(w*bpp, 16);
+    size = bpr * h;
+    *stride = bpr / bpp;
+    size = ALIGN(size, PAGE_SIZE);
+
+    err = ion_alloc_fd(ionfd, size, 0, 1 << ION_HEAP_TYPE_SYSTEM, flags, &fd);
+    *hnd = new private_handle_t(fd, size, 0, w, h, format, *stride);
+
+    return err;
+}
+
+static int gralloc_alloc_yuv(int ionfd, int w, int h, int format, int flags,
+                             private_handle_t **hnd, int *stride)
+{
+    size_t luma_size, chroma_size;
+    int err, planes, fd, fd1, fd2 = 0;
+    *stride = ALIGN(w, 16);
+
+    switch (format) {
+        ALOGE("invalid yuv format %d\n", format);
+        case HAL_PIXEL_FORMAT_YV12:
+        {
+            size_t vstride = ALIGN(h, 16);
+            luma_size = vstride * *stride;
+            chroma_size = (vstride / 2) * ALIGN(*stride / 2, 16);
+            planes = 3;
+            break;
+        }
+        case HAL_PIXEL_FORMAT_YCrCb_420_SP:
+        case HAL_PIXEL_FORMAT_YCbCr_420_SP:
+        case HAL_PIXEL_FORMAT_YCbCr_420_SP_TILED:
+        {
+            size_t luma_vstride = ALIGN(h, 32);
+            size_t chroma_vstride = ALIGN(h / 2, 32);
+            luma_size = luma_vstride * *stride;
+            chroma_size = chroma_vstride * *stride;
+            planes = 2;
+            break;
+        }
+        default:
+        ALOGE("invalid yuv format %d\n", format);
+        return -EINVAL;
+    }
+
+    err = ion_alloc_fd(ionfd, luma_size, 0, 1 << ION_HEAP_TYPE_SYSTEM, flags,
+                       &fd);
+    if (err)
+        return err;
+    err = ion_alloc_fd(ionfd, chroma_size, 0, 1 << ION_HEAP_TYPE_SYSTEM, flags,
+                       &fd1);
+    if (err)
+        goto err1;
+    if (planes == 3) {
+        err = ion_alloc_fd(ionfd, chroma_size, 0, 1 << ION_HEAP_TYPE_SYSTEM,
+                           flags, &fd2);
+        if (err)
+            goto err2;
+    }
+
+    *hnd = new private_handle_t(fd, fd1, fd2, luma_size, 0, w, h, format,
+                                *stride);
+    return err;
+
+err2:
+    close(fd1);
+err1:
+    close(fd);
+    return err;
+}
+
+static int gralloc_alloc(alloc_device_t* dev,
+                         int w, int h, int format, int usage,
+                         buffer_handle_t* pHandle, int* pStride)
+{
+    int stride;
+    int err;
+    int flags = 0;
+    private_handle_t *hnd;
+
+    if (!pHandle || !pStride)
+        return -EINVAL;
+
+    if( (usage & GRALLOC_USAGE_SW_READ_MASK) == GRALLOC_USAGE_SW_READ_OFTEN )
+        flags = ION_FLAG_CACHED;
+
+    private_module_t* m = reinterpret_cast<private_module_t*>
+        (dev->common.module);
+    gralloc_module_t* module = reinterpret_cast<gralloc_module_t*>
+        (dev->common.module);
+
+    err = gralloc_alloc_rgb(m->ionfd, w, h, format, flags, &hnd, &stride);
+    if (err)
+        err = gralloc_alloc_yuv(m->ionfd, w, h, format, flags, &hnd, &stride);
+    if (err)
+        return err;
+
+    err = grallocMap(module, hnd);
+
+    if (err != 0)
+        goto err;
+
+    *pHandle = hnd;
+    *pStride = stride;
+    return 0;
+err:
+    close(hnd->fd);
+    if (hnd->fd1 > 0)
+        close(hnd->fd1);
+    if (hnd->fd2 > 0)
+        close(hnd->fd2);
+    return err;
+}
+
+static int gralloc_free(alloc_device_t* dev,
+                        buffer_handle_t handle)
+{
+    if (private_handle_t::validate(handle) < 0)
+        return -EINVAL;
+
+    private_handle_t const* hnd = reinterpret_cast<private_handle_t const*>(handle);
+    gralloc_module_t* module = reinterpret_cast<gralloc_module_t*>(
+                                                                   dev->common.module);
+
+    grallocUnmap(module, const_cast<private_handle_t*>(hnd));
+    close(hnd->fd);
+    if (hnd->fd1 > 0)
+        close(hnd->fd1);
+    if (hnd->fd2 > 0)
+        close(hnd->fd2);
+
+    delete hnd;
+    return 0;
+}
+
+/*****************************************************************************/
+
+static int gralloc_close(struct hw_device_t *dev)
+{
+    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.
+         */
+        free(ctx);
+    }
+    return 0;
+}
+
+int gralloc_device_open(const hw_module_t* module, const char* name,
+                        hw_device_t** device)
+{
+    int status = -EINVAL;
+    if (!strcmp(name, GRALLOC_HARDWARE_GPU0)) {
+        gralloc_context_t *dev;
+        dev = (gralloc_context_t*)malloc(sizeof(*dev));
+
+        /* initialize our state here */
+        memset(dev, 0, sizeof(*dev));
+
+        /* initialize the procs */
+        dev->device.common.tag = HARDWARE_DEVICE_TAG;
+        dev->device.common.version = 0;
+        dev->device.common.module = const_cast<hw_module_t*>(module);
+        dev->device.common.close = gralloc_close;
+
+        dev->device.alloc = gralloc_alloc;
+        dev->device.free = gralloc_free;
+
+        private_module_t *p = reinterpret_cast<private_module_t*>(dev->device.common.module);
+        p->ionfd = ion_open();
+
+        *device = &dev->device.common;
+        status = 0;
+    } else {
+        status = fb_device_open(module, name, device);
+    }
+    return status;
+}
diff --git a/gralloc/mapper.cpp b/gralloc/mapper.cpp
new file mode 100644 (file)
index 0000000..1f5cf8f
--- /dev/null
@@ -0,0 +1,149 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <limits.h>
+#include <errno.h>
+#include <pthread.h>
+#include <unistd.h>
+#include <string.h>
+
+#include <sys/mman.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+
+#include <cutils/log.h>
+#include <cutils/atomic.h>
+
+#include <hardware/hardware.h>
+#include <hardware/gralloc.h>
+
+#include "gralloc_priv.h"
+
+#include <ion/ion.h>
+#include <linux/ion.h>
+
+/*****************************************************************************/
+
+static int gralloc_map(gralloc_module_t const* module, buffer_handle_t handle)
+{
+    private_handle_t* hnd = (private_handle_t*)handle;
+
+    void* mappedAddress = mmap(0, hnd->size, PROT_READ|PROT_WRITE, MAP_SHARED, 
+                               hnd->fd, 0);
+    if (mappedAddress == MAP_FAILED) {
+        ALOGE("%s: could not mmap %s", __func__, strerror(errno));
+        return -errno;
+    }
+    ALOGV("%s: base %p %d %d %d %d\n", __func__, mappedAddress, hnd->size,
+          hnd->width, hnd->height, hnd->stride);
+    hnd->base = mappedAddress;
+    return 0;
+}
+
+static int gralloc_unmap(gralloc_module_t const* module, buffer_handle_t handle)
+{
+    private_handle_t* hnd = (private_handle_t*)handle;
+
+    if (!hnd->base)
+        return 0;
+
+    if (munmap(hnd->base, hnd->size) < 0) {
+        ALOGE("%s :could not unmap %s %p %d", __func__, strerror(errno),
+              hnd->base, hnd->size);
+    }
+    ALOGV("%s: base %p %d %d %d %d\n", __func__, hnd->base, hnd->size,
+          hnd->width, hnd->height, hnd->stride);
+    hnd->base = 0;
+    return 0;
+}
+
+/*****************************************************************************/
+
+int grallocMap(gralloc_module_t const* module, private_handle_t *hnd)
+{
+    return gralloc_map(module, hnd);
+}
+
+int grallocUnmap(gralloc_module_t const* module, private_handle_t *hnd)        
+{
+    return gralloc_unmap(module, hnd);
+}
+
+static pthread_mutex_t sMapLock = PTHREAD_MUTEX_INITIALIZER; 
+
+/*****************************************************************************/
+
+int gralloc_register_buffer(gralloc_module_t const* module,
+                            buffer_handle_t handle)
+{
+    int err;
+    if (private_handle_t::validate(handle) < 0)
+        return -EINVAL;
+
+    err = gralloc_map(module, handle);
+
+    private_handle_t* hnd = (private_handle_t*)handle;
+    ALOGV("%s: base %p %d %d %d %d\n", __func__, hnd->base, hnd->size,
+          hnd->width, hnd->height, hnd->stride);
+    return err;
+}
+
+int gralloc_unregister_buffer(gralloc_module_t const* module,
+                              buffer_handle_t handle)
+{
+    if (private_handle_t::validate(handle) < 0)
+        return -EINVAL;
+
+    private_handle_t* hnd = (private_handle_t*)handle;
+    ALOGV("%s: base %p %d %d %d %d\n", __func__, hnd->base, hnd->size,
+          hnd->width, hnd->height, hnd->stride);
+
+    gralloc_unmap(module, handle);
+
+    return 0;
+}
+
+int gralloc_lock(gralloc_module_t const* module,
+                 buffer_handle_t handle, int usage,
+                 int l, int t, int w, int h,
+                 void** vaddr)
+{
+    // this is called when a buffer is being locked for software
+    // access. in thin implementation we have nothing to do since
+    // not synchronization with the h/w is needed.
+    // typically this is used to wait for the h/w to finish with
+    // this buffer if relevant. the data cache may need to be
+    // flushed or invalidated depending on the usage bits and the
+    // hardware.
+
+    if (private_handle_t::validate(handle) < 0)
+        return -EINVAL;
+
+    private_handle_t* hnd = (private_handle_t*)handle;
+    *vaddr = (void*)hnd->base;
+    return 0;
+}
+
+int gralloc_unlock(gralloc_module_t const* module, 
+                   buffer_handle_t handle)
+{
+    // we're done with a software buffer. nothing to do in this
+    // implementation. typically this is used to flush the data cache.
+
+    if (private_handle_t::validate(handle) < 0)
+        return -EINVAL;
+    return 0;
+}