1 /* 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef FONT_RAM_ALLOCATOR_H 17 #define FONT_RAM_ALLOCATOR_H 18 19 #include <cstdint> 20 21 #include "font/ui_font_allocator.h" 22 #include "gfx_utils/heap_base.h" 23 24 namespace OHOS { 25 class FontRamAllocator : public HeapBase { 26 static constexpr uint8_t RAM_ALIGN = 2; // align up to 4 byte, power of 2 27 public: 28 FontRamAllocator(); 29 30 FontRamAllocator(const FontRamAllocator&) = delete; 31 32 FontRamAllocator& operator=(const FontRamAllocator&) = delete; 33 34 FontRamAllocator(const FontRamAllocator&&) = delete; 35 36 FontRamAllocator& operator=(const FontRamAllocator&&) = delete; 37 38 ~FontRamAllocator(); 39 GetInstance(void)40 static FontRamAllocator& GetInstance(void) 41 { 42 static FontRamAllocator instance_; 43 return instance_; 44 } 45 46 void SetRamAddr(uintptr_t ramAddr, uint32_t ramLen); 47 void* Allocate(uint32_t size); 48 uint32_t GetRamUsedLen(); 49 void ClearRam(); 50 void* DynamicAllocate(uint32_t size); 51 void DynamicFree(void* addr); 52 uint32_t GetMemSize(void* addr); 53 54 private: 55 uint32_t AlignUp(uint32_t addr); 56 bool IsAligned(uint32_t addr); 57 58 uintptr_t ramAddr_; 59 uint32_t ramLen_; 60 uintptr_t currentRamAddr_; 61 uintptr_t dynamicAddr_; 62 UIFontAllocator allocator_; 63 }; 64 } // namespace OHOS 65 #endif /* FONT_RAM_ALLOCATOR_H */