PageRenderTime 56ms CodeModel.GetById 31ms RepoModel.GetById 1ms app.codeStats 0ms

/libs/nativewindow/include/android/hardware_buffer.h

https://gitlab.com/drgroovestarr/frameworks_native
C Header | 246 lines | 75 code | 28 blank | 143 comment | 0 complexity | 6e1b175b9f107cfc86676e99af0186ad MD5 | raw file
  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. * @file hardware_buffer.h
  18. */
  19. #ifndef ANDROID_HARDWARE_BUFFER_H
  20. #define ANDROID_HARDWARE_BUFFER_H
  21. #include <inttypes.h>
  22. #include <sys/cdefs.h>
  23. #include <android/rect.h>
  24. __BEGIN_DECLS
  25. /**
  26. * Buffer pixel formats.
  27. */
  28. enum {
  29. /**
  30. * Corresponding formats:
  31. * Vulkan: VK_FORMAT_R8G8B8A8_UNORM
  32. * OpenGL ES: GL_RGBA8
  33. */
  34. AHARDWAREBUFFER_FORMAT_R8G8B8A8_UNORM = 1,
  35. /**
  36. * Corresponding formats:
  37. * Vulkan: VK_FORMAT_R8G8B8A8_UNORM
  38. * OpenGL ES: GL_RGBA8
  39. */
  40. AHARDWAREBUFFER_FORMAT_R8G8B8X8_UNORM = 2,
  41. /**
  42. * Corresponding formats:
  43. * Vulkan: VK_FORMAT_R8G8B8_UNORM
  44. * OpenGL ES: GL_RGB8
  45. */
  46. AHARDWAREBUFFER_FORMAT_R8G8B8_UNORM = 3,
  47. /**
  48. * Corresponding formats:
  49. * Vulkan: VK_FORMAT_R5G6B5_UNORM_PACK16
  50. * OpenGL ES: GL_RGB565
  51. */
  52. AHARDWAREBUFFER_FORMAT_R5G6B5_UNORM = 4,
  53. /**
  54. * Corresponding formats:
  55. * Vulkan: VK_FORMAT_R16G16B16A16_SFLOAT
  56. * OpenGL ES: GL_RGBA16F
  57. */
  58. AHARDWAREBUFFER_FORMAT_R16G16B16A16_FLOAT = 0x16,
  59. /**
  60. * Corresponding formats:
  61. * Vulkan: VK_FORMAT_A2B10G10R10_UNORM_PACK32
  62. * OpenGL ES: GL_RGB10_A2
  63. */
  64. AHARDWAREBUFFER_FORMAT_R10G10B10A2_UNORM = 0x2b,
  65. /**
  66. * An opaque binary blob format that must have height 1, with width equal to
  67. * the buffer size in bytes.
  68. */
  69. AHARDWAREBUFFER_FORMAT_BLOB = 0x21,
  70. };
  71. enum {
  72. /* The buffer will never be read by the CPU */
  73. AHARDWAREBUFFER_USAGE_CPU_READ_NEVER = 0UL,
  74. /* The buffer will sometimes be read by the CPU */
  75. AHARDWAREBUFFER_USAGE_CPU_READ_RARELY = 2UL,
  76. /* The buffer will often be read by the CPU */
  77. AHARDWAREBUFFER_USAGE_CPU_READ_OFTEN = 3UL,
  78. /* CPU read value mask */
  79. AHARDWAREBUFFER_USAGE_CPU_READ_MASK = 0xFUL,
  80. /* The buffer will never be written by the CPU */
  81. AHARDWAREBUFFER_USAGE_CPU_WRITE_NEVER = 0UL << 4,
  82. /* The buffer will sometimes be written to by the CPU */
  83. AHARDWAREBUFFER_USAGE_CPU_WRITE_RARELY = 2UL << 4,
  84. /* The buffer will often be written to by the CPU */
  85. AHARDWAREBUFFER_USAGE_CPU_WRITE_OFTEN = 3UL << 4,
  86. /* CPU write value mask */
  87. AHARDWAREBUFFER_USAGE_CPU_WRITE_MASK = 0xFUL << 4,
  88. /* The buffer will be read from by the GPU */
  89. AHARDWAREBUFFER_USAGE_GPU_SAMPLED_IMAGE = 1UL << 8,
  90. /* The buffer will be written to by the GPU */
  91. AHARDWAREBUFFER_USAGE_GPU_COLOR_OUTPUT = 1UL << 9,
  92. /* The buffer must not be used outside of a protected hardware path */
  93. AHARDWAREBUFFER_USAGE_PROTECTED_CONTENT = 1UL << 14,
  94. /* The buffer will be read by a hardware video encoder */
  95. AHARDWAREBUFFER_USAGE_VIDEO_ENCODE = 1UL << 16,
  96. /** The buffer will be used for sensor direct data */
  97. AHARDWAREBUFFER_USAGE_SENSOR_DIRECT_DATA = 1UL << 23,
  98. /* The buffer will be used as a shader storage or uniform buffer object*/
  99. AHARDWAREBUFFER_USAGE_GPU_DATA_BUFFER = 1UL << 24,
  100. AHARDWAREBUFFER_USAGE_VENDOR_0 = 1ULL << 28,
  101. AHARDWAREBUFFER_USAGE_VENDOR_1 = 1ULL << 29,
  102. AHARDWAREBUFFER_USAGE_VENDOR_2 = 1ULL << 30,
  103. AHARDWAREBUFFER_USAGE_VENDOR_3 = 1ULL << 31,
  104. AHARDWAREBUFFER_USAGE_VENDOR_4 = 1ULL << 48,
  105. AHARDWAREBUFFER_USAGE_VENDOR_5 = 1ULL << 49,
  106. AHARDWAREBUFFER_USAGE_VENDOR_6 = 1ULL << 50,
  107. AHARDWAREBUFFER_USAGE_VENDOR_7 = 1ULL << 51,
  108. AHARDWAREBUFFER_USAGE_VENDOR_8 = 1ULL << 52,
  109. AHARDWAREBUFFER_USAGE_VENDOR_9 = 1ULL << 53,
  110. AHARDWAREBUFFER_USAGE_VENDOR_10 = 1ULL << 54,
  111. AHARDWAREBUFFER_USAGE_VENDOR_11 = 1ULL << 55,
  112. AHARDWAREBUFFER_USAGE_VENDOR_12 = 1ULL << 56,
  113. AHARDWAREBUFFER_USAGE_VENDOR_13 = 1ULL << 57,
  114. AHARDWAREBUFFER_USAGE_VENDOR_14 = 1ULL << 58,
  115. AHARDWAREBUFFER_USAGE_VENDOR_15 = 1ULL << 59,
  116. AHARDWAREBUFFER_USAGE_VENDOR_16 = 1ULL << 60,
  117. AHARDWAREBUFFER_USAGE_VENDOR_17 = 1ULL << 61,
  118. AHARDWAREBUFFER_USAGE_VENDOR_18 = 1ULL << 62,
  119. AHARDWAREBUFFER_USAGE_VENDOR_19 = 1ULL << 63,
  120. };
  121. typedef struct AHardwareBuffer_Desc {
  122. uint32_t width; // width in pixels
  123. uint32_t height; // height in pixels
  124. uint32_t layers; // number of images
  125. uint32_t format; // One of AHARDWAREBUFFER_FORMAT_*
  126. uint64_t usage; // Combination of AHARDWAREBUFFER_USAGE_*
  127. uint32_t stride; // Stride in pixels, ignored for AHardwareBuffer_allocate()
  128. uint32_t rfu0; // Initialize to zero, reserved for future use
  129. uint64_t rfu1; // Initialize to zero, reserved for future use
  130. } AHardwareBuffer_Desc;
  131. typedef struct AHardwareBuffer AHardwareBuffer;
  132. /**
  133. * Allocates a buffer that backs an AHardwareBuffer using the passed
  134. * AHardwareBuffer_Desc.
  135. *
  136. * Returns NO_ERROR on success, or an error number of the allocation fails for
  137. * any reason.
  138. */
  139. int AHardwareBuffer_allocate(const AHardwareBuffer_Desc* desc,
  140. AHardwareBuffer** outBuffer);
  141. /**
  142. * Acquire a reference on the given AHardwareBuffer object. This prevents the
  143. * object from being deleted until the last reference is removed.
  144. */
  145. void AHardwareBuffer_acquire(AHardwareBuffer* buffer);
  146. /**
  147. * Remove a reference that was previously acquired with
  148. * AHardwareBuffer_acquire().
  149. */
  150. void AHardwareBuffer_release(AHardwareBuffer* buffer);
  151. /**
  152. * Return a description of the AHardwareBuffer in the passed
  153. * AHardwareBuffer_Desc struct.
  154. */
  155. void AHardwareBuffer_describe(const AHardwareBuffer* buffer,
  156. AHardwareBuffer_Desc* outDesc);
  157. /*
  158. * Lock the AHardwareBuffer for reading or writing, depending on the usage flags
  159. * passed. This call may block if the hardware needs to finish rendering or if
  160. * CPU caches need to be synchronized, or possibly for other implementation-
  161. * specific reasons. If fence is not negative, then it specifies a fence file
  162. * descriptor that will be signaled when the buffer is locked, otherwise the
  163. * caller will block until the buffer is available.
  164. *
  165. * If rect is not NULL, the caller promises to modify only data in the area
  166. * specified by rect. If rect is NULL, the caller may modify the contents of the
  167. * entire buffer.
  168. *
  169. * The content of the buffer outside of the specified rect is NOT modified
  170. * by this call.
  171. *
  172. * The buffer usage may only specify AHARDWAREBUFFER_USAGE_CPU_*. If set, then
  173. * outVirtualAddress is filled with the address of the buffer in virtual memory,
  174. * otherwise this function will fail.
  175. *
  176. * THREADING CONSIDERATIONS:
  177. *
  178. * It is legal for several different threads to lock a buffer for read access;
  179. * none of the threads are blocked.
  180. *
  181. * Locking a buffer simultaneously for write or read/write is undefined, but
  182. * will neither terminate the process nor block the caller; AHardwareBuffer_lock
  183. * may return an error or leave the buffer's content into an indeterminate
  184. * state.
  185. *
  186. * Returns NO_ERROR on success, BAD_VALUE if the buffer is NULL or if the usage
  187. * flags are not a combination of AHARDWAREBUFFER_USAGE_CPU_*, or an error
  188. * number of the lock fails for any reason.
  189. */
  190. int AHardwareBuffer_lock(AHardwareBuffer* buffer, uint64_t usage,
  191. int32_t fence, const ARect* rect, void** outVirtualAddress);
  192. /*
  193. * Unlock the AHardwareBuffer; must be called after all changes to the buffer
  194. * are completed by the caller. If fence is not NULL then it will be set to a
  195. * file descriptor that is signaled when all pending work on the buffer is
  196. * completed. The caller is responsible for closing the fence when it is no
  197. * longer needed.
  198. *
  199. * Returns NO_ERROR on success, BAD_VALUE if the buffer is NULL, or an error
  200. * number of the lock fails for any reason.
  201. */
  202. int AHardwareBuffer_unlock(AHardwareBuffer* buffer, int32_t* fence);
  203. /*
  204. * Send the AHardwareBuffer to an AF_UNIX socket.
  205. *
  206. * Returns NO_ERROR on success, BAD_VALUE if the buffer is NULL, or an error
  207. * number of the lock fails for any reason.
  208. */
  209. int AHardwareBuffer_sendHandleToUnixSocket(const AHardwareBuffer* buffer, int socketFd);
  210. /*
  211. * Receive the AHardwareBuffer from an AF_UNIX socket.
  212. *
  213. * Returns NO_ERROR on success, BAD_VALUE if the buffer is NULL, or an error
  214. * number of the lock fails for any reason.
  215. */
  216. int AHardwareBuffer_recvHandleFromUnixSocket(int socketFd, AHardwareBuffer** outBuffer);
  217. __END_DECLS
  218. #endif // ANDROID_HARDWARE_BUFFER_H