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/NullBackend.h" 19 20 #include <memory> 21 22 namespace utils { 23 24 class NullBinding : public BackendBinding { 25 public: NullBinding(GLFWwindow * window,WGPUDevice device)26 NullBinding(GLFWwindow* window, WGPUDevice device) : BackendBinding(window, device) { 27 } 28 GetSwapChainImplementation()29 uint64_t GetSwapChainImplementation() override { 30 if (mSwapchainImpl.userData == nullptr) { 31 mSwapchainImpl = dawn_native::null::CreateNativeSwapChainImpl(); 32 } 33 return reinterpret_cast<uint64_t>(&mSwapchainImpl); 34 } GetPreferredSwapChainTextureFormat()35 WGPUTextureFormat GetPreferredSwapChainTextureFormat() override { 36 return WGPUTextureFormat_RGBA8Unorm; 37 } 38 39 private: 40 DawnSwapChainImplementation mSwapchainImpl = {}; 41 }; 42 CreateNullBinding(GLFWwindow * window,WGPUDevice device)43 BackendBinding* CreateNullBinding(GLFWwindow* window, WGPUDevice device) { 44 return new NullBinding(window, device); 45 } 46 47 } // namespace utils 48