diff options
author | Rebecca Schultz Zavin <rebecca@android.com> | 2012-08-14 16:08:04 -0700 |
---|---|---|
committer | Rebecca Schultz Zavin <rebecca@android.com> | 2012-08-15 09:33:19 -0700 |
commit | 2480eccc3025c1a888e233e2ffbd3c098395de15 (patch) | |
tree | e550c7e719d258b3c81a9bafba97b18463bbb43e /gralloc/mapper.cpp | |
parent | d6bb7cef6f2325e7703704b3acbec99df2b6d381 (diff) | |
download | exynos5-2480eccc3025c1a888e233e2ffbd3c098395de15.tar.gz |
Move gralloc from vendor to here
Change-Id: I47bca624cfcbeaeb67321e17a2f755785da16aa5
Signed-off-by: Rebecca Schultz Zavin <rebecca@android.com>
Diffstat (limited to 'gralloc/mapper.cpp')
-rw-r--r-- | gralloc/mapper.cpp | 149 |
1 files changed, 149 insertions, 0 deletions
diff --git a/gralloc/mapper.cpp b/gralloc/mapper.cpp new file mode 100644 index 0000000..1f5cf8f --- /dev/null +++ b/gralloc/mapper.cpp @@ -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; +} |