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 #ifndef OHOS_WINDOW_SCENE_JS_SCREEN_UTILS_H
17 #define OHOS_WINDOW_SCENE_JS_SCREEN_UTILS_H
18 
19 #include <native_engine/native_engine.h>
20 #include <native_engine/native_value.h>
21 #include <js_runtime_utils.h>
22 #include <pointer_event.h>
23 
24 #include "hitrace_meter.h"
25 #include "dm_common.h"
26 #include "session/screen/include/screen_property.h"
27 
28 namespace OHOS::Rosen {
29 bool ConvertRRectFromJs(napi_env env, napi_value jsObject, RRect& bound);
30 bool ConvertDMRectFromJs(napi_env env, napi_value jsObject, DMRect& rect);
31 bool ConvertScreenDirectionInfoFromJs(napi_env env, napi_value jsObject, ScreenDirectionInfo& directionInfo);
32 napi_value NapiGetUndefined(napi_env env);
33 bool NapiIsCallable(napi_env env, napi_value value);
34 class JsScreenUtils {
35 public:
36     static napi_value CreateJsScreenProperty(napi_env env, const ScreenProperty& screenProperty);
37     static napi_value CreateJsRRect(napi_env env, const RRect& rrect);
38     static napi_value CreateJsScreenConnectChangeType(napi_env env);
39     static napi_value CreateJsScreenPropertyChangeReason(napi_env env);
40     static napi_value CreateJsFoldStatus(napi_env env);
41     static napi_value CreateJsScreenPropertyChangeType(napi_env env);
42 };
43 
44 
45 class MainThreadScheduler {
46 public:
47     using Task = std::function<void()>;
48     explicit MainThreadScheduler(napi_env env);
49     void PostMainThreadTask(Task && localTask, std::string traceInfo = "DefaultDMSTask", int64_t delayTime = 0);
50 private:
51     void GetMainEventHandler();
52     napi_env env_;
53     std::shared_ptr<OHOS::AppExecFwk::EventHandler> handler_;
54 };
55 } // namespace OHOS::Rosen
56 
57 #endif // OHOS_WINDOW_SCENE_JS_SCREEN_UTILS_H
58