2016-04-21 14:59:44 +00:00
|
|
|
|
|
|
|
/*
|
2016-04-21 18:46:23 +00:00
|
|
|
* Copyright 2016 Google Inc.
|
2016-04-21 14:59:44 +00:00
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2016-07-26 19:02:50 +00:00
|
|
|
#include "WindowContextFactory_android.h"
|
2016-06-02 19:16:25 +00:00
|
|
|
#include "../VulkanWindowContext.h"
|
2016-04-21 14:59:44 +00:00
|
|
|
|
2016-05-05 19:32:03 +00:00
|
|
|
namespace sk_app {
|
|
|
|
|
2016-07-26 19:02:50 +00:00
|
|
|
namespace window_context_factory {
|
|
|
|
|
|
|
|
WindowContext* NewVulkanForAndroid(ANativeWindow* window, const DisplayParams& params) {
|
2017-11-10 00:29:45 +00:00
|
|
|
auto createVkSurface = [window] (VkInstance instance) -> VkSurfaceKHR {
|
2016-08-11 15:15:12 +00:00
|
|
|
PFN_vkCreateAndroidSurfaceKHR createAndroidSurfaceKHR =
|
2017-11-10 00:29:45 +00:00
|
|
|
(PFN_vkCreateAndroidSurfaceKHR)vkGetInstanceProcAddr(instance,
|
|
|
|
"vkCreateAndroidSurfaceKHR");
|
2016-07-26 19:02:50 +00:00
|
|
|
|
|
|
|
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; };
|
|
|
|
|
2017-11-10 00:29:45 +00:00
|
|
|
WindowContext* ctx = new VulkanWindowContext(params, createVkSurface, canPresent);
|
2016-07-26 19:02:50 +00:00
|
|
|
if (!ctx->isValid()) {
|
|
|
|
delete ctx;
|
|
|
|
return nullptr;
|
2016-04-21 18:46:23 +00:00
|
|
|
}
|
2016-07-26 19:02:50 +00:00
|
|
|
return ctx;
|
2016-04-21 14:59:44 +00:00
|
|
|
}
|
2016-05-05 19:32:03 +00:00
|
|
|
|
2016-07-26 19:02:50 +00:00
|
|
|
} // namespace window_context_factory
|
|
|
|
} // namespace sk_app
|