Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 2007 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #define LOG_TAG "BufferMapper" |
| 18 | |
| 19 | #include <stdint.h> |
| 20 | #include <unistd.h> |
| 21 | #include <fcntl.h> |
| 22 | #include <errno.h> |
| 23 | #include <sys/types.h> |
| 24 | #include <sys/stat.h> |
| 25 | |
| 26 | #include <utils/Errors.h> |
| 27 | #include <utils/threads.h> |
| 28 | #include <utils/Log.h> |
| 29 | |
| 30 | #include <ui/BufferMapper.h> |
| 31 | #include <ui/Rect.h> |
| 32 | |
| 33 | #include <EGL/android_natives.h> |
| 34 | |
| 35 | #include <hardware/gralloc.h> |
| 36 | |
| 37 | namespace android { |
| 38 | // --------------------------------------------------------------------------- |
| 39 | |
| 40 | BufferMapper::BufferMapper() |
| 41 | : mAllocMod(0) |
| 42 | { |
| 43 | hw_module_t const* module; |
| 44 | int err = hw_get_module(GRALLOC_HARDWARE_MODULE_ID, &module); |
| 45 | LOGE_IF(err, "FATAL: can't find the %s module", GRALLOC_HARDWARE_MODULE_ID); |
| 46 | if (err == 0) { |
| 47 | mAllocMod = (gralloc_module_t const *)module; |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | status_t BufferMapper::map(buffer_handle_t handle, void** addr) |
| 52 | { |
| 53 | Mutex::Autolock _l(mLock); |
| 54 | status_t err = mAllocMod->map(mAllocMod, handle, addr); |
| 55 | LOGW_IF(err, "map(...) failed %d (%s)", err, strerror(-err)); |
| 56 | return err; |
| 57 | } |
| 58 | |
| 59 | status_t BufferMapper::unmap(buffer_handle_t handle) |
| 60 | { |
| 61 | Mutex::Autolock _l(mLock); |
| 62 | status_t err = mAllocMod->unmap(mAllocMod, handle); |
| 63 | LOGW_IF(err, "unmap(...) failed %d (%s)", err, strerror(-err)); |
| 64 | return err; |
| 65 | } |
| 66 | |
| 67 | status_t BufferMapper::lock(buffer_handle_t handle, int usage, const Rect& bounds) |
| 68 | { |
| 69 | status_t err = mAllocMod->lock(mAllocMod, handle, usage, |
| 70 | bounds.left, bounds.top, bounds.width(), bounds.height()); |
| 71 | LOGW_IF(err, "unlock(...) failed %d (%s)", err, strerror(-err)); |
| 72 | return err; |
| 73 | } |
| 74 | |
| 75 | status_t BufferMapper::unlock(buffer_handle_t handle) |
| 76 | { |
| 77 | status_t err = mAllocMod->unlock(mAllocMod, handle); |
| 78 | LOGW_IF(err, "unlock(...) failed %d (%s)", err, strerror(-err)); |
| 79 | return err; |
| 80 | } |
| 81 | |
| 82 | // --------------------------------------------------------------------------- |
| 83 | }; // namespace android |