[vulkan] Use C++ FIDL bindings and add Android.bp

Update the code to use C++ FIDL bindings everywhere instead
of using C bindings in some places. No change in behavior.

This also adds an Android.bp file that can be used to build
a libvulkan_goldfish.so for Fuchsia outside the Fuchsia tree.
Tracing is temporarily disabled for this build.

Change-Id: I96b29497cd7b6f4fd6c614d9c653dc5b1830feaf
diff --git a/Android.bp b/Android.bp
new file mode 100644
index 0000000..7d01237
--- /dev/null
+++ b/Android.bp
@@ -0,0 +1,103 @@
+cc_library_shared {
+    name: "libvulkan_goldfish",
+
+    srcs: [
+        "android-emu/android/base/AlignedBuf.cpp",
+        "android-emu/android/base/Pool.cpp",
+        "android-emu/android/base/SubAllocator.cpp",
+        "android-emu/android/base/files/MemStream.cpp",
+        "android-emu/android/base/files/Stream.cpp",
+        "android-emu/android/base/files/StreamSerializing.cpp",
+        "android-emu/android/base/Tracing.cpp",
+        "shared/OpenglCodecCommon/ChecksumCalculator.cpp",
+        "shared/OpenglCodecCommon/glUtils.cpp",
+        "shared/OpenglCodecCommon/goldfish_address_space.cpp",
+        "shared/OpenglCodecCommon/goldfish_dma.cpp",
+        "system/OpenglSystemCommon/HostConnection.cpp",
+        "system/OpenglSystemCommon/ProcessPipe.cpp",
+        "system/OpenglSystemCommon/ThreadInfo.cpp",
+        "system/renderControl_enc/renderControl_enc.cpp",
+        "system/vulkan/func_table.cpp",
+        "system/vulkan/goldfish_vulkan.cpp",
+        "system/vulkan_enc/HostVisibleMemoryVirtualization.cpp",
+        "system/vulkan_enc/ResourceTracker.cpp",
+        "system/vulkan_enc/Resources.cpp",
+        "system/vulkan_enc/Validation.cpp",
+        "system/vulkan_enc/VkEncoder.cpp",
+        "system/vulkan_enc/VulkanHandleMapping.cpp",
+        "system/vulkan_enc/VulkanStreamGuest.cpp",
+        "system/vulkan_enc/goldfish_vk_deepcopy_guest.cpp",
+        "system/vulkan_enc/goldfish_vk_extension_structs_guest.cpp",
+        "system/vulkan_enc/goldfish_vk_marshaling_guest.cpp",
+        "system/vulkan_enc/goldfish_vk_transform_guest.cpp",
+    ],
+
+    cflags: [
+        "-DLOG_TAG=\"goldfish_vulkan\"",
+        "-DGOLDFISH_VULKAN",
+        "-DGOLDFISH_NO_GL",
+        "-DPAGE_SIZE=4096",
+        "-Wno-unused-parameter",
+        "-Wno-missing-field-initializers",
+        "-Wno-newline-eof",
+        "-Wno-unused-function",
+        "-Wno-unused-value",
+        "-Wno-unused-variable",
+    ],
+
+    include_dirs: [
+        "external/qemu/android/android-emugl/host/include",
+    ],
+
+    local_include_dirs: [
+        "android-emu",
+        "host/include/libOpenglRender",
+        "shared/OpenglCodecCommon",
+        "system/OpenglSystemCommon",
+        "system/renderControl_enc",
+        "system/vulkan_enc",
+        "system/include",
+    ],
+
+    // Only enable on fuchsia.
+    enabled: false,
+    target: {
+        fuchsia: {
+	    enabled: true,
+
+            srcs: [
+                "fuchsia/port.cc",
+                "system/OpenglSystemCommon/QemuPipeStreamFuchsia.cpp",
+            ],
+
+            cflags: [
+                "-DVK_USE_PLATFORM_FUCHSIA",
+                "-DPLATFORM_SDK_VERSION=1",
+                "-DFUCHSIA_NO_TRACE",
+                "-DQEMU_PIPE_PATH=\"/dev/class/goldfish-pipe/000\"",
+                "-DGOLDFISH_ADDRESS_SPACE_DEVICE_NAME=\"/dev/class/goldfish-address-space/000\"",
+            ],
+
+            local_include_dirs: [
+                "fuchsia/include",
+            ],
+
+            shared_libs: [
+                "libfdio",
+                "libfidl",
+                "libfidl_cpp",
+                "libfidl_cpp_base",
+                "libfidl_cpp_sync",
+                "libfuchsia.hardware.goldfish.address.space",
+                "libfuchsia.hardware.goldfish.control",
+                "libfuchsia.hardware.goldfish.pipe",
+                "libfuchsia.sysmem",
+                "libzx",
+            ],
+
+            required: [
+                "libzircon",
+            ],
+        },
+    },
+}
diff --git a/BUILD.gn b/BUILD.gn
index 6b4bc0c..9e48712 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -80,6 +80,7 @@
 
   cflags_cc = [
     "-Wno-missing-field-initializers",
+    "-Wno-newline-eof",
     "-Wno-unused-function",
     "-Wno-unused-value",
     "-Wno-unused-variable",
@@ -104,9 +105,9 @@
     ]
 
     deps = [
-      "//zircon/public/fidl/fuchsia-hardware-goldfish-address-space:fuchsia-hardware-goldfish-address-space_c",
-      "//zircon/public/fidl/fuchsia-hardware-goldfish-control:fuchsia-hardware-goldfish-control_c",
-      "//zircon/public/fidl/fuchsia-hardware-goldfish-pipe:fuchsia-hardware-goldfish-pipe_c",
+      "//zircon/public/fidl/fuchsia-hardware-goldfish-address-space",
+      "//zircon/public/fidl/fuchsia-hardware-goldfish-control",
+      "//zircon/public/fidl/fuchsia-hardware-goldfish-pipe",
       "//zircon/public/fidl/fuchsia-sysmem",
       "//zircon/public/lib/fdio",
       "//zircon/public/lib/trace",
diff --git a/android-emu/android/base/Tracing.cpp b/android-emu/android/base/Tracing.cpp
index 8b254d2..ff72093 100644
--- a/android-emu/android/base/Tracing.cpp
+++ b/android-emu/android/base/Tracing.cpp
@@ -36,7 +36,9 @@
 
 #elif __Fuchsia__
 
+#ifndef FUCHSIA_NO_TRACE
 #include <trace/event.h>
+#endif
 
 #define VK_TRACE_TAG "gfx"
 
@@ -44,11 +46,15 @@
 namespace base {
 
 void ScopedTrace::beginTraceImpl(const char* name) {
+#ifndef FUCHSIA_NO_TRACE
     TRACE_DURATION_BEGIN(VK_TRACE_TAG, name);
+#endif
 }
 
 void ScopedTrace::endTraceImpl(const char* name) {
+#ifndef FUCHSIA_NO_TRACE
     TRACE_DURATION_END(VK_TRACE_TAG, name);
+#endif
 }
 
 } // namespace base
diff --git a/shared/OpenglCodecCommon/goldfish_address_space.cpp b/shared/OpenglCodecCommon/goldfish_address_space.cpp
index bbc59c6..da6831e 100644
--- a/shared/OpenglCodecCommon/goldfish_address_space.cpp
+++ b/shared/OpenglCodecCommon/goldfish_address_space.cpp
@@ -127,8 +127,9 @@
 }
 #elif __Fuchsia__
 #include <fcntl.h>
-#include <fuchsia/hardware/goldfish/address/space/c/fidl.h>
 #include <lib/fdio/fdio.h>
+#include <lib/zx/channel.h>
+#include <lib/zx/vmo.h>
 #include <stdlib.h>
 #include <sys/stat.h>
 #include <sys/types.h>
@@ -138,17 +139,25 @@
 #include <zircon/syscalls/object.h>
 
 GoldfishAddressSpaceBlockProvider::GoldfishAddressSpaceBlockProvider() {
-    fdio_get_service_handle(::open(GOLDFISH_ADDRESS_SPACE_DEVICE_NAME, O_RDWR), &m_channel);
+    zx::channel channel;
+    zx_status_t status =
+        fdio_get_service_handle(::open(GOLDFISH_ADDRESS_SPACE_DEVICE_NAME, O_RDWR),
+                                channel.reset_and_get_address());
+    if (status != ZX_OK) {
+        ALOGE("%s: failed to get service handle for " GOLDFISH_ADDRESS_SPACE_DEVICE_NAME ": %d",
+              __FUNCTION__, status);
+        return;
+    }
+    m_device.Bind(std::move(channel));
 }
 
 GoldfishAddressSpaceBlockProvider::~GoldfishAddressSpaceBlockProvider()
 {
-    zx_handle_close(m_channel);
 }
 
 GoldfishAddressSpaceBlock::GoldfishAddressSpaceBlock()
-    : m_vmo(ZX_HANDLE_INVALID)
-    , m_channel(ZX_HANDLE_INVALID)
+    : m_device(NULL)
+    , m_vmo(ZX_HANDLE_INVALID)
     , m_mmaped_ptr(NULL)
     , m_phys_addr(0)
     , m_host_addr(0)
@@ -168,7 +177,7 @@
     m_host_addr = rhs.m_host_addr;
     m_offset = rhs.m_offset;
     m_size = rhs.m_size;
-    m_channel = rhs.m_channel;
+    m_device = rhs.m_device;
 
     return *this;
 }
@@ -184,10 +193,11 @@
         return false;
     }
 
+    fuchsia::hardware::goldfish::address::space::DeviceSyncPtr* device = &provider->m_device;
+
     int32_t res = ZX_OK;
-    zx_status_t status =
-        fuchsia_hardware_goldfish_address_space_DeviceAllocateBlock(
-            provider->m_channel, size, &res, &m_phys_addr, &m_vmo);
+    zx::vmo vmo;
+    zx_status_t status = (*device)->AllocateBlock(size, &res, &m_phys_addr, &vmo);
     if (status != ZX_OK || res != ZX_OK) {
         ALOGE("%s: allocate block failed: %d:%d", __func__, status, res);
         return false;
@@ -195,12 +205,13 @@
 
     m_offset = 0;
     m_size = size;
+    m_vmo = vmo.release();
 
     ALOGD("%s: allocate returned offset 0x%llx size 0x%llx\n", __func__,
           (unsigned long long)m_offset,
           (unsigned long long)m_size);
 
-    m_channel = provider->m_channel;
+    m_device = device;
     return true;
 }
 
@@ -264,13 +275,11 @@
         zx_handle_close(m_vmo);
         m_vmo = ZX_HANDLE_INVALID;
         int32_t res = ZX_OK;
-        zx_status_t status =
-            fuchsia_hardware_goldfish_address_space_DeviceDeallocateBlock(
-                m_channel, m_phys_addr, &res);
+        zx_status_t status = (*m_device)->DeallocateBlock(m_phys_addr, &res);
         if (status != ZX_OK || res != ZX_OK) {
             ALOGE("%s: deallocate block failed: %d:%d", __func__, status, res);
         }
-        m_channel = ZX_HANDLE_INVALID;
+        m_device = NULL;
         m_phys_addr = 0;
         m_host_addr = 0;
         m_offset = 0;
@@ -290,7 +299,7 @@
 
 bool GoldfishAddressSpaceBlockProvider::is_opened()
 {
-    return m_channel != ZX_HANDLE_INVALID;
+    return m_device.is_bound();
 }
 #else
 #include <linux/types.h>
diff --git a/shared/OpenglCodecCommon/goldfish_address_space.h b/shared/OpenglCodecCommon/goldfish_address_space.h
index 7ebb451..250c476 100644
--- a/shared/OpenglCodecCommon/goldfish_address_space.h
+++ b/shared/OpenglCodecCommon/goldfish_address_space.h
@@ -18,6 +18,10 @@
 #include <inttypes.h>
 #include <stddef.h>
 
+#ifdef __Fuchsia__
+#include <fuchsia/hardware/goldfish/address/space/cpp/fidl.h>
+#endif
+
 class GoldfishAddressSpaceBlock;
 
 #ifdef HOST_BUILD
@@ -46,7 +50,7 @@
 
    bool is_opened();
 #ifdef __Fuchsia__
-   uint32_t m_channel;
+   fuchsia::hardware::goldfish::address::space::DeviceSyncPtr m_device;
 #else
    int m_fd;
 #endif
@@ -78,8 +82,8 @@
     GoldfishAddressSpaceBlockProvider* m_provider;
 #else
 #ifdef __Fuchsia__
+    fuchsia::hardware::goldfish::address::space::DeviceSyncPtr* m_device;
     uint32_t  m_vmo;
-    uint32_t  m_channel;
 #else
     int       m_fd;
 #endif
diff --git a/system/OpenglSystemCommon/QemuPipeStream.h b/system/OpenglSystemCommon/QemuPipeStream.h
index 8d64ab8..a6a3d88 100644
--- a/system/OpenglSystemCommon/QemuPipeStream.h
+++ b/system/OpenglSystemCommon/QemuPipeStream.h
@@ -26,7 +26,7 @@
 #include "qemu_pipe.h"
 
 #ifdef __Fuchsia__
-#include <lib/zx/channel.h>
+#include <fuchsia/hardware/goldfish/pipe/cpp/fidl.h>
 #include <lib/zx/event.h>
 #include <lib/zx/vmo.h>
 #endif
@@ -55,7 +55,7 @@
     size_t m_bufsize;
     unsigned char *m_buf;
 #ifdef __Fuchsia__
-    zx::channel m_channel;
+    fuchsia::hardware::goldfish::pipe::DeviceSyncPtr m_device;
     zx::event m_event;
     zx::vmo m_vmo;
 #endif
diff --git a/system/OpenglSystemCommon/QemuPipeStreamFuchsia.cpp b/system/OpenglSystemCommon/QemuPipeStreamFuchsia.cpp
index f4ee61c..4377d40 100644
--- a/system/OpenglSystemCommon/QemuPipeStreamFuchsia.cpp
+++ b/system/OpenglSystemCommon/QemuPipeStreamFuchsia.cpp
@@ -17,8 +17,8 @@
 
 #include <cutils/log.h>
 #include <errno.h>
-#include <fuchsia/hardware/goldfish/pipe/c/fidl.h>
 #include <lib/fdio/fdio.h>
+#include <lib/zx/channel.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -45,7 +45,7 @@
 
 QemuPipeStream::~QemuPipeStream()
 {
-    if (m_channel.is_valid()) {
+    if (m_device.is_bound()) {
         flush();
     }
     if (m_buf) {
@@ -77,6 +77,7 @@
         close(fd);
         return -1;
     }
+    m_device.Bind(std::move(channel));
 
     zx::event event;
     status = zx::event::create(0, &event);
@@ -91,8 +92,7 @@
         return -1;
     }
 
-    status = fuchsia_hardware_goldfish_pipe_DeviceSetEvent(
-        channel.get(), event_copy.release());
+    status = m_device->SetEvent(std::move(event_copy));
     if (status != ZX_OK) {
         ALOGE("%s: failed to set event: %d:%d", __FUNCTION__, status);
         return -1;
@@ -100,8 +100,7 @@
 
     zx_status_t status2 = ZX_OK;
     zx::vmo vmo;
-    status = fuchsia_hardware_goldfish_pipe_DeviceGetBuffer(
-        channel.get(), &status2, vmo.reset_and_get_address());
+    status = m_device->GetBuffer(&status2, &vmo);
     if (status != ZX_OK || status2 != ZX_OK) {
         ALOGE("%s: failed to get buffer: %d:%d", __FUNCTION__, status, status2);
         return -1;
@@ -115,15 +114,13 @@
     }
 
     uint64_t actual;
-    status = fuchsia_hardware_goldfish_pipe_DeviceWrite(
-        channel.get(), len + 1, 0, &status2, &actual);
+    status = m_device->Write(len + 1, 0, &status2, &actual);
     if (status != ZX_OK || status2 != ZX_OK) {
         ALOGD("%s: connecting to pipe service failed: %d:%d", __FUNCTION__,
               status, status2);
         return -1;
     }
 
-    m_channel = std::move(channel);
     m_event = std::move(event);
     m_vmo = std::move(vmo);
     return 0;
@@ -149,16 +146,14 @@
     size_t allocSize = m_bufsize < minSize ? minSize : m_bufsize;
 
     zx_status_t status2 = ZX_OK;
-    status = fuchsia_hardware_goldfish_pipe_DeviceSetBufferSize(
-        m_channel.get(), allocSize, &status2);
+    status = m_device->SetBufferSize(allocSize, &status2);
     if (status != ZX_OK || status2 != ZX_OK) {
         ALOGE("%s: failed to get buffer: %d:%d", __FUNCTION__, status, status2);
         return nullptr;
     }
 
     zx::vmo vmo;
-    status = fuchsia_hardware_goldfish_pipe_DeviceGetBuffer(
-        m_channel.get(), &status2, vmo.reset_and_get_address());
+    status = m_device->GetBuffer(&status2, &vmo);
     if (status != ZX_OK || status2 != ZX_OK) {
         ALOGE("%s: failed to get buffer: %d:%d", __FUNCTION__, status, status2);
         return nullptr;
@@ -187,8 +182,8 @@
     while (remaining) {
         zx_status_t status2 = ZX_OK;
         uint64_t actual = 0;
-        zx_status_t status = fuchsia_hardware_goldfish_pipe_DeviceWrite(
-            m_channel.get(), remaining, size - remaining, &status2, &actual);
+        zx_status_t status = m_device->Write(
+            remaining, size - remaining, &status2, &actual);
         if (status != ZX_OK) {
             ALOGD("%s: Failed writing to pipe: %d", __FUNCTION__, status);
             return -1;
@@ -203,14 +198,14 @@
         }
         zx_signals_t observed = ZX_SIGNAL_NONE;
         status = m_event.wait_one(
-            fuchsia_hardware_goldfish_pipe_SIGNAL_WRITABLE |
-            fuchsia_hardware_goldfish_pipe_SIGNAL_HANGUP,
+            fuchsia::hardware::goldfish::pipe::SIGNAL_WRITABLE |
+            fuchsia::hardware::goldfish::pipe::SIGNAL_HANGUP,
             zx::time::infinite(), &observed);
         if (status != ZX_OK) {
             ALOGD("%s: wait_one failed: %d", __FUNCTION__, status);
             return -1;
         }
-        if (observed & fuchsia_hardware_goldfish_pipe_SIGNAL_HANGUP) {
+        if (observed & fuchsia::hardware::goldfish::pipe::SIGNAL_HANGUP) {
             ALOGD("%s: Remote end hungup", __FUNCTION__);
             return -1;
         }
@@ -232,7 +227,7 @@
 
 const unsigned char *QemuPipeStream::readFully(void *buf, size_t len)
 {
-    if (!m_channel.is_valid()) return nullptr;
+    if (!m_device.is_bound()) return nullptr;
 
     if (!buf) {
         if (len > 0) {
@@ -248,8 +243,7 @@
         size_t readSize = m_bufsize < remaining ? m_bufsize : remaining;
         zx_status_t status2 = ZX_OK;
         uint64_t actual = 0;
-        zx_status_t status = fuchsia_hardware_goldfish_pipe_DeviceRead(
-            m_channel.get(), readSize, 0, &status2, &actual);
+        zx_status_t status = m_device->Read(readSize, 0, &status2, &actual);
         if (status != ZX_OK) {
             ALOGD("%s: Failed reading from pipe: %d", __FUNCTION__, status);
             return nullptr;
@@ -265,14 +259,14 @@
         }
         zx_signals_t observed = ZX_SIGNAL_NONE;
         status = m_event.wait_one(
-            fuchsia_hardware_goldfish_pipe_SIGNAL_READABLE |
-            fuchsia_hardware_goldfish_pipe_SIGNAL_HANGUP,
+            fuchsia::hardware::goldfish::pipe::SIGNAL_READABLE |
+            fuchsia::hardware::goldfish::pipe::SIGNAL_HANGUP,
             zx::time::infinite(), &observed);
         if (status != ZX_OK) {
             ALOGD("%s: wait_one failed: %d", __FUNCTION__, status);
             return nullptr;
         }
-        if (observed & fuchsia_hardware_goldfish_pipe_SIGNAL_HANGUP) {
+        if (observed & fuchsia::hardware::goldfish::pipe::SIGNAL_HANGUP) {
             ALOGD("%s: Remote end hungup", __FUNCTION__);
             return nullptr;
         }
diff --git a/system/vulkan_enc/ResourceTracker.cpp b/system/vulkan_enc/ResourceTracker.cpp
index 9b46e81..98f5527 100644
--- a/system/vulkan_enc/ResourceTracker.cpp
+++ b/system/vulkan_enc/ResourceTracker.cpp
@@ -34,13 +34,14 @@
 #ifdef VK_USE_PLATFORM_FUCHSIA
 
 #include <cutils/native_handle.h>
-#include <fuchsia/hardware/goldfish/control/c/fidl.h>
+#include <fuchsia/hardware/goldfish/control/cpp/fidl.h>
 #include <fuchsia/sysmem/cpp/fidl.h>
 #include <lib/fdio/directory.h>
 #include <lib/fdio/fd.h>
 #include <lib/fdio/fdio.h>
 #include <lib/fdio/io.h>
 #include <lib/zx/channel.h>
+#include <lib/zx/vmo.h>
 #include <zircon/process.h>
 #include <zircon/syscalls.h>
 #include <zircon/syscalls/object.h>
@@ -546,14 +547,14 @@
                 ALOGE("failed to open control device");
                 abort();
             }
-            zx_status_t status = fdio_get_service_handle(fd, &mControlDevice);
+            zx::channel channel;
+            zx_status_t status = fdio_get_service_handle(fd, channel.reset_and_get_address());
             if (status != ZX_OK) {
                 ALOGE("failed to get control service handle, status %d", status);
                 abort();
             }
-            status = fuchsia_hardware_goldfish_control_DeviceConnectSysmem(
-                mControlDevice,
-                mSysmemAllocator.NewRequest().TakeChannel().release());
+            mControlDevice.Bind(std::move(channel));
+            status = mControlDevice->ConnectSysmem(mSysmemAllocator.NewRequest().TakeChannel());
             if (status != ZX_OK) {
                 ALOGE("failed to get sysmem connection, status %d", status);
                 abort();
@@ -1754,18 +1755,19 @@
 
                 collection->Close();
 
-                zx_handle_t vmo_copy;
-                status = zx_handle_duplicate(vmo_handle, ZX_RIGHT_SAME_RIGHTS, &vmo_copy);
+                zx::vmo vmo_copy;
+                status = zx_handle_duplicate(vmo_handle,
+                                             ZX_RIGHT_SAME_RIGHTS,
+                                             vmo_copy.reset_and_get_address());
                 if (status != ZX_OK) {
                     ALOGE("Failed to duplicate VMO: %d", status);
                     abort();
                 }
-                status = fuchsia_hardware_goldfish_control_DeviceCreateColorBuffer(
-                    mControlDevice,
-                    vmo_copy,
+                status = mControlDevice->CreateColorBuffer(
+                    std::move(vmo_copy),
                     imageCreateInfo.extent.width,
                     imageCreateInfo.extent.height,
-                    fuchsia_hardware_goldfish_control_FormatType_BGRA,
+                    fuchsia::hardware::goldfish::control::FormatType::BGRA,
                     &status2);
                 if (status != ZX_OK || status2 != ZX_OK) {
                     ALOGE("CreateColorBuffer failed: %d:%d", status, status2);
@@ -1775,17 +1777,17 @@
         }
 
         if (vmo_handle != ZX_HANDLE_INVALID) {
-            zx_handle_t vmo_copy;
+            zx::vmo vmo_copy;
             zx_status_t status = zx_handle_duplicate(vmo_handle,
                                                      ZX_RIGHT_SAME_RIGHTS,
-                                                     &vmo_copy);
+                                                     vmo_copy.reset_and_get_address());
             if (status != ZX_OK) {
                 ALOGE("Failed to duplicate VMO: %d", status);
                 abort();
             }
             zx_status_t status2 = ZX_OK;
-            status = fuchsia_hardware_goldfish_control_DeviceGetColorBuffer(
-                mControlDevice, vmo_copy, &status2, &importCbInfo.colorBuffer);
+            status = mControlDevice->GetColorBuffer(
+                std::move(vmo_copy), &status2, &importCbInfo.colorBuffer);
             if (status != ZX_OK || status2 != ZX_OK) {
                 ALOGE("GetColorBuffer failed: %d:%d", status, status2);
             }
@@ -2173,27 +2175,26 @@
             auto collection = reinterpret_cast<fuchsia::sysmem::BufferCollectionSyncPtr*>(
                 extBufferCollectionPtr->collection);
             uint32_t index = extBufferCollectionPtr->index;
-            zx_handle_t vmo_handle = ZX_HANDLE_INVALID;
+            zx::vmo vmo;
 
             fuchsia::sysmem::BufferCollectionInfo_2 info;
             zx_status_t status2;
             zx_status_t status = (*collection)->WaitForBuffersAllocated(&status2, &info);
             if (status == ZX_OK && status2 == ZX_OK) {
                 if (index < info.buffer_count) {
-                    vmo_handle = info.buffers[index].vmo.release();
+                    vmo = std::move(info.buffers[index].vmo);
                 }
             } else {
                 ALOGE("WaitForBuffersAllocated failed: %d %d", status, status2);
             }
 
-            if (vmo_handle != ZX_HANDLE_INVALID) {
+            if (vmo.is_valid()) {
                 zx_status_t status2 = ZX_OK;
-                status = fuchsia_hardware_goldfish_control_DeviceCreateColorBuffer(
-                    mControlDevice,
-                    vmo_handle,
+                status = mControlDevice->CreateColorBuffer(
+                    std::move(vmo),
                     localCreateInfo.extent.width,
                     localCreateInfo.extent.height,
-                    fuchsia_hardware_goldfish_control_FormatType_BGRA,
+                    fuchsia::hardware::goldfish::control::FormatType::BGRA,
                     &status2);
                 if (status != ZX_OK || status2 != ZX_OK) {
                     ALOGE("CreateColorBuffer failed: %d:%d", status, status2);
@@ -3202,7 +3203,7 @@
     int mSyncDeviceFd = -1;
 
 #ifdef VK_USE_PLATFORM_FUCHSIA
-    zx_handle_t mControlDevice = ZX_HANDLE_INVALID;
+    fuchsia::hardware::goldfish::control::DeviceSyncPtr mControlDevice;
     fuchsia::sysmem::AllocatorSyncPtr mSysmemAllocator;
 #endif
 };