提交 8a218122 编写于 作者: B Brian Salomon 提交者: Brian Osman

Vulkan swap chain setup no longer uses GrPixelConfig and doesn't include from skia/src (#4856)

上级 9e0e7247
......@@ -10,7 +10,6 @@
#include "third_party/skia/include/gpu/GrBackendSemaphore.h"
#include "third_party/skia/include/gpu/GrBackendSurface.h"
#include "third_party/skia/include/gpu/GrContext.h"
#include "third_party/skia/src/gpu/vk/GrVkImage.h"
namespace flutter_runner {
......
......@@ -11,7 +11,6 @@
#include "third_party/skia/include/gpu/GrBackendSemaphore.h"
#include "third_party/skia/include/gpu/GrContext.h"
#include "third_party/skia/include/gpu/vk/GrVkTypes.h"
#include "third_party/skia/src/gpu/vk/GrVkUtil.h"
namespace flutter_runner {
......
......@@ -6,9 +6,9 @@
#include <limits>
#include "flutter/vulkan/skia_vulkan_header.h"
#include "flutter/vulkan/vulkan_proc_table.h"
#include "third_party/skia/include/gpu/vk/GrVkTypes.h"
#include "third_party/skia/src/gpu/vk/GrVkUtil.h"
namespace vulkan {
......
......@@ -12,7 +12,6 @@
#include "flutter/vulkan/vulkan_surface.h"
#include "flutter/vulkan/vulkan_utilities.h"
#include "third_party/skia/include/gpu/vk/GrVkBackendContext.h"
#include "third_party/skia/src/gpu/vk/GrVkUtil.h"
namespace vulkan {
......@@ -260,65 +259,46 @@ std::vector<VkQueueFamilyProperties> VulkanDevice::GetQueueFamilyProperties()
return properties;
}
bool VulkanDevice::ChooseSurfaceFormat(const VulkanSurface& surface,
VkSurfaceFormatKHR* format) const {
int VulkanDevice::ChooseSurfaceFormat(const VulkanSurface& surface,
std::vector<VkFormat> desired_formats,
VkSurfaceFormatKHR* format) const {
if (!surface.IsValid() || format == nullptr) {
return false;
return -1;
}
uint32_t format_count = 0;
if (VK_CALL_LOG_ERROR(vk.GetPhysicalDeviceSurfaceFormatsKHR(
physical_device_, surface.Handle(), &format_count, nullptr)) !=
VK_SUCCESS) {
return false;
return -1;
}
if (format_count == 0) {
return false;
return -1;
}
VkSurfaceFormatKHR formats[format_count];
if (VK_CALL_LOG_ERROR(vk.GetPhysicalDeviceSurfaceFormatsKHR(
physical_device_, surface.Handle(), &format_count, formats)) !=
VK_SUCCESS) {
return false;
return -1;
}
std::map<VkFormat, VkSurfaceFormatKHR> supported_formats;
for (uint32_t i = 0; i < format_count; i++) {
GrPixelConfig pixel_config = GrVkFormatToPixelConfig(formats[i].format);
if (pixel_config != kUnknown_GrPixelConfig) {
supported_formats[formats[i].format] = formats[i];
}
supported_formats[formats[i].format] = formats[i];
}
if (supported_formats.size() == 0) {
return false;
}
const std::vector<VkFormat> desired_formats = {
VK_FORMAT_R8G8B8A8_SRGB, // kSRGBA_8888_GrPixelConfig
VK_FORMAT_B8G8R8A8_SRGB, // kSBGRA_8888_GrPixelConfig
VK_FORMAT_R16G16B16A16_SFLOAT, // kRGBA_half_GrPixelConfig
VK_FORMAT_R8G8B8A8_UNORM, // kRGBA_8888_GrPixelConfig
VK_FORMAT_B8G8R8A8_UNORM, // kBGRA_8888_GrPixelConfig
};
// Try to find the first supported format in the list of desired formats.
for (VkFormat current_format : desired_formats) {
auto found = supported_formats.find(current_format);
for (size_t i = 0; i < desired_formats.size(); ++i) {
auto found = supported_formats.find(desired_formats[i]);
if (found != supported_formats.end()) {
*format = found->second;
return true;
return static_cast<int>(i);
}
}
// None of the desired formats were supported. Return the first supported
// format even if we don't like it all that much (it has already returned true
// for GrVkFormatToPixelConfig).
*format = supported_formats.begin()->second;
return true;
return -1;
}
bool VulkanDevice::ChoosePresentMode(const VulkanSurface& surface,
......
......@@ -49,8 +49,9 @@ class VulkanDevice {
uint32_t* /* mask of GrVkFeatureFlags */ features) const;
FXL_WARN_UNUSED_RESULT
bool ChooseSurfaceFormat(const VulkanSurface& surface,
VkSurfaceFormatKHR* format) const;
int ChooseSurfaceFormat(const VulkanSurface& surface,
std::vector<VkFormat> desired_formats,
VkSurfaceFormatKHR* format) const;
FXL_WARN_UNUSED_RESULT
bool ChoosePresentMode(const VulkanSurface& surface,
......
......@@ -10,11 +10,32 @@
#include "flutter/vulkan/vulkan_proc_table.h"
#include "flutter/vulkan/vulkan_surface.h"
#include "third_party/skia/include/gpu/GrBackendSurface.h"
#include "third_party/skia/include/gpu/GrContext.h"
#include "third_party/skia/include/gpu/vk/GrVkTypes.h"
#include "third_party/skia/src/gpu/vk/GrVkUtil.h"
namespace vulkan {
namespace {
struct FormatInfo {
VkFormat format_;
SkColorType color_type_;
sk_sp<SkColorSpace> color_space_;
};
} // namespace
static std::vector<FormatInfo> DesiredFormatInfos() {
return {{VK_FORMAT_R8G8B8A8_SRGB, kRGBA_8888_SkColorType,
SkColorSpace::MakeSRGB()},
{VK_FORMAT_B8G8R8A8_SRGB, kRGBA_8888_SkColorType,
SkColorSpace::MakeSRGB()},
{VK_FORMAT_R16G16B16A16_SFLOAT, kRGBA_F16_SkColorType,
SkColorSpace::MakeSRGBLinear()},
{VK_FORMAT_R8G8B8A8_UNORM, kRGBA_8888_SkColorType,
SkColorSpace::MakeSRGB()},
{VK_FORMAT_B8G8R8A8_UNORM, kRGBA_8888_SkColorType,
SkColorSpace::MakeSRGB()}};
}
VulkanSwapchain::VulkanSwapchain(const VulkanProcTable& p_vk,
const VulkanDevice& device,
const VulkanSurface& surface,
......@@ -39,7 +60,20 @@ VulkanSwapchain::VulkanSwapchain(const VulkanProcTable& p_vk,
return;
}
if (!device_.ChooseSurfaceFormat(surface, &surface_format_)) {
const auto format_infos = DesiredFormatInfos();
std::vector<VkFormat> desired_formats(format_infos.size());
for (size_t i = 0; i < format_infos.size(); ++i) {
if (skia_context->colorTypeSupportedAsSurface(
format_infos[i].color_type_)) {
desired_formats[i] = format_infos[i].format_;
} else {
desired_formats[i] = VK_FORMAT_UNDEFINED;
}
}
int format_index =
device_.ChooseSurfaceFormat(surface, desired_formats, &surface_format_);
if (format_index < 0) {
FXL_DLOG(INFO) << "Could not choose surface format.";
return;
}
......@@ -115,7 +149,9 @@ VulkanSwapchain::VulkanSwapchain(const VulkanProcTable& p_vk,
nullptr);
}};
if (!CreateSwapchainImages(skia_context)) {
if (!CreateSwapchainImages(skia_context,
format_infos[format_index].color_type_,
format_infos[format_index].color_space_)) {
FXL_DLOG(INFO) << "Could not create swapchain images.";
return;
}
......@@ -171,29 +207,18 @@ SkISize VulkanSwapchain::GetSize() const {
return SkISize::Make(extents.width, extents.height);
}
static sk_sp<SkColorSpace> SkColorSpaceFromVkFormat(VkFormat format) {
if (GrVkFormatIsSRGB(format, nullptr /* dont care */)) {
return SkColorSpace::MakeSRGB();
}
if (format == VK_FORMAT_R16G16B16A16_SFLOAT) {
return SkColorSpace::MakeSRGBLinear();
}
return nullptr;
}
sk_sp<SkSurface> VulkanSwapchain::CreateSkiaSurface(GrContext* gr_context,
VkImage image,
const SkISize& size) const {
sk_sp<SkSurface> VulkanSwapchain::CreateSkiaSurface(
GrContext* gr_context,
VkImage image,
const SkISize& size,
SkColorType color_type,
sk_sp<SkColorSpace> color_space) const {
if (gr_context == nullptr) {
return nullptr;
}
GrPixelConfig pixel_config = GrVkFormatToPixelConfig(surface_format_.format);
if (pixel_config == kUnknown_GrPixelConfig) {
// Vulkan format unsupported by Skia.
if (color_type == kUnknown_SkColorType) {
// Unexpected Vulkan format.
return nullptr;
}
......@@ -212,15 +237,18 @@ sk_sp<SkSurface> VulkanSwapchain::CreateSkiaSurface(GrContext* gr_context,
SkSurfaceProps props(SkSurfaceProps::InitType::kLegacyFontHost_InitType);
return SkSurface::MakeFromBackendRenderTarget(
gr_context, // context
backend_render_target, // backend render target
kTopLeft_GrSurfaceOrigin,
SkColorSpaceFromVkFormat(surface_format_.format), // colorspace
&props // surface properties
gr_context, // context
backend_render_target, // backend render target
kTopLeft_GrSurfaceOrigin, // origin
color_type, // color type
std::move(color_space), // color space
&props // surface properties
);
}
bool VulkanSwapchain::CreateSwapchainImages(GrContext* skia_context) {
bool VulkanSwapchain::CreateSwapchainImages(GrContext* skia_context,
SkColorType color_type,
sk_sp<SkColorSpace> color_space) {
std::vector<VkImage> images = GetImages();
if (images.size() == 0) {
......@@ -250,7 +278,8 @@ bool VulkanSwapchain::CreateSwapchainImages(GrContext* skia_context) {
images_.emplace_back(std::move(vulkan_image));
// Populate the surface.
auto surface = CreateSkiaSurface(skia_context, image, surface_size);
auto surface = CreateSkiaSurface(skia_context, image, surface_size,
color_type, color_space);
if (surface == nullptr) {
return false;
......
......@@ -77,11 +77,15 @@ class VulkanSwapchain {
std::vector<VkImage> GetImages() const;
bool CreateSwapchainImages(GrContext* skia_context);
bool CreateSwapchainImages(GrContext* skia_context,
SkColorType color_type,
sk_sp<SkColorSpace> color_space);
sk_sp<SkSurface> CreateSkiaSurface(GrContext* skia_context,
VkImage image,
const SkISize& size) const;
const SkISize& size,
SkColorType color_type,
sk_sp<SkColorSpace> color_space) const;
VulkanBackbuffer* GetNextBackbuffer();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册