Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(66)

Unified Diff: tools/viewer/sk_app/win/VulkanWindowContext_win.cpp

Issue 2169543002: Use Windowing system-specific WindowContext factories. (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: more xlib Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/viewer/sk_app/win/GLWindowContext_win.cpp ('k') | tools/viewer/sk_app/win/WindowContextFactory_win.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/viewer/sk_app/win/VulkanWindowContext_win.cpp
diff --git a/tools/viewer/sk_app/win/VulkanWindowContext_win.cpp b/tools/viewer/sk_app/win/VulkanWindowContext_win.cpp
index e4251b88cfca6063de433752a7487c2d49b47cb3..521a1ee3cd8f1d5d2963d56ce46c181c01d3b239 100644
--- a/tools/viewer/sk_app/win/VulkanWindowContext_win.cpp
+++ b/tools/viewer/sk_app/win/VulkanWindowContext_win.cpp
@@ -6,6 +6,9 @@
* found in the LICENSE file.
*/
+#include <Windows.h>
+#include "WindowContextFactory_win.h"
+
#include "../VulkanWindowContext.h"
#include "Window_win.h"
@@ -13,51 +16,56 @@
#include "vk/GrVkUtil.h"
namespace sk_app {
+namespace window_context_factory {
-// Platform dependant call
-VkSurfaceKHR VulkanWindowContext::createVkSurface(VkInstance instance, void* platformData) {
- static PFN_vkCreateWin32SurfaceKHR createWin32SurfaceKHR = nullptr;
- if (!createWin32SurfaceKHR) {
- createWin32SurfaceKHR = (PFN_vkCreateWin32SurfaceKHR) vkGetInstanceProcAddr(instance,
- "vkCreateWin32SurfaceKHR");
- }
+WindowContext* NewVulkanForWin(HWND hwnd, const DisplayParams& params) {
+ auto createVkSurface = [hwnd] (VkInstance instance) -> VkSurfaceKHR {
+ static PFN_vkCreateWin32SurfaceKHR createWin32SurfaceKHR = nullptr;
+ if (!createWin32SurfaceKHR) {
+ createWin32SurfaceKHR = (PFN_vkCreateWin32SurfaceKHR)
+ vkGetInstanceProcAddr(instance, "vkCreateWin32SurfaceKHR");
+ }
+ HINSTANCE hinstance = GetModuleHandle(0);
+ VkSurfaceKHR surface;
- if (!platformData) {
- return VK_NULL_HANDLE;
- }
- ContextPlatformData_win* winPlatformData =
- reinterpret_cast<ContextPlatformData_win*>(platformData);
- VkSurfaceKHR surface;
-
- VkWin32SurfaceCreateInfoKHR surfaceCreateInfo;
- memset(&surfaceCreateInfo, 0, sizeof(VkWin32SurfaceCreateInfoKHR));
- surfaceCreateInfo.sType = VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR;
- surfaceCreateInfo.pNext = nullptr;
- surfaceCreateInfo.flags = 0;
- surfaceCreateInfo.hinstance = winPlatformData->fHInstance;
- surfaceCreateInfo.hwnd = winPlatformData->fHWnd;
-
- VkResult res = createWin32SurfaceKHR(instance, &surfaceCreateInfo, nullptr, &surface);
- if (VK_SUCCESS != res) {
- return VK_NULL_HANDLE;
- }
+ VkWin32SurfaceCreateInfoKHR surfaceCreateInfo;
+ memset(&surfaceCreateInfo, 0, sizeof(VkWin32SurfaceCreateInfoKHR));
+ surfaceCreateInfo.sType = VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR;
+ surfaceCreateInfo.pNext = nullptr;
+ surfaceCreateInfo.flags = 0;
+ surfaceCreateInfo.hinstance = hinstance;
+ surfaceCreateInfo.hwnd = hwnd;
- return surface;
-}
+ VkResult res = createWin32SurfaceKHR(instance, &surfaceCreateInfo, nullptr, &surface);
+ if (VK_SUCCESS != res) {
+ return VK_NULL_HANDLE;
+ }
-// Platform dependant call
-bool VulkanWindowContext::canPresent(VkInstance instance, VkPhysicalDevice physDev,
- uint32_t queueFamilyIndex, void*) {
- static PFN_vkGetPhysicalDeviceWin32PresentationSupportKHR
+ return surface;
+ };
+
+ auto canPresent = [hwnd] (VkInstance instance, VkPhysicalDevice physDev,
+ uint32_t queueFamilyIndex) {
+ static PFN_vkGetPhysicalDeviceWin32PresentationSupportKHR
getPhysicalDeviceWin32PresentationSupportKHR = nullptr;
- if (!getPhysicalDeviceWin32PresentationSupportKHR) {
- getPhysicalDeviceWin32PresentationSupportKHR =
- (PFN_vkGetPhysicalDeviceWin32PresentationSupportKHR) vkGetInstanceProcAddr(instance,
- "vkGetPhysicalDeviceWin32PresentationSupportKHR");
- }
+ if (!getPhysicalDeviceWin32PresentationSupportKHR) {
+ getPhysicalDeviceWin32PresentationSupportKHR =
+ (PFN_vkGetPhysicalDeviceWin32PresentationSupportKHR)
+ vkGetInstanceProcAddr(instance,
+ "vkGetPhysicalDeviceWin32PresentationSupportKHR");
+ }
- VkBool32 check = getPhysicalDeviceWin32PresentationSupportKHR(physDev, queueFamilyIndex);
- return (VK_FALSE != check);
+ VkBool32 check = getPhysicalDeviceWin32PresentationSupportKHR(physDev, queueFamilyIndex);
+ return (VK_FALSE != check);
+ };
+
+ WindowContext* ctx = new VulkanWindowContext(params, createVkSurface, canPresent);
+ if (!ctx->isValid()) {
+ delete ctx;
+ return nullptr;
+ }
+ return ctx;
}
-} // namespace sk_app
+} // namespace window_context_factory
+} // namespace sk_app
« no previous file with comments | « tools/viewer/sk_app/win/GLWindowContext_win.cpp ('k') | tools/viewer/sk_app/win/WindowContextFactory_win.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698