blob: 780a1bc56dce8892076e7ade7a1926ef6fdd6647 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
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>
Mathias Agopian07952722009-05-19 19:08:10 -070022#include <binder/MemoryDealer.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080023
24namespace android {
25
26// ---------------------------------------------------------------------------
27
28class PMemHeap;
29class MemoryHeapPmem;
30class SurfaceFlinger;
31
32// ---------------------------------------------------------------------------
33
34class SurfaceHeapManager : public RefBase
35{
36public:
37 SurfaceHeapManager(const sp<SurfaceFlinger>& flinger, size_t clientHeapSize);
38 virtual ~SurfaceHeapManager();
39 virtual void onFirstRef();
40 /* use ISurfaceComposer flags eGPU|eHArdware|eSecure */
41 sp<MemoryDealer> createHeap(uint32_t flags=0, pid_t client_pid = 0,
42 const sp<MemoryDealer>& defaultAllocator = 0);
43
44 // used for debugging only...
45 sp<SimpleBestFitAllocator> getAllocator(int type) const;
46
47private:
48 sp<PMemHeap> getHeap(int type) const;
49
50 sp<SurfaceFlinger> mFlinger;
51 mutable Mutex mLock;
52 size_t mClientHeapSize;
53 sp<PMemHeap> mPMemHeap;
54 static int global_pmem_heap;
55};
56
57// ---------------------------------------------------------------------------
58
59class PMemHeap : public MemoryHeapBase
60{
61public:
62 PMemHeap(const char* const vram,
63 size_t size=0, size_t reserved=0);
64 virtual ~PMemHeap();
65
66 virtual const sp<SimpleBestFitAllocator>& getAllocator() const {
67 return mAllocator;
68 }
69 virtual sp<MemoryHeapPmem> createClientHeap();
70
71private:
72 sp<SimpleBestFitAllocator> mAllocator;
73};
74
75// ---------------------------------------------------------------------------
76}; // namespace android
77
78#endif // ANDROID_VRAM_HEAP_H