• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 const native_handle_t* AHardwareBuffer_getNativeHandle(const AHardwareBuffer* buffer);
28 
29 enum CreateFromHandleMethod {
30     // enum values chosen to match internal GraphicBuffer::HandleWrapMethod
31     AHARDWAREBUFFER_CREATE_FROM_HANDLE_METHOD_REGISTER = 2,
32     AHARDWAREBUFFER_CREATE_FROM_HANDLE_METHOD_CLONE = 3,
33 };
34 
35 /**
36  * Create a AHardwareBuffer from a native handle.
37  *
38  * This function wraps a native handle in a AHardwareBuffer suitable for use by applications or
39  * other parts of the system. The contents of desc will be returned by AHardwareBuffer_describe().
40  *
41  * If method is AHARDWAREBUFFER_CREATE_FROM_HANDLE_METHOD_REGISTER, the handle is assumed to be
42  * unregistered, and it will be registered/imported before being wrapped in the AHardwareBuffer.
43  * If successful, the AHardwareBuffer will own the handle.
44  *
45  * If method is AHARDWAREBUFFER_CREATE_FROM_HANDLE_METHOD_CLONE, the handle will be cloned and the
46  * clone registered. The AHardwareBuffer will own the cloned handle but not the original.
47  */
48 int AHardwareBuffer_createFromHandle(const AHardwareBuffer_Desc* desc,
49                                      const native_handle_t* handle, int32_t method,
50                                      AHardwareBuffer** outBuffer);
51 
52 /**
53  * Buffer pixel formats.
54  */
55 enum {
56     /* for future proofing, keep these in sync with system/graphics-base.h */
57 
58     /* same as HAL_PIXEL_FORMAT_BGRA_8888 */
59     AHARDWAREBUFFER_FORMAT_B8G8R8A8_UNORM           = 5,
60     /* same as HAL_PIXEL_FORMAT_YV12 */
61     AHARDWAREBUFFER_FORMAT_YV12                     = 0x32315659,
62     /* same as HAL_PIXEL_FORMAT_Y8 */
63     AHARDWAREBUFFER_FORMAT_Y8                       = 0x20203859,
64     /* same as HAL_PIXEL_FORMAT_Y16 */
65     AHARDWAREBUFFER_FORMAT_Y16                      = 0x20363159,
66     /* same as HAL_PIXEL_FORMAT_RAW16 */
67     AHARDWAREBUFFER_FORMAT_RAW16                    = 0x20,
68     /* same as HAL_PIXEL_FORMAT_RAW10 */
69     AHARDWAREBUFFER_FORMAT_RAW10                    = 0x25,
70     /* same as HAL_PIXEL_FORMAT_RAW12 */
71     AHARDWAREBUFFER_FORMAT_RAW12                    = 0x26,
72     /* same as HAL_PIXEL_FORMAT_RAW_OPAQUE */
73     AHARDWAREBUFFER_FORMAT_RAW_OPAQUE               = 0x24,
74     /* same as HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED */
75     AHARDWAREBUFFER_FORMAT_IMPLEMENTATION_DEFINED   = 0x22,
76     /* same as HAL_PIXEL_FORMAT_YCBCR_422_SP */
77     AHARDWAREBUFFER_FORMAT_YCbCr_422_SP             = 0x10,
78     /* same as HAL_PIXEL_FORMAT_YCRCB_420_SP */
79     AHARDWAREBUFFER_FORMAT_YCrCb_420_SP             = 0x11,
80     /* same as HAL_PIXEL_FORMAT_YCBCR_422_I */
81     AHARDWAREBUFFER_FORMAT_YCbCr_422_I              = 0x14,
82 };
83 
84 __END_DECLS
85 
86 #endif /* ANDROID_VNDK_NATIVEWINDOW_AHARDWAREBUFFER_H */
87