1 /* 2 * Copyright (C) 2024 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 IMAGE_EFFECT_EFFECT_MEMORY_MANAGER_H 17 #define IMAGE_EFFECT_EFFECT_MEMORY_MANAGER_H 18 19 #include "effect_memory.h" 20 #include "error_code.h" 21 #include "effect_buffer.h" 22 #include "image_effect_marco_define.h" 23 24 namespace OHOS { 25 namespace Media { 26 namespace Effect { 27 28 enum class MemDataType { 29 INPUT = 0, 30 OUTPUT, 31 OTHER, 32 }; 33 34 struct Memory { 35 std::shared_ptr<MemoryData> memoryData_ = nullptr; 36 MemDataType memDataType_ = MemDataType::OTHER; 37 bool isAllowModify_ = true; 38 }; 39 40 class EffectMemoryManager { 41 public: 42 EffectMemoryManager() = default; 43 ~EffectMemoryManager() = default; 44 45 IMAGE_EFFECT_EXPORT ErrorCode Init(const std::shared_ptr<EffectBuffer> &srcEffectBuffer, 46 const std::shared_ptr<EffectBuffer> &dstEffectBuffer); 47 IMAGE_EFFECT_EXPORT void SetIPType(IPType ipType); 48 49 IMAGE_EFFECT_EXPORT MemoryData *AllocMemory(void *srcAddr, MemoryInfo &allocMemInfo); 50 IMAGE_EFFECT_EXPORT std::shared_ptr<Memory> GetAllocMemoryByAddr(void *addr); 51 52 IMAGE_EFFECT_EXPORT std::shared_ptr<Memory> GetMemoryByAddr(void *addr); 53 IMAGE_EFFECT_EXPORT void AddMemory(std::shared_ptr<Memory> &memory); 54 IMAGE_EFFECT_EXPORT void RemoveMemory(std::shared_ptr<Memory> &memory); 55 56 IMAGE_EFFECT_EXPORT void ClearMemory(); 57 58 IMAGE_EFFECT_EXPORT void Deinit(); 59 private: 60 void AddFilterMemory(const std::shared_ptr<EffectBuffer> &effectBuffer, MemDataType memDataType, 61 bool isAllowModify); 62 63 std::vector<std::shared_ptr<Memory>> memorys_; 64 IPType runningIPType_ = IPType::DEFAULT; 65 }; 66 } // namespace Effect 67 } // namespace Media 68 } // namespace OHOS 69 #endif // IMAGE_EFFECT_EFFECT_MEMORY_MANAGER_H 70