Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Get hardware buffer IDs.
  • Loading branch information
chinmaygarde committed Mar 14, 2024
commit f44366e47adea1c7dc191e8023844e56f2d89209
11 changes: 11 additions & 0 deletions impeller/toolkit/android/hardware_buffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,15 @@ bool HardwareBuffer::IsAvailableOnPlatform() {
GetProcTable().AHardwareBuffer_allocate.IsAvailable();
}

std::optional<uint64_t> HardwareBuffer::GetSystemUniqueID() const {
if (!IsValid() || !GetProcTable().AHardwareBuffer_getId) {
return false;
}
uint64_t out_id = 0u;
if (GetProcTable().AHardwareBuffer_getId(GetHandle(), &out_id) != 0) {
return std::nullopt;
}
return out_id;
}

} // namespace impeller::android
2 changes: 2 additions & 0 deletions impeller/toolkit/android/hardware_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ class HardwareBuffer {

const AHardwareBuffer_Desc& GetAndroidDescriptor() const;

std::optional<uint64_t> GetSystemUniqueID() const;

private:
struct UniqueAHardwareBufferTraits {
static AHardwareBuffer* InvalidValue() { return nullptr; }
Expand Down
1 change: 1 addition & 0 deletions impeller/toolkit/android/proc_table.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ namespace impeller::android {
INVOKE(AHardwareBuffer_release, 26) \
INVOKE(AHardwareBuffer_isSupported, 29) \
INVOKE(AHardwareBuffer_describe, 26) \
INVOKE(AHardwareBuffer_getId, 31) \
INVOKE(ANativeWindow_acquire, 0) \
INVOKE(ANativeWindow_release, 0) \
INVOKE(ANativeWindow_getWidth, 0) \
Expand Down
12 changes: 12 additions & 0 deletions impeller/toolkit/android/toolkit_android_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,18 @@ TEST_F(ToolkitAndroidTest, CanCreateHardwareBuffer) {
ASSERT_TRUE(buffer.IsValid());
}

TEST_F(ToolkitAndroidTest, CanGetHardwareBufferIDs) {
ASSERT_TRUE(HardwareBuffer::IsAvailableOnPlatform());
if (!GetProcTable().AHardwareBuffer_getId.IsAvailable()) {
GTEST_SKIP() << "Hardware buffer IDs are not available on this platform.";
}
auto desc = HardwareBufferDescriptor::MakeForSwapchainImage({100, 100});
ASSERT_TRUE(desc.IsAllocatable());
HardwareBuffer buffer(desc);
ASSERT_TRUE(buffer.IsValid());
ASSERT_TRUE(buffer.GetSystemUniqueID().has_value());
}

TEST_F(ToolkitAndroidTest, CanApplySurfaceTransaction) {
ASSERT_TRUE(SurfaceTransaction::IsAvailableOnPlatform());
SurfaceTransaction transaction;
Expand Down