1 /*
2  * Copyright (c) 2022 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_JS_DISPLAY_H
17 #define OHOS_JS_DISPLAY_H
18 #include <js_runtime_utils.h>
19 #include <native_engine/native_engine.h>
20 #include <native_engine/native_value.h>
21 #include <refbase.h>
22 
23 #include "cutout_info.h"
24 #include "display.h"
25 #include "dm_common.h"
26 
27 namespace OHOS {
28 namespace Rosen {
29 enum class ColorSpace : uint32_t {
30     UNKNOWN = 0,
31     ADOBE_RGB = 1,
32     BT2020_HLG = 2,
33     BT2020_PQ = 3,
34     BT601_EBU = 4,
35     BT601_SMPTE_C = 5,
36     BT709 = 6,
37     P3_HLG = 7,
38     P3_PQ = 8,
39     DISPLAY_P3 = 9,
40     SRGB = 10,
41     LINEAR_SRGB = 11,
42     LINEAR_P3 = 12,
43     LINEAR_BT2020 = 13,
44 };
45 
46 enum class HDRFormat : uint32_t {
47     NONE = 0,
48     VIDEO_HLG = 1,
49     VIDEO_HDR10 = 2,
50     VIDEO_HDR_VIVID = 3,
51     IMAGE_HDR_VIVID_DUAL = 4,
52     IMAGE_HDR_VIVID_SINGLE = 5,
53     IMAGE_HDR_ISO_DUAL = 6,
54     IMAGE_HDR_ISO_SINGLE = 7,
55 };
56 
57 std::shared_ptr<NativeReference> FindJsDisplayObject(DisplayId displayId);
58 napi_value CreateJsDisplayObject(napi_env env, sptr<Display>& display);
59 napi_value CreateJsCutoutInfoObject(napi_env env, sptr<CutoutInfo> cutoutInfo);
60 napi_value CreateJsRectObject(napi_env env, DMRect rect);
61 napi_value CreateJsWaterfallDisplayAreaRectsObject(napi_env env,
62     WaterfallDisplayAreaRects waterfallDisplayAreaRects);
63 napi_value CreateJsBoundingRectsArrayObject(napi_env env, std::vector<DMRect> boundingRects);
64 napi_value CreateJsDisplayPhysicalInfoObject(napi_env env, DisplayPhysicalResolution physicalInfo);
65 napi_value NapiGetUndefined(napi_env env);
66 napi_valuetype GetType(napi_env env, napi_value value);
67 class JsDisplay final {
68 public:
69     explicit JsDisplay(const sptr<Display>& display);
70     ~JsDisplay();
71     static void Finalizer(napi_env env, void* data, void* hint);
72     static napi_value GetCutoutInfo(napi_env env, napi_callback_info info);
73     static napi_value HasImmersiveWindow(napi_env env, napi_callback_info info);
74     static napi_value GetAvailableArea(napi_env env, napi_callback_info info);
75     static napi_value GetSupportedColorSpaces(napi_env env, napi_callback_info info);
76     static napi_value GetSupportedHDRFormats(napi_env env, napi_callback_info info);
77     static napi_value RegisterDisplayManagerCallback(napi_env env, napi_callback_info info);
78     static napi_value UnregisterDisplayManagerCallback(napi_env env, napi_callback_info info);
79 
80 private:
81     sptr<Display> display_ = nullptr;
82     napi_value OnGetCutoutInfo(napi_env env, napi_callback_info info);
83     napi_value OnHasImmersiveWindow(napi_env env, napi_callback_info info);
84     napi_value OnGetAvailableArea(napi_env env, napi_callback_info info);
85     napi_value OnGetSupportedColorSpaces(napi_env env, napi_callback_info info);
86     napi_value OnGetSupportedHDRFormats(napi_env env, napi_callback_info info);
87     napi_value OnRegisterDisplayManagerCallback(napi_env env, napi_callback_info info);
88     napi_value OnUnregisterDisplayManagerCallback(napi_env env, napi_callback_info info);
89     std::unique_ptr<AbilityRuntime::NapiAsyncTask> CreateEmptyAsyncTask(napi_env env,
90         napi_value lastParam, napi_value* result);
91     DMError RegisterDisplayListenerWithType(napi_env env, const std::string& type, napi_value value);
92     DMError UnregisterAllDisplayListenerWithType(const std::string& type);
93     DMError UnRegisterDisplayListenerWithType(napi_env env, const std::string& type, napi_value value);
94 };
95 enum class DisplayStateMode : uint32_t {
96     STATE_UNKNOWN = 0,
97     STATE_OFF,
98     STATE_ON,
99     STATE_DOZE,
100     STATE_DOZE_SUSPEND,
101     STATE_VR,
102     STATE_ON_SUSPEND
103 };
104 }  // namespace Rosen
105 }  // namespace OHOS
106 #endif