From 46b96f593a28a4f509c97e3d12673a6225795966 Mon Sep 17 00:00:00 2001 From: yangziyong Date: Fri, 22 Mar 2024 16:19:27 +0800 Subject: [PATCH] =?UTF-8?q?Modifier,blur=E5=92=8Cbackdrop=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0BlurOptions=E5=8F=AF=E9=80=89=E5=8F=82=E6=95=B0?= =?UTF-8?q?=EF=BC=8Cinvert=E6=B7=BB=E5=8A=A0=E6=94=AF=E6=8C=81InvertOption?= =?UTF-8?q?s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yangziyong --- .../ark_component/src/ArkClassDefine.ts | 22 ++++++ .../ark_component/src/ArkComponent.ts | 70 +++++++++++------- .../engine/arkComponent.js | 72 +++++++++++++------ .../arkts_native_common_bridge.cpp | 71 ++++++++++++++---- .../core/components_ng/base/view_abstract.cpp | 8 +-- .../core/components_ng/base/view_abstract.h | 4 +- .../core/interfaces/arkoala/arkoala_api.h | 8 ++- .../native/node/node_common_modifier.cpp | 47 ++++++++---- interfaces/native/node/style_modifier.cpp | 7 +- .../core/base/view_abstract_test_ng.cpp | 4 +- 10 files changed, 227 insertions(+), 86 deletions(-) diff --git a/frameworks/bridge/declarative_frontend/ark_component/src/ArkClassDefine.ts b/frameworks/bridge/declarative_frontend/ark_component/src/ArkClassDefine.ts index 5c6cb4772d7..d346ac04c77 100644 --- a/frameworks/bridge/declarative_frontend/ark_component/src/ArkClassDefine.ts +++ b/frameworks/bridge/declarative_frontend/ark_component/src/ArkClassDefine.ts @@ -374,6 +374,28 @@ class ArkScrollEdgeEffect { } } +class ArkBlurOptions{ + value: number; + options?: BlurOptions | undefined; + constructor() { + this.value = undefined; + this.options = undefined; + } +} + +class InvertOptions{ + high: number; + low: number; + threshold: number; + thresholdRange: number; + constructor() { + this.high = undefined; + this.low = undefined; + this.threshold = undefined; + this.thresholdRange = undefined; + } +} + class ArkMenuAlignType { alignType: number | MenuAlignType; dx: Length; diff --git a/frameworks/bridge/declarative_frontend/ark_component/src/ArkComponent.ts b/frameworks/bridge/declarative_frontend/ark_component/src/ArkComponent.ts index f9d9d4fe37f..66b911bebfc 100644 --- a/frameworks/bridge/declarative_frontend/ark_component/src/ArkComponent.ts +++ b/frameworks/bridge/declarative_frontend/ark_component/src/ArkComponent.ts @@ -505,8 +505,8 @@ class AlignModifier extends ModifierWithKey { } } -class BackdropBlurModifier extends ModifierWithKey { - constructor(value: number) { +class BackdropBlurModifier extends ModifierWithKey { + constructor(value: ArkBlurOptions) { super(value); } static identity: Symbol = Symbol('backdropBlur'); @@ -514,9 +514,13 @@ class BackdropBlurModifier extends ModifierWithKey { if (reset) { getUINativeModule().common.resetBackdropBlur(node); } else { - getUINativeModule().common.setBackdropBlur(node, this.value); + getUINativeModule().common.setBackdropBlur(node, this.value.value, this.value.options?.grayscale); } } + checkObjectDiff(): boolean { + return !((this.stageValue.value === this.value.value) && + (this.stageValue.options === this.value.options)); + } } class HueRotateModifier extends ModifierWithKey { @@ -533,8 +537,8 @@ class HueRotateModifier extends ModifierWithKey { } } -class InvertModifier extends ModifierWithKey { - constructor(value: number) { +class InvertModifier extends ModifierWithKey { + constructor(value: number | InvertOptions) { super(value); } static identity: Symbol = Symbol('invert'); @@ -542,9 +546,23 @@ class InvertModifier extends ModifierWithKey { if (reset) { getUINativeModule().common.resetInvert(node); } else { - getUINativeModule().common.setInvert(node, this.value); + if(isNumber(this.value)) { + getUINativeModule().common.setInvert(node, this.value, undefined, undefined, undefined, undefined); + } else { + getUINativeModule().common.setInvert(node, undefined, + (this.value as InvertOptions).low, + (this.value as InvertOptions).high, + (this.value as InvertOptions).threshold, + (this.value as InvertOptions).thresholdRange); + } } } + checkObjectDiff(): boolean { + return !((this.stageValue as InvertOptions).high == (this.value as InvertOptions).high && + (this.stageValue as InvertOptions).low == (this.value as InvertOptions).low && + (this.stageValue as InvertOptions).threshold == (this.value as InvertOptions).threshold && + (this.stageValue as InvertOptions).thresholdRange == (this.value as InvertOptions).thresholdRange); + } } class SepiaModifier extends ModifierWithKey { @@ -635,8 +653,8 @@ class BrightnessModifier extends ModifierWithKey { } } -class BlurModifier extends ModifierWithKey { - constructor(value: number) { +class BlurModifier extends ModifierWithKey { + constructor(value: ArkBlurOptions) { super(value); } static identity: Symbol = Symbol('blur'); @@ -644,9 +662,13 @@ class BlurModifier extends ModifierWithKey { if (reset) { getUINativeModule().common.resetBlur(node); } else { - getUINativeModule().common.setBlur(node, this.value); + getUINativeModule().common.setBlur(node, this.value.value, this.value.options?.grayscale); } } + checkObjectDiff(): boolean { + return !((this.stageValue.value === this.value.value) && + (this.stageValue.options === this.value.options)); + } } class LinearGradientModifier extends ModifierWithKey<{ @@ -2883,12 +2905,11 @@ class ArkComponent implements CommonMethod { throw new Error('Method not implemented.'); } - blur(value: number): this { - if (!isNumber(value)) { - modifierWithKey(this._modifiersWithKeys, BlurModifier.identity, BlurModifier, undefined); - } else { - modifierWithKey(this._modifiersWithKeys, BlurModifier.identity, BlurModifier, value); - } + blur(value: number, options?: BlurOptions): this { + let blur: ArkBlurOptions = new ArkBlurOptions(); + blur.value = value; + blur.options = options; + modifierWithKey(this._modifiersWithKeys, BlurModifier.identity, BlurModifier, blur); return this; } @@ -2957,11 +2978,11 @@ class ArkComponent implements CommonMethod { return this; } - invert(value: number): this { - if (!isNumber(value)) { - modifierWithKey(this._modifiersWithKeys, InvertModifier.identity, InvertModifier, undefined); - } else { + invert(value: number | InvertOptions): this { + if (!isUndefined(value)) { modifierWithKey(this._modifiersWithKeys, InvertModifier.identity, InvertModifier, value); + } else { + modifierWithKey(this._modifiersWithKeys, InvertModifier.identity, InvertModifier, undefined); } return this; } @@ -2980,12 +3001,11 @@ class ArkComponent implements CommonMethod { return this; } - backdropBlur(value: number): this { - if (!isNumber(value)) { - modifierWithKey(this._modifiersWithKeys, BackdropBlurModifier.identity, BackdropBlurModifier, undefined); - } else { - modifierWithKey(this._modifiersWithKeys, BackdropBlurModifier.identity, BackdropBlurModifier, value); - } + backdropBlur(value: number, options?: BlurOptions): this { + let blur: ArkBlurOptions = new ArkBlurOptions(); + blur.value = value; + blur.options = options; + modifierWithKey(this._modifiersWithKeys, BackdropBlurModifier.identity, BackdropBlurModifier, blur); return this; } diff --git a/frameworks/bridge/declarative_frontend/engine/arkComponent.js b/frameworks/bridge/declarative_frontend/engine/arkComponent.js index b4767ca931a..1bd78208549 100644 --- a/frameworks/bridge/declarative_frontend/engine/arkComponent.js +++ b/frameworks/bridge/declarative_frontend/engine/arkComponent.js @@ -476,9 +476,14 @@ class BackdropBlurModifier extends ModifierWithKey { getUINativeModule().common.resetBackdropBlur(node); } else { - getUINativeModule().common.setBackdropBlur(node, this.value); + getUINativeModule().common.setBackdropBlur( + node, this.value.value, (_a = this.value.options) === null || _a === void 0 ? void 0 : _a.grayscale); } } + checkObjectDiff() { + return !((this.stageValue.value === this.value.value) && + (this.stageValue.options === this.value.options)); + } } BackdropBlurModifier.identity = Symbol('backdropBlur'); class HueRotateModifier extends ModifierWithKey { @@ -504,9 +509,21 @@ class InvertModifier extends ModifierWithKey { getUINativeModule().common.resetInvert(node); } else { - getUINativeModule().common.setInvert(node, this.value); + if (isNumber(this.value)) { + getUINativeModule().common.setInvert(node, this.value, undefined, undefined, undefined, undefined); + } + else { + getUINativeModule().common.setInvert( + node, undefined, this.value.low, this.value.high, this.value.threshold, this.value.thresholdRange); + } } } + checkObjectDiff() { + return !(this.stageValue.high == this.value.high && + this.stageValue.low == this.value.low && + this.stageValue.threshold == this.value.threshold && + this.stageValue.thresholdRange == this.value.thresholdRange); + } } InvertModifier.identity = Symbol('invert'); class SepiaModifier extends ModifierWithKey { @@ -605,9 +622,14 @@ class BlurModifier extends ModifierWithKey { getUINativeModule().common.resetBlur(node); } else { - getUINativeModule().common.setBlur(node, this.value); + getUINativeModule().common.setBlur( + node, this.value.value, (_a = this.value.options) === null || _a === void 0 ? void 0 : _a.grayscale); } } + checkObjectDiff() { + return !((this.stageValue.value === this.value.value) && + (this.stageValue.options === this.value.options)); + } } BlurModifier.identity = Symbol('blur'); class LinearGradientModifier extends ModifierWithKey { @@ -2795,13 +2817,11 @@ class ArkComponent { parallelGesture(gesture, mask) { throw new Error('Method not implemented.'); } - blur(value) { - if (!isNumber(value)) { - modifierWithKey(this._modifiersWithKeys, BlurModifier.identity, BlurModifier, undefined); - } - else { - modifierWithKey(this._modifiersWithKeys, BlurModifier.identity, BlurModifier, value); - } + blur(value, options) { + let blur = new ArkBlurOptions(); + blur.value = value; + blur.options = options; + modifierWithKey(this._modifiersWithKeys, BlurModifier.identity, BlurModifier, blur); return this; } linearGradientBlur(value, options) { @@ -2866,11 +2886,11 @@ class ArkComponent { return this; } invert(value) { - if (!isNumber(value)) { - modifierWithKey(this._modifiersWithKeys, InvertModifier.identity, InvertModifier, undefined); + if (!isUndefined(value)) { + modifierWithKey(this._modifiersWithKeys, InvertModifier.identity, InvertModifier, value); } else { - modifierWithKey(this._modifiersWithKeys, InvertModifier.identity, InvertModifier, value); + modifierWithKey(this._modifiersWithKeys, InvertModifier.identity, InvertModifier, undefined); } return this; } @@ -2887,13 +2907,11 @@ class ArkComponent { modifierWithKey(this._modifiersWithKeys, UseEffectModifier.identity, UseEffectModifier, value); return this; } - backdropBlur(value) { - if (!isNumber(value)) { - modifierWithKey(this._modifiersWithKeys, BackdropBlurModifier.identity, BackdropBlurModifier, undefined); - } - else { - modifierWithKey(this._modifiersWithKeys, BackdropBlurModifier.identity, BackdropBlurModifier, value); - } + backdropBlur(value, options) { + let blur = new ArkBlurOptions(); + blur.value = value; + blur.options = options; + modifierWithKey(this._modifiersWithKeys, BackdropBlurModifier.identity, BackdropBlurModifier, blur); return this; } renderGroup(value) { @@ -9104,6 +9122,20 @@ class ArkScrollEdgeEffect { (this.options === another.options); } } +class ArkBlurOptions { + constructor() { + this.value = undefined; + this.options = undefined; + } +} +class InvertOptions { + constructor() { + this.high = undefined; + this.low = undefined; + this.threshold = undefined; + this.thresholdRange = undefined; + } +} class ArkMenuAlignType { constructor(alignType, offset) { this.alignType = alignType; diff --git a/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_common_bridge.cpp b/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_common_bridge.cpp index 04676fe1b8b..a4957f7639c 100644 --- a/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_common_bridge.cpp +++ b/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_common_bridge.cpp @@ -1889,13 +1889,21 @@ ArkUINativeModuleValue CommonBridge::SetBackdropBlur(ArkUIRuntimeCallInfo *runti EcmaVM *vm = runtimeCallInfo->GetVM(); CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr)); Local firstArg = runtimeCallInfo->GetCallArgRef(NUM_0); - Local secondArg = runtimeCallInfo->GetCallArgRef(NUM_1); + Local blurArg = runtimeCallInfo->GetCallArgRef(NUM_1); + Local blurOptionArg = runtimeCallInfo->GetCallArgRef(NUM_2); auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value()); - if (secondArg->IsNumber()) { - GetArkUINodeModifiers()->getCommonModifier()->setBackdropBlur(nativeNode, secondArg->ToNumber(vm)->Value()); - } else { + + double blur = 0.0; + if (!ArkTSUtils::ParseJsDouble(vm, blurArg, blur)) { GetArkUINodeModifiers()->getCommonModifier()->resetBackdropBlur(nativeNode); + return panda::JSValueRef::Undefined(vm); } + BlurOption blurOption; + if (blurOptionArg->IsArray(vm)) { + ParseBlurOption(vm, blurOptionArg, blurOption); + } + GetArkUINodeModifiers()->getCommonModifier()->setBackdropBlur( + nativeNode, blur, blurOption.grayscale.data(), blurOption.grayscale.size()); return panda::JSValueRef::Undefined(vm); } @@ -1947,16 +1955,45 @@ ArkUINativeModuleValue CommonBridge::ResetHueRotate(ArkUIRuntimeCallInfo *runtim ArkUINativeModuleValue CommonBridge::SetInvert(ArkUIRuntimeCallInfo *runtimeCallInfo) { - EcmaVM *vm = runtimeCallInfo->GetVM(); + EcmaVM* vm = runtimeCallInfo->GetVM(); CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr)); Local firstArg = runtimeCallInfo->GetCallArgRef(NUM_0); - Local secondArg = runtimeCallInfo->GetCallArgRef(NUM_1); + Local invertValueArg = runtimeCallInfo->GetCallArgRef(NUM_1); + Local optionLowArg = runtimeCallInfo->GetCallArgRef(NUM_2); + Local optionHighArg = runtimeCallInfo->GetCallArgRef(NUM_3); + Local optionThresholdArg = runtimeCallInfo->GetCallArgRef(NUM_4); + Local optionThresholdRangeArg = runtimeCallInfo->GetCallArgRef(NUM_5); auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value()); - if (secondArg->IsNumber()) { - GetArkUINodeModifiers()->getCommonModifier()->setInvert(nativeNode, secondArg->ToNumber(vm)->Value()); + + if (!invertValueArg->IsUndefined()) { + double invertValue = 0.0; + if (ArkTSUtils::ParseJsDouble(vm, invertValueArg, invertValue)) { + ArkUI_Float32 invert[] = { invertValue }; + GetArkUINodeModifiers()->getCommonModifier()->setInvert(nativeNode, invert, NUM_1); + } else { + GetArkUINodeModifiers()->getCommonModifier()->resetInvert(nativeNode); + } } else { - GetArkUINodeModifiers()->getCommonModifier()->resetInvert(nativeNode); + ArkUI_Float32 invert[] = { 0.0, 0.0, 0.0, 0.0 }; + double low = 0.0; + double high = 0.0; + double threshold = 0.0; + double thresholdRange = 0.0; + if (ArkTSUtils::ParseJsDouble(vm, optionLowArg, low)) { + invert[NUM_0] = std::clamp(low, 0.0, 1.0); + } + if (ArkTSUtils::ParseJsDouble(vm, optionHighArg, high)) { + invert[NUM_1] = std::clamp(high, 0.0, 1.0); + } + if (ArkTSUtils::ParseJsDouble(vm, optionThresholdArg, threshold)) { + invert[NUM_2] = std::clamp(threshold, 0.0, 1.0); + } + if (ArkTSUtils::ParseJsDouble(vm, optionThresholdRangeArg, thresholdRange)) { + invert[NUM_3] = std::clamp(thresholdRange, 0.0, 1.0); + } + GetArkUINodeModifiers()->getCommonModifier()->setInvert(nativeNode, invert, NUM_4); } + return panda::JSValueRef::Undefined(vm); } @@ -2126,13 +2163,21 @@ ArkUINativeModuleValue CommonBridge::SetBlur(ArkUIRuntimeCallInfo *runtimeCallIn EcmaVM *vm = runtimeCallInfo->GetVM(); CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr)); Local firstArg = runtimeCallInfo->GetCallArgRef(NUM_0); - Local secondArg = runtimeCallInfo->GetCallArgRef(NUM_1); + Local blurArg = runtimeCallInfo->GetCallArgRef(NUM_1); + Local blurOptionArg = runtimeCallInfo->GetCallArgRef(NUM_2); auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value()); - if (secondArg->IsNumber()) { - GetArkUINodeModifiers()->getCommonModifier()->setBlur(nativeNode, secondArg->ToNumber(vm)->Value()); - } else { + double blur = 0.0; + if (!ArkTSUtils::ParseJsDouble(vm, blurArg, blur)) { GetArkUINodeModifiers()->getCommonModifier()->resetBlur(nativeNode); + return panda::JSValueRef::Undefined(vm); } + BlurOption blurOption; + if (blurOptionArg->IsArray(vm)) { + ParseBlurOption(vm, blurOptionArg, blurOption); + } + GetArkUINodeModifiers()->getCommonModifier()->setBlur( + nativeNode, blur, blurOption.grayscale.data(), blurOption.grayscale.size()); + return panda::JSValueRef::Undefined(vm); } diff --git a/frameworks/core/components_ng/base/view_abstract.cpp b/frameworks/core/components_ng/base/view_abstract.cpp index 60955c8424d..4872417be92 100755 --- a/frameworks/core/components_ng/base/view_abstract.cpp +++ b/frameworks/core/components_ng/base/view_abstract.cpp @@ -1601,7 +1601,7 @@ void ViewAbstract::SetBackdropBlur(const Dimension &radius, const BlurOption &bl } } -void ViewAbstract::SetBackdropBlur(FrameNode *frameNode, const Dimension &radius) +void ViewAbstract::SetBackdropBlur(FrameNode *frameNode, const Dimension &radius, const BlurOption &blurOption) { CHECK_NULL_VOID(frameNode); auto target = frameNode->GetRenderContext(); @@ -1609,7 +1609,7 @@ void ViewAbstract::SetBackdropBlur(FrameNode *frameNode, const Dimension &radius if (target->GetBackgroundEffect().has_value()) { target->UpdateBackgroundEffect(std::nullopt); } - target->UpdateBackBlurRadius(radius); + target->UpdateBackBlur(radius, blurOption); if (target->GetBackBlurStyle().has_value()) { target->UpdateBackBlurStyle(std::nullopt); } @@ -1649,12 +1649,12 @@ void ViewAbstract::SetFrontBlur(const Dimension &radius, const BlurOption &blurO } } -void ViewAbstract::SetFrontBlur(FrameNode *frameNode, const Dimension &radius) +void ViewAbstract::SetFrontBlur(FrameNode *frameNode, const Dimension &radius, const BlurOption &blurOption) { CHECK_NULL_VOID(frameNode); auto target = frameNode->GetRenderContext(); if (target) { - target->UpdateFrontBlurRadius(radius); + target->UpdateFrontBlur(radius, blurOption); if (target->GetFrontBlurStyle().has_value()) { target->UpdateFrontBlurStyle(std::nullopt); } diff --git a/frameworks/core/components_ng/base/view_abstract.h b/frameworks/core/components_ng/base/view_abstract.h index 9342234b2c5..e083ce1daa5 100644 --- a/frameworks/core/components_ng/base/view_abstract.h +++ b/frameworks/core/components_ng/base/view_abstract.h @@ -398,7 +398,7 @@ public: static void SetOpacity(FrameNode* frameNode, double opacity); static void SetZIndex(FrameNode* frameNode, int32_t value); static void SetAlign(FrameNode* frameNode, Alignment alignment); - static void SetBackdropBlur(FrameNode* frameNode, const Dimension& radius); + static void SetBackdropBlur(FrameNode* frameNode, const Dimension& radius, const BlurOption &blurOption); static void SetInvert(FrameNode* frameNode, const InvertVariant& invert); static void SetSepia(FrameNode* frameNode, const Dimension& sepia); static void SetSaturate(FrameNode* frameNode, const Dimension& saturate); @@ -406,7 +406,7 @@ public: static void SetGrayScale(FrameNode* frameNode, const Dimension& grayScale); static void SetContrast(FrameNode* frameNode, const Dimension& contrast); static void SetBrightness(FrameNode* frameNode, const Dimension& brightness); - static void SetFrontBlur(FrameNode* frameNode, const Dimension& radius); + static void SetFrontBlur(FrameNode* frameNode, const Dimension& radius, const BlurOption &blurOption); static void SetHueRotate(FrameNode* frameNode, float hueRotate); static void SetLinearGradient(FrameNode* frameNode, const NG::Gradient& gradient); static void SetSweepGradient(FrameNode* frameNode, const NG::Gradient& gradient); diff --git a/frameworks/core/interfaces/arkoala/arkoala_api.h b/frameworks/core/interfaces/arkoala/arkoala_api.h index cb50a41ec19..8c885ea23de 100644 --- a/frameworks/core/interfaces/arkoala/arkoala_api.h +++ b/frameworks/core/interfaces/arkoala/arkoala_api.h @@ -1010,11 +1010,12 @@ struct ArkUICommonModifier { void (*resetOpacity)(ArkUINodeHandle node); void (*setAlign)(ArkUINodeHandle node, ArkUI_Int32 align); void (*resetAlign)(ArkUINodeHandle node); - void (*setBackdropBlur)(ArkUINodeHandle node, ArkUI_Float32 value); + void (*setBackdropBlur)( + ArkUINodeHandle node, ArkUI_Float32 value, const ArkUI_Float32* blurValues, ArkUI_Int32 blurValuesSize); void (*resetBackdropBlur)(ArkUINodeHandle node); void (*setHueRotate)(ArkUINodeHandle node, ArkUI_Float32 deg); void (*resetHueRotate)(ArkUINodeHandle node); - void (*setInvert)(ArkUINodeHandle node, ArkUI_Float32 invert); + void (*setInvert)(ArkUINodeHandle node, ArkUI_Float32* invert, ArkUI_Int32 length); void (*resetInvert)(ArkUINodeHandle node); void (*setSepia)(ArkUINodeHandle node, ArkUI_Float32 sepia); void (*resetSepia)(ArkUINodeHandle node); @@ -1028,7 +1029,8 @@ struct ArkUICommonModifier { void (*resetContrast)(ArkUINodeHandle node); void (*setBrightness)(ArkUINodeHandle node, ArkUI_Float32 brightness); void (*resetBrightness)(ArkUINodeHandle node); - void (*setBlur)(ArkUINodeHandle node, ArkUI_Float32 value); + void (*setBlur)( + ArkUINodeHandle node, ArkUI_Float32 value, const ArkUI_Float32* blurValues, ArkUI_Int32 blurValuesSize); void (*resetBlur)(ArkUINodeHandle node); void (*setLinearGradient)(ArkUINodeHandle node, const ArkUI_Float32* values, ArkUI_Int32 valuesLength, const ArkUIInt32orFloat32* colors, ArkUI_Int32 colorsLength); diff --git a/frameworks/core/interfaces/native/node/node_common_modifier.cpp b/frameworks/core/interfaces/native/node/node_common_modifier.cpp index 5f285d25d93..61bbb7b4fe5 100644 --- a/frameworks/core/interfaces/native/node/node_common_modifier.cpp +++ b/frameworks/core/interfaces/native/node/node_common_modifier.cpp @@ -1008,7 +1008,8 @@ void ResetAlign(ArkUINodeHandle node) ViewAbstract::SetAlign(frameNode, Alignment::CENTER); } -void SetBackdropBlur(ArkUINodeHandle node, ArkUI_Float32 value) +void SetBackdropBlur( + ArkUINodeHandle node, ArkUI_Float32 value, const ArkUI_Float32* blurValues, ArkUI_Int32 blurValuesSize) { ArkUI_Float32 blur = 0.0f; auto* frameNode = reinterpret_cast(node); @@ -1016,8 +1017,10 @@ void SetBackdropBlur(ArkUINodeHandle node, ArkUI_Float32 value) if (value > 0) { blur = value; } + BlurOption blurOption; + blurOption.grayscale.assign(blurValues, blurValues + blurValuesSize); CalcDimension dimensionRadius(blur, DimensionUnit::PX); - ViewAbstract::SetBackdropBlur(frameNode, dimensionRadius); + ViewAbstract::SetBackdropBlur(frameNode, dimensionRadius, blurOption); } void ResetBackdropBlur(ArkUINodeHandle node) @@ -1025,8 +1028,9 @@ void ResetBackdropBlur(ArkUINodeHandle node) auto* frameNode = reinterpret_cast(node); CHECK_NULL_VOID(frameNode); double blur = 0.0; + BlurOption option; CalcDimension dimensionRadius(blur, DimensionUnit::PX); - ViewAbstract::SetBackdropBlur(frameNode, dimensionRadius); + ViewAbstract::SetBackdropBlur(frameNode, dimensionRadius, option); } void SetHueRotate(ArkUINodeHandle node, ArkUI_Float32 deg) @@ -1048,11 +1052,21 @@ void ResetHueRotate(ArkUINodeHandle node) ViewAbstract::SetHueRotate(frameNode, deg); } -void SetInvert(ArkUINodeHandle node, ArkUI_Float32 invert) +void SetInvert(ArkUINodeHandle node, ArkUI_Float32* invert, ArkUI_Int32 length) { auto* frameNode = reinterpret_cast(node); CHECK_NULL_VOID(frameNode); - InvertVariant invertVariant = static_cast(invert); + InvertVariant invertVariant; + if (length == NUM_4) { + InvertOption option; + option.low_ = invert[NUM_0]; + option.high_ = invert[NUM_1]; + option.threshold_ = invert[NUM_2]; + option.thresholdRange_ = invert[NUM_3]; + invertVariant = option; + } else { + invertVariant = invert[NUM_0]; + } ViewAbstract::SetInvert(frameNode, invertVariant); } @@ -1177,16 +1191,18 @@ void ResetBrightness(ArkUINodeHandle node) ViewAbstract::SetBrightness(frameNode, value); } -void SetBlur(ArkUINodeHandle node, ArkUI_Float32 value) +void SetBlur(ArkUINodeHandle node, ArkUI_Float32 value, const ArkUI_Float32* blurValues, ArkUI_Int32 blurValuesSize) { auto* frameNode = reinterpret_cast(node); CHECK_NULL_VOID(frameNode); ArkUI_Float32 blur = 0.0f; + BlurOption blurOption; + blurOption.grayscale.assign(blurValues, blurValues + blurValuesSize); if (value > 0) { blur = value; } CalcDimension dimensionBlur(blur, DimensionUnit::PX); - ViewAbstract::SetFrontBlur(frameNode, dimensionBlur); + ViewAbstract::SetFrontBlur(frameNode, dimensionBlur, blurOption); } void ResetBlur(ArkUINodeHandle node) @@ -1194,8 +1210,9 @@ void ResetBlur(ArkUINodeHandle node) auto* frameNode = reinterpret_cast(node); CHECK_NULL_VOID(frameNode); double blur = 0.0; + BlurOption option; CalcDimension dimensionBlur(blur, DimensionUnit::PX); - ViewAbstract::SetFrontBlur(frameNode, dimensionBlur); + ViewAbstract::SetFrontBlur(frameNode, dimensionBlur, option); } /** @@ -2826,11 +2843,9 @@ void SetFlexBasis(ArkUINodeHandle node, const struct ArkUIStringAndFloat* flexBa Dimension result; if (flexBasisValue->valueStr != nullptr) { result = StringUtils::StringToDimensionWithUnit(std::string(flexBasisValue->valueStr), DimensionUnit::VP); - if (Container::LessThanAPIVersion(PlatformVersion::VERSION_TEN)) { - // flexbasis don't support percent case. - if (result.Unit() == DimensionUnit::PERCENT) { - result.SetUnit(DimensionUnit::AUTO); - } + // flexbasis don't support percent case. + if (result.Unit() == DimensionUnit::PERCENT) { + result.SetUnit(DimensionUnit::AUTO); } } else { result = Dimension(flexBasisValue->value, DimensionUnit::VP); @@ -4173,14 +4188,16 @@ void SetBlendMode(ArkUINodeHandle node, int32_t blendMode, ArkUI_Int32 blendAppl { auto* frameNode = reinterpret_cast(node); CHECK_NULL_VOID(frameNode); - ViewAbstract::SetBlendMode(frameNode, static_cast(blendMode)); + ViewAbstractModelNG::SetBlendMode(frameNode, static_cast(blendMode)); + ViewAbstractModelNG::SetBlendApplyType(frameNode, static_cast(blendApplyTypeValue)); } void ResetBlendMode(ArkUINodeHandle node) { auto* frameNode = reinterpret_cast(node); CHECK_NULL_VOID(frameNode); - ViewAbstract::SetBlendMode(frameNode, BlendMode::NONE); + ViewAbstractModelNG::SetBlendMode(frameNode, OHOS::Ace::BlendMode::NONE); + ViewAbstractModelNG::SetBlendApplyType(frameNode, OHOS::Ace::BlendApplyType::FAST); } void SetConstraintSize(ArkUINodeHandle node, const ArkUI_Float32* values, const ArkUI_Int32* units) diff --git a/interfaces/native/node/style_modifier.cpp b/interfaces/native/node/style_modifier.cpp index 795bfc75c18..2e8d2f34ad4 100644 --- a/interfaces/native/node/style_modifier.cpp +++ b/interfaces/native/node/style_modifier.cpp @@ -997,7 +997,9 @@ int32_t SetBlur(ArkUI_NodeHandle node, const ArkUI_AttributeItem* item) } auto fullImpl = GetFullImpl(); ArkUI_Float64 blur = item->value[NUM_0].f32; - fullImpl->getNodeModifiers()->getCommonModifier()->setBlur(node->uiNodeHandle, blur); + BlurOption blurOption; + fullImpl->getNodeModifiers()->getCommonModifier()->setBlur( + node->uiNodeHandle, blur, blurOption.grayscale.data(), blurOption.grayscale.size()); return ERROR_CODE_NO_ERROR; } @@ -2467,7 +2469,8 @@ int32_t SetInvert(ArkUI_NodeHandle node, const ArkUI_AttributeItem* item) return ERROR_CODE_PARAM_INVALID; } auto fullImpl = GetFullImpl(); - fullImpl->getNodeModifiers()->getCommonModifier()->setInvert(node->uiNodeHandle, item->value[0].f32); + ArkUI_Float32 invert[] = { item->value[0].f32 }; + fullImpl->getNodeModifiers()->getCommonModifier()->setInvert(node->uiNodeHandle, invert, NUM_1); return ERROR_CODE_NO_ERROR; } diff --git a/test/unittest/core/base/view_abstract_test_ng.cpp b/test/unittest/core/base/view_abstract_test_ng.cpp index b55db761868..82f41461e43 100644 --- a/test/unittest/core/base/view_abstract_test_ng.cpp +++ b/test/unittest/core/base/view_abstract_test_ng.cpp @@ -818,9 +818,9 @@ HWTEST_F(ViewAbstractTestNg, ViewAbstractTest015, TestSize.Level1) Matrix4 matrix; ViewAbstract::SetTransformMatrix(std::move(matrix)); ViewAbstract::SetBackdropBlur(RADIUS, blurOption); - ViewAbstract::SetBackdropBlur(nullptr, RADIUS); + ViewAbstract::SetBackdropBlur(nullptr, RADIUS, blurOption); ViewAbstract::SetFrontBlur(RADIUS, blurOption); - ViewAbstract::SetFrontBlur(nullptr, RADIUS); + ViewAbstract::SetFrontBlur(nullptr, RADIUS, blurOption); ViewAbstract::SetInspectorId(srcimages); Vector5F scale(1.0f, 1.0f, 2.0f, 2.0f, 0.0f);