Index: gpu/vulkan/vulkan_surface.cc |
diff --git a/gpu/vulkan/vulkan_surface.cc b/gpu/vulkan/vulkan_surface.cc |
index 63e01c36c32c42dfbb2c86453760d6214846d9b5..6c07d31af807a6b02dd207d84a593a0aa22d08cf 100644 |
--- a/gpu/vulkan/vulkan_surface.cc |
+++ b/gpu/vulkan/vulkan_surface.cc |
@@ -22,9 +22,21 @@ namespace gpu { |
namespace { |
const VkFormat kNativeVkFormat[] = { |
piman
2016/05/11 17:11:56
This is not used anymore, please remove.
sohanjg
2016/05/12 06:34:30
Done.
|
VK_FORMAT_B8G8R8A8_UNORM, // FORMAT_BGRA8888, |
+ VK_FORMAT_R8G8B8A8_UNORM, // FORMAT_RGBA8888, |
VK_FORMAT_R5G6B5_UNORM_PACK16, // FORMAT_RGB565, |
}; |
-static_assert(arraysize(kNativeVkFormat) == VulkanSurface::NUM_SURFACE_FORMATS, |
+ |
+const VkFormat kPreferredVkFormats32[] = { |
+ VK_FORMAT_B8G8R8A8_UNORM, // FORMAT_BGRA8888, |
+ VK_FORMAT_R8G8B8A8_UNORM, // FORMAT_RGBA8888, |
+}; |
+ |
+const VkFormat kPreferredVkFormats16[] = { |
+ VK_FORMAT_R5G6B5_UNORM_PACK16, // FORMAT_RGB565, |
+}; |
+ |
+static_assert(arraysize(kNativeVkFormat) == |
+ VulkanSurface::NUM_SURFACE_FORMATS + 1, |
"Array size for kNativeVkFormat must match surface formats."); |
} // namespace |
@@ -94,19 +106,30 @@ class VulkanWSISurface : public VulkanSurface { |
return false; |
} |
- const VkFormat preferred_format = kNativeVkFormat[format]; |
+ const VkFormat* preferred_formats = (format == FORMAT_RGBA_32) |
+ ? kPreferredVkFormats32 |
+ : kPreferredVkFormats16; |
+ |
if (formats.size() == 1 && VK_FORMAT_UNDEFINED == formats[0].format) { |
- surface_format_.format = preferred_format; |
+ surface_format_.format = preferred_formats[0]; |
surface_format_.colorSpace = VK_COLORSPACE_SRGB_NONLINEAR_KHR; |
} else { |
bool format_set = false; |
for (VkSurfaceFormatKHR supported_format : formats) { |
- if (supported_format.format == preferred_format) { |
- surface_format_ = supported_format; |
- surface_format_.colorSpace = VK_COLORSPACE_SRGB_NONLINEAR_KHR; |
- format_set = true; |
- break; |
+ uint counter = 0; |
piman
2016/05/11 17:11:56
nit: uint->unsigned int
sohanjg
2016/05/12 06:34:30
Done.
|
+ uint size = (format == FORMAT_RGBA_32) |
piman
2016/05/11 17:11:56
nit: uint->unsigned int. This can be hoisted out o
sohanjg
2016/05/12 06:34:30
Done.
|
+ ? arraysize(kPreferredVkFormats32) |
+ : arraysize(kPreferredVkFormats16); |
+ while (counter < size && format_set == false) { |
+ if (supported_format.format == *(preferred_formats + counter)) { |
piman
2016/05/11 17:11:56
nit: *(preferred_formats + counter) -> preferred_f
sohanjg
2016/05/12 06:34:30
Done.
|
+ surface_format_ = supported_format; |
+ surface_format_.colorSpace = VK_COLORSPACE_SRGB_NONLINEAR_KHR; |
+ format_set = true; |
+ } |
+ counter++; |
} |
+ if (format_set) |
+ break; |
} |
if (!format_set) { |
DLOG(ERROR) << "Format not supported."; |