blob: ff90033002963a3483cf3a676e8a8c4d1458adf7 [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(); }
Mathias Agopian4243e662009-04-15 18:34:24 -070043 status_t map(buffer_handle_t handle, void** addr, const void* id);
44 status_t unmap(buffer_handle_t handle, const void* id);
Mathias Agopian076b1cc2009-04-10 14:24:30 -070045 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
Mathias Agopian4243e662009-04-15 18:34:24 -070057 void logMapLocked(buffer_handle_t handle, const void* id);
58 void logUnmapLocked(buffer_handle_t handle, const void* id);
Mathias Agopian8b765b72009-04-10 20:34:46 -070059 struct map_info_t {
Mathias Agopian4243e662009-04-15 18:34:24 -070060 const void* id;
61 CallStack stack;
Mathias Agopian8b765b72009-04-10 20:34:46 -070062 };
Mathias Agopian4243e662009-04-15 18:34:24 -070063 KeyedVector<buffer_handle_t, Vector<map_info_t> > mMapInfo;
Mathias Agopian076b1cc2009-04-10 14:24:30 -070064};
65
66// ---------------------------------------------------------------------------
67
68}; // namespace android
69
70#endif // ANDROID_UI_BUFFER_MAPPER_H
71