1 /* 2 * Copyright (C) 2017 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef ANDROID_PRIVATE_NATIVE_AHARDWARE_BUFFER_HELPERS_H 18 #define ANDROID_PRIVATE_NATIVE_AHARDWARE_BUFFER_HELPERS_H 19 20 /* 21 * This file contains utility functions related to AHardwareBuffer, mostly to 22 * convert to/from HAL formats. 23 * 24 * These are PRIVATE methods, so this file can NEVER appear in a public NDK 25 * header. They are used by higher level libraries such as core/jni. 26 */ 27 28 #include <stdint.h> 29 30 #include <vndk/hardware_buffer.h> 31 32 struct ANativeWindowBuffer; 33 34 namespace android { 35 36 // Validates whether the passed description does not have conflicting 37 // parameters. Note: this does not verify any platform-specific contraints. 38 bool AHardwareBuffer_isValidDescription(const AHardwareBuffer_Desc* desc, bool log); 39 40 // whether this is a YUV type format 41 bool AHardwareBuffer_formatIsYuv(uint32_t format); 42 43 // convert AHardwareBuffer format to HAL format (note: this is a no-op) 44 uint32_t AHardwareBuffer_convertFromPixelFormat(uint32_t format); 45 46 // convert HAL format to AHardwareBuffer format (note: this is a no-op) 47 uint32_t AHardwareBuffer_convertToPixelFormat(uint32_t format); 48 49 // convert AHardwareBuffer usage bits to HAL usage bits (note: this is a no-op) 50 uint64_t AHardwareBuffer_convertFromGrallocUsageBits(uint64_t usage); 51 52 // convert HAL usage bits to AHardwareBuffer usage bits (note: this is a no-op) 53 uint64_t AHardwareBuffer_convertToGrallocUsageBits(uint64_t usage); 54 55 class GraphicBuffer; 56 const GraphicBuffer* AHardwareBuffer_to_GraphicBuffer(const AHardwareBuffer* buffer); 57 GraphicBuffer* AHardwareBuffer_to_GraphicBuffer(AHardwareBuffer* buffer); 58 59 const ANativeWindowBuffer* AHardwareBuffer_to_ANativeWindowBuffer(const AHardwareBuffer* buffer); 60 ANativeWindowBuffer* AHardwareBuffer_to_ANativeWindowBuffer(AHardwareBuffer* buffer); 61 62 AHardwareBuffer* AHardwareBuffer_from_GraphicBuffer(GraphicBuffer* buffer); 63 } // namespace android 64 65 #endif // ANDROID_PRIVATE_NATIVE_AHARDWARE_BUFFER_HELPERS_H 66