update openharmony 1.0.1

This commit is contained in:
mamingshuai
2021-03-11 18:38:22 +08:00
parent f8b3c5a5b8
commit ce1082a61a
47 changed files with 5023 additions and 63 deletions
+160
View File
@@ -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
+104
View File
@@ -0,0 +1,104 @@
# 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/ndk/ndk.gni")
lite_component("lite_wms") {
features = [
":wms_server",
":wms_client",
]
public_deps = [ ":wms_client" ]
}
ndk_lib("lite_wms_ndk") {
lib_extension = ".so"
deps = [ ":wms_client" ]
head_files = []
}
commonDeps = [
"//foundation/distributedschedule/samgr_lite/samgr:samgr",
"//foundation/distributedschedule/samgr_lite/communication/broadcast:broadcast",
"//foundation/communication/ipc_lite:liteipc_adapter",
"//foundation/graphic/surface:surface",
"//foundation/graphic/utils:lite_graphic_utils",
"//third_party/bounds_checking_function:libsec_shared",
]
shared_library("wms_client") {
sources = [
"frameworks/ims/input_event_listener_proxy.cpp",
"frameworks/wms/iwindows_manager.cpp",
"frameworks/wms/lite_proxy_surface.cpp",
"frameworks/wms/lite_proxy_window.cpp",
"frameworks/wms/lite_proxy_windows_manager.cpp",
"frameworks/wms/lite_win_requestor.cpp",
"frameworks/wms/lite_wm_requestor.cpp",
"frameworks/wms/lite_wms_client.cpp",
]
deps = commonDeps
public_deps = [ "//foundation/graphic/surface:lite_surface" ]
public_configs = [ ":wms_public_config" ]
ldflags = [ "-lstdc++" ]
cflags = [ "-Wall" ]
cflags_cc = cflags
}
config("wms_public_config") {
include_dirs = [ "interfaces/innerkits" ]
}
imsSources = [
"services/ims/input_event_distributer.cpp",
"services/ims/input_event_hub.cpp",
"services/ims/input_manager_service.cpp",
"services/ims/input_event_client_proxy.cpp",
"services/ims/samgr_ims.cpp",
]
imsInclude = [ "services/ims" ]
imsDeps = [ "//drivers/adapter/uhdf/posix:hdf_posix_osal" ]
executable("wms_server") {
sources = [
"services/wms/lite_win.cpp",
"services/wms/lite_wm.cpp",
"services/wms/lite_wms.cpp",
"services/wms/samgr_wms.cpp",
"services/wms/wms.cpp",
]
include_dirs = [
"frameworks/ims",
"interfaces/innerkits",
"//drivers/peripheral/input/interfaces/include",
"//third_party/FreeBSD/sys/dev/evdev",
]
ldflags = [
"-lstdc++",
"-lpthread",
"-Wl,-rpath-link=$ohos_root_path/$root_out_dir",
"-ldisplay_gfx",
"-ldisplay_gralloc",
"-ldisplay_layer",
]
deps = [
"//drivers/peripheral/input/hal:hdi_input",
"//foundation/graphic/utils:lite_graphic_hals",
]
deps += commonDeps
cflags = [ "-Wall" ]
cflags_cc = cflags
sources += imsSources
include_dirs += imsInclude
deps += imsDeps
}
+177
View File
@@ -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
-36
View File
@@ -1,36 +0,0 @@
# graphic_wms
#### 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/)
+47 -27
View File
@@ -1,39 +1,59 @@
# graphic_wms
# WMS<a name="EN-US_TOPIC_0000001122925147"></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 graphics service uses the client/server \(C/S\) architecture and is divided into two sub-services: Window Manager Service \(WMS\) and Input Manager Service \(IMS\). The application calls the APIs provided by the client to obtain the window status and process events. The server interacts with the hardware to implement display and input event distribution.
- WMS: Manages and combines windows of different applications in a unified manner. Each window is bound to a **RootView** object.
- IMS: Connects to the underlying input event driver framework to monitor and distribute input events.
**Figure 1** <a name="fig163546295165"></a>
#### 安装教程
![](figures/en-us_image_0000001127903103.png)
1. xxxx
2. xxxx
3. xxxx
## Directory Structure<a name="section161941989596"></a>
#### 使用说明
```
/foundation/graphic/wms
├── frameworks # Client
│ ├── ims # Input event management service client
│ └── wms # Window management service client
├── interfaces # APIs
│ ├── innerkits # APIs between modules
├── services # Server
│ ├── ims # Input event management service
│ └── wms # Window management service
└── test # Test code
```
1. xxxx
2. xxxx
3. xxxx
## Compilation and Building<a name="section137768191623"></a>
#### 参与贡献
```
# Generate the wms_server and libwms_client.so files in the out directory of the product folder through GN compilation.
hb build lite_wms
```
1. Fork 本仓库
2. 新建 Feat_xxx 分支
3. 提交代码
4. 新建 Pull Request
## Description<a name="section1312121216216"></a>
### Usage<a name="section129654513264"></a>
#### 特技
- WMS provides methods to display various UI components, send event notifications, and process various events. For details, see the related source code.
- **test/sample\_window** provides the unit testing for each WMS API. Refer to it for the usage of WMS.
## Repositories Involved<a name="section1371113476307"></a>
/hmf/graphic/surface
/hmf/graphic/ui
/hmf/graphic/utils
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/)
+59
View File
@@ -0,0 +1,59 @@
# 图形WMS组件<a name="ZH-CN_TOPIC_0000001122925147"></a>
- [简介](#section11660541593)
- [目录](#section161941989596)
- [编译构建](#section137768191623)
- [说明](#section1312121216216)
- [使用说明](#section129654513264)
- [相关仓](#section1371113476307)
## 简介<a name="section11660541593"></a>
图形服务采用C/S架构,内部分为窗口管理(WMS: Window Manager Service)和输入事件管理(IMS: Input Manger Service)两个子服务。APP调用客户端接口完成窗口状态获取、事件处理等操作,服务端与硬件交互实现送显、输入事件分发等。
- WMS:窗口管理服务对不同APP的窗口进行统一管理、合成。窗口与UI组件中的RootView呈一一对应的关系;
- IMS:输入事件管理服务对接底层输入事件驱动框架,对输入事件进行监听和分发。
**图 1** <a name="fig163546295165"></a>
![](figures/zh-cn_image_0000001127903103.png)
## 目录<a name="section161941989596"></a>
```
/foundation/graphic/wms
├── frameworks # 客户端
│ ├── ims # 输入管理客户端
│ └── wms # 窗口管理服务客户端
├── interfaces # 接口
│ └── innerkits # 模块间接口
├── services # 服务端
│ ├── ims # 输入管理服务
│ └── wms # 窗口管理服务
└── test # 测试代码
```
## 编译构建<a name="section137768191623"></a>
```
# 通过gn编译,在out目录下对应产品的文件夹中生成可执行文件wms_server和libwms_client.so
hb build lite_wms
```
## 说明<a name="section1312121216216"></a>
### 使用说明<a name="section129654513264"></a>
- 图形UI组件基于WMS组件实现了各种UI组件的显示以及事件通知、处理,可参考相关源码;
- test/sample\_window提供了WMS组件各接口的单元测试,也可参考使用。
## 相关仓<a name="section1371113476307"></a>
/hmf/graphic/surface
/hmf/graphic/ui
/hmf/graphic/utils
Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

+70
View File
@@ -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.
*/
#ifndef GRAPHIC_LITE_IMS_LISTERNER_PROXY_H
#define GRAPHIC_LITE_IMS_LISTERNER_PROXY_H
#include "input_event_distributer.h"
#include "input_event_info.h"
#include "input_manager_service.h"
#include "liteipc_adapter.h"
#include "serializer.h"
#include <pthread.h>
#include <map>
namespace OHOS {
#define MAX_CLIENT_SIZE 1
class InputEventClientProxy : public InputEventDistributer::RawEventListener {
public:
static InputEventClientProxy* GetInstance()
{
static InputEventClientProxy ims;
return &ims;
}
static void ClientRequestHandle(int funcId, void* origin, IpcIo* req, IpcIo* reply);
private:
InputEventClientProxy()
{
InputManagerService::GetInstance()->GetDistributer()->AddRawEventListener(this);
pthread_mutex_init(&lock_, nullptr);
}
~InputEventClientProxy()
{
pthread_mutex_destroy(&lock_);
}
struct ClientInfo {
SvcIdentity svc;
uint32_t cdId;
};
std::map<pid_t, ClientInfo> clientInfoMap_;
static pthread_mutex_t lock_;
InputEventClientProxy(const InputEventClientProxy&) = delete;
InputEventClientProxy& operator=(const InputEventClientProxy&) = delete;
InputEventClientProxy(InputEventClientProxy&&) = delete;
InputEventClientProxy& operator=(InputEventClientProxy&&) = delete;
void OnRawEvent(const RawEvent& event) override;
void AddListener(const void* origin, IpcIo* req, IpcIo* reply);
void RemoveListener(const void* origin, IpcIo* req, IpcIo* reply);
static int32_t DeathCallback(const IpcContext* context, void* ipcMsg, IpcIo* data, void* origin);
};
}
#endif
+109
View File
@@ -0,0 +1,109 @@
/*
* 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 "input_event_listener_proxy.h"
#include "graphic_log.h"
#include "samgr_lite.h"
namespace OHOS {
InputEventListenerProxy::RawEventListener* InputEventListenerProxy::listener_ = nullptr;
InputEventListenerProxy::~InputEventListenerProxy()
{
if (proxy_ != nullptr) {
UnregisterInputEventListener();
proxy_ = nullptr;
}
}
bool InputEventListenerProxy::GetIClientProxy()
{
if (proxy_ == nullptr) {
IUnknown *iUnknown = SAMGR_GetInstance()->GetDefaultFeatureApi(IMS_SERVICE_NAME);
if (iUnknown == nullptr) {
GRAPHIC_LOGE("iUnknown is NULL");
return false;
}
(void)iUnknown->QueryInterface(iUnknown, CLIENT_PROXY_VER, (void **)&proxy_);
if (proxy_ == nullptr) {
GRAPHIC_LOGE("QueryInterface failed, IClientProxy is empty!");
return false;
}
}
return true;
}
int32_t InputEventListenerProxy::ReceiveMsgHandler(const IpcContext* context, void* ipcMsg, IpcIo* io, void* arg)
{
if (listener_ == nullptr) {
return -1;
}
uint32_t size;
RawEvent* eventTemp = static_cast<RawEvent*>(IpcIoPopFlatObj(io, &size));
if (eventTemp == nullptr) {
GRAPHIC_LOGE("pop raw event failed.");
return -1;
}
RawEvent event = *eventTemp;
listener_->OnRawEvent(event);
FreeBuffer(nullptr, ipcMsg);
return 0;
}
bool InputEventListenerProxy::RegisterInputEventListener(RawEventListener* listener)
{
if (listener == nullptr) {
GRAPHIC_LOGE("Input event listener is empty.");
return false;
}
if (!GetIClientProxy()) {
GRAPHIC_LOGE("Get input event client proxy failed.");
return false;
}
IpcIo io;
uint8_t tmpData[IMS_DEFAULT_IPC_SIZE];
IpcIoInit(&io, tmpData, IMS_DEFAULT_IPC_SIZE, 1);
SvcIdentity svc;
if (RegisterIpcCallback(ReceiveMsgHandler, 0, IPC_WAIT_FOREVER, &svc, NULL) != LITEIPC_OK) {
GRAPHIC_LOGE("RegisterIpcCallback failed.");
return false;
}
IpcIoPushSvc(&io, &svc);
int32_t ret = proxy_->Invoke(proxy_, LITEIMS_CLIENT_REGISTER, &io, NULL, NULL);
if (ret != 0) {
GRAPHIC_LOGE("Client register failed, ret=%d", ret);
return false;
}
listener_ = listener;
return true;
}
bool InputEventListenerProxy::UnregisterInputEventListener()
{
if (proxy_ != nullptr) {
IpcIo io;
uint8_t tmpData[IMS_DEFAULT_IPC_SIZE];
IpcIoInit(&io, tmpData, IMS_DEFAULT_IPC_SIZE, 1);
int32_t ret = proxy_->Invoke(proxy_, LITEIMS_CLIENT_UNREGISTER, &io, NULL, NULL);
if (ret == 0) {
if (listener_ != nullptr) {
listener_ = nullptr;
}
return true;
}
}
return false;
}
} // namespace OHOS
+25
View File
@@ -0,0 +1,25 @@
/*
* 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 "iwindows_manager.h"
#include "lite_proxy_windows_manager.h"
namespace OHOS {
IWindowsManager* IWindowsManager::GetInstance()
{
static LiteProxyWindowsManager winManager;
return &winManager;
}
}
+63
View File
@@ -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 "lite_proxy_surface.h"
#include "graphic_log.h"
namespace OHOS {
LiteProxySurface::LiteProxySurface(Surface* surface)
: buffer_(nullptr), surface_(surface)
{
}
LiteProxySurface::~LiteProxySurface()
{
}
void LiteProxySurface::Lock(void** buf, void** phyMem, uint32_t* strideLen)
{
GRAPHIC_LOGI("Lock");
if (surface_ == nullptr) {
return;
}
if (buffer_ == nullptr) {
buffer_ = surface_->RequestBuffer();
if (buffer_ == nullptr) {
GRAPHIC_LOGE("buffer_ is null!");
*buf = nullptr;
*phyMem = nullptr;
*strideLen = 0;
return;
}
}
*buf = buffer_->GetVirAddr();
uintptr_t phyAddr = buffer_->GetPhyAddr();
*phyMem = (void*)phyAddr;
*strideLen = surface_->GetStride();
GRAPHIC_LOGI("strideLen=%d", *strideLen);
}
void LiteProxySurface::Unlock()
{
if (surface_ == nullptr || buffer_ == nullptr) {
return;
}
GRAPHIC_LOGI("Unlock");
surface_->FlushBuffer(buffer_);
buffer_ = nullptr;
}
}
+37
View File
@@ -0,0 +1,37 @@
/*
* 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_PROXY_SURFACE_H
#define GRAPHIC_LITE_PROXY_SURFACE_H
#include "isurface.h"
#include "lite_win_requestor.h"
#include "surface.h"
namespace OHOS {
class LiteProxySurface : public ISurface {
public:
LiteProxySurface(Surface* surface);
virtual ~LiteProxySurface();
virtual void Lock(void** buf, void** phyMem, uint32_t* strideLen) override;
virtual void Unlock() override;
private:
SurfaceBuffer* buffer_;
Surface* surface_;
};
}
#endif
+121
View File
@@ -0,0 +1,121 @@
/*
* 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 "lite_proxy_window.h"
#include "graphic_log.h"
#include "surface.h"
namespace OHOS {
LiteProxyWindow::LiteProxyWindow(LiteWinRequestor* requestor)
: winRequestor_(requestor), id_(INVALID_WINDOW_ID), surface_(nullptr)
{
}
LiteProxyWindow::~LiteProxyWindow()
{
if (winRequestor_ != nullptr) {
delete winRequestor_;
winRequestor_ = nullptr;
}
if (surface_ != nullptr) {
delete surface_;
surface_ = nullptr;
}
}
int LiteProxyWindow::Init()
{
return 0;
}
void LiteProxyWindow::Destroy()
{
}
void LiteProxyWindow::Show()
{
if (winRequestor_ != nullptr) {
winRequestor_->Show();
}
}
void LiteProxyWindow::Hide()
{
if (winRequestor_ != nullptr) {
winRequestor_->Hide();
}
}
void LiteProxyWindow::Resize(int16_t width, int16_t height)
{
if (winRequestor_ != nullptr) {
winRequestor_->Resize(width, height);
}
}
void LiteProxyWindow::MoveTo(int16_t x, int16_t y)
{
if (winRequestor_ != nullptr) {
winRequestor_->MoveTo(x, y);
}
}
void LiteProxyWindow::RaiseToTop()
{
if (winRequestor_ != nullptr) {
winRequestor_->RaiseToTop();
}
}
void LiteProxyWindow::LowerToBottom()
{
if (winRequestor_ != nullptr) {
winRequestor_->LowerToBottom();
}
}
ISurface* LiteProxyWindow::GetSurface()
{
if (surface_ == nullptr) {
Surface* surface = winRequestor_->GetSurface();
if (surface == nullptr) {
return nullptr;
}
surface_ = new LiteProxySurface(surface);
}
return surface_;
}
int32_t LiteProxyWindow::GetWindowId()
{
if (id_ != INVALID_WINDOW_ID) {
return id_;
}
if (winRequestor_ != nullptr) {
id_ = winRequestor_->GetWindowId();
return id_;
}
return INVALID_WINDOW_ID;
}
void LiteProxyWindow::Update()
{
if (winRequestor_ != nullptr) {
winRequestor_->Update();
}
}
}
+47
View File
@@ -0,0 +1,47 @@
/*
* 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_PROXY_WINDOW_H
#define GRAPHIC_LITE_PROXY_WINDOW_H
#include "iwindow.h"
#include "lite_proxy_surface.h"
#include "lite_win_requestor.h"
namespace OHOS {
class LiteProxyWindow : public IWindow {
public:
explicit LiteProxyWindow(LiteWinRequestor* requestor);
virtual ~LiteProxyWindow();
int Init() override;
void Destroy() override;
void Show() override;
void Hide() override;
void Resize(int16_t width, int16_t height) override;
void MoveTo(int16_t x, int16_t y) override;
void RaiseToTop() override;
void LowerToBottom() override;
ISurface* GetSurface() override;
int32_t GetWindowId() override;
void Update() override;
private:
LiteWinRequestor* winRequestor_;
int32_t id_;
ISurface* surface_;
};
}
#endif
+66
View File
@@ -0,0 +1,66 @@
/*
* 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 "lite_proxy_windows_manager.h"
#include "color.h"
#include "graphic_log.h"
#include "lite_wm_requestor.h"
#include "lite_wms_client.h"
namespace OHOS {
int LiteProxyWindowsManager::Init()
{
GRAPHIC_LOGI("Init");
LiteWMSClient::GetInstance()->InitLiteWMSClient();
LiteWMRequestor::GetInstance()->ClientRegister();
LiteWMRequestor::GetInstance()->GetLayerInfo();
return 0;
}
IWindow* LiteProxyWindowsManager::CreateWindow(const LiteWinConfig& config)
{
LiteWinRequestor* requstor = LiteWMRequestor::GetInstance()->CreateWindow(config);
if (requstor == nullptr) {
return nullptr;
} else {
return new LiteProxyWindow(requstor);
}
}
void LiteProxyWindowsManager::RemoveWindow(IWindow* window)
{
if (window != nullptr) {
int32_t id = window->GetWindowId();
delete window;
LiteWMRequestor::GetInstance()->RemoveWindow(id);
}
}
void LiteProxyWindowsManager::GetEventData(DeviceData* data)
{
LiteWMRequestor::GetInstance()->GetEventData(data);
}
void LiteProxyWindowsManager::Screenshot()
{
LiteWMRequestor::GetInstance()->Screenshot();
}
void LiteProxyWindowsManager::SetScreenshotListener(ScreenshotListener* listener)
{
LiteWMRequestor::GetInstance()->SetScreenshotListener(listener);
}
} // namespace OHOS
+37
View File
@@ -0,0 +1,37 @@
/*
* 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_PROXY_WINDOWS_MANAGER_H
#define GRAPHIC_LITE_PROXY_WINDOWS_MANAGER_H
#include "isurface.h"
#include "iwindows_manager.h"
#include "lite_proxy_window.h"
namespace OHOS {
class LiteProxyWindowsManager : public IWindowsManager {
public:
LiteProxyWindowsManager() {}
virtual ~LiteProxyWindowsManager() {}
int Init() override;
IWindow* CreateWindow(const LiteWinConfig& config) override;
void RemoveWindow(IWindow* win) override;
void GetEventData(DeviceData* data) override;
void Screenshot() override;
void SetScreenshotListener(ScreenshotListener* listener) override;
};
}
#endif
+182
View File
@@ -0,0 +1,182 @@
/*
* 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 "lite_win_requestor.h"
#include "graphic_log.h"
#include "lite_wm_type.h"
#include "lite_wms_client.h"
#include "surface_impl.h"
namespace OHOS {
LiteWinRequestor::LiteWinRequestor(int32_t id) : proxy_(nullptr), id_(id), surface_(nullptr)
{
proxy_ = LiteWMSClient::GetInstance()->GetClientProxy();
}
LiteWinRequestor::~LiteWinRequestor()
{
if (surface_ != nullptr) {
delete surface_;
surface_ = nullptr;
}
}
int LiteWinRequestor::Callback(void* owner, int code, IpcIo* reply)
{
if (code != 0) {
GRAPHIC_LOGE("callback error, code = %d", code);
return -1;
}
if (owner == nullptr) {
return -1;
}
CallBackPara* para = (CallBackPara*)owner;
GRAPHIC_LOGD("Callback, funcId = %d", para->funcId);
switch (para->funcId) {
case LiteWMS_GetSurface: {
LiteWinRequestor* requestor = (LiteWinRequestor*)(para->data);
int32_t ret = IpcIoPopInt32(reply);
if ((ret == LITEIPC_OK) && (requestor != nullptr)) {
requestor->GenericSurface(reply);
}
break;
}
default:
break;
}
return 0;
}
void LiteWinRequestor::GenericSurface(IpcIo* reply)
{
surface_ = SurfaceImpl::GenericSurfaceByIpcIo(*reply);
}
Surface* LiteWinRequestor::GetSurface()
{
if (surface_ == nullptr) {
IpcIo io;
uint8_t tmpData[DEFAULT_IPC_SIZE];
IpcIoInit(&io, tmpData, DEFAULT_IPC_SIZE, 0);
IpcIoPushInt32(&io, id_);
CallBackPara para = {};
para.funcId = LiteWMS_GetSurface;
para.data = this;
int32_t ret = proxy_->Invoke(proxy_, LiteWMS_GetSurface, &io, &para, Callback);
if (ret != 0) {
GRAPHIC_LOGE("GetSurface failed, ret=%d", ret);
}
}
return surface_;
}
void LiteWinRequestor::Show()
{
IpcIo io;
uint8_t tmpData[DEFAULT_IPC_SIZE];
IpcIoInit(&io, tmpData, DEFAULT_IPC_SIZE, 0);
IpcIoPushInt32(&io, id_);
int32_t ret = proxy_->Invoke(proxy_, LiteWMS_Show, &io, NULL, NULL);
if (ret != 0) {
GRAPHIC_LOGE("Show failed, ret=%d", ret);
}
}
void LiteWinRequestor::Hide()
{
IpcIo io;
uint8_t tmpData[DEFAULT_IPC_SIZE];
IpcIoInit(&io, tmpData, DEFAULT_IPC_SIZE, 0);
IpcIoPushInt32(&io, id_);
int32_t ret = proxy_->Invoke(proxy_, LiteWMS_Hide, &io, NULL, NULL);
if (ret != 0) {
GRAPHIC_LOGE("Hide failed, ret=%d", ret);
}
}
void LiteWinRequestor::RaiseToTop()
{
IpcIo io;
uint8_t tmpData[DEFAULT_IPC_SIZE];
IpcIoInit(&io, tmpData, DEFAULT_IPC_SIZE, 0);
IpcIoPushInt32(&io, id_);
int32_t ret = proxy_->Invoke(proxy_, LiteWMS_RaiseToTop, &io, NULL, NULL);
if (ret != 0) {
GRAPHIC_LOGE("RaiseToTop failed, ret=%d", ret);
}
}
void LiteWinRequestor::LowerToBottom()
{
IpcIo io;
uint8_t tmpData[DEFAULT_IPC_SIZE];
IpcIoInit(&io, tmpData, DEFAULT_IPC_SIZE, 0);
IpcIoPushInt32(&io, id_);
int32_t ret = proxy_->Invoke(proxy_, LiteWMS_LowerToBottom, &io, NULL, NULL);
if (ret != 0) {
GRAPHIC_LOGE("LowerToBottom failed, ret=%d", ret);
}
}
void LiteWinRequestor::MoveTo(int16_t x, int16_t y)
{
IpcIo io;
uint8_t tmpData[DEFAULT_IPC_SIZE];
IpcIoInit(&io, tmpData, DEFAULT_IPC_SIZE, 0);
IpcIoPushInt32(&io, id_);
IpcIoPushUint32(&io, x);
IpcIoPushUint32(&io, y);
int32_t ret = proxy_->Invoke(proxy_, LiteWMS_MoveTo, &io, NULL, NULL);
if (ret != 0) {
GRAPHIC_LOGE("MoveTo failed, ret=%d", ret);
}
}
void LiteWinRequestor::Resize(int16_t width, int16_t height)
{
IpcIo io;
uint8_t tmpData[DEFAULT_IPC_SIZE];
IpcIoInit(&io, tmpData, DEFAULT_IPC_SIZE, 0);
IpcIoPushInt32(&io, id_);
IpcIoPushUint32(&io, width);
IpcIoPushUint32(&io, height);
int32_t ret = proxy_->Invoke(proxy_, LiteWMS_Resize, &io, NULL, Callback);
if (ret != 0) {
GRAPHIC_LOGE("Resize failed, ret=%d", ret);
}
}
void LiteWinRequestor::Update()
{
IpcIo io;
uint8_t tmpData[DEFAULT_IPC_SIZE];
IpcIoInit(&io, tmpData, DEFAULT_IPC_SIZE, 0);
IpcIoPushInt32(&io, id_);
int32_t ret = proxy_->Invoke(proxy_, LiteWMS_Update, &io, NULL, NULL);
if (ret != 0) {
GRAPHIC_LOGE("Update failed, ret=%d", ret);
}
}
} // namespace OHOS
+51
View File
@@ -0,0 +1,51 @@
/*
* 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_LITE_WIN_REQUESTOR_H
#define GRAPHIC_LITE_LITE_WIN_REQUESTOR_H
#include "geometry2d.h"
#include <iproxy_client.h>
#include "surface.h"
namespace OHOS {
class LiteWinRequestor {
public:
explicit LiteWinRequestor(int32_t id);
~LiteWinRequestor();
static int Callback(void* owner, int code, IpcIo* reply);
void GenericSurface(IpcIo* reply);
Surface* GetSurface();
void Show();
void Hide();
void RaiseToTop();
void LowerToBottom();
void MoveTo(int16_t x, int16_t y);
void Resize(int16_t width, int16_t height);
void Update();
int32_t GetWindowId()
{
return id_;
}
private:
IClientProxy* proxy_;
int32_t id_;
Surface* surface_;
};
}
#endif
+240
View File
@@ -0,0 +1,240 @@
/*
* 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 "lite_wm_requestor.h"
#include "graphic_log.h"
#include "input_event_info.h"
#include "lite_wms_client.h"
#include "pixel_format_utils.h"
#include "surface_impl.h"
namespace OHOS {
LiteWMRequestor::LiteWMRequestor() : proxy_(nullptr), listener_(nullptr), surface_(nullptr), sid_({}), layerInfo_({})
{
proxy_ = LiteWMSClient::GetInstance()->GetClientProxy();
}
int LiteWMRequestor::Callback(void* owner, int code, IpcIo* reply)
{
if ((code != 0) || (owner == nullptr)) {
return -1;
}
CallBackPara* para = (CallBackPara*)owner;
switch (para->funcId) {
case LiteWMS_CreateWindow: {
LiteWinRequestor** requestor = (LiteWinRequestor**)(para->data);
if (requestor == nullptr) {
break;
}
int32_t id = IpcIoPopInt32(reply);
GRAPHIC_LOGI("CreateWindow, id=%d", id);
if (id == INVALID_WINDOW_ID) {
*requestor = nullptr;
} else {
*requestor = new LiteWinRequestor(id);
}
break;
}
case LiteWMS_GetEventData: {
uint32_t size;
DeviceData* data = static_cast<DeviceData*>(IpcIoPopFlatObj(reply, &size));
DeviceData* retData = (DeviceData*)(para->data);
if (data != nullptr && retData != nullptr) {
*retData = *data;
}
break;
}
case LiteWMS_Screenshot: {
int32_t ret = IpcIoPopInt32(reply);
if (ret != LiteWMS_EOK) {
GRAPHIC_LOGW("Screenshot busy!");
LiteWMRequestor::GetInstance()->ScreenShotClearup();
}
break;
}
case LiteWMS_GetLayerInfo: {
uint32_t size;
LiteLayerInfo* data = static_cast<LiteLayerInfo*>(IpcIoPopFlatObj(reply, &size));
LiteLayerInfo* retData = (LiteLayerInfo*)(para->data);
if (data != nullptr && retData != nullptr) {
*retData = *data;
}
break;
}
default:
break;
}
return 0;
}
int32_t LiteWMRequestor::WmsMsgHandler(const IpcContext* context, void* ipcMsg, IpcIo* io, void* arg)
{
// It's not used yet
return 0;
}
void LiteWMRequestor::ClientRegister()
{
IpcIo io;
uint8_t tmpData[DEFAULT_IPC_SIZE];
IpcIoInit(&io, tmpData, DEFAULT_IPC_SIZE, 1);
SvcIdentity svc;
if (RegisterIpcCallback(WmsMsgHandler, 0, IPC_WAIT_FOREVER, &svc, NULL) != LITEIPC_OK) {
GRAPHIC_LOGE("RegisterIpcCallback failed.");
return;
}
IpcIoPushSvc(&io, &svc);
int32_t ret = proxy_->Invoke(proxy_, LiteWMS_ClientRegister, &io, NULL, Callback);
if (ret != 0) {
GRAPHIC_LOGE("ClientRegister failed, ret=%d", ret);
}
}
void LiteWMRequestor::GetLayerInfo()
{
IpcIo io;
uint8_t tmpData[DEFAULT_IPC_SIZE];
IpcIoInit(&io, tmpData, DEFAULT_IPC_SIZE, 0);
CallBackPara para = {};
para.funcId = LiteWMS_GetLayerInfo;
para.data = &layerInfo_;
int32_t ret = proxy_->Invoke(proxy_, LiteWMS_GetLayerInfo, &io, &para, Callback);
if (ret != 0) {
GRAPHIC_LOGE("GetLayerInfo failed, ret=%d", ret);
}
}
LiteWinRequestor* LiteWMRequestor::CreateWindow(const LiteWinConfig& config)
{
IpcIo io;
uint8_t tmpData[DEFAULT_IPC_SIZE];
IpcIoInit(&io, tmpData, DEFAULT_IPC_SIZE, 0);
IpcIoPushFlatObj(&io, &config, sizeof(LiteWinConfig));
LiteWinRequestor* requestor = nullptr;
CallBackPara para = {};
para.funcId = LiteWMS_CreateWindow;
para.data = &requestor;
int32_t ret = proxy_->Invoke(proxy_, LiteWMS_CreateWindow, &io, &para, Callback);
if (ret != 0) {
GRAPHIC_LOGE("CreateWindow failed, ret=%d", ret);
}
return requestor;
}
void LiteWMRequestor::RemoveWindow(int32_t id)
{
IpcIo io;
uint8_t tmpData[DEFAULT_IPC_SIZE];
IpcIoInit(&io, tmpData, DEFAULT_IPC_SIZE, 0);
IpcIoPushInt32(&io, id);
int32_t ret = proxy_->Invoke(proxy_, LiteWMS_RemoveWindow, &io, NULL, Callback);
if (ret != 0) {
GRAPHIC_LOGE("RemoveWindow failed, ret=%d", ret);
}
}
void LiteWMRequestor::GetEventData(DeviceData* data)
{
IpcIo io;
uint8_t tmpData[DEFAULT_IPC_SIZE];
IpcIoInit(&io, tmpData, DEFAULT_IPC_SIZE, 0);
CallBackPara para = {};
para.funcId = LiteWMS_GetEventData;
para.data = data;
(void)proxy_->Invoke(proxy_, LiteWMS_GetEventData, &io, &para, Callback);
}
int LiteWMRequestor::SurfaceRequestHandler(const IpcContext* context, void* ipcMsg, IpcIo* io, void* arg)
{
SurfaceImpl* surface = (SurfaceImpl*)arg;
if (surface == nullptr) {
return 0;
}
surface->DoIpcMsg(ipcMsg, io);
return 0;
}
void LiteWMRequestor::ScreenShotClearup()
{
UnregisterIpcCallback(sid_);
if (surface_ != nullptr) {
delete surface_;
surface_ = nullptr;
}
}
void LiteWMRequestor::OnBufferAvailable()
{
GRAPHIC_LOGD("OnBufferAvailable");
if (surface_ != nullptr) {
SurfaceBuffer* buffer = surface_->AcquireBuffer();
if (buffer != nullptr) {
if (listener_ != nullptr) {
uint8_t* virAddr = static_cast<uint8_t*>(buffer->GetVirAddr());
uint32_t width = surface_->GetWidth();
uint32_t height = surface_->GetHeight();
ImagePixelFormat format = static_cast<ImagePixelFormat>(surface_->GetFormat());
uint32_t stride = surface_->GetStride();
listener_->OnScreenshotEnd(virAddr, width, height, format, stride);
}
surface_->ReleaseBuffer(buffer);
}
ScreenShotClearup();
}
}
void LiteWMRequestor::Screenshot()
{
if (surface_ != nullptr || listener_ == nullptr) {
return;
}
surface_ = Surface::CreateSurface();
if (surface_ == nullptr) {
return;
}
surface_->SetWidthAndHeight(layerInfo_.width, layerInfo_.height);
surface_->SetFormat(layerInfo_.pixelFormat);
surface_->SetUsage(1);
surface_->RegisterConsumerListener(*this);
int32_t ret = RegisterIpcCallback(SurfaceRequestHandler, 0, IPC_WAIT_FOREVER, &sid_, surface_);
if (ret != LITEIPC_OK) {
GRAPHIC_LOGE("RegisterIpcCallback failed.");
delete surface_;
surface_ = nullptr;
return;
}
IpcIo io;
uint8_t tmpData[DEFAULT_IPC_SIZE];
IpcIoInit(&io, tmpData, DEFAULT_IPC_SIZE, 1);
IpcIoPushSvc(&io, &sid_);
CallBackPara para = {};
para.funcId = LiteWMS_Screenshot;
ret = proxy_->Invoke(proxy_, LiteWMS_Screenshot, &io, &para, Callback);
if (ret != 0) {
GRAPHIC_LOGE("Screenshot failed, ret=%d", ret);
}
}
} // namespace OHOS
+65
View File
@@ -0,0 +1,65 @@
/*
* 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_LITE_WM_REQUESTOR_H
#define GRAPHIC_LITE_LITE_WM_REQUESTOR_H
#include "geometry2d.h"
#include "iproxy_client.h"
#include "iwindows_manager.h"
#include "lite_win_requestor.h"
#include "lite_wm_type.h"
#include "liteipc_adapter.h"
namespace OHOS {
class LiteWMRequestor : public IBufferConsumerListener {
public:
static LiteWMRequestor* GetInstance()
{
static LiteWMRequestor requestor;
return &requestor;
}
static int Callback(void* owner, int code, IpcIo* reply);
static int32_t WmsMsgHandler(const IpcContext* context, void* ipcMsg, IpcIo* io, void* arg);
static int32_t SurfaceRequestHandler(const IpcContext* context, void* ipcMsg, IpcIo* io, void* arg);
virtual void OnBufferAvailable() override;
void ClientRegister();
void GetLayerInfo();
LiteWinRequestor* CreateWindow(const LiteWinConfig& config);
void RemoveWindow(int32_t id);
void GetEventData(DeviceData* data);
void Screenshot();
void SetScreenshotListener(IWindowsManager::ScreenshotListener* listener)
{
listener_ = listener;
}
private:
LiteWMRequestor();
~LiteWMRequestor() {}
void ScreenShotClearup();
IClientProxy* proxy_;
IWindowsManager::ScreenshotListener* listener_;
Surface* surface_;
SvcIdentity sid_;
LiteLayerInfo layerInfo_;
};
} // namespace OHOS
#endif
+46
View File
@@ -0,0 +1,46 @@
/*
* 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 "lite_wms_client.h"
#include "graphic_log.h"
#include "lite_wm_type.h"
#include "samgr_lite.h"
namespace OHOS {
LiteWMSClient::~LiteWMSClient()
{
if (proxy_ != nullptr) {
proxy_->Release(reinterpret_cast<IUnknown*>(proxy_));
proxy_ = nullptr;
}
}
bool LiteWMSClient::InitLiteWMSClient()
{
if (proxy_ == nullptr) {
IUnknown* iUnknown = SAMGR_GetInstance()->GetDefaultFeatureApi(SERVICE_NAME);
if (iUnknown == nullptr) {
GRAPHIC_LOGE("iUnknown is NULL");
return false;
}
(void)iUnknown->QueryInterface(iUnknown, CLIENT_PROXY_VER, (void**)&proxy_);
if (proxy_ == nullptr) {
GRAPHIC_LOGE("QueryInterface failed!");
return false;
}
}
return true;
}
} // namespace OHOS
+48
View File
@@ -0,0 +1,48 @@
/*
* 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_LITE_WMS_CLIENT_H
#define GRAPHIC_LITE_LITE_WMS_CLIENT_H
#include <iproxy_client.h>
#include <iproxy_server.h>
#include <iunknown.h>
#include <unistd.h>
namespace OHOS {
static const int32_t DEFAULT_IPC_SIZE = 100;
class LiteWMSClient {
public:
static LiteWMSClient* GetInstance()
{
static LiteWMSClient client;
return &client;
}
bool InitLiteWMSClient();
IClientProxy* GetClientProxy()
{
return proxy_;
}
private:
LiteWMSClient() : proxy_(nullptr){}
~LiteWMSClient();
IClientProxy* proxy_;
};
}
#endif
+57
View File
@@ -0,0 +1,57 @@
/*
* 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_IMS_CLIENT_PROXY_H
#define GRAPHIC_LITE_IMS_CLIENT_PROXY_H
#include <iproxy_client.h>
#include "liteipc_adapter.h"
#include "input_event_info.h"
namespace OHOS {
class InputEventListenerProxy {
public:
static InputEventListenerProxy* GetInstance()
{
static InputEventListenerProxy client;
return &client;
}
class RawEventListener {
public:
virtual void OnRawEvent(const RawEvent& event) = 0;
};
bool RegisterInputEventListener(RawEventListener* listener);
bool UnregisterInputEventListener();
private:
InputEventListenerProxy() : proxy_(nullptr) {}
~InputEventListenerProxy();
bool GetIClientProxy();
static int32_t ReceiveMsgHandler(const IpcContext* context, void* ipcMsg, IpcIo* io, void* arg);
IClientProxy* proxy_;
static RawEventListener* listener_;
InputEventListenerProxy(const InputEventListenerProxy&) = delete;
InputEventListenerProxy& operator=(const InputEventListenerProxy&) = delete;
InputEventListenerProxy(InputEventListenerProxy&&) = delete;
InputEventListenerProxy& operator=(InputEventListenerProxy&&) = delete;
};
} // namespace OHOS
#endif
+41
View File
@@ -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_ISURFACE_H
#define GRAPHIC_LITE_ISURFACE_H
#include "geometry2d.h"
namespace OHOS {
/**
* @brief The ISurface class is an abstract definition of surface.
* Interface to a surface object, being a graphics context for rendering and state control,
* buffer operations, palette access.
*/
class ISurface {
public:
ISurface() {}
virtual ~ISurface() {}
virtual void Lock(void** buf, void** phyMem, uint32_t* strideLen) = 0;
/**
* @brief Unlock the surface.
*/
virtual void Unlock() = 0;
};
} // namespace OHOS
#endif // GRAPHIC_LITE_ISURFACE_H
+93
View File
@@ -0,0 +1,93 @@
/*
* 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_IWINDOW_H
#define GRAPHIC_LITE_IWINDOW_H
#include "isurface.h"
#include "lite_wm_type.h"
#include "geometry2d.h"
namespace OHOS {
/**
* @brief The IWindow class is an abstract definition of window. Each IWindow has a ISurface.
*/
class IWindow {
public:
IWindow() {}
virtual ~IWindow() {}
/**
* @brief Do some initialization after creating the window.
* @return The result of initialize.
*/
virtual int Init() = 0;
/**
* @brief Destroy the window.
*/
virtual void Destroy() = 0;
/**
* @brief Show the window.
*/
virtual void Show() = 0;
/**
* @brief Hide the window.
*/
virtual void Hide() = 0;
/**
* @brief Resize the window.
*/
virtual void Resize(int16_t width, int16_t height) = 0;
/**
* @brief Move the window to the specified coordinates.
*/
virtual void MoveTo(int16_t x, int16_t y) = 0;
/**
* @brief Put the window on the top of the window stack.
*/
virtual void RaiseToTop() = 0;
/**
* @brief Send a window to the bottom of the window stack.
*/
virtual void LowerToBottom() = 0;
/**
* @brief Get surface of the window.
* @return Pointer of surface
*/
virtual ISurface* GetSurface() = 0;
/**
* @brief Get identification of the window.
* @return Identification of the window
*/
virtual int32_t GetWindowId() = 0;
/**
* @brief Update window.
*/
virtual void Update() = 0;
};
}
#endif // GRAPHIC_LITE_IWINDOW_H
+64
View File
@@ -0,0 +1,64 @@
/*
* 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_IWINDOWS_MANAGER_H
#define GRAPHIC_LITE_IWINDOWS_MANAGER_H
#include "iwindow.h"
#include "geometry2d.h"
#include "input_event_info.h"
#include "list.h"
namespace OHOS {
/**
* @brief The IWindowsManager class is an abstract definition of windows manager.
* Provides a series of client/interfaces for window management, event processing, etc.
*/
class IWindowsManager {
public:
class ScreenshotListener {
public:
virtual void OnScreenshotEnd(uint8_t* virAddr, uint32_t width, uint32_t height,
ImagePixelFormat format, uint32_t stride) = 0;
};
IWindowsManager() {}
virtual ~IWindowsManager() {}
/**
* @brief Get the IWindowsManager's singleton.
* @return IWindowsManager's singleton
*/
static IWindowsManager* GetInstance();
/**
* @brief Do some initialization after creating the windows manager object.
* @return The result of initialize.
*/
virtual int Init() = 0;
virtual IWindow* CreateWindow(const LiteWinConfig& config) = 0;
virtual void RemoveWindow(IWindow* win) = 0;
virtual void GetEventData(DeviceData* data) = 0;
virtual void Screenshot() = 0;
virtual void SetScreenshotListener(ScreenshotListener* listener) = 0;
};
}
#endif // GRAPHIC_LITE_IWINDOWS_MANAGER_H
+88
View File
@@ -0,0 +1,88 @@
/*
* 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_LITE_WM_TYPE_H
#define GRAPHIC_LITE_LITE_WM_TYPE_H
#include "geometry2d.h"
#include "pixel_format_utils.h"
namespace OHOS {
struct LiteWinConfig {
enum CompositeMode {
COPY,
BLEND
};
Rect rect;
uint8_t opacity;
ImagePixelFormat pixelFormat;
CompositeMode compositeMode;
bool isModal;
};
struct LiteSurfaceData {
ImagePixelFormat pixelFormat;
uint16_t width;
uint16_t height;
uint8_t* virAddr;
uint8_t* phyAddr;
uint32_t stride;
uint8_t bytePerPixel;
};
struct LiteLayerInfo {
ImagePixelFormat pixelFormat;
uint16_t width;
uint16_t height;
};
typedef enum {
LiteWMS_GetSurface,
LiteWMS_Show,
LiteWMS_Hide,
LiteWMS_RaiseToTop,
LiteWMS_LowerToBottom,
LiteWMS_MoveTo,
LiteWMS_Resize,
LiteWMS_Update,
LiteWMS_CreateWindow,
LiteWMS_RemoveWindow,
LiteWMS_GetEventData,
LiteWMS_Screenshot,
LiteWMS_ClientRegister,
LiteWMS_GetLayerInfo
} LiteWMSCall;
typedef enum {
LiteWMS_EOK = 0,
LiteWMS_EUNKONW
} LiteWMSErrorCode;
struct CallBackPara {
int funcId;
void* data;
};
#ifdef LAYER_PF_ARGB1555
typedef uint16_t LayerColorType;
#elif defined LAYER_PF_ARGB8888
typedef uint32_t LayerColorType;
#endif
const char SERVICE_NAME[] = "WMS";
const int INVALID_WINDOW_ID = -1;
const int INVALID_PID = -1;
}
#endif
+104
View File
@@ -0,0 +1,104 @@
/*
* 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 "input_event_client_proxy.h"
#include "graphic_log.h"
#include "samgr_lite.h"
namespace OHOS {
pthread_mutex_t InputEventClientProxy::lock_;
void InputEventClientProxy::ClientRequestHandle(int funcId, void* origin, IpcIo* req, IpcIo* reply)
{
switch (funcId) {
case LITEIMS_CLIENT_REGISTER: {
InputEventClientProxy::GetInstance()->AddListener(origin, req, reply);
break;
}
case LITEIMS_CLIENT_UNREGISTER: {
InputEventClientProxy::GetInstance()->RemoveListener(origin, req, reply);
break;
}
default: {
break;
}
}
}
void InputEventClientProxy::AddListener(const void* origin, IpcIo* req, IpcIo* reply)
{
if (clientInfoMap_.size() >= MAX_CLIENT_SIZE) {
GRAPHIC_LOGE("Exceeded the maximum number!");
return;
}
pid_t pid = GetCallingPid(origin);
SvcIdentity* sid = IpcIoPopSvc(req);
if (sid == nullptr) {
GRAPHIC_LOGE("Pop Svc failed.");
return;
}
SvcIdentity svc = *sid;
#ifdef __LINUX__
BinderAcquire(svc.ipcContext, svc.handle);
free(sid);
sid = nullptr;
#endif
uint32_t cbId = 0;
if (RegisterDeathCallback(NULL, svc, DeathCallback, const_cast<void*>(origin), &cbId) != LITEIPC_OK) {
GRAPHIC_LOGE("Register death callback failed!");
return;
}
struct ClientInfo clientInfo = { svc, cbId };
pthread_mutex_lock(&lock_);
clientInfoMap_.insert(std::make_pair(pid, clientInfo));
pthread_mutex_unlock(&lock_);
}
int32_t InputEventClientProxy::DeathCallback(const IpcContext* context, void* ipcMsg, IpcIo* data, void* origin)
{
if (origin != nullptr) {
InputEventClientProxy::GetInstance()->RemoveListener(origin, nullptr, nullptr);
return 0;
}
return -1;
}
void InputEventClientProxy::RemoveListener(const void* origin, IpcIo* req, IpcIo* reply)
{
pid_t pid = GetCallingPid(origin);
if (clientInfoMap_.count(pid) > 0) {
#ifdef __LINUX__
BinderRelease(clientInfoMap_[pid].svc.ipcContext, clientInfoMap_[pid].svc.handle);
#endif
UnregisterDeathCallback(clientInfoMap_[pid].svc, clientInfoMap_[pid].cdId);
pthread_mutex_lock(&lock_);
clientInfoMap_.erase(pid);
pthread_mutex_unlock(&lock_);
}
}
void InputEventClientProxy::OnRawEvent(const RawEvent& event)
{
IpcIo io;
uint8_t tmpData[IMS_DEFAULT_IPC_SIZE];
IpcIoInit(&io, tmpData, IMS_DEFAULT_IPC_SIZE, 1);
IpcIoPushFlatObj(&io, static_cast<const void*>(&event), sizeof(RawEvent));
pthread_mutex_lock(&lock_);
std::map<pid_t, ClientInfo>::iterator it;
for (it = clientInfoMap_.begin(); it != clientInfoMap_.end(); it++) {
SendRequest(nullptr, it->second.svc, 0, &io, nullptr, LITEIPC_FLAG_ONEWAY, nullptr);
}
pthread_mutex_unlock(&lock_);
}
} // namespace OHOS
+30
View File
@@ -0,0 +1,30 @@
/*
* 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 "input_event_distributer.h"
#include "graphic_log.h"
namespace OHOS {
void InputEventDistributer::Distribute(const RawEvent* events, int32_t size)
{
for (int32_t i = 0; i < size; i++) {
for (auto listener : rawEventListeners_) {
if (listener != nullptr) {
listener->OnRawEvent(events[i]);
}
}
}
}
} // namespace OHOS
+77
View File
@@ -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.
*/
#ifndef GRAPHIC_LITE_INPUT_EVENT_DISTRIBUTER_H
#define GRAPHIC_LITE_INPUT_EVENT_DISTRIBUTER_H
#include <set>
#include "input_event_info.h"
namespace OHOS {
/**
* @brief Distributer distribute all input events to specific window.
*/
class InputEventDistributer {
public:
InputEventDistributer() {}
~InputEventDistributer() {}
/**
* @brief Distribute input events.
*
* @param [in] events events waiting for distribution.
* @param [in] size totoal size of events.
*
*/
void Distribute(const RawEvent* events, int32_t size);
/**
* @brief Listener of raw event.
*/
class RawEventListener {
public:
virtual void OnRawEvent(const RawEvent& event) = 0;
};
/**
* @brief Add a raw event listener.
*
* @param listener raw event listener.
*/
void AddRawEventListener(RawEventListener* listener)
{
if (listener == nullptr) {
return;
}
rawEventListeners_.insert(listener);
}
/**
* @brief Remove a raw event listener.
*
* @param listener raw event listener.
*/
void RemoveRawEventListener(RawEventListener* listener)
{
if (listener == nullptr) {
return;
}
rawEventListeners_.erase(listener);
}
private:
std::set<RawEventListener*> rawEventListeners_;
};
} // namespace OHOS
#endif // GRAPHIC_LITE_INPUT_EVENT_DISTRIBUTER_H
+177
View File
@@ -0,0 +1,177 @@
/*
* 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 "input_event_hub.h"
#include "graphic_log.h"
namespace OHOS {
const uint32_t TOUCH_DEV_ID = 1;
const uint32_t MOUSE_DEV_ID = 2;
const uint32_t UNKNOW_DEV_ID = 32;
IInputInterface* InputEventHub::inputInterface_ = nullptr;
InputReportEventCb InputEventHub::callback_ = { 0 };
InputEventHub::ReadCallback InputEventHub::readCallback_ = nullptr;
InputEventHub::InputEventHub()
{
for (uint8_t i = 0; i < MAX_INPUT_DEVICE_NUM; i++) {
mountDevIndex_[i] = UNKNOW_DEV_ID;
}
openDev_ = 0;
data_.deviceId = UNKNOW_DEV_ID;
data_.state = 0;
data_.timestamp = 0;
data_.type = InputDevType::INDEV_TYPE_UNKNOWN;
data_.x = 0;
data_.y = 0;
}
void InputEventHub::SetUp()
{
int32_t ret = GetInputInterface(&inputInterface_);
if (ret != INPUT_SUCCESS) {
GRAPHIC_LOGE("get input driver interface failed!");
return;
}
uint8_t num = ScanInputDevice();
if (num == 0) {
GRAPHIC_LOGE("There is no device!");
return;
}
for (uint8_t i = 0; i < num; i++) {
if (inputInterface_ == nullptr || inputInterface_->iInputManager == nullptr) {
GRAPHIC_LOGE("input interface or input manager is nullptr, open device failed!");
return;
}
ret = inputInterface_->iInputManager->OpenInputDevice(mountDevIndex_[i]);
if (ret == INPUT_SUCCESS && inputInterface_->iInputReporter != nullptr) {
callback_.ReportEventPkgCallback = EventCallback;
ret = inputInterface_->iInputReporter->RegisterReportCallback(mountDevIndex_[i], &callback_);
if (ret != INPUT_SUCCESS) {
GRAPHIC_LOGE("device dose not exist, can't register callback to it!");
return;
}
openDev_ = openDev_ | (1 << i);
}
}
}
void InputEventHub::TearDown()
{
int32_t ret = 0;
for (uint8_t i = 0; i < MAX_INPUT_DEVICE_NUM; i++) {
if ((openDev_ & (1 << i)) == 0) {
continue;
}
if (inputInterface_ == nullptr) {
GRAPHIC_LOGE("input interface point is nullptr!");
return;
}
if (inputInterface_->iInputReporter == nullptr || inputInterface_->iInputManager == nullptr) {
GRAPHIC_LOGE("input interface or input manager is nullptr, open device failed!");
return;
}
ret = inputInterface_->iInputReporter->UnregisterReportCallback(mountDevIndex_[i]);
if (ret != INPUT_SUCCESS) {
GRAPHIC_LOGE("Unregister callback failed!");
}
ret = inputInterface_->iInputManager->CloseInputDevice(mountDevIndex_[i]);
if (ret != INPUT_SUCCESS) {
GRAPHIC_LOGE("Unmount device failed!");
}
openDev_ = openDev_ & ~(1 << i);
}
if (inputInterface_ != nullptr) {
if (inputInterface_->iInputManager != nullptr) {
free(inputInterface_->iInputManager);
}
if (inputInterface_->iInputReporter != nullptr) {
free(inputInterface_->iInputReporter);
}
if (inputInterface_->iInputController != nullptr) {
free(inputInterface_->iInputController);
}
free(inputInterface_);
inputInterface_ = nullptr;
}
}
void InputEventHub::EventCallback(const EventPackage **pkgs, uint32_t count)
{
if (pkgs == nullptr || readCallback_ == nullptr || count == 0) {
return;
}
RawEvent& data = InputEventHub::GetInstance()->data_;
for (uint32_t i = 0; i < count; i++) {
if (pkgs[i]->type == EV_REL) {
data.type = InputDevType::INDEV_TYPE_MOUSE;
if (pkgs[i]->code == REL_X)
data.x += pkgs[i]->value;
else if (pkgs[i]->code == REL_Y)
data.y += pkgs[i]->value;
} else if (pkgs[i]->type == EV_ABS) {
data.type = InputDevType::INDEV_TYPE_TOUCH;
if (pkgs[i]->code == ABS_MT_POSITION_X)
data.x = pkgs[i]->value;
else if (pkgs[i]->code == ABS_MT_POSITION_Y)
data.y = pkgs[i]->value;
} else if (pkgs[i]->type == EV_KEY) {
if (pkgs[i]->code == BTN_MOUSE || pkgs[i]->code == BTN_TOUCH) {
if (pkgs[i]->value == 0)
data.state = 0;
else if (pkgs[i]->value == 1)
data.state = 1;
}
} else if (pkgs[i]->type == EV_SYN) {
if (pkgs[i]->code == SYN_REPORT) {
break;
}
}
}
readCallback_(&data);
}
InputDevType InputEventHub::GetDeviceType(uint32_t devIndex)
{
switch (devIndex) {
case TOUCH_DEV_ID: {
return InputDevType::INDEV_TYPE_TOUCH;
}
case MOUSE_DEV_ID: {
return InputDevType::INDEV_TYPE_MOUSE;
}
default: {
return InputDevType::INDEV_TYPE_UNKNOWN;
}
}
}
uint8_t InputEventHub::ScanInputDevice()
{
for (uint8_t i = 0; i < MAX_INPUT_DEVICE_NUM; i++) {
mountDevIndex_[i] = UNKNOW_DEV_ID;
}
/* later will be change get device mode */
uint32_t deviceNum = 0;
mountDevIndex_[0] = TOUCH_DEV_ID;
mountDevIndex_[1] = MOUSE_DEV_ID;
deviceNum = 2; // 2:Number of current devices
return deviceNum;
}
} // namespace OHOS
+87
View File
@@ -0,0 +1,87 @@
/*
* 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_HUB_H
#define GRAPHIC_LITE_INPUT_EVENT_HUB_H
#include <map>
#include "input-event-codes.h"
#include "input_event_info.h"
#include "input_manager.h"
#include "securec.h"
namespace OHOS {
/**
* @brief Hub of input event.
*/
class InputEventHub {
using ReadCallback = void (*)(const RawEvent*);
public:
static InputEventHub* GetInstance()
{
static InputEventHub instance;
return &instance;
}
/**
* @brief SetUp hub. This operation will open all input devices.
*
*/
void SetUp();
/**
* @brief TearDown hub. This operation will close all input devices.
*
*/
void TearDown();
/**
* @brief Registration read callback.
*
* @param [in] callback callback of read callback.
*
* @returns return -1: register callbacke failed; return 0: register success.
*/
int32_t RegisterReadCallback(ReadCallback callback)
{
if (callback == nullptr) {
return -1;
}
readCallback_ = callback;
return 0;
}
private:
static InputDevType GetDeviceType(uint32_t devIndex);
static void EventCallback(const EventPackage **pkgs, uint32_t count);
uint8_t ScanInputDevice();
InputEventHub();
~InputEventHub() {}
InputEventHub(const InputEventHub&) = delete;
InputEventHub& operator=(const InputEventHub&) = delete;
InputEventHub(InputEventHub&&) = delete;
InputEventHub& operator=(InputEventHub&&) = delete;
uint32_t mountDevIndex_[MAX_INPUT_DEVICE_NUM];
uint32_t openDev_;
RawEvent data_;
static IInputInterface* inputInterface_;
static InputReportEventCb callback_;
static ReadCallback readCallback_;
};
} // namespace OHOS
#endif
+90
View File
@@ -0,0 +1,90 @@
/*
* 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 "input_manager_service.h"
#include "graphic_log.h"
namespace OHOS {
InputEventHub* InputManagerService::hub_ = nullptr;
InputEventDistributer InputManagerService::distributer_;
pthread_t InputManagerService::distributerThread_ = -1;
int32_t InputManagerService::distributerThreadCreated_;
std::queue<RawEvent> InputManagerService::eventQueue_;
pthread_mutex_t InputManagerService::lock_;
pthread_cond_t InputManagerService::nonEmpty_;
pthread_cond_t InputManagerService::nonFull_;
void InputManagerService::Run()
{
hub_ = InputEventHub::GetInstance();
hub_->RegisterReadCallback(ReadCallback);
hub_->SetUp();
distributerThreadCreated_ = pthread_create(&distributerThread_, nullptr, Distribute, nullptr);
if (!distributerThreadCreated_) {
pthread_detach(distributerThread_);
}
}
void InputManagerService::Stop()
{
hub_->TearDown();
}
InputManagerService::~InputManagerService()
{
pthread_mutex_destroy(&lock_);
pthread_cond_destroy(&nonEmpty_);
pthread_cond_destroy(&nonFull_);
}
void InputManagerService::ReadCallback(const RawEvent* event)
{
if (event == nullptr) {
return;
}
pthread_mutex_lock(&lock_);
while (eventQueue_.size() == MAX_EVENT_SIZE) {
pthread_cond_wait(&nonFull_, &lock_);
}
// push events into queue
eventQueue_.push(event[0]);
pthread_mutex_unlock(&lock_);
pthread_cond_signal(&nonEmpty_);
}
void* InputManagerService::Distribute(void* args)
{
GRAPHIC_LOGI("InputManagerService::Distribute Ready to read distribute!");
while (true) {
pthread_mutex_lock(&lock_);
while (eventQueue_.size() == 0) {
pthread_cond_wait(&nonEmpty_, &lock_);
}
// pop events from queue
RawEvent events[MAX_INPUT_DEVICE_NUM];
int32_t len = (eventQueue_.size() > MAX_EVENT_SIZE) ? MAX_EVENT_SIZE : eventQueue_.size();
for (int32_t i = 0; i < len; i++) {
events[i] = eventQueue_.front();
eventQueue_.pop();
}
distributer_.Distribute(events, len);
pthread_mutex_unlock(&lock_);
pthread_cond_signal(&nonFull_);
}
return nullptr;
}
} // namespace OHOS
+101
View File
@@ -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_INPUT_MANAGER_SERVICE_H
#define GRAPHIC_LITE_INPUT_MANAGER_SERVICE_H
#include <pthread.h>
#include <queue>
#include "input_event_distributer.h"
#include "input_event_hub.h"
namespace OHOS {
/** @brief Manager service of input event. */
class InputManagerService {
public:
/**
* @brief Get instance of input manager service.
*
* @returns instance of input manager service
*/
static InputManagerService* GetInstance()
{
static InputManagerService instance;
return &instance;
}
/**
* Init input manager service.
*/
void Run();
/**
* Delete input manager service.
*/
void Stop();
/**
* @brief Distribute task function.
*
* @param args no use
*/
static void* Distribute(void* args);
/**
* @brief Get input event distributer in service.
*
* @returns input event distributer
*/
InputEventDistributer* GetDistributer()
{
return &distributer_;
}
/**
* @brief Get input event hub in service.
*
* @returns input event hub
*/
InputEventHub* GetHub()
{
return hub_;
}
private:
static void ReadCallback(const RawEvent* event);
InputManagerService()
{
pthread_mutex_init(&lock_, nullptr);
pthread_cond_init(&nonEmpty_, nullptr);
pthread_cond_init(&nonFull_, nullptr);
}
~InputManagerService();
InputManagerService(const InputManagerService&) = delete;
InputManagerService& operator=(const InputManagerService&) = delete;
InputManagerService(InputManagerService&&) = delete;
InputManagerService& operator=(InputManagerService&&) = delete;
static InputEventHub* hub_;
static InputEventDistributer distributer_;
static pthread_t distributerThread_;
static int32_t distributerThreadCreated_;
static std::queue<RawEvent> eventQueue_;
static pthread_mutex_t lock_;
static pthread_cond_t nonEmpty_;
static pthread_cond_t nonFull_;
};
} // namespace OHOS
#endif // GRAPHIC_LITE_INPUT_MANAGER_SERVICE_H
+99
View File
@@ -0,0 +1,99 @@
/*
* 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 <ohos_errno.h>
#include <ohos_init.h>
#include "feature.h"
#include "graphic_log.h"
#include "input_event_client_proxy.h"
#include "iproxy_client.h"
#include "iproxy_server.h"
#include "iunknown.h"
#include "samgr_lite.h"
#include "service.h"
namespace OHOS {
struct DefaultFeatureApi {
INHERIT_SERVER_IPROXY;
};
struct IMSService {
INHERIT_SERVICE;
INHERIT_IUNKNOWNENTRY(DefaultFeatureApi);
Identity identity;
};
static const char* GetName(Service* service)
{
(void)service;
return IMS_SERVICE_NAME;
}
static BOOL Initialize(Service* service, Identity identity)
{
IMSService* example = reinterpret_cast<IMSService*>(service);
example->identity = identity;
GRAPHIC_LOGI("Initialize(%s)! Identity<%d, %d, %p>", IMS_SERVICE_NAME,
identity.serviceId, identity.featureId, identity.queueId);
return TRUE;
}
static BOOL MessageHandle(Service* service, Request* msg)
{
GRAPHIC_LOGI("MessageHandle(%s)! Request<%d, %d, %p>",
service->GetName(service), msg->msgId, msg->msgValue, msg->data);
return FALSE;
}
static TaskConfig GetTaskConfig(Service* service)
{
(void)service;
TaskConfig config = {LEVEL_HIGH, PRI_BELOW_NORMAL, 0x800, 20, SHARED_TASK};
return config;
}
static int32 Invoke(IServerProxy* iProxy, int funcId, void* origin, IpcIo* req, IpcIo* reply)
{
InputEventClientProxy::GetInstance()->ClientRequestHandle(funcId, origin, req, reply);
return EC_SUCCESS;
}
static IMSService g_example = {
.GetName = GetName,
.Initialize = Initialize,
.MessageHandle = MessageHandle,
.GetTaskConfig = GetTaskConfig,
SERVER_IPROXY_IMPL_BEGIN,
.Invoke = Invoke,
IPROXY_END,
};
static void Init(void)
{
BOOL ret = SAMGR_GetInstance()->RegisterService(reinterpret_cast<Service*>(&g_example));
if (ret != TRUE) {
GRAPHIC_LOGE("regist service failed.");
return;
}
ret = SAMGR_GetInstance()->RegisterDefaultFeatureApi(IMS_SERVICE_NAME, GET_IUNKNOWN(g_example));
if (ret != TRUE) {
GRAPHIC_LOGE("regist feature failed.");
return;
}
}
SYSEX_SERVICE_INIT(Init);
} // namespace OHOS
+276
View File
@@ -0,0 +1,276 @@
/*
* 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 "lite_win.h"
#include "graphic_locker.h"
#include "graphic_log.h"
#include "graphic_performance.h"
#include "hals/gfx_engines.h"
#include "pixel_format_utils.h"
#include "securec.h"
#include "lite_wm.h"
#ifdef ARM_NEON_OPT
#include "graphic_neon_utils.h"
#endif
namespace OHOS {
#define COLOR_BLEND_RGBA(r1, g1, b1, a1, r2, g2, b2, a2) \
const float A1 = static_cast<float>(a1) / OPA_OPAQUE; \
const float A2 = static_cast<float>(a2) / OPA_OPAQUE; \
const float a = 1 - (1 - A1) * (1 - A2); \
(r1) = (A2 * (r2) + (1 - A2) * A1 * (r1)) / a; \
(g1) = (A2 * (g2) + (1 - A2) * A1 * (g1)) / a; \
(b1) = (A2 * (b2) + (1 - A2) * A1 * (b1)) / a; \
(a1) = a * OPA_OPAQUE;
#define COLOR_BLEND_RGB(r1, g1, b1, r2, g2, b2, a2) \
(r1) = (((r2) * (a2)) / OPA_OPAQUE) + (((r1) * (OPA_OPAQUE - (a2))) / OPA_OPAQUE); \
(g1) = (((g2) * (a2)) / OPA_OPAQUE) + (((g1) * (OPA_OPAQUE - (a2))) / OPA_OPAQUE); \
(b1) = (((b2) * (a2)) / OPA_OPAQUE) + (((b1) * (OPA_OPAQUE - (a2))) / OPA_OPAQUE);
namespace {
static const int16_t DEFAULT_QUEUE_SIZE = 2;
}
LiteWindow::LiteWindow(const LiteWinConfig& config)
: id_(INVALID_WINDOW_ID), pid_(INVALID_PID), isShow_(false), config_(config), surface_(nullptr),
backBuf_(nullptr), sid_({}), needUnregister_(false)
{
pthread_mutex_init(&backBufMutex_, NULL);
id_ = LiteWM::GetInstance()->GetUniqueWinId();
}
LiteWindow::~LiteWindow()
{
if (needUnregister_) {
GRAPHIC_LOGI("UnregisterIpcCallback");
UnregisterIpcCallback(sid_);
}
if (surface_ != nullptr) {
if (backBuf_ != nullptr) {
surface_->CancelBuffer(backBuf_);
}
delete surface_;
surface_ = nullptr;
}
LiteWM::GetInstance()->RecycleWinId(id_);
}
bool LiteWindow::CreateSurface()
{
if (surface_ == nullptr) {
surface_ = Surface::CreateSurface();
if (surface_ == nullptr) {
GRAPHIC_LOGE("CreateSurface failed!");
return false;
}
surface_->SetWidthAndHeight(config_.rect.GetWidth(), config_.rect.GetHeight());
surface_->SetQueueSize(DEFAULT_QUEUE_SIZE);
surface_->SetFormat(config_.pixelFormat);
surface_->SetUsage(BUFFER_CONSUMER_USAGE_HARDWARE);
if (backBuf_ == nullptr) {
backBuf_ = surface_->RequestBuffer();
}
}
return true;
}
void LiteWindow::ReleaseSurface()
{
}
void LiteWindow::ResizeSurface(int16_t width, int16_t height)
{
if (surface_ == nullptr) {
return;
}
GraphicLocker lock(backBufMutex_);
if (backBuf_ != nullptr) {
surface_->CancelBuffer(backBuf_);
}
surface_->SetWidthAndHeight(width, height);
backBuf_ = surface_->RequestBuffer();
}
void LiteWindow::Update(Rect rect)
{
LiteWM::GetInstance()->UpdateWindowRegion(this, rect);
}
void LiteWindow::UpdateBackBuf()
{
GraphicLocker lock(backBufMutex_);
if (surface_ == nullptr || backBuf_ == nullptr) {
return;
}
SurfaceBuffer* acquireBuffer = surface_->AcquireBuffer();
if (acquireBuffer != nullptr) {
void* acquireBufVirAddr = acquireBuffer->GetVirAddr();
void* backBufVirAddr = backBuf_->GetVirAddr();
if (acquireBufVirAddr != nullptr && backBufVirAddr != nullptr) {
GRAPHIC_LOGI("memcpy, backBuf size=%d, acquireBuffer size=%d",
backBuf_->GetSize(), acquireBuffer->GetSize());
#ifdef ARM_NEON_OPT
{
DEBUG_PERFORMANCE_TRACE("UpdateBackBuf_neon");
NeonMemcpy(backBufVirAddr, backBuf_->GetSize(), acquireBufVirAddr, acquireBuffer->GetSize());
}
#else
{
DEBUG_PERFORMANCE_TRACE("UpdateBackBuf");
if (memcpy_s(backBufVirAddr, backBuf_->GetSize(),
acquireBufVirAddr, acquireBuffer->GetSize()) != EOK) {
GRAPHIC_LOGE("memcpy_s error!");
}
}
#endif
GRAPHIC_LOGI("memcpy end");
}
surface_->ReleaseBuffer(acquireBuffer);
}
}
void LiteWindow::FlushWithModeCopy(const Rect& srcRect, const LiteSurfaceData* layerData, int16_t dx, int16_t dy)
{
int16_t x1 = srcRect.GetLeft();
int16_t y1 = srcRect.GetTop();
int16_t x2 = srcRect.GetRight();
int16_t y2 = srcRect.GetBottom();
uint32_t stride = surface_->GetStride();
uint8_t* srcBuf = reinterpret_cast<uint8_t*>(backBuf_->GetVirAddr()) + y1 * stride + x1 * sizeof(ColorType);
uint8_t* dstBuf = layerData->virAddr + dy * layerData->stride + dx * sizeof(LayerColorType);
int32_t lineSize = static_cast<int32_t>(x2 - x1 + 1) * sizeof(LayerColorType);
for (int16_t y = y1; y <= y2; ++y) {
#ifdef LAYER_PF_ARGB1555
ColorType* tmpSrc = reinterpret_cast<ColorType*>(srcBuf);
LayerColorType* tmpDst = reinterpret_cast<LayerColorType*>(dstBuf);
for (int16_t x = x1; x <= x2; ++x) {
*tmpDst++ = PixelFormatUtils::ARGB8888ToARGB1555((tmpSrc++)->full);
}
#elif defined LAYER_PF_ARGB8888
if (memcpy_s(dstBuf, lineSize, srcBuf, lineSize) != EOK) {
GRAPHIC_LOGE("memcpy_s error!");
}
#endif
srcBuf += stride;
dstBuf += layerData->stride;
}
}
void LiteWindow::FlushWithModeBlend(const Rect& srcRect, const LiteSurfaceData* layerData, int16_t dx, int16_t dy)
{
int16_t x1 = srcRect.GetLeft();
int16_t y1 = srcRect.GetTop();
int16_t x2 = srcRect.GetRight();
int16_t y2 = srcRect.GetBottom();
uint32_t stride = surface_->GetStride();
uint8_t* srcBuf = reinterpret_cast<uint8_t*>(backBuf_->GetVirAddr()) + y1 * stride + x1 * sizeof(ColorType);
uint8_t* dstBuf = layerData->virAddr + dy * layerData->stride + dx * sizeof(LayerColorType);
for (int16_t y = y1; y <= y2; ++y) {
ColorType* tmpSrc = reinterpret_cast<ColorType*>(srcBuf);
LayerColorType* tmpDst = reinterpret_cast<LayerColorType*>(dstBuf);
for (int16_t x = x1; x <= x2; ++x) {
uint8_t alpha = tmpSrc->alpha * config_.opacity / OPA_OPAQUE;
#ifdef LAYER_PF_ARGB1555
PF_ARGB1555* dst = reinterpret_cast<PF_ARGB1555*>(tmpDst);
if (dst->alpha == 0) {
if (alpha) {
// ARGB8888 to ARGB1555, R/G/B shoud right shift 3 bits
dst->red = (tmpSrc->red * alpha / OPA_OPAQUE) >> 3;
dst->green = (tmpSrc->green * alpha / OPA_OPAQUE) >> 3;
dst->blue = (tmpSrc->blue * alpha / OPA_OPAQUE) >> 3;
dst->alpha = 1;
}
} else {
COLOR_BLEND_RGB(dst->red, dst->green, dst->blue,
(tmpSrc->red) >> 3, (tmpSrc->green) >> 3, (tmpSrc->blue) >> 3, alpha);
}
#elif defined LAYER_PF_ARGB8888
if (alpha == OPA_OPAQUE) {
*tmpDst = tmpSrc->full;
} else {
Color32* dst = reinterpret_cast<Color32*>(tmpDst);
COLOR_BLEND_RGBA(dst->red, dst->green, dst->blue, dst->alpha,
tmpSrc->red, tmpSrc->green, tmpSrc->blue, alpha);
}
#endif
++tmpSrc;
++tmpDst;
}
srcBuf += stride;
dstBuf += layerData->stride;
}
}
void LiteWindow::Flush(const Rect& srcRect, const LiteSurfaceData* layerData, int16_t dx, int16_t dy)
{
if (layerData == nullptr) {
return;
}
GraphicLocker lock(backBufMutex_);
#if ENABLE_GFX_ENGINES
uintptr_t phyaddr = backBuf_->GetPhyAddr();
if (IsCoverMode() && phyaddr) {
LiteSurfaceData srcData;
srcData.width = surface_->GetWidth();
srcData.height = surface_->GetHeight();
srcData.pixelFormat = (ImagePixelFormat)surface_->GetFormat();
srcData.stride = surface_->GetStride();
srcData.phyAddr = reinterpret_cast<uint8_t*>(phyaddr);
GRAPHIC_LOGD("Hardware composite, width=%d, height=%d, pixelFormat=%d, stride=%d",
srcData.width, srcData.height, srcData.pixelFormat, srcData.stride);
if (GfxEngines::GetInstance()->GfxBlit(srcData, srcRect, *layerData, dx, dy)) {
return;
}
}
#endif
if (config_.compositeMode == LiteWinConfig::COPY) {
FlushWithModeCopy(srcRect, layerData, dx, dy);
} else if (config_.compositeMode == LiteWinConfig::BLEND) {
FlushWithModeBlend(srcRect, layerData, dx, dy);
}
}
Surface* LiteWindow::GetSurface()
{
return surface_;
}
void LiteWindow::MoveTo(int16_t x, int16_t y)
{
GRAPHIC_LOGI("{%d,%d}=>{%d,%d}", config_.rect.GetLeft(), config_.rect.GetTop(), x, y);
LiteWM::GetInstance()->UpdateWindowRegion(this, config_.rect);
config_.rect.SetPosition(x, y);
LiteWM::GetInstance()->UpdateWindowRegion(this, config_.rect);
}
void LiteWindow::Resize(int16_t width, int16_t height)
{
GRAPHIC_LOGI("{%d,%d}=>{%d,%d}", config_.rect.GetWidth(), config_.rect.GetHeight(), width, height);
config_.rect.Resize(width, height);
ResizeSurface(width, height);
}
}
+107
View File
@@ -0,0 +1,107 @@
/*
* 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_LITE_WIN_H
#define GRAPHIC_LITE_LITE_WIN_H
#include <pthread.h>
#include "liteipc_adapter.h"
#include "serializer.h"
#include "color.h"
#include "geometry2d.h"
#include "isurface.h"
#include "lite_wm_type.h"
#include "surface.h"
namespace OHOS {
class LiteWindow {
public:
friend class LiteWM;
explicit LiteWindow(const LiteWinConfig& config);
virtual ~LiteWindow();
int32_t GetWindowId() const
{
return id_;
}
const LiteWinConfig& GetConfig()
{
return config_;
}
void SetSid(const SvcIdentity& sid)
{
needUnregister_ = true;
sid_ = sid;
}
void SetIsShow(bool isShow)
{
isShow_ = isShow;
}
bool GetIsShow()
{
return isShow_;
}
void SetPid(pid_t pid)
{
pid_ = pid;
}
pid_t GetPid()
{
return pid_;
}
bool IsCoverMode()
{
return config_.compositeMode == LiteWinConfig::COPY;
}
bool NoNeedToDraw()
{
return config_.compositeMode == LiteWinConfig::BLEND && config_.opacity == OPA_TRANSPARENT;
}
void ResizeSurface(int16_t width, int16_t height);
void Update(Rect rect);
void UpdateBackBuf();
void Flush(const Rect& srcRect, const LiteSurfaceData* layerData, int16_t dx, int16_t dy);
Surface* GetSurface();
void MoveTo(int16_t x, int16_t y);
void Resize(int16_t width, int16_t height);
private:
bool CreateSurface();
void ReleaseSurface();
void FlushWithModeCopy(const Rect& srcRect, const LiteSurfaceData* layerData, int16_t dx, int16_t dy);
void FlushWithModeBlend(const Rect& srcRect, const LiteSurfaceData* layerData, int16_t dx, int16_t dy);
int32_t id_;
pid_t pid_;
bool isShow_;
LiteWinConfig config_;
Surface* surface_;
SurfaceBuffer* backBuf_;
pthread_mutex_t backBufMutex_;
SvcIdentity sid_;
bool needUnregister_;
};
}
#endif
+765
View File
@@ -0,0 +1,765 @@
/*
* 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 "lite_wm.h"
#include "color.h"
#include "graphic_log.h"
#include "pixel_format_utils.h"
namespace OHOS {
namespace {
#define EXPAND_RECT(x) x.GetLeft(), x.GetTop(), x.GetRight(), x.GetBottom()
const uint16_t CURSOR_WIDTH = 24;
const uint16_t CURSOR_HEIGHT = 25;
const uint8_t CURSOR_MAP[] = {
/* Pixel format: ARGB1555 */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x80,
0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x80, 0x00,
0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x80, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x80, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x80, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x80,
0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x80, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00,
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x80,
0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x80, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00,
0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x80, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80,
0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80,
0x00, 0x80, 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00,
0x80, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x80, 0x00,
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x80, 0x00,
0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x80, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00,
};
const uint8_t MAX_WINDOW_NUMBLE = 32;
const uint32_t WINDOW_ID_FULL_STORAGE = 0xFFFFFFFF;
}
LiteWM::LiteWM()
: updates_({}), layerData_(nullptr), cursorInfo_({}), mousePosition_({}), deviceData_({}),
needScreenshot_(false), screenshotSurface_(nullptr), winIdStorage(0)
{
InitMutex(stackLock_, PTHREAD_MUTEX_RECURSIVE);
pthread_mutex_init(&mouseLock_, NULL);
pthread_mutex_init(&eventLock_, NULL);
pthread_mutex_init(&screenshotMutex_, NULL);
InputManagerService::GetInstance()->GetDistributer()->AddRawEventListener(this);
InitMouseCursor();
layerData_ = GetDevSurfaceData();
if (layerData_ != nullptr) {
if (layerData_->virAddr == nullptr) {
GRAPHIC_LOGE("LayerInfo addr is null!");
}
GRAPHIC_LOGI("LayerInfo, width=%d, height=%d, stride=%d",
layerData_->width, layerData_->height, layerData_->stride);
} else {
GRAPHIC_LOGE("LayerInfo is null!");
}
}
LiteWM::~LiteWM()
{
}
void LiteWM::MainTaskHandler()
{
if (layerData_ == nullptr || layerData_->virAddr == nullptr) {
return;
}
if (needScreenshot_) {
Screenshot();
needScreenshot_ = false;
}
if (cursorInfo_.enableCursor) {
UpdateMouseCursor();
}
ProcessUpdates();
}
void LiteWM::UpdateMouseCursor()
{
Rect& rect = cursorInfo_.rect;
Point point = GetMousePosition();
if (rect.GetLeft() == point.x && rect.GetTop() == point.y) {
return;
}
cursorInfo_.needRedraw = true;
AddUpdateRegion(rect);
rect.SetPosition(point.x, point.y);
}
void LiteWM::GetLayerInfo(LiteLayerInfo& layerInfo)
{
if (layerData_ == nullptr) {
return;
}
layerInfo.pixelFormat = layerData_->pixelFormat;
layerInfo.width = layerData_->width;
layerInfo.height = layerData_->height;
}
Surface* LiteWM::GetSurface(int32_t id)
{
LiteWindow* window = GetWindowById(id);
if (window != nullptr) {
return window->GetSurface();
}
return nullptr;
}
void LiteWM::Show(int32_t id)
{
GraphicLocker lock(stackLock_);
LiteWindow* window = GetWindowById(id);
if (window != nullptr) {
window->SetIsShow(true);
UpdateWindowRegion(window, window->config_.rect);
}
}
void LiteWM::Hide(int32_t id)
{
GraphicLocker lock(stackLock_);
LiteWindow* window = GetWindowById(id);
if (window != nullptr) {
window->SetIsShow(false);
UpdateWindowRegion(window, window->config_.rect);
}
}
void LiteWM::RaiseToTop(int32_t id)
{
GraphicLocker lock(stackLock_);
auto node = GetWindowNodeById(id);
if (node != nullptr) {
node->prev_->next_ = node->next_;
node->next_->prev_ = node->prev_;
auto head = winList_.Begin()->prev_;
node->next_ = head->next_;
node->prev_ = head;
head->next_->prev_ = node;
head->next_ = node;
if (node->data_ != nullptr) {
UpdateWindowRegion(winList_.Begin()->data_, node->data_->config_.rect);
}
}
}
void LiteWM::LowerToBottom(int32_t id)
{
GraphicLocker lock(stackLock_);
auto node = GetWindowNodeById(id);
if (node != nullptr) {
node->prev_->next_ = node->next_;
node->next_->prev_ = node->prev_;
auto head = winList_.Begin()->prev_;
node->prev_ = head->prev_;
node->next_ = head;
head->prev_->next_ = node;
head->prev_ = node;
if (node->data_ != nullptr) {
UpdateWindowRegion(winList_.Begin()->data_, node->data_->config_.rect);
}
}
}
void LiteWM::MoveTo(int32_t id, int16_t x, int16_t y)
{
GraphicLocker lock(stackLock_);
LiteWindow* window = GetWindowById(id);
if (window != nullptr) {
window->MoveTo(x, y);
}
}
void LiteWM::Resize(int32_t id, int16_t width, int16_t height)
{
GraphicLocker lock(stackLock_);
LiteWindow* window = GetWindowById(id);
if (window == nullptr) {
return;
}
Rect rectBefore = window->config_.rect;
window->Resize(width, height);
Rect rectAfter = window->config_.rect;
Rect mask;
if (mask.Intersect(rectBefore, rectAfter)) {
int16_t x1 = mask.GetLeft();
int16_t x2 = mask.GetRight();
int16_t y1 = mask.GetTop();
int16_t y2 = mask.GetBottom();
if (x2 != rectBefore.GetRight()) {
UpdateWindowRegion(window, {static_cast<int16_t>(x2 + 1), y1, rectBefore.GetRight(),
rectBefore.GetBottom()});
}
if (y2 != rectBefore.GetBottom()) {
UpdateWindowRegion(window, {x1, static_cast<int16_t>(y2 + 1), x2, rectBefore.GetBottom()});
}
}
}
void LiteWM::UpdateWindow(int32_t id)
{
GRAPHIC_LOGI("UpdateWindow, id=%d", id);
LiteWindow* window = GetWindowById(id);
if (window != nullptr) {
UpdateWindowRegion(window, window->config_.rect);
}
}
LiteWindow* LiteWM::GetWindowById(int32_t id)
{
if (id == INVALID_WINDOW_ID) {
return nullptr;
}
LiteWindow* ret = nullptr;
auto node = winList_.Begin();
while (node != winList_.End()) {
if (node->data_->id_ == id) {
ret = node->data_;
break;
}
node = node->next_;
}
return ret;
}
ListNode<LiteWindow*>* LiteWM::GetWindowNodeById(int32_t id)
{
if (id == INVALID_WINDOW_ID) {
return nullptr;
}
ListNode<LiteWindow*>* ret = nullptr;
auto node = winList_.Begin();
while (node != winList_.End()) {
if (node->data_->id_ == id) {
ret = node;
break;
}
node = node->next_;
}
return ret;
}
void LiteWM::InitMouseCursor()
{
GRAPHIC_LOGI("InitMouseCursor");
cursorInfo_.rect.SetRect(0, 0, CURSOR_WIDTH - 1, CURSOR_HEIGHT - 1);
cursorInfo_.needRedraw = false;
cursorInfo_.enableCursor = false;
}
LiteWindow* LiteWM::CreateWindow(const LiteWinConfig& config, pid_t pid)
{
GraphicLocker lock(stackLock_);
if (CheckWinIdIsAvailable() == false) {
return nullptr;
}
LiteWindow* window = new LiteWindow(config);
if (window == nullptr) {
return nullptr;
}
if (!window->CreateSurface()) {
delete window;
return nullptr;
}
window->SetPid(pid);
winList_.PushFront(window);
return window;
}
void LiteWM::RemoveWindow(int32_t id)
{
GraphicLocker lock(stackLock_);
auto node = GetWindowNodeById(id);
if (node == nullptr) {
return;
}
LiteWindow* window = node->data_;
winList_.Remove(node);
if (window != nullptr) {
AddUpdateRegion(window->config_.rect);
delete window;
}
}
bool LiteWM::CheckWinIdIsAvailable()
{
if (winIdStorage == WINDOW_ID_FULL_STORAGE) {
GRAPHIC_LOGE("reach max window num!");
return false;
}
return true;
}
int32_t LiteWM::GetUniqueWinId()
{
static uint8_t winId = 0;
if (CheckWinIdIsAvailable() == false) {
return INVALID_WINDOW_ID;
}
while (winIdStorage & (1 << winId)) {
winId++;
winId %= MAX_WINDOW_NUMBLE;
}
winIdStorage |= (1 << winId);
return winId;
}
void LiteWM::RecycleWinId(int32_t id)
{
if (id == INVALID_WINDOW_ID) {
return;
}
winIdStorage &= (~(1 << static_cast<uint32_t>(id)));
}
void LiteWM::InitMutex(pthread_mutex_t& mutex, int type)
{
pthread_mutexattr_t attr;
pthread_mutexattr_init(&attr);
pthread_mutexattr_settype(&attr, type);
pthread_mutex_init(&mutex, &attr);
pthread_mutexattr_destroy(&attr);
}
void LiteWM::UpdateWindowRegion(const LiteWindow* window, const Rect& rect)
{
ListNode<LiteWindow *>* winNode = winList_.Tail();
while (winNode != winList_.End()) {
if (winNode->data_ == window) {
CalculateUpdateRegion(winNode->prev_, EXPAND_RECT(rect));
return;
}
winNode = winNode->prev_;
}
AddUpdateRegion(rect);
}
void LiteWM::CalculateUpdateRegion(const ListNode<LiteWindow*>* winNode, int16_t x1, int16_t y1, int16_t x2, int16_t y2)
{
Rect rect(x1, y1, x2, y2);
if (winNode == winList_.End()) {
AddUpdateRegion(rect);
return;
}
if (winNode == nullptr) {
return;
}
LiteWindow* window = winNode->data_;
if ((window != nullptr) && window->isShow_ && window->IsCoverMode()) {
Rect& winRect = window->config_.rect;
Rect mask;
GRAPHIC_LOGD("winRect={%d,%d,%d,%d}, rect={%d,%d,%d,%d}", EXPAND_RECT(winRect), EXPAND_RECT(rect));
if (mask.Intersect(winRect, rect)) {
if (x1 != mask.GetLeft()) {
CalculateUpdateRegion(winNode->prev_, x1, y1, mask.GetLeft() - 1, y2);
}
if (y1 != mask.GetTop()) {
CalculateUpdateRegion(winNode->prev_, mask.GetLeft(), y1, x2, mask.GetTop() - 1);
}
if (x2 != mask.GetRight()) {
CalculateUpdateRegion(winNode->prev_, mask.GetRight() + 1, mask.GetTop(), x2, y2);
}
if (y2 != mask.GetBottom()) {
CalculateUpdateRegion(winNode->prev_, mask.GetLeft(), mask.GetBottom() + 1, mask.GetRight(), y2);
}
return;
}
}
CalculateUpdateRegion(winNode->prev_, x1, y1, x2, y2);
}
void LiteWM::AddUpdateRegion(const Rect& rect)
{
GraphicLocker lock(stackLock_);
GRAPHIC_LOGD("AddUpdateRegion, rect={%d,%d,%d,%d}", EXPAND_RECT(rect));
if (updates_.num == 0) {
updates_.updates[updates_.num++] = rect;
updates_.bound = rect;
} else {
for (int i = 0; i < updates_.num; i++) {
Rect& updateRect = updates_.updates[i];
if (updateRect.IsIntersect(rect) || updateRect.IsExtends(rect)) {
updateRect.Join(updateRect, rect);
updates_.bound.Join(updates_.bound, rect);
return;
}
}
if (updates_.num == MAX_UPDATE_SIZE) {
updates_.bound.Join(updates_.bound, rect);
updates_.num = 0;
updates_.updates[updates_.num++] = updates_.bound;
} else {
updates_.updates[updates_.num++] = rect;
updates_.bound.Join(updates_.bound, rect);
}
}
}
void LiteWM::ProcessUpdates()
{
bool needFlush = false;
{
GraphicLocker lock(stackLock_);
for (int i = 0; i < updates_.num; i++) {
ListNode<LiteWindow *>* winNode = winList_.Begin();
DrawRegion(winNode, EXPAND_RECT(updates_.updates[i]));
if (cursorInfo_.enableCursor && cursorInfo_.rect.IsIntersect(updates_.updates[i])) {
cursorInfo_.needRedraw = true;
}
}
if (updates_.num != 0 || (cursorInfo_.enableCursor && cursorInfo_.needRedraw)) {
needFlush = true;
}
updates_ = {};
}
if (cursorInfo_.enableCursor && cursorInfo_.needRedraw) {
DrawMouseCursor();
cursorInfo_.needRedraw = false;
}
if (needFlush) {
LcdFlush();
}
}
void LiteWM::DrawRegion(const ListNode<LiteWindow*>* winNode, int16_t x1, int16_t y1, int16_t x2, int16_t y2)
{
if (winNode == nullptr) {
return;
}
if (winNode == winList_.End()) {
DrawBackground(x1, y1, x2, y2);
return;
}
LiteWindow* window = winNode->data_;
if (window == nullptr) {
return;
}
window->UpdateBackBuf();
Rect rect(x1, y1, x2, y2);
Rect& winRect = window->config_.rect;
Rect mask;
if (!window->isShow_ || window->NoNeedToDraw() ||
window->backBuf_ == nullptr || !mask.Intersect(winRect, rect)) {
GRAPHIC_LOGI("winRect={%d,%d,%d,%d}, rect={%d,%d,%d,%d}", EXPAND_RECT(winRect), EXPAND_RECT(rect));
DrawRegion(winNode->next_, x1, y1, x2, y2);
return;
}
int x = mask.GetLeft();
int y = mask.GetTop();
if (!window->IsCoverMode()) {
DrawRegion(winNode->next_, EXPAND_RECT(mask));
}
Rect srcRect = mask;
srcRect.SetPosition(mask.GetLeft() - winRect.GetLeft(), mask.GetTop() - winRect.GetTop());
GRAPHIC_LOGD("Blit, id=%d, srcRect={%d,%d,%d,%d}, x=%d, y=%d", window->id_, EXPAND_RECT(srcRect), x, y);
window->Flush(srcRect, layerData_, x, y);
GRAPHIC_LOGD("Blit finish");
if (x1 != mask.GetLeft()) {
DrawRegion(winNode->next_, x1, y1, mask.GetLeft() - 1, y2);
}
if (y1 != mask.GetTop()) {
DrawRegion(winNode->next_, mask.GetLeft(), y1, x2, mask.GetTop() - 1);
}
if (x2 != mask.GetRight()) {
DrawRegion(winNode->next_, mask.GetRight() + 1, mask.GetTop(), x2, y2);
}
if (y2 != mask.GetBottom()) {
DrawRegion(winNode->next_, mask.GetLeft(), mask.GetBottom() + 1, mask.GetRight(), y2);
}
}
void LiteWM::DrawBackground(int16_t x1, int16_t y1, int16_t x2, int16_t y2)
{
Rect rect(0, 0, layerData_->width - 1, layerData_->height - 1);
Rect rectBg(x1, y1, x2, y2);
if (rect.Intersect(rect, rectBg) == false) {
return;
}
x1 = rect.GetLeft();
x2 = rect.GetRight();
y1 = rect.GetTop();
y2 = rect.GetBottom();
GRAPHIC_LOGD("DrawBackground, {%d,%d,%d,%d}", x1, y1, x2, y2);
int32_t len = static_cast<int32_t>(x2 - x1 + 1) * layerData_->bytePerPixel;
for (int16_t y = y1; y <= y2; y++) {
LayerColorType* buf1 = reinterpret_cast<LayerColorType*>(layerData_->virAddr + y * layerData_->stride);
if (memset_s(buf1 + x1, len, 0, len) != EOK) {
GRAPHIC_LOGE("memset_s error!");
}
}
}
void LiteWM::DrawMouseCursor()
{
Rect rect(0, 0, layerData_->width - 1, layerData_->height - 1);
if (rect.Intersect(rect, cursorInfo_.rect) == false) {
return;
}
int16_t x1 = rect.GetLeft();
int16_t x2 = rect.GetRight();
int16_t y1 = rect.GetTop();
int16_t y2 = rect.GetBottom();
const uint16_t* srcbuf = reinterpret_cast<const uint16_t*>(CURSOR_MAP);
uint8_t* dstBuf = layerData_->virAddr + y1 * layerData_->stride + x1 * sizeof(LayerColorType);
for (int16_t y = y1; y <= y2; y++) {
const uint16_t* tmpSrc = srcbuf;
LayerColorType* tmpDst = reinterpret_cast<LayerColorType*>(dstBuf);
for (int16_t x = x1; x <= x2; x++) {
if ((*tmpSrc) & 0x8000) {
#ifdef LAYER_PF_ARGB1555
*tmpDst = *tmpSrc;
#elif defined LAYER_PF_ARGB8888
*tmpDst = PixelFormatUtils::ARGB1555ToARGB8888(*tmpSrc);
#endif
}
tmpSrc++;
tmpDst++;
}
dstBuf += layerData_->stride;
srcbuf += CURSOR_WIDTH;
}
}
LiteWindow* LiteWM::FindTargetWindow(const RawEvent& event)
{
if (winList_.IsEmpty()) {
return nullptr;
}
LiteWindow* targetWindow = nullptr;
auto node = winList_.Begin();
while (node != winList_.End()) {
if (node->data_->GetConfig().isModal) {
return node->data_;
}
node = node->next_;
}
switch (event.type) {
case InputDevType::INDEV_TYPE_MOUSE:
case InputDevType::INDEV_TYPE_TOUCH: {
auto node = winList_.Begin();
while (node != winList_.End()) {
Point p = { event.x, event.y };
if (node->data_->isShow_ && node->data_->GetConfig().rect.IsContains(p)) {
targetWindow = node->data_;
break;
}
node = node->next_;
}
break;
}
case InputDevType::INDEV_TYPE_KEY:
case InputDevType::INDEV_TYPE_BUTTON: {
targetWindow = winList_.Front();
break;
}
default:
break;
}
return targetWindow;
}
void LiteWM::OnRawEvent(const RawEvent& rawEvent)
{
static bool firstTime = true;
if (layerData_ == nullptr) {
return;
}
RawEvent event = rawEvent;
if (GetLayerRotateType() == LAYER_ROTATE_90) {
int16_t tmp = layerData_->height - event.x;
event.x = event.y;
event.y = tmp;
}
if (firstTime) {
if (event.type == InputDevType::INDEV_TYPE_MOUSE) {
cursorInfo_.enableCursor = true;
cursorInfo_.needRedraw = true;
} else {
cursorInfo_.enableCursor = false;
}
firstTime = false;
}
if (cursorInfo_.enableCursor) {
SetMousePosition(event.x, event.y);
}
LiteWindow* targetWindow = FindTargetWindow(event);
if (targetWindow == nullptr) {
return;
}
SetEventData(targetWindow, event);
}
bool LiteWM::OnScreenshot(Surface* surface)
{
GraphicLocker lock(screenshotMutex_);
if (!needScreenshot_) {
screenshotSurface_ = surface;
needScreenshot_ = true;
return true;
}
return false;
}
void LiteWM::Screenshot()
{
int32_t lineSize = 0;
int16_t bpp = 0;
uint8_t* dstAddr = nullptr;
uint8_t* srcAddr = nullptr;
uint32_t width = 0;
uint32_t height = 0;
if (screenshotSurface_ == nullptr) {
return;
}
SurfaceBuffer* buffer = screenshotSurface_->RequestBuffer();
if (buffer == nullptr) {
goto end2;
}
width = screenshotSurface_->GetWidth();
height = screenshotSurface_->GetHeight();
if (width > layerData_->width || height > layerData_->height) {
goto end1;
}
if (!PixelFormatUtils::BppOfPixelFormat(static_cast<ImagePixelFormat>(screenshotSurface_->GetFormat()), bpp)) {
goto end1;
}
lineSize = width * bpp;
dstAddr = static_cast<uint8_t*>(buffer->GetVirAddr());
srcAddr = layerData_->virAddr;
if (dstAddr != nullptr && srcAddr != nullptr) {
for (uint32_t i = 0; i < height; i++) {
if (memcpy_s(dstAddr, lineSize, srcAddr, lineSize) != EOK) {
GRAPHIC_LOGE("memcpy_s error!");
}
dstAddr += lineSize;
srcAddr += layerData_->stride;
}
}
end1:
screenshotSurface_->FlushBuffer(buffer);
end2:
delete screenshotSurface_;
screenshotSurface_ = nullptr;
}
void LiteWM::OnClientDeathNotify(pid_t pid)
{
GRAPHIC_LOGI("OnClientDeathNotify");
GraphicLocker lock(stackLock_);
auto node = winList_.Begin();
while (node != winList_.End()) {
auto tmp = node;
node = node->next_;
LiteWindow* window = tmp->data_;
GRAPHIC_LOGI("window->GetPid() = %d,pid = %d", window->GetPid(), pid);
if (window->GetPid() == pid) {
winList_.Remove(tmp);
AddUpdateRegion(window->config_.rect);
delete window;
}
}
}
}
+154
View File
@@ -0,0 +1,154 @@
/*
* 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_LITE_WM_H
#define GRAPHIC_LITE_LITE_WM_H
#include <pthread.h>
#include "surface.h"
#include "geometry2d.h"
#include "graphic_locker.h"
#include "hals/hi_fbdev.h"
#include "input_manager_service.h"
#include "list.h"
#include "lite_win.h"
namespace OHOS {
constexpr uint8_t MAX_UPDATE_SIZE = 8;
struct UpdateRegions {
int num;
Rect updates[MAX_UPDATE_SIZE];
Rect bound;
};
struct CursorInfo {
Rect rect;
bool needRedraw;
bool enableCursor;
};
class LiteWM : public InputEventDistributer::RawEventListener {
public:
static LiteWM* GetInstance()
{
static LiteWM liteWm;
return &liteWm;
}
void MainTaskHandler();
void InitMouseCursor();
void UpdateMouseCursor();
void DrawMouseCursor();
bool CheckWinIdIsAvailable();
int32_t GetUniqueWinId();
void RecycleWinId(int32_t id);
void GetLayerInfo(LiteLayerInfo& layerInfo);
Surface* GetSurface(int32_t id);
void Show(int32_t id);
void Hide(int32_t id);
void RaiseToTop(int32_t id);
void LowerToBottom(int32_t id);
void MoveTo(int32_t id, int16_t x, int16_t y);
void Resize(int32_t id, int16_t width, int16_t height);
void UpdateWindow(int32_t id);
void UpdateWindowRegion(const LiteWindow* window, const Rect& rect);
void CalculateUpdateRegion(const ListNode<LiteWindow*>* winNode, int16_t x1, int16_t y1, int16_t x2, int16_t y2);
void ProcessUpdates();
void DrawRegion(const ListNode<LiteWindow *>* winNode, int16_t x1, int16_t y1, int16_t x2, int16_t y2);
void DrawBackground(int16_t x1, int16_t y1, int16_t x2, int16_t y2);
void AddUpdateRegion(const Rect& rect);
LiteWindow* CreateWindow(const LiteWinConfig& config, pid_t pid);
void RemoveWindow(int32_t id);
LiteWindow* GetWindowById(int32_t id);
ListNode<LiteWindow*>* GetWindowNodeById(int32_t id);
LiteWindow* FindTargetWindow(const RawEvent& event);
void OnRawEvent(const RawEvent& rawEvent) override;
void Screenshot();
bool OnScreenshot(Surface* surface);
void OnClientDeathNotify(pid_t pid);
Point GetMousePosition()
{
GraphicLocker lock(mouseLock_);
return mousePosition_;
}
void SetMousePosition(int16_t x, int16_t y)
{
x = (x < 0) ? 0 : (x > layerData_->width - 1) ? (layerData_->width - 1) : x;
y = (y < 0) ? 0 : (y > layerData_->height - 1) ? (layerData_->height - 1) : y;
GraphicLocker lock(mouseLock_);
mousePosition_.x = x;
mousePosition_.y = y;
}
void GetEventData(DeviceData* data)
{
GraphicLocker lock(eventLock_);
if (data != nullptr) {
*data = deviceData_;
}
}
void SetEventData(const LiteWindow* window, const RawEvent& event)
{
GraphicLocker lock(eventLock_);
deviceData_.point.x = event.x;
deviceData_.point.y = event.y;
deviceData_.state = event.state;
if (window != nullptr) {
deviceData_.winId = window->GetWindowId();
}
}
private:
LiteWM();
virtual ~LiteWM();
void InitMutex(pthread_mutex_t& mutex, int type);
List<LiteWindow*> winList_;
UpdateRegions updates_;
LiteSurfaceData* layerData_;
CursorInfo cursorInfo_;
Point mousePosition_;
pthread_mutex_t stackLock_;
pthread_mutex_t mouseLock_;
pthread_mutex_t eventLock_;
pthread_mutex_t screenshotMutex_;
DeviceData deviceData_;
bool needScreenshot_;
Surface* screenshotSurface_;
// Store window ID by bit
uint32_t winIdStorage;
};
}
#endif
+242
View File
@@ -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.
*/
#include "lite_wms.h"
#include "graphic_log.h"
#include "lite_wm.h"
#include "lite_wm_type.h"
#include "surface.h"
#include "surface_impl.h"
namespace OHOS {
void LiteWMS::WMSRequestHandle(int funcId, void* origin, IpcIo* req, IpcIo* reply)
{
switch (funcId) {
case LiteWMS_GetSurface:
OHOS::LiteWMS::GetInstance()->GetSurface(req, reply);
break;
case LiteWMS_Show:
LiteWMS::GetInstance()->Show(req, reply);
break;
case LiteWMS_Hide:
LiteWMS::GetInstance()->Hide(req, reply);
break;
case LiteWMS_RaiseToTop:
LiteWMS::GetInstance()->RaiseToTop(req, reply);
break;
case LiteWMS_LowerToBottom:
LiteWMS::GetInstance()->LowerToBottom(req, reply);
break;
case LiteWMS_MoveTo:
LiteWMS::GetInstance()->MoveTo(req, reply);
break;
case LiteWMS_Resize:
LiteWMS::GetInstance()->Resize(req, reply);
break;
case LiteWMS_Update:
LiteWMS::GetInstance()->Update(req, reply);
break;
case LiteWMS_CreateWindow:
LiteWMS::GetInstance()->CreateWindow(origin, req, reply);
break;
case LiteWMS_RemoveWindow:
LiteWMS::GetInstance()->RemoveWindow(req, reply);
break;
case LiteWMS_GetEventData:
LiteWMS::GetInstance()->GetEventData(req, reply);
break;
case LiteWMS_Screenshot:
LiteWMS::GetInstance()->Screenshot(req, reply);
break;
case LiteWMS_ClientRegister:
LiteWMS::GetInstance()->ClientRegister(origin, req, reply);
break;
case LiteWMS_GetLayerInfo:
LiteWMS::GetInstance()->GetLayerInfo(req, reply);
break;
default:
GRAPHIC_LOGW("code not support:%d!", funcId);
break;
}
}
int32_t LiteWMS::SurfaceRequestHandler(const IpcContext* context, void* ipcMsg, IpcIo* io, void* arg)
{
uint32_t code;
(void)GetCode(ipcMsg, &code);
LiteWindow* window = (LiteWindow*)arg;
if (code == 0) {
GRAPHIC_LOGI("requestBuffer");
window->UpdateBackBuf();
}
Surface* surface = window->GetSurface();
SurfaceImpl* liteSurface = reinterpret_cast<SurfaceImpl*>(surface);
liteSurface->DoIpcMsg(ipcMsg, io);
return 0;
}
void LiteWMS::GetSurface(IpcIo* req, IpcIo* reply)
{
int32_t id = IpcIoPopInt32(req);
GRAPHIC_LOGI("GetSurface,id=%d", id);
LiteWindow* window = LiteWM::GetInstance()->GetWindowById(id);
if (window == nullptr) {
GRAPHIC_LOGE("window not found, id = %d", id);
return;
}
SvcIdentity svc;
int32_t ret = RegisterIpcCallback(SurfaceRequestHandler, 0, IPC_WAIT_FOREVER, &svc, window);
IpcIoPushInt32(reply, ret);
if (ret != LITEIPC_OK) {
GRAPHIC_LOGE("RegisterIpcCallback failed.");
return;
}
window->SetSid(svc);
IpcIoPushSvc(reply, &svc);
}
void LiteWMS::Show(IpcIo* req, IpcIo* reply)
{
GRAPHIC_LOGI("Show");
int32_t id = IpcIoPopInt32(req);
LiteWM::GetInstance()->Show(id);
}
void LiteWMS::Hide(IpcIo* req, IpcIo* reply)
{
GRAPHIC_LOGI("Hide");
int32_t id = IpcIoPopInt32(req);
LiteWM::GetInstance()->Hide(id);
}
void LiteWMS::RaiseToTop(IpcIo* req, IpcIo* reply)
{
GRAPHIC_LOGI("RaiseToTop");
int32_t id = IpcIoPopInt32(req);
LiteWM::GetInstance()->RaiseToTop(id);
}
void LiteWMS::LowerToBottom(IpcIo* req, IpcIo* reply)
{
GRAPHIC_LOGI("LowerToBottom");
int32_t id = IpcIoPopInt32(req);
LiteWM::GetInstance()->LowerToBottom(id);
}
void LiteWMS::MoveTo(IpcIo* req, IpcIo* reply)
{
GRAPHIC_LOGI("MoveTo");
int32_t id = IpcIoPopInt32(req);
uint32_t x = IpcIoPopUint32(req);
uint32_t y = IpcIoPopUint32(req);
LiteWM::GetInstance()->MoveTo(id, x, y);
}
void LiteWMS::Resize(IpcIo* req, IpcIo* reply)
{
GRAPHIC_LOGI("Resize");
int32_t id = IpcIoPopInt32(req);
uint32_t width = IpcIoPopUint32(req);
uint32_t height = IpcIoPopUint32(req);
LiteWM::GetInstance()->Resize(id, width, height);
}
void LiteWMS::Update(IpcIo* req, IpcIo* reply)
{
GRAPHIC_LOGI("Update");
int32_t id = IpcIoPopInt32(req);
LiteWM::GetInstance()->UpdateWindow(id);
}
void LiteWMS::CreateWindow(const void* origin, IpcIo* req, IpcIo* reply)
{
GRAPHIC_LOGI("CreateWindow");
uint32_t size;
LiteWinConfig* config = static_cast<LiteWinConfig*>(IpcIoPopFlatObj(req, &size));
if (config != nullptr) {
pid_t pid = GetCallingPid(origin);
LiteWindow* window = LiteWM::GetInstance()->CreateWindow(*config, pid);
if (window != nullptr) {
IpcIoPushInt32(reply, window->GetWindowId());
return;
}
}
IpcIoPushInt32(reply, INVALID_WINDOW_ID);
}
void LiteWMS::RemoveWindow(IpcIo* req, IpcIo* reply)
{
GRAPHIC_LOGI("RemoveWindow");
int32_t id = IpcIoPopInt32(req);
LiteWM::GetInstance()->RemoveWindow(id);
}
void LiteWMS::GetEventData(IpcIo* req, IpcIo* reply)
{
DeviceData data;
LiteWM::GetInstance()->GetEventData(&data);
IpcIoPushFlatObj(reply, &data, sizeof(DeviceData));
}
void LiteWMS::Screenshot(IpcIo* req, IpcIo* reply)
{
Surface* surface = SurfaceImpl::GenericSurfaceByIpcIo(*req);
bool ret = LiteWM::GetInstance()->OnScreenshot(surface);
IpcIoPushInt32(reply, ret ? LiteWMS_EOK : LiteWMS_EUNKONW);
}
void LiteWMS::ClientRegister(const void* origin, IpcIo* req, IpcIo* reply)
{
pid_t pid = GetCallingPid(origin);
SvcIdentity* sid = IpcIoPopSvc(req);
if (sid == nullptr) {
return;
}
DeathCallbackArg* arg = new DeathCallbackArg;
arg->pid = pid;
arg->sid = *sid;
uint32_t cbId = -1;
#ifdef __LINUX__
BinderAcquire(sid->ipcContext, sid->handle);
free(sid);
sid = nullptr;
#endif
if (RegisterDeathCallback(NULL, arg->sid, DeathCallback, arg, &cbId) != LITEIPC_OK) {
GRAPHIC_LOGE("RegisterDeathCallback failed!");
}
}
int32_t LiteWMS::DeathCallback(const IpcContext* context, void* ipcMsg, IpcIo* data, void* arg)
{
if (arg != nullptr) {
DeathCallbackArg* cbArg = static_cast<DeathCallbackArg*>(arg);
LiteWM::GetInstance()->OnClientDeathNotify(cbArg->pid);
#ifdef __LINUX__
BinderRelease(cbArg->sid.ipcContext, cbArg->sid.handle);
#endif
delete cbArg;
}
return 0;
}
void LiteWMS::GetLayerInfo(IpcIo* req, IpcIo* reply)
{
LiteLayerInfo layerInfo = {};
LiteWM::GetInstance()->GetLayerInfo(layerInfo);
IpcIoPushFlatObj(reply, &layerInfo, sizeof(LiteLayerInfo));
}
} // namespace OHOS
+62
View File
@@ -0,0 +1,62 @@
/*
* 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_LITE_WMS_H
#define GRAPHIC_LITE_LITE_WMS_H
#include "geometry2d.h"
#include "lite_wm_type.h"
#include "liteipc_adapter.h"
#include "serializer.h"
namespace OHOS {
class LiteWMS {
public:
struct DeathCallbackArg {
pid_t pid;
SvcIdentity sid;
};
static LiteWMS* GetInstance()
{
static LiteWMS wms;
return &wms;
}
static void WMSRequestHandle(int funcId, void* origin, IpcIo* req, IpcIo* reply);
private:
LiteWMS(){};
~LiteWMS() {}
static int32_t SurfaceRequestHandler(const IpcContext* context, void* ipcMsg, IpcIo* io, void* arg);
static int32_t DeathCallback(const IpcContext* context, void* ipcMsg, IpcIo* data, void* arg);
void GetSurface(IpcIo* req, IpcIo* reply);
void Show(IpcIo* req, IpcIo* reply);
void Hide(IpcIo* req, IpcIo* reply);
void RaiseToTop(IpcIo* req, IpcIo* reply);
void LowerToBottom(IpcIo* req, IpcIo* reply);
void MoveTo(IpcIo* req, IpcIo* reply);
void Resize(IpcIo* req, IpcIo* reply);
void Update(IpcIo* req, IpcIo* reply);
void CreateWindow(const void* origin, IpcIo* req, IpcIo* reply);
void RemoveWindow(IpcIo* req, IpcIo* reply);
void GetEventData(IpcIo* req, IpcIo* reply);
void Screenshot(IpcIo* req, IpcIo* reply);
void ClientRegister(const void* origin, IpcIo* req, IpcIo* reply);
void GetLayerInfo(IpcIo* req, IpcIo* reply);
};
} // namespace OHOS
#endif
+92
View File
@@ -0,0 +1,92 @@
/*
* 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 <ohos_errno.h>
#include <ohos_init.h>
#include "feature.h"
#include "graphic_log.h"
#include "iproxy_client.h"
#include "iproxy_server.h"
#include "iunknown.h"
#include "samgr_lite.h"
#include "service.h"
#include "lite_wms.h"
namespace OHOS {
struct DefaultFeatureApi {
INHERIT_SERVER_IPROXY;
};
struct WMSService {
INHERIT_SERVICE;
INHERIT_IUNKNOWNENTRY(DefaultFeatureApi);
Identity identity;
};
static const char* GetName(Service* service)
{
(void)service;
return SERVICE_NAME;
}
static BOOL Initialize(Service* service, Identity identity)
{
WMSService* example = reinterpret_cast<WMSService*>(service);
example->identity = identity;
GRAPHIC_LOGI("Initialize(%s)! Identity<%d, %d, %p>", SERVICE_NAME,
identity.serviceId, identity.featureId, identity.queueId);
return TRUE;
}
static BOOL MessageHandle(Service* service, Request* msg)
{
GRAPHIC_LOGI("MessageHandle(%s)! Request<%d, %d, %p>",
service->GetName(service), msg->msgId, msg->msgValue, msg->data);
return FALSE;
}
static TaskConfig GetTaskConfig(Service* service)
{
(void)service;
TaskConfig config = {LEVEL_HIGH, PRI_BELOW_NORMAL, 0x800, 20, SHARED_TASK};
return config;
}
static int32 Invoke(IServerProxy* iProxy, int funcId, void* origin, IpcIo* req, IpcIo* reply)
{
LiteWMS::WMSRequestHandle(funcId, origin, req, reply);
return EC_SUCCESS;
}
static WMSService g_example = {
.GetName = GetName,
.Initialize = Initialize,
.MessageHandle = MessageHandle,
.GetTaskConfig = GetTaskConfig,
SERVER_IPROXY_IMPL_BEGIN,
.Invoke = Invoke,
IPROXY_END,
};
static void Init(void)
{
SAMGR_GetInstance()->RegisterService((Service*)&g_example);
SAMGR_GetInstance()->RegisterDefaultFeatureApi(SERVICE_NAME, GET_IUNKNOWN(g_example));
}
SYSEX_SERVICE_INIT(Init);
} // namespace OHOS
+47
View File
@@ -0,0 +1,47 @@
/*
* 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"
#include "graphic_performance.h"
#include "hals/hi_fbdev.h"
#include "input_manager_service.h"
#include "samgr_lite.h"
#include "lite_wm.h"
extern "C" void __attribute__((weak)) HOS_SystemInit(void)
{
SAMGR_Bootstrap();
}
namespace {
constexpr uint16_t US_PER_MILLISECOND = 1000;
constexpr uint16_t WMS_MAIN_TASK_PERIOD_IN_US = OHOS::WMS_MAIN_TASK_PERIOD * US_PER_MILLISECOND;
}
int main()
{
DEBUG_PERFORMANCE_REGISTER_SIG();
OHOS::HiFbdevInit();
OHOS::GfxEngines::GetInstance()->InitDriver();
HOS_SystemInit();
OHOS::InputManagerService::GetInstance()->Run();
while (1) {
DEBUG_PERFORMANCE_PRINT_RESULT();
OHOS::LiteWM::GetInstance()->MainTaskHandler();
usleep(WMS_MAIN_TASK_PERIOD_IN_US);
}
}
Executable
+61
View File
@@ -0,0 +1,61 @@
# 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")
group("lite_wms_test") {
if (ohos_build_type == "debug") {
deps = [
":sample_ui",
":sample_window",
]
}
}
if (ohos_build_type == "debug") {
executable("sample_ui") {
sources = [ "sample_ui.cpp" ]
include_dirs = [
"//foundation/graphic/ui/frameworks",
"//third_party/freetype/include",
]
ldflags = [
"-lstdc++",
"-lpthread",
"-Wl,-rpath-link=$ohos_root_path/$root_out_dir",
]
deps = [
"//foundation/graphic/ui/test/framework:lite_graphic_test_framework",
"//foundation/graphic/utils:lite_graphic_hals",
"//foundation/graphic/wms:wms_client",
]
output_dir = "$root_out_dir/dev_tools"
}
executable("sample_window") {
sources = [ "sample_window.cpp" ]
include_dirs = [
"//foundation/graphic/ui/frameworks",
"//foundation/graphic/surface/interfaces/kits",
"//third_party/freetype/include",
]
ldflags = [
"-lstdc++",
"-lpthread",
"-Wl,-rpath-link=$ohos_root_path/$root_out_dir",
]
deps = [ "//foundation/graphic/ui:lite_ui" ]
output_dir = "$root_out_dir/dev_tools"
}
}
+74
View File
@@ -0,0 +1,74 @@
/*
* 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 <unistd.h>
#include "font/ui_font_vector.h"
#include "common/graphic_startup.h"
#include "common/screen.h"
#include "common/task_manager.h"
#include "dock/screen_device_proxy.h"
#include "graphic_config.h"
#include "graphic_log.h"
#include "window/window.h"
extern void RunApp();
namespace OHOS {
uint32_t g_animaterBuffer[HORIZONTAL_RESOLUTION * VERTICAL_RESOLUTION];
void TestAPP()
{
WindowConfig config = {};
config.rect.SetRect(0, 0, Screen::GetInstance().GetWidth() - 1, Screen::GetInstance().GetHeight() - 1);
Window* window = Window::CreateWindow(config);
if (window == nullptr) {
GRAPHIC_LOGE("Create window false!");
return;
}
window->BindRootView(RootView::GetInstance());
RunApp();
window->Show();
}
static void InitHal()
{
ScreenDevice* display = new ScreenDevice();
ScreenDeviceProxy::GetInstance()->SetDevice(display);
ScreenDeviceProxy::GetInstance()->SetScreenSize(HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION);
ScreenDeviceProxy::GetInstance()->SetAnimatorbuffer(reinterpret_cast<uint8_t*>(g_animaterBuffer), ARGB8888,
HORIZONTAL_RESOLUTION);
}
static uint32_t g_fontPsramBaseAddr[MIN_FONT_PSRAM_LENGTH / 4];
static void InitFontEngine()
{
GraphicStartUp::InitFontEngine(reinterpret_cast<uintptr_t>(g_fontPsramBaseAddr), MIN_FONT_PSRAM_LENGTH,
VECTOR_FONT_DIR, DEFAULT_VECTOR_FONT_FILENAME);
}
} // namespace OHOS
int main(int argc, char* argv[])
{
OHOS::GraphicStartUp::Init();
OHOS::InitHal();
OHOS::InitFontEngine();
OHOS::TestAPP();
while (1) {
/* Periodically call TaskHandler(). It could be done in a timer interrupt or an OS task too. */
OHOS::TaskManager::GetInstance()->TaskHandler();
usleep(1000 * 10); /* 1000 * 10: Just to let the system breathe */
}
return 0;
}
+281
View File
@@ -0,0 +1,281 @@
/*
* 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 "animator/animator.h"
#include "common/graphic_startup.h"
#include "common/task_manager.h"
#include "components/root_view.h"
#include "components/ui_button.h"
#include "components/ui_image_view.h"
#include "components/ui_label.h"
#include "dock/screen_device_proxy.h"
#include "font/ui_font.h"
#include "font/ui_font_vector.h"
#include "graphic_config.h"
#include "graphic_log.h"
#include "window/window.h"
#include <unistd.h>
namespace OHOS {
namespace {
const uint16_t MAX_LIST_NUM = 40;
}
static RootView* g_rootView1 = nullptr;
static RootView* g_rootView2 = nullptr;
static RootView* g_rootView3 = nullptr;
static bool g_flag = true;
void CreateDefaultWindow(RootView* rootView, int x, int y)
{
if (rootView != nullptr) {
WindowConfig config = {};
config.rect = rootView->GetRect();
config.rect.SetPosition(x, y);
Window* window = Window::CreateWindow(config);
if (window != nullptr) {
window->BindRootView(rootView);
window->Show();
} else {
GRAPHIC_LOGE("Create window false!");
}
}
}
class ImageAnimatorCallbackDemo : public AnimatorCallback {
public:
ImageAnimatorCallbackDemo() : times_(0) {}
virtual ~ImageAnimatorCallbackDemo() {}
enum {
CONDITION0,
CONDITION1,
CONDITION2,
CONDITION3,
CONDITION4,
CONDITION5,
CONDITION_COUNT,
};
virtual void Callback(UIView* view)
{
static int i = 0;
if ((times_++ % 90) != 0) { // 90: animator callback is performed every 90 ticks
return;
}
switch ((++i) % CONDITION_COUNT) {
case CONDITION0: {
if (g_flag) {
g_rootView3->GetBoundWindow()->LowerToBottom();
} else {
g_rootView3->GetBoundWindow()->RaiseToTop();
}
g_flag = !g_flag;
break;
}
case CONDITION1: {
if (g_flag) {
g_rootView1->Resize(403, 201); // 403: width, 201: height
g_rootView1->GetBoundWindow()->Resize(403, 201); // 403: width, 201: height
} else {
g_rootView1->Resize(600, 300); // 600: width, 300: height
g_rootView1->GetBoundWindow()->Resize(600, 300); // 600: width, 300: height
}
break;
}
case CONDITION2: {
Window* window = g_rootView3->GetBoundWindow();
int x = (window->GetRect().GetX() + 40) % 400; // 40: x offset, 400: maximum value of x
window->MoveTo(x, window->GetRect().GetY());
break;
}
case CONDITION3: {
Window* window = g_rootView2->GetBoundWindow();
if (window != nullptr) {
Window::DestoryWindow(window);
} else {
g_rootView2->Invalidate();
CreateDefaultWindow(g_rootView2, 70, 75); // 70: x, 75: y
}
break;
}
case CONDITION4: {
g_rootView3->GetBoundWindow()->Hide();
break;
}
case CONDITION5: {
g_rootView3->GetBoundWindow()->Show();
}
default:
break;
}
}
protected:
int16_t times_;
};
void AddButton()
{
UIButton* button = new UIButton();
button->SetPosition(40, 40); // 40: x, 40: y
button->SetWidth(40); // 40: width
button->SetHeight(40); // 40: height
button->SetStyle(STYLE_BACKGROUND_COLOR, Color::Gray().full);
UIButton* button1 = new UIButton();
button1->SetPosition(30, 10); // 30: x, 10: y
button1->SetWidth(60); // 60: width
button1->SetHeight(60); // 60: height
button1->SetStyle(STYLE_BACKGROUND_COLOR, Color::Green().full);
button1->SetStyle(STYLE_BACKGROUND_OPA, 200); // 200: background opacity
button1->SetStyle(STYLE_BORDER_RADIUS, 3); // 3: border radius
g_rootView1->Add(button1);
g_rootView2->Add(button);
}
void AddBlock()
{
UIViewGroup* block = new UIViewGroup();
block->SetPosition(100, 40); // 100: x, 40: y
block->SetWidth(60); // 60: width
block->SetHeight(60); // 60: height
block->SetStyle(STYLE_BACKGROUND_COLOR, Color::Gray().full);
block->SetStyle(STYLE_BACKGROUND_OPA, 200); // 200: background opacity
UIViewGroup* block2 = new UIViewGroup();
block2->SetPosition(40, 40); // 40: x, 40: y
block2->SetWidth(60); // 60: width
block2->SetHeight(60); // 60: height
block2->SetStyle(STYLE_BACKGROUND_COLOR, Color::Yellow().full);
block2->SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE);
UIViewGroup* block3 = new UIViewGroup();
block3->SetPosition(100, 40); // 100: x, 40: y
block3->SetWidth(60); // 60: width
block3->SetHeight(60); // 60: height
block3->SetStyle(STYLE_BACKGROUND_COLOR, Color::Yellow().full);
block3->SetStyle(STYLE_BACKGROUND_OPA, 200); // 200: background opacity
UIViewGroup* block4 = new UIViewGroup();
block4->SetPosition(1, 1);
block4->SetWidth(10); // 10: width
block4->SetHeight(10); // 10: height
block4->SetStyle(STYLE_BACKGROUND_COLOR, Color::Red().full);
block4->SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE);
g_rootView1->Add(block4);
g_rootView2->Add(block);
g_rootView3->Add(block2);
g_rootView3->Add(block3);
}
void TestWindow()
{
g_rootView1 = RootView::GetWindowRootView();
g_rootView1->SetWidth(600); // 600: width
g_rootView1->SetHeight(300); // 300: height
g_rootView1->SetPosition(0, 0);
g_rootView1->SetStyle(STYLE_BACKGROUND_COLOR, Color::Olive().full);
g_rootView2 = RootView::GetWindowRootView();
g_rootView2->SetPosition(0, 0, 200, 200); // 200: width, 200: height
g_rootView2->SetStyle(STYLE_BACKGROUND_COLOR, Color::Yellow().full);
g_rootView3 = RootView::GetWindowRootView();
g_rootView3->SetPosition(0, 0, 200, 200); // 200: width, 200: height
g_rootView3->SetStyle(STYLE_BACKGROUND_COLOR, Color::Red().full);
g_rootView3->SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE);
UILabel* label = new UILabel();
label->SetPosition(100, 0, 100, 100); // 100: x, 100: width, 100: height
label->SetFont("HYQiHei-65S.otf", 14); // 14: font size
label->SetText("轻量鸿蒙GUI");
label->SetStyle(STYLE_TEXT_COLOR, Color::Black().full);
label->SetStyle(STYLE_BACKGROUND_COLOR, Color::Yellow().full);
label->SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE);
UIImageView* image = new UIImageView;
image->SetPosition(220, 0, 80, 80); // 220: x, 80: width, 80: height
image->SetSrc("/user/data/A021_028.bin");
AddButton();
g_rootView1->Add(label);
g_rootView1->Add(image);
AddBlock();
g_rootView1->Invalidate();
g_rootView2->Invalidate();
g_rootView3->Invalidate();
auto imageAnimCallback = new ImageAnimatorCallbackDemo();
Animator* imageAnimator = new Animator(imageAnimCallback, g_rootView1, 0, true);
AnimatorManager::GetInstance()->Add(imageAnimator);
imageAnimator->Start();
CreateDefaultWindow(g_rootView1, 0, 50); // 50: y
CreateDefaultWindow(g_rootView2, 70, 75); // 70: x, 75: y
CreateDefaultWindow(g_rootView3, 120, 200); // 120: x, 200: y
}
RootView* g_rootViewList[MAX_LIST_NUM];
void TestWindowNumLimit()
{
for (int i = 0; i < MAX_LIST_NUM; i++) {
GRAPHIC_LOGI("CreateDefaultWindow, i = %d", i);
if (i == 10) { // 10, 9: Delete the tenth window in the 11th loop.
Window* window = g_rootViewList[9]->GetBoundWindow();
Window::DestoryWindow(window);
} else if (i == 15) { // 15, 5: Delete the sixth window in the 16th loop.
Window* window = g_rootViewList[5]->GetBoundWindow();
Window::DestoryWindow(window);
}
RootView* rootView = RootView::GetWindowRootView();
g_rootViewList[i] = rootView;
rootView->SetWidth(10); // 10: width
rootView->SetHeight(10); // 10: height
rootView->SetPosition(0, 0);
rootView->SetStyle(STYLE_BACKGROUND_COLOR, Color::Olive().full);
rootView->Invalidate();
CreateDefaultWindow(rootView, 20 * i, 0); // 20: offset
}
}
static void InitHal()
{
ScreenDevice* display = new ScreenDevice();
ScreenDeviceProxy::GetInstance()->SetDevice(display);
}
static uint32_t g_fontPsramBaseAddr[MIN_FONT_PSRAM_LENGTH / 4];
static void InitFontEngine()
{
GraphicStartUp::InitFontEngine(reinterpret_cast<uintptr_t>(g_fontPsramBaseAddr), MIN_FONT_PSRAM_LENGTH,
VECTOR_FONT_DIR, DEFAULT_VECTOR_FONT_FILENAME);
}
} // namespace OHOS
int main(int argc, char* argv[])
{
OHOS::GraphicStartUp::Init();
OHOS::InitHal();
OHOS::InitFontEngine();
OHOS::TestWindow();
while (1) {
/* Periodically call TaskHandler(). It could be done in a timer interrupt or an OS task too. */
OHOS::TaskManager::GetInstance()->TaskHandler();
usleep(1000 * 10); /* 1000 * 10: Just to let the system breathe */
}
return 0;
}