• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef LIB_RS_SRC_HM_SYMBOL_H_
16 #define LIB_RS_SRC_HM_SYMBOL_H_
17 #include <iostream>
18 #include <vector>
19 #include <string>
20 #include <map>
21 
22 #include "third_party/skia/include/core/SkCanvas.h"
23 #include "third_party/skia/include/core/SkFont.h"
24 #include "third_party/skia/include/core/SkFontMetrics.h"
25 #include "third_party/skia/include/core/SkMaskFilter.h"
26 #include "third_party/skia/include/core/SkPaint.h"
27 #include "third_party/skia/include/core/SkTextBlob.h"
28 #include "third_party/skia/include/core/SkTypeface.h"
29 #include "third_party/skia/include/core/SkTypes.h"
30 #include "third_party/skia/include/core/SkPaint.h"
31 #include "third_party/skia/include/pathops/SkPathOps.h"
32 #include "third_party/skia/include/effects/SkDashPathEffect.h"
33 #include "third_party/skia/include/effects/SkDiscretePathEffect.h"
34 
35 enum AnimationType {
36     INVALID_ANIMATION_TYPE = 0,
37     SCALE_TYPE = 1,
38     VARIABLE_COLOR_TYPE = 2,
39     APPEAR_TYPE = 3,
40     DISAPPEAR_TYPE = 4,
41     BOUNCE_TYPE = 5,
42     PULSE_TYPE = 6,
43     REPLACE_APPEAR_TYPE = 7,
44     REPLACE_DISAPPEAR_TYPE
45 };
46 
47 enum CurveType {
48     INVALID_CURVE_TYPE = 0,
49     SPRING = 1,
50     LINEAR = 2,
51     FRICTION = 3,
52     SHARP = 4,
53 };
54 
55 enum CommonSubType {
56     DOWN = 0,
57     UP = 1,
58 };
59 
60 using PiecewiseParameter = struct PiecewiseParameter {
61     CurveType curveType;
62     std::map<std::string, double_t> curveArgs;
63     uint32_t duration = 0;
64     int delay = 0;
65     std::map<std::string, std::vector<double_t>> properties;
66 };
67 
68 using AnimationPara = struct AnimationPara {
69     uint16_t animationMode = 0; // 0 is default value, is byLayer effect
70     CommonSubType commonSubType = CommonSubType::DOWN;
71     std::vector<std::vector<PiecewiseParameter>> groupParameters;
72 };
73 
74 using AnimationInfo = struct AnimationInfo {
75     AnimationType animationType;
76     std::vector<AnimationPara> animationParas;
77 };
78 
79 using SColor = struct SColor {
80     float a = 1;
81     U8CPU r = 0;
82     U8CPU g = 0;
83     U8CPU b = 0;
84 };
85 
86 using GroupInfo = struct GroupInfo {
87     std::vector<size_t> layerIndexes;
88     std::vector<size_t> maskIndexes;
89 };
90 
91 using GroupSetting = struct GroupSetting {
92     std::vector<GroupInfo> groupInfos;
93     int animationIndex = -1; // -1 is default value, the level has no effecet
94 };
95 
96 using AnimationSetting = struct AnimationSetting {
97     std::vector<AnimationType> animationTypes;
98     std::vector<GroupSetting> groupSettings;
99 };
100 
101 using RenderGroup = struct RenderGroup {
102     std::vector<GroupInfo> groupInfos;
103     SColor color;
104 };
105 
106 enum EffectStrategy {
107     NONE = 0,
108     SCALE = 1,
109     VARIABLE_COLOR = 2,
110     APPEAR = 3,
111     DISAPPEAR = 4,
112     BOUNCE = 5,
113     PULSE = 6,
114     REPLACE_APPEAR = 7,
115     REPLACE_DISAPPEAR
116 };
117 
118 using SymbolLayers = struct SymbolLayers {
119     uint32_t symbolGlyphId;
120     std::vector<std::vector<size_t>> layers;
121     std::vector<RenderGroup> renderGroups;
122 };
123 
124 enum SymbolRenderingStrategy {
125     SINGLE = 0,
126     MULTIPLE_COLOR = 1,
127     MULTIPLE_OPACITY = 2,
128 };
129 
130 
131 using SymbolLayersGroups = struct SymbolLayersGroups {
132     uint32_t symbolGlyphId = 0;
133     std::vector<std::vector<size_t>> layers;
134     std::map<SymbolRenderingStrategy, std::vector<RenderGroup>> renderModeGroups;
135     std::vector<AnimationSetting> animationSettings;
136 };
137 
138 class SK_API HMSymbolData
139 {
140 public:
141     SymbolLayers symbolInfo_;
142     SkPath path_;
143     uint64_t symbolId_ = 0;
144 };
145 
146 class SK_API HMSymbol
147 {
148 public:
HMSymbol()149     HMSymbol(){};
150 
~HMSymbol()151     ~HMSymbol(){};
152 
153     static void PathOutlineDecompose(const SkPath& path, std::vector<SkPath>& paths);
154 
155     static void MultilayerPath(const std::vector<std::vector<size_t>>& multMap,
156         const std::vector<SkPath>& paths, std::vector<SkPath>& multPaths);
157 };
158 
159 #endif