Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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
 
HardwareBufferoperator= (const HardwareBuffer &)=delete
 
bool IsValid () const
 
AHardwareBufferGetHandle () const
 
const HardwareBufferDescriptorGetDescriptor () 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.
 

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.
 

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 90 of file hardware_buffer.h.

Constructor & Destructor Documentation

◆ HardwareBuffer() [1/2]

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

Definition at line 44 of file hardware_buffer.cc.

45 : descriptor_(descriptor),
46 android_descriptor_(ToAHardwareBufferDesc(descriptor_)) {
47 if (!descriptor_.IsAllocatable()) {
48 VALIDATION_LOG << "The hardware buffer descriptor is not allocatable.";
49 return;
50 }
51 const auto& proc_table = GetProcTable();
52
53 AHardwareBuffer* buffer = nullptr;
54 if (auto result =
55 proc_table.AHardwareBuffer_allocate(&android_descriptor_, &buffer);
56 result != 0 || buffer == nullptr) {
57 VALIDATION_LOG << "Could not allocate hardware buffer. Error: " << result;
58 return;
59 }
60 buffer_.reset(buffer);
61 is_valid_ = true;
62}
struct AHardwareBuffer AHardwareBuffer
void reset(const T &value=Traits::InvalidValue())
static const uint8_t buffer[]
GAsyncResult * result
const ProcTable & GetProcTable()
Definition proc_table.cc:12
static AHardwareBuffer_Desc ToAHardwareBufferDesc(const HardwareBufferDescriptor &desc)
bool IsAllocatable() const
If hardware buffers can be created using this descriptor. Allocatable descriptors may still cause fai...
#define VALIDATION_LOG
Definition validation.h:73

◆ ~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 114 of file hardware_buffer.cc.

115 {
116 if (!buffer || !GetProcTable().AHardwareBuffer_describe) {
117 return std::nullopt;
118 }
119 AHardwareBuffer_Desc desc = {};
120 GetProcTable().AHardwareBuffer_describe(buffer, &desc);
121 return desc;
122}

◆ GetAndroidDescriptor()

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

Definition at line 90 of file hardware_buffer.cc.

90 {
91 return android_descriptor_;
92}

◆ GetDescriptor()

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

Definition at line 86 of file hardware_buffer.cc.

86 {
87 return descriptor_;
88}

◆ GetHandle()

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

Definition at line 70 of file hardware_buffer.cc.

70 {
71 return buffer_.get();
72}
const T & get() const

◆ 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 98 of file hardware_buffer.cc.

98 {
100}
AHardwareBuffer * GetHandle() 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 A...

◆ 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 102 of file hardware_buffer.cc.

103 {
104 if (!GetProcTable().AHardwareBuffer_getId) {
105 return std::nullopt;
106 }
107 uint64_t out_id = 0u;
108 if (GetProcTable().AHardwareBuffer_getId(buffer, &out_id) != 0) {
109 return std::nullopt;
110 }
111 return out_id;
112}

◆ IsAvailableOnPlatform()

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

Definition at line 94 of file hardware_buffer.cc.

94 {
95 return GetProcTable().IsValid() && GetProcTable().AHardwareBuffer_isSupported;
96}
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

◆ IsValid()

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

Definition at line 66 of file hardware_buffer.cc.

66 {
67 return is_valid_;
68}

◆ operator=()

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

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