1 /* 2 * Copyright 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_VNDK_NATIVEWINDOW_AHARDWAREBUFFER_H 18 #define ANDROID_VNDK_NATIVEWINDOW_AHARDWAREBUFFER_H 19 20 // vndk is a superset of the NDK 21 #include <android/hardware_buffer.h> 22 23 #include <cutils/native_handle.h> 24 25 __BEGIN_DECLS 26 27 /** 28 * Get the native handle from an AHardwareBuffer. 29 * 30 * \return a non-NULL native handle on success, NULL if \a buffer is nullptr or the operation fails 31 * for any reason. 32 */ 33 const native_handle_t* _Nullable AHardwareBuffer_getNativeHandle( 34 const AHardwareBuffer* _Nonnull buffer); 35 36 enum CreateFromHandleMethod { 37 // enum values chosen to match internal GraphicBuffer::HandleWrapMethod 38 AHARDWAREBUFFER_CREATE_FROM_HANDLE_METHOD_REGISTER = 2, 39 AHARDWAREBUFFER_CREATE_FROM_HANDLE_METHOD_CLONE = 3, 40 }; 41 42 /** 43 * Create an AHardwareBuffer from a native handle. 44 * 45 * This function wraps a native handle in an AHardwareBuffer suitable for use by applications or 46 * other parts of the system. The contents of desc will be returned by AHardwareBuffer_describe(). 47 * 48 * If method is AHARDWAREBUFFER_CREATE_FROM_HANDLE_METHOD_REGISTER, the handle is assumed to be 49 * unregistered, and it will be registered/imported before being wrapped in the AHardwareBuffer. 50 * If successful, the AHardwareBuffer will own the handle. 51 * 52 * If method is AHARDWAREBUFFER_CREATE_FROM_HANDLE_METHOD_CLONE, the handle will be cloned and the 53 * clone registered. The AHardwareBuffer will own the cloned handle but not the original. 54 * 55 * \return 0 on success, -EINVAL if \a desc or \a handle or outBuffer is NULL, or an error number if 56 * the operation fails for any reason. 57 */ 58 int AHardwareBuffer_createFromHandle(const AHardwareBuffer_Desc* _Nonnull desc, 59 const native_handle_t* _Nonnull handle, int32_t method, 60 AHardwareBuffer* _Nullable* _Nonnull outBuffer); 61 62 /** 63 * Buffer pixel formats. 64 */ 65 enum { 66 /* for future proofing, keep these in sync with system/graphics-base.h */ 67 68 /* same as HAL_PIXEL_FORMAT_BGRA_8888 */ 69 AHARDWAREBUFFER_FORMAT_B8G8R8A8_UNORM = 5, 70 /* same as HAL_PIXEL_FORMAT_YV12 */ 71 AHARDWAREBUFFER_FORMAT_YV12 = 0x32315659, 72 /* same as HAL_PIXEL_FORMAT_Y8 */ 73 AHARDWAREBUFFER_FORMAT_Y8 = 0x20203859, 74 /* same as HAL_PIXEL_FORMAT_Y16 */ 75 AHARDWAREBUFFER_FORMAT_Y16 = 0x20363159, 76 /* same as HAL_PIXEL_FORMAT_RAW16 */ 77 AHARDWAREBUFFER_FORMAT_RAW16 = 0x20, 78 /* same as HAL_PIXEL_FORMAT_RAW10 */ 79 AHARDWAREBUFFER_FORMAT_RAW10 = 0x25, 80 /* same as HAL_PIXEL_FORMAT_RAW12 */ 81 AHARDWAREBUFFER_FORMAT_RAW12 = 0x26, 82 /* same as HAL_PIXEL_FORMAT_RAW_OPAQUE */ 83 AHARDWAREBUFFER_FORMAT_RAW_OPAQUE = 0x24, 84 /* same as HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED */ 85 AHARDWAREBUFFER_FORMAT_IMPLEMENTATION_DEFINED = 0x22, 86 /* same as HAL_PIXEL_FORMAT_YCBCR_422_SP */ 87 AHARDWAREBUFFER_FORMAT_YCbCr_422_SP = 0x10, 88 /* same as HAL_PIXEL_FORMAT_YCRCB_420_SP */ 89 AHARDWAREBUFFER_FORMAT_YCrCb_420_SP = 0x11, 90 /* same as HAL_PIXEL_FORMAT_YCBCR_422_I */ 91 AHARDWAREBUFFER_FORMAT_YCbCr_422_I = 0x14, 92 }; 93 94 /** 95 * Buffer usage flags. 96 */ 97 enum { 98 /* for future proofing, keep these in sync with hardware/gralloc.h */ 99 100 /* The buffer will be written by the HW camera pipeline. */ 101 AHARDWAREBUFFER_USAGE_CAMERA_WRITE = 2UL << 16, 102 /* The buffer will be read by the HW camera pipeline. */ 103 AHARDWAREBUFFER_USAGE_CAMERA_READ = 4UL << 16, 104 /* Mask for the camera access values. */ 105 AHARDWAREBUFFER_USAGE_CAMERA_MASK = 6UL << 16, 106 }; 107 108 __END_DECLS 109 110 #endif /* ANDROID_VNDK_NATIVEWINDOW_AHARDWAREBUFFER_H */ 111