• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2017 The Dawn Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include "utils/BackendBinding.h"
16 
17 #include "common/Assert.h"
18 #include "dawn_native/VulkanBackend.h"
19 
20 // Include GLFW after VulkanBackend so that it declares the Vulkan-specific functions
21 #include "GLFW/glfw3.h"
22 
23 #include <memory>
24 
25 namespace utils {
26 
27     class VulkanBinding : public BackendBinding {
28       public:
VulkanBinding(GLFWwindow * window,WGPUDevice device)29         VulkanBinding(GLFWwindow* window, WGPUDevice device) : BackendBinding(window, device) {
30         }
31 
GetSwapChainImplementation()32         uint64_t GetSwapChainImplementation() override {
33             if (mSwapchainImpl.userData == nullptr) {
34                 VkSurfaceKHR surface = VK_NULL_HANDLE;
35                 if (glfwCreateWindowSurface(dawn_native::vulkan::GetInstance(mDevice), mWindow,
36                                             nullptr, &surface) != VK_SUCCESS) {
37                     ASSERT(false);
38                 }
39 
40                 mSwapchainImpl = dawn_native::vulkan::CreateNativeSwapChainImpl(mDevice, surface);
41             }
42             return reinterpret_cast<uint64_t>(&mSwapchainImpl);
43         }
GetPreferredSwapChainTextureFormat()44         WGPUTextureFormat GetPreferredSwapChainTextureFormat() override {
45             ASSERT(mSwapchainImpl.userData != nullptr);
46             return dawn_native::vulkan::GetNativeSwapChainPreferredFormat(&mSwapchainImpl);
47         }
48 
49       private:
50         DawnSwapChainImplementation mSwapchainImpl = {};
51     };
52 
CreateVulkanBinding(GLFWwindow * window,WGPUDevice device)53     BackendBinding* CreateVulkanBinding(GLFWwindow* window, WGPUDevice device) {
54         return new VulkanBinding(window, device);
55     }
56 
57 }  // namespace utils
58