diff --git a/build/libace.map b/build/libace.map index 9d0f1153e13406e060e8c3b8b9594e15d55a2db0..5687743cf98435a61f137d91f1ec31ce5bc35823 100644 --- a/build/libace.map +++ b/build/libace.map @@ -249,6 +249,7 @@ OHOS::Ace::Gradient::*; OHOS::Ace::CanvasPath2D::*; OHOS::Ace::NG::Matrix2D::*; + OHOS::Ace::NG::MatrixUtil::*; OHOS::Ace::NG::CanvasPattern::*; OHOS::Ace::NG::OffscreenCanvasPattern::*; OHOS::Ace::DatePickerDialogModel::*; diff --git a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/component/arkui-common.ts b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/component/arkui-common.ts index d3fe870362c7605a4f521e9ba8b324278bbcaa9a..349e2e0536da62df1b88002df459b4985a76079c 100644 --- a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/component/arkui-common.ts +++ b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/component/arkui-common.ts @@ -20,5 +20,5 @@ import { int32, int64, float32 } from "@koalaui/common" import { KInt, KPointer, KBoolean, NativeBuffer, KStringPtr, wrapCallback } from "@koalaui/interop" import { NodeAttach, remember } from "@koalaui/runtime" export interface TransformationMatrix { - matrix4x4: Array; + matrix4Object: int64; } diff --git a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/component/arkui-matrix4.ts b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/component/arkui-matrix4.ts index 923940e6df7559fa6c1e807530570e47e069d7ef..11767942fdcfb259aa80973b60487f33f98e59c9 100644 --- a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/component/arkui-matrix4.ts +++ b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/component/arkui-matrix4.ts @@ -26,17 +26,13 @@ import { Deserializer } from "./peers/Deserializer" import { CallbackTransformer } from "./peers/CallbackTransformer" import { NodeAttach, remember } from "@koalaui/runtime" import { Point } from "./point" -export interface Matrix4Transit { - copy(): Matrix4Transit - invert(): Matrix4Transit - combine(options: Matrix4Transit): Matrix4Transit - translate(options: TranslateOption): Matrix4Transit - scale(options: ScaleOption): Matrix4Transit - skew(x: number, y: number): Matrix4Transit - rotate(options: RotateOption): Matrix4Transit - transformPoint(options: [ number, number ]): [ number, number ] - setPolyToPoly(options: PolyToPolyOptions): Matrix4Transit -} + +import { Matrix4Transit as Matrix4Transit_, TranslateOption as TranslateOption_, ScaleOption as ScaleOption_, RotateOption as RotateOption_, PolyToPolyOptions as PolyToPolyOptions_} from "#external" +export type Matrix4Transit = Matrix4Transit_ +export type TranslateOption = TranslateOption_ +export type ScaleOption = ScaleOption_ +export type RotateOption = RotateOption_ +export type PolyToPolyOptions = PolyToPolyOptions_ export class Matrix4TransitInternal implements MaterializedBase,Matrix4Transit { peer?: Finalizable | undefined = undefined public getPeer(): Finalizable | undefined { @@ -160,30 +156,3 @@ export class Matrix4TransitInternal implements MaterializedBase,Matrix4Transit { return obj } } -export interface TranslateOption { - x?: number; - y?: number; - z?: number; -} -export interface ScaleOption { - x?: number; - y?: number; - z?: number; - centerX?: number; - centerY?: number; -} -export interface RotateOption { - x?: number; - y?: number; - z?: number; - centerX?: number; - centerY?: number; - angle?: number; -} -export interface PolyToPolyOptions { - src: Array; - srcIndex?: number; - dst: Array; - dstIndex?: number; - pointCount?: number; -} 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 50d9945ace1ed2ea9e281eeaa348eea74a1d9e81..0128635673ecdb5611a772fa02329def583565b7 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 @@ -39,7 +39,6 @@ import { PeerNode } from "./../PeerNode" import { ResizableOptions } from "./image" import { Filter, VisualEffect, BrightnessBlender } from "#external" import { FocusBoxStyle, FocusPriority } from "./focus" -import { TransformationMatrix } from "./arkui-common" import { GestureInfo, BaseGestureEvent, GestureJudgeResult, GestureRecognizer, GestureType, GestureMask, TapGestureInterface, LongPressGestureInterface, PanGestureInterface, PinchGestureInterface, SwipeGestureInterface, RotationGestureInterface, GestureGroupInterface, GestureHandler, GesturePriority, Gesture, GestureGroup, GestureGroupHandler } from "./gesture" import { StyledString } from "./styledString" import { Callback_Number_Number_Void } from "./grid" @@ -48,6 +47,7 @@ import { Tuple_Number_Number } from "./arkui-synthetics" import { ButtonType, ButtonStyleMode, ButtonRole } from "./button" import { Callback_Number_Void } from "./alphabetIndexer" import { AnimationRange_Number } from "./type-replacements" +import { Matrix4Transit } from "#external" import { ScrollState } from "./list" import { _animateTo, _animationStart, _animationStop } from "./../handwritten/ArkAnimation" import { GlobalScope } from "./GlobalScope" @@ -3907,14 +3907,15 @@ export class ArkCommonMethodPeer extends PeerNode { ArkUIGeneratedNativeModule._CommonMethod_rotate1(this.peer.ptr, thisSerializer.asBuffer(), thisSerializer.length()) thisSerializer.release() } - transform0Attribute(value: TransformationMatrix | undefined): void { + transform0Attribute(value: object | undefined): void { const thisSerializer : Serializer = Serializer.hold() let value_type : int32 = RuntimeType.UNDEFINED value_type = runtimeType(value) thisSerializer.writeInt8(value_type as int32) if ((RuntimeType.UNDEFINED) != (value_type)) { - const value_value = value! - thisSerializer.writeTransformationMatrix(value_value) + const value_curve_value = value! + const value_curve_value_2 = value_curve_value as Matrix4Transit + thisSerializer.writeInt64(Object.values(value_curve_value_2)[0] as int64) } ArkUIGeneratedNativeModule._CommonMethod_transform0(this.peer.ptr, thisSerializer.asBuffer(), thisSerializer.length()) thisSerializer.release() @@ -8065,7 +8066,7 @@ export interface CommonMethod { gridSpan(value: number | undefined): this {return this;} gridOffset(value: number | undefined): this {return this;} rotate(value: RotateOptions | undefined): this {return this;} - transform(value: TransformationMatrix | undefined | Object | undefined): this {return this;} + transform(value: object | undefined): this {return this;} onAppear(value: (() => void) | undefined): this {return this;} onDisAppear(value: (() => void) | undefined): this {return this;} onAttach(value: (() => void) | undefined): this {return this;} @@ -8256,7 +8257,7 @@ export class ArkCommonMethodStyle implements CommonMethod { gridSpan_value?: number | undefined gridOffset_value?: number | undefined rotate_value?: RotateOptions | undefined - transform_value?: TransformationMatrix | undefined + transform_value?: Matrix4Transit | undefined onAppear_value?: (() => void) | undefined onDisAppear_value?: (() => void) | undefined onAttach_value?: (() => void) | undefined @@ -8587,7 +8588,7 @@ export class ArkCommonMethodStyle implements CommonMethod { public rotate(value: RotateOptions | undefined): this { return this } - public transform(value: TransformationMatrix | undefined | Object | undefined): this { + public transform(value: object | undefined ): this { return this } public onAppear(value: (() => void) | undefined): this { @@ -10199,11 +10200,11 @@ export class ArkCommonMethodComponent extends ComponentBase implements CommonMet } return this } - public transform(value: TransformationMatrix | undefined | Object | undefined): this { + public transform(value: object | undefined): this { if (this.checkPriority("transform")) { const value_type = runtimeType(value) if ((RuntimeType.OBJECT == value_type) || (RuntimeType.UNDEFINED == value_type)) { - const value_casted = value as (TransformationMatrix | undefined) + const value_casted = value as (object | undefined) this.getPeer()?.transform0Attribute(value_casted) return this } diff --git a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/component/peers/Deserializer.ts b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/component/peers/Deserializer.ts index d39cb6e638871a565e9302aba5d9b7d3519d1e59..f5f8adcc448c78925e62df73620df38d181bdb32 100644 --- a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/component/peers/Deserializer.ts +++ b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/component/peers/Deserializer.ts @@ -179,7 +179,6 @@ import { DrawCallback, RenderNode, RenderNodeInternal } from "../../RenderNode" import { RoundedRectOptions, RectOptions, RadiusItem } from "./../rect" import { RowOptions, RowOptionsV2 } from "./../row" import { StackOptions } from "./../stack" -import { TransformationMatrix } from "./../arkui-common" import { FlexSpaceOptions, FlexOptions } from "./../flex" import { ImageFrameInfo } from "./../imageAnimator" import { MenuItemGroupOptions } from "./../menuItemGroup" @@ -499,8 +498,8 @@ export class Deserializer extends DeserializerBase { } readMatrix4Transit(): Matrix4Transit { let valueDeserializer : Deserializer = this - let ptr : KPointer = valueDeserializer.readPointer() - return Matrix4TransitInternal.fromPtr(ptr) + let value : Matrix4Transit = valueDeserializer.readInt64() as Object as Matrix4Transit + return value } readNativeMediaPlayerConfig(): NativeMediaPlayerConfig { let valueDeserializer : Deserializer = this @@ -10414,41 +10413,7 @@ export class Deserializer extends DeserializerBase { return value } readPolyToPolyOptions(): PolyToPolyOptions { - let valueDeserializer : Deserializer = this - const src_buf_length : int32 = valueDeserializer.readInt32() - let src_buf : Array = new Array(src_buf_length) - for (let src_buf_i = 0; src_buf_i < src_buf_length; src_buf_i++) { - src_buf[src_buf_i] = valueDeserializer.readPoint() - } - const src_result : Array = src_buf - const srcIndex_buf_runtimeType = (valueDeserializer.readInt8() as int32) - let srcIndex_buf : number | undefined - if ((RuntimeType.UNDEFINED) != (srcIndex_buf_runtimeType)) - { - srcIndex_buf = (valueDeserializer.readNumber() as number) - } - const srcIndex_result : number | undefined = srcIndex_buf - const dst_buf_length : int32 = valueDeserializer.readInt32() - let dst_buf : Array = new Array(dst_buf_length) - for (let dst_buf_i = 0; dst_buf_i < dst_buf_length; dst_buf_i++) { - dst_buf[dst_buf_i] = valueDeserializer.readPoint() - } - const dst_result : Array = dst_buf - const dstIndex_buf_runtimeType = (valueDeserializer.readInt8() as int32) - let dstIndex_buf : number | undefined - if ((RuntimeType.UNDEFINED) != (dstIndex_buf_runtimeType)) - { - dstIndex_buf = (valueDeserializer.readNumber() as number) - } - const dstIndex_result : number | undefined = dstIndex_buf - const pointCount_buf_runtimeType = (valueDeserializer.readInt8() as int32) - let pointCount_buf : number | undefined - if ((RuntimeType.UNDEFINED) != (pointCount_buf_runtimeType)) - { - pointCount_buf = (valueDeserializer.readNumber() as number) - } - const pointCount_result : number | undefined = pointCount_buf - let value : PolyToPolyOptions = ({src: src_result, srcIndex: srcIndex_result, dst: dst_result, dstIndex: dstIndex_result, pointCount: pointCount_result} as PolyToPolyOptions) + let value : PolyToPolyOptions = ({} as PolyToPolyOptions) return value } readPopInfo(): PopInfo { @@ -12455,15 +12420,9 @@ export class Deserializer extends DeserializerBase { let value : TouchResult = ({strategy: strategy_result, id: id_result} as TouchResult) return value } - readTransformationMatrix(): TransformationMatrix { + readTransformationMatrix(): Matrix4Transit { let valueDeserializer : Deserializer = this - const matrix4x4_buf_length : int32 = valueDeserializer.readInt32() - let matrix4x4_buf : Array = new Array(matrix4x4_buf_length) - for (let matrix4x4_buf_i = 0; matrix4x4_buf_i < matrix4x4_buf_length; matrix4x4_buf_i++) { - matrix4x4_buf[matrix4x4_buf_i] = (valueDeserializer.readNumber() as number) - } - const matrix4x4_result : Array = matrix4x4_buf - let value : TransformationMatrix = ({matrix4x4: matrix4x4_result} as TransformationMatrix) + let value : Matrix4Transit = valueDeserializer.readInt64() as Object as Matrix4Transit return value } readTranslateOption(): TranslateOption { diff --git a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/component/peers/Serializer.ts b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/component/peers/Serializer.ts index 9d168562bfd2ae6e2b155e3a363399cf8ad6c1f5..e0f576d5bb6e4c73bc9a45642ee11e2accc44d27 100644 --- a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/component/peers/Serializer.ts +++ b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/component/peers/Serializer.ts @@ -120,6 +120,7 @@ import { ListItemGroupStyle, ListItemGroupOptions } from "./../listItemGroup" import { LoadingProgressStyle } from "./../loadingProgress" import { MarqueeStartPolicy, MarqueeState, TextAttribute, TextOverflowOptions, TextMarqueeOptions, Callback_MarqueeState_Void, TextSpanType, TextResponseType, TextController, TextControllerInternal, TextOptions } from "./../text" import { Matrix4Transit, Matrix4TransitInternal, TranslateOption, ScaleOption, RotateOption, PolyToPolyOptions } from "./../arkui-matrix4" + import { Tuple_Number_Number, Tuple_Number_Number_Number } from "./../arkui-synthetics" import { NavigationType } from "./../navigator" import { NavRouteMode, RouteInfo } from "./../navRouter" @@ -421,8 +422,8 @@ export class Serializer extends SerializerBase { valueSerializer.writePointer(toPeerPtr(value)) } writeMatrix4Transit(value: Matrix4Transit): void { - let valueSerializer : Serializer = this - valueSerializer.writePointer(toPeerPtr(value)) + let valueSerializer : Serializer = this + valueSerializer.writeInt64(Object.values(value)[0] as int64) } writeNativeMediaPlayerConfig(value: NativeMediaPlayerConfig): void { let valueSerializer : Serializer = this @@ -5394,43 +5395,6 @@ export class Serializer extends SerializerBase { } } writePolyToPolyOptions(value: PolyToPolyOptions): void { - let valueSerializer : Serializer = this - const value_src = value.src - valueSerializer.writeInt32(value_src.length as int32) - for (let i = 0; i < value_src.length; i++) { - const value_src_element : Point = value_src[i] - valueSerializer.writePoint(value_src_element) - } - const value_srcIndex = value.srcIndex - let value_srcIndex_type : int32 = RuntimeType.UNDEFINED - value_srcIndex_type = runtimeType(value_srcIndex) - valueSerializer.writeInt8(value_srcIndex_type as int32) - if ((RuntimeType.UNDEFINED) != (value_srcIndex_type)) { - const value_srcIndex_value = value_srcIndex! - valueSerializer.writeNumber(value_srcIndex_value) - } - const value_dst = value.dst - valueSerializer.writeInt32(value_dst.length as int32) - for (let i = 0; i < value_dst.length; i++) { - const value_dst_element : Point = value_dst[i] - valueSerializer.writePoint(value_dst_element) - } - const value_dstIndex = value.dstIndex - let value_dstIndex_type : int32 = RuntimeType.UNDEFINED - value_dstIndex_type = runtimeType(value_dstIndex) - valueSerializer.writeInt8(value_dstIndex_type as int32) - if ((RuntimeType.UNDEFINED) != (value_dstIndex_type)) { - const value_dstIndex_value = value_dstIndex! - valueSerializer.writeNumber(value_dstIndex_value) - } - const value_pointCount = value.pointCount - let value_pointCount_type : int32 = RuntimeType.UNDEFINED - value_pointCount_type = runtimeType(value_pointCount) - valueSerializer.writeInt8(value_pointCount_type as int32) - if ((RuntimeType.UNDEFINED) != (value_pointCount_type)) { - const value_pointCount_value = value_pointCount! - valueSerializer.writeNumber(value_pointCount_value) - } } writePopInfo(value: PopInfo): void { let valueSerializer : Serializer = this @@ -7597,14 +7561,11 @@ export class Serializer extends SerializerBase { valueSerializer.writeString(value_id_value) } } - writeTransformationMatrix(value: TransformationMatrix): void { + writeTransformationMatrix(value: object): void { let valueSerializer : Serializer = this - const value_matrix4x4 = value.matrix4x4 - valueSerializer.writeInt32(value_matrix4x4.length as int32) - for (let i = 0; i < value_matrix4x4.length; i++) { - const value_matrix4x4_element : number = value_matrix4x4[i] - valueSerializer.writeNumber(value_matrix4x4_element) - } + const value_curve_value = value! + const value_curve_value_1 = value_curve_value as Matrix4Transit + valueSerializer.writeInt64(Object.values(value_curve_value_1)[0] as int64) } writeTranslateOption(value: TranslateOption): void { let valueSerializer : Serializer = this diff --git a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/external/arkts/index.ts b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/external/arkts/index.ts index 86c98a9385e046620a44423a1cd681bcca350cdd..34e355d958bfa390fce930a22e7a819cfd8a4a6a 100644 --- a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/external/arkts/index.ts +++ b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/external/arkts/index.ts @@ -13,6 +13,7 @@ * limitations under the License. */ +import matrix4 from "@ohos.matrix4" import image from "@ohos.multimedia.image" import _Want from "@ohos.app.ability.Want" import webview from "@ohos.web.webview" @@ -40,3 +41,8 @@ export type UnifiedData = unifiedDataChannel.UnifiedData export type Summary = unifiedDataChannel.Summary export type DataSyncOptions = unifiedDataChannel.GetDataParams export type UniformDataType = uniformTypeDescriptor.UniformDataType +export type TranslateOption = matrix4.TranslateOption +export type ScaleOption = matrix4.ScaleOption +export type RotateOption = matrix4.RotateOption +export type PolyToPolyOptions = matrix4.PolyToPolyOptions +export type Matrix4Transit = matrix4.Matrix4Transit \ No newline at end of file diff --git a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/external/ts/index.ts b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/external/ts/index.ts index ec19fdf204e46cdf39ab30c004ba8ade8958c4fb..48dc012687aaa3f91f0d44b9efcc607d027a209e 100644 --- a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/external/ts/index.ts +++ b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/external/ts/index.ts @@ -23,3 +23,5 @@ export * from "./multimodalInput/pointer" export * from "./drag_and_drop/drag_and_drop" export * from "./arkui/drawableDescriptor" export * from "./filter/filter" +export * from "./base/base" +export * from "./matrix/matrix" diff --git a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/external/ts/matrix/matrix.ts b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/external/ts/matrix/matrix.ts new file mode 100644 index 0000000000000000000000000000000000000000..085b6b5b59c97682f12338534eff29cd7f4aee52 --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/external/ts/matrix/matrix.ts @@ -0,0 +1,20 @@ +/* + * 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. + */ + +export type Matrix4Transit = any; +export type TranslateOption = any; +export type ScaleOption = any; +export type RotateOption = any; +export type PolyToPolyOptions = any; \ No newline at end of file diff --git a/frameworks/bridge/arkts_frontend/koala_projects/arkoala/framework/native/src/generated/Serializers.h b/frameworks/bridge/arkts_frontend/koala_projects/arkoala/framework/native/src/generated/Serializers.h index 1877f65d3d131005b10a7d75bb998cb4952e78c2..f8b9781f9c12386fc46807bca80bf6b7fcbd649f 100644 --- a/frameworks/bridge/arkts_frontend/koala_projects/arkoala/framework/native/src/generated/Serializers.h +++ b/frameworks/bridge/arkts_frontend/koala_projects/arkoala/framework/native/src/generated/Serializers.h @@ -43580,7 +43580,7 @@ inline void WriteToString(std::string* result, const Ark_TransformationMatrix* v result->append("{"); // Array_Number matrix4x4 result->append(".matrix4x4="); - WriteToString(result, &value->matrix4x4); + WriteToString(result, value->matrix4Object); result->append("}"); } template <> @@ -71040,12 +71040,8 @@ class Serializer : public SerializerBase { void writeTransformationMatrix(Ark_TransformationMatrix value) { Serializer& valueSerializer = *this; - const auto value_matrix4x4 = value.matrix4x4; - valueSerializer.writeInt32(value_matrix4x4.length); - for (int i = 0; i < value_matrix4x4.length; i++) { - const Ark_Number value_matrix4x4_element = value_matrix4x4.array[i]; - valueSerializer.writeNumber(value_matrix4x4_element); - } + const auto value_matrix4x4 = value.matrix4Object; + valueSerializer.writeInt64(value_matrix4x4); } void writeTranslateOption(Ark_TranslateOption value) { @@ -98183,16 +98179,9 @@ class Deserializer : public DeserializerBase { } Ark_TransformationMatrix readTransformationMatrix() { - Ark_TransformationMatrix value = {}; Deserializer& valueDeserializer = *this; - const Ark_Int32 matrix4x4_buf_length = valueDeserializer.readInt32(); - Array_Number matrix4x4_buf = {}; - valueDeserializer.resizeArray::type, - std::decay::type>(&matrix4x4_buf, matrix4x4_buf_length); - for (int matrix4x4_buf_i = 0; matrix4x4_buf_i < matrix4x4_buf_length; matrix4x4_buf_i++) { - matrix4x4_buf.array[matrix4x4_buf_i] = static_cast(valueDeserializer.readNumber()); - } - value.matrix4x4 = matrix4x4_buf; + Ark_TransformationMatrix value = {}; + value.matrix4Object = valueDeserializer.readInt64(); return value; } Ark_TranslateOption readTranslateOption() diff --git a/frameworks/bridge/arkts_frontend/koala_projects/arkoala/framework/native/src/generated/arkoala_api_generated.h b/frameworks/bridge/arkts_frontend/koala_projects/arkoala/framework/native/src/generated/arkoala_api_generated.h index fd679dc392cba4d08e0e60a277cf6c3ea6c0319f..84e58d09bfd4393ce0c7fe99f0efd40a4bebaa4f 100644 --- a/frameworks/bridge/arkts_frontend/koala_projects/arkoala/framework/native/src/generated/arkoala_api_generated.h +++ b/frameworks/bridge/arkts_frontend/koala_projects/arkoala/framework/native/src/generated/arkoala_api_generated.h @@ -14954,7 +14954,7 @@ typedef struct Opt_TouchResult { Ark_TouchResult value; } Opt_TouchResult; typedef struct Ark_TransformationMatrix { - Array_Number matrix4x4; + int64_t matrix4Object; } Ark_TransformationMatrix; typedef struct Opt_TransformationMatrix { Ark_Tag tag; diff --git a/frameworks/bridge/declarative_frontend/engine/jsi/modules/jsi_matrix4_module.cpp b/frameworks/bridge/declarative_frontend/engine/jsi/modules/jsi_matrix4_module.cpp index c23009ea747f177d690106d9ebb3bba22d9ca5b4..1c764e907fe0bd078d6005ecd076d1ff8d13d5a4 100644 --- a/frameworks/bridge/declarative_frontend/engine/jsi/modules/jsi_matrix4_module.cpp +++ b/frameworks/bridge/declarative_frontend/engine/jsi/modules/jsi_matrix4_module.cpp @@ -22,7 +22,7 @@ #include "core/components_ng/render/render_context.h" #include "frameworks/base/geometry/ng/point_t.h" #include "frameworks/bridge/js_frontend/engine/common/js_constants.h" -#include "frameworks/core/components_ng/render/adapter/matrix2d.h" +#include "frameworks/core/components_ng/render/adapter/matrix_util.h" namespace OHOS::Ace::Framework { @@ -306,7 +306,7 @@ shared_ptr SetPolyToPoly(const shared_ptr& runtime, const sh for (int i = dstIndex; i < dstLastIndex; i++) { totalPoint.push_back(dstPoint[i]); } - Matrix4 ret = OHOS::Ace::NG::SetMatrixPolyToPoly(matrix, totalPoint); + Matrix4 ret = OHOS::Ace::NG::MatrixUtil::SetMatrixPolyToPoly(matrix, totalPoint); thisObj->SetProperty(runtime, MATRIX_4X4, ConvertToJSValue(runtime, ret)); return thisObj; } diff --git a/frameworks/core/components_ng/render/BUILD.gn b/frameworks/core/components_ng/render/BUILD.gn index a084cee42d1733649590a56785c689b7c6498b2a..87aad14ae934b0ddc7fe6fba7f8a243a60062867 100644 --- a/frameworks/core/components_ng/render/BUILD.gn +++ b/frameworks/core/components_ng/render/BUILD.gn @@ -23,6 +23,7 @@ build_component_ng("render_ng") { "adapter/graphic_modifier.cpp", "adapter/image_painter_utils.cpp", "adapter/matrix2d.cpp", + "adapter/matrix_util.cpp", "adapter/path_painter.cpp", "adapter/pixelmap_image.cpp", "adapter/render_surface_impl.cpp", diff --git a/frameworks/core/components_ng/render/adapter/matrix2d.cpp b/frameworks/core/components_ng/render/adapter/matrix2d.cpp index 7e2adb960b8e9f3b2d7abd817879d2a812ba43df..b4e5119d65d7fa4be0b1d9c478e169e700e5819f 100644 --- a/frameworks/core/components_ng/render/adapter/matrix2d.cpp +++ b/frameworks/core/components_ng/render/adapter/matrix2d.cpp @@ -84,35 +84,5 @@ void Matrix2D::Rotate(TransformParam& param, double degree, double rx, double ry skMatrix = skMatrix.preRotate(degree, rx, ry); ConvertToTransformParam(param, skMatrix); } - -Matrix4 SetMatrixPolyToPoly( - const Matrix4& matrix, const std::vector>& totalPoint) -{ - auto matrix3d = OHOS::Rosen::Drawing::Matrix(); - /** - * When converting from matrix4 to matrix3 - * [a b c] [a b 0 c] - * [d e f] -> [d e 0 f] - * [g h i] [0 0 1 0] - * [g h 0 i] - */ - matrix3d.SetMatrix(matrix.Get(0, 0), matrix.Get(1, 0), matrix.Get(3, 0), matrix.Get(0, 1), matrix.Get(1, 1), - matrix.Get(3, 1), matrix.Get(0, 3), matrix.Get(1, 3), matrix.Get(3, 3)); - size_t arrayLength = totalPoint.size() / 2; - OHOS::Rosen::Drawing::PointF src[arrayLength]; - OHOS::Rosen::Drawing::PointF dst[arrayLength]; - for (size_t i = 0; i < arrayLength; i++) { - auto point = totalPoint[i]; - src[i] = OHOS::Rosen::Drawing::Point(point.GetX(), point.GetY()); - } - for (size_t i = 0; i < arrayLength; i++) { - auto point = totalPoint[i + arrayLength]; - dst[i] = OHOS::Rosen::Drawing::Point(point.GetX(), point.GetY()); - } - matrix3d.SetPolyToPoly(src, dst, arrayLength); - Matrix4 retMatrix4(matrix3d.Get(0), matrix3d.Get(1), 0, matrix3d.Get(2), matrix3d.Get(3), matrix3d.Get(4), 0, - matrix3d.Get(5), 0, 0, 1, 0, matrix3d.Get(6), matrix3d.Get(7), 0, matrix3d.Get(8)); - return retMatrix4; -} } // namespace OHOS::Ace::NG diff --git a/frameworks/core/components_ng/render/adapter/matrix2d.h b/frameworks/core/components_ng/render/adapter/matrix2d.h index 1d8b4a2095de8b99f776e1400b5dfc33b550dcf8..aa15a0a11740100b5c90042807f8e7abac840893 100644 --- a/frameworks/core/components_ng/render/adapter/matrix2d.h +++ b/frameworks/core/components_ng/render/adapter/matrix2d.h @@ -29,7 +29,6 @@ public: static void Rotate(TransformParam& param, double degree, double dx, double dy); static std::string ToString(); }; -Matrix4 SetMatrixPolyToPoly(const Matrix4& matrix, const std::vector>& totalPoint); } // namespace OHOS::Ace::NG #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_RENDER_ADAPTER_MATRIX2D_H diff --git a/frameworks/core/components_ng/render/adapter/matrix_util.cpp b/frameworks/core/components_ng/render/adapter/matrix_util.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a31c29d9f197f96a0e07d921a93647fdb5f2a974 --- /dev/null +++ b/frameworks/core/components_ng/render/adapter/matrix_util.cpp @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2023 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. + */ + +#include "frameworks/core/components_ng/render/adapter/matrix_util.h" + +#include "2d_graphics/include/utils/matrix.h" + +namespace OHOS::Ace::NG { +constexpr int32_t POSITION_TWO = 2; +constexpr int32_t POSITION_THREE = 3; +constexpr int32_t POSITION_FOUR = 4; +constexpr int32_t POSITION_FIVE = 5; +constexpr int32_t POSITION_SIX = 6; +constexpr int32_t POSITION_SEVEN = 7; +constexpr int32_t POSITION_EIGHT = 8; + +Matrix4 MatrixUtil::SetMatrixPolyToPoly( + const Matrix4& matrix, const std::vector>& totalPoint) +{ + auto matrix3d = OHOS::Rosen::Drawing::Matrix(); + /** + * When converting from matrix4 to matrix3 + * [a b c] [a b 0 c] + * [d e f] -> [d e 0 f] + * [g h i] [0 0 1 0] + * [g h 0 i] + */ + matrix3d.SetMatrix(matrix.Get(0, 0), matrix.Get(1, 0), matrix.Get(POSITION_THREE, 0), matrix.Get(0, 1), + matrix.Get(1, 1), matrix.Get(POSITION_THREE, 1), matrix.Get(0, POSITION_THREE), matrix.Get(1, POSITION_THREE), + matrix.Get(POSITION_THREE, POSITION_THREE)); + size_t arrayLength = totalPoint.size() / 2; + OHOS::Rosen::Drawing::PointF src[arrayLength]; + OHOS::Rosen::Drawing::PointF dst[arrayLength]; + for (size_t i = 0; i < arrayLength; i++) { + auto point = totalPoint[i]; + src[i] = OHOS::Rosen::Drawing::Point(point.GetX(), point.GetY()); + } + for (size_t i = 0; i < arrayLength; i++) { + auto point = totalPoint[i + arrayLength]; + dst[i] = OHOS::Rosen::Drawing::Point(point.GetX(), point.GetY()); + } + matrix3d.SetPolyToPoly(src, dst, arrayLength); + Matrix4 retMatrix4(matrix3d.Get(0), matrix3d.Get(1), 0, matrix3d.Get(POSITION_TWO), matrix3d.Get(POSITION_THREE), + matrix3d.Get(POSITION_FOUR), 0, matrix3d.Get(POSITION_FIVE), 0, 0, 1, 0, matrix3d.Get(POSITION_SIX), + matrix3d.Get(POSITION_SEVEN), 0, matrix3d.Get(POSITION_EIGHT)); + return retMatrix4; +} +} \ No newline at end of file diff --git a/frameworks/core/components_ng/render/adapter/matrix_util.h b/frameworks/core/components_ng/render/adapter/matrix_util.h new file mode 100644 index 0000000000000000000000000000000000000000..5c620078caab5a030bb4bed5cefb3cd8301badc4 --- /dev/null +++ b/frameworks/core/components_ng/render/adapter/matrix_util.h @@ -0,0 +1,28 @@ +/* + * 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. + */ +#ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_RENDER_ADAPTER_MATRIX_UIIL_H +#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_RENDER_ADAPTER_MATRIX_UIIL_H + +#include +#include "frameworks/core/components/common/properties/paint_state.h" + +namespace OHOS::Ace::NG { +class ACE_FORCE_EXPORT MatrixUtil final { +public: + static Matrix4 SetMatrixPolyToPoly(const Matrix4& matrix, + const std::vector>& totalPoint); +}; +} // namespace OHOS::Ace::NG +#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_RENDER_ADAPTER_MatrixUtil_H \ No newline at end of file diff --git a/frameworks/core/interfaces/native/generated/interface/arkoala_api_generated.h b/frameworks/core/interfaces/native/generated/interface/arkoala_api_generated.h index a28f875b72db240e02f36c1d4b425ed3d36d94a0..314684b2d2f8c671f1249f9cebf38f5baa020fe0 100644 --- a/frameworks/core/interfaces/native/generated/interface/arkoala_api_generated.h +++ b/frameworks/core/interfaces/native/generated/interface/arkoala_api_generated.h @@ -14953,7 +14953,7 @@ typedef struct Opt_TouchResult { Ark_TouchResult value; } Opt_TouchResult; typedef struct Ark_TransformationMatrix { - Array_Number matrix4x4; + int64_t matrix4Object; } Ark_TransformationMatrix; typedef struct Opt_TransformationMatrix { Ark_Tag tag; diff --git a/frameworks/core/interfaces/native/implementation/common_method_modifier.cpp b/frameworks/core/interfaces/native/implementation/common_method_modifier.cpp index 8d640e924105c54eddb1ee212e5309faef62a650..1698efa2fd46940fa1efa7ce8c87e32b09315108 100644 --- a/frameworks/core/interfaces/native/implementation/common_method_modifier.cpp +++ b/frameworks/core/interfaces/native/implementation/common_method_modifier.cpp @@ -3515,8 +3515,12 @@ void Transform0Impl(Ark_NativePointer node, { auto frameNode = reinterpret_cast(node); CHECK_NULL_VOID(frameNode); - //auto convValue = value ? Converter::OptConvert(*value) : std::nullopt; - //CommonMethodModelNG::SetTransform0(frameNode, convValue); + auto addr = value->value.matrix4Object; + auto convValue = reinterpret_cast(addr); + if (!convValue) { + return; + } + ViewAbstract::SetTransformMatrix(frameNode, *convValue); } void Transform1Impl(Ark_NativePointer node, const Opt_Object* value) diff --git a/frameworks/core/interfaces/native/implementation/matrix4_transit_accessor.cpp b/frameworks/core/interfaces/native/implementation/matrix4_transit_accessor.cpp index 9ec9b4ee581685666f14aa86c5dbdba4809ec965..18786eaef6aa8a333f491e899f94ca396af67939 100644 --- a/frameworks/core/interfaces/native/implementation/matrix4_transit_accessor.cpp +++ b/frameworks/core/interfaces/native/implementation/matrix4_transit_accessor.cpp @@ -19,6 +19,7 @@ #include "core/interfaces/native/utility/converter.h" #include "core/interfaces/native/utility/reverse_converter.h" #include "arkoala_api_generated.h" +#include "frameworks/core/components_ng/render/adapter/matrix_util.h" namespace OHOS::Ace::NG::GeneratedModifier { namespace Matrix4TransitAccessor { @@ -172,7 +173,7 @@ Ark_Matrix4Transit SetPolyToPolyImpl(Ark_Matrix4Transit peer, for (int i = dstIndex; i < dstLastIndex; i++) { totalPoint.push_back(dstPoint[i]); } - result->matrix = SetMatrixPolyToPoly(peer->matrix, totalPoint); + result->matrix = OHOS::Ace::NG::MatrixUtil::SetMatrixPolyToPoly(peer->matrix, totalPoint); return result; } diff --git a/interfaces/ets/ani/matrix4/BUILD.gn b/interfaces/ets/ani/matrix4/BUILD.gn index 137ed06cd20edf7e10a6b87fd3d1534da52854da..cd215f70032c07408c741391b9e99174e8b9e190 100644 --- a/interfaces/ets/ani/matrix4/BUILD.gn +++ b/interfaces/ets/ani/matrix4/BUILD.gn @@ -15,6 +15,15 @@ import("//build/config/components/ets_frontend/ets2abc_config.gni") import("//build/ohos.gni") import("//foundation/arkui/ace_engine/ace_config.gni") +config("ani_config") { + include_dirs = [ + "${ace_root}/frameworks", + "${ace_root}/interfaces", + "${ace_root}", + "graphic_2d:2d_graphics", + ] +} + #构建ANI库 ohos_shared_library("matrix4_ani") { deps = [ "$ace_root/build:libace_compatible" ] diff --git a/interfaces/ets/ani/matrix4/ets/@ohos.matrix4.ets b/interfaces/ets/ani/matrix4/ets/@ohos.matrix4.ets index 4ae79477424568418eef3ee0d41b04f2b336fbfc..94294d51dab8683ae34a306abe3d11d5b10500b6 100644 --- a/interfaces/ets/ani/matrix4/ets/@ohos.matrix4.ets +++ b/interfaces/ets/ani/matrix4/ets/@ohos.matrix4.ets @@ -38,6 +38,19 @@ export default namespace matrix4 { angle?: number; } + export interface Point { + x: number; + y: number; + } + + export interface PolyToPolyOptions { + src: Array; + srcIndex?: number; + dst: Array; + dstIndex?: number; + pointCount?: number; + } + export default interface Matrix4Transit { copy():Matrix4Transit; invert(): Matrix4Transit; @@ -45,6 +58,15 @@ export default namespace matrix4 { scale(options: ScaleOption): Matrix4Transit; rotate(options: RotateOption): Matrix4Transit; translate(options: TranslateOption): Matrix4Transit; + skew(x: number, y: number): Matrix4Transit; + setPolyToPoly(options: PolyToPolyOptions): Matrix4Transit; + transformPoint(options: [ + number, + number + ]): [ + number, + number + ]; } class Matrix4TransitInner implements Matrix4Transit { @@ -95,6 +117,15 @@ export default namespace matrix4 { public native scale(options: ScaleOption): Matrix4Transit; public native rotate(options: RotateOption): Matrix4Transit; public native translate(options: TranslateOption): Matrix4Transit; + public native skew(x: number, y: number): Matrix4Transit; + public native setPolyToPoly(options: PolyToPolyOptions): Matrix4Transit; + public native transformPoint(options: [ + number, + number + ]): [ + number, + number + ]; } export native function identity():Matrix4Transit; export native function init(options: [ diff --git a/interfaces/ets/ani/matrix4/src/matrix4.cpp b/interfaces/ets/ani/matrix4/src/matrix4.cpp index 7f889d97ed293488d004c97036c52244e6a74e93..9f49953106a93cc66c80f40ad775feb9cb2d747f 100644 --- a/interfaces/ets/ani/matrix4/src/matrix4.cpp +++ b/interfaces/ets/ani/matrix4/src/matrix4.cpp @@ -25,9 +25,18 @@ #include #include + +#include "base/geometry/matrix4.h" +#include "core/components_ng/base/view_abstract_model_ng.h" +#include "core/components_ng/render/render_context.h" +#include "frameworks/base/geometry/ng/point_t.h" +#include "frameworks/bridge/js_frontend/engine/common/js_constants.h" +#include "frameworks/core/components_ng/render/adapter/matrix2d.h" +#include "frameworks/core/components_ng/render/adapter/matrix_util.h" #include "interop_js/arkts_esvalue.h" namespace OHOS::Ace::MatrixAni { constexpr int32_t MATRIX_LENGTH = 16; +constexpr int32_t MATRIX_LENGTH_TRANSFORM_POINT = 2; static Matrix4_Obj* GetMatrixObj(ani_env* env, ani_object obj) { @@ -64,44 +73,20 @@ static ani_object Matrix4_Identity([[maybe_unused]] ani_env* env, [[maybe_unused Matrix4 ConvertToMatrix([[maybe_unused]] ani_env* env, [[maybe_unused]] ani_object option) { Matrix4 result = Matrix4::CreateIdentity(); - ani_class arrayClass; - if (ANI_OK != env->FindClass("Lescompat/Array;", &arrayClass)) { - return result; - } - ani_boolean isArray; - if (ANI_OK != env->Object_InstanceOf(static_cast(option), arrayClass, &isArray)) { - return result; - } - ani_array inputArray = static_cast(option); + ani_tuple_value inputArray = static_cast(option); ani_size length = 0; - if (ANI_OK != env->Array_GetLength(inputArray, &length)) { + if (ANI_OK != env->TupleValue_GetNumberOfItems(inputArray, &length)) { return result; } int32_t inputSize = static_cast(length); if (inputSize != MATRIX_LENGTH) { return result; } - - ani_class doubleClass = nullptr; - if (ANI_OK != env->FindClass("Lstd/core/Double;", &doubleClass)) { - return result; - } - ani_method doubleUnbox = nullptr; - if (ANI_OK != env->Class_FindMethod(doubleClass, "unboxed", ":D", &doubleUnbox)) { - return result; - } - - // in column order - ani_array doubleArray = inputArray; for (int32_t i = 0; i < Matrix4::DIMENSION; i++) { for (int32_t j = 0; j < Matrix4::DIMENSION; j++) { - auto index = static_cast(i * Matrix4::DIMENSION + j); - ani_ref val {}; - if (ANI_OK != env->Array_Get(doubleArray, index, &val)) { - return result; - } ani_double value; - if (ANI_OK != env->Object_CallMethod_Double(reinterpret_cast(val), doubleUnbox, &value)) { + auto index = static_cast(i * Matrix4::DIMENSION + j); + if (ANI_OK != env->TupleValue_GetItem_Double(inputArray, index, &value)) { return result; } auto ret = static_cast(value); @@ -137,7 +122,7 @@ Matrix4 ConvertToMatrixArray([[maybe_unused]] ani_env* env, [[maybe_unused]] ani return result; } -static ani_object Matrix4_Init([[maybe_unused]] ani_env* env, [[maybe_unused]] ani_object object, +static ani_object Matrix4_Init([[maybe_unused]] ani_env* env, [[maybe_unused]] ani_object option) { static const char* className = "L@ohos/matrix4/matrix4/Matrix4TransitInner;"; @@ -275,6 +260,149 @@ static ani_object Matrix4_Rotate([[maybe_unused]] ani_env* env, ani_object objec return object; } +static ani_object Matrix4_Skew([[maybe_unused]] ani_env* env, ani_object object, ani_double inputX, ani_double inputY) +{ + double sxInput = 0.0f; + double syInput = 0.0f; + if (!std::isnan(inputX)) { + sxInput = static_cast(inputX); + } + if (!std::isnan(inputX)) { + syInput = static_cast(inputX); + } + + Matrix4_Obj* matrixObj = GetMatrixObj(env, object); + if (matrixObj == nullptr) { + return nullptr; + } + matrixObj->matrix4x4 = + Matrix4::CreateFactorSkew(static_cast(sxInput), static_cast(syInput)) * matrixObj->matrix4x4; + return object; +} + +void ParseArray([[maybe_unused]] ani_env* env, const char* property, ani_object options, + std::vector>& points) +{ + ani_ref params_ref; + if (ANI_OK != env->Object_GetPropertyByName_Ref(options, property, ¶ms_ref)) { + return; + } + ani_class arrayClass; + if (ANI_OK != env->FindClass("Lescompat/Array;", &arrayClass)) { + return; + } + ani_boolean isArray; + if (ANI_OK != env->Object_InstanceOf(static_cast(params_ref), arrayClass, &isArray)) { + return; + } + ani_double length; + if (ANI_OK != env->Object_GetPropertyByName_Double(static_cast(params_ref), "length", &length)) { + return; + } + for (int i = 0; i < static_cast(length); i++) { + ani_ref pointRef; + if (ANI_OK != env->Object_CallMethodByName_Ref(static_cast(params_ref), + "$_get", "I:Lstd/core/Object;", &pointRef, (ani_int)i)) { + break; + } + ani_object pointObject = static_cast(pointRef); + // parse x + ani_double aniX; + if (ANI_OK != env->Object_GetPropertyByName_Double(pointObject, "x", &aniX)) { + aniX = 0.0f; + } + // parse y + ani_double aniY; + if (ANI_OK != env->Object_GetPropertyByName_Double(pointObject, "y", &aniY)) { + aniY = 0.0f; + } + points.emplace_back(OHOS::Ace::NG::PointT(static_cast(aniX), static_cast(aniY))); + } +} + +static ani_object Matrix4_SetPolyToPoly([[maybe_unused]] ani_env* env, ani_object object, ani_object options) +{ + double srcIndexInput = 0.0; + ParseOption(env, options, srcIndexInput, "srcIndex", "L@ohos/matrix4/matrix4/PolyToPolyOptions;"); + double dstIndexInput = 0.0; + ParseOption(env, options, dstIndexInput, "dstIndex", "L@ohos/matrix4/matrix4/PolyToPolyOptions;"); + double pointCountInput = 0.0; + ParseOption(env, options, pointCountInput, "pointCount", "L@ohos/matrix4/matrix4/PolyToPolyOptions;"); + int srcIndex = static_cast(srcIndexInput); + int dstIndex = static_cast(dstIndexInput); + int pointCount = static_cast(pointCountInput); + std::vector> srcPoint; + ParseArray(env, "src", options, srcPoint); + std::vector> dstPoint; + ParseArray(env, "dst", options, dstPoint); + if (pointCount <= 0 || pointCount > static_cast(srcPoint.size()) || + pointCount > static_cast(dstPoint.size())) { + LOGE("setpPolyToPoly pointCount out of range pointCount:%{public}d, src size:%{public}d, dst size:%{public}d", + pointCount, static_cast(srcPoint.size()), static_cast(dstPoint.size())); + return object; + } + if (srcIndex < 0 || (pointCount + srcIndex) > static_cast(srcPoint.size())) { + LOGE("setpPolyToPoly srcIndex out of range srcIndex:%{public}d, pointCount:%{public}d, src size%{public}d", + srcIndex, pointCount, static_cast(srcPoint.size())); + return object; + } + if (dstIndex < 0 || (pointCount + dstIndex) > static_cast(dstPoint.size())) { + LOGE("setpPolyToPoly dstIndex out of range dstIndex:%{public}d, pointCount:%{public}d, dst size%{public}d", + dstIndex, pointCount, static_cast(dstPoint.size())); + return object; + } + std::vector> totalPoint; + int srcLastIndex = pointCount + srcIndex; + for (int i = srcIndex; i < srcLastIndex; i++) { + totalPoint.push_back(srcPoint[i]); + } + int dstLastIndex = pointCount + dstIndex; + for (int i = dstIndex; i < dstLastIndex; i++) { + totalPoint.push_back(dstPoint[i]); + } + Matrix4_Obj* matrixObj = GetMatrixObj(env, object); + if (matrixObj == nullptr) { + return nullptr; + } + Matrix4 ret = OHOS::Ace::NG::MatrixUtil::SetMatrixPolyToPoly(matrixObj->matrix4x4, totalPoint); + matrixObj->matrix4x4 = ret; + return object; +} + +static ani_tuple_value Matrix4_TransformPoint([[maybe_unused]] ani_env* env, ani_object object, ani_object options) +{ + ani_tuple_value inputArray = static_cast(options); + ani_tuple_value arrayRes = static_cast(options); + ani_size length = 0; + ani_status tmp = env->TupleValue_GetNumberOfItems(inputArray, &length); + if (ANI_OK != tmp) { + return arrayRes; + } + int32_t inputSize = static_cast(length); + if (inputSize != MATRIX_LENGTH_TRANSFORM_POINT) { + return arrayRes; + } + ani_double x; + if (ANI_OK != env->TupleValue_GetItem_Double(inputArray, static_cast(0), &x)) { + return arrayRes; + } + ani_double y; + if (ANI_OK != env->TupleValue_GetItem_Double(inputArray, static_cast(1), &y)) { + return arrayRes; + } + Matrix4_Obj* matrixObj = GetMatrixObj(env, object); + if (matrixObj == nullptr) { + return arrayRes; + } + Point point { static_cast(x), static_cast(y) }; + Point target = matrixObj->matrix4x4 * point; + + // // in column order + env->TupleValue_SetItem_Double(arrayRes, static_cast(0), target.GetX()); + env->TupleValue_SetItem_Double(arrayRes, static_cast(1), target.GetY()); + return arrayRes; +} + static ani_object Matrix4_Translate([[maybe_unused]] ani_env* env, ani_object object, ani_object options) { double dx = 0.0; @@ -322,17 +450,15 @@ static ani_object Matrix4_Combine([[maybe_unused]] ani_env* env, ani_object obje ani_status BindMatrix(ani_env* env) { static const char* className = "L@ohos/matrix4/matrix4;"; - ani_class cls; - if (ANI_OK != env->FindClass(className, &cls)) { + ani_namespace cls; + if (ANI_OK != env->FindNamespace(className, &cls)) { return ANI_ERROR; } - std::array methods = { ani_native_function { "identity", nullptr, reinterpret_cast(Matrix4_Identity) }, ani_native_function { "init", nullptr, reinterpret_cast(Matrix4_Init) }, }; - - if (ANI_OK != env->Class_BindNativeMethods(cls, methods.data(), methods.size())) { + if (ANI_OK != env->Namespace_BindNativeFunctions(cls, methods.data(), methods.size())) { return ANI_ERROR; }; return ANI_OK; @@ -384,6 +510,9 @@ ani_status BindMatrixTransit(ani_env* env) ani_native_function { "translate", nullptr, reinterpret_cast(Matrix4_Translate) }, ani_native_function { "invert", nullptr, reinterpret_cast(Matrix4_Invert) }, ani_native_function { "combine", nullptr, reinterpret_cast(Matrix4_Combine) }, + ani_native_function { "skew", nullptr, reinterpret_cast(Matrix4_Skew) }, + ani_native_function { "setPolyToPoly", nullptr, reinterpret_cast(Matrix4_SetPolyToPoly) }, + ani_native_function { "transformPoint", nullptr, reinterpret_cast(Matrix4_TransformPoint) }, ani_native_function { "nativeTransferStatic", nullptr, reinterpret_cast(MatrixTransferStatic) }, }; if (ANI_OK != env->Class_BindNativeMethods(cls, methods.data(), methods.size())) { @@ -400,14 +529,14 @@ ANI_EXPORT ani_status ANI_Constructor(ani_vm* vm, uint32_t* result) return ANI_ERROR; } - ani_status ret = OHOS::Ace::MatrixAni::BindMatrix(env); - if (ret != ANI_OK) { - return ret; + ani_status retBindMatrix = OHOS::Ace::MatrixAni::BindMatrix(env); + if (retBindMatrix != ANI_OK) { + return retBindMatrix; } - ani_status ret1 = OHOS::Ace::MatrixAni::BindMatrixTransit(env); - if (ret1 != ANI_OK) { - return ret1; + ani_status retBindMatrixTransit = OHOS::Ace::MatrixAni::BindMatrixTransit(env); + if (retBindMatrixTransit != ANI_OK) { + return retBindMatrixTransit; } *result = ANI_VERSION_1; return ANI_OK;