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/D3D12Backend.h" 19 20 #include "GLFW/glfw3.h" 21 #define GLFW_EXPOSE_NATIVE_WIN32 22 #include "GLFW/glfw3native.h" 23 24 #include <memory> 25 26 namespace utils { 27 28 class D3D12Binding : public BackendBinding { 29 public: D3D12Binding(GLFWwindow * window,WGPUDevice device)30 D3D12Binding(GLFWwindow* window, WGPUDevice device) : BackendBinding(window, device) { 31 } 32 GetSwapChainImplementation()33 uint64_t GetSwapChainImplementation() override { 34 if (mSwapchainImpl.userData == nullptr) { 35 HWND win32Window = glfwGetWin32Window(mWindow); 36 mSwapchainImpl = 37 dawn_native::d3d12::CreateNativeSwapChainImpl(mDevice, win32Window); 38 } 39 return reinterpret_cast<uint64_t>(&mSwapchainImpl); 40 } 41 GetPreferredSwapChainTextureFormat()42 WGPUTextureFormat GetPreferredSwapChainTextureFormat() override { 43 ASSERT(mSwapchainImpl.userData != nullptr); 44 return dawn_native::d3d12::GetNativeSwapChainPreferredFormat(&mSwapchainImpl); 45 } 46 47 private: 48 DawnSwapChainImplementation mSwapchainImpl = {}; 49 }; 50 CreateD3D12Binding(GLFWwindow * window,WGPUDevice device)51 BackendBinding* CreateD3D12Binding(GLFWwindow* window, WGPUDevice device) { 52 return new D3D12Binding(window, device); 53 } 54 55 } // namespace utils 56