OLD | NEW |
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "gpu/vulkan/vulkan_swap_chain.h" | 5 #include "gpu/vulkan/vulkan_swap_chain.h" |
6 | 6 |
7 #include "gpu/vulkan/vulkan_command_buffer.h" | 7 #include "gpu/vulkan/vulkan_command_buffer.h" |
8 #include "gpu/vulkan/vulkan_command_pool.h" | 8 #include "gpu/vulkan/vulkan_command_pool.h" |
9 #include "gpu/vulkan/vulkan_device_queue.h" | 9 #include "gpu/vulkan/vulkan_device_queue.h" |
10 #include "gpu/vulkan/vulkan_image_view.h" | 10 #include "gpu/vulkan/vulkan_image_view.h" |
(...skipping 23 matching lines...) Expand all Loading... |
34 DestroySwapImages(); | 34 DestroySwapImages(); |
35 DestroySwapChain(); | 35 DestroySwapChain(); |
36 } | 36 } |
37 | 37 |
38 gfx::SwapResult VulkanSwapChain::SwapBuffers() { | 38 gfx::SwapResult VulkanSwapChain::SwapBuffers() { |
39 VkResult result = VK_SUCCESS; | 39 VkResult result = VK_SUCCESS; |
40 | 40 |
41 VkDevice device = device_queue_->GetVulkanDevice(); | 41 VkDevice device = device_queue_->GetVulkanDevice(); |
42 VkQueue queue = device_queue_->GetVulkanQueue(); | 42 VkQueue queue = device_queue_->GetVulkanQueue(); |
43 | 43 |
44 scoped_ptr<ImageData>& current_image_data = images_[current_image_]; | 44 std::unique_ptr<ImageData>& current_image_data = images_[current_image_]; |
45 | 45 |
46 // Default image subresource range. | 46 // Default image subresource range. |
47 VkImageSubresourceRange image_subresource_range = {}; | 47 VkImageSubresourceRange image_subresource_range = {}; |
48 image_subresource_range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; | 48 image_subresource_range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
49 image_subresource_range.baseMipLevel = 0; | 49 image_subresource_range.baseMipLevel = 0; |
50 image_subresource_range.levelCount = 1; | 50 image_subresource_range.levelCount = 1; |
51 image_subresource_range.baseArrayLayer = 0; | 51 image_subresource_range.baseArrayLayer = 0; |
52 image_subresource_range.layerCount = 1; | 52 image_subresource_range.layerCount = 1; |
53 | 53 |
54 // Submit our command buffer for the current buffer. | 54 // Submit our command buffer for the current buffer. |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 image_memory_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; | 183 image_memory_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; |
184 image_memory_barrier.subresourceRange = image_subresource_range; | 184 image_memory_barrier.subresourceRange = image_subresource_range; |
185 | 185 |
186 command_pool_ = device_queue_->CreateCommandPool(); | 186 command_pool_ = device_queue_->CreateCommandPool(); |
187 if (!command_pool_) | 187 if (!command_pool_) |
188 return false; | 188 return false; |
189 | 189 |
190 images_.resize(image_count); | 190 images_.resize(image_count); |
191 for (uint32_t i = 0; i < image_count; ++i) { | 191 for (uint32_t i = 0; i < image_count; ++i) { |
192 images_[i].reset(new ImageData); | 192 images_[i].reset(new ImageData); |
193 scoped_ptr<ImageData>& image_data = images_[i]; | 193 std::unique_ptr<ImageData>& image_data = images_[i]; |
194 image_data->image = images[i]; | 194 image_data->image = images[i]; |
195 | 195 |
196 // Setup semaphores. | 196 // Setup semaphores. |
197 result = vkCreateSemaphore(device, &semaphore_create_info, nullptr, | 197 result = vkCreateSemaphore(device, &semaphore_create_info, nullptr, |
198 &image_data->render_semaphore); | 198 &image_data->render_semaphore); |
199 if (VK_SUCCESS != result) { | 199 if (VK_SUCCESS != result) { |
200 DLOG(ERROR) << "vkCreateSemaphore(render) failed: " << result; | 200 DLOG(ERROR) << "vkCreateSemaphore(render) failed: " << result; |
201 return false; | 201 return false; |
202 } | 202 } |
203 | 203 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 } | 251 } |
252 | 252 |
253 void VulkanSwapChain::DestroySwapImages() { | 253 void VulkanSwapChain::DestroySwapImages() { |
254 VkDevice device = device_queue_->GetVulkanDevice(); | 254 VkDevice device = device_queue_->GetVulkanDevice(); |
255 | 255 |
256 if (VK_NULL_HANDLE != next_present_semaphore_) { | 256 if (VK_NULL_HANDLE != next_present_semaphore_) { |
257 vkDestroySemaphore(device, next_present_semaphore_, nullptr); | 257 vkDestroySemaphore(device, next_present_semaphore_, nullptr); |
258 next_present_semaphore_ = VK_NULL_HANDLE; | 258 next_present_semaphore_ = VK_NULL_HANDLE; |
259 } | 259 } |
260 | 260 |
261 for (const scoped_ptr<ImageData>& image_data : images_) { | 261 for (const std::unique_ptr<ImageData>& image_data : images_) { |
262 if (image_data->command_buffer) { | 262 if (image_data->command_buffer) { |
263 // Make sure command buffer is done processing. | 263 // Make sure command buffer is done processing. |
264 image_data->command_buffer->Wait(UINT64_MAX); | 264 image_data->command_buffer->Wait(UINT64_MAX); |
265 | 265 |
266 image_data->command_buffer->Destroy(); | 266 image_data->command_buffer->Destroy(); |
267 image_data->command_buffer.reset(); | 267 image_data->command_buffer.reset(); |
268 } | 268 } |
269 | 269 |
270 // Destroy Image View. | 270 // Destroy Image View. |
271 if (image_data->image_view) { | 271 if (image_data->image_view) { |
(...skipping 20 matching lines...) Expand all Loading... |
292 command_pool_->Destroy(); | 292 command_pool_->Destroy(); |
293 command_pool_.reset(); | 293 command_pool_.reset(); |
294 } | 294 } |
295 } | 295 } |
296 | 296 |
297 VulkanSwapChain::ImageData::ImageData() {} | 297 VulkanSwapChain::ImageData::ImageData() {} |
298 | 298 |
299 VulkanSwapChain::ImageData::~ImageData() {} | 299 VulkanSwapChain::ImageData::~ImageData() {} |
300 | 300 |
301 } // namespace gpu | 301 } // namespace gpu |
OLD | NEW |