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