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/Common.h> 23 #include <binder/IMemory.h> 24 #include <binder/MemoryHeapBase.h> 25 26 namespace android { 27 // ---------------------------------------------------------------------------- 28 29 class SimpleBestFitAllocator; 30 31 // ---------------------------------------------------------------------------- 32 33 class MemoryDealer : public RefBase { 34 public: 35 LIBBINDER_EXPORTED explicit MemoryDealer( 36 size_t size, const char* name = nullptr, 37 uint32_t flags = 0 /* or bits such as MemoryHeapBase::READ_ONLY */); 38 39 LIBBINDER_EXPORTED virtual sp<IMemory> allocate(size_t size); 40 LIBBINDER_EXPORTED 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 LIBBINDER_EXPORTED static size_t getAllocationAlignment(); 44 getMemoryHeap()45 sp<IMemoryHeap> getMemoryHeap() const { return heap(); } 46 47 protected: 48 LIBBINDER_EXPORTED virtual ~MemoryDealer(); 49 50 private: 51 friend class Allocation; 52 virtual void deallocate(size_t offset); 53 LIBBINDER_EXPORTED const sp<IMemoryHeap>& heap() const; 54 SimpleBestFitAllocator* allocator() const; 55 56 sp<IMemoryHeap> mHeap; 57 SimpleBestFitAllocator* mAllocator; 58 }; 59 60 // ---------------------------------------------------------------------------- 61 } // namespace android 62