1 /* 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 #pragma once 18 19 #include <stdint.h> 20 #include <sys/types.h> 21 22 #include <binder/IMemory.h> 23 #include <binder/MemoryHeapBase.h> 24 25 namespace android { 26 // ---------------------------------------------------------------------------- 27 28 class SimpleBestFitAllocator; 29 30 // ---------------------------------------------------------------------------- 31 32 class MemoryDealer : public RefBase 33 { 34 public: 35 explicit MemoryDealer(size_t size, const char* name = nullptr, 36 uint32_t flags = 0 /* or bits such as MemoryHeapBase::READ_ONLY */ ); 37 38 virtual sp<IMemory> allocate(size_t size); 39 virtual void deallocate(size_t offset); 40 virtual void dump(const char* what) const; 41 42 // allocations are aligned to some value. return that value so clients can account for it. 43 static size_t getAllocationAlignment(); 44 getMemoryHeap()45 sp<IMemoryHeap> getMemoryHeap() const { return heap(); } 46 47 protected: 48 virtual ~MemoryDealer(); 49 50 private: 51 const sp<IMemoryHeap>& heap() const; 52 SimpleBestFitAllocator* allocator() const; 53 54 sp<IMemoryHeap> mHeap; 55 SimpleBestFitAllocator* mAllocator; 56 }; 57 58 59 // ---------------------------------------------------------------------------- 60 } // namespace android 61