1 /*
2 * Copyright (c) 2021 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 "core/pipeline/layers/transform_layer.h"
17
18 #include "frameworks/core/components/svg/svg_transform.h"
19 #include "frameworks/core/components/transform/flutter_render_transform.h"
20
21 #include "base/log/dump_log.h"
22
23 namespace OHOS::Ace::Flutter {
24
Update(const Matrix4 & matrix)25 void TransformLayer::Update(const Matrix4& matrix)
26 {
27 matrix_ = matrix;
28 }
29
AddToScene(SceneBuilder & builder,double x,double y)30 void TransformLayer::AddToScene(SceneBuilder& builder, double x, double y)
31 {
32 builder.PushTransform(matrix_);
33 if (filterPaint_ != std::nullopt) {
34 builder.PushFilter(filterPaint_.value());
35 }
36 if (alpha_ != std::nullopt && alpha_.value() != UINT8_MAX) {
37 builder.PushOpacity(alpha_.value());
38 }
39 AddChildToScene(builder, x_ + x, y_ + y);
40 builder.Pop();
41 if (filterPaint_ != std::nullopt) {
42 builder.Pop();
43 }
44 if (alpha_ != std::nullopt && alpha_.value() != UINT8_MAX) {
45 builder.Pop();
46 }
47 }
48
Dump()49 void TransformLayer::Dump()
50 {
51 OffsetLayer::Dump();
52 if (DumpLog::GetInstance().GetDumpFile()) {
53 DumpLog::GetInstance().AddDesc("Matrix4:");
54 DumpLog::GetInstance().AddDesc("[", matrix_[0], matrix_[1], matrix_[2], matrix_[4], "]");
55 DumpLog::GetInstance().AddDesc("[", matrix_[4], matrix_[5], matrix_[6], matrix_[7], "]");
56 DumpLog::GetInstance().AddDesc("[", matrix_[8], matrix_[9], matrix_[10], matrix_[11], "]");
57 DumpLog::GetInstance().AddDesc("[", matrix_[12], matrix_[13], matrix_[14], matrix_[15], "]");
58 }
59 }
60
SetFilter(const SkPaint & skPaint)61 void TransformLayer::SetFilter(const SkPaint& skPaint)
62 {
63 filterPaint_ = skPaint;
64 }
65
SetOpacityLayer(int32_t alpha)66 void TransformLayer::SetOpacityLayer(int32_t alpha)
67 {
68 alpha_ = alpha;
69 }
70
71 } // namespace OHOS::Ace::Flutter
72