mirror of
https://github.com/openharmony/graphic_graphic_utils_lite.git
synced 2026-07-01 01:37:57 -04:00
update openharmony 1.0.1
This commit is contained in:
+160
@@ -0,0 +1,160 @@
|
||||
Language: Cpp
|
||||
# BasedOnStyle: LLVM
|
||||
# 访问说明符(public、private等)的偏移
|
||||
AccessModifierOffset: -4
|
||||
# 开括号(开圆括号、开尖括号、开方括号)后的对齐
|
||||
AlignAfterOpenBracket: Align
|
||||
# 连续赋值时,等号对齐
|
||||
AlignConsecutiveAssignments: false
|
||||
# 连续赋值时,变量名对齐
|
||||
AlignConsecutiveDeclarations: false
|
||||
# 左对齐逃脱换行(使用反斜杠换行)的反斜杠
|
||||
AlignEscapedNewlinesLeft: true
|
||||
# 水平对齐二元和三元表达式的操作数
|
||||
AlignOperands: true
|
||||
# 对齐连续的尾随的注释
|
||||
AlignTrailingComments: true
|
||||
# 允许函数声明的所有参数在放在下一行
|
||||
AllowAllParametersOfDeclarationOnNextLine: false
|
||||
# 允许短的块放在同一行
|
||||
AllowShortBlocksOnASingleLine: false
|
||||
# 允许短的case标签放在同一行
|
||||
AllowShortCaseLabelsOnASingleLine: false
|
||||
# 允许短的函数放在同一行: None, InlineOnly(定义在类中), Empty(空函数), Inline(定义在类中,空函数), All
|
||||
AllowShortFunctionsOnASingleLine: Empty
|
||||
# 允许短的if语句保持在同一行
|
||||
AllowShortIfStatementsOnASingleLine: false
|
||||
# 允许短的循环保持在同一行
|
||||
AllowShortLoopsOnASingleLine: false
|
||||
# 总是在定义返回类型后换行(deprecated)
|
||||
AlwaysBreakAfterDefinitionReturnType: None
|
||||
# 总是在返回类型后换行: None, All, TopLevel(顶级函数,不包括在类中的函数),
|
||||
# AllDefinitions(所有的定义,不包括声明), TopLevelDefinitions(所有的顶级函数的定义)
|
||||
AlwaysBreakAfterReturnType: None
|
||||
# 总是在多行string字面量前换行
|
||||
AlwaysBreakBeforeMultilineStrings: true
|
||||
# 总是在template声明后换行
|
||||
AlwaysBreakTemplateDeclarations: false
|
||||
# false表示函数实参要么都在同一行,要么都各自一行
|
||||
BinPackArguments: true
|
||||
# false表示所有形参要么都在同一行,要么都各自一行
|
||||
BinPackParameters: false
|
||||
# 大括号换行,只有当BreakBeforeBraces设置为Custom时才有效
|
||||
BraceWrapping:
|
||||
AfterClass: false
|
||||
AfterControlStatement: false
|
||||
AfterEnum: false
|
||||
AfterFunction: true
|
||||
AfterNamespace: false
|
||||
AfterObjCDeclaration: false
|
||||
AfterStruct: false
|
||||
AfterUnion: false
|
||||
BeforeCatch: false
|
||||
BeforeElse: false
|
||||
IndentBraces: false
|
||||
# 在二元运算符前换行: None(在操作符后换行), NonAssignment(在非赋值的操作符前换行), All(在操作符前换行)
|
||||
BreakBeforeBinaryOperators: None
|
||||
# 在大括号前换行: Attach(始终将大括号附加到周围的上下文), Linux(除函数、命名空间和类定义,与Attach类似),
|
||||
# Mozilla(除枚举、函数、记录定义,与Attach类似), Stroustrup(除函数定义、catch、else,与Attach类似),
|
||||
# Allman(总是在大括号前换行), GNU(总是在大括号前换行,并对于控制语句的大括号增加额外的缩进), WebKit(在函数前换行), Custom
|
||||
# 注:这里认为语句块也属于函数
|
||||
BreakBeforeBraces: Custom
|
||||
# 在三元运算符前换行
|
||||
BreakBeforeTernaryOperators: true
|
||||
# 在构造函数的初始化列表的逗号前换行
|
||||
BreakConstructorInitializersBeforeComma: false
|
||||
# 每行字符的限制,0表示没有限制
|
||||
ColumnLimit: 120
|
||||
# 描述具有特殊意义的注释的正则表达式,它不应该被分割为多行或以其它方式改变
|
||||
CommentPragmas: "^ IWYU pragma:"
|
||||
# 构造函数的初始化列表要么都在同一行,要么都各自一行
|
||||
ConstructorInitializerAllOnOneLineOrOnePerLine: true
|
||||
# 构造函数的初始化列表的缩进宽度
|
||||
ConstructorInitializerIndentWidth: 4
|
||||
# 延续的行的缩进宽度
|
||||
ContinuationIndentWidth: 4
|
||||
# 去除C++11的列表初始化的大括号{后和}前的空格
|
||||
Cpp11BracedListStyle: true
|
||||
# 继承最常用的指针和引用的对齐方式
|
||||
DerivePointerAlignment: false
|
||||
# 关闭格式化
|
||||
DisableFormat: false
|
||||
# 自动检测函数的调用和定义是否被格式为每行一个参数(Experimental)
|
||||
ExperimentalAutoDetectBinPacking: false
|
||||
# 需要被解读为foreach循环而不是函数调用的宏
|
||||
ForEachMacros: [foreach, Q_FOREACH, BOOST_FOREACH]
|
||||
# 对#include进行排序,匹配了某正则表达式的#include拥有对应的优先级,匹配不到的则默认优先级为INT_MAX(优先级越小排序越靠前),
|
||||
# 可以定义负数优先级从而保证某些#include永远在最前面
|
||||
IncludeCategories:
|
||||
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
|
||||
Priority: 2
|
||||
- Regex: '^(<|"(gtest|isl|json)/)'
|
||||
Priority: 3
|
||||
- Regex: ".*"
|
||||
Priority: 1
|
||||
# 缩进case标签
|
||||
IndentCaseLabels: true
|
||||
# 缩进宽度
|
||||
IndentWidth: 4
|
||||
# 函数返回类型换行时,缩进函数声明或函数定义的函数名
|
||||
IndentWrappedFunctionNames: true
|
||||
# 保留在块开始处的空行
|
||||
KeepEmptyLinesAtTheStartOfBlocks: true
|
||||
# 开始一个块的宏的正则表达式
|
||||
MacroBlockBegin: ""
|
||||
# 结束一个块的宏的正则表达式
|
||||
MacroBlockEnd: ""
|
||||
# 连续空行的最大数量
|
||||
MaxEmptyLinesToKeep: 1
|
||||
# 命名空间的缩进: None, Inner(缩进嵌套的命名空间中的内容), All
|
||||
NamespaceIndentation: None
|
||||
# 使用ObjC块时缩进宽度
|
||||
ObjCBlockIndentWidth: 4
|
||||
# 在ObjC的@property后添加一个空格
|
||||
ObjCSpaceAfterProperty: false
|
||||
# 在ObjC的protocol列表前添加一个空格
|
||||
ObjCSpaceBeforeProtocolList: true
|
||||
# 在call(后对函数调用换行的penalty
|
||||
PenaltyBreakBeforeFirstCallParameter: 19
|
||||
# 在一个注释中引入换行的penalty
|
||||
PenaltyBreakComment: 300
|
||||
# 第一次在<<前换行的penalty
|
||||
PenaltyBreakFirstLessLess: 120
|
||||
# 在一个字符串字面量中引入换行的penalty
|
||||
PenaltyBreakString: 1000
|
||||
# 对于每个在行字符数限制之外的字符的penalt
|
||||
PenaltyExcessCharacter: 1000000
|
||||
# 将函数的返回类型放到它自己的行的penalty
|
||||
PenaltyReturnTypeOnItsOwnLine: 60
|
||||
# 指针和引用的对齐: Left, Right, Middle
|
||||
PointerAlignment: Left
|
||||
# 允许重新排版注释
|
||||
ReflowComments: true
|
||||
# 允许排序#include
|
||||
SortIncludes: true
|
||||
# 在C风格类型转换后添加空格
|
||||
SpaceAfterCStyleCast: false
|
||||
# 在赋值运算符之前添加空格
|
||||
SpaceBeforeAssignmentOperators: true
|
||||
# 开圆括号之前添加一个空格: Never, ControlStatements, Always
|
||||
SpaceBeforeParens: ControlStatements
|
||||
# 在空的圆括号中添加空格
|
||||
SpaceInEmptyParentheses: false
|
||||
# 在尾随的评论前添加的空格数(只适用于//)
|
||||
SpacesBeforeTrailingComments: 1
|
||||
# 在尖括号的<后和>前添加空格
|
||||
SpacesInAngles: false
|
||||
# 在容器(ObjC和JavaScript的数组和字典等)字面量中添加空格
|
||||
SpacesInContainerLiterals: true
|
||||
# 在C风格类型转换的括号中添加空格
|
||||
SpacesInCStyleCastParentheses: false
|
||||
# 在圆括号的(后和)前添加空格
|
||||
SpacesInParentheses: false
|
||||
# 在方括号的[后和]前添加空格,lamda表达式和未指明大小的数组的声明不受影响
|
||||
SpacesInSquareBrackets: false
|
||||
# 标准: Cpp03, Cpp11, Auto
|
||||
Standard: Cpp11
|
||||
# tab宽度
|
||||
TabWidth: 4
|
||||
# 使用tab字符: Never, ForIndentation, ForContinuationAndIndentation, Always
|
||||
UseTab: Never
|
||||
@@ -0,0 +1,96 @@
|
||||
# Copyright (c) 2020-2021 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("//build/lite/config/component/lite_component.gni")
|
||||
import("//build/lite/config/subsystem/graphic/config.gni")
|
||||
import("//build/lite/ndk/ndk.gni")
|
||||
|
||||
lite_component("lite_graphic_utils") {
|
||||
features = [ ":graphic_utils" ]
|
||||
public_deps = features
|
||||
}
|
||||
|
||||
ndk_lib("lite_graphic_utils_ndk") {
|
||||
lib_extension = ".so"
|
||||
deps = [ ":graphic_utils" ]
|
||||
head_files = [ "interfaces/kits" ]
|
||||
}
|
||||
|
||||
lite_component("lite_graphic_hals") {
|
||||
features = [ ":graphic_hals" ]
|
||||
public_deps = features
|
||||
}
|
||||
|
||||
ndk_lib("lite_graphic_hals_ndk") {
|
||||
lib_extension = ".so"
|
||||
deps = [ ":graphic_hals" ]
|
||||
head_files = []
|
||||
}
|
||||
|
||||
shared_library("graphic_utils") {
|
||||
if (enable_graphic_dualcore == true) {
|
||||
defines = [ "HAL_CPU_NUM = 2" ]
|
||||
}
|
||||
|
||||
sources = [
|
||||
"frameworks/color.cpp",
|
||||
"frameworks/geometry2d.cpp",
|
||||
"frameworks/graphic_math.cpp",
|
||||
"frameworks/hal_cpu.cpp",
|
||||
"frameworks/hal_tick.cpp",
|
||||
"frameworks/mem_api.cpp",
|
||||
"frameworks/pixel_format_utils.cpp",
|
||||
"frameworks/queue.c",
|
||||
"frameworks/style.cpp",
|
||||
"frameworks/transform.cpp",
|
||||
"frameworks/version.cpp",
|
||||
]
|
||||
include_dirs = [ "frameworks" ]
|
||||
public_configs = [ ":graphic_utils_public_config" ]
|
||||
deps = [ "//third_party/bounds_checking_function:libsec_shared" ]
|
||||
public_deps =
|
||||
[ "//base/hiviewdfx/hilog_lite/frameworks/featured:hilog_shared" ]
|
||||
cflags = [ "-fPIC" ]
|
||||
cflags += [ "-Wall" ]
|
||||
cflags_cc = cflags
|
||||
}
|
||||
|
||||
config("graphic_utils_public_config") {
|
||||
include_dirs = [
|
||||
"interfaces/innerkits",
|
||||
"interfaces/kits",
|
||||
]
|
||||
}
|
||||
|
||||
shared_library("graphic_hals") {
|
||||
sources = [
|
||||
"frameworks/hals/gfx_engines.cpp",
|
||||
"frameworks/hals/hi_fbdev.cpp",
|
||||
]
|
||||
include_dirs = [ "//foundation/graphic/wms/interfaces/innerkits" ]
|
||||
deps = [
|
||||
":lite_graphic_utils",
|
||||
"//drivers/peripheral/display/hal:hdi_display",
|
||||
]
|
||||
public_configs = [ ":graphic_hals_public_config" ]
|
||||
ldflags = [
|
||||
"-ldisplay_gfx",
|
||||
"-ldisplay_gralloc",
|
||||
"-ldisplay_layer",
|
||||
]
|
||||
}
|
||||
|
||||
config("graphic_hals_public_config") {
|
||||
include_dirs = [
|
||||
"interfaces/innerkits",
|
||||
"//drivers/peripheral/display/interfaces/include",
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,177 @@
|
||||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
@@ -1,36 +0,0 @@
|
||||
# graphic_utils
|
||||
|
||||
#### Description
|
||||
{**When you're done, you can delete the content in this README and update the file with details for others getting started with your repository**}
|
||||
|
||||
#### Software Architecture
|
||||
Software architecture description
|
||||
|
||||
#### Installation
|
||||
|
||||
1. xxxx
|
||||
2. xxxx
|
||||
3. xxxx
|
||||
|
||||
#### Instructions
|
||||
|
||||
1. xxxx
|
||||
2. xxxx
|
||||
3. xxxx
|
||||
|
||||
#### Contribution
|
||||
|
||||
1. Fork the repository
|
||||
2. Create Feat_xxx branch
|
||||
3. Commit your code
|
||||
4. Create Pull Request
|
||||
|
||||
|
||||
#### Gitee Feature
|
||||
|
||||
1. You can use Readme\_XXX.md to support different languages, such as Readme\_en.md, Readme\_zh.md
|
||||
2. Gitee blog [blog.gitee.com](https://blog.gitee.com)
|
||||
3. Explore open source project [https://gitee.com/explore](https://gitee.com/explore)
|
||||
4. The most valuable open source project [GVP](https://gitee.com/gvp)
|
||||
5. The manual of Gitee [https://gitee.com/help](https://gitee.com/help)
|
||||
6. The most popular members [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)
|
||||
@@ -1,39 +1,109 @@
|
||||
# graphic_utils
|
||||
# Utils<a name="EN-US_TOPIC_0000001123083525"></a>
|
||||
|
||||
#### 介绍
|
||||
{**以下是 Gitee 平台说明,您可以替换此简介**
|
||||
Gitee 是 OSCHINA 推出的基于 Git 的代码托管平台(同时支持 SVN)。专为开发者提供稳定、高效、安全的云端软件开发协作平台
|
||||
无论是个人、团队、或是企业,都能够用 Gitee 实现代码托管、项目管理、协作开发。企业项目请看 [https://gitee.com/enterprises](https://gitee.com/enterprises)}
|
||||
- [Introduction](#section11660541593)
|
||||
- [Directory Structure](#section161941989596)
|
||||
- [Compilation and Building](#section137768191623)
|
||||
- [Description](#section1312121216216)
|
||||
- [Usage](#section129654513264)
|
||||
|
||||
#### 软件架构
|
||||
软件架构说明
|
||||
- [Repositories Involved](#section1371113476307)
|
||||
|
||||
## Introduction<a name="section11660541593"></a>
|
||||
|
||||
#### 安装教程
|
||||
The Utils module defines the common data structure in the graphics subsystem and provides a lite OS adaptation layer, which includes the lock, thread, and file system.
|
||||
|
||||
1. xxxx
|
||||
2. xxxx
|
||||
3. xxxx
|
||||
**Figure 1** Dependency between modules of the graphics subsystem<a name="fig717664212591"></a>
|
||||

|
||||
|
||||
#### 使用说明
|
||||
## Directory Structure<a name="section161941989596"></a>
|
||||
|
||||
1. xxxx
|
||||
2. xxxx
|
||||
3. xxxx
|
||||
```
|
||||
/foundation/graphic/utils
|
||||
├── frameworks # Framework code
|
||||
│ ├── hals # Hardware adaptation layer
|
||||
│ ├── linux # Linux platform adaptation layer
|
||||
│ ├── liteos # LiteOS platform adaptation layer
|
||||
│ └── windows # Windows platform adaptation layer
|
||||
├── interfaces # APIs
|
||||
│ ├── innerkits # APIs between modules
|
||||
│ │ └── hals # APIs of the hardware adaptation layer
|
||||
│ └── kits # External APIs
|
||||
└── test # Unit testing
|
||||
```
|
||||
|
||||
#### 参与贡献
|
||||
## Compilation and Building<a name="section137768191623"></a>
|
||||
|
||||
1. Fork 本仓库
|
||||
2. 新建 Feat_xxx 分支
|
||||
3. 提交代码
|
||||
4. 新建 Pull Request
|
||||
```
|
||||
# Generate the libgraphic_utils.so file in the out directory of the product folder through GN compilation.
|
||||
hb build lite_graphic_utils
|
||||
```
|
||||
|
||||
## Description<a name="section1312121216216"></a>
|
||||
|
||||
#### 特技
|
||||
### Usage<a name="section129654513264"></a>
|
||||
|
||||
- Utils is used in UI, surface, and WMS modules. For details, see the related source code.
|
||||
- The **test** folder provides unit testing for each utils API. Refer to it for the usage of utils.
|
||||
|
||||
## Repositories Involved<a name="section1371113476307"></a>
|
||||
|
||||
/hmf/graphic/surface
|
||||
|
||||
/hmf/graphic/wms
|
||||
|
||||
/hmf/graphic/ui
|
||||
|
||||
# Hals<a name="EN-US_TOPIC_0000001124625243"></a>
|
||||
|
||||
- [Introduction](#section11660541593)
|
||||
- [Directory Structure](#section161941989596)
|
||||
- [Compilation and Building](#section137768191623)
|
||||
- [Description](#section1312121216216)
|
||||
- [Usage](#section129654513264)
|
||||
|
||||
- [Repositories Involved](#section1371113476307)
|
||||
|
||||
## Introduction<a name="section11660541593"></a>
|
||||
|
||||
The Hals module adapts and encapsulates the functions related to the driver subsystem and platform, including FrameBuffer, graphics \(GFX\), and single instruction, multiple data \(SIMD\).
|
||||
|
||||
**Figure 1** Dependency between modules of the graphics subsystem and that between graphics modules and the driver subsystem<a name="fig717664212591"></a>
|
||||

|
||||
|
||||
## Directory Structure<a name="section161941989596"></a>
|
||||
|
||||
```
|
||||
/foundation/graphic/utils
|
||||
├── frameworks # Framework code
|
||||
│ ├── hals # Hardware adaptation layer
|
||||
│ ├── linux # Linux platform adaptation layer
|
||||
│ ├── liteos # LiteOS platform adaptation layer
|
||||
│ └── windows # Windows platform adaptation layer
|
||||
├── interfaces # APIs
|
||||
│ ├── innerkits # APIs between modules
|
||||
│ │ └── hals # APIs of the hardware adaptation layer
|
||||
│ └── kits # External APIs
|
||||
└── test # Unit testing
|
||||
```
|
||||
|
||||
## Compilation and Building<a name="section137768191623"></a>
|
||||
|
||||
```
|
||||
# Generate the libgraphic_hals.so file in the out directory of the product folder through GN compilation.
|
||||
hb build lite_graphic_utils
|
||||
```
|
||||
|
||||
## Description<a name="section1312121216216"></a>
|
||||
|
||||
### Usage<a name="section129654513264"></a>
|
||||
|
||||
- Hals is used in UI, surface, and WMS modules. For details, see the related source code.
|
||||
|
||||
## Repositories Involved<a name="section1371113476307"></a>
|
||||
|
||||
/hmf/graphic/surface
|
||||
|
||||
/hmf/graphic/wms
|
||||
|
||||
/hmf/graphic/ui
|
||||
|
||||
1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md
|
||||
2. Gitee 官方博客 [blog.gitee.com](https://blog.gitee.com)
|
||||
3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解 Gitee 上的优秀开源项目
|
||||
4. [GVP](https://gitee.com/gvp) 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目
|
||||
5. Gitee 官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help)
|
||||
6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)
|
||||
|
||||
+109
@@ -0,0 +1,109 @@
|
||||
# 图形HALS组件<a name="ZH-CN_TOPIC_0000001124625243"></a>
|
||||
|
||||
- [简介](#section11660541593)
|
||||
- [目录](#section161941989596)
|
||||
- [编译构建](#section137768191623)
|
||||
- [说明](#section1312121216216)
|
||||
- [使用说明](#section129654513264)
|
||||
|
||||
- [相关仓](#section1371113476307)
|
||||
|
||||
## 简介<a name="section11660541593"></a>
|
||||
|
||||
HALS组件中实现了对驱动子系统和平台相关功能的适配封装,包括了FrameBuffer/GFX/SIMD等。
|
||||
|
||||
**图 1** 图形子系统组件间以及与驱动子系统的依赖关系<a name="fig717664212591"></a>
|
||||

|
||||
|
||||
## 目录<a name="section161941989596"></a>
|
||||
|
||||
```
|
||||
/foundation/graphic/utils
|
||||
├── frameworks # 框架代码
|
||||
│ ├── hals # 硬件适配层
|
||||
│ ├── linux # linux平台适配层
|
||||
│ ├── liteos # liteos平台适配层
|
||||
│ └── windows # windows平台适配层
|
||||
├── interfaces # 接口
|
||||
│ ├── innerkits # 模块间接口
|
||||
│ │ └── hals # 硬件适配层接口
|
||||
│ └── kits # 对外接口
|
||||
└── test # 单元测试
|
||||
```
|
||||
|
||||
## 编译构建<a name="section137768191623"></a>
|
||||
|
||||
```
|
||||
# 通过gn编译,在out目录下对应产品的文件夹中生成libgraphic_hals.so
|
||||
hb build lite_graphic_utils
|
||||
```
|
||||
|
||||
## 说明<a name="section1312121216216"></a>
|
||||
|
||||
### 使用说明<a name="section129654513264"></a>
|
||||
|
||||
- 图形UI/SURFACE/WMS组件均使用了HALS组件,可参考相关源码;
|
||||
|
||||
## 相关仓<a name="section1371113476307"></a>
|
||||
|
||||
/hmf/graphic/surface
|
||||
|
||||
/hmf/graphic/wms
|
||||
|
||||
/hmf/graphic/ui
|
||||
|
||||
# 图形UTILS组件<a name="ZH-CN_TOPIC_0000001123083525"></a>
|
||||
|
||||
- [简介](#section11660541593)
|
||||
- [目录](#section161941989596)
|
||||
- [编译构建](#section137768191623)
|
||||
- [说明](#section1312121216216)
|
||||
- [使用说明](#section129654513264)
|
||||
|
||||
- [相关仓](#section1371113476307)
|
||||
|
||||
## 简介<a name="section11660541593"></a>
|
||||
|
||||
UTILS组件中定义了图形子系统中的公共数据结构,并提供了一层轻薄的操作系统适配层(如锁、线程、文件系统)。
|
||||
|
||||
**图 1** 图形子系统组件间依赖关系<a name="fig717664212591"></a>
|
||||

|
||||
|
||||
## 目录<a name="section161941989596"></a>
|
||||
|
||||
```
|
||||
/foundation/graphic/utils
|
||||
├── frameworks # 框架代码
|
||||
│ ├── hals # 硬件适配层
|
||||
│ ├── linux # linux平台适配层
|
||||
│ ├── liteos # liteos平台适配层
|
||||
│ └── windows # windows平台适配层
|
||||
├── interfaces # 接口
|
||||
│ ├── innerkits # 模块间接口
|
||||
│ │ └── hals # 硬件适配层接口
|
||||
│ └── kits # 对外接口
|
||||
└── test # 单元测试
|
||||
```
|
||||
|
||||
## 编译构建<a name="section137768191623"></a>
|
||||
|
||||
```
|
||||
# 通过gn编译,在out目录下对应产品的文件夹中生成libgraphic_utils.so
|
||||
hb build lite_graphic_utils
|
||||
```
|
||||
|
||||
## 说明<a name="section1312121216216"></a>
|
||||
|
||||
### 使用说明<a name="section129654513264"></a>
|
||||
|
||||
- 图形UI/SURFACE/WMS组件均使用了UTILS组件,可参考相关源码;
|
||||
- test提供了UTILS组件各接口的单元测试,也可参考使用。
|
||||
|
||||
## 相关仓<a name="section1371113476307"></a>
|
||||
|
||||
/hmf/graphic/surface
|
||||
|
||||
/hmf/graphic/wms
|
||||
|
||||
/hmf/graphic/ui
|
||||
|
||||
BIN
Binary file not shown.
|
After Width: | Height: | Size: 12 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 8.3 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 12 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 8.3 KiB |
Executable
+63
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "color.h"
|
||||
|
||||
namespace OHOS {
|
||||
uint32_t Color::ColorTo32(ColorType color)
|
||||
{
|
||||
#if COLOR_DEPTH == 16
|
||||
Color32 ret;
|
||||
ret.red = color.red << 3; /* (2^8 - 1)/(2^5 - 1) = 255/31 = 8 */
|
||||
ret.green = color.green << 2; /* (2^8 - 1)/(2^6 - 1) = 255/63 = 4 */
|
||||
ret.blue = color.blue << 3; /* (2^8 - 1)/(2^5 - 1) = 255/31 = 8 */
|
||||
ret.alpha = 0xFF;
|
||||
return ret.full;
|
||||
#elif COLOR_DEPTH == 32
|
||||
return color.full;
|
||||
#endif
|
||||
}
|
||||
|
||||
uint32_t Color::ColorTo32(Color16 color, uint8_t alpha)
|
||||
{
|
||||
Color32 ret;
|
||||
/*
|
||||
* when 16-bitmap image is tansformed to 32-bitmap,
|
||||
* R should shift left 3 bits,
|
||||
* G should shift left 2 bits,
|
||||
* B should shift left 3 bits,
|
||||
*/
|
||||
ret.red = color.red << 3; /* (2^8 - 1)/(2^5 - 1) = 255/31 = 8 */
|
||||
ret.green = color.green << 2; /* (2^8 - 1)/(2^6 - 1) = 255/63 = 4 */
|
||||
ret.blue = color.blue << 3; /* (2^8 - 1)/(2^5 - 1) = 255/31 = 8 */
|
||||
ret.alpha = alpha;
|
||||
return ret.full;
|
||||
}
|
||||
|
||||
uint16_t Color::ColorTo16(Color32 color)
|
||||
{
|
||||
/*
|
||||
* when 32-bitmap image is tansformed to 16-bitmap,
|
||||
* R should shift right 3 bits,
|
||||
* G should shift right 2 bits,
|
||||
* B should shift right 3 bits,
|
||||
*/
|
||||
Color16 rColor;
|
||||
rColor.red = color.red >> 3;
|
||||
rColor.green = color.green >> 2;
|
||||
rColor.blue = color.blue >> 3;
|
||||
return rColor.full;
|
||||
}
|
||||
} // namespace OHOS
|
||||
Executable
+382
@@ -0,0 +1,382 @@
|
||||
/*
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "geometry2d.h"
|
||||
#include "securec.h"
|
||||
|
||||
namespace OHOS {
|
||||
Rect::Rect(int16_t left, int16_t top, int16_t right, int16_t bottom)
|
||||
{
|
||||
left_ = left;
|
||||
right_ = right;
|
||||
top_ = top;
|
||||
bottom_ = bottom;
|
||||
}
|
||||
|
||||
Rect::Rect(const Rect& other)
|
||||
{
|
||||
left_ = other.left_;
|
||||
right_ = other.right_;
|
||||
top_ = other.top_;
|
||||
bottom_ = other.bottom_;
|
||||
}
|
||||
|
||||
Rect::Rect(const Rect&& other)
|
||||
{
|
||||
left_ = other.left_;
|
||||
right_ = other.right_;
|
||||
top_ = other.top_;
|
||||
bottom_ = other.bottom_;
|
||||
}
|
||||
|
||||
void Rect::operator = (const Rect& other)
|
||||
{
|
||||
left_ = other.left_;
|
||||
right_ = other.right_;
|
||||
top_ = other.top_;
|
||||
bottom_ = other.bottom_;
|
||||
}
|
||||
|
||||
void Rect::operator = (const Rect&& other)
|
||||
{
|
||||
left_ = other.left_;
|
||||
right_ = other.right_;
|
||||
top_ = other.top_;
|
||||
bottom_ = other.bottom_;
|
||||
}
|
||||
|
||||
bool Rect::operator == (const Rect& other) const
|
||||
{
|
||||
if (left_ == other.left_ && right_ == other.right_ &&
|
||||
top_ == other.top_ && bottom_ == other.bottom_) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void Rect::SetRect(int16_t left, int16_t top, int16_t right, int16_t bottom)
|
||||
{
|
||||
left_ = left;
|
||||
right_ = right;
|
||||
top_ = top;
|
||||
bottom_ = bottom;
|
||||
}
|
||||
|
||||
uint32_t Rect::GetSize() const
|
||||
{
|
||||
return static_cast<uint32_t>(right_ - left_ + 1) * (bottom_ - top_ + 1);
|
||||
}
|
||||
|
||||
bool Rect::Intersect(const Rect& rect1, const Rect& rect2)
|
||||
{
|
||||
/* Get the smaller area from 'rect1' and 'rect2' */
|
||||
left_ = MATH_MAX(rect1.left_, rect2.left_);
|
||||
top_ = MATH_MAX(rect1.top_, rect2.top_);
|
||||
right_ = MATH_MIN(rect1.right_, rect2.right_);
|
||||
bottom_ = MATH_MIN(rect1.bottom_, rect2.bottom_);
|
||||
if ((left_ > right_) || (top_ > bottom_)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void Rect::Join(const Rect& rect1, const Rect& rect2)
|
||||
{
|
||||
left_ = MATH_MIN(rect1.left_, rect2.left_);
|
||||
top_ = MATH_MIN(rect1.top_, rect2.top_);
|
||||
right_ = MATH_MAX(rect1.right_, rect2.right_);
|
||||
bottom_ = MATH_MAX(rect1.bottom_, rect2.bottom_);
|
||||
}
|
||||
|
||||
bool Rect::IsContains(const Vector2<int16_t>& point) const
|
||||
{
|
||||
bool isContains = false;
|
||||
|
||||
if ((point.x_ >= this->left_) && (point.x_ <= this->right_) &&
|
||||
(point.y_ >= this->top_) && (point.y_ <= this->bottom_)) {
|
||||
isContains = true;
|
||||
}
|
||||
|
||||
return isContains;
|
||||
}
|
||||
|
||||
bool Rect::IsContains(const Point& point) const
|
||||
{
|
||||
bool isContains = false;
|
||||
|
||||
if ((point.x >= this->left_) && (point.x <= this->right_) &&
|
||||
(point.y >= this->top_) && (point.y <= this->bottom_)) {
|
||||
isContains = true;
|
||||
}
|
||||
|
||||
return isContains;
|
||||
}
|
||||
bool Rect::IsIntersect(const Rect& other) const
|
||||
{
|
||||
if ((this->left_ <= other.right_) &&
|
||||
(this->right_ >= other.left_) &&
|
||||
(this->top_ <= other.bottom_) &&
|
||||
(this->bottom_ >= other.top_)) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool Rect::IsContains(const Rect& other) const
|
||||
{
|
||||
bool isContains = false;
|
||||
|
||||
if (other.left_ >= this->left_ &&
|
||||
other.top_ >= this->top_ &&
|
||||
other.right_ <= this->right_ &&
|
||||
other.bottom_ <= this->bottom_) {
|
||||
isContains = true;
|
||||
}
|
||||
|
||||
return isContains;
|
||||
}
|
||||
|
||||
bool Rect::IsExtends(const Rect& other) const
|
||||
{
|
||||
if (left_ == other.left_ && right_ == other.right_) {
|
||||
return (top_ == other.bottom_ + 1) || (bottom_ == other.top_ - 1);
|
||||
}
|
||||
|
||||
if (top_ == other.top_ && bottom_ == other.bottom_) {
|
||||
return (left_ == other.right_ + 1) || (right_ == other.left_ - 1);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/* return point of intersection of two lines when it is sure a and b is intersected */
|
||||
bool Intersect(const Line& a, const Line& b, Vector2<int16_t>& out)
|
||||
{
|
||||
Vector2<int16_t> aA = a[0];
|
||||
Vector2<int16_t> aB = a[1];
|
||||
Vector2<int16_t> bA = b[0];
|
||||
Vector2<int16_t> bB = b[1];
|
||||
int32_t den = static_cast<int32_t>(aA.x_ - aB.x_) * (bA.y_ - bB.y_) -
|
||||
static_cast<int32_t>(aA.y_ - aB.y_) * (bA.x_ - bB.x_);
|
||||
if (den == 0) {
|
||||
return false;
|
||||
}
|
||||
int32_t xNum = (static_cast<int32_t>(aA.x_) * aB.y_ - static_cast<int32_t>(aA.y_) * aB.x_) * (bA.x_ - bB.x_) -
|
||||
(aA.x_ - aB.x_) * (static_cast<int32_t>(bA.x_) * bB.y_ - static_cast<int32_t>(bA.y_) * bB.x_);
|
||||
int32_t yNum = (static_cast<int32_t>(aA.x_) * aB.y_ - static_cast<int32_t>(aA.y_) * aB.x_) * (bA.y_ - bB.y_) -
|
||||
(aA.y_ - aB.y_) * (static_cast<int32_t>(bA.x_) * bB.y_ - static_cast<int32_t>(bA.y_) * bB.x_);
|
||||
out.x_ = xNum / den;
|
||||
out.y_ = yNum / den;
|
||||
return true;
|
||||
}
|
||||
|
||||
/* check two line intersect if intersect return true, else false */
|
||||
bool IsIntersect(const Line& a, const Line& b)
|
||||
{
|
||||
Vector2<int16_t> aA = a[0];
|
||||
Vector2<int16_t> aB = a[1];
|
||||
Vector2<int16_t> bA = b[0];
|
||||
Vector2<int16_t> bB = b[1];
|
||||
|
||||
int32_t iPos = static_cast<int32_t>(aB.x_ - aA.x_) * (bA.y_ - aA.y_) -
|
||||
static_cast<int32_t>(aB.y_ - aA.y_) * (bA.x_ - aA.x_);
|
||||
int32_t kPos = static_cast<int32_t>(aB.x_ - aA.x_) * (bB.y_ - aA.y_) -
|
||||
static_cast<int32_t>(aB.y_ - aA.y_) * (bB.x_ - aA.x_);
|
||||
|
||||
if (static_cast<int64_t>(iPos) * kPos <= 0) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/* This functions clips all the edges w.r.t one clip edge of clipping area */
|
||||
void Clip(Polygon& poly, const Line& line)
|
||||
{
|
||||
uint8_t vertexNum = poly.GetVertexNum();
|
||||
Polygon newPoly;
|
||||
int16_t iX;
|
||||
int16_t iY;
|
||||
int16_t kX;
|
||||
int16_t kY;
|
||||
|
||||
int16_t x1;
|
||||
int16_t y1;
|
||||
int16_t x2;
|
||||
int16_t y2;
|
||||
|
||||
int8_t k;
|
||||
int32_t iPos;
|
||||
int32_t kPos;
|
||||
|
||||
/* (iX, iY), (kX, kY) are the co-ordinate values of the points */
|
||||
for (int8_t i = 0; i < vertexNum; i++) {
|
||||
/* i and k form a line in polygon */
|
||||
k = (i + 1) % vertexNum;
|
||||
iX = poly[i].x_;
|
||||
iY = poly[i].y_;
|
||||
kX = poly[k].x_;
|
||||
kY = poly[k].y_;
|
||||
|
||||
x1 = line[0].x_;
|
||||
y1 = line[0].y_;
|
||||
x2 = line[1].x_;
|
||||
y2 = line[1].y_;
|
||||
|
||||
/* Calculating position of first point w.r.t. clipper line */
|
||||
iPos = static_cast<int32_t>(x2 - x1) * (iY - y1) - static_cast<int32_t>(y2 - y1) * (iX - x1);
|
||||
|
||||
/* Calculating position of second point w.r.t. clipper line */
|
||||
kPos = static_cast<int32_t>(x2 - x1) * (kY - y1) - static_cast<int32_t>(y2 - y1) * (kX - x1);
|
||||
|
||||
uint8_t newVertexNum = newPoly.GetVertexNum();
|
||||
|
||||
if (iPos < 0 && kPos < 0) {
|
||||
/* Case 1 : When both points are inside */
|
||||
newPoly[newVertexNum].x_ = kX;
|
||||
newPoly[newVertexNum].y_ = kY;
|
||||
|
||||
newVertexNum++;
|
||||
} else if (iPos >= 0 && kPos < 0) {
|
||||
/* Case 2: When only first point is outside */
|
||||
Vector2<int16_t> intersectPoint;
|
||||
bool intersect = Intersect(Line(x1, y1, x2, y2), Line(iX, iY, kX, kY), intersectPoint);
|
||||
if (!intersect) {
|
||||
continue;
|
||||
}
|
||||
|
||||
newPoly[newVertexNum].x_ = intersectPoint.x_;
|
||||
newPoly[newVertexNum].y_ = intersectPoint.y_;
|
||||
newVertexNum++;
|
||||
|
||||
newPoly[newVertexNum].x_ = kX;
|
||||
newPoly[newVertexNum].y_ = kY;
|
||||
newVertexNum++;
|
||||
} else if (iPos < 0 && kPos >= 0) {
|
||||
/* Case 3: When only second point is outside Only point of intersection with edge is added */
|
||||
Vector2<int16_t> intersectPoint;
|
||||
bool intersect = Intersect(Line(x1, y1, x2, y2), Line(iX, iY, kX, kY), intersectPoint);
|
||||
if (!intersect) {
|
||||
continue;
|
||||
}
|
||||
|
||||
newPoly[newVertexNum].x_ = intersectPoint.x_;
|
||||
newPoly[newVertexNum].y_ = intersectPoint.y_;
|
||||
newVertexNum++;
|
||||
}
|
||||
newPoly.SetVertexNum(newVertexNum);
|
||||
}
|
||||
|
||||
/* Copying new points into original array and changing the no. of vertices */
|
||||
poly = newPoly;
|
||||
}
|
||||
|
||||
/* Implements Sutherland�CHodgman algorithm for polygon clipping */
|
||||
Polygon SuthHodgClip(const Rect& clipRect, const Polygon& polygon)
|
||||
{
|
||||
Polygon newPolygon(polygon);
|
||||
|
||||
Clip(newPolygon, Line(clipRect.GetLeft(), clipRect.GetTop(), clipRect.GetRight(), clipRect.GetTop()));
|
||||
Clip(newPolygon, Line(clipRect.GetRight(), clipRect.GetTop(), clipRect.GetRight(), clipRect.GetBottom()));
|
||||
Clip(newPolygon, Line(clipRect.GetRight(), clipRect.GetBottom(), clipRect.GetLeft(), clipRect.GetBottom()));
|
||||
Clip(newPolygon, Line(clipRect.GetLeft(), clipRect.GetBottom(), clipRect.GetLeft(), clipRect.GetTop()));
|
||||
return newPolygon;
|
||||
}
|
||||
|
||||
/* the max cross point is two when a line cross a convex polygon */
|
||||
void Clip(const Line& line, const Polygon& poly, Vector2<int16_t>* pOut, uint8_t *pNum)
|
||||
{
|
||||
if (pOut == nullptr || pNum == nullptr) {
|
||||
return;
|
||||
}
|
||||
uint8_t vertexNum = poly.GetVertexNum();
|
||||
int16_t iX;
|
||||
int16_t iY;
|
||||
int16_t kX;
|
||||
int16_t kY;
|
||||
|
||||
int16_t x1;
|
||||
int16_t y1;
|
||||
int16_t x2;
|
||||
int16_t y2;
|
||||
|
||||
int8_t k;
|
||||
int32_t iPos;
|
||||
int32_t kPos;
|
||||
|
||||
/* (iX, iY), (kX, kY) are the co-ordinate values of the points */
|
||||
for (int8_t i = 0; i < vertexNum; i++) {
|
||||
/* i and k form a line in polygon */
|
||||
k = (i + 1) % vertexNum;
|
||||
iX = poly[i].x_;
|
||||
iY = poly[i].y_;
|
||||
kX = poly[k].x_;
|
||||
kY = poly[k].y_;
|
||||
|
||||
x1 = line[0].x_;
|
||||
y1 = line[0].y_;
|
||||
x2 = line[1].x_;
|
||||
y2 = line[1].y_;
|
||||
|
||||
/* Calculating position of first point w.r.t. clipper line */
|
||||
iPos = static_cast<int32_t>(x2 - x1) * (iY - y1) - static_cast<int32_t>(y2 - y1) * (iX - x1);
|
||||
|
||||
/* Calculating position of second point w.r.t. clipper line */
|
||||
kPos = static_cast<int32_t>(x2 - x1) * (kY - y1) - static_cast<int32_t>(y2 - y1) * (kX - x1);
|
||||
|
||||
if ((iPos >= 0 && kPos < 0) || (iPos < 0 && kPos >= 0)) {
|
||||
Vector2<int16_t> intersectPoint;
|
||||
Intersect(Line(x1, y1, x2, y2), Line(iX, iY, kX, kY), intersectPoint);
|
||||
(*pOut) = intersectPoint;
|
||||
(*pNum)++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Polygon::Polygon(const Vector2<int16_t>* vertexes, const uint8_t vertexNum)
|
||||
{
|
||||
ASSERT(vertexNum <= MAX_VERTEX_NUM);
|
||||
if (memcpy_s(vertexes_, MAX_VERTEX_NUM * sizeof(Vector2<int16_t>),
|
||||
vertexes, vertexNum * sizeof(Vector2<int16_t>)) != EOK) {
|
||||
ASSERT(0);
|
||||
}
|
||||
vertexNum_ = vertexNum;
|
||||
}
|
||||
|
||||
Rect Polygon::MakeAABB() const
|
||||
{
|
||||
int16_t minX = vertexes_[0].x_;
|
||||
int16_t maxX = vertexes_[0].x_;
|
||||
int16_t minY = vertexes_[0].y_;
|
||||
int16_t maxY = vertexes_[0].y_;
|
||||
for (uint8_t i = 1; i < vertexNum_; i++) {
|
||||
if (minX > vertexes_[i].x_) {
|
||||
minX = vertexes_[i].x_;
|
||||
}
|
||||
if (maxX < vertexes_[i].x_) {
|
||||
maxX = vertexes_[i].x_;
|
||||
}
|
||||
if (minY > vertexes_[i].y_) {
|
||||
minY = vertexes_[i].y_;
|
||||
}
|
||||
if (maxY < vertexes_[i].y_) {
|
||||
maxY = vertexes_[i].y_;
|
||||
}
|
||||
}
|
||||
return Rect(minX, minY, maxX, maxY);
|
||||
}
|
||||
}
|
||||
Executable
+96
@@ -0,0 +1,96 @@
|
||||
/*
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "graphic_math.h"
|
||||
|
||||
namespace OHOS {
|
||||
static float g_sinValues[] = {
|
||||
0.000000, 0.017452, 0.034899, 0.052336, 0.069756, 0.087156, 0.104528, 0.121869, 0.139173, 0.156434, 0.173648,
|
||||
0.190809, 0.207912, 0.224951, 0.241922, 0.258819, 0.275637, 0.292372, 0.309017, 0.325568, 0.342020, 0.358368,
|
||||
0.374607, 0.390731, 0.406737, 0.422618, 0.438371, 0.453990, 0.469472, 0.484810, 0.500000, 0.515038, 0.529919,
|
||||
0.544639, 0.559193, 0.573576, 0.587785, 0.601815, 0.615661, 0.629320, 0.642788, 0.656059, 0.669131, 0.681998,
|
||||
0.694658, 0.707107, 0.719340, 0.731354, 0.743145, 0.754710, 0.766044, 0.777146, 0.788011, 0.798636, 0.809017,
|
||||
0.819152, 0.829038, 0.838671, 0.848048, 0.857167, 0.866025, 0.874620, 0.882948, 0.891007, 0.898794, 0.906308,
|
||||
0.913545, 0.920505, 0.927184, 0.933580, 0.939693, 0.945519, 0.951057, 0.956305, 0.961262, 0.965926, 0.970296,
|
||||
0.974370, 0.978148, 0.981627, 0.984808, 0.987688, 0.990268, 0.992546, 0.994522, 0.996195, 0.997564, 0.998630,
|
||||
0.999391, 0.999848, 1.000000
|
||||
};
|
||||
|
||||
float Sin(int16_t angle)
|
||||
{
|
||||
angle = angle % CIRCLE_IN_DEGREE;
|
||||
if (angle < 0) {
|
||||
angle = CIRCLE_IN_DEGREE + angle;
|
||||
}
|
||||
|
||||
if (angle <= QUARTER_IN_DEGREE) {
|
||||
return g_sinValues[angle];
|
||||
} else if (angle <= SEMICIRCLE_IN_DEGREE) {
|
||||
return g_sinValues[SEMICIRCLE_IN_DEGREE - angle];
|
||||
} else if (angle <= THREE_QUARTER_IN_DEGREE) {
|
||||
return -g_sinValues[angle - SEMICIRCLE_IN_DEGREE];
|
||||
} else {
|
||||
return -g_sinValues[CIRCLE_IN_DEGREE - angle];
|
||||
}
|
||||
}
|
||||
|
||||
/* arctan(x) = x - p3 * x^3 + p5 * x^5 - p7 * x^7 */
|
||||
uint16_t FastAtan2(int16_t x, int16_t y)
|
||||
{
|
||||
if (x == 0 && y == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int16_t absX = MATH_ABS(x);
|
||||
int16_t absY = MATH_ABS(y);
|
||||
float t;
|
||||
float t2;
|
||||
uint16_t angle;
|
||||
if (absX <= absY) {
|
||||
t = static_cast<float>(absX) / absY;
|
||||
t2 = t * t;
|
||||
angle = static_cast<uint16_t>(t * (1 + t2 * (ATAN2_P3 + t2 * (ATAN2_P5 + t2 * ATAN2_P7))) * RADIAN_TO_ANGLE);
|
||||
} else {
|
||||
t = static_cast<float>(absY) / absX;
|
||||
t2 = t * t;
|
||||
angle = QUARTER_IN_DEGREE -
|
||||
static_cast<uint16_t>(t * (1 + t2 * (ATAN2_P3 + t2 * (ATAN2_P5 + t2 * ATAN2_P7))) * RADIAN_TO_ANGLE);
|
||||
}
|
||||
|
||||
if (y < 0) {
|
||||
if (x < 0) {
|
||||
angle = SEMICIRCLE_IN_DEGREE + angle;
|
||||
} else {
|
||||
angle = SEMICIRCLE_IN_DEGREE - angle;
|
||||
}
|
||||
} else if (x < 0) {
|
||||
angle = CIRCLE_IN_DEGREE - angle;
|
||||
}
|
||||
|
||||
return angle;
|
||||
}
|
||||
|
||||
float Sqrt(float x)
|
||||
{
|
||||
const float xhalf = 0.5f * x;
|
||||
int32_t i = *(int32_t*)&x;
|
||||
i = 0x5f375a86 - (i / 2); // 0x5f375a86 : Initial value of Newton Iterator. 2 : inital parameter for iterator.
|
||||
float y = *(float*)&i;
|
||||
y = y * (1.5f - (xhalf * y * y));
|
||||
y = y * (1.5f - (xhalf * y * y));
|
||||
y = y * (1.5f - (xhalf * y * y));
|
||||
return x * y;
|
||||
}
|
||||
} // namespace OHOS
|
||||
Executable
+53
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "hal_cpu.h"
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#elif defined __LINUX__
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#endif
|
||||
|
||||
uint32_t HalGetCpuCoreNum()
|
||||
{
|
||||
static uint32_t cpuCoreNum = 0;
|
||||
if (cpuCoreNum) {
|
||||
return cpuCoreNum;
|
||||
}
|
||||
#ifdef _WIN32
|
||||
SYSTEM_INFO sysInfo;
|
||||
GetSystemInfo(&sysInfo);
|
||||
cpuCoreNum = sysInfo.dwNumberOfProcessors;
|
||||
#elif defined __LINUX__
|
||||
cpuCoreNum = sysconf(_SC_NPROCESSORS_ONLN);
|
||||
#elif defined HAL_CPU_NUM
|
||||
cpuCoreNum = HAL_CPU_NUM;
|
||||
#else
|
||||
cpuCoreNum = 1;
|
||||
#endif
|
||||
return cpuCoreNum;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cpluscplus */
|
||||
#endif /* __cpluscplus */
|
||||
Executable
+55
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "hal_tick.h"
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#elif defined __linux__ || defined __LITEOS__ || defined __APPLE__
|
||||
#include <ctime>
|
||||
#else
|
||||
#include "los_tick.h"
|
||||
#endif
|
||||
|
||||
namespace OHOS {
|
||||
uint32_t HALTick::GetTime()
|
||||
{
|
||||
#ifdef _WIN32
|
||||
return GetTickCount();
|
||||
#elif defined __linux__ || defined __LITEOS__ || defined __APPLE__
|
||||
struct timespec time;
|
||||
clock_gettime(CLOCK_MONOTONIC, &time);
|
||||
return time.tv_sec * SEC_TO_MILLISEC + time.tv_nsec / MILLISEC_TO_NANOSEC;
|
||||
#else
|
||||
return LOS_TickCountGet();
|
||||
#endif
|
||||
}
|
||||
|
||||
uint32_t HALTick::GetElapseTime(uint32_t startTime)
|
||||
{
|
||||
uint32_t currentTime = GetTime();
|
||||
uint32_t elapseTime;
|
||||
|
||||
if (currentTime > startTime) {
|
||||
elapseTime = currentTime - startTime;
|
||||
} else {
|
||||
elapseTime = (UINT32_MAX - startTime) + currentTime + 1;
|
||||
}
|
||||
|
||||
return elapseTime;
|
||||
}
|
||||
} // namespace OHOS
|
||||
Executable
+158
@@ -0,0 +1,158 @@
|
||||
/*
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "hals/gfx_engines.h"
|
||||
|
||||
#include "graphic_log.h"
|
||||
|
||||
namespace OHOS {
|
||||
struct {
|
||||
ImagePixelFormat srcColorFmt;
|
||||
PixelFormat dstColorFmt;
|
||||
} g_fmtMapTable[] = {
|
||||
{IMAGE_PIXEL_FORMAT_RGB565, PIXEL_FMT_RGB_565},
|
||||
{IMAGE_PIXEL_FORMAT_ARGB1555, PIXEL_FMT_RGBA_5551},
|
||||
{IMAGE_PIXEL_FORMAT_RGB888, PIXEL_FMT_RGB_888},
|
||||
{IMAGE_PIXEL_FORMAT_ARGB8888, PIXEL_FMT_RGBA_8888},
|
||||
};
|
||||
|
||||
static bool ConvertFormat(const ImagePixelFormat& srcColorFmt, PixelFormat& dstColorFmt)
|
||||
{
|
||||
int32_t i;
|
||||
int32_t len = sizeof(g_fmtMapTable) / sizeof(g_fmtMapTable[0]);
|
||||
for (i = 0; i < len; i++) {
|
||||
if (g_fmtMapTable[i].srcColorFmt == srcColorFmt) {
|
||||
dstColorFmt = g_fmtMapTable[i].dstColorFmt;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool Convert2ISurface(const LiteSurfaceData& liteSurfaceData, ISurface& iSurface)
|
||||
{
|
||||
if (ConvertFormat(liteSurfaceData.pixelFormat, iSurface.enColorFmt) == false) {
|
||||
GRAPHIC_LOGE("unsupport color format!");
|
||||
return false;
|
||||
}
|
||||
|
||||
uintptr_t phyAddr = reinterpret_cast<uintptr_t>(liteSurfaceData.phyAddr);
|
||||
iSurface.phyAddr = phyAddr;
|
||||
iSurface.height = liteSurfaceData.height;
|
||||
iSurface.width = liteSurfaceData.width;
|
||||
iSurface.stride = liteSurfaceData.stride;
|
||||
iSurface.clutPhyAddr = 0;
|
||||
iSurface.bYCbCrClut = false;
|
||||
iSurface.bAlphaMax255 = true;
|
||||
iSurface.bAlphaExt1555 = false;
|
||||
iSurface.alpha0 = 0;
|
||||
iSurface.alpha1 = OPA_OPAQUE;
|
||||
return true;
|
||||
}
|
||||
|
||||
static void Convert2IRect(const Rect& rect, IRect& iRect)
|
||||
{
|
||||
iRect.x = rect.GetLeft();
|
||||
iRect.y = rect.GetTop();
|
||||
iRect.w = rect.GetWidth();
|
||||
iRect.h = rect.GetHeight();
|
||||
}
|
||||
|
||||
bool GfxEngines::InitDriver()
|
||||
{
|
||||
if (GfxInitialize(&gfxFuncs_) == DISPLAY_SUCCESS) {
|
||||
if (gfxFuncs_ == nullptr) {
|
||||
GRAPHIC_LOGE("gfxFuncs_ is null!");
|
||||
return false;
|
||||
}
|
||||
if (gfxFuncs_->InitGfx == nullptr) {
|
||||
GRAPHIC_LOGE("InitGfx is null!");
|
||||
return false;
|
||||
}
|
||||
if (gfxFuncs_->InitGfx() != DISPLAY_SUCCESS) {
|
||||
GRAPHIC_LOGE("InitGfx failed!");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void GfxEngines::CloseDriver()
|
||||
{
|
||||
if (gfxFuncs_ == nullptr) {
|
||||
GRAPHIC_LOGE("gfxFuncs_ is null!");
|
||||
return;
|
||||
}
|
||||
if (gfxFuncs_->DeinitGfx != nullptr) {
|
||||
if (gfxFuncs_->DeinitGfx() != DISPLAY_SUCCESS) {
|
||||
GRAPHIC_LOGE("DeinitGfx failed!");
|
||||
}
|
||||
}
|
||||
GfxUninitialize(gfxFuncs_);
|
||||
gfxFuncs_ = nullptr;
|
||||
}
|
||||
|
||||
bool GfxEngines::GfxFillArea(const LiteSurfaceData& dstSurfaceData,
|
||||
const Rect& fillArea,
|
||||
const ColorType& color,
|
||||
const OpacityType& opa)
|
||||
{
|
||||
if (gfxFuncs_ == nullptr || dstSurfaceData.phyAddr == nullptr) {
|
||||
return false;
|
||||
}
|
||||
ISurface surface = {};
|
||||
if (Convert2ISurface(dstSurfaceData, surface) == false) {
|
||||
return false;
|
||||
}
|
||||
IRect rect = {};
|
||||
Convert2IRect(fillArea, rect);
|
||||
GfxOpt opt = {};
|
||||
opt.enGlobalAlpha = true;
|
||||
opt.globalAlpha = opa;
|
||||
if (gfxFuncs_->FillRect(&surface, &rect, color.full, &opt) == DISPLAY_FAILURE) {
|
||||
GRAPHIC_LOGE("fill rect failed!");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool GfxEngines::GfxBlit(const LiteSurfaceData& srcSurfaceData,
|
||||
const Rect& srcRect,
|
||||
const LiteSurfaceData& dstSurfaceData,
|
||||
int16_t x,
|
||||
int16_t y)
|
||||
{
|
||||
if (gfxFuncs_ == nullptr || srcSurfaceData.phyAddr == nullptr || dstSurfaceData.phyAddr == nullptr) {
|
||||
return false;
|
||||
}
|
||||
ISurface srcSurface = {};
|
||||
ISurface dstSurface = {};
|
||||
if (Convert2ISurface(srcSurfaceData, srcSurface) == false) {
|
||||
return false;
|
||||
}
|
||||
if (Convert2ISurface(dstSurfaceData, dstSurface) == false) {
|
||||
return false;
|
||||
}
|
||||
IRect srcIRect = {};
|
||||
Convert2IRect(srcRect, srcIRect);
|
||||
IRect dstIRect = {x, y, srcRect.GetWidth(), srcRect.GetHeight()};
|
||||
if (gfxFuncs_->Blit(&srcSurface, &srcIRect, &dstSurface, &dstIRect, NULL) == DISPLAY_FAILURE) {
|
||||
GRAPHIC_LOGE("blit failed!");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
} // namespace OHOS
|
||||
Executable
+188
@@ -0,0 +1,188 @@
|
||||
/*
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "hals/hi_fbdev.h"
|
||||
|
||||
#include "color.h"
|
||||
#include "display_layer.h"
|
||||
#include "display_type.h"
|
||||
#include "graphic_config.h"
|
||||
#include "graphic_log.h"
|
||||
|
||||
namespace OHOS {
|
||||
struct DisplayDesc {
|
||||
LayerFuncs* layerFuncs;
|
||||
uint32_t devId;
|
||||
uint32_t layerId;
|
||||
LayerBuffer buffer;
|
||||
LayerRotateType rotateType;
|
||||
};
|
||||
|
||||
static LayerInfo g_layerInfo = {};
|
||||
static DisplayDesc g_display = {};
|
||||
constexpr const uint8_t DISPALY_DEV_ID = 0;
|
||||
#ifdef LAYER_PF_ARGB1555
|
||||
constexpr const uint8_t LAYER_BPP = 16;
|
||||
constexpr const PixelFormat HDI_LAYER_PIXEL_FORMAT = PIXEL_FMT_RGBA_5551;
|
||||
constexpr const ImagePixelFormat LAYER_PIXEL_FORMAT = IMAGE_PIXEL_FORMAT_ARGB1555;
|
||||
#elif defined LAYER_PF_ARGB8888
|
||||
constexpr const uint8_t LAYER_BPP = 32;
|
||||
constexpr const PixelFormat HDI_LAYER_PIXEL_FORMAT = PIXEL_FMT_RGBA_8888;
|
||||
constexpr const ImagePixelFormat LAYER_PIXEL_FORMAT = IMAGE_PIXEL_FORMAT_ARGB8888;
|
||||
#endif
|
||||
constexpr const uint8_t BITS_PER_BYTE = 8;
|
||||
static LiteSurfaceData g_devSurfaceData = {};
|
||||
|
||||
void LcdFlush()
|
||||
{
|
||||
if (g_display.layerFuncs->Flush != nullptr) {
|
||||
int32_t ret =
|
||||
g_display.layerFuncs->Flush(g_display.devId, g_display.layerId, &g_display.buffer);
|
||||
if (ret != DISPLAY_SUCCESS) {
|
||||
GRAPHIC_LOGE("flush fail");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
LayerRotateType GetLayerRotateType()
|
||||
{
|
||||
return g_display.rotateType;
|
||||
}
|
||||
|
||||
LiteSurfaceData* GetDevSurfaceData()
|
||||
{
|
||||
return &g_devSurfaceData;
|
||||
}
|
||||
|
||||
static void DisplayInit(void)
|
||||
{
|
||||
int32_t ret = LayerInitialize(&g_display.layerFuncs);
|
||||
if (ret != DISPLAY_SUCCESS || g_display.layerFuncs == nullptr) {
|
||||
GRAPHIC_LOGE("layer initialize failed");
|
||||
return;
|
||||
}
|
||||
if (g_display.layerFuncs->InitDisplay != nullptr) {
|
||||
ret = g_display.layerFuncs->InitDisplay(DISPALY_DEV_ID);
|
||||
if (ret != DISPLAY_SUCCESS) {
|
||||
GRAPHIC_LOGE("InitDisplay fail");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void OpenLayer(void)
|
||||
{
|
||||
if (g_display.layerFuncs->GetDisplayInfo == nullptr) {
|
||||
return;
|
||||
}
|
||||
g_display.devId = DISPALY_DEV_ID;
|
||||
DisplayInfo displayInfo = {};
|
||||
int32_t ret = g_display.layerFuncs->GetDisplayInfo(g_display.devId, &displayInfo);
|
||||
if (ret != DISPLAY_SUCCESS) {
|
||||
GRAPHIC_LOGE("GetDisplayInfo fail");
|
||||
return;
|
||||
}
|
||||
g_display.rotateType = static_cast<LayerRotateType>(displayInfo.rotAngle);
|
||||
g_layerInfo.width = displayInfo.width;
|
||||
g_layerInfo.height = displayInfo.height;
|
||||
g_layerInfo.bpp = LAYER_BPP;
|
||||
g_layerInfo.pixFormat = HDI_LAYER_PIXEL_FORMAT;
|
||||
g_layerInfo.type = LAYER_TYPE_GRAPHIC;
|
||||
if (g_display.layerFuncs->OpenLayer != nullptr) {
|
||||
ret = g_display.layerFuncs->OpenLayer(g_display.devId, &g_layerInfo, &g_display.layerId);
|
||||
if (ret != DISPLAY_SUCCESS) {
|
||||
GRAPHIC_LOGE("OpenLayer fail");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void SetLayerVisible(bool visibled)
|
||||
{
|
||||
if (g_display.layerFuncs->SetLayerVisible != nullptr) {
|
||||
int32_t ret = g_display.layerFuncs->SetLayerVisible(g_display.devId, g_display.layerId, visibled);
|
||||
if (ret != DISPLAY_SUCCESS) {
|
||||
GRAPHIC_LOGE("setLayerVisible fail");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void SetLayerDirtyRegion(void)
|
||||
{
|
||||
IRect rect = {0, 0, g_layerInfo.width, g_layerInfo.height};
|
||||
if (g_display.layerFuncs->SetLayerDirtyRegion != nullptr) {
|
||||
int32_t ret = g_display.layerFuncs->SetLayerDirtyRegion(g_display.devId, g_display.layerId, &rect);
|
||||
if (ret != DISPLAY_SUCCESS) {
|
||||
GRAPHIC_LOGE("setLayerDirtyRegion fail");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void AllocDisplayBuffer(void)
|
||||
{
|
||||
if (g_display.layerFuncs->GetLayerBuffer != nullptr) {
|
||||
int32_t ret =
|
||||
g_display.layerFuncs->GetLayerBuffer(g_display.devId, g_display.layerId, &g_display.buffer);
|
||||
if (ret != DISPLAY_SUCCESS) {
|
||||
GRAPHIC_LOGE("getLayerBuffer fail");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void HiFbdevInit()
|
||||
{
|
||||
DisplayInit();
|
||||
OpenLayer();
|
||||
SetLayerVisible(true);
|
||||
SetLayerDirtyRegion();
|
||||
AllocDisplayBuffer();
|
||||
uintptr_t phyAddr = g_display.buffer.data.phyAddr;
|
||||
g_devSurfaceData.phyAddr = reinterpret_cast<uint8_t*>(phyAddr);
|
||||
g_devSurfaceData.pixelFormat = LAYER_PIXEL_FORMAT;
|
||||
g_devSurfaceData.width = g_layerInfo.width;
|
||||
g_devSurfaceData.height = g_layerInfo.height;
|
||||
g_devSurfaceData.stride = g_display.buffer.pitch;
|
||||
g_devSurfaceData.virAddr = static_cast<uint8_t*>(g_display.buffer.data.virAddr);
|
||||
g_devSurfaceData.bytePerPixel = g_layerInfo.bpp / BITS_PER_BYTE;
|
||||
}
|
||||
|
||||
void HiFbdevClose()
|
||||
{
|
||||
if (g_display.layerFuncs->CloseLayer == nullptr) {
|
||||
return;
|
||||
}
|
||||
if (g_display.layerFuncs->DeinitDisplay == nullptr) {
|
||||
return;
|
||||
}
|
||||
int32_t ret = g_display.layerFuncs->CloseLayer(g_display.devId, g_display.layerId);
|
||||
if (ret != DISPLAY_SUCCESS) {
|
||||
GRAPHIC_LOGE("CloseLayer fail");
|
||||
return;
|
||||
}
|
||||
ret = g_display.layerFuncs->DeinitDisplay(g_display.devId);
|
||||
if (ret != DISPLAY_SUCCESS) {
|
||||
GRAPHIC_LOGE("DeinitDisplay fail");
|
||||
return;
|
||||
}
|
||||
ret = LayerUninitialize(g_display.layerFuncs);
|
||||
if (ret != DISPLAY_SUCCESS) {
|
||||
GRAPHIC_LOGE("LayerUninitialize fail");
|
||||
}
|
||||
}
|
||||
} // namespace OHOS
|
||||
Executable
+43
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "mem_api.h"
|
||||
namespace OHOS {
|
||||
#ifndef IMG_CACHE_MEMORY_CUSTOM
|
||||
void* ImageCacheMalloc(ImageInfo& info)
|
||||
{
|
||||
return malloc(info.dataSize);
|
||||
}
|
||||
|
||||
void ImageCacheFree(ImageInfo& info)
|
||||
{
|
||||
uint8_t* buf = const_cast<uint8_t*>(info.data);
|
||||
free(buf);
|
||||
info.data = nullptr;
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !ENABLE_MEMORY_HOOKS
|
||||
void* UIMalloc(uint32_t size)
|
||||
{
|
||||
return malloc(size);
|
||||
}
|
||||
void UIFree(void* buffer)
|
||||
{
|
||||
free(buffer);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
Executable
+76
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "pixel_format_utils.h"
|
||||
|
||||
namespace OHOS {
|
||||
static struct {
|
||||
ImagePixelFormat pixelFormat;
|
||||
int16_t bpp;
|
||||
} g_mapBpp[] = {
|
||||
{IMAGE_PIXEL_FORMAT_RGB565, 2},
|
||||
{IMAGE_PIXEL_FORMAT_ARGB1555, 2},
|
||||
{IMAGE_PIXEL_FORMAT_RGB888, 3},
|
||||
{IMAGE_PIXEL_FORMAT_ARGB8888, 4},
|
||||
};
|
||||
|
||||
bool PixelFormatUtils::BppOfPixelFormat(ImagePixelFormat pixelFormat, int16_t& bpp)
|
||||
{
|
||||
int16_t len = sizeof(g_mapBpp) / sizeof(g_mapBpp[0]);
|
||||
for (int16_t i = 0; i < len; i++) {
|
||||
if (pixelFormat == g_mapBpp[i].pixelFormat) {
|
||||
bpp = g_mapBpp[i].bpp;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
uint16_t PixelFormatUtils::ARGB8888ToARGB1555(uint32_t color)
|
||||
{
|
||||
PF_ARGB1555 ret;
|
||||
PF_ARGB8888 in;
|
||||
in.full = color;
|
||||
ret.alpha = in.alpha ? 1 : 0;
|
||||
/*
|
||||
* when 32-bitmap image is tansformed to 16-bitmap
|
||||
* R should shift right 3 bits
|
||||
* G should shift right 3 bits
|
||||
* B should shift right 3 bits
|
||||
*/
|
||||
ret.red = in.red >> 3;
|
||||
ret.green = in.green >> 3;
|
||||
ret.blue = in.blue >> 3;
|
||||
return ret.full;
|
||||
}
|
||||
|
||||
uint32_t PixelFormatUtils::ARGB1555ToARGB8888(uint16_t color)
|
||||
{
|
||||
PF_ARGB8888 ret;
|
||||
PF_ARGB1555 in;
|
||||
in.full = color;
|
||||
ret.alpha = in.alpha ? 0xFF : 0x0;
|
||||
/*
|
||||
* when 16-bitmap image is tansformed to 32-bitmap
|
||||
* R should shift left 3 bits
|
||||
* G should shift left 3 bits
|
||||
* B should shift left 3 bits
|
||||
*/
|
||||
ret.red = in.red << 3;
|
||||
ret.green = in.green << 3;
|
||||
ret.blue = in.blue << 3;
|
||||
return ret.full;
|
||||
}
|
||||
}
|
||||
Executable
+91
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "queue.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define IS_POWER_OF_2(x) ((((x) - 1) & (x)) == 0)
|
||||
#define QUEUE_HEADER_MAGIC 0xccddddcc
|
||||
#define QUEUE_SIZE_MAX 8192
|
||||
#define CACHE_LINE_SIZE 64
|
||||
|
||||
int32_t QueueInit(LockFreeQueue* queue, uint32_t unitNum)
|
||||
{
|
||||
if (queue == NULL) {
|
||||
return QUEUE_INVAL;
|
||||
}
|
||||
if (!IS_POWER_OF_2(unitNum)) {
|
||||
return QUEUE_INVAL;
|
||||
}
|
||||
|
||||
(void)memset_s(queue, sizeof(LockFreeQueue), 0, sizeof(LockFreeQueue));
|
||||
|
||||
queue->magic = QUEUE_HEADER_MAGIC;
|
||||
queue->producer.size = unitNum;
|
||||
queue->consumer.size = unitNum;
|
||||
queue->producer.mask = unitNum - 1;
|
||||
queue->consumer.mask = unitNum - 1;
|
||||
queue->producer.head = 0;
|
||||
queue->consumer.head = 0;
|
||||
queue->producer.tail = 0;
|
||||
queue->consumer.tail = 0;
|
||||
queue->unitNum = unitNum;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t QueueSizeCalc(uint32_t unitNum, uint32_t* queueSize)
|
||||
{
|
||||
uint32_t size;
|
||||
|
||||
if (queueSize == NULL) {
|
||||
return QUEUE_INVAL;
|
||||
}
|
||||
if (unitNum > QUEUE_SIZE_MAX) {
|
||||
return QUEUE_INVAL;
|
||||
}
|
||||
|
||||
size = sizeof(uintptr_t) * unitNum + sizeof(LockFreeQueue);
|
||||
*queueSize = ((size + CACHE_LINE_SIZE - 1) & (~(CACHE_LINE_SIZE - 1)));
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t QueueCountGet(const LockFreeQueue* queue, uint32_t* count)
|
||||
{
|
||||
uint32_t producerTail;
|
||||
uint32_t consumerTail;
|
||||
uint32_t mask;
|
||||
|
||||
if (queue == NULL || count == NULL) {
|
||||
return QUEUE_INVAL;
|
||||
}
|
||||
producerTail = queue->producer.tail;
|
||||
consumerTail = queue->consumer.tail;
|
||||
mask = queue->producer.mask;
|
||||
|
||||
*count = ((producerTail - consumerTail) & mask);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cpluscplus */
|
||||
#endif /* __cpluscplus */
|
||||
Executable
+286
@@ -0,0 +1,286 @@
|
||||
/*
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "style.h"
|
||||
|
||||
namespace OHOS {
|
||||
Style StyleDefault::defaultStyle_;
|
||||
Style StyleDefault::brightStyle_;
|
||||
Style StyleDefault::brightColorStyle_;
|
||||
Style StyleDefault::buttonReleasedStyle_;
|
||||
Style StyleDefault::buttonPressedStyle_;
|
||||
Style StyleDefault::buttonInactiveStyle_;
|
||||
Style StyleDefault::labelStyle_;
|
||||
Style StyleDefault::backgroundTransparentStyle_;
|
||||
Style StyleDefault::progressBackgroundStyle_;
|
||||
Style StyleDefault::progressForegroundStyle_;
|
||||
Style StyleDefault::sliderKnobStyle_;
|
||||
Style StyleDefault::pickerBackgroundStyle_;
|
||||
Style StyleDefault::pickerHighlightStyle_;
|
||||
|
||||
Style::Style()
|
||||
: bgColor_(Color::Black()),
|
||||
bgOpa_(OPA_OPAQUE),
|
||||
borderOpa_(OPA_OPAQUE),
|
||||
borderWidth_(0),
|
||||
borderRadius_(0),
|
||||
borderColor_(Color::Black()),
|
||||
paddingLeft_(0),
|
||||
paddingRight_(0),
|
||||
paddingTop_(0),
|
||||
paddingBottom_(0),
|
||||
marginLeft_(0),
|
||||
marginRight_(0),
|
||||
marginTop_(0),
|
||||
marginBottom_(0),
|
||||
imageOpa_(OPA_OPAQUE),
|
||||
textOpa_(OPA_OPAQUE),
|
||||
font_(16), // 16 : default font size
|
||||
letterSpace_(0),
|
||||
lineSpace_(2), // 2 : default line space
|
||||
textColor_(Color::White()),
|
||||
lineColor_(Color::GetColorFromRGB(0x20, 0x20, 0x20)),
|
||||
lineOpa_(OPA_OPAQUE),
|
||||
lineCap_(CapType::CAP_NONE),
|
||||
lineWidth_(2) // 2 : default line width
|
||||
{
|
||||
}
|
||||
|
||||
int64_t Style::GetStyle(uint8_t key) const
|
||||
{
|
||||
switch (key) {
|
||||
case STYLE_BACKGROUND_COLOR:
|
||||
return bgColor_.full;
|
||||
case STYLE_BACKGROUND_OPA:
|
||||
return bgOpa_;
|
||||
case STYLE_BORDER_RADIUS:
|
||||
return borderRadius_;
|
||||
case STYLE_BORDER_COLOR:
|
||||
return borderColor_.full;
|
||||
case STYLE_BORDER_OPA:
|
||||
return borderOpa_;
|
||||
case STYLE_BORDER_WIDTH:
|
||||
return borderWidth_;
|
||||
case STYLE_PADDING_LEFT:
|
||||
return paddingLeft_;
|
||||
case STYLE_PADDING_RIGHT:
|
||||
return paddingRight_;
|
||||
case STYLE_PADDING_TOP:
|
||||
return paddingTop_;
|
||||
case STYLE_PADDING_BOTTOM:
|
||||
return paddingBottom_;
|
||||
case STYLE_MARGIN_LEFT:
|
||||
return marginLeft_;
|
||||
case STYLE_MARGIN_RIGHT:
|
||||
return marginRight_;
|
||||
case STYLE_MARGIN_TOP:
|
||||
return marginTop_;
|
||||
case STYLE_MARGIN_BOTTOM:
|
||||
return marginBottom_;
|
||||
case STYLE_IMAGE_OPA:
|
||||
return imageOpa_;
|
||||
case STYLE_TEXT_COLOR:
|
||||
return textColor_.full;
|
||||
case STYLE_TEXT_FONT:
|
||||
return font_;
|
||||
case STYLE_LETTER_SPACE:
|
||||
return letterSpace_;
|
||||
case STYLE_LINE_SPACE:
|
||||
return lineSpace_;
|
||||
case STYLE_TEXT_OPA:
|
||||
return textOpa_;
|
||||
case STYLE_LINE_COLOR:
|
||||
return lineColor_.full;
|
||||
case STYLE_LINE_WIDTH:
|
||||
return lineWidth_;
|
||||
case STYLE_LINE_OPA:
|
||||
return lineOpa_;
|
||||
case STYLE_LINE_CAP:
|
||||
return lineCap_;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
void Style::SetStyle(uint8_t key, int64_t value)
|
||||
{
|
||||
switch (key) {
|
||||
case STYLE_BACKGROUND_COLOR:
|
||||
bgColor_.full = value;
|
||||
break;
|
||||
case STYLE_BACKGROUND_OPA:
|
||||
bgOpa_ = value;
|
||||
break;
|
||||
case STYLE_BORDER_RADIUS:
|
||||
borderRadius_ = value;
|
||||
break;
|
||||
case STYLE_BORDER_COLOR:
|
||||
borderColor_.full = value;
|
||||
break;
|
||||
case STYLE_BORDER_OPA:
|
||||
borderOpa_ = value;
|
||||
break;
|
||||
case STYLE_BORDER_WIDTH:
|
||||
borderWidth_ = value;
|
||||
break;
|
||||
case STYLE_PADDING_LEFT:
|
||||
paddingLeft_ = value;
|
||||
break;
|
||||
case STYLE_PADDING_RIGHT:
|
||||
paddingRight_ = value;
|
||||
break;
|
||||
case STYLE_PADDING_TOP:
|
||||
paddingTop_ = value;
|
||||
break;
|
||||
case STYLE_PADDING_BOTTOM:
|
||||
paddingBottom_ = value;
|
||||
break;
|
||||
case STYLE_MARGIN_LEFT:
|
||||
marginLeft_ = value;
|
||||
break;
|
||||
case STYLE_MARGIN_RIGHT:
|
||||
marginRight_ = value;
|
||||
break;
|
||||
case STYLE_MARGIN_TOP:
|
||||
marginTop_ = value;
|
||||
break;
|
||||
case STYLE_MARGIN_BOTTOM:
|
||||
marginBottom_ = value;
|
||||
break;
|
||||
case STYLE_IMAGE_OPA:
|
||||
imageOpa_ = value;
|
||||
break;
|
||||
case STYLE_TEXT_COLOR:
|
||||
textColor_.full = value;
|
||||
break;
|
||||
case STYLE_TEXT_FONT:
|
||||
font_ = value;
|
||||
break;
|
||||
case STYLE_LETTER_SPACE:
|
||||
letterSpace_ = value;
|
||||
break;
|
||||
case STYLE_LINE_SPACE:
|
||||
lineSpace_ = value;
|
||||
break;
|
||||
case STYLE_TEXT_OPA:
|
||||
textOpa_ = value;
|
||||
break;
|
||||
case STYLE_LINE_COLOR:
|
||||
lineColor_.full = value;
|
||||
break;
|
||||
case STYLE_LINE_WIDTH:
|
||||
lineWidth_ = value;
|
||||
break;
|
||||
case STYLE_LINE_OPA:
|
||||
lineOpa_ = value;
|
||||
break;
|
||||
case STYLE_LINE_CAP:
|
||||
lineCap_ = value;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void StyleDefault::Init()
|
||||
{
|
||||
InitStyle();
|
||||
InitButtonStyle();
|
||||
InitLabelStyle();
|
||||
InitBackgroundTransparentStyle();
|
||||
InitProgressStyle();
|
||||
InitPickerStyle();
|
||||
}
|
||||
|
||||
void StyleDefault::InitStyle()
|
||||
{
|
||||
brightStyle_ = defaultStyle_;
|
||||
brightStyle_.SetStyle(STYLE_BACKGROUND_COLOR, Color::White().full);
|
||||
brightStyle_.SetStyle(STYLE_BORDER_RADIUS, 3); // 3: rect radius
|
||||
brightStyle_.SetStyle(STYLE_BORDER_COLOR, Color::GetColorFromRGB(0x40, 0x40, 0x40).full);
|
||||
brightStyle_.SetStyle(STYLE_BORDER_WIDTH, 3); // 3: rect border width
|
||||
brightStyle_.SetStyle(STYLE_BORDER_OPA, 76); // 76: default opa
|
||||
brightStyle_.SetStyle(STYLE_TEXT_COLOR, Color::GetColorFromRGB(0x20, 0x20, 0x20).full);
|
||||
brightStyle_.SetStyle(STYLE_LINE_COLOR, Color::GetColorFromRGB(0x20, 0x20, 0x20).full);
|
||||
|
||||
brightColorStyle_ = brightStyle_;
|
||||
brightColorStyle_.SetStyle(STYLE_TEXT_COLOR, Color::GetColorFromRGB(0xe0, 0xe0, 0xe0).full);
|
||||
brightColorStyle_.SetStyle(STYLE_LINE_COLOR, Color::GetColorFromRGB(0xc0, 0xc0, 0xc0).full);
|
||||
brightColorStyle_.SetStyle(STYLE_BACKGROUND_COLOR, Color::GetColorFromRGB(0x6b, 0x9a, 0xc7).full);
|
||||
brightColorStyle_.SetStyle(STYLE_BORDER_COLOR, Color::GetColorFromRGB(0x15, 0x2c, 0x42).full);
|
||||
}
|
||||
|
||||
void StyleDefault::InitButtonStyle()
|
||||
{
|
||||
/* Button released style */
|
||||
buttonReleasedStyle_ = defaultStyle_;
|
||||
buttonReleasedStyle_.SetStyle(STYLE_BACKGROUND_COLOR, Color::GetColorFromRGB(0x00, 0x7d, 0xff).full);
|
||||
buttonReleasedStyle_.SetStyle(STYLE_BORDER_RADIUS, 200); // 200: button radius
|
||||
buttonReleasedStyle_.SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE);
|
||||
|
||||
buttonReleasedStyle_.SetStyle(STYLE_BORDER_COLOR, Color::GetColorFromRGB(0x0b, 0x19, 0x28).full);
|
||||
buttonReleasedStyle_.SetStyle(STYLE_BORDER_WIDTH, 0);
|
||||
buttonReleasedStyle_.SetStyle(STYLE_BORDER_OPA, 178); // 178: default opa
|
||||
|
||||
/* Button pressed style */
|
||||
buttonPressedStyle_ = buttonReleasedStyle_;
|
||||
buttonPressedStyle_.SetStyle(STYLE_BACKGROUND_COLOR, Color::GetColorFromRGB(0x19, 0x96, 0xff).full);
|
||||
buttonPressedStyle_.SetStyle(STYLE_BORDER_COLOR, Color::GetColorFromRGB(0x0b, 0x19, 0x28).full);
|
||||
|
||||
/* Button inactive style */
|
||||
buttonInactiveStyle_ = buttonReleasedStyle_;
|
||||
buttonInactiveStyle_.SetStyle(STYLE_BACKGROUND_COLOR, Color::GetColorFromRGB(0x61, 0x7e, 0x9d).full);
|
||||
buttonInactiveStyle_.SetStyle(STYLE_BORDER_COLOR, Color::GetColorFromRGB(0x90, 0x90, 0x90).full);
|
||||
}
|
||||
|
||||
void StyleDefault::InitLabelStyle()
|
||||
{
|
||||
labelStyle_ = defaultStyle_;
|
||||
labelStyle_.SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT);
|
||||
}
|
||||
|
||||
void StyleDefault::InitBackgroundTransparentStyle()
|
||||
{
|
||||
backgroundTransparentStyle_ = defaultStyle_;
|
||||
backgroundTransparentStyle_.SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT);
|
||||
}
|
||||
|
||||
void StyleDefault::InitPickerStyle()
|
||||
{
|
||||
pickerBackgroundStyle_ = defaultStyle_;
|
||||
pickerBackgroundStyle_.SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT);
|
||||
pickerBackgroundStyle_.SetStyle(STYLE_TEXT_COLOR, Color::Gray().full);
|
||||
|
||||
pickerHighlightStyle_ = defaultStyle_;
|
||||
pickerHighlightStyle_.SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT);
|
||||
pickerHighlightStyle_.SetStyle(STYLE_TEXT_FONT, 18); // 18: font value
|
||||
pickerHighlightStyle_.SetStyle(STYLE_TEXT_COLOR, Color::GetColorFromRGB(0x45, 0xa5, 0xff).full);
|
||||
}
|
||||
|
||||
void StyleDefault::InitProgressStyle()
|
||||
{
|
||||
progressBackgroundStyle_ = defaultStyle_;
|
||||
progressBackgroundStyle_.SetStyle(STYLE_BORDER_WIDTH, 0);
|
||||
progressBackgroundStyle_.SetStyle(STYLE_BORDER_RADIUS, 0);
|
||||
|
||||
progressForegroundStyle_ = brightStyle_;
|
||||
progressForegroundStyle_.SetStyle(STYLE_BORDER_WIDTH, 0);
|
||||
progressForegroundStyle_.SetStyle(STYLE_BORDER_RADIUS, 0);
|
||||
progressForegroundStyle_.SetStyle(STYLE_LINE_COLOR, Color::GetColorFromRGB(0x45, 0xa5, 0xff).full);
|
||||
|
||||
sliderKnobStyle_ = brightColorStyle_;
|
||||
sliderKnobStyle_.SetStyle(STYLE_BORDER_WIDTH, 0);
|
||||
}
|
||||
} // namespace OHOS
|
||||
Executable
+29
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "sys_info.h"
|
||||
#include "core/render_manager.h"
|
||||
|
||||
namespace OHOS {
|
||||
float SysInfo::GetFPS()
|
||||
{
|
||||
return RenderManager::GetInstance().GetFPS();
|
||||
}
|
||||
|
||||
void SysInfo::RegisterFPSChangedListener(OnFPSChangedListener* onFPSChangedListener)
|
||||
{
|
||||
RenderManager::GetInstance().RegisterFPSChangedListener(onFPSChangedListener);
|
||||
}
|
||||
}
|
||||
Executable
+234
@@ -0,0 +1,234 @@
|
||||
/*
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "transform.h"
|
||||
#include "graphic_math.h"
|
||||
namespace OHOS {
|
||||
constexpr uint8_t VERTEX_NUM_MIN = 3;
|
||||
|
||||
TransformMap::TransformMap()
|
||||
: angle_(0),
|
||||
isInvalid_(false),
|
||||
scaleCoeff_({1.0f, 1.0f}),
|
||||
scalePivot_({0, 0}),
|
||||
rotatePivot_({0, 0}),
|
||||
rect_{0, 0, 0, 0},
|
||||
polygon_(Rect(0, 0, 0, 0))
|
||||
{
|
||||
scale_ = Matrix3<float>::Scale(Vector2<float>(1.0f, 1.0f), Vector2<float>(0, 0));
|
||||
rotate_ = Matrix3<float>::Rotate(0, Vector2<float>(0, 0));
|
||||
translate_ = Matrix3<float>::Translate(Vector2<float>(0, 0));
|
||||
trans_[ROTATE] = &rotate_;
|
||||
trans_[SCALE] = &scale_;
|
||||
trans_[TRANSLATE] = &translate_;
|
||||
opOrder_[ROTATE] = ROTATE;
|
||||
opOrder_[SCALE] = SCALE;
|
||||
opOrder_[TRANSLATE] = TRANSLATE;
|
||||
|
||||
UpdateMap();
|
||||
}
|
||||
|
||||
TransformMap::TransformMap(const Rect& rect)
|
||||
: angle_(0), isInvalid_(false), scaleCoeff_({1.0f, 1.0f}), scalePivot_({0, 0}), rotatePivot_({0, 0})
|
||||
{
|
||||
scale_ = Matrix3<float>::Scale(Vector2<float>(1.0f, 1.0f), Vector2<float>(0, 0));
|
||||
rotate_ = Matrix3<float>::Rotate(0, Vector2<float>(0, 0));
|
||||
translate_ = Matrix3<float>::Translate(Vector2<float>(0, 0));
|
||||
trans_[ROTATE] = &rotate_;
|
||||
trans_[SCALE] = &scale_;
|
||||
trans_[TRANSLATE] = &translate_;
|
||||
opOrder_[ROTATE] = ROTATE;
|
||||
opOrder_[SCALE] = SCALE;
|
||||
opOrder_[TRANSLATE] = TRANSLATE;
|
||||
rect_ = rect;
|
||||
polygon_ = rect;
|
||||
UpdateMap();
|
||||
}
|
||||
|
||||
bool TransformMap::GetClockWise() const
|
||||
{
|
||||
int16_t count = 0;
|
||||
int32_t c;
|
||||
|
||||
uint8_t vertexNum = polygon_.GetVertexNum();
|
||||
if (vertexNum < VERTEX_NUM_MIN) {
|
||||
return false;
|
||||
}
|
||||
|
||||
uint8_t i = 0;
|
||||
uint8_t j;
|
||||
uint8_t k;
|
||||
for (; i < vertexNum; i++) {
|
||||
j = (i + 1) % vertexNum; // 1: the next vertex
|
||||
k = (i + 2) % vertexNum; // 2: the after next vertex
|
||||
c = (static_cast<int32_t>(polygon_[j].x_ - polygon_[i].x_) * (polygon_[k].y_ - polygon_[j].y_)) -
|
||||
(static_cast<int32_t>(polygon_[j].y_ - polygon_[i].y_) * (polygon_[k].x_ - polygon_[j].x_));
|
||||
if (c < 0) {
|
||||
count--;
|
||||
} else if (c > 0) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
if (count > 0) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void TransformMap::SetTransMapRect(const Rect& rect)
|
||||
{
|
||||
rect_ = rect;
|
||||
polygon_ = rect;
|
||||
UpdateMap();
|
||||
}
|
||||
|
||||
void TransformMap::Scale(const Vector2<float> scale, const Vector2<float>& pivot)
|
||||
{
|
||||
scaleCoeff_ = scale;
|
||||
scalePivot_ = pivot;
|
||||
AddOp(SCALE);
|
||||
UpdateMap();
|
||||
}
|
||||
|
||||
bool TransformMap::IsInvalid() const
|
||||
{
|
||||
if (isInvalid_) {
|
||||
return true;
|
||||
}
|
||||
if (angle_ % CIRCLE_IN_DEGREE == 0 && scaleCoeff_.x_ == 1 && scaleCoeff_.y_ == 1) {
|
||||
return true;
|
||||
}
|
||||
for (uint8_t i = 0; i < polygon_.GetVertexNum(); i++) {
|
||||
if (polygon_[i].x_ != 0 || polygon_[i].y_ != 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void TransformMap::Rotate(int16_t angle, const Vector2<float>& pivot)
|
||||
{
|
||||
angle_ = angle;
|
||||
rotatePivot_ = pivot;
|
||||
AddOp(ROTATE);
|
||||
UpdateMap();
|
||||
}
|
||||
|
||||
void TransformMap::Translate(const Vector2<int16_t>& trans)
|
||||
{
|
||||
translate_ = Matrix3<float>::Translate(Vector2<float>(trans.x_, trans.y_));
|
||||
AddOp(TRANSLATE);
|
||||
UpdateMap();
|
||||
}
|
||||
|
||||
bool TransformMap::operator==(const TransformMap& other) const
|
||||
{
|
||||
if (rotate_ == other.rotate_ && translate_ == other.translate_ && scale_ == other.scale_ && rect_ == other.rect_) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void TransformMap::UpdateMap()
|
||||
{
|
||||
trans_[ROTATE] = &rotate_;
|
||||
trans_[SCALE] = &scale_;
|
||||
trans_[TRANSLATE] = &translate_;
|
||||
polygon_ = rect_;
|
||||
rotate_ =
|
||||
Matrix3<float>::Rotate(angle_, Vector2<float>(rotatePivot_.x_ + rect_.GetX(), rotatePivot_.y_ + rect_.GetY()));
|
||||
scale_ = Matrix3<float>::Scale(scaleCoeff_,
|
||||
Vector2<float>(scalePivot_.x_ + rect_.GetX(), scalePivot_.y_ + rect_.GetY()));
|
||||
|
||||
matrix_ = (*trans_[opOrder_[TRANSLATE]]) * (*trans_[opOrder_[SCALE]]) * (*trans_[opOrder_[ROTATE]]);
|
||||
uint8_t vertexNum = polygon_.GetVertexNum();
|
||||
Vector3<float> imgPoint3;
|
||||
for (uint8_t i = 0; i < vertexNum; i++) {
|
||||
Vector3<float> point(polygon_[i].x_, polygon_[i].y_, 1);
|
||||
imgPoint3 = matrix_ * point;
|
||||
if (imgPoint3.x_ < COORD_MIN) {
|
||||
polygon_[i].x_ = COORD_MIN;
|
||||
} else if (imgPoint3.x_ > COORD_MAX) {
|
||||
polygon_[i].x_ = COORD_MAX;
|
||||
} else {
|
||||
polygon_[i].x_ = imgPoint3.x_;
|
||||
}
|
||||
|
||||
if (imgPoint3.y_ < COORD_MIN) {
|
||||
polygon_[i].y_ = COORD_MIN;
|
||||
} else if (imgPoint3.y_ > COORD_MAX) {
|
||||
polygon_[i].y_ = COORD_MAX;
|
||||
} else {
|
||||
polygon_[i].y_ = imgPoint3.y_;
|
||||
}
|
||||
}
|
||||
Matrix3<float> translate = Matrix3<float>::Translate(Vector2<float>(rect_.GetX(), rect_.GetY()));
|
||||
matrix_ = matrix_ * translate;
|
||||
invMatrix_ = matrix_.Inverse();
|
||||
}
|
||||
|
||||
void TransformMap::AddOp(uint8_t op)
|
||||
{
|
||||
if (opOrder_[TRANSLATE] == op) {
|
||||
return;
|
||||
} else if (opOrder_[SCALE] == op) {
|
||||
opOrder_[SCALE] = opOrder_[TRANSLATE];
|
||||
opOrder_[TRANSLATE] = op;
|
||||
} else {
|
||||
opOrder_[ROTATE] = opOrder_[SCALE];
|
||||
opOrder_[SCALE] = opOrder_[TRANSLATE];
|
||||
opOrder_[TRANSLATE] = op;
|
||||
}
|
||||
}
|
||||
|
||||
void Rotate(const Vector2<int16_t>& point, int16_t angle, const Vector2<int16_t>& pivot, Vector2<int16_t>& out)
|
||||
{
|
||||
float sinma = Sin(angle);
|
||||
float cosma = Sin(angle + 90); // 90: cos
|
||||
|
||||
int16_t xt = point.x_ - pivot.x_;
|
||||
int16_t yt = point.y_ - pivot.y_;
|
||||
|
||||
/* 0.5: round up */
|
||||
float temp = cosma * xt - sinma * yt;
|
||||
out.x_ = static_cast<int16_t>((temp > 0) ? (temp + 0.5f) : (temp - 0.5f)) + pivot.x_;
|
||||
temp = sinma * xt + cosma * yt;
|
||||
out.y_ = static_cast<int16_t>((temp > 0) ? (temp + 0.5f) : (temp - 0.5f)) + pivot.y_;
|
||||
}
|
||||
|
||||
void Rotate(const Line& origLine, int16_t angle, const Vector2<int16_t>& pivot, Line& out)
|
||||
{
|
||||
Vector2<int16_t> pt1 = origLine[0];
|
||||
Vector2<int16_t> pt2 = origLine[1];
|
||||
|
||||
Rotate(pt1, angle, pivot, out[1]); // 1: the first point of line
|
||||
Rotate(pt2, angle, pivot, out[2]); // 2: the second point of line
|
||||
}
|
||||
|
||||
void Rotate(const Rect& origRect, int16_t angle, const Vector2<int16_t>& pivot, Polygon& out)
|
||||
{
|
||||
Vector2<int16_t> pt1 = {origRect.GetLeft(), origRect.GetTop()};
|
||||
Vector2<int16_t> pt2 = {origRect.GetRight(), origRect.GetTop()};
|
||||
Vector2<int16_t> pt3 = {origRect.GetRight(), origRect.GetBottom()};
|
||||
Vector2<int16_t> pt4 = {origRect.GetLeft(), origRect.GetBottom()};
|
||||
|
||||
Rotate(pt1, angle, pivot, out[1]); // 1: the first point
|
||||
Rotate(pt2, angle, pivot, out[2]); // 2: the second point
|
||||
Rotate(pt3, angle, pivot, out[3]); // 3: the third point
|
||||
Rotate(pt4, angle, pivot, out[4]); // 4: the fourth point
|
||||
|
||||
out.SetVertexNum(4); // 4: number of vertex
|
||||
}
|
||||
} // namespace OHOS
|
||||
Executable
+31
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "version.h"
|
||||
|
||||
namespace OHOS {
|
||||
constexpr char LIB_DSC[] = "OHOS lite graphic lib";
|
||||
constexpr char LIB_VERSION[] = "1.0.17";
|
||||
|
||||
std::string GetVersion()
|
||||
{
|
||||
return LIB_VERSION;
|
||||
}
|
||||
|
||||
std::string GetLibDsc()
|
||||
{
|
||||
return LIB_DSC;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,377 @@
|
||||
/*
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup Graphic
|
||||
* @{
|
||||
*
|
||||
* @brief Defines a lightweight graphics system that provides basic UI and container views,
|
||||
* including buttons, images, labels, lists, animators, scroll views, swipe views, and layouts.
|
||||
* This system also provides the Design for X (DFX) capability to implement features such as
|
||||
* view rendering, animation, and input event distribution.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file graphic_config.h
|
||||
*
|
||||
* @brief Provides configuration items required for graphics.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
#ifndef GRAPHIC_LITE_GRAPHIC_CONFIG_H
|
||||
#define GRAPHIC_LITE_GRAPHIC_CONFIG_H
|
||||
|
||||
#include "graphic_types.h"
|
||||
|
||||
namespace OHOS {
|
||||
/**
|
||||
* Defines three graphics library versions: lightweight, standard, and extended versions.
|
||||
* The three versions have different requirements on the memory and hardware.
|
||||
* The standard version is enabled by default.
|
||||
*
|
||||
* The macros of the versions are defined as follows:
|
||||
* Name | Version Description
|
||||
* ------------------- | ----------
|
||||
* VERSION_LITE | Lightweight version
|
||||
* VERSION_STANDARD | Standard version
|
||||
* VERSION_EXTENDED | Extended version
|
||||
*/
|
||||
#ifdef _LITEOS
|
||||
#define VERSION_LITE
|
||||
#elif defined _WIN32 || defined __APPLE__
|
||||
#define VERSION_LITE
|
||||
#else
|
||||
#define VERSION_STANDARD
|
||||
#endif
|
||||
|
||||
/* Defines some configurations and their default values on Huawei LiteOS and other system platforms. */
|
||||
#ifdef _LITEOS
|
||||
/**
|
||||
* @brief Font shaping, which is disabled by default on Huawei LiteOS.
|
||||
* Cannot take effect without ENABLE_ICU.
|
||||
*/
|
||||
#define ENABLE_SHAPING 0
|
||||
/**
|
||||
* @brief Advanced algorithm for line breaks, which is disabled by default on Huawei LiteOS.
|
||||
*/
|
||||
#define ENABLE_ICU 0
|
||||
/**
|
||||
* @brief Multi-Font type, which is disabled by default on Huawei LiteOS.
|
||||
*/
|
||||
#define ENABLE_MULTI_FONT 0
|
||||
/**
|
||||
* @brief Multi-window, which does not take effect on Huawei LiteOS.
|
||||
*/
|
||||
#define ENABLE_WINDOW 0
|
||||
/**
|
||||
* @brief Display buffer for rendering data refresh, which is disabled by default on Huawei LiteOS.
|
||||
*/
|
||||
#define ENABLE_FRAME_BUFFER 0
|
||||
/**
|
||||
* @brief Vector type font, which is enabled by default on Huawei LiteOS.
|
||||
*/
|
||||
#define ENABLE_VECTOR_FONT 1
|
||||
/**
|
||||
* @brief Bitmap type font, which is disabled by default on Huawei LiteOS.
|
||||
*/
|
||||
#define ENABLE_BITMAP_FONT 0
|
||||
/**
|
||||
* @brief Static Bitmap type font, which is disabled by default on Huawei LiteOS.
|
||||
*/
|
||||
#define ENABLE_STATIC_FONT 0
|
||||
|
||||
#define ENABLE_JPEG_AND_PNG 0
|
||||
/**
|
||||
* @brief Graphics rendering hardware acceleration, which is enabled by default on Huawei LiteOS.
|
||||
*/
|
||||
#define ENABLE_HARDWARE_ACCELERATION 1
|
||||
/**
|
||||
* @brief Graphics rendering hardware acceleration for text, which is disabled by default on Huawei LiteOS.
|
||||
*/
|
||||
#define ENABLE_HARDWARE_ACCELERATION_FOR_TEXT 0
|
||||
/**
|
||||
* @brief Graphics rendering accelerated by gfx_engines, which is disabled by default on Huawei LiteOS.
|
||||
*/
|
||||
#define ENABLE_GFX_ENGINES 0
|
||||
/**
|
||||
* @brief ARM NEON ability, which is disabled by default on Huawei LiteOS.
|
||||
*/
|
||||
#define ENABLE_ARM_NEON 0
|
||||
#elif defined _WIN32 || defined __APPLE__
|
||||
/**
|
||||
* @brief Font shaping, which is enabled by default on WIN32.
|
||||
* Cannot take effect without ENABLE_ICU.
|
||||
*/
|
||||
#define ENABLE_SHAPING 0
|
||||
/**
|
||||
* @brief Advanced algorithm for line breaks, which is enabled by default on WIN32.
|
||||
*/
|
||||
#define ENABLE_ICU 0
|
||||
/**
|
||||
* @brief Multi-Font type, which is enabled by default on WIN32.
|
||||
*/
|
||||
#define ENABLE_MULTI_FONT 0
|
||||
/**
|
||||
* @brief Multi-window, which is disabled by default on WIN32.
|
||||
*/
|
||||
#define ENABLE_WINDOW 0
|
||||
/**
|
||||
* @brief Display buffer for rendering data refresh, which is disabled by default on WIN32.
|
||||
*/
|
||||
#define ENABLE_FRAME_BUFFER 0
|
||||
/**
|
||||
* @brief Vector type font, which is enabled by default on WIN32.
|
||||
*/
|
||||
#define ENABLE_VECTOR_FONT 1
|
||||
/**
|
||||
* @brief Bitmap type font, which is enabled by default on WIN32.
|
||||
*/
|
||||
#define ENABLE_BITMAP_FONT 0
|
||||
/**
|
||||
* @brief Static Bitmap type font, enabled by default on WIN32.
|
||||
*/
|
||||
#define ENABLE_STATIC_FONT 0
|
||||
|
||||
#define HARMONYOS_CONFIG_LOG 0
|
||||
|
||||
#define ENABLE_JPEG_AND_PNG 1
|
||||
/**
|
||||
* @brief ARM NEON ability, which is disabled by default on WIN32.
|
||||
*/
|
||||
#define ENABLE_ARM_NEON 0
|
||||
/**
|
||||
* @brief Graphics rendering hardware acceleration, which is disabled by default on WIN32.
|
||||
*/
|
||||
#define ENABLE_HARDWARE_ACCELERATION 0
|
||||
/**
|
||||
* @brief Graphics rendering hardware acceleration for text, which is disabled by default on WIN32.
|
||||
*/
|
||||
#define ENABLE_HARDWARE_ACCELERATION_FOR_TEXT 0
|
||||
/**
|
||||
* @brief Graphics rendering accelerated by gfx_engines, which is disabled by default on WIN32.
|
||||
*/
|
||||
#define ENABLE_GFX_ENGINES 0
|
||||
#else
|
||||
/**
|
||||
* @brief Multi-window, which is enabled by default on other platforms.
|
||||
*/
|
||||
#define ENABLE_WINDOW 1
|
||||
/**
|
||||
* @brief Display buffer for rendering data refresh, which is disabled by default on other platforms.
|
||||
*/
|
||||
#define ENABLE_FRAME_BUFFER 0
|
||||
|
||||
#define ENABLE_JPEG_AND_PNG 1
|
||||
/**
|
||||
* @brief ARM NEON ability, which is enabled by default on other platforms.
|
||||
*/
|
||||
#define ENABLE_ARM_NEON 1
|
||||
/**
|
||||
* @brief Graphics rendering hardware acceleration, which is disabled by default on other platforms.
|
||||
*/
|
||||
#define ENABLE_HARDWARE_ACCELERATION 0
|
||||
/**
|
||||
* @brief Graphics rendering hardware acceleration for text, which is disabled by default on other platforms.
|
||||
*/
|
||||
#define ENABLE_HARDWARE_ACCELERATION_FOR_TEXT 0
|
||||
/**
|
||||
* @brief Graphics rendering accelerated by gfx_engines, which is enabled by default on other platforms.
|
||||
*/
|
||||
#define ENABLE_GFX_ENGINES 1
|
||||
#endif
|
||||
|
||||
#define ENABLE_ROTATE_INPUT 1
|
||||
|
||||
#define ENABLE_MOTOR 1
|
||||
|
||||
/**
|
||||
* @brief 开启或关闭局部渲染能力,默认使能
|
||||
*/
|
||||
#define LOCAL_RENDER 0
|
||||
|
||||
/**
|
||||
* @brief Actually use ARM NEON optimization.
|
||||
* __ARM_NEON__ and __ARM_NEON are set by the compiler according to the compilation option -mfpu=neon
|
||||
*/
|
||||
#if (defined(__ARM_NEON__) || defined(__ARM_NEON)) && ENABLE_ARM_NEON == 1
|
||||
#define ARM_NEON_OPT
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Graphics bottom-layer RGBA, which is enabled by default.
|
||||
*/
|
||||
#define ENABLE_BUFFER_RGBA 1
|
||||
/**
|
||||
* @brief Debug mode, which is disabled by default.
|
||||
*/
|
||||
#define ENABLE_DEBUG 1
|
||||
/**
|
||||
* @brief Memory hook, which is enabled by default. The system memory allocation is taken over after it is enabled.
|
||||
*/
|
||||
#define ENABLE_MEMORY_HOOKS 0
|
||||
/**
|
||||
* @brief Function for monitoring the image refresh frame rate, which is disabled by default.
|
||||
*/
|
||||
#define ENABLE_FPS_SUPPORT 0
|
||||
/**
|
||||
* @brief Anti-aliasing, which is enabled by default.
|
||||
*/
|
||||
#define ENABLE_ANTIALIAS 1
|
||||
/**
|
||||
* @brief Rectangle anti-aliasing, which is disabled by default.
|
||||
*/
|
||||
#define ENABLE_RECT_ANTIALIAS 0
|
||||
/**
|
||||
* @brief Font color mode, which is disabled by default.
|
||||
* After it is enabled, the font color mode is set to <b>4</b> to accelerate font rendering.
|
||||
*/
|
||||
#define ENABLE_SPEC_FONT 0
|
||||
/**
|
||||
* @brief Log function of a graphics subsystem, which is disabled by default
|
||||
*/
|
||||
#define ENABLE_GRAPHIC_LOG 0
|
||||
/**
|
||||
* @brief Performance tracking for debugging, which is disabled by default.
|
||||
*/
|
||||
#define ENABLE_DEBUG_PERFORMANCE_TRACE 0
|
||||
/**
|
||||
* @brief Function for receiving input events in screen-off mode, which is disabled by default.
|
||||
*/
|
||||
#define ENABLE_AOD 0
|
||||
|
||||
/**
|
||||
* @brief Defines the log level. A smaller value indicates a higher priority.
|
||||
* Logs whose priorities are higher than a specified level can be recorded.
|
||||
* Log levels:
|
||||
* NONE: disabling logs
|
||||
* FATAL: fatal level
|
||||
* ERROR: error level
|
||||
* WARN: warning level
|
||||
* INFO: info level
|
||||
* DEBUG: debugging level
|
||||
*/
|
||||
#define GRAPHIC_LOG_LEVEL 5
|
||||
/**
|
||||
* @brief Defines the color depth of graphics rendering. The default value is <b>32</b> bits.
|
||||
* The value can be <b>16</b> or <b>32</b>.
|
||||
*/
|
||||
#define COLOR_DEPTH 32
|
||||
|
||||
/**
|
||||
* @brief Represents the code number of the layer pixel format.
|
||||
* 0: LAYER_PF_ARGB1555
|
||||
* 1: LAYER_PF_ARGB8888
|
||||
* Other: LAYER_PF_ARGB8888
|
||||
*/
|
||||
#define LAYER_PF_CODE 1
|
||||
|
||||
#if LAYER_PF_CODE == 0
|
||||
#define LAYER_PF_ARGB1555
|
||||
#elif LAYER_PF_CODE == 1
|
||||
#define LAYER_PF_ARGB8888
|
||||
#else
|
||||
#define LAYER_PF_ARGB8888
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Defines the file name of default vector font.
|
||||
*/
|
||||
#define DEFAULT_VECTOR_FONT_FILENAME "SourceHanSansSC-Regular.otf"
|
||||
/* Default font size. The default value is <b>18</b>. */
|
||||
static constexpr uint8_t DEFAULT_VECTOR_FONT_SIZE = 18;
|
||||
|
||||
/* Defines some configurations and their default values on Huawei LiteOS and other system platforms. */
|
||||
#ifdef _LITEOS
|
||||
/* Resolution width of a graphics display screen. The default value is <b>454</b>. */
|
||||
static constexpr int16_t HORIZONTAL_RESOLUTION = 454;
|
||||
/* Resolution height of a graphics display screen. The default value is <b>454</b>. */
|
||||
static constexpr int16_t VERTICAL_RESOLUTION = 454;
|
||||
#elif defined _WIN32 || defined __APPLE__
|
||||
/* Resolution width of a graphics display screen. The default value is <b>454</b>. */
|
||||
static constexpr int16_t HORIZONTAL_RESOLUTION = 960;
|
||||
/* Resolution height of a graphics display screen. The default value is <b>454</b>. */
|
||||
static constexpr int16_t VERTICAL_RESOLUTION = 480;
|
||||
#else
|
||||
/* Resolution width of a graphics display screen. The default value is <b>960</b>. */
|
||||
static constexpr int16_t HORIZONTAL_RESOLUTION = 960;
|
||||
/* Resolution height of a graphics display screen. The default value is <b>480</b>. */
|
||||
static constexpr int16_t VERTICAL_RESOLUTION = 480;
|
||||
#endif
|
||||
|
||||
#ifndef VERSION_LITE
|
||||
static constexpr const char* MEDIA_IMAGE_PLAY_CENTER = "/user/data/videoplayer_play_center.png";
|
||||
static constexpr const char* MEDIA_IMAGE_PLAY = "/user/data/videoplayer_play.png";
|
||||
static constexpr const char* MEDIA_IMAGE_PAUSE = "/user/data/videoplayer_pause.png";
|
||||
static constexpr const char* MEDIA_IMAGE_VOLUME = "/user/data/videoplayer_volume.png";
|
||||
static constexpr const char* MEDIA_IMAGE_MUTE = "/user/data/videoplayer_mute.png";
|
||||
#endif
|
||||
|
||||
/* Defines some configurations and their default values on Huawei LiteOS and other system platforms. */
|
||||
#if defined QT_COMPILER
|
||||
/* Default file path for DOM tree logs */
|
||||
static constexpr const char* DEFAULT_DUMP_DOM_TREE_PATH = ".\\dump_dom_tree.json";
|
||||
/* Default file path for font */
|
||||
static constexpr const char* VECTOR_FONT_DIR = "..\\simulator\\font\\";
|
||||
#elif defined _WIN32
|
||||
/* Default file path for DOM tree logs */
|
||||
static constexpr const char* DEFAULT_DUMP_DOM_TREE_PATH = ".\\dump_dom_tree.json";
|
||||
/* Default file path for font */
|
||||
static constexpr const char* VECTOR_FONT_DIR = "..\\..\\tools\\font\\font_tool\\font_tool\\font\\";
|
||||
#elif defined _LITEOS
|
||||
/* Default file path for screenshots */
|
||||
static constexpr const char* DEFAULT_SCREENSHOT_PATH = "user/log/screenshot.bin";
|
||||
/* Default file path for DOM tree logs */
|
||||
static constexpr const char* DEFAULT_DUMP_DOM_TREE_PATH = "user/log/dump_dom_tree.json";
|
||||
#else
|
||||
/* Default file path for screenshots */
|
||||
static constexpr const char* DEFAULT_SCREENSHOT_PATH = "/storage/screenshot.bin";
|
||||
/* Default file path for DOM tree logs */
|
||||
static constexpr const char* DEFAULT_DUMP_DOM_TREE_PATH = "/storage/dump_dom_tree.json";
|
||||
/* Default file path for font */
|
||||
static constexpr const char* VECTOR_FONT_DIR = "/user/data/";
|
||||
#endif
|
||||
/* Default task execution period. The default value is <b>16</b> ms. */
|
||||
static constexpr uint8_t DEFAULT_TASK_PERIOD = 16;
|
||||
/* Window manager execution period. The default value is <b>16</b> ms. */
|
||||
static constexpr uint8_t WMS_MAIN_TASK_PERIOD = 16;
|
||||
static constexpr uint8_t IMG_CACHE_SIZE = 5; /* Maximum number of cached images. The default value is <b>5</b>. */
|
||||
static constexpr uint8_t INDEV_READ_PERIOD = 10; /* Input event read cycle. The default value is <b>10</b> ms. */
|
||||
/* Drag distance threshold of a drag event. The default value is <b>10px</b>. */
|
||||
static constexpr uint8_t INDEV_DRAG_LIMIT = 10;
|
||||
/* Maximum depth of view nesting. The default value is <b>64</b>. */
|
||||
static constexpr uint8_t COMPONENT_NESTING_DEPTH = 64;
|
||||
/* Long-press event threshold. The default value is <b>1000</b> ms. */
|
||||
static constexpr uint16_t INDEV_LONG_PRESS_TIME = 1000;
|
||||
/* Delay for reporting a press event on a draggable object. The default value is <b>100</b> ms. */
|
||||
static constexpr uint16_t INDEV_PRESS_TIME_IN_DRAG = 100;
|
||||
/* Maximum number of bytes in a text that can be continuously displayed. The default value is <b>4096</b> bytes. */
|
||||
static constexpr uint16_t MAX_TEXT_LENGTH = 4096;
|
||||
/* Maximum value of the graphic display range. The default value is <b>16383px</b>. */
|
||||
static constexpr int32_t COORD_MAX = 16383;
|
||||
/* Minimum value of the graphic display range. The default value is <b>-16384px</b>. */
|
||||
static constexpr int32_t COORD_MIN = -16384;
|
||||
static constexpr uint32_t HARFBUZ_CACHE_LENGTH = 0x19000; // 500K
|
||||
static constexpr uint16_t MAX_LINE_WIDTH = 128;
|
||||
/* Maximum length of a QR code string. The default value is <b>256</b>. */
|
||||
static constexpr uint32_t QRCODE_VAL_MAX = 256;
|
||||
/* Rotate sensitivity factor. The default value is <b>1<b> time. */
|
||||
static constexpr int16_t ROTATE_SENSITIVITY = 1;
|
||||
} // namespace OHOS
|
||||
#endif // GRAPHIC_LITE_GRAPHIC_CONFIG_H
|
||||
Executable
+41
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef GRAPHIC_LITE_GRAPHIC_LOCKER_H
|
||||
#define GRAPHIC_LITE_GRAPHIC_LOCKER_H
|
||||
|
||||
#include <pthread.h>
|
||||
|
||||
namespace OHOS {
|
||||
class GraphicLocker {
|
||||
public:
|
||||
GraphicLocker(pthread_mutex_t& mutex) : mutex_(mutex)
|
||||
{
|
||||
pthread_mutex_lock(&mutex_);
|
||||
}
|
||||
|
||||
~GraphicLocker()
|
||||
{
|
||||
pthread_mutex_unlock(&mutex_);
|
||||
}
|
||||
|
||||
GraphicLocker() = delete;
|
||||
GraphicLocker(const GraphicLocker&) = delete;
|
||||
GraphicLocker& operator= (const GraphicLocker&) = delete;
|
||||
private:
|
||||
pthread_mutex_t& mutex_;
|
||||
};
|
||||
}
|
||||
#endif
|
||||
Executable
+100
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef GRAPHIC_LITE_GRAPHIC_MUTEX_H
|
||||
#define GRAPHIC_LITE_GRAPHIC_MUTEX_H
|
||||
#include "stdbool.h"
|
||||
#include "stdint.h"
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#elif defined __linux__ || defined __LITEOS__ || defined __APPLE__
|
||||
#include <pthread.h>
|
||||
#else
|
||||
#include "los_mux.h"
|
||||
#endif // WIN32
|
||||
#include "heap_base.h"
|
||||
|
||||
namespace OHOS {
|
||||
/** @brief graphic mutex adapter for different platform. */
|
||||
class GraphicMutex : public HeapBase {
|
||||
public:
|
||||
/** Default constructor */
|
||||
GraphicMutex()
|
||||
{
|
||||
#ifdef _WIN32
|
||||
mutex_ = CreateMutex(NULL, FALSE, NULL);
|
||||
initFlag_ = (mutex_ != NULL);
|
||||
#elif defined __linux__ || defined __LITEOS__ || defined __APPLE__
|
||||
initFlag_ = (pthread_mutex_init(&mutex_, NULL) == 0);
|
||||
#else
|
||||
initFlag_ = (LOS_MuxCreate(&mutex_) == LOS_OK);
|
||||
#endif // WIN32
|
||||
}
|
||||
|
||||
/** Default destructor */
|
||||
~GraphicMutex()
|
||||
{
|
||||
if (initFlag_ == false) {
|
||||
return;
|
||||
}
|
||||
#ifdef _WIN32
|
||||
CloseHandle(mutex_);
|
||||
#elif defined __linux__ || defined __LITEOS__ || defined __APPLE__
|
||||
pthread_mutex_destroy(&mutex_);
|
||||
#else
|
||||
LOS_MuxDelete(mutex_);
|
||||
#endif // WIN32
|
||||
}
|
||||
|
||||
inline bool Lock()
|
||||
{
|
||||
if (initFlag_ == false) {
|
||||
return false;
|
||||
}
|
||||
#ifdef _WIN32
|
||||
return (WaitForSingleObject(mutex_, INFINITE) == WAIT_OBJECT_0);
|
||||
#elif defined __linux__ || defined __LITEOS__ || defined __APPLE__
|
||||
return (pthread_mutex_lock(&mutex_) == 0);
|
||||
#else
|
||||
return (LOS_MuxPend(mutex_, LOS_WAIT_FOREVER) == LOS_OK);
|
||||
#endif // WIN32
|
||||
}
|
||||
|
||||
inline bool Unlock()
|
||||
{
|
||||
if (initFlag_ == false) {
|
||||
return false;
|
||||
}
|
||||
#ifdef _WIN32
|
||||
return ReleaseMutex(mutex_);
|
||||
#elif defined __linux__ || defined __LITEOS__ || defined __APPLE__
|
||||
return (pthread_mutex_unlock(&mutex_) == 0);
|
||||
#else
|
||||
return (LOS_MuxPost(mutex_) == LOS_OK);
|
||||
#endif // WIN32
|
||||
}
|
||||
|
||||
private:
|
||||
bool initFlag_;
|
||||
#ifdef _WIN32
|
||||
HANDLE mutex_;
|
||||
#elif defined __linux__ || defined __LITEOS__ || defined __APPLE__
|
||||
pthread_mutex_t mutex_;
|
||||
#else
|
||||
uint32_t mutex_;
|
||||
#endif // WIN32
|
||||
};
|
||||
} // namespace OHOS
|
||||
#endif // GRAPHIC_LITE_GRAPHIC_MUTEX_H
|
||||
Executable
+141
@@ -0,0 +1,141 @@
|
||||
/*
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef GRAPHIC_LITE_GRAPHIC_NEON_PIPELINE_H
|
||||
#define GRAPHIC_LITE_GRAPHIC_NEON_PIPELINE_H
|
||||
|
||||
#include "graphic_config.h"
|
||||
#ifdef ARM_NEON_OPT
|
||||
#include <arm_neon.h>
|
||||
#include "color.h"
|
||||
#include "graphic_neon_utils.h"
|
||||
|
||||
namespace OHOS {
|
||||
using LoadBuf = void (*)(uint8_t* buf, uint8x8_t& r, uint8x8_t& g, uint8x8_t& b, uint8x8_t& a);
|
||||
using LoadBufA = void (*)(uint8_t* buf, uint8x8_t& r, uint8x8_t& g, uint8x8_t& b, uint8x8_t& a, uint8_t opa);
|
||||
using NeonBlend = void (*)(uint8x8_t& r1, uint8x8_t& g1, uint8x8_t& b1, uint8x8_t& a1,
|
||||
uint8x8_t r2, uint8x8_t g2, uint8x8_t b2, uint8x8_t a2);
|
||||
using StoreBuf = void (*)(uint8_t* buf, uint8x8_t& r, uint8x8_t& g, uint8x8_t& b, uint8x8_t& a);
|
||||
|
||||
struct {
|
||||
ColorMode dm;
|
||||
LoadBuf loadDstFunc;
|
||||
NeonBlend blendFunc;
|
||||
StoreBuf storeDstFunc;
|
||||
} g_dstFunc[] = {
|
||||
{ARGB8888, LoadBuf_ARGB8888, NeonBlendRGBA, StoreBuf_ARGB8888},
|
||||
{RGB888, LoadBuf_RGB888, NeonBlendRGB, StoreBuf_RGB888},
|
||||
{RGB565, LoadBuf_RGB565, NeonBlendRGB, StoreBuf_RGB565}
|
||||
};
|
||||
|
||||
struct {
|
||||
ColorMode sm;
|
||||
LoadBufA loadSrcFunc;
|
||||
} g_srcFunc[] = {
|
||||
{ARGB8888, LoadBufA_ARGB8888},
|
||||
{RGB888, LoadBufA_RGB888},
|
||||
{RGB565, LoadBufA_RGB565}
|
||||
};
|
||||
|
||||
class NeonBlendPipeLine {
|
||||
public:
|
||||
NeonBlendPipeLine() {}
|
||||
~NeonBlendPipeLine() {}
|
||||
|
||||
void Construct(ColorMode dm, ColorMode sm, void* srcColor = nullptr, uint8_t opa = OPA_OPAQUE)
|
||||
{
|
||||
int16_t dstNum = sizeof(g_dstFunc) / sizeof(g_dstFunc[0]);
|
||||
for (int16_t i = 0; i < dstNum; ++i) {
|
||||
if (g_dstFunc[i].dm == dm) {
|
||||
loadDstFunc_ = g_dstFunc[i].loadDstFunc;
|
||||
blendFunc_ = g_dstFunc[i].blendFunc;
|
||||
storeDstFunc_ = g_dstFunc[i].storeDstFunc;
|
||||
break;
|
||||
}
|
||||
}
|
||||
int16_t srcNum = sizeof(g_srcFunc) / sizeof(g_srcFunc[0]);
|
||||
for (int16_t i = 0; i < srcNum; ++i) {
|
||||
if (g_srcFunc[i].sm == sm) {
|
||||
loadSrcFunc_ = g_srcFunc[i].loadSrcFunc;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (srcColor != nullptr) {
|
||||
ConstructSrcColor(sm, srcColor, opa, r2_, g2_, b2_, a2_);
|
||||
}
|
||||
}
|
||||
|
||||
void Invoke(uint8_t* dst, uint8_t* src, uint8_t opa)
|
||||
{
|
||||
loadDstFunc_(dst, r1_, g1_, b1_, a1_);
|
||||
loadSrcFunc_(src, r2_, g2_, b2_, a2_, opa);
|
||||
blendFunc_(r1_, g1_, b1_, a1_, r2_, g2_, b2_, a2_);
|
||||
storeDstFunc_(dst, r1_, g1_, b1_, a1_);
|
||||
}
|
||||
|
||||
void Invoke(uint8_t* dst)
|
||||
{
|
||||
loadDstFunc_(dst, r1_, g1_, b1_, a1_);
|
||||
blendFunc_(r1_, g1_, b1_, a1_, r2_, g2_, b2_, a2_);
|
||||
storeDstFunc_(dst, r1_, g1_, b1_, a1_);
|
||||
}
|
||||
|
||||
void Invoke(uint8_t* dst, uint8x8_t& r, uint8x8_t& g, uint8x8_t& b, uint8x8_t& a)
|
||||
{
|
||||
loadDstFunc_(dst, r1_, g1_, b1_, a1_);
|
||||
blendFunc_(r1_, g1_, b1_, a1_, r, g, b, a);
|
||||
storeDstFunc_(dst, r1_, g1_, b1_, a1_);
|
||||
}
|
||||
private:
|
||||
void ConstructSrcColor(ColorMode sm, void* srcColor, uint8_t opa,
|
||||
uint8x8_t& r, uint8x8_t& g, uint8x8_t& b, uint8x8_t& a)
|
||||
{
|
||||
if (sm == ARGB8888) {
|
||||
Color32* color = reinterpret_cast<Color32*>(srcColor);
|
||||
r = vdup_n_u8(color->red);
|
||||
g = vdup_n_u8(color->green);
|
||||
b = vdup_n_u8(color->blue);
|
||||
a = NeonMulDiv255(vdup_n_u8(opa), vdup_n_u8(color->alpha));
|
||||
} else if (sm == RGB888) {
|
||||
Color24* color = reinterpret_cast<Color24*>(srcColor);
|
||||
r = vdup_n_u8(color->red);
|
||||
g = vdup_n_u8(color->green);
|
||||
b = vdup_n_u8(color->blue);
|
||||
a = vdup_n_u8(opa);
|
||||
} else if (sm == RGB565) {
|
||||
Color16* color = reinterpret_cast<Color16*>(srcColor);
|
||||
r = vdup_n_u8(color->red);
|
||||
g = vdup_n_u8(color->green);
|
||||
b = vdup_n_u8(color->blue);
|
||||
a = vdup_n_u8(opa);
|
||||
}
|
||||
}
|
||||
|
||||
LoadBuf loadDstFunc_ = nullptr;
|
||||
LoadBufA loadSrcFunc_ = nullptr;
|
||||
NeonBlend blendFunc_ = nullptr;
|
||||
StoreBuf storeDstFunc_ = nullptr;
|
||||
uint8x8_t r1_;
|
||||
uint8x8_t g1_;
|
||||
uint8x8_t b1_;
|
||||
uint8x8_t a1_;
|
||||
uint8x8_t r2_;
|
||||
uint8x8_t g2_;
|
||||
uint8x8_t b2_;
|
||||
uint8x8_t a2_;
|
||||
};
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
Executable
+213
@@ -0,0 +1,213 @@
|
||||
/*
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef GRAPHIC_LITE_GRAPHIC_NEON_UTILS_H
|
||||
#define GRAPHIC_LITE_GRAPHIC_NEON_UTILS_H
|
||||
|
||||
#include "graphic_config.h"
|
||||
#ifdef ARM_NEON_OPT
|
||||
#include <arm_neon.h>
|
||||
#include "color.h"
|
||||
#include "graphic_math.h"
|
||||
#include "graphic_types.h"
|
||||
|
||||
namespace OHOS {
|
||||
#define NEON_STEP_4 4
|
||||
#define NEON_STEP_8 8
|
||||
#define NEON_STEP_32 32
|
||||
#define NEON_A 3
|
||||
#define NEON_R 2
|
||||
#define NEON_G 1
|
||||
#define NEON_B 0
|
||||
|
||||
// return vIn / 255
|
||||
static inline uint8x8_t NeonFastDiv255(uint16x8_t vIn)
|
||||
{
|
||||
// 257: 2^8 + 1; 8: number of shifts
|
||||
return vmovn_u16(vshrq_n_u16(vIn + vshrq_n_u16(vIn + vdupq_n_u16(257), 8), 8));
|
||||
}
|
||||
|
||||
// return a * b / 255
|
||||
static inline uint8x8_t NeonMulDiv255(uint8x8_t a, uint8x8_t b)
|
||||
{
|
||||
return NeonFastDiv255(vmull_u8(a, b));
|
||||
}
|
||||
|
||||
// return a / b
|
||||
// a, b and result are floating-point numbers.
|
||||
static inline float32x4_t NeonDiv(float32x4_t a, float32x4_t b)
|
||||
{
|
||||
float32x4_t reciprocal = vrecpeq_f32(b);
|
||||
reciprocal = vmulq_f32(vrecpsq_f32(b, reciprocal), reciprocal);
|
||||
reciprocal = vmulq_f32(vrecpsq_f32(b, reciprocal), reciprocal);
|
||||
return vmulq_f32(a, reciprocal);
|
||||
}
|
||||
|
||||
// return a / b
|
||||
// a is a 16-bits integer, b and result are 8-bits integers.
|
||||
static inline uint8x8_t NeonDivInt(uint16x8_t a, uint8x8_t b)
|
||||
{
|
||||
float32x4_t low = NeonDiv(vcvtq_f32_u32(vmovl_u16(vget_low_u16(a))),
|
||||
vcvtq_f32_u32(vmovl_u16(vget_low_u16(vmovl_u8(b)))));
|
||||
float32x4_t high = NeonDiv(vcvtq_f32_u32(vmovl_u16(vget_high_u16(a))),
|
||||
vcvtq_f32_u32(vmovl_u16(vget_high_u16(vmovl_u8(b)))));
|
||||
return vmovn_u16(vcombine_u16(vmovn_u32(vcvtq_u32_f32(low)), vmovn_u32(vcvtq_u32_f32(high))));
|
||||
}
|
||||
|
||||
static void NeonMemcpy(void* dst, int32_t dstSize, const void* src, int32_t srcSize)
|
||||
{
|
||||
int32_t sz = MATH_MIN(dstSize, srcSize);
|
||||
// 64-bytes aligned
|
||||
int32_t mod = sz % 64;
|
||||
if (mod) {
|
||||
if (memcpy_s(dst, mod, src, mod) != EOK) {
|
||||
return;
|
||||
}
|
||||
sz -= mod;
|
||||
if (sz == 0) {
|
||||
return;
|
||||
}
|
||||
dst = (uint8_t*)dst + mod;
|
||||
src = (uint8_t*)src + mod;
|
||||
}
|
||||
|
||||
asm volatile (
|
||||
"NEONCopyPLD: \n"
|
||||
" PLD [%[src], #0xC0] \n"
|
||||
" VLDM %[src]!, {d0-d7} \n"
|
||||
" VSTM %[dst]!, {d0-d7} \n"
|
||||
" SUBS %[sz], %[sz], #0x40 \n"
|
||||
" BGT NEONCopyPLD \n"
|
||||
: [dst]"+r"(dst), [src]"+r"(src), [sz]"+r"(sz) : : "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7", "cc", "memory");
|
||||
}
|
||||
|
||||
static inline void NeonBlendRGBA(uint8x8_t& r1, uint8x8_t& g1, uint8x8_t& b1, uint8x8_t& a1,
|
||||
uint8x8_t r2, uint8x8_t g2, uint8x8_t b2, uint8x8_t a2)
|
||||
{
|
||||
uint8x8_t da = NeonMulDiv255(a1, vdup_n_u8(OPA_OPAQUE) - a2);
|
||||
a1 = a1 - NeonMulDiv255(a2, a1) + a2;
|
||||
uint16x8_t r = vmull_u8(r2, a2) + vmull_u8(r1, da);
|
||||
uint16x8_t g = vmull_u8(g2, a2) + vmull_u8(g1, da);
|
||||
uint16x8_t b = vmull_u8(b2, a2) + vmull_u8(b1, da);
|
||||
r1 = NeonDivInt(r, a1);
|
||||
g1 = NeonDivInt(g, a1);
|
||||
b1 = NeonDivInt(b, a1);
|
||||
}
|
||||
|
||||
static inline void NeonBlendRGB(uint8x8_t& r1, uint8x8_t& g1, uint8x8_t& b1, uint8x8_t& a1,
|
||||
uint8x8_t r2, uint8x8_t g2, uint8x8_t b2, uint8x8_t a2)
|
||||
{
|
||||
uint8x8_t da = vdup_n_u8(OPA_OPAQUE) - a2;
|
||||
r1 = NeonMulDiv255(r2, a2) + NeonMulDiv255(r1, da);
|
||||
g1 = NeonMulDiv255(g2, a2) + NeonMulDiv255(g1, da);
|
||||
b1 = NeonMulDiv255(b2, a2) + NeonMulDiv255(b1, da);
|
||||
}
|
||||
|
||||
static inline void LoadBuf_ARGB8888(uint8_t* buf, uint8x8_t& r, uint8x8_t& g, uint8x8_t& b, uint8x8_t& a)
|
||||
{
|
||||
uint8x8x4_t vBuf = vld4_u8(buf);
|
||||
r = vBuf.val[NEON_R];
|
||||
g = vBuf.val[NEON_G];
|
||||
b = vBuf.val[NEON_B];
|
||||
a = vBuf.val[NEON_A];
|
||||
}
|
||||
|
||||
static inline void LoadBuf_RGB888(uint8_t* buf, uint8x8_t& r, uint8x8_t& g, uint8x8_t& b, uint8x8_t& a)
|
||||
{
|
||||
uint8x8x3_t vBuf = vld3_u8(buf);
|
||||
r = vBuf.val[NEON_R];
|
||||
g = vBuf.val[NEON_G];
|
||||
b = vBuf.val[NEON_B];
|
||||
}
|
||||
|
||||
static inline void LoadBuf_RGB565(uint8_t* buf, uint8x8_t& r, uint8x8_t& g, uint8x8_t& b, uint8x8_t& a)
|
||||
{
|
||||
uint16x8_t vBuf = vld1q_u16(reinterpret_cast<uint16_t*>(buf));
|
||||
// 3: RRRRRGGG|GGGBBBBB => RRGGGGGG|BBBBB000
|
||||
b = vmovn_u16(vshlq_n_u16(vBuf, 3));
|
||||
// 5, 2: RRRRRGGG|GGGBBBBB => XXXRRRRR|GGGGGG00
|
||||
g = vshl_n_u8(vshrn_n_u16(vBuf, 5), 2);
|
||||
// 11, 3: RRRRRGGG|GGGBBBBB => XXXXXXXX|RRRRR000
|
||||
r = vmovn_u16(vshlq_n_u16(vshrq_n_u16(vBuf, 11), 3));
|
||||
}
|
||||
|
||||
static inline void LoadBufA_ARGB8888(uint8_t* buf, uint8x8_t& r, uint8x8_t& g, uint8x8_t& b, uint8x8_t& a, uint8_t opa)
|
||||
{
|
||||
uint8x8x4_t vBuf = vld4_u8(buf);
|
||||
r = vBuf.val[NEON_R];
|
||||
g = vBuf.val[NEON_G];
|
||||
b = vBuf.val[NEON_B];
|
||||
a = NeonMulDiv255(vBuf.val[NEON_A], vdup_n_u8(opa));
|
||||
}
|
||||
|
||||
static inline void LoadBufA_RGB888(uint8_t* buf, uint8x8_t& r, uint8x8_t& g, uint8x8_t& b, uint8x8_t& a, uint8_t opa)
|
||||
{
|
||||
uint8x8x3_t vBuf = vld3_u8(buf);
|
||||
r = vBuf.val[NEON_R];
|
||||
g = vBuf.val[NEON_G];
|
||||
b = vBuf.val[NEON_B];
|
||||
a = vdup_n_u8(opa);
|
||||
}
|
||||
|
||||
static inline void LoadBufA_RGB565(uint8_t* buf, uint8x8_t& r, uint8x8_t& g, uint8x8_t& b, uint8x8_t& a, uint8_t opa)
|
||||
{
|
||||
uint16x8_t vBuf = vld1q_u16(reinterpret_cast<uint16_t*>(buf));
|
||||
// 3: RRRRRGGG|GGGBBBBB => RRGGGGGG|BBBBB000
|
||||
b = vmovn_u16(vshlq_n_u16(vBuf, 3));
|
||||
// 5, 2: RRRRRGGG|GGGBBBBB => XXXRRRRR|GGGGGG00
|
||||
g = vshl_n_u8(vshrn_n_u16(vBuf, 5), 2);
|
||||
// 11, 3: RRRRRGGG|GGGBBBBB => XXXXXXXX|RRRRR000
|
||||
r = vmovn_u16(vshlq_n_u16(vshrq_n_u16(vBuf, 11), 3));
|
||||
a = vdup_n_u8(opa);
|
||||
}
|
||||
|
||||
static inline void StoreBuf_ARGB8888(uint8_t* buf, uint8x8_t& r, uint8x8_t& g, uint8x8_t& b, uint8x8_t& a)
|
||||
{
|
||||
uint8x8x4_t vBuf;
|
||||
vBuf.val[NEON_R] = r;
|
||||
vBuf.val[NEON_G] = g;
|
||||
vBuf.val[NEON_B] = b;
|
||||
vBuf.val[NEON_A] = a;
|
||||
vst4_u8(buf, vBuf);
|
||||
}
|
||||
|
||||
static inline void StoreBuf_RGB888(uint8_t* buf, uint8x8_t& r, uint8x8_t& g, uint8x8_t& b, uint8x8_t& a)
|
||||
{
|
||||
uint8x8x3_t vBuf;
|
||||
vBuf.val[NEON_R] = r;
|
||||
vBuf.val[NEON_G] = g;
|
||||
vBuf.val[NEON_B] = b;
|
||||
vst3_u8(buf, vBuf);
|
||||
}
|
||||
|
||||
static inline void StoreBuf_RGB565(uint8_t* buf, uint8x8_t& r, uint8x8_t& g, uint8x8_t& b, uint8x8_t& a)
|
||||
{
|
||||
/* red left shift 8 bit.
|
||||
* vBuf => RRRRRXXX|XXXXXXXX
|
||||
*/
|
||||
uint16x8_t vBuf = vshll_n_u8(r, 8);
|
||||
/* Keep the first 5 digits of vBuf, and splice it with vshll_n_u8(g, 8).
|
||||
* vBuf => RRRRRGGG|GGGXXXXX
|
||||
*/
|
||||
vBuf = vsriq_n_u16(vBuf, vshll_n_u8(g, 8), 5);
|
||||
/* Keep the first 11 digits of vBuf, and splice it with vshll_n_u8(b, 8).
|
||||
* vBuf => RRRRRGGG|GGGBBBBB
|
||||
*/
|
||||
vBuf = vsriq_n_u16(vBuf, vshll_n_u8(b, 8), 11);
|
||||
vst1q_u16(reinterpret_cast<uint16_t*>(buf), vBuf);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
Executable
+156
@@ -0,0 +1,156 @@
|
||||
/*
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef GRAPHIC_LITE_GRAPHIC_PERFORMANCE_H
|
||||
#define GRAPHIC_LITE_GRAPHIC_PERFORMANCE_H
|
||||
|
||||
#include "graphic_config.h"
|
||||
#if ENABLE_DEBUG && ENABLE_DEBUG_PERFORMANCE_TRACE
|
||||
#include <limits>
|
||||
#include <map>
|
||||
#include <signal.h>
|
||||
#include <string>
|
||||
#include <stdio.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
namespace OHOS {
|
||||
static const char* perfTitle[5] = {"name", "times", "minCost", "maxCost", "avgCost"};
|
||||
struct PerformanceItem {
|
||||
int32_t times;
|
||||
int32_t minCost;
|
||||
int32_t maxCost;
|
||||
double avgCost;
|
||||
int32_t warmup;
|
||||
};
|
||||
|
||||
class Performance {
|
||||
public:
|
||||
static Performance* GetInstance()
|
||||
{
|
||||
static Performance instance;
|
||||
return &instance;
|
||||
}
|
||||
|
||||
static void SigUsr(int signo)
|
||||
{
|
||||
if (signo == SIGUSR1) {
|
||||
Performance::GetInstance()->SetPrintFlag();
|
||||
}
|
||||
}
|
||||
|
||||
void RegisterSIGUSR1()
|
||||
{
|
||||
if (signal(SIGUSR1, SigUsr) == SIG_ERR) {
|
||||
printf("signal error!\n");
|
||||
}
|
||||
}
|
||||
|
||||
void UpdateItem(std::string name, int32_t cost, int32_t warmup)
|
||||
{
|
||||
if (mapPerfItem.find(name) == mapPerfItem.end()) {
|
||||
PerformanceItem item = { 0 };
|
||||
item.times = 1;
|
||||
item.minCost = INT32_MAX;
|
||||
item.warmup = warmup;
|
||||
mapPerfItem[name] = item;
|
||||
} else {
|
||||
PerformanceItem& item = mapPerfItem[name];
|
||||
item.times++;
|
||||
}
|
||||
PerformanceItem& item = mapPerfItem[name];
|
||||
if (item.times > warmup) {
|
||||
item.minCost = (item.minCost > cost) ? cost : item.minCost;
|
||||
item.maxCost = (item.maxCost < cost) ? cost : item.maxCost;
|
||||
item.avgCost = item.avgCost + 1.0 * (cost - item.avgCost) / (item.times - warmup);
|
||||
}
|
||||
}
|
||||
|
||||
void SetPrintFlag()
|
||||
{
|
||||
needPrint = true;
|
||||
}
|
||||
|
||||
void PrintResult()
|
||||
{
|
||||
if (!needPrint) {
|
||||
return;
|
||||
}
|
||||
needPrint = false;
|
||||
/*
|
||||
* perfTitle[0]: "name"
|
||||
* perfTitle[1]: "times"
|
||||
* perfTitle[2]: "minCost"
|
||||
* perfTitle[3]: "maxCost"
|
||||
* perfTitle[4]: "avgCost"
|
||||
*/
|
||||
printf("\n%-40s%-20s%-20s%-20s%-20s\n", perfTitle[0], perfTitle[1], perfTitle[2], perfTitle[3], perfTitle[4]);
|
||||
for (auto iter = mapPerfItem.begin(); iter != mapPerfItem.end(); iter++) {
|
||||
if (iter->second.times - iter->second.warmup > 0) {
|
||||
printf("%-40s%-20d%-20d%-20d%-20.2lf\n",
|
||||
iter->first.c_str(),
|
||||
iter->second.times - iter->second.warmup,
|
||||
iter->second.minCost,
|
||||
iter->second.maxCost,
|
||||
iter->second.avgCost);
|
||||
}
|
||||
}
|
||||
}
|
||||
private:
|
||||
Performance() {}
|
||||
~Performance() {}
|
||||
|
||||
std::map<std::string, PerformanceItem> mapPerfItem;
|
||||
bool needPrint = false;
|
||||
};
|
||||
|
||||
class PerformanceTool {
|
||||
public:
|
||||
PerformanceTool(const char* name) : name_(name)
|
||||
{
|
||||
gettimeofday(&tm_, NULL);
|
||||
}
|
||||
|
||||
PerformanceTool(const char* name, int32_t warmup) : name_(name), warmUp_(warmup)
|
||||
{
|
||||
gettimeofday(&tm_, NULL);
|
||||
}
|
||||
|
||||
~PerformanceTool()
|
||||
{
|
||||
struct timeval now;
|
||||
gettimeofday(&now, NULL);
|
||||
// 1000000: 1,000,000 microseconds per second
|
||||
int32_t cost = (now.tv_sec - tm_.tv_sec) * 1000000 + (now.tv_usec - tm_.tv_usec);
|
||||
Performance::GetInstance()->UpdateItem(name_, cost, warmUp_);
|
||||
}
|
||||
private:
|
||||
std::string name_;
|
||||
int32_t warmUp_ = 0;
|
||||
struct timeval tm_;
|
||||
};
|
||||
}
|
||||
#define DEBUG_PERFORMANCE_TRACE_AUTO() OHOS::PerformanceTool __tmp__(__FUNCTION__)
|
||||
#define DEBUG_PERFORMANCE_TRACE_WARMUP(x, warmup) OHOS::PerformanceTool __tmp__(x, warmup)
|
||||
#define DEBUG_PERFORMANCE_TRACE(x) OHOS::PerformanceTool __tmp__(x)
|
||||
#define DEBUG_PERFORMANCE_REGISTER_SIG() OHOS::Performance::GetInstance()->RegisterSIGUSR1()
|
||||
#define DEBUG_PERFORMANCE_PRINT_RESULT() OHOS::Performance::GetInstance()->PrintResult()
|
||||
#else
|
||||
#define DEBUG_PERFORMANCE_TRACE_AUTO()
|
||||
#define DEBUG_PERFORMANCE_TRACE_WARMUP(x, warmup)
|
||||
#define DEBUG_PERFORMANCE_TRACE(x)
|
||||
#define DEBUG_PERFORMANCE_REGISTER_SIG()
|
||||
#define DEBUG_PERFORMANCE_PRINT_RESULT()
|
||||
#endif
|
||||
#endif
|
||||
Executable
+119
@@ -0,0 +1,119 @@
|
||||
/*
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef GRAPHIC_LITE_GRAPHIC_SEMAPHORE_H
|
||||
#define GRAPHIC_LITE_GRAPHIC_SEMAPHORE_H
|
||||
#include "stdbool.h"
|
||||
#include "stdint.h"
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#elif defined __linux__ || defined __LITEOS__ || defined __APPLE__
|
||||
#include <limits.h>
|
||||
#include <semaphore.h>
|
||||
#else
|
||||
#include "los_sem.h"
|
||||
#endif // WIN32
|
||||
#include "heap_base.h"
|
||||
|
||||
namespace OHOS {
|
||||
static constexpr int32_t MAX_SEM_COUNT = 1000; // 1000: max number of semaphore count
|
||||
|
||||
/** @brief Semaphore adapter for different platform. */
|
||||
class GraphicSemaphore : public HeapBase {
|
||||
public:
|
||||
/** Default constructor */
|
||||
GraphicSemaphore() : GraphicSemaphore(0, MAX_SEM_COUNT) {}
|
||||
|
||||
GraphicSemaphore(int init) : GraphicSemaphore(init, MAX_SEM_COUNT) {}
|
||||
|
||||
GraphicSemaphore(int init, int max)
|
||||
{
|
||||
if (max > MAX_SEM_COUNT) {
|
||||
max = MAX_SEM_COUNT;
|
||||
}
|
||||
if (init > max) {
|
||||
init = max;
|
||||
}
|
||||
#ifdef _WIN32
|
||||
sem_ = CreateSemaphore(NULL, init, max, NULL);
|
||||
initFlag_ = (sem_ != nullptr);
|
||||
#elif defined __linux__ || defined __LITEOS__ || defined __APPLE__
|
||||
initFlag_ = (sem_init(&sem_, 0, init) == 0);
|
||||
#else
|
||||
if (max == 1) {
|
||||
initFlag_ = (LOS_BinarySemCreate((uint16_t)init, &sem_) == LOS_OK);
|
||||
} else {
|
||||
initFlag_ = (LOS_SemCreate((uint16_t)init, &sem_) == LOS_OK);
|
||||
}
|
||||
#endif // WIN32
|
||||
}
|
||||
|
||||
/** Default destructor */
|
||||
~GraphicSemaphore()
|
||||
{
|
||||
if (initFlag_ == false) {
|
||||
return;
|
||||
}
|
||||
#ifdef _WIN32
|
||||
CloseHandle(sem_);
|
||||
#elif defined __linux__ || defined __LITEOS__ || defined __APPLE__
|
||||
sem_destroy(&sem_);
|
||||
#else
|
||||
LOS_SemDelete(sem_);
|
||||
#endif // WIN32
|
||||
}
|
||||
|
||||
/** Increases the count of the specified semaphore object by a specified amount. */
|
||||
inline bool Notify()
|
||||
{
|
||||
if (initFlag_ == false) {
|
||||
return false;
|
||||
}
|
||||
#ifdef _WIN32
|
||||
return ReleaseSemaphore(sem_, 1, NULL);
|
||||
#elif defined __linux__ || defined __LITEOS__ || defined __APPLE__
|
||||
return (sem_post(&sem_) == 0);
|
||||
#else
|
||||
return (LOS_SemPost(sem_) == LOS_OK);
|
||||
#endif // WIN32
|
||||
}
|
||||
|
||||
/** Waits until the specified object is in the signaled state. */
|
||||
inline bool Wait()
|
||||
{
|
||||
if (initFlag_ == false) {
|
||||
return false;
|
||||
}
|
||||
#ifdef _WIN32
|
||||
return (WaitForSingleObject(sem_, INFINITE) == WAIT_OBJECT_0);
|
||||
#elif defined __linux__ || defined __LITEOS__ || defined __APPLE__
|
||||
return (sem_wait(&sem_) == 0);
|
||||
#else
|
||||
return (LOS_SemPend(sem_, LOS_WAIT_FOREVER) == LOS_OK);
|
||||
#endif // WIN32
|
||||
}
|
||||
|
||||
private:
|
||||
bool initFlag_;
|
||||
#ifdef _WIN32
|
||||
HANDLE sem_;
|
||||
#elif defined __linux__ || defined __LITEOS__ || defined __APPLE__
|
||||
sem_t sem_;
|
||||
#else
|
||||
uint32_t sem_;
|
||||
#endif // WIN32
|
||||
};
|
||||
} // namespace OHOS
|
||||
#endif // GRAPHIC_LITE_GRAPHIC_SEMAPHORE_H
|
||||
Executable
+73
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef GRAPHIC_LITE_THREAD_H
|
||||
#define GRAPHIC_LITE_THREAD_H
|
||||
|
||||
#include <stdint.h>
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#elif defined __linux__ || defined __LITEOS__ || defined __APPLE__
|
||||
#include <pthread.h>
|
||||
#endif // WIN32
|
||||
|
||||
typedef void* ThreadId;
|
||||
#ifdef _WIN32
|
||||
typedef DWORD(WINAPI* Runnable)(LPVOID lpThreadParameter);
|
||||
#else
|
||||
typedef void* (*Runnable)(void* argv);
|
||||
#endif
|
||||
typedef struct ThreadAttr ThreadAttr;
|
||||
struct ThreadAttr {
|
||||
const char* name; // name of the thread
|
||||
uint32_t stackSize; // size of stack
|
||||
uint8_t priority; // initial thread priority
|
||||
uint8_t reserved1; // reserved1 (must be 0)
|
||||
uint16_t reserved2; // reserved2 (must be 0)
|
||||
};
|
||||
|
||||
static inline ThreadId ThreadCreate(Runnable entry, void* arg, const ThreadAttr* attr)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
HANDLE handle = CreateThread(NULL, 0, entry, arg, 0, NULL);
|
||||
return (ThreadId)handle;
|
||||
#elif defined __linux__ || defined __LITEOS__ || defined __APPLE__
|
||||
pthread_attr_t threadAttr;
|
||||
pthread_attr_init(&threadAttr);
|
||||
pthread_attr_setdetachstate(&threadAttr, PTHREAD_CREATE_DETACHED);
|
||||
if (attr != NULL) {
|
||||
pthread_attr_setstacksize(&threadAttr, attr->stackSize);
|
||||
struct sched_param sched = {attr->priority};
|
||||
pthread_attr_setschedparam(&threadAttr, &sched);
|
||||
}
|
||||
pthread_t threadId;
|
||||
int ret = pthread_create(&threadId, &threadAttr, entry, arg);
|
||||
if (ret != 0) {
|
||||
return NULL;
|
||||
}
|
||||
return (ThreadId)threadId;
|
||||
#else
|
||||
return NULL;
|
||||
#endif
|
||||
}
|
||||
static inline void ThreadYield(void)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
SwitchToThread();
|
||||
#elif defined __linux__ || defined __LITEOS__ || defined __APPLE__
|
||||
sched_yield();
|
||||
#endif
|
||||
}
|
||||
#endif // GRAPHIC_LITE_THREAD_H
|
||||
Executable
+63
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef GRAPHIC_LITE_HAL_ATOMIC_H
|
||||
#define GRAPHIC_LITE_HAL_ATOMIC_H
|
||||
|
||||
#include "stdbool.h"
|
||||
#include "stdint.h"
|
||||
#include "stdio.h"
|
||||
|
||||
static inline void HalAtomicAdd32(volatile uint32_t* ptr, uint32_t value)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
InterlockedExchangeAdd(ptr, value);
|
||||
#elif defined __linux__ || defined __LITEOS__ || defined __APPLE__
|
||||
__sync_fetch_and_add(ptr, value);
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline uint32_t HalAtomicAddAndFetch32(volatile uint32_t* ptr, uint32_t value)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
return InterlockedExchangeAdd(ptr, value) + value;
|
||||
#elif defined __linux__ || defined __LITEOS__ || defined __APPLE__
|
||||
return __sync_add_and_fetch(ptr, value);
|
||||
#else
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline void HalAtomicAdd64(uint64_t* ptr, uint64_t value)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
InterlockedExchangeAdd64((volatile long long*)ptr, value);
|
||||
#elif defined __linux__ || defined __LITEOS__ || defined __APPLE__
|
||||
__sync_fetch_and_add(ptr, value);
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline bool HalAtomicCmpAndSwap32(volatile uint32_t* ptr, uint32_t oldValue, uint32_t newValue)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
uint32_t initial = InterlockedCompareExchange(ptr, newValue, oldValue);
|
||||
return initial == oldValue;
|
||||
#elif defined __linux__ || defined __LITEOS__ || defined __APPLE__
|
||||
return __sync_bool_compare_and_swap(ptr, oldValue, newValue);
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
#endif // GRAPHIC_LITE_HAL_ATOMIC_H
|
||||
Executable
+54
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef GRAPHIC_LITE_HAL_CPU_H
|
||||
#define GRAPHIC_LITE_HAL_CPU_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
#define BARRIER() MemoryBarrier()
|
||||
#define MB() BARRIER()
|
||||
#define WMB() BARRIER()
|
||||
#define RMB() BARRIER()
|
||||
#elif defined __linux__ || defined __LITEOS__ || defined __APPLE__
|
||||
#define DSB() __asm__ volatile("dsb" ::: "memory")
|
||||
#define DMB() __asm__ volatile("dmb" ::: "memory")
|
||||
#define ISB() __asm__ volatile("isb" ::: "memory")
|
||||
#define BARRIER() __asm__ volatile("" ::: "memory")
|
||||
|
||||
#define MB() DMB()
|
||||
#define WMB() DMB()
|
||||
#define RMB() DMB()
|
||||
#else
|
||||
#define MB()
|
||||
#define WMB()
|
||||
#define RMB()
|
||||
#endif
|
||||
|
||||
uint32_t HalGetCpuCoreNum();
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cpluscplus */
|
||||
#endif /* __cpluscplus */
|
||||
#endif // GRAPHIC_LITE_HAL_CPU_H
|
||||
Executable
+63
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef GRAPHIC_LITE_HAL_TICK_H
|
||||
#define GRAPHIC_LITE_HAL_TICK_H
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
#include "heap_base.h"
|
||||
|
||||
namespace OHOS {
|
||||
/** @brief Class for calculate the time. */
|
||||
class HALTick : public HeapBase {
|
||||
public:
|
||||
/**
|
||||
* Gets the instance
|
||||
*
|
||||
* @returns The instance.
|
||||
*/
|
||||
static HALTick& GetInstance()
|
||||
{
|
||||
static HALTick instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the milliseconds since start up
|
||||
*
|
||||
* @returns The elapsed time.
|
||||
*/
|
||||
uint32_t GetTime();
|
||||
|
||||
/**
|
||||
* Gets elapse milliseconds since the startTime
|
||||
*
|
||||
* @param startTime The start time.
|
||||
*
|
||||
* @returns The elapse time.
|
||||
*/
|
||||
uint32_t GetElapseTime(uint32_t startTime);
|
||||
|
||||
private:
|
||||
/** Default constructor */
|
||||
HALTick() {}
|
||||
/** Destructor */
|
||||
~HALTick() {}
|
||||
static constexpr uint32_t MILLISEC_TO_NANOSEC = 1000000;
|
||||
static constexpr uint16_t SEC_TO_MILLISEC = 1000;
|
||||
};
|
||||
} // namespace OHOS
|
||||
#endif // GRAPHIC_LITE_HAL_TICK_H
|
||||
Executable
+53
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef GRAPHIC_LITE_GFX_ENGINES_H
|
||||
#define GRAPHIC_LITE_GFX_ENGINES_H
|
||||
|
||||
#include "color.h"
|
||||
#include "lite_wm_type.h"
|
||||
#include "display_gfx.h"
|
||||
#include "display_type.h"
|
||||
#include "geometry2d.h"
|
||||
|
||||
namespace OHOS {
|
||||
class GfxEngines {
|
||||
public:
|
||||
static GfxEngines* GetInstance()
|
||||
{
|
||||
static GfxEngines instance;
|
||||
return &instance;
|
||||
}
|
||||
|
||||
bool InitDriver();
|
||||
void CloseDriver();
|
||||
|
||||
bool GfxFillArea(const LiteSurfaceData& dstSurfaceData,
|
||||
const Rect& fillArea,
|
||||
const ColorType& color,
|
||||
const OpacityType& opa);
|
||||
|
||||
bool GfxBlit(const LiteSurfaceData& srcSurfaceData,
|
||||
const Rect& srcRect,
|
||||
const LiteSurfaceData& dstSurfaceData,
|
||||
int16_t x,
|
||||
int16_t y);
|
||||
private:
|
||||
GfxEngines() : gfxFuncs_(nullptr) {}
|
||||
virtual ~GfxEngines() {}
|
||||
GfxFuncs* gfxFuncs_;
|
||||
};
|
||||
} // namespace OHOS
|
||||
#endif
|
||||
Executable
+55
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef GRAPHIC_LITE_HI_FBDEV_H
|
||||
#define GRAPHIC_LITE_HI_FBDEV_H
|
||||
|
||||
#include "lite_wm_type.h"
|
||||
|
||||
namespace OHOS {
|
||||
enum LayerRotateType {
|
||||
LAYER_ROTATE_NONE = 0, /**< No rotation */
|
||||
LAYER_ROTATE_90, /**< Rotation by 90 degrees */
|
||||
LAYER_ROTATE_180, /**< Rotation by 180 degrees */
|
||||
LAYER_ROTATE_270, /**< Rotation by 270 degrees */
|
||||
LAYER_ROTATE_BUTT /**< Invalid operation */
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Get dev surface data.
|
||||
*/
|
||||
LiteSurfaceData* GetDevSurfaceData();
|
||||
|
||||
/**
|
||||
* @brief Get layer rotate type.
|
||||
*/
|
||||
LayerRotateType GetLayerRotateType();
|
||||
|
||||
/**
|
||||
* @brief Initialize fbdev.
|
||||
*/
|
||||
void HiFbdevInit(void);
|
||||
|
||||
/**
|
||||
* @brief Close fbdev.
|
||||
*/
|
||||
void HiFbdevClose();
|
||||
|
||||
/**
|
||||
* @brief flush
|
||||
*/
|
||||
void LcdFlush();
|
||||
} // namespace OHOS
|
||||
#endif // GRAPHIC_LITE_HI_FBDEV_H
|
||||
Executable
+330
@@ -0,0 +1,330 @@
|
||||
/*
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef GRAPHIC_LITE_QUEUE_H
|
||||
#define GRAPHIC_LITE_QUEUE_H
|
||||
|
||||
#include "securec.h"
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "graphic_thread.h"
|
||||
#include "hal_cpu.h"
|
||||
#include "hal_atomic.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#endif
|
||||
|
||||
typedef enum {
|
||||
QUEUE_INVAL = -10,
|
||||
QUEUE_FULL,
|
||||
QUEUE_EMPTY
|
||||
} QueueError;
|
||||
|
||||
/** @brief Lock free ring queue */
|
||||
typedef struct {
|
||||
uint32_t magic;
|
||||
uint32_t unitNum; /* queue node limit */
|
||||
uint8_t pad[56]; /* cache line pad */
|
||||
|
||||
/* producer status */
|
||||
struct {
|
||||
uint32_t size; /* queue size */
|
||||
uint32_t mask; /* mask(size-1). */
|
||||
volatile uint32_t head; /* producer head */
|
||||
volatile uint32_t tail; /* producer tail */
|
||||
uint8_t pad[48]; /* cache line pad */
|
||||
} producer;
|
||||
|
||||
/* consumer status */
|
||||
struct {
|
||||
uint32_t size; /* queue size */
|
||||
uint32_t mask; /* mask(size-1). */
|
||||
volatile uint32_t head; /* consumer head */
|
||||
volatile uint32_t tail; /* consumer tail */
|
||||
uint8_t pad[48]; /* cache line pad */
|
||||
} consumer;
|
||||
|
||||
uintptr_t nodes[0]; /* queue nodes */
|
||||
} LockFreeQueue;
|
||||
|
||||
extern int32_t QueueSizeCalc(uint32_t unitNum, uint32_t* queueSize);
|
||||
|
||||
extern int32_t QueueCountGet(const LockFreeQueue* queue, uint32_t* count);
|
||||
|
||||
extern int32_t QueueInit(LockFreeQueue* queue, uint32_t unitNum);
|
||||
|
||||
static inline int32_t QueueIsEmpty(LockFreeQueue* queue)
|
||||
{
|
||||
uint32_t producerTail;
|
||||
uint32_t consumerTail;
|
||||
uint32_t mask;
|
||||
|
||||
if (queue == NULL) {
|
||||
return QUEUE_INVAL;
|
||||
}
|
||||
|
||||
producerTail = queue->producer.tail;
|
||||
consumerTail = queue->consumer.tail;
|
||||
mask = queue->producer.mask;
|
||||
|
||||
if (((producerTail - consumerTail) & mask) == 0) {
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/** @brief Enqueue operation, thread unsafe */
|
||||
static inline int32_t QueueSingleProducerEnqueue(LockFreeQueue *queue, void *node)
|
||||
{
|
||||
uint32_t producerHead;
|
||||
uint32_t producerNext;
|
||||
uint32_t consumerTail;
|
||||
uint32_t availableCount;
|
||||
uint32_t mask;
|
||||
|
||||
if (queue == NULL || node == NULL) {
|
||||
return QUEUE_INVAL;
|
||||
}
|
||||
mask = queue->producer.mask;
|
||||
|
||||
producerHead = queue->producer.head;
|
||||
RMB();
|
||||
consumerTail = queue->consumer.tail;
|
||||
|
||||
/*
|
||||
* 1. In normal cases, producerHead > consumerTail and producerHead < consumerTail + mask
|
||||
* 2. If only producerHead is reversed, producerHead > consumerTail - 0xFFFFFFFF and
|
||||
* producerHead < consumerTail + mask - 0xFFFFFFFF
|
||||
* The subtraction of two 32-bit integers results in 32-bit modulo.
|
||||
* Therefore, the availableCount must be between 0 and the queue length.
|
||||
*/
|
||||
availableCount = (mask + consumerTail) - producerHead;
|
||||
|
||||
if (availableCount < 1) {
|
||||
return QUEUE_FULL;
|
||||
}
|
||||
|
||||
producerNext = producerHead + 1;
|
||||
queue->producer.head = producerNext;
|
||||
|
||||
queue->nodes[producerHead & mask] = (uintptr_t)node;
|
||||
|
||||
/*
|
||||
* Make sure that the queue is filled with elements before updating the producer tail.
|
||||
* Prevents problems when the producer tail is updated first:
|
||||
* 1. The consumer thinks that the elements in this area have been queued and can be consumed,
|
||||
* but the consumer actually reads dirty elements.
|
||||
* 2. The process is abnormal. In this case, elements in the memory block in the queue are dirty elements.
|
||||
*/
|
||||
WMB();
|
||||
|
||||
queue->producer.tail = producerNext;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** @brief Enqueue operation, thread safe */
|
||||
static inline uint32_t QueueMultiProducerEnqueue(LockFreeQueue* queue, void* node)
|
||||
{
|
||||
uint32_t producerHead;
|
||||
uint32_t producerNext;
|
||||
uint32_t consumerTail;
|
||||
uint32_t availableCount;
|
||||
bool success = false;
|
||||
uint32_t mask;
|
||||
|
||||
if (queue == NULL || node == NULL) {
|
||||
return QUEUE_INVAL;
|
||||
}
|
||||
|
||||
mask = queue->producer.mask;
|
||||
do {
|
||||
producerHead = queue->producer.head;
|
||||
/*
|
||||
* Make sure the producer's head is read before the consumer's tail.
|
||||
* If the consumer tail is read first, then the consumer consumes the queue,and then other producers
|
||||
* produce the queue, the producer header may cross the consumer tail reversely.
|
||||
*/
|
||||
RMB();
|
||||
consumerTail = queue->consumer.tail;
|
||||
|
||||
/*
|
||||
* 1. In normal cases, producerHead > consumerTail and producerHead < consumerTail + mask
|
||||
* 2. If only producerHead is reversed, producerHead > consumerTail - 0xFFFFFFFF and
|
||||
* producerHead < consumerTail + mask - 0xFFFFFFFF
|
||||
* The subtraction of two 32-bit integers results in 32-bit modulo.
|
||||
* Therefore, the availableCount must be between 0 and the queue length.
|
||||
*/
|
||||
|
||||
availableCount = (mask + consumerTail) - producerHead;
|
||||
|
||||
if (availableCount < 1) {
|
||||
return QUEUE_FULL;
|
||||
}
|
||||
|
||||
producerNext = producerHead + 1;
|
||||
success = HalAtomicCmpAndSwap32(&queue->producer.head, producerHead, producerNext);
|
||||
} while (success == false);
|
||||
|
||||
queue->nodes[producerHead & mask] = (uintptr_t)node;
|
||||
|
||||
/*
|
||||
* Make sure that the queue is filled with elements before updating the producer tail.
|
||||
* Prevents problems when the producer tail is updated first:
|
||||
* 1. The consumer thinks that the elements in this area have been queued and can be consumed,
|
||||
* but the consumer actually reads dirty elements.
|
||||
* 2. The process is abnormal. In this case, elements in the memory block in the queue are dirty elements.
|
||||
*/
|
||||
|
||||
WMB();
|
||||
|
||||
/* Waiting for other producers to complete enqueuing. */
|
||||
while (queue->producer.tail != producerHead) {
|
||||
ThreadYield();
|
||||
}
|
||||
|
||||
queue->producer.tail += 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** @brief Dequeue operation, thread unsafe */
|
||||
static inline uint32_t QueueSingleConsumerDequeue(LockFreeQueue* queue, void** node)
|
||||
{
|
||||
uint32_t consumerHead;
|
||||
uint32_t producerTail;
|
||||
uint32_t consumerNext;
|
||||
uint32_t availableCount;
|
||||
uint32_t mask;
|
||||
|
||||
if (queue == NULL || node == NULL) {
|
||||
return QUEUE_INVAL;
|
||||
}
|
||||
mask = queue->producer.mask;
|
||||
|
||||
consumerHead = queue->consumer.head;
|
||||
|
||||
/* Prevent producerTail from being read before consumerHead, causing queue head and tail reversal. */
|
||||
RMB();
|
||||
|
||||
producerTail = queue->producer.tail;
|
||||
|
||||
/*
|
||||
* 1. In normal cases, producerTail > consumerHead and producerTail < consumerHead + mask
|
||||
* 2. If only producerTail is reversed, producerTail > consumerHead - 0xFFFFFFFF and
|
||||
* producerTail < consumerHead + mask - 0xFFFFFFFF
|
||||
* The subtraction of two 32-bit integers results in 32-bit modulo.
|
||||
* Therefore, the availableCount must be between 0 and the queue length.
|
||||
*/
|
||||
availableCount = (producerTail - consumerHead);
|
||||
|
||||
if (availableCount < 1) {
|
||||
return QUEUE_EMPTY;
|
||||
}
|
||||
|
||||
consumerNext = consumerHead + 1;
|
||||
queue->consumer.head = consumerNext;
|
||||
|
||||
/* Prevent the read of queue->nodes before the read of ProdTail. */
|
||||
RMB();
|
||||
|
||||
*node = (void *)(queue->nodes[consumerHead & mask]);
|
||||
|
||||
/*
|
||||
* Ensure that the queue element is dequeued before updating the consumer's tail.
|
||||
* After the consumer tail is updated, the producer considers that the elements in this area have been dequeued
|
||||
* and can fill in new elements, which actually overwrites the elements that are not dequeued.
|
||||
*/
|
||||
RMB();
|
||||
|
||||
queue->consumer.tail = consumerNext;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** @brief Dequeue operation, thread safe */
|
||||
static inline uint32_t QueueMultiConsumerDequeue(LockFreeQueue *queue, void **node)
|
||||
{
|
||||
bool success = false;
|
||||
uint32_t consumerHead;
|
||||
uint32_t producerTail;
|
||||
uint32_t consumerNext;
|
||||
uint32_t availableCount;
|
||||
uint32_t mask;
|
||||
|
||||
if (queue == NULL || node == NULL) {
|
||||
return QUEUE_INVAL;
|
||||
}
|
||||
mask = queue->producer.mask;
|
||||
|
||||
do {
|
||||
consumerHead = queue->consumer.head;
|
||||
|
||||
/*
|
||||
* Make sure the consumer's head is read before the producer's tail.
|
||||
* If the producer tail is read first, then other consumers consume the queue,
|
||||
* and finally the generator produces the queue, the consumer head may cross the producer tail.
|
||||
*/
|
||||
RMB();
|
||||
|
||||
producerTail = queue->producer.tail;
|
||||
|
||||
/*
|
||||
* 1. In normal cases, producerTail > consumerHead and producerTail < consumerHead + mask
|
||||
* 2. If only producerTail is reversed, producerTail > consumerHead - 0xFFFFFFFF and
|
||||
* producerTail < consumerHead + mask - 0xFFFFFFFF
|
||||
* The subtraction of two 32-bit integers results in 32-bit modulo.
|
||||
* Therefore, the availableCount must be between 0 and the queue length.
|
||||
*/
|
||||
|
||||
availableCount = (producerTail - consumerHead);
|
||||
|
||||
if (availableCount < 1) {
|
||||
return QUEUE_EMPTY;
|
||||
}
|
||||
|
||||
consumerNext = consumerHead + 1;
|
||||
success = HalAtomicCmpAndSwap32(&queue->consumer.head, consumerHead, consumerNext);
|
||||
} while (success == false);
|
||||
|
||||
/* Prevent the read of queue->nodes before the read of ProdTail. */
|
||||
RMB();
|
||||
|
||||
*node = (void *)(queue->nodes[consumerHead & mask]);
|
||||
|
||||
/*
|
||||
* Ensure that the queue element is dequeued before updating the consumer's tail.
|
||||
* After the consumer tail is updated, the producer considers that the elements in this area have been dequeued
|
||||
* and can fill in new elements, which actually overwrites the elements that are not dequeued.
|
||||
*/
|
||||
RMB();
|
||||
|
||||
/* Waiting for other consumers to finish dequeuing. */
|
||||
while (queue->consumer.tail != consumerHead) {
|
||||
ThreadYield();
|
||||
}
|
||||
|
||||
queue->consumer.tail += 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cpluscplus */
|
||||
#endif /* __cpluscplus */
|
||||
#endif // GRAPHIC_LITE_QUEUE_H
|
||||
Executable
+437
@@ -0,0 +1,437 @@
|
||||
/*
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup UI_Utils
|
||||
* @{
|
||||
*
|
||||
* @brief Defines basic UI utils.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file color.h
|
||||
*
|
||||
* @brief Defines color attributes for the graphics system and implements common color functions.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
#ifndef GRAPHIC_LITE_COLOR_H
|
||||
#define GRAPHIC_LITE_COLOR_H
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
#include "graphic_config.h"
|
||||
#include "heap_base.h"
|
||||
|
||||
namespace OHOS {
|
||||
/**
|
||||
* @brief Defines the color attribute when the color depth is <b>16</b>.
|
||||
*/
|
||||
typedef union {
|
||||
struct {
|
||||
/** Blue */
|
||||
uint16_t blue : 5;
|
||||
/** Green */
|
||||
uint16_t green : 6;
|
||||
/** Red */
|
||||
uint16_t red : 5;
|
||||
};
|
||||
/** Full RGB data */
|
||||
uint16_t full;
|
||||
} Color16;
|
||||
|
||||
/**
|
||||
* @brief Defines the color attribute when the color depth is <b>24</b>.
|
||||
*/
|
||||
struct Color24 {
|
||||
/** Blue */
|
||||
uint8_t blue;
|
||||
/** Green */
|
||||
uint8_t green;
|
||||
/** Red */
|
||||
uint8_t red;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Defines the color attribute when the color depth is <b>32</b>.
|
||||
*/
|
||||
typedef union {
|
||||
struct {
|
||||
/** Blue */
|
||||
uint8_t blue;
|
||||
/** Green */
|
||||
uint8_t green;
|
||||
/** Red */
|
||||
uint8_t red;
|
||||
/** Alpha (how opaque each pixel is) */
|
||||
uint8_t alpha;
|
||||
};
|
||||
/** Full RGB data */
|
||||
uint32_t full;
|
||||
} Color32;
|
||||
|
||||
#if COLOR_DEPTH == 16
|
||||
typedef Color16 ColorType;
|
||||
#elif COLOR_DEPTH == 32
|
||||
typedef Color32 ColorType;
|
||||
#else
|
||||
#error "Invalid COLOR_DEPTH, Set it to 16 or 32!"
|
||||
#endif
|
||||
|
||||
using OpacityType = uint8_t;
|
||||
|
||||
/**
|
||||
* @brief Enumerates opacity values.
|
||||
*/
|
||||
enum {
|
||||
/** The opacity is 0. */
|
||||
OPA_TRANSPARENT = 0,
|
||||
/** The opacity is 100%. */
|
||||
OPA_OPAQUE = 255,
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Converts colors in different formats and defines common colors.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
class Color : public HeapBase {
|
||||
public:
|
||||
/**
|
||||
* @brief Mixes two colors (color 1 and color 2) based on a specified opacity.
|
||||
*
|
||||
* @param c1 Indicates color 1.
|
||||
* @param c2 Indicates color 2.
|
||||
* @param mix Indicates the alpha, that is, how opaque each pixel is.
|
||||
|
||||
* @return Returns the color data after mixing.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
static ColorType GetMixColor(ColorType c1, ColorType c2, uint8_t mix)
|
||||
{
|
||||
ColorType ret;
|
||||
/* COLOR_DEPTH is 16 or 32 */
|
||||
// 8: right move 8 bit. 255: 2^8-1
|
||||
ret.red = (static_cast<uint16_t>(c1.red) * mix + (static_cast<uint16_t>(c2.red) * (255 ^ mix))) >> 8;
|
||||
// 8: right move 8 bit. 255: 2^8-1
|
||||
ret.green = (static_cast<uint16_t>(c1.green) * mix + (static_cast<uint16_t>(c2.green) * (255 ^ mix))) >> 8;
|
||||
// 8: right move 8 bit. 255: 2^8-1
|
||||
ret.blue = (static_cast<uint16_t>(c1.blue) * mix + (static_cast<uint16_t>(c2.blue) * (255 ^ mix))) >> 8;
|
||||
#if COLOR_DEPTH == 32
|
||||
ret.alpha = 0xFF;
|
||||
#endif
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Obtains the color based on the RGB color value.
|
||||
*
|
||||
* @param r8 Indicates the intensity of red.
|
||||
* @param g8 Indicates the intensity of green.
|
||||
* @param b8 Indicates the intensity of blue.
|
||||
*
|
||||
* @return Returns the color data generated.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
static ColorType GetColorFromRGB(uint8_t r8, uint8_t g8, uint8_t b8)
|
||||
{
|
||||
return GetColorFromRGBA(r8, g8, b8, 0xFF);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Obtains the color based on the RGBA color value.
|
||||
*
|
||||
* @param r8 Indicates the intensity of red.
|
||||
* @param g8 Indicates the intensity of green.
|
||||
* @param b8 Indicates the intensity of blue.
|
||||
* @param alpha Indicates the alpha, that is, how opaque each pixel is.
|
||||
*
|
||||
* @return Returns the color data generated.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
static ColorType GetColorFromRGBA(uint8_t r8, uint8_t g8, uint8_t b8, uint8_t alpha)
|
||||
{
|
||||
ColorType rColor;
|
||||
#if COLOR_DEPTH == 16
|
||||
rColor.red = r8 >> 3; // 3: shift right 3 places
|
||||
rColor.blue = b8 >> 3; // 3: shift right 3 places
|
||||
rColor.green = g8 >> 2; // 2: shift right 2 places
|
||||
#elif COLOR_DEPTH == 32
|
||||
// 24, 16, 8: shift right places
|
||||
rColor.full = (alpha << 24) | (r8 << 16) | (g8 << 8) | (b8);
|
||||
#endif
|
||||
return rColor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Converts color data into the RGBA8888 format.
|
||||
*
|
||||
* The color data definition varies according to the color depth.
|
||||
*
|
||||
* @param color Indicates the color data, which is defined by {@link ColorType}.
|
||||
* @return Returns the RGBA8888 color data.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
static uint32_t ColorTo32(ColorType color);
|
||||
|
||||
/**
|
||||
* @brief Converts color data with the 16-bit color depth into the RGBA8888 format.
|
||||
*
|
||||
* @param color Indicates the color data with the 16-bit color depth, which is defined by {@link Color16}.
|
||||
* @param alpha Indicates the alpha, that is, how opaque each pixel is.
|
||||
* @return Returns the RGBA8888 color data.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
static uint32_t ColorTo32(Color16 color, uint8_t alpha);
|
||||
|
||||
/**
|
||||
* @brief Converts color data from the RGBA8888 format into the RGB565 format.
|
||||
*
|
||||
* @param color Indicates the color data with the 32-bit color depth, which is defined by {@link Color32}.
|
||||
* @return Returns the RGB565 color data.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
static uint16_t ColorTo16(Color32 color);
|
||||
|
||||
/**
|
||||
* @brief Obtains the color data of white.
|
||||
*
|
||||
* @return Returns the color data.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
static ColorType White()
|
||||
{
|
||||
return GetColorFromRGB(0xFF, 0xFF, 0xFF);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Obtains the color data of silver.
|
||||
*
|
||||
* @return Returns the color data.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
static ColorType Silver()
|
||||
{
|
||||
return GetColorFromRGB(0xC0, 0xC0, 0xC0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Obtains the color data of gray.
|
||||
*
|
||||
* @return Returns the color data.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
static ColorType Gray()
|
||||
{
|
||||
return GetColorFromRGB(0x80, 0x80, 0x80);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Obtains the color data of black.
|
||||
*
|
||||
* @return Returns the color data.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
static ColorType Black()
|
||||
{
|
||||
return GetColorFromRGB(0x00, 0x00, 0x00);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Obtains the color data of red.
|
||||
*
|
||||
* @return Returns the color data.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
static ColorType Red()
|
||||
{
|
||||
return GetColorFromRGB(0xFF, 0x00, 0x00);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Obtains the color data of maroon.
|
||||
*
|
||||
* @return Returns the color data.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
static ColorType Maroon()
|
||||
{
|
||||
return GetColorFromRGB(0x80, 0x00, 0x00);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Obtains the color data of yellow.
|
||||
*
|
||||
* @return Returns the color data.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
static ColorType Yellow()
|
||||
{
|
||||
return GetColorFromRGB(0xFF, 0xFF, 0x00);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Obtains the color data of olive.
|
||||
*
|
||||
* @return Returns the color data.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
static ColorType Olive()
|
||||
{
|
||||
return GetColorFromRGB(0x80, 0x80, 0x00);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Obtains the color data of lime.
|
||||
*
|
||||
* @return Returns the color data.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
static ColorType Lime()
|
||||
{
|
||||
return GetColorFromRGB(0x00, 0xFF, 0x00);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Obtains the color data of green.
|
||||
*
|
||||
* @return Returns the color data.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
static ColorType Green()
|
||||
{
|
||||
return GetColorFromRGB(0x00, 0xFF, 0x00);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Obtains the color data of cyan.
|
||||
*
|
||||
* @return Returns the color data.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
static ColorType Cyan()
|
||||
{
|
||||
return GetColorFromRGB(0x00, 0xFF, 0xFF);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Obtains the color data of aqua.
|
||||
*
|
||||
* @return Returns the color data.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
static ColorType Aqua()
|
||||
{
|
||||
return GetColorFromRGB(0x00, 0xFF, 0xFF);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Obtains the color data of teal.
|
||||
*
|
||||
* @return Returns the color data.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
static ColorType Teal()
|
||||
{
|
||||
return GetColorFromRGB(0x00, 0x80, 0x80);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Obtains the color data of blue.
|
||||
*
|
||||
* @return Returns the color data.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
static ColorType Blue()
|
||||
{
|
||||
return GetColorFromRGB(0x00, 0x00, 0xFF);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Obtains the color data of navy.
|
||||
*
|
||||
* @return Returns the color data.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
static ColorType Navy()
|
||||
{
|
||||
return GetColorFromRGB(0x00, 0x00, 0x80);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Obtains the color data of magenta.
|
||||
*
|
||||
* @return Returns the color data.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
static ColorType Magenta()
|
||||
{
|
||||
return GetColorFromRGB(0xFF, 0x00, 0xFF);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Obtains the color data of purple.
|
||||
*
|
||||
* @return Returns the color data.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
static ColorType Purple()
|
||||
{
|
||||
return GetColorFromRGB(0x80, 0x00, 0x80);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Obtains the color data of orange.
|
||||
*
|
||||
* @return Returns the color data.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
static ColorType Orange()
|
||||
{
|
||||
return GetColorFromRGB(0xFF, 0xA5, 0x00);
|
||||
}
|
||||
};
|
||||
} // namespace OHOS
|
||||
#endif // GRAPHIC_LITE_COLOR_H
|
||||
Executable
+41
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef GRAPHIC_LITE_FILE_H
|
||||
#define GRAPHIC_LITE_FILE_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <io.h>
|
||||
#else
|
||||
#include "stdint.h"
|
||||
#include "fcntl.h"
|
||||
#include "unistd.h"
|
||||
#include "sys/mount.h"
|
||||
#include "sys/stat.h"
|
||||
#ifdef __APPLE__
|
||||
#include "sys/param.h"
|
||||
#else
|
||||
#include "sys/statfs.h"
|
||||
#endif
|
||||
#include "dirent.h"
|
||||
#include "stdio.h"
|
||||
#include "errno.h"
|
||||
#endif
|
||||
|
||||
#define DEFAULT_FILE_PERMISSION 0666 // default file permission when creat file
|
||||
#endif // GRAPHIC_LITE_FILE_H
|
||||
Executable
+309
@@ -0,0 +1,309 @@
|
||||
/*
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup UI_Utils
|
||||
* @{
|
||||
*
|
||||
* @brief Defines basic UI utils.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file geometry2d.h
|
||||
*
|
||||
* @brief Defines attributes of 2D geometries (including points, lines, rectangles, and polygons) of the lightweight
|
||||
* graphics system and provides functions for performing operations on the geometries.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
#ifndef GRAPHIC_LITE_GEOMETRY2D_H
|
||||
#define GRAPHIC_LITE_GEOMETRY2D_H
|
||||
|
||||
#include "graphic_assert.h"
|
||||
#include "graphic_math.h"
|
||||
#include "graphic_types.h"
|
||||
#include "heap_base.h"
|
||||
#include "rect.h"
|
||||
#include <string.h>
|
||||
|
||||
namespace OHOS {
|
||||
/**
|
||||
* @brief Defines a line, which consists of the start and end points.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
class Line : public HeapBase {
|
||||
public:
|
||||
/**
|
||||
* @brief The default constructor used to create a <b>Line</b> instance.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
Line() {}
|
||||
|
||||
/**
|
||||
* @brief A constructor used to create a <b>Line</b> instance.
|
||||
* @param a Indicates the start point of the line.
|
||||
* @param b Indicates the end point of the line.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
Line(const Vector2<int16_t>& a, const Vector2<int16_t>& b)
|
||||
{
|
||||
vertex_[0] = a;
|
||||
vertex_[1] = b;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief A constructor used to create a <b>Line</b> instance.
|
||||
* @param x1 Indicates the X coordinate of the line's start point.
|
||||
* @param y1 Indicates the Y coordinate of the line's start point.
|
||||
* @param x2 Indicates the X coordinate of the line's end point.
|
||||
* @param y2 Indicates the Y coordinate of the line's end point.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
Line(int16_t x1, int16_t y1, int16_t x2, int16_t y2)
|
||||
{
|
||||
vertex_[0].x_ = x1;
|
||||
vertex_[0].y_ = y1;
|
||||
vertex_[1].x_ = x2;
|
||||
vertex_[1].y_ = y2;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief A destructor used to delete the <b>Line</b> instance.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
~Line() {}
|
||||
|
||||
/**
|
||||
* @brief Obtains the start or end point of the line based on the value of <b>index</b>.
|
||||
* @param index Indicates the start or end point to obtain. The value <b>0</b> indicates that the start point is to
|
||||
* be obtained, and <b>1</b> indicates that the end point is to be obtained.
|
||||
* @return Returns the start or end point of the line.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
Vector2<int16_t>& operator[](uint8_t index)
|
||||
{
|
||||
return vertex_[index];
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Obtains the start or end point of the line based on the value of <b>index</b>.
|
||||
* @param index Indicates the start or end point to obtain. The value <b>0</b> indicates that the start point is to
|
||||
* be obtained, and <b>1</b> indicates that the end point is to be obtained.
|
||||
* @return Returns the start or end point of the line.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
const Vector2<int16_t> operator[](uint8_t index) const
|
||||
{
|
||||
return vertex_[index];
|
||||
}
|
||||
|
||||
protected:
|
||||
Vector2<int16_t> vertex_[2]; /* 2: two vertexes of the line */
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Defines a polygon, including vertex coordinates and the maximum number of vertices
|
||||
* (defined by {@link MAX_VERTEX_NUM}).
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
class Polygon : public HeapBase {
|
||||
public:
|
||||
/**
|
||||
* @brief The default constructor used to create a <b>Polygon</b> instance.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
Polygon() : vertexNum_(0) {}
|
||||
|
||||
/**
|
||||
* @brief A constructor used to construct a <b>Polygon</b> instance based on a rectangle.
|
||||
*
|
||||
* @param rect Indicates the rectangle used to construct the polygon.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
explicit Polygon(const Rect& rect)
|
||||
{
|
||||
vertexNum_ = 4; // 4: number of vertex
|
||||
vertexes_[0].x_ = rect.GetLeft();
|
||||
vertexes_[0].y_ = rect.GetTop();
|
||||
|
||||
vertexes_[1].x_ = rect.GetRight();
|
||||
vertexes_[1].y_ = rect.GetTop();
|
||||
|
||||
vertexes_[2].x_ = rect.GetRight();
|
||||
vertexes_[2].y_ = rect.GetBottom();
|
||||
|
||||
vertexes_[3].x_ = rect.GetLeft();
|
||||
vertexes_[3].y_ = rect.GetBottom();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief A constructor used to create a <b>Polygon</b> instance based on the vertex coordinates and the number of
|
||||
* coordinates.
|
||||
*
|
||||
* The number of vertex coordinates cannot exceed the value of {@link MAX_VERTEX_NUM}.
|
||||
*
|
||||
* @param vertexes Indicates the pointer to the vertex coordinates.
|
||||
* @param vertexNum Indicates the number of vertices.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
Polygon(const Vector2<int16_t>* vertexes, const uint8_t vertexNum);
|
||||
|
||||
/**
|
||||
* @brief A destructor used to delete the <b>Polygon</b> instance.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
~Polygon() {}
|
||||
|
||||
/**
|
||||
* @brief Obtains the minimum rectangle that can contain the polygon. All vertices of the polygon are inside this
|
||||
* rectangle.
|
||||
*
|
||||
* @return Returns the minimum rectangle that contains the polygon.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
Rect MakeAABB() const;
|
||||
|
||||
/**
|
||||
* @brief Obtains the number of vertices of the polygon.
|
||||
*
|
||||
* @return Returns the number of vertices.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
uint8_t GetVertexNum() const
|
||||
{
|
||||
return vertexNum_;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Sets the number of vertices of a polygon.
|
||||
* @param vertexNum Indicates the number of vertices.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
void SetVertexNum(uint8_t vertexNum)
|
||||
{
|
||||
vertexNum_ = vertexNum;
|
||||
}
|
||||
|
||||
const Vector2<int16_t> operator[](uint8_t index) const
|
||||
{
|
||||
return vertexes_[index];
|
||||
}
|
||||
|
||||
Vector2<int16_t>& operator[](uint8_t index)
|
||||
{
|
||||
ASSERT(index < MAX_VERTEX_NUM);
|
||||
return vertexes_[index];
|
||||
}
|
||||
|
||||
Polygon& operator=(const Rect& rect)
|
||||
{
|
||||
/* clockwise */
|
||||
vertexNum_ = 4; // 4: number of vertex
|
||||
vertexes_[0].x_ = rect.GetLeft();
|
||||
vertexes_[0].y_ = rect.GetTop();
|
||||
|
||||
vertexes_[1].x_ = rect.GetRight();
|
||||
vertexes_[1].y_ = rect.GetTop();
|
||||
|
||||
vertexes_[2].x_ = rect.GetRight();
|
||||
vertexes_[2].y_ = rect.GetBottom();
|
||||
|
||||
vertexes_[3].x_ = rect.GetLeft();
|
||||
vertexes_[3].y_ = rect.GetBottom();
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
/** Maximum number of vertices in a polygon */
|
||||
static const uint8_t MAX_VERTEX_NUM = 8;
|
||||
|
||||
protected:
|
||||
Vector2<int16_t> vertexes_[MAX_VERTEX_NUM]; /* the vertexes of polygon */
|
||||
uint8_t vertexNum_; /* the vertex num of polygon */
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Checks whether line segment a and line segment b intersect, and returns the intersection point (if available).
|
||||
* @param a Indicates line segment a.
|
||||
* @param b Indicates line segment b.
|
||||
* @param out Indicates the intersection point.
|
||||
* @return Returns <b>true</b> if the two line segments intersect; returns <b>false</b> otherwise.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
bool Intersect(const Line& a, const Line& b, Vector2<int16_t>& out);
|
||||
|
||||
/**
|
||||
* @brief Chekcs whether line segment a and line segment b intersect.
|
||||
* @param a Indicates line segment a.
|
||||
* @param b Indicates line segment b.
|
||||
* @return Returns <b>true</b> if the two line segments intersect; returns <b>false</b> otherwise.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
bool IsIntersect(const Line& a, const Line& b);
|
||||
|
||||
/**
|
||||
* @brief Clips a polygon by using a line segment.
|
||||
* @param poly Indicates the polygon to clip.
|
||||
* @param line Indicates the line segment used for clipping.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
void Clip(Polygon& poly, const Line& line);
|
||||
|
||||
/**
|
||||
* @brief Implements Sutherland-Hodgman, an algorithm used for clipping polygons.
|
||||
* @param clipRect Indicates the rectangle used for clipping the polygon.
|
||||
* @param polygon Indicates the polygon to clip.
|
||||
* @return Returns the polygon after clipping.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
Polygon SuthHodgClip(const Rect& clipRect, const Polygon& polygon);
|
||||
|
||||
/**
|
||||
* @brief Clips a polygon by using a line segment and obtains the intersections.
|
||||
* @param line Indicates the line segment used for clipping.
|
||||
* @param poly Indicates the polygon to clip.
|
||||
* @param pOut Indicates the pointer to the intersections.
|
||||
* @param pNum Indicates the pointer to the number of the intersections.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
void Clip(const Line& line, const Polygon& poly, Vector2<int16_t>* pOut, uint8_t* pNum);
|
||||
} // namespace OHOS
|
||||
#endif // GRAPHIC_LITE_GEOMETRY2D_H
|
||||
Executable
+49
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup UI_Utils
|
||||
* @{
|
||||
*
|
||||
* @brief Defines basic UI utils.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file graphic_assert.h
|
||||
*
|
||||
* @brief Declares the assertion utility for the graphics module.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
#ifndef GRAPHIC_LITE_GRAPHIC_ASSERT_H
|
||||
#define GRAPHIC_LITE_GRAPHIC_ASSERT_H
|
||||
|
||||
#if ENABLE_DEBUG
|
||||
#include <assert.h>
|
||||
#endif
|
||||
|
||||
namespace OHOS {
|
||||
#if ENABLE_DEBUG
|
||||
#define ASSERT(cond) assert(cond)
|
||||
#else
|
||||
#define ASSERT(cond)
|
||||
#endif
|
||||
} // namespace OHOS
|
||||
#endif // GRAPHIC_LITE_GRAPHIC_ASSERT_H
|
||||
Executable
+101
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef GRAPHIC_LITE_GRAPHIC_LOG_H
|
||||
#define GRAPHIC_LITE_GRAPHIC_LOG_H
|
||||
|
||||
#include "graphic_config.h"
|
||||
#if ENABLE_GRAPHIC_LOG
|
||||
#ifdef __LITEOS__
|
||||
#include <cstring>
|
||||
#include "hilog/log.h"
|
||||
#elif defined _WIN32
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
namespace OHOS {
|
||||
#if ENABLE_GRAPHIC_LOG
|
||||
#ifdef __LITEOS__
|
||||
typedef enum {
|
||||
LOG_LEVEL_FATAL = 0,
|
||||
LOG_LEVEL_ERROR,
|
||||
LOG_LEVEL_WARN,
|
||||
LOG_LEVEL_INFO,
|
||||
LOG_LEVEL_DEBUG,
|
||||
LOG_LEVEL_MAX
|
||||
} LOG_LEVEL;
|
||||
|
||||
static constexpr HiviewDFX::HiLogLabel GRPHIC_LABEL = {LOG_CORE, 0xD001400, "Graphic"};
|
||||
|
||||
#define FILE_NAME(x) (strrchr(x, '/') ? (strrchr(x, '/') + 1) : x)
|
||||
|
||||
#define GRAPHIC_DECORATOR_HILOG(level, op, fmt, args...) \
|
||||
do { \
|
||||
if ((level < GRAPHIC_LOG_LEVEL) && (level < LOG_LEVEL_MAX)) { \
|
||||
op(GRPHIC_LABEL, "{%s()-%s:%d} " fmt, __FUNCTION__, FILE_NAME(__FILE__), __LINE__, ##args); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define GRAPHIC_LOGF(fmt, args...) GRAPHIC_DECORATOR_HILOG(LOG_LEVEL_FATAL, HiviewDFX::HiLog::Fatal, fmt, ##args)
|
||||
#define GRAPHIC_LOGE(fmt, args...) GRAPHIC_DECORATOR_HILOG(LOG_LEVEL_ERROR, HiviewDFX::HiLog::Error, fmt, ##args)
|
||||
#define GRAPHIC_LOGW(fmt, args...) GRAPHIC_DECORATOR_HILOG(LOG_LEVEL_WARN, HiviewDFX::HiLog::Warn, fmt, ##args)
|
||||
#define GRAPHIC_LOGI(fmt, args...) GRAPHIC_DECORATOR_HILOG(LOG_LEVEL_INFO, HiviewDFX::HiLog::Info, fmt, ##args)
|
||||
#define GRAPHIC_LOGD(fmt, args...) GRAPHIC_DECORATOR_HILOG(LOG_LEVEL_DEBUG, HiviewDFX::HiLog::Debug, fmt, ##args)
|
||||
|
||||
#elif defined _WIN32
|
||||
#define GRAPHIC_LOGF(...) \
|
||||
do { \
|
||||
printf("%s\n", __VA_ARGS__); \
|
||||
} while (0)
|
||||
|
||||
#define GRAPHIC_LOGE(...) \
|
||||
do { \
|
||||
printf("%s\n", __VA_ARGS__); \
|
||||
} while (0)
|
||||
|
||||
#define GRAPHIC_LOGW(...) \
|
||||
do { \
|
||||
printf("%s\n", __VA_ARGS__); \
|
||||
} while (0)
|
||||
|
||||
#define GRAPHIC_LOGI(...) \
|
||||
do { \
|
||||
printf("%s\n", __VA_ARGS__); \
|
||||
} while (0)
|
||||
|
||||
#define GRAPHIC_LOGD(...) \
|
||||
do { \
|
||||
printf("%s\n", __VA_ARGS__); \
|
||||
} while (0)
|
||||
#else
|
||||
#define GRAPHIC_LOGF(...)
|
||||
#define GRAPHIC_LOGE(...)
|
||||
#define GRAPHIC_LOGW(...)
|
||||
#define GRAPHIC_LOGI(...)
|
||||
#define GRAPHIC_LOGD(...)
|
||||
#endif
|
||||
|
||||
#else // ENABLE_GRAPHIC_LOG
|
||||
|
||||
#define GRAPHIC_LOGF(...)
|
||||
#define GRAPHIC_LOGE(...)
|
||||
#define GRAPHIC_LOGW(...)
|
||||
#define GRAPHIC_LOGI(...)
|
||||
#define GRAPHIC_LOGD(...)
|
||||
|
||||
#endif // ENABLE_GRAPHIC_LOG
|
||||
} // namespace OHOS
|
||||
#endif // GRAPHIC_LITE_GRAPHIC_LOG_H
|
||||
Executable
+561
@@ -0,0 +1,561 @@
|
||||
/*
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup UI_Utils
|
||||
* @{
|
||||
*
|
||||
* @brief Defines basic UI utils.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file graphic_math.h
|
||||
*
|
||||
* @brief Defines mathematical operation functions and types, including trigonometric functions, two-dimensional
|
||||
* vectors, three-dimensional vectors, and matrices.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
#ifndef GRAPHIC_LITE_GRAPHIC_MATH_H
|
||||
#define GRAPHIC_LITE_GRAPHIC_MATH_H
|
||||
|
||||
#include "heap_base.h"
|
||||
#include <cstdint>
|
||||
|
||||
namespace OHOS {
|
||||
/**
|
||||
* @brief Larger of a and b.
|
||||
*/
|
||||
#define MATH_MAX(a, b) ((a) > (b) ? (a) : (b))
|
||||
/**
|
||||
* @brief Smaller of a and b.
|
||||
*/
|
||||
#define MATH_MIN(a, b) ((a) < (b) ? (a) : (b))
|
||||
/**
|
||||
* @brief Absolute value of x.
|
||||
*/
|
||||
#define MATH_ABS(x) ((x) > 0 ? (x) : (-(x)))
|
||||
/**
|
||||
* @brief Difference between a and b.
|
||||
*/
|
||||
#define MATH_MINUS(a, b) ((a) < (b) ? ((b) - (a)) : ((a) - (b)))
|
||||
|
||||
#define MATH_ROUND(x) ((x) > 0 ? (int16_t)((x) + 0.5) : (int16_t)((x) - 0.5))
|
||||
|
||||
#define MATH_FLT_EQUAL(a, b) (MATH_ABS((a) - (b)) <= UI_FLT_EPSILON)
|
||||
|
||||
/** A quarter of a rotation: 90 degrees */
|
||||
static constexpr uint16_t QUARTER_IN_DEGREE = 90;
|
||||
/** A half of a rotation: 180 degrees */
|
||||
static constexpr uint16_t SEMICIRCLE_IN_DEGREE = 180;
|
||||
/** Three fourths of a rotation: 270 degrees */
|
||||
static constexpr uint16_t THREE_QUARTER_IN_DEGREE = 270;
|
||||
/** A full rotation: 360 degrees */
|
||||
static constexpr uint16_t CIRCLE_IN_DEGREE = 360;
|
||||
/** Pi value */
|
||||
static constexpr double UI_PI = 3.14159265358979;
|
||||
static constexpr float ATAN2_P3 = -0.3258775;
|
||||
static constexpr float ATAN2_P5 = 0.1556117;
|
||||
static constexpr float ATAN2_P7 = -0.0443360;
|
||||
static constexpr float RADIAN_TO_ANGLE = 57.295779513;
|
||||
static constexpr float UI_FLT_EPSILON = 1E-5;
|
||||
|
||||
float Sin(int16_t angle);
|
||||
uint16_t FastAtan2(int16_t x, int16_t y);
|
||||
float Sqrt(float x);
|
||||
|
||||
/**
|
||||
* @brief Defines the two-dimensional vector, and provides basic mathematical operations such as vector assignment,
|
||||
* scalar product, cross product, addition, and subtraction.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
template<typename T>
|
||||
class Vector2 : public HeapBase {
|
||||
public:
|
||||
/**
|
||||
* @brief A constructor used to create a <b>Vector2</b> instance.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
Vector2() : x_(0), y_(0) {}
|
||||
|
||||
/**
|
||||
* @brief A constructor used to create a <b>Vector2</b> instance based on the X and Y coordinates.
|
||||
* @param x Indicates the X coordinate.
|
||||
* @param y Indicates the Y coordinate.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
Vector2(T x, T y)
|
||||
{
|
||||
x_ = x;
|
||||
y_ = y;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief A destructor used to delete the <b>Vector2</b> instance.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
~Vector2() {}
|
||||
|
||||
/**
|
||||
* @brief Calculates the scalar product of the two-dimensional vector and another two-dimensional vector.
|
||||
* @param other Indicates the two-dimensional vector to be used for calculation.
|
||||
* @return Returns the scalar product.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
T Dot(const Vector2<T>& other) const
|
||||
{
|
||||
T sum = x_ * other.x_;
|
||||
sum += y_ * other.y_;
|
||||
return sum;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Calculates the cross product of the two-dimensional vector and another two-dimensional vector.
|
||||
* @param other Indicates the two-dimensional vector to be used for calculation.
|
||||
* @return Returns the cross product.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
T Cross(const Vector2<T>& other) const
|
||||
{
|
||||
return x_ * other.y_ - y_ * other.x_;
|
||||
}
|
||||
|
||||
Vector2 operator-() const
|
||||
{
|
||||
return Vector2(-x_, -y_);
|
||||
}
|
||||
|
||||
Vector2 operator-(const Vector2<T>& other) const
|
||||
{
|
||||
return Vector2(x_ - other.x_, y_ - other.y_);
|
||||
}
|
||||
|
||||
Vector2 operator+(const Vector2<T>& other) const
|
||||
{
|
||||
return Vector2(x_ + other.x_, y_ + other.y_);
|
||||
}
|
||||
|
||||
Vector2 operator*(T scale) const
|
||||
{
|
||||
return Vector2(x_ * scale, y_ * scale);
|
||||
}
|
||||
|
||||
bool operator==(const Vector2& other) const
|
||||
{
|
||||
return (x_ == other.x_) && (y_ == other.y_);
|
||||
}
|
||||
|
||||
Vector2& operator=(const Vector2& other)
|
||||
{
|
||||
x_ = other.x_;
|
||||
y_ = other.y_;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Vector2& operator+=(const Vector2& other)
|
||||
{
|
||||
x_ += other.x_;
|
||||
y_ += other.y_;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Vector2& operator-=(const Vector2& other)
|
||||
{
|
||||
x_ -= other.x_;
|
||||
y_ -= other.y_;
|
||||
return *this;
|
||||
}
|
||||
|
||||
T x_;
|
||||
T y_;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Defines the 3-dimensional vector, and provides basic operators such as [] and ==.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
template<typename T>
|
||||
class Vector3 : public HeapBase {
|
||||
public:
|
||||
union {
|
||||
struct {
|
||||
T x_;
|
||||
T y_;
|
||||
T z_;
|
||||
};
|
||||
T data_[3]; // 3: size for x,y,z
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief A constructor used to create a <b>Vector3</b> instance.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
Vector3() : x_(0), y_(0), z_(1) {}
|
||||
|
||||
/**
|
||||
* @brief Defines a <b>Vector3</b> instance and initializes the values of <b>x</b>, <b>y</b>, and <b>z</b>.
|
||||
* @param x Indicates the X coordinate.
|
||||
* @param y Indicates the Y coordinate.
|
||||
* @param z Indicates the Z coordinate.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
Vector3(T x, T y, T z)
|
||||
{
|
||||
data_[0] = x;
|
||||
data_[1] = y;
|
||||
data_[2] = z; // 2: index of z
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief A destructor used to delete the <b>Vector3</b> instance.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
~Vector3() {}
|
||||
|
||||
T operator[](uint8_t index) const
|
||||
{
|
||||
return data_[index];
|
||||
}
|
||||
|
||||
T& operator[](uint8_t index)
|
||||
{
|
||||
return data_[index];
|
||||
}
|
||||
|
||||
bool operator==(const Vector3& other) const
|
||||
{
|
||||
return (x_ == other.x_) && (y_ == other.y_) && (z_ == other.z_);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Defines a 3 x 3 matrix.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
template<typename T>
|
||||
class Matrix3 : public HeapBase {
|
||||
public:
|
||||
/**
|
||||
* @brief Defines a <b>Matrix3</b> instance and initializes the 3 x 3 matrix data.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
Matrix3();
|
||||
|
||||
/**
|
||||
* @brief Defines a <b>Matrix3</b> instance and initializes the 3 x 3 matrix data.
|
||||
*
|
||||
* @param m00 Indicates the element in row 1 and column 1 of the matrix.
|
||||
* @param m01 Indicates the element in row 1 and column 2 of the matrix.
|
||||
* @param m02 Indicates the element in row 1 and column 3 of the matrix.
|
||||
* @param m10 Indicates the element in row 2 and column 1 of the matrix.
|
||||
* @param m11 Indicates the element in row 2 and column 2 of the matrix.
|
||||
* @param m12 Indicates the element in row 2 and column 3 of the matrix.
|
||||
* @param m20 Indicates the element in row 3 and column 1 of the matrix.
|
||||
* @param m21 Indicates the element in row 3 and column 2 of the matrix.
|
||||
* @param m22 Indicates the element in row 3 and column 3 of the matrix.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
Matrix3(T m00, T m01, T m02, T m10, T m11, T m12, T m20, T m21, T m22);
|
||||
|
||||
/**
|
||||
* @brief A destructor used to delete the <b>Matrix3</b> instance.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
~Matrix3() {}
|
||||
|
||||
/**
|
||||
* @brief Obtains the 3 x 3 matrix data.
|
||||
* @return Returns the 3 x 3 matrix data.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
const T* GetData() const
|
||||
{
|
||||
return data_;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Obtains the determinant of the matrix.
|
||||
* @return Returns the determinant.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
T Determinant() const;
|
||||
|
||||
/**
|
||||
* @brief Obtains the inverse matrix.
|
||||
* @return Returns the inverse matrix.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
Matrix3 Inverse() const;
|
||||
|
||||
/**
|
||||
* @brief Obtains a rotation matrix. After a matrix is rotated, its data is shifted leftwards by 15 bits. Therefore,
|
||||
* the result data needs to be shifted rightwards by 15 bits.
|
||||
* @param angle Indicates the angle to rotate.
|
||||
* @param pivot Indicates the rotation pivot.
|
||||
* @return Returns the matrix after rotation.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
static Matrix3 Rotate(T angle, const Vector2<T>& pivot);
|
||||
|
||||
/**
|
||||
* @brief Obtains the scaling matrix. After a matrix is scaled, its data is shifted leftwards by 8 bits. Therefore,
|
||||
* the result data needs to be shifted rightwards by 8 bits.
|
||||
* @param scale Indicates the scaling factors of the x-axis and y-axis.
|
||||
* @param fixed Indicates the fixed scaling point.
|
||||
* @return Returns the matrix after scaling.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
static Matrix3 Scale(const Vector2<T>& scale, const Vector2<T>& fixed);
|
||||
|
||||
/**
|
||||
* @brief Obtains a matrix translation.
|
||||
* @param trans Indicates the distances to translate along the x-axis and y-axis.
|
||||
* @return Returns the matrix after translation.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
static Matrix3<T> Translate(const Vector2<T>& trans);
|
||||
|
||||
Matrix3 operator*(const Matrix3& other) const;
|
||||
|
||||
Vector3<T> operator*(const Vector3<T>& other) const;
|
||||
|
||||
T* operator[](uint8_t col)
|
||||
{
|
||||
return &data_[col * 3]; // 3: size of point
|
||||
}
|
||||
|
||||
Matrix3& operator=(const Matrix3& other)
|
||||
{
|
||||
// 9: data_ value number
|
||||
data_[0] = other.data_[0];
|
||||
data_[1] = other.data_[1];
|
||||
data_[2] = other.data_[2];
|
||||
data_[3] = other.data_[3];
|
||||
data_[4] = other.data_[4];
|
||||
data_[5] = other.data_[5];
|
||||
data_[6] = other.data_[6];
|
||||
data_[7] = other.data_[7];
|
||||
data_[8] = other.data_[8];
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool operator==(const Matrix3& other) const;
|
||||
|
||||
protected:
|
||||
T data_[9]; // 9: 3 point with x,y,z
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
Matrix3<T>::Matrix3()
|
||||
{
|
||||
data_[1] = 0;
|
||||
data_[2] = 0;
|
||||
data_[3] = 0;
|
||||
data_[5] = 0;
|
||||
data_[6] = 0;
|
||||
data_[7] = 0;
|
||||
data_[0] = 1;
|
||||
data_[4] = 1;
|
||||
data_[8] = 1;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
Matrix3<T>::Matrix3(T m00, T m01, T m02, T m10, T m11, T m12, T m20, T m21, T m22)
|
||||
{
|
||||
data_[0] = m00;
|
||||
data_[1] = m01;
|
||||
data_[2] = m02;
|
||||
|
||||
data_[3] = m10;
|
||||
data_[4] = m11;
|
||||
data_[5] = m12;
|
||||
|
||||
data_[6] = m20;
|
||||
data_[7] = m21;
|
||||
data_[8] = m22;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
Matrix3<T> Matrix3<T>::operator*(const Matrix3<T>& other) const
|
||||
{
|
||||
Matrix3<T> rMulti;
|
||||
T* rData = rMulti.data_;
|
||||
const T* oData = other.data_;
|
||||
|
||||
rData[0] = data_[0] * oData[0] + data_[3] * oData[1] + data_[6] * oData[2];
|
||||
rData[3] = data_[0] * oData[3] + data_[3] * oData[4] + data_[6] * oData[5];
|
||||
rData[6] = data_[0] * oData[6] + data_[3] * oData[7] + data_[6] * oData[8];
|
||||
|
||||
rData[1] = data_[1] * oData[0] + data_[4] * oData[1] + data_[7] * oData[2];
|
||||
rData[4] = data_[1] * oData[3] + data_[4] * oData[4] + data_[7] * oData[5];
|
||||
rData[7] = data_[1] * oData[6] + data_[4] * oData[7] + data_[7] * oData[8];
|
||||
|
||||
rData[2] = data_[2] * oData[0] + data_[5] * oData[1] + data_[8] * oData[2];
|
||||
rData[5] = data_[2] * oData[3] + data_[5] * oData[4] + data_[8] * oData[5];
|
||||
rData[8] = data_[2] * oData[6] + data_[5] * oData[7] + data_[8] * oData[8];
|
||||
return rMulti;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
Vector3<T> Matrix3<T>::operator*(const Vector3<T>& other) const
|
||||
{
|
||||
Vector3<T> rMulti;
|
||||
T* rData = rMulti.data_;
|
||||
const T* oData = other.data_;
|
||||
rData[0] = data_[0] * oData[0] + data_[3] * oData[1] + data_[6] * oData[2];
|
||||
rData[1] = data_[1] * oData[0] + data_[4] * oData[1] + data_[7] * oData[2];
|
||||
rData[2] = data_[2] * oData[0] + data_[5] * oData[1] + data_[8] * oData[2];
|
||||
return rMulti;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T Matrix3<T>::Determinant() const
|
||||
{
|
||||
T x = data_[0] * ((data_[4] * data_[8]) - (data_[5] * data_[7]));
|
||||
T y = data_[1] * ((data_[3] * data_[8]) - (data_[5] * data_[6]));
|
||||
T z = data_[2] * ((data_[3] * data_[7]) - (data_[4] * data_[6]));
|
||||
return (x - y) + z;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
Matrix3<T> Matrix3<T>::Inverse() const
|
||||
{
|
||||
T det = this->Determinant();
|
||||
if (det == 0) {
|
||||
return Matrix3<T>(*this);
|
||||
}
|
||||
|
||||
T invDet = 1.0f / det;
|
||||
const T* data = this->data_;
|
||||
|
||||
T iX = invDet * (data[4] * data[8] - data[5] * data[7]);
|
||||
T iY = invDet * (data[2] * data[7] - data[1] * data[8]);
|
||||
T iZ = invDet * (data[1] * data[5] - data[2] * data[4]);
|
||||
T jX = invDet * (data[5] * data[6] - data[3] * data[8]);
|
||||
T jY = invDet * (data[0] * data[8] - data[2] * data[6]);
|
||||
T jZ = invDet * (data[2] * data[3] - data[0] * data[5]);
|
||||
T kX = invDet * (data[3] * data[7] - data[4] * data[6]);
|
||||
T kY = invDet * (data[1] * data[6] - data[0] * data[7]);
|
||||
T kZ = invDet * (data[0] * data[4] - data[1] * data[3]);
|
||||
|
||||
return Matrix3<T>(iX, iY, iZ, jX, jY, jZ, kX, kY, kZ);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool Matrix3<T>::operator==(const Matrix3& other) const
|
||||
{
|
||||
const T* oData = other.data_;
|
||||
|
||||
return (data_[0] == oData[0]) && (data_[1] == oData[1]) && (data_[2] == oData[2]) && (data_[3] == oData[3]) &&
|
||||
(data_[4] == oData[4]) && (data_[5] == oData[5]) && (data_[6] == oData[6]) && (data_[7] == oData[7]) &&
|
||||
(data_[8] == oData[8]);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
Matrix3<T> Matrix3<T>::Rotate(T angle, const Vector2<T>& pivot)
|
||||
{
|
||||
T s = static_cast<T>(Sin(angle));
|
||||
T c = static_cast<T>(Sin(angle + QUARTER_IN_DEGREE));
|
||||
|
||||
Matrix3<T> rotateMat3;
|
||||
T* rData = rotateMat3.data_;
|
||||
rData[0] = c;
|
||||
rData[1] = s;
|
||||
|
||||
rData[3] = -s;
|
||||
rData[4] = c;
|
||||
|
||||
rData[6] = pivot.x_ * (1 - c) + pivot.y_ * s;
|
||||
rData[7] = pivot.y_ * (1 - c) - pivot.x_ * s;
|
||||
|
||||
rData[8] = 1;
|
||||
|
||||
return rotateMat3;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
Matrix3<T> Matrix3<T>::Scale(const Vector2<T>& scale, const Vector2<T>& fixed)
|
||||
{
|
||||
Matrix3<T> scaleMat3;
|
||||
T* rData = scaleMat3.data_;
|
||||
rData[0] = scale.x_;
|
||||
|
||||
rData[4] = scale.y_;
|
||||
rData[6] = fixed.x_ * (1 - scale.x_);
|
||||
rData[7] = fixed.y_ * (1 - scale.y_);
|
||||
|
||||
rData[8] = 1;
|
||||
|
||||
return scaleMat3;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
Matrix3<T> Matrix3<T>::Translate(const Vector2<T>& trans)
|
||||
{
|
||||
Matrix3 transMat3;
|
||||
T* rData = transMat3.data_;
|
||||
|
||||
rData[6] = trans.x_;
|
||||
rData[7] = trans.y_;
|
||||
|
||||
return transMat3;
|
||||
}
|
||||
|
||||
inline int64_t FloatToInt64(float f)
|
||||
{
|
||||
if (f > 127.0) { // 127.0: 2^7
|
||||
return 0x7FFF;
|
||||
}
|
||||
|
||||
if (f < -127.0) { // 127.0: 2^7
|
||||
return -0x7FFF;
|
||||
}
|
||||
|
||||
// 256.0: 2^8 left move 8 bit. 0.5: round up
|
||||
return static_cast<int64_t>(f * 256.0 + ((f < 0) ? -0.5 : 0.5));
|
||||
}
|
||||
} // namespace OHOS
|
||||
#endif // GRAPHIC_LITE_GRAPHIC_MATH_H
|
||||
Executable
+134
@@ -0,0 +1,134 @@
|
||||
/*
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup UI_Utils
|
||||
* @{
|
||||
*
|
||||
* @brief Defines basic UI utils.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file graphic_types.h
|
||||
*
|
||||
* @brief Defines the common data types for the graphics system.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
#ifndef GRAPHIC_LITE_TYPES_H
|
||||
#define GRAPHIC_LITE_TYPES_H
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace OHOS {
|
||||
using TimeType = uint32_t;
|
||||
using ImageSrcType = uint8_t;
|
||||
|
||||
enum BlurLevel : uint8_t {
|
||||
INVALID,
|
||||
LEVEL0, // no blur
|
||||
LEVEL1, // blur one line
|
||||
LEVEL2, // blur two line
|
||||
};
|
||||
|
||||
enum TransformAlgorithm : uint8_t {
|
||||
NEAREST_NEIGHBOR,
|
||||
BILINEAR,
|
||||
};
|
||||
|
||||
enum LabelRotateDegree : uint8_t {
|
||||
DEGREE_0,
|
||||
DEGREE_90,
|
||||
DEGREE_180,
|
||||
DEGREE_270,
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief colormode of image and font.
|
||||
*/
|
||||
enum ColorMode : uint8_t {
|
||||
/** ARGB8888 color mode */
|
||||
ARGB8888 = 0,
|
||||
/** RGB888 color mode */
|
||||
RGB888,
|
||||
/** RGB565 color mode */
|
||||
RGB565,
|
||||
/** ARGB1555 color mode */
|
||||
ARGB1555,
|
||||
/** ARGB4444 color mode */
|
||||
ARGB4444,
|
||||
/** AL44 color mode */
|
||||
AL44,
|
||||
/** AL88 color mode */
|
||||
AL88,
|
||||
/** L1 color mode */
|
||||
L1,
|
||||
/** L2 color mode */
|
||||
L2,
|
||||
/** L4 color mode */
|
||||
L4,
|
||||
/** L8 color mode */
|
||||
L8,
|
||||
/** A1 color mode */
|
||||
A1,
|
||||
/** A2 color mode */
|
||||
A2,
|
||||
/** A4 color mode */
|
||||
A4,
|
||||
/** A8 color mode */
|
||||
A8,
|
||||
/** unknow color mode */
|
||||
UNKNOW,
|
||||
};
|
||||
|
||||
enum FontWeight : uint8_t {
|
||||
FONT_WEIGHT_1 = 1,
|
||||
FONT_WEIGHT_2 = 2,
|
||||
FONT_WEIGHT_4 = 4,
|
||||
FONT_WEIGHT_8 = 8,
|
||||
};
|
||||
|
||||
static constexpr uint8_t SHIFT_2 = 2;
|
||||
static constexpr uint8_t SHIFT_3 = 3;
|
||||
static constexpr uint8_t SHIFT_4 = 4;
|
||||
static constexpr uint8_t SHIFT_8 = 8;
|
||||
static constexpr uint8_t SHIFT_16 = 16;
|
||||
|
||||
/**
|
||||
* @brief Defines a point.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
struct Point {
|
||||
/** X coordinate */
|
||||
int16_t x;
|
||||
/** Y coordinate */
|
||||
int16_t y;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Enumerates image types.
|
||||
*/
|
||||
enum ImageType : uint8_t {
|
||||
IMG_SRC_FILE_PATH,
|
||||
IMG_SRC_IMAGE_INFO,
|
||||
};
|
||||
} // namespace OHOS
|
||||
#endif // GRAPHIC_LITE_TYPES_H
|
||||
Executable
+77
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup UI_Utils
|
||||
* @{
|
||||
*
|
||||
* @brief Defines basic UI utils.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file heap_base.h
|
||||
*
|
||||
* @brief Declares the functions for overriding the <b>new</b> and <b>delete</b> functions.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
#ifndef GRAPHIC_LITE_HEAP_BASE_H
|
||||
#define GRAPHIC_LITE_HEAP_BASE_H
|
||||
|
||||
#include "graphic_config.h"
|
||||
#include "mem_api.h"
|
||||
#include <stddef.h>
|
||||
namespace OHOS {
|
||||
/**
|
||||
* @brief Defines the base class, overriding the <b>new</b> and <b>delete</b> functions.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
class HeapBase {
|
||||
public:
|
||||
#if ENABLE_MEMORY_HOOKS
|
||||
/**
|
||||
* @brief Overrides the <b>new</b> function.
|
||||
* @param size Indicates the size of the memory to be allocated.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
void* operator new(size_t size)
|
||||
{
|
||||
return UIMalloc(static_cast<uint32_t>(size));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Overrides the <b>delete</b> function.
|
||||
* @param p Indicates the pointer to the memory to be released.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
void operator delete(void* p)
|
||||
{
|
||||
UIFree(p);
|
||||
}
|
||||
#endif
|
||||
};
|
||||
} // namespace OHOS
|
||||
#endif //
|
||||
Executable
+70
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup UI_Utils
|
||||
* @{
|
||||
*
|
||||
* @brief Defines basic UI utils.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file image_info.h
|
||||
*
|
||||
* @brief Defines image information.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
#ifndef GRAPHIC_LITE_IMAGE_INFO_H
|
||||
#define GRAPHIC_LITE_IMAGE_INFO_H
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace OHOS {
|
||||
/**
|
||||
* @brief Defines image head node information.
|
||||
*/
|
||||
struct ImageHeader {
|
||||
/** Color format, which is used to match image type. This variable is important. */
|
||||
uint32_t colorMode : 8;
|
||||
uint32_t version : 4;
|
||||
uint32_t compressMode : 4;
|
||||
uint32_t reserved : 16;
|
||||
/** Image width */
|
||||
uint16_t width;
|
||||
/** Image height */
|
||||
uint16_t height;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Defines image information.
|
||||
*/
|
||||
struct ImageInfo {
|
||||
/** Image head node information. For details, see {@link ImageHeader}. */
|
||||
ImageHeader header;
|
||||
/** Size of the image data (in bytes) */
|
||||
uint32_t dataSize;
|
||||
/** Pixel color data of pixelmap images */
|
||||
const uint8_t* data;
|
||||
/** User-defined data */
|
||||
void* userData;
|
||||
};
|
||||
} // namespace OHOS
|
||||
#endif // GRAPHIC_LITE_IMAGE_INFO_H
|
||||
Executable
+79
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef GRAPHIC_LITE_INPUT_EVENT_INFO_H
|
||||
#define GRAPHIC_LITE_INPUT_EVENT_INFO_H
|
||||
|
||||
#include <cstdint>
|
||||
#include "geometry2d.h"
|
||||
|
||||
namespace OHOS {
|
||||
const static uint8_t MAX_EVENT_SIZE = 10;
|
||||
const static uint8_t MAX_INPUT_DEVICE_NUM = 10;
|
||||
|
||||
/**
|
||||
* @brief Enumerates input device types.
|
||||
*/
|
||||
enum class InputDevType {
|
||||
INDEV_TYPE_TOUCH, /** Touchscreen */
|
||||
INDEV_TYPE_KEY, /** Physical key */
|
||||
INDEV_TYPE_KEYBOARD, /** Keyboard */
|
||||
INDEV_TYPE_MOUSE, /** Mouse */
|
||||
INDEV_TYPE_BUTTON, /** Virtual button */
|
||||
INDEV_TYPE_CROWN, /** Watch crown */
|
||||
INDEV_TYPE_ENCODER, /** Customized type of a specific function or event */
|
||||
INDEV_TYPE_UNKNOWN, /** Unknown input device type */
|
||||
};
|
||||
|
||||
/** @brief struct of raw event */
|
||||
struct RawEvent {
|
||||
int32_t deviceId;
|
||||
InputDevType type;
|
||||
union {
|
||||
struct {
|
||||
int16_t x;
|
||||
int16_t y;
|
||||
uint16_t state;
|
||||
};
|
||||
uint16_t keyId; /* key type device use this param for touched key id */
|
||||
};
|
||||
int32_t timestamp;
|
||||
};
|
||||
|
||||
struct DeviceData {
|
||||
union {
|
||||
Point point; /* pointer type device use this param for touched point */
|
||||
uint16_t keyId; /* key type device use this param for touched key id */
|
||||
int16_t encoderDiff; /* encode type device used this param for number of steps since the previous read */
|
||||
#if ENABLE_ROTATE_INPUT
|
||||
int16_t rotate; /* rotate type device used this param for rotate */
|
||||
#endif
|
||||
uint16_t type; /* for virtual device the currently event type */
|
||||
};
|
||||
uint16_t state;
|
||||
#if ENABLE_WINDOW
|
||||
int32_t winId;
|
||||
#endif
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
LITEIMS_CLIENT_REGISTER,
|
||||
LITEIMS_CLIENT_UNREGISTER
|
||||
} LiteIMSCall;
|
||||
|
||||
const char IMS_SERVICE_NAME[] = "IMS";
|
||||
const int32_t IMS_DEFAULT_IPC_SIZE = 200;
|
||||
} // namespace OHOS
|
||||
#endif // GRAPHIC_LITE_INPUT_EVENT_INFO_H
|
||||
Executable
+376
@@ -0,0 +1,376 @@
|
||||
/*
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup UI_Utils
|
||||
* @{
|
||||
*
|
||||
* @brief Defines basic UI utils.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file list.h
|
||||
*
|
||||
* @brief Defines a linked list template class, which implements the data structure of bidirectional linked list and
|
||||
* provides basic functions such as adding, deleting, inserting, clearing, popping up, and obtaining the size of
|
||||
* the linked list.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
#ifndef GRAPHIC_LITE_LIST_H
|
||||
#define GRAPHIC_LITE_LIST_H
|
||||
#include "heap_base.h"
|
||||
#include <cstdint>
|
||||
|
||||
namespace OHOS {
|
||||
/**
|
||||
* @brief Stores linked list data and contains pointers to the previous node and the next node.
|
||||
*
|
||||
* @param T Indicates the type of the data stored in the linked list.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
template<typename T>
|
||||
class ListNode : public HeapBase {
|
||||
public:
|
||||
ListNode<T>* prev_;
|
||||
ListNode<T>* next_;
|
||||
T data_;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Defines a linked list template class, which implements the data structure of bidirectional linked list and
|
||||
* provides basic functions such as adding, deleting, inserting, clearing, popping up, and obtaining the size of
|
||||
* the linked list.
|
||||
*
|
||||
* @param T Indicates the type of the data stored in the linked list.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
template<typename T>
|
||||
class List : public HeapBase {
|
||||
public:
|
||||
/**
|
||||
* @brief A default constructor used to create a <b>List</b> instance. The initial size is <b>0</b>.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
List() : size_(0)
|
||||
{
|
||||
head_.next_ = &head_;
|
||||
head_.prev_ = &head_;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief A destructor used to delete the <b>List</b> instance.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
virtual ~List() {}
|
||||
|
||||
/**
|
||||
* @brief Obtains the head node data of a linked list.
|
||||
*
|
||||
* @return Returns the head node data.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
const T Front() const
|
||||
{
|
||||
return head_.next_->data_;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Obtains the tail node data of a linked list.
|
||||
*
|
||||
* @return Returns the tail node data.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
const T Back() const
|
||||
{
|
||||
return head_.prev_->data_;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Inserts data at the end of a linked list.
|
||||
*
|
||||
* @param data Indicates the data to insert.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
void PushBack(T data)
|
||||
{
|
||||
ListNode<T>* listNode = new ListNode<T>();
|
||||
if (listNode == nullptr) {
|
||||
return;
|
||||
}
|
||||
listNode->data_ = data;
|
||||
|
||||
listNode->prev_ = head_.prev_;
|
||||
listNode->next_ = &head_;
|
||||
head_.prev_->next_ = listNode;
|
||||
head_.prev_ = listNode;
|
||||
|
||||
size_++;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Inserts data at the start of a linked list.
|
||||
*
|
||||
* @param data Indicates the data to insert.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
void PushFront(T data)
|
||||
{
|
||||
ListNode<T>* listNode = new ListNode<T>();
|
||||
if (listNode == nullptr) {
|
||||
return;
|
||||
}
|
||||
listNode->data_ = data;
|
||||
|
||||
listNode->next_ = head_.next_;
|
||||
listNode->prev_ = &head_;
|
||||
head_.next_->prev_ = listNode;
|
||||
head_.next_ = listNode;
|
||||
|
||||
size_++;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Pops up a data record at the end of a linked list.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
void PopBack()
|
||||
{
|
||||
if (IsEmpty()) {
|
||||
return;
|
||||
}
|
||||
ListNode<T>* tmpTail = head_.prev_;
|
||||
|
||||
tmpTail->prev_->next_ = &head_;
|
||||
head_.prev_ = tmpTail->prev_;
|
||||
|
||||
delete tmpTail;
|
||||
|
||||
if (size_ > 0) {
|
||||
size_--;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Pops up a data record at the start of a linked list.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
void PopFront()
|
||||
{
|
||||
if (IsEmpty()) {
|
||||
return;
|
||||
}
|
||||
ListNode<T>* tmpHead = head_.next_;
|
||||
|
||||
head_.next_ = tmpHead->next_;
|
||||
tmpHead->next_->prev_ = &head_;
|
||||
|
||||
delete tmpHead;
|
||||
|
||||
if (size_ > 0) {
|
||||
size_--;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Inserts data before a specified node, which follows the inserted data node.
|
||||
* @param node Indicates the pointer to the node holding the inserted data.
|
||||
* @param data Indicates the data to insert.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
void Insert(ListNode<T>* node, T data)
|
||||
{
|
||||
if ((node == nullptr) || (node->prev_ == nullptr)) {
|
||||
return;
|
||||
}
|
||||
ListNode<T>* listNode = new ListNode<T>();
|
||||
if (listNode == nullptr) {
|
||||
return;
|
||||
}
|
||||
listNode->data_ = data;
|
||||
|
||||
listNode->next_ = node;
|
||||
listNode->prev_ = node->prev_;
|
||||
node->prev_->next_ = listNode;
|
||||
node->prev_ = listNode;
|
||||
|
||||
size_++;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Deletes a data node.
|
||||
*
|
||||
* @param node Indicates the pointer to the node to delete.
|
||||
* @return 返回要删除节点的下一个节点.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
ListNode<T>* Remove(ListNode<T>* node)
|
||||
{
|
||||
if (IsEmpty()) {
|
||||
return &head_;
|
||||
}
|
||||
if ((node == nullptr) || (node->prev_ == nullptr) || (node->next_ == nullptr)) {
|
||||
return &head_;
|
||||
}
|
||||
ListNode<T>* next = node->next_;
|
||||
node->prev_->next_ = node->next_;
|
||||
node->next_->prev_ = node->prev_;
|
||||
|
||||
delete node;
|
||||
|
||||
if (size_ > 0) {
|
||||
size_--;
|
||||
}
|
||||
return next;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Deletes all nodes from a linked list.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
void Clear()
|
||||
{
|
||||
if (IsEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
ListNode<T>* node = head_.next_;
|
||||
ListNode<T>* tmpNode = node->next_;
|
||||
do {
|
||||
delete node;
|
||||
node = tmpNode;
|
||||
tmpNode = tmpNode->next_;
|
||||
} while (node != &head_);
|
||||
|
||||
head_.next_ = &head_;
|
||||
head_.prev_ = &head_;
|
||||
|
||||
size_ = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Obtains the head node address of a linked list.
|
||||
*
|
||||
* @return Returns the head node address.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
ListNode<T>* Head() const
|
||||
{
|
||||
return head_.next_;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Obtains the tail node address of a linked list.
|
||||
*
|
||||
* @return Returns the tail node address.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
ListNode<T>* Tail() const
|
||||
{
|
||||
return head_.prev_;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Obtains the head node address of a linked list.
|
||||
*
|
||||
* @return Returns the head node address.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
ListNode<T>* Begin() const
|
||||
{
|
||||
return head_.next_;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Obtains the end node address of a linked list.
|
||||
*
|
||||
* @return Returns the end node address.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
const ListNode<T>* End() const
|
||||
{
|
||||
return &head_;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Obtains the address of the node following the specified <b>node</b>.
|
||||
*
|
||||
* @param node Indicates the pointer to the data node in the linked list.
|
||||
* @return Returns the address of the node following <b>node</b>.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
ListNode<T>* Next(const ListNode<T>* node) const
|
||||
{
|
||||
return node != nullptr ? node->next_ : nullptr;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Checks whether a linked list is empty.
|
||||
*
|
||||
* @return Returns <b>true</b> if the linked list is empty; returns <b>false</b> otherwise.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
bool IsEmpty() const
|
||||
{
|
||||
return (head_.next_ == &head_);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Obtains the size of a linked list.
|
||||
*
|
||||
* @return Returns the size of the linked list.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
uint16_t Size() const
|
||||
{
|
||||
return size_;
|
||||
}
|
||||
|
||||
protected:
|
||||
ListNode<T> head_;
|
||||
uint16_t size_;
|
||||
};
|
||||
} // namespace OHOS
|
||||
#endif // GRAPHIC_LITE_LIST_H
|
||||
Executable
+85
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup UI_Utils
|
||||
* @{
|
||||
*
|
||||
* @brief Defines basic UI utils.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file mem_api.h
|
||||
*
|
||||
* @brief Defines the functions for memory application and release. You can implement the <b>malloc</b> and <b>free</b>
|
||||
* functions to manage the memory.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
#ifndef GRAPHIC_LITE_MEM_API_H
|
||||
#define GRAPHIC_LITE_MEM_API_H
|
||||
|
||||
#include "graphic_config.h"
|
||||
#include "image_info.h"
|
||||
|
||||
#ifndef IMG_CACHE_MEMORY_CUSTOM
|
||||
#include <cstdlib>
|
||||
#endif
|
||||
|
||||
namespace OHOS {
|
||||
/**
|
||||
* @brief Applies for the image cache memory. You can customize the memory area when loading image resources.
|
||||
*
|
||||
* @param info Indicates the image information. For details, see {@link ImageInfo}.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
void* ImageCacheMalloc(ImageInfo& info);
|
||||
|
||||
/**
|
||||
* @brief Releases the image cache memory.
|
||||
*
|
||||
* @param info Indicates the image information. For details, see {@link ImageInfo}.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
void ImageCacheFree(ImageInfo& info);
|
||||
|
||||
/**
|
||||
* @brief Applies for memory for the graphics module. You can implement this function to override the <b>malloc</b> and
|
||||
* <b>new</b> functions.
|
||||
*
|
||||
* @param size Indicates the size of the memory to apply for.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
void* UIMalloc(uint32_t size);
|
||||
|
||||
/**
|
||||
* @brief Releases memory for the graphics module. You can implement this function to override the <b>free</b> and
|
||||
* <b>delete</b> functions.
|
||||
*
|
||||
* @param buffer Indicates the pointer to the memory to be released.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
void UIFree(void* buffer);
|
||||
} // namespace OHOS
|
||||
#endif
|
||||
Executable
+103
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef GRAPHIC_LITE_PIXEL_FORMAT_UTILS
|
||||
#define GRAPHIC_LITE_PIXEL_FORMAT_UTILS
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
namespace OHOS {
|
||||
union PF_ARGB1555 {
|
||||
struct {
|
||||
uint16_t blue : 5;
|
||||
uint16_t green : 5;
|
||||
uint16_t red : 5;
|
||||
uint16_t alpha : 1;
|
||||
};
|
||||
uint16_t full;
|
||||
};
|
||||
|
||||
union PF_ARGB8888 {
|
||||
struct {
|
||||
uint32_t blue : 8;
|
||||
uint32_t green : 8;
|
||||
uint32_t red : 8;
|
||||
uint32_t alpha : 8;
|
||||
};
|
||||
uint32_t full;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Enumerates a pixel format.
|
||||
*/
|
||||
enum ImagePixelFormat {
|
||||
/** Invalid pixel format */
|
||||
IMAGE_PIXEL_FORMAT_NONE = 0,
|
||||
/** RGB565 pixel format */
|
||||
IMAGE_PIXEL_FORMAT_RGB565 = 101,
|
||||
/** ARGB555 pixel format */
|
||||
IMAGE_PIXEL_FORMAT_ARGB1555,
|
||||
/** RGB888 pixel format */
|
||||
IMAGE_PIXEL_FORMAT_RGB888,
|
||||
/** ARGB8888 pixel format */
|
||||
IMAGE_PIXEL_FORMAT_ARGB8888,
|
||||
/** YUYV pixel format */
|
||||
IMAGE_PIXEL_FORMAT_YUYV = 201,
|
||||
/** YVYU pixel format */
|
||||
IMAGE_PIXEL_FORMAT_YVYU,
|
||||
/** UYVY pixel format */
|
||||
IMAGE_PIXEL_FORMAT_UYVY,
|
||||
/** VYUY pixel format */
|
||||
IMAGE_PIXEL_FORMAT_VYUY,
|
||||
/** AYUV pixel format */
|
||||
IMAGE_PIXEL_FORMAT_AYUV,
|
||||
/** YUV410 pixel format */
|
||||
IMAGE_PIXEL_FORMAT_YUV410,
|
||||
/** YVU410 pixel format */
|
||||
IMAGE_PIXEL_FORMAT_YVU410,
|
||||
/** YUV411 pixel format */
|
||||
IMAGE_PIXEL_FORMAT_YUV411,
|
||||
/** YVU411 pixel format */
|
||||
IMAGE_PIXEL_FORMAT_YVU411,
|
||||
/** YUV420 pixel format */
|
||||
IMAGE_PIXEL_FORMAT_YUV420,
|
||||
/** YVU420 pixel format */
|
||||
IMAGE_PIXEL_FORMAT_YVU420,
|
||||
/** YUV422 pixel format */
|
||||
IMAGE_PIXEL_FORMAT_YUV422,
|
||||
/** YVU422 pixel format */
|
||||
IMAGE_PIXEL_FORMAT_YVU422,
|
||||
/** YUV444 pixel format */
|
||||
IMAGE_PIXEL_FORMAT_YUV444,
|
||||
/** YVU444 pixel format */
|
||||
IMAGE_PIXEL_FORMAT_YVU444,
|
||||
/** NV12 pixel format */
|
||||
IMAGE_PIXEL_FORMAT_NV12 = 301,
|
||||
/** NV21 pixel format */
|
||||
IMAGE_PIXEL_FORMAT_NV21,
|
||||
/** NV16 pixel format */
|
||||
IMAGE_PIXEL_FORMAT_NV16,
|
||||
/** NV61 pixel format */
|
||||
IMAGE_PIXEL_FORMAT_NV61
|
||||
};
|
||||
|
||||
class PixelFormatUtils {
|
||||
public:
|
||||
static bool BppOfPixelFormat(ImagePixelFormat pixelFormat, int16_t& bpp);
|
||||
static uint16_t ARGB8888ToARGB1555(uint32_t color);
|
||||
static uint32_t ARGB1555ToARGB8888(uint16_t color);
|
||||
};
|
||||
}
|
||||
#endif
|
||||
Executable
+398
@@ -0,0 +1,398 @@
|
||||
/*
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup UI_Utils
|
||||
* @{
|
||||
*
|
||||
* @brief Defines basic UI utils.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file rect.h
|
||||
*
|
||||
* @brief Defines a rectangle, including the position data of the four boundaries of the rectangle, and provides
|
||||
* functions for rectangle inclusion, intersection, and aggregation.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
#ifndef GRAPHIC_LITE_RECT_H
|
||||
#define GRAPHIC_LITE_RECT_H
|
||||
|
||||
#include "graphic_math.h"
|
||||
#include "graphic_types.h"
|
||||
#include "heap_base.h"
|
||||
|
||||
namespace OHOS {
|
||||
/**
|
||||
* @brief Defines a rectangle, including the position data of the four boundaries of the rectangle, and provides
|
||||
* functions for rectangle inclusion, intersection, and aggregation.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
class Rect : public HeapBase {
|
||||
public:
|
||||
/**
|
||||
* @brief A constructor used to create a <b>Rect</b> instance.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
Rect() : left_(0), top_(0), right_(0), bottom_(0) {}
|
||||
|
||||
/**
|
||||
* @brief A destructor used to delete the <b>Rect</b> instance.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
~Rect() {}
|
||||
|
||||
/**
|
||||
* @brief A constructor used to create a <b>Rect</b> instance based on the coordinates of the four boundaries.
|
||||
* @param left Indicates the coordinate of the left boundary.
|
||||
* @param top Indicates the coordinate of the top boundary.
|
||||
* @param right Indicates the coordinate of the right boundary.
|
||||
* @param bottom Indicates the coordinate of the bottom boundary.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
Rect(int16_t left, int16_t top, int16_t right, int16_t bottom);
|
||||
|
||||
/**
|
||||
* @brief A constructor used to create a <b>Rect</b> instance by copying another rectangle.
|
||||
*
|
||||
* @param other Indicates the rectangle to copy.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
Rect(const Rect& other);
|
||||
|
||||
/**
|
||||
* @brief A constructor used to create a <b>Rect</b> instance by copying another rectangle.
|
||||
*
|
||||
* @param other Indicates the rectangle to copy.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
Rect(const Rect&& other);
|
||||
|
||||
/**
|
||||
* @brief Sets the coordinates of the four boundaries of a rectangle.
|
||||
*
|
||||
* @param left Indicates the coordinate of the left boundary.
|
||||
* @param top Indicates the coordinate of the top boundary.
|
||||
* @param right Indicates the coordinate of the right boundary.
|
||||
* @param bottom Indicates the coordinate of the bottom boundary.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
void SetRect(int16_t left, int16_t top, int16_t right, int16_t bottom);
|
||||
|
||||
/**
|
||||
* @brief Obtains the rectangle width.
|
||||
* @return Returns the rectangle width.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
int16_t GetWidth() const
|
||||
{
|
||||
return right_ - left_ + 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Obtains the rectangle height.
|
||||
* @return Returns the rectangle height.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
int16_t GetHeight() const
|
||||
{
|
||||
return bottom_ - top_ + 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Obtains the left boundary coordinate of the rectangle.
|
||||
* @return Returns the left boundary coordinate.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
int16_t GetX() const
|
||||
{
|
||||
return left_;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Obtains the top boundary coordinate of the rectangle.
|
||||
* @return Returns the top boundary coordinate.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
int16_t GetY() const
|
||||
{
|
||||
return top_;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Obtains the left boundary coordinate of the rectangle.
|
||||
* @return Returns the left boundary coordinate.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
int16_t GetLeft() const
|
||||
{
|
||||
return left_;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Obtains the top boundary coordinate of the rectangle.
|
||||
* @return Returns the top boundary coordinate.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
int16_t GetTop() const
|
||||
{
|
||||
return top_;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Obtains the right boundary coordinate of the rectangle.
|
||||
* @return Returns the right boundary coordinate.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
int16_t GetRight() const
|
||||
{
|
||||
return right_;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Obtains the bottom boundary coordinate of the rectangle.
|
||||
* @return Returns the bottom boundary coordinate.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
int16_t GetBottom() const
|
||||
{
|
||||
return bottom_;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Changes the left boundary coordinate of the rectangle without changing the rectangle width.
|
||||
* @param x Indicates the coordinate of the left boundary.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
void SetX(int16_t x)
|
||||
{
|
||||
right_ += x - left_;
|
||||
left_ = x;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Changes the top boundary coordinate of the rectangle without changing the rectangle height.
|
||||
* @param y Indicates the coordinate of the top boundary.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
void SetY(int16_t y)
|
||||
{
|
||||
bottom_ += y - top_;
|
||||
top_ = y;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Changes the coordinates of the left and top boundaries of the rectangle without changing the rectangle
|
||||
* width and height.
|
||||
* @param x Indicates the coordinate of the left boundary.
|
||||
* @param y Indicates the coordinate of the top boundary.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
void SetPosition(int16_t x, int16_t y)
|
||||
{
|
||||
right_ += x - left_;
|
||||
bottom_ += y - top_;
|
||||
left_ = x;
|
||||
top_ = y;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Changes the width of the rectangle without changing the coordinate of the left boundary.
|
||||
* @param width Indicates the width of the rectangle.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
void SetWidth(int16_t width)
|
||||
{
|
||||
right_ = left_ + width - 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Changes the height of the rectangle without changing the coordinate of the top boundary.
|
||||
* @param height Indicates the height of the rectangle.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
void SetHeight(int16_t height)
|
||||
{
|
||||
bottom_ = top_ + height - 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Sets the coordinate of the left boundary of a rectangle.
|
||||
* @param left Indicates the coordinate of the left boundary.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
void SetLeft(int16_t left)
|
||||
{
|
||||
left_ = left;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Sets the coordinate of the top boundary of a rectangle.
|
||||
* @param top Indicates the coordinate of the top boundary.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
void SetTop(int16_t top)
|
||||
{
|
||||
top_ = top;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Sets the coordinate of the right boundary of a rectangle.
|
||||
* @param right Indicates the coordinate of the right boundary.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
void SetRight(int16_t right)
|
||||
{
|
||||
right_ = right;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Sets the coordinate of the bottom boundary of a rectangle.
|
||||
* @param bottom Indicates the coordinate of the bottom boundary.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
void SetBottom(int16_t bottom)
|
||||
{
|
||||
bottom_ = bottom;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Sets the width and height of a rectangle.
|
||||
* @param width Indicates the width of the rectangle.
|
||||
* @param height Indicates the height of the rectangle.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
void Resize(int16_t width, int16_t height)
|
||||
{
|
||||
right_ = left_ + width - 1;
|
||||
bottom_ = top_ + height - 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Obtains the area of a rectangle.
|
||||
* @return Returns the area of the rectangle.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
uint32_t GetSize() const;
|
||||
|
||||
/**
|
||||
* @brief Checks whether two rectangles intersect.
|
||||
* @param rect1 Indicates the first rectangle to check.
|
||||
* @param rect2 Indicates the second rectangle to check.
|
||||
* @return Returns <b>true</b> if the two rectangles intersect; returns <b>false</b> otherwise.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
bool Intersect(const Rect& rect1, const Rect& rect2);
|
||||
|
||||
/**
|
||||
* @brief Obtains the minimum rectangle that contains another two rectangles.
|
||||
* @param rect1 Indicates the first rectangle to contain.
|
||||
* @param rect2 Indicates the second rectangle to contain.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
void Join(const Rect& rect1, const Rect& rect2);
|
||||
|
||||
/**
|
||||
* @brief Checks whether the rectangle contains a coordinate point.
|
||||
* @param point Indicates the coordinate point.
|
||||
* @return Returns <b>true</b> if the input coordinate point is contained; returns <b>false</b> otherwise.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
bool IsContains(const Vector2<int16_t>& point) const;
|
||||
|
||||
/**
|
||||
* @brief Checks whether the rectangle contains a coordinate point.
|
||||
* @param point Indicates the coordinate point.
|
||||
* @return Returns <b>true</b> if the input coordinate point is contained; returns <b>false</b> otherwise.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
bool IsContains(const Point& point) const;
|
||||
|
||||
/**
|
||||
* @brief Checks whether the rectangle is adjacent to another rectangle horizontally or vertically.
|
||||
* @param other Indicates the rectangle to be used for check.
|
||||
* @return Returns <b>true</b> if the rectangle is adjacent to the input rectangle; returns <b>false</b> otherwise.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
bool IsExtends(const Rect& other) const;
|
||||
|
||||
/**
|
||||
* @brief Checks whether the rectangle intersects with another rectangle.
|
||||
* @param other Indicates the rectangle to be used for check.
|
||||
* @return Returns <b>true</b> if the two rectangles intersect; returns <b>false</b> otherwise.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
bool IsIntersect(const Rect& other) const;
|
||||
|
||||
/**
|
||||
* @brief Checks whether the rectangle contains another rectangle.
|
||||
*
|
||||
* @param other Indicates the rectangle to be used for check.
|
||||
* @return Returns <b>true</b> if the input rectangle is contained; returns <b>false</b> otherwise.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
bool IsContains(const Rect& other) const;
|
||||
|
||||
void Inflate(int16_t delta);
|
||||
void operator=(const Rect& other);
|
||||
void operator=(const Rect&& other);
|
||||
bool operator==(const Rect& other) const;
|
||||
|
||||
protected:
|
||||
int16_t left_;
|
||||
int16_t top_;
|
||||
int16_t right_;
|
||||
int16_t bottom_;
|
||||
};
|
||||
} // namespace OHOS
|
||||
#endif // GRAPHIC_LITE_RECT_H
|
||||
Executable
+395
@@ -0,0 +1,395 @@
|
||||
/*
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup UI_Utils
|
||||
* @{
|
||||
*
|
||||
* @brief Defines basic UI utils.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file style.h
|
||||
*
|
||||
* @brief Defines the attributes and common functions of style.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
#ifndef GRAPHIC_LITE_STYLE_H
|
||||
#define GRAPHIC_LITE_STYLE_H
|
||||
|
||||
#include "color.h"
|
||||
|
||||
namespace OHOS {
|
||||
/**
|
||||
* @brief Enumerates keys of styles.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
enum : uint8_t {
|
||||
/** Background color */
|
||||
STYLE_BACKGROUND_COLOR,
|
||||
/** Background opacity */
|
||||
STYLE_BACKGROUND_OPA,
|
||||
/** Border radius */
|
||||
STYLE_BORDER_RADIUS,
|
||||
/** Border color */
|
||||
STYLE_BORDER_COLOR,
|
||||
/** Border opacity */
|
||||
STYLE_BORDER_OPA,
|
||||
/** Border width */
|
||||
STYLE_BORDER_WIDTH,
|
||||
/** Left padding */
|
||||
STYLE_PADDING_LEFT,
|
||||
/** Right padding */
|
||||
STYLE_PADDING_RIGHT,
|
||||
/** Top padding */
|
||||
STYLE_PADDING_TOP,
|
||||
/** Bottom padding */
|
||||
STYLE_PADDING_BOTTOM,
|
||||
/** Left margin */
|
||||
STYLE_MARGIN_LEFT,
|
||||
/** Right margin */
|
||||
STYLE_MARGIN_RIGHT,
|
||||
/** Top margin */
|
||||
STYLE_MARGIN_TOP,
|
||||
/** Bottom margin */
|
||||
STYLE_MARGIN_BOTTOM,
|
||||
/** Image opacity */
|
||||
STYLE_IMAGE_OPA,
|
||||
/** Text color */
|
||||
STYLE_TEXT_COLOR,
|
||||
/** Text font */
|
||||
STYLE_TEXT_FONT,
|
||||
/** Letter spacing */
|
||||
STYLE_LETTER_SPACE,
|
||||
/** Line spacing */
|
||||
STYLE_LINE_SPACE,
|
||||
/** Text opacity */
|
||||
STYLE_TEXT_OPA,
|
||||
/** Line color */
|
||||
STYLE_LINE_COLOR,
|
||||
/** Line width */
|
||||
STYLE_LINE_WIDTH,
|
||||
/** Line opacity */
|
||||
STYLE_LINE_OPA,
|
||||
/** Line cap style */
|
||||
STYLE_LINE_CAP
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Enumerates cap styles.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
enum CapType : uint8_t {
|
||||
/** No cap style */
|
||||
CAP_NONE,
|
||||
/** Round cap style */
|
||||
CAP_ROUND,
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Defines the basic attributes and functions of a style. You can use this class to set different styles.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
class Style : public HeapBase {
|
||||
public:
|
||||
/**
|
||||
* @brief A constructor used to create a <b>Style</b> instance.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
Style();
|
||||
|
||||
/**
|
||||
* @brief A destructor used to delete the <b>Style</b> instance.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
virtual ~Style() {}
|
||||
|
||||
/**
|
||||
* @brief Sets a style.
|
||||
*
|
||||
* @param key Indicates the key of the style to set.
|
||||
* @param value Indicates the value matching the key.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
void SetStyle(uint8_t key, int64_t value);
|
||||
|
||||
/**
|
||||
* @brief Obtains the value of a style.
|
||||
*
|
||||
* @param key Indicates the key of the style.
|
||||
* @return Returns the value of the style.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
int64_t GetStyle(uint8_t key) const;
|
||||
|
||||
/* background style */
|
||||
ColorType bgColor_;
|
||||
uint8_t bgOpa_;
|
||||
/* border style */
|
||||
uint8_t borderOpa_;
|
||||
int16_t borderWidth_;
|
||||
int16_t borderRadius_;
|
||||
ColorType borderColor_;
|
||||
/* padding style */
|
||||
uint16_t paddingLeft_;
|
||||
uint16_t paddingRight_;
|
||||
uint16_t paddingTop_;
|
||||
uint16_t paddingBottom_;
|
||||
/* margin style */
|
||||
int16_t marginLeft_;
|
||||
int16_t marginRight_;
|
||||
int16_t marginTop_;
|
||||
int16_t marginBottom_;
|
||||
/* image style */
|
||||
uint8_t imageOpa_;
|
||||
/* text style */
|
||||
uint8_t textOpa_;
|
||||
uint8_t font_;
|
||||
int16_t letterSpace_;
|
||||
int16_t lineSpace_;
|
||||
ColorType textColor_;
|
||||
/* line style */
|
||||
ColorType lineColor_;
|
||||
uint8_t lineOpa_;
|
||||
uint8_t lineCap_;
|
||||
int16_t lineWidth_;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Define some default style for {@link UIView}.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
class StyleDefault : public HeapBase {
|
||||
public:
|
||||
/**
|
||||
* @brief A constructor used to create a <b>StyleDefault</b> instance.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
StyleDefault(){};
|
||||
|
||||
/**
|
||||
* @brief A destructor used to delete the <b>StyleDefault</b> instance.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
~StyleDefault(){};
|
||||
|
||||
static void Init();
|
||||
|
||||
/**
|
||||
* @brief Obtains the default style.
|
||||
*
|
||||
* @return Returns the default style.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
static Style& GetDefaultStyle()
|
||||
{
|
||||
return defaultStyle_;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Obtains the bright style.
|
||||
*
|
||||
* @return Returns the bright style.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
static Style& GetBrightStyle()
|
||||
{
|
||||
return brightStyle_;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Obtains the bright color style.
|
||||
*
|
||||
* @return Returns the bright color style.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
static Style& GetBrightColorStyle()
|
||||
{
|
||||
return brightColorStyle_;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Obtains the button pressed style.
|
||||
*
|
||||
* @return Returns the button pressed style.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
static Style& GetButtonPressedStyle()
|
||||
{
|
||||
return buttonPressedStyle_;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Obtains the button released style.
|
||||
*
|
||||
* @return Returns the button released style.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
static Style& GetButtonReleasedStyle()
|
||||
{
|
||||
return buttonReleasedStyle_;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Obtains the button inactive style.
|
||||
*
|
||||
* @return Returns the button inactive style.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
static Style& GetButtonInactiveStyle()
|
||||
{
|
||||
return buttonInactiveStyle_;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Obtains the label style.
|
||||
*
|
||||
* @return Returns the label style.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
static Style& GetLabelStyle()
|
||||
{
|
||||
return labelStyle_;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Obtains the background transparent style.
|
||||
*
|
||||
* @return Returns the background transparent style.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
static Style& GetBackgroundTransparentStyle()
|
||||
{
|
||||
return backgroundTransparentStyle_;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Obtains the progress background style.
|
||||
*
|
||||
* @return Returns the progress background style.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
static Style& GetProgressBackgroundStyle()
|
||||
{
|
||||
return progressBackgroundStyle_;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Obtains the progress foreground style.
|
||||
*
|
||||
* @return Returns the progress foreground style.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
static Style& GetProgressForegroundStyle()
|
||||
{
|
||||
return progressForegroundStyle_;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Obtains the slider knob style.
|
||||
*
|
||||
* @return Returns the slider knob style.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
static Style& GetSliderKnobStyle()
|
||||
{
|
||||
return sliderKnobStyle_;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Obtains the picker background style.
|
||||
*
|
||||
* @return Returns the picker background style.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
static Style& GetPickerBackgroundStyle()
|
||||
{
|
||||
return pickerBackgroundStyle_;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Obtains the picker highlight style.
|
||||
*
|
||||
* @return Returns the picker highlight style.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
static Style& GetPickerHighlightStyle()
|
||||
{
|
||||
return pickerHighlightStyle_;
|
||||
}
|
||||
|
||||
private:
|
||||
static Style defaultStyle_;
|
||||
static Style brightStyle_;
|
||||
static Style brightColorStyle_;
|
||||
|
||||
static Style buttonPressedStyle_;
|
||||
static Style buttonReleasedStyle_;
|
||||
static Style buttonInactiveStyle_;
|
||||
static Style labelStyle_;
|
||||
static Style backgroundTransparentStyle_;
|
||||
static Style progressBackgroundStyle_;
|
||||
static Style progressForegroundStyle_;
|
||||
static Style sliderKnobStyle_;
|
||||
|
||||
static Style pickerBackgroundStyle_;
|
||||
static Style pickerHighlightStyle_;
|
||||
|
||||
static void InitStyle();
|
||||
static void InitButtonStyle();
|
||||
static void InitLabelStyle();
|
||||
static void InitBackgroundTransparentStyle();
|
||||
static void InitProgressStyle();
|
||||
static void InitPickerStyle();
|
||||
};
|
||||
} // namespace OHOS
|
||||
#endif // GRAPHIC_LITE_STYLE_H
|
||||
Executable
+159
@@ -0,0 +1,159 @@
|
||||
/*
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup UI_Utils
|
||||
* @{
|
||||
*
|
||||
* @brief Defines basic UI utils.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file sys_info.h
|
||||
*
|
||||
* @brief Declares the system information about the graphics module, including the function to obtain the information
|
||||
* about FPS, which needs to be enabled by the <b>ENABLE_FPS_SUPPORT</b> macro.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
#ifndef GRAPHIC_LITE_SYS_INFO_H
|
||||
#define GRAPHIC_LITE_SYS_INFO_H
|
||||
|
||||
#include "graphic_config.h"
|
||||
#include "heap_base.h"
|
||||
|
||||
namespace OHOS {
|
||||
/**
|
||||
* @brief Obtains the system information. Currently, the FPS information can be obtained. To enable the FPS feature,
|
||||
* enable the <b>ENABLE_FPS_SUPPORT</b> macro.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
class SysInfo {
|
||||
public:
|
||||
/**
|
||||
* @brief Enumerates the FPS capture types.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
enum FPSCalculateType {
|
||||
/** Fixed time sampling: The system collects the number of page refresh times within one second. */
|
||||
FPS_CT_FIXED_TIME,
|
||||
/**
|
||||
* Average sampling: The system collects statistics on the average frame rate of 100 frames. No extra space is
|
||||
* required to store the data of each frame. The precision is not as high as that of precise sampling.
|
||||
*/
|
||||
FPS_CT_AVERAGE_SAMPLING,
|
||||
/**
|
||||
* Precise sampling: The system collects statistics on the average frame rate of the current 100 frames. Extra
|
||||
* space is required to save the data of each frame. The result is more precise than that of average sampling.
|
||||
*/
|
||||
FPS_CT_PRECISE_SAMPLING
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Called when the FPS changes.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
class OnFPSChangedListener : public HeapBase {
|
||||
public:
|
||||
/**
|
||||
* @brief A constructor used to create an <b>OnFPSChangedListener</b> instance with the default sampling type
|
||||
* <b>FPS_CT_FIXED_TIME</b>.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
OnFPSChangedListener() : type_(FPS_CT_FIXED_TIME){};
|
||||
|
||||
/**
|
||||
* @brief A destructor used to delete the <b>OnFPSChangedListener</b> instance.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
virtual ~OnFPSChangedListener() {}
|
||||
|
||||
/**
|
||||
* @brief Called when the FPS data changes.
|
||||
*
|
||||
* @param newFPS Indicates the FPS data.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
virtual void OnFPSChanged(float newFPS) = 0;
|
||||
|
||||
/**
|
||||
* @brief Obtains the FPS sampling type.
|
||||
*
|
||||
* @return Returns the FPS sampling type. For details, see {@link FPSCalculateType}.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
FPSCalculateType GetFPSCalculateType() const
|
||||
{
|
||||
return type_;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Sets the FPS sampling type.
|
||||
*
|
||||
* @param type Indicates the FPS sampling type. For details, see {@link FPSCalculateType}.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
void SetFPSCalculateType(FPSCalculateType type)
|
||||
{
|
||||
type_ = type;
|
||||
}
|
||||
|
||||
private:
|
||||
FPSCalculateType type_;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Obtains the FPS data.
|
||||
*
|
||||
* @return Returns the FPS data.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
static float GetFPS();
|
||||
|
||||
/**
|
||||
* @brief Registers the listener for notifying the FPS changes.
|
||||
*
|
||||
* @param onFPSChangedListener Indicates the pointer to the FPS change notification function. For details, see
|
||||
* {@link OnFPSChangedListener}.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
static void RegisterFPSChangedListener(OnFPSChangedListener* onFPSChangedListener);
|
||||
|
||||
private:
|
||||
SysInfo() = default;
|
||||
~SysInfo() = default;
|
||||
};
|
||||
} // namespace OHOS
|
||||
#endif
|
||||
Executable
+242
@@ -0,0 +1,242 @@
|
||||
/*
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup UI_Utils
|
||||
* @{
|
||||
*
|
||||
* @brief Defines basic UI utils.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file transform.h
|
||||
*
|
||||
* @brief Provides functions to transform components, points, and line segments, including rotation and scaling.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
#ifndef GRAPHIC_LITE_TRANSFORM_H
|
||||
#define GRAPHIC_LITE_TRANSFORM_H
|
||||
|
||||
#include "geometry2d.h"
|
||||
#include "graphic_math.h"
|
||||
namespace OHOS {
|
||||
/**
|
||||
* @brief Transforms a rectangle, including rotation and scaling.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
class TransformMap : public HeapBase {
|
||||
public:
|
||||
/**
|
||||
* @brief The default constructor used to create a <b>TransformMap</b> instance.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
TransformMap();
|
||||
|
||||
/**
|
||||
* @brief A constructor used to create a <b>TransformMap</b> instance.
|
||||
*
|
||||
* @param rect Indicates the rectangle to transform.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
explicit TransformMap(const Rect& rect);
|
||||
|
||||
/**
|
||||
* @brief A destructor used to delete the <b>TransformMap</b> instance.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
virtual ~TransformMap() {}
|
||||
|
||||
/**
|
||||
* @brief Checks whether the vertex coordinates of a polygon are clockwise.
|
||||
*
|
||||
* @return Returns <b>true</b> if the vertex coordinates are clockwise; returns <b>false</b> otherwise.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
bool GetClockWise() const;
|
||||
|
||||
/**
|
||||
* @brief Sets a polygon after rectangle transformation.
|
||||
* @param polygon Indicates the polygon to set.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
void SetPolygon(const Polygon& polygon)
|
||||
{
|
||||
polygon_ = polygon;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Obtains the polygon after rectangle transformation.
|
||||
* @return Returns the polygon.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
Polygon GetPolygon() const
|
||||
{
|
||||
return polygon_;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Obtains the pivot for the rotation or scaling operation.
|
||||
* @return Returns the pivot.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
const Vector2<float>& GetPivot() const
|
||||
{
|
||||
return scalePivot_;
|
||||
}
|
||||
|
||||
void SetTransMapRect(const Rect& rect);
|
||||
|
||||
const Rect& GetTransMapRect() const
|
||||
{
|
||||
return rect_;
|
||||
}
|
||||
|
||||
void SetInvalid(bool state)
|
||||
{
|
||||
isInvalid_ = state;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Checks whether the <b>TransformMap</b> instance is invalid. When the vertices are all 0, the
|
||||
* <b>TransformMap</b> is invalid.
|
||||
* @return Returns <b>true</b> if <b>TransformMap</b> is invalid; returns <b>false</b> otherwise.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
bool IsInvalid() const;
|
||||
|
||||
/**
|
||||
* @brief Obtains the minimum rectangle that can contain a polygon. All vertices of the polygon are inside this
|
||||
* rectangle.
|
||||
* @return Returns the minimum rectangle that can contain the polygon.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
Rect GetBoxRect() const
|
||||
{
|
||||
return polygon_.MakeAABB();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Obtains a three-dimensional homogenous transformation matrix.
|
||||
* @return Returns the three-dimensional homogeneous transformation matrix.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
const Matrix3<float>& GetTransformMatrix() const
|
||||
{
|
||||
return matrix_;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Rotates the rectangle.
|
||||
* @param angle Indicates the angle to rotate.
|
||||
* @param pivot Indicates the rotation pivot.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
void Rotate(int16_t angle, const Vector2<float>& pivot);
|
||||
|
||||
/**
|
||||
* @brief Scales the rectangle.
|
||||
*
|
||||
* @param scale Indicates the scaling factors of the x-axis and y-axis.
|
||||
* @param pivot Indicates the pivot for scaling.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
void Scale(const Vector2<float> scale, const Vector2<float>& pivot);
|
||||
|
||||
void Translate(const Vector2<int16_t>& trans);
|
||||
|
||||
bool operator==(const TransformMap& other) const;
|
||||
|
||||
Matrix3<float> invMatrix_;
|
||||
|
||||
private:
|
||||
void UpdateMap();
|
||||
void AddOp(uint8_t op);
|
||||
|
||||
enum : uint8_t {
|
||||
ROTATE = 0,
|
||||
SCALE,
|
||||
TRANSLATE,
|
||||
TRANS_NUM,
|
||||
};
|
||||
int16_t angle_;
|
||||
bool isInvalid_;
|
||||
Vector2<float> scaleCoeff_;
|
||||
Vector2<float> scalePivot_;
|
||||
Vector2<float> rotatePivot_;
|
||||
Matrix3<float> rotate_;
|
||||
Matrix3<float> scale_;
|
||||
Matrix3<float> translate_;
|
||||
|
||||
Matrix3<float>* trans_[TRANS_NUM];
|
||||
uint8_t opOrder_[TRANS_NUM];
|
||||
|
||||
Matrix3<float> matrix_;
|
||||
Rect rect_; /* orig rect */
|
||||
Polygon polygon_; /* transformed from rect and 'rotate_' 'translate_' 'scale_' */
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Rotates a point around the pivot by a certain angle.
|
||||
* @param point Indicates the point to rotate.
|
||||
* @param angle Indicates the angle to rotate.
|
||||
* @param pivot Indicates the rotation pivot.
|
||||
* @param out Indicates the point generated after rotation.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
void Rotate(const Vector2<int16_t>& point, int16_t angle, const Vector2<int16_t>& pivot, Vector2<int16_t>& out);
|
||||
|
||||
/**
|
||||
* @brief Rotates a line around the pivot by a certain angle.
|
||||
* @param origLine Indicates the line segment to rotate.
|
||||
* @param angle Indicates the angle to rotate.
|
||||
* @param pivot Indicates the rotation pivot.
|
||||
* @param out Indicates the line generated after rotation.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
void Rotate(const Line& origLine, int16_t angle, const Vector2<int16_t>& pivot, Line& out);
|
||||
|
||||
/**
|
||||
* @brief Rotates a rectangle around the pivot by a certain angle.
|
||||
* @param origRect Indicates the rectangle to rotate.
|
||||
* @param angle Indicates the angle to rotate.
|
||||
* @param pivot Indicates the rotation pivot.
|
||||
* @param out Indicates the polygon generated after the rectangle is rotated.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
void Rotate(const Rect& origRect, int16_t angle, const Vector2<int16_t>& pivot, Polygon& out);
|
||||
} // namespace OHOS
|
||||
#endif // GRAPHIC_LITE_TRANSFORM_H
|
||||
@@ -0,0 +1,183 @@
|
||||
/*
|
||||
* Copyright (c) 2020 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup Graphic
|
||||
* @{
|
||||
*
|
||||
* @brief Defines a lightweight graphics system that provides basic UI and container views,
|
||||
* including buttons, images, labels, lists, animators, scroll views, swipe views, and layouts.
|
||||
* This system also provides the Design for X (DFX) capability to implement features such as
|
||||
* view rendering, animation, and input event distribution.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
#ifndef GRAPHIC_LITE_VECTOR_H
|
||||
#define GRAPHIC_LITE_VECTOR_H
|
||||
#include "heap_base.h"
|
||||
#include <cstdint>
|
||||
|
||||
namespace OHOS {
|
||||
template<typename T> class Vector : public HeapBase {
|
||||
public:
|
||||
Vector(uint16_t capacity = 1) : capacity_(capacity)
|
||||
{
|
||||
array_ = new T[capacity];
|
||||
}
|
||||
|
||||
Vector(const Vector<T>& value)
|
||||
{
|
||||
capacity_ = value.Capacity();
|
||||
array_ = new T[capacity_];
|
||||
size_ = value.size_;
|
||||
if (value.array_ != nullptr) {
|
||||
for (uint16_t i = 0; i < value.size_; i++) {
|
||||
array_[i] = value.array_[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
virtual ~Vector()
|
||||
{
|
||||
delete[] array_;
|
||||
}
|
||||
|
||||
T& Front()
|
||||
{
|
||||
return array_[0]; // undefined operation while vector is empty
|
||||
}
|
||||
|
||||
T& Back()
|
||||
{
|
||||
return array_[size_ - 1]; // undefined operation while vector is empty
|
||||
}
|
||||
|
||||
void PushBack(const T& data)
|
||||
{
|
||||
if (size_ == capacity_) {
|
||||
capacity_ <<= 1;
|
||||
T* array = new T[capacity_];
|
||||
for (uint16_t i = 0; i < size_; i++) {
|
||||
array[i] = array_[i];
|
||||
}
|
||||
delete[] array_;
|
||||
array_ = array;
|
||||
}
|
||||
array_[size_++] = data;
|
||||
}
|
||||
|
||||
void PopBack()
|
||||
{
|
||||
if (IsEmpty()) {
|
||||
return;
|
||||
}
|
||||
--size_;
|
||||
}
|
||||
|
||||
void Clear()
|
||||
{
|
||||
size_ = 0;
|
||||
}
|
||||
|
||||
T* Begin() const
|
||||
{
|
||||
return array_;
|
||||
}
|
||||
|
||||
const T* End() const
|
||||
{
|
||||
return (array_ + size_);
|
||||
}
|
||||
|
||||
bool IsEmpty() const
|
||||
{
|
||||
return (size_ == 0);
|
||||
}
|
||||
|
||||
uint16_t Size() const
|
||||
{
|
||||
return size_;
|
||||
}
|
||||
|
||||
uint16_t Capacity() const
|
||||
{
|
||||
return capacity_;
|
||||
}
|
||||
|
||||
uint16_t ReSize(uint16_t size)
|
||||
{
|
||||
if (size <= capacity_) {
|
||||
size_ = size;
|
||||
}
|
||||
return size_;
|
||||
}
|
||||
|
||||
void Erase(uint16_t index)
|
||||
{
|
||||
if (index >= size_) {
|
||||
return;
|
||||
}
|
||||
size_--;
|
||||
for (; index < size_; index++) {
|
||||
array_[index] = array_[index + 1];
|
||||
}
|
||||
}
|
||||
|
||||
void Swap(Vector<T>& other)
|
||||
{
|
||||
uint16_t size = size_;
|
||||
size_ = other.size_;
|
||||
other.size_ = size;
|
||||
|
||||
uint16_t capacity = capacity_;
|
||||
capacity_ = other.capacity_;
|
||||
other.capacity_ = capacity;
|
||||
|
||||
T* array = array_;
|
||||
array_ = other.array_;
|
||||
other.array_ = array;
|
||||
}
|
||||
|
||||
T& operator[](uint16_t index)
|
||||
{
|
||||
return array_[index];
|
||||
}
|
||||
|
||||
void operator=(const Vector<T>& value)
|
||||
{
|
||||
if (capacity_ < value.Size()) {
|
||||
delete[] array_;
|
||||
capacity_ = value.capacity_;
|
||||
array_ = new T[capacity_];
|
||||
}
|
||||
if (value.array_ != nullptr) {
|
||||
for (uint16_t i = 0; i < value.size_; i++) {
|
||||
array_[i] = value.array_[i];
|
||||
}
|
||||
size_ = value.size_;
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
uint16_t size_ = 0;
|
||||
uint16_t capacity_ = 0;
|
||||
T* array_ = nullptr;
|
||||
uint16_t head = 0;
|
||||
uint16_t tail = 0;
|
||||
};
|
||||
} // namespace OHOS
|
||||
#endif // GRAPHIC_LITE_VECTOR_H
|
||||
Executable
+59
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup UI_Utils
|
||||
* @{
|
||||
*
|
||||
* @brief Defines basic UI utils.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file version.h
|
||||
*
|
||||
* @brief Declares the version number control for the graphics module. This file defines functions to obtain the version
|
||||
* number and library description.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
#ifndef GRAPHIC_LITE_VERSION_H
|
||||
#define GRAPHIC_LITE_VERSION_H
|
||||
#include <string>
|
||||
|
||||
namespace OHOS {
|
||||
/**
|
||||
* @brief Obtains the version number of the graphics module.
|
||||
*
|
||||
* @return Returns the version number of the graphics module.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
std::string GetVersion();
|
||||
|
||||
/**
|
||||
* @brief Obtains the library description of the graphics module.
|
||||
*
|
||||
* @return Returns the library description of the graphics module.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
std::string GetLibDsc();
|
||||
} // namespace OHOS
|
||||
#endif
|
||||
Executable
+81
@@ -0,0 +1,81 @@
|
||||
# Copyright (c) 2020-2021 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("//build/lite/config/test.gni")
|
||||
|
||||
group("lite_graphic_utils_test") {
|
||||
if (ohos_build_type == "debug") {
|
||||
deps = [
|
||||
":graphic_test_color",
|
||||
":graphic_test_container",
|
||||
":graphic_test_geometry2d",
|
||||
":graphic_test_math",
|
||||
":graphic_test_style",
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
config("lite_graphic_utils_test_config") {
|
||||
include_dirs = []
|
||||
ldflags = [
|
||||
"-lstdc++",
|
||||
"-Wl,-rpath-link=$ohos_root_path/$root_out_dir",
|
||||
]
|
||||
}
|
||||
|
||||
if (ohos_build_type == "debug") {
|
||||
unittest("graphic_test_color") {
|
||||
output_extension = "bin"
|
||||
output_dir = "$root_out_dir/test/unittest/graphic"
|
||||
deps = [ "//foundation/graphic/utils:graphic_utils" ]
|
||||
configs = [ ":lite_graphic_utils_test_config" ]
|
||||
sources = [ "color_unit_test.cpp" ]
|
||||
}
|
||||
|
||||
unittest("graphic_test_style") {
|
||||
output_extension = "bin"
|
||||
output_dir = "$root_out_dir/test/unittest/graphic"
|
||||
deps = [ "//foundation/graphic/utils:graphic_utils" ]
|
||||
configs = [ ":lite_graphic_utils_test_config" ]
|
||||
include_dirs = [ "//foundation/graphic/ui/interfaces/kits" ]
|
||||
sources = [ "style_unit_test.cpp" ]
|
||||
}
|
||||
|
||||
unittest("graphic_test_geometry2d") {
|
||||
output_extension = "bin"
|
||||
output_dir = "$root_out_dir/test/unittest/graphic"
|
||||
deps = [ "//foundation/graphic/utils:graphic_utils" ]
|
||||
configs = [ ":lite_graphic_utils_test_config" ]
|
||||
sources = [
|
||||
"geometry2d_unit_test.cpp",
|
||||
"rect_unit_test.cpp",
|
||||
]
|
||||
}
|
||||
|
||||
unittest("graphic_test_container") {
|
||||
output_extension = "bin"
|
||||
output_dir = "$root_out_dir/test/unittest/graphic"
|
||||
deps = [ "//foundation/graphic/utils:graphic_utils" ]
|
||||
configs = [ ":lite_graphic_utils_test_config" ]
|
||||
sources = [
|
||||
"list_unit_test.cpp",
|
||||
"vector_unit_test.cpp",
|
||||
]
|
||||
}
|
||||
|
||||
unittest("graphic_test_math") {
|
||||
output_extension = "bin"
|
||||
output_dir = "$root_out_dir/test/unittest/graphic"
|
||||
deps = [ "//foundation/graphic/utils:graphic_utils" ]
|
||||
configs = [ ":lite_graphic_utils_test_config" ]
|
||||
sources = [ "graphic_math_unit_test.cpp" ]
|
||||
}
|
||||
}
|
||||
Executable
+380
@@ -0,0 +1,380 @@
|
||||
/*
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "color.h"
|
||||
|
||||
#include <climits>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
using namespace testing::ext;
|
||||
namespace OHOS {
|
||||
class ColorTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase(void) {}
|
||||
static void TearDownTestCase(void) {}
|
||||
};
|
||||
|
||||
/**
|
||||
* @tc.name: ColorGetColorFromRGB_001
|
||||
* @tc.desc: Verify GetColorFromRGB function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ColorTest, ColorGetColorFromRGB_001, TestSize.Level0)
|
||||
{
|
||||
ColorType color = Color::GetColorFromRGB(0, 0, 0);
|
||||
|
||||
EXPECT_EQ(color.red, 0);
|
||||
EXPECT_EQ(color.green, 0);
|
||||
EXPECT_EQ(color.blue, 0);
|
||||
EXPECT_EQ(color.alpha, OPA_OPAQUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ColorGetColorFromRGBA_002
|
||||
* @tc.desc: Verify GetColorFromRGBA function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ColorTest, ColorGetColorFromRGBA_002, TestSize.Level0)
|
||||
{
|
||||
ColorType color = Color::GetColorFromRGBA(0, 0, 0, OPA_TRANSPARENT);
|
||||
|
||||
EXPECT_EQ(color.red, 0);
|
||||
EXPECT_EQ(color.green, 0);
|
||||
EXPECT_EQ(color.blue, 0);
|
||||
EXPECT_EQ(color.alpha, OPA_TRANSPARENT);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ColorColorTo32_001
|
||||
* @tc.desc: Verify ColorTo32 function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ColorTest, ColorColorTo32_001, TestSize.Level0)
|
||||
{
|
||||
ColorType color;
|
||||
color.red = 0;
|
||||
color.green = 0;
|
||||
color.blue = 0;
|
||||
color.alpha = OPA_TRANSPARENT;
|
||||
uint32_t color32 = 0;
|
||||
|
||||
EXPECT_EQ(Color::ColorTo32(color), color32);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ColorColorTo32_002
|
||||
* @tc.desc: Verify ColorTo32 function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ColorTest, ColorColorTo32_002, TestSize.Level0)
|
||||
{
|
||||
Color16 color16;
|
||||
color16.red = 0;
|
||||
color16.green = 0;
|
||||
color16.blue = 0;
|
||||
|
||||
EXPECT_EQ(Color::ColorTo32(color16, 0), 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ColorColorTo16_001
|
||||
* @tc.desc: Verify ColorTo16 function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ColorTest, ColorColorTo16_001, TestSize.Level0)
|
||||
{
|
||||
Color32 color32;
|
||||
color32.red = 0;
|
||||
color32.green = 0;
|
||||
color32.blue = 0;
|
||||
|
||||
EXPECT_EQ(Color::ColorTo16(color32), 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ColorWhite_001
|
||||
* @tc.desc: Verify White function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ColorTest, ColorWhite_001, TestSize.Level0)
|
||||
{
|
||||
ColorType white = Color::White();
|
||||
|
||||
EXPECT_EQ(white.red, 0xFF);
|
||||
EXPECT_EQ(white.green, 0xFF);
|
||||
EXPECT_EQ(white.blue, 0xFF);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ColorSilver_001
|
||||
* @tc.desc: Verify Silver function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ColorTest, ColorSilver_001, TestSize.Level0)
|
||||
{
|
||||
ColorType silver = Color::Silver();
|
||||
|
||||
EXPECT_EQ(silver.red, 0xC0);
|
||||
EXPECT_EQ(silver.green, 0xC0);
|
||||
EXPECT_EQ(silver.blue, 0xC0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ColorGray_001
|
||||
* @tc.desc: Verify Gray function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ColorTest, ColorGray_001, TestSize.Level0)
|
||||
{
|
||||
ColorType gray = Color::Gray();
|
||||
|
||||
EXPECT_EQ(gray.red, 0x80);
|
||||
EXPECT_EQ(gray.green, 0x80);
|
||||
EXPECT_EQ(gray.blue, 0x80);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ColorBlack_001
|
||||
* @tc.desc: Verify Black function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ColorTest, ColorBlack_001, TestSize.Level0)
|
||||
{
|
||||
ColorType black = Color::Black();
|
||||
|
||||
EXPECT_EQ(black.red, 0x00);
|
||||
EXPECT_EQ(black.green, 0x00);
|
||||
EXPECT_EQ(black.blue, 0x00);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ColorRed_001
|
||||
* @tc.desc: Verify Red function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ColorTest, ColorRed_001, TestSize.Level0)
|
||||
{
|
||||
ColorType red = Color::Red();
|
||||
|
||||
EXPECT_EQ(red.red, 0xFF);
|
||||
EXPECT_EQ(red.green, 0x00);
|
||||
EXPECT_EQ(red.blue, 0x00);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ColorMaroon_001
|
||||
* @tc.desc: Verify Maroon function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ColorTest, ColorMaroon_001, TestSize.Level0)
|
||||
{
|
||||
ColorType maroon = Color::Maroon();
|
||||
|
||||
EXPECT_EQ(maroon.red, 0x80);
|
||||
EXPECT_EQ(maroon.green, 0x00);
|
||||
EXPECT_EQ(maroon.blue, 0x00);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ColorYellow_001
|
||||
* @tc.desc: Verify Yellow function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ColorTest, ColorYellow_001, TestSize.Level0)
|
||||
{
|
||||
ColorType yellow = Color::Yellow();
|
||||
|
||||
EXPECT_EQ(yellow.red, 0xFF);
|
||||
EXPECT_EQ(yellow.green, 0xFF);
|
||||
EXPECT_EQ(yellow.blue, 0x00);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ColorOlive_001
|
||||
* @tc.desc: Verify Olive function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ColorTest, ColorOlive_001, TestSize.Level0)
|
||||
{
|
||||
ColorType olive = Color::Olive();
|
||||
|
||||
EXPECT_EQ(olive.red, 0x80);
|
||||
EXPECT_EQ(olive.green, 0x80);
|
||||
EXPECT_EQ(olive.blue, 0x00);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ColorLime_001
|
||||
* @tc.desc: Verify Lime function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ColorTest, ColorLime_001, TestSize.Level0)
|
||||
{
|
||||
ColorType lime = Color::Lime();
|
||||
|
||||
EXPECT_EQ(lime.red, 0x00);
|
||||
EXPECT_EQ(lime.green, 0xFF);
|
||||
EXPECT_EQ(lime.blue, 0x00);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ColorGreen_001
|
||||
* @tc.desc: Verify Green function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ColorTest, ColorGreen_001, TestSize.Level0)
|
||||
{
|
||||
ColorType green = Color::Green();
|
||||
|
||||
EXPECT_EQ(green.red, 0x00);
|
||||
EXPECT_EQ(green.green, 0xFF);
|
||||
EXPECT_EQ(green.blue, 0x00);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ColorCyan_001
|
||||
* @tc.desc: Verify Cyan function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ColorTest, ColorCyan_001, TestSize.Level0)
|
||||
{
|
||||
ColorType cyan = Color::Cyan();
|
||||
|
||||
EXPECT_EQ(cyan.red, 0x00);
|
||||
EXPECT_EQ(cyan.green, 0xFF);
|
||||
EXPECT_EQ(cyan.blue, 0xFF);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ColorAqua_001
|
||||
* @tc.desc: Verify Aqua function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ColorTest, ColorAqua_001, TestSize.Level0)
|
||||
{
|
||||
ColorType aqua = Color::Aqua();
|
||||
|
||||
EXPECT_EQ(aqua.red, 0x00);
|
||||
EXPECT_EQ(aqua.green, 0xFF);
|
||||
EXPECT_EQ(aqua.blue, 0xFF);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ColorTeal_001
|
||||
* @tc.desc: Verify Teal function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ColorTest, ColorTeal_001, TestSize.Level0)
|
||||
{
|
||||
ColorType teal = Color::Teal();
|
||||
|
||||
EXPECT_EQ(teal.red, 0x00);
|
||||
EXPECT_EQ(teal.green, 0x80);
|
||||
EXPECT_EQ(teal.blue, 0x80);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ColorBlue_001
|
||||
* @tc.desc: Verify Blue function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ColorTest, ColorBlue_001, TestSize.Level0)
|
||||
{
|
||||
ColorType blue = Color::Blue();
|
||||
|
||||
EXPECT_EQ(blue.red, 0x00);
|
||||
EXPECT_EQ(blue.green, 0x00);
|
||||
EXPECT_EQ(blue.blue, 0xFF);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ColorNavy_001
|
||||
* @tc.desc: Verify Navy function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ColorTest, ColorNavy_001, TestSize.Level0)
|
||||
{
|
||||
ColorType navy = Color::Navy();
|
||||
|
||||
EXPECT_EQ(navy.red, 0x00);
|
||||
EXPECT_EQ(navy.green, 0x00);
|
||||
EXPECT_EQ(navy.blue, 0x80);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ColorMagenta_001
|
||||
* @tc.desc: Verify Magenta function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ColorTest, ColorMagenta_001, TestSize.Level0)
|
||||
{
|
||||
ColorType magenta = Color::Magenta();
|
||||
|
||||
EXPECT_EQ(magenta.red, 0xFF);
|
||||
EXPECT_EQ(magenta.green, 0x00);
|
||||
EXPECT_EQ(magenta.blue, 0xFF);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ColorPurple_001
|
||||
* @tc.desc: Verify Purple function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ColorTest, ColorPurple_001, TestSize.Level0)
|
||||
{
|
||||
ColorType purple = Color::Purple();
|
||||
|
||||
EXPECT_EQ(purple.red, 0x80);
|
||||
EXPECT_EQ(purple.green, 0x00);
|
||||
EXPECT_EQ(purple.blue, 0x80);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ColorOrange_001
|
||||
* @tc.desc: Verify Orange function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ColorTest, ColorOrange_001, TestSize.Level0)
|
||||
{
|
||||
ColorType orange = Color::Orange();
|
||||
|
||||
EXPECT_EQ(orange.red, 0xFF);
|
||||
EXPECT_EQ(orange.green, 0xA5);
|
||||
EXPECT_EQ(orange.blue, 0x00);
|
||||
}
|
||||
} // namespace OHOS
|
||||
Executable
+317
@@ -0,0 +1,317 @@
|
||||
/*
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "geometry2d.h"
|
||||
|
||||
#include <climits>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
using namespace testing::ext;
|
||||
|
||||
namespace OHOS {
|
||||
namespace {
|
||||
const uint16_t VECTOR2_SIZE = 4;
|
||||
const int16_t BASE_VALUE = BASE_VALUE;
|
||||
const int16_t TWOFOLD_VALUE = 2 * BASE_VALUE;
|
||||
const int16_t THREEFOLD_VALUE = 3 * BASE_VALUE;
|
||||
const int16_t FOURFOLD_VALUE = 4 * BASE_VALUE;
|
||||
const int16_t FIVEFOLD_VALUE = 5 * BASE_VALUE;
|
||||
}
|
||||
|
||||
class Geometry2dTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase(void) {}
|
||||
static void TearDownTestCase(void) {}
|
||||
};
|
||||
|
||||
/**
|
||||
* @tc.name: LineOperator_001
|
||||
* @tc.desc: Verify index operator function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(Geometry2dTest, LineOperator_001, TestSize.Level0)
|
||||
{
|
||||
Vector2<int16_t> pt1 = { BASE_VALUE, TWOFOLD_VALUE };
|
||||
Vector2<int16_t> pt2 = { THREEFOLD_VALUE, FOURFOLD_VALUE };
|
||||
Line* line = new Line(pt1, pt2);
|
||||
|
||||
EXPECT_EQ(line->operator[](0).x_, BASE_VALUE);
|
||||
EXPECT_EQ(line->operator[](0).y_, TWOFOLD_VALUE);
|
||||
EXPECT_EQ(line->operator[](1).x_, THREEFOLD_VALUE);
|
||||
EXPECT_EQ(line->operator[](1).y_, FOURFOLD_VALUE);
|
||||
delete line;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: LineOperator_002
|
||||
* @tc.desc: Verify index operator function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(Geometry2dTest, LineOperator_002, TestSize.Level1)
|
||||
{
|
||||
int16_t x1 = BASE_VALUE;
|
||||
int16_t y1 = TWOFOLD_VALUE;
|
||||
int16_t x2 = THREEFOLD_VALUE;
|
||||
int16_t y2 = FOURFOLD_VALUE;
|
||||
Line* line = new Line(BASE_VALUE, TWOFOLD_VALUE, THREEFOLD_VALUE, FOURFOLD_VALUE);
|
||||
if (line == nullptr) {
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
EXPECT_EQ(line->operator[](0).x_, BASE_VALUE);
|
||||
EXPECT_EQ(line->operator[](0).y_, TWOFOLD_VALUE);
|
||||
EXPECT_EQ(line->operator[](1).x_, THREEFOLD_VALUE);
|
||||
EXPECT_EQ(line->operator[](1).y_, FOURFOLD_VALUE);
|
||||
delete line;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: PolygonMakeAABB_001
|
||||
* @tc.desc: Verify MakeAABB function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(Geometry2dTest, PolygonMakeAABB_001, TestSize.Level0)
|
||||
{
|
||||
Vector2<int16_t> vertexes[VECTOR2_SIZE] =
|
||||
{ {0, 0}, {FIVEFOLD_VALUE, BASE_VALUE},
|
||||
{THREEFOLD_VALUE, FIVEFOLD_VALUE}, {BASE_VALUE, THREEFOLD_VALUE} };
|
||||
Polygon* polygon = new Polygon(vertexes, VECTOR2_SIZE);
|
||||
if (polygon == nullptr) {
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
Rect rect = polygon->MakeAABB();
|
||||
|
||||
EXPECT_EQ(rect.GetLeft(), 0);
|
||||
EXPECT_EQ(rect.GetTop(), 0);
|
||||
EXPECT_EQ(rect.GetRight(), FIVEFOLD_VALUE);
|
||||
EXPECT_EQ(rect.GetBottom(), FIVEFOLD_VALUE);
|
||||
delete polygon;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: PolygonGetVertexNum_001
|
||||
* @tc.desc: Verify GetVertexNum function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(Geometry2dTest, PolygonGetVertexNum_001, TestSize.Level0)
|
||||
{
|
||||
Vector2<int16_t> vertexes[VECTOR2_SIZE] =
|
||||
{ { 0, 0 }, { FIVEFOLD_VALUE, BASE_VALUE },
|
||||
{ THREEFOLD_VALUE, FIVEFOLD_VALUE }, { BASE_VALUE, THREEFOLD_VALUE } };
|
||||
Polygon* polygon = new Polygon(vertexes, VECTOR2_SIZE);
|
||||
if (polygon == nullptr) {
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
EXPECT_EQ(polygon->GetVertexNum(), VECTOR2_SIZE);
|
||||
delete polygon;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: PolygonSetVertexNum_001
|
||||
* @tc.desc: Verify SetVertexNum function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(Geometry2dTest, PolygonSetVertexNum_001, TestSize.Level0)
|
||||
{
|
||||
Polygon* polygon = new Polygon();
|
||||
if (polygon == nullptr) {
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
const uint16_t VERTEX_NUM = 8;
|
||||
polygon->SetVertexNum(VERTEX_NUM);
|
||||
|
||||
EXPECT_EQ(polygon->GetVertexNum(), VERTEX_NUM);
|
||||
delete polygon;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: PolygonOperator_001
|
||||
* @tc.desc: Verify operator[] function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(Geometry2dTest, PolygonOperator_001, TestSize.Level0)
|
||||
{
|
||||
Vector2<int16_t> vertexes[VECTOR2_SIZE] =
|
||||
{ { 0, 0 }, { FIVEFOLD_VALUE, BASE_VALUE },
|
||||
{ THREEFOLD_VALUE, FIVEFOLD_VALUE }, { BASE_VALUE, THREEFOLD_VALUE } };
|
||||
Polygon* polygon = new Polygon(vertexes, VECTOR2_SIZE);
|
||||
if (polygon == nullptr) {
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
EXPECT_EQ(polygon->operator[](1).x_, FIVEFOLD_VALUE);
|
||||
EXPECT_EQ(polygon->operator[](2).y_, FIVEFOLD_VALUE);
|
||||
|
||||
delete polygon;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: PolygonOperator_002
|
||||
* @tc.desc: Verify operator[] function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(Geometry2dTest, PolygonOperator_002, TestSize.Level0)
|
||||
{
|
||||
Rect rect(BASE_VALUE, TWOFOLD_VALUE, THREEFOLD_VALUE, FOURFOLD_VALUE);
|
||||
Polygon* polygon = new Polygon(rect);
|
||||
if (polygon == nullptr) {
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
uint16_t i = 0;
|
||||
EXPECT_EQ(polygon->operator[](i).x_, BASE_VALUE);
|
||||
EXPECT_EQ(polygon->operator[](i++).y_, TWOFOLD_VALUE);
|
||||
EXPECT_EQ(polygon->operator[](i).x_, THREEFOLD_VALUE);
|
||||
EXPECT_EQ(polygon->operator[](i++).y_, TWOFOLD_VALUE);
|
||||
EXPECT_EQ(polygon->operator[](i).x_, THREEFOLD_VALUE);
|
||||
EXPECT_EQ(polygon->operator[](i++).y_, FOURFOLD_VALUE);
|
||||
EXPECT_EQ(polygon->operator[](i).x_, BASE_VALUE);
|
||||
EXPECT_EQ(polygon->operator[](i++).y_, FOURFOLD_VALUE);
|
||||
EXPECT_EQ(polygon->GetVertexNum(), VECTOR2_SIZE);
|
||||
|
||||
delete polygon;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Geometry2dIntersect_001
|
||||
* @tc.desc: Verify Intersect function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(Geometry2dTest, Geometry2dIntersect_001, TestSize.Level0)
|
||||
{
|
||||
Vector2<int16_t> pt11 = { 0, TWOFOLD_VALUE };
|
||||
Vector2<int16_t> pt12 = { FOURFOLD_VALUE, TWOFOLD_VALUE };
|
||||
Line* line1 = new Line(pt11, pt12);
|
||||
if (line1 == nullptr) {
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
Vector2<int16_t> pt21 = { TWOFOLD_VALUE, 0 };
|
||||
Vector2<int16_t> pt22 = { TWOFOLD_VALUE, FOURFOLD_VALUE };
|
||||
Line* line2 = new Line(pt21, pt22);
|
||||
if (line2 == nullptr) {
|
||||
delete line1;
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
Vector2<int16_t> pt31 = { 0, 0 };
|
||||
Vector2<int16_t> pt32 = { FIVEFOLD_VALUE, 0 };
|
||||
Line* line3 = new Line(pt31, pt32);
|
||||
if (line3 == nullptr) {
|
||||
delete line1;
|
||||
delete line2;
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
Vector2<int16_t> out;
|
||||
|
||||
EXPECT_EQ(Intersect(*line1, *line2, out), false);
|
||||
EXPECT_EQ(out.x_, TWOFOLD_VALUE);
|
||||
EXPECT_EQ(out.y_, TWOFOLD_VALUE);
|
||||
|
||||
delete line1;
|
||||
delete line2;
|
||||
delete line3;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Geometry2dIsIntersect_001
|
||||
* @tc.desc: Verify IsIntersect function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(Geometry2dTest, Geometry2dIsIntersect_001, TestSize.Level0)
|
||||
{
|
||||
Vector2<int16_t> pt11 = { 0, TWOFOLD_VALUE };
|
||||
Vector2<int16_t> pt12 = { FOURFOLD_VALUE, TWOFOLD_VALUE };
|
||||
Line* line1 = new Line(pt11, pt12);
|
||||
if (line1 == nullptr) {
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
Vector2<int16_t> pt21 = { TWOFOLD_VALUE, 0 };
|
||||
Vector2<int16_t> pt22 = { TWOFOLD_VALUE, FOURFOLD_VALUE };
|
||||
Line* line2 = new Line(pt21, pt22);
|
||||
if (line2 == nullptr) {
|
||||
delete line1;
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
Vector2<int16_t> pt31 = { 0, 0 };
|
||||
Vector2<int16_t> pt32 = { FIVEFOLD_VALUE, 0 };
|
||||
Line* line3 = new Line(pt31, pt32);
|
||||
if (line3 == nullptr) {
|
||||
delete line1;
|
||||
delete line2;
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
EXPECT_EQ(IsIntersect(*line1, *line2), true);
|
||||
|
||||
delete line1;
|
||||
delete line2;
|
||||
delete line3;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Geometry2dClip_001
|
||||
* @tc.desc: Verify Clip function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(Geometry2dTest, Geometry2dClip_001, TestSize.Level0)
|
||||
{
|
||||
Vector2<int16_t> vertexes[VECTOR2_SIZE] =
|
||||
{ { 0, 0 }, { FIVEFOLD_VALUE, BASE_VALUE },
|
||||
{ THREEFOLD_VALUE, FIVEFOLD_VALUE }, { BASE_VALUE, THREEFOLD_VALUE } };
|
||||
Polygon* polygon = new Polygon(vertexes, VECTOR2_SIZE);
|
||||
if (polygon == nullptr) {
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
Vector2<int16_t> pt11 = { BASE_VALUE, THREEFOLD_VALUE };
|
||||
Vector2<int16_t> pt12 = { FIVEFOLD_VALUE, BASE_VALUE };
|
||||
Line* line = new Line(pt11, pt12);
|
||||
if (line == nullptr) {
|
||||
delete polygon;
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
Clip(*polygon, *line);
|
||||
uint16_t i = 0;
|
||||
EXPECT_EQ(polygon->GetVertexNum(), 0);
|
||||
EXPECT_EQ(polygon->operator[](i).x_, FIVEFOLD_VALUE);
|
||||
EXPECT_EQ(polygon->operator[](i++).y_, BASE_VALUE);
|
||||
EXPECT_EQ(polygon->operator[](i).x_, BASE_VALUE);
|
||||
EXPECT_EQ(polygon->operator[](i++).y_, THREEFOLD_VALUE);
|
||||
EXPECT_EQ(polygon->operator[](i).x_, 0);
|
||||
EXPECT_EQ(polygon->operator[](i++).y_, 0);
|
||||
|
||||
delete polygon;
|
||||
delete line;
|
||||
}
|
||||
} // namespace OHOS
|
||||
Executable
+719
@@ -0,0 +1,719 @@
|
||||
/*
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "graphic_math.h"
|
||||
|
||||
#include <climits>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
using namespace testing::ext;
|
||||
|
||||
namespace OHOS {
|
||||
namespace {
|
||||
const Point POINT1 = { 5, 4 };
|
||||
const Point POINT2 = { 3, 2 };
|
||||
const uint16_t MAX_NUM_8BIT = 256;
|
||||
const uint32_t MAX_NUM_16BIT = 32768;
|
||||
}
|
||||
class MathTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase(void) {}
|
||||
static void TearDownTestCase(void) {}
|
||||
};
|
||||
|
||||
/**
|
||||
* @tc.name: MathSin_001
|
||||
* @tc.desc: Verify Sin function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(MathTest, MathSin_001, TestSize.Level0)
|
||||
{
|
||||
EXPECT_EQ(Sin(0), 0);
|
||||
EXPECT_EQ(Sin(QUARTER_IN_DEGREE), 1);
|
||||
EXPECT_EQ(Sin(SEMICIRCLE_IN_DEGREE), 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: MathFastAtan2_001
|
||||
* @tc.desc: Verify FastAtan2 function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(MathTest, MathFastAtan2_001, TestSize.Level0)
|
||||
{
|
||||
EXPECT_EQ(FastAtan2(0, 1), 0);
|
||||
EXPECT_EQ(FastAtan2(1, 0), QUARTER_IN_DEGREE);
|
||||
EXPECT_EQ(FastAtan2(0, -1), SEMICIRCLE_IN_DEGREE);
|
||||
EXPECT_EQ(FastAtan2(-1, 0), THREE_QUARTER_IN_DEGREE);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @tc.name: MathFloatToInt64_001
|
||||
* @tc.desc: Verify FloatToInt64 function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(MathTest, MathFloatToInt64_001, TestSize.Level0)
|
||||
{
|
||||
EXPECT_EQ(FloatToInt64(1), MAX_NUM_8BIT);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: MathSqrt_001
|
||||
* @tc.desc: Verify Sqrt function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(MathTest, MathSqrt_001, TestSize.Level0)
|
||||
{
|
||||
const float testInteger = 2.0;
|
||||
const float testIntegerSquared = testInteger * testInteger;
|
||||
const float testFloat = 2.121320; // 2.121320: 4.5 squaring results
|
||||
const float testFloatSquared = 4.5;
|
||||
const float accuracy = 0.000001;
|
||||
|
||||
EXPECT_EQ(Sqrt(0), 0);
|
||||
float ret = Sqrt(testIntegerSquared);
|
||||
if (ret > testInteger - accuracy && ret < testInteger + accuracy) {
|
||||
EXPECT_EQ(0, 0);
|
||||
} else {
|
||||
EXPECT_NE(0, 0);
|
||||
}
|
||||
|
||||
ret = Sqrt(testFloatSquared);
|
||||
if (ret > testFloat - accuracy && ret < testFloat + accuracy) {
|
||||
EXPECT_EQ(0, 0);
|
||||
} else {
|
||||
EXPECT_NE(0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Vector2Dot_001
|
||||
* @tc.desc: Verify Dot function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(MathTest, Vector2Dot_001, TestSize.Level0)
|
||||
{
|
||||
Vector2<uint16_t>* vector1 = new Vector2<uint16_t>(POINT1.x, POINT1.y);
|
||||
if (vector1 == nullptr) {
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
Vector2<uint16_t>* vector2 = new Vector2<uint16_t>(POINT2.x, POINT2.y);
|
||||
if (vector2 == nullptr) {
|
||||
delete vector1;
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
uint16_t value = POINT1.x * POINT2.x + POINT1.y * POINT2.y;
|
||||
|
||||
EXPECT_EQ(vector1->Dot(*vector2), value);
|
||||
|
||||
delete vector1;
|
||||
delete vector2;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Vector2Cross_001
|
||||
* @tc.desc: Verify Cross function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(MathTest, Vector2Cross_001, TestSize.Level0)
|
||||
{
|
||||
Vector2<uint16_t>* vector1 = new Vector2<uint16_t>(POINT1.x, POINT1.y);
|
||||
if (vector1 == nullptr) {
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
Vector2<uint16_t>* vector2 = new Vector2<uint16_t>(POINT2.x, POINT2.y);
|
||||
if (vector2 == nullptr) {
|
||||
delete vector1;
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
uint16_t value = POINT1.x * POINT2.y - POINT1.y * POINT2.x;
|
||||
|
||||
EXPECT_EQ(vector1->Cross(*vector2), value);
|
||||
|
||||
delete vector1;
|
||||
delete vector2;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Vector2Operator_001
|
||||
* @tc.desc: Verify negative operator function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(MathTest, Vector2Operator_001, TestSize.Level0)
|
||||
{
|
||||
Vector2<uint16_t>* vector1 = new Vector2<uint16_t>(POINT1.x, POINT1.y);
|
||||
if (vector1 == nullptr) {
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
Vector2<uint16_t> vector3 = vector1->operator-();
|
||||
|
||||
EXPECT_EQ(vector3.x_, 65531); // 65531: -POINT1.x
|
||||
EXPECT_EQ(vector3.y_, 65532); // 65532: -POINT1.y
|
||||
delete vector1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Vector2Operator_002
|
||||
* @tc.desc: Verify minus operator function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(MathTest, Vector2Operator_002, TestSize.Level0)
|
||||
{
|
||||
Vector2<uint16_t>* vector1 = new Vector2<uint16_t>(POINT1.x, POINT1.y);
|
||||
if (vector1 == nullptr) {
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
Vector2<uint16_t>* vector2 = new Vector2<uint16_t>(POINT2.x, POINT2.y);
|
||||
if (vector2 == nullptr) {
|
||||
delete vector1;
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
Vector2<uint16_t> vector3 = vector1->operator-(*vector2);
|
||||
|
||||
EXPECT_EQ(vector3.x_, POINT1.x - POINT2.x);
|
||||
EXPECT_EQ(vector3.y_, POINT1.y - POINT2.y);
|
||||
delete vector1;
|
||||
delete vector2;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Vector2Operator_003
|
||||
* @tc.desc: Verify addition operator function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(MathTest, Vector2Operator_003, TestSize.Level0)
|
||||
{
|
||||
Vector2<uint16_t>* vector1 = new Vector2<uint16_t>(POINT1.x, POINT1.y);
|
||||
if (vector1 == nullptr) {
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
Vector2<uint16_t>* vector2 = new Vector2<uint16_t>(POINT2.x, POINT2.y);
|
||||
if (vector2 == nullptr) {
|
||||
delete vector1;
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
Vector2<uint16_t> vector3 = vector1->operator+(*vector2);
|
||||
|
||||
EXPECT_EQ(vector3.x_, POINT1.x + POINT2.x);
|
||||
EXPECT_EQ(vector3.y_, POINT1.y + POINT2.y);
|
||||
delete vector1;
|
||||
delete vector2;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Vector2Operator_004
|
||||
* @tc.desc: Verify multiplication operator function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(MathTest, Vector2Operator_004, TestSize.Level0)
|
||||
{
|
||||
Vector2<uint16_t>* vector1 = new Vector2<uint16_t>(POINT1.x, POINT1.y);
|
||||
if (vector1 == nullptr) {
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
Vector2<uint16_t> vector3 = vector1->operator*(2);
|
||||
EXPECT_EQ(vector3.x_, POINT1.x * 2);
|
||||
EXPECT_EQ(vector3.y_, POINT1.y * 2);
|
||||
delete vector1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Vector2Operator_005
|
||||
* @tc.desc: Verify equal operator function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(MathTest, Vector2Operator_005, TestSize.Level0)
|
||||
{
|
||||
Vector2<uint16_t>* vector1 = new Vector2<uint16_t>(POINT1.x, POINT1.y);
|
||||
if (vector1 == nullptr) {
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
Vector2<uint16_t>* vector2 = new Vector2<uint16_t>(POINT2.x, POINT2.y);
|
||||
if (vector2 == nullptr) {
|
||||
delete vector1;
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
Vector2<uint16_t>* vector3 = new Vector2<uint16_t>(POINT1.x, POINT1.y);
|
||||
if (vector3 == nullptr) {
|
||||
delete vector1;
|
||||
delete vector2;
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
EXPECT_EQ(vector1->operator==(*vector2), false);
|
||||
EXPECT_EQ(vector1->operator==(*vector3), true);
|
||||
|
||||
delete vector1;
|
||||
delete vector2;
|
||||
delete vector3;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Vector2Operator_006
|
||||
* @tc.desc: Verify assignment operator function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(MathTest, Vector2Operator_006, TestSize.Level0)
|
||||
{
|
||||
Vector2<uint16_t>* vector2 = new Vector2<uint16_t>(POINT2.x, POINT2.y);
|
||||
if (vector2 == nullptr) {
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
Vector2<uint16_t>* vector3 = new Vector2<uint16_t>(POINT1.x, POINT1.y);
|
||||
if (vector3 == nullptr) {
|
||||
delete vector2;
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
vector3->operator=(*vector2);
|
||||
EXPECT_EQ(vector3->x_, POINT2.x);
|
||||
EXPECT_EQ(vector3->y_, POINT2.y);
|
||||
|
||||
delete vector2;
|
||||
delete vector3;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Vector2Operator_007
|
||||
* @tc.desc: Verify plus equal operator function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(MathTest, Vector2Operator_007, TestSize.Level0)
|
||||
{
|
||||
Vector2<uint16_t>* vector2 = new Vector2<uint16_t>(POINT2.x, POINT2.y);
|
||||
if (vector2 == nullptr) {
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
Vector2<uint16_t>* vector3 = new Vector2<uint16_t>(POINT1.x, POINT1.y);
|
||||
if (vector3 == nullptr) {
|
||||
delete vector2;
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
vector3->operator+=(*vector2);
|
||||
EXPECT_EQ(vector3->x_, POINT1.x + POINT2.x);
|
||||
EXPECT_EQ(vector3->y_, POINT1.y + POINT2.y);
|
||||
|
||||
delete vector2;
|
||||
delete vector3;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Vector2Operator_008
|
||||
* @tc.desc: Verify minus equal operator function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(MathTest, Vector2Operator_008, TestSize.Level0)
|
||||
{
|
||||
Vector2<uint16_t>* vector2 = new Vector2<uint16_t>(POINT2.x, POINT2.y);
|
||||
if (vector2 == nullptr) {
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
Vector2<uint16_t>* vector3 = new Vector2<uint16_t>(POINT1.x, POINT1.y);
|
||||
if (vector3 == nullptr) {
|
||||
delete vector2;
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
vector3->operator-=(*vector2);
|
||||
EXPECT_EQ(vector3->x_, POINT1.x - POINT2.x);
|
||||
EXPECT_EQ(vector3->y_, POINT1.y - POINT2.y);
|
||||
|
||||
delete vector2;
|
||||
delete vector3;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Vector3Operator_001
|
||||
* @tc.desc: Verify index operator function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(MathTest, Vector3Operator_001, TestSize.Level0)
|
||||
{
|
||||
const uint16_t posX = 3;
|
||||
const uint16_t posY = 5;
|
||||
const uint16_t posZ = 7;
|
||||
Vector3<uint16_t>* vector1 = new Vector3<uint16_t>(posX, posY, posZ);
|
||||
if (vector1 == nullptr) {
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
uint16_t i = 0;
|
||||
EXPECT_EQ(vector1->operator[](i++), posX);
|
||||
EXPECT_EQ(vector1->operator[](i++), posY);
|
||||
EXPECT_EQ(vector1->operator[](i++), posZ);
|
||||
|
||||
delete vector1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Vector3Operator_002
|
||||
* @tc.desc: Verify equal operator function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(MathTest, Vector3Operator_002, TestSize.Level0)
|
||||
{
|
||||
const uint16_t posX = 3;
|
||||
const uint16_t posY = 5;
|
||||
const uint16_t posZ = 7;
|
||||
Vector3<uint16_t>* vector1 = new Vector3<uint16_t>(posX, posY, posZ);
|
||||
if (vector1 == nullptr) {
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
Vector3<uint16_t>* vector2 = new Vector3<uint16_t>(posX, posY, posZ);
|
||||
if (vector2 == nullptr) {
|
||||
delete vector1;
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
Vector3<uint16_t>* vector3 = new Vector3<uint16_t>(posX - 1, posY, posZ);
|
||||
if (vector3 == nullptr) {
|
||||
delete vector1;
|
||||
delete vector2;
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
EXPECT_EQ(vector1->operator==(*vector2), true);
|
||||
EXPECT_EQ(vector1->operator==(*vector3), false);
|
||||
|
||||
delete vector1;
|
||||
delete vector2;
|
||||
delete vector3;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Matrix3GetData_001
|
||||
* @tc.desc: Verify GetData function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(MathTest, Matrix3GetData_001, TestSize.Level0)
|
||||
{
|
||||
Matrix3<uint16_t>* matrix = new Matrix3<uint16_t>(1, 1, 1, 1, 1, 1, 1, 1, 1);
|
||||
if (matrix == nullptr) {
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
EXPECT_EQ(matrix->GetData()[0], 1);
|
||||
|
||||
delete matrix;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Matrix3Operator_001
|
||||
* @tc.desc: Verify multiplication operator function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(MathTest, Matrix3Operator_001, TestSize.Level0)
|
||||
{
|
||||
Matrix3<uint16_t> matrix1(1, 1, 1, 1, 1, 1, 1, 1, 1);
|
||||
/*
|
||||
* 1: m00 Indicates the element in row 1 and column 1 of the matrix.
|
||||
* 2: m01 Indicates the element in row 1 and column 2 of the matrix.
|
||||
* 3: m02 Indicates the element in row 1 and column 3 of the matrix.
|
||||
* 4: m10 Indicates the element in row 2 and column 1 of the matrix.
|
||||
* 5: m11 Indicates the element in row 2 and column 2 of the matrix.
|
||||
* 6: m12 Indicates the element in row 2 and column 3 of the matrix.
|
||||
* 7: m20 Indicates the element in row 3 and column 1 of the matrix.
|
||||
* 8: m21 Indicates the element in row 3 and column 2 of the matrix.
|
||||
* 9: m22 Indicates the element in row 3 and column 3 of the matrix.
|
||||
*/
|
||||
Matrix3<uint16_t> matrix2(1, 2, 3, 4, 5, 6, 7, 8, 9);
|
||||
Matrix3<uint16_t> matrix3 = matrix1 * matrix2;
|
||||
|
||||
uint16_t i = 0;
|
||||
// 6: data_[0] * oData[0] + data_[3] * oData[1] + data_[6] * oData[2];
|
||||
EXPECT_EQ(matrix3.GetData()[i++], 6);
|
||||
// 6: data_[1] * oData[0] + data_[4] * oData[1] + data_[7] * oData[2];
|
||||
EXPECT_EQ(matrix3.GetData()[i++], 6);
|
||||
// 6: data_[2] * oData[0] + data_[5] * oData[1] + data_[8] * oData[2];
|
||||
EXPECT_EQ(matrix3.GetData()[i++], 6);
|
||||
// 15: data_[0] * oData[3] + data_[3] * oData[4] + data_[6] * oData[5];
|
||||
EXPECT_EQ(matrix3.GetData()[i++], 15);
|
||||
// 15: data_[1] * oData[3] + data_[4] * oData[4] + data_[7] * oData[5];
|
||||
EXPECT_EQ(matrix3.GetData()[i++], 15);
|
||||
// 15: data_[2] * oData[3] + data_[5] * oData[4] + data_[8] * oData[5];
|
||||
EXPECT_EQ(matrix3.GetData()[i++], 15);
|
||||
// 24: data_[0] * oData[6] + data_[3] * oData[7] + data_[6] * oData[8];
|
||||
EXPECT_EQ(matrix3.GetData()[i++], 24);
|
||||
// 24: data_[1] * oData[6] + data_[4] * oData[7] + data_[7] * oData[8];
|
||||
EXPECT_EQ(matrix3.GetData()[i++], 24);
|
||||
// 24: data_[2] * oData[6] + data_[5] * oData[7] + data_[8] * oData[8];
|
||||
EXPECT_EQ(matrix3.GetData()[i++], 24);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Matrix3Operator_002
|
||||
* @tc.desc: Verify multiplication operator function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(MathTest, Matrix3Operator_002, TestSize.Level0)
|
||||
{
|
||||
Matrix3<uint16_t> matrix1(1, 1, 1, 1, 1, 1, 1, 1, 1);
|
||||
/*
|
||||
* 1: Indicates the X coordinate.
|
||||
* 2: Indicates the Y coordinate.
|
||||
* 3: Indicates the Z coordinate.
|
||||
*/
|
||||
Vector3<uint16_t> vector1(1, 2, 3);
|
||||
Vector3<uint16_t> vector2 = matrix1 * vector1;
|
||||
|
||||
// 6: data_[0] * oData[0] + data_[3] * oData[1] + data_[6] * oData[2];
|
||||
EXPECT_EQ(vector2.x_, 6);
|
||||
// 6: data_[1] * oData[0] + data_[4] * oData[1] + data_[7] * oData[2];
|
||||
EXPECT_EQ(vector2.y_, 6);
|
||||
// 6: data_[2] * oData[0] + data_[5] * oData[1] + data_[8] * oData[2];
|
||||
EXPECT_EQ(vector2.z_, 6);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Matrix3Operator_003
|
||||
* @tc.desc: Verify index operator function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(MathTest, Matrix3Operator_003, TestSize.Level0)
|
||||
{
|
||||
Matrix3<uint16_t>* matrix = new Matrix3<uint16_t>(1, 0, 0, 1, 0, 0, 1, 0, 0);
|
||||
if (matrix == nullptr) {
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
uint16_t i = 0;
|
||||
EXPECT_EQ(*matrix->operator[](i++), 1);
|
||||
EXPECT_EQ(*matrix->operator[](i++), 1);
|
||||
EXPECT_EQ(*matrix->operator[](i++), 1);
|
||||
|
||||
delete matrix;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Matrix3Operator_004
|
||||
* @tc.desc: Verify assignment operator function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(MathTest, Matrix3Operator_004, TestSize.Level0)
|
||||
{
|
||||
Matrix3<uint16_t>* matrix = new Matrix3<uint16_t>(1, 0, 0, 1, 0, 0, 1, 0, 0);
|
||||
if (matrix == nullptr) {
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
Matrix3<uint16_t>* matrix2 = new Matrix3<uint16_t>(1, 1, 1, 1, 1, 1, 1, 1, 1);
|
||||
if (matrix2 == nullptr) {
|
||||
delete matrix;
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
matrix->operator=(*matrix2);
|
||||
uint16_t i = 0;
|
||||
EXPECT_EQ(matrix->GetData()[i++], 1);
|
||||
EXPECT_EQ(matrix->GetData()[i++], 1);
|
||||
EXPECT_EQ(matrix->GetData()[i++], 1);
|
||||
EXPECT_EQ(matrix->GetData()[i++], 1);
|
||||
EXPECT_EQ(matrix->GetData()[i++], 1);
|
||||
EXPECT_EQ(matrix->GetData()[i++], 1);
|
||||
EXPECT_EQ(matrix->GetData()[i++], 1);
|
||||
EXPECT_EQ(matrix->GetData()[i++], 1);
|
||||
EXPECT_EQ(matrix->GetData()[i++], 1);
|
||||
|
||||
delete matrix;
|
||||
delete matrix2;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Matrix3Determinant_001
|
||||
* @tc.desc: Verify Determinant operator function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(MathTest, Matrix3Determinant_001, TestSize.Level0)
|
||||
{
|
||||
Matrix3<uint16_t>* matrix2 = new Matrix3<uint16_t>(1, 1, 1, 1, 1, 1, 1, 1, 1);
|
||||
if (matrix2 == nullptr) {
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
EXPECT_EQ(matrix2->Determinant(), 0);
|
||||
|
||||
delete matrix2;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Matrix3Inverse_001
|
||||
* @tc.desc: Verify Inverse operator function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(MathTest, Matrix3Inverse_001, TestSize.Level0)
|
||||
{
|
||||
Matrix3<uint16_t>* matrix1 = new Matrix3<uint16_t>(1, 1, 1, 1, 1, 1, 1, 1, 1);
|
||||
if (matrix1 == nullptr) {
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
Matrix3<uint16_t> matrix2 = matrix1->Inverse();
|
||||
|
||||
uint16_t i = 0;
|
||||
EXPECT_EQ(matrix2.GetData()[i++], 1);
|
||||
EXPECT_EQ(matrix2.GetData()[i++], 1);
|
||||
EXPECT_EQ(matrix2.GetData()[i++], 1);
|
||||
EXPECT_EQ(matrix2.GetData()[i++], 1);
|
||||
EXPECT_EQ(matrix2.GetData()[i++], 1);
|
||||
EXPECT_EQ(matrix2.GetData()[i++], 1);
|
||||
EXPECT_EQ(matrix2.GetData()[i++], 1);
|
||||
EXPECT_EQ(matrix2.GetData()[i++], 1);
|
||||
EXPECT_EQ(matrix2.GetData()[i++], 1);
|
||||
|
||||
delete matrix1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Matrix3Operator_005
|
||||
* @tc.desc: Verify equal operator function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(MathTest, Matrix3Operator_005, TestSize.Level0)
|
||||
{
|
||||
Matrix3<uint16_t>* matrix1 = new Matrix3<uint16_t>(1, 1, 1, 1, 1, 1, 1, 1, 1);
|
||||
if (matrix1 == nullptr) {
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
Matrix3<uint16_t>* matrix2 = new Matrix3<uint16_t>(1, 1, 1, 1, 1, 1, 1, 1, 1);
|
||||
if (matrix2 == nullptr) {
|
||||
delete matrix1;
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
Matrix3<uint16_t>* matrix3 = new Matrix3<uint16_t>(1, 1, 1, 1, 1, 1, 0, 1, 1);
|
||||
if (matrix3 == nullptr) {
|
||||
delete matrix1;
|
||||
delete matrix2;
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
EXPECT_EQ(matrix1->operator==(*matrix2), true);
|
||||
EXPECT_EQ(matrix1->operator==(*matrix3), false);
|
||||
|
||||
delete matrix1;
|
||||
delete matrix2;
|
||||
delete matrix3;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Matrix3Rotate_001
|
||||
* @tc.desc: Verify Rotate function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(MathTest, Matrix3Rotate_001, TestSize.Level0)
|
||||
{
|
||||
Matrix3<uint64_t> rotate = Matrix3<uint64_t>::Rotate(0, Vector2<uint64_t>(0, 0));
|
||||
uint16_t i = 0;
|
||||
EXPECT_EQ(rotate.GetData()[i++], 1);
|
||||
EXPECT_EQ(rotate.GetData()[i++], 0);
|
||||
EXPECT_EQ(rotate.GetData()[i++], 0);
|
||||
EXPECT_EQ(rotate.GetData()[i++], 0);
|
||||
EXPECT_EQ(rotate.GetData()[i++], 1);
|
||||
EXPECT_EQ(rotate.GetData()[i++], 0);
|
||||
EXPECT_EQ(rotate.GetData()[i++], 0);
|
||||
EXPECT_EQ(rotate.GetData()[i++], 0);
|
||||
EXPECT_EQ(rotate.GetData()[i++], 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Matrix3Scale_001
|
||||
* @tc.desc: Verify Scale function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(MathTest, Matrix3Scale_001, TestSize.Level0)
|
||||
{
|
||||
Matrix3<int64_t> scale =
|
||||
Matrix3<int64_t>::Scale(Vector2<int64_t>(1, 1), Vector2<int64_t>(0, 0));
|
||||
uint16_t i = 0;
|
||||
EXPECT_EQ(scale.GetData()[i++], 1);
|
||||
EXPECT_EQ(scale.GetData()[i++], 0);
|
||||
EXPECT_EQ(scale.GetData()[i++], 0);
|
||||
EXPECT_EQ(scale.GetData()[i++], 0);
|
||||
EXPECT_EQ(scale.GetData()[i++], 1);
|
||||
EXPECT_EQ(scale.GetData()[i++], 0);
|
||||
EXPECT_EQ(scale.GetData()[i++], 0);
|
||||
EXPECT_EQ(scale.GetData()[i++], 0);
|
||||
EXPECT_EQ(scale.GetData()[i++], 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Matrix3Translate_001
|
||||
* @tc.desc: Verify Translate function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(MathTest, Matrix3Translate_001, TestSize.Level0)
|
||||
{
|
||||
Matrix3<int64_t> translate = Matrix3<int64_t>::Translate(Vector2<int64_t>(0, 0));
|
||||
uint16_t i = 0;
|
||||
EXPECT_EQ(translate.GetData()[i++], 1);
|
||||
EXPECT_EQ(translate.GetData()[i++], 0);
|
||||
EXPECT_EQ(translate.GetData()[i++], 0);
|
||||
EXPECT_EQ(translate.GetData()[i++], 0);
|
||||
EXPECT_EQ(translate.GetData()[i++], 1);
|
||||
EXPECT_EQ(translate.GetData()[i++], 0);
|
||||
EXPECT_EQ(translate.GetData()[i++], 0);
|
||||
EXPECT_EQ(translate.GetData()[i++], 0);
|
||||
EXPECT_EQ(translate.GetData()[i++], 1);
|
||||
}
|
||||
} // namespace OHOS
|
||||
Executable
+357
@@ -0,0 +1,357 @@
|
||||
/*
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "list.h"
|
||||
|
||||
#include <climits>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
using namespace testing::ext;
|
||||
namespace OHOS {
|
||||
namespace {
|
||||
const uint16_t FIRST_VALUE = 1;
|
||||
const uint16_t SECOND_VALUE = 2;
|
||||
const uint16_t THIRD_VALUE = 3;
|
||||
}
|
||||
|
||||
class ListTest : public testing::Test {
|
||||
public:
|
||||
ListTest() : list_(nullptr) {}
|
||||
~ListTest() {}
|
||||
static void SetUpTestCase(void) {}
|
||||
static void TearDownTestCase(void) {}
|
||||
void SetUp();
|
||||
void TearDown();
|
||||
|
||||
List<uint16_t>* list_;
|
||||
};
|
||||
|
||||
void ListTest::SetUp()
|
||||
{
|
||||
if (list_ == nullptr) {
|
||||
list_ = new List<uint16_t>();
|
||||
}
|
||||
}
|
||||
|
||||
void ListTest::TearDown()
|
||||
{
|
||||
if (list_ != nullptr) {
|
||||
delete list_;
|
||||
list_ = nullptr;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @tc.name: ListFront_001
|
||||
* @tc.desc: Verify Front function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ListTest, ListFront_001, TestSize.Level0)
|
||||
{
|
||||
if (list_ == nullptr) {
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
list_->PushBack(FIRST_VALUE);
|
||||
list_->PushBack(SECOND_VALUE);
|
||||
EXPECT_EQ(list_->Front(), FIRST_VALUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ListBack_001
|
||||
* @tc.desc: Verify Back function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ListTest, ListBack_001, TestSize.Level0)
|
||||
{
|
||||
if (list_ == nullptr) {
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
list_->PushBack(FIRST_VALUE);
|
||||
list_->PushBack(SECOND_VALUE);
|
||||
EXPECT_EQ(list_->Back(), SECOND_VALUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ListPushBack_001
|
||||
* @tc.desc: Verify PushBack function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ListTest, ListPushBack_001, TestSize.Level0)
|
||||
{
|
||||
uint16_t size = 0;
|
||||
if (list_ == nullptr) {
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
list_->PushBack(FIRST_VALUE);
|
||||
size++;
|
||||
list_->PushBack(SECOND_VALUE);
|
||||
size++;
|
||||
EXPECT_EQ(list_->Size(), size);
|
||||
EXPECT_EQ(list_->Front(), FIRST_VALUE);
|
||||
EXPECT_EQ(list_->Back(), SECOND_VALUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ListPushFront_001
|
||||
* @tc.desc: Verify PushFront function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ListTest, ListPushFront_001, TestSize.Level0)
|
||||
{
|
||||
uint16_t size = 0;
|
||||
if (list_ == nullptr) {
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
list_->PushFront(FIRST_VALUE);
|
||||
size++;
|
||||
list_->PushFront(SECOND_VALUE);
|
||||
size++;
|
||||
EXPECT_EQ(list_->Size(), size);
|
||||
EXPECT_EQ(list_->Front(), SECOND_VALUE);
|
||||
EXPECT_EQ(list_->Back(), FIRST_VALUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ListPopBack_001
|
||||
* @tc.desc: Verify PopBack function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ListTest, ListPopBack_001, TestSize.Level0)
|
||||
{
|
||||
uint16_t size = 0;
|
||||
if (list_ == nullptr) {
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
list_->PushBack(FIRST_VALUE);
|
||||
size++;
|
||||
list_->PushBack(SECOND_VALUE);
|
||||
size++;
|
||||
list_->PopBack();
|
||||
size--;
|
||||
EXPECT_EQ(list_->Size(), size);
|
||||
EXPECT_EQ(list_->Front(), FIRST_VALUE);
|
||||
EXPECT_EQ(list_->Back(), FIRST_VALUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ListPopFront_001
|
||||
* @tc.desc: Verify PopFront function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ListTest, ListPopFront_001, TestSize.Level0)
|
||||
{
|
||||
uint16_t size = 0;
|
||||
if (list_ == nullptr) {
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
list_->PushBack(FIRST_VALUE);
|
||||
size++;
|
||||
list_->PushBack(SECOND_VALUE);
|
||||
size++;
|
||||
list_->PopFront();
|
||||
size--;
|
||||
EXPECT_EQ(list_->Size(), size);
|
||||
EXPECT_EQ(list_->Front(), SECOND_VALUE);
|
||||
EXPECT_EQ(list_->Back(), SECOND_VALUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ListInsert_001
|
||||
* @tc.desc: Verify Insert function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ListTest, ListInsert_001, TestSize.Level0)
|
||||
{
|
||||
uint16_t size = 0;
|
||||
if (list_ == nullptr) {
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
list_->PushBack(FIRST_VALUE);
|
||||
size++;
|
||||
list_->PushBack(SECOND_VALUE);
|
||||
size++;
|
||||
ListNode<uint16_t>* node = list_->Tail();
|
||||
list_->Insert(node, THIRD_VALUE);
|
||||
size++;
|
||||
EXPECT_EQ(list_->Size(), size);
|
||||
EXPECT_EQ(list_->Front(), FIRST_VALUE);
|
||||
EXPECT_EQ(list_->Head()->next_->data_, THIRD_VALUE);
|
||||
EXPECT_EQ(list_->Back(), SECOND_VALUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ListRemove_001
|
||||
* @tc.desc: Verify Remove function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ListTest, ListRemove_001, TestSize.Level0)
|
||||
{
|
||||
uint16_t size = 0;
|
||||
if (list_ == nullptr) {
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
list_->PushBack(FIRST_VALUE);
|
||||
size++;
|
||||
list_->PushBack(SECOND_VALUE);
|
||||
size++;
|
||||
ListNode<uint16_t>* node = list_->Head();
|
||||
auto nextNode = list_->Remove(node);
|
||||
size--;
|
||||
EXPECT_EQ(list_->Size(), size);
|
||||
EXPECT_EQ(nextNode->data_, SECOND_VALUE);
|
||||
EXPECT_EQ(list_->Front(), SECOND_VALUE);
|
||||
EXPECT_EQ(list_->Back(), SECOND_VALUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ListClear_001
|
||||
* @tc.desc: Verify Clear function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ListTest, ListClear_001, TestSize.Level0)
|
||||
{
|
||||
if (list_ == nullptr) {
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
list_->PushBack(FIRST_VALUE);
|
||||
list_->PushBack(SECOND_VALUE);
|
||||
list_->Clear();
|
||||
EXPECT_EQ(list_->Size(), 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ListHead_001
|
||||
* @tc.desc: Verify Head function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ListTest, ListHead_001, TestSize.Level0)
|
||||
{
|
||||
if (list_ == nullptr) {
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
list_->PushBack(FIRST_VALUE);
|
||||
list_->PushBack(SECOND_VALUE);
|
||||
EXPECT_EQ(list_->Head()->data_, FIRST_VALUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ListTail_001
|
||||
* @tc.desc: Verify Tail function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ListTest, ListTail_001, TestSize.Level0)
|
||||
{
|
||||
if (list_ == nullptr) {
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
list_->PushBack(FIRST_VALUE);
|
||||
list_->PushBack(SECOND_VALUE);
|
||||
EXPECT_EQ(list_->Tail()->data_, SECOND_VALUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ListBegin_001
|
||||
* @tc.desc: Verify Begin function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ListTest, ListBegin_001, TestSize.Level0)
|
||||
{
|
||||
if (list_ == nullptr) {
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
list_->PushBack(FIRST_VALUE);
|
||||
list_->PushBack(SECOND_VALUE);
|
||||
EXPECT_EQ(list_->Begin()->data_, FIRST_VALUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ListNext_001
|
||||
* @tc.desc: Verify Next function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ListTest, ListNext_001, TestSize.Level0)
|
||||
{
|
||||
if (list_ == nullptr) {
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
list_->PushBack(FIRST_VALUE);
|
||||
list_->PushBack(SECOND_VALUE);
|
||||
EXPECT_EQ(list_->Next(list_->Head())->data_, SECOND_VALUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ListIsEmpty_001
|
||||
* @tc.desc: Verify IsEmpty function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ListTest, ListIsEmpty_001, TestSize.Level0)
|
||||
{
|
||||
if (list_ == nullptr) {
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
list_->PushBack(FIRST_VALUE);
|
||||
EXPECT_EQ(list_->IsEmpty(), false);
|
||||
list_->Clear();
|
||||
EXPECT_EQ(list_->IsEmpty(), true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ListSize_001
|
||||
* @tc.desc: Verify Size function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(ListTest, ListSize_001, TestSize.Level0)
|
||||
{
|
||||
if (list_ == nullptr) {
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
uint16_t size = 0;
|
||||
|
||||
list_->PushBack(FIRST_VALUE);
|
||||
size++;
|
||||
EXPECT_EQ(list_->Size(), size);
|
||||
list_->Clear();
|
||||
EXPECT_EQ(list_->Size(), 0);
|
||||
}
|
||||
} // namespace OHOS
|
||||
Executable
+593
@@ -0,0 +1,593 @@
|
||||
/*
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "rect.h"
|
||||
|
||||
#include <climits>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
using namespace testing::ext;
|
||||
|
||||
namespace OHOS {
|
||||
namespace {
|
||||
const int16_t TEST_VALUE = 100;
|
||||
const int16_t MIN_VALUE = 50;
|
||||
const int16_t MAX_VALUE = 200;
|
||||
}
|
||||
class RectTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase(void);
|
||||
static void TearDownTestCase(void);
|
||||
void SetUp();
|
||||
void TearDown() {}
|
||||
static Rect* rect_;
|
||||
};
|
||||
|
||||
Rect* RectTest::rect_ = nullptr;
|
||||
|
||||
void RectTest::SetUpTestCase(void)
|
||||
{
|
||||
if (rect_ == nullptr) {
|
||||
rect_ = new Rect();
|
||||
}
|
||||
}
|
||||
|
||||
void RectTest::TearDownTestCase(void)
|
||||
{
|
||||
if (rect_ != nullptr) {
|
||||
delete rect_;
|
||||
rect_ = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void RectTest::SetUp()
|
||||
{
|
||||
if (rect_ == nullptr) {
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
rect_->SetRect(0, 0, 0, 0);
|
||||
}
|
||||
/**
|
||||
* @tc.name: RectOperator_001
|
||||
* @tc.desc: Verify copy operator function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(RectTest, RectOperator_001, TestSize.Level0)
|
||||
{
|
||||
if (rect_ == nullptr) {
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
Rect* rect1 = new Rect();
|
||||
if (rect1 == nullptr) {
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
rect1->SetRect(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION);
|
||||
rect_->operator=(*rect1);
|
||||
|
||||
EXPECT_EQ(rect_->GetLeft(), 0);
|
||||
EXPECT_EQ(rect_->GetTop(), 0);
|
||||
EXPECT_EQ(rect_->GetRight(), HORIZONTAL_RESOLUTION);
|
||||
EXPECT_EQ(rect_->GetBottom(), VERTICAL_RESOLUTION);
|
||||
|
||||
delete rect1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: RectSetRect_001
|
||||
* @tc.desc: Verify SetRect function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(RectTest, RectSetRect_001, TestSize.Level0)
|
||||
{
|
||||
if (rect_ == nullptr) {
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
rect_->SetRect(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION);
|
||||
|
||||
EXPECT_EQ(rect_->GetLeft(), 0);
|
||||
EXPECT_EQ(rect_->GetTop(), 0);
|
||||
EXPECT_EQ(rect_->GetRight(), HORIZONTAL_RESOLUTION);
|
||||
EXPECT_EQ(rect_->GetBottom(), VERTICAL_RESOLUTION);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: RectGetWidth_001
|
||||
* @tc.desc: Verify GetWidth function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(RectTest, RectGetWidth_001, TestSize.Level0)
|
||||
{
|
||||
if (rect_ == nullptr) {
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
EXPECT_EQ(rect_->GetWidth(), 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: RectGetHeight_001
|
||||
* @tc.desc: Verify GetHeight function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(RectTest, RectGetHeight_001, TestSize.Level0)
|
||||
{
|
||||
if (rect_ == nullptr) {
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
EXPECT_EQ(rect_->GetHeight(), 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: RectGetX_001
|
||||
* @tc.desc: Verify GetX function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(RectTest, RectGetX_001, TestSize.Level0)
|
||||
{
|
||||
if (rect_ == nullptr) {
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
rect_->SetRect(TEST_VALUE, 0, 0, 0);
|
||||
EXPECT_EQ(rect_->GetX(), TEST_VALUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: RectGetY_001
|
||||
* @tc.desc: Verify GetY function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(RectTest, RectGetY_001, TestSize.Level0)
|
||||
{
|
||||
if (rect_ == nullptr) {
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
rect_->SetRect(0, TEST_VALUE, 0, 0);
|
||||
EXPECT_EQ(rect_->GetY(), TEST_VALUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: RectGetLeft_001
|
||||
* @tc.desc: Verify GetLeft function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(RectTest, RectGetLeft_001, TestSize.Level0)
|
||||
{
|
||||
if (rect_ == nullptr) {
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
rect_->SetRect(TEST_VALUE, 0, 0, 0);
|
||||
EXPECT_EQ(rect_->GetLeft(), TEST_VALUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: RectGetTop_001
|
||||
* @tc.desc: Verify GetTop function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(RectTest, RectGetTop_001, TestSize.Level0)
|
||||
{
|
||||
if (rect_ == nullptr) {
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
rect_->SetRect(0, TEST_VALUE, 0, 0);
|
||||
EXPECT_EQ(rect_->GetTop(), TEST_VALUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: RectGetRight_001
|
||||
* @tc.desc: Verify GetRight function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(RectTest, RectGetRight_001, TestSize.Level0)
|
||||
{
|
||||
if (rect_ == nullptr) {
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
rect_->SetRect(0, 0, TEST_VALUE, 0);
|
||||
EXPECT_EQ(rect_->GetRight(), TEST_VALUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: RectGetBottom_001
|
||||
* @tc.desc: Verify GetBottom function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(RectTest, RectGetBottom_001, TestSize.Level0)
|
||||
{
|
||||
if (rect_ == nullptr) {
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
rect_->SetRect(0, 0, 0, TEST_VALUE);
|
||||
EXPECT_EQ(rect_->GetBottom(), TEST_VALUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: RectSetX_001
|
||||
* @tc.desc: Verify SetX function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(RectTest, RectSetX_001, TestSize.Level0)
|
||||
{
|
||||
if (rect_ == nullptr) {
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
rect_->SetX(TEST_VALUE);
|
||||
EXPECT_EQ(rect_->GetLeft(), TEST_VALUE);
|
||||
EXPECT_EQ(rect_->GetRight(), TEST_VALUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: RectSetY_001
|
||||
* @tc.desc: Verify SetY function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(RectTest, RectSetY_001, TestSize.Level0)
|
||||
{
|
||||
if (rect_ == nullptr) {
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
rect_->SetY(TEST_VALUE);
|
||||
EXPECT_EQ(rect_->GetTop(), TEST_VALUE);
|
||||
EXPECT_EQ(rect_->GetBottom(), TEST_VALUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: RectSetPosition_001
|
||||
* @tc.desc: Verify SetPosition function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(RectTest, RectSetPosition_001, TestSize.Level0)
|
||||
{
|
||||
if (rect_ == nullptr) {
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
rect_->SetPosition(TEST_VALUE, TEST_VALUE);
|
||||
EXPECT_EQ(rect_->GetLeft(), TEST_VALUE);
|
||||
EXPECT_EQ(rect_->GetRight(), TEST_VALUE);
|
||||
EXPECT_EQ(rect_->GetTop(), TEST_VALUE);
|
||||
EXPECT_EQ(rect_->GetBottom(), TEST_VALUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: RectSetWidth_001
|
||||
* @tc.desc: Verify SetWidth function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(RectTest, RectSetWidth_001, TestSize.Level0)
|
||||
{
|
||||
if (rect_ == nullptr) {
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
rect_->SetWidth(TEST_VALUE);
|
||||
EXPECT_EQ(rect_->GetRight(), TEST_VALUE - 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: RectSetHeight_001
|
||||
* @tc.desc: Verify SetHeight function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(RectTest, RectSetHeight_001, TestSize.Level0)
|
||||
{
|
||||
if (rect_ == nullptr) {
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
rect_->SetHeight(TEST_VALUE);
|
||||
EXPECT_EQ(rect_->GetBottom(), TEST_VALUE - 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: RectSetLeft_001
|
||||
* @tc.desc: Verify SetLeft function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(RectTest, RectSetLeft_001, TestSize.Level0)
|
||||
{
|
||||
if (rect_ == nullptr) {
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
rect_->SetLeft(TEST_VALUE);
|
||||
EXPECT_EQ(rect_->GetLeft(), TEST_VALUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: RectSetTop_001
|
||||
* @tc.desc: Verify SetTop function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(RectTest, RectSetTop_001, TestSize.Level0)
|
||||
{
|
||||
if (rect_ == nullptr) {
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
rect_->SetTop(TEST_VALUE);
|
||||
EXPECT_EQ(rect_->GetTop(), TEST_VALUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: RectSetRight_001
|
||||
* @tc.desc: Verify SetRight function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(RectTest, RectSetRight_001, TestSize.Level0)
|
||||
{
|
||||
if (rect_ == nullptr) {
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
rect_->SetRight(TEST_VALUE);
|
||||
EXPECT_EQ(rect_->GetRight(), TEST_VALUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: RectSetBottom_001
|
||||
* @tc.desc: Verify SetBottom function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(RectTest, RectSetBottom_001, TestSize.Level0)
|
||||
{
|
||||
if (rect_ == nullptr) {
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
rect_->SetBottom(TEST_VALUE);
|
||||
EXPECT_EQ(rect_->GetBottom(), TEST_VALUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: RectResize_001
|
||||
* @tc.desc: Verify Resize function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(RectTest, RectResize_001, TestSize.Level0)
|
||||
{
|
||||
if (rect_ == nullptr) {
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
rect_->Resize(TEST_VALUE, TEST_VALUE);
|
||||
|
||||
EXPECT_EQ(rect_->GetLeft(), 0);
|
||||
EXPECT_EQ(rect_->GetTop(), 0);
|
||||
EXPECT_EQ(rect_->GetRight(), TEST_VALUE - 1);
|
||||
EXPECT_EQ(rect_->GetBottom(), TEST_VALUE - 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: RectGetSize_001
|
||||
* @tc.desc: Verify GetSize function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(RectTest, RectGetSize_001, TestSize.Level0)
|
||||
{
|
||||
if (rect_ == nullptr) {
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
EXPECT_EQ(rect_->GetSize(), 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: RectIntersect_001
|
||||
* @tc.desc: Verify Intersect function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(RectTest, RectIntersect_001, TestSize.Level0)
|
||||
{
|
||||
Rect* rect1 = new Rect(TEST_VALUE, TEST_VALUE, MAX_VALUE, MAX_VALUE);
|
||||
if (rect1 == nullptr) {
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
Rect* rect2 = new Rect(0, 0, MAX_VALUE, MAX_VALUE);
|
||||
if (rect2 == nullptr) {
|
||||
delete rect1;
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
Rect* rect3 = new Rect(0, 0, MIN_VALUE, 0);
|
||||
if (rect3 == nullptr) {
|
||||
delete rect1;
|
||||
delete rect2;
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
EXPECT_EQ(rect1->Intersect(*rect1, *rect2), true);
|
||||
EXPECT_EQ(rect1->Intersect(*rect1, *rect3), false);
|
||||
|
||||
delete rect1;
|
||||
delete rect2;
|
||||
delete rect3;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: RectJoin_001
|
||||
* @tc.desc: Verify Join function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(RectTest, RectJoin_001, TestSize.Level0)
|
||||
{
|
||||
Rect* rect1 = new Rect(TEST_VALUE, TEST_VALUE, TEST_VALUE, TEST_VALUE);
|
||||
if (rect1 == nullptr) {
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
Rect* rect2 = new Rect(MIN_VALUE, MIN_VALUE, MAX_VALUE, MAX_VALUE);
|
||||
if (rect2 == nullptr) {
|
||||
delete rect1;
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
rect1->Join(*rect1, *rect2);
|
||||
EXPECT_EQ(rect1->GetLeft(), MIN_VALUE);
|
||||
EXPECT_EQ(rect1->GetTop(), MIN_VALUE);
|
||||
EXPECT_EQ(rect1->GetRight(), MAX_VALUE);
|
||||
EXPECT_EQ(rect1->GetBottom(), MAX_VALUE);
|
||||
|
||||
delete rect1;
|
||||
delete rect2;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: RectIsContains_001
|
||||
* @tc.desc: Verify IsContains function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(RectTest, RectIsContains_001, TestSize.Level0)
|
||||
{
|
||||
Rect* rect1 = new Rect(MIN_VALUE, MIN_VALUE, MAX_VALUE, MAX_VALUE);
|
||||
if (rect1 == nullptr) {
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
Vector2<int16_t> pt1 = {TEST_VALUE, TEST_VALUE};
|
||||
Vector2<int16_t> pt2 = {0, 0};
|
||||
|
||||
EXPECT_EQ(rect1->IsContains(pt1), true);
|
||||
EXPECT_EQ(rect1->IsContains(pt2), false);
|
||||
|
||||
delete rect1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: RectIsContains_002
|
||||
* @tc.desc: Verify IsContains function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(RectTest, RectIsContains_002, TestSize.Level0)
|
||||
{
|
||||
Rect* rect1 = new Rect(MIN_VALUE, MIN_VALUE, MAX_VALUE, MAX_VALUE);
|
||||
if (rect1 == nullptr) {
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
Point pt1;
|
||||
pt1.x = TEST_VALUE;
|
||||
pt1.y = TEST_VALUE;
|
||||
Point pt2;
|
||||
pt2.x = 0;
|
||||
pt2.y = 0;
|
||||
|
||||
EXPECT_EQ(rect1->IsContains(pt1), true);
|
||||
EXPECT_EQ(rect1->IsContains(pt2), false);
|
||||
|
||||
delete rect1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: RectIsIntersect_001
|
||||
* @tc.desc: Verify IsIntersect function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(RectTest, RectIsIntersect_001, TestSize.Level0)
|
||||
{
|
||||
Rect* rect1 = new Rect(MIN_VALUE, MIN_VALUE, MAX_VALUE, MAX_VALUE);
|
||||
if (rect1 == nullptr) {
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
Rect* rect2 = new Rect(MAX_VALUE, MAX_VALUE, MIN_VALUE, MIN_VALUE);
|
||||
if (rect2 == nullptr) {
|
||||
delete rect1;
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
Rect* rect3 = new Rect();
|
||||
if (rect3 == nullptr) {
|
||||
delete rect1;
|
||||
delete rect2;
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
EXPECT_EQ(rect1->IsIntersect(*rect2), true);
|
||||
EXPECT_EQ(rect1->IsIntersect(*rect3), false);
|
||||
|
||||
delete rect1;
|
||||
delete rect2;
|
||||
delete rect3;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: RectIsContains_003
|
||||
* @tc.desc: Verify IsContains function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(RectTest, RectIsContains_003, TestSize.Level0)
|
||||
{
|
||||
Rect* rect1 = new Rect(MIN_VALUE, MIN_VALUE, MAX_VALUE, MAX_VALUE);
|
||||
if (rect1 == nullptr) {
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
Rect* rect2 = new Rect(TEST_VALUE, TEST_VALUE, TEST_VALUE, TEST_VALUE);
|
||||
if (rect2 == nullptr) {
|
||||
delete rect1;
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
EXPECT_EQ(rect2->IsContains(*rect1), false);
|
||||
|
||||
delete rect1;
|
||||
delete rect2;
|
||||
}
|
||||
} // namespace OHOS
|
||||
Executable
+434
@@ -0,0 +1,434 @@
|
||||
/*
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "style.h"
|
||||
|
||||
#include <climits>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
using namespace testing::ext;
|
||||
namespace OHOS {
|
||||
class StyleTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase(void);
|
||||
static void TearDownTestCase(void);
|
||||
static Style* style_;
|
||||
};
|
||||
Style* StyleTest::style_ = nullptr;
|
||||
|
||||
void StyleTest::SetUpTestCase()
|
||||
{
|
||||
if (style_ == nullptr) {
|
||||
style_ = new Style();
|
||||
}
|
||||
}
|
||||
|
||||
void StyleTest::TearDownTestCase()
|
||||
{
|
||||
if (style_ != nullptr) {
|
||||
delete style_;
|
||||
style_ = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: StyleSetStyle_001
|
||||
* @tc.desc: Verify SetStyle function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQC
|
||||
*/
|
||||
HWTEST_F(StyleTest, StyleSetStyle_001, TestSize.Level0)
|
||||
{
|
||||
if (style_ == nullptr) {
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
style_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Gray().full);
|
||||
EXPECT_EQ(style_->GetStyle(STYLE_BACKGROUND_COLOR), Color::Gray().full);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: StyleSetStyle_002
|
||||
* @tc.desc: Verify SetStyle function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQC
|
||||
*/
|
||||
HWTEST_F(StyleTest, StyleSetStyle_002, TestSize.Level0)
|
||||
{
|
||||
if (style_ == nullptr) {
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
style_->SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE);
|
||||
EXPECT_EQ(style_->GetStyle(STYLE_BACKGROUND_OPA), OPA_OPAQUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: StyleSetStyle_003
|
||||
* @tc.desc: Verify SetStyle function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQC
|
||||
*/
|
||||
HWTEST_F(StyleTest, StyleSetStyle_003, TestSize.Level0)
|
||||
{
|
||||
if (style_ == nullptr) {
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
style_->SetStyle(STYLE_BORDER_RADIUS, 0);
|
||||
EXPECT_EQ(style_->GetStyle(STYLE_BORDER_RADIUS), 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: StyleSetStyle_004
|
||||
* @tc.desc: Verify SetStyle function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQC
|
||||
*/
|
||||
HWTEST_F(StyleTest, StyleSetStyle_004, TestSize.Level0)
|
||||
{
|
||||
if (style_ == nullptr) {
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
style_->SetStyle(STYLE_BORDER_COLOR, Color::Gray().full);
|
||||
EXPECT_EQ(style_->GetStyle(STYLE_BORDER_COLOR), Color::Gray().full);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: StyleSetStyle_005
|
||||
* @tc.desc: Verify SetStyle function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQC
|
||||
*/
|
||||
HWTEST_F(StyleTest, StyleSetStyle_005, TestSize.Level0)
|
||||
{
|
||||
if (style_ == nullptr) {
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
style_->SetStyle(STYLE_BORDER_OPA, OPA_OPAQUE);
|
||||
EXPECT_EQ(style_->GetStyle(STYLE_BORDER_OPA), OPA_OPAQUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: StyleSetStyle_006
|
||||
* @tc.desc: Verify SetStyle function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQC
|
||||
*/
|
||||
HWTEST_F(StyleTest, StyleSetStyle_006, TestSize.Level0)
|
||||
{
|
||||
if (style_ == nullptr) {
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
const int16_t BORDER_WIDTH = 1;
|
||||
style_->SetStyle(STYLE_BORDER_WIDTH, BORDER_WIDTH);
|
||||
EXPECT_EQ(style_->GetStyle(STYLE_BORDER_WIDTH), BORDER_WIDTH);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: StyleSetStyle_007
|
||||
* @tc.desc: Verify SetStyle function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQC
|
||||
*/
|
||||
HWTEST_F(StyleTest, StyleSetStyle_007, TestSize.Level0)
|
||||
{
|
||||
if (style_ == nullptr) {
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
style_->SetStyle(STYLE_PADDING_LEFT, 0);
|
||||
EXPECT_EQ(style_->GetStyle(STYLE_PADDING_LEFT), 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: StyleSetStyle_008
|
||||
* @tc.desc: Verify SetStyle function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQC
|
||||
*/
|
||||
HWTEST_F(StyleTest, StyleSetStyle_008, TestSize.Level0)
|
||||
{
|
||||
if (style_ == nullptr) {
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
style_->SetStyle(STYLE_PADDING_RIGHT, HORIZONTAL_RESOLUTION);
|
||||
EXPECT_EQ(style_->GetStyle(STYLE_PADDING_RIGHT), HORIZONTAL_RESOLUTION);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: StyleSetStyle_009
|
||||
* @tc.desc: Verify SetStyle function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQC
|
||||
*/
|
||||
HWTEST_F(StyleTest, StyleSetStyle_009, TestSize.Level0)
|
||||
{
|
||||
if (style_ == nullptr) {
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
style_->SetStyle(STYLE_PADDING_TOP, 0);
|
||||
EXPECT_EQ(style_->GetStyle(STYLE_PADDING_TOP), 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: StyleSetStyle_010
|
||||
* @tc.desc: Verify SetStyle function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQC
|
||||
*/
|
||||
HWTEST_F(StyleTest, StyleSetStyle_010, TestSize.Level0)
|
||||
{
|
||||
if (style_ == nullptr) {
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
style_->SetStyle(STYLE_PADDING_BOTTOM, VERTICAL_RESOLUTION);
|
||||
EXPECT_EQ(style_->GetStyle(STYLE_PADDING_BOTTOM), VERTICAL_RESOLUTION);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: StyleSetStyle_011
|
||||
* @tc.desc: Verify SetStyle function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQC
|
||||
*/
|
||||
HWTEST_F(StyleTest, StyleSetStyle_011, TestSize.Level0)
|
||||
{
|
||||
if (style_ == nullptr) {
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
style_->SetStyle(STYLE_MARGIN_LEFT, 0);
|
||||
EXPECT_EQ(style_->GetStyle(STYLE_MARGIN_LEFT), 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: StyleSetStyle_012
|
||||
* @tc.desc: Verify SetStyle function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQC
|
||||
*/
|
||||
HWTEST_F(StyleTest, StyleSetStyle_012, TestSize.Level0)
|
||||
{
|
||||
if (style_ == nullptr) {
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
style_->SetStyle(STYLE_MARGIN_RIGHT, HORIZONTAL_RESOLUTION);
|
||||
EXPECT_EQ(style_->GetStyle(STYLE_MARGIN_RIGHT), HORIZONTAL_RESOLUTION);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: StyleSetStyle_013
|
||||
* @tc.desc: Verify SetStyle function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQC
|
||||
*/
|
||||
HWTEST_F(StyleTest, StyleSetStyle_013, TestSize.Level0)
|
||||
{
|
||||
if (style_ == nullptr) {
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
style_->SetStyle(STYLE_MARGIN_TOP, 0);
|
||||
EXPECT_EQ(style_->GetStyle(STYLE_MARGIN_TOP), 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: StyleSetStyle_014
|
||||
* @tc.desc: Verify SetStyle function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQC
|
||||
*/
|
||||
HWTEST_F(StyleTest, StyleSetStyle_014, TestSize.Level0)
|
||||
{
|
||||
if (style_ == nullptr) {
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
style_->SetStyle(STYLE_MARGIN_BOTTOM, VERTICAL_RESOLUTION);
|
||||
EXPECT_EQ(style_->GetStyle(STYLE_MARGIN_BOTTOM), VERTICAL_RESOLUTION);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: StyleSetStyle_015
|
||||
* @tc.desc: Verify SetStyle function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQC
|
||||
*/
|
||||
HWTEST_F(StyleTest, StyleSetStyle_015, TestSize.Level0)
|
||||
{
|
||||
if (style_ == nullptr) {
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
style_->SetStyle(STYLE_IMAGE_OPA, OPA_OPAQUE);
|
||||
EXPECT_EQ(style_->GetStyle(STYLE_IMAGE_OPA), OPA_OPAQUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: StyleSetStyle_015
|
||||
* @tc.desc: Verify SetStyle function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQC
|
||||
*/
|
||||
HWTEST_F(StyleTest, StyleSetStyle_016, TestSize.Level0)
|
||||
{
|
||||
if (style_ == nullptr) {
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
style_->SetStyle(STYLE_TEXT_COLOR, Color::Gray().full);
|
||||
EXPECT_EQ(style_->GetStyle(STYLE_TEXT_COLOR), Color::Gray().full);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: StyleSetStyle_016
|
||||
* @tc.desc: Verify SetStyle function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQC
|
||||
*/
|
||||
HWTEST_F(StyleTest, StyleSetStyle_017, TestSize.Level0)
|
||||
{
|
||||
if (style_ == nullptr) {
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
style_->SetStyle(STYLE_TEXT_FONT, 0);
|
||||
EXPECT_EQ(style_->GetStyle(STYLE_TEXT_FONT), 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: StyleSetStyle_017
|
||||
* @tc.desc: Verify SetStyle function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQC
|
||||
*/
|
||||
HWTEST_F(StyleTest, StyleSetStyle_018, TestSize.Level0)
|
||||
{
|
||||
if (style_ == nullptr) {
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
const int16_t letterSpace = 4;
|
||||
style_->SetStyle(STYLE_LETTER_SPACE, letterSpace);
|
||||
EXPECT_EQ(style_->GetStyle(STYLE_LETTER_SPACE), letterSpace);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @tc.name: StyleSetStyle_018
|
||||
* @tc.desc: Verify SetStyle function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQC
|
||||
*/
|
||||
HWTEST_F(StyleTest, StyleSetStyle_019, TestSize.Level0)
|
||||
{
|
||||
if (style_ == nullptr) {
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
const int16_t lineSpace = 1;
|
||||
style_->SetStyle(STYLE_LINE_SPACE, lineSpace);
|
||||
EXPECT_EQ(style_->GetStyle(STYLE_LINE_SPACE), lineSpace);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: StyleSetStyle_019
|
||||
* @tc.desc: Verify SetStyle function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQC
|
||||
*/
|
||||
HWTEST_F(StyleTest, StyleSetStyle_020, TestSize.Level0)
|
||||
{
|
||||
if (style_ == nullptr) {
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
style_->SetStyle(STYLE_TEXT_OPA, OPA_OPAQUE);
|
||||
EXPECT_EQ(style_->GetStyle(STYLE_TEXT_OPA), OPA_OPAQUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: StyleSetStyle_020
|
||||
* @tc.desc: Verify SetStyle function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQC
|
||||
*/
|
||||
HWTEST_F(StyleTest, StyleSetStyle_021, TestSize.Level0)
|
||||
{
|
||||
if (style_ == nullptr) {
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
style_->SetStyle(STYLE_LINE_COLOR, Color::Gray().full);
|
||||
EXPECT_EQ(style_->GetStyle(STYLE_LINE_COLOR), Color::Gray().full);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: StyleSetStyle_021
|
||||
* @tc.desc: Verify SetStyle function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQC
|
||||
*/
|
||||
HWTEST_F(StyleTest, StyleSetStyle_022, TestSize.Level0)
|
||||
{
|
||||
if (style_ == nullptr) {
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
const int16_t lineWidth = 1;
|
||||
style_->SetStyle(STYLE_LINE_WIDTH, lineWidth);
|
||||
EXPECT_EQ(style_->GetStyle(STYLE_LINE_WIDTH), lineWidth);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: StyleSetStyle_022
|
||||
* @tc.desc: Verify SetStyle function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQC
|
||||
*/
|
||||
HWTEST_F(StyleTest, StyleSetStyle_023, TestSize.Level0)
|
||||
{
|
||||
if (style_ == nullptr) {
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
style_->SetStyle(STYLE_LINE_OPA, OPA_OPAQUE);
|
||||
EXPECT_EQ(style_->GetStyle(STYLE_LINE_OPA), OPA_OPAQUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: StyleSetStyle_023
|
||||
* @tc.desc: Verify SetStyle function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQC
|
||||
*/
|
||||
HWTEST_F(StyleTest, StyleSetStyle_024, TestSize.Level0)
|
||||
{
|
||||
if (style_ == nullptr) {
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
style_->SetStyle(STYLE_LINE_CAP, CapType::CAP_ROUND);
|
||||
EXPECT_EQ(style_->GetStyle(STYLE_LINE_CAP), CapType::CAP_ROUND);
|
||||
}
|
||||
} // namespace OHOS
|
||||
Executable
+149
@@ -0,0 +1,149 @@
|
||||
/*
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "transform.h"
|
||||
|
||||
#include <climits>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
using namespace testing::ext;
|
||||
namespace OHOS {
|
||||
class TransformTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase(void);
|
||||
static void TearDownTestCase(void);
|
||||
static TransformMap* transform_;
|
||||
};
|
||||
|
||||
TransformMap* TransformTest::transform_ = nullptr;
|
||||
|
||||
void TransformTest::SetUpTestCase(void)
|
||||
{
|
||||
if (transform_ == nullptr) {
|
||||
transform_ = new TransformMap();
|
||||
}
|
||||
}
|
||||
|
||||
void TransformTest::TearDownTestCase(void)
|
||||
{
|
||||
if (transform_ != nullptr) {
|
||||
delete transform_;
|
||||
transform_ = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: TransformSetPolygon_001
|
||||
* @tc.desc: Verify SetPolygon function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(TransformTest, TransformSetPolygon_001, TestSize.Level0)
|
||||
{
|
||||
if (transform_ == nullptr) {
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
Polygon poly;
|
||||
const uint8_t verterNum = 8;
|
||||
poly.SetVertexNum(verterNum);
|
||||
transform_->SetPolygon(poly);
|
||||
EXPECT_EQ(transform_->GetPolygon().GetVertexNum(), verterNum);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: TransformGetPivot_001
|
||||
* @tc.desc: Verify GetPivot function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(TransformTest, TransformGetPivot_001, TestSize.Level0)
|
||||
{
|
||||
if (transform_ == nullptr) {
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
EXPECT_EQ(transform_->GetPivot().x, 0);
|
||||
EXPECT_EQ(transform_->GetPivot().y, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: TransformGetClockWise_001
|
||||
* @tc.desc: Verify GetClockWise function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(TransformTest, TransformGetClockWise_001, TestSize.Level0)
|
||||
{
|
||||
if (transform_ == nullptr) {
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
transform_->GetPolygon().SetVertexNum(2); // 2 < VERTEX_NUM_MIN
|
||||
EXPECT_EQ(transform_->GetClockWise(), false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: TransformIsInvalid_001
|
||||
* @tc.desc: Verify IsInvalid function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(TransformTest, TransformIsInvalid_001, TestSize.Level0)
|
||||
{
|
||||
if (transform_ == nullptr) {
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
EXPECT_EQ(transform_->IsInvalid(), true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: TransformIsInvalid_002
|
||||
* @tc.desc: Verify IsInvalid function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(TransformTest, TransformIsInvalid_002, TestSize.Level0)
|
||||
{
|
||||
TransformMap* transform = new TransformMap(Rect(1, 1, 1, 1));
|
||||
if (transform == nullptr) {
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
EXPECT_EQ(transform->IsInvalid(), false);
|
||||
delete transform;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: TransformGetTransMapRect_001
|
||||
* @tc.desc: Verify IsInvalid function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(TransformTest, TransformGetTransMapRect_001, TestSize.Level0)
|
||||
{
|
||||
TransformMap* transform = new TransformMap(Rect(1, 1, 1, 1));
|
||||
if (transform == nullptr) {
|
||||
EXPECT_EQ(1, 0);
|
||||
return;
|
||||
}
|
||||
EXPECT_EQ(transform->GetTransMapRect().GetLeft(), 1);
|
||||
EXPECT_EQ(transform->GetTransMapRect().GetTop(), 1);
|
||||
EXPECT_EQ(transform->GetTransMapRect().GetRight(), 1);
|
||||
EXPECT_EQ(transform->GetTransMapRect().GetBottom(), 1);
|
||||
delete transform;
|
||||
}
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,260 @@
|
||||
/*
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "vector.h"
|
||||
|
||||
#include <climits>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
using namespace testing::ext;
|
||||
namespace OHOS {
|
||||
namespace {
|
||||
const uint16_t FIRST_VALUE = 1;
|
||||
const uint16_t SECOND_VALUE = 2;
|
||||
const uint16_t THIRD_VALUE = 3;
|
||||
} // namespace
|
||||
|
||||
class VectorTest : public testing::Test {
|
||||
public:
|
||||
VectorTest() = default;
|
||||
~VectorTest() = default;
|
||||
static void SetUpTestCase(void) {}
|
||||
static void TearDownTestCase(void) {}
|
||||
void SetUp();
|
||||
void TearDown();
|
||||
|
||||
Vector<uint16_t>* vector_ = nullptr;
|
||||
};
|
||||
|
||||
void VectorTest::SetUp()
|
||||
{
|
||||
if (vector_ == nullptr) {
|
||||
vector_ = new Vector<uint16_t>();
|
||||
}
|
||||
}
|
||||
|
||||
void VectorTest::TearDown()
|
||||
{
|
||||
if (vector_ != nullptr) {
|
||||
delete vector_;
|
||||
vector_ = nullptr;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @tc.name: VectorFront_001
|
||||
* @tc.desc: Verify Front function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000FCKJR
|
||||
*/
|
||||
HWTEST_F(VectorTest, VectorFront_001, TestSize.Level0)
|
||||
{
|
||||
if (vector_ == nullptr) {
|
||||
ADD_FAILURE();
|
||||
return;
|
||||
}
|
||||
vector_->PushBack(FIRST_VALUE);
|
||||
vector_->PushBack(SECOND_VALUE);
|
||||
EXPECT_EQ(vector_->Front(), FIRST_VALUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: VectorBack_001
|
||||
* @tc.desc: Verify Back function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000FCKJR
|
||||
*/
|
||||
HWTEST_F(VectorTest, VectorBack_001, TestSize.Level0)
|
||||
{
|
||||
if (vector_ == nullptr) {
|
||||
ADD_FAILURE();
|
||||
return;
|
||||
}
|
||||
vector_->PushBack(FIRST_VALUE);
|
||||
vector_->PushBack(SECOND_VALUE);
|
||||
EXPECT_EQ(vector_->Back(), SECOND_VALUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: VectorPushBack_001
|
||||
* @tc.desc: Verify PushBack/PopBack function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000FCKJR
|
||||
*/
|
||||
HWTEST_F(VectorTest, VectorPushBack_001, TestSize.Level0)
|
||||
{
|
||||
uint16_t size = 0;
|
||||
if (vector_ == nullptr) {
|
||||
ADD_FAILURE();
|
||||
return;
|
||||
}
|
||||
vector_->PushBack(FIRST_VALUE);
|
||||
size++;
|
||||
vector_->PushBack(SECOND_VALUE);
|
||||
size++;
|
||||
EXPECT_EQ(vector_->Size(), size);
|
||||
EXPECT_EQ(vector_->Front(), FIRST_VALUE);
|
||||
EXPECT_EQ(vector_->Back(), SECOND_VALUE);
|
||||
|
||||
vector_->PopBack();
|
||||
size--;
|
||||
EXPECT_EQ(vector_->Size(), size);
|
||||
EXPECT_EQ(vector_->Front(), FIRST_VALUE);
|
||||
EXPECT_EQ(vector_->Back(), FIRST_VALUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: VectorClear_001
|
||||
* @tc.desc: Verify IsEmpty/Clear/Size function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000FCKJR
|
||||
*/
|
||||
HWTEST_F(VectorTest, VectorClear_001, TestSize.Level0)
|
||||
{
|
||||
if (vector_ == nullptr) {
|
||||
ADD_FAILURE();
|
||||
return;
|
||||
}
|
||||
uint16_t size = 0;
|
||||
EXPECT_TRUE(vector_->IsEmpty());
|
||||
|
||||
vector_->PushBack(FIRST_VALUE);
|
||||
++size;
|
||||
vector_->PushBack(SECOND_VALUE);
|
||||
++size;
|
||||
EXPECT_EQ(vector_->Size(), size);
|
||||
EXPECT_FALSE(vector_->IsEmpty());
|
||||
|
||||
vector_->Clear();
|
||||
EXPECT_TRUE(vector_->IsEmpty());
|
||||
EXPECT_EQ(vector_->Size(), 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: VectorBegin_001
|
||||
* @tc.desc: Verify Begin/End function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000FCKJR
|
||||
*/
|
||||
HWTEST_F(VectorTest, VectorBegin_001, TestSize.Level0)
|
||||
{
|
||||
if (vector_ == nullptr) {
|
||||
ADD_FAILURE();
|
||||
return;
|
||||
}
|
||||
vector_->PushBack(FIRST_VALUE);
|
||||
vector_->PushBack(SECOND_VALUE);
|
||||
EXPECT_EQ(*(vector_->Begin()), FIRST_VALUE);
|
||||
auto p = vector_->End();
|
||||
EXPECT_EQ((--p)[0], SECOND_VALUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: VectorSize_001
|
||||
* @tc.desc: Verify Size function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000FCKJR
|
||||
*/
|
||||
HWTEST_F(VectorTest, VectorSize_001, TestSize.Level0)
|
||||
{
|
||||
if (vector_ == nullptr) {
|
||||
ADD_FAILURE();
|
||||
return;
|
||||
}
|
||||
uint16_t size = 0;
|
||||
|
||||
vector_->PushBack(FIRST_VALUE);
|
||||
size++;
|
||||
EXPECT_EQ(vector_->Size(), size);
|
||||
vector_->Clear();
|
||||
EXPECT_EQ(vector_->Size(), 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: VectorCapacity_001
|
||||
* @tc.desc: Verify Capacity/ReSize function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000FCKJR
|
||||
*/
|
||||
HWTEST_F(VectorTest, VectorCapacity_001, TestSize.Level0)
|
||||
{
|
||||
if (vector_ == nullptr) {
|
||||
ADD_FAILURE();
|
||||
return;
|
||||
}
|
||||
uint16_t capacity = 1;
|
||||
uint16_t size = capacity;
|
||||
|
||||
vector_->PushBack(FIRST_VALUE);
|
||||
EXPECT_EQ(vector_->Capacity(), capacity);
|
||||
vector_->PushBack(SECOND_VALUE);
|
||||
capacity <<= 1; // 1: capacity double
|
||||
EXPECT_EQ(vector_->Capacity(), capacity);
|
||||
vector_->PushBack(THIRD_VALUE);
|
||||
capacity <<= 1; // 1: capacity double
|
||||
EXPECT_EQ(vector_->Capacity(), capacity);
|
||||
|
||||
EXPECT_EQ(vector_->ReSize(size), size);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: VectorErase_001
|
||||
* @tc.desc: Verify Erase function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000FCKJR
|
||||
*/
|
||||
HWTEST_F(VectorTest, VectorErase_001, TestSize.Level0)
|
||||
{
|
||||
if (vector_ == nullptr) {
|
||||
ADD_FAILURE();
|
||||
return;
|
||||
}
|
||||
uint16_t idx = 0;
|
||||
|
||||
vector_->PushBack(FIRST_VALUE);
|
||||
idx++;
|
||||
vector_->PushBack(SECOND_VALUE);
|
||||
vector_->PushBack(THIRD_VALUE);
|
||||
|
||||
vector_->Erase(idx); // remove SECOND_VALUE
|
||||
EXPECT_EQ((*vector_)[idx], THIRD_VALUE);
|
||||
EXPECT_EQ(vector_->Size(), ++idx);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: VectorSwap_001
|
||||
* @tc.desc: Verify Swap function, equal.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000FCKJR
|
||||
*/
|
||||
HWTEST_F(VectorTest, VectorSwap_001, TestSize.Level0)
|
||||
{
|
||||
if (vector_ == nullptr) {
|
||||
ADD_FAILURE();
|
||||
return;
|
||||
}
|
||||
vector_->PushBack(FIRST_VALUE);
|
||||
Vector<uint16_t> copy;
|
||||
copy = (*vector_);
|
||||
|
||||
vector_->PushBack(SECOND_VALUE);
|
||||
copy.Swap(*vector_);
|
||||
|
||||
EXPECT_EQ(copy.Size(), SECOND_VALUE);
|
||||
EXPECT_EQ(copy[0], FIRST_VALUE);
|
||||
EXPECT_EQ(copy[1], SECOND_VALUE);
|
||||
EXPECT_EQ(vector_->Size(), FIRST_VALUE);
|
||||
EXPECT_EQ((*vector_)[0], FIRST_VALUE);
|
||||
}
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,40 @@
|
||||
# Copyright (c) 2020-2021 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
GRAPHIC_UTILS_PATH = "//foundation/graphic/utils"
|
||||
|
||||
graphic_utils_include_dirs = [
|
||||
"$GRAPHIC_UTILS_PATH/interfaces/innerkits",
|
||||
"$GRAPHIC_UTILS_PATH/interfaces/kits",
|
||||
]
|
||||
|
||||
graphic_utils_sources = [
|
||||
"$GRAPHIC_UTILS_PATH/frameworks/color.cpp",
|
||||
"$GRAPHIC_UTILS_PATH/frameworks/geometry2d.cpp",
|
||||
"$GRAPHIC_UTILS_PATH/frameworks/graphic_math.cpp",
|
||||
"$GRAPHIC_UTILS_PATH/frameworks/hal_cpu.cpp",
|
||||
"$GRAPHIC_UTILS_PATH/frameworks/hal_tick.cpp",
|
||||
"$GRAPHIC_UTILS_PATH/frameworks/mem_api.cpp",
|
||||
"$GRAPHIC_UTILS_PATH/frameworks/pixel_format_utils.cpp",
|
||||
"$GRAPHIC_UTILS_PATH/frameworks/style.cpp",
|
||||
"$GRAPHIC_UTILS_PATH/frameworks/transform.cpp",
|
||||
"$GRAPHIC_UTILS_PATH/frameworks/version.cpp",
|
||||
]
|
||||
|
||||
graphic_hals_include_dirs = [
|
||||
"$GRAPHIC_UTILS_PATH/interfaces/innerkits",
|
||||
"//drivers/peripheral/display/interfaces/include",
|
||||
]
|
||||
|
||||
graphic_hals_sources = [
|
||||
"$GRAPHIC_UTILS_PATH/frameworks/hals/gfx_engines.cpp",
|
||||
"$GRAPHIC_UTILS_PATH/frameworks/hals/hi_fbdev.cpp",
|
||||
]
|
||||
Reference in New Issue
Block a user