GDK/Win32: Support Vulkan context creation

This adds support to the GDK Win32 backend so that we can support Vulkan
context creation for use in the GSK Vulkan renderer, so that we can test
it on Windows platforms as well.

https://bugzilla.gnome.org/show_bug.cgi?id=776544
This commit is contained in:
Chun-wei Fan 2016-12-28 22:25:07 +08:00
parent 1e084567f9
commit c4244ea104
4 changed files with 150 additions and 0 deletions

View File

@ -55,6 +55,8 @@ libgdk_win32_la_SOURCES = \
gdkscreen-win32.c \ gdkscreen-win32.c \
gdkselection-win32.c \ gdkselection-win32.c \
gdktestutils-win32.c \ gdktestutils-win32.c \
gdkvulkancontext-win32.c \
gdkvulkancontext-win32.h \
gdkwin32cursor.h \ gdkwin32cursor.h \
gdkwin32display.h \ gdkwin32display.h \
gdkwin32displaymanager.h \ gdkwin32displaymanager.h \

View File

@ -19,6 +19,7 @@
#include "config.h" #include "config.h"
#define _WIN32_WINNT 0x0600 #define _WIN32_WINNT 0x0600
#define VK_USE_PLATFORM_WIN32_KHR
#include "gdk.h" #include "gdk.h"
#include "gdkprivate-win32.h" #include "gdkprivate-win32.h"
@ -30,6 +31,7 @@
#include "gdkwin32window.h" #include "gdkwin32window.h"
#include "gdkmonitor-win32.h" #include "gdkmonitor-win32.h"
#include "gdkwin32.h" #include "gdkwin32.h"
#include "gdkvulkancontext-win32.h"
#include <dwmapi.h> #include <dwmapi.h>
@ -1282,5 +1284,10 @@ gdk_win32_display_class_init (GdkWin32DisplayClass *klass)
display_class->get_monitor = gdk_win32_display_get_monitor; display_class->get_monitor = gdk_win32_display_get_monitor;
display_class->get_primary_monitor = gdk_win32_display_get_primary_monitor; display_class->get_primary_monitor = gdk_win32_display_get_primary_monitor;
#ifdef GDK_RENDERING_VULKAN
display_class->vk_context_type = GDK_TYPE_WIN32_VULKAN_CONTEXT;
display_class->vk_extension_name = VK_KHR_WIN32_SURFACE_EXTENSION_NAME;
#endif
_gdk_win32_windowing_init (); _gdk_win32_windowing_init ();
} }

View File

@ -0,0 +1,79 @@
/* GDK - The GIMP Drawing Kit
*
* gdkvulkancontext-win32.c: Win32 specific Vulkan wrappers
*
* Copyright © 2016 Benjamin Otte
* Copyright © 2016 Chun-wei Fan
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#include "config.h"
#include "gdkconfig.h"
#ifdef GDK_RENDERING_VULKAN
#include "gdkvulkancontext-win32.h"
#include "gdkprivate-win32.h"
#include "gdkwin32misc.h"
extern HINSTANCE _gdk_dll_hinstance;
G_DEFINE_TYPE (GdkWin32VulkanContext, gdk_win32_vulkan_context, GDK_TYPE_VULKAN_CONTEXT)
static VkResult
gdk_win32_vulkan_context_create_surface (GdkVulkanContext *context,
VkSurfaceKHR *surface)
{
GdkWindow *window = gdk_draw_context_get_window (GDK_DRAW_CONTEXT (context));
GdkDisplay *display = gdk_draw_context_get_display (GDK_DRAW_CONTEXT (context));
VkWin32SurfaceCreateInfoKHR info;
info.sType = VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR;
info.pNext = NULL;
info.flags = 0;
info.hinstance = _gdk_dll_hinstance;
info.hwnd = GDK_WINDOW_HWND (window);
/* This is necessary so that Vulkan sees the Window.
* Usually, vkCreateWin32SurfaceKHR() will not cause a problem to happen as
* it just creates resources, but futher calls with the resulting surface
* do cause issues.
*/
gdk_display_sync (display);
return GDK_VK_CHECK (vkCreateWin32SurfaceKHR,
gdk_vulkan_context_get_instance (context),
&info,
NULL,
surface);
}
static void
gdk_win32_vulkan_context_class_init (GdkWin32VulkanContextClass *klass)
{
GdkVulkanContextClass *context_class = GDK_VULKAN_CONTEXT_CLASS (klass);
context_class->create_surface = gdk_win32_vulkan_context_create_surface;
}
static void
gdk_win32_vulkan_context_init (GdkWin32VulkanContext *self)
{
}
#endif /* GDK_RENDERING_VULKAN */

View File

@ -0,0 +1,62 @@
/* GDK - The GIMP Drawing Kit
*
* gdkvulkancontext-win32.h: Win32 specific Vulkan wrappers
*
* Copyright © 2016 Benjamin Otte
* Copyright © 2016 Chun-wei Fan
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __GDK_WIN32_VULKAN_CONTEXT__
#define __GDK_WIN32_VULKAN_CONTEXT__
#include "gdkconfig.h"
#ifdef GDK_RENDERING_VULKAN
#define VK_USE_PLATFORM_WIN32_KHR
#include "gdkvulkancontextprivate.h"
G_BEGIN_DECLS
#define GDK_TYPE_WIN32_VULKAN_CONTEXT (gdk_win32_vulkan_context_get_type ())
#define GDK_WIN32_VULKAN_CONTEXT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GDK_TYPE_WIN32_VULKAN_CONTEXT, GdkWin32VulkanContext))
#define GDK_IS_WIN32_VULKAN_CONTEXT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GDK_TYPE_WIN32_VULKAN_CONTEXT))
#define GDK_WIN32_VULKAN_CONTEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GDK_TYPE_WIN32_VULKAN_CONTEXT, GdkWin32VulkanContextClass))
#define GDK_IS_WIN32_VULKAN_CONTEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GDK_TYPE_WIN32_VULKAN_CONTEXT))
#define GDK_WIN32_VULKAN_CONTEXT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GDK_TYPE_WIN32_VULKAN_CONTEXT, GdkWin32VulkanContextClass))
typedef struct _GdkWin32VulkanContext GdkWin32VulkanContext;
typedef struct _GdkWin32VulkanContextClass GdkWin32VulkanContextClass;
struct _GdkWin32VulkanContext
{
GdkVulkanContext parent_instance;
};
struct _GdkWin32VulkanContextClass
{
GdkVulkanContextClass parent_class;
};
GDK_AVAILABLE_IN_3_90
GType gdk_win32_vulkan_context_get_type (void) G_GNUC_CONST;
G_END_DECLS
#endif /* !GDK_RENDERING_VULKAN */
#endif /* __GDK_WIN32_VULKAN_CONTEXT__ */