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