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_hm_symbol_config_ohos.h"
17
18 #include "src/ports/skia_ohos/HmSymbolConfig_ohos.h"
19 #include "utils/log.h"
20 namespace OHOS {
21 namespace Rosen {
22 namespace Drawing {
23
GetSymbolLayersGroups(uint16_t glyphId)24 DrawingSymbolLayersGroups SkiaHmSymbolConfigOhos::GetSymbolLayersGroups(uint16_t glyphId)
25 {
26 #if !defined(CROSS_PLATFORM)
27 SymbolLayersGroups groups = HmSymbolConfig_OHOS::GetInstance()->GetSymbolLayersGroups(glyphId);
28
29 DrawingSymbolLayersGroups drawingGroups;
30 drawingGroups.symbolGlyphId = groups.symbolGlyphId;
31 drawingGroups.layers = groups.layers;
32 std::vector<DrawingAnimationSetting> drawingSettings;
33 const auto& settings = groups.animationSettings;
34 std::map<DrawingSymbolRenderingStrategy, std::vector<DrawingRenderGroup>> drawingRenderModeGroups;
35 const auto& renderModeGroups = groups.renderModeGroups;
36 for (size_t i = 0; i < settings.size(); i++) {
37 drawingSettings.push_back(ConvertToDrawingAnimationSetting(settings.at(i)));
38 }
39
40 auto iter = renderModeGroups.begin();
41 while (iter != renderModeGroups.end()) {
42 auto renderGroups = iter->second;
43 std::vector<DrawingRenderGroup> drawingRenderGroups;
44 for (size_t j = 0; j < renderGroups.size(); j++) {
45 drawingRenderGroups.push_back(ConvertToDrawingRenderGroup(renderGroups.at(j)));
46 }
47 auto key = static_cast<DrawingSymbolRenderingStrategy>(iter->first);
48 drawingRenderModeGroups[key] = drawingRenderGroups;
49 iter++;
50 }
51
52 drawingGroups.animationSettings = drawingSettings;
53 drawingGroups.renderModeGroups = drawingRenderModeGroups;
54
55 return drawingGroups;
56 #else
57 DrawingSymbolLayersGroups drawingGroups;
58 return drawingGroups;
59 #endif
60 }
61
ConvertToDrawingAnimationSetting(AnimationSetting setting)62 DrawingAnimationSetting SkiaHmSymbolConfigOhos::ConvertToDrawingAnimationSetting(AnimationSetting setting)
63 {
64 DrawingAnimationSetting drawingSetting;
65 for (size_t i = 0; i < setting.animationTypes.size(); i++) {
66 DrawingAnimationType animationType = static_cast<DrawingAnimationType>(setting.animationTypes[i]);
67 drawingSetting.animationTypes.push_back(animationType);
68 }
69
70 std::vector<DrawingGroupSetting> groupSettings;
71 for (size_t i = 0; i < setting.groupSettings.size(); i++) {
72 DrawingGroupSetting groupSetting;
73 groupSetting.animationIndex = setting.groupSettings.at(i).animationIndex;
74 groupSetting.groupInfos = ConvertToDrawingGroupInfo(setting.groupSettings.at(i).groupInfos);
75 groupSettings.push_back(groupSetting);
76 }
77 drawingSetting.groupSettings = groupSettings;
78
79 return drawingSetting;
80 }
81
ConvertToDrawingRenderGroup(RenderGroup group)82 DrawingRenderGroup SkiaHmSymbolConfigOhos::ConvertToDrawingRenderGroup(RenderGroup group)
83 {
84 DrawingRenderGroup drawingRenderGroup;
85 drawingRenderGroup.color.a = group.color.a;
86 drawingRenderGroup.color.r = group.color.r;
87 drawingRenderGroup.color.g = group.color.g;
88 drawingRenderGroup.color.b = group.color.b;
89 drawingRenderGroup.groupInfos = ConvertToDrawingGroupInfo(group.groupInfos);
90
91 return drawingRenderGroup;
92 }
93
ConvertToDrawingGroupInfo(std::vector<GroupInfo> infos)94 std::vector<DrawingGroupInfo> SkiaHmSymbolConfigOhos::ConvertToDrawingGroupInfo(std::vector<GroupInfo> infos)
95 {
96 std::vector<DrawingGroupInfo> groupInfos;
97 for (size_t i = 0; i < infos.size(); i++) {
98 DrawingGroupInfo groupInfo;
99 groupInfo.layerIndexes = infos.at(i).layerIndexes;
100 groupInfo.maskIndexes = infos.at(i).maskIndexes;
101 groupInfos.push_back(groupInfo);
102 }
103 return groupInfos;
104 }
105
ConvertPiecewiseParameter(const PiecewiseParameter & in)106 static DrawingPiecewiseParameter ConvertPiecewiseParameter(const PiecewiseParameter& in)
107 {
108 DrawingPiecewiseParameter out;
109 out.curveType = static_cast<DrawingCurveType>(in.curveType);
110 out.duration = in.duration;
111 out.delay = in.delay;
112 std::copy(in.curveArgs.begin(), in.curveArgs.end(),
113 std::inserter(out.curveArgs, out.curveArgs.begin()));
114 std::copy(in.properties.begin(), in.properties.end(),
115 std::inserter(out.properties, out.properties.begin()));
116 return out;
117 }
118
ConvertPiecewiseParametersVec(const std::vector<PiecewiseParameter> & in)119 static std::vector<DrawingPiecewiseParameter> ConvertPiecewiseParametersVec(const std::vector<PiecewiseParameter>& in)
120 {
121 std::vector<DrawingPiecewiseParameter> out;
122 for (const auto& tmp : in) {
123 out.push_back(ConvertPiecewiseParameter(tmp));
124 }
125 return out;
126 }
127
128 #if !defined(CROSS_PLATFORM)
GetGroupParameters(DrawingAnimationType type,uint16_t groupSum,uint16_t animationMode,DrawingCommonSubType commonSubType)129 std::vector<std::vector<DrawingPiecewiseParameter>> SkiaHmSymbolConfigOhos::GetGroupParameters(
130 DrawingAnimationType type, uint16_t groupSum, uint16_t animationMode, DrawingCommonSubType commonSubType)
131 {
132 auto animationType = static_cast<AnimationType>(type);
133 auto subType = static_cast<CommonSubType>(commonSubType);
134 auto parametersPtr = HmSymbolConfig_OHOS::GetInstance()->GetGroupParameters(
135 animationType, groupSum, animationMode, subType);
136
137 std::vector<std::vector<DrawingPiecewiseParameter>> parameters;
138 for (auto& paraTmp : parametersPtr) {
139 parameters.push_back(ConvertPiecewiseParametersVec(paraTmp));
140 }
141 return parameters;
142 }
143 #endif
144
145 } // namespace Drawing
146 } // namespace Rosen
147 } // namespace OHOS