Mathias Agopian | 1473f46 | 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> |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 20 | #include <errno.h> |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 21 | |
| 22 | #include <utils/Errors.h> |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 23 | #include <utils/Log.h> |
| 24 | |
| 25 | #include <ui/BufferMapper.h> |
| 26 | #include <ui/Rect.h> |
| 27 | |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 28 | #include <hardware/gralloc.h> |
| 29 | |
Mathias Agopian | af9a515 | 2009-04-10 20:34:46 -0700 | [diff] [blame] | 30 | |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 31 | namespace android { |
| 32 | // --------------------------------------------------------------------------- |
| 33 | |
Mathias Agopian | 2b1927f | 2009-04-17 14:15:18 -0700 | [diff] [blame] | 34 | ANDROID_SINGLETON_STATIC_INSTANCE( BufferMapper ) |
Mathias Agopian | a6b40ba | 2009-04-15 18:34:24 -0700 | [diff] [blame] | 35 | |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 36 | BufferMapper::BufferMapper() |
| 37 | : mAllocMod(0) |
| 38 | { |
| 39 | hw_module_t const* module; |
| 40 | int err = hw_get_module(GRALLOC_HARDWARE_MODULE_ID, &module); |
| 41 | LOGE_IF(err, "FATAL: can't find the %s module", GRALLOC_HARDWARE_MODULE_ID); |
| 42 | if (err == 0) { |
| 43 | mAllocMod = (gralloc_module_t const *)module; |
| 44 | } |
| 45 | } |
| 46 | |
Mathias Agopian | dff8e58 | 2009-05-04 14:17:04 -0700 | [diff] [blame] | 47 | status_t BufferMapper::registerBuffer(buffer_handle_t handle) |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 48 | { |
Mathias Agopian | dff8e58 | 2009-05-04 14:17:04 -0700 | [diff] [blame] | 49 | status_t err = mAllocMod->registerBuffer(mAllocMod, handle); |
| 50 | LOGW_IF(err, "registerBuffer(%p) failed %d (%s)", |
| 51 | handle, err, strerror(-err)); |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 52 | return err; |
| 53 | } |
| 54 | |
Mathias Agopian | dff8e58 | 2009-05-04 14:17:04 -0700 | [diff] [blame] | 55 | status_t BufferMapper::unregisterBuffer(buffer_handle_t handle) |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 56 | { |
Mathias Agopian | dff8e58 | 2009-05-04 14:17:04 -0700 | [diff] [blame] | 57 | status_t err = mAllocMod->unregisterBuffer(mAllocMod, handle); |
| 58 | LOGW_IF(err, "unregisterBuffer(%p) failed %d (%s)", |
| 59 | handle, err, strerror(-err)); |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 60 | return err; |
| 61 | } |
| 62 | |
Mathias Agopian | dff8e58 | 2009-05-04 14:17:04 -0700 | [diff] [blame] | 63 | status_t BufferMapper::lock(buffer_handle_t handle, |
| 64 | int usage, const Rect& bounds, void** vaddr) |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 65 | { |
| 66 | status_t err = mAllocMod->lock(mAllocMod, handle, usage, |
Mathias Agopian | dff8e58 | 2009-05-04 14:17:04 -0700 | [diff] [blame] | 67 | bounds.left, bounds.top, bounds.width(), bounds.height(), vaddr); |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 68 | LOGW_IF(err, "unlock(...) failed %d (%s)", err, strerror(-err)); |
| 69 | return err; |
| 70 | } |
| 71 | |
| 72 | status_t BufferMapper::unlock(buffer_handle_t handle) |
| 73 | { |
| 74 | status_t err = mAllocMod->unlock(mAllocMod, handle); |
| 75 | LOGW_IF(err, "unlock(...) failed %d (%s)", err, strerror(-err)); |
| 76 | return err; |
| 77 | } |
| 78 | |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 79 | // --------------------------------------------------------------------------- |
| 80 | }; // namespace android |