Merge "[vr] Add DVR API to get native handle for buffers" into oc-dev
diff --git a/libs/vr/libdvr/dvr_api.cpp b/libs/vr/libdvr/dvr_api.cpp
index 5dc4a1b..c4634b1 100644
--- a/libs/vr/libdvr/dvr_api.cpp
+++ b/libs/vr/libdvr/dvr_api.cpp
@@ -53,14 +53,18 @@
     dvr_api->write_buffer_post = dvrWriteBufferPost;
     dvr_api->write_buffer_gain = dvrWriteBufferGain;
     dvr_api->write_buffer_gain_async = dvrWriteBufferGainAsync;
+    dvr_api->write_buffer_get_native_handle = dvrWriteBufferGetNativeHandle;
 
     dvr_api->read_buffer_destroy = dvrReadBufferDestroy;
     dvr_api->read_buffer_get_ahardwarebuffer = dvrReadBufferGetAHardwareBuffer;
     dvr_api->read_buffer_acquire = dvrReadBufferAcquire;
     dvr_api->read_buffer_release = dvrReadBufferRelease;
     dvr_api->read_buffer_release_async = dvrReadBufferReleaseAsync;
+    dvr_api->read_buffer_get_native_handle = dvrReadBufferGetNativeHandle;
+
     dvr_api->buffer_destroy = dvrBufferDestroy;
     dvr_api->buffer_get_ahardwarebuffer = dvrBufferGetAHardwareBuffer;
+    dvr_api->buffer_get_native_handle = dvrBufferGetNativeHandle;
 
     // dvr_buffer_queue.h
     dvr_api->write_buffer_queue_destroy = dvrWriteBufferQueueDestroy;
diff --git a/libs/vr/libdvr/dvr_buffer.cpp b/libs/vr/libdvr/dvr_buffer.cpp
index 0942b3d..e7fdb91 100644
--- a/libs/vr/libdvr/dvr_buffer.cpp
+++ b/libs/vr/libdvr/dvr_buffer.cpp
@@ -136,4 +136,18 @@
   return 0;
 }
 
+const struct native_handle* dvrWriteBufferGetNativeHandle(
+    DvrWriteBuffer* write_buffer) {
+  return write_buffer->write_buffer->native_handle();
+}
+
+const struct native_handle* dvrReadBufferGetNativeHandle(
+    DvrReadBuffer* read_buffer) {
+  return read_buffer->read_buffer->native_handle();
+}
+
+const struct native_handle* dvrBufferGetNativeHandle(DvrBuffer* buffer) {
+  return buffer->buffer->handle();
+}
+
 }  // extern "C"
diff --git a/libs/vr/libdvr/include/dvr/dvr_api.h b/libs/vr/libdvr/include/dvr/dvr_api.h
index b60f490..56f937b 100644
--- a/libs/vr/libdvr/include/dvr/dvr_api.h
+++ b/libs/vr/libdvr/include/dvr/dvr_api.h
@@ -38,6 +38,8 @@
 
 typedef struct DvrSurface DvrSurface;
 
+struct native_handle;
+
 // display_manager_client.h
 typedef int (*DvrDisplayManagerClientGetSurfaceListPtr)(
     DvrDisplayManagerClient* client,
@@ -70,6 +72,8 @@
 typedef int (*DvrWriteBufferGainPtr)(DvrWriteBuffer* client,
                                      int* release_fence_fd);
 typedef int (*DvrWriteBufferGainAsyncPtr)(DvrWriteBuffer* client);
+typedef const struct native_handle* (*DvrWriteBufferGetNativeHandle)(
+    DvrWriteBuffer* write_buffer);
 
 typedef void (*DvrReadBufferDestroyPtr)(DvrReadBuffer* client);
 typedef int (*DvrReadBufferGetAHardwareBufferPtr)(
@@ -80,9 +84,14 @@
 typedef int (*DvrReadBufferReleasePtr)(DvrReadBuffer* client,
                                        int release_fence_fd);
 typedef int (*DvrReadBufferReleaseAsyncPtr)(DvrReadBuffer* client);
+typedef const struct native_handle* (*DvrReadBufferGetNativeHandle)(
+    DvrReadBuffer* read_buffer);
+
 typedef void (*DvrBufferDestroy)(DvrBuffer* buffer);
 typedef int (*DvrBufferGetAHardwareBuffer)(DvrBuffer* buffer,
                                            AHardwareBuffer** hardware_buffer);
+typedef const struct native_handle* (*DvrBufferGetNativeHandle)(
+    DvrBuffer* buffer);
 
 // dvr_buffer_queue.h
 typedef void (*DvrWriteBufferQueueDestroyPtr)(DvrWriteBufferQueue* write_queue);
@@ -238,6 +247,7 @@
   DvrWriteBufferPostPtr write_buffer_post;
   DvrWriteBufferGainPtr write_buffer_gain;
   DvrWriteBufferGainAsyncPtr write_buffer_gain_async;
+  DvrWriteBufferGetNativeHandle write_buffer_get_native_handle;
 
   // Read buffer
   DvrReadBufferDestroyPtr read_buffer_destroy;
@@ -245,8 +255,12 @@
   DvrReadBufferAcquirePtr read_buffer_acquire;
   DvrReadBufferReleasePtr read_buffer_release;
   DvrReadBufferReleaseAsyncPtr read_buffer_release_async;
+  DvrReadBufferGetNativeHandle read_buffer_get_native_handle;
+
+  // Buffer
   DvrBufferDestroy buffer_destroy;
   DvrBufferGetAHardwareBuffer buffer_get_ahardwarebuffer;
+  DvrBufferGetNativeHandle buffer_get_native_handle;
 
   // Write buffer queue
   DvrWriteBufferQueueDestroyPtr write_buffer_queue_destroy;
diff --git a/libs/vr/libdvr/include/dvr/dvr_buffer.h b/libs/vr/libdvr/include/dvr/dvr_buffer.h
index 6c9c4d3..b2cf0d7 100644
--- a/libs/vr/libdvr/include/dvr/dvr_buffer.h
+++ b/libs/vr/libdvr/include/dvr/dvr_buffer.h
@@ -13,6 +13,7 @@
 typedef struct DvrReadBuffer DvrReadBuffer;
 typedef struct DvrBuffer DvrBuffer;
 typedef struct AHardwareBuffer AHardwareBuffer;
+struct native_handle;
 
 // Write buffer
 void dvrWriteBufferDestroy(DvrWriteBuffer* write_buffer);
@@ -23,6 +24,8 @@
                        const void* meta, size_t meta_size_bytes);
 int dvrWriteBufferGain(DvrWriteBuffer* write_buffer, int* release_fence_fd);
 int dvrWriteBufferGainAsync(DvrWriteBuffer* write_buffer);
+const struct native_handle* dvrWriteBufferGetNativeHandle(
+    DvrWriteBuffer* write_buffer);
 
 // Read buffer
 void dvrReadBufferDestroy(DvrReadBuffer* read_buffer);
@@ -33,11 +36,14 @@
                          void* meta, size_t meta_size_bytes);
 int dvrReadBufferRelease(DvrReadBuffer* read_buffer, int release_fence_fd);
 int dvrReadBufferReleaseAsync(DvrReadBuffer* read_buffer);
+const struct native_handle* dvrReadBufferGetNativeHandle(
+    DvrReadBuffer* read_buffer);
 
 // Buffer
 void dvrBufferDestroy(DvrBuffer* buffer);
 int dvrBufferGetAHardwareBuffer(DvrBuffer* buffer,
                                 AHardwareBuffer** hardware_buffer);
+const struct native_handle* dvrBufferGetNativeHandle(DvrBuffer* buffer);
 
 #ifdef __cplusplus
 }  // extern "C"