Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Graphic Ui
提交
8d8c20d4
G
Graphic Ui
项目概览
OpenHarmony
/
Graphic Ui
大约 1 年 前同步成功
通知
13
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
Graphic Ui
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
8d8c20d4
编写于
2月 01, 2023
作者:
O
openharmony_ci
提交者:
Gitee
2月 01, 2023
浏览文件
操作
浏览文件
下载
差异文件
!866 矢量字体内存对齐
Merge pull request !866 from Lizhiqi/font_opt
上级
c14b6cf2
6be24ad9
变更
13
隐藏空白更改
内联
并排
Showing
13 changed file
with
126 addition
and
76 deletion
+126
-76
BUILD.gn
BUILD.gn
+1
-1
frameworks/draw/draw_label.cpp
frameworks/draw/draw_label.cpp
+0
-4
frameworks/font/font_ram_allocator.h
frameworks/font/font_ram_allocator.h
+2
-1
frameworks/font/glyphs_file.cpp
frameworks/font/glyphs_file.cpp
+1
-26
frameworks/font/ui_font_allocator.cpp
frameworks/font/ui_font_allocator.cpp
+57
-4
frameworks/font/ui_font_allocator.h
frameworks/font/ui_font_allocator.h
+6
-0
frameworks/font/ui_font_bitmap.cpp
frameworks/font/ui_font_bitmap.cpp
+2
-14
frameworks/font/ui_font_cache.h
frameworks/font/ui_font_cache.h
+2
-0
frameworks/font/ui_font_cache_manager.cpp
frameworks/font/ui_font_cache_manager.cpp
+5
-1
frameworks/font/ui_font_vector.cpp
frameworks/font/ui_font_vector.cpp
+40
-16
interfaces/innerkits/font/ui_font_bitmap.h
interfaces/innerkits/font/ui_font_bitmap.h
+0
-1
interfaces/innerkits/font/ui_font_vector.h
interfaces/innerkits/font/ui_font_vector.h
+0
-8
interfaces/kits/font/ui_font_header.h
interfaces/kits/font/ui_font_header.h
+10
-0
未找到文件。
BUILD.gn
浏览文件 @
8d8c20d4
...
...
@@ -43,7 +43,7 @@ config("graphic_define_config") {
if (defined(board_toolchain_type) && board_toolchain_type == "iccarm") {
cflags = [
"--diag_suppress",
"Pa084,Pa093,Pa137,Pe161,Pe177,Pe186,Pe223,Pe226,Pe366,Pe367,Pe550,Pe940",
"Pa084,Pa093,Pa137,Pe161,Pe177,Pe186,Pe223,Pe226,Pe366,Pe367,Pe550,Pe940
,Pe068
",
]
cflags_cc = cflags
}
...
...
frameworks/draw/draw_label.cpp
浏览文件 @
8d8c20d4
...
...
@@ -89,13 +89,9 @@ uint16_t DrawLabel::DrawTextOneLine(BufferInfo& gfxDstBuffer, const LabelLineInf
uint8_t
*
fontMap
=
fontEngine
->
GetBitmap
(
letterInfo
.
letter
,
glyphNode
,
letterInfo
.
fontId
,
letterInfo
.
fontSize
,
letterInfo
.
shapingId
);
if
(
fontMap
!=
nullptr
)
{
#if defined(ENABLE_VECTOR_FONT) && ENABLE_VECTOR_FONT
if
(
TypedText
::
IsColourWord
(
letterInfo
.
letter
,
fontId
,
fontSize
))
{
#else
uint8_t
weight
=
UIFont
::
GetInstance
()
->
GetFontWeight
(
glyphNode
.
fontId
);
// 16: rgb565->16 rgba8888->32 font with rgba
if
(
weight
>=
16
)
{
#endif
DrawUtils
::
GetInstance
()
->
DrawColorLetter
(
gfxDstBuffer
,
letterInfo
,
fontMap
,
glyphNode
);
}
else
{
letterInfo
.
offsetY
=
labelLine
.
ellipsisOssetY
==
0
?
offsetPosY
:
labelLine
.
ellipsisOssetY
;
...
...
frameworks/font/font_ram_allocator.h
浏览文件 @
8d8c20d4
...
...
@@ -16,9 +16,10 @@
#ifndef FONT_RAM_ALLOCATOR_H
#define FONT_RAM_ALLOCATOR_H
#include <cstdint>
#include "font/ui_font_allocator.h"
#include "gfx_utils/heap_base.h"
#include <cstdint>
namespace
OHOS
{
class
FontRamAllocator
:
public
HeapBase
{
...
...
frameworks/font/glyphs_file.cpp
浏览文件 @
8d8c20d4
...
...
@@ -292,31 +292,6 @@ int16_t GlyphsFile::GetFontHeight(uint16_t fontId)
return
glyphInfo
.
fontHeader
->
fontHeight
;
}
namespace
{
void
RearrangeBitmap
(
BufferInfo
&
bufInfo
,
uint32_t
fileSz
)
{
uint32_t
word
=
bufInfo
.
width
;
word
=
BIT_TO_BYTE
(
word
*
DrawUtils
::
GetPxSizeByColorMode
(
bufInfo
.
mode
));
if
(
bufInfo
.
stride
<=
word
)
{
return
;
}
uint8_t
*
bitmap
=
reinterpret_cast
<
uint8_t
*>
(
bufInfo
.
virAddr
);
uint32_t
suffixLen
=
bufInfo
.
stride
-
word
;
uint8_t
*
rdestBuf
=
bitmap
+
bufInfo
.
stride
*
bufInfo
.
height
;
uint8_t
*
rsrcBuf
=
bitmap
+
fileSz
;
/* Rearrange bitmap in local buffer */
for
(
uint32_t
row
=
0
;
row
<
bufInfo
.
height
;
row
++
)
{
rdestBuf
-=
suffixLen
;
(
void
)
memset_s
(
rdestBuf
,
suffixLen
,
0
,
suffixLen
);
for
(
uint32_t
i
=
0
;
i
<
word
;
i
++
)
{
*
(
--
rdestBuf
)
=
*
(
--
rsrcBuf
);
}
}
BaseGfxEngine
::
GetInstance
()
->
MemoryBarrier
();
}
}
// namespace
int8_t
GlyphsFile
::
GetBitmap
(
GlyphNode
&
node
,
BufferInfo
&
bufInfo
)
{
...
...
@@ -345,7 +320,7 @@ int8_t GlyphsFile::GetBitmap(GlyphNode& node, BufferInfo& bufInfo)
GRAPHIC_LOGE
(
"GlyphsFile::GetBitmap read failed"
);
return
INVALID_RET_VALUE
;
}
RearrangeBitmap
(
bufInfo
,
siz
e
);
UIFontAllocator
::
RearrangeBitmap
(
bufInfo
,
size
,
fals
e
);
node
.
dataFlag
=
node
.
fontId
;
return
RET_VALUE_OK
;
...
...
frameworks/font/ui_font_allocator.cpp
浏览文件 @
8d8c20d4
...
...
@@ -15,6 +15,10 @@
#include "font/ui_font_allocator.h"
#include "draw/draw_utils.h"
#include "engines/gfx/gfx_engine_manager.h"
#include "font/ui_font.h"
#include "font/ui_font_cache_manager.h"
#include "gfx_utils/graphic_buffer.h"
namespace
OHOS
{
...
...
@@ -27,14 +31,19 @@ UIFontAllocator::~UIFontAllocator() {}
void
UIFontAllocator
::
SetRamAddr
(
uint8_t
*
ram
,
uint32_t
size
)
{
UI_ADDR_ALIGN
(
ram
,
size
);
struct
Chunk
*
chunk
=
nullptr
;
ram_
=
ram
;
if
(
size
<=
sizeof
(
struct
Chunk
)
*
2
)
{
// 2 : head and tail two chunk
ramSize_
=
0
;
return
;
}
if
(
ram
==
nullptr
)
{
ramSize_
=
0
;
return
;
}
UI_ADDR_ALIGN
(
ram
,
size
);
ram_
=
ram
;
struct
Chunk
*
chunk
=
nullptr
;
ramSize_
=
size
-
sizeof
(
struct
Chunk
)
*
2
;
// head and tail two chunk
chunk
=
reinterpret_cast
<
struct
Chunk
*>
(
ram_
);
chunk
->
next
=
size
-
sizeof
(
struct
Chunk
);
...
...
@@ -166,4 +175,48 @@ void UIFontAllocator::Free(void* addr)
freeSize_
+=
chunk
->
next
-
(
reinterpret_cast
<
uint8_t
*>
(
chunk
)
-
ram_
);
CombineFree
(
chunk
);
}
BufferInfo
UIFontAllocator
::
GetCacheBuffer
(
uint16_t
fontId
,
uint32_t
unicode
,
ColorMode
mode
,
GlyphNode
&
glyphNode
,
bool
hasMetric
)
{
BufferInfo
bufInfo
{
Rect
(),
0
,
nullptr
,
nullptr
,
glyphNode
.
cols
,
glyphNode
.
rows
,
mode
,
0
};
bufInfo
.
stride
=
BIT_TO_BYTE
(
bufInfo
.
width
*
DrawUtils
::
GetPxSizeByColorMode
(
bufInfo
.
mode
));
BaseGfxEngine
::
GetInstance
()
->
AdjustLineStride
(
bufInfo
);
uint32_t
bitmapSize
=
bufInfo
.
stride
*
bufInfo
.
height
;
if
(
hasMetric
)
{
bitmapSize
+=
sizeof
(
Metric
);
}
bufInfo
.
virAddr
=
reinterpret_cast
<
void
*>
(
UIFontCacheManager
::
GetInstance
()
->
GetSpace
(
fontId
,
unicode
,
bitmapSize
));
return
bufInfo
;
}
void
UIFontAllocator
::
RearrangeBitmap
(
BufferInfo
&
bufInfo
,
uint32_t
fileSz
,
bool
hasMetric
)
{
uint32_t
word
=
bufInfo
.
width
;
word
=
BIT_TO_BYTE
(
word
*
DrawUtils
::
GetPxSizeByColorMode
(
bufInfo
.
mode
));
if
(
bufInfo
.
stride
<=
word
)
{
return
;
}
uint8_t
*
bitmap
=
reinterpret_cast
<
uint8_t
*>
(
bufInfo
.
virAddr
);
if
(
hasMetric
)
{
bitmap
+=
sizeof
(
Metric
);
}
uint32_t
suffixLen
=
bufInfo
.
stride
-
word
;
uint8_t
*
rdestBuf
=
bitmap
+
bufInfo
.
stride
*
bufInfo
.
height
;
uint8_t
*
rsrcBuf
=
bitmap
+
fileSz
;
/* Rearrange bitmap in local buffer */
for
(
uint32_t
row
=
0
;
row
<
bufInfo
.
height
;
row
++
)
{
rdestBuf
-=
suffixLen
;
(
void
)
memset_s
(
rdestBuf
,
suffixLen
,
0
,
suffixLen
);
for
(
uint32_t
i
=
0
;
i
<
word
;
i
++
)
{
*
(
--
rdestBuf
)
=
*
(
--
rsrcBuf
);
}
}
BaseGfxEngine
::
GetInstance
()
->
MemoryBarrier
();
}
}
// namespace OHOS
frameworks/font/ui_font_allocator.h
浏览文件 @
8d8c20d4
...
...
@@ -18,6 +18,7 @@
#include <stdint.h>
#include "font/ui_font_header.h"
#include "gfx_utils/graphic_buffer.h"
namespace
OHOS
{
...
...
@@ -50,6 +51,11 @@ public:
void
Free
(
void
*
addr
);
static
BufferInfo
GetCacheBuffer
(
uint16_t
fontId
,
uint32_t
unicode
,
ColorMode
mode
,
GlyphNode
&
glyphNode
,
bool
hasMetric
);
static
void
RearrangeBitmap
(
BufferInfo
&
bufInfo
,
uint32_t
fileSz
,
bool
hasMetric
);
private:
void
CombineFree
(
Chunk
*
cache
);
...
...
frameworks/font/ui_font_bitmap.cpp
浏览文件 @
8d8c20d4
...
...
@@ -228,18 +228,6 @@ uint8_t* UIFontBitmap::GetCacheBitmap(uint16_t fontId, uint32_t unicode)
return
UIFontCacheManager
::
GetInstance
()
->
GetBitmap
(
fontId
,
unicode
);
}
BufferInfo
UIFontBitmap
::
GetCacheBuffer
(
uint16_t
fontId
,
uint32_t
unicode
,
GlyphNode
&
glyphNode
)
{
ColorMode
mode
=
UIFont
::
GetInstance
()
->
GetColorType
(
fontId
);
BufferInfo
bufInfo
{
Rect
(),
0
,
nullptr
,
nullptr
,
glyphNode
.
cols
,
glyphNode
.
rows
,
mode
,
0
};
bufInfo
.
stride
=
BIT_TO_BYTE
(
bufInfo
.
width
*
DrawUtils
::
GetPxSizeByColorMode
(
bufInfo
.
mode
));
BaseGfxEngine
::
GetInstance
()
->
AdjustLineStride
(
bufInfo
);
uint32_t
bitmapSize
=
bufInfo
.
stride
*
bufInfo
.
height
;
bufInfo
.
virAddr
=
reinterpret_cast
<
void
*>
(
UIFontCacheManager
::
GetInstance
()
->
GetSpace
(
fontId
,
unicode
,
bitmapSize
));
return
bufInfo
;
}
void
UIFontBitmap
::
PutCacheSpace
(
uint8_t
*
addr
)
{
UIFontCacheManager
::
GetInstance
()
->
PutSpace
(
addr
);
...
...
@@ -275,8 +263,8 @@ uint8_t* UIFontBitmap::SearchInFont(uint32_t unicode, GlyphNode& glyphNode, uint
if
(
glyphNode
.
kernOff
<=
glyphNode
.
dataOff
)
{
return
nullptr
;
}
BufferInfo
bufInfo
=
GetCacheBuffer
(
fontId
,
unicode
,
glyphNod
e
);
ColorMode
mode
=
UIFont
::
GetInstance
()
->
GetColorType
(
fontId
);
BufferInfo
bufInfo
=
UIFontAllocator
::
GetCacheBuffer
(
fontId
,
unicode
,
mode
,
glyphNode
,
fals
e
);
ret
=
dynamicFont_
.
GetBitmap
(
unicode
,
bufInfo
,
fontId
);
if
(
ret
==
RET_VALUE_OK
)
{
return
reinterpret_cast
<
uint8_t
*>
(
bufInfo
.
virAddr
);
...
...
frameworks/font/ui_font_cache.h
浏览文件 @
8d8c20d4
...
...
@@ -54,6 +54,8 @@ public:
ListHead
lruHead
;
uint32_t
fontId
;
// bitmap font: fontId vector font: fontKey ttfId + fontsize
uint32_t
unicode
;
uint32_t
reserve1
;
uint32_t
reserve2
;
#if defined(ENABLE_SPANNABLE_STRING) && ENABLE_SPANNABLE_STRING
TextStyle
textStyle
;
#endif
...
...
frameworks/font/ui_font_cache_manager.cpp
浏览文件 @
8d8c20d4
...
...
@@ -16,6 +16,7 @@
#include "font/ui_font_cache_manager.h"
#include "font/font_ram_allocator.h"
#include "gfx_utils/graphic_log.h"
#include "securec.h"
namespace
OHOS
{
UIFontCacheManager
::
UIFontCacheManager
()
:
bitmapCache_
(
nullptr
)
{}
...
...
@@ -72,7 +73,10 @@ void UIFontCacheManager::BitmapCacheInit()
return
;
}
memset
(
bitmapCacheAddr
,
0
,
bitmapCacheSize_
);
if
(
memset_s
(
bitmapCacheAddr
,
bitmapCacheSize_
,
0
,
bitmapCacheSize_
)
!=
EOK
)
{
GRAPHIC_LOGE
(
"UIFontCacheManager::BitmapCacheInit memset failed"
);
return
;
}
bitmapCache_
=
new
UIFontCache
(
bitmapCacheAddr
,
bitmapCacheSize_
);
}
...
...
frameworks/font/ui_font_vector.cpp
浏览文件 @
8d8c20d4
...
...
@@ -867,35 +867,59 @@ void UIFontVector::SetFace(FaceInfo& faceInfo, uint32_t unicode)
#if defined(ENABLE_SPANNALBE_STRING) && ENABLE_SPANNALBE_STRING
SetFace
(
faceInfo
,
unicode
,
TEXT_STYLE_NORMAL
);
#else
Metric
f
;
f
.
advance
=
static_cast
<
uint16_t
>
(
faceInfo
.
face
->
glyph
->
advance
.
x
/
FONT_PIXEL_IN_POINT
);
f
.
left
=
faceInfo
.
face
->
glyph
->
bitmap_left
;
f
.
top
=
faceInfo
.
face
->
glyph
->
bitmap_top
;
f
.
cols
=
faceInfo
.
face
->
glyph
->
bitmap
.
width
;
f
.
rows
=
faceInfo
.
face
->
glyph
->
bitmap
.
rows
;
Metric
*
f
=
reinterpret_cast
<
Metric
*>
(
UIMalloc
(
sizeof
(
Metric
)));
if
(
f
==
nullptr
)
{
return
;
}
f
->
advance
=
static_cast
<
uint16_t
>
(
faceInfo
.
face
->
glyph
->
advance
.
x
/
FONT_PIXEL_IN_POINT
);
f
->
left
=
faceInfo
.
face
->
glyph
->
bitmap_left
;
f
->
top
=
faceInfo
.
face
->
glyph
->
bitmap_top
;
f
->
cols
=
faceInfo
.
face
->
glyph
->
bitmap
.
width
;
f
->
rows
=
faceInfo
.
face
->
glyph
->
bitmap
.
rows
;
// cache glyph
SaveGlyphNode
(
unicode
,
faceInfo
.
key
,
&
f
);
SaveGlyphNode
(
unicode
,
faceInfo
.
key
,
f
);
int16_t
pixSize
=
1
;
int16_t
pixSize
;
ColorMode
mode
;
if
(
faceInfo
.
face
->
glyph
->
bitmap
.
pixel_mode
==
FT_PIXEL_MODE_BGRA
)
{
pixSize
=
0x04
;
// 4 Byte
mode
=
ARGB8888
;
}
uint32_t
bitmapSize
=
faceInfo
.
face
->
glyph
->
bitmap
.
width
*
faceInfo
.
face
->
glyph
->
bitmap
.
rows
*
pixSize
;
// cache bitmap
uint8_t
*
bitmap
=
UIFontCacheManager
::
GetInstance
()
->
GetSpace
(
faceInfo
.
key
,
unicode
,
bitmapSize
+
sizeof
(
Metric
));
if
(
bitmap
!=
nullptr
)
{
if
(
memcpy_s
(
bitmap
,
sizeof
(
Metric
),
&
f
,
sizeof
(
Metric
))
!=
EOK
)
{
UIFontCacheManager
::
GetInstance
()
->
PutSpace
(
bitmap
);
else
{
pixSize
=
1
;
mode
=
A8
;
}
GlyphNode
glyphNode
;
glyphNode
.
left
=
f
->
left
;
glyphNode
.
top
=
f
->
top
;
glyphNode
.
cols
=
f
->
cols
;
glyphNode
.
rows
=
f
->
rows
;
glyphNode
.
advance
=
f
->
advance
;
glyphNode
.
unicode
=
unicode
;
glyphNode
.
fontId
=
faceInfo
.
key
;
BufferInfo
bufInfo
=
UIFontAllocator
::
GetCacheBuffer
(
faceInfo
.
key
,
unicode
,
mode
,
glyphNode
,
true
);
uint32_t
bitmapSize
=
bufInfo
.
stride
*
bufInfo
.
height
;
uint32_t
rawSize
=
glyphNode
.
cols
*
glyphNode
.
rows
*
pixSize
;
if
(
bufInfo
.
virAddr
!=
nullptr
)
{
if
(
memcpy_s
(
bufInfo
.
virAddr
,
sizeof
(
Metric
),
f
,
sizeof
(
Metric
))
!=
EOK
)
{
UIFontCacheManager
::
GetInstance
()
->
PutSpace
(
reinterpret_cast
<
uint8_t
*>
(
bufInfo
.
virAddr
));
UIFree
(
f
);
return
;
}
if
((
faceInfo
.
face
->
glyph
->
bitmap
.
buffer
!=
nullptr
)
&&
(
memcpy_s
(
bitmap
+
sizeof
(
Metric
),
bitmapSize
,
faceInfo
.
face
->
glyph
->
bitmap
.
buffer
,
bitmapSize
)
!=
EOK
))
{
UIFontCacheManager
::
GetInstance
()
->
PutSpace
(
bitmap
);
(
memcpy_s
(
reinterpret_cast
<
uint8_t
*>
(
bufInfo
.
virAddr
)
+
sizeof
(
Metric
),
bitmapSize
,
faceInfo
.
face
->
glyph
->
bitmap
.
buffer
,
rawSize
)
!=
EOK
))
{
UIFontCacheManager
::
GetInstance
()
->
PutSpace
(
reinterpret_cast
<
uint8_t
*>
(
bufInfo
.
virAddr
));
UIFree
(
f
);
return
;
}
UIFontAllocator
::
RearrangeBitmap
(
bufInfo
,
rawSize
,
true
);
ClearFontGlyph
(
faceInfo
.
face
);
}
UIFree
(
f
);
#endif
}
...
...
interfaces/innerkits/font/ui_font_bitmap.h
浏览文件 @
8d8c20d4
...
...
@@ -53,7 +53,6 @@ public:
protected:
int8_t
GetDynamicFontBitmap
(
uint32_t
unicode
,
BufferInfo
&
bufInfo
,
uint16_t
fontId
);
uint8_t
*
GetCacheBitmap
(
uint16_t
fontId
,
uint32_t
unicode
);
BufferInfo
GetCacheBuffer
(
uint16_t
fontId
,
uint32_t
unicode
,
GlyphNode
&
glyphNode
);
void
PutCacheSpace
(
uint8_t
*
addr
);
int16_t
GetDynamicFontWidth
(
uint32_t
unicode
,
uint16_t
fontId
);
uint32_t
offset_
;
...
...
interfaces/innerkits/font/ui_font_vector.h
浏览文件 @
8d8c20d4
...
...
@@ -81,14 +81,6 @@ private:
const
char
*
ttcName
;
FT_Stream
stream
;
};
struct
Metric
{
int
left
;
int
top
;
int
cols
;
int
rows
;
int
advance
;
uint8_t
buf
[
0
];
};
TtcInfo
ttcInfos_
[
FONT_TTC_MAX
]
=
{};
void
SetFace
(
FaceInfo
&
faceInfo
,
uint32_t
unicode
);
#if defined(ENABLE_SPANNABLE_STRING) && ENABLE_SPANNABLE_STRING
...
...
interfaces/kits/font/ui_font_header.h
浏览文件 @
8d8c20d4
...
...
@@ -18,6 +18,7 @@
#include <string>
#include "graphic_config.h"
#include "gfx_utils/common_macros.h"
namespace
OHOS
{
#pragma pack(1)
#define BIT_TO_BYTE(x) (((x) + 0x7) >> 3)
...
...
@@ -413,6 +414,15 @@ struct TtfInfo {
uint8_t
shaping
;
};
struct
UI_STRUCT_ALIGN
Metric
{
int
left
;
int
top
;
int
cols
;
int
rows
;
int
advance
;
uint8_t
buf
[
0
];
};
#pragma pack()
}
// namespace OHOS
#endif
/* UI_FONT_HEADER_H */
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录