• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15import { display } from '@kit.ArkUI';
16import { BusinessError } from '@ohos.base';
17
18class VirtualScreenOptions {
19    name: string = '';
20    width: number = 0;
21    height: number = 0;
22    density: number = 0;
23    surfaceId: string = '';
24}
25
26@Entry
27@Component
28struct MakeUniqueTest {
29    xComponentController: XComponentController = new XComponentController();
30    @State message: string = '';
31    @State vid: number = 0;
32    @State text: string = '';
33    private caseName = 'test_MakeUnique_01 inPage';
34
35    build() {
36        Column() {
37            Row(){
38            Text(this.message).id('testResult')
39        }
40
41        Column() {
42            XComponent({
43                type: XComponentType.SURFACE,
44                controller: this.xComponentController
45            })
46        }.width('100%').height('50%')
47
48        Button('创建虚拟屏')
49            .onClick(() => {
50                try {
51                    display.createVirtualScreen({
52                    name: 'CommonScbScreen',
53                    width: 1080,
54                    height: 2720,
55                    density: 2,
56                    surfaceId: ''
57                }).then(async (displayId: number) => {
58                    this.vid = displayId;
59
60                    // 设置虚拟屏surfaceid
61                    let surfaceId = this.xComponentController.getXComponentSurfaceId();
62                    await display.setVirtualScreenSurface(this.vid, surfaceId).then(() => {
63                        console.log(this.caseName + 'succeeded in setVirtualScreenSurface');
64                    }).catch((err: BusinessError) => {
65                        console.log(this.caseName + 'Failed in setVirtualScreenSurface, err: ' + JSON.stringify(err));
66                    })
67
68                    // 虚拟屏设置异源屏
69                    display.makeUnique(this.vid).then(async () => {
70                        console.log(this.caseName + 'succeeded in makeUnique');
71                        this.message = 'success';
72                    }).catch((err: BusinessError) => {
73                        console.log(this.caseName + 'failed in makeUnique, err : ' + JSON.stringify(err));
74                        this.message = 'fail';
75                    })
76                })
77                } catch (err) {
78                    console.log(this.caseName + 'Failed in createVirtualScreen, err : ' + JSON.stringify(err));
79                    if (err.code == 801) {
80                        this.message = 'not support';
81                    } else {
82                        this.message = 'fail';
83                    }
84                }
85            })
86        }
87
88    }
89}