1 /* 2 * Copyright (c) 2021 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 HOS_BUFFER_ALLOCATOR_UTILS_H 17 #define HOS_BUFFER_ALLOCATOR_UTILS_H 18 19 #include "camera.h" 20 #include "ibuffer.h" 21 #include "ibuffer_allocator.h" 22 #include <memory> 23 24 namespace OHOS::Camera { 25 class BufferAllocatorUtils { 26 public: 27 // get buffer allocator 28 static std::shared_ptr<IBufferAllocator> GetAllocator(std::shared_ptr<IBuffer>& buffer); 29 30 // allocate buffer from source. 31 static std::shared_ptr<IBuffer> AllocBuffer(const int32_t source, 32 const uint32_t width, 33 const uint32_t height, 34 const uint64_t usage, 35 const uint32_t format); 36 37 // free the buffer 38 static RetCode FreeBuffer(std::shared_ptr<IBuffer>& buffer); 39 40 // Map the buffer 41 static RetCode MapBuffer(std::shared_ptr<IBuffer>& buffer); 42 43 // Unmap the buffer 44 static RetCode UnmapBuffer(std::shared_ptr<IBuffer>& buffer); 45 46 // flush the buffer 47 static RetCode FlushCache(std::shared_ptr<IBuffer>& buffer); 48 49 // invalidate the cache, update cache from memory 50 static RetCode InvalidateCache(std::shared_ptr<IBuffer>& buffer); 51 private: 52 static std::shared_ptr<IBufferAllocator> GetBufferAllocator(const int32_t source); 53 }; 54 } // namespace OHOS::Camera 55 #endif 56