Index: gpu/vulkan/vulkan_surface.cc |
diff --git a/gpu/vulkan/vulkan_surface.cc b/gpu/vulkan/vulkan_surface.cc |
index 63e01c36c32c42dfbb2c86453760d6214846d9b5..4344362ed9f981ecee23bf55aebe25d91ce65ed4 100644 |
--- a/gpu/vulkan/vulkan_surface.cc |
+++ b/gpu/vulkan/vulkan_surface.cc |
@@ -20,12 +20,14 @@ |
namespace gpu { |
namespace { |
-const VkFormat kNativeVkFormat[] = { |
- VK_FORMAT_B8G8R8A8_UNORM, // FORMAT_BGRA8888, |
+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, |
- "Array size for kNativeVkFormat must match surface formats."); |
} // namespace |
@@ -94,19 +96,30 @@ class VulkanWSISurface : public VulkanSurface { |
return false; |
} |
- const VkFormat preferred_format = kNativeVkFormat[format]; |
+ const VkFormat* preferred_formats = (format == FORMAT_RGBA_32) |
+ ? kPreferredVkFormats32 |
+ : kPreferredVkFormats16; |
+ unsigned int size = (format == FORMAT_RGBA_32) |
+ ? arraysize(kPreferredVkFormats32) |
+ : arraysize(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; |
+ unsigned int counter = 0; |
+ while (counter < size && format_set == false) { |
+ if (supported_format.format == preferred_formats[counter]) { |
+ 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."; |