• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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  */
15 
16 #include "napi/native_api.h"
17 #include <cstdint>
18 #include <hilog/log.h>
19 #include <multimedia/player_framework/native_avcodec_base.h>
20 #include <native_image/native_image.h>
21 #include <native_window/external_window.h>
22 #include <native_buffer/native_buffer.h>
23 #include "nativewindow.h"
24 #include "ace/xcomponent/native_interface_xcomponent.h"
25 #include <string>
26 
27 #define SUCCESS 0
28 #define FAIL (-1)
29 
30 #define CONSTANT_2147483647 2147483647
31 #define CONSTANT_2147483648 2147483648
32 #define CONSTANT_NEG_2147483647 (-2147483647)
33 #define CONSTANT_NEG_2147483648 (-2147483648)
34 #define CONSTANT_NEG_9223372036854775807 (9223372036854775807)
35 #define CONSTANT_NEG_9223372036854775808 (-9223372036854775808)
36 
37 
38 #define CONSTANT_0 0
39 #define CONSTANT_1 1
40 #define CONSTANT_2 2
41 #define CONSTANT_3 3
42 #define CONSTANT_4 4
43 #define CONSTANT_5 5
44 #define CONSTANT_6 6
45 #define CONSTANT_7 7
46 #define CONSTANT_8 8
47 #define CONSTANT_60 60
48 #define CONSTANT_2999 2999
49 #define CONSTANT_3000 3000
50 #define CONSTANT_3001 3001
51 #define CONSTANT_998899 998899
52 #define CONSTANT_100 100
53 #define CONSTANT_1000 1000
54 #define CONSTANT_10000 10000
55 #define CONSTANT_100000 100000
56 #define CONSTANT_1000000 1000000
57 #define CONSTANT_10000000 10000000
58 #define CONSTANT_100000000 100000000
59 #define CONSTANT_1000000000 1000000000
60 #define CONSTANT_1999999 1999999
61 #define CONSTANT_99999999 99999999
62 #define CONSTANT_99999999999999999 99999999999999999
63 #define CONSTANT_999999999999999999 999999999999999999
64 #define CONSTANT_40001000 40001000
65 #define CONSTANT_50002000 50002000
66 #define CONSTANT_50102000 50102000
67 
68 
testNativeWindowCreateNativeWindow(napi_env env,napi_callback_info info)69 napi_value testNativeWindowCreateNativeWindow(napi_env env, napi_callback_info info)
70 {
71     napi_value result = nullptr;
72     OHNativeWindow *nativeWindow = nullptr;
73     nativeWindow = OH_NativeWindow_CreateNativeWindow(nullptr);
74     if (nativeWindow == nullptr) {
75         napi_create_int32(env, SUCCESS, &result);
76         return result;
77     }
78     napi_create_int32(env, FAIL, &result);
79     return result;
80 }
81 
testNativeWindowNativeWindowSetSetScalingMode(napi_env env,napi_callback_info info)82 napi_value testNativeWindowNativeWindowSetSetScalingMode(napi_env env, napi_callback_info info)
83 {
84     napi_value result = nullptr;
85     InitNativeWindow* initNative = new InitNativeWindow();
86     OHNativeWindow *nativeWindow = nullptr;
87     nativeWindow = initNative->returnNativeWindow();
88     if (nativeWindow == nullptr) {
89         napi_create_int32(env, CONSTANT_998899, &result);
90         return result;
91     }
92     uint32_t sequence = 1000;
93     int32_t flag1 = OH_NativeWindow_NativeWindowSetScalingMode(nullptr, sequence, OH_SCALING_MODE_FREEZE);
94     int32_t flag2 =
95         OH_NativeWindow_NativeWindowSetScalingMode(nativeWindow, sequence, static_cast<OHScalingMode>(CONSTANT_100));
96     int32_t flag3 = OH_NativeWindow_NativeWindowSetScalingMode(nativeWindow, 0, OH_SCALING_MODE_FREEZE);
97     if (flag1 != CONSTANT_40001000 && flag2 != CONSTANT_40001000 && flag3 != CONSTANT_40001000) {
98         napi_create_int32(env, CONSTANT_1, &result);
99         return result;
100     }
101     delete initNative;
102     napi_create_int32(env, SUCCESS, &result);
103     return result;
104 }
105 
testNativeWindowNativeWindowSetMetaData(napi_env env,napi_callback_info info)106 napi_value testNativeWindowNativeWindowSetMetaData(napi_env env, napi_callback_info info)
107 {
108     napi_value result = nullptr;
109     InitNativeWindow* initNative = new InitNativeWindow();
110     OHNativeWindow *nativeWindow = nullptr;
111     nativeWindow = initNative->returnNativeWindow();
112     if (nativeWindow == nullptr) {
113         napi_create_int32(env, CONSTANT_998899, &result);
114         return result;
115     }
116     uint32_t sequence = 1000;
117     int32_t size = 0;
118     const OHHDRMetaData metaData[] = {{OH_METAKEY_RED_PRIMARY_X, 0}};
119     int32_t flag1 = OH_NativeWindow_NativeWindowSetMetaData(nullptr, sequence, sizeof(metaData), metaData);
120     int32_t flag2 = OH_NativeWindow_NativeWindowSetMetaData(nativeWindow, sequence, sizeof(metaData), nullptr);
121     int32_t flag3 = OH_NativeWindow_NativeWindowSetMetaData(nativeWindow, 0, sizeof(metaData), metaData);
122     if (flag1 != CONSTANT_40001000 && flag2 != CONSTANT_40001000 && flag3 != CONSTANT_40001000) {
123         napi_create_int32(env, CONSTANT_1, &result);
124         return result;
125     }
126     delete initNative;
127     napi_create_int32(env, SUCCESS, &result);
128     return result;
129 }
130 
testNativeWindowNativeWindowSetMetaDataSet(napi_env env,napi_callback_info info)131 napi_value testNativeWindowNativeWindowSetMetaDataSet(napi_env env, napi_callback_info info)
132 {
133     napi_value result = nullptr;
134     InitNativeWindow* initNative = new InitNativeWindow();
135     OHNativeWindow *nativeWindow = nullptr;
136     nativeWindow = initNative->returnNativeWindow();
137     if (nativeWindow == nullptr) {
138         napi_create_int32(env, CONSTANT_998899, &result);
139         return result;
140     }
141     uint32_t sequence = 1000;
142     int32_t size = 0;
143     OHHDRMetadataKey key = OHHDRMetadataKey::OH_METAKEY_HDR10_PLUS;
144     const uint8_t metaData[] = {0};
145     int32_t flag1 = OH_NativeWindow_NativeWindowSetMetaDataSet(nullptr, sequence, key, sizeof(metaData), metaData);
146     int32_t flag2 = OH_NativeWindow_NativeWindowSetMetaDataSet(nativeWindow, sequence, key, sizeof(metaData), nullptr);
147     int32_t flag3 = OH_NativeWindow_NativeWindowSetMetaDataSet(
148         nativeWindow, sequence, static_cast<OHHDRMetadataKey>(CONSTANT_100), sizeof(metaData), metaData);
149     if (flag1 != CONSTANT_40001000 && flag2 != CONSTANT_40001000 && flag3 != CONSTANT_40001000) {
150         napi_create_int32(env, CONSTANT_1000, &result);
151         return result;
152     }
153     delete initNative;
154     napi_create_int32(env, SUCCESS, &result);
155     return result;
156 }
157 
AllocOHExtDataHandle(uint32_t reserveInts)158 static OHExtDataHandle *AllocOHExtDataHandle(uint32_t reserveInts)
159 {
160     size_t handleSize = sizeof(OHExtDataHandle) + (sizeof(int32_t) * reserveInts);
161     OHExtDataHandle *handle = static_cast<OHExtDataHandle *>(malloc(handleSize));
162     if (handle == nullptr) {
163         return nullptr;
164     }
165     handle->fd = -1;
166     handle->reserveInts = reserveInts;
167     for (uint32_t i = 0; i < reserveInts; i++) {
168         handle->reserve[i] = -1;
169     }
170     return handle;
171 }
172 
testNativeWindowNativeWindowSetTunnelHandle(napi_env env,napi_callback_info info)173 napi_value testNativeWindowNativeWindowSetTunnelHandle(napi_env env, napi_callback_info info)
174 {
175     napi_value result = nullptr;
176     InitNativeWindow* initNative = new InitNativeWindow();
177     OHNativeWindow *nativeWindow = nullptr;
178     nativeWindow = initNative->returnNativeWindow();
179     if (nativeWindow == nullptr) {
180         napi_create_int32(env, CONSTANT_998899, &result);
181         return result;
182     }
183     uint32_t reserveInts = 1;
184     OHExtDataHandle *handle = AllocOHExtDataHandle(reserveInts);
185     int32_t flag1 = OH_NativeWindow_NativeWindowSetTunnelHandle(nullptr, handle);
186     int32_t flag2 = OH_NativeWindow_NativeWindowSetTunnelHandle(nativeWindow, nullptr);
187     if (flag1 != CONSTANT_40001000 && flag2 != CONSTANT_40001000) {
188         napi_create_int32(env, CONSTANT_1000, &result);
189         return result;
190     }
191     int32_t flag3 = OH_NativeWindow_NativeWindowSetTunnelHandle(nativeWindow, handle);
192     if (flag3 != SUCCESS) {
193         napi_create_int32(env, CONSTANT_10000, &result);
194         return result;
195     }
196     delete initNative;
197     napi_create_int32(env, SUCCESS, &result);
198     return result;
199 }
200