From a2952981b3b853798cc41c05617939e9485b2402 Mon Sep 17 00:00:00 2001 From: "DESKTOP-H8KLN8I\\lisitao" Date: Sat, 28 Jun 2025 17:53:47 +0800 Subject: [PATCH] =?UTF-8?q?[L]=20backgroundimage=20=E6=94=AF=E6=8C=81=20pi?= =?UTF-8?q?xelmap=20=E4=BF=AE=E6=94=B9Signed-off-by:lisitaolisitao3@huawei?= =?UTF-8?q?.com?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: DESKTOP-H8KLN8I\lisitao --- .../src/ani/arkts/ArkUIAniModule.ts | 1 + .../src/ani/native/common/common_module.cpp | 19 +++++++ .../src/ani/native/common/common_module.h | 2 + .../arkui-ohos/src/ani/native/module.cpp | 5 ++ .../arkui-ohos/src/component/common.ts | 12 ++--- .../src/handwritten/ArkBackgroundImageImpl.ts | 51 +++++++++++++++++++ frameworks/core/interfaces/ani/ani_api.h | 1 + .../native/ani/common_ani_modifier.cpp | 26 ++++++++++ 8 files changed, 109 insertions(+), 8 deletions(-) create mode 100644 frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/ArkBackgroundImageImpl.ts diff --git a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/arkts/ArkUIAniModule.ts b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/arkts/ArkUIAniModule.ts index e097ea1146c..636c3c19e02 100644 --- a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/arkts/ArkUIAniModule.ts +++ b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/arkts/ArkUIAniModule.ts @@ -104,6 +104,7 @@ export class ArkUIAniModule { native static _Animation_SetOrCreateAnimatableProperty(ptr: KPointer, propertyName: string, property: number | AnimatableArithmetic, callback: (value: number | AnimatableArithmetic) => void): void + native static _BackgroundImage_PixelMap(ptr: KPointer, pixelmap: image.PixelMap, repeat: KInt): void // for ImageSpan native static _ImageSpan_Set_PixelMap(ptr: KPointer, pixelmap: image.PixelMap): void native static _ImageSpan_SetAlt_PixelMap(ptr: KPointer, pixelmap: image.PixelMap): void diff --git a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/native/common/common_module.cpp b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/native/common/common_module.cpp index f83e220d264..14778aece1b 100644 --- a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/native/common/common_module.cpp +++ b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/native/common/common_module.cpp @@ -20,6 +20,7 @@ #include "load.h" #include "base/utils/utils.h" +#include "pixel_map_taihe_ani.h" namespace OHOS::Ace::Ani { @@ -100,6 +101,24 @@ ani_long BuilderProxyNodeConstruct(ani_env* env, [[maybe_unused]] ani_object ani CHECK_NULL_RETURN(builderProxyNode, nativeObj); return reinterpret_cast(builderProxyNode); } + +void SetBackgroundImagePixelMap([[maybe_unused]] ani_env* env, [[maybe_unused]] ani_object aniClass, ani_object node, + ani_object pixelMap, ani_int repeat) +{ + auto* arkNode = reinterpret_cast(node); + auto pixelMapValue = OHOS::Media::PixelMapTaiheAni::GetNativePixelMap(env, pixelMap); + if (!pixelMapValue) { + return; + } + auto pixelMapPtr = reinterpret_cast(&pixelMapValue); + const auto* modifier = GetNodeAniModifier(); + if (!modifier || !modifier->getCommonAniModifier() || !env) { + return; + } + modifier->getCommonAniModifier()->setBackgroundImagePixelMap( + env, arkNode, reinterpret_cast(pixelMapPtr), repeat); +} + void SetCustomCallback(ani_env* env, ani_object obj, ani_long ptr, ani_fn_object fnObjMeasure, ani_fn_object fnObjLayout) { diff --git a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/native/common/common_module.h b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/native/common/common_module.h index 9845ae19e8a..7641c8b54d5 100644 --- a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/native/common/common_module.h +++ b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/native/common/common_module.h @@ -27,6 +27,8 @@ void SetDrawCallback(ani_env* env, ani_object obj, ani_long ptr, ani_fn_object f void SetDrawModifier(ani_env* env, [[maybe_unused]] ani_object aniClass, ani_long ptr, ani_object drawModifier); void Invalidate(ani_env* env, [[maybe_unused]] ani_object aniClass, ani_long ptr); ani_long BuilderProxyNodeConstruct(ani_env* env, [[maybe_unused]] ani_object aniClass, ani_int id); +void SetBackgroundImagePixelMap([[maybe_unused]] ani_env* env, [[maybe_unused]] ani_object aniClass, ani_object node, + ani_object pixelMap, ani_int repeat); void SetCustomCallback(ani_env* env, ani_object obj, ani_long ptr, ani_fn_object fnObjMeasure, ani_fn_object fnObjLayout); ani_int RequireArkoalaNodeId(ani_env* env, ani_object obj, ani_int capacity); diff --git a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/native/module.cpp b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/native/module.cpp index 79a55e3475b..1282e23e95b 100644 --- a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/native/module.cpp +++ b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/native/module.cpp @@ -189,6 +189,11 @@ ANI_EXPORT ani_status ANI_Constructor(ani_vm* vm, uint32_t* result) nullptr, reinterpret_cast(OHOS::Ace::Ani::SetOrCreateAnimatableProperty) }, + ani_native_function { + "_BackgroundImage_PixelMap", + nullptr, + reinterpret_cast(OHOS::Ace::Ani::SetBackgroundImagePixelMap) + }, ani_native_function { "_DragController_executeDragWithCallback", nullptr, diff --git a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/component/common.ts b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/component/common.ts index b945875fa9a..4154d382f99 100644 --- a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/component/common.ts +++ b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/component/common.ts @@ -56,6 +56,7 @@ import { CommonModifier } from "../CommonModifier" import { AttributeUpdater } from "../ohos.arkui.modifier" import { ArkBaseNode } from "../handwritten/modifiers/ArkBaseNode" import { hookStateStyleImpl } from "../handwritten/ArkStateStyle" +import { hookBackgroundImageImpl } from "../handwritten/ArkBackgroundImageImpl" import { rememberMutableState } from '@koalaui/runtime' import { hookDrawModifierInvalidateImpl, hookDrawModifierAttributeImpl } from "../handwritten/ArkDrawModifierImpl" import { hookDragPreview, hookAllowDropAttribute, hookRegisterOnDragStartImpl } from "../handwritten/ArkDragDrop" @@ -11192,14 +11193,9 @@ export class ArkCommonMethodComponent extends ComponentBase implements CommonMet } public backgroundImage(src: ResourceStr | PixelMap | undefined, repeat?: ImageRepeat | undefined): this { if (this.checkPriority("backgroundImage")) { - const src_type = runtimeType(src) - const repeat_type = runtimeType(repeat) - if (((RuntimeType.STRING == src_type) || (RuntimeType.OBJECT == src_type) || (RuntimeType.OBJECT == src_type) || (RuntimeType.UNDEFINED == src_type)) && ((RuntimeType.NUMBER == repeat_type) || (RuntimeType.OBJECT == repeat_type))) { - const src_casted = src as (ResourceStr | PixelMap | undefined) - const repeat_casted = repeat as (ImageRepeat) - this.getPeer()?.backgroundImage0Attribute(src_casted, repeat_casted) - return this - } + const src_casted = src as (ResourceStr | PixelMap | undefined) + const repeat_casted = repeat as (ImageRepeat | undefined) + hookBackgroundImageImpl(this.getPeer(), src_casted, repeat_casted) } return this } diff --git a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/ArkBackgroundImageImpl.ts b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/ArkBackgroundImageImpl.ts new file mode 100644 index 00000000000..5a6edc39055 --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/ArkBackgroundImageImpl.ts @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { int32 } from "@koalaui/common" +import { contextNode, remember, scheduleCallback } from "@koalaui/runtime" +import { PeerNode, PeerNodeType } from "../PeerNode" +import { rememberMutableState } from '@koalaui/runtime'; +import { KPointer } from "@koalaui/interop" +import { ArkCommonMethodPeer, ResourceStr, CommonMethod, StateStylesOps } from '../component' +import { InteropNativeModule } from "@koalaui/interop" +import { ArkCommonAttributeSet } from "./modifiers/ArkCommonModifier"; +import { PointerStyle, UnifiedData, Summary, PixelMap } from "#external" +import { ImageRepeat } from "../component/enums" +import { TypeChecker } from "#components" +import { runtimeType, RuntimeType } from "@koalaui/interop" +import { ArkUIAniModule } from "arkui.ani" + +export function hookBackgroundImageImpl(node: ArkCommonMethodPeer, src: ResourceStr | PixelMap | undefined, repeat?: ImageRepeat | undefined): void { + const src_type = runtimeType(src) + const repeat_type = runtimeType(repeat) + if (((RuntimeType.STRING == src_type) || (RuntimeType.OBJECT == src_type) || (RuntimeType.OBJECT == src_type) || (RuntimeType.UNDEFINED == src_type)) && ((RuntimeType.NUMBER == repeat_type) || (RuntimeType.OBJECT == repeat_type))) { + const src_casted = src as (ResourceStr | PixelMap | undefined) + const repeat_casted = repeat as (ImageRepeat) + if (TypeChecker.isPixelMap(src_casted, false, false)) { + const src_0 = src as PixelMap + let repeatValue: int32 = 0 + let repeat_type: int32 = RuntimeType.UNDEFINED + repeat_type = runtimeType(repeat) + if ((RuntimeType.UNDEFINED) != (repeat_type)) { + const repeat_value = (repeat as ImageRepeat) + repeatValue = TypeChecker.ImageRepeat_ToNumeric(repeat_value) + } + ArkUIAniModule._BackgroundImage_PixelMap(node.peer.ptr, src_0, repeatValue) + return + } else { + node.backgroundImage0Attribute(src_casted, repeat_casted) + } + } +} \ No newline at end of file diff --git a/frameworks/core/interfaces/ani/ani_api.h b/frameworks/core/interfaces/ani/ani_api.h index 9e2269ff83c..a1bc815987f 100644 --- a/frameworks/core/interfaces/ani/ani_api.h +++ b/frameworks/core/interfaces/ani/ani_api.h @@ -81,6 +81,7 @@ struct ArkUIAniCommonModifier { void (*setDrawCallback)(ani_env* env, ani_long ptr, ani_fn_object fnObj); ArkUI_Int32 (*getCurrentInstanceId)(); ani_long (*builderProxyNodeConstruct)(ArkUI_Int32 id); + void (*setBackgroundImagePixelMap)(ani_env* env, ArkUINodeHandle node, ani_ref pixelMapPtr, ArkUI_Int32 repeat); void (*setCustomCallback)(ani_env* env, ani_long ptr, ani_fn_object fnObjMeasure, ani_fn_object fnObjLayout); ArkUI_Int32 (*requireArkoalaNodeId)(ArkUI_Int32 capacity); }; diff --git a/frameworks/core/interfaces/native/ani/common_ani_modifier.cpp b/frameworks/core/interfaces/native/ani/common_ani_modifier.cpp index da827e6a34b..e4d2840d43c 100644 --- a/frameworks/core/interfaces/native/ani/common_ani_modifier.cpp +++ b/frameworks/core/interfaces/native/ani/common_ani_modifier.cpp @@ -17,10 +17,16 @@ #include #include +#include "ani_utils.h" + #include "base/log/log.h" #include "bridge/arkts_frontend/ani_graphics_module.h" +#include "core/common/container.h" #include "core/common/container_scope.h" +#include "core/components_ng/base/frame_node.h" +#include "core/components_ng/base/view_abstract.h" #include "core/components_ng/pattern/stack/stack_pattern.h" +#include "core/pipeline_ng/pipeline_context.h" #include "frameworks/bridge/arkts_frontend/ani_context_module.h" #include "core/pipeline/base/element_register.h" @@ -75,6 +81,25 @@ ani_long BuilderProxyNodeConstruct(ArkUI_Int32 id) return reinterpret_cast(AceType::RawPtr(proxyNode)); } +void SetBackgroundImagePixelMap(ani_env* env, ArkUINodeHandle node, ani_ref pixelMapPtr, ArkUI_Int32 repeat) +{ + auto frameNode = reinterpret_cast(node); + CHECK_NULL_VOID(frameNode); + auto pixelMapValue = reinterpret_cast(pixelMapPtr); + CHECK_NULL_VOID(pixelMapValue); +#if defined(PIXEL_MAP_SUPPORTED) + auto pixelMap = PixelMap::CreatePixelMap(pixelMapValue); + CHECK_NULL_VOID(pixelMap); + ViewAbstract::SetBackgroundImage(frameNode, ImageSourceInfo { pixelMap }); +#endif + auto arkRepeat = static_cast(repeat); + if (arkRepeat >= OHOS::Ace::ImageRepeat::NO_REPEAT && arkRepeat <= OHOS::Ace::ImageRepeat::REPEAT) { + ViewAbstract::SetBackgroundImageRepeat(frameNode, arkRepeat); + } else { + ViewAbstract::SetBackgroundImageRepeat(frameNode, OHOS::Ace::ImageRepeat::NO_REPEAT); + } +} + void SetCustomCallback(ani_env* env, ani_long ptr, ani_fn_object fnObjMeasure, ani_fn_object fnObjLayout) { Framework::AniGraphicsModule::SetCustomCallback(env, ptr, fnObjMeasure, fnObjLayout); @@ -95,6 +120,7 @@ const ArkUIAniCommonModifier* GetCommonAniModifier() .setDrawCallback = OHOS::Ace::NG::SetDrawCallback, .getCurrentInstanceId = OHOS::Ace::NG::GetCurrentInstanceId, .builderProxyNodeConstruct = OHOS::Ace::NG::BuilderProxyNodeConstruct, + .setBackgroundImagePixelMap = OHOS::Ace::NG::SetBackgroundImagePixelMap, .setCustomCallback = OHOS::Ace::NG::SetCustomCallback, .requireArkoalaNodeId = OHOS::Ace::NG::RequireArkoalaNodeId }; return &impl; -- Gitee