android_hardware_buffer_compat.h 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. #ifndef BASE_ANDROID_ANDROID_HARDWARE_BUFFER_COMPAT_H_
  5. #define BASE_ANDROID_ANDROID_HARDWARE_BUFFER_COMPAT_H_
  6. #include <android/hardware_buffer.h>
  7. #include <android/sensor.h>
  8. #include "base/base_export.h"
  9. #include "base/macros.h"
  10. #include "base/no_destructor.h"
  11. extern "C" {
  12. using PFAHardwareBuffer_allocate = void (*)(const AHardwareBuffer_Desc* desc,
  13. AHardwareBuffer** outBuffer);
  14. using PFAHardwareBuffer_acquire = void (*)(AHardwareBuffer* buffer);
  15. using PFAHardwareBuffer_describe = void (*)(const AHardwareBuffer* buffer,
  16. AHardwareBuffer_Desc* outDesc);
  17. using PFAHardwareBuffer_lock = int (*)(AHardwareBuffer* buffer,
  18. uint64_t usage,
  19. int32_t fence,
  20. const ARect* rect,
  21. void** outVirtualAddress);
  22. using PFAHardwareBuffer_recvHandleFromUnixSocket =
  23. int (*)(int socketFd, AHardwareBuffer** outBuffer);
  24. using PFAHardwareBuffer_release = void (*)(AHardwareBuffer* buffer);
  25. using PFAHardwareBuffer_sendHandleToUnixSocket =
  26. int (*)(const AHardwareBuffer* buffer, int socketFd);
  27. using PFAHardwareBuffer_unlock = int (*)(AHardwareBuffer* buffer,
  28. int32_t* fence);
  29. }
  30. namespace base {
  31. // This class provides runtime support for working with AHardwareBuffer objects
  32. // on Android O systems without requiring building for the Android O NDK level.
  33. // Don't call GetInstance() unless IsSupportAvailable() returns true.
  34. class BASE_EXPORT AndroidHardwareBufferCompat {
  35. public:
  36. static bool IsSupportAvailable();
  37. static AndroidHardwareBufferCompat& GetInstance();
  38. void Allocate(const AHardwareBuffer_Desc* desc, AHardwareBuffer** outBuffer);
  39. void Acquire(AHardwareBuffer* buffer);
  40. void Describe(const AHardwareBuffer* buffer, AHardwareBuffer_Desc* outDesc);
  41. int Lock(AHardwareBuffer* buffer,
  42. uint64_t usage,
  43. int32_t fence,
  44. const ARect* rect,
  45. void** out_virtual_address);
  46. int RecvHandleFromUnixSocket(int socketFd, AHardwareBuffer** outBuffer);
  47. void Release(AHardwareBuffer* buffer);
  48. int SendHandleToUnixSocket(const AHardwareBuffer* buffer, int socketFd);
  49. int Unlock(AHardwareBuffer* buffer, int32_t* fence);
  50. private:
  51. friend class NoDestructor<AndroidHardwareBufferCompat>;
  52. AndroidHardwareBufferCompat();
  53. PFAHardwareBuffer_allocate allocate_;
  54. PFAHardwareBuffer_acquire acquire_;
  55. PFAHardwareBuffer_describe describe_;
  56. PFAHardwareBuffer_lock lock_;
  57. PFAHardwareBuffer_recvHandleFromUnixSocket recv_handle_;
  58. PFAHardwareBuffer_release release_;
  59. PFAHardwareBuffer_sendHandleToUnixSocket send_handle_;
  60. PFAHardwareBuffer_unlock unlock_;
  61. DISALLOW_COPY_AND_ASSIGN(AndroidHardwareBufferCompat);
  62. };
  63. } // namespace base
  64. #endif // BASE_ANDROID_ANDROID_HARDWARE_BUFFER_COMPAT_H_