12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- // Copyright 2017 The Chromium Authors. All rights reserved.
- // Use of this source code is governed by a BSD-style license that can be
- // found in the LICENSE file.
- #ifndef BASE_ANDROID_ANDROID_HARDWARE_BUFFER_COMPAT_H_
- #define BASE_ANDROID_ANDROID_HARDWARE_BUFFER_COMPAT_H_
- #include <android/hardware_buffer.h>
- #include <android/sensor.h>
- #include "base/base_export.h"
- #include "base/macros.h"
- #include "base/no_destructor.h"
- extern "C" {
- using PFAHardwareBuffer_allocate = void (*)(const AHardwareBuffer_Desc* desc,
- AHardwareBuffer** outBuffer);
- using PFAHardwareBuffer_acquire = void (*)(AHardwareBuffer* buffer);
- using PFAHardwareBuffer_describe = void (*)(const AHardwareBuffer* buffer,
- AHardwareBuffer_Desc* outDesc);
- using PFAHardwareBuffer_lock = int (*)(AHardwareBuffer* buffer,
- uint64_t usage,
- int32_t fence,
- const ARect* rect,
- void** outVirtualAddress);
- using PFAHardwareBuffer_recvHandleFromUnixSocket =
- int (*)(int socketFd, AHardwareBuffer** outBuffer);
- using PFAHardwareBuffer_release = void (*)(AHardwareBuffer* buffer);
- using PFAHardwareBuffer_sendHandleToUnixSocket =
- int (*)(const AHardwareBuffer* buffer, int socketFd);
- using PFAHardwareBuffer_unlock = int (*)(AHardwareBuffer* buffer,
- int32_t* fence);
- }
- namespace base {
- // This class provides runtime support for working with AHardwareBuffer objects
- // on Android O systems without requiring building for the Android O NDK level.
- // Don't call GetInstance() unless IsSupportAvailable() returns true.
- class BASE_EXPORT AndroidHardwareBufferCompat {
- public:
- static bool IsSupportAvailable();
- static AndroidHardwareBufferCompat& GetInstance();
- void Allocate(const AHardwareBuffer_Desc* desc, AHardwareBuffer** outBuffer);
- void Acquire(AHardwareBuffer* buffer);
- void Describe(const AHardwareBuffer* buffer, AHardwareBuffer_Desc* outDesc);
- int Lock(AHardwareBuffer* buffer,
- uint64_t usage,
- int32_t fence,
- const ARect* rect,
- void** out_virtual_address);
- int RecvHandleFromUnixSocket(int socketFd, AHardwareBuffer** outBuffer);
- void Release(AHardwareBuffer* buffer);
- int SendHandleToUnixSocket(const AHardwareBuffer* buffer, int socketFd);
- int Unlock(AHardwareBuffer* buffer, int32_t* fence);
- private:
- friend class NoDestructor<AndroidHardwareBufferCompat>;
- AndroidHardwareBufferCompat();
- PFAHardwareBuffer_allocate allocate_;
- PFAHardwareBuffer_acquire acquire_;
- PFAHardwareBuffer_describe describe_;
- PFAHardwareBuffer_lock lock_;
- PFAHardwareBuffer_recvHandleFromUnixSocket recv_handle_;
- PFAHardwareBuffer_release release_;
- PFAHardwareBuffer_sendHandleToUnixSocket send_handle_;
- PFAHardwareBuffer_unlock unlock_;
- DISALLOW_COPY_AND_ASSIGN(AndroidHardwareBufferCompat);
- };
- } // namespace base
- #endif // BASE_ANDROID_ANDROID_HARDWARE_BUFFER_COMPAT_H_
|