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