The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame^] | 1 | /* |
| 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 | |
| 24 | namespace android { |
| 25 | |
| 26 | // --------------------------------------------------------------------------- |
| 27 | |
| 28 | class PMemHeap; |
| 29 | class MemoryHeapPmem; |
| 30 | |
| 31 | // --------------------------------------------------------------------------- |
| 32 | |
| 33 | class SurfaceHeapManager : public RefBase |
| 34 | { |
| 35 | public: |
| 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 | |
| 44 | private: |
| 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 | |
| 55 | class PMemHeapInterface : public MemoryHeapBase |
| 56 | { |
| 57 | public: |
| 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 | |
| 67 | class PMemHeap : public PMemHeapInterface |
| 68 | { |
| 69 | public: |
| 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 | |
| 79 | private: |
| 80 | sp<SimpleBestFitAllocator> mAllocator; |
| 81 | }; |
| 82 | |
| 83 | // --------------------------------------------------------------------------- |
| 84 | }; // namespace android |
| 85 | |
| 86 | #endif // ANDROID_VRAM_HEAP_H |