• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 "frameworks/core/components_ng/render/adapter/matrix_util.h"
17 
18 #include "2d_graphics/include/utils/matrix.h"
19 
20 namespace OHOS::Ace::NG {
21 constexpr int32_t POSITION_TWO = 2;
22 constexpr int32_t POSITION_THREE = 3;
23 constexpr int32_t POSITION_FOUR = 4;
24 constexpr int32_t POSITION_FIVE = 5;
25 constexpr int32_t POSITION_SIX = 6;
26 constexpr int32_t POSITION_SEVEN = 7;
27 constexpr int32_t POSITION_EIGHT = 8;
28 
SetMatrixPolyToPoly(const Matrix4 & matrix,const std::vector<OHOS::Ace::NG::PointT<int32_t>> & totalPoint)29 Matrix4 MatrixUtil::SetMatrixPolyToPoly(
30     const Matrix4& matrix, const std::vector<OHOS::Ace::NG::PointT<int32_t>>& totalPoint)
31 {
32     auto matrix3d = OHOS::Rosen::Drawing::Matrix();
33     /**
34     * When converting from matrix4 to matrix3
35     * [a b c]    [a b 0 c]
36     * [d e f] -> [d e 0 f]
37     * [g h i]    [0 0 1 0]
38     *            [g h 0 i]
39     */
40     matrix3d.SetMatrix(matrix.Get(0, 0), matrix.Get(1, 0), matrix.Get(POSITION_THREE, 0), matrix.Get(0, 1),
41         matrix.Get(1, 1), matrix.Get(POSITION_THREE, 1), matrix.Get(0, POSITION_THREE), matrix.Get(1, POSITION_THREE),
42         matrix.Get(POSITION_THREE, POSITION_THREE));
43     size_t arrayLength = totalPoint.size() / 2;
44     OHOS::Rosen::Drawing::PointF src[arrayLength];
45     OHOS::Rosen::Drawing::PointF dst[arrayLength];
46     for (size_t i = 0; i < arrayLength; i++) {
47         auto point = totalPoint[i];
48         src[i] = OHOS::Rosen::Drawing::Point(point.GetX(), point.GetY());
49     }
50     for (size_t i = 0; i < arrayLength; i++) {
51         auto point = totalPoint[i + arrayLength];
52         dst[i] = OHOS::Rosen::Drawing::Point(point.GetX(), point.GetY());
53     }
54     matrix3d.SetPolyToPoly(src, dst, arrayLength);
55     Matrix4 retMatrix4(matrix3d.Get(0), matrix3d.Get(1), 0, matrix3d.Get(POSITION_TWO), matrix3d.Get(POSITION_THREE),
56         matrix3d.Get(POSITION_FOUR), 0, matrix3d.Get(POSITION_FIVE), 0, 0, 1, 0, matrix3d.Get(POSITION_SIX),
57         matrix3d.Get(POSITION_SEVEN), 0, matrix3d.Get(POSITION_EIGHT));
58     return retMatrix4;
59 }
60 }