Tighten up race condition risk in VulkanManager.

Checking for mDevice != null risks using inconsistent state if the
HardwareBufferUpload thread and the render thread race in setting up
vulkan. Instead, use an atomic bool and std::call_once to manage
initiaizing VulkanManager instances.

Bug: 280178674
Test: builds, boots
Change-Id: Ic0a1c3ae1939ece536eb57de369232b213236d11
diff --git a/libs/hwui/renderthread/VulkanManager.h b/libs/hwui/renderthread/VulkanManager.h
index 2be1ffd..dbef7fb 100644
--- a/libs/hwui/renderthread/VulkanManager.h
+++ b/libs/hwui/renderthread/VulkanManager.h
@@ -70,7 +70,7 @@
     void initialize();
 
     // Quick check to see if the VulkanManager has been initialized.
-    bool hasVkContext() { return mDevice != VK_NULL_HANDLE; }
+    bool hasVkContext() { return mInitialized; }
 
     // Create and destroy functions for wrapping an ANativeWindow in a VulkanSurface
     VulkanSurface* createSurface(ANativeWindow* window,
@@ -204,7 +204,8 @@
     VkSemaphore mSwapSemaphore = VK_NULL_HANDLE;
     void* mDestroySemaphoreContext = nullptr;
 
-    std::mutex mInitializeLock;
+    std::once_flag mInitFlag;
+    std::atomic_bool mInitialized = false;
 };
 
 } /* namespace renderthread */