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 | #ifndef ANDROID_UI_BUFFER_MAPPER_H |
| 18 | #define ANDROID_UI_BUFFER_MAPPER_H |
| 19 | |
| 20 | #include <stdint.h> |
| 21 | #include <sys/types.h> |
Mathias Agopian | af9a515 | 2009-04-10 20:34:46 -0700 | [diff] [blame^] | 22 | |
| 23 | #include <utils/CallStack.h> |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 24 | #include <utils/threads.h> |
| 25 | #include <utils/Singleton.h> |
Mathias Agopian | af9a515 | 2009-04-10 20:34:46 -0700 | [diff] [blame^] | 26 | #include <utils/KeyedVector.h> |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 27 | |
| 28 | #include <hardware/gralloc.h> |
| 29 | |
| 30 | |
| 31 | struct gralloc_module_t; |
| 32 | |
| 33 | namespace android { |
| 34 | |
| 35 | // --------------------------------------------------------------------------- |
| 36 | |
| 37 | class Rect; |
| 38 | |
| 39 | class BufferMapper : public Singleton<BufferMapper> |
| 40 | { |
| 41 | public: |
| 42 | static inline BufferMapper& get() { return getInstance(); } |
| 43 | status_t map(buffer_handle_t handle, void** addr); |
| 44 | status_t unmap(buffer_handle_t handle); |
| 45 | status_t lock(buffer_handle_t handle, int usage, const Rect& bounds); |
| 46 | status_t unlock(buffer_handle_t handle); |
| 47 | |
Mathias Agopian | af9a515 | 2009-04-10 20:34:46 -0700 | [diff] [blame^] | 48 | // dumps information about the mapping of this handle |
| 49 | void dump(buffer_handle_t handle); |
| 50 | |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 51 | private: |
| 52 | friend class Singleton<BufferMapper>; |
| 53 | BufferMapper(); |
| 54 | mutable Mutex mLock; |
| 55 | gralloc_module_t const *mAllocMod; |
Mathias Agopian | af9a515 | 2009-04-10 20:34:46 -0700 | [diff] [blame^] | 56 | |
| 57 | struct map_info_t { |
| 58 | int count; |
| 59 | KeyedVector<CallStack, int> callstacks; |
| 60 | }; |
| 61 | KeyedVector<buffer_handle_t, map_info_t> mMapInfo; |
| 62 | void logMapLocked(buffer_handle_t handle); |
| 63 | void logUnmapLocked(buffer_handle_t handle); |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 64 | }; |
| 65 | |
| 66 | // --------------------------------------------------------------------------- |
| 67 | |
| 68 | }; // namespace android |
| 69 | |
| 70 | #endif // ANDROID_UI_BUFFER_MAPPER_H |
| 71 | |