blob: 03e03368154881e0706f07a50cc43d216bb52287 [file] [log] [blame]
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -07001/*
2 * Copyright (C) 2008 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_VRAM_HEAP_H
18#define ANDROID_VRAM_HEAP_H
19
20#include <stdint.h>
21#include <sys/types.h>
22#include <utils/MemoryDealer.h>
23
24namespace android {
25
26// ---------------------------------------------------------------------------
27
28class PMemHeap;
29class MemoryHeapPmem;
30
31// ---------------------------------------------------------------------------
32
33class SurfaceHeapManager : public RefBase
34{
35public:
36 SurfaceHeapManager(size_t clientHeapSize);
37 virtual ~SurfaceHeapManager();
38 virtual void onFirstRef();
39 sp<MemoryDealer> createHeap(int type);
40
41 // used for debugging only...
42 sp<SimpleBestFitAllocator> getAllocator(int type) const;
43
44private:
45 sp<PMemHeap> getHeap(int type) const;
46
47 mutable Mutex mLock;
48 size_t mClientHeapSize;
49 sp<PMemHeap> mPMemHeap;
50 static int global_pmem_heap;
51};
52
53// ---------------------------------------------------------------------------
54
55class PMemHeapInterface : public MemoryHeapBase
56{
57public:
58 PMemHeapInterface(int fd, size_t size);
59 PMemHeapInterface(const char* device, size_t size = 0);
60 PMemHeapInterface(size_t size, uint32_t flags = 0, char const * name = NULL);
61 virtual ~PMemHeapInterface();
62 virtual sp<MemoryHeapPmem> createClientHeap() = 0;
63};
64
65// ---------------------------------------------------------------------------
66
67class PMemHeap : public PMemHeapInterface
68{
69public:
70 PMemHeap(const char* const vram,
71 size_t size=0, size_t reserved=0);
72 virtual ~PMemHeap();
73
74 virtual const sp<SimpleBestFitAllocator>& getAllocator() const {
75 return mAllocator;
76 }
77 virtual sp<MemoryHeapPmem> createClientHeap();
78
79private:
80 sp<SimpleBestFitAllocator> mAllocator;
81};
82
83// ---------------------------------------------------------------------------
84}; // namespace android
85
86#endif // ANDROID_VRAM_HEAP_H