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 #include "bridge/cj_frontend/cppview/matrix2d.h"
17
18 #include "core/components_ng/render/adapter/matrix2d.h"
19 #include "core/pipeline/pipeline_base.h"
20
21 using namespace OHOS::Ace;
22
23 namespace OHOS::Ace::Framework {
24
NativeMatrix2d()25 NativeMatrix2d::NativeMatrix2d() : FFIData() {}
26
NativeMatrix2d(const int32_t unit)27 NativeMatrix2d::NativeMatrix2d(const int32_t unit) : FFIData()
28 {
29 unit_ = static_cast<CanvasUnit>(unit);
30 }
31
~NativeMatrix2d()32 NativeMatrix2d::~NativeMatrix2d()
33 {
34 LOGI("Native Matrix2d Destroyed: %{public}" PRId64, GetID());
35 }
36
Identity()37 void NativeMatrix2d::Identity()
38 {
39 NG::Matrix2D::Identity(transform_);
40 }
41
Invert()42 void NativeMatrix2d::Invert()
43 {
44 bool retValue = NG::Matrix2D::Invert(transform_);
45 if (!retValue) {
46 transform_.scaleX = 0.0;
47 transform_.scaleY = 0.0;
48 transform_.skewX = 0.0;
49 transform_.skewY = 0.0;
50 transform_.translateX = 0.0;
51 transform_.translateY = 0.0;
52 }
53 }
54
Rotate(double degree,double rx,double ry)55 void NativeMatrix2d::Rotate(double degree, double rx, double ry)
56 {
57 double density = GetDensity();
58 rx *= density;
59 ry *= density;
60 NG::Matrix2D::Rotate(transform_, degree, rx, ry);
61 }
62
Translate(double tx,double ty)63 void NativeMatrix2d::Translate(double tx, double ty)
64 {
65 double density = GetDensity();
66 tx *= density;
67 ty *= density;
68 NG::Matrix2D::Translate(transform_, tx, ty);
69 }
70
Scale(double sx,double sy)71 void NativeMatrix2d::Scale(double sx, double sy)
72 {
73 NG::Matrix2D::Scale(transform_, sx, sy);
74 }
75
GetDensity()76 double NativeMatrix2d::GetDensity()
77 {
78 double density = PipelineBase::GetCurrentDensity();
79 return ((GetUnit() == CanvasUnit::DEFAULT) && !NearZero(density)) ? density : 1.0;
80 }
81 } // namespace OHOS::Ace::Framework