From a7619def2d09ff8b443cd10198c0c5b2a9514c2b Mon Sep 17 00:00:00 2001 From: zhengleran Date: Thu, 16 Jan 2025 21:42:40 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BE=9Bcolorspace=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=E9=80=9A=E8=B7=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhengleran --- .../js_scene_session.cpp | 37 ++++++++++++++++++- .../scene_session_manager/js_scene_session.h | 4 +- .../session/host/include/scene_session.h | 1 + .../session/host/src/scene_session.cpp | 21 +++++++++++ 4 files changed, 61 insertions(+), 2 deletions(-) diff --git a/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session.cpp b/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session.cpp index db1d9ad28d..7a1646a4b5 100644 --- a/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session.cpp +++ b/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session.cpp @@ -399,6 +399,7 @@ void JsSceneSession::BindNativeMethod(napi_env env, napi_value objValue, const c BindNativeFunction(env, objValue, "setFreezeImmediately", moduleName, JsSceneSession::SetFreezeImmediately); BindNativeFunction(env, objValue, "sendContainerModalEvent", moduleName, JsSceneSession::SendContainerModalEvent); + BindNativeFunction(env, objValue, "setColorSpace", moduleName, JsSceneSession::SetColorSpace); } void JsSceneSession::BindNativeMethodForKeyboard(napi_env env, napi_value objValue, const char* moduleName) @@ -2267,6 +2268,13 @@ napi_value JsSceneSession::SendContainerModalEvent(napi_env env, napi_callback_i return (me != nullptr) ? me->OnSendContainerModalEvent(env, info) : nullptr; } +napi_value JsSceneSession::SetColorSpace(napi_env env, napi_callback_info info) +{ + TLOGD(WmsLogTag::WMS_ATTRIBUTE, "[NAPI]"); + JsSceneSession* me = CheckParamsAndGetThis(env, info); + return (me != nullptr) ? me->OnSetColorSpace(env, info) : nullptr; +} + bool JsSceneSession::IsCallbackRegistered(napi_env env, const std::string& type, napi_value jsListenerObject) { HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "JsSceneSession::IsCallbackRegistered[%s]", type.c_str()); @@ -5827,7 +5835,7 @@ napi_value JsSceneSession::OnSendContainerModalEvent(napi_env env, napi_callback "Input parameter is missing or invalid")); return NapiGetUndefined(env); } - + auto session = weakSession_.promote(); if (session == nullptr) { TLOGE(WmsLogTag::WMS_EVENT, "session is nullptr, id:%{public}d", persistentId_); @@ -5840,4 +5848,31 @@ napi_value JsSceneSession::OnSendContainerModalEvent(napi_env env, napi_callback session->SendContainerModalEvent(eventName, eventValue); return NapiGetUndefined(env); } + +napi_value JsSceneSession::OnSetColorSpace(napi_env env, napi_callback_info info) +{ + size_t argc = ARGC_FOUR; + napi_value argv[ARGC_FOUR] = {nullptr}; + napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); + if (argc < ARGC_ONE) { + TLOGE(WmsLogTag::WMS_ATTRIBUTE, "Argc is invalid: %{public}zu", argc); + napi_throw(env, CreateJsError(env, static_cast(WSErrorCode::WS_ERROR_INVALID_PARAM), + "Input parameter is missing or invalid")); + return NapiGetUndefined(env); + } + ColorSpace colorSpace = ColorSpace::COLOR_SPACE_DEFAULT; + if (!ConvertFromJsValue(env, argv[0], colorSpace)) { + TLOGE(WmsLogTag::WMS_ATTRIBUTE, "Failed to convert parameter to ColorSpace"); + napi_throw(env, CreateJsError(env, static_cast(WSErrorCode::WS_ERROR_INVALID_PARAM), + "Input parameter is missing or invalid")); + return NapiGetUndefined(env); + } + auto session = weakSession_.promote(); + if (session == nullptr) { + TLOGE(WmsLogTag::WMS_ATTRIBUTE, "session is nullptr, id:%{public}d", persistentId_); + return NapiGetUndefined(env); + } + session->SetColorSpace(colorSpace); + return NapiGetUndefined(env); +} } // namespace OHOS::Rosen diff --git a/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session.h b/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session.h index c4a6e850e7..785e08f67b 100644 --- a/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session.h +++ b/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session.h @@ -199,6 +199,7 @@ private: static napi_value SetBehindWindowFilterEnabled(napi_env env, napi_callback_info info); static napi_value SetFreezeImmediately(napi_env env, napi_callback_info info); static napi_value SendContainerModalEvent(napi_env env, napi_callback_info info); + static napi_value setColorSpace(napi_env env, napi_callback_info info); napi_value OnRegisterCallback(napi_env env, napi_callback_info info); napi_value OnUpdateNativeVisibility(napi_env env, napi_callback_info info); @@ -267,6 +268,7 @@ private: napi_value OnMaskSupportEnterWaterfallMode(napi_env env, napi_callback_info info); napi_value OnUpdateFullScreenWaterfallMode(napi_env env, napi_callback_info info); napi_value OnSendContainerModalEvent(napi_env env, napi_callback_info info); + napi_value OnSetColorSpace(napi_env env, napi_callback_info info); bool IsCallbackRegistered(napi_env env, const std::string& type, napi_value jsListenerObject); void ProcessChangeSessionVisibilityWithStatusBarRegister(); @@ -321,7 +323,7 @@ private: * PC Window Layout */ void ProcessSetSupportedWindowModesRegister(); - + void ChangeSessionVisibilityWithStatusBar(const SessionInfo& info, bool visible); void ChangeSessionVisibilityWithStatusBarInner(std::shared_ptr sessionInfo, bool visible); void OnBufferAvailableChange(const bool isBufferAvailable); diff --git a/window_scene/session/host/include/scene_session.h b/window_scene/session/host/include/scene_session.h index 7f0fddedf1..b76ae79cb7 100644 --- a/window_scene/session/host/include/scene_session.h +++ b/window_scene/session/host/include/scene_session.h @@ -289,6 +289,7 @@ public: void SetLastSafeRect(WSRect rect); void SetMovable(bool isMovable); void SetOriPosYBeforeRaisedByKeyboard(int32_t posY); + void SetColorSpace(ColorSpace colorSpace); /* * Window Hierarchy diff --git a/window_scene/session/host/src/scene_session.cpp b/window_scene/session/host/src/scene_session.cpp index 9d157b5fc0..ee93df10aa 100644 --- a/window_scene/session/host/src/scene_session.cpp +++ b/window_scene/session/host/src/scene_session.cpp @@ -6260,4 +6260,25 @@ void SceneSession::UpdateAllModalUIExtensions(const WSRect& globalRect) parentTransX, parentTransY); }, __func__); } + +void SceneSession::SetColorSpace(ColorSpace colorSpace) +{ + auto surfaceNode = GetSurfaceNode(); + if (!surfaceNode) { + TLOGE(WmsLogTag::WMS_ATTRIBUTE, "surfaceNode is invalid"); + } + TLOGI(WmsLogTag::WMS_ATTRIBUTE, "SetColorSpace value=%{public}u", colorSpace); + auto colorGamut = GraphicColorGamut::GRAPHIC_COLOR_GAMUT_SRGB; + if (colorSpace == ColorSpace::COLOR_SPACE_WIDE_GAMUT) { + colorGamut = GraphicColorGamut::GRAPHIC_COLOR_GAMUT_DCI_P3; + } + auto rsTransaction = RSTransactionProxy::GetInstance(); + if (rsTransaction != nullptr) { + rsTransaction->Begin(); + } + surfaceNode->SetColorSpace(colorGamut); + if (rsTransaction != nullptr) { + rsTransaction->Commit(); + } +} } // namespace OHOS::Rosen -- Gitee