• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_SWAPCHAINVK_H_
16 #define DAWNNATIVE_VULKAN_SWAPCHAINVK_H_
17 
18 #include "dawn_native/SwapChain.h"
19 
20 #include "common/vulkan_platform.h"
21 
22 #include <vector>
23 
24 namespace dawn_native { namespace vulkan {
25 
26     class Device;
27     class Texture;
28     struct VulkanSurfaceInfo;
29 
30     class OldSwapChain : public OldSwapChainBase {
31       public:
32         static Ref<OldSwapChain> Create(Device* device, const SwapChainDescriptor* descriptor);
33 
34       protected:
35         OldSwapChain(Device* device, const SwapChainDescriptor* descriptor);
36         ~OldSwapChain() override;
37 
38         TextureBase* GetNextTextureImpl(const TextureDescriptor* descriptor) override;
39         MaybeError OnBeforePresent(TextureViewBase* texture) override;
40 
41       private:
42         wgpu::TextureUsage mTextureUsage;
43     };
44 
45     class SwapChain : public NewSwapChainBase {
46       public:
47         static ResultOrError<Ref<SwapChain>> Create(Device* device,
48                                                     Surface* surface,
49                                                     NewSwapChainBase* previousSwapChain,
50                                                     const SwapChainDescriptor* descriptor);
51         ~SwapChain() override;
52 
53       private:
54         using NewSwapChainBase::NewSwapChainBase;
55         MaybeError Initialize(NewSwapChainBase* previousSwapChain);
56         void DestroyImpl() override;
57 
58         struct Config {
59             // Information that's passed to vulkan swapchain creation.
60             VkPresentModeKHR presentMode;
61             VkExtent2D extent;
62             VkImageUsageFlags usage;
63             VkFormat format;
64             VkColorSpaceKHR colorSpace;
65             uint32_t targetImageCount;
66             VkSurfaceTransformFlagBitsKHR transform;
67             VkCompositeAlphaFlagBitsKHR alphaMode;
68 
69             // Redundant information but as WebGPU enums to create the wgpu::Texture that
70             // encapsulates the native swapchain texture.
71             wgpu::TextureUsage wgpuUsage;
72             wgpu::TextureFormat wgpuFormat;
73 
74             // Information about the blit workarounds we need to do (if any)
75             bool needsBlit = false;
76         };
77         ResultOrError<Config> ChooseConfig(const VulkanSurfaceInfo& surfaceInfo) const;
78         ResultOrError<TextureViewBase*> GetCurrentTextureViewInternal(bool isReentrant = false);
79 
80         // NewSwapChainBase implementation
81         MaybeError PresentImpl() override;
82         ResultOrError<TextureViewBase*> GetCurrentTextureViewImpl() override;
83         void DetachFromSurfaceImpl() override;
84 
85         Config mConfig;
86 
87         VkSurfaceKHR mVkSurface = VK_NULL_HANDLE;
88         VkSwapchainKHR mSwapChain = VK_NULL_HANDLE;
89         std::vector<VkImage> mSwapChainImages;
90         uint32_t mLastImageIndex = 0;
91 
92         Ref<Texture> mBlitTexture;
93         Ref<Texture> mTexture;
94     };
95 
96 }}  // namespace dawn_native::vulkan
97 
98 #endif  // DAWNNATIVE_VULKAN_SWAPCHAINVK_H_
99