From ead3d6eef3238f95a795603d9490e18492f3b37b Mon Sep 17 00:00:00 2001 From: Yiwei Zhang Date: Tue, 11 Aug 2020 16:12:50 -0700 Subject: AHB: add AHardwareBuffer_getId API in ndk Add this api to ndk so that there's a reliable system-wide unique id for caching. libui is not linkable from sphal so vendors cannot convert an AHB into GraphicBuffer to call getId(). This change solves the problem. This change has been forced to refactor the existing docs and annotations due to -Wnullability-completeness. Bug: 162425097 Bug: 163615119 Test: atest libnativewindow_test:AHardwareBufferTest#GetIdTest Change-Id: I91043b96b83bc9a896c361385581e9620fe373c3 --- libs/nativewindow/AHardwareBuffer.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'libs/nativewindow/AHardwareBuffer.cpp') diff --git a/libs/nativewindow/AHardwareBuffer.cpp b/libs/nativewindow/AHardwareBuffer.cpp index 1ec73ce961..a375d43a43 100644 --- a/libs/nativewindow/AHardwareBuffer.cpp +++ b/libs/nativewindow/AHardwareBuffer.cpp @@ -397,6 +397,16 @@ int AHardwareBuffer_isSupported(const AHardwareBuffer_Desc* desc) { return 0; } +int AHardwareBuffer_getId(const AHardwareBuffer* buffer, uint64_t* outId) { + if (!buffer || !outId) return BAD_VALUE; + + const GraphicBuffer* gb = AHardwareBuffer_to_GraphicBuffer(buffer); + if (!gb) return BAD_VALUE; + + *outId = gb->getId(); + + return OK; +} // ---------------------------------------------------------------------------- // VNDK functions -- cgit v1.2.3-59-g8ed1b