OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef GPU_VULKAN_VULKAN_SWAP_CHAIN_H_ |
| 6 #define GPU_VULKAN_VULKAN_SWAP_CHAIN_H_ |
| 7 |
| 8 #include <vulkan/vulkan.h> |
| 9 #include <vector> |
| 10 |
| 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "gpu/vulkan/vulkan_export.h" |
| 13 #include "ui/gfx/geometry/size.h" |
| 14 #include "ui/gfx/swap_result.h" |
| 15 |
| 16 namespace gpu { |
| 17 |
| 18 class VulkanCommandBuffer; |
| 19 class VulkanCommandPool; |
| 20 class VulkanImageView; |
| 21 |
| 22 class VulkanSwapChain { |
| 23 public: |
| 24 VulkanSwapChain(); |
| 25 ~VulkanSwapChain(); |
| 26 |
| 27 bool Initialize(VkSurfaceKHR surface, |
| 28 const VkSurfaceCapabilitiesKHR& surface_caps, |
| 29 const VkSurfaceFormatKHR& surface_format); |
| 30 void Destroy(); |
| 31 |
| 32 gfx::SwapResult SwapBuffers(); |
| 33 |
| 34 uint32_t num_images() const { return static_cast<uint32_t>(images_.size()); } |
| 35 uint32_t current_image() const { return current_image_; } |
| 36 const gfx::Size& size() const { return size_; } |
| 37 |
| 38 VulkanImageView* GetImageView(uint32_t index) const { |
| 39 DCHECK_LT(index, images_.size()); |
| 40 return images_[index]->image_view.get(); |
| 41 } |
| 42 |
| 43 VulkanImageView* GetCurrentImageView() const { |
| 44 return GetImageView(current_image_); |
| 45 } |
| 46 |
| 47 VulkanCommandBuffer* GetCurrentCommandBuffer() const { |
| 48 DCHECK_LT(current_image_, images_.size()); |
| 49 return images_[current_image_]->command_buffer.get(); |
| 50 } |
| 51 |
| 52 private: |
| 53 bool InitializeSwapChain(VkSurfaceKHR surface, |
| 54 const VkSurfaceCapabilitiesKHR& surface_caps, |
| 55 const VkSurfaceFormatKHR& surface_format); |
| 56 void DestroySwapChain(); |
| 57 |
| 58 bool InitializeImageLayoutCommandBuffer(); |
| 59 void DestroyImageLayoutCommandBuffer(); |
| 60 |
| 61 bool InitializeSwapImages(const VkSurfaceCapabilitiesKHR& surface_caps, |
| 62 const VkSurfaceFormatKHR& surface_format); |
| 63 void DestroySwapImages(); |
| 64 |
| 65 bool InitializeInitialBuffer(); |
| 66 |
| 67 VkSwapchainKHR swap_chain_ = VK_NULL_HANDLE; |
| 68 |
| 69 scoped_ptr<VulkanCommandPool> command_pool_; |
| 70 |
| 71 gfx::Size size_; |
| 72 |
| 73 struct ImageData { |
| 74 ImageData(); |
| 75 ~ImageData(); |
| 76 |
| 77 VkImage image = VK_NULL_HANDLE; |
| 78 scoped_ptr<VulkanImageView> image_view; |
| 79 scoped_ptr<VulkanCommandBuffer> command_buffer; |
| 80 |
| 81 VkSemaphore render_semaphore = VK_NULL_HANDLE; |
| 82 VkSemaphore present_semaphore = VK_NULL_HANDLE; |
| 83 }; |
| 84 std::vector<scoped_ptr<ImageData>> images_; |
| 85 uint32_t current_image_ = 0; |
| 86 }; |
| 87 |
| 88 } // namespace gpu |
| 89 |
| 90 #endif // GPU_VULKAN_VULKAN_SWAP_CHAIN_H_ |
OLD | NEW |