1 // Copyright 2018 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 #ifndef DAWNNATIVE_D3D12_NATIVESWAPCHAINIMPLD3D12_H_ 16 #define DAWNNATIVE_D3D12_NATIVESWAPCHAINIMPLD3D12_H_ 17 18 #include "dawn_native/d3d12/d3d12_platform.h" 19 20 #include "dawn/dawn_wsi.h" 21 #include "dawn_native/IntegerTypes.h" 22 #include "dawn_native/dawn_platform.h" 23 24 #include <vector> 25 26 namespace dawn_native { namespace d3d12 { 27 28 class Device; 29 30 class NativeSwapChainImpl { 31 public: 32 using WSIContext = DawnWSIContextD3D12; 33 34 NativeSwapChainImpl(Device* device, HWND window); 35 ~NativeSwapChainImpl(); 36 37 void Init(DawnWSIContextD3D12* context); 38 DawnSwapChainError Configure(WGPUTextureFormat format, 39 WGPUTextureUsage, 40 uint32_t width, 41 uint32_t height); 42 DawnSwapChainError GetNextTexture(DawnSwapChainNextTexture* nextTexture); 43 DawnSwapChainError Present(); 44 45 wgpu::TextureFormat GetPreferredFormat() const; 46 47 private: 48 HWND mWindow = nullptr; 49 Device* mDevice = nullptr; 50 UINT mInterval; 51 52 ComPtr<IDXGISwapChain3> mSwapChain = nullptr; 53 std::vector<ComPtr<ID3D12Resource>> mBuffers; 54 std::vector<ExecutionSerial> mBufferSerials; 55 uint32_t mCurrentBuffer; 56 }; 57 58 }} // namespace dawn_native::d3d12 59 60 #endif // DAWNNATIVE_D3D12_NATIVESWAPCHAINIMPLD3D12_H_ 61