1 /* 2 * Copyright 2020 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef SURROUND_VIEW_SERVICE_IMPL_ANIMATION_H_ 18 #define SURROUND_VIEW_SERVICE_IMPL_ANIMATION_H_ 19 20 #include "IOModuleCommon.h" 21 #include "core_lib.h" 22 23 #include <utils/SystemClock.h> 24 #include <cstdint> 25 #include <map> 26 #include <set> 27 #include <vector> 28 29 #include <android/hardware/automotive/vehicle/2.0/IVehicle.h> 30 31 using namespace ::android::hardware::automotive::vehicle::V2_0; 32 using namespace android_auto::surround_view; 33 34 namespace android { 35 namespace hardware { 36 namespace automotive { 37 namespace sv { 38 namespace V1_0 { 39 namespace implementation { 40 41 // Car animation class. It is constructed with textures, animations, and 42 // vhal_handler. It automatically updates animation params when 43 // GetUpdatedAnimationParams() is called. 44 class AnimationModule { 45 public: 46 // Constructor. 47 // |parts| is from I/O module. The key value is part id. 48 // |textures| is from I/O module. The key value is texture id. 49 // |animations| is from I/O module. 50 AnimationModule(const std::map<std::string, CarPart>& partsMap, 51 const std::map<std::string, CarTexture>& texturesMap, 52 const std::vector<AnimationInfo>& animations); 53 54 // Gets Animation parameters with input of VehiclePropValue. 55 std::vector<AnimationParam> getUpdatedAnimationParams( 56 const std::vector<VehiclePropValue>& vehiclePropValue); 57 58 private: 59 // Internal car part status. 60 struct CarPartStatus { 61 // Car part id. 62 std::string partId; 63 64 // Car part children ids. 65 std::vector<std::string> childIds; 66 67 // Parent model matrix. 68 Mat4x4 parentModel; 69 70 // Local model in local coordinate. 71 Mat4x4 localModel; 72 73 // Current status model matrix in global coordinate with 74 // animations combined. 75 // current_model = local_model * parent_model; 76 Mat4x4 currentModel; 77 78 // Gamma parameters. 79 float gamma; 80 81 // Texture id. 82 std::string textureId; 83 84 // Internal vhal percentage. Each car part maintain its own copy 85 // the vhal percentage. 86 // Key value is vhal property (combined with area id). 87 std::map<uint64_t, float> vhalProgressMap; 88 89 // Vhal off map. Key value is vhal property (combined with area id). 90 // Assume off status when vhal value is 0. 91 std::map<uint64_t, bool> vhalOffMap; 92 }; 93 94 // Internal Vhal status. 95 struct VhalStatus { 96 float vhalValueFloat; 97 }; 98 99 // Help function to get vhal to parts map. 100 void mapVhalToParts(); 101 102 // Help function to init car part status for constructor. 103 void initCarPartStatus(); 104 105 // Iteratively update children parts status if partent status is changed. 106 void updateChildrenParts(const std::string& partId, const Mat4x4& parentModel); 107 108 // Perform gamma opertion for the part with given vhal property. 109 void performGammaOp(const std::string& partId, uint64_t vhalProperty, const GammaOp& gammaOp); 110 111 // Perform translation opertion for the part with given vhal property. 112 void performTranslationOp(const std::string& partId, uint64_t vhalProperty, 113 const TranslationOp& translationOp); 114 115 // Perform texture opertion for the part with given vhal property. 116 // Not implemented yet. 117 void performTextureOp(const std::string& partId, uint64_t vhalProperty, 118 const TextureOp& textureOp); 119 120 // Perform rotation opertion for the part with given vhal property. 121 void performRotationOp(const std::string& partId, uint64_t vhalProperty, 122 const RotationOp& rotationOp); 123 124 // Last call time of GetUpdatedAnimationParams() in millisecond. 125 float mLastCallTime; 126 127 // Current call time of GetUpdatedAnimationParams() in millisecond. 128 float mCurrentCallTime; 129 130 // Flag indicating if GetUpdatedAnimationParams() was called before. 131 bool mIsCalled; 132 133 std::map<std::string, CarPart> mPartsMap; 134 135 std::map<std::string, CarTexture> mTexturesMap; 136 137 std::vector<AnimationInfo> mAnimations; 138 139 std::map<std::string, AnimationInfo> mPartsToAnimationMap; 140 141 std::map<uint64_t, VhalStatus> mVhalStatusMap; 142 143 std::map<uint64_t, std::set<std::string>> mVhalToPartsMap; 144 145 std::map<std::string, CarPartStatus> mCarPartsStatusMap; 146 147 std::map<std::string, AnimationParam> mUpdatedPartsMap; 148 }; 149 150 } // namespace implementation 151 } // namespace V1_0 152 } // namespace sv 153 } // namespace automotive 154 } // namespace hardware 155 } // namespace android 156 157 #endif // SURROUND_VIEW_SERVICE_IMPL_ANIMATION_H_ 158