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
Static system unique ID.
  • Loading branch information
chinmaygarde committed Mar 15, 2024
commit 317830f935bc53682468816a094655960f79693d
9 changes: 7 additions & 2 deletions impeller/toolkit/android/hardware_buffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,16 @@ bool HardwareBuffer::IsAvailableOnPlatform() {
}

std::optional<uint64_t> HardwareBuffer::GetSystemUniqueID() const {
if (!IsValid() || !GetProcTable().AHardwareBuffer_getId) {
return GetSystemUniqueID(GetHandle());
}

std::optional<uint64_t> HardwareBuffer::GetSystemUniqueID(
AHardwareBuffer* buffer) {
if (!GetProcTable().AHardwareBuffer_getId) {
return false;
}
uint64_t out_id = 0u;
if (GetProcTable().AHardwareBuffer_getId(GetHandle(), &out_id) != 0) {
if (GetProcTable().AHardwareBuffer_getId(buffer, &out_id) != 0) {
return std::nullopt;
}
return out_id;
Expand Down
9 changes: 9 additions & 0 deletions impeller/toolkit/android/hardware_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,15 @@ class HardwareBuffer {
///
std::optional<uint64_t> GetSystemUniqueID() const;

//----------------------------------------------------------------------------
/// @brief 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.
///
/// @return The system unique id if one can be obtained.
///
static std::optional<uint64_t> GetSystemUniqueID(AHardwareBuffer* buffer);

private:
struct UniqueAHardwareBufferTraits {
static AHardwareBuffer* InvalidValue() { return nullptr; }
Expand Down
4 changes: 3 additions & 1 deletion shell/platform/android/image_external_texture_gl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "flutter/common/graphics/texture.h"
#include "flutter/impeller/core/formats.h"
#include "flutter/impeller/display_list/dl_image_impeller.h"
#include "flutter/impeller/toolkit/android/hardware_buffer.h"
#include "flutter/impeller/toolkit/egl/image.h"
#include "flutter/impeller/toolkit/gles/texture.h"
#include "third_party/skia/include/core/SkAlphaType.h"
Expand Down Expand Up @@ -44,7 +45,8 @@ void ImageExternalTextureGL::UpdateImage(JavaLocalRef& hardware_buffer,
PaintContext& context) {
AHardwareBuffer* latest_hardware_buffer = AHardwareBufferFor(hardware_buffer);
std::optional<HardwareBufferKey> key =
flutter::NDKHelpers::AHardwareBuffer_getId(latest_hardware_buffer);
impeller::android::HardwareBuffer::GetSystemUniqueID(
latest_hardware_buffer);
auto existing_image = image_lru_.FindImage(key);
if (existing_image != nullptr) {
dl_image_ = existing_image;
Expand Down
3 changes: 2 additions & 1 deletion shell/platform/android/image_external_texture_vk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ void ImageExternalTextureVK::ProcessFrame(PaintContext& context,
auto hb_desc =
impeller::android::HardwareBuffer::Describe(latest_hardware_buffer);
std::optional<HardwareBufferKey> key =
flutter::NDKHelpers::AHardwareBuffer_getId(latest_hardware_buffer);
impeller::android::HardwareBuffer::GetSystemUniqueID(
latest_hardware_buffer);
auto existing_image = image_lru_.FindImage(key);
if (existing_image != nullptr) {
dl_image_ = existing_image;
Expand Down