Index: tools/viewer/sk_app/android/VulkanWindowContext_android.cpp |
diff --git a/tools/viewer/sk_app/android/VulkanWindowContext_android.cpp b/tools/viewer/sk_app/android/VulkanWindowContext_android.cpp |
index 15dc0b02f049a44c873814ab3376976f0307e289..68f2051f3aa636ef9730b335dc372cb7f5c18eb2 100644 |
--- a/tools/viewer/sk_app/android/VulkanWindowContext_android.cpp |
+++ b/tools/viewer/sk_app/android/VulkanWindowContext_android.cpp |
@@ -6,43 +6,47 @@ |
* found in the LICENSE file. |
*/ |
+#include "WindowContextFactory_android.h" |
#include "../VulkanWindowContext.h" |
-#include "WindowContext_android.h" |
- |
-#include "vk/GrVkInterface.h" |
-#include "vk/GrVkUtil.h" |
namespace sk_app { |
-VkSurfaceKHR VulkanWindowContext::createVkSurface(VkInstance instance, void* platformData) { |
- static PFN_vkCreateAndroidSurfaceKHR createAndroidSurfaceKHR = nullptr; |
- if (!createAndroidSurfaceKHR) { |
- createAndroidSurfaceKHR = (PFN_vkCreateAndroidSurfaceKHR)vkGetInstanceProcAddr(instance, |
- "vkCreateAndroidSurfaceKHR"); |
- } |
- |
- if (!platformData) { |
- return VK_NULL_HANDLE; |
+namespace window_context_factory { |
+ |
+WindowContext* NewVulkanForAndroid(ANativeWindow* window, const DisplayParams& params) { |
+ auto createVkSurface = [window] (VkInstance instance) -> VkSurfaceKHR { |
+ static PFN_vkCreateAndroidSurfaceKHR createAndroidSurfaceKHR = nullptr; |
+ if (!createAndroidSurfaceKHR) { |
+ createAndroidSurfaceKHR = (PFN_vkCreateAndroidSurfaceKHR)vkGetInstanceProcAddr( |
+ instance, "vkCreateAndroidSurfaceKHR"); |
+ } |
+ |
+ if (!window) { |
+ return VK_NULL_HANDLE; |
+ } |
+ VkSurfaceKHR surface; |
+ |
+ VkAndroidSurfaceCreateInfoKHR surfaceCreateInfo; |
+ memset(&surfaceCreateInfo, 0, sizeof(VkAndroidSurfaceCreateInfoKHR)); |
+ surfaceCreateInfo.sType = VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR; |
+ surfaceCreateInfo.pNext = nullptr; |
+ surfaceCreateInfo.flags = 0; |
+ surfaceCreateInfo.window = window; |
+ |
+ VkResult res = createAndroidSurfaceKHR(instance, &surfaceCreateInfo, |
+ nullptr, &surface); |
+ return (VK_SUCCESS == res) ? surface : VK_NULL_HANDLE; |
+ }; |
+ |
+ auto canPresent = [](VkInstance, VkPhysicalDevice, uint32_t) { return true; }; |
+ |
+ WindowContext* ctx = new VulkanWindowContext(params, createVkSurface, canPresent); |
+ if (!ctx->isValid()) { |
+ delete ctx; |
+ return nullptr; |
} |
- ContextPlatformData_android* androidPlatformData = |
- reinterpret_cast<ContextPlatformData_android*>(platformData); |
- VkSurfaceKHR surface; |
- |
- VkAndroidSurfaceCreateInfoKHR surfaceCreateInfo; |
- memset(&surfaceCreateInfo, 0, sizeof(VkAndroidSurfaceCreateInfoKHR)); |
- surfaceCreateInfo.sType = VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR; |
- surfaceCreateInfo.pNext = nullptr; |
- surfaceCreateInfo.flags = 0; |
- surfaceCreateInfo.window = androidPlatformData->fNativeWindow; |
- |
- VkResult res = createAndroidSurfaceKHR(instance, &surfaceCreateInfo, |
- nullptr, &surface); |
- return (VK_SUCCESS == res) ? surface : VK_NULL_HANDLE; |
-} |
- |
-bool VulkanWindowContext::canPresent(VkInstance instance, VkPhysicalDevice physDev, |
- uint32_t queueFamilyIndex, void*) { |
- return true; |
+ return ctx; |
} |
-} // namespace sk_app |
+} // namespace window_context_factory |
+} // namespace sk_app |