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_VULKAN_NATIVESWAPCHAINIMPLVK_H_ 16 #define DAWNNATIVE_VULKAN_NATIVESWAPCHAINIMPLVK_H_ 17 18 #include "dawn_native/vulkan/VulkanInfo.h" 19 20 #include "dawn/dawn_wsi.h" 21 #include "dawn_native/dawn_platform.h" 22 23 namespace dawn_native { namespace vulkan { 24 25 class Device; 26 27 class NativeSwapChainImpl { 28 public: 29 using WSIContext = DawnWSIContextVulkan; 30 31 NativeSwapChainImpl(Device* device, VkSurfaceKHR surface); 32 ~NativeSwapChainImpl(); 33 34 void Init(DawnWSIContextVulkan* context); 35 DawnSwapChainError Configure(WGPUTextureFormat format, 36 WGPUTextureUsage, 37 uint32_t width, 38 uint32_t height); 39 DawnSwapChainError GetNextTexture(DawnSwapChainNextTexture* nextTexture); 40 DawnSwapChainError Present(); 41 42 wgpu::TextureFormat GetPreferredFormat() const; 43 44 struct ChosenConfig { 45 VkFormat nativeFormat; 46 wgpu::TextureFormat format; 47 VkColorSpaceKHR colorSpace; 48 VkSurfaceTransformFlagBitsKHR preTransform; 49 uint32_t minImageCount; 50 VkPresentModeKHR presentMode; 51 VkCompositeAlphaFlagBitsKHR compositeAlpha; 52 }; 53 54 private: 55 void UpdateSurfaceConfig(); 56 57 VkSurfaceKHR mSurface = VK_NULL_HANDLE; 58 VkSwapchainKHR mSwapChain = VK_NULL_HANDLE; 59 std::vector<VkImage> mSwapChainImages; 60 uint32_t mLastImageIndex = 0; 61 62 VulkanSurfaceInfo mInfo; 63 64 ChosenConfig mConfig; 65 66 Device* mDevice = nullptr; 67 }; 68 69 }} // namespace dawn_native::vulkan 70 71 #endif // DAWNNATIVE_VULKAN_NATIVESWAPCHAINIMPLVK_H_ 72