| Flutter Impeller |

Classes | Public Member Functions | Static Public Member Functions | List of all members
impeller::android::HardwareBuffer Class Reference

A wrapper for AHardwareBuffer https://developer.android.com/ndk/reference/group/a-hardware-buffer. More...

`#include <hardware_buffer.h>`

## Public Member Functions
| HardwareBuffer (HardwareBufferDescriptor descriptor)
| ~HardwareBuffer ()
| HardwareBuffer (const HardwareBuffer &)=delete
HardwareBuffer & | operator= (const HardwareBuffer &)=delete
bool | IsValid () const
AHardwareBuffer * | GetHandle () const
const HardwareBufferDescriptor & | GetDescriptor () const
const AHardwareBuffer_Desc & | GetAndroidDescriptor () const
std::optional< uint64_t > | GetSystemUniqueID () const
| Get the system wide unique ID of the hardware buffer if possible. This is only available on Android API 31 and above. Within the process, the handle are unique. More...

## Static Public Member Functions
static bool | IsAvailableOnPlatform ()
static std::optional< AHardwareBuffer_Desc > | Describe (AHardwareBuffer *buffer)
static std::optional< uint64_t > | GetSystemUniqueID (AHardwareBuffer *buffer)
| Get the system wide unique ID of the hardware buffer if possible. This is only available on Android API 31 and above. Within the process, the handle are unique. More...

## Detailed Description

A wrapper for AHardwareBuffer https://developer.android.com/ndk/reference/group/a-hardware-buffer.

This wrapper creates and owns a handle to a managed hardware buffer. That is, there is no ability to take a reference to an externally created hardware buffer.

This wrapper is only available on Android API 29 and above.

Definition at line 88 of file hardware_buffer.h.

## Constructor & Destructor Documentation

## ◆ HardwareBuffer() [1/2]

impeller::android::HardwareBuffer::HardwareBuffer | ( | HardwareBufferDescriptor | descriptor | ) |
| explicit

Definition at line 47 of file hardware_buffer.cc.

48 : descriptor_(descriptor),
49 android_descriptor_(ToAHardwareBufferDesc(descriptor_)) {
50 if (!descriptor_.IsAllocatable()) {
51 VALIDATION_LOG << "The hardware buffer descriptor is not allocatable.";
52 return;
53 }
54 const auto& proc_table = GetProcTable();
55
56 AHardwareBuffer* buffer = nullptr;
57 if (auto result =
58 proc_table.AHardwareBuffer_allocate(&android_descriptor_, &buffer);
59 result != 0 || buffer == nullptr) {
60 VALIDATION_LOG << "Could not allocate hardware buffer. Error: " << result;
61 return;
62 }
63 buffer_.reset(buffer);
64 is_valid_ = true;
65 }

References impeller::android::GetProcTable(), impeller::android::HardwareBufferDescriptor::IsAllocatable(), and VALIDATION_LOG.

## ◆ ~HardwareBuffer()

impeller::android::HardwareBuffer::~HardwareBuffer | ( |  | ) |
| default

## ◆ HardwareBuffer() [2/2]

impeller::android::HardwareBuffer::HardwareBuffer | ( | const HardwareBuffer & |  | ) |
| delete

## Member Function Documentation

## ◆ Describe()

std::optional< AHardwareBuffer_Desc > impeller::android::HardwareBuffer::Describe | ( | AHardwareBuffer * | buffer | ) |
| static

Definition at line 120 of file hardware_buffer.cc.

121 {
122 if (!buffer || !GetProcTable().AHardwareBuffer_describe) {
123 return std::nullopt;
124 }
125 AHardwareBuffer_Desc desc = {};
126 GetProcTable().AHardwareBuffer_describe(buffer, &desc);
127 return desc;
128 }

References impeller::android::GetProcTable().

Referenced by impeller::android::testing::TEST().

## ◆ GetAndroidDescriptor()

const AHardwareBuffer_Desc & impeller::android::HardwareBuffer::GetAndroidDescriptor | ( |  | ) | const

Definition at line 96 of file hardware_buffer.cc.

96 {
97 return android_descriptor_;
98 }

## ◆ GetDescriptor()

const HardwareBufferDescriptor & impeller::android::HardwareBuffer::GetDescriptor | ( |  | ) | const

Definition at line 92 of file hardware_buffer.cc.

92 {
93 return descriptor_;
94 }

## ◆ GetHandle()

AHardwareBuffer * impeller::android::HardwareBuffer::GetHandle | ( |  | ) | const

Definition at line 73 of file hardware_buffer.cc.

73 {
74 return buffer_.get();
75 }

Referenced by GetSystemUniqueID(), impeller::android::SurfaceTransaction::SetContents(), and impeller::android::testing::TEST().

## ◆ GetSystemUniqueID() [1/2]

std::optional< uint64_t > impeller::android::HardwareBuffer::GetSystemUniqueID | ( |  | ) | const

Get the system wide unique ID of the hardware buffer if possible. This is only available on Android API 31 and above. Within the process, the handle are unique.

Returns
  The system unique id if one can be obtained.

Definition at line 104 of file hardware_buffer.cc.

104 {
105 return GetSystemUniqueID(GetHandle());
106 }

References GetHandle().

Referenced by impeller::android::testing::TEST().

## ◆ GetSystemUniqueID() [2/2]

std::optional< uint64_t > impeller::android::HardwareBuffer::GetSystemUniqueID | ( | AHardwareBuffer * | buffer | ) |
| static

Get the system wide unique ID of the hardware buffer if possible. This is only available on Android API 31 and above. Within the process, the handle are unique.

Returns
  The system unique id if one can be obtained.

Definition at line 108 of file hardware_buffer.cc.

109 {
110 if (!GetProcTable().AHardwareBuffer_getId) {
111 return std::nullopt;
112 }
113 uint64_t out_id = 0u;
114 if (GetProcTable().AHardwareBuffer_getId(buffer, &out_id) != 0) {
115 return std::nullopt;
116 }
117 return out_id;
118 }

References impeller::android::GetProcTable().

## ◆ IsAvailableOnPlatform()

bool impeller::android::HardwareBuffer::IsAvailableOnPlatform | ( |  | ) |
| static

Definition at line 100 of file hardware_buffer.cc.

100 {
101 return GetProcTable().IsValid() && GetProcTable().AHardwareBuffer_isSupported;
102 }

References impeller::android::GetProcTable(), and impeller::android::ProcTable::IsValid().

Referenced by impeller::android::testing::TEST().

## ◆ IsValid()

bool impeller::android::HardwareBuffer::IsValid | ( |  | ) | const

Definition at line 69 of file hardware_buffer.cc.

69 {
70 return is_valid_;
71 }

Referenced by impeller::android::testing::TEST().

## ◆ operator=()

HardwareBuffer& impeller::android::HardwareBuffer::operator= | ( | const HardwareBuffer & |  | ) |
| delete

The documentation for this class was generated from the following files:

- impeller/toolkit/android/hardware_buffer.h
- impeller/toolkit/android/hardware_buffer.cc

impeller::android::ToAHardwareBufferDesc
static AHardwareBuffer_Desc ToAHardwareBufferDesc(const HardwareBufferDescriptor &desc)
Definition: hardware_buffer.cc:20
impeller::android::HardwareBuffer::GetSystemUniqueID
std::optional< uint64_t > GetSystemUniqueID() const
Get the system wide unique ID of the hardware buffer if possible. This is only available on Android A...
Definition: hardware_buffer.cc:104
impeller::android::ProcTable::IsValid
bool IsValid() const
If a valid proc table could be setup. This may fail in case of setup on non-Android platforms.
Definition: proc_table.cc:65
impeller::android::HardwareBuffer::GetHandle
AHardwareBuffer * GetHandle() const
Definition: hardware_buffer.cc:73
VALIDATION_LOG
#define VALIDATION_LOG
Definition: validation.h:73
impeller::android::GetProcTable
const ProcTable & GetProcTable()
Definition: proc_table.cc:12
impeller::android::HardwareBufferDescriptor::IsAllocatable
bool IsAllocatable() const
If hardware buffers can be created using this descriptor. Allocatable descriptors may still cause fai...
Definition: hardware_buffer.cc:42