• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef BASE_ANDROID_ANDROID_HARDWARE_BUFFER_ABI_H_
6 #define BASE_ANDROID_ANDROID_HARDWARE_BUFFER_ABI_H_
7 
8 // Minimal binary interface definitions for AHardwareBuffer based on
9 // include/android/hardware_buffer.h from the Android NDK for platform level
10 // 26+. This is only intended for use from the AndroidHardwareBufferCompat
11 // wrapper for building without NDK platform level support, it is not a
12 // general-use header and is not complete.
13 //
14 // TODO(crbug.com/771171): Delete this file when third_party/android_ndk/
15 // is updated to a version that contains the android/hardware_buffer.h file.
16 //
17 // Please refer to the API documentation for details:
18 // https://developer.android.com/ndk/reference/hardware__buffer_8h.html
19 
20 #include <stdint.h>
21 
22 // Use "C" linkage to match the original header file. This isn't strictly
23 // required since the file is not declaring global functions, but the types
24 // should remain in the global namespace for compatibility, and it's a reminder
25 // that forward declarations elsewhere should use "extern "C" to avoid
26 // namespace issues.
27 extern "C" {
28 
29 typedef struct AHardwareBuffer AHardwareBuffer;
30 typedef struct ARect ARect;
31 
32 enum {
33   AHARDWAREBUFFER_FORMAT_R8G8B8A8_UNORM = 1,
34   AHARDWAREBUFFER_FORMAT_R8G8B8X8_UNORM = 2,
35   AHARDWAREBUFFER_FORMAT_R8G8B8_UNORM = 3,
36   AHARDWAREBUFFER_FORMAT_R5G6B5_UNORM = 4,
37   AHARDWAREBUFFER_FORMAT_R16G16B16A16_FLOAT = 0x16,
38   AHARDWAREBUFFER_FORMAT_R10G10B10A2_UNORM = 0x2b,
39   AHARDWAREBUFFER_FORMAT_BLOB = 0x21,
40 };
41 
42 enum {
43   AHARDWAREBUFFER_USAGE_CPU_READ_NEVER = 0UL,
44   AHARDWAREBUFFER_USAGE_CPU_READ_RARELY = 2UL,
45   AHARDWAREBUFFER_USAGE_CPU_READ_OFTEN = 3UL,
46   AHARDWAREBUFFER_USAGE_CPU_READ_MASK = 0xFUL,
47   AHARDWAREBUFFER_USAGE_CPU_WRITE_NEVER = 0UL << 4,
48   AHARDWAREBUFFER_USAGE_CPU_WRITE_RARELY = 2UL << 4,
49   AHARDWAREBUFFER_USAGE_CPU_WRITE_OFTEN = 3UL << 4,
50   AHARDWAREBUFFER_USAGE_CPU_WRITE_MASK = 0xFUL << 4,
51   AHARDWAREBUFFER_USAGE_GPU_SAMPLED_IMAGE = 1UL << 8,
52   AHARDWAREBUFFER_USAGE_GPU_COLOR_OUTPUT = 1UL << 9,
53   AHARDWAREBUFFER_USAGE_PROTECTED_CONTENT = 1UL << 14,
54   AHARDWAREBUFFER_USAGE_VIDEO_ENCODE = 1UL << 16,
55   AHARDWAREBUFFER_USAGE_SENSOR_DIRECT_DATA = 1UL << 23,
56   AHARDWAREBUFFER_USAGE_GPU_DATA_BUFFER = 1UL << 24,
57 };
58 
59 typedef struct AHardwareBuffer_Desc {
60   uint32_t width;
61   uint32_t height;
62   uint32_t layers;
63   uint32_t format;
64   uint64_t usage;
65   uint32_t stride;
66   uint32_t rfu0;
67   uint64_t rfu1;
68 } AHardwareBuffer_Desc;
69 
70 using PFAHardwareBuffer_allocate = void (*)(const AHardwareBuffer_Desc* desc,
71                                             AHardwareBuffer** outBuffer);
72 using PFAHardwareBuffer_acquire = void (*)(AHardwareBuffer* buffer);
73 using PFAHardwareBuffer_describe = void (*)(const AHardwareBuffer* buffer,
74                                             AHardwareBuffer_Desc* outDesc);
75 using PFAHardwareBuffer_lock = int (*)(AHardwareBuffer* buffer,
76                                        uint64_t usage,
77                                        int32_t fence,
78                                        const ARect* rect,
79                                        void** outVirtualAddress);
80 using PFAHardwareBuffer_recvHandleFromUnixSocket =
81     int (*)(int socketFd, AHardwareBuffer** outBuffer);
82 using PFAHardwareBuffer_release = void (*)(AHardwareBuffer* buffer);
83 using PFAHardwareBuffer_sendHandleToUnixSocket =
84     int (*)(const AHardwareBuffer* buffer, int socketFd);
85 using PFAHardwareBuffer_unlock = int (*)(AHardwareBuffer* buffer,
86                                          int32_t* fence);
87 
88 }  // extern "C"
89 
90 #endif  // BASE_ANDROID_ANDROID_HARDWARE_BUFFER_ABI_H_
91