package org.lwjgl.vulkan.swt;

import static org.lwjgl.system.MemoryUtil.*;
import static org.lwjgl.vulkan.KHRWin32Surface.*;
import static org.lwjgl.vulkan.VK10.*;

import java.nio.LongBuffer;

import org.eclipse.swt.SWTException;
import org.eclipse.swt.internal.win32.OS;
import org.eclipse.swt.widgets.Composite;
import org.lwjgl.vulkan.VkPhysicalDevice;
import org.lwjgl.vulkan.VkWin32SurfaceCreateInfoKHR;

public class PlatformWin32VKCanvas implements PlatformVKCanvas {
    private static final String USE_OWNDC_KEY = "org.eclipse.swt.internal.win32.useOwnDC";

    public int checkStyle(Composite parent, int style) {
        // Somehow we need to temporarily set 'org.eclipse.swt.internal.win32.useOwnDC' to true or else context creation on Windows fails...
        if (parent != null) {
            if (!org.eclipse.swt.internal.win32.OS.IsWinCE
                    && org.eclipse.swt.internal.win32.OS.WIN32_VERSION >= org.eclipse.swt.internal.win32.OS.VERSION(6, 0)) {
                parent.getDisplay().setData(USE_OWNDC_KEY, Boolean.TRUE);
            }
        }
        return style;
    }

    public void resetStyle(Composite parent) {
        parent.getDisplay().setData(USE_OWNDC_KEY, Boolean.FALSE);
    }

    @Override
    public long create(Composite composite, VKData data) {
        VkWin32SurfaceCreateInfoKHR sci = VkWin32SurfaceCreateInfoKHR.calloc();
        sci.sType(VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR);
        sci.hinstance(OS.GetModuleHandle(null));
        sci.hwnd(composite.handle);

        LongBuffer pSurface = memAllocLong(1);
        int err = vkCreateWin32SurfaceKHR(data.instance, sci, null, pSurface);
        long surface = pSurface.get(0);
        memFree(pSurface);
        sci.free();
        if (err != VK_SUCCESS) {
            throw new SWTException("Calling vkCreateWin32SurfaceKHR failed with error: " + err);
        }
        return surface;
    }

    public boolean getPhysicalDevicePresentationSupport(VkPhysicalDevice physicalDevice, int queueFamily) {
        return vkGetPhysicalDeviceWin32PresentationSupportKHR(physicalDevice, queueFamily) == 1;
    }

}

@@ -65,12 +65,13 @@
 mory
-Util
+Stack
 .*;%0A
@@ -1372,20 +1372,25 @@
 R.calloc
+Stack
 ();%0A
-
         
@@ -1534,17 +1534,16 @@
 andle);%0A
-%0A
         
@@ -1568,12 +1568,15 @@
 e = 
-memA
+stackMa
 lloc
@@ -1655,32 +1655,32 @@
 ull, pSurface);%0A
+
         long sur
@@ -1707,55 +1707,8 @@
 0);%0A
-        memFree(pSurface);%0A        sci.free();%0A
     

Modify Vulkan binding to use new LWJGL 3 stack allocation