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