mirror of
https://github.com/openharmony/windowmanager.git
synced 2026-07-21 04:25:28 -04:00
Merge branch 'master' of gitee.com:openharmony/windowmanager
Change-Id: I7834f863ae9dfe8413979ee146e915a8b329677c
This commit is contained in:
@@ -62,6 +62,7 @@ Note:If the text contains special characters, please escape them according to th
|
||||
<filteritem type="filename" name="*.cfg" desc="cfg no need to add policy"/>
|
||||
</filefilter>
|
||||
<filefilter name="binaryFileTypePolicyFilter" desc="Filters for binary file policies" >
|
||||
<filteritem type="filepath" name="figures/.*" desc="Self-developed image"/>
|
||||
<filteritem type="filepath" name=".*.db" desc="Database data file used for test case execution."/>
|
||||
</filefilter>
|
||||
</filefilterlist>
|
||||
|
||||
@@ -1,715 +0,0 @@
|
||||
# WidnowManager<a name="EN-US_TOPIC_0000001105482134"></a>
|
||||
|
||||
- [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<a name="section1333751883213"></a>
|
||||
|
||||
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.
|
||||
|
||||

|
||||
|
||||
- Surface
|
||||
|
||||
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<a name="section1882912343"></a>
|
||||
|
||||
```
|
||||
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<a name="section68982123611"></a>
|
||||
|
||||
- Language version: C++ 11 or later
|
||||
|
||||
## Compilation and Building<a name="section671864110372"></a>
|
||||
|
||||
The dependent APIs include the following:
|
||||
|
||||
- graphic\_standard:libwms\_client
|
||||
- graphic\_standard:libsurface
|
||||
- graphic\_standard:libvsync\_client
|
||||
|
||||
## Available APIs<a name="section197399520386"></a>
|
||||
|
||||
### WindowManager<a name="section5851104093816"></a>
|
||||
|
||||
<a name="table119mcpsimp"></a>
|
||||
<table><thead align="left"><tr id="row124mcpsimp"><th class="cellrowborder" valign="top" width="37%" id="mcps1.1.3.1.1"><p id="p126mcpsimp"><a name="p126mcpsimp"></a><a name="p126mcpsimp"></a><strong id="b193946358456"><a name="b193946358456"></a><a name="b193946358456"></a>API</strong></p>
|
||||
</th>
|
||||
<th class="cellrowborder" valign="top" width="63%" id="mcps1.1.3.1.2"><p id="p129mcpsimp"><a name="p129mcpsimp"></a><a name="p129mcpsimp"></a><strong id="b128701367459"><a name="b128701367459"></a><a name="b128701367459"></a>Description</strong></p>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody><tr id="row132mcpsimp"><td class="cellrowborder" valign="top" width="37%" headers="mcps1.1.3.1.1 "><p id="p134mcpsimp"><a name="p134mcpsimp"></a><a name="p134mcpsimp"></a>GetInstance</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="63%" headers="mcps1.1.3.1.2 "><p id="p136mcpsimp"><a name="p136mcpsimp"></a><a name="p136mcpsimp"></a>Obtains the pointer to a singleton <strong id="b18411195111456"><a name="b18411195111456"></a><a name="b18411195111456"></a>WindowManager</strong> instance.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row137mcpsimp"><td class="cellrowborder" valign="top" width="37%" headers="mcps1.1.3.1.1 "><p id="p139mcpsimp"><a name="p139mcpsimp"></a><a name="p139mcpsimp"></a>GetMaxWidth</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="63%" headers="mcps1.1.3.1.2 "><p id="p141mcpsimp"><a name="p141mcpsimp"></a><a name="p141mcpsimp"></a>Obtains the width of the screen.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row142mcpsimp"><td class="cellrowborder" valign="top" width="37%" headers="mcps1.1.3.1.1 "><p id="p144mcpsimp"><a name="p144mcpsimp"></a><a name="p144mcpsimp"></a>GetMaxHeight</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="63%" headers="mcps1.1.3.1.2 "><p id="p146mcpsimp"><a name="p146mcpsimp"></a><a name="p146mcpsimp"></a>Obtains the height of the screen.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row147mcpsimp"><td class="cellrowborder" valign="top" width="37%" headers="mcps1.1.3.1.1 "><p id="p149mcpsimp"><a name="p149mcpsimp"></a><a name="p149mcpsimp"></a>CreateWindow</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="63%" headers="mcps1.1.3.1.2 "><p id="p151mcpsimp"><a name="p151mcpsimp"></a><a name="p151mcpsimp"></a>Creates a standard window.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row152mcpsimp"><td class="cellrowborder" valign="top" width="37%" headers="mcps1.1.3.1.1 "><p id="p154mcpsimp"><a name="p154mcpsimp"></a><a name="p154mcpsimp"></a>CreateSubWindow</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="63%" headers="mcps1.1.3.1.2 "><p id="p156mcpsimp"><a name="p156mcpsimp"></a><a name="p156mcpsimp"></a>Creates a child window.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row157mcpsimp"><td class="cellrowborder" valign="top" width="37%" headers="mcps1.1.3.1.1 "><p id="p159mcpsimp"><a name="p159mcpsimp"></a><a name="p159mcpsimp"></a>StartShotScreen</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="63%" headers="mcps1.1.3.1.2 "><p id="p161mcpsimp"><a name="p161mcpsimp"></a><a name="p161mcpsimp"></a>Takes a screenshot.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row162mcpsimp"><td class="cellrowborder" valign="top" width="37%" headers="mcps1.1.3.1.1 "><p id="p164mcpsimp"><a name="p164mcpsimp"></a><a name="p164mcpsimp"></a>StartShotWindow</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="63%" headers="mcps1.1.3.1.2 "><p id="p166mcpsimp"><a name="p166mcpsimp"></a><a name="p166mcpsimp"></a>Captures a window.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row167mcpsimp"><td class="cellrowborder" valign="top" width="37%" headers="mcps1.1.3.1.1 "><p id="p169mcpsimp"><a name="p169mcpsimp"></a><a name="p169mcpsimp"></a>SwitchTop</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="63%" headers="mcps1.1.3.1.2 "><p id="p171mcpsimp"><a name="p171mcpsimp"></a><a name="p171mcpsimp"></a>Moves the specified window to the top.</p>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
### Window<a name="section3483122273912"></a>
|
||||
|
||||
<a name="table173mcpsimp"></a>
|
||||
<table><thead align="left"><tr id="row178mcpsimp"><th class="cellrowborder" valign="top" width="48%" id="mcps1.1.3.1.1"><p id="p180mcpsimp"><a name="p180mcpsimp"></a><a name="p180mcpsimp"></a><strong id="b1734339115416"><a name="b1734339115416"></a><a name="b1734339115416"></a>API</strong></p>
|
||||
</th>
|
||||
<th class="cellrowborder" valign="top" width="52%" id="mcps1.1.3.1.2"><p id="p183mcpsimp"><a name="p183mcpsimp"></a><a name="p183mcpsimp"></a><strong id="b660764018548"><a name="b660764018548"></a><a name="b660764018548"></a>Description</strong></p>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody><tr id="row186mcpsimp"><td class="cellrowborder" valign="top" width="48%" headers="mcps1.1.3.1.1 "><p id="p188mcpsimp"><a name="p188mcpsimp"></a><a name="p188mcpsimp"></a>Show</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="52%" headers="mcps1.1.3.1.2 "><p id="p190mcpsimp"><a name="p190mcpsimp"></a><a name="p190mcpsimp"></a>Displays the current window.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row191mcpsimp"><td class="cellrowborder" valign="top" width="48%" headers="mcps1.1.3.1.1 "><p id="p193mcpsimp"><a name="p193mcpsimp"></a><a name="p193mcpsimp"></a>Hide</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="52%" headers="mcps1.1.3.1.2 "><p id="p195mcpsimp"><a name="p195mcpsimp"></a><a name="p195mcpsimp"></a>Hides the current window.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row196mcpsimp"><td class="cellrowborder" valign="top" width="48%" headers="mcps1.1.3.1.1 "><p id="p198mcpsimp"><a name="p198mcpsimp"></a><a name="p198mcpsimp"></a>Move</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="52%" headers="mcps1.1.3.1.2 "><p id="p200mcpsimp"><a name="p200mcpsimp"></a><a name="p200mcpsimp"></a>Moves the current window to a specified position.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row201mcpsimp"><td class="cellrowborder" valign="top" width="48%" headers="mcps1.1.3.1.1 "><p id="p203mcpsimp"><a name="p203mcpsimp"></a><a name="p203mcpsimp"></a>SwitchTop</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="52%" headers="mcps1.1.3.1.2 "><p id="p205mcpsimp"><a name="p205mcpsimp"></a><a name="p205mcpsimp"></a>Moves the current window to the top.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row206mcpsimp"><td class="cellrowborder" valign="top" width="48%" headers="mcps1.1.3.1.1 "><p id="p208mcpsimp"><a name="p208mcpsimp"></a><a name="p208mcpsimp"></a>ChangeWindowType</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="52%" headers="mcps1.1.3.1.2 "><p id="p210mcpsimp"><a name="p210mcpsimp"></a><a name="p210mcpsimp"></a>Changes the type of the current window.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row211mcpsimp"><td class="cellrowborder" valign="top" width="48%" headers="mcps1.1.3.1.1 "><p id="p213mcpsimp"><a name="p213mcpsimp"></a><a name="p213mcpsimp"></a>ReSize</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="52%" headers="mcps1.1.3.1.2 "><p id="p215mcpsimp"><a name="p215mcpsimp"></a><a name="p215mcpsimp"></a>Resizes the current window.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row216mcpsimp"><td class="cellrowborder" valign="top" width="48%" headers="mcps1.1.3.1.1 "><p id="p218mcpsimp"><a name="p218mcpsimp"></a><a name="p218mcpsimp"></a>Rotate</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="52%" headers="mcps1.1.3.1.2 "><p id="p220mcpsimp"><a name="p220mcpsimp"></a><a name="p220mcpsimp"></a>Rotates the current window.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row221mcpsimp"><td class="cellrowborder" valign="top" width="48%" headers="mcps1.1.3.1.1 "><p id="p223mcpsimp"><a name="p223mcpsimp"></a><a name="p223mcpsimp"></a>RegistPointerButtonCb</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="52%" headers="mcps1.1.3.1.2 "><p id="p225mcpsimp"><a name="p225mcpsimp"></a><a name="p225mcpsimp"></a>Registers the callback for Button events of the mouse.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row226mcpsimp"><td class="cellrowborder" valign="top" width="48%" headers="mcps1.1.3.1.1 "><p id="p228mcpsimp"><a name="p228mcpsimp"></a><a name="p228mcpsimp"></a>RegistPointerEnterCb</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="52%" headers="mcps1.1.3.1.2 "><p id="p230mcpsimp"><a name="p230mcpsimp"></a><a name="p230mcpsimp"></a>Registers the callback for Enter events of the mouse.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row231mcpsimp"><td class="cellrowborder" valign="top" width="48%" headers="mcps1.1.3.1.1 "><p id="p233mcpsimp"><a name="p233mcpsimp"></a><a name="p233mcpsimp"></a>RegistPointerLeaveCb</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="52%" headers="mcps1.1.3.1.2 "><p id="p235mcpsimp"><a name="p235mcpsimp"></a><a name="p235mcpsimp"></a>Registers the callback for Leave events of the mouse.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row236mcpsimp"><td class="cellrowborder" valign="top" width="48%" headers="mcps1.1.3.1.1 "><p id="p238mcpsimp"><a name="p238mcpsimp"></a><a name="p238mcpsimp"></a>RegistPointerMotionCb</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="52%" headers="mcps1.1.3.1.2 "><p id="p240mcpsimp"><a name="p240mcpsimp"></a><a name="p240mcpsimp"></a>Registers the callback for Motion events of the mouse.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row241mcpsimp"><td class="cellrowborder" valign="top" width="48%" headers="mcps1.1.3.1.1 "><p id="p243mcpsimp"><a name="p243mcpsimp"></a><a name="p243mcpsimp"></a>RegistPointerAxisDiscreteCb</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="52%" headers="mcps1.1.3.1.2 "><p id="p245mcpsimp"><a name="p245mcpsimp"></a><a name="p245mcpsimp"></a>Registers the callback for AxisDiscrete events of the mouse.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row246mcpsimp"><td class="cellrowborder" valign="top" width="48%" headers="mcps1.1.3.1.1 "><p id="p248mcpsimp"><a name="p248mcpsimp"></a><a name="p248mcpsimp"></a>RegistPointerAxisSourceCb</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="52%" headers="mcps1.1.3.1.2 "><p id="p250mcpsimp"><a name="p250mcpsimp"></a><a name="p250mcpsimp"></a>Registers the callback for AxisSource events of the mouse.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row251mcpsimp"><td class="cellrowborder" valign="top" width="48%" headers="mcps1.1.3.1.1 "><p id="p253mcpsimp"><a name="p253mcpsimp"></a><a name="p253mcpsimp"></a>RegistPointerAxisStopCb</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="52%" headers="mcps1.1.3.1.2 "><p id="p255mcpsimp"><a name="p255mcpsimp"></a><a name="p255mcpsimp"></a>Registers the callback for AxisStop events of the mouse.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row256mcpsimp"><td class="cellrowborder" valign="top" width="48%" headers="mcps1.1.3.1.1 "><p id="p258mcpsimp"><a name="p258mcpsimp"></a><a name="p258mcpsimp"></a>RegistPointerAxisCb</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="52%" headers="mcps1.1.3.1.2 "><p id="p260mcpsimp"><a name="p260mcpsimp"></a><a name="p260mcpsimp"></a>Registers the callback for Axis events of the mouse.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row261mcpsimp"><td class="cellrowborder" valign="top" width="48%" headers="mcps1.1.3.1.1 "><p id="p263mcpsimp"><a name="p263mcpsimp"></a><a name="p263mcpsimp"></a>RegistTouchUpCb</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="52%" headers="mcps1.1.3.1.2 "><p id="p265mcpsimp"><a name="p265mcpsimp"></a><a name="p265mcpsimp"></a>Registers the callback for TouchUp events.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row266mcpsimp"><td class="cellrowborder" valign="top" width="48%" headers="mcps1.1.3.1.1 "><p id="p268mcpsimp"><a name="p268mcpsimp"></a><a name="p268mcpsimp"></a>RegistTouchDownCb</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="52%" headers="mcps1.1.3.1.2 "><p id="p270mcpsimp"><a name="p270mcpsimp"></a><a name="p270mcpsimp"></a>Registers the callback for TouchDown events.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row271mcpsimp"><td class="cellrowborder" valign="top" width="48%" headers="mcps1.1.3.1.1 "><p id="p273mcpsimp"><a name="p273mcpsimp"></a><a name="p273mcpsimp"></a>RegistTouchEmotionCb</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="52%" headers="mcps1.1.3.1.2 "><p id="p275mcpsimp"><a name="p275mcpsimp"></a><a name="p275mcpsimp"></a>Registers the callback for TouchEmotion events.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row276mcpsimp"><td class="cellrowborder" valign="top" width="48%" headers="mcps1.1.3.1.1 "><p id="p278mcpsimp"><a name="p278mcpsimp"></a><a name="p278mcpsimp"></a>RegistTouchFrameCb</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="52%" headers="mcps1.1.3.1.2 "><p id="p280mcpsimp"><a name="p280mcpsimp"></a><a name="p280mcpsimp"></a>Registers the callback for TouchFrame events.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row281mcpsimp"><td class="cellrowborder" valign="top" width="48%" headers="mcps1.1.3.1.1 "><p id="p283mcpsimp"><a name="p283mcpsimp"></a><a name="p283mcpsimp"></a>RegistTouchCancelCb</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="52%" headers="mcps1.1.3.1.2 "><p id="p285mcpsimp"><a name="p285mcpsimp"></a><a name="p285mcpsimp"></a>Registers the callback for TouchCancel events.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row286mcpsimp"><td class="cellrowborder" valign="top" width="48%" headers="mcps1.1.3.1.1 "><p id="p288mcpsimp"><a name="p288mcpsimp"></a><a name="p288mcpsimp"></a>RegistTouchShapeCb</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="52%" headers="mcps1.1.3.1.2 "><p id="p290mcpsimp"><a name="p290mcpsimp"></a><a name="p290mcpsimp"></a>Registers the callback for TouchShape events.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row291mcpsimp"><td class="cellrowborder" valign="top" width="48%" headers="mcps1.1.3.1.1 "><p id="p293mcpsimp"><a name="p293mcpsimp"></a><a name="p293mcpsimp"></a>RegistTouchOrientationCb</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="52%" headers="mcps1.1.3.1.2 "><p id="p295mcpsimp"><a name="p295mcpsimp"></a><a name="p295mcpsimp"></a>Registers the callback for TouchOrientation events.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row296mcpsimp"><td class="cellrowborder" valign="top" width="48%" headers="mcps1.1.3.1.1 "><p id="p298mcpsimp"><a name="p298mcpsimp"></a><a name="p298mcpsimp"></a>RegistKeyboardKeyCb</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="52%" headers="mcps1.1.3.1.2 "><p id="p300mcpsimp"><a name="p300mcpsimp"></a><a name="p300mcpsimp"></a>Registers the callback for Key events of the keyboard.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row301mcpsimp"><td class="cellrowborder" valign="top" width="48%" headers="mcps1.1.3.1.1 "><p id="p303mcpsimp"><a name="p303mcpsimp"></a><a name="p303mcpsimp"></a>RegistKeyboardKeyMapCb</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="52%" headers="mcps1.1.3.1.2 "><p id="p305mcpsimp"><a name="p305mcpsimp"></a><a name="p305mcpsimp"></a>Registers the callback for KeyMap events of the keyboard.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row306mcpsimp"><td class="cellrowborder" valign="top" width="48%" headers="mcps1.1.3.1.1 "><p id="p308mcpsimp"><a name="p308mcpsimp"></a><a name="p308mcpsimp"></a>RegistKeyboardLeaveCb</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="52%" headers="mcps1.1.3.1.2 "><p id="p310mcpsimp"><a name="p310mcpsimp"></a><a name="p310mcpsimp"></a>Registers the callback for Leave events of the keyboard.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row311mcpsimp"><td class="cellrowborder" valign="top" width="48%" headers="mcps1.1.3.1.1 "><p id="p313mcpsimp"><a name="p313mcpsimp"></a><a name="p313mcpsimp"></a>RegistKeyboardEnterCb</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="52%" headers="mcps1.1.3.1.2 "><p id="p315mcpsimp"><a name="p315mcpsimp"></a><a name="p315mcpsimp"></a>Registers the callback for Enter events of the keyboard.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row316mcpsimp"><td class="cellrowborder" valign="top" width="48%" headers="mcps1.1.3.1.1 "><p id="p318mcpsimp"><a name="p318mcpsimp"></a><a name="p318mcpsimp"></a>RegistKeyboardRepeatInfoCb</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="52%" headers="mcps1.1.3.1.2 "><p id="p320mcpsimp"><a name="p320mcpsimp"></a><a name="p320mcpsimp"></a>Registers the callback for RepeatInfo events of the keyboard.</p>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
### SubWindow<a name="section96481249183913"></a>
|
||||
|
||||
<a name="table322mcpsimp"></a>
|
||||
<table><thead align="left"><tr id="row327mcpsimp"><th class="cellrowborder" valign="top" width="49%" id="mcps1.1.3.1.1"><p id="p329mcpsimp"><a name="p329mcpsimp"></a><a name="p329mcpsimp"></a><strong id="b131086571302"><a name="b131086571302"></a><a name="b131086571302"></a>API</strong></p>
|
||||
</th>
|
||||
<th class="cellrowborder" valign="top" width="51%" id="mcps1.1.3.1.2"><p id="p332mcpsimp"><a name="p332mcpsimp"></a><a name="p332mcpsimp"></a><strong id="b041313581403"><a name="b041313581403"></a><a name="b041313581403"></a>Description</strong></p>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody><tr id="row335mcpsimp"><td class="cellrowborder" valign="top" width="49%" headers="mcps1.1.3.1.1 "><p id="p337mcpsimp"><a name="p337mcpsimp"></a><a name="p337mcpsimp"></a>Move</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="51%" headers="mcps1.1.3.1.2 "><p id="p339mcpsimp"><a name="p339mcpsimp"></a><a name="p339mcpsimp"></a>Moves the current child window.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row340mcpsimp"><td class="cellrowborder" valign="top" width="49%" headers="mcps1.1.3.1.1 "><p id="p342mcpsimp"><a name="p342mcpsimp"></a><a name="p342mcpsimp"></a>SetSubWindowSize</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="51%" headers="mcps1.1.3.1.2 "><p id="p344mcpsimp"><a name="p344mcpsimp"></a><a name="p344mcpsimp"></a>Sets the size of the current child window.</p>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
### Surface<a name="section12366161544010"></a>
|
||||
|
||||
<a name="table346mcpsimp"></a>
|
||||
<table><thead align="left"><tr id="row351mcpsimp"><th class="cellrowborder" valign="top" width="41%" id="mcps1.1.3.1.1"><p id="p353mcpsimp"><a name="p353mcpsimp"></a><a name="p353mcpsimp"></a><strong id="b8875439216"><a name="b8875439216"></a><a name="b8875439216"></a>API</strong></p>
|
||||
</th>
|
||||
<th class="cellrowborder" valign="top" width="59%" id="mcps1.1.3.1.2"><p id="p356mcpsimp"><a name="p356mcpsimp"></a><a name="p356mcpsimp"></a><strong id="b14608174222"><a name="b14608174222"></a><a name="b14608174222"></a>Description</strong></p>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody><tr id="row359mcpsimp"><td class="cellrowborder" valign="top" width="41%" headers="mcps1.1.3.1.1 "><p id="p361mcpsimp"><a name="p361mcpsimp"></a><a name="p361mcpsimp"></a>CreateSurfaceAsConsumer</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="59%" headers="mcps1.1.3.1.2 "><p id="p363mcpsimp"><a name="p363mcpsimp"></a><a name="p363mcpsimp"></a>Creates a surface for the buffer consumer.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row364mcpsimp"><td class="cellrowborder" valign="top" width="41%" headers="mcps1.1.3.1.1 "><p id="p366mcpsimp"><a name="p366mcpsimp"></a><a name="p366mcpsimp"></a>CreateSurfaceAsProducer</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="59%" headers="mcps1.1.3.1.2 "><p id="p368mcpsimp"><a name="p368mcpsimp"></a><a name="p368mcpsimp"></a>Creates a surface for the buffer producer. Only production-related APIs can be used.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row369mcpsimp"><td class="cellrowborder" valign="top" width="41%" headers="mcps1.1.3.1.1 "><p id="p371mcpsimp"><a name="p371mcpsimp"></a><a name="p371mcpsimp"></a>GetProducer</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="59%" headers="mcps1.1.3.1.2 "><p id="p373mcpsimp"><a name="p373mcpsimp"></a><a name="p373mcpsimp"></a>Obtains an internal <strong id="b1982865713319"><a name="b1982865713319"></a><a name="b1982865713319"></a>IBufferProducer</strong> object of <strong id="b14235152710419"><a name="b14235152710419"></a><a name="b14235152710419"></a>Surface</strong>.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row374mcpsimp"><td class="cellrowborder" valign="top" width="41%" headers="mcps1.1.3.1.1 "><p id="p376mcpsimp"><a name="p376mcpsimp"></a><a name="p376mcpsimp"></a>RequestBuffer</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="59%" headers="mcps1.1.3.1.2 "><p id="p378mcpsimp"><a name="p378mcpsimp"></a><a name="p378mcpsimp"></a>Requests a <strong id="b17591192851510"><a name="b17591192851510"></a><a name="b17591192851510"></a>SurfaceBuffer</strong> object to be produced.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row379mcpsimp"><td class="cellrowborder" valign="top" width="41%" headers="mcps1.1.3.1.1 "><p id="p381mcpsimp"><a name="p381mcpsimp"></a><a name="p381mcpsimp"></a>CancelBuffer</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="59%" headers="mcps1.1.3.1.2 "><p id="p383mcpsimp"><a name="p383mcpsimp"></a><a name="p383mcpsimp"></a>Cancels a <strong id="b11160135061513"><a name="b11160135061513"></a><a name="b11160135061513"></a>SurfaceBuffer</strong> object to be produced.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row384mcpsimp"><td class="cellrowborder" valign="top" width="41%" headers="mcps1.1.3.1.1 "><p id="p386mcpsimp"><a name="p386mcpsimp"></a><a name="p386mcpsimp"></a>FlushBuffer</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="59%" headers="mcps1.1.3.1.2 "><p id="p388mcpsimp"><a name="p388mcpsimp"></a><a name="p388mcpsimp"></a>Flushes a produced <strong id="b19478235151718"><a name="b19478235151718"></a><a name="b19478235151718"></a>SurfaceBuffer</strong> object with certain information.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row389mcpsimp"><td class="cellrowborder" valign="top" width="41%" headers="mcps1.1.3.1.1 "><p id="p391mcpsimp"><a name="p391mcpsimp"></a><a name="p391mcpsimp"></a>AcquireBuffer</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="59%" headers="mcps1.1.3.1.2 "><p id="p393mcpsimp"><a name="p393mcpsimp"></a><a name="p393mcpsimp"></a>Requests a <strong id="b4187111419210"><a name="b4187111419210"></a><a name="b4187111419210"></a>SurfaceBuffer</strong> object to be consumed.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row394mcpsimp"><td class="cellrowborder" valign="top" width="41%" headers="mcps1.1.3.1.1 "><p id="p396mcpsimp"><a name="p396mcpsimp"></a><a name="p396mcpsimp"></a>ReleaseBuffer</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="59%" headers="mcps1.1.3.1.2 "><p id="p398mcpsimp"><a name="p398mcpsimp"></a><a name="p398mcpsimp"></a>Returns a consumed <strong id="b626752116217"><a name="b626752116217"></a><a name="b626752116217"></a>SurfaceBuffer</strong> object.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row399mcpsimp"><td class="cellrowborder" valign="top" width="41%" headers="mcps1.1.3.1.1 "><p id="p401mcpsimp"><a name="p401mcpsimp"></a><a name="p401mcpsimp"></a>GetQueueSize</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="59%" headers="mcps1.1.3.1.2 "><p id="p403mcpsimp"><a name="p403mcpsimp"></a><a name="p403mcpsimp"></a>Obtains the number of concurrent buffers.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row404mcpsimp"><td class="cellrowborder" valign="top" width="41%" headers="mcps1.1.3.1.1 "><p id="p406mcpsimp"><a name="p406mcpsimp"></a><a name="p406mcpsimp"></a>SetQueueSize</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="59%" headers="mcps1.1.3.1.2 "><p id="p408mcpsimp"><a name="p408mcpsimp"></a><a name="p408mcpsimp"></a>Sets the number of concurrent buffers.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row409mcpsimp"><td class="cellrowborder" valign="top" width="41%" headers="mcps1.1.3.1.1 "><p id="p411mcpsimp"><a name="p411mcpsimp"></a><a name="p411mcpsimp"></a>SetDefaultWidthAndHeight</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="59%" headers="mcps1.1.3.1.2 "><p id="p413mcpsimp"><a name="p413mcpsimp"></a><a name="p413mcpsimp"></a>Sets the default width and height.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row414mcpsimp"><td class="cellrowborder" valign="top" width="41%" headers="mcps1.1.3.1.1 "><p id="p416mcpsimp"><a name="p416mcpsimp"></a><a name="p416mcpsimp"></a>GetDefaultWidth</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="59%" headers="mcps1.1.3.1.2 "><p id="p418mcpsimp"><a name="p418mcpsimp"></a><a name="p418mcpsimp"></a>Obtains the default width.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row419mcpsimp"><td class="cellrowborder" valign="top" width="41%" headers="mcps1.1.3.1.1 "><p id="p421mcpsimp"><a name="p421mcpsimp"></a><a name="p421mcpsimp"></a>GetDefaultHeight</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="59%" headers="mcps1.1.3.1.2 "><p id="p423mcpsimp"><a name="p423mcpsimp"></a><a name="p423mcpsimp"></a>Obtains the default height.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row424mcpsimp"><td class="cellrowborder" valign="top" width="41%" headers="mcps1.1.3.1.1 "><p id="p426mcpsimp"><a name="p426mcpsimp"></a><a name="p426mcpsimp"></a>SetUserData</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="59%" headers="mcps1.1.3.1.2 "><p id="p428mcpsimp"><a name="p428mcpsimp"></a><a name="p428mcpsimp"></a>Stores string data, which will not be transferred through IPC.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row429mcpsimp"><td class="cellrowborder" valign="top" width="41%" headers="mcps1.1.3.1.1 "><p id="p431mcpsimp"><a name="p431mcpsimp"></a><a name="p431mcpsimp"></a>GetUserData</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="59%" headers="mcps1.1.3.1.2 "><p id="p433mcpsimp"><a name="p433mcpsimp"></a><a name="p433mcpsimp"></a>Obtains string data.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row434mcpsimp"><td class="cellrowborder" valign="top" width="41%" headers="mcps1.1.3.1.1 "><p id="p436mcpsimp"><a name="p436mcpsimp"></a><a name="p436mcpsimp"></a>RegisterConsumerListener</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="59%" headers="mcps1.1.3.1.2 "><p id="p438mcpsimp"><a name="p438mcpsimp"></a><a name="p438mcpsimp"></a>Registers a consumer listener to listen for buffer flush events.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row439mcpsimp"><td class="cellrowborder" valign="top" width="41%" headers="mcps1.1.3.1.1 "><p id="p441mcpsimp"><a name="p441mcpsimp"></a><a name="p441mcpsimp"></a>UnregisterConsumerListener</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="59%" headers="mcps1.1.3.1.2 "><p id="p443mcpsimp"><a name="p443mcpsimp"></a><a name="p443mcpsimp"></a>Unregiseters a consumer listener.</p>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
### SurfaceBuffer<a name="section12001640184711"></a>
|
||||
|
||||
<a name="table445mcpsimp"></a>
|
||||
<table><thead align="left"><tr id="row450mcpsimp"><th class="cellrowborder" valign="top" width="32%" id="mcps1.1.3.1.1"><p id="p452mcpsimp"><a name="p452mcpsimp"></a><a name="p452mcpsimp"></a><strong id="b1560753920274"><a name="b1560753920274"></a><a name="b1560753920274"></a>API</strong></p>
|
||||
</th>
|
||||
<th class="cellrowborder" valign="top" width="68%" id="mcps1.1.3.1.2"><p id="p455mcpsimp"><a name="p455mcpsimp"></a><a name="p455mcpsimp"></a><strong id="b010044116274"><a name="b010044116274"></a><a name="b010044116274"></a>Description</strong></p>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody><tr id="row458mcpsimp"><td class="cellrowborder" valign="top" width="32%" headers="mcps1.1.3.1.1 "><p id="p460mcpsimp"><a name="p460mcpsimp"></a><a name="p460mcpsimp"></a>GetBufferHandle</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="68%" headers="mcps1.1.3.1.2 "><p id="p462mcpsimp"><a name="p462mcpsimp"></a><a name="p462mcpsimp"></a>Obtains the <strong id="b15990748192713"><a name="b15990748192713"></a><a name="b15990748192713"></a>BufferHandle</strong> pointer to the <strong id="b10706250132715"><a name="b10706250132715"></a><a name="b10706250132715"></a>SurfaceBuffer</strong> object.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row463mcpsimp"><td class="cellrowborder" valign="top" width="32%" headers="mcps1.1.3.1.1 "><p id="p465mcpsimp"><a name="p465mcpsimp"></a><a name="p465mcpsimp"></a>GetWidth</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="68%" headers="mcps1.1.3.1.2 "><p id="p467mcpsimp"><a name="p467mcpsimp"></a><a name="p467mcpsimp"></a>Obtains the width of the <strong id="b109605268315"><a name="b109605268315"></a><a name="b109605268315"></a>SurfaceBuffer</strong> object.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row468mcpsimp"><td class="cellrowborder" valign="top" width="32%" headers="mcps1.1.3.1.1 "><p id="p470mcpsimp"><a name="p470mcpsimp"></a><a name="p470mcpsimp"></a>GetHeight</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="68%" headers="mcps1.1.3.1.2 "><p id="p472mcpsimp"><a name="p472mcpsimp"></a><a name="p472mcpsimp"></a>Obtains the height of the <strong id="b142632918311"><a name="b142632918311"></a><a name="b142632918311"></a>SurfaceBuffer</strong> object.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row473mcpsimp"><td class="cellrowborder" valign="top" width="32%" headers="mcps1.1.3.1.1 "><p id="p475mcpsimp"><a name="p475mcpsimp"></a><a name="p475mcpsimp"></a>GetFormat</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="68%" headers="mcps1.1.3.1.2 "><p id="p477mcpsimp"><a name="p477mcpsimp"></a><a name="p477mcpsimp"></a>Obtains the color format of the <strong id="b11157143123112"><a name="b11157143123112"></a><a name="b11157143123112"></a>SurfaceBuffer</strong> object.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row478mcpsimp"><td class="cellrowborder" valign="top" width="32%" headers="mcps1.1.3.1.1 "><p id="p480mcpsimp"><a name="p480mcpsimp"></a><a name="p480mcpsimp"></a>GetUsage</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="68%" headers="mcps1.1.3.1.2 "><p id="p482mcpsimp"><a name="p482mcpsimp"></a><a name="p482mcpsimp"></a>Obtains the usage of the <strong id="b15685153383114"><a name="b15685153383114"></a><a name="b15685153383114"></a>SurfaceBuffer</strong> object.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row483mcpsimp"><td class="cellrowborder" valign="top" width="32%" headers="mcps1.1.3.1.1 "><p id="p485mcpsimp"><a name="p485mcpsimp"></a><a name="p485mcpsimp"></a>GetPhyAddr</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="68%" headers="mcps1.1.3.1.2 "><p id="p487mcpsimp"><a name="p487mcpsimp"></a><a name="p487mcpsimp"></a>Obtains the physical address of the <strong id="b1569003614310"><a name="b1569003614310"></a><a name="b1569003614310"></a>SurfaceBuffer</strong> object.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row488mcpsimp"><td class="cellrowborder" valign="top" width="32%" headers="mcps1.1.3.1.1 "><p id="p490mcpsimp"><a name="p490mcpsimp"></a><a name="p490mcpsimp"></a>GetKey</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="68%" headers="mcps1.1.3.1.2 "><p id="p492mcpsimp"><a name="p492mcpsimp"></a><a name="p492mcpsimp"></a>Obtains the key of the <strong id="b1679393910314"><a name="b1679393910314"></a><a name="b1679393910314"></a>SurfaceBuffer</strong> object.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row493mcpsimp"><td class="cellrowborder" valign="top" width="32%" headers="mcps1.1.3.1.1 "><p id="p495mcpsimp"><a name="p495mcpsimp"></a><a name="p495mcpsimp"></a>GetVirAddr</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="68%" headers="mcps1.1.3.1.2 "><p id="p497mcpsimp"><a name="p497mcpsimp"></a><a name="p497mcpsimp"></a>Obtains the virtual address of the <strong id="b56714253110"><a name="b56714253110"></a><a name="b56714253110"></a>SurfaceBuffer</strong> object.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row498mcpsimp"><td class="cellrowborder" valign="top" width="32%" headers="mcps1.1.3.1.1 "><p id="p500mcpsimp"><a name="p500mcpsimp"></a><a name="p500mcpsimp"></a>GetSize</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="68%" headers="mcps1.1.3.1.2 "><p id="p502mcpsimp"><a name="p502mcpsimp"></a><a name="p502mcpsimp"></a>Obtains the size of the <strong id="b12547184533112"><a name="b12547184533112"></a><a name="b12547184533112"></a>SurfaceBuffer</strong> object.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row503mcpsimp"><td class="cellrowborder" valign="top" width="32%" headers="mcps1.1.3.1.1 "><p id="p505mcpsimp"><a name="p505mcpsimp"></a><a name="p505mcpsimp"></a>SetInt32</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="68%" headers="mcps1.1.3.1.2 "><p id="p507mcpsimp"><a name="p507mcpsimp"></a><a name="p507mcpsimp"></a>Sets the 32-bit integer for the <strong id="b284244873112"><a name="b284244873112"></a><a name="b284244873112"></a>SurfaceBuffer</strong> object.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row508mcpsimp"><td class="cellrowborder" valign="top" width="32%" headers="mcps1.1.3.1.1 "><p id="p510mcpsimp"><a name="p510mcpsimp"></a><a name="p510mcpsimp"></a>GetInt32</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="68%" headers="mcps1.1.3.1.2 "><p id="p512mcpsimp"><a name="p512mcpsimp"></a><a name="p512mcpsimp"></a>Obtains the 32-bit integer for the <strong id="b11398105163116"><a name="b11398105163116"></a><a name="b11398105163116"></a>SurfaceBuffer</strong> object.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row513mcpsimp"><td class="cellrowborder" valign="top" width="32%" headers="mcps1.1.3.1.1 "><p id="p515mcpsimp"><a name="p515mcpsimp"></a><a name="p515mcpsimp"></a>SetInt64</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="68%" headers="mcps1.1.3.1.2 "><p id="p517mcpsimp"><a name="p517mcpsimp"></a><a name="p517mcpsimp"></a>Sets the 64-bit integer for the <strong id="b19859155463116"><a name="b19859155463116"></a><a name="b19859155463116"></a>SurfaceBuffer</strong> object.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row518mcpsimp"><td class="cellrowborder" valign="top" width="32%" headers="mcps1.1.3.1.1 "><p id="p520mcpsimp"><a name="p520mcpsimp"></a><a name="p520mcpsimp"></a>GetInt64</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="68%" headers="mcps1.1.3.1.2 "><p id="p522mcpsimp"><a name="p522mcpsimp"></a><a name="p522mcpsimp"></a>Obtains the 64-bit integer for the <strong id="b753775763118"><a name="b753775763118"></a><a name="b753775763118"></a>SurfaceBuffer</strong> object.</p>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
### VsyncHelper<a name="section1392116294211"></a>
|
||||
|
||||
<a name="table524mcpsimp"></a>
|
||||
<table><thead align="left"><tr id="row529mcpsimp"><th class="cellrowborder" valign="top" width="38%" id="mcps1.1.3.1.1"><p id="p531mcpsimp"><a name="p531mcpsimp"></a><a name="p531mcpsimp"></a><strong id="b133428253019"><a name="b133428253019"></a><a name="b133428253019"></a>API</strong></p>
|
||||
</th>
|
||||
<th class="cellrowborder" valign="top" width="62%" id="mcps1.1.3.1.2"><p id="p534mcpsimp"><a name="p534mcpsimp"></a><a name="p534mcpsimp"></a><strong id="b16934026309"><a name="b16934026309"></a><a name="b16934026309"></a>Description</strong></p>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody><tr id="row537mcpsimp"><td class="cellrowborder" valign="top" width="38%" headers="mcps1.1.3.1.1 "><p id="p539mcpsimp"><a name="p539mcpsimp"></a><a name="p539mcpsimp"></a>Current</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="62%" headers="mcps1.1.3.1.2 "><p id="p541mcpsimp"><a name="p541mcpsimp"></a><a name="p541mcpsimp"></a>Obtains the <strong id="b25453472308"><a name="b25453472308"></a><a name="b25453472308"></a>VsyncHelper</strong> object of the current runner.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row542mcpsimp"><td class="cellrowborder" valign="top" width="38%" headers="mcps1.1.3.1.1 "><p id="p544mcpsimp"><a name="p544mcpsimp"></a><a name="p544mcpsimp"></a>VsyncHelper</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="62%" headers="mcps1.1.3.1.2 "><p id="p546mcpsimp"><a name="p546mcpsimp"></a><a name="p546mcpsimp"></a>Constructs a <strong id="b157281123143212"><a name="b157281123143212"></a><a name="b157281123143212"></a>VsyncHelper</strong> object using an <strong id="b1650443412326"><a name="b1650443412326"></a><a name="b1650443412326"></a>EventHandler</strong> object.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row547mcpsimp"><td class="cellrowborder" valign="top" width="38%" headers="mcps1.1.3.1.1 "><p id="p549mcpsimp"><a name="p549mcpsimp"></a><a name="p549mcpsimp"></a>RequestFrameCallback</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="62%" headers="mcps1.1.3.1.2 "><p id="p551mcpsimp"><a name="p551mcpsimp"></a><a name="p551mcpsimp"></a>Registers a frame callback.</p>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
## Usage<a name="section18359134910422"></a>
|
||||
|
||||
### Transferring a Producer Surface<a name="section193464304411"></a>
|
||||
|
||||
1. Named service
|
||||
- Service registration:
|
||||
|
||||
```
|
||||
// Obtain a consumer surface.
|
||||
sptr<Surface> surface = Surface::CreateSurfaceAsConsumer();
|
||||
// Extract the producer object.
|
||||
sptr<IBufferProducer> 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<IRemoteObject> robj = sm->GetSystemAbility(IPC_SA_ID);
|
||||
// Construct a surface.
|
||||
sptr<IBufferProducer> bp = iface_cast<IBufferProducer>(robj);
|
||||
sptr<Surface> surface = Surface::CreateSurfaceAsProducer(bp);
|
||||
```
|
||||
|
||||
|
||||
2. Anonymous service
|
||||
- Sending of a surface:
|
||||
|
||||
```
|
||||
// Obtain a consumer surface.
|
||||
sptr<Surface> surface = CreateSurfaceAsConsumer();
|
||||
// Extract the producer object.
|
||||
sptr<IRemoteObject> producer = surface->GetProducer();
|
||||
// Return the producer object to the client.
|
||||
parcel.WriteRemoteObject(producer);
|
||||
```
|
||||
|
||||
|
||||
|
||||
### Creating a Producer Surface<a name="section1276823075112"></a>
|
||||
|
||||
```
|
||||
// Obtain a producer object.
|
||||
sptr<IRemoteObject> remoteObject = parcel.ReadRemoteObject();
|
||||
// Construct a surface.
|
||||
sptr<IBufferProducer> bp = iface_cast<IBufferProducer>(robj);
|
||||
sptr<Surface> surface = Surface::CreateSurfaceAsProducer(bp);
|
||||
```
|
||||
|
||||
### Producing a SurfaceBuffer<a name="section614545716513"></a>
|
||||
|
||||
```
|
||||
// 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<SurfaceBuffer> 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<a name="section315285412535"></a>
|
||||
|
||||
```
|
||||
// Prerequisite: a consumer surface
|
||||
class TestConsumerListener : public IBufferConsumerListener {
|
||||
public:
|
||||
void OnBufferAvailable() override {
|
||||
sptr<SurfaceBuffer> 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<IBufferConsumerListener> listener = new TestConsumerListener();
|
||||
SurfaceError ret = surface->RegisterConsumerListener(listener);
|
||||
if (ret != SURFACE_ERROR_OK) {
|
||||
// failed
|
||||
}
|
||||
```
|
||||
|
||||
### Adding Custom Data to a SurfaceBuffer<a name="section612412125616"></a>
|
||||
|
||||
```
|
||||
sptr<SurfaceBuffer> 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<a name="section1148115214576"></a>
|
||||
|
||||
1. Construct a **VsyncHelper** object using **handler**.
|
||||
|
||||
```
|
||||
auto runner = AppExecFwk::EventRunner::Create(true);
|
||||
auto handler = std::make_shared<AppExecFwk::EventHandler>(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<AppExecFwk::EventHandler>(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<a name="section6488145313"></a>
|
||||
|
||||
Graphics subsystem
|
||||
|
||||
**graphic\_standard**
|
||||
|
||||
ace\_ace\_engine
|
||||
|
||||
aafwk\_L2
|
||||
|
||||
multimedia\_media\_standard
|
||||
|
||||
multimedia\_camera\_standard
|
||||
|
||||
+23
-322
@@ -3,359 +3,60 @@
|
||||
- [简介](#简介)
|
||||
- [目录](#目录)
|
||||
- [约束](#约束)
|
||||
- [编译构建](#编译构建)
|
||||
- [接口说明](#接口说明)
|
||||
- [使用说明](#使用说明)
|
||||
- [相关仓](#相关仓)
|
||||
|
||||
## 简介
|
||||
|
||||
**Graphic子系统** 提供了图形接口能力和窗口管理接口能力,
|
||||
**窗口子系统** 提供窗口管理和Display管理的基础能力,是系统图形界面显示所需的基础子系统
|
||||
|
||||
其主要的结构如下图所示:
|
||||
|
||||

|
||||

|
||||
|
||||
- **Surface**
|
||||
- **Window Manager Client**
|
||||
|
||||
图形缓冲区管理接口,负责管理图形缓冲区和高效便捷的轮转缓冲区。
|
||||
应用进程窗口管理接口层,提供窗口对对象抽象和窗口管理接口,对接原能力和UI框架。
|
||||
|
||||
- **Vsync**
|
||||
- **Display Manager Client**
|
||||
|
||||
垂直同步信号管理接口,负责管理所有垂直同步信号注册和响应。
|
||||
应用进程Display管理接口层,提供Display信息抽象和Display管理接口。
|
||||
|
||||
- **WindowManager**
|
||||
- **Window Manager Server**
|
||||
|
||||
窗口管理器接口,负责创建和管理窗口。
|
||||
窗口管理服务,提供窗口布局、Z序控制、窗口树结构、窗口拖拽、窗口快照等能力,并提供窗口布局和焦点窗口给多模输入
|
||||
|
||||
- **WaylandProtocols**
|
||||
|
||||
窗口管理器和合成器的通信协议。
|
||||
|
||||
- **Compositor**
|
||||
|
||||
合成器,负责合成各个图层。
|
||||
|
||||
- **Renderer**
|
||||
|
||||
合成器的后端渲染模块。
|
||||
|
||||
- **Wayland protocols**
|
||||
|
||||
Wayland 进程间通信协议
|
||||
|
||||
- **Shell**
|
||||
|
||||
提供多窗口能力
|
||||
|
||||
- **Input Manger**
|
||||
|
||||
多模输入模块,负责接收事件输入
|
||||
- **Display Manager Server**
|
||||
|
||||
Display管理服务,提供Display信息、屏幕截图、屏幕亮灭和亮度处理控制,并处理Display与Screen映射关系
|
||||
|
||||
## 目录
|
||||
```
|
||||
foundation/graphic/standard/
|
||||
├── frameworks # 框架代码目录
|
||||
│ ├── bootanimation # 开机动画目录
|
||||
│ ├── surface # Surface代码
|
||||
│ ├── vsync # Vsync代码
|
||||
│ └── wm # WindowManager代码
|
||||
foundation/windowmanager/
|
||||
├── dm # Dislplay Manager Client实现代码
|
||||
├── dmserver # Dislplay Manager Service实现代码
|
||||
├── interfaces # 对外接口存放目录
|
||||
│ ├── innerkits # native接口存放目录
|
||||
│ └── kits # js/napi接口存放目录
|
||||
└── utils # 小部件存放目录
|
||||
├── resources # 框架使用资源文件存放目录
|
||||
├── sa_profile # 系统服务配置文件
|
||||
├── snapshot # 截屏命令行工具实现代码
|
||||
├── utils # 工具类存放目录
|
||||
├── wm # Window Manager Client实现代码
|
||||
├── wmserver # Window Manager Service实现代码
|
||||
```
|
||||
|
||||
## 约束
|
||||
- 语言版本
|
||||
- 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 = Surface::CreateSurfaceAsConsumer();
|
||||
|
||||
// 拿出里面的生产者对象
|
||||
sptr<IBufferProducer> producer = surface->GetProducer();
|
||||
|
||||
// 注册服务
|
||||
auto sm = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
|
||||
sm->AddSystemAbility(IPC_SA_ID, producer->AsObject());
|
||||
```
|
||||
|
||||
#### 客户端获得生产型Surface
|
||||
```cpp
|
||||
// 获得远程对象
|
||||
auto sm = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
|
||||
sptr<IRemoteObject> robj = sm->GetSystemAbility(IPC_SA_ID);
|
||||
|
||||
// 构造Surface
|
||||
sptr<IBufferProducer> bp = iface_cast<IBufferProducer>(robj);
|
||||
sptr<Surface> surface = Surface::CreateSurfaceAsProducer(bp);
|
||||
```
|
||||
|
||||
### 匿名服务-传递一个生产型Surface
|
||||
场景: 在一次IPC过程中
|
||||
|
||||
#### 发送
|
||||
```cpp
|
||||
// 拿到一个消费型Surface
|
||||
sptr<Surface> surface = CreateSurfaceAsConsumer();
|
||||
|
||||
// 拿出里面的生产者对象
|
||||
sptr<IRemoteObject> producer = surface->GetProducer();
|
||||
|
||||
// 返回给客户端
|
||||
parcel.WriteRemoteObject(producer);
|
||||
```
|
||||
|
||||
#### 接受并获得生产型Surface
|
||||
```cpp
|
||||
// 获得远程对象
|
||||
sptr<IRemoteObject> remoteObject = parcel.ReadRemoteObject();
|
||||
|
||||
// 构造Surface
|
||||
sptr<IBufferProducer> bp = iface_cast<IBufferProducer>(robj);
|
||||
sptr<Surface> 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<SurfaceBuffer> 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<SurfaceBuffer> 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<IBufferConsumerListener> listener = new TestConsumerListener();
|
||||
SurfaceError ret = surface->RegisterConsumerListener(listener);
|
||||
if (ret != SURFACE_ERROR_OK) {
|
||||
// failed
|
||||
}
|
||||
```
|
||||
|
||||
### 给SurfaceBuffer带上自定义数据
|
||||
```cpp
|
||||
sptr<SurfaceBuffer> 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<AppExecFwk::EventHandler>(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<AppExecFwk::EventHandler>(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();
|
||||
```
|
||||
- [Window](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis/js-apis-window.md)
|
||||
- [Display](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis/js-apis-display.md)
|
||||
|
||||
## 相关仓
|
||||
- **graphic_standard**
|
||||
- graphic_standard
|
||||
- ace_ace_engine
|
||||
- aafwk_standard
|
||||
- multimedia_media_standard
|
||||
- multimedia_camera_standard
|
||||
- multimodalinput_input
|
||||
+5
-1
@@ -17,6 +17,9 @@
|
||||
"adapted_system_type": [ "standard" ],
|
||||
"rom": "8000KB",
|
||||
"ram": "8000KB",
|
||||
"hisysevent_config": [
|
||||
"//foundation/windowmanager/hisysevent.yaml"
|
||||
],
|
||||
"deps": {
|
||||
"components": [
|
||||
"ability_base",
|
||||
@@ -90,7 +93,8 @@
|
||||
],
|
||||
"test": [
|
||||
"//foundation/windowmanager/wm:test",
|
||||
"//foundation/windowmanager/dm:test"
|
||||
"//foundation/windowmanager/dm:test",
|
||||
"//foundation/windowmanager/wmserver:test"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,12 +18,6 @@ config("libdm_private_config") {
|
||||
"include",
|
||||
"../dmserver/include",
|
||||
]
|
||||
|
||||
if (defined(product_name) &&
|
||||
(product_name == "rk3566" || product_name == "rk3568" ||
|
||||
product_name == "Hi3516DV300" || product_name == "watchos")) {
|
||||
defines = [ "PRODUCT_RK" ]
|
||||
}
|
||||
}
|
||||
|
||||
config("libdm_public_config") {
|
||||
@@ -40,7 +34,6 @@ ohos_shared_library("libdm") {
|
||||
"src/display.cpp",
|
||||
"src/display_manager.cpp",
|
||||
"src/display_manager_adapter.cpp",
|
||||
"src/display_manager_agent.cpp",
|
||||
"src/screen.cpp",
|
||||
"src/screen_group.cpp",
|
||||
"src/screen_manager.cpp",
|
||||
|
||||
@@ -28,35 +28,36 @@
|
||||
#include "singleton_delegator.h"
|
||||
|
||||
namespace OHOS::Rosen {
|
||||
class DMSDeathRecipient : public IRemoteObject::DeathRecipient {
|
||||
class BaseAdapter {
|
||||
public:
|
||||
virtual void OnRemoteDied(const wptr<IRemoteObject>& wptrDeath) override;
|
||||
};
|
||||
|
||||
class DisplayManagerAdapter {
|
||||
WM_DECLARE_SINGLE_INSTANCE(DisplayManagerAdapter);
|
||||
public:
|
||||
virtual DisplayId GetDefaultDisplayId();
|
||||
virtual sptr<Display> GetDisplayById(DisplayId displayId);
|
||||
|
||||
virtual ScreenId CreateVirtualScreen(VirtualScreenOption option);
|
||||
virtual DMError DestroyVirtualScreen(ScreenId screenId);
|
||||
virtual DMError SetVirtualScreenSurface(ScreenId screenId, sptr<Surface> surface);
|
||||
virtual bool RequestRotation(ScreenId screenId, Rotation rotation);
|
||||
virtual std::shared_ptr<Media::PixelMap> GetDisplaySnapshot(DisplayId displayId);
|
||||
|
||||
// colorspace, gamut
|
||||
virtual DMError GetScreenSupportedColorGamuts(ScreenId screenId, std::vector<ScreenColorGamut>& colorGamuts);
|
||||
virtual DMError GetScreenColorGamut(ScreenId screenId, ScreenColorGamut& colorGamut);
|
||||
virtual DMError SetScreenColorGamut(ScreenId screenId, int32_t colorGamutIdx);
|
||||
virtual DMError GetScreenGamutMap(ScreenId screenId, ScreenGamutMap& gamutMap);
|
||||
virtual DMError SetScreenGamutMap(ScreenId screenId, ScreenGamutMap gamutMap);
|
||||
virtual DMError SetScreenColorTransform(ScreenId screenId);
|
||||
|
||||
virtual bool RegisterDisplayManagerAgent(const sptr<IDisplayManagerAgent>& displayManagerAgent,
|
||||
DisplayManagerAgentType type);
|
||||
virtual bool UnregisterDisplayManagerAgent(const sptr<IDisplayManagerAgent>& displayManagerAgent,
|
||||
DisplayManagerAgentType type);
|
||||
virtual void Clear();
|
||||
protected:
|
||||
bool InitDMSProxy();
|
||||
std::recursive_mutex mutex_;
|
||||
sptr<IDisplayManager> displayManagerServiceProxy_ = nullptr;
|
||||
sptr<IRemoteObject::DeathRecipient> dmsDeath_ = nullptr;
|
||||
bool isProxyValid_ { false };
|
||||
};
|
||||
|
||||
class DMSDeathRecipient : public IRemoteObject::DeathRecipient {
|
||||
public:
|
||||
DMSDeathRecipient(BaseAdapter& adapter);
|
||||
virtual void OnRemoteDied(const wptr<IRemoteObject>& wptrDeath) override;
|
||||
private:
|
||||
BaseAdapter& adapter_;
|
||||
};
|
||||
|
||||
class DisplayManagerAdapter : public BaseAdapter {
|
||||
WM_DECLARE_SINGLE_INSTANCE(DisplayManagerAdapter);
|
||||
public:
|
||||
virtual DisplayId GetDefaultDisplayId();
|
||||
virtual sptr<DisplayInfo> GetDisplayInfoByScreenId(ScreenId screenId);
|
||||
virtual std::vector<DisplayId> GetAllDisplayIds();
|
||||
virtual std::shared_ptr<Media::PixelMap> GetDisplaySnapshot(DisplayId displayId);
|
||||
virtual bool WakeUpBegin(PowerStateChangeReason reason);
|
||||
virtual bool WakeUpEnd();
|
||||
virtual bool SuspendBegin(PowerStateChangeReason reason);
|
||||
@@ -65,26 +66,35 @@ public:
|
||||
virtual bool SetDisplayState(DisplayState state);
|
||||
virtual DisplayState GetDisplayState(DisplayId displayId);
|
||||
virtual void NotifyDisplayEvent(DisplayEvent event);
|
||||
virtual DMError MakeMirror(ScreenId mainScreenId, std::vector<ScreenId> mirrorScreenId);
|
||||
virtual void Clear();
|
||||
virtual sptr<Screen> GetScreenById(ScreenId screenId);
|
||||
virtual sptr<ScreenGroup> GetScreenGroupById(ScreenId screenId);
|
||||
virtual std::vector<sptr<Screen>> GetAllScreens();
|
||||
virtual DMError MakeExpand(std::vector<ScreenId> screenId, std::vector<Point> startPoint);
|
||||
virtual bool SetScreenActiveMode(ScreenId screenId, uint32_t modeId);
|
||||
|
||||
virtual sptr<DisplayInfo> GetDisplayInfo(DisplayId displayId);
|
||||
private:
|
||||
bool InitDMSProxyLocked();
|
||||
|
||||
static inline SingletonDelegator<DisplayManagerAdapter> delegator;
|
||||
};
|
||||
|
||||
std::recursive_mutex mutex_;
|
||||
sptr<IDisplayManager> displayManagerServiceProxy_ = nullptr;
|
||||
sptr<DMSDeathRecipient> dmsDeath_ = nullptr;
|
||||
std::map<DisplayId, sptr<Display>> displayMap_;
|
||||
std::map<ScreenId, sptr<Screen>> screenMap_;
|
||||
std::map<ScreenId, sptr<ScreenGroup>> screenGroupMap_;
|
||||
DisplayId defaultDisplayId_;
|
||||
class ScreenManagerAdapter : public BaseAdapter {
|
||||
WM_DECLARE_SINGLE_INSTANCE(ScreenManagerAdapter);
|
||||
public:
|
||||
virtual ScreenId CreateVirtualScreen(VirtualScreenOption option);
|
||||
virtual DMError DestroyVirtualScreen(ScreenId screenId);
|
||||
virtual DMError SetVirtualScreenSurface(ScreenId screenId, sptr<Surface> surface);
|
||||
virtual bool SetOrientation(ScreenId screenId, Orientation orientation);
|
||||
virtual sptr<ScreenGroupInfo> GetScreenGroupInfoById(ScreenId screenId);
|
||||
virtual std::vector<sptr<ScreenInfo>> GetAllScreenInfos();
|
||||
virtual ScreenId MakeMirror(ScreenId mainScreenId, std::vector<ScreenId> mirrorScreenId);
|
||||
virtual ScreenId MakeExpand(std::vector<ScreenId> screenId, std::vector<Point> startPoint);
|
||||
virtual void RemoveVirtualScreenFromGroup(std::vector<ScreenId>);
|
||||
virtual bool SetScreenActiveMode(ScreenId screenId, uint32_t modeId);
|
||||
virtual sptr<ScreenInfo> GetScreenInfo(ScreenId screenId);
|
||||
|
||||
// colorspace, gamut
|
||||
virtual DMError GetScreenSupportedColorGamuts(ScreenId screenId, std::vector<ScreenColorGamut>& colorGamuts);
|
||||
virtual DMError GetScreenColorGamut(ScreenId screenId, ScreenColorGamut& colorGamut);
|
||||
virtual DMError SetScreenColorGamut(ScreenId screenId, int32_t colorGamutIdx);
|
||||
virtual DMError GetScreenGamutMap(ScreenId screenId, ScreenGamutMap& gamutMap);
|
||||
virtual DMError SetScreenGamutMap(ScreenId screenId, ScreenGamutMap gamutMap);
|
||||
virtual DMError SetScreenColorTransform(ScreenId screenId);
|
||||
private:
|
||||
static inline SingletonDelegator<ScreenManagerAdapter> delegator;
|
||||
};
|
||||
} // namespace OHOS::Rosen
|
||||
#endif // FOUNDATION_DM_DISPLAY_MANAGER_ADAPTER_H
|
||||
|
||||
@@ -29,7 +29,8 @@ public:
|
||||
void NotifyDisplayStateChanged(DisplayId id, DisplayState state) override {};
|
||||
void OnScreenConnect(sptr<ScreenInfo>) override {};
|
||||
void OnScreenDisconnect(ScreenId) override {};
|
||||
void OnScreenChange(const std::vector<const sptr<ScreenInfo>>&, ScreenChangeEvent) override {};
|
||||
void OnScreenChange(const sptr<ScreenInfo>&, ScreenChangeEvent) override {};
|
||||
void OnScreenGroupChange(const std::vector<sptr<ScreenInfo>>&, ScreenGroupChangeEvent) override {};
|
||||
void OnDisplayCreate(sptr<DisplayInfo>) override {};
|
||||
void OnDisplayDestroy(DisplayId) override {};
|
||||
void OnDisplayChange(const sptr<DisplayInfo>, DisplayChangeEvent) override {};
|
||||
|
||||
@@ -40,6 +40,7 @@ public:
|
||||
TRANS_ID_ON_SCREEN_CONNECT,
|
||||
TRANS_ID_ON_SCREEN_DISCONNECT,
|
||||
TRANS_ID_ON_SCREEN_CHANGED,
|
||||
TRANS_ID_ON_SCREENGROUP_CHANGED,
|
||||
TRANS_ID_ON_DISPLAY_CONNECT,
|
||||
TRANS_ID_ON_DISPLAY_DISCONNECT,
|
||||
TRANS_ID_ON_DISPLAY_CHANGED,
|
||||
@@ -48,7 +49,8 @@ public:
|
||||
virtual void NotifyDisplayStateChanged(DisplayId id, DisplayState state) = 0;
|
||||
virtual void OnScreenConnect(sptr<ScreenInfo>) = 0;
|
||||
virtual void OnScreenDisconnect(ScreenId) = 0;
|
||||
virtual void OnScreenChange(const std::vector<const sptr<ScreenInfo>>&, ScreenChangeEvent) = 0;
|
||||
virtual void OnScreenChange(const sptr<ScreenInfo>&, ScreenChangeEvent) = 0;
|
||||
virtual void OnScreenGroupChange(const std::vector<sptr<ScreenInfo>>&, ScreenGroupChangeEvent) = 0;
|
||||
virtual void OnDisplayCreate(sptr<DisplayInfo>) = 0;
|
||||
virtual void OnDisplayDestroy(DisplayId) = 0;
|
||||
virtual void OnDisplayChange(sptr<DisplayInfo>, DisplayChangeEvent) = 0;
|
||||
|
||||
@@ -30,7 +30,8 @@ public:
|
||||
virtual void NotifyDisplayStateChanged(DisplayId id, DisplayState state) override;
|
||||
virtual void OnScreenConnect(sptr<ScreenInfo>) override;
|
||||
virtual void OnScreenDisconnect(ScreenId) override;
|
||||
virtual void OnScreenChange(const std::vector<const sptr<ScreenInfo>>&, ScreenChangeEvent) override;
|
||||
virtual void OnScreenChange(const sptr<ScreenInfo>&, ScreenChangeEvent) override;
|
||||
virtual void OnScreenGroupChange(const std::vector<sptr<ScreenInfo>>&, ScreenGroupChangeEvent) override;
|
||||
virtual void OnDisplayCreate(sptr<DisplayInfo>) override;
|
||||
virtual void OnDisplayDestroy(DisplayId) override;
|
||||
virtual void OnDisplayChange(sptr<DisplayInfo>, DisplayChangeEvent) override;
|
||||
|
||||
+54
-37
@@ -15,82 +15,99 @@
|
||||
|
||||
#include "display.h"
|
||||
#include "display_info.h"
|
||||
#include "display_manager_adapter.h"
|
||||
#include "window_manager_hilog.h"
|
||||
|
||||
namespace OHOS::Rosen {
|
||||
namespace {
|
||||
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "Display"};
|
||||
constexpr int32_t LARGE_SCREEN_WIDTH = 2560;
|
||||
}
|
||||
class Display::Impl : public RefBase {
|
||||
friend class Display;
|
||||
private:
|
||||
std::string name_;
|
||||
DisplayId id_ { DISPLAY_ID_INVALD };
|
||||
int32_t width_ { 0 };
|
||||
int32_t height_ { 0 };
|
||||
uint32_t freshRate_ { 0 };
|
||||
ScreenId screenId_ {SCREEN_ID_INVALID};
|
||||
public:
|
||||
Impl(const std::string& name, sptr<DisplayInfo> info)
|
||||
{
|
||||
name_= name;
|
||||
displayInfo_ = info;
|
||||
}
|
||||
~Impl() = default;
|
||||
DEFINE_VAR_FUNC_GET_SET(std::string, Name, name);
|
||||
DEFINE_VAR_FUNC_GET_SET(sptr<DisplayInfo>, DisplayInfo, displayInfo);
|
||||
};
|
||||
|
||||
Display::Display(const std::string& name, DisplayInfo* info)
|
||||
: pImpl_(new Impl())
|
||||
Display::Display(const std::string& name, sptr<DisplayInfo> info)
|
||||
: pImpl_(new Impl(name, info))
|
||||
{
|
||||
}
|
||||
|
||||
Display::~Display()
|
||||
{
|
||||
pImpl_->name_ = name;
|
||||
pImpl_->id_ = info->id_;
|
||||
pImpl_->width_ = info->width_;
|
||||
pImpl_->height_ = info->height_;
|
||||
pImpl_->freshRate_ = info->freshRate_;
|
||||
pImpl_->screenId_ = info->screenId_;
|
||||
}
|
||||
|
||||
DisplayId Display::GetId() const
|
||||
{
|
||||
return pImpl_->id_;
|
||||
return pImpl_->GetDisplayInfo()->GetDisplayId();
|
||||
}
|
||||
|
||||
int32_t Display::GetWidth() const
|
||||
{
|
||||
return pImpl_->width_;
|
||||
UpdateDisplayInfo();
|
||||
return pImpl_->GetDisplayInfo()->GetWidth();
|
||||
}
|
||||
|
||||
int32_t Display::GetHeight() const
|
||||
{
|
||||
return pImpl_->height_;
|
||||
UpdateDisplayInfo();
|
||||
return pImpl_->GetDisplayInfo()->GetHeight();
|
||||
}
|
||||
|
||||
uint32_t Display::GetFreshRate() const
|
||||
{
|
||||
return pImpl_->freshRate_;
|
||||
UpdateDisplayInfo();
|
||||
return pImpl_->GetDisplayInfo()->GetFreshRate();
|
||||
}
|
||||
|
||||
ScreenId Display::GetScreenId() const
|
||||
{
|
||||
return pImpl_->screenId_;
|
||||
UpdateDisplayInfo();
|
||||
return pImpl_->GetDisplayInfo()->GetScreenId();
|
||||
}
|
||||
|
||||
void Display::SetWidth(int32_t width)
|
||||
Rotation Display::GetRotation() const
|
||||
{
|
||||
pImpl_->width_ = width;
|
||||
UpdateDisplayInfo();
|
||||
return pImpl_->GetDisplayInfo()->GetRotation();
|
||||
}
|
||||
|
||||
void Display::SetHeight(int32_t height)
|
||||
Orientation Display::GetOrientation() const
|
||||
{
|
||||
pImpl_->height_ = height;
|
||||
UpdateDisplayInfo();
|
||||
return pImpl_->GetDisplayInfo()->GetOrientation();
|
||||
}
|
||||
|
||||
void Display::SetFreshRate(uint32_t freshRate)
|
||||
void Display::UpdateDisplayInfo(sptr<DisplayInfo> displayInfo) const
|
||||
{
|
||||
pImpl_->freshRate_ = freshRate;
|
||||
if (displayInfo == nullptr) {
|
||||
WLOGFE("displayInfo is invalid");
|
||||
return;
|
||||
}
|
||||
pImpl_->SetDisplayInfo(displayInfo);
|
||||
}
|
||||
|
||||
void Display::UpdateDisplayInfo() const
|
||||
{
|
||||
auto displayInfo = SingletonContainer::Get<DisplayManagerAdapter>().GetDisplayInfo(GetId());
|
||||
UpdateDisplayInfo(displayInfo);
|
||||
}
|
||||
|
||||
float Display::GetVirtualPixelRatio() const
|
||||
{
|
||||
// TODO: Should get from DMS
|
||||
#ifdef PRODUCT_RK
|
||||
return 1.0f;
|
||||
#else
|
||||
return 2.0f;
|
||||
#endif
|
||||
}
|
||||
|
||||
void Display::SetId(DisplayId id)
|
||||
{
|
||||
pImpl_->id_ = id;
|
||||
if ((pImpl_->GetDisplayInfo()->GetWidth() == LARGE_SCREEN_WIDTH)
|
||||
|| (pImpl_->GetDisplayInfo()->GetHeight() == LARGE_SCREEN_WIDTH)) {
|
||||
return 2.0f;
|
||||
} else {
|
||||
return 1.0f;
|
||||
}
|
||||
}
|
||||
} // namespace OHOS::Rosen
|
||||
+247
-109
@@ -19,7 +19,7 @@
|
||||
#include <transaction/rs_interfaces.h>
|
||||
|
||||
#include "display_manager_adapter.h"
|
||||
#include "display_manager_agent.h"
|
||||
#include "display_manager_agent_default.h"
|
||||
#include "dm_common.h"
|
||||
#include "singleton_delegator.h"
|
||||
#include "window_manager_hilog.h"
|
||||
@@ -33,20 +33,38 @@ WM_IMPLEMENT_SINGLE_INSTANCE(DisplayManager)
|
||||
class DisplayManager::Impl : public RefBase {
|
||||
public:
|
||||
static inline SingletonDelegator<DisplayManager> delegator;
|
||||
std::recursive_mutex mutex_;
|
||||
std::vector<sptr<IDisplayPowerEventListener>> powerEventListeners_;
|
||||
sptr<DisplayManagerAgent> powerEventListenerAgent_;
|
||||
sptr<DisplayManagerAgent> displayStateAgent_;
|
||||
DisplayStateCallback displayStateCallback_;
|
||||
|
||||
std::vector<sptr<IDisplayListener>> displayListeners_;
|
||||
|
||||
bool CheckRectValid(const Media::Rect& rect, int32_t oriHeight, int32_t oriWidth) const;
|
||||
bool CheckSizeValid(const Media::Size& size, int32_t oriHeight, int32_t oriWidth) const;
|
||||
sptr<Display> GetDisplayById(DisplayId displayId);
|
||||
bool RegisterDisplayListener(sptr<IDisplayListener> listener);
|
||||
bool UnregisterDisplayListener(sptr<IDisplayListener> listener);
|
||||
bool SetDisplayState(DisplayState state, DisplayStateCallback callback);
|
||||
bool RegisterDisplayPowerEventListener(sptr<IDisplayPowerEventListener> listener);
|
||||
bool UnregisterDisplayPowerEventListener(sptr<IDisplayPowerEventListener> listener);
|
||||
sptr<Display> GetDisplayByScreenId(ScreenId screenId);
|
||||
private:
|
||||
void ClearDisplayStateCallback();
|
||||
void NotifyDisplayPowerEvent(DisplayPowerEvent event, EventStatus status);
|
||||
void NotifyDisplayStateChanged(DisplayId id, DisplayState state);
|
||||
void NotifyDisplayChangedEvent(sptr<DisplayInfo> info, DisplayChangeEvent event);
|
||||
void NotifyDisplayCreate(sptr<DisplayInfo> info);
|
||||
void NotifyDisplayDestroy(DisplayId);
|
||||
void NotifyDisplayChange(sptr<DisplayInfo> displayInfo);
|
||||
bool UpdateDisplayInfoLocked(sptr<DisplayInfo>);
|
||||
|
||||
class DisplayManagerListener;
|
||||
sptr<DisplayManagerListener> displayManagerListener_;
|
||||
std::map<DisplayId, sptr<Display>> displayMap_;
|
||||
DisplayStateCallback displayStateCallback_;
|
||||
std::recursive_mutex mutex_;
|
||||
std::vector<sptr<IDisplayPowerEventListener>> powerEventListeners_;
|
||||
class DisplayManagerAgent;
|
||||
sptr<DisplayManagerAgent> powerEventListenerAgent_;
|
||||
sptr<DisplayManagerAgent> displayStateAgent_;
|
||||
std::vector<sptr<IDisplayListener>> displayListeners_;
|
||||
};
|
||||
|
||||
class DisplayManager::DisplayManagerListener : public DisplayManagerAgentDefault {
|
||||
class DisplayManager::Impl::DisplayManagerListener : public DisplayManagerAgentDefault {
|
||||
public:
|
||||
DisplayManagerListener(sptr<Impl> impl) : pImpl_(impl)
|
||||
{
|
||||
@@ -54,7 +72,7 @@ public:
|
||||
|
||||
void OnDisplayCreate(sptr<DisplayInfo> displayInfo) override
|
||||
{
|
||||
if (displayInfo == nullptr || displayInfo->id_ == DISPLAY_ID_INVALD) {
|
||||
if (displayInfo == nullptr || displayInfo->GetDisplayId() == DISPLAY_ID_INVALD) {
|
||||
WLOGFE("OnDisplayCreate, displayInfo is invalid.");
|
||||
return;
|
||||
}
|
||||
@@ -62,8 +80,9 @@ public:
|
||||
WLOGFE("OnDisplayCreate, impl is nullptr.");
|
||||
return;
|
||||
}
|
||||
pImpl_->NotifyDisplayCreate(displayInfo);
|
||||
for (auto listener : pImpl_->displayListeners_) {
|
||||
listener->OnCreate(displayInfo->id_);
|
||||
listener->OnCreate(displayInfo->GetDisplayId());
|
||||
}
|
||||
};
|
||||
|
||||
@@ -77,14 +96,15 @@ public:
|
||||
WLOGFE("OnDisplayDestroy, impl is nullptr.");
|
||||
return;
|
||||
}
|
||||
pImpl_->NotifyDisplayDestroy(displayId);
|
||||
for (auto listener : pImpl_->displayListeners_) {
|
||||
listener->OnDestroy(displayId);
|
||||
}
|
||||
};
|
||||
|
||||
void OnDisplayChange(const sptr<DisplayInfo> displayInfo, DisplayChangeEvent event) override
|
||||
void OnDisplayChange(sptr<DisplayInfo> displayInfo, DisplayChangeEvent event) override
|
||||
{
|
||||
if (displayInfo == nullptr || displayInfo->id_ == DISPLAY_ID_INVALD) {
|
||||
if (displayInfo == nullptr || displayInfo->GetDisplayId() == DISPLAY_ID_INVALD) {
|
||||
WLOGFE("OnDisplayChange, displayInfo is invalid.");
|
||||
return;
|
||||
}
|
||||
@@ -92,15 +112,36 @@ public:
|
||||
WLOGFE("OnDisplayChange, impl is nullptr.");
|
||||
return;
|
||||
}
|
||||
WLOGD("OnDisplayChange. display %{public}" PRIu64", event %{public}u", displayInfo->id_, event);
|
||||
WLOGD("OnDisplayChange. display %{public}" PRIu64", event %{public}u", displayInfo->GetDisplayId(), event);
|
||||
pImpl_->NotifyDisplayChange(displayInfo);
|
||||
for (auto listener : pImpl_->displayListeners_) {
|
||||
listener->OnChange(displayInfo->id_, event);
|
||||
listener->OnChange(displayInfo->GetDisplayId());
|
||||
}
|
||||
};
|
||||
private:
|
||||
sptr<Impl> pImpl_;
|
||||
};
|
||||
|
||||
class DisplayManager::Impl::DisplayManagerAgent : public DisplayManagerAgentDefault {
|
||||
public:
|
||||
DisplayManagerAgent(sptr<Impl> impl) : pImpl_(impl)
|
||||
{
|
||||
}
|
||||
~DisplayManagerAgent() = default;
|
||||
|
||||
virtual void NotifyDisplayPowerEvent(DisplayPowerEvent event, EventStatus status) override
|
||||
{
|
||||
pImpl_->NotifyDisplayPowerEvent(event, status);
|
||||
}
|
||||
|
||||
virtual void NotifyDisplayStateChanged(DisplayId id, DisplayState state) override
|
||||
{
|
||||
pImpl_->NotifyDisplayStateChanged(id, state);
|
||||
}
|
||||
private:
|
||||
sptr<Impl> pImpl_;
|
||||
};
|
||||
|
||||
bool DisplayManager::Impl::CheckRectValid(const Media::Rect& rect, int32_t oriHeight, int32_t oriWidth) const
|
||||
{
|
||||
if (!((rect.left >= 0) and (rect.left < oriWidth) and (rect.top >= 0) and (rect.top < oriHeight))) {
|
||||
@@ -136,6 +177,7 @@ bool DisplayManager::Impl::CheckSizeValid(const Media::Size& size, int32_t oriHe
|
||||
|
||||
void DisplayManager::Impl::ClearDisplayStateCallback()
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
displayStateCallback_ = nullptr;
|
||||
if (displayStateAgent_ != nullptr) {
|
||||
SingletonContainer::Get<DisplayManagerAdapter>().UnregisterDisplayManagerAgent(displayStateAgent_,
|
||||
@@ -157,16 +199,56 @@ DisplayId DisplayManager::GetDefaultDisplayId()
|
||||
return SingletonContainer::Get<DisplayManagerAdapter>().GetDefaultDisplayId();
|
||||
}
|
||||
|
||||
const sptr<Display> DisplayManager::GetDisplayById(DisplayId displayId)
|
||||
sptr<Display> DisplayManager::Impl::GetDisplayById(DisplayId displayId)
|
||||
{
|
||||
sptr<Display> display = SingletonContainer::Get<DisplayManagerAdapter>().GetDisplayById(displayId);
|
||||
if (display == nullptr) {
|
||||
WLOGFE("DisplayManager::GetDisplayById failed!\n");
|
||||
auto displayInfo = SingletonContainer::Get<DisplayManagerAdapter>().GetDisplayInfo(displayId);
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
if (!UpdateDisplayInfoLocked(displayInfo)) {
|
||||
displayMap_.erase(displayId);
|
||||
return nullptr;
|
||||
}
|
||||
return displayMap_[displayId];
|
||||
}
|
||||
|
||||
sptr<Display> DisplayManager::GetDisplayById(DisplayId displayId)
|
||||
{
|
||||
return pImpl_->GetDisplayById(displayId);
|
||||
}
|
||||
|
||||
sptr<Display> DisplayManager::GetDisplayByScreen(ScreenId screenId)
|
||||
{
|
||||
if (screenId == SCREEN_ID_INVALID) {
|
||||
WLOGFE("screenId is invalid.");
|
||||
return nullptr;
|
||||
}
|
||||
sptr<Display> display = pImpl_->GetDisplayByScreenId(screenId);
|
||||
if (display == nullptr) {
|
||||
WLOGFE("get display by screenId failed. screen %{public}" PRIu64"", screenId);
|
||||
}
|
||||
return display;
|
||||
}
|
||||
|
||||
sptr<Display> DisplayManager::Impl::GetDisplayByScreenId(ScreenId screenId)
|
||||
{
|
||||
sptr<DisplayInfo> displayInfo = SingletonContainer::Get<DisplayManagerAdapter>().GetDisplayInfoByScreenId(screenId);
|
||||
if (displayInfo == nullptr) {
|
||||
WLOGFE("get display by screenId: displayInfo is null");
|
||||
return nullptr;
|
||||
}
|
||||
DisplayId displayId = displayInfo->GetDisplayId();
|
||||
if (displayId == DISPLAY_ID_INVALD) {
|
||||
WLOGFE("get display by screenId: invalid displayInfo");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
if (!UpdateDisplayInfoLocked(displayInfo)) {
|
||||
displayMap_.erase(displayId);
|
||||
return nullptr;
|
||||
}
|
||||
return displayMap_[displayId];
|
||||
}
|
||||
|
||||
std::shared_ptr<Media::PixelMap> DisplayManager::GetScreenshot(DisplayId displayId)
|
||||
{
|
||||
if (displayId == DISPLAY_ID_INVALD) {
|
||||
@@ -227,27 +309,24 @@ std::shared_ptr<Media::PixelMap> DisplayManager::GetScreenshot(DisplayId display
|
||||
return dstScreenshot;
|
||||
}
|
||||
|
||||
const sptr<Display> DisplayManager::GetDefaultDisplay()
|
||||
sptr<Display> DisplayManager::GetDefaultDisplay()
|
||||
{
|
||||
return GetDisplayById(GetDefaultDisplayId());
|
||||
}
|
||||
|
||||
std::vector<DisplayId> DisplayManager::GetAllDisplayIds()
|
||||
{
|
||||
std::vector<DisplayId> res;
|
||||
res.push_back(GetDefaultDisplayId());
|
||||
// 获取所有displayIds
|
||||
return res;
|
||||
return SingletonContainer::Get<DisplayManagerAdapter>().GetAllDisplayIds();
|
||||
}
|
||||
|
||||
std::vector<const sptr<Display>> DisplayManager::GetAllDisplays()
|
||||
std::vector<sptr<Display>> DisplayManager::GetAllDisplays()
|
||||
{
|
||||
std::vector<const sptr<Display>> res;
|
||||
std::vector<sptr<Display>> res;
|
||||
auto displayIds = GetAllDisplayIds();
|
||||
for (auto displayId: displayIds) {
|
||||
const sptr<Display> display = GetDisplayById(displayId);
|
||||
if (display != nullptr) {
|
||||
res.push_back(display);
|
||||
res.emplace_back(display);
|
||||
} else {
|
||||
WLOGFE("DisplayManager::GetAllDisplays display %" PRIu64" nullptr!", displayId);
|
||||
}
|
||||
@@ -255,24 +334,48 @@ std::vector<const sptr<Display>> DisplayManager::GetAllDisplays()
|
||||
return res;
|
||||
}
|
||||
|
||||
bool DisplayManager::Impl::RegisterDisplayListener(sptr<IDisplayListener> listener)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
displayListeners_.push_back(listener);
|
||||
bool ret = true;
|
||||
if (displayManagerListener_ == nullptr) {
|
||||
displayManagerListener_ = new DisplayManagerListener(this);
|
||||
ret = SingletonContainer::Get<DisplayManagerAdapter>().RegisterDisplayManagerAgent(
|
||||
displayManagerListener_,
|
||||
DisplayManagerAgentType::DISPLAY_EVENT_LISTENER);
|
||||
if (!ret) {
|
||||
WLOGFW("RegisterDisplayManagerAgent failed ! remove listener!");
|
||||
displayListeners_.pop_back();
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool DisplayManager::RegisterDisplayListener(sptr<IDisplayListener> listener)
|
||||
{
|
||||
if (listener == nullptr) {
|
||||
WLOGFE("RegisterDisplayListener listener is nullptr.");
|
||||
return false;
|
||||
}
|
||||
std::lock_guard<std::recursive_mutex> lock(pImpl_->mutex_);
|
||||
pImpl_->displayListeners_.push_back(listener);
|
||||
return pImpl_->RegisterDisplayListener(listener);
|
||||
}
|
||||
|
||||
bool DisplayManager::Impl::UnregisterDisplayListener(sptr<IDisplayListener> listener)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
auto iter = std::find(displayListeners_.begin(), displayListeners_.end(), listener);
|
||||
if (iter == displayListeners_.end()) {
|
||||
WLOGFE("could not find this listener");
|
||||
return false;
|
||||
}
|
||||
displayListeners_.erase(iter);
|
||||
bool ret = true;
|
||||
if (displayManagerListener_ == nullptr) {
|
||||
displayManagerListener_ = new DisplayManagerListener(pImpl_);
|
||||
ret = SingletonContainer::Get<DisplayManagerAdapter>().RegisterDisplayManagerAgent(
|
||||
if (displayListeners_.empty() && displayManagerListener_ != nullptr) {
|
||||
ret = SingletonContainer::Get<DisplayManagerAdapter>().UnregisterDisplayManagerAgent(
|
||||
displayManagerListener_,
|
||||
DisplayManagerAgentType::DISPLAY_EVENT_LISTENER);
|
||||
if (!ret) {
|
||||
WLOGFW("RegisterDisplayManagerAgent failed ! remove listener!");
|
||||
pImpl_->displayListeners_.pop_back();
|
||||
}
|
||||
displayManagerListener_ = nullptr;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@@ -283,20 +386,25 @@ bool DisplayManager::UnregisterDisplayListener(sptr<IDisplayListener> listener)
|
||||
WLOGFE("UnregisterDisplayListener listener is nullptr.");
|
||||
return false;
|
||||
}
|
||||
std::lock_guard<std::recursive_mutex> lock(pImpl_->mutex_);
|
||||
auto iter = std::find(pImpl_->displayListeners_.begin(), pImpl_->displayListeners_.end(), listener);
|
||||
if (iter == pImpl_->displayListeners_.end()) {
|
||||
WLOGFE("could not find this listener");
|
||||
return false;
|
||||
}
|
||||
pImpl_->displayListeners_.erase(iter);
|
||||
return pImpl_->UnregisterDisplayListener(listener);
|
||||
}
|
||||
|
||||
bool DisplayManager::Impl::RegisterDisplayPowerEventListener(sptr<IDisplayPowerEventListener> listener)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
powerEventListeners_.push_back(listener);
|
||||
bool ret = true;
|
||||
if (pImpl_->displayListeners_.empty() && displayManagerListener_ != nullptr) {
|
||||
ret = SingletonContainer::Get<DisplayManagerAdapter>().UnregisterDisplayManagerAgent(
|
||||
displayManagerListener_,
|
||||
DisplayManagerAgentType::DISPLAY_EVENT_LISTENER);
|
||||
displayManagerListener_ = nullptr;
|
||||
if (powerEventListenerAgent_ == nullptr) {
|
||||
powerEventListenerAgent_ = new DisplayManagerAgent(this);
|
||||
ret = SingletonContainer::Get<DisplayManagerAdapter>().RegisterDisplayManagerAgent(
|
||||
powerEventListenerAgent_,
|
||||
DisplayManagerAgentType::DISPLAY_POWER_EVENT_LISTENER);
|
||||
if (!ret) {
|
||||
WLOGFW("RegisterDisplayManagerAgent failed ! remove listener!");
|
||||
powerEventListeners_.pop_back();
|
||||
}
|
||||
}
|
||||
WLOGFI("RegisterDisplayPowerEventListener end");
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -306,20 +414,26 @@ bool DisplayManager::RegisterDisplayPowerEventListener(sptr<IDisplayPowerEventLi
|
||||
WLOGFE("listener is nullptr");
|
||||
return false;
|
||||
}
|
||||
std::lock_guard<std::recursive_mutex> lock(pImpl_->mutex_);
|
||||
pImpl_->powerEventListeners_.push_back(listener);
|
||||
bool ret = true;
|
||||
if (pImpl_->powerEventListenerAgent_ == nullptr) {
|
||||
pImpl_->powerEventListenerAgent_ = new DisplayManagerAgent();
|
||||
ret = SingletonContainer::Get<DisplayManagerAdapter>().RegisterDisplayManagerAgent(
|
||||
pImpl_->powerEventListenerAgent_,
|
||||
DisplayManagerAgentType::DISPLAY_POWER_EVENT_LISTENER);
|
||||
if (!ret) {
|
||||
WLOGFW("RegisterDisplayManagerAgent failed ! remove listener!");
|
||||
pImpl_->powerEventListeners_.pop_back();
|
||||
}
|
||||
return pImpl_->RegisterDisplayPowerEventListener(listener);
|
||||
}
|
||||
|
||||
bool DisplayManager::Impl::UnregisterDisplayPowerEventListener(sptr<IDisplayPowerEventListener> listener)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
auto iter = std::find(powerEventListeners_.begin(), powerEventListeners_.end(), listener);
|
||||
if (iter == powerEventListeners_.end()) {
|
||||
WLOGFE("could not find this listener");
|
||||
return false;
|
||||
}
|
||||
WLOGFI("RegisterDisplayPowerEventListener end");
|
||||
powerEventListeners_.erase(iter);
|
||||
bool ret = true;
|
||||
if (powerEventListeners_.empty() && powerEventListenerAgent_ != nullptr) {
|
||||
ret = SingletonContainer::Get<DisplayManagerAdapter>().UnregisterDisplayManagerAgent(
|
||||
powerEventListenerAgent_,
|
||||
DisplayManagerAgentType::DISPLAY_POWER_EVENT_LISTENER);
|
||||
powerEventListenerAgent_ = nullptr;
|
||||
}
|
||||
WLOGFI("UnregisterDisplayPowerEventListener end");
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -329,54 +443,71 @@ bool DisplayManager::UnregisterDisplayPowerEventListener(sptr<IDisplayPowerEvent
|
||||
WLOGFE("listener is nullptr");
|
||||
return false;
|
||||
}
|
||||
|
||||
std::lock_guard<std::recursive_mutex> lock(pImpl_->mutex_);
|
||||
auto iter = std::find(pImpl_->powerEventListeners_.begin(), pImpl_->powerEventListeners_.end(), listener);
|
||||
if (iter == pImpl_->powerEventListeners_.end()) {
|
||||
WLOGFE("could not find this listener");
|
||||
return false;
|
||||
}
|
||||
pImpl_->powerEventListeners_.erase(iter);
|
||||
bool ret = true;
|
||||
if (pImpl_->powerEventListeners_.empty() && pImpl_->powerEventListenerAgent_ != nullptr) {
|
||||
ret = SingletonContainer::Get<DisplayManagerAdapter>().UnregisterDisplayManagerAgent(
|
||||
pImpl_->powerEventListenerAgent_,
|
||||
DisplayManagerAgentType::DISPLAY_POWER_EVENT_LISTENER);
|
||||
pImpl_->powerEventListenerAgent_ = nullptr;
|
||||
}
|
||||
WLOGFI("UnregisterDisplayPowerEventListener end");
|
||||
return ret;
|
||||
return pImpl_->UnregisterDisplayPowerEventListener(listener);
|
||||
}
|
||||
|
||||
void DisplayManager::NotifyDisplayPowerEvent(DisplayPowerEvent event, EventStatus status)
|
||||
void DisplayManager::Impl::NotifyDisplayPowerEvent(DisplayPowerEvent event, EventStatus status)
|
||||
{
|
||||
WLOGFI("NotifyDisplayPowerEvent event:%{public}u, status:%{public}u, size:%{public}zu", event, status,
|
||||
pImpl_->powerEventListeners_.size());
|
||||
std::lock_guard<std::recursive_mutex> lock(pImpl_->mutex_);
|
||||
for (auto& listener : pImpl_->powerEventListeners_) {
|
||||
powerEventListeners_.size());
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
for (auto& listener : powerEventListeners_) {
|
||||
listener->OnDisplayPowerEvent(event, status);
|
||||
}
|
||||
}
|
||||
|
||||
void DisplayManager::NotifyDisplayStateChanged(DisplayId id, DisplayState state)
|
||||
void DisplayManager::Impl::NotifyDisplayStateChanged(DisplayId id, DisplayState state)
|
||||
{
|
||||
WLOGFI("state:%{public}u", state);
|
||||
std::lock_guard<std::recursive_mutex> lock(pImpl_->mutex_);
|
||||
if (pImpl_->displayStateCallback_) {
|
||||
pImpl_->displayStateCallback_(state);
|
||||
pImpl_->ClearDisplayStateCallback();
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
if (displayStateCallback_) {
|
||||
displayStateCallback_(state);
|
||||
ClearDisplayStateCallback();
|
||||
return;
|
||||
}
|
||||
WLOGFW("callback_ target is not set!");
|
||||
}
|
||||
|
||||
void DisplayManager::NotifyDisplayChangedEvent(const sptr<DisplayInfo> info, DisplayChangeEvent event)
|
||||
void DisplayManager::Impl::NotifyDisplayCreate(sptr<DisplayInfo> info)
|
||||
{
|
||||
WLOGI("NotifyDisplayChangedEvent event:%{public}u, size:%{public}zu", event, pImpl_->displayListeners_.size());
|
||||
std::lock_guard<std::recursive_mutex> lock(pImpl_->mutex_);
|
||||
for (auto& listener : pImpl_->displayListeners_) {
|
||||
listener->OnChange(info->id_, event);
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
UpdateDisplayInfoLocked(info);
|
||||
}
|
||||
|
||||
void DisplayManager::Impl::NotifyDisplayDestroy(DisplayId displayId)
|
||||
{
|
||||
WLOGFI("displayId:%{public}" PRIu64".", displayId);
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
displayMap_.erase(displayId);
|
||||
}
|
||||
|
||||
void DisplayManager::Impl::NotifyDisplayChange(sptr<DisplayInfo> displayInfo)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
UpdateDisplayInfoLocked(displayInfo);
|
||||
}
|
||||
|
||||
bool DisplayManager::Impl::UpdateDisplayInfoLocked(sptr<DisplayInfo> displayInfo)
|
||||
{
|
||||
if (displayInfo == nullptr) {
|
||||
WLOGFE("displayInfo is null");
|
||||
return false;
|
||||
}
|
||||
DisplayId displayId = displayInfo->GetDisplayId();
|
||||
WLOGFI("displayId:%{public}" PRIu64".", displayId);
|
||||
if (displayId == DISPLAY_ID_INVALD) {
|
||||
WLOGFE("displayId is invalid.");
|
||||
return false;
|
||||
}
|
||||
auto iter = displayMap_.find(displayId);
|
||||
if (iter != displayMap_.end() && iter->second != nullptr) {
|
||||
WLOGFI("get screen in screen map");
|
||||
iter->second->UpdateDisplayInfo(displayInfo);
|
||||
return true;
|
||||
}
|
||||
sptr<Display> display = new Display("", displayInfo);
|
||||
displayMap_[displayId] = display;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DisplayManager::WakeUpBegin(PowerStateChangeReason reason)
|
||||
@@ -440,30 +571,37 @@ DisplayPowerState DisplayManager::GetScreenPower(uint64_t screenId)
|
||||
return res;
|
||||
}
|
||||
|
||||
bool DisplayManager::SetDisplayState(DisplayState state, DisplayStateCallback callback)
|
||||
bool DisplayManager::Impl::SetDisplayState(DisplayState state, DisplayStateCallback callback)
|
||||
{
|
||||
WLOGFI("state:%{public}u", state);
|
||||
std::lock_guard<std::recursive_mutex> lock(pImpl_->mutex_);
|
||||
if (pImpl_->displayStateCallback_ != nullptr || callback == nullptr) {
|
||||
WLOGFI("previous callback not called or callback invalid");
|
||||
return false;
|
||||
}
|
||||
pImpl_->displayStateCallback_ = callback;
|
||||
bool ret = true;
|
||||
if (pImpl_->displayStateAgent_ == nullptr) {
|
||||
pImpl_->displayStateAgent_ = new DisplayManagerAgent();
|
||||
ret = SingletonContainer::Get<DisplayManagerAdapter>().RegisterDisplayManagerAgent(
|
||||
pImpl_->displayStateAgent_,
|
||||
DisplayManagerAgentType::DISPLAY_STATE_LISTENER);
|
||||
}
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
if (displayStateCallback_ != nullptr || callback == nullptr) {
|
||||
WLOGFI("previous callback not called or callback invalid");
|
||||
return false;
|
||||
}
|
||||
displayStateCallback_ = callback;
|
||||
|
||||
ret &= SingletonContainer::Get<DisplayManagerAdapter>().SetDisplayState(state);
|
||||
if (displayStateAgent_ == nullptr) {
|
||||
displayStateAgent_ = new DisplayManagerAgent(this);
|
||||
ret = SingletonContainer::Get<DisplayManagerAdapter>().RegisterDisplayManagerAgent(
|
||||
displayStateAgent_,
|
||||
DisplayManagerAgentType::DISPLAY_STATE_LISTENER);
|
||||
}
|
||||
}
|
||||
ret = ret && SingletonContainer::Get<DisplayManagerAdapter>().SetDisplayState(state);
|
||||
if (!ret) {
|
||||
pImpl_->ClearDisplayStateCallback();
|
||||
ClearDisplayStateCallback();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool DisplayManager::SetDisplayState(DisplayState state, DisplayStateCallback callback)
|
||||
{
|
||||
return pImpl_->SetDisplayState(state, callback);
|
||||
}
|
||||
|
||||
DisplayState DisplayManager::GetDisplayState(DisplayId displayId)
|
||||
{
|
||||
return SingletonContainer::Get<DisplayManagerAdapter>().GetDisplayState(displayId);
|
||||
@@ -479,7 +617,7 @@ bool DisplayManager::SetScreenBrightness(uint64_t screenId, uint32_t level)
|
||||
uint32_t DisplayManager::GetScreenBrightness(uint64_t screenId) const
|
||||
{
|
||||
uint32_t level = static_cast<uint32_t>(RSInterfaces::GetInstance().GetScreenBacklight(screenId));
|
||||
WLOGFI("screenId:%{public}" PRIu64", level:%{public}u,", screenId, level);
|
||||
WLOGFD("screenId:%{public}" PRIu64", level:%{public}u,", screenId, level);
|
||||
return level;
|
||||
}
|
||||
|
||||
|
||||
+127
-202
@@ -26,210 +26,146 @@ namespace {
|
||||
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "DisplayManagerAdapter"};
|
||||
}
|
||||
WM_IMPLEMENT_SINGLE_INSTANCE(DisplayManagerAdapter)
|
||||
WM_IMPLEMENT_SINGLE_INSTANCE(ScreenManagerAdapter)
|
||||
|
||||
DisplayId DisplayManagerAdapter::GetDefaultDisplayId()
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
|
||||
if (defaultDisplayId_ != DISPLAY_ID_INVALD) {
|
||||
return defaultDisplayId_;
|
||||
}
|
||||
|
||||
if (!InitDMSProxyLocked()) {
|
||||
WLOGFE("displayManagerAdapter::GetDefaultDisplayId: InitDMSProxyLocked failed!");
|
||||
if (!InitDMSProxy()) {
|
||||
WLOGFE("displayManagerAdapter::GetDefaultDisplayId: InitDMSProxy failed!");
|
||||
return DISPLAY_ID_INVALD;
|
||||
}
|
||||
defaultDisplayId_ = displayManagerServiceProxy_->GetDefaultDisplayId();
|
||||
return defaultDisplayId_;
|
||||
return displayManagerServiceProxy_->GetDefaultDisplayId();
|
||||
}
|
||||
|
||||
sptr<Display> DisplayManagerAdapter::GetDisplayById(DisplayId displayId)
|
||||
sptr<DisplayInfo> DisplayManagerAdapter::GetDisplayInfoByScreenId(ScreenId screenId)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
|
||||
if (!InitDMSProxyLocked()) {
|
||||
WLOGFE("GetDisplayById: InitDMSProxyLocked failed!");
|
||||
if (!InitDMSProxy()) {
|
||||
WLOGFE("get display by screenId: init dms proxy failed!");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto iter = displayMap_.find(displayId);
|
||||
if (iter != displayMap_.end()) {
|
||||
// Update display in map
|
||||
// should be updated automatically
|
||||
DisplayInfo displayInfo = displayManagerServiceProxy_->GetDisplayInfoById(displayId);
|
||||
if (displayInfo.id_ == DISPLAY_ID_INVALD) {
|
||||
WLOGFE("GetDisplayById: Get invalid displayInfo!");
|
||||
return nullptr;
|
||||
}
|
||||
sptr<Display> display = iter->second;
|
||||
if (displayInfo.width_ != display->GetWidth()) {
|
||||
display->SetWidth(displayInfo.width_);
|
||||
WLOGFI("GetDisplayById: set new width %{public}d", display->GetWidth());
|
||||
}
|
||||
if (displayInfo.height_ != display->GetHeight()) {
|
||||
display->SetHeight(displayInfo.height_);
|
||||
WLOGFI("GetDisplayById: set new height %{public}d", display->GetHeight());
|
||||
}
|
||||
if (displayInfo.freshRate_ != display->GetFreshRate()) {
|
||||
display->SetFreshRate(displayInfo.freshRate_);
|
||||
WLOGFI("GetDisplayById: set new freshRate %{public}ud", display->GetFreshRate());
|
||||
}
|
||||
return iter->second;
|
||||
}
|
||||
DisplayInfo displayInfo = displayManagerServiceProxy_->GetDisplayInfoById(displayId);
|
||||
sptr<Display> display = new Display("", &displayInfo);
|
||||
if (display->GetId() != DISPLAY_ID_INVALD) {
|
||||
displayMap_[display->GetId()] = display;
|
||||
}
|
||||
return display;
|
||||
}
|
||||
|
||||
bool DisplayManagerAdapter::RequestRotation(ScreenId screenId, Rotation rotation)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
if (!InitDMSProxyLocked()) {
|
||||
WLOGFE("fail to request rotation: InitDMSProxyLocked failed!");
|
||||
return false;
|
||||
}
|
||||
|
||||
return displayManagerServiceProxy_->RequestRotation(screenId, rotation);
|
||||
return displayManagerServiceProxy_->GetDisplayInfoByScreen(screenId);
|
||||
}
|
||||
|
||||
std::shared_ptr<Media::PixelMap> DisplayManagerAdapter::GetDisplaySnapshot(DisplayId displayId)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
|
||||
if (!InitDMSProxyLocked()) {
|
||||
WLOGFE("displayManagerAdapter::GetDisplaySnapshot: InitDMSProxyLocked failed!");
|
||||
if (!InitDMSProxy()) {
|
||||
WLOGFE("GetDisplaySnapshot: init dms proxy failed!");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::shared_ptr<Media::PixelMap> dispalySnapshot = displayManagerServiceProxy_->GetDispalySnapshot(displayId);
|
||||
|
||||
return dispalySnapshot;
|
||||
return displayManagerServiceProxy_->GetDisplaySnapshot(displayId);
|
||||
}
|
||||
|
||||
DMError DisplayManagerAdapter::GetScreenSupportedColorGamuts(ScreenId screenId,
|
||||
DMError ScreenManagerAdapter::GetScreenSupportedColorGamuts(ScreenId screenId,
|
||||
std::vector<ScreenColorGamut>& colorGamuts)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
|
||||
if (!InitDMSProxyLocked()) {
|
||||
WLOGFE("displayManagerAdapter::GetScreenSupportedColorGamuts: InitDMSProxyLocked failed!");
|
||||
if (!InitDMSProxy()) {
|
||||
WLOGFE("displayManagerAdapter::GetScreenSupportedColorGamuts: InitDMSProxy failed!");
|
||||
return DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED;
|
||||
}
|
||||
|
||||
DMError ret = displayManagerServiceProxy_->GetScreenSupportedColorGamuts(screenId, colorGamuts);
|
||||
return ret;
|
||||
return displayManagerServiceProxy_->GetScreenSupportedColorGamuts(screenId, colorGamuts);
|
||||
}
|
||||
|
||||
DMError DisplayManagerAdapter::GetScreenColorGamut(ScreenId screenId, ScreenColorGamut& colorGamut)
|
||||
DMError ScreenManagerAdapter::GetScreenColorGamut(ScreenId screenId, ScreenColorGamut& colorGamut)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
|
||||
if (!InitDMSProxyLocked()) {
|
||||
WLOGFE("displayManagerAdapter::GetScreenColorGamut: InitDMSProxyLocked failed!");
|
||||
if (!InitDMSProxy()) {
|
||||
WLOGFE("displayManagerAdapter::GetScreenColorGamut: InitDMSProxy failed!");
|
||||
return DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED;
|
||||
}
|
||||
|
||||
DMError ret = displayManagerServiceProxy_->GetScreenColorGamut(screenId, colorGamut);
|
||||
return ret;
|
||||
return displayManagerServiceProxy_->GetScreenColorGamut(screenId, colorGamut);
|
||||
}
|
||||
|
||||
DMError DisplayManagerAdapter::SetScreenColorGamut(ScreenId screenId, int32_t colorGamutIdx)
|
||||
DMError ScreenManagerAdapter::SetScreenColorGamut(ScreenId screenId, int32_t colorGamutIdx)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
|
||||
if (!InitDMSProxyLocked()) {
|
||||
WLOGFE("displayManagerAdapter::SetScreenColorGamut: InitDMSProxyLocked failed!");
|
||||
if (!InitDMSProxy()) {
|
||||
WLOGFE("displayManagerAdapter::SetScreenColorGamut: InitDMSProxy failed!");
|
||||
return DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED;
|
||||
}
|
||||
|
||||
DMError ret = displayManagerServiceProxy_->SetScreenColorGamut(screenId, colorGamutIdx);
|
||||
return ret;
|
||||
return displayManagerServiceProxy_->SetScreenColorGamut(screenId, colorGamutIdx);
|
||||
}
|
||||
|
||||
DMError DisplayManagerAdapter::GetScreenGamutMap(ScreenId screenId, ScreenGamutMap& gamutMap)
|
||||
DMError ScreenManagerAdapter::GetScreenGamutMap(ScreenId screenId, ScreenGamutMap& gamutMap)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
|
||||
if (!InitDMSProxyLocked()) {
|
||||
WLOGFE("displayManagerAdapter::GetScreenGamutMap: InitDMSProxyLocked failed!");
|
||||
if (!InitDMSProxy()) {
|
||||
WLOGFE("displayManagerAdapter::GetScreenGamutMap: InitDMSProxy failed!");
|
||||
return DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED;
|
||||
}
|
||||
|
||||
DMError ret = displayManagerServiceProxy_->GetScreenGamutMap(screenId, gamutMap);
|
||||
return ret;
|
||||
return displayManagerServiceProxy_->GetScreenGamutMap(screenId, gamutMap);
|
||||
}
|
||||
|
||||
DMError DisplayManagerAdapter::SetScreenGamutMap(ScreenId screenId, ScreenGamutMap gamutMap)
|
||||
DMError ScreenManagerAdapter::SetScreenGamutMap(ScreenId screenId, ScreenGamutMap gamutMap)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
|
||||
if (!InitDMSProxyLocked()) {
|
||||
WLOGFE("displayManagerAdapter::SetScreenGamutMap: InitDMSProxyLocked failed!");
|
||||
if (!InitDMSProxy()) {
|
||||
WLOGFE("displayManagerAdapter::SetScreenGamutMap: InitDMSProxy failed!");
|
||||
return DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED;
|
||||
}
|
||||
|
||||
DMError ret = displayManagerServiceProxy_->SetScreenGamutMap(screenId, gamutMap);
|
||||
return ret;
|
||||
return displayManagerServiceProxy_->SetScreenGamutMap(screenId, gamutMap);
|
||||
}
|
||||
|
||||
DMError DisplayManagerAdapter::SetScreenColorTransform(ScreenId screenId)
|
||||
DMError ScreenManagerAdapter::SetScreenColorTransform(ScreenId screenId)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
|
||||
if (!InitDMSProxyLocked()) {
|
||||
WLOGFE("displayManagerAdapter::SetScreenColorTransform: InitDMSProxyLocked failed!");
|
||||
if (!InitDMSProxy()) {
|
||||
WLOGFE("displayManagerAdapter::SetScreenColorTransform: InitDMSProxy failed!");
|
||||
return DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED;
|
||||
}
|
||||
|
||||
DMError ret = displayManagerServiceProxy_->SetScreenColorTransform(screenId);
|
||||
return ret;
|
||||
return displayManagerServiceProxy_->SetScreenColorTransform(screenId);
|
||||
}
|
||||
|
||||
ScreenId DisplayManagerAdapter::CreateVirtualScreen(VirtualScreenOption option)
|
||||
ScreenId ScreenManagerAdapter::CreateVirtualScreen(VirtualScreenOption option)
|
||||
{
|
||||
if (!InitDMSProxyLocked()) {
|
||||
if (!InitDMSProxy()) {
|
||||
return SCREEN_ID_INVALID;
|
||||
}
|
||||
WLOGFI("DisplayManagerAdapter::CreateVirtualScreen");
|
||||
return displayManagerServiceProxy_->CreateVirtualScreen(option);
|
||||
}
|
||||
|
||||
DMError DisplayManagerAdapter::DestroyVirtualScreen(ScreenId screenId)
|
||||
DMError ScreenManagerAdapter::DestroyVirtualScreen(ScreenId screenId)
|
||||
{
|
||||
if (!InitDMSProxyLocked()) {
|
||||
if (!InitDMSProxy()) {
|
||||
return DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED;
|
||||
}
|
||||
WLOGFI("DisplayManagerAdapter::DestroyVirtualScreen");
|
||||
return displayManagerServiceProxy_->DestroyVirtualScreen(screenId);
|
||||
}
|
||||
|
||||
DMError DisplayManagerAdapter::SetVirtualScreenSurface(ScreenId screenId, sptr<Surface> surface)
|
||||
DMError ScreenManagerAdapter::SetVirtualScreenSurface(ScreenId screenId, sptr<Surface> surface)
|
||||
{
|
||||
if (!InitDMSProxyLocked()) {
|
||||
if (!InitDMSProxy()) {
|
||||
return DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED;
|
||||
}
|
||||
WLOGFI("DisplayManagerAdapter::SetVirtualScreenSurface");
|
||||
return displayManagerServiceProxy_->SetVirtualScreenSurface(screenId, surface);
|
||||
}
|
||||
|
||||
bool DisplayManagerAdapter::RegisterDisplayManagerAgent(const sptr<IDisplayManagerAgent>& displayManagerAgent,
|
||||
bool ScreenManagerAdapter::SetOrientation(ScreenId screenId, Orientation orientation)
|
||||
{
|
||||
if (!InitDMSProxy()) {
|
||||
WLOGFE("fail to set orientation: InitDMSProxy failed!");
|
||||
return false;
|
||||
}
|
||||
return displayManagerServiceProxy_->SetOrientation(screenId, orientation);
|
||||
}
|
||||
|
||||
bool BaseAdapter::RegisterDisplayManagerAgent(const sptr<IDisplayManagerAgent>& displayManagerAgent,
|
||||
DisplayManagerAgentType type)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
if (!InitDMSProxyLocked()) {
|
||||
if (!InitDMSProxy()) {
|
||||
return false;
|
||||
}
|
||||
return displayManagerServiceProxy_->RegisterDisplayManagerAgent(displayManagerAgent, type);
|
||||
}
|
||||
|
||||
bool DisplayManagerAdapter::UnregisterDisplayManagerAgent(const sptr<IDisplayManagerAgent>& displayManagerAgent,
|
||||
bool BaseAdapter::UnregisterDisplayManagerAgent(const sptr<IDisplayManagerAgent>& displayManagerAgent,
|
||||
DisplayManagerAgentType type)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
if (!InitDMSProxyLocked()) {
|
||||
if (!InitDMSProxy()) {
|
||||
return false;
|
||||
}
|
||||
return displayManagerServiceProxy_->UnregisterDisplayManagerAgent(displayManagerAgent, type);
|
||||
@@ -237,8 +173,7 @@ bool DisplayManagerAdapter::UnregisterDisplayManagerAgent(const sptr<IDisplayMan
|
||||
|
||||
bool DisplayManagerAdapter::WakeUpBegin(PowerStateChangeReason reason)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
if (!InitDMSProxyLocked()) {
|
||||
if (!InitDMSProxy()) {
|
||||
return false;
|
||||
}
|
||||
return displayManagerServiceProxy_->WakeUpBegin(reason);
|
||||
@@ -246,8 +181,7 @@ bool DisplayManagerAdapter::WakeUpBegin(PowerStateChangeReason reason)
|
||||
|
||||
bool DisplayManagerAdapter::WakeUpEnd()
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
if (!InitDMSProxyLocked()) {
|
||||
if (!InitDMSProxy()) {
|
||||
return false;
|
||||
}
|
||||
return displayManagerServiceProxy_->WakeUpEnd();
|
||||
@@ -255,8 +189,7 @@ bool DisplayManagerAdapter::WakeUpEnd()
|
||||
|
||||
bool DisplayManagerAdapter::SuspendBegin(PowerStateChangeReason reason)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
if (!InitDMSProxyLocked()) {
|
||||
if (!InitDMSProxy()) {
|
||||
return false;
|
||||
}
|
||||
return displayManagerServiceProxy_->SuspendBegin(reason);
|
||||
@@ -264,8 +197,7 @@ bool DisplayManagerAdapter::SuspendBegin(PowerStateChangeReason reason)
|
||||
|
||||
bool DisplayManagerAdapter::SuspendEnd()
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
if (!InitDMSProxyLocked()) {
|
||||
if (!InitDMSProxy()) {
|
||||
return false;
|
||||
}
|
||||
return displayManagerServiceProxy_->SuspendEnd();
|
||||
@@ -273,8 +205,7 @@ bool DisplayManagerAdapter::SuspendEnd()
|
||||
|
||||
bool DisplayManagerAdapter::SetScreenPowerForAll(DisplayPowerState state, PowerStateChangeReason reason)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
if (!InitDMSProxyLocked()) {
|
||||
if (!InitDMSProxy()) {
|
||||
return false;
|
||||
}
|
||||
return displayManagerServiceProxy_->SetScreenPowerForAll(state, reason);
|
||||
@@ -283,8 +214,7 @@ bool DisplayManagerAdapter::SetScreenPowerForAll(DisplayPowerState state, PowerS
|
||||
|
||||
bool DisplayManagerAdapter::SetDisplayState(DisplayState state)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
if (!InitDMSProxyLocked()) {
|
||||
if (!InitDMSProxy()) {
|
||||
return false;
|
||||
}
|
||||
return displayManagerServiceProxy_->SetDisplayState(state);
|
||||
@@ -292,8 +222,7 @@ bool DisplayManagerAdapter::SetDisplayState(DisplayState state)
|
||||
|
||||
DisplayState DisplayManagerAdapter::GetDisplayState(DisplayId displayId)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
if (!InitDMSProxyLocked()) {
|
||||
if (!InitDMSProxy()) {
|
||||
return DisplayState::UNKNOWN;
|
||||
}
|
||||
return displayManagerServiceProxy_->GetDisplayState(displayId);
|
||||
@@ -301,16 +230,16 @@ DisplayState DisplayManagerAdapter::GetDisplayState(DisplayId displayId)
|
||||
|
||||
void DisplayManagerAdapter::NotifyDisplayEvent(DisplayEvent event)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
if (!InitDMSProxyLocked()) {
|
||||
if (!InitDMSProxy()) {
|
||||
return;
|
||||
}
|
||||
displayManagerServiceProxy_->NotifyDisplayEvent(event);
|
||||
}
|
||||
|
||||
bool DisplayManagerAdapter::InitDMSProxyLocked()
|
||||
bool BaseAdapter::InitDMSProxy()
|
||||
{
|
||||
if (!displayManagerServiceProxy_) {
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
if (!isProxyValid_) {
|
||||
sptr<ISystemAbilityManager> systemAbilityManager =
|
||||
SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
|
||||
if (!systemAbilityManager) {
|
||||
@@ -331,7 +260,7 @@ bool DisplayManagerAdapter::InitDMSProxyLocked()
|
||||
return false;
|
||||
}
|
||||
|
||||
dmsDeath_ = new DMSDeathRecipient();
|
||||
dmsDeath_ = new DMSDeathRecipient(*this);
|
||||
if (!dmsDeath_) {
|
||||
WLOGFE("Failed to create death Recipient ptr DMSDeathRecipient");
|
||||
return false;
|
||||
@@ -340,10 +269,15 @@ bool DisplayManagerAdapter::InitDMSProxyLocked()
|
||||
WLOGFE("Failed to add death recipient");
|
||||
return false;
|
||||
}
|
||||
isProxyValid_ = true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
DMSDeathRecipient::DMSDeathRecipient(BaseAdapter& adapter) : adapter_(adapter)
|
||||
{
|
||||
}
|
||||
|
||||
void DMSDeathRecipient::OnRemoteDied(const wptr<IRemoteObject>& wptrDeath)
|
||||
{
|
||||
if (wptrDeath == nullptr) {
|
||||
@@ -356,114 +290,105 @@ void DMSDeathRecipient::OnRemoteDied(const wptr<IRemoteObject>& wptrDeath)
|
||||
WLOGFE("object is null");
|
||||
return;
|
||||
}
|
||||
SingletonContainer::Get<DisplayManagerAdapter>().Clear();
|
||||
adapter_.Clear();
|
||||
return;
|
||||
}
|
||||
|
||||
void DisplayManagerAdapter::Clear()
|
||||
void BaseAdapter::Clear()
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
if ((displayManagerServiceProxy_ != nullptr) && (displayManagerServiceProxy_->AsObject() != nullptr)) {
|
||||
displayManagerServiceProxy_->AsObject()->RemoveDeathRecipient(dmsDeath_);
|
||||
}
|
||||
displayManagerServiceProxy_ = nullptr;
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
isProxyValid_ = false;
|
||||
}
|
||||
|
||||
DMError DisplayManagerAdapter::MakeMirror(ScreenId mainScreenId, std::vector<ScreenId> mirrorScreenId)
|
||||
ScreenId ScreenManagerAdapter::MakeMirror(ScreenId mainScreenId, std::vector<ScreenId> mirrorScreenId)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
if (!InitDMSProxyLocked()) {
|
||||
return DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED;
|
||||
if (!InitDMSProxy()) {
|
||||
return SCREEN_ID_INVALID;
|
||||
}
|
||||
return displayManagerServiceProxy_->MakeMirror(mainScreenId, mirrorScreenId);
|
||||
}
|
||||
|
||||
sptr<Screen> DisplayManagerAdapter::GetScreenById(ScreenId screenId)
|
||||
sptr<ScreenInfo> ScreenManagerAdapter::GetScreenInfo(ScreenId screenId)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
if (screenId == SCREEN_ID_INVALID) {
|
||||
WLOGFE("screen id is invalid");
|
||||
return nullptr;
|
||||
}
|
||||
auto iter = screenMap_.find(screenId);
|
||||
if (iter != screenMap_.end()) {
|
||||
WLOGFI("get screen in screen map");
|
||||
return iter->second;
|
||||
}
|
||||
|
||||
if (!InitDMSProxyLocked()) {
|
||||
WLOGFE("InitDMSProxyLocked failed!");
|
||||
if (!InitDMSProxy()) {
|
||||
WLOGFE("InitDMSProxy failed!");
|
||||
return nullptr;
|
||||
}
|
||||
sptr<ScreenInfo> screenInfo = displayManagerServiceProxy_->GetScreenInfoById(screenId);
|
||||
if (screenInfo == nullptr) {
|
||||
WLOGFE("screenInfo is null");
|
||||
return nullptr;
|
||||
}
|
||||
sptr<Screen> screen = new Screen(screenInfo.GetRefPtr());
|
||||
screenMap_.insert(std::make_pair(screenId, screen));
|
||||
return screen;
|
||||
return screenInfo;
|
||||
}
|
||||
|
||||
sptr<ScreenGroup> DisplayManagerAdapter::GetScreenGroupById(ScreenId screenId)
|
||||
std::vector<DisplayId> DisplayManagerAdapter::GetAllDisplayIds()
|
||||
{
|
||||
if (!InitDMSProxy()) {
|
||||
WLOGFE("InitDMSProxyLocked failed!");
|
||||
return {};
|
||||
}
|
||||
return displayManagerServiceProxy_->GetAllDisplayIds();
|
||||
}
|
||||
|
||||
sptr<DisplayInfo> DisplayManagerAdapter::GetDisplayInfo(DisplayId displayId)
|
||||
{
|
||||
if (displayId == DISPLAY_ID_INVALD) {
|
||||
WLOGFE("screen id is invalid");
|
||||
return nullptr;
|
||||
}
|
||||
if (!InitDMSProxy()) {
|
||||
WLOGFE("InitDMSProxy failed!");
|
||||
return nullptr;
|
||||
}
|
||||
return displayManagerServiceProxy_->GetDisplayInfoById(displayId);
|
||||
}
|
||||
|
||||
sptr<ScreenGroupInfo> ScreenManagerAdapter::GetScreenGroupInfoById(ScreenId screenId)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
if (screenId == SCREEN_ID_INVALID) {
|
||||
WLOGFE("screenGroup id is invalid");
|
||||
return nullptr;
|
||||
}
|
||||
auto iter = screenGroupMap_.find(screenId);
|
||||
if (iter != screenGroupMap_.end()) {
|
||||
WLOGFI("get screenGroup in screenGroup map");
|
||||
return iter->second;
|
||||
}
|
||||
|
||||
if (!InitDMSProxyLocked()) {
|
||||
WLOGFE("InitDMSProxyLocked failed!");
|
||||
if (!InitDMSProxy()) {
|
||||
WLOGFE("InitDMSProxy failed!");
|
||||
return nullptr;
|
||||
}
|
||||
sptr<ScreenGroupInfo> screenGroupInfo = displayManagerServiceProxy_->GetScreenGroupInfoById(screenId);
|
||||
if (screenGroupInfo == nullptr) {
|
||||
WLOGFE("screenGroupInfo is null");
|
||||
return nullptr;
|
||||
}
|
||||
sptr<ScreenGroup> screenGroup = new ScreenGroup(screenGroupInfo.GetRefPtr());
|
||||
screenGroupMap_.insert(std::make_pair(screenId, screenGroup));
|
||||
return screenGroup;
|
||||
return displayManagerServiceProxy_->GetScreenGroupInfoById(screenId);
|
||||
}
|
||||
|
||||
std::vector<sptr<Screen>> DisplayManagerAdapter::GetAllScreens()
|
||||
std::vector<sptr<ScreenInfo>> ScreenManagerAdapter::GetAllScreenInfos()
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
std::vector<sptr<Screen>> screens;
|
||||
if (!InitDMSProxyLocked()) {
|
||||
WLOGFE("InitDMSProxyLocked failed!");
|
||||
return screens;
|
||||
if (!InitDMSProxy()) {
|
||||
WLOGFE("InitDMSProxy failed!");
|
||||
std::vector<sptr<ScreenInfo>> result;
|
||||
return result;
|
||||
}
|
||||
std::vector<sptr<ScreenInfo>> screenInfos = displayManagerServiceProxy_->GetAllScreenInfos();
|
||||
for (auto info: screenInfos) {
|
||||
if (info == nullptr) {
|
||||
WLOGFE("screenInfo is null");
|
||||
continue;
|
||||
}
|
||||
screens.emplace_back(new Screen(info.GetRefPtr()));
|
||||
}
|
||||
return screens;
|
||||
return displayManagerServiceProxy_->GetAllScreenInfos();
|
||||
}
|
||||
|
||||
DMError DisplayManagerAdapter::MakeExpand(std::vector<ScreenId> screenId, std::vector<Point> startPoint)
|
||||
ScreenId ScreenManagerAdapter::MakeExpand(std::vector<ScreenId> screenId, std::vector<Point> startPoint)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
if (!InitDMSProxyLocked()) {
|
||||
return DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED;
|
||||
if (!InitDMSProxy()) {
|
||||
return SCREEN_ID_INVALID;
|
||||
}
|
||||
return displayManagerServiceProxy_->MakeExpand(screenId, startPoint);
|
||||
}
|
||||
|
||||
bool DisplayManagerAdapter::SetScreenActiveMode(ScreenId screenId, uint32_t modeId)
|
||||
void ScreenManagerAdapter::RemoveVirtualScreenFromGroup(std::vector<ScreenId> screens)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
if (!InitDMSProxyLocked()) {
|
||||
if (!InitDMSProxy()) {
|
||||
return;
|
||||
}
|
||||
displayManagerServiceProxy_->RemoveVirtualScreenFromGroup(screens);
|
||||
}
|
||||
|
||||
bool ScreenManagerAdapter::SetScreenActiveMode(ScreenId screenId, uint32_t modeId)
|
||||
{
|
||||
if (!InitDMSProxy()) {
|
||||
return false;
|
||||
}
|
||||
return displayManagerServiceProxy_->SetScreenActiveMode(screenId, modeId);
|
||||
|
||||
+73
-54
@@ -16,7 +16,6 @@
|
||||
#include "screen.h"
|
||||
|
||||
#include "display_manager_adapter.h"
|
||||
#include "screen_group.h"
|
||||
#include "screen_info.h"
|
||||
#include "window_manager_hilog.h"
|
||||
|
||||
@@ -25,37 +24,18 @@ namespace {
|
||||
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "Screen"};
|
||||
}
|
||||
class Screen::Impl : public RefBase {
|
||||
friend class Screen;
|
||||
public:
|
||||
Impl() = default;
|
||||
Impl(sptr<ScreenInfo> info)
|
||||
{
|
||||
screenInfo_ = info;
|
||||
}
|
||||
~Impl() = default;
|
||||
|
||||
ScreenId id_ { SCREEN_ID_INVALID };
|
||||
uint32_t virtualWidth_ { 0 };
|
||||
uint32_t virtualHeight_ { 0 };
|
||||
float virtualPixelRatio_ { 0.0 };
|
||||
ScreenId parent_ { SCREEN_ID_INVALID };
|
||||
bool canHasChild_ { false };
|
||||
uint32_t modeId_ { 0 };
|
||||
std::vector<sptr<SupportedScreenModes>> modes_ {};
|
||||
Rotation rotation_ { Rotation::ROTATION_0 };
|
||||
DEFINE_VAR_FUNC_GET_SET(sptr<ScreenInfo>, ScreenInfo, screenInfo);
|
||||
};
|
||||
|
||||
Screen::Screen(const ScreenInfo* info)
|
||||
: pImpl_(new Impl())
|
||||
Screen::Screen(sptr<ScreenInfo> info)
|
||||
: pImpl_(new Impl(info))
|
||||
{
|
||||
if (info == nullptr) {
|
||||
WLOGFE("info is nullptr.");
|
||||
return;
|
||||
}
|
||||
pImpl_->id_ = info->id_;
|
||||
pImpl_->virtualWidth_ = info->virtualWidth_;
|
||||
pImpl_->virtualHeight_ = info->virtualHeight_;
|
||||
pImpl_->virtualPixelRatio_ = info->virtualPixelRatio_;
|
||||
pImpl_->parent_ = info->parent_;
|
||||
pImpl_->canHasChild_ = info->canHasChild_;
|
||||
pImpl_->modeId_ = info->modeId_;
|
||||
pImpl_->modes_ = info->modes_;
|
||||
}
|
||||
|
||||
Screen::~Screen()
|
||||
@@ -64,18 +44,25 @@ Screen::~Screen()
|
||||
|
||||
bool Screen::IsGroup() const
|
||||
{
|
||||
return pImpl_->canHasChild_;
|
||||
UpdateScreenInfo();
|
||||
return pImpl_->GetScreenInfo()->GetCanHasChild();
|
||||
}
|
||||
|
||||
const std::string& Screen::GetName() const
|
||||
{
|
||||
return pImpl_->GetScreenInfo()->GetName();
|
||||
}
|
||||
|
||||
ScreenId Screen::GetId() const
|
||||
{
|
||||
return pImpl_->id_;
|
||||
return pImpl_->GetScreenInfo()->GetScreenId();
|
||||
}
|
||||
|
||||
uint32_t Screen::GetWidth() const
|
||||
{
|
||||
auto modeId = pImpl_->modeId_;
|
||||
auto modes = pImpl_->modes_;
|
||||
UpdateScreenInfo();
|
||||
auto modeId = GetModeId();
|
||||
auto modes = GetSupportedModes();
|
||||
if (modeId < 0 || modeId >= modes.size()) {
|
||||
return 0;
|
||||
}
|
||||
@@ -84,8 +71,9 @@ uint32_t Screen::GetWidth() const
|
||||
|
||||
uint32_t Screen::GetHeight() const
|
||||
{
|
||||
auto modeId = pImpl_->modeId_;
|
||||
auto modes = pImpl_->modes_;
|
||||
UpdateScreenInfo();
|
||||
auto modeId = GetModeId();
|
||||
auto modes = GetSupportedModes();
|
||||
if (modeId < 0 || modeId >= modes.size()) {
|
||||
return 0;
|
||||
}
|
||||
@@ -94,85 +82,116 @@ uint32_t Screen::GetHeight() const
|
||||
|
||||
uint32_t Screen::GetVirtualWidth() const
|
||||
{
|
||||
return pImpl_->virtualWidth_;
|
||||
UpdateScreenInfo();
|
||||
return pImpl_->GetScreenInfo()->GetVirtualWidth();
|
||||
}
|
||||
|
||||
uint32_t Screen::GetVirtualHeight() const
|
||||
{
|
||||
return pImpl_->virtualHeight_;
|
||||
UpdateScreenInfo();
|
||||
return pImpl_->GetScreenInfo()->GetVirtualHeight();
|
||||
}
|
||||
|
||||
float Screen::GetVirtualPixelRatio() const
|
||||
{
|
||||
return pImpl_->virtualPixelRatio_;
|
||||
UpdateScreenInfo();
|
||||
return pImpl_->GetScreenInfo()->GetVirtualPixelRatio();
|
||||
}
|
||||
|
||||
Rotation Screen::GetRotation()
|
||||
Rotation Screen::GetRotation() const
|
||||
{
|
||||
return pImpl_->rotation_;
|
||||
UpdateScreenInfo();
|
||||
return pImpl_->GetScreenInfo()->GetRotation();
|
||||
}
|
||||
|
||||
bool Screen::RequestRotation(Rotation rotation)
|
||||
Orientation Screen::GetOrientation() const
|
||||
{
|
||||
WLOGFD("rotation the screen");
|
||||
return SingletonContainer::Get<DisplayManagerAdapter>().RequestRotation(pImpl_->id_, rotation);
|
||||
UpdateScreenInfo();
|
||||
return pImpl_->GetScreenInfo()->GetOrientation();
|
||||
}
|
||||
|
||||
bool Screen::IsReal() const
|
||||
{
|
||||
UpdateScreenInfo();
|
||||
return pImpl_->GetScreenInfo()->GetType() == ScreenType::REAL;
|
||||
}
|
||||
|
||||
bool Screen::SetOrientation(Orientation orientation) const
|
||||
{
|
||||
WLOGFD("set orientation %{public}u", orientation);
|
||||
return SingletonContainer::Get<ScreenManagerAdapter>().SetOrientation(GetId(), orientation);
|
||||
}
|
||||
|
||||
DMError Screen::GetScreenSupportedColorGamuts(std::vector<ScreenColorGamut>& colorGamuts) const
|
||||
{
|
||||
return SingletonContainer::Get<DisplayManagerAdapter>().GetScreenSupportedColorGamuts(pImpl_->id_, colorGamuts);
|
||||
return SingletonContainer::Get<ScreenManagerAdapter>().GetScreenSupportedColorGamuts(GetId(), colorGamuts);
|
||||
}
|
||||
|
||||
DMError Screen::GetScreenColorGamut(ScreenColorGamut& colorGamut) const
|
||||
{
|
||||
return SingletonContainer::Get<DisplayManagerAdapter>().GetScreenColorGamut(pImpl_->id_, colorGamut);
|
||||
return SingletonContainer::Get<ScreenManagerAdapter>().GetScreenColorGamut(GetId(), colorGamut);
|
||||
}
|
||||
|
||||
DMError Screen::SetScreenColorGamut(int32_t colorGamutIdx)
|
||||
{
|
||||
return SingletonContainer::Get<DisplayManagerAdapter>().SetScreenColorGamut(pImpl_->id_, colorGamutIdx);
|
||||
return SingletonContainer::Get<ScreenManagerAdapter>().SetScreenColorGamut(GetId(), colorGamutIdx);
|
||||
}
|
||||
|
||||
DMError Screen::GetScreenGamutMap(ScreenGamutMap& gamutMap) const
|
||||
{
|
||||
return SingletonContainer::Get<DisplayManagerAdapter>().GetScreenGamutMap(pImpl_->id_, gamutMap);
|
||||
return SingletonContainer::Get<ScreenManagerAdapter>().GetScreenGamutMap(GetId(), gamutMap);
|
||||
}
|
||||
|
||||
DMError Screen::SetScreenGamutMap(ScreenGamutMap gamutMap)
|
||||
{
|
||||
return SingletonContainer::Get<DisplayManagerAdapter>().SetScreenGamutMap(pImpl_->id_, gamutMap);
|
||||
return SingletonContainer::Get<ScreenManagerAdapter>().SetScreenGamutMap(GetId(), gamutMap);
|
||||
}
|
||||
|
||||
DMError Screen::SetScreenColorTransform()
|
||||
{
|
||||
return SingletonContainer::Get<DisplayManagerAdapter>().SetScreenColorTransform(pImpl_->id_);
|
||||
return SingletonContainer::Get<ScreenManagerAdapter>().SetScreenColorTransform(GetId());
|
||||
}
|
||||
|
||||
ScreenId Screen::GetParentId() const
|
||||
{
|
||||
return pImpl_->parent_;
|
||||
return pImpl_->GetScreenInfo()->GetParentId();
|
||||
}
|
||||
|
||||
uint32_t Screen::GetModeId() const
|
||||
{
|
||||
return pImpl_->modeId_;
|
||||
return pImpl_->GetScreenInfo()->GetModeId();
|
||||
}
|
||||
|
||||
std::vector<sptr<SupportedScreenModes>> Screen::GetSupportedModes() const
|
||||
{
|
||||
return pImpl_->modes_;
|
||||
return pImpl_->GetScreenInfo()->GetModes();
|
||||
}
|
||||
|
||||
bool Screen::SetScreenActiveMode(uint32_t modeId)
|
||||
{
|
||||
ScreenId screenId = pImpl_->id_;
|
||||
if (modeId < 0 || modeId >= pImpl_->modes_.size()) {
|
||||
ScreenId screenId = GetId();
|
||||
if (modeId >= GetSupportedModes().size()) {
|
||||
return false;
|
||||
}
|
||||
if (SingletonContainer::Get<DisplayManagerAdapter>().SetScreenActiveMode(screenId, modeId)) {
|
||||
pImpl_->modeId_ = modeId;
|
||||
if (SingletonContainer::Get<ScreenManagerAdapter>().SetScreenActiveMode(screenId, modeId)) {
|
||||
pImpl_->GetScreenInfo()->SetModeId(modeId);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void Screen::UpdateScreenInfo(sptr<ScreenInfo> info) const
|
||||
{
|
||||
if (info == nullptr) {
|
||||
WLOGFE("ScreenInfo is invalid");
|
||||
return;
|
||||
}
|
||||
pImpl_->SetScreenInfo(info);
|
||||
}
|
||||
|
||||
void Screen::UpdateScreenInfo() const
|
||||
{
|
||||
auto screenInfo = SingletonContainer::Get<ScreenManagerAdapter>().GetScreenInfo(GetId());
|
||||
UpdateScreenInfo(screenInfo);
|
||||
}
|
||||
} // namespace OHOS::Rosen
|
||||
+22
-15
@@ -23,26 +23,28 @@ namespace {
|
||||
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "ScreenGroup"};
|
||||
}
|
||||
class ScreenGroup::Impl : public RefBase {
|
||||
friend class ScreenGroup;
|
||||
private:
|
||||
Impl() = default;
|
||||
public:
|
||||
Impl(sptr<ScreenGroupInfo> info)
|
||||
{
|
||||
screenGroupInfo_ = info;
|
||||
}
|
||||
~Impl() = default;
|
||||
|
||||
std::vector<ScreenId> children_;
|
||||
std::vector<Point> position_;
|
||||
ScreenCombination combination_ { ScreenCombination::SCREEN_ALONE };
|
||||
DEFINE_VAR_FUNC_GET_SET(sptr<ScreenGroupInfo>, ScreenGroupInfo, screenGroupInfo);
|
||||
};
|
||||
|
||||
ScreenGroup::ScreenGroup(const ScreenGroupInfo* info)
|
||||
: Screen(info), pImpl_(new Impl())
|
||||
ScreenGroup::ScreenGroup(sptr<ScreenGroupInfo> info)
|
||||
: Screen(info), pImpl_(new Impl(info))
|
||||
{
|
||||
}
|
||||
|
||||
void ScreenGroup::UpdateScreenGroupInfo(sptr<ScreenGroupInfo> info)
|
||||
{
|
||||
if (info == nullptr) {
|
||||
WLOGFE("info is nullptr.");
|
||||
WLOGFE("ScreenGroupInfo is nullptr.");
|
||||
return;
|
||||
}
|
||||
pImpl_->children_ = info->children_;
|
||||
pImpl_->position_ = info->position_;
|
||||
pImpl_->combination_ = info->combination_;
|
||||
pImpl_->SetScreenGroupInfo(info);
|
||||
}
|
||||
|
||||
ScreenGroup::~ScreenGroup()
|
||||
@@ -51,11 +53,16 @@ ScreenGroup::~ScreenGroup()
|
||||
|
||||
ScreenCombination ScreenGroup::GetCombination() const
|
||||
{
|
||||
return pImpl_->combination_;
|
||||
return pImpl_->GetScreenGroupInfo()->GetCombination();
|
||||
}
|
||||
|
||||
std::vector<ScreenId> ScreenGroup::GetChildrenIds() const
|
||||
std::vector<ScreenId> ScreenGroup::GetChildIds() const
|
||||
{
|
||||
return pImpl_->children_;
|
||||
return pImpl_->GetScreenGroupInfo()->GetChildren();
|
||||
}
|
||||
|
||||
std::vector<Point> ScreenGroup::GetChildPositions() const
|
||||
{
|
||||
return pImpl_->GetScreenGroupInfo()->GetPosition();
|
||||
}
|
||||
} // namespace OHOS::Rosen
|
||||
+243
-38
@@ -30,12 +30,31 @@ public:
|
||||
Impl() = default;
|
||||
~Impl() = default;
|
||||
static inline SingletonDelegator<ScreenManager> delegator;
|
||||
bool RegisterScreenListener(sptr<IScreenListener> listener);
|
||||
bool UnregisterScreenListener(sptr<IScreenListener> listener);
|
||||
bool RegisterScreenGroupListener(sptr<IScreenGroupListener> listener);
|
||||
bool UnregisterScreenGroupListener(sptr<IScreenGroupListener> listener);
|
||||
sptr<Screen> GetScreen(ScreenId screenId);
|
||||
sptr<ScreenGroup> GetScreenGroup(ScreenId screenId);
|
||||
std::vector<sptr<Screen>> GetAllScreens();
|
||||
|
||||
private:
|
||||
void NotifyScreenConnect(sptr<ScreenInfo> info);
|
||||
void NotifyScreenDisconnect(ScreenId);
|
||||
void NotifyScreenChange(const sptr<ScreenInfo>& screenInfo);
|
||||
void NotifyScreenChange(const std::vector<sptr<ScreenInfo>>& screenInfos);
|
||||
bool UpdateScreenInfoLocked(sptr<ScreenInfo>);
|
||||
|
||||
class ScreenManagerListener;
|
||||
sptr<ScreenManagerListener> screenManagerListener_;
|
||||
std::map<ScreenId, sptr<Screen>> screenMap_;
|
||||
std::map<ScreenId, sptr<ScreenGroup>> screenGroupMap_;
|
||||
std::recursive_mutex mutex_;
|
||||
std::vector<sptr<IScreenListener>> screenListeners_;
|
||||
std::vector<sptr<IScreenGroupListener>> screenGroupListeners_;
|
||||
};
|
||||
|
||||
class ScreenManager::ScreenManagerListener : public DisplayManagerAgentDefault {
|
||||
class ScreenManager::Impl::ScreenManagerListener : public DisplayManagerAgentDefault {
|
||||
public:
|
||||
ScreenManagerListener(sptr<Impl> impl) : pImpl_(impl)
|
||||
{
|
||||
@@ -43,7 +62,7 @@ public:
|
||||
|
||||
void OnScreenConnect(sptr<ScreenInfo> screenInfo)
|
||||
{
|
||||
if (screenInfo == nullptr || screenInfo->id_ == SCREEN_ID_INVALID) {
|
||||
if (screenInfo == nullptr || screenInfo->GetScreenId() == SCREEN_ID_INVALID) {
|
||||
WLOGFE("OnScreenConnect, screenInfo is invalid.");
|
||||
return;
|
||||
}
|
||||
@@ -51,8 +70,9 @@ public:
|
||||
WLOGFE("OnScreenConnect, impl is nullptr.");
|
||||
return;
|
||||
}
|
||||
pImpl_->NotifyScreenConnect(screenInfo);
|
||||
for (auto listener : pImpl_->screenListeners_) {
|
||||
listener->OnConnect(screenInfo->id_);
|
||||
listener->OnConnect(screenInfo->GetScreenId());
|
||||
}
|
||||
};
|
||||
|
||||
@@ -66,15 +86,16 @@ public:
|
||||
WLOGFE("OnScreenDisconnect, impl is nullptr.");
|
||||
return;
|
||||
}
|
||||
pImpl_->NotifyScreenDisconnect(screenId);
|
||||
for (auto listener : pImpl_->screenListeners_) {
|
||||
listener->OnDisconnect(screenId);
|
||||
}
|
||||
};
|
||||
|
||||
void OnScreenChange(const std::vector<const sptr<ScreenInfo>>& screenInfos, ScreenChangeEvent event)
|
||||
void OnScreenChange(const sptr<ScreenInfo>& screenInfo, ScreenChangeEvent event)
|
||||
{
|
||||
if (screenInfos.empty()) {
|
||||
WLOGFE("OnScreenChange, screenInfos is empty.");
|
||||
if (screenInfo == nullptr) {
|
||||
WLOGFE("OnScreenChange, screenInfo is null.");
|
||||
return;
|
||||
}
|
||||
if (pImpl_ == nullptr) {
|
||||
@@ -82,14 +103,32 @@ public:
|
||||
return;
|
||||
}
|
||||
WLOGFD("OnScreenChange. event %{public}u", event);
|
||||
pImpl_->NotifyScreenChange(screenInfo);
|
||||
for (auto listener: pImpl_->screenListeners_) {
|
||||
listener->OnChange(screenInfo->GetScreenId());
|
||||
}
|
||||
};
|
||||
|
||||
void OnScreenGroupChange(const std::vector<sptr<ScreenInfo>>& screenInfos, ScreenGroupChangeEvent groupEvent)
|
||||
{
|
||||
if (screenInfos.empty()) {
|
||||
WLOGFE("OnScreenGroupChange, screenInfos is empty.");
|
||||
return;
|
||||
}
|
||||
if (pImpl_ == nullptr) {
|
||||
WLOGFE("OnScreenGroupChange, impl is nullptr.");
|
||||
return;
|
||||
}
|
||||
WLOGFD("OnScreenGroupChange. event %{public}u", groupEvent);
|
||||
pImpl_->NotifyScreenChange(screenInfos);
|
||||
std::vector<ScreenId> screenIds;
|
||||
for (auto screenInfo : screenInfos) {
|
||||
if (screenInfo->id_ != SCREEN_ID_INVALID) {
|
||||
screenIds.push_back(screenInfo->id_);
|
||||
if (screenInfo->GetScreenId() != SCREEN_ID_INVALID) {
|
||||
screenIds.push_back(screenInfo->GetScreenId());
|
||||
}
|
||||
}
|
||||
for (auto listener: pImpl_->screenListeners_) {
|
||||
listener->OnChange(screenIds, event);
|
||||
for (auto listener: pImpl_->screenGroupListeners_) {
|
||||
listener->OnChange(screenIds, groupEvent);
|
||||
}
|
||||
};
|
||||
private:
|
||||
@@ -106,19 +145,80 @@ ScreenManager::~ScreenManager()
|
||||
{
|
||||
}
|
||||
|
||||
sptr<Screen> ScreenManager::GetScreenById(ScreenId screenId)
|
||||
sptr<Screen> ScreenManager::Impl::GetScreen(ScreenId screenId)
|
||||
{
|
||||
return SingletonContainer::Get<DisplayManagerAdapter>().GetScreenById(screenId);
|
||||
auto screenInfo = SingletonContainer::Get<ScreenManagerAdapter>().GetScreenInfo(screenId);
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
if (!UpdateScreenInfoLocked(screenInfo)) {
|
||||
screenMap_.erase(screenId);
|
||||
return nullptr;
|
||||
}
|
||||
return screenMap_[screenId];
|
||||
}
|
||||
|
||||
sptr<ScreenGroup> ScreenManager::GetScreenGroupById(ScreenId screenId)
|
||||
sptr<Screen> ScreenManager::GetScreenById(ScreenId screenId)
|
||||
{
|
||||
return SingletonContainer::Get<DisplayManagerAdapter>().GetScreenGroupById(screenId);
|
||||
return pImpl_->GetScreen(screenId);
|
||||
}
|
||||
|
||||
sptr<ScreenGroup> ScreenManager::Impl::GetScreenGroup(ScreenId screenId)
|
||||
{
|
||||
auto screenGroupInfo = SingletonContainer::Get<ScreenManagerAdapter>().GetScreenGroupInfoById(screenId);
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
if (screenGroupInfo == nullptr) {
|
||||
WLOGFE("screenGroupInfo is null");
|
||||
screenGroupMap_.erase(screenId);
|
||||
return nullptr;
|
||||
}
|
||||
auto iter = screenGroupMap_.find(screenId);
|
||||
if (iter != screenGroupMap_.end() && iter->second != nullptr) {
|
||||
WLOGFI("get screenGroup in screenGroup map");
|
||||
iter->second->UpdateScreenGroupInfo(screenGroupInfo);
|
||||
return iter->second;
|
||||
}
|
||||
sptr<ScreenGroup> screenGroup = new ScreenGroup(screenGroupInfo);
|
||||
screenGroupMap_[screenId] = screenGroup;
|
||||
return screenGroup;
|
||||
}
|
||||
|
||||
sptr<ScreenGroup> ScreenManager::GetScreenGroup(ScreenId screenId)
|
||||
{
|
||||
return pImpl_->GetScreenGroup(screenId);
|
||||
}
|
||||
|
||||
std::vector<sptr<Screen>> ScreenManager::Impl::GetAllScreens()
|
||||
{
|
||||
auto screenInfos = SingletonContainer::Get<ScreenManagerAdapter>().GetAllScreenInfos();
|
||||
std::vector<sptr<Screen>> screens;
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
for (auto info: screenInfos) {
|
||||
if (UpdateScreenInfoLocked(info)) {
|
||||
screens.emplace_back(screenMap_[info->GetScreenId()]);
|
||||
}
|
||||
}
|
||||
screenMap_.clear();
|
||||
for (auto screen: screens) {
|
||||
screenMap_.insert(std::make_pair(screen->GetId(), screen));
|
||||
}
|
||||
return screens;
|
||||
}
|
||||
|
||||
std::vector<sptr<Screen>> ScreenManager::GetAllScreens()
|
||||
{
|
||||
return SingletonContainer::Get<DisplayManagerAdapter>().GetAllScreens();
|
||||
return pImpl_->GetAllScreens();
|
||||
}
|
||||
|
||||
bool ScreenManager::Impl::RegisterScreenListener(sptr<IScreenListener> listener)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
screenListeners_.push_back(listener);
|
||||
if (screenManagerListener_ == nullptr) {
|
||||
screenManagerListener_ = new ScreenManagerListener(this);
|
||||
SingletonContainer::Get<ScreenManagerAdapter>().RegisterDisplayManagerAgent(
|
||||
screenManagerListener_,
|
||||
DisplayManagerAgentType::SCREEN_EVENT_LISTENER);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ScreenManager::RegisterScreenListener(sptr<IScreenListener> listener)
|
||||
@@ -127,13 +227,23 @@ bool ScreenManager::RegisterScreenListener(sptr<IScreenListener> listener)
|
||||
WLOGFE("RegisterScreenListener listener is nullptr.");
|
||||
return false;
|
||||
}
|
||||
std::lock_guard<std::recursive_mutex> lock(pImpl_->mutex_);
|
||||
pImpl_->screenListeners_.push_back(listener);
|
||||
if (screenManagerListener_ == nullptr) {
|
||||
screenManagerListener_ = new ScreenManagerListener(pImpl_);
|
||||
SingletonContainer::Get<DisplayManagerAdapter>().RegisterDisplayManagerAgent(
|
||||
return pImpl_->RegisterScreenListener(listener);
|
||||
}
|
||||
|
||||
bool ScreenManager::Impl::UnregisterScreenListener(sptr<IScreenListener> listener)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
auto iter = std::find(screenListeners_.begin(), screenListeners_.end(), listener);
|
||||
if (iter == screenListeners_.end()) {
|
||||
WLOGFE("could not find this listener");
|
||||
return false;
|
||||
}
|
||||
screenListeners_.erase(iter);
|
||||
if (screenListeners_.empty() && screenManagerListener_ != nullptr) {
|
||||
SingletonContainer::Get<ScreenManagerAdapter>().UnregisterDisplayManagerAgent(
|
||||
screenManagerListener_,
|
||||
DisplayManagerAgentType::SCREEN_EVENT_LISTENER);
|
||||
screenManagerListener_ = nullptr;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -144,15 +254,42 @@ bool ScreenManager::UnregisterScreenListener(sptr<IScreenListener> listener)
|
||||
WLOGFE("UnregisterScreenListener listener is nullptr.");
|
||||
return false;
|
||||
}
|
||||
std::lock_guard<std::recursive_mutex> lock(pImpl_->mutex_);
|
||||
auto iter = std::find(pImpl_->screenListeners_.begin(), pImpl_->screenListeners_.end(), listener);
|
||||
if (iter == pImpl_->screenListeners_.end()) {
|
||||
return pImpl_->UnregisterScreenListener(listener);
|
||||
}
|
||||
|
||||
bool ScreenManager::Impl::RegisterScreenGroupListener(sptr<IScreenGroupListener> listener)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
screenGroupListeners_.push_back(listener);
|
||||
if (screenManagerListener_ == nullptr) {
|
||||
screenManagerListener_ = new ScreenManagerListener(this);
|
||||
SingletonContainer::Get<ScreenManagerAdapter>().RegisterDisplayManagerAgent(
|
||||
screenManagerListener_,
|
||||
DisplayManagerAgentType::SCREEN_EVENT_LISTENER);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ScreenManager::RegisterScreenGroupListener(sptr<IScreenGroupListener> listener)
|
||||
{
|
||||
if (listener == nullptr) {
|
||||
WLOGFE("RegisterScreenGroupListener listener is nullptr.");
|
||||
return false;
|
||||
}
|
||||
return pImpl_->RegisterScreenGroupListener(listener);
|
||||
}
|
||||
|
||||
bool ScreenManager::Impl::UnregisterScreenGroupListener(sptr<IScreenGroupListener> listener)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
auto iter = std::find(screenGroupListeners_.begin(), screenGroupListeners_.end(), listener);
|
||||
if (iter == screenGroupListeners_.end()) {
|
||||
WLOGFE("could not find this listener");
|
||||
return false;
|
||||
}
|
||||
pImpl_->screenListeners_.erase(iter);
|
||||
if (pImpl_->screenListeners_.empty() && screenManagerListener_ != nullptr) {
|
||||
SingletonContainer::Get<DisplayManagerAdapter>().UnregisterDisplayManagerAgent(
|
||||
screenGroupListeners_.erase(iter);
|
||||
if (screenGroupListeners_.empty() && screenManagerListener_ != nullptr) {
|
||||
SingletonContainer::Get<ScreenManagerAdapter>().UnregisterDisplayManagerAgent(
|
||||
screenManagerListener_,
|
||||
DisplayManagerAgentType::SCREEN_EVENT_LISTENER);
|
||||
screenManagerListener_ = nullptr;
|
||||
@@ -160,6 +297,15 @@ bool ScreenManager::UnregisterScreenListener(sptr<IScreenListener> listener)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ScreenManager::UnregisterScreenGroupListener(sptr<IScreenGroupListener> listener)
|
||||
{
|
||||
if (listener == nullptr) {
|
||||
WLOGFE("UnregisterScreenGroupListener listener is nullptr.");
|
||||
return false;
|
||||
}
|
||||
return pImpl_->UnregisterScreenGroupListener(listener);
|
||||
}
|
||||
|
||||
ScreenId ScreenManager::MakeExpand(const std::vector<ExpandOption>& options)
|
||||
{
|
||||
WLOGFI("make expand");
|
||||
@@ -172,37 +318,96 @@ ScreenId ScreenManager::MakeExpand(const std::vector<ExpandOption>& options)
|
||||
screenIds.emplace_back(option.screenId_);
|
||||
startPoints.emplace_back(Point(option.startX_, option.startY_));
|
||||
}
|
||||
DMError result = SingletonContainer::Get<DisplayManagerAdapter>().MakeExpand(screenIds, startPoints);
|
||||
if (result != DMError::DM_OK) {
|
||||
return SCREEN_ID_INVALID;
|
||||
ScreenId group = SingletonContainer::Get<ScreenManagerAdapter>().MakeExpand(screenIds, startPoints);
|
||||
if (group == SCREEN_ID_INVALID) {
|
||||
WLOGFI("make expand failed");
|
||||
}
|
||||
WLOGFI("make expand success");
|
||||
return screenIds.front(); // default main screenId is the first element of screenIds
|
||||
return group;
|
||||
}
|
||||
|
||||
ScreenId ScreenManager::MakeMirror(ScreenId mainScreenId, std::vector<ScreenId> mirrorScreenId)
|
||||
{
|
||||
WLOGFI("create mirror for screen: %{public}" PRIu64"", mainScreenId);
|
||||
// TODO: "record screen" should use another function, "MakeMirror" should return group id.
|
||||
DMError result = SingletonContainer::Get<DisplayManagerAdapter>().MakeMirror(mainScreenId, mirrorScreenId);
|
||||
if (result == DMError::DM_OK) {
|
||||
WLOGFI("create mirror success");
|
||||
ScreenId group = SingletonContainer::Get<ScreenManagerAdapter>().MakeMirror(mainScreenId, mirrorScreenId);
|
||||
if (group == SCREEN_ID_INVALID) {
|
||||
WLOGFI("create mirror failed");
|
||||
}
|
||||
return SCREEN_ID_INVALID;
|
||||
return group;
|
||||
}
|
||||
|
||||
void ScreenManager::RemoveVirtualScreenFromGroup(std::vector<ScreenId> screens)
|
||||
{
|
||||
SingletonContainer::Get<ScreenManagerAdapter>().RemoveVirtualScreenFromGroup(screens);
|
||||
}
|
||||
|
||||
void ScreenManager::CancelMakeMirrorOrExpand(std::vector<ScreenId> screens)
|
||||
{
|
||||
RemoveVirtualScreenFromGroup(screens);
|
||||
}
|
||||
|
||||
ScreenId ScreenManager::CreateVirtualScreen(VirtualScreenOption option)
|
||||
{
|
||||
return SingletonContainer::Get<DisplayManagerAdapter>().CreateVirtualScreen(option);
|
||||
return SingletonContainer::Get<ScreenManagerAdapter>().CreateVirtualScreen(option);
|
||||
}
|
||||
|
||||
DMError ScreenManager::DestroyVirtualScreen(ScreenId screenId)
|
||||
{
|
||||
return SingletonContainer::Get<DisplayManagerAdapter>().DestroyVirtualScreen(screenId);
|
||||
return SingletonContainer::Get<ScreenManagerAdapter>().DestroyVirtualScreen(screenId);
|
||||
}
|
||||
|
||||
DMError ScreenManager::SetVirtualScreenSurface(ScreenId screenId, sptr<Surface> surface)
|
||||
{
|
||||
return SingletonContainer::Get<DisplayManagerAdapter>().SetVirtualScreenSurface(screenId, surface);
|
||||
return SingletonContainer::Get<ScreenManagerAdapter>().SetVirtualScreenSurface(screenId, surface);
|
||||
}
|
||||
|
||||
void ScreenManager::Impl::NotifyScreenConnect(sptr<ScreenInfo> info)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
UpdateScreenInfoLocked(info);
|
||||
}
|
||||
|
||||
void ScreenManager::Impl::NotifyScreenDisconnect(ScreenId screenId)
|
||||
{
|
||||
WLOGFI("screenId:%{public}" PRIu64".", screenId);
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
screenMap_.erase(screenId);
|
||||
}
|
||||
|
||||
void ScreenManager::Impl::NotifyScreenChange(const sptr<ScreenInfo>& screenInfo)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
UpdateScreenInfoLocked(screenInfo);
|
||||
}
|
||||
|
||||
void ScreenManager::Impl::NotifyScreenChange(const std::vector<sptr<ScreenInfo>>& screenInfos)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
for (auto screenInfo : screenInfos) {
|
||||
UpdateScreenInfoLocked(screenInfo);
|
||||
}
|
||||
}
|
||||
|
||||
bool ScreenManager::Impl::UpdateScreenInfoLocked(sptr<ScreenInfo> screenInfo)
|
||||
{
|
||||
if (screenInfo == nullptr) {
|
||||
WLOGFE("displayInfo is null");
|
||||
return false;
|
||||
}
|
||||
ScreenId screenId = screenInfo->GetScreenId();
|
||||
WLOGFI("screenId:%{public}" PRIu64".", screenId);
|
||||
if (screenId == SCREEN_ID_INVALID) {
|
||||
WLOGFE("displayId is invalid.");
|
||||
return false;
|
||||
}
|
||||
auto iter = screenMap_.find(screenId);
|
||||
if (iter != screenMap_.end() && iter->second != nullptr) {
|
||||
WLOGFI("get screen in screen map");
|
||||
iter->second->UpdateScreenInfo(screenInfo);
|
||||
return true;
|
||||
}
|
||||
sptr<Screen> screen = new Screen(screenInfo);
|
||||
screenMap_[screenId] = screen;
|
||||
return true;
|
||||
}
|
||||
} // namespace OHOS::Rosen
|
||||
@@ -113,8 +113,33 @@ void DisplayManagerAgentProxy::OnScreenDisconnect(ScreenId screenId)
|
||||
}
|
||||
}
|
||||
|
||||
void DisplayManagerAgentProxy::OnScreenChange(
|
||||
const std::vector<const sptr<ScreenInfo>>& screenInfos, ScreenChangeEvent event)
|
||||
void DisplayManagerAgentProxy::OnScreenChange(const sptr<ScreenInfo>& screenInfo, ScreenChangeEvent event)
|
||||
{
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option(MessageOption::TF_ASYNC);
|
||||
if (!data.WriteInterfaceToken(GetDescriptor())) {
|
||||
WLOGFE("WriteInterfaceToken failed");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!data.WriteParcelable(screenInfo.GetRefPtr())) {
|
||||
WLOGFE("Write screenInfo failed");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!data.WriteUint32(static_cast<uint32_t>(event))) {
|
||||
WLOGFE("Write ScreenChangeEvent failed");
|
||||
return;
|
||||
}
|
||||
|
||||
if (Remote()->SendRequest(TRANS_ID_ON_SCREEN_CHANGED, data, reply, option) != ERR_NONE) {
|
||||
WLOGFE("SendRequest failed");
|
||||
}
|
||||
}
|
||||
|
||||
void DisplayManagerAgentProxy::OnScreenGroupChange(
|
||||
const std::vector<sptr<ScreenInfo>>& screenInfos, ScreenGroupChangeEvent event)
|
||||
{
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
@@ -130,19 +155,19 @@ void DisplayManagerAgentProxy::OnScreenChange(
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < size; i++) {
|
||||
for (size_t i = 0; i < size; i++) {
|
||||
if (!data.WriteParcelable(screenInfos[i].GetRefPtr())) {
|
||||
WLOGFE("Write screenInfos[%{public}d] size failed", i);
|
||||
WLOGFE("Write screenInfos[%{public}zu] size failed", i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!data.WriteUint32(static_cast<uint32_t>(event))) {
|
||||
WLOGFE("Write ScreenChangeEvent failed");
|
||||
WLOGFE("Write ScreenGroupChangeEvent failed");
|
||||
return;
|
||||
}
|
||||
|
||||
if (Remote()->SendRequest(TRANS_ID_ON_SCREEN_CHANGED, data, reply, option) != ERR_NONE) {
|
||||
if (Remote()->SendRequest(TRANS_ID_ON_SCREENGROUP_CHANGED, data, reply, option) != ERR_NONE) {
|
||||
WLOGFE("SendRequest failed");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,7 +59,17 @@ int32_t DisplayManagerAgentStub::OnRemoteRequest(uint32_t code, MessageParcel& d
|
||||
break;
|
||||
}
|
||||
case TRANS_ID_ON_SCREEN_CHANGED: {
|
||||
std::vector<const sptr<ScreenInfo>> screenInfos;
|
||||
sptr<ScreenInfo> screenInfo = data.ReadParcelable<ScreenInfo>();
|
||||
uint32_t event;
|
||||
if (!data.ReadUint32(event)) {
|
||||
WLOGFE("Read ScreenChangeEvent failed");
|
||||
return -1;
|
||||
}
|
||||
OnScreenChange(screenInfo, static_cast<ScreenChangeEvent>(event));
|
||||
break;
|
||||
}
|
||||
case TRANS_ID_ON_SCREENGROUP_CHANGED: {
|
||||
std::vector<sptr<ScreenInfo>> screenInfos;
|
||||
uint32_t size;
|
||||
if (!data.ReadUint32(size)) {
|
||||
WLOGFE("Read ScreenChangeEvent failed");
|
||||
@@ -75,7 +85,7 @@ int32_t DisplayManagerAgentStub::OnRemoteRequest(uint32_t code, MessageParcel& d
|
||||
WLOGFE("Read ScreenChangeEvent failed");
|
||||
return -1;
|
||||
}
|
||||
OnScreenChange(screenInfos, static_cast<ScreenChangeEvent>(event));
|
||||
OnScreenGroupChange(screenInfos, static_cast<ScreenGroupChangeEvent>(event));
|
||||
break;
|
||||
}
|
||||
case TRANS_ID_ON_DISPLAY_CONNECT: {
|
||||
|
||||
@@ -75,7 +75,12 @@ ohos_systemtest("dm_screenshot_test") {
|
||||
ohos_systemtest("dm_screenshot_cmd_test") {
|
||||
module_out_path = module_out_path
|
||||
|
||||
sources = [ "screenshot_cmd_test.cpp" ]
|
||||
include_dirs = [ "//foundation/windowmanager/snapshot" ]
|
||||
|
||||
sources = [
|
||||
"//foundation/windowmanager/snapshot/snapshot_utils.cpp",
|
||||
"screenshot_cmd_test.cpp",
|
||||
]
|
||||
|
||||
deps = [ ":dm_systemtest_common" ]
|
||||
}
|
||||
|
||||
@@ -44,15 +44,13 @@ public:
|
||||
WLOGI("DisplayChangeEventListener::OnDestroy displayId=%{public}" PRIu64"", displayId);
|
||||
}
|
||||
|
||||
virtual void OnChange(DisplayId displayId, DisplayChangeEvent event)
|
||||
virtual void OnChange(DisplayId displayId)
|
||||
{
|
||||
WLOGI("DisplayChangeEventListener::OnChange displayId=%{public}" PRIu64"", displayId);
|
||||
isCallbackCalled_ = true;
|
||||
event_ = event;
|
||||
displayId_ = displayId;
|
||||
}
|
||||
bool isCallbackCalled_ { false };
|
||||
DisplayChangeEvent event_ { DisplayChangeEvent::UNKNOWN };
|
||||
DisplayId displayId_ { DISPLAY_ID_INVALD };
|
||||
};
|
||||
|
||||
@@ -105,7 +103,6 @@ void DisplayChangeTest::TearDown()
|
||||
void DisplayChangeTest::ResetDisplayChangeListener()
|
||||
{
|
||||
listener_->isCallbackCalled_ = false;
|
||||
listener_->event_ = DisplayChangeEvent::UNKNOWN;
|
||||
listener_->displayId_ = DISPLAY_ID_INVALD;
|
||||
}
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include "display_manager.h"
|
||||
#include "window.h"
|
||||
#include "window_manager_hilog.h"
|
||||
|
||||
using namespace testing;
|
||||
@@ -53,7 +54,7 @@ public:
|
||||
|
||||
static inline DisplayId defaultId_;
|
||||
static inline uint32_t brightnessLevel_ = 80;
|
||||
static inline uint32_t invalidBrightnessLevel_ = 10000000;
|
||||
static inline uint32_t invalidBrightnessLevel_ = 1000000000;
|
||||
static inline uint32_t times_ = 0;
|
||||
static inline bool isDisplayStateCallbackCalled_ = false;
|
||||
static sptr<DisplayPowerEventListener> listener_;
|
||||
@@ -433,6 +434,28 @@ HWTEST_F(DisplayPowerTest, set_screen_brightness_002, Function | MediumTest | Le
|
||||
uint32_t level = DisplayManager::GetInstance().GetScreenBrightness(defaultId_);
|
||||
ASSERT_NE(level, invalidBrightnessLevel_);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: window_life_cycle_001
|
||||
* @tc.desc: Add a window and then call SuspendEnd and check window state; Notify unlock and check window state
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(DisplayPowerTest, window_life_cycle_001, Function | MediumTest | Level2)
|
||||
{
|
||||
sptr<WindowOption> option = new WindowOption();
|
||||
sptr<Window> window = Window::Create("window1", option, nullptr);
|
||||
EXPECT_EQ(WMError::WM_OK, window->Show());
|
||||
|
||||
DisplayManager::GetInstance().SuspendBegin(PowerStateChangeReason::POWER_BUTTON);
|
||||
usleep(SLEEP_TIME_IN_US);
|
||||
ASSERT_EQ(false, window->GetShowState());
|
||||
|
||||
DisplayManager::GetInstance().NotifyDisplayEvent(DisplayEvent::UNLOCK);
|
||||
usleep(SLEEP_TIME_IN_US);
|
||||
ASSERT_EQ(true, window->GetShowState());
|
||||
|
||||
window->Destroy();
|
||||
}
|
||||
} // namespace
|
||||
} // namespace Rosen
|
||||
} // namespace OHOS
|
||||
@@ -31,6 +31,9 @@ DisplayTestUtils::~DisplayTestUtils()
|
||||
}
|
||||
WLOGFI("prevBuffer_ release success");
|
||||
}
|
||||
if (csurface_ != nullptr) {
|
||||
csurface_->UnregisterConsumerListener();
|
||||
}
|
||||
csurface_ = nullptr;
|
||||
psurface_ = nullptr;
|
||||
listener_ = nullptr;
|
||||
@@ -86,7 +89,7 @@ bool DisplayTestUtils::CreateSurface()
|
||||
void DisplayTestUtils::OnVsync()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
WLOGFI("DisplayTestUtils::OnVsyn");
|
||||
WLOGFI("DisplayTestUtils::OnVsync");
|
||||
sptr<SurfaceBuffer> cbuffer = nullptr;
|
||||
int32_t fence = -1;
|
||||
int64_t timestamp = 0;
|
||||
|
||||
@@ -56,36 +56,135 @@ void ScreenGamutTest::TearDown()
|
||||
|
||||
namespace {
|
||||
/**
|
||||
* @tc.name: ScreenGamut01
|
||||
* @tc.desc: gamut
|
||||
* @tc.name: GetScreenSupportedColorGamuts01
|
||||
* @tc.desc: gamut GetScreenSupportedColorGamuts
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(ScreenGamutTest, ScreenGamut01, Function | MediumTest | Level1)
|
||||
HWTEST_F(ScreenGamutTest, GetScreenSupportedColorGamuts01, Function | MediumTest | Level3)
|
||||
{
|
||||
ASSERT_NE(defaultScreen_, nullptr);
|
||||
DMError ret;
|
||||
std::vector<ScreenColorGamut> colorGamuts;
|
||||
ret = defaultScreen_->GetScreenSupportedColorGamuts(colorGamuts);
|
||||
ASSERT_EQ(ret, DMError::DM_OK);
|
||||
|
||||
ScreenColorGamut colorGamut;
|
||||
ret = defaultScreen_->GetScreenColorGamut(colorGamut);
|
||||
ASSERT_EQ(ret, DMError::DM_OK);
|
||||
|
||||
ret = defaultScreen_->SetScreenColorGamut(0);
|
||||
ASSERT_EQ(ret, DMError::DM_OK);
|
||||
|
||||
const int32_t invalidColorGamutIndex = -1;
|
||||
ret = defaultScreen_->SetScreenColorGamut(invalidColorGamutIndex);
|
||||
ASSERT_NE(ret, DMError::DM_OK);
|
||||
ASSERT_GT(colorGamuts.size(), 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ScreenGamut02
|
||||
* @tc.desc: gamut
|
||||
* @tc.name: GetScreenColorGamut01
|
||||
* @tc.desc: gamut GetScreenColorGamut
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(ScreenGamutTest, ScreenGamut02, Function | MediumTest | Level1)
|
||||
HWTEST_F(ScreenGamutTest, GetScreenColorGamut01, Function | MediumTest | Level3)
|
||||
{
|
||||
ASSERT_NE(defaultScreen_, nullptr);
|
||||
DMError ret;
|
||||
ScreenColorGamut colorGamut;
|
||||
ret = defaultScreen_->GetScreenColorGamut(colorGamut);
|
||||
ASSERT_EQ(ret, DMError::DM_OK);
|
||||
ASSERT_NE(COLOR_GAMUT_INVALID, colorGamut);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: SetScreenColorGamut01
|
||||
* @tc.desc: gamut SetScreenColorGamut, valid index
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(ScreenGamutTest, SetScreenColorGamut01, Function | MediumTest | Level3)
|
||||
{
|
||||
ASSERT_NE(defaultScreen_, nullptr);
|
||||
DMError ret;
|
||||
ScreenColorGamut colorGamutBackup;
|
||||
int32_t colorGamutBackupIdx = -1;
|
||||
ScreenColorGamut colorGamut;
|
||||
std::vector<ScreenColorGamut> colorGamuts;
|
||||
|
||||
ret = defaultScreen_->GetScreenColorGamut(colorGamutBackup); // backup origin
|
||||
ASSERT_EQ(ret, DMError::DM_OK);
|
||||
|
||||
ret = defaultScreen_->GetScreenSupportedColorGamuts(colorGamuts);
|
||||
ASSERT_EQ(ret, DMError::DM_OK);
|
||||
|
||||
for (int32_t i = 0; i < static_cast<int32_t>(colorGamuts.size()); i++) {
|
||||
ret = defaultScreen_->SetScreenColorGamut(i);
|
||||
ASSERT_EQ(ret, DMError::DM_OK);
|
||||
|
||||
ret = defaultScreen_->GetScreenColorGamut(colorGamut);
|
||||
ASSERT_EQ(ret, DMError::DM_OK);
|
||||
|
||||
#ifdef SCREEN_GAMUT_SET_GET_OK
|
||||
ASSERT_EQ(colorGamut, colorGamuts[i]);
|
||||
#endif
|
||||
if (colorGamutBackup == colorGamuts[i]) {
|
||||
colorGamutBackupIdx = i;
|
||||
}
|
||||
}
|
||||
|
||||
ASSERT_GE(colorGamutBackupIdx, 0);
|
||||
ret = defaultScreen_->SetScreenColorGamut(colorGamutBackupIdx); // restore
|
||||
ASSERT_EQ(ret, DMError::DM_OK);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: SetScreenColorGamut02
|
||||
* @tc.desc: gamut SetScreenColorGamut, invalid index < 0
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(ScreenGamutTest, SetScreenColorGamut02, Function | MediumTest | Level3)
|
||||
{
|
||||
ASSERT_NE(defaultScreen_, nullptr);
|
||||
DMError ret;
|
||||
ScreenColorGamut colorGamutBefore;
|
||||
ScreenColorGamut colorGamutAfter;
|
||||
|
||||
ret = defaultScreen_->GetScreenColorGamut(colorGamutBefore);
|
||||
ASSERT_EQ(ret, DMError::DM_OK);
|
||||
|
||||
constexpr int32_t invalidColorGamutIndex = -1; // index < 0
|
||||
ret = defaultScreen_->SetScreenColorGamut(invalidColorGamutIndex);
|
||||
ASSERT_NE(ret, DMError::DM_OK);
|
||||
|
||||
ret = defaultScreen_->GetScreenColorGamut(colorGamutAfter);
|
||||
ASSERT_EQ(ret, DMError::DM_OK);
|
||||
|
||||
ASSERT_EQ(colorGamutBefore, colorGamutAfter); // don't change colorgamut after invalid set
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: SetScreenColorGamut03
|
||||
* @tc.desc: gamut SetScreenColorGamut, invalid index >= size
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(ScreenGamutTest, SetScreenColorGamut03, Function | MediumTest | Level3)
|
||||
{
|
||||
ASSERT_NE(defaultScreen_, nullptr);
|
||||
DMError ret;
|
||||
ScreenColorGamut colorGamutBefore;
|
||||
ScreenColorGamut colorGamutAfter;
|
||||
|
||||
ret = defaultScreen_->GetScreenColorGamut(colorGamutBefore);
|
||||
ASSERT_EQ(ret, DMError::DM_OK);
|
||||
|
||||
std::vector<ScreenColorGamut> colorGamuts;
|
||||
ret = defaultScreen_->GetScreenSupportedColorGamuts(colorGamuts);
|
||||
ASSERT_EQ(ret, DMError::DM_OK);
|
||||
|
||||
const int32_t invalidColorGamutIndex = static_cast<int32_t>(colorGamuts.size()); // index >= size
|
||||
ret = defaultScreen_->SetScreenColorGamut(invalidColorGamutIndex);
|
||||
ASSERT_NE(ret, DMError::DM_OK);
|
||||
|
||||
ret = defaultScreen_->GetScreenColorGamut(colorGamutAfter);
|
||||
ASSERT_EQ(ret, DMError::DM_OK);
|
||||
|
||||
ASSERT_EQ(colorGamutBefore, colorGamutAfter); // don't change colorgamut after invalid set
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetScreenGamutMap01
|
||||
* @tc.desc: gamut GetScreenGamutMap
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(ScreenGamutTest, GetScreenGamutMap01, Function | MediumTest | Level3)
|
||||
{
|
||||
ASSERT_NE(defaultScreen_, nullptr);
|
||||
DMError ret;
|
||||
@@ -93,21 +192,76 @@ HWTEST_F(ScreenGamutTest, ScreenGamut02, Function | MediumTest | Level1)
|
||||
|
||||
ret = defaultScreen_->GetScreenGamutMap(gamutMap);
|
||||
ASSERT_EQ(ret, DMError::DM_OK);
|
||||
}
|
||||
|
||||
ret = defaultScreen_->SetScreenGamutMap(gamutMap);
|
||||
/**
|
||||
* @tc.name: SetScreenGamutMap01
|
||||
* @tc.desc: gamut SetScreenGamutMap, valid param
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(ScreenGamutTest, SetScreenGamutMap01, Function | MediumTest | Level3)
|
||||
{
|
||||
ASSERT_NE(defaultScreen_, nullptr);
|
||||
DMError ret;
|
||||
const ScreenGamutMap gamutMaps[] = {
|
||||
GAMUT_MAP_CONSTANT,
|
||||
GAMUT_MAP_EXTENSION,
|
||||
GAMUT_MAP_HDR_CONSTANT,
|
||||
GAMUT_MAP_HDR_EXTENSION,
|
||||
};
|
||||
ScreenGamutMap gamutMap;
|
||||
ScreenGamutMap gamutMapBackup;
|
||||
|
||||
ret = defaultScreen_->GetScreenGamutMap(gamutMapBackup); // backup origin
|
||||
ASSERT_EQ(ret, DMError::DM_OK);
|
||||
|
||||
for (uint32_t i = 0; i < sizeof(gamutMaps) / sizeof(ScreenGamutMap); i++) {
|
||||
ret = defaultScreen_->SetScreenGamutMap(gamutMaps[i]);
|
||||
ASSERT_EQ(ret, DMError::DM_OK);
|
||||
|
||||
ret = defaultScreen_->GetScreenGamutMap(gamutMap);
|
||||
ASSERT_EQ(ret, DMError::DM_OK);
|
||||
#ifdef SCREEN_GAMUT_SET_GET_OK
|
||||
ASSERT_EQ(gamutMaps[i], gamutMap);
|
||||
#endif
|
||||
}
|
||||
|
||||
ret = defaultScreen_->SetScreenGamutMap(gamutMapBackup); // restore
|
||||
ASSERT_EQ(ret, DMError::DM_OK);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: SetScreenGamutMap02
|
||||
* @tc.desc: gamut SetScreenGamutMap, invalid param
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(ScreenGamutTest, SetScreenGamutMap02, Function | MediumTest | Level3)
|
||||
{
|
||||
ASSERT_NE(defaultScreen_, nullptr);
|
||||
DMError ret;
|
||||
ScreenGamutMap gamutMap;
|
||||
ScreenGamutMap gamutMapBefore;
|
||||
ScreenGamutMap gamutMapAfter;
|
||||
|
||||
ret = defaultScreen_->GetScreenGamutMap(gamutMapBefore);
|
||||
ASSERT_EQ(ret, DMError::DM_OK);
|
||||
|
||||
gamutMap = static_cast<ScreenGamutMap>(static_cast<uint32_t>(ScreenGamutMap::GAMUT_MAP_HDR_EXTENSION) + 1);
|
||||
ret = defaultScreen_->SetScreenGamutMap(gamutMap);
|
||||
ASSERT_NE(ret, DMError::DM_OK);
|
||||
|
||||
ret = defaultScreen_->GetScreenGamutMap(gamutMapAfter);
|
||||
ASSERT_EQ(ret, DMError::DM_OK);
|
||||
|
||||
ASSERT_EQ(gamutMapBefore, gamutMapAfter);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ScreenGamut03
|
||||
* @tc.desc: gamut
|
||||
* @tc.name: SetScreenColorTransform01
|
||||
* @tc.desc: gamut SetScreenColorTransform
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(ScreenGamutTest, ScreenGamut03, Function | MediumTest | Level1)
|
||||
HWTEST_F(ScreenGamutTest, SetScreenColorTransform01, Function | MediumTest | Level3)
|
||||
{
|
||||
ASSERT_NE(defaultScreen_, nullptr);
|
||||
DMError ret;
|
||||
|
||||
@@ -15,14 +15,21 @@
|
||||
|
||||
// gtest
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "display_test_utils.h"
|
||||
#include "future.h"
|
||||
#include "screen.h"
|
||||
#include "window.h"
|
||||
#include "window_option.h"
|
||||
#include "window_manager_hilog.h"
|
||||
using namespace testing;
|
||||
using namespace testing::ext;
|
||||
|
||||
namespace OHOS {
|
||||
namespace Rosen {
|
||||
namespace {
|
||||
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "ScreenManagerTest"};
|
||||
}
|
||||
class ScreenManagerTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase();
|
||||
@@ -38,13 +45,48 @@ public:
|
||||
static uint32_t defaultHeight_;
|
||||
static float defaultDensity_;
|
||||
static int32_t defaultFlags_;
|
||||
static VirtualScreenOption defaultoption_;
|
||||
static VirtualScreenOption defaultOption_;
|
||||
static uint32_t waitCount_;
|
||||
const uint32_t sleepUs_ = 10 * 1000;
|
||||
const uint32_t maxWaitCount_ = 2000;
|
||||
const uint32_t execTimes_ = 10;
|
||||
const uint32_t acquireFrames_ = 1;
|
||||
static constexpr uint32_t TEST_SPEEP_S = 1; // test spleep time
|
||||
static constexpr long TIME_OUT = 1000;
|
||||
};
|
||||
|
||||
class ScreenChangeListener : public ScreenManager::IScreenListener {
|
||||
public:
|
||||
virtual void OnConnect(ScreenId screenId) override
|
||||
{
|
||||
WLOGFI("OnConnect, screenId:%{public}" PRIu64"", screenId);
|
||||
connectFuture_.SetValue(screenId);
|
||||
}
|
||||
virtual void OnDisconnect(ScreenId screenId) override
|
||||
{
|
||||
WLOGFI("OnDisconnect, screenId:%{public}" PRIu64"", screenId);
|
||||
disconnectFuture_.SetValue(screenId);
|
||||
}
|
||||
virtual void OnChange(ScreenId screenId) override
|
||||
{
|
||||
WLOGFI("OnChange, screenId:%{public}" PRIu64"", screenId);
|
||||
changeFuture_.SetValue(screenId);
|
||||
}
|
||||
RunnableFuture<ScreenId> connectFuture_;
|
||||
RunnableFuture<ScreenId> disconnectFuture_;
|
||||
RunnableFuture<ScreenId> changeFuture_;
|
||||
};
|
||||
|
||||
class ScreenGroupChangeListener : public ScreenManager::IScreenGroupListener {
|
||||
public:
|
||||
virtual void OnChange(const std::vector<ScreenId>& screenIds, ScreenGroupChangeEvent event) override
|
||||
{
|
||||
for (auto screenId : screenIds) {
|
||||
changeFuture_.SetValue(std::make_pair(screenId, event));
|
||||
usleep(10 * 1000); // wait 10000 us
|
||||
}
|
||||
}
|
||||
RunnableFuture<std::pair<ScreenId, ScreenGroupChangeEvent>> changeFuture_;
|
||||
};
|
||||
|
||||
sptr<Display> ScreenManagerTest::defaultDisplay_ = nullptr;
|
||||
@@ -55,7 +97,7 @@ uint32_t ScreenManagerTest::defaultWidth_ = 480;
|
||||
uint32_t ScreenManagerTest::defaultHeight_ = 320;
|
||||
float ScreenManagerTest::defaultDensity_ = 2.0;
|
||||
int32_t ScreenManagerTest::defaultFlags_ = 0;
|
||||
VirtualScreenOption ScreenManagerTest::defaultoption_ = {
|
||||
VirtualScreenOption ScreenManagerTest::defaultOption_ = {
|
||||
defaultName_, defaultWidth_, defaultHeight_, defaultDensity_, nullptr, defaultFlags_
|
||||
};
|
||||
uint32_t ScreenManagerTest::waitCount_ = 0;
|
||||
@@ -67,8 +109,8 @@ void ScreenManagerTest::SetUpTestCase()
|
||||
defaultScreenId_ = defaultDisplay_->GetScreenId();
|
||||
defaultWidth_ = defaultDisplay_->GetWidth();
|
||||
defaultHeight_ = defaultDisplay_->GetHeight();
|
||||
defaultoption_.width_ = defaultWidth_;
|
||||
defaultoption_.height_ = defaultHeight_;
|
||||
defaultOption_.width_ = defaultWidth_;
|
||||
defaultOption_.height_ = defaultHeight_;
|
||||
}
|
||||
|
||||
void ScreenManagerTest::TearDownTestCase()
|
||||
@@ -112,8 +154,8 @@ HWTEST_F(ScreenManagerTest, ScreenManager01, Function | MediumTest | Level2)
|
||||
{
|
||||
DisplayTestUtils utils;
|
||||
ASSERT_TRUE(utils.CreateSurface());
|
||||
defaultoption_.surface_ = utils.psurface_;
|
||||
ScreenId virtualScreenId = ScreenManager::GetInstance().CreateVirtualScreen(defaultoption_);
|
||||
defaultOption_.surface_ = utils.psurface_;
|
||||
ScreenId virtualScreenId = ScreenManager::GetInstance().CreateVirtualScreen(defaultOption_);
|
||||
ASSERT_NE(SCREEN_ID_INVALID, virtualScreenId);
|
||||
ASSERT_EQ(DMError::DM_OK, ScreenManager::GetInstance().DestroyVirtualScreen(virtualScreenId));
|
||||
}
|
||||
@@ -127,8 +169,8 @@ HWTEST_F(ScreenManagerTest, ScreenManager02, Function | MediumTest | Level2)
|
||||
{
|
||||
DisplayTestUtils utils;
|
||||
ASSERT_TRUE(utils.CreateSurface());
|
||||
defaultoption_.surface_ = utils.psurface_;
|
||||
ScreenId virtualScreenId = ScreenManager::GetInstance().CreateVirtualScreen(defaultoption_);
|
||||
defaultOption_.surface_ = utils.psurface_;
|
||||
ScreenId virtualScreenId = ScreenManager::GetInstance().CreateVirtualScreen(defaultOption_);
|
||||
std::vector<ScreenId> mirrorIds;
|
||||
mirrorIds.push_back(virtualScreenId);
|
||||
ScreenManager::GetInstance().MakeMirror(defaultScreenId_, mirrorIds);
|
||||
@@ -145,9 +187,9 @@ HWTEST_F(ScreenManagerTest, ScreenManager03, Function | MediumTest | Level2)
|
||||
{
|
||||
DisplayTestUtils utils;
|
||||
ASSERT_TRUE(utils.CreateSurface());
|
||||
defaultoption_.surface_ = utils.psurface_;
|
||||
defaultOption_.surface_ = utils.psurface_;
|
||||
for (uint32_t i = 0; i < execTimes_; i++) {
|
||||
ScreenId virtualScreenId = ScreenManager::GetInstance().CreateVirtualScreen(defaultoption_);
|
||||
ScreenId virtualScreenId = ScreenManager::GetInstance().CreateVirtualScreen(defaultOption_);
|
||||
ASSERT_NE(SCREEN_ID_INVALID, virtualScreenId);
|
||||
ASSERT_EQ(DMError::DM_OK, ScreenManager::GetInstance().DestroyVirtualScreen(virtualScreenId));
|
||||
}
|
||||
@@ -162,9 +204,9 @@ HWTEST_F(ScreenManagerTest, ScreenManager04, Function | MediumTest | Level2)
|
||||
{
|
||||
DisplayTestUtils utils;
|
||||
ASSERT_TRUE(utils.CreateSurface());
|
||||
defaultoption_.surface_ = utils.psurface_;
|
||||
defaultOption_.surface_ = utils.psurface_;
|
||||
for (uint32_t i = 0; i < execTimes_; i++) {
|
||||
ScreenId virtualScreenId = ScreenManager::GetInstance().CreateVirtualScreen(defaultoption_);
|
||||
ScreenId virtualScreenId = ScreenManager::GetInstance().CreateVirtualScreen(defaultOption_);
|
||||
std::vector<ScreenId> mirrorIds;
|
||||
mirrorIds.push_back(virtualScreenId);
|
||||
ScreenManager::GetInstance().MakeMirror(defaultScreenId_, mirrorIds);
|
||||
@@ -183,8 +225,8 @@ HWTEST_F(ScreenManagerTest, ScreenManager05, Function | MediumTest | Level2)
|
||||
DisplayTestUtils utils;
|
||||
utils.SetDefaultWH(defaultDisplay_);
|
||||
ASSERT_TRUE(utils.CreateSurface());
|
||||
defaultoption_.surface_ = utils.psurface_;
|
||||
ScreenId virtualScreenId = ScreenManager::GetInstance().CreateVirtualScreen(defaultoption_);
|
||||
defaultOption_.surface_ = utils.psurface_;
|
||||
ScreenId virtualScreenId = ScreenManager::GetInstance().CreateVirtualScreen(defaultOption_);
|
||||
|
||||
ASSERT_NE(SCREEN_ID_INVALID, virtualScreenId);
|
||||
uint32_t lastCount = -1u;
|
||||
@@ -203,59 +245,125 @@ HWTEST_F(ScreenManagerTest, ScreenManager05, Function | MediumTest | Level2)
|
||||
ASSERT_EQ(DMError::DM_OK, ScreenManager::GetInstance().DestroyVirtualScreen(virtualScreenId));
|
||||
ASSERT_GT(utils.successCount_, 0);
|
||||
ASSERT_GT(maxWaitCount_, waitCount_);
|
||||
waitCount_ = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ScreenManager06
|
||||
* @tc.desc: Get and set screenMode
|
||||
* @tc.desc: Compare the length and width for recording screen, set VirtualScreen Surface before make mirror.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(ScreenManagerTest, ScreenManager06, Function | MediumTest | Level2)
|
||||
{
|
||||
sptr<Screen> screen = ScreenManager::GetInstance().GetScreenById(defaultScreenId_);
|
||||
auto modes = screen->GetSupportedModes();
|
||||
ASSERT_GT(modes.size(), 0);
|
||||
for (uint32_t modeIdx = 0; modeIdx < modes.size(); modeIdx++) {
|
||||
ASSERT_EQ(true, screen->SetScreenActiveMode(modeIdx));
|
||||
ASSERT_EQ(modeIdx, screen->GetModeId());
|
||||
DisplayTestUtils utils;
|
||||
utils.SetDefaultWH(defaultDisplay_);
|
||||
defaultOption_.surface_ = nullptr;
|
||||
ScreenId virtualScreenId = ScreenManager::GetInstance().CreateVirtualScreen(defaultOption_);
|
||||
ASSERT_NE(SCREEN_ID_INVALID, virtualScreenId);
|
||||
|
||||
ASSERT_TRUE(utils.CreateSurface());
|
||||
ASSERT_EQ(DMError::DM_OK, ScreenManager::GetInstance().SetVirtualScreenSurface(virtualScreenId, utils.psurface_));
|
||||
|
||||
uint32_t lastCount = -1u;
|
||||
std::vector<ScreenId> mirrorIds;
|
||||
mirrorIds.push_back(virtualScreenId);
|
||||
ScreenManager::GetInstance().MakeMirror(defaultScreenId_, mirrorIds);
|
||||
|
||||
while (utils.successCount_ < acquireFrames_ && waitCount_ <= maxWaitCount_) {
|
||||
if (lastCount != utils.successCount_) {
|
||||
lastCount = utils.successCount_;
|
||||
}
|
||||
ASSERT_EQ(0, utils.failCount_);
|
||||
waitCount_++;
|
||||
usleep(sleepUs_);
|
||||
}
|
||||
DMError res = ScreenManager::GetInstance().DestroyVirtualScreen(virtualScreenId);
|
||||
ASSERT_EQ(DMError::DM_OK, res);
|
||||
ASSERT_GT(utils.successCount_, 0);
|
||||
ASSERT_GT(maxWaitCount_, waitCount_);
|
||||
waitCount_ = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ScreenManager07
|
||||
* @tc.desc: Create a virtual screen as expansion of default screen, and destroy virtual screen
|
||||
* @tc.desc: Get and set screenMode
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(ScreenManagerTest, ScreenManager07, Function | MediumTest | Level2)
|
||||
{
|
||||
DisplayTestUtils utils;
|
||||
ASSERT_TRUE(utils.CreateSurface());
|
||||
defaultoption_.surface_ = utils.psurface_;
|
||||
defaultoption_.isForShot_ = false;
|
||||
ScreenId virtualScreenId = ScreenManager::GetInstance().CreateVirtualScreen(defaultoption_);
|
||||
ASSERT_NE(SCREEN_ID_INVALID, virtualScreenId);
|
||||
std::vector<sptr<Screen>> screens = ScreenManager::GetInstance().GetAllScreens();
|
||||
sptr<Screen> DefaultScreen = screens.front();
|
||||
std::vector<ExpandOption> options = {{DefaultScreen->GetId(), 0, 0}, {virtualScreenId, defaultWidth_, 0}};
|
||||
ScreenId expansionId = ScreenManager::GetInstance().MakeExpand(options);
|
||||
ASSERT_NE(SCREEN_ID_INVALID, expansionId);
|
||||
ASSERT_EQ(DMError::DM_OK, ScreenManager::GetInstance().DestroyVirtualScreen(virtualScreenId));
|
||||
sptr<Screen> screen = ScreenManager::GetInstance().GetScreenById(defaultScreenId_);
|
||||
auto modes = screen->GetSupportedModes();
|
||||
auto defaultModeId = screen->GetModeId();
|
||||
ASSERT_GT(modes.size(), 0);
|
||||
for (uint32_t modeIdx = 0; modeIdx < modes.size(); modeIdx++) {
|
||||
ASSERT_EQ(true, screen->SetScreenActiveMode(modeIdx));
|
||||
sleep(TEST_SPEEP_S);
|
||||
ASSERT_EQ(modeIdx, screen->GetModeId());
|
||||
}
|
||||
ASSERT_EQ(true, screen->SetScreenActiveMode(defaultModeId));
|
||||
sleep(TEST_SPEEP_S);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ScreenManager08
|
||||
* @tc.desc: Create a virtual screen as expansion of default screen, create windowNode on virtual screen,
|
||||
* and destroy virtual screen
|
||||
* @tc.desc: Create a virtual screen as expansion of default screen, and destroy virtual screen
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(ScreenManagerTest, ScreenManager08, Function | MediumTest | Level2)
|
||||
{
|
||||
DisplayTestUtils utils;
|
||||
ASSERT_TRUE(utils.CreateSurface());
|
||||
defaultoption_.surface_ = utils.psurface_;
|
||||
defaultoption_.isForShot_ = false;
|
||||
ScreenId virtualScreenId = ScreenManager::GetInstance().CreateVirtualScreen(defaultoption_);
|
||||
ASSERT_NE(SCREEN_ID_INVALID, virtualScreenId);
|
||||
defaultOption_.surface_ = utils.psurface_;
|
||||
defaultOption_.isForShot_ = false;
|
||||
sptr<ScreenChangeListener> screenListener = new ScreenChangeListener();
|
||||
sptr<ScreenGroupChangeListener> screenGroupChangeListener = new ScreenGroupChangeListener();
|
||||
ScreenManager::GetInstance().RegisterScreenListener(screenListener);
|
||||
ScreenManager::GetInstance().RegisterScreenGroupListener(screenGroupChangeListener);
|
||||
ScreenId virtualScreenId = ScreenManager::GetInstance().CreateVirtualScreen(defaultOption_);
|
||||
ScreenId screenId = screenListener->connectFuture_.GetResult(TIME_OUT);
|
||||
screenListener->connectFuture_.Reset();
|
||||
ASSERT_EQ(virtualScreenId, screenId);
|
||||
std::vector<sptr<Screen>> screens = ScreenManager::GetInstance().GetAllScreens();
|
||||
sptr<Screen> DefaultScreen = screens.front();
|
||||
std::vector<ExpandOption> options = {{DefaultScreen->GetId(), 0, 0}, {virtualScreenId, defaultWidth_, 0}};
|
||||
ScreenId expansionId = ScreenManager::GetInstance().MakeExpand(options);
|
||||
ASSERT_NE(SCREEN_ID_INVALID, expansionId);
|
||||
auto pair = screenGroupChangeListener->changeFuture_.GetResult(TIME_OUT);
|
||||
screenGroupChangeListener->changeFuture_.Reset();
|
||||
ASSERT_EQ(virtualScreenId, pair.first);
|
||||
ASSERT_EQ(ScreenGroupChangeEvent::ADD_TO_GROUP, pair.second);
|
||||
ASSERT_EQ(DMError::DM_OK, ScreenManager::GetInstance().DestroyVirtualScreen(virtualScreenId));
|
||||
screenId = screenListener->disconnectFuture_.GetResult(TIME_OUT);
|
||||
screenListener->disconnectFuture_.Reset();
|
||||
ASSERT_EQ(virtualScreenId, screenId);
|
||||
pair = screenGroupChangeListener->changeFuture_.GetResult(TIME_OUT);
|
||||
screenGroupChangeListener->changeFuture_.Reset();
|
||||
ASSERT_EQ(virtualScreenId, pair.first);
|
||||
ASSERT_EQ(ScreenGroupChangeEvent::REMOVE_FROM_GROUP, pair.second);
|
||||
ScreenManager::GetInstance().UnregisterScreenListener(screenListener);
|
||||
ScreenManager::GetInstance().UnregisterScreenGroupListener(screenGroupChangeListener);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ScreenManager09
|
||||
* @tc.desc: Create a virtual screen as expansion of default screen, create windowNode on virtual screen,
|
||||
* and destroy virtual screen
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(ScreenManagerTest, ScreenManager09, Function | MediumTest | Level2)
|
||||
{
|
||||
DisplayTestUtils utils;
|
||||
ASSERT_TRUE(utils.CreateSurface());
|
||||
defaultOption_.surface_ = utils.psurface_;
|
||||
defaultOption_.isForShot_ = false;
|
||||
sptr<ScreenChangeListener> screenListener = new ScreenChangeListener();
|
||||
sptr<ScreenGroupChangeListener> screenGroupChangeListener = new ScreenGroupChangeListener();
|
||||
ScreenManager::GetInstance().RegisterScreenListener(screenListener);
|
||||
ScreenManager::GetInstance().RegisterScreenGroupListener(screenGroupChangeListener);
|
||||
ScreenId virtualScreenId = ScreenManager::GetInstance().CreateVirtualScreen(defaultOption_);
|
||||
ScreenId screenId = screenListener->connectFuture_.GetResult(TIME_OUT);
|
||||
screenListener->connectFuture_.Reset();
|
||||
ASSERT_EQ(virtualScreenId, screenId);
|
||||
std::vector<sptr<Screen>> screens = ScreenManager::GetInstance().GetAllScreens();
|
||||
sptr<Screen> DefaultScreen = screens.front();
|
||||
DisplayId virtualDisplayId = DISPLAY_ID_INVALD;
|
||||
@@ -265,64 +373,311 @@ HWTEST_F(ScreenManagerTest, ScreenManager08, Function | MediumTest | Level2)
|
||||
virtualDisplayId = id; // find the display id of virtual screen
|
||||
}
|
||||
}
|
||||
ASSERT_NE(DISPLAY_ID_INVALD, virtualDisplayId);
|
||||
sptr<Window> window = CreateWindowByDisplayId(virtualDisplayId);
|
||||
ASSERT_NE(nullptr, window);
|
||||
sleep(TEST_SPEEP_S);
|
||||
std::vector<ExpandOption> options = {{DefaultScreen->GetId(), 0, 0}, {virtualScreenId, defaultWidth_, 0}};
|
||||
ScreenId expansionId = ScreenManager::GetInstance().MakeExpand(options);
|
||||
auto pair = screenGroupChangeListener->changeFuture_.GetResult(TIME_OUT);
|
||||
screenGroupChangeListener->changeFuture_.Reset();
|
||||
ASSERT_EQ(virtualScreenId, pair.first);
|
||||
ASSERT_EQ(ScreenGroupChangeEvent::ADD_TO_GROUP, pair.second);
|
||||
sleep(TEST_SPEEP_S);
|
||||
ASSERT_NE(SCREEN_ID_INVALID, expansionId);
|
||||
ASSERT_EQ(DMError::DM_OK, ScreenManager::GetInstance().DestroyVirtualScreen(virtualScreenId));
|
||||
screenId = screenListener->disconnectFuture_.GetResult(TIME_OUT);
|
||||
screenListener->disconnectFuture_.Reset();
|
||||
ASSERT_EQ(virtualScreenId, screenId);
|
||||
pair = screenGroupChangeListener->changeFuture_.GetResult(TIME_OUT);
|
||||
screenGroupChangeListener->changeFuture_.Reset();
|
||||
ASSERT_EQ(virtualScreenId, pair.first);
|
||||
ASSERT_EQ(ScreenGroupChangeEvent::REMOVE_FROM_GROUP, pair.second);
|
||||
ScreenManager::GetInstance().UnregisterScreenListener(screenListener);
|
||||
ScreenManager::GetInstance().UnregisterScreenGroupListener(screenGroupChangeListener);
|
||||
sleep(TEST_SPEEP_S);
|
||||
window->Destroy();
|
||||
// will add NotifyExpandDisconnect check logic.
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ScreenManager09
|
||||
* @tc.desc: Create a virtual screen and destroy it for 10 times, it's not for shot.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(ScreenManagerTest, ScreenManager09, Function | MediumTest | Level2)
|
||||
{
|
||||
DisplayTestUtils utils;
|
||||
ASSERT_TRUE(utils.CreateSurface());
|
||||
defaultoption_.surface_ = utils.psurface_;
|
||||
defaultoption_.isForShot_ = false;
|
||||
for (uint32_t i = 0; i < execTimes_; i++) {
|
||||
ScreenId virtualScreenId = ScreenManager::GetInstance().CreateVirtualScreen(defaultoption_);
|
||||
ASSERT_NE(SCREEN_ID_INVALID, virtualScreenId);
|
||||
auto screen = ScreenManager::GetInstance().GetScreenById(virtualScreenId);
|
||||
ASSERT_EQ(virtualScreenId, screen->GetId());
|
||||
ASSERT_EQ(SCREEN_ID_INVALID, screen->GetParentId());
|
||||
ASSERT_EQ(DMError::DM_OK, ScreenManager::GetInstance().DestroyVirtualScreen(virtualScreenId));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ScreenManager10
|
||||
* @tc.desc: Create a virtual screen , mirror and destroy it for 10 times, it's not for shot.
|
||||
* @tc.desc: Create a virtual screen and destroy it for 10 times, it's not for shot.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(ScreenManagerTest, ScreenManager10, Function | MediumTest | Level2)
|
||||
{
|
||||
DisplayTestUtils utils;
|
||||
ASSERT_TRUE(utils.CreateSurface());
|
||||
defaultoption_.surface_ = utils.psurface_;
|
||||
defaultoption_.isForShot_ = false;
|
||||
defaultOption_.surface_ = utils.psurface_;
|
||||
defaultOption_.isForShot_ = false;
|
||||
sptr<ScreenChangeListener> screenListener = new ScreenChangeListener();
|
||||
for (uint32_t i = 0; i < execTimes_; i++) {
|
||||
ScreenManager::GetInstance().RegisterScreenListener(screenListener);
|
||||
ScreenId virtualScreenId = ScreenManager::GetInstance().CreateVirtualScreen(defaultOption_);
|
||||
ASSERT_NE(SCREEN_ID_INVALID, virtualScreenId);
|
||||
ScreenId screenId = screenListener->connectFuture_.GetResult(TIME_OUT);
|
||||
screenListener->connectFuture_.Reset();
|
||||
ASSERT_EQ(virtualScreenId, screenId);
|
||||
auto screen = ScreenManager::GetInstance().GetScreenById(virtualScreenId);
|
||||
ASSERT_EQ(virtualScreenId, screen->GetId());
|
||||
ASSERT_EQ(SCREEN_ID_INVALID, screen->GetParentId());
|
||||
ASSERT_EQ(DMError::DM_OK, ScreenManager::GetInstance().DestroyVirtualScreen(virtualScreenId));
|
||||
screenId = screenListener->disconnectFuture_.GetResult(TIME_OUT);
|
||||
screenListener->disconnectFuture_.Reset();
|
||||
ASSERT_EQ(virtualScreenId, screenId);
|
||||
ScreenManager::GetInstance().UnregisterScreenListener(screenListener);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ScreenManager11
|
||||
* @tc.desc: Create a virtual screen , mirror and destroy it for 10 times, it's not for shot.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(ScreenManagerTest, ScreenManager11, Function | MediumTest | Level2)
|
||||
{
|
||||
DisplayTestUtils utils;
|
||||
ASSERT_TRUE(utils.CreateSurface());
|
||||
defaultOption_.surface_ = utils.psurface_;
|
||||
defaultOption_.isForShot_ = false;
|
||||
sptr<ScreenChangeListener> screenListener = new ScreenChangeListener();
|
||||
sptr<ScreenGroupChangeListener> screenGroupChangeListener = new ScreenGroupChangeListener();
|
||||
for (uint32_t i = 0; i < 10; i++) {
|
||||
ScreenId virtualScreenId = ScreenManager::GetInstance().CreateVirtualScreen(defaultoption_);
|
||||
ScreenManager::GetInstance().RegisterScreenListener(screenListener);
|
||||
ScreenManager::GetInstance().RegisterScreenGroupListener(screenGroupChangeListener);
|
||||
ScreenId virtualScreenId = ScreenManager::GetInstance().CreateVirtualScreen(defaultOption_);
|
||||
ASSERT_NE(SCREEN_ID_INVALID, virtualScreenId);
|
||||
ScreenId screenId = screenListener->connectFuture_.GetResult(TIME_OUT);
|
||||
screenListener->connectFuture_.Reset();
|
||||
ASSERT_EQ(virtualScreenId, screenId);
|
||||
std::vector<ScreenId> mirrorIds;
|
||||
mirrorIds.push_back(virtualScreenId);
|
||||
ScreenManager::GetInstance().MakeMirror(defaultScreenId_, mirrorIds);
|
||||
ASSERT_NE(SCREEN_ID_INVALID, virtualScreenId);
|
||||
auto pair = screenGroupChangeListener->changeFuture_.GetResult(TIME_OUT);
|
||||
screenGroupChangeListener->changeFuture_.Reset();
|
||||
ASSERT_EQ(virtualScreenId, pair.first);
|
||||
ASSERT_EQ(ScreenGroupChangeEvent::ADD_TO_GROUP, pair.second);
|
||||
auto screen = ScreenManager::GetInstance().GetScreenById(virtualScreenId);
|
||||
ASSERT_EQ(virtualScreenId, screen->GetId());
|
||||
ASSERT_NE(SCREEN_ID_INVALID, screen->GetParentId());
|
||||
ASSERT_EQ(DMError::DM_OK, ScreenManager::GetInstance().DestroyVirtualScreen(virtualScreenId));
|
||||
screenId = screenListener->disconnectFuture_.GetResult(TIME_OUT);
|
||||
screenListener->disconnectFuture_.Reset();
|
||||
ASSERT_EQ(virtualScreenId, screenId);
|
||||
pair = screenGroupChangeListener->changeFuture_.GetResult(TIME_OUT);
|
||||
screenGroupChangeListener->changeFuture_.Reset();
|
||||
ASSERT_EQ(virtualScreenId, pair.first);
|
||||
ASSERT_EQ(ScreenGroupChangeEvent::REMOVE_FROM_GROUP, pair.second);
|
||||
ScreenManager::GetInstance().UnregisterScreenListener(screenListener);
|
||||
ScreenManager::GetInstance().UnregisterScreenGroupListener(screenGroupChangeListener);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ScreenManager12
|
||||
* @tc.desc: Create a virtual screen as expansion of default screen cancel Make mirror, and destroy virtual screen
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(ScreenManagerTest, ScreenManager12, Function | MediumTest | Level2)
|
||||
{
|
||||
DisplayTestUtils utils;
|
||||
ASSERT_TRUE(utils.CreateSurface());
|
||||
defaultOption_.surface_ = utils.psurface_;
|
||||
defaultOption_.isForShot_ = false;
|
||||
sptr<ScreenChangeListener> screenListener = new ScreenChangeListener();
|
||||
sptr<ScreenGroupChangeListener> screenGroupChangeListener = new ScreenGroupChangeListener();
|
||||
ScreenManager::GetInstance().RegisterScreenListener(screenListener);
|
||||
ScreenManager::GetInstance().RegisterScreenGroupListener(screenGroupChangeListener);
|
||||
ScreenId virtualScreenId = ScreenManager::GetInstance().CreateVirtualScreen(defaultOption_);
|
||||
ASSERT_NE(SCREEN_ID_INVALID, virtualScreenId);
|
||||
ScreenId screenId = screenListener->connectFuture_.GetResult(TIME_OUT);
|
||||
screenListener->connectFuture_.Reset();
|
||||
ASSERT_EQ(virtualScreenId, screenId);
|
||||
|
||||
std::vector<ScreenId> mirrorIds;
|
||||
mirrorIds.push_back(virtualScreenId);
|
||||
ScreenManager::GetInstance().MakeMirror(defaultScreenId_, mirrorIds);
|
||||
auto pair = screenGroupChangeListener->changeFuture_.GetResult(TIME_OUT);
|
||||
screenGroupChangeListener->changeFuture_.Reset();
|
||||
ASSERT_EQ(virtualScreenId, pair.first);
|
||||
ASSERT_EQ(ScreenGroupChangeEvent::ADD_TO_GROUP, pair.second);
|
||||
auto screen = ScreenManager::GetInstance().GetScreenById(virtualScreenId);
|
||||
ASSERT_EQ(virtualScreenId, screen->GetId());
|
||||
ASSERT_NE(SCREEN_ID_INVALID, screen->GetParentId());
|
||||
|
||||
ScreenManager::GetInstance().RemoveVirtualScreenFromGroup(mirrorIds);
|
||||
pair = screenGroupChangeListener->changeFuture_.GetResult(TIME_OUT);
|
||||
screenGroupChangeListener->changeFuture_.Reset();
|
||||
ASSERT_EQ(virtualScreenId, pair.first);
|
||||
ASSERT_EQ(ScreenGroupChangeEvent::REMOVE_FROM_GROUP, pair.second);
|
||||
|
||||
ASSERT_EQ(DMError::DM_OK, ScreenManager::GetInstance().DestroyVirtualScreen(virtualScreenId));
|
||||
screenId = screenListener->disconnectFuture_.GetResult(TIME_OUT);
|
||||
screenListener->disconnectFuture_.Reset();
|
||||
ASSERT_EQ(virtualScreenId, screenId);
|
||||
ScreenManager::GetInstance().UnregisterScreenListener(screenListener);
|
||||
ScreenManager::GetInstance().UnregisterScreenGroupListener(screenGroupChangeListener);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ScreenManager13
|
||||
* @tc.desc: Create a virtual screen as expansion of default screen cancel MakeExpand, and destroy virtual screen
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(ScreenManagerTest, ScreenManager13, Function | MediumTest | Level2)
|
||||
{
|
||||
DisplayTestUtils utils;
|
||||
ASSERT_TRUE(utils.CreateSurface());
|
||||
defaultOption_.surface_ = utils.psurface_;
|
||||
defaultOption_.isForShot_ = false;
|
||||
sptr<ScreenChangeListener> screenListener = new ScreenChangeListener();
|
||||
sptr<ScreenGroupChangeListener> screenGroupChangeListener = new ScreenGroupChangeListener();
|
||||
ScreenManager::GetInstance().RegisterScreenListener(screenListener);
|
||||
ScreenManager::GetInstance().RegisterScreenGroupListener(screenGroupChangeListener);
|
||||
ScreenId virtualScreenId = ScreenManager::GetInstance().CreateVirtualScreen(defaultOption_);
|
||||
ScreenId screenId = screenListener->connectFuture_.GetResult(TIME_OUT);
|
||||
screenListener->connectFuture_.Reset();
|
||||
ASSERT_EQ(virtualScreenId, screenId);
|
||||
|
||||
std::vector<sptr<Screen>> screens = ScreenManager::GetInstance().GetAllScreens();
|
||||
sptr<Screen> DefaultScreen = screens.front();
|
||||
std::vector<ExpandOption> options = {{DefaultScreen->GetId(), 0, 0}, {virtualScreenId, defaultWidth_, 0}};
|
||||
ScreenId expansionId = ScreenManager::GetInstance().MakeExpand(options);
|
||||
ASSERT_NE(SCREEN_ID_INVALID, expansionId);
|
||||
auto pair = screenGroupChangeListener->changeFuture_.GetResult(TIME_OUT);
|
||||
screenGroupChangeListener->changeFuture_.Reset();
|
||||
ASSERT_EQ(virtualScreenId, pair.first);
|
||||
ASSERT_EQ(ScreenGroupChangeEvent::ADD_TO_GROUP, pair.second);
|
||||
|
||||
std::vector<ScreenId> cancelScreens;
|
||||
cancelScreens.emplace_back(virtualScreenId);
|
||||
ScreenManager::GetInstance().RemoveVirtualScreenFromGroup(cancelScreens);
|
||||
pair = screenGroupChangeListener->changeFuture_.GetResult(TIME_OUT);
|
||||
screenGroupChangeListener->changeFuture_.Reset();
|
||||
ASSERT_EQ(virtualScreenId, pair.first);
|
||||
ASSERT_EQ(ScreenGroupChangeEvent::REMOVE_FROM_GROUP, pair.second);
|
||||
|
||||
ASSERT_EQ(DMError::DM_OK, ScreenManager::GetInstance().DestroyVirtualScreen(virtualScreenId));
|
||||
screenId = screenListener->disconnectFuture_.GetResult(TIME_OUT);
|
||||
screenListener->disconnectFuture_.Reset();
|
||||
ASSERT_EQ(virtualScreenId, screenId);
|
||||
ScreenManager::GetInstance().UnregisterScreenListener(screenListener);
|
||||
ScreenManager::GetInstance().UnregisterScreenGroupListener(screenGroupChangeListener);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ScreenManager14
|
||||
* @tc.desc: Create a virtual screen, make expand to make mirror, and destroy virtual screen
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(ScreenManagerTest, ScreenManager14, Function | MediumTest | Level2)
|
||||
{
|
||||
DisplayTestUtils utils;
|
||||
ASSERT_TRUE(utils.CreateSurface());
|
||||
defaultOption_.surface_ = utils.psurface_;
|
||||
defaultOption_.isForShot_ = false;
|
||||
sptr<ScreenChangeListener> screenListener = new ScreenChangeListener();
|
||||
sptr<ScreenGroupChangeListener> screenGroupChangeListener = new ScreenGroupChangeListener();
|
||||
ScreenManager::GetInstance().RegisterScreenListener(screenListener);
|
||||
ScreenManager::GetInstance().RegisterScreenGroupListener(screenGroupChangeListener);
|
||||
ScreenId virtualScreenId = ScreenManager::GetInstance().CreateVirtualScreen(defaultOption_);
|
||||
ScreenId screenId = screenListener->connectFuture_.GetResult(TIME_OUT);
|
||||
screenListener->connectFuture_.Reset();
|
||||
ASSERT_EQ(virtualScreenId, screenId);
|
||||
|
||||
std::vector<sptr<Screen>> screens = ScreenManager::GetInstance().GetAllScreens();
|
||||
sptr<Screen> DefaultScreen = screens.front();
|
||||
std::vector<ExpandOption> options = {{DefaultScreen->GetId(), 0, 0}, {virtualScreenId, defaultWidth_, 0}};
|
||||
ScreenId expansionId = ScreenManager::GetInstance().MakeExpand(options);
|
||||
ASSERT_NE(SCREEN_ID_INVALID, expansionId);
|
||||
auto pair = screenGroupChangeListener->changeFuture_.GetResult(TIME_OUT);
|
||||
screenGroupChangeListener->changeFuture_.Reset();
|
||||
ASSERT_EQ(virtualScreenId, pair.first);
|
||||
ASSERT_EQ(ScreenGroupChangeEvent::ADD_TO_GROUP, pair.second);
|
||||
|
||||
std::vector<ScreenId> mirrorScreens;
|
||||
mirrorScreens.emplace_back(virtualScreenId);
|
||||
ScreenManager::GetInstance().MakeMirror(defaultScreenId_, mirrorScreens);
|
||||
pair = screenGroupChangeListener->changeFuture_.GetResult(TIME_OUT);
|
||||
screenGroupChangeListener->changeFuture_.Reset();
|
||||
ASSERT_EQ(virtualScreenId, pair.first);
|
||||
ASSERT_EQ(ScreenGroupChangeEvent::CHANGE_GROUP, pair.second);
|
||||
|
||||
ASSERT_EQ(DMError::DM_OK, ScreenManager::GetInstance().DestroyVirtualScreen(virtualScreenId));
|
||||
screenId = screenListener->disconnectFuture_.GetResult(TIME_OUT);
|
||||
screenListener->disconnectFuture_.Reset();
|
||||
ASSERT_EQ(virtualScreenId, screenId);
|
||||
ScreenManager::GetInstance().UnregisterScreenListener(screenListener);
|
||||
ScreenManager::GetInstance().UnregisterScreenGroupListener(screenGroupChangeListener);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ScreenManager15
|
||||
* @tc.desc: Create a virtual screen, make mirror to make expand, and destroy virtual screen
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(ScreenManagerTest, ScreenManager15, Function | MediumTest | Level2)
|
||||
{
|
||||
DisplayTestUtils utils;
|
||||
ASSERT_TRUE(utils.CreateSurface());
|
||||
defaultOption_.surface_ = utils.psurface_;
|
||||
defaultOption_.isForShot_ = false;
|
||||
sptr<ScreenChangeListener> screenListener = new ScreenChangeListener();
|
||||
sptr<ScreenGroupChangeListener> screenGroupChangeListener = new ScreenGroupChangeListener();
|
||||
ScreenManager::GetInstance().RegisterScreenListener(screenListener);
|
||||
ScreenManager::GetInstance().RegisterScreenGroupListener(screenGroupChangeListener);
|
||||
ScreenId virtualScreenId = ScreenManager::GetInstance().CreateVirtualScreen(defaultOption_);
|
||||
ScreenId screenId = screenListener->connectFuture_.GetResult(TIME_OUT);
|
||||
screenListener->connectFuture_.Reset();
|
||||
ASSERT_EQ(virtualScreenId, screenId);
|
||||
|
||||
std::vector<ScreenId> mirrorScreens;
|
||||
mirrorScreens.emplace_back(virtualScreenId);
|
||||
ScreenManager::GetInstance().MakeMirror(defaultScreenId_, mirrorScreens);
|
||||
auto pair = screenGroupChangeListener->changeFuture_.GetResult(TIME_OUT);
|
||||
screenGroupChangeListener->changeFuture_.Reset();
|
||||
ASSERT_EQ(virtualScreenId, pair.first);
|
||||
ASSERT_EQ(ScreenGroupChangeEvent::ADD_TO_GROUP, pair.second);
|
||||
|
||||
std::vector<sptr<Screen>> screens = ScreenManager::GetInstance().GetAllScreens();
|
||||
sptr<Screen> DefaultScreen = screens.front();
|
||||
std::vector<ExpandOption> options = {{DefaultScreen->GetId(), 0, 0}, {virtualScreenId, defaultWidth_, 0}};
|
||||
ScreenId expansionId = ScreenManager::GetInstance().MakeExpand(options);
|
||||
ASSERT_NE(SCREEN_ID_INVALID, expansionId);
|
||||
pair = screenGroupChangeListener->changeFuture_.GetResult(TIME_OUT);
|
||||
screenGroupChangeListener->changeFuture_.Reset();
|
||||
ASSERT_EQ(virtualScreenId, pair.first);
|
||||
ASSERT_EQ(ScreenGroupChangeEvent::CHANGE_GROUP, pair.second);
|
||||
|
||||
ASSERT_EQ(DMError::DM_OK, ScreenManager::GetInstance().DestroyVirtualScreen(virtualScreenId));
|
||||
screenId = screenListener->disconnectFuture_.GetResult(TIME_OUT);
|
||||
screenListener->disconnectFuture_.Reset();
|
||||
ASSERT_EQ(virtualScreenId, screenId);
|
||||
ScreenManager::GetInstance().UnregisterScreenListener(screenListener);
|
||||
ScreenManager::GetInstance().UnregisterScreenGroupListener(screenGroupChangeListener);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ScreenManager16
|
||||
* @tc.desc: Screen orientation.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(ScreenManagerTest, ScreenManager16, Function | MediumTest | Level2)
|
||||
{
|
||||
auto screens = ScreenManager::GetInstance().GetAllScreens();
|
||||
auto display = DisplayManager::GetInstance().GetDefaultDisplay();
|
||||
uint32_t orientation = static_cast<uint32_t>(Orientation::VERTICAL);
|
||||
uint32_t end = static_cast<uint32_t>(Orientation::REVERSE_HORIZONTAL);
|
||||
for (; orientation <= end; ++orientation) {
|
||||
screens[0]->SetOrientation(static_cast<Orientation>(orientation));
|
||||
usleep(1E6);
|
||||
ASSERT_EQ(static_cast<uint32_t>(screens[0]->GetOrientation()), orientation);
|
||||
ASSERT_EQ(static_cast<uint32_t>(display->GetOrientation()), orientation);
|
||||
}
|
||||
screens[0]->SetOrientation(Orientation::UNSPECIFIED);
|
||||
ASSERT_EQ(static_cast<uint32_t>(screens[0]->GetOrientation()), static_cast<uint32_t>(Orientation::UNSPECIFIED));
|
||||
ASSERT_EQ(static_cast<uint32_t>(display->GetOrientation()), static_cast<uint32_t>(Orientation::UNSPECIFIED));
|
||||
}
|
||||
}
|
||||
} // namespace Rosen
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -19,6 +19,8 @@
|
||||
#include "display_test_utils.h"
|
||||
#include "pixel_map.h"
|
||||
|
||||
#include "snapshot_utils.h"
|
||||
|
||||
using namespace testing;
|
||||
using namespace testing::ext;
|
||||
|
||||
@@ -37,7 +39,7 @@ public:
|
||||
static DisplayId defaultId_;
|
||||
DisplayId invalidId_ = DISPLAY_ID_INVALD;
|
||||
const std::string defaultCmd_ = "/system/bin/snapshot_display";
|
||||
const std::string defaultImg_ = "/data/snapshot_display_1.png";
|
||||
const int testTimeCount_ = 2;
|
||||
};
|
||||
|
||||
DisplayId ScreenshotCmdTest::defaultId_ = DISPLAY_ID_INVALD;
|
||||
@@ -87,15 +89,26 @@ namespace {
|
||||
*/
|
||||
HWTEST_F(ScreenshotCmdTest, ScreenShotCmdValid01, Function | MediumTest | Level2)
|
||||
{
|
||||
if (CheckFileExist(defaultImg_)) {
|
||||
remove(defaultImg_.c_str());
|
||||
std::string imgPath[testTimeCount_];
|
||||
int i;
|
||||
|
||||
for (i = 0; i < testTimeCount_; i++) {
|
||||
imgPath[i] = SnapShotUtils::GenerateFileName(i);
|
||||
if (CheckFileExist(imgPath[i])) {
|
||||
remove(imgPath[i].c_str());
|
||||
}
|
||||
}
|
||||
|
||||
(void)system(defaultCmd_.c_str());
|
||||
bool isExist = CheckFileExist(defaultImg_);
|
||||
if (isExist) {
|
||||
remove(defaultImg_.c_str());
|
||||
|
||||
for (i = 0; i < testTimeCount_; i++) {
|
||||
if (CheckFileExist(imgPath[i])) { // ok
|
||||
remove(imgPath[i].c_str());
|
||||
ASSERT_TRUE(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
ASSERT_EQ(true, isExist);
|
||||
ADD_FAILURE(); // fail, can't find snapshot file
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -105,16 +118,27 @@ HWTEST_F(ScreenshotCmdTest, ScreenShotCmdValid01, Function | MediumTest | Level2
|
||||
*/
|
||||
HWTEST_F(ScreenshotCmdTest, ScreenShotCmdValid02, Function | MediumTest | Level2)
|
||||
{
|
||||
if (CheckFileExist(defaultImg_)) {
|
||||
remove(defaultImg_.c_str());
|
||||
std::string imgPath[testTimeCount_];
|
||||
int i;
|
||||
|
||||
for (i = 0; i < testTimeCount_; i++) {
|
||||
imgPath[i] = SnapShotUtils::GenerateFileName(i);
|
||||
if (CheckFileExist(imgPath[i])) {
|
||||
remove(imgPath[i].c_str());
|
||||
}
|
||||
}
|
||||
|
||||
const std::string cmd = defaultCmd_ + " -i " + std::to_string(defaultId_);
|
||||
(void)system(cmd.c_str());
|
||||
bool isExist = CheckFileExist(defaultImg_);
|
||||
if (isExist) {
|
||||
remove(defaultImg_.c_str());
|
||||
|
||||
for (i = 0; i < testTimeCount_; i++) {
|
||||
if (CheckFileExist(imgPath[i])) { // ok
|
||||
remove(imgPath[i].c_str());
|
||||
ASSERT_TRUE(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
ASSERT_EQ(true, isExist);
|
||||
ADD_FAILURE(); // fail, can't find snapshot file
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -37,7 +37,7 @@ public:
|
||||
|
||||
virtual void OnDestroy(DisplayId displayId) {}
|
||||
|
||||
virtual void OnChange(DisplayId displayId, DisplayChangeEvent event) {}
|
||||
virtual void OnChange(DisplayId displayId) {}
|
||||
};
|
||||
|
||||
class DisplayChangeUnitTest : public testing::Test {
|
||||
|
||||
@@ -39,7 +39,7 @@ public:
|
||||
static inline sptr<DisplayPowerEventListener> listener_ = new DisplayPowerEventListener();
|
||||
static inline DisplayId defaultId_ = 0;
|
||||
static inline uint32_t brightnessLevel_ = 80;
|
||||
static inline uint32_t invalidBrightnessLevel_ = 10000000;
|
||||
static inline uint32_t invalidBrightnessLevel_ = 1000000000;
|
||||
static inline DisplayPowerState initialPowerState_;
|
||||
static inline DisplayState initialState_;
|
||||
};
|
||||
|
||||
@@ -23,25 +23,44 @@ namespace OHOS {
|
||||
namespace Rosen {
|
||||
class MockDisplayManagerAdapter : public DisplayManagerAdapter {
|
||||
public:
|
||||
MOCK_METHOD0(GetDefaultDisplayId, DisplayId());
|
||||
MOCK_METHOD1(GetDisplayById, sptr<Display>(DisplayId displayId));
|
||||
MOCK_METHOD1(CreateVirtualScreen, ScreenId(VirtualScreenOption option));
|
||||
MOCK_METHOD1(DestroyVirtualScreen, DMError(ScreenId screenId));
|
||||
MOCK_METHOD1(GetDisplaySnapshot, std::shared_ptr<Media::PixelMap>(DisplayId displayId));
|
||||
MOCK_METHOD0(Clear, void());
|
||||
MOCK_METHOD2(RegisterDisplayManagerAgent, bool(const sptr<IDisplayManagerAgent>& displayManagerAgent,
|
||||
DisplayManagerAgentType type));
|
||||
MOCK_METHOD2(UnregisterDisplayManagerAgent, bool(const sptr<IDisplayManagerAgent>& displayManagerAgent,
|
||||
DisplayManagerAgentType type));
|
||||
MOCK_METHOD0(GetDefaultDisplayId, DisplayId());
|
||||
MOCK_METHOD1(GetDisplayInfoByScreenId, sptr<DisplayInfo>(ScreenId screenId));
|
||||
MOCK_METHOD1(GetDisplaySnapshot, std::shared_ptr<Media::PixelMap>(DisplayId displayId));
|
||||
|
||||
MOCK_METHOD1(WakeUpBegin, bool(PowerStateChangeReason reason));
|
||||
MOCK_METHOD0(WakeUpEnd, bool());
|
||||
MOCK_METHOD1(SuspendBegin, bool(PowerStateChangeReason reason));
|
||||
MOCK_METHOD0(SuspendEnd, bool());
|
||||
MOCK_METHOD2(SetScreenPowerForAll, bool(DisplayPowerState state, PowerStateChangeReason reason));
|
||||
MOCK_METHOD1(SetDisplayState, bool(DisplayState state));
|
||||
MOCK_METHOD1(GetDisplayState, DisplayState(uint64_t displayId));
|
||||
MOCK_METHOD1(GetDisplayState, DisplayState(DisplayId displayId));
|
||||
MOCK_METHOD1(NotifyDisplayEvent, void(DisplayEvent event));
|
||||
MOCK_METHOD1(GetDisplayInfo, sptr<DisplayInfo>(DisplayId displayId));
|
||||
};
|
||||
|
||||
class MockScreenManagerAdapter : public ScreenManagerAdapter {
|
||||
public:
|
||||
MOCK_METHOD0(Clear, void());
|
||||
MOCK_METHOD2(RegisterDisplayManagerAgent, bool(const sptr<IDisplayManagerAgent>& displayManagerAgent,
|
||||
DisplayManagerAgentType type));
|
||||
MOCK_METHOD2(UnregisterDisplayManagerAgent, bool(const sptr<IDisplayManagerAgent>& displayManagerAgent,
|
||||
DisplayManagerAgentType type));
|
||||
MOCK_METHOD2(RequestRotation, bool(ScreenId screenId, Rotation rotation));
|
||||
MOCK_METHOD1(CreateVirtualScreen, ScreenId(VirtualScreenOption option));
|
||||
MOCK_METHOD1(DestroyVirtualScreen, DMError(ScreenId screenId));
|
||||
MOCK_METHOD2(SetVirtualScreenSurface, DMError(ScreenId screenId, sptr<Surface> surface));
|
||||
MOCK_METHOD1(GetScreenGroupInfoById, sptr<ScreenGroupInfo>(ScreenId screenId));
|
||||
MOCK_METHOD0(GetAllScreenInfos, std::vector<sptr<ScreenInfo>>());
|
||||
MOCK_METHOD2(MakeMirror, ScreenId(ScreenId mainScreenId, std::vector<ScreenId> mirrorScreenId));
|
||||
MOCK_METHOD2(MakeExpand, ScreenId(std::vector<ScreenId> screenId, std::vector<Point> startPoint));
|
||||
MOCK_METHOD2(SetScreenActiveMode, bool(ScreenId screenId, uint32_t modeId));
|
||||
MOCK_METHOD2(MakeExpand, DMError(std::vector<ScreenId> screenId, std::vector<Point> startPoint));
|
||||
MOCK_METHOD1(GetScreenInfo, sptr<ScreenInfo>(ScreenId screenId));
|
||||
|
||||
MOCK_METHOD2(GetScreenSupportedColorGamuts, DMError(ScreenId screenId, std::vector<ScreenColorGamut>& colorGamuts));
|
||||
MOCK_METHOD2(GetScreenColorGamut, DMError(ScreenId screenId, ScreenColorGamut& colorGamut));
|
||||
MOCK_METHOD2(SetScreenColorGamut, DMError(ScreenId screenId, int32_t colorGamutIdx));
|
||||
|
||||
@@ -22,7 +22,7 @@ using namespace testing::ext;
|
||||
|
||||
namespace OHOS {
|
||||
namespace Rosen {
|
||||
using Mocker = SingletonMocker<DisplayManagerAdapter, MockDisplayManagerAdapter>;
|
||||
using Mocker = SingletonMocker<ScreenManagerAdapter, MockScreenManagerAdapter>;
|
||||
|
||||
sptr<Display> ScreenManagerTest::defaultDisplay_ = nullptr;
|
||||
DisplayId ScreenManagerTest::defaultDisplayId_ = DISPLAY_ID_INVALD;
|
||||
@@ -105,7 +105,7 @@ HWTEST_F(ScreenManagerTest, MakeExpand_001, Function | SmallTest | Level1)
|
||||
std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
|
||||
EXPECT_CALL(m->Mock(), CreateVirtualScreen(_)).Times(1).WillOnce(Return(virtualScreenId));
|
||||
EXPECT_CALL(m->Mock(), DestroyVirtualScreen(_)).Times(1).WillOnce(Return(DMError::DM_OK));
|
||||
EXPECT_CALL(m->Mock(), MakeExpand(_, _)).Times(1).WillOnce(Return(DMError::DM_OK));
|
||||
EXPECT_CALL(m->Mock(), MakeExpand(_, _)).Times(1).WillOnce(Return(0));
|
||||
ScreenId vScreenId = ScreenManager::GetInstance().CreateVirtualScreen(defaultOption);
|
||||
std::vector<ExpandOption> options = {{validId, 0, 0}, {vScreenId, defaultWidth_, 0}};
|
||||
ScreenId expansionId = ScreenManager::GetInstance().MakeExpand(options);
|
||||
@@ -123,12 +123,57 @@ HWTEST_F(ScreenManagerTest, MakeExpand_001, Function | SmallTest | Level1)
|
||||
HWTEST_F(ScreenManagerTest, MakeExpand_002, Function | SmallTest | Level1)
|
||||
{
|
||||
ScreenId invalidId = SCREEN_ID_INVALID;
|
||||
std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
|
||||
EXPECT_CALL(m->Mock(), MakeExpand(_, _)).Times(1).WillOnce(Return(DMError::DM_ERROR_INVALID_PARAM));
|
||||
std::vector<ExpandOption> options = {};
|
||||
ScreenId expansionId = ScreenManager::GetInstance().MakeExpand(options);
|
||||
ASSERT_EQ(expansionId, invalidId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: SetSurface01
|
||||
* @tc.desc: SetVirtualScreenSurface with valid option and return success
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(ScreenManagerTest, SetSurface01, Function | SmallTest | Level1)
|
||||
{
|
||||
ScreenManagerUtils utils;
|
||||
ASSERT_TRUE(utils.CreateSurface());
|
||||
VirtualScreenOption defaultOption = {defaultName_, defaultWidth_, defaultHeight_,
|
||||
defaultDensity_, nullptr, defaultFlags_};
|
||||
ScreenId validId = 0;
|
||||
std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
|
||||
EXPECT_CALL(m->Mock(), CreateVirtualScreen(_)).Times(1).WillOnce(Return(validId));
|
||||
EXPECT_CALL(m->Mock(), SetVirtualScreenSurface(_, _)).Times(1).WillOnce(Return(DMError::DM_OK));
|
||||
EXPECT_CALL(m->Mock(), DestroyVirtualScreen(_)).Times(1).WillOnce(Return(DMError::DM_OK));
|
||||
ScreenId id = ScreenManager::GetInstance().CreateVirtualScreen(defaultOption);
|
||||
DMError surfaceRes = ScreenManager::GetInstance().SetVirtualScreenSurface(id, utils.psurface_);
|
||||
DMError destroyRes = ScreenManager::GetInstance().DestroyVirtualScreen(id);
|
||||
ASSERT_EQ(validId, id);
|
||||
ASSERT_EQ(DMError::DM_OK, surfaceRes);
|
||||
ASSERT_EQ(DMError::DM_OK, destroyRes);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: SetSurface02
|
||||
* @tc.desc: SetVirtualScreenSurface with invalid option and return failed
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(ScreenManagerTest, SetSurface02, Function | SmallTest | Level1)
|
||||
{
|
||||
ScreenManagerUtils utils;
|
||||
ASSERT_TRUE(utils.CreateSurface());
|
||||
VirtualScreenOption defaultOption = {defaultName_, defaultWidth_, defaultHeight_,
|
||||
defaultDensity_, nullptr, defaultFlags_};
|
||||
std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
|
||||
EXPECT_CALL(m->Mock(), CreateVirtualScreen(_)).Times(1).WillOnce(Return(SCREEN_ID_INVALID));
|
||||
EXPECT_CALL(m->Mock(), SetVirtualScreenSurface(_, _)).Times(1).WillOnce(Return(DMError::DM_ERROR_INVALID_PARAM));
|
||||
EXPECT_CALL(m->Mock(), DestroyVirtualScreen(_)).Times(1).WillOnce(Return(DMError::DM_ERROR_INVALID_PARAM));
|
||||
ScreenId id = ScreenManager::GetInstance().CreateVirtualScreen(defaultOption);
|
||||
DMError surfaceRes = ScreenManager::GetInstance().SetVirtualScreenSurface(id, utils.psurface_);
|
||||
DMError destroyRes = ScreenManager::GetInstance().DestroyVirtualScreen(id);
|
||||
ASSERT_EQ(SCREEN_ID_INVALID, id);
|
||||
ASSERT_EQ(DMError::DM_ERROR_INVALID_PARAM, surfaceRes);
|
||||
ASSERT_EQ(DMError::DM_ERROR_INVALID_PARAM, destroyRes);
|
||||
}
|
||||
}
|
||||
} // namespace Rosen
|
||||
} // namespace OHOS
|
||||
@@ -22,7 +22,7 @@ using namespace testing::ext;
|
||||
|
||||
namespace OHOS {
|
||||
namespace Rosen {
|
||||
using Mocker = SingletonMocker<DisplayManagerAdapter, MockDisplayManagerAdapter>;
|
||||
using Mocker = SingletonMocker<ScreenManagerAdapter, MockScreenManagerAdapter>;
|
||||
|
||||
sptr<Display> ScreenTest::defaultDisplay_ = nullptr;
|
||||
ScreenId ScreenTest::defaultScreenId_ = SCREEN_ID_INVALID;
|
||||
|
||||
@@ -28,7 +28,7 @@ public:
|
||||
constexpr static int32_t DEFAULT_HIGHT = 1280;
|
||||
constexpr static float DEFAULT_VIRTUAL_PIXEL_RATIO = 1.0;
|
||||
constexpr static uint32_t DEFAULT_FRESH_RATE = 60;
|
||||
AbstractDisplay(const DisplayInfo& info);
|
||||
AbstractDisplay(const DisplayInfo* info);
|
||||
AbstractDisplay(DisplayId id, ScreenId screenId, int32_t width, int32_t height, uint32_t freshRate);
|
||||
~AbstractDisplay() = default;
|
||||
static inline bool IsVertical(Rotation rotation)
|
||||
@@ -43,14 +43,16 @@ public:
|
||||
ScreenId GetAbstractScreenId() const;
|
||||
bool BindAbstractScreen(ScreenId dmsScreenId);
|
||||
bool BindAbstractScreen(sptr<AbstractScreen> abstractDisplay);
|
||||
const sptr<DisplayInfo> ConvertToDisplayInfo() const;
|
||||
sptr<DisplayInfo> ConvertToDisplayInfo() const;
|
||||
|
||||
void SetId(DisplayId displayId);
|
||||
void SetWidth(int32_t width);
|
||||
void SetHeight(int32_t height);
|
||||
void SetFreshRate(uint32_t freshRate);
|
||||
void SetVirtualPixelRatio(float virtualPixelRatio);
|
||||
void SetOrientation(Orientation orientation);
|
||||
bool RequestRotation(Rotation rotation);
|
||||
Rotation GetRotation();
|
||||
|
||||
private:
|
||||
DisplayId id_ { DISPLAY_ID_INVALD };
|
||||
@@ -60,6 +62,7 @@ private:
|
||||
uint32_t freshRate_ { 0 };
|
||||
float virtualPixelRatio_ { 1.0 };
|
||||
Rotation rotation_ { Rotation::ROTATION_0 };
|
||||
Orientation orientation_ { Orientation::UNSPECIFIED };
|
||||
};
|
||||
} // namespace OHOS::Rosen
|
||||
#endif // FOUNDATION_DMSERVER_ABSTRACT_DISPLAY_H
|
||||
@@ -40,19 +40,21 @@ public:
|
||||
|
||||
std::shared_ptr<Media::PixelMap> GetScreenSnapshot(DisplayId displayId);
|
||||
sptr<AbstractDisplay> GetAbstractDisplay(DisplayId displayId) const;
|
||||
sptr<AbstractDisplay> GetAbstractDisplayByScreen(ScreenId screenId) const;
|
||||
std::vector<DisplayId> GetAllDisplayIds() const;
|
||||
void AddDisplayForExpandScreen(sptr<AbstractScreen> absScreen);
|
||||
|
||||
private:
|
||||
void OnAbstractScreenConnect(sptr<AbstractScreen> absScreen);
|
||||
void OnAbstractScreenDisconnect(sptr<AbstractScreen> absScreen);
|
||||
void OnAbstractScreenChange(sptr<AbstractScreen> absScreen, DisplayChangeEvent event);
|
||||
void ProcessDisplayUpdateRotation(sptr<AbstractScreen> absScreen);
|
||||
void ProcessDisplayUpdateOrientation(sptr<AbstractScreen> absScreen);
|
||||
void ProcessDisplaySizeChange(sptr<AbstractScreen> absScreen);
|
||||
void BindAloneScreenLocked(sptr<AbstractScreen> absScreen);
|
||||
void AddScreenToMirrorLocked(sptr<AbstractScreen> absScreen);
|
||||
void AddScreenToExpandLocked(sptr<AbstractScreen> absScreen);
|
||||
void ProcessNormalScreenDisconnected(sptr<AbstractScreen> absScreen, sptr<AbstractScreenGroup> screenGroup);
|
||||
void ProcessExpandScreenDisconnected(sptr<AbstractScreen> absScreen, sptr<AbstractScreenGroup> screenGroup);
|
||||
DisplayId ProcessNormalScreenDisconnected(sptr<AbstractScreen> absScreen, sptr<AbstractScreenGroup> screenGroup);
|
||||
DisplayId ProcessExpandScreenDisconnected(sptr<AbstractScreen> absScreen, sptr<AbstractScreenGroup> screenGroup);
|
||||
bool UpdateDisplaySize(sptr<AbstractDisplay> absDisplay, sptr<SupportedScreenModes> info);
|
||||
|
||||
std::recursive_mutex& mutex_;
|
||||
|
||||
@@ -30,25 +30,19 @@
|
||||
#include "screen_info.h"
|
||||
|
||||
namespace OHOS::Rosen {
|
||||
enum class ScreenType : uint32_t {
|
||||
UNDEFINE,
|
||||
REAL,
|
||||
VIRTUAL
|
||||
};
|
||||
|
||||
class AbstractScreenGroup;
|
||||
class AbstractScreenController;
|
||||
class AbstractScreen : public RefBase {
|
||||
public:
|
||||
AbstractScreen(ScreenId dmsId, ScreenId rsId);
|
||||
AbstractScreen(const std::string& name, ScreenId dmsId, ScreenId rsId);
|
||||
AbstractScreen() = delete;
|
||||
~AbstractScreen();
|
||||
sptr<SupportedScreenModes> GetActiveScreenMode() const;
|
||||
std::vector<sptr<SupportedScreenModes>> GetAbstractScreenModes() const;
|
||||
sptr<AbstractScreenGroup> GetGroup() const;
|
||||
const sptr<ScreenInfo> ConvertToScreenInfo() const;
|
||||
void RequestRotation(Rotation rotation);
|
||||
Rotation GetRotation() const;
|
||||
sptr<ScreenInfo> ConvertToScreenInfo() const;
|
||||
bool SetOrientation(Orientation orientation);
|
||||
Rotation CalcRotation(Orientation orientation) const;
|
||||
|
||||
void UpdateRSTree(std::shared_ptr<RSSurfaceNode>& surfaceNode, bool isAdd);
|
||||
void InitRSDisplayNode(RSDisplayNodeConfig& config);
|
||||
@@ -61,16 +55,18 @@ public:
|
||||
DMError SetScreenGamutMap(ScreenGamutMap gamutMap);
|
||||
DMError SetScreenColorTransform();
|
||||
|
||||
const std::string name_;
|
||||
ScreenId dmsId_;
|
||||
ScreenId rsId_;
|
||||
bool canHasChild_ { false };
|
||||
std::shared_ptr<RSDisplayNode> rsDisplayNode_;
|
||||
RSDisplayNodeConfig rSDisplayNodeConfig_;
|
||||
ScreenId groupDmsId_ {INVALID_SCREEN_ID};
|
||||
ScreenId groupDmsId_ { SCREEN_ID_INVALID };
|
||||
ScreenType type_ { ScreenType::REAL };
|
||||
int32_t activeIdx_ { 0 };
|
||||
float virtualPixelRatio = { 1.0 };
|
||||
std::vector<sptr<SupportedScreenModes>> modes_ = {};
|
||||
float virtualPixelRatio = { 1.0 };
|
||||
Orientation orientation_ { Orientation::UNSPECIFIED };
|
||||
Rotation rotation_ { Rotation::ROTATION_0 };
|
||||
protected:
|
||||
void FillScreenInfo(sptr<ScreenInfo>) const;
|
||||
@@ -90,11 +86,11 @@ public:
|
||||
std::vector<sptr<AbstractScreen>> GetChildren() const;
|
||||
std::vector<Point> GetChildrenPosition() const;
|
||||
size_t GetChildCount() const;
|
||||
const sptr<ScreenGroupInfo> ConvertToScreenGroupInfo() const;
|
||||
sptr<ScreenGroupInfo> ConvertToScreenGroupInfo() const;
|
||||
bool SetRSDisplayNodeConfig(sptr<AbstractScreen>& dmsScreen, struct RSDisplayNodeConfig& config);
|
||||
|
||||
ScreenCombination combination_ { ScreenCombination::SCREEN_ALONE };
|
||||
ScreenId mirrorScreenId_ {INVALID_SCREEN_ID};
|
||||
ScreenId mirrorScreenId_ { SCREEN_ID_INVALID };
|
||||
|
||||
private:
|
||||
std::map<ScreenId, std::pair<sptr<AbstractScreen>, Point>> abstractScreenMap_;
|
||||
|
||||
@@ -49,21 +49,22 @@ public:
|
||||
std::vector<ScreenId> GetAllExpandOrMirrorScreenIds(std::vector<ScreenId>) const;
|
||||
sptr<AbstractScreenGroup> GetAbstractScreenGroup(ScreenId dmsScreenId);
|
||||
ScreenId GetDefaultAbstractScreenId();
|
||||
ScreenId GetDefaultScreenId() const; // save default screenID got by GetDefaultAbstractScreenId as cache
|
||||
ScreenId ConvertToRsScreenId(ScreenId dmsScreenId);
|
||||
ScreenId ConvertToDmsScreenId(ScreenId rsScreenId);
|
||||
void RegisterAbstractScreenCallback(sptr<AbstractScreenCallback> cb);
|
||||
ScreenId CreateVirtualScreen(VirtualScreenOption option);
|
||||
DMError DestroyVirtualScreen(ScreenId screenId);
|
||||
DMError SetVirtualScreenSurface(ScreenId screenId, sptr<Surface> surface);
|
||||
bool RequestRotation(ScreenId screenId, Rotation rotation);
|
||||
bool SetOrientation(ScreenId screenId, Orientation orientation);
|
||||
|
||||
void OnScreenRotate(ScreenId dmsScreenId, Rotation before, Rotation after);
|
||||
bool IsScreenGroup(ScreenId screenId) const;
|
||||
bool SetScreenActiveMode(ScreenId screenId, uint32_t modeId);
|
||||
std::shared_ptr<RSDisplayNode> GetRSDisplayNodeByScreenId(ScreenId dmsScreenId) const;
|
||||
void UpdateRSTree(ScreenId dmsScreenId, std::shared_ptr<RSSurfaceNode>& surfaceNode, bool isAdd);
|
||||
bool MakeMirror(ScreenId, std::vector<ScreenId> screens);
|
||||
bool MakeExpand(std::vector<ScreenId> screenIds, std::vector<Point> startPoints);
|
||||
void RemoveVirtualScreenFromGroup(std::vector<ScreenId> screens);
|
||||
void DumpScreenInfo() const;
|
||||
void DumpScreenGroupInfo() const;
|
||||
|
||||
@@ -81,10 +82,15 @@ private:
|
||||
bool FillAbstractScreen(sptr<AbstractScreen>& absScreen, ScreenId rsScreenId);
|
||||
sptr<AbstractScreenGroup> AddToGroupLocked(sptr<AbstractScreen> newScreen);
|
||||
sptr<AbstractScreenGroup> RemoveFromGroupLocked(sptr<AbstractScreen> newScreen);
|
||||
bool RemoveChildFromGroup(sptr<AbstractScreen>, sptr<AbstractScreenGroup>);
|
||||
bool CheckScreenInScreenGroup(sptr<AbstractScreen> newScreen) const;
|
||||
sptr<AbstractScreenGroup> AddAsFirstScreenLocked(sptr<AbstractScreen> newScreen);
|
||||
sptr<AbstractScreenGroup> AddAsSuccedentScreenLocked(sptr<AbstractScreen> newScreen);
|
||||
void ProcessScreenModeChanged(ScreenId rsScreenId);
|
||||
void ProcessScreenModeChanged(ScreenId dmsScreenId);
|
||||
void ChangeScreenGroup(sptr<AbstractScreenGroup> group, const std::vector<ScreenId>& screens,
|
||||
const std::vector<Point>& startPoints, bool filterScreen, ScreenCombination combination);
|
||||
void AddScreenToGroup(sptr<AbstractScreenGroup>, const std::vector<ScreenId>&,
|
||||
const std::vector<Point>&, std::map<ScreenId, bool>&);
|
||||
|
||||
std::recursive_mutex& mutex_;
|
||||
OHOS::Rosen::RSInterfaces& rsInterface_;
|
||||
@@ -95,6 +101,7 @@ private:
|
||||
std::map<ScreenId, sptr<AbstractScreen>> dmsScreenMap_;
|
||||
std::map<ScreenId, sptr<AbstractScreenGroup>> dmsScreenGroupMap_;
|
||||
sptr<AbstractScreenCallback> abstractScreenCallback_;
|
||||
ScreenId defaultScreenId = INVALID_SCREEN_ID;
|
||||
};
|
||||
} // namespace OHOS::Rosen
|
||||
#endif // FOUNDATION_DMSERVER_ABSTRACT_SCREEN_CONTROLLER_H
|
||||
@@ -36,8 +36,9 @@ public:
|
||||
|
||||
void OnScreenConnect(sptr<ScreenInfo> screenInfo);
|
||||
void OnScreenDisconnect(ScreenId);
|
||||
void OnScreenChange(const std::vector<const sptr<ScreenInfo>>&, ScreenChangeEvent);
|
||||
void OnScreenChange(sptr<ScreenInfo>, ScreenChangeEvent);
|
||||
void OnScreenChange(const sptr<ScreenInfo>, ScreenChangeEvent);
|
||||
void OnScreenGroupChange(const sptr<ScreenInfo>&, ScreenGroupChangeEvent);
|
||||
void OnScreenGroupChange(const std::vector<sptr<ScreenInfo>>&, ScreenGroupChangeEvent);
|
||||
void OnDisplayCreate(sptr<DisplayInfo>);
|
||||
void OnDisplayDestroy(DisplayId);
|
||||
void OnDisplayChange(sptr<DisplayInfo>, DisplayChangeEvent);
|
||||
|
||||
@@ -35,6 +35,7 @@ public:
|
||||
enum {
|
||||
TRANS_ID_GET_DEFAULT_DISPLAY_ID = 0,
|
||||
TRANS_ID_GET_DISPLAY_BY_ID,
|
||||
TRANS_ID_GET_DISPLAY_BY_SCREEN,
|
||||
TRANS_ID_GET_DISPLAY_SNAPSHOT,
|
||||
TRANS_ID_REGISTER_DISPLAY_MANAGER_AGENT,
|
||||
TRANS_ID_UNREGISTER_DISPLAY_MANAGER_AGENT,
|
||||
@@ -45,6 +46,7 @@ public:
|
||||
TRANS_ID_SET_SCREEN_POWER_FOR_ALL,
|
||||
TRANS_ID_SET_DISPLAY_STATE,
|
||||
TRANS_ID_GET_DISPLAY_STATE,
|
||||
TRANS_ID_GET_ALL_DISPLAYIDS,
|
||||
TRANS_ID_NOTIFY_DISPLAY_EVENT,
|
||||
TRANS_ID_SCREEN_BASE = 1000,
|
||||
TRANS_ID_CREATE_VIRTUAL_SCREEN = TRANS_ID_SCREEN_BASE,
|
||||
@@ -54,10 +56,11 @@ public:
|
||||
TRANS_ID_GET_SCREEN_GROUP_INFO_BY_ID,
|
||||
TRANS_ID_SET_SCREEN_ACTIVE_MODE,
|
||||
TRANS_ID_GET_ALL_SCREEN_INFOS,
|
||||
TRANS_ID_REQUEST_ROTATION,
|
||||
TRANS_ID_SET_ORIENTATION,
|
||||
TRANS_ID_SCREENGROUP_BASE = 1100,
|
||||
TRANS_ID_SCREEN_MAKE_MIRROR = TRANS_ID_SCREENGROUP_BASE,
|
||||
TRANS_ID_SCREEN_MAKE_EXPAND,
|
||||
TRANS_ID_SCREEN_MAKE_MIRROR_OR_EXPAND_CANCELED,
|
||||
TRANS_ID_SCREEN_GAMUT_BASE = 1200,
|
||||
TRANS_ID_SCREEN_GET_SUPPORTED_COLOR_GAMUTS = TRANS_ID_SCREEN_GAMUT_BASE,
|
||||
TRANS_ID_SCREEN_GET_COLOR_GAMUT,
|
||||
@@ -68,13 +71,14 @@ public:
|
||||
};
|
||||
|
||||
virtual DisplayId GetDefaultDisplayId() = 0;
|
||||
virtual DisplayInfo GetDisplayInfoById(DisplayId displayId) = 0;
|
||||
virtual sptr<DisplayInfo> GetDisplayInfoById(DisplayId displayId) = 0;
|
||||
virtual sptr<DisplayInfo> GetDisplayInfoByScreen(ScreenId screenId) = 0;
|
||||
|
||||
virtual ScreenId CreateVirtualScreen(VirtualScreenOption option) = 0;
|
||||
virtual DMError DestroyVirtualScreen(ScreenId screenId) = 0;
|
||||
virtual DMError SetVirtualScreenSurface(ScreenId screenId, sptr<Surface> surface) = 0;
|
||||
virtual bool RequestRotation(ScreenId screenId, Rotation rotation) = 0;
|
||||
virtual std::shared_ptr<Media::PixelMap> GetDispalySnapshot(DisplayId displayId) = 0;
|
||||
virtual bool SetOrientation(ScreenId screenId, Orientation orientation) = 0;
|
||||
virtual std::shared_ptr<Media::PixelMap> GetDisplaySnapshot(DisplayId displayId) = 0;
|
||||
|
||||
// colorspace, gamut
|
||||
virtual DMError GetScreenSupportedColorGamuts(ScreenId screenId, std::vector<ScreenColorGamut>& colorGamuts) = 0;
|
||||
@@ -95,12 +99,14 @@ public:
|
||||
virtual bool SetScreenPowerForAll(DisplayPowerState state, PowerStateChangeReason reason) = 0;
|
||||
virtual bool SetDisplayState(DisplayState state) = 0;
|
||||
virtual DisplayState GetDisplayState(DisplayId displayId) = 0;
|
||||
virtual std::vector<DisplayId> GetAllDisplayIds() = 0;
|
||||
virtual void NotifyDisplayEvent(DisplayEvent event) = 0;
|
||||
virtual sptr<ScreenInfo> GetScreenInfoById(ScreenId screenId) = 0;
|
||||
virtual sptr<ScreenGroupInfo> GetScreenGroupInfoById(ScreenId screenId) = 0;
|
||||
virtual std::vector<sptr<ScreenInfo>> GetAllScreenInfos() = 0;
|
||||
virtual DMError MakeMirror(ScreenId mainScreenId, std::vector<ScreenId> mirrorScreenId) = 0;
|
||||
virtual DMError MakeExpand(std::vector<ScreenId> screenId, std::vector<Point> startPoint) = 0;
|
||||
virtual ScreenId MakeMirror(ScreenId mainScreenId, std::vector<ScreenId> mirrorScreenId) = 0;
|
||||
virtual ScreenId MakeExpand(std::vector<ScreenId> screenId, std::vector<Point> startPoint) = 0;
|
||||
virtual void RemoveVirtualScreenFromGroup(std::vector<ScreenId> screens) = 0;
|
||||
virtual bool SetScreenActiveMode(ScreenId screenId, uint32_t modeId) = 0;
|
||||
};
|
||||
} // namespace OHOS::Rosen
|
||||
|
||||
@@ -32,13 +32,14 @@ public:
|
||||
~DisplayManagerProxy() {};
|
||||
|
||||
DisplayId GetDefaultDisplayId() override;
|
||||
DisplayInfo GetDisplayInfoById(DisplayId displayId) override;
|
||||
sptr<DisplayInfo> GetDisplayInfoById(DisplayId displayId) override;
|
||||
sptr<DisplayInfo> GetDisplayInfoByScreen(ScreenId screenId) override;
|
||||
|
||||
ScreenId CreateVirtualScreen(VirtualScreenOption option) override;
|
||||
DMError DestroyVirtualScreen(ScreenId screenId) override;
|
||||
DMError SetVirtualScreenSurface(ScreenId screenId, sptr<Surface> surface) override;
|
||||
bool RequestRotation(ScreenId screenId, Rotation rotation) override;
|
||||
std::shared_ptr<Media::PixelMap> GetDispalySnapshot(DisplayId displayId) override;
|
||||
bool SetOrientation(ScreenId screenId, Orientation orientation) override;
|
||||
std::shared_ptr<Media::PixelMap> GetDisplaySnapshot(DisplayId displayId) override;
|
||||
|
||||
// colorspace, gamut
|
||||
DMError GetScreenSupportedColorGamuts(ScreenId screenId, std::vector<ScreenColorGamut>& colorGamuts) override;
|
||||
@@ -58,13 +59,15 @@ public:
|
||||
bool SuspendEnd() override;
|
||||
bool SetScreenPowerForAll(DisplayPowerState state, PowerStateChangeReason reason) override;
|
||||
bool SetDisplayState(DisplayState state) override;
|
||||
std::vector<DisplayId> GetAllDisplayIds() override;
|
||||
DisplayState GetDisplayState(DisplayId displayId) override;
|
||||
void NotifyDisplayEvent(DisplayEvent event) override;
|
||||
DMError MakeMirror(ScreenId mainScreenId, std::vector<ScreenId> mirrorScreenId) override;
|
||||
ScreenId MakeMirror(ScreenId mainScreenId, std::vector<ScreenId> mirrorScreenId) override;
|
||||
sptr<ScreenInfo> GetScreenInfoById(ScreenId screenId) override;
|
||||
sptr<ScreenGroupInfo> GetScreenGroupInfoById(ScreenId screenId) override;
|
||||
std::vector<sptr<ScreenInfo>> GetAllScreenInfos() override;
|
||||
DMError MakeExpand(std::vector<ScreenId> screenId, std::vector<Point> startPoint) override;
|
||||
ScreenId MakeExpand(std::vector<ScreenId> screenId, std::vector<Point> startPoint) override;
|
||||
void RemoveVirtualScreenFromGroup(std::vector<ScreenId> screens) override;
|
||||
bool SetScreenActiveMode(ScreenId screenId, uint32_t modeId) override;
|
||||
|
||||
private:
|
||||
|
||||
@@ -51,9 +51,10 @@ public:
|
||||
DMError SetVirtualScreenSurface(ScreenId screenId, sptr<Surface> surface) override;
|
||||
|
||||
DisplayId GetDefaultDisplayId() override;
|
||||
DisplayInfo GetDisplayInfoById(DisplayId displayId) override;
|
||||
bool RequestRotation(ScreenId screenId, Rotation rotation) override;
|
||||
std::shared_ptr<Media::PixelMap> GetDispalySnapshot(DisplayId displayId) override;
|
||||
sptr<DisplayInfo> GetDisplayInfoById(DisplayId displayId) override;
|
||||
sptr<DisplayInfo> GetDisplayInfoByScreen(ScreenId screenId) override;
|
||||
bool SetOrientation(ScreenId screenId, Orientation orientation) override;
|
||||
std::shared_ptr<Media::PixelMap> GetDisplaySnapshot(DisplayId displayId) override;
|
||||
ScreenId GetRSScreenId(DisplayId displayId) const;
|
||||
|
||||
// colorspace, gamut
|
||||
@@ -82,11 +83,15 @@ public:
|
||||
sptr<AbstractDisplay> GetAbstractDisplay(DisplayId displayId);
|
||||
sptr<AbstractScreenController> GetAbstractScreenController();
|
||||
sptr<AbstractDisplay> GetDisplayByDisplayId(DisplayId displayId) const;
|
||||
DMError MakeMirror(ScreenId mainScreenId, std::vector<ScreenId> mirrorScreenId) override;
|
||||
sptr<AbstractDisplay> GetDisplayByScreen(ScreenId screenId) const;
|
||||
ScreenId MakeMirror(ScreenId mainScreenId, std::vector<ScreenId> mirrorScreenId) override;
|
||||
ScreenId MakeExpand(std::vector<ScreenId> screenId, std::vector<Point> startPoint) override;
|
||||
void RemoveVirtualScreenFromGroup(std::vector<ScreenId> screens) override;
|
||||
sptr<ScreenInfo> GetScreenInfoById(ScreenId screenId) override;
|
||||
sptr<ScreenGroupInfo> GetScreenGroupInfoById(ScreenId screenId) override;
|
||||
std::vector<sptr<ScreenInfo>> GetAllScreenInfos() override;
|
||||
DMError MakeExpand(std::vector<ScreenId> screenId, std::vector<Point> startPoint) override;
|
||||
|
||||
std::vector<DisplayId> GetAllDisplayIds() override;
|
||||
bool SetScreenActiveMode(ScreenId screenId, uint32_t modeId) override;
|
||||
|
||||
private:
|
||||
@@ -105,7 +110,7 @@ private:
|
||||
static inline SingletonDelegator<DisplayManagerService> delegator_;
|
||||
sptr<AbstractDisplayController> abstractDisplayController_;
|
||||
sptr<AbstractScreenController> abstractScreenController_;
|
||||
DisplayPowerController displayPowerController_;
|
||||
sptr<DisplayPowerController> displayPowerController_;
|
||||
std::map<ScreenId, std::shared_ptr<RSDisplayNode>> displayNodeMap_;
|
||||
sptr<IDisplayChangeListener> displayChangeListener_;
|
||||
};
|
||||
|
||||
@@ -36,6 +36,7 @@ public:
|
||||
std::vector<DisplayId> GetAllDisplayIds();
|
||||
ScreenId GetRSScreenId(DisplayId displayId) const;
|
||||
const sptr<ScreenInfo> GetScreenInfoByDisplayId(DisplayId displayId) const;
|
||||
const sptr<SupportedScreenModes> GetScreenModesByDisplayId(DisplayId displayId);
|
||||
void UpdateRSTree(DisplayId displayId, std::shared_ptr<RSSurfaceNode>& surfaceNode, bool isAdd);
|
||||
void RegisterDisplayChangeListener(sptr<IDisplayChangeListener> listener);
|
||||
};
|
||||
|
||||
@@ -18,14 +18,15 @@
|
||||
|
||||
#include <map>
|
||||
#include <mutex>
|
||||
#include <refbase.h>
|
||||
#include "display.h"
|
||||
#include "dm_common.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Rosen {
|
||||
class DisplayPowerController {
|
||||
class DisplayPowerController : public RefBase {
|
||||
public:
|
||||
DisplayPowerController() = default;
|
||||
DisplayPowerController(std::recursive_mutex& mutex) : mutex_(mutex) {}
|
||||
virtual ~DisplayPowerController() = default;
|
||||
|
||||
bool SuspendBegin(PowerStateChangeReason reason);
|
||||
@@ -36,6 +37,7 @@ public:
|
||||
private:
|
||||
DisplayState displayState_ { DisplayState::UNKNOWN };
|
||||
bool isKeyguardDrawn_ { false };
|
||||
std::recursive_mutex& mutex_;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,12 +24,16 @@ namespace {
|
||||
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "AbstractDisplay"};
|
||||
}
|
||||
|
||||
AbstractDisplay::AbstractDisplay(const DisplayInfo& info)
|
||||
: id_(info.id_),
|
||||
width_(info.width_),
|
||||
height_(info.height_),
|
||||
freshRate_(info.freshRate_)
|
||||
AbstractDisplay::AbstractDisplay(const DisplayInfo* info)
|
||||
{
|
||||
if (info == nullptr) {
|
||||
WLOGFE("DisplayInfo is nullptr");
|
||||
return;
|
||||
}
|
||||
id_ = info->GetDisplayId();
|
||||
width_ = info->GetWidth();
|
||||
height_ = info->GetHeight();
|
||||
freshRate_ = info->GetFreshRate();
|
||||
}
|
||||
|
||||
AbstractDisplay::AbstractDisplay(DisplayId id, ScreenId screenId, int32_t width, int32_t height, uint32_t freshRate)
|
||||
@@ -91,6 +95,11 @@ void AbstractDisplay::SetId(DisplayId id)
|
||||
id_ = id;
|
||||
}
|
||||
|
||||
void AbstractDisplay::SetOrientation(Orientation orientation)
|
||||
{
|
||||
orientation_ = orientation;
|
||||
}
|
||||
|
||||
bool AbstractDisplay::RequestRotation(Rotation rotation)
|
||||
{
|
||||
WLOGD("request rotation from %{public}u to %{public}u, display %{public}" PRIu64"", rotation_, rotation, id_);
|
||||
@@ -107,6 +116,11 @@ bool AbstractDisplay::RequestRotation(Rotation rotation)
|
||||
return true;
|
||||
}
|
||||
|
||||
Rotation AbstractDisplay::GetRotation()
|
||||
{
|
||||
return rotation_;
|
||||
}
|
||||
|
||||
bool AbstractDisplay::BindAbstractScreen(ScreenId dmsScreenId)
|
||||
{
|
||||
sptr<AbstractScreenController> screenController
|
||||
@@ -128,8 +142,8 @@ bool AbstractDisplay::BindAbstractScreen(sptr<AbstractScreen> abstractScreen)
|
||||
id_, dmsScreenId);
|
||||
return false;
|
||||
}
|
||||
width_ = info->width_;
|
||||
height_ = info->height_;
|
||||
width_ = static_cast<int32_t>(info->width_);
|
||||
height_ = static_cast<int32_t>(info->height_);
|
||||
freshRate_ = info->freshRate_;
|
||||
screenId_ = dmsScreenId;
|
||||
WLOGD("display bound to screen. display:%{public}" PRIu64", screen:%{public}" PRIu64"", id_, dmsScreenId);
|
||||
@@ -141,7 +155,7 @@ ScreenId AbstractDisplay::GetAbstractScreenId() const
|
||||
return screenId_;
|
||||
}
|
||||
|
||||
const sptr<DisplayInfo> AbstractDisplay::ConvertToDisplayInfo() const
|
||||
sptr<DisplayInfo> AbstractDisplay::ConvertToDisplayInfo() const
|
||||
{
|
||||
sptr<DisplayInfo> displayInfo = new DisplayInfo();
|
||||
displayInfo->width_ = width_;
|
||||
@@ -149,6 +163,8 @@ const sptr<DisplayInfo> AbstractDisplay::ConvertToDisplayInfo() const
|
||||
displayInfo->id_ = id_;
|
||||
displayInfo->freshRate_ = freshRate_;
|
||||
displayInfo->screenId_ = screenId_;
|
||||
displayInfo->rotation_ = rotation_;
|
||||
displayInfo->orientation_ = orientation_;
|
||||
return displayInfo;
|
||||
}
|
||||
} // namespace OHOS::Rosen
|
||||
@@ -86,6 +86,29 @@ sptr<AbstractDisplay> AbstractDisplayController::GetAbstractDisplay(DisplayId di
|
||||
return iter->second;
|
||||
}
|
||||
|
||||
sptr<AbstractDisplay> AbstractDisplayController::GetAbstractDisplayByScreen(ScreenId screenId) const
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
for (auto iter : abstractDisplayMap_) {
|
||||
sptr<AbstractDisplay> display = iter.second;
|
||||
if (display->GetAbstractScreenId() == screenId) {
|
||||
return display;
|
||||
}
|
||||
}
|
||||
WLOGFE("fail to get AbstractDisplay %{public}" PRIu64"", screenId);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::vector<DisplayId> AbstractDisplayController::GetAllDisplayIds() const
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
std::vector<DisplayId> res;
|
||||
for (auto iter = abstractDisplayMap_.begin(); iter != abstractDisplayMap_.end(); ++iter) {
|
||||
res.push_back(iter->first);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
std::shared_ptr<Media::PixelMap> AbstractDisplayController::GetScreenSnapshot(DisplayId displayId)
|
||||
{
|
||||
sptr<AbstractDisplay> abstractDisplay = GetAbstractDisplay(displayId);
|
||||
@@ -129,67 +152,82 @@ void AbstractDisplayController::OnAbstractScreenConnect(sptr<AbstractScreen> abs
|
||||
|
||||
void AbstractDisplayController::OnAbstractScreenDisconnect(sptr<AbstractScreen> absScreen)
|
||||
{
|
||||
WLOGI("disconnect screen. id:%{public}" PRIu64"", absScreen->dmsId_);
|
||||
if (absScreen == nullptr) {
|
||||
WLOGE("the information of the screen is wrong");
|
||||
return;
|
||||
}
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
sptr<AbstractScreenGroup> screenGroup = absScreen->GetGroup();
|
||||
if (screenGroup == nullptr) {
|
||||
WLOGE("the group information of the screen is wrong");
|
||||
WLOGI("disconnect screen. id:%{public}" PRIu64"", absScreen->dmsId_);
|
||||
sptr<AbstractScreenGroup> screenGroup;
|
||||
DisplayId absDisplayId = DISPLAY_ID_INVALD;
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
screenGroup = absScreen->GetGroup();
|
||||
if (screenGroup == nullptr) {
|
||||
WLOGE("the group information of the screen is wrong");
|
||||
return;
|
||||
}
|
||||
if (screenGroup->combination_ == ScreenCombination::SCREEN_ALONE
|
||||
|| screenGroup->combination_ == ScreenCombination::SCREEN_MIRROR) {
|
||||
absDisplayId = ProcessNormalScreenDisconnected(absScreen, screenGroup);
|
||||
} else if (screenGroup->combination_ == ScreenCombination::SCREEN_EXPAND) {
|
||||
absDisplayId = ProcessExpandScreenDisconnected(absScreen, screenGroup);
|
||||
} else {
|
||||
WLOGE("support in future. combination:%{public}u", screenGroup->combination_);
|
||||
}
|
||||
}
|
||||
if (absDisplayId == DISPLAY_ID_INVALD) {
|
||||
WLOGE("the displayId of the disconnected expand screen was not found");
|
||||
return;
|
||||
}
|
||||
if (screenGroup->combination_ == ScreenCombination::SCREEN_ALONE
|
||||
|| screenGroup->combination_ == ScreenCombination::SCREEN_MIRROR) {
|
||||
ProcessNormalScreenDisconnected(absScreen, screenGroup);
|
||||
if (screenGroup->GetChildCount() == 0) {
|
||||
abstractDisplayMap_.erase(absDisplayId);
|
||||
DisplayManagerAgentController::GetInstance().OnDisplayDestroy(absDisplayId);
|
||||
}
|
||||
} else if (screenGroup->combination_ == ScreenCombination::SCREEN_EXPAND) {
|
||||
ProcessExpandScreenDisconnected(absScreen, screenGroup);
|
||||
DisplayManagerService::GetInstance().NotifyDisplayStateChange(
|
||||
absDisplayId, DisplayStateChangeType::DESTROY);
|
||||
DisplayManagerAgentController::GetInstance().OnDisplayDestroy(absDisplayId);
|
||||
abstractDisplayMap_.erase(absDisplayId);
|
||||
} else {
|
||||
WLOGE("support in future. combination:%{public}u", screenGroup->combination_);
|
||||
}
|
||||
}
|
||||
|
||||
void AbstractDisplayController::ProcessNormalScreenDisconnected(
|
||||
DisplayId AbstractDisplayController::ProcessNormalScreenDisconnected(
|
||||
sptr<AbstractScreen> absScreen, sptr<AbstractScreenGroup> screenGroup)
|
||||
{
|
||||
WLOGI("normal screen disconnect");
|
||||
ScreenId defaultScreenId = abstractScreenController_->GetDefaultAbstractScreenId();
|
||||
sptr<AbstractScreen> defaultScreen = abstractScreenController_->GetAbstractScreen(defaultScreenId);
|
||||
for (auto iter = abstractDisplayMap_.begin(); iter != abstractDisplayMap_.end(); iter++) {
|
||||
DisplayId displayId = iter->first;
|
||||
sptr<AbstractDisplay> abstractDisplay = iter->second;
|
||||
if (abstractDisplay->GetAbstractScreenId() != absScreen->dmsId_) {
|
||||
continue;
|
||||
}
|
||||
abstractDisplay->BindAbstractScreen(defaultScreen);
|
||||
if (screenGroup->GetChildCount() == 0) {
|
||||
abstractDisplayMap_.erase(iter);
|
||||
DisplayManagerAgentController::GetInstance().OnDisplayDestroy(abstractDisplay->GetId());
|
||||
if (abstractDisplay->GetAbstractScreenId() == absScreen->dmsId_) {
|
||||
WLOGI("normal screen disconnect, displayId: %{public}" PRIu64", screenId: %{public}" PRIu64"",
|
||||
displayId, abstractDisplay->GetAbstractScreenId());
|
||||
abstractDisplay->BindAbstractScreen(defaultScreen);
|
||||
return displayId;
|
||||
}
|
||||
}
|
||||
return DISPLAY_ID_INVALD;
|
||||
}
|
||||
|
||||
void AbstractDisplayController::ProcessExpandScreenDisconnected(
|
||||
DisplayId AbstractDisplayController::ProcessExpandScreenDisconnected(
|
||||
sptr<AbstractScreen> absScreen, sptr<AbstractScreenGroup> screenGroup)
|
||||
{
|
||||
WLOGI("expand screen disconnect");
|
||||
ScreenId defaultScreenId = abstractScreenController_->GetDefaultAbstractScreenId();
|
||||
sptr<AbstractScreen> defaultScreen = abstractScreenController_->GetAbstractScreen(defaultScreenId);
|
||||
for (auto iter = abstractDisplayMap_.begin(); iter != abstractDisplayMap_.end(); iter++) {
|
||||
DisplayId displayId = iter->first;
|
||||
sptr<AbstractDisplay> abstractDisplay = iter->second;
|
||||
if (abstractDisplay->GetAbstractScreenId() != absScreen->dmsId_) {
|
||||
continue;
|
||||
if (abstractDisplay->GetAbstractScreenId() == absScreen->dmsId_) {
|
||||
WLOGI("expand screen disconnect, displayId: %{public}" PRIu64", screenId: %{public}" PRIu64"",
|
||||
displayId, abstractDisplay->GetAbstractScreenId());
|
||||
return displayId;
|
||||
}
|
||||
WLOGI("notify wms and dm which expand screen disconnect, displayId: %{public}" PRIu64""
|
||||
", screenId: %{public}" PRIu64"", displayId, abstractDisplay->GetAbstractScreenId());
|
||||
// Notify disconnect event to WMS
|
||||
DisplayManagerService::GetInstance().NotifyDisplayStateChange(displayId, DisplayStateChangeType::DESTROY);
|
||||
// Notify disconnect event to DisplayManager
|
||||
DisplayManagerAgentController::GetInstance().OnDisplayDestroy(abstractDisplay->GetId());
|
||||
abstractDisplayMap_.erase(iter);
|
||||
break;
|
||||
}
|
||||
return DISPLAY_ID_INVALD;
|
||||
}
|
||||
|
||||
void AbstractDisplayController::OnAbstractScreenChange(sptr<AbstractScreen> absScreen, DisplayChangeEvent event)
|
||||
@@ -199,57 +237,60 @@ void AbstractDisplayController::OnAbstractScreenChange(sptr<AbstractScreen> absS
|
||||
return;
|
||||
}
|
||||
WLOGI("screen changes. id:%{public}" PRIu64"", absScreen->dmsId_);
|
||||
|
||||
if (event == DisplayChangeEvent::UPDATE_ROTATION) {
|
||||
ProcessDisplayUpdateRotation(absScreen);
|
||||
}
|
||||
if (event == DisplayChangeEvent::DISPLAY_SIZE_CHANGED) {
|
||||
if (event == DisplayChangeEvent::UPDATE_ORIENTATION) {
|
||||
ProcessDisplayUpdateOrientation(absScreen);
|
||||
} else if (event == DisplayChangeEvent::DISPLAY_SIZE_CHANGED) {
|
||||
ProcessDisplaySizeChange(absScreen);
|
||||
} else {
|
||||
WLOGE("unknow screen change event. id:%{public}" PRIu64" event %{public}u", absScreen->dmsId_, event);
|
||||
}
|
||||
}
|
||||
|
||||
void AbstractDisplayController::ProcessDisplayUpdateRotation(sptr<AbstractScreen> absScreen)
|
||||
void AbstractDisplayController::ProcessDisplayUpdateOrientation(sptr<AbstractScreen> absScreen)
|
||||
{
|
||||
sptr<AbstractDisplay> abstractDisplay = nullptr;
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
auto iter = abstractDisplayMap_.begin();
|
||||
for (; iter != abstractDisplayMap_.end(); iter++) {
|
||||
abstractDisplay = iter->second;
|
||||
if (abstractDisplay->GetAbstractScreenId() == absScreen->dmsId_) {
|
||||
WLOGFD("find abstract display of the screen. display %{public}" PRIu64", screen %{public}" PRIu64"",
|
||||
abstractDisplay->GetId(), absScreen->dmsId_);
|
||||
break;
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
auto iter = abstractDisplayMap_.begin();
|
||||
for (; iter != abstractDisplayMap_.end(); iter++) {
|
||||
abstractDisplay = iter->second;
|
||||
if (abstractDisplay->GetAbstractScreenId() == absScreen->dmsId_) {
|
||||
WLOGFD("find abstract display of the screen. display %{public}" PRIu64", screen %{public}" PRIu64"",
|
||||
abstractDisplay->GetId(), absScreen->dmsId_);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sptr<AbstractScreenGroup> group = absScreen->GetGroup();
|
||||
if (group == nullptr) {
|
||||
WLOGFE("cannot get screen group");
|
||||
return;
|
||||
}
|
||||
if (iter == abstractDisplayMap_.end()) {
|
||||
if (group->combination_ == ScreenCombination::SCREEN_ALONE
|
||||
|| group->combination_ == ScreenCombination::SCREEN_EXPAND) {
|
||||
WLOGFE("cannot find abstract display of the screen %{public}" PRIu64"", absScreen->dmsId_);
|
||||
return;
|
||||
} else if (group->combination_ == ScreenCombination::SCREEN_MIRROR) {
|
||||
// If the 'absScreen' cannot be found in 'abstractDisplayMap_', it means that the screen is the secondary.
|
||||
WLOGFI("It's the secondary screen of the mirrored.");
|
||||
return;
|
||||
} else {
|
||||
WLOGFE("Unknow combination");
|
||||
sptr<AbstractScreenGroup> group = absScreen->GetGroup();
|
||||
if (group == nullptr) {
|
||||
WLOGFE("cannot get screen group");
|
||||
return;
|
||||
}
|
||||
if (iter == abstractDisplayMap_.end()) {
|
||||
if (group->combination_ == ScreenCombination::SCREEN_ALONE
|
||||
|| group->combination_ == ScreenCombination::SCREEN_EXPAND) {
|
||||
WLOGFE("cannot find abstract display of the screen %{public}" PRIu64"", absScreen->dmsId_);
|
||||
return;
|
||||
} else if (group->combination_ == ScreenCombination::SCREEN_MIRROR) {
|
||||
// If the screen cannot be found in 'abstractDisplayMap_', it means that the screen is the secondary
|
||||
WLOGFI("It's the secondary screen of the mirrored.");
|
||||
return;
|
||||
} else {
|
||||
WLOGFE("Unknow combination");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
abstractDisplay->SetOrientation(absScreen->orientation_);
|
||||
if (abstractDisplay->RequestRotation(absScreen->rotation_)) {
|
||||
// Notify rotation event to WMS
|
||||
DisplayManagerService::GetInstance().NotifyDisplayStateChange(abstractDisplay->GetId(),
|
||||
DisplayStateChangeType::UPDATE_ROTATION);
|
||||
// Notify rotation event to DisplayManager
|
||||
sptr<DisplayInfo> displayInfo = abstractDisplay->ConvertToDisplayInfo();
|
||||
DisplayManagerAgentController::GetInstance().OnDisplayChange(displayInfo,
|
||||
DisplayChangeEvent::UPDATE_ROTATION);
|
||||
}
|
||||
// Notify orientation event to DisplayManager
|
||||
sptr<DisplayInfo> displayInfo = abstractDisplay->ConvertToDisplayInfo();
|
||||
DisplayManagerAgentController::GetInstance().OnDisplayChange(displayInfo,
|
||||
DisplayChangeEvent::UPDATE_ORIENTATION);
|
||||
}
|
||||
|
||||
void AbstractDisplayController::ProcessDisplaySizeChange(sptr<AbstractScreen> absScreen)
|
||||
@@ -279,7 +320,8 @@ void AbstractDisplayController::ProcessDisplaySizeChange(sptr<AbstractScreen> ab
|
||||
|
||||
bool AbstractDisplayController::UpdateDisplaySize(sptr<AbstractDisplay> absDisplay, sptr<SupportedScreenModes> info)
|
||||
{
|
||||
if (info->height_ == absDisplay->GetHeight() && info->width_ == absDisplay->GetWidth()) {
|
||||
if (info->height_ == static_cast<uint32_t>(absDisplay->GetHeight()) &&
|
||||
info->width_ == static_cast<uint32_t>(absDisplay->GetWidth())) {
|
||||
WLOGI("keep display size. display:%{public}" PRIu64"", absDisplay->GetId());
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -25,8 +25,9 @@ namespace {
|
||||
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "AbstractScreenGroup"};
|
||||
}
|
||||
|
||||
AbstractScreen::AbstractScreen(ScreenId dmsId, ScreenId rsId)
|
||||
: dmsId_(dmsId), rsId_(rsId), screenController_(DisplayManagerService::GetInstance().abstractScreenController_)
|
||||
AbstractScreen::AbstractScreen(const std::string& name, ScreenId dmsId, ScreenId rsId)
|
||||
: name_(name), dmsId_(dmsId), rsId_(rsId),
|
||||
screenController_(DisplayManagerService::GetInstance().abstractScreenController_)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -53,7 +54,7 @@ sptr<AbstractScreenGroup> AbstractScreen::GetGroup() const
|
||||
return DisplayManagerService::GetInstance().GetAbstractScreenController()->GetAbstractScreenGroup(groupDmsId_);
|
||||
}
|
||||
|
||||
const sptr<ScreenInfo> AbstractScreen::ConvertToScreenInfo() const
|
||||
sptr<ScreenInfo> AbstractScreen::ConvertToScreenInfo() const
|
||||
{
|
||||
sptr<ScreenInfo> info = new ScreenInfo();
|
||||
FillScreenInfo(info);
|
||||
@@ -68,18 +69,11 @@ void AbstractScreen::UpdateRSTree(std::shared_ptr<RSSurfaceNode>& surfaceNode, b
|
||||
}
|
||||
WLOGFI("AbstractScreen::UpdateRSTree");
|
||||
|
||||
// default duration 350ms
|
||||
static const RSAnimationTimingProtocol timingProtocol(350);
|
||||
// default curve EASE OUT
|
||||
static const Rosen::RSAnimationTimingCurve curve = Rosen::RSAnimationTimingCurve::EASE_OUT;
|
||||
// add or remove window with transition animation
|
||||
RSNode::Animate(timingProtocol, curve, [=]() {
|
||||
if (isAdd) {
|
||||
rsDisplayNode_->AddChild(surfaceNode, -1);
|
||||
} else {
|
||||
rsDisplayNode_->RemoveChild(surfaceNode);
|
||||
}
|
||||
});
|
||||
if (isAdd) {
|
||||
rsDisplayNode_->AddChild(surfaceNode, -1);
|
||||
} else {
|
||||
rsDisplayNode_->RemoveChild(surfaceNode);
|
||||
}
|
||||
}
|
||||
|
||||
void AbstractScreen::InitRSDisplayNode(RSDisplayNodeConfig& config)
|
||||
@@ -91,6 +85,10 @@ void AbstractScreen::InitRSDisplayNode(RSDisplayNodeConfig& config)
|
||||
}
|
||||
rsDisplayNode_ = rsDisplayNode;
|
||||
rSDisplayNodeConfig_ = config;
|
||||
auto transactionProxy = RSTransactionProxy::GetInstance();
|
||||
if (transactionProxy != nullptr) {
|
||||
transactionProxy->FlushImplicitTransaction();
|
||||
}
|
||||
}
|
||||
|
||||
DMError AbstractScreen::GetScreenSupportedColorGamuts(std::vector<ScreenColorGamut>& colorGamuts)
|
||||
@@ -195,22 +193,52 @@ void AbstractScreen::FillScreenInfo(sptr<ScreenInfo> info) const
|
||||
info->parent_ = groupDmsId_;
|
||||
info->canHasChild_ = canHasChild_;
|
||||
info->rotation_ = rotation_;
|
||||
info->orientation_ = orientation_;
|
||||
info->type_ = type_;
|
||||
info->modeId_ = activeIdx_;
|
||||
info->modes_ = modes_;
|
||||
}
|
||||
|
||||
Rotation AbstractScreen::GetRotation() const
|
||||
bool AbstractScreen::SetOrientation(Orientation orientation)
|
||||
{
|
||||
return rotation_;
|
||||
orientation_ = orientation;
|
||||
return true;
|
||||
}
|
||||
|
||||
void AbstractScreen::RequestRotation(Rotation rotation)
|
||||
Rotation AbstractScreen::CalcRotation(Orientation orientation) const
|
||||
{
|
||||
rotation_ = rotation;
|
||||
if (activeIdx_ < 0 || activeIdx_ >= modes_.size()) {
|
||||
WLOGE("active mode index is wrong: %{public}d", activeIdx_);
|
||||
return Rotation::ROTATION_0;
|
||||
}
|
||||
sptr<SupportedScreenModes> info = modes_[activeIdx_];
|
||||
// virtical: phone(Plugin screen); horizontal: pad & external screen
|
||||
bool isVerticalScreen = info->width_ < info->height_;
|
||||
switch (orientation) {
|
||||
case Orientation::UNSPECIFIED: {
|
||||
return Rotation::ROTATION_0;
|
||||
}
|
||||
case Orientation::VERTICAL: {
|
||||
return isVerticalScreen ? Rotation::ROTATION_0 : Rotation::ROTATION_90;
|
||||
}
|
||||
case Orientation::HORIZONTAL: {
|
||||
return isVerticalScreen ? Rotation::ROTATION_90 : Rotation::ROTATION_0;
|
||||
}
|
||||
case Orientation::REVERSE_VERTICAL: {
|
||||
return isVerticalScreen ? Rotation::ROTATION_180 : Rotation::ROTATION_270;
|
||||
}
|
||||
case Orientation::REVERSE_HORIZONTAL: {
|
||||
return isVerticalScreen ? Rotation::ROTATION_270 : Rotation::ROTATION_180;
|
||||
}
|
||||
default: {
|
||||
WLOGE("unknown orientation %{public}u", orientation);
|
||||
return Rotation::ROTATION_0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
AbstractScreenGroup::AbstractScreenGroup(ScreenId dmsId, ScreenId rsId, ScreenCombination combination)
|
||||
: AbstractScreen(dmsId, rsId), combination_(combination)
|
||||
: AbstractScreen("", dmsId, rsId), combination_(combination)
|
||||
{
|
||||
type_ = ScreenType::UNDEFINE;
|
||||
canHasChild_ = true;
|
||||
@@ -222,7 +250,7 @@ AbstractScreenGroup::~AbstractScreenGroup()
|
||||
abstractScreenMap_.clear();
|
||||
}
|
||||
|
||||
const sptr<ScreenGroupInfo> AbstractScreenGroup::ConvertToScreenGroupInfo() const
|
||||
sptr<ScreenGroupInfo> AbstractScreenGroup::ConvertToScreenGroupInfo() const
|
||||
{
|
||||
sptr<ScreenGroupInfo> screenGroupInfo = new ScreenGroupInfo();
|
||||
FillScreenInfo(screenGroupInfo);
|
||||
@@ -303,7 +331,7 @@ bool AbstractScreenGroup::AddChildren(std::vector<sptr<AbstractScreen>>& dmsScre
|
||||
}
|
||||
bool res = true;
|
||||
for (size_t i = 0; i < size; i++) {
|
||||
res &= AddChild(dmsScreens[i], startPoints[i]);
|
||||
res = AddChild(dmsScreens[i], startPoints[i]) && res;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
@@ -347,4 +375,4 @@ size_t AbstractScreenGroup::GetChildCount() const
|
||||
{
|
||||
return abstractScreenMap_.size();
|
||||
}
|
||||
} // namespace OHOS::Rosen
|
||||
} // namespace OHOS::Rosen
|
||||
|
||||
@@ -107,7 +107,7 @@ std::shared_ptr<RSDisplayNode> AbstractScreenController::GetRSDisplayNodeByScree
|
||||
if (screen == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
WLOGI("GetAbstractScreen: screen: %{public}" PRIu64", nodeId: %{public}" PRIu64" ",
|
||||
WLOGI("GetRSDisplayNodeByScreenId: screen: %{public}" PRIu64", nodeId: %{public}" PRIu64" ",
|
||||
screen->dmsId_, screen->rsDisplayNode_->GetId());
|
||||
return screen->rsDisplayNode_;
|
||||
}
|
||||
@@ -159,11 +159,12 @@ ScreenId AbstractScreenController::GetDefaultAbstractScreenId()
|
||||
auto iter = rs2DmsScreenIdMap_.find(rsDefaultId);
|
||||
if (iter != rs2DmsScreenIdMap_.end()) {
|
||||
WLOGI("GetDefaultAbstractScreenId, screen:%{public}" PRIu64"", iter->second);
|
||||
defaultScreenId = iter->second;
|
||||
return iter->second;
|
||||
}
|
||||
WLOGFI("GetDefaultAbstractScreenId, default screen is null, try to get.");
|
||||
ScreenId dmsScreenId = dmsScreenCount_;
|
||||
sptr<AbstractScreen> absScreen = new AbstractScreen(dmsScreenId, rsDefaultId);
|
||||
sptr<AbstractScreen> absScreen = new AbstractScreen(DEFAULT_SCREEN_NAME, dmsScreenId, rsDefaultId);
|
||||
if (!FillAbstractScreen(absScreen, rsDefaultId)) {
|
||||
WLOGFW("GetDefaultAbstractScreenId, FillAbstractScreen failed.");
|
||||
return INVALID_SCREEN_ID;
|
||||
@@ -172,9 +173,15 @@ ScreenId AbstractScreenController::GetDefaultAbstractScreenId()
|
||||
dms2RsScreenIdMap_.insert(std::make_pair(dmsScreenId, rsDefaultId));
|
||||
dmsScreenMap_.insert(std::make_pair(dmsScreenId, absScreen));
|
||||
dmsScreenCount_++;
|
||||
defaultScreenId = dmsScreenId;
|
||||
return dmsScreenId;
|
||||
}
|
||||
|
||||
ScreenId AbstractScreenController::GetDefaultScreenId() const
|
||||
{
|
||||
return defaultScreenId;
|
||||
}
|
||||
|
||||
ScreenId AbstractScreenController::ConvertToRsScreenId(ScreenId dmsScreenId)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
@@ -211,7 +218,7 @@ void AbstractScreenController::OnRsScreenConnectionChange(ScreenId rsScreenId, S
|
||||
if (iter == rs2DmsScreenIdMap_.end()) {
|
||||
WLOGFD("connect new screen");
|
||||
dmsScreenId = dmsScreenCount_;
|
||||
sptr<AbstractScreen> absScreen = new AbstractScreen(dmsScreenId, rsScreenId);
|
||||
sptr<AbstractScreen> absScreen = new AbstractScreen(DEFAULT_SCREEN_NAME, dmsScreenId, rsScreenId);
|
||||
if (!FillAbstractScreen(absScreen, rsScreenId)) {
|
||||
return;
|
||||
}
|
||||
@@ -248,32 +255,6 @@ void AbstractScreenController::ScreenConnectionInDisplayInit(sptr<AbstractScreen
|
||||
}
|
||||
}
|
||||
|
||||
void AbstractScreenController::ProcessScreenModeChanged(ScreenId rsScreenId)
|
||||
{
|
||||
WM_SCOPED_TRACE("dms:ProcessScreenModeChanged(%" PRIu64")", rsScreenId);
|
||||
auto iter = rs2DmsScreenIdMap_.find(rsScreenId);
|
||||
if (iter == rs2DmsScreenIdMap_.end()) {
|
||||
WLOGE("ProcessScreenModeChanged: screenId=%{public}" PRIu64" is not in rs2DmsScreenIdMap_", rsScreenId);
|
||||
return;
|
||||
}
|
||||
WLOGFD("ProcessScreenModeChanged: process screen info changes");
|
||||
ScreenId dmsScreenId = iter->second;
|
||||
auto dmsScreenMapIter = dmsScreenMap_.find(dmsScreenId);
|
||||
if (dmsScreenMapIter == dmsScreenMap_.end()) {
|
||||
WLOGE("ProcessScreenModeChanged: no dms screen is found, rsscreenId=%{public}" PRIu64"", rsScreenId);
|
||||
return;
|
||||
}
|
||||
// should be called by OnRsScreenConnectionChange
|
||||
// if not, the recursive_mutex should be added
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
sptr<AbstractScreen> absScreen = dmsScreenMapIter->second;
|
||||
if (abstractScreenCallback_ != nullptr) {
|
||||
abstractScreenCallback_->onChange_(absScreen, DisplayChangeEvent::DISPLAY_SIZE_CHANGED);
|
||||
}
|
||||
DisplayManagerAgentController::GetInstance().OnScreenChange(
|
||||
absScreen->ConvertToScreenInfo(), ScreenChangeEvent::CHANGE_MODE);
|
||||
}
|
||||
|
||||
void AbstractScreenController::ProcessScreenDisconnected(ScreenId rsScreenId)
|
||||
{
|
||||
WLOGI("disconnect screen, screenId=%{public}" PRIu64"", rsScreenId);
|
||||
@@ -312,8 +293,8 @@ bool AbstractScreenController::FillAbstractScreen(sptr<AbstractScreen>& absScree
|
||||
}
|
||||
for (RSScreenModeInfo rsScreenModeInfo : allModes) {
|
||||
sptr<SupportedScreenModes> info = new SupportedScreenModes();
|
||||
info->width_ = rsScreenModeInfo.GetScreenWidth();
|
||||
info->height_ = rsScreenModeInfo.GetScreenHeight();
|
||||
info->width_ = static_cast<uint32_t>(rsScreenModeInfo.GetScreenWidth());
|
||||
info->height_ = static_cast<uint32_t>(rsScreenModeInfo.GetScreenHeight());
|
||||
info->freshRate_ = rsScreenModeInfo.GetScreenFreshRate();
|
||||
absScreen->modes_.push_back(info);
|
||||
WLOGD("fill screen w/h:%{public}d/%{public}d", info->width_, info->height_);
|
||||
@@ -339,8 +320,8 @@ sptr<AbstractScreenGroup> AbstractScreenController::AddToGroupLocked(sptr<Abstra
|
||||
res = AddAsSuccedentScreenLocked(newScreen);
|
||||
}
|
||||
if (res != nullptr) {
|
||||
DisplayManagerAgentController::GetInstance().OnScreenChange(
|
||||
newScreen->ConvertToScreenInfo(), ScreenChangeEvent::ADD_TO_GROUP);
|
||||
DisplayManagerAgentController::GetInstance().OnScreenGroupChange(
|
||||
newScreen->ConvertToScreenInfo(), ScreenGroupChangeEvent::ADD_TO_GROUP);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
@@ -355,11 +336,21 @@ sptr<AbstractScreenGroup> AbstractScreenController::RemoveFromGroupLocked(sptr<A
|
||||
return nullptr;
|
||||
}
|
||||
sptr<AbstractScreenGroup> screenGroup = iter->second;
|
||||
if (!RemoveChildFromGroup(screen, screenGroup)) {
|
||||
return nullptr;
|
||||
}
|
||||
DisplayManagerAgentController::GetInstance().OnScreenGroupChange(
|
||||
screen->ConvertToScreenInfo(), ScreenGroupChangeEvent::REMOVE_FROM_GROUP);
|
||||
return screenGroup;
|
||||
}
|
||||
|
||||
bool AbstractScreenController::RemoveChildFromGroup(sptr<AbstractScreen> screen, sptr<AbstractScreenGroup> screenGroup)
|
||||
{
|
||||
bool res = screenGroup->RemoveChild(screen);
|
||||
if (!res) {
|
||||
WLOGE("RemoveFromGroupLocked. remove screen:%{public}" PRIu64" failed from screenGroup:%{public}" PRIu64".",
|
||||
screen->dmsId_, groupDmsId);
|
||||
return nullptr;
|
||||
screen->dmsId_, screen->groupDmsId_);
|
||||
return false;
|
||||
}
|
||||
if (screen->dmsId_ == screenGroup->mirrorScreenId_) {
|
||||
// Todo: if mirror screen removed and it is SCREEN_MIRROR type, then should make mirror in this group.
|
||||
@@ -370,9 +361,7 @@ sptr<AbstractScreenGroup> AbstractScreenController::RemoveFromGroupLocked(sptr<A
|
||||
dmsScreenGroupMap_.erase(screenGroup->dmsId_);
|
||||
dmsScreenMap_.erase(screenGroup->dmsId_);
|
||||
}
|
||||
DisplayManagerAgentController::GetInstance().OnScreenChange(
|
||||
screen->ConvertToScreenInfo(), ScreenChangeEvent::REMOVE_FROM_GROUP);
|
||||
return screenGroup;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool AbstractScreenController::CheckScreenInScreenGroup(sptr<AbstractScreen> screen) const
|
||||
@@ -436,31 +425,40 @@ sptr<AbstractScreenGroup> AbstractScreenController::AddAsSuccedentScreenLocked(s
|
||||
|
||||
ScreenId AbstractScreenController::CreateVirtualScreen(VirtualScreenOption option)
|
||||
{
|
||||
ScreenId result = rsInterface_.CreateVirtualScreen(option.name_, option.width_,
|
||||
ScreenId rsId = rsInterface_.CreateVirtualScreen(option.name_, option.width_,
|
||||
option.height_, option.surface_, INVALID_SCREEN_ID, option.flags_);
|
||||
WLOGFI("AbstractScreenController::CreateVirtualScreen id: %{public}" PRIu64"", result);
|
||||
if (result == SCREEN_ID_INVALID) {
|
||||
WLOGFI("CreateVirtualScreen id: %{public}" PRIu64"", rsId);
|
||||
if (rsId == SCREEN_ID_INVALID) {
|
||||
return SCREEN_ID_INVALID;
|
||||
}
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
ScreenId dmsScreenId = SCREEN_ID_INVALID;
|
||||
auto iter = rs2DmsScreenIdMap_.find(result);
|
||||
auto iter = rs2DmsScreenIdMap_.find(rsId);
|
||||
if (iter == rs2DmsScreenIdMap_.end()) {
|
||||
if (!option.isForShot_) {
|
||||
WLOGI("CreateVirtualScreen is not shot");
|
||||
dmsScreenId = dmsScreenCount_;
|
||||
sptr<AbstractScreen> absScreen = new AbstractScreen(dmsScreenId, result);
|
||||
sptr<AbstractScreen> absScreen = new AbstractScreen(option.name_, dmsScreenId, rsId);
|
||||
sptr<SupportedScreenModes> info = new SupportedScreenModes();
|
||||
info->width_ = option.width_;
|
||||
info->height_ = option.height_;
|
||||
auto defaultScreen = GetAbstractScreen(GetDefaultAbstractScreenId());
|
||||
if (defaultScreen != nullptr && defaultScreen->GetActiveScreenMode() != nullptr) {
|
||||
info->freshRate_ = defaultScreen->GetActiveScreenMode()->freshRate_;
|
||||
}
|
||||
absScreen->modes_.push_back(info);
|
||||
absScreen->activeIdx_ = 0;
|
||||
absScreen->type_ = ScreenType::VIRTUAL;
|
||||
dmsScreenCount_++;
|
||||
rs2DmsScreenIdMap_.insert(std::make_pair(result, dmsScreenId));
|
||||
dms2RsScreenIdMap_.insert(std::make_pair(dmsScreenId, result));
|
||||
rs2DmsScreenIdMap_.insert(std::make_pair(rsId, dmsScreenId));
|
||||
dms2RsScreenIdMap_.insert(std::make_pair(dmsScreenId, rsId));
|
||||
dmsScreenMap_.insert(std::make_pair(dmsScreenId, absScreen));
|
||||
DisplayManagerAgentController::GetInstance().OnScreenConnect(absScreen->ConvertToScreenInfo());
|
||||
} else {
|
||||
WLOGI("CreateVirtualScreen is shot");
|
||||
dmsScreenId = dmsScreenCount_++;
|
||||
rs2DmsScreenIdMap_.insert(std::make_pair(result, dmsScreenId));
|
||||
dms2RsScreenIdMap_.insert(std::make_pair(dmsScreenId, result));
|
||||
rs2DmsScreenIdMap_.insert(std::make_pair(rsId, dmsScreenId));
|
||||
dms2RsScreenIdMap_.insert(std::make_pair(dmsScreenId, rsId));
|
||||
}
|
||||
} else {
|
||||
return iter->second;
|
||||
@@ -470,8 +468,6 @@ ScreenId AbstractScreenController::CreateVirtualScreen(VirtualScreenOption optio
|
||||
|
||||
DMError AbstractScreenController::DestroyVirtualScreen(ScreenId screenId)
|
||||
{
|
||||
WLOGFI("DumpScreenInfo before Destroy VirtualScreen");
|
||||
DumpScreenInfo();
|
||||
WLOGFI("AbstractScreenController::DestroyVirtualScreen");
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
ScreenId rsScreenId = SCREEN_ID_INVALID;
|
||||
@@ -495,7 +491,11 @@ DMError AbstractScreenController::DestroyVirtualScreen(ScreenId screenId)
|
||||
DMError AbstractScreenController::SetVirtualScreenSurface(ScreenId screenId, sptr<Surface> surface)
|
||||
{
|
||||
WLOGFI("AbstractScreenController::SetVirtualScreenSurface");
|
||||
int32_t res = rsInterface_.SetVirtualScreenSurface(screenId, surface);
|
||||
int32_t res = -1;
|
||||
auto iter = dms2RsScreenIdMap_.find(screenId);
|
||||
if (iter != dms2RsScreenIdMap_.end()) {
|
||||
res = rsInterface_.SetVirtualScreenSurface(iter->second, surface);
|
||||
}
|
||||
if (res != 0) {
|
||||
WLOGE("SetVirtualScreenSurface failed in RenderService");
|
||||
return DMError::DM_ERROR_RENDER_SERVICE_FAILED;
|
||||
@@ -503,43 +503,47 @@ DMError AbstractScreenController::SetVirtualScreenSurface(ScreenId screenId, spt
|
||||
return DMError::DM_OK;
|
||||
}
|
||||
|
||||
bool AbstractScreenController::RequestRotation(ScreenId screenId, Rotation rotation)
|
||||
bool AbstractScreenController::SetOrientation(ScreenId screenId, Orientation newOrientation)
|
||||
{
|
||||
WLOGD("request rotation: screen %{public}" PRIu64"", screenId);
|
||||
WLOGD("set orientation. screen %{public}" PRIu64" orientation %{public}u", screenId, newOrientation);
|
||||
auto screen = GetAbstractScreen(screenId);
|
||||
if (screen == nullptr) {
|
||||
WLOGFE("fail to request rotation, cannot find screen %{public}" PRIu64"", screenId);
|
||||
WLOGFE("fail to set orientation, cannot find screen %{public}" PRIu64"", screenId);
|
||||
return false;
|
||||
}
|
||||
if (screen->canHasChild_) {
|
||||
WLOGE("cannot rotate the combination screen: %{public}" PRIu64"", screenId);
|
||||
WLOGE("cannot set orientation to the combination. screen: %{public}" PRIu64"", screenId);
|
||||
return false;
|
||||
}
|
||||
if (!rsInterface_.RequestRotation(screenId, static_cast<ScreenRotation>(rotation))) {
|
||||
WLOGE("rotate screen fail: %{public}" PRIu64"", screenId);
|
||||
return false;
|
||||
if (screen->orientation_ == newOrientation) {
|
||||
WLOGI("skip setting orientation. screen %{public}" PRIu64" orientation %{public}u", screenId, newOrientation);
|
||||
return true;
|
||||
}
|
||||
Rotation before = screen->rotation_;
|
||||
screen->RequestRotation(rotation);
|
||||
OnScreenRotate(screenId, before, rotation);
|
||||
return true;
|
||||
}
|
||||
|
||||
void AbstractScreenController::OnScreenRotate(ScreenId dmsId, Rotation before, Rotation after)
|
||||
{
|
||||
auto iter = dmsScreenMap_.find(dmsId);
|
||||
if (iter == dmsScreenMap_.end()) {
|
||||
WLOGE("rotate screen fail, not found abstract screen %{public}" PRIu64"", dmsId);
|
||||
return;
|
||||
Rotation rotationAfter = screen->CalcRotation(newOrientation);
|
||||
if (rotationAfter != screen->rotation_) {
|
||||
WLOGI("set orientation. roatiton %{public}u", rotationAfter);
|
||||
if (!rsInterface_.RequestRotation(screenId, static_cast<ScreenRotation>(rotationAfter))) {
|
||||
WLOGE("rotate screen fail. %{public}" PRIu64"", screenId);
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
WLOGI("rotation not changed. screen %{public}" PRIu64" rotation %{public}u", screenId, rotationAfter);
|
||||
}
|
||||
sptr<AbstractScreen> abstractScreen = iter->second;
|
||||
if (!screen->SetOrientation(newOrientation)) {
|
||||
WLOGE("fail to set orientation, screen %{public}" PRIu64"", screenId);
|
||||
return false;
|
||||
}
|
||||
screen->rotation_ = rotationAfter;
|
||||
|
||||
// Notify rotation event to ScreenManager
|
||||
DisplayManagerAgentController::GetInstance().OnScreenChange(
|
||||
abstractScreen->ConvertToScreenInfo(), ScreenChangeEvent::UPDATE_ROTATION);
|
||||
screen->ConvertToScreenInfo(), ScreenChangeEvent::UPDATE_ORIENTATION);
|
||||
// Notify rotation event to AbstractDisplayController
|
||||
if (abstractScreenCallback_ != nullptr) {
|
||||
abstractScreenCallback_->onChange_(abstractScreen, DisplayChangeEvent::UPDATE_ROTATION);
|
||||
abstractScreenCallback_->onChange_(screen, DisplayChangeEvent::UPDATE_ORIENTATION);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
DMError AbstractScreenController::GetScreenSupportedColorGamuts(ScreenId screenId,
|
||||
@@ -605,18 +609,29 @@ bool AbstractScreenController::IsScreenGroup(ScreenId screenId) const
|
||||
|
||||
bool AbstractScreenController::SetScreenActiveMode(ScreenId screenId, uint32_t modeId)
|
||||
{
|
||||
WLOGI("SetScreenActiveMode: screenId: %{public}" PRIu64", modeId: %{public}u", screenId, modeId);
|
||||
rsInterface_.SetScreenActiveMode(screenId, modeId);
|
||||
auto screen = GetAbstractScreen(screenId);
|
||||
if (screen == nullptr) {
|
||||
WLOGFE("SetScreenActiveMode: Get AbstractScreen failed");
|
||||
WLOGI("SetScreenActiveMode: RsScreenId: %{public}" PRIu64", modeId: %{public}u", screenId, modeId);
|
||||
if (screenId == SCREEN_ID_INVALID) {
|
||||
WLOGFE("SetScreenActiveMode: invalid screenId");
|
||||
return false;
|
||||
}
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
uint32_t usedModeId = screen->activeIdx_;
|
||||
screen->activeIdx_ = modeId;
|
||||
uint32_t usedModeId = 0;
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
auto iter = dms2RsScreenIdMap_.find(screenId);
|
||||
if (iter == dms2RsScreenIdMap_.end()) {
|
||||
WLOGFE("SetScreenActiveMode: No corresponding rsId");
|
||||
return false;
|
||||
}
|
||||
rsInterface_.SetScreenActiveMode(iter->second, modeId);
|
||||
auto screen = GetAbstractScreen(screenId);
|
||||
if (screen == nullptr) {
|
||||
WLOGFE("SetScreenActiveMode: Get AbstractScreen failed");
|
||||
return false;
|
||||
}
|
||||
usedModeId = static_cast<uint32_t>(screen->activeIdx_);
|
||||
screen->activeIdx_ = static_cast<int32_t>(modeId);
|
||||
}
|
||||
// add thread to process mode change sync event
|
||||
// should be called by OnRsScreenChange if rs implement corresponding event callback
|
||||
if (usedModeId != modeId) {
|
||||
WLOGI("SetScreenActiveMode: modeId: %{public}u -> %{public}u", usedModeId, modeId);
|
||||
auto func = [=]() {
|
||||
@@ -629,9 +644,36 @@ bool AbstractScreenController::SetScreenActiveMode(ScreenId screenId, uint32_t m
|
||||
return true;
|
||||
}
|
||||
|
||||
void AbstractScreenController::ProcessScreenModeChanged(ScreenId dmsScreenId)
|
||||
{
|
||||
WM_SCOPED_TRACE("dms:ProcessScreenModeChanged(%" PRIu64")", dmsScreenId);
|
||||
sptr<AbstractScreen> absScreen = nullptr;
|
||||
sptr<AbstractScreenCallback> absScreenCallback = nullptr;
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
auto dmsScreenMapIter = dmsScreenMap_.find(dmsScreenId);
|
||||
if (dmsScreenMapIter == dmsScreenMap_.end()) {
|
||||
WLOGFE("dmsScreenId=%{public}" PRIu64" is not in dmsScreenMap", dmsScreenId);
|
||||
return;
|
||||
}
|
||||
absScreen = GetAbstractScreen(dmsScreenId);
|
||||
if (absScreen == nullptr) {
|
||||
WLOGFE("screen is nullptr. dmsScreenId=%{public}" PRIu64"", dmsScreenId);
|
||||
return;
|
||||
}
|
||||
absScreenCallback = abstractScreenCallback_;
|
||||
}
|
||||
|
||||
if (absScreenCallback != nullptr) {
|
||||
absScreenCallback->onChange_(absScreen, DisplayChangeEvent::DISPLAY_SIZE_CHANGED);
|
||||
}
|
||||
DisplayManagerAgentController::GetInstance().OnScreenChange(
|
||||
absScreen->ConvertToScreenInfo(), ScreenChangeEvent::CHANGE_MODE);
|
||||
}
|
||||
|
||||
bool AbstractScreenController::MakeMirror(ScreenId screenId, std::vector<ScreenId> screens)
|
||||
{
|
||||
WLOGI("AbstractScreenController::MakeMirror, screenId:%{public}" PRIu64"", screenId);
|
||||
WLOGI("MakeMirror, screenId:%{public}" PRIu64"", screenId);
|
||||
sptr<AbstractScreen> screen = GetAbstractScreen(screenId);
|
||||
if (screen == nullptr || screen->type_ != ScreenType::REAL) {
|
||||
WLOGFE("screen is nullptr, or screenType is not real.");
|
||||
@@ -654,27 +696,87 @@ bool AbstractScreenController::MakeMirror(ScreenId screenId, std::vector<ScreenI
|
||||
}
|
||||
}
|
||||
WLOGFI("GetAbstractScreenGroup end");
|
||||
group->combination_ = ScreenCombination::SCREEN_MIRROR;
|
||||
group->mirrorScreenId_ = screen->dmsId_;
|
||||
Point point;
|
||||
for (ScreenId mirrorScreenId : screens) {
|
||||
WLOGI("GetAbstractScreen: mirrorScreenId: %{public}" PRIu64"", mirrorScreenId);
|
||||
auto mirrorScreen = GetAbstractScreen(mirrorScreenId);
|
||||
if (mirrorScreen == nullptr) {
|
||||
WLOGFE("mirrorScreen:%{public}" PRIu64" is nullptr", mirrorScreenId);
|
||||
continue;
|
||||
}
|
||||
WLOGI("GetAbstractScreen: mirrorScreen->groupDmsId_: %{public}" PRIu64"", mirrorScreen->groupDmsId_);
|
||||
auto originGroup = GetAbstractScreenGroup(mirrorScreen->groupDmsId_);
|
||||
if (originGroup != nullptr) {
|
||||
originGroup->RemoveChild(mirrorScreen);
|
||||
}
|
||||
group->AddChild(mirrorScreen, point);
|
||||
}
|
||||
std::vector<Point> startPoints;
|
||||
startPoints.insert(startPoints.begin(), screens.size(), point);
|
||||
bool filterMirroredScreen =
|
||||
group->combination_ == ScreenCombination::SCREEN_MIRROR && group->mirrorScreenId_ == screen->dmsId_;
|
||||
ChangeScreenGroup(group, screens, startPoints, filterMirroredScreen, ScreenCombination::SCREEN_MIRROR);
|
||||
WLOGFI("MakeMirror success");
|
||||
return true;
|
||||
}
|
||||
|
||||
void AbstractScreenController::ChangeScreenGroup(sptr<AbstractScreenGroup> group, const std::vector<ScreenId>& screens,
|
||||
const std::vector<Point>& startPoints, bool filterScreen, ScreenCombination combination)
|
||||
{
|
||||
std::map<ScreenId, bool> removeChildResMap;
|
||||
std::vector<ScreenId> addScreens;
|
||||
std::vector<Point> addChildPos;
|
||||
for (uint64_t i = 0; i != screens.size(); i++) {
|
||||
ScreenId screenId = screens[i];
|
||||
WLOGFI("ChangeScreenGroup: screenId: %{public}" PRIu64"", screenId);
|
||||
auto screen = GetAbstractScreen(screenId);
|
||||
if (screen == nullptr) {
|
||||
WLOGFE("screen:%{public}" PRIu64" is nullptr", screenId);
|
||||
continue;
|
||||
}
|
||||
WLOGFI("ChangeScreenGroup: screen->groupDmsId_: %{public}" PRIu64"", screen->groupDmsId_);
|
||||
if (filterScreen && screen->groupDmsId_ == group->dmsId_ && group->HasChild(screen->dmsId_)) {
|
||||
continue;
|
||||
}
|
||||
auto originGroup = GetAbstractScreenGroup(screen->groupDmsId_);
|
||||
bool removeChildRes = false;
|
||||
if (originGroup != nullptr) {
|
||||
removeChildRes = RemoveChildFromGroup(screen, originGroup);
|
||||
abstractScreenCallback_->onDisconnect_(screen);
|
||||
}
|
||||
addChildPos.emplace_back(startPoints[i]);
|
||||
removeChildResMap[screenId] = removeChildRes;
|
||||
addScreens.emplace_back(screenId);
|
||||
}
|
||||
group->combination_ = combination;
|
||||
AddScreenToGroup(group, addScreens, addChildPos, removeChildResMap);
|
||||
}
|
||||
|
||||
void AbstractScreenController::AddScreenToGroup(sptr<AbstractScreenGroup> group,
|
||||
const std::vector<ScreenId>& addScreens, const std::vector<Point>& addChildPos,
|
||||
std::map<ScreenId, bool>& removeChildResMap)
|
||||
{
|
||||
std::vector<sptr<ScreenInfo>> addToGroup;
|
||||
std::vector<sptr<ScreenInfo>> removeFromGroup;
|
||||
std::vector<sptr<ScreenInfo>> changeGroup;
|
||||
for (uint64_t i = 0; i != addScreens.size(); i++) {
|
||||
ScreenId screenId = addScreens[i];
|
||||
sptr<AbstractScreen> screen = GetAbstractScreen(screenId);
|
||||
if (screen == nullptr) {
|
||||
continue;
|
||||
}
|
||||
Point expandPoint = addChildPos[i];
|
||||
WLOGFI("screenId: %{public}" PRIu64", Point: %{public}d, %{public}d",
|
||||
screen->dmsId_, expandPoint.posX_, expandPoint.posY_);
|
||||
bool addChildRes = group->AddChild(screen, expandPoint);
|
||||
if (removeChildResMap[screenId] && addChildRes) {
|
||||
changeGroup.emplace_back(screen->ConvertToScreenInfo());
|
||||
WLOGFI("changeGroup");
|
||||
} else if (removeChildResMap[screenId]) {
|
||||
WLOGFI("removeChild");
|
||||
removeFromGroup.emplace_back(screen->ConvertToScreenInfo());
|
||||
} else if (addChildRes) {
|
||||
WLOGFI("AddChild");
|
||||
addToGroup.emplace_back(screen->ConvertToScreenInfo());
|
||||
} else {
|
||||
WLOGFI("default, AddChild failed");
|
||||
}
|
||||
abstractScreenCallback_->onConnect_(screen);
|
||||
}
|
||||
DisplayManagerAgentController::GetInstance().
|
||||
OnScreenGroupChange(removeFromGroup, ScreenGroupChangeEvent::REMOVE_FROM_GROUP);
|
||||
DisplayManagerAgentController::GetInstance().
|
||||
OnScreenGroupChange(changeGroup, ScreenGroupChangeEvent::CHANGE_GROUP);
|
||||
DisplayManagerAgentController::GetInstance().
|
||||
OnScreenGroupChange(addToGroup, ScreenGroupChangeEvent::ADD_TO_GROUP);
|
||||
}
|
||||
|
||||
bool AbstractScreenController::MakeExpand(std::vector<ScreenId> screenIds, std::vector<Point> startPoints)
|
||||
{
|
||||
ScreenId defaultScreenId = GetDefaultAbstractScreenId();
|
||||
@@ -687,26 +789,36 @@ bool AbstractScreenController::MakeExpand(std::vector<ScreenId> screenIds, std::
|
||||
if (group == nullptr) {
|
||||
return false;
|
||||
}
|
||||
group->combination_ = ScreenCombination::SCREEN_EXPAND;
|
||||
for (uint64_t i = 0; i != screenIds.size(); i++) {
|
||||
ScreenId expandScreenId = screenIds[i];
|
||||
Point expandPoint = startPoints[i];
|
||||
WLOGFI("expandScreenId: %{public}" PRIu64", Point: %{public}d, %{public}d",
|
||||
expandScreenId, expandPoint.posX_, expandPoint.posY_);
|
||||
auto expandScreen = GetAbstractScreen(expandScreenId);
|
||||
if (expandScreen == nullptr) {
|
||||
WLOGFE("expandScreen:%{public}" PRIu64" is nullptr", expandScreenId);
|
||||
bool filterExpandScreen = group->combination_ == ScreenCombination::SCREEN_EXPAND;
|
||||
ChangeScreenGroup(group, screenIds, startPoints, filterExpandScreen, ScreenCombination::SCREEN_EXPAND);
|
||||
WLOGFI("MakeExpand success");
|
||||
return true;
|
||||
}
|
||||
|
||||
void AbstractScreenController::RemoveVirtualScreenFromGroup(std::vector<ScreenId> screens)
|
||||
{
|
||||
if (screens.empty()) {
|
||||
return;
|
||||
}
|
||||
std::vector<sptr<ScreenInfo>> removeFromGroup;
|
||||
for (ScreenId screenId : screens) {
|
||||
auto screen = GetAbstractScreen(screenId);
|
||||
if (screen->type_ != ScreenType::VIRTUAL) {
|
||||
continue;
|
||||
}
|
||||
WLOGI("expandScreen->groupDmsId_: %{public}" PRIu64"", expandScreen->groupDmsId_);
|
||||
auto originGroup = GetAbstractScreenGroup(expandScreen->groupDmsId_);
|
||||
if (originGroup != nullptr) {
|
||||
originGroup->RemoveChild(expandScreen);
|
||||
auto originGroup = GetAbstractScreenGroup(screen->groupDmsId_);
|
||||
if (originGroup == nullptr) {
|
||||
continue;
|
||||
}
|
||||
group->AddChild(expandScreen, expandPoint);
|
||||
if (!originGroup->HasChild(screenId)) {
|
||||
continue;
|
||||
}
|
||||
removeFromGroup.emplace_back(screen->ConvertToScreenInfo());
|
||||
RemoveChildFromGroup(screen, originGroup);
|
||||
abstractScreenCallback_->onDisconnect_(screen);
|
||||
}
|
||||
WLOGI("MakeExpand success");
|
||||
return true;
|
||||
DisplayManagerAgentController::GetInstance().
|
||||
OnScreenGroupChange(removeFromGroup, ScreenGroupChangeEvent::REMOVE_FROM_GROUP);
|
||||
}
|
||||
|
||||
void AbstractScreenController::DumpScreenInfo() const
|
||||
@@ -752,12 +864,13 @@ void AbstractScreenController::DumpScreenGroupInfo() const
|
||||
std::string screenType = "UNDEFINE";
|
||||
NodeId nodeId = (screenGroup->rsDisplayNode_ == nullptr) ? 0 : screenGroup->rsDisplayNode_->GetId();
|
||||
WLOGI("%{public}10s %{public}20" PRIu64" %{public}20" PRIu64" %{public}20" PRIu64" %{public}10s %{public}20"
|
||||
PRIu64" %{public}10s %{public}20" PRIu64" ", isGroup.c_str(), screenGroup->dmsId_,screenGroup->rsId_,
|
||||
PRIu64" %{public}10s %{public}20" PRIu64" ", isGroup.c_str(), screenGroup->dmsId_, screenGroup->rsId_,
|
||||
screenGroup->groupDmsId_, screenType.c_str(), nodeId,
|
||||
isMirrored.c_str(), screenGroup->rSDisplayNodeConfig_.mirrorNodeId);
|
||||
auto childrenScreen = screenGroup->GetChildren();
|
||||
for (auto screen : childrenScreen) {
|
||||
std::string isGroup = (dmsScreenGroupMap_.find(screen->dmsId_) != dmsScreenGroupMap_.end()) ? "true" : "false";
|
||||
std::string isGroup =
|
||||
(dmsScreenGroupMap_.find(screen->dmsId_) != dmsScreenGroupMap_.end()) ? "true" : "false";
|
||||
if (screen->type_ == ScreenType::UNDEFINE) {
|
||||
screenType = "UNDEFINE";
|
||||
} else if (screen->type_ == ScreenType::REAL) {
|
||||
@@ -768,7 +881,7 @@ void AbstractScreenController::DumpScreenGroupInfo() const
|
||||
isMirrored = screen->rSDisplayNodeConfig_.isMirrored ? "true" : "false";
|
||||
nodeId = (screen->rsDisplayNode_ == nullptr) ? 0 : screen->rsDisplayNode_->GetId();
|
||||
WLOGI("%{public}10s %{public}20" PRIu64" %{public}20" PRIu64" %{public}20" PRIu64" %{public}10s %{public}20"
|
||||
PRIu64" %{public}10s %{public}20" PRIu64" ", isGroup.c_str(), screen->dmsId_,screen->rsId_,
|
||||
PRIu64" %{public}10s %{public}20" PRIu64" ", isGroup.c_str(), screen->dmsId_, screen->rsId_,
|
||||
screen->groupDmsId_, screenType.c_str(), nodeId,
|
||||
isMirrored.c_str(), screen->rSDisplayNodeConfig_.mirrorNodeId);
|
||||
}
|
||||
|
||||
@@ -88,26 +88,43 @@ void DisplayManagerAgentController::OnScreenDisconnect(ScreenId screenId)
|
||||
}
|
||||
}
|
||||
|
||||
void DisplayManagerAgentController::OnScreenChange(sptr<ScreenInfo> screenInfo, ScreenChangeEvent screenChangeEvent)
|
||||
void DisplayManagerAgentController::OnScreenChange(const sptr<ScreenInfo> screenInfo,
|
||||
ScreenChangeEvent screenChangeEvent)
|
||||
{
|
||||
if (screenInfo == nullptr) {
|
||||
return;
|
||||
}
|
||||
std::vector<const sptr<ScreenInfo>> screenInfos;
|
||||
screenInfos.push_back(screenInfo);
|
||||
OnScreenChange(screenInfos, screenChangeEvent);
|
||||
auto agents = dmAgentContainer_.GetAgentsByType(DisplayManagerAgentType::SCREEN_EVENT_LISTENER);
|
||||
if (agents.empty()) {
|
||||
return;
|
||||
}
|
||||
WLOGFI("OnScreenChange");
|
||||
for (auto& agent : agents) {
|
||||
agent->OnScreenChange(screenInfo, screenChangeEvent);
|
||||
}
|
||||
}
|
||||
|
||||
void DisplayManagerAgentController::OnScreenChange(
|
||||
const std::vector<const sptr<ScreenInfo>>& screenInfos, ScreenChangeEvent screenChangeEvent)
|
||||
void DisplayManagerAgentController::OnScreenGroupChange(const sptr<ScreenInfo>& screenInfo,
|
||||
ScreenGroupChangeEvent groupEvent)
|
||||
{
|
||||
if (screenInfo == nullptr) {
|
||||
return;
|
||||
}
|
||||
std::vector<sptr<ScreenInfo>> screenInfos;
|
||||
screenInfos.push_back(screenInfo);
|
||||
OnScreenGroupChange(screenInfos, groupEvent);
|
||||
}
|
||||
|
||||
void DisplayManagerAgentController::OnScreenGroupChange(
|
||||
const std::vector<sptr<ScreenInfo>>& screenInfos, ScreenGroupChangeEvent groupEvent)
|
||||
{
|
||||
auto agents = dmAgentContainer_.GetAgentsByType(DisplayManagerAgentType::SCREEN_EVENT_LISTENER);
|
||||
if (agents.empty() || screenInfos.empty()) {
|
||||
return;
|
||||
}
|
||||
WLOGFI("OnScreenChange");
|
||||
WLOGFI("OnScreenGroupChange");
|
||||
for (auto& agent : agents) {
|
||||
agent->OnScreenChange(screenInfos, screenChangeEvent);
|
||||
agent->OnScreenGroupChange(screenInfos, groupEvent);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -52,12 +52,12 @@ DisplayId DisplayManagerProxy::GetDefaultDisplayId()
|
||||
return displayId;
|
||||
}
|
||||
|
||||
DisplayInfo DisplayManagerProxy::GetDisplayInfoById(DisplayId displayId)
|
||||
sptr<DisplayInfo> DisplayManagerProxy::GetDisplayInfoById(DisplayId displayId)
|
||||
{
|
||||
sptr<IRemoteObject> remote = Remote();
|
||||
if (remote == nullptr) {
|
||||
WLOGFW("GetDisplayInfoById: remote is nullptr");
|
||||
return DisplayInfo();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
MessageParcel data;
|
||||
@@ -65,30 +65,62 @@ DisplayInfo DisplayManagerProxy::GetDisplayInfoById(DisplayId displayId)
|
||||
MessageOption option;
|
||||
if (!data.WriteInterfaceToken(GetDescriptor())) {
|
||||
WLOGFE("GetDisplayInfoById: WriteInterfaceToken failed");
|
||||
return DisplayInfo();
|
||||
return nullptr;
|
||||
}
|
||||
if (!data.WriteUint64(displayId)) {
|
||||
WLOGFW("GetDisplayInfoById: WriteUint64 displayId failed");
|
||||
return DisplayInfo();
|
||||
return nullptr;
|
||||
}
|
||||
if (remote->SendRequest(TRANS_ID_GET_DISPLAY_BY_ID, data, reply, option) != ERR_NONE) {
|
||||
WLOGFW("GetDisplayInfoById: SendRequest failed");
|
||||
return DisplayInfo();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
sptr<DisplayInfo> info = reply.ReadParcelable<DisplayInfo>();
|
||||
if (info == nullptr) {
|
||||
WLOGFW("DisplayManagerProxy::GetDisplayInfoById SendRequest nullptr.");
|
||||
return DisplayInfo();
|
||||
return nullptr;
|
||||
}
|
||||
return *info;
|
||||
return info;
|
||||
}
|
||||
|
||||
sptr<DisplayInfo> DisplayManagerProxy::GetDisplayInfoByScreen(ScreenId screenId)
|
||||
{
|
||||
sptr<IRemoteObject> remote = Remote();
|
||||
if (remote == nullptr) {
|
||||
WLOGFE("fail to get displayInfo by screenId: remote is null");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
if (!data.WriteInterfaceToken(GetDescriptor())) {
|
||||
WLOGFE("fail to get displayInfo by screenId: WriteInterfaceToken failed");
|
||||
return nullptr;
|
||||
}
|
||||
if (!data.WriteUint64(screenId)) {
|
||||
WLOGFW("fail to get displayInfo by screenId: WriteUint64 displayId failed");
|
||||
return nullptr;
|
||||
}
|
||||
if (remote->SendRequest(TRANS_ID_GET_DISPLAY_BY_SCREEN, data, reply, option) != ERR_NONE) {
|
||||
WLOGFW("fail to get displayInfo by screenId: SendRequest failed");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
sptr<DisplayInfo> info = reply.ReadParcelable<DisplayInfo>();
|
||||
if (info == nullptr) {
|
||||
WLOGFW("fail to get displayInfo by screenId: SendRequest null");
|
||||
return nullptr;
|
||||
}
|
||||
return info;
|
||||
}
|
||||
|
||||
ScreenId DisplayManagerProxy::CreateVirtualScreen(VirtualScreenOption virtualOption)
|
||||
{
|
||||
sptr<IRemoteObject> remote = Remote();
|
||||
if (remote == nullptr) {
|
||||
WLOGFW("DisplayManagerProxy::CreateVirtualScreen: remote is nullptr");
|
||||
WLOGFW("CreateVirtualScreen: remote is nullptr");
|
||||
return SCREEN_ID_INVALID;
|
||||
}
|
||||
|
||||
@@ -96,24 +128,31 @@ ScreenId DisplayManagerProxy::CreateVirtualScreen(VirtualScreenOption virtualOpt
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
if (!data.WriteInterfaceToken(GetDescriptor())) {
|
||||
WLOGFE("DisplayManagerProxy::CreateVirtualScreen: WriteInterfaceToken failed");
|
||||
WLOGFE("CreateVirtualScreen: WriteInterfaceToken failed");
|
||||
return SCREEN_ID_INVALID;
|
||||
}
|
||||
bool res = data.WriteString(virtualOption.name_) && data.WriteUint32(virtualOption.width_) &&
|
||||
data.WriteUint32(virtualOption.height_) && data.WriteFloat(virtualOption.density_) &&
|
||||
data.WriteRemoteObject(virtualOption.surface_->GetProducer()->AsObject()) &&
|
||||
data.WriteInt32(virtualOption.flags_) && data.WriteBool(virtualOption.isForShot_);
|
||||
if (virtualOption.surface_ != nullptr && virtualOption.surface_->GetProducer() != nullptr) {
|
||||
res = res &&
|
||||
data.WriteBool(true) &&
|
||||
data.WriteRemoteObject(virtualOption.surface_->GetProducer()->AsObject());
|
||||
} else {
|
||||
WLOGFW("CreateVirtualScreen: surface is nullptr");
|
||||
res = res && data.WriteBool(false);
|
||||
}
|
||||
if (!res) {
|
||||
WLOGFE("DisplayManagerProxy::Write data failed");
|
||||
WLOGFE("Write data failed");
|
||||
return SCREEN_ID_INVALID;
|
||||
}
|
||||
if (remote->SendRequest(TRANS_ID_CREATE_VIRTUAL_SCREEN, data, reply, option) != ERR_NONE) {
|
||||
WLOGFW("DisplayManagerProxy::CreateVirtualScreen: SendRequest failed");
|
||||
WLOGFW("CreateVirtualScreen: SendRequest failed");
|
||||
return SCREEN_ID_INVALID;
|
||||
}
|
||||
|
||||
ScreenId screenId = static_cast<ScreenId>(reply.ReadUint64());
|
||||
WLOGFI("DisplayManagerProxy::CreateVirtualScreen %" PRIu64"", screenId);
|
||||
WLOGFI("CreateVirtualScreen %" PRIu64"", screenId);
|
||||
return screenId;
|
||||
}
|
||||
|
||||
@@ -121,7 +160,7 @@ DMError DisplayManagerProxy::DestroyVirtualScreen(ScreenId screenId)
|
||||
{
|
||||
sptr<IRemoteObject> remote = Remote();
|
||||
if (remote == nullptr) {
|
||||
WLOGFW("DisplayManagerProxy::DestroyVirtualScreen: remote is nullptr");
|
||||
WLOGFW("DestroyVirtualScreen: remote is nullptr");
|
||||
return DMError::DM_ERROR_REMOTE_CREATE_FAILED;
|
||||
}
|
||||
|
||||
@@ -129,15 +168,15 @@ DMError DisplayManagerProxy::DestroyVirtualScreen(ScreenId screenId)
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
if (!data.WriteInterfaceToken(GetDescriptor())) {
|
||||
WLOGFE("DisplayManagerProxy::DestroyVirtualScreen: WriteInterfaceToken failed");
|
||||
WLOGFE("DestroyVirtualScreen: WriteInterfaceToken failed");
|
||||
return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED;
|
||||
}
|
||||
if (!data.WriteUint64(static_cast<uint64_t>(screenId))) {
|
||||
WLOGFW("DisplayManagerProxy::DestroyVirtualScreen: WriteUint64 screenId failed");
|
||||
WLOGFW("DestroyVirtualScreen: WriteUint64 screenId failed");
|
||||
return DMError::DM_ERROR_IPC_FAILED;
|
||||
}
|
||||
if (remote->SendRequest(TRANS_ID_DESTROY_VIRTUAL_SCREEN, data, reply, option) != ERR_NONE) {
|
||||
WLOGFW("DisplayManagerProxy::DestroyVirtualScreen: SendRequest failed");
|
||||
WLOGFW("DestroyVirtualScreen: SendRequest failed");
|
||||
return DMError::DM_ERROR_IPC_FAILED;
|
||||
}
|
||||
return static_cast<DMError>(reply.ReadInt32());
|
||||
@@ -158,8 +197,16 @@ DMError DisplayManagerProxy::SetVirtualScreenSurface(ScreenId screenId, sptr<Sur
|
||||
WLOGFE("SetVirtualScreenSurface: WriteInterfaceToken failed");
|
||||
return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED;
|
||||
}
|
||||
if (!data.WriteUint64(static_cast<uint64_t>(screenId)) ||
|
||||
!data.WriteRemoteObject(surface->GetProducer()->AsObject())) {
|
||||
bool res = data.WriteUint64(static_cast<uint64_t>(screenId));
|
||||
if (surface != nullptr && surface->GetProducer() != nullptr) {
|
||||
res = res &&
|
||||
data.WriteBool(true) &&
|
||||
data.WriteRemoteObject(surface->GetProducer()->AsObject());
|
||||
} else {
|
||||
WLOGFW("SetVirtualScreenSurface: surface is nullptr");
|
||||
res = res && data.WriteBool(false);
|
||||
}
|
||||
if (!res) {
|
||||
WLOGFW("SetVirtualScreenSurface: Write screenId/surface failed");
|
||||
return DMError::DM_ERROR_IPC_FAILED;
|
||||
}
|
||||
@@ -170,11 +217,11 @@ DMError DisplayManagerProxy::SetVirtualScreenSurface(ScreenId screenId, sptr<Sur
|
||||
return static_cast<DMError>(reply.ReadInt32());
|
||||
}
|
||||
|
||||
bool DisplayManagerProxy::RequestRotation(ScreenId screenId, Rotation rotation)
|
||||
bool DisplayManagerProxy::SetOrientation(ScreenId screenId, Orientation orientation)
|
||||
{
|
||||
sptr<IRemoteObject> remote = Remote();
|
||||
if (remote == nullptr) {
|
||||
WLOGFW("fail to request rotation: remote is null");
|
||||
WLOGFW("fail to set orientation: remote is null");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -182,29 +229,29 @@ bool DisplayManagerProxy::RequestRotation(ScreenId screenId, Rotation rotation)
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
if (!data.WriteInterfaceToken(GetDescriptor())) {
|
||||
WLOGFE("fail to request rotation: WriteInterfaceToken failed");
|
||||
WLOGFE("fail to set orientation: WriteInterfaceToken failed");
|
||||
return false;
|
||||
}
|
||||
if (!data.WriteUint64(static_cast<uint64_t>(screenId))) {
|
||||
WLOGFW("fail to request rotation: Write screenId failed");
|
||||
WLOGFW("fail to set orientation: Write screenId failed");
|
||||
return false;
|
||||
}
|
||||
if (!data.WriteUint32(static_cast<uint32_t>(rotation))) {
|
||||
WLOGFW("fail to request rotation: Write rotation failed");
|
||||
if (!data.WriteUint32(static_cast<uint32_t>(orientation))) {
|
||||
WLOGFW("fail to set orientation: Write orientation failed");
|
||||
return false;
|
||||
}
|
||||
if (remote->SendRequest(TRANS_ID_REQUEST_ROTATION, data, reply, option) != ERR_NONE) {
|
||||
WLOGFW("fail to request rotation: SendRequest failed");
|
||||
if (remote->SendRequest(TRANS_ID_SET_ORIENTATION, data, reply, option) != ERR_NONE) {
|
||||
WLOGFW("fail to set orientation: SendRequest failed");
|
||||
return false;
|
||||
}
|
||||
return reply.ReadBool();
|
||||
}
|
||||
|
||||
std::shared_ptr<Media::PixelMap> DisplayManagerProxy::GetDispalySnapshot(DisplayId displayId)
|
||||
std::shared_ptr<Media::PixelMap> DisplayManagerProxy::GetDisplaySnapshot(DisplayId displayId)
|
||||
{
|
||||
sptr<IRemoteObject> remote = Remote();
|
||||
if (remote == nullptr) {
|
||||
WLOGFW("GetDispalySnapshot: remote is nullptr");
|
||||
WLOGFW("GetDisplaySnapshot: remote is nullptr");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -212,7 +259,7 @@ std::shared_ptr<Media::PixelMap> DisplayManagerProxy::GetDispalySnapshot(Display
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
if (!data.WriteInterfaceToken(GetDescriptor())) {
|
||||
WLOGFE("GetDispalySnapshot: WriteInterfaceToken failed");
|
||||
WLOGFE("GetDisplaySnapshot: WriteInterfaceToken failed");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -222,13 +269,13 @@ std::shared_ptr<Media::PixelMap> DisplayManagerProxy::GetDispalySnapshot(Display
|
||||
}
|
||||
|
||||
if (remote->SendRequest(TRANS_ID_GET_DISPLAY_SNAPSHOT, data, reply, option) != ERR_NONE) {
|
||||
WLOGFW("GetDispalySnapshot: SendRequest failed");
|
||||
WLOGFW("GetDisplaySnapshot: SendRequest failed");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::shared_ptr<Media::PixelMap> pixelMap(reply.ReadParcelable<Media::PixelMap>());
|
||||
if (pixelMap == nullptr) {
|
||||
WLOGFW("DisplayManagerProxy::GetDispalySnapshot SendRequest nullptr.");
|
||||
WLOGFW("DisplayManagerProxy::GetDisplaySnapshot SendRequest nullptr.");
|
||||
return nullptr;
|
||||
}
|
||||
return pixelMap;
|
||||
@@ -606,6 +653,24 @@ DisplayState DisplayManagerProxy::GetDisplayState(DisplayId displayId)
|
||||
return static_cast<DisplayState>(reply.ReadUint32());
|
||||
}
|
||||
|
||||
std::vector<DisplayId> DisplayManagerProxy::GetAllDisplayIds()
|
||||
{
|
||||
std::vector<DisplayId> allDisplayIds;
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
if (!data.WriteInterfaceToken(GetDescriptor())) {
|
||||
WLOGFE("WriteInterfaceToken failed");
|
||||
return allDisplayIds;
|
||||
}
|
||||
if (Remote()->SendRequest(TRANS_ID_GET_ALL_DISPLAYIDS, data, reply, option) != ERR_NONE) {
|
||||
WLOGFW("SendRequest failed");
|
||||
return allDisplayIds;
|
||||
}
|
||||
reply.ReadUInt64Vector(&allDisplayIds);
|
||||
return allDisplayIds;
|
||||
}
|
||||
|
||||
void DisplayManagerProxy::NotifyDisplayEvent(DisplayEvent event)
|
||||
{
|
||||
MessageParcel data;
|
||||
@@ -625,12 +690,12 @@ void DisplayManagerProxy::NotifyDisplayEvent(DisplayEvent event)
|
||||
}
|
||||
}
|
||||
|
||||
DMError DisplayManagerProxy::MakeMirror(ScreenId mainScreenId, std::vector<ScreenId> mirrorScreenId)
|
||||
ScreenId DisplayManagerProxy::MakeMirror(ScreenId mainScreenId, std::vector<ScreenId> mirrorScreenId)
|
||||
{
|
||||
sptr<IRemoteObject> remote = Remote();
|
||||
if (remote == nullptr) {
|
||||
WLOGFW("create mirror fail: remote is null");
|
||||
return DMError::DM_ERROR_REMOTE_CREATE_FAILED;
|
||||
return SCREEN_ID_INVALID;
|
||||
}
|
||||
|
||||
MessageParcel data;
|
||||
@@ -638,19 +703,19 @@ DMError DisplayManagerProxy::MakeMirror(ScreenId mainScreenId, std::vector<Scree
|
||||
MessageOption option;
|
||||
if (!data.WriteInterfaceToken(GetDescriptor())) {
|
||||
WLOGFE("create mirror fail: WriteInterfaceToken failed");
|
||||
return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED;
|
||||
return SCREEN_ID_INVALID;
|
||||
}
|
||||
bool res = data.WriteUint64(static_cast<uint64_t>(mainScreenId)) &&
|
||||
data.WriteUInt64Vector(mirrorScreenId);
|
||||
if (!res) {
|
||||
WLOGFE("create mirror fail: data write failed");
|
||||
return DMError::DM_ERROR_WRITE_DATA_FAILED;
|
||||
return SCREEN_ID_INVALID;
|
||||
}
|
||||
if (remote->SendRequest(TRANS_ID_SCREEN_MAKE_MIRROR, data, reply, option) != ERR_NONE) {
|
||||
WLOGFW("create mirror fail: SendRequest failed");
|
||||
return DMError::DM_ERROR_IPC_FAILED;
|
||||
return SCREEN_ID_INVALID;
|
||||
}
|
||||
return static_cast<DMError>(reply.ReadInt32());
|
||||
return static_cast<ScreenId>(reply.ReadUint64());
|
||||
}
|
||||
|
||||
sptr<ScreenInfo> DisplayManagerProxy::GetScreenInfoById(ScreenId screenId)
|
||||
@@ -682,9 +747,9 @@ sptr<ScreenInfo> DisplayManagerProxy::GetScreenInfoById(ScreenId screenId)
|
||||
WLOGFW("GetScreenInfoById SendRequest nullptr.");
|
||||
return nullptr;
|
||||
}
|
||||
for (int i = 0; i < info->modes_.size(); i++) {
|
||||
for (auto& mode : info->GetModes()) {
|
||||
WLOGFI("info modes is width: %{public}u, height: %{public}u, freshRate: %{public}u",
|
||||
info->modes_[i]->width_, info->modes_[i]->height_, info->modes_[i]->freshRate_);
|
||||
mode->width_, mode->height_, mode->freshRate_);
|
||||
}
|
||||
return info;
|
||||
}
|
||||
@@ -750,12 +815,12 @@ std::vector<sptr<ScreenInfo>> DisplayManagerProxy::GetAllScreenInfos()
|
||||
return screenInfos;
|
||||
}
|
||||
|
||||
DMError DisplayManagerProxy::MakeExpand(std::vector<ScreenId> screenId, std::vector<Point> startPoint)
|
||||
ScreenId DisplayManagerProxy::MakeExpand(std::vector<ScreenId> screenId, std::vector<Point> startPoint)
|
||||
{
|
||||
sptr<IRemoteObject> remote = Remote();
|
||||
if (remote == nullptr) {
|
||||
WLOGFW("MakeExpand: remote is null");
|
||||
return DMError::DM_ERROR_REMOTE_CREATE_FAILED;
|
||||
return SCREEN_ID_INVALID;
|
||||
}
|
||||
|
||||
MessageParcel data;
|
||||
@@ -763,28 +828,53 @@ DMError DisplayManagerProxy::MakeExpand(std::vector<ScreenId> screenId, std::vec
|
||||
MessageOption option;
|
||||
if (!data.WriteInterfaceToken(GetDescriptor())) {
|
||||
WLOGFE("MakeExpand: WriteInterfaceToken failed");
|
||||
return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED;
|
||||
return SCREEN_ID_INVALID;
|
||||
}
|
||||
if (!data.WriteUInt64Vector(screenId)) {
|
||||
WLOGFE("MakeExpand: write screenId failed");
|
||||
return DMError::DM_ERROR_WRITE_DATA_FAILED;
|
||||
return SCREEN_ID_INVALID;
|
||||
}
|
||||
uint32_t num = startPoint.size();
|
||||
if (!data.WriteUint32(num)) {
|
||||
WLOGFE("MakeExpand: write startPoint size failed");
|
||||
return DMError::DM_ERROR_WRITE_DATA_FAILED;
|
||||
return SCREEN_ID_INVALID;
|
||||
}
|
||||
for (auto point: startPoint) {
|
||||
if (!(data.WriteInt32(point.posX_) && data.WriteInt32(point.posY_))) {
|
||||
WLOGFE("MakeExpand: write startPoint failed");
|
||||
return DMError::DM_ERROR_WRITE_DATA_FAILED;
|
||||
return SCREEN_ID_INVALID;
|
||||
}
|
||||
}
|
||||
if (remote->SendRequest(TRANS_ID_SCREEN_MAKE_EXPAND, data, reply, option) != ERR_NONE) {
|
||||
WLOGFE("MakeExpand: SendRequest failed");
|
||||
return DMError::DM_ERROR_IPC_FAILED;
|
||||
return SCREEN_ID_INVALID;
|
||||
}
|
||||
return static_cast<ScreenId>(reply.ReadUint64());
|
||||
}
|
||||
|
||||
void DisplayManagerProxy::RemoveVirtualScreenFromGroup(std::vector<ScreenId> screens)
|
||||
{
|
||||
sptr<IRemoteObject> remote = Remote();
|
||||
if (remote == nullptr) {
|
||||
WLOGFW("cancel make mirror or expand fail: remote is null");
|
||||
return;
|
||||
}
|
||||
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
if (!data.WriteInterfaceToken(GetDescriptor())) {
|
||||
WLOGFE("cancel make mirror or expand fail: WriteInterfaceToken failed");
|
||||
return;
|
||||
}
|
||||
bool res = data.WriteUInt64Vector(screens);
|
||||
if (!res) {
|
||||
WLOGFE("cancel make mirror or expand fail: write screens failed.");
|
||||
return;
|
||||
}
|
||||
if (remote->SendRequest(TRANS_ID_SCREEN_MAKE_MIRROR_OR_EXPAND_CANCELED, data, reply, option) != ERR_NONE) {
|
||||
WLOGFW("cancel make mirror or expand fail: SendRequest failed");
|
||||
}
|
||||
return static_cast<DMError>(reply.ReadInt32());
|
||||
}
|
||||
|
||||
bool DisplayManagerProxy::SetScreenActiveMode(ScreenId screenId, uint32_t modeId)
|
||||
|
||||
@@ -33,7 +33,8 @@ const bool REGISTER_RESULT = SystemAbility::MakeAndRegisterAbility(&SingletonCon
|
||||
|
||||
DisplayManagerService::DisplayManagerService() : SystemAbility(DISPLAY_MANAGER_SERVICE_SA_ID, true),
|
||||
abstractDisplayController_(new AbstractDisplayController(mutex_)),
|
||||
abstractScreenController_(new AbstractScreenController(mutex_))
|
||||
abstractScreenController_(new AbstractScreenController(mutex_)),
|
||||
displayPowerController_(new DisplayPowerController(mutex_))
|
||||
{
|
||||
}
|
||||
|
||||
@@ -84,25 +85,34 @@ ScreenId DisplayManagerService::GetScreenIdFromDisplayId(DisplayId displayId)
|
||||
|
||||
DisplayId DisplayManagerService::GetDefaultDisplayId()
|
||||
{
|
||||
ScreenId screenId = abstractDisplayController_->GetDefaultScreenId();
|
||||
WLOGFI("GetDefaultDisplayId %{public}" PRIu64"", screenId);
|
||||
return GetDisplayIdFromScreenId(screenId);
|
||||
ScreenId dmsScreenId = abstractScreenController_->GetDefaultScreenId();
|
||||
WLOGFI("GetDefaultDisplayId %{public}" PRIu64"", dmsScreenId);
|
||||
sptr<AbstractDisplay> display = GetDisplayByScreen(dmsScreenId);
|
||||
if (display == nullptr) {
|
||||
WLOGFE("fail to get displayInfo by id: invalid display");
|
||||
return DISPLAY_ID_INVALD;
|
||||
}
|
||||
return display->GetId();
|
||||
}
|
||||
|
||||
DisplayInfo DisplayManagerService::GetDisplayInfoById(DisplayId displayId)
|
||||
sptr<DisplayInfo> DisplayManagerService::GetDisplayInfoById(DisplayId displayId)
|
||||
{
|
||||
DisplayInfo displayInfo;
|
||||
sptr<AbstractDisplay> display = GetDisplayByDisplayId(displayId);
|
||||
if (display == nullptr) {
|
||||
WLOGFE("GetDisplayById: Get invalid display!");
|
||||
return displayInfo;
|
||||
WLOGFE("fail to get displayInfo by id: invalid display");
|
||||
return nullptr;
|
||||
}
|
||||
displayInfo.id_ = displayId;
|
||||
displayInfo.width_ = display->GetWidth();
|
||||
displayInfo.height_ = display->GetHeight();
|
||||
displayInfo.freshRate_ = display->GetFreshRate();
|
||||
displayInfo.screenId_ = display->GetAbstractScreenId();
|
||||
return displayInfo;
|
||||
return display->ConvertToDisplayInfo();
|
||||
}
|
||||
|
||||
sptr<DisplayInfo> DisplayManagerService::GetDisplayInfoByScreen(ScreenId screenId)
|
||||
{
|
||||
sptr<AbstractDisplay> display = GetDisplayByScreen(screenId);
|
||||
if (display == nullptr) {
|
||||
WLOGFE("fail to get displayInfo by screenId: invalid display");
|
||||
return nullptr;
|
||||
}
|
||||
return display->ConvertToDisplayInfo();
|
||||
}
|
||||
|
||||
sptr<AbstractDisplay> DisplayManagerService::GetAbstractDisplay(DisplayId displayId)
|
||||
@@ -113,8 +123,6 @@ sptr<AbstractDisplay> DisplayManagerService::GetAbstractDisplay(DisplayId displa
|
||||
ScreenId DisplayManagerService::CreateVirtualScreen(VirtualScreenOption option)
|
||||
{
|
||||
WM_SCOPED_TRACE("dms:CreateVirtualScreen(%s)", option.name_.c_str());
|
||||
WLOGFI("DumpScreenInfo before Create VirtualScreen");
|
||||
abstractScreenController_->DumpScreenInfo();
|
||||
ScreenId screenId = abstractScreenController_->CreateVirtualScreen(option);
|
||||
if (screenId == SCREEN_ID_INVALID) {
|
||||
WLOGFE("DisplayManagerService::CreateVirtualScreen: Get virtualScreenId failed");
|
||||
@@ -160,15 +168,15 @@ DMError DisplayManagerService::SetVirtualScreenSurface(ScreenId screenId, sptr<S
|
||||
return abstractScreenController_->SetVirtualScreenSurface(screenId, surface);
|
||||
}
|
||||
|
||||
bool DisplayManagerService::RequestRotation(ScreenId screenId, Rotation rotation)
|
||||
bool DisplayManagerService::SetOrientation(ScreenId screenId, Orientation orientation)
|
||||
{
|
||||
WM_SCOPED_TRACE("dms:RequestRotation(%" PRIu64")", screenId);
|
||||
return abstractScreenController_->RequestRotation(screenId, rotation);
|
||||
WM_SCOPED_TRACE("dms:SetOrientation(%" PRIu64")", screenId);
|
||||
return abstractScreenController_->SetOrientation(screenId, orientation);
|
||||
}
|
||||
|
||||
std::shared_ptr<Media::PixelMap> DisplayManagerService::GetDispalySnapshot(DisplayId displayId)
|
||||
std::shared_ptr<Media::PixelMap> DisplayManagerService::GetDisplaySnapshot(DisplayId displayId)
|
||||
{
|
||||
WM_SCOPED_TRACE("dms:GetDispalySnapshot(%" PRIu64")", displayId);
|
||||
WM_SCOPED_TRACE("dms:GetDisplaySnapshot(%" PRIu64")", displayId);
|
||||
std::shared_ptr<Media::PixelMap> screenSnapshot
|
||||
= abstractDisplayController_->GetScreenSnapshot(displayId);
|
||||
return screenSnapshot;
|
||||
@@ -296,7 +304,7 @@ bool DisplayManagerService::WakeUpEnd()
|
||||
bool DisplayManagerService::SuspendBegin(PowerStateChangeReason reason)
|
||||
{
|
||||
WM_SCOPED_TRACE("dms:SuspendBegin(%u)", reason);
|
||||
displayPowerController_.SuspendBegin(reason);
|
||||
displayPowerController_->SuspendBegin(reason);
|
||||
return DisplayManagerAgentController::GetInstance().NotifyDisplayPowerEvent(DisplayPowerEvent::SLEEP,
|
||||
EventStatus::BEGIN);
|
||||
}
|
||||
@@ -317,8 +325,7 @@ bool DisplayManagerService::SetScreenPowerForAll(DisplayPowerState state, PowerS
|
||||
|
||||
bool DisplayManagerService::SetDisplayState(DisplayState state)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
return displayPowerController_.SetDisplayState(state);
|
||||
return displayPowerController_->SetDisplayState(state);
|
||||
}
|
||||
|
||||
ScreenId DisplayManagerService::GetScreenIdByDisplayId(DisplayId displayId) const
|
||||
@@ -336,6 +343,11 @@ sptr<AbstractDisplay> DisplayManagerService::GetDisplayByDisplayId(DisplayId dis
|
||||
return abstractDisplayController_->GetAbstractDisplay(displayId);
|
||||
}
|
||||
|
||||
sptr<AbstractDisplay> DisplayManagerService::GetDisplayByScreen(ScreenId screenId) const
|
||||
{
|
||||
return abstractDisplayController_->GetAbstractDisplayByScreen(screenId);
|
||||
}
|
||||
|
||||
sptr<AbstractScreenController> DisplayManagerService::GetAbstractScreenController()
|
||||
{
|
||||
return abstractScreenController_;
|
||||
@@ -344,13 +356,12 @@ sptr<AbstractScreenController> DisplayManagerService::GetAbstractScreenControlle
|
||||
DisplayState DisplayManagerService::GetDisplayState(DisplayId displayId)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
return displayPowerController_.GetDisplayState(displayId);
|
||||
return displayPowerController_->GetDisplayState(displayId);
|
||||
}
|
||||
|
||||
void DisplayManagerService::NotifyDisplayEvent(DisplayEvent event)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
displayPowerController_.NotifyDisplayEvent(event);
|
||||
displayPowerController_->NotifyDisplayEvent(event);
|
||||
}
|
||||
|
||||
|
||||
@@ -367,6 +378,10 @@ std::shared_ptr<RSDisplayNode> DisplayManagerService::GetRSDisplayNodeByDisplayI
|
||||
void DisplayManagerService::SetShotScreen(ScreenId mainScreenId, std::vector<ScreenId> shotScreenIds)
|
||||
{
|
||||
WLOGFI("SetShotScreen. mainScreenId: %{public}" PRIu64"", mainScreenId);
|
||||
if (shotScreenIds.empty()) {
|
||||
WLOGFI("shotScreenIds is empty");
|
||||
return;
|
||||
}
|
||||
std::shared_ptr<RSDisplayNode> displayNode = abstractScreenController_->GetRSDisplayNodeByScreenId(mainScreenId);
|
||||
if (displayNode == nullptr) {
|
||||
WLOGFE("SetShotScreen error, cannot get DisplayNode");
|
||||
@@ -386,10 +401,9 @@ void DisplayManagerService::SetShotScreen(ScreenId mainScreenId, std::vector<Scr
|
||||
transactionProxy->FlushImplicitTransaction();
|
||||
}
|
||||
|
||||
DMError DisplayManagerService::MakeMirror(ScreenId mainScreenId, std::vector<ScreenId> mirrorScreenIds)
|
||||
ScreenId DisplayManagerService::MakeMirror(ScreenId mainScreenId, std::vector<ScreenId> mirrorScreenIds)
|
||||
{
|
||||
WLOGFI("MakeMirror. mainScreenId :%{public}" PRIu64"", mainScreenId);
|
||||
abstractScreenController_->DumpScreenInfo();
|
||||
auto shotScreenIds = abstractScreenController_->GetShotScreenIds(mirrorScreenIds);
|
||||
auto iter = std::find(shotScreenIds.begin(), shotScreenIds.end(), mainScreenId);
|
||||
if (iter != shotScreenIds.end()) {
|
||||
@@ -402,16 +416,26 @@ DMError DisplayManagerService::MakeMirror(ScreenId mainScreenId, std::vector<Scr
|
||||
}
|
||||
if (mainScreenId == SCREEN_ID_INVALID || (shotScreenIds.empty() && allMirrorScreenIds.empty())) {
|
||||
WLOGFI("create mirror fail, screen is invalid. Screen :%{public}" PRIu64"", mainScreenId);
|
||||
return DMError::DM_ERROR_INVALID_PARAM;
|
||||
return SCREEN_ID_INVALID;
|
||||
}
|
||||
SetShotScreen(mainScreenId, shotScreenIds);
|
||||
WM_SCOPED_TRACE("dms:MakeMirror");
|
||||
if (!allMirrorScreenIds.empty() && !abstractScreenController_->MakeMirror(mainScreenId, allMirrorScreenIds)) {
|
||||
WLOGFE("make mirror failed.");
|
||||
return DMError::DM_ERROR_NULLPTR;
|
||||
return SCREEN_ID_INVALID;
|
||||
}
|
||||
abstractScreenController_->DumpScreenInfo();
|
||||
return DMError::DM_OK;
|
||||
auto screen = abstractScreenController_->GetAbstractScreen(mainScreenId);
|
||||
if (screen == nullptr || abstractScreenController_->GetAbstractScreenGroup(screen->groupDmsId_) == nullptr) {
|
||||
WLOGFE("get screen group failed.");
|
||||
return SCREEN_ID_INVALID;
|
||||
}
|
||||
return screen->groupDmsId_;
|
||||
}
|
||||
|
||||
void DisplayManagerService::RemoveVirtualScreenFromGroup(std::vector<ScreenId> screens)
|
||||
{
|
||||
abstractScreenController_->RemoveVirtualScreenFromGroup(screens);
|
||||
}
|
||||
|
||||
void DisplayManagerService::UpdateRSTree(DisplayId displayId, std::shared_ptr<RSSurfaceNode>& surfaceNode,
|
||||
@@ -445,6 +469,11 @@ sptr<ScreenGroupInfo> DisplayManagerService::GetScreenGroupInfoById(ScreenId scr
|
||||
return screenGroup->ConvertToScreenGroupInfo();
|
||||
}
|
||||
|
||||
std::vector<DisplayId> DisplayManagerService::GetAllDisplayIds()
|
||||
{
|
||||
return abstractDisplayController_->GetAllDisplayIds();
|
||||
}
|
||||
|
||||
std::vector<sptr<ScreenInfo>> DisplayManagerService::GetAllScreenInfos()
|
||||
{
|
||||
std::vector<ScreenId> screenIds = abstractScreenController_->GetAllScreenIds();
|
||||
@@ -460,16 +489,15 @@ std::vector<sptr<ScreenInfo>> DisplayManagerService::GetAllScreenInfos()
|
||||
return screenInfos;
|
||||
}
|
||||
|
||||
DMError DisplayManagerService::MakeExpand(std::vector<ScreenId> expandScreenIds, std::vector<Point> startPoints)
|
||||
ScreenId DisplayManagerService::MakeExpand(std::vector<ScreenId> expandScreenIds, std::vector<Point> startPoints)
|
||||
{
|
||||
WLOGI("MakeExpand");
|
||||
if (expandScreenIds.empty() || startPoints.empty() || expandScreenIds.size() != startPoints.size()) {
|
||||
WLOGFI("create expand fail, input params is invalid. "
|
||||
"screenId vector size :%{public}ud, startPoint vector size :%{public}ud",
|
||||
static_cast<uint32_t>(expandScreenIds.size()), static_cast<uint32_t>(startPoints.size()));
|
||||
return DMError::DM_ERROR_INVALID_PARAM;
|
||||
return SCREEN_ID_INVALID;
|
||||
}
|
||||
abstractScreenController_->DumpScreenInfo();
|
||||
ScreenId defaultScreenId = abstractScreenController_->GetDefaultAbstractScreenId();
|
||||
WLOGI("MakeExpand, defaultScreenId:%{public}" PRIu64"", defaultScreenId);
|
||||
auto shotScreenIds = abstractScreenController_->GetShotScreenIds(expandScreenIds);
|
||||
@@ -490,10 +518,15 @@ DMError DisplayManagerService::MakeExpand(std::vector<ScreenId> expandScreenIds,
|
||||
WM_SCOPED_TRACE("dms:MakeExpand");
|
||||
if (!allExpandScreenIds.empty() && !abstractScreenController_->MakeExpand(allExpandScreenIds, startPoints)) {
|
||||
WLOGFE("make expand failed.");
|
||||
return DMError::DM_ERROR_NULLPTR;
|
||||
return SCREEN_ID_INVALID;
|
||||
}
|
||||
abstractScreenController_->DumpScreenInfo();
|
||||
return DMError::DM_OK;
|
||||
auto screen = abstractScreenController_->GetAbstractScreen(allExpandScreenIds[0]);
|
||||
if (screen == nullptr || abstractScreenController_->GetAbstractScreenGroup(screen->groupDmsId_) == nullptr) {
|
||||
WLOGFE("get screen group failed.");
|
||||
return SCREEN_ID_INVALID;
|
||||
}
|
||||
return screen->groupDmsId_;
|
||||
}
|
||||
|
||||
bool DisplayManagerService::SetScreenActiveMode(ScreenId screenId, uint32_t modeId)
|
||||
|
||||
@@ -41,23 +41,24 @@ const sptr<AbstractDisplay> DisplayManagerServiceInner::GetDisplayById(DisplayId
|
||||
{
|
||||
sptr<AbstractDisplay> display = DisplayManagerService::GetInstance().GetAbstractDisplay(displayId);
|
||||
if (display == nullptr) {
|
||||
DisplayInfo displayInfo = DisplayManagerService::GetInstance().GetDisplayInfoById(displayId);
|
||||
display = new AbstractDisplay(displayInfo);
|
||||
WLOGFE("GetDisplayById create new!\n");
|
||||
WLOGFE("GetDisplayById can not find corresponding display!\n");
|
||||
}
|
||||
return display;
|
||||
}
|
||||
|
||||
const sptr<AbstractDisplay> DisplayManagerServiceInner::GetDefaultDisplay()
|
||||
{
|
||||
DisplayId defaultDisplayId = GetDefaultDisplayId();
|
||||
if (defaultDisplayId == DISPLAY_ID_INVALD) {
|
||||
WLOGFE("Fail to get default displayId");
|
||||
return nullptr;
|
||||
}
|
||||
return GetDisplayById(GetDefaultDisplayId());
|
||||
}
|
||||
|
||||
std::vector<DisplayId> DisplayManagerServiceInner::GetAllDisplayIds()
|
||||
{
|
||||
std::vector<DisplayId> res;
|
||||
res.push_back(GetDefaultDisplayId());
|
||||
return res;
|
||||
return DisplayManagerService::GetInstance().GetAllDisplayIds();
|
||||
}
|
||||
|
||||
std::vector<const sptr<AbstractDisplay>> DisplayManagerServiceInner::GetAllDisplays()
|
||||
@@ -92,6 +93,23 @@ const sptr<ScreenInfo> DisplayManagerServiceInner::GetScreenInfoByDisplayId(Disp
|
||||
DisplayManagerService::GetInstance().GetScreenIdByDisplayId(displayId));
|
||||
}
|
||||
|
||||
const sptr<SupportedScreenModes> DisplayManagerServiceInner::GetScreenModesByDisplayId(DisplayId displayId)
|
||||
{
|
||||
const sptr<AbstractDisplay> display = GetDisplayById(displayId);
|
||||
if (display == nullptr) {
|
||||
WLOGFE("can not get display.");
|
||||
return nullptr;
|
||||
}
|
||||
ScreenId dmsScreenId = display->GetAbstractScreenId();
|
||||
sptr<AbstractScreen> abstractScreen =
|
||||
DisplayManagerService::GetInstance().abstractScreenController_->GetAbstractScreen(dmsScreenId);
|
||||
if (abstractScreen == nullptr) {
|
||||
WLOGFE("can not get screenMode.");
|
||||
return nullptr;
|
||||
}
|
||||
return abstractScreen->GetActiveScreenMode();
|
||||
}
|
||||
|
||||
void DisplayManagerServiceInner::RegisterDisplayChangeListener(sptr<IDisplayChangeListener> listener)
|
||||
{
|
||||
DisplayManagerService::GetInstance().RegisterDisplayChangeListener(listener);
|
||||
|
||||
@@ -45,7 +45,13 @@ int32_t DisplayManagerStub::OnRemoteRequest(uint32_t code, MessageParcel &data,
|
||||
case TRANS_ID_GET_DISPLAY_BY_ID: {
|
||||
DisplayId displayId = data.ReadUint64();
|
||||
auto info = GetDisplayInfoById(displayId);
|
||||
reply.WriteParcelable(&info);
|
||||
reply.WriteParcelable(info);
|
||||
break;
|
||||
}
|
||||
case TRANS_ID_GET_DISPLAY_BY_SCREEN: {
|
||||
ScreenId screenId = data.ReadUint64();
|
||||
auto info = GetDisplayInfoByScreen(screenId);
|
||||
reply.WriteParcelable(info);
|
||||
break;
|
||||
}
|
||||
case TRANS_ID_CREATE_VIRTUAL_SCREEN: {
|
||||
@@ -53,11 +59,15 @@ int32_t DisplayManagerStub::OnRemoteRequest(uint32_t code, MessageParcel &data,
|
||||
uint32_t width = data.ReadUint32();
|
||||
uint32_t height = data.ReadUint32();
|
||||
float density = data.ReadFloat();
|
||||
sptr<IRemoteObject> surfaceObject = data.ReadRemoteObject();
|
||||
sptr<IBufferProducer> bp = iface_cast<IBufferProducer>(surfaceObject);
|
||||
sptr<Surface> surface = Surface::CreateSurfaceAsProducer(bp);
|
||||
int32_t flags = data.ReadInt32();
|
||||
bool isForShot = data.ReadBool();
|
||||
bool isSurfaceValid = data.ReadBool();
|
||||
sptr<Surface> surface = nullptr;
|
||||
if (isSurfaceValid) {
|
||||
sptr<IRemoteObject> surfaceObject = data.ReadRemoteObject();
|
||||
sptr<IBufferProducer> bp = iface_cast<IBufferProducer>(surfaceObject);
|
||||
surface = Surface::CreateSurfaceAsProducer(bp);
|
||||
}
|
||||
VirtualScreenOption option = {
|
||||
.name_ = name,
|
||||
.width_ = width,
|
||||
@@ -79,22 +89,26 @@ int32_t DisplayManagerStub::OnRemoteRequest(uint32_t code, MessageParcel &data,
|
||||
}
|
||||
case TRANS_ID_SET_VIRTUAL_SCREEN_SURFACE: {
|
||||
ScreenId screenId = static_cast<ScreenId>(data.ReadUint64());
|
||||
sptr<IRemoteObject> surfaceObject = data.ReadRemoteObject();
|
||||
sptr<IBufferProducer> bp = iface_cast<IBufferProducer>(surfaceObject);
|
||||
sptr<Surface> surface = Surface::CreateSurfaceAsProducer(bp);
|
||||
bool isSurfaceValid = data.ReadBool();
|
||||
sptr<Surface> surface = nullptr;
|
||||
if (isSurfaceValid) {
|
||||
sptr<IRemoteObject> surfaceObject = data.ReadRemoteObject();
|
||||
sptr<IBufferProducer> bp = iface_cast<IBufferProducer>(surfaceObject);
|
||||
surface = Surface::CreateSurfaceAsProducer(bp);
|
||||
}
|
||||
DMError result = SetVirtualScreenSurface(screenId, surface);
|
||||
reply.WriteInt32(static_cast<int32_t>(result));
|
||||
break;
|
||||
}
|
||||
case TRANS_ID_REQUEST_ROTATION: {
|
||||
case TRANS_ID_SET_ORIENTATION: {
|
||||
ScreenId screenId = static_cast<ScreenId>(data.ReadUint64());
|
||||
Rotation rotation = static_cast<Rotation>(data.ReadUint32());
|
||||
reply.WriteBool(RequestRotation(screenId, rotation));
|
||||
Orientation orientation = static_cast<Orientation>(data.ReadUint32());
|
||||
reply.WriteBool(SetOrientation(screenId, orientation));
|
||||
break;
|
||||
}
|
||||
case TRANS_ID_GET_DISPLAY_SNAPSHOT: {
|
||||
DisplayId displayId = data.ReadUint64();
|
||||
std::shared_ptr<Media::PixelMap> dispalySnapshot = GetDispalySnapshot(displayId);
|
||||
std::shared_ptr<Media::PixelMap> dispalySnapshot = GetDisplaySnapshot(displayId);
|
||||
if (dispalySnapshot == nullptr) {
|
||||
reply.WriteParcelable(nullptr);
|
||||
break;
|
||||
@@ -159,16 +173,16 @@ int32_t DisplayManagerStub::OnRemoteRequest(uint32_t code, MessageParcel &data,
|
||||
WLOGE("fail to receive mirror screen in stub. screen:%{public}" PRIu64"", mainScreenId);
|
||||
break;
|
||||
}
|
||||
DMError result = MakeMirror(mainScreenId, mirrorScreenId);
|
||||
reply.WriteInt32(static_cast<int32_t>(result));
|
||||
ScreenId result = MakeMirror(mainScreenId, mirrorScreenId);
|
||||
reply.WriteUint64(static_cast<uint64_t>(result));
|
||||
break;
|
||||
}
|
||||
case TRANS_ID_GET_SCREEN_INFO_BY_ID: {
|
||||
ScreenId screenId = static_cast<ScreenId>(data.ReadUint64());
|
||||
auto screenInfo = GetScreenInfoById(screenId);
|
||||
for (int i = 0; i < screenInfo->modes_.size(); i++) {
|
||||
for (auto& mode : screenInfo->GetModes()) {
|
||||
WLOGFI("info modes is width: %{public}u, height: %{public}u, freshRate: %{public}u",
|
||||
screenInfo->modes_[i]->width_, screenInfo->modes_[i]->height_, screenInfo->modes_[i]->freshRate_);
|
||||
mode->width_, mode->height_, mode->freshRate_);
|
||||
}
|
||||
reply.WriteStrongParcelable(screenInfo);
|
||||
break;
|
||||
@@ -188,6 +202,11 @@ int32_t DisplayManagerStub::OnRemoteRequest(uint32_t code, MessageParcel &data,
|
||||
}
|
||||
break;
|
||||
}
|
||||
case TRANS_ID_GET_ALL_DISPLAYIDS: {
|
||||
std::vector<DisplayId> allDisplayIds = GetAllDisplayIds();
|
||||
reply.WriteUInt64Vector(allDisplayIds);
|
||||
break;
|
||||
}
|
||||
case TRANS_ID_SCREEN_MAKE_EXPAND: {
|
||||
std::vector<ScreenId> screenId;
|
||||
if (!data.ReadUInt64Vector(&screenId)) {
|
||||
@@ -200,8 +219,17 @@ int32_t DisplayManagerStub::OnRemoteRequest(uint32_t code, MessageParcel &data,
|
||||
Point point { data.ReadInt32(), data.ReadInt32() };
|
||||
startPoint.push_back(point);
|
||||
}
|
||||
DMError result = MakeExpand(screenId, startPoint);
|
||||
reply.WriteInt32(static_cast<int32_t>(result));
|
||||
ScreenId result = MakeExpand(screenId, startPoint);
|
||||
reply.WriteUint64(static_cast<uint64_t>(result));
|
||||
break;
|
||||
}
|
||||
case TRANS_ID_SCREEN_MAKE_MIRROR_OR_EXPAND_CANCELED: {
|
||||
std::vector<ScreenId> screenId;
|
||||
if (!data.ReadUInt64Vector(&screenId)) {
|
||||
WLOGE("fail to receive screens in stub.");
|
||||
break;
|
||||
}
|
||||
RemoveVirtualScreenFromGroup(screenId);
|
||||
break;
|
||||
}
|
||||
case TRANS_ID_SET_SCREEN_ACTIVE_MODE: {
|
||||
|
||||
@@ -35,14 +35,22 @@ bool DisplayPowerController::SuspendBegin(PowerStateChangeReason reason)
|
||||
bool DisplayPowerController::SetDisplayState(DisplayState state)
|
||||
{
|
||||
WLOGFI("state:%{public}u", state);
|
||||
if (displayState_ == state) {
|
||||
WLOGFE("state is already set");
|
||||
return false;
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
if (displayState_ == state) {
|
||||
WLOGFE("state is already set");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
switch (state) {
|
||||
case DisplayState::ON: {
|
||||
displayState_ = state;
|
||||
if (!isKeyguardDrawn_) {
|
||||
bool isKeyguardDrawn;
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
displayState_ = state;
|
||||
isKeyguardDrawn = isKeyguardDrawn_;
|
||||
}
|
||||
if (!isKeyguardDrawn) {
|
||||
DisplayManagerService::GetInstance().NotifyDisplayStateChange(DISPLAY_ID_INVALD,
|
||||
DisplayStateChangeType::BEFORE_UNLOCK);
|
||||
}
|
||||
@@ -51,7 +59,10 @@ bool DisplayPowerController::SetDisplayState(DisplayState state)
|
||||
break;
|
||||
}
|
||||
case DisplayState::OFF: {
|
||||
displayState_ = state;
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
displayState_ = state;
|
||||
}
|
||||
DisplayManagerAgentController::GetInstance().NotifyDisplayPowerEvent(DisplayPowerEvent::DISPLAY_OFF,
|
||||
EventStatus::BEGIN);
|
||||
break;
|
||||
@@ -78,10 +89,12 @@ void DisplayPowerController::NotifyDisplayEvent(DisplayEvent event)
|
||||
DisplayStateChangeType::BEFORE_UNLOCK);
|
||||
DisplayManagerAgentController::GetInstance().NotifyDisplayPowerEvent(DisplayPowerEvent::DESKTOP_READY,
|
||||
EventStatus::BEGIN);
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
isKeyguardDrawn_ = false;
|
||||
return;
|
||||
}
|
||||
if (event == DisplayEvent::KEYGUARD_DRAWN) {
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
isKeyguardDrawn_ = true;
|
||||
}
|
||||
}
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 107 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 45 KiB |
@@ -0,0 +1,48 @@
|
||||
# Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
#####################################################
|
||||
# below is the format of defining event #
|
||||
#####################################################
|
||||
#domain: domain name. [Only one domain name can be defined at the top]
|
||||
#
|
||||
#author: the author name who defined this event.
|
||||
#date: the date when this event was defined, format is YYYY-MM-DD.
|
||||
#logged: source file which refer to this event.
|
||||
#usage: the usage of this event.
|
||||
#//Define event name and event properties.
|
||||
#@EVENT_NAME: the event definition part begin.
|
||||
# // __BASE is used for defining the basic info of the event.
|
||||
# // "type" optional values are: FAULT, STATISTICS, SECURITY, BEHAVIOR.
|
||||
# // "level" optional values are: CRITICAL, MINOR.
|
||||
# // "tag" set tags with may used by subscriber of this event, multiple tags devided by space.
|
||||
# // "desc" full description of this event.
|
||||
# @PARAMETER: {type: parameter type, arrsize: array length(optional), desc: parameter description}.
|
||||
# // follow the __BASE block, each line defines a parameter of this event.
|
||||
# // "type" optional values are: INT8, UINT8, INT16, UINT16, INT32, UINT32, INT64, UINT64, FLOAT, DOUBLE, STRING.
|
||||
# // "arrsize" of the parameter is an array, set a non-zero value.
|
||||
# // "desc" full description of this parameter.
|
||||
|
||||
#####################################################
|
||||
# Example of some hiviewdfx events definition #
|
||||
#####################################################
|
||||
|
||||
domain: WINDOWMANAGER
|
||||
|
||||
NO_FOCUS_WINDOW:
|
||||
__BASE: {type: FAULT, level: CRITICAL, desc: The event is not consumed }
|
||||
PID: {type: INT32, desc: session pid}
|
||||
UID: {type: INT32, desc: session uid}
|
||||
PACKAGE_NAME: {type: STRING, desc: package name}
|
||||
PROCESS_NAME: {type: STRING, desc: process name}
|
||||
MSG: {type: STRING, desc: windowmanager event message}
|
||||
@@ -27,23 +27,29 @@ typedef enum DisplayType {
|
||||
} DisplayType;
|
||||
|
||||
class Display : public RefBase {
|
||||
friend class DisplayManager;
|
||||
public:
|
||||
Display(const std::string& name, DisplayInfo* info);
|
||||
~Display() = default;
|
||||
|
||||
~Display();
|
||||
Display(const Display&) = delete;
|
||||
Display(Display&&) = delete;
|
||||
Display& operator=(const Display&) = delete;
|
||||
Display& operator=(Display&&) = delete;
|
||||
DisplayId GetId() const;
|
||||
int32_t GetWidth() const;
|
||||
int32_t GetHeight() const;
|
||||
uint32_t GetFreshRate() const;
|
||||
ScreenId GetScreenId() const;
|
||||
float GetVirtualPixelRatio() const;
|
||||
Rotation GetRotation() const;
|
||||
Orientation GetOrientation() const;
|
||||
|
||||
void SetId(DisplayId displayId);
|
||||
void SetWidth(int32_t width);
|
||||
void SetHeight(int32_t height);
|
||||
void SetFreshRate(uint32_t freshRate);
|
||||
|
||||
protected:
|
||||
// No more methods or variables can be defined here.
|
||||
Display(const std::string& name, sptr<DisplayInfo> info);
|
||||
private:
|
||||
// No more methods or variables can be defined here.
|
||||
void UpdateDisplayInfo(sptr<DisplayInfo>) const;
|
||||
void UpdateDisplayInfo() const;
|
||||
class Impl;
|
||||
sptr<Impl> pImpl_;
|
||||
};
|
||||
|
||||
@@ -26,22 +26,21 @@
|
||||
#include "wm_single_instance.h"
|
||||
|
||||
namespace OHOS::Rosen {
|
||||
class DisplayManagerAgent;
|
||||
class DisplayManager {
|
||||
friend class DisplayManagerAgent;
|
||||
WM_DECLARE_SINGLE_INSTANCE_BASE(DisplayManager);
|
||||
public:
|
||||
class IDisplayListener : public virtual RefBase {
|
||||
public:
|
||||
virtual void OnCreate(DisplayId) = 0;
|
||||
virtual void OnDestroy(DisplayId) = 0;
|
||||
virtual void OnChange(DisplayId, DisplayChangeEvent) = 0;
|
||||
virtual void OnChange(DisplayId) = 0;
|
||||
};
|
||||
|
||||
std::vector<const sptr<Display>> GetAllDisplays();
|
||||
std::vector<sptr<Display>> GetAllDisplays();
|
||||
DisplayId GetDefaultDisplayId();
|
||||
const sptr<Display> GetDefaultDisplay();
|
||||
const sptr<Display> GetDisplayById(DisplayId displayId);
|
||||
sptr<Display> GetDefaultDisplay();
|
||||
sptr<Display> GetDisplayById(DisplayId displayId);
|
||||
sptr<Display> GetDisplayByScreen(ScreenId screenId);
|
||||
std::vector<DisplayId> GetAllDisplayIds();
|
||||
bool RegisterDisplayListener(sptr<IDisplayListener> listener);
|
||||
bool UnregisterDisplayListener(sptr<IDisplayListener> listener);
|
||||
@@ -69,14 +68,8 @@ private:
|
||||
DisplayManager();
|
||||
~DisplayManager();
|
||||
|
||||
class DisplayManagerListener;
|
||||
sptr<DisplayManagerListener> displayManagerListener_;
|
||||
class Impl;
|
||||
sptr<Impl> pImpl_;
|
||||
|
||||
void NotifyDisplayPowerEvent(DisplayPowerEvent event, EventStatus status);
|
||||
void NotifyDisplayStateChanged(DisplayId id, DisplayState state);
|
||||
void NotifyDisplayChangedEvent(const sptr<DisplayInfo> info, DisplayChangeEvent event);
|
||||
};
|
||||
} // namespace OHOS::Rosen
|
||||
|
||||
|
||||
@@ -22,8 +22,11 @@ namespace OHOS {
|
||||
namespace Rosen {
|
||||
using DisplayId = uint64_t;
|
||||
using ScreenId = uint64_t;
|
||||
static constexpr DisplayId DISPLAY_ID_INVALD = -1ULL;
|
||||
static constexpr ScreenId SCREEN_ID_INVALID = -1ULL;
|
||||
namespace {
|
||||
constexpr DisplayId DISPLAY_ID_INVALD = -1ULL;
|
||||
constexpr ScreenId SCREEN_ID_INVALID = -1ULL;
|
||||
const static std::string DEFAULT_SCREEN_NAME = "buildIn";
|
||||
}
|
||||
|
||||
enum class PowerStateChangeReason : uint32_t {
|
||||
POWER_BUTTON,
|
||||
@@ -84,11 +87,14 @@ public:
|
||||
};
|
||||
|
||||
enum class ScreenChangeEvent : uint32_t {
|
||||
UPDATE_ORIENTATION,
|
||||
CHANGE_MODE,
|
||||
};
|
||||
|
||||
enum class ScreenGroupChangeEvent : uint32_t {
|
||||
ADD_TO_GROUP,
|
||||
REMOVE_FROM_GROUP,
|
||||
CHANGE_GROUP,
|
||||
UPDATE_ROTATION,
|
||||
CHANGE_MODE,
|
||||
};
|
||||
|
||||
enum class Rotation : uint32_t {
|
||||
@@ -98,8 +104,21 @@ enum class Rotation : uint32_t {
|
||||
ROTATION_270,
|
||||
};
|
||||
|
||||
enum class Orientation : uint32_t {
|
||||
BEGIN = 0,
|
||||
UNSPECIFIED = BEGIN,
|
||||
VERTICAL = 1,
|
||||
HORIZONTAL = 2,
|
||||
REVERSE_VERTICAL = 3,
|
||||
REVERSE_HORIZONTAL = 4,
|
||||
SENSOR = 5,
|
||||
SENSOR_VERTICAL = 6,
|
||||
SENSOR_HORIZONTAL = 7,
|
||||
END = SENSOR_HORIZONTAL,
|
||||
};
|
||||
|
||||
enum class DisplayChangeEvent : uint32_t {
|
||||
UPDATE_ROTATION,
|
||||
UPDATE_ORIENTATION,
|
||||
DISPLAY_SIZE_CHANGED,
|
||||
UNKNOWN,
|
||||
};
|
||||
|
||||
@@ -30,7 +30,7 @@ class ScreenInfo;
|
||||
struct Point {
|
||||
int32_t posX_;
|
||||
int32_t posY_;
|
||||
Point() {};
|
||||
Point() : posX_(0), posY_(0) {};
|
||||
Point(int32_t posX, int32_t posY) : posX_(posX), posY_(posY) {};
|
||||
};
|
||||
|
||||
@@ -57,22 +57,29 @@ struct ExpandOption {
|
||||
};
|
||||
|
||||
class Screen : public RefBase {
|
||||
friend class ScreenManager;
|
||||
public:
|
||||
Screen(const ScreenInfo* info);
|
||||
~Screen();
|
||||
Screen(const Screen&) = delete;
|
||||
Screen(Screen&&) = delete;
|
||||
Screen& operator=(const Screen&) = delete;
|
||||
Screen& operator=(Screen&&) = delete;
|
||||
bool IsGroup() const;
|
||||
const std::string& GetName() const;
|
||||
ScreenId GetId() const;
|
||||
uint32_t GetWidth() const;
|
||||
uint32_t GetHeight() const;
|
||||
uint32_t GetVirtualWidth() const;
|
||||
uint32_t GetVirtualHeight() const;
|
||||
float GetVirtualPixelRatio() const;
|
||||
bool RequestRotation(Rotation rotation);
|
||||
Rotation GetRotation();
|
||||
Rotation GetRotation() const;
|
||||
Orientation GetOrientation() const;
|
||||
bool IsReal() const;
|
||||
ScreenId GetParentId() const;
|
||||
uint32_t GetModeId() const;
|
||||
std::vector<sptr<SupportedScreenModes>> GetSupportedModes() const;
|
||||
bool SetScreenActiveMode(uint32_t modeId);
|
||||
bool SetOrientation(Orientation orientation) const;
|
||||
|
||||
// colorspace, gamut
|
||||
DMError GetScreenSupportedColorGamuts(std::vector<ScreenColorGamut>& colorGamuts) const;
|
||||
@@ -81,8 +88,13 @@ public:
|
||||
DMError GetScreenGamutMap(ScreenGamutMap& gamutMap) const;
|
||||
DMError SetScreenGamutMap(ScreenGamutMap gamutMap);
|
||||
DMError SetScreenColorTransform();
|
||||
|
||||
protected:
|
||||
// No more methods or variables can be defined here.
|
||||
Screen(sptr<ScreenInfo> info);
|
||||
void UpdateScreenInfo() const;
|
||||
void UpdateScreenInfo(sptr<ScreenInfo> info) const;
|
||||
private:
|
||||
// No more methods or variables can be defined here.
|
||||
class Impl;
|
||||
sptr<Impl> pImpl_;
|
||||
};
|
||||
|
||||
@@ -29,13 +29,21 @@ enum class ScreenCombination : uint32_t {
|
||||
};
|
||||
|
||||
class ScreenGroup : public Screen {
|
||||
friend class ScreenManager;
|
||||
public:
|
||||
ScreenGroup(const ScreenGroupInfo* info);
|
||||
~ScreenGroup();
|
||||
ScreenGroup(const ScreenGroup&) = delete;
|
||||
ScreenGroup(ScreenGroup&&) = delete;
|
||||
ScreenGroup& operator=(const ScreenGroup&) = delete;
|
||||
ScreenGroup& operator=(ScreenGroup&&) = delete;
|
||||
ScreenCombination GetCombination() const;
|
||||
std::vector<ScreenId> GetChildrenIds() const;
|
||||
std::vector<ScreenId> GetChildIds() const;
|
||||
std::vector<Point> GetChildPositions() const;
|
||||
|
||||
private:
|
||||
// No more methods or variables can be defined here.
|
||||
ScreenGroup(sptr<ScreenGroupInfo> info);
|
||||
void UpdateScreenGroupInfo(sptr<ScreenGroupInfo> info);
|
||||
class Impl;
|
||||
sptr<Impl> pImpl_;
|
||||
};
|
||||
|
||||
@@ -31,17 +31,26 @@ public:
|
||||
public:
|
||||
virtual void OnConnect(ScreenId) = 0;
|
||||
virtual void OnDisconnect(ScreenId) = 0;
|
||||
virtual void OnChange(const std::vector<ScreenId>&, ScreenChangeEvent) = 0;
|
||||
virtual void OnChange(ScreenId) = 0;
|
||||
};
|
||||
|
||||
class IScreenGroupListener : public virtual RefBase {
|
||||
public:
|
||||
virtual void OnChange(const std::vector<ScreenId>&, ScreenGroupChangeEvent) = 0;
|
||||
};
|
||||
|
||||
sptr<Screen> GetScreenById(ScreenId screenId);
|
||||
sptr<ScreenGroup> GetScreenGroupById(ScreenId screenId);
|
||||
sptr<ScreenGroup> GetScreenGroup(ScreenId groupId);
|
||||
std::vector<sptr<Screen>> GetAllScreens();
|
||||
|
||||
bool RegisterScreenListener(sptr<IScreenListener> listener);
|
||||
bool UnregisterScreenListener(sptr<IScreenListener> listener);
|
||||
bool RegisterScreenGroupListener(sptr<IScreenGroupListener> listener);
|
||||
bool UnregisterScreenGroupListener(sptr<IScreenGroupListener> listener);
|
||||
ScreenId MakeExpand(const std::vector<ExpandOption>& options);
|
||||
ScreenId MakeMirror(ScreenId mainScreenId, std::vector<ScreenId> mirrorScreenId);
|
||||
void RemoveVirtualScreenFromGroup(std::vector<ScreenId> screens);
|
||||
void CancelMakeMirrorOrExpand(std::vector<ScreenId> screens);
|
||||
ScreenId CreateVirtualScreen(VirtualScreenOption option);
|
||||
DMError DestroyVirtualScreen(ScreenId screenId);
|
||||
DMError SetVirtualScreenSurface(ScreenId screenId, sptr<Surface> surface);
|
||||
@@ -50,8 +59,6 @@ private:
|
||||
ScreenManager();
|
||||
~ScreenManager();
|
||||
|
||||
class ScreenManagerListener;
|
||||
sptr<ScreenManagerListener> screenManagerListener_;
|
||||
class Impl;
|
||||
sptr<Impl> pImpl_;
|
||||
};
|
||||
|
||||
@@ -38,6 +38,10 @@ namespace OHOS::AbilityRuntime {
|
||||
class Context;
|
||||
}
|
||||
|
||||
namespace OHOS::Ace {
|
||||
class UIContent;
|
||||
}
|
||||
|
||||
namespace OHOS {
|
||||
namespace Rosen {
|
||||
class RSSurfaceNode;
|
||||
@@ -57,6 +61,12 @@ public:
|
||||
virtual void OnDrag(int32_t x, int32_t y, DragEvent event) = 0;
|
||||
};
|
||||
|
||||
class IDisplayMoveListener : virtual public RefBase {
|
||||
public:
|
||||
virtual void OnDisplayMove(DisplayId from, DisplayId to) = 0;
|
||||
};
|
||||
|
||||
|
||||
class Window : public RefBase {
|
||||
public:
|
||||
static sptr<Window> Create(const std::string& windowName,
|
||||
@@ -114,9 +124,12 @@ public:
|
||||
virtual void UnregisterAvoidAreaChangeListener() = 0;
|
||||
virtual void RegisterDragListener(sptr<IWindowDragListener>& listener) = 0;
|
||||
virtual void UnregisterDragListener(sptr<IWindowDragListener>& listener) = 0;
|
||||
virtual void RegisterDisplayMoveListener(sptr<IDisplayMoveListener>& listener) = 0;
|
||||
virtual void UnregisterDisplayMoveListener(sptr<IDisplayMoveListener>& listener) = 0;
|
||||
virtual WMError SetUIContent(const std::string& contentInfo, NativeEngine* engine,
|
||||
NativeValue* storage, bool isdistributed = false) = 0;
|
||||
virtual std::string GetContentInfo() = 0;
|
||||
virtual Ace::UIContent* GetUIContent() const = 0;
|
||||
|
||||
virtual bool IsDecorEnable() const = 0;
|
||||
virtual WMError Maximize() = 0;
|
||||
|
||||
@@ -49,6 +49,27 @@ public:
|
||||
virtual void OnSystemBarPropertyChange(DisplayId displayId, const SystemBarRegionTints& tints) = 0;
|
||||
};
|
||||
|
||||
class WindowVisibilityInfo : public Parcelable {
|
||||
public:
|
||||
WindowVisibilityInfo() = default;
|
||||
WindowVisibilityInfo(uint32_t winId, int32_t pid, int32_t uid, bool visibility)
|
||||
: windowId_(winId), pid_(pid), uid_(uid), isVisible_(visibility) {};
|
||||
~WindowVisibilityInfo() = default;
|
||||
|
||||
virtual bool Marshalling(Parcel& parcel) const override;
|
||||
static WindowVisibilityInfo* Unmarshalling(Parcel& parcel);
|
||||
|
||||
uint32_t windowId_ { INVALID_WINDOW_ID };
|
||||
int32_t pid_ { 0 };
|
||||
int32_t uid_ { 0 };
|
||||
bool isVisible_ { false };
|
||||
};
|
||||
|
||||
class IVisibilityChangedListener : public RefBase {
|
||||
public:
|
||||
virtual void OnWindowVisibilityChanged(const std::vector<sptr<WindowVisibilityInfo>>& windowVisibilityInfo) = 0;
|
||||
};
|
||||
|
||||
class WindowInfo : public Parcelable {
|
||||
public:
|
||||
WindowInfo() = default;
|
||||
@@ -78,8 +99,10 @@ public:
|
||||
void UnregisterSystemBarChangedListener(const sptr<ISystemBarChangedListener>& listener);
|
||||
void RegisterWindowUpdateListener(const sptr<IWindowUpdateListener>& listener);
|
||||
void UnregisterWindowUpdateListener(const sptr<IWindowUpdateListener>& listener);
|
||||
void RegisterVisibilityChangedListener(const sptr<IVisibilityChangedListener>& listener);
|
||||
void UnregisterVisibilityChangedListener(const sptr<IVisibilityChangedListener>& listener);
|
||||
void MinimizeAllAppWindows(DisplayId displayId);
|
||||
void SetWindowLayoutMode(WindowLayoutMode mode, DisplayId displayId);
|
||||
WMError SetWindowLayoutMode(WindowLayoutMode mode, DisplayId displayId);
|
||||
|
||||
private:
|
||||
WindowManager();
|
||||
@@ -91,6 +114,8 @@ private:
|
||||
DisplayId displayId, bool focused) const;
|
||||
void UpdateSystemBarRegionTints(DisplayId displayId, const SystemBarRegionTints& tints) const;
|
||||
void UpdateWindowStatus(const sptr<WindowInfo>& windowInfo, WindowUpdateType type);
|
||||
void UpdateWindowVisibilityInfo(
|
||||
const std::vector<sptr<WindowVisibilityInfo>>& windowVisibilityInfos) const;
|
||||
};
|
||||
} // namespace Rosen
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -23,19 +23,19 @@ enum class WindowType : uint32_t {
|
||||
APP_WINDOW_BASE = 1,
|
||||
APP_MAIN_WINDOW_BASE = APP_WINDOW_BASE,
|
||||
WINDOW_TYPE_APP_MAIN_WINDOW = APP_MAIN_WINDOW_BASE,
|
||||
APP_MAIN_WINDOW_END = WINDOW_TYPE_APP_MAIN_WINDOW, // equals last window type
|
||||
APP_MAIN_WINDOW_END,
|
||||
|
||||
APP_SUB_WINDOW_BASE = 1000,
|
||||
WINDOW_TYPE_MEDIA = APP_SUB_WINDOW_BASE,
|
||||
WINDOW_TYPE_APP_SUB_WINDOW,
|
||||
APP_SUB_WINDOW_END = WINDOW_TYPE_APP_SUB_WINDOW, // equals last window type
|
||||
APP_SUB_WINDOW_END,
|
||||
APP_WINDOW_END = APP_SUB_WINDOW_END,
|
||||
|
||||
SYSTEM_WINDOW_BASE = 2000,
|
||||
BELOW_APP_SYSTEM_WINDOW_BASE = SYSTEM_WINDOW_BASE,
|
||||
WINDOW_TYPE_WALLPAPER = SYSTEM_WINDOW_BASE,
|
||||
WINDOW_TYPE_DESKTOP,
|
||||
BELOW_APP_SYSTEM_WINDOW_END = WINDOW_TYPE_DESKTOP, // equals last window type
|
||||
BELOW_APP_SYSTEM_WINDOW_END,
|
||||
|
||||
ABOVE_APP_SYSTEM_WINDOW_BASE = 2100,
|
||||
WINDOW_TYPE_APP_LAUNCHING = ABOVE_APP_SYSTEM_WINDOW_BASE,
|
||||
@@ -55,7 +55,9 @@ enum class WindowType : uint32_t {
|
||||
WINDOW_TYPE_POINTER,
|
||||
WINDOW_TYPE_LAUNCHER_RECENT,
|
||||
WINDOW_TYPE_LAUNCHER_DOCK,
|
||||
ABOVE_APP_SYSTEM_WINDOW_END = WINDOW_TYPE_LAUNCHER_DOCK, // equals last window type
|
||||
WINDOW_TYPE_BOOT_ANIMATION,
|
||||
ABOVE_APP_SYSTEM_WINDOW_END,
|
||||
|
||||
SYSTEM_WINDOW_END = ABOVE_APP_SYSTEM_WINDOW_END,
|
||||
};
|
||||
|
||||
@@ -125,10 +127,17 @@ struct Rect {
|
||||
int32_t posY_;
|
||||
uint32_t width_;
|
||||
uint32_t height_;
|
||||
bool operator == (const Rect& a) const
|
||||
|
||||
bool operator==(const Rect& a) const
|
||||
{
|
||||
return (posX_ == a.posX_ && posY_ == a.posY_ && width_ == a.width_ && height_ == a.height_);
|
||||
}
|
||||
|
||||
bool IsInsideOf(const Rect& a) const
|
||||
{
|
||||
return (posX_ >= a.posX_ && posY_ >= a.posY_ &&
|
||||
posX_ + width_ <= a.posX_ + a.width_ && posY_ + height_ <= a.posY_ + a.height_);
|
||||
}
|
||||
};
|
||||
|
||||
struct PointInfo {
|
||||
@@ -139,21 +148,14 @@ struct PointInfo {
|
||||
namespace {
|
||||
constexpr uint32_t SYSTEM_COLOR_WHITE = 0xE5FFFFFF;
|
||||
constexpr uint32_t SYSTEM_COLOR_BLACK = 0x66000000;
|
||||
constexpr float DEFAULT_SPLIT_RATIO = 0.5;
|
||||
constexpr uint32_t DIVIDER_WIDTH = 8;
|
||||
constexpr uint32_t INVALID_WINDOW_ID = 0;
|
||||
constexpr uint32_t HOTZONE = 40;
|
||||
constexpr uint32_t MIN_VERTICAL_FLOATING_WIDTH = 240;
|
||||
constexpr uint32_t MIN_VERTICAL_FLOATING_HEIGHT = 426;
|
||||
constexpr uint32_t MIN_VERTICAL_SPLIT_HEIGHT = 426;
|
||||
constexpr uint32_t MIN_HORIZONTAL_SPLIT_WIDTH = 426;
|
||||
}
|
||||
|
||||
struct SystemBarProperty {
|
||||
bool enable_;
|
||||
uint32_t backgroundColor_;
|
||||
uint32_t contentColor_;
|
||||
SystemBarProperty() : enable_(true), backgroundColor_(SYSTEM_COLOR_WHITE), contentColor_(SYSTEM_COLOR_BLACK) {}
|
||||
SystemBarProperty() : enable_(true), backgroundColor_(SYSTEM_COLOR_BLACK), contentColor_(SYSTEM_COLOR_WHITE) {}
|
||||
SystemBarProperty(bool enable, uint32_t background, uint32_t content)
|
||||
: enable_(enable), backgroundColor_(background), contentColor_(content) {}
|
||||
bool operator == (const SystemBarProperty& a) const
|
||||
|
||||
@@ -13,20 +13,58 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { AsyncCallback, Callback } from './basic';
|
||||
|
||||
/**
|
||||
* interface of display manager
|
||||
* @syscap SystemCapability.WindowManager.WindowManager.Core
|
||||
* @devices tv, phone, tablet, wearable
|
||||
*/
|
||||
declare namespace display {
|
||||
|
||||
/**
|
||||
* get the default display
|
||||
* @devices tv, phone, tablet, wearable
|
||||
*/
|
||||
function getDefaultDisplay(callback: AsyncCallback<Display>): void;
|
||||
|
||||
/**
|
||||
* get the default display
|
||||
* @devices tv, phone, tablet, wearable
|
||||
*/
|
||||
function getDefaultDisplay(): Promise<Display>;
|
||||
|
||||
/**
|
||||
* get all displays
|
||||
* @devices tv, phone, tablet, wearable
|
||||
* @param callback
|
||||
*/
|
||||
function getAllDisplay(callback: AsyncCallback<Array<Display>>): void;
|
||||
|
||||
/**
|
||||
* get all displays
|
||||
* @devices tv, phone, tablet, wearable
|
||||
*/
|
||||
function getAllDisplay() : Promise<Array<Display>>;
|
||||
|
||||
/**
|
||||
* register the callback of display change
|
||||
* @param type: type of callback
|
||||
* @devices tv, phone, tablet, wearable, car
|
||||
*/
|
||||
function on(type: 'add' | 'remove' | 'change', callback: Callback<number>): void;
|
||||
|
||||
/**
|
||||
* unregister the callback of display change
|
||||
* @param type: type of callback
|
||||
* #devices tv, phone, tablet, wearable, car
|
||||
*/
|
||||
function off(type: 'add' | 'remove' | 'change', callback?: Callback<number>): void;
|
||||
|
||||
/**
|
||||
/**
|
||||
* the state of display
|
||||
* @syscap SystemCapability.WindowManager.WindowManager.Core
|
||||
* @devices tv, phone, tablet, wearable
|
||||
*/
|
||||
enum DisplayState {
|
||||
@@ -62,6 +100,7 @@ declare namespace display {
|
||||
|
||||
/**
|
||||
* Properties of display, it couldn't update automatically
|
||||
* @syscap SystemCapability.WindowManager.WindowManager.Core
|
||||
* @devices tv, phone, tablet, wearable
|
||||
*/
|
||||
interface Display {
|
||||
|
||||
@@ -16,7 +16,7 @@ import("//build/ohos.gni")
|
||||
|
||||
group("napi_packages") {
|
||||
deps = [
|
||||
"display:display",
|
||||
"display:display_napi",
|
||||
"display_runtime:screen_napi",
|
||||
"screenshot:screenshot",
|
||||
"window_runtime:window_napi",
|
||||
|
||||
@@ -13,22 +13,47 @@
|
||||
|
||||
import("//build/ohos.gni")
|
||||
|
||||
## Build display.so {{{
|
||||
ohos_shared_library("display") {
|
||||
sources = [ "native_display_module.cpp" ]
|
||||
config("display_config") {
|
||||
visibility = [ ":*" ]
|
||||
|
||||
include_dirs = [
|
||||
"//foundation/windowmanager/interfaces/kits/napi/display",
|
||||
"//foundation/windowmanager/utils/include",
|
||||
]
|
||||
}
|
||||
|
||||
## Build display_napi.so {{{
|
||||
ohos_shared_library("display_napi") {
|
||||
sources = [
|
||||
"js_display.cpp",
|
||||
"js_display_listener.cpp",
|
||||
"js_display_manager.cpp",
|
||||
"js_display_module.cpp",
|
||||
]
|
||||
|
||||
configs = [ ":display_config" ]
|
||||
|
||||
deps = [
|
||||
"../common:wm_napi_common",
|
||||
"//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native",
|
||||
"//foundation/aafwk/standard/frameworks/kits/appkit:app_context",
|
||||
"//foundation/aafwk/standard/frameworks/kits/appkit:appkit_native",
|
||||
"//foundation/aafwk/standard/interfaces/innerkits/want:want",
|
||||
"//foundation/graphic/standard/rosen/modules/render_service_client:librender_service_client",
|
||||
"//foundation/windowmanager/dm:libdm",
|
||||
"//foundation/windowmanager/utils:libwmutil",
|
||||
"//foundation/windowmanager/wm:libwm",
|
||||
"//foundation/windowmanager/wmserver:libwms",
|
||||
]
|
||||
|
||||
external_deps = [ "multimedia_image_standard:image_native" ]
|
||||
external_deps = [
|
||||
"ability_runtime:ability_manager",
|
||||
"ability_runtime:runtime",
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
"multimedia_image_standard:image_native",
|
||||
"napi:ace_napi",
|
||||
]
|
||||
|
||||
relative_install_dir = "module"
|
||||
part_name = "window_manager"
|
||||
subsystem_name = "window"
|
||||
}
|
||||
## Build display.so }}}
|
||||
## Build display_napi.so }}}
|
||||
|
||||
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT 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 "js_display.h"
|
||||
|
||||
#include <cinttypes>
|
||||
#include <map>
|
||||
#include "display.h"
|
||||
#include "window_manager_hilog.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Rosen {
|
||||
using namespace AbilityRuntime;
|
||||
namespace {
|
||||
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "JsDisplay"};
|
||||
}
|
||||
|
||||
static std::map<DisplayId, std::shared_ptr<NativeReference>> g_JsDisplayMap;
|
||||
std::recursive_mutex g_mutex;
|
||||
|
||||
JsDisplay::JsDisplay(const sptr<Display>& display) : display_(display)
|
||||
{
|
||||
}
|
||||
|
||||
JsDisplay::~JsDisplay()
|
||||
{
|
||||
WLOGFI("JsDisplay::~JsDisplay is called");
|
||||
}
|
||||
|
||||
void JsDisplay::Finalizer(NativeEngine* engine, void* data, void* hint)
|
||||
{
|
||||
WLOGFI("JsDisplay::Finalizer is called");
|
||||
auto jsDisplay = std::unique_ptr<JsDisplay>(static_cast<JsDisplay*>(data));
|
||||
if (jsDisplay == nullptr) {
|
||||
WLOGFE("JsDisplay::Finalizer jsDisplay is null");
|
||||
return;
|
||||
}
|
||||
sptr<Display> display = jsDisplay->display_;
|
||||
if (display == nullptr) {
|
||||
WLOGFE("JsDisplay::Finalizer display is null");
|
||||
return;
|
||||
}
|
||||
DisplayId displayId = display->GetId();
|
||||
WLOGFI("JsDisplay::Finalizer displayId : %{public}" PRIu64"", displayId);
|
||||
std::lock_guard<std::recursive_mutex> lock(g_mutex);
|
||||
if (g_JsDisplayMap.find(displayId) != g_JsDisplayMap.end()) {
|
||||
WLOGFI("JsDisplay::Finalizer Display is destroyed: %{public}" PRIu64"", displayId);
|
||||
g_JsDisplayMap.erase(displayId);
|
||||
}
|
||||
}
|
||||
|
||||
NativeValue* CreateJsDisplayObject(NativeEngine& engine, sptr<Display>& display)
|
||||
{
|
||||
WLOGFI("JsDisplay::CreateJsDisplay is called");
|
||||
NativeValue* objValue = engine.CreateObject();
|
||||
NativeObject* object = ConvertNativeValueTo<NativeObject>(objValue);
|
||||
if (object == nullptr) {
|
||||
WLOGFE("Failed to convert prop to jsObject");
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
std::unique_ptr<JsDisplay> jsDisplay = std::make_unique<JsDisplay>(display);
|
||||
object->SetNativePointer(jsDisplay.release(), JsDisplay::Finalizer, nullptr);
|
||||
|
||||
object->SetProperty("id", CreateJsValue(engine, static_cast<uint32_t>(display->GetId())));
|
||||
object->SetProperty("width", CreateJsValue(engine, display->GetWidth()));
|
||||
object->SetProperty("height", CreateJsValue(engine, display->GetHeight()));
|
||||
object->SetProperty("refreshRate", CreateJsValue(engine, display->GetFreshRate()));
|
||||
object->SetProperty("name", engine.CreateUndefined());
|
||||
object->SetProperty("alive", engine.CreateUndefined());
|
||||
object->SetProperty("state", engine.CreateUndefined());
|
||||
object->SetProperty("rotation", engine.CreateUndefined());
|
||||
object->SetProperty("densityDPI", engine.CreateUndefined());
|
||||
object->SetProperty("densityPixels", engine.CreateUndefined());
|
||||
object->SetProperty("scaledDensity", engine.CreateUndefined());
|
||||
object->SetProperty("xDPI", engine.CreateUndefined());
|
||||
object->SetProperty("yDPI", engine.CreateUndefined());
|
||||
|
||||
std::shared_ptr<NativeReference> jsDisplayRef;
|
||||
jsDisplayRef.reset(engine.CreateReference(objValue, 1));
|
||||
DisplayId displayId = display->GetId();
|
||||
std::lock_guard<std::recursive_mutex> lock(g_mutex);
|
||||
g_JsDisplayMap[displayId] = jsDisplayRef;
|
||||
return objValue;
|
||||
}
|
||||
} // namespace Rosen
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT 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_JS_DISPLAY_H
|
||||
#define OHOS_JS_DISPLAY_H
|
||||
#include "js_runtime_utils.h"
|
||||
#include "native_engine/native_engine.h"
|
||||
#include "native_engine/native_value.h"
|
||||
#include "display.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Rosen {
|
||||
NativeValue* CreateJsDisplayObject(NativeEngine& engine, sptr<Display>& Display);
|
||||
class JsDisplay final {
|
||||
public:
|
||||
explicit JsDisplay(const sptr<Display>& Display);
|
||||
~JsDisplay();
|
||||
static void Finalizer(NativeEngine* engine, void* data, void* hint);
|
||||
|
||||
private:
|
||||
sptr<Display> display_ = nullptr;
|
||||
};
|
||||
} // namespace Rosen
|
||||
} // namespace OHOS
|
||||
#endif
|
||||
@@ -0,0 +1,143 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT 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 "js_display_listener.h"
|
||||
#include "js_runtime_utils.h"
|
||||
#include "window_manager_hilog.h"
|
||||
namespace OHOS {
|
||||
namespace Rosen {
|
||||
using namespace AbilityRuntime;
|
||||
namespace {
|
||||
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "JsDisplayListener"};
|
||||
}
|
||||
|
||||
void JsDisplayListener::AddCallback(NativeValue* jsListenerObject)
|
||||
{
|
||||
WLOGFI("JsDisplayListener::AddCallback is called");
|
||||
std::unique_ptr<NativeReference> callbackRef;
|
||||
if (engine_ == nullptr) {
|
||||
WLOGFE("engine_ nullptr");
|
||||
return;
|
||||
}
|
||||
callbackRef.reset(engine_->CreateReference(jsListenerObject, 1));
|
||||
std::lock_guard<std::mutex> lock(mtx_);
|
||||
jsCallBack_.push_back(std::move(callbackRef));
|
||||
WLOGFI("JsDisplayListener::AddCallback success jsCallBack_ size: %{public}u!",
|
||||
static_cast<uint32_t>(jsCallBack_.size()));
|
||||
}
|
||||
|
||||
void JsDisplayListener::RemoveAllCallback()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mtx_);
|
||||
jsCallBack_.clear();
|
||||
}
|
||||
|
||||
void JsDisplayListener::RemoveCallback(NativeValue* jsListenerObject)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mtx_);
|
||||
for (auto iter = jsCallBack_.begin(); iter != jsCallBack_.end();) {
|
||||
if (jsListenerObject->StrictEquals((*iter)->Get())) {
|
||||
jsCallBack_.erase(iter);
|
||||
} else {
|
||||
iter++;
|
||||
}
|
||||
}
|
||||
WLOGFI("JsDisplayListener::RemoveCallback success jsCallBack_ size: %{public}u!",
|
||||
static_cast<uint32_t>(jsCallBack_.size()));
|
||||
}
|
||||
|
||||
void JsDisplayListener::CallJsMethod(const char* methodName, NativeValue* const* argv, size_t argc)
|
||||
{
|
||||
WLOGFI("CallJsMethod methodName = %{public}s", methodName);
|
||||
if (engine_ == nullptr) {
|
||||
WLOGFE("engine_ nullptr");
|
||||
return;
|
||||
}
|
||||
for (auto& callback : jsCallBack_) {
|
||||
NativeValue* method = callback->Get();
|
||||
if (method == nullptr) {
|
||||
WLOGFE("Failed to get method callback from object");
|
||||
continue;
|
||||
}
|
||||
engine_->CallFunction(engine_->CreateUndefined(), method, argv, argc);
|
||||
}
|
||||
}
|
||||
|
||||
void JsDisplayListener::OnCreate(DisplayId id)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mtx_);
|
||||
WLOGFI("JsDisplayListener::OnCreate is called, displayId: %{public}d", static_cast<uint32_t>(id));
|
||||
if (jsCallBack_.empty()) {
|
||||
WLOGFE("JsDisplayListener::OnCreate not register!");
|
||||
return;
|
||||
}
|
||||
|
||||
std::unique_ptr<AsyncTask::CompleteCallback> complete = std::make_unique<AsyncTask::CompleteCallback> (
|
||||
[=] (NativeEngine &engine, AsyncTask &task, int32_t status) {
|
||||
NativeValue* argv[] = {CreateJsValue(*engine_, static_cast<uint32_t>(id))};
|
||||
CallJsMethod("add", argv, ArraySize(argv));
|
||||
}
|
||||
);
|
||||
|
||||
NativeReference* callback = nullptr;
|
||||
std::unique_ptr<AsyncTask::ExecuteCallback> execute = nullptr;
|
||||
AsyncTask::Schedule(*engine_, std::make_unique<AsyncTask>(
|
||||
callback, std::move(execute), std::move(complete)));
|
||||
}
|
||||
|
||||
void JsDisplayListener::OnDestroy(DisplayId id)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mtx_);
|
||||
WLOGFI("JsDisplayListener::OnDestroy is called, displayId: %{public}d", static_cast<uint32_t>(id));
|
||||
if (jsCallBack_.empty()) {
|
||||
WLOGFE("JsDisplayListener::OnDestroy not register!");
|
||||
return;
|
||||
}
|
||||
|
||||
std::unique_ptr<AsyncTask::CompleteCallback> complete = std::make_unique<AsyncTask::CompleteCallback> (
|
||||
[=] (NativeEngine &engine, AsyncTask &task, int32_t status) {
|
||||
NativeValue* argv[] = {CreateJsValue(*engine_, static_cast<uint32_t>(id))};
|
||||
CallJsMethod("remove", argv, ArraySize(argv));
|
||||
}
|
||||
);
|
||||
|
||||
NativeReference* callback = nullptr;
|
||||
std::unique_ptr<AsyncTask::ExecuteCallback> execute = nullptr;
|
||||
AsyncTask::Schedule(*engine_, std::make_unique<AsyncTask>(
|
||||
callback, std::move(execute), std::move(complete)));
|
||||
}
|
||||
|
||||
void JsDisplayListener::OnChange(DisplayId id)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mtx_);
|
||||
WLOGFI("JsDisplayListener::OnChange is called, displayId: %{public}d", static_cast<uint32_t>(id));
|
||||
if (jsCallBack_.empty()) {
|
||||
WLOGFE("JsDisplayListener::OnChange not register!");
|
||||
return;
|
||||
}
|
||||
|
||||
std::unique_ptr<AsyncTask::CompleteCallback> complete = std::make_unique<AsyncTask::CompleteCallback> (
|
||||
[=] (NativeEngine &engine, AsyncTask &task, int32_t status) {
|
||||
NativeValue* argv[] = {CreateJsValue(*engine_, static_cast<uint32_t>(id))};
|
||||
CallJsMethod("change", argv, ArraySize(argv));
|
||||
}
|
||||
);
|
||||
|
||||
NativeReference* callback = nullptr;
|
||||
std::unique_ptr<AsyncTask::ExecuteCallback> execute = nullptr;
|
||||
AsyncTask::Schedule(*engine_, std::make_unique<AsyncTask>(
|
||||
callback, std::move(execute), std::move(complete)));
|
||||
}
|
||||
} // namespace Rosen
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT 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_JS_DISPLAY_LISTENER_H
|
||||
#define OHOS_JS_DISPLAY_LISTENER_H
|
||||
|
||||
#include <mutex>
|
||||
#include "native_engine/native_engine.h"
|
||||
#include "native_engine/native_value.h"
|
||||
#include "refbase.h"
|
||||
#include "display_manager.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Rosen {
|
||||
class JsDisplayListener : public DisplayManager::IDisplayListener {
|
||||
public:
|
||||
explicit JsDisplayListener(NativeEngine* engine) : engine_(engine) {}
|
||||
~JsDisplayListener() override = default;
|
||||
void AddCallback(NativeValue* jsListenerObject);
|
||||
void RemoveAllCallback();
|
||||
void RemoveCallback(NativeValue* jsListenerObject);
|
||||
void OnCreate(DisplayId id) override;
|
||||
void OnDestroy(DisplayId id) override;
|
||||
void OnChange(DisplayId id) override;
|
||||
|
||||
private:
|
||||
void CallJsMethod(const char* methodName, NativeValue* const* argv = nullptr, size_t argc = 0);
|
||||
NativeEngine* engine_ = nullptr;
|
||||
std::mutex mtx_;
|
||||
std::vector<std::unique_ptr<NativeReference>> jsCallBack_;
|
||||
NativeValue* CreateDisplayIdArray(NativeEngine& engine, const std::vector<DisplayId>& data);
|
||||
};
|
||||
} // namespace Rosen
|
||||
} // namespace OHOS
|
||||
#endif /* OHOS_JS_DISPLAY_LISTENER_H */
|
||||
@@ -0,0 +1,328 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <vector>
|
||||
#include <new>
|
||||
|
||||
#include "js_runtime_utils.h"
|
||||
#include "native_engine/native_reference.h"
|
||||
#include "display_manager.h"
|
||||
#include "window_manager_hilog.h"
|
||||
#include "singleton_container.h"
|
||||
#include "js_display_listener.h"
|
||||
#include "js_display.h"
|
||||
#include "js_display_manager.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Rosen {
|
||||
using namespace AbilityRuntime;
|
||||
constexpr size_t ARGC_ONE = 1;
|
||||
constexpr size_t ARGC_TWO = 2;
|
||||
constexpr int32_t INDEX_ONE = 1;
|
||||
namespace {
|
||||
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "JsDisplayManager"};
|
||||
}
|
||||
|
||||
class JsDisplayManager {
|
||||
public:
|
||||
explicit JsDisplayManager(NativeEngine* engine) {
|
||||
}
|
||||
|
||||
~JsDisplayManager() = default;
|
||||
|
||||
static void Finalizer(NativeEngine* engine, void* data, void* hint)
|
||||
{
|
||||
WLOGFI("JsDisplayManager::Finalizer is called");
|
||||
std::unique_ptr<JsDisplayManager>(static_cast<JsDisplayManager*>(data));
|
||||
}
|
||||
|
||||
static NativeValue* GetDefaultDisplay(NativeEngine* engine, NativeCallbackInfo* info)
|
||||
{
|
||||
JsDisplayManager* me = CheckParamsAndGetThis<JsDisplayManager>(engine, info);
|
||||
return (me != nullptr) ? me->OnGetDefaultDisplay(*engine, *info) : nullptr;
|
||||
}
|
||||
|
||||
static NativeValue* GetAllDisplay(NativeEngine* engine, NativeCallbackInfo* info)
|
||||
{
|
||||
JsDisplayManager* me = CheckParamsAndGetThis<JsDisplayManager>(engine, info);
|
||||
return (me != nullptr) ? me->OnGetAllDisplay(*engine, *info) : nullptr;
|
||||
}
|
||||
|
||||
static NativeValue* RegisterDisplayManagerCallback(NativeEngine* engine, NativeCallbackInfo* info)
|
||||
{
|
||||
JsDisplayManager* me = CheckParamsAndGetThis<JsDisplayManager>(engine, info);
|
||||
return (me != nullptr) ? me->OnRegisterDisplayManagerCallback(*engine, *info) : nullptr;
|
||||
}
|
||||
|
||||
static NativeValue* UnregisterDisplayManagerCallback(NativeEngine* engine, NativeCallbackInfo* info)
|
||||
{
|
||||
JsDisplayManager* me = CheckParamsAndGetThis<JsDisplayManager>(engine, info);
|
||||
return (me != nullptr) ? me->OnUnregisterDisplayManagerCallback(*engine, *info) : nullptr;
|
||||
}
|
||||
|
||||
private:
|
||||
std::map<std::string, std::map<std::unique_ptr<NativeReference>, sptr<JsDisplayListener>>> jsCbMap_;
|
||||
std::mutex mtx_;
|
||||
|
||||
NativeValue* OnGetDefaultDisplay(NativeEngine& engine, NativeCallbackInfo& info)
|
||||
{
|
||||
WLOGFI("JsDisplayManager::OnGetDefaultDisplay is called");
|
||||
DMError errCode = DMError::DM_OK;
|
||||
if (info.argc != 0 && info.argc != ARGC_ONE) {
|
||||
WLOGFE("JsDisplayManager::OnGetDefaultDisplay params not match");
|
||||
errCode = DMError::DM_ERROR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
AsyncTask::CompleteCallback complete =
|
||||
[=](NativeEngine& engine, AsyncTask& task, int32_t status) {
|
||||
if (errCode != DMError::DM_OK) {
|
||||
task.Reject(engine, CreateJsError(engine,
|
||||
static_cast<int32_t>(errCode), "JsDisplayManager::OnGetDefaultDisplay failed."));
|
||||
}
|
||||
sptr<Display> display = SingletonContainer::Get<DisplayManager>().GetDefaultDisplay();
|
||||
if (display != nullptr) {
|
||||
task.Resolve(engine, CreateJsDisplayObject(engine, display));
|
||||
WLOGFI("JsDisplayManager::OnGetDefaultDisplay success");
|
||||
} else {
|
||||
task.Reject(engine, CreateJsError(engine,
|
||||
static_cast<int32_t>(DMError::DM_ERROR_NULLPTR), "JsDisplayManager::OnGetDefaultDisplay failed."));
|
||||
}
|
||||
};
|
||||
NativeValue* lastParam = nullptr;
|
||||
if (info.argc == ARGC_ONE && info.argv[0]->TypeOf() == NATIVE_FUNCTION) {
|
||||
lastParam = info.argv[0];
|
||||
}
|
||||
NativeValue* result = nullptr;
|
||||
AsyncTask::Schedule(
|
||||
engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
|
||||
return result;
|
||||
}
|
||||
|
||||
NativeValue* OnGetAllDisplay(NativeEngine& engine, NativeCallbackInfo& info)
|
||||
{
|
||||
WLOGFI("JsDisplayManager::OnGetAllDisplay is called");
|
||||
DMError errCode = DMError::DM_OK;
|
||||
if (info.argc != 0 && info.argc != ARGC_ONE) {
|
||||
WLOGFE("JsDisplayManager::OnGetAllDisplay params not match");
|
||||
errCode = DMError::DM_ERROR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
AsyncTask::CompleteCallback complete =
|
||||
[=](NativeEngine& engine, AsyncTask& task, int32_t status) {
|
||||
if (errCode != DMError::DM_OK) {
|
||||
task.Reject(engine, CreateJsError(engine,
|
||||
static_cast<int32_t>(errCode), "JsDisplayManager::OnGetAllDisplay failed."));
|
||||
}
|
||||
std::vector<sptr<Display>> displays = SingletonContainer::Get<DisplayManager>().GetAllDisplays();
|
||||
if (!displays.empty()) {
|
||||
task.Resolve(engine, CreateJsDisplayArrayObject(engine, displays));
|
||||
WLOGFI("JsDisplayManager::GetAllDisplays success");
|
||||
} else {
|
||||
task.Reject(engine, CreateJsError(engine,
|
||||
static_cast<int32_t>(DMError::DM_ERROR_NULLPTR), "JsDisplayManager::OnGetAllDisplay failed."));
|
||||
}
|
||||
};
|
||||
|
||||
NativeValue* lastParam = nullptr;
|
||||
if (info.argc == ARGC_ONE && info.argv[0]->TypeOf() == NATIVE_FUNCTION) {
|
||||
lastParam = info.argv[0];
|
||||
}
|
||||
NativeValue* result = nullptr;
|
||||
AsyncTask::Schedule(
|
||||
engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
|
||||
return result;
|
||||
}
|
||||
|
||||
void RegisterDisplayListenerWithType(NativeEngine& engine, const std::string& type, NativeValue* value)
|
||||
{
|
||||
if (IfCallbackRegistered(type, value)) {
|
||||
WLOGFE("JsDisplayManager::RegisterDisplayListenerWithType callback already registered!");
|
||||
return;
|
||||
}
|
||||
std::unique_ptr<NativeReference> callbackRef;
|
||||
callbackRef.reset(engine.CreateReference(value, 1));
|
||||
sptr<JsDisplayListener> displayListener = new(std::nothrow) JsDisplayListener(&engine);
|
||||
if (displayListener == nullptr) {
|
||||
WLOGFE("displayListener is nullptr");
|
||||
return;
|
||||
}
|
||||
if (type == "add" || type == "remove" || type == "change") {
|
||||
SingletonContainer::Get<DisplayManager>().RegisterDisplayListener(displayListener);
|
||||
WLOGFI("JsDisplayManager::RegisterDisplayListenerWithType success");
|
||||
} else {
|
||||
WLOGFE("JsDisplayManager::RegisterDisplayListenerWithType failed method: %{public}s not support!",
|
||||
type.c_str());
|
||||
return;
|
||||
}
|
||||
displayListener->AddCallback(value);
|
||||
jsCbMap_[type][std::move(callbackRef)] = displayListener;
|
||||
}
|
||||
|
||||
bool IfCallbackRegistered(const std::string& type, NativeValue* jsListenerObject)
|
||||
{
|
||||
if (jsCbMap_.empty() || jsCbMap_.find(type) == jsCbMap_.end()) {
|
||||
WLOGFI("JsDisplayManager::IfCallbackRegistered methodName %{public}s not registered!", type.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
for (auto& iter : jsCbMap_[type]) {
|
||||
if (jsListenerObject->StrictEquals(iter.first->Get())) {
|
||||
WLOGFE("JsDisplayManager::IfCallbackRegistered callback already registered!");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void UnregisterAllDisplayListenerWithType(const std::string& type)
|
||||
{
|
||||
if (jsCbMap_.empty() || jsCbMap_.find(type) == jsCbMap_.end()) {
|
||||
WLOGFI("JsDisplayManager::UnregisterAllDisplayListenerWithType methodName %{public}s not registered!",
|
||||
type.c_str());
|
||||
return;
|
||||
}
|
||||
for (auto it = jsCbMap_[type].begin(); it != jsCbMap_[type].end();) {
|
||||
it->second->RemoveAllCallback();
|
||||
if (type == "add" || type == "remove" || type == "change") {
|
||||
sptr<DisplayManager::IDisplayListener> thisListener(it->second);
|
||||
SingletonContainer::Get<DisplayManager>().UnregisterDisplayListener(thisListener);
|
||||
WLOGFI("JsDisplayManager::UnregisterAllDisplayListenerWithType success");
|
||||
}
|
||||
jsCbMap_[type].erase(it++);
|
||||
}
|
||||
jsCbMap_.erase(type);
|
||||
}
|
||||
|
||||
void UnRegisterDisplayListenerWithType(const std::string& type, NativeValue* value)
|
||||
{
|
||||
if (jsCbMap_.empty() || jsCbMap_.find(type) == jsCbMap_.end()) {
|
||||
WLOGFI("JsDisplayManager::UnRegisterDisplayListenerWithType methodName %{public}s not registered!",
|
||||
type.c_str());
|
||||
return;
|
||||
}
|
||||
for (auto it = jsCbMap_[type].begin(); it != jsCbMap_[type].end();) {
|
||||
if (value->StrictEquals(it->first->Get())) {
|
||||
it->second->RemoveCallback(value);
|
||||
if (type == "add" || type == "remove" || type == "change") {
|
||||
sptr<DisplayManager::IDisplayListener> thisListener(it->second);
|
||||
SingletonContainer::Get<DisplayManager>().UnregisterDisplayListener(thisListener);
|
||||
WLOGFI("JsDisplayManager::UnRegisterDisplayListenerWithType success");
|
||||
}
|
||||
jsCbMap_[type].erase(it++);
|
||||
break;
|
||||
} else {
|
||||
it++;
|
||||
}
|
||||
}
|
||||
if (jsCbMap_[type].empty()) {
|
||||
jsCbMap_.erase(type);
|
||||
}
|
||||
}
|
||||
|
||||
NativeValue* OnRegisterDisplayManagerCallback(NativeEngine& engine, NativeCallbackInfo& info)
|
||||
{
|
||||
WLOGFI("JsDisplayManager::OnRegisterDisplayManagerCallback is called");
|
||||
if (info.argc != ARGC_TWO) {
|
||||
WLOGFE("JsDisplayManager Params not match: %{public}zu", info.argc);
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
std::string cbType;
|
||||
if (!ConvertFromJsValue(engine, info.argv[0], cbType)) {
|
||||
WLOGFE("Failed to convert parameter to callbackType");
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
NativeValue* value = info.argv[INDEX_ONE];
|
||||
if (value == nullptr) {
|
||||
WLOGFI("JsDisplayManager::OnRegisterDisplayManagerCallback info->argv[1] is nullptr");
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
if (!value->IsCallable()) {
|
||||
WLOGFI("JsDisplayManager::OnRegisterDisplayManagerCallback info->argv[1] is not callable");
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
std::lock_guard<std::mutex> lock(mtx_);
|
||||
RegisterDisplayListenerWithType(engine, cbType, value);
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
|
||||
NativeValue* OnUnregisterDisplayManagerCallback(NativeEngine& engine, NativeCallbackInfo& info)
|
||||
{
|
||||
WLOGFI("JsDisplayManager::OnUnregisterDisplayCallback is called");
|
||||
if (info.argc == 0) {
|
||||
WLOGFE("JsDisplayManager Params not match %{public}zu", info.argc);
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
std::string cbType;
|
||||
if (!ConvertFromJsValue(engine, info.argv[0], cbType)) {
|
||||
WLOGFE("Failed to convert parameter to callbackType");
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
std::lock_guard<std::mutex> lock(mtx_);
|
||||
if (info.argc == ARGC_ONE) {
|
||||
UnregisterAllDisplayListenerWithType(cbType);
|
||||
} else {
|
||||
NativeValue* value = info.argv[INDEX_ONE];
|
||||
if (value == nullptr) {
|
||||
WLOGFI("JsDisplayManager::OnUnregisterDisplayManagerCallback info->argv[1] is nullptr");
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
if (!value->IsCallable()) {
|
||||
WLOGFI("JsDisplayManager::OnUnregisterDisplayManagerCallback info->argv[1] is not callable");
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
UnRegisterDisplayListenerWithType(cbType, value);
|
||||
}
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
|
||||
NativeValue* CreateJsDisplayArrayObject(NativeEngine& engine, std::vector<sptr<Display>>& displays)
|
||||
{
|
||||
WLOGFI("JsDisplayManager::CreateJsDisplayArrayObject is called");
|
||||
NativeValue* arrayValue = engine.CreateArray(displays.size());
|
||||
NativeArray* array = ConvertNativeValueTo<NativeArray>(arrayValue);
|
||||
int32_t i = 0;
|
||||
for (auto& display : displays) {
|
||||
array->SetElement(i++, CreateJsDisplayObject(engine, display));
|
||||
}
|
||||
return arrayValue;
|
||||
}
|
||||
};
|
||||
|
||||
NativeValue* JsDisplayManagerInit(NativeEngine* engine, NativeValue* exportObj)
|
||||
{
|
||||
WLOGFI("JsDisplayManagerInit is called");
|
||||
|
||||
if (engine == nullptr || exportObj == nullptr) {
|
||||
WLOGFE("JsDisplayManagerInit engine or exportObj is nullptr");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
NativeObject* object = ConvertNativeValueTo<NativeObject>(exportObj);
|
||||
if (object == nullptr) {
|
||||
WLOGFE("JsDisplayManagerInit object is nullptr");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::unique_ptr<JsDisplayManager> jsDisplayManager = std::make_unique<JsDisplayManager>(engine);
|
||||
object->SetNativePointer(jsDisplayManager.release(), JsDisplayManager::Finalizer, nullptr);
|
||||
|
||||
BindNativeFunction(*engine, *object, "getDefaultDisplay", JsDisplayManager::GetDefaultDisplay);
|
||||
BindNativeFunction(*engine, *object, "getAllDisplay", JsDisplayManager::GetAllDisplay);
|
||||
BindNativeFunction(*engine, *object, "on", JsDisplayManager::RegisterDisplayManagerCallback);
|
||||
BindNativeFunction(*engine, *object, "off", JsDisplayManager::UnregisterDisplayManagerCallback);
|
||||
return engine->CreateUndefined();
|
||||
}
|
||||
} // namespace Rosen
|
||||
} // namespace OHOS
|
||||
+28
-19
@@ -1,19 +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.
|
||||
*/
|
||||
|
||||
#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
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT 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_JS_DISPLAY_MANAGER_H
|
||||
#define OHOS_JS_DISPLAY_MANAGER_H
|
||||
|
||||
#include "native_engine/native_engine.h"
|
||||
#include "native_engine/native_value.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Rosen {
|
||||
NativeValue* JsDisplayManagerInit(NativeEngine* engine, NativeValue* exportObj);
|
||||
} // namespace Rosen
|
||||
} // namespace OHOS
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT 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 "js_display_manager.h"
|
||||
#include "native_engine/native_engine.h"
|
||||
|
||||
extern "C" __attribute__((constructor)) void NAPI_application_displaymanager_AutoRegister()
|
||||
{
|
||||
auto moduleManager = NativeModuleManager::GetInstance();
|
||||
NativeModule newModuleInfo = {
|
||||
.name = "display",
|
||||
.fileName = "module/libdisplay_napi.so/display.js",
|
||||
.registerCallback = OHOS::Rosen::JsDisplayManagerInit,
|
||||
};
|
||||
|
||||
moduleManager->Register(&newModuleInfo);
|
||||
}
|
||||
@@ -1,113 +0,0 @@
|
||||
/*
|
||||
* 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 <cinttypes>
|
||||
|
||||
#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> display;
|
||||
};
|
||||
|
||||
void Async(napi_env env, std::unique_ptr<Param> ¶m)
|
||||
{
|
||||
param->display = DisplayManager::GetInstance().GetDefaultDisplay();
|
||||
if (param->display == nullptr) {
|
||||
GNAPI_LOG("Get display failed!");
|
||||
param->wret = WMError::WM_ERROR_NULLPTR;
|
||||
return;
|
||||
}
|
||||
GNAPI_LOG("GetDefaultDisplay: id %{public}" PRIu64", w %{public}d, h %{public}d",
|
||||
param->display->GetId(), param->display->GetWidth(), param->display->GetHeight());
|
||||
param->wret = WMError::WM_OK;
|
||||
}
|
||||
|
||||
napi_value Resolve(napi_env env, std::unique_ptr<Param> ¶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}" PRIu64"", 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<Param>();
|
||||
return CreatePromise<Param>(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);
|
||||
}
|
||||
+15
-52
@@ -30,8 +30,8 @@ declare namespace screen {
|
||||
function getAllScreen(): Promise<Array<Screen>>;
|
||||
|
||||
// Screen plug-in event; Screen resolution ratio and other parameters, combination relationship changes
|
||||
function on(eventType: 'screenConnectEvent' | 'screenChangeEvent', callback: Callback<ScreenEvent>): void;
|
||||
function off(eventType: 'screenConnectEvent' | 'screenChangeEvent', callback?: Callback<ScreenEvent>): void;
|
||||
function on(eventType: 'connect' | 'disconnect' | 'change', callback: Callback<number>): void;
|
||||
function off(eventType: 'connect' | 'disconnect' | 'change', callback?: Callback<number>): void;
|
||||
|
||||
/**
|
||||
* make screens as expand-screen
|
||||
@@ -89,14 +89,14 @@ declare namespace screen {
|
||||
|
||||
readonly activeModeIndex: number;
|
||||
|
||||
readonly orientation: Orientation;
|
||||
|
||||
/**
|
||||
* get the rotation of the screen
|
||||
* set the orientation of the screen
|
||||
* @devices tv, phone, tablet, wearable
|
||||
* @since 8
|
||||
*/
|
||||
readonly rotation: Rotation;
|
||||
|
||||
requestRotation(rotation: Rotation): Promise<boolean>;
|
||||
setOrientation(orientation: Orientation): Promise<boolean>;
|
||||
|
||||
setScreenActiveMode(modeIndex: number): Promise<boolean>;
|
||||
}
|
||||
@@ -128,52 +128,15 @@ declare namespace screen {
|
||||
mirrorScreenId: Array<number>;
|
||||
}
|
||||
|
||||
/**
|
||||
* screen connect or disconnect event
|
||||
* @devices tv, phone, tablet, wearable
|
||||
* @since 8
|
||||
*/
|
||||
type ScreenEvent = {
|
||||
screenId: number;
|
||||
type: ScreenConnectEventType;
|
||||
} | {
|
||||
screenId: Array<number>;
|
||||
type: ScreenChangeEventType;
|
||||
}
|
||||
|
||||
enum ScreenConnectEventType {
|
||||
DISCONNECT = 0,
|
||||
CONNECT = 1,
|
||||
}
|
||||
|
||||
enum ScreenChangeEventType {
|
||||
ADD_TO_GROUP = 0,
|
||||
REMOVE_FROM_GROUP = 1,
|
||||
CHANGE_GROUP = 2,
|
||||
}
|
||||
|
||||
/**
|
||||
* rotation degree of screen
|
||||
* @devices tv, phone, tablet, wearable
|
||||
* @since 8
|
||||
*/
|
||||
enum Rotation {
|
||||
/**
|
||||
* 0 degree
|
||||
*/
|
||||
ROTATION_0 = 0,
|
||||
/**
|
||||
* 90 degree
|
||||
*/
|
||||
ROTATION_90 = 1,
|
||||
/**
|
||||
* 180 degree
|
||||
*/
|
||||
ROTATION_180 = 2,
|
||||
/**
|
||||
* 270 degree
|
||||
*/
|
||||
ROTATION_270 = 3,
|
||||
enum Orientation {
|
||||
UNSPECIFIED = 0,
|
||||
VERTICAL = 1,
|
||||
HORIZONTAL = 2,
|
||||
REVERSE_VERTICAL = 3,
|
||||
REVERSE_HORIZONTAL = 4,
|
||||
SENSOR = 5,
|
||||
SENSOR_VERTICAL = 6,
|
||||
SENSOR_HORIZONTAL = 7,
|
||||
}
|
||||
|
||||
interface ScreenModeInfo {
|
||||
|
||||
@@ -43,6 +43,10 @@ void JsScreen::Finalizer(NativeEngine* engine, void* data, void* hint)
|
||||
{
|
||||
WLOGFI("JsScreen::Finalizer is called");
|
||||
auto jsScreen = std::unique_ptr<JsScreen>(static_cast<JsScreen*>(data));
|
||||
if (jsScreen == nullptr) {
|
||||
WLOGFE("jsScreen::Finalizer jsScreen is null");
|
||||
return;
|
||||
}
|
||||
sptr<Screen> screen = jsScreen->screen_;
|
||||
if (screen == nullptr) {
|
||||
WLOGFE("JsScreen::Finalizer screen is null");
|
||||
@@ -57,52 +61,49 @@ void JsScreen::Finalizer(NativeEngine* engine, void* data, void* hint)
|
||||
}
|
||||
}
|
||||
|
||||
NativeValue* JsScreen::RequestRotation(NativeEngine* engine, NativeCallbackInfo* info)
|
||||
NativeValue* JsScreen::SetOrientation(NativeEngine* engine, NativeCallbackInfo* info)
|
||||
{
|
||||
JsScreen* me = CheckParamsAndGetThis<JsScreen>(engine, info);
|
||||
return (me != nullptr) ? me->OnRequestRotation(*engine, *info) : nullptr;
|
||||
return (me != nullptr) ? me->OnSetOrientation(*engine, *info) : nullptr;
|
||||
}
|
||||
|
||||
NativeValue* JsScreen::OnRequestRotation(NativeEngine& engine, NativeCallbackInfo& info)
|
||||
NativeValue* JsScreen::OnSetOrientation(NativeEngine& engine, NativeCallbackInfo& info)
|
||||
{
|
||||
WLOGFI("JsScreen::OnRequestRotation is called");
|
||||
WLOGFI("JsScreen::OnSetOrientation is called");
|
||||
bool paramValidFlag = true;
|
||||
Rotation rotation = Rotation::ROTATION_0;
|
||||
Orientation orientation = Orientation::UNSPECIFIED;
|
||||
if (info.argc != ARGC_ONE) {
|
||||
WLOGFE("OnRequestRotation Params not match, info argc: %{public}zu", info.argc);
|
||||
WLOGFE("OnSetOrientation Params not match, info argc: %{public}zu", info.argc);
|
||||
paramValidFlag = false;
|
||||
} else {
|
||||
if (!ConvertFromJsValue(engine, info.argv[0], rotation)) {
|
||||
if (!ConvertFromJsValue(engine, info.argv[0], orientation)) {
|
||||
paramValidFlag = false;
|
||||
WLOGFE("Failed to convert parameter to rotation");
|
||||
WLOGFE("Failed to convert parameter to orientation");
|
||||
}
|
||||
}
|
||||
|
||||
AsyncTask::CompleteCallback complete =
|
||||
[=](NativeEngine& engine, AsyncTask& task, int32_t status) {
|
||||
if (!paramValidFlag) {
|
||||
WLOGE("JsScreen::OnRequestRotation paramValidFlag error");
|
||||
WLOGE("JsScreen::OnSetOrientation paramValidFlag error");
|
||||
task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(DMError::DM_ERROR_INVALID_PARAM),
|
||||
"JsScreen::OnRequestRotation failed."));
|
||||
"JsScreen::OnSetOrientation failed."));
|
||||
return;
|
||||
}
|
||||
if (rotation != Rotation::ROTATION_0 &&
|
||||
rotation != Rotation::ROTATION_90 &&
|
||||
rotation != Rotation::ROTATION_180 &&
|
||||
rotation != Rotation::ROTATION_270) {
|
||||
WLOGE("Rotation param error! rotation value must from enum Rotation");
|
||||
if (orientation < Orientation::BEGIN || orientation > Orientation::END) {
|
||||
WLOGE("Orientation param error! orientation value must from enum Orientation");
|
||||
task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(DMError::DM_ERROR_INVALID_PARAM),
|
||||
"JsScreen::OnRequestRotation failed."));
|
||||
"JsScreen::OnSetOrientation failed."));
|
||||
return;
|
||||
}
|
||||
|
||||
bool res = screen_->RequestRotation(rotation);
|
||||
bool res = screen_->SetOrientation(orientation);
|
||||
if (res) {
|
||||
task.Resolve(engine, CreateJsValue(engine, true));
|
||||
WLOGFI("JsScreen::OnRequestRotation success");
|
||||
WLOGFI("JsScreen::OnSetOrientation success");
|
||||
} else {
|
||||
task.Resolve(engine, CreateJsError(engine, false, "JsScreen::OnRequestRotation failed."));
|
||||
WLOGFE("JsScreen::OnRequestRotation failed");
|
||||
task.Resolve(engine, CreateJsError(engine, false, "JsScreen::OnSetOrientation failed."));
|
||||
WLOGFE("JsScreen::OnSetOrientation failed");
|
||||
}
|
||||
};
|
||||
NativeValue* lastParam = nullptr;
|
||||
@@ -174,7 +175,7 @@ NativeValue* CreateJsScreenObject(NativeEngine& engine, sptr<Screen>& screen)
|
||||
|
||||
object->SetProperty("id", CreateJsValue(engine, static_cast<uint32_t>(screen->GetId())));
|
||||
object->SetProperty("parent", CreateJsValue(engine, static_cast<uint32_t>(screen->GetParentId())));
|
||||
object->SetProperty("rotation", CreateJsValue(engine, screen->GetRotation()));
|
||||
object->SetProperty("orientation", CreateJsValue(engine, screen->GetOrientation()));
|
||||
object->SetProperty("activeModeIndex", CreateJsValue(engine, screen->GetModeId()));
|
||||
object->SetProperty("supportedModeInfo", CreateJsScreenModeArrayObject(engine, screen->GetSupportedModes()));
|
||||
|
||||
@@ -184,7 +185,7 @@ NativeValue* CreateJsScreenObject(NativeEngine& engine, sptr<Screen>& screen)
|
||||
std::lock_guard<std::recursive_mutex> lock(g_mutex);
|
||||
g_JsScreenMap[screenId] = JsScreenRef;
|
||||
BindNativeFunction(engine, *object, "setScreenActiveMode", JsScreen::SetScreenActiveMode);
|
||||
BindNativeFunction(engine, *object, "requestRotation", JsScreen::RequestRotation);
|
||||
BindNativeFunction(engine, *object, "setOrientation", JsScreen::SetOrientation);
|
||||
return objValue;
|
||||
}
|
||||
|
||||
|
||||
@@ -31,11 +31,11 @@ public:
|
||||
~JsScreen();
|
||||
static void Finalizer(NativeEngine* engine, void* data, void* hint);
|
||||
static NativeValue* SetScreenActiveMode(NativeEngine* engine, NativeCallbackInfo* info);
|
||||
static NativeValue* RequestRotation(NativeEngine* engine, NativeCallbackInfo* info);
|
||||
static NativeValue* SetOrientation(NativeEngine* engine, NativeCallbackInfo* info);
|
||||
|
||||
private:
|
||||
sptr<Screen> screen_ = nullptr;
|
||||
NativeValue* OnRequestRotation(NativeEngine& engine, NativeCallbackInfo& info);
|
||||
NativeValue* OnSetOrientation(NativeEngine& engine, NativeCallbackInfo& info);
|
||||
NativeValue* OnSetScreenActiveMode(NativeEngine& engine, NativeCallbackInfo& info);
|
||||
};
|
||||
} // namespace Rosen
|
||||
|
||||
@@ -80,16 +80,18 @@ void JsScreenListener::OnConnect(ScreenId id)
|
||||
WLOGFE("JsScreenListener::OnConnect not register!");
|
||||
return;
|
||||
}
|
||||
NativeValue* propertyValue = engine_->CreateObject();
|
||||
NativeObject* object = ConvertNativeValueTo<NativeObject>(propertyValue);
|
||||
if (object == nullptr) {
|
||||
WLOGFE("Failed to convert prop to jsObject");
|
||||
return;
|
||||
}
|
||||
object->SetProperty("screenId", CreateJsValue(*engine_, static_cast<uint32_t>(id)));
|
||||
object->SetProperty("type", CreateJsValue(*engine_, SCREEN_CONNECT_TYPE));
|
||||
NativeValue* argv[] = {propertyValue};
|
||||
CallJsMethod("screenConnectEvent", argv, ArraySize(argv));
|
||||
|
||||
std::unique_ptr<AsyncTask::CompleteCallback> complete = std::make_unique<AsyncTask::CompleteCallback> (
|
||||
[=] (NativeEngine &engine, AsyncTask &task, int32_t status) {
|
||||
NativeValue* argv[] = {CreateJsValue(*engine_, static_cast<uint32_t>(id))};
|
||||
CallJsMethod("connect", argv, ArraySize(argv));
|
||||
}
|
||||
);
|
||||
|
||||
NativeReference* callback = nullptr;
|
||||
std::unique_ptr<AsyncTask::ExecuteCallback> execute = nullptr;
|
||||
AsyncTask::Schedule(*engine_, std::make_unique<AsyncTask>(
|
||||
callback, std::move(execute), std::move(complete)));
|
||||
}
|
||||
|
||||
void JsScreenListener::OnDisconnect(ScreenId id)
|
||||
@@ -100,19 +102,21 @@ void JsScreenListener::OnDisconnect(ScreenId id)
|
||||
WLOGFE("JsScreenListener::OnDisconnect not register!");
|
||||
return;
|
||||
}
|
||||
NativeValue* propertyValue = engine_->CreateObject();
|
||||
NativeObject* object = ConvertNativeValueTo<NativeObject>(propertyValue);
|
||||
if (object == nullptr) {
|
||||
WLOGFE("Failed to convert prop to jsObject");
|
||||
return;
|
||||
}
|
||||
object->SetProperty("screenId", CreateJsValue(*engine_, static_cast<uint32_t>(id)));
|
||||
object->SetProperty("type", CreateJsValue(*engine_, SCREEN_DISCONNECT_TYPE));
|
||||
NativeValue* argv[] = {propertyValue};
|
||||
CallJsMethod("screenConnectEvent", argv, ArraySize(argv));
|
||||
|
||||
std::unique_ptr<AsyncTask::CompleteCallback> complete = std::make_unique<AsyncTask::CompleteCallback> (
|
||||
[=] (NativeEngine &engine, AsyncTask &task, int32_t status) {
|
||||
NativeValue* argv[] = {CreateJsValue(*engine_, static_cast<uint32_t>(id))};
|
||||
CallJsMethod("disconnect", argv, ArraySize(argv));
|
||||
}
|
||||
);
|
||||
|
||||
NativeReference* callback = nullptr;
|
||||
std::unique_ptr<AsyncTask::ExecuteCallback> execute = nullptr;
|
||||
AsyncTask::Schedule(*engine_, std::make_unique<AsyncTask>(
|
||||
callback, std::move(execute), std::move(complete)));
|
||||
}
|
||||
|
||||
void JsScreenListener::OnChange(const std::vector<ScreenId> &vector, ScreenChangeEvent event)
|
||||
void JsScreenListener::OnChange(ScreenId id)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mtx_);
|
||||
WLOGFI("JsScreenListener::OnChange is called");
|
||||
@@ -120,16 +124,18 @@ void JsScreenListener::OnChange(const std::vector<ScreenId> &vector, ScreenChang
|
||||
WLOGFE("JsScreenListener::OnChange not register!");
|
||||
return;
|
||||
}
|
||||
NativeValue* propertyValue = engine_->CreateObject();
|
||||
NativeObject* object = ConvertNativeValueTo<NativeObject>(propertyValue);
|
||||
if (object == nullptr) {
|
||||
WLOGFE("Failed to convert prop to jsObject");
|
||||
return;
|
||||
}
|
||||
object->SetProperty("screenId", CreateScreenIdArray(*engine_, vector));
|
||||
object->SetProperty("type", CreateJsValue(*engine_, event));
|
||||
NativeValue* argv[] = {propertyValue};
|
||||
CallJsMethod("screenChangeEvent", argv, ArraySize(argv));
|
||||
|
||||
std::unique_ptr<AsyncTask::CompleteCallback> complete = std::make_unique<AsyncTask::CompleteCallback> (
|
||||
[=] (NativeEngine &engine, AsyncTask &task, int32_t status) {
|
||||
NativeValue* argv[] = {CreateJsValue(*engine_, static_cast<uint32_t>(id))};
|
||||
CallJsMethod("change", argv, ArraySize(argv));
|
||||
}
|
||||
);
|
||||
|
||||
NativeReference* callback = nullptr;
|
||||
std::unique_ptr<AsyncTask::ExecuteCallback> execute = nullptr;
|
||||
AsyncTask::Schedule(*engine_, std::make_unique<AsyncTask>(
|
||||
callback, std::move(execute), std::move(complete)));
|
||||
}
|
||||
|
||||
NativeValue* JsScreenListener::CreateScreenIdArray(NativeEngine& engine, const std::vector<ScreenId>& data)
|
||||
|
||||
@@ -33,7 +33,7 @@ public:
|
||||
void RemoveCallback(NativeValue* jsListenerObject);
|
||||
void OnConnect(ScreenId id) override;
|
||||
void OnDisconnect(ScreenId id) override;
|
||||
void OnChange(const std::vector<ScreenId> &vector, ScreenChangeEvent event) override;
|
||||
void OnChange(ScreenId id) override;
|
||||
|
||||
private:
|
||||
void CallJsMethod(const char* methodName, NativeValue* const* argv = nullptr, size_t argc = 0);
|
||||
|
||||
@@ -12,10 +12,11 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "js_screen_manager.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include <new>
|
||||
#include <ability.h>
|
||||
#include "js_runtime_utils.h"
|
||||
#include "js_screen_listener.h"
|
||||
@@ -138,8 +139,12 @@ void RegisterScreenListenerWithType(NativeEngine& engine, const std::string& typ
|
||||
}
|
||||
std::unique_ptr<NativeReference> callbackRef;
|
||||
callbackRef.reset(engine.CreateReference(value, 1));
|
||||
sptr<JsScreenListener> screenListener = new JsScreenListener(&engine);
|
||||
if (type == "screenConnectEvent" || type == "screenChangeEvent") {
|
||||
sptr<JsScreenListener> screenListener = new(std::nothrow) JsScreenListener(&engine);
|
||||
if (screenListener == nullptr) {
|
||||
WLOGFE("screenListener is nullptr");
|
||||
return;
|
||||
}
|
||||
if (type == "connect" || type == "disconnect" || type == "change") {
|
||||
SingletonContainer::Get<ScreenManager>().RegisterScreenListener(screenListener);
|
||||
WLOGFI("JsScreenManager::RegisterScreenListenerWithType success");
|
||||
} else {
|
||||
@@ -209,6 +214,10 @@ NativeValue* OnRegisterScreenMangerCallback(NativeEngine& engine, NativeCallback
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
NativeValue* value = info.argv[INDEX_ONE];
|
||||
if (value == nullptr) {
|
||||
WLOGFI("JsScreenManager::OnRegisterScreenMangerCallback info->argv[1] is nullptr");
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
if (!value->IsCallable()) {
|
||||
WLOGFI("JsScreenManager::OnRegisterScreenMangerCallback info->argv[1] is not callable");
|
||||
return engine.CreateUndefined();
|
||||
@@ -235,6 +244,10 @@ NativeValue* OnUnregisterScreenManagerCallback(NativeEngine& engine, NativeCallb
|
||||
UnregisterAllScreenListenerWithType(cbType);
|
||||
} else {
|
||||
NativeValue* value = info.argv[INDEX_ONE];
|
||||
if (value == nullptr) {
|
||||
WLOGFI("JsScreenManager::OnUnregisterScreenManagerCallback info->argv[1] is nullptr");
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
if (!value->IsCallable()) {
|
||||
WLOGFI("JsScreenManager::OnUnregisterScreenManagerCallback info->argv[1] is not callable");
|
||||
return engine.CreateUndefined();
|
||||
@@ -308,7 +321,7 @@ NativeValue* OnMakeExpand(NativeEngine& engine, NativeCallbackInfo& info)
|
||||
}
|
||||
uint32_t size = array->GetLength();
|
||||
std::vector<ExpandOption> options;
|
||||
for (auto i = 0; i < size; ++i) {
|
||||
for (uint32_t i = 0; i < size; ++i) {
|
||||
NativeObject* object = ConvertNativeValueTo<NativeObject>(array->GetElement(i));
|
||||
ExpandOption expandOption;
|
||||
int32_t res = GetExpandOptionFromJs(engine, object, expandOption);
|
||||
|
||||
@@ -605,10 +605,14 @@ NativeValue* JsWindowManager::OnSetWindowLayoutMode(NativeEngine& engine, Native
|
||||
task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(errCode), "Invalidate params."));
|
||||
return;
|
||||
}
|
||||
SingletonContainer::Get<WindowManager>().SetWindowLayoutMode(winLayoutMode,
|
||||
WMError ret = SingletonContainer::Get<WindowManager>().SetWindowLayoutMode(winLayoutMode,
|
||||
static_cast<uint64_t>(displayId));
|
||||
task.Resolve(engine, engine.CreateUndefined());
|
||||
WLOGFI("JsWindowManager::OnSetWindowLayoutMode success");
|
||||
if (ret == WMError::WM_OK) {
|
||||
task.Resolve(engine, engine.CreateUndefined());
|
||||
WLOGFI("JsWindowManager::OnSetWindowLayoutMode success");
|
||||
} else {
|
||||
task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(ret), "do failed"));
|
||||
}
|
||||
};
|
||||
NativeValue* lastParam = (info.argc < ARGC_THREE) ? nullptr :
|
||||
(info.argv[INDEX_TWO]->TypeOf() == NATIVE_FUNCTION ? info.argv[INDEX_TWO] : nullptr);
|
||||
|
||||
@@ -49,6 +49,10 @@ void JsWindow::Finalizer(NativeEngine* engine, void* data, void* hint)
|
||||
{
|
||||
WLOGFI("JsWindow::Finalizer is called");
|
||||
auto jsWin = std::unique_ptr<JsWindow>(static_cast<JsWindow*>(data));
|
||||
if (jsWin == nullptr) {
|
||||
WLOGFE("JsWindow::Finalizer JsWindow is null");
|
||||
return;
|
||||
}
|
||||
std::string windowName = jsWin->GetWindowName();
|
||||
WLOGFI("JsWindow::Finalizer windowName : %{public}s", windowName.c_str());
|
||||
std::lock_guard<std::recursive_mutex> lock(g_mutex);
|
||||
|
||||
@@ -78,7 +78,7 @@ static std::string GetHexColor(uint32_t color)
|
||||
std::string temp;
|
||||
ioss << std::setiosflags(std::ios::uppercase) << std::hex << color;
|
||||
ioss >> temp;
|
||||
int count = RGBA_LENGTH - temp.length();
|
||||
int count = RGBA_LENGTH - static_cast<int>(temp.length());
|
||||
std::string tmpColor(count, '0');
|
||||
tmpColor += temp;
|
||||
std::string finalColor("#");
|
||||
|
||||
@@ -43,6 +43,32 @@ ohos_executable("snapshot_display") {
|
||||
subsystem_name = "window"
|
||||
}
|
||||
|
||||
ohos_executable("snapshot_virtual_screen") {
|
||||
install_enable = false
|
||||
sources = [
|
||||
"snapshot_utils.cpp",
|
||||
"snapshot_virtual_screen.cpp",
|
||||
]
|
||||
|
||||
configs = [ ":snapshot_config" ]
|
||||
|
||||
deps = [
|
||||
"//foundation/graphic/standard/rosen/modules/render_service_client:librender_service_client",
|
||||
"//foundation/windowmanager/dm:libdm",
|
||||
"//foundation/windowmanager/utils:libwmutil",
|
||||
"//foundation/windowmanager/wm:libwm",
|
||||
"//third_party/libpng:libpng", # png
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"multimedia_image_standard:image_native",
|
||||
"utils_base:utils",
|
||||
]
|
||||
|
||||
part_name = "window_manager"
|
||||
subsystem_name = "window"
|
||||
}
|
||||
|
||||
## Build snapshot }}}
|
||||
|
||||
group("test") {
|
||||
|
||||
@@ -24,7 +24,7 @@ using namespace OHOS::Rosen;
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
CmdArgments cmdArgments;
|
||||
cmdArgments.fileName = "/data/snapshot_display_1.png";
|
||||
cmdArgments.fileName = "";
|
||||
|
||||
if (!SnapShotUtils::ProcessArgs(argc, argv, cmdArgments)) {
|
||||
return 0;
|
||||
|
||||
@@ -16,7 +16,9 @@
|
||||
#include "snapshot_utils.h"
|
||||
|
||||
#include <cstdio>
|
||||
#include <sys/time.h>
|
||||
#include <getopt.h>
|
||||
#include <securec.h>
|
||||
#include <png.h>
|
||||
#include "wm_trace.h"
|
||||
|
||||
@@ -26,8 +28,11 @@ using namespace OHOS::Rosen;
|
||||
namespace OHOS {
|
||||
constexpr int BITMAP_DEPTH = 8;
|
||||
constexpr int BPP = 4;
|
||||
constexpr int MAX_TIME_STR_LEN = 40;
|
||||
constexpr int YEAR_SINCE = 1900;
|
||||
|
||||
const char *VALID_SNAPSHOT_PATH = "/data";
|
||||
const char *DEFAULT_SNAPSHOT_PREFIX = "/snapshot";
|
||||
const char *VALID_SNAPSHOT_SUFFIX = ".png";
|
||||
|
||||
void SnapShotUtils::PrintUsage(const std::string &cmdLine)
|
||||
@@ -35,6 +40,28 @@ void SnapShotUtils::PrintUsage(const std::string &cmdLine)
|
||||
printf("usage: %s [-i displayId] [-f output_file] [-w width] [-h height] [-m]\n", cmdLine.c_str());
|
||||
}
|
||||
|
||||
std::string SnapShotUtils::GenerateFileName(int offset)
|
||||
{
|
||||
timeval tv;
|
||||
std::string fileName = VALID_SNAPSHOT_PATH;
|
||||
char timeStr[MAX_TIME_STR_LEN] = { 0 };
|
||||
|
||||
fileName += DEFAULT_SNAPSHOT_PREFIX;
|
||||
if (gettimeofday(&tv, nullptr) == 0) {
|
||||
tv.tv_sec += offset; // add offset second
|
||||
struct tm *tmVal = localtime(&tv.tv_sec);
|
||||
if (tmVal != nullptr) {
|
||||
snprintf_s(timeStr, sizeof(timeStr), sizeof(timeStr) - 1,
|
||||
"_%04d-%02d-%02d_%02d-%02d-%02d",
|
||||
tmVal->tm_year + YEAR_SINCE, tmVal->tm_mon + 1, tmVal->tm_mday,
|
||||
tmVal->tm_hour, tmVal->tm_min, tmVal->tm_sec);
|
||||
fileName += timeStr;
|
||||
}
|
||||
}
|
||||
fileName += VALID_SNAPSHOT_SUFFIX;
|
||||
return fileName;
|
||||
}
|
||||
|
||||
bool SnapShotUtils::CheckFileNameValid(const std::string &fileName)
|
||||
{
|
||||
WM_SCOPED_TRACE("snapshot:CheckFileNameValid(%s)", fileName.c_str());
|
||||
@@ -237,6 +264,11 @@ bool SnapShotUtils::ProcessArgs(int argc, char * const argv[], CmdArgments &cmdA
|
||||
return false;
|
||||
}
|
||||
|
||||
if (cmdArgments.fileName == "") {
|
||||
cmdArgments.fileName = GenerateFileName();
|
||||
printf("process: set filename to %s\n", cmdArgments.fileName.c_str());
|
||||
}
|
||||
|
||||
// check fileName
|
||||
if (!SnapShotUtils::CheckFileNameValid(cmdArgments.fileName)) {
|
||||
printf("error: filename %s invalid!\n", cmdArgments.fileName.c_str());
|
||||
|
||||
@@ -47,6 +47,7 @@ public:
|
||||
|
||||
static void PrintUsage(const std::string &cmdLine);
|
||||
static bool CheckFileNameValid(const std::string &fileName);
|
||||
static std::string GenerateFileName(int offset = 0);
|
||||
static bool CheckWidthAndHeightValid(const CmdArgments& cmdArgments);
|
||||
static bool WriteToPng(const std::string &fileName, const WriteToPngParam ¶m);
|
||||
static bool WriteToPngWithPixelMap(const std::string &fileName, Media::PixelMap &pixelMap);
|
||||
|
||||
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT 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 <string>
|
||||
#include <unistd.h>
|
||||
#include <ctime>
|
||||
|
||||
#include "snapshot_utils.h"
|
||||
#include "screen_manager.h"
|
||||
#include "surface_reader.h"
|
||||
#include "surface_reader_handler_impl.h"
|
||||
|
||||
using namespace OHOS;
|
||||
using namespace OHOS::Rosen;
|
||||
using namespace OHOS::Media;
|
||||
|
||||
namespace {
|
||||
const int SLEEP_US = 10 * 1000; // 10ms
|
||||
const int MAX_SNAPSHOT_COUNT = 10;
|
||||
const int MAX_WAIT_COUNT = 200;
|
||||
const float DEFAULT_DENSITY = 2.0;
|
||||
const std::string FILE_NAME = "/data/snapshot_virtual_screen";
|
||||
}
|
||||
|
||||
static VirtualScreenOption InitOption(ScreenId mainId, SurfaceReader& surfaceReader)
|
||||
{
|
||||
auto defaultScreen = ScreenManager::GetInstance().GetScreenById(mainId);
|
||||
VirtualScreenOption option = {
|
||||
.name_ = "virtualScreen",
|
||||
.width_ = defaultScreen->GetWidth(),
|
||||
.height_ = defaultScreen->GetHeight(),
|
||||
.density_ = DEFAULT_DENSITY,
|
||||
.surface_ = surfaceReader.GetSurface(),
|
||||
.flags_ = 0,
|
||||
.isForShot_ = true,
|
||||
};
|
||||
return option;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
SurfaceReader surfaceReader;
|
||||
sptr<SurfaceReaderHandlerImpl> surfaceReaderHandler = new SurfaceReaderHandlerImpl();
|
||||
if (!surfaceReader.Init()) {
|
||||
printf("surfaceReader init failed!\n");
|
||||
return 0;
|
||||
}
|
||||
surfaceReader.SetHandler(surfaceReaderHandler);
|
||||
ScreenId mainId = static_cast<ScreenId>(DisplayManager::GetInstance().GetDefaultDisplayId());
|
||||
VirtualScreenOption option = InitOption(mainId, surfaceReader);
|
||||
ScreenId virtualScreenId = ScreenManager::GetInstance().CreateVirtualScreen(option);
|
||||
std::vector<ScreenId> mirrorIds;
|
||||
mirrorIds.push_back(virtualScreenId);
|
||||
ScreenManager::GetInstance().MakeMirror(mainId, mirrorIds);
|
||||
int fileIndex = 1;
|
||||
auto startTime = time(nullptr);
|
||||
while (time(nullptr) - startTime < MAX_SNAPSHOT_COUNT) {
|
||||
int waitCount = 0;
|
||||
while (!surfaceReaderHandler->IsImageOk()) {
|
||||
waitCount++;
|
||||
if (waitCount >= MAX_WAIT_COUNT) {
|
||||
printf("wait image overtime\n");
|
||||
break;
|
||||
}
|
||||
usleep(SLEEP_US);
|
||||
}
|
||||
if (waitCount >= MAX_WAIT_COUNT) {
|
||||
continue;
|
||||
}
|
||||
auto pixelMap = surfaceReaderHandler->GetPixelMap();
|
||||
bool ret = SnapShotUtils::WriteToPngWithPixelMap(FILE_NAME + std::to_string(fileIndex) + ".png", *pixelMap);
|
||||
if (ret) {
|
||||
printf("snapshot %" PRIu64 ", write to %s as png\n",
|
||||
mainId, (FILE_NAME + std::to_string(fileIndex)).c_str());
|
||||
} else {
|
||||
printf("snapshot %" PRIu64 " write to %s failed!\n",
|
||||
mainId, (FILE_NAME + std::to_string(fileIndex)).c_str());
|
||||
}
|
||||
surfaceReaderHandler->ResetFlag();
|
||||
fileIndex++;
|
||||
}
|
||||
ScreenManager::GetInstance().DestroyVirtualScreen(virtualScreenId);
|
||||
printf("DestroyVirtualScreen %" PRIu64 "\n", virtualScreenId);
|
||||
return 0;
|
||||
}
|
||||
@@ -34,6 +34,8 @@ ohos_shared_library("libwmutil") {
|
||||
"src/screen_group_info.cpp",
|
||||
"src/screen_info.cpp",
|
||||
"src/singleton_container.cpp",
|
||||
"src/surface_reader.cpp",
|
||||
"src/surface_reader_handler_impl.cpp",
|
||||
"src/window_property.cpp",
|
||||
"src/wm_trace.cpp",
|
||||
]
|
||||
@@ -49,6 +51,7 @@ ohos_shared_library("libwmutil") {
|
||||
"graphic_standard:surface",
|
||||
"hilog_native:libhilog",
|
||||
"ipc:ipc_core",
|
||||
"multimedia_image_standard:image_native",
|
||||
"utils_base:utils",
|
||||
]
|
||||
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed 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 OHOS_ROSEN_CLASS_VAR_DEFINATION_H
|
||||
#define OHOS_ROSEN_CLASS_VAR_DEFINATION_H
|
||||
namespace OHOS::Rosen {
|
||||
#define DEFINE_VAR(type, memberName) \
|
||||
private: \
|
||||
type memberName##_;
|
||||
|
||||
#define DEFINE_VAR_DEFAULT(type, memberName, defaultValue) \
|
||||
private: \
|
||||
type memberName##_ {defaultValue};
|
||||
|
||||
#define DEFINE_FUNC_GET(type, funcName, memberName) \
|
||||
public: \
|
||||
type Get##funcName() const \
|
||||
{ \
|
||||
return memberName##_; \
|
||||
}
|
||||
|
||||
#define DEFINE_FUNC_SET(type, funcName, memberName) \
|
||||
public: \
|
||||
void Set##funcName(type value) \
|
||||
{ \
|
||||
memberName##_ = value; \
|
||||
}
|
||||
|
||||
#define DEFINE_VAR_FUNC_GET(type, funcName, memberName) \
|
||||
DEFINE_VAR(type, memberName) \
|
||||
DEFINE_FUNC_GET(type, funcName, memberName)
|
||||
|
||||
#define DEFINE_VAR_DEFAULT_FUNC_GET(type, funcName, memberName, defaultValue) \
|
||||
DEFINE_VAR_DEFAULT(type, memberName, defaultValue) \
|
||||
DEFINE_FUNC_GET(type, funcName, memberName)
|
||||
|
||||
#define DEFINE_VAR_FUNC_GET_SET(type, funcName, memberName) \
|
||||
DEFINE_VAR(type, memberName) \
|
||||
DEFINE_FUNC_GET(type, funcName, memberName) \
|
||||
DEFINE_FUNC_SET(type, funcName, memberName)
|
||||
|
||||
#define DEFINE_VAR_DEFAULT_FUNC_GET_SET(type, funcName, memberName, defaultValue) \
|
||||
DEFINE_VAR_DEFAULT(type, memberName, defaultValue) \
|
||||
DEFINE_FUNC_GET(type, funcName, memberName) \
|
||||
DEFINE_FUNC_SET(type, funcName, memberName)
|
||||
} // namespace OHOS::Rosen
|
||||
#endif // OHOS_ROSEN_CLASS_VAR_DEFINATION_H
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed 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 OHOS_ROSEN_CLASS_VAR_DEFINITION_H
|
||||
#define OHOS_ROSEN_CLASS_VAR_DEFINITION_H
|
||||
namespace OHOS::Rosen {
|
||||
#define DEFINE_VAR(type, memberName) \
|
||||
private: \
|
||||
type memberName##_;
|
||||
|
||||
#define DEFINE_VAR_DEFAULT(type, memberName, defaultValue) \
|
||||
private: \
|
||||
type memberName##_ {defaultValue};
|
||||
|
||||
#define DEFINE_FUNC_GET(type, funcName, memberName) \
|
||||
public: \
|
||||
type Get##funcName() const \
|
||||
{ \
|
||||
return memberName##_; \
|
||||
}
|
||||
|
||||
#define DEFINE_FUNC_SET(type, funcName, memberName) \
|
||||
public: \
|
||||
void Set##funcName(type value) \
|
||||
{ \
|
||||
memberName##_ = value; \
|
||||
}
|
||||
|
||||
#define DEFINE_VAR_FUNC_GET(type, funcName, memberName) \
|
||||
DEFINE_VAR(type, memberName) \
|
||||
DEFINE_FUNC_GET(type, funcName, memberName)
|
||||
|
||||
#define DEFINE_VAR_DEFAULT_FUNC_GET(type, funcName, memberName, defaultValue) \
|
||||
DEFINE_VAR_DEFAULT(type, memberName, defaultValue) \
|
||||
DEFINE_FUNC_GET(type, funcName, memberName)
|
||||
|
||||
#define DEFINE_VAR_FUNC_GET_SET(type, funcName, memberName) \
|
||||
DEFINE_VAR(type, memberName) \
|
||||
DEFINE_FUNC_GET(type, funcName, memberName) \
|
||||
DEFINE_FUNC_SET(type, funcName, memberName)
|
||||
|
||||
#define DEFINE_VAR_DEFAULT_FUNC_GET_SET(type, funcName, memberName, defaultValue) \
|
||||
DEFINE_VAR_DEFAULT(type, memberName, defaultValue) \
|
||||
DEFINE_FUNC_GET(type, funcName, memberName) \
|
||||
DEFINE_FUNC_SET(type, funcName, memberName)
|
||||
} // namespace OHOS::Rosen
|
||||
#endif // OHOS_ROSEN_CLASS_VAR_DEFINITION_H
|
||||
@@ -18,29 +18,35 @@
|
||||
|
||||
#include <parcel.h>
|
||||
|
||||
#include "class_var_definition.h"
|
||||
#include "display.h"
|
||||
#include "dm_common.h"
|
||||
|
||||
namespace OHOS::Rosen {
|
||||
class DisplayInfo : public Parcelable {
|
||||
friend class AbstractDisplay;
|
||||
public:
|
||||
DisplayInfo() = default;
|
||||
~DisplayInfo() = default;
|
||||
|
||||
void Update(DisplayInfo* info);
|
||||
DisplayInfo(const DisplayInfo&) = delete;
|
||||
DisplayInfo(DisplayInfo&&) = delete;
|
||||
DisplayInfo& operator=(const DisplayInfo&) = delete;
|
||||
DisplayInfo& operator=(DisplayInfo&&) = delete;
|
||||
|
||||
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 };
|
||||
ScreenId screenId_ { SCREEN_ID_INVALID };
|
||||
float xDpi_ { 0.0 };
|
||||
float yDpi_ { 0.0 };
|
||||
Rotation rotation_ { Rotation::ROTATION_0 };
|
||||
DEFINE_VAR_DEFAULT_FUNC_GET(DisplayId, DisplayId, id, DISPLAY_ID_INVALD);
|
||||
DEFINE_VAR_DEFAULT_FUNC_GET(DisplayType, DisplayType, type, DisplayType::DEFAULT);
|
||||
DEFINE_VAR_DEFAULT_FUNC_GET(int32_t, Width, width, 0);
|
||||
DEFINE_VAR_DEFAULT_FUNC_GET(int32_t, Height, height, 0);
|
||||
DEFINE_VAR_DEFAULT_FUNC_GET(uint32_t, FreshRate, freshRate, 0);
|
||||
DEFINE_VAR_DEFAULT_FUNC_GET(ScreenId, ScreenId, screenId, SCREEN_ID_INVALID);
|
||||
DEFINE_VAR_DEFAULT_FUNC_GET(float, XDpi, xDpi, 0.0f);
|
||||
DEFINE_VAR_DEFAULT_FUNC_GET(float, YDpi, yDpi, 0.0f);
|
||||
DEFINE_VAR_DEFAULT_FUNC_GET(Rotation, Rotation, rotation, Rotation::ROTATION_0);
|
||||
DEFINE_VAR_DEFAULT_FUNC_GET(Orientation, Orientation, orientation, Orientation::UNSPECIFIED);
|
||||
protected:
|
||||
DisplayInfo() = default;
|
||||
};
|
||||
} // namespace OHOS::Rosen
|
||||
#endif // FOUNDATION_DMSERVER_DISPLAY_INFO_H
|
||||
@@ -50,5 +50,37 @@ private:
|
||||
std::condition_variable conditionVariable_;
|
||||
std::mutex mutex_;
|
||||
};
|
||||
|
||||
template<class T>
|
||||
class RunnableFuture : public Future<T> {
|
||||
public:
|
||||
void SetValue(T res)
|
||||
{
|
||||
Future<T>::FutureCall(res);
|
||||
}
|
||||
void Reset()
|
||||
{
|
||||
flag_ = false;
|
||||
}
|
||||
protected:
|
||||
void Call(T res) override
|
||||
{
|
||||
if (!flag_) {
|
||||
flag_ = true;
|
||||
result_ = res;
|
||||
}
|
||||
}
|
||||
bool IsReady() override
|
||||
{
|
||||
return flag_;
|
||||
}
|
||||
T FetchResult() override
|
||||
{
|
||||
return result_;
|
||||
}
|
||||
private:
|
||||
bool flag_ {false};
|
||||
T result_;
|
||||
};
|
||||
} // namespace OHOS::Rosen
|
||||
#endif // OHOS_WM_INCLUDE_FUTURE_H
|
||||
|
||||
@@ -23,20 +23,23 @@
|
||||
|
||||
namespace OHOS::Rosen {
|
||||
class ScreenGroupInfo : public ScreenInfo {
|
||||
friend class AbstractScreenGroup;
|
||||
public:
|
||||
ScreenGroupInfo() = default;
|
||||
~ScreenGroupInfo() = default;
|
||||
|
||||
void Update(sptr<ScreenGroupInfo> info);
|
||||
ScreenGroupInfo(const ScreenGroupInfo&) = delete;
|
||||
ScreenGroupInfo(ScreenGroupInfo&&) = delete;
|
||||
ScreenGroupInfo& operator=(const ScreenGroupInfo&) = delete;
|
||||
ScreenGroupInfo& operator=(ScreenGroupInfo&&) = delete;
|
||||
|
||||
virtual bool Marshalling(Parcel& parcel) const override;
|
||||
static ScreenGroupInfo* Unmarshalling(Parcel& parcel);
|
||||
|
||||
std::vector<ScreenId> children_;
|
||||
std::vector<Point> position_;
|
||||
ScreenCombination combination_ { ScreenCombination::SCREEN_ALONE };
|
||||
protected:
|
||||
ScreenGroupInfo* InnerUnmarshalling(Parcel& parcel);
|
||||
DEFINE_VAR_FUNC_GET(std::vector<ScreenId>, Children, children);
|
||||
DEFINE_VAR_FUNC_GET(std::vector<Point>, Position, position);
|
||||
DEFINE_VAR_DEFAULT_FUNC_GET(ScreenCombination, Combination, combination, ScreenCombination::SCREEN_ALONE);
|
||||
private:
|
||||
ScreenGroupInfo() = default;
|
||||
bool InnerUnmarshalling(Parcel& parcel);
|
||||
};
|
||||
} // namespace OHOS::Rosen
|
||||
#endif // FOUNDATION_DMSERVER_SCREEN_GROUP_INFO_H
|
||||
+25
-13
@@ -18,30 +18,42 @@
|
||||
|
||||
#include <parcel.h>
|
||||
|
||||
#include "class_var_definition.h"
|
||||
#include "screen.h"
|
||||
|
||||
namespace OHOS::Rosen {
|
||||
enum class ScreenType : uint32_t {
|
||||
UNDEFINE,
|
||||
REAL,
|
||||
VIRTUAL
|
||||
};
|
||||
class ScreenInfo : public Parcelable {
|
||||
friend class AbstractScreen;
|
||||
public:
|
||||
ScreenInfo() = default;
|
||||
~ScreenInfo() = default;
|
||||
|
||||
void Update(sptr<ScreenInfo> info);
|
||||
ScreenInfo(const ScreenInfo&) = delete;
|
||||
ScreenInfo(ScreenInfo&&) = delete;
|
||||
ScreenInfo& operator=(const ScreenInfo&) = delete;
|
||||
ScreenInfo& operator= (ScreenInfo&&) = delete;
|
||||
|
||||
virtual bool Marshalling(Parcel& parcel) const override;
|
||||
static ScreenInfo* Unmarshalling(Parcel& parcel);
|
||||
|
||||
ScreenId id_ { SCREEN_ID_INVALID };
|
||||
uint32_t virtualWidth_ { 0 };
|
||||
uint32_t virtualHeight_ { 0 };
|
||||
float virtualPixelRatio_ { 0.0 };
|
||||
ScreenId parent_ { 0 };
|
||||
bool canHasChild_ { false };
|
||||
Rotation rotation_ { Rotation::ROTATION_0 };
|
||||
uint32_t modeId_ { 0 };
|
||||
std::vector<sptr<SupportedScreenModes>> modes_ {};
|
||||
DEFINE_VAR_FUNC_GET(std::string, Name, name);
|
||||
DEFINE_VAR_DEFAULT_FUNC_GET(ScreenId, ScreenId, id, SCREEN_ID_INVALID);
|
||||
DEFINE_VAR_DEFAULT_FUNC_GET(uint32_t, VirtualWidth, virtualWidth, 0);
|
||||
DEFINE_VAR_DEFAULT_FUNC_GET(uint32_t, VirtualHeight, virtualHeight, 0);
|
||||
DEFINE_VAR_DEFAULT_FUNC_GET(float, VirtualPixelRatio, virtualPixelRatio, 0.0f);
|
||||
DEFINE_VAR_DEFAULT_FUNC_GET(ScreenId, ParentId, parent, 0);
|
||||
DEFINE_VAR_DEFAULT_FUNC_GET(bool, CanHasChild, canHasChild, false);
|
||||
DEFINE_VAR_DEFAULT_FUNC_GET(Rotation, Rotation, rotation, Rotation::ROTATION_0);
|
||||
DEFINE_VAR_DEFAULT_FUNC_GET(Orientation, Orientation, orientation, Orientation::UNSPECIFIED);
|
||||
DEFINE_VAR_DEFAULT_FUNC_GET(ScreenType, Type, type, ScreenType::REAL);
|
||||
DEFINE_VAR_DEFAULT_FUNC_GET_SET(uint32_t, ModeId, modeId, 0);
|
||||
DEFINE_VAR_FUNC_GET(std::vector<sptr<SupportedScreenModes>>, Modes, modes);
|
||||
protected:
|
||||
ScreenInfo* InnerUnmarshalling(Parcel& parcel);
|
||||
ScreenInfo() = default;
|
||||
bool InnerUnmarshalling(Parcel& parcel);
|
||||
};
|
||||
} // namespace OHOS::Rosen
|
||||
#endif // FOUNDATION_DMSERVER_DISPLAY_INFO_H
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT 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 SURFACE_READER_H
|
||||
#define SURFACE_READER_H
|
||||
|
||||
#include "refbase.h"
|
||||
|
||||
#include <surface.h>
|
||||
|
||||
#include "surface_reader_handler.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Rosen {
|
||||
class SurfaceReader {
|
||||
public:
|
||||
SurfaceReader();
|
||||
virtual ~SurfaceReader();
|
||||
|
||||
bool Init();
|
||||
void DeInit();
|
||||
|
||||
sptr<Surface> GetSurface() const;
|
||||
void SetHandler(sptr<SurfaceReaderHandler> handler);
|
||||
private:
|
||||
class BufferListener : public IBufferConsumerListener {
|
||||
public:
|
||||
explicit BufferListener(SurfaceReader &surfaceReader): surfaceReader_(surfaceReader)
|
||||
{
|
||||
}
|
||||
~BufferListener() noexcept override = default;
|
||||
void OnBufferAvailable() override
|
||||
{
|
||||
surfaceReader_.OnVsync();
|
||||
}
|
||||
|
||||
private:
|
||||
SurfaceReader &surfaceReader_;
|
||||
};
|
||||
friend class BufferListener;
|
||||
|
||||
void OnVsync();
|
||||
bool ProcessBuffer(const sptr<SurfaceBuffer> &buf);
|
||||
|
||||
sptr<IBufferConsumerListener> listener_ = nullptr;
|
||||
sptr<Surface> csurface_ = nullptr; // cosumer surface
|
||||
sptr<Surface> psurface_ = nullptr; // producer surface
|
||||
sptr<SurfaceBuffer> prevBuffer_ = nullptr;
|
||||
sptr<SurfaceReaderHandler> handler_ = nullptr;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif // SURFACE_READER_H
|
||||
@@ -13,20 +13,22 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "display_manager_agent.h"
|
||||
#include "display_manager.h"
|
||||
#include "singleton_container.h"
|
||||
#ifndef SURFACE_READER_HANDLER_H
|
||||
#define SURFACE_READER_HANDLER_H
|
||||
|
||||
#include "pixel_map.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Rosen {
|
||||
void DisplayManagerAgent::NotifyDisplayPowerEvent(DisplayPowerEvent event, EventStatus status)
|
||||
{
|
||||
SingletonContainer::Get<DisplayManager>().NotifyDisplayPowerEvent(event, status);
|
||||
class SurfaceReaderHandler : public RefBase {
|
||||
public:
|
||||
SurfaceReaderHandler() {}
|
||||
virtual ~SurfaceReaderHandler() noexcept
|
||||
{
|
||||
}
|
||||
virtual bool OnImageAvalible(sptr<Media::PixelMap> pixleMap) = 0;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
void DisplayManagerAgent::NotifyDisplayStateChanged(DisplayId id, DisplayState state)
|
||||
{
|
||||
SingletonContainer::Get<DisplayManager>().NotifyDisplayStateChanged(id, state);
|
||||
}
|
||||
} // namespace Rosen
|
||||
} // namespace OHOS
|
||||
#endif // IMAGE_READER_HANDLER_H
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
@@ -13,22 +13,27 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_ROSEN_DISPLAY_MANAGER_AGENT_H
|
||||
#define OHOS_ROSEN_DISPLAY_MANAGER_AGENT_H
|
||||
#ifndef SURFACE_READER_HANDLER_IMPL_H
|
||||
#define SURFACE_READER_HANDLER_IMPL_H
|
||||
|
||||
#include <refbase.h>
|
||||
#include <display_manager_agent_default.h>
|
||||
#include <mutex>
|
||||
#include "surface_reader_handler.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Rosen {
|
||||
class DisplayManagerAgent : public DisplayManagerAgentDefault {
|
||||
class SurfaceReaderHandlerImpl : public SurfaceReaderHandler {
|
||||
public:
|
||||
DisplayManagerAgent() = default;
|
||||
~DisplayManagerAgent() = default;
|
||||
bool OnImageAvalible(sptr<Media::PixelMap> pixleMap) override;
|
||||
bool IsImageOk();
|
||||
void ResetFlag();
|
||||
sptr<Media::PixelMap> GetPixelMap();
|
||||
|
||||
virtual void NotifyDisplayPowerEvent(DisplayPowerEvent event, EventStatus status) override;
|
||||
virtual void NotifyDisplayStateChanged(DisplayId id, DisplayState state) override;
|
||||
private:
|
||||
bool flag_ = false;
|
||||
sptr<Media::PixelMap> pixleMap_ = nullptr;
|
||||
std::recursive_mutex mutex_;
|
||||
};
|
||||
}
|
||||
}
|
||||
#endif // OHOS_ROSEN_DISPLAY_MANAGER_AGENT_H
|
||||
|
||||
#endif // SURFACE_READER_HANDLER_IMPL_H
|
||||
@@ -17,6 +17,7 @@
|
||||
#define OHOS_WM_INCLUDE_WM_HELPER_H
|
||||
|
||||
#include <wm_common.h>
|
||||
#include <wm_common_inner.h>
|
||||
|
||||
namespace OHOS {
|
||||
namespace Rosen {
|
||||
@@ -24,12 +25,12 @@ class WindowHelper {
|
||||
public:
|
||||
static inline bool IsMainWindow(WindowType type)
|
||||
{
|
||||
return (type >= WindowType::APP_MAIN_WINDOW_BASE && type <= WindowType::APP_MAIN_WINDOW_END);
|
||||
return (type >= WindowType::APP_MAIN_WINDOW_BASE && type < WindowType::APP_MAIN_WINDOW_END);
|
||||
}
|
||||
|
||||
static inline bool IsSubWindow(WindowType type)
|
||||
{
|
||||
return (type >= WindowType::APP_SUB_WINDOW_BASE && type <= WindowType::APP_SUB_WINDOW_END);
|
||||
return (type >= WindowType::APP_SUB_WINDOW_BASE && type < WindowType::APP_SUB_WINDOW_END);
|
||||
}
|
||||
|
||||
static inline bool IsAppWindow(WindowType type)
|
||||
@@ -39,12 +40,12 @@ public:
|
||||
|
||||
static inline bool IsBelowSystemWindow(WindowType type)
|
||||
{
|
||||
return (type >= WindowType::BELOW_APP_SYSTEM_WINDOW_BASE && type <= WindowType::BELOW_APP_SYSTEM_WINDOW_END);
|
||||
return (type >= WindowType::BELOW_APP_SYSTEM_WINDOW_BASE && type < WindowType::BELOW_APP_SYSTEM_WINDOW_END);
|
||||
}
|
||||
|
||||
static inline bool IsAboveSystemWindow(WindowType type)
|
||||
{
|
||||
return (type >= WindowType::ABOVE_APP_SYSTEM_WINDOW_BASE && type <= WindowType::ABOVE_APP_SYSTEM_WINDOW_END);
|
||||
return (type >= WindowType::ABOVE_APP_SYSTEM_WINDOW_BASE && type < WindowType::ABOVE_APP_SYSTEM_WINDOW_END);
|
||||
}
|
||||
|
||||
static inline bool IsSystemWindow(WindowType type)
|
||||
@@ -57,6 +58,11 @@ public:
|
||||
return ((IsMainWindow(type)) && (mode == WindowMode::WINDOW_MODE_FLOATING));
|
||||
}
|
||||
|
||||
static inline bool IsAvoidAreaWindow(WindowType type)
|
||||
{
|
||||
return (type == WindowType::WINDOW_TYPE_STATUS_BAR || type == WindowType::WINDOW_TYPE_NAVIGATION_BAR);
|
||||
}
|
||||
|
||||
static inline bool IsSplitWindowMode(WindowMode mode)
|
||||
{
|
||||
return mode == WindowMode::WINDOW_MODE_SPLIT_PRIMARY || mode == WindowMode::WINDOW_MODE_SPLIT_SECONDARY;
|
||||
@@ -79,23 +85,28 @@ public:
|
||||
return (r.posX_ == 0 && r.posY_ == 0 && r.width_ == 0 && r.height_ == 0);
|
||||
}
|
||||
|
||||
static Rect GetFixedWindowRectByMinRect(const Rect& oriDstRect, const Rect& lastRect, bool isVertical)
|
||||
static Rect GetFixedWindowRectByMinRect(const Rect& oriDstRect, const Rect& lastRect, bool isVertical,
|
||||
float virtualPixelRatio)
|
||||
{
|
||||
uint32_t minVerticalFloatingW = static_cast<uint32_t>(MIN_VERTICAL_FLOATING_WIDTH * virtualPixelRatio);
|
||||
uint32_t minVerticalFloatingH = static_cast<uint32_t>(MIN_VERTICAL_FLOATING_HEIGHT * virtualPixelRatio);
|
||||
Rect dstRect = oriDstRect;
|
||||
if (isVertical) {
|
||||
dstRect.width_ = std::max(MIN_VERTICAL_FLOATING_WIDTH, oriDstRect.width_);
|
||||
dstRect.height_ = std::max(MIN_VERTICAL_FLOATING_HEIGHT, oriDstRect.height_);
|
||||
dstRect.width_ = std::max(minVerticalFloatingW, oriDstRect.width_);
|
||||
dstRect.height_ = std::max(minVerticalFloatingH, oriDstRect.height_);
|
||||
} else {
|
||||
dstRect.width_ = std::max(MIN_VERTICAL_FLOATING_HEIGHT, oriDstRect.width_);
|
||||
dstRect.height_ = std::max(MIN_VERTICAL_FLOATING_WIDTH, oriDstRect.height_);
|
||||
dstRect.width_ = std::max(minVerticalFloatingH, oriDstRect.width_);
|
||||
dstRect.height_ = std::max(minVerticalFloatingW, oriDstRect.height_);
|
||||
}
|
||||
|
||||
// limit position by fixed width or height
|
||||
if (oriDstRect.posX_ != lastRect.posX_) {
|
||||
dstRect.posX_ = oriDstRect.posX_ + oriDstRect.width_ - dstRect.width_;
|
||||
dstRect.posX_ = oriDstRect.posX_ + static_cast<int32_t>(oriDstRect.width_) -
|
||||
static_cast<int32_t>(dstRect.width_);
|
||||
}
|
||||
if (oriDstRect.posY_ != lastRect.posY_) {
|
||||
dstRect.posY_ = oriDstRect.posY_ + oriDstRect.height_ - dstRect.height_;
|
||||
dstRect.posY_ = oriDstRect.posY_ + static_cast<int32_t>(oriDstRect.height_) -
|
||||
static_cast<int32_t>(dstRect.height_);
|
||||
}
|
||||
return dstRect;
|
||||
}
|
||||
@@ -103,9 +114,9 @@ public:
|
||||
static bool IsPointInWindow(int32_t pointPosX, int32_t pointPosY, Rect pointRect)
|
||||
{
|
||||
if ((pointPosX > pointRect.posX_) &&
|
||||
(pointPosX < static_cast<int32_t>(pointRect.posX_ + pointRect.width_)) &&
|
||||
(pointPosX < (pointRect.posX_ + static_cast<int32_t>(pointRect.width_))) &&
|
||||
(pointPosY > pointRect.posY_) &&
|
||||
(pointPosY < static_cast<int32_t>(pointRect.posY_ + pointRect.height_))) {
|
||||
(pointPosY < (pointRect.posY_ + static_cast<int32_t>(pointRect.height_)))) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -35,6 +35,27 @@ enum class WindowStateChangeReason : uint32_t {
|
||||
NORMAL,
|
||||
KEYGUARD,
|
||||
};
|
||||
|
||||
enum class WindowUpdateReason : uint32_t {
|
||||
UPDATE_ALL,
|
||||
UPDATE_MODE,
|
||||
UPDATE_RECT,
|
||||
UPDATE_FLAGS,
|
||||
UPDATE_TYPE,
|
||||
UPDATE_OTHER_PROPS,
|
||||
};
|
||||
namespace {
|
||||
constexpr float DEFAULT_SPLIT_RATIO = 0.5;
|
||||
constexpr uint32_t DIVIDER_WIDTH = 8;
|
||||
constexpr uint32_t WINDOW_TITLE_BAR_HEIGHT = 48;
|
||||
constexpr uint32_t WINDOW_FRAME_WIDTH = 4;
|
||||
constexpr uint32_t HOTZONE = 40;
|
||||
constexpr uint32_t DIV_HOTZONE = 20;
|
||||
constexpr uint32_t MIN_VERTICAL_FLOATING_WIDTH = 240;
|
||||
constexpr uint32_t MIN_VERTICAL_FLOATING_HEIGHT = 426;
|
||||
constexpr uint32_t MIN_VERTICAL_SPLIT_HEIGHT = 426;
|
||||
constexpr uint32_t MIN_HORIZONTAL_SPLIT_WIDTH = 426;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif // OHOS_ROSEN_WM_COMMON_INNER_H
|
||||
@@ -16,47 +16,34 @@
|
||||
#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_;
|
||||
screenId_ = info->screenId_;
|
||||
xDpi_ = info->xDpi_;
|
||||
yDpi_ = info->yDpi_;
|
||||
rotation_ = info->rotation_;
|
||||
}
|
||||
|
||||
bool DisplayInfo::Marshalling(Parcel &parcel) const
|
||||
{
|
||||
return parcel.WriteUint64(id_) && parcel.WriteUint32(type_) &&
|
||||
parcel.WriteInt32(width_) && parcel.WriteInt32(height_) &&
|
||||
parcel.WriteUint32(freshRate_) && parcel.WriteUint64(screenId_) &&
|
||||
parcel.WriteFloat(xDpi_) && parcel.WriteFloat(yDpi_) &&
|
||||
parcel.WriteUint32(static_cast<uint32_t>(rotation_));
|
||||
parcel.WriteUint32(static_cast<uint32_t>(rotation_)) &&
|
||||
parcel.WriteUint32(static_cast<uint32_t>(orientation_));
|
||||
}
|
||||
|
||||
DisplayInfo *DisplayInfo::Unmarshalling(Parcel &parcel)
|
||||
{
|
||||
DisplayInfo *displayInfo = new DisplayInfo();
|
||||
if (displayInfo == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
uint32_t type = (uint32_t)DisplayType::DEFAULT;
|
||||
uint32_t rotation;
|
||||
uint32_t orientation;
|
||||
bool res = parcel.ReadUint64(displayInfo->id_) && parcel.ReadUint32(type) &&
|
||||
parcel.ReadInt32(displayInfo->width_) && parcel.ReadInt32(displayInfo->height_) &&
|
||||
parcel.ReadUint32(displayInfo->freshRate_) && parcel.ReadUint64(displayInfo->screenId_) &&
|
||||
parcel.ReadFloat(displayInfo->xDpi_) && parcel.ReadFloat(displayInfo->yDpi_) &&
|
||||
parcel.ReadUint32(rotation);
|
||||
parcel.ReadUint32(rotation) && parcel.ReadUint32(orientation);
|
||||
if (!res) {
|
||||
displayInfo = nullptr;
|
||||
} else {
|
||||
displayInfo->type_ = (DisplayType)type;
|
||||
displayInfo->rotation_ = static_cast<Rotation>(rotation);
|
||||
delete displayInfo;
|
||||
return nullptr;
|
||||
}
|
||||
displayInfo->type_ = (DisplayType)type;
|
||||
displayInfo->rotation_ = static_cast<Rotation>(rotation);
|
||||
displayInfo->orientation_ = static_cast<Orientation>(orientation);
|
||||
return displayInfo;
|
||||
}
|
||||
} // namespace OHOS::Rosen
|
||||
@@ -16,16 +16,6 @@
|
||||
#include "screen_group_info.h"
|
||||
|
||||
namespace OHOS::Rosen {
|
||||
void ScreenGroupInfo::Update(sptr<ScreenGroupInfo> info)
|
||||
{
|
||||
ScreenInfo::Update(info);
|
||||
children_.clear();
|
||||
children_.insert(children_.begin(), info->children_.begin(), info->children_.end());
|
||||
position_.clear();
|
||||
position_.insert(position_.begin(), info->position_.begin(), info->position_.end());
|
||||
combination_ = info->combination_;
|
||||
}
|
||||
|
||||
bool ScreenGroupInfo::Marshalling(Parcel &parcel) const
|
||||
{
|
||||
bool res = ScreenInfo::Marshalling(parcel) && parcel.WriteUint32((uint32_t)combination_) &&
|
||||
@@ -48,29 +38,34 @@ bool ScreenGroupInfo::Marshalling(Parcel &parcel) const
|
||||
ScreenGroupInfo* ScreenGroupInfo::Unmarshalling(Parcel &parcel)
|
||||
{
|
||||
ScreenGroupInfo* screenGroupInfo = new ScreenGroupInfo();
|
||||
return screenGroupInfo->InnerUnmarshalling(parcel);
|
||||
bool res = screenGroupInfo->InnerUnmarshalling(parcel);
|
||||
if (res) {
|
||||
return screenGroupInfo;
|
||||
}
|
||||
delete screenGroupInfo;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
ScreenGroupInfo* ScreenGroupInfo::InnerUnmarshalling(Parcel& parcel)
|
||||
bool ScreenGroupInfo::InnerUnmarshalling(Parcel& parcel)
|
||||
{
|
||||
uint32_t combination;
|
||||
if (!ScreenInfo::InnerUnmarshalling(parcel) || !parcel.ReadUint32(combination) ||
|
||||
!parcel.ReadUInt64Vector(&children_)) {
|
||||
return nullptr;
|
||||
return false;
|
||||
}
|
||||
combination_ = (ScreenCombination) combination;
|
||||
uint32_t size;
|
||||
if (!parcel.ReadUint32(size)) {
|
||||
return nullptr;
|
||||
return false;
|
||||
}
|
||||
for (size_t i = 0; i < size; i++) {
|
||||
Point point;
|
||||
if (parcel.ReadInt32(point.posX_) && parcel.ReadInt32(point.posY_)) {
|
||||
position_.push_back(point);
|
||||
} else {
|
||||
return nullptr;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return this;
|
||||
return true;
|
||||
}
|
||||
} // namespace OHOS::Rosen
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user