1 /*
2  * Copyright (c) 2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef OHOS_ACE_FRAMEWORK_CJ_MATRIX4_FFI_H
17 #define OHOS_ACE_FRAMEWORK_CJ_MATRIX4_FFI_H
18 
19 #include <cstdint>
20 
21 #include "base/geometry/matrix4.h"
22 #include "ffi_remote_data.h"
23 #include "bridge/cj_frontend/interfaces/cj_ffi/cj_common_ffi.h"
24 #include "bridge/cj_frontend/interfaces/cj_ffi/cj_macro.h"
25 #include "bridge/cj_frontend/interfaces/cj_ffi/utils.h"
26 
27 using VectorFloat32Ptr = void*;
28 
29 namespace OHOS::Matrix4 {
30 
31 class ACE_EXPORT NativeMatrix : public OHOS::FFI::FFIData {
32     DECL_TYPE(NativeMatrix, OHOS::FFI::FFIData)
33 public:
34     NativeMatrix();
35 
GetMatrix4()36     const OHOS::Ace::Matrix4& GetMatrix4()
37     {
38         return instance_;
39     }
40 
SetMatrix4(const OHOS::Ace::Matrix4 & instance)41     void SetMatrix4(const OHOS::Ace::Matrix4& instance)
42     {
43         instance_ = instance;
44     }
45 
SetMatrix4(OHOS::Ace::Matrix4 && instance)46     void SetMatrix4(OHOS::Ace::Matrix4&& instance)
47     {
48         instance_ = std::move(instance);
49     }
50 
51 private:
52     OHOS::Ace::Matrix4 instance_ = OHOS::Ace::Matrix4();
53 };
54 
55 } // namespace OHOS::Matrix4
56 
57 extern "C" {
58 struct FfiScaleParams {
59     float x;
60     float y;
61     float z;
62     float centerX;
63     float centerY;
64 };
65 
66 struct FfiRotateParams {
67     float x;
68     float y;
69     float z;
70     float angle;
71     float centerX;
72     float centerY;
73 };
74 
75 struct FfiPoint {
76     double x;
77     double y;
78 };
79 
80 CJ_EXPORT int64_t FfiOHOSMatrix4Init(VectorFloat32Ptr array);
81 CJ_EXPORT int64_t FfiOHOSMatrix4Identity();
82 CJ_EXPORT int64_t FfiOHOSMatrix4Copy(int64_t id);
83 CJ_EXPORT void FfiOHOSMatrix4Invert(int64_t id);
84 CJ_EXPORT void FfiOHOSMatrix4Combine(int64_t result, int64_t target);
85 CJ_EXPORT void FfiOHOSMatrix4Translate(int64_t id, float x, float y, float z);
86 CJ_EXPORT void FfiOHOSMatrix4Scale(int64_t id, FfiScaleParams params);
87 CJ_EXPORT void FfiOHOSMatrix4Rotate(int64_t id, FfiRotateParams params);
88 CJ_EXPORT FfiPoint FfiOHOSMatrix4TransformPoint(int64_t id, FfiPoint ffiPoint);
89 }
90 
91 #endif // OHOS_ACE_FRAMEWORK_CJ_MATRIX4_FFI_H
92