1 // Copyright 2017 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef BASE_ANDROID_ANDROID_HARDWARE_BUFFER_COMPAT_H_
6 #define BASE_ANDROID_ANDROID_HARDWARE_BUFFER_COMPAT_H_
8 #include <android/hardware_buffer.h>
9 #include <android/sensor.h>
11 #include "base/base_export.h"
12 #include "base/no_destructor.h"
15 using PFAHardwareBuffer_allocate = void (*)(const AHardwareBuffer_Desc* desc,
16 AHardwareBuffer** outBuffer);
17 using PFAHardwareBuffer_acquire = void (*)(AHardwareBuffer* buffer);
18 using PFAHardwareBuffer_describe = void (*)(const AHardwareBuffer* buffer,
19 AHardwareBuffer_Desc* outDesc);
20 using PFAHardwareBuffer_lock = int (*)(AHardwareBuffer* buffer,
24 void** outVirtualAddress);
25 using PFAHardwareBuffer_recvHandleFromUnixSocket =
26 int (*)(int socketFd, AHardwareBuffer** outBuffer);
27 using PFAHardwareBuffer_release = void (*)(AHardwareBuffer* buffer);
28 using PFAHardwareBuffer_sendHandleToUnixSocket =
29 int (*)(const AHardwareBuffer* buffer, int socketFd);
30 using PFAHardwareBuffer_unlock = int (*)(AHardwareBuffer* buffer,
36 // This class provides runtime support for working with AHardwareBuffer objects
37 // on Android O systems without requiring building for the Android O NDK level.
38 // Don't call GetInstance() unless IsSupportAvailable() returns true.
39 class BASE_EXPORT AndroidHardwareBufferCompat {
41 static bool IsSupportAvailable();
42 static AndroidHardwareBufferCompat& GetInstance();
44 AndroidHardwareBufferCompat(const AndroidHardwareBufferCompat&) = delete;
45 AndroidHardwareBufferCompat& operator=(const AndroidHardwareBufferCompat&) =
48 void Allocate(const AHardwareBuffer_Desc* desc, AHardwareBuffer** outBuffer);
49 void Acquire(AHardwareBuffer* buffer);
50 void Describe(const AHardwareBuffer* buffer, AHardwareBuffer_Desc* outDesc);
51 int Lock(AHardwareBuffer* buffer,
55 void** out_virtual_address);
56 int RecvHandleFromUnixSocket(int socketFd, AHardwareBuffer** outBuffer);
57 void Release(AHardwareBuffer* buffer);
58 int SendHandleToUnixSocket(const AHardwareBuffer* buffer, int socketFd);
59 int Unlock(AHardwareBuffer* buffer, int32_t* fence);
62 friend class NoDestructor<AndroidHardwareBufferCompat>;
63 AndroidHardwareBufferCompat();
65 PFAHardwareBuffer_allocate allocate_;
66 PFAHardwareBuffer_acquire acquire_;
67 PFAHardwareBuffer_describe describe_;
68 PFAHardwareBuffer_lock lock_;
69 PFAHardwareBuffer_recvHandleFromUnixSocket recv_handle_;
70 PFAHardwareBuffer_release release_;
71 PFAHardwareBuffer_sendHandleToUnixSocket send_handle_;
72 PFAHardwareBuffer_unlock unlock_;
77 #endif // BASE_ANDROID_ANDROID_HARDWARE_BUFFER_COMPAT_H_