blob: 9e5c5d7fd7fa39f3e094d9b8c0f97761274c4219 [file] [log] [blame]
Mathias Agopian076b1cc2009-04-10 14:24:30 -07001/*
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 Agopian8b765b72009-04-10 20:34:46 -070022
23#include <utils/CallStack.h>
Mathias Agopian076b1cc2009-04-10 14:24:30 -070024#include <utils/threads.h>
25#include <utils/Singleton.h>
Mathias Agopian8b765b72009-04-10 20:34:46 -070026#include <utils/KeyedVector.h>
Mathias Agopian076b1cc2009-04-10 14:24:30 -070027
28#include <hardware/gralloc.h>
29
30
31struct gralloc_module_t;
32
33namespace android {
34
35// ---------------------------------------------------------------------------
36
37class Rect;
38
39class BufferMapper : public Singleton<BufferMapper>
40{
41public:
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 Agopian8b765b72009-04-10 20:34:46 -070048 // dumps information about the mapping of this handle
49 void dump(buffer_handle_t handle);
50
Mathias Agopian076b1cc2009-04-10 14:24:30 -070051private:
52 friend class Singleton<BufferMapper>;
53 BufferMapper();
54 mutable Mutex mLock;
55 gralloc_module_t const *mAllocMod;
Mathias Agopian8b765b72009-04-10 20:34:46 -070056
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 Agopian076b1cc2009-04-10 14:24:30 -070064};
65
66// ---------------------------------------------------------------------------
67
68}; // namespace android
69
70#endif // ANDROID_UI_BUFFER_MAPPER_H
71