1 /* 2 * Copyright (c) 2025 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 #ifndef RENDER_SERVICE_BASE_RS_HPAE_HIANIMATION_H 17 #define RENDER_SERVICE_BASE_RS_HPAE_HIANIMATION_H 18 19 #include <condition_variable> 20 #include <cstdint> 21 #include <deque> 22 #include <mutex> 23 #include <set> 24 25 #include "hpae_base/rs_hpae_hianimation_types.h" 26 27 #include "common/rs_macros.h" 28 29 namespace OHOS::Rosen { 30 31 class RSB_EXPORT HianimationManager final { 32 public: 33 HianimationManager(const HianimationManager &) = delete; 34 HianimationManager &operator==(const HianimationManager &) = delete; 35 36 static HianimationManager &GetInstance(); 37 38 void OpenDeviceAsync(); 39 void AlgoInitAsync(uint32_t imgWidth, uint32_t imgHeight, float maxSigma, uint32_t format); 40 void AlgoDeInitAsync(); 41 42 void OpenDevice(); 43 void CloseDevice(); 44 45 bool HianimationInputCheck(const struct BlurImgParam *imgInfo, const struct HaeNoiseValue *noisePara); 46 47 int32_t HianimationAlgoInit(uint32_t imgWidth, uint32_t imgHeight, float maxSigma, uint32_t format); 48 49 int32_t HianimationAlgoDeInit(); 50 51 int32_t HianimationBuildTask(const struct HaeBlurBasicAttr *basicInfo, 52 const struct HaeBlurEffectAttr *effectInfo, uint32_t *outTaskId, void **outTaskPtr); 53 54 int32_t HianimationDestroyTask(uint32_t taskId); 55 56 bool HianimationInvalid(); 57 58 int32_t HianimationDestroyTaskAndNotify(uint32_t taskId); 59 60 bool WaitPreviousTask(); 61 62 bool WaitAllTaskDone(); 63 64 void WaitAlgoInit(); 65 66 void HianimationPerfTrack(); 67 68 private: 69 std::mutex mutex_; // mutex for public api 70 71 HianimationManager(); 72 ~HianimationManager(); 73 74 void WaitHpaeDone(); 75 void NotifyHpaeDone(); 76 77 hianimation_algo_device_t *hianimationDevice_ = nullptr; 78 void *libHandle_ = nullptr; 79 80 std::mutex hpaePerfMutex_; 81 bool hpaePerfDone_ = true; 82 std::condition_variable hpaePerfCv_; 83 84 int openFailNum_ = 0; 85 86 std::set<uint32_t> taskIdMap_; 87 std::condition_variable taskAvailableCv_; 88 89 std::mutex algoInitMutex_; 90 bool algoInitDone_ = true; 91 std::condition_variable algoInitCv_; 92 }; 93 94 } // OHOS::Rosen 95 96 #endif // RENDER_SERVICE_BASE_RS_HPAE_HIANIMATION_H 97