Flutter Engine
 
Loading...
Searching...
No Matches
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 Types

enum class  CPUAccessType {
  kRead ,
  kWrite
}
 

Public Member Functions

 HardwareBuffer (HardwareBufferDescriptor descriptor)
 
 ~HardwareBuffer ()
 
 HardwareBuffer (const HardwareBuffer &)=delete
 
HardwareBufferoperator= (const HardwareBuffer &)=delete
 
bool IsValid () const
 
AHardwareBuffer * GetHandle () 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.
 
void * Lock (CPUAccessType type) const
 Lock the buffer for CPU access. This call may fail if the buffer was not created with one the usages that allow for CPU access.
 
bool Unlock () const
 Unlock a mapping previously locked for CPU access.
 

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

Member Enumeration Documentation

◆ CPUAccessType

Constructor & Destructor Documentation

◆ HardwareBuffer() [1/2]

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

Definition at line 57 of file hardware_buffer.cc.

58 : descriptor_(descriptor),
59 android_descriptor_(ToAHardwareBufferDesc(descriptor_)) {
60 if (!descriptor_.IsAllocatable()) {
61 VALIDATION_LOG << "The hardware buffer descriptor is not allocatable.";
62 return;
63 }
64 const auto& proc_table = GetProcTable();
65
66 AHardwareBuffer* buffer = nullptr;
67 if (auto result =
68 proc_table.AHardwareBuffer_allocate(&android_descriptor_, &buffer);
69 result != 0 || buffer == nullptr) {
70 VALIDATION_LOG << "Could not allocate hardware buffer. Error: " << result;
71 return;
72 }
73 buffer_.reset(buffer);
74 is_valid_ = true;
75}
void reset(const T &value=Traits::InvalidValue())
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set profile Make the profiler discard new samples once the profiler sample buffer is full When this flag is not the profiler sample buffer is used as a ring buffer
Definition switch_defs.h:98
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:91

References impeller::android::GetProcTable(), impeller::android::HardwareBufferDescriptor::IsAllocatable(), fml::UniqueObject< T, Traits >::reset(), 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 127 of file hardware_buffer.cc.

128 {
129 if (!buffer || !GetProcTable().AHardwareBuffer_describe) {
130 return std::nullopt;
131 }
132 AHardwareBuffer_Desc desc = {};
133 GetProcTable().AHardwareBuffer_describe(buffer, &desc);
134 return desc;
135}

References impeller::android::GetProcTable().

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

◆ GetAndroidDescriptor()

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

Definition at line 103 of file hardware_buffer.cc.

103 {
104 return android_descriptor_;
105}

◆ GetDescriptor()

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

Definition at line 99 of file hardware_buffer.cc.

99 {
100 return descriptor_;
101}

◆ GetHandle()

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

Definition at line 83 of file hardware_buffer.cc.

83 {
84 return buffer_.get();
85}
const T & get() const

References fml::UniqueObject< T, Traits >::get().

Referenced by impeller::glvk::CreateEGLImageFromAHBTexture(), and GetSystemUniqueID().

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

111 {
113}
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...

References GetHandle(), and GetSystemUniqueID().

Referenced by GetSystemUniqueID(), impeller::android::testing::TEST(), and flutter::ImageExternalTextureGL::UpdateImage().

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

116 {
117 if (!GetProcTable().AHardwareBuffer_getId) {
118 return std::nullopt;
119 }
120 uint64_t out_id = 0u;
121 if (GetProcTable().AHardwareBuffer_getId(buffer, &out_id) != 0) {
122 return std::nullopt;
123 }
124 return out_id;
125}

References impeller::android::GetProcTable().

◆ IsAvailableOnPlatform()

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

Definition at line 107 of file hardware_buffer.cc.

107 {
108 return GetProcTable().IsValid() && GetProcTable().AHardwareBuffer_isSupported;
109}
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

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

Referenced by impeller::AHBSwapchainVK::IsAvailableOnPlatform(), impeller::android::testing::TEST(), impeller::android::testing::TEST(), impeller::android::testing::TEST(), impeller::android::testing::TEST(), and impeller::android::testing::TEST().

◆ IsValid()

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

Definition at line 79 of file hardware_buffer.cc.

79 {
80 return is_valid_;
81}

◆ Lock()

void * impeller::android::HardwareBuffer::Lock ( CPUAccessType  type) const

Lock the buffer for CPU access. This call may fail if the buffer was not created with one the usages that allow for CPU access.

Parameters
[in]typeThe type
Returns
A host-accessible buffer if there was no error related to usage or buffer validity.

Definition at line 137 of file hardware_buffer.cc.

137 {
138 if (!is_valid_ || !GetProcTable().AHardwareBuffer_lock) {
139 return nullptr;
140 }
141 uint64_t usage = 0;
142 switch (type) {
144 usage |= AHARDWAREBUFFER_USAGE_CPU_READ_MASK;
145 break;
147 usage |= AHARDWAREBUFFER_USAGE_CPU_WRITE_MASK;
148 break;
149 }
150 void* buffer = nullptr;
151 const auto result = GetProcTable().AHardwareBuffer_lock( //
152 buffer_.get(), // buffer
153 usage, // usage
154 -1, // fence
155 nullptr, // rect
156 &buffer // out-addr
157 );
158 return result == 0 ? buffer : nullptr;
159}
GLenum type

References fml::UniqueObject< T, Traits >::get(), impeller::android::GetProcTable(), kRead, kWrite, and type.

◆ operator=()

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

◆ Unlock()

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

Unlock a mapping previously locked for CPU access.

Returns
If the unlock was successful.

Definition at line 161 of file hardware_buffer.cc.

161 {
162 if (!is_valid_ || !GetProcTable().AHardwareBuffer_unlock) {
163 return false;
164 }
165 const auto result =
166 GetProcTable().AHardwareBuffer_unlock(buffer_.get(), nullptr);
167 return result == 0;
168}

References fml::UniqueObject< T, Traits >::get(), and impeller::android::GetProcTable().


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