1 /* 2 * Copyright (c) 2020 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_CAMERA_BUFFER_ADAPTER_H 17 #define HOS_CAMERA_BUFFER_ADAPTER_H 18 19 #include "display_type.h" 20 #include "ibuffer.h" 21 #include <surface_buffer.h> 22 #include <memory> 23 24 namespace OHOS::Camera { 25 class BufferAdapter { 26 public: 27 // convert surfae buffer to camera ibuffer, only for external buffer. 28 static RetCode SurfaceBufferToCameraBuffer(const OHOS::sptr<OHOS::SurfaceBuffer>& surfaceBuffer, 29 const std::shared_ptr<IBuffer>& buffer); 30 31 // convert camera ibuffer to surface buffer, only for external buffer. 32 // It may lose information of surface buffer, call this function with caution. 33 static RetCode CameraBufferToSurfaceBuffer(const std::shared_ptr<IBuffer>& buffer, 34 const OHOS::sptr<OHOS::SurfaceBuffer>& surfaceBuffer); 35 static RetCode SetExtInfoToSurfaceBuffer(const std::shared_ptr<IBuffer>& buffer, 36 const OHOS::sptr<OHOS::SurfaceBuffer>& surfaceBuffer); 37 38 // convert camera format to pixel format. 39 static PixelFormat CameraFormatToPixelFormat(const uint32_t cameraFormat); 40 // convert pixel format to camera format. 41 static uint32_t PixelFormatToCameraFormat(const PixelFormat format); 42 43 // convert camera usage to gralloc usage. 44 static uint64_t CameraUsageToGrallocUsage(const uint64_t cameraUsage); 45 46 // convert gralloc usage to camera usage. 47 static uint64_t GrallocUsageToCameraUsage(const uint64_t usage); 48 }; 49 } // namespace OHOS::Camera 50 #endif 51