From 8d42dda46ec978f57d54b7b017905cf1a4d7fbf5 Mon Sep 17 00:00:00 2001 From: Ning Yuanfeng Date: Fri, 30 Aug 2024 16:26:43 +0800 Subject: [PATCH] =?UTF-8?q?=E9=85=8D=E5=90=88=E8=A7=A3=E5=86=B3=E7=94=BB?= =?UTF-8?q?=E4=B8=AD=E7=94=BBtypeNode=E6=96=B9=E6=A1=88=E4=B8=ADonSurfaceC?= =?UTF-8?q?reated=E7=AD=89=E5=9B=9E=E8=B0=83=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ning Yuanfeng --- .../inner/js_pip_manager.cpp | 32 +++++++++++++++++++ .../inner/js_pip_manager.h | 2 ++ .../js_pip_window_manager.cpp | 1 + resources/abc/pip/interface/PiPContent.js | 3 ++ resources/abc/pip/source/PiPContent.ets | 3 ++ 5 files changed, 41 insertions(+) diff --git a/interfaces/kits/napi/picture_in_picture_napi/inner/js_pip_manager.cpp b/interfaces/kits/napi/picture_in_picture_napi/inner/js_pip_manager.cpp index 8b3de50fb9..55653d3f40 100644 --- a/interfaces/kits/napi/picture_in_picture_napi/inner/js_pip_manager.cpp +++ b/interfaces/kits/napi/picture_in_picture_napi/inner/js_pip_manager.cpp @@ -27,6 +27,13 @@ namespace { constexpr int32_t NUMBER_TWO = 2; } +napi_value GetType(napi_env env, napi_value value) +{ + napi_valuetype res = napi_undefined; + napi_typeof(env, value, &res); + return res; +} + napi_value NapiGetUndefined(napi_env env) { napi_value result = nullptr; @@ -179,6 +186,30 @@ napi_value JsPipManager::OnSetTypeNodeEnabled(napi_env env, napi_callback_info i return NapiGetUndefined(env); } +napi_value JsPipManager::ResetNodeType(napi_env env, napi_callback_info info) +{ + JsPipManager* me = CheckParamsAndGetThis(env, info); + return (me != nullptr) ? me->OnResetNodeType(env, info) : nullptr; +} + +napi_value JsPipManager::OnResetNodeType(napi_env env, napi_callback_info info) +{ + TLOGD(WmsLogTag::WMS_PIP, "[NAPI]"); + size_t argc = 4; + napi_value argv[4] = {nullptr}; + napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); + if (argc < NUMBER_ONE) { + TLOGE(WmsLogTag::WMS_PIP, "[NAPI]Argc count is invalid: %{public}zu", argc); + return NapiGetUndefined(env); + } + napi_value typeNode = argv[0]; + if (typeNode != nullptr && GetType(env, typeNode) != napi_undefined) { + TLOGI(WmsLogTag::WMS_PIP, "reset to DEFAULT"); + XComponentController::SetSurfaceCallbackMode(env, typeNode, SurfaceCallbackMode::DEFAULT); + } + return NapiGetUndefined(env); +} + napi_value JsPipManager::RegisterCallback(napi_env env, napi_callback_info info) { JsPipManager* me = CheckParamsAndGetThis(env, info); @@ -250,6 +281,7 @@ napi_value JsPipManagerInit(napi_env env, napi_value exportObj) BindNativeFunction(env, exportObj, "on", moduleName, JsPipManager::RegisterCallback); BindNativeFunction(env, exportObj, "off", moduleName, JsPipManager::UnregisterCallback); BindNativeFunction(env, exportObj, "setTypeNodeEnabled", moduleName, JsPipManager::SetTypeNodeEnabled); + BindNativeFunction(env, exportObj, "resetNodeType", moduleName, JsPipManager::ResetNodeType); return NapiGetUndefined(env); } } // namespace Rosen diff --git a/interfaces/kits/napi/picture_in_picture_napi/inner/js_pip_manager.h b/interfaces/kits/napi/picture_in_picture_napi/inner/js_pip_manager.h index 90ae2aa865..8192d748e4 100644 --- a/interfaces/kits/napi/picture_in_picture_napi/inner/js_pip_manager.h +++ b/interfaces/kits/napi/picture_in_picture_napi/inner/js_pip_manager.h @@ -32,6 +32,7 @@ public: static napi_value RegisterCallback(napi_env env, napi_callback_info info); static napi_value UnregisterCallback(napi_env env, napi_callback_info info); static napi_value SetTypeNodeEnabled(napi_env env, napi_callback_info info); + static napi_value ResetNodeType(napi_env env, napi_callback_info info); private: napi_value OnInitXComponentController(napi_env env, napi_callback_info info); napi_value OnGetCustomUIController(napi_env env, napi_callback_info info); @@ -39,6 +40,7 @@ private: napi_value OnRegisterCallback(napi_env env, napi_callback_info info); napi_value OnUnregisterCallback(napi_env env, napi_callback_info info); napi_value OnSetTypeNodeEnabled(napi_env env, napi_callback_info info); + napi_value OnResetNodeType(napi_env env, napi_callback_info info); }; } // namespace Rosen } // namespace OHOS diff --git a/interfaces/kits/napi/picture_in_picture_napi/js_pip_window_manager.cpp b/interfaces/kits/napi/picture_in_picture_napi/js_pip_window_manager.cpp index ae1a8faeab..32d120aef3 100644 --- a/interfaces/kits/napi/picture_in_picture_napi/js_pip_window_manager.cpp +++ b/interfaces/kits/napi/picture_in_picture_napi/js_pip_window_manager.cpp @@ -281,6 +281,7 @@ napi_value JsPipWindowManager::OnCreatePipController(napi_env env, napi_callback if (typeNode != nullptr && GetType(env, typeNode) != napi_undefined) { TLOGI(WmsLogTag::WMS_PIP, "typeNode enabled"); pipOption.SetTypeNodeEnabled(true); + XComponentController::SetSurfaceCallbackTypeMode(env, typeNode, SurfaceCallbackMode::PIP); napi_create_reference(env, typeNode, 1, &typeNodeRef); pipOption.SetTypeNodeRef(typeNodeRef); } else { diff --git a/resources/abc/pip/interface/PiPContent.js b/resources/abc/pip/interface/PiPContent.js index e45215a4f0..9010886ec4 100644 --- a/resources/abc/pip/interface/PiPContent.js +++ b/resources/abc/pip/interface/PiPContent.js @@ -99,6 +99,9 @@ export class PiPContent extends ViewPU { return; } this.useNode = true; + if (this.xComponent.getParent() === null || this.xComponent.getParent() === undefined) { + pip.resetNodeType(this.xComponent); + } pip.setTypeNodeEnabled(); this.mXCNodeController = new XCNodeController(this.xComponent); console.info(TAG, 'use Node Controller'); diff --git a/resources/abc/pip/source/PiPContent.ets b/resources/abc/pip/source/PiPContent.ets index 258303c1c2..242374a028 100644 --- a/resources/abc/pip/source/PiPContent.ets +++ b/resources/abc/pip/source/PiPContent.ets @@ -63,6 +63,9 @@ export struct PiPContent { return; } this.useNode = true; + if (this.xComponent.getParent() === null || this.xComponent.getParent() === undefined) { + pip.resetNodeType(this.xComponent); + } pip.setTypeNodeEnabled(); this.mXCNodeController = new XCNodeController(this.xComponent); console.info(TAG, 'use Node Controller');