Commit a0031165 authored by Sergey Ulanov's avatar Sergey Ulanov Committed by Commit Bot

Fix DCHECK in VulkanSurface

After crrev.com/649520 VulkanSurface was failing with a DCHECK when
initializing on platforms that don't report currentExtent values for
VulkanSurface. Updated VulkanSurface::CreateSwapChain() to handle this
case properly.
Also added some extra checks when casting uint32_t value received from
Vulkan to int.

Change-Id: I33a1d1ff3dc40b12ed9f7951ec5068f791fc45a7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1565249Reviewed-by: default avatarAntoine Labour <piman@chromium.org>
Commit-Queue: Sergey Ulanov <sergeyu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#650469}
parent 38ada3fc
...@@ -6,6 +6,8 @@ ...@@ -6,6 +6,8 @@
#include <vulkan/vulkan.h> #include <vulkan/vulkan.h>
#include <algorithm>
#include "base/macros.h" #include "base/macros.h"
#include "base/stl_util.h" #include "base/stl_util.h"
#include "gpu/vulkan/vulkan_device_queue.h" #include "gpu/vulkan/vulkan_device_queue.h"
...@@ -147,16 +149,14 @@ bool VulkanSurface::CreateSwapChain(const gfx::Size& size) { ...@@ -147,16 +149,14 @@ bool VulkanSurface::CreateSwapChain(const gfx::Size& size) {
// In that case, we will use the |size| which is the window size for the // In that case, we will use the |size| which is the window size for the
// swapchain. Otherwise, we just use the current surface size for the // swapchain. Otherwise, we just use the current surface size for the
// swapchian. // swapchian.
if (surface_caps.currentExtent.width == const uint32_t kUndefinedExtent = 0xFFFFFFFF;
std::numeric_limits<uint32_t>::max() || if (surface_caps.currentExtent.width == kUndefinedExtent &&
surface_caps.currentExtent.height == surface_caps.currentExtent.height == kUndefinedExtent) {
std::numeric_limits<uint32_t>::max()) { surface_caps.currentExtent.width = std::max(
DCHECK_EQ(surface_caps.currentExtent.width, surface_caps.minImageExtent.width, static_cast<uint32_t>(size.width()));
std::numeric_limits<uint32_t>::max()); surface_caps.currentExtent.height =
DCHECK_EQ(surface_caps.currentExtent.height, std::max(surface_caps.minImageExtent.height,
std::numeric_limits<uint32_t>::max()); static_cast<uint32_t>(size.height()));
surface_caps.currentExtent.width = size.width();
surface_caps.currentExtent.height = size.height();
} }
DCHECK_GE(surface_caps.currentExtent.width, DCHECK_GE(surface_caps.currentExtent.width,
...@@ -170,8 +170,9 @@ bool VulkanSurface::CreateSwapChain(const gfx::Size& size) { ...@@ -170,8 +170,9 @@ bool VulkanSurface::CreateSwapChain(const gfx::Size& size) {
DCHECK_GT(surface_caps.currentExtent.width, 0u); DCHECK_GT(surface_caps.currentExtent.width, 0u);
DCHECK_GT(surface_caps.currentExtent.height, 0u); DCHECK_GT(surface_caps.currentExtent.height, 0u);
gfx::Size new_size(surface_caps.currentExtent.width, gfx::Size new_size(
surface_caps.currentExtent.height); base::checked_cast<int>(surface_caps.currentExtent.width),
base::checked_cast<int>(surface_caps.currentExtent.height));
if (size_ == new_size) if (size_ == new_size)
return true; return true;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment