Chromium Code Reviews| 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_surface.h" | 5 #include "gpu/vulkan/vulkan_surface.h" |
| 6 | 6 |
| 7 #include <vulkan/vulkan.h> | 7 #include <vulkan/vulkan.h> |
| 8 | 8 |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "gpu/vulkan/vulkan_command_buffer.h" | 10 #include "gpu/vulkan/vulkan_command_buffer.h" |
| 11 #include "gpu/vulkan/vulkan_device_queue.h" | 11 #include "gpu/vulkan/vulkan_device_queue.h" |
| 12 #include "gpu/vulkan/vulkan_implementation.h" | 12 #include "gpu/vulkan/vulkan_implementation.h" |
| 13 #include "gpu/vulkan/vulkan_platform.h" | 13 #include "gpu/vulkan/vulkan_platform.h" |
| 14 #include "gpu/vulkan/vulkan_swap_chain.h" | 14 #include "gpu/vulkan/vulkan_swap_chain.h" |
| 15 | 15 |
| 16 #if defined(USE_X11) | 16 #if defined(USE_X11) |
| 17 #include "ui/gfx/x/x11_types.h" | 17 #include "ui/gfx/x/x11_types.h" |
| 18 #endif // defined(USE_X11) | 18 #endif // defined(USE_X11) |
| 19 | 19 |
| 20 namespace gpu { | 20 namespace gpu { |
| 21 | 21 |
| 22 namespace { | 22 namespace { |
| 23 const VkFormat kNativeVkFormat[] = { | 23 const VkFormat kNativeVkFormat[] = { |
| 24 VK_FORMAT_B8G8R8A8_UNORM, // FORMAT_BGRA8888, | 24 VK_FORMAT_B8G8R8A8_UNORM, // FORMAT_BGRA8888, |
| 25 VK_FORMAT_R8G8B8A8_UNORM, // FORMAT_RGBA8888, | |
| 25 VK_FORMAT_R5G6B5_UNORM_PACK16, // FORMAT_RGB565, | 26 VK_FORMAT_R5G6B5_UNORM_PACK16, // FORMAT_RGB565, |
| 26 }; | 27 }; |
| 27 static_assert(arraysize(kNativeVkFormat) == VulkanSurface::NUM_SURFACE_FORMATS, | 28 static_assert(arraysize(kNativeVkFormat) == |
| 29 VulkanSurface::NUM_SURFACE_FORMATS + 1, | |
| 28 "Array size for kNativeVkFormat must match surface formats."); | 30 "Array size for kNativeVkFormat must match surface formats."); |
| 29 | 31 |
| 30 } // namespace | 32 } // namespace |
| 31 | 33 |
| 32 class VulkanWSISurface : public VulkanSurface { | 34 class VulkanWSISurface : public VulkanSurface { |
| 33 public: | 35 public: |
| 34 explicit VulkanWSISurface(gfx::AcceleratedWidget window) : window_(window) {} | 36 explicit VulkanWSISurface(gfx::AcceleratedWidget window) : window_(window) {} |
| 35 | 37 |
| 36 ~VulkanWSISurface() override { | 38 ~VulkanWSISurface() override { |
| 37 DCHECK_EQ(static_cast<VkSurfaceKHR>(VK_NULL_HANDLE), surface_); | 39 DCHECK_EQ(static_cast<VkSurfaceKHR>(VK_NULL_HANDLE), surface_); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 87 std::vector<VkSurfaceFormatKHR> formats(format_count); | 89 std::vector<VkSurfaceFormatKHR> formats(format_count); |
| 88 result = vkGetPhysicalDeviceSurfaceFormatsKHR( | 90 result = vkGetPhysicalDeviceSurfaceFormatsKHR( |
| 89 device_queue_->GetVulkanPhysicalDevice(), surface_, &format_count, | 91 device_queue_->GetVulkanPhysicalDevice(), surface_, &format_count, |
| 90 formats.data()); | 92 formats.data()); |
| 91 if (VK_SUCCESS != result) { | 93 if (VK_SUCCESS != result) { |
| 92 DLOG(ERROR) << "vkGetPhysicalDeviceSurfaceFormatsKHR() failed: " | 94 DLOG(ERROR) << "vkGetPhysicalDeviceSurfaceFormatsKHR() failed: " |
| 93 << result; | 95 << result; |
| 94 return false; | 96 return false; |
| 95 } | 97 } |
| 96 | 98 |
| 97 const VkFormat preferred_format = kNativeVkFormat[format]; | 99 const VkFormat preferred_format = kNativeVkFormat[format]; |
|
piman
2016/05/10 19:52:44
nit: this is not used anymore, please remove.
sohanjg
2016/05/11 09:25:50
Acknowledged.
| |
| 100 | |
| 101 std::vector<VkFormat> preferred_formats(VulkanSurface::NUM_SURFACE_FORMATS); | |
| 102 if (format == VulkanSurface::Format::FORMAT_RGBA_32) { | |
| 103 preferred_formats[0] = kNativeVkFormat[format]; | |
| 104 preferred_formats[1] = kNativeVkFormat[format + 1]; | |
| 105 } else if (format == VulkanSurface::Format::FORMAT_RGB_16) { | |
| 106 preferred_formats[0] = kNativeVkFormat[format + 1]; | |
| 107 } | |
|
piman
2016/05/10 19:52:44
I think we could instead have 2 arrays, kPreferred
sohanjg
2016/05/11 09:25:50
Done.
| |
| 108 | |
| 98 if (formats.size() == 1 && VK_FORMAT_UNDEFINED == formats[0].format) { | 109 if (formats.size() == 1 && VK_FORMAT_UNDEFINED == formats[0].format) { |
| 99 surface_format_.format = preferred_format; | 110 surface_format_.format = preferred_formats[0]; |
| 100 surface_format_.colorSpace = VK_COLORSPACE_SRGB_NONLINEAR_KHR; | 111 surface_format_.colorSpace = VK_COLORSPACE_SRGB_NONLINEAR_KHR; |
| 101 } else { | 112 } else { |
| 102 bool format_set = false; | 113 bool format_set = false; |
| 103 for (VkSurfaceFormatKHR supported_format : formats) { | 114 for (VkSurfaceFormatKHR supported_format : formats) { |
| 104 if (supported_format.format == preferred_format) { | 115 for (VkFormat fmt : preferred_formats) { |
| 105 surface_format_ = supported_format; | 116 if (supported_format.format == fmt) { |
| 106 surface_format_.colorSpace = VK_COLORSPACE_SRGB_NONLINEAR_KHR; | 117 surface_format_ = supported_format; |
| 107 format_set = true; | 118 surface_format_.colorSpace = VK_COLORSPACE_SRGB_NONLINEAR_KHR; |
| 108 break; | 119 format_set = true; |
| 120 break; | |
| 121 } | |
| 109 } | 122 } |
| 110 } | 123 } |
| 111 if (!format_set) { | 124 if (!format_set) { |
| 112 DLOG(ERROR) << "Format not supported."; | 125 DLOG(ERROR) << "Format not supported."; |
| 113 return false; | 126 return false; |
| 114 } | 127 } |
| 115 } | 128 } |
| 116 | 129 |
| 117 // Get Surface Information. | 130 // Get Surface Information. |
| 118 VkSurfaceCapabilitiesKHR surface_caps; | 131 VkSurfaceCapabilitiesKHR surface_caps; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 162 | 175 |
| 163 // static | 176 // static |
| 164 std::unique_ptr<VulkanSurface> VulkanSurface::CreateViewSurface( | 177 std::unique_ptr<VulkanSurface> VulkanSurface::CreateViewSurface( |
| 165 gfx::AcceleratedWidget window) { | 178 gfx::AcceleratedWidget window) { |
| 166 return std::unique_ptr<VulkanSurface>(new VulkanWSISurface(window)); | 179 return std::unique_ptr<VulkanSurface>(new VulkanWSISurface(window)); |
| 167 } | 180 } |
| 168 | 181 |
| 169 VulkanSurface::VulkanSurface() {} | 182 VulkanSurface::VulkanSurface() {} |
| 170 | 183 |
| 171 } // namespace gpu | 184 } // namespace gpu |
| OLD | NEW |