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/matrix44.h"
19
20 namespace OHOS {
21 namespace Rosen {
22 namespace Drawing {
SkiaMatrix44()23 SkiaMatrix44::SkiaMatrix44() : skMatrix44_() {}
24
25 #ifdef NEW_SKIA
GetSkMatrix44() const26 const SkM44& SkiaMatrix44::GetSkMatrix44() const
27 #else
28 const SkMatrix44& SkiaMatrix44::GetSkMatrix44() const
29 #endif
30 {
31 return skMatrix44_;
32 }
33
Translate(scalar dx,scalar dy,scalar dz)34 void SkiaMatrix44::Translate(scalar dx, scalar dy, scalar dz)
35 {
36 skMatrix44_.setTranslate(dx, dy, dz);
37 }
38
Scale(scalar sx,scalar sy,scalar sz)39 void SkiaMatrix44::Scale(scalar sx, scalar sy, scalar sz)
40 {
41 skMatrix44_.setScale(sx, sy, sz);
42 }
43
Multiply(const Matrix44 & a,const Matrix44 & b)44 void SkiaMatrix44::Multiply(const Matrix44& a, const Matrix44& b)
45 {
46 auto m1 = a.GetImpl<SkiaMatrix44>();
47 auto m2 = b.GetImpl<SkiaMatrix44>();
48 skMatrix44_.setConcat(m1->GetSkMatrix44(), m2->GetSkMatrix44());
49 }
50
SetMatrix44(const std::array<scalar,Matrix44Impl::MATRIX44_SIZE> & buffer)51 void SkiaMatrix44::SetMatrix44(const std::array<scalar, Matrix44Impl::MATRIX44_SIZE>& buffer)
52 {
53 #ifdef NEW_SKIA
54 SkScalar r[16] = {
55 buffer[0], buffer[1], buffer[2], buffer[3],
56 buffer[4], buffer[5], buffer[6], buffer[7],
57 buffer[8], buffer[9], buffer[10], buffer[11],
58 buffer[12], buffer[13], buffer[14], buffer[15]
59 };
60 skMatrix44_ = SkM44::ColMajor(r);
61 #else
62 skMatrix44_.set4x4(
63 buffer[0], buffer[1], buffer[2], buffer[3],
64 buffer[4], buffer[5], buffer[6], buffer[7],
65 buffer[8], buffer[9], buffer[10], buffer[11],
66 buffer[12], buffer[13], buffer[14], buffer[15]);
67 #endif
68 }
69
ConvertToMatrix()70 Matrix SkiaMatrix44::ConvertToMatrix()
71 {
72 Matrix matrix;
73 #ifdef NEW_SKIA
74 SkMatrix skMatrix = skMatrix44_.asM33();
75 #else
76 SkMatrix skMatrix = SkMatrix(skMatrix44_);
77 #endif
78 matrix.SetMatrix(skMatrix[0], skMatrix[1], skMatrix[2],
79 skMatrix[3], skMatrix[4], skMatrix[5],
80 skMatrix[6], skMatrix[7], skMatrix[8]);
81 return matrix;
82 }
83 } // namespace Drawing
84 } // namespace Rosen
85 } // namespace OHOS
86