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 InitializeSwapImages(const VkSurfaceCapabilitiesKHR& surface_caps, |
| 59 const VkSurfaceFormatKHR& surface_format); |
| 60 void DestroySwapImages(); |
| 61 |
| 62 VkSwapchainKHR swap_chain_ = VK_NULL_HANDLE; |
| 63 |
| 64 scoped_ptr<VulkanCommandPool> command_pool_; |
| 65 |
| 66 gfx::Size size_; |
| 67 |
| 68 struct ImageData { |
| 69 ImageData(); |
| 70 ~ImageData(); |
| 71 |
| 72 VkImage image = VK_NULL_HANDLE; |
| 73 scoped_ptr<VulkanImageView> image_view; |
| 74 scoped_ptr<VulkanCommandBuffer> command_buffer; |
| 75 |
| 76 VkSemaphore render_semaphore = VK_NULL_HANDLE; |
| 77 VkSemaphore present_semaphore = VK_NULL_HANDLE; |
| 78 }; |
| 79 std::vector<scoped_ptr<ImageData>> images_; |
| 80 uint32_t current_image_ = 0; |
| 81 |
| 82 VkSemaphore next_present_semaphore_ = VK_NULL_HANDLE; |
| 83 }; |
| 84 |
| 85 } // namespace gpu |
| 86 |
| 87 #endif // GPU_VULKAN_VULKAN_SWAP_CHAIN_H_ |
OLD | NEW |