• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2020-2021 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 UI_FONT_ALLOCATOR_H
17 #define UI_FONT_ALLOCATOR_H
18 
19 #include <stdint.h>
20 
21 #include "font/ui_font_header.h"
22 #include "gfx_utils/graphic_buffer.h"
23 
24 namespace OHOS {
25 class UIFontAllocator {
26     struct UI_STRUCT_ALIGN Chunk {
27         uint32_t next;
28         uint32_t prev;
29         bool used;
30         uint32_t reserve;
31     };
32 
33 public:
34     UIFontAllocator();
35 
36     ~UIFontAllocator();
37 
38     void SetRamAddr(uint8_t* ram, uint32_t size);
39 
40     void SetMinChunkSize(uint32_t size);
41 
42     uint32_t GetSize(void* addr);
43 
44     /**
45      * @brief allocate memory
46      *
47      * @param size
48      * @return memory address
49      */
50     void* Allocate(uint32_t size);
51 
52     void Free(void* addr);
53 
54     static BufferInfo
55         GetCacheBuffer(uint16_t fontId, uint32_t unicode, ColorMode mode, GlyphNode& glyphNode, bool hasMetric);
56 
57     static void RearrangeBitmap(BufferInfo& bufInfo, uint32_t fileSz, bool hasMetric);
58 
59 private:
60     void CombineFree(Chunk* cache);
61 
62     uint8_t* ram_;
63     uint32_t ramSize_;
64     uint32_t freeSize_;
65     uint32_t minSize_;
66     struct Chunk* end_;
67     struct Chunk* free_;
68 };
69 } // namespace OHOS
70 #endif /* UI_FONT_ALLOCATOR_H */
71