diff --git a/README.md b/README.md index 098e283c85d26c345b28f5cad4c9131158304209..cf45c0175573d1c0132b16168f02decb9b5d6f6c 100644 --- a/README.md +++ b/README.md @@ -1,39 +1,715 @@ -# windowmanager +# Graphics -#### 介绍 -{**以下是 Gitee 平台说明,您可以替换此简介** -Gitee 是 OSCHINA 推出的基于 Git 的代码托管平台(同时支持 SVN)。专为开发者提供稳定、高效、安全的云端软件开发协作平台 -无论是个人、团队、或是企业,都能够用 Gitee 实现代码托管、项目管理、协作开发。企业项目请看 [https://gitee.com/enterprises](https://gitee.com/enterprises)} +- [Introduction](#section1333751883213) +- [Directory Structure](#section1882912343) +- [Constraints](#section68982123611) +- [Compilation and Building](#section671864110372) +- [Available APIs](#section197399520386) + - [WindowManager](#section5851104093816) + - [Window](#section3483122273912) + - [SubWindow](#section96481249183913) + - [Surface](#section12366161544010) + - [SurfaceBuffer](#section12001640184711) + - [VsyncHelper](#section1392116294211) -#### 软件架构 -软件架构说明 +- [Usage](#section18359134910422) + - [Transferring a Producer Surface](#section193464304411) + - [Creating a Producer Surface](#section1276823075112) + - [Producing a SurfaceBuffer](#section614545716513) + - [Consuming a SurfaceBuffer](#section315285412535) + - [Adding Custom Data to a SurfaceBuffer](#section612412125616) + - [Registering a Vsync Callback Listener](#section1148115214576) +- [\#EN-US\_TOPIC\_0000001105482134/section1939493174420](#section1939493174420) +- [Repositories Involved](#section6488145313) -#### 安装教程 +## Introduction -1. xxxx -2. xxxx -3. xxxx +The Graphics subsystem provides graphics and window management capabilities, which can be invoked by using Java or JS APIs. It can be used for UI development for all standard-system devices. -#### 使用说明 +The following figure shows the architecture of the Graphics subsystem. -1. xxxx -2. xxxx -3. xxxx +![](figures/graphic.png) -#### 参与贡献 +- Surface -1. Fork 本仓库 -2. 新建 Feat_xxx 分支 -3. 提交代码 -4. 新建 Pull Request + Provides APIs for managing the graphics buffer and the efficient and convenient rotation buffer. +- Vsync -#### 特技 + Provides APIs for managing registration and response of all vertical sync signals. + +- WindowManager + + Provides APIs for creating and managing windows. + +- WaylandProtocols + + Provides the communication protocols between the window manager and synthesizer. + +- Compositor + + Implements synthesis of layers. + +- Renderer + + Functions as the back-end rendering module of the synthesizer. + +- Wayland protocols + + Provides Wayland inter-process communication protocols. + +- Shell + + Provides multi-window capabilities. + +- Input Manger + + Functions as the multimodal input module that receives input events. + + +## Directory Structure + +``` +foundation/graphic/standard/ +├── frameworks # Framework code +│ ├── bootanimation # Boot Animation code +│ ├── surface # Surface code +│ ├── vsync # Vsync code +│ └── wm # WindowManager code +├── interfaces # External APIs +│ ├── innerkits # Native APIs +│ └── kits # JS APIs and NAPIs +└── utils # Utilities +``` + +## Constraints + +- Language version: C++ 11 or later + +## Compilation and Building + +The dependent APIs include the following: + +- graphic\_standard:libwms\_client +- graphic\_standard:libsurface +- graphic\_standard:libvsync\_client + +## Available APIs + +### WindowManager + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

API

+

Description

+

GetInstance

+

Obtains the pointer to a singleton WindowManager instance.

+

GetMaxWidth

+

Obtains the width of the screen.

+

GetMaxHeight

+

Obtains the height of the screen.

+

CreateWindow

+

Creates a standard window.

+

CreateSubWindow

+

Creates a child window.

+

StartShotScreen

+

Takes a screenshot.

+

StartShotWindow

+

Captures a window.

+

SwitchTop

+

Moves the specified window to the top.

+
+ +### Window + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

API

+

Description

+

Show

+

Displays the current window.

+

Hide

+

Hides the current window.

+

Move

+

Moves the current window to a specified position.

+

SwitchTop

+

Moves the current window to the top.

+

ChangeWindowType

+

Changes the type of the current window.

+

ReSize

+

Resizes the current window.

+

Rotate

+

Rotates the current window.

+

RegistPointerButtonCb

+

Registers the callback for Button events of the mouse.

+

RegistPointerEnterCb

+

Registers the callback for Enter events of the mouse.

+

RegistPointerLeaveCb

+

Registers the callback for Leave events of the mouse.

+

RegistPointerMotionCb

+

Registers the callback for Motion events of the mouse.

+

RegistPointerAxisDiscreteCb

+

Registers the callback for AxisDiscrete events of the mouse.

+

RegistPointerAxisSourceCb

+

Registers the callback for AxisSource events of the mouse.

+

RegistPointerAxisStopCb

+

Registers the callback for AxisStop events of the mouse.

+

RegistPointerAxisCb

+

Registers the callback for Axis events of the mouse.

+

RegistTouchUpCb

+

Registers the callback for TouchUp events.

+

RegistTouchDownCb

+

Registers the callback for TouchDown events.

+

RegistTouchEmotionCb

+

Registers the callback for TouchEmotion events.

+

RegistTouchFrameCb

+

Registers the callback for TouchFrame events.

+

RegistTouchCancelCb

+

Registers the callback for TouchCancel events.

+

RegistTouchShapeCb

+

Registers the callback for TouchShape events.

+

RegistTouchOrientationCb

+

Registers the callback for TouchOrientation events.

+

RegistKeyboardKeyCb

+

Registers the callback for Key events of the keyboard.

+

RegistKeyboardKeyMapCb

+

Registers the callback for KeyMap events of the keyboard.

+

RegistKeyboardLeaveCb

+

Registers the callback for Leave events of the keyboard.

+

RegistKeyboardEnterCb

+

Registers the callback for Enter events of the keyboard.

+

RegistKeyboardRepeatInfoCb

+

Registers the callback for RepeatInfo events of the keyboard.

+
+ +### SubWindow + + + + + + + + + + + + + +

API

+

Description

+

Move

+

Moves the current child window.

+

SetSubWindowSize

+

Sets the size of the current child window.

+
+ +### Surface + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

API

+

Description

+

CreateSurfaceAsConsumer

+

Creates a surface for the buffer consumer.

+

CreateSurfaceAsProducer

+

Creates a surface for the buffer producer. Only production-related APIs can be used.

+

GetProducer

+

Obtains an internal IBufferProducer object of Surface.

+

RequestBuffer

+

Requests a SurfaceBuffer object to be produced.

+

CancelBuffer

+

Cancels a SurfaceBuffer object to be produced.

+

FlushBuffer

+

Flushes a produced SurfaceBuffer object with certain information.

+

AcquireBuffer

+

Requests a SurfaceBuffer object to be consumed.

+

ReleaseBuffer

+

Returns a consumed SurfaceBuffer object.

+

GetQueueSize

+

Obtains the number of concurrent buffers.

+

SetQueueSize

+

Sets the number of concurrent buffers.

+

SetDefaultWidthAndHeight

+

Sets the default width and height.

+

GetDefaultWidth

+

Obtains the default width.

+

GetDefaultHeight

+

Obtains the default height.

+

SetUserData

+

Stores string data, which will not be transferred through IPC.

+

GetUserData

+

Obtains string data.

+

RegisterConsumerListener

+

Registers a consumer listener to listen for buffer flush events.

+

UnregisterConsumerListener

+

Unregiseters a consumer listener.

+
+ +### SurfaceBuffer + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

API

+

Description

+

GetBufferHandle

+

Obtains the BufferHandle pointer to the SurfaceBuffer object.

+

GetWidth

+

Obtains the width of the SurfaceBuffer object.

+

GetHeight

+

Obtains the height of the SurfaceBuffer object.

+

GetFormat

+

Obtains the color format of the SurfaceBuffer object.

+

GetUsage

+

Obtains the usage of the SurfaceBuffer object.

+

GetPhyAddr

+

Obtains the physical address of the SurfaceBuffer object.

+

GetKey

+

Obtains the key of the SurfaceBuffer object.

+

GetVirAddr

+

Obtains the virtual address of the SurfaceBuffer object.

+

GetSize

+

Obtains the size of the SurfaceBuffer object.

+

SetInt32

+

Sets the 32-bit integer for the SurfaceBuffer object.

+

GetInt32

+

Obtains the 32-bit integer for the SurfaceBuffer object.

+

SetInt64

+

Sets the 64-bit integer for the SurfaceBuffer object.

+

GetInt64

+

Obtains the 64-bit integer for the SurfaceBuffer object.

+
+ +### VsyncHelper + + + + + + + + + + + + + + + + +

API

+

Description

+

Current

+

Obtains the VsyncHelper object of the current runner.

+

VsyncHelper

+

Constructs a VsyncHelper object using an EventHandler object.

+

RequestFrameCallback

+

Registers a frame callback.

+
+ +## Usage + +### Transferring a Producer Surface + +1. Named service + - Service registration: + + ``` + // Obtain a consumer surface. + sptr surface = Surface::CreateSurfaceAsConsumer(); + // Extract the producer object. + sptr producer = surface->GetProducer(); + // Register the service. + auto sm = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + sm->AddSystemAbility(IPC_SA_ID, producer->AsObject()); + ``` + + - Construction of a producer surface: + + ``` + // Obtain a producer object. + auto sm = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + sptr robj = sm->GetSystemAbility(IPC_SA_ID); + // Construct a surface. + sptr bp = iface_cast(robj); + sptr surface = Surface::CreateSurfaceAsProducer(bp); + ``` + + +2. Anonymous service + - Sending of a surface: + + ``` + // Obtain a consumer surface. + sptr surface = CreateSurfaceAsConsumer(); + // Extract the producer object. + sptr producer = surface->GetProducer(); + // Return the producer object to the client. + parcel.WriteRemoteObject(producer); + ``` + + + +### Creating a Producer Surface + +``` +// Obtain a producer object. +sptr remoteObject = parcel.ReadRemoteObject(); +// Construct a surface. +sptr bp = iface_cast(robj); +sptr surface = Surface::CreateSurfaceAsProducer(bp); +``` + +### Producing a SurfaceBuffer + +``` +// Prerequisite: a producer surface +BufferRequestConfig requestConfig = { + .width = 1920, // Screen width + .height = 1080, // Screen height + .strideAlignment = 8, // Stride alignment byte + .format = PIXEL_FMT_RGBA_8888, // Color format + .usage = HBM_USE_CPU_READ | HBM_USE_CPU_WRITE | HBM_USE_MEM_DMA, // Usage + .timeout = 0, // Delay +}; + +sptr buffer; +int32_t releaseFence; + +SurfaceError ret = surface->RequestBuffer(buffer, releaseFence, requestConfig); +if (ret != SURFACE_ERROR_OK) { + // failed +} + +BufferFlushConfig flushConfig = { + .damage = { // Redrawing buffer zone + .x = 0, // Horizontal coordinate of the start point + .y = 0, // Vertical coordinate of the start point + .w = buffer->GetWidth(), // Width of the buffer zone + .h = buffer->GetHeight(), // Height of the buffer zone + }, + .timestamp = 0 // Time displayed to consumers. Value 0 indicates the current time. +}; + +ret = surface->FlushBuffer(buffer, -1, flushConfig); +if (ret != SURFACE_ERROR_OK) { + // failed +} +``` + +### Consuming a SurfaceBuffer + +``` +// Prerequisite: a consumer surface +class TestConsumerListener : public IBufferConsumerListener { +public: + void OnBufferAvailable() override { + sptr buffer; + int32_t flushFence; + SurfaceError ret = surface->AcquireBuffer(buffer, flushFence, timestamp, damage); + if (ret != SURFACE_ERROR_OK) { + // failed + } + // ... + ret = surface->ReleaseBuffer(buffer, -1); + if (ret != SURFACE_ERROR_OK) { + // failed + } + } +}; + +sptr listener = new TestConsumerListener(); +SurfaceError ret = surface->RegisterConsumerListener(listener); +if (ret != SURFACE_ERROR_OK) { + // failed +} +``` + +### Adding Custom Data to a SurfaceBuffer + +``` +sptr buffer; +SurfaceError ret = buffer->SetInt32(1, 3); +if (ret != SURFACE_ERROR_OK) { +// failed +} + +int32_t val; +ret = buffer->GetInt32(1, val); +if (ret != SURFACE_ERROR_OK) { +// failed +} +``` + +### Registering a Vsync Callback Listener + +1. Construct a **VsyncHelper** object using **handler**. + + ``` + auto runner = AppExecFwk::EventRunner::Create(true); + auto handler = std::make_shared(runner); + auto helper = new VsyncHelper(handler); + runner->Run(); + + struct FrameCallback cb = { + .timestamp_ = 0, + .userdata_ = nullptr, + .callback_ = [](int64_t timestamp, void* userdata) { + }, + }; + + VsyncError ret = helper->RequestFrameCallback(cb); + if (ret != VSYNC_ERROR_OK) { + // failed + } + ``` + +2. Use **Current** in **handler**. + + ``` + auto runner = AppExecFwk::EventRunner::Create(true); + auto handler = std::make_shared(runner); + handler->PostTask([]() { + auto helper = VsyncHelper::Current(); + struct FrameCallback cb = { + .timestamp_ = 0, + .userdata_ = nullptr, + .callback_ = [](int64_t timestamp, void* userdata) { + }, + }; + VsyncError ret = helper->RequestFrameCallback(cb); + if (ret != VSYNC_ERROR_OK) { + // failed + } + }); + + runner->Run(); + ``` + + +## Repositories Involved + +Graphics subsystem + +**graphic\_standard** + +ace\_ace\_engine + +aafwk\_L2 + +multimedia\_media\_standard + +multimedia\_camera\_standard -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/) diff --git a/README_zh.md b/README_zh.md new file mode 100644 index 0000000000000000000000000000000000000000..3ffb0ca2f2ed320ac554c037cb7e9c3de93d13e6 --- /dev/null +++ b/README_zh.md @@ -0,0 +1,361 @@ +# graphic_standard + +- [简介](#简介) +- [目录](#目录) +- [约束](#约束) +- [编译构建](#编译构建) +- [接口说明](#接口说明) +- [使用说明](#使用说明) +- [相关仓](#相关仓) + +## 简介 + +**Graphic子系统** 提供了图形接口能力和窗口管理接口能力, + +其主要的结构如下图所示: + +![Graphic子系统架构图](./figures/graphic.png) + +- **Surface** + + 图形缓冲区管理接口,负责管理图形缓冲区和高效便捷的轮转缓冲区。 + +- **Vsync** + + 垂直同步信号管理接口,负责管理所有垂直同步信号注册和响应。 + +- **WindowManager** + + 窗口管理器接口,负责创建和管理窗口。 + +- **WaylandProtocols** + + 窗口管理器和合成器的通信协议。 + +- **Compositor** + + 合成器,负责合成各个图层。 + +- **Renderer** + + 合成器的后端渲染模块。 + +- **Wayland protocols** + + Wayland 进程间通信协议 + +- **Shell** + + 提供多窗口能力 + +- **Input Manger** + + 多模输入模块,负责接收事件输入 + + +## 目录 +``` +foundation/graphic/standard/ +├── frameworks # 框架代码目录 +│ ├── bootanimation # 开机动画目录 +│   ├── surface # Surface代码 +│   ├── vsync # Vsync代码 +│   └── wm # WindowManager代码 +├── interfaces # 对外接口存放目录 +│   ├── innerkits # native接口存放目录 +│   └── kits # js/napi接口存放目录 +└── utils # 小部件存放目录 +``` + +## 约束 +- 语言版本 + - C++11或以上 + +## 编译构建 +可以依赖的接口有: +- graphic_standard:libwms_client +- graphic_standard:libsurface +- graphic_standard:libvsync_client + +## 接口说明 + +### WindowManager + +| 接口名 | 职责 | +|-----------------|-----------------------------| +| GetInstance | 获取WindowManager的单例指针 | +| GetMaxWidth | 获取当前屏幕宽度 | +| GetMaxHeight | 获取当前屏幕高度 | +| CreateWindow | 创建一个标准窗口 | +| CreateSubWindow | 创建一个子窗口 | +| StartShotScreen | 截屏操作 | +| StartShotWindow | 截取窗口操作 | +| SwitchTop | 将指定窗口调整至最上层显示 | + +### Window +| 接口名 | 职责 | +|-----------------------------|------------------------------| +| Show | 显示当前窗口 | +| Hide | 隐藏当前窗口 | +| Move | 移动当前窗口至指定位置 | +| SwitchTop | 将当前窗口调整到最上层显示 | +| ChangeWindowType | 更改当前窗口类型 | +| ReSize | 调整当前窗口至指定大小 | +| Rotate | 旋转当前窗口 | +| RegistPointerButtonCb | 注册鼠标Button事件回调 | +| RegistPointerEnterCb | 注册鼠标Enter事件回调 | +| RegistPointerLeaveCb | 注册鼠标Leave事件回调 | +| RegistPointerMotionCb | 注册鼠标Motion事件回调 | +| RegistPointerAxisDiscreteCb | 注册鼠标AxisDiscrete事件回调 | +| RegistPointerAxisSourceCb | 注册鼠标AxisSource事件回调 | +| RegistPointerAxisStopCb | 注册鼠标AxisStop事件回调 | +| RegistPointerAxisCb | 注册鼠标Axis事件回调 | +| RegistTouchUpCb | 注册TouchUp事件回调 | +| RegistTouchDownCb | 注册TouchDown事件回调 | +| RegistTouchEmotionCb | 注册TouchEmotion事件回调 | +| RegistTouchFrameCb | 注册TouchFrame事件回调 | +| RegistTouchCancelCb | 注册TouchCancel事件回调 | +| RegistTouchShapeCb | 注册TouchShape事件回调 | +| RegistTouchOrientationCb | 注册TouchOrientation事件回调 | +| RegistKeyboardKeyCb | 注册键盘Key事件回调 | +| RegistKeyboardKeyMapCb | 注册键盘KeyMap事件回调 | +| RegistKeyboardLeaveCb | 注册键盘Leave事件回调 | +| RegistKeyboardEnterCb | 注册键盘Enter事件回调 | +| RegistKeyboardRepeatInfoCb | 注册键盘RepeatInfo事件回调 | + +### SubWindow +| 接口名 | 职责 | +|------------------|--------------------| +| Move | 移动当前子窗口 | +| SetSubWindowSize | 调整当前子窗口位置 | + +### Surface +| 接口名 | 职责 | +|----------------------------|-------------------------------------------------------------------| +| CreateSurfaceAsConsumer | Buffer的消费者来使用该函数创建一个Surface | +| CreateSurfaceAsProducer | Buffer的生产者使用该函数创建一个Surface,只能使用与生产相关的接口 | +| GetProducer | 获得一个Surface内部的IBufferProducer对象 | +| RequestBuffer | 请求一个待生产的SurfaceBuffer对象 | +| CancelBuffer | 取消、归还一个待生产的SurfaceBuffer对象 | +| FlushBuffer | 归还一个生产好的SurfaceBuffer对象并携带一些信息 | +| AcquireBuffer | 请求一个待消费的SurfaceBuffer对象 | +| ReleaseBuffer | 归还一个已消费的SurfaceBuffer对象 | +| GetQueueSize | 获得当前同时能并存buffer的数量 | +| SetQueueSize | 设置当前同时能并存buffer的数量 | +| SetDefaultWidthAndHeight | 设置默认宽和高 | +| GetDefaultWidth | 获得默认宽度 | +| GetDefaultHeight | 获得默认高度 | +| SetUserData | 存贮字符串数据,不随着IPC传递 | +| GetUserData | 取出字符串数据 | +| RegisterConsumerListener | 注册一个消费监听器,监听Buffer的Flush事件 | +| UnregisterConsumerListener | 取消监听 | + +### SurfaceBuffer +| 接口名 | 职责 | +|-----------------|-------------------------------------| +| GetBufferHandle | 获得SurfaceBuffer的BufferHandle指针 | +| GetWidth | 获得SurfaceBuffer的宽度 | +| GetHeight | 获得SurfaceBuffer的高度 | +| GetFormat | 获得SurfaceBuffer的颜色格式 | +| GetUsage | 获得SurfaceBuffer的用途 | +| GetPhyAddr | 获得SurfaceBuffer的物理地址 | +| GetKey | 获得SurfaceBuffer的key | +| GetVirAddr | 获得SurfaceBuffer的虚拟地址 | +| GetSize | 获得SurfaceBuffer的文件句柄 | +| SetInt32 | 获得SurfaceBuffer的缓冲区大小 | +| GetInt32 | 设置SurfaceBuffer的32位整数 | +| SetInt64 | 获得SurfaceBuffer的32位整数 | +| GetInt64 | 设置SurfaceBuffer的64位整数 | + +### VsyncHelper +| 接口名 | 职责 | +|----------------------|-----------------------------------| +| Current | 获取当前runner对应的VsyncHelper | +| VsyncHelper | 用EventHandler对象构造VsyncHelper | +| RequestFrameCallback | 注册一个帧回调 | + +## 使用说明 + +### 具名服务-传递一个生产型Surface + +#### 注册 +```cpp +// 拿到一个消费型Surface +sptr surface = Surface::CreateSurfaceAsConsumer(); + +// 拿出里面的生产者对象 +sptr producer = surface->GetProducer(); + +// 注册服务 +auto sm = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); +sm->AddSystemAbility(IPC_SA_ID, producer->AsObject()); +``` + +#### 客户端获得生产型Surface +```cpp +// 获得远程对象 +auto sm = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); +sptr robj = sm->GetSystemAbility(IPC_SA_ID); + +// 构造Surface +sptr bp = iface_cast(robj); +sptr surface = Surface::CreateSurfaceAsProducer(bp); +``` + +### 匿名服务-传递一个生产型Surface +场景: 在一次IPC过程中 + +#### 发送 +```cpp +// 拿到一个消费型Surface +sptr surface = CreateSurfaceAsConsumer(); + +// 拿出里面的生产者对象 +sptr producer = surface->GetProducer(); + +// 返回给客户端 +parcel.WriteRemoteObject(producer); +``` + +#### 接受并获得生产型Surface +```cpp +// 获得远程对象 +sptr remoteObject = parcel.ReadRemoteObject(); + +// 构造Surface +sptr bp = iface_cast(robj); +sptr surface = Surface::CreateSurfaceAsProducer(bp); +``` + +### 生产一个SurfaceBuffer +条件: 一个生产型Surface + +```cpp +BufferRequestConfig requestConfig = { + .width = 1920, // 屏幕宽度 + .height = 1080, // 屏幕高度 + .strideAlignment = 8, // stride对齐字节 + .format = PIXEL_FMT_RGBA_8888, // 颜色格式 + .usage = HBM_USE_CPU_READ | HBM_USE_CPU_WRITE | HBM_USE_MEM_DMA, // 用法 + .timeout = 0, // 时延 +}; + +sptr buffer; +int32_t releaseFence; + +SurfaceError ret = surface->RequestBuffer(buffer, releaseFence, requestConfig); +if (ret != SURFACE_ERROR_OK) { + // failed +} + +BufferFlushConfig flushConfig = { + .damage = { // 重绘区域 + .x = 0, // 起点横坐标 + .y = 0, // 起点纵坐标 + .w = buffer->GetWidth(), // 区域宽度 + .h = buffer->GetHeight(), // 区域高度 + }, + .timestamp = 0 // 给消费者看的时间,0为使用当前时间 +}; + +ret = surface->FlushBuffer(buffer, -1, flushConfig); +if (ret != SURFACE_ERROR_OK) { + // failed +} +``` + +### 消费一个SurfaceBuffer +条件: 一个消费型Surface + +```cpp +class TestConsumerListener : public IBufferConsumerListener { +public: + void OnBufferAvailable() override { + sptr buffer; + int32_t flushFence; + + SurfaceError ret = surface->AcquireBuffer(buffer, flushFence, timestamp, damage); + if (ret != SURFACE_ERROR_OK) { + // failed + } + + // ... + + ret = surface->ReleaseBuffer(buffer, -1); + if (ret != SURFACE_ERROR_OK) { + // failed + } + } +}; + +sptr listener = new TestConsumerListener(); +SurfaceError ret = surface->RegisterConsumerListener(listener); +if (ret != SURFACE_ERROR_OK) { + // failed +} +``` + +### 给SurfaceBuffer带上自定义数据 +```cpp +sptr buffer; +SurfaceError ret = buffer->SetInt32(1, 3); +if (ret != SURFACE_ERROR_OK) { + // failed +} + +int32_t val; +ret = buffer->GetInt32(1, val); +if (ret != SURFACE_ERROR_OK) { + // failed +} +``` + +### 注册一个Vsync回调事件 +#### 用handler构造VsyncHelper +```cpp +auto runner = AppExecFwk::EventRunner::Create(true); +auto handler = std::make_shared(runner); +auto helper = new VsyncHelper(handler); +runner->Run(); + +struct FrameCallback cb = { + .timestamp_ = 0, + .userdata_ = nullptr, + .callback_ = [](int64_t timestamp, void* userdata) { + }, +}; + +VsyncError ret = helper->RequestFrameCallback(cb); +if (ret != VSYNC_ERROR_OK) { + // failed +} +``` + +#### 在handler里用Current +```cpp +auto runner = AppExecFwk::EventRunner::Create(true); +auto handler = std::make_shared(runner); +handler->PostTask([]() { + auto helper = VsyncHelper::Current(); + struct FrameCallback cb = { + .timestamp_ = 0, + .userdata_ = nullptr, + .callback_ = [](int64_t timestamp, void* userdata) { + }, + }; + + VsyncError ret = helper->RequestFrameCallback(cb); + if (ret != VSYNC_ERROR_OK) { + // failed + } +}); + +runner->Run(); +``` + +## 相关仓 +- **graphic_standard** +- ace_ace_engine +- aafwk_standard +- multimedia_media_standard +- multimedia_camera_standard diff --git a/adapter/BUILD.gn b/adapter/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..0efe55427523b7ac4c2afb8462c470d7dce8efe8 --- /dev/null +++ b/adapter/BUILD.gn @@ -0,0 +1,98 @@ +# Copyright (c) 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/ohos.gni") + +## Build libwmadaptertest.so {{{ +config("libwmadaptertest_config") { + visibility = [ ":*" ] + + include_dirs = [ + "include", + "//utils/system/safwk/native/include", + "//foundation/windowmanager/wmserver/include", + "//foundation/windowmanager/interfaces/innerkits/wm", + "//foundation/windowmanager/wm/include", + "//foundation/windowmanager/utils/include", + "//foundation/graphic/standard/interfaces/innerkits/wmclient", + "//foundation/graphic/standard/interfaces/innerkits/common", + "//foundation/graphic/standard/interfaces/innerkits/surface", + + # for abilityContext + "//foundation/aafwk/standard/frameworks/kits/ability/ability_runtime/include", + "//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_base/include", + "//base/global/resmgr_standard/interfaces/innerkits/include", + "//third_party/node/deps/icu-small/source/common", + "//foundation/aafwk/standard/interfaces/innerkits/ability_manager/include", + "//foundation/aafwk/standard/interfaces/innerkits/want/include/ohos/aafwk/content", + "//foundation/distributedschedule/dmsfwk/services/dtbschedmgr/include", + "//foundation/aafwk/standard/interfaces/innerkits/base/include", + ] + + cflags = [ + "-Wall", + "-Werror", + "-g3", + ] +} + +config("libwmadaptertest_public_config") { + include_dirs = [ + "//foundation/graphic/standard/interfaces/innerkits/wmclient", + "//foundation/windowmanager/interfaces/innerkits/wm", + "//foundation/multimodalinput/input/interfaces/native/innerkits/proxy/include", + "//foundation/multimodalinput/input/interfaces/native/innerkits/event/include", + "//foundation/multimodalinput/input/common/include", + ] +} + +ohos_shared_library("libwmadaptertest") { + sources = [ "src/adapter.cpp" ] + + configs = [ ":libwmadaptertest_config" ] + + public_configs = [ ":libwmadaptertest_public_config" ] + + deps = [ + "//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog", + "//foundation/graphic/standard:libwmclient", + "//utils/native/base:utils", + + # RSSurface + "//foundation/graphic/standard/rosen/modules/render_service_base:librender_service_base", + "//foundation/graphic/standard/rosen/modules/render_service_client:librender_service_client", + + # native value + "//foundation/ace/napi:ace_napi", + + # ace + "//foundation/ace/ace_engine/interfaces/innerkits/ace:ace_uicontent", + + # aafwk + "//foundation/aafwk/standard/interfaces/innerkits/want:want", + ] + + public_deps = [ + "//foundation/communication/ipc/interfaces/innerkits/ipc_core:ipc_core", + "//foundation/graphic/standard:libsurface", + "//foundation/graphic/standard/utils:promise", + "//utils/native/base:utils", + + # IMS + "//foundation/multimodalinput/input/frameworks/proxy:libmmi-client", + "//foundation/multimodalinput/input/frameworks/proxy:libmmi-common", + ] + + part_name = "window_manager" + subsystem_name = "window" +} diff --git a/adapter/include/adapter.h b/adapter/include/adapter.h new file mode 100644 index 0000000000000000000000000000000000000000..c387a88d0feadcecb9318025c9e453a45b0dfe7c --- /dev/null +++ b/adapter/include/adapter.h @@ -0,0 +1,63 @@ +/* + * Copyright (c) 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 OHOS_ROSEN_WINDOW_ADAPTER_H +#define OHOS_ROSEN_WINDOW_ADAPTER_H +#define _NEW_RENDERSERVER_ +#include +#include +#include +#include +#include +#include +#include +#include "foundation/windowmanager/interfaces/innerkits/wm/window_option.h" +#include "wm_common.h" +#include "window.h" +#include "foundation/graphic/standard/interfaces/innerkits/wmclient/window_option.h" +#include "window_manager.h" +#include "window_manager_hilog.h" + +namespace OHOS { +namespace Rosen { +class Adapter { +public: + Adapter(); + ~Adapter(); + + static WMError Init(); + static bool CreateWestonWindow(sptr& option); + static void DestroyWestonWindow(); + static bool GetMainWindowRect(OHOS::Rosen::Rect &rect); + static OHOS::Rosen::WMError Show(); + static OHOS::Rosen::WMError Hide(); + static OHOS::Rosen::WMError MoveTo(int32_t x, int32_t y); + static OHOS::Rosen::WMError Resize(uint32_t width, uint32_t height); + +private: + static bool WindowOptionConvertToWeston(sptr& option, + sptr& config); + static bool GetSurfaceBuffer(sptr &surface, + sptr &buffer, + OHOS::BufferRequestConfig &rconfig); + static void WriteDataToSurface(); + static void ColorDraw(void *vaddr, uint32_t width, uint32_t height, uint32_t count); + static void BlackDraw(void *vaddr, uint32_t width, uint32_t height, uint32_t count); + static void FlushDraw(void *vaddr, uint32_t width, uint32_t height, uint32_t count); + static void set(void *vaddr, char ch, size_t len); +}; +} +} +#endif // OHOS_ROSEN_WINDOW_ADAPTER_H diff --git a/adapter/src/adapter.cpp b/adapter/src/adapter.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f705b490235b00f8dda6535abf4dc5a1d04e0643 --- /dev/null +++ b/adapter/src/adapter.cpp @@ -0,0 +1,327 @@ +/* + * Copyright (c) 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 "adapter.h" +#include "window_impl.h" + +namespace OHOS { +namespace Rosen { + +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, 0, "Adapter" }; + +static inline sptr westonMainWindow_ = nullptr; + +Adapter::Adapter() +{ +} + +Adapter::~Adapter() +{ +} + +OHOS::Rosen::WMError Adapter::Init() +{ + // "AbilityWindow::Init()" + auto wmi = WindowManager::GetInstance(); + if (wmi == nullptr) { + WLOGFE("Adapter::Init WindowManager::GetInstance() is nullptr."); + return OHOS::Rosen::WMError::WM_ERROR_WINDOWMANAGER_GETINSTANCE; + } + + auto wret = wmi->Init(); + if (wret != OHOS::WM_OK) { + WLOGFE("Adapter::Init WindowManager::Init() return %d", wret); + return OHOS::Rosen::WMError::WM_ERROR_WINDOWMANAGER_INIT; + } + WLOGFI("%{public}s end.", __func__); + return OHOS::Rosen::WMError::WM_OK; +} + +bool Adapter::CreateWestonWindow(sptr& option) +{ + sptr config = OHOS::WindowOption::Get(); + if (!WindowOptionConvertToWeston(option, config)) { + WLOGFE("Adapter::CreateWindow convert windowOption fail"); + return false; + } + + auto wmi = OHOS::WindowManager::GetInstance(); + if (wmi == nullptr) { + WLOGFE("Adapter::ConvertToWindowOption WindowManager::GetInstance() is nullptr."); + return false; + } + + WLOGFI("%{public}s begin wms->CreateWindow.", __func__); + auto retvalCreate = wmi->CreateWindow(westonMainWindow_, config); + WLOGFI("%{public}s end wms->CreateWindow.", __func__); + + WriteDataToSurface(); + + if (retvalCreate != OHOS::WMError::WM_OK) { + WLOGFE("Adapter::ConvertToWindowOption WindowManager::CreateWindow() return %d", retvalCreate); + return false; + } + return true; +} + +void Adapter::DestroyWestonWindow() +{ + if (westonMainWindow_ != nullptr) { + OHOS::WMError err = westonMainWindow_->Destroy(); + westonMainWindow_ = nullptr; + if (err == OHOS::WMError::WM_OK) { + WLOGFI("DestroyWestonWindow OK"); + return; + } + WLOGFE("DestroyWestonWindow errorcode=%d", static_cast(err)); + } + WLOGFE("DestroyWestonWindow westonMainWindow_ is null"); +} + +bool Adapter::WindowOptionConvertToWeston(sptr& option, sptr& config) +{ + // window type + config->SetWindowType(OHOS::WindowType::WINDOW_TYPE_NORMAL); + config->SetWindowMode(OHOS::WindowMode::WINDOW_MODE_FULL); + return true; +} + +bool Adapter::GetMainWindowRect(OHOS::Rosen::Rect &rect) +{ + if (westonMainWindow_ == nullptr) { + return false; + } + rect.posX_ = westonMainWindow_->GetX(); + rect.posY_ = westonMainWindow_->GetY(); + rect.width_ = westonMainWindow_->GetWidth(); + rect.height_ = westonMainWindow_->GetHeight(); + return true; +} + +static inline bool hide = false; + +OHOS::Rosen::WMError Adapter::Show() +{ + if (westonMainWindow_ == nullptr) { + WLOGFE("Adapter::Show westonMainWindow_ is null"); + return OHOS::Rosen::WMError::WM_ERROR_WINDOWMANAGER_SHOW; + } + + if (!hide) { + auto promise = westonMainWindow_->Show(); + if (promise == nullptr) { + WLOGFE("Adapter::Show Show error"); + return OHOS::Rosen::WMError::WM_ERROR_WINDOWMANAGER_SHOW; + } + auto error = promise->Await(); + if (error != OHOS::WMError::WM_OK) { + WLOGFE("Adapter::Show Show error=%d", static_cast(error)); + return OHOS::Rosen::WMError::WM_ERROR_WINDOWMANAGER_SHOW; + } + } + + auto promise2 = westonMainWindow_->SwitchTop(); + if (promise2 == nullptr) { + WLOGFE("Adapter::Show SwitchTop error"); + return OHOS::Rosen::WMError::WM_ERROR_WINDOWMANAGER_SHOW; + } + auto error2 = promise2->Await(); + if (error2 != OHOS::WMError::WM_OK) { + WLOGFE("Adapter::Show SwitchTop error=%d", static_cast(error2)); + return OHOS::Rosen::WMError::WM_ERROR_WINDOWMANAGER_SHOW; + } + + return OHOS::Rosen::WMError::WM_OK; +} + +void Adapter::WriteDataToSurface() +{ + /* write data to surface */ + sptr surface = westonMainWindow_->GetSurface(); + sptr buffer; + BufferRequestConfig rconfig; + if (GetSurfaceBuffer(surface, buffer, rconfig)) { + BlackDraw(buffer->GetVirAddr(), rconfig.width, rconfig.height, 1); + } else { + WLOGFE("Adapter::WriteDataToSurface GetSurfaceBuffer fail"); + } + BufferFlushConfig fconfig = { + .damage = { + .w = rconfig.width, + .h = rconfig.height, + }, + }; + surface->FlushBuffer(buffer, -1, fconfig); +} + +OHOS::Rosen::WMError Adapter::Hide() +{ + if (westonMainWindow_ == nullptr) { + WLOGFE("Adapter::Hide westonMainWindow_ is null"); + return OHOS::Rosen::WMError::WM_ERROR_WINDOWMANAGER_HIDE; + } + auto promise = westonMainWindow_->Hide(); + if (promise == nullptr) { + WLOGFE("Adapter::Hide Hide error"); + return OHOS::Rosen::WMError::WM_ERROR_WINDOWMANAGER_HIDE; + } + auto error = promise->Await(); + if (error != OHOS::WMError::WM_OK) { + WLOGFE("Adapter::Hide Hide error=%d", static_cast(error)); + return OHOS::Rosen::WMError::WM_ERROR_WINDOWMANAGER_HIDE; + } + hide = true; + return OHOS::Rosen::WMError::WM_OK; +} + +OHOS::Rosen::WMError Adapter::MoveTo(int32_t x, int32_t y) +{ + if (westonMainWindow_ == nullptr) { + WLOGFE("Adapter::MoveTo westonMainWindow_ is null"); + return OHOS::Rosen::WMError::WM_ERROR_WINDOWMANAGER_MOVE; + } + auto promise = westonMainWindow_->Move(x, y); + if (promise == nullptr) { + WLOGFE("Adapter::MoveTo promise is null"); + return OHOS::Rosen::WMError::WM_ERROR_WINDOWMANAGER_MOVE; + } + return OHOS::Rosen::WMError::WM_OK; +} + +OHOS::Rosen::WMError Adapter::Resize(uint32_t width, uint32_t height) +{ + if (westonMainWindow_ == nullptr) { + WLOGFE("Adapter::Resize westonMainWindow_ is null"); + return OHOS::Rosen::WMError::WM_ERROR_WINDOWMANAGER_RESIZE; + } + auto promise = westonMainWindow_->Resize(width, height); + if (promise == nullptr) { + WLOGFE("Adapter::Resize promise is null"); + return OHOS::Rosen::WMError::WM_ERROR_WINDOWMANAGER_RESIZE; + } + return OHOS::Rosen::WMError::WM_OK; +} + +bool Adapter::GetSurfaceBuffer(sptr &surface, sptr &buffer, BufferRequestConfig &rconfig) +{ + int32_t releaseFence; + rconfig = { + .width = surface->GetDefaultWidth(), + .height = surface->GetDefaultHeight(), + .strideAlignment = 0x8, + .format = 12, // PIXEL_FMT_RGBA_8888, + .usage = surface->GetDefaultUsage(), + .timeout = 0, + }; + OHOS::SurfaceError ret = surface->RequestBuffer(buffer, releaseFence, rconfig); + if (ret == 40601000) { // OHOS::SurfaceError::SURFACE_ERROR_NO_BUFFER + WLOGFE("Adapter::GetSurfaceBuffer RequestBuffer error=%d", static_cast(ret)); + return false; + } else if (ret != 0) { // OHOS::SurfaceError::SURFACE_ERROR_OK + WLOGFE("Adapter::GetSurfaceBuffer RequestBuffer is NG error=%d", static_cast(ret)); + return false; + } else if (buffer == nullptr) { + WLOGFE("Adapter::GetSurfaceBuffer buffer is nullptr"); + return false; + } + return true; +} + +void Adapter::ColorDraw(void *vaddr, uint32_t width, uint32_t height, uint32_t count) +{ + auto addr = static_cast(vaddr); + if (addr == nullptr) { + return; + } + + constexpr uint32_t wdiv = 2; + constexpr uint32_t colorTable[][wdiv] = { + {0xffff0000, 0xffff00ff}, + {0xffff0000, 0xffffff00}, + {0xff00ff00, 0xffffff00}, + {0xff00ff00, 0xff00ffff}, + {0xff0000ff, 0xff00ffff}, + {0xff0000ff, 0xffff00ff}, + {0xff777777, 0xff777777}, + {0xff777777, 0xff777777}, + }; + const uint32_t hdiv = sizeof(colorTable) / sizeof(*colorTable); + + for (uint32_t i = 0; i < height; i++) { + auto table = colorTable[i / (height / hdiv)]; + for (uint32_t j = 0; j < wdiv; j++) { + auto color = table[j]; + for (uint32_t k = j * width / wdiv; k < (j + 1) * width / wdiv; k++) { + addr[i * width + k] = color; + } + } + } +} + +void Adapter::BlackDraw(void *vaddr, uint32_t width, uint32_t height, uint32_t count) +{ + auto addr = static_cast(vaddr); + if (addr == nullptr) { + return; + } + + for (uint32_t i = 0; i < width * height; i++) { + addr[i] = 0xff00ff00; + } +} + +void Adapter::FlushDraw(void *vaddr, uint32_t width, uint32_t height, uint32_t count) +{ + auto addr = static_cast(vaddr); + if (addr == nullptr) { + return; + } + + constexpr uint32_t bpp = 4; + constexpr uint32_t color1 = 0xff / 3 * 0; + constexpr uint32_t color2 = 0xff / 3 * 1; + constexpr uint32_t color3 = 0xff / 3 * 2; + constexpr uint32_t color4 = 0xff / 3 * 3; + constexpr uint32_t bigDiv = 7; + constexpr uint32_t smallDiv = 10; + uint32_t c = count % (bigDiv * smallDiv); + uint32_t stride = width * bpp; + uint32_t beforeCount = height * c / bigDiv / smallDiv; + uint32_t afterCount = height - beforeCount - 1; + + size_t len = ((stride * height) < (beforeCount * stride) ? (stride * height) : (beforeCount * stride)); + set(addr, color3, len); + + len = ((stride * height) < (afterCount * stride) ? (stride * height) : (afterCount * stride)); + set(addr + (beforeCount + 1) * stride, color1, len); + + for (uint32_t i = 0; i < bigDiv; i++) { + len = ((stride * height) < (stride) ? (stride * height) : (stride)); + set(addr + (i * height / bigDiv) * stride, color4, len); + } + + len = ((stride * height) < (stride) ? (stride * height) : (stride)); + set(addr + beforeCount * stride, color2, len); +} + +void Adapter::set(void *vaddr, char ch, size_t len) +{ + char *ptr = static_cast(vaddr); + for (size_t i = 0; i < len; i++) { + ptr[i] = ch; + } +} +} +} diff --git a/dm/include/README.md b/dm/include/README.md new file mode 100644 index 0000000000000000000000000000000000000000..bda91e7389908403060ac7266cf998451a5aee85 --- /dev/null +++ b/dm/include/README.md @@ -0,0 +1 @@ +Store code of display client inner header files diff --git a/dm/include/display_manager_adapter.h b/dm/include/display_manager_adapter.h new file mode 100644 index 0000000000000000000000000000000000000000..61882fd0dba9c134c7fb798b7565ac8652682c33 --- /dev/null +++ b/dm/include/display_manager_adapter.h @@ -0,0 +1,54 @@ +/* + * Copyright (c) 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 FOUNDATION_DM_DISPLAY_MANAGER_ADAPTER_H +#define FOUNDATION_DM_DISPLAY_MANAGER_ADAPTER_H + +#include +#include + +#include "display.h" +#include "display_manager_interface.h" +#include "single_instance.h" +#include "singleton_delegator.h" + +namespace OHOS::Rosen { +class DMSDeathRecipient : public IRemoteObject::DeathRecipient { +public: + virtual void OnRemoteDied(const wptr& wptrDeath) override; +}; + +class DisplayManagerAdapter : public RefBase { + DECLARE_SINGLE_INSTANCE_BASE(DisplayManagerAdapter); +public: + sptr GetDisplay(DisplayType type); + DisplayId GetDefaultDisplayId(); + sptr GetDisplayById(DisplayId displayId); + + void Clear(); +private: + DisplayManagerAdapter() = default; + ~DisplayManagerAdapter() = default; + bool InitDMSProxyLocked(); + static inline SingletonDelegator delegator; + + std::mutex mutex_; + sptr displayManagerServiceProxy_ = nullptr; + sptr dmsDeath_ = nullptr; + std::map> displayMap_; + DisplayId defaultDisplayId_; +}; +} // namespace OHOS::Rosen +#endif // FOUNDATION_DM_DISPLAY_MANAGER_ADAPTER_H diff --git a/dm/src/README.md b/dm/src/README.md new file mode 100644 index 0000000000000000000000000000000000000000..8eb6cfc677dd9bd5133781d11e412945a4bb96fd --- /dev/null +++ b/dm/src/README.md @@ -0,0 +1 @@ +Store code of display source files diff --git a/dm/src/display.cpp b/dm/src/display.cpp new file mode 100644 index 0000000000000000000000000000000000000000..73655b9404a87e6eba3d41f0159244c642e34c83 --- /dev/null +++ b/dm/src/display.cpp @@ -0,0 +1,68 @@ +/* + * Copyright (c) 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 "display.h" +#include "display_info.h" + +namespace OHOS::Rosen { +Display::Display(const std::string& name, DisplayInfo* info) + : name_(name), + id_(info->id_), + width_(info->width_), + height_(info->height_), + freshRate_(info->freshRate_) +{ +} + +DisplayId Display::GetId() const +{ + return id_; +} + +int32_t Display::GetWidth() const +{ + return width_; +} + +int32_t Display::GetHeight() const +{ + return height_; +} + +uint32_t Display::GetFreshRate() const +{ + return freshRate_; +} + +void Display::SetWidth(int32_t width) +{ + width_ = width; +} + +void Display::SetHeight(int32_t height) +{ + height_ = height; +} + +void Display::SetFreshRate(uint32_t freshRate) +{ + freshRate_ = freshRate; +} + +void Display::SetId(DisplayId id) +{ + id_ = id; +} +} // namespace OHOS::Rosen \ No newline at end of file diff --git a/dm/src/display_manager.cpp b/dm/src/display_manager.cpp new file mode 100644 index 0000000000000000000000000000000000000000..57b8ac1b0ae7cf96ab69773682d26f71227cd42c --- /dev/null +++ b/dm/src/display_manager.cpp @@ -0,0 +1,97 @@ +/* + * Copyright (c) 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 "display_manager.h" +#include "display_manager_adapter.h" +#include "window_manager_hilog.h" + +namespace OHOS::Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "DisplayManager"}; +} + +IMPLEMENT_SINGLE_INSTANCE(DisplayManager); + +DisplayManager::DisplayManager() +{ + dmsAdapter_ = SingletonContainer::Get(); +} + +DisplayManager::~DisplayManager() +{ +} + +const sptr& DisplayManager::GetDisplay(const DisplayType type) +{ + if (dmsAdapter_ == nullptr) { + WLOGFE("DisplayManager::GetDisplay null!"); + return nullptr; + } + return dmsAdapter_->GetDisplay(type); +} + +DisplayId DisplayManager::GetDefaultDisplayId() +{ + if (dmsAdapter_ == nullptr) { + WLOGFE("DisplayManager::GetDefaultDisplayId null!\n"); + return DISPLAY_ID_INVALD; + } + return dmsAdapter_->GetDefaultDisplayId(); +} + +const sptr DisplayManager::GetDisplayById(DisplayId displayId) +{ + if (dmsAdapter_ == nullptr) { + WLOGFE("DisplayManager::GetDisplayById null!\n"); + return nullptr; + } + + sptr display = dmsAdapter_->GetDisplayById(displayId); + if (display == nullptr) { + WLOGFE("DisplayManager::GetDisplayById failed!\n"); + return nullptr; + } + return display; +} + + +const sptr DisplayManager::GetDefaultDisplay() +{ + return GetDisplayById(GetDefaultDisplayId()); +} + +std::vector DisplayManager::GetAllDisplayIds() +{ + std::vector res; + res.push_back(GetDefaultDisplayId()); + // 获取所有displayIds + return res; +} + +std::vector> DisplayManager::GetAllDisplays() +{ + std::vector> res; + auto displayIds = GetAllDisplayIds(); + for (auto displayId: displayIds) { + const sptr display = GetDisplayById(displayId); + if (display != nullptr) { + res.push_back(display); + } else { + WLOGFE("DisplayManager::GetAllDisplays display %llu nullptr!", displayId); + } + } + return res; +} +} // namespace OHOS::Rosen \ No newline at end of file diff --git a/dm/src/display_manager_adapter.cpp b/dm/src/display_manager_adapter.cpp new file mode 100644 index 0000000000000000000000000000000000000000..675bb97b8be1212aae57e403fc8d248196b2eae6 --- /dev/null +++ b/dm/src/display_manager_adapter.cpp @@ -0,0 +1,143 @@ +/* + * Copyright (c) 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 "display_manager_adapter.h" + +#include +#include +#include + +#include "window_manager_hilog.h" +#include "wm_common.h" + +namespace OHOS::Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "DisplayManagerAdapter"}; +} + +IMPLEMENT_SINGLE_INSTANCE(DisplayManagerAdapter); + +sptr DisplayManagerAdapter::GetDisplay(DisplayType type) +{ + std::lock_guard lock(mutex_); + + if (!InitDMSProxyLocked()) { + WLOGFE("displayManagerAdapter::GetDisplay: InitDMSProxyLocked failed!"); + return nullptr; + } + sptr info = displayManagerServiceProxy_->GetDisplayInfo(type); + // TODO DisplayInfo内容更新到对应的Display.displayInfo_. auto iter = displayMap_.find(info.id_); + return nullptr; +} + +DisplayId DisplayManagerAdapter::GetDefaultDisplayId() +{ + std::lock_guard lock(mutex_); + + if (defaultDisplayId_ != DISPLAY_ID_INVALD) { + return defaultDisplayId_; + } + + if (!InitDMSProxyLocked()) { + WLOGFE("displayManagerAdapter::GetDefaultDisplayId: InitDMSProxyLocked failed!"); + return DISPLAY_ID_INVALD; + } + defaultDisplayId_ = displayManagerServiceProxy_->GetDefaultDisplayId(); + return defaultDisplayId_; +} + +sptr DisplayManagerAdapter::GetDisplayById(DisplayId displayId) +{ + std::lock_guard lock(mutex_); + + auto iter = displayMap_.find(displayId); + if (iter != displayMap_.end()) { + return iter->second; + } + + if (!InitDMSProxyLocked()) { + WLOGFE("displayManagerAdapter::GetDisplayById: InitDMSProxyLocked failed!"); + return nullptr; + } + DisplayInfo displayInfo = displayManagerServiceProxy_->GetDisplayInfoById(displayId); + sptr display = new Display("", &displayInfo); + if (display->GetId() != DISPLAY_ID_INVALD) { + displayMap_[display->GetId()] = display; + } + return display; +} + +bool DisplayManagerAdapter::InitDMSProxyLocked() +{ + WLOGFI("InitDMSProxy"); + if (!displayManagerServiceProxy_) { + sptr systemAbilityManager = + SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + if (!systemAbilityManager) { + WLOGFE("Failed to get system ability mgr."); + return false; + } + + sptr remoteObject + = systemAbilityManager->GetSystemAbility(DISPLAY_MANAGER_SERVICE_SA_ID); + if (!remoteObject) { + WLOGFE("Failed to get display manager service."); + return false; + } + + displayManagerServiceProxy_ = iface_cast(remoteObject); + if ((!displayManagerServiceProxy_) || (!displayManagerServiceProxy_->AsObject())) { + WLOGFE("Failed to get system display manager services"); + return false; + } + + dmsDeath_ = new DMSDeathRecipient(); + if (!dmsDeath_) { + WLOGFE("Failed to create death Recipient ptr DMSDeathRecipient"); + return false; + } + if (!remoteObject->AddDeathRecipient(dmsDeath_)) { + WLOGFE("Failed to add death recipient"); + return false; + } + } + return true; +} + +void DMSDeathRecipient::OnRemoteDied(const wptr& wptrDeath) +{ + if (wptrDeath == nullptr) { + WLOGFE("wptrDeath is null"); + return; + } + + sptr object = wptrDeath.promote(); + if (!object) { + WLOGFE("object is null"); + return; + } + SingletonContainer::Get().GetRefPtr()->Clear(); + return; +} + +void DisplayManagerAdapter::Clear() +{ + std::lock_guard lock(mutex_); + if ((displayManagerServiceProxy_ != nullptr) && (displayManagerServiceProxy_->AsObject() != nullptr)) { + displayManagerServiceProxy_->AsObject()->RemoveDeathRecipient(dmsDeath_); + } + displayManagerServiceProxy_ = nullptr; +} +} // namespace OHOS::Rosen \ No newline at end of file diff --git a/dm/src/monitor.cpp b/dm/src/monitor.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ca8933d58b4aea5bdbe2f9de8a475c0c61fbe738 --- /dev/null +++ b/dm/src/monitor.cpp @@ -0,0 +1,19 @@ +/* + * Copyright (c) 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 "monitor.h" + +namespace OHOS::Rosen { +} // namespace OHOS::Rosen \ No newline at end of file diff --git a/dmserver/include/README.md b/dmserver/include/README.md new file mode 100644 index 0000000000000000000000000000000000000000..92b3669bdd6971bac668e392d46d0439ec732390 --- /dev/null +++ b/dmserver/include/README.md @@ -0,0 +1 @@ +Store code of display manager service inner header files diff --git a/dmserver/include/display_info.h b/dmserver/include/display_info.h new file mode 100644 index 0000000000000000000000000000000000000000..72edc10998d20f9ae0370453fd2bcbf68d2a4fcc --- /dev/null +++ b/dmserver/include/display_info.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 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 p ermissions and + * limitations under the License. + */ + +#ifndef FOUNDATION_DMSERVER_DISPLAY_INFO_H +#define FOUNDATION_DMSERVER_DISPLAY_INFO_H + +#include + +#include "display.h" + +namespace OHOS::Rosen { +class DisplayInfo : public Parcelable { +public: + DisplayInfo() = default; + ~DisplayInfo() = default; + + void Update(DisplayInfo* info); + + virtual bool Marshalling(Parcel& parcel) const override; + static DisplayInfo *Unmarshalling(Parcel& parcel); + + DisplayId id_ {DISPLAY_ID_INVALD}; + DisplayType type_ {DisplayType::DEFAULT}; + int32_t width_ {0}; + int32_t height_ {0}; + uint32_t freshRate_ {0}; + float xDpi_ {0.0}; + float yDpi_ {0.0}; +}; +} // namespace OHOS::Rosen +#endif // FOUNDATION_DMSERVER_DISPLAY_INFO_H \ No newline at end of file diff --git a/dmserver/include/display_manager_interface.h b/dmserver/include/display_manager_interface.h new file mode 100644 index 0000000000000000000000000000000000000000..8a7d71fc5e46fca2ae133a6cd13e1d60c236bc87 --- /dev/null +++ b/dmserver/include/display_manager_interface.h @@ -0,0 +1,41 @@ +/* + * Copyright (c) 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 FOUNDATION_DMSERVER_DISPLAY_MANAGER_INTERFACE_H +#define FOUNDATION_DMSERVER_DISPLAY_MANAGER_INTERFACE_H + +#include + +#include "display_info.h" + +namespace OHOS::Rosen { +class IDisplayManager : public IRemoteBroker { +public: + DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.IDisplayManager"); + + enum { + TRANS_ID_GET_DISPLAY_INFO = 1, + TRANS_ID_GET_DEFAULT_DISPLAY_ID = 2, + TRANS_ID_GET_DISPLAY_BY_ID = 3, + }; + + virtual const sptr& GetDisplayInfo(const DisplayType type) = 0; + + virtual DisplayId GetDefaultDisplayId() = 0; + virtual DisplayInfo GetDisplayInfoById(DisplayId displayId) = 0; +}; +} // namespace OHOS::Rosen + +#endif // FOUNDATION_DMSERVER_DISPLAY_MANAGER_INTERFACE_H \ No newline at end of file diff --git a/dmserver/include/display_manager_proxy.h b/dmserver/include/display_manager_proxy.h new file mode 100644 index 0000000000000000000000000000000000000000..519107124d52720ced4aa4842d79c5f5d989dd01 --- /dev/null +++ b/dmserver/include/display_manager_proxy.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) 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 FOUNDATION_DMSERVER_DISPLAY_MANAGER_PROXY_H +#define FOUNDATION_DMSERVER_DISPLAY_MANAGER_PROXY_H + +#include "display_manager_interface.h" + +#include + +namespace OHOS::Rosen { +class DisplayManagerProxy : public IRemoteProxy { +public: + explicit DisplayManagerProxy(const sptr &impl) + : IRemoteProxy(impl) {}; + ~DisplayManagerProxy() {}; + + const sptr& GetDisplayInfo(const DisplayType type) override; + + DisplayId GetDefaultDisplayId() override; + DisplayInfo GetDisplayInfoById(DisplayId displayId) override; +private: + static inline BrokerDelegator delegator_; +}; +} // namespace OHOS::Rosen + +#endif // FOUNDATION_DMSERVER_DISPLAY_MANAGER_PROXY_H \ No newline at end of file diff --git a/dmserver/include/display_manager_service.h b/dmserver/include/display_manager_service.h new file mode 100644 index 0000000000000000000000000000000000000000..83ffbbe94abfeb64d7f4b3d7e7cb2f32ad044cc5 --- /dev/null +++ b/dmserver/include/display_manager_service.h @@ -0,0 +1,57 @@ +/* + * Copyright (c) 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 FOUNDATION_DMSERVER_DISPLAY_MANAGER_SERVICE_H +#define FOUNDATION_DMSERVER_DISPLAY_MANAGER_SERVICE_H + +#include +#include + +#include + +#include "display_manager_stub.h" +#include "display_screen.h" +#include "single_instance.h" +#include "singleton_delegator.h" +#include "display_screen_manager.h" + +namespace OHOS::Rosen { +class DisplayManagerService : public SystemAbility, public DisplayManagerStub { +DECLARE_SYSTEM_ABILITY(DisplayManagerService); + +DECLARE_SINGLE_INSTANCE_BASE(DisplayManagerService); + +public: + void OnStart() override; + void OnStop() override; + const sptr& GetDisplayInfo(const DisplayType type) override; + + DisplayId GetDefaultDisplayId() override; + DisplayInfo GetDisplayInfoById(DisplayId displayId) override; + +private: + DisplayManagerService(); + ~DisplayManagerService() = default; + bool Init(); + DisplayId GetDisplayIdFromScreenId(ScreenId screenId); + ScreenId GetScreenIdFromDisplayId(DisplayId displayId); + + static inline SingletonDelegator delegator_; + std::map> displayScreenMap_; + sptr displayScreenManager_; +}; +} // namespace OHOS::Rosen + +#endif // FOUNDATION_DMSERVER_DISPLAY_MANAGER_SERVICE_H \ No newline at end of file diff --git a/dmserver/include/display_manager_service_inner.h b/dmserver/include/display_manager_service_inner.h new file mode 100644 index 0000000000000000000000000000000000000000..6051c8044364b94d4bccda04b9d4d5e2c08b2c03 --- /dev/null +++ b/dmserver/include/display_manager_service_inner.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) 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 FOUNDATION_DMSERVER_DISPLAY_MANAGER_SERVICE_INNER_H +#define FOUNDATION_DMSERVER_DISPLAY_MANAGER_SERVICE_INNER_H + +#include +#include + +#include "display_screen.h" +#include "single_instance.h" +#include "singleton_delegator.h" + +namespace OHOS::Rosen { +class DisplayManagerServiceInner : public RefBase { +DECLARE_SINGLE_INSTANCE(DisplayManagerServiceInner); + +public: + std::vector> GetAllDisplays(); + DisplayId GetDefaultDisplayId(); + const sptr GetDefaultDisplay(); + const sptr GetDisplayById(DisplayId displayId); + std::vector GetAllDisplayIds(); +}; +} // namespace OHOS::Rosen + +#endif // FOUNDATION_DMSERVER_DISPLAY_MANAGER_SERVICE_H \ No newline at end of file diff --git a/dmserver/include/display_manager_stub.h b/dmserver/include/display_manager_stub.h new file mode 100644 index 0000000000000000000000000000000000000000..d88c4a0c652f4591b600a1e4b2f5ed339502127e --- /dev/null +++ b/dmserver/include/display_manager_stub.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) 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 FOUNDATION_DMSERVER_DISPLAY_MANAGER_STUB_H +#define FOUNDATION_DMSERVER_DISPLAY_MANAGER_STUB_H + +#include "display_manager_interface.h" + +#include + +namespace OHOS::Rosen { +class DisplayManagerStub : public IRemoteStub { +public: + DisplayManagerStub() = default; + ~DisplayManagerStub() = default; + virtual int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, + MessageOption &option) override; +}; +} // namespace OHOS::Rosen + +#endif // FOUNDATION_DMSERVER_DISPLAY_MANAGER_STUB_H \ No newline at end of file diff --git a/dmserver/include/display_node_control.h b/dmserver/include/display_node_control.h new file mode 100644 index 0000000000000000000000000000000000000000..5da96a208147911f1bc9f74bf9fdb5752f816528 --- /dev/null +++ b/dmserver/include/display_node_control.h @@ -0,0 +1,25 @@ +/* + * Copyright (c) 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 FOUNDATION_DMSERVER_DISPLAY_NODE_CONTROL_H +#define FOUNDATION_DMSERVER_DISPLAY_NODE_CONTROL_H + +#include + +namespace OHOS::Rosen { +class DisplayNodeControl : public RefBase { +}; +} // namespace OHOS::Rosen +#endif // FOUNDATION_DMSERVER_DISPLAY_NODE_CONTROL_H \ No newline at end of file diff --git a/dmserver/include/display_screen.h b/dmserver/include/display_screen.h new file mode 100644 index 0000000000000000000000000000000000000000..d656621953e85274d62a4dd0670693a0150d32b9 --- /dev/null +++ b/dmserver/include/display_screen.h @@ -0,0 +1,45 @@ +/* + * Copyright (c) 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 FOUNDATION_DMSERVER_DISPLAY_SCREEN_H +#define FOUNDATION_DMSERVER_DISPLAY_SCREEN_H + +#include +#include "display_info.h" + +namespace OHOS::Rosen { +class DisplayScreen : public RefBase { +public: + DisplayScreen(const DisplayInfo& info); + ~DisplayScreen() = default; + + DisplayId GetId() const; + int32_t GetWidth() const; + int32_t GetHeight() const; + uint32_t GetFreshRate() const; + + void SetId(DisplayId displayId); + void SetWidth(int32_t width); + void SetHeight(int32_t height); + void SetFreshRate(uint32_t freshRate); + +private: + DisplayId id_ {DISPLAY_ID_INVALD}; + int32_t width_ {0}; + int32_t height_ {0}; + uint32_t freshRate_ {0}; +}; +} // namespace OHOS::Rosen +#endif // FOUNDATION_DMSERVER_DISPLAY_SCREEN_H \ No newline at end of file diff --git a/dmserver/include/display_screen_manager.h b/dmserver/include/display_screen_manager.h new file mode 100644 index 0000000000000000000000000000000000000000..0c1df9b379a1c28c9827bd1533d8aae263b9980a --- /dev/null +++ b/dmserver/include/display_screen_manager.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 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 FOUNDATION_DMSERVER_DISPLAY_SCREEN_MANAGER_H +#define FOUNDATION_DMSERVER_DISPLAY_SCREEN_MANAGER_H + +#include +#include + +#include "display_screen.h" +#include "single_instance.h" +#include "transaction/rs_interfaces.h" + +namespace OHOS::Rosen { +class DisplayScreenManager : public RefBase { +DECLARE_SINGLE_INSTANCE_BASE(DisplayScreenManager); +public: + std::map> displayScreenMap_; + + ScreenId GetDefaultScreenId(); + RSScreenModeInfo GetScreenActiveMode(ScreenId id); + +private: + DisplayScreenManager(); + ~DisplayScreenManager(); + void parepareRSScreenManger(); + + OHOS::Rosen::RSInterfaces *rsInterface_; +}; + +} // namespace OHOS::Rosen +#endif // FOUNDATION_DMSERVER_DISPLAY_SCREEN_MANAGER_H \ No newline at end of file diff --git a/dmserver/include/rs_adapter.h b/dmserver/include/rs_adapter.h new file mode 100644 index 0000000000000000000000000000000000000000..9f19e344c929afbdb13a1e3f866dfb29d07ecf13 --- /dev/null +++ b/dmserver/include/rs_adapter.h @@ -0,0 +1,48 @@ +/* + * Copyright (c) 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 FOUNDATION_DMSERVER_RS_ADAPTER_H +#define FOUNDATION_DMSERVER_RS_ADAPTER_H + +#include +#include + +#include + +#include "single_instance.h" + +namespace OHOS::Rosen { +class DMSDeathRecipient : public IRemoteObject::DeathRecipient { +public: + virtual void OnRemoteDied(const wptr& wptrDeath) override; +private: + sptr& rsAdatper_; +}; + +class RsAdapter : public RefBase { + DECLARE_SINGLE_INSTANCE_BASE(RsAdapter); +public: + void Clear(); +private: + RsAdapter() = default; + ~RsAdapter() = default; + bool InitRSProxyLocked(); + + std::mutex mutex_; + sptr rsProxy_ = nullptr; + sptr rsDeath_ = nullptr; +}; +} // namespace OHOS::Rosen +#endif // FOUNDATION_DMSERVER_RS_ADAPTER_H diff --git a/dmserver/include/screen.h b/dmserver/include/screen.h new file mode 100644 index 0000000000000000000000000000000000000000..bbe436d55bb515aab342fe883f3b6155eedad961 --- /dev/null +++ b/dmserver/include/screen.h @@ -0,0 +1,25 @@ +/* + * Copyright (c) 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 FOUNDATION_DMSERVER_SCREEN_H +#define FOUNDATION_DMSERVER_SCREEN_H + +#include + +namespace OHOS::Rosen { +class Screen : public RefBase { +}; +} // namespace OHOS::Rosen +#endif // FOUNDATION_DMSERVER_SCREEN_H \ No newline at end of file diff --git a/dmserver/src/README.md b/dmserver/src/README.md new file mode 100644 index 0000000000000000000000000000000000000000..acfe633cd715263cb8c9f3795589fe28071660b5 --- /dev/null +++ b/dmserver/src/README.md @@ -0,0 +1 @@ +Store code of display manager service source files diff --git a/dmserver/src/display_info.cpp b/dmserver/src/display_info.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e26ebf2f44aa87ca28df1fddbdcafc8e37f864d8 --- /dev/null +++ b/dmserver/src/display_info.cpp @@ -0,0 +1,56 @@ +/* + * Copyright (c) 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 "display_info.h" + +namespace OHOS::Rosen { +void DisplayInfo::Update(DisplayInfo* info) +{ + id_ = info->id_; + type_ = info->type_; + width_ = info->width_; + height_ = info->height_; + freshRate_ = info->freshRate_; + xDpi_ = info->xDpi_; + yDpi_ = info->yDpi_; +} + +bool DisplayInfo::Marshalling(Parcel &parcel) const +{ + return parcel.WriteUint64(id_) && parcel.WriteUint32(type_) && + parcel.WriteInt32(width_) && parcel.WriteInt32(height_) && + parcel.WriteUint32(freshRate_) && + parcel.WriteFloat(xDpi_) && parcel.WriteFloat(yDpi_); +} + +DisplayInfo *DisplayInfo::Unmarshalling(Parcel &parcel) +{ + DisplayInfo *displayInfo = new DisplayInfo(); + if (displayInfo == nullptr) { + return nullptr; + } + uint32_t type = (uint32_t)DisplayType::DEFAULT; + bool res = parcel.ReadUint64(displayInfo->id_) && parcel.ReadUint32(type) && + parcel.ReadInt32(displayInfo->width_) && parcel.ReadInt32(displayInfo->height_) && + parcel.ReadUint32(displayInfo->freshRate_) && + parcel.ReadFloat(displayInfo->xDpi_) && parcel.ReadFloat(displayInfo->yDpi_); + if (!res) { + displayInfo = nullptr; + } else { + displayInfo->type_ = (DisplayType)type; + } + return displayInfo; +} +} // namespace OHOS::Rosen \ No newline at end of file diff --git a/dmserver/src/display_manager_proxy.cpp b/dmserver/src/display_manager_proxy.cpp new file mode 100644 index 0000000000000000000000000000000000000000..87c482a3e6d6876c5786b7c5b776f353734614c9 --- /dev/null +++ b/dmserver/src/display_manager_proxy.cpp @@ -0,0 +1,104 @@ +/* + * Copyright (c) 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 "display_manager_proxy.h" + +#include + +#include "window_manager_hilog.h" + +namespace OHOS::Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "DisplayManagerProxy"}; +} + +const sptr& DisplayManagerProxy::GetDisplayInfo(const DisplayType type) +{ + sptr remote = Remote(); + if (remote == nullptr) { + WLOGFW("get display: remote is nullptr"); + return nullptr; + } + + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!data.WriteInterfaceToken(GetDescriptor())) { + WLOGFE("get display: WriteInterfaceToken failed"); + return nullptr; + } + data.WriteInt32(static_cast(type)); + if (remote->SendRequest(TRANS_ID_GET_DISPLAY_INFO, data, reply, option) != ERR_NONE) { + WLOGFW("get display: SendRequest failed"); + return nullptr; + } + // TODO: decode reply + return nullptr; +} + +DisplayId DisplayManagerProxy::GetDefaultDisplayId() +{ + sptr remote = Remote(); + if (remote == nullptr) { + WLOGFW("GetDefaultDisplayId: remote is nullptr"); + return DISPLAY_ID_INVALD; + } + + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!data.WriteInterfaceToken(GetDescriptor())) { + WLOGFE("GetDefaultDisplayId: WriteInterfaceToken failed"); + return DISPLAY_ID_INVALD; + } + if (remote->SendRequest(TRANS_ID_GET_DEFAULT_DISPLAY_ID, data, reply, option) != ERR_NONE) { + WLOGFW("GetDefaultDisplayId: SendRequest failed"); + return DISPLAY_ID_INVALD; + } + + DisplayId displayId = reply.ReadUint64(); + WLOGFI("DisplayManagerProxy::GetDefaultDisplayId %llu", displayId); + return displayId; +} + +DisplayInfo DisplayManagerProxy::GetDisplayInfoById(DisplayId displayId) +{ + sptr remote = Remote(); + if (remote == nullptr) { + WLOGFW("GetDisplayInfoById: remote is nullptr"); + return DisplayInfo(); + } + + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!data.WriteInterfaceToken(GetDescriptor())) { + WLOGFE("GetDisplayInfoById: WriteInterfaceToken failed"); + return DisplayInfo(); + } + data.WriteUint64(static_cast(displayId)); + if (remote->SendRequest(TRANS_ID_GET_DISPLAY_BY_ID, data, reply, option) != ERR_NONE) { + WLOGFW("GetDisplayInfoById: SendRequest failed"); + return DisplayInfo(); + } + + sptr info = reply.ReadParcelable(); + if (info == nullptr) { + WLOGFW("DisplayManagerProxy::GetDisplayInfoById SendRequest nullptr."); + return DisplayInfo(); + } + return *info; +} +} // namespace OHOS::Rosen \ No newline at end of file diff --git a/dmserver/src/display_manager_service.cpp b/dmserver/src/display_manager_service.cpp new file mode 100644 index 0000000000000000000000000000000000000000..93ca0d2d6a4a53e56cdbeb91ffdb52e7f38c56aa --- /dev/null +++ b/dmserver/src/display_manager_service.cpp @@ -0,0 +1,113 @@ +/* + * Copyright (c) 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 "display_manager_service.h" + +#include +#include + +#include +#include +#include + +#include "window_manager_hilog.h" + +namespace OHOS::Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "DisplayManagerService"}; +} + +IMPLEMENT_SINGLE_INSTANCE(DisplayManagerService); + +const bool REGISTER_RESULT = + SystemAbility::MakeAndRegisterAbility(SingletonContainer::Get().GetRefPtr()); + +DisplayManagerService::DisplayManagerService() : SystemAbility(DISPLAY_MANAGER_SERVICE_SA_ID, true) +{ +} + +void DisplayManagerService::OnStart() +{ + WLOGFI("DisplayManagerService::OnStart start"); + if (!Init()) { + return; + } +} + +bool DisplayManagerService::Init() +{ + WLOGFI("DisplayManagerService::Init start"); + bool ret = Publish(this); + if (!ret) { + WLOGFW("DisplayManagerService::Init failed"); + return false; + } + displayScreenManager_ = DisplayScreenManager::GetInstance(); + if (displayScreenManager_ == nullptr) { + WLOGFW("Get DisplayScreenManager failed"); + return false; + } + WLOGFI("DisplayManagerService::Init success"); + return true; +} + +const sptr& DisplayManagerService::GetDisplayInfo(const DisplayType type) +{ + // TODO 从displayScreenMap_得到DisplayInfo + WLOGFI("DisplayManagerService::GetDisplayInfo"); + return new DisplayInfo(); +} + +DisplayId DisplayManagerService::GetDisplayIdFromScreenId(ScreenId screenId) +{ + return (DisplayId)screenId; +} + +ScreenId DisplayManagerService::GetScreenIdFromDisplayId(DisplayId displayId) +{ + return (ScreenId)displayId; +} + +DisplayId DisplayManagerService::GetDefaultDisplayId() +{ + if (displayScreenManager_ == nullptr) { + return DISPLAY_ID_INVALD; + } + ScreenId screenId = displayScreenManager_->GetDefaultScreenId(); + WLOGFI("GetDefaultDisplayId %{public}llu", screenId); + return GetDisplayIdFromScreenId(screenId); +} + +DisplayInfo DisplayManagerService::GetDisplayInfoById(DisplayId displayId) +{ + DisplayInfo displayInfo; + if (displayScreenManager_ == nullptr) { + return displayInfo; + } + ScreenId screenId = GetScreenIdFromDisplayId(displayId); + auto screenModeInfo = displayScreenManager_->GetScreenActiveMode(screenId); + displayInfo.id_ = displayId; + displayInfo.width_ = screenModeInfo.GetScreenWidth(); + displayInfo.height_ = screenModeInfo.GetScreenHeight(); + displayInfo.freshRate_ = screenModeInfo.GetScreenFreshRate(); + return displayInfo; +} + +void DisplayManagerService::OnStop() +{ + WLOGFI("ready to stop display service."); + displayScreenManager_ = nullptr; +} +} // namespace OHOS::Rosen \ No newline at end of file diff --git a/dmserver/src/display_manager_service_inner.cpp b/dmserver/src/display_manager_service_inner.cpp new file mode 100644 index 0000000000000000000000000000000000000000..61a9c3f6f868f3df191f14847fdbde83284be279 --- /dev/null +++ b/dmserver/src/display_manager_service_inner.cpp @@ -0,0 +1,89 @@ +/* + * Copyright (c) 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 "display_manager_service_inner.h" + +#include +#include + +#include +#include +#include + +#include "display_screen_manager.h" +#include "display_manager_service.h" +#include "window_manager_hilog.h" + +namespace OHOS::Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "DisplayManagerServiceInner"}; +} + +IMPLEMENT_SINGLE_INSTANCE(DisplayManagerServiceInner); + +DisplayId DisplayManagerServiceInner::GetDefaultDisplayId() +{ + auto dms = DisplayManagerService::GetInstance(); + if (dms == nullptr) { + WLOGFE("GetDefaultDisplayId null!\n"); + return DISPLAY_ID_INVALD; + } + return dms->GetDefaultDisplayId(); +} + +const sptr DisplayManagerServiceInner::GetDisplayById(DisplayId displayId) +{ + auto dms = DisplayManagerService::GetInstance(); + if (dms == nullptr) { + WLOGFE("GetDisplayById null!\n"); + return nullptr; + } + DisplayInfo displayInfo = dms->GetDisplayInfoById(displayId); + + sptr display = new DisplayScreen(displayInfo); + if (display == nullptr) { + WLOGFE("GetDisplayById failed!\n"); + return nullptr; + } + return display; +} + +const sptr DisplayManagerServiceInner::GetDefaultDisplay() +{ + return GetDisplayById(GetDefaultDisplayId()); +} + +std::vector DisplayManagerServiceInner::GetAllDisplayIds() +{ + std::vector res; + res.push_back(GetDefaultDisplayId()); + return res; +} + +std::vector> DisplayManagerServiceInner::GetAllDisplays() +{ + std::vector> res; + auto displayIds = GetAllDisplayIds(); + for (auto displayId: displayIds) { + const sptr display = GetDisplayById(displayId); + if (display != nullptr) { + res.push_back(display); + } else { + WLOGFE("GetAllDisplays display %llu nullptr!", displayId); + } + } + return res; +} +} // namespace OHOS::Rosen \ No newline at end of file diff --git a/dmserver/src/display_manager_stub.cpp b/dmserver/src/display_manager_stub.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0e065619c8ef8c51af5aa8e3dc6db07f0e6fe872 --- /dev/null +++ b/dmserver/src/display_manager_stub.cpp @@ -0,0 +1,59 @@ +/* + * Copyright (c) 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 "display_manager_stub.h" + +#include + +#include "window_manager_hilog.h" + +namespace OHOS::Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "DisplayManagerStub"}; +} + +int32_t DisplayManagerStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, + MessageOption &option) +{ + WLOGFI("OnRemoteRequest code is %{public}d", code); + if (data.ReadInterfaceToken() != GetDescriptor()) { + WLOGFE("InterfaceToken check failed"); + return -1; + } + switch (code) { + case TRANS_ID_GET_DISPLAY_INFO: { + DisplayType type = static_cast(data.ReadInt32()); + sptr info = GetDisplayInfo(type); + reply.WriteParcelable(info.GetRefPtr()); + break; + } + case TRANS_ID_GET_DEFAULT_DISPLAY_ID: { + DisplayId displayId = GetDefaultDisplayId(); + reply.WriteUint64(displayId); + break; + } + case TRANS_ID_GET_DISPLAY_BY_ID: { + DisplayId displayId = static_cast(data.ReadUint64()); + auto info = GetDisplayInfoById(displayId); + reply.WriteParcelable(&info); + break; + } + default: + WLOGFW("unknown transaction code"); + return IPCObjectStub::OnRemoteRequest(code, data, reply, option); + } + return 0; +} +} // namespace OHOS::Rosen \ No newline at end of file diff --git a/dmserver/src/display_node_control.cpp b/dmserver/src/display_node_control.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8f821aca7424aef573194937f43a09eb8439dc3c --- /dev/null +++ b/dmserver/src/display_node_control.cpp @@ -0,0 +1,19 @@ +/* + * Copyright (c) 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 "display_node_control.h" + +namespace OHOS::Rosen { +} // namespace OHOS::Rosen \ No newline at end of file diff --git a/dmserver/src/display_screen.cpp b/dmserver/src/display_screen.cpp new file mode 100644 index 0000000000000000000000000000000000000000..bbc1876a1708a3f7c781c82e9acde37b060f6a4c --- /dev/null +++ b/dmserver/src/display_screen.cpp @@ -0,0 +1,66 @@ +/* + * Copyright (c) 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 "display_screen.h" + +namespace OHOS::Rosen { +DisplayScreen::DisplayScreen(const DisplayInfo& info) + : id_(info.id_), + width_(info.width_), + height_(info.height_), + freshRate_(info.freshRate_) +{ +} + +DisplayId DisplayScreen::GetId() const +{ + return id_; +} + +int32_t DisplayScreen::GetWidth() const +{ + return width_; +} + +int32_t DisplayScreen::GetHeight() const +{ + return height_; +} + +uint32_t DisplayScreen::GetFreshRate() const +{ + return freshRate_; +} + +void DisplayScreen::SetWidth(int32_t width) +{ + width_ = width; +} + +void DisplayScreen::SetHeight(int32_t height) +{ + height_ = height; +} + +void DisplayScreen::SetFreshRate(uint32_t freshRate) +{ + freshRate_ = freshRate; +} + +void DisplayScreen::SetId(DisplayId id) +{ + id_ = id; +} +} // namespace OHOS::Rosen \ No newline at end of file diff --git a/dmserver/src/display_screen_manager.cpp b/dmserver/src/display_screen_manager.cpp new file mode 100644 index 0000000000000000000000000000000000000000..91620c7493cc2452158a5080a8ccd0385f80d1aa --- /dev/null +++ b/dmserver/src/display_screen_manager.cpp @@ -0,0 +1,51 @@ +/* + * Copyright (c) 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 "display_screen_manager.h" + +namespace OHOS::Rosen { +IMPLEMENT_SINGLE_INSTANCE(DisplayScreenManager); + +DisplayScreenManager::DisplayScreenManager() : rsInterface_(&(RSInterfaces::GetInstance())) +{ + parepareRSScreenManger(); +} + +DisplayScreenManager::~DisplayScreenManager() +{ + rsInterface_ = nullptr; +} + +void DisplayScreenManager::parepareRSScreenManger() +{ +} + +ScreenId DisplayScreenManager::GetDefaultScreenId() +{ + if (rsInterface_ == nullptr) { + return INVALID_SCREEN_ID; + } + return rsInterface_->GetDefaultScreenId(); +} + +RSScreenModeInfo DisplayScreenManager::GetScreenActiveMode(ScreenId id) +{ + RSScreenModeInfo screenModeInfo; + if (rsInterface_ == nullptr) { + return screenModeInfo; + } + return rsInterface_->GetScreenActiveMode(id); +} +} // namespace OHOS::Rosen \ No newline at end of file diff --git a/dmserver/src/rs_adapter.cpp b/dmserver/src/rs_adapter.cpp new file mode 100644 index 0000000000000000000000000000000000000000..5e5d66581dbf3064e666305cfc936108183dcf5f --- /dev/null +++ b/dmserver/src/rs_adapter.cpp @@ -0,0 +1,99 @@ +/* + * Copyright (c) 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 "rs_adapter.h" + +#include +#include +#include + +#include "window_manager_hilog.h" + +namespace OHOS::Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "RsAdapter"}; +} + +IMPLEMENT_SINGLE_INSTANCE(RsAdapter); + +bool RsAdapter::InitRSProxyLocked() +{ + WLOGFI("InitRProxy"); + if (!rsProxy_) { + sptr systemAbilityManager = + SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + if (!systemAbilityManager) { + WLOGFE("Failed to get system ability mgr."); + return false; + } + + sptr remoteObject + = systemAbilityManager->GetSystemAbility(); + if (!remoteObject) { + WLOGFE("Failed to get display manager service."); + return false; + } + + rsProxy_ = iface_cast(remoteObject); + if ((!rsProxy_) || (!rsProxy_->AsObject())) { + WLOGFE("Failed to get system display manager services"); + return false; + } + + rsDeath_ = new RSDeathRecipient(this); + if (!rsDeath_) { + WLOGFE("Failed to create death Recipient ptr RSDeathRecipient"); + return false; + } + if (!remoteObject->AddDeathRecipient(rsDeath_)) { + WLOGFE("Failed to add death recipient"); + return false; + } + } + return true; +} + +RSDeathRecipient::RSDeathRecipient(sptr& rsAdapter) +{ + rsAdatper_ = rsAdapter; +} + +void RSDeathRecipient::OnRemoteDied(const wptr& wptrDeath) +{ + if (wptrDeath == nullptr) { + WLOGFE("wptrDeath is null"); + return; + } + + sptr object = wptrDeath.promote(); + if (!object) { + WLOGFE("object is null"); + return; + } + if (rsAdapter_ != null) { + rsAdatper_.Clear(); + rsAdatper_ = nullptr; + } +} + +void RsAdapter::Clear() +{ + std::lock_guard lock(mutex_); + if ((rsProxy_ != nullptr) && (rsProxy_->AsObject() != nullptr)) { + rsProxy_->AsObject()->RemoveDeathRecipient(rsDeath_); + } + rsProxy_ = nullptr; +} +} // namespace OHOS::Rosen diff --git a/dmserver/src/screen.cpp b/dmserver/src/screen.cpp new file mode 100644 index 0000000000000000000000000000000000000000..11c222d130b9cbf29974b32080f165bd769e71ca --- /dev/null +++ b/dmserver/src/screen.cpp @@ -0,0 +1,19 @@ +/* + * Copyright (c) 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 "screen.h" + +namespace OHOS::Rosen { +} // namespace OHOS::Rosen \ No newline at end of file diff --git a/figures/graphic.png b/figures/graphic.png new file mode 100644 index 0000000000000000000000000000000000000000..b72003f5221553d66ae4b4183f92bcfcac595bc2 Binary files /dev/null and b/figures/graphic.png differ diff --git a/interfaces/innerkits/BUILD.gn b/interfaces/innerkits/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..19b84753960f4359d913ec18436188ede1b46b63 --- /dev/null +++ b/interfaces/innerkits/BUILD.gn @@ -0,0 +1,35 @@ +# Copyright (c) 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/ohos.gni") + +config("wm_interface_config") { + visibility = [ ":*" ] + include_dirs = [ "//foundation/windowmanager/interfaces/innerkits" ] +} + +ohos_shared_library("wm_interface") { + public_configs = [ ":wm_interface_config" ] + + include_dirs = [ "//foundation/windowmanager/interfaces/innerkits" ] + + public_deps = [ + "//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", + "//foundation/graphic/standard/rosen/modules/render_service_client:librender_service_client", + "//foundation/multimodalinput/input/frameworks/proxy:libmmi-client", + "//utils/native/base:utils", + ] + + part_name = "window_manager" + subsystem_name = "window" +} diff --git a/interfaces/innerkits/dm/README.md b/interfaces/innerkits/dm/README.md new file mode 100644 index 0000000000000000000000000000000000000000..bf79d111584d69930e9ec5dcb1e8e8d1015fd7a5 --- /dev/null +++ b/interfaces/innerkits/dm/README.md @@ -0,0 +1 @@ +Store code of display client out header files diff --git a/interfaces/innerkits/dm/display.h b/interfaces/innerkits/dm/display.h new file mode 100644 index 0000000000000000000000000000000000000000..64b1bac72c3843938cd2bf5765fe6972ec144127 --- /dev/null +++ b/interfaces/innerkits/dm/display.h @@ -0,0 +1,56 @@ +/* + * Copyright (c) 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 p ermissions and + * limitations under the License. + */ + +#ifndef FOUNDATION_DM_DISPLAY_H +#define FOUNDATION_DM_DISPLAY_H + +#include + +#include + +namespace OHOS::Rosen { +class DisplayInfo; +using DisplayId = uint64_t; +static constexpr DisplayId DISPLAY_ID_INVALD = -1ULL; + +typedef enum DisplayType { + DEFAULT = 0, +} DisplayType; + +class Display : public RefBase { +public: + Display(const std::string& name, DisplayInfo* info); + ~Display() = default; + + DisplayId GetId() const; + int32_t GetWidth() const; + int32_t GetHeight() const; + uint32_t GetFreshRate() const; + + void SetId(DisplayId displayId); + void SetWidth(int32_t width); + void SetHeight(int32_t height); + void SetFreshRate(uint32_t freshRate); + +private: + std::string name_; + DisplayId id_ {DISPLAY_ID_INVALD}; + int32_t width_ {0}; + int32_t height_ {0}; + uint32_t freshRate_ {0}; +}; +} // namespace OHOS::Rosen + +#endif // FOUNDATION_DM_DISPLAY_H \ No newline at end of file diff --git a/interfaces/innerkits/dm/display_manager.h b/interfaces/innerkits/dm/display_manager.h new file mode 100644 index 0000000000000000000000000000000000000000..ed91aba1d3324c2cd3a802664bd5ee07ac7cf201 --- /dev/null +++ b/interfaces/innerkits/dm/display_manager.h @@ -0,0 +1,48 @@ +/* + * Copyright (c) 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 FOUNDATION_DM_DISPLAY_MANAGER_H +#define FOUNDATION_DM_DISPLAY_MANAGER_H + +#include +#include + +#include "display.h" +#include "single_instance.h" + +namespace OHOS::Rosen { +class DisplayManagerAdapter; + +class DisplayManager : public RefBase { +DECLARE_SINGLE_INSTANCE_BASE(DisplayManager); +public: + const sptr& GetDisplay(const DisplayType type); + std::vector> GetAllDisplays(); + + DisplayId GetDefaultDisplayId(); + const sptr GetDefaultDisplay(); + + const sptr GetDisplayById(DisplayId displayId); + + std::vector GetAllDisplayIds(); + +private: + DisplayManager(); + ~DisplayManager(); + sptr dmsAdapter_; +}; +} // namespace OHOS::Rosen + +#endif // FOUNDATION_DM_DISPLAY_MANAGER_H \ No newline at end of file diff --git a/interfaces/innerkits/dm/display_property.h b/interfaces/innerkits/dm/display_property.h new file mode 100644 index 0000000000000000000000000000000000000000..7409c0d12d8f142e7e12ce354150b81d387f04e4 --- /dev/null +++ b/interfaces/innerkits/dm/display_property.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 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 FOUNDATION_DM_DISPLAY_PROPERTY_H +#define FOUNDATION_DM_DISPLAY_PROPERTY_H + +#include + +namespace OHOS::Rosen { +class DisplayProperty : public RefBase { +public: + DisplayProperty() = default; + ~DisplayProperty() = default; + + DisplayType type_; + std::string name_; + + int width_; + int height_; + float xDpi_; + float yDpi_; + // Surface surface_; +}; +} // namespace OHOS::Rosen + +#endif // FOUNDATION_DM_DISPLAY_PROPERTY_H \ No newline at end of file diff --git a/interfaces/innerkits/dm/monitor.h b/interfaces/innerkits/dm/monitor.h new file mode 100644 index 0000000000000000000000000000000000000000..0cb2b1647509a91ac75a018a971d70879186ebf3 --- /dev/null +++ b/interfaces/innerkits/dm/monitor.h @@ -0,0 +1,24 @@ +/* + * Copyright (c) 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 FOUNDATION_DM_MONITOR_H +#define FOUNDATION_DM_MONITOR_H + +namespace OHOS::Rosen { +class Monitor { +}; +} // namespace OHOS::Rosen + +#endif // FOUNDATION_DM_MONITOR_H \ No newline at end of file diff --git a/interfaces/innerkits/dmserver/README.md b/interfaces/innerkits/dmserver/README.md new file mode 100644 index 0000000000000000000000000000000000000000..24e92014b98eebf446e3a87d2b5a7b29398866ab --- /dev/null +++ b/interfaces/innerkits/dmserver/README.md @@ -0,0 +1 @@ +Store code of display server out header files diff --git a/interfaces/innerkits/wm/README.md b/interfaces/innerkits/wm/README.md new file mode 100644 index 0000000000000000000000000000000000000000..9702ea7e24e8e307993e40fa9d6b443c59d7672a --- /dev/null +++ b/interfaces/innerkits/wm/README.md @@ -0,0 +1 @@ +Store code of window client out header files diff --git a/interfaces/innerkits/wm/window.h b/interfaces/innerkits/wm/window.h new file mode 100644 index 0000000000000000000000000000000000000000..7b7d89eae0dba0f01fc89f7163a96d88215c5b24 --- /dev/null +++ b/interfaces/innerkits/wm/window.h @@ -0,0 +1,81 @@ +/* + * Copyright (c) 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 OHOS_ROSEN_WINDOW_H +#define OHOS_ROSEN_WINDOW_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include "wm_common.h" +#include "window_option.h" +#include "window_life_cycle_interface.h" + +class NativeValue; +class NativeEngine; + +namespace OHOS::AbilityRuntime { +class AbilityContext; +} + +namespace OHOS { +namespace Rosen { +class IWindowChangeListener : public RefBase { +public: + virtual void OnSizeChange(Rect rect) = 0; +}; + +class Window : public RefBase { +public: + static sptr Create(const std::string& windowName, + sptr& option, const sptr& abilityToken = nullptr); + static sptr Find(const std::string& windowName); + + virtual std::shared_ptr GetSurfaceNode() const = 0; + + virtual Rect GetRect() const = 0; + virtual WindowType GetType() const = 0; + virtual WindowMode GetMode() const = 0; + virtual const std::string& GetWindowName() const = 0; + virtual uint32_t GetWindowId() = 0; + + virtual WMError SetWindowType(WindowType type) = 0; + virtual WMError SetWindowMode(WindowMode mode) = 0; + + virtual WMError Destroy() = 0; + virtual WMError Show() = 0; + virtual WMError Hide() = 0; + + virtual WMError MoveTo(int32_t x, int32_t y) = 0; + virtual WMError Resize(uint32_t width, uint32_t height) = 0; + + virtual WMError RequestFocus() const = 0; + virtual void AddInputEventListener(std::shared_ptr& inputEventListener) = 0; // for api 7 + virtual void ConsumeKeyEvent(std::shared_ptr& inputEvent) = 0; + virtual void ConsumePointerEvent(std::shared_ptr& inputEvent) = 0; + + virtual void RegisterLifeCycleListener(sptr& listener) = 0; + virtual void RegisterWindowChangeListener(sptr& listener) = 0; + virtual WMError SetUIContent(std::shared_ptr context, + std::string& url, NativeEngine* engine, NativeValue* storage) = 0; +}; +} +} +#endif // OHOS_ROSEN_WINDOW_H diff --git a/interfaces/innerkits/wm/window_life_cycle_interface.h b/interfaces/innerkits/wm/window_life_cycle_interface.h new file mode 100644 index 0000000000000000000000000000000000000000..c9fa54b2a31bea26eb9c97cf72802c04fa9e71b3 --- /dev/null +++ b/interfaces/innerkits/wm/window_life_cycle_interface.h @@ -0,0 +1,32 @@ +/* + * Copyright (c) 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 OHOS_ROSEN_WINDOW_LIFE_CYCLE_H +#define OHOS_ROSEN_WINDOW_LIFE_CYCLE_H + +#include + +namespace OHOS { +namespace Rosen { +class IWindowLifeCycle : public RefBase { +public: + virtual void AfterForeground() = 0; + virtual void AfterBackground() = 0; + virtual void AfterFocused() = 0; + virtual void AfterUnFocused() = 0; +}; +} +} +#endif // OHOS_ROSEN_WINDOW_LIFE_CYCLE_H diff --git a/interfaces/innerkits/wm/window_option.h b/interfaces/innerkits/wm/window_option.h new file mode 100644 index 0000000000000000000000000000000000000000..9f695dae2fa222d3ccf217bfa0d3f8ab56d63c69 --- /dev/null +++ b/interfaces/innerkits/wm/window_option.h @@ -0,0 +1,63 @@ +/* + * Copyright (c) 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 OHOS_ROSEN_WINDOW_OPTION_H +#define OHOS_ROSEN_WINDOW_OPTION_H +#include +#include +#include "wm_common.h" + +namespace OHOS { +namespace Rosen { +class WindowOption : public RefBase { +public: + WindowOption(); + virtual ~WindowOption() = default; + + void SetWindowRect(const struct Rect& rect); + void SetWindowType(WindowType type); + void SetWindowMode(WindowMode mode); + void SetFocusable(bool isFocusable); + void SetTouchable(bool isTouchable); + void SetDisplayId(int32_t displayId); + void SetParentName(const std::string& parentName); + void SetWindowName(const std::string& windowName); + void AddWindowFlag(WindowFlag flag); + void RemoveWindowFlag(WindowFlag flag); + void SetWindowFlags(uint32_t flags); + + Rect GetWindowRect() const; + WindowType GetWindowType() const; + WindowMode GetWindowMode() const; + bool GetFocusable() const; + bool GetTouchable() const; + int32_t GetDisplayId() const; + const std::string& GetParentName() const; + const std::string& GetWindowName() const; + uint32_t GetWindowFlags() const; +private: + Rect windowRect_ { 0, 0, 0, 0 }; + WindowType type_ { WindowType::WINDOW_TYPE_APP_MAIN_WINDOW }; + WindowMode mode_ { WindowMode::WINDOW_MODE_FULLSCREEN }; + bool focusable_ { true }; + bool touchable_ { true }; + int32_t displayId_ { 0 }; + std::string parentName_ { "" }; + std::string windowName_ { "" }; + uint32_t flags_ { 0 }; +}; +} +} +#endif // OHOS_ROSEN_WINDOW_OPTION_H diff --git a/interfaces/innerkits/wm/window_scene.h b/interfaces/innerkits/wm/window_scene.h new file mode 100644 index 0000000000000000000000000000000000000000..dc984b01f9d773d4a610611e1ccf66babde93c7e --- /dev/null +++ b/interfaces/innerkits/wm/window_scene.h @@ -0,0 +1,57 @@ +/* + * Copyright (c) 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 INTERFACES_INNERKITS_WINDOW_SCENE_H +#define INTERFACES_INNERKITS_WINDOW_SCENE_H + +#include +#include +#include + +#include "window.h" +#include "window_option.h" + +namespace OHOS { +namespace Rosen { +class WindowScene : public RefBase { +public: + static const int32_t DEFAULT_DISPLAY_ID = 0; + static const std::string MAIN_WINDOW_ID; + + WindowScene() = default; + ~WindowScene(); + + WMError Init(int32_t displayId, std::shared_ptr& abilityContext, + sptr& listener); + + sptr CreateWindow(const std::string& windowName, sptr& option) const; + + const sptr& GetMainWindow() const; + + WMError GoForeground(); + WMError GoBackground() const; + + WMError RequestFocus() const; + +private: + static inline std::atomic count { 0 }; + sptr mainWindow_ = nullptr; + int32_t displayId_ = DEFAULT_DISPLAY_ID; + + std::shared_ptr abilityContext_ = nullptr; +}; +} // namespace Rosen +} // namespace OHOS +#endif // INTERFACES_INNERKITS_WINDOW_SCENE_H diff --git a/interfaces/innerkits/wm/wm_common.h b/interfaces/innerkits/wm/wm_common.h new file mode 100644 index 0000000000000000000000000000000000000000..cd472f88b15a46170d649a5e40ae70761e52ddaf --- /dev/null +++ b/interfaces/innerkits/wm/wm_common.h @@ -0,0 +1,96 @@ +/* + * Copyright (c) 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 OHOS_ROSEN_WM_COMMON_H +#define OHOS_ROSEN_WM_COMMON_H + +#include + +namespace OHOS { +namespace Rosen { +enum class WindowType : uint32_t { + APP_WINDOW_BASE = 1, + WINDOW_TYPE_APP_MAIN_WINDOW = APP_WINDOW_BASE, + APP_WINDOW_END = 999, + + APP_SUB_WINDOW_BASE = 1000, + WINDOW_TYPE_MEDIA = APP_SUB_WINDOW_BASE, + WINDOW_TYPE_APP_SUB_WINDOW, + APP_SUB_WINDOW_END = 1999, + + SYSTEM_WINDOW_BASE = 2000, + WINDOW_TYPE_WALLPAPER = SYSTEM_WINDOW_BASE, + ABOVE_APP_SYSTEM_WINDOW_BASE = 2100, + WINDOW_TYPE_APP_LAUNCHING, + WINDOW_TYPE_DOCK_SLICE, + WINDOW_TYPE_INCOMING_CALL, + WINDOW_TYPE_SEARCHING_BAR, + WINDOW_TYPE_SYSTEM_ALARM_WINDOW, + WINDOW_TYPE_INPUT_METHOD_FLOAT, + WINDOW_TYPE_FLOAT, + WINDOW_TYPE_TOAST, + WINDOW_TYPE_STATUS_BAR, + WINDOW_TYPE_PANEL, + WINDOW_TYPE_KEYGUARD, + WINDOW_TYPE_VOLUME_OVERLAY, + WINDOW_TYPE_NAVIGATION_BAR, + WINDOW_TYPE_DRAGGING_EFFECT, + WINDOW_TYPE_POINTER, + SYSTEM_WINDOW_END = 2999, +}; + +enum class WindowMode : uint32_t { + WINDOW_MODE_FULLSCREEN, + WINDOW_MODE_SPLIT, + WINDOW_MODE_FLOATING, + WINDOW_MODE_PIP +}; + +enum class WMError : int32_t { + WM_OK = 0, + WM_ERROR_SAMGR = 100, + WM_ERROR_IPC_FAILED = 101, + WM_ERROR_NO_MEM = 110, + WM_ERROR_NULLPTR = 120, + WM_ERROR_INVALID_PARAM = 130, + WM_ERROR_DESTROYED_OBJECT = 140, + WM_ERROR_DEATH_RECIPIENT = 150, + WM_ERROR_INVALID_WINDOW = 160, + WM_ERROR_UNKNOWN, + + /* weston adater */ + WM_ERROR_WINDOWMANAGER_GETINSTANCE = 100000, + WM_ERROR_WINDOWMANAGER_INIT = 100001, + WM_ERROR_WINDOWMANAGER_SHOW = 100002, + WM_ERROR_WINDOWMANAGER_HIDE = 100003, + WM_ERROR_WINDOWMANAGER_MOVE = 100004, + WM_ERROR_WINDOWMANAGER_RESIZE = 100005, +}; + +enum class WindowFlag : uint32_t { + WINDOW_FLAG_NEED_AVOID = 1, + WINDOW_FLAG_PARENT_LIMIT = 1 << 1, + WINDOW_FLAG_END = 1 << 2, +}; + +struct Rect { + int32_t posX_; + int32_t posY_; + uint32_t width_; + uint32_t height_; +}; +} +} +#endif // OHOS_ROSEN_WM_COMMON_H diff --git a/interfaces/innerkits/wmserver/README.md b/interfaces/innerkits/wmserver/README.md new file mode 100644 index 0000000000000000000000000000000000000000..449c0fe9fdd851fbe5f3d56ede74b9bb3a196347 --- /dev/null +++ b/interfaces/innerkits/wmserver/README.md @@ -0,0 +1 @@ +Store code of window server out header files diff --git a/interfaces/kits/README.md b/interfaces/kits/README.md new file mode 100644 index 0000000000000000000000000000000000000000..033c7c544c454719ab8ccb97c8d75305486c54a3 --- /dev/null +++ b/interfaces/kits/README.md @@ -0,0 +1 @@ +Store code of window js api diff --git a/interfaces/kits/js/declaration/BUILD.gn b/interfaces/kits/js/declaration/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..d63c1a22e0d716adef76adb82b6577df0f0e1604 --- /dev/null +++ b/interfaces/kits/js/declaration/BUILD.gn @@ -0,0 +1,29 @@ +# Copyright (c) 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/ohos.gni") + +js_declaration("window") { + sources = [ "./api" ] + + part_name = "window_manager" +} + +ohos_copy("window_declaration") { + sources = [ "./api" ] + + outputs = [ target_out_dir + "/$target_name/" ] + + module_source_dir = target_out_dir + "/$target_name" + module_install_name = "" +} diff --git a/interfaces/kits/js/declaration/api/@ohos.display.d.ts b/interfaces/kits/js/declaration/api/@ohos.display.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..17ac54ae5dab238b0214df8be4b7e55f3be58573 --- /dev/null +++ b/interfaces/kits/js/declaration/api/@ohos.display.d.ts @@ -0,0 +1,135 @@ +/* +* Copyright (c) 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. +*/ + +/** + * interface of display manager + * @devices tv, phone, tablet, wearable + */ +declare namespace display { + /** + * get the default display + * @devices tv, phone, tablet, wearable + */ + function getDefaultDisplay(): Promise; + + /** + /** + * the state of display + * @devices tv, phone, tablet, wearable + */ + enum DisplayState { + /** + * unknown + */ + STATE_UNKNOWN = 0, + /** + * screen off + */ + STATE_OFF, + /** + * screen on + */ + STATE_ON, + /** + * doze, but it will update for some important system messages + */ + STATE_DOZE, + /** + * doze and not update + */ + STATE_DOZE_SUSPEND, + /** + * VR node + */ + STATE_VR, + /** + * screen on and not update + */ + STATE_ON_SUSPEND, + } + + /** + * Properties of display, it couldn't update automatically + * @devices tv, phone, tablet, wearable + */ + interface Display { + /** + * display id + */ + id: number; + + /** + * display name + */ + name: string; + + /** + * the display is alive + */ + alive: boolean; + + /** + * the state of display + */ + state: DisplayState; + + /** + * refresh rate, unit: Hz + */ + refreshRate: number; + + /** + * the rotation degrees of the display + */ + rotation: number; + + /** + * the width of display, unit: pixel + */ + width: number; + + /** + * the height of display, unit: pixel + */ + height: number; + + /** + * indicates the display resolution. + */ + densityDPI: number; + + /** + * indicates the display density in pixels. The value of a low-resolution display is 1.0 + */ + densityPixels: number; + + /** + * indicates the text scale density of a display. + */ + scaledDensity: number; + + /** + * the DPI on X-axis. + */ + xDPI: number; + + /** + * the DPI on Y-axis. + */ + yDPI: number; + } +} + +export default display; diff --git a/interfaces/kits/js/declaration/api/@ohos.window.d.ts b/interfaces/kits/js/declaration/api/@ohos.window.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..3872e90048735e3fa1ea9da9dce0769e4ba149fb --- /dev/null +++ b/interfaces/kits/js/declaration/api/@ohos.window.d.ts @@ -0,0 +1,79 @@ +/* +* Copyright (c) 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. +*/ + +/** + * Window manager. + * @devices tv, phone, tablet, wearable. +*/ +declare namespace window { + /** + * Obtain the top window of the current application. + * @devices tv, phone, tablet, wearable. + */ + function getTopWindow(): Promise; + + /** + * The type of a window. + * @devices tv, phone, tablet, wearable. + */ + enum WindowType { + /** + * App. + */ + TYPE_APP = 0, + /** + * System alert. + */ + TYPE_SYSTEM_ALERT = 30, + /** + * System volume. + */ + TYPE_SYSTEM_VOLUME = 70, + /** + * System panel. + */ + TYPE_SYSTEM_PANEL = 90, + } + + /** + * The interface of window. + */ + interface Window { + /** + * Set the position of a window. + * @param x Indicate the X-coordinate of the window. + * @param y Indicate the Y-coordinate of the window. + * @devices tv, phone, tablet, wearable, liteWearable. + */ + moveTo(x: number, y: number): Promise; + + /** + * Set the size of a window . + * @param width Indicates the width of the window. + * @param height Indicates the height of the window. + * @devices tv, phone, tablet, wearable, liteWearable. + */ + resetSize(width: number, height: number): Promise; + + /** + * Set the type of a window. + * @param type Indicate the type of a window. + * @devices tv, phone, tablet, wearable, liteWearable. + */ + setWindowType(type: WindowType): Promise; + } +} + +export default window; diff --git a/interfaces/kits/napi/BUILD.gn b/interfaces/kits/napi/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..00c0281a28413ee05cff7e7ff7c4b94be2da7bdd --- /dev/null +++ b/interfaces/kits/napi/BUILD.gn @@ -0,0 +1,58 @@ +# Copyright (c) 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("//ark/ts2abc/ts2panda/ts2abc_config.gni") +import("//build/ohos.gni") + +ts2abc_gen_abc("gen_window_stage_abc") { + src_js = rebase_path("window_stage.js") + dst_file = rebase_path(target_out_dir + "/window_stage.abc") + in_puts = [ "window_stage.js" ] + out_puts = [ target_out_dir + "/window_stage.abc" ] + extra_args = [ "--module" ] +} + +gen_js_obj("window_stage_js") { + input = "window_stage.js" + output = target_out_dir + "/window_stage.o" +} + +gen_js_obj("window_stage_abc") { + input = get_label_info(":gen_window_stage_abc", "target_out_dir") + + "/window_stage.abc" + output = target_out_dir + "/window_stage_abc.o" + dep = ":gen_window_stage_abc" +} + +ohos_shared_library("windowstage") { + sources = [ "window_stage_module.cpp" ] + + deps = [ + ":window_stage_abc", + ":window_stage_js", + ] + + external_deps = [ "napi:ace_napi" ] + + relative_install_dir = "module/application" + + part_name = "window_manager" + subsystem_name = "window" +} + +group("napi_packages") { + deps = [ + "display:display", + "window:window", + ] +} diff --git a/interfaces/kits/napi/common/BUILD.gn b/interfaces/kits/napi/common/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..081352bd7b0e40125324ae1282ee56dea13bf13e --- /dev/null +++ b/interfaces/kits/napi/common/BUILD.gn @@ -0,0 +1,46 @@ +# Copyright (c) 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/ohos.gni") + +## Build wm_napi_common.a {{{ +config("wm_napi_common_config") { + visibility = [ ":*" ] + + cflags = [ + "-Wall", + "-Werror", + "-g3", + ] +} + +config("wm_napi_common_public_config") { + include_dirs = [ + ".", + "//third_party/node/src", + ] +} + +ohos_static_library("wm_napi_common") { + sources = [ "wm_napi_common.cpp" ] + + configs = [ ":wm_napi_common_config" ] + + public_configs = [ ":wm_napi_common_public_config" ] + + public_deps = [ + "//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog", + "//foundation/ace/napi:ace_napi", + ] +} +## Build wm_napi_common.a }}} diff --git a/interfaces/kits/napi/common/wm_napi_common.cpp b/interfaces/kits/napi/common/wm_napi_common.cpp new file mode 100644 index 0000000000000000000000000000000000000000..16b5e6ef53e5ecfd58fe299b3a1c92e3564c9ea7 --- /dev/null +++ b/interfaces/kits/napi/common/wm_napi_common.cpp @@ -0,0 +1,44 @@ +/* + * Copyright (c) 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 "wm_napi_common.h" + +#include + +namespace OHOS { +napi_status SetMemberInt32(napi_env env, napi_value result, const char *key, int32_t value) +{ + napi_value num; + GNAPI_INNER(napi_create_int32(env, value, &num)); + GNAPI_INNER(napi_set_named_property(env, result, key, num)); + return napi_ok; +} + +napi_status SetMemberUint32(napi_env env, napi_value result, const char *key, uint32_t value) +{ + napi_value num; + GNAPI_INNER(napi_create_uint32(env, value, &num)); + GNAPI_INNER(napi_set_named_property(env, result, key, num)); + return napi_ok; +} + +napi_status SetMemberUndefined(napi_env env, napi_value result, const char *key) +{ + napi_value undefined; + GNAPI_INNER(napi_get_undefined(env, &undefined)); + GNAPI_INNER(napi_set_named_property(env, result, key, undefined)); + return napi_ok; +} +} // namespace OHOS diff --git a/interfaces/kits/napi/common/wm_napi_common.h b/interfaces/kits/napi/common/wm_napi_common.h new file mode 100644 index 0000000000000000000000000000000000000000..480c511de12f56c776c31b05345df24facf900a8 --- /dev/null +++ b/interfaces/kits/napi/common/wm_napi_common.h @@ -0,0 +1,111 @@ +/* + * Copyright (c) 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 INTERFACES_KITS_NAPI_GRAPHIC_COMMON_COMMON_H +#define INTERFACES_KITS_NAPI_GRAPHIC_COMMON_COMMON_H + +#include +#include + +#include +#include +#include +#include + +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, 0, "NapiWindowManagerCommonLayer" }; + +#define GNAPI_LOG(fmt, ...) OHOS::HiviewDFX::HiLog::Info(LABEL, \ + "%{public}s:%{public}d " fmt, __func__, __LINE__, ##__VA_ARGS__) + +#define GNAPI_ASSERT(env, assertion, fmt, ...) \ + do { \ + if (assertion) { \ + GNAPI_LOG(fmt, ##__VA_ARGS__); \ + return nullptr; \ + } \ + } while (0) + +#define GNAPI_INNER(call) \ + do { \ + napi_status s = (call); \ + if (s != napi_ok) { \ + GNAPI_LOG(#call " is %{public}d", s); \ + return s; \ + } \ + } while (0) + +namespace OHOS { +napi_status SetMemberInt32(napi_env env, napi_value result, const char *key, int32_t value); +napi_status SetMemberUint32(napi_env env, napi_value result, const char *key, uint32_t value); +napi_status SetMemberUndefined(napi_env env, napi_value result, const char *key); + +template +napi_value CreatePromise(napi_env env, + std::string funcname, + void(*async)(napi_env env, std::unique_ptr& param), + napi_value(*resolve)(napi_env env, std::unique_ptr& param), + std::unique_ptr& param) +{ + struct AsyncCallbackInfo { + napi_async_work asyncWork; + napi_deferred deferred; + void (*async)(napi_env env, std::unique_ptr& param); + napi_value (*resolve)(napi_env env, std::unique_ptr& param); + std::unique_ptr param; + }; + + AsyncCallbackInfo *info = new AsyncCallbackInfo { + .async = async, + .resolve = resolve, + .param = std::move(param), + }; + + napi_value resourceName; + NAPI_CALL(env, napi_create_string_latin1(env, + funcname.c_str(), NAPI_AUTO_LENGTH, &resourceName)); + + napi_value promise; + NAPI_CALL(env, napi_create_promise(env, &info->deferred, &promise)); + + auto asyncFunc = [](napi_env env, void *data) { + AsyncCallbackInfo *info = reinterpret_cast(data); + if (info->async) { + info->async(env, info->param); + } + }; + + auto completeFunc = [](napi_env env, napi_status status, void *data) { + AsyncCallbackInfo *info = reinterpret_cast(data); + napi_value resolveValue; + if (info->resolve) { + resolveValue = info->resolve(env, info->param); + } else { + napi_get_undefined(env, &resolveValue); + } + + napi_resolve_deferred(env, info->deferred, resolveValue); + napi_delete_async_work(env, info->asyncWork); + delete info; + }; + + NAPI_CALL(env, napi_create_async_work(env, nullptr, resourceName, asyncFunc, completeFunc, + reinterpret_cast(info), &info->asyncWork)); + + NAPI_CALL(env, napi_queue_async_work(env, info->asyncWork)); + return promise; +}; +} // namespace OHOS + +#endif // INTERFACES_KITS_NAPI_GRAPHIC_COMMON_COMMON_H diff --git a/interfaces/kits/napi/display/BUILD.gn b/interfaces/kits/napi/display/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..574ecb8a1c87b32f9c8b3050e80d78af543cb53b --- /dev/null +++ b/interfaces/kits/napi/display/BUILD.gn @@ -0,0 +1,30 @@ +# Copyright (c) 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/ohos.gni") + +## Build display.so {{{ +ohos_shared_library("display") { + sources = [ "native_display_module.cpp" ] + + deps = [ + "../common:wm_napi_common", + "//foundation/windowmanager/wm:libwm", + "//foundation/windowmanager/wmserver:libwms", + ] + + relative_install_dir = "module" + part_name = "window_manager" + subsystem_name = "window" +} +## Build display.so }}} diff --git a/interfaces/kits/napi/display/native_display_module.cpp b/interfaces/kits/napi/display/native_display_module.cpp new file mode 100644 index 0000000000000000000000000000000000000000..613ffaa0de1ba0d5d4bbb117a43c5fdfffc02904 --- /dev/null +++ b/interfaces/kits/napi/display/native_display_module.cpp @@ -0,0 +1,116 @@ +/* + * Copyright (c) 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 "display_manager.h" +#include "native_display_module.h" +#include "wm_common.h" +#include "wm_napi_common.h" + +namespace OHOS { +namespace Rosen { +namespace getDefaultDisplay { +struct Param { + WMError wret; + sptr display; +}; + +void Async(napi_env env, std::unique_ptr ¶m) +{ + sptr dm = DisplayManager::GetInstance(); + if (dm == nullptr) { + GNAPI_LOG("dm error!\n"); + return; + } + + param->display = dm->GetDefaultDisplay(); + if (param->display == nullptr) { + GNAPI_LOG("Get display failed!"); + param->wret = WMError::WM_ERROR_NULLPTR; + return; + } + GNAPI_LOG("GetDefaultDisplay: id %llu, w %d, h %d", + param->display->GetId(), param->display->GetWidth(), param->display->GetHeight()); + param->wret = WMError::WM_OK; +} + +napi_value Resolve(napi_env env, std::unique_ptr ¶m) +{ + napi_value result; + if (param->wret != WMError::WM_OK) { + NAPI_CALL(env, napi_get_undefined(env, &result)); + return result; + } + + DisplayId id = param->display->GetId(); + int32_t width = param->display->GetWidth(); + int32_t height = param->display->GetHeight(); + GNAPI_LOG("id : %{public}llu", id); + GNAPI_LOG("width : %{public}d", width); + GNAPI_LOG("height : %{public}d", height); + + NAPI_CALL(env, napi_create_object(env, &result)); + NAPI_CALL(env, SetMemberInt32(env, result, "id", id)); + NAPI_CALL(env, SetMemberUndefined(env, result, "name")); + NAPI_CALL(env, SetMemberUndefined(env, result, "alive")); + NAPI_CALL(env, SetMemberUndefined(env, result, "state")); + NAPI_CALL(env, SetMemberUndefined(env, result, "refreshRate")); + NAPI_CALL(env, SetMemberUndefined(env, result, "rotation")); + NAPI_CALL(env, SetMemberUint32(env, result, "width", width)); + NAPI_CALL(env, SetMemberUint32(env, result, "height", height)); + NAPI_CALL(env, SetMemberUndefined(env, result, "densityDPI")); + NAPI_CALL(env, SetMemberUndefined(env, result, "densityPixels")); + NAPI_CALL(env, SetMemberUndefined(env, result, "scaledDensity")); + NAPI_CALL(env, SetMemberUndefined(env, result, "xDPI")); + NAPI_CALL(env, SetMemberUndefined(env, result, "yDPI")); + + return result; +} + +napi_value MainFunc(napi_env env, napi_callback_info info) +{ + GNAPI_LOG("Display Interface: getDefaultDisplay()"); + GNAPI_LOG("%{public}s called", __PRETTY_FUNCTION__); + auto param = std::make_unique(); + return CreatePromise(env, __PRETTY_FUNCTION__, Async, Resolve, param); +} +} // namespace getDefaultDisplay + +napi_value DisplayModuleInit(napi_env env, napi_value exports) +{ + GNAPI_LOG("%{public}s called", __PRETTY_FUNCTION__); + + napi_property_descriptor properties[] = { + DECLARE_NAPI_FUNCTION("getDefaultDisplay", getDefaultDisplay::MainFunc), + }; + + NAPI_CALL(env, napi_define_properties(env, + exports, sizeof(properties) / sizeof(properties[0]), properties)); + return exports; +} +} // namespace Rosen +} // namespace OHOS + +extern "C" __attribute__((constructor)) void RegisterModule(void) +{ + napi_module displayModule = { + .nm_version = 1, // NAPI v1 + .nm_flags = 0, // normal + .nm_filename = nullptr, + .nm_register_func = OHOS::Rosen::DisplayModuleInit, + .nm_modname = "display", + .nm_priv = nullptr, + }; + napi_module_register(&displayModule); +} diff --git a/interfaces/kits/napi/display/native_display_module.h b/interfaces/kits/napi/display/native_display_module.h new file mode 100644 index 0000000000000000000000000000000000000000..a24c7026abc00fa5964b264b278e9f9ba75770d1 --- /dev/null +++ b/interfaces/kits/napi/display/native_display_module.h @@ -0,0 +1,19 @@ +/* + * Copyright (c) 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 INTERFACES_KITS_NAPI_GRAPHIC_DISPLAY_NATIVE_MODULE_H +#define INTERFACES_KITS_NAPI_GRAPHIC_DISPLAY_NATIVE_MODULE_H + +#endif // INTERFACES_KITS_NAPI_GRAPHIC_DISPLAY_NATIVE_MODULE_H diff --git a/interfaces/kits/napi/window/BUILD.gn b/interfaces/kits/napi/window/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..449bfb7fb414b0ae53027a0a39827a18e469061c --- /dev/null +++ b/interfaces/kits/napi/window/BUILD.gn @@ -0,0 +1,40 @@ +# Copyright (c) 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/ohos.gni") + +## Build window.so {{{ +ohos_shared_library("window") { + sources = [ "native_window_module.cpp" ] + + configs = [ + "//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_core:bundlemgr_sdk_config", + "//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_base:appexecfwk_base_sdk_config", + "//foundation/aafwk/standard/interfaces/innerkits/want:want_public_config", + "//foundation/aafwk/standard/interfaces/innerkits/ability_manager:ability_manager_public_config", + "//foundation/aafwk/standard/services/abilitymgr:abilityms_config", + ] + + deps = [ + "../common:wm_napi_common", + "//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native", + "//foundation/appexecfwk/standard/kits:appkit_native", + "//foundation/windowmanager/wm:libwm", + "//foundation/windowmanager/wmserver:libwms", + ] + + relative_install_dir = "module" + part_name = "window_manager" + subsystem_name = "window" +} +## Build window.so }}} diff --git a/interfaces/kits/napi/window/native_window_module.cpp b/interfaces/kits/napi/window/native_window_module.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c009e2aa996ee8520d8559a3f14d39a2da37b0ec --- /dev/null +++ b/interfaces/kits/napi/window/native_window_module.cpp @@ -0,0 +1,233 @@ +/* + * Copyright (c) 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 + +#include "native_window_module.h" +#include "window.h" +#include "window_scene.h" +#include "wm_common.h" +#include "wm_napi_common.h" + +namespace OHOS { +namespace Rosen { +namespace { +napi_value g_classWindow; +napi_status GetAbility(napi_env env, napi_callback_info info, AppExecFwk::Ability* &pAbility) +{ + napi_value global; + GNAPI_INNER(napi_get_global(env, &global)); + + napi_value jsAbility; + GNAPI_INNER(napi_get_named_property(env, global, "ability", &jsAbility)); + + GNAPI_INNER(napi_get_value_external(env, jsAbility, reinterpret_cast(&pAbility))); + + return napi_ok; +} +} // namespace + + +namespace NAPIWindow { +napi_value WindowConstructor(napi_env env, napi_callback_info info) +{ + napi_value jsthis = nullptr; + NAPI_CALL(env, napi_get_cb_info(env, info, nullptr, nullptr, &jsthis, nullptr)); + return jsthis; +} + +namespace ResetSize { +struct Param { + ::OHOS::AppExecFwk::Ability *ability; + int width; + int height; +}; + +void Async(napi_env env, std::unique_ptr& param) +{ + param->ability->GetScene()->GetMainWindow()->Resize(param->width, param->height); +} + +napi_value MainFunc(napi_env env, napi_callback_info info) +{ + GNAPI_LOG("Window Interface: ResetSize()"); + GNAPI_LOG("%{public}s called", __PRETTY_FUNCTION__); + constexpr int argumentSize = 2; + size_t argc = argumentSize; + napi_value argv[argc]; + + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr)); + + GNAPI_ASSERT(env, argc < argumentSize, "ResetSize need %{public}d arguments", argumentSize); + + auto param = std::make_unique(); + NAPI_CALL(env, GetAbility(env, info, param->ability)); + NAPI_CALL(env, napi_get_value_int32(env, argv[0], ¶m->width)); + NAPI_CALL(env, napi_get_value_int32(env, argv[1], ¶m->height)); + + return CreatePromise(env, __PRETTY_FUNCTION__, Async, nullptr, param); +} +} // namespace ResetSize + +namespace MoveTo { +struct Param { + ::OHOS::AppExecFwk::Ability *ability; + int x; + int y; +}; + +void Async(napi_env env, std::unique_ptr& param) +{ + param->ability->GetScene()->GetMainWindow()->MoveTo(param->x, param->y); +} + +napi_value MainFunc(napi_env env, napi_callback_info info) +{ + GNAPI_LOG("Window Interface: MoveTo()"); + GNAPI_LOG("%{public}s called", __PRETTY_FUNCTION__); + constexpr int argumentSize = 2; + size_t argc = argumentSize; + napi_value argv[argc]; + + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr)); + + GNAPI_ASSERT(env, argc < argumentSize, "MoveTo need %{public}d arguments", argumentSize); + + auto param = std::make_unique(); + NAPI_CALL(env, GetAbility(env, info, param->ability)); + NAPI_CALL(env, napi_get_value_int32(env, argv[0], ¶m->x)); + NAPI_CALL(env, napi_get_value_int32(env, argv[1], ¶m->y)); + + return CreatePromise(env, __PRETTY_FUNCTION__, Async, nullptr, param); +} +} // namespace MoveTo + +namespace SetWindowType { +struct Param { + ::OHOS::AppExecFwk::Ability *ability; + int windowType; +}; + +void Async(napi_env env, std::unique_ptr& param) +{ + param->ability->GetScene()->GetMainWindow()->SetWindowType(static_cast(param->windowType)); +} + +void CreateWindowTypeObject(napi_env env, napi_value value) +{ + SetMemberInt32(env, value, "TYPE_APP", static_cast(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW)); + SetMemberInt32(env, value, "TYPE_SYSTEM_ALERT", static_cast(WindowType::WINDOW_TYPE_SYSTEM_ALARM_WINDOW)); + SetMemberInt32(env, value, "TYPE_SYSTEM_VOLUME", static_cast(WindowType::WINDOW_TYPE_VOLUME_OVERLAY)); + SetMemberInt32(env, value, "TYPE_SYSTEM_PANEL", static_cast(WindowType::WINDOW_TYPE_PANEL)); +} + +napi_value MainFunc(napi_env env, napi_callback_info info) +{ + GNAPI_LOG("Window Interface: SetWindowType()"); + GNAPI_LOG("%{public}s called", __PRETTY_FUNCTION__); + constexpr int argumentSize = 1; + size_t argc = argumentSize; + napi_value argv[argc]; + + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr)); + + GNAPI_ASSERT(env, argc < argumentSize, "SetWindowType need %{public}d arguments", argumentSize); + + auto param = std::make_unique(); + NAPI_CALL(env, GetAbility(env, info, param->ability)); + NAPI_CALL(env, napi_get_value_int32(env, argv[0], ¶m->windowType)); + + return CreatePromise(env, __PRETTY_FUNCTION__, Async, nullptr, param); +} +} // namespace SetWindowType +} // namespace NAPIWindow + +namespace getTopWindow { +struct Param { + ::OHOS::AppExecFwk::Ability *ability; + WMError wret; + sptr window; +}; + +void Async(napi_env env, std::unique_ptr ¶m) +{ + param->window = param->ability->GetScene()->GetMainWindow(); + if (param->window == nullptr) { + GNAPI_LOG("Get main-window failed!"); + param->wret = WMError::WM_ERROR_NULLPTR; + return; + } + param->wret = WMError::WM_OK; +} + +napi_value Resolve(napi_env env, std::unique_ptr& userdata) +{ + napi_value ret; + NAPI_CALL(env, napi_new_instance(env, g_classWindow, 0, nullptr, &ret)); + return ret; +} + +napi_value MainFunc(napi_env env, napi_callback_info info) +{ + GNAPI_LOG("Window Interface: getTopWindow()"); + GNAPI_LOG("%{public}s called", __PRETTY_FUNCTION__); + auto param = std::make_unique(); + return CreatePromise(env, __PRETTY_FUNCTION__, Async, Resolve, param); +} +} // namespace getTopWindow + +napi_value WindowModuleInit(napi_env env, napi_value exports) +{ + GNAPI_LOG("%{public}s called", __PRETTY_FUNCTION__); + + napi_value nWindowType = nullptr; + NAPI_CALL(env, napi_create_object(env, &nWindowType)); + NAPIWindow::SetWindowType::CreateWindowTypeObject(env, nWindowType); + + napi_property_descriptor desc[] = { + DECLARE_NAPI_FUNCTION("resetSize", NAPIWindow::ResetSize::MainFunc), + DECLARE_NAPI_FUNCTION("moveTo", NAPIWindow::MoveTo::MainFunc), + DECLARE_NAPI_FUNCTION("setWindowType", NAPIWindow::SetWindowType::MainFunc), + }; + + NAPI_CALL(env, napi_define_class(env, "Window", NAPI_AUTO_LENGTH, + NAPIWindow::WindowConstructor, nullptr, + sizeof(desc) / sizeof(*desc), desc, &g_classWindow)); + + napi_property_descriptor exportFuncs[] = { + DECLARE_NAPI_FUNCTION("getTopWindow", getTopWindow::MainFunc), + DECLARE_NAPI_PROPERTY("WindowType", nWindowType), + DECLARE_NAPI_PROPERTY("Window", g_classWindow), + }; + + NAPI_CALL(env, napi_define_properties(env, + exports, sizeof(exportFuncs) / sizeof(*exportFuncs), exportFuncs)); + return exports; +} +} // namespace Rosen +} // namespace OHOS + +extern "C" __attribute__((constructor)) void RegisterModule(void) +{ + napi_module windowModule = { + .nm_version = 1, // NAPI v1 + .nm_flags = 0, // normal + .nm_filename = nullptr, + .nm_register_func = OHOS::Rosen::WindowModuleInit, + .nm_modname = "window", + .nm_priv = nullptr, + }; + napi_module_register(&windowModule); +} diff --git a/interfaces/kits/napi/window/native_window_module.h b/interfaces/kits/napi/window/native_window_module.h new file mode 100644 index 0000000000000000000000000000000000000000..c4a21c440cb040305c15a5816fceba2824d6ec7d --- /dev/null +++ b/interfaces/kits/napi/window/native_window_module.h @@ -0,0 +1,19 @@ +/* + * Copyright (c) 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 INTERFACES_KITS_NAPI_GRAPHIC_WINDOW_NATIVE_WINDOW_MODULE_H +#define INTERFACES_KITS_NAPI_GRAPHIC_WINDOW_NATIVE_WINDOW_MODULE_H + +#endif // INTERFACES_KITS_NAPI_GRAPHIC_WINDOW_NATIVE_WINDOW_MODULE_H diff --git a/interfaces/kits/napi/window_stage.js b/interfaces/kits/napi/window_stage.js new file mode 100644 index 0000000000000000000000000000000000000000..43af79d1a0e23162632d56776f0ad82a123019d9 --- /dev/null +++ b/interfaces/kits/napi/window_stage.js @@ -0,0 +1,26 @@ +/* + * Copyright (c) 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. + */ + +class WindowStage { + constructor(obj) { + this.__window_stage__ = obj + } + + setUIContent(context, url, storage) { + return this.__window_stage__.setUIContent(context, url, storage) + } +} + +export default WindowStage diff --git a/interfaces/kits/napi/window_stage_module.cpp b/interfaces/kits/napi/window_stage_module.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b6ad1d3a6524d736975e43ebb38086998b678766 --- /dev/null +++ b/interfaces/kits/napi/window_stage_module.cpp @@ -0,0 +1,58 @@ +/* + * Copyright (c) 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 "native_engine/native_engine.h" + +extern const char _binary_window_stage_js_start[]; +extern const char _binary_window_stage_js_end[]; +extern const char _binary_window_stage_abc_start[]; +extern const char _binary_window_stage_abc_end[]; + +extern "C" __attribute__((constructor)) +void NAPI_application_WindowStage_AutoRegister() +{ + auto moduleManager = NativeModuleManager::GetInstance(); + NativeModule newModuleInfo = { + .name = "application.WindowStage", + .fileName = "application/libwindowstage.so/window_stage.js", + }; + + moduleManager->Register(&newModuleInfo); +} + +extern "C" __attribute__((visibility("default"))) +void NAPI_application_WindowStage_GetJSCode(const char **buf, int *bufLen) +{ + if (buf != nullptr) { + *buf = _binary_window_stage_js_start; + } + + if (bufLen != nullptr) { + *bufLen = _binary_window_stage_js_end - _binary_window_stage_js_start; + } +} + +// window_stage JS register +extern "C" __attribute__((visibility("default"))) +void NAPI_application_WindowStage_GetABCCode(const char **buf, int *buflen) +{ + if (buf != nullptr) { + *buf = _binary_window_stage_abc_start; + } + if (buflen != nullptr) { + *buflen = _binary_window_stage_abc_end - _binary_window_stage_abc_start; + } +} + diff --git a/ohos.build b/ohos.build new file mode 100644 index 0000000000000000000000000000000000000000..49aaabd0f0d5fd7588fae9c0a98ceacf02323b83 --- /dev/null +++ b/ohos.build @@ -0,0 +1,22 @@ +{ + "subsystem": "window", + "parts": { + "window_manager": { + "module_list": [ + "//foundation/windowmanager/interfaces/kits/js/declaration:window", + "//foundation/windowmanager/sa_profile:wms_sa_profile", + "//foundation/windowmanager/adapter:libwmadaptertest", + "//foundation/windowmanager/wm:libwm", + "//foundation/windowmanager/wmserver:libwms", + "//foundation/windowmanager/wm:libwmutil", + "//foundation/windowmanager/wmtest:rosenwmtest", + + "//foundation/windowmanager/interfaces/kits/napi:windowstage", + "//foundation/windowmanager/interfaces/kits/napi:napi_packages" + ], + + "test_list": [ + ] + } + } +} diff --git a/sa_profile/4605.xml b/sa_profile/4605.xml new file mode 100644 index 0000000000000000000000000000000000000000..9197521b84da4a3c388437fdcd08737748f304df --- /dev/null +++ b/sa_profile/4605.xml @@ -0,0 +1,26 @@ + + + + foundation + + 4605 + libwms.z.so + + + true + false + 1 + + \ No newline at end of file diff --git a/sa_profile/4606.xml b/sa_profile/4606.xml new file mode 100644 index 0000000000000000000000000000000000000000..7a02c334da51c72dd7275991b7f5fe9b667c4f74 --- /dev/null +++ b/sa_profile/4606.xml @@ -0,0 +1,26 @@ + + + + foundation + + 4606 + libwms.z.so + + + true + false + 1 + + diff --git a/sa_profile/BUILD.gn b/sa_profile/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..f3a586d78108d54cf5737e224b183325af25b5f7 --- /dev/null +++ b/sa_profile/BUILD.gn @@ -0,0 +1,22 @@ +# Copyright (c) 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/ohos/sa_profile/sa_profile.gni") + +ohos_sa_profile("wms_sa_profile") { + sources = [ + "4605.xml", + "4606.xml", + ] + part_name = "window_manager" +} diff --git a/utils/include/single_instance.h b/utils/include/single_instance.h new file mode 100644 index 0000000000000000000000000000000000000000..b255caf73d94d65f85c9e98eaad4207333caa372 --- /dev/null +++ b/utils/include/single_instance.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 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 OHOS_SINGLE_INSTANCE_H +#define OHOS_SINGLE_INSTANCE_H +namespace OHOS { +namespace Rosen { +#define DECLARE_SINGLE_INSTANCE_BASE(className) \ +public: \ + static sptr GetInstance(); \ +private: \ + className(const className&) = delete; \ + className& operator= (const className&) = delete; \ + className(className&&) = delete; \ + className& operator= (className&&) = delete; \ + + +#define DECLARE_SINGLE_INSTANCE(className) \ + DECLARE_SINGLE_INSTANCE_BASE(className) \ +private: \ + className() = default; \ + ~className() = default; \ + +#define IMPLEMENT_SINGLE_INSTANCE(className) \ +sptr className::GetInstance() \ +{ \ + static sptr instance = new className(); \ + return instance; \ +} +} // namespace OHOS +} +#endif // OHOS_SINGLE_INSTANCE_H diff --git a/utils/include/singleton_container.h b/utils/include/singleton_container.h new file mode 100644 index 0000000000000000000000000000000000000000..68d6d7e8ec60101761646726b6f38ec9af720958 --- /dev/null +++ b/utils/include/singleton_container.h @@ -0,0 +1,81 @@ +/* + * Copyright (c) 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 OHOS_SINGLETON_CONTAINER_H +#define OHOS_SINGLETON_CONTAINER_H + +#include +#include +#include +#include +#include + +#include + +namespace OHOS { +namespace Rosen { +class SingletonContainer : public RefBase { +public: + static sptr GetInstance(); + + void AddSingleton(const std::string &name, const std::any &instance); + void SetSingleton(const std::string &name, const std::any &instance); + const std::any &GetSingleton(const std::string &name); + const std::any &DependOn(const std::string &instance, const std::string &name); + + template + static sptr Get() + { + std::string nameT = __PRETTY_FUNCTION__; + nameT = nameT.substr(nameT.find("T = ")); + nameT = nameT.substr(sizeof("T ="), nameT.length() - sizeof("T = ")); + + using sptrT = sptr; + sptrT ret = nullptr; + const std::any &instance = SingletonContainer::GetInstance()->GetSingleton(nameT); + auto pRet = std::any_cast(&instance); + if (pRet != nullptr) { + ret = *pRet; + } + return ret; + } + + template + static void Set(const sptr &ptr) + { + std::string nameT = __PRETTY_FUNCTION__; + nameT = nameT.substr(nameT.find("T = ")); + nameT = nameT.substr(sizeof("T ="), nameT.length() - sizeof("T = ")); + + SingletonContainer::GetInstance()->SetSingleton(nameT, ptr); + } + +private: + SingletonContainer() = default; + virtual ~SingletonContainer() override; + static inline sptr instance = nullptr; + + struct Singleton { + std::any value; + int32_t refCount; + }; + std::map stringMap; + std::map singletonMap; + std::map> dependencySetMap; +}; +} // namespace Rosen +} // namespace OHOS + +#endif // FRAMEWORKS_WM_INCLUDE_SINGLETON_CONTAINER_H diff --git a/utils/include/singleton_delegator.h b/utils/include/singleton_delegator.h new file mode 100644 index 0000000000000000000000000000000000000000..dae000468f0385e443135a54846f1c6d05feefe9 --- /dev/null +++ b/utils/include/singleton_delegator.h @@ -0,0 +1,57 @@ +/* + * Copyright (c) 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 OHOS_SINGLETON_DELEGATOR_H +#define OHOS_SINGLETON_DELEGATOR_H + +#include "singleton_container.h" + +#define MOCKABLE virtual + +namespace OHOS { +namespace Rosen { +template +class SingletonDelegator { +public: + SingletonDelegator() + { + nameT = __PRETTY_FUNCTION__; + nameT = nameT.substr(nameT.find("T = ")); + nameT = nameT.substr(sizeof("T ="), nameT.length() - sizeof("T = ")); + SingletonContainer::GetInstance()->AddSingleton(nameT, T::GetInstance()); + } + ~SingletonDelegator() = default; + + template + sptr Dep() + { + std::string nameS = __PRETTY_FUNCTION__; + nameS = nameS.substr(nameS.find("S = ")); + nameS = nameS.substr(sizeof("S ="), nameS.length() - sizeof("S = ")); + + auto ret = SingletonContainer::Get(); + if (ret != nullptr) { + SingletonContainer::GetInstance()->DependOn(nameT, nameS); + } + return ret; + } + +private: + std::string nameT; +}; +} // namespace Rosen +} // namespace OHOS + +#endif // FRAMEWORKS_WM_INCLUDE_SINGLETON_DELEGATOR_H diff --git a/utils/include/static_call.h b/utils/include/static_call.h new file mode 100644 index 0000000000000000000000000000000000000000..e505d2b7aba755d5649597ec593f175261555217 --- /dev/null +++ b/utils/include/static_call.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) 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 OHOS_STATIC_CALL_H +#define OHOS_STATIC_CALL_H + +#include +#include "singleton_delegator.h" +#include "single_instance.h" +#include "window.h" +#include "window_option.h" +namespace OHOS { +namespace Rosen { +class StaticCall : public RefBase { + DECLARE_SINGLE_INSTANCE_BASE(StaticCall); +public: + virtual sptr CreateWindow(const std::string& windowName, + sptr& option, const sptr& abilityToken = nullptr); +protected: + StaticCall() = default; +private: + static inline SingletonDelegator delegator_; +}; +} // namespace ROSEN +} // namespace OHOS + +#endif // FRAMEWORKS_WM_TEST_UT_STATIC_CALL_H \ No newline at end of file diff --git a/utils/include/window_manager_hilog.h b/utils/include/window_manager_hilog.h new file mode 100644 index 0000000000000000000000000000000000000000..bf790ce8880a48f8f70b000ba8e26d293381a71a --- /dev/null +++ b/utils/include/window_manager_hilog.h @@ -0,0 +1,50 @@ +/* + * Copyright (c) 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 OHOS_WM_INCLUDE_WINDOW_MANAGER_HILOG_H +#define OHOS_WM_INCLUDE_WINDOW_MANAGER_HILOG_H + +#include "hilog/log.h" +namespace OHOS { +namespace Rosen { +static constexpr OHOS::HiviewDFX::HiLogLabel LOG_LABEL = {LOG_CORE, 0, "WindowManager"}; + +#define WLOG_F(...) (void)OHOS::HiviewDFX::HiLog::Fatal(LOG_LABEL, __VA_ARGS__) +#define WLOG_E(...) (void)OHOS::HiviewDFX::HiLog::Error(LOG_LABEL, __VA_ARGS__) +#define WLOG_W(...) (void)OHOS::HiviewDFX::HiLog::Warn(LOG_LABEL, __VA_ARGS__) +#define WLOG_I(...) (void)OHOS::HiviewDFX::HiLog::Info(LOG_LABEL, __VA_ARGS__) +#define WLOG_D(...) (void)OHOS::HiviewDFX::HiLog::Debug(LOG_LABEL, __VA_ARGS__) + +#define _W_DFUNC HiviewDFX::HiLog::Debug +#define _W_IFUNC HiviewDFX::HiLog::Info +#define _W_WFUNC HiviewDFX::HiLog::Warn +#define _W_EFUNC HiviewDFX::HiLog::Error + +#define _W_CPRINTF(func, fmt, ...) func(LABEL, "<%{public}d>" fmt, __LINE__, ##__VA_ARGS__) + +#define WLOGD(fmt, ...) _W_CPRINTF(_W_DFUNC, fmt, ##__VA_ARGS__) +#define WLOGI(fmt, ...) _W_CPRINTF(_W_IFUNC, fmt, ##__VA_ARGS__) +#define WLOGW(fmt, ...) _W_CPRINTF(_W_WFUNC, fmt, ##__VA_ARGS__) +#define WLOGE(fmt, ...) _W_CPRINTF(_W_EFUNC, fmt, ##__VA_ARGS__) + +#define _W_FUNC __func__ + +#define WLOGFD(fmt, ...) WLOGD("%{public}s: " fmt, _W_FUNC, ##__VA_ARGS__) +#define WLOGFI(fmt, ...) WLOGI("%{public}s: " fmt, _W_FUNC, ##__VA_ARGS__) +#define WLOGFW(fmt, ...) WLOGW("%{public}s: " fmt, _W_FUNC, ##__VA_ARGS__) +#define WLOGFE(fmt, ...) WLOGE("%{public}s: " fmt, _W_FUNC, ##__VA_ARGS__) +} // namespace OHOS +} +#endif // FRAMEWORKS_WM_INCLUDE_WINDOW_MANAGER_HILOG_H diff --git a/utils/src/singleton_container.cpp b/utils/src/singleton_container.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0b851fdae250c59a4b7fc65bf13f346d042c7bb7 --- /dev/null +++ b/utils/src/singleton_container.cpp @@ -0,0 +1,110 @@ +/* + * Copyright (c) 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 "singleton_container.h" +#include +#include "window_manager_hilog.h" + +namespace OHOS { +namespace Rosen { +namespace { +constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "WindowManager_SingletonContainer"}; +} // namespace + +sptr SingletonContainer::GetInstance() +{ + if (instance == nullptr) { + static std::mutex mutex; + std::lock_guard lock(mutex); + if (instance == nullptr) { + instance = new SingletonContainer(); + } + } + return instance; +} + +SingletonContainer::~SingletonContainer() +{ + while (singletonMap.empty() == false) { + auto it = singletonMap.begin(); + while (it != singletonMap.end()) { + if (it->second.refCount > 0) { + it++; + continue; + } + + if (dependencySetMap.find(it->first) != dependencySetMap.end()) { + for (auto mid : dependencySetMap[it->first]) { + singletonMap[mid].refCount--; + } + dependencySetMap.erase(it->first); + } + + for (const auto &[k, v] : stringMap) { + if (v == it->first) { + WLOGFD("remove %{public}s", k.c_str()); + break; + } + } + singletonMap.erase(it++); + } + } +} + +void SingletonContainer::AddSingleton(const std::string &name, const std::any &instance) +{ + if (stringMap.find(name) == stringMap.end()) { + static int32_t nextId = 0; + singletonMap[nextId].value = instance; + singletonMap[nextId].refCount = 0; + WLOGFD("add %{public}s", name.c_str()); + stringMap[name] = nextId++; + } else { + WLOGFE("add failed: %{public}s", name.c_str()); + } +} + +void SingletonContainer::SetSingleton(const std::string &name, const std::any &instance) +{ + if (stringMap.find(name) == stringMap.end()) { + AddSingleton(name, instance); + } else { + WLOGFD("set %{public}s", name.c_str()); + singletonMap[stringMap[name]].value = instance; + } +} + +const std::any &SingletonContainer::GetSingleton(const std::string &name) +{ + if (stringMap.find(name) == stringMap.end()) { + WLOGFD("cannot get %{public}s", name.c_str()); + static std::any voidAny; + return voidAny; + } + return singletonMap[stringMap[name]].value; +} + +const std::any &SingletonContainer::DependOn(const std::string &instance, const std::string &name) +{ + auto &instanceDependencySet = dependencySetMap[stringMap[instance]]; + if (instanceDependencySet.find(stringMap[name]) == instanceDependencySet.end()) { + WLOGFD("%{public}s dependon %{public}s", instance.c_str(), name.c_str()); + instanceDependencySet.insert(stringMap[name]); + singletonMap[stringMap[name]].refCount++; + } + return GetSingleton(name); +} +} // namespace Rosen +} // namespace OHOS diff --git a/utils/src/static_call.cpp b/utils/src/static_call.cpp new file mode 100644 index 0000000000000000000000000000000000000000..5b8797a3b166161f559f06339418113c8469df98 --- /dev/null +++ b/utils/src/static_call.cpp @@ -0,0 +1,28 @@ +/* + * Copyright (c) 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 "static_call.h" + +namespace OHOS { +namespace Rosen { +IMPLEMENT_SINGLE_INSTANCE(StaticCall); + +sptr StaticCall::CreateWindow(const std::string& windowName, + sptr& option, const sptr& abilityToken) +{ + return Window::Create(windowName, option, abilityToken); +} +} // namespace Rosen +} // namespace OHOS \ No newline at end of file diff --git a/wm/BUILD.gn b/wm/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..a517968506f142873b301717c63dbc94d2715c82 --- /dev/null +++ b/wm/BUILD.gn @@ -0,0 +1,161 @@ +# Copyright (c) 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/ohos.gni") + +config("libwm_config") { + visibility = [ ":*" ] + + include_dirs = [ + "include", + "//utils/system/safwk/native/include", + "//foundation/windowmanager/wmserver/include", + "//foundation/windowmanager/dm/include", + "//foundation/windowmanager/dmserver/include", + "//foundation/windowmanager/utils/include", + + # for abilityContext + "//foundation/aafwk/standard/frameworks/kits/ability/ability_runtime/include", + "//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_base/include", + "//base/global/resmgr_standard/interfaces/innerkits/include", + "//third_party/node/deps/icu-small/source/common", + "//foundation/aafwk/standard/interfaces/innerkits/ability_manager/include", + "//foundation/aafwk/standard/interfaces/innerkits/want/include/ohos/aafwk/content", + "//foundation/distributedschedule/dmsfwk/services/dtbschedmgr/include", + "//foundation/aafwk/standard/interfaces/innerkits/base/include", + + # abilityContext end + + # weston adapter + "//foundation/windowmanager/adapter/include", + "//foundation/graphic/standard/interfaces/innerkits", + "//foundation/graphic/standard/interfaces/innerkits/wm", + "//foundation/graphic/standard/interfaces/innerkits/common", + + # weston adapter end + ] + + cflags = [ + "-Wall", + "-Werror", + "-g3", + ] +} + +config("libwm_public_config") { + include_dirs = [ + "//foundation/windowmanager/interfaces/innerkits/wm", + "//foundation/windowmanager/wmserver/include", + "//foundation/windowmanager/dmserver/include", + "//foundation/windowmanager/utils/include", + "../interfaces/innerkits/dm", + ] +} + +## Build libwmutil.so +ohos_shared_library("libwmutil") { + sources = [ + "../dmserver/src/display_info.cpp", + "//foundation/windowmanager/dmserver/src/display_manager_proxy.cpp", + "//foundation/windowmanager/utils/src/singleton_container.cpp", + "//foundation/windowmanager/wm/src/window_proxy.cpp", + "//foundation/windowmanager/wmserver/src/window_manager_proxy.cpp", + "src/window_option.cpp", + "src/window_property.cpp", + ] + + configs = [ ":libwm_config" ] + + public_configs = [ ":libwm_public_config" ] + + deps = [ + "//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog", + "//utils/native/base:utils", + ] + + public_deps = [ + # RSSurface + "//foundation/graphic/standard/rosen/modules/render_service_base:librender_service_base", + "//foundation/graphic/standard/rosen/modules/render_service_client:librender_service_client", + ] + + external_deps = [ "ipc:ipc_core" ] + + part_name = "window_manager" + subsystem_name = "window" +} + +## Build libwm.so +ohos_shared_library("libwm") { + sources = [ + "../dm/src/display.cpp", + "../dm/src/display_manager.cpp", + "../dm/src/display_manager_adapter.cpp", + "../dm/src/monitor.cpp", + "../utils/src/static_call.cpp", + "src/input_transfer_station.cpp", + "src/vsync_station.cpp", + "src/window.cpp", + "src/window_adapter.cpp", + "src/window_agent.cpp", + "src/window_impl.cpp", + "src/window_input_channel.cpp", + "src/window_scene.cpp", + "src/window_stub.cpp", + ] + + configs = [ ":libwm_config" ] + + public_configs = [ ":libwm_public_config" ] + + deps = [ + "//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog", + "//foundation/aafwk/standard/interfaces/innerkits/want:want", + "//foundation/distributedschedule/safwk/interfaces/innerkits/safwk:system_ability_fwk", + "//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", + "//foundation/windowmanager/wm:libwmutil", + "//utils/native/base:utils", + + # weston adapter + "//foundation/windowmanager/adapter:libwmadaptertest", + + # ace + "//foundation/ace/ace_engine/interfaces/innerkits/ace:ace_uicontent", + ] + + public_deps = [ + # native value + # RSSurface + "//foundation/ace/napi:ace_napi", + + # vsync + "//foundation/graphic/standard:libvsync_client", + "//foundation/graphic/standard/rosen/modules/render_service_base:librender_service_base", + "//foundation/graphic/standard/rosen/modules/render_service_client:librender_service_client", + + # IMS + "//foundation/multimodalinput/input/frameworks/proxy:libmmi-client", + "//foundation/multimodalinput/input/frameworks/proxy:libmmi-common", + + # weston adapter + "//foundation/windowmanager/adapter:libwmadaptertest", + ] + + external_deps = [ + "aafwk_standard:ability_context_native", + "ipc:ipc_core", + ] + + part_name = "window_manager" + subsystem_name = "window" +} diff --git a/wm/include/README.md b/wm/include/README.md new file mode 100644 index 0000000000000000000000000000000000000000..f0321dc5d0e30b1a50abc177befda0f70cb81358 --- /dev/null +++ b/wm/include/README.md @@ -0,0 +1 @@ +Store code of window client inner header files diff --git a/wm/include/input_transfer_station.h b/wm/include/input_transfer_station.h new file mode 100644 index 0000000000000000000000000000000000000000..5c8fa1466fa3733fda488952225800566cc4b2ad --- /dev/null +++ b/wm/include/input_transfer_station.h @@ -0,0 +1,55 @@ +/* + * Copyright (c) 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 OHOS_INPUT_TRANSFER_STATION +#define OHOS_INPUT_TRANSFER_STATION + + +#include +#include +#include "input_manager.h" +#include "pointer_event.h" +#include "window.h" +#include "window_input_channel.h" +#include "vsync_station.h" + +namespace OHOS { +namespace Rosen { +class InputEventListener; +class InputTransferStation : public RefBase { +DECLARE_SINGLE_INSTANCE(InputTransferStation); +friend class InputEventListener; +public: + void AddInputWindow(const sptr& window); + void RemoveInputWindow(const sptr& window); + void SetInputListener(uint32_t windowId, std::shared_ptr& listener); +private: + sptr GetInputChannel(uint32_t windowId); + bool initInputListener_ = false; + std::unordered_map> windowInputChannels_; + std::shared_ptr inputListener_; +}; +class InputEventListener: public RefBase, public MMI::IInputEventConsumer { +public: + InputEventListener() = default; + void OnInputEvent(std::shared_ptr pointerEvent) const override; + void OnInputEvent(std::shared_ptr keyEvent) const override; + void OnInputEvent(std::shared_ptr axisEvent) const override; +}; +} +} + + +#endif // OHOS_INPUT_TRANSFER_STATION diff --git a/wm/include/vsync_station.h b/wm/include/vsync_station.h new file mode 100644 index 0000000000000000000000000000000000000000..eba3a26caf4b038270233b5aa7cc8e1d0c927d5a --- /dev/null +++ b/wm/include/vsync_station.h @@ -0,0 +1,59 @@ +/* + * Copyright (c) 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 OHOS_VSYNC_STATION_H +#define OHOS_VSYNC_STATION_H + +#include +#include +#include +#include +#include + +#include +#include + +#include "single_instance.h" + +namespace OHOS { +namespace Rosen { +class VsyncStation : public RefBase { +DECLARE_SINGLE_INSTANCE_BASE(VsyncStation); +using OnCallback = std::function; +public: + enum class CallbackType { + CALLBACK_INPUT = 0, + CALLBACK_FRAME = 1, + }; + struct VsyncCallback { + OnCallback onCallback; + }; + ~VsyncStation() = default; + void RequestVsync(CallbackType type, std::shared_ptr vsyncCallback); + +private: + FrameCallback callback_; + VsyncStation() = default; + static void OnVsync(int64_t nanoTimestamp, void* client); + void VsyncCallbackInner(int64_t nanoTimestamp); + std::atomic_bool hasRequestedVsync_ {false}; + std::map>> vsyncCallbacks_ = { + {CallbackType::CALLBACK_INPUT, {}}, + {CallbackType::CALLBACK_FRAME, {}}, + }; +}; +} // namespace Rosen +} // namespace OHOS +#endif // OHOS_VSYNC_STATION_H \ No newline at end of file diff --git a/wm/include/window_adapter.h b/wm/include/window_adapter.h new file mode 100644 index 0000000000000000000000000000000000000000..49ca563360fb9356485d8b259b79331d7fae6dbc --- /dev/null +++ b/wm/include/window_adapter.h @@ -0,0 +1,61 @@ +/* + * Copyright (c) 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 OHOS_WINDOW_ADAPTER_H +#define OHOS_WINDOW_ADAPTER_H + +#include + +#include "window.h" +#include "window_proxy.h" +#include "single_instance.h" +#include "singleton_delegator.h" +#include "window_property.h" +#include "window_manager_interface.h" +namespace OHOS { +namespace Rosen { +class WMSDeathRecipient : public IRemoteObject::DeathRecipient { +public: + virtual void OnRemoteDied(const wptr& wptrDeath) override; +}; + +class WindowAdapter : public RefBase { + DECLARE_SINGLE_INSTANCE_BASE(WindowAdapter); +public: + ~WindowAdapter() = default; + virtual WMError CreateWindow(sptr& window, sptr& windowProperty, + std::shared_ptr surfaceNode, uint32_t& windowId); + virtual WMError AddWindow(sptr& windowProperty); + virtual WMError RemoveWindow(uint32_t windowId); + virtual WMError DestroyWindow(uint32_t windowId); + virtual WMError SaveAbilityToken(const sptr& abilityToken, uint32_t windowId); + virtual WMError MoveTo(uint32_t windowId, int32_t x, int32_t y); + virtual WMError Resize(uint32_t windowId, uint32_t width, uint32_t height); + virtual WMError RequestFocus(uint32_t windowId); + + virtual void ClearWindowAdapter(); +protected: + WindowAdapter() = default; +private: + static inline SingletonDelegator delegator; + bool InitWMSProxyLocked(); + + std::mutex mutex_; + sptr windowManagerServiceProxy_ = nullptr; + sptr wmsDeath_ = nullptr; +}; +} // namespace Rosen +} // namespace OHOS +#endif // OHOS_WINDOW_ADAPTER_H diff --git a/wm/include/window_agent.h b/wm/include/window_agent.h new file mode 100644 index 0000000000000000000000000000000000000000..31bd1ccd4b41deea54d6d0291044660fdbdbe808 --- /dev/null +++ b/wm/include/window_agent.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) 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 OHOS_WINDOW_AGENT_H +#define OHOS_WINDOW_AGENT_H + +#include "window_stub.h" +#include "window_impl.h" +#include "window_property.h" + +namespace OHOS { +namespace Rosen { +class WindowAgent : public WindowStub { +public: + WindowAgent(sptr& window); + ~WindowAgent() = default; + void UpdateWindowProperty(const WindowProperty& windowProperty) override; + void UpdateWindowRect(const struct Rect& rect) override; + void UpdateWindowMode(WindowMode mode) override; + void UpdateFocusStatus(bool focused) override; + +private: + sptr window_; +}; +} // namespace Rosen +} // namespace OHOS +#endif // OHOS_WINDOW_AGENT_H diff --git a/wm/include/window_impl.h b/wm/include/window_impl.h new file mode 100644 index 0000000000000000000000000000000000000000..17766e3f105bbffe6812bcd7dc21c28405f31e0b --- /dev/null +++ b/wm/include/window_impl.h @@ -0,0 +1,122 @@ +/* + * Copyright (c) 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 OHOS_ROSEN_WINDOW_IMPL_H +#define OHOS_ROSEN_WINDOW_IMPL_H +#include +#include +#include +#include +#include "window.h" +#include "input_transfer_station.h" +#include "window_property.h" + +namespace OHOS { +namespace Rosen { +class WindowImpl : public Window { +#define CALL_LIFECYCLE_LISTENER(windowLifecycleCb, uiContentCb) \ + do { \ + if (lifecycleListener_ != nullptr) { \ + lifecycleListener_->windowLifecycleCb(); \ + } \ + if (uiContent_ != nullptr) { \ + uiContent_->uiContentCb(); \ + } \ + } while (0); + +public: + WindowImpl(const sptr& option); + ~WindowImpl(); + + static sptr Find(const std::string& id); + + virtual std::shared_ptr GetSurfaceNode() const override; + virtual Rect GetRect() const override; + virtual WindowType GetType() const override; + virtual WindowMode GetMode() const override; + virtual const std::string& GetWindowName() const override; + virtual uint32_t GetWindowId() override; + virtual WMError SetWindowType(WindowType type) override; + virtual WMError SetWindowMode(WindowMode mode) override; + + WMError Create(const std::string& parentName, const sptr& abilityToken = nullptr); + virtual WMError Destroy() override; + virtual WMError Show() override; + virtual WMError Hide() override; + virtual WMError MoveTo(int32_t x, int32_t y) override; + virtual WMError Resize(uint32_t width, uint32_t height) override; + + virtual WMError RequestFocus() const override; + virtual void AddInputEventListener(std::shared_ptr& inputEventListener) override; + + virtual void RegisterLifeCycleListener(sptr& listener) override; + virtual void RegisterWindowChangeListener(sptr& listener) override; + + void UpdateRect(const struct Rect& rect); + void UpdateMode(WindowMode mode); + virtual void ConsumeKeyEvent(std::shared_ptr& inputEvent) override; + virtual void ConsumePointerEvent(std::shared_ptr& inputEvent) override; + void UpdateFocusStatus(bool focused); + + virtual WMError SetUIContent(std::shared_ptr context, + std::string& url, NativeEngine* engine, NativeValue* storage) override; + +private: + inline void NotifyAfterForeground() const + { + CALL_LIFECYCLE_LISTENER(AfterForeground, Foreground); + } + inline void NotifyAfterBackground() const + { + CALL_LIFECYCLE_LISTENER(AfterBackground, Background); + } + inline void NotifyAfterFocused() const + { + CALL_LIFECYCLE_LISTENER(AfterFocused, Focus); + } + inline void NotifyAfterUnFocused() const + { + CALL_LIFECYCLE_LISTENER(AfterUnFocused, UnFocus); + } + inline void NotifyBeforeDestroy() const + { + if (uiContent_ != nullptr) { + uiContent_->Destroy(); + } + } + void SetDefaultOption(); // for api7 + bool IsWindowValid() const; + + enum WindowState { + STATE_INITIAL, + STATE_CREATED, + STATE_SHOWN, + STATE_HIDDEN, + STATE_DESTROYED, + STATE_BOTTOM = STATE_DESTROYED, + }; + + static std::map>> windowMap_; + sptr property_; + WindowState state_ { STATE_INITIAL }; + sptr lifecycleListener_; + sptr windowChangeListener_; + std::shared_ptr surfaceNode_; + std::string name_; + std::unique_ptr uiContent_; +}; +} +} +#endif // OHOS_ROSEN_WINDOW_IMPL_H diff --git a/wm/include/window_input_channel.h b/wm/include/window_input_channel.h new file mode 100644 index 0000000000000000000000000000000000000000..fb700a1d5464032c5d913eb3d82783ce53f580fe --- /dev/null +++ b/wm/include/window_input_channel.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 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 +#include "refbase.h" +#include "vsync_station.h" +#ifndef OHOS_WINDOW_INPUT_CHANNEL +#define OHOS_WINDOW_INPUT_CHANNEL + +namespace OHOS { +namespace Rosen { +class WindowInputChannel : public RefBase { +public: + WindowInputChannel(const sptr& window); + ~WindowInputChannel() = default; + void HandlePointerEvent(std::shared_ptr& pointerEvent); + void HandleKeyEvent(std::shared_ptr& keyEvent); + void SetInputListener(std::shared_ptr& listener); +private: + void OnVsync(int64_t timeStamp); + std::vector> pointerEventPool_; + sptr window_; + std::shared_ptr callback_ = + std::make_shared(VsyncStation::VsyncCallback()); + static const int32_t MAX_INPUT_NUM = 100; + std::shared_ptr inputListener_; +}; +} +} + + +#endif // OHOS_WINDOW_INPUT_CHANNEL diff --git a/wm/include/window_interface.h b/wm/include/window_interface.h new file mode 100644 index 0000000000000000000000000000000000000000..846ded865285ddb6bf00841e5411b64335fd3911 --- /dev/null +++ b/wm/include/window_interface.h @@ -0,0 +1,42 @@ +/* + * Copyright (c) 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 OHOS_WINDOW_INTERFACE_H +#define OHOS_WINDOW_INTERFACE_H + +#include "iremote_broker.h" +#include "window_property.h" + +namespace OHOS { +namespace Rosen { +class IWindow : public IRemoteBroker { +public: + DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.IWindow"); + + enum { + TRANS_ID_UPDATE_WINDOW_PROPERTY = 1, + TRANS_ID_UPDATE_WINDOW_RECT, + TRANS_ID_UPDATE_WINDOW_MODE, + TRANS_ID_UPDATE_FOCUS_STATUS, + }; + + virtual void UpdateWindowProperty(const WindowProperty& windowProperty) = 0; + virtual void UpdateWindowRect(const struct Rect& rect) = 0; + virtual void UpdateWindowMode(WindowMode mode) = 0; + virtual void UpdateFocusStatus(bool focused) = 0; +}; +} // namespace Rosen +} // namespace OHOS +#endif // OHOS_WINDOW_INTERFACE_H diff --git a/wm/include/window_property.h b/wm/include/window_property.h new file mode 100644 index 0000000000000000000000000000000000000000..f8b9ed4ca0d6fa47458baeec987794856c72559d --- /dev/null +++ b/wm/include/window_property.h @@ -0,0 +1,79 @@ +/* + * Copyright (c) 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 OHOS_ROSEN_WINDOW_PROPERTY_H +#define OHOS_ROSEN_WINDOW_PROPERTY_H + +#include +#include +#include "parcel.h" +#include "wm_common.h" + +namespace OHOS { +namespace Rosen { +class WindowProperty : public Parcelable { +public: + WindowProperty() = default; + ~WindowProperty() = default; + + void SetWindowRect(const struct Rect& rect); + void SetWindowType(WindowType type); + void SetWindowMode(WindowMode mode); + void SetFullScreen(bool isFullScreen); + void SetFocusable(bool isFocusable); + void SetTouchable(bool isTouchable); + void SetPrivacyMode(bool isPrivate); + void SetTransparent(bool isTransparent); + void SetAlpha(float alpha); + void SetDisplayId(int32_t displayId); + void SetWindowId(uint32_t windowId); + void SetParentId(uint32_t parentId); + void SetWindowFlags(uint32_t flags); + + Rect GetWindowRect() const; + WindowType GetWindowType() const; + WindowMode GetWindowMode() const; + bool GetFullScreen() const; + bool GetFocusable() const; + bool GetTouchable() const; + bool GetPrivacyMode() const; + bool GetTransparent() const; + float GetAlpha() const; + int32_t GetDisplayId() const; + uint32_t GetWindowId() const; + uint32_t GetParentId() const; + uint32_t GetWindowFlags() const; + + virtual bool Marshalling(Parcel& parcel) const override; + static sptr Unmarshalling(Parcel& parcel); + +private: + Rect windowRect_ { 0, 0, 0, 0 }; + WindowType type_ { WindowType::WINDOW_TYPE_APP_MAIN_WINDOW }; + WindowMode mode_ { WindowMode::WINDOW_MODE_FULLSCREEN }; + uint32_t flags_ { 0 }; + bool isFullScreen_ { true }; + bool focusable_ { true }; + bool touchable_ { true }; + bool isPrivacyMode_ { false }; + bool isTransparent_ { false }; + float alpha_ { 1.0f }; + int32_t displayId_ { 0 }; + uint32_t windowId_ { 0 }; + uint32_t parentId_ { 0 }; +}; +} +} +#endif // OHOS_ROSEN_WINDOW_PROPERTY_H diff --git a/wm/include/window_proxy.h b/wm/include/window_proxy.h new file mode 100644 index 0000000000000000000000000000000000000000..8e1ea4a52e6aa791451abb05dd5f1dcaf4c8618e --- /dev/null +++ b/wm/include/window_proxy.h @@ -0,0 +1,40 @@ +/* + * Copyright (c) 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 OHOS_WINDOW_PROXY_H +#define OHOS_WINDOW_PROXY_H + +#include "window_interface.h" +#include "iremote_proxy.h" + +namespace OHOS { +namespace Rosen { +class WindowProxy : public IRemoteProxy { +public: + explicit WindowProxy(const sptr& impl) : IRemoteProxy(impl) {}; + + ~WindowProxy() {}; + + void UpdateWindowProperty(const WindowProperty& windowProperty) override; + void UpdateWindowRect(const struct Rect& rect) override; + void UpdateWindowMode(WindowMode mode) override; + void UpdateFocusStatus(bool focused) override; + +private: + static inline BrokerDelegator delegator_; +}; +} // namespace Rosen +} // namespace OHOS +#endif // OHOS_WINDOW_PROXY_H diff --git a/wm/include/window_stub.h b/wm/include/window_stub.h new file mode 100644 index 0000000000000000000000000000000000000000..efc29d3b5081f72df4dd93873e6b03d4a598a5aa --- /dev/null +++ b/wm/include/window_stub.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 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 OHOS_WINDOW_STUB_H +#define OHOS_WINDOW_STUB_H + +#include "window_interface.h" +#include "iremote_stub.h" + +namespace OHOS { +namespace Rosen { +class WindowStub : public IRemoteStub { +public: + WindowStub() = default; + ~WindowStub() = default; + + virtual int OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, + MessageOption &option) override; +}; +} // namespace Rosen +} // namespace OHOS +#endif // OHOS_WINDOW_STUB_H diff --git a/wm/src/README.md b/wm/src/README.md new file mode 100644 index 0000000000000000000000000000000000000000..2a99b4a2c9cf32ca8a28ce0857c95758c2cbde42 --- /dev/null +++ b/wm/src/README.md @@ -0,0 +1 @@ +Store code of window client source files diff --git a/wm/src/input_transfer_station.cpp b/wm/src/input_transfer_station.cpp new file mode 100644 index 0000000000000000000000000000000000000000..43adc731bc68971b9c7203896bcd3bf78d55e693 --- /dev/null +++ b/wm/src/input_transfer_station.cpp @@ -0,0 +1,114 @@ +/* + * Copyright (c) 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_transfer_station.h" +#include + +namespace OHOS { +namespace Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "InputTransferStation"}; +} +IMPLEMENT_SINGLE_INSTANCE(InputTransferStation) +void InputEventListener::OnInputEvent(std::shared_ptr keyEvent) const +{ + WLOGFI("OnInputEvent: receive keyEvent"); + if (keyEvent == nullptr) { + WLOGE("OnInputEvent receive KeyEvent is nullptr"); + return; + } + uint32_t windowId = keyEvent->GetAgentWindowId(); + auto channel = InputTransferStation::GetInstance()->GetInputChannel(windowId); + if (channel == nullptr) { + WLOGE("OnInputEvent channel is nullptr"); + return; + } + channel->HandleKeyEvent(keyEvent); +} + +void InputEventListener::OnInputEvent(std::shared_ptr axisEvent) const +{ + WLOGFI("OnInputEvent: receive axisEvent"); + if (axisEvent == nullptr) { + WLOGE("OnInputEvent receive axisEvent is nullptr"); + return; + } + axisEvent->MarkProcessed(); +} + +void InputEventListener::OnInputEvent(std::shared_ptr pointerEvent) const +{ + WLOGFI("OnInputEvent: receive pointerEvent"); + if (pointerEvent == nullptr) { + WLOGE("OnInputEvent receive pointerEvent is nullptr"); + return; + } + uint32_t windowId = pointerEvent->GetAgentWindowId(); + auto channel = InputTransferStation::GetInstance()->GetInputChannel(windowId); + if (channel == nullptr) { + WLOGE("OnInputEvent channel is nullptr"); + return; + } + channel->HandlePointerEvent(pointerEvent); +} + +void InputTransferStation::AddInputWindow(const sptr& window) +{ + WLOGFI("AddInputWindow: add window"); + uint32_t windowId = window->GetWindowId(); + sptr inputChannel = new WindowInputChannel(window); + windowInputChannels_.insert(std::make_pair(windowId, inputChannel)); + if (!initInputListener_) { + WLOGFI("init input listener"); + std::shared_ptr listener = std::make_shared(InputEventListener()); + MMI::InputManager::GetInstance()->SetWindowInputEventConsumer(listener); + inputListener_ = listener; + initInputListener_ = true; + } +} + +void InputTransferStation::RemoveInputWindow(const sptr& window) +{ + WLOGFI("RemoveInputWindow: remove window"); + uint32_t windowId = window->GetWindowId(); + auto iter = windowInputChannels_.find(windowId); + if (iter != windowInputChannels_.end()) { + windowInputChannels_.erase(windowId); + } else { + WLOGE("RemoveInputWindow do not find windowId: %{public}d", windowId); + } +} + +void InputTransferStation::SetInputListener(uint32_t windowId, std::shared_ptr &listener) +{ + auto channel = GetInputChannel(windowId); + if (channel == nullptr) { + WLOGE("SetInputListener channel is nullptr"); + return; + } + channel->SetInputListener(listener); +} + +sptr InputTransferStation::GetInputChannel(uint32_t windowId) +{ + auto iter = windowInputChannels_.find(windowId); + if (iter == windowInputChannels_.end()) { + WLOGE("GetInputChannel do not find channel according to windowId: %{public}d", windowId); + return nullptr; + } + return iter->second; +} +} +} diff --git a/wm/src/vsync_station.cpp b/wm/src/vsync_station.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4cc44398270977ea9fbb6e77b86547e007e5056b --- /dev/null +++ b/wm/src/vsync_station.cpp @@ -0,0 +1,69 @@ +/* + * Copyright (c) 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 + +#include "window_manager_hilog.h" + +namespace OHOS { +namespace Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "VsyncStation"}; +} + +IMPLEMENT_SINGLE_INSTANCE(VsyncStation); + +void VsyncStation::RequestVsync(CallbackType type, std::shared_ptr vsyncCallback) +{ + auto iter = vsyncCallbacks_.find(type); + if (iter == vsyncCallbacks_.end()) { + WLOGFE("wrong callback type."); + return; + } + iter->second.insert(vsyncCallback); + if (!hasRequestedVsync_) { + hasRequestedVsync_.store(true); + callback_.timestamp_ = 0; + callback_.userdata_ = this; + callback_.callback_ = OnVsync; + VsyncError ret = VsyncHelper::Current()->RequestFrameCallback(callback_); + if (ret != VSYNC_ERROR_OK) { + WLOGFE("VsyncStation::RequestNextVsync fail: %s", VsyncErrorStr(ret).c_str()); + } + } +} + +void VsyncStation::VsyncCallbackInner(int64_t timestamp) +{ + for (auto& vsyncCallbacksSet: vsyncCallbacks_) { + for (const auto& callback: vsyncCallbacksSet.second) { + callback->onCallback(timestamp); + } + vsyncCallbacksSet.second.clear(); + } + hasRequestedVsync_.store(false); +} + +void VsyncStation::OnVsync(int64_t timestamp, void* client) +{ + auto vsyncClient = static_cast(client); + if (vsyncClient) { + vsyncClient->VsyncCallbackInner(timestamp); + } else { + WLOGFE("VsyncStation::OnVsync vsyncClient is null"); + } +} +} +} \ No newline at end of file diff --git a/wm/src/window.cpp b/wm/src/window.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e1ac8e3139040df9eb8482218d52dbe4b7edae6b --- /dev/null +++ b/wm/src/window.cpp @@ -0,0 +1,49 @@ +/* + * Copyright (c) 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 "window.h" +#include "window_impl.h" +#include "window_manager_hilog.h" + +namespace OHOS { +namespace Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "WindowImpl"}; +} +sptr Window::Create(const std::string& windowName, sptr& option, + const sptr& abilityToken) +{ + if (windowName.empty()) { + WLOGFE("window name is empty"); + return nullptr; + } + if (option == nullptr) { + option = new WindowOption(); + } + option->SetWindowName(windowName); + sptr windowImpl = new WindowImpl(option); + WMError error = windowImpl->Create(option->GetParentName(), abilityToken); + if (error != WMError::WM_OK) { + return nullptr; + } + return windowImpl; +} + +sptr Window::Find(const std::string& windowName) +{ + return WindowImpl::Find(windowName); +} +} +} diff --git a/wm/src/window_adapter.cpp b/wm/src/window_adapter.cpp new file mode 100644 index 0000000000000000000000000000000000000000..81b169617ed63d643d9299114f6bdfc4bfa5cae3 --- /dev/null +++ b/wm/src/window_adapter.cpp @@ -0,0 +1,171 @@ +/* + * Copyright (c) 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 "window_adapter.h" +#include +#include +#include "window_manager_hilog.h" +#include "wm_common.h" + +namespace OHOS { +namespace Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "WindowAdapter"}; +} + +IMPLEMENT_SINGLE_INSTANCE(WindowAdapter); + +WMError WindowAdapter::SaveAbilityToken(const sptr& abilityToken, uint32_t windowId) +{ + std::lock_guard lock(mutex_); + + if (!InitWMSProxyLocked()) { + return WMError::WM_ERROR_SAMGR; + } + return windowManagerServiceProxy_->SaveAbilityToken(abilityToken, windowId); +} + +WMError WindowAdapter::CreateWindow(sptr& window, sptr& windowProperty, + std::shared_ptr surfaceNode, uint32_t& windowId) +{ + std::lock_guard lock(mutex_); + + if (!InitWMSProxyLocked()) { + return WMError::WM_ERROR_SAMGR; + } + return windowManagerServiceProxy_->CreateWindow(window, windowProperty, surfaceNode, windowId); +} + +WMError WindowAdapter::AddWindow(sptr& windowProperty) +{ + std::lock_guard lock(mutex_); + + if (!InitWMSProxyLocked()) { + return WMError::WM_ERROR_SAMGR; + } + return windowManagerServiceProxy_->AddWindow(windowProperty); +} + +WMError WindowAdapter::RemoveWindow(uint32_t windowId) +{ + std::lock_guard lock(mutex_); + + if (!InitWMSProxyLocked()) { + return WMError::WM_ERROR_SAMGR; + } + return windowManagerServiceProxy_->RemoveWindow(windowId); +} + +WMError WindowAdapter::DestroyWindow(uint32_t windowId) +{ + std::lock_guard lock(mutex_); + + if (!InitWMSProxyLocked()) { + return WMError::WM_ERROR_SAMGR; + } + return windowManagerServiceProxy_->DestroyWindow(windowId); +} + +WMError WindowAdapter::MoveTo(uint32_t windowId, int32_t x, int32_t y) +{ + std::lock_guard lock(mutex_); + + if (!InitWMSProxyLocked()) { + return WMError::WM_ERROR_SAMGR; + } + return windowManagerServiceProxy_->MoveTo(windowId, x, y); +} + +WMError WindowAdapter::Resize(uint32_t windowId, uint32_t width, uint32_t height) +{ + std::lock_guard lock(mutex_); + + if (!InitWMSProxyLocked()) { + return WMError::WM_ERROR_SAMGR; + } + return windowManagerServiceProxy_->Resize(windowId, width, height); +} + +WMError WindowAdapter::RequestFocus(uint32_t windowId) +{ + std::lock_guard lock(mutex_); + + if (!InitWMSProxyLocked()) { + return WMError::WM_ERROR_SAMGR; + } + return windowManagerServiceProxy_->RequestFocus(windowId); +} + +bool WindowAdapter::InitWMSProxyLocked() +{ + if (!windowManagerServiceProxy_) { + sptr systemAbilityManager = + SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + if (!systemAbilityManager) { + WLOGFE("Failed to get system ability mgr."); + return false; + } + + sptr remoteObject = systemAbilityManager->GetSystemAbility(WINDOW_MANAGER_SERVICE_ID); + if (!remoteObject) { + WLOGFE("Failed to get window manager service."); + return false; + } + + windowManagerServiceProxy_ = iface_cast(remoteObject); + if ((!windowManagerServiceProxy_) || (!windowManagerServiceProxy_->AsObject())) { + WLOGFE("Failed to get system window manager services"); + return false; + } + + wmsDeath_ = new WMSDeathRecipient(); + if (!wmsDeath_) { + WLOGFE("Failed to create death Recipient ptr WMSDeathRecipient"); + return false; + } + if (!remoteObject->AddDeathRecipient(wmsDeath_)) { + WLOGFE("Failed to add death recipient"); + return false; + } + } + return true; +} + +void WindowAdapter::ClearWindowAdapter() +{ + std::lock_guard lock(mutex_); + if ((windowManagerServiceProxy_ != nullptr) && (windowManagerServiceProxy_->AsObject() != nullptr)) { + windowManagerServiceProxy_->AsObject()->RemoveDeathRecipient(wmsDeath_); + } + windowManagerServiceProxy_ = nullptr; +} + +void WMSDeathRecipient::OnRemoteDied(const wptr& wptrDeath) +{ + if (wptrDeath == nullptr) { + WLOGFE("wptrDeath is null"); + return; + } + + sptr object = wptrDeath.promote(); + if (!object) { + WLOGFE("object is null"); + return; + } + SingletonContainer::Get()->ClearWindowAdapter(); + return; +} +} // namespace Rosen +} // namespace OHOS \ No newline at end of file diff --git a/wm/src/window_agent.cpp b/wm/src/window_agent.cpp new file mode 100644 index 0000000000000000000000000000000000000000..79f7a28536838460c6cf5c47cf718df47f170212 --- /dev/null +++ b/wm/src/window_agent.cpp @@ -0,0 +1,61 @@ +/* + * Copyright (c) 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 "window_agent.h" +#include "window_manager_hilog.h" + +namespace OHOS { +namespace Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "WindowAgent"}; +} + +WindowAgent::WindowAgent(sptr& windowImpl) +{ + window_ = windowImpl; +} + +void WindowAgent::UpdateWindowProperty(const WindowProperty& windowProperty) +{ +} + +void WindowAgent::UpdateWindowRect(const struct Rect& rect) +{ + if (window_ == nullptr) { + WLOGFE("window_ is nullptr"); + return; + } + window_->UpdateRect(rect); +} + +void WindowAgent::UpdateWindowMode(WindowMode mode) +{ + if (window_ == nullptr) { + WLOGFE("window_ is nullptr"); + return; + } + window_->UpdateMode(mode); +} + +void WindowAgent::UpdateFocusStatus(bool focused) +{ + if (window_ == nullptr) { + WLOGFE("window_ is nullptr"); + return; + } + window_->UpdateFocusStatus(focused); +} +} // namespace Rosen +} // namespace OHOS diff --git a/wm/src/window_impl.cpp b/wm/src/window_impl.cpp new file mode 100644 index 0000000000000000000000000000000000000000..6f5d980a75727f90abdebdfa1142db444acee58a --- /dev/null +++ b/wm/src/window_impl.cpp @@ -0,0 +1,428 @@ +/* + * Copyright (c) 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 "window_impl.h" +#include "display_manager.h" +#include "singleton_container.h" +#include "window_adapter.h" +#include "window_agent.h" +#include "window_manager_hilog.h" +#ifndef _NEW_RENDERSERVER_ +#include "adapter.h" +#endif + +namespace OHOS { +namespace Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "WindowImpl"}; +} + +std::map>> WindowImpl::windowMap_; + +WindowImpl::WindowImpl(const sptr& option) +{ + property_ = new WindowProperty(); + property_->SetWindowRect(option->GetWindowRect()); + property_->SetWindowType(option->GetWindowType()); + property_->SetWindowMode(option->GetWindowMode()); + property_->SetFullScreen(option->GetWindowMode() == WindowMode::WINDOW_MODE_FULLSCREEN); + property_->SetFocusable(option->GetFocusable()); + property_->SetTouchable(option->GetTouchable()); + property_->SetDisplayId(option->GetDisplayId()); + property_->SetWindowFlags(option->GetWindowFlags()); + name_ = option->GetWindowName(); + +#ifdef _NEW_RENDERSERVER_ + struct RSSurfaceNodeConfig rsSurfaceNodeConfig; + surfaceNode_ = RSSurfaceNode::Create(rsSurfaceNodeConfig); +#endif +} + +WindowImpl::~WindowImpl() +{ + Destroy(); +} + +sptr WindowImpl::Find(const std::string& name) +{ + auto iter = windowMap_.find(name); + if (iter == windowMap_.end()) { + return nullptr; + } + return iter->second.second; +} + +std::shared_ptr WindowImpl::GetSurfaceNode() const +{ + return surfaceNode_; +} + +Rect WindowImpl::GetRect() const +{ + return property_->GetWindowRect(); +} + +WindowType WindowImpl::GetType() const +{ + return property_->GetWindowType(); +} + +WindowMode WindowImpl::GetMode() const +{ + return property_->GetWindowMode(); +} + +const std::string& WindowImpl::GetWindowName() const +{ + return name_; +} + +uint32_t WindowImpl::GetWindowId() +{ + return property_->GetWindowId(); +} + +WMError WindowImpl::SetWindowType(WindowType type) +{ + if (!IsWindowValid()) { + WLOGFI("window is already destroyed or not created! id: %{public}d", property_->GetWindowId()); + return WMError::WM_ERROR_INVALID_WINDOW; + } + if (state_ == STATE_CREATED) { + property_->SetWindowType(type); + return WMError::WM_OK; + } + if (property_->GetWindowType() != type) { + return WMError::WM_ERROR_INVALID_PARAM; + } + return WMError::WM_OK; +} + +WMError WindowImpl::SetWindowMode(WindowMode mode) +{ + if (!IsWindowValid()) { + WLOGFI("window is already destroyed or not created! id: %{public}d", property_->GetWindowId()); + return WMError::WM_ERROR_INVALID_WINDOW; + } + if (state_ == STATE_CREATED || state_ == STATE_HIDDEN) { + property_->SetWindowMode(mode); + return WMError::WM_OK; + } + if (property_->GetWindowMode() != mode) { + // TODO + } + return WMError::WM_OK; +} + +WMError WindowImpl::SetUIContent(std::shared_ptr context, + std::string& url, NativeEngine* engine, NativeValue* storage) +{ + WLOGFI("SetUIContent"); + uiContent_ = Ace::UIContent::Create(context.get(), engine); + if (uiContent_ == nullptr) { + WLOGFE("fail to SetUIContent id: %{public}d", property_->GetWindowId()); + return WMError::WM_ERROR_NULLPTR; + } + uiContent_->Initialize(this, url, storage); + return WMError::WM_OK; +} + +WMError WindowImpl::Create(const std::string& parentName, const sptr& abilityToken) +{ +#ifdef _NEW_RENDERSERVER_ + // check window name, same window names are forbidden + if (windowMap_.find(name_) != windowMap_.end()) { + WLOGFE("WindowName(%{public}s) already exists.", name_.c_str()); + return WMError::WM_ERROR_INVALID_PARAM; + } + // check parent name, if create sub window and there is not exist parent Window, then return + if (parentName != "") { + if (windowMap_.find(parentName) == windowMap_.end()) { + WLOGFE("ParentName is empty or valid. ParentName is %{public}s", parentName.c_str()); + return WMError::WM_ERROR_INVALID_PARAM; + } else { + uint32_t parentId = windowMap_[parentName].first; + property_->SetParentId(parentId); + } + } + + sptr window(this); + sptr windowAgent(new WindowAgent(window)); + uint32_t windowId = 0; + WMError ret = SingletonContainer::Get()->CreateWindow(windowAgent, property_, surfaceNode_, + windowId); + property_->SetWindowId(windowId); + + if (ret != WMError::WM_OK) { + WLOGFE("create window failed with errCode:%{public}d", static_cast(ret)); + return ret; + } + if (abilityToken != nullptr) { + ret = SingletonContainer::Get()->SaveAbilityToken(abilityToken, windowId); + if (ret != WMError::WM_OK) { + WLOGFE("SaveAbilityToken failed with errCode:%{public}d", static_cast(ret)); + return ret; + } + } + windowMap_.insert({ name_, std::pair>(windowId, this) }); + state_ = STATE_CREATED; + WLOGFI("create window success with winId:%{public}d", windowId); + InputTransferStation::GetInstance()->AddInputWindow(this); + return ret; +#else + /* weston adapter */ + return WMError::WM_OK; +#endif +} + +WMError WindowImpl::Destroy() +{ + NotifyBeforeDestroy(); +#ifdef _NEW_RENDERSERVER_ + // should destroy surface here + if (!IsWindowValid()) { + WLOGFI("window is already destroyed or not created! id: %{public}d", property_->GetWindowId()); + return WMError::WM_OK; + } + WLOGFI("destroy window id: %{public}d", property_->GetWindowId()); + WMError ret = SingletonContainer::Get()->DestroyWindow(property_->GetWindowId()); + windowMap_.erase(GetWindowName()); + state_ = STATE_DESTROYED; + InputTransferStation::GetInstance()->RemoveInputWindow(this); + return ret; +#else + InputTransferStation::GetInstance()->RemoveInputWindow(this); + Adapter::DestroyWestonWindow(); +#endif + return WMError::WM_OK; +} + +WMError WindowImpl::Show() +{ +#ifdef _NEW_RENDERSERVER_ + if (!IsWindowValid()) { + WLOGFI("window is already destroyed or not created! id: %{public}d", property_->GetWindowId()); + return WMError::WM_ERROR_INVALID_WINDOW; + } + if (state_ == STATE_SHOWN) { + WLOGFI("window is already shown id: %{public}d", property_->GetWindowId()); + return WMError::WM_OK; + } + SetDefaultOption(); + WMError ret = SingletonContainer::Get()->AddWindow(property_); + if (ret == WMError::WM_OK || ret == WMError::WM_ERROR_DEATH_RECIPIENT) { + Rect rect = property_->GetWindowRect(); + WLOGFI("show x: %{public}d ; y: %{public}d; width: %{public}d; height: %{public}d, winId:%{public}d;", + rect.posX_, rect.posY_, rect.width_, rect.height_, property_->GetWindowId()); + state_ = STATE_SHOWN; + NotifyAfterForeground(); + } + WLOGFE("show errCode:%{public}d for winId:%{public}d", static_cast(ret), property_->GetWindowId()); + return ret; +#else + /* weston adapter */ + WMError rtn = Adapter::Show(); + if (rtn == WMError::WM_OK) { + NotifyAfterForeground(); + NotifyAfterFocused(); + WLOGFI("Show AfterForeground was invoked"); + } else { + WLOGFE("Show error=%d", static_cast(rtn)); + } + InputTransferStation::GetInstance()->AddInputWindow(this); + return rtn; +#endif +} + +WMError WindowImpl::Hide() +{ +#ifdef _NEW_RENDERSERVER_ + if (!IsWindowValid()) { + WLOGFI("window is already destroyed or not created! id: %{public}d", property_->GetWindowId()); + return WMError::WM_ERROR_INVALID_WINDOW; + } + if (state_ == STATE_HIDDEN || state_ == STATE_CREATED) { + WLOGFI("window is already hidden id: %{public}d", property_->GetWindowId()); + return WMError::WM_OK; + } + WMError ret = SingletonContainer::Get()->RemoveWindow(property_->GetWindowId()); + WLOGFI("hide errCode:%{public}d for winId:%{public}d", static_cast(ret), property_->GetWindowId()); + if (ret != WMError::WM_OK) { + return ret; + } + state_ = STATE_HIDDEN; + NotifyAfterBackground(); + return ret; +#else + /* weston adapter */ + WMError rtn = Adapter::Hide(); + if (rtn == WMError::WM_OK) { + NotifyAfterUnFocused(); + NotifyAfterBackground(); + WLOGFI("WindowImpl::Show AfterBackground was ivoked"); + } else { + WLOGFE("WindowImpl::Show error=%d", static_cast(rtn)); + } + InputTransferStation::GetInstance()->RemoveInputWindow(this); + return rtn; +#endif +} + +WMError WindowImpl::MoveTo(int32_t x, int32_t y) +{ + /* weston adapter */ +#ifdef _NEW_RENDERSERVER_ + if (!IsWindowValid()) { + WLOGFI("window is already destroyed or not created! id: %{public}d", property_->GetWindowId()); + return WMError::WM_ERROR_INVALID_WINDOW; + } + if (state_ == STATE_HIDDEN || state_ == STATE_CREATED) { + Rect rect = GetRect(); + property_->SetWindowRect({ x, y, rect.width_, rect.height_ }); + WLOGFI("window is hidden or created! id: %{public}d, rect: [%{public}d, %{public}d, %{public}d, %{public}d]", + property_->GetWindowId(), rect.posX_, rect.posY_, x, y); + return WMError::WM_OK; + } + return SingletonContainer::Get()->MoveTo(property_->GetWindowId(), x, y); +#else + return Adapter::MoveTo(x, y); +#endif +} + +WMError WindowImpl::Resize(uint32_t width, uint32_t height) +{ + /* weston adapter */ +#ifdef _NEW_RENDERSERVER_ + if (!IsWindowValid()) { + WLOGFI("window is already destroyed or not created! id: %{public}d", property_->GetWindowId()); + return WMError::WM_ERROR_INVALID_WINDOW; + } + if (state_ == STATE_HIDDEN || state_ == STATE_CREATED) { + Rect rect = GetRect(); + property_->SetWindowRect({ rect.posX_, rect.posY_, width, height }); + WLOGFI("window is hidden or created! id: %{public}d, rect: [%{public}d, %{public}d, %{public}d, %{public}d]", + property_->GetWindowId(), rect.posX_, rect.posY_, width, height); + return WMError::WM_OK; + } + return SingletonContainer::Get()->Resize(property_->GetWindowId(), width, height); +#else + return Adapter::Resize(width, height); +#endif +} + +WMError WindowImpl::RequestFocus() const +{ + if (!IsWindowValid()) { + WLOGFI("window is already destroyed or not created! id: %{public}d", property_->GetWindowId()); + return WMError::WM_ERROR_INVALID_WINDOW; + } + return SingletonContainer::Get()->RequestFocus(property_->GetWindowId()); +} + +void WindowImpl::AddInputEventListener(std::shared_ptr& inputEventListener) +{ + InputTransferStation::GetInstance()->SetInputListener(GetWindowId(), inputEventListener); +} + +void WindowImpl::RegisterLifeCycleListener(sptr& listener) +{ + lifecycleListener_ = listener; +} + +void WindowImpl::RegisterWindowChangeListener(sptr& listener) +{ + windowChangeListener_ = listener; +} + +void WindowImpl::UpdateRect(const struct Rect& rect) +{ + property_->SetWindowRect(rect); + if (windowChangeListener_ != nullptr) { + windowChangeListener_->OnSizeChange(rect); + } +} + +void WindowImpl::UpdateMode(WindowMode mode) +{ + property_->SetWindowMode(mode); +} + +void WindowImpl::ConsumeKeyEvent(std::shared_ptr& keyEvent) +{ + uiContent_->ProcessKeyEvent(keyEvent); +} +void WindowImpl::ConsumePointerEvent(std::shared_ptr& pointerEvent) +{ + uiContent_->ProcessPointerEvent(pointerEvent); +} + +void WindowImpl::UpdateFocusStatus(bool focused) +{ + WLOGFI("window focus status: %{public}d, id: %{public}d", focused, property_->GetWindowId()); + if (focused) { + NotifyAfterFocused(); + } else { + NotifyAfterUnFocused(); + } +} + +void WindowImpl::SetDefaultOption() +{ + auto display = DisplayManager::GetInstance()->GetDisplayById(property_->GetDisplayId()); + if (display == nullptr) { + WLOGFE("get display failed displayId:%{public}d, window id:%{public}u", property_->GetDisplayId(), + property_->GetWindowId()); + return; + } + uint32_t width = display->GetWidth(); + uint32_t height = display->GetHeight(); + WLOGFI("width:%{public}u, height:%{public}u, displayId:%{public}d", width, height, property_->GetDisplayId()); + + Rect rect; + switch (property_->GetWindowType()) { + case WindowType::WINDOW_TYPE_STATUS_BAR: { + rect = { 0, 0, width, static_cast((static_cast(height) * 0.07)) }; + property_->SetWindowRect(rect); + property_->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING); + break; + } + case WindowType::WINDOW_TYPE_NAVIGATION_BAR: { + uint32_t navHeight = static_cast((static_cast(height) * 0.07)); + rect = { 0, static_cast(height - navHeight), width, navHeight }; + property_->SetWindowRect(rect); + property_->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING); + break; + } + case WindowType::WINDOW_TYPE_SYSTEM_ALARM_WINDOW: { + uint32_t alarmWidth = static_cast((static_cast(width) * 0.8)); + uint32_t alarmHeight = static_cast((static_cast(height) * 0.3)); + + rect = { static_cast((width - alarmWidth) / 2), static_cast((height - alarmHeight) / 2), + alarmWidth, alarmHeight }; + property_->SetWindowRect(rect); + property_->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING); + break; + } + default: + break; + } + +} +bool WindowImpl::IsWindowValid() const +{ + return ((state_ > STATE_INITIAL) && (state_ < STATE_BOTTOM)); +} +} +} \ No newline at end of file diff --git a/wm/src/window_input_channel.cpp b/wm/src/window_input_channel.cpp new file mode 100644 index 0000000000000000000000000000000000000000..952270f3aae386b0e806e51e282bc49c89c533c9 --- /dev/null +++ b/wm/src/window_input_channel.cpp @@ -0,0 +1,83 @@ +/* + * Copyright (c) 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 "window_input_channel.h" +#include + +namespace OHOS { +namespace Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "WindowInputChannel"}; +} +WindowInputChannel::WindowInputChannel(const sptr& window) +{ + window_ = window; + callback_->onCallback = std::bind(&WindowInputChannel::OnVsync, this, std::placeholders::_1); +} + +void WindowInputChannel::HandleKeyEvent(std::shared_ptr& keyEvent) +{ + if (keyEvent == nullptr) { + WLOGE("HandleKeyEvent keyEvent is nullptr"); + return; + } + if (inputListener_ != nullptr) { + inputListener_->OnInputEvent(keyEvent); + return; + } + window_->ConsumeKeyEvent(keyEvent); + keyEvent->MarkProcessed(); +} + +void WindowInputChannel::HandlePointerEvent(std::shared_ptr& pointerEvent) +{ + if (pointerEvent == nullptr) { + WLOGE("HandlePointerEvent pointerEvent is nullptr"); + return; + } + if (inputListener_ != nullptr) { + inputListener_->OnInputEvent(pointerEvent); + return; + } + if (pointerEvent->GetPointerAction() == MMI::PointerEvent::POINTER_ACTION_MOVE) { + if (pointerEventPool_.size() > MAX_INPUT_NUM) { + pointerEventPool_.clear(); + } + pointerEventPool_.emplace_back(pointerEvent); + VsyncStation::GetInstance()->RequestVsync(VsyncStation::CallbackType::CALLBACK_INPUT, callback_); + } else { + window_->ConsumePointerEvent(pointerEvent); + pointerEvent->MarkProcessed(); + } +} + +void WindowInputChannel::OnVsync(int64_t timeStamp) +{ + if (pointerEventPool_.empty()) { + WLOGE("pointerEventPool_ is empty"); + return; + } + auto pointerEvent = pointerEventPool_.back(); + HandlePointerEvent(pointerEvent); + pointerEvent->MarkProcessed(); + pointerEventPool_.clear(); +} + +void WindowInputChannel::SetInputListener(std::shared_ptr& listener) +{ + inputListener_ = listener; +} +} +} \ No newline at end of file diff --git a/wm/src/window_option.cpp b/wm/src/window_option.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d116dd97893bdb8e80421372db91aa1b1a38144d --- /dev/null +++ b/wm/src/window_option.cpp @@ -0,0 +1,126 @@ +/* + * Copyright (c) 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 "window_option.h" + +namespace OHOS { +namespace Rosen { +WindowOption::WindowOption() +{ + AddWindowFlag(WindowFlag::WINDOW_FLAG_NEED_AVOID); +} + +void WindowOption::SetWindowRect(const struct Rect& rect) +{ + windowRect_ = rect; +} + +void WindowOption::SetWindowType(WindowType type) +{ + type_ = type; +} + +void WindowOption::SetWindowMode(WindowMode mode) +{ + mode_ = mode; +} + +void WindowOption::SetFocusable(bool isFocusable) +{ + focusable_ = isFocusable; +} + +void WindowOption::SetTouchable(bool isTouchable) +{ + touchable_ = isTouchable; +} + +void WindowOption::SetDisplayId(int32_t displayId) +{ + displayId_ = displayId; +} + +void WindowOption::SetParentName(const std::string& parentName) +{ + parentName_ = parentName; +} + +void WindowOption::SetWindowName(const std::string& windowName) +{ + windowName_ = windowName; +} + +void WindowOption::AddWindowFlag(WindowFlag flag) +{ + flags_ |= static_cast(flag); +} + +void WindowOption::RemoveWindowFlag(WindowFlag flag) +{ + flags_ &= ~(static_cast(flag)); +} + +void WindowOption::SetWindowFlags(uint32_t flags) +{ + flags_ = flags; +} + +Rect WindowOption::GetWindowRect() const +{ + return windowRect_; +} + +WindowType WindowOption::GetWindowType() const +{ + return type_; +} + +WindowMode WindowOption::GetWindowMode() const +{ + return mode_; +} + +bool WindowOption::GetFocusable() const +{ + return focusable_; +} + +bool WindowOption::GetTouchable() const +{ + return touchable_; +} + +int32_t WindowOption::GetDisplayId() const +{ + return displayId_; +} + +const std::string& WindowOption::GetParentName() const +{ + return parentName_; +} + +const std::string& WindowOption::GetWindowName() const +{ + return windowName_; +} + +uint32_t WindowOption::GetWindowFlags() const +{ + return flags_; +} +} +} + diff --git a/wm/src/window_property.cpp b/wm/src/window_property.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3ee405db3ebb870d75f5b17093ae8433474b74bb --- /dev/null +++ b/wm/src/window_property.cpp @@ -0,0 +1,238 @@ +/* + * Copyright (c) 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 "window_property.h" + +namespace OHOS { +namespace Rosen { +void WindowProperty::SetWindowRect(const struct Rect& rect) +{ + windowRect_ = rect; +} + +void WindowProperty::SetWindowType(WindowType type) +{ + type_ = type; +} + +void WindowProperty::SetWindowMode(WindowMode mode) +{ + mode_ = mode; +} + +void WindowProperty::SetFullScreen(bool isFullScreen) +{ + isFullScreen_ = isFullScreen; +} + +void WindowProperty::SetFocusable(bool isFocusable) +{ + focusable_ = isFocusable; +} + +void WindowProperty::SetTouchable(bool isTouchable) +{ + touchable_ = isTouchable; +} + +void WindowProperty::SetPrivacyMode(bool isPrivate) +{ + isPrivacyMode_ = isPrivate; +} + +void WindowProperty::SetTransparent(bool isTransparent) +{ + isTransparent_ = isTransparent; +} + +void WindowProperty::SetAlpha(float alpha) +{ + alpha_ = alpha; +} + +void WindowProperty::SetDisplayId(int32_t displayId) +{ + displayId_ = displayId; +} + +void WindowProperty::SetWindowFlags(uint32_t flags) +{ + flags_ = flags; +} + +Rect WindowProperty::GetWindowRect() const +{ + return windowRect_; +} + +WindowType WindowProperty::GetWindowType() const +{ + return type_; +} + +WindowMode WindowProperty::GetWindowMode() const +{ + return mode_; +} + +bool WindowProperty::GetFullScreen() const +{ + return isFullScreen_; +} + +bool WindowProperty::GetFocusable() const +{ + return focusable_; +} + +bool WindowProperty::GetTouchable() const +{ + return touchable_; +} + +bool WindowProperty::GetPrivacyMode() const +{ + return isPrivacyMode_; +} + +bool WindowProperty::GetTransparent() const +{ + return isTransparent_; +} + +float WindowProperty::GetAlpha() const +{ + return alpha_; +} + +int32_t WindowProperty::GetDisplayId() const +{ + return displayId_; +} + +uint32_t WindowProperty::GetWindowFlags() const +{ + return flags_; +} + +// TODO +void WindowProperty::SetWindowId(uint32_t windowId) +{ + windowId_ = windowId; +} +void WindowProperty::SetParentId(uint32_t parentId) +{ + parentId_ = parentId; +} +uint32_t WindowProperty::GetWindowId() const +{ + return windowId_; +} +uint32_t WindowProperty::GetParentId() const +{ + return parentId_; +} + +bool WindowProperty::Marshalling(Parcel& parcel) const +{ + // write windowRect_ + if (!(parcel.WriteInt32(windowRect_.posX_) && parcel.WriteInt32(windowRect_.posY_) && + parcel.WriteUint32(windowRect_.width_) && parcel.WriteUint32(windowRect_.height_))) { + return false; + } + + // write type_ + if (!parcel.WriteUint32(static_cast(type_))) { + return false; + } + + // write mode_ + if (!parcel.WriteUint32(static_cast(mode_))) { + return false; + } + + // write flags_ + if (!parcel.WriteUint32(flags_)) { + return false; + } + + // write isFullScreen_ + if (!parcel.WriteBool(isFullScreen_)) { + return false; + } + + // write focusable_ + if (!parcel.WriteBool(focusable_)) { + return false; + } + + // write touchable_ + if (!parcel.WriteBool(touchable_)) { + return false; + } + + // write isPrivacyMode_ + if (!parcel.WriteBool(isPrivacyMode_)) { + return false; + } + + // write isTransparent_ + if (!parcel.WriteBool(isTransparent_)) { + return false; + } + + // write alpha_ + if (!parcel.WriteFloat(alpha_)) { + return false; + } + + // write displayId_ + if (!parcel.WriteInt32(displayId_)) { + return false; + } + + // write windowId_ + if (!parcel.WriteUint32(windowId_)) { + return false; + } + + // write parentId_ + if (!parcel.WriteUint32(parentId_)) { + return false; + } + return true; +} + +sptr WindowProperty::Unmarshalling(Parcel& parcel) +{ + sptr property(new WindowProperty()); + Rect rect = { parcel.ReadInt32(), parcel.ReadInt32(), parcel.ReadUint32(), parcel.ReadUint32() }; + property->SetWindowRect(rect); + property->SetWindowType(static_cast(parcel.ReadUint32())); + property->SetWindowMode(static_cast(parcel.ReadUint32())); + property->SetWindowFlags(parcel.ReadUint32()); + property->SetFullScreen(parcel.ReadBool()); + property->SetFocusable(parcel.ReadBool()); + property->SetTouchable(parcel.ReadBool()); + property->SetPrivacyMode(parcel.ReadBool()); + property->SetTransparent(parcel.ReadBool()); + property->SetAlpha(parcel.ReadFloat()); + property->SetDisplayId(parcel.ReadInt32()); + property->SetWindowId(parcel.ReadUint32()); + property->SetParentId(parcel.ReadUint32()); + return property; +} +} +} diff --git a/wm/src/window_proxy.cpp b/wm/src/window_proxy.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7334d6bb601df3801b650e5950f985b6a985f72c --- /dev/null +++ b/wm/src/window_proxy.cpp @@ -0,0 +1,97 @@ +/* + * Copyright (c) 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 "window_proxy.h" +#include +#include "window_manager_hilog.h" + +namespace OHOS { +namespace Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "WindowProxy"}; +} + +void WindowProxy::UpdateWindowProperty(const WindowProperty& windowProperty) +{ + sptr remote = Remote(); + if (remote == nullptr) { + WLOGFW("remote is nullptr"); + return; + } +} + +void WindowProxy::UpdateWindowRect(const struct Rect& rect) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!data.WriteInterfaceToken(GetDescriptor())) { + WLOGFE("WriteInterfaceToken failed"); + return; + } + if (!(data.WriteInt32(rect.posX_) && data.WriteInt32(rect.posY_) && + data.WriteUint32(rect.width_) && data.WriteUint32(rect.height_))) { + WLOGFE("Write WindowRect failed"); + return; + } + + if (Remote()->SendRequest(TRANS_ID_UPDATE_WINDOW_RECT, data, reply, option) != ERR_NONE) { + WLOGFE("SendRequest failed"); + } + return; +} + +void WindowProxy::UpdateWindowMode(WindowMode mode) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!data.WriteInterfaceToken(GetDescriptor())) { + WLOGFE("WriteInterfaceToken failed"); + return; + } + if (!data.WriteUint32(static_cast(mode))) { + WLOGFE("Write WindowMode failed"); + return; + } + + if (Remote()->SendRequest(TRANS_ID_UPDATE_WINDOW_MODE, data, reply, option) != ERR_NONE) { + WLOGFE("SendRequest failed"); + } + return; +} + +void WindowProxy::UpdateFocusStatus(bool focused) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!data.WriteInterfaceToken(GetDescriptor())) { + WLOGFE("WriteInterfaceToken failed"); + return; + } + if (!data.WriteBool(focused)) { + WLOGFE("Write Focus failed"); + return; + } + + if (Remote()->SendRequest(TRANS_ID_UPDATE_FOCUS_STATUS, data, reply, option) != ERR_NONE) { + WLOGFE("SendRequest failed"); + } + return; +} +} // namespace Rosen +} // namespace OHOS + diff --git a/wm/src/window_scene.cpp b/wm/src/window_scene.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3281d774287eb59dfd8df0b1bd053d8cc46ffc42 --- /dev/null +++ b/wm/src/window_scene.cpp @@ -0,0 +1,127 @@ +/* + * Copyright (c) 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 "window_scene.h" +#include "static_call.h" +#include "window_impl.h" +#include "window_manager_hilog.h" +#ifndef _NEW_RENDERSERVER_ +#include "adapter.h" +#endif + +namespace OHOS { +namespace Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "WindowScene"}; +} + +const std::string WindowScene::MAIN_WINDOW_ID = "main window"; + +WindowScene::~WindowScene() +{ + WLOGFI("~WindowScene"); + if (mainWindow_ != nullptr) { + mainWindow_->Destroy(); + mainWindow_ = nullptr; + } +} + +WMError WindowScene::Init(int32_t displayId, std::shared_ptr& abilityContext, + sptr& listener) +{ + displayId_ = displayId; + abilityContext_ = abilityContext; + sptr option = new WindowOption(); + option->SetDisplayId(displayId); + +#ifndef _NEW_RENDERSERVER_ + /* weston adapter */ + Adapter::Init(); + mainWindow_ = CreateWindow(MAIN_WINDOW_ID, option); +#else + if (abilityContext_ != nullptr) { + mainWindow_ = SingletonContainer::Get()->CreateWindow( + MAIN_WINDOW_ID + std::to_string(count++), option, abilityContext_->GetAbilityToken()); + } else { + mainWindow_ = SingletonContainer::Get()->CreateWindow( + MAIN_WINDOW_ID + std::to_string(count++), option); + } + +#endif + if (mainWindow_ == nullptr) { + return WMError::WM_ERROR_NULLPTR; + } + mainWindow_->RegisterLifeCycleListener(listener); + + return WMError::WM_OK; +} + +sptr WindowScene::CreateWindow(const std::string& windowName, sptr& option) const +{ +#ifdef _NEW_RENDERSERVER_ + if (windowName.empty() || mainWindow_ == nullptr || option == nullptr) { + WLOGFE("WindowScene Name: %{public}s", windowName.c_str()); + return nullptr; + } + option->SetParentName(mainWindow_->GetWindowName()); + return SingletonContainer::Get()->CreateWindow(windowName, option); +#else + /* weston adapter */ + if (!Adapter::CreateWestonWindow(option)) { + WLOGFE("WindowScene::CreateWindow fail to CreateWestonWindow"); + return nullptr; + } + Rect rect; + if (!Adapter::GetMainWindowRect(rect)) { + WLOGFE("WindowScene::CreateWindow fail to GetMainWindowRect"); + return nullptr; + } + option->SetWindowName(windowName); + option->SetWindowRect(rect); + sptr window = new WindowImpl(option); + return window; +#endif +} + +const sptr& WindowScene::GetMainWindow() const +{ + return mainWindow_; +} + +WMError WindowScene::GoForeground() +{ + if (mainWindow_ == nullptr) { + return WMError::WM_ERROR_NULLPTR; + } + return mainWindow_->Show(); +} + +WMError WindowScene::GoBackground() const +{ + if (mainWindow_ == nullptr) { + return WMError::WM_ERROR_NULLPTR; + } + return mainWindow_->Hide(); +} + +WMError WindowScene::RequestFocus() const +{ + if (mainWindow_ == nullptr) { + return WMError::WM_ERROR_NULLPTR; + } + return mainWindow_->RequestFocus(); +} +} // namespace Rosen +} // namespace OHOS diff --git a/wm/src/window_stub.cpp b/wm/src/window_stub.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e7640726e2dd92bf8714057c2947f8806991bc23 --- /dev/null +++ b/wm/src/window_stub.cpp @@ -0,0 +1,59 @@ +/* + * Copyright (c) 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 "window_stub.h" +#include "ipc_skeleton.h" +#include "window_manager_hilog.h" +#include "wm_common.h" + +namespace OHOS { +namespace Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "WindowStub"}; +} + +int WindowStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) +{ + WLOGFI("WindowStub::OnRemoteRequest code is %{public}d", code); + if (data.ReadInterfaceToken() != GetDescriptor()) { + WLOGFE("InterfaceToken check failed"); + return -1; + } + switch (code) { + case TRANS_ID_UPDATE_WINDOW_PROPERTY: { + break; + } + case TRANS_ID_UPDATE_WINDOW_RECT: { + struct Rect rect{ data.ReadInt32(), data.ReadInt32(), data.ReadUint32(), data.ReadUint32() }; + UpdateWindowRect(rect); + break; + } + case TRANS_ID_UPDATE_WINDOW_MODE: { + WindowMode mode = static_cast(data.ReadUint32()); + UpdateWindowMode(mode); + break; + } + case TRANS_ID_UPDATE_FOCUS_STATUS: { + bool focused = data.ReadBool(); + UpdateFocusStatus(focused); + break; + } + default: + break; + } + return 0; +} +} // namespace Rosen +} // namespace OHOS diff --git a/wmserver/BUILD.gn b/wmserver/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..6db371375123cae1b8cc078d6aaefe8f41908413 --- /dev/null +++ b/wmserver/BUILD.gn @@ -0,0 +1,85 @@ +# Copyright (c) 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/ohos.gni") + +## Build libwms.so +config("libwms_config") { + visibility = [ ":*" ] + + include_dirs = [ + "include", + "//utils/system/safwk/native/include", + "//foundation/windowmanager/interfaces/innerkits/wm", + "//foundation/windowmanager/interfaces/innerkits/dm", + "//foundation/windowmanager/wm/include", + "//foundation/windowmanager/utils/include", + "//foundation/windowmanager/dm/include", + "//foundation/windowmanager/dmserver/include", + ] + + cflags = [ + "-Wall", + "-Werror", + "-g3", + ] +} + +ohos_shared_library("libwms") { + sources = [ + "../dmserver/src/display_manager_service.cpp", + "../dmserver/src/display_manager_service_inner.cpp", + "../dmserver/src/display_manager_stub.cpp", + "../dmserver/src/display_node_control.cpp", + "../dmserver/src/display_screen.cpp", + "../dmserver/src/display_screen_manager.cpp", + "../dmserver/src/screen.cpp", + "src/input_window_monitor.cpp", + "src/window_controller.cpp", + "src/window_layout_policy.cpp", + "src/window_manager_service.cpp", + "src/window_manager_stub.cpp", + "src/window_node.cpp", + "src/window_node_container.cpp", + "src/window_root.cpp", + "src/window_zorder_policy.cpp", + ] + + configs = [ ":libwms_config" ] + + deps = [ + "//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog", + "//foundation/distributedschedule/safwk/interfaces/innerkits/safwk:system_ability_fwk", + "//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", + "//foundation/windowmanager/wm:libwmutil", + "//utils/native/base:utils", + + # RSSurface + "//foundation/graphic/standard/rosen/modules/render_service_base:librender_service_base", + "//foundation/graphic/standard/rosen/modules/render_service_client:librender_service_client", + + # IMS + "//foundation/multimodalinput/input/frameworks/proxy:libmmi-client", + ] + + public_deps = [ + # ability manager + "//foundation/aafwk/standard/interfaces/innerkits/ability_manager:ability_manager", + "//foundation/aafwk/standard/interfaces/innerkits/want:want", + ] + + external_deps = [ "ipc:ipc_core" ] + + part_name = "window_manager" + subsystem_name = "window" +} diff --git a/wmserver/include/README.md b/wmserver/include/README.md new file mode 100644 index 0000000000000000000000000000000000000000..539249966b4bf441daae568854d04f8f8b0e5029 --- /dev/null +++ b/wmserver/include/README.md @@ -0,0 +1 @@ +Store code of window sever inner header files \ No newline at end of file diff --git a/wmserver/include/input_window_monitor.h b/wmserver/include/input_window_monitor.h new file mode 100644 index 0000000000000000000000000000000000000000..ed446505805590d1edc8f2f1891476daa8c7a677 --- /dev/null +++ b/wmserver/include/input_window_monitor.h @@ -0,0 +1,72 @@ +/* + * Copyright (c) 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 OHOS_INPUT_WINDOW_MONITOR_H +#define OHOS_INPUT_WINDOW_MONITOR_H + +#include +#include + +#include "window_root.h" + +namespace OHOS { +namespace Rosen { +class InputWindowMonitor : public RefBase { +public: + InputWindowMonitor(sptr& root) : windowRoot_(root) + { + MMI::PhysicalDisplayInfo physicalDisplayInfo = { + .id = 0, //todo: update when DMS is ready + .leftDisplayId = -1, // todo: invalid displayId for testing + .upDisplayId = -1, // todo: invalid displayId for testing + .topLeftX = 0, // todo: use wgn info for testing + .topLeftY = 0, // todo: use wgn info for testing + .width = 2560, // todo: use wgn info for testing + .height = 1600, // todo: use wgn info for testing + .name = "physical_display0", // todo: wait for DMS + .seatId = "seat0", // todo: update seatId + .seatName = "default0", // todo: update seatId + .logicWidth = 2560, // todo: use wgn info for testing + .logicHeight = 1600, // todo: use wgn info for testing + .direction = MMI::Direction0 // todo: use direction 0 for testing + }; + physicalDisplays_.emplace_back(physicalDisplayInfo); + MMI::LogicalDisplayInfo logicalDisplayInfo = { + .id = 0, //todo: update when DMS is ready + .topLeftX = 0, // todo: use wgn info for testing + .topLeftY = 0, // todo: use wgn info for testing + .width = 2560, // todo: use wgn info for testing + .height = 1600, // todo: use wgn info for testing + .name = "logical_display0", // todo: wait for DMS + .seatId = "seat0", // todo: update seatId + .seatName = "default0", // todo: update seatName + .focusWindowId = -1, + .windowsInfo_ = {}, + }; + logicalDisplays_.emplace_back(logicalDisplayInfo); + } + ~InputWindowMonitor() = default; + void UpdateInputWindow(uint32_t windowId); + +private: + sptr windowRoot_; + std::vector physicalDisplays_; + std::vector logicalDisplays_; + void TraverseWindowNodes(const std::vector>& windowNodes, + std::vector::iterator& iter); +}; +} +} +#endif // OHOS_INPUT_WINDOW_MONITOR_H diff --git a/wmserver/include/window_controller.h b/wmserver/include/window_controller.h new file mode 100644 index 0000000000000000000000000000000000000000..043cad3d49d9773c55b9202279e2d919ac75a265 --- /dev/null +++ b/wmserver/include/window_controller.h @@ -0,0 +1,48 @@ +/* + * Copyright (c) 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 OHOS_ROSEN_WINDOW_CONTROLLER_H +#define OHOS_ROSEN_WINDOW_CONTROLLER_H + +#include +#include "window_root.h" + +namespace OHOS { +namespace Rosen { +class WindowController : public RefBase { +public: + WindowController(sptr& root) : windowRoot_(root) {} + ~WindowController() = default; + + WMError CreateWindow(sptr& window, sptr& property, + const std::shared_ptr& surfaceNode, uint32_t& windowId); + WMError AddWindowNode(sptr& property); + WMError RemoveWindowNode(uint32_t windowId); + WMError DestroyWindow(uint32_t windowId); + WMError MoveTo(uint32_t windowId, int32_t x, int32_t y); + WMError Resize(uint32_t windowId, uint32_t width, uint32_t height); + WMError RequestFocus(uint32_t windowId); + WMError SaveAbilityToken(const sptr& abilityToken, uint32_t windowId); + +private: + uint32_t GenWindowId(); + WMError LayoutWindowNodeTrees(); + + sptr windowRoot_; + std::atomic windowId_ { 0 }; +}; +} +} +#endif // OHOS_ROSEN_WINDOW_CONTROLLER_H diff --git a/wmserver/include/window_layout_policy.h b/wmserver/include/window_layout_policy.h new file mode 100644 index 0000000000000000000000000000000000000000..350b8c0e2a0515e50004b60413486a84cf46055d --- /dev/null +++ b/wmserver/include/window_layout_policy.h @@ -0,0 +1,53 @@ +/* + * Copyright (c) 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 OHOS_ROSEN_WINDOW_LAYOUT_POLICY_H +#define OHOS_ROSEN_WINDOW_LAYOUT_POLICY_H + +#include +#include +#include + +#include "window_node.h" +#include "wm_common.h" + +namespace OHOS { +namespace Rosen { +class WindowLayoutPolicy : public RefBase { +public: + WindowLayoutPolicy() = default; + ~WindowLayoutPolicy() = default; + WMError UpdateDisplayInfo(const Rect& displayRect); + WMError LayoutWindow(sptr& node); + +private: + Rect displayRect_ = {0, 0, 0, 0}; + Rect limitRect_ = {0, 0, 0, 0}; + std::map> aviodNodes_; + const std::set aviodTypes_ { + WindowType::WINDOW_TYPE_STATUS_BAR, + WindowType::WINDOW_TYPE_NAVIGATION_BAR, + }; + void UpdateLimitRect(const sptr& node); + void RecordAvoidRect(const sptr& node); + bool UpdateLayoutRects(sptr& node); + bool IsNeedAvoidNode(const sptr& node); + bool IsFullScreenNode(const sptr& node); + bool IsParentLimitNode(const sptr& node); + bool IsRectChanged(const Rect& l, const Rect& r); +}; +} +} +#endif // OHOS_ROSEN_WINDOW_LAYOUT_POLICY_H diff --git a/wmserver/include/window_manager_interface.h b/wmserver/include/window_manager_interface.h new file mode 100644 index 0000000000000000000000000000000000000000..e1d9d4d49443a9937fc7d525f719bd287aef4549 --- /dev/null +++ b/wmserver/include/window_manager_interface.h @@ -0,0 +1,52 @@ +/* + * Copyright (c) 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 OHOS_WINDOW_MANAGER_INTERFACE_H +#define OHOS_WINDOW_MANAGER_INTERFACE_H + +#include +#include +#include "window_property.h" +#include "window_interface.h" + +namespace OHOS { +namespace Rosen { +class IWindowManager : public IRemoteBroker { +public: + DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.IWindowManager"); + + enum { + TRANS_ID_CREATE_WINDOW, + TRANS_ID_ADD_WINDOW, + TRANS_ID_REMOVE_WINDOW, + TRANS_ID_DESTROY_WINDOW, + TRANS_ID_MOVE, + TRANS_ID_RESIZE, + TRANS_ID_REQUEST_FOCUS, + TRANS_ID_SEND_ABILITY_TOKEN, + }; + virtual WMError CreateWindow(sptr& window, sptr& property, + const std::shared_ptr& surfaceNode, uint32_t& windowId) = 0; + virtual WMError AddWindow(sptr& property) = 0; + virtual WMError RemoveWindow(uint32_t windowId) = 0; + virtual WMError DestroyWindow(uint32_t windowId) = 0; + virtual WMError MoveTo(uint32_t windowId, int32_t x, int32_t y) = 0; + virtual WMError Resize(uint32_t windowId, uint32_t width, uint32_t height) = 0; + virtual WMError RequestFocus(uint32_t windowId) = 0; + virtual WMError SaveAbilityToken(const sptr& abilityToken, uint32_t windowId) = 0; +}; +} +} +#endif // OHOS_WINDOW_MANAGER_INTERFACE_H diff --git a/wmserver/include/window_manager_proxy.h b/wmserver/include/window_manager_proxy.h new file mode 100644 index 0000000000000000000000000000000000000000..60e89fd3cfd206b25681127a72a77c0f2d4864a0 --- /dev/null +++ b/wmserver/include/window_manager_proxy.h @@ -0,0 +1,45 @@ +/* + * Copyright (c) 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 OHOS_WINDOW_MANAGER_PROXY_H +#define OHOS_WINDOW_MANAGER_PROXY_H + +#include "window_manager_interface.h" +#include + +namespace OHOS { +namespace Rosen { +class WindowManagerProxy : public IRemoteProxy { +public: + explicit WindowManagerProxy(const sptr& impl) : IRemoteProxy(impl) {}; + + ~WindowManagerProxy() {}; + + WMError CreateWindow(sptr& window, sptr& property, + const std::shared_ptr& surfaceNode, uint32_t& windowId) override; + WMError AddWindow(sptr& property) override; + WMError RemoveWindow(uint32_t windowId) override; + WMError DestroyWindow(uint32_t windowId) override; + WMError MoveTo(uint32_t windowId, int32_t x, int32_t y) override; + WMError Resize(uint32_t windowId, uint32_t width, uint32_t height) override; + WMError RequestFocus(uint32_t windowId) override; + WMError SaveAbilityToken(const sptr& abilityToken, uint32_t windowId) override; + +private: + static inline BrokerDelegator delegator_; +}; +} +} +#endif // OHOS_WINDOW_MANAGER_PROXY_H diff --git a/wmserver/include/window_manager_service.h b/wmserver/include/window_manager_service.h new file mode 100644 index 0000000000000000000000000000000000000000..b722b1646912b283861a259a1854d3aff4d0648f --- /dev/null +++ b/wmserver/include/window_manager_service.h @@ -0,0 +1,63 @@ +/* + * Copyright (c) 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 OHOS_WINDOW_MANAGER_SERVICE_H +#define OHOS_WINDOW_MANAGER_SERVICE_H + +#include +#include + +#include +#include +#include +#include "singleton_delegator.h" +#include "single_instance.h" +#include "window_controller.h" +#include "window_manager_stub.h" +#include "window_root.h" + +namespace OHOS { +namespace Rosen { +class WindowManagerService : public SystemAbility, public WindowManagerStub { +DECLARE_SYSTEM_ABILITY(WindowManagerService); + +DECLARE_SINGLE_INSTANCE_BASE(WindowManagerService); + +public: + ~WindowManagerService() = default; + void OnStart() override; + void OnStop() override; + + WMError CreateWindow(sptr& window, sptr& property, + const std::shared_ptr& surfaceNode, uint32_t& windowId) override; + WMError AddWindow(sptr& property) override; + WMError RemoveWindow(uint32_t windowId) override; + WMError DestroyWindow(uint32_t windowId) override; + WMError MoveTo(uint32_t windowId, int32_t x, int32_t y) override; + WMError Resize(uint32_t windowId, uint32_t width, uint32_t height) override; + WMError RequestFocus(uint32_t windowId) override; + WMError SaveAbilityToken(const sptr& abilityToken, uint32_t windowId) override; +private: + WindowManagerService(); + bool Init(); + static inline SingletonDelegator delegator; + std::mutex mutex_; + sptr windowRoot_; + sptr windowController_; + sptr inputWindowMonitor_; +}; +} +} +#endif // OHOS_WINDOW_MANAGER_SERVICE_H diff --git a/wmserver/include/window_manager_stub.h b/wmserver/include/window_manager_stub.h new file mode 100644 index 0000000000000000000000000000000000000000..4fa7df0aa9b7335b9d08cbae98396157f10e7cb3 --- /dev/null +++ b/wmserver/include/window_manager_stub.h @@ -0,0 +1,32 @@ +/* + * Copyright (c) 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 OHOS_WINDOW_MANAGER_STUB_H +#define OHOS_WINDOW_MANAGER_STUB_H + +#include "window_manager_interface.h" +#include +namespace OHOS { +namespace Rosen { +class WindowManagerStub : public IRemoteStub { +public: + WindowManagerStub() = default; + ~WindowManagerStub() = default; + virtual int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, + MessageOption &option) override; +}; +} +} +#endif // OHOS_WINDOW_MANAGER_STUB_H diff --git a/wmserver/include/window_node.h b/wmserver/include/window_node.h new file mode 100644 index 0000000000000000000000000000000000000000..0684ebe71db850c6ea4e5753a8df58c1590c35c4 --- /dev/null +++ b/wmserver/include/window_node.h @@ -0,0 +1,82 @@ +/* + * Copyright (c) 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 OHOS_ROSEN_WINDOW_NODE_H +#define OHOS_ROSEN_WINDOW_NODE_H + +#include +#include +#include +#include "window_interface.h" +#include "window_manager_hilog.h" + +namespace OHOS { +namespace Rosen { +struct LayoutRects { + Rect displayRect_ = { 0, 0, 0, 0 }; + Rect parentRect_ = { 0, 0, 0, 0 }; + Rect limitRect_ = { 0, 0, 0, 0 }; + Rect rect_ = { 0, 0, 0, 0 }; +}; + +class WindowNode : public RefBase { +public: + WindowNode(const sptr& property, const sptr& window, + std::shared_ptr surfaceNode) + : surfaceNode_(surfaceNode), property_(property), windowToken_(window) + { + callingPid_ = IPCSkeleton::GetCallingPid(); + callingUid_ = IPCSkeleton::GetCallingUid(); + } + WindowNode() : property_(new WindowProperty()) + { + callingPid_ = IPCSkeleton::GetCallingPid(); + callingUid_ = IPCSkeleton::GetCallingUid(); + } + ~WindowNode() = default; + + void SetDisplayId(int32_t displayId); + void UpdateLayoutRects(const LayoutRects& rects); + void SetWindowProperty(const sptr& property); + + const sptr& GetWindowToken() const; + uint32_t GetWindowId() const; + int32_t GetDisplayId() const; + const LayoutRects& GetLayoutRects() const; + WindowType GetWindowType() const; + WindowMode GetWindowMode() const; + uint32_t GetWindowFlags() const; + const sptr& GetWindowProperty() const; + int32_t GetCallingPid() const; + int32_t GetCallingUid() const; + + sptr parent_; + std::vector> children_; + std::shared_ptr surfaceNode_; + sptr abilityToken_ = nullptr; + int32_t priority_ { 0 }; + bool requestedVisibility_ { false }; + bool currentVisibility_ { false }; + +private: + sptr property_; + sptr windowToken_; + LayoutRects layoutRects_; + int32_t callingPid_; + int32_t callingUid_; +}; +} +} +#endif // OHOS_ROSEN_WINDOW_NODE_H diff --git a/wmserver/include/window_node_container.h b/wmserver/include/window_node_container.h new file mode 100644 index 0000000000000000000000000000000000000000..251683b665fea1a812bf9b756845b8193cf00ba6 --- /dev/null +++ b/wmserver/include/window_node_container.h @@ -0,0 +1,76 @@ +/* + * Copyright (c) 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 OHOS_ROSEN_WINDOW_NODE_CONTAINER_H +#define OHOS_ROSEN_WINDOW_NODE_CONTAINER_H + +#include +#include "window_layout_policy.h" +#include "window_node.h" +#include "window_zorder_policy.h" +#include "wm_common.h" + +namespace OHOS { +namespace Rosen { +class WindowNodeContainer : public RefBase { +public: + WindowNodeContainer(uint64_t screenId, uint32_t width, uint32_t height) + { + struct RSDisplayNodeConfig config = {screenId}; + displayNode_ = RSDisplayNode::Create(config); + displayRect_ = { + .posX_ = 0, + .posY_ = 0, + .width_ = width, + .height_ = height + }; + } + + ~WindowNodeContainer(); + WMError AddWindowNode(sptr& node, sptr& parentNode); + WMError RemoveWindowNode(sptr& node); + WMError DestroyWindowNode(sptr& node, std::vector& windowIds); + const std::vector& Destroy(); + void AssignZOrder(); + WMError SetFocusWindow(uint32_t windowId); + uint32_t GetFocusWindow() const; + WMError MinimizeOtherFullScreenAbility(); // adapt to api7 + void TraverseContainer(std::vector>& windowNodes); + WMError LayoutWindowNodes(); + +private: + void AssignZOrder(sptr& node); + void TraverseWindowNode(sptr& root, std::vector>& windowNodes); + sptr FindRoot(WindowType type) const; + void UpdateFocusWindow(); + sptr FindWindowNodeById(uint32_t id) const; + void UpdateFocusStatus(uint32_t id, bool focused) const; + void UpdateWindowTree(sptr& node); + bool UpdateRSTree(sptr& node, bool isAdd); + sptr zorderPolicy_ = new WindowZorderPolicy(); + sptr layoutPolicy_ = new WindowLayoutPolicy(); + sptr belowAppWindowNode_ = new WindowNode(); + sptr appWindowNode_ = new WindowNode(); + sptr aboveAppWindowNode_ = new WindowNode(); + std::shared_ptr displayNode_; + std::vector removedIds_; + uint32_t zOrder_ { 0 }; + uint32_t focusedWindow_ { 0 }; + Rect displayRect_; + WMError LayoutWindowNode(sptr& node); +}; +} +} +#endif // OHOS_ROSEN_WINDOW_NODE_CONTAINER_H diff --git a/wmserver/include/window_root.h b/wmserver/include/window_root.h new file mode 100644 index 0000000000000000000000000000000000000000..9a86234686cc8e5504f1129d0896986d87b26bda --- /dev/null +++ b/wmserver/include/window_root.h @@ -0,0 +1,65 @@ +/* + * Copyright (c) 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 OHOS_ROSEN_WINDOW_ROOT_H +#define OHOS_ROSEN_WINDOW_ROOT_H + +#include +#include +#include "window_node_container.h" + +namespace OHOS { +namespace Rosen { +class WindowDeathRecipient : public IRemoteObject::DeathRecipient { +public: + WindowDeathRecipient(std::function&)> callback) : callback_(callback) {} + ~WindowDeathRecipient() = default; + + virtual void OnRemoteDied(const wptr& wptrDeath) override; + + std::function&)> callback_; +}; + +class WindowRoot : public RefBase { +public: + WindowRoot() = default; + ~WindowRoot() = default; + + sptr GetOrCreateWindowNodeContainer(int32_t displayId); + void NotifyDisplayRemoved(int32_t displayId); + sptr GetWindowNode(uint32_t windowId) const; + + WMError SaveWindow(const sptr& node); + WMError AddWindowNode(uint32_t parentId, sptr& node); + WMError RemoveWindowNode(uint32_t windowId); + WMError DestroyWindow(uint32_t windowId); + const std::map>& GetWindowNodeContainerMap() const; + + WMError RequestFocus(uint32_t windowId); + WMError MinimizeOtherFullScreenAbility(sptr& node); + +private: + void ClearWindow(const sptr& remoteObject); + WMError DestroyWindowInner(sptr& node); + + std::map> windowNodeContainerMap_; + std::map> windowNodeMap_; + std::map, uint32_t> windowIdMap_; + + sptr windowDeath_ = new WindowDeathRecipient(std::bind(&WindowRoot::ClearWindow, + this, std::placeholders::_1)); +}; +} +} +#endif // OHOS_ROSEN_WINDOW_ROOT_H diff --git a/wmserver/include/window_zorder_policy.h b/wmserver/include/window_zorder_policy.h new file mode 100644 index 0000000000000000000000000000000000000000..8e91d3d664faa9e906e395d4d497652ae7d1ad99 --- /dev/null +++ b/wmserver/include/window_zorder_policy.h @@ -0,0 +1,63 @@ +/* + * Copyright (c) 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 OHOS_ROSEN_WINDOW_ZORDER_POLICY_H +#define OHOS_ROSEN_WINDOW_ZORDER_POLICY_H + +#include +#include + +#include "wm_common.h" + +namespace OHOS { +namespace Rosen { +class WindowZorderPolicy : public RefBase { +public: + WindowZorderPolicy() = default; + ~WindowZorderPolicy() = default; + + int32_t GetWindowPriority(WindowType type) const; + +private: + const std::map windowPriorityMap_ { + // sub-windows types + { WindowType::WINDOW_TYPE_MEDIA, -1 }, + { WindowType::WINDOW_TYPE_APP_SUB_WINDOW, 1 }, + + // main window + { WindowType::WINDOW_TYPE_APP_MAIN_WINDOW, 0 }, + + // system-specific window + { WindowType::WINDOW_TYPE_WALLPAPER, 101 }, + { WindowType::WINDOW_TYPE_APP_LAUNCHING, 102 }, + { WindowType::WINDOW_TYPE_DOCK_SLICE, 103 }, + { WindowType::WINDOW_TYPE_INCOMING_CALL, 104 }, + { WindowType::WINDOW_TYPE_SEARCHING_BAR, 105 }, + { WindowType::WINDOW_TYPE_SYSTEM_ALARM_WINDOW, 106 }, + { WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT, 107 }, + { WindowType::WINDOW_TYPE_FLOAT, 108 }, + { WindowType::WINDOW_TYPE_TOAST, 109 }, + { WindowType::WINDOW_TYPE_STATUS_BAR, 110 }, + { WindowType::WINDOW_TYPE_PANEL, 111 }, + { WindowType::WINDOW_TYPE_KEYGUARD, 112 }, + { WindowType::WINDOW_TYPE_VOLUME_OVERLAY, 113 }, + { WindowType::WINDOW_TYPE_NAVIGATION_BAR, 114 }, + { WindowType::WINDOW_TYPE_DRAGGING_EFFECT, 115 }, + { WindowType::WINDOW_TYPE_POINTER, 116 }, + }; +}; +} +} +#endif // OHOS_ROSEN_WINDOW_STATE_H diff --git a/wmserver/src/README.md b/wmserver/src/README.md new file mode 100644 index 0000000000000000000000000000000000000000..6aa13c7e6a88bfb1eafe50621b24c3d17b1c9acb --- /dev/null +++ b/wmserver/src/README.md @@ -0,0 +1 @@ +Store code of window server source files diff --git a/wmserver/src/input_window_monitor.cpp b/wmserver/src/input_window_monitor.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9dc6ff82a8cd355eebe41612d650631eec262bbd --- /dev/null +++ b/wmserver/src/input_window_monitor.cpp @@ -0,0 +1,87 @@ +/* + * Copyright (c) 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_window_monitor.h" + +#include + +#include + +#include "window_manager_hilog.h" + +namespace OHOS { +namespace Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "InputWindowMonitor"}; +} + +void InputWindowMonitor::UpdateInputWindow(uint32_t windowId) +{ + if (windowRoot_ == nullptr) { + WLOGFE("windowRoot is null."); + return; + } + sptr windowNode = windowRoot_->GetWindowNode(windowId); + if (windowNode == nullptr) { + WLOGFE("window node could not be found."); + return; + } + int32_t displayId = windowNode->GetDisplayId(); + auto container = windowRoot_->GetOrCreateWindowNodeContainer(displayId); + if (container == nullptr) { + WLOGFE("can not get window node container."); + return; + } + std::vector> windowNodes; + container->TraverseContainer(windowNodes); + + auto iter = std::find_if(logicalDisplays_.begin(), logicalDisplays_.end(), + [displayId](MMI::LogicalDisplayInfo& logicalDisplay) { + return logicalDisplay.id == displayId; + }); + if (iter != logicalDisplays_.end()) { + TraverseWindowNodes(windowNodes, iter); + if (!iter->windowsInfo_.empty()) { + iter->focusWindowId = container->GetFocusWindow(); + } + } else { + WLOGFE("There is no display for this window action."); + return; + } + WLOGFI("update display info to IMS."); + MMI::InputManager::GetInstance()->UpdateDisplayInfo(physicalDisplays_, logicalDisplays_); +} + +void InputWindowMonitor::TraverseWindowNodes(const std::vector> &windowNodes, + std::vector::iterator& iter) +{ + iter->windowsInfo_.clear(); + for (auto& windowNode: windowNodes) { + MMI::WindowInfo windowInfo = { + .id = static_cast(windowNode->GetWindowId()), + .pid = windowNode->GetCallingPid(), + .uid = windowNode->GetCallingUid(), + .topLeftX = windowNode->GetLayoutRects().rect_.posX_, + .topLeftY = windowNode->GetLayoutRects().rect_.posY_, + .width = static_cast(windowNode->GetLayoutRects().rect_.width_), + .height = static_cast(windowNode->GetLayoutRects().rect_.height_), + .displayId = windowNode->GetDisplayId(), + .agentWindowId = static_cast(windowNode->GetWindowId()), + }; + iter->windowsInfo_.emplace_back(windowInfo); + } +} +} +} \ No newline at end of file diff --git a/wmserver/src/window_controller.cpp b/wmserver/src/window_controller.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9f3dbe1ead73a03774e74706da4f41afca68733e --- /dev/null +++ b/wmserver/src/window_controller.cpp @@ -0,0 +1,153 @@ +/* + * Copyright (c) 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 "window_controller.h" +#include +#include "window_manager_hilog.h" + +namespace OHOS { +namespace Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "WindowController"}; +} +uint32_t WindowController::GenWindowId() +{ + return ++windowId_; +} + +WMError WindowController::CreateWindow(sptr& window, sptr& property, + const std::shared_ptr& surfaceNode, uint32_t& windowId) +{ + windowId = GenWindowId(); + property->SetWindowId(windowId); + + sptr node = new WindowNode(property, window, surfaceNode); + return windowRoot_->SaveWindow(node); +} + +WMError WindowController::SaveAbilityToken(const sptr& abilityToken, uint32_t windowId) +{ + auto node = windowRoot_->GetWindowNode(windowId); + if (node == nullptr) { + WLOGFE("could not find window"); + return WMError::WM_ERROR_NULLPTR; + } + node->abilityToken_ = abilityToken; + return WMError::WM_OK; +} + +WMError WindowController::AddWindowNode(sptr& property) +{ + auto node = windowRoot_->GetWindowNode(property->GetWindowId()); + if (node == nullptr) { + WLOGFE("could not find window"); + return WMError::WM_ERROR_NULLPTR; + } + node->SetWindowProperty(property); + // TODO: check permission + // TODO: adjust property + + WMError res = windowRoot_->AddWindowNode(property->GetParentId(), node); + if (res != WMError::WM_OK) { + return res; + } + res = LayoutWindowNodeTrees(); + RSTransaction::FlushImplicitTransaction(); + WLOGFI("AddWindowNode FlushImplicitTransaction end"); + + if (node->GetWindowMode() == WindowMode::WINDOW_MODE_FULLSCREEN) { + WLOGFI("need minimize previous fullscreen window if exists"); + WMError res = windowRoot_->MinimizeOtherFullScreenAbility(node); + if (res != WMError::WM_OK) { + WLOGFE("Minimize other fullscreen window failed"); + } + } + return res; +} + +WMError WindowController::LayoutWindowNodeTrees() +{ + auto& windowContainerMap = windowRoot_->GetWindowNodeContainerMap(); + if (windowContainerMap.empty()) { + WLOGFE("could not find window container"); + return WMError::WM_ERROR_INVALID_PARAM; + } + for (auto& iter : windowContainerMap) { + const sptr& windowContainer = iter.second; + WMError ret = windowContainer->LayoutWindowNodes(); + if (ret != WMError::WM_OK) { + return ret; + } + } + return WMError::WM_OK; +} + +WMError WindowController::RemoveWindowNode(uint32_t windowId) +{ + WMError res = windowRoot_->RemoveWindowNode(windowId); + if (res != WMError::WM_OK) { + return res; + } + res = LayoutWindowNodeTrees(); + RSTransaction::FlushImplicitTransaction(); + WLOGFI("RemoveWindowNode FlushImplicitTransaction end"); + return res; +} + +WMError WindowController::DestroyWindow(uint32_t windowId) +{ + WMError res = windowRoot_->DestroyWindow(windowId); + if (res != WMError::WM_OK) { + return res; + } + res = LayoutWindowNodeTrees(); + RSTransaction::FlushImplicitTransaction(); + WLOGFI("DestroyWindow FlushImplicitTransaction end"); + return res; +} + +WMError WindowController::MoveTo(uint32_t windowId, int32_t x, int32_t y) +{ + auto node = windowRoot_->GetWindowNode(windowId); + if (node == nullptr) { + WLOGFE("could not find window"); + return WMError::WM_ERROR_NULLPTR; + } + Vector2f pos(x, y); + node->surfaceNode_->SetBoundsPosition(pos); + RSTransaction::FlushImplicitTransaction(); + WLOGFI("MoveTo FlushImplicitTransaction end"); + return WMError::WM_OK; +} + +WMError WindowController::Resize(uint32_t windowId, uint32_t width, uint32_t height) +{ + auto node = windowRoot_->GetWindowNode(windowId); + if (node == nullptr) { + WLOGFE("could not find window"); + return WMError::WM_ERROR_NULLPTR; + } + node->surfaceNode_->SetBoundsSize(width, height); + RSTransaction::FlushImplicitTransaction(); + WLOGFI("Resize FlushImplicitTransaction end"); + return WMError::WM_OK; +} + +WMError WindowController::RequestFocus(uint32_t windowId) +{ + return windowRoot_->RequestFocus(windowId); +} +} +} diff --git a/wmserver/src/window_layout_policy.cpp b/wmserver/src/window_layout_policy.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c90a5f030e760c1592fbb39b7276fb0ab9569b62 --- /dev/null +++ b/wmserver/src/window_layout_policy.cpp @@ -0,0 +1,184 @@ +/* + * Copyright (c) 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 "window_layout_policy.h" +#include "window_manager_hilog.h" + +namespace OHOS { +namespace Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "WindowLayoutPolicy"}; +} + +WMError WindowLayoutPolicy::UpdateDisplayInfo(const Rect& displayRect) +{ + if (displayRect.height_ == 0 || displayRect.width_ == 0) { + return WMError::WM_ERROR_INVALID_PARAM; + } + displayRect_ = displayRect; + limitRect_ = displayRect; + aviodNodes_.clear(); + return WMError::WM_OK; +} + +WMError WindowLayoutPolicy::LayoutWindow(sptr& node) +{ + if (node->GetWindowType() >= WindowType::SYSTEM_WINDOW_END) { + WLOGFE("unknown window type!"); + return WMError::WM_ERROR_INVALID_PARAM; + } + UpdateLayoutRects(node); + if (aviodTypes_.find(node->GetWindowType()) != aviodTypes_.end()) { + RecordAvoidRect(node); + } + return WMError::WM_OK; +} + +bool WindowLayoutPolicy::IsRectChanged(const Rect& l, const Rect& r) +{ + return !((l.posX_ == r.posX_) && (l.posY_ == r.posY_) && (l.width_ == r.width_) && (l.height_ == r.height_)); +} + +bool WindowLayoutPolicy::UpdateLayoutRects(sptr& node) +{ + bool needAvoid = IsNeedAvoidNode(node); + bool fullScreen = IsFullScreenNode(node); + bool parentLimit = IsParentLimitNode(node); + bool subWindow = (node->GetWindowType() == WindowType::WINDOW_TYPE_APP_SUB_WINDOW); + bool floatingWindow = (node->GetWindowMode() == WindowMode::WINDOW_MODE_FLOATING); + WLOGFI("Id:%{public}d, avoid:%{public}d fullS:%{public}d parLimit:%{public}d float:%{public}d, types:%{public}d", + node->GetWindowId(), needAvoid, fullScreen, parentLimit, floatingWindow, + static_cast(node->GetWindowType())); + const LayoutRects& layoutRects = node->GetLayoutRects(); + Rect lastRect = layoutRects.rect_; + Rect dRect = layoutRects.displayRect_; + Rect pRect = layoutRects.parentRect_; + Rect lRect = layoutRects.limitRect_; + Rect winRect = node->GetWindowProperty()->GetWindowRect(); + + if (needAvoid) { + dRect = limitRect_; + } else { + dRect = displayRect_; + } + + if (subWindow) { + pRect = node->parent_->GetLayoutRects().rect_; + } else { + pRect = dRect; + } + + if (parentLimit) { + lRect = pRect; + } else { + lRect = dRect; + } + + if (fullScreen) { + winRect = lRect; + } else if (!floatingWindow) { + winRect.width_ = std::min(lRect.width_, winRect.width_); + winRect.height_ = std::min(lRect.height_, winRect.height_); + winRect.posX_ = std::max(lRect.posX_, winRect.posX_); + winRect.posY_ = std::max(lRect.posY_, winRect.posY_); + winRect.posX_ = std::min( + lRect.posX_ + static_cast(lRect.width_) - static_cast(winRect.width_), + winRect.posX_); + winRect.posY_ = std::min( + lRect.posY_ + static_cast(lRect.height_) - static_cast(winRect.height_), + winRect.posY_); + } + node->UpdateLayoutRects({ dRect, pRect, lRect, winRect }); + if (IsRectChanged(lastRect, winRect)) { + node->GetWindowToken()->UpdateWindowRect(winRect); + node->surfaceNode_->SetBounds(winRect.posX_, winRect.posY_, winRect.width_, winRect.height_); + WLOGFI("UpdateLayoutRects for winId: %{public}d, Rect: %{public}d %{public}d %{public}d %{public}d", + node->GetWindowId(), winRect.posX_, winRect.posY_, winRect.width_, winRect.height_); + return true; + } + WLOGFI("UpdateLayoutRects rect not changed for winId: %{public}d", node->GetWindowId()); + return false; +} + +void WindowLayoutPolicy::UpdateLimitRect(const sptr& node) +{ + auto& layoutRects = node->GetLayoutRects(); + if (node->GetWindowType() == WindowType::WINDOW_TYPE_STATUS_BAR) { // STATUS_BAR + int32_t boundTop = limitRect_.posY_; + int32_t rectBottom = layoutRects.rect_.posY_ + layoutRects.rect_.height_; + int32_t offsetH = rectBottom - boundTop; + limitRect_.posY_ += offsetH; + limitRect_.height_ -= offsetH; + } else if (node->GetWindowType() == WindowType::WINDOW_TYPE_NAVIGATION_BAR) { // NAVIGATION_BAR + int32_t boundBottom = limitRect_.posY_ + limitRect_.height_; + int32_t offsetH = boundBottom - layoutRects.rect_.posY_; + limitRect_.height_ -= offsetH; + } + WLOGFI("after add WinId: %{public}d, limitRect: %{public}d %{public}d %{public}d %{public}d", + node->GetWindowId(), limitRect_.posX_, limitRect_.posY_, limitRect_.width_, limitRect_.height_); +} + +void WindowLayoutPolicy::RecordAvoidRect(const sptr& node) +{ + uint32_t id = node->GetWindowId(); + if (aviodNodes_.find(id) == aviodNodes_.end()) { // new avoid rect + aviodNodes_.insert(std::pair>(id, node)); + UpdateLimitRect(node); + } else { // update existing avoid rect + limitRect_ = displayRect_; + aviodNodes_[id] = node; + for (auto item : aviodNodes_) { + UpdateLimitRect(item.second); + } + } +} + +bool WindowLayoutPolicy::IsNeedAvoidNode(const sptr& node) +{ + auto type = node->GetWindowType(); + auto mode = node->GetWindowMode(); + auto flags = node->GetWindowFlags(); + if (mode == WindowMode::WINDOW_MODE_FLOATING) { + return false; + } + if (type >= WindowType::APP_WINDOW_BASE && + type <= WindowType::APP_SUB_WINDOW_END && + (flags & static_cast(WindowFlag::WINDOW_FLAG_NEED_AVOID))) { + return true; + } + return false; +} + +bool WindowLayoutPolicy::IsFullScreenNode(const sptr& node) +{ + auto mode = node->GetWindowMode(); + if (mode == WindowMode::WINDOW_MODE_FULLSCREEN || mode == WindowMode::WINDOW_MODE_SPLIT) { + return true; + } + return false; +} + +bool WindowLayoutPolicy::IsParentLimitNode(const sptr& node) +{ + auto mode = node->GetWindowMode(); + auto flags = node->GetWindowFlags(); + if (mode != WindowMode::WINDOW_MODE_FLOATING && + (flags & static_cast(WindowFlag::WINDOW_FLAG_PARENT_LIMIT))) { + return true; + } + return false; +} +} +} diff --git a/wmserver/src/window_manager_proxy.cpp b/wmserver/src/window_manager_proxy.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f1f2da589e9d5dfbfddf5c866bbe454f542d8c45 --- /dev/null +++ b/wmserver/src/window_manager_proxy.cpp @@ -0,0 +1,247 @@ +/* + * Copyright (c) 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 "window_manager_proxy.h" +#include +#include "window_manager_hilog.h" + +namespace OHOS { +namespace Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "WindowManagerProxy"}; +} + + +WMError WindowManagerProxy::CreateWindow(sptr& window, sptr& property, + const std::shared_ptr& surfaceNode, uint32_t& windowId) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!data.WriteInterfaceToken(GetDescriptor())) { + WLOGFE("WriteInterfaceToken failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + + if (!data.WriteRemoteObject(window->AsObject())) { + WLOGFE("Write IWindow failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + + if (!data.WriteParcelable(property.GetRefPtr())) { + WLOGFE("Write windowProperty failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + + if (!data.WriteParcelable(surfaceNode.get())) { + WLOGFE("Write windowProperty failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + + if (Remote()->SendRequest(TRANS_ID_CREATE_WINDOW, data, reply, option) != ERR_NONE) { + return WMError::WM_ERROR_IPC_FAILED; + } + windowId = reply.ReadUint32(); + int32_t ret = reply.ReadInt32(); + return static_cast(ret); +} + +WMError WindowManagerProxy::AddWindow(sptr& property) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!data.WriteInterfaceToken(GetDescriptor())) { + WLOGFE("WriteInterfaceToken failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + + if (!data.WriteParcelable(property.GetRefPtr())) { + WLOGFE("Write windowProperty failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + + if (Remote()->SendRequest(TRANS_ID_ADD_WINDOW, data, reply, option) != ERR_NONE) { + return WMError::WM_ERROR_IPC_FAILED; + } + + int32_t ret = reply.ReadInt32(); + return static_cast(ret); +} + +WMError WindowManagerProxy::RemoveWindow(uint32_t windowId) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!data.WriteInterfaceToken(GetDescriptor())) { + WLOGFE("WriteInterfaceToken failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + + if (!data.WriteUint32(windowId)) { + WLOGFE("Write windowId failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + + if (Remote()->SendRequest(TRANS_ID_REMOVE_WINDOW, data, reply, option) != ERR_NONE) { + return WMError::WM_ERROR_IPC_FAILED; + } + + int32_t ret = reply.ReadInt32(); + return static_cast(ret); +} + +WMError WindowManagerProxy::DestroyWindow(uint32_t windowId) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!data.WriteInterfaceToken(GetDescriptor())) { + WLOGFE("WriteInterfaceToken failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + + if (!data.WriteUint32(windowId)) { + WLOGFE("Write windowId failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + + if (Remote()->SendRequest(TRANS_ID_DESTROY_WINDOW, data, reply, option) != ERR_NONE) { + return WMError::WM_ERROR_IPC_FAILED; + } + + int32_t ret = reply.ReadInt32(); + return static_cast(ret); +} + +WMError WindowManagerProxy::MoveTo(uint32_t windowId, int32_t x, int32_t y) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!data.WriteInterfaceToken(GetDescriptor())) { + WLOGFE("WriteInterfaceToken failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + + if (!data.WriteUint32(windowId)) { + WLOGFE("Write windowId failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + + if (!data.WriteInt32(x)) { + WLOGFE("Write posX failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + + if (!data.WriteInt32(y)) { + WLOGFE("Write posY failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + + if (Remote()->SendRequest(TRANS_ID_MOVE, data, reply, option) != ERR_NONE) { + return WMError::WM_ERROR_IPC_FAILED; + } + + int32_t ret = reply.ReadInt32(); + return static_cast(ret); +} + +WMError WindowManagerProxy::Resize(uint32_t windowId, uint32_t width, uint32_t height) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!data.WriteInterfaceToken(GetDescriptor())) { + WLOGFE("WriteInterfaceToken failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + + if (!data.WriteUint32(windowId)) { + WLOGFE("Write windowId failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + + if (!data.WriteUint32(width)) { + WLOGFE("Write width failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + + if (!data.WriteUint32(height)) { + WLOGFE("Write height failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + + if (Remote()->SendRequest(TRANS_ID_RESIZE, data, reply, option) != ERR_NONE) { + return WMError::WM_ERROR_IPC_FAILED; + } + + int32_t ret = reply.ReadInt32(); + return static_cast(ret); +} + +WMError WindowManagerProxy::RequestFocus(uint32_t windowId) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!data.WriteInterfaceToken(GetDescriptor())) { + WLOGFE("WriteInterfaceToken failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + + if (!data.WriteUint32(windowId)) { + WLOGFE("Write windowId failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + if (Remote()->SendRequest(TRANS_ID_REQUEST_FOCUS, data, reply, option) != ERR_NONE) { + return WMError::WM_ERROR_IPC_FAILED; + } + + int32_t ret = reply.ReadInt32(); + return static_cast(ret); +} + +WMError WindowManagerProxy::SaveAbilityToken(const sptr& abilityToken, uint32_t windowId) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!data.WriteInterfaceToken(GetDescriptor())) { + WLOGFE("WriteInterfaceToken failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + + if (!data.WriteRemoteObject(abilityToken)) { + WLOGFE("Write abilityToken failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + + if (!data.WriteUint32(windowId)) { + WLOGFE("Write windowId failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + + if (Remote()->SendRequest(TRANS_ID_SEND_ABILITY_TOKEN, data, reply, option) != ERR_NONE) { + return WMError::WM_ERROR_IPC_FAILED; + } + + int32_t ret = reply.ReadInt32(); + return static_cast(ret); +} +} +} + diff --git a/wmserver/src/window_manager_service.cpp b/wmserver/src/window_manager_service.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7c70a580ba2556d99dc3417daa42011c34f95781 --- /dev/null +++ b/wmserver/src/window_manager_service.cpp @@ -0,0 +1,134 @@ +/* + * Copyright (c) 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 "window_manager_service.h" + +#include + +#include +#include + +#include "window_manager_hilog.h" + +namespace OHOS { +namespace Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "WindowManagerService"}; +} + +IMPLEMENT_SINGLE_INSTANCE(WindowManagerService); + +const bool REGISTER_RESULT = SystemAbility::MakeAndRegisterAbility( + SingletonContainer::Get().GetRefPtr()); + +WindowManagerService::WindowManagerService() : SystemAbility(WINDOW_MANAGER_SERVICE_ID, true) +{ + windowRoot_ = new WindowRoot(); + windowController_ = new WindowController(windowRoot_); + inputWindowMonitor_ = new InputWindowMonitor(windowRoot_); +} + +void WindowManagerService::OnStart() +{ + WLOGFI("WindowManagerService::OnStart start"); + if (!Init()) { + return; + } +} + +bool WindowManagerService::Init() +{ + WLOGFI("WindowManagerService::Init start"); + bool ret = Publish(this); + if (!ret) { + WLOGFW("WindowManagerService::Init failed"); + return false; + } + WLOGFI("WindowManagerService::Init success"); + sleep(10); // for RS temporary + return true; +} + +void WindowManagerService::OnStop() +{ + WLOGFI("ready to stop service."); +} + +WMError WindowManagerService::CreateWindow(sptr& window, sptr& property, + const std::shared_ptr& surfaceNode, uint32_t& windowId) +{ + if (window == nullptr || property == nullptr || surfaceNode == nullptr) { + WLOGFE("window is invalid"); + return WMError::WM_ERROR_NULLPTR; + } + std::lock_guard lock(mutex_); + return windowController_->CreateWindow(window, property, surfaceNode, windowId); +} + +WMError WindowManagerService::AddWindow(sptr& property) +{ + std::lock_guard lock(mutex_); + WMError res = windowController_->AddWindowNode(property); + if (res == WMError::WM_OK) { + inputWindowMonitor_->UpdateInputWindow(property->GetWindowId()); + } + return res; +} + +WMError WindowManagerService::RemoveWindow(uint32_t windowId) +{ + std::lock_guard lock(mutex_); + WMError res = windowController_->RemoveWindowNode(windowId); + if (res == WMError::WM_OK) { + inputWindowMonitor_->UpdateInputWindow(windowId); + } + return res; +} + +WMError WindowManagerService::DestroyWindow(uint32_t windowId) +{ + std::lock_guard lock(mutex_); + WMError res = windowController_->DestroyWindow(windowId); + if (res == WMError::WM_OK) { + inputWindowMonitor_->UpdateInputWindow(windowId); + } + return res; +} + +WMError WindowManagerService::MoveTo(uint32_t windowId, int32_t x, int32_t y) +{ + std::lock_guard lock(mutex_); + return windowController_->MoveTo(windowId, x, y); +} + +WMError WindowManagerService::Resize(uint32_t windowId, uint32_t width, uint32_t height) +{ + std::lock_guard lock(mutex_); + return windowController_->Resize(windowId, width, height); +} + +WMError WindowManagerService::RequestFocus(uint32_t windowId) +{ + std::lock_guard lock(mutex_); + return windowController_->RequestFocus(windowId); +} + +WMError WindowManagerService::SaveAbilityToken(const sptr& abilityToken, uint32_t windowId) +{ + std::lock_guard lock(mutex_); + return windowController_->SaveAbilityToken(abilityToken, windowId); +} +} +} \ No newline at end of file diff --git a/wmserver/src/window_manager_stub.cpp b/wmserver/src/window_manager_stub.cpp new file mode 100644 index 0000000000000000000000000000000000000000..cd18fed9f453d28c2d7cf2daab8ce8e8780da4d1 --- /dev/null +++ b/wmserver/src/window_manager_stub.cpp @@ -0,0 +1,101 @@ +/* + * Copyright (c) 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 "window_manager_stub.h" +#include +#include "window_manager_hilog.h" + +namespace OHOS { +namespace Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "WindowManagerStub"}; +} + +int32_t WindowManagerStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, + MessageOption &option) +{ + WLOGFI("WindowManagerStub::OnRemoteRequest code is %{public}d", code); + if (data.ReadInterfaceToken() != GetDescriptor()) { + WLOGFE("InterfaceToken check failed"); + return -1; + } + switch (code) { + case TRANS_ID_CREATE_WINDOW: { + sptr windowObject = data.ReadRemoteObject(); + sptr windowProxy = iface_cast(windowObject); + sptr windowProperty = data.ReadStrongParcelable(); + std::shared_ptr surfaceNode(data.ReadParcelable()); + uint32_t windowId; + WMError errCode = CreateWindow(windowProxy, windowProperty, surfaceNode, windowId); + reply.WriteUint32(windowId); + reply.WriteInt32(static_cast(errCode)); + break; + } + case TRANS_ID_ADD_WINDOW: { + sptr windowProperty = data.ReadStrongParcelable(); + WMError errCode = AddWindow(windowProperty); + reply.WriteInt32(static_cast(errCode)); + break; + } + case TRANS_ID_REMOVE_WINDOW: { + uint32_t windowId = data.ReadUint32(); + WMError errCode = RemoveWindow(windowId); + reply.WriteInt32(static_cast(errCode)); + break; + } + case TRANS_ID_DESTROY_WINDOW: { + uint32_t windowId = data.ReadUint32(); + WMError errCode = DestroyWindow(windowId); + reply.WriteInt32(static_cast(errCode)); + break; + } + case TRANS_ID_MOVE: { + uint32_t windowId = data.ReadUint32(); + int32_t x = data.ReadInt32(); + int32_t y = data.ReadInt32(); + WMError errCode = MoveTo(windowId, x, y); + reply.WriteInt32(static_cast(errCode)); + break; + } + case TRANS_ID_RESIZE: { + uint32_t windowId = data.ReadUint32(); + uint32_t width = data.ReadUint32(); + uint32_t height = data.ReadUint32(); + WMError errCode = Resize(windowId, width, height); + reply.WriteInt32(static_cast(errCode)); + break; + } + case TRANS_ID_REQUEST_FOCUS: { + uint32_t windowId = data.ReadUint32(); + WMError errCode = RequestFocus(windowId); + reply.WriteInt32(static_cast(errCode)); + break; + } + + case TRANS_ID_SEND_ABILITY_TOKEN: { + sptr abilityToken = data.ReadRemoteObject(); + uint32_t windowId = data.ReadUint32(); + WMError errCode = SaveAbilityToken(abilityToken, windowId); + reply.WriteInt32(static_cast(errCode)); + break; + } + default: + WLOGFW("unknown transaction code"); + return IPCObjectStub::OnRemoteRequest(code, data, reply, option); + } + return 0; +} +} +} diff --git a/wmserver/src/window_node.cpp b/wmserver/src/window_node.cpp new file mode 100644 index 0000000000000000000000000000000000000000..389d4f367782c55b13a7622c7f03a38459e66649 --- /dev/null +++ b/wmserver/src/window_node.cpp @@ -0,0 +1,86 @@ +/* + * Copyright (c) 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 "window_node.h" +#include "window_manager_hilog.h" + +namespace OHOS { +namespace Rosen { +void WindowNode::SetDisplayId(int32_t displayId) +{ + property_->SetDisplayId(displayId); +} + +void WindowNode::UpdateLayoutRects(const LayoutRects& rects) +{ + layoutRects_ = rects; +} + +void WindowNode::SetWindowProperty(const sptr& property) +{ + property_ = property; +} + +const sptr& WindowNode::GetWindowToken() const +{ + return windowToken_; +} + +int32_t WindowNode::GetDisplayId() const +{ + return property_->GetDisplayId(); +} + +uint32_t WindowNode::GetWindowId() const +{ + return property_->GetWindowId(); +} + +const LayoutRects& WindowNode::GetLayoutRects() const +{ + return layoutRects_; +} + +WindowType WindowNode::GetWindowType() const +{ + return property_->GetWindowType(); +} + +WindowMode WindowNode::GetWindowMode() const +{ + return property_->GetWindowMode(); +} + +uint32_t WindowNode::GetWindowFlags() const +{ + return property_->GetWindowFlags(); +} + +const sptr& WindowNode::GetWindowProperty() const +{ + return property_; +} + +int32_t WindowNode::GetCallingPid() const +{ + return callingPid_; +} + +int32_t WindowNode::GetCallingUid() const +{ + return callingUid_; +} +} +} diff --git a/wmserver/src/window_node_container.cpp b/wmserver/src/window_node_container.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f4ed70a0c0ba6898056e4fe2075e8e8081495be3 --- /dev/null +++ b/wmserver/src/window_node_container.cpp @@ -0,0 +1,366 @@ +/* + * Copyright (c) 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 "window_node_container.h" +#include +#include +#include "window_manager_hilog.h" + +namespace OHOS { +namespace Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "WindowNodeContainer"}; +} + +WindowNodeContainer::~WindowNodeContainer() +{ + Destroy(); +} + +WMError WindowNodeContainer::MinimizeOtherFullScreenAbility() +{ + if (appWindowNode_->children_.empty()) { + WLOGFI("no appWindowNode, return"); + return WMError::WM_OK; + } + for (auto iter = appWindowNode_->children_.begin(); iter < appWindowNode_->children_.end() - 1; ++iter) { + if ((*iter)->GetWindowMode() != WindowMode::WINDOW_MODE_FULLSCREEN) { + continue; + } + WLOGFI("find previous fullscreen window"); + if ((*iter)->abilityToken_ != nullptr) { + WLOGFI("notify ability to minimize"); + AAFwk::AbilityManagerClient::GetInstance()->MinimizeAbility((*iter)->abilityToken_); + } + } + return WMError::WM_OK; +} + +WMError WindowNodeContainer::AddWindowNode(sptr& node, sptr& parentNode) +{ + if (!node->surfaceNode_ || !displayNode_) { + WLOGFE("surface node or display node is nullptr!"); + return WMError::WM_ERROR_NULLPTR; + } + sptr root = FindRoot(node->GetWindowType()); + if (root == nullptr) { + WLOGFE("root window node is nullptr!"); + return WMError::WM_ERROR_NULLPTR; + } + node->requestedVisibility_ = true; + if (parentNode != nullptr) { // subwindow + if (parentNode->parent_ != root) { + WLOGFE("window type and parent window not match or try to add subwindow to subwindow, which is forbidden"); + return WMError::WM_ERROR_INVALID_PARAM; + } + node->currentVisibility_ = parentNode->currentVisibility_; + } else { // mainwindow + parentNode = root; + node->currentVisibility_ = true; + for (auto& child : node->children_) { + child->currentVisibility_ = child->requestedVisibility_; + } + } + node->parent_ = parentNode; + + UpdateWindowTree(node); + UpdateRSTree(node, true); + AssignZOrder(); + UpdateFocusWindow(); + WLOGFI("AddWindowNode windowId: %{public}d end", node->GetWindowId()); + return WMError::WM_OK; +} + +void WindowNodeContainer::UpdateWindowTree(sptr& node) +{ + node->priority_ = zorderPolicy_->GetWindowPriority(node->GetWindowType()); + auto parentNode = node->parent_; + auto position = parentNode->children_.end(); + for (auto iter = parentNode->children_.begin(); iter < parentNode->children_.end(); ++iter) { + if ((*iter)->priority_ > node->priority_) { + position = iter; + break; + } + } + parentNode->children_.insert(position, node); +} + +bool WindowNodeContainer::UpdateRSTree(sptr& node, bool isAdd) +{ + if (displayNode_ == nullptr) { + WLOGFE("displayNode_ is nullptr"); + return false; + } + if (isAdd) { + displayNode_->AddChild(node->surfaceNode_, -1); + for (auto& child : node->children_) { + if (child->currentVisibility_) { + displayNode_->AddChild(child->surfaceNode_, -1); + } + } + } else { + displayNode_->RemoveChild(node->surfaceNode_); + for (auto& child : node->children_) { + displayNode_->RemoveChild(child->surfaceNode_); + } + } + return true; +} + +WMError WindowNodeContainer::DestroyWindowNode(sptr& node, std::vector& windowIds) +{ + WMError ret = RemoveWindowNode(node); + if (ret != WMError::WM_OK) { + return ret; + } + node->surfaceNode_ = nullptr; + windowIds.push_back(node->GetWindowId()); + + for (auto& child : node->children_) { // destroy sub window if exists + windowIds.push_back(child->GetWindowId()); + child->parent_ = nullptr; + if (child->surfaceNode_ != nullptr && displayNode_ != nullptr) { + displayNode_->RemoveChild(child->surfaceNode_); + child->surfaceNode_ = nullptr; + } + } + node->children_.clear(); + WLOGFI("DestroyWindowNode windowId: %{public}d end", node->GetWindowId()); + return WMError::WM_OK; +} + +WMError WindowNodeContainer::LayoutWindowNodes() +{ + WMError ret = WMError::WM_OK; + layoutPolicy_->UpdateDisplayInfo(displayRect_); + std::vector> rootNodes = { aboveAppWindowNode_, appWindowNode_, belowAppWindowNode_ }; + for (auto& node : rootNodes) { // ensure that the avoid area windows are traversed first + ret = LayoutWindowNode(node); + if (ret != WMError::WM_OK) { + return ret; + } + } + return ret; +} + +WMError WindowNodeContainer::LayoutWindowNode(sptr& node) +{ + WMError ret = WMError::WM_OK; + if (node->parent_ != nullptr) { // isn't root node + ret = layoutPolicy_->LayoutWindow(node); + if (ret != WMError::WM_OK) { + return ret; + } + } + for (auto& childNode : node->children_) { + ret = LayoutWindowNode(childNode); + if (ret != WMError::WM_OK) { + return ret; + } + } + return ret; +} + +WMError WindowNodeContainer::RemoveWindowNode(sptr& node) +{ + if (node == nullptr || !node->surfaceNode_) { + WLOGFE("window node or surface node is nullptr, invalid"); + return WMError::WM_ERROR_DESTROYED_OBJECT; + } + + if (node->parent_ == nullptr) { + WLOGFW("can't find parent of this node"); + } else { + // remove this node from parent + auto iter = std::find(node->parent_->children_.begin(), node->parent_->children_.end(), node); + if (iter != node->parent_->children_.end()) { + node->parent_->children_.erase(iter); + } else { + WLOGFE("can't find this node in parent"); + } + node->parent_ = nullptr; + } + node->requestedVisibility_ = false; + node->currentVisibility_ = false; + for (auto& child : node->children_) { + child->currentVisibility_ = false; + } + UpdateRSTree(node, false); + UpdateFocusWindow(); + WLOGFI("RemoveWindowNode windowId: %{public}d end", node->GetWindowId()); + return WMError::WM_OK; +} + +const std::vector& WindowNodeContainer::Destroy() +{ + removedIds_.clear(); + for (auto& node : belowAppWindowNode_->children_) { + DestroyWindowNode(node, removedIds_); + } + for (auto& node : appWindowNode_->children_) { + DestroyWindowNode(node, removedIds_); + } + for (auto& node : aboveAppWindowNode_->children_) { + DestroyWindowNode(node, removedIds_); + } + displayNode_ = nullptr; + return removedIds_; +} + +sptr WindowNodeContainer::FindRoot(WindowType type) const +{ + if (type >= WindowType::APP_WINDOW_BASE && type <= WindowType::APP_SUB_WINDOW_END) { + return appWindowNode_; + } else if (type < WindowType::ABOVE_APP_SYSTEM_WINDOW_BASE) { + return belowAppWindowNode_; + } else { + return aboveAppWindowNode_; + } +} + +void WindowNodeContainer::UpdateFocusWindow() +{ + for (auto iter = appWindowNode_->children_.rbegin(); iter < appWindowNode_->children_.rend(); iter++) { + if ((*iter)->GetWindowProperty()->GetFocusable()) { + WLOGFI("find focused id %{public}d;", (*iter)->GetWindowId()); + SetFocusWindow((*iter)->GetWindowId()); + break; + } + } +} + +sptr WindowNodeContainer::FindWindowNodeById(uint32_t id) const +{ + std::vector> rootNodes = { aboveAppWindowNode_, appWindowNode_, belowAppWindowNode_ }; + for (auto& rootNode : rootNodes) { + for (auto& node : rootNode->children_) { + if (node->GetWindowId() == id) { + return node; + } + for (auto& subNode : node->children_) { + if (subNode->GetWindowId() == id) { + return subNode; + } + } + } + } + return nullptr; +} + +void WindowNodeContainer::UpdateFocusStatus(uint32_t id, bool focused) const +{ + auto node = FindWindowNodeById(id); + if (node == nullptr) { + WLOGFW("cannot find old focused window id:%{public}d", id); + } else { + node->GetWindowToken()->UpdateFocusStatus(focused); + } +} + +void WindowNodeContainer::AssignZOrder() +{ + zOrder_ = 0; + for (auto& node : belowAppWindowNode_->children_) { + AssignZOrder(node); + } + for (auto& node : appWindowNode_->children_) { + AssignZOrder(node); + } + for (auto& node : aboveAppWindowNode_->children_) { + AssignZOrder(node); + } +} + +void WindowNodeContainer::AssignZOrder(sptr& node) +{ + if (node == nullptr) { + return; + } + auto iter = node->children_.begin(); + for (; iter < node->children_.end(); ++iter) { + if ((*iter)->priority_ < 0) { + if ((*iter)->surfaceNode_) { + (*iter)->surfaceNode_->SetPositionZ(zOrder_); + WLOGFI("for subWindow id %{public}d; zOrder:%{public}d", (*iter)->GetWindowId(), zOrder_); + ++zOrder_; + } + } else { + break; + } + } + if (node->surfaceNode_) { + node->surfaceNode_->SetPositionZ(zOrder_); + WLOGFI("window id:%{public}d; zOrder:%{public}d", node->GetWindowId(), zOrder_); + ++zOrder_; + } + for (; iter < node->children_.end(); ++iter) { + if ((*iter)->surfaceNode_) { + (*iter)->surfaceNode_->SetPositionZ(zOrder_); + WLOGFI("for subWindow id %{public}d; zOrder:%{public}d", (*iter)->GetWindowId(), zOrder_); + ++zOrder_; + } + } +} + +WMError WindowNodeContainer::SetFocusWindow(uint32_t windowId) +{ + if (focusedWindow_ == windowId) { + return WMError::WM_OK; + } + UpdateFocusStatus(focusedWindow_, false); + focusedWindow_ = windowId; + UpdateFocusStatus(focusedWindow_, true); + return WMError::WM_OK; +} + +uint32_t WindowNodeContainer::GetFocusWindow() const +{ + return focusedWindow_; +} + +void WindowNodeContainer::TraverseContainer(std::vector>& windowNodes) +{ + for (auto& node : belowAppWindowNode_->children_) { + TraverseWindowNode(node, windowNodes); + } + for (auto& node : appWindowNode_->children_) { + TraverseWindowNode(node, windowNodes); + } + for (auto& node : aboveAppWindowNode_->children_) { + TraverseWindowNode(node, windowNodes); + } + std::reverse(windowNodes.begin(), windowNodes.end()); +} + +void WindowNodeContainer::TraverseWindowNode(sptr& node, std::vector>& windowNodes) +{ + if (node == nullptr) { + return; + } + auto iter = node->children_.begin(); + for (; iter < node->children_.end(); ++iter) { + if ((*iter)->priority_ < 0) { + windowNodes.emplace_back(*iter); + } else { + break; + } + } + windowNodes.emplace_back(node); + for (; iter < node->children_.end(); ++iter) { + windowNodes.emplace_back(*iter); + } +} +} +} diff --git a/wmserver/src/window_root.cpp b/wmserver/src/window_root.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ac626427923ab10c2b54dcf0e55686fcff4ca5d5 --- /dev/null +++ b/wmserver/src/window_root.cpp @@ -0,0 +1,219 @@ +/* + * Copyright (c) 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 "window_root.h" +#include "display_manager_service_inner.h" +#include "window_manager_hilog.h" + +namespace OHOS { +namespace Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "WindowRoot"}; +} +sptr WindowRoot::GetOrCreateWindowNodeContainer(int32_t displayId) +{ + auto iter = windowNodeContainerMap_.find(displayId); + if (iter != windowNodeContainerMap_.end()) { + return iter->second; + } + auto displayScreen = DisplayManagerServiceInner::GetInstance()->GetDisplayById(displayId); + if (displayScreen == nullptr) { + WLOGFE("get display failed displayId:%{public}d", displayId); + return nullptr; + } + WLOGFI("create new window node container display width:%{public}d, height:%{public}d, screenId:%{public}llu", + displayScreen->GetWidth(), displayScreen->GetHeight(), displayScreen->GetId()); + sptr container = new WindowNodeContainer(displayScreen->GetId(), + static_cast(displayScreen->GetWidth()), static_cast(displayScreen->GetHeight())); + windowNodeContainerMap_.insert({ displayId, container }); + return container; +} + +const std::map>& WindowRoot::GetWindowNodeContainerMap() const +{ + return windowNodeContainerMap_; +} + +void WindowRoot::NotifyDisplayRemoved(int32_t displayId) +{ + auto container = GetOrCreateWindowNodeContainer(displayId); + if (container == nullptr) { + WLOGFI("this display does not have any window"); + return; + } + std::vector windowIds = container->Destroy(); + for (auto id : windowIds) { + auto node = GetWindowNode(id); + DestroyWindowInner(node); + } + windowNodeContainerMap_.erase(displayId); +} + +sptr WindowRoot::GetWindowNode(uint32_t windowId) const +{ + auto iter = windowNodeMap_.find(windowId); + if (iter == windowNodeMap_.end()) { + WLOGFE("window node could not be found"); + return nullptr; + } + return iter->second; +} + +WMError WindowRoot::SaveWindow(const sptr& node) +{ + if (node == nullptr) { + WLOGFE("add window failed, node is nullptr"); + return WMError::WM_ERROR_NULLPTR; + } + WLOGFI("save windowId %{public}d", node->GetWindowId()); + windowNodeMap_.insert({ node->GetWindowId(), node }); + auto remoteObject = node->GetWindowToken()->AsObject(); + windowIdMap_.insert({ remoteObject, node->GetWindowId() }); + + if (windowDeath_ == nullptr) { + WLOGFI("failed to create death Recipient ptr WindowDeathRecipient"); + } + if (!remoteObject->AddDeathRecipient(windowDeath_)) { + WLOGFI("failed to add death recipient"); + } + return WMError::WM_OK; +} + +WMError WindowRoot::MinimizeOtherFullScreenAbility(sptr& node) +{ + auto container = GetOrCreateWindowNodeContainer(node->GetDisplayId()); + if (container == nullptr) { + WLOGFE("MinimizeAbility failed, window container could not be found"); + return WMError::WM_ERROR_NULLPTR; + } + return container->MinimizeOtherFullScreenAbility(); +} + +WMError WindowRoot::AddWindowNode(uint32_t parentId, sptr& node) +{ + if (node == nullptr) { + WLOGFE("add window failed, node is nullptr"); + return WMError::WM_ERROR_NULLPTR; + } + auto parentNode = GetWindowNode(parentId); + + auto container = GetOrCreateWindowNodeContainer(node->GetDisplayId()); + if (container == nullptr) { + WLOGFE("add window failed, window container could not be found"); + return WMError::WM_ERROR_NULLPTR; + } + + return container->AddWindowNode(node, parentNode); +} + +WMError WindowRoot::RemoveWindowNode(uint32_t windowId) +{ + auto node = GetWindowNode(windowId); + if (node == nullptr) { + WLOGFE("could not find window"); + return WMError::WM_ERROR_NULLPTR; + } + auto container = GetOrCreateWindowNodeContainer(node->GetDisplayId()); + if (container == nullptr) { + WLOGFE("add window failed, window container could not be found"); + return WMError::WM_ERROR_NULLPTR; + } + return container->RemoveWindowNode(node); +} + +WMError WindowRoot::DestroyWindow(uint32_t windowId) +{ + auto node = GetWindowNode(windowId); + if (node == nullptr) { + return WMError::WM_ERROR_DESTROYED_OBJECT; + } + WMError res; + auto container = GetOrCreateWindowNodeContainer(node->GetDisplayId()); + if (container != nullptr) { + std::vector windowIds; + res = container->DestroyWindowNode(node, windowIds); + for (auto id : windowIds) { + node = GetWindowNode(id); + DestroyWindowInner(node); + } + return res; + } + res = DestroyWindowInner(node); + WLOGFI("destroy window failed, window container could not be found"); + return res; +} + +WMError WindowRoot::DestroyWindowInner(sptr& node) +{ + if (node == nullptr) { + WLOGFE("window has been destroyed"); + return WMError::WM_ERROR_DESTROYED_OBJECT; + } + sptr window = node->GetWindowToken(); + if (windowIdMap_.count(window->AsObject()) == 0) { + WLOGFI("window remote object has been destroyed"); + return WMError::WM_ERROR_DESTROYED_OBJECT; + } + + if (window->AsObject() != nullptr) { + window->AsObject()->RemoveDeathRecipient(windowDeath_); + } + windowIdMap_.erase(window->AsObject()); + windowNodeMap_.erase(node->GetWindowId()); + return WMError::WM_OK; +} + +WMError WindowRoot::RequestFocus(uint32_t windowId) +{ + auto node = GetWindowNode(windowId); + if (node == nullptr) { + WLOGFE("could not find window"); + return WMError::WM_ERROR_NULLPTR; + } + auto container = GetOrCreateWindowNodeContainer(node->GetDisplayId()); + if (container == nullptr) { + WLOGFE("window container could not be found"); + return WMError::WM_ERROR_NULLPTR; + } + return container->SetFocusWindow(windowId); +} + +void WindowRoot::ClearWindow(const sptr& remoteObject) +{ + auto iter = windowIdMap_.find(remoteObject); + if (iter == windowIdMap_.end()) { + WLOGFE("window id could not be found"); + return; + } + uint32_t windowId = iter->second; + DestroyWindow(windowId); +} + +void WindowDeathRecipient::OnRemoteDied(const wptr& wptrDeath) +{ + if (wptrDeath == nullptr) { + WLOGFE("wptrDeath is null"); + return; + } + + sptr object = wptrDeath.promote(); + if (!object) { + WLOGFE("object is null"); + return; + } + callback_(object); +} +} +} diff --git a/wmserver/src/window_zorder_policy.cpp b/wmserver/src/window_zorder_policy.cpp new file mode 100644 index 0000000000000000000000000000000000000000..1a41d6fb18aaff3f0dc09c8b4acc582df2834f3d --- /dev/null +++ b/wmserver/src/window_zorder_policy.cpp @@ -0,0 +1,34 @@ +/* + * Copyright (c) 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 "window_manager_hilog.h" +#include "window_zorder_policy.h" + +namespace OHOS { +namespace Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "WindowZorderPolicy"}; +} + +int32_t WindowZorderPolicy::GetWindowPriority(WindowType type) const +{ + if (windowPriorityMap_.count(type) == 0) { + WLOGFE("invalid window type"); + return windowPriorityMap_.at(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW); + } + return windowPriorityMap_.at(type); +} +} +} \ No newline at end of file diff --git a/wmtest/BUILD.gn b/wmtest/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..2d2d77b669e3f2c2e1909170b5512a5c6bf0b760 --- /dev/null +++ b/wmtest/BUILD.gn @@ -0,0 +1,84 @@ +# Copyright (c) 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/ohos.gni") + +## Build rosenwmtest {{{ +config("rosenwmtest_config") { + visibility = [ ":*" ] + + include_dirs = [ + "frameworks", + + # for abilityContext + "//foundation/aafwk/standard/frameworks/kits/ability/ability_runtime/include", + "//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_base/include", + "//base/global/resmgr_standard/interfaces/innerkits/include", + "//third_party/node/deps/icu-small/source/common", + "//foundation/aafwk/standard/interfaces/innerkits/ability_manager/include", + "//foundation/aafwk/standard/interfaces/innerkits/want/include/ohos/aafwk/content", + "//foundation/distributedschedule/dmsfwk/services/dtbschedmgr/include", + "//foundation/aafwk/standard/interfaces/innerkits/base/include", + + # RSSurface + "//foundation/graphic/standard/rosen/modules/render_service_client:librender_service_client", + "//foundation/graphic/standard/rosen/modules/render_service_base:librender_service_base", + ] + + cflags = [ + "-Wall", + "-Werror", + "-g3", + ] +} + +ohos_executable("rosenwmtest") { + install_enable = false + + sources = [ + "frameworks/inative_test.cpp", + "frameworks/main.cpp", + "test/dm_native_test.cpp", + "test/wm_native_test.cpp", + ] + + configs = [ ":rosenwmtest_config" ] + + deps = [ + "//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", + "//foundation/graphic/standard:libvsync_client", + "//foundation/graphic/standard:libwmclient", + "//foundation/graphic/standard:libwmservice", + "//foundation/windowmanager/adapter:libwmadaptertest", + "//foundation/windowmanager/wm:libwm", + "//foundation/windowmanager/wm:libwmutil", + "//foundation/windowmanager/wmserver:libwms", + "//third_party/zlib:libz", + + # ace + # native value + "//foundation/ace/ace_engine/interfaces/innerkits/ace:ace_uicontent", + "//foundation/ace/napi:ace_napi", + ] + + part_name = "window_manager" + subsystem_name = "window" +} + +## Build rosenwmtest }}} + +group("test") { + testonly = true + + deps = [ "unittest:unittest" ] +} diff --git a/wmtest/README.en.md b/wmtest/README.en.md new file mode 100644 index 0000000000000000000000000000000000000000..996c31240565f10647e77d11019ba0da47036d65 --- /dev/null +++ b/wmtest/README.en.md @@ -0,0 +1,36 @@ +# windowmanager + +#### 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/) diff --git a/wmtest/README.md b/wmtest/README.md new file mode 100644 index 0000000000000000000000000000000000000000..098e283c85d26c345b28f5cad4c9131158304209 --- /dev/null +++ b/wmtest/README.md @@ -0,0 +1,39 @@ +# windowmanager + +#### 介绍 +{**以下是 Gitee 平台说明,您可以替换此简介** +Gitee 是 OSCHINA 推出的基于 Git 的代码托管平台(同时支持 SVN)。专为开发者提供稳定、高效、安全的云端软件开发协作平台 +无论是个人、团队、或是企业,都能够用 Gitee 实现代码托管、项目管理、协作开发。企业项目请看 [https://gitee.com/enterprises](https://gitee.com/enterprises)} + +#### 软件架构 +软件架构说明 + + +#### 安装教程 + +1. xxxx +2. xxxx +3. xxxx + +#### 使用说明 + +1. xxxx +2. xxxx +3. xxxx + +#### 参与贡献 + +1. Fork 本仓库 +2. 新建 Feat_xxx 分支 +3. 提交代码 +4. 新建 Pull Request + + +#### 特技 + +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/) diff --git a/wmtest/adapter/BUILD.gn b/wmtest/adapter/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..0efe55427523b7ac4c2afb8462c470d7dce8efe8 --- /dev/null +++ b/wmtest/adapter/BUILD.gn @@ -0,0 +1,98 @@ +# Copyright (c) 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/ohos.gni") + +## Build libwmadaptertest.so {{{ +config("libwmadaptertest_config") { + visibility = [ ":*" ] + + include_dirs = [ + "include", + "//utils/system/safwk/native/include", + "//foundation/windowmanager/wmserver/include", + "//foundation/windowmanager/interfaces/innerkits/wm", + "//foundation/windowmanager/wm/include", + "//foundation/windowmanager/utils/include", + "//foundation/graphic/standard/interfaces/innerkits/wmclient", + "//foundation/graphic/standard/interfaces/innerkits/common", + "//foundation/graphic/standard/interfaces/innerkits/surface", + + # for abilityContext + "//foundation/aafwk/standard/frameworks/kits/ability/ability_runtime/include", + "//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_base/include", + "//base/global/resmgr_standard/interfaces/innerkits/include", + "//third_party/node/deps/icu-small/source/common", + "//foundation/aafwk/standard/interfaces/innerkits/ability_manager/include", + "//foundation/aafwk/standard/interfaces/innerkits/want/include/ohos/aafwk/content", + "//foundation/distributedschedule/dmsfwk/services/dtbschedmgr/include", + "//foundation/aafwk/standard/interfaces/innerkits/base/include", + ] + + cflags = [ + "-Wall", + "-Werror", + "-g3", + ] +} + +config("libwmadaptertest_public_config") { + include_dirs = [ + "//foundation/graphic/standard/interfaces/innerkits/wmclient", + "//foundation/windowmanager/interfaces/innerkits/wm", + "//foundation/multimodalinput/input/interfaces/native/innerkits/proxy/include", + "//foundation/multimodalinput/input/interfaces/native/innerkits/event/include", + "//foundation/multimodalinput/input/common/include", + ] +} + +ohos_shared_library("libwmadaptertest") { + sources = [ "src/adapter.cpp" ] + + configs = [ ":libwmadaptertest_config" ] + + public_configs = [ ":libwmadaptertest_public_config" ] + + deps = [ + "//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog", + "//foundation/graphic/standard:libwmclient", + "//utils/native/base:utils", + + # RSSurface + "//foundation/graphic/standard/rosen/modules/render_service_base:librender_service_base", + "//foundation/graphic/standard/rosen/modules/render_service_client:librender_service_client", + + # native value + "//foundation/ace/napi:ace_napi", + + # ace + "//foundation/ace/ace_engine/interfaces/innerkits/ace:ace_uicontent", + + # aafwk + "//foundation/aafwk/standard/interfaces/innerkits/want:want", + ] + + public_deps = [ + "//foundation/communication/ipc/interfaces/innerkits/ipc_core:ipc_core", + "//foundation/graphic/standard:libsurface", + "//foundation/graphic/standard/utils:promise", + "//utils/native/base:utils", + + # IMS + "//foundation/multimodalinput/input/frameworks/proxy:libmmi-client", + "//foundation/multimodalinput/input/frameworks/proxy:libmmi-common", + ] + + part_name = "window_manager" + subsystem_name = "window" +} diff --git a/wmtest/adapter/include/adapter.h b/wmtest/adapter/include/adapter.h new file mode 100644 index 0000000000000000000000000000000000000000..c387a88d0feadcecb9318025c9e453a45b0dfe7c --- /dev/null +++ b/wmtest/adapter/include/adapter.h @@ -0,0 +1,63 @@ +/* + * Copyright (c) 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 OHOS_ROSEN_WINDOW_ADAPTER_H +#define OHOS_ROSEN_WINDOW_ADAPTER_H +#define _NEW_RENDERSERVER_ +#include +#include +#include +#include +#include +#include +#include +#include "foundation/windowmanager/interfaces/innerkits/wm/window_option.h" +#include "wm_common.h" +#include "window.h" +#include "foundation/graphic/standard/interfaces/innerkits/wmclient/window_option.h" +#include "window_manager.h" +#include "window_manager_hilog.h" + +namespace OHOS { +namespace Rosen { +class Adapter { +public: + Adapter(); + ~Adapter(); + + static WMError Init(); + static bool CreateWestonWindow(sptr& option); + static void DestroyWestonWindow(); + static bool GetMainWindowRect(OHOS::Rosen::Rect &rect); + static OHOS::Rosen::WMError Show(); + static OHOS::Rosen::WMError Hide(); + static OHOS::Rosen::WMError MoveTo(int32_t x, int32_t y); + static OHOS::Rosen::WMError Resize(uint32_t width, uint32_t height); + +private: + static bool WindowOptionConvertToWeston(sptr& option, + sptr& config); + static bool GetSurfaceBuffer(sptr &surface, + sptr &buffer, + OHOS::BufferRequestConfig &rconfig); + static void WriteDataToSurface(); + static void ColorDraw(void *vaddr, uint32_t width, uint32_t height, uint32_t count); + static void BlackDraw(void *vaddr, uint32_t width, uint32_t height, uint32_t count); + static void FlushDraw(void *vaddr, uint32_t width, uint32_t height, uint32_t count); + static void set(void *vaddr, char ch, size_t len); +}; +} +} +#endif // OHOS_ROSEN_WINDOW_ADAPTER_H diff --git a/wmtest/adapter/src/adapter.cpp b/wmtest/adapter/src/adapter.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f705b490235b00f8dda6535abf4dc5a1d04e0643 --- /dev/null +++ b/wmtest/adapter/src/adapter.cpp @@ -0,0 +1,327 @@ +/* + * Copyright (c) 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 "adapter.h" +#include "window_impl.h" + +namespace OHOS { +namespace Rosen { + +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, 0, "Adapter" }; + +static inline sptr westonMainWindow_ = nullptr; + +Adapter::Adapter() +{ +} + +Adapter::~Adapter() +{ +} + +OHOS::Rosen::WMError Adapter::Init() +{ + // "AbilityWindow::Init()" + auto wmi = WindowManager::GetInstance(); + if (wmi == nullptr) { + WLOGFE("Adapter::Init WindowManager::GetInstance() is nullptr."); + return OHOS::Rosen::WMError::WM_ERROR_WINDOWMANAGER_GETINSTANCE; + } + + auto wret = wmi->Init(); + if (wret != OHOS::WM_OK) { + WLOGFE("Adapter::Init WindowManager::Init() return %d", wret); + return OHOS::Rosen::WMError::WM_ERROR_WINDOWMANAGER_INIT; + } + WLOGFI("%{public}s end.", __func__); + return OHOS::Rosen::WMError::WM_OK; +} + +bool Adapter::CreateWestonWindow(sptr& option) +{ + sptr config = OHOS::WindowOption::Get(); + if (!WindowOptionConvertToWeston(option, config)) { + WLOGFE("Adapter::CreateWindow convert windowOption fail"); + return false; + } + + auto wmi = OHOS::WindowManager::GetInstance(); + if (wmi == nullptr) { + WLOGFE("Adapter::ConvertToWindowOption WindowManager::GetInstance() is nullptr."); + return false; + } + + WLOGFI("%{public}s begin wms->CreateWindow.", __func__); + auto retvalCreate = wmi->CreateWindow(westonMainWindow_, config); + WLOGFI("%{public}s end wms->CreateWindow.", __func__); + + WriteDataToSurface(); + + if (retvalCreate != OHOS::WMError::WM_OK) { + WLOGFE("Adapter::ConvertToWindowOption WindowManager::CreateWindow() return %d", retvalCreate); + return false; + } + return true; +} + +void Adapter::DestroyWestonWindow() +{ + if (westonMainWindow_ != nullptr) { + OHOS::WMError err = westonMainWindow_->Destroy(); + westonMainWindow_ = nullptr; + if (err == OHOS::WMError::WM_OK) { + WLOGFI("DestroyWestonWindow OK"); + return; + } + WLOGFE("DestroyWestonWindow errorcode=%d", static_cast(err)); + } + WLOGFE("DestroyWestonWindow westonMainWindow_ is null"); +} + +bool Adapter::WindowOptionConvertToWeston(sptr& option, sptr& config) +{ + // window type + config->SetWindowType(OHOS::WindowType::WINDOW_TYPE_NORMAL); + config->SetWindowMode(OHOS::WindowMode::WINDOW_MODE_FULL); + return true; +} + +bool Adapter::GetMainWindowRect(OHOS::Rosen::Rect &rect) +{ + if (westonMainWindow_ == nullptr) { + return false; + } + rect.posX_ = westonMainWindow_->GetX(); + rect.posY_ = westonMainWindow_->GetY(); + rect.width_ = westonMainWindow_->GetWidth(); + rect.height_ = westonMainWindow_->GetHeight(); + return true; +} + +static inline bool hide = false; + +OHOS::Rosen::WMError Adapter::Show() +{ + if (westonMainWindow_ == nullptr) { + WLOGFE("Adapter::Show westonMainWindow_ is null"); + return OHOS::Rosen::WMError::WM_ERROR_WINDOWMANAGER_SHOW; + } + + if (!hide) { + auto promise = westonMainWindow_->Show(); + if (promise == nullptr) { + WLOGFE("Adapter::Show Show error"); + return OHOS::Rosen::WMError::WM_ERROR_WINDOWMANAGER_SHOW; + } + auto error = promise->Await(); + if (error != OHOS::WMError::WM_OK) { + WLOGFE("Adapter::Show Show error=%d", static_cast(error)); + return OHOS::Rosen::WMError::WM_ERROR_WINDOWMANAGER_SHOW; + } + } + + auto promise2 = westonMainWindow_->SwitchTop(); + if (promise2 == nullptr) { + WLOGFE("Adapter::Show SwitchTop error"); + return OHOS::Rosen::WMError::WM_ERROR_WINDOWMANAGER_SHOW; + } + auto error2 = promise2->Await(); + if (error2 != OHOS::WMError::WM_OK) { + WLOGFE("Adapter::Show SwitchTop error=%d", static_cast(error2)); + return OHOS::Rosen::WMError::WM_ERROR_WINDOWMANAGER_SHOW; + } + + return OHOS::Rosen::WMError::WM_OK; +} + +void Adapter::WriteDataToSurface() +{ + /* write data to surface */ + sptr surface = westonMainWindow_->GetSurface(); + sptr buffer; + BufferRequestConfig rconfig; + if (GetSurfaceBuffer(surface, buffer, rconfig)) { + BlackDraw(buffer->GetVirAddr(), rconfig.width, rconfig.height, 1); + } else { + WLOGFE("Adapter::WriteDataToSurface GetSurfaceBuffer fail"); + } + BufferFlushConfig fconfig = { + .damage = { + .w = rconfig.width, + .h = rconfig.height, + }, + }; + surface->FlushBuffer(buffer, -1, fconfig); +} + +OHOS::Rosen::WMError Adapter::Hide() +{ + if (westonMainWindow_ == nullptr) { + WLOGFE("Adapter::Hide westonMainWindow_ is null"); + return OHOS::Rosen::WMError::WM_ERROR_WINDOWMANAGER_HIDE; + } + auto promise = westonMainWindow_->Hide(); + if (promise == nullptr) { + WLOGFE("Adapter::Hide Hide error"); + return OHOS::Rosen::WMError::WM_ERROR_WINDOWMANAGER_HIDE; + } + auto error = promise->Await(); + if (error != OHOS::WMError::WM_OK) { + WLOGFE("Adapter::Hide Hide error=%d", static_cast(error)); + return OHOS::Rosen::WMError::WM_ERROR_WINDOWMANAGER_HIDE; + } + hide = true; + return OHOS::Rosen::WMError::WM_OK; +} + +OHOS::Rosen::WMError Adapter::MoveTo(int32_t x, int32_t y) +{ + if (westonMainWindow_ == nullptr) { + WLOGFE("Adapter::MoveTo westonMainWindow_ is null"); + return OHOS::Rosen::WMError::WM_ERROR_WINDOWMANAGER_MOVE; + } + auto promise = westonMainWindow_->Move(x, y); + if (promise == nullptr) { + WLOGFE("Adapter::MoveTo promise is null"); + return OHOS::Rosen::WMError::WM_ERROR_WINDOWMANAGER_MOVE; + } + return OHOS::Rosen::WMError::WM_OK; +} + +OHOS::Rosen::WMError Adapter::Resize(uint32_t width, uint32_t height) +{ + if (westonMainWindow_ == nullptr) { + WLOGFE("Adapter::Resize westonMainWindow_ is null"); + return OHOS::Rosen::WMError::WM_ERROR_WINDOWMANAGER_RESIZE; + } + auto promise = westonMainWindow_->Resize(width, height); + if (promise == nullptr) { + WLOGFE("Adapter::Resize promise is null"); + return OHOS::Rosen::WMError::WM_ERROR_WINDOWMANAGER_RESIZE; + } + return OHOS::Rosen::WMError::WM_OK; +} + +bool Adapter::GetSurfaceBuffer(sptr &surface, sptr &buffer, BufferRequestConfig &rconfig) +{ + int32_t releaseFence; + rconfig = { + .width = surface->GetDefaultWidth(), + .height = surface->GetDefaultHeight(), + .strideAlignment = 0x8, + .format = 12, // PIXEL_FMT_RGBA_8888, + .usage = surface->GetDefaultUsage(), + .timeout = 0, + }; + OHOS::SurfaceError ret = surface->RequestBuffer(buffer, releaseFence, rconfig); + if (ret == 40601000) { // OHOS::SurfaceError::SURFACE_ERROR_NO_BUFFER + WLOGFE("Adapter::GetSurfaceBuffer RequestBuffer error=%d", static_cast(ret)); + return false; + } else if (ret != 0) { // OHOS::SurfaceError::SURFACE_ERROR_OK + WLOGFE("Adapter::GetSurfaceBuffer RequestBuffer is NG error=%d", static_cast(ret)); + return false; + } else if (buffer == nullptr) { + WLOGFE("Adapter::GetSurfaceBuffer buffer is nullptr"); + return false; + } + return true; +} + +void Adapter::ColorDraw(void *vaddr, uint32_t width, uint32_t height, uint32_t count) +{ + auto addr = static_cast(vaddr); + if (addr == nullptr) { + return; + } + + constexpr uint32_t wdiv = 2; + constexpr uint32_t colorTable[][wdiv] = { + {0xffff0000, 0xffff00ff}, + {0xffff0000, 0xffffff00}, + {0xff00ff00, 0xffffff00}, + {0xff00ff00, 0xff00ffff}, + {0xff0000ff, 0xff00ffff}, + {0xff0000ff, 0xffff00ff}, + {0xff777777, 0xff777777}, + {0xff777777, 0xff777777}, + }; + const uint32_t hdiv = sizeof(colorTable) / sizeof(*colorTable); + + for (uint32_t i = 0; i < height; i++) { + auto table = colorTable[i / (height / hdiv)]; + for (uint32_t j = 0; j < wdiv; j++) { + auto color = table[j]; + for (uint32_t k = j * width / wdiv; k < (j + 1) * width / wdiv; k++) { + addr[i * width + k] = color; + } + } + } +} + +void Adapter::BlackDraw(void *vaddr, uint32_t width, uint32_t height, uint32_t count) +{ + auto addr = static_cast(vaddr); + if (addr == nullptr) { + return; + } + + for (uint32_t i = 0; i < width * height; i++) { + addr[i] = 0xff00ff00; + } +} + +void Adapter::FlushDraw(void *vaddr, uint32_t width, uint32_t height, uint32_t count) +{ + auto addr = static_cast(vaddr); + if (addr == nullptr) { + return; + } + + constexpr uint32_t bpp = 4; + constexpr uint32_t color1 = 0xff / 3 * 0; + constexpr uint32_t color2 = 0xff / 3 * 1; + constexpr uint32_t color3 = 0xff / 3 * 2; + constexpr uint32_t color4 = 0xff / 3 * 3; + constexpr uint32_t bigDiv = 7; + constexpr uint32_t smallDiv = 10; + uint32_t c = count % (bigDiv * smallDiv); + uint32_t stride = width * bpp; + uint32_t beforeCount = height * c / bigDiv / smallDiv; + uint32_t afterCount = height - beforeCount - 1; + + size_t len = ((stride * height) < (beforeCount * stride) ? (stride * height) : (beforeCount * stride)); + set(addr, color3, len); + + len = ((stride * height) < (afterCount * stride) ? (stride * height) : (afterCount * stride)); + set(addr + (beforeCount + 1) * stride, color1, len); + + for (uint32_t i = 0; i < bigDiv; i++) { + len = ((stride * height) < (stride) ? (stride * height) : (stride)); + set(addr + (i * height / bigDiv) * stride, color4, len); + } + + len = ((stride * height) < (stride) ? (stride * height) : (stride)); + set(addr + beforeCount * stride, color2, len); +} + +void Adapter::set(void *vaddr, char ch, size_t len) +{ + char *ptr = static_cast(vaddr); + for (size_t i = 0; i < len; i++) { + ptr[i] = ch; + } +} +} +} diff --git a/wmtest/dm/include/README.md b/wmtest/dm/include/README.md new file mode 100644 index 0000000000000000000000000000000000000000..bda91e7389908403060ac7266cf998451a5aee85 --- /dev/null +++ b/wmtest/dm/include/README.md @@ -0,0 +1 @@ +Store code of display client inner header files diff --git a/wmtest/dm/include/display_manager_adapter.h b/wmtest/dm/include/display_manager_adapter.h new file mode 100644 index 0000000000000000000000000000000000000000..61882fd0dba9c134c7fb798b7565ac8652682c33 --- /dev/null +++ b/wmtest/dm/include/display_manager_adapter.h @@ -0,0 +1,54 @@ +/* + * Copyright (c) 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 FOUNDATION_DM_DISPLAY_MANAGER_ADAPTER_H +#define FOUNDATION_DM_DISPLAY_MANAGER_ADAPTER_H + +#include +#include + +#include "display.h" +#include "display_manager_interface.h" +#include "single_instance.h" +#include "singleton_delegator.h" + +namespace OHOS::Rosen { +class DMSDeathRecipient : public IRemoteObject::DeathRecipient { +public: + virtual void OnRemoteDied(const wptr& wptrDeath) override; +}; + +class DisplayManagerAdapter : public RefBase { + DECLARE_SINGLE_INSTANCE_BASE(DisplayManagerAdapter); +public: + sptr GetDisplay(DisplayType type); + DisplayId GetDefaultDisplayId(); + sptr GetDisplayById(DisplayId displayId); + + void Clear(); +private: + DisplayManagerAdapter() = default; + ~DisplayManagerAdapter() = default; + bool InitDMSProxyLocked(); + static inline SingletonDelegator delegator; + + std::mutex mutex_; + sptr displayManagerServiceProxy_ = nullptr; + sptr dmsDeath_ = nullptr; + std::map> displayMap_; + DisplayId defaultDisplayId_; +}; +} // namespace OHOS::Rosen +#endif // FOUNDATION_DM_DISPLAY_MANAGER_ADAPTER_H diff --git a/wmtest/dm/src/README.md b/wmtest/dm/src/README.md new file mode 100644 index 0000000000000000000000000000000000000000..8eb6cfc677dd9bd5133781d11e412945a4bb96fd --- /dev/null +++ b/wmtest/dm/src/README.md @@ -0,0 +1 @@ +Store code of display source files diff --git a/wmtest/dm/src/display.cpp b/wmtest/dm/src/display.cpp new file mode 100644 index 0000000000000000000000000000000000000000..73655b9404a87e6eba3d41f0159244c642e34c83 --- /dev/null +++ b/wmtest/dm/src/display.cpp @@ -0,0 +1,68 @@ +/* + * Copyright (c) 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 "display.h" +#include "display_info.h" + +namespace OHOS::Rosen { +Display::Display(const std::string& name, DisplayInfo* info) + : name_(name), + id_(info->id_), + width_(info->width_), + height_(info->height_), + freshRate_(info->freshRate_) +{ +} + +DisplayId Display::GetId() const +{ + return id_; +} + +int32_t Display::GetWidth() const +{ + return width_; +} + +int32_t Display::GetHeight() const +{ + return height_; +} + +uint32_t Display::GetFreshRate() const +{ + return freshRate_; +} + +void Display::SetWidth(int32_t width) +{ + width_ = width; +} + +void Display::SetHeight(int32_t height) +{ + height_ = height; +} + +void Display::SetFreshRate(uint32_t freshRate) +{ + freshRate_ = freshRate; +} + +void Display::SetId(DisplayId id) +{ + id_ = id; +} +} // namespace OHOS::Rosen \ No newline at end of file diff --git a/wmtest/dm/src/display_manager.cpp b/wmtest/dm/src/display_manager.cpp new file mode 100644 index 0000000000000000000000000000000000000000..57b8ac1b0ae7cf96ab69773682d26f71227cd42c --- /dev/null +++ b/wmtest/dm/src/display_manager.cpp @@ -0,0 +1,97 @@ +/* + * Copyright (c) 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 "display_manager.h" +#include "display_manager_adapter.h" +#include "window_manager_hilog.h" + +namespace OHOS::Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "DisplayManager"}; +} + +IMPLEMENT_SINGLE_INSTANCE(DisplayManager); + +DisplayManager::DisplayManager() +{ + dmsAdapter_ = SingletonContainer::Get(); +} + +DisplayManager::~DisplayManager() +{ +} + +const sptr& DisplayManager::GetDisplay(const DisplayType type) +{ + if (dmsAdapter_ == nullptr) { + WLOGFE("DisplayManager::GetDisplay null!"); + return nullptr; + } + return dmsAdapter_->GetDisplay(type); +} + +DisplayId DisplayManager::GetDefaultDisplayId() +{ + if (dmsAdapter_ == nullptr) { + WLOGFE("DisplayManager::GetDefaultDisplayId null!\n"); + return DISPLAY_ID_INVALD; + } + return dmsAdapter_->GetDefaultDisplayId(); +} + +const sptr DisplayManager::GetDisplayById(DisplayId displayId) +{ + if (dmsAdapter_ == nullptr) { + WLOGFE("DisplayManager::GetDisplayById null!\n"); + return nullptr; + } + + sptr display = dmsAdapter_->GetDisplayById(displayId); + if (display == nullptr) { + WLOGFE("DisplayManager::GetDisplayById failed!\n"); + return nullptr; + } + return display; +} + + +const sptr DisplayManager::GetDefaultDisplay() +{ + return GetDisplayById(GetDefaultDisplayId()); +} + +std::vector DisplayManager::GetAllDisplayIds() +{ + std::vector res; + res.push_back(GetDefaultDisplayId()); + // 获取所有displayIds + return res; +} + +std::vector> DisplayManager::GetAllDisplays() +{ + std::vector> res; + auto displayIds = GetAllDisplayIds(); + for (auto displayId: displayIds) { + const sptr display = GetDisplayById(displayId); + if (display != nullptr) { + res.push_back(display); + } else { + WLOGFE("DisplayManager::GetAllDisplays display %llu nullptr!", displayId); + } + } + return res; +} +} // namespace OHOS::Rosen \ No newline at end of file diff --git a/wmtest/dm/src/display_manager_adapter.cpp b/wmtest/dm/src/display_manager_adapter.cpp new file mode 100644 index 0000000000000000000000000000000000000000..675bb97b8be1212aae57e403fc8d248196b2eae6 --- /dev/null +++ b/wmtest/dm/src/display_manager_adapter.cpp @@ -0,0 +1,143 @@ +/* + * Copyright (c) 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 "display_manager_adapter.h" + +#include +#include +#include + +#include "window_manager_hilog.h" +#include "wm_common.h" + +namespace OHOS::Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "DisplayManagerAdapter"}; +} + +IMPLEMENT_SINGLE_INSTANCE(DisplayManagerAdapter); + +sptr DisplayManagerAdapter::GetDisplay(DisplayType type) +{ + std::lock_guard lock(mutex_); + + if (!InitDMSProxyLocked()) { + WLOGFE("displayManagerAdapter::GetDisplay: InitDMSProxyLocked failed!"); + return nullptr; + } + sptr info = displayManagerServiceProxy_->GetDisplayInfo(type); + // TODO DisplayInfo内容更新到对应的Display.displayInfo_. auto iter = displayMap_.find(info.id_); + return nullptr; +} + +DisplayId DisplayManagerAdapter::GetDefaultDisplayId() +{ + std::lock_guard lock(mutex_); + + if (defaultDisplayId_ != DISPLAY_ID_INVALD) { + return defaultDisplayId_; + } + + if (!InitDMSProxyLocked()) { + WLOGFE("displayManagerAdapter::GetDefaultDisplayId: InitDMSProxyLocked failed!"); + return DISPLAY_ID_INVALD; + } + defaultDisplayId_ = displayManagerServiceProxy_->GetDefaultDisplayId(); + return defaultDisplayId_; +} + +sptr DisplayManagerAdapter::GetDisplayById(DisplayId displayId) +{ + std::lock_guard lock(mutex_); + + auto iter = displayMap_.find(displayId); + if (iter != displayMap_.end()) { + return iter->second; + } + + if (!InitDMSProxyLocked()) { + WLOGFE("displayManagerAdapter::GetDisplayById: InitDMSProxyLocked failed!"); + return nullptr; + } + DisplayInfo displayInfo = displayManagerServiceProxy_->GetDisplayInfoById(displayId); + sptr display = new Display("", &displayInfo); + if (display->GetId() != DISPLAY_ID_INVALD) { + displayMap_[display->GetId()] = display; + } + return display; +} + +bool DisplayManagerAdapter::InitDMSProxyLocked() +{ + WLOGFI("InitDMSProxy"); + if (!displayManagerServiceProxy_) { + sptr systemAbilityManager = + SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + if (!systemAbilityManager) { + WLOGFE("Failed to get system ability mgr."); + return false; + } + + sptr remoteObject + = systemAbilityManager->GetSystemAbility(DISPLAY_MANAGER_SERVICE_SA_ID); + if (!remoteObject) { + WLOGFE("Failed to get display manager service."); + return false; + } + + displayManagerServiceProxy_ = iface_cast(remoteObject); + if ((!displayManagerServiceProxy_) || (!displayManagerServiceProxy_->AsObject())) { + WLOGFE("Failed to get system display manager services"); + return false; + } + + dmsDeath_ = new DMSDeathRecipient(); + if (!dmsDeath_) { + WLOGFE("Failed to create death Recipient ptr DMSDeathRecipient"); + return false; + } + if (!remoteObject->AddDeathRecipient(dmsDeath_)) { + WLOGFE("Failed to add death recipient"); + return false; + } + } + return true; +} + +void DMSDeathRecipient::OnRemoteDied(const wptr& wptrDeath) +{ + if (wptrDeath == nullptr) { + WLOGFE("wptrDeath is null"); + return; + } + + sptr object = wptrDeath.promote(); + if (!object) { + WLOGFE("object is null"); + return; + } + SingletonContainer::Get().GetRefPtr()->Clear(); + return; +} + +void DisplayManagerAdapter::Clear() +{ + std::lock_guard lock(mutex_); + if ((displayManagerServiceProxy_ != nullptr) && (displayManagerServiceProxy_->AsObject() != nullptr)) { + displayManagerServiceProxy_->AsObject()->RemoveDeathRecipient(dmsDeath_); + } + displayManagerServiceProxy_ = nullptr; +} +} // namespace OHOS::Rosen \ No newline at end of file diff --git a/wmtest/dm/src/monitor.cpp b/wmtest/dm/src/monitor.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ca8933d58b4aea5bdbe2f9de8a475c0c61fbe738 --- /dev/null +++ b/wmtest/dm/src/monitor.cpp @@ -0,0 +1,19 @@ +/* + * Copyright (c) 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 "monitor.h" + +namespace OHOS::Rosen { +} // namespace OHOS::Rosen \ No newline at end of file diff --git a/wmtest/dmserver/include/README.md b/wmtest/dmserver/include/README.md new file mode 100644 index 0000000000000000000000000000000000000000..92b3669bdd6971bac668e392d46d0439ec732390 --- /dev/null +++ b/wmtest/dmserver/include/README.md @@ -0,0 +1 @@ +Store code of display manager service inner header files diff --git a/wmtest/dmserver/include/display_info.h b/wmtest/dmserver/include/display_info.h new file mode 100644 index 0000000000000000000000000000000000000000..72edc10998d20f9ae0370453fd2bcbf68d2a4fcc --- /dev/null +++ b/wmtest/dmserver/include/display_info.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 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 p ermissions and + * limitations under the License. + */ + +#ifndef FOUNDATION_DMSERVER_DISPLAY_INFO_H +#define FOUNDATION_DMSERVER_DISPLAY_INFO_H + +#include + +#include "display.h" + +namespace OHOS::Rosen { +class DisplayInfo : public Parcelable { +public: + DisplayInfo() = default; + ~DisplayInfo() = default; + + void Update(DisplayInfo* info); + + virtual bool Marshalling(Parcel& parcel) const override; + static DisplayInfo *Unmarshalling(Parcel& parcel); + + DisplayId id_ {DISPLAY_ID_INVALD}; + DisplayType type_ {DisplayType::DEFAULT}; + int32_t width_ {0}; + int32_t height_ {0}; + uint32_t freshRate_ {0}; + float xDpi_ {0.0}; + float yDpi_ {0.0}; +}; +} // namespace OHOS::Rosen +#endif // FOUNDATION_DMSERVER_DISPLAY_INFO_H \ No newline at end of file diff --git a/wmtest/dmserver/include/display_manager_interface.h b/wmtest/dmserver/include/display_manager_interface.h new file mode 100644 index 0000000000000000000000000000000000000000..8a7d71fc5e46fca2ae133a6cd13e1d60c236bc87 --- /dev/null +++ b/wmtest/dmserver/include/display_manager_interface.h @@ -0,0 +1,41 @@ +/* + * Copyright (c) 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 FOUNDATION_DMSERVER_DISPLAY_MANAGER_INTERFACE_H +#define FOUNDATION_DMSERVER_DISPLAY_MANAGER_INTERFACE_H + +#include + +#include "display_info.h" + +namespace OHOS::Rosen { +class IDisplayManager : public IRemoteBroker { +public: + DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.IDisplayManager"); + + enum { + TRANS_ID_GET_DISPLAY_INFO = 1, + TRANS_ID_GET_DEFAULT_DISPLAY_ID = 2, + TRANS_ID_GET_DISPLAY_BY_ID = 3, + }; + + virtual const sptr& GetDisplayInfo(const DisplayType type) = 0; + + virtual DisplayId GetDefaultDisplayId() = 0; + virtual DisplayInfo GetDisplayInfoById(DisplayId displayId) = 0; +}; +} // namespace OHOS::Rosen + +#endif // FOUNDATION_DMSERVER_DISPLAY_MANAGER_INTERFACE_H \ No newline at end of file diff --git a/wmtest/dmserver/include/display_manager_proxy.h b/wmtest/dmserver/include/display_manager_proxy.h new file mode 100644 index 0000000000000000000000000000000000000000..519107124d52720ced4aa4842d79c5f5d989dd01 --- /dev/null +++ b/wmtest/dmserver/include/display_manager_proxy.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) 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 FOUNDATION_DMSERVER_DISPLAY_MANAGER_PROXY_H +#define FOUNDATION_DMSERVER_DISPLAY_MANAGER_PROXY_H + +#include "display_manager_interface.h" + +#include + +namespace OHOS::Rosen { +class DisplayManagerProxy : public IRemoteProxy { +public: + explicit DisplayManagerProxy(const sptr &impl) + : IRemoteProxy(impl) {}; + ~DisplayManagerProxy() {}; + + const sptr& GetDisplayInfo(const DisplayType type) override; + + DisplayId GetDefaultDisplayId() override; + DisplayInfo GetDisplayInfoById(DisplayId displayId) override; +private: + static inline BrokerDelegator delegator_; +}; +} // namespace OHOS::Rosen + +#endif // FOUNDATION_DMSERVER_DISPLAY_MANAGER_PROXY_H \ No newline at end of file diff --git a/wmtest/dmserver/include/display_manager_service.h b/wmtest/dmserver/include/display_manager_service.h new file mode 100644 index 0000000000000000000000000000000000000000..83ffbbe94abfeb64d7f4b3d7e7cb2f32ad044cc5 --- /dev/null +++ b/wmtest/dmserver/include/display_manager_service.h @@ -0,0 +1,57 @@ +/* + * Copyright (c) 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 FOUNDATION_DMSERVER_DISPLAY_MANAGER_SERVICE_H +#define FOUNDATION_DMSERVER_DISPLAY_MANAGER_SERVICE_H + +#include +#include + +#include + +#include "display_manager_stub.h" +#include "display_screen.h" +#include "single_instance.h" +#include "singleton_delegator.h" +#include "display_screen_manager.h" + +namespace OHOS::Rosen { +class DisplayManagerService : public SystemAbility, public DisplayManagerStub { +DECLARE_SYSTEM_ABILITY(DisplayManagerService); + +DECLARE_SINGLE_INSTANCE_BASE(DisplayManagerService); + +public: + void OnStart() override; + void OnStop() override; + const sptr& GetDisplayInfo(const DisplayType type) override; + + DisplayId GetDefaultDisplayId() override; + DisplayInfo GetDisplayInfoById(DisplayId displayId) override; + +private: + DisplayManagerService(); + ~DisplayManagerService() = default; + bool Init(); + DisplayId GetDisplayIdFromScreenId(ScreenId screenId); + ScreenId GetScreenIdFromDisplayId(DisplayId displayId); + + static inline SingletonDelegator delegator_; + std::map> displayScreenMap_; + sptr displayScreenManager_; +}; +} // namespace OHOS::Rosen + +#endif // FOUNDATION_DMSERVER_DISPLAY_MANAGER_SERVICE_H \ No newline at end of file diff --git a/wmtest/dmserver/include/display_manager_service_inner.h b/wmtest/dmserver/include/display_manager_service_inner.h new file mode 100644 index 0000000000000000000000000000000000000000..6051c8044364b94d4bccda04b9d4d5e2c08b2c03 --- /dev/null +++ b/wmtest/dmserver/include/display_manager_service_inner.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) 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 FOUNDATION_DMSERVER_DISPLAY_MANAGER_SERVICE_INNER_H +#define FOUNDATION_DMSERVER_DISPLAY_MANAGER_SERVICE_INNER_H + +#include +#include + +#include "display_screen.h" +#include "single_instance.h" +#include "singleton_delegator.h" + +namespace OHOS::Rosen { +class DisplayManagerServiceInner : public RefBase { +DECLARE_SINGLE_INSTANCE(DisplayManagerServiceInner); + +public: + std::vector> GetAllDisplays(); + DisplayId GetDefaultDisplayId(); + const sptr GetDefaultDisplay(); + const sptr GetDisplayById(DisplayId displayId); + std::vector GetAllDisplayIds(); +}; +} // namespace OHOS::Rosen + +#endif // FOUNDATION_DMSERVER_DISPLAY_MANAGER_SERVICE_H \ No newline at end of file diff --git a/wmtest/dmserver/include/display_manager_stub.h b/wmtest/dmserver/include/display_manager_stub.h new file mode 100644 index 0000000000000000000000000000000000000000..d88c4a0c652f4591b600a1e4b2f5ed339502127e --- /dev/null +++ b/wmtest/dmserver/include/display_manager_stub.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) 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 FOUNDATION_DMSERVER_DISPLAY_MANAGER_STUB_H +#define FOUNDATION_DMSERVER_DISPLAY_MANAGER_STUB_H + +#include "display_manager_interface.h" + +#include + +namespace OHOS::Rosen { +class DisplayManagerStub : public IRemoteStub { +public: + DisplayManagerStub() = default; + ~DisplayManagerStub() = default; + virtual int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, + MessageOption &option) override; +}; +} // namespace OHOS::Rosen + +#endif // FOUNDATION_DMSERVER_DISPLAY_MANAGER_STUB_H \ No newline at end of file diff --git a/wmtest/dmserver/include/display_node_control.h b/wmtest/dmserver/include/display_node_control.h new file mode 100644 index 0000000000000000000000000000000000000000..5da96a208147911f1bc9f74bf9fdb5752f816528 --- /dev/null +++ b/wmtest/dmserver/include/display_node_control.h @@ -0,0 +1,25 @@ +/* + * Copyright (c) 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 FOUNDATION_DMSERVER_DISPLAY_NODE_CONTROL_H +#define FOUNDATION_DMSERVER_DISPLAY_NODE_CONTROL_H + +#include + +namespace OHOS::Rosen { +class DisplayNodeControl : public RefBase { +}; +} // namespace OHOS::Rosen +#endif // FOUNDATION_DMSERVER_DISPLAY_NODE_CONTROL_H \ No newline at end of file diff --git a/wmtest/dmserver/include/display_screen.h b/wmtest/dmserver/include/display_screen.h new file mode 100644 index 0000000000000000000000000000000000000000..d656621953e85274d62a4dd0670693a0150d32b9 --- /dev/null +++ b/wmtest/dmserver/include/display_screen.h @@ -0,0 +1,45 @@ +/* + * Copyright (c) 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 FOUNDATION_DMSERVER_DISPLAY_SCREEN_H +#define FOUNDATION_DMSERVER_DISPLAY_SCREEN_H + +#include +#include "display_info.h" + +namespace OHOS::Rosen { +class DisplayScreen : public RefBase { +public: + DisplayScreen(const DisplayInfo& info); + ~DisplayScreen() = default; + + DisplayId GetId() const; + int32_t GetWidth() const; + int32_t GetHeight() const; + uint32_t GetFreshRate() const; + + void SetId(DisplayId displayId); + void SetWidth(int32_t width); + void SetHeight(int32_t height); + void SetFreshRate(uint32_t freshRate); + +private: + DisplayId id_ {DISPLAY_ID_INVALD}; + int32_t width_ {0}; + int32_t height_ {0}; + uint32_t freshRate_ {0}; +}; +} // namespace OHOS::Rosen +#endif // FOUNDATION_DMSERVER_DISPLAY_SCREEN_H \ No newline at end of file diff --git a/wmtest/dmserver/include/display_screen_manager.h b/wmtest/dmserver/include/display_screen_manager.h new file mode 100644 index 0000000000000000000000000000000000000000..0c1df9b379a1c28c9827bd1533d8aae263b9980a --- /dev/null +++ b/wmtest/dmserver/include/display_screen_manager.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 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 FOUNDATION_DMSERVER_DISPLAY_SCREEN_MANAGER_H +#define FOUNDATION_DMSERVER_DISPLAY_SCREEN_MANAGER_H + +#include +#include + +#include "display_screen.h" +#include "single_instance.h" +#include "transaction/rs_interfaces.h" + +namespace OHOS::Rosen { +class DisplayScreenManager : public RefBase { +DECLARE_SINGLE_INSTANCE_BASE(DisplayScreenManager); +public: + std::map> displayScreenMap_; + + ScreenId GetDefaultScreenId(); + RSScreenModeInfo GetScreenActiveMode(ScreenId id); + +private: + DisplayScreenManager(); + ~DisplayScreenManager(); + void parepareRSScreenManger(); + + OHOS::Rosen::RSInterfaces *rsInterface_; +}; + +} // namespace OHOS::Rosen +#endif // FOUNDATION_DMSERVER_DISPLAY_SCREEN_MANAGER_H \ No newline at end of file diff --git a/wmtest/dmserver/include/rs_adapter.h b/wmtest/dmserver/include/rs_adapter.h new file mode 100644 index 0000000000000000000000000000000000000000..9f19e344c929afbdb13a1e3f866dfb29d07ecf13 --- /dev/null +++ b/wmtest/dmserver/include/rs_adapter.h @@ -0,0 +1,48 @@ +/* + * Copyright (c) 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 FOUNDATION_DMSERVER_RS_ADAPTER_H +#define FOUNDATION_DMSERVER_RS_ADAPTER_H + +#include +#include + +#include + +#include "single_instance.h" + +namespace OHOS::Rosen { +class DMSDeathRecipient : public IRemoteObject::DeathRecipient { +public: + virtual void OnRemoteDied(const wptr& wptrDeath) override; +private: + sptr& rsAdatper_; +}; + +class RsAdapter : public RefBase { + DECLARE_SINGLE_INSTANCE_BASE(RsAdapter); +public: + void Clear(); +private: + RsAdapter() = default; + ~RsAdapter() = default; + bool InitRSProxyLocked(); + + std::mutex mutex_; + sptr rsProxy_ = nullptr; + sptr rsDeath_ = nullptr; +}; +} // namespace OHOS::Rosen +#endif // FOUNDATION_DMSERVER_RS_ADAPTER_H diff --git a/wmtest/dmserver/include/screen.h b/wmtest/dmserver/include/screen.h new file mode 100644 index 0000000000000000000000000000000000000000..bbe436d55bb515aab342fe883f3b6155eedad961 --- /dev/null +++ b/wmtest/dmserver/include/screen.h @@ -0,0 +1,25 @@ +/* + * Copyright (c) 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 FOUNDATION_DMSERVER_SCREEN_H +#define FOUNDATION_DMSERVER_SCREEN_H + +#include + +namespace OHOS::Rosen { +class Screen : public RefBase { +}; +} // namespace OHOS::Rosen +#endif // FOUNDATION_DMSERVER_SCREEN_H \ No newline at end of file diff --git a/wmtest/dmserver/src/README.md b/wmtest/dmserver/src/README.md new file mode 100644 index 0000000000000000000000000000000000000000..acfe633cd715263cb8c9f3795589fe28071660b5 --- /dev/null +++ b/wmtest/dmserver/src/README.md @@ -0,0 +1 @@ +Store code of display manager service source files diff --git a/wmtest/dmserver/src/display_info.cpp b/wmtest/dmserver/src/display_info.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e26ebf2f44aa87ca28df1fddbdcafc8e37f864d8 --- /dev/null +++ b/wmtest/dmserver/src/display_info.cpp @@ -0,0 +1,56 @@ +/* + * Copyright (c) 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 "display_info.h" + +namespace OHOS::Rosen { +void DisplayInfo::Update(DisplayInfo* info) +{ + id_ = info->id_; + type_ = info->type_; + width_ = info->width_; + height_ = info->height_; + freshRate_ = info->freshRate_; + xDpi_ = info->xDpi_; + yDpi_ = info->yDpi_; +} + +bool DisplayInfo::Marshalling(Parcel &parcel) const +{ + return parcel.WriteUint64(id_) && parcel.WriteUint32(type_) && + parcel.WriteInt32(width_) && parcel.WriteInt32(height_) && + parcel.WriteUint32(freshRate_) && + parcel.WriteFloat(xDpi_) && parcel.WriteFloat(yDpi_); +} + +DisplayInfo *DisplayInfo::Unmarshalling(Parcel &parcel) +{ + DisplayInfo *displayInfo = new DisplayInfo(); + if (displayInfo == nullptr) { + return nullptr; + } + uint32_t type = (uint32_t)DisplayType::DEFAULT; + bool res = parcel.ReadUint64(displayInfo->id_) && parcel.ReadUint32(type) && + parcel.ReadInt32(displayInfo->width_) && parcel.ReadInt32(displayInfo->height_) && + parcel.ReadUint32(displayInfo->freshRate_) && + parcel.ReadFloat(displayInfo->xDpi_) && parcel.ReadFloat(displayInfo->yDpi_); + if (!res) { + displayInfo = nullptr; + } else { + displayInfo->type_ = (DisplayType)type; + } + return displayInfo; +} +} // namespace OHOS::Rosen \ No newline at end of file diff --git a/wmtest/dmserver/src/display_manager_proxy.cpp b/wmtest/dmserver/src/display_manager_proxy.cpp new file mode 100644 index 0000000000000000000000000000000000000000..87c482a3e6d6876c5786b7c5b776f353734614c9 --- /dev/null +++ b/wmtest/dmserver/src/display_manager_proxy.cpp @@ -0,0 +1,104 @@ +/* + * Copyright (c) 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 "display_manager_proxy.h" + +#include + +#include "window_manager_hilog.h" + +namespace OHOS::Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "DisplayManagerProxy"}; +} + +const sptr& DisplayManagerProxy::GetDisplayInfo(const DisplayType type) +{ + sptr remote = Remote(); + if (remote == nullptr) { + WLOGFW("get display: remote is nullptr"); + return nullptr; + } + + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!data.WriteInterfaceToken(GetDescriptor())) { + WLOGFE("get display: WriteInterfaceToken failed"); + return nullptr; + } + data.WriteInt32(static_cast(type)); + if (remote->SendRequest(TRANS_ID_GET_DISPLAY_INFO, data, reply, option) != ERR_NONE) { + WLOGFW("get display: SendRequest failed"); + return nullptr; + } + // TODO: decode reply + return nullptr; +} + +DisplayId DisplayManagerProxy::GetDefaultDisplayId() +{ + sptr remote = Remote(); + if (remote == nullptr) { + WLOGFW("GetDefaultDisplayId: remote is nullptr"); + return DISPLAY_ID_INVALD; + } + + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!data.WriteInterfaceToken(GetDescriptor())) { + WLOGFE("GetDefaultDisplayId: WriteInterfaceToken failed"); + return DISPLAY_ID_INVALD; + } + if (remote->SendRequest(TRANS_ID_GET_DEFAULT_DISPLAY_ID, data, reply, option) != ERR_NONE) { + WLOGFW("GetDefaultDisplayId: SendRequest failed"); + return DISPLAY_ID_INVALD; + } + + DisplayId displayId = reply.ReadUint64(); + WLOGFI("DisplayManagerProxy::GetDefaultDisplayId %llu", displayId); + return displayId; +} + +DisplayInfo DisplayManagerProxy::GetDisplayInfoById(DisplayId displayId) +{ + sptr remote = Remote(); + if (remote == nullptr) { + WLOGFW("GetDisplayInfoById: remote is nullptr"); + return DisplayInfo(); + } + + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!data.WriteInterfaceToken(GetDescriptor())) { + WLOGFE("GetDisplayInfoById: WriteInterfaceToken failed"); + return DisplayInfo(); + } + data.WriteUint64(static_cast(displayId)); + if (remote->SendRequest(TRANS_ID_GET_DISPLAY_BY_ID, data, reply, option) != ERR_NONE) { + WLOGFW("GetDisplayInfoById: SendRequest failed"); + return DisplayInfo(); + } + + sptr info = reply.ReadParcelable(); + if (info == nullptr) { + WLOGFW("DisplayManagerProxy::GetDisplayInfoById SendRequest nullptr."); + return DisplayInfo(); + } + return *info; +} +} // namespace OHOS::Rosen \ No newline at end of file diff --git a/wmtest/dmserver/src/display_manager_service.cpp b/wmtest/dmserver/src/display_manager_service.cpp new file mode 100644 index 0000000000000000000000000000000000000000..93ca0d2d6a4a53e56cdbeb91ffdb52e7f38c56aa --- /dev/null +++ b/wmtest/dmserver/src/display_manager_service.cpp @@ -0,0 +1,113 @@ +/* + * Copyright (c) 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 "display_manager_service.h" + +#include +#include + +#include +#include +#include + +#include "window_manager_hilog.h" + +namespace OHOS::Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "DisplayManagerService"}; +} + +IMPLEMENT_SINGLE_INSTANCE(DisplayManagerService); + +const bool REGISTER_RESULT = + SystemAbility::MakeAndRegisterAbility(SingletonContainer::Get().GetRefPtr()); + +DisplayManagerService::DisplayManagerService() : SystemAbility(DISPLAY_MANAGER_SERVICE_SA_ID, true) +{ +} + +void DisplayManagerService::OnStart() +{ + WLOGFI("DisplayManagerService::OnStart start"); + if (!Init()) { + return; + } +} + +bool DisplayManagerService::Init() +{ + WLOGFI("DisplayManagerService::Init start"); + bool ret = Publish(this); + if (!ret) { + WLOGFW("DisplayManagerService::Init failed"); + return false; + } + displayScreenManager_ = DisplayScreenManager::GetInstance(); + if (displayScreenManager_ == nullptr) { + WLOGFW("Get DisplayScreenManager failed"); + return false; + } + WLOGFI("DisplayManagerService::Init success"); + return true; +} + +const sptr& DisplayManagerService::GetDisplayInfo(const DisplayType type) +{ + // TODO 从displayScreenMap_得到DisplayInfo + WLOGFI("DisplayManagerService::GetDisplayInfo"); + return new DisplayInfo(); +} + +DisplayId DisplayManagerService::GetDisplayIdFromScreenId(ScreenId screenId) +{ + return (DisplayId)screenId; +} + +ScreenId DisplayManagerService::GetScreenIdFromDisplayId(DisplayId displayId) +{ + return (ScreenId)displayId; +} + +DisplayId DisplayManagerService::GetDefaultDisplayId() +{ + if (displayScreenManager_ == nullptr) { + return DISPLAY_ID_INVALD; + } + ScreenId screenId = displayScreenManager_->GetDefaultScreenId(); + WLOGFI("GetDefaultDisplayId %{public}llu", screenId); + return GetDisplayIdFromScreenId(screenId); +} + +DisplayInfo DisplayManagerService::GetDisplayInfoById(DisplayId displayId) +{ + DisplayInfo displayInfo; + if (displayScreenManager_ == nullptr) { + return displayInfo; + } + ScreenId screenId = GetScreenIdFromDisplayId(displayId); + auto screenModeInfo = displayScreenManager_->GetScreenActiveMode(screenId); + displayInfo.id_ = displayId; + displayInfo.width_ = screenModeInfo.GetScreenWidth(); + displayInfo.height_ = screenModeInfo.GetScreenHeight(); + displayInfo.freshRate_ = screenModeInfo.GetScreenFreshRate(); + return displayInfo; +} + +void DisplayManagerService::OnStop() +{ + WLOGFI("ready to stop display service."); + displayScreenManager_ = nullptr; +} +} // namespace OHOS::Rosen \ No newline at end of file diff --git a/wmtest/dmserver/src/display_manager_service_inner.cpp b/wmtest/dmserver/src/display_manager_service_inner.cpp new file mode 100644 index 0000000000000000000000000000000000000000..61a9c3f6f868f3df191f14847fdbde83284be279 --- /dev/null +++ b/wmtest/dmserver/src/display_manager_service_inner.cpp @@ -0,0 +1,89 @@ +/* + * Copyright (c) 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 "display_manager_service_inner.h" + +#include +#include + +#include +#include +#include + +#include "display_screen_manager.h" +#include "display_manager_service.h" +#include "window_manager_hilog.h" + +namespace OHOS::Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "DisplayManagerServiceInner"}; +} + +IMPLEMENT_SINGLE_INSTANCE(DisplayManagerServiceInner); + +DisplayId DisplayManagerServiceInner::GetDefaultDisplayId() +{ + auto dms = DisplayManagerService::GetInstance(); + if (dms == nullptr) { + WLOGFE("GetDefaultDisplayId null!\n"); + return DISPLAY_ID_INVALD; + } + return dms->GetDefaultDisplayId(); +} + +const sptr DisplayManagerServiceInner::GetDisplayById(DisplayId displayId) +{ + auto dms = DisplayManagerService::GetInstance(); + if (dms == nullptr) { + WLOGFE("GetDisplayById null!\n"); + return nullptr; + } + DisplayInfo displayInfo = dms->GetDisplayInfoById(displayId); + + sptr display = new DisplayScreen(displayInfo); + if (display == nullptr) { + WLOGFE("GetDisplayById failed!\n"); + return nullptr; + } + return display; +} + +const sptr DisplayManagerServiceInner::GetDefaultDisplay() +{ + return GetDisplayById(GetDefaultDisplayId()); +} + +std::vector DisplayManagerServiceInner::GetAllDisplayIds() +{ + std::vector res; + res.push_back(GetDefaultDisplayId()); + return res; +} + +std::vector> DisplayManagerServiceInner::GetAllDisplays() +{ + std::vector> res; + auto displayIds = GetAllDisplayIds(); + for (auto displayId: displayIds) { + const sptr display = GetDisplayById(displayId); + if (display != nullptr) { + res.push_back(display); + } else { + WLOGFE("GetAllDisplays display %llu nullptr!", displayId); + } + } + return res; +} +} // namespace OHOS::Rosen \ No newline at end of file diff --git a/wmtest/dmserver/src/display_manager_stub.cpp b/wmtest/dmserver/src/display_manager_stub.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0e065619c8ef8c51af5aa8e3dc6db07f0e6fe872 --- /dev/null +++ b/wmtest/dmserver/src/display_manager_stub.cpp @@ -0,0 +1,59 @@ +/* + * Copyright (c) 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 "display_manager_stub.h" + +#include + +#include "window_manager_hilog.h" + +namespace OHOS::Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "DisplayManagerStub"}; +} + +int32_t DisplayManagerStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, + MessageOption &option) +{ + WLOGFI("OnRemoteRequest code is %{public}d", code); + if (data.ReadInterfaceToken() != GetDescriptor()) { + WLOGFE("InterfaceToken check failed"); + return -1; + } + switch (code) { + case TRANS_ID_GET_DISPLAY_INFO: { + DisplayType type = static_cast(data.ReadInt32()); + sptr info = GetDisplayInfo(type); + reply.WriteParcelable(info.GetRefPtr()); + break; + } + case TRANS_ID_GET_DEFAULT_DISPLAY_ID: { + DisplayId displayId = GetDefaultDisplayId(); + reply.WriteUint64(displayId); + break; + } + case TRANS_ID_GET_DISPLAY_BY_ID: { + DisplayId displayId = static_cast(data.ReadUint64()); + auto info = GetDisplayInfoById(displayId); + reply.WriteParcelable(&info); + break; + } + default: + WLOGFW("unknown transaction code"); + return IPCObjectStub::OnRemoteRequest(code, data, reply, option); + } + return 0; +} +} // namespace OHOS::Rosen \ No newline at end of file diff --git a/wmtest/dmserver/src/display_node_control.cpp b/wmtest/dmserver/src/display_node_control.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8f821aca7424aef573194937f43a09eb8439dc3c --- /dev/null +++ b/wmtest/dmserver/src/display_node_control.cpp @@ -0,0 +1,19 @@ +/* + * Copyright (c) 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 "display_node_control.h" + +namespace OHOS::Rosen { +} // namespace OHOS::Rosen \ No newline at end of file diff --git a/wmtest/dmserver/src/display_screen.cpp b/wmtest/dmserver/src/display_screen.cpp new file mode 100644 index 0000000000000000000000000000000000000000..bbc1876a1708a3f7c781c82e9acde37b060f6a4c --- /dev/null +++ b/wmtest/dmserver/src/display_screen.cpp @@ -0,0 +1,66 @@ +/* + * Copyright (c) 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 "display_screen.h" + +namespace OHOS::Rosen { +DisplayScreen::DisplayScreen(const DisplayInfo& info) + : id_(info.id_), + width_(info.width_), + height_(info.height_), + freshRate_(info.freshRate_) +{ +} + +DisplayId DisplayScreen::GetId() const +{ + return id_; +} + +int32_t DisplayScreen::GetWidth() const +{ + return width_; +} + +int32_t DisplayScreen::GetHeight() const +{ + return height_; +} + +uint32_t DisplayScreen::GetFreshRate() const +{ + return freshRate_; +} + +void DisplayScreen::SetWidth(int32_t width) +{ + width_ = width; +} + +void DisplayScreen::SetHeight(int32_t height) +{ + height_ = height; +} + +void DisplayScreen::SetFreshRate(uint32_t freshRate) +{ + freshRate_ = freshRate; +} + +void DisplayScreen::SetId(DisplayId id) +{ + id_ = id; +} +} // namespace OHOS::Rosen \ No newline at end of file diff --git a/wmtest/dmserver/src/display_screen_manager.cpp b/wmtest/dmserver/src/display_screen_manager.cpp new file mode 100644 index 0000000000000000000000000000000000000000..91620c7493cc2452158a5080a8ccd0385f80d1aa --- /dev/null +++ b/wmtest/dmserver/src/display_screen_manager.cpp @@ -0,0 +1,51 @@ +/* + * Copyright (c) 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 "display_screen_manager.h" + +namespace OHOS::Rosen { +IMPLEMENT_SINGLE_INSTANCE(DisplayScreenManager); + +DisplayScreenManager::DisplayScreenManager() : rsInterface_(&(RSInterfaces::GetInstance())) +{ + parepareRSScreenManger(); +} + +DisplayScreenManager::~DisplayScreenManager() +{ + rsInterface_ = nullptr; +} + +void DisplayScreenManager::parepareRSScreenManger() +{ +} + +ScreenId DisplayScreenManager::GetDefaultScreenId() +{ + if (rsInterface_ == nullptr) { + return INVALID_SCREEN_ID; + } + return rsInterface_->GetDefaultScreenId(); +} + +RSScreenModeInfo DisplayScreenManager::GetScreenActiveMode(ScreenId id) +{ + RSScreenModeInfo screenModeInfo; + if (rsInterface_ == nullptr) { + return screenModeInfo; + } + return rsInterface_->GetScreenActiveMode(id); +} +} // namespace OHOS::Rosen \ No newline at end of file diff --git a/wmtest/dmserver/src/rs_adapter.cpp b/wmtest/dmserver/src/rs_adapter.cpp new file mode 100644 index 0000000000000000000000000000000000000000..5e5d66581dbf3064e666305cfc936108183dcf5f --- /dev/null +++ b/wmtest/dmserver/src/rs_adapter.cpp @@ -0,0 +1,99 @@ +/* + * Copyright (c) 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 "rs_adapter.h" + +#include +#include +#include + +#include "window_manager_hilog.h" + +namespace OHOS::Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "RsAdapter"}; +} + +IMPLEMENT_SINGLE_INSTANCE(RsAdapter); + +bool RsAdapter::InitRSProxyLocked() +{ + WLOGFI("InitRProxy"); + if (!rsProxy_) { + sptr systemAbilityManager = + SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + if (!systemAbilityManager) { + WLOGFE("Failed to get system ability mgr."); + return false; + } + + sptr remoteObject + = systemAbilityManager->GetSystemAbility(); + if (!remoteObject) { + WLOGFE("Failed to get display manager service."); + return false; + } + + rsProxy_ = iface_cast(remoteObject); + if ((!rsProxy_) || (!rsProxy_->AsObject())) { + WLOGFE("Failed to get system display manager services"); + return false; + } + + rsDeath_ = new RSDeathRecipient(this); + if (!rsDeath_) { + WLOGFE("Failed to create death Recipient ptr RSDeathRecipient"); + return false; + } + if (!remoteObject->AddDeathRecipient(rsDeath_)) { + WLOGFE("Failed to add death recipient"); + return false; + } + } + return true; +} + +RSDeathRecipient::RSDeathRecipient(sptr& rsAdapter) +{ + rsAdatper_ = rsAdapter; +} + +void RSDeathRecipient::OnRemoteDied(const wptr& wptrDeath) +{ + if (wptrDeath == nullptr) { + WLOGFE("wptrDeath is null"); + return; + } + + sptr object = wptrDeath.promote(); + if (!object) { + WLOGFE("object is null"); + return; + } + if (rsAdapter_ != null) { + rsAdatper_.Clear(); + rsAdatper_ = nullptr; + } +} + +void RsAdapter::Clear() +{ + std::lock_guard lock(mutex_); + if ((rsProxy_ != nullptr) && (rsProxy_->AsObject() != nullptr)) { + rsProxy_->AsObject()->RemoveDeathRecipient(rsDeath_); + } + rsProxy_ = nullptr; +} +} // namespace OHOS::Rosen diff --git a/wmtest/dmserver/src/screen.cpp b/wmtest/dmserver/src/screen.cpp new file mode 100644 index 0000000000000000000000000000000000000000..11c222d130b9cbf29974b32080f165bd769e71ca --- /dev/null +++ b/wmtest/dmserver/src/screen.cpp @@ -0,0 +1,19 @@ +/* + * Copyright (c) 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 "screen.h" + +namespace OHOS::Rosen { +} // namespace OHOS::Rosen \ No newline at end of file diff --git a/wmtest/frameworks/inative_test.cpp b/wmtest/frameworks/inative_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..62b5316df5fee38aa69faffc7a58f2760233a45c --- /dev/null +++ b/wmtest/frameworks/inative_test.cpp @@ -0,0 +1,41 @@ +/* + * Copyright (c) 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 "inative_test.h" + +#include +#include + +namespace OHOS::Rosen { +void INativeTest::VisitTests(VisitTestFunc func) +{ + auto sortFunc = [](const auto &it, const auto &jt) { + if (it->GetDomain() == jt->GetDomain()) { + return it->GetID() < jt->GetID(); + } + return it->GetDomain() < jt->GetDomain(); + }; + std::sort(nativeTest_.begin(), nativeTest_.end(), sortFunc); + + for (auto &test : nativeTest_) { + func(test); + } +} + +INativeTest::INativeTest() +{ + nativeTest_.push_back(this); +} +} // namespace OHOS::Rosen diff --git a/wmtest/frameworks/inative_test.h b/wmtest/frameworks/inative_test.h new file mode 100644 index 0000000000000000000000000000000000000000..4a0ade056caefcb8ecb711a31d6338853cdb0437 --- /dev/null +++ b/wmtest/frameworks/inative_test.h @@ -0,0 +1,48 @@ +/* + * Copyright (c) 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 OHOS_ROSEN_INATIVE_TEST_H +#define OHOS_ROSEN_INATIVE_TEST_H + +#include +#include +#include +#include + +namespace OHOS::Rosen { +class INativeTest; +using VisitTestFunc = std::function; + +class INativeTest { +public: + enum { + LAST_TIME_FOREVER = 999999999, + }; + + static void VisitTests(VisitTestFunc func); + INativeTest(); + virtual ~INativeTest() = default; + + virtual std::string GetDescription() const = 0; + virtual std::string GetDomain() const = 0; + virtual int32_t GetID() const = 0; + virtual uint32_t GetLastTime() const = 0; + virtual void Run(int32_t argc, const char **argv) = 0; +private: + static inline std::vector nativeTest_; +}; +} // namespace OHOS::Rosen + +#endif // OHOS_ROSEN_INATIVE_TEST_H diff --git a/wmtest/frameworks/main.cpp b/wmtest/frameworks/main.cpp new file mode 100644 index 0000000000000000000000000000000000000000..cd38311459c022d0ba927088682c80234959c369 --- /dev/null +++ b/wmtest/frameworks/main.cpp @@ -0,0 +1,88 @@ +/* + * Copyright (c) 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 +#include +#include +#include +#include +#include + +#include + +#include "inative_test.h" + +using namespace OHOS::Rosen; + +namespace { +void Usage(const char *argv0) +{ + printf("Usage: %s type id\n", argv0); + auto visitFunc = [](const INativeTest *test) { + std::stringstream ss; + ss << test->GetDomain() << ", id="; + ss << test->GetID() << ": "; + ss << test->GetDescription(); + if (test->GetLastTime() != INativeTest::LAST_TIME_FOREVER) { + constexpr double msecToSec = 1000.0; + ss << " (last " << std::setprecision(1) << test->GetLastTime() / msecToSec << "s)"; + } + std::cout << ss.str() << std::endl; + }; + INativeTest::VisitTests(visitFunc); +} +} // namespace + +int32_t main(int32_t argc, const char **argv) +{ + constexpr int32_t argNumber = 2; + if (argc <= argNumber) { + Usage(argv[0]); + return 0; + } + + int32_t testcase = -1; + constexpr int32_t domainIndex = 1; + constexpr int32_t idIndex = 2; + std::stringstream ss(argv[idIndex]); + ss >> testcase; + if (ss.fail() == true || testcase == -1) { + Usage(argv[0]); + return 1; + } + + INativeTest *found = nullptr; + auto visitFunc = [argv, testcase, &found](INativeTest *test) { + if (test->GetDomain() == argv[domainIndex] && test->GetID() == testcase) { + found = test; + } + }; + INativeTest::VisitTests(visitFunc); + //if (found == nullptr) { + // printf("not found test %d\n", testcase); + // return 1; + //} + + auto runner = OHOS::AppExecFwk::EventRunner::Create(false); + auto handler = std::make_shared(runner); + handler->PostTask(std::bind(&INativeTest::Run, found, argc - 1, argv + 1)); + if (found->GetLastTime() != INativeTest::LAST_TIME_FOREVER) { + handler->PostTask(std::bind(&OHOS::AppExecFwk::EventRunner::Stop, runner), found->GetLastTime()); + } + + printf("%d %s run! pid=%d\n", found->GetID(), found->GetDescription().c_str(), getpid()); + runner->Run(); + return 0; +} diff --git a/wmtest/interfaces/innerkits/BUILD.gn b/wmtest/interfaces/innerkits/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..19b84753960f4359d913ec18436188ede1b46b63 --- /dev/null +++ b/wmtest/interfaces/innerkits/BUILD.gn @@ -0,0 +1,35 @@ +# Copyright (c) 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/ohos.gni") + +config("wm_interface_config") { + visibility = [ ":*" ] + include_dirs = [ "//foundation/windowmanager/interfaces/innerkits" ] +} + +ohos_shared_library("wm_interface") { + public_configs = [ ":wm_interface_config" ] + + include_dirs = [ "//foundation/windowmanager/interfaces/innerkits" ] + + public_deps = [ + "//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", + "//foundation/graphic/standard/rosen/modules/render_service_client:librender_service_client", + "//foundation/multimodalinput/input/frameworks/proxy:libmmi-client", + "//utils/native/base:utils", + ] + + part_name = "window_manager" + subsystem_name = "window" +} diff --git a/wmtest/interfaces/innerkits/dm/README.md b/wmtest/interfaces/innerkits/dm/README.md new file mode 100644 index 0000000000000000000000000000000000000000..bf79d111584d69930e9ec5dcb1e8e8d1015fd7a5 --- /dev/null +++ b/wmtest/interfaces/innerkits/dm/README.md @@ -0,0 +1 @@ +Store code of display client out header files diff --git a/wmtest/interfaces/innerkits/dm/display.h b/wmtest/interfaces/innerkits/dm/display.h new file mode 100644 index 0000000000000000000000000000000000000000..64b1bac72c3843938cd2bf5765fe6972ec144127 --- /dev/null +++ b/wmtest/interfaces/innerkits/dm/display.h @@ -0,0 +1,56 @@ +/* + * Copyright (c) 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 p ermissions and + * limitations under the License. + */ + +#ifndef FOUNDATION_DM_DISPLAY_H +#define FOUNDATION_DM_DISPLAY_H + +#include + +#include + +namespace OHOS::Rosen { +class DisplayInfo; +using DisplayId = uint64_t; +static constexpr DisplayId DISPLAY_ID_INVALD = -1ULL; + +typedef enum DisplayType { + DEFAULT = 0, +} DisplayType; + +class Display : public RefBase { +public: + Display(const std::string& name, DisplayInfo* info); + ~Display() = default; + + DisplayId GetId() const; + int32_t GetWidth() const; + int32_t GetHeight() const; + uint32_t GetFreshRate() const; + + void SetId(DisplayId displayId); + void SetWidth(int32_t width); + void SetHeight(int32_t height); + void SetFreshRate(uint32_t freshRate); + +private: + std::string name_; + DisplayId id_ {DISPLAY_ID_INVALD}; + int32_t width_ {0}; + int32_t height_ {0}; + uint32_t freshRate_ {0}; +}; +} // namespace OHOS::Rosen + +#endif // FOUNDATION_DM_DISPLAY_H \ No newline at end of file diff --git a/wmtest/interfaces/innerkits/dm/display_manager.h b/wmtest/interfaces/innerkits/dm/display_manager.h new file mode 100644 index 0000000000000000000000000000000000000000..ed91aba1d3324c2cd3a802664bd5ee07ac7cf201 --- /dev/null +++ b/wmtest/interfaces/innerkits/dm/display_manager.h @@ -0,0 +1,48 @@ +/* + * Copyright (c) 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 FOUNDATION_DM_DISPLAY_MANAGER_H +#define FOUNDATION_DM_DISPLAY_MANAGER_H + +#include +#include + +#include "display.h" +#include "single_instance.h" + +namespace OHOS::Rosen { +class DisplayManagerAdapter; + +class DisplayManager : public RefBase { +DECLARE_SINGLE_INSTANCE_BASE(DisplayManager); +public: + const sptr& GetDisplay(const DisplayType type); + std::vector> GetAllDisplays(); + + DisplayId GetDefaultDisplayId(); + const sptr GetDefaultDisplay(); + + const sptr GetDisplayById(DisplayId displayId); + + std::vector GetAllDisplayIds(); + +private: + DisplayManager(); + ~DisplayManager(); + sptr dmsAdapter_; +}; +} // namespace OHOS::Rosen + +#endif // FOUNDATION_DM_DISPLAY_MANAGER_H \ No newline at end of file diff --git a/wmtest/interfaces/innerkits/dm/display_property.h b/wmtest/interfaces/innerkits/dm/display_property.h new file mode 100644 index 0000000000000000000000000000000000000000..7409c0d12d8f142e7e12ce354150b81d387f04e4 --- /dev/null +++ b/wmtest/interfaces/innerkits/dm/display_property.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 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 FOUNDATION_DM_DISPLAY_PROPERTY_H +#define FOUNDATION_DM_DISPLAY_PROPERTY_H + +#include + +namespace OHOS::Rosen { +class DisplayProperty : public RefBase { +public: + DisplayProperty() = default; + ~DisplayProperty() = default; + + DisplayType type_; + std::string name_; + + int width_; + int height_; + float xDpi_; + float yDpi_; + // Surface surface_; +}; +} // namespace OHOS::Rosen + +#endif // FOUNDATION_DM_DISPLAY_PROPERTY_H \ No newline at end of file diff --git a/wmtest/interfaces/innerkits/dm/monitor.h b/wmtest/interfaces/innerkits/dm/monitor.h new file mode 100644 index 0000000000000000000000000000000000000000..0cb2b1647509a91ac75a018a971d70879186ebf3 --- /dev/null +++ b/wmtest/interfaces/innerkits/dm/monitor.h @@ -0,0 +1,24 @@ +/* + * Copyright (c) 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 FOUNDATION_DM_MONITOR_H +#define FOUNDATION_DM_MONITOR_H + +namespace OHOS::Rosen { +class Monitor { +}; +} // namespace OHOS::Rosen + +#endif // FOUNDATION_DM_MONITOR_H \ No newline at end of file diff --git a/wmtest/interfaces/innerkits/dmserver/README.md b/wmtest/interfaces/innerkits/dmserver/README.md new file mode 100644 index 0000000000000000000000000000000000000000..24e92014b98eebf446e3a87d2b5a7b29398866ab --- /dev/null +++ b/wmtest/interfaces/innerkits/dmserver/README.md @@ -0,0 +1 @@ +Store code of display server out header files diff --git a/wmtest/interfaces/innerkits/wm/README.md b/wmtest/interfaces/innerkits/wm/README.md new file mode 100644 index 0000000000000000000000000000000000000000..9702ea7e24e8e307993e40fa9d6b443c59d7672a --- /dev/null +++ b/wmtest/interfaces/innerkits/wm/README.md @@ -0,0 +1 @@ +Store code of window client out header files diff --git a/wmtest/interfaces/innerkits/wm/window.h b/wmtest/interfaces/innerkits/wm/window.h new file mode 100644 index 0000000000000000000000000000000000000000..7b7d89eae0dba0f01fc89f7163a96d88215c5b24 --- /dev/null +++ b/wmtest/interfaces/innerkits/wm/window.h @@ -0,0 +1,81 @@ +/* + * Copyright (c) 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 OHOS_ROSEN_WINDOW_H +#define OHOS_ROSEN_WINDOW_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include "wm_common.h" +#include "window_option.h" +#include "window_life_cycle_interface.h" + +class NativeValue; +class NativeEngine; + +namespace OHOS::AbilityRuntime { +class AbilityContext; +} + +namespace OHOS { +namespace Rosen { +class IWindowChangeListener : public RefBase { +public: + virtual void OnSizeChange(Rect rect) = 0; +}; + +class Window : public RefBase { +public: + static sptr Create(const std::string& windowName, + sptr& option, const sptr& abilityToken = nullptr); + static sptr Find(const std::string& windowName); + + virtual std::shared_ptr GetSurfaceNode() const = 0; + + virtual Rect GetRect() const = 0; + virtual WindowType GetType() const = 0; + virtual WindowMode GetMode() const = 0; + virtual const std::string& GetWindowName() const = 0; + virtual uint32_t GetWindowId() = 0; + + virtual WMError SetWindowType(WindowType type) = 0; + virtual WMError SetWindowMode(WindowMode mode) = 0; + + virtual WMError Destroy() = 0; + virtual WMError Show() = 0; + virtual WMError Hide() = 0; + + virtual WMError MoveTo(int32_t x, int32_t y) = 0; + virtual WMError Resize(uint32_t width, uint32_t height) = 0; + + virtual WMError RequestFocus() const = 0; + virtual void AddInputEventListener(std::shared_ptr& inputEventListener) = 0; // for api 7 + virtual void ConsumeKeyEvent(std::shared_ptr& inputEvent) = 0; + virtual void ConsumePointerEvent(std::shared_ptr& inputEvent) = 0; + + virtual void RegisterLifeCycleListener(sptr& listener) = 0; + virtual void RegisterWindowChangeListener(sptr& listener) = 0; + virtual WMError SetUIContent(std::shared_ptr context, + std::string& url, NativeEngine* engine, NativeValue* storage) = 0; +}; +} +} +#endif // OHOS_ROSEN_WINDOW_H diff --git a/wmtest/interfaces/innerkits/wm/window_life_cycle_interface.h b/wmtest/interfaces/innerkits/wm/window_life_cycle_interface.h new file mode 100644 index 0000000000000000000000000000000000000000..c9fa54b2a31bea26eb9c97cf72802c04fa9e71b3 --- /dev/null +++ b/wmtest/interfaces/innerkits/wm/window_life_cycle_interface.h @@ -0,0 +1,32 @@ +/* + * Copyright (c) 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 OHOS_ROSEN_WINDOW_LIFE_CYCLE_H +#define OHOS_ROSEN_WINDOW_LIFE_CYCLE_H + +#include + +namespace OHOS { +namespace Rosen { +class IWindowLifeCycle : public RefBase { +public: + virtual void AfterForeground() = 0; + virtual void AfterBackground() = 0; + virtual void AfterFocused() = 0; + virtual void AfterUnFocused() = 0; +}; +} +} +#endif // OHOS_ROSEN_WINDOW_LIFE_CYCLE_H diff --git a/wmtest/interfaces/innerkits/wm/window_option.h b/wmtest/interfaces/innerkits/wm/window_option.h new file mode 100644 index 0000000000000000000000000000000000000000..9f695dae2fa222d3ccf217bfa0d3f8ab56d63c69 --- /dev/null +++ b/wmtest/interfaces/innerkits/wm/window_option.h @@ -0,0 +1,63 @@ +/* + * Copyright (c) 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 OHOS_ROSEN_WINDOW_OPTION_H +#define OHOS_ROSEN_WINDOW_OPTION_H +#include +#include +#include "wm_common.h" + +namespace OHOS { +namespace Rosen { +class WindowOption : public RefBase { +public: + WindowOption(); + virtual ~WindowOption() = default; + + void SetWindowRect(const struct Rect& rect); + void SetWindowType(WindowType type); + void SetWindowMode(WindowMode mode); + void SetFocusable(bool isFocusable); + void SetTouchable(bool isTouchable); + void SetDisplayId(int32_t displayId); + void SetParentName(const std::string& parentName); + void SetWindowName(const std::string& windowName); + void AddWindowFlag(WindowFlag flag); + void RemoveWindowFlag(WindowFlag flag); + void SetWindowFlags(uint32_t flags); + + Rect GetWindowRect() const; + WindowType GetWindowType() const; + WindowMode GetWindowMode() const; + bool GetFocusable() const; + bool GetTouchable() const; + int32_t GetDisplayId() const; + const std::string& GetParentName() const; + const std::string& GetWindowName() const; + uint32_t GetWindowFlags() const; +private: + Rect windowRect_ { 0, 0, 0, 0 }; + WindowType type_ { WindowType::WINDOW_TYPE_APP_MAIN_WINDOW }; + WindowMode mode_ { WindowMode::WINDOW_MODE_FULLSCREEN }; + bool focusable_ { true }; + bool touchable_ { true }; + int32_t displayId_ { 0 }; + std::string parentName_ { "" }; + std::string windowName_ { "" }; + uint32_t flags_ { 0 }; +}; +} +} +#endif // OHOS_ROSEN_WINDOW_OPTION_H diff --git a/wmtest/interfaces/innerkits/wm/window_scene.h b/wmtest/interfaces/innerkits/wm/window_scene.h new file mode 100644 index 0000000000000000000000000000000000000000..dc984b01f9d773d4a610611e1ccf66babde93c7e --- /dev/null +++ b/wmtest/interfaces/innerkits/wm/window_scene.h @@ -0,0 +1,57 @@ +/* + * Copyright (c) 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 INTERFACES_INNERKITS_WINDOW_SCENE_H +#define INTERFACES_INNERKITS_WINDOW_SCENE_H + +#include +#include +#include + +#include "window.h" +#include "window_option.h" + +namespace OHOS { +namespace Rosen { +class WindowScene : public RefBase { +public: + static const int32_t DEFAULT_DISPLAY_ID = 0; + static const std::string MAIN_WINDOW_ID; + + WindowScene() = default; + ~WindowScene(); + + WMError Init(int32_t displayId, std::shared_ptr& abilityContext, + sptr& listener); + + sptr CreateWindow(const std::string& windowName, sptr& option) const; + + const sptr& GetMainWindow() const; + + WMError GoForeground(); + WMError GoBackground() const; + + WMError RequestFocus() const; + +private: + static inline std::atomic count { 0 }; + sptr mainWindow_ = nullptr; + int32_t displayId_ = DEFAULT_DISPLAY_ID; + + std::shared_ptr abilityContext_ = nullptr; +}; +} // namespace Rosen +} // namespace OHOS +#endif // INTERFACES_INNERKITS_WINDOW_SCENE_H diff --git a/wmtest/interfaces/innerkits/wm/wm_common.h b/wmtest/interfaces/innerkits/wm/wm_common.h new file mode 100644 index 0000000000000000000000000000000000000000..cd472f88b15a46170d649a5e40ae70761e52ddaf --- /dev/null +++ b/wmtest/interfaces/innerkits/wm/wm_common.h @@ -0,0 +1,96 @@ +/* + * Copyright (c) 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 OHOS_ROSEN_WM_COMMON_H +#define OHOS_ROSEN_WM_COMMON_H + +#include + +namespace OHOS { +namespace Rosen { +enum class WindowType : uint32_t { + APP_WINDOW_BASE = 1, + WINDOW_TYPE_APP_MAIN_WINDOW = APP_WINDOW_BASE, + APP_WINDOW_END = 999, + + APP_SUB_WINDOW_BASE = 1000, + WINDOW_TYPE_MEDIA = APP_SUB_WINDOW_BASE, + WINDOW_TYPE_APP_SUB_WINDOW, + APP_SUB_WINDOW_END = 1999, + + SYSTEM_WINDOW_BASE = 2000, + WINDOW_TYPE_WALLPAPER = SYSTEM_WINDOW_BASE, + ABOVE_APP_SYSTEM_WINDOW_BASE = 2100, + WINDOW_TYPE_APP_LAUNCHING, + WINDOW_TYPE_DOCK_SLICE, + WINDOW_TYPE_INCOMING_CALL, + WINDOW_TYPE_SEARCHING_BAR, + WINDOW_TYPE_SYSTEM_ALARM_WINDOW, + WINDOW_TYPE_INPUT_METHOD_FLOAT, + WINDOW_TYPE_FLOAT, + WINDOW_TYPE_TOAST, + WINDOW_TYPE_STATUS_BAR, + WINDOW_TYPE_PANEL, + WINDOW_TYPE_KEYGUARD, + WINDOW_TYPE_VOLUME_OVERLAY, + WINDOW_TYPE_NAVIGATION_BAR, + WINDOW_TYPE_DRAGGING_EFFECT, + WINDOW_TYPE_POINTER, + SYSTEM_WINDOW_END = 2999, +}; + +enum class WindowMode : uint32_t { + WINDOW_MODE_FULLSCREEN, + WINDOW_MODE_SPLIT, + WINDOW_MODE_FLOATING, + WINDOW_MODE_PIP +}; + +enum class WMError : int32_t { + WM_OK = 0, + WM_ERROR_SAMGR = 100, + WM_ERROR_IPC_FAILED = 101, + WM_ERROR_NO_MEM = 110, + WM_ERROR_NULLPTR = 120, + WM_ERROR_INVALID_PARAM = 130, + WM_ERROR_DESTROYED_OBJECT = 140, + WM_ERROR_DEATH_RECIPIENT = 150, + WM_ERROR_INVALID_WINDOW = 160, + WM_ERROR_UNKNOWN, + + /* weston adater */ + WM_ERROR_WINDOWMANAGER_GETINSTANCE = 100000, + WM_ERROR_WINDOWMANAGER_INIT = 100001, + WM_ERROR_WINDOWMANAGER_SHOW = 100002, + WM_ERROR_WINDOWMANAGER_HIDE = 100003, + WM_ERROR_WINDOWMANAGER_MOVE = 100004, + WM_ERROR_WINDOWMANAGER_RESIZE = 100005, +}; + +enum class WindowFlag : uint32_t { + WINDOW_FLAG_NEED_AVOID = 1, + WINDOW_FLAG_PARENT_LIMIT = 1 << 1, + WINDOW_FLAG_END = 1 << 2, +}; + +struct Rect { + int32_t posX_; + int32_t posY_; + uint32_t width_; + uint32_t height_; +}; +} +} +#endif // OHOS_ROSEN_WM_COMMON_H diff --git a/wmtest/interfaces/innerkits/wmserver/README.md b/wmtest/interfaces/innerkits/wmserver/README.md new file mode 100644 index 0000000000000000000000000000000000000000..449c0fe9fdd851fbe5f3d56ede74b9bb3a196347 --- /dev/null +++ b/wmtest/interfaces/innerkits/wmserver/README.md @@ -0,0 +1 @@ +Store code of window server out header files diff --git a/wmtest/interfaces/kits/README.md b/wmtest/interfaces/kits/README.md new file mode 100644 index 0000000000000000000000000000000000000000..033c7c544c454719ab8ccb97c8d75305486c54a3 --- /dev/null +++ b/wmtest/interfaces/kits/README.md @@ -0,0 +1 @@ +Store code of window js api diff --git a/wmtest/interfaces/kits/js/declaration/BUILD.gn b/wmtest/interfaces/kits/js/declaration/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..d63c1a22e0d716adef76adb82b6577df0f0e1604 --- /dev/null +++ b/wmtest/interfaces/kits/js/declaration/BUILD.gn @@ -0,0 +1,29 @@ +# Copyright (c) 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/ohos.gni") + +js_declaration("window") { + sources = [ "./api" ] + + part_name = "window_manager" +} + +ohos_copy("window_declaration") { + sources = [ "./api" ] + + outputs = [ target_out_dir + "/$target_name/" ] + + module_source_dir = target_out_dir + "/$target_name" + module_install_name = "" +} diff --git a/wmtest/interfaces/kits/js/declaration/api/@ohos.display.d.ts b/wmtest/interfaces/kits/js/declaration/api/@ohos.display.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..17ac54ae5dab238b0214df8be4b7e55f3be58573 --- /dev/null +++ b/wmtest/interfaces/kits/js/declaration/api/@ohos.display.d.ts @@ -0,0 +1,135 @@ +/* +* Copyright (c) 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. +*/ + +/** + * interface of display manager + * @devices tv, phone, tablet, wearable + */ +declare namespace display { + /** + * get the default display + * @devices tv, phone, tablet, wearable + */ + function getDefaultDisplay(): Promise; + + /** + /** + * the state of display + * @devices tv, phone, tablet, wearable + */ + enum DisplayState { + /** + * unknown + */ + STATE_UNKNOWN = 0, + /** + * screen off + */ + STATE_OFF, + /** + * screen on + */ + STATE_ON, + /** + * doze, but it will update for some important system messages + */ + STATE_DOZE, + /** + * doze and not update + */ + STATE_DOZE_SUSPEND, + /** + * VR node + */ + STATE_VR, + /** + * screen on and not update + */ + STATE_ON_SUSPEND, + } + + /** + * Properties of display, it couldn't update automatically + * @devices tv, phone, tablet, wearable + */ + interface Display { + /** + * display id + */ + id: number; + + /** + * display name + */ + name: string; + + /** + * the display is alive + */ + alive: boolean; + + /** + * the state of display + */ + state: DisplayState; + + /** + * refresh rate, unit: Hz + */ + refreshRate: number; + + /** + * the rotation degrees of the display + */ + rotation: number; + + /** + * the width of display, unit: pixel + */ + width: number; + + /** + * the height of display, unit: pixel + */ + height: number; + + /** + * indicates the display resolution. + */ + densityDPI: number; + + /** + * indicates the display density in pixels. The value of a low-resolution display is 1.0 + */ + densityPixels: number; + + /** + * indicates the text scale density of a display. + */ + scaledDensity: number; + + /** + * the DPI on X-axis. + */ + xDPI: number; + + /** + * the DPI on Y-axis. + */ + yDPI: number; + } +} + +export default display; diff --git a/wmtest/interfaces/kits/js/declaration/api/@ohos.window.d.ts b/wmtest/interfaces/kits/js/declaration/api/@ohos.window.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..3872e90048735e3fa1ea9da9dce0769e4ba149fb --- /dev/null +++ b/wmtest/interfaces/kits/js/declaration/api/@ohos.window.d.ts @@ -0,0 +1,79 @@ +/* +* Copyright (c) 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. +*/ + +/** + * Window manager. + * @devices tv, phone, tablet, wearable. +*/ +declare namespace window { + /** + * Obtain the top window of the current application. + * @devices tv, phone, tablet, wearable. + */ + function getTopWindow(): Promise; + + /** + * The type of a window. + * @devices tv, phone, tablet, wearable. + */ + enum WindowType { + /** + * App. + */ + TYPE_APP = 0, + /** + * System alert. + */ + TYPE_SYSTEM_ALERT = 30, + /** + * System volume. + */ + TYPE_SYSTEM_VOLUME = 70, + /** + * System panel. + */ + TYPE_SYSTEM_PANEL = 90, + } + + /** + * The interface of window. + */ + interface Window { + /** + * Set the position of a window. + * @param x Indicate the X-coordinate of the window. + * @param y Indicate the Y-coordinate of the window. + * @devices tv, phone, tablet, wearable, liteWearable. + */ + moveTo(x: number, y: number): Promise; + + /** + * Set the size of a window . + * @param width Indicates the width of the window. + * @param height Indicates the height of the window. + * @devices tv, phone, tablet, wearable, liteWearable. + */ + resetSize(width: number, height: number): Promise; + + /** + * Set the type of a window. + * @param type Indicate the type of a window. + * @devices tv, phone, tablet, wearable, liteWearable. + */ + setWindowType(type: WindowType): Promise; + } +} + +export default window; diff --git a/wmtest/interfaces/kits/napi/BUILD.gn b/wmtest/interfaces/kits/napi/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..00c0281a28413ee05cff7e7ff7c4b94be2da7bdd --- /dev/null +++ b/wmtest/interfaces/kits/napi/BUILD.gn @@ -0,0 +1,58 @@ +# Copyright (c) 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("//ark/ts2abc/ts2panda/ts2abc_config.gni") +import("//build/ohos.gni") + +ts2abc_gen_abc("gen_window_stage_abc") { + src_js = rebase_path("window_stage.js") + dst_file = rebase_path(target_out_dir + "/window_stage.abc") + in_puts = [ "window_stage.js" ] + out_puts = [ target_out_dir + "/window_stage.abc" ] + extra_args = [ "--module" ] +} + +gen_js_obj("window_stage_js") { + input = "window_stage.js" + output = target_out_dir + "/window_stage.o" +} + +gen_js_obj("window_stage_abc") { + input = get_label_info(":gen_window_stage_abc", "target_out_dir") + + "/window_stage.abc" + output = target_out_dir + "/window_stage_abc.o" + dep = ":gen_window_stage_abc" +} + +ohos_shared_library("windowstage") { + sources = [ "window_stage_module.cpp" ] + + deps = [ + ":window_stage_abc", + ":window_stage_js", + ] + + external_deps = [ "napi:ace_napi" ] + + relative_install_dir = "module/application" + + part_name = "window_manager" + subsystem_name = "window" +} + +group("napi_packages") { + deps = [ + "display:display", + "window:window", + ] +} diff --git a/wmtest/interfaces/kits/napi/common/BUILD.gn b/wmtest/interfaces/kits/napi/common/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..081352bd7b0e40125324ae1282ee56dea13bf13e --- /dev/null +++ b/wmtest/interfaces/kits/napi/common/BUILD.gn @@ -0,0 +1,46 @@ +# Copyright (c) 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/ohos.gni") + +## Build wm_napi_common.a {{{ +config("wm_napi_common_config") { + visibility = [ ":*" ] + + cflags = [ + "-Wall", + "-Werror", + "-g3", + ] +} + +config("wm_napi_common_public_config") { + include_dirs = [ + ".", + "//third_party/node/src", + ] +} + +ohos_static_library("wm_napi_common") { + sources = [ "wm_napi_common.cpp" ] + + configs = [ ":wm_napi_common_config" ] + + public_configs = [ ":wm_napi_common_public_config" ] + + public_deps = [ + "//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog", + "//foundation/ace/napi:ace_napi", + ] +} +## Build wm_napi_common.a }}} diff --git a/wmtest/interfaces/kits/napi/common/wm_napi_common.cpp b/wmtest/interfaces/kits/napi/common/wm_napi_common.cpp new file mode 100644 index 0000000000000000000000000000000000000000..16b5e6ef53e5ecfd58fe299b3a1c92e3564c9ea7 --- /dev/null +++ b/wmtest/interfaces/kits/napi/common/wm_napi_common.cpp @@ -0,0 +1,44 @@ +/* + * Copyright (c) 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 "wm_napi_common.h" + +#include + +namespace OHOS { +napi_status SetMemberInt32(napi_env env, napi_value result, const char *key, int32_t value) +{ + napi_value num; + GNAPI_INNER(napi_create_int32(env, value, &num)); + GNAPI_INNER(napi_set_named_property(env, result, key, num)); + return napi_ok; +} + +napi_status SetMemberUint32(napi_env env, napi_value result, const char *key, uint32_t value) +{ + napi_value num; + GNAPI_INNER(napi_create_uint32(env, value, &num)); + GNAPI_INNER(napi_set_named_property(env, result, key, num)); + return napi_ok; +} + +napi_status SetMemberUndefined(napi_env env, napi_value result, const char *key) +{ + napi_value undefined; + GNAPI_INNER(napi_get_undefined(env, &undefined)); + GNAPI_INNER(napi_set_named_property(env, result, key, undefined)); + return napi_ok; +} +} // namespace OHOS diff --git a/wmtest/interfaces/kits/napi/common/wm_napi_common.h b/wmtest/interfaces/kits/napi/common/wm_napi_common.h new file mode 100644 index 0000000000000000000000000000000000000000..480c511de12f56c776c31b05345df24facf900a8 --- /dev/null +++ b/wmtest/interfaces/kits/napi/common/wm_napi_common.h @@ -0,0 +1,111 @@ +/* + * Copyright (c) 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 INTERFACES_KITS_NAPI_GRAPHIC_COMMON_COMMON_H +#define INTERFACES_KITS_NAPI_GRAPHIC_COMMON_COMMON_H + +#include +#include + +#include +#include +#include +#include + +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, 0, "NapiWindowManagerCommonLayer" }; + +#define GNAPI_LOG(fmt, ...) OHOS::HiviewDFX::HiLog::Info(LABEL, \ + "%{public}s:%{public}d " fmt, __func__, __LINE__, ##__VA_ARGS__) + +#define GNAPI_ASSERT(env, assertion, fmt, ...) \ + do { \ + if (assertion) { \ + GNAPI_LOG(fmt, ##__VA_ARGS__); \ + return nullptr; \ + } \ + } while (0) + +#define GNAPI_INNER(call) \ + do { \ + napi_status s = (call); \ + if (s != napi_ok) { \ + GNAPI_LOG(#call " is %{public}d", s); \ + return s; \ + } \ + } while (0) + +namespace OHOS { +napi_status SetMemberInt32(napi_env env, napi_value result, const char *key, int32_t value); +napi_status SetMemberUint32(napi_env env, napi_value result, const char *key, uint32_t value); +napi_status SetMemberUndefined(napi_env env, napi_value result, const char *key); + +template +napi_value CreatePromise(napi_env env, + std::string funcname, + void(*async)(napi_env env, std::unique_ptr& param), + napi_value(*resolve)(napi_env env, std::unique_ptr& param), + std::unique_ptr& param) +{ + struct AsyncCallbackInfo { + napi_async_work asyncWork; + napi_deferred deferred; + void (*async)(napi_env env, std::unique_ptr& param); + napi_value (*resolve)(napi_env env, std::unique_ptr& param); + std::unique_ptr param; + }; + + AsyncCallbackInfo *info = new AsyncCallbackInfo { + .async = async, + .resolve = resolve, + .param = std::move(param), + }; + + napi_value resourceName; + NAPI_CALL(env, napi_create_string_latin1(env, + funcname.c_str(), NAPI_AUTO_LENGTH, &resourceName)); + + napi_value promise; + NAPI_CALL(env, napi_create_promise(env, &info->deferred, &promise)); + + auto asyncFunc = [](napi_env env, void *data) { + AsyncCallbackInfo *info = reinterpret_cast(data); + if (info->async) { + info->async(env, info->param); + } + }; + + auto completeFunc = [](napi_env env, napi_status status, void *data) { + AsyncCallbackInfo *info = reinterpret_cast(data); + napi_value resolveValue; + if (info->resolve) { + resolveValue = info->resolve(env, info->param); + } else { + napi_get_undefined(env, &resolveValue); + } + + napi_resolve_deferred(env, info->deferred, resolveValue); + napi_delete_async_work(env, info->asyncWork); + delete info; + }; + + NAPI_CALL(env, napi_create_async_work(env, nullptr, resourceName, asyncFunc, completeFunc, + reinterpret_cast(info), &info->asyncWork)); + + NAPI_CALL(env, napi_queue_async_work(env, info->asyncWork)); + return promise; +}; +} // namespace OHOS + +#endif // INTERFACES_KITS_NAPI_GRAPHIC_COMMON_COMMON_H diff --git a/wmtest/interfaces/kits/napi/display/BUILD.gn b/wmtest/interfaces/kits/napi/display/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..574ecb8a1c87b32f9c8b3050e80d78af543cb53b --- /dev/null +++ b/wmtest/interfaces/kits/napi/display/BUILD.gn @@ -0,0 +1,30 @@ +# Copyright (c) 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/ohos.gni") + +## Build display.so {{{ +ohos_shared_library("display") { + sources = [ "native_display_module.cpp" ] + + deps = [ + "../common:wm_napi_common", + "//foundation/windowmanager/wm:libwm", + "//foundation/windowmanager/wmserver:libwms", + ] + + relative_install_dir = "module" + part_name = "window_manager" + subsystem_name = "window" +} +## Build display.so }}} diff --git a/wmtest/interfaces/kits/napi/display/native_display_module.cpp b/wmtest/interfaces/kits/napi/display/native_display_module.cpp new file mode 100644 index 0000000000000000000000000000000000000000..613ffaa0de1ba0d5d4bbb117a43c5fdfffc02904 --- /dev/null +++ b/wmtest/interfaces/kits/napi/display/native_display_module.cpp @@ -0,0 +1,116 @@ +/* + * Copyright (c) 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 "display_manager.h" +#include "native_display_module.h" +#include "wm_common.h" +#include "wm_napi_common.h" + +namespace OHOS { +namespace Rosen { +namespace getDefaultDisplay { +struct Param { + WMError wret; + sptr display; +}; + +void Async(napi_env env, std::unique_ptr ¶m) +{ + sptr dm = DisplayManager::GetInstance(); + if (dm == nullptr) { + GNAPI_LOG("dm error!\n"); + return; + } + + param->display = dm->GetDefaultDisplay(); + if (param->display == nullptr) { + GNAPI_LOG("Get display failed!"); + param->wret = WMError::WM_ERROR_NULLPTR; + return; + } + GNAPI_LOG("GetDefaultDisplay: id %llu, w %d, h %d", + param->display->GetId(), param->display->GetWidth(), param->display->GetHeight()); + param->wret = WMError::WM_OK; +} + +napi_value Resolve(napi_env env, std::unique_ptr ¶m) +{ + napi_value result; + if (param->wret != WMError::WM_OK) { + NAPI_CALL(env, napi_get_undefined(env, &result)); + return result; + } + + DisplayId id = param->display->GetId(); + int32_t width = param->display->GetWidth(); + int32_t height = param->display->GetHeight(); + GNAPI_LOG("id : %{public}llu", id); + GNAPI_LOG("width : %{public}d", width); + GNAPI_LOG("height : %{public}d", height); + + NAPI_CALL(env, napi_create_object(env, &result)); + NAPI_CALL(env, SetMemberInt32(env, result, "id", id)); + NAPI_CALL(env, SetMemberUndefined(env, result, "name")); + NAPI_CALL(env, SetMemberUndefined(env, result, "alive")); + NAPI_CALL(env, SetMemberUndefined(env, result, "state")); + NAPI_CALL(env, SetMemberUndefined(env, result, "refreshRate")); + NAPI_CALL(env, SetMemberUndefined(env, result, "rotation")); + NAPI_CALL(env, SetMemberUint32(env, result, "width", width)); + NAPI_CALL(env, SetMemberUint32(env, result, "height", height)); + NAPI_CALL(env, SetMemberUndefined(env, result, "densityDPI")); + NAPI_CALL(env, SetMemberUndefined(env, result, "densityPixels")); + NAPI_CALL(env, SetMemberUndefined(env, result, "scaledDensity")); + NAPI_CALL(env, SetMemberUndefined(env, result, "xDPI")); + NAPI_CALL(env, SetMemberUndefined(env, result, "yDPI")); + + return result; +} + +napi_value MainFunc(napi_env env, napi_callback_info info) +{ + GNAPI_LOG("Display Interface: getDefaultDisplay()"); + GNAPI_LOG("%{public}s called", __PRETTY_FUNCTION__); + auto param = std::make_unique(); + return CreatePromise(env, __PRETTY_FUNCTION__, Async, Resolve, param); +} +} // namespace getDefaultDisplay + +napi_value DisplayModuleInit(napi_env env, napi_value exports) +{ + GNAPI_LOG("%{public}s called", __PRETTY_FUNCTION__); + + napi_property_descriptor properties[] = { + DECLARE_NAPI_FUNCTION("getDefaultDisplay", getDefaultDisplay::MainFunc), + }; + + NAPI_CALL(env, napi_define_properties(env, + exports, sizeof(properties) / sizeof(properties[0]), properties)); + return exports; +} +} // namespace Rosen +} // namespace OHOS + +extern "C" __attribute__((constructor)) void RegisterModule(void) +{ + napi_module displayModule = { + .nm_version = 1, // NAPI v1 + .nm_flags = 0, // normal + .nm_filename = nullptr, + .nm_register_func = OHOS::Rosen::DisplayModuleInit, + .nm_modname = "display", + .nm_priv = nullptr, + }; + napi_module_register(&displayModule); +} diff --git a/wmtest/interfaces/kits/napi/display/native_display_module.h b/wmtest/interfaces/kits/napi/display/native_display_module.h new file mode 100644 index 0000000000000000000000000000000000000000..a24c7026abc00fa5964b264b278e9f9ba75770d1 --- /dev/null +++ b/wmtest/interfaces/kits/napi/display/native_display_module.h @@ -0,0 +1,19 @@ +/* + * Copyright (c) 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 INTERFACES_KITS_NAPI_GRAPHIC_DISPLAY_NATIVE_MODULE_H +#define INTERFACES_KITS_NAPI_GRAPHIC_DISPLAY_NATIVE_MODULE_H + +#endif // INTERFACES_KITS_NAPI_GRAPHIC_DISPLAY_NATIVE_MODULE_H diff --git a/wmtest/interfaces/kits/napi/window/BUILD.gn b/wmtest/interfaces/kits/napi/window/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..449bfb7fb414b0ae53027a0a39827a18e469061c --- /dev/null +++ b/wmtest/interfaces/kits/napi/window/BUILD.gn @@ -0,0 +1,40 @@ +# Copyright (c) 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/ohos.gni") + +## Build window.so {{{ +ohos_shared_library("window") { + sources = [ "native_window_module.cpp" ] + + configs = [ + "//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_core:bundlemgr_sdk_config", + "//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_base:appexecfwk_base_sdk_config", + "//foundation/aafwk/standard/interfaces/innerkits/want:want_public_config", + "//foundation/aafwk/standard/interfaces/innerkits/ability_manager:ability_manager_public_config", + "//foundation/aafwk/standard/services/abilitymgr:abilityms_config", + ] + + deps = [ + "../common:wm_napi_common", + "//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native", + "//foundation/appexecfwk/standard/kits:appkit_native", + "//foundation/windowmanager/wm:libwm", + "//foundation/windowmanager/wmserver:libwms", + ] + + relative_install_dir = "module" + part_name = "window_manager" + subsystem_name = "window" +} +## Build window.so }}} diff --git a/wmtest/interfaces/kits/napi/window/native_window_module.cpp b/wmtest/interfaces/kits/napi/window/native_window_module.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c009e2aa996ee8520d8559a3f14d39a2da37b0ec --- /dev/null +++ b/wmtest/interfaces/kits/napi/window/native_window_module.cpp @@ -0,0 +1,233 @@ +/* + * Copyright (c) 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 + +#include "native_window_module.h" +#include "window.h" +#include "window_scene.h" +#include "wm_common.h" +#include "wm_napi_common.h" + +namespace OHOS { +namespace Rosen { +namespace { +napi_value g_classWindow; +napi_status GetAbility(napi_env env, napi_callback_info info, AppExecFwk::Ability* &pAbility) +{ + napi_value global; + GNAPI_INNER(napi_get_global(env, &global)); + + napi_value jsAbility; + GNAPI_INNER(napi_get_named_property(env, global, "ability", &jsAbility)); + + GNAPI_INNER(napi_get_value_external(env, jsAbility, reinterpret_cast(&pAbility))); + + return napi_ok; +} +} // namespace + + +namespace NAPIWindow { +napi_value WindowConstructor(napi_env env, napi_callback_info info) +{ + napi_value jsthis = nullptr; + NAPI_CALL(env, napi_get_cb_info(env, info, nullptr, nullptr, &jsthis, nullptr)); + return jsthis; +} + +namespace ResetSize { +struct Param { + ::OHOS::AppExecFwk::Ability *ability; + int width; + int height; +}; + +void Async(napi_env env, std::unique_ptr& param) +{ + param->ability->GetScene()->GetMainWindow()->Resize(param->width, param->height); +} + +napi_value MainFunc(napi_env env, napi_callback_info info) +{ + GNAPI_LOG("Window Interface: ResetSize()"); + GNAPI_LOG("%{public}s called", __PRETTY_FUNCTION__); + constexpr int argumentSize = 2; + size_t argc = argumentSize; + napi_value argv[argc]; + + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr)); + + GNAPI_ASSERT(env, argc < argumentSize, "ResetSize need %{public}d arguments", argumentSize); + + auto param = std::make_unique(); + NAPI_CALL(env, GetAbility(env, info, param->ability)); + NAPI_CALL(env, napi_get_value_int32(env, argv[0], ¶m->width)); + NAPI_CALL(env, napi_get_value_int32(env, argv[1], ¶m->height)); + + return CreatePromise(env, __PRETTY_FUNCTION__, Async, nullptr, param); +} +} // namespace ResetSize + +namespace MoveTo { +struct Param { + ::OHOS::AppExecFwk::Ability *ability; + int x; + int y; +}; + +void Async(napi_env env, std::unique_ptr& param) +{ + param->ability->GetScene()->GetMainWindow()->MoveTo(param->x, param->y); +} + +napi_value MainFunc(napi_env env, napi_callback_info info) +{ + GNAPI_LOG("Window Interface: MoveTo()"); + GNAPI_LOG("%{public}s called", __PRETTY_FUNCTION__); + constexpr int argumentSize = 2; + size_t argc = argumentSize; + napi_value argv[argc]; + + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr)); + + GNAPI_ASSERT(env, argc < argumentSize, "MoveTo need %{public}d arguments", argumentSize); + + auto param = std::make_unique(); + NAPI_CALL(env, GetAbility(env, info, param->ability)); + NAPI_CALL(env, napi_get_value_int32(env, argv[0], ¶m->x)); + NAPI_CALL(env, napi_get_value_int32(env, argv[1], ¶m->y)); + + return CreatePromise(env, __PRETTY_FUNCTION__, Async, nullptr, param); +} +} // namespace MoveTo + +namespace SetWindowType { +struct Param { + ::OHOS::AppExecFwk::Ability *ability; + int windowType; +}; + +void Async(napi_env env, std::unique_ptr& param) +{ + param->ability->GetScene()->GetMainWindow()->SetWindowType(static_cast(param->windowType)); +} + +void CreateWindowTypeObject(napi_env env, napi_value value) +{ + SetMemberInt32(env, value, "TYPE_APP", static_cast(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW)); + SetMemberInt32(env, value, "TYPE_SYSTEM_ALERT", static_cast(WindowType::WINDOW_TYPE_SYSTEM_ALARM_WINDOW)); + SetMemberInt32(env, value, "TYPE_SYSTEM_VOLUME", static_cast(WindowType::WINDOW_TYPE_VOLUME_OVERLAY)); + SetMemberInt32(env, value, "TYPE_SYSTEM_PANEL", static_cast(WindowType::WINDOW_TYPE_PANEL)); +} + +napi_value MainFunc(napi_env env, napi_callback_info info) +{ + GNAPI_LOG("Window Interface: SetWindowType()"); + GNAPI_LOG("%{public}s called", __PRETTY_FUNCTION__); + constexpr int argumentSize = 1; + size_t argc = argumentSize; + napi_value argv[argc]; + + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr)); + + GNAPI_ASSERT(env, argc < argumentSize, "SetWindowType need %{public}d arguments", argumentSize); + + auto param = std::make_unique(); + NAPI_CALL(env, GetAbility(env, info, param->ability)); + NAPI_CALL(env, napi_get_value_int32(env, argv[0], ¶m->windowType)); + + return CreatePromise(env, __PRETTY_FUNCTION__, Async, nullptr, param); +} +} // namespace SetWindowType +} // namespace NAPIWindow + +namespace getTopWindow { +struct Param { + ::OHOS::AppExecFwk::Ability *ability; + WMError wret; + sptr window; +}; + +void Async(napi_env env, std::unique_ptr ¶m) +{ + param->window = param->ability->GetScene()->GetMainWindow(); + if (param->window == nullptr) { + GNAPI_LOG("Get main-window failed!"); + param->wret = WMError::WM_ERROR_NULLPTR; + return; + } + param->wret = WMError::WM_OK; +} + +napi_value Resolve(napi_env env, std::unique_ptr& userdata) +{ + napi_value ret; + NAPI_CALL(env, napi_new_instance(env, g_classWindow, 0, nullptr, &ret)); + return ret; +} + +napi_value MainFunc(napi_env env, napi_callback_info info) +{ + GNAPI_LOG("Window Interface: getTopWindow()"); + GNAPI_LOG("%{public}s called", __PRETTY_FUNCTION__); + auto param = std::make_unique(); + return CreatePromise(env, __PRETTY_FUNCTION__, Async, Resolve, param); +} +} // namespace getTopWindow + +napi_value WindowModuleInit(napi_env env, napi_value exports) +{ + GNAPI_LOG("%{public}s called", __PRETTY_FUNCTION__); + + napi_value nWindowType = nullptr; + NAPI_CALL(env, napi_create_object(env, &nWindowType)); + NAPIWindow::SetWindowType::CreateWindowTypeObject(env, nWindowType); + + napi_property_descriptor desc[] = { + DECLARE_NAPI_FUNCTION("resetSize", NAPIWindow::ResetSize::MainFunc), + DECLARE_NAPI_FUNCTION("moveTo", NAPIWindow::MoveTo::MainFunc), + DECLARE_NAPI_FUNCTION("setWindowType", NAPIWindow::SetWindowType::MainFunc), + }; + + NAPI_CALL(env, napi_define_class(env, "Window", NAPI_AUTO_LENGTH, + NAPIWindow::WindowConstructor, nullptr, + sizeof(desc) / sizeof(*desc), desc, &g_classWindow)); + + napi_property_descriptor exportFuncs[] = { + DECLARE_NAPI_FUNCTION("getTopWindow", getTopWindow::MainFunc), + DECLARE_NAPI_PROPERTY("WindowType", nWindowType), + DECLARE_NAPI_PROPERTY("Window", g_classWindow), + }; + + NAPI_CALL(env, napi_define_properties(env, + exports, sizeof(exportFuncs) / sizeof(*exportFuncs), exportFuncs)); + return exports; +} +} // namespace Rosen +} // namespace OHOS + +extern "C" __attribute__((constructor)) void RegisterModule(void) +{ + napi_module windowModule = { + .nm_version = 1, // NAPI v1 + .nm_flags = 0, // normal + .nm_filename = nullptr, + .nm_register_func = OHOS::Rosen::WindowModuleInit, + .nm_modname = "window", + .nm_priv = nullptr, + }; + napi_module_register(&windowModule); +} diff --git a/wmtest/interfaces/kits/napi/window/native_window_module.h b/wmtest/interfaces/kits/napi/window/native_window_module.h new file mode 100644 index 0000000000000000000000000000000000000000..c4a21c440cb040305c15a5816fceba2824d6ec7d --- /dev/null +++ b/wmtest/interfaces/kits/napi/window/native_window_module.h @@ -0,0 +1,19 @@ +/* + * Copyright (c) 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 INTERFACES_KITS_NAPI_GRAPHIC_WINDOW_NATIVE_WINDOW_MODULE_H +#define INTERFACES_KITS_NAPI_GRAPHIC_WINDOW_NATIVE_WINDOW_MODULE_H + +#endif // INTERFACES_KITS_NAPI_GRAPHIC_WINDOW_NATIVE_WINDOW_MODULE_H diff --git a/wmtest/interfaces/kits/napi/window_stage.js b/wmtest/interfaces/kits/napi/window_stage.js new file mode 100644 index 0000000000000000000000000000000000000000..43af79d1a0e23162632d56776f0ad82a123019d9 --- /dev/null +++ b/wmtest/interfaces/kits/napi/window_stage.js @@ -0,0 +1,26 @@ +/* + * Copyright (c) 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. + */ + +class WindowStage { + constructor(obj) { + this.__window_stage__ = obj + } + + setUIContent(context, url, storage) { + return this.__window_stage__.setUIContent(context, url, storage) + } +} + +export default WindowStage diff --git a/wmtest/interfaces/kits/napi/window_stage_module.cpp b/wmtest/interfaces/kits/napi/window_stage_module.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b6ad1d3a6524d736975e43ebb38086998b678766 --- /dev/null +++ b/wmtest/interfaces/kits/napi/window_stage_module.cpp @@ -0,0 +1,58 @@ +/* + * Copyright (c) 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 "native_engine/native_engine.h" + +extern const char _binary_window_stage_js_start[]; +extern const char _binary_window_stage_js_end[]; +extern const char _binary_window_stage_abc_start[]; +extern const char _binary_window_stage_abc_end[]; + +extern "C" __attribute__((constructor)) +void NAPI_application_WindowStage_AutoRegister() +{ + auto moduleManager = NativeModuleManager::GetInstance(); + NativeModule newModuleInfo = { + .name = "application.WindowStage", + .fileName = "application/libwindowstage.so/window_stage.js", + }; + + moduleManager->Register(&newModuleInfo); +} + +extern "C" __attribute__((visibility("default"))) +void NAPI_application_WindowStage_GetJSCode(const char **buf, int *bufLen) +{ + if (buf != nullptr) { + *buf = _binary_window_stage_js_start; + } + + if (bufLen != nullptr) { + *bufLen = _binary_window_stage_js_end - _binary_window_stage_js_start; + } +} + +// window_stage JS register +extern "C" __attribute__((visibility("default"))) +void NAPI_application_WindowStage_GetABCCode(const char **buf, int *buflen) +{ + if (buf != nullptr) { + *buf = _binary_window_stage_abc_start; + } + if (buflen != nullptr) { + *buflen = _binary_window_stage_abc_end - _binary_window_stage_abc_start; + } +} + diff --git a/wmtest/ohos.build b/wmtest/ohos.build new file mode 100644 index 0000000000000000000000000000000000000000..49aaabd0f0d5fd7588fae9c0a98ceacf02323b83 --- /dev/null +++ b/wmtest/ohos.build @@ -0,0 +1,22 @@ +{ + "subsystem": "window", + "parts": { + "window_manager": { + "module_list": [ + "//foundation/windowmanager/interfaces/kits/js/declaration:window", + "//foundation/windowmanager/sa_profile:wms_sa_profile", + "//foundation/windowmanager/adapter:libwmadaptertest", + "//foundation/windowmanager/wm:libwm", + "//foundation/windowmanager/wmserver:libwms", + "//foundation/windowmanager/wm:libwmutil", + "//foundation/windowmanager/wmtest:rosenwmtest", + + "//foundation/windowmanager/interfaces/kits/napi:windowstage", + "//foundation/windowmanager/interfaces/kits/napi:napi_packages" + ], + + "test_list": [ + ] + } + } +} diff --git a/wmtest/sa_profile/4605.xml b/wmtest/sa_profile/4605.xml new file mode 100644 index 0000000000000000000000000000000000000000..9197521b84da4a3c388437fdcd08737748f304df --- /dev/null +++ b/wmtest/sa_profile/4605.xml @@ -0,0 +1,26 @@ + + + + foundation + + 4605 + libwms.z.so + + + true + false + 1 + + \ No newline at end of file diff --git a/wmtest/sa_profile/4606.xml b/wmtest/sa_profile/4606.xml new file mode 100644 index 0000000000000000000000000000000000000000..7a02c334da51c72dd7275991b7f5fe9b667c4f74 --- /dev/null +++ b/wmtest/sa_profile/4606.xml @@ -0,0 +1,26 @@ + + + + foundation + + 4606 + libwms.z.so + + + true + false + 1 + + diff --git a/wmtest/sa_profile/BUILD.gn b/wmtest/sa_profile/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..f3a586d78108d54cf5737e224b183325af25b5f7 --- /dev/null +++ b/wmtest/sa_profile/BUILD.gn @@ -0,0 +1,22 @@ +# Copyright (c) 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/ohos/sa_profile/sa_profile.gni") + +ohos_sa_profile("wms_sa_profile") { + sources = [ + "4605.xml", + "4606.xml", + ] + part_name = "window_manager" +} diff --git a/wmtest/test/dm_native_test.cpp b/wmtest/test/dm_native_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3373ab11eddf9328cb918d6b5b2866710bbc49d3 --- /dev/null +++ b/wmtest/test/dm_native_test.cpp @@ -0,0 +1,96 @@ +/* + * Copyright (c) 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 "dm_native_test.h" + +#include +#include +#include "wm_common.h" +#include "display_manager.h" +#include "singleton_container.h" + +using namespace OHOS::Rosen; + +namespace { +DMNativeTest g_autoload; +} // namespace + +std::string DMNativeTest::GetDescription() const +{ + constexpr const char *desc = "normal display"; + return desc; +} + +std::string DMNativeTest::GetDomain() const +{ + constexpr const char *desc = "dmclient"; + return desc; +} + +int32_t DMNativeTest::GetID() const +{ + constexpr int32_t id = 1; + return id; +} + +uint32_t DMNativeTest::GetLastTime() const +{ + constexpr uint32_t lastTime = LAST_TIME_FOREVER; + return lastTime; +} + +void DMNativeTest::Run(int32_t argc, const char **argv) +{ + printf("DMNativeTest run begin\n"); + sptr dms = DisplayManager::GetInstance(); + if (dms == nullptr) { + printf("dms error!\n"); + return; + } + + DisplayId displayId = dms->GetDefaultDisplayId(); + printf("defaultDisplayId: %llu\n", displayId); + + auto display = dms->GetDefaultDisplay(); + if (display == nullptr) { + printf("GetDefaultDisplay: failed!\n"); + } else { + printf("GetDefaultDisplay: id %llu, w %d, h %d, fps %u\n", display->GetId(), display->GetWidth(), + display->GetHeight(), display->GetFreshRate()); + } + + auto ids = dms->GetAllDisplayIds(); + for (auto id: ids) { + display = dms->GetDisplayById(displayId); + if (display == nullptr) { + printf("GetDisplayById(%llu): failed!\n", id); + } else { + printf("GetDisplayById(%llu): id %llu, w %d, h %d, fps %u\n", id, display->GetId(), display->GetWidth(), + display->GetHeight(), display->GetFreshRate()); + } + } + + auto displays = dms->GetAllDisplays(); + for (auto disp: displays) { + if (disp == nullptr) { + printf("GetAllDisplays: failed!\n"); + } else { + printf("GetAllDisplays: id %llu, w %d, h %d, fps %u\n", disp->GetId(), disp->GetWidth(), + disp->GetHeight(), disp->GetFreshRate()); + } + } + + printf("DMNativeTest run finish\n"); +} diff --git a/wmtest/test/dm_native_test.h b/wmtest/test/dm_native_test.h new file mode 100644 index 0000000000000000000000000000000000000000..7b325bf81d6dfae52a8af88b2b2d410c869f355e --- /dev/null +++ b/wmtest/test/dm_native_test.h @@ -0,0 +1,40 @@ +/* + * Copyright (c) 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 OHOS_ROSEN_DM_NATIVE_TEST_H +#define OHOS_ROSEN_DM_NATIVE_TEST_H + +#include +#include "inative_test.h" + +namespace OHOS::Rosen { +class DMNativeTest : public INativeTest { +public: + virtual ~DMNativeTest() = default; + virtual std::string GetDescription() const override; + virtual std::string GetDomain() const override; + virtual int32_t GetID() const override; + virtual uint32_t GetLastTime() const override; + + virtual void Run(int32_t argc, const char **argv) override; + +private: + void PostTask(std::function func, uint32_t delayTime = 0); + void ExitTest(); + int64_t GetNowTime(); +}; +} + +#endif // OHOS_ROSEN_DM_NATIVE_TEST_H diff --git a/wmtest/test/wm_native_test.cpp b/wmtest/test/wm_native_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..6d63a5e21b9fa82c02472525b3d6a2a4f532e334 --- /dev/null +++ b/wmtest/test/wm_native_test.cpp @@ -0,0 +1,74 @@ +/* + * Copyright (c) 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 "wm_native_test.h" + +#include +#include +#include +#include "window.h" +#include "window_life_cycle_interface.h" +#include "window_option.h" +#include "window_scene.h" +#include "wm_common.h" + +using namespace OHOS::Rosen; + +namespace { +WMNativeTest g_autoload; +} // namespace + +std::string WMNativeTest::GetDescription() const +{ + constexpr const char *desc = "normal window"; + return desc; +} + +std::string WMNativeTest::GetDomain() const +{ + constexpr const char *desc = "wmclient"; + return desc; +} + +int32_t WMNativeTest::GetID() const +{ + constexpr int32_t id = 1; + return id; +} + +uint32_t WMNativeTest::GetLastTime() const +{ + constexpr uint32_t lastTime = LAST_TIME_FOREVER; + return lastTime; +} + +void WMNativeTest::Run(int32_t argc, const char **argv) +{ + int displayId = 0; + sptr listener = nullptr; + sptr scene = new WindowScene(); + std::shared_ptr abilityContext = nullptr; + WMError rtn = scene->Init(displayId, abilityContext, listener); + if (rtn != OHOS::Rosen::WMError::WM_OK) { + return; + } + + while(true) { + scene->GoForeground(); + sleep(3); + scene->GoBackground(); + sleep(3); + } +} diff --git a/wmtest/test/wm_native_test.h b/wmtest/test/wm_native_test.h new file mode 100644 index 0000000000000000000000000000000000000000..6b978531e61e97fe9439108df2bfff38ef33b6fa --- /dev/null +++ b/wmtest/test/wm_native_test.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) 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 OHOS_ROSEN_WM_NATIVE_TEST_H +#define OHOS_ROSEN_WM_NATIVE_TEST_H + +#include "inative_test.h" + +namespace OHOS::Rosen { +class WMNativeTest : public INativeTest { +public: + virtual ~WMNativeTest() = default; + virtual std::string GetDescription() const override; + virtual std::string GetDomain() const override; + virtual int32_t GetID() const override; + virtual uint32_t GetLastTime() const override; + + virtual void Run(int32_t argc, const char **argv) override; + +private: + void PostTask(std::function func, uint32_t delayTime = 0); + void ExitTest(); + int64_t GetNowTime(); +}; +} + +#endif // OHOS_ROSEN_WM_NATIVE_TEST_H diff --git a/wmtest/unittest/BUILD.gn b/wmtest/unittest/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..b034b6997bc91a51f29533ee592ca0d4d068bec2 --- /dev/null +++ b/wmtest/unittest/BUILD.gn @@ -0,0 +1,85 @@ +# Copyright (c) 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/test.gni") +module_out_path = "window_manager/" + +group("unittest") { + testonly = true + + deps = [ ":ut_window_impl_test" ] +} + +## UnitTest ut_window_impl_test {{{ +ohos_unittest("ut_window_impl_test") { + module_out_path = module_out_path + + sources = [ "src/window_impl_test.cpp" ] + + deps = [ ":unittest_wmtest_common" ] +} + +## UnitTest ut_window_impl_test }}} + +## Build unittest_wmtest_common.a {{{ +config("unittest_wmtest_common_public_config") { + include_dirs = [ + "//foundation/windowmanager/wm/include", + "//foundation/windowmanager/wmserver/include", + "include", + "//foundation/windowmanager/interfaces/innerkits/wm", + "//utils/native/base/include", + "//foundation/communication/ipc/interfaces/innerkits/ipc_core/include", + "//base/hiviewdfx/hilog/interfaces/native/innerkits/include", + "//foundation/windowmanager/utils/include", + "//third_party/googletest/googlemock/include", + + #RSSurface + "//foundation/graphic/standard/rosen/modules/render_service_client/core", + "//foundation/graphic/standard/rosen/modules/render_service_base/include", + "//third_party/flutter/skia", + ] + + cflags = [ + "-Wall", + "-Werror", + "-g3", + "-Dprivate=public", + "-Dprotected=public", + ] +} + +ohos_static_library("unittest_wmtest_common") { + visibility = [ ":*" ] + testonly = true + + public_configs = [ ":unittest_wmtest_common_public_config" ] + + deps = [ + "//foundation/windowmanager/wm:libwm", + "//foundation/windowmanager/wm:libwmutil", + "//foundation/windowmanager/wmserver:libwms", + "//third_party/googletest:gmock", + "//utils/native/base:utils", + + # RSSurface + "//foundation/graphic/standard/rosen/modules/render_service_base:librender_service_base", + "//foundation/graphic/standard/rosen/modules/render_service_client:librender_service_client", + ] + + external_deps = [ + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + ] +} +## Build unittest_wmtest_common.a }}} diff --git a/wmtest/unittest/include/mock/mock_window_adapter.h b/wmtest/unittest/include/mock/mock_window_adapter.h new file mode 100644 index 0000000000000000000000000000000000000000..b839fe7819aaf26e4c336c843348d0d0f7e04fa1 --- /dev/null +++ b/wmtest/unittest/include/mock/mock_window_adapter.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 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 UNITTEST_MOCK_WINDOW_ADAPTER_H +#define UNITTEST_MOCK_WINDOW_ADAPTER_H + +#include + +#include "window_adapter.h" + +namespace OHOS { +namespace Rosen { +class MockWindowAdapter : public WindowAdapter { +public: + MOCK_METHOD1(AddWindow, WMError(sptr& windowProperty)); + MOCK_METHOD1(RemoveWindow, WMError(uint32_t windowId)); + MOCK_METHOD0(ClearWindowAdapter, void()); +}; +} +} // namespace OHOS + + +#endif \ No newline at end of file diff --git a/wmtest/unittest/include/mock/singleton_mocker.h b/wmtest/unittest/include/mock/singleton_mocker.h new file mode 100644 index 0000000000000000000000000000000000000000..c3bce98c20d39c139086e188f4a34f2a898642b4 --- /dev/null +++ b/wmtest/unittest/include/mock/singleton_mocker.h @@ -0,0 +1,54 @@ +/* + * Copyright (c) 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 UNITTEST_MOCK_SINGLETON_MOCKER_H +#define UNITTEST_MOCK_SINGLETON_MOCKER_H + +#include "singleton_container.h" +namespace OHOS { +namespace Rosen { +template +class SingletonMocker { +public: + SingletonMocker() + { + origin = SingletonContainer::Get(); + mock = new MockT(); + SingletonContainer::Set(mock); + } + + ~SingletonMocker() + { + SingletonContainer::Set(origin); + } + + sptr Origin() + { + return origin; + } + + sptr Mock() + { + return mock; + } + +private: + sptr origin = nullptr; + sptr mock = nullptr; +}; +} // namespace Rosen +} // namespace OHOS + +#endif // FRAMEWORKS_WM_TEST_UNITTEST_MOCK_SINGLETON_MOCKER_H diff --git a/wmtest/unittest/include/test_header.h b/wmtest/unittest/include/test_header.h new file mode 100644 index 0000000000000000000000000000000000000000..31f8bfbd0a59fd5fdf44a9a54089d8261be2bebf --- /dev/null +++ b/wmtest/unittest/include/test_header.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 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 UNITTEST_TEST_HEADER_H +#define UNITTEST_TEST_HEADER_H + +#include "window_manager_hilog.h" + +namespace OHOS { +namespace Rosen { +#define _WMT_CPRINTF(color, func, fmt, ...) \ + func({LOG_CORE, 0, "WM_UINTTEST"}, "\033[" #color "m" "<%{public}d>" fmt "\033[0m", __LINE__, ##__VA_ARGS__) +#define WMTLOGI(color, fmt, ...) \ + _WMT_CPRINTF(color, HiviewDFX::HiLog::Info, "%{public}s: " fmt, __func__, ##__VA_ARGS__) + +#define PART(part) WMTLOGI(33, part); if (const char *strPart = part) +#define STEP(desc) WMTLOGI(34, desc); if (const char *strDesc = desc) + +#define STEP_CONDITION(condition) strPart << ": " << strDesc << " (" << condition << ")" + +#define STEP_ASSERT_(l, r, func, opstr) ASSERT_##func(l, r) << STEP_CONDITION(#l " " opstr " " #r) + +#define STEP_ASSERT_EQ(l, r) STEP_ASSERT_(l, r, EQ, "==") +#define STEP_ASSERT_NE(l, r) STEP_ASSERT_(l, r, NE, "!=") +#define STEP_ASSERT_GE(l, r) STEP_ASSERT_(l, r, GE, ">=") +#define STEP_ASSERT_LE(l, r) STEP_ASSERT_(l, r, LE, "<=") +#define STEP_ASSERT_GT(l, r) STEP_ASSERT_(l, r, GT, ">") +#define STEP_ASSERT_LT(l, r) STEP_ASSERT_(l, r, LT, "<") +} // namespace Rosen +} // namespace OHOS +#endif // UNITTEST_TEST_HEADER_H diff --git a/wmtest/unittest/include/window_impl_test.h b/wmtest/unittest/include/window_impl_test.h new file mode 100644 index 0000000000000000000000000000000000000000..f9adbf5f59346c947c91e6f8f8e5d22bce2d3e22 --- /dev/null +++ b/wmtest/unittest/include/window_impl_test.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 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 UNITTEST_WINDOW_IMPL_TEST_H +#define UNITTEST_WINDOW_IMPL_TEST_H + +#include +#include "window_impl.h" + +namespace OHOS { +namespace Rosen { +class WindowImplTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + virtual void SetUp() override; + virtual void TearDown() override; + + static inline sptr window_ = nullptr; + static inline sptr property_ = nullptr; +}; +} // namespace ROSEN +} // namespace OHOS + +#endif // FRAMEWORKS_WM_TEST_UNITTEST_WINDOW_IMPL_TEST_H \ No newline at end of file diff --git a/wmtest/unittest/src/window_impl_test.cpp b/wmtest/unittest/src/window_impl_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..52d585fb806edd253582ec27f523951449f9c56d --- /dev/null +++ b/wmtest/unittest/src/window_impl_test.cpp @@ -0,0 +1,47 @@ +/* + * Copyright (c) 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 "window_impl_test.h" +#include "mock/mock_window_adapter.h" +#include "mock/singleton_mocker.h" +#include "test_header.h" +#include "window_property.h" + + +namespace OHOS { +namespace Rosen { +using namespace testing; + +void WindowImplTest::SetUpTestCase() +{ + property_ = sptr(new WindowProperty()); + property_->SetWindowId(0); + window_ = sptr(new WindowImpl(property_)); +} + +void WindowImplTest::TearDownTestCase() +{ +} + +void WindowImplTest::SetUp() +{ +} + +void WindowImplTest::TearDown() +{ +} + +} // namespace Rosen +} // namespace OHOS diff --git a/wmtest/utils/include/single_instance.h b/wmtest/utils/include/single_instance.h new file mode 100644 index 0000000000000000000000000000000000000000..b255caf73d94d65f85c9e98eaad4207333caa372 --- /dev/null +++ b/wmtest/utils/include/single_instance.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 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 OHOS_SINGLE_INSTANCE_H +#define OHOS_SINGLE_INSTANCE_H +namespace OHOS { +namespace Rosen { +#define DECLARE_SINGLE_INSTANCE_BASE(className) \ +public: \ + static sptr GetInstance(); \ +private: \ + className(const className&) = delete; \ + className& operator= (const className&) = delete; \ + className(className&&) = delete; \ + className& operator= (className&&) = delete; \ + + +#define DECLARE_SINGLE_INSTANCE(className) \ + DECLARE_SINGLE_INSTANCE_BASE(className) \ +private: \ + className() = default; \ + ~className() = default; \ + +#define IMPLEMENT_SINGLE_INSTANCE(className) \ +sptr className::GetInstance() \ +{ \ + static sptr instance = new className(); \ + return instance; \ +} +} // namespace OHOS +} +#endif // OHOS_SINGLE_INSTANCE_H diff --git a/wmtest/utils/include/singleton_container.h b/wmtest/utils/include/singleton_container.h new file mode 100644 index 0000000000000000000000000000000000000000..68d6d7e8ec60101761646726b6f38ec9af720958 --- /dev/null +++ b/wmtest/utils/include/singleton_container.h @@ -0,0 +1,81 @@ +/* + * Copyright (c) 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 OHOS_SINGLETON_CONTAINER_H +#define OHOS_SINGLETON_CONTAINER_H + +#include +#include +#include +#include +#include + +#include + +namespace OHOS { +namespace Rosen { +class SingletonContainer : public RefBase { +public: + static sptr GetInstance(); + + void AddSingleton(const std::string &name, const std::any &instance); + void SetSingleton(const std::string &name, const std::any &instance); + const std::any &GetSingleton(const std::string &name); + const std::any &DependOn(const std::string &instance, const std::string &name); + + template + static sptr Get() + { + std::string nameT = __PRETTY_FUNCTION__; + nameT = nameT.substr(nameT.find("T = ")); + nameT = nameT.substr(sizeof("T ="), nameT.length() - sizeof("T = ")); + + using sptrT = sptr; + sptrT ret = nullptr; + const std::any &instance = SingletonContainer::GetInstance()->GetSingleton(nameT); + auto pRet = std::any_cast(&instance); + if (pRet != nullptr) { + ret = *pRet; + } + return ret; + } + + template + static void Set(const sptr &ptr) + { + std::string nameT = __PRETTY_FUNCTION__; + nameT = nameT.substr(nameT.find("T = ")); + nameT = nameT.substr(sizeof("T ="), nameT.length() - sizeof("T = ")); + + SingletonContainer::GetInstance()->SetSingleton(nameT, ptr); + } + +private: + SingletonContainer() = default; + virtual ~SingletonContainer() override; + static inline sptr instance = nullptr; + + struct Singleton { + std::any value; + int32_t refCount; + }; + std::map stringMap; + std::map singletonMap; + std::map> dependencySetMap; +}; +} // namespace Rosen +} // namespace OHOS + +#endif // FRAMEWORKS_WM_INCLUDE_SINGLETON_CONTAINER_H diff --git a/wmtest/utils/include/singleton_delegator.h b/wmtest/utils/include/singleton_delegator.h new file mode 100644 index 0000000000000000000000000000000000000000..dae000468f0385e443135a54846f1c6d05feefe9 --- /dev/null +++ b/wmtest/utils/include/singleton_delegator.h @@ -0,0 +1,57 @@ +/* + * Copyright (c) 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 OHOS_SINGLETON_DELEGATOR_H +#define OHOS_SINGLETON_DELEGATOR_H + +#include "singleton_container.h" + +#define MOCKABLE virtual + +namespace OHOS { +namespace Rosen { +template +class SingletonDelegator { +public: + SingletonDelegator() + { + nameT = __PRETTY_FUNCTION__; + nameT = nameT.substr(nameT.find("T = ")); + nameT = nameT.substr(sizeof("T ="), nameT.length() - sizeof("T = ")); + SingletonContainer::GetInstance()->AddSingleton(nameT, T::GetInstance()); + } + ~SingletonDelegator() = default; + + template + sptr Dep() + { + std::string nameS = __PRETTY_FUNCTION__; + nameS = nameS.substr(nameS.find("S = ")); + nameS = nameS.substr(sizeof("S ="), nameS.length() - sizeof("S = ")); + + auto ret = SingletonContainer::Get(); + if (ret != nullptr) { + SingletonContainer::GetInstance()->DependOn(nameT, nameS); + } + return ret; + } + +private: + std::string nameT; +}; +} // namespace Rosen +} // namespace OHOS + +#endif // FRAMEWORKS_WM_INCLUDE_SINGLETON_DELEGATOR_H diff --git a/wmtest/utils/include/static_call.h b/wmtest/utils/include/static_call.h new file mode 100644 index 0000000000000000000000000000000000000000..e505d2b7aba755d5649597ec593f175261555217 --- /dev/null +++ b/wmtest/utils/include/static_call.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) 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 OHOS_STATIC_CALL_H +#define OHOS_STATIC_CALL_H + +#include +#include "singleton_delegator.h" +#include "single_instance.h" +#include "window.h" +#include "window_option.h" +namespace OHOS { +namespace Rosen { +class StaticCall : public RefBase { + DECLARE_SINGLE_INSTANCE_BASE(StaticCall); +public: + virtual sptr CreateWindow(const std::string& windowName, + sptr& option, const sptr& abilityToken = nullptr); +protected: + StaticCall() = default; +private: + static inline SingletonDelegator delegator_; +}; +} // namespace ROSEN +} // namespace OHOS + +#endif // FRAMEWORKS_WM_TEST_UT_STATIC_CALL_H \ No newline at end of file diff --git a/wmtest/utils/include/window_manager_hilog.h b/wmtest/utils/include/window_manager_hilog.h new file mode 100644 index 0000000000000000000000000000000000000000..bf790ce8880a48f8f70b000ba8e26d293381a71a --- /dev/null +++ b/wmtest/utils/include/window_manager_hilog.h @@ -0,0 +1,50 @@ +/* + * Copyright (c) 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 OHOS_WM_INCLUDE_WINDOW_MANAGER_HILOG_H +#define OHOS_WM_INCLUDE_WINDOW_MANAGER_HILOG_H + +#include "hilog/log.h" +namespace OHOS { +namespace Rosen { +static constexpr OHOS::HiviewDFX::HiLogLabel LOG_LABEL = {LOG_CORE, 0, "WindowManager"}; + +#define WLOG_F(...) (void)OHOS::HiviewDFX::HiLog::Fatal(LOG_LABEL, __VA_ARGS__) +#define WLOG_E(...) (void)OHOS::HiviewDFX::HiLog::Error(LOG_LABEL, __VA_ARGS__) +#define WLOG_W(...) (void)OHOS::HiviewDFX::HiLog::Warn(LOG_LABEL, __VA_ARGS__) +#define WLOG_I(...) (void)OHOS::HiviewDFX::HiLog::Info(LOG_LABEL, __VA_ARGS__) +#define WLOG_D(...) (void)OHOS::HiviewDFX::HiLog::Debug(LOG_LABEL, __VA_ARGS__) + +#define _W_DFUNC HiviewDFX::HiLog::Debug +#define _W_IFUNC HiviewDFX::HiLog::Info +#define _W_WFUNC HiviewDFX::HiLog::Warn +#define _W_EFUNC HiviewDFX::HiLog::Error + +#define _W_CPRINTF(func, fmt, ...) func(LABEL, "<%{public}d>" fmt, __LINE__, ##__VA_ARGS__) + +#define WLOGD(fmt, ...) _W_CPRINTF(_W_DFUNC, fmt, ##__VA_ARGS__) +#define WLOGI(fmt, ...) _W_CPRINTF(_W_IFUNC, fmt, ##__VA_ARGS__) +#define WLOGW(fmt, ...) _W_CPRINTF(_W_WFUNC, fmt, ##__VA_ARGS__) +#define WLOGE(fmt, ...) _W_CPRINTF(_W_EFUNC, fmt, ##__VA_ARGS__) + +#define _W_FUNC __func__ + +#define WLOGFD(fmt, ...) WLOGD("%{public}s: " fmt, _W_FUNC, ##__VA_ARGS__) +#define WLOGFI(fmt, ...) WLOGI("%{public}s: " fmt, _W_FUNC, ##__VA_ARGS__) +#define WLOGFW(fmt, ...) WLOGW("%{public}s: " fmt, _W_FUNC, ##__VA_ARGS__) +#define WLOGFE(fmt, ...) WLOGE("%{public}s: " fmt, _W_FUNC, ##__VA_ARGS__) +} // namespace OHOS +} +#endif // FRAMEWORKS_WM_INCLUDE_WINDOW_MANAGER_HILOG_H diff --git a/wmtest/utils/src/singleton_container.cpp b/wmtest/utils/src/singleton_container.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0b851fdae250c59a4b7fc65bf13f346d042c7bb7 --- /dev/null +++ b/wmtest/utils/src/singleton_container.cpp @@ -0,0 +1,110 @@ +/* + * Copyright (c) 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 "singleton_container.h" +#include +#include "window_manager_hilog.h" + +namespace OHOS { +namespace Rosen { +namespace { +constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "WindowManager_SingletonContainer"}; +} // namespace + +sptr SingletonContainer::GetInstance() +{ + if (instance == nullptr) { + static std::mutex mutex; + std::lock_guard lock(mutex); + if (instance == nullptr) { + instance = new SingletonContainer(); + } + } + return instance; +} + +SingletonContainer::~SingletonContainer() +{ + while (singletonMap.empty() == false) { + auto it = singletonMap.begin(); + while (it != singletonMap.end()) { + if (it->second.refCount > 0) { + it++; + continue; + } + + if (dependencySetMap.find(it->first) != dependencySetMap.end()) { + for (auto mid : dependencySetMap[it->first]) { + singletonMap[mid].refCount--; + } + dependencySetMap.erase(it->first); + } + + for (const auto &[k, v] : stringMap) { + if (v == it->first) { + WLOGFD("remove %{public}s", k.c_str()); + break; + } + } + singletonMap.erase(it++); + } + } +} + +void SingletonContainer::AddSingleton(const std::string &name, const std::any &instance) +{ + if (stringMap.find(name) == stringMap.end()) { + static int32_t nextId = 0; + singletonMap[nextId].value = instance; + singletonMap[nextId].refCount = 0; + WLOGFD("add %{public}s", name.c_str()); + stringMap[name] = nextId++; + } else { + WLOGFE("add failed: %{public}s", name.c_str()); + } +} + +void SingletonContainer::SetSingleton(const std::string &name, const std::any &instance) +{ + if (stringMap.find(name) == stringMap.end()) { + AddSingleton(name, instance); + } else { + WLOGFD("set %{public}s", name.c_str()); + singletonMap[stringMap[name]].value = instance; + } +} + +const std::any &SingletonContainer::GetSingleton(const std::string &name) +{ + if (stringMap.find(name) == stringMap.end()) { + WLOGFD("cannot get %{public}s", name.c_str()); + static std::any voidAny; + return voidAny; + } + return singletonMap[stringMap[name]].value; +} + +const std::any &SingletonContainer::DependOn(const std::string &instance, const std::string &name) +{ + auto &instanceDependencySet = dependencySetMap[stringMap[instance]]; + if (instanceDependencySet.find(stringMap[name]) == instanceDependencySet.end()) { + WLOGFD("%{public}s dependon %{public}s", instance.c_str(), name.c_str()); + instanceDependencySet.insert(stringMap[name]); + singletonMap[stringMap[name]].refCount++; + } + return GetSingleton(name); +} +} // namespace Rosen +} // namespace OHOS diff --git a/wmtest/utils/src/static_call.cpp b/wmtest/utils/src/static_call.cpp new file mode 100644 index 0000000000000000000000000000000000000000..5b8797a3b166161f559f06339418113c8469df98 --- /dev/null +++ b/wmtest/utils/src/static_call.cpp @@ -0,0 +1,28 @@ +/* + * Copyright (c) 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 "static_call.h" + +namespace OHOS { +namespace Rosen { +IMPLEMENT_SINGLE_INSTANCE(StaticCall); + +sptr StaticCall::CreateWindow(const std::string& windowName, + sptr& option, const sptr& abilityToken) +{ + return Window::Create(windowName, option, abilityToken); +} +} // namespace Rosen +} // namespace OHOS \ No newline at end of file diff --git a/wmtest/wm/BUILD.gn b/wmtest/wm/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..a517968506f142873b301717c63dbc94d2715c82 --- /dev/null +++ b/wmtest/wm/BUILD.gn @@ -0,0 +1,161 @@ +# Copyright (c) 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/ohos.gni") + +config("libwm_config") { + visibility = [ ":*" ] + + include_dirs = [ + "include", + "//utils/system/safwk/native/include", + "//foundation/windowmanager/wmserver/include", + "//foundation/windowmanager/dm/include", + "//foundation/windowmanager/dmserver/include", + "//foundation/windowmanager/utils/include", + + # for abilityContext + "//foundation/aafwk/standard/frameworks/kits/ability/ability_runtime/include", + "//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_base/include", + "//base/global/resmgr_standard/interfaces/innerkits/include", + "//third_party/node/deps/icu-small/source/common", + "//foundation/aafwk/standard/interfaces/innerkits/ability_manager/include", + "//foundation/aafwk/standard/interfaces/innerkits/want/include/ohos/aafwk/content", + "//foundation/distributedschedule/dmsfwk/services/dtbschedmgr/include", + "//foundation/aafwk/standard/interfaces/innerkits/base/include", + + # abilityContext end + + # weston adapter + "//foundation/windowmanager/adapter/include", + "//foundation/graphic/standard/interfaces/innerkits", + "//foundation/graphic/standard/interfaces/innerkits/wm", + "//foundation/graphic/standard/interfaces/innerkits/common", + + # weston adapter end + ] + + cflags = [ + "-Wall", + "-Werror", + "-g3", + ] +} + +config("libwm_public_config") { + include_dirs = [ + "//foundation/windowmanager/interfaces/innerkits/wm", + "//foundation/windowmanager/wmserver/include", + "//foundation/windowmanager/dmserver/include", + "//foundation/windowmanager/utils/include", + "../interfaces/innerkits/dm", + ] +} + +## Build libwmutil.so +ohos_shared_library("libwmutil") { + sources = [ + "../dmserver/src/display_info.cpp", + "//foundation/windowmanager/dmserver/src/display_manager_proxy.cpp", + "//foundation/windowmanager/utils/src/singleton_container.cpp", + "//foundation/windowmanager/wm/src/window_proxy.cpp", + "//foundation/windowmanager/wmserver/src/window_manager_proxy.cpp", + "src/window_option.cpp", + "src/window_property.cpp", + ] + + configs = [ ":libwm_config" ] + + public_configs = [ ":libwm_public_config" ] + + deps = [ + "//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog", + "//utils/native/base:utils", + ] + + public_deps = [ + # RSSurface + "//foundation/graphic/standard/rosen/modules/render_service_base:librender_service_base", + "//foundation/graphic/standard/rosen/modules/render_service_client:librender_service_client", + ] + + external_deps = [ "ipc:ipc_core" ] + + part_name = "window_manager" + subsystem_name = "window" +} + +## Build libwm.so +ohos_shared_library("libwm") { + sources = [ + "../dm/src/display.cpp", + "../dm/src/display_manager.cpp", + "../dm/src/display_manager_adapter.cpp", + "../dm/src/monitor.cpp", + "../utils/src/static_call.cpp", + "src/input_transfer_station.cpp", + "src/vsync_station.cpp", + "src/window.cpp", + "src/window_adapter.cpp", + "src/window_agent.cpp", + "src/window_impl.cpp", + "src/window_input_channel.cpp", + "src/window_scene.cpp", + "src/window_stub.cpp", + ] + + configs = [ ":libwm_config" ] + + public_configs = [ ":libwm_public_config" ] + + deps = [ + "//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog", + "//foundation/aafwk/standard/interfaces/innerkits/want:want", + "//foundation/distributedschedule/safwk/interfaces/innerkits/safwk:system_ability_fwk", + "//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", + "//foundation/windowmanager/wm:libwmutil", + "//utils/native/base:utils", + + # weston adapter + "//foundation/windowmanager/adapter:libwmadaptertest", + + # ace + "//foundation/ace/ace_engine/interfaces/innerkits/ace:ace_uicontent", + ] + + public_deps = [ + # native value + # RSSurface + "//foundation/ace/napi:ace_napi", + + # vsync + "//foundation/graphic/standard:libvsync_client", + "//foundation/graphic/standard/rosen/modules/render_service_base:librender_service_base", + "//foundation/graphic/standard/rosen/modules/render_service_client:librender_service_client", + + # IMS + "//foundation/multimodalinput/input/frameworks/proxy:libmmi-client", + "//foundation/multimodalinput/input/frameworks/proxy:libmmi-common", + + # weston adapter + "//foundation/windowmanager/adapter:libwmadaptertest", + ] + + external_deps = [ + "aafwk_standard:ability_context_native", + "ipc:ipc_core", + ] + + part_name = "window_manager" + subsystem_name = "window" +} diff --git a/wmtest/wm/include/README.md b/wmtest/wm/include/README.md new file mode 100644 index 0000000000000000000000000000000000000000..f0321dc5d0e30b1a50abc177befda0f70cb81358 --- /dev/null +++ b/wmtest/wm/include/README.md @@ -0,0 +1 @@ +Store code of window client inner header files diff --git a/wmtest/wm/include/input_transfer_station.h b/wmtest/wm/include/input_transfer_station.h new file mode 100644 index 0000000000000000000000000000000000000000..5c8fa1466fa3733fda488952225800566cc4b2ad --- /dev/null +++ b/wmtest/wm/include/input_transfer_station.h @@ -0,0 +1,55 @@ +/* + * Copyright (c) 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 OHOS_INPUT_TRANSFER_STATION +#define OHOS_INPUT_TRANSFER_STATION + + +#include +#include +#include "input_manager.h" +#include "pointer_event.h" +#include "window.h" +#include "window_input_channel.h" +#include "vsync_station.h" + +namespace OHOS { +namespace Rosen { +class InputEventListener; +class InputTransferStation : public RefBase { +DECLARE_SINGLE_INSTANCE(InputTransferStation); +friend class InputEventListener; +public: + void AddInputWindow(const sptr& window); + void RemoveInputWindow(const sptr& window); + void SetInputListener(uint32_t windowId, std::shared_ptr& listener); +private: + sptr GetInputChannel(uint32_t windowId); + bool initInputListener_ = false; + std::unordered_map> windowInputChannels_; + std::shared_ptr inputListener_; +}; +class InputEventListener: public RefBase, public MMI::IInputEventConsumer { +public: + InputEventListener() = default; + void OnInputEvent(std::shared_ptr pointerEvent) const override; + void OnInputEvent(std::shared_ptr keyEvent) const override; + void OnInputEvent(std::shared_ptr axisEvent) const override; +}; +} +} + + +#endif // OHOS_INPUT_TRANSFER_STATION diff --git a/wmtest/wm/include/vsync_station.h b/wmtest/wm/include/vsync_station.h new file mode 100644 index 0000000000000000000000000000000000000000..eba3a26caf4b038270233b5aa7cc8e1d0c927d5a --- /dev/null +++ b/wmtest/wm/include/vsync_station.h @@ -0,0 +1,59 @@ +/* + * Copyright (c) 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 OHOS_VSYNC_STATION_H +#define OHOS_VSYNC_STATION_H + +#include +#include +#include +#include +#include + +#include +#include + +#include "single_instance.h" + +namespace OHOS { +namespace Rosen { +class VsyncStation : public RefBase { +DECLARE_SINGLE_INSTANCE_BASE(VsyncStation); +using OnCallback = std::function; +public: + enum class CallbackType { + CALLBACK_INPUT = 0, + CALLBACK_FRAME = 1, + }; + struct VsyncCallback { + OnCallback onCallback; + }; + ~VsyncStation() = default; + void RequestVsync(CallbackType type, std::shared_ptr vsyncCallback); + +private: + FrameCallback callback_; + VsyncStation() = default; + static void OnVsync(int64_t nanoTimestamp, void* client); + void VsyncCallbackInner(int64_t nanoTimestamp); + std::atomic_bool hasRequestedVsync_ {false}; + std::map>> vsyncCallbacks_ = { + {CallbackType::CALLBACK_INPUT, {}}, + {CallbackType::CALLBACK_FRAME, {}}, + }; +}; +} // namespace Rosen +} // namespace OHOS +#endif // OHOS_VSYNC_STATION_H \ No newline at end of file diff --git a/wmtest/wm/include/window_adapter.h b/wmtest/wm/include/window_adapter.h new file mode 100644 index 0000000000000000000000000000000000000000..49ca563360fb9356485d8b259b79331d7fae6dbc --- /dev/null +++ b/wmtest/wm/include/window_adapter.h @@ -0,0 +1,61 @@ +/* + * Copyright (c) 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 OHOS_WINDOW_ADAPTER_H +#define OHOS_WINDOW_ADAPTER_H + +#include + +#include "window.h" +#include "window_proxy.h" +#include "single_instance.h" +#include "singleton_delegator.h" +#include "window_property.h" +#include "window_manager_interface.h" +namespace OHOS { +namespace Rosen { +class WMSDeathRecipient : public IRemoteObject::DeathRecipient { +public: + virtual void OnRemoteDied(const wptr& wptrDeath) override; +}; + +class WindowAdapter : public RefBase { + DECLARE_SINGLE_INSTANCE_BASE(WindowAdapter); +public: + ~WindowAdapter() = default; + virtual WMError CreateWindow(sptr& window, sptr& windowProperty, + std::shared_ptr surfaceNode, uint32_t& windowId); + virtual WMError AddWindow(sptr& windowProperty); + virtual WMError RemoveWindow(uint32_t windowId); + virtual WMError DestroyWindow(uint32_t windowId); + virtual WMError SaveAbilityToken(const sptr& abilityToken, uint32_t windowId); + virtual WMError MoveTo(uint32_t windowId, int32_t x, int32_t y); + virtual WMError Resize(uint32_t windowId, uint32_t width, uint32_t height); + virtual WMError RequestFocus(uint32_t windowId); + + virtual void ClearWindowAdapter(); +protected: + WindowAdapter() = default; +private: + static inline SingletonDelegator delegator; + bool InitWMSProxyLocked(); + + std::mutex mutex_; + sptr windowManagerServiceProxy_ = nullptr; + sptr wmsDeath_ = nullptr; +}; +} // namespace Rosen +} // namespace OHOS +#endif // OHOS_WINDOW_ADAPTER_H diff --git a/wmtest/wm/include/window_agent.h b/wmtest/wm/include/window_agent.h new file mode 100644 index 0000000000000000000000000000000000000000..31bd1ccd4b41deea54d6d0291044660fdbdbe808 --- /dev/null +++ b/wmtest/wm/include/window_agent.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) 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 OHOS_WINDOW_AGENT_H +#define OHOS_WINDOW_AGENT_H + +#include "window_stub.h" +#include "window_impl.h" +#include "window_property.h" + +namespace OHOS { +namespace Rosen { +class WindowAgent : public WindowStub { +public: + WindowAgent(sptr& window); + ~WindowAgent() = default; + void UpdateWindowProperty(const WindowProperty& windowProperty) override; + void UpdateWindowRect(const struct Rect& rect) override; + void UpdateWindowMode(WindowMode mode) override; + void UpdateFocusStatus(bool focused) override; + +private: + sptr window_; +}; +} // namespace Rosen +} // namespace OHOS +#endif // OHOS_WINDOW_AGENT_H diff --git a/wmtest/wm/include/window_impl.h b/wmtest/wm/include/window_impl.h new file mode 100644 index 0000000000000000000000000000000000000000..17766e3f105bbffe6812bcd7dc21c28405f31e0b --- /dev/null +++ b/wmtest/wm/include/window_impl.h @@ -0,0 +1,122 @@ +/* + * Copyright (c) 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 OHOS_ROSEN_WINDOW_IMPL_H +#define OHOS_ROSEN_WINDOW_IMPL_H +#include +#include +#include +#include +#include "window.h" +#include "input_transfer_station.h" +#include "window_property.h" + +namespace OHOS { +namespace Rosen { +class WindowImpl : public Window { +#define CALL_LIFECYCLE_LISTENER(windowLifecycleCb, uiContentCb) \ + do { \ + if (lifecycleListener_ != nullptr) { \ + lifecycleListener_->windowLifecycleCb(); \ + } \ + if (uiContent_ != nullptr) { \ + uiContent_->uiContentCb(); \ + } \ + } while (0); + +public: + WindowImpl(const sptr& option); + ~WindowImpl(); + + static sptr Find(const std::string& id); + + virtual std::shared_ptr GetSurfaceNode() const override; + virtual Rect GetRect() const override; + virtual WindowType GetType() const override; + virtual WindowMode GetMode() const override; + virtual const std::string& GetWindowName() const override; + virtual uint32_t GetWindowId() override; + virtual WMError SetWindowType(WindowType type) override; + virtual WMError SetWindowMode(WindowMode mode) override; + + WMError Create(const std::string& parentName, const sptr& abilityToken = nullptr); + virtual WMError Destroy() override; + virtual WMError Show() override; + virtual WMError Hide() override; + virtual WMError MoveTo(int32_t x, int32_t y) override; + virtual WMError Resize(uint32_t width, uint32_t height) override; + + virtual WMError RequestFocus() const override; + virtual void AddInputEventListener(std::shared_ptr& inputEventListener) override; + + virtual void RegisterLifeCycleListener(sptr& listener) override; + virtual void RegisterWindowChangeListener(sptr& listener) override; + + void UpdateRect(const struct Rect& rect); + void UpdateMode(WindowMode mode); + virtual void ConsumeKeyEvent(std::shared_ptr& inputEvent) override; + virtual void ConsumePointerEvent(std::shared_ptr& inputEvent) override; + void UpdateFocusStatus(bool focused); + + virtual WMError SetUIContent(std::shared_ptr context, + std::string& url, NativeEngine* engine, NativeValue* storage) override; + +private: + inline void NotifyAfterForeground() const + { + CALL_LIFECYCLE_LISTENER(AfterForeground, Foreground); + } + inline void NotifyAfterBackground() const + { + CALL_LIFECYCLE_LISTENER(AfterBackground, Background); + } + inline void NotifyAfterFocused() const + { + CALL_LIFECYCLE_LISTENER(AfterFocused, Focus); + } + inline void NotifyAfterUnFocused() const + { + CALL_LIFECYCLE_LISTENER(AfterUnFocused, UnFocus); + } + inline void NotifyBeforeDestroy() const + { + if (uiContent_ != nullptr) { + uiContent_->Destroy(); + } + } + void SetDefaultOption(); // for api7 + bool IsWindowValid() const; + + enum WindowState { + STATE_INITIAL, + STATE_CREATED, + STATE_SHOWN, + STATE_HIDDEN, + STATE_DESTROYED, + STATE_BOTTOM = STATE_DESTROYED, + }; + + static std::map>> windowMap_; + sptr property_; + WindowState state_ { STATE_INITIAL }; + sptr lifecycleListener_; + sptr windowChangeListener_; + std::shared_ptr surfaceNode_; + std::string name_; + std::unique_ptr uiContent_; +}; +} +} +#endif // OHOS_ROSEN_WINDOW_IMPL_H diff --git a/wmtest/wm/include/window_input_channel.h b/wmtest/wm/include/window_input_channel.h new file mode 100644 index 0000000000000000000000000000000000000000..fb700a1d5464032c5d913eb3d82783ce53f580fe --- /dev/null +++ b/wmtest/wm/include/window_input_channel.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 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 +#include "refbase.h" +#include "vsync_station.h" +#ifndef OHOS_WINDOW_INPUT_CHANNEL +#define OHOS_WINDOW_INPUT_CHANNEL + +namespace OHOS { +namespace Rosen { +class WindowInputChannel : public RefBase { +public: + WindowInputChannel(const sptr& window); + ~WindowInputChannel() = default; + void HandlePointerEvent(std::shared_ptr& pointerEvent); + void HandleKeyEvent(std::shared_ptr& keyEvent); + void SetInputListener(std::shared_ptr& listener); +private: + void OnVsync(int64_t timeStamp); + std::vector> pointerEventPool_; + sptr window_; + std::shared_ptr callback_ = + std::make_shared(VsyncStation::VsyncCallback()); + static const int32_t MAX_INPUT_NUM = 100; + std::shared_ptr inputListener_; +}; +} +} + + +#endif // OHOS_WINDOW_INPUT_CHANNEL diff --git a/wmtest/wm/include/window_interface.h b/wmtest/wm/include/window_interface.h new file mode 100644 index 0000000000000000000000000000000000000000..846ded865285ddb6bf00841e5411b64335fd3911 --- /dev/null +++ b/wmtest/wm/include/window_interface.h @@ -0,0 +1,42 @@ +/* + * Copyright (c) 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 OHOS_WINDOW_INTERFACE_H +#define OHOS_WINDOW_INTERFACE_H + +#include "iremote_broker.h" +#include "window_property.h" + +namespace OHOS { +namespace Rosen { +class IWindow : public IRemoteBroker { +public: + DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.IWindow"); + + enum { + TRANS_ID_UPDATE_WINDOW_PROPERTY = 1, + TRANS_ID_UPDATE_WINDOW_RECT, + TRANS_ID_UPDATE_WINDOW_MODE, + TRANS_ID_UPDATE_FOCUS_STATUS, + }; + + virtual void UpdateWindowProperty(const WindowProperty& windowProperty) = 0; + virtual void UpdateWindowRect(const struct Rect& rect) = 0; + virtual void UpdateWindowMode(WindowMode mode) = 0; + virtual void UpdateFocusStatus(bool focused) = 0; +}; +} // namespace Rosen +} // namespace OHOS +#endif // OHOS_WINDOW_INTERFACE_H diff --git a/wmtest/wm/include/window_property.h b/wmtest/wm/include/window_property.h new file mode 100644 index 0000000000000000000000000000000000000000..f8b9ed4ca0d6fa47458baeec987794856c72559d --- /dev/null +++ b/wmtest/wm/include/window_property.h @@ -0,0 +1,79 @@ +/* + * Copyright (c) 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 OHOS_ROSEN_WINDOW_PROPERTY_H +#define OHOS_ROSEN_WINDOW_PROPERTY_H + +#include +#include +#include "parcel.h" +#include "wm_common.h" + +namespace OHOS { +namespace Rosen { +class WindowProperty : public Parcelable { +public: + WindowProperty() = default; + ~WindowProperty() = default; + + void SetWindowRect(const struct Rect& rect); + void SetWindowType(WindowType type); + void SetWindowMode(WindowMode mode); + void SetFullScreen(bool isFullScreen); + void SetFocusable(bool isFocusable); + void SetTouchable(bool isTouchable); + void SetPrivacyMode(bool isPrivate); + void SetTransparent(bool isTransparent); + void SetAlpha(float alpha); + void SetDisplayId(int32_t displayId); + void SetWindowId(uint32_t windowId); + void SetParentId(uint32_t parentId); + void SetWindowFlags(uint32_t flags); + + Rect GetWindowRect() const; + WindowType GetWindowType() const; + WindowMode GetWindowMode() const; + bool GetFullScreen() const; + bool GetFocusable() const; + bool GetTouchable() const; + bool GetPrivacyMode() const; + bool GetTransparent() const; + float GetAlpha() const; + int32_t GetDisplayId() const; + uint32_t GetWindowId() const; + uint32_t GetParentId() const; + uint32_t GetWindowFlags() const; + + virtual bool Marshalling(Parcel& parcel) const override; + static sptr Unmarshalling(Parcel& parcel); + +private: + Rect windowRect_ { 0, 0, 0, 0 }; + WindowType type_ { WindowType::WINDOW_TYPE_APP_MAIN_WINDOW }; + WindowMode mode_ { WindowMode::WINDOW_MODE_FULLSCREEN }; + uint32_t flags_ { 0 }; + bool isFullScreen_ { true }; + bool focusable_ { true }; + bool touchable_ { true }; + bool isPrivacyMode_ { false }; + bool isTransparent_ { false }; + float alpha_ { 1.0f }; + int32_t displayId_ { 0 }; + uint32_t windowId_ { 0 }; + uint32_t parentId_ { 0 }; +}; +} +} +#endif // OHOS_ROSEN_WINDOW_PROPERTY_H diff --git a/wmtest/wm/include/window_proxy.h b/wmtest/wm/include/window_proxy.h new file mode 100644 index 0000000000000000000000000000000000000000..8e1ea4a52e6aa791451abb05dd5f1dcaf4c8618e --- /dev/null +++ b/wmtest/wm/include/window_proxy.h @@ -0,0 +1,40 @@ +/* + * Copyright (c) 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 OHOS_WINDOW_PROXY_H +#define OHOS_WINDOW_PROXY_H + +#include "window_interface.h" +#include "iremote_proxy.h" + +namespace OHOS { +namespace Rosen { +class WindowProxy : public IRemoteProxy { +public: + explicit WindowProxy(const sptr& impl) : IRemoteProxy(impl) {}; + + ~WindowProxy() {}; + + void UpdateWindowProperty(const WindowProperty& windowProperty) override; + void UpdateWindowRect(const struct Rect& rect) override; + void UpdateWindowMode(WindowMode mode) override; + void UpdateFocusStatus(bool focused) override; + +private: + static inline BrokerDelegator delegator_; +}; +} // namespace Rosen +} // namespace OHOS +#endif // OHOS_WINDOW_PROXY_H diff --git a/wmtest/wm/include/window_stub.h b/wmtest/wm/include/window_stub.h new file mode 100644 index 0000000000000000000000000000000000000000..efc29d3b5081f72df4dd93873e6b03d4a598a5aa --- /dev/null +++ b/wmtest/wm/include/window_stub.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 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 OHOS_WINDOW_STUB_H +#define OHOS_WINDOW_STUB_H + +#include "window_interface.h" +#include "iremote_stub.h" + +namespace OHOS { +namespace Rosen { +class WindowStub : public IRemoteStub { +public: + WindowStub() = default; + ~WindowStub() = default; + + virtual int OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, + MessageOption &option) override; +}; +} // namespace Rosen +} // namespace OHOS +#endif // OHOS_WINDOW_STUB_H diff --git a/wmtest/wm/src/README.md b/wmtest/wm/src/README.md new file mode 100644 index 0000000000000000000000000000000000000000..2a99b4a2c9cf32ca8a28ce0857c95758c2cbde42 --- /dev/null +++ b/wmtest/wm/src/README.md @@ -0,0 +1 @@ +Store code of window client source files diff --git a/wmtest/wm/src/input_transfer_station.cpp b/wmtest/wm/src/input_transfer_station.cpp new file mode 100644 index 0000000000000000000000000000000000000000..43adc731bc68971b9c7203896bcd3bf78d55e693 --- /dev/null +++ b/wmtest/wm/src/input_transfer_station.cpp @@ -0,0 +1,114 @@ +/* + * Copyright (c) 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_transfer_station.h" +#include + +namespace OHOS { +namespace Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "InputTransferStation"}; +} +IMPLEMENT_SINGLE_INSTANCE(InputTransferStation) +void InputEventListener::OnInputEvent(std::shared_ptr keyEvent) const +{ + WLOGFI("OnInputEvent: receive keyEvent"); + if (keyEvent == nullptr) { + WLOGE("OnInputEvent receive KeyEvent is nullptr"); + return; + } + uint32_t windowId = keyEvent->GetAgentWindowId(); + auto channel = InputTransferStation::GetInstance()->GetInputChannel(windowId); + if (channel == nullptr) { + WLOGE("OnInputEvent channel is nullptr"); + return; + } + channel->HandleKeyEvent(keyEvent); +} + +void InputEventListener::OnInputEvent(std::shared_ptr axisEvent) const +{ + WLOGFI("OnInputEvent: receive axisEvent"); + if (axisEvent == nullptr) { + WLOGE("OnInputEvent receive axisEvent is nullptr"); + return; + } + axisEvent->MarkProcessed(); +} + +void InputEventListener::OnInputEvent(std::shared_ptr pointerEvent) const +{ + WLOGFI("OnInputEvent: receive pointerEvent"); + if (pointerEvent == nullptr) { + WLOGE("OnInputEvent receive pointerEvent is nullptr"); + return; + } + uint32_t windowId = pointerEvent->GetAgentWindowId(); + auto channel = InputTransferStation::GetInstance()->GetInputChannel(windowId); + if (channel == nullptr) { + WLOGE("OnInputEvent channel is nullptr"); + return; + } + channel->HandlePointerEvent(pointerEvent); +} + +void InputTransferStation::AddInputWindow(const sptr& window) +{ + WLOGFI("AddInputWindow: add window"); + uint32_t windowId = window->GetWindowId(); + sptr inputChannel = new WindowInputChannel(window); + windowInputChannels_.insert(std::make_pair(windowId, inputChannel)); + if (!initInputListener_) { + WLOGFI("init input listener"); + std::shared_ptr listener = std::make_shared(InputEventListener()); + MMI::InputManager::GetInstance()->SetWindowInputEventConsumer(listener); + inputListener_ = listener; + initInputListener_ = true; + } +} + +void InputTransferStation::RemoveInputWindow(const sptr& window) +{ + WLOGFI("RemoveInputWindow: remove window"); + uint32_t windowId = window->GetWindowId(); + auto iter = windowInputChannels_.find(windowId); + if (iter != windowInputChannels_.end()) { + windowInputChannels_.erase(windowId); + } else { + WLOGE("RemoveInputWindow do not find windowId: %{public}d", windowId); + } +} + +void InputTransferStation::SetInputListener(uint32_t windowId, std::shared_ptr &listener) +{ + auto channel = GetInputChannel(windowId); + if (channel == nullptr) { + WLOGE("SetInputListener channel is nullptr"); + return; + } + channel->SetInputListener(listener); +} + +sptr InputTransferStation::GetInputChannel(uint32_t windowId) +{ + auto iter = windowInputChannels_.find(windowId); + if (iter == windowInputChannels_.end()) { + WLOGE("GetInputChannel do not find channel according to windowId: %{public}d", windowId); + return nullptr; + } + return iter->second; +} +} +} diff --git a/wmtest/wm/src/vsync_station.cpp b/wmtest/wm/src/vsync_station.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4cc44398270977ea9fbb6e77b86547e007e5056b --- /dev/null +++ b/wmtest/wm/src/vsync_station.cpp @@ -0,0 +1,69 @@ +/* + * Copyright (c) 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 + +#include "window_manager_hilog.h" + +namespace OHOS { +namespace Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "VsyncStation"}; +} + +IMPLEMENT_SINGLE_INSTANCE(VsyncStation); + +void VsyncStation::RequestVsync(CallbackType type, std::shared_ptr vsyncCallback) +{ + auto iter = vsyncCallbacks_.find(type); + if (iter == vsyncCallbacks_.end()) { + WLOGFE("wrong callback type."); + return; + } + iter->second.insert(vsyncCallback); + if (!hasRequestedVsync_) { + hasRequestedVsync_.store(true); + callback_.timestamp_ = 0; + callback_.userdata_ = this; + callback_.callback_ = OnVsync; + VsyncError ret = VsyncHelper::Current()->RequestFrameCallback(callback_); + if (ret != VSYNC_ERROR_OK) { + WLOGFE("VsyncStation::RequestNextVsync fail: %s", VsyncErrorStr(ret).c_str()); + } + } +} + +void VsyncStation::VsyncCallbackInner(int64_t timestamp) +{ + for (auto& vsyncCallbacksSet: vsyncCallbacks_) { + for (const auto& callback: vsyncCallbacksSet.second) { + callback->onCallback(timestamp); + } + vsyncCallbacksSet.second.clear(); + } + hasRequestedVsync_.store(false); +} + +void VsyncStation::OnVsync(int64_t timestamp, void* client) +{ + auto vsyncClient = static_cast(client); + if (vsyncClient) { + vsyncClient->VsyncCallbackInner(timestamp); + } else { + WLOGFE("VsyncStation::OnVsync vsyncClient is null"); + } +} +} +} \ No newline at end of file diff --git a/wmtest/wm/src/window.cpp b/wmtest/wm/src/window.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e1ac8e3139040df9eb8482218d52dbe4b7edae6b --- /dev/null +++ b/wmtest/wm/src/window.cpp @@ -0,0 +1,49 @@ +/* + * Copyright (c) 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 "window.h" +#include "window_impl.h" +#include "window_manager_hilog.h" + +namespace OHOS { +namespace Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "WindowImpl"}; +} +sptr Window::Create(const std::string& windowName, sptr& option, + const sptr& abilityToken) +{ + if (windowName.empty()) { + WLOGFE("window name is empty"); + return nullptr; + } + if (option == nullptr) { + option = new WindowOption(); + } + option->SetWindowName(windowName); + sptr windowImpl = new WindowImpl(option); + WMError error = windowImpl->Create(option->GetParentName(), abilityToken); + if (error != WMError::WM_OK) { + return nullptr; + } + return windowImpl; +} + +sptr Window::Find(const std::string& windowName) +{ + return WindowImpl::Find(windowName); +} +} +} diff --git a/wmtest/wm/src/window_adapter.cpp b/wmtest/wm/src/window_adapter.cpp new file mode 100644 index 0000000000000000000000000000000000000000..81b169617ed63d643d9299114f6bdfc4bfa5cae3 --- /dev/null +++ b/wmtest/wm/src/window_adapter.cpp @@ -0,0 +1,171 @@ +/* + * Copyright (c) 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 "window_adapter.h" +#include +#include +#include "window_manager_hilog.h" +#include "wm_common.h" + +namespace OHOS { +namespace Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "WindowAdapter"}; +} + +IMPLEMENT_SINGLE_INSTANCE(WindowAdapter); + +WMError WindowAdapter::SaveAbilityToken(const sptr& abilityToken, uint32_t windowId) +{ + std::lock_guard lock(mutex_); + + if (!InitWMSProxyLocked()) { + return WMError::WM_ERROR_SAMGR; + } + return windowManagerServiceProxy_->SaveAbilityToken(abilityToken, windowId); +} + +WMError WindowAdapter::CreateWindow(sptr& window, sptr& windowProperty, + std::shared_ptr surfaceNode, uint32_t& windowId) +{ + std::lock_guard lock(mutex_); + + if (!InitWMSProxyLocked()) { + return WMError::WM_ERROR_SAMGR; + } + return windowManagerServiceProxy_->CreateWindow(window, windowProperty, surfaceNode, windowId); +} + +WMError WindowAdapter::AddWindow(sptr& windowProperty) +{ + std::lock_guard lock(mutex_); + + if (!InitWMSProxyLocked()) { + return WMError::WM_ERROR_SAMGR; + } + return windowManagerServiceProxy_->AddWindow(windowProperty); +} + +WMError WindowAdapter::RemoveWindow(uint32_t windowId) +{ + std::lock_guard lock(mutex_); + + if (!InitWMSProxyLocked()) { + return WMError::WM_ERROR_SAMGR; + } + return windowManagerServiceProxy_->RemoveWindow(windowId); +} + +WMError WindowAdapter::DestroyWindow(uint32_t windowId) +{ + std::lock_guard lock(mutex_); + + if (!InitWMSProxyLocked()) { + return WMError::WM_ERROR_SAMGR; + } + return windowManagerServiceProxy_->DestroyWindow(windowId); +} + +WMError WindowAdapter::MoveTo(uint32_t windowId, int32_t x, int32_t y) +{ + std::lock_guard lock(mutex_); + + if (!InitWMSProxyLocked()) { + return WMError::WM_ERROR_SAMGR; + } + return windowManagerServiceProxy_->MoveTo(windowId, x, y); +} + +WMError WindowAdapter::Resize(uint32_t windowId, uint32_t width, uint32_t height) +{ + std::lock_guard lock(mutex_); + + if (!InitWMSProxyLocked()) { + return WMError::WM_ERROR_SAMGR; + } + return windowManagerServiceProxy_->Resize(windowId, width, height); +} + +WMError WindowAdapter::RequestFocus(uint32_t windowId) +{ + std::lock_guard lock(mutex_); + + if (!InitWMSProxyLocked()) { + return WMError::WM_ERROR_SAMGR; + } + return windowManagerServiceProxy_->RequestFocus(windowId); +} + +bool WindowAdapter::InitWMSProxyLocked() +{ + if (!windowManagerServiceProxy_) { + sptr systemAbilityManager = + SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + if (!systemAbilityManager) { + WLOGFE("Failed to get system ability mgr."); + return false; + } + + sptr remoteObject = systemAbilityManager->GetSystemAbility(WINDOW_MANAGER_SERVICE_ID); + if (!remoteObject) { + WLOGFE("Failed to get window manager service."); + return false; + } + + windowManagerServiceProxy_ = iface_cast(remoteObject); + if ((!windowManagerServiceProxy_) || (!windowManagerServiceProxy_->AsObject())) { + WLOGFE("Failed to get system window manager services"); + return false; + } + + wmsDeath_ = new WMSDeathRecipient(); + if (!wmsDeath_) { + WLOGFE("Failed to create death Recipient ptr WMSDeathRecipient"); + return false; + } + if (!remoteObject->AddDeathRecipient(wmsDeath_)) { + WLOGFE("Failed to add death recipient"); + return false; + } + } + return true; +} + +void WindowAdapter::ClearWindowAdapter() +{ + std::lock_guard lock(mutex_); + if ((windowManagerServiceProxy_ != nullptr) && (windowManagerServiceProxy_->AsObject() != nullptr)) { + windowManagerServiceProxy_->AsObject()->RemoveDeathRecipient(wmsDeath_); + } + windowManagerServiceProxy_ = nullptr; +} + +void WMSDeathRecipient::OnRemoteDied(const wptr& wptrDeath) +{ + if (wptrDeath == nullptr) { + WLOGFE("wptrDeath is null"); + return; + } + + sptr object = wptrDeath.promote(); + if (!object) { + WLOGFE("object is null"); + return; + } + SingletonContainer::Get()->ClearWindowAdapter(); + return; +} +} // namespace Rosen +} // namespace OHOS \ No newline at end of file diff --git a/wmtest/wm/src/window_agent.cpp b/wmtest/wm/src/window_agent.cpp new file mode 100644 index 0000000000000000000000000000000000000000..79f7a28536838460c6cf5c47cf718df47f170212 --- /dev/null +++ b/wmtest/wm/src/window_agent.cpp @@ -0,0 +1,61 @@ +/* + * Copyright (c) 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 "window_agent.h" +#include "window_manager_hilog.h" + +namespace OHOS { +namespace Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "WindowAgent"}; +} + +WindowAgent::WindowAgent(sptr& windowImpl) +{ + window_ = windowImpl; +} + +void WindowAgent::UpdateWindowProperty(const WindowProperty& windowProperty) +{ +} + +void WindowAgent::UpdateWindowRect(const struct Rect& rect) +{ + if (window_ == nullptr) { + WLOGFE("window_ is nullptr"); + return; + } + window_->UpdateRect(rect); +} + +void WindowAgent::UpdateWindowMode(WindowMode mode) +{ + if (window_ == nullptr) { + WLOGFE("window_ is nullptr"); + return; + } + window_->UpdateMode(mode); +} + +void WindowAgent::UpdateFocusStatus(bool focused) +{ + if (window_ == nullptr) { + WLOGFE("window_ is nullptr"); + return; + } + window_->UpdateFocusStatus(focused); +} +} // namespace Rosen +} // namespace OHOS diff --git a/wmtest/wm/src/window_impl.cpp b/wmtest/wm/src/window_impl.cpp new file mode 100644 index 0000000000000000000000000000000000000000..6f5d980a75727f90abdebdfa1142db444acee58a --- /dev/null +++ b/wmtest/wm/src/window_impl.cpp @@ -0,0 +1,428 @@ +/* + * Copyright (c) 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 "window_impl.h" +#include "display_manager.h" +#include "singleton_container.h" +#include "window_adapter.h" +#include "window_agent.h" +#include "window_manager_hilog.h" +#ifndef _NEW_RENDERSERVER_ +#include "adapter.h" +#endif + +namespace OHOS { +namespace Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "WindowImpl"}; +} + +std::map>> WindowImpl::windowMap_; + +WindowImpl::WindowImpl(const sptr& option) +{ + property_ = new WindowProperty(); + property_->SetWindowRect(option->GetWindowRect()); + property_->SetWindowType(option->GetWindowType()); + property_->SetWindowMode(option->GetWindowMode()); + property_->SetFullScreen(option->GetWindowMode() == WindowMode::WINDOW_MODE_FULLSCREEN); + property_->SetFocusable(option->GetFocusable()); + property_->SetTouchable(option->GetTouchable()); + property_->SetDisplayId(option->GetDisplayId()); + property_->SetWindowFlags(option->GetWindowFlags()); + name_ = option->GetWindowName(); + +#ifdef _NEW_RENDERSERVER_ + struct RSSurfaceNodeConfig rsSurfaceNodeConfig; + surfaceNode_ = RSSurfaceNode::Create(rsSurfaceNodeConfig); +#endif +} + +WindowImpl::~WindowImpl() +{ + Destroy(); +} + +sptr WindowImpl::Find(const std::string& name) +{ + auto iter = windowMap_.find(name); + if (iter == windowMap_.end()) { + return nullptr; + } + return iter->second.second; +} + +std::shared_ptr WindowImpl::GetSurfaceNode() const +{ + return surfaceNode_; +} + +Rect WindowImpl::GetRect() const +{ + return property_->GetWindowRect(); +} + +WindowType WindowImpl::GetType() const +{ + return property_->GetWindowType(); +} + +WindowMode WindowImpl::GetMode() const +{ + return property_->GetWindowMode(); +} + +const std::string& WindowImpl::GetWindowName() const +{ + return name_; +} + +uint32_t WindowImpl::GetWindowId() +{ + return property_->GetWindowId(); +} + +WMError WindowImpl::SetWindowType(WindowType type) +{ + if (!IsWindowValid()) { + WLOGFI("window is already destroyed or not created! id: %{public}d", property_->GetWindowId()); + return WMError::WM_ERROR_INVALID_WINDOW; + } + if (state_ == STATE_CREATED) { + property_->SetWindowType(type); + return WMError::WM_OK; + } + if (property_->GetWindowType() != type) { + return WMError::WM_ERROR_INVALID_PARAM; + } + return WMError::WM_OK; +} + +WMError WindowImpl::SetWindowMode(WindowMode mode) +{ + if (!IsWindowValid()) { + WLOGFI("window is already destroyed or not created! id: %{public}d", property_->GetWindowId()); + return WMError::WM_ERROR_INVALID_WINDOW; + } + if (state_ == STATE_CREATED || state_ == STATE_HIDDEN) { + property_->SetWindowMode(mode); + return WMError::WM_OK; + } + if (property_->GetWindowMode() != mode) { + // TODO + } + return WMError::WM_OK; +} + +WMError WindowImpl::SetUIContent(std::shared_ptr context, + std::string& url, NativeEngine* engine, NativeValue* storage) +{ + WLOGFI("SetUIContent"); + uiContent_ = Ace::UIContent::Create(context.get(), engine); + if (uiContent_ == nullptr) { + WLOGFE("fail to SetUIContent id: %{public}d", property_->GetWindowId()); + return WMError::WM_ERROR_NULLPTR; + } + uiContent_->Initialize(this, url, storage); + return WMError::WM_OK; +} + +WMError WindowImpl::Create(const std::string& parentName, const sptr& abilityToken) +{ +#ifdef _NEW_RENDERSERVER_ + // check window name, same window names are forbidden + if (windowMap_.find(name_) != windowMap_.end()) { + WLOGFE("WindowName(%{public}s) already exists.", name_.c_str()); + return WMError::WM_ERROR_INVALID_PARAM; + } + // check parent name, if create sub window and there is not exist parent Window, then return + if (parentName != "") { + if (windowMap_.find(parentName) == windowMap_.end()) { + WLOGFE("ParentName is empty or valid. ParentName is %{public}s", parentName.c_str()); + return WMError::WM_ERROR_INVALID_PARAM; + } else { + uint32_t parentId = windowMap_[parentName].first; + property_->SetParentId(parentId); + } + } + + sptr window(this); + sptr windowAgent(new WindowAgent(window)); + uint32_t windowId = 0; + WMError ret = SingletonContainer::Get()->CreateWindow(windowAgent, property_, surfaceNode_, + windowId); + property_->SetWindowId(windowId); + + if (ret != WMError::WM_OK) { + WLOGFE("create window failed with errCode:%{public}d", static_cast(ret)); + return ret; + } + if (abilityToken != nullptr) { + ret = SingletonContainer::Get()->SaveAbilityToken(abilityToken, windowId); + if (ret != WMError::WM_OK) { + WLOGFE("SaveAbilityToken failed with errCode:%{public}d", static_cast(ret)); + return ret; + } + } + windowMap_.insert({ name_, std::pair>(windowId, this) }); + state_ = STATE_CREATED; + WLOGFI("create window success with winId:%{public}d", windowId); + InputTransferStation::GetInstance()->AddInputWindow(this); + return ret; +#else + /* weston adapter */ + return WMError::WM_OK; +#endif +} + +WMError WindowImpl::Destroy() +{ + NotifyBeforeDestroy(); +#ifdef _NEW_RENDERSERVER_ + // should destroy surface here + if (!IsWindowValid()) { + WLOGFI("window is already destroyed or not created! id: %{public}d", property_->GetWindowId()); + return WMError::WM_OK; + } + WLOGFI("destroy window id: %{public}d", property_->GetWindowId()); + WMError ret = SingletonContainer::Get()->DestroyWindow(property_->GetWindowId()); + windowMap_.erase(GetWindowName()); + state_ = STATE_DESTROYED; + InputTransferStation::GetInstance()->RemoveInputWindow(this); + return ret; +#else + InputTransferStation::GetInstance()->RemoveInputWindow(this); + Adapter::DestroyWestonWindow(); +#endif + return WMError::WM_OK; +} + +WMError WindowImpl::Show() +{ +#ifdef _NEW_RENDERSERVER_ + if (!IsWindowValid()) { + WLOGFI("window is already destroyed or not created! id: %{public}d", property_->GetWindowId()); + return WMError::WM_ERROR_INVALID_WINDOW; + } + if (state_ == STATE_SHOWN) { + WLOGFI("window is already shown id: %{public}d", property_->GetWindowId()); + return WMError::WM_OK; + } + SetDefaultOption(); + WMError ret = SingletonContainer::Get()->AddWindow(property_); + if (ret == WMError::WM_OK || ret == WMError::WM_ERROR_DEATH_RECIPIENT) { + Rect rect = property_->GetWindowRect(); + WLOGFI("show x: %{public}d ; y: %{public}d; width: %{public}d; height: %{public}d, winId:%{public}d;", + rect.posX_, rect.posY_, rect.width_, rect.height_, property_->GetWindowId()); + state_ = STATE_SHOWN; + NotifyAfterForeground(); + } + WLOGFE("show errCode:%{public}d for winId:%{public}d", static_cast(ret), property_->GetWindowId()); + return ret; +#else + /* weston adapter */ + WMError rtn = Adapter::Show(); + if (rtn == WMError::WM_OK) { + NotifyAfterForeground(); + NotifyAfterFocused(); + WLOGFI("Show AfterForeground was invoked"); + } else { + WLOGFE("Show error=%d", static_cast(rtn)); + } + InputTransferStation::GetInstance()->AddInputWindow(this); + return rtn; +#endif +} + +WMError WindowImpl::Hide() +{ +#ifdef _NEW_RENDERSERVER_ + if (!IsWindowValid()) { + WLOGFI("window is already destroyed or not created! id: %{public}d", property_->GetWindowId()); + return WMError::WM_ERROR_INVALID_WINDOW; + } + if (state_ == STATE_HIDDEN || state_ == STATE_CREATED) { + WLOGFI("window is already hidden id: %{public}d", property_->GetWindowId()); + return WMError::WM_OK; + } + WMError ret = SingletonContainer::Get()->RemoveWindow(property_->GetWindowId()); + WLOGFI("hide errCode:%{public}d for winId:%{public}d", static_cast(ret), property_->GetWindowId()); + if (ret != WMError::WM_OK) { + return ret; + } + state_ = STATE_HIDDEN; + NotifyAfterBackground(); + return ret; +#else + /* weston adapter */ + WMError rtn = Adapter::Hide(); + if (rtn == WMError::WM_OK) { + NotifyAfterUnFocused(); + NotifyAfterBackground(); + WLOGFI("WindowImpl::Show AfterBackground was ivoked"); + } else { + WLOGFE("WindowImpl::Show error=%d", static_cast(rtn)); + } + InputTransferStation::GetInstance()->RemoveInputWindow(this); + return rtn; +#endif +} + +WMError WindowImpl::MoveTo(int32_t x, int32_t y) +{ + /* weston adapter */ +#ifdef _NEW_RENDERSERVER_ + if (!IsWindowValid()) { + WLOGFI("window is already destroyed or not created! id: %{public}d", property_->GetWindowId()); + return WMError::WM_ERROR_INVALID_WINDOW; + } + if (state_ == STATE_HIDDEN || state_ == STATE_CREATED) { + Rect rect = GetRect(); + property_->SetWindowRect({ x, y, rect.width_, rect.height_ }); + WLOGFI("window is hidden or created! id: %{public}d, rect: [%{public}d, %{public}d, %{public}d, %{public}d]", + property_->GetWindowId(), rect.posX_, rect.posY_, x, y); + return WMError::WM_OK; + } + return SingletonContainer::Get()->MoveTo(property_->GetWindowId(), x, y); +#else + return Adapter::MoveTo(x, y); +#endif +} + +WMError WindowImpl::Resize(uint32_t width, uint32_t height) +{ + /* weston adapter */ +#ifdef _NEW_RENDERSERVER_ + if (!IsWindowValid()) { + WLOGFI("window is already destroyed or not created! id: %{public}d", property_->GetWindowId()); + return WMError::WM_ERROR_INVALID_WINDOW; + } + if (state_ == STATE_HIDDEN || state_ == STATE_CREATED) { + Rect rect = GetRect(); + property_->SetWindowRect({ rect.posX_, rect.posY_, width, height }); + WLOGFI("window is hidden or created! id: %{public}d, rect: [%{public}d, %{public}d, %{public}d, %{public}d]", + property_->GetWindowId(), rect.posX_, rect.posY_, width, height); + return WMError::WM_OK; + } + return SingletonContainer::Get()->Resize(property_->GetWindowId(), width, height); +#else + return Adapter::Resize(width, height); +#endif +} + +WMError WindowImpl::RequestFocus() const +{ + if (!IsWindowValid()) { + WLOGFI("window is already destroyed or not created! id: %{public}d", property_->GetWindowId()); + return WMError::WM_ERROR_INVALID_WINDOW; + } + return SingletonContainer::Get()->RequestFocus(property_->GetWindowId()); +} + +void WindowImpl::AddInputEventListener(std::shared_ptr& inputEventListener) +{ + InputTransferStation::GetInstance()->SetInputListener(GetWindowId(), inputEventListener); +} + +void WindowImpl::RegisterLifeCycleListener(sptr& listener) +{ + lifecycleListener_ = listener; +} + +void WindowImpl::RegisterWindowChangeListener(sptr& listener) +{ + windowChangeListener_ = listener; +} + +void WindowImpl::UpdateRect(const struct Rect& rect) +{ + property_->SetWindowRect(rect); + if (windowChangeListener_ != nullptr) { + windowChangeListener_->OnSizeChange(rect); + } +} + +void WindowImpl::UpdateMode(WindowMode mode) +{ + property_->SetWindowMode(mode); +} + +void WindowImpl::ConsumeKeyEvent(std::shared_ptr& keyEvent) +{ + uiContent_->ProcessKeyEvent(keyEvent); +} +void WindowImpl::ConsumePointerEvent(std::shared_ptr& pointerEvent) +{ + uiContent_->ProcessPointerEvent(pointerEvent); +} + +void WindowImpl::UpdateFocusStatus(bool focused) +{ + WLOGFI("window focus status: %{public}d, id: %{public}d", focused, property_->GetWindowId()); + if (focused) { + NotifyAfterFocused(); + } else { + NotifyAfterUnFocused(); + } +} + +void WindowImpl::SetDefaultOption() +{ + auto display = DisplayManager::GetInstance()->GetDisplayById(property_->GetDisplayId()); + if (display == nullptr) { + WLOGFE("get display failed displayId:%{public}d, window id:%{public}u", property_->GetDisplayId(), + property_->GetWindowId()); + return; + } + uint32_t width = display->GetWidth(); + uint32_t height = display->GetHeight(); + WLOGFI("width:%{public}u, height:%{public}u, displayId:%{public}d", width, height, property_->GetDisplayId()); + + Rect rect; + switch (property_->GetWindowType()) { + case WindowType::WINDOW_TYPE_STATUS_BAR: { + rect = { 0, 0, width, static_cast((static_cast(height) * 0.07)) }; + property_->SetWindowRect(rect); + property_->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING); + break; + } + case WindowType::WINDOW_TYPE_NAVIGATION_BAR: { + uint32_t navHeight = static_cast((static_cast(height) * 0.07)); + rect = { 0, static_cast(height - navHeight), width, navHeight }; + property_->SetWindowRect(rect); + property_->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING); + break; + } + case WindowType::WINDOW_TYPE_SYSTEM_ALARM_WINDOW: { + uint32_t alarmWidth = static_cast((static_cast(width) * 0.8)); + uint32_t alarmHeight = static_cast((static_cast(height) * 0.3)); + + rect = { static_cast((width - alarmWidth) / 2), static_cast((height - alarmHeight) / 2), + alarmWidth, alarmHeight }; + property_->SetWindowRect(rect); + property_->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING); + break; + } + default: + break; + } + +} +bool WindowImpl::IsWindowValid() const +{ + return ((state_ > STATE_INITIAL) && (state_ < STATE_BOTTOM)); +} +} +} \ No newline at end of file diff --git a/wmtest/wm/src/window_input_channel.cpp b/wmtest/wm/src/window_input_channel.cpp new file mode 100644 index 0000000000000000000000000000000000000000..952270f3aae386b0e806e51e282bc49c89c533c9 --- /dev/null +++ b/wmtest/wm/src/window_input_channel.cpp @@ -0,0 +1,83 @@ +/* + * Copyright (c) 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 "window_input_channel.h" +#include + +namespace OHOS { +namespace Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "WindowInputChannel"}; +} +WindowInputChannel::WindowInputChannel(const sptr& window) +{ + window_ = window; + callback_->onCallback = std::bind(&WindowInputChannel::OnVsync, this, std::placeholders::_1); +} + +void WindowInputChannel::HandleKeyEvent(std::shared_ptr& keyEvent) +{ + if (keyEvent == nullptr) { + WLOGE("HandleKeyEvent keyEvent is nullptr"); + return; + } + if (inputListener_ != nullptr) { + inputListener_->OnInputEvent(keyEvent); + return; + } + window_->ConsumeKeyEvent(keyEvent); + keyEvent->MarkProcessed(); +} + +void WindowInputChannel::HandlePointerEvent(std::shared_ptr& pointerEvent) +{ + if (pointerEvent == nullptr) { + WLOGE("HandlePointerEvent pointerEvent is nullptr"); + return; + } + if (inputListener_ != nullptr) { + inputListener_->OnInputEvent(pointerEvent); + return; + } + if (pointerEvent->GetPointerAction() == MMI::PointerEvent::POINTER_ACTION_MOVE) { + if (pointerEventPool_.size() > MAX_INPUT_NUM) { + pointerEventPool_.clear(); + } + pointerEventPool_.emplace_back(pointerEvent); + VsyncStation::GetInstance()->RequestVsync(VsyncStation::CallbackType::CALLBACK_INPUT, callback_); + } else { + window_->ConsumePointerEvent(pointerEvent); + pointerEvent->MarkProcessed(); + } +} + +void WindowInputChannel::OnVsync(int64_t timeStamp) +{ + if (pointerEventPool_.empty()) { + WLOGE("pointerEventPool_ is empty"); + return; + } + auto pointerEvent = pointerEventPool_.back(); + HandlePointerEvent(pointerEvent); + pointerEvent->MarkProcessed(); + pointerEventPool_.clear(); +} + +void WindowInputChannel::SetInputListener(std::shared_ptr& listener) +{ + inputListener_ = listener; +} +} +} \ No newline at end of file diff --git a/wmtest/wm/src/window_option.cpp b/wmtest/wm/src/window_option.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d116dd97893bdb8e80421372db91aa1b1a38144d --- /dev/null +++ b/wmtest/wm/src/window_option.cpp @@ -0,0 +1,126 @@ +/* + * Copyright (c) 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 "window_option.h" + +namespace OHOS { +namespace Rosen { +WindowOption::WindowOption() +{ + AddWindowFlag(WindowFlag::WINDOW_FLAG_NEED_AVOID); +} + +void WindowOption::SetWindowRect(const struct Rect& rect) +{ + windowRect_ = rect; +} + +void WindowOption::SetWindowType(WindowType type) +{ + type_ = type; +} + +void WindowOption::SetWindowMode(WindowMode mode) +{ + mode_ = mode; +} + +void WindowOption::SetFocusable(bool isFocusable) +{ + focusable_ = isFocusable; +} + +void WindowOption::SetTouchable(bool isTouchable) +{ + touchable_ = isTouchable; +} + +void WindowOption::SetDisplayId(int32_t displayId) +{ + displayId_ = displayId; +} + +void WindowOption::SetParentName(const std::string& parentName) +{ + parentName_ = parentName; +} + +void WindowOption::SetWindowName(const std::string& windowName) +{ + windowName_ = windowName; +} + +void WindowOption::AddWindowFlag(WindowFlag flag) +{ + flags_ |= static_cast(flag); +} + +void WindowOption::RemoveWindowFlag(WindowFlag flag) +{ + flags_ &= ~(static_cast(flag)); +} + +void WindowOption::SetWindowFlags(uint32_t flags) +{ + flags_ = flags; +} + +Rect WindowOption::GetWindowRect() const +{ + return windowRect_; +} + +WindowType WindowOption::GetWindowType() const +{ + return type_; +} + +WindowMode WindowOption::GetWindowMode() const +{ + return mode_; +} + +bool WindowOption::GetFocusable() const +{ + return focusable_; +} + +bool WindowOption::GetTouchable() const +{ + return touchable_; +} + +int32_t WindowOption::GetDisplayId() const +{ + return displayId_; +} + +const std::string& WindowOption::GetParentName() const +{ + return parentName_; +} + +const std::string& WindowOption::GetWindowName() const +{ + return windowName_; +} + +uint32_t WindowOption::GetWindowFlags() const +{ + return flags_; +} +} +} + diff --git a/wmtest/wm/src/window_property.cpp b/wmtest/wm/src/window_property.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3ee405db3ebb870d75f5b17093ae8433474b74bb --- /dev/null +++ b/wmtest/wm/src/window_property.cpp @@ -0,0 +1,238 @@ +/* + * Copyright (c) 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 "window_property.h" + +namespace OHOS { +namespace Rosen { +void WindowProperty::SetWindowRect(const struct Rect& rect) +{ + windowRect_ = rect; +} + +void WindowProperty::SetWindowType(WindowType type) +{ + type_ = type; +} + +void WindowProperty::SetWindowMode(WindowMode mode) +{ + mode_ = mode; +} + +void WindowProperty::SetFullScreen(bool isFullScreen) +{ + isFullScreen_ = isFullScreen; +} + +void WindowProperty::SetFocusable(bool isFocusable) +{ + focusable_ = isFocusable; +} + +void WindowProperty::SetTouchable(bool isTouchable) +{ + touchable_ = isTouchable; +} + +void WindowProperty::SetPrivacyMode(bool isPrivate) +{ + isPrivacyMode_ = isPrivate; +} + +void WindowProperty::SetTransparent(bool isTransparent) +{ + isTransparent_ = isTransparent; +} + +void WindowProperty::SetAlpha(float alpha) +{ + alpha_ = alpha; +} + +void WindowProperty::SetDisplayId(int32_t displayId) +{ + displayId_ = displayId; +} + +void WindowProperty::SetWindowFlags(uint32_t flags) +{ + flags_ = flags; +} + +Rect WindowProperty::GetWindowRect() const +{ + return windowRect_; +} + +WindowType WindowProperty::GetWindowType() const +{ + return type_; +} + +WindowMode WindowProperty::GetWindowMode() const +{ + return mode_; +} + +bool WindowProperty::GetFullScreen() const +{ + return isFullScreen_; +} + +bool WindowProperty::GetFocusable() const +{ + return focusable_; +} + +bool WindowProperty::GetTouchable() const +{ + return touchable_; +} + +bool WindowProperty::GetPrivacyMode() const +{ + return isPrivacyMode_; +} + +bool WindowProperty::GetTransparent() const +{ + return isTransparent_; +} + +float WindowProperty::GetAlpha() const +{ + return alpha_; +} + +int32_t WindowProperty::GetDisplayId() const +{ + return displayId_; +} + +uint32_t WindowProperty::GetWindowFlags() const +{ + return flags_; +} + +// TODO +void WindowProperty::SetWindowId(uint32_t windowId) +{ + windowId_ = windowId; +} +void WindowProperty::SetParentId(uint32_t parentId) +{ + parentId_ = parentId; +} +uint32_t WindowProperty::GetWindowId() const +{ + return windowId_; +} +uint32_t WindowProperty::GetParentId() const +{ + return parentId_; +} + +bool WindowProperty::Marshalling(Parcel& parcel) const +{ + // write windowRect_ + if (!(parcel.WriteInt32(windowRect_.posX_) && parcel.WriteInt32(windowRect_.posY_) && + parcel.WriteUint32(windowRect_.width_) && parcel.WriteUint32(windowRect_.height_))) { + return false; + } + + // write type_ + if (!parcel.WriteUint32(static_cast(type_))) { + return false; + } + + // write mode_ + if (!parcel.WriteUint32(static_cast(mode_))) { + return false; + } + + // write flags_ + if (!parcel.WriteUint32(flags_)) { + return false; + } + + // write isFullScreen_ + if (!parcel.WriteBool(isFullScreen_)) { + return false; + } + + // write focusable_ + if (!parcel.WriteBool(focusable_)) { + return false; + } + + // write touchable_ + if (!parcel.WriteBool(touchable_)) { + return false; + } + + // write isPrivacyMode_ + if (!parcel.WriteBool(isPrivacyMode_)) { + return false; + } + + // write isTransparent_ + if (!parcel.WriteBool(isTransparent_)) { + return false; + } + + // write alpha_ + if (!parcel.WriteFloat(alpha_)) { + return false; + } + + // write displayId_ + if (!parcel.WriteInt32(displayId_)) { + return false; + } + + // write windowId_ + if (!parcel.WriteUint32(windowId_)) { + return false; + } + + // write parentId_ + if (!parcel.WriteUint32(parentId_)) { + return false; + } + return true; +} + +sptr WindowProperty::Unmarshalling(Parcel& parcel) +{ + sptr property(new WindowProperty()); + Rect rect = { parcel.ReadInt32(), parcel.ReadInt32(), parcel.ReadUint32(), parcel.ReadUint32() }; + property->SetWindowRect(rect); + property->SetWindowType(static_cast(parcel.ReadUint32())); + property->SetWindowMode(static_cast(parcel.ReadUint32())); + property->SetWindowFlags(parcel.ReadUint32()); + property->SetFullScreen(parcel.ReadBool()); + property->SetFocusable(parcel.ReadBool()); + property->SetTouchable(parcel.ReadBool()); + property->SetPrivacyMode(parcel.ReadBool()); + property->SetTransparent(parcel.ReadBool()); + property->SetAlpha(parcel.ReadFloat()); + property->SetDisplayId(parcel.ReadInt32()); + property->SetWindowId(parcel.ReadUint32()); + property->SetParentId(parcel.ReadUint32()); + return property; +} +} +} diff --git a/wmtest/wm/src/window_proxy.cpp b/wmtest/wm/src/window_proxy.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7334d6bb601df3801b650e5950f985b6a985f72c --- /dev/null +++ b/wmtest/wm/src/window_proxy.cpp @@ -0,0 +1,97 @@ +/* + * Copyright (c) 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 "window_proxy.h" +#include +#include "window_manager_hilog.h" + +namespace OHOS { +namespace Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "WindowProxy"}; +} + +void WindowProxy::UpdateWindowProperty(const WindowProperty& windowProperty) +{ + sptr remote = Remote(); + if (remote == nullptr) { + WLOGFW("remote is nullptr"); + return; + } +} + +void WindowProxy::UpdateWindowRect(const struct Rect& rect) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!data.WriteInterfaceToken(GetDescriptor())) { + WLOGFE("WriteInterfaceToken failed"); + return; + } + if (!(data.WriteInt32(rect.posX_) && data.WriteInt32(rect.posY_) && + data.WriteUint32(rect.width_) && data.WriteUint32(rect.height_))) { + WLOGFE("Write WindowRect failed"); + return; + } + + if (Remote()->SendRequest(TRANS_ID_UPDATE_WINDOW_RECT, data, reply, option) != ERR_NONE) { + WLOGFE("SendRequest failed"); + } + return; +} + +void WindowProxy::UpdateWindowMode(WindowMode mode) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!data.WriteInterfaceToken(GetDescriptor())) { + WLOGFE("WriteInterfaceToken failed"); + return; + } + if (!data.WriteUint32(static_cast(mode))) { + WLOGFE("Write WindowMode failed"); + return; + } + + if (Remote()->SendRequest(TRANS_ID_UPDATE_WINDOW_MODE, data, reply, option) != ERR_NONE) { + WLOGFE("SendRequest failed"); + } + return; +} + +void WindowProxy::UpdateFocusStatus(bool focused) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!data.WriteInterfaceToken(GetDescriptor())) { + WLOGFE("WriteInterfaceToken failed"); + return; + } + if (!data.WriteBool(focused)) { + WLOGFE("Write Focus failed"); + return; + } + + if (Remote()->SendRequest(TRANS_ID_UPDATE_FOCUS_STATUS, data, reply, option) != ERR_NONE) { + WLOGFE("SendRequest failed"); + } + return; +} +} // namespace Rosen +} // namespace OHOS + diff --git a/wmtest/wm/src/window_scene.cpp b/wmtest/wm/src/window_scene.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3281d774287eb59dfd8df0b1bd053d8cc46ffc42 --- /dev/null +++ b/wmtest/wm/src/window_scene.cpp @@ -0,0 +1,127 @@ +/* + * Copyright (c) 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 "window_scene.h" +#include "static_call.h" +#include "window_impl.h" +#include "window_manager_hilog.h" +#ifndef _NEW_RENDERSERVER_ +#include "adapter.h" +#endif + +namespace OHOS { +namespace Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "WindowScene"}; +} + +const std::string WindowScene::MAIN_WINDOW_ID = "main window"; + +WindowScene::~WindowScene() +{ + WLOGFI("~WindowScene"); + if (mainWindow_ != nullptr) { + mainWindow_->Destroy(); + mainWindow_ = nullptr; + } +} + +WMError WindowScene::Init(int32_t displayId, std::shared_ptr& abilityContext, + sptr& listener) +{ + displayId_ = displayId; + abilityContext_ = abilityContext; + sptr option = new WindowOption(); + option->SetDisplayId(displayId); + +#ifndef _NEW_RENDERSERVER_ + /* weston adapter */ + Adapter::Init(); + mainWindow_ = CreateWindow(MAIN_WINDOW_ID, option); +#else + if (abilityContext_ != nullptr) { + mainWindow_ = SingletonContainer::Get()->CreateWindow( + MAIN_WINDOW_ID + std::to_string(count++), option, abilityContext_->GetAbilityToken()); + } else { + mainWindow_ = SingletonContainer::Get()->CreateWindow( + MAIN_WINDOW_ID + std::to_string(count++), option); + } + +#endif + if (mainWindow_ == nullptr) { + return WMError::WM_ERROR_NULLPTR; + } + mainWindow_->RegisterLifeCycleListener(listener); + + return WMError::WM_OK; +} + +sptr WindowScene::CreateWindow(const std::string& windowName, sptr& option) const +{ +#ifdef _NEW_RENDERSERVER_ + if (windowName.empty() || mainWindow_ == nullptr || option == nullptr) { + WLOGFE("WindowScene Name: %{public}s", windowName.c_str()); + return nullptr; + } + option->SetParentName(mainWindow_->GetWindowName()); + return SingletonContainer::Get()->CreateWindow(windowName, option); +#else + /* weston adapter */ + if (!Adapter::CreateWestonWindow(option)) { + WLOGFE("WindowScene::CreateWindow fail to CreateWestonWindow"); + return nullptr; + } + Rect rect; + if (!Adapter::GetMainWindowRect(rect)) { + WLOGFE("WindowScene::CreateWindow fail to GetMainWindowRect"); + return nullptr; + } + option->SetWindowName(windowName); + option->SetWindowRect(rect); + sptr window = new WindowImpl(option); + return window; +#endif +} + +const sptr& WindowScene::GetMainWindow() const +{ + return mainWindow_; +} + +WMError WindowScene::GoForeground() +{ + if (mainWindow_ == nullptr) { + return WMError::WM_ERROR_NULLPTR; + } + return mainWindow_->Show(); +} + +WMError WindowScene::GoBackground() const +{ + if (mainWindow_ == nullptr) { + return WMError::WM_ERROR_NULLPTR; + } + return mainWindow_->Hide(); +} + +WMError WindowScene::RequestFocus() const +{ + if (mainWindow_ == nullptr) { + return WMError::WM_ERROR_NULLPTR; + } + return mainWindow_->RequestFocus(); +} +} // namespace Rosen +} // namespace OHOS diff --git a/wmtest/wm/src/window_stub.cpp b/wmtest/wm/src/window_stub.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e7640726e2dd92bf8714057c2947f8806991bc23 --- /dev/null +++ b/wmtest/wm/src/window_stub.cpp @@ -0,0 +1,59 @@ +/* + * Copyright (c) 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 "window_stub.h" +#include "ipc_skeleton.h" +#include "window_manager_hilog.h" +#include "wm_common.h" + +namespace OHOS { +namespace Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "WindowStub"}; +} + +int WindowStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) +{ + WLOGFI("WindowStub::OnRemoteRequest code is %{public}d", code); + if (data.ReadInterfaceToken() != GetDescriptor()) { + WLOGFE("InterfaceToken check failed"); + return -1; + } + switch (code) { + case TRANS_ID_UPDATE_WINDOW_PROPERTY: { + break; + } + case TRANS_ID_UPDATE_WINDOW_RECT: { + struct Rect rect{ data.ReadInt32(), data.ReadInt32(), data.ReadUint32(), data.ReadUint32() }; + UpdateWindowRect(rect); + break; + } + case TRANS_ID_UPDATE_WINDOW_MODE: { + WindowMode mode = static_cast(data.ReadUint32()); + UpdateWindowMode(mode); + break; + } + case TRANS_ID_UPDATE_FOCUS_STATUS: { + bool focused = data.ReadBool(); + UpdateFocusStatus(focused); + break; + } + default: + break; + } + return 0; +} +} // namespace Rosen +} // namespace OHOS diff --git a/wmtest/wmserver/BUILD.gn b/wmtest/wmserver/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..6db371375123cae1b8cc078d6aaefe8f41908413 --- /dev/null +++ b/wmtest/wmserver/BUILD.gn @@ -0,0 +1,85 @@ +# Copyright (c) 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/ohos.gni") + +## Build libwms.so +config("libwms_config") { + visibility = [ ":*" ] + + include_dirs = [ + "include", + "//utils/system/safwk/native/include", + "//foundation/windowmanager/interfaces/innerkits/wm", + "//foundation/windowmanager/interfaces/innerkits/dm", + "//foundation/windowmanager/wm/include", + "//foundation/windowmanager/utils/include", + "//foundation/windowmanager/dm/include", + "//foundation/windowmanager/dmserver/include", + ] + + cflags = [ + "-Wall", + "-Werror", + "-g3", + ] +} + +ohos_shared_library("libwms") { + sources = [ + "../dmserver/src/display_manager_service.cpp", + "../dmserver/src/display_manager_service_inner.cpp", + "../dmserver/src/display_manager_stub.cpp", + "../dmserver/src/display_node_control.cpp", + "../dmserver/src/display_screen.cpp", + "../dmserver/src/display_screen_manager.cpp", + "../dmserver/src/screen.cpp", + "src/input_window_monitor.cpp", + "src/window_controller.cpp", + "src/window_layout_policy.cpp", + "src/window_manager_service.cpp", + "src/window_manager_stub.cpp", + "src/window_node.cpp", + "src/window_node_container.cpp", + "src/window_root.cpp", + "src/window_zorder_policy.cpp", + ] + + configs = [ ":libwms_config" ] + + deps = [ + "//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog", + "//foundation/distributedschedule/safwk/interfaces/innerkits/safwk:system_ability_fwk", + "//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", + "//foundation/windowmanager/wm:libwmutil", + "//utils/native/base:utils", + + # RSSurface + "//foundation/graphic/standard/rosen/modules/render_service_base:librender_service_base", + "//foundation/graphic/standard/rosen/modules/render_service_client:librender_service_client", + + # IMS + "//foundation/multimodalinput/input/frameworks/proxy:libmmi-client", + ] + + public_deps = [ + # ability manager + "//foundation/aafwk/standard/interfaces/innerkits/ability_manager:ability_manager", + "//foundation/aafwk/standard/interfaces/innerkits/want:want", + ] + + external_deps = [ "ipc:ipc_core" ] + + part_name = "window_manager" + subsystem_name = "window" +} diff --git a/wmtest/wmserver/include/README.md b/wmtest/wmserver/include/README.md new file mode 100644 index 0000000000000000000000000000000000000000..539249966b4bf441daae568854d04f8f8b0e5029 --- /dev/null +++ b/wmtest/wmserver/include/README.md @@ -0,0 +1 @@ +Store code of window sever inner header files \ No newline at end of file diff --git a/wmtest/wmserver/include/input_window_monitor.h b/wmtest/wmserver/include/input_window_monitor.h new file mode 100644 index 0000000000000000000000000000000000000000..ed446505805590d1edc8f2f1891476daa8c7a677 --- /dev/null +++ b/wmtest/wmserver/include/input_window_monitor.h @@ -0,0 +1,72 @@ +/* + * Copyright (c) 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 OHOS_INPUT_WINDOW_MONITOR_H +#define OHOS_INPUT_WINDOW_MONITOR_H + +#include +#include + +#include "window_root.h" + +namespace OHOS { +namespace Rosen { +class InputWindowMonitor : public RefBase { +public: + InputWindowMonitor(sptr& root) : windowRoot_(root) + { + MMI::PhysicalDisplayInfo physicalDisplayInfo = { + .id = 0, //todo: update when DMS is ready + .leftDisplayId = -1, // todo: invalid displayId for testing + .upDisplayId = -1, // todo: invalid displayId for testing + .topLeftX = 0, // todo: use wgn info for testing + .topLeftY = 0, // todo: use wgn info for testing + .width = 2560, // todo: use wgn info for testing + .height = 1600, // todo: use wgn info for testing + .name = "physical_display0", // todo: wait for DMS + .seatId = "seat0", // todo: update seatId + .seatName = "default0", // todo: update seatId + .logicWidth = 2560, // todo: use wgn info for testing + .logicHeight = 1600, // todo: use wgn info for testing + .direction = MMI::Direction0 // todo: use direction 0 for testing + }; + physicalDisplays_.emplace_back(physicalDisplayInfo); + MMI::LogicalDisplayInfo logicalDisplayInfo = { + .id = 0, //todo: update when DMS is ready + .topLeftX = 0, // todo: use wgn info for testing + .topLeftY = 0, // todo: use wgn info for testing + .width = 2560, // todo: use wgn info for testing + .height = 1600, // todo: use wgn info for testing + .name = "logical_display0", // todo: wait for DMS + .seatId = "seat0", // todo: update seatId + .seatName = "default0", // todo: update seatName + .focusWindowId = -1, + .windowsInfo_ = {}, + }; + logicalDisplays_.emplace_back(logicalDisplayInfo); + } + ~InputWindowMonitor() = default; + void UpdateInputWindow(uint32_t windowId); + +private: + sptr windowRoot_; + std::vector physicalDisplays_; + std::vector logicalDisplays_; + void TraverseWindowNodes(const std::vector>& windowNodes, + std::vector::iterator& iter); +}; +} +} +#endif // OHOS_INPUT_WINDOW_MONITOR_H diff --git a/wmtest/wmserver/include/window_controller.h b/wmtest/wmserver/include/window_controller.h new file mode 100644 index 0000000000000000000000000000000000000000..043cad3d49d9773c55b9202279e2d919ac75a265 --- /dev/null +++ b/wmtest/wmserver/include/window_controller.h @@ -0,0 +1,48 @@ +/* + * Copyright (c) 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 OHOS_ROSEN_WINDOW_CONTROLLER_H +#define OHOS_ROSEN_WINDOW_CONTROLLER_H + +#include +#include "window_root.h" + +namespace OHOS { +namespace Rosen { +class WindowController : public RefBase { +public: + WindowController(sptr& root) : windowRoot_(root) {} + ~WindowController() = default; + + WMError CreateWindow(sptr& window, sptr& property, + const std::shared_ptr& surfaceNode, uint32_t& windowId); + WMError AddWindowNode(sptr& property); + WMError RemoveWindowNode(uint32_t windowId); + WMError DestroyWindow(uint32_t windowId); + WMError MoveTo(uint32_t windowId, int32_t x, int32_t y); + WMError Resize(uint32_t windowId, uint32_t width, uint32_t height); + WMError RequestFocus(uint32_t windowId); + WMError SaveAbilityToken(const sptr& abilityToken, uint32_t windowId); + +private: + uint32_t GenWindowId(); + WMError LayoutWindowNodeTrees(); + + sptr windowRoot_; + std::atomic windowId_ { 0 }; +}; +} +} +#endif // OHOS_ROSEN_WINDOW_CONTROLLER_H diff --git a/wmtest/wmserver/include/window_layout_policy.h b/wmtest/wmserver/include/window_layout_policy.h new file mode 100644 index 0000000000000000000000000000000000000000..350b8c0e2a0515e50004b60413486a84cf46055d --- /dev/null +++ b/wmtest/wmserver/include/window_layout_policy.h @@ -0,0 +1,53 @@ +/* + * Copyright (c) 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 OHOS_ROSEN_WINDOW_LAYOUT_POLICY_H +#define OHOS_ROSEN_WINDOW_LAYOUT_POLICY_H + +#include +#include +#include + +#include "window_node.h" +#include "wm_common.h" + +namespace OHOS { +namespace Rosen { +class WindowLayoutPolicy : public RefBase { +public: + WindowLayoutPolicy() = default; + ~WindowLayoutPolicy() = default; + WMError UpdateDisplayInfo(const Rect& displayRect); + WMError LayoutWindow(sptr& node); + +private: + Rect displayRect_ = {0, 0, 0, 0}; + Rect limitRect_ = {0, 0, 0, 0}; + std::map> aviodNodes_; + const std::set aviodTypes_ { + WindowType::WINDOW_TYPE_STATUS_BAR, + WindowType::WINDOW_TYPE_NAVIGATION_BAR, + }; + void UpdateLimitRect(const sptr& node); + void RecordAvoidRect(const sptr& node); + bool UpdateLayoutRects(sptr& node); + bool IsNeedAvoidNode(const sptr& node); + bool IsFullScreenNode(const sptr& node); + bool IsParentLimitNode(const sptr& node); + bool IsRectChanged(const Rect& l, const Rect& r); +}; +} +} +#endif // OHOS_ROSEN_WINDOW_LAYOUT_POLICY_H diff --git a/wmtest/wmserver/include/window_manager_interface.h b/wmtest/wmserver/include/window_manager_interface.h new file mode 100644 index 0000000000000000000000000000000000000000..e1d9d4d49443a9937fc7d525f719bd287aef4549 --- /dev/null +++ b/wmtest/wmserver/include/window_manager_interface.h @@ -0,0 +1,52 @@ +/* + * Copyright (c) 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 OHOS_WINDOW_MANAGER_INTERFACE_H +#define OHOS_WINDOW_MANAGER_INTERFACE_H + +#include +#include +#include "window_property.h" +#include "window_interface.h" + +namespace OHOS { +namespace Rosen { +class IWindowManager : public IRemoteBroker { +public: + DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.IWindowManager"); + + enum { + TRANS_ID_CREATE_WINDOW, + TRANS_ID_ADD_WINDOW, + TRANS_ID_REMOVE_WINDOW, + TRANS_ID_DESTROY_WINDOW, + TRANS_ID_MOVE, + TRANS_ID_RESIZE, + TRANS_ID_REQUEST_FOCUS, + TRANS_ID_SEND_ABILITY_TOKEN, + }; + virtual WMError CreateWindow(sptr& window, sptr& property, + const std::shared_ptr& surfaceNode, uint32_t& windowId) = 0; + virtual WMError AddWindow(sptr& property) = 0; + virtual WMError RemoveWindow(uint32_t windowId) = 0; + virtual WMError DestroyWindow(uint32_t windowId) = 0; + virtual WMError MoveTo(uint32_t windowId, int32_t x, int32_t y) = 0; + virtual WMError Resize(uint32_t windowId, uint32_t width, uint32_t height) = 0; + virtual WMError RequestFocus(uint32_t windowId) = 0; + virtual WMError SaveAbilityToken(const sptr& abilityToken, uint32_t windowId) = 0; +}; +} +} +#endif // OHOS_WINDOW_MANAGER_INTERFACE_H diff --git a/wmtest/wmserver/include/window_manager_proxy.h b/wmtest/wmserver/include/window_manager_proxy.h new file mode 100644 index 0000000000000000000000000000000000000000..60e89fd3cfd206b25681127a72a77c0f2d4864a0 --- /dev/null +++ b/wmtest/wmserver/include/window_manager_proxy.h @@ -0,0 +1,45 @@ +/* + * Copyright (c) 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 OHOS_WINDOW_MANAGER_PROXY_H +#define OHOS_WINDOW_MANAGER_PROXY_H + +#include "window_manager_interface.h" +#include + +namespace OHOS { +namespace Rosen { +class WindowManagerProxy : public IRemoteProxy { +public: + explicit WindowManagerProxy(const sptr& impl) : IRemoteProxy(impl) {}; + + ~WindowManagerProxy() {}; + + WMError CreateWindow(sptr& window, sptr& property, + const std::shared_ptr& surfaceNode, uint32_t& windowId) override; + WMError AddWindow(sptr& property) override; + WMError RemoveWindow(uint32_t windowId) override; + WMError DestroyWindow(uint32_t windowId) override; + WMError MoveTo(uint32_t windowId, int32_t x, int32_t y) override; + WMError Resize(uint32_t windowId, uint32_t width, uint32_t height) override; + WMError RequestFocus(uint32_t windowId) override; + WMError SaveAbilityToken(const sptr& abilityToken, uint32_t windowId) override; + +private: + static inline BrokerDelegator delegator_; +}; +} +} +#endif // OHOS_WINDOW_MANAGER_PROXY_H diff --git a/wmtest/wmserver/include/window_manager_service.h b/wmtest/wmserver/include/window_manager_service.h new file mode 100644 index 0000000000000000000000000000000000000000..b722b1646912b283861a259a1854d3aff4d0648f --- /dev/null +++ b/wmtest/wmserver/include/window_manager_service.h @@ -0,0 +1,63 @@ +/* + * Copyright (c) 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 OHOS_WINDOW_MANAGER_SERVICE_H +#define OHOS_WINDOW_MANAGER_SERVICE_H + +#include +#include + +#include +#include +#include +#include "singleton_delegator.h" +#include "single_instance.h" +#include "window_controller.h" +#include "window_manager_stub.h" +#include "window_root.h" + +namespace OHOS { +namespace Rosen { +class WindowManagerService : public SystemAbility, public WindowManagerStub { +DECLARE_SYSTEM_ABILITY(WindowManagerService); + +DECLARE_SINGLE_INSTANCE_BASE(WindowManagerService); + +public: + ~WindowManagerService() = default; + void OnStart() override; + void OnStop() override; + + WMError CreateWindow(sptr& window, sptr& property, + const std::shared_ptr& surfaceNode, uint32_t& windowId) override; + WMError AddWindow(sptr& property) override; + WMError RemoveWindow(uint32_t windowId) override; + WMError DestroyWindow(uint32_t windowId) override; + WMError MoveTo(uint32_t windowId, int32_t x, int32_t y) override; + WMError Resize(uint32_t windowId, uint32_t width, uint32_t height) override; + WMError RequestFocus(uint32_t windowId) override; + WMError SaveAbilityToken(const sptr& abilityToken, uint32_t windowId) override; +private: + WindowManagerService(); + bool Init(); + static inline SingletonDelegator delegator; + std::mutex mutex_; + sptr windowRoot_; + sptr windowController_; + sptr inputWindowMonitor_; +}; +} +} +#endif // OHOS_WINDOW_MANAGER_SERVICE_H diff --git a/wmtest/wmserver/include/window_manager_stub.h b/wmtest/wmserver/include/window_manager_stub.h new file mode 100644 index 0000000000000000000000000000000000000000..4fa7df0aa9b7335b9d08cbae98396157f10e7cb3 --- /dev/null +++ b/wmtest/wmserver/include/window_manager_stub.h @@ -0,0 +1,32 @@ +/* + * Copyright (c) 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 OHOS_WINDOW_MANAGER_STUB_H +#define OHOS_WINDOW_MANAGER_STUB_H + +#include "window_manager_interface.h" +#include +namespace OHOS { +namespace Rosen { +class WindowManagerStub : public IRemoteStub { +public: + WindowManagerStub() = default; + ~WindowManagerStub() = default; + virtual int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, + MessageOption &option) override; +}; +} +} +#endif // OHOS_WINDOW_MANAGER_STUB_H diff --git a/wmtest/wmserver/include/window_node.h b/wmtest/wmserver/include/window_node.h new file mode 100644 index 0000000000000000000000000000000000000000..0684ebe71db850c6ea4e5753a8df58c1590c35c4 --- /dev/null +++ b/wmtest/wmserver/include/window_node.h @@ -0,0 +1,82 @@ +/* + * Copyright (c) 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 OHOS_ROSEN_WINDOW_NODE_H +#define OHOS_ROSEN_WINDOW_NODE_H + +#include +#include +#include +#include "window_interface.h" +#include "window_manager_hilog.h" + +namespace OHOS { +namespace Rosen { +struct LayoutRects { + Rect displayRect_ = { 0, 0, 0, 0 }; + Rect parentRect_ = { 0, 0, 0, 0 }; + Rect limitRect_ = { 0, 0, 0, 0 }; + Rect rect_ = { 0, 0, 0, 0 }; +}; + +class WindowNode : public RefBase { +public: + WindowNode(const sptr& property, const sptr& window, + std::shared_ptr surfaceNode) + : surfaceNode_(surfaceNode), property_(property), windowToken_(window) + { + callingPid_ = IPCSkeleton::GetCallingPid(); + callingUid_ = IPCSkeleton::GetCallingUid(); + } + WindowNode() : property_(new WindowProperty()) + { + callingPid_ = IPCSkeleton::GetCallingPid(); + callingUid_ = IPCSkeleton::GetCallingUid(); + } + ~WindowNode() = default; + + void SetDisplayId(int32_t displayId); + void UpdateLayoutRects(const LayoutRects& rects); + void SetWindowProperty(const sptr& property); + + const sptr& GetWindowToken() const; + uint32_t GetWindowId() const; + int32_t GetDisplayId() const; + const LayoutRects& GetLayoutRects() const; + WindowType GetWindowType() const; + WindowMode GetWindowMode() const; + uint32_t GetWindowFlags() const; + const sptr& GetWindowProperty() const; + int32_t GetCallingPid() const; + int32_t GetCallingUid() const; + + sptr parent_; + std::vector> children_; + std::shared_ptr surfaceNode_; + sptr abilityToken_ = nullptr; + int32_t priority_ { 0 }; + bool requestedVisibility_ { false }; + bool currentVisibility_ { false }; + +private: + sptr property_; + sptr windowToken_; + LayoutRects layoutRects_; + int32_t callingPid_; + int32_t callingUid_; +}; +} +} +#endif // OHOS_ROSEN_WINDOW_NODE_H diff --git a/wmtest/wmserver/include/window_node_container.h b/wmtest/wmserver/include/window_node_container.h new file mode 100644 index 0000000000000000000000000000000000000000..251683b665fea1a812bf9b756845b8193cf00ba6 --- /dev/null +++ b/wmtest/wmserver/include/window_node_container.h @@ -0,0 +1,76 @@ +/* + * Copyright (c) 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 OHOS_ROSEN_WINDOW_NODE_CONTAINER_H +#define OHOS_ROSEN_WINDOW_NODE_CONTAINER_H + +#include +#include "window_layout_policy.h" +#include "window_node.h" +#include "window_zorder_policy.h" +#include "wm_common.h" + +namespace OHOS { +namespace Rosen { +class WindowNodeContainer : public RefBase { +public: + WindowNodeContainer(uint64_t screenId, uint32_t width, uint32_t height) + { + struct RSDisplayNodeConfig config = {screenId}; + displayNode_ = RSDisplayNode::Create(config); + displayRect_ = { + .posX_ = 0, + .posY_ = 0, + .width_ = width, + .height_ = height + }; + } + + ~WindowNodeContainer(); + WMError AddWindowNode(sptr& node, sptr& parentNode); + WMError RemoveWindowNode(sptr& node); + WMError DestroyWindowNode(sptr& node, std::vector& windowIds); + const std::vector& Destroy(); + void AssignZOrder(); + WMError SetFocusWindow(uint32_t windowId); + uint32_t GetFocusWindow() const; + WMError MinimizeOtherFullScreenAbility(); // adapt to api7 + void TraverseContainer(std::vector>& windowNodes); + WMError LayoutWindowNodes(); + +private: + void AssignZOrder(sptr& node); + void TraverseWindowNode(sptr& root, std::vector>& windowNodes); + sptr FindRoot(WindowType type) const; + void UpdateFocusWindow(); + sptr FindWindowNodeById(uint32_t id) const; + void UpdateFocusStatus(uint32_t id, bool focused) const; + void UpdateWindowTree(sptr& node); + bool UpdateRSTree(sptr& node, bool isAdd); + sptr zorderPolicy_ = new WindowZorderPolicy(); + sptr layoutPolicy_ = new WindowLayoutPolicy(); + sptr belowAppWindowNode_ = new WindowNode(); + sptr appWindowNode_ = new WindowNode(); + sptr aboveAppWindowNode_ = new WindowNode(); + std::shared_ptr displayNode_; + std::vector removedIds_; + uint32_t zOrder_ { 0 }; + uint32_t focusedWindow_ { 0 }; + Rect displayRect_; + WMError LayoutWindowNode(sptr& node); +}; +} +} +#endif // OHOS_ROSEN_WINDOW_NODE_CONTAINER_H diff --git a/wmtest/wmserver/include/window_root.h b/wmtest/wmserver/include/window_root.h new file mode 100644 index 0000000000000000000000000000000000000000..9a86234686cc8e5504f1129d0896986d87b26bda --- /dev/null +++ b/wmtest/wmserver/include/window_root.h @@ -0,0 +1,65 @@ +/* + * Copyright (c) 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 OHOS_ROSEN_WINDOW_ROOT_H +#define OHOS_ROSEN_WINDOW_ROOT_H + +#include +#include +#include "window_node_container.h" + +namespace OHOS { +namespace Rosen { +class WindowDeathRecipient : public IRemoteObject::DeathRecipient { +public: + WindowDeathRecipient(std::function&)> callback) : callback_(callback) {} + ~WindowDeathRecipient() = default; + + virtual void OnRemoteDied(const wptr& wptrDeath) override; + + std::function&)> callback_; +}; + +class WindowRoot : public RefBase { +public: + WindowRoot() = default; + ~WindowRoot() = default; + + sptr GetOrCreateWindowNodeContainer(int32_t displayId); + void NotifyDisplayRemoved(int32_t displayId); + sptr GetWindowNode(uint32_t windowId) const; + + WMError SaveWindow(const sptr& node); + WMError AddWindowNode(uint32_t parentId, sptr& node); + WMError RemoveWindowNode(uint32_t windowId); + WMError DestroyWindow(uint32_t windowId); + const std::map>& GetWindowNodeContainerMap() const; + + WMError RequestFocus(uint32_t windowId); + WMError MinimizeOtherFullScreenAbility(sptr& node); + +private: + void ClearWindow(const sptr& remoteObject); + WMError DestroyWindowInner(sptr& node); + + std::map> windowNodeContainerMap_; + std::map> windowNodeMap_; + std::map, uint32_t> windowIdMap_; + + sptr windowDeath_ = new WindowDeathRecipient(std::bind(&WindowRoot::ClearWindow, + this, std::placeholders::_1)); +}; +} +} +#endif // OHOS_ROSEN_WINDOW_ROOT_H diff --git a/wmtest/wmserver/include/window_zorder_policy.h b/wmtest/wmserver/include/window_zorder_policy.h new file mode 100644 index 0000000000000000000000000000000000000000..8e91d3d664faa9e906e395d4d497652ae7d1ad99 --- /dev/null +++ b/wmtest/wmserver/include/window_zorder_policy.h @@ -0,0 +1,63 @@ +/* + * Copyright (c) 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 OHOS_ROSEN_WINDOW_ZORDER_POLICY_H +#define OHOS_ROSEN_WINDOW_ZORDER_POLICY_H + +#include +#include + +#include "wm_common.h" + +namespace OHOS { +namespace Rosen { +class WindowZorderPolicy : public RefBase { +public: + WindowZorderPolicy() = default; + ~WindowZorderPolicy() = default; + + int32_t GetWindowPriority(WindowType type) const; + +private: + const std::map windowPriorityMap_ { + // sub-windows types + { WindowType::WINDOW_TYPE_MEDIA, -1 }, + { WindowType::WINDOW_TYPE_APP_SUB_WINDOW, 1 }, + + // main window + { WindowType::WINDOW_TYPE_APP_MAIN_WINDOW, 0 }, + + // system-specific window + { WindowType::WINDOW_TYPE_WALLPAPER, 101 }, + { WindowType::WINDOW_TYPE_APP_LAUNCHING, 102 }, + { WindowType::WINDOW_TYPE_DOCK_SLICE, 103 }, + { WindowType::WINDOW_TYPE_INCOMING_CALL, 104 }, + { WindowType::WINDOW_TYPE_SEARCHING_BAR, 105 }, + { WindowType::WINDOW_TYPE_SYSTEM_ALARM_WINDOW, 106 }, + { WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT, 107 }, + { WindowType::WINDOW_TYPE_FLOAT, 108 }, + { WindowType::WINDOW_TYPE_TOAST, 109 }, + { WindowType::WINDOW_TYPE_STATUS_BAR, 110 }, + { WindowType::WINDOW_TYPE_PANEL, 111 }, + { WindowType::WINDOW_TYPE_KEYGUARD, 112 }, + { WindowType::WINDOW_TYPE_VOLUME_OVERLAY, 113 }, + { WindowType::WINDOW_TYPE_NAVIGATION_BAR, 114 }, + { WindowType::WINDOW_TYPE_DRAGGING_EFFECT, 115 }, + { WindowType::WINDOW_TYPE_POINTER, 116 }, + }; +}; +} +} +#endif // OHOS_ROSEN_WINDOW_STATE_H diff --git a/wmtest/wmserver/src/README.md b/wmtest/wmserver/src/README.md new file mode 100644 index 0000000000000000000000000000000000000000..6aa13c7e6a88bfb1eafe50621b24c3d17b1c9acb --- /dev/null +++ b/wmtest/wmserver/src/README.md @@ -0,0 +1 @@ +Store code of window server source files diff --git a/wmtest/wmserver/src/input_window_monitor.cpp b/wmtest/wmserver/src/input_window_monitor.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9dc6ff82a8cd355eebe41612d650631eec262bbd --- /dev/null +++ b/wmtest/wmserver/src/input_window_monitor.cpp @@ -0,0 +1,87 @@ +/* + * Copyright (c) 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_window_monitor.h" + +#include + +#include + +#include "window_manager_hilog.h" + +namespace OHOS { +namespace Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "InputWindowMonitor"}; +} + +void InputWindowMonitor::UpdateInputWindow(uint32_t windowId) +{ + if (windowRoot_ == nullptr) { + WLOGFE("windowRoot is null."); + return; + } + sptr windowNode = windowRoot_->GetWindowNode(windowId); + if (windowNode == nullptr) { + WLOGFE("window node could not be found."); + return; + } + int32_t displayId = windowNode->GetDisplayId(); + auto container = windowRoot_->GetOrCreateWindowNodeContainer(displayId); + if (container == nullptr) { + WLOGFE("can not get window node container."); + return; + } + std::vector> windowNodes; + container->TraverseContainer(windowNodes); + + auto iter = std::find_if(logicalDisplays_.begin(), logicalDisplays_.end(), + [displayId](MMI::LogicalDisplayInfo& logicalDisplay) { + return logicalDisplay.id == displayId; + }); + if (iter != logicalDisplays_.end()) { + TraverseWindowNodes(windowNodes, iter); + if (!iter->windowsInfo_.empty()) { + iter->focusWindowId = container->GetFocusWindow(); + } + } else { + WLOGFE("There is no display for this window action."); + return; + } + WLOGFI("update display info to IMS."); + MMI::InputManager::GetInstance()->UpdateDisplayInfo(physicalDisplays_, logicalDisplays_); +} + +void InputWindowMonitor::TraverseWindowNodes(const std::vector> &windowNodes, + std::vector::iterator& iter) +{ + iter->windowsInfo_.clear(); + for (auto& windowNode: windowNodes) { + MMI::WindowInfo windowInfo = { + .id = static_cast(windowNode->GetWindowId()), + .pid = windowNode->GetCallingPid(), + .uid = windowNode->GetCallingUid(), + .topLeftX = windowNode->GetLayoutRects().rect_.posX_, + .topLeftY = windowNode->GetLayoutRects().rect_.posY_, + .width = static_cast(windowNode->GetLayoutRects().rect_.width_), + .height = static_cast(windowNode->GetLayoutRects().rect_.height_), + .displayId = windowNode->GetDisplayId(), + .agentWindowId = static_cast(windowNode->GetWindowId()), + }; + iter->windowsInfo_.emplace_back(windowInfo); + } +} +} +} \ No newline at end of file diff --git a/wmtest/wmserver/src/window_controller.cpp b/wmtest/wmserver/src/window_controller.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9f3dbe1ead73a03774e74706da4f41afca68733e --- /dev/null +++ b/wmtest/wmserver/src/window_controller.cpp @@ -0,0 +1,153 @@ +/* + * Copyright (c) 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 "window_controller.h" +#include +#include "window_manager_hilog.h" + +namespace OHOS { +namespace Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "WindowController"}; +} +uint32_t WindowController::GenWindowId() +{ + return ++windowId_; +} + +WMError WindowController::CreateWindow(sptr& window, sptr& property, + const std::shared_ptr& surfaceNode, uint32_t& windowId) +{ + windowId = GenWindowId(); + property->SetWindowId(windowId); + + sptr node = new WindowNode(property, window, surfaceNode); + return windowRoot_->SaveWindow(node); +} + +WMError WindowController::SaveAbilityToken(const sptr& abilityToken, uint32_t windowId) +{ + auto node = windowRoot_->GetWindowNode(windowId); + if (node == nullptr) { + WLOGFE("could not find window"); + return WMError::WM_ERROR_NULLPTR; + } + node->abilityToken_ = abilityToken; + return WMError::WM_OK; +} + +WMError WindowController::AddWindowNode(sptr& property) +{ + auto node = windowRoot_->GetWindowNode(property->GetWindowId()); + if (node == nullptr) { + WLOGFE("could not find window"); + return WMError::WM_ERROR_NULLPTR; + } + node->SetWindowProperty(property); + // TODO: check permission + // TODO: adjust property + + WMError res = windowRoot_->AddWindowNode(property->GetParentId(), node); + if (res != WMError::WM_OK) { + return res; + } + res = LayoutWindowNodeTrees(); + RSTransaction::FlushImplicitTransaction(); + WLOGFI("AddWindowNode FlushImplicitTransaction end"); + + if (node->GetWindowMode() == WindowMode::WINDOW_MODE_FULLSCREEN) { + WLOGFI("need minimize previous fullscreen window if exists"); + WMError res = windowRoot_->MinimizeOtherFullScreenAbility(node); + if (res != WMError::WM_OK) { + WLOGFE("Minimize other fullscreen window failed"); + } + } + return res; +} + +WMError WindowController::LayoutWindowNodeTrees() +{ + auto& windowContainerMap = windowRoot_->GetWindowNodeContainerMap(); + if (windowContainerMap.empty()) { + WLOGFE("could not find window container"); + return WMError::WM_ERROR_INVALID_PARAM; + } + for (auto& iter : windowContainerMap) { + const sptr& windowContainer = iter.second; + WMError ret = windowContainer->LayoutWindowNodes(); + if (ret != WMError::WM_OK) { + return ret; + } + } + return WMError::WM_OK; +} + +WMError WindowController::RemoveWindowNode(uint32_t windowId) +{ + WMError res = windowRoot_->RemoveWindowNode(windowId); + if (res != WMError::WM_OK) { + return res; + } + res = LayoutWindowNodeTrees(); + RSTransaction::FlushImplicitTransaction(); + WLOGFI("RemoveWindowNode FlushImplicitTransaction end"); + return res; +} + +WMError WindowController::DestroyWindow(uint32_t windowId) +{ + WMError res = windowRoot_->DestroyWindow(windowId); + if (res != WMError::WM_OK) { + return res; + } + res = LayoutWindowNodeTrees(); + RSTransaction::FlushImplicitTransaction(); + WLOGFI("DestroyWindow FlushImplicitTransaction end"); + return res; +} + +WMError WindowController::MoveTo(uint32_t windowId, int32_t x, int32_t y) +{ + auto node = windowRoot_->GetWindowNode(windowId); + if (node == nullptr) { + WLOGFE("could not find window"); + return WMError::WM_ERROR_NULLPTR; + } + Vector2f pos(x, y); + node->surfaceNode_->SetBoundsPosition(pos); + RSTransaction::FlushImplicitTransaction(); + WLOGFI("MoveTo FlushImplicitTransaction end"); + return WMError::WM_OK; +} + +WMError WindowController::Resize(uint32_t windowId, uint32_t width, uint32_t height) +{ + auto node = windowRoot_->GetWindowNode(windowId); + if (node == nullptr) { + WLOGFE("could not find window"); + return WMError::WM_ERROR_NULLPTR; + } + node->surfaceNode_->SetBoundsSize(width, height); + RSTransaction::FlushImplicitTransaction(); + WLOGFI("Resize FlushImplicitTransaction end"); + return WMError::WM_OK; +} + +WMError WindowController::RequestFocus(uint32_t windowId) +{ + return windowRoot_->RequestFocus(windowId); +} +} +} diff --git a/wmtest/wmserver/src/window_layout_policy.cpp b/wmtest/wmserver/src/window_layout_policy.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c90a5f030e760c1592fbb39b7276fb0ab9569b62 --- /dev/null +++ b/wmtest/wmserver/src/window_layout_policy.cpp @@ -0,0 +1,184 @@ +/* + * Copyright (c) 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 "window_layout_policy.h" +#include "window_manager_hilog.h" + +namespace OHOS { +namespace Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "WindowLayoutPolicy"}; +} + +WMError WindowLayoutPolicy::UpdateDisplayInfo(const Rect& displayRect) +{ + if (displayRect.height_ == 0 || displayRect.width_ == 0) { + return WMError::WM_ERROR_INVALID_PARAM; + } + displayRect_ = displayRect; + limitRect_ = displayRect; + aviodNodes_.clear(); + return WMError::WM_OK; +} + +WMError WindowLayoutPolicy::LayoutWindow(sptr& node) +{ + if (node->GetWindowType() >= WindowType::SYSTEM_WINDOW_END) { + WLOGFE("unknown window type!"); + return WMError::WM_ERROR_INVALID_PARAM; + } + UpdateLayoutRects(node); + if (aviodTypes_.find(node->GetWindowType()) != aviodTypes_.end()) { + RecordAvoidRect(node); + } + return WMError::WM_OK; +} + +bool WindowLayoutPolicy::IsRectChanged(const Rect& l, const Rect& r) +{ + return !((l.posX_ == r.posX_) && (l.posY_ == r.posY_) && (l.width_ == r.width_) && (l.height_ == r.height_)); +} + +bool WindowLayoutPolicy::UpdateLayoutRects(sptr& node) +{ + bool needAvoid = IsNeedAvoidNode(node); + bool fullScreen = IsFullScreenNode(node); + bool parentLimit = IsParentLimitNode(node); + bool subWindow = (node->GetWindowType() == WindowType::WINDOW_TYPE_APP_SUB_WINDOW); + bool floatingWindow = (node->GetWindowMode() == WindowMode::WINDOW_MODE_FLOATING); + WLOGFI("Id:%{public}d, avoid:%{public}d fullS:%{public}d parLimit:%{public}d float:%{public}d, types:%{public}d", + node->GetWindowId(), needAvoid, fullScreen, parentLimit, floatingWindow, + static_cast(node->GetWindowType())); + const LayoutRects& layoutRects = node->GetLayoutRects(); + Rect lastRect = layoutRects.rect_; + Rect dRect = layoutRects.displayRect_; + Rect pRect = layoutRects.parentRect_; + Rect lRect = layoutRects.limitRect_; + Rect winRect = node->GetWindowProperty()->GetWindowRect(); + + if (needAvoid) { + dRect = limitRect_; + } else { + dRect = displayRect_; + } + + if (subWindow) { + pRect = node->parent_->GetLayoutRects().rect_; + } else { + pRect = dRect; + } + + if (parentLimit) { + lRect = pRect; + } else { + lRect = dRect; + } + + if (fullScreen) { + winRect = lRect; + } else if (!floatingWindow) { + winRect.width_ = std::min(lRect.width_, winRect.width_); + winRect.height_ = std::min(lRect.height_, winRect.height_); + winRect.posX_ = std::max(lRect.posX_, winRect.posX_); + winRect.posY_ = std::max(lRect.posY_, winRect.posY_); + winRect.posX_ = std::min( + lRect.posX_ + static_cast(lRect.width_) - static_cast(winRect.width_), + winRect.posX_); + winRect.posY_ = std::min( + lRect.posY_ + static_cast(lRect.height_) - static_cast(winRect.height_), + winRect.posY_); + } + node->UpdateLayoutRects({ dRect, pRect, lRect, winRect }); + if (IsRectChanged(lastRect, winRect)) { + node->GetWindowToken()->UpdateWindowRect(winRect); + node->surfaceNode_->SetBounds(winRect.posX_, winRect.posY_, winRect.width_, winRect.height_); + WLOGFI("UpdateLayoutRects for winId: %{public}d, Rect: %{public}d %{public}d %{public}d %{public}d", + node->GetWindowId(), winRect.posX_, winRect.posY_, winRect.width_, winRect.height_); + return true; + } + WLOGFI("UpdateLayoutRects rect not changed for winId: %{public}d", node->GetWindowId()); + return false; +} + +void WindowLayoutPolicy::UpdateLimitRect(const sptr& node) +{ + auto& layoutRects = node->GetLayoutRects(); + if (node->GetWindowType() == WindowType::WINDOW_TYPE_STATUS_BAR) { // STATUS_BAR + int32_t boundTop = limitRect_.posY_; + int32_t rectBottom = layoutRects.rect_.posY_ + layoutRects.rect_.height_; + int32_t offsetH = rectBottom - boundTop; + limitRect_.posY_ += offsetH; + limitRect_.height_ -= offsetH; + } else if (node->GetWindowType() == WindowType::WINDOW_TYPE_NAVIGATION_BAR) { // NAVIGATION_BAR + int32_t boundBottom = limitRect_.posY_ + limitRect_.height_; + int32_t offsetH = boundBottom - layoutRects.rect_.posY_; + limitRect_.height_ -= offsetH; + } + WLOGFI("after add WinId: %{public}d, limitRect: %{public}d %{public}d %{public}d %{public}d", + node->GetWindowId(), limitRect_.posX_, limitRect_.posY_, limitRect_.width_, limitRect_.height_); +} + +void WindowLayoutPolicy::RecordAvoidRect(const sptr& node) +{ + uint32_t id = node->GetWindowId(); + if (aviodNodes_.find(id) == aviodNodes_.end()) { // new avoid rect + aviodNodes_.insert(std::pair>(id, node)); + UpdateLimitRect(node); + } else { // update existing avoid rect + limitRect_ = displayRect_; + aviodNodes_[id] = node; + for (auto item : aviodNodes_) { + UpdateLimitRect(item.second); + } + } +} + +bool WindowLayoutPolicy::IsNeedAvoidNode(const sptr& node) +{ + auto type = node->GetWindowType(); + auto mode = node->GetWindowMode(); + auto flags = node->GetWindowFlags(); + if (mode == WindowMode::WINDOW_MODE_FLOATING) { + return false; + } + if (type >= WindowType::APP_WINDOW_BASE && + type <= WindowType::APP_SUB_WINDOW_END && + (flags & static_cast(WindowFlag::WINDOW_FLAG_NEED_AVOID))) { + return true; + } + return false; +} + +bool WindowLayoutPolicy::IsFullScreenNode(const sptr& node) +{ + auto mode = node->GetWindowMode(); + if (mode == WindowMode::WINDOW_MODE_FULLSCREEN || mode == WindowMode::WINDOW_MODE_SPLIT) { + return true; + } + return false; +} + +bool WindowLayoutPolicy::IsParentLimitNode(const sptr& node) +{ + auto mode = node->GetWindowMode(); + auto flags = node->GetWindowFlags(); + if (mode != WindowMode::WINDOW_MODE_FLOATING && + (flags & static_cast(WindowFlag::WINDOW_FLAG_PARENT_LIMIT))) { + return true; + } + return false; +} +} +} diff --git a/wmtest/wmserver/src/window_manager_proxy.cpp b/wmtest/wmserver/src/window_manager_proxy.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f1f2da589e9d5dfbfddf5c866bbe454f542d8c45 --- /dev/null +++ b/wmtest/wmserver/src/window_manager_proxy.cpp @@ -0,0 +1,247 @@ +/* + * Copyright (c) 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 "window_manager_proxy.h" +#include +#include "window_manager_hilog.h" + +namespace OHOS { +namespace Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "WindowManagerProxy"}; +} + + +WMError WindowManagerProxy::CreateWindow(sptr& window, sptr& property, + const std::shared_ptr& surfaceNode, uint32_t& windowId) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!data.WriteInterfaceToken(GetDescriptor())) { + WLOGFE("WriteInterfaceToken failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + + if (!data.WriteRemoteObject(window->AsObject())) { + WLOGFE("Write IWindow failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + + if (!data.WriteParcelable(property.GetRefPtr())) { + WLOGFE("Write windowProperty failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + + if (!data.WriteParcelable(surfaceNode.get())) { + WLOGFE("Write windowProperty failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + + if (Remote()->SendRequest(TRANS_ID_CREATE_WINDOW, data, reply, option) != ERR_NONE) { + return WMError::WM_ERROR_IPC_FAILED; + } + windowId = reply.ReadUint32(); + int32_t ret = reply.ReadInt32(); + return static_cast(ret); +} + +WMError WindowManagerProxy::AddWindow(sptr& property) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!data.WriteInterfaceToken(GetDescriptor())) { + WLOGFE("WriteInterfaceToken failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + + if (!data.WriteParcelable(property.GetRefPtr())) { + WLOGFE("Write windowProperty failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + + if (Remote()->SendRequest(TRANS_ID_ADD_WINDOW, data, reply, option) != ERR_NONE) { + return WMError::WM_ERROR_IPC_FAILED; + } + + int32_t ret = reply.ReadInt32(); + return static_cast(ret); +} + +WMError WindowManagerProxy::RemoveWindow(uint32_t windowId) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!data.WriteInterfaceToken(GetDescriptor())) { + WLOGFE("WriteInterfaceToken failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + + if (!data.WriteUint32(windowId)) { + WLOGFE("Write windowId failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + + if (Remote()->SendRequest(TRANS_ID_REMOVE_WINDOW, data, reply, option) != ERR_NONE) { + return WMError::WM_ERROR_IPC_FAILED; + } + + int32_t ret = reply.ReadInt32(); + return static_cast(ret); +} + +WMError WindowManagerProxy::DestroyWindow(uint32_t windowId) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!data.WriteInterfaceToken(GetDescriptor())) { + WLOGFE("WriteInterfaceToken failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + + if (!data.WriteUint32(windowId)) { + WLOGFE("Write windowId failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + + if (Remote()->SendRequest(TRANS_ID_DESTROY_WINDOW, data, reply, option) != ERR_NONE) { + return WMError::WM_ERROR_IPC_FAILED; + } + + int32_t ret = reply.ReadInt32(); + return static_cast(ret); +} + +WMError WindowManagerProxy::MoveTo(uint32_t windowId, int32_t x, int32_t y) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!data.WriteInterfaceToken(GetDescriptor())) { + WLOGFE("WriteInterfaceToken failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + + if (!data.WriteUint32(windowId)) { + WLOGFE("Write windowId failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + + if (!data.WriteInt32(x)) { + WLOGFE("Write posX failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + + if (!data.WriteInt32(y)) { + WLOGFE("Write posY failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + + if (Remote()->SendRequest(TRANS_ID_MOVE, data, reply, option) != ERR_NONE) { + return WMError::WM_ERROR_IPC_FAILED; + } + + int32_t ret = reply.ReadInt32(); + return static_cast(ret); +} + +WMError WindowManagerProxy::Resize(uint32_t windowId, uint32_t width, uint32_t height) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!data.WriteInterfaceToken(GetDescriptor())) { + WLOGFE("WriteInterfaceToken failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + + if (!data.WriteUint32(windowId)) { + WLOGFE("Write windowId failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + + if (!data.WriteUint32(width)) { + WLOGFE("Write width failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + + if (!data.WriteUint32(height)) { + WLOGFE("Write height failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + + if (Remote()->SendRequest(TRANS_ID_RESIZE, data, reply, option) != ERR_NONE) { + return WMError::WM_ERROR_IPC_FAILED; + } + + int32_t ret = reply.ReadInt32(); + return static_cast(ret); +} + +WMError WindowManagerProxy::RequestFocus(uint32_t windowId) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!data.WriteInterfaceToken(GetDescriptor())) { + WLOGFE("WriteInterfaceToken failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + + if (!data.WriteUint32(windowId)) { + WLOGFE("Write windowId failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + if (Remote()->SendRequest(TRANS_ID_REQUEST_FOCUS, data, reply, option) != ERR_NONE) { + return WMError::WM_ERROR_IPC_FAILED; + } + + int32_t ret = reply.ReadInt32(); + return static_cast(ret); +} + +WMError WindowManagerProxy::SaveAbilityToken(const sptr& abilityToken, uint32_t windowId) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!data.WriteInterfaceToken(GetDescriptor())) { + WLOGFE("WriteInterfaceToken failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + + if (!data.WriteRemoteObject(abilityToken)) { + WLOGFE("Write abilityToken failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + + if (!data.WriteUint32(windowId)) { + WLOGFE("Write windowId failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + + if (Remote()->SendRequest(TRANS_ID_SEND_ABILITY_TOKEN, data, reply, option) != ERR_NONE) { + return WMError::WM_ERROR_IPC_FAILED; + } + + int32_t ret = reply.ReadInt32(); + return static_cast(ret); +} +} +} + diff --git a/wmtest/wmserver/src/window_manager_service.cpp b/wmtest/wmserver/src/window_manager_service.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7c70a580ba2556d99dc3417daa42011c34f95781 --- /dev/null +++ b/wmtest/wmserver/src/window_manager_service.cpp @@ -0,0 +1,134 @@ +/* + * Copyright (c) 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 "window_manager_service.h" + +#include + +#include +#include + +#include "window_manager_hilog.h" + +namespace OHOS { +namespace Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "WindowManagerService"}; +} + +IMPLEMENT_SINGLE_INSTANCE(WindowManagerService); + +const bool REGISTER_RESULT = SystemAbility::MakeAndRegisterAbility( + SingletonContainer::Get().GetRefPtr()); + +WindowManagerService::WindowManagerService() : SystemAbility(WINDOW_MANAGER_SERVICE_ID, true) +{ + windowRoot_ = new WindowRoot(); + windowController_ = new WindowController(windowRoot_); + inputWindowMonitor_ = new InputWindowMonitor(windowRoot_); +} + +void WindowManagerService::OnStart() +{ + WLOGFI("WindowManagerService::OnStart start"); + if (!Init()) { + return; + } +} + +bool WindowManagerService::Init() +{ + WLOGFI("WindowManagerService::Init start"); + bool ret = Publish(this); + if (!ret) { + WLOGFW("WindowManagerService::Init failed"); + return false; + } + WLOGFI("WindowManagerService::Init success"); + sleep(10); // for RS temporary + return true; +} + +void WindowManagerService::OnStop() +{ + WLOGFI("ready to stop service."); +} + +WMError WindowManagerService::CreateWindow(sptr& window, sptr& property, + const std::shared_ptr& surfaceNode, uint32_t& windowId) +{ + if (window == nullptr || property == nullptr || surfaceNode == nullptr) { + WLOGFE("window is invalid"); + return WMError::WM_ERROR_NULLPTR; + } + std::lock_guard lock(mutex_); + return windowController_->CreateWindow(window, property, surfaceNode, windowId); +} + +WMError WindowManagerService::AddWindow(sptr& property) +{ + std::lock_guard lock(mutex_); + WMError res = windowController_->AddWindowNode(property); + if (res == WMError::WM_OK) { + inputWindowMonitor_->UpdateInputWindow(property->GetWindowId()); + } + return res; +} + +WMError WindowManagerService::RemoveWindow(uint32_t windowId) +{ + std::lock_guard lock(mutex_); + WMError res = windowController_->RemoveWindowNode(windowId); + if (res == WMError::WM_OK) { + inputWindowMonitor_->UpdateInputWindow(windowId); + } + return res; +} + +WMError WindowManagerService::DestroyWindow(uint32_t windowId) +{ + std::lock_guard lock(mutex_); + WMError res = windowController_->DestroyWindow(windowId); + if (res == WMError::WM_OK) { + inputWindowMonitor_->UpdateInputWindow(windowId); + } + return res; +} + +WMError WindowManagerService::MoveTo(uint32_t windowId, int32_t x, int32_t y) +{ + std::lock_guard lock(mutex_); + return windowController_->MoveTo(windowId, x, y); +} + +WMError WindowManagerService::Resize(uint32_t windowId, uint32_t width, uint32_t height) +{ + std::lock_guard lock(mutex_); + return windowController_->Resize(windowId, width, height); +} + +WMError WindowManagerService::RequestFocus(uint32_t windowId) +{ + std::lock_guard lock(mutex_); + return windowController_->RequestFocus(windowId); +} + +WMError WindowManagerService::SaveAbilityToken(const sptr& abilityToken, uint32_t windowId) +{ + std::lock_guard lock(mutex_); + return windowController_->SaveAbilityToken(abilityToken, windowId); +} +} +} \ No newline at end of file diff --git a/wmtest/wmserver/src/window_manager_stub.cpp b/wmtest/wmserver/src/window_manager_stub.cpp new file mode 100644 index 0000000000000000000000000000000000000000..cd18fed9f453d28c2d7cf2daab8ce8e8780da4d1 --- /dev/null +++ b/wmtest/wmserver/src/window_manager_stub.cpp @@ -0,0 +1,101 @@ +/* + * Copyright (c) 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 "window_manager_stub.h" +#include +#include "window_manager_hilog.h" + +namespace OHOS { +namespace Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "WindowManagerStub"}; +} + +int32_t WindowManagerStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, + MessageOption &option) +{ + WLOGFI("WindowManagerStub::OnRemoteRequest code is %{public}d", code); + if (data.ReadInterfaceToken() != GetDescriptor()) { + WLOGFE("InterfaceToken check failed"); + return -1; + } + switch (code) { + case TRANS_ID_CREATE_WINDOW: { + sptr windowObject = data.ReadRemoteObject(); + sptr windowProxy = iface_cast(windowObject); + sptr windowProperty = data.ReadStrongParcelable(); + std::shared_ptr surfaceNode(data.ReadParcelable()); + uint32_t windowId; + WMError errCode = CreateWindow(windowProxy, windowProperty, surfaceNode, windowId); + reply.WriteUint32(windowId); + reply.WriteInt32(static_cast(errCode)); + break; + } + case TRANS_ID_ADD_WINDOW: { + sptr windowProperty = data.ReadStrongParcelable(); + WMError errCode = AddWindow(windowProperty); + reply.WriteInt32(static_cast(errCode)); + break; + } + case TRANS_ID_REMOVE_WINDOW: { + uint32_t windowId = data.ReadUint32(); + WMError errCode = RemoveWindow(windowId); + reply.WriteInt32(static_cast(errCode)); + break; + } + case TRANS_ID_DESTROY_WINDOW: { + uint32_t windowId = data.ReadUint32(); + WMError errCode = DestroyWindow(windowId); + reply.WriteInt32(static_cast(errCode)); + break; + } + case TRANS_ID_MOVE: { + uint32_t windowId = data.ReadUint32(); + int32_t x = data.ReadInt32(); + int32_t y = data.ReadInt32(); + WMError errCode = MoveTo(windowId, x, y); + reply.WriteInt32(static_cast(errCode)); + break; + } + case TRANS_ID_RESIZE: { + uint32_t windowId = data.ReadUint32(); + uint32_t width = data.ReadUint32(); + uint32_t height = data.ReadUint32(); + WMError errCode = Resize(windowId, width, height); + reply.WriteInt32(static_cast(errCode)); + break; + } + case TRANS_ID_REQUEST_FOCUS: { + uint32_t windowId = data.ReadUint32(); + WMError errCode = RequestFocus(windowId); + reply.WriteInt32(static_cast(errCode)); + break; + } + + case TRANS_ID_SEND_ABILITY_TOKEN: { + sptr abilityToken = data.ReadRemoteObject(); + uint32_t windowId = data.ReadUint32(); + WMError errCode = SaveAbilityToken(abilityToken, windowId); + reply.WriteInt32(static_cast(errCode)); + break; + } + default: + WLOGFW("unknown transaction code"); + return IPCObjectStub::OnRemoteRequest(code, data, reply, option); + } + return 0; +} +} +} diff --git a/wmtest/wmserver/src/window_node.cpp b/wmtest/wmserver/src/window_node.cpp new file mode 100644 index 0000000000000000000000000000000000000000..389d4f367782c55b13a7622c7f03a38459e66649 --- /dev/null +++ b/wmtest/wmserver/src/window_node.cpp @@ -0,0 +1,86 @@ +/* + * Copyright (c) 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 "window_node.h" +#include "window_manager_hilog.h" + +namespace OHOS { +namespace Rosen { +void WindowNode::SetDisplayId(int32_t displayId) +{ + property_->SetDisplayId(displayId); +} + +void WindowNode::UpdateLayoutRects(const LayoutRects& rects) +{ + layoutRects_ = rects; +} + +void WindowNode::SetWindowProperty(const sptr& property) +{ + property_ = property; +} + +const sptr& WindowNode::GetWindowToken() const +{ + return windowToken_; +} + +int32_t WindowNode::GetDisplayId() const +{ + return property_->GetDisplayId(); +} + +uint32_t WindowNode::GetWindowId() const +{ + return property_->GetWindowId(); +} + +const LayoutRects& WindowNode::GetLayoutRects() const +{ + return layoutRects_; +} + +WindowType WindowNode::GetWindowType() const +{ + return property_->GetWindowType(); +} + +WindowMode WindowNode::GetWindowMode() const +{ + return property_->GetWindowMode(); +} + +uint32_t WindowNode::GetWindowFlags() const +{ + return property_->GetWindowFlags(); +} + +const sptr& WindowNode::GetWindowProperty() const +{ + return property_; +} + +int32_t WindowNode::GetCallingPid() const +{ + return callingPid_; +} + +int32_t WindowNode::GetCallingUid() const +{ + return callingUid_; +} +} +} diff --git a/wmtest/wmserver/src/window_node_container.cpp b/wmtest/wmserver/src/window_node_container.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f4ed70a0c0ba6898056e4fe2075e8e8081495be3 --- /dev/null +++ b/wmtest/wmserver/src/window_node_container.cpp @@ -0,0 +1,366 @@ +/* + * Copyright (c) 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 "window_node_container.h" +#include +#include +#include "window_manager_hilog.h" + +namespace OHOS { +namespace Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "WindowNodeContainer"}; +} + +WindowNodeContainer::~WindowNodeContainer() +{ + Destroy(); +} + +WMError WindowNodeContainer::MinimizeOtherFullScreenAbility() +{ + if (appWindowNode_->children_.empty()) { + WLOGFI("no appWindowNode, return"); + return WMError::WM_OK; + } + for (auto iter = appWindowNode_->children_.begin(); iter < appWindowNode_->children_.end() - 1; ++iter) { + if ((*iter)->GetWindowMode() != WindowMode::WINDOW_MODE_FULLSCREEN) { + continue; + } + WLOGFI("find previous fullscreen window"); + if ((*iter)->abilityToken_ != nullptr) { + WLOGFI("notify ability to minimize"); + AAFwk::AbilityManagerClient::GetInstance()->MinimizeAbility((*iter)->abilityToken_); + } + } + return WMError::WM_OK; +} + +WMError WindowNodeContainer::AddWindowNode(sptr& node, sptr& parentNode) +{ + if (!node->surfaceNode_ || !displayNode_) { + WLOGFE("surface node or display node is nullptr!"); + return WMError::WM_ERROR_NULLPTR; + } + sptr root = FindRoot(node->GetWindowType()); + if (root == nullptr) { + WLOGFE("root window node is nullptr!"); + return WMError::WM_ERROR_NULLPTR; + } + node->requestedVisibility_ = true; + if (parentNode != nullptr) { // subwindow + if (parentNode->parent_ != root) { + WLOGFE("window type and parent window not match or try to add subwindow to subwindow, which is forbidden"); + return WMError::WM_ERROR_INVALID_PARAM; + } + node->currentVisibility_ = parentNode->currentVisibility_; + } else { // mainwindow + parentNode = root; + node->currentVisibility_ = true; + for (auto& child : node->children_) { + child->currentVisibility_ = child->requestedVisibility_; + } + } + node->parent_ = parentNode; + + UpdateWindowTree(node); + UpdateRSTree(node, true); + AssignZOrder(); + UpdateFocusWindow(); + WLOGFI("AddWindowNode windowId: %{public}d end", node->GetWindowId()); + return WMError::WM_OK; +} + +void WindowNodeContainer::UpdateWindowTree(sptr& node) +{ + node->priority_ = zorderPolicy_->GetWindowPriority(node->GetWindowType()); + auto parentNode = node->parent_; + auto position = parentNode->children_.end(); + for (auto iter = parentNode->children_.begin(); iter < parentNode->children_.end(); ++iter) { + if ((*iter)->priority_ > node->priority_) { + position = iter; + break; + } + } + parentNode->children_.insert(position, node); +} + +bool WindowNodeContainer::UpdateRSTree(sptr& node, bool isAdd) +{ + if (displayNode_ == nullptr) { + WLOGFE("displayNode_ is nullptr"); + return false; + } + if (isAdd) { + displayNode_->AddChild(node->surfaceNode_, -1); + for (auto& child : node->children_) { + if (child->currentVisibility_) { + displayNode_->AddChild(child->surfaceNode_, -1); + } + } + } else { + displayNode_->RemoveChild(node->surfaceNode_); + for (auto& child : node->children_) { + displayNode_->RemoveChild(child->surfaceNode_); + } + } + return true; +} + +WMError WindowNodeContainer::DestroyWindowNode(sptr& node, std::vector& windowIds) +{ + WMError ret = RemoveWindowNode(node); + if (ret != WMError::WM_OK) { + return ret; + } + node->surfaceNode_ = nullptr; + windowIds.push_back(node->GetWindowId()); + + for (auto& child : node->children_) { // destroy sub window if exists + windowIds.push_back(child->GetWindowId()); + child->parent_ = nullptr; + if (child->surfaceNode_ != nullptr && displayNode_ != nullptr) { + displayNode_->RemoveChild(child->surfaceNode_); + child->surfaceNode_ = nullptr; + } + } + node->children_.clear(); + WLOGFI("DestroyWindowNode windowId: %{public}d end", node->GetWindowId()); + return WMError::WM_OK; +} + +WMError WindowNodeContainer::LayoutWindowNodes() +{ + WMError ret = WMError::WM_OK; + layoutPolicy_->UpdateDisplayInfo(displayRect_); + std::vector> rootNodes = { aboveAppWindowNode_, appWindowNode_, belowAppWindowNode_ }; + for (auto& node : rootNodes) { // ensure that the avoid area windows are traversed first + ret = LayoutWindowNode(node); + if (ret != WMError::WM_OK) { + return ret; + } + } + return ret; +} + +WMError WindowNodeContainer::LayoutWindowNode(sptr& node) +{ + WMError ret = WMError::WM_OK; + if (node->parent_ != nullptr) { // isn't root node + ret = layoutPolicy_->LayoutWindow(node); + if (ret != WMError::WM_OK) { + return ret; + } + } + for (auto& childNode : node->children_) { + ret = LayoutWindowNode(childNode); + if (ret != WMError::WM_OK) { + return ret; + } + } + return ret; +} + +WMError WindowNodeContainer::RemoveWindowNode(sptr& node) +{ + if (node == nullptr || !node->surfaceNode_) { + WLOGFE("window node or surface node is nullptr, invalid"); + return WMError::WM_ERROR_DESTROYED_OBJECT; + } + + if (node->parent_ == nullptr) { + WLOGFW("can't find parent of this node"); + } else { + // remove this node from parent + auto iter = std::find(node->parent_->children_.begin(), node->parent_->children_.end(), node); + if (iter != node->parent_->children_.end()) { + node->parent_->children_.erase(iter); + } else { + WLOGFE("can't find this node in parent"); + } + node->parent_ = nullptr; + } + node->requestedVisibility_ = false; + node->currentVisibility_ = false; + for (auto& child : node->children_) { + child->currentVisibility_ = false; + } + UpdateRSTree(node, false); + UpdateFocusWindow(); + WLOGFI("RemoveWindowNode windowId: %{public}d end", node->GetWindowId()); + return WMError::WM_OK; +} + +const std::vector& WindowNodeContainer::Destroy() +{ + removedIds_.clear(); + for (auto& node : belowAppWindowNode_->children_) { + DestroyWindowNode(node, removedIds_); + } + for (auto& node : appWindowNode_->children_) { + DestroyWindowNode(node, removedIds_); + } + for (auto& node : aboveAppWindowNode_->children_) { + DestroyWindowNode(node, removedIds_); + } + displayNode_ = nullptr; + return removedIds_; +} + +sptr WindowNodeContainer::FindRoot(WindowType type) const +{ + if (type >= WindowType::APP_WINDOW_BASE && type <= WindowType::APP_SUB_WINDOW_END) { + return appWindowNode_; + } else if (type < WindowType::ABOVE_APP_SYSTEM_WINDOW_BASE) { + return belowAppWindowNode_; + } else { + return aboveAppWindowNode_; + } +} + +void WindowNodeContainer::UpdateFocusWindow() +{ + for (auto iter = appWindowNode_->children_.rbegin(); iter < appWindowNode_->children_.rend(); iter++) { + if ((*iter)->GetWindowProperty()->GetFocusable()) { + WLOGFI("find focused id %{public}d;", (*iter)->GetWindowId()); + SetFocusWindow((*iter)->GetWindowId()); + break; + } + } +} + +sptr WindowNodeContainer::FindWindowNodeById(uint32_t id) const +{ + std::vector> rootNodes = { aboveAppWindowNode_, appWindowNode_, belowAppWindowNode_ }; + for (auto& rootNode : rootNodes) { + for (auto& node : rootNode->children_) { + if (node->GetWindowId() == id) { + return node; + } + for (auto& subNode : node->children_) { + if (subNode->GetWindowId() == id) { + return subNode; + } + } + } + } + return nullptr; +} + +void WindowNodeContainer::UpdateFocusStatus(uint32_t id, bool focused) const +{ + auto node = FindWindowNodeById(id); + if (node == nullptr) { + WLOGFW("cannot find old focused window id:%{public}d", id); + } else { + node->GetWindowToken()->UpdateFocusStatus(focused); + } +} + +void WindowNodeContainer::AssignZOrder() +{ + zOrder_ = 0; + for (auto& node : belowAppWindowNode_->children_) { + AssignZOrder(node); + } + for (auto& node : appWindowNode_->children_) { + AssignZOrder(node); + } + for (auto& node : aboveAppWindowNode_->children_) { + AssignZOrder(node); + } +} + +void WindowNodeContainer::AssignZOrder(sptr& node) +{ + if (node == nullptr) { + return; + } + auto iter = node->children_.begin(); + for (; iter < node->children_.end(); ++iter) { + if ((*iter)->priority_ < 0) { + if ((*iter)->surfaceNode_) { + (*iter)->surfaceNode_->SetPositionZ(zOrder_); + WLOGFI("for subWindow id %{public}d; zOrder:%{public}d", (*iter)->GetWindowId(), zOrder_); + ++zOrder_; + } + } else { + break; + } + } + if (node->surfaceNode_) { + node->surfaceNode_->SetPositionZ(zOrder_); + WLOGFI("window id:%{public}d; zOrder:%{public}d", node->GetWindowId(), zOrder_); + ++zOrder_; + } + for (; iter < node->children_.end(); ++iter) { + if ((*iter)->surfaceNode_) { + (*iter)->surfaceNode_->SetPositionZ(zOrder_); + WLOGFI("for subWindow id %{public}d; zOrder:%{public}d", (*iter)->GetWindowId(), zOrder_); + ++zOrder_; + } + } +} + +WMError WindowNodeContainer::SetFocusWindow(uint32_t windowId) +{ + if (focusedWindow_ == windowId) { + return WMError::WM_OK; + } + UpdateFocusStatus(focusedWindow_, false); + focusedWindow_ = windowId; + UpdateFocusStatus(focusedWindow_, true); + return WMError::WM_OK; +} + +uint32_t WindowNodeContainer::GetFocusWindow() const +{ + return focusedWindow_; +} + +void WindowNodeContainer::TraverseContainer(std::vector>& windowNodes) +{ + for (auto& node : belowAppWindowNode_->children_) { + TraverseWindowNode(node, windowNodes); + } + for (auto& node : appWindowNode_->children_) { + TraverseWindowNode(node, windowNodes); + } + for (auto& node : aboveAppWindowNode_->children_) { + TraverseWindowNode(node, windowNodes); + } + std::reverse(windowNodes.begin(), windowNodes.end()); +} + +void WindowNodeContainer::TraverseWindowNode(sptr& node, std::vector>& windowNodes) +{ + if (node == nullptr) { + return; + } + auto iter = node->children_.begin(); + for (; iter < node->children_.end(); ++iter) { + if ((*iter)->priority_ < 0) { + windowNodes.emplace_back(*iter); + } else { + break; + } + } + windowNodes.emplace_back(node); + for (; iter < node->children_.end(); ++iter) { + windowNodes.emplace_back(*iter); + } +} +} +} diff --git a/wmtest/wmserver/src/window_root.cpp b/wmtest/wmserver/src/window_root.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ac626427923ab10c2b54dcf0e55686fcff4ca5d5 --- /dev/null +++ b/wmtest/wmserver/src/window_root.cpp @@ -0,0 +1,219 @@ +/* + * Copyright (c) 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 "window_root.h" +#include "display_manager_service_inner.h" +#include "window_manager_hilog.h" + +namespace OHOS { +namespace Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "WindowRoot"}; +} +sptr WindowRoot::GetOrCreateWindowNodeContainer(int32_t displayId) +{ + auto iter = windowNodeContainerMap_.find(displayId); + if (iter != windowNodeContainerMap_.end()) { + return iter->second; + } + auto displayScreen = DisplayManagerServiceInner::GetInstance()->GetDisplayById(displayId); + if (displayScreen == nullptr) { + WLOGFE("get display failed displayId:%{public}d", displayId); + return nullptr; + } + WLOGFI("create new window node container display width:%{public}d, height:%{public}d, screenId:%{public}llu", + displayScreen->GetWidth(), displayScreen->GetHeight(), displayScreen->GetId()); + sptr container = new WindowNodeContainer(displayScreen->GetId(), + static_cast(displayScreen->GetWidth()), static_cast(displayScreen->GetHeight())); + windowNodeContainerMap_.insert({ displayId, container }); + return container; +} + +const std::map>& WindowRoot::GetWindowNodeContainerMap() const +{ + return windowNodeContainerMap_; +} + +void WindowRoot::NotifyDisplayRemoved(int32_t displayId) +{ + auto container = GetOrCreateWindowNodeContainer(displayId); + if (container == nullptr) { + WLOGFI("this display does not have any window"); + return; + } + std::vector windowIds = container->Destroy(); + for (auto id : windowIds) { + auto node = GetWindowNode(id); + DestroyWindowInner(node); + } + windowNodeContainerMap_.erase(displayId); +} + +sptr WindowRoot::GetWindowNode(uint32_t windowId) const +{ + auto iter = windowNodeMap_.find(windowId); + if (iter == windowNodeMap_.end()) { + WLOGFE("window node could not be found"); + return nullptr; + } + return iter->second; +} + +WMError WindowRoot::SaveWindow(const sptr& node) +{ + if (node == nullptr) { + WLOGFE("add window failed, node is nullptr"); + return WMError::WM_ERROR_NULLPTR; + } + WLOGFI("save windowId %{public}d", node->GetWindowId()); + windowNodeMap_.insert({ node->GetWindowId(), node }); + auto remoteObject = node->GetWindowToken()->AsObject(); + windowIdMap_.insert({ remoteObject, node->GetWindowId() }); + + if (windowDeath_ == nullptr) { + WLOGFI("failed to create death Recipient ptr WindowDeathRecipient"); + } + if (!remoteObject->AddDeathRecipient(windowDeath_)) { + WLOGFI("failed to add death recipient"); + } + return WMError::WM_OK; +} + +WMError WindowRoot::MinimizeOtherFullScreenAbility(sptr& node) +{ + auto container = GetOrCreateWindowNodeContainer(node->GetDisplayId()); + if (container == nullptr) { + WLOGFE("MinimizeAbility failed, window container could not be found"); + return WMError::WM_ERROR_NULLPTR; + } + return container->MinimizeOtherFullScreenAbility(); +} + +WMError WindowRoot::AddWindowNode(uint32_t parentId, sptr& node) +{ + if (node == nullptr) { + WLOGFE("add window failed, node is nullptr"); + return WMError::WM_ERROR_NULLPTR; + } + auto parentNode = GetWindowNode(parentId); + + auto container = GetOrCreateWindowNodeContainer(node->GetDisplayId()); + if (container == nullptr) { + WLOGFE("add window failed, window container could not be found"); + return WMError::WM_ERROR_NULLPTR; + } + + return container->AddWindowNode(node, parentNode); +} + +WMError WindowRoot::RemoveWindowNode(uint32_t windowId) +{ + auto node = GetWindowNode(windowId); + if (node == nullptr) { + WLOGFE("could not find window"); + return WMError::WM_ERROR_NULLPTR; + } + auto container = GetOrCreateWindowNodeContainer(node->GetDisplayId()); + if (container == nullptr) { + WLOGFE("add window failed, window container could not be found"); + return WMError::WM_ERROR_NULLPTR; + } + return container->RemoveWindowNode(node); +} + +WMError WindowRoot::DestroyWindow(uint32_t windowId) +{ + auto node = GetWindowNode(windowId); + if (node == nullptr) { + return WMError::WM_ERROR_DESTROYED_OBJECT; + } + WMError res; + auto container = GetOrCreateWindowNodeContainer(node->GetDisplayId()); + if (container != nullptr) { + std::vector windowIds; + res = container->DestroyWindowNode(node, windowIds); + for (auto id : windowIds) { + node = GetWindowNode(id); + DestroyWindowInner(node); + } + return res; + } + res = DestroyWindowInner(node); + WLOGFI("destroy window failed, window container could not be found"); + return res; +} + +WMError WindowRoot::DestroyWindowInner(sptr& node) +{ + if (node == nullptr) { + WLOGFE("window has been destroyed"); + return WMError::WM_ERROR_DESTROYED_OBJECT; + } + sptr window = node->GetWindowToken(); + if (windowIdMap_.count(window->AsObject()) == 0) { + WLOGFI("window remote object has been destroyed"); + return WMError::WM_ERROR_DESTROYED_OBJECT; + } + + if (window->AsObject() != nullptr) { + window->AsObject()->RemoveDeathRecipient(windowDeath_); + } + windowIdMap_.erase(window->AsObject()); + windowNodeMap_.erase(node->GetWindowId()); + return WMError::WM_OK; +} + +WMError WindowRoot::RequestFocus(uint32_t windowId) +{ + auto node = GetWindowNode(windowId); + if (node == nullptr) { + WLOGFE("could not find window"); + return WMError::WM_ERROR_NULLPTR; + } + auto container = GetOrCreateWindowNodeContainer(node->GetDisplayId()); + if (container == nullptr) { + WLOGFE("window container could not be found"); + return WMError::WM_ERROR_NULLPTR; + } + return container->SetFocusWindow(windowId); +} + +void WindowRoot::ClearWindow(const sptr& remoteObject) +{ + auto iter = windowIdMap_.find(remoteObject); + if (iter == windowIdMap_.end()) { + WLOGFE("window id could not be found"); + return; + } + uint32_t windowId = iter->second; + DestroyWindow(windowId); +} + +void WindowDeathRecipient::OnRemoteDied(const wptr& wptrDeath) +{ + if (wptrDeath == nullptr) { + WLOGFE("wptrDeath is null"); + return; + } + + sptr object = wptrDeath.promote(); + if (!object) { + WLOGFE("object is null"); + return; + } + callback_(object); +} +} +} diff --git a/wmtest/wmserver/src/window_zorder_policy.cpp b/wmtest/wmserver/src/window_zorder_policy.cpp new file mode 100644 index 0000000000000000000000000000000000000000..1a41d6fb18aaff3f0dc09c8b4acc582df2834f3d --- /dev/null +++ b/wmtest/wmserver/src/window_zorder_policy.cpp @@ -0,0 +1,34 @@ +/* + * Copyright (c) 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 "window_manager_hilog.h" +#include "window_zorder_policy.h" + +namespace OHOS { +namespace Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "WindowZorderPolicy"}; +} + +int32_t WindowZorderPolicy::GetWindowPriority(WindowType type) const +{ + if (windowPriorityMap_.count(type) == 0) { + WLOGFE("invalid window type"); + return windowPriorityMap_.at(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW); + } + return windowPriorityMap_.at(type); +} +} +} \ No newline at end of file