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 "skia_matrix44.h"
17
18 #include "utils/matrix.h"
19 #include "utils/matrix44.h"
20
21 namespace OHOS {
22 namespace Rosen {
23 namespace Drawing {
SkiaMatrix44()24 SkiaMatrix44::SkiaMatrix44() : skMatrix44_() {}
25
GetSkMatrix44() const26 const SkM44& SkiaMatrix44::GetSkMatrix44() const
27 {
28 return skMatrix44_;
29 }
30
Translate(scalar dx,scalar dy,scalar dz)31 void SkiaMatrix44::Translate(scalar dx, scalar dy, scalar dz)
32 {
33 skMatrix44_.setTranslate(dx, dy, dz);
34 }
35
Scale(scalar sx,scalar sy,scalar sz)36 void SkiaMatrix44::Scale(scalar sx, scalar sy, scalar sz)
37 {
38 skMatrix44_.setScale(sx, sy, sz);
39 }
40
PreTranslate(scalar dx,scalar dy,scalar dz)41 void SkiaMatrix44::PreTranslate(scalar dx, scalar dy, scalar dz)
42 {
43 skMatrix44_.preTranslate(dx, dy, dz);
44 }
45
PostTranslate(scalar dx,scalar dy,scalar dz)46 void SkiaMatrix44::PostTranslate(scalar dx, scalar dy, scalar dz)
47 {
48 skMatrix44_.postTranslate(dx, dy, dz);
49 }
50
PreScale(scalar sx,scalar sy,scalar sz)51 void SkiaMatrix44::PreScale(scalar sx, scalar sy, scalar sz)
52 {
53 skMatrix44_.preScale(sx, sy, sz);
54 }
55
Multiply(const Matrix44 & a,const Matrix44 & b)56 void SkiaMatrix44::Multiply(const Matrix44& a, const Matrix44& b)
57 {
58 auto m1 = a.GetImpl<SkiaMatrix44>();
59 auto m2 = b.GetImpl<SkiaMatrix44>();
60 skMatrix44_.setConcat(m1->GetSkMatrix44(), m2->GetSkMatrix44());
61 }
62
SetCol(int column,scalar x,scalar y,scalar z,scalar w)63 void SkiaMatrix44::SetCol(int column, scalar x, scalar y, scalar z, scalar w)
64 {
65 auto skv4 = SkV4 { x, y, z, w };
66 skMatrix44_.setCol(column, skv4);
67 }
68
SetMatrix44ColMajor(const std::array<scalar,Matrix44Impl::MATRIX44_SIZE> & buffer)69 void SkiaMatrix44::SetMatrix44ColMajor(const std::array<scalar, Matrix44Impl::MATRIX44_SIZE>& buffer)
70 {
71 SkScalar r[16] = {
72 buffer[0], buffer[1], buffer[2], buffer[3],
73 buffer[4], buffer[5], buffer[6], buffer[7],
74 buffer[8], buffer[9], buffer[10], buffer[11],
75 buffer[12], buffer[13], buffer[14], buffer[15]
76 };
77 skMatrix44_ = SkM44::ColMajor(r);
78 }
79
SetMatrix44RowMajor(const std::array<scalar,Matrix44Impl::MATRIX44_SIZE> & buffer)80 void SkiaMatrix44::SetMatrix44RowMajor(const std::array<scalar, Matrix44Impl::MATRIX44_SIZE>& buffer)
81 {
82 SkScalar r[16] = {
83 buffer[0], buffer[1], buffer[2], buffer[3],
84 buffer[4], buffer[5], buffer[6], buffer[7],
85 buffer[8], buffer[9], buffer[10], buffer[11],
86 buffer[12], buffer[13], buffer[14], buffer[15]
87 };
88 skMatrix44_ = SkM44::RowMajor(r);
89 }
90
ConvertToMatrix()91 Matrix SkiaMatrix44::ConvertToMatrix()
92 {
93 Matrix matrix;
94 SkMatrix skMatrix = skMatrix44_.asM33();
95 matrix.SetMatrix(skMatrix[0], skMatrix[1], skMatrix[2],
96 skMatrix[3], skMatrix[4], skMatrix[5],
97 skMatrix[6], skMatrix[7], skMatrix[8]);
98 return matrix;
99 }
100 } // namespace Drawing
101 } // namespace Rosen
102 } // namespace OHOS
103