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